@ea-lab/reactive-json 2.0.1 → 2.2.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.
@@ -1,100 +1,109 @@
1
- import { jsx as _ } from "react/jsx-runtime";
2
- import { useContext as x, useRef as m, useCallback as q, useEffect as T } from "react";
3
- import { ActionDependant as A } from "../../../engine/Actions.js";
4
- import { GlobalDataContext as $ } from "../../../engine/GlobalDataContext.js";
5
- import { useStore as B } from "../../../engine/StoreContext.js";
6
- import { TemplateContext as G } from "../../../engine/TemplateContext.js";
7
- import { dataLocationToPath as v } from "../../../engine/TemplateSystem.js";
8
- import { a as M } from "../../../index-BUPRVmV-.js";
9
- import { l as C } from "../../../lodash-CYNxjS-I.js";
10
- const E = (t) => t === "data" ? "" : t && t.startsWith("data.") ? t.substring(5) : t, Q = ({ props: t }) => {
11
- const S = x($), y = x(G), e = B(), p = m(void 0), d = m(null), a = m(null), u = m(null), g = m(!1), c = m(0), b = t.mode || "onIdle", R = t.idleDelay || 1e3, D = t.maxRetries ?? 0, I = t.retryDelay ?? 5e3;
12
- let o = null;
1
+ import { jsx as L } from "react/jsx-runtime";
2
+ import { useContext as P, useRef as l, useCallback as H, useEffect as k } from "react";
3
+ import { ActionDependant as M } from "../../../engine/Actions.js";
4
+ import { GlobalDataContext as N } from "../../../engine/GlobalDataContext.js";
5
+ import { useStore as U } from "../../../engine/StoreContext.js";
6
+ import { TemplateContext as W } from "../../../engine/TemplateContext.js";
7
+ import { dataLocationToPath as w } from "../../../engine/TemplateSystem.js";
8
+ import { a as j } from "../../../index-BUPRVmV-.js";
9
+ import { l as _ } from "../../../lodash-CYNxjS-I.js";
10
+ const q = (t) => t === "data" ? "" : t && t.startsWith("data.") ? t.substring(5) : t, tt = ({ props: t }) => {
11
+ const x = P(N), h = P(W), e = U(), D = l(void 0), g = l(null), u = l(null), f = l(null), v = l(!1), c = l(0), b = l(null), S = t.mode || "onIdle", R = t.idleDelay || 1e3, C = t.maxRetries ?? 0, A = t.retryDelay ?? 5e3;
12
+ let n = null;
13
13
  try {
14
- o = E(v({
14
+ n = q(w({
15
15
  dataLocation: t.path,
16
- currentPath: y.templatePath,
17
- globalDataContext: S,
18
- templateContext: y
16
+ currentPath: h.templatePath,
17
+ globalDataContext: x,
18
+ templateContext: h
19
19
  }));
20
20
  } catch (r) {
21
21
  console.error("DataSync: Invalid path", t.path, r);
22
22
  }
23
- let i = null;
23
+ let m = null;
24
24
  if (t.trigger)
25
25
  try {
26
- i = E(v({
26
+ m = q(w({
27
27
  dataLocation: t.trigger,
28
- currentPath: y.templatePath,
29
- globalDataContext: S,
30
- templateContext: y
28
+ currentPath: h.templatePath,
29
+ globalDataContext: x,
30
+ templateContext: h
31
31
  }));
32
32
  } catch (r) {
33
33
  console.error("DataSync: Invalid trigger path", t.trigger, r);
34
34
  }
35
- const l = q(async (r) => {
36
- var f;
35
+ const d = H(async (r) => {
36
+ var y, a, i, E, T, I;
37
37
  if (!r || !r.submission_url) {
38
38
  r && console.warn("DataSync: Missing submission_url in data object", r);
39
39
  return;
40
40
  }
41
- if (!g.current && !(c.current > D)) {
42
- g.current = !0, c.current++, p.current = r.data, e.set(`${o}.status`, {
41
+ if (!v.current && !(c.current > C)) {
42
+ v.current = !0, c.current++, D.current = r.data, e.set(`${n}.status`, {
43
43
  type: "info",
44
44
  // TODO: translate this.
45
45
  message: "Synchronisation en cours..."
46
46
  });
47
47
  try {
48
- const { submission_url: n } = r, h = (await M.post(n, r)).data;
49
- d.current = h, c.current = 0, e.set(o, h);
50
- } catch (n) {
51
- console.error("DataSync error:", n);
52
- const s = (f = n.response) == null ? void 0 : f.data;
53
- if (s && typeof s == "object" && s.status) {
54
- d.current = s, c.current = 0, e.set(o, s), g.current = !1;
48
+ const { submission_url: s } = r, o = await j.post(s, r), p = o.data;
49
+ g.current = p, c.current = 0, e.set(n, p), (y = b.current) == null || y.dispatchEvent(new CustomEvent("syncSuccess", {
50
+ bubbles: !0,
51
+ detail: { value: p, responseContext: { status: o.status } }
52
+ }));
53
+ } catch (s) {
54
+ console.error("DataSync error:", s);
55
+ const o = (a = s.response) == null ? void 0 : a.data;
56
+ if (o && typeof o == "object" && o.status) {
57
+ g.current = o, c.current = 0, e.set(n, o), (E = b.current) == null || E.dispatchEvent(new CustomEvent("syncError", {
58
+ bubbles: !0,
59
+ detail: { value: o, responseContext: { status: (i = s.response) == null ? void 0 : i.status } }
60
+ })), v.current = !1;
55
61
  return;
56
62
  }
57
- const h = {
63
+ const p = {
58
64
  type: "error",
59
- message: n.message || "Unknown error"
65
+ message: s.message || "Unknown error"
60
66
  };
61
- e.set(`${o}.status`, h);
62
- const L = n.response && n.response.status >= 500, P = !n.response && typeof navigator < "u" && !navigator.onLine;
63
- (L || P) && c.current <= D && (u.current = setTimeout(() => {
64
- const k = e.get(o);
65
- l(k);
66
- }, I));
67
+ e.set(`${n}.status`, p), (I = b.current) == null || I.dispatchEvent(new CustomEvent("syncError", {
68
+ bubbles: !0,
69
+ detail: { value: o, responseContext: { status: (T = s.response) == null ? void 0 : T.status } }
70
+ }));
71
+ const $ = s.response && s.response.status >= 500, B = !s.response && typeof navigator < "u" && !navigator.onLine;
72
+ ($ || B) && c.current <= C && (f.current = setTimeout(() => {
73
+ const G = e.get(n);
74
+ d(G);
75
+ }, A));
67
76
  } finally {
68
- g.current = !1;
77
+ v.current = !1;
69
78
  }
70
79
  }
71
- }, [e, o, D]);
72
- return T(() => {
73
- if (!e || o === null) return;
80
+ }, [e, n, C]);
81
+ return k(() => {
82
+ if (!e || n === null) return;
74
83
  const r = () => {
75
- const n = e.get(o);
76
- if (!n || n === d.current)
84
+ const a = e.get(n);
85
+ if (!a || a === g.current)
77
86
  return;
78
- const s = n.data;
79
- p.current !== void 0 && C.isEqual(s, p.current) || d.current && C.isEqual(s, d.current.data) || (c.current = 0, u.current && (clearTimeout(u.current), u.current = null), b === "immediate" ? l(n) : b === "onIdle" && (a.current && clearTimeout(a.current), a.current = setTimeout(() => {
80
- l(n);
87
+ const i = a.data;
88
+ D.current !== void 0 && _.isEqual(i, D.current) || g.current && _.isEqual(i, g.current.data) || (c.current = 0, f.current && (clearTimeout(f.current), f.current = null), S === "immediate" ? d(a) : S === "onIdle" && (u.current && clearTimeout(u.current), u.current = setTimeout(() => {
89
+ d(a);
81
90
  }, R)));
82
- }, f = e.subscribe(o, r);
91
+ }, y = e.subscribe(n, r);
83
92
  return () => {
84
- f(), a.current && clearTimeout(a.current), u.current && clearTimeout(u.current);
93
+ y(), u.current && clearTimeout(u.current), f.current && clearTimeout(f.current);
85
94
  };
86
- }, [e, o, b, R, l]), T(() => {
87
- if (!e || i === null) return;
95
+ }, [e, n, S, R, d]), k(() => {
96
+ if (!e || m === null) return;
88
97
  const r = () => {
89
- if (e.get(i) === !0) {
90
- e.set(i, !1), a.current && (clearTimeout(a.current), a.current = null), c.current = 0;
91
- const s = e.get(o);
92
- l(s);
98
+ if (e.get(m) === !0) {
99
+ e.set(m, !1), u.current && (clearTimeout(u.current), u.current = null), c.current = 0;
100
+ const i = e.get(n);
101
+ d(i);
93
102
  }
94
- }, f = e.subscribe(i, r);
95
- return () => f();
96
- }, [e, i, o, l]), /* @__PURE__ */ _(A, { ...t });
103
+ }, y = e.subscribe(m, r);
104
+ return () => y();
105
+ }, [e, m, n, d]), /* @__PURE__ */ L(M, { ...t, attributesHolderRef: b, children: /* @__PURE__ */ L("span", { ref: b, style: { display: "none" } }) });
97
106
  };
98
107
  export {
99
- Q as DataSync
108
+ tt as DataSync
100
109
  };
@@ -1,10 +1,10 @@
1
1
  import { jsx as p, jsxs as H, Fragment as st } from "react/jsx-runtime";
2
- import { a as J } from "../index-BUPRVmV-.js";
3
- import { useRef as K, useState as Q, useEffect as V, useMemo as it } from "react";
2
+ import { a as G } from "../index-BUPRVmV-.js";
3
+ import { useRef as K, useState as Q, useEffect as N, useMemo as it } from "react";
4
4
  import { r as ct } from "../dnd-kit-sortable-tree.esm-Cz1RJyIg.js";
5
5
  import { coreComponentsPlugin as X } from "../coreComponentsPlugin.js";
6
- import { mergeComponentCollections as pt } from "./ComponentCollector.js";
7
- import { DataStore as lt } from "./DataStore.js";
6
+ import { mergeComponentCollections as lt } from "./ComponentCollector.js";
7
+ import { DataStore as pt } from "./DataStore.js";
8
8
  import { EventDispatcherProvider as dt } from "./EventDispatcherProvider.js";
9
9
  import { GlobalDataContext as ut } from "./GlobalDataContext.js";
10
10
  import mt from "./ParsingDebugDisplay/ParsingDebugDisplay.js";
@@ -15,75 +15,76 @@ import { useReactiveData as Pt } from "./hook/useReactiveData.js";
15
15
  import { alterData as yt } from "./utility/alterData.js";
16
16
  import { applyDataMapping as Dt } from "./utility/dataMappingSystem.js";
17
17
  import { parseRjBuild as wt } from "./utility/parseRjBuild.js";
18
- import { stringToBoolean as bt } from "./utility/stringToBoolean.js";
19
- import { View as Ct } from "./View.js";
20
- const St = ({ Wrapper: m }) => {
18
+ import { interpolateSegments as bt } from "./utility/interpolateSegments.js";
19
+ import { stringToBoolean as Ct } from "./utility/stringToBoolean.js";
20
+ import { View as St } from "./View.js";
21
+ const vt = ({ Wrapper: m }) => {
21
22
  const E = Pt("");
22
23
  return /* @__PURE__ */ p(m, { children: JSON.stringify(E, null, " ") });
23
24
  }, xt = ({
24
25
  dataOverride: m,
25
26
  dataFetchMethod: E,
26
- dataUrl: G,
27
+ dataUrl: L,
27
28
  debugMode: Y,
28
- DebugModeContentWrapper: L,
29
- DebugModeDataWrapper: O,
29
+ DebugModeContentWrapper: O,
30
+ DebugModeDataWrapper: z,
30
31
  DebugModeRootWrapper: Z,
31
- headersForData: z,
32
+ headersForData: I,
32
33
  headersForRjBuild: s,
33
- maybeRawAppData: I,
34
+ maybeRawAppData: M,
34
35
  maybeRawAppRjBuild: w,
35
- plugins: N,
36
+ plugins: R,
36
37
  rjBuildFetchMethod: b,
37
38
  rjBuildUrl: f,
38
- upstreamUpdateCallbacks: R
39
+ upstreamUpdateCallbacks: T
39
40
  }) => {
40
41
  const g = [];
41
42
  E && (g.push({
42
43
  deprecatedProperty: "dataFetchMethod",
43
44
  newProperty: "rjBuildFetchMethod"
44
- }), b = E), G && (g.push({
45
+ }), b = E), L && (g.push({
45
46
  deprecatedProperty: "dataUrl",
46
47
  newProperty: "rjBuildUrl"
47
- }), f = G), z && (g.push({
48
+ }), f = L), I && (g.push({
48
49
  deprecatedProperty: "headersForData",
49
50
  newProperty: "headersForRjBuild"
50
- }), s = z), I && (g.push({
51
+ }), s = I), M && (g.push({
51
52
  deprecatedProperty: "maybeRawAppData",
52
53
  newProperty: "maybeRawAppRjBuild"
53
- }), w = I), g.length > 0 && console.warn(
54
+ }), w = M), g.length > 0 && console.warn(
54
55
  "A ReactiveJsonRoot component got the following deprecated properties that must be replaced: " + g.map((t) => t.deprecatedProperty + " -> " + t.newProperty).join(", ")
55
56
  );
56
- const a = K(new lt({})).current, [d, C] = Q({
57
+ const o = K(new pt({})).current, [u, C] = Q({
57
58
  templates: {},
58
59
  renderView: {},
59
60
  items: [],
60
61
  rawAppRjBuild: null
61
- }), [T, M] = Q(null), o = K(null);
62
- V(() => () => {
63
- typeof document < "u" && o.current && o.current.parentNode && (o.current.parentNode.removeChild(o.current), o.current = null);
62
+ }), [j, W] = Q(null), a = K(null);
63
+ N(() => () => {
64
+ typeof document < "u" && a.current && a.current.parentNode && (a.current.parentNode.removeChild(a.current), a.current = null);
64
65
  }, []);
65
66
  const S = it(
66
- () => N ? pt([X, N]) : X,
67
- [N]
67
+ () => R ? lt([X, R]) : X,
68
+ [R]
68
69
  );
69
- V(() => {
70
+ N(() => {
70
71
  let t = w;
71
72
  typeof t == "string" || t && (t = JSON.stringify(t)), t && C((r) => ({ ...r, rawAppRjBuild: t }));
72
- }, [w]), V(() => {
73
+ }, [w]), N(() => {
73
74
  if (!f) return;
74
75
  const t = {
75
76
  method: b || "GET",
76
77
  url: f,
77
78
  headers: s
78
79
  };
79
- t.method.toLowerCase() === "post" ? J.post(t.url, {}, { headers: t.headers }).then((r) => {
80
+ t.method.toLowerCase() === "post" ? G.post(t.url, {}, { headers: t.headers }).then((r) => {
80
81
  C((i) => ({ ...i, rawAppRjBuild: r.data }));
81
- }) : J.get(t.url, { headers: t.headers }).then((r) => {
82
+ }) : G.get(t.url, { headers: t.headers }).then((r) => {
82
83
  C((i) => ({ ...i, rawAppRjBuild: r.data }));
83
84
  });
84
- }, [f, s, b]), V(() => {
85
- if (!d.rawAppRjBuild) return;
86
- const t = wt(d.rawAppRjBuild);
85
+ }, [f, s, b]), N(() => {
86
+ if (!u.rawAppRjBuild) return;
87
+ const t = wt(u.rawAppRjBuild);
87
88
  if (!t.success) {
88
89
  if (console.group(
89
90
  `Tried to load the app's RjBuild but the ${t.format} content could not be parsed.`
@@ -95,11 +96,11 @@ const St = ({ Wrapper: m }) => {
95
96
  dataOverride: m
96
97
  }), console.debug("Error details:", t.error), console.groupEnd(), typeof document < "u") {
97
98
  let e = document.getElementById("rj-parsing-error-root");
98
- if (e || (e = document.createElement("div"), e.id = "rj-parsing-error-root", document.body.appendChild(e)), !o.current) {
99
- const l = document.createElement("div");
100
- e.appendChild(l), o.current = l;
99
+ if (e || (e = document.createElement("div"), e.id = "rj-parsing-error-root", document.body.appendChild(e)), !a.current) {
100
+ const d = document.createElement("div");
101
+ e.appendChild(d), a.current = d;
101
102
  }
102
- M(
103
+ W(
103
104
  ct.createPortal(
104
105
  /* @__PURE__ */ p(
105
106
  mt,
@@ -113,73 +114,74 @@ const St = ({ Wrapper: m }) => {
113
114
  }
114
115
  }
115
116
  ),
116
- o.current,
117
+ a.current,
117
118
  () => {
118
- o.current && (o.current.parentNode.removeChild(o.current), o.current = null);
119
+ a.current && (a.current.parentNode.removeChild(a.current), a.current = null);
119
120
  }
120
121
  )
121
122
  );
122
123
  }
123
124
  return;
124
125
  }
125
- T && (M(null), typeof document < "u" && o.current && o.current.parentNode && (o.current.parentNode.removeChild(o.current), o.current = null));
126
+ j && (W(null), typeof document < "u" && a.current && a.current.parentNode && (a.current.parentNode.removeChild(a.current), a.current = null));
126
127
  const r = t.data, i = m !== void 0 ? m : r.data;
127
- a.set("", i);
128
+ o.set("", i);
128
129
  const n = {
129
130
  templates: r.templates ?? r.listForms ?? {},
130
131
  renderView: r.renderView ?? {},
131
132
  items: Object.keys(r.renderView ?? {}),
132
- rawAppRjBuild: d.rawAppRjBuild
133
+ rawAppRjBuild: u.rawAppRjBuild
133
134
  }, h = r.additionalDataSource;
134
135
  if (!Array.isArray(h) || h.length === 0) {
135
136
  C((e) => ({ ...e, ...n }));
136
137
  return;
137
138
  }
138
- const x = h.filter((e) => e.blocking === !0), A = h.filter((e) => e.blocking !== !0), B = (e) => !e || e === "data" ? "" : e.startsWith("data.") ? e.substring(5) : e, _ = async (e, l) => {
139
+ const v = h.filter((e) => e.blocking === !0), A = h.filter((e) => e.blocking !== !0), _ = (e) => !e || e === "data" ? "" : e.startsWith("data.") ? e.substring(5) : e, $ = async (e, d) => {
139
140
  var P;
140
141
  try {
141
- if (!e.src) {
142
- console.warn("additionalDataSource item number " + l + " missing 'src' property.", e);
142
+ const k = bt(e.src, (c) => o.get(c));
143
+ if (!k) {
144
+ console.warn("additionalDataSource item number " + d + ": could not resolve 'src'.", e);
143
145
  return;
144
146
  }
145
147
  const y = {
146
148
  method: ((P = e.method) == null ? void 0 : P.toUpperCase()) || "GET",
147
- url: e.src
149
+ url: k
148
150
  };
149
151
  s && Object.keys(s).length > 0 && (y.headers = s);
150
- const k = await J(y), rt = {
152
+ const V = await G(y), rt = {
151
153
  url: y.url,
152
154
  method: y.method,
153
155
  headers: y.headers || {},
154
156
  body: y.data
155
157
  }, ot = {
156
- headers: k.headers || {},
157
- status: k.status,
158
- data: k.data
158
+ headers: V.headers || {},
159
+ status: V.status,
160
+ data: V.data
159
161
  }, D = yt({
160
162
  requestContext: rt,
161
163
  responseContext: ot,
162
- responseBody: k.data,
164
+ responseBody: V.data,
163
165
  // additionalDataSource always processes raw data, not RjBuild.
164
166
  isRjBuild: !1,
165
167
  dataProcessors: (S == null ? void 0 : S.dataProcessor) || {}
166
168
  });
167
169
  if (e.dataMapping) {
168
- const u = {
170
+ const c = {
169
171
  headersForRjBuild: s,
170
172
  plugins: S,
171
173
  get templateData() {
172
- return a.get("");
174
+ return o.get("");
173
175
  },
174
176
  templatePath: "data",
175
- setData: (c) => a.set("", c),
176
- updateData: (c, j, at) => {
177
- const nt = B(j);
178
- a.set(nt, c, at);
177
+ setData: (l) => o.set("", l),
178
+ updateData: (l, J, at) => {
179
+ const nt = _(J);
180
+ o.set(nt, l, at);
179
181
  }
180
- }, v = {
182
+ }, x = {
181
183
  get templateData() {
182
- return a.get("");
184
+ return o.get("");
183
185
  },
184
186
  templatePath: "data"
185
187
  };
@@ -187,12 +189,12 @@ const St = ({ Wrapper: m }) => {
187
189
  Dt({
188
190
  dataMapping: e.dataMapping,
189
191
  responseData: D,
190
- globalDataContext: u,
191
- templateContext: v
192
+ globalDataContext: c,
193
+ templateContext: x
192
194
  });
193
195
  return;
194
- } catch (c) {
195
- console.error("Error applying dataMapping for additionalDataSource:", c);
196
+ } catch (l) {
197
+ console.error("Error applying dataMapping for additionalDataSource:", l);
196
198
  }
197
199
  }
198
200
  if (!e.path) {
@@ -203,65 +205,65 @@ const St = ({ Wrapper: m }) => {
203
205
  );
204
206
  return;
205
207
  }
206
- Object.entries(D).forEach(([u, v]) => {
207
- a.set(u, v);
208
+ Object.entries(D).forEach(([c, x]) => {
209
+ o.set(c, x);
208
210
  });
209
211
  return;
210
212
  }
211
213
  try {
212
- const u = {
213
- templateData: a.get(""),
214
+ const c = {
215
+ templateData: o.get(""),
214
216
  // use current snapshot
215
217
  templatePath: "data"
216
- }, v = {
217
- templateData: a.get(""),
218
+ }, x = {
219
+ templateData: o.get(""),
218
220
  // use current snapshot
219
221
  templatePath: "data"
220
- }, c = ht({
222
+ }, l = ht({
221
223
  dataLocation: e.path,
222
224
  currentPath: "data",
223
- globalDataContext: u,
224
- templateContext: v
225
+ globalDataContext: c,
226
+ templateContext: x
225
227
  });
226
- if (typeof c != "string") {
228
+ if (typeof l != "string") {
227
229
  console.warn(
228
230
  "additionalDataSource path evaluation did not result in a string:",
229
231
  e.path,
230
232
  "->",
231
- c
233
+ l
232
234
  );
233
235
  return;
234
236
  }
235
- const j = B(c);
236
- a.set(j, D);
237
- } catch (u) {
238
- console.error("Error evaluating additionalDataSource path:", e.path, u);
237
+ const J = _(l);
238
+ o.set(J, D);
239
+ } catch (c) {
240
+ console.error("Error evaluating additionalDataSource path:", e.path, c);
239
241
  }
240
- } catch ($) {
241
- console.error("Error fetching additional data source:", e.src, $);
242
+ } catch (k) {
243
+ console.error("Error fetching additional data source:", e.src, k);
242
244
  }
243
245
  };
244
246
  (async () => {
245
- if (x.length > 0) {
246
- const e = x.map((l, P) => _(l, P));
247
+ if (v.length > 0) {
248
+ const e = v.map((d, P) => $(d, P));
247
249
  await Promise.allSettled(e);
248
250
  }
249
251
  if (C((e) => ({ ...e, ...n })), A.length > 0) {
250
252
  const e = A.map(
251
- (l, P) => _(l, x.length + P)
253
+ (d, P) => $(d, v.length + P)
252
254
  );
253
255
  Promise.allSettled(e);
254
256
  }
255
257
  })();
256
- }, [d.rawAppRjBuild, m, a]);
257
- function W(t, r, i) {
258
- if (!R || R.size === 0)
258
+ }, [u.rawAppRjBuild, m, o]);
259
+ function q(t, r, i) {
260
+ if (!T || T.size === 0)
259
261
  return !1;
260
- for (const [n, h] of R)
262
+ for (const [n, h] of T)
261
263
  if (t === n || t.startsWith(n + ".") || n === "") {
262
- const x = n === "" ? t : t.substring(n.length + 1);
264
+ const v = n === "" ? t : t.substring(n.length + 1);
263
265
  try {
264
- return h(r, x, i), !0;
266
+ return h(r, v, i), !0;
265
267
  } catch (A) {
266
268
  console.warn("Error during upstream update:", A);
267
269
  break;
@@ -270,46 +272,46 @@ const St = ({ Wrapper: m }) => {
270
272
  return !1;
271
273
  }
272
274
  const U = (t) => {
273
- W("", t, void 0) || a.set("", t);
275
+ q("", t, void 0) || o.set("", t);
274
276
  }, F = (t, r, i) => {
275
277
  const n = r.startsWith("data.") ? r.substring(5) : r === "data" ? "" : r;
276
- W(n, t, i) || a.set(n, t, i);
278
+ q(n, t, i) || o.set(n, t, i);
277
279
  }, tt = {
278
- element: d.templates,
280
+ element: u.templates,
279
281
  headersForRjBuild: s,
280
282
  plugins: S,
281
283
  ReactiveJsonRoot: xt,
282
284
  setData: U,
283
285
  updateData: F,
284
286
  // experimental: expose store for advanced usage
285
- store: a,
287
+ store: o,
286
288
  // fallback: get data from store directly (non-reactive access)
287
289
  get templateData() {
288
- return a.get("");
290
+ return o.get("");
289
291
  },
290
292
  templatePath: "data"
291
- }, q = d.items.map((t) => /* @__PURE__ */ p(
292
- Ct,
293
+ }, B = u.items.map((t) => /* @__PURE__ */ p(
294
+ St,
293
295
  {
294
296
  datafield: t,
295
297
  path: "data." + t,
296
- props: d.renderView[t]
298
+ props: u.renderView[t]
297
299
  },
298
300
  t
299
- )), et = bt(Y);
300
- return /* @__PURE__ */ p(ft.Provider, { value: a, children: /* @__PURE__ */ p(dt, { children: /* @__PURE__ */ p(ut.Provider, { value: tt, children: /* @__PURE__ */ p(gt.Provider, { value: {
301
+ )), et = Ct(Y);
302
+ return /* @__PURE__ */ p(ft.Provider, { value: o, children: /* @__PURE__ */ p(dt, { children: /* @__PURE__ */ p(ut.Provider, { value: tt, children: /* @__PURE__ */ p(gt.Provider, { value: {
301
303
  // Same here, getter for compatibility, but won't trigger updates
302
304
  get templateData() {
303
- return a.get("");
305
+ return o.get("");
304
306
  },
305
307
  templatePath: "data"
306
- }, children: et && L ? /* @__PURE__ */ H(Z, { children: [
307
- /* @__PURE__ */ p(L, { children: q }),
308
- O && /* @__PURE__ */ p(St, { Wrapper: O }),
309
- T
308
+ }, children: et && O ? /* @__PURE__ */ H(Z, { children: [
309
+ /* @__PURE__ */ p(O, { children: B }),
310
+ z && /* @__PURE__ */ p(vt, { Wrapper: z }),
311
+ j
310
312
  ] }) : /* @__PURE__ */ H(st, { children: [
311
- q,
312
- T
313
+ B,
314
+ j
313
315
  ] }) }) }) }) });
314
316
  };
315
317
  export {
@@ -6,8 +6,8 @@ import { EventDispatcherProvider as f, addEventListener as s, removeEventListene
6
6
  import { GlobalDataContext as c } from "./GlobalDataContext.js";
7
7
  import { GlobalDataContextProvider as D } from "./GlobalDataContextProvider.js";
8
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";
9
+ import { ReactiveJsonRoot as P } from "./ReactiveJsonRoot.js";
10
+ import { StoreContext as S, StoreProvider as T, useStore as A } from "./StoreContext.js";
11
11
  import { TemplateContext as V } from "./TemplateContext.js";
12
12
  import { dataLocationToPath as L, evaluateAttributes as y, evaluateTemplateValue as z, evaluateTemplateValueCollection as F, isTemplateValue as J, useEvaluatedAttributes as B } from "./TemplateSystem.js";
13
13
  import { useReactiveData as j } from "./hook/useReactiveData.js";
@@ -19,8 +19,9 @@ import { formatString as Q, maybeFormatString as U } from "./utility/formatStrin
19
19
  import { propsDataLocationToPathAndValue as X } from "./utility/formElementsCommon.js";
20
20
  import { parseRjBuild as Z } from "./utility/parseRjBuild.js";
21
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";
22
+ import { interpolateSegments as oe } from "./utility/interpolateSegments.js";
23
+ import { stringToBoolean as ae } from "./utility/stringToBoolean.js";
24
+ import { View as me } from "./View.js";
24
25
  export {
25
26
  o as ActionDependant,
26
27
  n as DataStore,
@@ -29,11 +30,11 @@ export {
29
30
  c as GlobalDataContext,
30
31
  D as GlobalDataContextProvider,
31
32
  b as PaginationContext,
32
- R as ReactiveJsonRoot,
33
- g as StoreContext,
34
- A as StoreProvider,
33
+ P as ReactiveJsonRoot,
34
+ S as StoreContext,
35
+ T as StoreProvider,
35
36
  V as TemplateContext,
36
- ae as View,
37
+ me as View,
37
38
  s as addEventListener,
38
39
  M as alterData,
39
40
  O as analyzeDataOverrideReferences,
@@ -43,6 +44,7 @@ export {
43
44
  z as evaluateTemplateValue,
44
45
  F as evaluateTemplateValueCollection,
45
46
  Q as formatString,
47
+ oe as interpolateSegments,
46
48
  J as isTemplateValue,
47
49
  r as isValid,
48
50
  U as maybeFormatString,
@@ -53,8 +55,8 @@ export {
53
55
  X as propsDataLocationToPathAndValue,
54
56
  u as removeEventListener,
55
57
  I as replaceEventPlaceholders,
56
- oe as stringToBoolean,
58
+ ae as stringToBoolean,
57
59
  B as useEvaluatedAttributes,
58
60
  j as useReactiveData,
59
- E as useStore
61
+ A as useStore
60
62
  };
@@ -4,19 +4,21 @@ import { applyDataMapping as m } from "./dataMappingSystem.js";
4
4
  import { replaceEventPlaceholders as f } from "./eventPlaceholderSystem.js";
5
5
  import { formatString as l, maybeFormatString as x } from "./formatString.js";
6
6
  import { propsDataLocationToPathAndValue as c } from "./formElementsCommon.js";
7
- import { parseRjBuild as g } from "./parseRjBuild.js";
7
+ import { parseRjBuild as d } from "./parseRjBuild.js";
8
8
  import { normalizeAttributeNameForReactJsx as D, normalizeAttributesForReactJsx as R } from "./reactJsxHelpers.js";
9
- import { stringToBoolean as y } from "./stringToBoolean.js";
9
+ import { interpolateSegments as y } from "./interpolateSegments.js";
10
+ import { stringToBoolean as A } from "./stringToBoolean.js";
10
11
  export {
11
12
  o as alterData,
12
13
  a as analyzeDataOverrideReferences,
13
14
  m as applyDataMapping,
14
15
  l as formatString,
16
+ y as interpolateSegments,
15
17
  x as maybeFormatString,
16
18
  D as normalizeAttributeNameForReactJsx,
17
19
  R as normalizeAttributesForReactJsx,
18
- g as parseRjBuild,
20
+ d as parseRjBuild,
19
21
  c as propsDataLocationToPathAndValue,
20
22
  f as replaceEventPlaceholders,
21
- y as stringToBoolean
23
+ A as stringToBoolean
22
24
  };
@@ -0,0 +1,12 @@
1
+ const e = (r, i) => typeof r == "string" ? r || null : !Array.isArray(r) || r.length === 0 ? null : r.map((t) => {
2
+ if (typeof t == "string" && t.startsWith("~~.")) {
3
+ const o = t.substring(3), n = i(o);
4
+ return n == null ? (console.warn(
5
+ `interpolateSegments: reference "${t}" resolved to ${n}.`
6
+ ), "") : String(n);
7
+ }
8
+ return String(t ?? "");
9
+ }).join("");
10
+ export {
11
+ e as interpolateSegments
12
+ };
package/dist/main.js CHANGED
@@ -35,117 +35,118 @@ import { formatString as Se, maybeFormatString as he } from "./engine/utility/fo
35
35
  import { propsDataLocationToPathAndValue as Ee } from "./engine/utility/formElementsCommon.js";
36
36
  import { parseRjBuild as Ve } from "./engine/utility/parseRjBuild.js";
37
37
  import { normalizeAttributeNameForReactJsx as He, normalizeAttributesForReactJsx as Me } from "./engine/utility/reactJsxHelpers.js";
38
- import { stringToBoolean as Be } from "./engine/utility/stringToBoolean.js";
39
- import { View as ke } from "./engine/View.js";
40
- import { simpleMapping as Ne } from "./component/dataMapping/simpleMapping.js";
41
- import { VariablesDebug as Ue } from "./component/element/debug/VariablesDebug/VariablesDebug.js";
42
- import { Input as Ie } from "./component/element/form/Input.js";
43
- import { CheckBoxField as We } from "./component/element/form/CheckBoxField.js";
44
- import { ColorField as qe } from "./component/element/form/ColorField.js";
45
- import { DateField as Qe } from "./component/element/form/DateField.js";
46
- import { DateTimeField as Ye } from "./component/element/form/DateTimeField.js";
47
- import { EmailField as _e } from "./component/element/form/EmailField.js";
48
- import { FileField as eo } from "./component/element/form/FileField.js";
49
- import { HiddenField as ro } from "./component/element/form/HiddenField.js";
50
- import { MonthField as ao } from "./component/element/form/MonthField.js";
51
- import { NumberField as po } from "./component/element/form/NumberField.js";
52
- import { PasswordField as fo } from "./component/element/form/PasswordField.js";
53
- import { RangeField as lo } from "./component/element/form/RangeField.js";
54
- import { SearchField as so } from "./component/element/form/SearchField.js";
55
- import { SelectField as co } from "./component/element/form/SelectField.js";
56
- import { TelField as Do } from "./component/element/form/TelField.js";
57
- import { TextAreaField as Co } from "./component/element/form/TextAreaField.js";
58
- import { TextField as go } from "./component/element/form/TextField.js";
59
- import { TimeField as Ro } from "./component/element/form/TimeField.js";
60
- import { UrlField as ho } from "./component/element/form/UrlField.js";
61
- import { WeekField as Eo } from "./component/element/form/WeekField.js";
62
- import { FolderSortableTree as Vo } from "./component/element/html/FolderSortableTree.js";
63
- import { FormatNumeral as Ho } from "./component/element/html/FormatNumeral.js";
64
- import { Html as yo } from "./component/element/html/Html.js";
65
- import { LabelFromValue as Jo } from "./component/element/html/LabelFromValue.js";
66
- import { PreformattedMarkup as wo } from "./component/element/html/PreformattedMarkup.js";
67
- import { SortableTreeItemCollapseButton as zo } from "./component/element/html/SortableTreeItemCollapseButton.js";
68
- import { Count as Go } from "./component/element/special/Count.js";
69
- import { DataFilter as Oo } from "./component/element/special/DataFilter.js";
70
- import { DataSync as jo } from "./component/element/special/DataSync.js";
71
- import { DelayedActions as Ko, getReactionFunctionsToExecute as Qo } from "./component/element/special/DelayedActions.js";
72
- import { PageControls as Yo } from "./component/element/special/PageControls.js";
73
- import { Phantom as _o } from "./component/element/special/Phantom.js";
74
- import { ReactiveJsonBasicComponentWrapper as er } from "./component/element/special/ReactiveJsonBasicComponentWrapper.js";
75
- import { ReactiveJsonSubroot as rr } from "./component/element/special/ReactiveJsonSubroot.js";
76
- import { Switch as ar } from "./component/element/special/Switch.js";
77
- import { addData as pr } from "./component/reaction/addData.js";
78
- import { fetchData as fr } from "./component/reaction/fetchData.js";
79
- import { executeHttpRequest as lr } from "./component/reaction/utility/httpRequestCommon.js";
80
- import { moveData as sr } from "./component/reaction/moveData.js";
81
- import { postMessage as ur } from "./component/reaction/postMessage.js";
82
- import { redirectNow as Fr } from "./component/reaction/redirectNow.js";
83
- import { removeData as vr } from "./component/reaction/removeData.js";
84
- import { setClipboardData as br } from "./component/reaction/setClipboardData.js";
85
- import { setData as Tr } from "./component/reaction/setData.js";
86
- import { submitData as Sr } from "./component/reaction/submitData.js";
87
- import { triggerEvent as Ar } from "./component/reaction/triggerEvent.js";
38
+ import { interpolateSegments as Be } from "./engine/utility/interpolateSegments.js";
39
+ import { stringToBoolean as ke } from "./engine/utility/stringToBoolean.js";
40
+ import { View as Ne } from "./engine/View.js";
41
+ import { simpleMapping as Ue } from "./component/dataMapping/simpleMapping.js";
42
+ import { VariablesDebug as Ie } from "./component/element/debug/VariablesDebug/VariablesDebug.js";
43
+ import { Input as We } from "./component/element/form/Input.js";
44
+ import { CheckBoxField as qe } from "./component/element/form/CheckBoxField.js";
45
+ import { ColorField as Qe } from "./component/element/form/ColorField.js";
46
+ import { DateField as Ye } from "./component/element/form/DateField.js";
47
+ import { DateTimeField as _e } from "./component/element/form/DateTimeField.js";
48
+ import { EmailField as eo } from "./component/element/form/EmailField.js";
49
+ import { FileField as ro } from "./component/element/form/FileField.js";
50
+ import { HiddenField as ao } from "./component/element/form/HiddenField.js";
51
+ import { MonthField as po } from "./component/element/form/MonthField.js";
52
+ import { NumberField as fo } from "./component/element/form/NumberField.js";
53
+ import { PasswordField as lo } from "./component/element/form/PasswordField.js";
54
+ import { RangeField as so } from "./component/element/form/RangeField.js";
55
+ import { SearchField as co } from "./component/element/form/SearchField.js";
56
+ import { SelectField as Do } from "./component/element/form/SelectField.js";
57
+ import { TelField as Co } from "./component/element/form/TelField.js";
58
+ import { TextAreaField as go } from "./component/element/form/TextAreaField.js";
59
+ import { TextField as Ro } from "./component/element/form/TextField.js";
60
+ import { TimeField as ho } from "./component/element/form/TimeField.js";
61
+ import { UrlField as Eo } from "./component/element/form/UrlField.js";
62
+ import { WeekField as Vo } from "./component/element/form/WeekField.js";
63
+ import { FolderSortableTree as Ho } from "./component/element/html/FolderSortableTree.js";
64
+ import { FormatNumeral as yo } from "./component/element/html/FormatNumeral.js";
65
+ import { Html as Jo } from "./component/element/html/Html.js";
66
+ import { LabelFromValue as wo } from "./component/element/html/LabelFromValue.js";
67
+ import { PreformattedMarkup as zo } from "./component/element/html/PreformattedMarkup.js";
68
+ import { SortableTreeItemCollapseButton as Go } from "./component/element/html/SortableTreeItemCollapseButton.js";
69
+ import { Count as Oo } from "./component/element/special/Count.js";
70
+ import { DataFilter as jo } from "./component/element/special/DataFilter.js";
71
+ import { DataSync as Ko } from "./component/element/special/DataSync.js";
72
+ import { DelayedActions as Xo, getReactionFunctionsToExecute as Yo } from "./component/element/special/DelayedActions.js";
73
+ import { PageControls as _o } from "./component/element/special/PageControls.js";
74
+ import { Phantom as er } from "./component/element/special/Phantom.js";
75
+ import { ReactiveJsonBasicComponentWrapper as rr } from "./component/element/special/ReactiveJsonBasicComponentWrapper.js";
76
+ import { ReactiveJsonSubroot as ar } from "./component/element/special/ReactiveJsonSubroot.js";
77
+ import { Switch as pr } from "./component/element/special/Switch.js";
78
+ import { addData as fr } from "./component/reaction/addData.js";
79
+ import { fetchData as lr } from "./component/reaction/fetchData.js";
80
+ import { executeHttpRequest as sr } from "./component/reaction/utility/httpRequestCommon.js";
81
+ import { moveData as ur } from "./component/reaction/moveData.js";
82
+ import { postMessage as Fr } from "./component/reaction/postMessage.js";
83
+ import { redirectNow as vr } from "./component/reaction/redirectNow.js";
84
+ import { removeData as br } from "./component/reaction/removeData.js";
85
+ import { setClipboardData as Tr } from "./component/reaction/setClipboardData.js";
86
+ import { setData as Sr } from "./component/reaction/setData.js";
87
+ import { submitData as Ar } from "./component/reaction/submitData.js";
88
+ import { triggerEvent as Pr } from "./component/reaction/triggerEvent.js";
88
89
  export {
89
90
  B as ActionDependant,
90
- We as CheckBoxField,
91
- qe as ColorField,
92
- Go as Count,
91
+ qe as CheckBoxField,
92
+ Qe as ColorField,
93
+ Oo as Count,
93
94
  r as CustomEventListener,
94
- Oo as DataFilter,
95
+ jo as DataFilter,
95
96
  z as DataStore,
96
- jo as DataSync,
97
- Qe as DateField,
98
- Ye as DateTimeField,
99
- Ko as DelayedActions,
100
- _e as EmailField,
97
+ Ko as DataSync,
98
+ Ye as DateField,
99
+ _e as DateTimeField,
100
+ Xo as DelayedActions,
101
+ eo as EmailField,
101
102
  G as EventDispatcherContext,
102
103
  O as EventDispatcherProvider,
103
- eo as FileField,
104
- Vo as FolderSortableTree,
105
- Ho as FormatNumeral,
104
+ ro as FileField,
105
+ Ho as FolderSortableTree,
106
+ yo as FormatNumeral,
106
107
  K as GlobalDataContext,
107
108
  X as GlobalDataContextProvider,
108
109
  a as HashChangeListener,
109
- ro as HiddenField,
110
+ ao as HiddenField,
110
111
  p as Hide,
111
- yo as Html,
112
- Ie as Input,
113
- Jo as LabelFromValue,
112
+ Jo as Html,
113
+ We as Input,
114
+ wo as LabelFromValue,
114
115
  f as MessageListener,
115
- ao as MonthField,
116
- po as NumberField,
117
- Yo as PageControls,
116
+ po as MonthField,
117
+ fo as NumberField,
118
+ _o as PageControls,
118
119
  Z as PaginationContext,
119
- fo as PasswordField,
120
- _o as Phantom,
121
- wo as PreformattedMarkup,
122
- lo as RangeField,
120
+ lo as PasswordField,
121
+ er as Phantom,
122
+ zo as PreformattedMarkup,
123
+ so as RangeField,
123
124
  l as ReactOnEvent,
124
- er as ReactiveJsonBasicComponentWrapper,
125
+ rr as ReactiveJsonBasicComponentWrapper,
125
126
  $ as ReactiveJsonRoot,
126
- rr as ReactiveJsonSubroot,
127
+ ar as ReactiveJsonSubroot,
127
128
  s as Redirect,
128
- so as SearchField,
129
- co as SelectField,
129
+ co as SearchField,
130
+ Do as SelectField,
130
131
  u as SetAttributeValue,
131
- zo as SortableTreeItemCollapseButton,
132
+ Go as SortableTreeItemCollapseButton,
132
133
  oe as StoreContext,
133
134
  re as StoreProvider,
134
- ar as Switch,
135
- Do as TelField,
135
+ pr as Switch,
136
+ Co as TelField,
136
137
  me as TemplateContext,
137
- Co as TextAreaField,
138
- go as TextField,
139
- Ro as TimeField,
138
+ go as TextAreaField,
139
+ Ro as TextField,
140
+ ho as TimeField,
140
141
  F as ToggleAttributeValue,
141
142
  v as UnsetAttribute,
142
143
  b as UnsetAttributeValue,
143
- ho as UrlField,
144
- Ue as VariablesDebug,
145
- ke as View,
144
+ Eo as UrlField,
145
+ Ie as VariablesDebug,
146
+ Ne as View,
146
147
  T as VisuallyHide,
147
- Eo as WeekField,
148
- pr as addData,
148
+ Vo as WeekField,
149
+ fr as addData,
149
150
  W as addEventListener,
150
151
  Fe as alterData,
151
152
  ve as analyzeDataOverrideReferences,
@@ -159,30 +160,31 @@ export {
159
160
  fe as evaluateAttributes,
160
161
  ie as evaluateTemplateValue,
161
162
  le as evaluateTemplateValueCollection,
162
- lr as executeHttpRequest,
163
- fr as fetchData,
163
+ sr as executeHttpRequest,
164
+ lr as fetchData,
164
165
  Se as formatString,
165
- Qo as getReactionFunctionsToExecute,
166
+ Yo as getReactionFunctionsToExecute,
167
+ Be as interpolateSegments,
166
168
  ne as isTemplateValue,
167
169
  J as isValid,
168
170
  he as maybeFormatString,
169
171
  w as mergeComponentCollections,
170
- sr as moveData,
172
+ ur as moveData,
171
173
  He as normalizeAttributeNameForReactJsx,
172
174
  Me as normalizeAttributesForReactJsx,
173
175
  Ve as parseRjBuild,
174
- ur as postMessage,
176
+ Fr as postMessage,
175
177
  Ee as propsDataLocationToPathAndValue,
176
- Fr as redirectNow,
177
- vr as removeData,
178
+ vr as redirectNow,
179
+ br as removeData,
178
180
  j as removeEventListener,
179
181
  Te as replaceEventPlaceholders,
180
- br as setClipboardData,
181
- Tr as setData,
182
- Ne as simpleMapping,
183
- Be as stringToBoolean,
184
- Sr as submitData,
185
- Ar as triggerEvent,
182
+ Tr as setClipboardData,
183
+ Sr as setData,
184
+ Ue as simpleMapping,
185
+ ke as stringToBoolean,
186
+ Ar as submitData,
187
+ Pr as triggerEvent,
186
188
  se as useEvaluatedAttributes,
187
189
  ue as useReactiveData,
188
190
  te as useStore
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ea-lab/reactive-json",
3
3
  "private": false,
4
- "version": "2.0.1",
4
+ "version": "2.2.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",