@ea-lab/reactive-json 1.3.0 → 2.0.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 (33) hide show
  1. package/dist/component/action/CustomEventListener.js +4 -3
  2. package/dist/component/action/ReactOnEvent.js +7 -6
  3. package/dist/component/attributeTransformer/setAttributeValue.js +21 -20
  4. package/dist/component/attributeTransformer/toggleAttributeValue.js +16 -15
  5. package/dist/component/attributeTransformer/unsetAttributeValue.js +9 -8
  6. package/dist/component/element/debug/VariablesDebug/VariablesDebug.js +75 -61
  7. package/dist/component/element/html/LabelFromValue.js +30 -18
  8. package/dist/component/element/index.js +28 -26
  9. package/dist/component/element/special/Count.js +1 -1
  10. package/dist/component/element/special/DataFilter.js +49 -40
  11. package/dist/component/element/special/DataSync.js +94 -0
  12. package/dist/component/element/special/ReactiveJsonSubroot.js +1 -1
  13. package/dist/component/element/special/index.js +15 -13
  14. package/dist/component/index.js +57 -55
  15. package/dist/component/reaction/fetchData.js +1 -1
  16. package/dist/component/reaction/index.js +1 -1
  17. package/dist/component/reaction/submitData.js +1 -1
  18. package/dist/component/reaction/utility/httpRequestCommon.js +119 -6
  19. package/dist/component/reaction/utility/index.js +1 -1
  20. package/dist/engine/DataStore.js +120 -0
  21. package/dist/engine/ReactiveJsonRoot.js +218 -277
  22. package/dist/engine/StoreContext.js +17 -0
  23. package/dist/engine/View.js +94 -58
  24. package/dist/engine/hook/useReactiveData.js +9 -0
  25. package/dist/engine/index.js +53 -45
  26. package/dist/engine/utility/formElementsCommon.js +36 -23
  27. package/dist/engine/utility/parseRjBuild.js +1 -1
  28. package/dist/{httpRequestCommon-BNA1zivP.js → index-BUPRVmV-.js} +599 -704
  29. package/dist/index-DJuOXIM5.js +25 -0
  30. package/dist/{js-yaml-Bw0KO4XO.js → js-yaml-CFDLc3Ha.js} +196 -193
  31. package/dist/main.js +156 -146
  32. package/package.json +2 -2
  33. package/dist/index-Ya6_R5yr.js +0 -23
@@ -1,76 +1,112 @@
1
1
  import { jsx as l } from "react/jsx-runtime";
