main.js 138 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457
  1. 'use strict';
  2. var obsidian = require('obsidian');
  3. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  4. var obsidian__default = /*#__PURE__*/_interopDefaultLegacy(obsidian);
  5. const DEFAULT_WEEK_FORMAT = "gggg-[W]ww";
  6. const DEFAULT_WORDS_PER_DOT = 250;
  7. const VIEW_TYPE_CALENDAR = "calendar";
  8. const TRIGGER_ON_OPEN = "calendar:open";
  9. const DEFAULT_DAILY_NOTE_FORMAT = "YYYY-MM-DD";
  10. const DEFAULT_WEEKLY_NOTE_FORMAT = "gggg-[W]ww";
  11. const DEFAULT_MONTHLY_NOTE_FORMAT = "YYYY-MM";
  12. function shouldUsePeriodicNotesSettings(periodicity) {
  13. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  14. const periodicNotes = window.app.plugins.getPlugin("periodic-notes");
  15. return periodicNotes && periodicNotes.settings?.[periodicity]?.enabled;
  16. }
  17. /**
  18. * Read the user settings for the `daily-notes` plugin
  19. * to keep behavior of creating a new note in-sync.
  20. */
  21. function getDailyNoteSettings() {
  22. try {
  23. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  24. const { internalPlugins, plugins } = window.app;
  25. if (shouldUsePeriodicNotesSettings("daily")) {
  26. const { format, folder, template } = plugins.getPlugin("periodic-notes")?.settings?.daily || {};
  27. return {
  28. format: format || DEFAULT_DAILY_NOTE_FORMAT,
  29. folder: folder?.trim() || "",
  30. template: template?.trim() || "",
  31. };
  32. }
  33. const { folder, format, template } = internalPlugins.getPluginById("daily-notes")?.instance?.options || {};
  34. return {
  35. format: format || DEFAULT_DAILY_NOTE_FORMAT,
  36. folder: folder?.trim() || "",
  37. template: template?.trim() || "",
  38. };
  39. }
  40. catch (err) {
  41. console.info("No custom daily note settings found!", err);
  42. }
  43. }
  44. /**
  45. * Read the user settings for the `weekly-notes` plugin
  46. * to keep behavior of creating a new note in-sync.
  47. */
  48. function getWeeklyNoteSettings() {
  49. try {
  50. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  51. const pluginManager = window.app.plugins;
  52. const calendarSettings = pluginManager.getPlugin("calendar")?.options;
  53. const periodicNotesSettings = pluginManager.getPlugin("periodic-notes")
  54. ?.settings?.weekly;
  55. if (shouldUsePeriodicNotesSettings("weekly")) {
  56. return {
  57. format: periodicNotesSettings.format || DEFAULT_WEEKLY_NOTE_FORMAT,
  58. folder: periodicNotesSettings.folder?.trim() || "",
  59. template: periodicNotesSettings.template?.trim() || "",
  60. };
  61. }
  62. const settings = calendarSettings || {};
  63. return {
  64. format: settings.weeklyNoteFormat || DEFAULT_WEEKLY_NOTE_FORMAT,
  65. folder: settings.weeklyNoteFolder?.trim() || "",
  66. template: settings.weeklyNoteTemplate?.trim() || "",
  67. };
  68. }
  69. catch (err) {
  70. console.info("No custom weekly note settings found!", err);
  71. }
  72. }
  73. /**
  74. * Read the user settings for the `periodic-notes` plugin
  75. * to keep behavior of creating a new note in-sync.
  76. */
  77. function getMonthlyNoteSettings() {
  78. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  79. const pluginManager = window.app.plugins;
  80. try {
  81. const settings = (shouldUsePeriodicNotesSettings("monthly") &&
  82. pluginManager.getPlugin("periodic-notes")?.settings?.monthly) ||
  83. {};
  84. return {
  85. format: settings.format || DEFAULT_MONTHLY_NOTE_FORMAT,
  86. folder: settings.folder?.trim() || "",
  87. template: settings.template?.trim() || "",
  88. };
  89. }
  90. catch (err) {
  91. console.info("No custom monthly note settings found!", err);
  92. }
  93. }
  94. /**
  95. * dateUID is a way of weekly identifying daily/weekly/monthly notes.
  96. * They are prefixed with the granularity to avoid ambiguity.
  97. */
  98. function getDateUID$1(date, granularity = "day") {
  99. const ts = date.clone().startOf(granularity).format();
  100. return `${granularity}-${ts}`;
  101. }
  102. function removeEscapedCharacters(format) {
  103. return format.replace(/\[[^\]]*\]/g, ""); // remove everything within brackets
  104. }
  105. /**
  106. * XXX: When parsing dates that contain both week numbers and months,
  107. * Moment choses to ignore the week numbers. For the week dateUID, we
  108. * want the opposite behavior. Strip the MMM from the format to patch.
  109. */
  110. function isFormatAmbiguous(format, granularity) {
  111. if (granularity === "week") {
  112. const cleanFormat = removeEscapedCharacters(format);
  113. return (/w{1,2}/i.test(cleanFormat) &&
  114. (/M{1,4}/.test(cleanFormat) || /D{1,4}/.test(cleanFormat)));
  115. }
  116. return false;
  117. }
  118. function getDateFromFile(file, granularity) {
  119. const getSettings = {
  120. day: getDailyNoteSettings,
  121. week: getWeeklyNoteSettings,
  122. month: getMonthlyNoteSettings,
  123. };
  124. const format = getSettings[granularity]().format.split("/").pop();
  125. const noteDate = window.moment(file.basename, format, true);
  126. if (!noteDate.isValid()) {
  127. return null;
  128. }
  129. if (isFormatAmbiguous(format, granularity)) {
  130. if (granularity === "week") {
  131. const cleanFormat = removeEscapedCharacters(format);
  132. if (/w{1,2}/i.test(cleanFormat)) {
  133. return window.moment(file.basename,
  134. // If format contains week, remove day & month formatting
  135. format.replace(/M{1,4}/g, "").replace(/D{1,4}/g, ""), false);
  136. }
  137. }
  138. }
  139. return noteDate;
  140. }
  141. // Credit: @creationix/path.js
  142. function join(...partSegments) {
  143. // Split the inputs into a list of path commands.
  144. let parts = [];
  145. for (let i = 0, l = partSegments.length; i < l; i++) {
  146. parts = parts.concat(partSegments[i].split("/"));
  147. }
  148. // Interpret the path commands to get the new resolved path.
  149. const newParts = [];
  150. for (let i = 0, l = parts.length; i < l; i++) {
  151. const part = parts[i];
  152. // Remove leading and trailing slashes
  153. // Also remove "." segments
  154. if (!part || part === ".")
  155. continue;
  156. // Push new path segments.
  157. else
  158. newParts.push(part);
  159. }
  160. // Preserve the initial slash if there was one.
  161. if (parts[0] === "")
  162. newParts.unshift("");
  163. // Turn back into a single string path.
  164. return newParts.join("/");
  165. }
  166. async function ensureFolderExists(path) {
  167. const dirs = path.replace(/\\/g, "/").split("/");
  168. dirs.pop(); // remove basename
  169. if (dirs.length) {
  170. const dir = join(...dirs);
  171. if (!window.app.vault.getAbstractFileByPath(dir)) {
  172. await window.app.vault.createFolder(dir);
  173. }
  174. }
  175. }
  176. async function getNotePath(directory, filename) {
  177. if (!filename.endsWith(".md")) {
  178. filename += ".md";
  179. }
  180. const path = obsidian__default['default'].normalizePath(join(directory, filename));
  181. await ensureFolderExists(path);
  182. return path;
  183. }
  184. async function getTemplateInfo(template) {
  185. const { metadataCache, vault } = window.app;
  186. const templatePath = obsidian__default['default'].normalizePath(template);
  187. if (templatePath === "/") {
  188. return Promise.resolve(["", null]);
  189. }
  190. try {
  191. const templateFile = metadataCache.getFirstLinkpathDest(templatePath, "");
  192. const contents = await vault.cachedRead(templateFile);
  193. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  194. const IFoldInfo = window.app.foldManager.load(templateFile);
  195. return [contents, IFoldInfo];
  196. }
  197. catch (err) {
  198. console.error(`Failed to read the daily note template '${templatePath}'`, err);
  199. new obsidian__default['default'].Notice("Failed to read the daily note template");
  200. return ["", null];
  201. }
  202. }
  203. class DailyNotesFolderMissingError extends Error {
  204. }
  205. /**
  206. * This function mimics the behavior of the daily-notes plugin
  207. * so it will replace {{date}}, {{title}}, and {{time}} with the
  208. * formatted timestamp.
  209. *
  210. * Note: it has an added bonus that it's not 'today' specific.
  211. */
  212. async function createDailyNote(date) {
  213. const app = window.app;
  214. const { vault } = app;
  215. const moment = window.moment;
  216. const { template, format, folder } = getDailyNoteSettings();
  217. const [templateContents, IFoldInfo] = await getTemplateInfo(template);
  218. const filename = date.format(format);
  219. const normalizedPath = await getNotePath(folder, filename);
  220. try {
  221. const createdFile = await vault.create(normalizedPath, templateContents
  222. .replace(/{{\s*date\s*}}/gi, filename)
  223. .replace(/{{\s*time\s*}}/gi, moment().format("HH:mm"))
  224. .replace(/{{\s*title\s*}}/gi, filename)
  225. .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => {
  226. const now = moment();
  227. const currentDate = date.clone().set({
  228. hour: now.get("hour"),
  229. minute: now.get("minute"),
  230. second: now.get("second"),
  231. });
  232. if (calc) {
  233. currentDate.add(parseInt(timeDelta, 10), unit);
  234. }
  235. if (momentFormat) {
  236. return currentDate.format(momentFormat.substring(1).trim());
  237. }
  238. return currentDate.format(format);
  239. })
  240. .replace(/{{\s*yesterday\s*}}/gi, date.clone().subtract(1, "day").format(format))
  241. .replace(/{{\s*tomorrow\s*}}/gi, date.clone().add(1, "d").format(format)));
  242. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  243. app.foldManager.save(createdFile, IFoldInfo);
  244. return createdFile;
  245. }
  246. catch (err) {
  247. console.error(`Failed to create file: '${normalizedPath}'`, err);
  248. new obsidian__default['default'].Notice("Unable to create new file.");
  249. }
  250. }
  251. function getDailyNote(date, dailyNotes) {
  252. return dailyNotes[getDateUID$1(date, "day")] ?? null;
  253. }
  254. function getAllDailyNotes() {
  255. /**
  256. * Find all daily notes in the daily note folder
  257. */
  258. const { vault } = window.app;
  259. const { folder } = getDailyNoteSettings();
  260. const dailyNotesFolder = vault.getAbstractFileByPath(obsidian__default['default'].normalizePath(folder));
  261. if (!dailyNotesFolder) {
  262. throw new DailyNotesFolderMissingError("Failed to find daily notes folder");
  263. }
  264. const dailyNotes = {};
  265. obsidian__default['default'].Vault.recurseChildren(dailyNotesFolder, (note) => {
  266. if (note instanceof obsidian__default['default'].TFile) {
  267. const date = getDateFromFile(note, "day");
  268. if (date) {
  269. const dateString = getDateUID$1(date, "day");
  270. dailyNotes[dateString] = note;
  271. }
  272. }
  273. });
  274. return dailyNotes;
  275. }
  276. class WeeklyNotesFolderMissingError extends Error {
  277. }
  278. function getDaysOfWeek$1() {
  279. const { moment } = window;
  280. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  281. let weekStart = moment.localeData()._week.dow;
  282. const daysOfWeek = [
  283. "sunday",
  284. "monday",
  285. "tuesday",
  286. "wednesday",
  287. "thursday",
  288. "friday",
  289. "saturday",
  290. ];
  291. while (weekStart) {
  292. daysOfWeek.push(daysOfWeek.shift());
  293. weekStart--;
  294. }
  295. return daysOfWeek;
  296. }
  297. function getDayOfWeekNumericalValue(dayOfWeekName) {
  298. return getDaysOfWeek$1().indexOf(dayOfWeekName.toLowerCase());
  299. }
  300. async function createWeeklyNote(date) {
  301. const { vault } = window.app;
  302. const { template, format, folder } = getWeeklyNoteSettings();
  303. const [templateContents, IFoldInfo] = await getTemplateInfo(template);
  304. const filename = date.format(format);
  305. const normalizedPath = await getNotePath(folder, filename);
  306. try {
  307. const createdFile = await vault.create(normalizedPath, templateContents
  308. .replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi, (_, _timeOrDate, calc, timeDelta, unit, momentFormat) => {
  309. const now = window.moment();
  310. const currentDate = date.clone().set({
  311. hour: now.get("hour"),
  312. minute: now.get("minute"),
  313. second: now.get("second"),
  314. });
  315. if (calc) {
  316. currentDate.add(parseInt(timeDelta, 10), unit);
  317. }
  318. if (momentFormat) {
  319. return currentDate.format(momentFormat.substring(1).trim());
  320. }
  321. return currentDate.format(format);
  322. })
  323. .replace(/{{\s*title\s*}}/gi, filename)
  324. .replace(/{{\s*time\s*}}/gi, window.moment().format("HH:mm"))
  325. .replace(/{{\s*(sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s*:(.*?)}}/gi, (_, dayOfWeek, momentFormat) => {
  326. const day = getDayOfWeekNumericalValue(dayOfWeek);
  327. return date.weekday(day).format(momentFormat.trim());
  328. }));
  329. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  330. window.app.foldManager.save(createdFile, IFoldInfo);
  331. return createdFile;
  332. }
  333. catch (err) {
  334. console.error(`Failed to create file: '${normalizedPath}'`, err);
  335. new obsidian__default['default'].Notice("Unable to create new file.");
  336. }
  337. }
  338. function getWeeklyNote(date, weeklyNotes) {
  339. return weeklyNotes[getDateUID$1(date, "week")] ?? null;
  340. }
  341. function getAllWeeklyNotes() {
  342. const { vault } = window.app;
  343. const { folder } = getWeeklyNoteSettings();
  344. const weeklyNotesFolder = vault.getAbstractFileByPath(obsidian__default['default'].normalizePath(folder));
  345. if (!weeklyNotesFolder) {
  346. throw new WeeklyNotesFolderMissingError("Failed to find weekly notes folder");
  347. }
  348. const weeklyNotes = {};
  349. obsidian__default['default'].Vault.recurseChildren(weeklyNotesFolder, (note) => {
  350. if (note instanceof obsidian__default['default'].TFile) {
  351. const date = getDateFromFile(note, "week");
  352. if (date) {
  353. const dateString = getDateUID$1(date, "week");
  354. weeklyNotes[dateString] = note;
  355. }
  356. }
  357. });
  358. return weeklyNotes;
  359. }
  360. function appHasDailyNotesPluginLoaded() {
  361. const { app } = window;
  362. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  363. const dailyNotesPlugin = app.internalPlugins.plugins["daily-notes"];
  364. if (dailyNotesPlugin && dailyNotesPlugin.enabled) {
  365. return true;
  366. }
  367. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  368. const periodicNotes = app.plugins.getPlugin("periodic-notes");
  369. return periodicNotes && periodicNotes.settings?.daily?.enabled;
  370. }
  371. var appHasDailyNotesPluginLoaded_1 = appHasDailyNotesPluginLoaded;
  372. var createDailyNote_1 = createDailyNote;
  373. var createWeeklyNote_1 = createWeeklyNote;
  374. var getAllDailyNotes_1 = getAllDailyNotes;
  375. var getAllWeeklyNotes_1 = getAllWeeklyNotes;
  376. var getDailyNote_1 = getDailyNote;
  377. var getDailyNoteSettings_1 = getDailyNoteSettings;
  378. var getDateFromFile_1 = getDateFromFile;
  379. var getDateUID_1$1 = getDateUID$1;
  380. var getWeeklyNote_1 = getWeeklyNote;
  381. var getWeeklyNoteSettings_1 = getWeeklyNoteSettings;
  382. function noop$1() { }
  383. function run$1(fn) {
  384. return fn();
  385. }
  386. function blank_object$1() {
  387. return Object.create(null);
  388. }
  389. function run_all$1(fns) {
  390. fns.forEach(run$1);
  391. }
  392. function is_function$1(thing) {
  393. return typeof thing === 'function';
  394. }
  395. function safe_not_equal$1(a, b) {
  396. return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
  397. }
  398. function not_equal$1(a, b) {
  399. return a != a ? b == b : a !== b;
  400. }
  401. function is_empty$1(obj) {
  402. return Object.keys(obj).length === 0;
  403. }
  404. function subscribe(store, ...callbacks) {
  405. if (store == null) {
  406. return noop$1;
  407. }
  408. const unsub = store.subscribe(...callbacks);
  409. return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
  410. }
  411. function get_store_value(store) {
  412. let value;
  413. subscribe(store, _ => value = _)();
  414. return value;
  415. }
  416. function component_subscribe(component, store, callback) {
  417. component.$$.on_destroy.push(subscribe(store, callback));
  418. }
  419. function detach$1(node) {
  420. node.parentNode.removeChild(node);
  421. }
  422. function children$1(element) {
  423. return Array.from(element.childNodes);
  424. }
  425. let current_component$1;
  426. function set_current_component$1(component) {
  427. current_component$1 = component;
  428. }
  429. function get_current_component$1() {
  430. if (!current_component$1)
  431. throw new Error('Function called outside component initialization');
  432. return current_component$1;
  433. }
  434. function onDestroy(fn) {
  435. get_current_component$1().$$.on_destroy.push(fn);
  436. }
  437. const dirty_components$1 = [];
  438. const binding_callbacks$1 = [];
  439. const render_callbacks$1 = [];
  440. const flush_callbacks$1 = [];
  441. const resolved_promise$1 = Promise.resolve();
  442. let update_scheduled$1 = false;
  443. function schedule_update$1() {
  444. if (!update_scheduled$1) {
  445. update_scheduled$1 = true;
  446. resolved_promise$1.then(flush$1);
  447. }
  448. }
  449. function add_render_callback$1(fn) {
  450. render_callbacks$1.push(fn);
  451. }
  452. function add_flush_callback(fn) {
  453. flush_callbacks$1.push(fn);
  454. }
  455. let flushing$1 = false;
  456. const seen_callbacks$1 = new Set();
  457. function flush$1() {
  458. if (flushing$1)
  459. return;
  460. flushing$1 = true;
  461. do {
  462. // first, call beforeUpdate functions
  463. // and update components
  464. for (let i = 0; i < dirty_components$1.length; i += 1) {
  465. const component = dirty_components$1[i];
  466. set_current_component$1(component);
  467. update$1(component.$$);
  468. }
  469. set_current_component$1(null);
  470. dirty_components$1.length = 0;
  471. while (binding_callbacks$1.length)
  472. binding_callbacks$1.pop()();
  473. // then, once components are updated, call
  474. // afterUpdate functions. This may cause
  475. // subsequent updates...
  476. for (let i = 0; i < render_callbacks$1.length; i += 1) {
  477. const callback = render_callbacks$1[i];
  478. if (!seen_callbacks$1.has(callback)) {
  479. // ...so guard against infinite loops
  480. seen_callbacks$1.add(callback);
  481. callback();
  482. }
  483. }
  484. render_callbacks$1.length = 0;
  485. } while (dirty_components$1.length);
  486. while (flush_callbacks$1.length) {
  487. flush_callbacks$1.pop()();
  488. }
  489. update_scheduled$1 = false;
  490. flushing$1 = false;
  491. seen_callbacks$1.clear();
  492. }
  493. function update$1($$) {
  494. if ($$.fragment !== null) {
  495. $$.update();
  496. run_all$1($$.before_update);
  497. const dirty = $$.dirty;
  498. $$.dirty = [-1];
  499. $$.fragment && $$.fragment.p($$.ctx, dirty);
  500. $$.after_update.forEach(add_render_callback$1);
  501. }
  502. }
  503. const outroing$1 = new Set();
  504. let outros$1;
  505. function transition_in$1(block, local) {
  506. if (block && block.i) {
  507. outroing$1.delete(block);
  508. block.i(local);
  509. }
  510. }
  511. function transition_out$1(block, local, detach, callback) {
  512. if (block && block.o) {
  513. if (outroing$1.has(block))
  514. return;
  515. outroing$1.add(block);
  516. outros$1.c.push(() => {
  517. outroing$1.delete(block);
  518. if (callback) {
  519. if (detach)
  520. block.d(1);
  521. callback();
  522. }
  523. });
  524. block.o(local);
  525. }
  526. }
  527. function bind(component, name, callback) {
  528. const index = component.$$.props[name];
  529. if (index !== undefined) {
  530. component.$$.bound[index] = callback;
  531. callback(component.$$.ctx[index]);
  532. }
  533. }
  534. function create_component$1(block) {
  535. block && block.c();
  536. }
  537. function mount_component$1(component, target, anchor, customElement) {
  538. const { fragment, on_mount, on_destroy, after_update } = component.$$;
  539. fragment && fragment.m(target, anchor);
  540. if (!customElement) {
  541. // onMount happens before the initial afterUpdate
  542. add_render_callback$1(() => {
  543. const new_on_destroy = on_mount.map(run$1).filter(is_function$1);
  544. if (on_destroy) {
  545. on_destroy.push(...new_on_destroy);
  546. }
  547. else {
  548. // Edge case - component was destroyed immediately,
  549. // most likely as a result of a binding initialising
  550. run_all$1(new_on_destroy);
  551. }
  552. component.$$.on_mount = [];
  553. });
  554. }
  555. after_update.forEach(add_render_callback$1);
  556. }
  557. function destroy_component$1(component, detaching) {
  558. const $$ = component.$$;
  559. if ($$.fragment !== null) {
  560. run_all$1($$.on_destroy);
  561. $$.fragment && $$.fragment.d(detaching);
  562. // TODO null out other refs, including component.$$ (but need to
  563. // preserve final state?)
  564. $$.on_destroy = $$.fragment = null;
  565. $$.ctx = [];
  566. }
  567. }
  568. function make_dirty$1(component, i) {
  569. if (component.$$.dirty[0] === -1) {
  570. dirty_components$1.push(component);
  571. schedule_update$1();
  572. component.$$.dirty.fill(0);
  573. }
  574. component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
  575. }
  576. function init$1(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
  577. const parent_component = current_component$1;
  578. set_current_component$1(component);
  579. const $$ = component.$$ = {
  580. fragment: null,
  581. ctx: null,
  582. // state
  583. props,
  584. update: noop$1,
  585. not_equal,
  586. bound: blank_object$1(),
  587. // lifecycle
  588. on_mount: [],
  589. on_destroy: [],
  590. on_disconnect: [],
  591. before_update: [],
  592. after_update: [],
  593. context: new Map(parent_component ? parent_component.$$.context : []),
  594. // everything else
  595. callbacks: blank_object$1(),
  596. dirty,
  597. skip_bound: false
  598. };
  599. let ready = false;
  600. $$.ctx = instance
  601. ? instance(component, options.props || {}, (i, ret, ...rest) => {
  602. const value = rest.length ? rest[0] : ret;
  603. if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
  604. if (!$$.skip_bound && $$.bound[i])
  605. $$.bound[i](value);
  606. if (ready)
  607. make_dirty$1(component, i);
  608. }
  609. return ret;
  610. })
  611. : [];
  612. $$.update();
  613. ready = true;
  614. run_all$1($$.before_update);
  615. // `false` as a special case of no DOM component
  616. $$.fragment = create_fragment ? create_fragment($$.ctx) : false;
  617. if (options.target) {
  618. if (options.hydrate) {
  619. const nodes = children$1(options.target);
  620. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  621. $$.fragment && $$.fragment.l(nodes);
  622. nodes.forEach(detach$1);
  623. }
  624. else {
  625. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  626. $$.fragment && $$.fragment.c();
  627. }
  628. if (options.intro)
  629. transition_in$1(component.$$.fragment);
  630. mount_component$1(component, options.target, options.anchor, options.customElement);
  631. flush$1();
  632. }
  633. set_current_component$1(parent_component);
  634. }
  635. /**
  636. * Base class for Svelte components. Used when dev=false.
  637. */
  638. class SvelteComponent$1 {
  639. $destroy() {
  640. destroy_component$1(this, 1);
  641. this.$destroy = noop$1;
  642. }
  643. $on(type, callback) {
  644. const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
  645. callbacks.push(callback);
  646. return () => {
  647. const index = callbacks.indexOf(callback);
  648. if (index !== -1)
  649. callbacks.splice(index, 1);
  650. };
  651. }
  652. $set($$props) {
  653. if (this.$$set && !is_empty$1($$props)) {
  654. this.$$.skip_bound = true;
  655. this.$$set($$props);
  656. this.$$.skip_bound = false;
  657. }
  658. }
  659. }
  660. const subscriber_queue = [];
  661. /**
  662. * Create a `Writable` store that allows both updating and reading by subscription.
  663. * @param {*=}value initial value
  664. * @param {StartStopNotifier=}start start and stop notifications for subscriptions
  665. */
  666. function writable(value, start = noop$1) {
  667. let stop;
  668. const subscribers = [];
  669. function set(new_value) {
  670. if (safe_not_equal$1(value, new_value)) {
  671. value = new_value;
  672. if (stop) { // store is ready
  673. const run_queue = !subscriber_queue.length;
  674. for (let i = 0; i < subscribers.length; i += 1) {
  675. const s = subscribers[i];
  676. s[1]();
  677. subscriber_queue.push(s, value);
  678. }
  679. if (run_queue) {
  680. for (let i = 0; i < subscriber_queue.length; i += 2) {
  681. subscriber_queue[i][0](subscriber_queue[i + 1]);
  682. }
  683. subscriber_queue.length = 0;
  684. }
  685. }
  686. }
  687. }
  688. function update(fn) {
  689. set(fn(value));
  690. }
  691. function subscribe(run, invalidate = noop$1) {
  692. const subscriber = [run, invalidate];
  693. subscribers.push(subscriber);
  694. if (subscribers.length === 1) {
  695. stop = start(set) || noop$1;
  696. }
  697. run(value);
  698. return () => {
  699. const index = subscribers.indexOf(subscriber);
  700. if (index !== -1) {
  701. subscribers.splice(index, 1);
  702. }
  703. if (subscribers.length === 0) {
  704. stop();
  705. stop = null;
  706. }
  707. };
  708. }
  709. return { set, update, subscribe };
  710. }
  711. const weekdays$1 = [
  712. "sunday",
  713. "monday",
  714. "tuesday",
  715. "wednesday",
  716. "thursday",
  717. "friday",
  718. "saturday",
  719. ];
  720. const defaultSettings = Object.freeze({
  721. shouldConfirmBeforeCreate: true,
  722. weekStart: "locale",
  723. wordsPerDot: DEFAULT_WORDS_PER_DOT,
  724. showWeeklyNote: false,
  725. weeklyNoteFormat: "",
  726. weeklyNoteTemplate: "",
  727. weeklyNoteFolder: "",
  728. localeOverride: "system-default",
  729. });
  730. function appHasPeriodicNotesPluginLoaded() {
  731. var _a, _b;
  732. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  733. const periodicNotes = window.app.plugins.getPlugin("periodic-notes");
  734. return periodicNotes && ((_b = (_a = periodicNotes.settings) === null || _a === void 0 ? void 0 : _a.weekly) === null || _b === void 0 ? void 0 : _b.enabled);
  735. }
  736. class CalendarSettingsTab extends obsidian.PluginSettingTab {
  737. constructor(app, plugin) {
  738. super(app, plugin);
  739. this.plugin = plugin;
  740. }
  741. display() {
  742. this.containerEl.empty();
  743. if (!appHasDailyNotesPluginLoaded_1()) {
  744. this.containerEl.createDiv("settings-banner", (banner) => {
  745. banner.createEl("h3", {
  746. text: "⚠️ Daily Notes plugin not enabled",
  747. });
  748. banner.createEl("p", {
  749. cls: "setting-item-description",
  750. text: "The calendar is best used in conjunction with either the Daily Notes plugin or the Periodic Notes plugin (available in the Community Plugins catalog).",
  751. });
  752. });
  753. }
  754. this.containerEl.createEl("h3", {
  755. text: "General Settings",
  756. });
  757. this.addDotThresholdSetting();
  758. this.addWeekStartSetting();
  759. this.addConfirmCreateSetting();
  760. this.addShowWeeklyNoteSetting();
  761. if (this.plugin.options.showWeeklyNote &&
  762. !appHasPeriodicNotesPluginLoaded()) {
  763. this.containerEl.createEl("h3", {
  764. text: "Weekly Note Settings",
  765. });
  766. this.containerEl.createEl("p", {
  767. cls: "setting-item-description",
  768. text: "Note: Weekly Note settings are moving. You are encouraged to install the 'Periodic Notes' plugin to keep the functionality in the future.",
  769. });
  770. this.addWeeklyNoteFormatSetting();
  771. this.addWeeklyNoteTemplateSetting();
  772. this.addWeeklyNoteFolderSetting();
  773. }
  774. this.containerEl.createEl("h3", {
  775. text: "Advanced Settings",
  776. });
  777. this.addLocaleOverrideSetting();
  778. }
  779. addDotThresholdSetting() {
  780. new obsidian.Setting(this.containerEl)
  781. .setName("Words per dot")
  782. .setDesc("How many words should be represented by a single dot?")
  783. .addText((textfield) => {
  784. textfield.setPlaceholder(String(DEFAULT_WORDS_PER_DOT));
  785. textfield.inputEl.type = "number";
  786. textfield.setValue(String(this.plugin.options.wordsPerDot));
  787. textfield.onChange(async (value) => {
  788. this.plugin.writeOptions(() => ({
  789. wordsPerDot: value !== "" ? Number(value) : undefined,
  790. }));
  791. });
  792. });
  793. }
  794. addWeekStartSetting() {
  795. const { moment } = window;
  796. const localizedWeekdays = moment.weekdays();
  797. const localeWeekStartNum = window._bundledLocaleWeekSpec.dow;
  798. const localeWeekStart = moment.weekdays()[localeWeekStartNum];
  799. new obsidian.Setting(this.containerEl)
  800. .setName("Start week on:")
  801. .setDesc("Choose what day of the week to start. Select 'Locale default' to use the default specified by moment.js")
  802. .addDropdown((dropdown) => {
  803. dropdown.addOption("locale", `Locale default (${localeWeekStart})`);
  804. localizedWeekdays.forEach((day, i) => {
  805. dropdown.addOption(weekdays$1[i], day);
  806. });
  807. dropdown.setValue(this.plugin.options.weekStart);
  808. dropdown.onChange(async (value) => {
  809. this.plugin.writeOptions(() => ({
  810. weekStart: value,
  811. }));
  812. });
  813. });
  814. }
  815. addConfirmCreateSetting() {
  816. new obsidian.Setting(this.containerEl)
  817. .setName("Confirm before creating new note")
  818. .setDesc("Show a confirmation modal before creating a new note")
  819. .addToggle((toggle) => {
  820. toggle.setValue(this.plugin.options.shouldConfirmBeforeCreate);
  821. toggle.onChange(async (value) => {
  822. this.plugin.writeOptions(() => ({
  823. shouldConfirmBeforeCreate: value,
  824. }));
  825. });
  826. });
  827. }
  828. addShowWeeklyNoteSetting() {
  829. new obsidian.Setting(this.containerEl)
  830. .setName("Show week number")
  831. .setDesc("Enable this to add a column with the week number")
  832. .addToggle((toggle) => {
  833. toggle.setValue(this.plugin.options.showWeeklyNote);
  834. toggle.onChange(async (value) => {
  835. this.plugin.writeOptions(() => ({ showWeeklyNote: value }));
  836. this.display(); // show/hide weekly settings
  837. });
  838. });
  839. }
  840. addWeeklyNoteFormatSetting() {
  841. new obsidian.Setting(this.containerEl)
  842. .setName("Weekly note format")
  843. .setDesc("For more syntax help, refer to format reference")
  844. .addText((textfield) => {
  845. textfield.setValue(this.plugin.options.weeklyNoteFormat);
  846. textfield.setPlaceholder(DEFAULT_WEEK_FORMAT);
  847. textfield.onChange(async (value) => {
  848. this.plugin.writeOptions(() => ({ weeklyNoteFormat: value }));
  849. });
  850. });
  851. }
  852. addWeeklyNoteTemplateSetting() {
  853. new obsidian.Setting(this.containerEl)
  854. .setName("Weekly note template")
  855. .setDesc("Choose the file you want to use as the template for your weekly notes")
  856. .addText((textfield) => {
  857. textfield.setValue(this.plugin.options.weeklyNoteTemplate);
  858. textfield.onChange(async (value) => {
  859. this.plugin.writeOptions(() => ({ weeklyNoteTemplate: value }));
  860. });
  861. });
  862. }
  863. addWeeklyNoteFolderSetting() {
  864. new obsidian.Setting(this.containerEl)
  865. .setName("Weekly note folder")
  866. .setDesc("New weekly notes will be placed here")
  867. .addText((textfield) => {
  868. textfield.setValue(this.plugin.options.weeklyNoteFolder);
  869. textfield.onChange(async (value) => {
  870. this.plugin.writeOptions(() => ({ weeklyNoteFolder: value }));
  871. });
  872. });
  873. }
  874. addLocaleOverrideSetting() {
  875. var _a;
  876. const { moment } = window;
  877. const sysLocale = (_a = navigator.language) === null || _a === void 0 ? void 0 : _a.toLowerCase();
  878. new obsidian.Setting(this.containerEl)
  879. .setName("Override locale:")
  880. .setDesc("Set this if you want to use a locale different from the default")
  881. .addDropdown((dropdown) => {
  882. dropdown.addOption("system-default", `Same as system (${sysLocale})`);
  883. moment.locales().forEach((locale) => {
  884. dropdown.addOption(locale, locale);
  885. });
  886. dropdown.setValue(this.plugin.options.localeOverride);
  887. dropdown.onChange(async (value) => {
  888. this.plugin.writeOptions(() => ({
  889. localeOverride: value,
  890. }));
  891. });
  892. });
  893. }
  894. }
  895. const classList = (obj) => {
  896. return Object.entries(obj)
  897. .filter(([_k, v]) => !!v)
  898. .map(([k, _k]) => k);
  899. };
  900. function clamp(num, lowerBound, upperBound) {
  901. return Math.min(Math.max(lowerBound, num), upperBound);
  902. }
  903. function partition(arr, predicate) {
  904. const pass = [];
  905. const fail = [];
  906. arr.forEach((elem) => {
  907. if (predicate(elem)) {
  908. pass.push(elem);
  909. }
  910. else {
  911. fail.push(elem);
  912. }
  913. });
  914. return [pass, fail];
  915. }
  916. /**
  917. * Lookup the dateUID for a given file. It compares the filename
  918. * to the daily and weekly note formats to find a match.
  919. *
  920. * @param file
  921. */
  922. function getDateUIDFromFile(file) {
  923. if (!file) {
  924. return null;
  925. }
  926. // TODO: I'm not checking the path!
  927. let date = getDateFromFile_1(file, "day");
  928. if (date) {
  929. return getDateUID_1$1(date, "day");
  930. }
  931. date = getDateFromFile_1(file, "week");
  932. if (date) {
  933. return getDateUID_1$1(date, "week");
  934. }
  935. return null;
  936. }
  937. function getWordCount(text) {
  938. const spaceDelimitedChars = /A-Za-z\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC/
  939. .source;
  940. const nonSpaceDelimitedWords = /\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u4E00-\u9FD5/
  941. .source;
  942. const pattern = new RegExp([
  943. `(?:[0-9]+(?:(?:,|\\.)[0-9]+)*|[\\-${spaceDelimitedChars}])+`,
  944. nonSpaceDelimitedWords,
  945. ].join("|"), "g");
  946. return (text.match(pattern) || []).length;
  947. }
  948. function createDailyNotesStore() {
  949. let hasError = false;
  950. const store = writable(null);
  951. return Object.assign({ reindex: () => {
  952. try {
  953. const dailyNotes = getAllDailyNotes_1();
  954. store.set(dailyNotes);
  955. hasError = false;
  956. }
  957. catch (err) {
  958. if (!hasError) {
  959. // Avoid error being shown multiple times
  960. console.log("[Calendar] Failed to find daily notes folder", err);
  961. }
  962. store.set({});
  963. hasError = true;
  964. }
  965. } }, store);
  966. }
  967. function createWeeklyNotesStore() {
  968. let hasError = false;
  969. const store = writable(null);
  970. return Object.assign({ reindex: () => {
  971. try {
  972. const weeklyNotes = getAllWeeklyNotes_1();
  973. store.set(weeklyNotes);
  974. hasError = false;
  975. }
  976. catch (err) {
  977. if (!hasError) {
  978. // Avoid error being shown multiple times
  979. console.log("[Calendar] Failed to find weekly notes folder", err);
  980. }
  981. store.set({});
  982. hasError = true;
  983. }
  984. } }, store);
  985. }
  986. const settings = writable(defaultSettings);
  987. const dailyNotes = createDailyNotesStore();
  988. const weeklyNotes = createWeeklyNotesStore();
  989. function createSelectedFileStore() {
  990. const store = writable(null);
  991. return Object.assign({ setFile: (file) => {
  992. const id = getDateUIDFromFile(file);
  993. store.set(id);
  994. } }, store);
  995. }
  996. const activeFile = createSelectedFileStore();
  997. class ConfirmationModal extends obsidian.Modal {
  998. constructor(app, config) {
  999. super(app);
  1000. const { cta, onAccept, text, title } = config;
  1001. this.contentEl.createEl("h2", { text: title });
  1002. this.contentEl.createEl("p", { text });
  1003. this.contentEl.createDiv("modal-button-container", (buttonsEl) => {
  1004. buttonsEl
  1005. .createEl("button", { text: "Never mind" })
  1006. .addEventListener("click", () => this.close());
  1007. buttonsEl
  1008. .createEl("button", {
  1009. cls: "mod-cta",
  1010. text: cta,
  1011. })
  1012. .addEventListener("click", async (e) => {
  1013. await onAccept(e);
  1014. this.close();
  1015. });
  1016. });
  1017. }
  1018. }
  1019. function createConfirmationDialog({ cta, onAccept, text, title, }) {
  1020. new ConfirmationModal(window.app, { cta, onAccept, text, title }).open();
  1021. }
  1022. /**
  1023. * Create a Daily Note for a given date.
  1024. */
  1025. async function tryToCreateDailyNote(date, inNewSplit, settings, cb) {
  1026. const { workspace } = window.app;
  1027. const { format } = getDailyNoteSettings_1();
  1028. const filename = date.format(format);
  1029. const createFile = async () => {
  1030. const dailyNote = await createDailyNote_1(date);
  1031. const leaf = inNewSplit
  1032. ? workspace.splitActiveLeaf()
  1033. : workspace.getUnpinnedLeaf();
  1034. await leaf.openFile(dailyNote);
  1035. cb === null || cb === void 0 ? void 0 : cb(dailyNote);
  1036. };
  1037. if (settings.shouldConfirmBeforeCreate) {
  1038. createConfirmationDialog({
  1039. cta: "Create",
  1040. onAccept: createFile,
  1041. text: `File ${filename} does not exist. Would you like to create it?`,
  1042. title: "New Daily Note",
  1043. });
  1044. }
  1045. else {
  1046. await createFile();
  1047. }
  1048. }
  1049. /**
  1050. * Create a Weekly Note for a given date.
  1051. */
  1052. async function tryToCreateWeeklyNote(date, inNewSplit, settings, cb) {
  1053. const { workspace } = window.app;
  1054. const { format } = getWeeklyNoteSettings_1();
  1055. const filename = date.format(format);
  1056. const createFile = async () => {
  1057. const dailyNote = await createWeeklyNote_1(date);
  1058. const leaf = inNewSplit
  1059. ? workspace.splitActiveLeaf()
  1060. : workspace.getUnpinnedLeaf();
  1061. await leaf.openFile(dailyNote);
  1062. cb === null || cb === void 0 ? void 0 : cb(dailyNote);
  1063. };
  1064. if (settings.shouldConfirmBeforeCreate) {
  1065. createConfirmationDialog({
  1066. cta: "Create",
  1067. onAccept: createFile,
  1068. text: `File ${filename} does not exist. Would you like to create it?`,
  1069. title: "New Weekly Note",
  1070. });
  1071. }
  1072. else {
  1073. await createFile();
  1074. }
  1075. }
  1076. function noop() { }
  1077. function assign(tar, src) {
  1078. // @ts-ignore
  1079. for (const k in src)
  1080. tar[k] = src[k];
  1081. return tar;
  1082. }
  1083. function is_promise(value) {
  1084. return value && typeof value === 'object' && typeof value.then === 'function';
  1085. }
  1086. function run(fn) {
  1087. return fn();
  1088. }
  1089. function blank_object() {
  1090. return Object.create(null);
  1091. }
  1092. function run_all(fns) {
  1093. fns.forEach(run);
  1094. }
  1095. function is_function(thing) {
  1096. return typeof thing === 'function';
  1097. }
  1098. function safe_not_equal(a, b) {
  1099. return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
  1100. }
  1101. function not_equal(a, b) {
  1102. return a != a ? b == b : a !== b;
  1103. }
  1104. function is_empty(obj) {
  1105. return Object.keys(obj).length === 0;
  1106. }
  1107. function create_slot(definition, ctx, $$scope, fn) {
  1108. if (definition) {
  1109. const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
  1110. return definition[0](slot_ctx);
  1111. }
  1112. }
  1113. function get_slot_context(definition, ctx, $$scope, fn) {
  1114. return definition[1] && fn
  1115. ? assign($$scope.ctx.slice(), definition[1](fn(ctx)))
  1116. : $$scope.ctx;
  1117. }
  1118. function get_slot_changes(definition, $$scope, dirty, fn) {
  1119. if (definition[2] && fn) {
  1120. const lets = definition[2](fn(dirty));
  1121. if ($$scope.dirty === undefined) {
  1122. return lets;
  1123. }
  1124. if (typeof lets === 'object') {
  1125. const merged = [];
  1126. const len = Math.max($$scope.dirty.length, lets.length);
  1127. for (let i = 0; i < len; i += 1) {
  1128. merged[i] = $$scope.dirty[i] | lets[i];
  1129. }
  1130. return merged;
  1131. }
  1132. return $$scope.dirty | lets;
  1133. }
  1134. return $$scope.dirty;
  1135. }
  1136. function update_slot(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_context_fn) {
  1137. const slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn);
  1138. if (slot_changes) {
  1139. const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
  1140. slot.p(slot_context, slot_changes);
  1141. }
  1142. }
  1143. function null_to_empty(value) {
  1144. return value == null ? '' : value;
  1145. }
  1146. function append(target, node) {
  1147. target.appendChild(node);
  1148. }
  1149. function insert(target, node, anchor) {
  1150. target.insertBefore(node, anchor || null);
  1151. }
  1152. function detach(node) {
  1153. node.parentNode.removeChild(node);
  1154. }
  1155. function destroy_each(iterations, detaching) {
  1156. for (let i = 0; i < iterations.length; i += 1) {
  1157. if (iterations[i])
  1158. iterations[i].d(detaching);
  1159. }
  1160. }
  1161. function element(name) {
  1162. return document.createElement(name);
  1163. }
  1164. function svg_element(name) {
  1165. return document.createElementNS('http://www.w3.org/2000/svg', name);
  1166. }
  1167. function text(data) {
  1168. return document.createTextNode(data);
  1169. }
  1170. function space() {
  1171. return text(' ');
  1172. }
  1173. function empty() {
  1174. return text('');
  1175. }
  1176. function listen(node, event, handler, options) {
  1177. node.addEventListener(event, handler, options);
  1178. return () => node.removeEventListener(event, handler, options);
  1179. }
  1180. function attr(node, attribute, value) {
  1181. if (value == null)
  1182. node.removeAttribute(attribute);
  1183. else if (node.getAttribute(attribute) !== value)
  1184. node.setAttribute(attribute, value);
  1185. }
  1186. function set_attributes(node, attributes) {
  1187. // @ts-ignore
  1188. const descriptors = Object.getOwnPropertyDescriptors(node.__proto__);
  1189. for (const key in attributes) {
  1190. if (attributes[key] == null) {
  1191. node.removeAttribute(key);
  1192. }
  1193. else if (key === 'style') {
  1194. node.style.cssText = attributes[key];
  1195. }
  1196. else if (key === '__value') {
  1197. node.value = node[key] = attributes[key];
  1198. }
  1199. else if (descriptors[key] && descriptors[key].set) {
  1200. node[key] = attributes[key];
  1201. }
  1202. else {
  1203. attr(node, key, attributes[key]);
  1204. }
  1205. }
  1206. }
  1207. function children(element) {
  1208. return Array.from(element.childNodes);
  1209. }
  1210. function set_data(text, data) {
  1211. data = '' + data;
  1212. if (text.wholeText !== data)
  1213. text.data = data;
  1214. }
  1215. function toggle_class(element, name, toggle) {
  1216. element.classList[toggle ? 'add' : 'remove'](name);
  1217. }
  1218. let current_component;
  1219. function set_current_component(component) {
  1220. current_component = component;
  1221. }
  1222. function get_current_component() {
  1223. if (!current_component)
  1224. throw new Error('Function called outside component initialization');
  1225. return current_component;
  1226. }
  1227. const dirty_components = [];
  1228. const binding_callbacks = [];
  1229. const render_callbacks = [];
  1230. const flush_callbacks = [];
  1231. const resolved_promise = Promise.resolve();
  1232. let update_scheduled = false;
  1233. function schedule_update() {
  1234. if (!update_scheduled) {
  1235. update_scheduled = true;
  1236. resolved_promise.then(flush);
  1237. }
  1238. }
  1239. function add_render_callback(fn) {
  1240. render_callbacks.push(fn);
  1241. }
  1242. let flushing = false;
  1243. const seen_callbacks = new Set();
  1244. function flush() {
  1245. if (flushing)
  1246. return;
  1247. flushing = true;
  1248. do {
  1249. // first, call beforeUpdate functions
  1250. // and update components
  1251. for (let i = 0; i < dirty_components.length; i += 1) {
  1252. const component = dirty_components[i];
  1253. set_current_component(component);
  1254. update(component.$$);
  1255. }
  1256. set_current_component(null);
  1257. dirty_components.length = 0;
  1258. while (binding_callbacks.length)
  1259. binding_callbacks.pop()();
  1260. // then, once components are updated, call
  1261. // afterUpdate functions. This may cause
  1262. // subsequent updates...
  1263. for (let i = 0; i < render_callbacks.length; i += 1) {
  1264. const callback = render_callbacks[i];
  1265. if (!seen_callbacks.has(callback)) {
  1266. // ...so guard against infinite loops
  1267. seen_callbacks.add(callback);
  1268. callback();
  1269. }
  1270. }
  1271. render_callbacks.length = 0;
  1272. } while (dirty_components.length);
  1273. while (flush_callbacks.length) {
  1274. flush_callbacks.pop()();
  1275. }
  1276. update_scheduled = false;
  1277. flushing = false;
  1278. seen_callbacks.clear();
  1279. }
  1280. function update($$) {
  1281. if ($$.fragment !== null) {
  1282. $$.update();
  1283. run_all($$.before_update);
  1284. const dirty = $$.dirty;
  1285. $$.dirty = [-1];
  1286. $$.fragment && $$.fragment.p($$.ctx, dirty);
  1287. $$.after_update.forEach(add_render_callback);
  1288. }
  1289. }
  1290. const outroing = new Set();
  1291. let outros;
  1292. function group_outros() {
  1293. outros = {
  1294. r: 0,
  1295. c: [],
  1296. p: outros // parent group
  1297. };
  1298. }
  1299. function check_outros() {
  1300. if (!outros.r) {
  1301. run_all(outros.c);
  1302. }
  1303. outros = outros.p;
  1304. }
  1305. function transition_in(block, local) {
  1306. if (block && block.i) {
  1307. outroing.delete(block);
  1308. block.i(local);
  1309. }
  1310. }
  1311. function transition_out(block, local, detach, callback) {
  1312. if (block && block.o) {
  1313. if (outroing.has(block))
  1314. return;
  1315. outroing.add(block);
  1316. outros.c.push(() => {
  1317. outroing.delete(block);
  1318. if (callback) {
  1319. if (detach)
  1320. block.d(1);
  1321. callback();
  1322. }
  1323. });
  1324. block.o(local);
  1325. }
  1326. }
  1327. function handle_promise(promise, info) {
  1328. const token = info.token = {};
  1329. function update(type, index, key, value) {
  1330. if (info.token !== token)
  1331. return;
  1332. info.resolved = value;
  1333. let child_ctx = info.ctx;
  1334. if (key !== undefined) {
  1335. child_ctx = child_ctx.slice();
  1336. child_ctx[key] = value;
  1337. }
  1338. const block = type && (info.current = type)(child_ctx);
  1339. let needs_flush = false;
  1340. if (info.block) {
  1341. if (info.blocks) {
  1342. info.blocks.forEach((block, i) => {
  1343. if (i !== index && block) {
  1344. group_outros();
  1345. transition_out(block, 1, 1, () => {
  1346. if (info.blocks[i] === block) {
  1347. info.blocks[i] = null;
  1348. }
  1349. });
  1350. check_outros();
  1351. }
  1352. });
  1353. }
  1354. else {
  1355. info.block.d(1);
  1356. }
  1357. block.c();
  1358. transition_in(block, 1);
  1359. block.m(info.mount(), info.anchor);
  1360. needs_flush = true;
  1361. }
  1362. info.block = block;
  1363. if (info.blocks)
  1364. info.blocks[index] = block;
  1365. if (needs_flush) {
  1366. flush();
  1367. }
  1368. }
  1369. if (is_promise(promise)) {
  1370. const current_component = get_current_component();
  1371. promise.then(value => {
  1372. set_current_component(current_component);
  1373. update(info.then, 1, info.value, value);
  1374. set_current_component(null);
  1375. }, error => {
  1376. set_current_component(current_component);
  1377. update(info.catch, 2, info.error, error);
  1378. set_current_component(null);
  1379. if (!info.hasCatch) {
  1380. throw error;
  1381. }
  1382. });
  1383. // if we previously had a then/catch block, destroy it
  1384. if (info.current !== info.pending) {
  1385. update(info.pending, 0);
  1386. return true;
  1387. }
  1388. }
  1389. else {
  1390. if (info.current !== info.then) {
  1391. update(info.then, 1, info.value, promise);
  1392. return true;
  1393. }
  1394. info.resolved = promise;
  1395. }
  1396. }
  1397. function outro_and_destroy_block(block, lookup) {
  1398. transition_out(block, 1, 1, () => {
  1399. lookup.delete(block.key);
  1400. });
  1401. }
  1402. function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, next, get_context) {
  1403. let o = old_blocks.length;
  1404. let n = list.length;
  1405. let i = o;
  1406. const old_indexes = {};
  1407. while (i--)
  1408. old_indexes[old_blocks[i].key] = i;
  1409. const new_blocks = [];
  1410. const new_lookup = new Map();
  1411. const deltas = new Map();
  1412. i = n;
  1413. while (i--) {
  1414. const child_ctx = get_context(ctx, list, i);
  1415. const key = get_key(child_ctx);
  1416. let block = lookup.get(key);
  1417. if (!block) {
  1418. block = create_each_block(key, child_ctx);
  1419. block.c();
  1420. }
  1421. else if (dynamic) {
  1422. block.p(child_ctx, dirty);
  1423. }
  1424. new_lookup.set(key, new_blocks[i] = block);
  1425. if (key in old_indexes)
  1426. deltas.set(key, Math.abs(i - old_indexes[key]));
  1427. }
  1428. const will_move = new Set();
  1429. const did_move = new Set();
  1430. function insert(block) {
  1431. transition_in(block, 1);
  1432. block.m(node, next);
  1433. lookup.set(block.key, block);
  1434. next = block.first;
  1435. n--;
  1436. }
  1437. while (o && n) {
  1438. const new_block = new_blocks[n - 1];
  1439. const old_block = old_blocks[o - 1];
  1440. const new_key = new_block.key;
  1441. const old_key = old_block.key;
  1442. if (new_block === old_block) {
  1443. // do nothing
  1444. next = new_block.first;
  1445. o--;
  1446. n--;
  1447. }
  1448. else if (!new_lookup.has(old_key)) {
  1449. // remove old block
  1450. destroy(old_block, lookup);
  1451. o--;
  1452. }
  1453. else if (!lookup.has(new_key) || will_move.has(new_key)) {
  1454. insert(new_block);
  1455. }
  1456. else if (did_move.has(old_key)) {
  1457. o--;
  1458. }
  1459. else if (deltas.get(new_key) > deltas.get(old_key)) {
  1460. did_move.add(new_key);
  1461. insert(new_block);
  1462. }
  1463. else {
  1464. will_move.add(old_key);
  1465. o--;
  1466. }
  1467. }
  1468. while (o--) {
  1469. const old_block = old_blocks[o];
  1470. if (!new_lookup.has(old_block.key))
  1471. destroy(old_block, lookup);
  1472. }
  1473. while (n)
  1474. insert(new_blocks[n - 1]);
  1475. return new_blocks;
  1476. }
  1477. function get_spread_update(levels, updates) {
  1478. const update = {};
  1479. const to_null_out = {};
  1480. const accounted_for = { $$scope: 1 };
  1481. let i = levels.length;
  1482. while (i--) {
  1483. const o = levels[i];
  1484. const n = updates[i];
  1485. if (n) {
  1486. for (const key in o) {
  1487. if (!(key in n))
  1488. to_null_out[key] = 1;
  1489. }
  1490. for (const key in n) {
  1491. if (!accounted_for[key]) {
  1492. update[key] = n[key];
  1493. accounted_for[key] = 1;
  1494. }
  1495. }
  1496. levels[i] = n;
  1497. }
  1498. else {
  1499. for (const key in o) {
  1500. accounted_for[key] = 1;
  1501. }
  1502. }
  1503. }
  1504. for (const key in to_null_out) {
  1505. if (!(key in update))
  1506. update[key] = undefined;
  1507. }
  1508. return update;
  1509. }
  1510. function get_spread_object(spread_props) {
  1511. return typeof spread_props === 'object' && spread_props !== null ? spread_props : {};
  1512. }
  1513. function create_component(block) {
  1514. block && block.c();
  1515. }
  1516. function mount_component(component, target, anchor, customElement) {
  1517. const { fragment, on_mount, on_destroy, after_update } = component.$$;
  1518. fragment && fragment.m(target, anchor);
  1519. if (!customElement) {
  1520. // onMount happens before the initial afterUpdate
  1521. add_render_callback(() => {
  1522. const new_on_destroy = on_mount.map(run).filter(is_function);
  1523. if (on_destroy) {
  1524. on_destroy.push(...new_on_destroy);
  1525. }
  1526. else {
  1527. // Edge case - component was destroyed immediately,
  1528. // most likely as a result of a binding initialising
  1529. run_all(new_on_destroy);
  1530. }
  1531. component.$$.on_mount = [];
  1532. });
  1533. }
  1534. after_update.forEach(add_render_callback);
  1535. }
  1536. function destroy_component(component, detaching) {
  1537. const $$ = component.$$;
  1538. if ($$.fragment !== null) {
  1539. run_all($$.on_destroy);
  1540. $$.fragment && $$.fragment.d(detaching);
  1541. // TODO null out other refs, including component.$$ (but need to
  1542. // preserve final state?)
  1543. $$.on_destroy = $$.fragment = null;
  1544. $$.ctx = [];
  1545. }
  1546. }
  1547. function make_dirty(component, i) {
  1548. if (component.$$.dirty[0] === -1) {
  1549. dirty_components.push(component);
  1550. schedule_update();
  1551. component.$$.dirty.fill(0);
  1552. }
  1553. component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
  1554. }
  1555. function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
  1556. const parent_component = current_component;
  1557. set_current_component(component);
  1558. const $$ = component.$$ = {
  1559. fragment: null,
  1560. ctx: null,
  1561. // state
  1562. props,
  1563. update: noop,
  1564. not_equal,
  1565. bound: blank_object(),
  1566. // lifecycle
  1567. on_mount: [],
  1568. on_destroy: [],
  1569. on_disconnect: [],
  1570. before_update: [],
  1571. after_update: [],
  1572. context: new Map(parent_component ? parent_component.$$.context : []),
  1573. // everything else
  1574. callbacks: blank_object(),
  1575. dirty,
  1576. skip_bound: false
  1577. };
  1578. let ready = false;
  1579. $$.ctx = instance
  1580. ? instance(component, options.props || {}, (i, ret, ...rest) => {
  1581. const value = rest.length ? rest[0] : ret;
  1582. if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
  1583. if (!$$.skip_bound && $$.bound[i])
  1584. $$.bound[i](value);
  1585. if (ready)
  1586. make_dirty(component, i);
  1587. }
  1588. return ret;
  1589. })
  1590. : [];
  1591. $$.update();
  1592. ready = true;
  1593. run_all($$.before_update);
  1594. // `false` as a special case of no DOM component
  1595. $$.fragment = create_fragment ? create_fragment($$.ctx) : false;
  1596. if (options.target) {
  1597. if (options.hydrate) {
  1598. const nodes = children(options.target);
  1599. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  1600. $$.fragment && $$.fragment.l(nodes);
  1601. nodes.forEach(detach);
  1602. }
  1603. else {
  1604. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  1605. $$.fragment && $$.fragment.c();
  1606. }
  1607. if (options.intro)
  1608. transition_in(component.$$.fragment);
  1609. mount_component(component, options.target, options.anchor, options.customElement);
  1610. flush();
  1611. }
  1612. set_current_component(parent_component);
  1613. }
  1614. /**
  1615. * Base class for Svelte components. Used when dev=false.
  1616. */
  1617. class SvelteComponent {
  1618. $destroy() {
  1619. destroy_component(this, 1);
  1620. this.$destroy = noop;
  1621. }
  1622. $on(type, callback) {
  1623. const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
  1624. callbacks.push(callback);
  1625. return () => {
  1626. const index = callbacks.indexOf(callback);
  1627. if (index !== -1)
  1628. callbacks.splice(index, 1);
  1629. };
  1630. }
  1631. $set($$props) {
  1632. if (this.$$set && !is_empty($$props)) {
  1633. this.$$.skip_bound = true;
  1634. this.$$set($$props);
  1635. this.$$.skip_bound = false;
  1636. }
  1637. }
  1638. }
  1639. /**
  1640. * dateUID is a way of weekly identifying daily/weekly/monthly notes.
  1641. * They are prefixed with the granularity to avoid ambiguity.
  1642. */
  1643. function getDateUID(date, granularity = "day") {
  1644. const ts = date.clone().startOf(granularity).format();
  1645. return `${granularity}-${ts}`;
  1646. }
  1647. var getDateUID_1 = getDateUID;
  1648. /* src/components/Dot.svelte generated by Svelte v3.35.0 */
  1649. function add_css$5() {
  1650. var style = element("style");
  1651. style.id = "svelte-1widvzq-style";
  1652. style.textContent = ".dot.svelte-1widvzq,.hollow.svelte-1widvzq{display:inline-block;height:6px;width:6px;margin:0 1px}.filled.svelte-1widvzq{fill:var(--color-dot)}.active.filled.svelte-1widvzq{fill:var(--text-on-accent)}.hollow.svelte-1widvzq{fill:none;stroke:var(--color-dot)}.active.hollow.svelte-1widvzq{fill:none;stroke:var(--text-on-accent)}";
  1653. append(document.head, style);
  1654. }
  1655. // (14:0) {:else}
  1656. function create_else_block$1(ctx) {
  1657. let svg;
  1658. let circle;
  1659. let svg_class_value;
  1660. return {
  1661. c() {
  1662. svg = svg_element("svg");
  1663. circle = svg_element("circle");
  1664. attr(circle, "cx", "3");
  1665. attr(circle, "cy", "3");
  1666. attr(circle, "r", "2");
  1667. attr(svg, "class", svg_class_value = "" + (null_to_empty(`hollow ${/*className*/ ctx[0]}`) + " svelte-1widvzq"));
  1668. attr(svg, "viewBox", "0 0 6 6");
  1669. attr(svg, "xmlns", "http://www.w3.org/2000/svg");
  1670. toggle_class(svg, "active", /*isActive*/ ctx[2]);
  1671. },
  1672. m(target, anchor) {
  1673. insert(target, svg, anchor);
  1674. append(svg, circle);
  1675. },
  1676. p(ctx, dirty) {
  1677. if (dirty & /*className*/ 1 && svg_class_value !== (svg_class_value = "" + (null_to_empty(`hollow ${/*className*/ ctx[0]}`) + " svelte-1widvzq"))) {
  1678. attr(svg, "class", svg_class_value);
  1679. }
  1680. if (dirty & /*className, isActive*/ 5) {
  1681. toggle_class(svg, "active", /*isActive*/ ctx[2]);
  1682. }
  1683. },
  1684. d(detaching) {
  1685. if (detaching) detach(svg);
  1686. }
  1687. };
  1688. }
  1689. // (6:0) {#if isFilled}
  1690. function create_if_block$2(ctx) {
  1691. let svg;
  1692. let circle;
  1693. let svg_class_value;
  1694. return {
  1695. c() {
  1696. svg = svg_element("svg");
  1697. circle = svg_element("circle");
  1698. attr(circle, "cx", "3");
  1699. attr(circle, "cy", "3");
  1700. attr(circle, "r", "2");
  1701. attr(svg, "class", svg_class_value = "" + (null_to_empty(`dot filled ${/*className*/ ctx[0]}`) + " svelte-1widvzq"));
  1702. attr(svg, "viewBox", "0 0 6 6");
  1703. attr(svg, "xmlns", "http://www.w3.org/2000/svg");
  1704. toggle_class(svg, "active", /*isActive*/ ctx[2]);
  1705. },
  1706. m(target, anchor) {
  1707. insert(target, svg, anchor);
  1708. append(svg, circle);
  1709. },
  1710. p(ctx, dirty) {
  1711. if (dirty & /*className*/ 1 && svg_class_value !== (svg_class_value = "" + (null_to_empty(`dot filled ${/*className*/ ctx[0]}`) + " svelte-1widvzq"))) {
  1712. attr(svg, "class", svg_class_value);
  1713. }
  1714. if (dirty & /*className, isActive*/ 5) {
  1715. toggle_class(svg, "active", /*isActive*/ ctx[2]);
  1716. }
  1717. },
  1718. d(detaching) {
  1719. if (detaching) detach(svg);
  1720. }
  1721. };
  1722. }
  1723. function create_fragment$6(ctx) {
  1724. let if_block_anchor;
  1725. function select_block_type(ctx, dirty) {
  1726. if (/*isFilled*/ ctx[1]) return create_if_block$2;
  1727. return create_else_block$1;
  1728. }
  1729. let current_block_type = select_block_type(ctx);
  1730. let if_block = current_block_type(ctx);
  1731. return {
  1732. c() {
  1733. if_block.c();
  1734. if_block_anchor = empty();
  1735. },
  1736. m(target, anchor) {
  1737. if_block.m(target, anchor);
  1738. insert(target, if_block_anchor, anchor);
  1739. },
  1740. p(ctx, [dirty]) {
  1741. if (current_block_type === (current_block_type = select_block_type(ctx)) && if_block) {
  1742. if_block.p(ctx, dirty);
  1743. } else {
  1744. if_block.d(1);
  1745. if_block = current_block_type(ctx);
  1746. if (if_block) {
  1747. if_block.c();
  1748. if_block.m(if_block_anchor.parentNode, if_block_anchor);
  1749. }
  1750. }
  1751. },
  1752. i: noop,
  1753. o: noop,
  1754. d(detaching) {
  1755. if_block.d(detaching);
  1756. if (detaching) detach(if_block_anchor);
  1757. }
  1758. };
  1759. }
  1760. function instance$6($$self, $$props, $$invalidate) {
  1761. let { className = "" } = $$props;
  1762. let { isFilled } = $$props;
  1763. let { isActive } = $$props;
  1764. $$self.$$set = $$props => {
  1765. if ("className" in $$props) $$invalidate(0, className = $$props.className);
  1766. if ("isFilled" in $$props) $$invalidate(1, isFilled = $$props.isFilled);
  1767. if ("isActive" in $$props) $$invalidate(2, isActive = $$props.isActive);
  1768. };
  1769. return [className, isFilled, isActive];
  1770. }
  1771. class Dot extends SvelteComponent {
  1772. constructor(options) {
  1773. super();
  1774. if (!document.getElementById("svelte-1widvzq-style")) add_css$5();
  1775. init(this, options, instance$6, create_fragment$6, safe_not_equal, { className: 0, isFilled: 1, isActive: 2 });
  1776. }
  1777. }
  1778. /* src/components/MetadataResolver.svelte generated by Svelte v3.35.0 */
  1779. const get_default_slot_changes_1 = dirty => ({});
  1780. const get_default_slot_context_1 = ctx => ({ metadata: null });
  1781. const get_default_slot_changes = dirty => ({ metadata: dirty & /*metadata*/ 1 });
  1782. const get_default_slot_context = ctx => ({ metadata: /*resolvedMeta*/ ctx[3] });
  1783. // (11:0) {:else}
  1784. function create_else_block(ctx) {
  1785. let current;
  1786. const default_slot_template = /*#slots*/ ctx[2].default;
  1787. const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[1], get_default_slot_context_1);
  1788. return {
  1789. c() {
  1790. if (default_slot) default_slot.c();
  1791. },
  1792. m(target, anchor) {
  1793. if (default_slot) {
  1794. default_slot.m(target, anchor);
  1795. }
  1796. current = true;
  1797. },
  1798. p(ctx, dirty) {
  1799. if (default_slot) {
  1800. if (default_slot.p && dirty & /*$$scope*/ 2) {
  1801. update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[1], dirty, get_default_slot_changes_1, get_default_slot_context_1);
  1802. }
  1803. }
  1804. },
  1805. i(local) {
  1806. if (current) return;
  1807. transition_in(default_slot, local);
  1808. current = true;
  1809. },
  1810. o(local) {
  1811. transition_out(default_slot, local);
  1812. current = false;
  1813. },
  1814. d(detaching) {
  1815. if (default_slot) default_slot.d(detaching);
  1816. }
  1817. };
  1818. }
  1819. // (7:0) {#if metadata}
  1820. function create_if_block$1(ctx) {
  1821. let await_block_anchor;
  1822. let promise;
  1823. let current;
  1824. let info = {
  1825. ctx,
  1826. current: null,
  1827. token: null,
  1828. hasCatch: false,
  1829. pending: create_pending_block,
  1830. then: create_then_block,
  1831. catch: create_catch_block,
  1832. value: 3,
  1833. blocks: [,,,]
  1834. };
  1835. handle_promise(promise = /*metadata*/ ctx[0], info);
  1836. return {
  1837. c() {
  1838. await_block_anchor = empty();
  1839. info.block.c();
  1840. },
  1841. m(target, anchor) {
  1842. insert(target, await_block_anchor, anchor);
  1843. info.block.m(target, info.anchor = anchor);
  1844. info.mount = () => await_block_anchor.parentNode;
  1845. info.anchor = await_block_anchor;
  1846. current = true;
  1847. },
  1848. p(new_ctx, dirty) {
  1849. ctx = new_ctx;
  1850. info.ctx = ctx;
  1851. if (dirty & /*metadata*/ 1 && promise !== (promise = /*metadata*/ ctx[0]) && handle_promise(promise, info)) ; else {
  1852. const child_ctx = ctx.slice();
  1853. child_ctx[3] = info.resolved;
  1854. info.block.p(child_ctx, dirty);
  1855. }
  1856. },
  1857. i(local) {
  1858. if (current) return;
  1859. transition_in(info.block);
  1860. current = true;
  1861. },
  1862. o(local) {
  1863. for (let i = 0; i < 3; i += 1) {
  1864. const block = info.blocks[i];
  1865. transition_out(block);
  1866. }
  1867. current = false;
  1868. },
  1869. d(detaching) {
  1870. if (detaching) detach(await_block_anchor);
  1871. info.block.d(detaching);
  1872. info.token = null;
  1873. info = null;
  1874. }
  1875. };
  1876. }
  1877. // (1:0) <svelte:options immutable /> <script lang="ts">; export let metadata; </script> {#if metadata}
  1878. function create_catch_block(ctx) {
  1879. return {
  1880. c: noop,
  1881. m: noop,
  1882. p: noop,
  1883. i: noop,
  1884. o: noop,
  1885. d: noop
  1886. };
  1887. }
  1888. // (8:37) <slot metadata="{resolvedMeta}
  1889. function create_then_block(ctx) {
  1890. let current;
  1891. const default_slot_template = /*#slots*/ ctx[2].default;
  1892. const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[1], get_default_slot_context);
  1893. return {
  1894. c() {
  1895. if (default_slot) default_slot.c();
  1896. },
  1897. m(target, anchor) {
  1898. if (default_slot) {
  1899. default_slot.m(target, anchor);
  1900. }
  1901. current = true;
  1902. },
  1903. p(ctx, dirty) {
  1904. if (default_slot) {
  1905. if (default_slot.p && dirty & /*$$scope, metadata*/ 3) {
  1906. update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[1], dirty, get_default_slot_changes, get_default_slot_context);
  1907. }
  1908. }
  1909. },
  1910. i(local) {
  1911. if (current) return;
  1912. transition_in(default_slot, local);
  1913. current = true;
  1914. },
  1915. o(local) {
  1916. transition_out(default_slot, local);
  1917. current = false;
  1918. },
  1919. d(detaching) {
  1920. if (default_slot) default_slot.d(detaching);
  1921. }
  1922. };
  1923. }
  1924. // (1:0) <svelte:options immutable /> <script lang="ts">; export let metadata; </script> {#if metadata}
  1925. function create_pending_block(ctx) {
  1926. return {
  1927. c: noop,
  1928. m: noop,
  1929. p: noop,
  1930. i: noop,
  1931. o: noop,
  1932. d: noop
  1933. };
  1934. }
  1935. function create_fragment$5(ctx) {
  1936. let current_block_type_index;
  1937. let if_block;
  1938. let if_block_anchor;
  1939. let current;
  1940. const if_block_creators = [create_if_block$1, create_else_block];
  1941. const if_blocks = [];
  1942. function select_block_type(ctx, dirty) {
  1943. if (/*metadata*/ ctx[0]) return 0;
  1944. return 1;
  1945. }
  1946. current_block_type_index = select_block_type(ctx);
  1947. if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
  1948. return {
  1949. c() {
  1950. if_block.c();
  1951. if_block_anchor = empty();
  1952. },
  1953. m(target, anchor) {
  1954. if_blocks[current_block_type_index].m(target, anchor);
  1955. insert(target, if_block_anchor, anchor);
  1956. current = true;
  1957. },
  1958. p(ctx, [dirty]) {
  1959. let previous_block_index = current_block_type_index;
  1960. current_block_type_index = select_block_type(ctx);
  1961. if (current_block_type_index === previous_block_index) {
  1962. if_blocks[current_block_type_index].p(ctx, dirty);
  1963. } else {
  1964. group_outros();
  1965. transition_out(if_blocks[previous_block_index], 1, 1, () => {
  1966. if_blocks[previous_block_index] = null;
  1967. });
  1968. check_outros();
  1969. if_block = if_blocks[current_block_type_index];
  1970. if (!if_block) {
  1971. if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
  1972. if_block.c();
  1973. } else {
  1974. if_block.p(ctx, dirty);
  1975. }
  1976. transition_in(if_block, 1);
  1977. if_block.m(if_block_anchor.parentNode, if_block_anchor);
  1978. }
  1979. },
  1980. i(local) {
  1981. if (current) return;
  1982. transition_in(if_block);
  1983. current = true;
  1984. },
  1985. o(local) {
  1986. transition_out(if_block);
  1987. current = false;
  1988. },
  1989. d(detaching) {
  1990. if_blocks[current_block_type_index].d(detaching);
  1991. if (detaching) detach(if_block_anchor);
  1992. }
  1993. };
  1994. }
  1995. function instance$5($$self, $$props, $$invalidate) {
  1996. let { $$slots: slots = {}, $$scope } = $$props;
  1997. let { metadata } = $$props;
  1998. $$self.$$set = $$props => {
  1999. if ("metadata" in $$props) $$invalidate(0, metadata = $$props.metadata);
  2000. if ("$$scope" in $$props) $$invalidate(1, $$scope = $$props.$$scope);
  2001. };
  2002. return [metadata, $$scope, slots];
  2003. }
  2004. class MetadataResolver extends SvelteComponent {
  2005. constructor(options) {
  2006. super();
  2007. init(this, options, instance$5, create_fragment$5, not_equal, { metadata: 0 });
  2008. }
  2009. }
  2010. function isMacOS() {
  2011. return navigator.appVersion.indexOf("Mac") !== -1;
  2012. }
  2013. function isMetaPressed(e) {
  2014. return isMacOS() ? e.metaKey : e.ctrlKey;
  2015. }
  2016. function getDaysOfWeek(..._args) {
  2017. return window.moment.weekdaysShort(true);
  2018. }
  2019. function isWeekend(date) {
  2020. return date.isoWeekday() === 6 || date.isoWeekday() === 7;
  2021. }
  2022. function getStartOfWeek(days) {
  2023. return days[0].weekday(0);
  2024. }
  2025. /**
  2026. * Generate a 2D array of daily information to power
  2027. * the calendar view.
  2028. */
  2029. function getMonth(displayedMonth, ..._args) {
  2030. const locale = window.moment().locale();
  2031. const month = [];
  2032. let week;
  2033. const startOfMonth = displayedMonth.clone().locale(locale).date(1);
  2034. const startOffset = startOfMonth.weekday();
  2035. let date = startOfMonth.clone().subtract(startOffset, "days");
  2036. for (let _day = 0; _day < 42; _day++) {
  2037. if (_day % 7 === 0) {
  2038. week = {
  2039. days: [],
  2040. weekNum: date.week(),
  2041. };
  2042. month.push(week);
  2043. }
  2044. week.days.push(date);
  2045. date = date.clone().add(1, "days");
  2046. }
  2047. return month;
  2048. }
  2049. /* src/components/Day.svelte generated by Svelte v3.35.0 */
  2050. function add_css$4() {
  2051. var style = element("style");
  2052. style.id = "svelte-q3wqg9-style";
  2053. style.textContent = ".day.svelte-q3wqg9{background-color:var(--color-background-day);border-radius:4px;color:var(--color-text-day);cursor:pointer;font-size:0.8em;height:100%;padding:4px;position:relative;text-align:center;transition:background-color 0.1s ease-in, color 0.1s ease-in;vertical-align:baseline}.day.svelte-q3wqg9:hover{background-color:var(--interactive-hover)}.day.active.svelte-q3wqg9:hover{background-color:var(--interactive-accent-hover)}.adjacent-month.svelte-q3wqg9{opacity:0.25}.today.svelte-q3wqg9{color:var(--color-text-today)}.day.svelte-q3wqg9:active,.active.svelte-q3wqg9,.active.today.svelte-q3wqg9{color:var(--text-on-accent);background-color:var(--interactive-accent)}.dot-container.svelte-q3wqg9{display:flex;flex-wrap:wrap;justify-content:center;line-height:6px;min-height:6px}";
  2054. append(document.head, style);
  2055. }
  2056. function get_each_context$2(ctx, list, i) {
  2057. const child_ctx = ctx.slice();
  2058. child_ctx[11] = list[i];
  2059. return child_ctx;
  2060. }
  2061. // (36:8) {#each metadata.dots as dot}
  2062. function create_each_block$2(ctx) {
  2063. let dot;
  2064. let current;
  2065. const dot_spread_levels = [/*dot*/ ctx[11]];
  2066. let dot_props = {};
  2067. for (let i = 0; i < dot_spread_levels.length; i += 1) {
  2068. dot_props = assign(dot_props, dot_spread_levels[i]);
  2069. }
  2070. dot = new Dot({ props: dot_props });
  2071. return {
  2072. c() {
  2073. create_component(dot.$$.fragment);
  2074. },
  2075. m(target, anchor) {
  2076. mount_component(dot, target, anchor);
  2077. current = true;
  2078. },
  2079. p(ctx, dirty) {
  2080. const dot_changes = (dirty & /*metadata*/ 128)
  2081. ? get_spread_update(dot_spread_levels, [get_spread_object(/*dot*/ ctx[11])])
  2082. : {};
  2083. dot.$set(dot_changes);
  2084. },
  2085. i(local) {
  2086. if (current) return;
  2087. transition_in(dot.$$.fragment, local);
  2088. current = true;
  2089. },
  2090. o(local) {
  2091. transition_out(dot.$$.fragment, local);
  2092. current = false;
  2093. },
  2094. d(detaching) {
  2095. destroy_component(dot, detaching);
  2096. }
  2097. };
  2098. }
  2099. // (22:2) <MetadataResolver metadata="{metadata}" let:metadata>
  2100. function create_default_slot$1(ctx) {
  2101. let div1;
  2102. let t0_value = /*date*/ ctx[0].format("D") + "";
  2103. let t0;
  2104. let t1;
  2105. let div0;
  2106. let div1_class_value;
  2107. let current;
  2108. let mounted;
  2109. let dispose;
  2110. let each_value = /*metadata*/ ctx[7].dots;
  2111. let each_blocks = [];
  2112. for (let i = 0; i < each_value.length; i += 1) {
  2113. each_blocks[i] = create_each_block$2(get_each_context$2(ctx, each_value, i));
  2114. }
  2115. const out = i => transition_out(each_blocks[i], 1, 1, () => {
  2116. each_blocks[i] = null;
  2117. });
  2118. let div1_levels = [
  2119. {
  2120. class: div1_class_value = `day ${/*metadata*/ ctx[7].classes.join(" ")}`
  2121. },
  2122. /*metadata*/ ctx[7].dataAttributes || {}
  2123. ];
  2124. let div1_data = {};
  2125. for (let i = 0; i < div1_levels.length; i += 1) {
  2126. div1_data = assign(div1_data, div1_levels[i]);
  2127. }
  2128. return {
  2129. c() {
  2130. div1 = element("div");
  2131. t0 = text(t0_value);
  2132. t1 = space();
  2133. div0 = element("div");
  2134. for (let i = 0; i < each_blocks.length; i += 1) {
  2135. each_blocks[i].c();
  2136. }
  2137. attr(div0, "class", "dot-container svelte-q3wqg9");
  2138. set_attributes(div1, div1_data);
  2139. toggle_class(div1, "active", /*selectedId*/ ctx[6] === getDateUID_1(/*date*/ ctx[0], "day"));
  2140. toggle_class(div1, "adjacent-month", !/*date*/ ctx[0].isSame(/*displayedMonth*/ ctx[5], "month"));
  2141. toggle_class(div1, "today", /*date*/ ctx[0].isSame(/*today*/ ctx[4], "day"));
  2142. toggle_class(div1, "svelte-q3wqg9", true);
  2143. },
  2144. m(target, anchor) {
  2145. insert(target, div1, anchor);
  2146. append(div1, t0);
  2147. append(div1, t1);
  2148. append(div1, div0);
  2149. for (let i = 0; i < each_blocks.length; i += 1) {
  2150. each_blocks[i].m(div0, null);
  2151. }
  2152. current = true;
  2153. if (!mounted) {
  2154. dispose = [
  2155. listen(div1, "click", function () {
  2156. if (is_function(/*onClick*/ ctx[2] && /*click_handler*/ ctx[8])) (/*onClick*/ ctx[2] && /*click_handler*/ ctx[8]).apply(this, arguments);
  2157. }),
  2158. listen(div1, "contextmenu", function () {
  2159. if (is_function(/*onContextMenu*/ ctx[3] && /*contextmenu_handler*/ ctx[9])) (/*onContextMenu*/ ctx[3] && /*contextmenu_handler*/ ctx[9]).apply(this, arguments);
  2160. }),
  2161. listen(div1, "pointerover", function () {
  2162. if (is_function(/*onHover*/ ctx[1] && /*pointerover_handler*/ ctx[10])) (/*onHover*/ ctx[1] && /*pointerover_handler*/ ctx[10]).apply(this, arguments);
  2163. })
  2164. ];
  2165. mounted = true;
  2166. }
  2167. },
  2168. p(new_ctx, dirty) {
  2169. ctx = new_ctx;
  2170. if ((!current || dirty & /*date*/ 1) && t0_value !== (t0_value = /*date*/ ctx[0].format("D") + "")) set_data(t0, t0_value);
  2171. if (dirty & /*metadata*/ 128) {
  2172. each_value = /*metadata*/ ctx[7].dots;
  2173. let i;
  2174. for (i = 0; i < each_value.length; i += 1) {
  2175. const child_ctx = get_each_context$2(ctx, each_value, i);
  2176. if (each_blocks[i]) {
  2177. each_blocks[i].p(child_ctx, dirty);
  2178. transition_in(each_blocks[i], 1);
  2179. } else {
  2180. each_blocks[i] = create_each_block$2(child_ctx);
  2181. each_blocks[i].c();
  2182. transition_in(each_blocks[i], 1);
  2183. each_blocks[i].m(div0, null);
  2184. }
  2185. }
  2186. group_outros();
  2187. for (i = each_value.length; i < each_blocks.length; i += 1) {
  2188. out(i);
  2189. }
  2190. check_outros();
  2191. }
  2192. set_attributes(div1, div1_data = get_spread_update(div1_levels, [
  2193. (!current || dirty & /*metadata*/ 128 && div1_class_value !== (div1_class_value = `day ${/*metadata*/ ctx[7].classes.join(" ")}`)) && { class: div1_class_value },
  2194. dirty & /*metadata*/ 128 && (/*metadata*/ ctx[7].dataAttributes || {})
  2195. ]));
  2196. toggle_class(div1, "active", /*selectedId*/ ctx[6] === getDateUID_1(/*date*/ ctx[0], "day"));
  2197. toggle_class(div1, "adjacent-month", !/*date*/ ctx[0].isSame(/*displayedMonth*/ ctx[5], "month"));
  2198. toggle_class(div1, "today", /*date*/ ctx[0].isSame(/*today*/ ctx[4], "day"));
  2199. toggle_class(div1, "svelte-q3wqg9", true);
  2200. },
  2201. i(local) {
  2202. if (current) return;
  2203. for (let i = 0; i < each_value.length; i += 1) {
  2204. transition_in(each_blocks[i]);
  2205. }
  2206. current = true;
  2207. },
  2208. o(local) {
  2209. each_blocks = each_blocks.filter(Boolean);
  2210. for (let i = 0; i < each_blocks.length; i += 1) {
  2211. transition_out(each_blocks[i]);
  2212. }
  2213. current = false;
  2214. },
  2215. d(detaching) {
  2216. if (detaching) detach(div1);
  2217. destroy_each(each_blocks, detaching);
  2218. mounted = false;
  2219. run_all(dispose);
  2220. }
  2221. };
  2222. }
  2223. function create_fragment$4(ctx) {
  2224. let td;
  2225. let metadataresolver;
  2226. let current;
  2227. metadataresolver = new MetadataResolver({
  2228. props: {
  2229. metadata: /*metadata*/ ctx[7],
  2230. $$slots: {
  2231. default: [
  2232. create_default_slot$1,
  2233. ({ metadata }) => ({ 7: metadata }),
  2234. ({ metadata }) => metadata ? 128 : 0
  2235. ]
  2236. },
  2237. $$scope: { ctx }
  2238. }
  2239. });
  2240. return {
  2241. c() {
  2242. td = element("td");
  2243. create_component(metadataresolver.$$.fragment);
  2244. },
  2245. m(target, anchor) {
  2246. insert(target, td, anchor);
  2247. mount_component(metadataresolver, td, null);
  2248. current = true;
  2249. },
  2250. p(ctx, [dirty]) {
  2251. const metadataresolver_changes = {};
  2252. if (dirty & /*metadata*/ 128) metadataresolver_changes.metadata = /*metadata*/ ctx[7];
  2253. if (dirty & /*$$scope, metadata, selectedId, date, displayedMonth, today, onClick, onContextMenu, onHover*/ 16639) {
  2254. metadataresolver_changes.$$scope = { dirty, ctx };
  2255. }
  2256. metadataresolver.$set(metadataresolver_changes);
  2257. },
  2258. i(local) {
  2259. if (current) return;
  2260. transition_in(metadataresolver.$$.fragment, local);
  2261. current = true;
  2262. },
  2263. o(local) {
  2264. transition_out(metadataresolver.$$.fragment, local);
  2265. current = false;
  2266. },
  2267. d(detaching) {
  2268. if (detaching) detach(td);
  2269. destroy_component(metadataresolver);
  2270. }
  2271. };
  2272. }
  2273. function instance$4($$self, $$props, $$invalidate) {
  2274. let { date } = $$props;
  2275. let { metadata } = $$props;
  2276. let { onHover } = $$props;
  2277. let { onClick } = $$props;
  2278. let { onContextMenu } = $$props;
  2279. let { today } = $$props;
  2280. let { displayedMonth = null } = $$props;
  2281. let { selectedId = null } = $$props;
  2282. const click_handler = e => onClick(date, isMetaPressed(e));
  2283. const contextmenu_handler = e => onContextMenu(date, e);
  2284. const pointerover_handler = e => onHover(date, e.target, isMetaPressed(e));
  2285. $$self.$$set = $$props => {
  2286. if ("date" in $$props) $$invalidate(0, date = $$props.date);
  2287. if ("metadata" in $$props) $$invalidate(7, metadata = $$props.metadata);
  2288. if ("onHover" in $$props) $$invalidate(1, onHover = $$props.onHover);
  2289. if ("onClick" in $$props) $$invalidate(2, onClick = $$props.onClick);
  2290. if ("onContextMenu" in $$props) $$invalidate(3, onContextMenu = $$props.onContextMenu);
  2291. if ("today" in $$props) $$invalidate(4, today = $$props.today);
  2292. if ("displayedMonth" in $$props) $$invalidate(5, displayedMonth = $$props.displayedMonth);
  2293. if ("selectedId" in $$props) $$invalidate(6, selectedId = $$props.selectedId);
  2294. };
  2295. return [
  2296. date,
  2297. onHover,
  2298. onClick,
  2299. onContextMenu,
  2300. today,
  2301. displayedMonth,
  2302. selectedId,
  2303. metadata,
  2304. click_handler,
  2305. contextmenu_handler,
  2306. pointerover_handler
  2307. ];
  2308. }
  2309. class Day extends SvelteComponent {
  2310. constructor(options) {
  2311. super();
  2312. if (!document.getElementById("svelte-q3wqg9-style")) add_css$4();
  2313. init(this, options, instance$4, create_fragment$4, not_equal, {
  2314. date: 0,
  2315. metadata: 7,
  2316. onHover: 1,
  2317. onClick: 2,
  2318. onContextMenu: 3,
  2319. today: 4,
  2320. displayedMonth: 5,
  2321. selectedId: 6
  2322. });
  2323. }
  2324. }
  2325. /* src/components/Arrow.svelte generated by Svelte v3.35.0 */
  2326. function add_css$3() {
  2327. var style = element("style");
  2328. style.id = "svelte-156w7na-style";
  2329. style.textContent = ".arrow.svelte-156w7na.svelte-156w7na{align-items:center;cursor:pointer;display:flex;justify-content:center;width:24px}.arrow.is-mobile.svelte-156w7na.svelte-156w7na{width:32px}.right.svelte-156w7na.svelte-156w7na{transform:rotate(180deg)}.arrow.svelte-156w7na svg.svelte-156w7na{color:var(--color-arrow);height:16px;width:16px}";
  2330. append(document.head, style);
  2331. }
  2332. function create_fragment$3(ctx) {
  2333. let div;
  2334. let svg;
  2335. let path;
  2336. let mounted;
  2337. let dispose;
  2338. return {
  2339. c() {
  2340. div = element("div");
  2341. svg = svg_element("svg");
  2342. path = svg_element("path");
  2343. attr(path, "fill", "currentColor");
  2344. attr(path, "d", "M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z");
  2345. attr(svg, "focusable", "false");
  2346. attr(svg, "role", "img");
  2347. attr(svg, "xmlns", "http://www.w3.org/2000/svg");
  2348. attr(svg, "viewBox", "0 0 320 512");
  2349. attr(svg, "class", "svelte-156w7na");
  2350. attr(div, "class", "arrow svelte-156w7na");
  2351. attr(div, "aria-label", /*tooltip*/ ctx[1]);
  2352. toggle_class(div, "is-mobile", /*isMobile*/ ctx[3]);
  2353. toggle_class(div, "right", /*direction*/ ctx[2] === "right");
  2354. },
  2355. m(target, anchor) {
  2356. insert(target, div, anchor);
  2357. append(div, svg);
  2358. append(svg, path);
  2359. if (!mounted) {
  2360. dispose = listen(div, "click", function () {
  2361. if (is_function(/*onClick*/ ctx[0])) /*onClick*/ ctx[0].apply(this, arguments);
  2362. });
  2363. mounted = true;
  2364. }
  2365. },
  2366. p(new_ctx, [dirty]) {
  2367. ctx = new_ctx;
  2368. if (dirty & /*tooltip*/ 2) {
  2369. attr(div, "aria-label", /*tooltip*/ ctx[1]);
  2370. }
  2371. if (dirty & /*direction*/ 4) {
  2372. toggle_class(div, "right", /*direction*/ ctx[2] === "right");
  2373. }
  2374. },
  2375. i: noop,
  2376. o: noop,
  2377. d(detaching) {
  2378. if (detaching) detach(div);
  2379. mounted = false;
  2380. dispose();
  2381. }
  2382. };
  2383. }
  2384. function instance$3($$self, $$props, $$invalidate) {
  2385. let { onClick } = $$props;
  2386. let { tooltip } = $$props;
  2387. let { direction } = $$props;
  2388. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2389. let isMobile = window.app.isMobile;
  2390. $$self.$$set = $$props => {
  2391. if ("onClick" in $$props) $$invalidate(0, onClick = $$props.onClick);
  2392. if ("tooltip" in $$props) $$invalidate(1, tooltip = $$props.tooltip);
  2393. if ("direction" in $$props) $$invalidate(2, direction = $$props.direction);
  2394. };
  2395. return [onClick, tooltip, direction, isMobile];
  2396. }
  2397. class Arrow extends SvelteComponent {
  2398. constructor(options) {
  2399. super();
  2400. if (!document.getElementById("svelte-156w7na-style")) add_css$3();
  2401. init(this, options, instance$3, create_fragment$3, safe_not_equal, { onClick: 0, tooltip: 1, direction: 2 });
  2402. }
  2403. }
  2404. /* src/components/Nav.svelte generated by Svelte v3.35.0 */
  2405. function add_css$2() {
  2406. var style = element("style");
  2407. style.id = "svelte-1vwr9dd-style";
  2408. style.textContent = ".nav.svelte-1vwr9dd.svelte-1vwr9dd{align-items:center;display:flex;margin:0.6em 0 1em;padding:0 8px;width:100%}.nav.is-mobile.svelte-1vwr9dd.svelte-1vwr9dd{padding:0}.title.svelte-1vwr9dd.svelte-1vwr9dd{color:var(--color-text-title);font-size:1.5em;margin:0}.is-mobile.svelte-1vwr9dd .title.svelte-1vwr9dd{font-size:1.3em}.month.svelte-1vwr9dd.svelte-1vwr9dd{font-weight:500;text-transform:capitalize}.year.svelte-1vwr9dd.svelte-1vwr9dd{color:var(--interactive-accent)}.right-nav.svelte-1vwr9dd.svelte-1vwr9dd{display:flex;justify-content:center;margin-left:auto}.reset-button.svelte-1vwr9dd.svelte-1vwr9dd{cursor:pointer;border-radius:4px;color:var(--text-muted);font-size:0.7em;font-weight:600;letter-spacing:1px;margin:0 4px;padding:0px 4px;text-transform:uppercase}.is-mobile.svelte-1vwr9dd .reset-button.svelte-1vwr9dd{display:none}";
  2409. append(document.head, style);
  2410. }
  2411. function create_fragment$2(ctx) {
  2412. let div2;
  2413. let h3;
  2414. let span0;
  2415. let t0_value = /*displayedMonth*/ ctx[0].format("MMM") + "";
  2416. let t0;
  2417. let t1;
  2418. let span1;
  2419. let t2_value = /*displayedMonth*/ ctx[0].format("YYYY") + "";
  2420. let t2;
  2421. let t3;
  2422. let div1;
  2423. let arrow0;
  2424. let t4;
  2425. let div0;
  2426. let t6;
  2427. let arrow1;
  2428. let current;
  2429. let mounted;
  2430. let dispose;
  2431. arrow0 = new Arrow({
  2432. props: {
  2433. direction: "left",
  2434. onClick: /*decrementDisplayedMonth*/ ctx[3],
  2435. tooltip: "Previous Month"
  2436. }
  2437. });
  2438. arrow1 = new Arrow({
  2439. props: {
  2440. direction: "right",
  2441. onClick: /*incrementDisplayedMonth*/ ctx[2],
  2442. tooltip: "Next Month"
  2443. }
  2444. });
  2445. return {
  2446. c() {
  2447. div2 = element("div");
  2448. h3 = element("h3");
  2449. span0 = element("span");
  2450. t0 = text(t0_value);
  2451. t1 = space();
  2452. span1 = element("span");
  2453. t2 = text(t2_value);
  2454. t3 = space();
  2455. div1 = element("div");
  2456. create_component(arrow0.$$.fragment);
  2457. t4 = space();
  2458. div0 = element("div");
  2459. div0.textContent = `${/*todayDisplayStr*/ ctx[4]}`;
  2460. t6 = space();
  2461. create_component(arrow1.$$.fragment);
  2462. attr(span0, "class", "month svelte-1vwr9dd");
  2463. attr(span1, "class", "year svelte-1vwr9dd");
  2464. attr(h3, "class", "title svelte-1vwr9dd");
  2465. attr(div0, "class", "reset-button svelte-1vwr9dd");
  2466. attr(div1, "class", "right-nav svelte-1vwr9dd");
  2467. attr(div2, "class", "nav svelte-1vwr9dd");
  2468. toggle_class(div2, "is-mobile", /*isMobile*/ ctx[5]);
  2469. },
  2470. m(target, anchor) {
  2471. insert(target, div2, anchor);
  2472. append(div2, h3);
  2473. append(h3, span0);
  2474. append(span0, t0);
  2475. append(h3, t1);
  2476. append(h3, span1);
  2477. append(span1, t2);
  2478. append(div2, t3);
  2479. append(div2, div1);
  2480. mount_component(arrow0, div1, null);
  2481. append(div1, t4);
  2482. append(div1, div0);
  2483. append(div1, t6);
  2484. mount_component(arrow1, div1, null);
  2485. current = true;
  2486. if (!mounted) {
  2487. dispose = [
  2488. listen(h3, "click", function () {
  2489. if (is_function(/*resetDisplayedMonth*/ ctx[1])) /*resetDisplayedMonth*/ ctx[1].apply(this, arguments);
  2490. }),
  2491. listen(div0, "click", function () {
  2492. if (is_function(/*resetDisplayedMonth*/ ctx[1])) /*resetDisplayedMonth*/ ctx[1].apply(this, arguments);
  2493. })
  2494. ];
  2495. mounted = true;
  2496. }
  2497. },
  2498. p(new_ctx, [dirty]) {
  2499. ctx = new_ctx;
  2500. if ((!current || dirty & /*displayedMonth*/ 1) && t0_value !== (t0_value = /*displayedMonth*/ ctx[0].format("MMM") + "")) set_data(t0, t0_value);
  2501. if ((!current || dirty & /*displayedMonth*/ 1) && t2_value !== (t2_value = /*displayedMonth*/ ctx[0].format("YYYY") + "")) set_data(t2, t2_value);
  2502. const arrow0_changes = {};
  2503. if (dirty & /*decrementDisplayedMonth*/ 8) arrow0_changes.onClick = /*decrementDisplayedMonth*/ ctx[3];
  2504. arrow0.$set(arrow0_changes);
  2505. const arrow1_changes = {};
  2506. if (dirty & /*incrementDisplayedMonth*/ 4) arrow1_changes.onClick = /*incrementDisplayedMonth*/ ctx[2];
  2507. arrow1.$set(arrow1_changes);
  2508. },
  2509. i(local) {
  2510. if (current) return;
  2511. transition_in(arrow0.$$.fragment, local);
  2512. transition_in(arrow1.$$.fragment, local);
  2513. current = true;
  2514. },
  2515. o(local) {
  2516. transition_out(arrow0.$$.fragment, local);
  2517. transition_out(arrow1.$$.fragment, local);
  2518. current = false;
  2519. },
  2520. d(detaching) {
  2521. if (detaching) detach(div2);
  2522. destroy_component(arrow0);
  2523. destroy_component(arrow1);
  2524. mounted = false;
  2525. run_all(dispose);
  2526. }
  2527. };
  2528. }
  2529. function instance$2($$self, $$props, $$invalidate) {
  2530. let { displayedMonth } = $$props;
  2531. let { today } = $$props;
  2532. let { resetDisplayedMonth } = $$props;
  2533. let { incrementDisplayedMonth } = $$props;
  2534. let { decrementDisplayedMonth } = $$props;
  2535. // Get the word 'Today' but localized to the current language
  2536. const todayDisplayStr = today.calendar().split(/\d|\s/)[0];
  2537. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2538. let isMobile = window.app.isMobile;
  2539. $$self.$$set = $$props => {
  2540. if ("displayedMonth" in $$props) $$invalidate(0, displayedMonth = $$props.displayedMonth);
  2541. if ("today" in $$props) $$invalidate(6, today = $$props.today);
  2542. if ("resetDisplayedMonth" in $$props) $$invalidate(1, resetDisplayedMonth = $$props.resetDisplayedMonth);
  2543. if ("incrementDisplayedMonth" in $$props) $$invalidate(2, incrementDisplayedMonth = $$props.incrementDisplayedMonth);
  2544. if ("decrementDisplayedMonth" in $$props) $$invalidate(3, decrementDisplayedMonth = $$props.decrementDisplayedMonth);
  2545. };
  2546. return [
  2547. displayedMonth,
  2548. resetDisplayedMonth,
  2549. incrementDisplayedMonth,
  2550. decrementDisplayedMonth,
  2551. todayDisplayStr,
  2552. isMobile,
  2553. today
  2554. ];
  2555. }
  2556. class Nav extends SvelteComponent {
  2557. constructor(options) {
  2558. super();
  2559. if (!document.getElementById("svelte-1vwr9dd-style")) add_css$2();
  2560. init(this, options, instance$2, create_fragment$2, safe_not_equal, {
  2561. displayedMonth: 0,
  2562. today: 6,
  2563. resetDisplayedMonth: 1,
  2564. incrementDisplayedMonth: 2,
  2565. decrementDisplayedMonth: 3
  2566. });
  2567. }
  2568. }
  2569. /* src/components/WeekNum.svelte generated by Svelte v3.35.0 */
  2570. function add_css$1() {
  2571. var style = element("style");
  2572. style.id = "svelte-egt0yd-style";
  2573. style.textContent = "td.svelte-egt0yd{border-right:1px solid var(--background-modifier-border)}.week-num.svelte-egt0yd{background-color:var(--color-background-weeknum);border-radius:4px;color:var(--color-text-weeknum);cursor:pointer;font-size:0.65em;height:100%;padding:4px;text-align:center;transition:background-color 0.1s ease-in, color 0.1s ease-in;vertical-align:baseline}.week-num.svelte-egt0yd:hover{background-color:var(--interactive-hover)}.week-num.active.svelte-egt0yd:hover{background-color:var(--interactive-accent-hover)}.active.svelte-egt0yd{color:var(--text-on-accent);background-color:var(--interactive-accent)}.dot-container.svelte-egt0yd{display:flex;flex-wrap:wrap;justify-content:center;line-height:6px;min-height:6px}";
  2574. append(document.head, style);
  2575. }
  2576. function get_each_context$1(ctx, list, i) {
  2577. const child_ctx = ctx.slice();
  2578. child_ctx[11] = list[i];
  2579. return child_ctx;
  2580. }
  2581. // (35:8) {#each metadata.dots as dot}
  2582. function create_each_block$1(ctx) {
  2583. let dot;
  2584. let current;
  2585. const dot_spread_levels = [/*dot*/ ctx[11]];
  2586. let dot_props = {};
  2587. for (let i = 0; i < dot_spread_levels.length; i += 1) {
  2588. dot_props = assign(dot_props, dot_spread_levels[i]);
  2589. }
  2590. dot = new Dot({ props: dot_props });
  2591. return {
  2592. c() {
  2593. create_component(dot.$$.fragment);
  2594. },
  2595. m(target, anchor) {
  2596. mount_component(dot, target, anchor);
  2597. current = true;
  2598. },
  2599. p(ctx, dirty) {
  2600. const dot_changes = (dirty & /*metadata*/ 64)
  2601. ? get_spread_update(dot_spread_levels, [get_spread_object(/*dot*/ ctx[11])])
  2602. : {};
  2603. dot.$set(dot_changes);
  2604. },
  2605. i(local) {
  2606. if (current) return;
  2607. transition_in(dot.$$.fragment, local);
  2608. current = true;
  2609. },
  2610. o(local) {
  2611. transition_out(dot.$$.fragment, local);
  2612. current = false;
  2613. },
  2614. d(detaching) {
  2615. destroy_component(dot, detaching);
  2616. }
  2617. };
  2618. }
  2619. // (24:2) <MetadataResolver metadata="{metadata}" let:metadata>
  2620. function create_default_slot(ctx) {
  2621. let div1;
  2622. let t0;
  2623. let t1;
  2624. let div0;
  2625. let div1_class_value;
  2626. let current;
  2627. let mounted;
  2628. let dispose;
  2629. let each_value = /*metadata*/ ctx[6].dots;
  2630. let each_blocks = [];
  2631. for (let i = 0; i < each_value.length; i += 1) {
  2632. each_blocks[i] = create_each_block$1(get_each_context$1(ctx, each_value, i));
  2633. }
  2634. const out = i => transition_out(each_blocks[i], 1, 1, () => {
  2635. each_blocks[i] = null;
  2636. });
  2637. return {
  2638. c() {
  2639. div1 = element("div");
  2640. t0 = text(/*weekNum*/ ctx[0]);
  2641. t1 = space();
  2642. div0 = element("div");
  2643. for (let i = 0; i < each_blocks.length; i += 1) {
  2644. each_blocks[i].c();
  2645. }
  2646. attr(div0, "class", "dot-container svelte-egt0yd");
  2647. attr(div1, "class", div1_class_value = "" + (null_to_empty(`week-num ${/*metadata*/ ctx[6].classes.join(" ")}`) + " svelte-egt0yd"));
  2648. toggle_class(div1, "active", /*selectedId*/ ctx[5] === getDateUID_1(/*days*/ ctx[1][0], "week"));
  2649. },
  2650. m(target, anchor) {
  2651. insert(target, div1, anchor);
  2652. append(div1, t0);
  2653. append(div1, t1);
  2654. append(div1, div0);
  2655. for (let i = 0; i < each_blocks.length; i += 1) {
  2656. each_blocks[i].m(div0, null);
  2657. }
  2658. current = true;
  2659. if (!mounted) {
  2660. dispose = [
  2661. listen(div1, "click", function () {
  2662. if (is_function(/*onClick*/ ctx[3] && /*click_handler*/ ctx[8])) (/*onClick*/ ctx[3] && /*click_handler*/ ctx[8]).apply(this, arguments);
  2663. }),
  2664. listen(div1, "contextmenu", function () {
  2665. if (is_function(/*onContextMenu*/ ctx[4] && /*contextmenu_handler*/ ctx[9])) (/*onContextMenu*/ ctx[4] && /*contextmenu_handler*/ ctx[9]).apply(this, arguments);
  2666. }),
  2667. listen(div1, "pointerover", function () {
  2668. if (is_function(/*onHover*/ ctx[2] && /*pointerover_handler*/ ctx[10])) (/*onHover*/ ctx[2] && /*pointerover_handler*/ ctx[10]).apply(this, arguments);
  2669. })
  2670. ];
  2671. mounted = true;
  2672. }
  2673. },
  2674. p(new_ctx, dirty) {
  2675. ctx = new_ctx;
  2676. if (!current || dirty & /*weekNum*/ 1) set_data(t0, /*weekNum*/ ctx[0]);
  2677. if (dirty & /*metadata*/ 64) {
  2678. each_value = /*metadata*/ ctx[6].dots;
  2679. let i;
  2680. for (i = 0; i < each_value.length; i += 1) {
  2681. const child_ctx = get_each_context$1(ctx, each_value, i);
  2682. if (each_blocks[i]) {
  2683. each_blocks[i].p(child_ctx, dirty);
  2684. transition_in(each_blocks[i], 1);
  2685. } else {
  2686. each_blocks[i] = create_each_block$1(child_ctx);
  2687. each_blocks[i].c();
  2688. transition_in(each_blocks[i], 1);
  2689. each_blocks[i].m(div0, null);
  2690. }
  2691. }
  2692. group_outros();
  2693. for (i = each_value.length; i < each_blocks.length; i += 1) {
  2694. out(i);
  2695. }
  2696. check_outros();
  2697. }
  2698. if (!current || dirty & /*metadata*/ 64 && div1_class_value !== (div1_class_value = "" + (null_to_empty(`week-num ${/*metadata*/ ctx[6].classes.join(" ")}`) + " svelte-egt0yd"))) {
  2699. attr(div1, "class", div1_class_value);
  2700. }
  2701. if (dirty & /*metadata, selectedId, getDateUID, days*/ 98) {
  2702. toggle_class(div1, "active", /*selectedId*/ ctx[5] === getDateUID_1(/*days*/ ctx[1][0], "week"));
  2703. }
  2704. },
  2705. i(local) {
  2706. if (current) return;
  2707. for (let i = 0; i < each_value.length; i += 1) {
  2708. transition_in(each_blocks[i]);
  2709. }
  2710. current = true;
  2711. },
  2712. o(local) {
  2713. each_blocks = each_blocks.filter(Boolean);
  2714. for (let i = 0; i < each_blocks.length; i += 1) {
  2715. transition_out(each_blocks[i]);
  2716. }
  2717. current = false;
  2718. },
  2719. d(detaching) {
  2720. if (detaching) detach(div1);
  2721. destroy_each(each_blocks, detaching);
  2722. mounted = false;
  2723. run_all(dispose);
  2724. }
  2725. };
  2726. }
  2727. function create_fragment$1(ctx) {
  2728. let td;
  2729. let metadataresolver;
  2730. let current;
  2731. metadataresolver = new MetadataResolver({
  2732. props: {
  2733. metadata: /*metadata*/ ctx[6],
  2734. $$slots: {
  2735. default: [
  2736. create_default_slot,
  2737. ({ metadata }) => ({ 6: metadata }),
  2738. ({ metadata }) => metadata ? 64 : 0
  2739. ]
  2740. },
  2741. $$scope: { ctx }
  2742. }
  2743. });
  2744. return {
  2745. c() {
  2746. td = element("td");
  2747. create_component(metadataresolver.$$.fragment);
  2748. attr(td, "class", "svelte-egt0yd");
  2749. },
  2750. m(target, anchor) {
  2751. insert(target, td, anchor);
  2752. mount_component(metadataresolver, td, null);
  2753. current = true;
  2754. },
  2755. p(ctx, [dirty]) {
  2756. const metadataresolver_changes = {};
  2757. if (dirty & /*metadata*/ 64) metadataresolver_changes.metadata = /*metadata*/ ctx[6];
  2758. if (dirty & /*$$scope, metadata, selectedId, days, onClick, startOfWeek, onContextMenu, onHover, weekNum*/ 16639) {
  2759. metadataresolver_changes.$$scope = { dirty, ctx };
  2760. }
  2761. metadataresolver.$set(metadataresolver_changes);
  2762. },
  2763. i(local) {
  2764. if (current) return;
  2765. transition_in(metadataresolver.$$.fragment, local);
  2766. current = true;
  2767. },
  2768. o(local) {
  2769. transition_out(metadataresolver.$$.fragment, local);
  2770. current = false;
  2771. },
  2772. d(detaching) {
  2773. if (detaching) detach(td);
  2774. destroy_component(metadataresolver);
  2775. }
  2776. };
  2777. }
  2778. function instance$1($$self, $$props, $$invalidate) {
  2779. let { weekNum } = $$props;
  2780. let { days } = $$props;
  2781. let { metadata } = $$props;
  2782. let { onHover } = $$props;
  2783. let { onClick } = $$props;
  2784. let { onContextMenu } = $$props;
  2785. let { selectedId = null } = $$props;
  2786. let startOfWeek;
  2787. const click_handler = e => onClick(startOfWeek, isMetaPressed(e));
  2788. const contextmenu_handler = e => onContextMenu(days[0], e);
  2789. const pointerover_handler = e => onHover(startOfWeek, e.target, isMetaPressed(e));
  2790. $$self.$$set = $$props => {
  2791. if ("weekNum" in $$props) $$invalidate(0, weekNum = $$props.weekNum);
  2792. if ("days" in $$props) $$invalidate(1, days = $$props.days);
  2793. if ("metadata" in $$props) $$invalidate(6, metadata = $$props.metadata);
  2794. if ("onHover" in $$props) $$invalidate(2, onHover = $$props.onHover);
  2795. if ("onClick" in $$props) $$invalidate(3, onClick = $$props.onClick);
  2796. if ("onContextMenu" in $$props) $$invalidate(4, onContextMenu = $$props.onContextMenu);
  2797. if ("selectedId" in $$props) $$invalidate(5, selectedId = $$props.selectedId);
  2798. };
  2799. $$self.$$.update = () => {
  2800. if ($$self.$$.dirty & /*days*/ 2) {
  2801. $$invalidate(7, startOfWeek = getStartOfWeek(days));
  2802. }
  2803. };
  2804. return [
  2805. weekNum,
  2806. days,
  2807. onHover,
  2808. onClick,
  2809. onContextMenu,
  2810. selectedId,
  2811. metadata,
  2812. startOfWeek,
  2813. click_handler,
  2814. contextmenu_handler,
  2815. pointerover_handler
  2816. ];
  2817. }
  2818. class WeekNum extends SvelteComponent {
  2819. constructor(options) {
  2820. super();
  2821. if (!document.getElementById("svelte-egt0yd-style")) add_css$1();
  2822. init(this, options, instance$1, create_fragment$1, not_equal, {
  2823. weekNum: 0,
  2824. days: 1,
  2825. metadata: 6,
  2826. onHover: 2,
  2827. onClick: 3,
  2828. onContextMenu: 4,
  2829. selectedId: 5
  2830. });
  2831. }
  2832. }
  2833. async function metadataReducer(promisedMetadata) {
  2834. const meta = {
  2835. dots: [],
  2836. classes: [],
  2837. dataAttributes: {},
  2838. };
  2839. const metas = await Promise.all(promisedMetadata);
  2840. return metas.reduce((acc, meta) => ({
  2841. classes: [...acc.classes, ...(meta.classes || [])],
  2842. dataAttributes: Object.assign(acc.dataAttributes, meta.dataAttributes),
  2843. dots: [...acc.dots, ...(meta.dots || [])],
  2844. }), meta);
  2845. }
  2846. function getDailyMetadata(sources, date, ..._args) {
  2847. return metadataReducer(sources.map((source) => source.getDailyMetadata(date)));
  2848. }
  2849. function getWeeklyMetadata(sources, date, ..._args) {
  2850. return metadataReducer(sources.map((source) => source.getWeeklyMetadata(date)));
  2851. }
  2852. /* src/components/Calendar.svelte generated by Svelte v3.35.0 */
  2853. function add_css() {
  2854. var style = element("style");
  2855. style.id = "svelte-pcimu8-style";
  2856. style.textContent = ".container.svelte-pcimu8{--color-background-heading:transparent;--color-background-day:transparent;--color-background-weeknum:transparent;--color-background-weekend:transparent;--color-dot:var(--text-muted);--color-arrow:var(--text-muted);--color-button:var(--text-muted);--color-text-title:var(--text-normal);--color-text-heading:var(--text-muted);--color-text-day:var(--text-normal);--color-text-today:var(--interactive-accent);--color-text-weeknum:var(--text-muted)}.container.svelte-pcimu8{padding:0 8px}.container.is-mobile.svelte-pcimu8{padding:0}th.svelte-pcimu8{text-align:center}.weekend.svelte-pcimu8{background-color:var(--color-background-weekend)}.calendar.svelte-pcimu8{border-collapse:collapse;width:100%}th.svelte-pcimu8{background-color:var(--color-background-heading);color:var(--color-text-heading);font-size:0.6em;letter-spacing:1px;padding:4px;text-transform:uppercase}";
  2857. append(document.head, style);
  2858. }
  2859. function get_each_context(ctx, list, i) {
  2860. const child_ctx = ctx.slice();
  2861. child_ctx[18] = list[i];
  2862. return child_ctx;
  2863. }
  2864. function get_each_context_1(ctx, list, i) {
  2865. const child_ctx = ctx.slice();
  2866. child_ctx[21] = list[i];
  2867. return child_ctx;
  2868. }
  2869. function get_each_context_2(ctx, list, i) {
  2870. const child_ctx = ctx.slice();
  2871. child_ctx[24] = list[i];
  2872. return child_ctx;
  2873. }
  2874. function get_each_context_3(ctx, list, i) {
  2875. const child_ctx = ctx.slice();
  2876. child_ctx[27] = list[i];
  2877. return child_ctx;
  2878. }
  2879. // (55:6) {#if showWeekNums}
  2880. function create_if_block_2(ctx) {
  2881. let col;
  2882. return {
  2883. c() {
  2884. col = element("col");
  2885. },
  2886. m(target, anchor) {
  2887. insert(target, col, anchor);
  2888. },
  2889. d(detaching) {
  2890. if (detaching) detach(col);
  2891. }
  2892. };
  2893. }
  2894. // (58:6) {#each month[1].days as date}
  2895. function create_each_block_3(ctx) {
  2896. let col;
  2897. return {
  2898. c() {
  2899. col = element("col");
  2900. attr(col, "class", "svelte-pcimu8");
  2901. toggle_class(col, "weekend", isWeekend(/*date*/ ctx[27]));
  2902. },
  2903. m(target, anchor) {
  2904. insert(target, col, anchor);
  2905. },
  2906. p(ctx, dirty) {
  2907. if (dirty & /*isWeekend, month*/ 16384) {
  2908. toggle_class(col, "weekend", isWeekend(/*date*/ ctx[27]));
  2909. }
  2910. },
  2911. d(detaching) {
  2912. if (detaching) detach(col);
  2913. }
  2914. };
  2915. }
  2916. // (64:8) {#if showWeekNums}
  2917. function create_if_block_1(ctx) {
  2918. let th;
  2919. return {
  2920. c() {
  2921. th = element("th");
  2922. th.textContent = "W";
  2923. attr(th, "class", "svelte-pcimu8");
  2924. },
  2925. m(target, anchor) {
  2926. insert(target, th, anchor);
  2927. },
  2928. d(detaching) {
  2929. if (detaching) detach(th);
  2930. }
  2931. };
  2932. }
  2933. // (67:8) {#each daysOfWeek as dayOfWeek}
  2934. function create_each_block_2(ctx) {
  2935. let th;
  2936. let t_value = /*dayOfWeek*/ ctx[24] + "";
  2937. let t;
  2938. return {
  2939. c() {
  2940. th = element("th");
  2941. t = text(t_value);
  2942. attr(th, "class", "svelte-pcimu8");
  2943. },
  2944. m(target, anchor) {
  2945. insert(target, th, anchor);
  2946. append(th, t);
  2947. },
  2948. p(ctx, dirty) {
  2949. if (dirty & /*daysOfWeek*/ 32768 && t_value !== (t_value = /*dayOfWeek*/ ctx[24] + "")) set_data(t, t_value);
  2950. },
  2951. d(detaching) {
  2952. if (detaching) detach(th);
  2953. }
  2954. };
  2955. }
  2956. // (75:10) {#if showWeekNums}
  2957. function create_if_block(ctx) {
  2958. let weeknum;
  2959. let current;
  2960. const weeknum_spread_levels = [
  2961. /*week*/ ctx[18],
  2962. {
  2963. metadata: getWeeklyMetadata(/*sources*/ ctx[8], /*week*/ ctx[18].days[0], /*today*/ ctx[10])
  2964. },
  2965. { onClick: /*onClickWeek*/ ctx[7] },
  2966. {
  2967. onContextMenu: /*onContextMenuWeek*/ ctx[5]
  2968. },
  2969. { onHover: /*onHoverWeek*/ ctx[3] },
  2970. { selectedId: /*selectedId*/ ctx[9] }
  2971. ];
  2972. let weeknum_props = {};
  2973. for (let i = 0; i < weeknum_spread_levels.length; i += 1) {
  2974. weeknum_props = assign(weeknum_props, weeknum_spread_levels[i]);
  2975. }
  2976. weeknum = new WeekNum({ props: weeknum_props });
  2977. return {
  2978. c() {
  2979. create_component(weeknum.$$.fragment);
  2980. },
  2981. m(target, anchor) {
  2982. mount_component(weeknum, target, anchor);
  2983. current = true;
  2984. },
  2985. p(ctx, dirty) {
  2986. const weeknum_changes = (dirty & /*month, getWeeklyMetadata, sources, today, onClickWeek, onContextMenuWeek, onHoverWeek, selectedId*/ 18344)
  2987. ? get_spread_update(weeknum_spread_levels, [
  2988. dirty & /*month*/ 16384 && get_spread_object(/*week*/ ctx[18]),
  2989. dirty & /*getWeeklyMetadata, sources, month, today*/ 17664 && {
  2990. metadata: getWeeklyMetadata(/*sources*/ ctx[8], /*week*/ ctx[18].days[0], /*today*/ ctx[10])
  2991. },
  2992. dirty & /*onClickWeek*/ 128 && { onClick: /*onClickWeek*/ ctx[7] },
  2993. dirty & /*onContextMenuWeek*/ 32 && {
  2994. onContextMenu: /*onContextMenuWeek*/ ctx[5]
  2995. },
  2996. dirty & /*onHoverWeek*/ 8 && { onHover: /*onHoverWeek*/ ctx[3] },
  2997. dirty & /*selectedId*/ 512 && { selectedId: /*selectedId*/ ctx[9] }
  2998. ])
  2999. : {};
  3000. weeknum.$set(weeknum_changes);
  3001. },
  3002. i(local) {
  3003. if (current) return;
  3004. transition_in(weeknum.$$.fragment, local);
  3005. current = true;
  3006. },
  3007. o(local) {
  3008. transition_out(weeknum.$$.fragment, local);
  3009. current = false;
  3010. },
  3011. d(detaching) {
  3012. destroy_component(weeknum, detaching);
  3013. }
  3014. };
  3015. }
  3016. // (85:10) {#each week.days as day (day.format())}
  3017. function create_each_block_1(key_1, ctx) {
  3018. let first;
  3019. let day;
  3020. let current;
  3021. day = new Day({
  3022. props: {
  3023. date: /*day*/ ctx[21],
  3024. today: /*today*/ ctx[10],
  3025. displayedMonth: /*displayedMonth*/ ctx[0],
  3026. onClick: /*onClickDay*/ ctx[6],
  3027. onContextMenu: /*onContextMenuDay*/ ctx[4],
  3028. onHover: /*onHoverDay*/ ctx[2],
  3029. metadata: getDailyMetadata(/*sources*/ ctx[8], /*day*/ ctx[21], /*today*/ ctx[10]),
  3030. selectedId: /*selectedId*/ ctx[9]
  3031. }
  3032. });
  3033. return {
  3034. key: key_1,
  3035. first: null,
  3036. c() {
  3037. first = empty();
  3038. create_component(day.$$.fragment);
  3039. this.first = first;
  3040. },
  3041. m(target, anchor) {
  3042. insert(target, first, anchor);
  3043. mount_component(day, target, anchor);
  3044. current = true;
  3045. },
  3046. p(new_ctx, dirty) {
  3047. ctx = new_ctx;
  3048. const day_changes = {};
  3049. if (dirty & /*month*/ 16384) day_changes.date = /*day*/ ctx[21];
  3050. if (dirty & /*today*/ 1024) day_changes.today = /*today*/ ctx[10];
  3051. if (dirty & /*displayedMonth*/ 1) day_changes.displayedMonth = /*displayedMonth*/ ctx[0];
  3052. if (dirty & /*onClickDay*/ 64) day_changes.onClick = /*onClickDay*/ ctx[6];
  3053. if (dirty & /*onContextMenuDay*/ 16) day_changes.onContextMenu = /*onContextMenuDay*/ ctx[4];
  3054. if (dirty & /*onHoverDay*/ 4) day_changes.onHover = /*onHoverDay*/ ctx[2];
  3055. if (dirty & /*sources, month, today*/ 17664) day_changes.metadata = getDailyMetadata(/*sources*/ ctx[8], /*day*/ ctx[21], /*today*/ ctx[10]);
  3056. if (dirty & /*selectedId*/ 512) day_changes.selectedId = /*selectedId*/ ctx[9];
  3057. day.$set(day_changes);
  3058. },
  3059. i(local) {
  3060. if (current) return;
  3061. transition_in(day.$$.fragment, local);
  3062. current = true;
  3063. },
  3064. o(local) {
  3065. transition_out(day.$$.fragment, local);
  3066. current = false;
  3067. },
  3068. d(detaching) {
  3069. if (detaching) detach(first);
  3070. destroy_component(day, detaching);
  3071. }
  3072. };
  3073. }
  3074. // (73:6) {#each month as week (week.weekNum)}
  3075. function create_each_block(key_1, ctx) {
  3076. let tr;
  3077. let t0;
  3078. let each_blocks = [];
  3079. let each_1_lookup = new Map();
  3080. let t1;
  3081. let current;
  3082. let if_block = /*showWeekNums*/ ctx[1] && create_if_block(ctx);
  3083. let each_value_1 = /*week*/ ctx[18].days;
  3084. const get_key = ctx => /*day*/ ctx[21].format();
  3085. for (let i = 0; i < each_value_1.length; i += 1) {
  3086. let child_ctx = get_each_context_1(ctx, each_value_1, i);
  3087. let key = get_key(child_ctx);
  3088. each_1_lookup.set(key, each_blocks[i] = create_each_block_1(key, child_ctx));
  3089. }
  3090. return {
  3091. key: key_1,
  3092. first: null,
  3093. c() {
  3094. tr = element("tr");
  3095. if (if_block) if_block.c();
  3096. t0 = space();
  3097. for (let i = 0; i < each_blocks.length; i += 1) {
  3098. each_blocks[i].c();
  3099. }
  3100. t1 = space();
  3101. this.first = tr;
  3102. },
  3103. m(target, anchor) {
  3104. insert(target, tr, anchor);
  3105. if (if_block) if_block.m(tr, null);
  3106. append(tr, t0);
  3107. for (let i = 0; i < each_blocks.length; i += 1) {
  3108. each_blocks[i].m(tr, null);
  3109. }
  3110. append(tr, t1);
  3111. current = true;
  3112. },
  3113. p(new_ctx, dirty) {
  3114. ctx = new_ctx;
  3115. if (/*showWeekNums*/ ctx[1]) {
  3116. if (if_block) {
  3117. if_block.p(ctx, dirty);
  3118. if (dirty & /*showWeekNums*/ 2) {
  3119. transition_in(if_block, 1);
  3120. }
  3121. } else {
  3122. if_block = create_if_block(ctx);
  3123. if_block.c();
  3124. transition_in(if_block, 1);
  3125. if_block.m(tr, t0);
  3126. }
  3127. } else if (if_block) {
  3128. group_outros();
  3129. transition_out(if_block, 1, 1, () => {
  3130. if_block = null;
  3131. });
  3132. check_outros();
  3133. }
  3134. if (dirty & /*month, today, displayedMonth, onClickDay, onContextMenuDay, onHoverDay, getDailyMetadata, sources, selectedId*/ 18261) {
  3135. each_value_1 = /*week*/ ctx[18].days;
  3136. group_outros();
  3137. each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value_1, each_1_lookup, tr, outro_and_destroy_block, create_each_block_1, t1, get_each_context_1);
  3138. check_outros();
  3139. }
  3140. },
  3141. i(local) {
  3142. if (current) return;
  3143. transition_in(if_block);
  3144. for (let i = 0; i < each_value_1.length; i += 1) {
  3145. transition_in(each_blocks[i]);
  3146. }
  3147. current = true;
  3148. },
  3149. o(local) {
  3150. transition_out(if_block);
  3151. for (let i = 0; i < each_blocks.length; i += 1) {
  3152. transition_out(each_blocks[i]);
  3153. }
  3154. current = false;
  3155. },
  3156. d(detaching) {
  3157. if (detaching) detach(tr);
  3158. if (if_block) if_block.d();
  3159. for (let i = 0; i < each_blocks.length; i += 1) {
  3160. each_blocks[i].d();
  3161. }
  3162. }
  3163. };
  3164. }
  3165. function create_fragment$7(ctx) {
  3166. let div;
  3167. let nav;
  3168. let t0;
  3169. let table;
  3170. let colgroup;
  3171. let t1;
  3172. let t2;
  3173. let thead;
  3174. let tr;
  3175. let t3;
  3176. let t4;
  3177. let tbody;
  3178. let each_blocks = [];
  3179. let each2_lookup = new Map();
  3180. let current;
  3181. nav = new Nav({
  3182. props: {
  3183. today: /*today*/ ctx[10],
  3184. displayedMonth: /*displayedMonth*/ ctx[0],
  3185. incrementDisplayedMonth: /*incrementDisplayedMonth*/ ctx[11],
  3186. decrementDisplayedMonth: /*decrementDisplayedMonth*/ ctx[12],
  3187. resetDisplayedMonth: /*resetDisplayedMonth*/ ctx[13]
  3188. }
  3189. });
  3190. let if_block0 = /*showWeekNums*/ ctx[1] && create_if_block_2();
  3191. let each_value_3 = /*month*/ ctx[14][1].days;
  3192. let each_blocks_2 = [];
  3193. for (let i = 0; i < each_value_3.length; i += 1) {
  3194. each_blocks_2[i] = create_each_block_3(get_each_context_3(ctx, each_value_3, i));
  3195. }
  3196. let if_block1 = /*showWeekNums*/ ctx[1] && create_if_block_1();
  3197. let each_value_2 = /*daysOfWeek*/ ctx[15];
  3198. let each_blocks_1 = [];
  3199. for (let i = 0; i < each_value_2.length; i += 1) {
  3200. each_blocks_1[i] = create_each_block_2(get_each_context_2(ctx, each_value_2, i));
  3201. }
  3202. let each_value = /*month*/ ctx[14];
  3203. const get_key = ctx => /*week*/ ctx[18].weekNum;
  3204. for (let i = 0; i < each_value.length; i += 1) {
  3205. let child_ctx = get_each_context(ctx, each_value, i);
  3206. let key = get_key(child_ctx);
  3207. each2_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx));
  3208. }
  3209. return {
  3210. c() {
  3211. div = element("div");
  3212. create_component(nav.$$.fragment);
  3213. t0 = space();
  3214. table = element("table");
  3215. colgroup = element("colgroup");
  3216. if (if_block0) if_block0.c();
  3217. t1 = space();
  3218. for (let i = 0; i < each_blocks_2.length; i += 1) {
  3219. each_blocks_2[i].c();
  3220. }
  3221. t2 = space();
  3222. thead = element("thead");
  3223. tr = element("tr");
  3224. if (if_block1) if_block1.c();
  3225. t3 = space();
  3226. for (let i = 0; i < each_blocks_1.length; i += 1) {
  3227. each_blocks_1[i].c();
  3228. }
  3229. t4 = space();
  3230. tbody = element("tbody");
  3231. for (let i = 0; i < each_blocks.length; i += 1) {
  3232. each_blocks[i].c();
  3233. }
  3234. attr(table, "class", "calendar svelte-pcimu8");
  3235. attr(div, "id", "calendar-container");
  3236. attr(div, "class", "container svelte-pcimu8");
  3237. toggle_class(div, "is-mobile", /*isMobile*/ ctx[16]);
  3238. },
  3239. m(target, anchor) {
  3240. insert(target, div, anchor);
  3241. mount_component(nav, div, null);
  3242. append(div, t0);
  3243. append(div, table);
  3244. append(table, colgroup);
  3245. if (if_block0) if_block0.m(colgroup, null);
  3246. append(colgroup, t1);
  3247. for (let i = 0; i < each_blocks_2.length; i += 1) {
  3248. each_blocks_2[i].m(colgroup, null);
  3249. }
  3250. append(table, t2);
  3251. append(table, thead);
  3252. append(thead, tr);
  3253. if (if_block1) if_block1.m(tr, null);
  3254. append(tr, t3);
  3255. for (let i = 0; i < each_blocks_1.length; i += 1) {
  3256. each_blocks_1[i].m(tr, null);
  3257. }
  3258. append(table, t4);
  3259. append(table, tbody);
  3260. for (let i = 0; i < each_blocks.length; i += 1) {
  3261. each_blocks[i].m(tbody, null);
  3262. }
  3263. current = true;
  3264. },
  3265. p(ctx, [dirty]) {
  3266. const nav_changes = {};
  3267. if (dirty & /*today*/ 1024) nav_changes.today = /*today*/ ctx[10];
  3268. if (dirty & /*displayedMonth*/ 1) nav_changes.displayedMonth = /*displayedMonth*/ ctx[0];
  3269. nav.$set(nav_changes);
  3270. if (/*showWeekNums*/ ctx[1]) {
  3271. if (if_block0) ; else {
  3272. if_block0 = create_if_block_2();
  3273. if_block0.c();
  3274. if_block0.m(colgroup, t1);
  3275. }
  3276. } else if (if_block0) {
  3277. if_block0.d(1);
  3278. if_block0 = null;
  3279. }
  3280. if (dirty & /*isWeekend, month*/ 16384) {
  3281. each_value_3 = /*month*/ ctx[14][1].days;
  3282. let i;
  3283. for (i = 0; i < each_value_3.length; i += 1) {
  3284. const child_ctx = get_each_context_3(ctx, each_value_3, i);
  3285. if (each_blocks_2[i]) {
  3286. each_blocks_2[i].p(child_ctx, dirty);
  3287. } else {
  3288. each_blocks_2[i] = create_each_block_3(child_ctx);
  3289. each_blocks_2[i].c();
  3290. each_blocks_2[i].m(colgroup, null);
  3291. }
  3292. }
  3293. for (; i < each_blocks_2.length; i += 1) {
  3294. each_blocks_2[i].d(1);
  3295. }
  3296. each_blocks_2.length = each_value_3.length;
  3297. }
  3298. if (/*showWeekNums*/ ctx[1]) {
  3299. if (if_block1) ; else {
  3300. if_block1 = create_if_block_1();
  3301. if_block1.c();
  3302. if_block1.m(tr, t3);
  3303. }
  3304. } else if (if_block1) {
  3305. if_block1.d(1);
  3306. if_block1 = null;
  3307. }
  3308. if (dirty & /*daysOfWeek*/ 32768) {
  3309. each_value_2 = /*daysOfWeek*/ ctx[15];
  3310. let i;
  3311. for (i = 0; i < each_value_2.length; i += 1) {
  3312. const child_ctx = get_each_context_2(ctx, each_value_2, i);
  3313. if (each_blocks_1[i]) {
  3314. each_blocks_1[i].p(child_ctx, dirty);
  3315. } else {
  3316. each_blocks_1[i] = create_each_block_2(child_ctx);
  3317. each_blocks_1[i].c();
  3318. each_blocks_1[i].m(tr, null);
  3319. }
  3320. }
  3321. for (; i < each_blocks_1.length; i += 1) {
  3322. each_blocks_1[i].d(1);
  3323. }
  3324. each_blocks_1.length = each_value_2.length;
  3325. }
  3326. if (dirty & /*month, today, displayedMonth, onClickDay, onContextMenuDay, onHoverDay, getDailyMetadata, sources, selectedId, getWeeklyMetadata, onClickWeek, onContextMenuWeek, onHoverWeek, showWeekNums*/ 18431) {
  3327. each_value = /*month*/ ctx[14];
  3328. group_outros();
  3329. each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value, each2_lookup, tbody, outro_and_destroy_block, create_each_block, null, get_each_context);
  3330. check_outros();
  3331. }
  3332. },
  3333. i(local) {
  3334. if (current) return;
  3335. transition_in(nav.$$.fragment, local);
  3336. for (let i = 0; i < each_value.length; i += 1) {
  3337. transition_in(each_blocks[i]);
  3338. }
  3339. current = true;
  3340. },
  3341. o(local) {
  3342. transition_out(nav.$$.fragment, local);
  3343. for (let i = 0; i < each_blocks.length; i += 1) {
  3344. transition_out(each_blocks[i]);
  3345. }
  3346. current = false;
  3347. },
  3348. d(detaching) {
  3349. if (detaching) detach(div);
  3350. destroy_component(nav);
  3351. if (if_block0) if_block0.d();
  3352. destroy_each(each_blocks_2, detaching);
  3353. if (if_block1) if_block1.d();
  3354. destroy_each(each_blocks_1, detaching);
  3355. for (let i = 0; i < each_blocks.length; i += 1) {
  3356. each_blocks[i].d();
  3357. }
  3358. }
  3359. };
  3360. }
  3361. function instance$7($$self, $$props, $$invalidate) {
  3362. let { localeData } = $$props;
  3363. let { showWeekNums = false } = $$props;
  3364. let { onHoverDay } = $$props;
  3365. let { onHoverWeek } = $$props;
  3366. let { onContextMenuDay } = $$props;
  3367. let { onContextMenuWeek } = $$props;
  3368. let { onClickDay } = $$props;
  3369. let { onClickWeek } = $$props;
  3370. let { sources = [] } = $$props;
  3371. let { selectedId } = $$props;
  3372. let { today = window.moment() } = $$props;
  3373. let { displayedMonth = today } = $$props;
  3374. let month;
  3375. let daysOfWeek;
  3376. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3377. let isMobile = window.app.isMobile;
  3378. function incrementDisplayedMonth() {
  3379. $$invalidate(0, displayedMonth = displayedMonth.clone().add(1, "month"));
  3380. }
  3381. function decrementDisplayedMonth() {
  3382. $$invalidate(0, displayedMonth = displayedMonth.clone().subtract(1, "month"));
  3383. }
  3384. function resetDisplayedMonth() {
  3385. $$invalidate(0, displayedMonth = today.clone());
  3386. }
  3387. $$self.$$set = $$props => {
  3388. if ("localeData" in $$props) $$invalidate(17, localeData = $$props.localeData);
  3389. if ("showWeekNums" in $$props) $$invalidate(1, showWeekNums = $$props.showWeekNums);
  3390. if ("onHoverDay" in $$props) $$invalidate(2, onHoverDay = $$props.onHoverDay);
  3391. if ("onHoverWeek" in $$props) $$invalidate(3, onHoverWeek = $$props.onHoverWeek);
  3392. if ("onContextMenuDay" in $$props) $$invalidate(4, onContextMenuDay = $$props.onContextMenuDay);
  3393. if ("onContextMenuWeek" in $$props) $$invalidate(5, onContextMenuWeek = $$props.onContextMenuWeek);
  3394. if ("onClickDay" in $$props) $$invalidate(6, onClickDay = $$props.onClickDay);
  3395. if ("onClickWeek" in $$props) $$invalidate(7, onClickWeek = $$props.onClickWeek);
  3396. if ("sources" in $$props) $$invalidate(8, sources = $$props.sources);
  3397. if ("selectedId" in $$props) $$invalidate(9, selectedId = $$props.selectedId);
  3398. if ("today" in $$props) $$invalidate(10, today = $$props.today);
  3399. if ("displayedMonth" in $$props) $$invalidate(0, displayedMonth = $$props.displayedMonth);
  3400. };
  3401. $$self.$$.update = () => {
  3402. if ($$self.$$.dirty & /*displayedMonth, localeData*/ 131073) {
  3403. $$invalidate(14, month = getMonth(displayedMonth, localeData));
  3404. }
  3405. if ($$self.$$.dirty & /*today, localeData*/ 132096) {
  3406. $$invalidate(15, daysOfWeek = getDaysOfWeek(today, localeData));
  3407. }
  3408. };
  3409. return [
  3410. displayedMonth,
  3411. showWeekNums,
  3412. onHoverDay,
  3413. onHoverWeek,
  3414. onContextMenuDay,
  3415. onContextMenuWeek,
  3416. onClickDay,
  3417. onClickWeek,
  3418. sources,
  3419. selectedId,
  3420. today,
  3421. incrementDisplayedMonth,
  3422. decrementDisplayedMonth,
  3423. resetDisplayedMonth,
  3424. month,
  3425. daysOfWeek,
  3426. isMobile,
  3427. localeData
  3428. ];
  3429. }
  3430. class Calendar$1 extends SvelteComponent {
  3431. constructor(options) {
  3432. super();
  3433. if (!document.getElementById("svelte-pcimu8-style")) add_css();
  3434. init(this, options, instance$7, create_fragment$7, not_equal, {
  3435. localeData: 17,
  3436. showWeekNums: 1,
  3437. onHoverDay: 2,
  3438. onHoverWeek: 3,
  3439. onContextMenuDay: 4,
  3440. onContextMenuWeek: 5,
  3441. onClickDay: 6,
  3442. onClickWeek: 7,
  3443. sources: 8,
  3444. selectedId: 9,
  3445. today: 10,
  3446. displayedMonth: 0,
  3447. incrementDisplayedMonth: 11,
  3448. decrementDisplayedMonth: 12,
  3449. resetDisplayedMonth: 13
  3450. });
  3451. }
  3452. get incrementDisplayedMonth() {
  3453. return this.$$.ctx[11];
  3454. }
  3455. get decrementDisplayedMonth() {
  3456. return this.$$.ctx[12];
  3457. }
  3458. get resetDisplayedMonth() {
  3459. return this.$$.ctx[13];
  3460. }
  3461. }
  3462. const langToMomentLocale = {
  3463. en: "en-gb",
  3464. zh: "zh-cn",
  3465. "zh-TW": "zh-tw",
  3466. ru: "ru",
  3467. ko: "ko",
  3468. it: "it",
  3469. id: "id",
  3470. ro: "ro",
  3471. "pt-BR": "pt-br",
  3472. cz: "cs",
  3473. da: "da",
  3474. de: "de",
  3475. es: "es",
  3476. fr: "fr",
  3477. no: "nn",
  3478. pl: "pl",
  3479. pt: "pt",
  3480. tr: "tr",
  3481. hi: "hi",
  3482. nl: "nl",
  3483. ar: "ar",
  3484. ja: "ja",
  3485. };
  3486. const weekdays = [
  3487. "sunday",
  3488. "monday",
  3489. "tuesday",
  3490. "wednesday",
  3491. "thursday",
  3492. "friday",
  3493. "saturday",
  3494. ];
  3495. function overrideGlobalMomentWeekStart(weekStart) {
  3496. const { moment } = window;
  3497. const currentLocale = moment.locale();
  3498. // Save the initial locale weekspec so that we can restore
  3499. // it when toggling between the different options in settings.
  3500. if (!window._bundledLocaleWeekSpec) {
  3501. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3502. window._bundledLocaleWeekSpec = moment.localeData()._week;
  3503. }
  3504. if (weekStart === "locale") {
  3505. moment.updateLocale(currentLocale, {
  3506. week: window._bundledLocaleWeekSpec,
  3507. });
  3508. }
  3509. else {
  3510. moment.updateLocale(currentLocale, {
  3511. week: {
  3512. dow: weekdays.indexOf(weekStart) || 0,
  3513. },
  3514. });
  3515. }
  3516. }
  3517. /**
  3518. * Sets the locale used by the calendar. This allows the calendar to
  3519. * default to the user's locale (e.g. Start Week on Sunday/Monday/Friday)
  3520. *
  3521. * @param localeOverride locale string (e.g. "en-US")
  3522. */
  3523. function configureGlobalMomentLocale(localeOverride = "system-default", weekStart = "locale") {
  3524. var _a;
  3525. const obsidianLang = localStorage.getItem("language") || "en";
  3526. const systemLang = (_a = navigator.language) === null || _a === void 0 ? void 0 : _a.toLowerCase();
  3527. let momentLocale = langToMomentLocale[obsidianLang];
  3528. if (localeOverride !== "system-default") {
  3529. momentLocale = localeOverride;
  3530. }
  3531. else if (systemLang.startsWith(obsidianLang)) {
  3532. // If the system locale is more specific (en-gb vs en), use the system locale.
  3533. momentLocale = systemLang;
  3534. }
  3535. const currentLocale = window.moment.locale(momentLocale);
  3536. console.debug(`[Calendar] Trying to switch Moment.js global locale to ${momentLocale}, got ${currentLocale}`);
  3537. overrideGlobalMomentWeekStart(weekStart);
  3538. return currentLocale;
  3539. }
  3540. /* src/ui/Calendar.svelte generated by Svelte v3.35.0 */
  3541. function create_fragment(ctx) {
  3542. let calendarbase;
  3543. let updating_displayedMonth;
  3544. let current;
  3545. function calendarbase_displayedMonth_binding(value) {
  3546. /*calendarbase_displayedMonth_binding*/ ctx[12](value);
  3547. }
  3548. let calendarbase_props = {
  3549. sources: /*sources*/ ctx[1],
  3550. today: /*today*/ ctx[9],
  3551. onHoverDay: /*onHoverDay*/ ctx[2],
  3552. onHoverWeek: /*onHoverWeek*/ ctx[3],
  3553. onContextMenuDay: /*onContextMenuDay*/ ctx[6],
  3554. onContextMenuWeek: /*onContextMenuWeek*/ ctx[7],
  3555. onClickDay: /*onClickDay*/ ctx[4],
  3556. onClickWeek: /*onClickWeek*/ ctx[5],
  3557. localeData: /*today*/ ctx[9].localeData(),
  3558. selectedId: /*$activeFile*/ ctx[10],
  3559. showWeekNums: /*$settings*/ ctx[8].showWeeklyNote
  3560. };
  3561. if (/*displayedMonth*/ ctx[0] !== void 0) {
  3562. calendarbase_props.displayedMonth = /*displayedMonth*/ ctx[0];
  3563. }
  3564. calendarbase = new Calendar$1({ props: calendarbase_props });
  3565. binding_callbacks$1.push(() => bind(calendarbase, "displayedMonth", calendarbase_displayedMonth_binding));
  3566. return {
  3567. c() {
  3568. create_component$1(calendarbase.$$.fragment);
  3569. },
  3570. m(target, anchor) {
  3571. mount_component$1(calendarbase, target, anchor);
  3572. current = true;
  3573. },
  3574. p(ctx, [dirty]) {
  3575. const calendarbase_changes = {};
  3576. if (dirty & /*sources*/ 2) calendarbase_changes.sources = /*sources*/ ctx[1];
  3577. if (dirty & /*today*/ 512) calendarbase_changes.today = /*today*/ ctx[9];
  3578. if (dirty & /*onHoverDay*/ 4) calendarbase_changes.onHoverDay = /*onHoverDay*/ ctx[2];
  3579. if (dirty & /*onHoverWeek*/ 8) calendarbase_changes.onHoverWeek = /*onHoverWeek*/ ctx[3];
  3580. if (dirty & /*onContextMenuDay*/ 64) calendarbase_changes.onContextMenuDay = /*onContextMenuDay*/ ctx[6];
  3581. if (dirty & /*onContextMenuWeek*/ 128) calendarbase_changes.onContextMenuWeek = /*onContextMenuWeek*/ ctx[7];
  3582. if (dirty & /*onClickDay*/ 16) calendarbase_changes.onClickDay = /*onClickDay*/ ctx[4];
  3583. if (dirty & /*onClickWeek*/ 32) calendarbase_changes.onClickWeek = /*onClickWeek*/ ctx[5];
  3584. if (dirty & /*today*/ 512) calendarbase_changes.localeData = /*today*/ ctx[9].localeData();
  3585. if (dirty & /*$activeFile*/ 1024) calendarbase_changes.selectedId = /*$activeFile*/ ctx[10];
  3586. if (dirty & /*$settings*/ 256) calendarbase_changes.showWeekNums = /*$settings*/ ctx[8].showWeeklyNote;
  3587. if (!updating_displayedMonth && dirty & /*displayedMonth*/ 1) {
  3588. updating_displayedMonth = true;
  3589. calendarbase_changes.displayedMonth = /*displayedMonth*/ ctx[0];
  3590. add_flush_callback(() => updating_displayedMonth = false);
  3591. }
  3592. calendarbase.$set(calendarbase_changes);
  3593. },
  3594. i(local) {
  3595. if (current) return;
  3596. transition_in$1(calendarbase.$$.fragment, local);
  3597. current = true;
  3598. },
  3599. o(local) {
  3600. transition_out$1(calendarbase.$$.fragment, local);
  3601. current = false;
  3602. },
  3603. d(detaching) {
  3604. destroy_component$1(calendarbase, detaching);
  3605. }
  3606. };
  3607. }
  3608. function instance($$self, $$props, $$invalidate) {
  3609. let $settings;
  3610. let $activeFile;
  3611. component_subscribe($$self, settings, $$value => $$invalidate(8, $settings = $$value));
  3612. component_subscribe($$self, activeFile, $$value => $$invalidate(10, $activeFile = $$value));
  3613. let today;
  3614. let { displayedMonth = today } = $$props;
  3615. let { sources } = $$props;
  3616. let { onHoverDay } = $$props;
  3617. let { onHoverWeek } = $$props;
  3618. let { onClickDay } = $$props;
  3619. let { onClickWeek } = $$props;
  3620. let { onContextMenuDay } = $$props;
  3621. let { onContextMenuWeek } = $$props;
  3622. function tick() {
  3623. $$invalidate(9, today = window.moment());
  3624. }
  3625. function getToday(settings) {
  3626. configureGlobalMomentLocale(settings.localeOverride, settings.weekStart);
  3627. dailyNotes.reindex();
  3628. weeklyNotes.reindex();
  3629. return window.moment();
  3630. }
  3631. // 1 minute heartbeat to keep `today` reflecting the current day
  3632. let heartbeat = setInterval(
  3633. () => {
  3634. tick();
  3635. const isViewingCurrentMonth = displayedMonth.isSame(today, "day");
  3636. if (isViewingCurrentMonth) {
  3637. // if it's midnight on the last day of the month, this will
  3638. // update the display to show the new month.
  3639. $$invalidate(0, displayedMonth = today);
  3640. }
  3641. },
  3642. 1000 * 60
  3643. );
  3644. onDestroy(() => {
  3645. clearInterval(heartbeat);
  3646. });
  3647. function calendarbase_displayedMonth_binding(value) {
  3648. displayedMonth = value;
  3649. $$invalidate(0, displayedMonth);
  3650. }
  3651. $$self.$$set = $$props => {
  3652. if ("displayedMonth" in $$props) $$invalidate(0, displayedMonth = $$props.displayedMonth);
  3653. if ("sources" in $$props) $$invalidate(1, sources = $$props.sources);
  3654. if ("onHoverDay" in $$props) $$invalidate(2, onHoverDay = $$props.onHoverDay);
  3655. if ("onHoverWeek" in $$props) $$invalidate(3, onHoverWeek = $$props.onHoverWeek);
  3656. if ("onClickDay" in $$props) $$invalidate(4, onClickDay = $$props.onClickDay);
  3657. if ("onClickWeek" in $$props) $$invalidate(5, onClickWeek = $$props.onClickWeek);
  3658. if ("onContextMenuDay" in $$props) $$invalidate(6, onContextMenuDay = $$props.onContextMenuDay);
  3659. if ("onContextMenuWeek" in $$props) $$invalidate(7, onContextMenuWeek = $$props.onContextMenuWeek);
  3660. };
  3661. $$self.$$.update = () => {
  3662. if ($$self.$$.dirty & /*$settings*/ 256) {
  3663. $$invalidate(9, today = getToday($settings));
  3664. }
  3665. };
  3666. return [
  3667. displayedMonth,
  3668. sources,
  3669. onHoverDay,
  3670. onHoverWeek,
  3671. onClickDay,
  3672. onClickWeek,
  3673. onContextMenuDay,
  3674. onContextMenuWeek,
  3675. $settings,
  3676. today,
  3677. $activeFile,
  3678. tick,
  3679. calendarbase_displayedMonth_binding
  3680. ];
  3681. }
  3682. class Calendar extends SvelteComponent$1 {
  3683. constructor(options) {
  3684. super();
  3685. init$1(this, options, instance, create_fragment, not_equal$1, {
  3686. displayedMonth: 0,
  3687. sources: 1,
  3688. onHoverDay: 2,
  3689. onHoverWeek: 3,
  3690. onClickDay: 4,
  3691. onClickWeek: 5,
  3692. onContextMenuDay: 6,
  3693. onContextMenuWeek: 7,
  3694. tick: 11
  3695. });
  3696. }
  3697. get tick() {
  3698. return this.$$.ctx[11];
  3699. }
  3700. }
  3701. function showFileMenu(app, file, position) {
  3702. const fileMenu = new obsidian.Menu(app);
  3703. fileMenu.addItem((item) => item
  3704. .setTitle("Delete")
  3705. .setIcon("trash")
  3706. .onClick(() => {
  3707. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3708. app.fileManager.promptForFileDeletion(file);
  3709. }));
  3710. app.workspace.trigger("file-menu", fileMenu, file, "calendar-context-menu", null);
  3711. fileMenu.showAtPosition(position);
  3712. }
  3713. const getStreakClasses = (file) => {
  3714. return classList({
  3715. "has-note": !!file,
  3716. });
  3717. };
  3718. const streakSource = {
  3719. getDailyMetadata: async (date) => {
  3720. const file = getDailyNote_1(date, get_store_value(dailyNotes));
  3721. return {
  3722. classes: getStreakClasses(file),
  3723. dots: [],
  3724. };
  3725. },
  3726. getWeeklyMetadata: async (date) => {
  3727. const file = getWeeklyNote_1(date, get_store_value(weeklyNotes));
  3728. return {
  3729. classes: getStreakClasses(file),
  3730. dots: [],
  3731. };
  3732. },
  3733. };
  3734. function getNoteTags(note) {
  3735. var _a;
  3736. if (!note) {
  3737. return [];
  3738. }
  3739. const { metadataCache } = window.app;
  3740. const frontmatter = (_a = metadataCache.getFileCache(note)) === null || _a === void 0 ? void 0 : _a.frontmatter;
  3741. const tags = [];
  3742. if (frontmatter) {
  3743. const frontmatterTags = obsidian.parseFrontMatterTags(frontmatter) || [];
  3744. tags.push(...frontmatterTags);
  3745. }
  3746. // strip the '#' at the beginning
  3747. return tags.map((tag) => tag.substring(1));
  3748. }
  3749. function getFormattedTagAttributes(note) {
  3750. const attrs = {};
  3751. const tags = getNoteTags(note);
  3752. const [emojiTags, nonEmojiTags] = partition(tags, (tag) => /(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/.test(tag));
  3753. if (nonEmojiTags) {
  3754. attrs["data-tags"] = nonEmojiTags.join(" ");
  3755. }
  3756. if (emojiTags) {
  3757. attrs["data-emoji-tag"] = emojiTags[0];
  3758. }
  3759. return attrs;
  3760. }
  3761. const customTagsSource = {
  3762. getDailyMetadata: async (date) => {
  3763. const file = getDailyNote_1(date, get_store_value(dailyNotes));
  3764. return {
  3765. dataAttributes: getFormattedTagAttributes(file),
  3766. dots: [],
  3767. };
  3768. },
  3769. getWeeklyMetadata: async (date) => {
  3770. const file = getWeeklyNote_1(date, get_store_value(weeklyNotes));
  3771. return {
  3772. dataAttributes: getFormattedTagAttributes(file),
  3773. dots: [],
  3774. };
  3775. },
  3776. };
  3777. async function getNumberOfRemainingTasks(note) {
  3778. if (!note) {
  3779. return 0;
  3780. }
  3781. const { vault } = window.app;
  3782. const fileContents = await vault.cachedRead(note);
  3783. return (fileContents.match(/(-|\*) \[ \]/g) || []).length;
  3784. }
  3785. async function getDotsForDailyNote$1(dailyNote) {
  3786. if (!dailyNote) {
  3787. return [];
  3788. }
  3789. const numTasks = await getNumberOfRemainingTasks(dailyNote);
  3790. const dots = [];
  3791. if (numTasks) {
  3792. dots.push({
  3793. className: "task",
  3794. color: "default",
  3795. isFilled: false,
  3796. });
  3797. }
  3798. return dots;
  3799. }
  3800. const tasksSource = {
  3801. getDailyMetadata: async (date) => {
  3802. const file = getDailyNote_1(date, get_store_value(dailyNotes));
  3803. const dots = await getDotsForDailyNote$1(file);
  3804. return {
  3805. dots,
  3806. };
  3807. },
  3808. getWeeklyMetadata: async (date) => {
  3809. const file = getWeeklyNote_1(date, get_store_value(weeklyNotes));
  3810. const dots = await getDotsForDailyNote$1(file);
  3811. return {
  3812. dots,
  3813. };
  3814. },
  3815. };
  3816. const NUM_MAX_DOTS = 5;
  3817. async function getWordLengthAsDots(note) {
  3818. const { wordsPerDot = DEFAULT_WORDS_PER_DOT } = get_store_value(settings);
  3819. if (!note || wordsPerDot <= 0) {
  3820. return 0;
  3821. }
  3822. const fileContents = await window.app.vault.cachedRead(note);
  3823. const wordCount = getWordCount(fileContents);
  3824. const numDots = wordCount / wordsPerDot;
  3825. return clamp(Math.floor(numDots), 1, NUM_MAX_DOTS);
  3826. }
  3827. async function getDotsForDailyNote(dailyNote) {
  3828. if (!dailyNote) {
  3829. return [];
  3830. }
  3831. const numSolidDots = await getWordLengthAsDots(dailyNote);
  3832. const dots = [];
  3833. for (let i = 0; i < numSolidDots; i++) {
  3834. dots.push({
  3835. color: "default",
  3836. isFilled: true,
  3837. });
  3838. }
  3839. return dots;
  3840. }
  3841. const wordCountSource = {
  3842. getDailyMetadata: async (date) => {
  3843. const file = getDailyNote_1(date, get_store_value(dailyNotes));
  3844. const dots = await getDotsForDailyNote(file);
  3845. return {
  3846. dots,
  3847. };
  3848. },
  3849. getWeeklyMetadata: async (date) => {
  3850. const file = getWeeklyNote_1(date, get_store_value(weeklyNotes));
  3851. const dots = await getDotsForDailyNote(file);
  3852. return {
  3853. dots,
  3854. };
  3855. },
  3856. };
  3857. class CalendarView extends obsidian.ItemView {
  3858. constructor(leaf) {
  3859. super(leaf);
  3860. this.openOrCreateDailyNote = this.openOrCreateDailyNote.bind(this);
  3861. this.openOrCreateWeeklyNote = this.openOrCreateWeeklyNote.bind(this);
  3862. this.onNoteSettingsUpdate = this.onNoteSettingsUpdate.bind(this);
  3863. this.onFileCreated = this.onFileCreated.bind(this);
  3864. this.onFileDeleted = this.onFileDeleted.bind(this);
  3865. this.onFileModified = this.onFileModified.bind(this);
  3866. this.onFileOpen = this.onFileOpen.bind(this);
  3867. this.onHoverDay = this.onHoverDay.bind(this);
  3868. this.onHoverWeek = this.onHoverWeek.bind(this);
  3869. this.onContextMenuDay = this.onContextMenuDay.bind(this);
  3870. this.onContextMenuWeek = this.onContextMenuWeek.bind(this);
  3871. this.registerEvent(
  3872. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3873. this.app.workspace.on("periodic-notes:settings-updated", this.onNoteSettingsUpdate));
  3874. this.registerEvent(this.app.vault.on("create", this.onFileCreated));
  3875. this.registerEvent(this.app.vault.on("delete", this.onFileDeleted));
  3876. this.registerEvent(this.app.vault.on("modify", this.onFileModified));
  3877. this.registerEvent(this.app.workspace.on("file-open", this.onFileOpen));
  3878. this.settings = null;
  3879. settings.subscribe((val) => {
  3880. this.settings = val;
  3881. // Refresh the calendar if settings change
  3882. if (this.calendar) {
  3883. this.calendar.tick();
  3884. }
  3885. });
  3886. }
  3887. getViewType() {
  3888. return VIEW_TYPE_CALENDAR;
  3889. }
  3890. getDisplayText() {
  3891. return "Calendar";
  3892. }
  3893. getIcon() {
  3894. return "calendar-with-checkmark";
  3895. }
  3896. onClose() {
  3897. if (this.calendar) {
  3898. this.calendar.$destroy();
  3899. }
  3900. return Promise.resolve();
  3901. }
  3902. async onOpen() {
  3903. // Integration point: external plugins can listen for `calendar:open`
  3904. // to feed in additional sources.
  3905. const sources = [
  3906. customTagsSource,
  3907. streakSource,
  3908. wordCountSource,
  3909. tasksSource,
  3910. ];
  3911. this.app.workspace.trigger(TRIGGER_ON_OPEN, sources);
  3912. this.calendar = new Calendar({
  3913. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  3914. target: this.contentEl,
  3915. props: {
  3916. onClickDay: this.openOrCreateDailyNote,
  3917. onClickWeek: this.openOrCreateWeeklyNote,
  3918. onHoverDay: this.onHoverDay,
  3919. onHoverWeek: this.onHoverWeek,
  3920. onContextMenuDay: this.onContextMenuDay,
  3921. onContextMenuWeek: this.onContextMenuWeek,
  3922. sources,
  3923. },
  3924. });
  3925. }
  3926. onHoverDay(date, targetEl, isMetaPressed) {
  3927. if (!isMetaPressed) {
  3928. return;
  3929. }
  3930. const { format } = getDailyNoteSettings_1();
  3931. const note = getDailyNote_1(date, get_store_value(dailyNotes));
  3932. this.app.workspace.trigger("link-hover", this, targetEl, date.format(format), note === null || note === void 0 ? void 0 : note.path);
  3933. }
  3934. onHoverWeek(date, targetEl, isMetaPressed) {
  3935. if (!isMetaPressed) {
  3936. return;
  3937. }
  3938. const note = getWeeklyNote_1(date, get_store_value(weeklyNotes));
  3939. const { format } = getWeeklyNoteSettings_1();
  3940. this.app.workspace.trigger("link-hover", this, targetEl, date.format(format), note === null || note === void 0 ? void 0 : note.path);
  3941. }
  3942. onContextMenuDay(date, event) {
  3943. const note = getDailyNote_1(date, get_store_value(dailyNotes));
  3944. if (!note) {
  3945. // If no file exists for a given day, show nothing.
  3946. return;
  3947. }
  3948. showFileMenu(this.app, note, {
  3949. x: event.pageX,
  3950. y: event.pageY,
  3951. });
  3952. }
  3953. onContextMenuWeek(date, event) {
  3954. const note = getWeeklyNote_1(date, get_store_value(weeklyNotes));
  3955. if (!note) {
  3956. // If no file exists for a given day, show nothing.
  3957. return;
  3958. }
  3959. showFileMenu(this.app, note, {
  3960. x: event.pageX,
  3961. y: event.pageY,
  3962. });
  3963. }
  3964. onNoteSettingsUpdate() {
  3965. dailyNotes.reindex();
  3966. weeklyNotes.reindex();
  3967. this.updateActiveFile();
  3968. }
  3969. async onFileDeleted(file) {
  3970. if (getDateFromFile_1(file, "day")) {
  3971. dailyNotes.reindex();
  3972. this.updateActiveFile();
  3973. }
  3974. if (getDateFromFile_1(file, "week")) {
  3975. weeklyNotes.reindex();
  3976. this.updateActiveFile();
  3977. }
  3978. }
  3979. async onFileModified(file) {
  3980. const date = getDateFromFile_1(file, "day") || getDateFromFile_1(file, "week");
  3981. if (date && this.calendar) {
  3982. this.calendar.tick();
  3983. }
  3984. }
  3985. onFileCreated(file) {
  3986. if (this.app.workspace.layoutReady && this.calendar) {
  3987. if (getDateFromFile_1(file, "day")) {
  3988. dailyNotes.reindex();
  3989. this.calendar.tick();
  3990. }
  3991. if (getDateFromFile_1(file, "week")) {
  3992. weeklyNotes.reindex();
  3993. this.calendar.tick();
  3994. }
  3995. }
  3996. }
  3997. onFileOpen(_file) {
  3998. if (this.app.workspace.layoutReady) {
  3999. this.updateActiveFile();
  4000. }
  4001. }
  4002. updateActiveFile() {
  4003. const { view } = this.app.workspace.activeLeaf;
  4004. let file = null;
  4005. if (view instanceof obsidian.FileView) {
  4006. file = view.file;
  4007. }
  4008. activeFile.setFile(file);
  4009. if (this.calendar) {
  4010. this.calendar.tick();
  4011. }
  4012. }
  4013. revealActiveNote() {
  4014. const { moment } = window;
  4015. const { activeLeaf } = this.app.workspace;
  4016. if (activeLeaf.view instanceof obsidian.FileView) {
  4017. // Check to see if the active note is a daily-note
  4018. let date = getDateFromFile_1(activeLeaf.view.file, "day");
  4019. if (date) {
  4020. this.calendar.$set({ displayedMonth: date });
  4021. return;
  4022. }
  4023. // Check to see if the active note is a weekly-note
  4024. const { format } = getWeeklyNoteSettings_1();
  4025. date = moment(activeLeaf.view.file.basename, format, true);
  4026. if (date.isValid()) {
  4027. this.calendar.$set({ displayedMonth: date });
  4028. return;
  4029. }
  4030. }
  4031. }
  4032. async openOrCreateWeeklyNote(date, inNewSplit) {
  4033. const { workspace } = this.app;
  4034. const startOfWeek = date.clone().startOf("week");
  4035. const existingFile = getWeeklyNote_1(date, get_store_value(weeklyNotes));
  4036. if (!existingFile) {
  4037. // File doesn't exist
  4038. tryToCreateWeeklyNote(startOfWeek, inNewSplit, this.settings, (file) => {
  4039. activeFile.setFile(file);
  4040. });
  4041. return;
  4042. }
  4043. const leaf = inNewSplit
  4044. ? workspace.splitActiveLeaf()
  4045. : workspace.getUnpinnedLeaf();
  4046. await leaf.openFile(existingFile);
  4047. activeFile.setFile(existingFile);
  4048. }
  4049. async openOrCreateDailyNote(date, inNewSplit) {
  4050. const { workspace } = this.app;
  4051. const existingFile = getDailyNote_1(date, get_store_value(dailyNotes));
  4052. if (!existingFile) {
  4053. // File doesn't exist
  4054. tryToCreateDailyNote(date, inNewSplit, this.settings, (dailyNote) => {
  4055. activeFile.setFile(dailyNote);
  4056. });
  4057. return;
  4058. }
  4059. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4060. const mode = this.app.vault.getConfig("defaultViewMode");
  4061. const leaf = inNewSplit
  4062. ? workspace.splitActiveLeaf()
  4063. : workspace.getUnpinnedLeaf();
  4064. await leaf.openFile(existingFile, { mode });
  4065. activeFile.setFile(existingFile);
  4066. }
  4067. }
  4068. class CalendarPlugin extends obsidian.Plugin {
  4069. onunload() {
  4070. this.app.workspace
  4071. .getLeavesOfType(VIEW_TYPE_CALENDAR)
  4072. .forEach((leaf) => leaf.detach());
  4073. }
  4074. async onload() {
  4075. this.register(settings.subscribe((value) => {
  4076. this.options = value;
  4077. }));
  4078. this.registerView(VIEW_TYPE_CALENDAR, (leaf) => (this.view = new CalendarView(leaf)));
  4079. this.addCommand({
  4080. id: "show-calendar-view",
  4081. name: "Open view",
  4082. checkCallback: (checking) => {
  4083. if (checking) {
  4084. return (this.app.workspace.getLeavesOfType(VIEW_TYPE_CALENDAR).length === 0);
  4085. }
  4086. this.initLeaf();
  4087. },
  4088. });
  4089. this.addCommand({
  4090. id: "open-weekly-note",
  4091. name: "Open Weekly Note",
  4092. checkCallback: (checking) => {
  4093. if (checking) {
  4094. return !appHasPeriodicNotesPluginLoaded();
  4095. }
  4096. this.view.openOrCreateWeeklyNote(window.moment(), false);
  4097. },
  4098. });
  4099. this.addCommand({
  4100. id: "reveal-active-note",
  4101. name: "Reveal active note",
  4102. callback: () => this.view.revealActiveNote(),
  4103. });
  4104. await this.loadOptions();
  4105. this.addSettingTab(new CalendarSettingsTab(this.app, this));
  4106. if (this.app.workspace.layoutReady) {
  4107. this.initLeaf();
  4108. }
  4109. else {
  4110. this.registerEvent(this.app.workspace.on("layout-ready", this.initLeaf.bind(this)));
  4111. }
  4112. }
  4113. initLeaf() {
  4114. if (this.app.workspace.getLeavesOfType(VIEW_TYPE_CALENDAR).length) {
  4115. return;
  4116. }
  4117. this.app.workspace.getRightLeaf(false).setViewState({
  4118. type: VIEW_TYPE_CALENDAR,
  4119. });
  4120. }
  4121. async loadOptions() {
  4122. const options = await this.loadData();
  4123. settings.update((old) => {
  4124. return Object.assign(Object.assign({}, old), (options || {}));
  4125. });
  4126. await this.saveData(this.options);
  4127. }
  4128. async writeOptions(changeOpts) {
  4129. settings.update((old) => (Object.assign(Object.assign({}, old), changeOpts(old))));
  4130. await this.saveData(this.options);
  4131. }
  4132. }
  4133. module.exports = CalendarPlugin;