@ea-lab/reactive-json 2.1.0 → 2.3.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,317 +1,328 @@
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";
4
- import { r as ct } from "../dnd-kit-sortable-tree.esm-Cz1RJyIg.js";
5
- import { coreComponentsPlugin as X } from "../coreComponentsPlugin.js";
6
- import { mergeComponentCollections as pt } from "./ComponentCollector.js";
7
- import { DataStore as lt } from "./DataStore.js";
8
- import { EventDispatcherProvider as dt } from "./EventDispatcherProvider.js";
9
- import { GlobalDataContext as ut } from "./GlobalDataContext.js";
10
- import mt from "./ParsingDebugDisplay/ParsingDebugDisplay.js";
11
- import { StoreContext as ft } from "./StoreContext.js";
12
- import { TemplateContext as gt } from "./TemplateContext.js";
13
- import { dataLocationToPath as ht } from "./TemplateSystem.js";
14
- import { useReactiveData as Pt } from "./hook/useReactiveData.js";
15
- import { alterData as yt } from "./utility/alterData.js";
16
- import { applyDataMapping as Dt } from "./utility/dataMappingSystem.js";
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 }) => {
21
- const E = Pt("");
22
- return /* @__PURE__ */ p(m, { children: JSON.stringify(E, null, " ") });
23
- }, xt = ({
24
- dataOverride: m,
25
- dataFetchMethod: E,
26
- dataUrl: G,
27
- debugMode: Y,
28
- DebugModeContentWrapper: L,
29
- DebugModeDataWrapper: O,
30
- DebugModeRootWrapper: Z,
31
- headersForData: z,
1
+ import { jsx as u, jsxs as Y, Fragment as lt } from "react/jsx-runtime";
2
+ import { a as L } from "../index-BUPRVmV-.js";
3
+ import { useRef as Z, useState as U, useEffect as N, useMemo as pt } from "react";
4
+ import { r as dt } from "../dnd-kit-sortable-tree.esm-Cz1RJyIg.js";
5
+ import { coreComponentsPlugin as F } from "../coreComponentsPlugin.js";
6
+ import { mergeComponentCollections as ut } from "./ComponentCollector.js";
7
+ import { DataStore as mt } from "./DataStore.js";
8
+ import { EventDispatcherProvider as ft } from "./EventDispatcherProvider.js";
9
+ import { GlobalDataContext as gt } from "./GlobalDataContext.js";
10
+ import ht from "./ParsingDebugDisplay/ParsingDebugDisplay.js";
11
+ import { StoreContext as yt } from "./StoreContext.js";
12
+ import { TemplateContext as Pt } from "./TemplateContext.js";
13
+ import { dataLocationToPath as Dt } from "./TemplateSystem.js";
14
+ import { useReactiveData as wt } from "./hook/useReactiveData.js";
15
+ import { alterData as bt } from "./utility/alterData.js";
16
+ import { applyDataMapping as St } from "./utility/dataMappingSystem.js";
17
+ import { parseRjBuild as Ct } from "./utility/parseRjBuild.js";
18
+ import { interpolateSegments as vt } from "./utility/interpolateSegments.js";
19
+ import { stringToBoolean as Et } from "./utility/stringToBoolean.js";
20
+ import { View as xt } from "./View.js";
21
+ const kt = ({ Wrapper: g }) => {
22
+ const T = wt("");
23
+ return /* @__PURE__ */ u(g, { children: JSON.stringify(T, null, " ") });
24
+ }, At = ({
25
+ dataOverride: g,
26
+ dataFetchMethod: T,
27
+ dataUrl: O,
28
+ debugMode: tt,
29
+ DebugModeContentWrapper: q,
30
+ DebugModeDataWrapper: z,
31
+ DebugModeRootWrapper: et,
32
+ headersForData: I,
32
33
  headersForRjBuild: s,
33
- maybeRawAppData: I,
34
- maybeRawAppRjBuild: w,
35
- plugins: N,
36
- rjBuildFetchMethod: b,
37
- rjBuildUrl: f,
38
- upstreamUpdateCallbacks: R
34
+ maybeRawAppData: M,
35
+ maybeRawAppRjBuild: S,
36
+ plugins: R,
37
+ rjBuildFetchMethod: C,
38
+ rjBuildUrl: h,
39
+ upstreamUpdateCallbacks: $
39
40
  }) => {
40
- const g = [];
41
- E && (g.push({
41
+ const y = [];
42
+ T && (y.push({
42
43
  deprecatedProperty: "dataFetchMethod",
43
44
  newProperty: "rjBuildFetchMethod"
44
- }), b = E), G && (g.push({
45
+ }), C = T), O && (y.push({
45
46
  deprecatedProperty: "dataUrl",
46
47
  newProperty: "rjBuildUrl"
47
- }), f = G), z && (g.push({
48
+ }), h = O), I && (y.push({
48
49
  deprecatedProperty: "headersForData",
49
50
  newProperty: "headersForRjBuild"
50
- }), s = z), I && (g.push({
51
+ }), s = I), M && (y.push({
51
52
  deprecatedProperty: "maybeRawAppData",
52
53
  newProperty: "maybeRawAppRjBuild"
53
- }), w = I), g.length > 0 && console.warn(
54
- "A ReactiveJsonRoot component got the following deprecated properties that must be replaced: " + g.map((t) => t.deprecatedProperty + " -> " + t.newProperty).join(", ")
54
+ }), S = M), y.length > 0 && console.warn(
55
+ "A ReactiveJsonRoot component got the following deprecated properties that must be replaced: " + y.map((t) => t.deprecatedProperty + " -> " + t.newProperty).join(", ")
55
56
  );
56
- const a = K(new lt({})).current, [d, C] = Q({
57
+ const o = Z(new mt({})).current, [m, v] = U({
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] = U(null), a = Z(null);
63
+ N(() => () => {
64
+ typeof document < "u" && a.current && a.current.parentNode && (a.current.parentNode.removeChild(a.current), a.current = null);
64
65
  }, []);
65
- const S = it(
66
- () => N ? pt([X, N]) : X,
67
- [N]
66
+ const E = pt(
67
+ () => R ? ut([F, R]) : F,
68
+ [R]
68
69
  );
69
- V(() => {
70
- let t = w;
71
- typeof t == "string" || t && (t = JSON.stringify(t)), t && C((r) => ({ ...r, rawAppRjBuild: t }));
72
- }, [w]), V(() => {
73
- if (!f) return;
70
+ N(() => {
71
+ let t = S;
72
+ typeof t == "string" || t && (t = JSON.stringify(t)), t && v((r) => ({ ...r, rawAppRjBuild: t }));
73
+ }, [S]), N(() => {
74
+ if (!h) return;
74
75
  const t = {
75
- method: b || "GET",
76
- url: f,
76
+ method: C || "GET",
77
+ url: h,
77
78
  headers: s
78
79
  };
79
- t.method.toLowerCase() === "post" ? J.post(t.url, {}, { headers: t.headers }).then((r) => {
80
- C((i) => ({ ...i, rawAppRjBuild: r.data }));
81
- }) : J.get(t.url, { headers: t.headers }).then((r) => {
82
- C((i) => ({ ...i, rawAppRjBuild: r.data }));
80
+ t.method.toLowerCase() === "post" ? L.post(t.url, {}, { headers: t.headers }).then((r) => {
81
+ v((c) => ({ ...c, rawAppRjBuild: r.data }));
82
+ }) : L.get(t.url, { headers: t.headers }).then((r) => {
83
+ v((c) => ({ ...c, rawAppRjBuild: r.data }));
83
84
  });
84
- }, [f, s, b]), V(() => {
85
- if (!d.rawAppRjBuild) return;
86
- const t = wt(d.rawAppRjBuild);
85
+ }, [h, s, C]), N(() => {
86
+ if (!m.rawAppRjBuild) return;
87
+ const t = Ct(m.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.`
90
91
  ), console.error(t.error.message), console.debug("Context:", {
91
- rjBuildUrl: f,
92
- rjBuildFetchMethod: b,
92
+ rjBuildUrl: h,
93
+ rjBuildFetchMethod: C,
93
94
  headersForRjBuild: s,
94
- maybeRawAppRjBuild: w,
95
- dataOverride: m
95
+ maybeRawAppRjBuild: S,
96
+ dataOverride: g
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 i = document.createElement("div");
101
+ e.appendChild(i), a.current = i;
101
102
  }
102
- M(
103
- ct.createPortal(
104
- /* @__PURE__ */ p(
105
- mt,
103
+ W(
104
+ dt.createPortal(
105
+ /* @__PURE__ */ u(
106
+ ht,
106
107
  {
107
108
  processedRjBuild: t,
108
109
  errorContext: {
109
- rjBuildUrl: f,
110
- rjBuildFetchMethod: b,
110
+ rjBuildUrl: h,
111
+ rjBuildFetchMethod: C,
111
112
  headersForRjBuild: s,
112
- maybeRawAppRjBuild: w
113
+ maybeRawAppRjBuild: S
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
- const r = t.data, i = m !== void 0 ? m : r.data;
127
- a.set("", i);
126
+ j && (W(null), typeof document < "u" && a.current && a.current.parentNode && (a.current.parentNode.removeChild(a.current), a.current = null));
127
+ const r = t.data, c = g !== void 0 ? g : r.data;
128
+ o.set("", c);
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
- }, h = r.additionalDataSource;
134
- if (!Array.isArray(h) || h.length === 0) {
135
- C((e) => ({ ...e, ...n }));
133
+ rawAppRjBuild: m.rawAppRjBuild
134
+ }, P = r.additionalDataSource;
135
+ if (!Array.isArray(P) || P.length === 0) {
136
+ v((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
- var P;
139
+ const x = P.filter((e) => e.blocking === !0), V = P.filter((e) => e.blocking !== !0), _ = (e) => !e || e === "data" ? "" : e.startsWith("data.") ? e.substring(5) : e, J = async (e, i) => {
140
+ var X;
141
+ const { fallbackDataSource: D, ...l } = e, K = async (p) => {
142
+ D ? (console.warn(`additionalDataSource item ${i}: ${p} — trying fallbackDataSource.`), await J(D, i)) : console.warn(`additionalDataSource item ${i}: ${p}.`, l);
143
+ }, Q = vt(l.src, (p) => o.get(p));
144
+ if (!Q) {
145
+ await K("could not resolve 'src'");
146
+ return;
147
+ }
148
+ const w = {
149
+ method: ((X = l.method) == null ? void 0 : X.toUpperCase()) || "GET",
150
+ url: Q
151
+ };
152
+ s && Object.keys(s).length > 0 && (w.headers = s);
153
+ let k;
140
154
  try {
141
- if (!e.src) {
142
- console.warn("additionalDataSource item number " + l + " missing 'src' property.", e);
143
- return;
144
- }
145
- const y = {
146
- method: ((P = e.method) == null ? void 0 : P.toUpperCase()) || "GET",
147
- url: e.src
148
- };
149
- s && Object.keys(s).length > 0 && (y.headers = s);
150
- const k = await J(y), rt = {
151
- url: y.url,
152
- method: y.method,
153
- headers: y.headers || {},
154
- body: y.data
155
- }, ot = {
155
+ k = await L(w);
156
+ } catch (p) {
157
+ await K(`HTTP request failed (${p.message})`);
158
+ return;
159
+ }
160
+ try {
161
+ const p = {
162
+ url: w.url,
163
+ method: w.method,
164
+ headers: w.headers || {},
165
+ body: w.data
166
+ }, st = {
156
167
  headers: k.headers || {},
157
168
  status: k.status,
158
169
  data: k.data
159
- }, D = yt({
160
- requestContext: rt,
161
- responseContext: ot,
170
+ }, b = bt({
171
+ requestContext: p,
172
+ responseContext: st,
162
173
  responseBody: k.data,
163
174
  // additionalDataSource always processes raw data, not RjBuild.
164
175
  isRjBuild: !1,
165
- dataProcessors: (S == null ? void 0 : S.dataProcessor) || {}
176
+ dataProcessors: (E == null ? void 0 : E.dataProcessor) || {}
166
177
  });
167
- if (e.dataMapping) {
168
- const u = {
178
+ if (l.dataMapping) {
179
+ const f = {
169
180
  headersForRjBuild: s,
170
- plugins: S,
181
+ plugins: E,
171
182
  get templateData() {
172
- return a.get("");
183
+ return o.get("");
173
184
  },
174
185
  templatePath: "data",
175
- setData: (c) => a.set("", c),
176
- updateData: (c, j, at) => {
177
- const nt = B(j);
178
- a.set(nt, c, at);
186
+ setData: (d) => o.set("", d),
187
+ updateData: (d, G, ct) => {
188
+ const it = _(G);
189
+ o.set(it, d, ct);
179
190
  }
180
- }, v = {
191
+ }, A = {
181
192
  get templateData() {
182
- return a.get("");
193
+ return o.get("");
183
194
  },
184
195
  templatePath: "data"
185
196
  };
186
197
  try {
187
- Dt({
188
- dataMapping: e.dataMapping,
189
- responseData: D,
190
- globalDataContext: u,
191
- templateContext: v
198
+ St({
199
+ dataMapping: l.dataMapping,
200
+ responseData: b,
201
+ globalDataContext: f,
202
+ templateContext: A
192
203
  });
193
204
  return;
194
- } catch (c) {
195
- console.error("Error applying dataMapping for additionalDataSource:", c);
205
+ } catch (d) {
206
+ console.error("Error applying dataMapping for additionalDataSource:", d);
196
207
  }
197
208
  }
198
- if (!e.path) {
199
- if (typeof D != "object" || Array.isArray(D)) {
209
+ if (!l.path) {
210
+ if (typeof b != "object" || Array.isArray(b)) {
200
211
  console.warn(
201
212
  "additionalDataSource data cannot be merged at root - must be an object:",
202
- D
213
+ b
203
214
  );
204
215
  return;
205
216
  }
206
- Object.entries(D).forEach(([u, v]) => {
207
- a.set(u, v);
217
+ Object.entries(b).forEach(([f, A]) => {
218
+ o.set(f, A);
208
219
  });
209
220
  return;
210
221
  }
211
222
  try {
212
- const u = {
213
- templateData: a.get(""),
223
+ const f = {
224
+ templateData: o.get(""),
214
225
  // use current snapshot
215
226
  templatePath: "data"
216
- }, v = {
217
- templateData: a.get(""),
227
+ }, A = {
228
+ templateData: o.get(""),
218
229
  // use current snapshot
219
230
  templatePath: "data"
220
- }, c = ht({
221
- dataLocation: e.path,
231
+ }, d = Dt({
232
+ dataLocation: l.path,
222
233
  currentPath: "data",
223
- globalDataContext: u,
224
- templateContext: v
234
+ globalDataContext: f,
235
+ templateContext: A
225
236
  });
226
- if (typeof c != "string") {
237
+ if (typeof d != "string") {
227
238
  console.warn(
228
239
  "additionalDataSource path evaluation did not result in a string:",
229
- e.path,
240
+ l.path,
230
241
  "->",
231
- c
242
+ d
232
243
  );
233
244
  return;
234
245
  }
235
- const j = B(c);
236
- a.set(j, D);
237
- } catch (u) {
238
- console.error("Error evaluating additionalDataSource path:", e.path, u);
246
+ const G = _(d);
247
+ o.set(G, b);
248
+ } catch (f) {
249
+ console.error("Error evaluating additionalDataSource path:", l.path, f);
239
250
  }
240
- } catch ($) {
241
- console.error("Error fetching additional data source:", e.src, $);
251
+ } catch (p) {
252
+ console.error("Error processing additionalDataSource response:", l.src, p);
242
253
  }
243
254
  };
244
255
  (async () => {
245
256
  if (x.length > 0) {
246
- const e = x.map((l, P) => _(l, P));
257
+ const e = x.map((i, D) => J(i, D));
247
258
  await Promise.allSettled(e);
248
259
  }
249
- if (C((e) => ({ ...e, ...n })), A.length > 0) {
250
- const e = A.map(
251
- (l, P) => _(l, x.length + P)
260
+ if (v((e) => ({ ...e, ...n })), V.length > 0) {
261
+ const e = V.map(
262
+ (i, D) => J(i, x.length + D)
252
263
  );
253
264
  Promise.allSettled(e);
254
265
  }
255
266
  })();
256
- }, [d.rawAppRjBuild, m, a]);
257
- function W(t, r, i) {
258
- if (!R || R.size === 0)
267
+ }, [m.rawAppRjBuild, g, o]);
268
+ function B(t, r, c) {
269
+ if (!$ || $.size === 0)
259
270
  return !1;
260
- for (const [n, h] of R)
271
+ for (const [n, P] of $)
261
272
  if (t === n || t.startsWith(n + ".") || n === "") {
262
273
  const x = n === "" ? t : t.substring(n.length + 1);
263
274
  try {
264
- return h(r, x, i), !0;
265
- } catch (A) {
266
- console.warn("Error during upstream update:", A);
275
+ return P(r, x, c), !0;
276
+ } catch (V) {
277
+ console.warn("Error during upstream update:", V);
267
278
  break;
268
279
  }
269
280
  }
270
281
  return !1;
271
282
  }
272
- const U = (t) => {
273
- W("", t, void 0) || a.set("", t);
274
- }, F = (t, r, i) => {
283
+ const rt = (t) => {
284
+ B("", t, void 0) || o.set("", t);
285
+ }, ot = (t, r, c) => {
275
286
  const n = r.startsWith("data.") ? r.substring(5) : r === "data" ? "" : r;
276
- W(n, t, i) || a.set(n, t, i);
277
- }, tt = {
278
- element: d.templates,
287
+ B(n, t, c) || o.set(n, t, c);
288
+ }, at = {
289
+ element: m.templates,
279
290
  headersForRjBuild: s,
280
- plugins: S,
281
- ReactiveJsonRoot: xt,
282
- setData: U,
283
- updateData: F,
291
+ plugins: E,
292
+ ReactiveJsonRoot: At,
293
+ setData: rt,
294
+ updateData: ot,
284
295
  // experimental: expose store for advanced usage
285
- store: a,
296
+ store: o,
286
297
  // fallback: get data from store directly (non-reactive access)
287
298
  get templateData() {
288
- return a.get("");
299
+ return o.get("");
289
300
  },
290
301
  templatePath: "data"
291
- }, q = d.items.map((t) => /* @__PURE__ */ p(
292
- Ct,
302
+ }, H = m.items.map((t) => /* @__PURE__ */ u(
303
+ xt,
293
304
  {
294
305
  datafield: t,
295
306
  path: "data." + t,
296
- props: d.renderView[t]
307
+ props: m.renderView[t]
297
308
  },
298
309
  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: {
310
+ )), nt = Et(tt);
311
+ return /* @__PURE__ */ u(yt.Provider, { value: o, children: /* @__PURE__ */ u(ft, { children: /* @__PURE__ */ u(gt.Provider, { value: at, children: /* @__PURE__ */ u(Pt.Provider, { value: {
301
312
  // Same here, getter for compatibility, but won't trigger updates
302
313
  get templateData() {
303
- return a.get("");
314
+ return o.get("");
304
315
  },
305
316
  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
310
- ] }) : /* @__PURE__ */ H(st, { children: [
311
- q,
312
- T
317
+ }, children: nt && q ? /* @__PURE__ */ Y(et, { children: [
318
+ /* @__PURE__ */ u(q, { children: H }),
319
+ z && /* @__PURE__ */ u(kt, { Wrapper: z }),
320
+ j
321
+ ] }) : /* @__PURE__ */ Y(lt, { children: [
322
+ H,
323
+ j
313
324
  ] }) }) }) }) });
314
325
  };
315
326
  export {
316
- xt as ReactiveJsonRoot
327
+ At as ReactiveJsonRoot
317
328
  };
@@ -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,63 @@
1
+ const i = (e, l) => {
2
+ if (typeof e == "string") {
3
+ let t = null;
4
+ if (e.startsWith("~~.") ? t = e.substring(3) : e.startsWith("~.") && (t = e.substring(2)), t !== null) {
5
+ const r = l(t);
6
+ return r == null ? null : String(r);
7
+ }
8
+ return e;
9
+ }
10
+ return e == null ? null : String(e);
11
+ }, p = (e, l) => {
12
+ if (typeof e == "string")
13
+ return e || null;
14
+ if (!Array.isArray(e) || e.length === 0)
15
+ return null;
16
+ const t = [], r = [];
17
+ for (const n of e) {
18
+ if (n !== null && typeof n == "object") {
19
+ if ("param" in n) {
20
+ const o = i(n.param, l), s = i(n.value, l);
21
+ if (!o || !s) {
22
+ if (n.required)
23
+ return console.warn(
24
+ `interpolateSegments: required param "${n.param}" resolved to empty key or value — aborting URL.`
25
+ ), null;
26
+ continue;
27
+ }
28
+ r.push(
29
+ `${encodeURIComponent(o)}=${encodeURIComponent(s)}`
30
+ );
31
+ continue;
32
+ }
33
+ if ("segment" in n) {
34
+ const o = i(n.segment, l);
35
+ if (!o) {
36
+ if (n.required)
37
+ return console.warn(
38
+ `interpolateSegments: required segment "${n.segment}" resolved to empty — aborting URL.`
39
+ ), null;
40
+ t.push("");
41
+ continue;
42
+ }
43
+ t.push(o);
44
+ continue;
45
+ }
46
+ console.warn("interpolateSegments: unrecognized segment object.", n);
47
+ continue;
48
+ }
49
+ if (typeof n == "string") {
50
+ const o = i(n, l);
51
+ o === null ? (console.warn(
52
+ `interpolateSegments: reference "${n}" resolved to null.`
53
+ ), t.push("")) : t.push(o);
54
+ continue;
55
+ }
56
+ t.push(String(n ?? ""));
57
+ }
58
+ const u = t.join(""), a = r.length > 0 ? "?" + r.join("&") : "";
59
+ return u + a || null;
60
+ };
61
+ export {
62
+ p as interpolateSegments
63
+ };
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.1.0",
4
+ "version": "2.3.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",