From 3c206c6ac2d77c2fa1beb34c7270ab266f363f71 Mon Sep 17 00:00:00 2001 From: JP Cen Date: Tue, 29 Oct 2024 17:05:33 -0400 Subject: [PATCH] 0.9.1010 --- main.js | 2 +- manifest.json | 2 +- .../react/components/PathView/NoteView.tsx | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/main.js b/main.js index 7805f14..5f7e8d3 100644 --- a/main.js +++ b/main.js @@ -297,7 +297,7 @@ In case of a (multi dimensional) array or matrix, the prob order quantile of all //! moment.js //! momentjs.com //! version : 2.29.4 -`,{name:"Superstate Indexer"})}var A5=class{constructor(t,r){this.numWorkers=t;this.cache=r;this.workers=[],this.busy=[],this.reloadQueue=[],this.reloadSet=new Set,this.callbacks=new Map;for(let n=0;nthis.finish(a.data.job,a.data.result,n),this.workers.push(i),this.busy.push(!1)}}reload(t){let r=F2(t),n=new Promise((a,o)=>{this.callbacks.has(r)?this.callbacks.get(r)?.push([a,o]):this.callbacks.set(r,[[a,o]])});if(this.reloadSet.has(r))return n;this.reloadSet.add(r);let i=this.nextAvailableWorker();return i!==void 0?this.send(t,i):this.reloadQueue.push(t),n}finish(t,r,n){let i=F2(t),a=[].concat(this.callbacks.get(i)??[]);this.reloadSet.delete(i),this.callbacks.delete(i),this.busy[n]=!1;let o=this.reloadQueue.shift();if(o!==void 0&&this.send(o,n),"$error"in r)for(let[s,l]of a)l(r.$error);else for(let[s,l]of a)s(r)}async send(t,r){if(t.type=="paths"){let n=await this.cache.spaceManager.allCaches(),i={settings:this.cache.settings,spacesCache:this.cache.spacesIndex,pathCache:n,oldMetadata:this.cache.pathsIndex};this.message(r,{job:t,payload:i}),this.busy[r]=!0;return}if(t.type=="path"){let n=this.cache.spacesIndex.get(t.path),i=t.path,a;n&&(a=n.space.name,this.cache.settings.enableFolderNote?i=n.space.notePath:i=n.space.defPath);let o=await this.cache.spaceManager.readPathCache(i)??await this.cache.spaceManager.readPathCache(t.path);a=a??o?.label.name;let s=await this.cache.spaceManager.parentPathForPath(t.path),l=n?"space":o.type,u=n?n.type:o?.subtype,c={path:t.path,settings:this.cache.settings,spacesCache:this.cache.spacesIndex,pathMetadata:o,name:a,parent:s,type:l,subtype:u,oldMetadata:this.cache.pathsIndex.get(t.path)};this.message(r,{job:t,payload:c}),this.busy[r]=!0;return}if(t.type=="context"){let n=this.cache.spacesIndex.get(t.path)?.space;if(!n||!n.path){this.message(r,{job:t,payload:{space:n,mdb:null,paths:[...this.cache.spacesMap.getInverse(t.path)],pathsIndex:this.cache.pathsIndex}}),this.busy[r]=!0;return}let i=await this.cache.spaceManager.contextInitiated(n.path);this.cache.spaceManager.readAllTables(n.path).then(a=>{this.message(r,{job:t,payload:{space:n,mdb:a,paths:[...this.cache.spacesMap.getInverse(t.path)],dbExists:i,pathsIndex:this.cache.pathsIndex}}),this.busy[r]=!0});return}if(t.type=="contexts"){let n=this.cache.allSpaces().filter(a=>a.type!="default").map(a=>a.space),i=new Map;for(let a of n){let o=await this.cache.spaceManager.contextInitiated(a.path);await this.cache.spaceManager.readAllTables(a.path).then(s=>{i.set(a.path,{space:a,mdb:s,paths:[...this.cache.spacesMap.getInverse(a.path)],dbExists:o})})}this.message(r,{job:t,payload:{map:i,pathsIndex:this.cache.pathsIndex}}),this.busy[r]=!0}}message(t,r){this.workers[t].postMessage(r)}nextAvailableWorker(){let t=this.busy.indexOf(!1);return t==-1?void 0:t}};function RH(){return pC('"use strict";function Xe(t){return Array.isArray(t)?t:typeof t=="string"?[t]:[]}var Je=(t,e)=>e.indexOf(t)>0?e.indexOf(t):e.length;function H(t){return H=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},H(t)}function O(t){if(t===null||t===!0||t===!1)return NaN;var e=Number(t);return isNaN(e)?e:e<0?Math.ceil(e):Math.floor(e)}function x(t,e){if(e.length1?"s":"")+" required, but only "+e.length+" present")}function y(t){x(1,arguments);var e=Object.prototype.toString.call(t);return t instanceof Date||H(t)==="object"&&e==="[object Date]"?new Date(t.getTime()):typeof t=="number"||e==="[object Number]"?new Date(t):((typeof t=="string"||e==="[object String]")&&typeof console<"u"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn\'t accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function me(t,e){x(2,arguments);var r=y(t).getTime(),n=O(e);return new Date(r+n)}var Lt={};function R(){return Lt}function pe(t){var e=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return e.setUTCFullYear(t.getFullYear()),t.getTime()-e.getTime()}function he(t){return x(1,arguments),t instanceof Date||H(t)==="object"&&Object.prototype.toString.call(t)==="[object Date]"}function ge(t){if(x(1,arguments),!he(t)&&typeof t!="number")return!1;var e=y(t);return!isNaN(Number(e))}function xe(t,e){x(2,arguments);var r=O(e);return me(t,-r)}var Ut=864e5;function ye(t){x(1,arguments);var e=y(t),r=e.getTime();e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0);var n=e.getTime(),a=r-n;return Math.floor(a/Ut)+1}function $(t){x(1,arguments);var e=1,r=y(t),n=r.getUTCDay(),a=(n=a.getTime()?r+1:e.getTime()>=i.getTime()?r:r-1}function ve(t){x(1,arguments);var e=te(t),r=new Date(0);r.setUTCFullYear(e,0,4),r.setUTCHours(0,0,0,0);var n=$(r);return n}var Rt=6048e5;function be(t){x(1,arguments);var e=y(t),r=$(e).getTime()-ve(e).getTime();return Math.round(r/Rt)+1}function j(t,e){var r,n,a,o,i,s,u,f;x(1,arguments);var l=R(),c=O((r=(n=(a=(o=e?.weekStartsOn)!==null&&o!==void 0?o:e==null||(i=e.locale)===null||i===void 0||(s=i.options)===null||s===void 0?void 0:s.weekStartsOn)!==null&&a!==void 0?a:l.weekStartsOn)!==null&&n!==void 0?n:(u=l.locale)===null||u===void 0||(f=u.options)===null||f===void 0?void 0:f.weekStartsOn)!==null&&r!==void 0?r:0);if(!(c>=0&&c<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var d=y(t),p=d.getUTCDay(),g=(p=1&&p<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var g=new Date(0);g.setUTCFullYear(c+1,0,p),g.setUTCHours(0,0,0,0);var v=j(g,e),T=new Date(0);T.setUTCFullYear(c,0,p),T.setUTCHours(0,0,0,0);var S=j(T,e);return l.getTime()>=v.getTime()?c+1:l.getTime()>=S.getTime()?c:c-1}function we(t,e){var r,n,a,o,i,s,u,f;x(1,arguments);var l=R(),c=O((r=(n=(a=(o=e?.firstWeekContainsDate)!==null&&o!==void 0?o:e==null||(i=e.locale)===null||i===void 0||(s=i.options)===null||s===void 0?void 0:s.firstWeekContainsDate)!==null&&a!==void 0?a:l.firstWeekContainsDate)!==null&&n!==void 0?n:(u=l.locale)===null||u===void 0||(f=u.options)===null||f===void 0?void 0:f.firstWeekContainsDate)!==null&&r!==void 0?r:1),d=re(t,e),p=new Date(0);p.setUTCFullYear(d,0,c),p.setUTCHours(0,0,0,0);var g=j(p,e);return g}var $t=6048e5;function Te(t,e){x(1,arguments);var r=y(t),n=j(r,e).getTime()-we(r,e).getTime();return Math.round(n/$t)+1}function h(t,e){for(var r=t<0?"-":"",n=Math.abs(t).toString();n.length0?n:1-n;return h(r==="yy"?a%100:a,r.length)},M:function(e,r){var n=e.getUTCMonth();return r==="M"?String(n+1):h(n+1,2)},d:function(e,r){return h(e.getUTCDate(),r.length)},a:function(e,r){var n=e.getUTCHours()/12>=1?"pm":"am";switch(r){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h:function(e,r){return h(e.getUTCHours()%12||12,r.length)},H:function(e,r){return h(e.getUTCHours(),r.length)},m:function(e,r){return h(e.getUTCMinutes(),r.length)},s:function(e,r){return h(e.getUTCSeconds(),r.length)},S:function(e,r){var n=r.length,a=e.getUTCMilliseconds(),o=Math.floor(a*Math.pow(10,n-3));return h(o,r.length)}},A=jt;var J={am:"am",pm:"pm",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},qt={G:function(e,r,n){var a=e.getUTCFullYear()>0?1:0;switch(r){case"G":case"GG":case"GGG":return n.era(a,{width:"abbreviated"});case"GGGGG":return n.era(a,{width:"narrow"});case"GGGG":default:return n.era(a,{width:"wide"})}},y:function(e,r,n){if(r==="yo"){var a=e.getUTCFullYear(),o=a>0?a:1-a;return n.ordinalNumber(o,{unit:"year"})}return A.y(e,r)},Y:function(e,r,n,a){var o=re(e,a),i=o>0?o:1-o;if(r==="YY"){var s=i%100;return h(s,2)}return r==="Yo"?n.ordinalNumber(i,{unit:"year"}):h(i,r.length)},R:function(e,r){var n=te(e);return h(n,r.length)},u:function(e,r){var n=e.getUTCFullYear();return h(n,r.length)},Q:function(e,r,n){var a=Math.ceil((e.getUTCMonth()+1)/3);switch(r){case"Q":return String(a);case"QQ":return h(a,2);case"Qo":return n.ordinalNumber(a,{unit:"quarter"});case"QQQ":return n.quarter(a,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(a,{width:"narrow",context:"formatting"});case"QQQQ":default:return n.quarter(a,{width:"wide",context:"formatting"})}},q:function(e,r,n){var a=Math.ceil((e.getUTCMonth()+1)/3);switch(r){case"q":return String(a);case"qq":return h(a,2);case"qo":return n.ordinalNumber(a,{unit:"quarter"});case"qqq":return n.quarter(a,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(a,{width:"narrow",context:"standalone"});case"qqqq":default:return n.quarter(a,{width:"wide",context:"standalone"})}},M:function(e,r,n){var a=e.getUTCMonth();switch(r){case"M":case"MM":return A.M(e,r);case"Mo":return n.ordinalNumber(a+1,{unit:"month"});case"MMM":return n.month(a,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(a,{width:"narrow",context:"formatting"});case"MMMM":default:return n.month(a,{width:"wide",context:"formatting"})}},L:function(e,r,n){var a=e.getUTCMonth();switch(r){case"L":return String(a+1);case"LL":return h(a+1,2);case"Lo":return n.ordinalNumber(a+1,{unit:"month"});case"LLL":return n.month(a,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(a,{width:"narrow",context:"standalone"});case"LLLL":default:return n.month(a,{width:"wide",context:"standalone"})}},w:function(e,r,n,a){var o=Te(e,a);return r==="wo"?n.ordinalNumber(o,{unit:"week"}):h(o,r.length)},I:function(e,r,n){var a=be(e);return r==="Io"?n.ordinalNumber(a,{unit:"week"}):h(a,r.length)},d:function(e,r,n){return r==="do"?n.ordinalNumber(e.getUTCDate(),{unit:"date"}):A.d(e,r)},D:function(e,r,n){var a=ye(e);return r==="Do"?n.ordinalNumber(a,{unit:"dayOfYear"}):h(a,r.length)},E:function(e,r,n){var a=e.getUTCDay();switch(r){case"E":case"EE":case"EEE":return n.day(a,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(a,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(a,{width:"short",context:"formatting"});case"EEEE":default:return n.day(a,{width:"wide",context:"formatting"})}},e:function(e,r,n,a){var o=e.getUTCDay(),i=(o-a.weekStartsOn+8)%7||7;switch(r){case"e":return String(i);case"ee":return h(i,2);case"eo":return n.ordinalNumber(i,{unit:"day"});case"eee":return n.day(o,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(o,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(o,{width:"short",context:"formatting"});case"eeee":default:return n.day(o,{width:"wide",context:"formatting"})}},c:function(e,r,n,a){var o=e.getUTCDay(),i=(o-a.weekStartsOn+8)%7||7;switch(r){case"c":return String(i);case"cc":return h(i,r.length);case"co":return n.ordinalNumber(i,{unit:"day"});case"ccc":return n.day(o,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(o,{width:"narrow",context:"standalone"});case"cccccc":return n.day(o,{width:"short",context:"standalone"});case"cccc":default:return n.day(o,{width:"wide",context:"standalone"})}},i:function(e,r,n){var a=e.getUTCDay(),o=a===0?7:a;switch(r){case"i":return String(o);case"ii":return h(o,r.length);case"io":return n.ordinalNumber(o,{unit:"day"});case"iii":return n.day(a,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(a,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(a,{width:"short",context:"formatting"});case"iiii":default:return n.day(a,{width:"wide",context:"formatting"})}},a:function(e,r,n){var a=e.getUTCHours(),o=a/12>=1?"pm":"am";switch(r){case"a":case"aa":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(o,{width:"narrow",context:"formatting"});case"aaaa":default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},b:function(e,r,n){var a=e.getUTCHours(),o;switch(a===12?o=J.noon:a===0?o=J.midnight:o=a/12>=1?"pm":"am",r){case"b":case"bb":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(o,{width:"narrow",context:"formatting"});case"bbbb":default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},B:function(e,r,n){var a=e.getUTCHours(),o;switch(a>=17?o=J.evening:a>=12?o=J.afternoon:a>=4?o=J.morning:o=J.night,r){case"B":case"BB":case"BBB":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(o,{width:"narrow",context:"formatting"});case"BBBB":default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},h:function(e,r,n){if(r==="ho"){var a=e.getUTCHours()%12;return a===0&&(a=12),n.ordinalNumber(a,{unit:"hour"})}return A.h(e,r)},H:function(e,r,n){return r==="Ho"?n.ordinalNumber(e.getUTCHours(),{unit:"hour"}):A.H(e,r)},K:function(e,r,n){var a=e.getUTCHours()%12;return r==="Ko"?n.ordinalNumber(a,{unit:"hour"}):h(a,r.length)},k:function(e,r,n){var a=e.getUTCHours();return a===0&&(a=24),r==="ko"?n.ordinalNumber(a,{unit:"hour"}):h(a,r.length)},m:function(e,r,n){return r==="mo"?n.ordinalNumber(e.getUTCMinutes(),{unit:"minute"}):A.m(e,r)},s:function(e,r,n){return r==="so"?n.ordinalNumber(e.getUTCSeconds(),{unit:"second"}):A.s(e,r)},S:function(e,r){return A.S(e,r)},X:function(e,r,n,a){var o=a._originalDate||e,i=o.getTimezoneOffset();if(i===0)return"Z";switch(r){case"X":return Ze(i);case"XXXX":case"XX":return Q(i);case"XXXXX":case"XXX":default:return Q(i,":")}},x:function(e,r,n,a){var o=a._originalDate||e,i=o.getTimezoneOffset();switch(r){case"x":return Ze(i);case"xxxx":case"xx":return Q(i);case"xxxxx":case"xxx":default:return Q(i,":")}},O:function(e,r,n,a){var o=a._originalDate||e,i=o.getTimezoneOffset();switch(r){case"O":case"OO":case"OOO":return"GMT"+Ke(i,":");case"OOOO":default:return"GMT"+Q(i,":")}},z:function(e,r,n,a){var o=a._originalDate||e,i=o.getTimezoneOffset();switch(r){case"z":case"zz":case"zzz":return"GMT"+Ke(i,":");case"zzzz":default:return"GMT"+Q(i,":")}},t:function(e,r,n,a){var o=a._originalDate||e,i=Math.floor(o.getTime()/1e3);return h(i,r.length)},T:function(e,r,n,a){var o=a._originalDate||e,i=o.getTime();return h(i,r.length)}};function Ke(t,e){var r=t>0?"-":"+",n=Math.abs(t),a=Math.floor(n/60),o=n%60;if(o===0)return r+String(a);var i=e||"";return r+String(a)+i+h(o,2)}function Ze(t,e){if(t%60===0){var r=t>0?"-":"+";return r+h(Math.abs(t)/60,2)}return Q(t,e)}function Q(t,e){var r=e||"",n=t>0?"-":"+",a=Math.abs(t),o=h(Math.floor(a/60),2),i=h(a%60,2);return n+o+r+i}var et=qt;var tt=function(e,r){switch(e){case"P":return r.date({width:"short"});case"PP":return r.date({width:"medium"});case"PPP":return r.date({width:"long"});case"PPPP":default:return r.date({width:"full"})}},rt=function(e,r){switch(e){case"p":return r.time({width:"short"});case"pp":return r.time({width:"medium"});case"ppp":return r.time({width:"long"});case"pppp":default:return r.time({width:"full"})}},Ht=function(e,r){var n=e.match(/(P+)(p+)?/)||[],a=n[1],o=n[2];if(!o)return tt(e,r);var i;switch(a){case"P":i=r.dateTime({width:"short"});break;case"PP":i=r.dateTime({width:"medium"});break;case"PPP":i=r.dateTime({width:"long"});break;case"PPPP":default:i=r.dateTime({width:"full"});break}return i.replace("{{date}}",tt(a,r)).replace("{{time}}",rt(o,r))},Qt={p:rt,P:Ht},nt=Qt;var Bt=["D","DD"],Gt=["YY","YYYY"];function at(t){return Bt.indexOf(t)!==-1}function ot(t){return Gt.indexOf(t)!==-1}function Se(t,e,r){if(t==="YYYY")throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(e,"`) for formatting years to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(t==="YY")throw new RangeError("Use `yy` instead of `YY` (in `".concat(e,"`) for formatting years to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(t==="D")throw new RangeError("Use `d` instead of `D` (in `".concat(e,"`) for formatting days of the month to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(t==="DD")throw new RangeError("Use `dd` instead of `DD` (in `".concat(e,"`) for formatting days of the month to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"))}var Vt={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},Xt=function(e,r,n){var a,o=Vt[e];return typeof o=="string"?a=o:r===1?a=o.one:a=o.other.replace("{{count}}",r.toString()),n!=null&&n.addSuffix?n.comparison&&n.comparison>0?"in "+a:a+" ago":a},it=Xt;function ne(t){return function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=e.width?String(e.width):t.defaultWidth,n=t.formats[r]||t.formats[t.defaultWidth];return n}}var Jt={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},zt={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},Kt={full:"{{date}} \'at\' {{time}}",long:"{{date}} \'at\' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},Zt={date:ne({formats:Jt,defaultWidth:"full"}),time:ne({formats:zt,defaultWidth:"full"}),dateTime:ne({formats:Kt,defaultWidth:"full"})},st=Zt;var er={lastWeek:"\'last\' eeee \'at\' p",yesterday:"\'yesterday at\' p",today:"\'today at\' p",tomorrow:"\'tomorrow at\' p",nextWeek:"eeee \'at\' p",other:"P"},tr=function(e,r,n,a){return er[e]},ut=tr;function B(t){return function(e,r){var n=r!=null&&r.context?String(r.context):"standalone",a;if(n==="formatting"&&t.formattingValues){var o=t.defaultFormattingWidth||t.defaultWidth,i=r!=null&&r.width?String(r.width):o;a=t.formattingValues[i]||t.formattingValues[o]}else{var s=t.defaultWidth,u=r!=null&&r.width?String(r.width):t.defaultWidth;a=t.values[u]||t.values[s]}var f=t.argumentCallback?t.argumentCallback(e):e;return a[f]}}var rr={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},nr={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},ar={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},or={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},ir={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},sr={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},ur=function(e,r){var n=Number(e),a=n%100;if(a>20||a<10)switch(a%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},fr={ordinalNumber:ur,era:B({values:rr,defaultWidth:"wide"}),quarter:B({values:nr,defaultWidth:"wide",argumentCallback:function(e){return e-1}}),month:B({values:ar,defaultWidth:"wide"}),day:B({values:or,defaultWidth:"wide"}),dayPeriod:B({values:ir,defaultWidth:"wide",formattingValues:sr,defaultFormattingWidth:"wide"})},ft=fr;function G(t){return function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=r.width,a=n&&t.matchPatterns[n]||t.matchPatterns[t.defaultMatchWidth],o=e.match(a);if(!o)return null;var i=o[0],s=n&&t.parsePatterns[n]||t.parsePatterns[t.defaultParseWidth],u=Array.isArray(s)?cr(s,function(c){return c.test(i)}):lr(s,function(c){return c.test(i)}),f;f=t.valueCallback?t.valueCallback(u):u,f=r.valueCallback?r.valueCallback(f):f;var l=e.slice(i.length);return{value:f,rest:l}}}function lr(t,e){for(var r in t)if(t.hasOwnProperty(r)&&e(t[r]))return r}function cr(t,e){for(var r=0;r1&&arguments[1]!==void 0?arguments[1]:{},n=e.match(t.matchPattern);if(!n)return null;var a=n[0],o=e.match(t.parsePattern);if(!o)return null;var i=t.valueCallback?t.valueCallback(o[0]):o[0];i=r.valueCallback?r.valueCallback(i):i;var s=e.slice(a.length);return{value:i,rest:s}}}var dr=/^(\\d+)(th|st|nd|rd)?/i,mr=/\\d+/i,pr={narrow:/^(b|a)/i,abbreviated:/^(b\\.?\\s?c\\.?|b\\.?\\s?c\\.?\\s?e\\.?|a\\.?\\s?d\\.?|c\\.?\\s?e\\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},hr={any:[/^b/i,/^(a|c)/i]},gr={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},xr={any:[/1/i,/2/i,/3/i,/4/i]},yr={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},vr={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},br={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},wr={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},Tr={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\\.?\\s?m\\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},Sr={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},Or={ordinalNumber:Oe({matchPattern:dr,parsePattern:mr,valueCallback:function(e){return parseInt(e,10)}}),era:G({matchPatterns:pr,defaultMatchWidth:"wide",parsePatterns:hr,defaultParseWidth:"any"}),quarter:G({matchPatterns:gr,defaultMatchWidth:"wide",parsePatterns:xr,defaultParseWidth:"any",valueCallback:function(e){return e+1}}),month:G({matchPatterns:yr,defaultMatchWidth:"wide",parsePatterns:vr,defaultParseWidth:"any"}),day:G({matchPatterns:br,defaultMatchWidth:"wide",parsePatterns:wr,defaultParseWidth:"any"}),dayPeriod:G({matchPatterns:Tr,defaultMatchWidth:"any",parsePatterns:Sr,defaultParseWidth:"any"})},lt=Or;var Mr={code:"en-US",formatDistance:it,formatLong:st,formatRelative:ut,localize:ft,match:lt,options:{weekStartsOn:0,firstWeekContainsDate:1}},ct=Mr;var dt=ct;var Dr=/[yYQqMLwIdDecihHKkms]o|(\\w)\\1*|\'\'|\'(\'\'|[^\'])+(\'|$)|./g,kr=/P+p+|P+|p+|\'\'|\'(\'\'|[^\'])+(\'|$)|./g,Cr=/^\'([^]*?)\'?$/,Wr=/\'\'/g,Ir=/[a-zA-Z]/;function ie(t,e,r){var n,a,o,i,s,u,f,l,c,d,p,g,v,T,S,P,W,L;x(2,arguments);var de=String(e),E=R(),b=(n=(a=r?.locale)!==null&&a!==void 0?a:E.locale)!==null&&n!==void 0?n:dt,k=O((o=(i=(s=(u=r?.firstWeekContainsDate)!==null&&u!==void 0?u:r==null||(f=r.locale)===null||f===void 0||(l=f.options)===null||l===void 0?void 0:l.firstWeekContainsDate)!==null&&s!==void 0?s:E.firstWeekContainsDate)!==null&&i!==void 0?i:(c=E.locale)===null||c===void 0||(d=c.options)===null||d===void 0?void 0:d.firstWeekContainsDate)!==null&&o!==void 0?o:1);if(!(k>=1&&k<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var C=O((p=(g=(v=(T=r?.weekStartsOn)!==null&&T!==void 0?T:r==null||(S=r.locale)===null||S===void 0||(P=S.options)===null||P===void 0?void 0:P.weekStartsOn)!==null&&v!==void 0?v:E.weekStartsOn)!==null&&g!==void 0?g:(W=E.locale)===null||W===void 0||(L=W.options)===null||L===void 0?void 0:L.weekStartsOn)!==null&&p!==void 0?p:0);if(!(C>=0&&C<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");if(!b.localize)throw new RangeError("locale must contain localize property");if(!b.formatLong)throw new RangeError("locale must contain formatLong property");var q=y(t);if(!ge(q))throw new RangeError("Invalid time value");var ee=pe(q),U=xe(q,ee),Ve={firstWeekContainsDate:k,weekStartsOn:C,locale:b,_originalDate:q},M=de.match(kr).map(function(w){var I=w[0];if(I==="p"||I==="P"){var oe=nt[I];return oe(w,b.formatLong)}return w}).join("").match(Dr).map(function(w){if(w==="\'\'")return"\'";var I=w[0];if(I==="\'")return Pr(w);var oe=et[I];if(oe)return!(r!=null&&r.useAdditionalWeekYearTokens)&&ot(w)&&Se(w,e,String(t)),!(r!=null&&r.useAdditionalDayOfYearTokens)&&at(w)&&Se(w,e,String(t)),oe(U,w,b.localize,Ve);if(I.match(Ir))throw new RangeError("Format string contains an unescaped latin alphabet character `"+I+"`");return w}).join("");return M}function Pr(t){var e=t.match(Cr);return e?e[1].replace(Wr,"\'"):t}var mt=t=>[...new Set(t)];var Me=(t,e)=>{if(t instanceof Date)return"date";if(typeof t=="string"){if(/\\/\\/(\\S+?(?:jpe?g|png|gif|svg))/gi.test(t)||t.includes("unsplash"))return"image";if(/^\\d{4}-\\d{2}-\\d{2}$/.test(t))return"date";if(e=="tag"||e=="tags")return"tags-multi";if(/\\[\\[.*?\\]\\]/.test(t))return"link"}else{if(typeof t=="number")return"number";if(typeof t=="boolean")return"boolean";if(t)if(Array.isArray(t)||typeof t=="string"&&t.indexOf(",")>-1){let r=Array.isArray(t)?t:[];if(typeof t=="string"&&t.indexOf(",")>-1&&(r=V(t)),e=="tag"||e=="tags")return"tags-multi";if(r.length==1&&Array.isArray(r[0])&&r[0].length==1&&typeof r[0][0]=="string")return"link";let n=mt(r.map(a=>Me(a,e)));return n.length==1&&n[0]=="link"?"link-multi":n.some(a=>a=="object")?"object-multi":"option-multi"}else return t.isLuxonDateTime?"date":t.isLuxonDuration?"duration":t.type=="file"?"link":typeof t=="object"&&!Array.isArray(t)&&t!==null?"object":"unknown";else return"unknown"}return"text"};var pt=t=>t.map(e=>e.replace(",","\\\\,")).join(", "),z=t=>JSON.stringify(t);var V=t=>t?.startsWith("[")?Xe(ze(t)):Fr(t),Fr=t=>(t?.replace("\\\\,",",")?.match(/(\\\\.|[^,])+/g)??[]).map(e=>e.trim()),ke=(t,e,r)=>{let n=r??Me(e,t);if(!e)return"";switch(n){case"tags-multi":return e;case"object":case"object-multi":return JSON.stringify(e);case"number":return e.toString();case"boolean":return e?"true":"false";case"date":{if(e instanceof Date){let a=ie(e,"yyyy-MM-dd");return typeof a=="string"?a:""}return typeof e!="string"?"":e}break;case"duration":return pt(Object.keys(e.values).reduce((a,o)=>[...a,...e.values[o]>0?[e.values[o]+" "+o]:[]],[]));case"option-multi":case"link-multi":case"context-multi":return typeof e=="string"?De(e):z(e.map(a=>a?typeof a=="string"?De(a):a.path?a.path:Array.isArray(e)&&a.length==1&&Array.isArray(a[0])&&a[0].length==1&&typeof a[0][0]=="string"?a[0][0]:JSON.stringify(a):""));case"link":case"context":return Array.isArray(e)&&e.length==1&&Array.isArray(e[0])&&e[0].length==1&&typeof e[0][0]=="string"?e[0][0]:typeof e=="string"?De(e):e.path;case"text":case"tag":case"option":case"image":return e}return""};var ze=t=>{let e;try{e=JSON.parse(t)}catch{}return e};var De=t=>{if(!t)return"";let e=/\\[\\[(.*?)\\]\\]/g.exec(t),r=e?.length>1?e[1].substring(0,Je("|",e[1])):t;return r||t};var ht=(t,e)=>{let r=t?V(t):[],n=e?V(e):[];return n.every(a=>r.some(o=>o==a))&&r.every(a=>n.some(o=>o==a))},K=(t,e)=>t==e,Ce=(t,e)=>(t??"").length==0,We=(t,e)=>(t??"").toLowerCase().includes((e??"").toLowerCase()),Ie=(t,e)=>parseFloat(t)>parseFloat(e),Pe=(t,e)=>parseInt(t){let r=isNaN(Date.parse(t))?new Date(parseInt(t)):new Date(t),n=isNaN(Date.parse(e))?new Date(parseInt(e)):new Date(e);return r.valueOf()>=n.valueOf()},xt=(t,e)=>{let r=isNaN(Date.parse(t))?new Date(parseInt(t)):new Date(t),n=isNaN(Date.parse(e))?new Date(parseInt(e)):new Date(e);return r.valueOf(){let r=t?V(t):[],n=e?V(e):[];return r.length==0?!1:n.some(a=>r.some(o=>o==a))},yt=(t,e)=>{if(!t)return!1;let r=new Date(`${t.toString().replace(".",":")}`),n=new Date(`${e}`);return r.getMonth()===n.getMonth()&&r.getDate()===n.getDate()},vt=t=>{if(!t)return!1;let e=new Date(`${t.toString()}T00:00`),r=new Date;return e.getMonth()===r.getMonth()&&e.getDate()===r.getDate()};var Z={isNotEmpty:{type:["text","file","number","option","option-multi","link","link-multi","image"],fn:(t,e)=>!Ce(t,""),valueType:"none"},isEmpty:{type:["text","file","number","option","option-multi","link","link-multi","image"],fn:(t,e)=>Ce(t,""),valueType:"none"},include:{fn:(t,e)=>We(t,e),type:["text","file","link","image"],valueType:"text"},notInclude:{type:["text","file","link","image"],fn:(t,e)=>!We(t,e),valueType:"text"},is:{type:["text"],fn:(t,e)=>K(t,e),valueType:"text"},isNot:{type:["text"],fn:(t,e)=>!K(t,e),valueType:"text"},equal:{type:["number"],fn:(t,e)=>K(t,e),valueType:"number"},isLink:{type:["link","context"],fn:(t,e)=>K(t,e),valueType:"link"},isNotLink:{type:["link","context"],fn:(t,e)=>!K(t,e),valueType:"link"},isGreatThan:{type:["number"],fn:(t,e)=>Ie(t,e),valueType:"number"},isLessThan:{type:["number"],fn:(t,e)=>Pe(t,e),valueType:"number"},isLessThanOrEqual:{type:["number"],fn:(t,e)=>!Ie(t,e),valueType:"number"},isGreatThanOrEqual:{type:["number"],fn:(t,e)=>!Pe(t,e),valueType:"number"},dateBefore:{type:["date"],fn:(t,e)=>xt(t,e),valueType:"date"},dateAfter:{type:["date"],fn:(t,e)=>gt(t,e),valueType:"date"},isSameDate:{type:["date"],fn:(t,e)=>yt(t,e),valueType:"date"},isSameDateAsToday:{type:["date"],fn:(t,e)=>vt(t,e),valueType:"none"},isExactList:{type:["option","option-multi","link-multi","context-multi","tags-multi"],fn:(t,e)=>ht(t,e),valueType:"list"},isAnyInList:{type:["option","context","link","option-multi","link-multi","context-multi","tags-multi"],fn:(t,e)=>Fe(t,e),valueType:"list"},isNoneInList:{type:["option","context","link","option-multi","link-multi","context-multi","tags-multi"],fn:(t,e)=>!Fe(t,e),valueType:"list"},isTrue:{type:["boolean"],fn:(t,e)=>t=="true",valueType:"none"},isFalse:{type:["boolean"],fn:(t,e)=>t!="true",valueType:"none"}};var _r=(t,e,r)=>e.reduce((a,o)=>{let[i,s]=a,u=o.type=="context"?bt(s,o,r):o.type=="path"?Tt(s,o,r):o.type=="frontmatter"?wt(s,o,r):St(s,o,r),f=s.filter(l=>!u.includes(l));return[[...i,...u],f]},[[],t])[0],Er=(t,e,r)=>e.reduce((n,a)=>a.type=="context"?bt(n,a,r):a.type=="path"?Tt(n,a,r):a.type=="frontmatter"?wt(n,a,r):St(n,a,r),t),bt=(t,e,r)=>{let n=Z[e.fn];return!n||n.valueType!="none"&&e.value.length==0?[]:t.filter(a=>{let[o,i]=e.field.split("."),s=a.metadata?.property;if(!a.spaces?.includes(o)||!s||!s[i])return!1;let u=!0;if(n){let f=e.fType=="property"?r[e.value]:e.value;u=n.fn(ke(i,s[i]),f)}return u})},wt=(t,e,r)=>{let n=Z[e.fn];return!n||n.valueType!="none"&&e.value.length==0?[]:t.filter(a=>{let o=a.metadata?.property;if(!o||o[e.field]===void 0)return!1;let i=!0;if(n){let s=e.fType=="property"?r[e.value]:e.value;i=n.fn(ke(e.field,o[e.field]),s)}return i})},Tt=(t,e,r)=>{let n=Z[e.fn];return!n||n.valueType!="none"&&e.value.length==0?[]:t.filter(a=>{let o="";e.field=="outlinks"?o=z(a.outlinks??[]):e.field=="inlinks"?o=z(a.metadata?.inlinks??[]):e.field=="tags"&&(o=z(a.tags??[]));let i=!0;if(n){let s=e.fType=="property"?r[e.value]:e.value;i=n.fn(o,s)}return i})},St=(t,e,r)=>{let n=Z[e.fn];return!n||n.valueType!="none"&&e.value.length==0?[]:t.filter(a=>{let o=!0;if(n){let i=e.fType=="property"?r[e.value]:e.value;o=n.fn(a.metadata?.[e.type]?.[e.field],i)}return o})},Ot=(t,e,r)=>t.reduce((a,o)=>!a||o.filters.length==0?!1:o.type=="any"?_r([e],o.filters,r).length>0:Er([e],o.filters,r).length>0,!0);function Y(t){return Array.isArray?Array.isArray(t):Ft(t)==="[object Array]"}var Ar=1/0;function Yr(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-Ar?"-0":e}function Nr(t){return t==null?"":Yr(t)}function F(t){return typeof t=="string"}function It(t){return typeof t=="number"}function Lr(t){return t===!0||t===!1||Ur(t)&&Ft(t)=="[object Boolean]"}function Pt(t){return typeof t=="object"}function Ur(t){return Pt(t)&&t!==null}function D(t){return t!=null}function _e(t){return!t.trim().length}function Ft(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}var Rr="Incorrect \'index\' type",$r=t=>`Invalid value for key ${t}`,jr=t=>`Pattern length exceeds max of ${t}.`,qr=t=>`Missing ${t} property in key`,Hr=t=>`Property \'weight\' in key \'${t}\' must be a positive integer`,Mt=Object.prototype.hasOwnProperty,Ee=class{constructor(e){this._keys=[],this._keyMap={};let r=0;e.forEach(n=>{let a=_t(n);this._keys.push(a),this._keyMap[a.id]=a,r+=a.weight}),this._keys.forEach(n=>{n.weight/=r})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function _t(t){let e=null,r=null,n=null,a=1,o=null;if(F(t)||Y(t))n=t,e=Dt(t),r=Ae(t);else{if(!Mt.call(t,"name"))throw new Error(qr("name"));let i=t.name;if(n=i,Mt.call(t,"weight")&&(a=t.weight,a<=0))throw new Error(Hr(i));e=Dt(i),r=Ae(i),o=t.getFn}return{path:e,id:r,weight:a,src:n,getFn:o}}function Dt(t){return Y(t)?t:t.split(".")}function Ae(t){return Y(t)?t.join("."):t}function Qr(t,e){let r=[],n=!1,a=(o,i,s)=>{if(!!D(o))if(!i[s])r.push(o);else{let u=i[s],f=o[u];if(!D(f))return;if(s===i.length-1&&(F(f)||It(f)||Lr(f)))r.push(Nr(f));else if(Y(f)){n=!0;for(let l=0,c=f.length;lt.score===e.score?t.idx{this._keysMap[r.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,F(this.docs[0])?this.docs.forEach((e,r)=>{this._addString(e,r)}):this.docs.forEach((e,r)=>{this._addObject(e,r)}),this.norm.clear())}add(e){let r=this.size();F(e)?this._addString(e,r):this._addObject(e,r)}removeAt(e){this.records.splice(e,1);for(let r=e,n=this.size();r{let i=a.getFn?a.getFn(e):this.getFn(e,a.path);if(!!D(i)){if(Y(i)){let s=[],u=[{nestedArrIndex:-1,value:i}];for(;u.length;){let{nestedArrIndex:f,value:l}=u.pop();if(!!D(l))if(F(l)&&!_e(l)){let c={v:l,i:f,n:this.norm.get(l)};s.push(c)}else Y(l)&&l.forEach((c,d)=>{u.push({nestedArrIndex:d,value:c})})}n.$[o]=s}else if(F(i)&&!_e(i)){let s={v:i,n:this.norm.get(i)};n.$[o]=s}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}};function Et(t,e,{getFn:r=m.getFn,fieldNormWeight:n=m.fieldNormWeight}={}){let a=new ae({getFn:r,fieldNormWeight:n});return a.setKeys(t.map(_t)),a.setSources(e),a.create(),a}function Kr(t,{getFn:e=m.getFn,fieldNormWeight:r=m.fieldNormWeight}={}){let{keys:n,records:a}=t,o=new ae({getFn:e,fieldNormWeight:r});return o.setKeys(n),o.setIndexRecords(a),o}function se(t,{errors:e=0,currentLocation:r=0,expectedLocation:n=0,distance:a=m.distance,ignoreLocation:o=m.ignoreLocation}={}){let i=e/t.length;if(o)return i;let s=Math.abs(n-r);return a?i+s/a:s?1:i}function Zr(t=[],e=m.minMatchCharLength){let r=[],n=-1,a=-1,o=0;for(let i=t.length;o=e&&r.push([n,a]),n=-1)}return t[o-1]&&o-n>=e&&r.push([n,o-1]),r}var X=32;function en(t,e,r,{location:n=m.location,distance:a=m.distance,threshold:o=m.threshold,findAllMatches:i=m.findAllMatches,minMatchCharLength:s=m.minMatchCharLength,includeMatches:u=m.includeMatches,ignoreLocation:f=m.ignoreLocation}={}){if(e.length>X)throw new Error(jr(X));let l=e.length,c=t.length,d=Math.max(0,Math.min(n,c)),p=o,g=d,v=s>1||u,T=v?Array(c):[],S;for(;(S=t.indexOf(e,g))>-1;){let b=se(e,{currentLocation:S,expectedLocation:d,distance:a,ignoreLocation:f});if(p=Math.min(b,p),g=S+l,v){let k=0;for(;k=q;M-=1){let w=M-1,I=r[t.charAt(w)];if(v&&(T[w]=+!!I),U[M]=(U[M+1]<<1|1)&I,b&&(U[M]|=(P[M+1]|P[M])<<1|1|P[M+1]),U[M]&de&&(W=se(e,{errors:b,currentLocation:w,expectedLocation:d,distance:a,ignoreLocation:f}),W<=p)){if(p=W,g=w,g<=d)break;q=Math.max(1,2*d-g)}}if(se(e,{errors:b+1,currentLocation:d,expectedLocation:d,distance:a,ignoreLocation:f})>p)break;P=U}let E={isMatch:g>=0,score:Math.max(.001,W)};if(v){let b=Zr(T,s);b.length?u&&(E.indices=b):E.isMatch=!1}return E}function tn(t){let e={};for(let r=0,n=t.length;r{this.chunks.push({pattern:d,alphabet:tn(d),startIndex:p})},c=this.pattern.length;if(c>X){let d=0,p=c%X,g=c-p;for(;d{let{isMatch:S,score:P,indices:W}=en(e,g,v,{location:a+T,distance:o,threshold:i,findAllMatches:s,minMatchCharLength:u,includeMatches:n,ignoreLocation:f});S&&(d=!0),c+=P,S&&W&&(l=[...l,...W])});let p={isMatch:d,score:d?c/this.chunks.length:1};return d&&n&&(p.indices=l),p}},_=class{constructor(e){this.pattern=e}static isMultiMatch(e){return kt(e,this.multiRegex)}static isSingleMatch(e){return kt(e,this.singleRegex)}search(){}};function kt(t,e){let r=t.match(e);return r?r[1]:null}var Ye=class extends _{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){let r=e===this.pattern;return{isMatch:r,score:r?0:1,indices:[0,this.pattern.length-1]}}},Ne=class extends _{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){let n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}},Le=class extends _{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\\^"(.*)"$/}static get singleRegex(){return/^\\^(.*)$/}search(e){let r=e.startsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,this.pattern.length-1]}}},Ue=class extends _{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\\^"(.*)"$/}static get singleRegex(){return/^!\\^(.*)$/}search(e){let r=!e.startsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}},Re=class extends _{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\\$$/}static get singleRegex(){return/^(.*)\\$$/}search(e){let r=e.endsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[e.length-this.pattern.length,e.length-1]}}},$e=class extends _{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\\$$/}static get singleRegex(){return/^!(.*)\\$$/}search(e){let r=!e.endsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}},fe=class extends _{constructor(e,{location:r=m.location,threshold:n=m.threshold,distance:a=m.distance,includeMatches:o=m.includeMatches,findAllMatches:i=m.findAllMatches,minMatchCharLength:s=m.minMatchCharLength,isCaseSensitive:u=m.isCaseSensitive,ignoreLocation:f=m.ignoreLocation}={}){super(e),this._bitapSearch=new ue(e,{location:r,threshold:n,distance:a,includeMatches:o,findAllMatches:i,minMatchCharLength:s,isCaseSensitive:u,ignoreLocation:f})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}},le=class extends _{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^\'"(.*)"$/}static get singleRegex(){return/^\'(.*)$/}search(e){let r=0,n,a=[],o=this.pattern.length;for(;(n=e.indexOf(this.pattern,r))>-1;)r=n+o,a.push([n,r-1]);let i=!!a.length;return{isMatch:i,score:i?0:1,indices:a}}},je=[Ye,le,Le,Ue,$e,Re,Ne,fe],Ct=je.length,rn=/ +(?=(?:[^\\"]*\\"[^\\"]*\\")*[^\\"]*$)/,nn="|";function an(t,e={}){return t.split(nn).map(r=>{let n=r.trim().split(rn).filter(o=>o&&!!o.trim()),a=[];for(let o=0,i=n.length;o!!(t[ce.AND]||t[ce.OR]),un=t=>!!t[Be.PATH],fn=t=>!Y(t)&&Pt(t)&&!Ge(t),Wt=t=>({[ce.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function At(t,e,{auto:r=!0}={}){let n=a=>{let o=Object.keys(a),i=un(a);if(!i&&o.length>1&&!Ge(a))return n(Wt(a));if(fn(a)){let u=i?a[Be.PATH]:o[0],f=i?a[Be.PATTERN]:a[u];if(!F(f))throw new Error($r(u));let l={keyId:Ae(u),pattern:f};return r&&(l.searcher=Qe(f,e)),l}let s={children:[],operator:o[0]};return o.forEach(u=>{let f=a[u];Y(f)&&f.forEach(l=>{s.children.push(n(l))})}),s};return Ge(t)||(t=Wt(t)),n(t)}function ln(t,{ignoreFieldNorm:e=m.ignoreFieldNorm}){t.forEach(r=>{let n=1;r.matches.forEach(({key:a,norm:o,score:i})=>{let s=a?a.weight:null;n*=Math.pow(i===0&&s?Number.EPSILON:i,(s||1)*(e?1:o))}),r.score=n})}function cn(t,e){let r=t.matches;e.matches=[],D(r)&&r.forEach(n=>{if(!D(n.indices)||!n.indices.length)return;let{indices:a,value:o}=n,i={indices:a,value:o};n.key&&(i.key=n.key.src),n.idx>-1&&(i.refIndex=n.idx),e.matches.push(i)})}function dn(t,e){e.score=t.score}function mn(t,e,{includeMatches:r=m.includeMatches,includeScore:n=m.includeScore}={}){let a=[];return r&&a.push(cn),n&&a.push(dn),t.map(o=>{let{idx:i}=o,s={item:e[i],refIndex:i};return a.length&&a.forEach(u=>{u(o,s)}),s})}var N=class{constructor(e,r={},n){this.options={...m,...r},this.options.useExtendedSearch,this._keyStore=new Ee(this.options.keys),this.setCollection(e,n)}setCollection(e,r){if(this._docs=e,r&&!(r instanceof ae))throw new Error(Rr);this._myIndex=r||Et(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){!D(e)||(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){let r=[];for(let n=0,a=this._docs.length;n-1&&(u=u.slice(0,r)),mn(u,this._docs,{includeMatches:n,includeScore:a})}_searchStringList(e){let r=Qe(e,this.options),{records:n}=this._myIndex,a=[];return n.forEach(({v:o,i,n:s})=>{if(!D(o))return;let{isMatch:u,score:f,indices:l}=r.searchIn(o);u&&a.push({item:o,idx:i,matches:[{score:f,value:o,norm:s,indices:l}]})}),a}_searchLogical(e){let r=At(e,this.options),n=(s,u,f)=>{if(!s.children){let{keyId:c,searcher:d}=s,p=this._findMatches({key:this._keyStore.get(c),value:this._myIndex.getValueForItemAtKeyId(u,c),searcher:d});return p&&p.length?[{idx:f,item:u,matches:p}]:[]}let l=[];for(let c=0,d=s.children.length;c{if(D(s)){let f=n(r,s,u);f.length&&(o[u]||(o[u]={idx:u,item:s,matches:[]},i.push(o[u])),f.forEach(({matches:l})=>{o[u].matches.push(...l)}))}}),i}_searchObjectList(e){let r=Qe(e,this.options),{keys:n,records:a}=this._myIndex,o=[];return a.forEach(({$:i,i:s})=>{if(!D(i))return;let u=[];n.forEach((f,l)=>{u.push(...this._findMatches({key:f,value:i[l],searcher:r}))}),u.length&&o.push({idx:s,item:i,matches:u})}),o}_findMatches({key:e,value:r,searcher:n}){if(!D(r))return[];let a=[];if(Y(r))r.forEach(({v:o,i,n:s})=>{if(!D(o))return;let{isMatch:u,score:f,indices:l}=n.searchIn(o);u&&a.push({score:f,key:e,value:o,idx:i,norm:s,indices:l})});else{let{v:o,n:i}=r,{isMatch:s,score:u,indices:f}=n.searchIn(o);s&&a.push({score:u,key:e,value:o,norm:i,indices:f})}return a}};N.version="7.0.0";N.createIndex=Et;N.parseIndex=Kr;N.config=m;N.parseQuery=At;sn(qe);function Yt(t){let{query:e,pathsIndex:r,count:n}=t,a=[],o={shouldSort:!0,threshold:0,ignoreLocation:!0,keys:["name","path","label.preview"]};return new N([...r.values()].filter(s=>s.hidden==!1),o).search(e).map(s=>s.item).slice(0,n)}function Nt(t){let{queries:e,pathsIndex:r,count:n}=t,a=[];for(let[o,i]of r)!i.hidden&&Ot(e,i,{})&&a.push(i);return a.slice(0,n)}var pn=self;pn.onmessage=async t=>{let{payload:e,job:r}=t.data,n;r.type=="search"&&(n=Nt(e)),r.type=="fastSearch"&&(n=Yt(e));try{postMessage({job:r,result:n})}catch(a){console.log(a),postMessage({job:r,result:{$error:`Failed to run ${r.type} ${r.path}: ${a}`}})}};\n',{name:"Superstate Search"})}var g5=class{constructor(t,r){this.numWorkers=t;this.cache=r;this.workers=[],this.busy=[],this.reloadQueue=[],this.reloadSet=new Set,this.callbacks=new Map;for(let n=0;nthis.finish(a.data.job,a.data.result,n),this.workers.push(i),this.busy.push(!1)}}run(t){let r=F2(t),n=new Promise((a,o)=>{this.callbacks.has(r)?this.callbacks.get(r)?.push([a,o]):this.callbacks.set(r,[[a,o]])});if(this.reloadSet.has(r))return n;this.reloadSet.add(r);let i=this.nextAvailableWorker();return i!==void 0?this.send(t,i):this.reloadQueue.push(t),n}finish(t,r,n){let i=F2(t),a=[].concat(this.callbacks.get(i)??[]);this.reloadSet.delete(i),this.callbacks.delete(i),this.busy[n]=!1;let o=this.reloadQueue.shift();if(o!==void 0&&this.send(o,n),"$error"in r)for(let[s,l]of a)l(r.$error);else for(let[s,l]of a)s(r)}async send(t,r){t.type=="search"&&(this.message(r,{job:t,payload:{queries:t.payload.queries,pathsIndex:this.cache.pathsIndex,count:t.payload.count}}),this.busy[r]=!0),t.type=="fastSearch"&&(this.message(r,{job:t,payload:{query:t.payload.query,pathsIndex:this.cache.pathsIndex,count:t.payload.count}}),this.busy[r]=!0)}message(t,r){this.workers[t].postMessage(r)}nextAvailableWorker(){let t=this.busy.indexOf(!1);return t==-1?void 0:t}};var Ay=class{constructor(t,r,n,i,a){this.indexVersion=t;this.onChange=r;this.loadouts=[];this.kit=[Um,_2,$2,B2,R2,jwe,q2,cC,Dwe,Twe,Rwe,Bwe,Fwe,Pwe,_we,Iwe,$we,qwe,Uwe,Wwe,Mwe,Owe,P2,Wm,zwe,p5,I2,fC,Lwe,Nwe,Vwe];this.eventsDispatcher=new u0;let o={...uG,createAdd:G("add",[],()=>function(f,d){return f+d}),createEqual:G("equal",[],()=>function(f,d){return f==d}),createUnequal:G("unequal",[],()=>function(f,d){return f!=d})},l=yB(o,{matrix:"Array"});l.import(P6,{override:!0}),this.formulaContext=l,this.initialized=!1,this.spaceManager=n,this.spaceManager.superstate=this,this.ui=i,this.ui.superstate=this,this.cli=a;let u=new m5(this.cli,this);this.cli.superstate=this,this.cli.terminals.splice(0,0,u),this.cli.mainTerminal=u,this.allMetadata={},this.api=new uC(this),this.pathsIndex=new Map,this.spacesIndex=new Map,this.contextsIndex=new Map,this.actionsIndex=new Map,this.kitFrames=new Map,this.kits=new Map,this.actions=new Map,this.templateCache=new Map,this.focuses=[],this.spacesMap=new vd,this.linksMap=new vd,this.tagsMap=new vd,this.liveSpaceLinkMap=new vd,this.iconsCache=new Map,this.imagesCache=new Map,this.contextStateQueue=Promise.resolve(),this.vaultDBCache=[],this.indexer=new A5(2,this),this.searcher=new g5(1,this)}static create(t,r,n,i,a){return new Ay(t,r,n,i,a)}refreshMetadata(){this.allMetadata=h5(this)}async initializeIndex(){await this.loadFromCache()}addToContextStateQueue(t){this.contextStateQueue=this.contextStateQueue.then(t).catch(()=>{})}async initialize(){if(!this.persister){console.log("Cache Persister Not Found");return}let t=Date.now();this.initializeActions(),this.initializeFocuses(),this.initializeKits(),this.initializeTemplates(),this.settings.spacesEnabled&&await this.initializeSpaces(),await this.initializeBuiltins(),await this.initializeTags(),await this.initializePaths(),await this.initializeContexts(),await this.initializeFrames(),this.refreshMetadata(),this.dispatchEvent("superstateUpdated",null),this.ui.notify(`Make.md - Superstate Loaded in ${(Date.now()-t)/1e3} seconds`,"console"),this.persister.cleanType("space"),this.persister.cleanType("path"),this.persister.cleanType("context"),this.persister.cleanType("frame")}async reloadSystemActions(){(await this.spaceManager.readSystemCommands()).forEach(r=>this.actions.set(r.name,r.commands)),this.dispatchEvent("actionStateUpdated",{path:"spaces://$actions"})}async initializeActions(){await this.reloadSystemActions();let t=this.allSpaces().filter(r=>r.type!="default").map(r=>r.space).map(r=>this.reloadActions(r));await Promise.all(t)}async initializeKits(){let t=await this.spaceManager.readAllKits();t.forEach(r=>this.kits.set(r.id,r)),t.length==0&&this.kits.set("default",{id:"default",name:"Default",colors:{},frames:[]}),this.selectedKit=this.kits.get(this.settings.selectedKit)??this.kits.get("default"),this.selectedKit.frames=[...this.selectedKit.frames,...this.kit.map(r=>AN(r)).filter(r=>!this.selectedKit.frames.some(n=>n.schema.id==r.schema.id))];for(let r of this.selectedKit.frames){let n=to(r.schema).def.id,i=await hN(this,r,{...c0,screenType:this.ui.getScreenType()});this.kitFrames.set(n,i)}this.dispatchEvent("frameStateUpdated",{path:"spaces://$kit"})}async initializeTemplates(){let t=await this.spaceManager.readAllTemplates();Object.keys(t).forEach(r=>{this.templateCache.set(r,t[r])})}async initializeSpaces(){let t=[...this.spaceManager.allSpaces().values()],r=t.map(n=>this.reloadSpace(n,null,!0));[...this.spacesIndex.keys()].filter(n=>!t.some(i=>i.path==n)).forEach(n=>this.onSpaceDeleted(n)),await Promise.all(r)}getSpaceItems(t,r){let n=[...this.spacesMap.getInverse(t)],i=this.contextsIndex.get(t)?.paths??[];return n.map((a,o)=>({...this.pathsIndex.get(a),rank:i.indexOf(a)})).filter(a=>a?.hidden!=!0&&a.path!=t)}async initializeFrames(){await this.initializeTemplates()}async initializeContexts(){await this.indexer.reload({type:"contexts",path:""}).then(async t=>{let r=[...t.entries()].map(([n,{cache:i,changed:a}])=>this.contextReloaded(n,i,a,!0));await Promise.all(r)})}async loadFromCache(){if(this.dispatchEvent("superstateReindex",null),this.settings.indexSVG){let i=await this.persister.loadAll("icon");this.spaceManager.allPaths(["svg"]).forEach(a=>{let o=i.find(s=>s.path==a);o?.cache.length>0&&this.iconsCache.set(a,o.cache)})}let t=await this.persister.loadAll("path"),r=await this.persister.loadAll("space"),n=await this.persister.loadAll("context");r.forEach(i=>{let a=dr(i.cache);a&&a.type&&this.spacesIndex.set(i.path,a)}),n.forEach(i=>{let a=dr(i.cache);a&&this.contextsIndex.set(i.path,a)}),t.forEach(i=>{let a=c5(i.cache);this.pathsIndex.set(i.path,a),this.tagsMap.set(i.path,new Set(a.tags)),this.spacesMap.set(i.path,new Set(a.spaces)),this.linksMap.set(i.path,new Set(a.outlinks))}),this.settings.enhancedLogs&&console.log("Initial Cache Loaded"),this.dispatchEvent("superstateUpdated",null)}dispatchEvent(t,r){this.eventsDispatcher.dispatchEvent(t,r)}async initializeBuiltins(){let r=Object.keys(cm).map(n=>this.reloadPath("spaces://$"+n,!0));await Promise.all(r)}async initializeTags(){let r=[...this.spaceManager.readTags().map(n=>If(n))].map(n=>this.reloadPath(n,!0));await Promise.all(r)}async onSpaceDefinitionChanged(t,r){if(t.space.readOnly)return;let n=this.spacesMap.getInverse(t.path),i=[];if(t.metadata?.links&&!K0.default.isEqual(t.metadata.links,r?.links)&&i.push(...t.metadata.links),t.metadata?.filters?.length>0){let s=t.metadata.filters.some(l=>l.filters.some(u=>u.fType=="property"));if(!K0.default.isEqual(t.metadata?.filters,r?.filters)||s)for(let[l,u]of this.pathsIndex)!u.hidden&&u5(t.metadata?.filters,u,t.properties)&&i.push(l)}let o=[...K0.default.difference(i,[...n]),...K0.default.difference([...n],i)].map(s=>this.reloadPath(s,!0).then(l=>this.dispatchEvent("pathStateUpdated",{path:s})));await Promise.all(o)}async initializeFocuses(){let t=await this.spaceManager.readFocuses();if(t.length==0){this.spaceManager.saveFocuses([{name:"Home",sticker:"ui//home",paths:["/"]}]);return}this.focuses=t,this.dispatchEvent("focusesChanged",null)}async initializePaths(){this.dispatchEvent("superstateReindex",null);let t=this.spaceManager.allPaths(),r=Date.now();await this.indexer.reload({type:"paths",path:""}).then(async i=>{for await(let[a,{cache:o,changed:s}]of Object.entries(i))await this.pathReloaded(a,o,s,!1)}),this.ui.notify(`Make.md - ${t.length} Paths Cached in ${(Date.now()-r)/1e3} seconds`,"console");let n=Mr([...this.spacesIndex.keys(),...t]);[...this.pathsIndex.keys()].filter(i=>!n.some(a=>a==i)).forEach(i=>this.onPathDeleted(i)),this.dispatchEvent("superstateUpdated",null)}async onTagRenamed(t,r){let n=aJ(t),i=Fg(this.spaceManager,r);await this.onSpaceRenamed(n,i),await this.onPathRename(n,i.path),this.dispatchEvent("spaceChanged",{path:n,newPath:i.path});let a=[];for(let[o,s]of this.spacesIndex)this.contextsIndex.get(o)?.contexts.includes(t)&&this.addToContextStateQueue(()=>Lye(this.spaceManager,t,r,a)),s.metadata?.contexts.includes(t)&&of(this,s.space,{...s.metadata,contexts:s.metadata.contexts.map(u=>u==t?r:u)});this.dispatchEvent("spaceStateUpdated",{path:mx})}async onTagDeleted(t){this.tagsMap.getInverse(t).forEach(i=>{this.deleteTagInPath(t,i)});let r=_j(t,this.settings);await this.spaceManager.deletePath(r),this.onSpaceDeleted(If(t));for(let[i,a]of this.spacesIndex)a.metadata?.contexts.includes(t)&&of(this,a.space,{...a.metadata,contexts:a.metadata.contexts.filter(o=>o!=t)});let n=[];for(let[i,a]of this.contextsIndex)a.contexts.includes(t)&&n.push(this.spaceManager.spaceInfoForPath(a.path));this.addToContextStateQueue(()=>zye(this.spaceManager,t,n)),this.dispatchEvent("spaceStateUpdated",{path:mx})}async deleteTagInPath(t,r){let n;if(this.pathsIndex.has(r)&&(n=this.pathsIndex.get(r)),n){let i={...n,tags:n.tags.filter(a=>a!=t),spaces:n.spaces.filter(a=>a!=If(t))};this.pathsIndex.set(r,i),this.tagsMap.set(r,new Set(i.tags)),this.spacesMap.set(r,new Set(i.spaces))}else await this.reloadPath(r);this.onPathReloaded(r),this.dispatchEvent("pathStateUpdated",{path:r})}onMetadataChange(t){this.settings.enhancedLogs&&console.log("Metadata Changed",t),this.pathsIndex.has(t)&&this.reloadPath(t).then(r=>{let n=this.pathsIndex.get(t),i=this.spacesIndex.get(t);i&&this.reloadSpace(i.space).then(o=>this.onSpaceDefinitionChanged(o,i.metadata));let a=n.spaces.map(o=>this.spacesIndex.get(o)?.space).filter(o=>o);this.addToContextStateQueue(()=>vG(this,t,a)),this.dispatchEvent("pathStateUpdated",{path:t})})}reloadSpaceByPath(t,r){return this.reloadSpace(this.spaceManager.spaceInfoForPath(t),r)}async onPathRename(t,r){let n=r,i=this.pathsIndex.get(t),a=i?.spaces??[];if(i){this.spacesMap.delete(t),this.spacesMap.deleteInverse(t),this.linksMap.delete(t),this.linksMap.deleteInverse(t),this.pathsIndex.delete(t);let u=a.map(f=>this.spacesIndex.get(f)).filter(f=>f);await Hye(this.spaceManager,t,n,u.map(f=>f.space));for(let f of u)f.metadata?.links?.includes(t)&&this.addToContextStateQueue(()=>oy(this,f.path,"links",f.metadata.links.map(d=>d==t?r:d))),await this.reloadContext(f.space,!0);let c=[];for(let[f,d]of this.contextsIndex)d.outlinks.includes(t)&&c.push(this.spacesIndex.get(d.path).space);this.addToContextStateQueue(()=>Vye(this.spaceManager,t,n,c).then(f=>Promise.all(c.map(d=>this.reloadContext(d,!0)))))}let o=!1;this.focuses.forEach(u=>{u.paths.includes(t)&&(u.paths=u.paths.map(c=>c==t?r:c),o=!0)}),o&&(await this.spaceManager.saveFocuses(this.focuses),this.dispatchEvent("focusesChanged",null)),await this.reloadPath(r,!0);let s=Mr([...this.spacesMap.get(r)??[],...a]),l=s.map(u=>this.reloadContext(this.spacesIndex.get(u)?.space));await Promise.all(l),s.forEach(u=>this.dispatchEvent("spaceStateUpdated",{path:u})),this.dispatchEvent("pathChanged",{path:t,newPath:r}),this.ui.viewsByPath(t).forEach(u=>{u.openPath(r)})}async onPathCreated(t){await this.reloadPath(t,!0);let r=cu(t);this.spacesIndex.has(r)&&this.spacesIndex.get(r).space.notePath==t&&await this.reloadSpace(this.spacesIndex.get(r).space),this.dispatchEvent("pathCreated",{path:t})}onPathDeleted(t){this.spacesMap.delete(t),this.linksMap.delete(t),this.linksMap.deleteInverse(t),this.persister.remove(t,"path");let r=this.pathsIndex.get(t);if(!r)return;let n=(r.spaces??[]).map(a=>this.spacesIndex.get(a)?.space).filter(a=>a);this.addToContextStateQueue(()=>Qye(this.spaceManager,t,n).then(a=>n.forEach(o=>this.reloadContext(o))));let i=[];for(let[a,o]of this.contextsIndex)o.outlinks.includes(t)&&this.spacesIndex.has(o.path)&&i.push(this.spacesIndex.get(o.path).space);this.addToContextStateQueue(()=>Gye(this.spaceManager,t,i).then(a=>n.forEach(o=>this.reloadContext(o)))),(r.spaces??[]).forEach(a=>{this.dispatchEvent("spaceStateUpdated",{path:a})}),this.pathsIndex.delete(t),this.dispatchEvent("pathDeleted",{path:t})}async onSpaceRenamed(t,r){if(this.spacesIndex.has(t)){let n=this.spacesIndex.get(t).metadata;this.spacesIndex.set(r.path,{...this.spacesIndex.get(t),path:r.path,name:r.name,space:r}),this.spacesMap.rename(t,r.path),this.spacesMap.renameInverse(t,r.path),this.spacesIndex.delete(t),this.contextsIndex.delete(t),this.actionsIndex.delete(t),await this.reloadSpace(r,n).then(i=>this.onSpaceDefinitionChanged(i,n)),await this.reloadContext(r,!0),await this.reloadActions(r)}}onSpaceDeleted(t){this.spacesIndex.has(t)&&(this.spacesIndex.delete(t),this.contextsIndex.delete(t)),this.spacesMap.delete(t),this.spacesMap.deleteInverse(t),this.persister.remove(t,"space"),this.dispatchEvent("spaceDeleted",{path:t})}async reloadActions(t){if(!t)return!1;this.spaceManager.commandsForSpace(t.path).then(r=>{this.actionsIndex.set(t.path,r),this.dispatchEvent("actionStateUpdated",{path:t.path})})}async reloadContextByPath(t,r){return this.reloadContext(this.spaceManager.spaceInfoForPath(t),r)}async reloadContext(t,r){return t?this.indexer.reload({type:"context",path:t.path}).then(n=>this.contextReloaded(t.path,n.cache,n.changed,r)):!1}async contextReloaded(t,r,n,i){if(!r||(this.settings.enhancedLogs&&console.log("Context Reloaded"),!n&&!i))return!1;this.contextsIndex.set(t,r);let a=this.pathsIndex.get(t);if(a&&r.dbExists&&!a.readOnly&&this.settings.syncFormulaToFrontmatter){let o=r.contextTable?.rows??[],s=r.contextTable?.cols??[],l=o.filter(u=>{let c=u[Ft],f=this.pathsIndex.get(c);return!f||f.type=="file"&&f.subtype!="md"?!1:s.reduce((d,p,h)=>d||p.type!="fileprop"||p.primary=="true"?d:u[p.name]?.length>0&&f.metadata?.property?.[p.name]!=u[p.name]?!0:d,!1)});l.length>0&&l.forEach(u=>Di(this,u[Ft],s.reduce((c,f,d)=>f.type=="fileprop"&&f.primary!="true"?{...c,[f.name]:u[f.name]}:c,{})))}return r.dbExists&&n&&await this.spaceManager.saveTable(t,r.contextTable),this.persister.store(t,JSON.stringify(r),"context"),this.dispatchEvent("contextStateUpdated",{path:t}),!0}allSpaces(t){return t?JK([...this.spacesIndex.values()],this.spaceOrder(),"path"):[...this.spacesIndex.values()]}spaceOrder(){return[...this.focuses.flatMap(t=>t.paths)]}async updateSpaceMetadata(t,r){let n=this.spacesIndex.get(t),i=n?.metadata;if(!n)return this.reloadSpaceByPath(t);let a=!1,s=(r?.sort??{field:"rank",asc:!0,group:!0}).field=="rank";(!K0.default.isEqual(n.metadata.links,r.links)||!K0.default.isEqual(n.metadata.filters,r.filters))&&(a=!0);let l={...n,metadata:r,contexts:r?.contexts??[],sortable:s};return this.spacesIndex.set(t,l),a&&await this.onSpaceDefinitionChanged(l,i),this.dispatchEvent("spaceStateUpdated",{path:n.path}),l}async reloadSpace(t,r,n=!0){if(!t)return;this.settings.enhancedLogs&&console.log("Reloading Space");let i=r??await this.spaceManager.spaceDefForSpace(t.path),a=this.pathsIndex.get(t.path),o=this.spaceManager.uriByString(t.path);if(!o)return null;let s=this.spaceManager.spaceTypeByString(o);(s=="default"||s=="tag")&&(i.filters=[],i.links=[]);let l=[],u={},c=await this.spaceManager.readFrame(t.path,r1).then(b=>b?.cols??[]);if(l.push(...c),l.length>0){if(!a)if(this.settings.enableFolderNote){let b=await this.spaceManager.readPathCache(t.notePath);a={path:t.path,name:t.name,tags:[],spaces:[],outlinks:[],readOnly:t.readOnly,hidden:!1,metadata:b?.metadata,type:"space",subtype:s,label:b?.label}}else{let b=await this.spaceManager.readPathCache(t.path);a={path:t.path,name:t.name,tags:[],spaces:[],outlinks:[],readOnly:t.readOnly,hidden:!1,metadata:b?.metadata,type:"space",subtype:s,label:b?.label}}u=await this.spaceManager.readProperties(t.notePath).then(b=>Vm(this.formulaContext,this.pathsIndex,b,l,a))}[...this.spacesMap.get(t.path)].map(b=>this.contextsIndex.get(b)).forEach(b=>{if(b){let v=b.contextTable?.cols??[];l.push(...v),u={...u,...b.contextTable?.rows.find(x=>x[Ft]==t.path)??{}}}});let f=i?.sort??{field:"rank",asc:!0,group:!0},d=f.field=="rank"||!f,p=i?.contexts??[],h=Mr((i.filters??[]).flatMap(b=>b.filters).flatMap(b=>b.type=="context"?[b.field.split(".")[0]]:b.type=="path"&&b.field=="space"?mr(b.value):[])),m=Mr((i.filters??[]).flatMap(b=>b.filters).flatMap(b=>b.type.startsWith("link")?mr(b.value):[]));if(s=="tag"&&this.settings.autoAddContextsToSubtags){let b=EJ(t.name);p.push(...b)}let g=await this.spaceManager.readTemplates(t.path),A={name:t.name,space:t,path:t.path,type:s,templates:g,contexts:p.map(b=>b.toLowerCase()),metadata:i,dependencies:h,sortable:d,properties:u,propertyTypes:l};if(this.spacesIndex.set(t.path,A),this.persister.store(t.path,JSON.stringify(A),"space"),A.metadata?.links?.forEach(b=>{PK(this,b)&&this.spacesMap.set(b,new Set([...this.spacesMap.get(b),t.path]))}),n)return this.dispatchEvent("spaceStateUpdated",{path:t.path}),A}async pathReloaded(t,r,n,i){if(this.settings.enhancedLogs&&console.log("Path Reloaded"),this.pathsIndex.set(t,r),await this.onPathReloaded(t),(r.subtype=="image"||r.metadata?.file?.extension=="svg")&&this.imagesCache.set(r.metadata.file.filename,t),!n&&!i)return!1;if(this.tagsMap.set(t,new Set(r.tags)),this.linksMap.set(t,new Set(r.outlinks)),!K0.default.isEqual(r.spaces,Array.from(this.spacesMap.get(t)))){this.spacesMap.set(t,new Set(r.spaces));let a=r.tags.map(s=>Fg(this.spaceManager,s)).filter(s=>!this.spacesIndex.has(s.path)).map(async s=>{await this.reloadSpace(s),this.reloadContext(s),await this.reloadPath(s.path)});await Promise.all(a).then(s=>{this.dispatchEvent("spaceStateUpdated",{path:mx})})}if(i){let a=r.spaces.map(o=>this.spacesIndex.get(o)?.space).filter(o=>o);this.addToContextStateQueue(()=>vG(this,t,a).then(o=>{a.forEach(s=>{this.dispatchEvent("spaceStateUpdated",{path:s.path})})}))}r.metadata?.file?.extension=="svg"&&this.settings.indexSVG&&this.spaceManager.readPath(t).then(a=>{this.iconsCache.set(t,a),this.persister.store(t,a,"icon")})}async reloadPath(t,r){return t?this.indexer.reload({type:"path",path:t}).then(async n=>(await this.pathReloaded(t,n.cache,n.changed,r),!0)):!1}async onPathReloaded(t){let r;if(this.pathsIndex.has(t)&&(r=this.pathsIndex.get(t)),!r)return!1;await this.persister.store(t,kwe(r),"path")}};var gy=class{constructor(){this.filesystems=[];this.filetypes=[];this.eventDispatch=new u0}static create(){return new gy}resolvePath(t,r){return this.primary.resolvePath(t,r)}keysForCacheType(t){return this.primary.keysForCacheType(t)}allTags(){return this.primary.readAllTags()}fileFragmentChanged(t){this.eventDispatch.dispatchEvent("onFileFragmentChanged",{file:t})}initiateFileSystemAdapter(t,r){t.initiate(this),r&&(this.primary=t),this.filesystems.push(t)}initiateFiletypeAdapter(t){t.initiate(this),this.filetypes.push(t)}filetypeAdaptersForFile(t){return t?this.filetypes.filter(r=>r.supportedFileTypes.includes(t.extension)):[]}filetypeAdaptersForFileFragments(t,r){return this.filetypeAdaptersForFile(t).filter(n=>n.contentTypes?n.contentTypes(t).includes(r):!1)}getFileCacheTypeByRefString(t,r){return this.filetypeAdaptersForFile(t).reduce((i,a)=>i||a.getCacheTypeByRefString(t,r),null)}allCaches(){return this.primary.cache}allFiles(){return this.primary.allFiles()}resourcePathForPath(t){return this.adapterForPath(t).resourcePathForPath(t)}parentPathForPath(t){return this.adapterForPath(t).parentPathForPath(t)}async createFileCache(t){let r=await this.getFile(t);for(let n of this.filetypeAdaptersForFile(r))n.parseCache&&await n.parseCache(r,!1)}getFileCache(t){return this.adapterForPath(t).getFileCache(t)}getFileContent(t,r,n){let i=this.filetypeAdaptersForFile(t).filter(a=>a.contentTypes(t).includes(r));if(i.length>=1)return i[0].readContent(t,r,n)}updateFileCache(t,r,n){this.adapterForPath(t).updateFileCache(t,r,n)}readFileFragments(t,r,n){let i=this.filetypeAdaptersForFileFragments(t,r);if(i.length>=1)return i[0].readContent(t,r,n)}async newFile(t,r,n,i){let a=this.filetypes.find(o=>o.supportedFileTypes.includes(n));if(a)return a.newFile(t,r,n,i)}newFileFragment(t,r,n,i,a){let o=this.filetypeAdaptersForFileFragments(t,r);if(o.length>=1)return o[0].newContent(t,r,n,i,a)}saveFileLabel(t,r,n){let i=this.filetypeAdaptersForFileFragments(t,"label");return i.length>=1?i[0].saveContent(t,"label",r,()=>n):this.primary.updateFileLabel(t.path,r,n)}saveFileFragment(t,r,n,i){let a=this.filetypeAdaptersForFileFragments(t,r);return a.length>=1?a[0].saveContent(t,r,n,i):!1}deleteFileFragment(t,r,n){let i=this.filetypeAdaptersForFileFragments(t,r);if(i.length>=1)return i[0].deleteContent(t,r,n)}onCreate(t){this.eventDispatch.dispatchEvent("onCreate",{file:t})}onModify(t){this.eventDispatch.dispatchEvent("onModify",{file:t})}onRename(t,r){this.eventDispatch.dispatchEvent("onRename",{file:t,oldPath:r})}onDelete(t){this.eventDispatch.dispatchEvent("onDelete",{file:t})}onSpaceUpdated(t,r){this.eventDispatch.dispatchEvent("onSpaceUpdated",{path:t,type:r})}onFocusesUpdated(){this.eventDispatch.dispatchEvent("onFocusesUpdated",null)}adapterForPath(t){return this.primary}async getRoot(){return this.adapterForPath().getRoot()}async copyFile(t,r,n){return this.adapterForPath(t).copyFile(t,r,n)}async writeTextToFile(t,r){return this.adapterForPath(t).writeTextToFile(t,r)}async readTextFromFile(t){return this.adapterForPath(t).readTextFromFile(t)}async writeBinaryToFile(t,r){return this.adapterForPath(t).writeBinaryToFile(t,r)}async readBinaryToFile(t){return this.adapterForPath(t).readBinaryToFile(t)}async renameFile(t,r){return this.adapterForPath(t).renameFile(t,r)}async createFolder(t){return this.adapterForPath(t).createFolder(t)}async childrenForFolder(t,r){return this.adapterForPath(t).childrenForFolder(t,r)}async fileExists(t){return this.adapterForPath(t).fileExists(t)}async getFile(t,r){return this.adapterForPath(t).getFile(t,r)}async deleteFile(t){return this.adapterForPath(t).deleteFile(t)}async addTagToFile(t,r){return this.adapterForPath(t).addTagToFile(t,r)}async renameTagForFile(t,r,n){return this.adapterForPath(t).renameTagForFile(t,r,n)}async removeTagFromFile(t,r){return this.adapterForPath(t).removeTagFromFile(t,r)}filesForTag(t){return this.primary.filesForTag(t)}};var $H=(e,t)=>e.skipFolderNames.some(r=>t.endsWith(r))||t.endsWith("/"+e.spaceSubFolder)||t==e.spaceSubFolder||t.split("/").pop()==e.spaceSubFolder||t.startsWith(e.spacesFolder+"/#")||t.startsWith(e.spacesFolder+"/$")||e.skipFolders.some(r=>r==t);var mC="templates",hC="kits",AC="actions",gC="waypoints.json",vC=class{constructor(t,r){this.fileSystem=t;this.dataPath=r;this.schemes=["spaces","vault"];this.onFocusesUpdated=()=>{this.spaceManager.onFocusesUpdated()};this.onSpaceUpdated=t=>{t.type=="views.mdb"?this.spaceManager.onSpaceUpdated(t.path,"frame"):t.type=="context.mdb"?this.spaceManager.onSpaceUpdated(t.path,"context"):t.type=="commands.mdb"&&this.spaceManager.onSpaceUpdated(t.path,"action")};this.onCreate=async t=>{t.file.isFolder?this.spaceManager.onSpaceCreated(t.file.path):this.spaceManager.onPathCreated(t.file.path)};this.onDelete=t=>{!t.file||(!t.file.isFolder&&t.file.extension!="mdb"?this.spaceManager.onPathDeleted(t.file.path):t.file.isFolder&&this.spaceManager.onSpaceDeleted(t.file.path))};this.onRename=t=>{!t.file||(!t.file.isFolder&&t.file.extension!="mdb"?this.spaceManager.onPathChanged(t.file.path,t.oldPath):t.file.isFolder&&this.spaceManager.onSpaceRenamed(t.file.path,t.oldPath))};this.authorities=["vault"];t.eventDispatch.addListener("onCreate",this.onCreate,0,this),t.eventDispatch.addListener("onRename",this.onRename,0,this),t.eventDispatch.addListener("onDelete",this.onDelete,0,this),t.eventDispatch.addListener("onFocusesUpdated",this.onFocusesUpdated,0,this),t.eventDispatch.addListener("onSpaceUpdated",this.onSpaceUpdated,0,this),t.eventDispatch.addListener("onCacheUpdated",this.onMetadataChange,0,this)}initiateAdapter(t){this.spaceManager=t}async readTemplates(t){return(await this.childrenForPath(`${t}/${this.spaceManager.superstate.settings.spaceSubFolder}/templates`)).filter(r=>!r.startsWith(".")).map(r=>r.split("/").pop())}async saveTemplate(t,r){return this.copyPath(t,`${r}/${this.spaceManager.superstate.settings.spaceSubFolder}/templates`)}deleteTemplate(t,r){return this.deletePath(`${r}/${this.spaceManager.superstate.settings.spaceSubFolder}/templates/${t}`)}async readFocuses(){return await this.fileSystem.fileExists(this.dataPath)||await this.fileSystem.createFolder(this.dataPath),await this.fileSystem.fileExists(`${this.dataPath}/${gC}`)?this.fileSystem.readTextFromFile(`${this.dataPath}/${gC}`).then(t=>Zs(dr(t))):[]}async saveFocuses(t){return await this.fileSystem.fileExists(this.dataPath)||await this.fileSystem.createFolder(this.dataPath),this.fileSystem.writeTextToFile(`${this.dataPath}/${gC}`,JSON.stringify(t))}async readTemplate(t){let r=`${this.dataPath}/${mC}/${t}`;if(await this.fileSystem.fileExists(r))return this.fileSystem.readFileFragments({path:`${r}/${this.spaceManager.superstate.settings.spaceSubFolder}/views.mdb`,name:"views",filename:"views.mdb",parent:r,isFolder:!1,extension:"mdb"},"mdbTables")}async readAllKits(){let t=(await this.childrenForPath(`${this.dataPath}/${hC}`)).map(n=>n.split("/").pop());return Promise.all(t.map(async n=>{let i=await this.readKitFrames(n);return{id:n,name:n,colors:{},frames:Object.values(i??{})}}))}async readAllTemplates(){let t=(await this.childrenForPath(`${this.dataPath}/${mC}`)).map(n=>n.split("/").pop()),r={};for(let n of t){let i=await this.readTemplate(n);i&&(r[n]=i)}return r}async readKitFrames(t){return this.fileSystem.readFileFragments({path:`${this.dataPath}/${hC}/${t}/kit.mdb`,name:"kit",filename:"kit.mdb",parent:`${this.dataPath}/${hC}/${t}`,isFolder:!1,extension:"mdb"},"mdbTables")}async saveFrameKit(t,r){let n={path:`${this.dataPath}/${hC}/${r}/kit.mdb`,name:"kit",filename:"kit.mdb",parent:`${this.dataPath}/${hC}/${r}`,isFolder:!1,extension:"mdb"};await this.fileSystem.saveFileFragment(n,"schema",t.schema.id,()=>t.schema),this.fileSystem.saveFileFragment(n,"mdbFrame",t.schema.id,()=>t)}async saveSpaceTemplate(t,r){let n=r;if(await this.fileSystem.fileExists(`${this.dataPath}/${mC}`)){let i=await this.childrenForPath(`${this.dataPath}/${mC}/${r}`);n=Mi(n,i)}await this.fileSystem.newFile(`${this.dataPath}/${mC}/${n}/${this.spaceManager.superstate.settings.spaceSubFolder}`,"view","mdb",t)}async onMetadataChange(t){if(!t.path)return;if(t.path.endsWith(".json")){let n=t.path.split("/").slice(0,-2).join("/");this.spaceManager.onPathPropertyChanged(n);return}let r=this.spaceManager.superstate.pathsIndex.get(t.path);if(r?.metadata.spacePath?.length>0){this.spaceManager.onPathPropertyChanged(r?.metadata.spacePath);return}this.spaceManager.onPathPropertyChanged(t.path)}uriByPath(t){return this.spaceManager.uriByString(t)}allPaths(t){return[...this.fileSystem.allFiles().filter(r=>t?t.some(n=>n=="folder"?r.isFolder:r.extension==n):!0).map(r=>r.path).filter(r=>!$H(this.spaceManager.superstate.settings,r))]}async pathExists(t){return this.fileSystem.fileExists(t)}async createItemAtPath(t,r,n,i){let a=await this.getPathInfo(t);if(!a)await this.fileSystem.createFolder(t);else if(!a?.isFolder){let o=await this.fileSystem.getFile(t);return o?this.fileSystem.newFileFragment(o,r,n,i)?.then(s=>o.path):null}return this.fileSystem.newFile(t,n,r,i).then(o=>o?.path)}async renamePath(t,r){let n=this.uriByPath(t),i=this.uriByPath(r),a=await this.fileSystem.getFile(n.path);if(n.refStr){let o=await this.fileSystem.getFileCacheTypeByRefString(a,n.refStr);return await this.fileSystem.saveFileFragment(a,o,n.refStr,()=>i.refStr),r}return await this.fileSystem.renameFile(t,r)}async deletePath(t){let r=this.uriByPath(t);if(r.refStr){let n=await this.fileSystem.getFile(r.path),i=await this.fileSystem.getFileCacheTypeByRefString(n,r.refStr);return this.fileSystem.deleteFileFragment(n,i,r.refStr)}return this.fileSystem.deleteFile(t)}async getPathInfo(t){let r=this.uriByPath(t),n=await this.fileSystem.getFile(r.path);if(r.refStr){let i=this.fileSystem.getFileCacheTypeByRefString(n,r.refStr)}return n}keysForCacheType(t){return this.fileSystem.keysForCacheType(t)}async readPathCache(t){let r=this.uriByPath(t);if(r.scheme=="spaces"){if(r.authority.charAt(0)=="$"){let n=Object.keys(cm).find(i=>i==r.authority.slice(1));if(n)return{file:null,metadata:null,label:{name:cm[n].name,sticker:cm[n].icon,color:""},readOnly:!1,type:"space",parent:"",tags:[]}}if(r.authority.charAt(0)=="#")return{file:null,metadata:null,label:{name:r.authority,sticker:"",color:""},type:"space",parent:"",tags:[],readOnly:!1}}return t=="/"?{file:{name:this.spaceManager.superstate.settings.systemName,path:"/",isFolder:!0},metadata:{},label:{name:this.spaceManager.superstate.settings.systemName,sticker:"",color:""},type:"space",subtype:"folder",parent:"",tags:[],readOnly:!1}:this.fileSystem.getFileCache(t)}async readPath(t){let r=this.uriByPath(t),n=await this.fileSystem.getFile(r.path);if(r.refStr){let i=this.fileSystem.getFileCacheTypeByRefString(n,r.refStr);this.fileSystem.getFileContent(n,i,r.refStr)}return this.fileSystem.readTextFromFile(t)}async copyPath(t,r,n){let i=this.uriByPath(t),a=await this.fileSystem.getFile(i.path);return this.fileSystem.copyFile(a.path,r,n)}async writeToPath(t,r,n){let i=this.uriByPath(t),a=await this.fileSystem.getFile(i.path);if(i.refStr){let o=this.fileSystem.getFileCacheTypeByRefString(a,i.refStr);this.fileSystem.saveFileFragment(a,o,i.refStr,()=>r)}return n?this.fileSystem.writeBinaryToFile(t,r):this.fileSystem.writeTextToFile(t,r)}async childrenForPath(t,r){return await this.fileSystem.fileExists(t)?this.fileSystem.childrenForFolder(t,r):[]}parentPathForPath(t){return this.fileSystem.parentPathForPath(t)}async readFrame(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);if(!n){let i=this.defaultFrame(t);if(Object.keys(i).some(a=>a==r))return i[r]}return this.fileSystem.readFileFragments(n,"mdbTable",r)}async readAllFrames(t){let r=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return r?this.fileSystem.readFileFragments(r,"mdbTables"):this.defaultFrame(t)}async readTable(t,r){let n=this.spaceInfoForPath(t),i=await this.fileSystem.getFile(n.dbPath);if(!i&&r==um.id){let o=dx(this.spaceManager.superstate,n),s=dC(o.cols),l=o.rows.map(u=>Vm(this.spaceManager.superstate.formulaContext,this.spaceManager.superstate.pathsIndex,u,o.cols,this.spaceManager.superstate.pathsIndex.get(t),s));return{...o,rows:l}}let a=await this.fileSystem.readFileFragments(i,"mdbTable",r);if(a&&a.schema.id!=um.id){let o=dC(a.cols),s=a.rows.map(l=>Vm(this.spaceManager.superstate.formulaContext,this.spaceManager.superstate.pathsIndex,l,a.cols,this.spaceManager.superstate.pathsIndex.get(t),o));return{...a,rows:s}}else if(!a&&r==um.id){let o=dx(this.spaceManager.superstate,n),s=dC(o.cols),l=o.rows.map(u=>Vm(this.spaceManager.superstate.formulaContext,this.spaceManager.superstate.pathsIndex,u,o.cols,this.spaceManager.superstate.pathsIndex.get(t),s));return{...o,rows:l}}return a}async spaceInitiated(t){return!0}async contextInitiated(t){let r=this.spaceInfoForPath(t);return await this.fileSystem.fileExists(r.dbPath)}async tablesForSpace(t){let r=this.spaceInfoForPath(t),n=await this.fileSystem.getFile(r.dbPath);if(!n)return Gh.rows;let i=await this.fileSystem.readFileFragments(n,"schemas",null);return i.length==0?Gh.rows:i}defaultDBTablesForContext(t){let r=dx(this.spaceManager.superstate,t),n=P$(t);return{...vJ(t),m_fields:{uniques:n.uniques,cols:n.cols,rows:[...n.rows??[],...r.cols]},[r.schema.id]:{uniques:r.cols.filter(a=>a.unique=="true").map(a=>a.name),cols:r.cols.map(a=>a.name),rows:r.rows}}}defaultFrame(t){return t.startsWith(_g)&&t==_g+"overview"?Voe:this.spaceManager.superstate.settings.defaultSpaceTemplate.length>0&&this.spaceManager.superstate.templateCache.has(this.spaceManager.superstate.settings.defaultSpaceTemplate)?this.spaceManager.superstate.templateCache.get(this.spaceManager.superstate.settings.defaultSpaceTemplate):this.spaceManager.superstate.settings.enableFolderNote?Goe:Hoe}async createDefaultTable(t){let r=this.spaceInfoForPath(t),n=this.spaceInfoForPath(t).dbPath,i=n.split(".").pop(),a=n.split("/").slice(0,-1).join("/"),o=n.split("/").pop().split(".")[0];return this.fileSystem.newFile(a,o,i,this.defaultDBTablesForContext(r))}async createDefaultFrames(t){let r=this.defaultFrame(t),n={...l6(r),m_schema:hJ},i=this.spaceInfoForPath(t).framePath,a=i.split(".").pop(),o=i.split("/").slice(0,-1).join("/"),s=i.split("/").pop().split(".")[0];return this.fileSystem.newFile(o,s,a,n)}async createTable(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return n||(n=await this.createDefaultTable(t)),this.fileSystem.newFileFragment(n,"schema",r.id,r)}async saveTableSchema(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return i||(i=await this.createDefaultTable(t)),this.fileSystem.saveFileFragment(i,"schema",r,n)}async saveTable(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);if(!i)if(n)i=await this.createDefaultTable(t);else return!1;return this.fileSystem.saveFileFragment(i,"mdbTable",r.schema.id,()=>r)}async deleteTable(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return this.fileSystem.deleteFileFragment(n,"schema",r)}async readAllTables(t){let r=this.spaceInfoForPath(t),n=await this.fileSystem.getFile(r.dbPath);if(!n){let i=dx(this.spaceManager.superstate,r);return{[i.schema.id]:i}}return this.fileSystem.readFileFragments(n,"mdbTables",null)}async framesForSpace(t){let r=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);if(!r){let n=this.defaultFrame(t);return Object.values(n).map(i=>i.schema)}return this.fileSystem.readFileFragments(r,"schemas",null)}async createFrame(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return n||(n=await this.createDefaultFrames(t)),this.fileSystem.newFileFragment(n,"schema",r.id,r)}async deleteFrame(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return this.fileSystem.deleteFileFragment(n,"schema",r)}async saveFrameSchema(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return i||(i=await this.createDefaultFrames(t)),this.fileSystem.saveFileFragment(i,"schema",r,n)}async saveFrame(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return n||(n=await this.createDefaultFrames(t)),this.fileSystem.saveFileFragment(n,"mdbFrame",r.schema.id,()=>r)}async createDefaultCommands(t){let r={m_fields:{uniques:Ji.uniques,cols:Ji.cols,rows:[]},m_schema:{uniques:[],cols:["id","name","type","def","predicate","primary"],rows:[]}},n=this.spaceInfoForPath(t).commandsPath,i=n.split(".").pop(),a=n.split("/").slice(0,-1).join("/"),o=n.split("/").pop().split(".")[0];return this.fileSystem.newFile(a,o,i,r)}async commandsForSpace(t){let r=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);return r?this.fileSystem.readFileFragments(r,"mdbCommands",null):[]}async runCommand(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);if(!i)return{result:null,error:"No commands file found"};let a=await this.fileSystem.readFileFragments(i,"mdbCommand",r);if(!a)return{result:null,error:"No command found"};let o,s;try{a.schema.type=="script"&&(o=C2(a.code,n)),a.schema.type=="formula"&&(o=md(this.spaceManager.superstate.formulaContext,this.spaceManager.superstate.pathsIndex,a.code,a.fields.reduce((l,u)=>({...l,[u.name]:u}),{}),n,this.spaceManager.superstate.pathsIndex.get(t)))}catch(l){s=l}return{result:o,error:s}}async createCommand(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);return n||(n=await this.createDefaultCommands(t)),this.fileSystem.newFileFragment(n,"schema",r.id,r)}async readSystemCommands(){let t=(await this.childrenForPath(`${this.dataPath}/${AC}`,"folder")).map(n=>n.split("/").pop());return Promise.all(t.map(async n=>{let i=await this.readLibraryCommands(n);return{name:n,commands:Object.values(i??{})}}))}async readLibraryCommands(t){return this.fileSystem.readFileFragments({path:`${this.dataPath}/${AC}/${t}/commands.mdb`,name:"commands",filename:"commands.mdb",parent:`${this.dataPath}/${AC}/${t}`,isFolder:!1,extension:"mdb"},"mdbCommands")}async saveSystemCommand(t,r){let n={path:`${this.dataPath}/${AC}/${t}/commands.mdb`,name:"commands",filename:"commands.mdb",parent:`${this.dataPath}/${AC}/${t}`,isFolder:!1,extension:"mdb"};if(r)await this.fileSystem.saveFileFragment(n,"schema",r.schema.id,()=>r.schema),await this.fileSystem.saveFileFragment(n,"mdbCommand",r.schema.id,()=>r);else{let i={m_fields:{uniques:Ji.uniques,cols:Ji.cols,rows:[]},m_schema:{uniques:[],cols:["id","name","type","def","predicate","primary"],rows:[]}},a=n.path,o=a.split(".").pop(),s=a.split("/").slice(0,-1).join("/"),l=a.split("/").pop().split(".")[0];await this.fileSystem.newFile(s,l,o,i)}}async deleteCommand(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);return this.fileSystem.deleteFileFragment(n,"mdbCommand",r)}async saveCommand(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);return i||(i=await this.createDefaultCommands(t)),this.fileSystem.saveFileFragment(i,"mdbCommand",r,n)}async contextForSpace(t){let r=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return r?this.fileSystem.readFileFragments(r,"mdbTable",Nr):dx(this.spaceManager.superstate,this.spaceInfoForPath(t))}async addSpaceProperty(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t)?.dbPath);return n||await this.createDefaultTable(t),this.fileSystem.newFileFragment(n,"field",r.name,r)}async deleteSpaceProperty(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return this.fileSystem.deleteFileFragment(n,"field",r)}async saveSpaceProperty(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return i||await this.createDefaultTable(t),this.fileSystem.saveFileFragment(i,"field",n,a=>({...a,...r}))}async addProperty(t,r){let n=await this.fileSystem.getFile(t);this.fileSystem.newFileFragment(n,"property",r.name,r)}async saveProperties(t,r){let n=await this.fileSystem.getFile(t);return this.fileSystem.saveFileFragment(n,"property",null,i=>({...i,...r}))}async readLabel(t){let r=this.fileSystem.getFileCache(t)?.label;if(!r){let n=await this.fileSystem.getFile(t);return n?this.fileSystem.readFileFragments(n,"label",null):{}}return r}async saveLabel(t,r,n){if(this.spaceManager.superstate.spacesIndex.has(t)){let a=this.spaceInfoForPath(t),o=await this.fileSystem.getFile(a.defPath),s=await this.fileSystem.getFile(a.notePath);if(this.spaceManager.superstate.settings.enableFolderNote)s||(s=await this.fileSystem.newFile(a.folderPath,a.name,"md"));else{if(!o){let l=this.spaceInfoForPath(t).defPath,u=l.split(".").pop(),c=l.split("/").slice(0,-1).join("/"),f=l.split("/").pop().split(".")[0];o=await this.fileSystem.newFile(c,f,u)}s=o}await this.fileSystem.saveFileLabel(s,r,n);return}let i=await this.fileSystem.getFile(t);this.fileSystem.saveFileLabel(i,r,n)}async renameProperty(t,r,n){let i=await this.fileSystem.getFile(t);this.fileSystem.saveFileFragment(i,"property",null,a=>{let{[r]:o,...s}=a;return o?{...s,[n]:o}:a})}async readProperties(t){let r=await this.fileSystem.getFile(t);return this.fileSystem.readFileFragments(r,"property",null)}async deleteProperty(t,r){let n=await this.fileSystem.getFile(t);this.fileSystem.deleteFileFragment(n,"property",r)}allSpaces(){let t=Object.keys(cm).map(o=>this.spaceManager.spaceInfoForPath(`spaces://$${o}`)),r=()=>this.readTags().map(o=>Fg(this.spaceManager,Jj(o)))??[],n=()=>this.allPaths(["folder"]).filter(s=>!$H(this.spaceManager.superstate.settings,s)).map(s=>IE(this.spaceManager,s)),i=this.spaceManager.superstate.settings.enableDefaultSpaces?r():[],a=n();return[...t,...i,...a]}readTags(){return this.fileSystem.allTags()}spaceInfoForPath(t){return CJ(this.spaceManager,t)}allCaches(){return this.fileSystem.allCaches()}async spaceDefForSpace(t){let r=this.spaceInfoForPath(t);if(!r)return null;let n=r.defPath?await this.fileSystem.readTextFromFile(r.defPath):null;if(!n){let a=await this.fileSystem.getFile(r.notePath),s=(a?this.fileSystem.getFileCache(a.path)?.frontmatter:null)??{};return B6(s,this.spaceManager.superstate.settings)}let i=dr(n)??{};return B6(i,this.spaceManager.superstate.settings)}async createSpace(t,r,n){let i=this.spaceInfoForPath(r),a=i.folderPath=="/"?t:i.folderPath+"/"+t;if(await this.fileSystem.createFolder(a),Object.keys(n??{}).length>0)return this.saveSpace(a,()=>n)}async saveSpace(t,r,n){let i=r(await this.spaceDefForSpace(t))??{},a=this.spaceInfoForPath(t),o=await this.fileSystem.getFile(a.defPath);if(!o){let l=this.spaceInfoForPath(t).defPath,u=l.split(".").pop(),c=l.split("/").slice(0,-1).join("/"),f=l.split("/").pop().split(".")[0];o=await this.fileSystem.newFile(c,f,u)}let s=await this.fileSystem.getFile(a.notePath);this.spaceManager.superstate.settings.enableFolderNote?s||(s=await this.fileSystem.newFile(a.folderPath,qc(a.notePath),"md")):s=o,n&&await this.fileSystem.saveFileFragment(s,"property",null,l=>({...l,...n??{}})),await this.fileSystem.saveFileFragment(o,"definition",null,l=>({[qE]:i.filters,[BE]:i.contexts,[LE]:i.links,[zE]:i.sort,[RE]:i.template,[$E]:i.templateName,[eO]:i.recursive}))}renameSpace(t,r){let n=this.spaceInfoForPath(t),i=this.spaceInfoForPath(r);return this.fileSystem.renameFile(n.folderPath,i.folderPath).then(a=>(this.spaceManager.superstate.settings.enableFolderNote&&this.fileSystem.renameFile(Rf(n.notePath,i.path),i.notePath),a))}deleteSpace(t){let r=this.spaceInfoForPath(t),n=Fg(this.spaceManager,r.name);this.fileSystem.deleteFile(n.folderPath)}childrenForSpace(t){return this.fileSystem.allFiles().filter(r=>r.parent==t).map(r=>r.path)}addTag(t,r){this.fileSystem.addTagToFile(t,r)}renameTag(t,r,n){this.fileSystem.renameTagForFile(t,r,n)}deleteTag(t,r){this.fileSystem.removeTagFromFile(t,r)}pathsForTag(t){return this.fileSystem.filesForTag(t)}resolvePath(t,r){return this.fileSystem.resolvePath(t,r)}};var df=ge(Te());function PA(e){return Array.isArray?Array.isArray(e):r2e(e)==="[object Array]"}var lYe=1/0;function uYe(e){if(typeof e=="string")return e;let t=e+"";return t=="0"&&1/e==-lYe?"-0":t}function cYe(e){return e==null?"":uYe(e)}function Gm(e){return typeof e=="string"}function e2e(e){return typeof e=="number"}function fYe(e){return e===!0||e===!1||dYe(e)&&r2e(e)=="[object Boolean]"}function t2e(e){return typeof e=="object"}function dYe(e){return t2e(e)&&e!==null}function ff(e){return e!=null}function qH(e){return!e.trim().length}function r2e(e){return e==null?e===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}var pYe="Incorrect 'index' type",mYe=e=>`Invalid value for key ${e}`,hYe=e=>`Pattern length exceeds max of ${e}.`,AYe=e=>`Missing ${e} property in key`,gYe=e=>`Property 'weight' in key '${e}' must be a positive integer`,Ywe=Object.prototype.hasOwnProperty,LH=class{constructor(t){this._keys=[],this._keyMap={};let r=0;t.forEach(n=>{let i=n2e(n);this._keys.push(i),this._keyMap[i.id]=i,r+=i.weight}),this._keys.forEach(n=>{n.weight/=r})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function n2e(e){let t=null,r=null,n=null,i=1,a=null;if(Gm(e)||PA(e))n=e,t=Zwe(e),r=zH(e);else{if(!Ywe.call(e,"name"))throw new Error(AYe("name"));let o=e.name;if(n=o,Ywe.call(e,"weight")&&(i=e.weight,i<=0))throw new Error(gYe(o));t=Zwe(o),r=zH(o),a=e.getFn}return{path:t,id:r,weight:i,src:n,getFn:a}}function Zwe(e){return PA(e)?e:e.split(".")}function zH(e){return PA(e)?e.join("."):e}function vYe(e,t){let r=[],n=!1,i=(a,o,s)=>{if(!!ff(a))if(!o[s])r.push(a);else{let l=o[s],u=a[l];if(!ff(u))return;if(s===o.length-1&&(Gm(u)||e2e(u)||fYe(u)))r.push(cYe(u));else if(PA(u)){n=!0;for(let c=0,f=u.length;ce.score===t.score?e.idx{this._keysMap[r.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Gm(this.docs[0])?this.docs.forEach((t,r)=>{this._addString(t,r)}):this.docs.forEach((t,r)=>{this._addObject(t,r)}),this.norm.clear())}add(t){let r=this.size();Gm(t)?this._addString(t,r):this._addObject(t,r)}removeAt(t){this.records.splice(t,1);for(let r=t,n=this.size();r{let o=i.getFn?i.getFn(t):this.getFn(t,i.path);if(!!ff(o)){if(PA(o)){let s=[],l=[{nestedArrIndex:-1,value:o}];for(;l.length;){let{nestedArrIndex:u,value:c}=l.pop();if(!!ff(c))if(Gm(c)&&!qH(c)){let f={v:c,i:u,n:this.norm.get(c)};s.push(f)}else PA(c)&&c.forEach((f,d)=>{l.push({nestedArrIndex:d,value:f})})}n.$[a]=s}else if(Gm(o)&&!qH(o)){let s={v:o,n:this.norm.get(o)};n.$[a]=s}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}};function i2e(e,t,{getFn:r=$r.getFn,fieldNormWeight:n=$r.fieldNormWeight}={}){let i=new yC({getFn:r,fieldNormWeight:n});return i.setKeys(e.map(n2e)),i.setSources(t),i.create(),i}function kYe(e,{getFn:t=$r.getFn,fieldNormWeight:r=$r.fieldNormWeight}={}){let{keys:n,records:i}=e,a=new yC({getFn:t,fieldNormWeight:r});return a.setKeys(n),a.setIndexRecords(i),a}function v5(e,{errors:t=0,currentLocation:r=0,expectedLocation:n=0,distance:i=$r.distance,ignoreLocation:a=$r.ignoreLocation}={}){let o=t/e.length;if(a)return o;let s=Math.abs(n-r);return i?o+s/i:s?1:o}function CYe(e=[],t=$r.minMatchCharLength){let r=[],n=-1,i=-1,a=0;for(let o=e.length;a=t&&r.push([n,i]),n=-1)}return e[a-1]&&a-n>=t&&r.push([n,a-1]),r}var vy=32;function DYe(e,t,r,{location:n=$r.location,distance:i=$r.distance,threshold:a=$r.threshold,findAllMatches:o=$r.findAllMatches,minMatchCharLength:s=$r.minMatchCharLength,includeMatches:l=$r.includeMatches,ignoreLocation:u=$r.ignoreLocation}={}){if(t.length>vy)throw new Error(hYe(vy));let c=t.length,f=e.length,d=Math.max(0,Math.min(n,f)),p=a,h=d,m=s>1||l,g=m?Array(f):[],A;for(;(A=e.indexOf(t,h))>-1;){let k=v5(t,{currentLocation:A,expectedLocation:d,distance:i,ignoreLocation:u});if(p=Math.min(k,p),h=A+c,m){let M=0;for(;M=C;R-=1){let $=R-1,B=r[e.charAt($)];if(m&&(g[$]=+!!B),D[R]=(D[R+1]<<1|1)&B,k&&(D[R]|=(b[R+1]|b[R])<<1|1|b[R+1]),D[R]&w&&(v=v5(t,{errors:k,currentLocation:$,expectedLocation:d,distance:i,ignoreLocation:u}),v<=p)){if(p=v,h=$,h<=d)break;C=Math.max(1,2*d-h)}}if(v5(t,{errors:k+1,currentLocation:d,expectedLocation:d,distance:i,ignoreLocation:u})>p)break;b=D}let S={isMatch:h>=0,score:Math.max(.001,v)};if(m){let k=CYe(g,s);k.length?l&&(S.indices=k):S.isMatch=!1}return S}function jYe(e){let t={};for(let r=0,n=e.length;r{this.chunks.push({pattern:d,alphabet:jYe(d),startIndex:p})},f=this.pattern.length;if(f>vy){let d=0,p=f%vy,h=f-p;for(;d{let{isMatch:A,score:b,indices:v}=DYe(t,h,m,{location:i+g,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:l,includeMatches:n,ignoreLocation:u});A&&(d=!0),f+=b,A&&v&&(c=[...c,...v])});let p={isMatch:d,score:d?f/this.chunks.length:1};return d&&n&&(p.indices=c),p}},Hm=class{constructor(t){this.pattern=t}static isMultiMatch(t){return Xwe(t,this.multiRegex)}static isSingleMatch(t){return Xwe(t,this.singleRegex)}search(){}};function Xwe(e,t){let r=e.match(t);return r?r[1]:null}var UH=class extends Hm{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){let r=t===this.pattern;return{isMatch:r,score:r?0:1,indices:[0,this.pattern.length-1]}}},WH=class extends Hm{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){let n=t.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}},VH=class extends Hm{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){let r=t.startsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,this.pattern.length-1]}}},GH=class extends Hm{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){let r=!t.startsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,t.length-1]}}},HH=class extends Hm{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){let r=t.endsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},QH=class extends Hm{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){let r=!t.endsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,t.length-1]}}},b5=class extends Hm{constructor(t,{location:r=$r.location,threshold:n=$r.threshold,distance:i=$r.distance,includeMatches:a=$r.includeMatches,findAllMatches:o=$r.findAllMatches,minMatchCharLength:s=$r.minMatchCharLength,isCaseSensitive:l=$r.isCaseSensitive,ignoreLocation:u=$r.ignoreLocation}={}){super(t),this._bitapSearch=new y5(t,{location:r,threshold:n,distance:i,includeMatches:a,findAllMatches:o,minMatchCharLength:s,isCaseSensitive:l,ignoreLocation:u})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}},x5=class extends Hm{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let r=0,n,i=[],a=this.pattern.length;for(;(n=t.indexOf(this.pattern,r))>-1;)r=n+a,i.push([n,r-1]);let o=!!i.length;return{isMatch:o,score:o?0:1,indices:i}}},YH=[UH,x5,VH,GH,QH,HH,WH,b5],Kwe=YH.length,OYe=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,MYe="|";function NYe(e,t={}){return e.split(MYe).map(r=>{let n=r.trim().split(OYe).filter(a=>a&&!!a.trim()),i=[];for(let a=0,o=n.length;a!!(e[w5.AND]||e[w5.OR]),_Ye=e=>!!e[JH.PATH],PYe=e=>!PA(e)&&t2e(e)&&!eQ(e),Jwe=e=>({[w5.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function a2e(e,t,{auto:r=!0}={}){let n=i=>{let a=Object.keys(i),o=_Ye(i);if(!o&&a.length>1&&!eQ(i))return n(Jwe(i));if(PYe(i)){let l=o?i[JH.PATH]:a[0],u=o?i[JH.PATTERN]:i[l];if(!Gm(u))throw new Error(mYe(l));let c={keyId:zH(l),pattern:u};return r&&(c.searcher=KH(u,t)),c}let s={children:[],operator:a[0]};return a.forEach(l=>{let u=i[l];PA(u)&&u.forEach(c=>{s.children.push(n(c))})}),s};return eQ(e)||(e=Jwe(e)),n(e)}function IYe(e,{ignoreFieldNorm:t=$r.ignoreFieldNorm}){e.forEach(r=>{let n=1;r.matches.forEach(({key:i,norm:a,score:o})=>{let s=i?i.weight:null;n*=Math.pow(o===0&&s?Number.EPSILON:o,(s||1)*(t?1:a))}),r.score=n})}function BYe(e,t){let r=e.matches;t.matches=[],ff(r)&&r.forEach(n=>{if(!ff(n.indices)||!n.indices.length)return;let{indices:i,value:a}=n,o={indices:i,value:a};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),t.matches.push(o)})}function RYe(e,t){t.score=e.score}function $Ye(e,t,{includeMatches:r=$r.includeMatches,includeScore:n=$r.includeScore}={}){let i=[];return r&&i.push(BYe),n&&i.push(RYe),e.map(a=>{let{idx:o}=a,s={item:t[o],refIndex:o};return i.length&&i.forEach(l=>{l(a,s)}),s})}var yc=class{constructor(t,r={},n){this.options={...$r,...r},this.options.useExtendedSearch,this._keyStore=new LH(this.options.keys),this.setCollection(t,n)}setCollection(t,r){if(this._docs=t,r&&!(r instanceof yC))throw new Error(pYe);this._myIndex=r||i2e(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(t){!ff(t)||(this._docs.push(t),this._myIndex.add(t))}remove(t=()=>!1){let r=[];for(let n=0,i=this._docs.length;n-1&&(l=l.slice(0,r)),$Ye(l,this._docs,{includeMatches:n,includeScore:i})}_searchStringList(t){let r=KH(t,this.options),{records:n}=this._myIndex,i=[];return n.forEach(({v:a,i:o,n:s})=>{if(!ff(a))return;let{isMatch:l,score:u,indices:c}=r.searchIn(a);l&&i.push({item:a,idx:o,matches:[{score:u,value:a,norm:s,indices:c}]})}),i}_searchLogical(t){let r=a2e(t,this.options),n=(s,l,u)=>{if(!s.children){let{keyId:f,searcher:d}=s,p=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(l,f),searcher:d});return p&&p.length?[{idx:u,item:l,matches:p}]:[]}let c=[];for(let f=0,d=s.children.length;f{if(ff(s)){let u=n(r,s,l);u.length&&(a[l]||(a[l]={idx:l,item:s,matches:[]},o.push(a[l])),u.forEach(({matches:c})=>{a[l].matches.push(...c)}))}}),o}_searchObjectList(t){let r=KH(t,this.options),{keys:n,records:i}=this._myIndex,a=[];return i.forEach(({$:o,i:s})=>{if(!ff(o))return;let l=[];n.forEach((u,c)=>{l.push(...this._findMatches({key:u,value:o[c],searcher:r}))}),l.length&&a.push({idx:s,item:o,matches:l})}),a}_findMatches({key:t,value:r,searcher:n}){if(!ff(r))return[];let i=[];if(PA(r))r.forEach(({v:a,i:o,n:s})=>{if(!ff(a))return;let{isMatch:l,score:u,indices:c}=n.searchIn(a);l&&i.push({score:u,key:t,value:a,idx:o,norm:s,indices:c})});else{let{v:a,n:o}=r,{isMatch:s,score:l,indices:u}=n.searchIn(a);s&&i.push({score:l,key:t,value:a,norm:o,indices:u})}return i}};yc.version="7.0.0";yc.createIndex=i2e;yc.parseIndex=kYe;yc.config=$r;yc.parseQuery=a2e;FYe(ZH);var vi=ge(Te());var cl=ge(Te()),qYe={position:"absolute",width:0,height:0,visibility:"hidden",overflow:"scroll",whiteSpace:"pre"},LYe=["fontSize","fontFamily","fontWeight","fontStyle","letterSpacing","textTransform"],o2e=(0,cl.forwardRef)((e,t)=>{let{classNames:r,inputAttributes:n,inputEventHandlers:i,index:a}=e,o=(0,cl.useRef)(null),[s,l]=(0,cl.useState)(null),[u,c]=(0,cl.useState)("");(0,cl.useEffect)(()=>{f(),d(),setTimeout(()=>{t.current?.focus()},50)},[]),(0,cl.useEffect)(()=>{u!==e.placeholderText&&(c(e.placeholderText),d())},[e.query,e.placeholderText]);let f=()=>{let p=window.getComputedStyle(t.current);LYe.forEach(h=>{o.current.style[h]=p[h]})},d=()=>{let p=Math.ceil(o.current.scrollWidth)+2;p!==s&&l(p)};return cl.default.createElement("div",{className:r.search},cl.default.createElement("div",{className:r.searchWrapper},cl.default.createElement("div",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//search")}}),cl.default.createElement("input",{...n,...i,ref:t,value:e.query,placeholder:u,className:r.searchInput,role:"combobox",style:{width:"100%"},onClick:p=>p.stopPropagation()}),cl.default.createElement("div",{ref:o,style:qYe},e.query||u),cl.default.createElement("span",null)))}),s2e=o2e;o2e.displayName="SelectMenuSearch";var tQ=ge(Te()),zYe=e=>tQ.default.createElement("button",{type:"button",className:e.classNames.selectedTag,onClick:e.onDelete},tQ.default.createElement("span",{className:e.classNames.selectedTagName},e.tag.name)),l2e=zYe;var u2e=ge(Te()),c2e=e=>u2e.default.createElement("div",{className:"mk-sticker",dangerouslySetInnerHTML:{__html:e.ui.getSticker(e.sticker)}});var ui=ge(Te());function f2e(e,t){let r=j2(t);return e?.replace(r,"$&")}var UYe=e=>{let t=(0,ui.useRef)(null);return(0,ui.useEffect)(()=>{e.active&&t?.current?.scrollIntoViewIfNeeded()},[e.active]),ui.default.createElement(ui.default.Fragment,null,e.item.icon&&ui.default.createElement(c2e,{ui:e.ui,sticker:e.item.icon}),ui.default.createElement("div",{ref:t,className:"mk-menu-options-inner"},e.item.onToggle&&ui.default.createElement("div",null,"Toggle"),ui.default.createElement("span",{style:e.item.color?.length>0?{background:e.item.color,padding:"2px 4px",borderRadius:"4px",color:e.item.color=="var(--mk-color-none)"?"inherit":"var(--mk-color-white)"}:{},dangerouslySetInnerHTML:{__html:f2e(e.item.name,e.query)}}),e.item.description&&ui.default.createElement("span",{"aria-label":e.item.description,className:"mk-menu-options-description",dangerouslySetInnerHTML:{__html:f2e(e.item.description,e.query)}})),e.item.type==1&&ui.default.createElement("span",null,e.item.value),e.item.type==3&&e.item.value&&ui.default.createElement("div",{className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//check")}}),e.item.onMoreOptions||e.onMoreOption&&e.item.removeable?ui.default.createElement("div",{onClick:r=>{r.stopPropagation(),r.preventDefault(),e.item.onMoreOptions?e.item.onMoreOptions(r):e.onMoreOption(r,e.item.value)},className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//options")}}):null,e.item.removeable&&e.onDeleteOption&&ui.default.createElement("div",{onClick:r=>{r.stopPropagation(),r.preventDefault(),e.onDeleteOption(e.item.value)},className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//close")}}),e.item.type==6&&ui.default.createElement("div",{className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//chevron-right")}}))},WYe=e=>{let[t,r]=(0,ui.useState)(e.value);return ui.default.createElement("input",{type:"text",value:t,onKeyDown:n=>{n.key=="Enter"&&e.setValue(t)},onMouseDown:n=>n.stopPropagation(),onClick:n=>n.stopPropagation(),onFocus:n=>{n.stopPropagation()},onChange:n=>r(n.target.value),onBlur:n=>e.setValue(t)})},VYe=e=>{let t=e.options.map((r,n)=>{let i=`${e.id}-${n}`,a=r.type==-1?"mk-menu-separator":r.type==2?"mk-menu-input":r.type==5?"mk-menu-custom":`mk-menu-option ${e.index===n&&e.classNames.suggestionActive} ${r.disabled&&e.classNames.suggestionDisabled}`;return ui.default.createElement("div",{ref:o=>{e.refs?.current&&(e.refs.current[n]=o)},onMouseDown:o=>{e.isDisclosureMenu||o.stopPropagation(),o.preventDefault()},onClick:o=>{if(r.onSubmenu&&e.openSubmenu){let s=e.refs?.current[n].getBoundingClientRect();e.openSubmenu(r.onSubmenu(s,()=>{e.onHide&&e.onHide(),e.hide()}))}else r.onClick?(r.onClick(o),r.type!=6&&r.type!=1&&e.hide()):(r.type==null||r.type==0||r.type==1)&&(e.selectOption(r,{ctrlKey:o.ctrlKey,metaKey:o.metaKey,altKey:o.altKey,shiftKey:o.shiftKey,doubleClick:o.detail==2}),e.isDisclosureMenu||o.stopPropagation())},id:i,key:i,className:a},r.type==-1?ui.default.createElement(ui.default.Fragment,null):r.type==-2?ui.default.createElement("div",{className:"mk-menu-options-section"},r.name):r.type==2?ui.default.createElement(WYe,{value:r.value,setValue:r.onValueChange}):r.type==5?ui.default.createElement(r.fragment,{hide:e.hide,onSubmenu:o=>{if(e.openSubmenu){let s=e.refs?.current[n].getBoundingClientRect();e.openSubmenu(o(s,()=>{e.onHide&&e.onHide(),e.hide()}))}}}):ui.default.createElement(UYe,{ui:e.ui,item:r,query:e.query,active:n==e.index,onMoreOption:e.moreOption,onDeleteOption:e.deleteOption}))});return ui.default.createElement("div",{className:"mk-menu-suggestions"},t,e.query&&e.allowNew&&ui.default.createElement("div",{className:"mk-menu-option",onMouseDown:r=>r.preventDefault(),onClick:r=>e.selectOption({name:e.query,value:e.query},{ctrlKey:r.ctrlKey,metaKey:r.metaKey,altKey:r.altKey,shiftKey:r.shiftKey})},ui.default.createElement("div",{className:"mk-sticker",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//plus")}}),ui.default.createElement("div",{className:"mk-menu-options-inner"},e.addKeyword??"Add"," ",e.query)))},S5=VYe;function d2e(e,t){let r=e.querySelectorAll("a,button,input"),n=Array.prototype.findIndex.call(r,a=>a===t),i=r[n-1]||r[n+1];i&&i.focus()}var yy={ENTER:"Enter",TAB:"Tab",BACKSPACE:"Backspace",UP_ARROW:"ArrowUp",UP_ARROW_COMPAT:"Up",DOWN_ARROW:"ArrowDown",DOWN_ARROW_COMPAT:"Down",LEFT_ARROW:"ArrowLeft",RIGHT_ARROW:"ArrowRight"},m2e={root:"mk-menu-container",rootFocused:"mk-focused",selected:"mk-menu-input-wrapper",selectedTagWrapper:"mk-menu-selected-tag-wrapper",selectedTag:"mk-menu-selected-tag",selectedTagName:"mk-menu-selected-tag-name",search:"mk-menu-search",searchWrapper:"mk-menu-search-container",searchInput:"mk-menu-search-input",suggestions:"mk-menu-suggestions",suggestionActive:"mk-active",suggestionDisabled:"mk-disabled"},GYe={ui:null,id:"SelectMenu",tags:[],hide:()=>null,onHide:()=>null,suggestionsOnly:!1,placeholderText:z.labels.optionItemSelectPlaceholder,noSuggestionsText:null,newTagText:null,suggestions:[],suggestionsFilter:HYe,suggestionsTransform:null,classNames:m2e,delimiters:[yy.ENTER],minQueryLength:2,maxSuggestionsLength:8,inputAttributes:{}},h2e=(e,t)=>e.findIndex(r=>oxe(t).test(r.name)),p2e=(e,t,r,n,i,a)=>{if(t.length>=e.minQueryLength){let o=h2e(n,t),s=r===-1?o:r,l=s>-1?n[s]:null;i(l||{name:t,value:t},a)}};function HYe(e,t){return j2(t).test(e.name)}function QYe(e,t,r){let n,i=e.suggestions;r.length>0&&(i=e.suggestions.filter(s=>s.section==r));let a={threshold:0,ignoreLocation:!0,keys:["name","value"]},o=new yc(i,a);return n=t.length==0?i:o.search(t).map(s=>s.item),n=n.slice(0,e.maxSuggestionsLength),e.newTagText&&h2e(n,t)===-1?n.push({id:0,name:t,value:t}):e.noSuggestionsText&&n.length===0&&n.push({id:0,name:e.noSuggestionsText,value:"",disabled:!0}),n}var A2e=vi.default.forwardRef((e,t)=>{let r={...GYe,...e},[n,i]=(0,vi.useState)([]),a=(0,vi.useRef)([]),o=(0,vi.useMemo)(()=>r.showSections?[{name:"All",value:""},...r.sections??Mr(r.suggestions.map(re=>re.section)).filter(re=>re)]:[],[r.showSections,r.sections,r.suggestions]),s=(0,vi.useRef)(null),[l,u]=(0,vi.useState)(""),[c,f]=(0,vi.useState)(""),[d,p]=(0,vi.useState)(!1),[h,m]=(0,vi.useState)(0),g=(0,vi.useRef)(!1);(0,vi.useEffect)(()=>{t&&(t.current=()=>d?!0:(s?.current?.focus(),p(!0),!1))},[d]),(0,vi.useEffect)(()=>{if(c.length==0&&r.defaultSuggestions){i(r.defaultSuggestions);return}i(QYe(r,c,l))},[c,r.defaultSuggestions,l,r.suggestions]);let A=(0,vi.useRef)(null),b=re=>{if(re.type==="compositionstart"){g.current=!0;return}if(re.type==="compositionend"){g.current=!1;return}let Q=re.target.value;r.onInput&&r.onInput(Q),Q.length===c.length+1&&r.delimiters.indexOf(c.slice(-1))>-1?p2e(r,c,h,n,k,{}):Q!==c&&f(Q)},v=re=>{g.current||(r.delimiters.indexOf(re.key)>-1&&((c||h>-1)&&re.preventDefault(),p2e(r,c,h,n,k,{ctrlKey:re.ctrlKey,metaKey:re.metaKey,altKey:re.altKey,shiftKey:re.shiftKey})),re.key!="Escape"&&(re.key===yy.TAB&&R(re),re.key===yy.BACKSPACE&&P(),(re.key===yy.UP_ARROW||re.key===yy.UP_ARROW_COMPAT)&&T(re),(re.key===yy.DOWN_ARROW||re.key===yy.DOWN_ARROW_COMPAT)&&D(re),re.stopPropagation()))},x=()=>{p(!1),r.onBlur&&r.onBlur()},w=()=>{p(!0),r.onFocus&&r.onFocus()},S=(re,Q)=>{A.current&&d2e(A.current,Q.currentTarget),M(re)},k=(re,Q)=>{re.disabled||r.onValidate&&!r.onValidate(re)||(r.onAddition(re,Q),O())},M=re=>{r.onDelete(re)},O=()=>{f(""),m(-1)},C=()=>{m(-1)},T=re=>{re.preventDefault();let Q=n.length-1,he=h<=0?Q:h-1;n[he].disabled?m(he<=0?Q:he-1):m(he)},D=re=>{re.preventDefault();let Q=n.length-1,he=h>=Q?0:h+1;n[he].disabled?m(he>=Q?0:he+1):m(he)};function P(){c.length||M(r.tags.length-1)}function R(re){r.showSections&&(re.preventDefault(),re.stopPropagation(),u(Q=>{let he=o.findIndex(Ie=>Ie.value==Q);return re.shiftKey?he==0?Q:(r.onSelectSection&&r.onSelectSection(o[he-1].value),o[he-1].value):he==o.length-1?Q:(r.onSelectSection&&r.onSelectSection(o[he+1].value),o[he+1].value)}))}let $=()=>{s.current.focus()},B={onChange:b,onCompositionEnd:b,onCompositionStart:b};(0,vi.useEffect)(()=>(r.ui.inputManager.on("keydown",v),()=>{r.ui.inputManager.off("keydown",v)}),[n,h]);let N=d&&c.length>=r.minQueryLength,W=Object.assign({},m2e,r.classNames);r.wrapperClass&&(W.root=`${W.root} ${r.wrapperClass}`);let _=[W.root];d&&_.push(W.rootFocused);let X=(0,vi.useRef)(null),oe=re=>{X.current&&X.current.hide(!0),X.current=re};return vi.default.createElement("div",{ref:A,className:_.join(" "),style:r.suggestionsOnly?{}:{"--mk-menu-max-height":"200px"}},r.suggestionsOnly?null:vi.default.createElement("div",{className:W.selected,"aria-relevant":"additions removals","aria-live":"polite"},r.tags.length>0&&vi.default.createElement("div",{className:W.selectedTagWrapper},r.tags.map((re,Q)=>vi.default.createElement(l2e,{key:Q,tag:re,classNames:W,onDelete:he=>S(Q,he)}))),vi.default.createElement(s2e,{ui:r.ui,ref:s,query:c,index:h,id:r.id,currentSection:o.find(re=>re.value==l),classNames:W,inputAttributes:r.inputAttributes,inputEventHandlers:B,expanded:N,placeholderText:r.placeholderText})),r.showSections?vi.default.createElement("div",{className:"mk-menu-sections"},o.map((re,Q)=>vi.default.createElement("div",{key:Q,onClick:he=>{he.stopPropagation(),u(re.value)},className:`${l==re.value?"is-active":""} mk-menu-section`},re.name==""?z.labels.all:re.name))):vi.default.createElement(vi.default.Fragment,null),n.length||r.allowNew?vi.default.createElement(S5,{ui:r.ui,hide:()=>{r.hide()},addKeyword:r.addKeyword,refs:a,options:n,query:c,setIndex:m,index:h,onHide:r.onHide,id:r.id,classNames:W,expanded:N,selectOption:k,allowNew:r.allowNew,moreOption:r.onMoreOption,deleteOption:r.onDeleteOption,isDisclosureMenu:r.isDisclosure,openSubmenu:oe}):null,r.previewComponent)});A2e.displayName="SelectMenuComponent";var g2e=A2e;var v2e=df.default.forwardRef((e,t)=>{let r=e.options.map((f,d)=>({...f,id:d+1}));(0,df.useEffect)(()=>{i(e.options.map((f,d)=>({...f,id:d+1})))},[e.options]);let[n,i]=(0,df.useState)(r),[a,o]=(0,df.useState)(e.value.map(f=>r.find(d=>d.value==f)??{id:0,name:f,value:f})),s=(0,df.useCallback)(f=>{let d=a.filter((p,h)=>h!==f);o(d),e.saveOptions&&e.saveOptions(n.map(p=>p.value),d.map(p=>p.value),!1)},[n,a,e]),l=(0,df.useCallback)(f=>{let d=n.filter(h=>h.value!=f),p=a.filter(h=>h.value!=f);i(d),o(p),e.removeOption&&e.removeOption(f),e.hide()},[a,n,e]),u=(0,df.useCallback)((f,d)=>{let p=f,h=n,m=a;n.find(g=>g.value==f.value)||(p={id:n.length+1,name:f.name,value:f.value??f.name},h=[...n,p],i(h)),e.multi?a.find(g=>g.value==p.value)||(m=[...a,p],o(m)):(m=[p],o(m)),e.saveOptions&&e.saveOptions(h.map(g=>g.value),m.map(g=>g.value),!0),!e.multi&&f.type!=1&&e.hide()},[a,n]),c=(0,df.useCallback)(f=>!(!e.editable&&!n.find(d=>d.value==f.value)||f.name.length==0),[n]);return df.default.createElement(g2e,{tags:e.multi?a:[],suggestions:n,ui:e.ui,ref:t,addKeyword:e.addKeyword,hide:e.hide,onDelete:s,wrapperClass:e.wrapperClass,onMoreOption:e.onMoreOption,onDeleteOption:l,onAddition:u,onValidate:c,onSelectSection:e.onSelectSection,defaultSuggestions:e.defaultOptions,placeholderText:e.placeholder??"",minQueryLength:0,onHover:e.onHover,showSections:e.showSections,sections:e.sections,maxSuggestionsLength:e.showAll?Math.min(50,e.options.length):25,suggestionsOnly:!e.searchable&&!e.editable,allowNew:e.editable,previewComponent:e.previewComponent,isDisclosure:e.isDisclosure})});v2e.displayName="SelectMenu";var Kz=v2e;var To=ge(Te());var fl=ge(Te());var yd=(0,fl.forwardRef)((e,t)=>{let r=(0,fl.useRef)(null),[n,i]=(0,fl.useState)(!1),[a,o]=(0,fl.useState)(!1),s=async u=>{let c=r.current,f=e.superstate.spaceManager.uriByString(e.path,e.source),d=e.properties,p=e.superstate.pathsIndex.get(f.basePath),h=p?.type=="space"?e.superstate.spacesIndex.get(e.path)?.space.notePath:f.fullPath,m=e.forceNote??h?await e.superstate.spaceManager.pathExists(h):!1;if(!h||!m)if(u){let g=p?.type=="space"?(e.superstate.spacesIndex.get(e.path)?.space).folderPath:e.superstate.spaceManager.parentPathForPath(f.basePath);if(!g)return;let A=await e.superstate.spaceManager.createItemAtPath(g,"md",qc(e.path));i(!1),await e.superstate.ui.openPath(A,!1,c,d)}else{i(!0),o(!1);return}else i(!1),e.superstate.ui.openPath(h,!1,c,d);o(!0)},l=()=>{e.load?s():r?.current&&(r.current.innerHTML="")};return(0,fl.useEffect)(()=>{l()},[e.load,e.path]),(0,fl.useEffect)(()=>{let u=()=>{r.current&&!r.current.hasChildNodes()&&e.load&&!n&&s()};return e.superstate.ui.eventsDispatch.addListener("activeStateChanged",u),()=>{r.current=null,e.superstate.ui.eventsDispatch.removeListener("activeStateChanged",u)}},[]),fl.default.createElement(fl.default.Fragment,null,fl.default.createElement("div",{className:`${e.classname??""} mk-flowspace-editor`,ref:r,onClick:u=>u.stopPropagation()}),n?fl.default.createElement("div",{onClick:()=>s(!0),className:"mk-placeholder",style:{color:"var(--mk-ui-text-tertiary)"}},z.labels.notePlaceholder.replace("${1}",qc(e.path))):fl.default.createElement(fl.default.Fragment,null))});yd.displayName="FlowView";var y2e=(e,t,r,n,i,a,o,s)=>{let l=[];l.push(Pm(n?.name??"",u=>o(n.name,u))),l.push(Ut),l.push({name:z.menu.changePropertyType,icon:"ui//list",onClick:u=>{s(u,n.name)}}),n.type!="object"&&l.push({name:z.menu.syncToContext,icon:"ui//sync",onClick:u=>{a(n)}}),l.push({name:z.menu.deleteProperty,icon:"ui//trash",onClick:u=>{i(n)}}),e.ui.openMenu(t,Yt(e.ui,l),r)};var os=ge(Te());var b2e=e=>{let{pathState:t}=(0,os.useContext)(Ir),[r,n]=(0,os.useState)({}),[i,a]=(0,os.useState)([]),[o,s]=(0,os.useState)([]),{tableData:l,saveProperty:u,delProperty:c,saveFrame:f}=(0,os.useContext)(aa),d=async()=>{let D=e.superstate.spacesMap.get(t.path)??new Set,P=(await Promise.all([...D].map(async _=>e.superstate.spaceManager.readTable(_,Nr).then(X=>X.cols??[])))).reduce((_,X)=>[..._,...X],[]),R=[],$={},B=t?.metadata?.property??{},N=Gj([...Object.keys(B),...l?.cols?.map(_=>_.name)??[]]).filter(_=>!P.some(X=>X.name==_)),W=N.map(_=>l?.cols?.find(X=>X.name==_)??{table:"",name:_,schemaId:"",type:Uh(B[_],_)});B&&(R.push(...W),N.forEach(_=>{$[_]=Ki(_,B[_])})),a(R.filter(_=>!e.excludeKeys?.some(X=>X==_.name))),s([...e.superstate.settings.hideFrontmatter?P.map(_=>_.name):[]]),n(Vm(e.superstate.formulaContext,e.superstate.pathsIndex,$,W,t))},p=D=>{e.spaces.find(P=>P==D.path)&&d()};(0,os.useEffect)(()=>(d(),e.superstate.eventsDispatcher.addListener("contextStateUpdated",p),()=>{e.superstate.eventsDispatcher.removeListener("contextStateUpdated",p)}),[e.spaces,l]);let h=(D,P)=>{if(u){let R=l?.cols?.find($=>$.name==P.name);R&&u(P,R)}Di(e.superstate,t.path,{[P.name]:Sa(P.type,D,!0)})},m=D=>{c&&D&&c(D),Pye(e.superstate,t.path,D.name)},g=async(D,P)=>{let R={...D,schemaId:Nr},$=e.superstate.spacesIndex.get(P)?.space;!$||(await e.superstate.spaceManager.addSpaceProperty(P,R),await CB(e.superstate.spaceManager,$,t.path,R.name,r[R.name]))},A=(D,P)=>{let R=D.target.getBoundingClientRect(),$=[...e.superstate.spacesMap.get(t.path)].map(B=>e.superstate.pathsIndex.get(B)).filter(B=>B).map(B=>({name:B.name,value:B.path,icon:B.label?.sticker,description:B.path}));e.superstate.ui.openMenu(R,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:$,saveOptions:(B,N)=>{g(P,N[0])},placeholder:z.labels.spaceSelectPlaceholder,detail:!0,searchable:!0,showAll:!0},je(D.view.document),"bottom")},b=(D,P)=>{if(u){let R=l?.cols?.find($=>$.name==D);R&&u({...R,name:P},R)}gG(e.superstate,t.path,D,P)},v=(D,P)=>{if(u){let R=l?.cols?.find($=>$.name==P);R&&u({...R,type:D[0]},R)}Di(e.superstate,t.path,{[P]:rx(D[0])})},x=(D,P)=>{let R=D.target.getBoundingClientRect();e.superstate.ui.openMenu(R,{ui:e.superstate.ui,multi:!1,editable:!1,searchable:!1,saveOptions:($,B)=>v(B,P),value:[],showAll:!0,options:Xs.filter($=>$.metadata).map(($,B)=>({id:B+1,name:$.label,value:$.type,icon:$.icon}))},je(D.view.document))},[w,S]=(0,os.useState)(null),[k,M]=(0,os.useState)(null),O=()=>{M(null),S(null)};Vo({onDragStart({active:D}){D.data.current.type=="property"&&S(D.data.current.property)},onDragOver({active:D,over:P}){let R=P?.data.current.id;P?.data.current.type=="property"&&R&&M(R)},onDragCancel(){O()},onDragEnd({active:D,over:P}){if(!D||!k){O();return}O()}});let C=(D,P)=>{if(u){let R=l?.cols?.find($=>$.name==P.name);R&&u(D,R)}D.name!=P.name&&gG(e.superstate,t.path,P.name,D.name)},T=(D,P)=>{let R=D.target.getBoundingClientRect();if(t.type=="space"){Lm({superstate:e.superstate,rect:R,win:je(D.view.document),editable:!0,options:[],field:P,fields:i,contextPath:null,saveField:$=>C($,P),deleteColumn:m,anchor:"bottom"});return}y2e(e.superstate,R,je(D.view.document),P,m,()=>A(D,P),b,x)};return os.default.createElement(os.default.Fragment,null,e.compactMode?i.map((D,P)=>os.default.createElement(as,{key:P,path:t.path,propertyMenu:R=>T(R,D),superstate:e.superstate,initialValue:r[D.name],row:r,compactMode:e.compactMode,column:{...D,table:""},columns:[],editMode:e.editable?5:2,updateValue:R=>h(R,D),updateFieldValue:(R,$)=>h($,{...D,value:R}),contextTable:{},source:t.path})):e.force?i.map((D,P)=>os.default.createElement(as,{key:P,path:t.path,propertyMenu:R=>T(R,D),superstate:e.superstate,initialValue:r[D.name],row:r,compactMode:e.compactMode,column:{...D,table:""},columns:[],editMode:e.editable?5:2,updateValue:R=>h(R,D),updateFieldValue:(R,$)=>h($,{...D,value:R}),contextTable:{},source:t.path})):os.default.createElement(os.default.Fragment,null),o.length>0&&os.default.createElement("style",null,`${o.map(D=>`.metadata-property[data-property-key="${D}"]`).join(", ")} +`,{name:"Superstate Indexer"})}var A5=class{constructor(t,r){this.numWorkers=t;this.cache=r;this.workers=[],this.busy=[],this.reloadQueue=[],this.reloadSet=new Set,this.callbacks=new Map;for(let n=0;nthis.finish(a.data.job,a.data.result,n),this.workers.push(i),this.busy.push(!1)}}reload(t){let r=F2(t),n=new Promise((a,o)=>{this.callbacks.has(r)?this.callbacks.get(r)?.push([a,o]):this.callbacks.set(r,[[a,o]])});if(this.reloadSet.has(r))return n;this.reloadSet.add(r);let i=this.nextAvailableWorker();return i!==void 0?this.send(t,i):this.reloadQueue.push(t),n}finish(t,r,n){let i=F2(t),a=[].concat(this.callbacks.get(i)??[]);this.reloadSet.delete(i),this.callbacks.delete(i),this.busy[n]=!1;let o=this.reloadQueue.shift();if(o!==void 0&&this.send(o,n),"$error"in r)for(let[s,l]of a)l(r.$error);else for(let[s,l]of a)s(r)}async send(t,r){if(t.type=="paths"){let n=await this.cache.spaceManager.allCaches(),i={settings:this.cache.settings,spacesCache:this.cache.spacesIndex,pathCache:n,oldMetadata:this.cache.pathsIndex};this.message(r,{job:t,payload:i}),this.busy[r]=!0;return}if(t.type=="path"){let n=this.cache.spacesIndex.get(t.path),i=t.path,a;n&&(a=n.space.name,this.cache.settings.enableFolderNote?i=n.space.notePath:i=n.space.defPath);let o=await this.cache.spaceManager.readPathCache(i)??await this.cache.spaceManager.readPathCache(t.path);a=a??o?.label.name;let s=await this.cache.spaceManager.parentPathForPath(t.path),l=n?"space":o.type,u=n?n.type:o?.subtype,c={path:t.path,settings:this.cache.settings,spacesCache:this.cache.spacesIndex,pathMetadata:o,name:a,parent:s,type:l,subtype:u,oldMetadata:this.cache.pathsIndex.get(t.path)};this.message(r,{job:t,payload:c}),this.busy[r]=!0;return}if(t.type=="context"){let n=this.cache.spacesIndex.get(t.path)?.space;if(!n||!n.path){this.message(r,{job:t,payload:{space:n,mdb:null,paths:[...this.cache.spacesMap.getInverse(t.path)],pathsIndex:this.cache.pathsIndex}}),this.busy[r]=!0;return}let i=await this.cache.spaceManager.contextInitiated(n.path);this.cache.spaceManager.readAllTables(n.path).then(a=>{this.message(r,{job:t,payload:{space:n,mdb:a,paths:[...this.cache.spacesMap.getInverse(t.path)],dbExists:i,pathsIndex:this.cache.pathsIndex}}),this.busy[r]=!0});return}if(t.type=="contexts"){let n=this.cache.allSpaces().filter(a=>a.type!="default").map(a=>a.space),i=new Map;for(let a of n){let o=await this.cache.spaceManager.contextInitiated(a.path);await this.cache.spaceManager.readAllTables(a.path).then(s=>{i.set(a.path,{space:a,mdb:s,paths:[...this.cache.spacesMap.getInverse(a.path)],dbExists:o})})}this.message(r,{job:t,payload:{map:i,pathsIndex:this.cache.pathsIndex}}),this.busy[r]=!0}}message(t,r){this.workers[t].postMessage(r)}nextAvailableWorker(){let t=this.busy.indexOf(!1);return t==-1?void 0:t}};function RH(){return pC('"use strict";function Xe(t){return Array.isArray(t)?t:typeof t=="string"?[t]:[]}var Je=(t,e)=>e.indexOf(t)>0?e.indexOf(t):e.length;function H(t){return H=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},H(t)}function O(t){if(t===null||t===!0||t===!1)return NaN;var e=Number(t);return isNaN(e)?e:e<0?Math.ceil(e):Math.floor(e)}function x(t,e){if(e.length1?"s":"")+" required, but only "+e.length+" present")}function y(t){x(1,arguments);var e=Object.prototype.toString.call(t);return t instanceof Date||H(t)==="object"&&e==="[object Date]"?new Date(t.getTime()):typeof t=="number"||e==="[object Number]"?new Date(t):((typeof t=="string"||e==="[object String]")&&typeof console<"u"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn\'t accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function me(t,e){x(2,arguments);var r=y(t).getTime(),n=O(e);return new Date(r+n)}var Lt={};function R(){return Lt}function pe(t){var e=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return e.setUTCFullYear(t.getFullYear()),t.getTime()-e.getTime()}function he(t){return x(1,arguments),t instanceof Date||H(t)==="object"&&Object.prototype.toString.call(t)==="[object Date]"}function ge(t){if(x(1,arguments),!he(t)&&typeof t!="number")return!1;var e=y(t);return!isNaN(Number(e))}function xe(t,e){x(2,arguments);var r=O(e);return me(t,-r)}var Ut=864e5;function ye(t){x(1,arguments);var e=y(t),r=e.getTime();e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0);var n=e.getTime(),a=r-n;return Math.floor(a/Ut)+1}function $(t){x(1,arguments);var e=1,r=y(t),n=r.getUTCDay(),a=(n=a.getTime()?r+1:e.getTime()>=i.getTime()?r:r-1}function ve(t){x(1,arguments);var e=te(t),r=new Date(0);r.setUTCFullYear(e,0,4),r.setUTCHours(0,0,0,0);var n=$(r);return n}var Rt=6048e5;function be(t){x(1,arguments);var e=y(t),r=$(e).getTime()-ve(e).getTime();return Math.round(r/Rt)+1}function j(t,e){var r,n,a,o,i,s,u,f;x(1,arguments);var l=R(),c=O((r=(n=(a=(o=e?.weekStartsOn)!==null&&o!==void 0?o:e==null||(i=e.locale)===null||i===void 0||(s=i.options)===null||s===void 0?void 0:s.weekStartsOn)!==null&&a!==void 0?a:l.weekStartsOn)!==null&&n!==void 0?n:(u=l.locale)===null||u===void 0||(f=u.options)===null||f===void 0?void 0:f.weekStartsOn)!==null&&r!==void 0?r:0);if(!(c>=0&&c<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var d=y(t),p=d.getUTCDay(),g=(p=1&&p<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var g=new Date(0);g.setUTCFullYear(c+1,0,p),g.setUTCHours(0,0,0,0);var v=j(g,e),T=new Date(0);T.setUTCFullYear(c,0,p),T.setUTCHours(0,0,0,0);var S=j(T,e);return l.getTime()>=v.getTime()?c+1:l.getTime()>=S.getTime()?c:c-1}function we(t,e){var r,n,a,o,i,s,u,f;x(1,arguments);var l=R(),c=O((r=(n=(a=(o=e?.firstWeekContainsDate)!==null&&o!==void 0?o:e==null||(i=e.locale)===null||i===void 0||(s=i.options)===null||s===void 0?void 0:s.firstWeekContainsDate)!==null&&a!==void 0?a:l.firstWeekContainsDate)!==null&&n!==void 0?n:(u=l.locale)===null||u===void 0||(f=u.options)===null||f===void 0?void 0:f.firstWeekContainsDate)!==null&&r!==void 0?r:1),d=re(t,e),p=new Date(0);p.setUTCFullYear(d,0,c),p.setUTCHours(0,0,0,0);var g=j(p,e);return g}var $t=6048e5;function Te(t,e){x(1,arguments);var r=y(t),n=j(r,e).getTime()-we(r,e).getTime();return Math.round(n/$t)+1}function h(t,e){for(var r=t<0?"-":"",n=Math.abs(t).toString();n.length0?n:1-n;return h(r==="yy"?a%100:a,r.length)},M:function(e,r){var n=e.getUTCMonth();return r==="M"?String(n+1):h(n+1,2)},d:function(e,r){return h(e.getUTCDate(),r.length)},a:function(e,r){var n=e.getUTCHours()/12>=1?"pm":"am";switch(r){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h:function(e,r){return h(e.getUTCHours()%12||12,r.length)},H:function(e,r){return h(e.getUTCHours(),r.length)},m:function(e,r){return h(e.getUTCMinutes(),r.length)},s:function(e,r){return h(e.getUTCSeconds(),r.length)},S:function(e,r){var n=r.length,a=e.getUTCMilliseconds(),o=Math.floor(a*Math.pow(10,n-3));return h(o,r.length)}},A=jt;var J={am:"am",pm:"pm",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},qt={G:function(e,r,n){var a=e.getUTCFullYear()>0?1:0;switch(r){case"G":case"GG":case"GGG":return n.era(a,{width:"abbreviated"});case"GGGGG":return n.era(a,{width:"narrow"});case"GGGG":default:return n.era(a,{width:"wide"})}},y:function(e,r,n){if(r==="yo"){var a=e.getUTCFullYear(),o=a>0?a:1-a;return n.ordinalNumber(o,{unit:"year"})}return A.y(e,r)},Y:function(e,r,n,a){var o=re(e,a),i=o>0?o:1-o;if(r==="YY"){var s=i%100;return h(s,2)}return r==="Yo"?n.ordinalNumber(i,{unit:"year"}):h(i,r.length)},R:function(e,r){var n=te(e);return h(n,r.length)},u:function(e,r){var n=e.getUTCFullYear();return h(n,r.length)},Q:function(e,r,n){var a=Math.ceil((e.getUTCMonth()+1)/3);switch(r){case"Q":return String(a);case"QQ":return h(a,2);case"Qo":return n.ordinalNumber(a,{unit:"quarter"});case"QQQ":return n.quarter(a,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(a,{width:"narrow",context:"formatting"});case"QQQQ":default:return n.quarter(a,{width:"wide",context:"formatting"})}},q:function(e,r,n){var a=Math.ceil((e.getUTCMonth()+1)/3);switch(r){case"q":return String(a);case"qq":return h(a,2);case"qo":return n.ordinalNumber(a,{unit:"quarter"});case"qqq":return n.quarter(a,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(a,{width:"narrow",context:"standalone"});case"qqqq":default:return n.quarter(a,{width:"wide",context:"standalone"})}},M:function(e,r,n){var a=e.getUTCMonth();switch(r){case"M":case"MM":return A.M(e,r);case"Mo":return n.ordinalNumber(a+1,{unit:"month"});case"MMM":return n.month(a,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(a,{width:"narrow",context:"formatting"});case"MMMM":default:return n.month(a,{width:"wide",context:"formatting"})}},L:function(e,r,n){var a=e.getUTCMonth();switch(r){case"L":return String(a+1);case"LL":return h(a+1,2);case"Lo":return n.ordinalNumber(a+1,{unit:"month"});case"LLL":return n.month(a,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(a,{width:"narrow",context:"standalone"});case"LLLL":default:return n.month(a,{width:"wide",context:"standalone"})}},w:function(e,r,n,a){var o=Te(e,a);return r==="wo"?n.ordinalNumber(o,{unit:"week"}):h(o,r.length)},I:function(e,r,n){var a=be(e);return r==="Io"?n.ordinalNumber(a,{unit:"week"}):h(a,r.length)},d:function(e,r,n){return r==="do"?n.ordinalNumber(e.getUTCDate(),{unit:"date"}):A.d(e,r)},D:function(e,r,n){var a=ye(e);return r==="Do"?n.ordinalNumber(a,{unit:"dayOfYear"}):h(a,r.length)},E:function(e,r,n){var a=e.getUTCDay();switch(r){case"E":case"EE":case"EEE":return n.day(a,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(a,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(a,{width:"short",context:"formatting"});case"EEEE":default:return n.day(a,{width:"wide",context:"formatting"})}},e:function(e,r,n,a){var o=e.getUTCDay(),i=(o-a.weekStartsOn+8)%7||7;switch(r){case"e":return String(i);case"ee":return h(i,2);case"eo":return n.ordinalNumber(i,{unit:"day"});case"eee":return n.day(o,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(o,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(o,{width:"short",context:"formatting"});case"eeee":default:return n.day(o,{width:"wide",context:"formatting"})}},c:function(e,r,n,a){var o=e.getUTCDay(),i=(o-a.weekStartsOn+8)%7||7;switch(r){case"c":return String(i);case"cc":return h(i,r.length);case"co":return n.ordinalNumber(i,{unit:"day"});case"ccc":return n.day(o,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(o,{width:"narrow",context:"standalone"});case"cccccc":return n.day(o,{width:"short",context:"standalone"});case"cccc":default:return n.day(o,{width:"wide",context:"standalone"})}},i:function(e,r,n){var a=e.getUTCDay(),o=a===0?7:a;switch(r){case"i":return String(o);case"ii":return h(o,r.length);case"io":return n.ordinalNumber(o,{unit:"day"});case"iii":return n.day(a,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(a,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(a,{width:"short",context:"formatting"});case"iiii":default:return n.day(a,{width:"wide",context:"formatting"})}},a:function(e,r,n){var a=e.getUTCHours(),o=a/12>=1?"pm":"am";switch(r){case"a":case"aa":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(o,{width:"narrow",context:"formatting"});case"aaaa":default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},b:function(e,r,n){var a=e.getUTCHours(),o;switch(a===12?o=J.noon:a===0?o=J.midnight:o=a/12>=1?"pm":"am",r){case"b":case"bb":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(o,{width:"narrow",context:"formatting"});case"bbbb":default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},B:function(e,r,n){var a=e.getUTCHours(),o;switch(a>=17?o=J.evening:a>=12?o=J.afternoon:a>=4?o=J.morning:o=J.night,r){case"B":case"BB":case"BBB":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(o,{width:"narrow",context:"formatting"});case"BBBB":default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},h:function(e,r,n){if(r==="ho"){var a=e.getUTCHours()%12;return a===0&&(a=12),n.ordinalNumber(a,{unit:"hour"})}return A.h(e,r)},H:function(e,r,n){return r==="Ho"?n.ordinalNumber(e.getUTCHours(),{unit:"hour"}):A.H(e,r)},K:function(e,r,n){var a=e.getUTCHours()%12;return r==="Ko"?n.ordinalNumber(a,{unit:"hour"}):h(a,r.length)},k:function(e,r,n){var a=e.getUTCHours();return a===0&&(a=24),r==="ko"?n.ordinalNumber(a,{unit:"hour"}):h(a,r.length)},m:function(e,r,n){return r==="mo"?n.ordinalNumber(e.getUTCMinutes(),{unit:"minute"}):A.m(e,r)},s:function(e,r,n){return r==="so"?n.ordinalNumber(e.getUTCSeconds(),{unit:"second"}):A.s(e,r)},S:function(e,r){return A.S(e,r)},X:function(e,r,n,a){var o=a._originalDate||e,i=o.getTimezoneOffset();if(i===0)return"Z";switch(r){case"X":return Ze(i);case"XXXX":case"XX":return Q(i);case"XXXXX":case"XXX":default:return Q(i,":")}},x:function(e,r,n,a){var o=a._originalDate||e,i=o.getTimezoneOffset();switch(r){case"x":return Ze(i);case"xxxx":case"xx":return Q(i);case"xxxxx":case"xxx":default:return Q(i,":")}},O:function(e,r,n,a){var o=a._originalDate||e,i=o.getTimezoneOffset();switch(r){case"O":case"OO":case"OOO":return"GMT"+Ke(i,":");case"OOOO":default:return"GMT"+Q(i,":")}},z:function(e,r,n,a){var o=a._originalDate||e,i=o.getTimezoneOffset();switch(r){case"z":case"zz":case"zzz":return"GMT"+Ke(i,":");case"zzzz":default:return"GMT"+Q(i,":")}},t:function(e,r,n,a){var o=a._originalDate||e,i=Math.floor(o.getTime()/1e3);return h(i,r.length)},T:function(e,r,n,a){var o=a._originalDate||e,i=o.getTime();return h(i,r.length)}};function Ke(t,e){var r=t>0?"-":"+",n=Math.abs(t),a=Math.floor(n/60),o=n%60;if(o===0)return r+String(a);var i=e||"";return r+String(a)+i+h(o,2)}function Ze(t,e){if(t%60===0){var r=t>0?"-":"+";return r+h(Math.abs(t)/60,2)}return Q(t,e)}function Q(t,e){var r=e||"",n=t>0?"-":"+",a=Math.abs(t),o=h(Math.floor(a/60),2),i=h(a%60,2);return n+o+r+i}var et=qt;var tt=function(e,r){switch(e){case"P":return r.date({width:"short"});case"PP":return r.date({width:"medium"});case"PPP":return r.date({width:"long"});case"PPPP":default:return r.date({width:"full"})}},rt=function(e,r){switch(e){case"p":return r.time({width:"short"});case"pp":return r.time({width:"medium"});case"ppp":return r.time({width:"long"});case"pppp":default:return r.time({width:"full"})}},Ht=function(e,r){var n=e.match(/(P+)(p+)?/)||[],a=n[1],o=n[2];if(!o)return tt(e,r);var i;switch(a){case"P":i=r.dateTime({width:"short"});break;case"PP":i=r.dateTime({width:"medium"});break;case"PPP":i=r.dateTime({width:"long"});break;case"PPPP":default:i=r.dateTime({width:"full"});break}return i.replace("{{date}}",tt(a,r)).replace("{{time}}",rt(o,r))},Qt={p:rt,P:Ht},nt=Qt;var Bt=["D","DD"],Gt=["YY","YYYY"];function at(t){return Bt.indexOf(t)!==-1}function ot(t){return Gt.indexOf(t)!==-1}function Se(t,e,r){if(t==="YYYY")throw new RangeError("Use `yyyy` instead of `YYYY` (in `".concat(e,"`) for formatting years to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(t==="YY")throw new RangeError("Use `yy` instead of `YY` (in `".concat(e,"`) for formatting years to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(t==="D")throw new RangeError("Use `d` instead of `D` (in `".concat(e,"`) for formatting days of the month to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"));if(t==="DD")throw new RangeError("Use `dd` instead of `DD` (in `".concat(e,"`) for formatting days of the month to the input `").concat(r,"`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md"))}var Vt={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},Xt=function(e,r,n){var a,o=Vt[e];return typeof o=="string"?a=o:r===1?a=o.one:a=o.other.replace("{{count}}",r.toString()),n!=null&&n.addSuffix?n.comparison&&n.comparison>0?"in "+a:a+" ago":a},it=Xt;function ne(t){return function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=e.width?String(e.width):t.defaultWidth,n=t.formats[r]||t.formats[t.defaultWidth];return n}}var Jt={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},zt={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},Kt={full:"{{date}} \'at\' {{time}}",long:"{{date}} \'at\' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},Zt={date:ne({formats:Jt,defaultWidth:"full"}),time:ne({formats:zt,defaultWidth:"full"}),dateTime:ne({formats:Kt,defaultWidth:"full"})},st=Zt;var er={lastWeek:"\'last\' eeee \'at\' p",yesterday:"\'yesterday at\' p",today:"\'today at\' p",tomorrow:"\'tomorrow at\' p",nextWeek:"eeee \'at\' p",other:"P"},tr=function(e,r,n,a){return er[e]},ut=tr;function B(t){return function(e,r){var n=r!=null&&r.context?String(r.context):"standalone",a;if(n==="formatting"&&t.formattingValues){var o=t.defaultFormattingWidth||t.defaultWidth,i=r!=null&&r.width?String(r.width):o;a=t.formattingValues[i]||t.formattingValues[o]}else{var s=t.defaultWidth,u=r!=null&&r.width?String(r.width):t.defaultWidth;a=t.values[u]||t.values[s]}var f=t.argumentCallback?t.argumentCallback(e):e;return a[f]}}var rr={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},nr={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},ar={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},or={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},ir={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},sr={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},ur=function(e,r){var n=Number(e),a=n%100;if(a>20||a<10)switch(a%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},fr={ordinalNumber:ur,era:B({values:rr,defaultWidth:"wide"}),quarter:B({values:nr,defaultWidth:"wide",argumentCallback:function(e){return e-1}}),month:B({values:ar,defaultWidth:"wide"}),day:B({values:or,defaultWidth:"wide"}),dayPeriod:B({values:ir,defaultWidth:"wide",formattingValues:sr,defaultFormattingWidth:"wide"})},ft=fr;function G(t){return function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=r.width,a=n&&t.matchPatterns[n]||t.matchPatterns[t.defaultMatchWidth],o=e.match(a);if(!o)return null;var i=o[0],s=n&&t.parsePatterns[n]||t.parsePatterns[t.defaultParseWidth],u=Array.isArray(s)?cr(s,function(c){return c.test(i)}):lr(s,function(c){return c.test(i)}),f;f=t.valueCallback?t.valueCallback(u):u,f=r.valueCallback?r.valueCallback(f):f;var l=e.slice(i.length);return{value:f,rest:l}}}function lr(t,e){for(var r in t)if(t.hasOwnProperty(r)&&e(t[r]))return r}function cr(t,e){for(var r=0;r1&&arguments[1]!==void 0?arguments[1]:{},n=e.match(t.matchPattern);if(!n)return null;var a=n[0],o=e.match(t.parsePattern);if(!o)return null;var i=t.valueCallback?t.valueCallback(o[0]):o[0];i=r.valueCallback?r.valueCallback(i):i;var s=e.slice(a.length);return{value:i,rest:s}}}var dr=/^(\\d+)(th|st|nd|rd)?/i,mr=/\\d+/i,pr={narrow:/^(b|a)/i,abbreviated:/^(b\\.?\\s?c\\.?|b\\.?\\s?c\\.?\\s?e\\.?|a\\.?\\s?d\\.?|c\\.?\\s?e\\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},hr={any:[/^b/i,/^(a|c)/i]},gr={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},xr={any:[/1/i,/2/i,/3/i,/4/i]},yr={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},vr={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},br={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},wr={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},Tr={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\\.?\\s?m\\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},Sr={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},Or={ordinalNumber:Oe({matchPattern:dr,parsePattern:mr,valueCallback:function(e){return parseInt(e,10)}}),era:G({matchPatterns:pr,defaultMatchWidth:"wide",parsePatterns:hr,defaultParseWidth:"any"}),quarter:G({matchPatterns:gr,defaultMatchWidth:"wide",parsePatterns:xr,defaultParseWidth:"any",valueCallback:function(e){return e+1}}),month:G({matchPatterns:yr,defaultMatchWidth:"wide",parsePatterns:vr,defaultParseWidth:"any"}),day:G({matchPatterns:br,defaultMatchWidth:"wide",parsePatterns:wr,defaultParseWidth:"any"}),dayPeriod:G({matchPatterns:Tr,defaultMatchWidth:"any",parsePatterns:Sr,defaultParseWidth:"any"})},lt=Or;var Mr={code:"en-US",formatDistance:it,formatLong:st,formatRelative:ut,localize:ft,match:lt,options:{weekStartsOn:0,firstWeekContainsDate:1}},ct=Mr;var dt=ct;var Dr=/[yYQqMLwIdDecihHKkms]o|(\\w)\\1*|\'\'|\'(\'\'|[^\'])+(\'|$)|./g,kr=/P+p+|P+|p+|\'\'|\'(\'\'|[^\'])+(\'|$)|./g,Cr=/^\'([^]*?)\'?$/,Wr=/\'\'/g,Ir=/[a-zA-Z]/;function ie(t,e,r){var n,a,o,i,s,u,f,l,c,d,p,g,v,T,S,P,W,L;x(2,arguments);var de=String(e),E=R(),b=(n=(a=r?.locale)!==null&&a!==void 0?a:E.locale)!==null&&n!==void 0?n:dt,k=O((o=(i=(s=(u=r?.firstWeekContainsDate)!==null&&u!==void 0?u:r==null||(f=r.locale)===null||f===void 0||(l=f.options)===null||l===void 0?void 0:l.firstWeekContainsDate)!==null&&s!==void 0?s:E.firstWeekContainsDate)!==null&&i!==void 0?i:(c=E.locale)===null||c===void 0||(d=c.options)===null||d===void 0?void 0:d.firstWeekContainsDate)!==null&&o!==void 0?o:1);if(!(k>=1&&k<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");var C=O((p=(g=(v=(T=r?.weekStartsOn)!==null&&T!==void 0?T:r==null||(S=r.locale)===null||S===void 0||(P=S.options)===null||P===void 0?void 0:P.weekStartsOn)!==null&&v!==void 0?v:E.weekStartsOn)!==null&&g!==void 0?g:(W=E.locale)===null||W===void 0||(L=W.options)===null||L===void 0?void 0:L.weekStartsOn)!==null&&p!==void 0?p:0);if(!(C>=0&&C<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");if(!b.localize)throw new RangeError("locale must contain localize property");if(!b.formatLong)throw new RangeError("locale must contain formatLong property");var q=y(t);if(!ge(q))throw new RangeError("Invalid time value");var ee=pe(q),U=xe(q,ee),Ve={firstWeekContainsDate:k,weekStartsOn:C,locale:b,_originalDate:q},M=de.match(kr).map(function(w){var I=w[0];if(I==="p"||I==="P"){var oe=nt[I];return oe(w,b.formatLong)}return w}).join("").match(Dr).map(function(w){if(w==="\'\'")return"\'";var I=w[0];if(I==="\'")return Pr(w);var oe=et[I];if(oe)return!(r!=null&&r.useAdditionalWeekYearTokens)&&ot(w)&&Se(w,e,String(t)),!(r!=null&&r.useAdditionalDayOfYearTokens)&&at(w)&&Se(w,e,String(t)),oe(U,w,b.localize,Ve);if(I.match(Ir))throw new RangeError("Format string contains an unescaped latin alphabet character `"+I+"`");return w}).join("");return M}function Pr(t){var e=t.match(Cr);return e?e[1].replace(Wr,"\'"):t}var mt=t=>[...new Set(t)];var Me=(t,e)=>{if(t instanceof Date)return"date";if(typeof t=="string"){if(/\\/\\/(\\S+?(?:jpe?g|png|gif|svg))/gi.test(t)||t.includes("unsplash"))return"image";if(/^\\d{4}-\\d{2}-\\d{2}$/.test(t))return"date";if(e=="tag"||e=="tags")return"tags-multi";if(/\\[\\[.*?\\]\\]/.test(t))return"link"}else{if(typeof t=="number")return"number";if(typeof t=="boolean")return"boolean";if(t)if(Array.isArray(t)||typeof t=="string"&&t.indexOf(",")>-1){let r=Array.isArray(t)?t:[];if(typeof t=="string"&&t.indexOf(",")>-1&&(r=V(t)),e=="tag"||e=="tags")return"tags-multi";if(r.length==1&&Array.isArray(r[0])&&r[0].length==1&&typeof r[0][0]=="string")return"link";let n=mt(r.map(a=>Me(a,e)));return n.length==1&&n[0]=="link"?"link-multi":n.some(a=>a=="object")?"object-multi":"option-multi"}else return t.isLuxonDateTime?"date":t.isLuxonDuration?"duration":t.type=="file"?"link":typeof t=="object"&&!Array.isArray(t)&&t!==null?"object":"unknown";else return"unknown"}return"text"};var pt=t=>t.map(e=>e.replace(",","\\\\,")).join(", "),z=t=>JSON.stringify(t);var V=t=>t?.startsWith("[")?Xe(ze(t)):Fr(t),Fr=t=>(t?.replace("\\\\,",",")?.match(/(\\\\.|[^,])+/g)??[]).map(e=>e.trim()),ke=(t,e,r)=>{let n=r??Me(e,t);if(!e)return"";switch(n){case"tags-multi":return e;case"object":case"object-multi":return JSON.stringify(e);case"number":return e.toString();case"boolean":return e?"true":"false";case"date":{if(e instanceof Date){let a=ie(e,"yyyy-MM-dd");return typeof a=="string"?a:""}return typeof e!="string"?"":e}break;case"duration":return pt(Object.keys(e.values).reduce((a,o)=>[...a,...e.values[o]>0?[e.values[o]+" "+o]:[]],[]));case"option-multi":case"link-multi":case"context-multi":return typeof e=="string"?De(e):z(e.map(a=>a?typeof a=="string"?De(a):a.path?a.path:Array.isArray(e)&&a.length==1&&Array.isArray(a[0])&&a[0].length==1&&typeof a[0][0]=="string"?a[0][0]:JSON.stringify(a):""));case"link":case"context":return Array.isArray(e)&&e.length==1&&Array.isArray(e[0])&&e[0].length==1&&typeof e[0][0]=="string"?e[0][0]:typeof e=="string"?De(e):e.path;case"text":case"tag":case"option":case"image":return e}return""};var ze=t=>{let e;try{e=JSON.parse(t)}catch{}return e};var De=t=>{if(!t)return"";let e=/\\[\\[(.*?)\\]\\]/g.exec(t),r=e?.length>1?e[1].substring(0,Je("|",e[1])):t;return r||t};var ht=(t,e)=>{let r=t?V(t):[],n=e?V(e):[];return n.every(a=>r.some(o=>o==a))&&r.every(a=>n.some(o=>o==a))},K=(t,e)=>t==e,Ce=(t,e)=>(t??"").length==0,We=(t,e)=>(t??"").toLowerCase().includes((e??"").toLowerCase()),Ie=(t,e)=>parseFloat(t)>parseFloat(e),Pe=(t,e)=>parseInt(t){let r=isNaN(Date.parse(t))?new Date(parseInt(t)):new Date(t),n=isNaN(Date.parse(e))?new Date(parseInt(e)):new Date(e);return r.valueOf()>=n.valueOf()},xt=(t,e)=>{let r=isNaN(Date.parse(t))?new Date(parseInt(t)):new Date(t),n=isNaN(Date.parse(e))?new Date(parseInt(e)):new Date(e);return r.valueOf(){let r=t?V(t):[],n=e?V(e):[];return r.length==0?!1:n.some(a=>r.some(o=>o==a))},yt=(t,e)=>{if(!t)return!1;let r=new Date(`${t.toString().replace(".",":")}`),n=new Date(`${e}`);return r.getMonth()===n.getMonth()&&r.getDate()===n.getDate()},vt=t=>{if(!t)return!1;let e=new Date(`${t.toString()}T00:00`),r=new Date;return e.getMonth()===r.getMonth()&&e.getDate()===r.getDate()};var Z={isNotEmpty:{type:["text","file","number","option","option-multi","link","link-multi","image"],fn:(t,e)=>!Ce(t,""),valueType:"none"},isEmpty:{type:["text","file","number","option","option-multi","link","link-multi","image"],fn:(t,e)=>Ce(t,""),valueType:"none"},include:{fn:(t,e)=>We(t,e),type:["text","file","link","image"],valueType:"text"},notInclude:{type:["text","file","link","image"],fn:(t,e)=>!We(t,e),valueType:"text"},is:{type:["text"],fn:(t,e)=>K(t,e),valueType:"text"},isNot:{type:["text"],fn:(t,e)=>!K(t,e),valueType:"text"},equal:{type:["number"],fn:(t,e)=>K(t,e),valueType:"number"},isLink:{type:["link","context"],fn:(t,e)=>K(t,e),valueType:"link"},isNotLink:{type:["link","context"],fn:(t,e)=>!K(t,e),valueType:"link"},isGreatThan:{type:["number"],fn:(t,e)=>Ie(t,e),valueType:"number"},isLessThan:{type:["number"],fn:(t,e)=>Pe(t,e),valueType:"number"},isLessThanOrEqual:{type:["number"],fn:(t,e)=>!Ie(t,e),valueType:"number"},isGreatThanOrEqual:{type:["number"],fn:(t,e)=>!Pe(t,e),valueType:"number"},dateBefore:{type:["date"],fn:(t,e)=>xt(t,e),valueType:"date"},dateAfter:{type:["date"],fn:(t,e)=>gt(t,e),valueType:"date"},isSameDate:{type:["date"],fn:(t,e)=>yt(t,e),valueType:"date"},isSameDateAsToday:{type:["date"],fn:(t,e)=>vt(t,e),valueType:"none"},isExactList:{type:["option","option-multi","link-multi","context-multi","tags-multi"],fn:(t,e)=>ht(t,e),valueType:"list"},isAnyInList:{type:["option","context","link","option-multi","link-multi","context-multi","tags-multi"],fn:(t,e)=>Fe(t,e),valueType:"list"},isNoneInList:{type:["option","context","link","option-multi","link-multi","context-multi","tags-multi"],fn:(t,e)=>!Fe(t,e),valueType:"list"},isTrue:{type:["boolean"],fn:(t,e)=>t=="true",valueType:"none"},isFalse:{type:["boolean"],fn:(t,e)=>t!="true",valueType:"none"}};var _r=(t,e,r)=>e.reduce((a,o)=>{let[i,s]=a,u=o.type=="context"?bt(s,o,r):o.type=="path"?Tt(s,o,r):o.type=="frontmatter"?wt(s,o,r):St(s,o,r),f=s.filter(l=>!u.includes(l));return[[...i,...u],f]},[[],t])[0],Er=(t,e,r)=>e.reduce((n,a)=>a.type=="context"?bt(n,a,r):a.type=="path"?Tt(n,a,r):a.type=="frontmatter"?wt(n,a,r):St(n,a,r),t),bt=(t,e,r)=>{let n=Z[e.fn];return!n||n.valueType!="none"&&e.value.length==0?[]:t.filter(a=>{let[o,i]=e.field.split("."),s=a.metadata?.property;if(!a.spaces?.includes(o)||!s||!s[i])return!1;let u=!0;if(n){let f=e.fType=="property"?r[e.value]:e.value;u=n.fn(ke(i,s[i]),f)}return u})},wt=(t,e,r)=>{let n=Z[e.fn];return!n||n.valueType!="none"&&e.value.length==0?[]:t.filter(a=>{let o=a.metadata?.property;if(!o||o[e.field]===void 0)return!1;let i=!0;if(n){let s=e.fType=="property"?r[e.value]:e.value;i=n.fn(ke(e.field,o[e.field]),s)}return i})},Tt=(t,e,r)=>{let n=Z[e.fn];return!n||n.valueType!="none"&&e.value.length==0?[]:t.filter(a=>{let o="";e.field=="outlinks"?o=z(a.outlinks??[]):e.field=="inlinks"?o=z(a.metadata?.inlinks??[]):e.field=="tags"&&(o=z(a.tags??[]));let i=!0;if(n){let s=e.fType=="property"?r[e.value]:e.value;i=n.fn(o,s)}return i})},St=(t,e,r)=>{let n=Z[e.fn];return!n||n.valueType!="none"&&e.value.length==0?[]:t.filter(a=>{let o=!0;if(n){let i=e.fType=="property"?r[e.value]:e.value;o=n.fn(a.metadata?.[e.type]?.[e.field],i)}return o})},Ot=(t,e,r)=>t.reduce((a,o)=>!a||o.filters.length==0?!1:o.type=="any"?_r([e],o.filters,r).length>0:Er([e],o.filters,r).length>0,!0);function Y(t){return Array.isArray?Array.isArray(t):Ft(t)==="[object Array]"}var Ar=1/0;function Yr(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-Ar?"-0":e}function Nr(t){return t==null?"":Yr(t)}function F(t){return typeof t=="string"}function It(t){return typeof t=="number"}function Lr(t){return t===!0||t===!1||Ur(t)&&Ft(t)=="[object Boolean]"}function Pt(t){return typeof t=="object"}function Ur(t){return Pt(t)&&t!==null}function D(t){return t!=null}function _e(t){return!t.trim().length}function Ft(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}var Rr="Incorrect \'index\' type",$r=t=>`Invalid value for key ${t}`,jr=t=>`Pattern length exceeds max of ${t}.`,qr=t=>`Missing ${t} property in key`,Hr=t=>`Property \'weight\' in key \'${t}\' must be a positive integer`,Mt=Object.prototype.hasOwnProperty,Ee=class{constructor(e){this._keys=[],this._keyMap={};let r=0;e.forEach(n=>{let a=_t(n);this._keys.push(a),this._keyMap[a.id]=a,r+=a.weight}),this._keys.forEach(n=>{n.weight/=r})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function _t(t){let e=null,r=null,n=null,a=1,o=null;if(F(t)||Y(t))n=t,e=Dt(t),r=Ae(t);else{if(!Mt.call(t,"name"))throw new Error(qr("name"));let i=t.name;if(n=i,Mt.call(t,"weight")&&(a=t.weight,a<=0))throw new Error(Hr(i));e=Dt(i),r=Ae(i),o=t.getFn}return{path:e,id:r,weight:a,src:n,getFn:o}}function Dt(t){return Y(t)?t:t.split(".")}function Ae(t){return Y(t)?t.join("."):t}function Qr(t,e){let r=[],n=!1,a=(o,i,s)=>{if(!!D(o))if(!i[s])r.push(o);else{let u=i[s],f=o[u];if(!D(f))return;if(s===i.length-1&&(F(f)||It(f)||Lr(f)))r.push(Nr(f));else if(Y(f)){n=!0;for(let l=0,c=f.length;lt.score===e.score?t.idx{this._keysMap[r.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,F(this.docs[0])?this.docs.forEach((e,r)=>{this._addString(e,r)}):this.docs.forEach((e,r)=>{this._addObject(e,r)}),this.norm.clear())}add(e){let r=this.size();F(e)?this._addString(e,r):this._addObject(e,r)}removeAt(e){this.records.splice(e,1);for(let r=e,n=this.size();r{let i=a.getFn?a.getFn(e):this.getFn(e,a.path);if(!!D(i)){if(Y(i)){let s=[],u=[{nestedArrIndex:-1,value:i}];for(;u.length;){let{nestedArrIndex:f,value:l}=u.pop();if(!!D(l))if(F(l)&&!_e(l)){let c={v:l,i:f,n:this.norm.get(l)};s.push(c)}else Y(l)&&l.forEach((c,d)=>{u.push({nestedArrIndex:d,value:c})})}n.$[o]=s}else if(F(i)&&!_e(i)){let s={v:i,n:this.norm.get(i)};n.$[o]=s}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}};function Et(t,e,{getFn:r=m.getFn,fieldNormWeight:n=m.fieldNormWeight}={}){let a=new ae({getFn:r,fieldNormWeight:n});return a.setKeys(t.map(_t)),a.setSources(e),a.create(),a}function Kr(t,{getFn:e=m.getFn,fieldNormWeight:r=m.fieldNormWeight}={}){let{keys:n,records:a}=t,o=new ae({getFn:e,fieldNormWeight:r});return o.setKeys(n),o.setIndexRecords(a),o}function se(t,{errors:e=0,currentLocation:r=0,expectedLocation:n=0,distance:a=m.distance,ignoreLocation:o=m.ignoreLocation}={}){let i=e/t.length;if(o)return i;let s=Math.abs(n-r);return a?i+s/a:s?1:i}function Zr(t=[],e=m.minMatchCharLength){let r=[],n=-1,a=-1,o=0;for(let i=t.length;o=e&&r.push([n,a]),n=-1)}return t[o-1]&&o-n>=e&&r.push([n,o-1]),r}var X=32;function en(t,e,r,{location:n=m.location,distance:a=m.distance,threshold:o=m.threshold,findAllMatches:i=m.findAllMatches,minMatchCharLength:s=m.minMatchCharLength,includeMatches:u=m.includeMatches,ignoreLocation:f=m.ignoreLocation}={}){if(e.length>X)throw new Error(jr(X));let l=e.length,c=t.length,d=Math.max(0,Math.min(n,c)),p=o,g=d,v=s>1||u,T=v?Array(c):[],S;for(;(S=t.indexOf(e,g))>-1;){let b=se(e,{currentLocation:S,expectedLocation:d,distance:a,ignoreLocation:f});if(p=Math.min(b,p),g=S+l,v){let k=0;for(;k=q;M-=1){let w=M-1,I=r[t.charAt(w)];if(v&&(T[w]=+!!I),U[M]=(U[M+1]<<1|1)&I,b&&(U[M]|=(P[M+1]|P[M])<<1|1|P[M+1]),U[M]&de&&(W=se(e,{errors:b,currentLocation:w,expectedLocation:d,distance:a,ignoreLocation:f}),W<=p)){if(p=W,g=w,g<=d)break;q=Math.max(1,2*d-g)}}if(se(e,{errors:b+1,currentLocation:d,expectedLocation:d,distance:a,ignoreLocation:f})>p)break;P=U}let E={isMatch:g>=0,score:Math.max(.001,W)};if(v){let b=Zr(T,s);b.length?u&&(E.indices=b):E.isMatch=!1}return E}function tn(t){let e={};for(let r=0,n=t.length;r{this.chunks.push({pattern:d,alphabet:tn(d),startIndex:p})},c=this.pattern.length;if(c>X){let d=0,p=c%X,g=c-p;for(;d{let{isMatch:S,score:P,indices:W}=en(e,g,v,{location:a+T,distance:o,threshold:i,findAllMatches:s,minMatchCharLength:u,includeMatches:n,ignoreLocation:f});S&&(d=!0),c+=P,S&&W&&(l=[...l,...W])});let p={isMatch:d,score:d?c/this.chunks.length:1};return d&&n&&(p.indices=l),p}},_=class{constructor(e){this.pattern=e}static isMultiMatch(e){return kt(e,this.multiRegex)}static isSingleMatch(e){return kt(e,this.singleRegex)}search(){}};function kt(t,e){let r=t.match(e);return r?r[1]:null}var Ye=class extends _{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){let r=e===this.pattern;return{isMatch:r,score:r?0:1,indices:[0,this.pattern.length-1]}}},Ne=class extends _{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){let n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}},Le=class extends _{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\\^"(.*)"$/}static get singleRegex(){return/^\\^(.*)$/}search(e){let r=e.startsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,this.pattern.length-1]}}},Ue=class extends _{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\\^"(.*)"$/}static get singleRegex(){return/^!\\^(.*)$/}search(e){let r=!e.startsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}},Re=class extends _{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\\$$/}static get singleRegex(){return/^(.*)\\$$/}search(e){let r=e.endsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[e.length-this.pattern.length,e.length-1]}}},$e=class extends _{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\\$$/}static get singleRegex(){return/^!(.*)\\$$/}search(e){let r=!e.endsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}},fe=class extends _{constructor(e,{location:r=m.location,threshold:n=m.threshold,distance:a=m.distance,includeMatches:o=m.includeMatches,findAllMatches:i=m.findAllMatches,minMatchCharLength:s=m.minMatchCharLength,isCaseSensitive:u=m.isCaseSensitive,ignoreLocation:f=m.ignoreLocation}={}){super(e),this._bitapSearch=new ue(e,{location:r,threshold:n,distance:a,includeMatches:o,findAllMatches:i,minMatchCharLength:s,isCaseSensitive:u,ignoreLocation:f})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}},le=class extends _{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^\'"(.*)"$/}static get singleRegex(){return/^\'(.*)$/}search(e){let r=0,n,a=[],o=this.pattern.length;for(;(n=e.indexOf(this.pattern,r))>-1;)r=n+o,a.push([n,r-1]);let i=!!a.length;return{isMatch:i,score:i?0:1,indices:a}}},je=[Ye,le,Le,Ue,$e,Re,Ne,fe],Ct=je.length,rn=/ +(?=(?:[^\\"]*\\"[^\\"]*\\")*[^\\"]*$)/,nn="|";function an(t,e={}){return t.split(nn).map(r=>{let n=r.trim().split(rn).filter(o=>o&&!!o.trim()),a=[];for(let o=0,i=n.length;o!!(t[ce.AND]||t[ce.OR]),un=t=>!!t[Be.PATH],fn=t=>!Y(t)&&Pt(t)&&!Ge(t),Wt=t=>({[ce.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function At(t,e,{auto:r=!0}={}){let n=a=>{let o=Object.keys(a),i=un(a);if(!i&&o.length>1&&!Ge(a))return n(Wt(a));if(fn(a)){let u=i?a[Be.PATH]:o[0],f=i?a[Be.PATTERN]:a[u];if(!F(f))throw new Error($r(u));let l={keyId:Ae(u),pattern:f};return r&&(l.searcher=Qe(f,e)),l}let s={children:[],operator:o[0]};return o.forEach(u=>{let f=a[u];Y(f)&&f.forEach(l=>{s.children.push(n(l))})}),s};return Ge(t)||(t=Wt(t)),n(t)}function ln(t,{ignoreFieldNorm:e=m.ignoreFieldNorm}){t.forEach(r=>{let n=1;r.matches.forEach(({key:a,norm:o,score:i})=>{let s=a?a.weight:null;n*=Math.pow(i===0&&s?Number.EPSILON:i,(s||1)*(e?1:o))}),r.score=n})}function cn(t,e){let r=t.matches;e.matches=[],D(r)&&r.forEach(n=>{if(!D(n.indices)||!n.indices.length)return;let{indices:a,value:o}=n,i={indices:a,value:o};n.key&&(i.key=n.key.src),n.idx>-1&&(i.refIndex=n.idx),e.matches.push(i)})}function dn(t,e){e.score=t.score}function mn(t,e,{includeMatches:r=m.includeMatches,includeScore:n=m.includeScore}={}){let a=[];return r&&a.push(cn),n&&a.push(dn),t.map(o=>{let{idx:i}=o,s={item:e[i],refIndex:i};return a.length&&a.forEach(u=>{u(o,s)}),s})}var N=class{constructor(e,r={},n){this.options={...m,...r},this.options.useExtendedSearch,this._keyStore=new Ee(this.options.keys),this.setCollection(e,n)}setCollection(e,r){if(this._docs=e,r&&!(r instanceof ae))throw new Error(Rr);this._myIndex=r||Et(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){!D(e)||(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){let r=[];for(let n=0,a=this._docs.length;n-1&&(u=u.slice(0,r)),mn(u,this._docs,{includeMatches:n,includeScore:a})}_searchStringList(e){let r=Qe(e,this.options),{records:n}=this._myIndex,a=[];return n.forEach(({v:o,i,n:s})=>{if(!D(o))return;let{isMatch:u,score:f,indices:l}=r.searchIn(o);u&&a.push({item:o,idx:i,matches:[{score:f,value:o,norm:s,indices:l}]})}),a}_searchLogical(e){let r=At(e,this.options),n=(s,u,f)=>{if(!s.children){let{keyId:c,searcher:d}=s,p=this._findMatches({key:this._keyStore.get(c),value:this._myIndex.getValueForItemAtKeyId(u,c),searcher:d});return p&&p.length?[{idx:f,item:u,matches:p}]:[]}let l=[];for(let c=0,d=s.children.length;c{if(D(s)){let f=n(r,s,u);f.length&&(o[u]||(o[u]={idx:u,item:s,matches:[]},i.push(o[u])),f.forEach(({matches:l})=>{o[u].matches.push(...l)}))}}),i}_searchObjectList(e){let r=Qe(e,this.options),{keys:n,records:a}=this._myIndex,o=[];return a.forEach(({$:i,i:s})=>{if(!D(i))return;let u=[];n.forEach((f,l)=>{u.push(...this._findMatches({key:f,value:i[l],searcher:r}))}),u.length&&o.push({idx:s,item:i,matches:u})}),o}_findMatches({key:e,value:r,searcher:n}){if(!D(r))return[];let a=[];if(Y(r))r.forEach(({v:o,i,n:s})=>{if(!D(o))return;let{isMatch:u,score:f,indices:l}=n.searchIn(o);u&&a.push({score:f,key:e,value:o,idx:i,norm:s,indices:l})});else{let{v:o,n:i}=r,{isMatch:s,score:u,indices:f}=n.searchIn(o);s&&a.push({score:u,key:e,value:o,norm:i,indices:f})}return a}};N.version="7.0.0";N.createIndex=Et;N.parseIndex=Kr;N.config=m;N.parseQuery=At;sn(qe);function Yt(t){let{query:e,pathsIndex:r,count:n}=t,a=[],o={shouldSort:!0,threshold:0,ignoreLocation:!0,keys:["name","path","label.preview"]};return new N([...r.values()].filter(s=>s.hidden==!1),o).search(e).map(s=>s.item).slice(0,n)}function Nt(t){let{queries:e,pathsIndex:r,count:n}=t,a=[];for(let[o,i]of r)!i.hidden&&Ot(e,i,{})&&a.push(i);return a.slice(0,n)}var pn=self;pn.onmessage=async t=>{let{payload:e,job:r}=t.data,n;r.type=="search"&&(n=Nt(e)),r.type=="fastSearch"&&(n=Yt(e));try{postMessage({job:r,result:n})}catch(a){console.log(a),postMessage({job:r,result:{$error:`Failed to run ${r.type} ${r.path}: ${a}`}})}};\n',{name:"Superstate Search"})}var g5=class{constructor(t,r){this.numWorkers=t;this.cache=r;this.workers=[],this.busy=[],this.reloadQueue=[],this.reloadSet=new Set,this.callbacks=new Map;for(let n=0;nthis.finish(a.data.job,a.data.result,n),this.workers.push(i),this.busy.push(!1)}}run(t){let r=F2(t),n=new Promise((a,o)=>{this.callbacks.has(r)?this.callbacks.get(r)?.push([a,o]):this.callbacks.set(r,[[a,o]])});if(this.reloadSet.has(r))return n;this.reloadSet.add(r);let i=this.nextAvailableWorker();return i!==void 0?this.send(t,i):this.reloadQueue.push(t),n}finish(t,r,n){let i=F2(t),a=[].concat(this.callbacks.get(i)??[]);this.reloadSet.delete(i),this.callbacks.delete(i),this.busy[n]=!1;let o=this.reloadQueue.shift();if(o!==void 0&&this.send(o,n),"$error"in r)for(let[s,l]of a)l(r.$error);else for(let[s,l]of a)s(r)}async send(t,r){t.type=="search"&&(this.message(r,{job:t,payload:{queries:t.payload.queries,pathsIndex:this.cache.pathsIndex,count:t.payload.count}}),this.busy[r]=!0),t.type=="fastSearch"&&(this.message(r,{job:t,payload:{query:t.payload.query,pathsIndex:this.cache.pathsIndex,count:t.payload.count}}),this.busy[r]=!0)}message(t,r){this.workers[t].postMessage(r)}nextAvailableWorker(){let t=this.busy.indexOf(!1);return t==-1?void 0:t}};var Ay=class{constructor(t,r,n,i,a){this.indexVersion=t;this.onChange=r;this.loadouts=[];this.kit=[Um,_2,$2,B2,R2,jwe,q2,cC,Dwe,Twe,Rwe,Bwe,Fwe,Pwe,_we,Iwe,$we,qwe,Uwe,Wwe,Mwe,Owe,P2,Wm,zwe,p5,I2,fC,Lwe,Nwe,Vwe];this.eventsDispatcher=new u0;let o={...uG,createAdd:G("add",[],()=>function(f,d){return f+d}),createEqual:G("equal",[],()=>function(f,d){return f==d}),createUnequal:G("unequal",[],()=>function(f,d){return f!=d})},l=yB(o,{matrix:"Array"});l.import(P6,{override:!0}),this.formulaContext=l,this.initialized=!1,this.spaceManager=n,this.spaceManager.superstate=this,this.ui=i,this.ui.superstate=this,this.cli=a;let u=new m5(this.cli,this);this.cli.superstate=this,this.cli.terminals.splice(0,0,u),this.cli.mainTerminal=u,this.allMetadata={},this.api=new uC(this),this.pathsIndex=new Map,this.spacesIndex=new Map,this.contextsIndex=new Map,this.actionsIndex=new Map,this.kitFrames=new Map,this.kits=new Map,this.actions=new Map,this.templateCache=new Map,this.focuses=[],this.spacesMap=new vd,this.linksMap=new vd,this.tagsMap=new vd,this.liveSpaceLinkMap=new vd,this.iconsCache=new Map,this.imagesCache=new Map,this.contextStateQueue=Promise.resolve(),this.vaultDBCache=[],this.indexer=new A5(2,this),this.searcher=new g5(1,this)}static create(t,r,n,i,a){return new Ay(t,r,n,i,a)}refreshMetadata(){this.allMetadata=h5(this)}async initializeIndex(){await this.loadFromCache()}addToContextStateQueue(t){this.contextStateQueue=this.contextStateQueue.then(t).catch(()=>{})}async initialize(){if(!this.persister){console.log("Cache Persister Not Found");return}let t=Date.now();this.initializeActions(),this.initializeFocuses(),this.initializeKits(),this.initializeTemplates(),this.settings.spacesEnabled&&await this.initializeSpaces(),await this.initializeBuiltins(),await this.initializeTags(),await this.initializePaths(),await this.initializeContexts(),await this.initializeFrames(),this.refreshMetadata(),this.dispatchEvent("superstateUpdated",null),this.ui.notify(`Make.md - Superstate Loaded in ${(Date.now()-t)/1e3} seconds`,"console"),this.persister.cleanType("space"),this.persister.cleanType("path"),this.persister.cleanType("context"),this.persister.cleanType("frame")}async reloadSystemActions(){(await this.spaceManager.readSystemCommands()).forEach(r=>this.actions.set(r.name,r.commands)),this.dispatchEvent("actionStateUpdated",{path:"spaces://$actions"})}async initializeActions(){await this.reloadSystemActions();let t=this.allSpaces().filter(r=>r.type!="default").map(r=>r.space).map(r=>this.reloadActions(r));await Promise.all(t)}async initializeKits(){let t=await this.spaceManager.readAllKits();t.forEach(r=>this.kits.set(r.id,r)),t.length==0&&this.kits.set("default",{id:"default",name:"Default",colors:{},frames:[]}),this.selectedKit=this.kits.get(this.settings.selectedKit)??this.kits.get("default"),this.selectedKit.frames=[...this.selectedKit.frames,...this.kit.map(r=>AN(r)).filter(r=>!this.selectedKit.frames.some(n=>n.schema.id==r.schema.id))];for(let r of this.selectedKit.frames){let n=to(r.schema).def.id,i=await hN(this,r,{...c0,screenType:this.ui.getScreenType()});this.kitFrames.set(n,i)}this.dispatchEvent("frameStateUpdated",{path:"spaces://$kit"})}async initializeTemplates(){let t=await this.spaceManager.readAllTemplates();Object.keys(t).forEach(r=>{this.templateCache.set(r,t[r])})}async initializeSpaces(){let t=[...this.spaceManager.allSpaces().values()],r=t.map(n=>this.reloadSpace(n,null,!0));[...this.spacesIndex.keys()].filter(n=>!t.some(i=>i.path==n)).forEach(n=>this.onSpaceDeleted(n)),await Promise.all(r)}getSpaceItems(t,r){let n=[...this.spacesMap.getInverse(t)],i=this.contextsIndex.get(t)?.paths??[];return n.map((a,o)=>({...this.pathsIndex.get(a),rank:i.indexOf(a)})).filter(a=>a?.hidden!=!0&&a.path!=t)}async initializeFrames(){await this.initializeTemplates()}async initializeContexts(){await this.indexer.reload({type:"contexts",path:""}).then(async t=>{let r=[...t.entries()].map(([n,{cache:i,changed:a}])=>this.contextReloaded(n,i,a,!0));await Promise.all(r)})}async loadFromCache(){if(this.dispatchEvent("superstateReindex",null),this.settings.indexSVG){let i=await this.persister.loadAll("icon");this.spaceManager.allPaths(["svg"]).forEach(a=>{let o=i.find(s=>s.path==a);o?.cache.length>0&&this.iconsCache.set(a,o.cache)})}let t=await this.persister.loadAll("path"),r=await this.persister.loadAll("space"),n=await this.persister.loadAll("context");r.forEach(i=>{let a=dr(i.cache);a&&a.type&&this.spacesIndex.set(i.path,a)}),n.forEach(i=>{let a=dr(i.cache);a&&this.contextsIndex.set(i.path,a)}),t.forEach(i=>{let a=c5(i.cache);this.pathsIndex.set(i.path,a),this.tagsMap.set(i.path,new Set(a.tags)),this.spacesMap.set(i.path,new Set(a.spaces)),this.linksMap.set(i.path,new Set(a.outlinks))}),this.settings.enhancedLogs&&console.log("Initial Cache Loaded"),this.dispatchEvent("superstateUpdated",null)}dispatchEvent(t,r){this.eventsDispatcher.dispatchEvent(t,r)}async initializeBuiltins(){let r=Object.keys(cm).map(n=>this.reloadPath("spaces://$"+n,!0));await Promise.all(r)}async initializeTags(){let r=[...this.spaceManager.readTags().map(n=>If(n))].map(n=>this.reloadPath(n,!0));await Promise.all(r)}async onSpaceDefinitionChanged(t,r){if(t.space.readOnly)return;let n=this.spacesMap.getInverse(t.path),i=[];if(t.metadata?.links&&!K0.default.isEqual(t.metadata.links,r?.links)&&i.push(...t.metadata.links),t.metadata?.filters?.length>0){let s=t.metadata.filters.some(l=>l.filters.some(u=>u.fType=="property"));if(!K0.default.isEqual(t.metadata?.filters,r?.filters)||s)for(let[l,u]of this.pathsIndex)!u.hidden&&u5(t.metadata?.filters,u,t.properties)&&i.push(l)}let o=[...K0.default.difference(i,[...n]),...K0.default.difference([...n],i)].map(s=>this.reloadPath(s,!0).then(l=>this.dispatchEvent("pathStateUpdated",{path:s})));await Promise.all(o)}async initializeFocuses(){let t=await this.spaceManager.readFocuses();if(t.length==0){this.spaceManager.saveFocuses([{name:"Home",sticker:"ui//home",paths:["/"]}]);return}this.focuses=t,this.dispatchEvent("focusesChanged",null)}async initializePaths(){this.dispatchEvent("superstateReindex",null);let t=this.spaceManager.allPaths(),r=Date.now();await this.indexer.reload({type:"paths",path:""}).then(async i=>{for await(let[a,{cache:o,changed:s}]of Object.entries(i))await this.pathReloaded(a,o,s,!1)}),this.ui.notify(`Make.md - ${t.length} Paths Cached in ${(Date.now()-r)/1e3} seconds`,"console");let n=Mr([...this.spacesIndex.keys(),...t]);[...this.pathsIndex.keys()].filter(i=>!n.some(a=>a==i)).forEach(i=>this.onPathDeleted(i)),this.dispatchEvent("superstateUpdated",null)}async onTagRenamed(t,r){let n=aJ(t),i=Fg(this.spaceManager,r);await this.onSpaceRenamed(n,i),await this.onPathRename(n,i.path),this.dispatchEvent("spaceChanged",{path:n,newPath:i.path});let a=[];for(let[o,s]of this.spacesIndex)this.contextsIndex.get(o)?.contexts.includes(t)&&this.addToContextStateQueue(()=>Lye(this.spaceManager,t,r,a)),s.metadata?.contexts.includes(t)&&of(this,s.space,{...s.metadata,contexts:s.metadata.contexts.map(u=>u==t?r:u)});this.dispatchEvent("spaceStateUpdated",{path:mx})}async onTagDeleted(t){this.tagsMap.getInverse(t).forEach(i=>{this.deleteTagInPath(t,i)});let r=_j(t,this.settings);await this.spaceManager.deletePath(r),this.onSpaceDeleted(If(t));for(let[i,a]of this.spacesIndex)a.metadata?.contexts.includes(t)&&of(this,a.space,{...a.metadata,contexts:a.metadata.contexts.filter(o=>o!=t)});let n=[];for(let[i,a]of this.contextsIndex)a.contexts.includes(t)&&n.push(this.spaceManager.spaceInfoForPath(a.path));this.addToContextStateQueue(()=>zye(this.spaceManager,t,n)),this.dispatchEvent("spaceStateUpdated",{path:mx})}async deleteTagInPath(t,r){let n;if(this.pathsIndex.has(r)&&(n=this.pathsIndex.get(r)),n){let i={...n,tags:n.tags.filter(a=>a!=t),spaces:n.spaces.filter(a=>a!=If(t))};this.pathsIndex.set(r,i),this.tagsMap.set(r,new Set(i.tags)),this.spacesMap.set(r,new Set(i.spaces))}else await this.reloadPath(r);this.onPathReloaded(r),this.dispatchEvent("pathStateUpdated",{path:r})}onMetadataChange(t){this.settings.enhancedLogs&&console.log("Metadata Changed",t),this.pathsIndex.has(t)&&this.reloadPath(t).then(r=>{let n=this.pathsIndex.get(t),i=this.spacesIndex.get(t);i&&this.reloadSpace(i.space).then(o=>this.onSpaceDefinitionChanged(o,i.metadata));let a=n.spaces.map(o=>this.spacesIndex.get(o)?.space).filter(o=>o);this.addToContextStateQueue(()=>vG(this,t,a)),this.dispatchEvent("pathStateUpdated",{path:t})})}reloadSpaceByPath(t,r){return this.reloadSpace(this.spaceManager.spaceInfoForPath(t),r)}async onPathRename(t,r){let n=r,i=this.pathsIndex.get(t),a=i?.spaces??[];if(i){this.spacesMap.delete(t),this.spacesMap.deleteInverse(t),this.linksMap.delete(t),this.linksMap.deleteInverse(t),this.pathsIndex.delete(t);let u=a.map(f=>this.spacesIndex.get(f)).filter(f=>f);await Hye(this.spaceManager,t,n,u.map(f=>f.space));for(let f of u)f.metadata?.links?.includes(t)&&this.addToContextStateQueue(()=>oy(this,f.path,"links",f.metadata.links.map(d=>d==t?r:d))),await this.reloadContext(f.space,!0);let c=[];for(let[f,d]of this.contextsIndex)d.outlinks.includes(t)&&c.push(this.spacesIndex.get(d.path).space);this.addToContextStateQueue(()=>Vye(this.spaceManager,t,n,c).then(f=>Promise.all(c.map(d=>this.reloadContext(d,!0)))))}let o=!1;this.focuses.forEach(u=>{u.paths.includes(t)&&(u.paths=u.paths.map(c=>c==t?r:c),o=!0)}),o&&(await this.spaceManager.saveFocuses(this.focuses),this.dispatchEvent("focusesChanged",null)),await this.reloadPath(r,!0);let s=Mr([...this.spacesMap.get(r)??[],...a]),l=s.map(u=>this.reloadContext(this.spacesIndex.get(u)?.space));await Promise.all(l),s.forEach(u=>this.dispatchEvent("spaceStateUpdated",{path:u})),this.dispatchEvent("pathChanged",{path:t,newPath:r}),this.ui.viewsByPath(t).forEach(u=>{u.openPath(r)})}async onPathCreated(t){await this.reloadPath(t,!0);let r=cu(t);this.spacesIndex.has(r)&&this.spacesIndex.get(r).space.notePath==t&&await this.reloadSpace(this.spacesIndex.get(r).space),this.dispatchEvent("pathCreated",{path:t})}onPathDeleted(t){this.spacesMap.delete(t),this.linksMap.delete(t),this.linksMap.deleteInverse(t),this.persister.remove(t,"path");let r=this.pathsIndex.get(t);if(!r)return;let n=(r.spaces??[]).map(a=>this.spacesIndex.get(a)?.space).filter(a=>a);this.addToContextStateQueue(()=>Qye(this.spaceManager,t,n).then(a=>n.forEach(o=>this.reloadContext(o))));let i=[];for(let[a,o]of this.contextsIndex)o.outlinks.includes(t)&&this.spacesIndex.has(o.path)&&i.push(this.spacesIndex.get(o.path).space);this.addToContextStateQueue(()=>Gye(this.spaceManager,t,i).then(a=>n.forEach(o=>this.reloadContext(o)))),(r.spaces??[]).forEach(a=>{this.dispatchEvent("spaceStateUpdated",{path:a})}),this.pathsIndex.delete(t),this.dispatchEvent("pathDeleted",{path:t})}async onSpaceRenamed(t,r){if(this.spacesIndex.has(t)){let n=this.spacesIndex.get(t).metadata;this.spacesIndex.set(r.path,{...this.spacesIndex.get(t),path:r.path,name:r.name,space:r}),this.spacesMap.rename(t,r.path),this.spacesMap.renameInverse(t,r.path),this.spacesIndex.delete(t),this.contextsIndex.delete(t),this.actionsIndex.delete(t),await this.reloadSpace(r,n).then(i=>this.onSpaceDefinitionChanged(i,n)),await this.reloadContext(r,!0),await this.reloadActions(r)}}onSpaceDeleted(t){this.spacesIndex.has(t)&&(this.spacesIndex.delete(t),this.contextsIndex.delete(t)),this.spacesMap.delete(t),this.spacesMap.deleteInverse(t),this.persister.remove(t,"space"),this.dispatchEvent("spaceDeleted",{path:t})}async reloadActions(t){if(!t)return!1;this.spaceManager.commandsForSpace(t.path).then(r=>{this.actionsIndex.set(t.path,r),this.dispatchEvent("actionStateUpdated",{path:t.path})})}async reloadContextByPath(t,r){return this.reloadContext(this.spaceManager.spaceInfoForPath(t),r)}async reloadContext(t,r){return t?this.indexer.reload({type:"context",path:t.path}).then(n=>this.contextReloaded(t.path,n.cache,n.changed,r)):!1}async contextReloaded(t,r,n,i){if(!r||(this.settings.enhancedLogs&&console.log("Context Reloaded"),!n&&!i))return!1;this.contextsIndex.set(t,r);let a=this.pathsIndex.get(t);if(a&&r.dbExists&&!a.readOnly&&this.settings.syncFormulaToFrontmatter){let o=r.contextTable?.rows??[],s=r.contextTable?.cols??[],l=o.filter(u=>{let c=u[Ft],f=this.pathsIndex.get(c);return!f||f.type=="file"&&f.subtype!="md"?!1:s.reduce((d,p,h)=>d||p.type!="fileprop"||p.primary=="true"?d:u[p.name]?.length>0&&f.metadata?.property?.[p.name]!=u[p.name]?!0:d,!1)});l.length>0&&l.forEach(u=>Di(this,u[Ft],s.reduce((c,f,d)=>f.type=="fileprop"&&f.primary!="true"?{...c,[f.name]:u[f.name]}:c,{})))}return r.dbExists&&n&&await this.spaceManager.saveTable(t,r.contextTable),this.persister.store(t,JSON.stringify(r),"context"),this.dispatchEvent("contextStateUpdated",{path:t}),!0}allSpaces(t){return t?JK([...this.spacesIndex.values()],this.spaceOrder(),"path"):[...this.spacesIndex.values()]}spaceOrder(){return[...this.focuses.flatMap(t=>t.paths)]}async updateSpaceMetadata(t,r){let n=this.spacesIndex.get(t),i=n?.metadata;if(!n)return this.reloadSpaceByPath(t);let a=!1,s=(r?.sort??{field:"rank",asc:!0,group:!0}).field=="rank";(!K0.default.isEqual(n.metadata.links,r.links)||!K0.default.isEqual(n.metadata.filters,r.filters))&&(a=!0);let l={...n,metadata:r,contexts:r?.contexts??[],sortable:s};return this.spacesIndex.set(t,l),a&&await this.onSpaceDefinitionChanged(l,i),this.dispatchEvent("spaceStateUpdated",{path:n.path}),l}async reloadSpace(t,r,n=!0){if(!t)return;this.settings.enhancedLogs&&console.log("Reloading Space");let i=r??await this.spaceManager.spaceDefForSpace(t.path),a=this.pathsIndex.get(t.path),o=this.spaceManager.uriByString(t.path);if(!o)return null;let s=this.spaceManager.spaceTypeByString(o);(s=="default"||s=="tag")&&(i.filters=[],i.links=[]);let l=[],u={},c=await this.spaceManager.readFrame(t.path,r1).then(b=>b?.cols??[]);if(l.push(...c),l.length>0){if(!a)if(this.settings.enableFolderNote){let b=await this.spaceManager.readPathCache(t.notePath);a={path:t.path,name:t.name,tags:[],spaces:[],outlinks:[],readOnly:t.readOnly,hidden:!1,metadata:b?.metadata,type:"space",subtype:s,label:b?.label}}else{let b=await this.spaceManager.readPathCache(t.path);a={path:t.path,name:t.name,tags:[],spaces:[],outlinks:[],readOnly:t.readOnly,hidden:!1,metadata:b?.metadata,type:"space",subtype:s,label:b?.label}}u=await this.spaceManager.readProperties(t.notePath).then(b=>Vm(this.formulaContext,this.pathsIndex,b,l,a))}[...this.spacesMap.get(t.path)].map(b=>this.contextsIndex.get(b)).forEach(b=>{if(b){let v=b.contextTable?.cols??[];l.push(...v),u={...u,...b.contextTable?.rows.find(x=>x[Ft]==t.path)??{}}}});let f=i?.sort??{field:"rank",asc:!0,group:!0},d=f.field=="rank"||!f,p=i?.contexts??[],h=Mr((i.filters??[]).flatMap(b=>b.filters).flatMap(b=>b.type=="context"?[b.field.split(".")[0]]:b.type=="path"&&b.field=="space"?mr(b.value):[])),m=Mr((i.filters??[]).flatMap(b=>b.filters).flatMap(b=>b.type.startsWith("link")?mr(b.value):[]));if(s=="tag"&&this.settings.autoAddContextsToSubtags){let b=EJ(t.name);p.push(...b)}let g=await this.spaceManager.readTemplates(t.path),A={name:t.name,space:t,path:t.path,type:s,templates:g,contexts:p.map(b=>b.toLowerCase()),metadata:i,dependencies:h,sortable:d,properties:u,propertyTypes:l};if(this.spacesIndex.set(t.path,A),this.persister.store(t.path,JSON.stringify(A),"space"),A.metadata?.links?.forEach(b=>{PK(this,b)&&this.spacesMap.set(b,new Set([...this.spacesMap.get(b),t.path]))}),n)return this.dispatchEvent("spaceStateUpdated",{path:t.path}),A}async pathReloaded(t,r,n,i){if(this.settings.enhancedLogs&&console.log("Path Reloaded"),this.pathsIndex.set(t,r),await this.onPathReloaded(t),(r.subtype=="image"||r.metadata?.file?.extension=="svg")&&this.imagesCache.set(r.metadata.file.filename,t),!n&&!i)return!1;if(this.tagsMap.set(t,new Set(r.tags)),this.linksMap.set(t,new Set(r.outlinks)),!K0.default.isEqual(r.spaces,Array.from(this.spacesMap.get(t)))){this.spacesMap.set(t,new Set(r.spaces));let a=r.tags.map(s=>Fg(this.spaceManager,s)).filter(s=>!this.spacesIndex.has(s.path)).map(async s=>{await this.reloadSpace(s),this.reloadContext(s),await this.reloadPath(s.path)});await Promise.all(a).then(s=>{this.dispatchEvent("spaceStateUpdated",{path:mx})})}if(i){let a=r.spaces.map(o=>this.spacesIndex.get(o)?.space).filter(o=>o);this.addToContextStateQueue(()=>vG(this,t,a).then(o=>{a.forEach(s=>{this.dispatchEvent("spaceStateUpdated",{path:s.path})})}))}r.metadata?.file?.extension=="svg"&&this.settings.indexSVG&&this.spaceManager.readPath(t).then(a=>{this.iconsCache.set(t,a),this.persister.store(t,a,"icon")})}async reloadPath(t,r){return t?this.indexer.reload({type:"path",path:t}).then(async n=>(await this.pathReloaded(t,n.cache,n.changed,r),!0)):!1}async onPathReloaded(t){let r;if(this.pathsIndex.has(t)&&(r=this.pathsIndex.get(t)),!r)return!1;await this.persister.store(t,kwe(r),"path")}};var gy=class{constructor(){this.filesystems=[];this.filetypes=[];this.eventDispatch=new u0}static create(){return new gy}resolvePath(t,r){return this.primary.resolvePath(t,r)}keysForCacheType(t){return this.primary.keysForCacheType(t)}allTags(){return this.primary.readAllTags()}fileFragmentChanged(t){this.eventDispatch.dispatchEvent("onFileFragmentChanged",{file:t})}initiateFileSystemAdapter(t,r){t.initiate(this),r&&(this.primary=t),this.filesystems.push(t)}initiateFiletypeAdapter(t){t.initiate(this),this.filetypes.push(t)}filetypeAdaptersForFile(t){return t?this.filetypes.filter(r=>r.supportedFileTypes.includes(t.extension)):[]}filetypeAdaptersForFileFragments(t,r){return this.filetypeAdaptersForFile(t).filter(n=>n.contentTypes?n.contentTypes(t).includes(r):!1)}getFileCacheTypeByRefString(t,r){return this.filetypeAdaptersForFile(t).reduce((i,a)=>i||a.getCacheTypeByRefString(t,r),null)}allCaches(){return this.primary.cache}allFiles(){return this.primary.allFiles()}resourcePathForPath(t){return this.adapterForPath(t).resourcePathForPath(t)}parentPathForPath(t){return this.adapterForPath(t).parentPathForPath(t)}async createFileCache(t){let r=await this.getFile(t);for(let n of this.filetypeAdaptersForFile(r))n.parseCache&&await n.parseCache(r,!1)}getFileCache(t){return this.adapterForPath(t).getFileCache(t)}getFileContent(t,r,n){let i=this.filetypeAdaptersForFile(t).filter(a=>a.contentTypes(t).includes(r));if(i.length>=1)return i[0].readContent(t,r,n)}updateFileCache(t,r,n){this.adapterForPath(t).updateFileCache(t,r,n)}readFileFragments(t,r,n){let i=this.filetypeAdaptersForFileFragments(t,r);if(i.length>=1)return i[0].readContent(t,r,n)}async newFile(t,r,n,i){let a=this.filetypes.find(o=>o.supportedFileTypes.includes(n));if(a)return a.newFile(t,r,n,i)}newFileFragment(t,r,n,i,a){let o=this.filetypeAdaptersForFileFragments(t,r);if(o.length>=1)return o[0].newContent(t,r,n,i,a)}saveFileLabel(t,r,n){let i=this.filetypeAdaptersForFileFragments(t,"label");return i.length>=1?i[0].saveContent(t,"label",r,()=>n):this.primary.updateFileLabel(t.path,r,n)}saveFileFragment(t,r,n,i){let a=this.filetypeAdaptersForFileFragments(t,r);return a.length>=1?a[0].saveContent(t,r,n,i):!1}deleteFileFragment(t,r,n){let i=this.filetypeAdaptersForFileFragments(t,r);if(i.length>=1)return i[0].deleteContent(t,r,n)}onCreate(t){this.eventDispatch.dispatchEvent("onCreate",{file:t})}onModify(t){this.eventDispatch.dispatchEvent("onModify",{file:t})}onRename(t,r){this.eventDispatch.dispatchEvent("onRename",{file:t,oldPath:r})}onDelete(t){this.eventDispatch.dispatchEvent("onDelete",{file:t})}onSpaceUpdated(t,r){this.eventDispatch.dispatchEvent("onSpaceUpdated",{path:t,type:r})}onFocusesUpdated(){this.eventDispatch.dispatchEvent("onFocusesUpdated",null)}adapterForPath(t){return this.primary}async getRoot(){return this.adapterForPath().getRoot()}async copyFile(t,r,n){return this.adapterForPath(t).copyFile(t,r,n)}async writeTextToFile(t,r){return this.adapterForPath(t).writeTextToFile(t,r)}async readTextFromFile(t){return this.adapterForPath(t).readTextFromFile(t)}async writeBinaryToFile(t,r){return this.adapterForPath(t).writeBinaryToFile(t,r)}async readBinaryToFile(t){return this.adapterForPath(t).readBinaryToFile(t)}async renameFile(t,r){return this.adapterForPath(t).renameFile(t,r)}async createFolder(t){return this.adapterForPath(t).createFolder(t)}async childrenForFolder(t,r){return this.adapterForPath(t).childrenForFolder(t,r)}async fileExists(t){return this.adapterForPath(t).fileExists(t)}async getFile(t,r){return this.adapterForPath(t).getFile(t,r)}async deleteFile(t){return this.adapterForPath(t).deleteFile(t)}async addTagToFile(t,r){return this.adapterForPath(t).addTagToFile(t,r)}async renameTagForFile(t,r,n){return this.adapterForPath(t).renameTagForFile(t,r,n)}async removeTagFromFile(t,r){return this.adapterForPath(t).removeTagFromFile(t,r)}filesForTag(t){return this.primary.filesForTag(t)}};var $H=(e,t)=>e.skipFolderNames.some(r=>t.endsWith(r))||t.endsWith("/"+e.spaceSubFolder)||t==e.spaceSubFolder||t.split("/").pop()==e.spaceSubFolder||t.startsWith(e.spacesFolder+"/#")||t.startsWith(e.spacesFolder+"/$")||e.skipFolders.some(r=>r==t);var mC="templates",hC="kits",AC="actions",gC="waypoints.json",vC=class{constructor(t,r){this.fileSystem=t;this.dataPath=r;this.schemes=["spaces","vault"];this.onFocusesUpdated=()=>{this.spaceManager.onFocusesUpdated()};this.onSpaceUpdated=t=>{t.type=="views.mdb"?this.spaceManager.onSpaceUpdated(t.path,"frame"):t.type=="context.mdb"?this.spaceManager.onSpaceUpdated(t.path,"context"):t.type=="commands.mdb"&&this.spaceManager.onSpaceUpdated(t.path,"action")};this.onCreate=async t=>{t.file.isFolder?this.spaceManager.onSpaceCreated(t.file.path):this.spaceManager.onPathCreated(t.file.path)};this.onDelete=t=>{!t.file||(!t.file.isFolder&&t.file.extension!="mdb"?this.spaceManager.onPathDeleted(t.file.path):t.file.isFolder&&this.spaceManager.onSpaceDeleted(t.file.path))};this.onRename=t=>{!t.file||(!t.file.isFolder&&t.file.extension!="mdb"?this.spaceManager.onPathChanged(t.file.path,t.oldPath):t.file.isFolder&&this.spaceManager.onSpaceRenamed(t.file.path,t.oldPath))};this.authorities=["vault"];t.eventDispatch.addListener("onCreate",this.onCreate,0,this),t.eventDispatch.addListener("onRename",this.onRename,0,this),t.eventDispatch.addListener("onDelete",this.onDelete,0,this),t.eventDispatch.addListener("onFocusesUpdated",this.onFocusesUpdated,0,this),t.eventDispatch.addListener("onSpaceUpdated",this.onSpaceUpdated,0,this),t.eventDispatch.addListener("onCacheUpdated",this.onMetadataChange,0,this)}initiateAdapter(t){this.spaceManager=t}async readTemplates(t){return(await this.childrenForPath(`${t}/${this.spaceManager.superstate.settings.spaceSubFolder}/templates`)).filter(r=>!r.startsWith(".")).map(r=>r.split("/").pop())}async saveTemplate(t,r){return this.copyPath(t,`${r}/${this.spaceManager.superstate.settings.spaceSubFolder}/templates`)}deleteTemplate(t,r){return this.deletePath(`${r}/${this.spaceManager.superstate.settings.spaceSubFolder}/templates/${t}`)}async readFocuses(){return await this.fileSystem.fileExists(this.dataPath)||await this.fileSystem.createFolder(this.dataPath),await this.fileSystem.fileExists(`${this.dataPath}/${gC}`)?this.fileSystem.readTextFromFile(`${this.dataPath}/${gC}`).then(t=>Zs(dr(t))):[]}async saveFocuses(t){return await this.fileSystem.fileExists(this.dataPath)||await this.fileSystem.createFolder(this.dataPath),this.fileSystem.writeTextToFile(`${this.dataPath}/${gC}`,JSON.stringify(t))}async readTemplate(t){let r=`${this.dataPath}/${mC}/${t}`;if(await this.fileSystem.fileExists(r))return this.fileSystem.readFileFragments({path:`${r}/${this.spaceManager.superstate.settings.spaceSubFolder}/views.mdb`,name:"views",filename:"views.mdb",parent:r,isFolder:!1,extension:"mdb"},"mdbTables")}async readAllKits(){let t=(await this.childrenForPath(`${this.dataPath}/${hC}`)).map(n=>n.split("/").pop());return Promise.all(t.map(async n=>{let i=await this.readKitFrames(n);return{id:n,name:n,colors:{},frames:Object.values(i??{})}}))}async readAllTemplates(){let t=(await this.childrenForPath(`${this.dataPath}/${mC}`)).map(n=>n.split("/").pop()),r={};for(let n of t){let i=await this.readTemplate(n);i&&(r[n]=i)}return r}async readKitFrames(t){return this.fileSystem.readFileFragments({path:`${this.dataPath}/${hC}/${t}/kit.mdb`,name:"kit",filename:"kit.mdb",parent:`${this.dataPath}/${hC}/${t}`,isFolder:!1,extension:"mdb"},"mdbTables")}async saveFrameKit(t,r){let n={path:`${this.dataPath}/${hC}/${r}/kit.mdb`,name:"kit",filename:"kit.mdb",parent:`${this.dataPath}/${hC}/${r}`,isFolder:!1,extension:"mdb"};await this.fileSystem.saveFileFragment(n,"schema",t.schema.id,()=>t.schema),this.fileSystem.saveFileFragment(n,"mdbFrame",t.schema.id,()=>t)}async saveSpaceTemplate(t,r){let n=r;if(await this.fileSystem.fileExists(`${this.dataPath}/${mC}`)){let i=await this.childrenForPath(`${this.dataPath}/${mC}/${r}`);n=Mi(n,i)}await this.fileSystem.newFile(`${this.dataPath}/${mC}/${n}/${this.spaceManager.superstate.settings.spaceSubFolder}`,"view","mdb",t)}async onMetadataChange(t){if(!t.path)return;if(t.path.endsWith(".json")){let n=t.path.split("/").slice(0,-2).join("/");this.spaceManager.onPathPropertyChanged(n);return}let r=this.spaceManager.superstate.pathsIndex.get(t.path);if(r?.metadata.spacePath?.length>0){this.spaceManager.onPathPropertyChanged(r?.metadata.spacePath);return}this.spaceManager.onPathPropertyChanged(t.path)}uriByPath(t){return this.spaceManager.uriByString(t)}allPaths(t){return[...this.fileSystem.allFiles().filter(r=>t?t.some(n=>n=="folder"?r.isFolder:r.extension==n):!0).map(r=>r.path).filter(r=>!$H(this.spaceManager.superstate.settings,r))]}async pathExists(t){return this.fileSystem.fileExists(t)}async createItemAtPath(t,r,n,i){let a=await this.getPathInfo(t);if(!a)await this.fileSystem.createFolder(t);else if(!a?.isFolder){let o=await this.fileSystem.getFile(t);return o?this.fileSystem.newFileFragment(o,r,n,i)?.then(s=>o.path):null}return this.fileSystem.newFile(t,n,r,i).then(o=>o?.path)}async renamePath(t,r){let n=this.uriByPath(t),i=this.uriByPath(r),a=await this.fileSystem.getFile(n.path);if(n.refStr){let o=await this.fileSystem.getFileCacheTypeByRefString(a,n.refStr);return await this.fileSystem.saveFileFragment(a,o,n.refStr,()=>i.refStr),r}return await this.fileSystem.renameFile(t,r)}async deletePath(t){let r=this.uriByPath(t);if(r.refStr){let n=await this.fileSystem.getFile(r.path),i=await this.fileSystem.getFileCacheTypeByRefString(n,r.refStr);return this.fileSystem.deleteFileFragment(n,i,r.refStr)}return this.fileSystem.deleteFile(t)}async getPathInfo(t){let r=this.uriByPath(t),n=await this.fileSystem.getFile(r.path);if(r.refStr){let i=this.fileSystem.getFileCacheTypeByRefString(n,r.refStr)}return n}keysForCacheType(t){return this.fileSystem.keysForCacheType(t)}async readPathCache(t){let r=this.uriByPath(t);if(r.scheme=="spaces"){if(r.authority.charAt(0)=="$"){let n=Object.keys(cm).find(i=>i==r.authority.slice(1));if(n)return{file:null,metadata:null,label:{name:cm[n].name,sticker:cm[n].icon,color:""},readOnly:!1,type:"space",parent:"",tags:[]}}if(r.authority.charAt(0)=="#")return{file:null,metadata:null,label:{name:r.authority,sticker:"",color:""},type:"space",parent:"",tags:[],readOnly:!1}}return t=="/"?{file:{name:this.spaceManager.superstate.settings.systemName,path:"/",isFolder:!0},metadata:{},label:{name:this.spaceManager.superstate.settings.systemName,sticker:"",color:""},type:"space",subtype:"folder",parent:"",tags:[],readOnly:!1}:this.fileSystem.getFileCache(t)}async readPath(t){let r=this.uriByPath(t),n=await this.fileSystem.getFile(r.path);if(r.refStr){let i=this.fileSystem.getFileCacheTypeByRefString(n,r.refStr);this.fileSystem.getFileContent(n,i,r.refStr)}return this.fileSystem.readTextFromFile(t)}async copyPath(t,r,n){let i=this.uriByPath(t),a=await this.fileSystem.getFile(i.path);return this.fileSystem.copyFile(a.path,r,n)}async writeToPath(t,r,n){let i=this.uriByPath(t),a=await this.fileSystem.getFile(i.path);if(i.refStr){let o=this.fileSystem.getFileCacheTypeByRefString(a,i.refStr);this.fileSystem.saveFileFragment(a,o,i.refStr,()=>r)}return n?this.fileSystem.writeBinaryToFile(t,r):this.fileSystem.writeTextToFile(t,r)}async childrenForPath(t,r){return await this.fileSystem.fileExists(t)?this.fileSystem.childrenForFolder(t,r):[]}parentPathForPath(t){return this.fileSystem.parentPathForPath(t)}async readFrame(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);if(!n){let i=this.defaultFrame(t);if(Object.keys(i).some(a=>a==r))return i[r]}return this.fileSystem.readFileFragments(n,"mdbTable",r)}async readAllFrames(t){let r=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return r?this.fileSystem.readFileFragments(r,"mdbTables"):this.defaultFrame(t)}async readTable(t,r){let n=this.spaceInfoForPath(t),i=await this.fileSystem.getFile(n.dbPath);if(!i&&r==um.id){let o=dx(this.spaceManager.superstate,n),s=dC(o.cols),l=o.rows.map(u=>Vm(this.spaceManager.superstate.formulaContext,this.spaceManager.superstate.pathsIndex,u,o.cols,this.spaceManager.superstate.pathsIndex.get(t),s));return{...o,rows:l}}let a=await this.fileSystem.readFileFragments(i,"mdbTable",r);if(a&&a.schema.id!=um.id){let o=dC(a.cols),s=a.rows.map(l=>Vm(this.spaceManager.superstate.formulaContext,this.spaceManager.superstate.pathsIndex,l,a.cols,this.spaceManager.superstate.pathsIndex.get(t),o));return{...a,rows:s}}else if(!a&&r==um.id){let o=dx(this.spaceManager.superstate,n),s=dC(o.cols),l=o.rows.map(u=>Vm(this.spaceManager.superstate.formulaContext,this.spaceManager.superstate.pathsIndex,u,o.cols,this.spaceManager.superstate.pathsIndex.get(t),s));return{...o,rows:l}}return a}async spaceInitiated(t){return!0}async contextInitiated(t){let r=this.spaceInfoForPath(t);return await this.fileSystem.fileExists(r.dbPath)}async tablesForSpace(t){let r=this.spaceInfoForPath(t),n=await this.fileSystem.getFile(r.dbPath);if(!n)return Gh.rows;let i=await this.fileSystem.readFileFragments(n,"schemas",null);return i.length==0?Gh.rows:i}defaultDBTablesForContext(t){let r=dx(this.spaceManager.superstate,t),n=P$(t);return{...vJ(t),m_fields:{uniques:n.uniques,cols:n.cols,rows:[...n.rows??[],...r.cols]},[r.schema.id]:{uniques:r.cols.filter(a=>a.unique=="true").map(a=>a.name),cols:r.cols.map(a=>a.name),rows:r.rows}}}defaultFrame(t){return t.startsWith(_g)&&t==_g+"overview"?Voe:this.spaceManager.superstate.settings.defaultSpaceTemplate.length>0&&this.spaceManager.superstate.templateCache.has(this.spaceManager.superstate.settings.defaultSpaceTemplate)?this.spaceManager.superstate.templateCache.get(this.spaceManager.superstate.settings.defaultSpaceTemplate):this.spaceManager.superstate.settings.enableFolderNote?Goe:Hoe}async createDefaultTable(t){let r=this.spaceInfoForPath(t),n=this.spaceInfoForPath(t).dbPath,i=n.split(".").pop(),a=n.split("/").slice(0,-1).join("/"),o=n.split("/").pop().split(".")[0];return this.fileSystem.newFile(a,o,i,this.defaultDBTablesForContext(r))}async createDefaultFrames(t){let r=this.defaultFrame(t),n={...l6(r),m_schema:hJ},i=this.spaceInfoForPath(t).framePath,a=i.split(".").pop(),o=i.split("/").slice(0,-1).join("/"),s=i.split("/").pop().split(".")[0];return this.fileSystem.newFile(o,s,a,n)}async createTable(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return n||(n=await this.createDefaultTable(t)),this.fileSystem.newFileFragment(n,"schema",r.id,r)}async saveTableSchema(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return i||(i=await this.createDefaultTable(t)),this.fileSystem.saveFileFragment(i,"schema",r,n)}async saveTable(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);if(!i)if(n)i=await this.createDefaultTable(t);else return!1;return this.fileSystem.saveFileFragment(i,"mdbTable",r.schema.id,()=>r)}async deleteTable(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return this.fileSystem.deleteFileFragment(n,"schema",r)}async readAllTables(t){let r=this.spaceInfoForPath(t),n=await this.fileSystem.getFile(r.dbPath);if(!n){let i=dx(this.spaceManager.superstate,r);return{[i.schema.id]:i}}return this.fileSystem.readFileFragments(n,"mdbTables",null)}async framesForSpace(t){let r=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);if(!r){let n=this.defaultFrame(t);return Object.values(n).map(i=>i.schema)}return this.fileSystem.readFileFragments(r,"schemas",null)}async createFrame(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return n||(n=await this.createDefaultFrames(t)),this.fileSystem.newFileFragment(n,"schema",r.id,r)}async deleteFrame(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return this.fileSystem.deleteFileFragment(n,"schema",r)}async saveFrameSchema(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return i||(i=await this.createDefaultFrames(t)),this.fileSystem.saveFileFragment(i,"schema",r,n)}async saveFrame(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).framePath);return n||(n=await this.createDefaultFrames(t)),this.fileSystem.saveFileFragment(n,"mdbFrame",r.schema.id,()=>r)}async createDefaultCommands(t){let r={m_fields:{uniques:Ji.uniques,cols:Ji.cols,rows:[]},m_schema:{uniques:[],cols:["id","name","type","def","predicate","primary"],rows:[]}},n=this.spaceInfoForPath(t).commandsPath,i=n.split(".").pop(),a=n.split("/").slice(0,-1).join("/"),o=n.split("/").pop().split(".")[0];return this.fileSystem.newFile(a,o,i,r)}async commandsForSpace(t){let r=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);return r?this.fileSystem.readFileFragments(r,"mdbCommands",null):[]}async runCommand(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);if(!i)return{result:null,error:"No commands file found"};let a=await this.fileSystem.readFileFragments(i,"mdbCommand",r);if(!a)return{result:null,error:"No command found"};let o,s;try{a.schema.type=="script"&&(o=C2(a.code,n)),a.schema.type=="formula"&&(o=md(this.spaceManager.superstate.formulaContext,this.spaceManager.superstate.pathsIndex,a.code,a.fields.reduce((l,u)=>({...l,[u.name]:u}),{}),n,this.spaceManager.superstate.pathsIndex.get(t)))}catch(l){s=l}return{result:o,error:s}}async createCommand(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);return n||(n=await this.createDefaultCommands(t)),this.fileSystem.newFileFragment(n,"schema",r.id,r)}async readSystemCommands(){let t=(await this.childrenForPath(`${this.dataPath}/${AC}`,"folder")).map(n=>n.split("/").pop());return Promise.all(t.map(async n=>{let i=await this.readLibraryCommands(n);return{name:n,commands:Object.values(i??{})}}))}async readLibraryCommands(t){return this.fileSystem.readFileFragments({path:`${this.dataPath}/${AC}/${t}/commands.mdb`,name:"commands",filename:"commands.mdb",parent:`${this.dataPath}/${AC}/${t}`,isFolder:!1,extension:"mdb"},"mdbCommands")}async saveSystemCommand(t,r){let n={path:`${this.dataPath}/${AC}/${t}/commands.mdb`,name:"commands",filename:"commands.mdb",parent:`${this.dataPath}/${AC}/${t}`,isFolder:!1,extension:"mdb"};if(r)await this.fileSystem.saveFileFragment(n,"schema",r.schema.id,()=>r.schema),await this.fileSystem.saveFileFragment(n,"mdbCommand",r.schema.id,()=>r);else{let i={m_fields:{uniques:Ji.uniques,cols:Ji.cols,rows:[]},m_schema:{uniques:[],cols:["id","name","type","def","predicate","primary"],rows:[]}},a=n.path,o=a.split(".").pop(),s=a.split("/").slice(0,-1).join("/"),l=a.split("/").pop().split(".")[0];await this.fileSystem.newFile(s,l,o,i)}}async deleteCommand(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);return this.fileSystem.deleteFileFragment(n,"mdbCommand",r)}async saveCommand(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).commandsPath);return i||(i=await this.createDefaultCommands(t)),this.fileSystem.saveFileFragment(i,"mdbCommand",r,n)}async contextForSpace(t){let r=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return r?this.fileSystem.readFileFragments(r,"mdbTable",Nr):dx(this.spaceManager.superstate,this.spaceInfoForPath(t))}async addSpaceProperty(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t)?.dbPath);return n||await this.createDefaultTable(t),this.fileSystem.newFileFragment(n,"field",r.name,r)}async deleteSpaceProperty(t,r){let n=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return this.fileSystem.deleteFileFragment(n,"field",r)}async saveSpaceProperty(t,r,n){let i=await this.fileSystem.getFile(this.spaceInfoForPath(t).dbPath);return i||await this.createDefaultTable(t),this.fileSystem.saveFileFragment(i,"field",n,a=>({...a,...r}))}async addProperty(t,r){let n=await this.fileSystem.getFile(t);this.fileSystem.newFileFragment(n,"property",r.name,r)}async saveProperties(t,r){let n=await this.fileSystem.getFile(t);return this.fileSystem.saveFileFragment(n,"property",null,i=>({...i,...r}))}async readLabel(t){let r=this.fileSystem.getFileCache(t)?.label;if(!r){let n=await this.fileSystem.getFile(t);return n?this.fileSystem.readFileFragments(n,"label",null):{}}return r}async saveLabel(t,r,n){if(this.spaceManager.superstate.spacesIndex.has(t)){let a=this.spaceInfoForPath(t),o=await this.fileSystem.getFile(a.defPath),s=await this.fileSystem.getFile(a.notePath);if(this.spaceManager.superstate.settings.enableFolderNote)s||(s=await this.fileSystem.newFile(a.folderPath,a.name,"md"));else{if(!o){let l=this.spaceInfoForPath(t).defPath,u=l.split(".").pop(),c=l.split("/").slice(0,-1).join("/"),f=l.split("/").pop().split(".")[0];o=await this.fileSystem.newFile(c,f,u)}s=o}await this.fileSystem.saveFileLabel(s,r,n);return}let i=await this.fileSystem.getFile(t);this.fileSystem.saveFileLabel(i,r,n)}async renameProperty(t,r,n){let i=await this.fileSystem.getFile(t);this.fileSystem.saveFileFragment(i,"property",null,a=>{let{[r]:o,...s}=a;return o?{...s,[n]:o}:a})}async readProperties(t){let r=await this.fileSystem.getFile(t);return this.fileSystem.readFileFragments(r,"property",null)}async deleteProperty(t,r){let n=await this.fileSystem.getFile(t);this.fileSystem.deleteFileFragment(n,"property",r)}allSpaces(){let t=Object.keys(cm).map(o=>this.spaceManager.spaceInfoForPath(`spaces://$${o}`)),r=()=>this.readTags().map(o=>Fg(this.spaceManager,Jj(o)))??[],n=()=>this.allPaths(["folder"]).filter(s=>!$H(this.spaceManager.superstate.settings,s)).map(s=>IE(this.spaceManager,s)),i=this.spaceManager.superstate.settings.enableDefaultSpaces?r():[],a=n();return[...t,...i,...a]}readTags(){return this.fileSystem.allTags()}spaceInfoForPath(t){return CJ(this.spaceManager,t)}allCaches(){return this.fileSystem.allCaches()}async spaceDefForSpace(t){let r=this.spaceInfoForPath(t);if(!r)return null;let n=r.defPath?await this.fileSystem.readTextFromFile(r.defPath):null;if(!n){let a=await this.fileSystem.getFile(r.notePath),s=(a?this.fileSystem.getFileCache(a.path)?.frontmatter:null)??{};return B6(s,this.spaceManager.superstate.settings)}let i=dr(n)??{};return B6(i,this.spaceManager.superstate.settings)}async createSpace(t,r,n){let i=this.spaceInfoForPath(r),a=i.folderPath=="/"?t:i.folderPath+"/"+t;if(await this.fileSystem.createFolder(a),Object.keys(n??{}).length>0)return this.saveSpace(a,()=>n)}async saveSpace(t,r,n){let i=r(await this.spaceDefForSpace(t))??{},a=this.spaceInfoForPath(t),o=await this.fileSystem.getFile(a.defPath);if(!o){let l=this.spaceInfoForPath(t).defPath,u=l.split(".").pop(),c=l.split("/").slice(0,-1).join("/"),f=l.split("/").pop().split(".")[0];o=await this.fileSystem.newFile(c,f,u)}let s=await this.fileSystem.getFile(a.notePath);this.spaceManager.superstate.settings.enableFolderNote?s||(s=await this.fileSystem.newFile(a.folderPath,qc(a.notePath),"md")):s=o,n&&await this.fileSystem.saveFileFragment(s,"property",null,l=>({...l,...n??{}})),await this.fileSystem.saveFileFragment(o,"definition",null,l=>({[qE]:i.filters,[BE]:i.contexts,[LE]:i.links,[zE]:i.sort,[RE]:i.template,[$E]:i.templateName,[eO]:i.recursive}))}renameSpace(t,r){let n=this.spaceInfoForPath(t),i=this.spaceInfoForPath(r);return this.fileSystem.renameFile(n.folderPath,i.folderPath).then(a=>(this.spaceManager.superstate.settings.enableFolderNote&&this.fileSystem.renameFile(Rf(n.notePath,i.path),i.notePath),a))}deleteSpace(t){let r=this.spaceInfoForPath(t),n=Fg(this.spaceManager,r.name);this.fileSystem.deleteFile(n.folderPath)}childrenForSpace(t){return this.fileSystem.allFiles().filter(r=>r.parent==t).map(r=>r.path)}addTag(t,r){this.fileSystem.addTagToFile(t,r)}renameTag(t,r,n){this.fileSystem.renameTagForFile(t,r,n)}deleteTag(t,r){this.fileSystem.removeTagFromFile(t,r)}pathsForTag(t){return this.fileSystem.filesForTag(t)}resolvePath(t,r){return this.fileSystem.resolvePath(t,r)}};var df=ge(Te());function PA(e){return Array.isArray?Array.isArray(e):r2e(e)==="[object Array]"}var lYe=1/0;function uYe(e){if(typeof e=="string")return e;let t=e+"";return t=="0"&&1/e==-lYe?"-0":t}function cYe(e){return e==null?"":uYe(e)}function Gm(e){return typeof e=="string"}function e2e(e){return typeof e=="number"}function fYe(e){return e===!0||e===!1||dYe(e)&&r2e(e)=="[object Boolean]"}function t2e(e){return typeof e=="object"}function dYe(e){return t2e(e)&&e!==null}function ff(e){return e!=null}function qH(e){return!e.trim().length}function r2e(e){return e==null?e===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}var pYe="Incorrect 'index' type",mYe=e=>`Invalid value for key ${e}`,hYe=e=>`Pattern length exceeds max of ${e}.`,AYe=e=>`Missing ${e} property in key`,gYe=e=>`Property 'weight' in key '${e}' must be a positive integer`,Ywe=Object.prototype.hasOwnProperty,LH=class{constructor(t){this._keys=[],this._keyMap={};let r=0;t.forEach(n=>{let i=n2e(n);this._keys.push(i),this._keyMap[i.id]=i,r+=i.weight}),this._keys.forEach(n=>{n.weight/=r})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function n2e(e){let t=null,r=null,n=null,i=1,a=null;if(Gm(e)||PA(e))n=e,t=Zwe(e),r=zH(e);else{if(!Ywe.call(e,"name"))throw new Error(AYe("name"));let o=e.name;if(n=o,Ywe.call(e,"weight")&&(i=e.weight,i<=0))throw new Error(gYe(o));t=Zwe(o),r=zH(o),a=e.getFn}return{path:t,id:r,weight:i,src:n,getFn:a}}function Zwe(e){return PA(e)?e:e.split(".")}function zH(e){return PA(e)?e.join("."):e}function vYe(e,t){let r=[],n=!1,i=(a,o,s)=>{if(!!ff(a))if(!o[s])r.push(a);else{let l=o[s],u=a[l];if(!ff(u))return;if(s===o.length-1&&(Gm(u)||e2e(u)||fYe(u)))r.push(cYe(u));else if(PA(u)){n=!0;for(let c=0,f=u.length;ce.score===t.score?e.idx{this._keysMap[r.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Gm(this.docs[0])?this.docs.forEach((t,r)=>{this._addString(t,r)}):this.docs.forEach((t,r)=>{this._addObject(t,r)}),this.norm.clear())}add(t){let r=this.size();Gm(t)?this._addString(t,r):this._addObject(t,r)}removeAt(t){this.records.splice(t,1);for(let r=t,n=this.size();r{let o=i.getFn?i.getFn(t):this.getFn(t,i.path);if(!!ff(o)){if(PA(o)){let s=[],l=[{nestedArrIndex:-1,value:o}];for(;l.length;){let{nestedArrIndex:u,value:c}=l.pop();if(!!ff(c))if(Gm(c)&&!qH(c)){let f={v:c,i:u,n:this.norm.get(c)};s.push(f)}else PA(c)&&c.forEach((f,d)=>{l.push({nestedArrIndex:d,value:f})})}n.$[a]=s}else if(Gm(o)&&!qH(o)){let s={v:o,n:this.norm.get(o)};n.$[a]=s}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}};function i2e(e,t,{getFn:r=$r.getFn,fieldNormWeight:n=$r.fieldNormWeight}={}){let i=new yC({getFn:r,fieldNormWeight:n});return i.setKeys(e.map(n2e)),i.setSources(t),i.create(),i}function kYe(e,{getFn:t=$r.getFn,fieldNormWeight:r=$r.fieldNormWeight}={}){let{keys:n,records:i}=e,a=new yC({getFn:t,fieldNormWeight:r});return a.setKeys(n),a.setIndexRecords(i),a}function v5(e,{errors:t=0,currentLocation:r=0,expectedLocation:n=0,distance:i=$r.distance,ignoreLocation:a=$r.ignoreLocation}={}){let o=t/e.length;if(a)return o;let s=Math.abs(n-r);return i?o+s/i:s?1:o}function CYe(e=[],t=$r.minMatchCharLength){let r=[],n=-1,i=-1,a=0;for(let o=e.length;a=t&&r.push([n,i]),n=-1)}return e[a-1]&&a-n>=t&&r.push([n,a-1]),r}var vy=32;function DYe(e,t,r,{location:n=$r.location,distance:i=$r.distance,threshold:a=$r.threshold,findAllMatches:o=$r.findAllMatches,minMatchCharLength:s=$r.minMatchCharLength,includeMatches:l=$r.includeMatches,ignoreLocation:u=$r.ignoreLocation}={}){if(t.length>vy)throw new Error(hYe(vy));let c=t.length,f=e.length,d=Math.max(0,Math.min(n,f)),p=a,h=d,m=s>1||l,g=m?Array(f):[],A;for(;(A=e.indexOf(t,h))>-1;){let k=v5(t,{currentLocation:A,expectedLocation:d,distance:i,ignoreLocation:u});if(p=Math.min(k,p),h=A+c,m){let M=0;for(;M=C;R-=1){let $=R-1,B=r[e.charAt($)];if(m&&(g[$]=+!!B),D[R]=(D[R+1]<<1|1)&B,k&&(D[R]|=(b[R+1]|b[R])<<1|1|b[R+1]),D[R]&w&&(v=v5(t,{errors:k,currentLocation:$,expectedLocation:d,distance:i,ignoreLocation:u}),v<=p)){if(p=v,h=$,h<=d)break;C=Math.max(1,2*d-h)}}if(v5(t,{errors:k+1,currentLocation:d,expectedLocation:d,distance:i,ignoreLocation:u})>p)break;b=D}let S={isMatch:h>=0,score:Math.max(.001,v)};if(m){let k=CYe(g,s);k.length?l&&(S.indices=k):S.isMatch=!1}return S}function jYe(e){let t={};for(let r=0,n=e.length;r{this.chunks.push({pattern:d,alphabet:jYe(d),startIndex:p})},f=this.pattern.length;if(f>vy){let d=0,p=f%vy,h=f-p;for(;d{let{isMatch:A,score:b,indices:v}=DYe(t,h,m,{location:i+g,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:l,includeMatches:n,ignoreLocation:u});A&&(d=!0),f+=b,A&&v&&(c=[...c,...v])});let p={isMatch:d,score:d?f/this.chunks.length:1};return d&&n&&(p.indices=c),p}},Hm=class{constructor(t){this.pattern=t}static isMultiMatch(t){return Xwe(t,this.multiRegex)}static isSingleMatch(t){return Xwe(t,this.singleRegex)}search(){}};function Xwe(e,t){let r=e.match(t);return r?r[1]:null}var UH=class extends Hm{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){let r=t===this.pattern;return{isMatch:r,score:r?0:1,indices:[0,this.pattern.length-1]}}},WH=class extends Hm{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){let n=t.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}},VH=class extends Hm{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){let r=t.startsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,this.pattern.length-1]}}},GH=class extends Hm{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){let r=!t.startsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,t.length-1]}}},HH=class extends Hm{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){let r=t.endsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[t.length-this.pattern.length,t.length-1]}}},QH=class extends Hm{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){let r=!t.endsWith(this.pattern);return{isMatch:r,score:r?0:1,indices:[0,t.length-1]}}},b5=class extends Hm{constructor(t,{location:r=$r.location,threshold:n=$r.threshold,distance:i=$r.distance,includeMatches:a=$r.includeMatches,findAllMatches:o=$r.findAllMatches,minMatchCharLength:s=$r.minMatchCharLength,isCaseSensitive:l=$r.isCaseSensitive,ignoreLocation:u=$r.ignoreLocation}={}){super(t),this._bitapSearch=new y5(t,{location:r,threshold:n,distance:i,includeMatches:a,findAllMatches:o,minMatchCharLength:s,isCaseSensitive:l,ignoreLocation:u})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}},x5=class extends Hm{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let r=0,n,i=[],a=this.pattern.length;for(;(n=t.indexOf(this.pattern,r))>-1;)r=n+a,i.push([n,r-1]);let o=!!i.length;return{isMatch:o,score:o?0:1,indices:i}}},YH=[UH,x5,VH,GH,QH,HH,WH,b5],Kwe=YH.length,OYe=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,MYe="|";function NYe(e,t={}){return e.split(MYe).map(r=>{let n=r.trim().split(OYe).filter(a=>a&&!!a.trim()),i=[];for(let a=0,o=n.length;a!!(e[w5.AND]||e[w5.OR]),_Ye=e=>!!e[JH.PATH],PYe=e=>!PA(e)&&t2e(e)&&!eQ(e),Jwe=e=>({[w5.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function a2e(e,t,{auto:r=!0}={}){let n=i=>{let a=Object.keys(i),o=_Ye(i);if(!o&&a.length>1&&!eQ(i))return n(Jwe(i));if(PYe(i)){let l=o?i[JH.PATH]:a[0],u=o?i[JH.PATTERN]:i[l];if(!Gm(u))throw new Error(mYe(l));let c={keyId:zH(l),pattern:u};return r&&(c.searcher=KH(u,t)),c}let s={children:[],operator:a[0]};return a.forEach(l=>{let u=i[l];PA(u)&&u.forEach(c=>{s.children.push(n(c))})}),s};return eQ(e)||(e=Jwe(e)),n(e)}function IYe(e,{ignoreFieldNorm:t=$r.ignoreFieldNorm}){e.forEach(r=>{let n=1;r.matches.forEach(({key:i,norm:a,score:o})=>{let s=i?i.weight:null;n*=Math.pow(o===0&&s?Number.EPSILON:o,(s||1)*(t?1:a))}),r.score=n})}function BYe(e,t){let r=e.matches;t.matches=[],ff(r)&&r.forEach(n=>{if(!ff(n.indices)||!n.indices.length)return;let{indices:i,value:a}=n,o={indices:i,value:a};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),t.matches.push(o)})}function RYe(e,t){t.score=e.score}function $Ye(e,t,{includeMatches:r=$r.includeMatches,includeScore:n=$r.includeScore}={}){let i=[];return r&&i.push(BYe),n&&i.push(RYe),e.map(a=>{let{idx:o}=a,s={item:t[o],refIndex:o};return i.length&&i.forEach(l=>{l(a,s)}),s})}var yc=class{constructor(t,r={},n){this.options={...$r,...r},this.options.useExtendedSearch,this._keyStore=new LH(this.options.keys),this.setCollection(t,n)}setCollection(t,r){if(this._docs=t,r&&!(r instanceof yC))throw new Error(pYe);this._myIndex=r||i2e(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(t){!ff(t)||(this._docs.push(t),this._myIndex.add(t))}remove(t=()=>!1){let r=[];for(let n=0,i=this._docs.length;n-1&&(l=l.slice(0,r)),$Ye(l,this._docs,{includeMatches:n,includeScore:i})}_searchStringList(t){let r=KH(t,this.options),{records:n}=this._myIndex,i=[];return n.forEach(({v:a,i:o,n:s})=>{if(!ff(a))return;let{isMatch:l,score:u,indices:c}=r.searchIn(a);l&&i.push({item:a,idx:o,matches:[{score:u,value:a,norm:s,indices:c}]})}),i}_searchLogical(t){let r=a2e(t,this.options),n=(s,l,u)=>{if(!s.children){let{keyId:f,searcher:d}=s,p=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(l,f),searcher:d});return p&&p.length?[{idx:u,item:l,matches:p}]:[]}let c=[];for(let f=0,d=s.children.length;f{if(ff(s)){let u=n(r,s,l);u.length&&(a[l]||(a[l]={idx:l,item:s,matches:[]},o.push(a[l])),u.forEach(({matches:c})=>{a[l].matches.push(...c)}))}}),o}_searchObjectList(t){let r=KH(t,this.options),{keys:n,records:i}=this._myIndex,a=[];return i.forEach(({$:o,i:s})=>{if(!ff(o))return;let l=[];n.forEach((u,c)=>{l.push(...this._findMatches({key:u,value:o[c],searcher:r}))}),l.length&&a.push({idx:s,item:o,matches:l})}),a}_findMatches({key:t,value:r,searcher:n}){if(!ff(r))return[];let i=[];if(PA(r))r.forEach(({v:a,i:o,n:s})=>{if(!ff(a))return;let{isMatch:l,score:u,indices:c}=n.searchIn(a);l&&i.push({score:u,key:t,value:a,idx:o,norm:s,indices:c})});else{let{v:a,n:o}=r,{isMatch:s,score:l,indices:u}=n.searchIn(a);s&&i.push({score:l,key:t,value:a,norm:o,indices:u})}return i}};yc.version="7.0.0";yc.createIndex=i2e;yc.parseIndex=kYe;yc.config=$r;yc.parseQuery=a2e;FYe(ZH);var vi=ge(Te());var cl=ge(Te()),qYe={position:"absolute",width:0,height:0,visibility:"hidden",overflow:"scroll",whiteSpace:"pre"},LYe=["fontSize","fontFamily","fontWeight","fontStyle","letterSpacing","textTransform"],o2e=(0,cl.forwardRef)((e,t)=>{let{classNames:r,inputAttributes:n,inputEventHandlers:i,index:a}=e,o=(0,cl.useRef)(null),[s,l]=(0,cl.useState)(null),[u,c]=(0,cl.useState)("");(0,cl.useEffect)(()=>{f(),d(),setTimeout(()=>{t.current?.focus()},50)},[]),(0,cl.useEffect)(()=>{u!==e.placeholderText&&(c(e.placeholderText),d())},[e.query,e.placeholderText]);let f=()=>{let p=window.getComputedStyle(t.current);LYe.forEach(h=>{o.current.style[h]=p[h]})},d=()=>{let p=Math.ceil(o.current.scrollWidth)+2;p!==s&&l(p)};return cl.default.createElement("div",{className:r.search},cl.default.createElement("div",{className:r.searchWrapper},cl.default.createElement("div",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//search")}}),cl.default.createElement("input",{...n,...i,ref:t,value:e.query,placeholder:u,className:r.searchInput,role:"combobox",style:{width:"100%"},onClick:p=>p.stopPropagation()}),cl.default.createElement("div",{ref:o,style:qYe},e.query||u),cl.default.createElement("span",null)))}),s2e=o2e;o2e.displayName="SelectMenuSearch";var tQ=ge(Te()),zYe=e=>tQ.default.createElement("button",{type:"button",className:e.classNames.selectedTag,onClick:e.onDelete},tQ.default.createElement("span",{className:e.classNames.selectedTagName},e.tag.name)),l2e=zYe;var u2e=ge(Te()),c2e=e=>u2e.default.createElement("div",{className:"mk-sticker",dangerouslySetInnerHTML:{__html:e.ui.getSticker(e.sticker)}});var ui=ge(Te());function f2e(e,t){let r=j2(t);return e?.replace(r,"$&")}var UYe=e=>{let t=(0,ui.useRef)(null);return(0,ui.useEffect)(()=>{e.active&&t?.current?.scrollIntoViewIfNeeded()},[e.active]),ui.default.createElement(ui.default.Fragment,null,e.item.icon&&ui.default.createElement(c2e,{ui:e.ui,sticker:e.item.icon}),ui.default.createElement("div",{ref:t,className:"mk-menu-options-inner"},e.item.onToggle&&ui.default.createElement("div",null,"Toggle"),ui.default.createElement("span",{style:e.item.color?.length>0?{background:e.item.color,padding:"2px 4px",borderRadius:"4px",color:e.item.color=="var(--mk-color-none)"?"inherit":"var(--mk-color-white)"}:{},dangerouslySetInnerHTML:{__html:f2e(e.item.name,e.query)}}),e.item.description&&ui.default.createElement("span",{"aria-label":e.item.description,className:"mk-menu-options-description",dangerouslySetInnerHTML:{__html:f2e(e.item.description,e.query)}})),e.item.type==1&&ui.default.createElement("span",null,e.item.value),e.item.type==3&&e.item.value&&ui.default.createElement("div",{className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//check")}}),e.item.onMoreOptions||e.onMoreOption&&e.item.removeable?ui.default.createElement("div",{onClick:r=>{r.stopPropagation(),r.preventDefault(),e.item.onMoreOptions?e.item.onMoreOptions(r):e.onMoreOption(r,e.item.value)},className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//options")}}):null,e.item.removeable&&e.onDeleteOption&&ui.default.createElement("div",{onClick:r=>{r.stopPropagation(),r.preventDefault(),e.onDeleteOption(e.item.value)},className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//close")}}),e.item.type==6&&ui.default.createElement("div",{className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//chevron-right")}}))},WYe=e=>{let[t,r]=(0,ui.useState)(e.value);return ui.default.createElement("input",{type:"text",value:t,onKeyDown:n=>{n.key=="Enter"&&e.setValue(t)},onMouseDown:n=>n.stopPropagation(),onClick:n=>n.stopPropagation(),onFocus:n=>{n.stopPropagation()},onChange:n=>r(n.target.value),onBlur:n=>e.setValue(t)})},VYe=e=>{let t=e.options.map((r,n)=>{let i=`${e.id}-${n}`,a=r.type==-1?"mk-menu-separator":r.type==2?"mk-menu-input":r.type==5?"mk-menu-custom":`mk-menu-option ${e.index===n&&e.classNames.suggestionActive} ${r.disabled&&e.classNames.suggestionDisabled}`;return ui.default.createElement("div",{ref:o=>{e.refs?.current&&(e.refs.current[n]=o)},onMouseDown:o=>{e.isDisclosureMenu||o.stopPropagation(),o.preventDefault()},onClick:o=>{if(r.onSubmenu&&e.openSubmenu){let s=e.refs?.current[n].getBoundingClientRect();e.openSubmenu(r.onSubmenu(s,()=>{e.onHide&&e.onHide(),e.hide()}))}else r.onClick?(r.onClick(o),r.type!=6&&r.type!=1&&e.hide()):(r.type==null||r.type==0||r.type==1)&&(e.selectOption(r,{ctrlKey:o.ctrlKey,metaKey:o.metaKey,altKey:o.altKey,shiftKey:o.shiftKey,doubleClick:o.detail==2}),e.isDisclosureMenu||o.stopPropagation())},id:i,key:i,className:a},r.type==-1?ui.default.createElement(ui.default.Fragment,null):r.type==-2?ui.default.createElement("div",{className:"mk-menu-options-section"},r.name):r.type==2?ui.default.createElement(WYe,{value:r.value,setValue:r.onValueChange}):r.type==5?ui.default.createElement(r.fragment,{hide:e.hide,onSubmenu:o=>{if(e.openSubmenu){let s=e.refs?.current[n].getBoundingClientRect();e.openSubmenu(o(s,()=>{e.onHide&&e.onHide(),e.hide()}))}}}):ui.default.createElement(UYe,{ui:e.ui,item:r,query:e.query,active:n==e.index,onMoreOption:e.moreOption,onDeleteOption:e.deleteOption}))});return ui.default.createElement("div",{className:"mk-menu-suggestions"},t,e.query&&e.allowNew&&ui.default.createElement("div",{className:"mk-menu-option",onMouseDown:r=>r.preventDefault(),onClick:r=>e.selectOption({name:e.query,value:e.query},{ctrlKey:r.ctrlKey,metaKey:r.metaKey,altKey:r.altKey,shiftKey:r.shiftKey})},ui.default.createElement("div",{className:"mk-sticker",dangerouslySetInnerHTML:{__html:e.ui.getSticker("ui//plus")}}),ui.default.createElement("div",{className:"mk-menu-options-inner"},e.addKeyword??"Add"," ",e.query)))},S5=VYe;function d2e(e,t){let r=e.querySelectorAll("a,button,input"),n=Array.prototype.findIndex.call(r,a=>a===t),i=r[n-1]||r[n+1];i&&i.focus()}var yy={ENTER:"Enter",TAB:"Tab",BACKSPACE:"Backspace",UP_ARROW:"ArrowUp",UP_ARROW_COMPAT:"Up",DOWN_ARROW:"ArrowDown",DOWN_ARROW_COMPAT:"Down",LEFT_ARROW:"ArrowLeft",RIGHT_ARROW:"ArrowRight"},m2e={root:"mk-menu-container",rootFocused:"mk-focused",selected:"mk-menu-input-wrapper",selectedTagWrapper:"mk-menu-selected-tag-wrapper",selectedTag:"mk-menu-selected-tag",selectedTagName:"mk-menu-selected-tag-name",search:"mk-menu-search",searchWrapper:"mk-menu-search-container",searchInput:"mk-menu-search-input",suggestions:"mk-menu-suggestions",suggestionActive:"mk-active",suggestionDisabled:"mk-disabled"},GYe={ui:null,id:"SelectMenu",tags:[],hide:()=>null,onHide:()=>null,suggestionsOnly:!1,placeholderText:z.labels.optionItemSelectPlaceholder,noSuggestionsText:null,newTagText:null,suggestions:[],suggestionsFilter:HYe,suggestionsTransform:null,classNames:m2e,delimiters:[yy.ENTER],minQueryLength:2,maxSuggestionsLength:8,inputAttributes:{}},h2e=(e,t)=>e.findIndex(r=>oxe(t).test(r.name)),p2e=(e,t,r,n,i,a)=>{if(t.length>=e.minQueryLength){let o=h2e(n,t),s=r===-1?o:r,l=s>-1?n[s]:null;i(l||{name:t,value:t},a)}};function HYe(e,t){return j2(t).test(e.name)}function QYe(e,t,r){let n,i=e.suggestions;r.length>0&&(i=e.suggestions.filter(s=>s.section==r));let a={threshold:0,ignoreLocation:!0,keys:["name","value"]},o=new yc(i,a);return n=t.length==0?i:o.search(t).map(s=>s.item),n=n.slice(0,e.maxSuggestionsLength),e.newTagText&&h2e(n,t)===-1?n.push({id:0,name:t,value:t}):e.noSuggestionsText&&n.length===0&&n.push({id:0,name:e.noSuggestionsText,value:"",disabled:!0}),n}var A2e=vi.default.forwardRef((e,t)=>{let r={...GYe,...e},[n,i]=(0,vi.useState)([]),a=(0,vi.useRef)([]),o=(0,vi.useMemo)(()=>r.showSections?[{name:"All",value:""},...r.sections??Mr(r.suggestions.map(re=>re.section)).filter(re=>re)]:[],[r.showSections,r.sections,r.suggestions]),s=(0,vi.useRef)(null),[l,u]=(0,vi.useState)(""),[c,f]=(0,vi.useState)(""),[d,p]=(0,vi.useState)(!1),[h,m]=(0,vi.useState)(0),g=(0,vi.useRef)(!1);(0,vi.useEffect)(()=>{t&&(t.current=()=>d?!0:(s?.current?.focus(),p(!0),!1))},[d]),(0,vi.useEffect)(()=>{if(c.length==0&&r.defaultSuggestions){i(r.defaultSuggestions);return}i(QYe(r,c,l))},[c,r.defaultSuggestions,l,r.suggestions]);let A=(0,vi.useRef)(null),b=re=>{if(re.type==="compositionstart"){g.current=!0;return}if(re.type==="compositionend"){g.current=!1;return}let Q=re.target.value;r.onInput&&r.onInput(Q),Q.length===c.length+1&&r.delimiters.indexOf(c.slice(-1))>-1?p2e(r,c,h,n,k,{}):Q!==c&&f(Q)},v=re=>{g.current||(r.delimiters.indexOf(re.key)>-1&&((c||h>-1)&&re.preventDefault(),p2e(r,c,h,n,k,{ctrlKey:re.ctrlKey,metaKey:re.metaKey,altKey:re.altKey,shiftKey:re.shiftKey})),re.key!="Escape"&&(re.key===yy.TAB&&R(re),re.key===yy.BACKSPACE&&P(),(re.key===yy.UP_ARROW||re.key===yy.UP_ARROW_COMPAT)&&T(re),(re.key===yy.DOWN_ARROW||re.key===yy.DOWN_ARROW_COMPAT)&&D(re),re.stopPropagation()))},x=()=>{p(!1),r.onBlur&&r.onBlur()},w=()=>{p(!0),r.onFocus&&r.onFocus()},S=(re,Q)=>{A.current&&d2e(A.current,Q.currentTarget),M(re)},k=(re,Q)=>{re.disabled||r.onValidate&&!r.onValidate(re)||(r.onAddition(re,Q),O())},M=re=>{r.onDelete(re)},O=()=>{f(""),m(-1)},C=()=>{m(-1)},T=re=>{re.preventDefault();let Q=n.length-1,he=h<=0?Q:h-1;n[he].disabled?m(he<=0?Q:he-1):m(he)},D=re=>{re.preventDefault();let Q=n.length-1,he=h>=Q?0:h+1;n[he].disabled?m(he>=Q?0:he+1):m(he)};function P(){c.length||M(r.tags.length-1)}function R(re){r.showSections&&(re.preventDefault(),re.stopPropagation(),u(Q=>{let he=o.findIndex(Ie=>Ie.value==Q);return re.shiftKey?he==0?Q:(r.onSelectSection&&r.onSelectSection(o[he-1].value),o[he-1].value):he==o.length-1?Q:(r.onSelectSection&&r.onSelectSection(o[he+1].value),o[he+1].value)}))}let $=()=>{s.current.focus()},B={onChange:b,onCompositionEnd:b,onCompositionStart:b};(0,vi.useEffect)(()=>(r.ui.inputManager.on("keydown",v),()=>{r.ui.inputManager.off("keydown",v)}),[n,h]);let N=d&&c.length>=r.minQueryLength,W=Object.assign({},m2e,r.classNames);r.wrapperClass&&(W.root=`${W.root} ${r.wrapperClass}`);let _=[W.root];d&&_.push(W.rootFocused);let X=(0,vi.useRef)(null),oe=re=>{X.current&&X.current.hide(!0),X.current=re};return vi.default.createElement("div",{ref:A,className:_.join(" "),style:r.suggestionsOnly?{}:{"--mk-menu-max-height":"200px"}},r.suggestionsOnly?null:vi.default.createElement("div",{className:W.selected,"aria-relevant":"additions removals","aria-live":"polite"},r.tags.length>0&&vi.default.createElement("div",{className:W.selectedTagWrapper},r.tags.map((re,Q)=>vi.default.createElement(l2e,{key:Q,tag:re,classNames:W,onDelete:he=>S(Q,he)}))),vi.default.createElement(s2e,{ui:r.ui,ref:s,query:c,index:h,id:r.id,currentSection:o.find(re=>re.value==l),classNames:W,inputAttributes:r.inputAttributes,inputEventHandlers:B,expanded:N,placeholderText:r.placeholderText})),r.showSections?vi.default.createElement("div",{className:"mk-menu-sections"},o.map((re,Q)=>vi.default.createElement("div",{key:Q,onClick:he=>{he.stopPropagation(),u(re.value)},className:`${l==re.value?"is-active":""} mk-menu-section`},re.name==""?z.labels.all:re.name))):vi.default.createElement(vi.default.Fragment,null),n.length||r.allowNew?vi.default.createElement(S5,{ui:r.ui,hide:()=>{r.hide()},addKeyword:r.addKeyword,refs:a,options:n,query:c,setIndex:m,index:h,onHide:r.onHide,id:r.id,classNames:W,expanded:N,selectOption:k,allowNew:r.allowNew,moreOption:r.onMoreOption,deleteOption:r.onDeleteOption,isDisclosureMenu:r.isDisclosure,openSubmenu:oe}):null,r.previewComponent)});A2e.displayName="SelectMenuComponent";var g2e=A2e;var v2e=df.default.forwardRef((e,t)=>{let r=e.options.map((f,d)=>({...f,id:d+1}));(0,df.useEffect)(()=>{i(e.options.map((f,d)=>({...f,id:d+1})))},[e.options]);let[n,i]=(0,df.useState)(r),[a,o]=(0,df.useState)(e.value.map(f=>r.find(d=>d.value==f)??{id:0,name:f,value:f})),s=(0,df.useCallback)(f=>{let d=a.filter((p,h)=>h!==f);o(d),e.saveOptions&&e.saveOptions(n.map(p=>p.value),d.map(p=>p.value),!1)},[n,a,e]),l=(0,df.useCallback)(f=>{let d=n.filter(h=>h.value!=f),p=a.filter(h=>h.value!=f);i(d),o(p),e.removeOption&&e.removeOption(f),e.hide()},[a,n,e]),u=(0,df.useCallback)((f,d)=>{let p=f,h=n,m=a;n.find(g=>g.value==f.value)||(p={id:n.length+1,name:f.name,value:f.value??f.name},h=[...n,p],i(h)),e.multi?a.find(g=>g.value==p.value)||(m=[...a,p],o(m)):(m=[p],o(m)),e.saveOptions&&e.saveOptions(h.map(g=>g.value),m.map(g=>g.value),!0),!e.multi&&f.type!=1&&e.hide()},[a,n]),c=(0,df.useCallback)(f=>!(!e.editable&&!n.find(d=>d.value==f.value)||f.name.length==0),[n]);return df.default.createElement(g2e,{tags:e.multi?a:[],suggestions:n,ui:e.ui,ref:t,addKeyword:e.addKeyword,hide:e.hide,onDelete:s,wrapperClass:e.wrapperClass,onMoreOption:e.onMoreOption,onDeleteOption:l,onAddition:u,onValidate:c,onSelectSection:e.onSelectSection,defaultSuggestions:e.defaultOptions,placeholderText:e.placeholder??"",minQueryLength:0,onHover:e.onHover,showSections:e.showSections,sections:e.sections,maxSuggestionsLength:e.showAll?Math.min(50,e.options.length):25,suggestionsOnly:!e.searchable&&!e.editable,allowNew:e.editable,previewComponent:e.previewComponent,isDisclosure:e.isDisclosure})});v2e.displayName="SelectMenu";var Kz=v2e;var To=ge(Te());var fl=ge(Te());var yd=(0,fl.forwardRef)((e,t)=>{let r=(0,fl.useRef)(null),[n,i]=(0,fl.useState)(!1),[a,o]=(0,fl.useState)(!1),s=async u=>{let c=r.current,f=e.superstate.spaceManager.uriByString(e.path,e.source),d=e.properties,p=e.superstate.pathsIndex.get(f.basePath),h=p?.type=="space"&&e.forceNote?e.superstate.spacesIndex.get(e.path)?.space.notePath:p?f.fullPath:null;if(h)i(!1),e.superstate.ui.openPath(h,!1,c,d);else if(u){let m=p?.type=="space"?(e.superstate.spacesIndex.get(e.path)?.space).folderPath:e.superstate.spaceManager.parentPathForPath(f.basePath);if(!m)return;console.log(m,e.path,f,e.path,e.source);let g=await e.superstate.spaceManager.createItemAtPath(m,"md",qc(e.path));i(!1),await e.superstate.ui.openPath(g,!1,c,d)}else{i(!0),o(!1);return}o(!0)},l=()=>{e.load?s():r?.current&&(r.current.innerHTML="")};return(0,fl.useEffect)(()=>{l()},[e.load,e.path]),(0,fl.useEffect)(()=>{let u=()=>{r.current&&!r.current.hasChildNodes()&&e.load&&!n&&s()};return e.superstate.ui.eventsDispatch.addListener("activeStateChanged",u),()=>{r.current=null,e.superstate.ui.eventsDispatch.removeListener("activeStateChanged",u)}},[]),fl.default.createElement(fl.default.Fragment,null,fl.default.createElement("div",{className:`${e.classname??""} mk-flowspace-editor`,ref:r,onClick:u=>u.stopPropagation()}),n?fl.default.createElement("div",{onClick:()=>s(!0),className:"mk-placeholder",style:{color:"var(--mk-ui-text-tertiary)"}},z.labels.notePlaceholder.replace("${1}",qc(e.path))):fl.default.createElement(fl.default.Fragment,null))});yd.displayName="FlowView";var y2e=(e,t,r,n,i,a,o,s)=>{let l=[];l.push(Pm(n?.name??"",u=>o(n.name,u))),l.push(Ut),l.push({name:z.menu.changePropertyType,icon:"ui//list",onClick:u=>{s(u,n.name)}}),n.type!="object"&&l.push({name:z.menu.syncToContext,icon:"ui//sync",onClick:u=>{a(n)}}),l.push({name:z.menu.deleteProperty,icon:"ui//trash",onClick:u=>{i(n)}}),e.ui.openMenu(t,Yt(e.ui,l),r)};var os=ge(Te());var b2e=e=>{let{pathState:t}=(0,os.useContext)(Ir),[r,n]=(0,os.useState)({}),[i,a]=(0,os.useState)([]),[o,s]=(0,os.useState)([]),{tableData:l,saveProperty:u,delProperty:c,saveFrame:f}=(0,os.useContext)(aa),d=async()=>{let D=e.superstate.spacesMap.get(t.path)??new Set,P=(await Promise.all([...D].map(async _=>e.superstate.spaceManager.readTable(_,Nr).then(X=>X.cols??[])))).reduce((_,X)=>[..._,...X],[]),R=[],$={},B=t?.metadata?.property??{},N=Gj([...Object.keys(B),...l?.cols?.map(_=>_.name)??[]]).filter(_=>!P.some(X=>X.name==_)),W=N.map(_=>l?.cols?.find(X=>X.name==_)??{table:"",name:_,schemaId:"",type:Uh(B[_],_)});B&&(R.push(...W),N.forEach(_=>{$[_]=Ki(_,B[_])})),a(R.filter(_=>!e.excludeKeys?.some(X=>X==_.name))),s([...e.superstate.settings.hideFrontmatter?P.map(_=>_.name):[]]),n(Vm(e.superstate.formulaContext,e.superstate.pathsIndex,$,W,t))},p=D=>{e.spaces.find(P=>P==D.path)&&d()};(0,os.useEffect)(()=>(d(),e.superstate.eventsDispatcher.addListener("contextStateUpdated",p),()=>{e.superstate.eventsDispatcher.removeListener("contextStateUpdated",p)}),[e.spaces,l]);let h=(D,P)=>{if(u){let R=l?.cols?.find($=>$.name==P.name);R&&u(P,R)}Di(e.superstate,t.path,{[P.name]:Sa(P.type,D,!0)})},m=D=>{c&&D&&c(D),Pye(e.superstate,t.path,D.name)},g=async(D,P)=>{let R={...D,schemaId:Nr},$=e.superstate.spacesIndex.get(P)?.space;!$||(await e.superstate.spaceManager.addSpaceProperty(P,R),await CB(e.superstate.spaceManager,$,t.path,R.name,r[R.name]))},A=(D,P)=>{let R=D.target.getBoundingClientRect(),$=[...e.superstate.spacesMap.get(t.path)].map(B=>e.superstate.pathsIndex.get(B)).filter(B=>B).map(B=>({name:B.name,value:B.path,icon:B.label?.sticker,description:B.path}));e.superstate.ui.openMenu(R,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:$,saveOptions:(B,N)=>{g(P,N[0])},placeholder:z.labels.spaceSelectPlaceholder,detail:!0,searchable:!0,showAll:!0},je(D.view.document),"bottom")},b=(D,P)=>{if(u){let R=l?.cols?.find($=>$.name==D);R&&u({...R,name:P},R)}gG(e.superstate,t.path,D,P)},v=(D,P)=>{if(u){let R=l?.cols?.find($=>$.name==P);R&&u({...R,type:D[0]},R)}Di(e.superstate,t.path,{[P]:rx(D[0])})},x=(D,P)=>{let R=D.target.getBoundingClientRect();e.superstate.ui.openMenu(R,{ui:e.superstate.ui,multi:!1,editable:!1,searchable:!1,saveOptions:($,B)=>v(B,P),value:[],showAll:!0,options:Xs.filter($=>$.metadata).map(($,B)=>({id:B+1,name:$.label,value:$.type,icon:$.icon}))},je(D.view.document))},[w,S]=(0,os.useState)(null),[k,M]=(0,os.useState)(null),O=()=>{M(null),S(null)};Vo({onDragStart({active:D}){D.data.current.type=="property"&&S(D.data.current.property)},onDragOver({active:D,over:P}){let R=P?.data.current.id;P?.data.current.type=="property"&&R&&M(R)},onDragCancel(){O()},onDragEnd({active:D,over:P}){if(!D||!k){O();return}O()}});let C=(D,P)=>{if(u){let R=l?.cols?.find($=>$.name==P.name);R&&u(D,R)}D.name!=P.name&&gG(e.superstate,t.path,P.name,D.name)},T=(D,P)=>{let R=D.target.getBoundingClientRect();if(t.type=="space"){Lm({superstate:e.superstate,rect:R,win:je(D.view.document),editable:!0,options:[],field:P,fields:i,contextPath:null,saveField:$=>C($,P),deleteColumn:m,anchor:"bottom"});return}y2e(e.superstate,R,je(D.view.document),P,m,()=>A(D,P),b,x)};return os.default.createElement(os.default.Fragment,null,e.compactMode?i.map((D,P)=>os.default.createElement(as,{key:P,path:t.path,propertyMenu:R=>T(R,D),superstate:e.superstate,initialValue:r[D.name],row:r,compactMode:e.compactMode,column:{...D,table:""},columns:[],editMode:e.editable?5:2,updateValue:R=>h(R,D),updateFieldValue:(R,$)=>h($,{...D,value:R}),contextTable:{},source:t.path})):e.force?i.map((D,P)=>os.default.createElement(as,{key:P,path:t.path,propertyMenu:R=>T(R,D),superstate:e.superstate,initialValue:r[D.name],row:r,compactMode:e.compactMode,column:{...D,table:""},columns:[],editMode:e.editable?5:2,updateValue:R=>h(R,D),updateFieldValue:(R,$)=>h($,{...D,value:R}),contextTable:{},source:t.path})):os.default.createElement(os.default.Fragment,null),o.length>0&&os.default.createElement("style",null,`${o.map(D=>`.metadata-property[data-property-key="${D}"]`).join(", ")} { display: none; }`))};var Ul=ge(Te());var J0={isEmpty:z.filterTypes.isEmpty,isNotEmpty:z.filterTypes.isNotEmpty,include:z.filterTypes.contains,notInclude:z.filterTypes.notContains,is:z.filterTypes.is,isNot:z.filterTypes.isNot,isLink:z.filterTypes.is,isNotLink:z.filterTypes.isNot,equal:"=",isGreatThan:">",isLessThan:"<",isLessThanOrEqual:"\u2264",isGreatThanOrEqual:"\u2265",dateBefore:z.filterTypes.before,dateAfter:z.filterTypes.after,isSameDate:z.filterTypes.isSameDate,isSameDateAsToday:z.filterTypes.isSameDateAsToday,isExactList:z.filterTypes.is,isAnyInList:z.filterTypes.anyOf,isNoneInList:z.filterTypes.noneOf,isTrue:z.filterTypes.checked,isFalse:z.filterTypes.unchecked};var yi=ge(Te());var C2e=ge($a());var E5=(e,t,r,n,i,a)=>{if(!!n&&n.type!="text"){if(n.type=="number"){let o=Pm("",s=>i(s));r.ui.openMenu(e,{...Yt(r.ui,[o])},t)}else if(n.type=="date")Y0(r.ui,e,t,new Date,o=>i(o.toISOString()),0);else if(n.type=="option"){let o=Lr(n.value,n.type,r,a)?.options??[];r.ui.openMenu(e,{...Yt(r.ui,o),saveOptions:(s,l)=>{i(l[0])}},t)}else if(n.type=="boolean"){let o=[{name:"Yes",value:"true"},{name:"No",value:"false"}];r.ui.openMenu(e,{...Yt(r.ui,o),saveOptions:(s,l)=>{i(l[0])}},t)}}};var Xt=ge(Te());var YYe=(e,t)=>e.type=="folder"?`${e.path}/#*${t}`:e.type=="vault"?`/#*${t}`:`${e.path}/#*${t}`,rQ=(e,t)=>e.type=="folder"?`${e.path}/#;${t}`:e.type=="vault"?`/#;${t}`:`${e.path}/#;${t}`,by=(e,t)=>e.type=="folder"?`${e.path}/#^${t}`:e.type=="vault"?`/#^${t}`:`${e.path}/#^${t}`,k5=(e,t)=>`![![${YYe(e,t)}]]`,C5=(e,t)=>`![![${by(e,t)}]]`;var ev=ge(Te());var x2e=e=>{let{dbSchema:t,source:r}=(0,ev.useContext)(ts),n=u=>{e.superstate.ui.openPalette(ev.default.createElement(va,{ui:e.superstate.ui,selectedSticker:c=>e.superstate.spaceManager.saveTableSchema(r,t.id,()=>({...t,def:JSON.stringify({...dr(t?.def)??{},icon:c})}))}),je(u.view.document))},i=t?.name,a=u=>{let c=u.target.innerText;c!=i&&e.superstate.spaceManager.saveTableSchema(r,t.id,()=>({...t,name:c}))},o=u=>{u.stopPropagation()},s=u=>{u.stopPropagation()},l=u=>{if(u.stopPropagation(),u.key=="a"&&u.metaKey){u.preventDefault();let c=window.getSelection(),f=document.createRange();f.selectNodeContents(u.target),c.removeAllRanges(),c.addRange(f)}u.key=="Enter"&&(u.target.blur(),u.preventDefault()),u.key=="Escape"&&(u.target.blur(),u.preventDefault())};return ev.default.createElement("div",{className:"mk-context-title"},ev.default.createElement("div",{className:"mk-path-icon",onClick:u=>n(u),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker(mJ(t))}}),ev.default.createElement("div",{contentEditable:!0,dangerouslySetInnerHTML:{__html:t?.name},onBlur:a,onKeyPress:o,onKeyUp:s,onKeyDown:l}),ev.default.createElement("button",{className:"mk-toolbar-button",onClick:()=>e.superstate.ui.openPath(by(e.superstate.spacesIndex.get(r),t.id)),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//expand")}}))};var w2e=ge(Te()),S2e=e=>w2e.default.createElement("div",{onClick:t=>e.onSelect(t),onContextMenu:t=>e.onContextMenu(t,e.schema),className:`mk-context ${e.active?"mk-active":""}`},Hj(e.schema.name,"Untitled"),e.children);var E2e=ge(Te()),bc=e=>E2e.default.createElement("button",{className:`mk-collapse ${e.collapsed?"mk-collapsed":""}`,onClick:t=>{!e.onToggle||(t.stopPropagation(),e.onToggle(!e.collapsed,t))},dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//collapse")}});var Is=ge(Te());var k2e=e=>{let{views:t,dbSchema:r,source:n}=(0,Is.useContext)(ts),{readMode:i}=(0,Is.useContext)(Ir),{spaceState:a}=(0,Is.useContext)(lr),{frameSchema:o,setFrameSchema:s,saveSchema:l,deleteSchema:u}=(0,Is.useContext)(aa),c=(m,g)=>{let A=[];A.push({name:z.menu.copyEmbedLink,icon:"ui//link",onClick:b=>{navigator.clipboard.writeText(k5(a,g.id))}}),A.push({name:z.buttons.renameView,icon:"ui//edit",onClick:b=>{e.superstate.ui.openModal(z.labels.renameView,Is.default.createElement(ji,{value:g.name,saveLabel:z.labels.renameView,saveValue:v=>l({...g,name:v})}),je(b.view.document))}}),t.length>1&&A.push({name:z.buttons.delete,icon:"ui//trash",onClick:b=>{o.id==g.id&&e.setView&&(t[0].id==g.id?(e.setView(t[1].id),s(t[1])):(e.setView(t[0].id),s(t[0]))),u(g)}}),e.superstate.ui.openMenu(m.target.getBoundingClientRect(),Yt(e.superstate.ui,A),je(m.view.document))},f=m=>{s(t.find(g=>g.id==m)),e.setView&&e.setView(m)},d=(0,Is.useRef)(null),p=m=>{e.superstate.ui.openModal(z.labels.saveView,Is.default.createElement(ji,{value:"",saveLabel:z.labels.saveView,saveValue:g=>{let A={...o??{name:r.name,def:{db:r.id},type:"view"},id:g.replace(/ /g,"_"),name:g};l(A).then(b=>f(A.id))}}),je(m.view.document))},h=m=>{let g=[];(t??[]).forEach(A=>{g.push({name:Hj(A.name,"Untitled"),value:A.id,icon:ux(A),onClick:()=>f(A.id),onMoreOptions:i?null:b=>c(b,A)})}),i||(g.push(Ut),g.push({name:z.menu.newView,icon:"ui//plus",value:"",onClick:A=>p(A)})),e.superstate.ui.openMenu(m.target.getBoundingClientRect(),Yt(e.superstate.ui,g),je(m.view.document),"bottom")};return r&&(o?Is.default.createElement(Is.default.Fragment,null,Is.default.createElement("div",{className:"mk-view-selector",ref:d},t.map((m,g)=>Is.default.createElement(S2e,{key:g,active:o.id==m.id,superstate:e.superstate,schema:m,onSelect:()=>s(t.find(A=>A.id==m.id)),onContextMenu:c})),Is.default.createElement("button",{className:"mk-toolbar-button",onClick:m=>p(m),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}}))):Is.default.createElement("div",{onClick:m=>h(m),className:"mk-context"},Is.default.createElement("div",{className:"mk-path-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//table")}}),r.name,Is.default.createElement(bc,{collapsed:!1,onToggle:null,superstate:e.superstate})))};var Mp=ge(Te()),D5=e=>{let[t,r]=Mp.default.useState(!1),n=()=>{r(!1),e.setSearchString("")},i=Mp.default.useRef(null);return(0,Mp.useEffect)(()=>{t&&i.current?.focus()},[t]),Mp.default.createElement("div",{className:"mk-view-search"},Mp.default.createElement("button",{className:"mk-toolbar-button",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//search")}}),Mp.default.createElement(Mp.default.Fragment,null,Mp.default.createElement("input",{onChange:a=>e.setSearchString(a.target.value),placeholder:z.labels.searchPlaceholder,className:"mk-search-bar",ref:i}),e.closeSearch&&Mp.default.createElement("button",{className:"mk-toolbar-button",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//clear")},onClick:a=>{a.stopPropagation(),n(),e.closeSearch()}})))};var j5=e=>{let{spaceState:t}=(0,Xt.useContext)(lr),{readMode:r}=(0,Xt.useContext)(Ir),{source:n,dbSchema:i,cols:a,setSearchString:o,setEditMode:s,predicate:l,savePredicate:u,hideColumn:c,delColumn:f,saveColumn:d}=(0,Xt.useContext)(ts),{frameSchema:p,saveSchema:h,setFrameSchema:m}=(0,Xt.useContext)(aa),[g,A]=(0,Xt.useState)(!1),b=t?.propertyTypes??[],v=async se=>{if(!se)return[];let L=e.superstate.spaceManager.uriByString(se);if(L.authority=="$kit"){let ue=e.superstate.kitFrames.get(L.ref).node;return Object.keys(ue.types).map(ce=>({type:ue.types[ce],name:ce,attrs:JSON.stringify(ue.propsAttrs?.[ce]),schemaId:ue.schemaId,value:JSON.stringify(ue.propsValue?.[ce])})).filter(ce=>!ce.name.startsWith("_"))}else return e.superstate.spaceManager.readFrame(L.path,L.ref).then(ue=>ue?.cols.filter(ce=>!ce.name.startsWith("_"))??[])},x=a.filter(se=>se.hidden!="true"),[w,S]=(0,Xt.useState)(!1),k=se=>{se=="table"&&u({view:"table",listView:"",listGroup:"",listItem:""}),se=="flow"&&u({view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*listGroup",listItem:"spaces://$kit/#*flowListItem"}),se=="list"&&u({view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*listGroup",listItem:"spaces://$kit/#*rowItem"}),se=="details"&&u({view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*listGroup",listItem:"spaces://$kit/#*detailItem"}),se=="board"&&u({view:"list",listView:"spaces://$kit/#*columnView",listGroup:"spaces://$kit/#*columnGroup",listItem:"spaces://$kit/#*cardListItem"}),se=="cards"&&u({view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*gridGroup",listItem:"spaces://$kit/#*cardsListItem"}),se=="catalog"&&u({view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*rowGroup",listItem:"spaces://$kit/#*coverListItem"}),se=="gallery"&&u({view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*masonryGroup",listItem:"spaces://$kit/#*imageListItem"}),se=="calendar"&&u({view:"list",listView:"spaces://$kit/#*calendarView",listGroup:"spaces://$kit/#*dateGroup",listItem:"spaces://$kit/#*eventItem"})},M=()=>{u({filters:[],sort:[]})},O=()=>{u({colsHidden:[]})},C=(se,L)=>{let ce=[...(l??Y6(i)).filters.filter((U,q)=>q!=L)];u({filters:ce})},T={table:{name:z.menu.tableView,icon:"ui//table",view:"table",listView:"",listGroup:"",listItem:""},list:{name:z.menu.listView,icon:"ui//list",view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*listGroup",listItem:"spaces://$kit/#*rowItem"},details:{name:z.menu.detailsView,icon:"ui//layout-grid",view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*listGroup",listItem:"spaces://$kit/#*detailItem"},board:{name:z.menu.boardView,icon:"ui//square-kanban",view:"list",listView:"spaces://$kit/#*columnView",listGroup:"spaces://$kit/#*columnGroup",listItem:"spaces://$kit/#*cardListItem"},cards:{name:z.menu.cardView,icon:"ui//layout-dashboard",view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*gridGroup",listItem:"spaces://$kit/#*cardsListItem"},catalog:{name:z.menu.catalogView,icon:"ui//gallery-horizontal-end",view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*rowGroup",listItem:"spaces://$kit/#*coverListItem"},gallery:{name:z.menu.galleryView,icon:"ui//layout-dashboard",view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*masonryGroup",listItem:"spaces://$kit/#*imageListItem"},flow:{name:z.menu.flowView,icon:"ui//edit",view:"list",listView:"spaces://$kit/#*listView",listGroup:"spaces://$kit/#*listGroup",listItem:"spaces://$kit/#*flowListItem"}},D=se=>{let L=se.target.getBoundingClientRect(),ue=[];return Object.keys(T).forEach(ce=>{let U=T[ce];ue.push({name:U.name,icon:U.icon,onClick:q=>{u({view:U.view,listView:U.listView,listGroup:U.listGroup,listItem:U.listItem})}})}),e.superstate.settings.experimental&&ue.push({name:z.menu.customView,icon:"ui//brush",onClick:ce=>{s(3)}}),e.superstate.ui.openMenu(L,Yt(e.superstate.ui,ue),je(se.view.document))},P=(se,L)=>Wa(se,L,e.superstate,ue=>{let ce={...p,name:p.name,def:{db:i.id,context:ue},type:"view"};h(ce).then(U=>m(ce))}),R=async se=>{let L=[];if(r||(L.push(Pm(p.name??"",Y=>h({...p,name:Y}))),L.push(Ut),L.push({name:z.menu.properties,icon:"ui//list",type:6,onSubmenu:(Y,te)=>Re(Y,je(se.view.document),te)})),L.push({name:z.menu.groupBy,icon:"ui//columns",type:6,onSubmenu:(Y,te)=>_e(Y,je(se.view.document),te)}),L.push({name:z.menu.sortBy,icon:"ui//sort-desc",type:6,onSubmenu:(Y,te)=>re(Y,je(se.view.document),te)}),L.push({name:z.menu.filters,icon:"ui//filter",type:6,onSubmenu:(Y,te)=>oe(Y,je(se.view.document),te)}),L.push(Ut),i?.primary=="true"){let Y=e.superstate.spacesIndex.get(n);L.push({name:"Source",icon:"ui//table",type:1,value:Y.name,onSubmenu:(te,ie)=>P(te,je(se.view.document))}),L.push({name:z.labels.contexts,icon:"ui//tags",type:6,onSubmenu:(te,ie)=>Oe(te,je(se.view.document),ie)}),L.push(Ut)}let ue=await v(l?.listView),ce=await v(l?.listGroup),U=await v(l?.listItem),q=(Y,te,ie)=>{u({[Y]:{...l[Y],[te]:ie}})};ue.forEach(Y=>{L.push({name:Ds(Y,e.superstate),icon:Li(Y),type:1,onClick:te=>{E5(te.target.getBoundingClientRect(),je(te.view.document),e.superstate,Y,ie=>q("listViewProps",Y.name,Sa(Y.type,ie,!0)),t.path)}})}),ce.forEach(Y=>{L.push({name:Ds(Y,e.superstate),icon:Li(Y),type:1,onClick:te=>{E5(te.target.getBoundingClientRect(),je(te.view.document),e.superstate,Y,ie=>q("listGroupProps",Y.name,Sa(Y.type,ie,!0)),t.path)}})}),U.forEach(Y=>{L.push({name:Ds(Y,e.superstate),icon:Li(Y),type:1,onClick:te=>{E5(te.target.getBoundingClientRect(),je(te.view.document),e.superstate,Y,ie=>q("listItemProps",Y.name,Sa(Y.type,ie,!0)),t.path)}})});let ee=se.target.getBoundingClientRect();e.superstate.ui.openMenu(ee,Yt(e.superstate.ui,L),je(se.view.document))},$=(se,L)=>{let ue=L[0],ce=x.find(q=>q.name+q.table==ue),U=Hu(ce);if(U){let q=JG(U,kp),ee={field:ue,fn:q};u({sort:[...l?.sort.filter(Y=>Y.field!=ee.field)??[],ee]})}},B=(se,L)=>{u({groupBy:L})},N=se=>{let L=[...(l?.sort??[]).filter(ue=>ue.field!=se.field)];u({sort:L})},W=se=>{let L=x.find(ce=>ce.name+ce.table==se),ue=Hu(L);if(ue){let ce=JG(ue,_i);if(!ce)return;let U=ue=="boolean"?{field:se,fn:ce,fType:_i[ce].valueType,value:"true"}:{field:se,fn:ce,fType:_i[ce].valueType,value:""};u({filters:[...l?.filters??[],U]})}},_=(se,L)=>{let ue=se.target.getBoundingClientRect(),ce=(Y,te)=>{let ie=te[0],Se={...L,fn:ie};u({sort:[...(l?.sort??[]).filter(ke=>ke.field!=Se.field),Se]})},U=x.find(Y=>Y.name+Y.table==L.field),q=Hu(U),ee=M2(q,kp);e.superstate.ui.openMenu(ue,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:ee.map(Y=>({name:kp[Y].label,value:Y})),saveOptions:ce,placeholder:z.labels.sortItemSelectPlaceholder,searchable:!1,showAll:!0},je(se.view.document))},X=(se,L,ue)=>{let ce=se.target.getBoundingClientRect(),U=(te,ie)=>{let Se=ie[0],ke={...L,fn:Se,fType:_i[Se].valueType};u({filters:(l?.filters??[]).map((Me,me)=>me==ue?ke:Me)})},q=x.find(te=>te.name+te.table==L.field),ee=Hu(q),Y=M2(ee,_i);e.superstate.ui.openMenu(ce,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:Y.map(te=>({name:J0[te],value:te})),saveOptions:U,placeholder:z.labels.filterItemSelectPlaceholder,searchable:!1,showAll:!0},je(se.view.document))},oe=(se,L,ue)=>{let ce=x.filter(U=>U.type=="fileprop"||M2(U.type,_i).length>0).map(U=>({name:U.name+U.table,value:U.name+U.table,icon:Li(U),onClick:q=>{W(U.name+U.table)}}));return ce.push(Ut),ce.push({name:z.menu.clearFilters,icon:"ui//x-square",onClick:U=>{M()}}),e.superstate.ui.openMenu(se,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:ce,placeholder:z.labels.propertyItemSelectPlaceholder,searchable:!0,showAll:!0},L,null,ue)},re=(se,L,ue)=>e.superstate.ui.openMenu(se,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:x.map(ce=>({name:ce.name+ce.table,icon:Li(ce),value:ce.name+ce.table})),saveOptions:$,placeholder:z.labels.sortItemSelectPlaceholder,searchable:!0,showAll:!0},L,"right",ue),Q=(se,L)=>{if(se.name.length>0&&(se.name!=L.name||se.type!=L.type||se.value!=L.value||se.attrs!=L.attrs)){let ue=d(se,L)}},he=(se,L)=>d({...L,table:""}),Ie=(se,L)=>{let ue=e.superstate.spacesIndex.get(se);of(e.superstate,ue.space,{...ue.metadata,contexts:L})},xe=(se,L,ue)=>{let ce=e.superstate.spacesIndex.get(n),U=e.superstate.spaceManager.readTags(),q=async ee=>{let Y=px(ee);Ie(ce.path,[...ce.metadata.contexts.filter(te=>te!=Y),Y])};return e.superstate.ui.openMenu(se,{ui:e.superstate.ui,multi:!1,editable:!0,value:[],options:U.map(ee=>({name:ee,value:ee})),saveOptions:(ee,Y)=>q(Y[0]),placeholder:z.labels.contextItemSelectPlaceholder,searchable:!0,showAll:!0},L,null,ue)},Oe=(se,L,ue)=>{let ce=[];ce.push({name:z.buttons.addContext,icon:"ui//plus",type:6,onSubmenu:(q,ee)=>xe(q,L,ee)}),ce.push(Ut);let U=e.superstate.spacesIndex.get(n);return U.contexts.forEach(q=>{ce.push({name:q,icon:"ui//tags",onClick:ee=>{e.superstate.ui.openPath(If(q))},onMoreOptions:ee=>{let Y=ee.target.getBoundingClientRect(),te=[];return te.push({name:z.menu.deleteContext,icon:"ui//trash",onClick:ie=>{Ie(U.path,U.contexts.filter(Se=>Se!=q))}}),e.superstate.ui.openMenu(Y,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:te,placeholder:z.labels.contextItemSelectPlaceholder,searchable:!1,showAll:!0},L)}})}),e.superstate.ui.openMenu(se,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:ce,placeholder:z.labels.contextItemSelectPlaceholder,searchable:!1,showAll:!0},L,null,ue)},Re=(se,L,ue)=>{let ce=(q,ee,Y)=>Lm({superstate:e.superstate,rect:ee,editable:q.primary!="true",win:L,options:[],field:q,fields:x,contextPath:t.path,saveField:te=>Q(te,q),hide:c,deleteColumn:f,hidden:l?.colsHidden.includes(q.name+q.table)},Y,!0),U=[];return U.push({name:z.labels.newProperty,icon:"ui//plus",type:6,onSubmenu:(q,ee)=>uf(e.superstate,q,L,{spaces:[],fields:[],saveField:he,schemaId:i.id,contextPath:t.path},ee)}),U.push(Ut),U.push(...x.filter(q=>l.colsHidden.some(ee=>ee==q.name+q.table)==!1).map(q=>({name:q.name+q.table,icon:Li(q),value:q.name+q.table,type:6,onSubmenu:(ee,Y)=>ce(q,ee,Y)}))),U.push(Ut),U.push(...x.filter(q=>l.colsHidden.some(ee=>ee==q.name+q.table)).map(q=>({name:q.name+q.table,icon:Li(q),value:q.name+q.table,type:6,onSubmenu:(ee,Y)=>ce(q,ee,Y)}))),U.push(Ut),U.push({name:z.menu.unhideFields,icon:"ui//eye",onClick:q=>{O()}}),e.superstate.ui.openMenu(se,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:U,placeholder:z.labels.propertyItemSelectPlaceholder,searchable:!1,showAll:!0},L,"right",ue)},_e=(se,L,ue)=>e.superstate.ui.openMenu(se,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:x.map(ce=>({name:ce.name+ce.table,icon:Li(ce),value:ce.name+ce.table})),saveOptions:B,placeholder:z.labels.propertyItemSelectPlaceholder,searchable:!1,showAll:!0},L,"right",ue),we=(se,L,ue)=>{switch(L.fType??_i[L.fn].valueType){case"property":u({filters:(l?.filters??[]).map((ce,U)=>U==ue?L:ce)});break;case"text":case"number":u({filters:(l?.filters??[]).map((ce,U)=>U==ue?L:ce)});break;case"date":{let ce=ee=>{let Y={...L,value:ee?Qu(e.superstate,ee):""};u({filters:(l?.filters??[]).map((te,ie)=>ie==ue?Y:te)})},U=se.target.getBoundingClientRect(),q=new Date(L.value);Y0(e.superstate.ui,U,je(se.view.document),q.getTime()?q:null,ce,0);break}case"link":{let ce=a.find(ee=>ee.name+ee.table==L.field);if(ce?.type.startsWith("context")){let ee=Lr(ce.value,ce.type)?.space;if(!ee)return;let Y=e.superstate.getSpaceItems(ee)??[],te=se.target.getBoundingClientRect();e.superstate.ui.openMenu(te,{ui:e.superstate.ui,multi:!1,editable:!1,value:mr(L.value),options:Y.map(ie=>({name:ie.name,value:ie.path}))??[],saveOptions:(ie,Se)=>{let ke={...L,value:Se[0]};u({filters:(l?.filters??[]).map((Me,me)=>me==ue?ke:Me)})},placeholder:z.labels.optionItemSelectPlaceholder,searchable:!0,showAll:!0},je(se.view.document));return}let U=ee=>{let Y={...L,value:ee};u({filters:(l?.filters??[]).map((te,ie)=>ie==ue?Y:te)})},q=se.target.getBoundingClientRect();Ns(q,je(se.view.document),e.superstate,ee=>{U(ee)},{multi:!0}),se.stopPropagation()}break;case"list":{let ce=a.find(q=>q.name+q.table==L.field),U=(q,ee)=>{let Y={...L,value:Ni(ee)};u({filters:(l?.filters??[]).map((te,ie)=>ie==ue?Y:te)})};if(ce.type.startsWith("option")){let q=se.target.getBoundingClientRect(),ee=Lr(ce.value,ce.type).options;e.superstate.ui.openMenu(q,{ui:e.superstate.ui,multi:!0,editable:!1,value:mr(L.value),options:ee??[],saveOptions:U,placeholder:z.labels.optionItemSelectPlaceholder,searchable:!0,showAll:!0},je(se.view.document))}else if(ce.type.startsWith("context")){let q=Lr(ce.value,ce.type)?.space;if(!q)return;let ee=e.superstate.getSpaceItems(q)??[],Y=se.target.getBoundingClientRect();e.superstate.ui.openMenu(Y,{ui:e.superstate.ui,multi:!0,editable:!1,value:mr(L.value),options:ee.map(te=>({name:te.name,value:te.path}))??[],saveOptions:U,placeholder:z.labels.optionItemSelectPlaceholder,searchable:!0,showAll:!0},je(se.view.document))}else if(ce.type.startsWith("link")){let q=se.target.getBoundingClientRect();Ns(q,je(se.view.document),e.superstate,ee=>{U([ee],[ee])},{multi:!0}),se.stopPropagation()}else if(ce.type.startsWith("tags")){let q=e.superstate.spaceManager.readTags(),ee=se.target.getBoundingClientRect();e.superstate.ui.openMenu(ee,{ui:e.superstate.ui,multi:!0,editable:!1,value:mr(L.value),options:q.map(Y=>({name:Y,value:Y}))??[],saveOptions:U,placeholder:z.labels.tagItemSelectPlaceholder,searchable:!0,showAll:!0},je(se.view.document))}}break}};return Xt.default.createElement(Xt.default.Fragment,null,e.minMode?Xt.default.createElement("div",{className:"mk-view-config"},Xt.default.createElement(D5,{superstate:e.superstate,setSearchString:o,closeSearch:()=>A(!1)}),Xt.default.createElement("button",{className:"mk-toolbar-button",onClick:se=>{let L=se.target.getBoundingClientRect();re(L,je(se.view.document),null)},dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//sort-desc")}}),Xt.default.createElement("button",{className:"mk-toolbar-button",onClick:se=>{let L=se.target.getBoundingClientRect();oe(L,je(se.view.document),null)},dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//filter")}})):Xt.default.createElement(Xt.default.Fragment,null,e.showTitle&&Xt.default.createElement("div",{className:"mk-context-config"},Xt.default.createElement(x2e,{superstate:e.superstate}),Xt.default.createElement("span",null),i?.id==Nr&&!t.space.readOnly&&Xt.default.createElement(Xt.default.Fragment,null,Xt.default.createElement("button",{className:"mk-button-new",onClick:se=>NB(e.superstate,se.target.getBoundingClientRect(),je(se.view.document),t,!0),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}}))),Xt.default.createElement("div",{className:"mk-view-config"},!w&&Xt.default.createElement(k2e,{superstate:e.superstate,expanded:!1,setView:e.setView}),Xt.default.createElement("div",{className:"mk-view-options"},Xt.default.createElement("span",null),(tc(e.superstate.ui)||!g)&&Xt.default.createElement("button",{className:(0,C2e.default)("mk-toolbar-button",g&&"mk-active"),onClick:se=>{se.stopPropagation(),A(L=>!L)},dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//search")}}),!tc(e.superstate.ui)&&g&&Xt.default.createElement(D5,{superstate:e.superstate,setSearchString:o,closeSearch:()=>A(!1)}),Xt.default.createElement("button",{className:"mk-toolbar-button",onClick:se=>D(se),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//layout")}}),Xt.default.createElement("button",{className:"mk-toolbar-button",onClick:se=>R(se),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//view-options")}}))),tc(e.superstate.ui)&&g&&Xt.default.createElement(D5,{superstate:e.superstate,setSearchString:o})),(l?.filters.length>0||l?.sort.length>0||l?.groupBy.length>0)&&Xt.default.createElement("div",{className:"mk-filter-bar"},l.groupBy.length>0&&Xt.default.createElement("div",{className:"mk-filter"},Xt.default.createElement("span",null,z.menu.groupBy),Xt.default.createElement("span",{onClick:se=>_e(se.target.getBoundingClientRect(),je(se.view.document),null)},l.groupBy[0]),Xt.default.createElement("div",{onClick:()=>B(null,[]),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//close")}})),(l?.sort??[]).map((se,L)=>Xt.default.createElement("div",{key:L,className:"mk-filter"},Xt.default.createElement("span",null,se.field),Xt.default.createElement("span",{onClick:ue=>_(ue,se)},kp[se.fn].label),Xt.default.createElement("div",{onClick:()=>N(se),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//close")}}))),(l?.filters??[]??[]).map((se,L)=>Xt.default.createElement("div",{key:L,className:"mk-filter"},Xt.default.createElement("span",null,se.field),Xt.default.createElement("span",{onClick:ue=>X(ue,se,L)},J0[se.fn]),Xt.default.createElement(nQ,{superstate:e.superstate,fieldType:a.find(ue=>ue.name+ue.table==se.field)?.type,filter:se,selectFilterValue:(ue,ce)=>we(ue,ce,L)}),b.length>0&&Xt.default.createElement("span",{onClick:ue=>{ue.stopPropagation(),e.superstate.ui.openMenu(ue.currentTarget.getBoundingClientRect(),{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:b.map(ce=>({name:ce.name,value:ce.name,section:ce.type})),saveOptions:(ce,U)=>we(ue,{...se,fType:"property",value:U[0]},L),placeholder:z.labels.contextItemSelectPlaceholder,searchable:!0,showAll:!0,sections:[],showSections:!1},je(ue.view.document))}},Xt.default.createElement("div",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plug")}})),Xt.default.createElement("div",{onClick:()=>C(se,L),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//close")}}))),(l?.filters??[]).length>0&&Xt.default.createElement("div",{className:"mk-filter-add",onClick:se=>{let L=se.target.getBoundingClientRect();oe(L,je(se.view.document),null)}},Xt.default.createElement("span",null,Xt.default.createElement("span",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}}),z.buttons.addFilter)),Xt.default.createElement("span",null)))},nQ=e=>{let{filter:t,selectFilterValue:r,fieldType:n}=e,i=_i[t.fn],[a,o]=(0,Xt.useState)(t.value);if((0,Xt.useEffect)(()=>o(t.value),[t.value]),t.fType=="property")return Xt.default.createElement("span",null,t.value);if(!n||!i||i.valueType=="none")return Xt.default.createElement(Xt.default.Fragment,null);if(i.valueType=="text"||i.valueType=="number")return Xt.default.createElement("input",{type:"text",onChange:s=>o(s.currentTarget.value),onBlur:s=>{r(null,{...t,value:a})},onKeyDown:s=>{s.key=="Escape"&&(o(t.value),s.currentTarget.blur()),s.key=="Enter"&&s.currentTarget.blur()},value:a});if(n.startsWith("option")||n.startsWith("context")||n.startsWith("link")||n.startsWith("tag")){let s=mr(t.value);return Xt.default.createElement("span",{onClick:l=>r(l,t)},s.length==0?z.labels.select:s.map((l,u)=>n.startsWith("option")?Xt.default.createElement("span",{key:u},l):Xt.default.createElement(ns,{superstate:e.superstate,key:u,path:l})))}else if(!t.value||t.value.length==0)return Xt.default.createElement("span",{onClick:s=>r(s,t)},z.labels.select);return Xt.default.createElement("span",{onClick:s=>r(s,t)},t.value)};var L2=e=>{(0,yi.useEffect)(()=>{e.superstate.refreshMetadata()},[]);let{filters:t,setFilters:r}=e,n=(h,m,g,A)=>{let b=v=>{l(v,g,A)};if(m.fType=="property"){r(t.map((v,x)=>g==x?{...v,filters:v.filters.map((w,S)=>A==S?{...w,fType:"property",value:m.value}:w)}:v));return}switch(_i[m.fn]?.valueType){case"text":case"number":b(m.value);break;case"date":{let v=S=>{b(Pa(S,"yyyy-MM-dd"))},x=h.target.getBoundingClientRect(),w=new Date(m.value);Y0(e.superstate.ui,x,je(h.view.document),w.getTime()?w:null,v,0);break}case"link":{let v=w=>{b(w)},x=h.target.getBoundingClientRect();Ns(x,je(h.view.document),e.superstate,v),h.stopPropagation();break}case"space":{let v=w=>{b(w)},x=h.target.getBoundingClientRect();Wa(x,je(h.view.document),e.superstate,v);break}case"list":{let v=m.fType,x=(k,M)=>{b(Ni(M))},w=[];v.startsWith("option")?w=mr(m.value).map(k=>({name:k,value:k})):v.startsWith("tags")?w=e.superstate.spaceManager.readTags().map(k=>({value:k,name:k})):v.startsWith("link")&&(w=e.superstate.spaceManager.allPaths().map(k=>({name:ox(k),value:k,description:k})));let S=h.target.getBoundingClientRect();e.superstate.ui.openMenu(S,{ui:e.superstate.ui,multi:!0,editable:!0,value:mr(m.value),options:w,saveOptions:x,placeholder:z.labels.optionItemSelectPlaceholder,searchable:!1,showAll:!0},je(h.view.document))}break}},i=()=>{r(h=>[...h,{type:"any",trueFalse:!0,filters:[]}])},a=h=>{r(t.filter((m,g)=>g!=h))},o=(h,m,g)=>{if(!!h){if(t.length==0){r([{type:"all",trueFalse:!0,filters:[{type:h.type,field:h.field,fType:h.vType,fn:h.defaultFilter,value:""}]}]);return}if(t[m]?.filters.length==0){r(t.map((A,b)=>b==m?{...A,filters:[{type:h.type,field:h.field,fType:h.vType,fn:h.defaultFilter,value:""}]}:A));return}r(t.map((A,b)=>b==m?{...A,filters:!A.filters||g==A.filters.length?[...A.filters??[],{type:h.type,field:h.field,fType:h.vType,fn:h.defaultFilter,value:""}]:A.filters.map((v,x)=>x==g?{...v,type:h.type,field:h.field,fType:h.vType,fn:h.defaultFilter}:v)}:A))}},s=(h,m,g)=>{r(t.map((A,b)=>b==m?{...A,filters:A.filters.map((v,x)=>x==g?{...v,fn:h}:v)}:A))},l=(h,m,g)=>{r(t.map((A,b)=>b==m?{...A,filters:A.filters.map((v,x)=>x==g?{...v,value:h}:v)}:A))},u=(h,m)=>{r(t.map((g,A)=>A==m?{...g,filters:g.filters.filter((b,v)=>v!=h)}:g))},c=(h,m)=>{h==0&&t.length==0?r([{type:m,trueFalse:!0,filters:[]}]):r(t.map((g,A)=>A==h?{...g,type:m}:g))},f=(h,m)=>{let g=h.target.getBoundingClientRect(),A=["any","all"];e.superstate.ui.openMenu(g,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:A.map(b=>({name:b=="any"?"or":"and",value:b})),saveOptions:(b,v)=>c(m,v[0]),searchable:!1,showAll:!0},je(h.view.document))},d=(h,m,g)=>{let A=h.target.getBoundingClientRect(),{type:b,field:v,fType:x}=t[m].filters[g],w=x=="any"?pxe(_i):M2(x,_i);e.superstate.ui.openMenu(A,{ui:e.superstate.ui,multi:!1,editable:!0,value:[],options:w.map(S=>({name:J0[S],value:S})),saveOptions:(S,k)=>s(k[0],m,g),placeholder:z.labels.contextItemSelectPlaceholder,searchable:!0,showAll:!0},je(h.view.document))},p=async(h,m,g)=>{let A=h.target.getBoundingClientRect();e.superstate.ui.openMenu(A,{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:e.fields.map(b=>({name:b.label,value:b,section:b.type,description:b.description})),saveOptions:(b,v)=>o(v[0],m,g),placeholder:z.labels.contextItemSelectPlaceholder,searchable:!0,showAll:!0,sections:e.sections,showSections:!0},je(h.view.document))};return yi.default.createElement("div",{className:"mk-query"},t.length==0?yi.default.createElement(D2e,{superstate:e.superstate,selectGroupType:f,group:null,addDefGroup:i,selectField:p,i:0,removeable:e.removeable,removeDefGroup:a}):t.map((h,m)=>yi.default.createElement(D2e,{superstate:e.superstate,key:m,group:h,selectGroupType:f,addDefGroup:i,selectField:p,removeable:e.removeable,i:m,removeDefGroup:a},h.filters.map((g,A,b)=>yi.default.createElement(yi.default.Fragment,{key:A},yi.default.createElement(ZYe,{superstate:e.superstate,key:A,filter:g,i:m,k:A,selectField:p,selectFilter:d,selectFilterValue:n,removeDefFilter:u,linkProps:e.linkProps}),A!=b.length-1&&yi.default.createElement("div",{className:"mk-filter",onClick:v=>f(v,m)},yi.default.createElement("span",null,h.type=="any"?"or":"and")))))))},ZYe=e=>{let{filter:t,selectField:r,selectFilter:n,selectFilterValue:i,removeDefFilter:a,i:o,k:s}=e,l=e.superstate.allMetadata[t.type]?.properties.find(u=>u.field==t.field)?.label??t.field;return yi.default.createElement("div",{className:"mk-filter"},yi.default.createElement("span",{onClick:u=>r(u,o,s)},t.field.length==0?z.labels.select:l),t.field.length>0&&yi.default.createElement("span",{onClick:u=>n(u,o,s)},J0[t.fn]?J0[t.fn]:z.labels.select),t.field.length>0&&J0[t.fn]&&_i[t.fn]?.valueType!="none"&&yi.default.createElement(yi.default.Fragment,null,yi.default.createElement("span",null,yi.default.createElement(nQ,{superstate:e.superstate,fieldType:t.fType,filter:t,selectFilterValue:(u,c)=>i(u,c,o,s)})),e.linkProps&&e.linkProps.length>0&&yi.default.createElement("span",{onClick:u=>{u.stopPropagation(),e.superstate.ui.openMenu(u.currentTarget.getBoundingClientRect(),{ui:e.superstate.ui,multi:!1,editable:!1,value:[],options:e.linkProps.map(c=>({name:c.name,value:c.name,section:c.type})),saveOptions:(c,f)=>i(u,{...t,fType:"property",value:f[0]},o,s),placeholder:z.labels.contextItemSelectPlaceholder,searchable:!0,showAll:!0,sections:[],showSections:!1},je(u.view.document))}},yi.default.createElement("div",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plug")}}))),yi.default.createElement("span",{onClick:u=>{a(s,o),u.stopPropagation()}},yi.default.createElement("div",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//close")}})))},D2e=e=>{let{group:t,selectGroupType:r,addDefGroup:n,selectField:i,i:a,removeDefGroup:o}=e;return yi.default.createElement("div",{className:"mk-query-group"},yi.default.createElement("div",{className:"mk-filter-bar mk-query-filters"},e.children,yi.default.createElement("div",{className:"mk-filter-add",onClick:s=>i(s,a,t?.filters.length??0)},yi.default.createElement("span",null,yi.default.createElement("span",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}}),z.buttons.addCondition))),e.removeable&&yi.default.createElement("div",{className:"mk-filter-add",onClick:s=>{o(a),s.stopPropagation()}},yi.default.createElement("span",null,yi.default.createElement("span",{className:"mk-icon-small",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//close")}}))))};var j2e=e=>{let[t,r]=(0,Ul.useState)(e.space.metadata??{}),n=l=>{i({...t,filters:l})},i=l=>{r(l),of(e.superstate,e.space.space,l)},a=e.superstate.allMetadata,o=[];Object.keys(a).forEach(l=>{a[l].properties.forEach(u=>{o.push(u)})});let s=Object.keys(a).map(l=>({name:a[l].name,value:l}));return(0,Ul.useEffect)(()=>{let l=u=>{if(u.path==e.space.path){let c=e.superstate.spacesIndex.get(e.space.path)?.metadata;c&&r(c)}};return e.superstate.eventsDispatcher.addListener("spaceStateUpdated",l),()=>{e.superstate.eventsDispatcher.removeListener("spaceStateUpdated",l)}},[e.space]),t?.filters?.length>0&&Ul.default.createElement("div",{className:"mk-path-context-row"},Ul.default.createElement("div",{className:"mk-path-context-field"},Ul.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//live")}}),Ul.default.createElement("div",{className:"mk-path-context-field-key"},z.subViews.smartSearch)),Ul.default.createElement("div",{className:"mk-path-context-value"},Ul.default.createElement("div",{className:"mk-props-value"},Ul.default.createElement("div",{className:"mk-props-list"},Ul.default.createElement("div",{className:"mk-space-editor-smart"},t?.filters?.length>0&&Ul.default.createElement(L2,{superstate:e.superstate,filters:t.filters??[],setFilters:n,removeable:!0,fields:o,sections:s,linkProps:e.space.propertyTypes}),Ul.default.createElement("button",{className:"mk-filter-add","aria-label":z.buttons.addSmartSearch,onClick:l=>i({...t,filters:[...t.filters??[],{type:"any",trueFalse:!0,filters:[]}]})},Ul.default.createElement("div",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}}),z.buttons.addSmartSearch))))))};var ya=ge(Te());var O2e=e=>{let{pathState:t}=(0,ya.useContext)(Ir),{spaceState:r}=(0,ya.useContext)(lr),[n,i]=(0,ya.useState)(!0),[a,o]=ya.default.useState([]);(0,ya.useEffect)(()=>{s({path:t.path})},[]);let s=c=>{c.path==t?.path&&e.superstate.spaceManager.commandsForSpace(t.path).then(f=>o(f))};(0,ya.useEffect)(()=>(e.superstate.eventsDispatcher.addListener("actionStateUpdated",s),()=>{e.superstate.eventsDispatcher.removeListener("actionStateUpdated",s)}),[t]);let l=c=>{e.superstate.ui.openModal(z.labels.newAction,ya.default.createElement(ji,{value:"",saveLabel:z.buttons.save,saveValue:f=>{e.superstate.spaceManager.createCommand(r.path,{id:f,name:f,type:"actions"})}}),je(c.view.document))},u=(c,f)=>{c.preventDefault();let d=c.target.getBoundingClientRect(),p=[];p.push({name:"Run Action",icon:"lucide//play",onClick:()=>e.superstate.cli.runCommand(rQ(r,f.schema.id),{iterations:0,instanceProps:{},props:{}})}),p.push({name:"Delete Action",icon:"ui//trash",onClick:()=>e.superstate.spaceManager.deleteCommand(r.path,f.schema.id)}),e.superstate.ui.openMenu(d,Yt(e.superstate.ui,p),je(c.view.document))};return a.length>0?e.compactMode?ya.default.createElement("div",{className:"mk-props-pill",onClick:()=>i(c=>!c)},a.length," Actions"):ya.default.createElement("div",{className:"mk-path-context-row"},ya.default.createElement("div",{className:"mk-path-context-field"},ya.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//mouse-pointer-click")}}),ya.default.createElement("div",{className:"mk-path-context-field-key"},"Actions")),ya.default.createElement("div",{className:"mk-path-context-value"},ya.default.createElement("div",{className:"mk-props-pill",onClick:()=>i(c=>!c)},a.length," Actions",ya.default.createElement(Bm,{superstate:e.superstate,collapsed:n})),!n&&ya.default.createElement("div",{className:"mk-props-list"},a.map((c,f)=>ya.default.createElement("div",{key:f,className:"mk-path",onContextMenu:d=>u(d,c)},ya.default.createElement("div",{className:"mk-path-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker(ux(c.schema))}}),ya.default.createElement("div",{onClick:d=>{e.superstate.ui.openPath(rQ(r,c.schema.id),d.metaKey)}},c.schema.name)))))):ya.default.createElement(ya.default.Fragment,null)};var ja=ge(Te());var M2e=e=>{let[t,r]=(0,ja.useState)(!0),[n,i]=(0,ja.useState)(e.space.metadata??{}),a=l=>{i(l),of(e.superstate,e.space.space,l)},o=(0,ja.useMemo)(()=>(n?.links??[]).map(l=>e.superstate.pathsIndex.get(l)).filter(l=>l),[n]),s=(0,ja.useMemo)(()=>[...e.superstate.spacesMap.getInverse(e.space.path)].map(l=>e.superstate.pathsIndex.get(l)).filter(l=>l.parent==e.space.path),[e.space]);return(0,ja.useEffect)(()=>{let l=u=>{if(u.path==e.space.path){let c=e.superstate.spacesIndex.get(e.space.path)?.metadata;c&&i(c)}};return e.superstate.eventsDispatcher.addListener("spaceStateUpdated",l),()=>{e.superstate.eventsDispatcher.removeListener("spaceStateUpdated",l)}},[e.space]),e.compactMode?ja.default.createElement("div",{className:"mk-props-pill",onClick:()=>r(l=>!l)},ja.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//file-stack")}}),o.length+s.length," Items"):ja.default.createElement("div",{className:"mk-path-context-row"},ja.default.createElement("div",{className:"mk-path-context-field"},ja.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//file-stack")}}),ja.default.createElement("div",{className:"mk-path-context-field-key","aria-label":z.descriptions.spaceItems},"Items")),ja.default.createElement("div",{className:"mk-path-context-value"},ja.default.createElement("div",{className:"mk-props-value"},ja.default.createElement("div",{className:"mk-props-list"},ja.default.createElement("div",{className:"mk-props-pill",onClick:()=>r(l=>!l)},o.length+s.length," Items",ja.default.createElement(Bm,{superstate:e.superstate,collapsed:t})),ja.default.createElement("button",{className:"mk-toolbar-button","aria-label":z.buttons.addSmartSearch,onClick:l=>{let u=[];u.push({name:z.buttons.addSmartSearch,icon:"ui//live",onClick:()=>{a({...n,filters:[...n.filters??[],{type:"any",trueFalse:!0,filters:[]}]})}}),u.push({name:z.buttons.subFolders,icon:"ui//folder",type:6,onSubmenu:(f,d)=>{let p=[];return p.push({name:"Include all items in subfolders",onClick:()=>{a({...n,recursive:"file"})}}),p.push({name:"Include all folders and items in subfolders",onClick:()=>{a({...n,recursive:"all"})}}),p.push({name:"Don't include items in subfolder",onClick:()=>{a({...n,recursive:""})}}),e.superstate.ui.openMenu(f,Yt(e.superstate.ui,p),je(l.view.document),null,d)}});let c=l.currentTarget.getBoundingClientRect();e.superstate.ui.openMenu(c,Yt(e.superstate.ui,u),je(l.view.document))},dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}})),!t&&ja.default.createElement("div",{className:"mk-props-list"},o.map((l,u)=>ja.default.createElement(ns,{key:u,superstate:e.superstate,path:l.path,source:e.space.path})),s.map((l,u)=>ja.default.createElement(ns,{key:u,superstate:e.superstate,path:l.path,source:e.space.path}))))))};var IA=ge(Te()),N2e=e=>{let{setDragNode:t}=(0,IA.useContext)(qm),{spaceInfo:r}=(0,IA.useContext)(lr),n=r.path+e.schema?.id,{attributes:i,listeners:a,setNodeRef:o,transform:s}=gm({id:n,data:{id:n,type:"context",space:r?.path,schema:e.schema?.id}}),l=(0,IA.useRef)(null);return Vo({onDragStart:u=>{u.active.data.current.id==n&&t(IA.default.createElement("div",{dangerouslySetInnerHTML:{__html:l.current.innerHTML}}))}}),IA.default.createElement("div",{className:"mk-path",onClick:u=>e.onClick(u),ref:u=>{o(u),l.current=u},onContextMenu:u=>e.onContextMenu(u),...i,...a},IA.default.createElement("div",{className:"mk-path-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker(e.schema?.primary=="true"?"ui//layout-list":"ui//table")}}),e.schema?.name)};var Ii=ge(Te());var T2e=e=>{let{pathState:t}=(0,Ii.useContext)(Ir),{spaceState:r}=(0,Ii.useContext)(lr),[n,i]=(0,Ii.useState)(!0),[a,o]=(0,Ii.useState)([]);(0,Ii.useEffect)(()=>{s({path:t.path})},[]);let s=c=>{c.path==t?.path&&e.superstate.spaceManager.readAllTables(t?.path)?.then(f=>f?(Object.values(f).map(d=>d.schema)??[]).filter(d=>d.primary!="true"):null).then(f=>{f&&o(f)})};(0,Ii.useEffect)(()=>(e.superstate.eventsDispatcher.addListener("contextStateUpdated",s),()=>{e.superstate.eventsDispatcher.removeListener("contextStateUpdated",s)}),[t]);let l=c=>{e.superstate.ui.openModal(z.labels.newTable,Ii.default.createElement(ji,{value:"",saveLabel:z.buttons.save,saveValue:f=>{e.superstate.spaceManager.tablesForSpace(r.path).then(d=>{if(d){let p={id:Mi(Tm(f),d.map(h=>h.id)),name:f,type:"db"};return e.superstate.spaceManager.createTable(r.path,p).then(h=>e.superstate.spaceManager.addSpaceProperty(r.path,{...cx[0],schemaId:p.id}))}})}}),je(c.view.document))},u=(c,f)=>{let d=[];d.push({name:z.menu.copyEmbedLink,icon:"ui//link",onClick:p=>{navigator.clipboard.writeText(C5(r,f.id))}}),d.push({name:z.menu.moveFile,icon:"ui//move",onClick:p=>{let h=p.target.getBoundingClientRect();Wa(h,je(p.view.document),e.superstate,async m=>{let g=await e.superstate.spaceManager.readTable(r.path,f.id),A=await e.superstate.spaceManager.readAllTables(r.path);g.schema.id=Mi(Tm(g.schema.id),Object.keys(A)),g.cols=g.cols.map(b=>({...b,schemaId:g.schema.id})),e.superstate.spaceManager.createTable(m,g.schema).then(b=>e.superstate.spaceManager.saveTable(m,g))})}}),d.push({name:z.menu.duplicate,icon:"ui//copy",onClick:p=>{e.superstate.ui.openModal("Duplicate Table",Ii.default.createElement(ji,{value:"",saveLabel:"Save",saveValue:async h=>{let m=await e.superstate.spaceManager.readTable(r.path,f.id),g=await e.superstate.spaceManager.readAllTables(r.path);m.schema.id=Mi(Tm(h),Object.keys(g)),m.cols=m.cols.map(A=>({...A,schemaId:m.schema.id})),e.superstate.spaceManager.createTable(r.path,m.schema).then(A=>e.superstate.spaceManager.saveTable(r.path,m)).then(A=>A&&e.superstate.reloadContextByPath(r.path,!0))}}),je(p.view.document))}}),d.push({name:z.buttons.renameView,icon:"ui//edit",onClick:p=>{e.superstate.ui.openModal(z.labels.renameView,Ii.default.createElement(ji,{value:f.name,saveLabel:z.labels.renameView,saveValue:h=>{e.superstate.spaceManager.saveTableSchema(t.path,f.id,()=>({...f,name:h}))}}),je(p.view.document))}}),d.push({name:z.buttons.delete,icon:"ui//trash",onClick:p=>{e.superstate.spaceManager.deleteTable(t.path,f.id)}}),e.superstate.ui.openMenu(c.target.getBoundingClientRect(),Yt(e.superstate.ui,d),je(c.view.document))};return a.length>0?e.compactMode?Ii.default.createElement("div",{className:"mk-props-pill",onClick:()=>i(c=>!c)},a.length," Lists"):Ii.default.createElement("div",{className:"mk-path-context-row"},Ii.default.createElement("div",{className:"mk-path-context-field"},Ii.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//layout-list")}}),Ii.default.createElement("div",{className:"mk-path-context-field-key"},"Lists")),Ii.default.createElement("div",{className:"mk-props-value"},Ii.default.createElement("div",{className:"mk-props-pill",onClick:()=>i(c=>!c)},a.length," Lists",Ii.default.createElement(Bm,{superstate:e.superstate,collapsed:n})),!n&&Ii.default.createElement(Ii.default.Fragment,null,Ii.default.createElement("div",{className:"mk-props-list"},a.map((c,f)=>Ii.default.createElement(N2e,{key:f,superstate:e.superstate,schema:c,onClick:d=>{e.superstate.ui.openPath(by(r,c.id),d.metaKey)},onContextMenu:d=>{u(d,c)}})),Ii.default.createElement("button",{className:"mk-toolbar-button","aria-label":z.labels.newTable,onClick:c=>l(c),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}}))))):Ii.default.createElement(Ii.default.Fragment,null)};var Bi=ge(Te());var F2e=e=>{let{pathState:t}=(0,Bi.useContext)(Ir),{spaceState:r}=(0,Bi.useContext)(lr),[n,i]=(0,Bi.useState)(!0),[a,o]=Bi.default.useState([]);(0,Bi.useEffect)(()=>{s({path:t.path})},[]);let s=f=>{f.path==t?.path&&o(e.superstate.spacesIndex.get(r.path)?.templates)};(0,Bi.useEffect)(()=>(e.superstate.eventsDispatcher.addListener("spaceStateUpdated",s),()=>{e.superstate.eventsDispatcher.removeListener("spaceStateUpdated",s)}),[t]);let l=f=>{let d=f.target.getBoundingClientRect();Ns(d,je(f.view.document),e.superstate,p=>{B0(e.superstate,t.path,p)}),f.stopPropagation()},u=(f,d)=>{let p=f.target.getBoundingClientRect(),h=[];h.push({name:"Set as Default",icon:"ui//clipboard-pen",onClick:()=>Tye(e.superstate,t.path,d)}),h.push({name:"Delete",icon:"ui//trash",onClick:()=>e.superstate.spaceManager.deleteTemplate(d,r.path)}),e.superstate.ui.openMenu(p,Yt(e.superstate.ui,h),je(f.view.document),"bottom")},c=f=>{let d={superstate:e.superstate,saveFormula:p=>Fye(e.superstate,t.path,p),formula:r.metadata.templateName,value:{},fields:[],description:"Automatically set a template name using a formula",path:t.path};e.superstate.ui.openCustomMenu(f.target.getBoundingClientRect(),Bi.default.createElement(Im,{...d}),{...d},je(f.view.document),"bottom")};return a?.length>0?e.compactMode?Bi.default.createElement("div",{className:"mk-props-pill",onClick:()=>i(f=>!f)},a.length," Templates"):Bi.default.createElement("div",{className:"mk-path-context-row"},Bi.default.createElement("div",{className:"mk-path-context-field"},Bi.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//clipboard-pen")}}),Bi.default.createElement("div",{className:"mk-path-context-field-key"},"Templates")),Bi.default.createElement("div",{className:"mk-path-context-value"},Bi.default.createElement("div",{className:"mk-props-pill",onClick:()=>i(f=>!f)},a.length," Templates",Bi.default.createElement(Bm,{superstate:e.superstate,collapsed:n})),Bi.default.createElement("button",{className:"mk-toolbar-button","aria-label":z.labels.editFormula,onClick:f=>c(f),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//formula")}}),!n&&Bi.default.createElement("div",{className:"mk-props-list"},a.map((f,d)=>Bi.default.createElement("div",{key:d,className:"mk-path",onContextMenu:p=>u(p,f)},Bi.default.createElement("div",{className:"mk-path-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//clipboard-pen")}}),Bi.default.createElement("div",null,f),r.metadata.template==f&&Bi.default.createElement("div",{className:"mk-path-icon","aria-label":"Default",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//check")}}))),Bi.default.createElement("button",{className:"mk-toolbar-button","aria-label":z.labels.newAction,onClick:f=>l(f),dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}})))):Bi.default.createElement(Bi.default.Fragment,null)};var pr=ge(Te());var z2=e=>{let[t,r]=(0,pr.useState)(!e.superstate.settings.inlineContextExpanded||!e.collapseSpaces);(0,pr.useEffect)(()=>{e.superstate.settings.inlineContextExpanded=!t,e.superstate.saveSettings()},[t]);let{spaceState:n}=(0,pr.useContext)(lr),{addToSpace:i,readMode:a,removeFromSpace:o,pathState:s}=(0,pr.useContext)(Ir),l=s.type=="space",u=(R,$)=>{let B=e.superstate.spacesIndex.get($);if(!B)return;let N=!1;B.type=="tag"&&!(s.metadata?.tags??[]).includes(B.space.name)&&(N=!0),B.type=="folder"&&(s.liveSpaces??[]).includes($)&&(N=!0),R.preventDefault();let W=[];W.push({name:z.menu.openSpace,icon:"ui//layout-grid",onClick:X=>{e.superstate.ui.openPath(B.path,X.metaKey)}}),W.push({name:z.labels.newProperty,icon:"ui//plus",onClick:X=>{h(X,B.path)}}),o&&!N&&W.push({name:z.menu.removeFromSpace,icon:"ui//trash",onClick:X=>{o(B.path)}});let _=R.target.getBoundingClientRect();e.superstate.ui.openMenu(_,Yt(e.superstate.ui,W),je(R.view.document))},c=R=>[...e.superstate.spacesMap.get(R)].map($=>e.superstate.spacesIndex.get($)).filter($=>$&&$.type!="default"&&$.path!="/").map($=>e.superstate.pathsIndex.get($.path)).sort(($,B)=>R.startsWith($.path)?-1:R.startsWith(B.path)?1:0).filter($=>$),f=(0,pr.useMemo)(()=>c(s.path),[s]),d=(0,pr.useMemo)(()=>[...e.superstate.spacesMap.get(s?.path)??[]].map(R=>e.superstate.spacesIndex.get(R)?.space).filter(R=>R),[s]),p=(R,$)=>R=="$fm"?(_ye(e.superstate,s.path,$),!0):(e.superstate.spaceManager.addSpaceProperty(R,$),!0),h=(R,$)=>{let B=R.target.getBoundingClientRect();uf(e.superstate,B,je(R.view.document),{spaces:f.map(N=>N.path),fields:[],saveField:(N,W)=>p($,W),schemaId:Nr,contextPath:$,fileMetadata:!l})},m=R=>{let $=R.target.getBoundingClientRect();Wa($,je(R.view.document),e.superstate,(B,N)=>{N?B.charAt(0)=="#"?Fm(e.superstate,s.path,B):Sp(e.superstate,B,{links:[s.path]}):i(B)},!1,!0)},g=R=>{e.superstate.ui.openModal(z.labels.newAction,pr.default.createElement(ji,{value:"",saveLabel:z.buttons.save,saveValue:$=>{e.superstate.spaceManager.createCommand(n.path,{id:$,name:$,type:"actions"})}}),je(R.view.document))},A=R=>{e.superstate.ui.openModal(z.labels.newTable,pr.default.createElement(ji,{value:"",saveLabel:z.buttons.save,saveValue:$=>{e.superstate.spaceManager.tablesForSpace(n.path).then(B=>{if(B){let N={id:Mi(Tm($),B.map(W=>W.id)),name:$,type:"db"};return e.superstate.spaceManager.createTable(n.path,N).then(W=>e.superstate.spaceManager.addSpaceProperty(n.path,{...cx[0],schemaId:N.id}))}})}}),je(R.view.document))},b=(R,$)=>Ns(R,$,e.superstate,B=>{B0(e.superstate,s.path,B)}),v=R=>{let $=R.target.getBoundingClientRect(),B=je(R.view.document);e.superstate.ui.openMenu($,Yt(e.superstate.ui,[{name:z.labels.newTable,description:z.descriptions.spaceLists,icon:"ui//table",onClick:N=>A(N)},{name:z.labels.template,description:z.descriptions.spaceTemplates,icon:"ui//clipboard-pen",onClick:N=>b($,B)},{name:z.labels.newAction,description:z.descriptions.spaceActions,icon:"ui//mouse-pointer-click",onClick:N=>g(N)}]),B)},[x,w]=(0,pr.useState)([]);(0,pr.useEffect)(()=>{S()},[s]),(0,pr.useEffect)(()=>{let R=$=>{![...e.superstate.spacesMap.get(s?.path)??[]].includes($.path)||S()};return e.superstate.eventsDispatcher.addListener("contextStateUpdated",R),()=>{e.superstate.eventsDispatcher.removeListener("contextStateUpdated",R)}},[s]);let S=async()=>{let R=[...e.superstate.spacesMap.get(s?.path)??[]],$=await Promise.all(R.map(async N=>e.superstate.spaceManager.readTable(N,Nr).then(W=>({path:N,cols:W.cols,rows:W.rows})))),B=[];$.forEach(N=>{let W=N.rows.find(_=>_[Ft]==s.path);N.cols.filter(_=>_.primary!="true").forEach(_=>{let X=B.findIndex(oe=>oe.property.name==_.name);X==-1?B.push({property:_,contexts:[N.path],value:W?.[_.name]??""}):B[X].contexts.push(N.path)})},[]),w(B)},k=(R,$)=>{Di(e.superstate,s.path,{[$.property.name]:Sa($.property.type,R,!0)})},M=(R,$,B)=>{Di(e.superstate,s.path,{[B.property.name]:Sa(B.property.type,$,!0)}),e.superstate.spaceManager.saveSpaceProperty(B.contexts[0],{...B.property,value:R},B.property)},O=(R,$)=>{let B=R.target.getBoundingClientRect();Lm({superstate:e.superstate,field:$.property,rect:B,win:je(R.view.document),options:[],fields:x.map(N=>N.property),contextPath:s.path,saveField:N=>{e.superstate.spaceManager.saveSpaceProperty($.contexts[0],N,$.property)},anchor:"bottom",deleteColumn:N=>{e.superstate.spaceManager.deleteSpaceProperty($.contexts[0],$.property)},editable:!0})},[C,T]=(0,pr.useTransition)();(0,pr.useEffect)(()=>{T(()=>null)},[]);let D=()=>{T(()=>r(R=>!R))},P=[...Pg(e.superstate.settings)];return pr.default.createElement("div",{className:"mk-props-contexts"},!a&&e.collapseSpaces&&pr.default.createElement("div",{style:{position:"relative"}},pr.default.createElement("div",{className:"mk-fold"},pr.default.createElement(bc,{superstate:e.superstate,collapsed:t,onToggle:R=>D()}))),e.collapseSpaces&&pr.default.createElement("div",{className:"mk-path-context-row"},pr.default.createElement("div",{className:"mk-props-contexts-space-list"},f.map((R,$)=>pr.default.createElement("div",{key:$,className:"mk-props-contexts-space-name",onContextMenu:B=>u(B,R.path),onClick:B=>e.superstate.ui.openPath(R.path,B.metaKey),style:R.label?.color?.length>0?{"--tag-background":R.label?.color,"--tag-color":"var(--color-white)"}:{}},pr.default.createElement("div",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker(R.label?.sticker)}}),R.name)),pr.default.createElement("div",{className:"mk-props-contexts-space-name",onClick:R=>m(R),style:{opacity:.5}},pr.default.createElement("span",{className:"mk-icon-xsmall",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//space-add")}}),z.labels.spaces))),(!t||!e.collapseSpaces||C)&&pr.default.createElement("div",{className:"mk-header-space",style:{transition:"all 0.3s ease-in-out",maxHeight:C?"0px":"unset"}},!e.collapseSpaces&&pr.default.createElement("div",{className:"mk-path-context-row"},pr.default.createElement("div",{className:"mk-path-context-field"},pr.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//file-stack")}}),pr.default.createElement("div",{className:"mk-path-context-field-key"},"Spaces")),pr.default.createElement("div",{className:"mk-path-context-value"},pr.default.createElement("div",{className:"mk-props-value"},pr.default.createElement("div",{className:"mk-props-list"},f.map((R,$)=>pr.default.createElement(ns,{key:$,superstate:e.superstate,path:R.path})))))),l&&n&&pr.default.createElement(pr.default.Fragment,null,pr.default.createElement(M2e,{superstate:e.superstate,space:n,compactMode:!1}),pr.default.createElement(j2e,{superstate:e.superstate,space:n}),pr.default.createElement(T2e,{superstate:e.superstate,compactMode:!1}),pr.default.createElement(F2e,{superstate:e.superstate,compactMode:!1}),pr.default.createElement(O2e,{superstate:e.superstate,compactMode:!1})),x.map((R,$)=>pr.default.createElement(as,{key:$,superstate:e.superstate,initialValue:R.value,row:s.metadata.property,compactMode:!1,column:{...R.property,table:""},editMode:5,updateValue:B=>k(B,R),updateFieldValue:(B,N)=>M(B,N,R),contextTable:{},source:s.path,path:s.path,contexts:R.contexts,propertyMenu:B=>O(B,R)})),pr.default.createElement(b2e,{superstate:e.superstate,spaces:d.map(R=>R.path),force:!0,compactMode:!1,excludeKeys:[...P,e.superstate.settings.fmKeyAlias],editable:!0}),pr.default.createElement("div",{className:"mk-path-context-row-new"},pr.default.createElement("div",{className:"mk-path-context-new",onClick:R=>h(R,"$fm")},pr.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//plus")}}),pr.default.createElement("div",{className:"mk-path-context-field-key"},z.labels.newProperty)),l&&pr.default.createElement("div",{className:"mk-path-context-new",onClick:R=>v(R)},pr.default.createElement("div",{className:"mk-path-context-field-icon",dangerouslySetInnerHTML:{__html:e.superstate.ui.getSticker("ui//options")}})))),P.length>0&&pr.default.createElement("style",null,`${P.map(R=>`.metadata-property[data-property-key="${R}"]`).join(", ")} diff --git a/manifest.json b/manifest.json index 3cc532b..665a033 100755 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "make-md", "name": "MAKE.md", - "version": "0.9.1009", + "version": "0.9.1010", "minAppVersion": "0.16.0", "description": "Make.md brings powerful and modern note-taking features to Obsidian. Capture, organize and connect information with more flexibility without any code.", "author": "MAKE.md", diff --git a/src/core/react/components/PathView/NoteView.tsx b/src/core/react/components/PathView/NoteView.tsx index 4c3e679..008fcfe 100644 --- a/src/core/react/components/PathView/NoteView.tsx +++ b/src/core/react/components/PathView/NoteView.tsx @@ -28,15 +28,14 @@ export const NoteView = forwardRef((props: NoteViewProps, ref) => { const properties: Record = props.properties; const pathState = props.superstate.pathsIndex.get(path.basePath); - const notePath = - pathState?.type == "space" + const filePath = + pathState?.type == "space" && props.forceNote ? props.superstate.spacesIndex.get(props.path)?.space.notePath - : path.fullPath; - const fileExists = - props.forceNote ?? notePath - ? await props.superstate.spaceManager.pathExists(notePath) - : false; - if (!notePath || !fileExists) { + : pathState + ? path.fullPath + : null; + + if (!filePath) { if (!force) { setExistsPas(true); setLoaded(false); @@ -50,6 +49,7 @@ export const NoteView = forwardRef((props: NoteViewProps, ref) => { ).folderPath : props.superstate.spaceManager.parentPathForPath(path.basePath); if (!parent) return; + console.log(parent, props.path, path, props.path, props.source); const newPath = await props.superstate.spaceManager.createItemAtPath( parent, "md", @@ -60,7 +60,7 @@ export const NoteView = forwardRef((props: NoteViewProps, ref) => { } } else { setExistsPas(false); - props.superstate.ui.openPath(notePath, false, div, properties); + props.superstate.ui.openPath(filePath, false, div, properties); } // if (path.refStr?.length > 0) { // const pathPropertiesFromRef ;