@fuma-content/studio 1.0.3 → 1.0.4
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/build/client/assets/{QueryClientProvider-Cys2v_1v.js → QueryClientProvider-BFSUF51X.js} +1 -1
- package/build/client/assets/actions-ByenKsIt.js +1 -0
- package/build/client/assets/actions-ClHPL1CP.js +1 -0
- package/build/client/assets/badge-BnhEE6iu.js +1 -0
- package/build/client/assets/{client-Cfd36Zz-.js → client-BEKU4RIg.js} +146 -146
- package/build/client/assets/client-DBU2dkUR.js +1 -0
- package/build/client/assets/client-DvwvjHta.js +1 -0
- package/build/client/assets/client-wd2sce2I.js +8 -0
- package/build/client/assets/dropdown-menu-By_XeFX4.js +1 -0
- package/build/client/assets/entry.rsc-J_U0YQEr.js +1 -0
- package/build/client/assets/{index-DL539Bhx.js → index-B5GacMxj.js} +1 -1
- package/build/client/assets/index-BTaHNKf7.js +1 -0
- package/build/client/assets/index-BgFxGtat.js +1 -0
- package/build/client/assets/index-CG_0cSZQ.js +1 -0
- package/build/client/assets/index-CfCSvolS.js +1 -0
- package/build/client/assets/{index-C37mbJ0i.js → index-D8KuzOxG.js} +1 -1
- package/build/client/assets/index-DrT4Adhh.js +41 -0
- package/build/client/assets/{index-DXHuzvfN.js → index-El_a1Yhs.js} +1 -1
- package/build/client/assets/index-QYLIz8qa.js +1 -0
- package/build/client/assets/layout-BPVd8vtW.js +1 -0
- package/build/client/assets/{mdx-CehodSrM.js → mdx-DBJIR6uw.js} +1 -1
- package/build/client/assets/page-BJL5nvn-.js +1 -0
- package/build/client/assets/page-eyuUZvVn.js +1 -0
- package/build/client/assets/popover-BowiFsDm.js +1 -0
- package/build/client/assets/{react-D58ornpH.js → react-CzFdRS7Y.js} +7 -7
- package/build/client/assets/root-7fvd-0uP.js +1 -0
- package/build/client/assets/root-B0B6-NU5.css +1 -0
- package/build/client/assets/{root-CNcQf1GA.js → root-jg-0qm8s.js} +1 -1
- package/build/client/assets/route-BLLsZ_zO.js +1 -0
- package/build/client/assets/{router-XCTsiXqQ.js → router-QEl8O8lm.js} +1 -1
- package/build/client/assets/select-BI356bZ1.js +1 -0
- package/build/client/assets/separator-0kwG7IIM.js +1 -0
- package/build/client/assets/sidebar-ByyQE2QS.js +12 -0
- package/build/client/assets/{site-header-1Aor7-g4.js → site-header-iBpA4Sim.js} +1 -1
- package/build/client/assets/spinner-D35u7i0p.js +1 -0
- package/build/client/assets/tooltip-v-_I4rCw.js +16 -0
- package/build/client/assets/use-sync-yCWvjE_m.js +2 -0
- package/build/client/assets/{yaml-DUnUkeX8.js → yaml-BnQf_2Zt.js} +1 -1
- package/build/server/__ssr_build/__vite_rsc_assets_manifest.js +213 -133
- package/build/server/__ssr_build/assets/{actions-DLZnfFzU.js → actions-C5Kv8XYU.js} +2 -2
- package/build/server/__ssr_build/assets/{actions-D6dLhck1.js → actions-DQIBBM15.js} +4 -4
- package/build/server/__ssr_build/assets/{badge-CH6ntch2.js → badge-B48L9yYO.js} +1 -1
- package/build/server/__ssr_build/assets/{client-C-WcMcGh.js → client-AuWNsacU.js} +3 -3
- package/build/server/__ssr_build/assets/client-BHaLyky8.js +1162 -0
- package/build/server/__ssr_build/assets/{client-DX-wDNer.js → client-BogEWrwz.js} +9 -5
- package/build/server/__ssr_build/assets/{client-JNaR8Jey.js → client-DXOHI3cC.js} +2808 -4397
- package/build/server/__ssr_build/assets/{dropdown-menu-gcIcDMHP.js → dropdown-menu-CnDgV_JY.js} +7 -9
- package/build/server/__ssr_build/assets/{entry.rsc-Cg_DxYkh.js → entry.rsc-aOU-YPkj.js} +1 -1
- package/build/server/__ssr_build/assets/{index-PpqpVA51.js → index-B6ajh-UP.js} +1 -1
- package/build/server/__ssr_build/assets/index-BPd5y8T-.js +76 -0
- package/build/server/__ssr_build/assets/{button-U-KvP9zg.js → index-By9m5mBe.js} +3272 -3175
- package/build/server/__ssr_build/assets/index-Ch7b9Ofo.js +37 -0
- package/build/server/__ssr_build/assets/{index-BJ-AF-IL.js → index-Cw6b1mnl.js} +8 -7
- package/build/server/__ssr_build/assets/{index-BloUStie.js → index-kCa2P0Xn.js} +4 -75
- package/build/server/__ssr_build/assets/{index-CWwW5yWZ.js → index-tFzyztyE.js} +2 -2
- package/build/server/__ssr_build/assets/{layout-B79fq6F-.js → layout-CC-HJHWR.js} +13 -11
- package/build/server/__ssr_build/assets/{mdx-bmeV1kyx.js → mdx-D9VFmsYC.js} +1 -1
- package/build/server/__ssr_build/assets/{page-CxhOzrct.js → page-BVUd9aDy.js} +10 -8
- package/build/server/__ssr_build/assets/{page-DxtKhA1K.js → page-C_wQzy3_.js} +13 -11
- package/build/server/__ssr_build/assets/popover-CzQgoguQ.js +321 -0
- package/build/server/__ssr_build/assets/{root-TWeSpY2W.js → root-BmMc6_zA.js} +1 -1
- package/build/server/__ssr_build/assets/route-CNYc37pV.js +860 -0
- package/build/server/__ssr_build/assets/{spinner-w3Q_wkh3.js → select-B8QQSB6X.js} +10 -25
- package/build/server/__ssr_build/assets/{separator-CKrKBtv4.js → separator-C601eKPH.js} +2 -2
- package/build/server/__ssr_build/assets/{sidebar-DoXmiwf0.js → sidebar-C6fHDjcx.js} +237 -65
- package/build/server/__ssr_build/assets/{site-header-pFjDV73T.js → site-header-Bmsr3a30.js} +2 -2
- package/build/server/__ssr_build/assets/spinner-D5zAJQcS.js +19 -0
- package/build/server/__ssr_build/assets/{tooltip-B2NV0tpS.js → tooltip-B3A57zPO.js} +1211 -1211
- package/build/server/__ssr_build/assets/{use-sync-p_-o0jkt.js → use-sync-DTZgOM1O.js} +29 -1185
- package/build/server/__ssr_build/assets/{yaml-BEdFfhvc.js → yaml-xJU1Ur4O.js} +1 -1
- package/build/server/__ssr_build/index.js +31 -15
- package/build/server/__vite_rsc_assets_manifest.js +213 -133
- package/build/server/assets/{actions-C92yn6jE.js → actions-BbMzIy5J.js} +2 -2
- package/build/server/assets/{actions-CWWFIcb1.js → actions-CjWBMAed.js} +2 -2
- package/build/server/assets/{actions-DZdN0IBq.js → actions-cRzXiMyR.js} +2 -2
- package/build/server/assets/{config-Cb909uq6.js → config-Dka4Bvz4.js} +10 -10
- package/build/server/assets/{layout-CRw_6FCt.js → layout-CIIfFN0v.js} +2 -2
- package/build/server/assets/{page-BfKoQQmw.js → page-pyqagPXb.js} +2 -2
- package/build/server/assets/root-B0B6-NU5.css +1 -0
- package/build/server/assets/{root-BqMNAwvK.js → root-D1ebFoST.js} +1 -1
- package/build/server/assets/{route-DiqCR5uw.js → route-C7QEArEP.js} +13911 -5699
- package/build/server/index.js +40 -15
- package/dist/bin.mjs +4 -4
- package/dist/package.mjs +1 -1
- package/package.json +32 -15
- package/build/client/assets/actions-BIaFztcg.js +0 -1
- package/build/client/assets/actions-Bws1O3FH.js +0 -1
- package/build/client/assets/badge-C70RdDmr.js +0 -1
- package/build/client/assets/button-B0G-joJA.js +0 -41
- package/build/client/assets/client-C814jsdE.js +0 -1
- package/build/client/assets/client-wwp8K9Xz.js +0 -1
- package/build/client/assets/dropdown-menu-Re3QusA0.js +0 -1
- package/build/client/assets/entry.rsc-CdTwhQ3_.js +0 -1
- package/build/client/assets/index-DZ8LIlZu.js +0 -1
- package/build/client/assets/index-DprkZK2S.js +0 -1
- package/build/client/assets/index-UnlOgAz7.js +0 -1
- package/build/client/assets/layout-C5TjiFIx.js +0 -1
- package/build/client/assets/page-CiRIEJz9.js +0 -1
- package/build/client/assets/page-DBIuN_hk.js +0 -1
- package/build/client/assets/root-CbriXo_i.css +0 -1
- package/build/client/assets/root-DJ8qMHCd.js +0 -1
- package/build/client/assets/separator-BDe8wWVP.js +0 -1
- package/build/client/assets/sidebar-DNKkYLTA.js +0 -12
- package/build/client/assets/spinner-O3ZbB6fn.js +0 -1
- package/build/client/assets/tooltip-B4fI3WTO.js +0 -16
- package/build/client/assets/use-sync-CfDyibsS.js +0 -9
- package/build/server/assets/root-CbriXo_i.css +0 -1
- /package/build/server/__ssr_build/assets/{root-BYlluTc0.js → root-S8l7oX7x.js} +0 -0
- /package/build/server/assets/{root-ByROcfN4.js → root-DRYtk85G.js} +0 -0
|
@@ -0,0 +1,1162 @@
|
|
|
1
|
+
import { r as reactExports, j as jsxRuntimeExports } from "../index.js";
|
|
2
|
+
import { S as Select, a as SelectTrigger, b as SelectValue, c as SelectContent, d as SelectItem } from "./select-B8QQSB6X.js";
|
|
3
|
+
import { c as createLucideIcon, b as cn, C as ChevronRight, j as buttonVariants, X } from "./index-By9m5mBe.js";
|
|
4
|
+
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
5
|
+
import { cva } from "class-variance-authority";
|
|
6
|
+
const __iconNode$1 = [
|
|
7
|
+
["path", { d: "M5 12h14", key: "1ays0h" }],
|
|
8
|
+
["path", { d: "M12 5v14", key: "s699le" }]
|
|
9
|
+
];
|
|
10
|
+
const Plus = createLucideIcon("plus", __iconNode$1);
|
|
11
|
+
const __iconNode = [
|
|
12
|
+
["path", { d: "M10 11v6", key: "nco0om" }],
|
|
13
|
+
["path", { d: "M14 11v6", key: "outv1u" }],
|
|
14
|
+
["path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6", key: "miytrc" }],
|
|
15
|
+
["path", { d: "M3 6h18", key: "d0wm0j" }],
|
|
16
|
+
["path", { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2", key: "e791ji" }]
|
|
17
|
+
];
|
|
18
|
+
const Trash2 = createLucideIcon("trash-2", __iconNode);
|
|
19
|
+
function objectGet(obj, key) {
|
|
20
|
+
let cur = obj;
|
|
21
|
+
for (const prop of key) {
|
|
22
|
+
if (typeof cur !== "object" || cur === null || !(prop in cur)) return;
|
|
23
|
+
cur = cur[prop];
|
|
24
|
+
}
|
|
25
|
+
return cur;
|
|
26
|
+
}
|
|
27
|
+
function objectSet(obj, key, value) {
|
|
28
|
+
if (key.length === 0) return value;
|
|
29
|
+
const parent = objectGet(obj, key.slice(0, -1));
|
|
30
|
+
if (typeof parent !== "object" || parent === null) throw new Error("missing parent object");
|
|
31
|
+
parent[key[key.length - 1]] = value;
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
function deepEqual$1(a, b) {
|
|
35
|
+
if (a === b) return true;
|
|
36
|
+
if (a == null || b == null) return false;
|
|
37
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
38
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
39
|
+
if (a.length !== b.length) return false;
|
|
40
|
+
return a.every((item, index) => deepEqual$1(item, b[index]));
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(a) || Array.isArray(b)) return false;
|
|
43
|
+
const keysA = Object.keys(a);
|
|
44
|
+
const keysB = Object.keys(b);
|
|
45
|
+
if (keysA.length !== keysB.length) return false;
|
|
46
|
+
return keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqual$1(a[key], b[key]));
|
|
47
|
+
}
|
|
48
|
+
function stringifyFieldKey(fieldKey) {
|
|
49
|
+
return fieldKey.map((v) => `${typeof v}:${v}`).join(".");
|
|
50
|
+
}
|
|
51
|
+
const Context = reactExports.createContext(null);
|
|
52
|
+
function StfProvider({ value, children }) {
|
|
53
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Context, {
|
|
54
|
+
value,
|
|
55
|
+
children
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function useStf(options) {
|
|
59
|
+
const { defaultValues } = options;
|
|
60
|
+
const dataEngine = reactExports.useMemo(() => new DataEngine(defaultValues), []);
|
|
61
|
+
return reactExports.useMemo(() => ({ dataEngine }), [dataEngine]);
|
|
62
|
+
}
|
|
63
|
+
function useDataEngine(stf) {
|
|
64
|
+
if (stf) return stf.dataEngine;
|
|
65
|
+
return reactExports.use(Context).dataEngine;
|
|
66
|
+
}
|
|
67
|
+
function useArray(field, options = {}) {
|
|
68
|
+
const engine = useDataEngine();
|
|
69
|
+
const [items] = useFieldValue(field, {
|
|
70
|
+
defaultValue: options.defaultValue,
|
|
71
|
+
compute(value) {
|
|
72
|
+
const items$1 = [];
|
|
73
|
+
if (Array.isArray(value)) for (let i = 0; i < value.length; i++) items$1.push({
|
|
74
|
+
field: [...field, i],
|
|
75
|
+
index: i
|
|
76
|
+
});
|
|
77
|
+
return items$1;
|
|
78
|
+
},
|
|
79
|
+
isChanged(prev, next) {
|
|
80
|
+
return prev.length !== next.length;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
items,
|
|
85
|
+
insertItem(itemValue) {
|
|
86
|
+
const value = engine.get(field);
|
|
87
|
+
engine.update(field, Array.isArray(value) ? [...value, itemValue] : [itemValue]);
|
|
88
|
+
},
|
|
89
|
+
removeItem(index) {
|
|
90
|
+
engine.delete([...field, index]);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function useObject(field, options) {
|
|
95
|
+
const engine = useDataEngine();
|
|
96
|
+
const [objectKeys] = useFieldValue(field, {
|
|
97
|
+
defaultValue: options.defaultValue,
|
|
98
|
+
compute(currentValue) {
|
|
99
|
+
return currentValue ? Object.keys(currentValue) : [];
|
|
100
|
+
},
|
|
101
|
+
isChanged(prev, next) {
|
|
102
|
+
return !deepEqual$1(prev, next);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
properties: reactExports.useMemo(() => {
|
|
107
|
+
const properties = [];
|
|
108
|
+
const unknownKeys = new Set(objectKeys);
|
|
109
|
+
for (const [key, prop] of Object.entries(options.properties)) {
|
|
110
|
+
unknownKeys.delete(key);
|
|
111
|
+
properties.push({
|
|
112
|
+
kind: "fixed",
|
|
113
|
+
field: [...field, key],
|
|
114
|
+
key,
|
|
115
|
+
info: prop
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
for (const [pattern, prop] of Object.entries(options.patternProperties ?? {})) {
|
|
119
|
+
const regex = RegExp(pattern);
|
|
120
|
+
for (const key of unknownKeys) {
|
|
121
|
+
if (!key.match(regex)) continue;
|
|
122
|
+
unknownKeys.delete(key);
|
|
123
|
+
properties.push({
|
|
124
|
+
kind: "pattern",
|
|
125
|
+
info: prop,
|
|
126
|
+
key,
|
|
127
|
+
pattern,
|
|
128
|
+
field: [...field, key]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (options.fallback) for (const key of unknownKeys) properties.push({
|
|
133
|
+
kind: "fallback",
|
|
134
|
+
field: [...field, key],
|
|
135
|
+
key,
|
|
136
|
+
info: options.fallback
|
|
137
|
+
});
|
|
138
|
+
return properties;
|
|
139
|
+
}, [
|
|
140
|
+
field,
|
|
141
|
+
objectKeys,
|
|
142
|
+
options.fallback,
|
|
143
|
+
options.patternProperties,
|
|
144
|
+
options.properties
|
|
145
|
+
]),
|
|
146
|
+
onAppend(name, value) {
|
|
147
|
+
name = name.trim();
|
|
148
|
+
if (name.length === 0) return;
|
|
149
|
+
engine.init([...field, name], value);
|
|
150
|
+
},
|
|
151
|
+
onDelete(name) {
|
|
152
|
+
return engine.delete([...field, name]);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function getDefaultValue$1(defaultValue) {
|
|
157
|
+
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
158
|
+
}
|
|
159
|
+
var ListenerManager = class {
|
|
160
|
+
constructor() {
|
|
161
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
162
|
+
this.indexed = /* @__PURE__ */ new Map();
|
|
163
|
+
}
|
|
164
|
+
add(listener) {
|
|
165
|
+
if (!listener.field) {
|
|
166
|
+
this.listeners.add(listener);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const key = stringifyFieldKey(listener.field);
|
|
170
|
+
const set = this.indexed.get(key) ?? /* @__PURE__ */ new Set();
|
|
171
|
+
set.add(listener);
|
|
172
|
+
this.indexed.set(key, set);
|
|
173
|
+
}
|
|
174
|
+
remove(listener) {
|
|
175
|
+
if (!listener.field) this.listeners.delete(listener);
|
|
176
|
+
else this.indexed.get(stringifyFieldKey(listener.field))?.delete(listener);
|
|
177
|
+
}
|
|
178
|
+
onUpdate(field, ctx) {
|
|
179
|
+
for (const v of this.listeners) v.onUpdate?.(field, ctx);
|
|
180
|
+
const updatedKey = stringifyFieldKey(field);
|
|
181
|
+
if (ctx.swallow) {
|
|
182
|
+
const set = this.indexed.get(updatedKey);
|
|
183
|
+
if (set) for (const v of set) v.onUpdate?.(field, ctx);
|
|
184
|
+
} else for (const [k, listeners] of this.indexed.entries()) {
|
|
185
|
+
if (k !== updatedKey && !k.startsWith(updatedKey + ".")) continue;
|
|
186
|
+
for (const v of listeners) v.onUpdate?.(field, ctx);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
onInit(field) {
|
|
190
|
+
for (const v of this.listeners) v.onInit?.(field);
|
|
191
|
+
const set = this.indexed.get(stringifyFieldKey(field));
|
|
192
|
+
if (set) for (const v of set) v.onInit?.(field);
|
|
193
|
+
}
|
|
194
|
+
onDelete(field) {
|
|
195
|
+
for (const v of this.listeners) v.onDelete?.(field);
|
|
196
|
+
const set = this.indexed.get(stringifyFieldKey(field));
|
|
197
|
+
if (set) for (const v of set) v.onDelete?.(field);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var DataEngine = class {
|
|
201
|
+
constructor(defaultValues = {}) {
|
|
202
|
+
this.attachedDataMap = /* @__PURE__ */ new Map();
|
|
203
|
+
this.listeners = new ListenerManager();
|
|
204
|
+
this.data = getDefaultValue$1(defaultValues);
|
|
205
|
+
}
|
|
206
|
+
listen(listener) {
|
|
207
|
+
this.listeners.add(listener);
|
|
208
|
+
}
|
|
209
|
+
unlisten(listener) {
|
|
210
|
+
this.listeners.remove(listener);
|
|
211
|
+
}
|
|
212
|
+
getData() {
|
|
213
|
+
return this.data;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* init a field
|
|
217
|
+
* @param key the key of field
|
|
218
|
+
* @param defaultValue the initial value, the field is also created for `undefined`
|
|
219
|
+
* @returns the value of initialized field, or the current value of field if already initialized
|
|
220
|
+
*/
|
|
221
|
+
init(key, defaultValue) {
|
|
222
|
+
if (key.length === 0) return this.data;
|
|
223
|
+
let cur = this.data;
|
|
224
|
+
const currentKey = [];
|
|
225
|
+
for (let i = 0; i < key.length; i++) {
|
|
226
|
+
const propKey = key[i];
|
|
227
|
+
const propValue = cur[propKey];
|
|
228
|
+
if (i === key.length - 1) {
|
|
229
|
+
if (propValue !== void 0) return propValue;
|
|
230
|
+
cur[propKey] = getDefaultValue$1(defaultValue);
|
|
231
|
+
this.listeners.onUpdate(currentKey, { swallow: true });
|
|
232
|
+
this.listeners.onInit(key);
|
|
233
|
+
return cur[propKey];
|
|
234
|
+
} else if (typeof propValue === "object" && propValue !== null) cur = propValue;
|
|
235
|
+
else {
|
|
236
|
+
if (propValue !== void 0) console.warn(`the original value of field ${currentKey.join(".")} is overidden, this might be unexpected.`);
|
|
237
|
+
cur = cur[propKey] = {};
|
|
238
|
+
this.listeners.onUpdate(currentKey, { swallow: true });
|
|
239
|
+
}
|
|
240
|
+
currentKey.push(propKey);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
delete(key) {
|
|
244
|
+
if (key.length === 0) return;
|
|
245
|
+
const parentKey = key.slice(0, -1);
|
|
246
|
+
const prop = key[key.length - 1];
|
|
247
|
+
const parent = this.get(parentKey);
|
|
248
|
+
if (Array.isArray(parent) && typeof prop === "number") {
|
|
249
|
+
const [deleted] = parent.splice(prop, 1);
|
|
250
|
+
this.listeners.onUpdate(parentKey, { swallow: false });
|
|
251
|
+
this.listeners.onDelete(key);
|
|
252
|
+
return deleted;
|
|
253
|
+
} else if (typeof parent === "object" && parent !== null) {
|
|
254
|
+
const temp = parent[prop];
|
|
255
|
+
delete parent[prop];
|
|
256
|
+
this.listeners.onUpdate(parentKey, { swallow: true });
|
|
257
|
+
this.listeners.onDelete(key);
|
|
258
|
+
return temp;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
get(key) {
|
|
262
|
+
return objectGet(this.data, key);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* update the value of field if it exists
|
|
266
|
+
* @returns if the field is updated
|
|
267
|
+
*/
|
|
268
|
+
update(key, value) {
|
|
269
|
+
try {
|
|
270
|
+
this.data = objectSet(this.data, key, value);
|
|
271
|
+
this.listeners.onUpdate(key, { swallow: false });
|
|
272
|
+
return true;
|
|
273
|
+
} catch {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
attachedData(namespace) {
|
|
278
|
+
return {
|
|
279
|
+
get: (field) => {
|
|
280
|
+
return this.attachedDataMap.get(`${namespace}:${stringifyFieldKey(field)}`);
|
|
281
|
+
},
|
|
282
|
+
set: (field, value) => {
|
|
283
|
+
this.attachedDataMap.set(`${namespace}:${stringifyFieldKey(field)}`, value);
|
|
284
|
+
},
|
|
285
|
+
delete: (field) => {
|
|
286
|
+
if (field) this.attachedDataMap.delete(`${namespace}:${stringifyFieldKey(field)}`);
|
|
287
|
+
else for (const key of this.attachedDataMap.keys()) if (key.startsWith(`${namespace}:`)) this.attachedDataMap.delete(key);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
reset(data) {
|
|
292
|
+
this.update([], data);
|
|
293
|
+
this.attachedDataMap.clear();
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
function useFieldValue(key, options = {}) {
|
|
297
|
+
const engine = useDataEngine(options.stf);
|
|
298
|
+
const { compute = (v) => v, defaultValue, isChanged = (a, b) => a !== b } = options;
|
|
299
|
+
const [value, setValue] = reactExports.useState(() => compute(engine.init(key, defaultValue)));
|
|
300
|
+
useListener({
|
|
301
|
+
field: key,
|
|
302
|
+
onUpdate() {
|
|
303
|
+
const computed = compute(engine.get(key));
|
|
304
|
+
if (isChanged(value, computed)) setValue(computed);
|
|
305
|
+
},
|
|
306
|
+
onDelete() {
|
|
307
|
+
const computed = compute(void 0);
|
|
308
|
+
if (isChanged(value, computed)) setValue(computed);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
return [value, (newValue) => engine.update(key, newValue)];
|
|
312
|
+
}
|
|
313
|
+
function useListener(listener) {
|
|
314
|
+
const engine = useDataEngine(listener.stf);
|
|
315
|
+
const listenerRef = reactExports.useRef(listener);
|
|
316
|
+
listenerRef.current = listener;
|
|
317
|
+
reactExports.useEffect(() => {
|
|
318
|
+
const internal = {
|
|
319
|
+
field: listener.field,
|
|
320
|
+
onDelete(...args) {
|
|
321
|
+
return listenerRef.current.onDelete?.(...args);
|
|
322
|
+
},
|
|
323
|
+
onInit(...args) {
|
|
324
|
+
return listenerRef.current.onInit?.(...args);
|
|
325
|
+
},
|
|
326
|
+
onUpdate(...args) {
|
|
327
|
+
return listenerRef.current.onUpdate?.(...args);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
engine.listen(internal);
|
|
331
|
+
return () => {
|
|
332
|
+
engine.unlisten(internal);
|
|
333
|
+
};
|
|
334
|
+
}, [engine, listener.field]);
|
|
335
|
+
}
|
|
336
|
+
function Input({ className, type, ...props }) {
|
|
337
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
338
|
+
"input",
|
|
339
|
+
{
|
|
340
|
+
type,
|
|
341
|
+
"data-slot": "input",
|
|
342
|
+
className: cn(
|
|
343
|
+
"h-9 w-full min-w-0 rounded-4xl border border-input bg-input/30 px-3 py-1 text-base outline-none transition-colors file:inline-flex file:h-7 file:border-0 file:bg-transparent file:font-medium file:text-foreground file:text-sm placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-[3px] aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
344
|
+
className
|
|
345
|
+
),
|
|
346
|
+
...props
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
function getDefaultValue(schema) {
|
|
351
|
+
if (typeof schema === "boolean") return null;
|
|
352
|
+
const type = schema.type;
|
|
353
|
+
if (Array.isArray(type))
|
|
354
|
+
return getDefaultValue({
|
|
355
|
+
...schema,
|
|
356
|
+
type: type[0]
|
|
357
|
+
});
|
|
358
|
+
if (type === "object" && typeof schema === "object")
|
|
359
|
+
return Object.fromEntries(
|
|
360
|
+
Object.entries(schema.properties ?? {}).map(([key, prop]) => {
|
|
361
|
+
return [key, getDefaultValue(prop)];
|
|
362
|
+
})
|
|
363
|
+
);
|
|
364
|
+
if (type === "array") return [];
|
|
365
|
+
if (type === "null") return null;
|
|
366
|
+
if (type === "string") {
|
|
367
|
+
if (typeof schema === "object" && schema.format === "binary") return void 0;
|
|
368
|
+
return "";
|
|
369
|
+
}
|
|
370
|
+
if (type === "number" || type === "integer") return 0;
|
|
371
|
+
if (type === "boolean") return false;
|
|
372
|
+
}
|
|
373
|
+
var FormatFlags = /* @__PURE__ */ ((FormatFlags2) => {
|
|
374
|
+
FormatFlags2[FormatFlags2["None"] = 0] = "None";
|
|
375
|
+
FormatFlags2[FormatFlags2["UseAlias"] = 1] = "UseAlias";
|
|
376
|
+
return FormatFlags2;
|
|
377
|
+
})(FormatFlags || {});
|
|
378
|
+
function schemaToString(value, flags = 0) {
|
|
379
|
+
function union(union2, sep, flags2) {
|
|
380
|
+
const members = /* @__PURE__ */ new Set();
|
|
381
|
+
let nullable = false;
|
|
382
|
+
for (const item of union2) {
|
|
383
|
+
const result2 = run(
|
|
384
|
+
item,
|
|
385
|
+
flags2 | 1
|
|
386
|
+
/* UseAlias */
|
|
387
|
+
);
|
|
388
|
+
if (result2 === "null") {
|
|
389
|
+
nullable = true;
|
|
390
|
+
} else if (result2 !== "unknown") {
|
|
391
|
+
members.add(result2);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
const result = Array.from(members).join(sep);
|
|
395
|
+
return nullable ? `${result} | null` : result;
|
|
396
|
+
}
|
|
397
|
+
function run(schema, flags2) {
|
|
398
|
+
if (schema === true) return "any";
|
|
399
|
+
else if (schema === false) return "never";
|
|
400
|
+
if ((flags2 & 1) === 1) {
|
|
401
|
+
if (schema.title) return schema.title;
|
|
402
|
+
}
|
|
403
|
+
if (Array.isArray(schema.type)) {
|
|
404
|
+
return union(
|
|
405
|
+
schema.type.map((type) => ({
|
|
406
|
+
...schema,
|
|
407
|
+
type
|
|
408
|
+
})),
|
|
409
|
+
" | ",
|
|
410
|
+
flags2
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
if (schema.type === "array")
|
|
414
|
+
return `array<${schema.items ? run(
|
|
415
|
+
schema.items,
|
|
416
|
+
flags2 | 1
|
|
417
|
+
/* UseAlias */
|
|
418
|
+
) : "unknown"}>`;
|
|
419
|
+
const or = schema.oneOf ?? schema.anyOf;
|
|
420
|
+
if (schema.oneOf && schema.anyOf) {
|
|
421
|
+
return `(${union(schema.oneOf, " | ", flags2)}) & (${union(schema.anyOf, " | ", flags2)})`;
|
|
422
|
+
} else if (or) {
|
|
423
|
+
return union(or, " | ", flags2);
|
|
424
|
+
}
|
|
425
|
+
if (schema.allOf) {
|
|
426
|
+
return union(schema.allOf, " & ", flags2);
|
|
427
|
+
}
|
|
428
|
+
if (schema.not) return `not ${run(schema.not, flags2)}`;
|
|
429
|
+
if (schema.type === "string" && schema.format === "binary") return "file";
|
|
430
|
+
if (schema.type && Array.isArray(schema.type)) {
|
|
431
|
+
return schema.type.filter((v) => v !== "null").join(" | ");
|
|
432
|
+
}
|
|
433
|
+
if (schema.type) {
|
|
434
|
+
return schema.type;
|
|
435
|
+
}
|
|
436
|
+
return "unknown";
|
|
437
|
+
}
|
|
438
|
+
return run(value, flags);
|
|
439
|
+
}
|
|
440
|
+
function deepEqual(a, b) {
|
|
441
|
+
if (a === b) {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
if (a == null || b == null) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
451
|
+
if (a.length !== b.length) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
return a.every((item, index) => deepEqual(item, b[index]));
|
|
455
|
+
}
|
|
456
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
const keysA = Object.keys(a);
|
|
460
|
+
const keysB = Object.keys(b);
|
|
461
|
+
if (keysA.length !== keysB.length) {
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
return keysA.every(
|
|
465
|
+
(key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqual(a[key], b[key])
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
function mergeAllOf(schema) {
|
|
469
|
+
if (typeof schema === "boolean" || !schema.allOf) return schema;
|
|
470
|
+
const { allOf, ...rest } = schema;
|
|
471
|
+
let result = rest;
|
|
472
|
+
for (const item of allOf) {
|
|
473
|
+
result = intersection(result, item);
|
|
474
|
+
}
|
|
475
|
+
return result;
|
|
476
|
+
}
|
|
477
|
+
function intersection(a, b) {
|
|
478
|
+
a = mergeAllOf(a);
|
|
479
|
+
b = mergeAllOf(b);
|
|
480
|
+
if (typeof a === "boolean" && typeof b === "boolean") return a && b;
|
|
481
|
+
if (typeof a === "boolean") return a;
|
|
482
|
+
if (typeof b === "boolean") return b;
|
|
483
|
+
const result = { ...a };
|
|
484
|
+
for (const _k in b) {
|
|
485
|
+
const key = _k;
|
|
486
|
+
switch (key) {
|
|
487
|
+
case "$id":
|
|
488
|
+
case "$comment":
|
|
489
|
+
case "description":
|
|
490
|
+
case "additionalItems":
|
|
491
|
+
case "examples":
|
|
492
|
+
case "allOf":
|
|
493
|
+
case "writeOnly":
|
|
494
|
+
case "readOnly":
|
|
495
|
+
break;
|
|
496
|
+
case "title": {
|
|
497
|
+
const value = b[key];
|
|
498
|
+
if (value === void 0) break;
|
|
499
|
+
if (result[key]) {
|
|
500
|
+
result[key] = `${result[key]} & ${value}`;
|
|
501
|
+
} else {
|
|
502
|
+
result[key] = value;
|
|
503
|
+
}
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
case "minItems":
|
|
507
|
+
case "minimum":
|
|
508
|
+
case "exclusiveMinimum":
|
|
509
|
+
case "minProperties":
|
|
510
|
+
case "minContains":
|
|
511
|
+
case "minLength": {
|
|
512
|
+
const value = b[key];
|
|
513
|
+
if (value === void 0) break;
|
|
514
|
+
result[key] = result[key] === void 0 ? value : Math.max(result[key], value);
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
case "maxContains":
|
|
518
|
+
case "maxItems":
|
|
519
|
+
case "maxLength":
|
|
520
|
+
case "maxProperties":
|
|
521
|
+
case "maximum":
|
|
522
|
+
case "exclusiveMaximum": {
|
|
523
|
+
const value = b[key];
|
|
524
|
+
if (value === void 0) break;
|
|
525
|
+
result[key] = result[key] === void 0 ? value : Math.min(result[key], value);
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
// intersection
|
|
529
|
+
case "enum":
|
|
530
|
+
case "anyOf":
|
|
531
|
+
case "oneOf": {
|
|
532
|
+
const value = b[key];
|
|
533
|
+
if (value === void 0) break;
|
|
534
|
+
result[key] = result[key] === void 0 ? value : intersectArray(result[key], value);
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
// require same
|
|
538
|
+
case "format":
|
|
539
|
+
case "const":
|
|
540
|
+
case "type": {
|
|
541
|
+
const value = b[key];
|
|
542
|
+
if (value === void 0) break;
|
|
543
|
+
result[key] ??= value;
|
|
544
|
+
if (!deepEqual(result[key], value)) return false;
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
// add
|
|
548
|
+
case "required": {
|
|
549
|
+
const value = b[key];
|
|
550
|
+
if (value === void 0) break;
|
|
551
|
+
result[key] = [...result[key] ?? [], ...value];
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
case "properties":
|
|
555
|
+
case "patternProperties": {
|
|
556
|
+
const value = b[key];
|
|
557
|
+
if (value === void 0) break;
|
|
558
|
+
if (result[key] === void 0) {
|
|
559
|
+
result[key] = value;
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
const out = {};
|
|
563
|
+
const allProps = /* @__PURE__ */ new Set();
|
|
564
|
+
for (const k in result[key]) allProps.add(k);
|
|
565
|
+
for (const k in value) allProps.add(k);
|
|
566
|
+
for (const prop of allProps) {
|
|
567
|
+
const aProp = result[key][prop];
|
|
568
|
+
const bProp = value[prop];
|
|
569
|
+
if (aProp === void 0) {
|
|
570
|
+
out[prop] = bProp;
|
|
571
|
+
} else if (bProp === void 0) {
|
|
572
|
+
out[prop] = aProp;
|
|
573
|
+
} else {
|
|
574
|
+
out[prop] = intersection(aProp, bProp);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
result[key] = out;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
case "additionalProperties":
|
|
581
|
+
case "contains":
|
|
582
|
+
case "items": {
|
|
583
|
+
const value = b[key];
|
|
584
|
+
if (value === void 0) break;
|
|
585
|
+
result[key] = result[key] === void 0 ? value : intersection(result[key], value);
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
case "not": {
|
|
589
|
+
const value = b[key];
|
|
590
|
+
if (value === void 0) break;
|
|
591
|
+
if (result[key] && value) {
|
|
592
|
+
result.not = { anyOf: [result[key], value] };
|
|
593
|
+
} else if (value) {
|
|
594
|
+
result.not = value;
|
|
595
|
+
}
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
default:
|
|
599
|
+
result[key] = b[key];
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return result;
|
|
603
|
+
}
|
|
604
|
+
function intersectArray(a, b) {
|
|
605
|
+
const out = /* @__PURE__ */ new Set();
|
|
606
|
+
for (const item of a) {
|
|
607
|
+
if (b.includes(item)) out.add(item);
|
|
608
|
+
}
|
|
609
|
+
for (const item of b) {
|
|
610
|
+
if (a.includes(item)) out.add(item);
|
|
611
|
+
}
|
|
612
|
+
return Array.from(out);
|
|
613
|
+
}
|
|
614
|
+
const SchemaContext = reactExports.createContext(void 0);
|
|
615
|
+
const anyFields = {
|
|
616
|
+
type: ["string", "number", "boolean", "array", "object"],
|
|
617
|
+
items: true,
|
|
618
|
+
additionalProperties: true
|
|
619
|
+
};
|
|
620
|
+
function SchemaProvider({
|
|
621
|
+
schema,
|
|
622
|
+
children
|
|
623
|
+
}) {
|
|
624
|
+
const ajv = reactExports.useMemo(
|
|
625
|
+
() => new Ajv2020({
|
|
626
|
+
strict: false,
|
|
627
|
+
validateSchema: false,
|
|
628
|
+
validateFormats: false,
|
|
629
|
+
schemas: [schema]
|
|
630
|
+
}),
|
|
631
|
+
[schema]
|
|
632
|
+
);
|
|
633
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(SchemaContext.Provider, { value: reactExports.useMemo(() => ({ schema, ajv }), [schema, ajv]), children });
|
|
634
|
+
}
|
|
635
|
+
function useFieldInfo(fieldName, schema) {
|
|
636
|
+
const { ajv } = reactExports.use(SchemaContext);
|
|
637
|
+
const engine = useDataEngine();
|
|
638
|
+
const attachedData = engine.attachedData("field-info");
|
|
639
|
+
const [info, setInfo] = reactExports.useState(() => {
|
|
640
|
+
const value = engine.get(fieldName);
|
|
641
|
+
const initialInfo = attachedData.get(fieldName);
|
|
642
|
+
if (initialInfo) return initialInfo;
|
|
643
|
+
const out = {
|
|
644
|
+
oneOf: -1
|
|
645
|
+
};
|
|
646
|
+
const union = getUnion(schema);
|
|
647
|
+
if (union) {
|
|
648
|
+
const [members, field] = union;
|
|
649
|
+
out.oneOf = members.findIndex((item) => ajv.validate(item, value));
|
|
650
|
+
if (out.oneOf === -1) out.oneOf = 0;
|
|
651
|
+
out.unionField = field;
|
|
652
|
+
}
|
|
653
|
+
if (Array.isArray(schema.type)) {
|
|
654
|
+
const types = schema.type;
|
|
655
|
+
out.selectedType = types.find((type) => ajv.validate({ ...schema, type }, value)) ?? types.at(0);
|
|
656
|
+
}
|
|
657
|
+
if (schema.allOf) {
|
|
658
|
+
const merged = mergeAllOf(schema);
|
|
659
|
+
if (typeof merged !== "boolean")
|
|
660
|
+
out.intersection = {
|
|
661
|
+
merged
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
return out;
|
|
665
|
+
});
|
|
666
|
+
attachedData.set(fieldName, info);
|
|
667
|
+
return {
|
|
668
|
+
info,
|
|
669
|
+
updateInfo(value) {
|
|
670
|
+
const updated = {
|
|
671
|
+
...info,
|
|
672
|
+
...value
|
|
673
|
+
};
|
|
674
|
+
if (updated.oneOf === info.oneOf && updated.selectedType === info.selectedType) return;
|
|
675
|
+
setInfo(updated);
|
|
676
|
+
let valueSchema = schema;
|
|
677
|
+
if (updated.unionField) {
|
|
678
|
+
valueSchema = schema[updated.unionField][updated.oneOf];
|
|
679
|
+
} else if (updated.selectedType) {
|
|
680
|
+
valueSchema = { ...schema, type: updated.selectedType };
|
|
681
|
+
}
|
|
682
|
+
engine.update(fieldName, getDefaultValue(valueSchema));
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
function useSchemaContext() {
|
|
687
|
+
return reactExports.use(SchemaContext);
|
|
688
|
+
}
|
|
689
|
+
function useResolvedSchema(schema) {
|
|
690
|
+
const { ajv } = reactExports.use(SchemaContext);
|
|
691
|
+
return reactExports.useMemo(() => fallbackAny(dereference(schema, { ajv })), [ajv, schema]);
|
|
692
|
+
}
|
|
693
|
+
function fallbackAny(schema) {
|
|
694
|
+
return typeof schema === "boolean" ? anyFields : schema;
|
|
695
|
+
}
|
|
696
|
+
function getUnion(schema) {
|
|
697
|
+
if (schema.anyOf) {
|
|
698
|
+
return [schema.anyOf, "anyOf"];
|
|
699
|
+
}
|
|
700
|
+
if (schema.oneOf) return [schema.oneOf, "oneOf"];
|
|
701
|
+
}
|
|
702
|
+
function dereference(schema, { ajv }) {
|
|
703
|
+
if (typeof schema === "boolean") return schema;
|
|
704
|
+
if (schema.$ref) return ajv.getSchema(schema.$ref)?.schema ?? false;
|
|
705
|
+
return schema;
|
|
706
|
+
}
|
|
707
|
+
const labelVariants = cva(
|
|
708
|
+
"text-xs font-medium text-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
709
|
+
);
|
|
710
|
+
function FieldLabel(props) {
|
|
711
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("label", { ...props, className: cn("w-full inline-flex items-center gap-0.5", props.className), children: props.children });
|
|
712
|
+
}
|
|
713
|
+
function FieldLabelType(props) {
|
|
714
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("code", { ...props, className: cn("text-xs text-muted-foreground", props.className), children: props.children });
|
|
715
|
+
}
|
|
716
|
+
function ObjectInput({
|
|
717
|
+
field: _field,
|
|
718
|
+
fieldName,
|
|
719
|
+
...props
|
|
720
|
+
}) {
|
|
721
|
+
const field = useResolvedSchema(_field);
|
|
722
|
+
const [nextName, setNextName] = reactExports.useState("");
|
|
723
|
+
const { properties, onAppend, onDelete } = useObject(fieldName, {
|
|
724
|
+
defaultValue: () => getDefaultValue(field),
|
|
725
|
+
properties: field.properties ?? {},
|
|
726
|
+
fallback: field.additionalProperties,
|
|
727
|
+
patternProperties: field.patternProperties
|
|
728
|
+
});
|
|
729
|
+
const isDynamic = field.patternProperties ?? field.additionalProperties;
|
|
730
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ...props, className: cn("grid grid-cols-1 gap-4 @md:grid-cols-2", props.className), children: [
|
|
731
|
+
properties.map((child) => {
|
|
732
|
+
let toolbar = null;
|
|
733
|
+
if (child.kind === "pattern" || child.kind === "fallback") {
|
|
734
|
+
toolbar = /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
735
|
+
"button",
|
|
736
|
+
{
|
|
737
|
+
type: "button",
|
|
738
|
+
"aria-label": "Remove Item",
|
|
739
|
+
className: cn(
|
|
740
|
+
buttonVariants({
|
|
741
|
+
variant: "outline",
|
|
742
|
+
size: "icon-xs"
|
|
743
|
+
})
|
|
744
|
+
),
|
|
745
|
+
onClick: () => {
|
|
746
|
+
onDelete(child.key);
|
|
747
|
+
},
|
|
748
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx(Trash2, {})
|
|
749
|
+
}
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
753
|
+
FieldSet,
|
|
754
|
+
{
|
|
755
|
+
name: child.key,
|
|
756
|
+
field: child.info,
|
|
757
|
+
fieldName: child.field,
|
|
758
|
+
isRequired: field.required?.includes(child.key),
|
|
759
|
+
toolbar
|
|
760
|
+
},
|
|
761
|
+
child.key
|
|
762
|
+
);
|
|
763
|
+
}),
|
|
764
|
+
isDynamic && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-2 col-span-full", children: [
|
|
765
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
766
|
+
Input,
|
|
767
|
+
{
|
|
768
|
+
value: nextName,
|
|
769
|
+
placeholder: "Enter Property Name",
|
|
770
|
+
onChange: (e) => setNextName(e.target.value),
|
|
771
|
+
onKeyDown: (e) => {
|
|
772
|
+
if (e.key === "Enter") {
|
|
773
|
+
setNextName("");
|
|
774
|
+
onAppend(nextName);
|
|
775
|
+
e.preventDefault();
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
),
|
|
780
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
781
|
+
"button",
|
|
782
|
+
{
|
|
783
|
+
type: "button",
|
|
784
|
+
className: cn(buttonVariants({ variant: "secondary", size: "sm" }), "px-4"),
|
|
785
|
+
onClick: () => {
|
|
786
|
+
onAppend(nextName);
|
|
787
|
+
setNextName("");
|
|
788
|
+
},
|
|
789
|
+
children: "New"
|
|
790
|
+
}
|
|
791
|
+
)
|
|
792
|
+
] })
|
|
793
|
+
] });
|
|
794
|
+
}
|
|
795
|
+
function FieldInput({
|
|
796
|
+
field,
|
|
797
|
+
fieldName,
|
|
798
|
+
isRequired,
|
|
799
|
+
...props
|
|
800
|
+
}) {
|
|
801
|
+
const engine = useDataEngine();
|
|
802
|
+
const [value, setValue] = useFieldValue(fieldName);
|
|
803
|
+
const id = stringifyFieldKey(fieldName);
|
|
804
|
+
if (field.type === "null") return;
|
|
805
|
+
function renderUnset(children) {
|
|
806
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ...props, className: cn("flex flex-row gap-2", props.className), children: [
|
|
807
|
+
children,
|
|
808
|
+
value !== void 0 && !isRequired && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
809
|
+
"button",
|
|
810
|
+
{
|
|
811
|
+
type: "button",
|
|
812
|
+
onClick: () => engine.delete(fieldName),
|
|
813
|
+
className: "text-muted-foreground",
|
|
814
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx(X, { className: "size-4" })
|
|
815
|
+
}
|
|
816
|
+
)
|
|
817
|
+
] });
|
|
818
|
+
}
|
|
819
|
+
if (field.enum && field.enum.length > 0) {
|
|
820
|
+
const idx = field.enum.indexOf(value);
|
|
821
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(Select, { value: String(idx), onValueChange: (v) => setValue(field.enum[Number(v)]), children: [
|
|
822
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectTrigger, { id, ...props, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectValue, {}) }),
|
|
823
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(SelectContent, { children: [
|
|
824
|
+
field.enum.map((item, i) => /* @__PURE__ */ jsxRuntimeExports.jsx(SelectItem, { value: String(i), children: typeof item === "string" ? item : JSON.stringify(item, null, 2) }, i)),
|
|
825
|
+
!isRequired && /* @__PURE__ */ jsxRuntimeExports.jsx(SelectItem, { value: "-1", children: "Unset" })
|
|
826
|
+
] })
|
|
827
|
+
] });
|
|
828
|
+
}
|
|
829
|
+
if (field.type === "boolean") {
|
|
830
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
831
|
+
Select,
|
|
832
|
+
{
|
|
833
|
+
value: String(value),
|
|
834
|
+
onValueChange: (value2) => setValue(value2 === "undefined" ? void 0 : value2 === "true"),
|
|
835
|
+
children: [
|
|
836
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectTrigger, { id, ...props, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectValue, {}) }),
|
|
837
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(SelectContent, { children: [
|
|
838
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectItem, { value: "true", children: "True" }),
|
|
839
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectItem, { value: "false", children: "False" }),
|
|
840
|
+
!isRequired && /* @__PURE__ */ jsxRuntimeExports.jsx(SelectItem, { value: "undefined", children: "Unset" })
|
|
841
|
+
] })
|
|
842
|
+
]
|
|
843
|
+
}
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
if (field.type === "integer" || field.type === "number") {
|
|
847
|
+
return renderUnset(
|
|
848
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
849
|
+
Input,
|
|
850
|
+
{
|
|
851
|
+
id,
|
|
852
|
+
placeholder: "Enter value",
|
|
853
|
+
type: "number",
|
|
854
|
+
step: field.type === "integer" ? 1 : void 0,
|
|
855
|
+
value: String(value ?? ""),
|
|
856
|
+
onChange: (e) => setValue(Number.isNaN(e.target.valueAsNumber) ? void 0 : e.target.valueAsNumber)
|
|
857
|
+
}
|
|
858
|
+
)
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
if (field.type === "string" && field.format === "binary") {
|
|
862
|
+
return renderUnset(
|
|
863
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
864
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
865
|
+
"label",
|
|
866
|
+
{
|
|
867
|
+
htmlFor: id,
|
|
868
|
+
className: cn(
|
|
869
|
+
buttonVariants({
|
|
870
|
+
variant: "secondary",
|
|
871
|
+
className: "w-full h-9 gap-2 truncate"
|
|
872
|
+
})
|
|
873
|
+
),
|
|
874
|
+
children: value instanceof File ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
875
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground text-xs", children: "Selected" }),
|
|
876
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate w-0 flex-1 text-end", children: value.name })
|
|
877
|
+
] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: "Upload" })
|
|
878
|
+
}
|
|
879
|
+
),
|
|
880
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
881
|
+
"input",
|
|
882
|
+
{
|
|
883
|
+
id,
|
|
884
|
+
type: "file",
|
|
885
|
+
multiple: false,
|
|
886
|
+
onChange: (e) => {
|
|
887
|
+
if (!e.target.files || e.target.files.length === 0) return;
|
|
888
|
+
setValue(e.target.files.item(0));
|
|
889
|
+
},
|
|
890
|
+
hidden: true
|
|
891
|
+
}
|
|
892
|
+
)
|
|
893
|
+
] })
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
return renderUnset(
|
|
897
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
898
|
+
Input,
|
|
899
|
+
{
|
|
900
|
+
id,
|
|
901
|
+
placeholder: "Enter value",
|
|
902
|
+
type: field.format === "date" ? "date" : "text",
|
|
903
|
+
value: String(value ?? ""),
|
|
904
|
+
onChange: (e) => setValue(e.target.value)
|
|
905
|
+
}
|
|
906
|
+
)
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
function FieldSet({
|
|
910
|
+
field: _field,
|
|
911
|
+
fieldName,
|
|
912
|
+
toolbar,
|
|
913
|
+
name,
|
|
914
|
+
isRequired,
|
|
915
|
+
depth = 0,
|
|
916
|
+
slotType,
|
|
917
|
+
collapsible = true,
|
|
918
|
+
...props
|
|
919
|
+
}) {
|
|
920
|
+
const field = useResolvedSchema(_field);
|
|
921
|
+
const [show, setShow] = reactExports.useState(!collapsible);
|
|
922
|
+
const { info, updateInfo } = useFieldInfo(fieldName, field);
|
|
923
|
+
const id = stringifyFieldKey(fieldName);
|
|
924
|
+
const dataEngine = useDataEngine();
|
|
925
|
+
if (_field === false) return;
|
|
926
|
+
function renderLabelTrigger(schema = field) {
|
|
927
|
+
if (!collapsible) return renderLabelName();
|
|
928
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
929
|
+
"button",
|
|
930
|
+
{
|
|
931
|
+
type: "button",
|
|
932
|
+
className: cn(labelVariants(), "inline-flex items-center gap-1 font-mono me-auto"),
|
|
933
|
+
onClick: () => {
|
|
934
|
+
dataEngine.init(fieldName, getDefaultValue(schema));
|
|
935
|
+
setShow((prev) => !prev);
|
|
936
|
+
},
|
|
937
|
+
children: [
|
|
938
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: cn("size-3.5 text-muted-foreground", show && "rotate-90") }),
|
|
939
|
+
name,
|
|
940
|
+
isRequired && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-400/80", children: "*" })
|
|
941
|
+
]
|
|
942
|
+
}
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
function renderLabelName() {
|
|
946
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: cn(labelVariants(), "font-mono me-auto"), children: [
|
|
947
|
+
name,
|
|
948
|
+
isRequired && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-red-400/80 mx-1", children: "*" })
|
|
949
|
+
] });
|
|
950
|
+
}
|
|
951
|
+
if (info.unionField && field[info.unionField]) {
|
|
952
|
+
const union = field[info.unionField];
|
|
953
|
+
const showSelect = union.length > 1;
|
|
954
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
955
|
+
FieldSet,
|
|
956
|
+
{
|
|
957
|
+
...props,
|
|
958
|
+
name,
|
|
959
|
+
fieldName,
|
|
960
|
+
isRequired,
|
|
961
|
+
field: union[info.oneOf],
|
|
962
|
+
depth: depth + 1,
|
|
963
|
+
slotType: showSelect ? false : slotType,
|
|
964
|
+
collapsible,
|
|
965
|
+
toolbar: /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
966
|
+
showSelect && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
967
|
+
"select",
|
|
968
|
+
{
|
|
969
|
+
className: "text-xs font-mono",
|
|
970
|
+
value: info.oneOf,
|
|
971
|
+
onChange: (e) => {
|
|
972
|
+
updateInfo({
|
|
973
|
+
oneOf: Number(e.target.value)
|
|
974
|
+
});
|
|
975
|
+
},
|
|
976
|
+
children: union.map((item, i) => /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: i, className: "bg-popover text-popover-foreground", children: schemaToString(item, FormatFlags.UseAlias) }, i))
|
|
977
|
+
}
|
|
978
|
+
),
|
|
979
|
+
toolbar
|
|
980
|
+
] })
|
|
981
|
+
}
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
if (Array.isArray(field.type)) {
|
|
985
|
+
const showSelect = field.type.length > 1;
|
|
986
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
987
|
+
FieldSet,
|
|
988
|
+
{
|
|
989
|
+
...props,
|
|
990
|
+
name,
|
|
991
|
+
fieldName,
|
|
992
|
+
isRequired,
|
|
993
|
+
field: {
|
|
994
|
+
...field,
|
|
995
|
+
type: info.selectedType
|
|
996
|
+
},
|
|
997
|
+
depth: depth + 1,
|
|
998
|
+
slotType: showSelect ? false : slotType,
|
|
999
|
+
collapsible,
|
|
1000
|
+
toolbar: /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
1001
|
+
showSelect && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1002
|
+
"select",
|
|
1003
|
+
{
|
|
1004
|
+
className: "text-xs font-mono",
|
|
1005
|
+
value: info.selectedType,
|
|
1006
|
+
onChange: (e) => {
|
|
1007
|
+
updateInfo({
|
|
1008
|
+
selectedType: e.target.value
|
|
1009
|
+
});
|
|
1010
|
+
},
|
|
1011
|
+
children: field.type.map((item) => /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: item, className: "bg-popover text-popover-foreground", children: item }, item))
|
|
1012
|
+
}
|
|
1013
|
+
),
|
|
1014
|
+
toolbar
|
|
1015
|
+
] })
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
if (field.type === "object" || info.intersection) {
|
|
1020
|
+
const schema = info.intersection?.merged ?? field;
|
|
1021
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
1022
|
+
"fieldset",
|
|
1023
|
+
{
|
|
1024
|
+
...props,
|
|
1025
|
+
className: cn("flex flex-col gap-1.5 col-span-full @container", props.className),
|
|
1026
|
+
children: [
|
|
1027
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(FieldLabel, { htmlFor: id, children: [
|
|
1028
|
+
renderLabelTrigger(schema),
|
|
1029
|
+
slotType ?? /* @__PURE__ */ jsxRuntimeExports.jsx(FieldLabelType, { children: schemaToString(field) }),
|
|
1030
|
+
toolbar
|
|
1031
|
+
] }),
|
|
1032
|
+
show && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1033
|
+
ObjectInput,
|
|
1034
|
+
{
|
|
1035
|
+
field: schema,
|
|
1036
|
+
fieldName,
|
|
1037
|
+
className: "rounded-lg border bg-card text-card-foreground p-2 shadow-sm"
|
|
1038
|
+
}
|
|
1039
|
+
)
|
|
1040
|
+
]
|
|
1041
|
+
}
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
if (field.type === "array") {
|
|
1045
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("fieldset", { ...props, className: cn("flex flex-col gap-1.5 col-span-full", props.className), children: [
|
|
1046
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(FieldLabel, { htmlFor: id, children: [
|
|
1047
|
+
renderLabelTrigger(),
|
|
1048
|
+
slotType ?? /* @__PURE__ */ jsxRuntimeExports.jsx(FieldLabelType, { children: schemaToString(field) }),
|
|
1049
|
+
toolbar
|
|
1050
|
+
] }),
|
|
1051
|
+
show && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1052
|
+
ArrayInput,
|
|
1053
|
+
{
|
|
1054
|
+
fieldName,
|
|
1055
|
+
items: field.items ?? anyFields,
|
|
1056
|
+
className: "rounded-lg border bg-card text-card-foreground p-2 shadow-sm"
|
|
1057
|
+
}
|
|
1058
|
+
)
|
|
1059
|
+
] });
|
|
1060
|
+
}
|
|
1061
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("fieldset", { ...props, className: cn("flex flex-col gap-1.5", props.className), children: [
|
|
1062
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(FieldLabel, { htmlFor: id, children: [
|
|
1063
|
+
renderLabelName(),
|
|
1064
|
+
slotType ?? /* @__PURE__ */ jsxRuntimeExports.jsx(FieldLabelType, { children: schemaToString(field) }),
|
|
1065
|
+
toolbar
|
|
1066
|
+
] }),
|
|
1067
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(FieldInput, { field, fieldName, isRequired })
|
|
1068
|
+
] });
|
|
1069
|
+
}
|
|
1070
|
+
function ArrayInput({
|
|
1071
|
+
fieldName,
|
|
1072
|
+
items: itemSchema,
|
|
1073
|
+
...props
|
|
1074
|
+
}) {
|
|
1075
|
+
const name = fieldName.at(-1) ?? "";
|
|
1076
|
+
const { items, insertItem, removeItem } = useArray(fieldName, {
|
|
1077
|
+
defaultValue: []
|
|
1078
|
+
});
|
|
1079
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ...props, className: cn("flex flex-col gap-2", props.className), children: [
|
|
1080
|
+
items.map((item) => /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1081
|
+
FieldSet,
|
|
1082
|
+
{
|
|
1083
|
+
name: /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-muted-foreground", children: [
|
|
1084
|
+
name,
|
|
1085
|
+
"[",
|
|
1086
|
+
item.index,
|
|
1087
|
+
"]"
|
|
1088
|
+
] }),
|
|
1089
|
+
field: itemSchema,
|
|
1090
|
+
isRequired: true,
|
|
1091
|
+
fieldName: item.field,
|
|
1092
|
+
toolbar: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1093
|
+
"button",
|
|
1094
|
+
{
|
|
1095
|
+
type: "button",
|
|
1096
|
+
"aria-label": "Remove Item",
|
|
1097
|
+
className: cn(
|
|
1098
|
+
buttonVariants({
|
|
1099
|
+
variant: "outline",
|
|
1100
|
+
size: "icon-xs"
|
|
1101
|
+
})
|
|
1102
|
+
),
|
|
1103
|
+
onClick: () => removeItem(item.index),
|
|
1104
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx(Trash2, {})
|
|
1105
|
+
}
|
|
1106
|
+
)
|
|
1107
|
+
},
|
|
1108
|
+
item.index
|
|
1109
|
+
)),
|
|
1110
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
1111
|
+
"button",
|
|
1112
|
+
{
|
|
1113
|
+
type: "button",
|
|
1114
|
+
className: cn(
|
|
1115
|
+
buttonVariants({
|
|
1116
|
+
variant: "secondary",
|
|
1117
|
+
className: "gap-1.5 py-2",
|
|
1118
|
+
size: "sm"
|
|
1119
|
+
})
|
|
1120
|
+
),
|
|
1121
|
+
onClick: () => {
|
|
1122
|
+
insertItem(getDefaultValue(itemSchema));
|
|
1123
|
+
},
|
|
1124
|
+
children: [
|
|
1125
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Plus, { className: "size-4" }),
|
|
1126
|
+
"New Item"
|
|
1127
|
+
]
|
|
1128
|
+
}
|
|
1129
|
+
)
|
|
1130
|
+
] });
|
|
1131
|
+
}
|
|
1132
|
+
function JSONSchemaEditorProvider({
|
|
1133
|
+
children,
|
|
1134
|
+
defaultValue,
|
|
1135
|
+
onValueChange,
|
|
1136
|
+
...props
|
|
1137
|
+
}) {
|
|
1138
|
+
const stf = useStf({
|
|
1139
|
+
defaultValues: defaultValue
|
|
1140
|
+
});
|
|
1141
|
+
useListener({
|
|
1142
|
+
stf,
|
|
1143
|
+
onUpdate() {
|
|
1144
|
+
onValueChange(stf.dataEngine.getData());
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(StfProvider, { value: stf, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SchemaProvider, { ...props, children }) });
|
|
1148
|
+
}
|
|
1149
|
+
function JSONSchemaEditorContent() {
|
|
1150
|
+
const { schema } = useSchemaContext();
|
|
1151
|
+
const field = useResolvedSchema(schema);
|
|
1152
|
+
if (field.format === "binary") return /* @__PURE__ */ jsxRuntimeExports.jsx(FieldSet, { field, fieldName: [] });
|
|
1153
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(FieldSet, { field, fieldName: [], collapsible: false });
|
|
1154
|
+
}
|
|
1155
|
+
export {
|
|
1156
|
+
Input as I,
|
|
1157
|
+
JSONSchemaEditorProvider as J,
|
|
1158
|
+
Plus as P,
|
|
1159
|
+
Trash2 as T,
|
|
1160
|
+
JSONSchemaEditorContent as a,
|
|
1161
|
+
anyFields as b
|
|
1162
|
+
};
|