@almadar/ui 2.48.4 → 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 +117 -25
- package/dist/avl/index.js +117 -25
- 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 +1173 -1783
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +417 -1030
- 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;
|
|
@@ -47242,23 +47324,33 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate }) {
|
|
|
47242
47324
|
}
|
|
47243
47325
|
function OrbPreview({
|
|
47244
47326
|
schema,
|
|
47245
|
-
mockData
|
|
47327
|
+
mockData,
|
|
47328
|
+
autoMock = false,
|
|
47246
47329
|
height = "400px",
|
|
47247
47330
|
className,
|
|
47248
47331
|
serverUrl
|
|
47249
47332
|
}) {
|
|
47250
|
-
const
|
|
47333
|
+
const parseResult = React125.useMemo(() => {
|
|
47334
|
+
let parsed;
|
|
47251
47335
|
if (typeof schema === "string") {
|
|
47252
47336
|
try {
|
|
47253
|
-
|
|
47337
|
+
parsed = JSON.parse(schema);
|
|
47254
47338
|
} catch (e) {
|
|
47255
|
-
return { error: String(e) };
|
|
47339
|
+
return { ok: false, error: String(e) };
|
|
47256
47340
|
}
|
|
47341
|
+
} else {
|
|
47342
|
+
parsed = schema;
|
|
47257
47343
|
}
|
|
47258
|
-
|
|
47259
|
-
|
|
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 : {};
|
|
47260
47352
|
const pages = React125.useMemo(() => {
|
|
47261
|
-
if (!parsedSchema
|
|
47353
|
+
if (!parsedSchema) return [];
|
|
47262
47354
|
try {
|
|
47263
47355
|
return getAllPages(parsedSchema);
|
|
47264
47356
|
} catch {
|
|
@@ -47272,10 +47364,10 @@ function OrbPreview({
|
|
|
47272
47364
|
setCurrentPage(match.page.name);
|
|
47273
47365
|
}
|
|
47274
47366
|
}, [pages]);
|
|
47275
|
-
if (
|
|
47367
|
+
if (!parseResult.ok) {
|
|
47276
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: [
|
|
47277
47369
|
"Parse error: ",
|
|
47278
|
-
|
|
47370
|
+
parseResult.error
|
|
47279
47371
|
] }) });
|
|
47280
47372
|
}
|
|
47281
47373
|
const containerRef = React125.useRef(null);
|
|
@@ -47301,7 +47393,7 @@ function OrbPreview({
|
|
|
47301
47393
|
ref: containerRef,
|
|
47302
47394
|
className: `overflow-auto border border-[var(--color-border)] rounded-[var(--radius-md)] ${className ?? ""}`,
|
|
47303
47395
|
style: { height },
|
|
47304
|
-
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 }) }) })
|
|
47305
47397
|
}
|
|
47306
47398
|
);
|
|
47307
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;
|
|
@@ -47195,23 +47277,33 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate }) {
|
|
|
47195
47277
|
}
|
|
47196
47278
|
function OrbPreview({
|
|
47197
47279
|
schema,
|
|
47198
|
-
mockData
|
|
47280
|
+
mockData,
|
|
47281
|
+
autoMock = false,
|
|
47199
47282
|
height = "400px",
|
|
47200
47283
|
className,
|
|
47201
47284
|
serverUrl
|
|
47202
47285
|
}) {
|
|
47203
|
-
const
|
|
47286
|
+
const parseResult = useMemo(() => {
|
|
47287
|
+
let parsed;
|
|
47204
47288
|
if (typeof schema === "string") {
|
|
47205
47289
|
try {
|
|
47206
|
-
|
|
47290
|
+
parsed = JSON.parse(schema);
|
|
47207
47291
|
} catch (e) {
|
|
47208
|
-
return { error: String(e) };
|
|
47292
|
+
return { ok: false, error: String(e) };
|
|
47209
47293
|
}
|
|
47294
|
+
} else {
|
|
47295
|
+
parsed = schema;
|
|
47210
47296
|
}
|
|
47211
|
-
|
|
47212
|
-
|
|
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 : {};
|
|
47213
47305
|
const pages = useMemo(() => {
|
|
47214
|
-
if (!parsedSchema
|
|
47306
|
+
if (!parsedSchema) return [];
|
|
47215
47307
|
try {
|
|
47216
47308
|
return getAllPages(parsedSchema);
|
|
47217
47309
|
} catch {
|
|
@@ -47225,10 +47317,10 @@ function OrbPreview({
|
|
|
47225
47317
|
setCurrentPage(match.page.name);
|
|
47226
47318
|
}
|
|
47227
47319
|
}, [pages]);
|
|
47228
|
-
if (
|
|
47320
|
+
if (!parseResult.ok) {
|
|
47229
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: [
|
|
47230
47322
|
"Parse error: ",
|
|
47231
|
-
|
|
47323
|
+
parseResult.error
|
|
47232
47324
|
] }) });
|
|
47233
47325
|
}
|
|
47234
47326
|
const containerRef = useRef(null);
|
|
@@ -47254,7 +47346,7 @@ function OrbPreview({
|
|
|
47254
47346
|
ref: containerRef,
|
|
47255
47347
|
className: `overflow-auto border border-[var(--color-border)] rounded-[var(--radius-md)] ${className ?? ""}`,
|
|
47256
47348
|
style: { height },
|
|
47257
|
-
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 }) }) })
|
|
47258
47350
|
}
|
|
47259
47351
|
);
|
|
47260
47352
|
}
|