@almadar/ui 2.48.3 → 2.48.5
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/avl/index.cjs +125 -31
- package/dist/avl/index.js +125 -31
- package/dist/components/index.cjs +37 -177
- package/dist/components/index.js +36 -176
- package/dist/components/organisms/game/three/index.cjs +5 -14
- package/dist/components/organisms/game/three/index.js +5 -14
- package/dist/docs/index.cjs +5 -14
- package/dist/docs/index.js +5 -14
- package/dist/hooks/index.cjs +233 -246
- package/dist/hooks/index.js +8 -21
- package/dist/lib/index.cjs +5 -14
- package/dist/lib/index.js +5 -14
- package/dist/marketing/index.cjs +5 -14
- package/dist/marketing/index.js +5 -14
- package/dist/providers/index.cjs +5 -14
- package/dist/providers/index.js +5 -14
- package/dist/runtime/OrbPreview.d.ts +25 -5
- package/dist/runtime/index.cjs +1180 -1788
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +424 -1035
- package/dist/runtime/prepareSchemaForPreview.d.ts +71 -0
- package/package.json +1 -1
package/dist/avl/index.cjs
CHANGED
|
@@ -2866,16 +2866,8 @@ var init_Avl3DLabel = __esm({
|
|
|
2866
2866
|
});
|
|
2867
2867
|
|
|
2868
2868
|
// lib/logger.ts
|
|
2869
|
-
function
|
|
2870
|
-
|
|
2871
|
-
const meta = (0, eval)('typeof import.meta !== "undefined" && import.meta');
|
|
2872
|
-
return meta ? meta.env?.[key] : void 0;
|
|
2873
|
-
} catch {
|
|
2874
|
-
return void 0;
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
function envGet(key, viteKey) {
|
|
2878
|
-
return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
|
|
2869
|
+
function envGet(key) {
|
|
2870
|
+
return ENV[key] ?? ENV[`VITE_${key}`];
|
|
2879
2871
|
}
|
|
2880
2872
|
function matchesNamespace(namespace) {
|
|
2881
2873
|
if (DEBUG_FILTER.length === 0) return true;
|
|
@@ -2914,16 +2906,15 @@ function createLogger(namespace) {
|
|
|
2914
2906
|
error: (msg, data, cid) => log4("ERROR", msg, data, cid)
|
|
2915
2907
|
};
|
|
2916
2908
|
}
|
|
2917
|
-
var LEVEL_PRIORITY, ENV,
|
|
2909
|
+
var LEVEL_PRIORITY, ENV, NODE_ENV, CONFIGURED_LEVEL, MIN_PRIORITY, DEBUG_FILTER;
|
|
2918
2910
|
var init_logger = __esm({
|
|
2919
2911
|
"lib/logger.ts"() {
|
|
2920
2912
|
LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
|
|
2921
2913
|
ENV = typeof process !== "undefined" && process.env ? process.env : {};
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
|
|
2914
|
+
NODE_ENV = envGet("NODE_ENV") ?? "development";
|
|
2915
|
+
CONFIGURED_LEVEL = (envGet("LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
|
|
2925
2916
|
MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
|
|
2926
|
-
DEBUG_FILTER = (envGet("ALMADAR_DEBUG"
|
|
2917
|
+
DEBUG_FILTER = (envGet("ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
2927
2918
|
}
|
|
2928
2919
|
});
|
|
2929
2920
|
function EventBusProvider({ children, debug: debug2 = false }) {
|
|
@@ -47066,6 +47057,97 @@ function ServerBridgeProvider({
|
|
|
47066
47057
|
}, [schema, registerSchema, unregisterSchema]);
|
|
47067
47058
|
return /* @__PURE__ */ jsxRuntime.jsx(ServerBridgeContext.Provider, { value: { connected, sendEvent }, children });
|
|
47068
47059
|
}
|
|
47060
|
+
|
|
47061
|
+
// runtime/prepareSchemaForPreview.ts
|
|
47062
|
+
function generateEntityRow(entity, idx) {
|
|
47063
|
+
const row = { id: String(idx) };
|
|
47064
|
+
for (const f3 of entity.fields) {
|
|
47065
|
+
if (f3.name === "id") continue;
|
|
47066
|
+
row[f3.name] = generateFieldValue(entity.name, f3, idx);
|
|
47067
|
+
}
|
|
47068
|
+
return row;
|
|
47069
|
+
}
|
|
47070
|
+
function generateFieldValue(entityName, field, idx) {
|
|
47071
|
+
if (field.values && field.values.length > 0) {
|
|
47072
|
+
return field.values[(idx - 1) % field.values.length];
|
|
47073
|
+
}
|
|
47074
|
+
switch (field.type) {
|
|
47075
|
+
case "string":
|
|
47076
|
+
return `${entityName} ${field.name.charAt(0).toUpperCase() + field.name.slice(1)} ${idx}`;
|
|
47077
|
+
case "number":
|
|
47078
|
+
return idx * 10;
|
|
47079
|
+
case "boolean":
|
|
47080
|
+
return idx % 2 === 0;
|
|
47081
|
+
default:
|
|
47082
|
+
return field.default ?? null;
|
|
47083
|
+
}
|
|
47084
|
+
}
|
|
47085
|
+
function buildMockData(schema) {
|
|
47086
|
+
const result = {};
|
|
47087
|
+
for (const orbital of schema.orbitals) {
|
|
47088
|
+
const entity = orbital.entity;
|
|
47089
|
+
if (!entity || typeof entity === "string") continue;
|
|
47090
|
+
const entityName = entity.name;
|
|
47091
|
+
if (!entityName) continue;
|
|
47092
|
+
if (entity.instances && entity.instances.length > 0) {
|
|
47093
|
+
result[entityName] = entity.instances;
|
|
47094
|
+
continue;
|
|
47095
|
+
}
|
|
47096
|
+
const rows = Array.from(
|
|
47097
|
+
{ length: 10 },
|
|
47098
|
+
(_, i) => generateEntityRow(entity, i + 1)
|
|
47099
|
+
);
|
|
47100
|
+
result[entityName] = rows;
|
|
47101
|
+
}
|
|
47102
|
+
return result;
|
|
47103
|
+
}
|
|
47104
|
+
function isInlineTrait(traitRef) {
|
|
47105
|
+
return typeof traitRef === "object" && traitRef !== null && "stateMachine" in traitRef;
|
|
47106
|
+
}
|
|
47107
|
+
function findDataState(sm, initialStateName) {
|
|
47108
|
+
return sm.states.find((s) => {
|
|
47109
|
+
if (s.name === initialStateName) return false;
|
|
47110
|
+
return sm.transitions.some(
|
|
47111
|
+
(t) => t.event === "INIT" && (t.from === s.name || Array.isArray(t.from) && t.from.includes(s.name))
|
|
47112
|
+
);
|
|
47113
|
+
});
|
|
47114
|
+
}
|
|
47115
|
+
function rewriteTraitInitialState(trait, mockData) {
|
|
47116
|
+
const sm = trait.stateMachine;
|
|
47117
|
+
if (!sm) return trait;
|
|
47118
|
+
const linkedEntity = trait.linkedEntity;
|
|
47119
|
+
if (!linkedEntity || !mockData[linkedEntity]?.length) return trait;
|
|
47120
|
+
const initialStateName = sm.states.find((s) => s.isInitial)?.name ?? sm.states[0]?.name;
|
|
47121
|
+
if (!initialStateName) return trait;
|
|
47122
|
+
const dataState = findDataState(sm, initialStateName);
|
|
47123
|
+
if (!dataState) return trait;
|
|
47124
|
+
const updatedStates = sm.states.map((s) => {
|
|
47125
|
+
if (s.name === initialStateName) return { ...s, isInitial: false };
|
|
47126
|
+
if (s.name === dataState.name) return { ...s, isInitial: true };
|
|
47127
|
+
return s;
|
|
47128
|
+
});
|
|
47129
|
+
return { ...trait, stateMachine: { ...sm, states: updatedStates } };
|
|
47130
|
+
}
|
|
47131
|
+
function adjustSchemaForMockData(schema, mockData) {
|
|
47132
|
+
let changed = false;
|
|
47133
|
+
const updatedOrbitals = schema.orbitals.map((orbital) => {
|
|
47134
|
+
const traits2 = orbital.traits ?? [];
|
|
47135
|
+
const updatedTraits = traits2.map((traitRef) => {
|
|
47136
|
+
if (!isInlineTrait(traitRef)) return traitRef;
|
|
47137
|
+
const updated = rewriteTraitInitialState(traitRef, mockData);
|
|
47138
|
+
if (updated !== traitRef) changed = true;
|
|
47139
|
+
return updated;
|
|
47140
|
+
});
|
|
47141
|
+
return changed ? { ...orbital, traits: updatedTraits } : orbital;
|
|
47142
|
+
});
|
|
47143
|
+
return changed ? { ...schema, orbitals: updatedOrbitals } : schema;
|
|
47144
|
+
}
|
|
47145
|
+
function prepareSchemaForPreview(input) {
|
|
47146
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
47147
|
+
const mockData = buildMockData(parsed);
|
|
47148
|
+
const schema = adjustSchemaForMockData(parsed, mockData);
|
|
47149
|
+
return { schema, mockData };
|
|
47150
|
+
}
|
|
47069
47151
|
function normalizeChild(child) {
|
|
47070
47152
|
const { type, children, ...rest } = child;
|
|
47071
47153
|
const normalizedChildren = Array.isArray(children) ? children.map((c) => normalizeChild(c)) : children;
|
|
@@ -47220,14 +47302,16 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate }) {
|
|
|
47220
47302
|
const entityStore = useEntityStore();
|
|
47221
47303
|
const seededRef = React125.useRef("");
|
|
47222
47304
|
const mockKey = mockData ? Object.keys(mockData).sort().join(",") : "";
|
|
47223
|
-
|
|
47224
|
-
seededRef.current
|
|
47225
|
-
|
|
47226
|
-
|
|
47227
|
-
|
|
47305
|
+
React125__namespace.default.useLayoutEffect(() => {
|
|
47306
|
+
if (!serverUrl && mockData && seededRef.current !== mockKey) {
|
|
47307
|
+
seededRef.current = mockKey;
|
|
47308
|
+
for (const [entityType, records] of Object.entries(mockData)) {
|
|
47309
|
+
if (Array.isArray(records)) {
|
|
47310
|
+
entityStore.setAll(entityType, records);
|
|
47311
|
+
}
|
|
47228
47312
|
}
|
|
47229
47313
|
}
|
|
47230
|
-
}
|
|
47314
|
+
}, [mockKey, serverUrl, mockData, entityStore]);
|
|
47231
47315
|
const inner = /* @__PURE__ */ jsxRuntime.jsx(VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsxRuntime.jsx(SlotsProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(EntitySchemaProvider, { entities: Array.from(allEntities.values()), children: [
|
|
47232
47316
|
/* @__PURE__ */ jsxRuntime.jsx(TraitInitializer, { traits: allPageTraits, orbitalNames: serverUrl ? orbitalNames : void 0, onNavigate }),
|
|
47233
47317
|
/* @__PURE__ */ jsxRuntime.jsx(SlotBridge, {}),
|
|
@@ -47240,23 +47324,33 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate }) {
|
|
|
47240
47324
|
}
|
|
47241
47325
|
function OrbPreview({
|
|
47242
47326
|
schema,
|
|
47243
|
-
mockData
|
|
47327
|
+
mockData,
|
|
47328
|
+
autoMock = false,
|
|
47244
47329
|
height = "400px",
|
|
47245
47330
|
className,
|
|
47246
47331
|
serverUrl
|
|
47247
47332
|
}) {
|
|
47248
|
-
const
|
|
47333
|
+
const parseResult = React125.useMemo(() => {
|
|
47334
|
+
let parsed;
|
|
47249
47335
|
if (typeof schema === "string") {
|
|
47250
47336
|
try {
|
|
47251
|
-
|
|
47337
|
+
parsed = JSON.parse(schema);
|
|
47252
47338
|
} catch (e) {
|
|
47253
|
-
return { error: String(e) };
|
|
47339
|
+
return { ok: false, error: String(e) };
|
|
47254
47340
|
}
|
|
47341
|
+
} else {
|
|
47342
|
+
parsed = schema;
|
|
47255
47343
|
}
|
|
47256
|
-
|
|
47257
|
-
|
|
47344
|
+
if (autoMock && !serverUrl) {
|
|
47345
|
+
const prepared = prepareSchemaForPreview(parsed);
|
|
47346
|
+
return { ok: true, schema: prepared.schema, mockData: prepared.mockData };
|
|
47347
|
+
}
|
|
47348
|
+
return { ok: true, schema: parsed, mockData: mockData ?? {} };
|
|
47349
|
+
}, [schema, autoMock, serverUrl, mockData]);
|
|
47350
|
+
const parsedSchema = parseResult.ok ? parseResult.schema : null;
|
|
47351
|
+
const effectiveMockData = parseResult.ok ? parseResult.mockData : {};
|
|
47258
47352
|
const pages = React125.useMemo(() => {
|
|
47259
|
-
if (!parsedSchema
|
|
47353
|
+
if (!parsedSchema) return [];
|
|
47260
47354
|
try {
|
|
47261
47355
|
return getAllPages(parsedSchema);
|
|
47262
47356
|
} catch {
|
|
@@ -47270,10 +47364,10 @@ function OrbPreview({
|
|
|
47270
47364
|
setCurrentPage(match.page.name);
|
|
47271
47365
|
}
|
|
47272
47366
|
}, [pages]);
|
|
47273
|
-
if (
|
|
47367
|
+
if (!parseResult.ok) {
|
|
47274
47368
|
return /* @__PURE__ */ jsxRuntime.jsx(Box, { className, style: { height }, children: /* @__PURE__ */ jsxRuntime.jsxs(Typography, { as: "pre", color: "error", variant: "small", className: "font-mono whitespace-pre-wrap break-all m-0 p-4", children: [
|
|
47275
47369
|
"Parse error: ",
|
|
47276
|
-
|
|
47370
|
+
parseResult.error
|
|
47277
47371
|
] }) });
|
|
47278
47372
|
}
|
|
47279
47373
|
const containerRef = React125.useRef(null);
|
|
@@ -47299,7 +47393,7 @@ function OrbPreview({
|
|
|
47299
47393
|
ref: containerRef,
|
|
47300
47394
|
className: `overflow-auto border border-[var(--color-border)] rounded-[var(--radius-md)] ${className ?? ""}`,
|
|
47301
47395
|
style: { height },
|
|
47302
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(OrbitalProvider, { initialData:
|
|
47396
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(OrbitalProvider, { initialData: effectiveMockData, skipTheme: true, verification: true, children: /* @__PURE__ */ jsxRuntime.jsx(UISlotProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(SchemaRunner, { schema: parsedSchema, serverUrl, mockData: effectiveMockData, pageName: currentPage, onNavigate: handleNavigate }) }) })
|
|
47303
47397
|
}
|
|
47304
47398
|
);
|
|
47305
47399
|
}
|
package/dist/avl/index.js
CHANGED
|
@@ -2819,16 +2819,8 @@ var init_Avl3DLabel = __esm({
|
|
|
2819
2819
|
});
|
|
2820
2820
|
|
|
2821
2821
|
// lib/logger.ts
|
|
2822
|
-
function
|
|
2823
|
-
|
|
2824
|
-
const meta = (0, eval)('typeof import.meta !== "undefined" && import.meta');
|
|
2825
|
-
return meta ? meta.env?.[key] : void 0;
|
|
2826
|
-
} catch {
|
|
2827
|
-
return void 0;
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
function envGet(key, viteKey) {
|
|
2831
|
-
return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
|
|
2822
|
+
function envGet(key) {
|
|
2823
|
+
return ENV[key] ?? ENV[`VITE_${key}`];
|
|
2832
2824
|
}
|
|
2833
2825
|
function matchesNamespace(namespace) {
|
|
2834
2826
|
if (DEBUG_FILTER.length === 0) return true;
|
|
@@ -2867,16 +2859,15 @@ function createLogger(namespace) {
|
|
|
2867
2859
|
error: (msg, data, cid) => log4("ERROR", msg, data, cid)
|
|
2868
2860
|
};
|
|
2869
2861
|
}
|
|
2870
|
-
var LEVEL_PRIORITY, ENV,
|
|
2862
|
+
var LEVEL_PRIORITY, ENV, NODE_ENV, CONFIGURED_LEVEL, MIN_PRIORITY, DEBUG_FILTER;
|
|
2871
2863
|
var init_logger = __esm({
|
|
2872
2864
|
"lib/logger.ts"() {
|
|
2873
2865
|
LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
|
|
2874
2866
|
ENV = typeof process !== "undefined" && process.env ? process.env : {};
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
|
|
2867
|
+
NODE_ENV = envGet("NODE_ENV") ?? "development";
|
|
2868
|
+
CONFIGURED_LEVEL = (envGet("LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
|
|
2878
2869
|
MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
|
|
2879
|
-
DEBUG_FILTER = (envGet("ALMADAR_DEBUG"
|
|
2870
|
+
DEBUG_FILTER = (envGet("ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
2880
2871
|
}
|
|
2881
2872
|
});
|
|
2882
2873
|
function EventBusProvider({ children, debug: debug2 = false }) {
|
|
@@ -47019,6 +47010,97 @@ function ServerBridgeProvider({
|
|
|
47019
47010
|
}, [schema, registerSchema, unregisterSchema]);
|
|
47020
47011
|
return /* @__PURE__ */ jsx(ServerBridgeContext.Provider, { value: { connected, sendEvent }, children });
|
|
47021
47012
|
}
|
|
47013
|
+
|
|
47014
|
+
// runtime/prepareSchemaForPreview.ts
|
|
47015
|
+
function generateEntityRow(entity, idx) {
|
|
47016
|
+
const row = { id: String(idx) };
|
|
47017
|
+
for (const f3 of entity.fields) {
|
|
47018
|
+
if (f3.name === "id") continue;
|
|
47019
|
+
row[f3.name] = generateFieldValue(entity.name, f3, idx);
|
|
47020
|
+
}
|
|
47021
|
+
return row;
|
|
47022
|
+
}
|
|
47023
|
+
function generateFieldValue(entityName, field, idx) {
|
|
47024
|
+
if (field.values && field.values.length > 0) {
|
|
47025
|
+
return field.values[(idx - 1) % field.values.length];
|
|
47026
|
+
}
|
|
47027
|
+
switch (field.type) {
|
|
47028
|
+
case "string":
|
|
47029
|
+
return `${entityName} ${field.name.charAt(0).toUpperCase() + field.name.slice(1)} ${idx}`;
|
|
47030
|
+
case "number":
|
|
47031
|
+
return idx * 10;
|
|
47032
|
+
case "boolean":
|
|
47033
|
+
return idx % 2 === 0;
|
|
47034
|
+
default:
|
|
47035
|
+
return field.default ?? null;
|
|
47036
|
+
}
|
|
47037
|
+
}
|
|
47038
|
+
function buildMockData(schema) {
|
|
47039
|
+
const result = {};
|
|
47040
|
+
for (const orbital of schema.orbitals) {
|
|
47041
|
+
const entity = orbital.entity;
|
|
47042
|
+
if (!entity || typeof entity === "string") continue;
|
|
47043
|
+
const entityName = entity.name;
|
|
47044
|
+
if (!entityName) continue;
|
|
47045
|
+
if (entity.instances && entity.instances.length > 0) {
|
|
47046
|
+
result[entityName] = entity.instances;
|
|
47047
|
+
continue;
|
|
47048
|
+
}
|
|
47049
|
+
const rows = Array.from(
|
|
47050
|
+
{ length: 10 },
|
|
47051
|
+
(_, i) => generateEntityRow(entity, i + 1)
|
|
47052
|
+
);
|
|
47053
|
+
result[entityName] = rows;
|
|
47054
|
+
}
|
|
47055
|
+
return result;
|
|
47056
|
+
}
|
|
47057
|
+
function isInlineTrait(traitRef) {
|
|
47058
|
+
return typeof traitRef === "object" && traitRef !== null && "stateMachine" in traitRef;
|
|
47059
|
+
}
|
|
47060
|
+
function findDataState(sm, initialStateName) {
|
|
47061
|
+
return sm.states.find((s) => {
|
|
47062
|
+
if (s.name === initialStateName) return false;
|
|
47063
|
+
return sm.transitions.some(
|
|
47064
|
+
(t) => t.event === "INIT" && (t.from === s.name || Array.isArray(t.from) && t.from.includes(s.name))
|
|
47065
|
+
);
|
|
47066
|
+
});
|
|
47067
|
+
}
|
|
47068
|
+
function rewriteTraitInitialState(trait, mockData) {
|
|
47069
|
+
const sm = trait.stateMachine;
|
|
47070
|
+
if (!sm) return trait;
|
|
47071
|
+
const linkedEntity = trait.linkedEntity;
|
|
47072
|
+
if (!linkedEntity || !mockData[linkedEntity]?.length) return trait;
|
|
47073
|
+
const initialStateName = sm.states.find((s) => s.isInitial)?.name ?? sm.states[0]?.name;
|
|
47074
|
+
if (!initialStateName) return trait;
|
|
47075
|
+
const dataState = findDataState(sm, initialStateName);
|
|
47076
|
+
if (!dataState) return trait;
|
|
47077
|
+
const updatedStates = sm.states.map((s) => {
|
|
47078
|
+
if (s.name === initialStateName) return { ...s, isInitial: false };
|
|
47079
|
+
if (s.name === dataState.name) return { ...s, isInitial: true };
|
|
47080
|
+
return s;
|
|
47081
|
+
});
|
|
47082
|
+
return { ...trait, stateMachine: { ...sm, states: updatedStates } };
|
|
47083
|
+
}
|
|
47084
|
+
function adjustSchemaForMockData(schema, mockData) {
|
|
47085
|
+
let changed = false;
|
|
47086
|
+
const updatedOrbitals = schema.orbitals.map((orbital) => {
|
|
47087
|
+
const traits2 = orbital.traits ?? [];
|
|
47088
|
+
const updatedTraits = traits2.map((traitRef) => {
|
|
47089
|
+
if (!isInlineTrait(traitRef)) return traitRef;
|
|
47090
|
+
const updated = rewriteTraitInitialState(traitRef, mockData);
|
|
47091
|
+
if (updated !== traitRef) changed = true;
|
|
47092
|
+
return updated;
|
|
47093
|
+
});
|
|
47094
|
+
return changed ? { ...orbital, traits: updatedTraits } : orbital;
|
|
47095
|
+
});
|
|
47096
|
+
return changed ? { ...schema, orbitals: updatedOrbitals } : schema;
|
|
47097
|
+
}
|
|
47098
|
+
function prepareSchemaForPreview(input) {
|
|
47099
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
47100
|
+
const mockData = buildMockData(parsed);
|
|
47101
|
+
const schema = adjustSchemaForMockData(parsed, mockData);
|
|
47102
|
+
return { schema, mockData };
|
|
47103
|
+
}
|
|
47022
47104
|
function normalizeChild(child) {
|
|
47023
47105
|
const { type, children, ...rest } = child;
|
|
47024
47106
|
const normalizedChildren = Array.isArray(children) ? children.map((c) => normalizeChild(c)) : children;
|
|
@@ -47173,14 +47255,16 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate }) {
|
|
|
47173
47255
|
const entityStore = useEntityStore();
|
|
47174
47256
|
const seededRef = useRef("");
|
|
47175
47257
|
const mockKey = mockData ? Object.keys(mockData).sort().join(",") : "";
|
|
47176
|
-
|
|
47177
|
-
seededRef.current
|
|
47178
|
-
|
|
47179
|
-
|
|
47180
|
-
|
|
47258
|
+
React125__default.useLayoutEffect(() => {
|
|
47259
|
+
if (!serverUrl && mockData && seededRef.current !== mockKey) {
|
|
47260
|
+
seededRef.current = mockKey;
|
|
47261
|
+
for (const [entityType, records] of Object.entries(mockData)) {
|
|
47262
|
+
if (Array.isArray(records)) {
|
|
47263
|
+
entityStore.setAll(entityType, records);
|
|
47264
|
+
}
|
|
47181
47265
|
}
|
|
47182
47266
|
}
|
|
47183
|
-
}
|
|
47267
|
+
}, [mockKey, serverUrl, mockData, entityStore]);
|
|
47184
47268
|
const inner = /* @__PURE__ */ jsx(VerificationProvider, { enabled: true, children: /* @__PURE__ */ jsx(SlotsProvider, { children: /* @__PURE__ */ jsxs(EntitySchemaProvider, { entities: Array.from(allEntities.values()), children: [
|
|
47185
47269
|
/* @__PURE__ */ jsx(TraitInitializer, { traits: allPageTraits, orbitalNames: serverUrl ? orbitalNames : void 0, onNavigate }),
|
|
47186
47270
|
/* @__PURE__ */ jsx(SlotBridge, {}),
|
|
@@ -47193,23 +47277,33 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate }) {
|
|
|
47193
47277
|
}
|
|
47194
47278
|
function OrbPreview({
|
|
47195
47279
|
schema,
|
|
47196
|
-
mockData
|
|
47280
|
+
mockData,
|
|
47281
|
+
autoMock = false,
|
|
47197
47282
|
height = "400px",
|
|
47198
47283
|
className,
|
|
47199
47284
|
serverUrl
|
|
47200
47285
|
}) {
|
|
47201
|
-
const
|
|
47286
|
+
const parseResult = useMemo(() => {
|
|
47287
|
+
let parsed;
|
|
47202
47288
|
if (typeof schema === "string") {
|
|
47203
47289
|
try {
|
|
47204
|
-
|
|
47290
|
+
parsed = JSON.parse(schema);
|
|
47205
47291
|
} catch (e) {
|
|
47206
|
-
return { error: String(e) };
|
|
47292
|
+
return { ok: false, error: String(e) };
|
|
47207
47293
|
}
|
|
47294
|
+
} else {
|
|
47295
|
+
parsed = schema;
|
|
47208
47296
|
}
|
|
47209
|
-
|
|
47210
|
-
|
|
47297
|
+
if (autoMock && !serverUrl) {
|
|
47298
|
+
const prepared = prepareSchemaForPreview(parsed);
|
|
47299
|
+
return { ok: true, schema: prepared.schema, mockData: prepared.mockData };
|
|
47300
|
+
}
|
|
47301
|
+
return { ok: true, schema: parsed, mockData: mockData ?? {} };
|
|
47302
|
+
}, [schema, autoMock, serverUrl, mockData]);
|
|
47303
|
+
const parsedSchema = parseResult.ok ? parseResult.schema : null;
|
|
47304
|
+
const effectiveMockData = parseResult.ok ? parseResult.mockData : {};
|
|
47211
47305
|
const pages = useMemo(() => {
|
|
47212
|
-
if (!parsedSchema
|
|
47306
|
+
if (!parsedSchema) return [];
|
|
47213
47307
|
try {
|
|
47214
47308
|
return getAllPages(parsedSchema);
|
|
47215
47309
|
} catch {
|
|
@@ -47223,10 +47317,10 @@ function OrbPreview({
|
|
|
47223
47317
|
setCurrentPage(match.page.name);
|
|
47224
47318
|
}
|
|
47225
47319
|
}, [pages]);
|
|
47226
|
-
if (
|
|
47320
|
+
if (!parseResult.ok) {
|
|
47227
47321
|
return /* @__PURE__ */ jsx(Box, { className, style: { height }, children: /* @__PURE__ */ jsxs(Typography, { as: "pre", color: "error", variant: "small", className: "font-mono whitespace-pre-wrap break-all m-0 p-4", children: [
|
|
47228
47322
|
"Parse error: ",
|
|
47229
|
-
|
|
47323
|
+
parseResult.error
|
|
47230
47324
|
] }) });
|
|
47231
47325
|
}
|
|
47232
47326
|
const containerRef = useRef(null);
|
|
@@ -47252,7 +47346,7 @@ function OrbPreview({
|
|
|
47252
47346
|
ref: containerRef,
|
|
47253
47347
|
className: `overflow-auto border border-[var(--color-border)] rounded-[var(--radius-md)] ${className ?? ""}`,
|
|
47254
47348
|
style: { height },
|
|
47255
|
-
children: /* @__PURE__ */ jsx(OrbitalProvider, { initialData:
|
|
47349
|
+
children: /* @__PURE__ */ jsx(OrbitalProvider, { initialData: effectiveMockData, skipTheme: true, verification: true, children: /* @__PURE__ */ jsx(UISlotProvider, { children: /* @__PURE__ */ jsx(SchemaRunner, { schema: parsedSchema, serverUrl, mockData: effectiveMockData, pageName: currentPage, onNavigate: handleNavigate }) }) })
|
|
47256
47350
|
}
|
|
47257
47351
|
);
|
|
47258
47352
|
}
|