2
- import { useContext as y } from "react";
3
- import { GlobalDataContext as D } from "./GlobalDataContext.js";
4
- import { TemplateContext as C } from "./TemplateContext.js";
5
- import L, { evaluateTemplateValue as x, dataLocationToPath as P } from "./TemplateSystem.js";
6
- function u({ props: t, currentData: o, datafield: c, path: n }) {
7
- const i = y(D), v = y(C), f = i.plugins ?? {}, d = (f == null ? void 0 : f.element) ?? {};
8
- if (!d)
2
+ import { useContext as x, useReducer as H, useSyncExternalStore as L, useMemo as O, useCallback as S } from "react";
3
+ import { GlobalDataContext as V } from "./GlobalDataContext.js";
4
+ import { TemplateContext as W } from "./TemplateContext.js";
5
+ import { useStore as N } from "./StoreContext.js";
6
+ import G, { dataLocationToPath as w } from "./TemplateSystem.js";
7
+ const y = (t) => !t || t === "data" ? "" : t.startsWith("data.") ? t.substring(5) : t, P = ({ props: t, datafield: g, path: o }) => {
8
+ const r = N(), i = x(V), s = x(W), [, J] = H((e) => e + 1, 0), v = y(o), D = (s == null ? void 0 : s.templatePath) || "data", b = (i == null ? void 0 : i.templatePath) || "data", C = L(
9
+ (e) => r.subscribe(v, e),
10
+ () => r.get(v)
11
+ ), u = O(() => {
12
+ if (!t || typeof t != "object") return [];
13
+ const e = [], n = (a) => {
14
+ if (a)
15
+ if (typeof a == "string") {
16
+ if (a.startsWith("~.") || a.startsWith("~~.") || a.startsWith("~>") || a.startsWith("~~>"))
17
+ try {
18
+ const c = w({
19
+ dataLocation: a,
20
+ currentPath: o,
21
+ globalDataContext: { templatePath: b },
22
+ templateContext: { templatePath: D }
23
+ });
24
+ c && c !== o && e.push(y(c));
25
+ } catch {
26
+ }
27
+ } else typeof a == "object" && Object.values(a).forEach((c) => n(c));
28
+ };
29
+ return n(t), [...new Set(e)];
30
+ }, [t, o, D, b]), E = S((e) => {
31
+ const n = u.map(
32
+ (a) => r.subscribe(a, e)
33
+ );
34
+ return () => n.forEach((a) => a());
35
+ }, [u, r]), R = S(() => {
36
+ const e = u.map((n) => r.get(n));
37
+ return JSON.stringify(e);
38
+ }, [u, r]);
39
+ L(E, R);
40
+ const m = i.plugins ?? {}, f = (m == null ? void 0 : m.element) ?? {};
41
+ if (!f)
9
42
  return null;
10
- const { element: T } = i;
11
- if (o === void 0 && (o = ""), t != null && t.type) {
12
- let e = d[t.type] ?? void 0;
13
- const a = d.Html;
14
- return e === void 0 && (e = a), e ? (a === e && (t.tag = t.tag ?? t.type), /* @__PURE__ */ l(e, { path: n, props: t, currentData: o, datafield: c })) : (console.warn(`No component found for type "${t.type}" and no Html fallback available.`), null);
43
+ const { element: k } = i, d = C === void 0 ? "" : C;
44
+ if (t != null && t.type) {
45
+ let e = f[t.type] ?? void 0;
46
+ const n = f.Html;
47
+ return e === void 0 && (e = n), e ? (n === e && (t.tag || (t.tag = t.type)), /* @__PURE__ */ l(e, { path: o, props: t, currentData: d, datafield: g })) : (console.warn(`No component found for type "${t.type}" and no Html fallback available.`), null);
15
48
  }
16
49
  if (t != null && t.load) {
17
50
  let e;
18
- const a = (t == null ? void 0 : t.customDataLocation) ?? void 0, m = a ? (
19
- // The data is located somewhere in the current data.
20
- x({
21
- globalDataContext: i,
22
- templateContext: v,
23
- valueToEvaluate: a
24
- })
25
- ) : (
26
- // The data is the current data.
27
- o
28
- ), r = a ? P({
29
- dataLocation: a,
30
- currentPath: n,
31
- globalDataContext: i,
32
- templateContext: v
33
- }) : n;
34
- typeof t.load == "function" ? e = t.load(m) : e = T[t.load];
35
- const { load: h, customDataLocation: g, ...b } = t;
36
- return e = { ...e, ...b }, t.keepTemplateContext ? /* @__PURE__ */ l(
37
- u,
38
- {
39
- currentData: m,
40
- datafield: c,
41
- path: r,
42
- props: e
51
+ const n = (t == null ? void 0 : t.customDataLocation) ?? void 0;
52
+ let a;
53
+ if (n)
54
+ try {
55
+ a = w({
56
+ dataLocation: n,
57
+ currentPath: o,
58
+ globalDataContext: { templatePath: "data", get templateData() {
59
+ return r.get("");
60
+ } },
61
+ templateContext: { templatePath: o, get templateData() {
62
+ return r.get("");
63
+ } }
64
+ });
65
+ } catch (h) {
66
+ console.error("View: Error evaluating customDataLocation", h), a = o;
43
67
  }
44
- ) : /* @__PURE__ */ l(C.Provider, { value: { templateData: m, templatePath: r }, children: /* @__PURE__ */ l(
45
- u,
68
+ else
69
+ a = o;
70
+ typeof t.load == "function" ? e = t.load(d) : e = k[t.load];
71
+ const { load: c, customDataLocation: M, ...z } = t;
72
+ e = { ...e, ...z };
73
+ const T = /* @__PURE__ */ l(
74
+ P,
46
75
  {
47
- currentData: m,
48
- datafield: c,
49
- path: r,
76
+ datafield: g,
77
+ path: a,
50
78
  props: e
51
79
  }
52
- ) });
80
+ );
81
+ if (t.keepTemplateContext)
82
+ return T;
83
+ const A = {
84
+ templatePath: a,
85
+ get templateData() {
86
+ const h = y(a);
87
+ return r.get(h);
88
+ }
89
+ };
90
+ return /* @__PURE__ */ l(W.Provider, { value: A, children: T });
53
91
  }
54
- return Array.isArray(t) ? t.map((e, a) => /* @__PURE__ */ l(
55
- u,
92
+ return Array.isArray(t) ? t.map((e, n) => /* @__PURE__ */ l(
93
+ P,
56
94
  {
57
- currentData: o[a] ?? void 0,
58
- datafield: a,
59
- path: n + "." + a,
95
+ path: o + "." + n,
96
+ datafield: n,
60
97
  props: e ?? void 0
61
98
  },
62
- n + "." + a
63
- )) : typeof t == "object" ? Object.entries(t).map(([e, a]) => /* @__PURE__ */ l(
64
- u,
99
+ o + "." + n
100
+ )) : typeof t == "object" ? Object.entries(t).map(([e, n]) => /* @__PURE__ */ l(
101
+ P,
65
102
  {
66
- currentData: o[e] ?? void 0,
103
+ path: o + "." + e,
67
104
  datafield: e ?? void 0,
68
- path: n + "." + e,
69
- props: a
105
+ props: n
70
106
  },
71
- n + "." + e
72
- )) : /* @__PURE__ */ l(L, { valueToEvaluate: o || (t ?? null) });
73
- }
107
+ o + "." + e
108
+ )) : /* @__PURE__ */ l(G, { valueToEvaluate: d || (t ?? null) });
109
+ };
74
110
  export {
75
- u as View
111
+ P as View
76
112
  };
@@ -0,0 +1,9 @@
1
+ import { useStore as u } from "../StoreContext.js";
2
+ import { useCallback as s, useSyncExternalStore as i } from "react";
3
+ const c = (t) => !t || t === "data" ? "" : t.startsWith("data.") ? t.substring(5) : t, f = (t) => {
4
+ const r = u(), e = c(t), n = s((a) => r.subscribe(e, a), [e, r]), o = s(() => r.get(e), [e, r]);
5
+ return i(n, o);
6
+ };
7
+ export {
8
+ f as useReactiveData
9
+ };
@@ -1,52 +1,60 @@
1
1
  import { ActionDependant as o, isValid as r } from "./Actions.js";
2
2
  import { mergeComponentCollections as p } from "./ComponentCollector.js";
3
- import { EventDispatcherContext as m } from "./EventDispatcherContext.js";
4
- import { EventDispatcherProvider as i, addEventListener as x, removeEventListener as f } from "./EventDispatcherProvider.js";
5
- import { GlobalDataContext as u } from "./GlobalDataContext.js";
6
- import { GlobalDataContextProvider as c } from "./GlobalDataContextProvider.js";
7
- import { PaginationContext as D } from "./PaginationContext.js";
8
- import { ReactiveJsonRoot as b } from "./ReactiveJsonRoot.js";
9
- import { TemplateContext as g } from "./TemplateContext.js";
10
- import { dataLocationToPath as E, evaluateAttributes as P, evaluateTemplateValue as R, evaluateTemplateValueCollection as V, isTemplateValue as h, useEvaluatedAttributes as L } from "./TemplateSystem.js";
11
- import { alterData as z } from "./utility/alterData.js";
12
- import { analyzeDataOverrideReferences as J } from "./utility/analyzeDataOverrideReferences.js";
13
- import { applyDataMapping as G } from "./utility/dataMappingSystem.js";
14
- import { replaceEventPlaceholders as j } from "./utility/eventPlaceholderSystem.js";
15
- import { formatString as M, maybeFormatString as N } from "./utility/formatString.js";
16
- import { propsDataLocationToPathAndValue as k } from "./utility/formElementsCommon.js";
17
- import { parseRjBuild as H } from "./utility/parseRjBuild.js";
18
- import { normalizeAttributeNameForReactJsx as K, normalizeAttributesForReactJsx as Q } from "./utility/reactJsxHelpers.js";
19
- import { stringToBoolean as W } from "./utility/stringToBoolean.js";
20
- import { View as Y } from "./View.js";
3
+ import { DataStore as n } from "./DataStore.js";
4
+ import { EventDispatcherContext as l } from "./EventDispatcherContext.js";
5
+ import { EventDispatcherProvider as f, addEventListener as s, removeEventListener as u } from "./EventDispatcherProvider.js";
6
+ import { GlobalDataContext as c } from "./GlobalDataContext.js";
7
+ import { GlobalDataContextProvider as D } from "./GlobalDataContextProvider.js";
8
+ import { PaginationContext as b } from "./PaginationContext.js";
9
+ import { ReactiveJsonRoot as R } from "./ReactiveJsonRoot.js";
10
+ import { StoreContext as g, StoreProvider as A, useStore as E } from "./StoreContext.js";
11
+ import { TemplateContext as V } from "./TemplateContext.js";
12
+ import { dataLocationToPath as L, evaluateAttributes as y, evaluateTemplateValue as z, evaluateTemplateValueCollection as F, isTemplateValue as J, useEvaluatedAttributes as B } from "./TemplateSystem.js";
13
+ import { useReactiveData as j } from "./hook/useReactiveData.js";
14
+ import { alterData as M } from "./utility/alterData.js";
15
+ import { analyzeDataOverrideReferences as O } from "./utility/analyzeDataOverrideReferences.js";
16
+ import { applyDataMapping as q } from "./utility/dataMappingSystem.js";
17
+ import { replaceEventPlaceholders as I } from "./utility/eventPlaceholderSystem.js";
18
+ import { formatString as Q, maybeFormatString as U } from "./utility/formatString.js";
19
+ import { propsDataLocationToPathAndValue as X } from "./utility/formElementsCommon.js";
20
+ import { parseRjBuild as Z } from "./utility/parseRjBuild.js";
21
+ import { normalizeAttributeNameForReactJsx as $, normalizeAttributesForReactJsx as ee } from "./utility/reactJsxHelpers.js";
22
+ import { stringToBoolean as oe } from "./utility/stringToBoolean.js";
23
+ import { View as ae } from "./View.js";
21
24
  export {
22
25
  o as ActionDependant,
23
- m as EventDispatcherContext,
24
- i as EventDispatcherProvider,
25
- u as GlobalDataContext,
26
- c as GlobalDataContextProvider,
27
- D as PaginationContext,
28
- b as ReactiveJsonRoot,
29
- g as TemplateContext,
30
- Y as View,
31
- x as addEventListener,
32
- z as alterData,
33
- J as analyzeDataOverrideReferences,
34
- G as applyDataMapping,
35
- E as dataLocationToPath,
36
- P as evaluateAttributes,
37
- R as evaluateTemplateValue,
38
- V as evaluateTemplateValueCollection,
39
- M as formatString,
40
- h as isTemplateValue,
26
+ n as DataStore,
27
+ l as EventDispatcherContext,
28
+ f as EventDispatcherProvider,
29
+ c as GlobalDataContext,
30
+ D as GlobalDataContextProvider,
31
+ b as PaginationContext,
32
+ R as ReactiveJsonRoot,
33
+ g as StoreContext,
34
+ A as StoreProvider,
35
+ V as TemplateContext,
36
+ ae as View,
37
+ s as addEventListener,
38
+ M as alterData,
39
+ O as analyzeDataOverrideReferences,
40
+ q as applyDataMapping,
41
+ L as dataLocationToPath,
42
+ y as evaluateAttributes,
43
+ z as evaluateTemplateValue,
44
+ F as evaluateTemplateValueCollection,
45
+ Q as formatString,
46
+ J as isTemplateValue,
41
47
  r as isValid,
42
- N as maybeFormatString,
48
+ U as maybeFormatString,
43
49
  p as mergeComponentCollections,
44
- K as normalizeAttributeNameForReactJsx,
45
- Q as normalizeAttributesForReactJsx,
46
- H as parseRjBuild,
47
- k as propsDataLocationToPathAndValue,
48
- f as removeEventListener,
49
- j as replaceEventPlaceholders,
50
- W as stringToBoolean,
51
- L as useEvaluatedAttributes
50
+ $ as normalizeAttributeNameForReactJsx,
51
+ ee as normalizeAttributesForReactJsx,
52
+ Z as parseRjBuild,
53
+ X as propsDataLocationToPathAndValue,
54
+ u as removeEventListener,
55
+ I as replaceEventPlaceholders,
56
+ oe as stringToBoolean,
57
+ B as useEvaluatedAttributes,
58
+ j as useReactiveData,
59
+ E as useStore
52
60
  };
@@ -1,34 +1,47 @@
1
- import { evaluateTemplateValue as P, dataLocationToPath as m } from "../TemplateSystem.js";
2
- const u = ({
1
+ import { evaluateTemplateValue as P, dataLocationToPath as s } from "../TemplateSystem.js";
2
+ const i = ({
3
3
  currentPath: v,
4
- datafield: D,
5
- dataLocation: o,
6
- defaultValue: h,
7
- globalDataContext: f,
4
+ datafield: r,
5
+ dataLocation: h,
6
+ defaultValue: o,
7
+ globalDataContext: m,
8
8
  templateContext: a
9
9
  }) => {
10
- const r = {
10
+ const D = {
11
11
  // This is the data that contains the current checked state.
12
12
  formData: void 0,
13
13
  // This is the path that leads to the data.
14
14
  formDataPath: void 0
15
15
  };
16
- return o && typeof o == "string" ? (r.formData = P({
17
- globalDataContext: f,
18
- templateContext: a,
19
- valueToEvaluate: o
20
- }) ?? h, r.formDataPath = m({
21
- dataLocation: o,
22
- currentPath: v,
23
- globalDataContext: f,
24
- templateContext: a
25
- })) : ((a.templateData[D] ?? void 0) === void 0 && (a.templateData = typeof a.templateData == "object" ? a.templateData : {}, a.templateData[D] = h), r.formData = a.templateData[D], r.formDataPath = m({
26
- dataLocation: "~." + D,
27
- currentPath: a.templatePath,
28
- globalDataContext: f,
29
- templateContext: a
30
- })), r;
16
+ if (h && typeof h == "string")
17
+ D.formData = P({
18
+ globalDataContext: m,
19
+ templateContext: a,
20
+ valueToEvaluate: h
21
+ }) ?? o, D.formDataPath = s({
22
+ dataLocation: h,
23
+ currentPath: v,
24
+ globalDataContext: m,
25
+ templateContext: a
26
+ });
27
+ else {
28
+ if ((a.templateData[r] ?? void 0) === void 0)
29
+ if (typeof a.templateData == "object" && a.templateData !== null)
30
+ a.templateData[r] = o;
31
+ else
32
+ try {
33
+ a.templateData = {}, a.templateData[r] = o;
34
+ } catch {
35
+ }
36
+ D.formData = a.templateData[r], D.formDataPath = s({
37
+ dataLocation: "~." + r,
38
+ currentPath: a.templatePath,
39
+ globalDataContext: m,
40
+ templateContext: a
41
+ });
42
+ }
43
+ return D;
31
44
  };
32
45
  export {
33
- u as propsDataLocationToPathAndValue
46
+ i as propsDataLocationToPathAndValue
34
47
  };
@@ -1,4 +1,4 @@
1
- import { l as n } from "../../js-yaml-Bw0KO4XO.js";
1
+ import { l as n } from "../../js-yaml-CFDLc3Ha.js";
2
2
  const c = (t) => {
3
3
  try {
4
4
  return { success: !0, format: "json", data: JSON.parse(t) };