simplyflow 0.7.5 → 0.7.7

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.
@@ -12,15 +12,18 @@
12
12
  batch: () => batch,
13
13
  clockEffect: () => clockEffect,
14
14
  destroy: () => destroy,
15
- domSignal: () => domSignal,
16
15
  effect: () => effect2,
16
+ makeContext: () => makeContext,
17
+ notifyGet: () => notifyGet,
18
+ notifySet: () => notifySet,
17
19
  signal: () => signal,
20
+ signals: () => signals,
18
21
  throttledEffect: () => throttledEffect,
19
22
  trace: () => trace,
20
23
  untracked: () => untracked,
21
24
  unwrap: () => unwrap
22
25
  });
23
- var iterate = Symbol("iterate");
26
+ var iterate2 = Symbol("iterate");
24
27
  if (!Symbol.xRay) {
25
28
  Symbol.xRay = Symbol("xRay");
26
29
  }
@@ -72,14 +75,13 @@
72
75
  },
73
76
  set: (target, property, value, receiver) => {
74
77
  value = value?.[Symbol.xRay] || value;
75
- unwrap(value);
76
78
  let current = target[property];
77
79
  if (current !== value) {
78
80
  target[property] = value;
79
81
  notifySet(receiver, makeContext(property, { was: current, now: value }));
80
82
  }
81
83
  if (typeof current === "undefined") {
82
- notifySet(receiver, makeContext(iterate, {}));
84
+ notifySet(receiver, makeContext(iterate2, {}));
83
85
  }
84
86
  return true;
85
87
  },
@@ -102,19 +104,18 @@
102
104
  defineProperty: (target, property, descriptor) => {
103
105
  if (typeof target[property] === "undefined") {
104
106
  let receiver = signals.get(target);
105
- notifySet(receiver, makeContext(iterate, {}));
107
+ notifySet(receiver, makeContext(iterate2, {}));
106
108
  }
107
109
  return Object.defineProperty(target, property, descriptor);
108
110
  },
109
111
  ownKeys: (target) => {
110
112
  let receiver = signals.get(target);
111
- notifyGet(receiver, iterate);
113
+ notifyGet(receiver, iterate2);
112
114
  return Reflect.ownKeys(target);
113
115
  }
114
116
  };
115
117
  var signals = /* @__PURE__ */ new WeakMap();
