simplyflow 0.7.5 → 0.7.6

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
  }
@@ -79,7 +82,7 @@
79
82
  notifySet(receiver, makeContext(property, { was: current, now: value }));
80
83
  }
81
84
  if (typeof current === "undefined") {
82
- notifySet(receiver, makeContext(iterate, {}));
85
+ notifySet(receiver, makeContext(iterate2, {}));
83
86
  }
84
87
  return true;
85
88
  },
@@ -102,13 +105,13 @@
102
105
  defineProperty: (target, property, descriptor) => {
103
106
  if (typeof target[property] === "undefined") {
104
107
  let receiver = signals.get(target);
105
- notifySet(receiver, makeContext(iterate, {}));
108
+ notifySet(receiver, makeContext(iterate2, {}));
106
109
  }
107
110
  return Object.defineProperty(target, property, descriptor);
108
111
  },
109
112
  ownKeys: (target) => {
110
113
  let receiver = signals.get(target);
111
- notifyGet(receiver, iterate);
114
+ notifyGet(receiver, iterate2);
112
115
  return Reflect.ownKeys(target);
113
116
  }
114
117
  };
@@ -126,60 +129,15 @@
126
129
  }
127
130
  return signals.get(v);
128
131
  }
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
132
  var tracers = [];
175
133
  var tracing = false;
