@optiaxiom/proteus 0.3.0 → 1.1.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 (64) hide show
  1. package/dist/esm/_virtual/_openai-shim-script.js +3 -2
  2. package/dist/esm/assets/src/proteus-chart/{ProteusChart.css.ts.vanilla-DNE5j3uT.css → ProteusChart.css.ts.vanilla-yGx8JdKz.css} +2 -2
  3. package/dist/esm/assets/src/proteus-chart/{ProteusChartTooltipContent.css.ts.vanilla-DM8u1icS.css → ProteusChartTooltipContent.css.ts.vanilla-HapBe2oo.css} +2 -2
  4. package/dist/esm/assets/src/proteus-document/{ProteusDocumentShell.css.ts.vanilla-DjZJuQ2A.css → ProteusDocumentShell.css.ts.vanilla-BPytQ9pT.css} +2 -2
  5. package/dist/esm/assets/src/proteus-image-carousel/{ProteusImageCarousel.css.ts.vanilla-CIwMJ4Cg.css → ProteusImageCarousel.css.ts.vanilla-DnlXoyv1.css} +2 -2
  6. package/dist/esm/assets/src/proteus-question/{ProteusQuestion.css.ts.vanilla-DiCe_bxf.css → ProteusQuestion.css.ts.vanilla-CpDgoW0l.css} +2 -2
  7. package/dist/esm/hooks/useEffectEvent.js +11 -10
  8. package/dist/esm/hooks/useObserveValue.js +24 -30
  9. package/dist/esm/icons/IconAngleLeft.js +13 -19
  10. package/dist/esm/icons/IconAngleRight.js +13 -19
  11. package/dist/esm/icons/IconX.js +10 -18
  12. package/dist/esm/icons/withIcon.js +17 -28
  13. package/dist/esm/index.js +22 -17
  14. package/dist/esm/proteus-action/ProteusAction.js +44 -39
  15. package/dist/esm/proteus-bridge/ProteusBridge.js +71 -85
  16. package/dist/esm/proteus-card-link/ProteusCardLink.js +24 -37
  17. package/dist/esm/proteus-chart/ProteusChart-css.js +14 -5
  18. package/dist/esm/proteus-chart/ProteusChart.js +86 -84
  19. package/dist/esm/proteus-chart/ProteusChartContext.js +3 -3
  20. package/dist/esm/proteus-chart/ProteusChartTooltipContent-css.js +23 -6
  21. package/dist/esm/proteus-chart/ProteusChartTooltipContent.js +52 -66
  22. package/dist/esm/proteus-data-table/ProteusDataTable.js +28 -29
  23. package/dist/esm/proteus-date-input/ProteusDateInput.js +23 -0
  24. package/dist/esm/proteus-document/ProteusDocumentContext.js +4 -3
  25. package/dist/esm/proteus-document/ProteusDocumentPathContext.js +6 -5
  26. package/dist/esm/proteus-document/ProteusDocumentRenderer.js +25 -33
  27. package/dist/esm/proteus-document/ProteusDocumentShell-css.js +32 -6
  28. package/dist/esm/proteus-document/ProteusDocumentShell.js +226 -219
  29. package/dist/esm/proteus-document/getProteusValue.js +28 -42
  30. package/dist/esm/proteus-document/resolveProteusProp.js +31 -49
  31. package/dist/esm/proteus-document/resolveProteusValue.js +73 -136
  32. package/dist/esm/proteus-document/schemas.js +42 -45
  33. package/dist/esm/proteus-document/useResolveProteusValues.js +10 -16
  34. package/dist/esm/proteus-element/ProteusElement.js +114 -180
  35. package/dist/esm/proteus-federated/ProteusFederated.js +51 -52
  36. package/dist/esm/proteus-file-icon/ProteusFileIcon.js +29 -38
  37. package/dist/esm/proteus-file-upload/ProteusFileUpload.js +107 -133
  38. package/dist/esm/proteus-image/ProteusImage.js +99 -106
  39. package/dist/esm/proteus-image/downloadFile.js +3 -2
  40. package/dist/esm/proteus-image-carousel/ProteusImageCarousel-css.js +49 -11
  41. package/dist/esm/proteus-image-carousel/ProteusImageCarousel.js +151 -163
  42. package/dist/esm/proteus-input/ProteusInput.js +19 -27
  43. package/dist/esm/proteus-length/ProteusLength.js +10 -0
  44. package/dist/esm/proteus-map/ProteusMap.js +18 -31
  45. package/dist/esm/proteus-map-index/ProteusMapIndex.js +11 -0
  46. package/dist/esm/proteus-pill-menu/ProteusPillMenu.js +65 -0
  47. package/dist/esm/proteus-pill-menu/useInputValueChangeInteraction.js +36 -0
  48. package/dist/esm/proteus-question/ProteusQuestion-css.js +40 -8
  49. package/dist/esm/proteus-question/ProteusQuestion.js +324 -400
  50. package/dist/esm/proteus-select/ProteusSelect.js +25 -40
  51. package/dist/esm/proteus-show/ProteusShow.js +10 -18
  52. package/dist/esm/proteus-switch/ProteusSwitch.js +33 -36
  53. package/dist/esm/proteus-textarea/ProteusTextarea.js +18 -27
  54. package/dist/esm/proteus-value/ProteusValue.js +4 -4
  55. package/dist/esm/schema/public-schema.js +4537 -0
  56. package/dist/esm/schema/runtime-schema.js +4460 -0
  57. package/dist/esm/spec.js +5 -1
  58. package/dist/esm/use-proteus-value/useProteusValue.js +8 -12
  59. package/dist/index.d.ts +516 -347
  60. package/dist/spec.d.ts +5 -9952
  61. package/package.json +5 -5
  62. package/dist/esm/icons/IconCalendar.js +0 -20
  63. package/dist/esm/schema/public-schema.json.js +0 -9041
  64. package/dist/esm/schema/runtime-schema.json.js +0 -8974
