@jinntec/fore 2.6.0 → 2.7.0

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.
Files changed (53) hide show
  1. package/dist/fore-dev.js +4470 -2643
  2. package/dist/fore.js +4415 -2620
  3. package/index.js +2 -0
  4. package/package.json +10 -4
  5. package/resources/fore.css +2 -6
  6. package/src/DependencyNotifyingDomFacade.js +27 -21
  7. package/src/ForeElementMixin.js +282 -277
  8. package/src/actions/abstract-action.js +7 -12
  9. package/src/actions/fx-append.js +23 -2
  10. package/src/actions/fx-call.js +2 -2
  11. package/src/actions/fx-delete.js +54 -29
  12. package/src/actions/fx-insert.js +23 -15
  13. package/src/actions/fx-refresh.js +15 -5
  14. package/src/actions/fx-replace.js +18 -3
  15. package/src/actions/fx-reset.js +6 -0
  16. package/src/actions/fx-send.js +10 -7
  17. package/src/actions/fx-setattribute.js +12 -0
  18. package/src/actions/fx-setfocus.js +11 -8
  19. package/src/actions/fx-setvalue.js +93 -93
  20. package/src/actions/fx-toggle.js +1 -1
  21. package/src/extract-predicate-deps.js +57 -0
  22. package/src/extractPredicateDependencies.js +36 -0
  23. package/src/fore.js +41 -16
  24. package/src/fx-bind.js +128 -23
  25. package/src/fx-connection.js +24 -7
  26. package/src/fx-fore.js +506 -259
  27. package/src/fx-instance.js +9 -11
  28. package/src/fx-model.js +154 -65
  29. package/src/fx-submission.js +19 -30
  30. package/src/fx-var.js +5 -0
  31. package/src/getInScopeContext.js +7 -8
  32. package/src/modelitem.js +247 -112
  33. package/src/tools/fx-action-log.js +21 -19
  34. package/src/tools/fx-log-settings.js +4 -2
  35. package/src/ui/TemplateExpression.js +12 -0
  36. package/src/ui/UIElement.js +125 -10
  37. package/src/ui/abstract-control.js +5 -0
  38. package/src/ui/fx-case.js +15 -3
  39. package/src/ui/fx-container.js +5 -0
  40. package/src/ui/fx-control-menu.js +23 -14
  41. package/src/ui/fx-control.js +55 -15
  42. package/src/ui/fx-items.js +10 -4
  43. package/src/ui/fx-repeat-attributes.js +111 -35
  44. package/src/ui/fx-repeat.js +332 -85
  45. package/src/ui/fx-repeat.updated.js +821 -0
  46. package/src/ui/fx-repeatitem.js +23 -20
  47. package/src/ui/fx-switch.js +5 -3
  48. package/src/ui/fx-upload.js +36 -40
  49. package/src/ui/repeat-base.js +532 -0
  50. package/src/withDraggability.js +8 -4
  51. package/src/xpath-evaluation.js +26 -8
  52. package/src/xpath-path.js +79 -0
  53. package/src/xpath-util.js +357 -289
@@ -0,0 +1,79 @@
1
+ import * as fx from 'fontoxpath';
2
+ import { evaluateXPathToString } from './xpath-evaluation.js';
3
+
4
+ /**
5
+ * @param {string} path
6
+ * @returns string
7
+ */
8
+ function shortenPath(path) {
9
+ const tmp = path.replaceAll(/(Q{(.*?)\})/g, '');
10
+ if (tmp === 'root()') return tmp;
11
+ // cut off leading slash
12
+ const tmp1 = tmp.substring(1, tmp.length);
13
+ // ### cut-off root node ref
14
+ return tmp1.substring(tmp1.indexOf('/'), tmp.length);
15
+ }
16
+
17
+ /**
18
+ * @param {Node} node
19
+ * @returns string
20
+ */
21
+ export function getDocPath(node) {
22
+ const path = fx.evaluateXPathToString('path()', node);
23
+ // Path is like `$default/x[1]/y[1]`
24
+ const shortened = shortenPath(path);
25
+ return shortened.startsWith('/') ? `${shortened}` : `/${shortened}`;
26
+ }
27
+
28
+ /**
29
+ * @param {Node} node
30
+ * @param {string} instanceId
31
+ * @returns string
32
+ */
33
+ export function getPath(node, instanceId) {
34
+ const path = fx.evaluateXPathToString('path()', node);
35
+ // Path is like `$default/x[1]/y[1]`
36
+ const shortened = shortenPath(path);
37
+ return shortened.startsWith('/') ? `$${instanceId}${shortened}` : `$${instanceId}/${shortened}`;
38
+ }
39
+
40
+ /**
41
+ * Checks if a template expression is dynamic, i.e. refers to data (via XPath) or functions.
42
+ * Used to determine whether to set up data observers or evaluate on every refresh.
43
+ *
44
+ * @param {string} expr - The raw XPath expression (from inside `{}`)
45
+ * @returns {boolean} - True if the expression is dynamic (data/function dependent)
46
+ */
47
+ export function isDynamic(expr) {
48
+ try {
49
+ const result = evaluateXPathToString(expr, document, null);
50
+
51
+ // 1. Check for function calls with non-literal arguments
52
+ const functionCallPattern = /\b([\w-]+)\s*\(\s*([^)]+)\)/g;
53
+ let match;
54
+ while ((match = functionCallPattern.exec(expr)) !== null) {
55
+ const arg = match[2].trim();
56
+ if (!/^(['"]).*\1$/.test(arg) && isNaN(arg)) {
57
+ return true;
58
+ }
59
+ }
60
+
61
+ // 2. Check for variable references
62
+ if (expr.includes('$')) return true;
63
+
64
+ // 3. Check for unquoted predicates
65
+ let inQuote = false;
66
+ for (let i = 0; i < expr.length; i++) {
67
+ const char = expr[i];
68
+ if (char === '"' || char === "'") {
69
+ inQuote = inQuote === char ? false : char;
70
+ } else if (!inQuote && char === '[') {
71
+ return true;
72
+ }
73
+ }
74
+
75
+ return false;
76
+ } catch {
77
+ return true;
78
+ }
79
+ }