simplyview 3.0.1 → 3.0.3

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.
@@ -43,11 +43,11 @@
43
43
  matches = route.match.exec(path);
44
44
  if (matches && matches.length) {
45
45
  var params = {};
46
- route.params.forEach((key, i) => {
46
+ route.params.forEach((key, i2) => {
47
47
  if (key == "*") {
48
48
  key = "remainder";
49
49
  }
50
- params[key] = matches[i + 1];
50
+ params[key] = matches[i2 + 1];
51
51
  });
52
52
  Object.assign(params, options);
53
53
  args.route = route;
@@ -62,6 +62,8 @@
62
62
  if (path && path[path.length - 1] != "/") {
63
63
  return this.match(path + "/", options);
64
64
  }
65
+ console.log(path, this.routeInfo);
66
+ process.exit();
65
67
  return false;
66
68
  }
67
69
  runListeners(action, params) {
@@ -174,8 +176,7 @@
174
176
  function getRegexpFromRoute(route) {
175
177
  return new RegExp("^" + route.replace(/:\w+/g, "([^/]+)").replace(/:\*/, "(.*)"));
176
178
  }
177
- function parseRoutes(routes2) {
178
- let routeInfo = [];
179
+ function parseRoutes(routes2, routeInfo) {
179
180
  const paths = Object.keys(routes2);
180
181
  const matchParams = /:(\w+|\*)/g;
181
182
  for (let path of paths) {
@@ -219,7 +220,7 @@
219
220
  return;
220
221
  }
221
222
  const shouldContinue = this[command.name].call(options.app, command.source, command.value);
222
- if (shouldContinue === false) {
223
+ if (shouldContinue !== true) {
223
224
  evt.preventDefault();
224
225
  evt.stopPropagation();
225
226
  return false;
@@ -331,7 +332,14 @@
331
332
  }
332
333
 
333
334
  // src/key.mjs
334
- var SimplyKeys = class {
335
+ var KEY = Object.freeze({
336
+ Compose: 229,
337
+ Control: 17,
338
+ Meta: 224,
339
+ Alt: 18,
340
+ Shift: 16
341
+ });
342
+ var SimplyKey = class {
335
343
  constructor(options = {}) {
336
344
  if (!options.app) {
337
345
  options.app = {};
@@ -341,7 +349,7 @@
341
349
  }
342
350
  Object.assign(this, options.keys);
343
351
  const keyHandler = (e) => {
344
- if (e.isComposing || e.keyCode === 229) {
352
+ if (e.isComposing || e.keyCode === KEY.Compose) {
345
353
  return;
346
354
  }
347
355
  if (e.defaultPrevented) {
@@ -354,733 +362,88 @@
354
362
  if (e.target.closest("[data-simply-keyboard]")) {
355
363
  selectedKeyboard = e.target.closest("[data-simply-keyboard]").dataset.simplyKeyboard;
356
364
  }
357
- let key = "";
358
- if (e.ctrlKey && e.keyCode != 17) {
359
- key += "Control+";
360
- }
361
- if (e.metaKey && e.keyCode != 224) {
362
- key += "Meta+";
363
- }
364
- if (e.altKey && e.keyCode != 18) {
365
- key += "Alt+";
366
- }
367
- if (e.shiftKey && e.keyCode != 16) {
368
- key += "Shift+";
369
- }
370
- key += e.key;
371
- if (this[selectedKeyboard] && this[selectedKeyboard][key]) {
372
- let keyboard = this[selectedKeyboard];
373
- keyboard[key].call(options.app, e);
374
- }
375
- };
376
- options.app.container.addEventListener("keydown", keyHandler);
377
- }
378
- };
379
- function keys(options = {}) {
380
- return new SimplyKeys(options);
381
- }
382
-
383
- // src/state.mjs
384
- var iterate = Symbol("iterate");
385
- if (!Symbol.xRay) {
386
- Symbol.xRay = Symbol("xRay");
387
- }
388
- var signalHandler = {
389
- get: (target, property, receiver) => {
390
- if (property === Symbol.xRay) {
391
- return target;
392
- }
393
- const value = target?.[property];
394
- notifyGet(receiver, property);
395
- if (typeof value === "function") {
396
- if (Array.isArray(target)) {
397
- return (...args) => {
398
- let l = target.length;
399
- let result = value.apply(receiver, args);
400
- if (l != target.length) {
401
- notifySet(receiver, makeContext("length", { was: l, now: target.length }));
402
- }
403
- return result;
404
- };
405
- } else if (target instanceof Set || target instanceof Map) {
406
- return (...args) => {
407
- let s = target.size;
408
- let result = value.apply(target, args);
409
- if (s != target.size) {
410
- notifySet(receiver, makeContext("size", { was: s, now: target.size }));
411
- }
412
- if (["set", "add", "clear", "delete"].includes(property)) {
413
- notifySet(receiver, makeContext({ entries: {}, forEach: {}, has: {}, keys: {}, values: {}, [Symbol.iterator]: {} }));
414
- }
415
- return result;
416
- };
417
- } else if (target instanceof HTMLElement || target instanceof Number || target instanceof String || target instanceof Boolean) {
418
- return value.bind(target);
419
- } else {
420
- return value.bind(receiver);
421
- }
422
- }
423
- if (value && typeof value == "object") {
424
- return signal(value);
425
- }
426
- return value;
427
- },
428
- set: (target, property, value, receiver) => {
429
- value = value?.[Symbol.xRay] || value;
430
- let current = target[property];
431
- if (current !== value) {
432
- target[property] = value;
433
- notifySet(receiver, makeContext(property, { was: current, now: value }));
434
- }
435
- if (typeof current === "undefined") {
436
- notifySet(receiver, makeContext(iterate, {}));
437
- }
438
- return true;
439
- },
440
- has: (target, property) => {
441
- let receiver = signals.get(target);
442
- if (receiver) {
443
- notifyGet(receiver, property);
444
- }
445
- return Object.hasOwn(target, property);
446
- },
447
- deleteProperty: (target, property) => {
448
- if (typeof target[property] !== "undefined") {
449
- let current = target[property];
450
- delete target[property];
451
- let receiver = signals.get(target);
452
- notifySet(receiver, makeContext(property, { delete: true, was: current }));
453
- }
454
- return true;
455
- },
456
- defineProperty: (target, property, descriptor) => {
457
- if (typeof target[property] === "undefined") {
458
- let receiver = signals.get(target);
459
- notifySet(receiver, makeContext(iterate, {}));
460
- }
461
- return Object.defineProperty(target, property, descriptor);
462
- },
463
- ownKeys: (target) => {
464
- let receiver = signals.get(target);
465
- notifyGet(receiver, iterate);
466
- return Reflect.ownKeys(target);
467
- }
468
- };
469
- var signals = /* @__PURE__ */ new WeakMap();
470
- function signal(v) {
471
- if (!signals.has(v)) {
472
- signals.set(v, new Proxy(v, signalHandler));
473
- }
474
- return signals.get(v);
475
- }
476
- var batchedListeners = /* @__PURE__ */ new Set();
477
- var batchMode = 0;
478
- function notifySet(self, context = {}) {
479
- let listeners = [];
480
- context.forEach((change, property) => {
481
- let propListeners = getListeners(self, property);
482
- if (propListeners?.length) {
483
- for (let listener of propListeners) {
484
- addContext(listener, makeContext(property, change));
485
- }
486
- listeners = listeners.concat(propListeners);
487
- }
488
- });
489
- listeners = new Set(listeners.filter(Boolean));
490
- if (listeners) {
491
- if (batchMode) {
492
- batchedListeners = batchedListeners.union(listeners);
493
- } else {
494
- const currentEffect = computeStack[computeStack.length - 1];
495
- for (let listener of Array.from(listeners)) {
496
- if (listener != currentEffect && listener?.needsUpdate) {
497
- listener();
498
- }
499
- clearContext(listener);
500
- }
501
- }
502
- }
503
- }
504
- function makeContext(property, change) {
505
- let context = /* @__PURE__ */ new Map();
506
- if (typeof property === "object") {
507
- for (let prop in property) {
508
- context.set(prop, property[prop]);
509
- }
510
- } else {
511
- context.set(property, change);
512
- }
513
- return context;
514
- }
515
- function addContext(listener, context) {
516
- if (!listener.context) {
517
- listener.context = context;
518
- } else {
519
- context.forEach((change, property) => {
520
- listener.context.set(property, change);
521
- });
522
- }
523
- listener.needsUpdate = true;
524
- }
525
- function clearContext(listener) {
526
- delete listener.context;
527
- delete listener.needsUpdate;
528
- }
529
- function notifyGet(self, property) {
530
- let currentCompute = computeStack[computeStack.length - 1];
531
- if (currentCompute) {
532
- setListeners(self, property, currentCompute);
533
- }
534
- }
535
- var listenersMap = /* @__PURE__ */ new WeakMap();
536
- var computeMap = /* @__PURE__ */ new WeakMap();
537
- function getListeners(self, property) {
538
- let listeners = listenersMap.get(self);
539
- return listeners ? Array.from(listeners.get(property) || []) : [];
540
- }
541
- function setListeners(self, property, compute) {
542
- if (!listenersMap.has(self)) {
543
- listenersMap.set(self, /* @__PURE__ */ new Map());
544
- }
545
- let listeners = listenersMap.get(self);
546
- if (!listeners.has(property)) {
547
- listeners.set(property, /* @__PURE__ */ new Set());
548
- }
549
- listeners.get(property).add(compute);
550
- if (!computeMap.has(compute)) {
551
- computeMap.set(compute, /* @__PURE__ */ new Map());
552
- }
553
- let connectedSignals = computeMap.get(compute);
554
- if (!connectedSignals.has(property)) {
555
- connectedSignals.set(property, /* @__PURE__ */ new Set());
556
- }
557
- connectedSignals.get(property).add(self);
558
- }
559
- function clearListeners(compute) {
560
- let connectedSignals = computeMap.get(compute);
561
- if (connectedSignals) {
562
- connectedSignals.forEach((property) => {
563
- property.forEach((s) => {
564
- let listeners = listenersMap.get(s);
565
- if (listeners.has(property)) {
566
- listeners.get(property).delete(compute);
365
+ let keyCombination = [];
366
+ if (e.ctrlKey && e.keyCode != KEY.Control) {
367
+ keyCombination.push("Control");
368
+ }
369
+ if (e.metaKey && e.keyCode != KEY.Meta) {
370
+ keyCombination.push("Meta");
371
+ }
372
+ if (e.altKey && e.keyCode != KEY.Alt) {
373
+ keyCombination.push("Alt");
374
+ }
375
+ if (e.shiftKey && e.keyCode != KEY.Shift) {
376
+ keyCombination.push("Shift");
377
+ }
378
+ keyCombination.push(e.key.toLowerCase());
379
+ let keyboards = [];
380
+ let keyboardElement = event.target.closest("[data-simply-keyboard]");
381
+ while (keyboardElement) {
382
+ keyboards.push(keyboardElement.dataset.simplyKeyboard);
383
+ keyboardElement = keyboardElement.parentNode.closest("[data-simply-keyboard]");
384
+ }
385
+ keyboards.push("");
386
+ let keyboard, subkeyboard;
387
+ let separators = ["+", "-"];
388
+ for (i in keyboards) {
389
+ keyboard = keyboards[i];
390
+ if (keyboard == "") {
391
+ subkeyboard = "default";
392
+ } else {
393
+ subkeyboard = keyboard;
394
+ keyboard += ".";
567
395
  }
568
- });
569
- });
570
- }
571
- }
572
- var computeStack = [];
573
- var effectStack = [];
574
- var effectMap = /* @__PURE__ */ new WeakMap();
575
- var signalStack = [];
576
- function destroy(connectedSignal) {
577
- const computeEffect = effectMap.get(connectedSignal)?.deref();
578
- if (!computeEffect) {
579
- return;
580
- }
581
- clearListeners(computeEffect);
582
- let fn = computeEffect.fn;
583
- signals.remove(fn);
584
- effectMap.delete(connectedSignal);
585
- }
586
- function throttledEffect(fn, throttleTime) {
587
- if (effectStack.findIndex((f) => fn == f) !== -1) {
588
- throw new Error("Recursive update() call", { cause: fn });
589
- }
590
- effectStack.push(fn);
591
- let connectedSignal = signals.get(fn);
592
- if (!connectedSignal) {
593
- connectedSignal = signal({
594
- current: null
595
- });
596
- signals.set(fn, connectedSignal);
597
- }
598
- let throttled = false;
599
- let hasChange = true;
600
- const computeEffect = function computeEffect2() {
601
- if (signalStack.findIndex((s) => s == connectedSignal) !== -1) {
602
- throw new Error("Cyclical dependency in update() call", { cause: fn });
603
- }
604
- if (throttled && throttled > Date.now()) {
605
- hasChange = true;
606
- return;
607
- }
608
- clearListeners(computeEffect2);
609
- computeStack.push(computeEffect2);
610
- signalStack.push(connectedSignal);
611
- let result;
612
- try {
613
- result = fn(computeEffect2, computeStack, signalStack);
614
- } finally {
615
- hasChange = false;
616
- computeStack.pop();
617
- signalStack.pop();
618
- if (result instanceof Promise) {
619
- result.then((result2) => {
620
- connectedSignal.current = result2;
621
- });
622
- } else {
623
- connectedSignal.current = result;
624
- }
625
- }
626
- throttled = Date.now() + throttleTime;
627
- globalThis.setTimeout(() => {
628
- if (hasChange) {
629
- computeEffect2();
630
- }
631
- }, throttleTime);
632
- };
633
- computeEffect();
634
- return connectedSignal;
635
- }
636
-
637
- // src/bind.mjs
638
- var SimplyBind = class {
639
- constructor(options) {
640
- this.bindings = /* @__PURE__ */ new Map();
641
- const defaultOptions = {
642
- container: document.body,
643
- attribute: "data-bind",
644
- transformers: [],
645
- defaultTransformers: [defaultTransformer]
646
- };
647
- if (!options?.root) {
648
- throw new Error("bind needs at least options.root set");
649
- }
650
- this.options = Object.assign({}, defaultOptions, options);
651
- const attribute = this.options.attribute;
652
- const render = (el) => {
653
- this.bindings.set(el, throttledEffect(() => {
654
- const context = {
655
- templates: el.querySelectorAll(":scope > template"),
656
- path: this.getBindingPath(el)
657
- };
658
- context.value = getValueByPath(this.options.root, context.path);
659
- context.element = el;
660
- runTransformers(context);
661
- }, 100));
662
- };
663
- const runTransformers = (context) => {
664
- let transformers = this.options.defaultTransformers || [];
665
- if (context.element.dataset.transform) {
666
- context.element.dataset.transform.split(" ").filter(Boolean).forEach((t) => {
667
- if (this.options.transformers[t]) {
668
- transformers.push(this.options.transformers[t]);
669
- } else {
670
- console.warn("No transformer with name " + t + " configured", { cause: context.element });
671
- }
672
- });
673
- }
674
- let next;
675
- for (let transformer of transformers) {
676
- next = /* @__PURE__ */ ((next2, transformer2) => {
677
- return (context2) => {
678
- return transformer2.call(this, context2, next2);
679
- };
680
- })(next, transformer);
681
- }
682
- next(context);
683
- };
684
- const applyBindings = (bindings2) => {
685
- for (let bindingEl of bindings2) {
686
- render(bindingEl);
687
- }
688
- };
689
- const updateBindings = (changes) => {
690
- for (const change of changes) {
691
- if (change.type == "childList" && change.addedNodes) {
692
- for (let node of change.addedNodes) {
693
- if (node instanceof HTMLElement) {
694
- let bindings2 = Array.from(node.querySelectorAll(`[${attribute}]`));
695
- if (node.matches(`[${attribute}]`)) {
696
- bindings2.unshift(node);
697
- }
698
- if (bindings2.length) {
699
- applyBindings(bindings2);
700
- }
396
+ for (let separator of separators) {
397
+ let keyString = keyCombination.join(separator);
398
+ if (this[subkeyboard] && typeof this[subkeyboard][keyString] == "function") {
399
+ let _continue = this[subkeyboard][keyString].call(this[subkeyboard], e);
400
+ if (!_continue) {
401
+ e.preventDefault();
402
+ return;
701
403
  }
702
404
  }
703
- }
704
- }
705
- };
706
- this.observer = new MutationObserver((changes) => {
707
- updateBindings(changes);
708
- });
709
- this.observer.observe(options.container, {
710
- subtree: true,
711
- childList: true
712
- });
713
- const bindings = this.options.container.querySelectorAll("[" + this.options.attribute + "]:not(template)");
714
- if (bindings.length) {
715
- applyBindings(bindings);
716
- }
717
- }
718
- /**
719
- * Finds the first matching template and creates a new DocumentFragment
720
- * with the correct data bind attributes in it (prepends the current path)
721
- */
722
- applyTemplate(context) {
723
- const path = context.path;
724
- const templates = context.templates;
725
- const list = context.list;
726
- const index = context.index;
727
- const parent = context.parent;
728
- const value = list ? list[index] : context.value;
729
- let template = this.findTemplate(templates, value);
730
- if (!template) {
731
- let result = new DocumentFragment();
732
- result.innerHTML = "<!-- no matching template -->";
733
- return result;
734
- }
735
- let clone = template.content.cloneNode(true);
736
- if (!clone.children?.length) {
737
- throw new Error("template must contain a single html element", { cause: template });
738
- }
739
- if (clone.children.length > 1) {
740
- throw new Error("template must contain a single root node", { cause: template });
741
- }
742
- const bindings = clone.querySelectorAll("[" + this.options.attribute + "]");
743
- const attribute = this.options.attribute;
744
- for (let binding of bindings) {
745
- const bind2 = binding.getAttribute(attribute);
746
- if (bind2.substring(0, "#root.".length) == "#root.") {
747
- binding.setAttribute(attribute, bind2.substring("#root.".length));
748
- } else if (bind2 == "#value" && index != null) {
749
- binding.setAttribute(attribute, path + "." + index);
750
- } else if (index != null) {
751
- binding.setAttribute(attribute, path + "." + index + "." + bind2);
752
- } else {
753
- binding.setAttribute(attribute, parent + "." + bind2);
754
- }
755
- }
756
- if (typeof index !== "undefined") {
757
- clone.children[0].setAttribute(attribute + "-key", index);
758
- }
759
- clone.children[0].$bindTemplate = template;
760
- return clone;
761
- }
762
- getBindingPath(el) {
763
- return el.getAttribute(this.options.attribute);
764
- }
765
- /**
766
- * Finds the first template from an array of templates that
767
- * matches the given value.
768
- */
769
- findTemplate(templates, value) {
770
- const templateMatches = (t) => {
771
- let path = this.getBindingPath(t);
772
- let currentItem;
773
- if (path) {
774
- if (path.substr(0, 6) == "#root.") {
775
- currentItem = getValueByPath(this.options.root, path);
776
- } else {
777
- currentItem = getValueByPath(value, path);
778
- }
779
- } else {
780
- currentItem = value;
781
- }
782
- const strItem = "" + currentItem;
783
- let matches = t.getAttribute(this.options.attribute + "-match");
784
- if (matches) {
785
- if (matches === "#empty" && !currentItem) {
786
- return t;
787
- } else if (matches === "#notempty" && currentItem) {
788
- return t;
789
- }
790
- if (strItem.match(matches)) {
791
- return t;
792
- }
793
- }
794
- if (!matches) {
795
- if (currentItem) {
796
- return t;
797
- }
798
- }
799
- };
800
- let template = Array.from(templates).find(templateMatches);
801
- let rel = template?.getAttribute("rel");
802
- if (rel) {
803
- let replacement = document.querySelector("template#" + rel);
804
- if (!replacement) {
805
- throw new Error("Could not find template with id " + rel);
806
- }
807
- template = replacement;
808
- }
809
- return template;
810
- }
811
- destroy() {
812
- this.bindings.forEach((binding) => {
813
- destroy(binding);
814
- });
815
- this.bindings = /* @__PURE__ */ new Map();
816
- this.observer.disconnect();
817
- }
818
- };
819
- function bind(options) {
820
- return new SimplyBind(options);
821
- }
822
- function matchValue(a, b) {
823
- if (a == "#empty" && !b) {
824
- return true;
825
- }
826
- if (b == "#empty" && !a) {
827
- return true;
828
- }
829
- if ("" + a == "" + b) {
830
- return true;
831
- }
832
- return false;
833
- }
834
- function getValueByPath(root, path) {
835
- let parts = path.split(".");
836
- let curr = root;
837
- let part, prevPart;
838
- while (parts.length && curr) {
839
- part = parts.shift();
840
- if (part == "#key") {
841
- return prevPart;
842
- } else if (part == "#value") {
843
- return curr;
844
- } else if (part == "#root") {
845
- curr = root;
846
- } else {
847
- part = decodeURIComponent(part);
848
- curr = curr[part];
849
- prevPart = part;
850
- }
851
- }
852
- return curr;
853
- }
854
- function defaultTransformer(context) {
855
- const el = context.element;
856
- const templates = context.templates;
857
- const templatesCount = templates.length;
858
- const path = context.path;
859
- const value = context.value;
860
- const attribute = this.options.attribute;
861
- if (Array.isArray(value) && templates?.length) {
862
- transformArrayByTemplates.call(this, context);
863
- } else if (typeof value == "object" && templates?.length) {
864
- transformObjectByTemplates.call(this, context);
865
- } else if (templates?.length) {
866
- transformLiteralByTemplates.call(this, context);
867
- } else if (el.tagName == "INPUT") {
868
- transformInput.call(this, context);
869
- } else if (el.tagName == "BUTTON") {
870
- transformButton.call(this, context);
871
- } else if (el.tagName == "SELECT") {
872
- transformSelect.call(this, context);
873
- } else if (el.tagName == "A") {
874
- transformAnchor.call(this, context);
875
- } else {
876
- transformElement.call(this, context);
877
- }
878
- return context;
879
- }
880
- function transformArrayByTemplates(context) {
881
- const el = context.element;
882
- const templates = context.templates;
883
- const templatesCount = templates.length;
884
- const path = context.path;
885
- const value = context.value;
886
- const attribute = this.options.attribute;
887
- let items = el.querySelectorAll(":scope > [" + attribute + "-key]");
888
- let lastKey = 0;
889
- let skipped = 0;
890
- context.list = value;
891
- for (let item of items) {
892
- let currentKey = parseInt(item.getAttribute(attribute + "-key"));
893
- if (currentKey > lastKey) {
894
- context.index = lastKey;
895
- el.insertBefore(this.applyTemplate(context), item);
896
- } else if (currentKey < lastKey) {
897
- item.remove();
898
- } else {
899
- let bindings = Array.from(item.querySelectorAll(`[${attribute}]`));
900
- if (item.matches(`[${attribute}]`)) {
901
- bindings.unshift(item);
902
- }
903
- let needsReplacement = bindings.find((b) => {
904
- let databind = b.getAttribute(attribute);
905
- return databind.substr(0, 5) !== "#root" && databind.substr(0, path.length) !== path;
906
- });
907
- if (!needsReplacement) {
908
- if (item.$bindTemplate) {
909
- let newTemplate = this.findTemplate(templates, value[lastKey]);
910
- if (newTemplate != item.$bindTemplate) {
911
- needsReplacement = true;
912
- if (!newTemplate) {
913
- skipped++;
405
+ if (typeof this[subkeyboard + keyString] == "function") {
406
+ let _continue = this[subkeyboard + keyString].call(this, e);
407
+ if (!_continue) {
408
+ e.preventDefault();
409
+ return;
914
410
  }
915
411
  }
916
- }
917
- }
918
- if (needsReplacement) {
919
- context.index = lastKey;
920
- el.replaceChild(this.applyTemplate(context), item);
921
- }
922
- }
923
- lastKey++;
924
- if (lastKey >= value.length) {
925
- break;
926
- }
927
- }
928
- items = el.querySelectorAll(":scope > [" + attribute + "-key]");
929
- let length = items.length + skipped;
930
- if (length > value.length) {
931
- while (length > value.length) {
932
- let child = el.querySelectorAll(":scope > :not(template)")?.[length - 1];
933
- child?.remove();
934
- length--;
935
- }
936
- } else if (length < value.length) {
937
- while (length < value.length) {
938
- context.index = length;
939
- el.appendChild(this.applyTemplate(context));
940
- length++;
941
- }
942
- }
943
- }
944
- function transformObjectByTemplates(context) {
945
- const el = context.element;
946
- const templates = context.templates;
947
- const templatesCount = templates.length;
948
- const path = context.path;
949
- const value = context.value;
950
- const attribute = this.options.attribute;
951
- context.list = value;
952
- let list = Object.entries(value);
953
- let items = el.querySelectorAll(":scope > [" + attribute + "-key]");
954
- let current = 0;
955
- let skipped = 0;
956
- for (let item of items) {
957
- if (current >= list.length) {
958
- break;
959
- }
960
- let key = list[current][0];
961
- current++;
962
- let keypath = path + "." + key;
963
- let needsReplacement;
964
- const databind = item.getAttribute(attribute);
965
- if (databind && databind.substr(0, keypath.length) != keypath) {
966
- needsReplacement = true;
967
- } else {
968
- let bindings = Array.from(item.querySelectorAll(`[${attribute}]`));
969
- needsReplacement = bindings.find((b) => {
970
- const db = b.getAttribute(attribute);
971
- return db.substr(0, 5) !== "#root" && db.substr(0, keypath.length) !== keypath;
972
- });
973
- if (!needsReplacement) {
974
- if (item.$bindTemplate) {
975
- let newTemplate = this.findTemplate(templates, value[key]);
976
- if (newTemplate != item.$bindTemplate) {
977
- needsReplacement = true;
978
- if (!newTemplate) {
979
- skipped++;
412
+ if (this[selectedKeyboard] && this[selectedKeyboard][keyString]) {
413
+ let targets = options.app.container.querySelectorAll('[data-simply-accesskey="' + keyboard + keyString + '"]');
414
+ if (targets.length) {
415
+ targets.forEach((t) => t.click());
416
+ e.preventDefault();
980
417
  }
981
418
  }
982
419
  }
983
420
  }
984
- }
985
- if (needsReplacement) {
986
- context.index = key;
987
- let clone = this.applyTemplate(context);
988
- el.replaceChild(clone, item);
989
- }
990
- }
991
- items = el.querySelectorAll(":scope > [" + attribute + "-key]");
992
- let length = items.length + skipped;
993
- if (length > list.length) {
994
- while (length > list.length) {
995
- let child = el.querySelectorAll(":scope > :not(template)")?.[length - 1];
996
- child?.remove();
997
- length--;
998
- }
999
- } else if (length < list.length) {
1000
- while (length < list.length) {
1001
- context.index = list[length][0];
1002
- el.appendChild(this.applyTemplate(context));
1003
- length++;
1004
- }
1005
- }
1006
- }
1007
- function transformLiteralByTemplates(context) {
1008
- const el = context.element;
1009
- const templates = context.templates;
1010
- const value = context.value;
1011
- const attribute = this.options.attribute;
1012
- const rendered = el.querySelector(":scope > :not(template)");
1013
- const template = this.findTemplate(templates, value);
1014
- context.parent = el.parentElement?.closest(`[${attribute}]`)?.getAttribute(attribute) || "#root";
1015
- if (rendered) {
1016
- if (template) {
1017
- if (rendered?.$bindTemplate != template) {
1018
- const clone = this.applyTemplate(context);
1019
- el.replaceChild(clone, rendered);
1020
- }
1021
- } else {
1022
- el.removeChild(rendered);
1023
- }
1024
- } else if (template) {
1025
- const clone = this.applyTemplate(context);
1026
- el.appendChild(clone);
421
+ };
422
+ options.app.container.addEventListener("keydown", keyHandler);
1027
423
  }
424
+ };
425
+ function keys(options = {}) {
426
+ return new SimplyKey(options);
1028
427
  }
1029
- function transformInput(context) {
1030
- const el = context.element;
1031
- const value = context.value;
1032
- if (el.type == "checkbox" || el.type == "radio") {
1033
- if (matchValue(el.value, value)) {
1034
- el.checked = true;
428
+
429
+ // src/view.mjs
430
+ function view(options) {
431
+ if (options.app) {
432
+ options.app.view = options.view || {};
433
+ const load = () => {
434
+ const data = options.app.view;
435
+ const path = globalThis.editor.data.getDataPath(options.app.container || document.body);
436
+ options.app.view = globalThis.editor.currentData[path];
437
+ Object.assign(options.app.view, data);
438
+ };
439
+ if (globalThis.editor && globalThis.editor.currentData) {
440
+ load();
1035
441
  } else {
1036
- el.checked = false;
1037
- }
1038
- } else if (!matchValue(el.value, value)) {
1039
- el.value = "" + value;
1040
- }
1041
- }
1042
- function transformButton(context) {
1043
- const el = context.element;
1044
- const value = context.value;
1045
- if (!matchValue(el.value, value)) {
1046
- el.value = "" + value;
1047
- }
1048
- }
1049
- function transformSelect(context) {
1050
- const el = context.element;
1051
- const value = context.value;
1052
- if (el.multiple) {
1053
- if (Array.isArray(value)) {
1054
- for (let option of el.options) {
1055
- if (value.indexOf(option.value) === false) {
1056
- option.selected = false;
1057
- } else {
1058
- option.selected = true;
1059
- }
1060
- }
442
+ document.addEventListener("simply-content-loaded", load);
1061
443
  }
444
+ return options.app.view;
1062
445
  } else {
1063
- let option = el.options.find((o) => matchValue(o.value, value));
1064
- if (option) {
1065
- option.selected = true;
1066
- }
1067
- }
1068
- }
1069
- function transformAnchor(context) {
1070
- const el = context.element;
1071
- const value = context.value;
1072
- if (value?.innerHTML && !matchValue(el.innerHTML, value.innerHTML)) {
1073
- el.innerHTML = "" + value.innerHTML;
1074
- }
1075
- if (value?.href && !matchValue(el.href, value.href)) {
1076
- el.href = "" + value.href;
1077
- }
1078
- }
1079
- function transformElement(context) {
1080
- const el = context.element;
1081
- const value = context.value;
1082
- if (!matchValue(el.innerHTML, value)) {
1083
- el.innerHTML = "" + value;
446
+ return options.view;
1084
447
  }
1085
448
  }
1086
449
 
@@ -1088,10 +451,6 @@
1088
451
  var SimplyApp = class {
1089
452
  constructor(options = {}) {
1090
453
  this.container = options.container || document.body;
1091
- if (!options.state) {
1092
- options.state = {};
1093
- }
1094
- this.state = signal(options.state);
1095
454
  if (options.commands) {
1096
455
  this.commands = commands({ app: this, container: this.container, commands: options.commands });
1097
456
  }
@@ -1104,14 +463,9 @@
1104
463
  if (options.actions) {
1105
464
  this.actions = actions({ app: this, actions: options.actions });
1106
465
  }
1107
- let bindOptions = { container: this.container, root: this.state };
1108
- if (options.defaultTransformers) {
1109
- bindOptions.defaultTransformers = options.defaultTransformers;
1110
- }
1111
- if (options.transformers) {
1112
- bindOptions.transformers = options.transformers;
466
+ if (options.view) {
467
+ this.view = view({ app: this, view: options.view });
1113
468
  }
1114
- this.bind = bind(bindOptions);
1115
469
  }
1116
470
  };
1117
471
  function app(options = {}) {