116
118
  function signal(v) {
117
- unwrap(v);
118
119
  if (v[Symbol.Signal]) {
119
120
  let target = v[Symbol.xRay];
120
121
  if (!signals.has(target)) {
@@ -126,60 +127,15 @@
126
127
  }
127
128
  return signals.get(v);
128
129
  }
129
- var domSignalHandler = {
130
- get: (target, property, receiver) => {
131
- if (property === Symbol.xRay) {
132
- return target;
133
- }
134
- if (property === Symbol.Signal) {
135
- return true;
136
- }
137
- const value = target?.[property];
138
- domListen(target, receiver);
139
- notifyGet(receiver, property);
140
- if (typeof value === "function") {
141
- return value.bind(target);
142
- }
143
- if (value && typeof value == "object") {
144
- return signal(value);
145
- }
146
- return value;
147
- },
148
- has: (target, property) => {
149
- let receiver = signals.get(target);
150
- if (receiver) {
151
- domListen(target, receiver);
152
- notifyGet(receiver, property);
153
- }
154
- return Object.hasOwn(target, property);
155
- },
156
- ownKeys: (target) => {
157
- let receiver = signals.get(target);
158
- if (receiver) {
159
- domListen(target, receiver);
160
- notifyGet(receiver, iterate);
161
- }
162
- return Reflect.ownKeys(target);
163
- }
164
- };
165
- function domSignal(el) {
166
- if (el[Symbol.xRay]) {
167
- return el;
168
- }
169
- if (!signals.has(el)) {
170
- signals.set(el, new Proxy(el, domSignalHandler));
171
- }
172
- return signals.get(el);
173
- }
174
130
  var tracers = [];
175
131
  var tracing = false;
176
- function trace(signal2, prop) {
177
- if (typeof signal2 === "function") {
132
+ function trace(signal3, prop) {
133
+ if (typeof signal3 === "function") {
178
134
  tracing = true;
179
- signal2();
135
+ signal3();
180
136
  tracing = false;
181
137
  } else {
182
- const listeners = getListeners(signal2, prop);
138
+ const listeners = getListeners(signal3, prop);
183
139
  return listeners.map((listener) => {
184
140
  return {
185
141
  effect: listener.effectType,
@@ -242,53 +198,6 @@
242
198
  }
243
199
  }
244
200
  }
245
- var observers = /* @__PURE__ */ new WeakMap();
246
- function domListen(el, signal2) {
247
- let oldContentHTML = el.innerHTML;
248
- let oldContentText = el.innerText;
249
- if (!observers.has(el)) {
250
- const observer = new MutationObserver((mutationList, observer2) => {
251
- const changes = {};
252
- for (const mutation of mutationList) {
253
- if (mutation.type === "attributes") {
254
- changes[mutation.attributeName] = mutation.attributeOldValue;
255
- } else if (mutation.type === "subtree" || mutation.type === "characterData") {
256
- if (el.innerHTML != oldContentHTML) {
257
- changes.innerHTML = oldContentHTML;
258
- oldContentHTML = el.innerHTML;
259
- }
260
- if (el.innerText != oldContentText) {
261
- changes.innerText = oldContentText;
262
- oldContentText = el.innerText;
263
- }
264
- }
265
- }
266
- for (const prop in changes) {
267
- notifySet(signal2, makeContext(prop, { was: changes[prop], now: el[prop] }));
268
- }
269
- });
270
- observer.observe(el, {
271
- characterData: true,
272
- subtree: true,
273
- attributes: true,
274
- attributesOldValue: true
275
- });
276
- observers.set(el, observer);
277
- if (el.matches("input, textarea, select")) {
278
- let prevValue = el.value;
279
- el.addEventListener("change", (evt) => {
280
- notifySet(signal2, makeContext("value", { was: prevValue, now: el.value }));
281
- prevValue = el.value;
282
- });
283
- if (el.matches("input, textarea")) {
284
- el.addEventListener("input", (evt) => {
285
- notifySet(signal2, makeContext("value", { was: prevValue, now: el.value }));
286
- prevValue = el.value;
287
- });
288
- }
289
- }
290
- }
291
- }
292
201
  function makeContext(property, change) {
293
202
  let context = /* @__PURE__ */ new Map();
294
203
  if (typeof property === "object") {
@@ -556,7 +465,7 @@
556
465
  }
557
466
  var seen = /* @__PURE__ */ new WeakMap();
558
467
  function innerUnwrap(ob) {
559
- if (!ob || typeof ob !== "object" || seen.has(ob)) {
468
+ if (!ob || typeof ob !== "object" || ob instanceof HTMLElement || seen.has(ob)) {
560
469
  return;
561
470
  }
562
471
  seen.set(ob, true);
@@ -605,6 +514,102 @@
605
514
  next(context);
606
515
  }
607
516
 
517
+ // src/dom.mjs
518
+ var dom_exports = {};
519
+ __export(dom_exports, {
520
+ signal: () => signal2
521
+ });
522
+ var domSignalHandler = {
523
+ get: (target, property, receiver) => {
524
+ if (property === Symbol.xRay) {
525
+ return target;
526
+ }
527
+ if (property === Symbol.Signal) {
528
+ return true;
529
+ }
530
+ const value = target?.[property];
531
+ notifyGet(receiver, property);
532
+ if (typeof value === "function") {
533
+ return value.bind(target);
534
+ }
535
+ if (value && typeof value == "object") {
536
+ return signal(value);
537
+ }
538
+ return value;
539
+ },
540
+ has: (target, property) => {
541
+ let receiver = signals.get(target);
542
+ if (receiver) {
543
+ notifyGet(receiver, property);
544
+ }
545
+ return Object.hasOwn(target, property);
546
+ },
547
+ ownKeys: (target) => {
548
+ let receiver = signals.get(target);
549
+ if (receiver) {
550
+ notifyGet(receiver, iterate);
551
+ }
552
+ return Reflect.ownKeys(target);
553
+ }
554
+ };
555
+ function signal2(el) {
556
+ if (el[Symbol.xRay]) {
557
+ return el;
558
+ }
559
+ if (!signals.has(el)) {
560
+ signals.set(el, new Proxy(el, domSignalHandler));
561
+ domListen(el, signals.get(el));
562
+ }
563
+ return signals.get(el);
564
+ }
565
+ var observers = /* @__PURE__ */ new WeakMap();
566
+ function domListen(el, signal3) {
567
+ let oldContentHTML = el.innerHTML;
568
+ let oldContentText = el.innerText;
569
+ if (!observers.has(el)) {
570
+ const observer = new MutationObserver((mutationList, observer2) => {
571
+ const changes = {};
572
+ for (const mutation of mutationList) {
573
+ if (mutation.type === "attributes") {
574
+ changes[mutation.attributeName] = mutation.attributeOldValue;
575
+ } else if (mutation.type === "subtree" || mutation.type === "characterData") {
576
+ if (el.innerHTML != oldContentHTML) {
577
+ changes.innerHTML = oldContentHTML;
578
+ oldContentHTML = el.innerHTML;
579
+ }
580
+ if (el.innerText != oldContentText) {
581
+ changes.innerText = oldContentText;
582
+ oldContentText = el.innerText;
583
+ }
584
+ }
585
+ }
586
+ for (const prop in changes) {
587
+ notifySet(signal3, makeContext(prop, { was: changes[prop], now: el[prop] }));
588
+ }
589
+ });
590
+ observer.observe(el, {
591
+ characterData: true,
592
+ subtree: true,
593
+ attributes: true,
594
+ attributesOldValue: true
595
+ });
596
+ observers.set(el, observer);
597
+ if (el.matches("input, textarea, select")) {
598
+ let prevValue = el.value;
599
+ el.addEventListener("change", (evt) => {
600
+ notifySet(signal3, makeContext("value", { was: prevValue, now: el.value }));
601
+ prevValue = el.value;
602
+ });
603
+ if (el.matches("input, textarea")) {
604
+ el.addEventListener("input", (evt) => {
605
+ notifySet(signal3, makeContext("value", { was: prevValue, now: el.value }));
606
+ prevValue = el.value;
607
+ });
608
+ }
609
+ }
610
+ }
611
+ }
612
+
608
613
  // src/bind.render.mjs
609
614
  function field(context) {
610
615
  if (context.templates?.length) {
@@ -617,7 +622,7 @@
617
622
  } else if (this.options.renderers["*"]) {
618
623
  this.options.renderers["*"].call(this, context);
619
624
  if (this.options.twoway) {
620
- const s = domSignal(context.element);
625
+ const s = signal2(context.element);
621
626
  effect(() => {
622
627
  setValueByPath(this.options.root, context.path, s.innerHTML);
623
628
  });
@@ -1420,7 +1425,7 @@
1420
1425
  let result = {};
1421
1426
  for (let key of Object.keys(this.state.options.columns)) {
1422
1427
  if (!this.state.options.columns[key]?.hidden) {
1423
- result[key] = input2[key];
1428
+ result[key] = input2[key] ?? null;
1424
1429
  }
1425
1430
  }
1426
1431
  return result;
@@ -1526,7 +1531,8 @@
1526
1531
  Object.assign(globalThis.simply, {
1527
1532
  bind,
1528
1533
  flow: model_exports,
1529
- state: state_exports
1534
+ state: state_exports,
1535
+ dom: dom_exports
1530
1536
  });
1531
1537
  var flow_default = globalThis.simply;
1532
1538
  })();
@@ -1,2 +1,2 @@
1
- (()=>{var ve=Object.defineProperty;var te=(e,t)=>{for(var n in t)ve(e,n,{get:t[n],enumerable:!0})};var J={};te(J,{addTracer:()=>Oe,batch:()=>_,clockEffect:()=>ae,destroy:()=>F,domSignal:()=>K,effect:()=>oe,signal:()=>A,throttledEffect:()=>g,trace:()=>Le,untracked:()=>Ce,unwrap:()=>G});var C=Symbol("iterate");Symbol.xRay||(Symbol.xRay=Symbol("xRay"));Symbol.Signal||(Symbol.Signal=Symbol("Signal"));var Me={get:(e,t,n)=>{if(t===Symbol.xRay)return e;if(t===Symbol.Signal)return!0;let i=e?.[t];return M(n,t),typeof i=="function"?Array.isArray(e)?(...r)=>{let l=e.length,s=i.apply(n,r);return l!=e.length&&T(n,w("length",{was:l,now:e.length})),s}:e instanceof Set||e instanceof Map?(...r)=>{let l=e.size,s=i.apply(e,r);return l!=e.size&&T(n,w("size",{was:l,now:e.size})),["set","add","clear","delete"].includes(t)&&T(n,w({entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}})),s}:e instanceof HTMLElement||e instanceof Number||e instanceof String||e instanceof Boolean?i.bind(e):i.bind(n):i&&typeof i=="object"?A(i):i},set:(e,t,n,i)=>{n=n?.[Symbol.xRay]||n,G(n);let r=e[t];return r!==n&&(e[t]=n,T(i,w(t,{was:r,now:n}))),typeof r>"u"&&T(i,w(C,{})),!0},has:(e,t)=>{let n=p.get(e);return n&&M(n,t),Object.hasOwn(e,t)},deleteProperty:(e,t)=>{if(typeof e[t]<"u"){let n=e[t];delete e[t];let i=p.get(e);T(i,w(t,{delete:!0,was:n}))}return!0},defineProperty:(e,t,n)=>{if(typeof e[t]>"u"){let i=p.get(e);T(i,w(C,{}))}return Object.defineProperty(e,t,n)},ownKeys:e=>{let t=p.get(e);return M(t,C),Reflect.ownKeys(e)}},p=new WeakMap;function A(e){if(G(e),e[Symbol.Signal]){let t=e[Symbol.xRay];p.has(t)||p.set(t,e),e=t}else p.has(e)||p.set(e,new Proxy(e,Me));return p.get(e)}var ke={get:(e,t,n)=>{if(t===Symbol.xRay)return e;if(t===Symbol.Signal)return!0;let i=e?.[t];return W(e,n),M(n,t),typeof i=="function"?i.bind(e):i&&typeof i=="object"?A(i):i},has:(e,t)=>{let n=p.get(e);return n&&(W(e,n),M(n,t)),Object.hasOwn(e,t)},ownKeys:e=>{let t=p.get(e);return t&&(W(e,t),M(t,C)),Reflect.ownKeys(e)}};function K(e){return e[Symbol.xRay]?e:(p.has(e)||p.set(e,new Proxy(e,ke)),p.get(e))}var z=[],H=!1;function Le(e,t){if(typeof e=="function")H=!0,e(),H=!1;else return le(e,t).map(i=>({effect:i.effectType,fn:i.effectFunction,signal:p.get(i.effectFunction)}))}function Oe(e){if(!e.get&&!e.set)throw new Error('simply.state: addTracer: missing "get" or "set" property in tracer',e);if(e.get&&typeof e.get!="function")throw new Error('simply.state: addTracer: "get" is not a function',e);if(e.set&&typeof e.set!="function")throw new Error('simply.state: addTracer: "set" is not a function',e);z.push(e)}function re(e,...t){for(let n of z)n[e]&&n[e](...t)}var N=new Set,v=0;function T(e,t={}){if(R)return;let n=[];if(t.forEach((i,r)=>{let l=le(e,r);if(l?.length){for(let s of l)je(s,w(r,i));n=n.concat(l)}}),n=new Set(n.filter(Boolean)),n)if(v)N=N.union(n);else{let i=m[m.length-1];for(let r of Array.from(n))r!=i&&r?.needsUpdate&&(H&&z.length&&re("set",e,t,r),r()),se(r)}}var ne=new WeakMap;function W(e,t){let n=e.innerHTML,i=e.innerText;if(!ne.has(e)){let r=new MutationObserver((l,s)=>{let o={};for(let f of l)f.type==="attributes"?o[f.attributeName]=f.attributeOldValue:(f.type==="subtree"||f.type==="characterData")&&(e.innerHTML!=n&&(o.innerHTML=n,n=e.innerHTML),e.innerText!=i&&(o.innerText=i,i=e.innerText));for(let f in o)T(t,w(f,{was:o[f],now:e[f]}))});r.observe(e,{characterData:!0,subtree:!0,attributes:!0,attributesOldValue:!0}),ne.set(e,r)}}function w(e,t){let n=new Map;if(typeof e=="object")for(let i in e)n.set(i,e[i]);else n.set(e,t);return n}function je(e,t){e.context?t.forEach((n,i)=>{e.context.set(i,n)}):e.context=t,e.needsUpdate=!0}function se(e){delete e.context,delete e.needsUpdate}function M(e,t){if(R)return;let n=m[m.length-1];n&&(H&&z.length&&re("get",e,t),Be(e,t,n))}var L=new WeakMap,P=new WeakMap;function le(e,t){let n=L.get(e);return n?Array.from(n.get(t)||[]):[]}function Be(e,t,n){L.has(e)||L.set(e,new Map);let i=L.get(e);i.has(t)||i.set(t,new Set),i.get(t).add(n),P.has(n)||P.set(n,new Map);let r=P.get(n);r.has(t)||r.set(t,new Set),r.get(t).add(e)}function $(e){let t=P.get(e);t&&t.forEach(n=>{n.forEach(i=>{let r=L.get(i);r.has(n)&&r.get(n).delete(e)})})}var m=[],q=[],V=new WeakMap,S=[];function oe(e){if(q.findIndex(i=>e==i)!==-1)throw new Error("Recursive update() call",{cause:e});q.push(e);let t=p.get(e);t||(t=A({current:null}),p.set(e,t));let n=function i(){if(S.findIndex(l=>l==t)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});$(i),i.effectFunction=e,i.effectType=oe,m.push(i),S.push(t);let r;try{r=e(i,m,S)}finally{m.pop(),S.pop(),r instanceof Promise?r.then(l=>{t.current=l}):t.current=r}};return n.fn=e,V.set(t,n),n(),t}function F(e){let t=V.get(e)?.deref();if(!t)return;$(t);let n=t.fn;p.remove(n),V.delete(e)}function _(e){v++;let t;try{t=e()}finally{t instanceof Promise?t.then(()=>{v--,v||ie()}):(v--,v||ie())}return t}function ie(){let e=Array.from(N);N=new Set;let t=m[m.length-1];for(let n of e)n!=t&&n?.needsUpdate&&n(),se(n)}function g(e,t){if(q.findIndex(s=>e==s)!==-1)throw new Error("Recursive update() call",{cause:e});q.push(e);let n=p.get(e);n||(n=A({current:null}),p.set(e,n));let i=!1,r=!0;return function s(){if(S.findIndex(f=>f==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});if(i&&i>Date.now()){r=!0;return}$(s),s.effectFunction=e,s.effectType=g,m.push(s),S.push(n);let o;try{o=e(s,m,S)}finally{r=!1,m.pop(),S.pop(),o instanceof Promise?o.then(f=>{n.current=f}):n.current=o}i=Date.now()+t,globalThis.setTimeout(()=>{r&&s()},t)}(),n}function ae(e,t){let n=p.get(e);n||(n=A({current:null}),p.set(e,n));let i=-1,r=!0;return function s(){if(i<t.time)if(r){$(s),s.effectFunction=e,s.effectType=ae,m.push(s),i=t.time;let o;try{o=e(s,m)}finally{m.pop(),o instanceof Promise?o.then(f=>{n.current=f}):n.current=o,r=!1}}else i=t.time;else r=!0}(),n}var R=!1;function Ce(e){R=!0;try{return e()}finally{R=!1}}var I=new WeakMap;function D(e){if(!(!e||typeof e!="object"||I.has(e))){I.set(e,!0);for(let t in e)if(e[t]?.[Symbol.Signal]&&(e[t]=e[t][Symbol.xRay]),Array.isArray(e[t]))for(let[n,i]of Object.entries(e[t]))i&&typeof i=="object"&&D(i);else e[t]&&typeof e[t]=="object"&&D(e[t])}}function G(e){e&&typeof e=="object"&&(I=new WeakMap,D(e),I=null)}function fe(e,t){let n=e.value?.innerHTML;typeof e.value=="string"&&(n=e.value,e.value={innerHTML:n}),n&&(n=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),e.value.innerHTML=n),t(e)}function ue(e,t){typeof e.value=="string"?e.value={}:delete e.value?.innerHTML,t(e)}function pe(e){if(e.templates?.length)qe.call(this,e);else if(Object.hasOwnProperty.call(this.options.renderers,e.element.tagName)){let t=this.options.renderers[e.element.tagName];t&&t.call(this,e)}else if(this.options.renderers["*"]&&(this.options.renderers["*"].call(this,e),this.options.twoway)){let t=K(e.element);effect(()=>{Pe(this.options.root,e.path,t.innerHTML)})}return e}function de(e){return Array.isArray(e.value)||(e.value=[e.value]),e.templates?.length?He.call(this,e):console.error("No templates found in",e.element),e}function he(e){return typeof e.value!="object"||!e.value?console.error("Value is not an object.",e.element,e.path,e.value):e.templates?.length?Ne.call(this,e):console.error("No templates found in",e.element),e}function Pe(e,t,n){let i=t.split("."),r=e,l;l=i.shift();let s=null,o=null;for(;l&&r;){if(l=decodeURIComponent(l),!(l=="0"&&!Array.isArray(r))){if(l==":key")throw new Error("setting key not yet supported");l==":value"||(Array.isArray(r)&&typeof r[l]>"u"?(s=r[0],r=r[0][l]):(s=r,r=r[l]))}o=l,l=i.shift()}s&&o&&s[o]!==n&&(s[o]=n)}function He(e){let t=this.options.attribute,n=e.element.querySelectorAll(":scope > ["+t+"-key]"),i=0,r=0;e.list=e.value;for(let s of n){let o=parseInt(s.getAttribute(t+"-key"));if(o>i)e.index=i,e.element.insertBefore(this.applyTemplate(e),s);else if(o<i)s.remove();else{let f=Array.from(s.querySelectorAll(`[${t}]`));s.matches(`[${t}]`)&&f.unshift(s);let c=f.find(d=>{let y=d.getAttribute(t);return y.substr(0,5)!==":root"&&y.substr(0,e.path.length)!==e.path});if(!c&&s[Symbol.bindTemplate]){let d=this.findTemplate(e.templates,e.list[i]);d!=s[Symbol.bindTemplate]&&(c=!0,d||r++)}c&&(e.index=i,e.element.replaceChild(this.applyTemplate(e),s))}if(i++,i>=e.value.length)break}n=e.element.querySelectorAll(":scope > ["+t+"-key]");let l=n.length+r;if(l>e.value.length)for(;l>e.value.length;)e.element.querySelectorAll(":scope > :not(template)")?.[l-1]?.remove(),l--;else if(l<e.value.length)for(;l<e.value.length;)e.index=l,e.element.appendChild(this.applyTemplate(e)),l++}function Ne(e){let t=this.options.attribute;e.list=e.value;let n=Array.from(e.element.querySelectorAll(":scope > ["+t+"-key]"));for(let i in e.list){e.index=i;let r=n.shift();if(!r){let s=this.applyTemplate(e);e.element.appendChild(s);continue}if(r.getAttribute[t+"-key"]!=i){n.unshift(r);let s=e.element.querySelector(":scope > ["+t+'-key="'+i+'"]');if(s)e.element.insertBefore(s,r),r=s,n=n.filter(o=>o!=s);else{let o=this.applyTemplate(e);e.element.insertBefore(o,r);continue}}if(this.findTemplate(e.templates,e.list[e.index])!=r[Symbol.bindTemplate]){let s=this.applyTemplate(e);e.element.replaceChild(s,r)}}for(;n.length;)n.shift().remove()}function qe(e){let t=e.element.querySelector(":scope > :not(template)"),n=this.findTemplate(e.templates,e.value);if(e.parent=Re(e.element),t)if(n){if(t?.[Symbol.bindTemplate]!=n){let i=this.applyTemplate(e);e.element.replaceChild(i,t)}}else e.element.removeChild(t);else if(n){let i=this.applyTemplate(e);e.element.appendChild(i)}}function Re(e,t){let n=e.parentElement?.closest(`[${t}-list],[${t}-map]`);return n?n.hasAttribute(`${t}-list`)?n.getAttribute(`${t}-list`)+".":n.getAttribute(`${t}-map`)+".":""}function me(e){let t=e.element,n=e.value;O(e),typeof n>"u"&&(n=""),t.type=="checkbox"||t.type=="radio"?U(t.value,n)?t.checked=!0:t.checked=!1:U(t.value,n)||(t.value=""+n)}function ye(e){O(e),E(e.element,e.value,"value")}function Q(e){let t=e.element,n=e.value;if(n===null&&(n=""),typeof n!="object")if(t.multiple){if(Array.isArray(n))for(let i of t.options)n.indexOf(i.value)===!1?i.selected=!1:i.selected=!0}else{let i=t.options.find(r=>U(r.value,n));i&&(i.selected=!0,i.setAttribute("selected",!0))}else n.options&&Ie(t,n.options),n.selected&&Q(Object.asssign({},e,{value:n.selected})),E(t,n,"name","id","selectedIndex","className")}function ce(e,t){t&&(typeof t!="object"?e.options.add(new Option(""+t)):t.text?e.options.add(new Option(t.text,t.value,t.defaultSelected,t.selected)):typeof t.value<"u"&&e.options.add(new Option(""+t.value,t.value,t.defaultSelected,t.selected)))}function Ie(e,t){if(e.innerHTML="",Array.isArray(t))for(let n of t)ce(e,n);else if(t&&typeof t=="object")for(let n in t)ce(e,{text:t[n],value:n})}function be(e){O(e),E(e.element,e.value,"target","href","name","newwindow","nofollow")}function ge(e){E(e.element,e.value,"title","alt","src","id")}function we(e){E(e.element,e.value,"title","src","id")}function Te(e){E(e.element,e.value,"content","id")}function O(e){let t=e.element,n=e.value;(typeof n>"u"||n==null)&&(n="");let i=""+n;(typeof n!="object"||i.substring(0,8)!="[object ")&&(n={innerHTML:n}),E(t,n,"innerHTML","title","id","className")}function E(e,t,...n){if(!(!t||typeof t!="object"))for(let i of n)typeof t[i]>"u"||U(e[i],t[i])||(t[i]===null?e[i]="":e[i]=""+t[i])}function U(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}Symbol.bindTemplate||(Symbol.bindTemplate=Symbol("bindTemplate"));var Y=class{constructor(t){this.bindings=new Map;let n={escape_html:fe,fixed_content:ue},i={container:document.body,attribute:"data-flow",transformers:n,render:{field:[pe],list:[de],map:[he]},renderers:{INPUT:me,BUTTON:ye,SELECT:Q,A:be,IMG:ge,IFRAME:we,META:Te,TEMPLATE:null,"*":O}};if(!t?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},i,t),t.transformers&&(this.options.transformers=Object.assign({},n,t?.transformers));let r=this.options.attribute,l=[r+"-field",r+"-list",r+"-map"],s=r+"-transform",o=a=>{let u=l.find(h=>a.hasAttribute(h));return u||console.error("No matching attribute found",a,l),u},f=a=>{this.bindings.set(a,g(()=>{if(!a.isConnected){Fe(a,this.getBindingPath(a)),F(this.bindings.get(a));return}let u={templates:a.querySelectorAll(":scope > template"),attribute:o(a)};u.path=this.getBindingPath(a),u.value=X(this.options.root,u.path),u.element=a,$e(a,u),c(u)},50))},c=a=>{let u;switch(a.attribute){case this.options.attribute+"-field":u=Array.from(this.options.render.field);break;case this.options.attribute+"-list":u=Array.from(this.options.render.list);break;case this.options.attribute+"-map":u=Array.from(this.options.render.map);break;default:throw new Error("no valid context attribute specified",a)}a.element.hasAttribute(s)&&a.element.getAttribute(s).split(" ").filter(Boolean).forEach(b=>{this.options.transformers[b]?u.push(this.options.transformers[b]):console.warn("No transformer with name "+b+" configured",{cause:a.element})});let h;for(let b of u)h=((k,Ae)=>Ee=>Ae.call(this,Ee,k))(h,b);h(a)},d=a=>{for(let u of a)this.bindings.get(u)||f(u)},y=a=>{let u=`[${r}-field],[${r}-list],[${r}-map]`;for(let h of a)if(h.type=="childList"&&h.addedNodes){for(let b of h.addedNodes)if(b instanceof HTMLElement){let k=Array.from(b.querySelectorAll(u));b.matches(u)&&k.unshift(b),k.length&&d(k)}}};this.observer=new MutationObserver(a=>{y(a)}),this.observer.observe(this.options.container,{subtree:!0,childList:!0});let B=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");B.length&&d(B)}applyTemplate(t){let n=t.path,i=t.parent,r=t.templates,l=t.list,s=t.index,o=l?l[s]:t.value,f=this.findTemplate(r,o);if(!f){let a=new DocumentFragment;return a.innerHTML="<!-- no matching template -->",a}let c=f.content.cloneNode(!0);if(!c.children?.length)return c;if(c.children.length>1)throw new Error("template must contain a single root node",{cause:f});let d=this.options.attribute,y=[d+"-field",d+"-list",d+"-map"],B=c.querySelectorAll(`[${d}-field],[${d}-list],[${d}-map]`);for(let a of B){if(a.tagName=="TEMPLATE")continue;let u=y.find(b=>a.hasAttribute(b)),h=a.getAttribute(u);h=this.applyLinks(f.links,h),h.substring(0,6)==":root."?a.setAttribute(u,h.substring(6)):h==":value"&&s!=null?a.setAttribute(u,n+"."+s):s!=null?a.setAttribute(u,n+"."+s+"."+h):a.setAttribute(u,i+h)}return typeof s<"u"&&c.children[0].setAttribute(d+"-key",s),c.children[0][Symbol.bindTemplate]=f,c}parseLinks(t){let n={};t=t.split(";").map(i=>i.trim());for(let i of t)i=i.split("="),n[i[0].trim()]=i[1].trim();return n}applyLinks(t,n){for(let i in t){if(n.startsWith(i+"."))return t[i]+n.substr(i.length);if(n==i)return t[i]}return n}getBindingPath(t){let n=[this.options.attribute+"-field",this.options.attribute+"-list",this.options.attribute+"-map"];for(let i of n)if(t.hasAttribute(i))return t.getAttribute(i)}findTemplate(t,n){let i=o=>{let f=this.getBindingPath(o),c;f?f.substr(0,6)==":root."?c=X(this.options.root,f):c=X(n,f):c=n;let d=""+c,y=o.getAttribute(this.options.attribute+"-match");if(y){if(y===":empty"&&!c)return o;if(y===":notempty"&&c||d==y)return o}if(!y&&c!==null&&c!==void 0)return o},r=Array.from(t).find(i),l=null;r?.hasAttribute(this.options.attribute+"-link")&&(l=this.parseLinks(r.getAttribute(this.options.attribute+"-link")));let s=r?.getAttribute("rel");if(s){let o=document.querySelector("template#"+s);if(!o)throw new Error("Could not find template with id "+s);r=o}return r&&(r.links=l),r}destroy(){this.bindings.forEach(t=>{F(t)}),this.bindings=new Map,this.observer.disconnect()}};function Se(e){return new Y(e)}var j=new Map;function $e(e,t){j.has(t.path)?j.get(t.path).push(t):j.set(t.path,[t])}function Fe(e,t){let n=j.get(t);n&&(n=n.filter(i=>i.element==e),j.set(t,n))}function X(e,t){let n=t.split("."),i=e,r;r=n.shift();let l=null;for(;r&&i;)r=decodeURIComponent(r),r=="0"&&!Array.isArray(i)||(r==":key"?i=l:r==":value"||(Array.isArray(i)&&typeof i[r]>"u"?i=i[0][r]:i=i[r])),l=r,r=n.shift();return i}var x={};te(x,{columns:()=>Ke,filter:()=>De,model:()=>Ue,paging:()=>Ve,scroll:()=>_e,sort:()=>We});var Z=class{constructor(t){if(!t)throw new Error("no options set");(t.data==null||typeof t.data[Symbol.iterator]!="function")&&console.warn("SimplyFlowModel: options.data is not iterable"),this.state=A(t),this.state.options||(this.state.options={}),this.effects=[{current:this.state.data}],this.view={current:this.state.data}}addEffect(t){if(!t||typeof t!="function")throw new Error("addEffect requires an effect function as its parameter",{cause:t});let n=this.effects[this.effects.length-1],i=t.call(this,n);if(!i||!i[Symbol.Signal])throw new Error("addEffect function parameter must return a Signal",{cause:t});this.view=i,this.effects.push(this.view)}};function Ue(e){return new Z(e)}function We(e={}){return function(t){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,i)=>{let r=this.state.options.sort,l=r.sortBy;if(!r.sortBy)return 0;let s=r.direction=="asc"?1:-1,o=r.direction=="asc"?-1:1;return typeof n?.[l]>"u"?typeof i?.[l]>"u"?0:s:typeof i?.[l]>"u"||n[l]<i[l]?o:n[l]>i[l]?s:0}},e),g(()=>{let n=this.state.options.sort;return n?.sortBy&&n?.direction?t.current.toSorted(n?.sortFn):t.current},50)}}function Ve(e={}){return function(t){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},e),g(()=>_(()=>{let n=this.state.options.paging;n.pageSize||(n.pageSize=20),n.max=Math.ceil(this.state.data.length/n.pageSize),n.page=Math.max(1,Math.min(n.max,n.page));let i=(n.page-1)*n.pageSize,r=i+n.pageSize;return t.current.slice(i,r)}),50)}}function De(e){if(!e?.name||typeof e.name!="string")throw new Error("filter requires options.name to be a string");if(!e.matches||typeof e.matches!="function")throw new Error("filter requires options.matches to be a function");return function(t){if(this.state.options[e.name])throw new Error("a filter with this name already exists on this model");return this.state.options[e.name]=e,g(()=>this.state.options[e.name].enabled?t.current.filter(this.state.options[e.name].matches.bind(this)):t.current,50)}}function Ke(e={}){if(!e||typeof e!="object"||Object.keys(e).length===0)throw new Error("columns requires options to be an object with at least one property");return function(t){return this.state.options.columns=e,g(()=>t.current.map(n=>{let i={};for(let r of Object.keys(this.state.options.columns))this.state.options.columns[r]?.hidden||(i[r]=n[r]);return i}),50)}}function _e(e){return function(t){this.state.options.scroll=Object.assign({offset:0,rowHeight:26,rowCount:20,itemsPerRow:1,size:t.current.length},e);let n=this.state.options.scroll,i=n.scrollbar||n.container?.querySelector("[data-flow-scrollbar]");return i&&(n.container&&n.container.addEventListener("scroll",r=>{n.offset=Math.floor(n.container.scrollTop/(n.rowHeight*n.itemsPerRow))}),g(()=>{n.size=t.current.length*n.rowHeight,i.style.height=n.size+"px"},50)),g(()=>{n.container&&(n.rowCount=Math.ceil(n.container.getBoundingClientRect().height/n.rowHeight)),n.data=t.current;let r=Math.min(n.offset,t.current.length-1),l=r+n.rowCount;return l>t.current.length&&(l=t.current.length,r=l-n.rowCount),t.current.slice(r,l)},50)}}var ee=class extends HTMLElement{constructor(){super()}connectedCallback(){let t=this.getAttribute("rel"),n=document.getElementById(t);if(n){let i=n.content.cloneNode(!0);for(let r of i.childNodes){let l=r.cloneNode(!0);if(l.nodeType==document.ELEMENT_NODE&&(l.querySelectorAll("template").forEach(function(s){s.setAttribute("simply-render","")}),this.attributes))for(let s of this.attributes)s.name!="rel"&&l.setAttribute(s.name,s.value);this.parentNode.insertBefore(l,this)}this.parentNode.removeChild(this)}else(()=>{let r=new MutationObserver(()=>{n=document.getElementById(t),n&&(r.disconnect(),this.replaceWith(this))});r.observe(globalThis.document,{subtree:!0,childList:!0})})()}};customElements.get("simply-render")||customElements.define("simply-render",ee);globalThis.simply||(globalThis.simply={});Object.assign(globalThis.simply,{bind:Se,flow:x,state:J});var rt=globalThis.simply;})();
1
+ (()=>{var Ae=Object.defineProperty;var U=(e,t)=>{for(var n in t)Ae(e,n,{get:t[n],enumerable:!0})};var _={};U(_,{addTracer:()=>ke,batch:()=>K,clockEffect:()=>le,destroy:()=>$,effect:()=>se,makeContext:()=>y,notifyGet:()=>A,notifySet:()=>w,signal:()=>T,signals:()=>c,throttledEffect:()=>v,trace:()=>Me,untracked:()=>je,unwrap:()=>Ce});var W=Symbol("iterate");Symbol.xRay||(Symbol.xRay=Symbol("xRay"));Symbol.Signal||(Symbol.Signal=Symbol("Signal"));var Ee={get:(e,t,n)=>{if(t===Symbol.xRay)return e;if(t===Symbol.Signal)return!0;let r=e?.[t];return A(n,t),typeof r=="function"?Array.isArray(e)?(...i)=>{let s=e.length,l=r.apply(n,i);return s!=e.length&&w(n,y("length",{was:s,now:e.length})),l}:e instanceof Set||e instanceof Map?(...i)=>{let s=e.size,l=r.apply(e,i);return s!=e.size&&w(n,y("size",{was:s,now:e.size})),["set","add","clear","delete"].includes(t)&&w(n,y({entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}})),l}:e instanceof HTMLElement||e instanceof Number||e instanceof String||e instanceof Boolean?r.bind(e):r.bind(n):r&&typeof r=="object"?T(r):r},set:(e,t,n,r)=>{n=n?.[Symbol.xRay]||n;let i=e[t];return i!==n&&(e[t]=n,w(r,y(t,{was:i,now:n}))),typeof i>"u"&&w(r,y(W,{})),!0},has:(e,t)=>{let n=c.get(e);return n&&A(n,t),Object.hasOwn(e,t)},deleteProperty:(e,t)=>{if(typeof e[t]<"u"){let n=e[t];delete e[t];let r=c.get(e);w(r,y(t,{delete:!0,was:n}))}return!0},defineProperty:(e,t,n)=>{if(typeof e[t]>"u"){let r=c.get(e);w(r,y(W,{}))}return Object.defineProperty(e,t,n)},ownKeys:e=>{let t=c.get(e);return A(t,W),Reflect.ownKeys(e)}},c=new WeakMap;function T(e){if(e[Symbol.Signal]){let t=e[Symbol.xRay];c.has(t)||c.set(t,e),e=t}else c.has(e)||c.set(e,new Proxy(e,Ee));return c.get(e)}var I=[],P=!1;function Me(e,t){if(typeof e=="function")P=!0,e(),P=!1;else return ie(e,t).map(r=>({effect:r.effectType,fn:r.effectFunction,signal:c.get(r.effectFunction)}))}function ke(e){if(!e.get&&!e.set)throw new Error('simply.state: addTracer: missing "get" or "set" property in tracer',e);if(e.get&&typeof e.get!="function")throw new Error('simply.state: addTracer: "get" is not a function',e);if(e.set&&typeof e.set!="function")throw new Error('simply.state: addTracer: "set" is not a function',e);I.push(e)}function ne(e,...t){for(let n of I)n[e]&&n[e](...t)}var H=new Set,M=0;function w(e,t={}){if(q)return;let n=[];if(t.forEach((r,i)=>{let s=ie(e,i);if(s?.length){for(let l of s)Le(l,y(i,r));n=n.concat(s)}}),n=new Set(n.filter(Boolean)),n)if(M)H=H.union(n);else{let r=m[m.length-1];for(let i of Array.from(n))i!=r&&i?.needsUpdate&&(P&&I.length&&ne("set",e,t,i),i()),re(i)}}function y(e,t){let n=new Map;if(typeof e=="object")for(let r in e)n.set(r,e[r]);else n.set(e,t);return n}function Le(e,t){e.context?t.forEach((n,r)=>{e.context.set(r,n)}):e.context=t,e.needsUpdate=!0}function re(e){delete e.context,delete e.needsUpdate}function A(e,t){if(q)return;let n=m[m.length-1];n&&(P&&I.length&&ne("get",e,t),Oe(e,t,n))}var L=new WeakMap,B=new WeakMap;function ie(e,t){let n=L.get(e);return n?Array.from(n.get(t)||[]):[]}function Oe(e,t,n){L.has(e)||L.set(e,new Map);let r=L.get(e);r.has(t)||r.set(t,new Set),r.get(t).add(n),B.has(n)||B.set(n,new Map);let i=B.get(n);i.has(t)||i.set(t,new Set),i.get(t).add(e)}function z(e){let t=B.get(e);t&&t.forEach(n=>{n.forEach(r=>{let i=L.get(r);i.has(n)&&i.get(n).delete(e)})})}var m=[],N=[],V=new WeakMap,S=[];function se(e){if(N.findIndex(r=>e==r)!==-1)throw new Error("Recursive update() call",{cause:e});N.push(e);let t=c.get(e);t||(t=T({current:null}),c.set(e,t));let n=function r(){if(S.findIndex(s=>s==t)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});z(r),r.effectFunction=e,r.effectType=se,m.push(r),S.push(t);let i;try{i=e(r,m,S)}finally{m.pop(),S.pop(),i instanceof Promise?i.then(s=>{t.current=s}):t.current=i}};return n.fn=e,V.set(t,n),n(),t}function $(e){let t=V.get(e)?.deref();if(!t)return;z(t);let n=t.fn;c.remove(n),V.delete(e)}function K(e){M++;let t;try{t=e()}finally{t instanceof Promise?t.then(()=>{M--,M||te()}):(M--,M||te())}return t}function te(){let e=Array.from(H);H=new Set;let t=m[m.length-1];for(let n of e)n!=t&&n?.needsUpdate&&n(),re(n)}function v(e,t){if(N.findIndex(l=>e==l)!==-1)throw new Error("Recursive update() call",{cause:e});N.push(e);let n=c.get(e);n||(n=T({current:null}),c.set(e,n));let r=!1,i=!0;return function l(){if(S.findIndex(f=>f==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});if(r&&r>Date.now()){i=!0;return}z(l),l.effectFunction=e,l.effectType=v,m.push(l),S.push(n);let o;try{o=e(l,m,S)}finally{i=!1,m.pop(),S.pop(),o instanceof Promise?o.then(f=>{n.current=f}):n.current=o}r=Date.now()+t,globalThis.setTimeout(()=>{i&&l()},t)}(),n}function le(e,t){let n=c.get(e);n||(n=T({current:null}),c.set(e,n));let r=-1,i=!0;return function l(){if(r<t.time)if(i){z(l),l.effectFunction=e,l.effectType=le,m.push(l),r=t.time;let o;try{o=e(l,m)}finally{m.pop(),o instanceof Promise?o.then(f=>{n.current=f}):n.current=o,i=!1}}else r=t.time;else i=!0}(),n}var q=!1;function je(e){q=!0;try{return e()}finally{q=!1}}var R=new WeakMap;function D(e){if(!(!e||typeof e!="object"||e instanceof HTMLElement||R.has(e))){R.set(e,!0);for(let t in e)if(e[t]?.[Symbol.Signal]&&(e[t]=e[t][Symbol.xRay]),Array.isArray(e[t]))for(let[n,r]of Object.entries(e[t]))r&&typeof r=="object"&&D(r);else e[t]&&typeof e[t]=="object"&&D(e[t])}}function Ce(e){e&&typeof e=="object"&&(R=new WeakMap,D(e),R=null)}function oe(e,t){let n=e.value?.innerHTML;typeof e.value=="string"&&(n=e.value,e.value={innerHTML:n}),n&&(n=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),e.value.innerHTML=n),t(e)}function ae(e,t){typeof e.value=="string"?e.value={}:delete e.value?.innerHTML,t(e)}var J={};U(J,{signal:()=>G});var Be={get:(e,t,n)=>{if(t===Symbol.xRay)return e;if(t===Symbol.Signal)return!0;let r=e?.[t];return A(n,t),typeof r=="function"?r.bind(e):r&&typeof r=="object"?T(r):r},has:(e,t)=>{let n=c.get(e);return n&&A(n,t),Object.hasOwn(e,t)},ownKeys:e=>{let t=c.get(e);return t&&A(t,iterate),Reflect.ownKeys(e)}};function G(e){return e[Symbol.xRay]?e:(c.has(e)||(c.set(e,new Proxy(e,Be)),Pe(e,c.get(e))),c.get(e))}var fe=new WeakMap;function Pe(e,t){let n=e.innerHTML,r=e.innerText;if(!fe.has(e)){let i=new MutationObserver((s,l)=>{let o={};for(let f of s)f.type==="attributes"?o[f.attributeName]=f.attributeOldValue:(f.type==="subtree"||f.type==="characterData")&&(e.innerHTML!=n&&(o.innerHTML=n,n=e.innerHTML),e.innerText!=r&&(o.innerText=r,r=e.innerText));for(let f in o)w(t,y(f,{was:o[f],now:e[f]}))});if(i.observe(e,{characterData:!0,subtree:!0,attributes:!0,attributesOldValue:!0}),fe.set(e,i),e.matches("input, textarea, select")){let s=e.value;e.addEventListener("change",l=>{w(t,y("value",{was:s,now:e.value})),s=e.value}),e.matches("input, textarea")&&e.addEventListener("input",l=>{w(t,y("value",{was:s,now:e.value})),s=e.value})}}}function ce(e){if(e.templates?.length)Re.call(this,e);else if(Object.hasOwnProperty.call(this.options.renderers,e.element.tagName)){let t=this.options.renderers[e.element.tagName];t&&t.call(this,e)}else if(this.options.renderers["*"]&&(this.options.renderers["*"].call(this,e),this.options.twoway)){let t=G(e.element);effect(()=>{He(this.options.root,e.path,t.innerHTML)})}return e}function pe(e){return Array.isArray(e.value)||(e.value=[e.value]),e.templates?.length?Ne.call(this,e):console.error("No templates found in",e.element),e}function de(e){return typeof e.value!="object"||!e.value?console.error("Value is not an object.",e.element,e.path,e.value):e.templates?.length?qe.call(this,e):console.error("No templates found in",e.element),e}function He(e,t,n){let r=t.split("."),i=e,s;s=r.shift();let l=null,o=null;for(;s&&i;){if(s=decodeURIComponent(s),!(s=="0"&&!Array.isArray(i))){if(s==":key")throw new Error("setting key not yet supported");s==":value"||(Array.isArray(i)&&typeof i[s]>"u"?(l=i[0],i=i[0][s]):(l=i,i=i[s]))}o=s,s=r.shift()}l&&o&&l[o]!==n&&(l[o]=n)}function Ne(e){let t=this.options.attribute,n=e.element.querySelectorAll(":scope > ["+t+"-key]"),r=0,i=0;e.list=e.value;for(let l of n){let o=parseInt(l.getAttribute(t+"-key"));if(o>r)e.index=r,e.element.insertBefore(this.applyTemplate(e),l);else if(o<r)l.remove();else{let f=Array.from(l.querySelectorAll(`[${t}]`));l.matches(`[${t}]`)&&f.unshift(l);let p=f.find(d=>{let b=d.getAttribute(t);return b.substr(0,5)!==":root"&&b.substr(0,e.path.length)!==e.path});if(!p&&l[Symbol.bindTemplate]){let d=this.findTemplate(e.templates,e.list[r]);d!=l[Symbol.bindTemplate]&&(p=!0,d||i++)}p&&(e.index=r,e.element.replaceChild(this.applyTemplate(e),l))}if(r++,r>=e.value.length)break}n=e.element.querySelectorAll(":scope > ["+t+"-key]");let s=n.length+i;if(s>e.value.length)for(;s>e.value.length;)e.element.querySelectorAll(":scope > :not(template)")?.[s-1]?.remove(),s--;else if(s<e.value.length)for(;s<e.value.length;)e.index=s,e.element.appendChild(this.applyTemplate(e)),s++}function qe(e){let t=this.options.attribute;e.list=e.value;let n=Array.from(e.element.querySelectorAll(":scope > ["+t+"-key]"));for(let r in e.list){e.index=r;let i=n.shift();if(!i){let l=this.applyTemplate(e);e.element.appendChild(l);continue}if(i.getAttribute[t+"-key"]!=r){n.unshift(i);let l=e.element.querySelector(":scope > ["+t+'-key="'+r+'"]');if(l)e.element.insertBefore(l,i),i=l,n=n.filter(o=>o!=l);else{let o=this.applyTemplate(e);e.element.insertBefore(o,i);continue}}if(this.findTemplate(e.templates,e.list[e.index])!=i[Symbol.bindTemplate]){let l=this.applyTemplate(e);e.element.replaceChild(l,i)}}for(;n.length;)n.shift().remove()}function Re(e){let t=e.element.querySelector(":scope > :not(template)"),n=this.findTemplate(e.templates,e.value);if(e.parent=Ie(e.element),t)if(n){if(t?.[Symbol.bindTemplate]!=n){let r=this.applyTemplate(e);e.element.replaceChild(r,t)}}else e.element.removeChild(t);else if(n){let r=this.applyTemplate(e);e.element.appendChild(r)}}function Ie(e,t){let n=e.parentElement?.closest(`[${t}-list],[${t}-map]`);return n?n.hasAttribute(`${t}-list`)?n.getAttribute(`${t}-list`)+".":n.getAttribute(`${t}-map`)+".":""}function he(e){let t=e.element,n=e.value;O(e),typeof n>"u"&&(n=""),t.type=="checkbox"||t.type=="radio"?F(t.value,n)?t.checked=!0:t.checked=!1:F(t.value,n)||(t.value=""+n)}function me(e){O(e),E(e.element,e.value,"value")}function Q(e){let t=e.element,n=e.value;if(n===null&&(n=""),typeof n!="object")if(t.multiple){if(Array.isArray(n))for(let r of t.options)n.indexOf(r.value)===!1?r.selected=!1:r.selected=!0}else{let r=t.options.find(i=>F(i.value,n));r&&(r.selected=!0,r.setAttribute("selected",!0))}else n.options&&ze(t,n.options),n.selected&&Q(Object.asssign({},e,{value:n.selected})),E(t,n,"name","id","selectedIndex","className")}function ue(e,t){t&&(typeof t!="object"?e.options.add(new Option(""+t)):t.text?e.options.add(new Option(t.text,t.value,t.defaultSelected,t.selected)):typeof t.value<"u"&&e.options.add(new Option(""+t.value,t.value,t.defaultSelected,t.selected)))}function ze(e,t){if(e.innerHTML="",Array.isArray(t))for(let n of t)ue(e,n);else if(t&&typeof t=="object")for(let n in t)ue(e,{text:t[n],value:n})}function ye(e){O(e),E(e.element,e.value,"target","href","name","newwindow","nofollow")}function be(e){E(e.element,e.value,"title","alt","src","id")}function ge(e){E(e.element,e.value,"title","src","id")}function we(e){E(e.element,e.value,"content","id")}function O(e){let t=e.element,n=e.value;(typeof n>"u"||n==null)&&(n="");let r=""+n;(typeof n!="object"||r.substring(0,8)!="[object ")&&(n={innerHTML:n}),E(t,n,"innerHTML","title","id","className")}function E(e,t,...n){if(!(!t||typeof t!="object"))for(let r of n)typeof t[r]>"u"||F(e[r],t[r])||(t[r]===null?e[r]="":e[r]=""+t[r])}function F(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}Symbol.bindTemplate||(Symbol.bindTemplate=Symbol("bindTemplate"));var Y=class{constructor(t){this.bindings=new Map;let n={escape_html:oe,fixed_content:ae},r={container:document.body,attribute:"data-flow",transformers:n,render:{field:[ce],list:[pe],map:[de]},renderers:{INPUT:he,BUTTON:me,SELECT:Q,A:ye,IMG:be,IFRAME:ge,META:we,TEMPLATE:null,"*":O}};if(!t?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},r,t),t.transformers&&(this.options.transformers=Object.assign({},n,t?.transformers));let i=this.options.attribute,s=[i+"-field",i+"-list",i+"-map"],l=i+"-transform",o=a=>{let u=s.find(h=>a.hasAttribute(h));return u||console.error("No matching attribute found",a,s),u},f=a=>{this.bindings.set(a,v(()=>{if(!a.isConnected){Ue(a,this.getBindingPath(a)),$(this.bindings.get(a));return}let u={templates:a.querySelectorAll(":scope > template"),attribute:o(a)};u.path=this.getBindingPath(a),u.value=X(this.options.root,u.path),u.element=a,Fe(a,u),p(u)},50))},p=a=>{let u;switch(a.attribute){case this.options.attribute+"-field":u=Array.from(this.options.render.field);break;case this.options.attribute+"-list":u=Array.from(this.options.render.list);break;case this.options.attribute+"-map":u=Array.from(this.options.render.map);break;default:throw new Error("no valid context attribute specified",a)}a.element.hasAttribute(l)&&a.element.getAttribute(l).split(" ").filter(Boolean).forEach(g=>{this.options.transformers[g]?u.push(this.options.transformers[g]):console.warn("No transformer with name "+g+" configured",{cause:a.element})});let h;for(let g of u)h=((k,Te)=>Se=>Te.call(this,Se,k))(h,g);h(a)},d=a=>{for(let u of a)this.bindings.get(u)||f(u)},b=a=>{let u=`[${i}-field],[${i}-list],[${i}-map]`;for(let h of a)if(h.type=="childList"&&h.addedNodes){for(let g of h.addedNodes)if(g instanceof HTMLElement){let k=Array.from(g.querySelectorAll(u));g.matches(u)&&k.unshift(g),k.length&&d(k)}}};this.observer=new MutationObserver(a=>{b(a)}),this.observer.observe(this.options.container,{subtree:!0,childList:!0});let C=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");C.length&&d(C)}applyTemplate(t){let n=t.path,r=t.parent,i=t.templates,s=t.list,l=t.index,o=s?s[l]:t.value,f=this.findTemplate(i,o);if(!f){let a=new DocumentFragment;return a.innerHTML="<!-- no matching template -->",a}let p=f.content.cloneNode(!0);if(!p.children?.length)return p;if(p.children.length>1)throw new Error("template must contain a single root node",{cause:f});let d=this.options.attribute,b=[d+"-field",d+"-list",d+"-map"],C=p.querySelectorAll(`[${d}-field],[${d}-list],[${d}-map]`);for(let a of C){if(a.tagName=="TEMPLATE")continue;let u=b.find(g=>a.hasAttribute(g)),h=a.getAttribute(u);h=this.applyLinks(f.links,h),h.substring(0,6)==":root."?a.setAttribute(u,h.substring(6)):h==":value"&&l!=null?a.setAttribute(u,n+"."+l):l!=null?a.setAttribute(u,n+"."+l+"."+h):a.setAttribute(u,r+h)}return typeof l<"u"&&p.children[0].setAttribute(d+"-key",l),p.children[0][Symbol.bindTemplate]=f,p}parseLinks(t){let n={};t=t.split(";").map(r=>r.trim());for(let r of t)r=r.split("="),n[r[0].trim()]=r[1].trim();return n}applyLinks(t,n){for(let r in t){if(n.startsWith(r+"."))return t[r]+n.substr(r.length);if(n==r)return t[r]}return n}getBindingPath(t){let n=[this.options.attribute+"-field",this.options.attribute+"-list",this.options.attribute+"-map"];for(let r of n)if(t.hasAttribute(r))return t.getAttribute(r)}findTemplate(t,n){let r=o=>{let f=this.getBindingPath(o),p;f?f.substr(0,6)==":root."?p=X(this.options.root,f):p=X(n,f):p=n;let d=""+p,b=o.getAttribute(this.options.attribute+"-match");if(b){if(b===":empty"&&!p)return o;if(b===":notempty"&&p||d==b)return o}if(!b&&p!==null&&p!==void 0)return o},i=Array.from(t).find(r),s=null;i?.hasAttribute(this.options.attribute+"-link")&&(s=this.parseLinks(i.getAttribute(this.options.attribute+"-link")));let l=i?.getAttribute("rel");if(l){let o=document.querySelector("template#"+l);if(!o)throw new Error("Could not find template with id "+l);i=o}return i&&(i.links=s),i}destroy(){this.bindings.forEach(t=>{$(t)}),this.bindings=new Map,this.observer.disconnect()}};function ve(e){return new Y(e)}var j=new Map;function Fe(e,t){j.has(t.path)?j.get(t.path).push(t):j.set(t.path,[t])}function Ue(e,t){let n=j.get(t);n&&(n=n.filter(r=>r.element==e),j.set(t,n))}function X(e,t){let n=t.split("."),r=e,i;i=n.shift();let s=null;for(;i&&r;)i=decodeURIComponent(i),i=="0"&&!Array.isArray(r)||(i==":key"?r=s:i==":value"||(Array.isArray(r)&&typeof r[i]>"u"?r=r[0][i]:r=r[i])),s=i,i=n.shift();return r}var x={};U(x,{columns:()=>_e,filter:()=>Ke,model:()=>We,paging:()=>De,scroll:()=>Ge,sort:()=>Ve});var Z=class{constructor(t){if(!t)throw new Error("no options set");(t.data==null||typeof t.data[Symbol.iterator]!="function")&&console.warn("SimplyFlowModel: options.data is not iterable"),this.state=T(t),this.state.options||(this.state.options={}),this.effects=[{current:this.state.data}],this.view={current:this.state.data}}addEffect(t){if(!t||typeof t!="function")throw new Error("addEffect requires an effect function as its parameter",{cause:t});let n=this.effects[this.effects.length-1],r=t.call(this,n);if(!r||!r[Symbol.Signal])throw new Error("addEffect function parameter must return a Signal",{cause:t});this.view=r,this.effects.push(this.view)}};function We(e){return new Z(e)}function Ve(e={}){return function(t){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,r)=>{let i=this.state.options.sort,s=i.sortBy;if(!i.sortBy)return 0;let l=i.direction=="asc"?1:-1,o=i.direction=="asc"?-1:1;return typeof n?.[s]>"u"?typeof r?.[s]>"u"?0:l:typeof r?.[s]>"u"||n[s]<r[s]?o:n[s]>r[s]?l:0}},e),v(()=>{let n=this.state.options.sort;return n?.sortBy&&n?.direction?t.current.toSorted(n?.sortFn):t.current},50)}}function De(e={}){return function(t){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},e),v(()=>K(()=>{let n=this.state.options.paging;n.pageSize||(n.pageSize=20),n.max=Math.ceil(this.state.data.length/n.pageSize),n.page=Math.max(1,Math.min(n.max,n.page));let r=(n.page-1)*n.pageSize,i=r+n.pageSize;return t.current.slice(r,i)}),50)}}function Ke(e){if(!e?.name||typeof e.name!="string")throw new Error("filter requires options.name to be a string");if(!e.matches||typeof e.matches!="function")throw new Error("filter requires options.matches to be a function");return function(t){if(this.state.options[e.name])throw new Error("a filter with this name already exists on this model");return this.state.options[e.name]=e,v(()=>this.state.options[e.name].enabled?t.current.filter(this.state.options[e.name].matches.bind(this)):t.current,50)}}function _e(e={}){if(!e||typeof e!="object"||Object.keys(e).length===0)throw new Error("columns requires options to be an object with at least one property");return function(t){return this.state.options.columns=e,v(()=>t.current.map(n=>{let r={};for(let i of Object.keys(this.state.options.columns))this.state.options.columns[i]?.hidden||(r[i]=n[i]??null);return r}),50)}}function Ge(e){return function(t){this.state.options.scroll=Object.assign({offset:0,rowHeight:26,rowCount:20,itemsPerRow:1,size:t.current.length},e);let n=this.state.options.scroll,r=n.scrollbar||n.container?.querySelector("[data-flow-scrollbar]");return r&&(n.container&&n.container.addEventListener("scroll",i=>{n.offset=Math.floor(n.container.scrollTop/(n.rowHeight*n.itemsPerRow))}),v(()=>{n.size=t.current.length*n.rowHeight,r.style.height=n.size+"px"},50)),v(()=>{n.container&&(n.rowCount=Math.ceil(n.container.getBoundingClientRect().height/n.rowHeight)),n.data=t.current;let i=Math.min(n.offset,t.current.length-1),s=i+n.rowCount;return s>t.current.length&&(s=t.current.length,i=s-n.rowCount),t.current.slice(i,s)},50)}}var ee=class extends HTMLElement{constructor(){super()}connectedCallback(){let t=this.getAttribute("rel"),n=document.getElementById(t);if(n){let r=n.content.cloneNode(!0);for(let i of r.childNodes){let s=i.cloneNode(!0);if(s.nodeType==document.ELEMENT_NODE&&(s.querySelectorAll("template").forEach(function(l){l.setAttribute("simply-render","")}),this.attributes))for(let l of this.attributes)l.name!="rel"&&s.setAttribute(l.name,l.value);this.parentNode.insertBefore(s,this)}this.parentNode.removeChild(this)}else(()=>{let i=new MutationObserver(()=>{n=document.getElementById(t),n&&(i.disconnect(),this.replaceWith(this))});i.observe(globalThis.document,{subtree:!0,childList:!0})})()}};customElements.get("simply-render")||customElements.define("simply-render",ee);globalThis.simply||(globalThis.simply={});Object.assign(globalThis.simply,{bind:ve,flow:x,state:_,dom:J});var lt=globalThis.simply;})();
2
2
  //# sourceMappingURL=simply.flow.min.js.map