@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.
- package/dist/esm/_virtual/_openai-shim-script.js +3 -2
- package/dist/esm/assets/src/proteus-chart/{ProteusChart.css.ts.vanilla-DNE5j3uT.css → ProteusChart.css.ts.vanilla-yGx8JdKz.css} +2 -2
- package/dist/esm/assets/src/proteus-chart/{ProteusChartTooltipContent.css.ts.vanilla-DM8u1icS.css → ProteusChartTooltipContent.css.ts.vanilla-HapBe2oo.css} +2 -2
- package/dist/esm/assets/src/proteus-document/{ProteusDocumentShell.css.ts.vanilla-DjZJuQ2A.css → ProteusDocumentShell.css.ts.vanilla-BPytQ9pT.css} +2 -2
- package/dist/esm/assets/src/proteus-image-carousel/{ProteusImageCarousel.css.ts.vanilla-CIwMJ4Cg.css → ProteusImageCarousel.css.ts.vanilla-DnlXoyv1.css} +2 -2
- package/dist/esm/assets/src/proteus-question/{ProteusQuestion.css.ts.vanilla-DiCe_bxf.css → ProteusQuestion.css.ts.vanilla-CpDgoW0l.css} +2 -2
- package/dist/esm/hooks/useEffectEvent.js +11 -10
- package/dist/esm/hooks/useObserveValue.js +24 -30
- package/dist/esm/icons/IconAngleLeft.js +13 -19
- package/dist/esm/icons/IconAngleRight.js +13 -19
- package/dist/esm/icons/IconX.js +10 -18
- package/dist/esm/icons/withIcon.js +17 -28
- package/dist/esm/index.js +22 -17
- package/dist/esm/proteus-action/ProteusAction.js +44 -39
- package/dist/esm/proteus-bridge/ProteusBridge.js +71 -85
- package/dist/esm/proteus-card-link/ProteusCardLink.js +24 -37
- package/dist/esm/proteus-chart/ProteusChart-css.js +14 -5
- package/dist/esm/proteus-chart/ProteusChart.js +86 -84
- package/dist/esm/proteus-chart/ProteusChartContext.js +3 -3
- package/dist/esm/proteus-chart/ProteusChartTooltipContent-css.js +23 -6
- package/dist/esm/proteus-chart/ProteusChartTooltipContent.js +52 -66
- package/dist/esm/proteus-data-table/ProteusDataTable.js +28 -29
- package/dist/esm/proteus-date-input/ProteusDateInput.js +23 -0
- package/dist/esm/proteus-document/ProteusDocumentContext.js +4 -3
- package/dist/esm/proteus-document/ProteusDocumentPathContext.js +6 -5
- package/dist/esm/proteus-document/ProteusDocumentRenderer.js +25 -33
- package/dist/esm/proteus-document/ProteusDocumentShell-css.js +32 -6
- package/dist/esm/proteus-document/ProteusDocumentShell.js +226 -219
- package/dist/esm/proteus-document/getProteusValue.js +28 -42
- package/dist/esm/proteus-document/resolveProteusProp.js +31 -49
- package/dist/esm/proteus-document/resolveProteusValue.js +73 -136
- package/dist/esm/proteus-document/schemas.js +42 -45
- package/dist/esm/proteus-document/useResolveProteusValues.js +10 -16
- package/dist/esm/proteus-element/ProteusElement.js +114 -180
- package/dist/esm/proteus-federated/ProteusFederated.js +51 -52
- package/dist/esm/proteus-file-icon/ProteusFileIcon.js +29 -38
- package/dist/esm/proteus-file-upload/ProteusFileUpload.js +107 -133
- package/dist/esm/proteus-image/ProteusImage.js +99 -106
- package/dist/esm/proteus-image/downloadFile.js +3 -2
- package/dist/esm/proteus-image-carousel/ProteusImageCarousel-css.js +49 -11
- package/dist/esm/proteus-image-carousel/ProteusImageCarousel.js +151 -163
- package/dist/esm/proteus-input/ProteusInput.js +19 -27
- package/dist/esm/proteus-length/ProteusLength.js +10 -0
- package/dist/esm/proteus-map/ProteusMap.js +18 -31
- package/dist/esm/proteus-map-index/ProteusMapIndex.js +11 -0
- package/dist/esm/proteus-pill-menu/ProteusPillMenu.js +65 -0
- package/dist/esm/proteus-pill-menu/useInputValueChangeInteraction.js +36 -0
- package/dist/esm/proteus-question/ProteusQuestion-css.js +40 -8
- package/dist/esm/proteus-question/ProteusQuestion.js +324 -400
- package/dist/esm/proteus-select/ProteusSelect.js +25 -40
- package/dist/esm/proteus-show/ProteusShow.js +10 -18
- package/dist/esm/proteus-switch/ProteusSwitch.js +33 -36
- package/dist/esm/proteus-textarea/ProteusTextarea.js +18 -27
- package/dist/esm/proteus-value/ProteusValue.js +4 -4
- package/dist/esm/schema/public-schema.js +4537 -0
- package/dist/esm/schema/runtime-schema.js +4460 -0
- package/dist/esm/spec.js +5 -1
- package/dist/esm/use-proteus-value/useProteusValue.js +8 -12
- package/dist/index.d.ts +516 -347
- package/dist/spec.d.ts +5 -9952
- package/package.json +5 -5
- package/dist/esm/icons/IconCalendar.js +0 -20
- package/dist/esm/schema/public-schema.json.js +0 -9041
- package/dist/esm/schema/runtime-schema.json.js +0 -8974
|
@@ -1,223 +1,230 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
function ProteusDocumentShell({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
|
2
|
-
|
|
1
|
+
import { get } from "jsonpointer";
|
|
2
|
+
//#region src/proteus-document/getProteusValue.ts
|
|
3
3
|
function getProteusValue(data, element, parentPath) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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 {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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 };
|