simplyflow 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,17 +14,24 @@
14
14
  effect: () => effect,
15
15
  signal: () => signal,
16
16
  throttledEffect: () => throttledEffect,
17
+ trace: () => trace,
17
18
  untracked: () => untracked
18
19
  });
19
20
  var iterate = Symbol("iterate");
20
21
  if (!Symbol.xRay) {
21
22
  Symbol.xRay = Symbol("xRay");
22
23
  }
24
+ if (!Symbol.Signal) {
25
+ Symbol.Signal = Symbol("Signal");
26
+ }
23
27
  var signalHandler = {
24
28
  get: (target, property, receiver) => {
25
29
  if (property === Symbol.xRay) {
26
30
  return target;
27
31
  }
32
+ if (property === Symbol.Signal) {
33
+ return true;
34
+ }
28
35
  const value = target?.[property];
29
36
  notifyGet(receiver, property);
30
37
  if (typeof value === "function") {
@@ -103,11 +110,27 @@
103
110
  };
104
111
  var signals = /* @__PURE__ */ new WeakMap();
105
112
  function signal(v) {
106
- if (!signals.has(v)) {
113
+ if (v[Symbol.Signal]) {
114
+ let target = v[Symbol.xRay];
115
+ if (!signals.has(target)) {
116
+ signals.set(target, v);
117
+ }
118
+ v = target;
119
+ } else if (!signals.has(v)) {
107
120
  signals.set(v, new Proxy(v, signalHandler));
108
121
  }
109
122
  return signals.get(v);
110
123
  }
124
+ function trace(signal2, prop) {
125
+ const listeners = getListeners(signal2, prop);
126
+ return listeners.map((listener) => {
127
+ return {
128
+ effect: listener.effectType,
129
+ fn: listener.effectFunction,
130
+ signal: signals.get(listener.effectFunction)
131
+ };
132
+ });
133
+ }
111
134
  var batchedListeners = /* @__PURE__ */ new Set();
112
135
  var batchMode = 0;
113
136
  function notifySet(self, context = {}) {
@@ -225,6 +248,8 @@
225
248
  throw new Error("Cyclical dependency in update() call", { cause: fn });
226
249
  }
227
250
  clearListeners(computeEffect2);
251
+ computeEffect2.effectFunction = fn;
252
+ computeEffect2.effectType = effect;
228
253
  computeStack.push(computeEffect2);
229
254
  signalStack.push(connectedSignal);
230
255
  let result;
@@ -313,6 +338,8 @@
313
338
  return;
314
339
  }
315
340
  clearListeners(computeEffect2);
341
+ computeEffect2.effectFunction = fn;
342
+ computeEffect2.effectType = throttledEffect;
316
343
  computeStack.push(computeEffect2);
317
344
  signalStack.push(connectedSignal);
318
345
  let result;
@@ -354,6 +381,8 @@
354
381
  if (lastTick < clock.time) {
355
382
  if (hasChanged) {
356
383
  clearListeners(computeEffect2);
384
+ computeEffect2.effectFunction = fn;
385
+ computeEffect2.effectType = clockEffect;
357
386
  computeStack.push(computeEffect2);
358
387
  lastTick = clock.time;
359
388
  let result;
@@ -392,12 +421,20 @@
392
421
 
393
422
  // src/bind.mjs
394
423
  var SimplyBind = class {
424
+ /**
425
+ * @param Object options - a set of options for this instance, options may include:
426
+ * - root (signal) (required) - the root data object that contains al signals that can be bound
427
+ * - container (HTMLElement) - the dom element to use as the root for all bindings
428
+ * - attribute (string) - the prefix for the field, list and map attributes, e.g. 'data-bind'
429
+ * - transformers (object name:function) - a map of transformer names and functions
430
+ * - defaultTransformers (object with field, list and map properties)
431
+ */
395
432
  constructor(options) {
396
433
  this.bindings = /* @__PURE__ */ new Map();
397
434
  const defaultOptions = {
398
435
  container: document.body,
399
436
  attribute: "data-bind",
400
- transformers: [],
437
+ transformers: {},
401
438
  defaultTransformers: {
402
439
  field: [defaultFieldTransformer],
403
440
  list: [defaultListTransformer],
@@ -411,15 +448,21 @@
411
448
  const attribute = this.options.attribute;
412
449
  const bindAttributes = [attribute + "-field", attribute + "-list", attribute + "-map"];
413
450
  const bindSelector = `[${attribute}-field],[${attribute}-list],[${attribute}-map]`;
451
+ const transformAttribute = attribute + "-transform";
414
452
  const getBindingAttribute = (el) => {
415
- const foundAttribute = bindAttributes.find((attr) => el.hasAttribute(attr));
453
+ const foundAttribute = bindAttributes.find((attr2) => el.hasAttribute(attr2));
416
454
  if (!foundAttribute) {
417
- console.error("No matching attribute found", el);
455
+ console.error("No matching attribute found", el, attr);
418
456
  }
419
457
  return foundAttribute;
420
458
  };
421
459
  const render = (el) => {
422
460
  this.bindings.set(el, throttledEffect(() => {
461
+ if (!el.isConnected) {
462
+ untrack(el, this.getBindingPath(el));
463
+ destroy(this.bindings.get(el));
464
+ return;
465
+ }
423
466
  const context = {
424
467
  templates: el.querySelectorAll(":scope > template"),
425
468
  attribute: getBindingAttribute(el)
@@ -427,8 +470,9 @@
427
470
  context.path = this.getBindingPath(el);
428
471
  context.value = getValueByPath(this.options.root, context.path);
429
472
  context.element = el;
473
+ track(el, context);
430
474
  runTransformers(context);
431
- }, 100));
475
+ }, 50));
432
476
  };
433
477
  const runTransformers = (context) => {
434
478
  let transformers;
@@ -443,8 +487,8 @@
443
487
  transformers = this.options.defaultTransformers.map || [];
444
488
  break;
445
489
  }
446
- if (context.element.dataset.transform) {
447
- context.element.dataset.transform.split(" ").filter(Boolean).forEach((t) => {
490
+ if (context.element.hasAttribute(transformAttribute)) {
491
+ context.element.getAttribute(transformAttribute).split(" ").filter(Boolean).forEach((t) => {
448
492
  if (this.options.transformers[t]) {
449
493
  transformers.push(this.options.transformers[t]);
450
494
  } else {
@@ -464,7 +508,9 @@
464
508
  };
465
509
  const applyBindings = (bindings2) => {
466
510
  for (let bindingEl of bindings2) {
467
- render(bindingEl);
511
+ if (!this.bindings.get(bindingEl)) {
512
+ render(bindingEl);
513
+ }
468
514
  }
469
515
  };
470
516
  const updateBindings = (changes) => {
@@ -488,7 +534,7 @@
488
534
  this.observer = new MutationObserver((changes) => {
489
535
  updateBindings(changes);
490
536
  });
491
- this.observer.observe(options.container, {
537
+ this.observer.observe(this.options.container, {
492
538
  subtree: true,
493
539
  childList: true
494
540
  });
@@ -502,6 +548,8 @@
502
548
  /**
503
549
  * Finds the first matching template and creates a new DocumentFragment
504
550
  * with the correct data bind attributes in it (prepends the current path)
551
+ * @param Context context
552
+ * @return DocumentFragment
505
553
  */
506
554
  applyTemplate(context) {
507
555
  const path = context.path;
@@ -527,33 +575,47 @@
527
575
  const attributes = [attribute + "-field", attribute + "-list", attribute + "-map"];
528
576
  const bindings = clone.querySelectorAll(`[${attribute}-field],[${attribute}-list],[${attribute}-map]`);
529
577
  for (let binding of bindings) {
530
- const attr = attributes.find((attr2) => binding.hasAttribute(attr2));
531
- const bind2 = binding.getAttribute(attr);
578
+ const attr2 = attributes.find((attr3) => binding.hasAttribute(attr3));
579
+ const bind2 = binding.getAttribute(attr2);
532
580
  if (bind2.substring(0, ":root.".length) == ":root.") {
533
- binding.setAttribute(attr, bind2.substring(":root.".length));
581
+ binding.setAttribute(attr2, bind2.substring(":root.".length));
534
582
  } else if (bind2 == ":value" && index != null) {
535
- binding.setAttribute(attr, path + "." + index);
583
+ binding.setAttribute(attr2, path + "." + index);
536
584
  } else if (index != null) {
537
- binding.setAttribute(attr, path + "." + index + "." + bind2);
585
+ binding.setAttribute(attr2, path + "." + index + "." + bind2);
538
586
  } else {
539
- binding.setAttribute(attr, parent + "." + bind2);
587
+ binding.setAttribute(attr2, parent + "." + bind2);
540
588
  }
541
589
  }
542
590
  if (typeof index !== "undefined") {
543
591
  clone.children[0].setAttribute(attribute + "-key", index);
544
592
  }
545
- clone.children[0].$bindTemplate = template;
593
+ Object.defineProperty(
594
+ clone.children[0],
595
+ "$bindTemplate",
596
+ {
597
+ value: template,
598
+ enumerable: false,
599
+ writable: true,
600
+ configurable: true
601
+ }
602
+ );
546
603
  return clone;
547
604
  }
605
+ /**
606
+ * Returns the path referenced in either the field, list or map attribute
607
+ * @param HTMLElement el
608
+ * @return string The path referenced, or void
609
+ */
548
610
  getBindingPath(el) {
549
611
  const attributes = [
550
612
  this.options.attribute + "-field",
551
613
  this.options.attribute + "-list",
552
614
  this.options.attribute + "-map"
553
615
  ];
554
- for (let attr of attributes) {
555
- if (el.hasAttribute(attr)) {
556
- return el.getAttribute(attr);
616
+ for (let attr2 of attributes) {
617
+ if (el.hasAttribute(attr2)) {
618
+ return el.getAttribute(attr2);
557
619
  }
558
620
  }
559
621
  }
@@ -612,6 +674,19 @@
612
674
  function bind(options) {
613
675
  return new SimplyBind(options);
614
676
  }
677
+ var tracking = /* @__PURE__ */ new Map();
678
+ function track(el, context) {
679
+ if (!tracking.has(context.path)) {
680
+ tracking.set(context.path, [context]);
681
+ } else {
682
+ tracking.get(context.path).push(context);
683
+ }
684
+ }
685
+ function untrack(el, path) {
686
+ let list = tracking.get(path);
687
+ list = list.filter((context) => context.element == el);
688
+ tracking.set(path, list);
689
+ }
615
690
  function matchValue(a, b) {
616
691
  if (a == ":empty" && !b) {
617
692
  return true;
@@ -667,6 +742,15 @@
667
742
  case "A":
668
743
  transformAnchor.call(this, context);
669
744
  break;
745
+ case "IMG":
746
+ transformImage.call(this, contet);
747
+ break;
748
+ case "IFRAME":
749
+ transformIframe.call(this, context);
750
+ break;
751
+ case "META":
752
+ transformMeta.call(this, context);
753
+ break;
670
754
  case "TEMPLATE":
671
755
  break;
672
756
  default:
@@ -684,7 +768,7 @@
684
768
  const value = context.value;
685
769
  const attribute = this.options.attribute;
686
770
  if (!Array.isArray(value)) {
687
- console.error("Value is not an array.", el, value);
771
+ console.error("Value is not an array.", el, path, value);
688
772
  } else if (!templates?.length) {
689
773
  console.error("No templates found in", el);
690
774
  } else {
@@ -700,7 +784,7 @@
700
784
  const value = context.value;
701
785
  const attribute = this.options.attribute;
702
786
  if (typeof value != "object") {
703
- console.error("Value is not an object.", el, value);
787
+ console.error("Value is not an object.", el, path, value);
704
788
  } else if (!templates?.length) {
705
789
  console.error("No templates found in", el);
706
790
  } else {
@@ -847,7 +931,11 @@
847
931
  }
848
932
  function transformInput(context) {
849
933
  const el = context.element;
850
- const value = context.value;
934
+ let value = context.value;
935
+ transformElement(context);
936
+ if (typeof value == "undefined") {
937
+ value = "";
938
+ }
851
939
  if (el.type == "checkbox" || el.type == "radio") {
852
940
  if (matchValue(el.value, value)) {
853
941
  el.checked = true;
@@ -861,48 +949,119 @@
861
949
  function transformButton(context) {
862
950
  const el = context.element;
863
951
  const value = context.value;
864
- if (!matchValue(el.value, value)) {
865
- el.value = "" + value;
866
- }
952
+ transformElement(context);
953
+ setProperties(el, value, "value");
867
954
  }
868
955
  function transformSelect(context) {
869
956
  const el = context.element;
870
- const value = context.value;
871
- if (el.multiple) {
872
- if (Array.isArray(value)) {
873
- for (let option of el.options) {
874
- if (value.indexOf(option.value) === false) {
875
- option.selected = false;
876
- } else {
877
- option.selected = true;
957
+ let value = context.value;
958
+ if (value === null) {
959
+ value = "";
960
+ }
961
+ if (typeof value != "object") {
962
+ if (el.multiple) {
963
+ if (Array.isArray(value)) {
964
+ for (let option of el.options) {
965
+ if (value.indexOf(option.value) === false) {
966
+ option.selected = false;
967
+ } else {
968
+ option.selected = true;
969
+ }
878
970
  }
879
971
  }
972
+ } else {
973
+ let option = el.options.find((o) => matchValue(o.value, value));
974
+ if (option) {
975
+ option.selected = true;
976
+ option.setAttribute("selected", true);
977
+ }
880
978
  }
881
979
  } else {
882
- let option = el.options.find((o) => matchValue(o.value, value));
883
- if (option) {
884
- option.selected = true;
980
+ if (value.options) {
981
+ setSelectOptions(el, value.options);
982
+ }
983
+ if (value.selected) {
984
+ transformSelect(Object.asssign({}, context, { value: value.selected }));
985
+ }
986
+ setProperties(el, value, "name", "id", "selectedIndex", "className");
987
+ }
988
+ }
989
+ function addOption(select, option) {
990
+ if (!option) {
991
+ return;
992
+ }
993
+ if (typeof option !== "object") {
994
+ select.options.add(new Option("" + option));
995
+ } else if (option.text) {
996
+ select.options.add(new Option(option.text, option.value, option.defaultSelected, option.selected));
997
+ } else if (typeof option.value != "undefined") {
998
+ select.options.add(new Option("" + option.value, option.value, option.defaultSelected, option.selected));
999
+ }
1000
+ }
1001
+ function setSelectOptions(select, options) {
1002
+ select.innerHTML = "";
1003
+ if (Array.isArray(options)) {
1004
+ for (const option of options) {
1005
+ addOption(select, option);
1006
+ }
1007
+ } else if (options && typeof options == "object") {
1008
+ for (const option in options) {
1009
+ addOption(select, { text: options[option], value: option });
885
1010
  }
886
1011
  }
887
1012
  }
888
1013
  function transformAnchor(context) {
889
1014
  const el = context.element;
890
1015
  const value = context.value;
891
- if (value?.innerHTML && !matchValue(el.innerHTML, value.innerHTML)) {
892
- el.innerHTML = "" + value.innerHTML;
893
- }
894
- if (value?.href && !matchValue(el.href, value.href)) {
895
- el.href = "" + value.href;
896
- }
1016
+ transformElement(context);
1017
+ setProperties(el, value, "title", "target", "href", "name", "newwindow", "nofollow");
897
1018
  }
898
- function transformElement(context) {
1019
+ function transformImage(context) {
1020
+ const el = context.element;
1021
+ const value = context.value;
1022
+ transformElement(context);
1023
+ setProperties(el, value, "title", "alt", "src");
1024
+ }
1025
+ function transformIframe(context) {
1026
+ const el = context.element;
1027
+ const value = context.value;
1028
+ transformElement(context);
1029
+ setProperties(el, value, "title", "src");
1030
+ }
1031
+ function transformMeta(context) {
899
1032
  const el = context.element;
900
1033
  const value = context.value;
901
- if (!matchValue(el.innerHTML, value)) {
902
- if (typeof value == "undefined" || value == null) {
903
- el.innerHTML = "";
1034
+ transformElement(context);
1035
+ setProperties(el, value, "content");
1036
+ }
1037
+ function transformElement(context) {
1038
+ const el = context.element;
1039
+ let value = context.value;
1040
+ if (typeof value == "undefined" || value == null) {
1041
+ value = "";
1042
+ }
1043
+ let strValue = "" + value;
1044
+ if (typeof value != "object" || strValue.substring(0, 8) != "[object ") {
1045
+ el.innerHTML = strValue;
1046
+ return;
1047
+ }
1048
+ setProperties(el, value, "innerHTML", "title", "id", "className");
1049
+ }
1050
+ function setProperties(el, data, ...properties) {
1051
+ if (!data || typeof data !== "object") {
1052
+ return;
1053
+ }
1054
+ for (const property of properties) {
1055
+ if (typeof data[property] === "undefined") {
1056
+ continue;
1057
+ }
1058
+ if (matchValue(el[property], data[property])) {
1059
+ continue;
1060
+ }
1061
+ if (data[property] === null) {
1062
+ el[property] = "";
904
1063
  } else {
905
- el.innerHTML = "" + value;
1064
+ el[property] = "" + data[property];
906
1065
  }
907
1066
  }
908
1067
  }
@@ -980,13 +1139,13 @@
980
1139
  }
981
1140
  }
982
1141
  }, options);
983
- return effect(() => {
1142
+ return throttledEffect(() => {
984
1143
  const sort2 = this.state.options.sort;
985
1144
  if (sort2?.sortBy && sort2?.direction) {
986
1145
  return data.current.toSorted(sort2?.sortFn);
987
1146
  }
988
1147
  return data.current;
989
- });
1148
+ }, 50);
990
1149
  };
991
1150
  }
992
1151
  function paging(options = {}) {
@@ -996,7 +1155,7 @@
996
1155
  pageSize: 20,
997
1156
  max: 1
998
1157
  }, options);
999
- return effect(() => {
1158
+ return throttledEffect(() => {
1000
1159
  return batch(() => {
1001
1160
  const paging2 = this.state.options.paging;
1002
1161
  if (!paging2.pageSize) {
@@ -1008,26 +1167,27 @@
1008
1167
  const end = start + paging2.pageSize;
1009
1168
  return data.current.slice(start, end);
1010
1169
  });
1011
- });
1170
+ }, 50);
1012
1171
  };
1013
1172
  }
1014
1173
  function filter(options) {
1015
1174
  if (!options?.name || typeof options.name !== "string") {
1016
1175
  throw new Error("filter requires options.name to be a string");
1017
1176
  }
1018
- if (this.state.options[options.name]) {
1019
- throw new Error("a filter with this name already exists on this model");
1020
- }
1021
1177
  if (!options.matches || typeof options.matches !== "function") {
1022
1178
  throw new Error("filter requires options.matches to be a function");
1023
1179
  }
1024
1180
  return function(data) {
1181
+ if (this.state.options[options.name]) {
1182
+ throw new Error("a filter with this name already exists on this model");
1183
+ }
1025
1184
  this.state.options[options.name] = options;
1026
- return effect(() => {
1185
+ return throttledEffect(() => {
1027
1186
  if (this.state.options[options.name].enabled) {
1028
- return data.filter(this.state.options[options.name].matches);
1187
+ return data.current.filter(this.state.options[options.name].matches.bind(this));
1029
1188
  }
1030
- });
1189
+ return data.current;
1190
+ }, 50);
1031
1191
  };
1032
1192
  }
1033
1193
  function columns(options = {}) {
@@ -1036,7 +1196,7 @@
1036
1196
  }
1037
1197
  return function(data) {
1038
1198
  this.state.options.columns = options;
1039
- return effect(() => {
1199
+ return throttledEffect(() => {
1040
1200
  return data.current.map((input) => {
1041
1201
  let result = {};
1042
1202
  for (let key of Object.keys(this.state.options.columns)) {
@@ -1046,7 +1206,7 @@
1046
1206
  }
1047
1207
  return result;
1048
1208
  });
1049
- });
1209
+ }, 50);
1050
1210
  };
1051
1211
  }
1052
1212
  function scroll(options) {
@@ -1068,12 +1228,12 @@
1068
1228
  );
1069
1229
  });
1070
1230
  }
1071
- effect(() => {
1231
+ throttledEffect(() => {
1072
1232
  scrollOptions.size = data.current.length * scrollOptions.rowHeight;
1073
1233
  scrollbar.style.height = scrollOptions.size + "px";
1074
- });
1234
+ }, 50);
1075
1235
  }
1076
- return effect(() => {
1236
+ return throttledEffect(() => {
1077
1237
  if (scrollOptions.container) {
1078
1238
  scrollOptions.rowCount = Math.ceil(
1079
1239
  scrollOptions.container.getBoundingClientRect().height / scrollOptions.rowHeight
@@ -1087,7 +1247,7 @@
1087
1247
  start = end - scrollOptions.rowCount;
1088
1248
  }
1089
1249
  return data.current.slice(start, end);
1090
- });
1250
+ }, 50);
1091
1251
  };
1092
1252
  }
1093
1253
 
@@ -1,2 +1,2 @@
1
- (()=>{var J=Object.defineProperty;var V=(e,t)=>{for(var n in t)J(e,n,{get:t[n],enumerable:!0})};var R={};V(R,{batch:()=>H,clockEffect:()=>_,destroy:()=>q,effect:()=>E,signal:()=>A,throttledEffect:()=>z,untracked:()=>ee});var P=Symbol("iterate");Symbol.xRay||(Symbol.xRay=Symbol("xRay"));var Q={get:(e,t,n)=>{if(t===Symbol.xRay)return e;let i=e?.[t];return O(n,t),typeof i=="function"?Array.isArray(e)?(...r)=>{let s=e.length,l=i.apply(n,r);return s!=e.length&&S(n,w("length",{was:s,now:e.length})),l}:e instanceof Set||e instanceof Map?(...r)=>{let s=e.size,l=i.apply(e,r);return s!=e.size&&S(n,w("size",{was:s,now:e.size})),["set","add","clear","delete"].includes(t)&&S(n,w({entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}})),l}: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;let r=e[t];return r!==n&&(e[t]=n,S(i,w(t,{was:r,now:n}))),typeof r>"u"&&S(i,w(P,{})),!0},has:(e,t)=>{let n=g.get(e);return n&&O(n,t),Object.hasOwn(e,t)},deleteProperty:(e,t)=>{if(typeof e[t]<"u"){let n=e[t];delete e[t];let i=g.get(e);S(i,w(t,{delete:!0,was:n}))}return!0},defineProperty:(e,t,n)=>{if(typeof e[t]>"u"){let i=g.get(e);S(i,w(P,{}))}return Object.defineProperty(e,t,n)},ownKeys:e=>{let t=g.get(e);return O(t,P),Reflect.ownKeys(e)}},g=new WeakMap;function A(e){return g.has(e)||g.set(e,new Proxy(e,Q)),g.get(e)}var B=new Set,k=0;function S(e,t={}){let n=[];if(t.forEach((i,r)=>{let s=Y(e,r);if(s?.length){for(let l of s)X(l,w(r,i));n=n.concat(s)}}),n=new Set(n.filter(Boolean)),n)if(k)B=B.union(n);else{let i=b[b.length-1];for(let r of Array.from(n))r!=i&&r?.needsUpdate&&r(),x(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 X(e,t){e.context?t.forEach((n,i)=>{e.context.set(i,n)}):e.context=t,e.needsUpdate=!0}function x(e){delete e.context,delete e.needsUpdate}function O(e,t){let n=b[b.length-1];n&&Z(e,t,n)}var M=new WeakMap,C=new WeakMap;function Y(e,t){let n=M.get(e);return n?Array.from(n.get(t)||[]):[]}function Z(e,t,n){M.has(e)||M.set(e,new Map);let i=M.get(e);i.has(t)||i.set(t,new Set),i.get(t).add(n),C.has(n)||C.set(n,new Map);let r=C.get(n);r.has(t)||r.set(t,new Set),r.get(t).add(e)}function $(e){let t=C.get(e);t&&t.forEach(n=>{n.forEach(i=>{let r=M.get(i);r.has(n)&&r.get(n).delete(e)})})}var b=[],L=[],j=new WeakMap,T=[];function E(e){if(L.findIndex(i=>e==i)!==-1)throw new Error("Recursive update() call",{cause:e});L.push(e);let t=g.get(e);t||(t=A({current:null}),g.set(e,t));let n=function i(){if(T.findIndex(s=>s==t)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});$(i),b.push(i),T.push(t);let r;try{r=e(i,b,T)}finally{b.pop(),T.pop(),r instanceof Promise?r.then(s=>{t.current=s}):t.current=r}};return n.fn=e,j.set(t,n),n(),t}function q(e){let t=j.get(e)?.deref();if(!t)return;$(t);let n=t.fn;g.remove(n),j.delete(e)}function H(e){k++;let t;try{t=e()}finally{t instanceof Promise?t.then(()=>{k--,k||W()}):(k--,k||W())}return t}function W(){let e=Array.from(B);B=new Set;let t=b[b.length-1];for(let n of e)n!=t&&n?.needsUpdate&&n(),x(n)}function z(e,t){if(L.findIndex(l=>e==l)!==-1)throw new Error("Recursive update() call",{cause:e});L.push(e);let n=g.get(e);n||(n=A({current:null}),g.set(e,n));let i=!1,r=!0;return function l(){if(T.findIndex(a=>a==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});if(i&&i>Date.now()){r=!0;return}$(l),b.push(l),T.push(n);let o;try{o=e(l,b,T)}finally{r=!1,b.pop(),T.pop(),o instanceof Promise?o.then(a=>{n.current=a}):n.current=o}i=Date.now()+t,globalThis.setTimeout(()=>{r&&l()},t)}(),n}function _(e,t){let n=g.get(e);n||(n=A({current:null}),g.set(e,n));let i=-1,r=!0;return function l(){if(i<t.time)if(r){$(l),b.push(l),i=t.time;let o;try{o=e(l,b)}finally{b.pop(),o instanceof Promise?o.then(a=>{n.current=a}):n.current=o,r=!1}}else i=t.time;else r=!0}(),n}function ee(e){let t=b.slice();b=[];try{return e()}finally{b=t}}var N=class{constructor(t){this.bindings=new Map;let n={container:document.body,attribute:"data-bind",transformers:[],defaultTransformers:{field:[te],list:[ne],map:[ie]}};if(!t?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},n,t);let i=this.options.attribute,r=[i+"-field",i+"-list",i+"-map"],s=`[${i}-field],[${i}-list],[${i}-map]`,l=u=>{let f=r.find(m=>u.hasAttribute(m));return f||console.error("No matching attribute found",u),f},o=u=>{this.bindings.set(u,z(()=>{let f={templates:u.querySelectorAll(":scope > template"),attribute:l(u)};f.path=this.getBindingPath(u),f.value=I(this.options.root,f.path),f.element=u,a(f)},100))},a=u=>{let f;switch(u.attribute){case this.options.attribute+"-field":f=this.options.defaultTransformers.field||[];break;case this.options.attribute+"-list":f=this.options.defaultTransformers.list||[];break;case this.options.attribute+"-map":f=this.options.defaultTransformers.map||[];break}u.element.dataset.transform&&u.element.dataset.transform.split(" ").filter(Boolean).forEach(d=>{this.options.transformers[d]?f.push(this.options.transformers[d]):console.warn("No transformer with name "+d+" configured",{cause:u.element})});let m;for(let d of f)m=((y,F)=>G=>F.call(this,G,y))(m,d);m(u)},p=u=>{for(let f of u)o(f)},c=u=>{let f=`[${i}-field],[${i}-list],[${i}-map]`;for(let m of u)if(m.type=="childList"&&m.addedNodes){for(let d of m.addedNodes)if(d instanceof HTMLElement){let y=Array.from(d.querySelectorAll(f));d.matches(f)&&y.unshift(d),y.length&&p(y)}}};this.observer=new MutationObserver(u=>{c(u)}),this.observer.observe(t.container,{subtree:!0,childList:!0});let h=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");h.length&&p(h)}applyTemplate(t){let n=t.path,i=t.templates,r=t.list,s=t.index,l=t.parent,o=r?r[s]:t.value,a=this.findTemplate(i,o);if(!a){let f=new DocumentFragment;return f.innerHTML="<!-- no matching template -->",f}let p=a.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:a});let c=this.options.attribute,h=[c+"-field",c+"-list",c+"-map"],u=p.querySelectorAll(`[${c}-field],[${c}-list],[${c}-map]`);for(let f of u){let m=h.find(y=>f.hasAttribute(y)),d=f.getAttribute(m);d.substring(0,6)==":root."?f.setAttribute(m,d.substring(6)):d==":value"&&s!=null?f.setAttribute(m,n+"."+s):s!=null?f.setAttribute(m,n+"."+s+"."+d):f.setAttribute(m,l+"."+d)}return typeof s<"u"&&p.children[0].setAttribute(c+"-key",s),p.children[0].$bindTemplate=a,p}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=l=>{let o=this.getBindingPath(l),a;o?o.substr(0,6)==":root."?a=I(this.options.root,o):a=I(n,o):a=n;let p=""+a,c=l.getAttribute(this.options.attribute+"-match");if(c){if(c===":empty"&&!a)return l;if(c===":notempty"&&a||p.match(c))return l}if(!c&&a!==null&&a!==void 0)return l},r=Array.from(t).find(i),s=r?.getAttribute("rel");if(s){let l=document.querySelector("template#"+s);if(!l)throw new Error("Could not find template with id "+s);r=l}return r}destroy(){this.bindings.forEach(t=>{q(t)}),this.bindings=new Map,this.observer.disconnect()}};function D(e){return new N(e)}function v(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}function I(e,t){let n=t.split("."),i=e,r,s;for(;n.length&&i;){if(r=n.shift(),r==":key")return s;if(r==":value")return i;r==":root"?i=e:(r=decodeURIComponent(r),i=i[r],s=r)}return i}function te(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute;if(n?.length)oe.call(this,e);else switch(t.tagName){case"INPUT":ae.call(this,e);break;case"BUTTON":fe.call(this,e);break;case"SELECT":ue.call(this,e);break;case"A":ce.call(this,e);break;case"TEMPLATE":break;default:pe.call(this,e);break}return e}function ne(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute;return Array.isArray(s)?n?.length?re.call(this,e):console.error("No templates found in",t):console.error("Value is not an array.",t,s),e}function ie(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute;return typeof s!="object"?console.error("Value is not an object.",t,s):n?.length?se.call(this,e):console.error("No templates found in",t),e}function re(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute,o=t.querySelectorAll(":scope > ["+l+"-key]"),a=0,p=0;e.list=s;for(let h of o){let u=parseInt(h.getAttribute(l+"-key"));if(u>a)e.index=a,t.insertBefore(this.applyTemplate(e),h);else if(u<a)h.remove();else{let f=Array.from(h.querySelectorAll(`[${l}]`));h.matches(`[${l}]`)&&f.unshift(h);let m=f.find(d=>{let y=d.getAttribute(l);return y.substr(0,5)!==":root"&&y.substr(0,r.length)!==r});if(!m&&h.$bindTemplate){let d=this.findTemplate(n,s[a]);d!=h.$bindTemplate&&(m=!0,d||p++)}m&&(e.index=a,t.replaceChild(this.applyTemplate(e),h))}if(a++,a>=s.length)break}o=t.querySelectorAll(":scope > ["+l+"-key]");let c=o.length+p;if(c>s.length)for(;c>s.length;)t.querySelectorAll(":scope > :not(template)")?.[c-1]?.remove(),c--;else if(c<s.length)for(;c<s.length;)e.index=c,t.appendChild(this.applyTemplate(e)),c++}function se(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute;e.list=s;let o=Array.from(t.querySelectorAll(":scope > ["+l+"-key]"));for(let a in e.list){e.index=a;let p=o.shift();if(!p){let h=this.applyTemplate(e);t.appendChild(h);continue}if(p.getAttribute[l+"-key"]!=a){o.unshift(p);let h=t.querySelector(":scope > ["+l+'-key="'+a+'"]');if(h)t.insertBefore(h,p),p=h,o=o.filter(u=>u!=h);else{let u=this.applyTemplate(e);t.insertBefore(u,p);continue}}if(this.findTemplate(n,s[a])!=p.$bindTemplate){let h=this.applyTemplate(e);t.replaceChild(h,p)}}for(;o.length;)o.shift().remove()}function le(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`):":root"}function oe(e){let t=e.element,n=e.templates,i=e.value,r=this.options.attribute,s=t.querySelector(":scope > :not(template)"),l=this.findTemplate(n,i);if(e.parent=le(t,r),s)if(l){if(s?.$bindTemplate!=l){let o=this.applyTemplate(e);t.replaceChild(o,s)}}else t.removeChild(s);else if(l){let o=this.applyTemplate(e);t.appendChild(o)}}function ae(e){let t=e.element,n=e.value;t.type=="checkbox"||t.type=="radio"?v(t.value,n)?t.checked=!0:t.checked=!1:v(t.value,n)||(t.value=""+n)}function fe(e){let t=e.element,n=e.value;v(t.value,n)||(t.value=""+n)}function ue(e){let t=e.element,n=e.value;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=>v(r.value,n));i&&(i.selected=!0)}}function ce(e){let t=e.element,n=e.value;n?.innerHTML&&!v(t.innerHTML,n.innerHTML)&&(t.innerHTML=""+n.innerHTML),n?.href&&!v(t.href,n.href)&&(t.href=""+n.href)}function pe(e){let t=e.element,n=e.value;v(t.innerHTML,n)||(typeof n>"u"||n==null?t.innerHTML="":t.innerHTML=""+n)}var K={};V(K,{columns:()=>ge,filter:()=>be,model:()=>he,paging:()=>me,scroll:()=>ye,sort:()=>de});var U=class{constructor(t){this.state=A(t),this.state.options||(this.state.options={}),this.effects=[{current:t.data}],this.view=A(t.data)}addEffect(t){let n=this.effects[this.effects.length-1];this.view=t.call(this,n),this.effects.push(this.view)}};function he(e){return new U(e)}function de(e={}){return function(t){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,i)=>{let r=this.state.options.sort,s=r.sortBy;if(!r.sortBy)return 0;let l=r.direction=="asc"?1:-1,o=r.direction=="asc"?-1:1;return typeof n?.[s]>"u"?typeof i?.[s]>"u"?0:l:typeof i?.[s]>"u"||n[s]<i[s]?o:n[s]>i[s]?l:0}},e),E(()=>{let n=this.state.options.sort;return n?.sortBy&&n?.direction?t.current.toSorted(n?.sortFn):t.current})}}function me(e={}){return function(t){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},e),E(()=>H(()=>{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)}))}}function be(e){if(!e?.name||typeof e.name!="string")throw new Error("filter requires options.name to be a string");if(this.state.options[e.name])throw new Error("a filter with this name already exists on this model");if(!e.matches||typeof e.matches!="function")throw new Error("filter requires options.matches to be a function");return function(t){return this.state.options[e.name]=e,E(()=>{if(this.state.options[e.name].enabled)return t.filter(this.state.options[e.name].matches)})}}function ge(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,E(()=>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}))}}function ye(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))}),E(()=>{n.size=t.current.length*n.rowHeight,i.style.height=n.size+"px"})),E(()=>{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),s=r+n.rowCount;return s>t.current.length&&(s=t.current.length,r=s-n.rowCount),t.current.slice(r,s)})}}window.simply||(window.simply={});Object.assign(window.simply,{bind:D,flow:K,state:R});var ve=window.simply;})();
1
+ (()=>{var ne=Object.defineProperty;var D=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})};var F={};D(F,{batch:()=>H,clockEffect:()=>X,destroy:()=>q,effect:()=>Q,signal:()=>T,throttledEffect:()=>w,trace:()=>re,untracked:()=>oe});var R=Symbol("iterate");Symbol.xRay||(Symbol.xRay=Symbol("xRay"));Symbol.Signal||(Symbol.Signal=Symbol("Signal"));var ie={get:(e,t,n)=>{if(t===Symbol.xRay)return e;if(t===Symbol.Signal)return!0;let i=e?.[t];return z(n,t),typeof i=="function"?Array.isArray(e)?(...r)=>{let s=e.length,l=i.apply(n,r);return s!=e.length&&v(n,S("length",{was:s,now:e.length})),l}:e instanceof Set||e instanceof Map?(...r)=>{let s=e.size,l=i.apply(e,r);return s!=e.size&&v(n,S("size",{was:s,now:e.size})),["set","add","clear","delete"].includes(t)&&v(n,S({entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}})),l}:e instanceof HTMLElement||e instanceof Number||e instanceof String||e instanceof Boolean?i.bind(e):i.bind(n):i&&typeof i=="object"?T(i):i},set:(e,t,n,i)=>{n=n?.[Symbol.xRay]||n;let r=e[t];return r!==n&&(e[t]=n,v(i,S(t,{was:r,now:n}))),typeof r>"u"&&v(i,S(R,{})),!0},has:(e,t)=>{let n=b.get(e);return n&&z(n,t),Object.hasOwn(e,t)},deleteProperty:(e,t)=>{if(typeof e[t]<"u"){let n=e[t];delete e[t];let i=b.get(e);v(i,S(t,{delete:!0,was:n}))}return!0},defineProperty:(e,t,n)=>{if(typeof e[t]>"u"){let i=b.get(e);v(i,S(R,{}))}return Object.defineProperty(e,t,n)},ownKeys:e=>{let t=b.get(e);return z(t,R),Reflect.ownKeys(e)}},b=new WeakMap;function T(e){if(e[Symbol.Signal]){let t=e[Symbol.xRay];b.has(t)||b.set(t,e),e=t}else b.has(e)||b.set(e,new Proxy(e,ie));return b.get(e)}function re(e,t){return J(e,t).map(i=>({effect:i.effectType,fn:i.effectFunction,signal:b.get(i.effectFunction)}))}var P=new Set,M=0;function v(e,t={}){let n=[];if(t.forEach((i,r)=>{let s=J(e,r);if(s?.length){for(let l of s)se(l,S(r,i));n=n.concat(s)}}),n=new Set(n.filter(Boolean)),n)if(M)P=P.union(n);else{let i=m[m.length-1];for(let r of Array.from(n))r!=i&&r?.needsUpdate&&r(),x(r)}}function S(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 se(e,t){e.context?t.forEach((n,i)=>{e.context.set(i,n)}):e.context=t,e.needsUpdate=!0}function x(e){delete e.context,delete e.needsUpdate}function z(e,t){let n=m[m.length-1];n&&le(e,t,n)}var B=new WeakMap,j=new WeakMap;function J(e,t){let n=B.get(e);return n?Array.from(n.get(t)||[]):[]}function le(e,t,n){B.has(e)||B.set(e,new Map);let i=B.get(e);i.has(t)||i.set(t,new Set),i.get(t).add(n),j.has(n)||j.set(n,new Map);let r=j.get(n);r.has(t)||r.set(t,new Set),r.get(t).add(e)}function L(e){let t=j.get(e);t&&t.forEach(n=>{n.forEach(i=>{let r=B.get(i);r.has(n)&&r.get(n).delete(e)})})}var m=[],$=[],N=new WeakMap,A=[];function Q(e){if($.findIndex(i=>e==i)!==-1)throw new Error("Recursive update() call",{cause:e});$.push(e);let t=b.get(e);t||(t=T({current:null}),b.set(e,t));let n=function i(){if(A.findIndex(s=>s==t)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});L(i),i.effectFunction=e,i.effectType=Q,m.push(i),A.push(t);let r;try{r=e(i,m,A)}finally{m.pop(),A.pop(),r instanceof Promise?r.then(s=>{t.current=s}):t.current=r}};return n.fn=e,N.set(t,n),n(),t}function q(e){let t=N.get(e)?.deref();if(!t)return;L(t);let n=t.fn;b.remove(n),N.delete(e)}function H(e){M++;let t;try{t=e()}finally{t instanceof Promise?t.then(()=>{M--,M||G()}):(M--,M||G())}return t}function G(){let e=Array.from(P);P=new Set;let t=m[m.length-1];for(let n of e)n!=t&&n?.needsUpdate&&n(),x(n)}function w(e,t){if($.findIndex(l=>e==l)!==-1)throw new Error("Recursive update() call",{cause:e});$.push(e);let n=b.get(e);n||(n=T({current:null}),b.set(e,n));let i=!1,r=!0;return function l(){if(A.findIndex(f=>f==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});if(i&&i>Date.now()){r=!0;return}L(l),l.effectFunction=e,l.effectType=w,m.push(l),A.push(n);let a;try{a=e(l,m,A)}finally{r=!1,m.pop(),A.pop(),a instanceof Promise?a.then(f=>{n.current=f}):n.current=a}i=Date.now()+t,globalThis.setTimeout(()=>{r&&l()},t)}(),n}function X(e,t){let n=b.get(e);n||(n=T({current:null}),b.set(e,n));let i=-1,r=!0;return function l(){if(i<t.time)if(r){L(l),l.effectFunction=e,l.effectType=X,m.push(l),i=t.time;let a;try{a=e(l,m)}finally{m.pop(),a instanceof Promise?a.then(f=>{n.current=f}):n.current=a,r=!1}}else i=t.time;else r=!0}(),n}function oe(e){let t=m.slice();m=[];try{return e()}finally{m=t}}var V=class{constructor(t){this.bindings=new Map;let n={container:document.body,attribute:"data-bind",transformers:{},defaultTransformers:{field:[ue],list:[ce],map:[pe]}};if(!t?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},n,t);let i=this.options.attribute,r=[i+"-field",i+"-list",i+"-map"],s=`[${i}-field],[${i}-list],[${i}-map]`,l=i+"-transform",a=o=>{let u=r.find(d=>o.hasAttribute(d));return u||console.error("No matching attribute found",o,attr),u},f=o=>{this.bindings.set(o,w(()=>{if(!o.isConnected){fe(o,this.getBindingPath(o)),q(this.bindings.get(o));return}let u={templates:o.querySelectorAll(":scope > template"),attribute:a(o)};u.path=this.getBindingPath(o),u.value=U(this.options.root,u.path),u.element=o,ae(o,u),p(u)},50))},p=o=>{let u;switch(o.attribute){case this.options.attribute+"-field":u=this.options.defaultTransformers.field||[];break;case this.options.attribute+"-list":u=this.options.defaultTransformers.list||[];break;case this.options.attribute+"-map":u=this.options.defaultTransformers.map||[];break}o.element.hasAttribute(l)&&o.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:o.element})});let d;for(let g of u)d=((C,ee)=>te=>ee.call(this,te,C))(d,g);d(o)},c=o=>{for(let u of o)this.bindings.get(u)||f(u)},h=o=>{let u=`[${i}-field],[${i}-list],[${i}-map]`;for(let d of o)if(d.type=="childList"&&d.addedNodes){for(let g of d.addedNodes)if(g instanceof HTMLElement){let C=Array.from(g.querySelectorAll(u));g.matches(u)&&C.unshift(g),C.length&&c(C)}}};this.observer=new MutationObserver(o=>{h(o)}),this.observer.observe(this.options.container,{subtree:!0,childList:!0});let y=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");y.length&&c(y)}applyTemplate(t){let n=t.path,i=t.templates,r=t.list,s=t.index,l=t.parent,a=r?r[s]:t.value,f=this.findTemplate(i,a);if(!f){let o=new DocumentFragment;return o.innerHTML="<!-- no matching template -->",o}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 c=this.options.attribute,h=[c+"-field",c+"-list",c+"-map"],y=p.querySelectorAll(`[${c}-field],[${c}-list],[${c}-map]`);for(let o of y){let u=h.find(g=>o.hasAttribute(g)),d=o.getAttribute(u);d.substring(0,6)==":root."?o.setAttribute(u,d.substring(6)):d==":value"&&s!=null?o.setAttribute(u,n+"."+s):s!=null?o.setAttribute(u,n+"."+s+"."+d):o.setAttribute(u,l+"."+d)}return typeof s<"u"&&p.children[0].setAttribute(c+"-key",s),Object.defineProperty(p.children[0],"$bindTemplate",{value:f,enumerable:!1,writable:!0,configurable:!0}),p}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=l=>{let a=this.getBindingPath(l),f;a?a.substr(0,6)==":root."?f=U(this.options.root,a):f=U(n,a):f=n;let p=""+f,c=l.getAttribute(this.options.attribute+"-match");if(c){if(c===":empty"&&!f)return l;if(c===":notempty"&&f||p.match(c))return l}if(!c&&f!==null&&f!==void 0)return l},r=Array.from(t).find(i),s=r?.getAttribute("rel");if(s){let l=document.querySelector("template#"+s);if(!l)throw new Error("Could not find template with id "+s);r=l}return r}destroy(){this.bindings.forEach(t=>{q(t)}),this.bindings=new Map,this.observer.disconnect()}};function Z(e){return new V(e)}var O=new Map;function ae(e,t){O.has(t.path)?O.get(t.path).push(t):O.set(t.path,[t])}function fe(e,t){let n=O.get(t);n=n.filter(i=>i.element==e),O.set(t,n)}function I(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}function U(e,t){let n=t.split("."),i=e,r,s;for(;n.length&&i;){if(r=n.shift(),r==":key")return s;if(r==":value")return i;r==":root"?i=e:(r=decodeURIComponent(r),i=i[r],s=r)}return i}function ue(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute;if(n?.length)be.call(this,e);else switch(t.tagName){case"INPUT":ge.call(this,e);break;case"BUTTON":ye.call(this,e);break;case"SELECT":_.call(this,e);break;case"A":Se.call(this,e);break;case"IMG":Ae.call(this,contet);break;case"IFRAME":Te.call(this,e);break;case"META":ve.call(this,e);break;case"TEMPLATE":break;default:E.call(this,e);break}return e}function ce(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute;return Array.isArray(s)?n?.length?he.call(this,e):console.error("No templates found in",t):console.error("Value is not an array.",t,r,s),e}function pe(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute;return typeof s!="object"?console.error("Value is not an object.",t,r,s):n?.length?de.call(this,e):console.error("No templates found in",t),e}function he(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute,a=t.querySelectorAll(":scope > ["+l+"-key]"),f=0,p=0;e.list=s;for(let h of a){let y=parseInt(h.getAttribute(l+"-key"));if(y>f)e.index=f,t.insertBefore(this.applyTemplate(e),h);else if(y<f)h.remove();else{let o=Array.from(h.querySelectorAll(`[${l}]`));h.matches(`[${l}]`)&&o.unshift(h);let u=o.find(d=>{let g=d.getAttribute(l);return g.substr(0,5)!==":root"&&g.substr(0,r.length)!==r});if(!u&&h.$bindTemplate){let d=this.findTemplate(n,s[f]);d!=h.$bindTemplate&&(u=!0,d||p++)}u&&(e.index=f,t.replaceChild(this.applyTemplate(e),h))}if(f++,f>=s.length)break}a=t.querySelectorAll(":scope > ["+l+"-key]");let c=a.length+p;if(c>s.length)for(;c>s.length;)t.querySelectorAll(":scope > :not(template)")?.[c-1]?.remove(),c--;else if(c<s.length)for(;c<s.length;)e.index=c,t.appendChild(this.applyTemplate(e)),c++}function de(e){let t=e.element,n=e.templates,i=n.length,r=e.path,s=e.value,l=this.options.attribute;e.list=s;let a=Array.from(t.querySelectorAll(":scope > ["+l+"-key]"));for(let f in e.list){e.index=f;let p=a.shift();if(!p){let h=this.applyTemplate(e);t.appendChild(h);continue}if(p.getAttribute[l+"-key"]!=f){a.unshift(p);let h=t.querySelector(":scope > ["+l+'-key="'+f+'"]');if(h)t.insertBefore(h,p),p=h,a=a.filter(y=>y!=h);else{let y=this.applyTemplate(e);t.insertBefore(y,p);continue}}if(this.findTemplate(n,s[f])!=p.$bindTemplate){let h=this.applyTemplate(e);t.replaceChild(h,p)}}for(;a.length;)a.shift().remove()}function me(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`):":root"}function be(e){let t=e.element,n=e.templates,i=e.value,r=this.options.attribute,s=t.querySelector(":scope > :not(template)"),l=this.findTemplate(n,i);if(e.parent=me(t,r),s)if(l){if(s?.$bindTemplate!=l){let a=this.applyTemplate(e);t.replaceChild(a,s)}}else t.removeChild(s);else if(l){let a=this.applyTemplate(e);t.appendChild(a)}}function ge(e){let t=e.element,n=e.value;E(e),typeof n>"u"&&(n=""),t.type=="checkbox"||t.type=="radio"?I(t.value,n)?t.checked=!0:t.checked=!1:I(t.value,n)||(t.value=""+n)}function ye(e){let t=e.element,n=e.value;E(e),k(t,n,"value")}function _(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=>I(r.value,n));i&&(i.selected=!0,i.setAttribute("selected",!0))}else n.options&&we(t,n.options),n.selected&&_(Object.asssign({},e,{value:n.selected})),k(t,n,"name","id","selectedIndex","className")}function Y(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 we(e,t){if(e.innerHTML="",Array.isArray(t))for(let n of t)Y(e,n);else if(t&&typeof t=="object")for(let n in t)Y(e,{text:t[n],value:n})}function Se(e){let t=e.element,n=e.value;E(e),k(t,n,"title","target","href","name","newwindow","nofollow")}function Ae(e){let t=e.element,n=e.value;E(e),k(t,n,"title","alt","src")}function Te(e){let t=e.element,n=e.value;E(e),k(t,n,"title","src")}function ve(e){let t=e.element,n=e.value;E(e),k(t,n,"content")}function E(e){let t=e.element,n=e.value;(typeof n>"u"||n==null)&&(n="");let i=""+n;if(typeof n!="object"||i.substring(0,8)!="[object "){t.innerHTML=i;return}k(t,n,"innerHTML","title","id","className")}function k(e,t,...n){if(!(!t||typeof t!="object"))for(let i of n)typeof t[i]>"u"||I(e[i],t[i])||(t[i]===null?e[i]="":e[i]=""+t[i])}var W={};D(W,{columns:()=>Be,filter:()=>Ce,model:()=>Ee,paging:()=>Me,scroll:()=>Oe,sort:()=>ke});var K=class{constructor(t){this.state=T(t),this.state.options||(this.state.options={}),this.effects=[{current:t.data}],this.view=T(t.data)}addEffect(t){let n=this.effects[this.effects.length-1];this.view=t.call(this,n),this.effects.push(this.view)}};function Ee(e){return new K(e)}function ke(e={}){return function(t){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,i)=>{let r=this.state.options.sort,s=r.sortBy;if(!r.sortBy)return 0;let l=r.direction=="asc"?1:-1,a=r.direction=="asc"?-1:1;return typeof n?.[s]>"u"?typeof i?.[s]>"u"?0:l:typeof i?.[s]>"u"||n[s]<i[s]?a:n[s]>i[s]?l:0}},e),w(()=>{let n=this.state.options.sort;return n?.sortBy&&n?.direction?t.current.toSorted(n?.sortFn):t.current},50)}}function Me(e={}){return function(t){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},e),w(()=>H(()=>{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 Ce(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,w(()=>this.state.options[e.name].enabled?t.current.filter(this.state.options[e.name].matches.bind(this)):t.current,50)}}function Be(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,w(()=>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 Oe(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))}),w(()=>{n.size=t.current.length*n.rowHeight,i.style.height=n.size+"px"},50)),w(()=>{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),s=r+n.rowCount;return s>t.current.length&&(s=t.current.length,r=s-n.rowCount),t.current.slice(r,s)},50)}}window.simply||(window.simply={});Object.assign(window.simply,{bind:Z,flow:W,state:F});var Re=window.simply;})();
2
2
  //# sourceMappingURL=simply.flow.min.js.map