simplyview 3.4.4 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,8 +74,8 @@
74
74
  callListeners(node);
75
75
  }
76
76
  }
77
- var observer2 = new MutationObserver(handleChanges);
78
- observer2.observe(document, {
77
+ var observer = new MutationObserver(handleChanges);
78
+ observer.observe(document, {
79
79
  subtree: true,
80
80
  childList: true
81
81
  });
@@ -88,42 +88,18 @@
88
88
  options.app = app2;
89
89
  }
90
90
  if (options.app) {
91
- const waitHandler = {
92
- apply(target, thisArg, argumentsList) {
93
- try {
94
- const result = target(...argumentsList);
95
- if (result instanceof Promise) {
96
- options.app.hooks.wait(true);
97
- return result.finally(() => {
98
- options.app.hooks.wait(false, target);
99
- });
100
- }
101
- return result;
102
- } catch (err) {
103
- }
104
- }
105
- };
106
91
  const functionHandler = {
107
92
  apply(target, thisArg, argumentsList) {
108
93
  try {
109
94
  const result = target(...argumentsList);
110
95
  if (result instanceof Promise) {
111
- if (options.app.hooks.wait) {
112
- options.app.hooks.wait(true, target);
113
- return result.catch((err) => {
114
- return options.app.hooks.error(err, target);
115
- }).finally(() => {
116
- options.app.hooks.wait(false, target);
117
- });
118
- } else {
119
- return result.catch((err) => {
120
- return options.app.hooks.error(err, target);
121
- });
122
- }
96
+ return result.catch((err) => {
97
+ return options.app.hooks.error.call(this, err, target);
98
+ });
123
99
  }
124
100
  return result;
125
101
  } catch (err) {
126
- return options.app.hooks.error(err, target);
102
+ return options.app.hooks.error.call(this, err, target);
127
103
  }
128
104
  }
129
105
  };
@@ -134,8 +110,6 @@
134
110
  }
135
111
  if (options.app.hooks?.error) {
136
112
  return new Proxy(target[property].bind(options.app), functionHandler);
137
- } else if (options.app.hooks?.wait) {
138
- return new Proxy(target[property].bind(options.app), waitHandler);
139
113
  } else {
140
114
  return target[property].bind(options.app);
141
115
  }
@@ -188,13 +162,15 @@
188
162
  path2 = args.path ? args.path : path2;
189
163
  let matches;
190
164
  if (!path2) {
191
- if (this.match(document.location.pathname + document.location.hash)) {
192
- return true;
165
+ if (this.has(document.location.pathname + document.location.hash)) {
166
+ path2 = document.location.pathname + document.location.hash;
167
+ } else if (this.has(document.location.hash)) {
168
+ path2 = document.location.hash;
193
169
  } else {
194
- return this.match(document.location.pathname);
170
+ path2 = document.location.pathname;
195
171
  }
196
172
  }
197
- path2 = getPath(path2);
173
+ path2 = getPath(path2, this.baseURL);
198
174
  for (let route of this.routeInfo) {
199
175
  matches = route.match.exec(path2);
200
176
  if (this.addMissingSlash && !matches?.length) {
@@ -247,9 +223,7 @@
247
223
  }
248
224
  handleEvents() {
249
225
  globalThis.addEventListener("popstate", () => {
250
- if (this.match(getPath(document.location.pathname + document.location.hash, this.baseURL)) === false) {
251
- this.match(getPath(document.location.pathname, this.baseURL));
252
- }
226
+ this.match();
253
227
  });
254
228
  this.app.container.addEventListener("click", (evt) => {
255
229
  if (evt.ctrlKey) {
@@ -401,12 +375,12 @@
401
375
  options.app.container.addEventListener("change", commandHandler);
402
376
  options.app.container.addEventListener("input", commandHandler);
403
377
  }
404
- call(command, el2, value) {
378
+ call(command, el, value) {
405
379
  if (!this[command]) {
406
380
  console.error("simply.command: undefined command " + command);
407
381
  return;
408
382
  }
409
- return this[command].call(this.app, el2, value);
383
+ return this[command].call(this.app, el, value);
410
384
  }
411
385
  action(name) {
412
386
  console.warn("deprecated call to `this.commands.action`");
@@ -430,15 +404,15 @@
430
404
  return new SimplyCommands(options);
431
405
  }
432
406
  function getCommand(evt, handlers) {
433
- var el2 = evt.target.closest("[data-simply-command]");
434
- if (el2) {
407
+ var el = evt.target.closest("[data-simply-command]");
408
+ if (el) {
435
409
  for (let handler of handlers) {
436
- if (el2.matches(handler.match)) {
437
- if (handler.check(el2, evt)) {
410
+ if (el.matches(handler.match)) {
411
+ if (handler.check(el, evt)) {
438
412
  return {
439
- name: el2.dataset.simplyCommand,
440
- source: el2,
441
- value: handler.get(el2)
413
+ name: el.dataset.simplyCommand,
414
+ source: el,
415
+ value: handler.get(el)
442
416
  };
443
417
  }
444
418
  return null;
@@ -450,36 +424,36 @@
450
424
  var defaultHandlers = [
451
425
  {
452
426
  match: "input,select,textarea",
453
- get: function(el2) {
454
- if (el2.tagName === "SELECT" && el2.multiple) {
427
+ get: function(el) {
428
+ if (el.tagName === "SELECT" && el.multiple) {
455
429
  let values = [];
456
- for (let option of el2.options) {
430
+ for (let option of el.options) {
457
431
  if (option.selected) {
458
432
  values.push(option.value);
459
433
  }
460
434
  }
461
435
  return values;
462
436
  }
463
- return el2.dataset.simplyValue || el2.value;
437
+ return el.dataset.simplyValue || el.value;
464
438
  },
465
- check: function(el2, evt) {
466
- return evt.type == "change" || el2.dataset.simplyImmediate && evt.type == "input";
439
+ check: function(el, evt) {
440
+ return evt.type == "change" || el.dataset.simplyImmediate && evt.type == "input";
467
441
  }
468
442
  },
469
443
  {
470
444
  match: "a,button",
471
- get: function(el2) {
472
- return el2.dataset.simplyValue || el2.href || el2.value;
445
+ get: function(el) {
446
+ return el.dataset.simplyValue || el.href || el.value;
473
447
  },
474
- check: function(el2, evt) {
448
+ check: function(el, evt) {
475
449
  return evt.type == "click" && evt.ctrlKey == false && evt.button == 0;
476
450
  }
477
451
  },
478
452
  {
479
453
  match: "form",
480
- get: function(el2) {
454
+ get: function(el) {
481
455
  let data = {};
482
- for (let input of Array.from(el2.elements)) {
456
+ for (let input of Array.from(el.elements)) {
483
457
  if (input.tagName == "INPUT" && (input.type == "checkbox" || input.type == "radio")) {
484
458
  if (!input.checked) {
485
459
  return;
@@ -496,16 +470,16 @@
496
470
  }
497
471
  return data;
498
472
  },
499
- check: function(el2, evt) {
473
+ check: function(el, evt) {
500
474
  return evt.type == "submit";
501
475
  }
502
476
  },
503
477
  {
504
478
  match: "*",
505
- get: function(el2) {
506
- return el2.dataset.simplyValue;
479
+ get: function(el) {
480
+ return el.dataset.simplyValue;
507
481
  },
508
- check: function(el2, evt) {
482
+ check: function(el, evt) {
509
483
  return evt.type == "click" && evt.ctrlKey == false && evt.button == 0;
510
484
  }
511
485
  }
@@ -714,33 +688,12 @@
714
688
  this.view = view({ app: this, view: options.view });
715
689
  break;
716
690
  case "hooks":
717
- const moduleHandler = {
718
- get: (target, property) => {
719
- if (!target[property]) {
720
- return void 0;
721
- }
722
- if (typeof target[property] == "function") {
723
- return new Proxy(target[property], functionHandler);
724
- } else if (target[property] && typeof target[property] == "object") {
725
- return new Proxy(target[property], moduleHandler);
726
- } else {
727
- return target[property];
728
- }
729
- }
730
- };
731
- const functionHandler = {
732
- apply: (target, thisArg, argumentsList) => {
733
- return target.apply(this, argumentsList);
734
- }
735
- };
736
- this[key] = new Proxy(options[key], moduleHandler);
691
+ case "components":
692
+ this[key] = options[key];
737
693
  break;
738
- components:
739
- this.components = components;
694
+ case "prototype":
695
+ case "__proto__":
740
696
  break;
741
- prototype:
742
- __proto__:
743
- break;
744
697
  default:
745
698
  console.log('simply.app: unknown initialization option "' + key + '", added as-is');
746
699
  this[key] = options[key];
@@ -751,34 +704,30 @@
751
704
  get app() {
752
705
  return this;
753
706
  }
754
- async start() {
755
- if (this.components) {
756
- for (const name in this.components) {
757
- if (this.components[name].hooks?.start) {
758
- await this.components[name].hooks.start.call(this, this.components[name]);
759
- }
760
- }
761
- }
762
- if (this.hooks?.start) {
763
- await this.hooks.start();
764
- }
765
- if (this.routes) {
766
- if (this.baseURL) {
767
- this.routes.init({ baseURL: this.baseURL });
707
+ };
708
+ function initRoutes(app2) {
709
+ if (app2.routes) {
710
+ if (app2.baseURL) {
711
+ app2.routes.init({ baseURL: this.baseURL });
712
+ }
713
+ app2.routes.handleEvents();
714
+ globalThis.setTimeout(() => {
715
+ if (app2.routes.has(globalThis.location?.hash)) {
716
+ app2.routes.match(globalThis.location.hash);
717
+ } else {
718
+ app2.routes.match(globalThis.location?.pathname + globalThis.location?.hash);
768
719
  }
769
- this.routes.handleEvents();
770
- globalThis.setTimeout(() => {
771
- if (this.routes.has(globalThis.location?.hash)) {
772
- this.routes.match(globalThis.location.hash);
773
- } else {
774
- this.routes.match(globalThis.location?.pathname + globalThis.location?.hash);
775
- }
776
- });
777
- }
720
+ });
778
721
  }
779
- };
722
+ }
780
723
  function app(options = {}) {
781
- return new SimplyApp(options);
724
+ const app2 = new SimplyApp(options);
725
+ if (app2.hooks?.start) {
726
+ app2.hooks.start.call(app2).then(() => initRoutes(app2));
727
+ } else {
728
+ initRoutes(app2);
729
+ }
730
+ return app2;
782
731
  }
783
732
  if (!globalThis.html) {
784
733
  globalThis.html = html;
@@ -804,9 +753,9 @@
804
753
  }
805
754
  }
806
755
  }
807
- function mergeComponents(options, components2) {
808
- for (const name in components2) {
809
- const component = components2[name];
756
+ function mergeComponents(options, components) {
757
+ for (const name in components) {
758
+ const component = components[name];
810
759
  if (component.components) {
811
760
  mergeComponents(options, component.components);
812
761
  }
@@ -861,7 +810,7 @@
861
810
  }
862
811
  return url.href;
863
812
  }
864
- var observer3;
813
+ var observer2;
865
814
  var loaded = {};
866
815
  var head = globalThis.document.querySelector("head");
867
816
  var currentScript = globalThis.document.currentScript;
@@ -994,8 +943,8 @@
994
943
  });
995
944
  });
996
945
  var observe = () => {
997
- observer3 = new MutationObserver(handleChanges2);
998
- observer3.observe(globalThis.document, {
946
+ observer2 = new MutationObserver(handleChanges2);
947
+ observer2.observe(globalThis.document, {
999
948
  subtree: true,
1000
949
  childList: true
1001
950
  });
@@ -1041,49 +990,6 @@
1041
990
  };
1042
991
  var path_default = path;
1043
992
 
1044
- // src/render.mjs
1045
- var SimplyRender = class extends HTMLElement {
1046
- constructor() {
1047
- super();
1048
- }
1049
- connectedCallback() {
1050
- let templateId = this.getAttribute("rel");
1051
- let template = document.getElementById(templateId);
1052
- if (template) {
1053
- let content = template.content.cloneNode(true);
1054
- for (const node of content.childNodes) {
1055
- const clone = node.cloneNode(true);
1056
- if (clone.nodeType == document.ELEMENT_NODE) {
1057
- clone.querySelectorAll("template").forEach(function(t) {
1058
- t.setAttribute("simply-render", "");
1059
- });
1060
- }
1061
- this.parentNode.insertBefore(clone, this);
1062
- }
1063
- this.parentNode.removeChild(this);
1064
- }
1065
- }
1066
- };
1067
- if (!customElements.get("simply-render")) {
1068
- customElements.define("simply-render", SimplyRender);
1069
- }
1070
- var handleChanges3 = () => {
1071
- const simplyrenders = globalThis.document.querySelectorAll("simply-render[rel]");
1072
- for (el of simplyrenders) {
1073
- if (document.querySelector("template#" + el.getAttribute("rel"))) {
1074
- el.replaceWith(el);
1075
- }
1076
- }
1077
- };
1078
- var observe2 = () => {
1079
- observer = new MutationObserver(handleChanges3);
1080
- observer.observe(globalThis.document, {
1081
- subtree: true,
1082
- childList: true
1083
- });
1084
- };
1085
- observe2();
1086
-
1087
993
  // src/everything.mjs
1088
994
  var simply = {
1089
995
  activate,
@@ -1,2 +1,2 @@
1
- (()=>{Symbol.onDestroy||(Symbol.onDestroy=Symbol("onDestroy"));var u=new Map,q={addListener:(t,e)=>{u.has(t)||u.set(t,[]),u.get(t).push(e),Q(t)},removeListener:(t,e)=>{if(!u.has(t))return!1;u.set(t,u.get(t).filter(r=>r!=e))}};function Q(t){let e=document.querySelectorAll('[data-simply-activate="'+t+'"]');if(e)for(let r of e)D(r)}function D(t){let e=t?.dataset?.simplyActivate;if(e&&u.has(e))for(let r of u.get(e)){let n=r.call(t);typeof n=="function"?t[Symbol.onDestroy]=n:typeof n<"u"&&console.warn("activate listener may only return a de-activate function, instead got",n)}}function X(t){let e=[];for(let r of t)if(r.type=="childList"){for(let n of r.addedNodes)if(n.querySelectorAll){let i=Array.from(n.querySelectorAll("[data-simply-activate]"));n.matches("[data-simply-activate]")&&i.push(n),e=e.concat(i)}for(let n of r.removedNodes)if(n.querySelectorAll){let i=Array.from(n.querySelectorAll("[data-simply-activate]"));n.matches["[data-simply-activate"]&&i.push(n);for(let s of i)s[Symbol.onDestroy]&&s[Symbol.onDestroy].call(s)}}for(let r of e)D(r)}var Z=new MutationObserver(X);Z.observe(document,{subtree:!0,childList:!0});function b(t,e){if(e){let r=t;t=e,t.app=r}if(t.app){let r={apply(s,a,l){try{let c=s(...l);return c instanceof Promise?(t.app.hooks.wait(!0),c.finally(()=>{t.app.hooks.wait(!1,s)})):c}catch{}}},n={apply(s,a,l){try{let c=s(...l);return c instanceof Promise?t.app.hooks.wait?(t.app.hooks.wait(!0,s),c.catch(o=>t.app.hooks.error(o,s)).finally(()=>{t.app.hooks.wait(!1,s)})):c.catch(o=>t.app.hooks.error(o,s)):c}catch(c){return t.app.hooks.error(c,s)}}},i={get(s,a){if(s[a])return t.app.hooks?.error?new Proxy(s[a].bind(t.app),n):t.app.hooks?.wait?new Proxy(s[a].bind(t.app),r):s[a].bind(t.app)}};return new Proxy(t.actions,i)}else return t}function g(t,e){if(e){let r=t;t=e,t.app=t}return new T(t)}var T=class{constructor(e={}){this.baseURL=e.baseURL||"/",this.app=e.app||{},this.addMissingSlash=!!e.addMissingSlash,this.matchExact=!!e.matchExact,this.clear(),e.routes&&this.load(e.routes)}load(e){ee(e,this.routeInfo,this.matchExact)}clear(){this.routeInfo=[],this.listeners={match:{},call:{},goto:{},finish:{}}}match(e,r){let n={path:e,options:r};n=this.runListeners("match",n),e=n.path?n.path:e;let i;if(!e)return this.match(document.location.pathname+document.location.hash)?!0:this.match(document.location.pathname);e=f(e);for(let s of this.routeInfo)if(i=s.match.exec(e),this.addMissingSlash&&!i?.length&&e&&e[e.length-1]!="/"&&(i=s.match.exec(e+"/"),i&&(e+="/",history.replaceState({},"",R(e,this.baseURL)))),i&&i.length){let a={};s.params.forEach((c,o)=>{c=="*"&&(c="remainder"),a[c]=i[o+1]}),Object.assign(a,r),n.route=s,n.params=a,n=this.runListeners("call",n),a=n.params?n.params:a;let l=new URLSearchParams(document.location.search);return n.result=s.action.call(this.app,a,l),this.runListeners("finish",n),n.result}return!1}runListeners(e,r){if(!(!this.listeners[e]||!Object.keys(this.listeners[e])))return Object.keys(this.listeners[e]).forEach(n=>{var i=j(n);if(i.exec(r.path)){var s;for(let a of this.listeners[e][n])s=a.call(this.app,r),s&&(r=s)}}),r}handleEvents(){globalThis.addEventListener("popstate",()=>{this.match(f(document.location.pathname+document.location.hash,this.baseURL))===!1&&this.match(f(document.location.pathname,this.baseURL))}),this.app.container.addEventListener("click",e=>{if(!e.ctrlKey&&e.which==1){for(var r=e.target;r&&r.tagName!="A";)r=r.parentElement;if(r&&r.pathname&&r.hostname==globalThis.location.hostname&&!r.link&&!r.dataset.simplyCommand){let n=[r.hash,r.pathname+r.hash,r.pathname],i;do i=f(n.shift(),this.baseURL);while(n.length&&!this.has(i));if(this.has(i)){let s=this.runListeners("goto",{path:i});if(s.path&&this.goto(s.path))return e.preventDefault(),!1}}}})}goto(e){return history.pushState({},"",R(e,this.baseURL)),this.match(e)}has(e){e=f(e,this.baseURL);for(let n of this.routeInfo){var r=n.match.exec(e);if(r&&r.length)return!0}return!1}addListener(e,r,n){if(["goto","match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][r]||(this.listeners[e][r]=[]),this.listeners[e][r].push(n)}removeListener(e,r,n){if(["match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][r]&&(this.listeners[e][r]=this.listeners[e][r].filter(i=>i!=n))}init(e){e.baseURL&&(this.baseURL=e.baseURL)}};function f(t,e="/"){return(t.substring(0,e.length)==e||e[e.length-1]=="/"&&t.length==e.length-1&&t==e.substring(0,t.length))&&(t=t.substring(e.length)),t[0]!="/"&&t[0]!="#"&&(t="/"+t),t}function R(t,e){return t=f(t,e),e[e.length-1]==="/"&&t[0]==="/"&&(t=t.substring(1)),t[0]=="#"?t:e+t}function j(t,e=!1){return e?new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)")+"(\\?|$)"):new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)"))}function ee(t,e,r=!1){let n=Object.keys(t),i=/:(\w+|\*)/g;for(let s of n){let a=[],l=[];do a=i.exec(s),a&&l.push(a[1]);while(a);e.push({match:j(s,r),params:l,action:t[s]})}return e}var x=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),this.app=e.app,this.$handlers=e.handlers||re,e.commands&&Object.assign(this,e.commands);let r=n=>{let i=te(n,this.$handlers);if(!i)return;if(!this[i.name]){console.error("simply.command: undefined command "+i.name,i.source);return}if(this[i.name].call(e.app,i.source,i.value)!==!0)return n.preventDefault(),n.stopPropagation(),!1};e.app.container.addEventListener("click",r),e.app.container.addEventListener("submit",r),e.app.container.addEventListener("change",r),e.app.container.addEventListener("input",r)}call(e,r,n){if(!this[e]){console.error("simply.command: undefined command "+e);return}return this[e].call(this.app,r,n)}action(e){console.warn("deprecated call to `this.commands.action`");let r=Array.from(arguments).slice();return r.shift(),this.app.actions[e](...r)}appendHandler(e){this.$handlers.push(e)}prependHandler(e){this.$handlers.unshift(e)}};function k(t={},e){if(e){let r=t;t=e,t.app=t}return new x(t)}function te(t,e){var r=t.target.closest("[data-simply-command]");if(r){for(let n of e)if(r.matches(n.match))return n.check(r,t)?{name:r.dataset.simplyCommand,source:r,value:n.get(r)}:null}return null}var re=[{match:"input,select,textarea",get:function(t){if(t.tagName==="SELECT"&&t.multiple){let e=[];for(let r of t.options)r.selected&&e.push(r.value);return e}return t.dataset.simplyValue||t.value},check:function(t,e){return e.type=="change"||t.dataset.simplyImmediate&&e.type=="input"}},{match:"a,button",get:function(t){return t.dataset.simplyValue||t.href||t.value},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}},{match:"form",get:function(t){let e={};for(let r of Array.from(t.elements)){if(r.tagName=="INPUT"&&(r.type=="checkbox"||r.type=="radio")&&!r.checked)return;e[r.name]&&!Array.isArray(e[r.name])&&(e[r.name]=[e[r.name]]),Array.isArray(e[r.name])?e[r.name].push(r.value):e[r.name]=r.value}return e},check:function(t,e){return e.type=="submit"}},{match:"*",get:function(t){return t.dataset.simplyValue},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}}];var d=Object.freeze({Compose:229,Control:17,Meta:224,Alt:18,Shift:16}),A=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),Object.assign(this,e.keys);let r=n=>{if(n.isComposing||n.keyCode===d.Compose||n.defaultPrevented||!n.target)return;let i="default";n.target.closest("[data-simply-keyboard]")&&(i=n.target.closest("[data-simply-keyboard]").dataset.simplyKeyboard);let s=[];n.ctrlKey&&n.keyCode!=d.Control&&s.push("Control"),n.metaKey&&n.keyCode!=d.Meta&&s.push("Meta"),n.altKey&&n.keyCode!=d.Alt&&s.push("Alt"),n.shiftKey&&n.keyCode!=d.Shift&&s.push("Shift"),s.push(n.key.toLowerCase());let a=[],l=event.target.closest("[data-simply-keyboard]");for(;l;)a.push(l.dataset.simplyKeyboard),l=l.parentNode.closest("[data-simply-keyboard]");a.push("");let c,o,W=["+","-"];for(let Y in a){c=a[Y],c==""?o="default":(o=c,c+=".");for(let G of W){let h=s.join(G);if(this[o]&&typeof this[o][h]=="function"&&!this[o][h].call(e.app,n)){n.preventDefault();return}if(typeof this[o+h]=="function"&&!this[o+h].call(e.app,n)){n.preventDefault();return}if(this[i]&&this[i][h]){let y=e.app.container.querySelectorAll('[data-simply-accesskey="'+c+h+'"]');y.length&&(y.forEach(J=>J.click()),n.preventDefault())}}}};e.app.container.addEventListener("keydown",r)}};function v(t={},e){if(e){let r=t;t=e,t.app=t}return new A(t)}function w(t,e){if(e){let r=t;t=e,t.app=t}if(t.app){t.app.view=t.view||{};let r=()=>{let n=t.app.view,i=globalThis.editor.data.getDataPath(t.app.container||document.body);t.app.view=globalThis.editor.currentData[i],Object.assign(t.app.view,n)};return globalThis.editor&&globalThis.editor.currentData?r():document.addEventListener("simply-content-loaded",r),t.app.view}else return t.view}function E(t,...e){return e.map((n,i)=>`${t[i]}${n}`).join("")+t[t.length-1]}function H(t,...e){return E(t,...e)}var C=class{constructor(e={}){if(this.container=e.container||document.body,e.components){let r={};U(r,e.components),S(r,e),e=r}for(let r in e)switch(r){case"html":for(let s in e.html){let a=document.createElement("div");a.innerHTML=e.html[s];let l=this.container.querySelector("template#"+s);l?l.content.replaceChildren(...a.children):(l=document.createElement("template"),l.id=s,l.content.append(...a.children),this.container.appendChild(l))}break;case"css":for(let s in e.css){let a=this.container.querySelector("style#"+s);a||(a=document.createElement("style"),a.id=s,this.container.appendChild(a)),a.innerHTML=e.css[s]}break;case"commands":this.commands=k({app:this,container:this.container,commands:e.commands});break;case"keys":case"keyboard":this.keys=v({app:this,keys:e.keys});break;case"root":case"baseURL":this.baseURL=e[r];break;case"routes":this.routes=g({app:this,routes:e.routes});break;case"actions":this.actions=b({app:this,actions:e.actions}),this.action=function(s){console.warn("deprecated call to `this.action`");let a=Array.from(arguments).slice();return a.shift(),this.actions[s](...a)};break;case"view":this.view=w({app:this,view:e.view});break;case"hooks":let n={get:(s,a)=>{if(s[a])return typeof s[a]=="function"?new Proxy(s[a],i):s[a]&&typeof s[a]=="object"?new Proxy(s[a],n):s[a]}},i={apply:(s,a,l)=>s.apply(this,l)};this[r]=new Proxy(e[r],n);break;default:console.log('simply.app: unknown initialization option "'+r+'", added as-is'),this[r]=e[r];break}}get app(){return this}async start(){if(this.components)for(let e in this.components)this.components[e].hooks?.start&&await this.components[e].hooks.start.call(this,this.components[e]);this.hooks?.start&&await this.hooks.start(),this.routes&&(this.baseURL&&this.routes.init({baseURL:this.baseURL}),this.routes.handleEvents(),globalThis.setTimeout(()=>{this.routes.has(globalThis.location?.hash)?this.routes.match(globalThis.location.hash):this.routes.match(globalThis.location?.pathname+globalThis.location?.hash)}))}};function M(t={}){return new C(t)}globalThis.html||(globalThis.html=E);globalThis.css||(globalThis.css=H);function S(t,e){for(let r in e)switch(typeof e[r]){case"object":if(!e[r])continue;t[r]?S(t[r],e[r]):t[r]=e[r];break;default:t[r]=e[r]}}function U(t,e){for(let r in e){let n=e[r];n.components&&U(t,n.components),t.components||(t.components={}),t.components[r]=n;for(let i in n)switch(i){case"hooks":case"components":break;default:t[i]||(t[i]=Object.create(null)),S(t[i],n[i]);break}}}function ne(t,e){let r=0;return()=>{let n=arguments;r||(r=globalThis.setTimeout(()=>{t.apply(this,n),r=0},e))}}var ae=globalThis.requestIdleCallback?t=>{globalThis.requestIdleCallback(t,{timeout:500})}:globalThis.requestAnimationFrame;function O(t,e){let r=new URL(t,e);return m.cacheBuster&&r.searchParams.set("cb",m.cacheBuster),r.href}var I,se={},N=globalThis.document.querySelector("head"),B=globalThis.document.currentScript,K,$;B?$=B.src:(K=(()=>{var t=document.getElementsByTagName("script"),e=t.length-1,r=t[e];return()=>r?.src})(),$=K());var ie=async()=>new Promise(function(t){var e=globalThis.document.createElement("script");e.src="https://cdn.jsdelivr.net/gh/simplyedit/simplyview/dist/simply.include.next.js",e.async=!1,globalThis.document.addEventListener("simply-include-next",()=>{N.removeChild(e),t()},{once:!0,passive:!0}),N.appendChild(e)}),L=[],m={cacheBuster:null,scripts:(t,e)=>{let r=t.slice(),n=()=>{let i=r.shift();if(!i)return;let s=[].map.call(i.attributes,l=>l.name),a=globalThis.document.createElement("script");for(let l of s)a.setAttribute(l,i.getAttribute(l));if(a.removeAttribute("data-simply-location"),!a.src)a.innerHTML=i.innerHTML,ie().then(()=>{let l=L[i.dataset.simplyLocation];l.parentNode.insertBefore(a,l),l.parentNode.removeChild(l),n()});else{a.src=O(a.src,e),!a.hasAttribute("async")&&!a.hasAttribute("defer")&&(a.async=!1);let l=L[i.dataset.simplyLocation];l.parentNode.insertBefore(a,l),l.parentNode.removeChild(l),se[a.src]=!0,n()}};r.length&&n()},html:(t,e)=>{let r=globalThis.document.createRange().createContextualFragment(t),n=r.querySelectorAll('link[rel="stylesheet"],style');for(let a of n)a.href&&(a.href=O(a.href,e.href)),N.appendChild(a);let i=globalThis.document.createDocumentFragment(),s=r.querySelectorAll("script");if(s.length){for(let a of s){let l=globalThis.document.createComment(a.src||"inline script");a.parentNode.insertBefore(l,a),a.dataset.simplyLocation=L.length,L.push(l),i.appendChild(a)}globalThis.setTimeout(function(){m.scripts(Array.from(i.children),e?e.href:globalThis.location.href)},10)}e.parentNode.insertBefore(r,e||null)}},F={},le=async t=>{let e=[].reduce.call(t,(r,n)=>(n.rel=="simply-include-once"&&F[n.href]?n.parentNode.removeChild(n):(F[n.href]=!0,n.rel="simply-include-loading",r.push(n)),r),[]);for(let r of e){if(!r.href)return;let n=await fetch(r.href);if(!n.ok){console.log("simply-include: failed to load "+r.href);continue}console.log("simply-include: loaded "+r.href);let i=await n.text();m.html(i,r),r.parentNode.removeChild(r)}},_=ne(()=>{ae(()=>{var t=globalThis.document.querySelectorAll('link[rel="simply-include"],link[rel="simply-include-once"]');t.length&&le(t)})}),ce=()=>{I=new MutationObserver(_),I.observe(globalThis.document,{subtree:!0,childList:!0})};ce();_();var p={get(t,e){return typeof e!="string"?e:e?e.split(".").reduce(function(r,n){return r&&r[n]?r[n]:null},t):t},set:function(t,e,r){let n=p.get(t,p.parent(e));n[p.pop(e)]=r},pop:function(t){return t.split(".").pop()},push:function(t,e){return(t?t+".":"")+e},parent:function(t,e){let r=e.split(".");return r.pop(),r.join(".")},parents:function(t,e){let r=[];for(;e;)e=p.parent(e),r.unshift(e)}},V=p;var P=class extends HTMLElement{constructor(){super()}connectedCallback(){let e=this.getAttribute("rel"),r=document.getElementById(e);if(r){let n=r.content.cloneNode(!0);for(let i of n.childNodes){let s=i.cloneNode(!0);s.nodeType==document.ELEMENT_NODE&&s.querySelectorAll("template").forEach(function(a){a.setAttribute("simply-render","")}),this.parentNode.insertBefore(s,this)}this.parentNode.removeChild(this)}}};customElements.get("simply-render")||customElements.define("simply-render",P);var oe=()=>{let t=globalThis.document.querySelectorAll("simply-render[rel]");for(el of t)document.querySelector("template#"+el.getAttribute("rel"))&&el.replaceWith(el)},ue=()=>{observer=new MutationObserver(oe),observer.observe(globalThis.document,{subtree:!0,childList:!0})};ue();var z={activate:q,action:b,app:M,command:k,include:m,key:v,path:V,route:g,view:w};globalThis.simply=z;var Ie=z;})();
1
+ (()=>{Symbol.onDestroy||(Symbol.onDestroy=Symbol("onDestroy"));var u=new Map,D={addListener:(t,e)=>{u.has(t)||u.set(t,[]),u.get(t).push(e),Q(t)},removeListener:(t,e)=>{if(!u.has(t))return!1;u.set(t,u.get(t).filter(r=>r!=e))}};function Q(t){let e=document.querySelectorAll('[data-simply-activate="'+t+'"]');if(e)for(let r of e)N(r)}function N(t){let e=t?.dataset?.simplyActivate;if(e&&u.has(e))for(let r of u.get(e)){let a=r.call(t);typeof a=="function"?t[Symbol.onDestroy]=a:typeof a<"u"&&console.warn("activate listener may only return a de-activate function, instead got",a)}}function X(t){let e=[];for(let r of t)if(r.type=="childList"){for(let a of r.addedNodes)if(a.querySelectorAll){let n=Array.from(a.querySelectorAll("[data-simply-activate]"));a.matches("[data-simply-activate]")&&n.push(a),e=e.concat(n)}for(let a of r.removedNodes)if(a.querySelectorAll){let n=Array.from(a.querySelectorAll("[data-simply-activate]"));a.matches["[data-simply-activate"]&&n.push(a);for(let s of n)s[Symbol.onDestroy]&&s[Symbol.onDestroy].call(s)}}for(let r of e)N(r)}var Z=new MutationObserver(X);Z.observe(document,{subtree:!0,childList:!0});function y(t,e){if(e){let r=t;t=e,t.app=r}if(t.app){let r={apply(n,s,i){try{let l=n(...i);return l instanceof Promise?l.catch(c=>t.app.hooks.error.call(this,c,n)):l}catch(l){return t.app.hooks.error.call(this,l,n)}}},a={get(n,s){if(n[s])return t.app.hooks?.error?new Proxy(n[s].bind(t.app),r):n[s].bind(t.app)}};return new Proxy(t.actions,a)}else return t}function b(t,e){if(e){let r=t;t=e,t.app=t}return new T(t)}var T=class{constructor(e={}){this.baseURL=e.baseURL||"/",this.app=e.app||{},this.addMissingSlash=!!e.addMissingSlash,this.matchExact=!!e.matchExact,this.clear(),e.routes&&this.load(e.routes)}load(e){ee(e,this.routeInfo,this.matchExact)}clear(){this.routeInfo=[],this.listeners={match:{},call:{},goto:{},finish:{}}}match(e,r){let a={path:e,options:r};a=this.runListeners("match",a),e=a.path?a.path:e;let n;e||(this.has(document.location.pathname+document.location.hash)?e=document.location.pathname+document.location.hash:this.has(document.location.hash)?e=document.location.hash:e=document.location.pathname),e=g(e,this.baseURL);for(let s of this.routeInfo)if(n=s.match.exec(e),this.addMissingSlash&&!n?.length&&e&&e[e.length-1]!="/"&&(n=s.match.exec(e+"/"),n&&(e+="/",history.replaceState({},"",j(e,this.baseURL)))),n&&n.length){let i={};s.params.forEach((c,o)=>{c=="*"&&(c="remainder"),i[c]=n[o+1]}),Object.assign(i,r),a.route=s,a.params=i,a=this.runListeners("call",a),i=a.params?a.params:i;let l=new URLSearchParams(document.location.search);return a.result=s.action.call(this.app,i,l),this.runListeners("finish",a),a.result}return!1}runListeners(e,r){if(!(!this.listeners[e]||!Object.keys(this.listeners[e])))return Object.keys(this.listeners[e]).forEach(a=>{var n=q(a);if(n.exec(r.path)){var s;for(let i of this.listeners[e][a])s=i.call(this.app,r),s&&(r=s)}}),r}handleEvents(){globalThis.addEventListener("popstate",()=>{this.match()}),this.app.container.addEventListener("click",e=>{if(!e.ctrlKey&&e.which==1){for(var r=e.target;r&&r.tagName!="A";)r=r.parentElement;if(r&&r.pathname&&r.hostname==globalThis.location.hostname&&!r.link&&!r.dataset.simplyCommand){let a=[r.hash,r.pathname+r.hash,r.pathname],n;do n=g(a.shift(),this.baseURL);while(a.length&&!this.has(n));if(this.has(n)){let s=this.runListeners("goto",{path:n});if(s.path&&this.goto(s.path))return e.preventDefault(),!1}}}})}goto(e){return history.pushState({},"",j(e,this.baseURL)),this.match(e)}has(e){e=g(e,this.baseURL);for(let a of this.routeInfo){var r=a.match.exec(e);if(r&&r.length)return!0}return!1}addListener(e,r,a){if(["goto","match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][r]||(this.listeners[e][r]=[]),this.listeners[e][r].push(a)}removeListener(e,r,a){if(["match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][r]&&(this.listeners[e][r]=this.listeners[e][r].filter(n=>n!=a))}init(e){e.baseURL&&(this.baseURL=e.baseURL)}};function g(t,e="/"){return(t.substring(0,e.length)==e||e[e.length-1]=="/"&&t.length==e.length-1&&t==e.substring(0,t.length))&&(t=t.substring(e.length)),t[0]!="/"&&t[0]!="#"&&(t="/"+t),t}function j(t,e){return t=g(t,e),e[e.length-1]==="/"&&t[0]==="/"&&(t=t.substring(1)),t[0]=="#"?t:e+t}function q(t,e=!1){return e?new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)")+"(\\?|$)"):new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)"))}function ee(t,e,r=!1){let a=Object.keys(t),n=/:(\w+|\*)/g;for(let s of a){let i=[],l=[];do i=n.exec(s),i&&l.push(i[1]);while(i);e.push({match:q(s,r),params:l,action:t[s]})}return e}var x=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),this.app=e.app,this.$handlers=e.handlers||re,e.commands&&Object.assign(this,e.commands);let r=a=>{let n=te(a,this.$handlers);if(!n)return;if(!this[n.name]){console.error("simply.command: undefined command "+n.name,n.source);return}if(this[n.name].call(e.app,n.source,n.value)!==!0)return a.preventDefault(),a.stopPropagation(),!1};e.app.container.addEventListener("click",r),e.app.container.addEventListener("submit",r),e.app.container.addEventListener("change",r),e.app.container.addEventListener("input",r)}call(e,r,a){if(!this[e]){console.error("simply.command: undefined command "+e);return}return this[e].call(this.app,r,a)}action(e){console.warn("deprecated call to `this.commands.action`");let r=Array.from(arguments).slice();return r.shift(),this.app.actions[e](...r)}appendHandler(e){this.$handlers.push(e)}prependHandler(e){this.$handlers.unshift(e)}};function v(t={},e){if(e){let r=t;t=e,t.app=t}return new x(t)}function te(t,e){var r=t.target.closest("[data-simply-command]");if(r){for(let a of e)if(r.matches(a.match))return a.check(r,t)?{name:r.dataset.simplyCommand,source:r,value:a.get(r)}:null}return null}var re=[{match:"input,select,textarea",get:function(t){if(t.tagName==="SELECT"&&t.multiple){let e=[];for(let r of t.options)r.selected&&e.push(r.value);return e}return t.dataset.simplyValue||t.value},check:function(t,e){return e.type=="change"||t.dataset.simplyImmediate&&e.type=="input"}},{match:"a,button",get:function(t){return t.dataset.simplyValue||t.href||t.value},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}},{match:"form",get:function(t){let e={};for(let r of Array.from(t.elements)){if(r.tagName=="INPUT"&&(r.type=="checkbox"||r.type=="radio")&&!r.checked)return;e[r.name]&&!Array.isArray(e[r.name])&&(e[r.name]=[e[r.name]]),Array.isArray(e[r.name])?e[r.name].push(r.value):e[r.name]=r.value}return e},check:function(t,e){return e.type=="submit"}},{match:"*",get:function(t){return t.dataset.simplyValue},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}}];var m=Object.freeze({Compose:229,Control:17,Meta:224,Alt:18,Shift:16}),A=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),Object.assign(this,e.keys);let r=a=>{if(a.isComposing||a.keyCode===m.Compose||a.defaultPrevented||!a.target)return;let n="default";a.target.closest("[data-simply-keyboard]")&&(n=a.target.closest("[data-simply-keyboard]").dataset.simplyKeyboard);let s=[];a.ctrlKey&&a.keyCode!=m.Control&&s.push("Control"),a.metaKey&&a.keyCode!=m.Meta&&s.push("Meta"),a.altKey&&a.keyCode!=m.Alt&&s.push("Alt"),a.shiftKey&&a.keyCode!=m.Shift&&s.push("Shift"),s.push(a.key.toLowerCase());let i=[],l=event.target.closest("[data-simply-keyboard]");for(;l;)i.push(l.dataset.simplyKeyboard),l=l.parentNode.closest("[data-simply-keyboard]");i.push("");let c,o,W=["+","-"];for(let Y in i){c=i[Y],c==""?o="default":(o=c,c+=".");for(let G of W){let h=s.join(G);if(this[o]&&typeof this[o][h]=="function"&&!this[o][h].call(e.app,a)){a.preventDefault();return}if(typeof this[o+h]=="function"&&!this[o+h].call(e.app,a)){a.preventDefault();return}if(this[n]&&this[n][h]){let p=e.app.container.querySelectorAll('[data-simply-accesskey="'+c+h+'"]');p.length&&(p.forEach(J=>J.click()),a.preventDefault())}}}};e.app.container.addEventListener("keydown",r)}};function k(t={},e){if(e){let r=t;t=e,t.app=t}return new A(t)}function w(t,e){if(e){let r=t;t=e,t.app=t}if(t.app){t.app.view=t.view||{};let r=()=>{let a=t.app.view,n=globalThis.editor.data.getDataPath(t.app.container||document.body);t.app.view=globalThis.editor.currentData[n],Object.assign(t.app.view,a)};return globalThis.editor&&globalThis.editor.currentData?r():document.addEventListener("simply-content-loaded",r),t.app.view}else return t.view}function C(t,...e){return e.map((a,n)=>`${t[n]}${a}`).join("")+t[t.length-1]}function P(t,...e){return C(t,...e)}var E=class{constructor(e={}){if(this.container=e.container||document.body,e.components){let r={};H(r,e.components),S(r,e),e=r}for(let r in e)switch(r){case"html":for(let a in e.html){let n=document.createElement("div");n.innerHTML=e.html[a];let s=this.container.querySelector("template#"+a);s?s.content.replaceChildren(...n.children):(s=document.createElement("template"),s.id=a,s.content.append(...n.children),this.container.appendChild(s))}break;case"css":for(let a in e.css){let n=this.container.querySelector("style#"+a);n||(n=document.createElement("style"),n.id=a,this.container.appendChild(n)),n.innerHTML=e.css[a]}break;case"commands":this.commands=v({app:this,container:this.container,commands:e.commands});break;case"keys":case"keyboard":this.keys=k({app:this,keys:e.keys});break;case"root":case"baseURL":this.baseURL=e[r];break;case"routes":this.routes=b({app:this,routes:e.routes});break;case"actions":this.actions=y({app:this,actions:e.actions}),this.action=function(a){console.warn("deprecated call to `this.action`");let n=Array.from(arguments).slice();return n.shift(),this.actions[a](...n)};break;case"view":this.view=w({app:this,view:e.view});break;case"hooks":case"components":this[r]=e[r];break;case"prototype":case"__proto__":break;default:console.log('simply.app: unknown initialization option "'+r+'", added as-is'),this[r]=e[r];break}}get app(){return this}};function U(t){t.routes&&(t.baseURL&&t.routes.init({baseURL:this.baseURL}),t.routes.handleEvents(),globalThis.setTimeout(()=>{t.routes.has(globalThis.location?.hash)?t.routes.match(globalThis.location.hash):t.routes.match(globalThis.location?.pathname+globalThis.location?.hash)}))}function M(t={}){let e=new E(t);return e.hooks?.start?e.hooks.start.call(e).then(()=>U(e)):U(e),e}globalThis.html||(globalThis.html=C);globalThis.css||(globalThis.css=P);function S(t,e){for(let r in e)switch(typeof e[r]){case"object":if(!e[r])continue;t[r]?S(t[r],e[r]):t[r]=e[r];break;default:t[r]=e[r]}}function H(t,e){for(let r in e){let a=e[r];a.components&&H(t,a.components),t.components||(t.components={}),t.components[r]=a;for(let n in a)switch(n){case"hooks":case"components":break;default:t[n]||(t[n]=Object.create(null)),S(t[n],a[n]);break}}}function ae(t,e){let r=0;return()=>{let a=arguments;r||(r=globalThis.setTimeout(()=>{t.apply(this,a),r=0},e))}}var ne=globalThis.requestIdleCallback?t=>{globalThis.requestIdleCallback(t,{timeout:500})}:globalThis.requestAnimationFrame;function K(t,e){let r=new URL(t,e);return f.cacheBuster&&r.searchParams.set("cb",f.cacheBuster),r.href}var O,se={},R=globalThis.document.querySelector("head"),I=globalThis.document.currentScript,B,_;I?_=I.src:(B=(()=>{var t=document.getElementsByTagName("script"),e=t.length-1,r=t[e];return()=>r?.src})(),_=B());var ie=async()=>new Promise(function(t){var e=globalThis.document.createElement("script");e.src="https://cdn.jsdelivr.net/gh/simplyedit/simplyview/dist/simply.include.next.js",e.async=!1,globalThis.document.addEventListener("simply-include-next",()=>{R.removeChild(e),t()},{once:!0,passive:!0}),R.appendChild(e)}),L=[],f={cacheBuster:null,scripts:(t,e)=>{let r=t.slice(),a=()=>{let n=r.shift();if(!n)return;let s=[].map.call(n.attributes,l=>l.name),i=globalThis.document.createElement("script");for(let l of s)i.setAttribute(l,n.getAttribute(l));if(i.removeAttribute("data-simply-location"),!i.src)i.innerHTML=n.innerHTML,ie().then(()=>{let l=L[n.dataset.simplyLocation];l.parentNode.insertBefore(i,l),l.parentNode.removeChild(l),a()});else{i.src=K(i.src,e),!i.hasAttribute("async")&&!i.hasAttribute("defer")&&(i.async=!1);let l=L[n.dataset.simplyLocation];l.parentNode.insertBefore(i,l),l.parentNode.removeChild(l),se[i.src]=!0,a()}};r.length&&a()},html:(t,e)=>{let r=globalThis.document.createRange().createContextualFragment(t),a=r.querySelectorAll('link[rel="stylesheet"],style');for(let i of a)i.href&&(i.href=K(i.href,e.href)),R.appendChild(i);let n=globalThis.document.createDocumentFragment(),s=r.querySelectorAll("script");if(s.length){for(let i of s){let l=globalThis.document.createComment(i.src||"inline script");i.parentNode.insertBefore(l,i),i.dataset.simplyLocation=L.length,L.push(l),n.appendChild(i)}globalThis.setTimeout(function(){f.scripts(Array.from(n.children),e?e.href:globalThis.location.href)},10)}e.parentNode.insertBefore(r,e||null)}},$={},le=async t=>{let e=[].reduce.call(t,(r,a)=>(a.rel=="simply-include-once"&&$[a.href]?a.parentNode.removeChild(a):($[a.href]=!0,a.rel="simply-include-loading",r.push(a)),r),[]);for(let r of e){if(!r.href)return;let a=await fetch(r.href);if(!a.ok){console.log("simply-include: failed to load "+r.href);continue}console.log("simply-include: loaded "+r.href);let n=await a.text();f.html(n,r),r.parentNode.removeChild(r)}},F=ae(()=>{ne(()=>{var t=globalThis.document.querySelectorAll('link[rel="simply-include"],link[rel="simply-include-once"]');t.length&&le(t)})}),ce=()=>{O=new MutationObserver(F),O.observe(globalThis.document,{subtree:!0,childList:!0})};ce();F();var d={get(t,e){return typeof e!="string"?e:e?e.split(".").reduce(function(r,a){return r&&r[a]?r[a]:null},t):t},set:function(t,e,r){let a=d.get(t,d.parent(e));a[d.pop(e)]=r},pop:function(t){return t.split(".").pop()},push:function(t,e){return(t?t+".":"")+e},parent:function(t,e){let r=e.split(".");return r.pop(),r.join(".")},parents:function(t,e){let r=[];for(;e;)e=d.parent(e),r.unshift(e)}},V=d;var z={activate:D,action:y,app:M,command:v,include:f,key:k,path:V,route:b,view:w};globalThis.simply=z;var Pe=z;})();
2
2
  //# sourceMappingURL=simply.everything.min.js.map