@@ -1,223 +1,230 @@
1
1
  "use client";
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { IconArrowDown } from '@optiaxiom/icons';
4
- import { Disclosure, DisclosureTrigger, Box, Group, Text, DisclosureContent, Heading, Tooltip } from '@optiaxiom/react';
5
- import { useControllableState } from '@radix-ui/react-use-controllable-state';
6
- import { set } from 'jsonpointer';
7
- import { useState, useRef, useEffect } from 'react';
8
- import { useEffectEvent } from '../hooks/useEffectEvent.js';
9
- import { downloadFile } from '../proteus-image/downloadFile.js';
10
- import { ProteusDocumentProvider } from './ProteusDocumentContext.js';
11
- import { scrollIndicator, body } from './ProteusDocumentShell-css.js';
12
- import { resolveProteusValue } from './resolveProteusValue.js';
13
-
14
- function ProteusDocumentShell({
15
- collapsible: collapsibleProp,
16
- data = {},
17
- defaultOpen = true,
18
- element,
19
- onDataChange,
20
- onDownload,
21
- onInteraction,
22
- onMessage,
23
- onOpenChange,
24
- onPreview,
25
- onTrack,
26
- onUpload,
27
- open: openProp,
28
- readOnly = false,
29
- strict,
30
- useResource
31
- }) {
32
- const [valid, setValid] = useState(false);
33
- const formRef = useRef(null);
34
- useEffect(() => {
35
- if (formRef.current) {
36
- setValid(formRef.current.checkValidity());
37
- }
38
- }, []);
39
- const [open, setOpen] = useControllableState({
40
- defaultProp: defaultOpen,
41
- onChange: onOpenChange,
42
- prop: openProp
43
- });
44
- const bodyRef = useRef(null);
45
- useEffect(() => {
46
- const node = bodyRef.current;
47
- if (!node)
48
- return;
49
- const update = () => {
50
- if (node.scrollHeight - node.scrollTop - node.clientHeight > 1) {
51
- node.dataset.canScroll = "";
52
- } else {
53
- delete node.dataset.canScroll;
54
- }
55
- };
56
- const observer = new ResizeObserver(update);
57
- observer.observe(node);
58
- node.addEventListener("scroll", update, { passive: true });
59
- return () => {
60
- observer.disconnect();
61
- node.removeEventListener("scroll", update);
62
- };
63
- }, []);
64
- const collapsible = collapsibleProp && element.appName;
65
- const Trigger = collapsible ? DisclosureTrigger : Box;
66
- const appearance = resolveProteusValue(element.appearance, data, "", []);
67
- const inline = appearance === "inline";
68
- return /* @__PURE__ */ jsx(
69
- ProteusDocumentProvider,
70
- {
71
- data,
72
- onDataChange: useEffectEvent((path, value) => {
73
- const next = structuredClone(data);
74
- set(next, path, value);
75
- onDataChange?.(next);
76
- }),
77
- onEvent: useEffectEvent(async (event) => {
78
- if ("interaction" in event) {
79
- return await onInteraction?.(event.interaction, event.params);
80
- } else if ("message" in event) {
81
- await onMessage?.(event.message);
82
- } else if (event.action === "download") {
83
- const urls = [];
84
- if (typeof event.url === "string") {
85
- urls.push(event.url);
86
- } else if (Array.isArray(event.url)) {
87
- for (const u of event.url) {
88
- if (typeof u !== "string") {
89
- throw new Error("Invalid URL in download array");
90
- }
91
- urls.push(u);
92
- }
93
- } else {
94
- throw new Error("Invalid URL for download action");
95
- }
96
- if (onDownload) {
97
- await onDownload(urls);
98
- } else {
99
- await Promise.all(urls.map((u) => downloadFile(u)));
100
- }
101
- } else if (event.action === "openLink") {
102
- if (typeof event.url === "string") {
103
- window.open(event.url, "_blank", "noopener,noreferrer");
104
- }
105
- } else if (event.action === "preview") {
106
- await onPreview?.(event.file);
107
- }
108
- return;
109
- }),
110
- onTrack: useEffectEvent(
111
- (event, properties) => {
112
- onTrack?.(event, properties);
113
- }
114
- ),
115
- onUpload,
116
- readOnly,
117
- strict,
118
- useResource,
119
- valid,
120
- children: /* @__PURE__ */ jsxs(
121
- Disclosure,
122
- {
123
- bg: inline ? void 0 : "bg.default",
124
- border: inline ? void 0 : "1",
125
- borderColor: inline ? void 0 : "border.tertiary",
126
- onOpenChange: setOpen,
127
- open,
128
- p: inline ? void 0 : "20",
129
- rounded: inline ? void 0 : "xl",
130
- children: [
131
- !inline && element.appName && /* @__PURE__ */ jsx(Trigger, { py: "0", ...collapsible ? { chevronPosition: "end" } : {}, children: /* @__PURE__ */ jsxs(Group, { fontSize: "sm", gap: "8", children: [
132
- /* @__PURE__ */ jsx(
133
- Box,
134
- {
135
- asChild: true,
136
- bg: element.appIcon ? void 0 : "bg.accent.subtle",
137
- flex: "none",
138
- rounded: "xs",
139
- size: "20",
140
- children: element.appIcon ? /* @__PURE__ */ jsx("img", { alt: "", src: element.appIcon }) : /* @__PURE__ */ jsx("div", {})
141
- }
142
- ),
143
- /* @__PURE__ */ jsx(Text, { fontWeight: "500", children: element.appName }),
144
- !open && /* @__PURE__ */ jsx(Text, { color: "fg.secondary", lineClamp: "1", children: element.title })
145
- ] }) }),
146
- /* @__PURE__ */ jsxs(
147
- DisclosureContent,
148
- {
149
- alignItems: "stretch",
150
- display: "flex",
151
- flexDirection: "column",
152
- gap: "16",
153
- pb: "0",
154
- pt: element.appName ? "16" : "0",
155
- children: [
156
- !inline && element.title && /* @__PURE__ */ jsxs(
157
- Group,
158
- {
159
- alignItems: element.titleIcon ? "start" : void 0,
160
- bg: element.titleIcon ? "bg.page" : "transparent",
161
- gap: "12",
162
- p: element.titleIcon ? "12" : void 0,
163
- rounded: "lg",
164
- children: [
165
- element.titleIcon && /* @__PURE__ */ jsx(
166
- Group,
167
- {
168
- bg: "bg.avatar.purple",
169
- flex: "none",
170
- justifyContent: "center",
171
- rounded: "lg",
172
- size: "md",
173
- children: /* @__PURE__ */ jsx(Box, { asChild: true, children: /* @__PURE__ */ jsx("img", { alt: "", src: element.titleIcon }) })
174
- }
175
- ),
176
- /* @__PURE__ */ jsxs(Group, { flex: "1", flexDirection: "column", gap: "4", children: [
177
- /* @__PURE__ */ jsx(Heading, { fontSize: "lg", fontWeight: "600", level: "2", lineClamp: "2", children: element.title }),
178
- !!element.subtitle && /* @__PURE__ */ jsx(Tooltip, { auto: true, content: element.subtitle, children: /* @__PURE__ */ jsx(Text, { color: "fg.secondary", lineClamp: "2", children: element.subtitle }) })
179
- ] })
180
- ]
181
- }
182
- ),
183
- /* @__PURE__ */ jsx(Group, { asChild: true, flexDirection: "column", gap: "16", children: /* @__PURE__ */ jsxs(
184
- "form",
185
- {
186
- onChange: (event) => {
187
- const form = event.currentTarget;
188
- setTimeout(() => {
189
- setValid(form.checkValidity());
190
- });
191
- },
192
- onSubmit: (event) => {
193
- event.preventDefault();
194
- },
195
- ref: formRef,
196
- children: [
197
- /* @__PURE__ */ jsxs(
198
- Group,
199
- {
200
- ref: element.compact ? bodyRef : void 0,
201
- ...body({ truncate: element.compact }),
202
- children: [
203
- element.body,
204
- element.compact && /* @__PURE__ */ jsx(Box, { ...scrollIndicator(), children: /* @__PURE__ */ jsx(IconArrowDown, {}) })
205
- ]
206
- }
207
- ),
208
- element.actions && !readOnly && /* @__PURE__ */ jsx(Group, { gap: "16", justifyContent: "end", w: "full", children: element.actions })
209
- ]
210
- }
211
- ) })
212
- ]
213
- }
214
- )
215
- ]
216
- }
217
- )
218
- }
219
- );
2
+ import { ProteusDocumentProvider } from "./ProteusDocumentContext.js";
3
+ import { resolveProteusValue } from "./resolveProteusValue.js";
4
+ import { useEffectEvent } from "../hooks/useEffectEvent.js";
5
+ import { downloadFile } from "../proteus-image/downloadFile.js";
6
+ import { body, scrollIndicator } from "./ProteusDocumentShell-css.js";
7
+ import { Box, Disclosure, DisclosureContent, DisclosureTrigger, Group, Heading, Text, Tooltip } from "@optiaxiom/react";
8
+ import { useEffect, useRef, useState } from "react";
9
+ import { get, set } from "jsonpointer";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+ import { IconArrowDown } from "@optiaxiom/icons";
12
+ import { useControllableState } from "@radix-ui/react-use-controllable-state";
13
+ //#region src/proteus-document/ProteusDocumentShell.tsx
14
+ function ProteusDocumentShell({ collapsible: collapsibleProp, data = {}, defaultOpen = true, element, icons, onDataChange, onDownload, onInteraction, onMessage, onOpenChange, onPreview, onTrack, onUpload, open: openProp, readOnly = false, strict, useResource }) {
15
+ const [valid, setValid] = useState(false);
16
+ const formRef = useRef(null);
17
+ useEffect(() => {
18
+ if (formRef.current) setValid(formRef.current.checkValidity());
19
+ }, []);
20
+ const [open, setOpen] = useControllableState({
21
+ defaultProp: defaultOpen,
22
+ onChange: onOpenChange,
23
+ prop: openProp
24
+ });
25
+ const bodyRef = useRef(null);
26
+ useEffect(() => {
27
+ const node = bodyRef.current;
28
+ if (!node) return;
29
+ const update = () => {
30
+ if (node.scrollHeight - node.scrollTop - node.clientHeight > 1) node.dataset.canScroll = "";
31
+ else delete node.dataset.canScroll;
32
+ };
33
+ const observer = new ResizeObserver(update);
34
+ observer.observe(node);
35
+ node.addEventListener("scroll", update, { passive: true });
36
+ return () => {
37
+ observer.disconnect();
38
+ node.removeEventListener("scroll", update);
39
+ };
40
+ }, []);
41
+ const collapsible = collapsibleProp && element.appName;
42
+ const Trigger = collapsible ? DisclosureTrigger : Box;
43
+ const inline = resolveProteusValue(element.appearance, data, "", []) === "inline";
44
+ return /* @__PURE__ */ jsx(ProteusDocumentProvider, {
45
+ data,
46
+ icons,
47
+ onDataChange: useEffectEvent((path, value) => {
48
+ onDataChange?.((prev) => {
49
+ const next = structuredClone(prev);
50
+ set(next, path, value);
51
+ return next;
52
+ });
53
+ }),
54
+ onEvent: useEffectEvent(async (event) => {
55
+ if ("interaction" in event) return await onInteraction?.(event.interaction, event.params);
56
+ else if ("message" in event) await onMessage?.(event.message);
57
+ else if (event.action === "download") {
58
+ const urls = [];
59
+ if (typeof event.url === "string") urls.push(event.url);
60
+ else if (Array.isArray(event.url)) for (const u of event.url) {
61
+ if (typeof u !== "string") throw new Error("Invalid URL in download array");
62
+ urls.push(u);
63
+ }
64
+ else throw new Error("Invalid URL for download action");
65
+ if (onDownload) await onDownload(urls);
66
+ else await Promise.all(urls.map((u) => downloadFile(u)));
67
+ } else if (event.action === "openLink") {
68
+ if (typeof event.url === "string") window.open(event.url, "_blank", "noopener,noreferrer");
69
+ } else if (event.action === "preview") await onPreview?.(event.file);
70
+ else if (event.action === "pushValue") {
71
+ const { path, value } = event;
72
+ onDataChange?.((prev) => {
73
+ const next = structuredClone(prev);
74
+ const current = get(next, path);
75
+ if (current !== void 0 && !Array.isArray(current)) {
76
+ if (strict) throw new Error(`pushValue: expected array at "${path}"`);
77
+ return prev;
78
+ }
79
+ set(next, path, [...current ?? [], value]);
80
+ return next;
81
+ });
82
+ } else if (event.action === "removeValue") {
83
+ const { path } = event;
84
+ const slash = path.lastIndexOf("/");
85
+ const parent = slash > 0 ? path.slice(0, slash) : "";
86
+ const index = Number(path.slice(slash + 1));
87
+ if (!parent || !Number.isInteger(index)) {
88
+ if (strict) throw new Error(`removeValue: "${path}" is not an array index`);
89
+ return;
90
+ }
91
+ onDataChange?.((prev) => {
92
+ const next = structuredClone(prev);
93
+ const arr = get(next, parent);
94
+ if (!Array.isArray(arr)) {
95
+ if (strict) throw new Error(`removeValue: "${parent}" is not an array`);
96
+ return prev;
97
+ }
98
+ set(next, parent, arr.filter((_, i) => i !== index));
99
+ return next;
100
+ });
101
+ }
102
+ }),
103
+ onTrack: useEffectEvent((event, properties) => {
104
+ onTrack?.(event, properties);
105
+ }),
106
+ onUpload,
107
+ readOnly,
108
+ strict,
109
+ useResource,
110
+ valid,
111
+ children: /* @__PURE__ */ jsxs(Disclosure, {
112
+ bg: inline ? void 0 : "bg.default",
113
+ border: inline ? void 0 : "1",
114
+ borderColor: inline ? void 0 : "border.tertiary",
115
+ onOpenChange: setOpen,
116
+ open,
117
+ p: inline ? void 0 : "20",
118
+ rounded: inline ? void 0 : "xl",
119
+ children: [!inline && element.appName && /* @__PURE__ */ jsx(Trigger, {
120
+ py: "0",
121
+ ...collapsible ? { chevronPosition: "end" } : {},
122
+ children: /* @__PURE__ */ jsxs(Group, {
123
+ fontSize: "sm",
124
+ gap: "8",
125
+ children: [
126
+ /* @__PURE__ */ jsx(Box, {
127
+ asChild: true,
128
+ bg: element.appIcon ? void 0 : "bg.accent.subtle",
129
+ flex: "none",
130
+ rounded: "xs",
131
+ size: "20",
132
+ children: element.appIcon ? /* @__PURE__ */ jsx("img", {
133
+ alt: "",
134
+ src: element.appIcon
135
+ }) : /* @__PURE__ */ jsx("div", {})
136
+ }),
137
+ /* @__PURE__ */ jsx(Text, {
138
+ fontWeight: "500",
139
+ children: element.appName
140
+ }),
141
+ !open && /* @__PURE__ */ jsx(Text, {
142
+ color: "fg.secondary",
143
+ lineClamp: "1",
144
+ children: element.title
145
+ })
146
+ ]
147
+ })
148
+ }), /* @__PURE__ */ jsxs(DisclosureContent, {
149
+ alignItems: "stretch",
150
+ display: "flex",
151
+ flexDirection: "column",
152
+ gap: "16",
153
+ pb: "0",
154
+ pt: element.appName ? "16" : "0",
155
+ children: [!inline && element.title && /* @__PURE__ */ jsxs(Group, {
156
+ alignItems: element.titleIcon ? "start" : void 0,
157
+ bg: element.titleIcon ? "bg.page" : "transparent",
158
+ gap: "12",
159
+ p: element.titleIcon ? "12" : void 0,
160
+ rounded: "lg",
161
+ children: [element.titleIcon && /* @__PURE__ */ jsx(Group, {
162
+ bg: "bg.avatar.purple",
163
+ flex: "none",
164
+ justifyContent: "center",
165
+ rounded: "lg",
166
+ size: "md",
167
+ children: /* @__PURE__ */ jsx(Box, {
168
+ asChild: true,
169
+ children: /* @__PURE__ */ jsx("img", {
170
+ alt: "",
171
+ src: element.titleIcon
172
+ })
173
+ })
174
+ }), /* @__PURE__ */ jsxs(Group, {
175
+ flex: "1",
176
+ flexDirection: "column",
177
+ gap: "4",
178
+ children: [/* @__PURE__ */ jsx(Heading, {
179
+ fontSize: "lg",
180
+ fontWeight: "600",
181
+ level: "2",
182
+ lineClamp: "2",
183
+ children: element.title
184
+ }), !!element.subtitle && /* @__PURE__ */ jsx(Tooltip, {
185
+ auto: true,
186
+ content: element.subtitle,
187
+ children: /* @__PURE__ */ jsx(Text, {
188
+ color: "fg.secondary",
189
+ lineClamp: "2",
190
+ children: element.subtitle
191
+ })
192
+ })]
193
+ })]
194
+ }), /* @__PURE__ */ jsx(Group, {
195
+ asChild: true,
196
+ flexDirection: "column",
197
+ gap: "16",
198
+ children: /* @__PURE__ */ jsxs("form", {
199
+ onChange: (event) => {
200
+ const form = event.currentTarget;
201
+ setTimeout(() => {
202
+ setValid(form.checkValidity());
203
+ });
204
+ },
205
+ onSubmit: (event) => {
206
+ event.preventDefault();
207
+ },
208
+ ref: formRef,
209
+ children: [/* @__PURE__ */ jsxs(Group, {
210
+ ref: element.compact ? bodyRef : void 0,
211
+ ...body({ truncate: element.compact }),
212
+ children: [element.body, element.compact && /* @__PURE__ */ jsx(Box, {
213
+ ...scrollIndicator(),
214
+ children: /* @__PURE__ */ jsx(IconArrowDown, {})
215
+ })]
216
+ }), element.actions && !readOnly && /* @__PURE__ */ jsx(Group, {
217
+ gap: "16",
218
+ justifyContent: "end",
219
+ w: "full",
220
+ children: element.actions
221
+ })]
222
+ })
223
+ })]
224
+ })]
225
+ })
226
+ });
220
227
  }
221
228
  ProteusDocumentShell.displayName = "@optiaxiom/proteus/ProteusDocumentShell";
222
-
229
+ //#endregion
223
230
  export { ProteusDocumentShell };
@@ -1,49 +1,35 @@
1
- import { get } from 'jsonpointer';
2
-
1
+ import { get } from "jsonpointer";
2
+ //#region src/proteus-document/getProteusValue.ts
3
3
  function getProteusValue(data, element, parentPath) {
4
- try {
5
- const value = get(
6
- data,
7
- element.path.startsWith("/") ? element.path : element.path ? `${parentPath}/${element.path}` : parentPath
8
- );
9
- if (element.formatter) {
10
- return applyFormatter(value, element.formatter);
11
- }
12
- return value;
13
- } catch {
14
- return null;
15
- }
4
+ try {
5
+ const value = get(data, element.path.startsWith("/") ? element.path : element.path ? `${parentPath}/${element.path}` : parentPath);
6
+ if (element.formatter) return applyFormatter(value, element.formatter);
7
+ return value;
8
+ } catch {
9
+ return null;
10
+ }
16
11
  }
17
12
  const formatters = {
18
- DateTime: (value, options) => {
19
- if (typeof value === "number" || typeof value === "string") {
20
- return new Intl.DateTimeFormat(void 0, {
21
- day: "numeric",
22
- month: "short",
23
- ...options
24
- }).format(new Date(value));
25
- }
26
- return value;
27
- },
28
- Number: (value, options) => {
29
- const num = typeof value === "number" ? value : typeof value === "string" && value !== "" ? Number(value) : NaN;
30
- if (!Number.isNaN(num)) {
31
- return new Intl.NumberFormat(void 0, options).format(num);
32
- }
33
- return value;
34
- }
13
+ DateTime: (value, options) => {
14
+ if (typeof value === "number" || typeof value === "string") return new Intl.DateTimeFormat(void 0, {
15
+ day: "numeric",
16
+ month: "short",
17
+ ...options
18
+ }).format(new Date(value));
19
+ return value;
20
+ },
21
+ Number: (value, options) => {
22
+ const num = typeof value === "number" ? value : typeof value === "string" && value !== "" ? Number(value) : NaN;
23
+ if (!Number.isNaN(num)) return new Intl.NumberFormat(void 0, options).format(num);
24
+ return value;
25
+ }
35
26
  };
36
27
  function applyFormatter(value, formatter) {
37
- const key = typeof formatter === "string" ? formatter : formatter.type;
38
- const fn = formatters[key];
39
- if (!fn) {
40
- return value;
41
- }
42
- const options = typeof formatter === "string" ? void 0 : formatter.options;
43
- if (Array.isArray(value)) {
44
- return value.map((v) => fn(v, options));
45
- }
46
- return fn(value, options);
28
+ const fn = formatters[typeof formatter === "string" ? formatter : formatter.type];
29
+ if (!fn) return value;
30
+ const options = typeof formatter === "string" ? void 0 : formatter.options;
31
+ if (Array.isArray(value)) return value.map((v) => fn(v, options));
32
+ return fn(value, options);
47
33
  }
48
-
34
+ //#endregion
49
35
  export { applyFormatter, getProteusValue };
@@ -1,53 +1,35 @@
1
1
  "use client";
2
- import { jsx } from 'react/jsx-runtime';
3
- import { ProteusElement } from '../proteus-element/ProteusElement.js';
4
- import { getProteusValue } from './getProteusValue.js';
5
- import { evaluateCondition } from './resolveProteusValue.js';
6
-
2
+ import { getProteusValue } from "./getProteusValue.js";
3
+ import { evaluateCondition } from "./resolveProteusValue.js";
4
+ import { ProteusElement } from "../proteus-element/ProteusElement.js";
5
+ import { jsx } from "react/jsx-runtime";
6
+ //#region src/proteus-document/resolveProteusProp.tsx
7
7
  function resolveProteusProp(value, data, parentPath, mapIndices = []) {
8
- if (typeof value !== "object" || value === null) {
9
- return value;
10
- }
11
- if ("$type" in value && value.$type === "MapIndex") {
12
- return mapIndices.at(-1);
13
- }
14
- if ("$type" in value && value.$type === "Value" && "path" in value && typeof value.path === "string") {
15
- return getProteusValue(
16
- data,
17
- value,
18
- parentPath
19
- );
20
- }
21
- if ("$type" in value && value.$type === "Zip" && "sources" in value) {
22
- const sources = value.sources;
23
- const resolved = {};
24
- let length = 0;
25
- for (const [k, v] of Object.entries(sources)) {
26
- const arr = resolveProteusProp(v, data, parentPath, mapIndices);
27
- if (Array.isArray(arr)) {
28
- resolved[k] = arr;
29
- length = Math.max(length, arr.length);
30
- }
31
- }
32
- return Array.from({ length }, (_, i) => {
33
- const row = {};
34
- for (const [k, arr] of Object.entries(resolved)) {
35
- row[k] = arr[i];
36
- }
37
- return row;
38
- });
39
- }
40
- if ("$type" in value && value.$type === "Show" && "when" in value && "children" in value) {
41
- const conditions = Array.isArray(value.when) ? value.when : [value.when];
42
- const shouldShow = conditions.every(
43
- (condition) => evaluateCondition(condition, data, parentPath, mapIndices)
44
- );
45
- if (!shouldShow) {
46
- return void 0;
47
- }
48
- return resolveProteusProp(value.children, data, parentPath, mapIndices);
49
- }
50
- return "$type" in value || Array.isArray(value) && value.some((v) => v && typeof v === "object" && "$type" in v) ? /* @__PURE__ */ jsx(ProteusElement, { element: value }) : value;
8
+ if (typeof value !== "object" || value === null) return value;
9
+ if ("$type" in value && value.$type === "MapIndex") return mapIndices.at(-1);
10
+ if ("$type" in value && value.$type === "Value" && "path" in value && typeof value.path === "string") return getProteusValue(data, value, parentPath);
11
+ if ("$type" in value && value.$type === "Zip" && "sources" in value) {
12
+ const sources = value.sources;
13
+ const resolved = {};
14
+ let length = 0;
15
+ for (const [k, v] of Object.entries(sources)) {
16
+ const arr = resolveProteusProp(v, data, parentPath, mapIndices);
17
+ if (Array.isArray(arr)) {
18
+ resolved[k] = arr;
19
+ length = Math.max(length, arr.length);
20
+ }
21
+ }
22
+ return Array.from({ length }, (_, i) => {
23
+ const row = {};
24
+ for (const [k, arr] of Object.entries(resolved)) row[k] = arr[i];
25
+ return row;
26
+ });
27
+ }
28
+ if ("$type" in value && value.$type === "Show" && "when" in value && "children" in value) {
29
+ if (!(Array.isArray(value.when) ? value.when : [value.when]).every((condition) => evaluateCondition(condition, data, parentPath, mapIndices))) return;
30
+ return resolveProteusProp(value.children, data, parentPath, mapIndices);
31
+ }
32
+ return "$type" in value || Array.isArray(value) && value.some((v) => v && typeof v === "object" && "$type" in v) ? /* @__PURE__ */ jsx(ProteusElement, { element: value }) : value;
51
33
  }
52
-
34
+ //#endregion
53
35
  export { resolveProteusProp };