176
- function trace(signal2, prop) {
177
- if (typeof signal2 === "function") {
134
+ function trace(signal3, prop) {
135
+ if (typeof signal3 === "function") {
178
136
  tracing = true;
179
- signal2();
137
+ signal3();
180
138
  tracing = false;
181
139
  } else {
182
- const listeners = getListeners(signal2, prop);
140
+ const listeners = getListeners(signal3, prop);
183
141
  return listeners.map((listener) => {
184
142
  return {
185
143
  effect: listener.effectType,
@@ -242,53 +200,6 @@
242
200
  }
243
201
  }
244
202
  }
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
203
  function makeContext(property, change) {
293
204
  let context = /* @__PURE__ */ new Map();
294
205
  if (typeof property === "object") {
@@ -556,7 +467,7 @@
556
467
  }
557
468
  var seen = /* @__PURE__ */ new WeakMap();
558
469
  function innerUnwrap(ob) {
559
- if (!ob || typeof ob !== "object" || seen.has(ob)) {
470
+ if (!ob || typeof ob !== "object" || ob instanceof HTMLElement || seen.has(ob)) {
560
471
  return;
561
472
  }
562
473
  seen.set(ob, true);
@@ -605,6 +516,102 @@
605
516
  next(context);
606
517
  }
607
518
 
519
+ // src/dom.mjs
520
+ var dom_exports = {};
521
+ __export(dom_exports, {
522
+ signal: () => signal2
523
+ });
524
+ var domSignalHandler = {
525
+ get: (target, property, receiver) => {
526
+ if (property === Symbol.xRay) {
527
+ return target;
528
+ }
529
+ if (property === Symbol.Signal) {
530
+ return true;
531
+ }
532
+ const value = target?.[property];
533
+ notifyGet(receiver, property);
534
+ if (typeof value === "function") {
535
+ return value.bind(target);
536
+ }
537
+ if (value && typeof value == "object") {
538
+ return signal(value);
539
+ }
540
+ return value;
541
+ },
542
+ has: (target, property) => {
543
+ let receiver = signals.get(target);
544
+ if (receiver) {
545
+ notifyGet(receiver, property);
546
+ }
547
+ return Object.hasOwn(target, property);
548
+ },
549
+ ownKeys: (target) => {
550
+ let receiver = signals.get(target);
551
+ if (receiver) {
552
+ notifyGet(receiver, iterate);
553
+ }
554
+ return Reflect.ownKeys(target);
555
+ }
556
+ };
557
+ function signal2(el) {
558
+ if (el[Symbol.xRay]) {
559
+ return el;
560
+ }
561
+ if (!signals.has(el)) {
562
+ signals.set(el, new Proxy(el, domSignalHandler));
563
+ domListen(el, signals.get(el));
564
+ }
565
+ return signals.get(el);
566
+ }
567
+ var observers = /* @__PURE__ */ new WeakMap();
568
+ function domListen(el, signal3) {
569
+ let oldContentHTML = el.innerHTML;
570
+ let oldContentText = el.innerText;
571
+ if (!observers.has(el)) {
572
+ const observer = new MutationObserver((mutationList, observer2) => {
573
+ const changes = {};
574
+ for (const mutation of mutationList) {
575
+ if (mutation.type === "attributes") {
576
+ changes[mutation.attributeName] = mutation.attributeOldValue;
577
+ } else if (mutation.type === "subtree" || mutation.type === "characterData") {
578
+ if (el.innerHTML != oldContentHTML) {
579
+ changes.innerHTML = oldContentHTML;
580
+ oldContentHTML = el.innerHTML;
581
+ }
582
+ if (el.innerText != oldContentText) {
583
+ changes.innerText = oldContentText;
584
+ oldContentText = el.innerText;
585
+ }
586
+ }
587
+ }
588
+ for (const prop in changes) {
589
+ notifySet(signal3, makeContext(prop, { was: changes[prop], now: el[prop] }));
590
+ }
591
+ });
592
+ observer.observe(el, {
593
+ characterData: true,
594
+ subtree: true,
595
+ attributes: true,
596
+ attributesOldValue: true
597
+ });
598
+ observers.set(el, observer);
599
+ if (el.matches("input, textarea, select")) {
600
+ let prevValue = el.value;
601
+ el.addEventListener("change", (evt) => {
602
+ notifySet(signal3, makeContext("value", { was: prevValue, now: el.value }));
603
+ prevValue = el.value;
604
+ });
605
+ if (el.matches("input, textarea")) {
606
+ el.addEventListener("input", (evt) => {
607
+ notifySet(signal3, makeContext("value", { was: prevValue, now: el.value }));
608
+ prevValue = el.value;
609
+ });
610
+ }
611
+ }
612
+ }
613
+ }
614
+
608
615
  // src/bind.render.mjs
609
616
  function field(context) {
610
617
  if (context.templates?.length) {
@@ -617,7 +624,7 @@
617
624
  } else if (this.options.renderers["*"]) {
618
625
  this.options.renderers["*"].call(this, context);
619
626
  if (this.options.twoway) {
620
- const s = domSignal(context.element);
627
+ const s = signal2(context.element);
621
628
  effect(() => {
622
629
  setValueByPath(this.options.root, context.path, s.innerHTML);
623
630
  });
@@ -1420,7 +1427,7 @@
1420
1427
  let result = {};
1421
1428
  for (let key of Object.keys(this.state.options.columns)) {
1422
1429
  if (!this.state.options.columns[key]?.hidden) {
1423
- result[key] = input2[key];
1430
+ result[key] = input2[key] ?? null;
1424
1431
  }
1425
1432
  }
1426
1433
  return result;
@@ -1526,7 +1533,8 @@
1526
1533
  Object.assign(globalThis.simply, {
1527
1534
  bind,
1528
1535
  flow: model_exports,
1529
- state: state_exports
1536
+ state: state_exports,
1537
+ dom: dom_exports
1530
1538
  });
1531
1539
  var flow_default = globalThis.simply;
1532
1540
  })();
@@ -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 Ee=Object.defineProperty;var U=(e,t)=>{for(var n in t)Ee(e,n,{get:t[n],enumerable:!0})};var G={};U(G,{addTracer:()=>Le,batch:()=>K,clockEffect:()=>oe,destroy:()=>$,effect:()=>le,makeContext:()=>y,notifyGet:()=>A,notifySet:()=>w,signal:()=>v,signals:()=>c,throttledEffect:()=>T,trace:()=>ke,untracked:()=>Ce,unwrap:()=>_});var W=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 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"?v(r):r},set:(e,t,n,r)=>{n=n?.[Symbol.xRay]||n,_(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 v(e){if(_(e),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,Me));return c.get(e)}var I=[],P=!1;function ke(e,t){if(typeof e=="function")P=!0,e(),P=!1;else return se(e,t).map(r=>({effect:r.effectType,fn:r.effectFunction,signal:c.get(r.effectFunction)}))}function Le(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 re(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=se(e,i);if(s?.length){for(let l of s)Oe(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&&re("set",e,t,i),i()),ie(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 Oe(e,t){e.context?t.forEach((n,r)=>{e.context.set(r,n)}):e.context=t,e.needsUpdate=!0}function ie(e){delete e.context,delete e.needsUpdate}function A(e,t){if(q)return;let n=m[m.length-1];n&&(P&&I.length&&re("get",e,t),je(e,t,n))}var L=new WeakMap,B=new WeakMap;function se(e,t){let n=L.get(e);return n?Array.from(n.get(t)||[]):[]}function je(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 le(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=v({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=le,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||ne()}):(M--,M||ne())}return t}function ne(){let e=Array.from(H);H=new Set;let t=m[m.length-1];for(let n of e)n!=t&&n?.needsUpdate&&n(),ie(n)}function T(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=v({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=T,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 oe(e,t){let n=c.get(e);n||(n=v({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=oe,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 Ce(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 _(e){e&&typeof e=="object"&&(R=new WeakMap,D(e),R=null)}function ae(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 fe(e,t){typeof e.value=="string"?e.value={}:delete e.value?.innerHTML,t(e)}var Q={};U(Q,{signal:()=>J});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"?v(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 J(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 ue=new WeakMap;function Pe(e,t){let n=e.innerHTML,r=e.innerText;if(!ue.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}),ue.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 pe(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=J(e.element);effect(()=>{He(this.options.root,e.path,t.innerHTML)})}return e}function de(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 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?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 me(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 ye(e){O(e),E(e.element,e.value,"value")}function X(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&&X(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 ze(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 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 Z=class{constructor(t){this.bindings=new Map;let n={escape_html:ae,fixed_content:fe},r={container:document.body,attribute:"data-flow",transformers:n,render:{field:[pe],list:[de],map:[he]},renderers:{INPUT:me,BUTTON:ye,SELECT:X,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({},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,T(()=>{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=Y(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,Se)=>Ae=>Se.call(this,Ae,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=Y(this.options.root,f):p=Y(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 Z(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 Y(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 ee={};U(ee,{columns:()=>_e,filter:()=>Ke,model:()=>We,paging:()=>De,scroll:()=>Ge,sort:()=>Ve});var x=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=v(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 x(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),T(()=>{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),T(()=>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,T(()=>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,T(()=>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))}),T(()=>{n.size=t.current.length*n.rowHeight,r.style.height=n.size+"px"},50)),T(()=>{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 te=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",te);globalThis.simply||(globalThis.simply={});Object.assign(globalThis.simply,{bind:ve,flow:ee,state:G,dom:Q});var lt=globalThis.simply;})();
2
2
  //# sourceMappingURL=simply.flow.min.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/state.mjs", "../src/bind.transformers.mjs", "../src/bind.render.mjs", "../src/bind.mjs", "../src/model.mjs", "../src/render.mjs", "../src/flow.mjs"],
4
- "sourcesContent": ["const iterate = Symbol('iterate')\nif (!Symbol.xRay) {\n Symbol.xRay = Symbol('xRay')\n}\nif (!Symbol.Signal) {\n Symbol.Signal = Symbol('Signal')\n}\n\nconst signalHandler = {\n get: (target, property, receiver) => {\n if (property===Symbol.xRay) {\n return target // don't notifyGet here, this is only called by set\n }\n if (property===Symbol.Signal) {\n return true\n }\n const value = target?.[property] // Reflect.get fails on a Set.\n notifyGet(receiver, property)\n if (typeof value === 'function') {\n if (Array.isArray(target)) {\n return (...args) => {\n let l = target.length\n // by binding the function to the receiver\n // all accesses in the function will be trapped\n // by the Proxy, so get/set/delete is all handled\n let result = value.apply(receiver, args)\n if (l != target.length) {\n notifySet(receiver, makeContext('length', { was: l, now: target.length }) )\n }\n return result\n }\n } else if (target instanceof Set || target instanceof Map) {\n return (...args) => {\n // node doesn't allow you to call set/map functions\n // bound to the receiver.. so using target instead\n // there are no properties to update anyway, except for size\n let s = target.size\n let result = value.apply(target, args)\n if (s != target.size) {\n notifySet(receiver, makeContext( 'size', { was: s, now: target.size }) )\n }\n // there is no efficient way to see if the function called\n // has actually changed the Set/Map, but by assuming the\n // 'setter' functions will change the results of the\n // 'getter' functions, effects should update correctly\n if (['set','add','clear','delete'].includes(property)) {\n notifySet(receiver, makeContext( { entries: {}, forEach: {}, has: {}, keys: {}, values: {}, [Symbol.iterator]: {} } ) )\n }\n return result\n }\n } else if (\n target instanceof HTMLElement\n || target instanceof Number\n || target instanceof String\n || target instanceof Boolean\n ) {\n return value.bind(target)\n } else {\n // support custom classes, hopefully\n return value.bind(receiver)\n }\n }\n if (value && typeof value == 'object') {\n return signal(value)\n }\n return value\n },\n set: (target, property, value, receiver) => {\n value = value?.[Symbol.xRay] || value // unwraps signal\n //FIXME: if value contains child objects, these may be signals as well... so do this recursively\n unwrap(value)\n let current = target[property]\n if (current!==value) {\n target[property] = value\n notifySet(receiver, makeContext(property, { was: current, now: value } ) )\n }\n if (typeof current === 'undefined') {\n notifySet(receiver, makeContext(iterate, {}))\n }\n return true\n },\n has: (target, property) => { // receiver is not part of the has() call\n let receiver = signals.get(target) // so retrieve it here\n if (receiver) {\n notifyGet(receiver, property)\n }\n return Object.hasOwn(target, property)\n },\n deleteProperty: (target, property) => {\n if (typeof target[property] !== 'undefined') {\n let current = target[property]\n delete target[property]\n let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here\n notifySet(receiver, makeContext(property,{ delete: true, was: current }))\n }\n return true\n },\n defineProperty: (target, property, descriptor) => {\n if (typeof target[property] === 'undefined') {\n let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here\n notifySet(receiver, makeContext(iterate, {}))\n }\n return Object.defineProperty(target, property, descriptor)\n },\n ownKeys: (target) => {\n let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here\n notifyGet(receiver, iterate)\n return Reflect.ownKeys(target)\n }\n\n}\n\n/**\n * Keeps track of the return signal for an update function, as well\n * as signals connected to other objects. \n * Makes sure that a given object or function always uses the same\n * signal\n */\nconst signals = new WeakMap()\n\n/**\n * Creates a new signal proxy of the given object, that intercepts get/has and set/delete\n * to allow reactive functions to be triggered when signal values change.\n */\nexport function signal(v) {\n unwrap(v)\n if (v[Symbol.Signal]) { // avoid wrapping a Signal inside a Signal\n let target = v[Symbol.xRay]\n if (!signals.has(target)) {\n signals.set(target, v)\n }\n v = target\n } else if (!signals.has(v)) {\n signals.set(v, new Proxy(v, signalHandler))\n }\n return signals.get(v)\n}\n\nconst domSignalHandler = {\n get: (target, property, receiver) => {\n if (property===Symbol.xRay) {\n return target // don't notifyGet here, this is only called by set\n }\n if (property===Symbol.Signal) {\n return true\n }\n const value = target?.[property]\n domListen(target, receiver)\n notifyGet(receiver, property)\n if (typeof value === 'function') {\n return value.bind(target) // make sure element functions are not linked to the proxy\n }\n if (value && typeof value == 'object') {\n return signal(value)\n }\n return value\n },\n has: (target, property) => {\n let receiver = signals.get(target)\n if (receiver) {\n domListen(target, receiver)\n notifyGet(receiver, property)\n }\n return Object.hasOwn(target, property)\n },\n ownKeys: (target) => {\n let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here\n if (receiver) {\n domListen(target, receiver)\n notifyGet(receiver, iterate)\n }\n return Reflect.ownKeys(target)\n }\n}\n\nexport function domSignal(el) {\n if (el[Symbol.xRay]) {\n return el\n }\n if (!signals.has(el)) {\n signals.set(el, new Proxy(el, domSignalHandler))\n }\n return signals.get(el)\n}\n\nlet tracers = []\nlet tracing = false\n/**\n * @param Signal|Function signal\n * If given a singal and property, this function lists all effects \n * that are currently listening to changes to that signal and property\n * returns a list with \n * - effect: the effect function (effect, throttledEffect, clockEffect)\n * - fn: the user provided function to this effect function\n * - signal: the connectedSignal to this user provided function\n * @param string prop \n * @return array of { effect, fn, signal }\n * \n * If given a function, it will enable any tracers added with addTracer\n * call the given function and then disable all tracers.\n * @return void\n */\nexport function trace(signal, prop) {\n if (typeof signal==='function') {\n tracing = true\n signal()\n tracing = false\n } else {\n const listeners = getListeners(signal, prop)\n return listeners.map(listener => {\n return {\n effect: listener.effectType,\n fn: listener.effectFunction,\n signal: signals.get(listener.effectFunction)\n }\n })\n }\n}\n\n/**\n * Adds a tracer. This is an object with a 'set' and/or 'get' function.\n * If enabled (with the trace() method) each access to notifyGet will \n * call the 'get' function. Each access to notifySet will call the 'set'\n * function.\n * @param tracer { get: fn, set: fn }\n * get: function(signal, property)\n * set: function(signal, context, listener)\n */\nexport function addTracer(tracer) {\n if (!tracer.get && !tracer.set) {\n throw new Error('simply.state: addTracer: missing \"get\" or \"set\" property in tracer', tracer)\n }\n if (tracer.get && typeof tracer.get!=='function') {\n throw new Error('simply.state: addTracer: \"get\" is not a function', tracer)\n }\n if (tracer.set && typeof tracer.set!=='function') {\n throw new Error('simply.state: addTracer: \"set\" is not a function', tracer)\n }\n tracers.push(tracer)\n}\n\nfunction callTracers(getset, ...params) {\n for (const tracer of tracers) {\n if (tracer[getset]) {\n tracer[getset](...params)\n }\n }\n}\n\nlet batchedListeners = new Set()\nlet batchMode = 0\n/**\n * Called when a signal changes a property (set/delete)\n * Triggers any reactor function that depends on this signal\n * to re-compute its values\n */\nfunction notifySet(self, context={}) {\n if (disableTracking) {\n return\n }\n let listeners = []\n context.forEach((change, property) => {\n let propListeners = getListeners(self, property)\n if (propListeners?.length) {\n for (let listener of propListeners) {\n addContext(listener, makeContext(property,change))\n }\n listeners = listeners.concat(propListeners)\n }\n })\n listeners = new Set(listeners.filter(Boolean))\n if (listeners) {\n if (batchMode) {\n batchedListeners = batchedListeners.union(listeners)\n } else {\n const currentEffect = computeStack[computeStack.length-1]\n for (let listener of Array.from(listeners)) {\n if (listener!=currentEffect && listener?.needsUpdate) {\n if (tracing && tracers.length) {\n callTracers('set', self, context, listener)\n }\n listener()\n }\n clearContext(listener)\n }\n }\n }\n}\n\nconst observers = new WeakMap()\n\nfunction domListen(el, signal) {\n let oldContentHTML = el.innerHTML\n let oldContentText = el.innerText\n if (!observers.has(el)) {\n const observer = new MutationObserver((mutationList, observer) => {\n // collect changes\n const changes = {}\n for (const mutation of mutationList) {\n if (mutation.type==='attributes') {\n // check if any listeners for each attribute\n changes[mutation.attributeName] = mutation.attributeOldValue\n } else if (mutation.type==='subtree' || mutation.type==='characterData') {\n // change on innerHTML/innerText\n if (el.innerHTML != oldContentHTML) {\n changes.innerHTML = oldContentHTML\n oldContentHTML = el.innerHTML\n }\n if (el.innerText != oldContentText) {\n changes.innerText = oldContentText\n oldContentText = el.innerText\n }\n }\n }\n for (const prop in changes) {\n notifySet(signal, makeContext(prop, { was: changes[prop], now: el[prop] }))\n }\n })\n observer.observe(el, {\n characterData: true,\n subtree: true,\n attributes: true,\n attributesOldValue: true\n })\n observers.set(el, observer)\n //@TODO: unregister the observer when el is removed from the dom (after a timeout)\n }\n}\n\nfunction makeContext(property, change) {\n let context = new Map()\n if (typeof property === 'object') {\n for (let prop in property) {\n context.set(prop, property[prop])\n }\n } else {\n context.set(property, change)\n }\n return context\n}\n\nfunction addContext(listener, context) {\n if (!listener.context) {\n listener.context = context\n } else {\n context.forEach((change,property)=> {\n listener.context.set(property, change) // TODO: merge change if needed\n })\n }\n listener.needsUpdate = true\n}\n\nfunction clearContext(listener) {\n delete listener.context\n delete listener.needsUpdate\n}\n\n/**\n * Called when a signal property is accessed. If this happens\n * inside a reactor function--computeStack is not empty--\n * then it adds the current reactor (top of this stack) to its\n * listeners. These are later called if this property changes\n */\nfunction notifyGet(self, property) {\n if (disableTracking) {\n return\n }\n let currentCompute = computeStack[computeStack.length-1]\n if (currentCompute) {\n if (tracing && tracers.length) {\n callTracers('get', self, property)\n }\n // get was part of a react() function, so add it\n setListeners(self, property, currentCompute)\n }\n}\n\n/**\n * Keeps track of which update() functions are dependent on which\n * signal objects and which properties. Maps signals to update fns\n */\nconst listenersMap = new WeakMap()\n\n/**\n * Keeps track of which signals and properties are linked to which\n * update functions. Maps update functions and properties to signals\n */\nconst computeMap = new WeakMap()\n\n/**\n * Returns the update functions for a given signal and property\n */\nfunction getListeners(self, property) {\n let listeners = listenersMap.get(self)\n return listeners ? Array.from(listeners.get(property) || []) : []\n}\n\n/**\n * Adds an update function (compute) to the list of listeners on\n * the given signal (self) and property\n */\nfunction setListeners(self, property, compute) {\n if (!listenersMap.has(self)) {\n listenersMap.set(self, new Map())\n }\n let listeners = listenersMap.get(self)\n if (!listeners.has(property)) {\n listeners.set(property, new Set())\n }\n listeners.get(property).add(compute)\n\n if (!computeMap.has(compute)) {\n computeMap.set(compute, new Map())\n }\n let connectedSignals = computeMap.get(compute)\n if (!connectedSignals.has(property)) {\n connectedSignals.set(property, new Set)\n }\n connectedSignals.get(property).add(self)\n}\n\n/**\n * Removes alle listeners that trigger the given reactor function (compute)\n * This happens when a reactor is called, so that it can set new listeners\n * based on the current call (code path)\n */\nfunction clearListeners(compute) {\n let connectedSignals = computeMap.get(compute)\n if (connectedSignals) {\n connectedSignals.forEach(property => {\n property.forEach(s => {\n let listeners = listenersMap.get(s)\n if (listeners.has(property)) {\n listeners.get(property).delete(compute)\n }\n })\n })\n }\n}\n\n/**\n * The top most entry is the currently running update function, used\n * to automatically record signals used in an update function.\n */\nlet computeStack = []\n\n/**\n * Used for cycle detection: effectStack contains all running effect\n * functions. If the same function appears twice in this stack, there\n * is a recursive update call, which would cause an infinite loop.\n */\nconst effectStack = []\n\nconst effectMap = new WeakMap()\n/**\n * Used for cycle detection: signalStack contains all used signals. \n * If the same signal appears more than once, there is a cyclical \n * dependency between signals, which would cause an infinite loop.\n */\nconst signalStack = []\n\n/**\n * Runs the given function at once, and then whenever a signal changes that\n * is used by the given function (or at least signals used in the previous run).\n */\nexport function effect(fn) {\n if (effectStack.findIndex(f => fn==f)!==-1) {\n throw new Error('Recursive update() call', {cause:fn})\n }\n effectStack.push(fn)\n\n let connectedSignal = signals.get(fn)\n if (!connectedSignal) {\n connectedSignal = signal({\n current: null\n })\n signals.set(fn, connectedSignal)\n }\n\n // this is the function that is called automatically\n // whenever a signal dependency changes\n const computeEffect = function computeEffect() {\n if (signalStack.findIndex(s => s==connectedSignal)!==-1) {\n throw new Error('Cyclical dependency in update() call', { cause: fn})\n }\n // remove all dependencies (signals) from previous runs \n clearListeners(computeEffect)\n computeEffect.effectFunction = fn\n computeEffect.effectType = effect\n // record new dependencies on this run\n computeStack.push(computeEffect)\n // prevent recursion\n signalStack.push(connectedSignal)\n // call the actual update function\n let result\n try {\n result = fn(computeEffect, computeStack, signalStack)\n } finally {\n // stop recording dependencies\n computeStack.pop()\n // stop the recursion prevention\n signalStack.pop()\n if (result instanceof Promise) {\n result.then((result) => {\n connectedSignal.current = result\n })\n } else {\n connectedSignal.current = result\n }\n }\n }\n computeEffect.fn = fn\n effectMap.set(connectedSignal, computeEffect)\n\n // run the computEffect immediately upon creation\n computeEffect()\n return connectedSignal\n}\n\n\nexport function destroy(connectedSignal) {\n // find the computeEffect associated with this signal\n const computeEffect = effectMap.get(connectedSignal)?.deref()\n if (!computeEffect) {\n return\n }\n\n // remove all listeners for this effect\n clearListeners(computeEffect)\n\n // remove all references to connectedSignal\n let fn = computeEffect.fn\n signals.remove(fn)\n\n effectMap.delete(connectedSignal)\n\n // if no other references to connectedSignal exist, it will be garbage collected\n}\n\n/**\n * Inside a batch() call, any changes to signals do not trigger effects\n * immediately. Instead, immediately after finishing the batch() call,\n * these effects will be called. Effects that are triggered by multiple\n * signals are called only once.\n * @param Function fn batch() calls this function immediately\n * @result mixed the result of the fn() function call\n */\nexport function batch(fn) {\n batchMode++\n let result\n try {\n result = fn()\n } finally {\n if (result instanceof Promise) {\n result.then(() => {\n batchMode--\n if (!batchMode) {\n runBatchedListeners()\n }\n })\n } else {\n batchMode--\n if (!batchMode) {\n runBatchedListeners()\n }\n }\n }\n return result\n}\n\nfunction runBatchedListeners() {\n let copyBatchedListeners = Array.from(batchedListeners)\n batchedListeners = new Set()\n const currentEffect = computeStack[computeStack.length-1]\n for (let listener of copyBatchedListeners) {\n if (listener!=currentEffect && listener?.needsUpdate) {\n listener()\n }\n clearContext(listener)\n }\n}\n\n/**\n * A throttledEffect is run immediately once. And then only once\n * per throttleTime (in ms).\n * @param Function fn the effect function to run whenever a signal changes\n * @param int throttleTime in ms\n * @returns signal with the result of the effect function fn\n */\nexport function throttledEffect(fn, throttleTime) {\n if (effectStack.findIndex(f => fn==f)!==-1) {\n throw new Error('Recursive update() call', {cause:fn})\n }\n effectStack.push(fn)\n\n let connectedSignal = signals.get(fn)\n if (!connectedSignal) {\n connectedSignal = signal({\n current: null\n })\n signals.set(fn, connectedSignal)\n }\n\n let throttled = false\n let hasChange = true\n // this is the function that is called automatically\n // whenever a signal dependency changes\n const computeEffect = function computeEffect() {\n if (signalStack.findIndex(s => s==connectedSignal)!==-1) {\n throw new Error('Cyclical dependency in update() call', { cause: fn})\n }\n if (throttled && throttled>Date.now()) {\n hasChange = true\n return\n }\n // remove all dependencies (signals) from previous runs \n clearListeners(computeEffect)\n // record new dependencies on this run\n computeEffect.effectFunction = fn\n computeEffect.effectType = throttledEffect\n computeStack.push(computeEffect)\n // prevent recursion\n signalStack.push(connectedSignal)\n // call the actual update function\n let result\n try {\n result = fn(computeEffect, computeStack, signalStack)\n } finally {\n hasChange = false\n // stop recording dependencies\n computeStack.pop()\n // stop the recursion prevention\n signalStack.pop()\n if (result instanceof Promise) {\n result.then((result) => {\n connectedSignal.current = result\n })\n } else {\n connectedSignal.current = result\n }\n }\n throttled = Date.now()+throttleTime\n globalThis.setTimeout(() => {\n if (hasChange) {\n computeEffect()\n }\n }, throttleTime)\n }\n // run the computEffect immediately upon creation\n computeEffect()\n return connectedSignal\n}\n\n// refactor: Class clock() with an effect() method\n// keep track of effects per clock, and add clock property to the effect function\n// on notifySet add clock.effects to clock.needsUpdate list\n// on clock.tick() (or clock.time++) run only the clock.needsUpdate effects \n// (first create a copy and reset clock.needsUpdate, then run effects)\nexport function clockEffect(fn, clock) {\n let connectedSignal = signals.get(fn)\n if (!connectedSignal) {\n connectedSignal = signal({\n current: null\n })\n signals.set(fn, connectedSignal)\n }\n\n let lastTick = -1 // clock.time should start at 0 or larger\n let hasChanged = true // make sure the first run goes through\n // this is the function that is called automatically\n // whenever a signal dependency changes\n const computeEffect = function computeEffect() {\n if (lastTick < clock.time) {\n if (hasChanged) {\n // remove all dependencies (signals) from previous runs \n clearListeners(computeEffect)\n computeEffect.effectFunction = fn\n computeEffect.effectType = clockEffect\n // record new dependencies on this run\n computeStack.push(computeEffect)\n // make sure the clock.time signal is a dependency\n lastTick = clock.time\n // call the actual update function\n let result \n try {\n result = fn(computeEffect, computeStack)\n } finally {\n // stop recording dependencies\n computeStack.pop()\n if (result instanceof Promise) {\n result.then((result) => {\n connectedSignal.current = result\n })\n } else {\n connectedSignal.current = result\n }\n hasChanged = false\n }\n } else {\n lastTick = clock.time\n }\n } else {\n hasChanged = true\n }\n }\n // run the computEffect immediately upon creation\n computeEffect()\n return connectedSignal\n}\n\nlet disableTracking = false\nexport function untracked(fn) {\n disableTracking = true\n try {\n return fn()\n } finally {\n disableTracking = false\n }\n}\n\nlet seen = new WeakMap()\n\nfunction innerUnwrap(ob) {\n if (!ob || typeof ob!=='object' || seen.has(ob)) {\n return\n }\n seen.set(ob, true)\n for (const prop in ob) {\n if (ob[prop]?.[Symbol.Signal]) {\n ob[prop] = ob[prop][Symbol.xRay]\n }\n if (Array.isArray(ob[prop])) {\n for (const [key, value] of Object.entries(ob[prop])) {\n if (value && typeof value==='object') {\n innerUnwrap(value)\n }\n }\n } else if (ob[prop] && typeof ob[prop] === 'object') {\n innerUnwrap(ob[prop])\n }\n }\n}\n\nexport function unwrap(ob) {\n if (ob && typeof ob==='object') {\n seen = new WeakMap()\n innerUnwrap(ob)\n seen = null\n }\n}\n", "export function escape_html(context, next) {\n let content = context.value?.innerHTML\n if (typeof context.value == 'string') {\n content = context.value\n context.value = { innerHTML: content }\n }\n if (content) {\n content = content.replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#39;');\n context.value.innerHTML = content\n }\n next(context)\n}\n\nexport function fixed_content(context, next) {\n if (typeof context.value == 'string') {\n context.value = {}\n } else {\n delete context.value?.innerHTML\n }\n next(context)\n}\n", "/*\n * Default renderers for data binding\n * Will be used unless overriden in the SimplyBind options parameter\n */\nimport { domSignal } from './state.mjs'\n\n/**\n * This function is used by default to render dom elements with the `data-flow-field` attribute.\n * It will switch to only switching in template content if the context has any templates.\n * Otherwise it will call the matching render function depending on the tagName of the\n * context.element\n */\nexport function field(context)\n{\n if (context.templates?.length) {\n fieldByTemplates.call(this, context)\n // TODO: check if existence of one or more templates must mean that\n // only the template rendering is applied, instead of also rendering attributes\n } else if (Object.hasOwnProperty.call(this.options.renderers, context.element.tagName)) {\n const renderer = this.options.renderers[context.element.tagName]\n if (renderer) {\n renderer.call(this, context)\n }\n } else if (this.options.renderers['*']) {\n this.options.renderers['*'].call(this, context)\n // FIXME: should call a setter (defined in field type) to set the value back into root data\n if (this.options.twoway) { \n // TODO: make content-editable if editmode is toggled on\n // how do you toggle editmode? global signal?\n // make uneditable if editmode is toggled off\n const s = domSignal(context.element)\n effect(() => {\n setValueByPath(this.options.root, context.path, s.innerHTML)\n })\n }\n }\n return context\n}\n\n/**\n * This function is used by default to render DOM elements with the `data-flow-list` attribute.\n * The context.value must be an array. And context.templates must not be empty.\n */\nexport function list(context)\n{\n if (!Array.isArray(context.value)) {\n context.value = [context.value]\n }\n if (!context.templates?.length) {\n console.error('No templates found in', context.element)\n } else {\n arrayByTemplates.call(this, context)\n }\n return context\n}\n\n/**\n * This function is used by default to render DOM elements with the `data-flow-map` attribute.\n * The context.value must be a non-null object. And context.templates must not be empty.\n */\nexport function map(context)\n{\n if (typeof context.value != 'object' || !context.value) {\n console.error('Value is not an object.', context.element, context.path, context.value)\n } else if (!context.templates?.length) {\n console.error('No templates found in', context.element)\n } else {\n objectByTemplates.call(this, context)\n }\n return context\n}\n\nexport function setValueByPath(root, path, value)\n{\n let parts = path.split('.')\n let curr = root\n let part\n part = parts.shift()\n let prev = null\n let prevPart = null\n while (part && curr) {\n part = decodeURIComponent(part)\n if (part=='0' && !Array.isArray(curr)) {\n // ignore so that data-flow-list=\"nonarray\" will work\n } else if (part==':key') {\n // FIXME: should change the key, not the value... not supported yet?\n throw new Error('setting key not yet supported')\n curr = prevPart\n } else if (part==':value') {\n // do nothing\n } else if (Array.isArray(curr) && typeof curr[part]=='undefined') {\n prev = curr[0]\n curr = curr[0][part] // so that data-flow-field=\"array.foo\" works\n } else {\n prev = curr\n curr = curr[part]\n }\n prevPart = part\n part = parts.shift()\n }\n if (prev && prevPart && prev[prevPart]!==value) {\n prev[prevPart] = value\n }\n}\n\n/**\n * Renders an array value by applying templates for each entry\n * Replaces or removes existing DOM children if needed\n * Reuses (doesn't touch) DOM children if template doesn't change\n * FIXME: this doesn't handle situations where there is no matching template\n * this messes up self healing. check renderObjectByTemplates for a better implementation\n */\nexport function arrayByTemplates(context)\n{\n const attribute = this.options.attribute\n\n let items = context.element.querySelectorAll(':scope > ['+attribute+'-key]')\n // do single merge strategy for now, in future calculate optimal merge strategy from a number\n // now just do a delete if a key <= last key, insert if a key >= last key\n let lastKey = 0\n let skipped = 0\n context.list = context.value\n for (let item of items) {\n let currentKey = parseInt(item.getAttribute(attribute+'-key'))\n if (currentKey>lastKey) {\n // insert before\n context.index = lastKey\n context.element.insertBefore(this.applyTemplate(context), item)\n } else if (currentKey<lastKey) {\n // remove this\n item.remove()\n } else {\n // check that all data-bind params start with current json path or ':root', otherwise replaceChild\n let bindings = Array.from(item.querySelectorAll(`[${attribute}]`))\n if (item.matches(`[${attribute}]`)) {\n bindings.unshift(item)\n }\n let needsReplacement = bindings.find(b => {\n let databind = b.getAttribute(attribute)\n return (databind.substr(0,5)!==':root' \n && databind.substr(0, context.path.length)!==context.path)\n })\n if (!needsReplacement) {\n if (item[Symbol.bindTemplate]) {\n let newTemplate = this.findTemplate(context.templates, context.list[lastKey])\n if (newTemplate != item[Symbol.bindTemplate]){\n needsReplacement = true\n if (!newTemplate) {\n skipped++\n }\n }\n }\n }\n if (needsReplacement) {\n context.index = lastKey\n context.element.replaceChild(this.applyTemplate(context), item)\n }\n }\n lastKey++\n if (lastKey>=context.value.length) {\n break\n }\n }\n items = context.element.querySelectorAll(':scope > ['+attribute+'-key]')\n let length = items.length + skipped\n if (length > context.value.length) {\n while (length > context.value.length) {\n let child = context.element.querySelectorAll(':scope > :not(template)')?.[length-1]\n child?.remove()\n length--\n }\n } else if (length < context.value.length ) {\n while (length < context.value.length) {\n context.index = length\n context.element.appendChild(this.applyTemplate(context))\n length++\n }\n }\n}\n\n/**\n * Renders an object value by applying templates for each entry (Object.entries)\n * Replaces,moves or removes existing DOM children if needed\n * Reuses (doesn't touch) DOM children if template doesn't change\n */\nexport function objectByTemplates(context)\n{\n const attribute = this.options.attribute\n context.list = context.value\n\n let items = Array.from(context.element.querySelectorAll(':scope > ['+attribute+'-key]'))\n for (let key in context.list) {\n context.index = key\n let item = items.shift()\n if (!item) { // more properties than rendered items\n let clone = this.applyTemplate(context)\n context.element.appendChild(clone)\n continue\n }\n if (item.getAttribute[attribute+'-key']!=key) { \n // next item doesn't match key\n items.unshift(item) // put item back for next cycle\n let outOfOrderItem = context.element.querySelector(':scope > ['+attribute+'-key=\"'+key+'\"]') //FIXME: escape key\n if (!outOfOrderItem) {\n let clone = this.applyTemplate(context)\n context.element.insertBefore(clone, item)\n continue // new template doesn't need replacement, so continue \n } else {\n context.element.insertBefore(outOfOrderItem, item)\n item = outOfOrderItem // check needsreplacement next\n items = items.filter(i => i!=outOfOrderItem)\n }\n }\n let newTemplate = this.findTemplate(context.templates, context.list[context.index])\n if (newTemplate != item[Symbol.bindTemplate]){\n let clone = this.applyTemplate(context)\n context.element.replaceChild(clone, item)\n }\n }\n // clean up remaining items\n while (items.length) {\n let item = items.shift()\n item.remove()\n }\n}\n\n/**\n * renders the contents of an html element by rendering\n * a matching template, once.\n */\nexport function fieldByTemplates(context)\n{\n const rendered = context.element.querySelector(':scope > :not(template)')\n const template = this.findTemplate(context.templates, context.value)\n context.parent = getParentPath(context.element)\n if (rendered) {\n if (template) {\n if (rendered?.[Symbol.bindTemplate] != template) {\n const clone = this.applyTemplate(context)\n context.element.replaceChild(clone, rendered)\n }\n } else {\n context.element.removeChild(rendered)\n }\n } else if (template) {\n const clone = this.applyTemplate(context)\n context.element.appendChild(clone)\n }\n}\n\nfunction getParentPath(el, attribute)\n{\n const parentEl = el.parentElement?.closest(`[${attribute}-list],[${attribute}-map]`)\n if (!parentEl) {\n return ''\n }\n if (parentEl.hasAttribute(`${attribute}-list`)) {\n return parentEl.getAttribute(`${attribute}-list`)+'.'\n }\n return parentEl.getAttribute(`${attribute}-map`)+'.'\n}\n\n/**\n * renders a single input type\n * for radio/checkbox inputs it only sets the checked attribute to true/false\n * if the value attribute matches the current value\n * for other inputs the value attribute is updated\n */\nexport function input(context)\n{\n const el = context.element\n let value = context.value\n\n element(context)\n if (typeof value == 'undefined') {\n value = ''\n }\n if (el.type=='checkbox' || el.type=='radio') {\n if (matchValue(el.value, value)) {\n el.checked = true\n } else {\n el.checked = false\n }\n } else if (!matchValue(el.value, value)) {\n el.value = ''+value\n }\n}\n\n/**\n * Sets the value of the button, doesn't touch the innerHTML\n */\nexport function button(context)\n{\n element(context)\n setProperties(context.element, context.value, 'value')\n}\n\n/**\n * Sets the selected attribute of select options\n */\nexport function select(context)\n{\n const el = context.element\n let value = context.value\n\n if (value === null) {\n value = ''\n }\n if (typeof value!='object') {\n if (el.multiple) {\n if (Array.isArray(value)) { //FIXME: cannot be true, since typeof != 'object'\n for (let option of el.options) {\n if (value.indexOf(option.value)===false) {\n option.selected = false\n } else {\n option.selected = true\n }\n }\n }\n } else {\n let option = el.options.find(o => matchValue(o.value,value))\n if (option) {\n option.selected = true\n option.setAttribute('selected', true)\n }\n }\n } else { // value is a non-null object\n if (value.options) {\n setSelectOptions(el, value.options)\n }\n if (value.selected) {\n select(Object.asssign({}, context, {value:value.selected}))\n }\n setProperties(el, value, 'name', 'id', 'selectedIndex', 'className') // allow innerHTML? if so call element instead\n }\n}\n\n/**\n * adds a single option to a select element. The option.text property is optional, if not set option.value is used.\n * @param select The select element\n * @param option An option descriptor, either a string, object with {text,value,defaultSelected,selected} properties or an Option object\n */\nexport function addOption(select, option)\n{\n if (!option) {\n return\n }\n if (typeof option !== 'object') {\n select.options.add(new Option(''+option))\n } else if (option.text) {\n select.options.add(new Option(option.text, option.value, option.defaultSelected, option.selected))\n } else if (typeof option.value != 'undefined') {\n select.options.add(new Option(''+option.value, option.value, option.defaultSelected, option.selected))\n }\n}\n\n/**\n * This function clears all existing options of a select element, and adds the specified options.\n */\nexport function setSelectOptions(select,options)\n{\n //@TODO: only update in case of changes?\n select.innerHTML = ''\n if (Array.isArray(options)) {\n for (const option of options) {\n addOption(select, option)\n }\n } else if (options && typeof options == 'object') {\n for (const option in options) {\n addOption(select, { text: options[option], value: option })\n }\n }\n}\n\n/**\n * Sets the innerHTML and href, id, title, target, name, newwindow, nofollow attributes of an anchor\n */\nexport function anchor(context)\n{\n element(context)\n setProperties(context.element, context.value, 'target', 'href', 'name', 'newwindow', 'nofollow')\n}\n\n/**\n * Sets the title, id, alt and src attributes of an image.\n */\nexport function image(context)\n{\n setProperties(context.element, context.value, 'title', 'alt', 'src', 'id')\n}\n\n/**\n * Sets the title, id and src attribute of an iframe\n */\nexport function iframe(context)\n{\n setProperties(context.element, context.value, 'title', 'src', 'id')\n}\n\n/**\n * Sets the content and id attribute of a meta element\n */\nexport function meta(context)\n{\n setProperties(context.element, context.value, 'content', 'id') \n}\n\n/**\n * sets the innerHTML and title and id properties of any HTML element\n */\nexport function element(context)\n{\n const el = context.element\n let value = context.value\n\n if (typeof value=='undefined' || value==null) {\n value = ''\n }\n let strValue = ''+value\n if (typeof value!='object' || strValue.substring(0,8)!='[object ') {\n value = { innerHTML: value }\n }\n setProperties(el, value, 'innerHTML', 'title', 'id', 'className')\n}\n\n/**\n * Sets a list of properties on a dom element, equal to \n * the string value of a data object\n * only updates the dom element if the property doesn't match\n */\nexport function setProperties(el, data, ...properties) {\n if (!data || typeof data!=='object') {\n return\n }\n for (const property of properties) {\n if (typeof data[property] === 'undefined') {\n continue\n }\n if (matchValue(el[property], data[property])) {\n continue\n }\n if (data[property] === null) {\n el[property] = ''\n } else {\n el[property] = ''+data[property]\n }\n }\n}\n\n/**\n * Returns true if a matches b, either by having the\n * same string value, or matching string :empty against a falsy value\n */\nexport function matchValue(a,b)\n{\n if (a==':empty' && !b) {\n return true\n }\n if (b==':empty' && !a) {\n return true\n }\n if (''+a == ''+b) {\n return true\n }\n return false\n}\n", "import { throttledEffect, destroy } from './state.mjs'\nimport { escape_html, fixed_content } from './bind.transformers.mjs'\nimport * as render from './bind.render.mjs'\n\nif (!Symbol.bindTemplate) {\n Symbol.bindTemplate = Symbol('bindTemplate')\n}\n\n/**\n * Implements one way databinding, updating dom elements with matching attributes\n * to changes in signals (see state.mjs)\n * \n * @class\n */\nclass SimplyBind\n{\n \n /**\n * @param Object options - a set of options for this instance, options may include:\n * - root (signal) (required) - the root data object that contains al signals that can be bound\n * - container (HTMLElement) - the dom element to use as the root for all bindings\n * - attribute (string) - the prefix for the field, list and map attributes, e.g. 'data-bind'\n * - transformers (object name:function) - a map of transformer names and functions\n * - render (object with field, list and map properties)\n */\n constructor(options)\n {\n /**\n * A map of HTMLElements and the data bindings on each, in the form of \n * the connectedSignal returned by the (throttled)Effect.\n * @type {Map}\n * @public\n */\n this.bindings = new Map()\n\n const defaultTransformers = {\n escape_html,\n fixed_content\n }\n const defaultOptions = {\n container: document.body,\n attribute: 'data-flow',\n transformers: defaultTransformers,\n render: {\n field: [render.field],\n list: [render.list],\n map: [render.map]\n },\n renderers: {\n 'INPUT':render.input,\n 'BUTTON':render.button,\n 'SELECT':render.select,\n 'A':render.anchor,\n 'IMG':render.image,\n 'IFRAME':render.iframe,\n 'META':render.meta,\n 'TEMPLATE':null,\n '*':render.element\n }\n }\n if (!options?.root) {\n throw new Error('bind needs at least options.root set')\n }\n this.options = Object.assign({}, defaultOptions, options)\n if (options.transformers) {\n this.options.transformers = Object.assign({}, defaultTransformers, options?.transformers)\n }\n const attribute = this.options.attribute\n const bindAttributes = [attribute+'-field',attribute+'-list',attribute+'-map']\n const transformAttribute = attribute+'-transform'\n\n const getBindingAttribute = (el) => {\n const foundAttribute = bindAttributes.find(attr => el.hasAttribute(attr))\n if (!foundAttribute) {\n console.error('No matching attribute found',el,bindAttributes)\n }\n return foundAttribute\n }\n\n // sets up the effect that updates the element if its\n // data binding value changes\n const renderElement = (el) => {\n this.bindings.set(el, throttledEffect(() => {\n if (!el.isConnected) {\n // el is no longer part of this document\n untrack(el, this.getBindingPath(el))\n destroy(this.bindings.get(el))\n // doing this here instead of in a mutationobserver\n // allows an element to be temporary removed and then inserted\n // without the binding having to be reset\n return\n }\n let context = {\n templates: el.querySelectorAll(':scope > template'),\n attribute: getBindingAttribute(el)\n }\n context.path = this.getBindingPath(el)\n context.value = getValueByPath(this.options.root, context.path)\n context.element = el\n track(el, context)\n runTransformers(context)\n }, 50))\n }\n\n // finds and runs applicable transformers\n // creates a stack of transformers, calls the topmost\n // each transformer can opt to call the next or not\n // transformers should return the context object (possibly altered)\n const runTransformers = (context) => {\n let transformers\n switch(context.attribute) {\n case this.options.attribute+'-field':\n transformers = Array.from(this.options.render.field)\n break\n case this.options.attribute+'-list':\n transformers = Array.from(this.options.render.list)\n break\n case this.options.attribute+'-map':\n transformers = Array.from(this.options.render.map)\n break\n default:\n throw new Error('no valid context attribute specified',context)\n break\n }\n if (context.element.hasAttribute(transformAttribute)) {\n context.element.getAttribute(transformAttribute)\n .split(' ').filter(Boolean)\n .forEach(t => {\n if (this.options.transformers[t]) {\n transformers.push(this.options.transformers[t])\n } else {\n console.warn('No transformer with name '+t+' configured', {cause:context.element})\n }\n })\n }\n let next\n for (let transformer of transformers) {\n next = ((next, transformer) => {\n return (context) => {\n return transformer.call(this, context, next)\n }\n })(next, transformer)\n }\n next(context)\n }\n\n // given a set of elements with data bind attribute\n // this renders each of those elements\n const applyBindings = (bindings) => {\n for (let bindingEl of bindings) {\n if (!this.bindings.get(bindingEl)) { // bindingEl may have moved from somewhere else in this document\n renderElement(bindingEl)\n }\n }\n }\n\n // this handles the mutation observer changes\n // if any element is added, and has a data bind attribute\n // it applies that data binding\n const updateBindings = (changes) => {\n const selector = `[${attribute}-field],[${attribute}-list],[${attribute}-map]`\n for (const change of changes) {\n if (change.type==\"childList\" && change.addedNodes) {\n for (let node of change.addedNodes) {\n if (node instanceof HTMLElement) {\n let bindings = Array.from(node.querySelectorAll(selector))\n if (node.matches(selector)) {\n bindings.unshift(node)\n }\n if (bindings.length) {\n applyBindings(bindings)\n }\n }\n }\n }\n }\n }\n\n // this responds to elements getting added to the dom\n // and if any have data bind attributes, it applies those bindings\n this.observer = new MutationObserver((changes) => {\n updateBindings(changes)\n })\n\n this.observer.observe(this.options.container, {\n subtree: true,\n childList: true\n })\n\n // this finds elements with data binding attributes and applies those bindings\n // must come after setting up the observer, or included templates\n // won't trigger their own bindings\n const bindings = this.options.container.querySelectorAll(\n ':is(['+this.options.attribute+'-field]'+\n ',['+this.options.attribute+'-list]'+\n ',['+this.options.attribute+'-map]):not(template)'\n )\n if (bindings.length) {\n applyBindings(bindings)\n }\n\n }\n\n /**\n * Finds the first matching template and creates a new DocumentFragment\n * with the correct data bind attributes in it (prepends the current path)\n * @param Context context\n * @return DocumentFragment\n */\n applyTemplate(context)\n {\n const path = context.path\n const parent = context.parent\n const templates = context.templates\n const list = context.list\n const index = context.index\n const value = list ? list[index] : context.value\n\n let template = this.findTemplate(templates, value)\n if (!template) {\n let result = new DocumentFragment()\n result.innerHTML = '<!-- no matching template -->'\n return result\n }\n let clone = template.content.cloneNode(true)\n if (!clone.children?.length) {\n return clone\n }\n if (clone.children.length>1) {\n throw new Error('template must contain a single root node', { cause: template })\n }\n const attribute = this.options.attribute\n\n const attributes = [attribute+'-field',attribute+'-list',attribute+'-map']\n const bindings = clone.querySelectorAll(`[${attribute}-field],[${attribute}-list],[${attribute}-map]`)\n for (let binding of bindings) {\n if (binding.tagName=='TEMPLATE') {\n continue\n }\n const attr = attributes.find(attr => binding.hasAttribute(attr))\n let bind = binding.getAttribute(attr)\n bind = this.applyLinks(template.links, bind)\n if (bind.substring(0, ':root.'.length)==':root.') {\n binding.setAttribute(attr, bind.substring(':root.'.length))\n } else if (bind==':value' && index!=null) {\n binding.setAttribute(attr, path+'.'+index)\n } else if (index!=null) {\n binding.setAttribute(attr, path+'.'+index+'.'+bind)\n } else {\n binding.setAttribute(attr, parent+bind)\n }\n }\n if (typeof index !== 'undefined') {\n clone.children[0].setAttribute(attribute+'-key',index)\n }\n // keep track of the used template, so if that changes, the item can be updated\n clone.children[0][Symbol.bindTemplate] = template\n\n // return clone, not the firstChild, so that all whitespace is cloned as well\n return clone\n }\n\n parseLinks(links)\n {\n let result = {}\n links = links.split(';').map(link => link.trim())\n for (let link of links) {\n link = link.split('=')\n result[link[0].trim()] = link[1].trim()\n }\n return result\n }\n\n applyLinks(links, value)\n {\n for (let link in links) {\n if (value.startsWith(link+'.')) {\n return links[link] + value.substr(link.length)\n } else if (value==link) {\n return links[link]\n }\n }\n return value\n }\n\n /**\n * Returns the path referenced in either the field, list or map attribute\n * @param HTMLElement el\n * @return string The path referenced, or void\n */\n getBindingPath(el)\n {\n const attributes = [\n this.options.attribute+'-field', \n this.options.attribute+'-list',\n this.options.attribute+'-map'\n ]\n for (let attr of attributes) {\n if (el.hasAttribute(attr)) {\n return el.getAttribute(attr)\n }\n }\n }\n\n /**\n * Finds the first template from an array of templates that\n * matches the given value. \n */\n findTemplate(templates, value)\n {\n const templateMatches = t => {\n // find the value to match against (e.g. data-bind=\"foo\")\n let path = this.getBindingPath(t)\n let currentItem\n if (path) {\n if (path.substr(0,6)==':root.') {\n currentItem = getValueByPath(this.options.root, path)\n } else {\n currentItem = getValueByPath(value, path)\n }\n } else {\n currentItem = value\n }\n\n // then check the value against pattern, if set (e.g. data-bind-match=\"bar\")\n const strItem = ''+currentItem\n let matches = t.getAttribute(this.options.attribute+'-match')\n if (matches) {\n if (matches===':empty' && !currentItem) {\n return t\n } else if (matches===':notempty' && currentItem) {\n return t\n }\n if (strItem == matches) {\n return t\n }\n }\n if (!matches && currentItem!==null && currentItem!==undefined) {\n //FIXME: this doesn't run templates in lists where list entry is null\n //which messes up the count\n //\n // no data-bind-match is set, so return this template\n return t\n }\n }\n let template = Array.from(templates).find(templateMatches)\n let links = null\n if (template?.hasAttribute(this.options.attribute+'-link')) {\n links = this.parseLinks(template.getAttribute(this.options.attribute+'-link'))\n }\n let rel = template?.getAttribute('rel')\n if (rel) {\n let replacement = document.querySelector('template#'+rel)\n if (!replacement) {\n throw new Error('Could not find template with id '+rel)\n }\n template = replacement\n }\n if (template) {\n template.links = links\n }\n return template\n }\n\n destroy()\n {\n this.bindings.forEach(binding => {\n destroy(binding)\n })\n this.bindings = new Map()\n this.observer.disconnect()\n }\n\n}\n\n/**\n * Returns a new instance of SimplyBind. This is the normal start\n * of a data bind flow\n */\nexport function bind(options)\n{\n return new SimplyBind(options)\n}\n\nconst tracking = new Map()\n\nexport function trace(path)\n{\n return tracking.get(path)\n}\n\nfunction track(el, context) {\n if (!tracking.has(context.path)) {\n tracking.set(context.path, [context])\n } else {\n tracking.get(context.path).push(context)\n }\n}\n\nfunction untrack(el, path) {\n let list = tracking.get(path)\n if (list) {\n list = list.filter(context => context.element == el)\n tracking.set(path, list)\n }\n}\n\n\n/**\n * Returns the value by walking the given path as a json pointer, starting at root\n * if you have a property with a '.' in its name urlencode the '.', e.g: %46\n * \n * @param HTMLElement root\n * @param string path e.g. 'foo.bar'\n * @return mixed the value found by walking the path from the root object or undefined\n */\nexport function getValueByPath(root, path)\n{\n let parts = path.split('.')\n let curr = root\n let part\n part = parts.shift()\n let prevPart = null\n while (part && curr) {\n part = decodeURIComponent(part)\n if (part=='0' && !Array.isArray(curr)) {\n // ignore so that data-flow-list=\"nonarray\" will work\n } else if (part==':key') {\n curr = prevPart\n } else if (part==':value') {\n // do nothing\n } else if (Array.isArray(curr) && typeof curr[part]=='undefined') {\n curr = curr[0][part] // so that data-flow-field=\"array.foo\" works\n } else {\n curr = curr[part]\n }\n prevPart = part\n part = parts.shift()\n }\n return curr\n}\n", "import {signal, effect, throttledEffect, batch} from './state.mjs'\n\n/**\n * This class implements a pluggable data model, where you can\n * add effects that are run only when either an option for that\n * effect changes, or when an effect earlier in the chain of\n * effects changes.\n */\nclass SimplyFlowModel {\n\n\t/**\n\t * Creates a new datamodel, with a state property that contains\n\t * all the data passed to this constructor\n\t * @param state\tObject with all the data for this model\n\t * @throws Error if state is not set\n\t */\n\tconstructor(state) {\n\t\tif (!state) {\n\t\t\tthrow new Error('no options set')\n\t\t}\n\t\tif (state.data==null || typeof state.data[Symbol.iterator] !== 'function') {\n\t\t\tconsole.warn('SimplyFlowModel: options.data is not iterable')\n\t\t}\n\t\tthis.state = signal(state)\n\t\tif (!this.state.options) {\n\t\t\tthis.state.options = {}\n\t\t}\n\t\tthis.effects = [{current:this.state.data}]\n\t\tthis.view = {\n current: this.state.data\n }\n\t}\n\n\t/**\n\t * Adds an effect to run whenever a signal it depends on\n\t * changes. this.state is the usual signal.\n\t * The `fn` function param is not itself an effect, but must return\n\t * and effect function. `fn` takes one param, which is the data signal.\n\t * This signal will always have at least a `current` property.\n\t * The result of the effect function is pushed on to the this.effects\n\t * list. And the last effect added is set as this.view\n\t */\n\taddEffect(fn) {\n\t\tif (!fn || typeof fn !=='function') {\n\t\t\tthrow new Error('addEffect requires an effect function as its parameter', { cause: fn })\n\t\t}\n\t\tconst dataSignal = this.effects[this.effects.length-1]\n\t\tconst connectedSignal = fn.call(this, dataSignal)\n\t\tif (!connectedSignal || !connectedSignal[Symbol.Signal]) {\n\t\t\tthrow new Error('addEffect function parameter must return a Signal', { cause: fn })\n\t\t}\n\t\tthis.view = connectedSignal\n\t\tthis.effects.push(this.view)\n\t}\n}\n\nexport function model(options) {\n\treturn new SimplyFlowModel(options)\n}\n\n/**\n * Returns a function for model.addEffect that sorts the input data\n * \n * Options:\n * - direction (string) default 'asc' - change to 'desc' to sort in descending order\n * - sortBy (string) (optional) - used by the default sorting function to select the property to sort on\n * - sortFn (function) (required - set by default) - the sort function to use\n */\nexport function sort(options={}) {\n\treturn function(data) {\n\t\t// initialize the sort options, only gets called once\n\t\tthis.state.options.sort = Object.assign({\n\t\t\tdirection: 'asc',\n\t\t\tsortBy: null,\n\t\t\tsortFn: ((a,b) => {\n\t\t\t\tconst sort = this.state.options.sort\n\t\t\t\tconst sortBy = sort.sortBy\n\t\t\t\tif (!sort.sortBy) {\n\t\t\t\t\treturn 0\n\t\t\t\t}\n\t\t\t\tconst larger = sort.direction == 'asc' ? 1 : -1\n\t\t\t\tconst smaller = sort.direction == 'asc' ? -1 : 1\n\t\t\t\tif (typeof a?.[sortBy] === 'undefined') {\n\t\t\t\t\tif (typeof b?.[sortBy] === 'undefined') {\n\t\t\t\t\t\treturn 0\n\t\t\t\t\t}\n\t\t\t\t\treturn larger\n\t\t\t\t}\n\t\t\t\tif (typeof b?.[sortBy] === 'undefined') {\n\t\t\t\t\treturn smaller\n\t\t\t\t}\n\t\t\t\tif (a[sortBy]<b[sortBy]) {\n\t\t\t\t\treturn smaller\n\t\t\t\t} else if (a[sortBy]>b[sortBy]) {\n\t\t\t\t\treturn larger\n\t\t\t\t} else {\n\t\t\t\t\treturn 0\n\t\t\t\t}\n\t\t\t})\n\t\t}, options);\n\t\t// then return the effect, which is called when\n\t\t// either the data or the sort options change\n\t\treturn throttledEffect(() => {\n\t\t\tconst sort = this.state.options.sort\n\t\t\tif (sort?.sortBy && sort?.direction) {\n\t\t\t\treturn data.current.toSorted(sort?.sortFn)\n\t\t\t}\n\t\t\treturn data.current\n\t\t}, 50)\n\t}\n}\n\n/**\n * Returns a function for model.addEffect that implements paging\n * for the input data. It will return a slice of the data matching\n * the page and pageSize options.\n * \n * Options:\n * - page (int) default 1 - which page to show, starts at 1\n * - pageSize (int) default 20 - how many items in a single page\n * - max (int) (calculated) - how many pages in total\n */\nexport function paging(options={}) {\n\treturn function(data) {\n\t\t// initialize the paging options\n\t\tthis.state.options.paging = Object.assign({\n\t\t\tpage: 1,\n\t\t\tpageSize: 20,\n\t\t\tmax: 1\n\t\t}, options)\n\t\treturn throttledEffect(() => {\n\t\t\treturn batch(() => {\n\t\t\t\tconst paging = this.state.options.paging\n\t\t\t\tif (!paging.pageSize) {\n\t\t\t\t\tpaging.pageSize = 20\n\t\t\t\t}\n\t\t\t\tpaging.max = Math.ceil(this.state.data.length / paging.pageSize)\n\t\t\t\tpaging.page = Math.max(1, Math.min(paging.max, paging.page))\n\n\t\t\t\tconst start = (paging.page-1) * paging.pageSize\n\t\t\t\tconst end = start + paging.pageSize\n\t\t\t\treturn data.current.slice(start, end)\n\t\t\t})\n\t\t}, 50)\n\t}\n}\n\n/**\n * Returns a function for model.addEffect that filters rows from the data,\n * using a custom filter function `options.matches`\n * \n * Options:\n * - name (string) (required) - the name of this filter, must be unique\n * - matches (function) (required) - the filter function to apply to the data\n * - enabled (bool) (required) - filter is applied only when enabled is set to true\n */\nexport function filter(options) {\n\tif (!options?.name || typeof options.name!=='string') {\n\t\tthrow new Error('filter requires options.name to be a string')\n\t}\n\tif (!options.matches || typeof options.matches!=='function') {\n\t\tthrow new Error('filter requires options.matches to be a function')\n\t}\n\treturn function(data) {\n\t\tif (this.state.options[options.name]) {\n\t\t\tthrow new Error('a filter with this name already exists on this model')\n\t\t}\n\t\tthis.state.options[options.name] = options\n\t\treturn throttledEffect(() => {\n\t\t\tif (this.state.options[options.name].enabled) {\n\t\t\t\treturn data.current.filter(this.state.options[options.name].matches.bind(this))\n\t\t\t}\n\t\t\treturn data.current\n\t\t}, 50)\n\t}\n}\n\n/**\n * Returns a function for model.addEffect that filters the data to only contain\n * columns (properties) that aren't hidden. Automatically runs again if any columns\n * hidden property changes.\n * \n * Options:\n * - columns (object) (required) - an object with properties describing each column. Each \n * property must be an object with an optional `hidden` property. If set to a truthy value,\n * and property in the dataset with the same name, will be filtered out.\n */\nexport function columns(options={}) {\n\tif (!options\n\t\t|| typeof options!=='object'\n\t\t|| Object.keys(options).length===0) {\n\t\tthrow new Error('columns requires options to be an object with at least one property')\n\t}\n\treturn function(data) {\n\t\tthis.state.options.columns = options\n\t\treturn throttledEffect(() => {\n\t\t\treturn data.current.map(input => {\n\t\t\t\tlet result = {}\n\t\t\t\tfor (let key of Object.keys(this.state.options.columns)) {\n\t\t\t\t\tif (!this.state.options.columns[key]?.hidden) {\n\t\t\t\t\t\tresult[key] = input[key]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn result\n\t\t\t})\n\t\t}, 50)\n\t}\n}\n\n/**\n * Returns a function for use with model.addEffect, with the given options set\n * as model.options.scroll. The effect will return a slice of the input data, which\n * makes it easy to render just a part (slice) of the whole data.\n * \n * Options are:\n * - offset (int) default 0 (optional) - the offset in the data to start the slice\n * - rowCount (int) default 20 (optional / calculated) - the number of rows in the slice\n * - rowHeight (int) default 26 (optional) - the height of a single row in pixels\n * - itemsPerRow (int) default 1 (optional) - the number of items on a single row\n * - size (int) default data.current.length (calculated) - how many rows inside data.current before slicing\n * - scrollbar (HTMLElement) defualt null (optional) - if set, an effect is added to update this elements \n * \t height if data.current.length changes\n * - container (HTMLElement) default null (optional) - if set, a scroll listener is added to this element, \n * which will update the options.offset signal and trigger the slice effect. It will also set the rowCount.\n */\nexport function scroll(options) {\n\n\treturn function(data) {\n\t\tthis.state.options.scroll = Object.assign({\n\t\t\toffset: 0,\n\t\t\trowHeight: 26,\n\t\t\trowCount: 20,\n\t\t\titemsPerRow: 1,\n\t\t\tsize: data.current.length\n\t\t}, options)\n\t\tconst scrollOptions = this.state.options.scroll\n\n\t\tconst scrollbar = scrollOptions.scrollbar \n\t\t\t|| scrollOptions.container?.querySelector('[data-flow-scrollbar]')\n\t\tif (scrollbar) {\n\t\t\tif (scrollOptions.container) {\n\t\t\t\tscrollOptions.container.addEventListener('scroll', (evt) => {\n\t\t\t\t\tscrollOptions.offset = Math.floor(scrollOptions.container.scrollTop\n\t\t\t\t\t\t/ (scrollOptions.rowHeight*scrollOptions.itemsPerRow)\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tthrottledEffect(() => {\n\t\t\t\tscrollOptions.size = data.current.length * scrollOptions.rowHeight\n\t\t\t\tscrollbar.style.height = scrollOptions.size + 'px'\n\t\t\t}, 50)\n\t\t}\n\n\t\treturn throttledEffect(() => {\n\t\t\tif (scrollOptions.container) {\n\t\t\t\t//TODO: add a resize listener so that if the size of the container\n\t\t\t\t// changes, the rowCount is calculated again\n\t\t\t\tscrollOptions.rowCount = Math.ceil(\n\t\t\t\t\tscrollOptions.container.getBoundingClientRect().height \n\t\t\t\t\t/ scrollOptions.rowHeight\n\t\t\t\t)\n\t\t\t}\n\t\t\tscrollOptions.data = data.current\n\t\t\tlet start = Math.min(scrollOptions.offset, data.current.length-1)\n\t\t\tlet end = start + scrollOptions.rowCount\n\t\t\tif (end > data.current.length) {\n\t\t\t\tend = data.current.length\n\t\t\t\tstart = end - scrollOptions.rowCount\n\t\t\t}\n\t\t\treturn data.current.slice(start, end)\n\t\t}, 50)\n\t}\n}", "export class SimplyRender extends HTMLElement \n{\n constructor()\n {\n super()\n }\n\n connectedCallback()\n {\n let templateId = this.getAttribute(\"rel\")\n let template = document.getElementById(templateId)\n\n if (template) {\n let content = template.content.cloneNode(true)\n for (const node of content.childNodes) {\n const clone = node.cloneNode(true)\n if (clone.nodeType == document.ELEMENT_NODE) {\n clone.querySelectorAll(\"template\").forEach(function(t) {\n t.setAttribute(\"simply-render\", \"\") //FIXME: whats this?\n })\n if (this.attributes) {\n for (const attr of this.attributes) {\n if (attr.name!='rel') {\n clone.setAttribute(attr.name, attr.value)\n }\n }\n }\n }\n this.parentNode.insertBefore(clone, this)\n }\n this.parentNode.removeChild(this)\n } else {\n const observe = () => {\n const observer = new MutationObserver(() => {\n template = document.getElementById(templateId)\n if (template) {\n observer.disconnect()\n this.replaceWith(this) // trigger connectedCallback?\n }\n })\n observer.observe(globalThis.document, {\n subtree: true,\n childList: true,\n })\n }\n\n observe()\n }\n }\n}\n\nif (!customElements.get('simply-render')) {\n customElements.define('simply-render', SimplyRender);\n}", "import { bind } from './bind.mjs'\nimport * as model from './model.mjs'\nimport * as state from './state.mjs'\nimport './render.mjs'\n\nif (!globalThis.simply) {\n\tglobalThis.simply = {}\n}\nObject.assign(globalThis.simply, {\n\tbind,\n\tflow: model,\n\tstate\n})\n\nexport default globalThis.simply"],
5
- "mappings": "mGAAA,IAAAA,EAAA,GAAAC,GAAAD,EAAA,eAAAE,GAAA,UAAAC,EAAA,gBAAAC,GAAA,YAAAC,EAAA,cAAAC,EAAA,WAAAC,GAAA,WAAAC,EAAA,oBAAAC,EAAA,UAAAC,GAAA,cAAAC,GAAA,WAAAC,IAAA,IAAMC,EAAU,OAAO,SAAS,EAC3B,OAAO,OACR,OAAO,KAAO,OAAO,MAAM,GAE1B,OAAO,SACR,OAAO,OAAS,OAAO,QAAQ,GAGnC,IAAMC,GAAgB,CAClB,IAAK,CAACC,EAAQC,EAAUC,IAAa,CACjC,GAAID,IAAW,OAAO,KAClB,OAAOD,EAEX,GAAIC,IAAW,OAAO,OAClB,MAAO,GAEX,IAAME,EAAQH,IAASC,CAAQ,EAE/B,OADAG,EAAUF,EAAUD,CAAQ,EACxB,OAAOE,GAAU,WACb,MAAM,QAAQH,CAAM,EACb,IAAIK,IAAS,CAChB,IAAI,EAAIL,EAAO,OAIXM,EAASH,EAAM,MAAMD,EAAUG,CAAI,EACvC,OAAI,GAAKL,EAAO,QACZO,EAAUL,EAAWM,EAAY,SAAU,CAAE,IAAK,EAAG,IAAKR,EAAO,MAAO,CAAC,CAAE,EAExEM,CACX,EACON,aAAkB,KAAOA,aAAkB,IAC3C,IAAIK,IAAS,CAIhB,IAAII,EAAIT,EAAO,KACXM,EAASH,EAAM,MAAMH,EAAQK,CAAI,EACrC,OAAII,GAAKT,EAAO,MACZO,EAAUL,EAAUM,E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Y,CACnC,IAAME,EAAQD,EAAK,UAAU,EAAI,EACjC,GAAIC,EAAM,UAAY,SAAS,eAC3BA,EAAM,iBAAiB,UAAU,EAAE,QAAQ,SAASC,EAAG,CACnDA,EAAE,aAAa,gBAAiB,EAAE,CACtC,CAAC,EACG,KAAK,YACL,QAAWC,KAAQ,KAAK,WAChBA,EAAK,MAAM,OACXF,EAAM,aAAaE,EAAK,KAAMA,EAAK,KAAK,EAKxD,KAAK,WAAW,aAAaF,EAAO,IAAI,CAC5C,CACA,KAAK,WAAW,YAAY,IAAI,CACpC,MACoB,IAAM,CAClB,IAAMG,EAAW,IAAI,iBAAiB,IAAM,CACxCN,EAAW,SAAS,eAAeD,CAAU,EACzCC,IACAM,EAAS,WAAW,EACpB,KAAK,YAAY,IAAI,EAE7B,CAAC,EACDA,EAAS,QAAQ,WAAW,SAAU,CAClC,QAAS,GACT,UAAW,EACf,CAAC,CACL,GAEQ,CAEhB,CACJ,EAEK,eAAe,IAAI,eAAe,GACnC,eAAe,OAAO,gBAAiBR,EAAY,EC/ClD,WAAW,SACf,WAAW,OAAS,CAAC,GAEtB,OAAO,OAAO,WAAW,OAAQ,CAChC,KAAAS,GACA,KAAMC,EACN,MAAAC,CACD,CAAC,EAED,IAAOC,GAAQ,WAAW",
6
- "names": ["state_exports", "__export", "addTracer", "batch", "clockEffect", "destroy", "domSignal", "effect", "signal", "throttledEffect", "trace", "untracked", "unwrap", "iterate", "signalHandler", "target", "property", "receiver", "value", "notifyGet", "args", "result", "notifySet", "makeContext", "s", "current", "signals", "descriptor", "v", "domSignalHandler", "domListen", "el", "tracers", "tracing", "prop", "getListeners", "listener", "tracer", "callTracers", "getset", "params", "batchedListeners", "batchMode", "self", "context", "disableTracking", "listeners", "change", "propListeners", "addContext", "currentEffect", "computeStack", "clearContext", "observers", "oldContentHTML", "oldContentText", "observer", "mutationList", "changes", "mutation", "currentCompute", "setListeners", "listenersMap", "computeMap", "compute", "connectedSignals", "clearListeners", "effectStack", "effectMap", "signalStack", "fn", "f", "connectedSignal", "computeEffect", "runBatchedListeners", "copyBatchedListeners", "throttleTime", "throttled", "hasChange", "clock", "lastTick", "hasChanged", "seen", "innerUnwrap", "ob", "key", "escape_html", "context", "next", "content", "fixed_content", "field", "context", "fieldByTemplates", "renderer", "s", "domSignal", "setValueByPath", "list", "arrayByTemplates", "map", "objectByTemplates", "root", "path", "value", "parts", "curr", "part", "prev", "prevPart", "attribute", "items", "lastKey", "skipped", "item", "currentKey", "bindings", "needsReplacement", "b", "databind", "newTemplate", "length", "key", "clone", "outOfOrderItem", "i", "rendered", "template", "getParentPath", "el", "parentEl", "input", "element", "matchValue", "button", "setProperties", "select", "option", "o", "setSelectOptions", "addOption", "options", "anchor", "image", "iframe", "meta", "strValue", "data", "properties", "property", "a", "SimplyBind", "options", "defaultTransformers", "escape_html", "fixed_content", "defaultOptions", "field", "list", "map", "input", "button", "select", "anchor", "image", "iframe", "meta", "element", "attribute", "bindAttributes", "transformAttribute", "getBindingAttribute", "el", "foundAttribute", "attr", "renderElement", "throttledEffect", "untrack", "destroy", "context", "getValueByPath", "track", "runTransformers", "transformers", "t", "next", "transformer", "applyBindings", "bindings", "bindingEl", "updateBindings", "changes", "selector", "change", "node", "path", "parent", "templates", "index", "value", "template", "result", "clone", "attributes", "binding", "bind", "links", "link", "templateMatches", "currentItem", "strItem", "matches", "rel", "replacement", "tracking", "track", "el", "context", "tracking", "untrack", "path", "list", "getValueByPath", "root", "parts", "curr", "part", "prevPart", "model_exports", "__export", "columns", "filter", "model", "paging", "scroll", "sort", "SimplyFlowModel", "state", "signal", "fn", "dataSignal", "connectedSignal", "model", "options", "sort", "data", "a", "b", "sortBy", "larger", "smaller", "throttledEffect", "paging", "batch", "start", "end", "filter", "columns", "input", "result", "key", "scroll", "scrollOptions", "scrollbar", "evt", "SimplyRender", "templateId", "template", "content", "node", "clone", "t", "attr", "observer", "bind", "model_exports", "state_exports", "flow_default"]
3
+ "sources": ["../src/state.mjs", "../src/bind.transformers.mjs", "../src/dom.mjs", "../src/bind.render.mjs", "../src/bind.mjs", "../src/model.mjs", "../src/render.mjs", "../src/flow.mjs"],
4
+ "sourcesContent": ["const iterate = Symbol('iterate')\nif (!Symbol.xRay) {\n Symbol.xRay = Symbol('xRay')\n}\nif (!Symbol.Signal) {\n Symbol.Signal = Symbol('Signal')\n}\n\nconst signalHandler = {\n get: (target, property, receiver) => {\n if (property===Symbol.xRay) {\n return target // don't notifyGet here, this is only called by set\n }\n if (property===Symbol.Signal) {\n return true\n }\n const value = target?.[property] // Reflect.get fails on a Set.\n notifyGet(receiver, property)\n if (typeof value === 'function') {\n if (Array.isArray(target)) {\n return (...args) => {\n let l = target.length\n // by binding the function to the receiver\n // all accesses in the function will be trapped\n // by the Proxy, so get/set/delete is all handled\n let result = value.apply(receiver, args)\n if (l != target.length) {\n notifySet(receiver, makeContext('length', { was: l, now: target.length }) )\n }\n return result\n }\n } else if (target instanceof Set || target instanceof Map) {\n return (...args) => {\n // node doesn't allow you to call set/map functions\n // bound to the receiver.. so using target instead\n // there are no properties to update anyway, except for size\n let s = target.size\n let result = value.apply(target, args)\n if (s != target.size) {\n notifySet(receiver, makeContext( 'size', { was: s, now: target.size }) )\n }\n // there is no efficient way to see if the function called\n // has actually changed the Set/Map, but by assuming the\n // 'setter' functions will change the results of the\n // 'getter' functions, effects should update correctly\n if (['set','add','clear','delete'].includes(property)) {\n notifySet(receiver, makeContext( { entries: {}, forEach: {}, has: {}, keys: {}, values: {}, [Symbol.iterator]: {} } ) )\n }\n return result\n }\n } else if (\n target instanceof HTMLElement\n || target instanceof Number\n || target instanceof String\n || target instanceof Boolean\n ) {\n return value.bind(target)\n } else {\n // support custom classes, hopefully\n return value.bind(receiver)\n }\n }\n if (value && typeof value == 'object') {\n return signal(value)\n }\n return value\n },\n set: (target, property, value, receiver) => {\n value = value?.[Symbol.xRay] || value // unwraps signal\n //FIXME: if value contains child objects, these may be signals as well... so do this recursively\n unwrap(value)\n let current = target[property]\n if (current!==value) {\n target[property] = value\n notifySet(receiver, makeContext(property, { was: current, now: value } ) )\n }\n if (typeof current === 'undefined') {\n notifySet(receiver, makeContext(iterate, {}))\n }\n return true\n },\n has: (target, property) => { // receiver is not part of the has() call\n let receiver = signals.get(target) // so retrieve it here\n if (receiver) {\n notifyGet(receiver, property)\n }\n return Object.hasOwn(target, property)\n },\n deleteProperty: (target, property) => {\n if (typeof target[property] !== 'undefined') {\n let current = target[property]\n delete target[property]\n let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here\n notifySet(receiver, makeContext(property,{ delete: true, was: current }))\n }\n return true\n },\n defineProperty: (target, property, descriptor) => {\n if (typeof target[property] === 'undefined') {\n let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here\n notifySet(receiver, makeContext(iterate, {}))\n }\n return Object.defineProperty(target, property, descriptor)\n },\n ownKeys: (target) => {\n let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here\n notifyGet(receiver, iterate)\n return Reflect.ownKeys(target)\n }\n\n}\n\n/**\n * Keeps track of the return signal for an update function, as well\n * as signals connected to other objects. \n * Makes sure that a given object or function always uses the same\n * signal\n */\nexport const signals = new WeakMap()\n\n/**\n * Creates a new signal proxy of the given object, that intercepts get/has and set/delete\n * to allow reactive functions to be triggered when signal values change.\n */\nexport function signal(v) {\n unwrap(v)\n if (v[Symbol.Signal]) { // avoid wrapping a Signal inside a Signal\n let target = v[Symbol.xRay]\n if (!signals.has(target)) {\n signals.set(target, v)\n }\n v = target\n } else if (!signals.has(v)) {\n signals.set(v, new Proxy(v, signalHandler))\n }\n return signals.get(v)\n}\n\n\nlet tracers = []\nlet tracing = false\n/**\n * @param Signal|Function signal\n * If given a singal and property, this function lists all effects \n * that are currently listening to changes to that signal and property\n * returns a list with \n * - effect: the effect function (effect, throttledEffect, clockEffect)\n * - fn: the user provided function to this effect function\n * - signal: the connectedSignal to this user provided function\n * @param string prop \n * @return array of { effect, fn, signal }\n * \n * If given a function, it will enable any tracers added with addTracer\n * call the given function and then disable all tracers.\n * @return void\n */\nexport function trace(signal, prop) {\n if (typeof signal==='function') {\n tracing = true\n signal()\n tracing = false\n } else {\n const listeners = getListeners(signal, prop)\n return listeners.map(listener => {\n return {\n effect: listener.effectType,\n fn: listener.effectFunction,\n signal: signals.get(listener.effectFunction)\n }\n })\n }\n}\n\n/**\n * Adds a tracer. This is an object with a 'set' and/or 'get' function.\n * If enabled (with the trace() method) each access to notifyGet will \n * call the 'get' function. Each access to notifySet will call the 'set'\n * function.\n * @param tracer { get: fn, set: fn }\n * get: function(signal, property)\n * set: function(signal, context, listener)\n */\nexport function addTracer(tracer) {\n if (!tracer.get && !tracer.set) {\n throw new Error('simply.state: addTracer: missing \"get\" or \"set\" property in tracer', tracer)\n }\n if (tracer.get && typeof tracer.get!=='function') {\n throw new Error('simply.state: addTracer: \"get\" is not a function', tracer)\n }\n if (tracer.set && typeof tracer.set!=='function') {\n throw new Error('simply.state: addTracer: \"set\" is not a function', tracer)\n }\n tracers.push(tracer)\n}\n\nfunction callTracers(getset, ...params) {\n for (const tracer of tracers) {\n if (tracer[getset]) {\n tracer[getset](...params)\n }\n }\n}\n\nlet batchedListeners = new Set()\nlet batchMode = 0\n/**\n * Called when a signal changes a property (set/delete)\n * Triggers any reactor function that depends on this signal\n * to re-compute its values\n */\nexport function notifySet(self, context={}) {\n if (disableTracking) {\n return\n }\n let listeners = []\n context.forEach((change, property) => {\n let propListeners = getListeners(self, property)\n if (propListeners?.length) {\n for (let listener of propListeners) {\n addContext(listener, makeContext(property,change))\n }\n listeners = listeners.concat(propListeners)\n }\n })\n listeners = new Set(listeners.filter(Boolean))\n if (listeners) {\n if (batchMode) {\n batchedListeners = batchedListeners.union(listeners)\n } else {\n const currentEffect = computeStack[computeStack.length-1]\n for (let listener of Array.from(listeners)) {\n if (listener!=currentEffect && listener?.needsUpdate) {\n if (tracing && tracers.length) {\n callTracers('set', self, context, listener)\n }\n listener()\n }\n clearContext(listener)\n }\n }\n }\n}\n\n\nexport function makeContext(property, change) {\n let context = new Map()\n if (typeof property === 'object') {\n for (let prop in property) {\n context.set(prop, property[prop])\n }\n } else {\n context.set(property, change)\n }\n return context\n}\n\nfunction addContext(listener, context) {\n if (!listener.context) {\n listener.context = context\n } else {\n context.forEach((change,property)=> {\n listener.context.set(property, change) // TODO: merge change if needed\n })\n }\n listener.needsUpdate = true\n}\n\nfunction clearContext(listener) {\n delete listener.context\n delete listener.needsUpdate\n}\n\n/**\n * Called when a signal property is accessed. If this happens\n * inside a reactor function--computeStack is not empty--\n * then it adds the current reactor (top of this stack) to its\n * listeners. These are later called if this property changes\n */\nexport function notifyGet(self, property) {\n if (disableTracking) {\n return\n }\n let currentCompute = computeStack[computeStack.length-1]\n if (currentCompute) {\n if (tracing && tracers.length) {\n callTracers('get', self, property)\n }\n // get was part of a react() function, so add it\n setListeners(self, property, currentCompute)\n }\n}\n\n/**\n * Keeps track of which update() functions are dependent on which\n * signal objects and which properties. Maps signals to update fns\n */\nconst listenersMap = new WeakMap()\n\n/**\n * Keeps track of which signals and properties are linked to which\n * update functions. Maps update functions and properties to signals\n */\nconst computeMap = new WeakMap()\n\n/**\n * Returns the update functions for a given signal and property\n */\nfunction getListeners(self, property) {\n let listeners = listenersMap.get(self)\n return listeners ? Array.from(listeners.get(property) || []) : []\n}\n\n/**\n * Adds an update function (compute) to the list of listeners on\n * the given signal (self) and property\n */\nfunction setListeners(self, property, compute) {\n if (!listenersMap.has(self)) {\n listenersMap.set(self, new Map())\n }\n let listeners = listenersMap.get(self)\n if (!listeners.has(property)) {\n listeners.set(property, new Set())\n }\n listeners.get(property).add(compute)\n\n if (!computeMap.has(compute)) {\n computeMap.set(compute, new Map())\n }\n let connectedSignals = computeMap.get(compute)\n if (!connectedSignals.has(property)) {\n connectedSignals.set(property, new Set)\n }\n connectedSignals.get(property).add(self)\n}\n\n/**\n * Removes alle listeners that trigger the given reactor function (compute)\n * This happens when a reactor is called, so that it can set new listeners\n * based on the current call (code path)\n */\nfunction clearListeners(compute) {\n let connectedSignals = computeMap.get(compute)\n if (connectedSignals) {\n connectedSignals.forEach(property => {\n property.forEach(s => {\n let listeners = listenersMap.get(s)\n if (listeners.has(property)) {\n listeners.get(property).delete(compute)\n }\n })\n })\n }\n}\n\n/**\n * The top most entry is the currently running update function, used\n * to automatically record signals used in an update function.\n */\nlet computeStack = []\n\n/**\n * Used for cycle detection: effectStack contains all running effect\n * functions. If the same function appears twice in this stack, there\n * is a recursive update call, which would cause an infinite loop.\n */\nconst effectStack = []\n\nconst effectMap = new WeakMap()\n/**\n * Used for cycle detection: signalStack contains all used signals. \n * If the same signal appears more than once, there is a cyclical \n * dependency between signals, which would cause an infinite loop.\n */\nconst signalStack = []\n\n/**\n * Runs the given function at once, and then whenever a signal changes that\n * is used by the given function (or at least signals used in the previous run).\n */\nexport function effect(fn) {\n if (effectStack.findIndex(f => fn==f)!==-1) {\n throw new Error('Recursive update() call', {cause:fn})\n }\n effectStack.push(fn)\n\n let connectedSignal = signals.get(fn)\n if (!connectedSignal) {\n connectedSignal = signal({\n current: null\n })\n signals.set(fn, connectedSignal)\n }\n\n // this is the function that is called automatically\n // whenever a signal dependency changes\n const computeEffect = function computeEffect() {\n if (signalStack.findIndex(s => s==connectedSignal)!==-1) {\n throw new Error('Cyclical dependency in update() call', { cause: fn})\n }\n // remove all dependencies (signals) from previous runs \n clearListeners(computeEffect)\n computeEffect.effectFunction = fn\n computeEffect.effectType = effect\n // record new dependencies on this run\n computeStack.push(computeEffect)\n // prevent recursion\n signalStack.push(connectedSignal)\n // call the actual update function\n let result\n try {\n result = fn(computeEffect, computeStack, signalStack)\n } finally {\n // stop recording dependencies\n computeStack.pop()\n // stop the recursion prevention\n signalStack.pop()\n if (result instanceof Promise) {\n result.then((result) => {\n connectedSignal.current = result\n })\n } else {\n connectedSignal.current = result\n }\n }\n }\n computeEffect.fn = fn\n effectMap.set(connectedSignal, computeEffect)\n\n // run the computEffect immediately upon creation\n computeEffect()\n return connectedSignal\n}\n\n\nexport function destroy(connectedSignal) {\n // find the computeEffect associated with this signal\n const computeEffect = effectMap.get(connectedSignal)?.deref()\n if (!computeEffect) {\n return\n }\n\n // remove all listeners for this effect\n clearListeners(computeEffect)\n\n // remove all references to connectedSignal\n let fn = computeEffect.fn\n signals.remove(fn)\n\n effectMap.delete(connectedSignal)\n\n // if no other references to connectedSignal exist, it will be garbage collected\n}\n\n/**\n * Inside a batch() call, any changes to signals do not trigger effects\n * immediately. Instead, immediately after finishing the batch() call,\n * these effects will be called. Effects that are triggered by multiple\n * signals are called only once.\n * @param Function fn batch() calls this function immediately\n * @result mixed the result of the fn() function call\n */\nexport function batch(fn) {\n batchMode++\n let result\n try {\n result = fn()\n } finally {\n if (result instanceof Promise) {\n result.then(() => {\n batchMode--\n if (!batchMode) {\n runBatchedListeners()\n }\n })\n } else {\n batchMode--\n if (!batchMode) {\n runBatchedListeners()\n }\n }\n }\n return result\n}\n\nfunction runBatchedListeners() {\n let copyBatchedListeners = Array.from(batchedListeners)\n batchedListeners = new Set()\n const currentEffect = computeStack[computeStack.length-1]\n for (let listener of copyBatchedListeners) {\n if (listener!=currentEffect && listener?.needsUpdate) {\n listener()\n }\n clearContext(listener)\n }\n}\n\n/**\n * A throttledEffect is run immediately once. And then only once\n * per throttleTime (in ms).\n * @param Function fn the effect function to run whenever a signal changes\n * @param int throttleTime in ms\n * @returns signal with the result of the effect function fn\n */\nexport function throttledEffect(fn, throttleTime) {\n if (effectStack.findIndex(f => fn==f)!==-1) {\n throw new Error('Recursive update() call', {cause:fn})\n }\n effectStack.push(fn)\n\n let connectedSignal = signals.get(fn)\n if (!connectedSignal) {\n connectedSignal = signal({\n current: null\n })\n signals.set(fn, connectedSignal)\n }\n\n let throttled = false\n let hasChange = true\n // this is the function that is called automatically\n // whenever a signal dependency changes\n const computeEffect = function computeEffect() {\n if (signalStack.findIndex(s => s==connectedSignal)!==-1) {\n throw new Error('Cyclical dependency in update() call', { cause: fn})\n }\n if (throttled && throttled>Date.now()) {\n hasChange = true\n return\n }\n // remove all dependencies (signals) from previous runs \n clearListeners(computeEffect)\n // record new dependencies on this run\n computeEffect.effectFunction = fn\n computeEffect.effectType = throttledEffect\n computeStack.push(computeEffect)\n // prevent recursion\n signalStack.push(connectedSignal)\n // call the actual update function\n let result\n try {\n result = fn(computeEffect, computeStack, signalStack)\n } finally {\n hasChange = false\n // stop recording dependencies\n computeStack.pop()\n // stop the recursion prevention\n signalStack.pop()\n if (result instanceof Promise) {\n result.then((result) => {\n connectedSignal.current = result\n })\n } else {\n connectedSignal.current = result\n }\n }\n throttled = Date.now()+throttleTime\n globalThis.setTimeout(() => {\n if (hasChange) {\n computeEffect()\n }\n }, throttleTime)\n }\n // run the computEffect immediately upon creation\n computeEffect()\n return connectedSignal\n}\n\n// refactor: Class clock() with an effect() method\n// keep track of effects per clock, and add clock property to the effect function\n// on notifySet add clock.effects to clock.needsUpdate list\n// on clock.tick() (or clock.time++) run only the clock.needsUpdate effects \n// (first create a copy and reset clock.needsUpdate, then run effects)\nexport function clockEffect(fn, clock) {\n let connectedSignal = signals.get(fn)\n if (!connectedSignal) {\n connectedSignal = signal({\n current: null\n })\n signals.set(fn, connectedSignal)\n }\n\n let lastTick = -1 // clock.time should start at 0 or larger\n let hasChanged = true // make sure the first run goes through\n // this is the function that is called automatically\n // whenever a signal dependency changes\n const computeEffect = function computeEffect() {\n if (lastTick < clock.time) {\n if (hasChanged) {\n // remove all dependencies (signals) from previous runs \n clearListeners(computeEffect)\n computeEffect.effectFunction = fn\n computeEffect.effectType = clockEffect\n // record new dependencies on this run\n computeStack.push(computeEffect)\n // make sure the clock.time signal is a dependency\n lastTick = clock.time\n // call the actual update function\n let result \n try {\n result = fn(computeEffect, computeStack)\n } finally {\n // stop recording dependencies\n computeStack.pop()\n if (result instanceof Promise) {\n result.then((result) => {\n connectedSignal.current = result\n })\n } else {\n connectedSignal.current = result\n }\n hasChanged = false\n }\n } else {\n lastTick = clock.time\n }\n } else {\n hasChanged = true\n }\n }\n // run the computEffect immediately upon creation\n computeEffect()\n return connectedSignal\n}\n\nlet disableTracking = false\nexport function untracked(fn) {\n disableTracking = true\n try {\n return fn()\n } finally {\n disableTracking = false\n }\n}\n\nlet seen = new WeakMap()\n\nfunction innerUnwrap(ob) {\n if (!ob || typeof ob!=='object' || ob instanceof HTMLElement || seen.has(ob)) {\n return\n }\n seen.set(ob, true)\n for (const prop in ob) {\n if (ob[prop]?.[Symbol.Signal]) {\n ob[prop] = ob[prop][Symbol.xRay]\n }\n if (Array.isArray(ob[prop])) {\n for (const [key, value] of Object.entries(ob[prop])) {\n if (value && typeof value==='object') {\n innerUnwrap(value)\n }\n }\n } else if (ob[prop] && typeof ob[prop] === 'object') {\n innerUnwrap(ob[prop])\n }\n }\n}\n\nexport function unwrap(ob) {\n if (ob && typeof ob==='object') {\n seen = new WeakMap()\n innerUnwrap(ob)\n seen = null\n }\n}\n", "export function escape_html(context, next) {\n let content = context.value?.innerHTML\n if (typeof context.value == 'string') {\n content = context.value\n context.value = { innerHTML: content }\n }\n if (content) {\n content = content.replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#39;');\n context.value.innerHTML = content\n }\n next(context)\n}\n\nexport function fixed_content(context, next) {\n if (typeof context.value == 'string') {\n context.value = {}\n } else {\n delete context.value?.innerHTML\n }\n next(context)\n}\n", "import { signals, signal as stateSignal, notifyGet, notifySet, makeContext } from './state.mjs'\n\nconst domSignalHandler = {\n get: (target, property, receiver) => {\n if (property===Symbol.xRay) {\n return target // don't notifyGet here, this is only called by set\n }\n if (property===Symbol.Signal) {\n return true\n }\n const value = target?.[property]\n notifyGet(receiver, property)\n if (typeof value === 'function') {\n return value.bind(target) // make sure element functions are not linked to the proxy\n }\n if (value && typeof value == 'object') {\n return stateSignal(value)\n }\n return value\n },\n has: (target, property) => {\n let receiver = signals.get(target)\n if (receiver) {\n notifyGet(receiver, property)\n }\n return Object.hasOwn(target, property)\n },\n ownKeys: (target) => {\n let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here\n if (receiver) {\n notifyGet(receiver, iterate)\n }\n return Reflect.ownKeys(target)\n }\n}\n\nexport function signal(el) {\n if (el[Symbol.xRay]) {\n return el\n }\n if (!signals.has(el)) {\n signals.set(el, new Proxy(el, domSignalHandler))\n domListen(el, signals.get(el))\n }\n return signals.get(el)\n}\n\nconst observers = new WeakMap()\n\nfunction domListen(el, signal) {\n let oldContentHTML = el.innerHTML\n let oldContentText = el.innerText\n if (!observers.has(el)) {\n const observer = new MutationObserver((mutationList, observer) => {\n // collect changes\n const changes = {}\n for (const mutation of mutationList) {\n if (mutation.type==='attributes') {\n // check if any listeners for each attribute\n changes[mutation.attributeName] = mutation.attributeOldValue\n } else if (mutation.type==='subtree' || mutation.type==='characterData') {\n // change on innerHTML/innerText\n if (el.innerHTML != oldContentHTML) {\n changes.innerHTML = oldContentHTML\n oldContentHTML = el.innerHTML\n }\n if (el.innerText != oldContentText) {\n changes.innerText = oldContentText\n oldContentText = el.innerText\n }\n }\n }\n for (const prop in changes) {\n notifySet(signal, makeContext(prop, { was: changes[prop], now: el[prop] }))\n }\n })\n observer.observe(el, {\n characterData: true,\n subtree: true,\n attributes: true,\n attributesOldValue: true\n })\n observers.set(el, observer)\n //@TODO: unregister the observer when el is removed from the dom (after a timeout)\n if (el.matches('input, textarea, select')) {\n let prevValue = el.value\n el.addEventListener('change', (evt) => {\n notifySet(signal, makeContext('value', { was: prevValue, now: el.value }))\n prevValue = el.value\n })\n if (el.matches('input, textarea')) {\n el.addEventListener('input', (evt) => {\n notifySet(signal, makeContext('value', { was: prevValue, now: el.value }))\n prevValue = el.value\n })\n }\n }\n }\n}\n", "/*\n * Default renderers for data binding\n * Will be used unless overriden in the SimplyBind options parameter\n */\nimport { signal as domSignal } from './dom.mjs'\n\n/**\n * This function is used by default to render dom elements with the `data-flow-field` attribute.\n * It will switch to only switching in template content if the context has any templates.\n * Otherwise it will call the matching render function depending on the tagName of the\n * context.element\n */\nexport function field(context)\n{\n if (context.templates?.length) {\n fieldByTemplates.call(this, context)\n // TODO: check if existence of one or more templates must mean that\n // only the template rendering is applied, instead of also rendering attributes\n } else if (Object.hasOwnProperty.call(this.options.renderers, context.element.tagName)) {\n const renderer = this.options.renderers[context.element.tagName]\n if (renderer) {\n renderer.call(this, context)\n }\n } else if (this.options.renderers['*']) {\n this.options.renderers['*'].call(this, context)\n // FIXME: should call a setter (defined in field type) to set the value back into root data\n if (this.options.twoway) { \n // TODO: make content-editable if editmode is toggled on\n // how do you toggle editmode? global signal?\n // make uneditable if editmode is toggled off\n const s = domSignal(context.element)\n effect(() => {\n setValueByPath(this.options.root, context.path, s.innerHTML)\n })\n }\n }\n return context\n}\n\n/**\n * This function is used by default to render DOM elements with the `data-flow-list` attribute.\n * The context.value must be an array. And context.templates must not be empty.\n */\nexport function list(context)\n{\n if (!Array.isArray(context.value)) {\n context.value = [context.value]\n }\n if (!context.templates?.length) {\n console.error('No templates found in', context.element)\n } else {\n arrayByTemplates.call(this, context)\n }\n return context\n}\n\n/**\n * This function is used by default to render DOM elements with the `data-flow-map` attribute.\n * The context.value must be a non-null object. And context.templates must not be empty.\n */\nexport function map(context)\n{\n if (typeof context.value != 'object' || !context.value) {\n console.error('Value is not an object.', context.element, context.path, context.value)\n } else if (!context.templates?.length) {\n console.error('No templates found in', context.element)\n } else {\n objectByTemplates.call(this, context)\n }\n return context\n}\n\nexport function setValueByPath(root, path, value)\n{\n let parts = path.split('.')\n let curr = root\n let part\n part = parts.shift()\n let prev = null\n let prevPart = null\n while (part && curr) {\n part = decodeURIComponent(part)\n if (part=='0' && !Array.isArray(curr)) {\n // ignore so that data-flow-list=\"nonarray\" will work\n } else if (part==':key') {\n // FIXME: should change the key, not the value... not supported yet?\n throw new Error('setting key not yet supported')\n curr = prevPart\n } else if (part==':value') {\n // do nothing\n } else if (Array.isArray(curr) && typeof curr[part]=='undefined') {\n prev = curr[0]\n curr = curr[0][part] // so that data-flow-field=\"array.foo\" works\n } else {\n prev = curr\n curr = curr[part]\n }\n prevPart = part\n part = parts.shift()\n }\n if (prev && prevPart && prev[prevPart]!==value) {\n prev[prevPart] = value\n }\n}\n\n/**\n * Renders an array value by applying templates for each entry\n * Replaces or removes existing DOM children if needed\n * Reuses (doesn't touch) DOM children if template doesn't change\n * FIXME: this doesn't handle situations where there is no matching template\n * this messes up self healing. check renderObjectByTemplates for a better implementation\n */\nexport function arrayByTemplates(context)\n{\n const attribute = this.options.attribute\n\n let items = context.element.querySelectorAll(':scope > ['+attribute+'-key]')\n // do single merge strategy for now, in future calculate optimal merge strategy from a number\n // now just do a delete if a key <= last key, insert if a key >= last key\n let lastKey = 0\n let skipped = 0\n context.list = context.value\n for (let item of items) {\n let currentKey = parseInt(item.getAttribute(attribute+'-key'))\n if (currentKey>lastKey) {\n // insert before\n context.index = lastKey\n context.element.insertBefore(this.applyTemplate(context), item)\n } else if (currentKey<lastKey) {\n // remove this\n item.remove()\n } else {\n // check that all data-bind params start with current json path or ':root', otherwise replaceChild\n let bindings = Array.from(item.querySelectorAll(`[${attribute}]`))\n if (item.matches(`[${attribute}]`)) {\n bindings.unshift(item)\n }\n let needsReplacement = bindings.find(b => {\n let databind = b.getAttribute(attribute)\n return (databind.substr(0,5)!==':root' \n && databind.substr(0, context.path.length)!==context.path)\n })\n if (!needsReplacement) {\n if (item[Symbol.bindTemplate]) {\n let newTemplate = this.findTemplate(context.templates, context.list[lastKey])\n if (newTemplate != item[Symbol.bindTemplate]){\n needsReplacement = true\n if (!newTemplate) {\n skipped++\n }\n }\n }\n }\n if (needsReplacement) {\n context.index = lastKey\n context.element.replaceChild(this.applyTemplate(context), item)\n }\n }\n lastKey++\n if (lastKey>=context.value.length) {\n break\n }\n }\n items = context.element.querySelectorAll(':scope > ['+attribute+'-key]')\n let length = items.length + skipped\n if (length > context.value.length) {\n while (length > context.value.length) {\n let child = context.element.querySelectorAll(':scope > :not(template)')?.[length-1]\n child?.remove()\n length--\n }\n } else if (length < context.value.length ) {\n while (length < context.value.length) {\n context.index = length\n context.element.appendChild(this.applyTemplate(context))\n length++\n }\n }\n}\n\n/**\n * Renders an object value by applying templates for each entry (Object.entries)\n * Replaces,moves or removes existing DOM children if needed\n * Reuses (doesn't touch) DOM children if template doesn't change\n */\nexport function objectByTemplates(context)\n{\n const attribute = this.options.attribute\n context.list = context.value\n\n let items = Array.from(context.element.querySelectorAll(':scope > ['+attribute+'-key]'))\n for (let key in context.list) {\n context.index = key\n let item = items.shift()\n if (!item) { // more properties than rendered items\n let clone = this.applyTemplate(context)\n context.element.appendChild(clone)\n continue\n }\n if (item.getAttribute[attribute+'-key']!=key) { \n // next item doesn't match key\n items.unshift(item) // put item back for next cycle\n let outOfOrderItem = context.element.querySelector(':scope > ['+attribute+'-key=\"'+key+'\"]') //FIXME: escape key\n if (!outOfOrderItem) {\n let clone = this.applyTemplate(context)\n context.element.insertBefore(clone, item)\n continue // new template doesn't need replacement, so continue \n } else {\n context.element.insertBefore(outOfOrderItem, item)\n item = outOfOrderItem // check needsreplacement next\n items = items.filter(i => i!=outOfOrderItem)\n }\n }\n let newTemplate = this.findTemplate(context.templates, context.list[context.index])\n if (newTemplate != item[Symbol.bindTemplate]){\n let clone = this.applyTemplate(context)\n context.element.replaceChild(clone, item)\n }\n }\n // clean up remaining items\n while (items.length) {\n let item = items.shift()\n item.remove()\n }\n}\n\n/**\n * renders the contents of an html element by rendering\n * a matching template, once.\n */\nexport function fieldByTemplates(context)\n{\n const rendered = context.element.querySelector(':scope > :not(template)')\n const template = this.findTemplate(context.templates, context.value)\n context.parent = getParentPath(context.element)\n if (rendered) {\n if (template) {\n if (rendered?.[Symbol.bindTemplate] != template) {\n const clone = this.applyTemplate(context)\n context.element.replaceChild(clone, rendered)\n }\n } else {\n context.element.removeChild(rendered)\n }\n } else if (template) {\n const clone = this.applyTemplate(context)\n context.element.appendChild(clone)\n }\n}\n\nfunction getParentPath(el, attribute)\n{\n const parentEl = el.parentElement?.closest(`[${attribute}-list],[${attribute}-map]`)\n if (!parentEl) {\n return ''\n }\n if (parentEl.hasAttribute(`${attribute}-list`)) {\n return parentEl.getAttribute(`${attribute}-list`)+'.'\n }\n return parentEl.getAttribute(`${attribute}-map`)+'.'\n}\n\n/**\n * renders a single input type\n * for radio/checkbox inputs it only sets the checked attribute to true/false\n * if the value attribute matches the current value\n * for other inputs the value attribute is updated\n */\nexport function input(context)\n{\n const el = context.element\n let value = context.value\n\n element(context)\n if (typeof value == 'undefined') {\n value = ''\n }\n if (el.type=='checkbox' || el.type=='radio') {\n if (matchValue(el.value, value)) {\n el.checked = true\n } else {\n el.checked = false\n }\n } else if (!matchValue(el.value, value)) {\n el.value = ''+value\n }\n}\n\n/**\n * Sets the value of the button, doesn't touch the innerHTML\n */\nexport function button(context)\n{\n element(context)\n setProperties(context.element, context.value, 'value')\n}\n\n/**\n * Sets the selected attribute of select options\n */\nexport function select(context)\n{\n const el = context.element\n let value = context.value\n\n if (value === null) {\n value = ''\n }\n if (typeof value!='object') {\n if (el.multiple) {\n if (Array.isArray(value)) { //FIXME: cannot be true, since typeof != 'object'\n for (let option of el.options) {\n if (value.indexOf(option.value)===false) {\n option.selected = false\n } else {\n option.selected = true\n }\n }\n }\n } else {\n let option = el.options.find(o => matchValue(o.value,value))\n if (option) {\n option.selected = true\n option.setAttribute('selected', true)\n }\n }\n } else { // value is a non-null object\n if (value.options) {\n setSelectOptions(el, value.options)\n }\n if (value.selected) {\n select(Object.asssign({}, context, {value:value.selected}))\n }\n setProperties(el, value, 'name', 'id', 'selectedIndex', 'className') // allow innerHTML? if so call element instead\n }\n}\n\n/**\n * adds a single option to a select element. The option.text property is optional, if not set option.value is used.\n * @param select The select element\n * @param option An option descriptor, either a string, object with {text,value,defaultSelected,selected} properties or an Option object\n */\nexport function addOption(select, option)\n{\n if (!option) {\n return\n }\n if (typeof option !== 'object') {\n select.options.add(new Option(''+option))\n } else if (option.text) {\n select.options.add(new Option(option.text, option.value, option.defaultSelected, option.selected))\n } else if (typeof option.value != 'undefined') {\n select.options.add(new Option(''+option.value, option.value, option.defaultSelected, option.selected))\n }\n}\n\n/**\n * This function clears all existing options of a select element, and adds the specified options.\n */\nexport function setSelectOptions(select,options)\n{\n //@TODO: only update in case of changes?\n select.innerHTML = ''\n if (Array.isArray(options)) {\n for (const option of options) {\n addOption(select, option)\n }\n } else if (options && typeof options == 'object') {\n for (const option in options) {\n addOption(select, { text: options[option], value: option })\n }\n }\n}\n\n/**\n * Sets the innerHTML and href, id, title, target, name, newwindow, nofollow attributes of an anchor\n */\nexport function anchor(context)\n{\n element(context)\n setProperties(context.element, context.value, 'target', 'href', 'name', 'newwindow', 'nofollow')\n}\n\n/**\n * Sets the title, id, alt and src attributes of an image.\n */\nexport function image(context)\n{\n setProperties(context.element, context.value, 'title', 'alt', 'src', 'id')\n}\n\n/**\n * Sets the title, id and src attribute of an iframe\n */\nexport function iframe(context)\n{\n setProperties(context.element, context.value, 'title', 'src', 'id')\n}\n\n/**\n * Sets the content and id attribute of a meta element\n */\nexport function meta(context)\n{\n setProperties(context.element, context.value, 'content', 'id') \n}\n\n/**\n * sets the innerHTML and title and id properties of any HTML element\n */\nexport function element(context)\n{\n const el = context.element\n let value = context.value\n\n if (typeof value=='undefined' || value==null) {\n value = ''\n }\n let strValue = ''+value\n if (typeof value!='object' || strValue.substring(0,8)!='[object ') {\n value = { innerHTML: value }\n }\n setProperties(el, value, 'innerHTML', 'title', 'id', 'className')\n}\n\n/**\n * Sets a list of properties on a dom element, equal to \n * the string value of a data object\n * only updates the dom element if the property doesn't match\n */\nexport function setProperties(el, data, ...properties) {\n if (!data || typeof data!=='object') {\n return\n }\n for (const property of properties) {\n if (typeof data[property] === 'undefined') {\n continue\n }\n if (matchValue(el[property], data[property])) {\n continue\n }\n if (data[property] === null) {\n el[property] = ''\n } else {\n el[property] = ''+data[property]\n }\n }\n}\n\n/**\n * Returns true if a matches b, either by having the\n * same string value, or matching string :empty against a falsy value\n */\nexport function matchValue(a,b)\n{\n if (a==':empty' && !b) {\n return true\n }\n if (b==':empty' && !a) {\n return true\n }\n if (''+a == ''+b) {\n return true\n }\n return false\n}\n", "import { throttledEffect, destroy } from './state.mjs'\nimport { escape_html, fixed_content } from './bind.transformers.mjs'\nimport * as render from './bind.render.mjs'\n\nif (!Symbol.bindTemplate) {\n Symbol.bindTemplate = Symbol('bindTemplate')\n}\n\n/**\n * Implements one way databinding, updating dom elements with matching attributes\n * to changes in signals (see state.mjs)\n * \n * @class\n */\nclass SimplyBind\n{\n \n /**\n * @param Object options - a set of options for this instance, options may include:\n * - root (signal) (required) - the root data object that contains al signals that can be bound\n * - container (HTMLElement) - the dom element to use as the root for all bindings\n * - attribute (string) - the prefix for the field, list and map attributes, e.g. 'data-bind'\n * - transformers (object name:function) - a map of transformer names and functions\n * - render (object with field, list and map properties)\n */\n constructor(options)\n {\n /**\n * A map of HTMLElements and the data bindings on each, in the form of \n * the connectedSignal returned by the (throttled)Effect.\n * @type {Map}\n * @public\n */\n this.bindings = new Map()\n\n const defaultTransformers = {\n escape_html,\n fixed_content\n }\n const defaultOptions = {\n container: document.body,\n attribute: 'data-flow',\n transformers: defaultTransformers,\n render: {\n field: [render.field],\n list: [render.list],\n map: [render.map]\n },\n renderers: {\n 'INPUT':render.input,\n 'BUTTON':render.button,\n 'SELECT':render.select,\n 'A':render.anchor,\n 'IMG':render.image,\n 'IFRAME':render.iframe,\n 'META':render.meta,\n 'TEMPLATE':null,\n '*':render.element\n }\n }\n if (!options?.root) {\n throw new Error('bind needs at least options.root set')\n }\n this.options = Object.assign({}, defaultOptions, options)\n if (options.transformers) {\n this.options.transformers = Object.assign({}, defaultTransformers, options?.transformers)\n }\n const attribute = this.options.attribute\n const bindAttributes = [attribute+'-field',attribute+'-list',attribute+'-map']\n const transformAttribute = attribute+'-transform'\n\n const getBindingAttribute = (el) => {\n const foundAttribute = bindAttributes.find(attr => el.hasAttribute(attr))\n if (!foundAttribute) {\n console.error('No matching attribute found',el,bindAttributes)\n }\n return foundAttribute\n }\n\n // sets up the effect that updates the element if its\n // data binding value changes\n const renderElement = (el) => {\n this.bindings.set(el, throttledEffect(() => {\n if (!el.isConnected) {\n // el is no longer part of this document\n untrack(el, this.getBindingPath(el))\n destroy(this.bindings.get(el))\n // doing this here instead of in a mutationobserver\n // allows an element to be temporary removed and then inserted\n // without the binding having to be reset\n return\n }\n let context = {\n templates: el.querySelectorAll(':scope > template'),\n attribute: getBindingAttribute(el)\n }\n context.path = this.getBindingPath(el)\n context.value = getValueByPath(this.options.root, context.path)\n context.element = el\n track(el, context)\n runTransformers(context)\n }, 50))\n }\n\n // finds and runs applicable transformers\n // creates a stack of transformers, calls the topmost\n // each transformer can opt to call the next or not\n // transformers should return the context object (possibly altered)\n const runTransformers = (context) => {\n let transformers\n switch(context.attribute) {\n case this.options.attribute+'-field':\n transformers = Array.from(this.options.render.field)\n break\n case this.options.attribute+'-list':\n transformers = Array.from(this.options.render.list)\n break\n case this.options.attribute+'-map':\n transformers = Array.from(this.options.render.map)\n break\n default:\n throw new Error('no valid context attribute specified',context)\n break\n }\n if (context.element.hasAttribute(transformAttribute)) {\n context.element.getAttribute(transformAttribute)\n .split(' ').filter(Boolean)\n .forEach(t => {\n if (this.options.transformers[t]) {\n transformers.push(this.options.transformers[t])\n } else {\n console.warn('No transformer with name '+t+' configured', {cause:context.element})\n }\n })\n }\n let next\n for (let transformer of transformers) {\n next = ((next, transformer) => {\n return (context) => {\n return transformer.call(this, context, next)\n }\n })(next, transformer)\n }\n next(context)\n }\n\n // given a set of elements with data bind attribute\n // this renders each of those elements\n const applyBindings = (bindings) => {\n for (let bindingEl of bindings) {\n if (!this.bindings.get(bindingEl)) { // bindingEl may have moved from somewhere else in this document\n renderElement(bindingEl)\n }\n }\n }\n\n // this handles the mutation observer changes\n // if any element is added, and has a data bind attribute\n // it applies that data binding\n const updateBindings = (changes) => {\n const selector = `[${attribute}-field],[${attribute}-list],[${attribute}-map]`\n for (const change of changes) {\n if (change.type==\"childList\" && change.addedNodes) {\n for (let node of change.addedNodes) {\n if (node instanceof HTMLElement) {\n let bindings = Array.from(node.querySelectorAll(selector))\n if (node.matches(selector)) {\n bindings.unshift(node)\n }\n if (bindings.length) {\n applyBindings(bindings)\n }\n }\n }\n }\n }\n }\n\n // this responds to elements getting added to the dom\n // and if any have data bind attributes, it applies those bindings\n this.observer = new MutationObserver((changes) => {\n updateBindings(changes)\n })\n\n this.observer.observe(this.options.container, {\n subtree: true,\n childList: true\n })\n\n // this finds elements with data binding attributes and applies those bindings\n // must come after setting up the observer, or included templates\n // won't trigger their own bindings\n const bindings = this.options.container.querySelectorAll(\n ':is(['+this.options.attribute+'-field]'+\n ',['+this.options.attribute+'-list]'+\n ',['+this.options.attribute+'-map]):not(template)'\n )\n if (bindings.length) {\n applyBindings(bindings)\n }\n\n }\n\n /**\n * Finds the first matching template and creates a new DocumentFragment\n * with the correct data bind attributes in it (prepends the current path)\n * @param Context context\n * @return DocumentFragment\n */\n applyTemplate(context)\n {\n const path = context.path\n const parent = context.parent\n const templates = context.templates\n const list = context.list\n const index = context.index\n const value = list ? list[index] : context.value\n\n let template = this.findTemplate(templates, value)\n if (!template) {\n let result = new DocumentFragment()\n result.innerHTML = '<!-- no matching template -->'\n return result\n }\n let clone = template.content.cloneNode(true)\n if (!clone.children?.length) {\n return clone\n }\n if (clone.children.length>1) {\n throw new Error('template must contain a single root node', { cause: template })\n }\n const attribute = this.options.attribute\n\n const attributes = [attribute+'-field',attribute+'-list',attribute+'-map']\n const bindings = clone.querySelectorAll(`[${attribute}-field],[${attribute}-list],[${attribute}-map]`)\n for (let binding of bindings) {\n if (binding.tagName=='TEMPLATE') {\n continue\n }\n const attr = attributes.find(attr => binding.hasAttribute(attr))\n let bind = binding.getAttribute(attr)\n bind = this.applyLinks(template.links, bind)\n if (bind.substring(0, ':root.'.length)==':root.') {\n binding.setAttribute(attr, bind.substring(':root.'.length))\n } else if (bind==':value' && index!=null) {\n binding.setAttribute(attr, path+'.'+index)\n } else if (index!=null) {\n binding.setAttribute(attr, path+'.'+index+'.'+bind)\n } else {\n binding.setAttribute(attr, parent+bind)\n }\n }\n if (typeof index !== 'undefined') {\n clone.children[0].setAttribute(attribute+'-key',index)\n }\n // keep track of the used template, so if that changes, the item can be updated\n clone.children[0][Symbol.bindTemplate] = template\n\n // return clone, not the firstChild, so that all whitespace is cloned as well\n return clone\n }\n\n parseLinks(links)\n {\n let result = {}\n links = links.split(';').map(link => link.trim())\n for (let link of links) {\n link = link.split('=')\n result[link[0].trim()] = link[1].trim()\n }\n return result\n }\n\n applyLinks(links, value)\n {\n for (let link in links) {\n if (value.startsWith(link+'.')) {\n return links[link] + value.substr(link.length)\n } else if (value==link) {\n return links[link]\n }\n }\n return value\n }\n\n /**\n * Returns the path referenced in either the field, list or map attribute\n * @param HTMLElement el\n * @return string The path referenced, or void\n */\n getBindingPath(el)\n {\n const attributes = [\n this.options.attribute+'-field', \n this.options.attribute+'-list',\n this.options.attribute+'-map'\n ]\n for (let attr of attributes) {\n if (el.hasAttribute(attr)) {\n return el.getAttribute(attr)\n }\n }\n }\n\n /**\n * Finds the first template from an array of templates that\n * matches the given value. \n */\n findTemplate(templates, value)\n {\n const templateMatches = t => {\n // find the value to match against (e.g. data-bind=\"foo\")\n let path = this.getBindingPath(t)\n let currentItem\n if (path) {\n if (path.substr(0,6)==':root.') {\n currentItem = getValueByPath(this.options.root, path)\n } else {\n currentItem = getValueByPath(value, path)\n }\n } else {\n currentItem = value\n }\n\n // then check the value against pattern, if set (e.g. data-bind-match=\"bar\")\n const strItem = ''+currentItem\n let matches = t.getAttribute(this.options.attribute+'-match')\n if (matches) {\n if (matches===':empty' && !currentItem) {\n return t\n } else if (matches===':notempty' && currentItem) {\n return t\n }\n if (strItem == matches) {\n return t\n }\n }\n if (!matches && currentItem!==null && currentItem!==undefined) {\n //FIXME: this doesn't run templates in lists where list entry is null\n //which messes up the count\n //\n // no data-bind-match is set, so return this template\n return t\n }\n }\n let template = Array.from(templates).find(templateMatches)\n let links = null\n if (template?.hasAttribute(this.options.attribute+'-link')) {\n links = this.parseLinks(template.getAttribute(this.options.attribute+'-link'))\n }\n let rel = template?.getAttribute('rel')\n if (rel) {\n let replacement = document.querySelector('template#'+rel)\n if (!replacement) {\n throw new Error('Could not find template with id '+rel)\n }\n template = replacement\n }\n if (template) {\n template.links = links\n }\n return template\n }\n\n destroy()\n {\n this.bindings.forEach(binding => {\n destroy(binding)\n })\n this.bindings = new Map()\n this.observer.disconnect()\n }\n\n}\n\n/**\n * Returns a new instance of SimplyBind. This is the normal start\n * of a data bind flow\n */\nexport function bind(options)\n{\n return new SimplyBind(options)\n}\n\nconst tracking = new Map()\n\nexport function trace(path)\n{\n return tracking.get(path)\n}\n\nfunction track(el, context) {\n if (!tracking.has(context.path)) {\n tracking.set(context.path, [context])\n } else {\n tracking.get(context.path).push(context)\n }\n}\n\nfunction untrack(el, path) {\n let list = tracking.get(path)\n if (list) {\n list = list.filter(context => context.element == el)\n tracking.set(path, list)\n }\n}\n\n\n/**\n * Returns the value by walking the given path as a json pointer, starting at root\n * if you have a property with a '.' in its name urlencode the '.', e.g: %46\n * \n * @param HTMLElement root\n * @param string path e.g. 'foo.bar'\n * @return mixed the value found by walking the path from the root object or undefined\n */\nexport function getValueByPath(root, path)\n{\n let parts = path.split('.')\n let curr = root\n let part\n part = parts.shift()\n let prevPart = null\n while (part && curr) {\n part = decodeURIComponent(part)\n if (part=='0' && !Array.isArray(curr)) {\n // ignore so that data-flow-list=\"nonarray\" will work\n } else if (part==':key') {\n curr = prevPart\n } else if (part==':value') {\n // do nothing\n } else if (Array.isArray(curr) && typeof curr[part]=='undefined') {\n curr = curr[0][part] // so that data-flow-field=\"array.foo\" works\n } else {\n curr = curr[part]\n }\n prevPart = part\n part = parts.shift()\n }\n return curr\n}\n", "import {signal, effect, throttledEffect, batch} from './state.mjs'\n\n/**\n * This class implements a pluggable data model, where you can\n * add effects that are run only when either an option for that\n * effect changes, or when an effect earlier in the chain of\n * effects changes.\n */\nclass SimplyFlowModel {\n\n\t/**\n\t * Creates a new datamodel, with a state property that contains\n\t * all the data passed to this constructor\n\t * @param state\tObject with all the data for this model\n\t * @throws Error if state is not set\n\t */\n\tconstructor(state) {\n\t\tif (!state) {\n\t\t\tthrow new Error('no options set')\n\t\t}\n\t\tif (state.data==null || typeof state.data[Symbol.iterator] !== 'function') {\n\t\t\tconsole.warn('SimplyFlowModel: options.data is not iterable')\n\t\t}\n\t\tthis.state = signal(state)\n\t\tif (!this.state.options) {\n\t\t\tthis.state.options = {}\n\t\t}\n\t\tthis.effects = [{current:this.state.data}]\n\t\tthis.view = {\n current: this.state.data\n }\n\t}\n\n\t/**\n\t * Adds an effect to run whenever a signal it depends on\n\t * changes. this.state is the usual signal.\n\t * The `fn` function param is not itself an effect, but must return\n\t * and effect function. `fn` takes one param, which is the data signal.\n\t * This signal will always have at least a `current` property.\n\t * The result of the effect function is pushed on to the this.effects\n\t * list. And the last effect added is set as this.view\n\t */\n\taddEffect(fn) {\n\t\tif (!fn || typeof fn !=='function') {\n\t\t\tthrow new Error('addEffect requires an effect function as its parameter', { cause: fn })\n\t\t}\n\t\tconst dataSignal = this.effects[this.effects.length-1]\n\t\tconst connectedSignal = fn.call(this, dataSignal)\n\t\tif (!connectedSignal || !connectedSignal[Symbol.Signal]) {\n\t\t\tthrow new Error('addEffect function parameter must return a Signal', { cause: fn })\n\t\t}\n\t\tthis.view = connectedSignal\n\t\tthis.effects.push(this.view)\n\t}\n}\n\nexport function model(options) {\n\treturn new SimplyFlowModel(options)\n}\n\n/**\n * Returns a function for model.addEffect that sorts the input data\n * \n * Options:\n * - direction (string) default 'asc' - change to 'desc' to sort in descending order\n * - sortBy (string) (optional) - used by the default sorting function to select the property to sort on\n * - sortFn (function) (required - set by default) - the sort function to use\n */\nexport function sort(options={}) {\n\treturn function(data) {\n\t\t// initialize the sort options, only gets called once\n\t\tthis.state.options.sort = Object.assign({\n\t\t\tdirection: 'asc',\n\t\t\tsortBy: null,\n\t\t\tsortFn: ((a,b) => {\n\t\t\t\tconst sort = this.state.options.sort\n\t\t\t\tconst sortBy = sort.sortBy\n\t\t\t\tif (!sort.sortBy) {\n\t\t\t\t\treturn 0\n\t\t\t\t}\n\t\t\t\tconst larger = sort.direction == 'asc' ? 1 : -1\n\t\t\t\tconst smaller = sort.direction == 'asc' ? -1 : 1\n\t\t\t\tif (typeof a?.[sortBy] === 'undefined') {\n\t\t\t\t\tif (typeof b?.[sortBy] === 'undefined') {\n\t\t\t\t\t\treturn 0\n\t\t\t\t\t}\n\t\t\t\t\treturn larger\n\t\t\t\t}\n\t\t\t\tif (typeof b?.[sortBy] === 'undefined') {\n\t\t\t\t\treturn smaller\n\t\t\t\t}\n\t\t\t\tif (a[sortBy]<b[sortBy]) {\n\t\t\t\t\treturn smaller\n\t\t\t\t} else if (a[sortBy]>b[sortBy]) {\n\t\t\t\t\treturn larger\n\t\t\t\t} else {\n\t\t\t\t\treturn 0\n\t\t\t\t}\n\t\t\t})\n\t\t}, options);\n\t\t// then return the effect, which is called when\n\t\t// either the data or the sort options change\n\t\treturn throttledEffect(() => {\n\t\t\tconst sort = this.state.options.sort\n\t\t\tif (sort?.sortBy && sort?.direction) {\n\t\t\t\treturn data.current.toSorted(sort?.sortFn)\n\t\t\t}\n\t\t\treturn data.current\n\t\t}, 50)\n\t}\n}\n\n/**\n * Returns a function for model.addEffect that implements paging\n * for the input data. It will return a slice of the data matching\n * the page and pageSize options.\n * \n * Options:\n * - page (int) default 1 - which page to show, starts at 1\n * - pageSize (int) default 20 - how many items in a single page\n * - max (int) (calculated) - how many pages in total\n */\nexport function paging(options={}) {\n\treturn function(data) {\n\t\t// initialize the paging options\n\t\tthis.state.options.paging = Object.assign({\n\t\t\tpage: 1,\n\t\t\tpageSize: 20,\n\t\t\tmax: 1\n\t\t}, options)\n\t\treturn throttledEffect(() => {\n\t\t\treturn batch(() => {\n\t\t\t\tconst paging = this.state.options.paging\n\t\t\t\tif (!paging.pageSize) {\n\t\t\t\t\tpaging.pageSize = 20\n\t\t\t\t}\n\t\t\t\tpaging.max = Math.ceil(this.state.data.length / paging.pageSize)\n\t\t\t\tpaging.page = Math.max(1, Math.min(paging.max, paging.page))\n\n\t\t\t\tconst start = (paging.page-1) * paging.pageSize\n\t\t\t\tconst end = start + paging.pageSize\n\t\t\t\treturn data.current.slice(start, end)\n\t\t\t})\n\t\t}, 50)\n\t}\n}\n\n/**\n * Returns a function for model.addEffect that filters rows from the data,\n * using a custom filter function `options.matches`\n * \n * Options:\n * - name (string) (required) - the name of this filter, must be unique\n * - matches (function) (required) - the filter function to apply to the data\n * - enabled (bool) (required) - filter is applied only when enabled is set to true\n */\nexport function filter(options) {\n\tif (!options?.name || typeof options.name!=='string') {\n\t\tthrow new Error('filter requires options.name to be a string')\n\t}\n\tif (!options.matches || typeof options.matches!=='function') {\n\t\tthrow new Error('filter requires options.matches to be a function')\n\t}\n\treturn function(data) {\n\t\tif (this.state.options[options.name]) {\n\t\t\tthrow new Error('a filter with this name already exists on this model')\n\t\t}\n\t\tthis.state.options[options.name] = options\n\t\treturn throttledEffect(() => {\n\t\t\tif (this.state.options[options.name].enabled) {\n\t\t\t\treturn data.current.filter(this.state.options[options.name].matches.bind(this))\n\t\t\t}\n\t\t\treturn data.current\n\t\t}, 50)\n\t}\n}\n\n/**\n * Returns a function for model.addEffect that filters the data to only contain\n * columns (properties) that aren't hidden. Automatically runs again if any columns\n * hidden property changes.\n * \n * Options:\n * - columns (object) (required) - an object with properties describing each column. Each \n * property must be an object with an optional `hidden` property. If set to a truthy value,\n * and property in the dataset with the same name, will be filtered out.\n */\nexport function columns(options={}) {\n\tif (!options\n\t\t|| typeof options!=='object'\n\t\t|| Object.keys(options).length===0) {\n\t\tthrow new Error('columns requires options to be an object with at least one property')\n\t}\n\treturn function(data) {\n\t\tthis.state.options.columns = options\n\t\treturn throttledEffect(() => {\n\t\t\treturn data.current.map(input => {\n\t\t\t\tlet result = {}\n\t\t\t\tfor (let key of Object.keys(this.state.options.columns)) {\n\t\t\t\t\tif (!this.state.options.columns[key]?.hidden) {\n\t\t\t\t\t\tresult[key] = input[key] ?? null\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn result\n\t\t\t})\n\t\t}, 50)\n\t}\n}\n\n/**\n * Returns a function for use with model.addEffect, with the given options set\n * as model.options.scroll. The effect will return a slice of the input data, which\n * makes it easy to render just a part (slice) of the whole data.\n * \n * Options are:\n * - offset (int) default 0 (optional) - the offset in the data to start the slice\n * - rowCount (int) default 20 (optional / calculated) - the number of rows in the slice\n * - rowHeight (int) default 26 (optional) - the height of a single row in pixels\n * - itemsPerRow (int) default 1 (optional) - the number of items on a single row\n * - size (int) default data.current.length (calculated) - how many rows inside data.current before slicing\n * - scrollbar (HTMLElement) defualt null (optional) - if set, an effect is added to update this elements \n * \t height if data.current.length changes\n * - container (HTMLElement) default null (optional) - if set, a scroll listener is added to this element, \n * which will update the options.offset signal and trigger the slice effect. It will also set the rowCount.\n */\nexport function scroll(options) {\n\n\treturn function(data) {\n\t\tthis.state.options.scroll = Object.assign({\n\t\t\toffset: 0,\n\t\t\trowHeight: 26,\n\t\t\trowCount: 20,\n\t\t\titemsPerRow: 1,\n\t\t\tsize: data.current.length\n\t\t}, options)\n\t\tconst scrollOptions = this.state.options.scroll\n\n\t\tconst scrollbar = scrollOptions.scrollbar \n\t\t\t|| scrollOptions.container?.querySelector('[data-flow-scrollbar]')\n\t\tif (scrollbar) {\n\t\t\tif (scrollOptions.container) {\n\t\t\t\tscrollOptions.container.addEventListener('scroll', (evt) => {\n\t\t\t\t\tscrollOptions.offset = Math.floor(scrollOptions.container.scrollTop\n\t\t\t\t\t\t/ (scrollOptions.rowHeight*scrollOptions.itemsPerRow)\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tthrottledEffect(() => {\n\t\t\t\tscrollOptions.size = data.current.length * scrollOptions.rowHeight\n\t\t\t\tscrollbar.style.height = scrollOptions.size + 'px'\n\t\t\t}, 50)\n\t\t}\n\n\t\treturn throttledEffect(() => {\n\t\t\tif (scrollOptions.container) {\n\t\t\t\t//TODO: add a resize listener so that if the size of the container\n\t\t\t\t// changes, the rowCount is calculated again\n\t\t\t\tscrollOptions.rowCount = Math.ceil(\n\t\t\t\t\tscrollOptions.container.getBoundingClientRect().height \n\t\t\t\t\t/ scrollOptions.rowHeight\n\t\t\t\t)\n\t\t\t}\n\t\t\tscrollOptions.data = data.current\n\t\t\tlet start = Math.min(scrollOptions.offset, data.current.length-1)\n\t\t\tlet end = start + scrollOptions.rowCount\n\t\t\tif (end > data.current.length) {\n\t\t\t\tend = data.current.length\n\t\t\t\tstart = end - scrollOptions.rowCount\n\t\t\t}\n\t\t\treturn data.current.slice(start, end)\n\t\t}, 50)\n\t}\n}", "export class SimplyRender extends HTMLElement \n{\n constructor()\n {\n super()\n }\n\n connectedCallback()\n {\n let templateId = this.getAttribute(\"rel\")\n let template = document.getElementById(templateId)\n\n if (template) {\n let content = template.content.cloneNode(true)\n for (const node of content.childNodes) {\n const clone = node.cloneNode(true)\n if (clone.nodeType == document.ELEMENT_NODE) {\n clone.querySelectorAll(\"template\").forEach(function(t) {\n t.setAttribute(\"simply-render\", \"\") //FIXME: whats this?\n })\n if (this.attributes) {\n for (const attr of this.attributes) {\n if (attr.name!='rel') {\n clone.setAttribute(attr.name, attr.value)\n }\n }\n }\n }\n this.parentNode.insertBefore(clone, this)\n }\n this.parentNode.removeChild(this)\n } else {\n const observe = () => {\n const observer = new MutationObserver(() => {\n template = document.getElementById(templateId)\n if (template) {\n observer.disconnect()\n this.replaceWith(this) // trigger connectedCallback?\n }\n })\n observer.observe(globalThis.document, {\n subtree: true,\n childList: true,\n })\n }\n\n observe()\n }\n }\n}\n\nif (!customElements.get('simply-render')) {\n customElements.define('simply-render', SimplyRender);\n}", "import { bind } from './bind.mjs'\nimport * as model from './model.mjs'\nimport * as state from './state.mjs'\nimport './render.mjs'\nimport * as dom from './dom.mjs'\n\nif (!globalThis.simply) {\n\tglobalThis.simply = {}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AClC,CACI,aACA,CACI,MAAM,CACV,CAEA,mBACA,CACI,IAAIC,EAAa,KAAK,aAAa,KAAK,EACpCC,EAAW,SAAS,eAAeD,CAAU,EAEjD,GAAIC,EAAU,CACV,IAAIC,EAAUD,EAAS,QAAQ,UAAU,EAAI,EAC7C,QAAWE,KAAQD,EAAQ,WAAY,CACnC,IAAME,EAAQD,EAAK,UAAU,EAAI,EACjC,GAAIC,EAAM,UAAY,SAAS,eAC3BA,EAAM,iBAAiB,UAAU,EAAE,QAAQ,SAASC,EAAG,CACnDA,EAAE,aAAa,gBAAiB,EAAE,CACtC,CAAC,EACG,KAAK,YACL,QAAWC,KAAQ,KAAK,WAChBA,EAAK,MAAM,OACXF,EAAM,aAAaE,EAAK,KAAMA,EAAK,KAAK,EAKxD,KAAK,WAAW,aAAaF,EAAO,IAAI,CAC5C,CACA,KAAK,WAAW,YAAY,IAAI,CACpC,MACoB,IAAM,CAClB,IAAMG,EAAW,IAAI,iBAAiB,IAAM,CACxCN,EAAW,SAAS,eAAeD,CAAU,EACzCC,IACAM,EAAS,WAAW,EACpB,KAAK,YAAY,IAAI,EAE7B,CAAC,EACDA,EAAS,QAAQ,WAAW,SAAU,CAClC,QAAS,GACT,UAAW,EACf,CAAC,CACL,GAEQ,CAEhB,CACJ,EAEK,eAAe,IAAI,eAAe,GACnC,eAAe,OAAO,gBAAiBR,EAAY,EC9ClD,WAAW,SACf,WAAW,OAAS,CAAC,GAEtB,OAAO,OAAO,WAAW,OAAQ,CAChC,KAAAS,GACA,KAAMC,GACN,MAAAC,EACA,IAAAC,CACD,CAAC,EAED,IAAOC,GAAQ,WAAW",
6
+ "names": ["state_exports", "__export", "addTracer", "batch", "clockEffect", "destroy", "effect", "makeContext", "notifyGet", "notifySet", "signal", "signals", "throttledEffect", "trace", "untracked", "unwrap", "iterate", "signalHandler", "target", "property", "receiver", "value", "args", "l", "result", "current", "descriptor", "v", "tracers", "tracing", "prop", "getListeners", "listener", "tracer", "callTracers", "getset", "params", "batchedListeners", "batchMode", "self", "context", "disableTracking", "listeners", "change", "propListeners", "addContext", "currentEffect", "computeStack", "clearContext", "currentCompute", "setListeners", "listenersMap", "computeMap", "compute", "connectedSignals", "clearListeners", "s", "effectStack", "effectMap", "signalStack", "fn", "f", "connectedSignal", "computeEffect", "runBatchedListeners", "copyBatchedListeners", "throttleTime", "throttled", "hasChange", "clock", "lastTick", "hasChanged", "seen", "innerUnwrap", "ob", "key", "escape_html", "context", "next", "content", "fixed_content", "dom_exports", "__export", "signal", "domSignalHandler", "target", "property", "receiver", "value", "notifyGet", "signal", "signals", "el", "domListen", "observers", "oldContentHTML", "oldContentText", "observer", "mutationList", "changes", "mutation", "prop", "notifySet", "makeContext", "prevValue", "evt", "field", "context", "fieldByTemplates", "renderer", "s", "signal", "setValueByPath", "list", "arrayByTemplates", "map", "objectByTemplates", "root", "path", "value", "parts", "curr", "part", "prev", "prevPart", "attribute", "items", "lastKey", "skipped", "item", "currentKey", "bindings", "needsReplacement", "b", "databind", "newTemplate", "length", "key", "clone", "outOfOrderItem", "i", "rendered", "template", "getParentPath", "el", "parentEl", "input", "element", "matchValue", "button", "setProperties", "select", "option", "o", "setSelectOptions", "addOption", "options", "anchor", "image", "iframe", "meta", "strValue", "data", "properties", "property", "a", "SimplyBind", "options", "defaultTransformers", "escape_html", "fixed_content", "defaultOptions", "field", "list", "map", "input", "button", "select", "anchor", "image", "iframe", "meta", "element", "attribute", "bindAttributes", "transformAttribute", "getBindingAttribute", "el", "foundAttribute", "attr", "renderElement", "throttledEffect", "untrack", "destroy", "context", "getValueByPath", "track", "runTransformers", "transformers", "t", "next", "transformer", "applyBindings", "bindings", "bindingEl", "updateBindings", "changes", "selector", "change", "node", "path", "parent", "templates", "index", "value", "template", "result", "clone", "attributes", "binding", "bind", "links", "link", "templateMatches", "currentItem", "strItem", "matches", "rel", "replacement", "tracking", "track", "el", "context", "tracking", "untrack", "path", "list", "getValueByPath", "root", "parts", "curr", "part", "prevPart", "model_exports", "__export", "columns", "filter", "model", "paging", "scroll", "sort", "SimplyFlowModel", "state", "signal", "fn", "dataSignal", "connectedSignal", "model", "options", "sort", "data", "a", "b", "sortBy", "larger", "smaller", "throttledEffect", "paging", "batch", "start", "end", "filter", "columns", "input", "result", "key", "scroll", "scrollOptions", "scrollbar", "evt", "SimplyRender", "templateId", "template", "content", "node", "clone", "t", "attr", "observer", "bind", "model_exports", "state_exports", "dom_exports", "flow_default"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplyflow",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "description": "Flow based programming in javascript, with signals and effects",
5
5
  "main": "src/flow.mjs",
6
6
  "type": "module",
@@ -37,7 +37,8 @@
37
37
  "esbuild": "^0.24.2",
38
38
  "globals": "^15.13.0",
39
39
  "jest": "^29.7.0",
40
- "jest-environment-jsdom": "^29.7.0"
40
+ "jest-environment-jsdom": "^29.7.0",
41
+ "watch": "^1.0.2"
41
42
  },
42
43
  "files": [
43
44
  "README.md",
@@ -47,8 +48,5 @@
47
48
  "jest": {
48
49
  "transform": {},
49
50
  "testEnvironment": "jsdom"
50
- },
51
- "dependencies": {
52
- "watch": "^1.0.2"
53
51
  }
54
52
  }
@@ -2,7 +2,7 @@
2
2
  * Default renderers for data binding
3
3
  * Will be used unless overriden in the SimplyBind options parameter
4
4
  */
5
- import { domSignal } from './state.mjs'
5
+ import { signal as domSignal } from './dom.mjs'
6
6
 
7
7
  /**
8
8
  * This function is used by default to render dom elements with the `data-flow-field` attribute.
package/src/dom.mjs ADDED
@@ -0,0 +1,99 @@
1
+ import { signals, signal as stateSignal, notifyGet, notifySet, makeContext } from './state.mjs'
2
+
3
+ const domSignalHandler = {
4
+ get: (target, property, receiver) => {
5
+ if (property===Symbol.xRay) {
6
+ return target // don't notifyGet here, this is only called by set
7
+ }
8
+ if (property===Symbol.Signal) {
9
+ return true
10
+ }
11
+ const value = target?.[property]
12
+ notifyGet(receiver, property)
13
+ if (typeof value === 'function') {
14
+ return value.bind(target) // make sure element functions are not linked to the proxy
15
+ }
16
+ if (value && typeof value == 'object') {
17
+ return stateSignal(value)
18
+ }
19
+ return value
20
+ },
21
+ has: (target, property) => {
22
+ let receiver = signals.get(target)
23
+ if (receiver) {
24
+ notifyGet(receiver, property)
25
+ }
26
+ return Object.hasOwn(target, property)
27
+ },
28
+ ownKeys: (target) => {
29
+ let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here
30
+ if (receiver) {
31
+ notifyGet(receiver, iterate)
32
+ }
33
+ return Reflect.ownKeys(target)
34
+ }
35
+ }
36
+
37
+ export function signal(el) {
38
+ if (el[Symbol.xRay]) {
39
+ return el
40
+ }
41
+ if (!signals.has(el)) {
42
+ signals.set(el, new Proxy(el, domSignalHandler))
43
+ domListen(el, signals.get(el))
44
+ }
45
+ return signals.get(el)
46
+ }
47
+
48
+ const observers = new WeakMap()
49
+
50
+ function domListen(el, signal) {
51
+ let oldContentHTML = el.innerHTML
52
+ let oldContentText = el.innerText
53
+ if (!observers.has(el)) {
54
+ const observer = new MutationObserver((mutationList, observer) => {
55
+ // collect changes
56
+ const changes = {}
57
+ for (const mutation of mutationList) {
58
+ if (mutation.type==='attributes') {
59
+ // check if any listeners for each attribute
60
+ changes[mutation.attributeName] = mutation.attributeOldValue
61
+ } else if (mutation.type==='subtree' || mutation.type==='characterData') {
62
+ // change on innerHTML/innerText
63
+ if (el.innerHTML != oldContentHTML) {
64
+ changes.innerHTML = oldContentHTML
65
+ oldContentHTML = el.innerHTML
66
+ }
67
+ if (el.innerText != oldContentText) {
68
+ changes.innerText = oldContentText
69
+ oldContentText = el.innerText
70
+ }
71
+ }
72
+ }
73
+ for (const prop in changes) {
74
+ notifySet(signal, makeContext(prop, { was: changes[prop], now: el[prop] }))
75
+ }
76
+ })
77
+ observer.observe(el, {
78
+ characterData: true,
79
+ subtree: true,
80
+ attributes: true,
81
+ attributesOldValue: true
82
+ })
83
+ observers.set(el, observer)
84
+ //@TODO: unregister the observer when el is removed from the dom (after a timeout)
85
+ if (el.matches('input, textarea, select')) {
86
+ let prevValue = el.value
87
+ el.addEventListener('change', (evt) => {
88
+ notifySet(signal, makeContext('value', { was: prevValue, now: el.value }))
89
+ prevValue = el.value
90
+ })
91
+ if (el.matches('input, textarea')) {
92
+ el.addEventListener('input', (evt) => {
93
+ notifySet(signal, makeContext('value', { was: prevValue, now: el.value }))
94
+ prevValue = el.value
95
+ })
96
+ }
97
+ }
98
+ }
99
+ }
package/src/flow.mjs CHANGED
@@ -2,6 +2,7 @@ import { bind } from './bind.mjs'
2
2
  import * as model from './model.mjs'
3
3
  import * as state from './state.mjs'
4
4
  import './render.mjs'
5
+ import * as dom from './dom.mjs'
5
6
 
6
7
  if (!globalThis.simply) {
7
8
  globalThis.simply = {}
@@ -9,7 +10,8 @@ if (!globalThis.simply) {
9
10
  Object.assign(globalThis.simply, {
10
11
  bind,
11
12
  flow: model,
12
- state
13
+ state,
14
+ dom
13
15
  })
14
16
 
15
17
  export default globalThis.simply
package/src/model.mjs CHANGED
@@ -198,7 +198,7 @@ export function columns(options={}) {
198
198
  let result = {}
199
199
  for (let key of Object.keys(this.state.options.columns)) {
200
200
  if (!this.state.options.columns[key]?.hidden) {
201
- result[key] = input[key]
201
+ result[key] = input[key] ?? null
202
202
  }
203
203
  }
204
204
  return result
package/src/state.mjs CHANGED
@@ -116,7 +116,7 @@ const signalHandler = {
116
116
  * Makes sure that a given object or function always uses the same
117
117
  * signal
118
118
  */
119
- const signals = new WeakMap()
119
+ export const signals = new WeakMap()
120
120
 
121
121
  /**
122
122
  * Creates a new signal proxy of the given object, that intercepts get/has and set/delete
@@ -136,52 +136,6 @@ export function signal(v) {
136
136
  return signals.get(v)
137
137
  }
138
138
 
139
- const domSignalHandler = {
140
- get: (target, property, receiver) => {
141
- if (property===Symbol.xRay) {
142
- return target // don't notifyGet here, this is only called by set
143
- }
144
- if (property===Symbol.Signal) {
145
- return true
146
- }
147
- const value = target?.[property]
148
- domListen(target, receiver)
149
- notifyGet(receiver, property)
150
- if (typeof value === 'function') {
151
- return value.bind(target) // make sure element functions are not linked to the proxy
152
- }
153
- if (value && typeof value == 'object') {
154
- return signal(value)
155
- }
156
- return value
157
- },
158
- has: (target, property) => {
159
- let receiver = signals.get(target)
160
- if (receiver) {
161
- domListen(target, receiver)
162
- notifyGet(receiver, property)
163
- }
164
- return Object.hasOwn(target, property)
165
- },
166
- ownKeys: (target) => {
167
- let receiver = signals.get(target) // receiver is not part of the trap arguments, so retrieve it here
168
- if (receiver) {
169
- domListen(target, receiver)
170
- notifyGet(receiver, iterate)
171
- }
172
- return Reflect.ownKeys(target)
173
- }
174
- }
175
-
176
- export function domSignal(el) {
177
- if (el[Symbol.xRay]) {
178
- return el
179
- }
180
- if (!signals.has(el)) {
181
- signals.set(el, new Proxy(el, domSignalHandler))
182
- }
183
- return signals.get(el)
184
- }
185
139
 
186
140
  let tracers = []
187
141
  let tracing = false
@@ -254,7 +208,7 @@ let batchMode = 0
254
208
  * Triggers any reactor function that depends on this signal
255
209
  * to re-compute its values
256
210
  */
257
- function notifySet(self, context={}) {
211
+ export function notifySet(self, context={}) {
258
212
  if (disableTracking) {
259
213
  return
260
214
  }
@@ -287,60 +241,8 @@ function notifySet(self, context={}) {
287
241
  }
288
242
  }
289
243
 
290
- const observers = new WeakMap()
291
-
292
- function domListen(el, signal) {
293
- let oldContentHTML = el.innerHTML
294
- let oldContentText = el.innerText
295
- if (!observers.has(el)) {
296
- const observer = new MutationObserver((mutationList, observer) => {
297
- // collect changes
298
- const changes = {}
299
- for (const mutation of mutationList) {
300
- if (mutation.type==='attributes') {
301
- // check if any listeners for each attribute
302
- changes[mutation.attributeName] = mutation.attributeOldValue
303
- } else if (mutation.type==='subtree' || mutation.type==='characterData') {
304
- // change on innerHTML/innerText
305
- if (el.innerHTML != oldContentHTML) {
306
- changes.innerHTML = oldContentHTML
307
- oldContentHTML = el.innerHTML
308
- }
309
- if (el.innerText != oldContentText) {
310
- changes.innerText = oldContentText
311
- oldContentText = el.innerText
312
- }
313
- }
314
- }
315
- for (const prop in changes) {
316
- notifySet(signal, makeContext(prop, { was: changes[prop], now: el[prop] }))
317
- }
318
- })
319
- observer.observe(el, {
320
- characterData: true,
321
- subtree: true,
322
- attributes: true,
323
- attributesOldValue: true
324
- })
325
- observers.set(el, observer)
326
- //@TODO: unregister the observer when el is removed from the dom (after a timeout)
327
- if (el.matches('input, textarea, select')) {
328
- let prevValue = el.value
329
- el.addEventListener('change', (evt) => {
330
- notifySet(signal, makeContext('value', { was: prevValue, now: el.value }))
331
- prevValue = el.value
332
- })
333
- if (el.matches('input, textarea')) {
334
- el.addEventListener('input', (evt) => {
335
- notifySet(signal, makeContext('value', { was: prevValue, now: el.value }))
336
- prevValue = el.value
337
- })
338
- }
339
- }
340
- }
341
- }
342
244
 
343
- function makeContext(property, change) {
245
+ export function makeContext(property, change) {
344
246
  let context = new Map()
345
247
  if (typeof property === 'object') {
346
248
  for (let prop in property) {
@@ -374,7 +276,7 @@ function clearContext(listener) {
374
276
  * then it adds the current reactor (top of this stack) to its
375
277
  * listeners. These are later called if this property changes
376
278
  */
377
- function notifyGet(self, property) {
279
+ export function notifyGet(self, property) {
378
280
  if (disableTracking) {
379
281
  return
380
282
  }
@@ -734,7 +636,7 @@ export function untracked(fn) {
734
636
  let seen = new WeakMap()
735
637
 
736
638
  function innerUnwrap(ob) {
737
- if (!ob || typeof ob!=='object' || seen.has(ob)) {
639
+ if (!ob || typeof ob!=='object' || ob instanceof HTMLElement || seen.has(ob)) {
738
640
  return
739
641
  }
740
642
  seen.set(ob, true)