@jfdevelops/react-layout 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-config/create-defined-resource-layout.cjs +41 -4
- package/dist/create-config/create-defined-resource-layout.cjs.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.cts +33 -13
- package/dist/create-config/create-defined-resource-layout.d.cts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.d.mts +33 -13
- package/dist/create-config/create-defined-resource-layout.d.mts.map +1 -1
- package/dist/create-config/create-defined-resource-layout.mjs +41 -4
- package/dist/create-config/create-defined-resource-layout.mjs.map +1 -1
- package/dist/create-config/define-layout.cjs +173 -25
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +46 -15
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +46 -15
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +173 -25
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resource.cjs.map +1 -1
- package/dist/create-config/for-resource.d.cts +2 -1
- package/dist/create-config/for-resource.d.cts.map +1 -1
- package/dist/create-config/for-resource.d.mts +2 -1
- package/dist/create-config/for-resource.d.mts.map +1 -1
- package/dist/create-config/for-resource.mjs.map +1 -1
- package/dist/create-config/index.d.cts +2 -1
- package/dist/create-config/index.d.mts +2 -1
- package/dist/create-config/inspection.cjs +67 -0
- package/dist/create-config/inspection.cjs.map +1 -0
- package/dist/create-config/inspection.mjs +66 -0
- package/dist/create-config/inspection.mjs.map +1 -0
- package/dist/create-config/layout-name.cjs +21 -0
- package/dist/create-config/layout-name.cjs.map +1 -0
- package/dist/create-config/layout-name.d.cts +49 -0
- package/dist/create-config/layout-name.d.cts.map +1 -0
- package/dist/create-config/layout-name.d.mts +49 -0
- package/dist/create-config/layout-name.d.mts.map +1 -0
- package/dist/create-config/layout-name.mjs +20 -0
- package/dist/create-config/layout-name.mjs.map +1 -0
- package/dist/create-config/lazy-resource-layout.cjs +1 -1
- package/dist/create-config/lazy-resource-layout.mjs +1 -1
- package/dist/create-config/merge-layout-props.cjs +20 -0
- package/dist/create-config/merge-layout-props.cjs.map +1 -0
- package/dist/create-config/merge-layout-props.mjs +19 -0
- package/dist/create-config/merge-layout-props.mjs.map +1 -0
- package/dist/create-config/preview.cjs +62 -0
- package/dist/create-config/preview.cjs.map +1 -0
- package/dist/create-config/preview.d.cts +13 -0
- package/dist/create-config/preview.d.cts.map +1 -0
- package/dist/create-config/preview.d.mts +13 -0
- package/dist/create-config/preview.d.mts.map +1 -0
- package/dist/create-config/preview.mjs +61 -0
- package/dist/create-config/preview.mjs.map +1 -0
- package/dist/create-config/render-state.cjs +19 -3
- package/dist/create-config/render-state.cjs.map +1 -1
- package/dist/create-config/render-state.d.cts +18 -14
- package/dist/create-config/render-state.d.cts.map +1 -1
- package/dist/create-config/render-state.d.mts +18 -14
- package/dist/create-config/render-state.d.mts.map +1 -1
- package/dist/create-config/render-state.mjs +19 -3
- package/dist/create-config/render-state.mjs.map +1 -1
- package/dist/create-config/state-composable.cjs +3 -0
- package/dist/create-config/state-composable.cjs.map +1 -1
- package/dist/create-config/state-composable.mjs +3 -1
- package/dist/create-config/state-composable.mjs.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +3 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +3 -1
- package/dist/utils/capitalize.d.cts +6 -0
- package/dist/utils/capitalize.d.cts.map +1 -0
- package/dist/utils/capitalize.d.mts +6 -0
- package/dist/utils/capitalize.d.mts.map +1 -0
- package/package.json +5 -4
|
@@ -2,21 +2,25 @@ import { InvalidConfigError } from "../errors/invalid-config.mjs";
|
|
|
2
2
|
import { MissingResourceProviderError } from "../errors/missing-resource-provider.mjs";
|
|
3
3
|
import { LayoutConfigurationError } from "../errors/layout-configuration-error.mjs";
|
|
4
4
|
import { ResourceModuleLoadError, ResourceRenderError } from "../errors/resource-state-error.mjs";
|
|
5
|
+
import { capitalize } from "../utils/capitalize.mjs";
|
|
6
|
+
import { StateComposableContext, createStateReferences, stateReferenceSource } from "./state-composable.mjs";
|
|
7
|
+
import { mergeLayoutProps } from "./merge-layout-props.mjs";
|
|
8
|
+
import { createPreviewComponent } from "./preview.mjs";
|
|
9
|
+
import { inspectDefinition, trackComposable } from "./inspection.mjs";
|
|
5
10
|
import { createIsValidResourceFn, normalizeResourceDefinitions, normalizeResources, toResourceEnum } from "../resource.mjs";
|
|
6
11
|
import { functionalUpdate, pick } from "../utils.mjs";
|
|
7
|
-
import { capitalize } from "../utils/capitalize.mjs";
|
|
8
12
|
import { isResourceConfigComponentKey } from "./component-keys.mjs";
|
|
9
13
|
import { createResourceConfig } from "./get-component.mjs";
|
|
10
14
|
import { createResourceLinksFn } from "./create-resource-links.mjs";
|
|
11
15
|
import { createForResource } from "./for-resource.mjs";
|
|
12
16
|
import { createForResources } from "./for-resources/create-for-resources.mjs";
|
|
13
17
|
import { ResourceLayoutShellPublisherContext, useResourceLayoutShellPublisher } from "./shell-context.mjs";
|
|
14
|
-
import { StateComposableContext, createStateReferences } from "./state-composable.mjs";
|
|
15
18
|
import { deferredRenderStateSymbol, definedResourceLayoutComponentSymbol, findDefinedRenderState, isDeferredRenderState, isLazyRenderState, lazyRenderStateSymbol } from "./render-state.mjs";
|
|
16
19
|
import { LayoutComposablePresetProvider, collectComposablePresetEntries, makeComposable, resolveLayoutComposables } from "@jfdevelops/react-layout-composables";
|
|
17
20
|
import { Component, Suspense, createContext, lazy, useCallback, useContext, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
18
|
-
import {
|
|
21
|
+
import { getLayoutDebug, inspectionId, layoutDebug, layoutPreviewFixtures } from "@jfdevelops/react-layout-devtools-core";
|
|
19
22
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
23
|
+
import { attachComponentPropDefinitions, createPrimitivePropBuilder, createProp, resolvePropDefinitionValues, validateProps } from "@jfdevelops/react-layout-validator";
|
|
20
24
|
|
|
21
25
|
//#region src/create-config/define-layout.tsx
|
|
22
26
|
const RenderStateRetryContext = createContext(void 0);
|
|
@@ -138,9 +142,22 @@ function assertUnreservedResourceSlugs(resources, owner) {
|
|
|
138
142
|
if (typeof resource !== "string") assertUnreservedResourceSlugs(resource.subResources, slug);
|
|
139
143
|
}
|
|
140
144
|
}
|
|
141
|
-
function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
145
|
+
function defineResourceLayoutImpl(options, inheritedStateScope, inheritedInspection) {
|
|
142
146
|
const { options: inProps = {}, resources, layout, namespace: defaultNamespace = false } = options;
|
|
143
147
|
const shellId = options.shellId;
|
|
148
|
+
const inspection = inheritedInspection ? void 0 : inspectDefinition(resources, getLayoutDebug(options)?.source ?? getLayoutDebug(layout)?.source);
|
|
149
|
+
if (inspection) inspection.store.node({
|
|
150
|
+
id: inspection.definition,
|
|
151
|
+
kind: "definition",
|
|
152
|
+
label: "Layout definition",
|
|
153
|
+
source: getLayoutDebug(options)?.source ?? getLayoutDebug(layout)?.source,
|
|
154
|
+
details: {
|
|
155
|
+
props: layout.props,
|
|
156
|
+
propSchemas: typeof inProps === "function" ? void 0 : inProps,
|
|
157
|
+
options: typeof inProps === "function" ? "Resource-specific schemas" : Object.keys(inProps),
|
|
158
|
+
states: typeof layout.render === "function" ? ["default"] : Object.keys(layout.render)
|
|
159
|
+
}
|
|
160
|
+
});
|
|
144
161
|
assertUnreservedResourceSlugs(resources);
|
|
145
162
|
const resourcesAccessor = createLayoutResourcesAccessor(resources);
|
|
146
163
|
const ResourceContext = createContext(void 0);
|
|
@@ -158,19 +175,74 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
158
175
|
const normalizedResources = normalizeResources(resources);
|
|
159
176
|
const resourcesEnum = createPrimitivePropBuilder("string").enum(toResourceEnum(normalizedResources));
|
|
160
177
|
const definedResourceLayout = ((layoutOptions) => {
|
|
161
|
-
const { name, props: instancePropDefinitions, namespace = defaultNamespace, ...layoutOptionProps } = layoutOptions;
|
|
178
|
+
const { name: suppliedName, props: instancePropDefinitions, namespace = defaultNamespace, ...layoutOptionProps } = layoutOptions;
|
|
179
|
+
const naming = suppliedName ?? options.name;
|
|
180
|
+
const name = typeof naming === "function" ? naming({
|
|
181
|
+
resource: layoutOptions.resource,
|
|
182
|
+
states: typeof layout.render === "function" ? ["default"] : Object.keys(layout.render),
|
|
183
|
+
capitalize
|
|
184
|
+
}) : naming;
|
|
185
|
+
if (name !== void 0 && (typeof name !== "string" || !name)) throw new LayoutConfigurationError("A non-empty layout name is required");
|
|
162
186
|
const createComposableLayout = makeComposable();
|
|
163
187
|
const nameProp = createProp.string().literal(name);
|
|
188
|
+
const rawResolvedOptions = typeof inProps === "function" ? inProps({
|
|
189
|
+
resource: resourcesEnum,
|
|
190
|
+
name: nameProp
|
|
191
|
+
}) : inProps;
|
|
164
192
|
const { resolvedInProps, splitInProps } = splitLayoutInProps({
|
|
165
|
-
...
|
|
166
|
-
resource: resourcesEnum,
|
|
167
|
-
name: nameProp
|
|
168
|
-
}) : inProps,
|
|
193
|
+
...rawResolvedOptions,
|
|
169
194
|
...instancePropDefinitions,
|
|
170
195
|
...layoutOptionProps
|
|
171
196
|
});
|
|
172
197
|
const { composables, props: legacyLayoutProps } = layout;
|
|
173
198
|
const renderStates = typeof layout.render === "function" ? { default: layout.render } : layout.render;
|
|
199
|
+
const inspectionStore = inheritedInspection?.store ?? inspection.store;
|
|
200
|
+
const layoutId = inheritedInspection?.layout ?? inspectionStore.node({
|
|
201
|
+
id: inspectionId("layout"),
|
|
202
|
+
kind: "layout",
|
|
203
|
+
label: name ?? String(layoutOptionProps.resource),
|
|
204
|
+
source: getLayoutDebug(layoutOptions)?.source ?? getLayoutDebug(options)?.source ?? getLayoutDebug(layout)?.source,
|
|
205
|
+
registrationSource: getLayoutDebug(options)?.source ?? getLayoutDebug(layout)?.source,
|
|
206
|
+
details: {
|
|
207
|
+
resource: layoutOptionProps.resource,
|
|
208
|
+
props: legacyLayoutProps,
|
|
209
|
+
propSchemas: rawResolvedOptions
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
const resourceId = inheritedInspection?.resource ?? inspection?.resourceIds.get(String(layoutOptionProps.resource));
|
|
213
|
+
if (inspection) {
|
|
214
|
+
inspectionStore.edge(inspection.definition, layoutId, "defines");
|
|
215
|
+
if (resourceId) inspectionStore.edge(resourceId, layoutId, "renders");
|
|
216
|
+
}
|
|
217
|
+
const stateIds = new Map(Object.keys(renderStates).map((state) => [state, inheritedInspection?.state ?? inspectionStore.node({
|
|
218
|
+
id: inspectionId("state"),
|
|
219
|
+
kind: "state",
|
|
220
|
+
label: state,
|
|
221
|
+
source: getLayoutDebug(renderStates[state])?.source ?? getLayoutDebug(options)?.source ?? getLayoutDebug(layout)?.source,
|
|
222
|
+
registrationSource: getLayoutDebug(options)?.source ?? getLayoutDebug(layout)?.source,
|
|
223
|
+
unresolved: isLazyRenderState(renderStates[state]) || isDeferredRenderState(renderStates[state])
|
|
224
|
+
})]));
|
|
225
|
+
for (const id of stateIds.values()) inspectionStore.edge(layoutId, id, "defines");
|
|
226
|
+
const activeInspection = {
|
|
227
|
+
store: inspectionStore,
|
|
228
|
+
layout: layoutId,
|
|
229
|
+
resource: resourceId,
|
|
230
|
+
state: stateIds.get("default")
|
|
231
|
+
};
|
|
232
|
+
const referenceStateIds = /* @__PURE__ */ new Map();
|
|
233
|
+
function getReferenceStateId(input, label) {
|
|
234
|
+
let id = referenceStateIds.get(input);
|
|
235
|
+
if (!id) {
|
|
236
|
+
id = inspectionStore.node({
|
|
237
|
+
id: inspectionId("state-reference"),
|
|
238
|
+
kind: "state",
|
|
239
|
+
label,
|
|
240
|
+
details: { relationship: "Referenced render state" }
|
|
241
|
+
});
|
|
242
|
+
referenceStateIds.set(input, id);
|
|
243
|
+
}
|
|
244
|
+
return id;
|
|
245
|
+
}
|
|
174
246
|
const referenceComponents = /* @__PURE__ */ new Map();
|
|
175
247
|
const stateScope = inheritedStateScope ?? {
|
|
176
248
|
states: createStateReferences(renderStates),
|
|
@@ -189,8 +261,18 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
189
261
|
const defaultRenderDefinition = getSynchronousRenderStateDefinition(defaultRenderInput, legacyLayoutProps) ?? { render: () => null };
|
|
190
262
|
if (typeof defaultRenderDefinition !== "object" || defaultRenderDefinition === null || !("render" in defaultRenderDefinition) || typeof defaultRenderDefinition.render !== "function") throw new LayoutConfigurationError("The \"default\" render state must define a render function");
|
|
191
263
|
const defaultState = defaultRenderDefinition;
|
|
264
|
+
if (!inheritedInspection) inspectionStore.node({
|
|
265
|
+
id: activeInspection.state,
|
|
266
|
+
kind: "state",
|
|
267
|
+
label: "default",
|
|
268
|
+
unresolved: createdDefaultState,
|
|
269
|
+
details: {
|
|
270
|
+
props: mergeLayoutProps(legacyLayoutProps, defaultState.props),
|
|
271
|
+
propSchemas: rawResolvedOptions
|
|
272
|
+
}
|
|
273
|
+
});
|
|
192
274
|
const render = defaultState.render;
|
|
193
|
-
const layoutProps = defaultState.props
|
|
275
|
+
const layoutProps = mergeLayoutProps(legacyLayoutProps, defaultState.props);
|
|
194
276
|
const customLayoutProps = layoutProps?.custom;
|
|
195
277
|
const includeLayoutProps = layoutProps?.include;
|
|
196
278
|
const layoutOptionValues = layoutOptionProps;
|
|
@@ -208,7 +290,27 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
208
290
|
...composables?.(create, stateScope.states) ?? {},
|
|
209
291
|
...defaultState.composables?.(create, stateScope.states)
|
|
210
292
|
}) : void 0;
|
|
211
|
-
const resolvedComposables = defaultComposables ? resolveLayoutComposables(defaultComposables, layoutContext) : void 0;
|
|
293
|
+
const resolvedComposables = defaultComposables ? { ...resolveLayoutComposables(defaultComposables, layoutContext) } : void 0;
|
|
294
|
+
for (const [key, component] of Object.entries(resolvedComposables ?? {})) {
|
|
295
|
+
const id = inspectionStore.node({
|
|
296
|
+
id: inspectionId("composable"),
|
|
297
|
+
kind: "composable",
|
|
298
|
+
label: key,
|
|
299
|
+
source: getLayoutDebug(component)?.source,
|
|
300
|
+
details: {
|
|
301
|
+
displayName: component.displayName,
|
|
302
|
+
relationship: "declared; may not be rendered"
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
inspectionStore.edge(activeInspection.state, id, "declares");
|
|
306
|
+
resolvedComposables[key] = trackComposable(component, inspectionStore, id);
|
|
307
|
+
const reference = component[stateReferenceSource];
|
|
308
|
+
if (reference) {
|
|
309
|
+
const stateName = Object.entries(renderStates).find(([, input]) => input === reference.input)?.[0];
|
|
310
|
+
const target = stateName ? stateIds.get(stateName) : getReferenceStateId(reference.input, reference.name);
|
|
311
|
+
inspectionStore.edge(id, target, "references");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
212
314
|
const mergedResolvedInProps = { ...resolvedInProps };
|
|
213
315
|
for (const { props: presetPropDefinitions } of collectComposablePresetEntries(resolvedComposables)) Object.assign(mergedResolvedInProps, presetPropDefinitions);
|
|
214
316
|
const composablePresetProps = Object.fromEntries(collectComposablePresetEntries(resolvedComposables).map(({ key, props: presetPropDefinitions }) => {
|
|
@@ -228,6 +330,10 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
228
330
|
const stateComponents = {};
|
|
229
331
|
let CreatedDefaultStateComponent;
|
|
230
332
|
function RenderDefaultState({ renderProps }) {
|
|
333
|
+
useLayoutEffect(() => {
|
|
334
|
+
if (CreatedDefaultStateComponent) return;
|
|
335
|
+
return inspectionStore.mount(activeInspection.layout, activeInspection.state, ...resourceId ? [resourceId] : []);
|
|
336
|
+
}, []);
|
|
231
337
|
if (CreatedDefaultStateComponent) return /* @__PURE__ */ jsx(CreatedDefaultStateComponent, { ...renderProps });
|
|
232
338
|
return render(renderProps, mergedRenderContext);
|
|
233
339
|
}
|
|
@@ -295,6 +401,7 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
295
401
|
return { makeComposable: createComposableLayout(compositionOptions) };
|
|
296
402
|
}
|
|
297
403
|
function createStateComponent(stateName, input, validateStateName = true, fallbackStateName = stateName) {
|
|
404
|
+
const inspectedId = validateStateName ? stateIds.get(stateName) : getReferenceStateId(input, stateName);
|
|
298
405
|
if (isLazyRenderState(input)) {
|
|
299
406
|
const loadState = input[lazyRenderStateSymbol];
|
|
300
407
|
function createLazyState() {
|
|
@@ -303,7 +410,7 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
303
410
|
throw new ResourceModuleLoadError(String(layoutContext.resource), error);
|
|
304
411
|
}));
|
|
305
412
|
if (validateStateName && stateDefinition.state !== void 0 && stateDefinition.state !== stateName) throw new LayoutConfigurationError(`Lazy render state "${stateDefinition.state}" cannot be used as "${stateName}"`);
|
|
306
|
-
return { default: createLoadedStateComponent(validateStateName ? stateName : stateDefinition.state ?? stateName, stateDefinition) };
|
|
413
|
+
return { default: createLoadedStateComponent(validateStateName ? stateName : stateDefinition.state ?? stateName, stateDefinition, inspectedId) };
|
|
307
414
|
});
|
|
308
415
|
}
|
|
309
416
|
function LazyStateComponent(props) {
|
|
@@ -336,7 +443,7 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
336
443
|
}
|
|
337
444
|
const definition = isDeferredRenderState(input) ? input[deferredRenderStateSymbol] : typeof input === "function" ? { render: input } : input;
|
|
338
445
|
if (typeof definition !== "object" || definition === null || !("render" in definition) || typeof definition.render !== "function") throw new LayoutConfigurationError(`Render state "${stateName}" must define a render function`);
|
|
339
|
-
const StateComponent = createLoadedStateComponent(stateName, definition);
|
|
446
|
+
const StateComponent = createLoadedStateComponent(stateName, definition, inspectedId);
|
|
340
447
|
if (!isDeferredRenderState(input)) return StateComponent;
|
|
341
448
|
const DeferredState = lazy(() => Promise.resolve({ default: StateComponent }));
|
|
342
449
|
function DeferredStateComponent(props) {
|
|
@@ -359,7 +466,18 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
359
466
|
}
|
|
360
467
|
return DeferredStateComponent;
|
|
361
468
|
}
|
|
362
|
-
function createLoadedStateComponent(stateName, definition) {
|
|
469
|
+
function createLoadedStateComponent(stateName, definition, inspectedState = stateIds.get(stateName)) {
|
|
470
|
+
if (inspectedState) inspectionStore.node({
|
|
471
|
+
id: inspectedState,
|
|
472
|
+
kind: "state",
|
|
473
|
+
label: stateName,
|
|
474
|
+
unresolved: false,
|
|
475
|
+
source: getLayoutDebug(definition)?.source,
|
|
476
|
+
details: {
|
|
477
|
+
props: mergeLayoutProps(legacyLayoutProps, definition.props),
|
|
478
|
+
propSchemas: rawResolvedOptions
|
|
479
|
+
}
|
|
480
|
+
});
|
|
363
481
|
const stateComposables = composables || definition.composables ? (create) => ({
|
|
364
482
|
...composables?.(create, stateScope.states) ?? {},
|
|
365
483
|
...definition.composables?.(create, stateScope.states)
|
|
@@ -373,11 +491,15 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
373
491
|
options: inProps,
|
|
374
492
|
layout: {
|
|
375
493
|
composables: stateComposables,
|
|
376
|
-
props: definition.props,
|
|
494
|
+
props: mergeLayoutProps(legacyLayoutProps, definition.props),
|
|
377
495
|
render: stateRender
|
|
378
496
|
}
|
|
379
|
-
}, stateScope
|
|
497
|
+
}, stateScope, {
|
|
498
|
+
...activeInspection,
|
|
499
|
+
state: inspectedState ?? getReferenceStateId(definition, stateName)
|
|
500
|
+
}).createResourceLayout({
|
|
380
501
|
...layoutOptions,
|
|
502
|
+
name,
|
|
381
503
|
namespace: false
|
|
382
504
|
});
|
|
383
505
|
StateComponent.displayName = `${name}.${stateName}`;
|
|
@@ -409,7 +531,27 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
409
531
|
const definition = mergedResolvedInProps[key];
|
|
410
532
|
return [[key, isIncludedPropRequired(includeLayoutProps?.[key]) ? definition : definition.optional?.() ?? definition]];
|
|
411
533
|
}));
|
|
412
|
-
const
|
|
534
|
+
const previewEnabled = !inheritedInspection && (getLayoutDebug(layoutOptions)?.preview ?? getLayoutDebug(options)?.preview ?? getLayoutDebug(layout)?.preview) === true;
|
|
535
|
+
const previewTargets = {
|
|
536
|
+
default: Component,
|
|
537
|
+
...stateComponents
|
|
538
|
+
};
|
|
539
|
+
let previewRoot;
|
|
540
|
+
const previewOptions = {
|
|
541
|
+
store: inspectionStore,
|
|
542
|
+
layout: layoutId,
|
|
543
|
+
states: stateIds,
|
|
544
|
+
components: previewTargets,
|
|
545
|
+
fixtures: () => previewRoot[layoutPreviewFixtures]
|
|
546
|
+
};
|
|
547
|
+
const exposedStates = previewEnabled ? Object.fromEntries(Object.entries(stateComponents).map(([key, component]) => [key, createPreviewComponent(component, {
|
|
548
|
+
...previewOptions,
|
|
549
|
+
state: stateIds.get(key)
|
|
550
|
+
})])) : stateComponents;
|
|
551
|
+
const createdComponent = Object.assign(previewEnabled ? createPreviewComponent(Component, {
|
|
552
|
+
...previewOptions,
|
|
553
|
+
state: activeInspection.state
|
|
554
|
+
}) : Component, {
|
|
413
555
|
displayName: name,
|
|
414
556
|
props: void 0,
|
|
415
557
|
resource: void 0,
|
|
@@ -417,9 +559,12 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
417
559
|
components: resolvedComposables,
|
|
418
560
|
name
|
|
419
561
|
}),
|
|
420
|
-
...
|
|
562
|
+
...exposedStates,
|
|
421
563
|
[definedResourceLayoutComponentSymbol]: true
|
|
422
|
-
})
|
|
564
|
+
});
|
|
565
|
+
previewRoot = createdComponent;
|
|
566
|
+
inspectionStore.attach(createdComponent);
|
|
567
|
+
const rootComponent = attachComponentPropDefinitions(createdComponent, {
|
|
423
568
|
...customLayoutProps,
|
|
424
569
|
...includedComponentDefinitions
|
|
425
570
|
});
|
|
@@ -427,7 +572,7 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
427
572
|
if (Object.prototype.hasOwnProperty.call(stateComponents, "Root")) throw new LayoutConfigurationError("Render state name \"Root\" is reserved when namespace is true");
|
|
428
573
|
return {
|
|
429
574
|
Root: rootComponent,
|
|
430
|
-
...
|
|
575
|
+
...exposedStates
|
|
431
576
|
};
|
|
432
577
|
}
|
|
433
578
|
return rootComponent;
|
|
@@ -463,7 +608,7 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
463
608
|
for (const { props: presetPropDefinitions } of collectComposablePresetEntries(resolvedComposables)) Object.assign(resolvedInProps, presetPropDefinitions);
|
|
464
609
|
return {
|
|
465
610
|
...resolvedInProps,
|
|
466
|
-
...(defaultState?.props
|
|
611
|
+
...mergeLayoutProps(layout.props, defaultState?.props)?.custom
|
|
467
612
|
};
|
|
468
613
|
}
|
|
469
614
|
const { createLayoutForResourceBuilder, forResource } = createForResource({
|
|
@@ -480,14 +625,16 @@ function defineResourceLayoutImpl(options, inheritedStateScope) {
|
|
|
480
625
|
})
|
|
481
626
|
};
|
|
482
627
|
if (layout.composables) createResourceLayoutExtras.makeComposable = createTopLevelMakeComposable();
|
|
483
|
-
|
|
628
|
+
const createResourceLayout = Object.assign(definedResourceLayout, createResourceLayoutExtras);
|
|
629
|
+
const createResourceLinks = createResourceLinksFn(resources);
|
|
630
|
+
return (inspection?.store.attach ?? ((value) => value))({
|
|
484
631
|
createResourceConfig,
|
|
485
|
-
createResourceLayout
|
|
486
|
-
createResourceLinks
|
|
632
|
+
createResourceLayout,
|
|
633
|
+
createResourceLinks,
|
|
487
634
|
resources: resourcesAccessor,
|
|
488
635
|
ResourceProvider,
|
|
489
636
|
useResource
|
|
490
|
-
};
|
|
637
|
+
});
|
|
491
638
|
}
|
|
492
639
|
function defineResources(...resources) {
|
|
493
640
|
return resources;
|
|
@@ -654,6 +801,7 @@ function defineResourceLayoutWithLayoutImpl(options) {
|
|
|
654
801
|
};
|
|
655
802
|
const shellId = Symbol("resourceLayoutShell");
|
|
656
803
|
const base = defineResourceLayoutImpl({
|
|
804
|
+
[layoutDebug]: getLayoutDebug(options),
|
|
657
805
|
resources,
|
|
658
806
|
options: inProps,
|
|
659
807
|
layout: resolvedLayout,
|