@netlisian/softconfig 0.0.11 → 0.1.1
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/README.md +0 -0
- package/dist/index.css +0 -0
- package/dist/index.d.mts +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/index.mjs +0 -0
- package/dist/puck/index.css +44 -43
- package/dist/puck/index.d.mts +91 -30
- package/dist/puck/index.d.ts +91 -30
- package/dist/puck/index.js +871 -433
- package/dist/puck/index.mjs +839 -400
- package/package.json +3 -1
package/dist/puck/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as zustand from 'zustand';
|
|
2
2
|
import { StoreApi } from 'zustand';
|
|
3
|
-
import { History, AppState, PuckApi,
|
|
3
|
+
import { History, AppState, PuckApi, ComponentData, ComponentConfig, DefaultComponentProps, Field, Config, Fields, RootData, AsFieldProps, WithChildren, Metadata, ResolveDataTrigger, PuckAction, Data } from '@measured/puck';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import react__default, { ReactNode, ReactElement } from 'react';
|
|
6
6
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -21,7 +21,7 @@ type BuildersSlice = {
|
|
|
21
21
|
build: (history: History<AppState>[], selectedItem: PuckApi["selectedItem"], itemSelector: {
|
|
22
22
|
index: number;
|
|
23
23
|
zone?: string;
|
|
24
|
-
} | null, puckDispatch: PuckApi["dispatch"]) => void | null;
|
|
24
|
+
} | null, puckDispatch: PuckApi["dispatch"], name?: string) => void | null;
|
|
25
25
|
/**
|
|
26
26
|
* Remodel the selected soft component by decomposing it and resetting as root.
|
|
27
27
|
*
|
|
@@ -38,7 +38,7 @@ type BuildersSlice = {
|
|
|
38
38
|
remodel: (history: History<AppState>[], selectedItem: PuckApi["selectedItem"], itemSelector: {
|
|
39
39
|
index: number;
|
|
40
40
|
zone?: string;
|
|
41
|
-
} | null, puckDispatch: PuckApi["dispatch"]) => void;
|
|
41
|
+
} | null, puckDispatch: PuckApi["dispatch"], refreshPermission: () => void) => void;
|
|
42
42
|
/**
|
|
43
43
|
* Switch to a different version of the soft component being remodeled.
|
|
44
44
|
*
|
|
@@ -61,7 +61,7 @@ type BuildersSlice = {
|
|
|
61
61
|
* - Strip the build settings fields
|
|
62
62
|
* - Apply modified history to puck data.
|
|
63
63
|
*/
|
|
64
|
-
complete: (appState: AppState<any>, setHistories: PuckApi["history"]["setHistories"]) => string;
|
|
64
|
+
complete: (appState: AppState<any>, setHistories: PuckApi["history"]["setHistories"], getItemBySelector: PuckApi["getItemBySelector"]) => string;
|
|
65
65
|
demolish: (componentName: string, data: AppState["data"], puckDispatch: PuckApi["dispatch"]) => void;
|
|
66
66
|
inspect: (componentName: string, puckDispatch: PuckApi["dispatch"]) => void;
|
|
67
67
|
/**
|
|
@@ -77,7 +77,7 @@ type BuildersSlice = {
|
|
|
77
77
|
/** Compose multiple components into a soft component.
|
|
78
78
|
* 1. SoftComponent: Get soft fields + default values from the appState.root + sub-component maps + fixedProps
|
|
79
79
|
*/
|
|
80
|
-
compose: (appState: AppState, componentName: string) => [ComponentConfig, string] | undefined;
|
|
80
|
+
compose: (appState: AppState, componentName: string, editedItem: ComponentData, displayName: string, category?: string) => [ComponentConfig, string] | undefined;
|
|
81
81
|
/** Break down a composed component into its parts.
|
|
82
82
|
* 1. Get softComponentProps
|
|
83
83
|
* 2. Create a virtual component with all the props from soft-component.
|
|
@@ -88,6 +88,7 @@ type BuildersSlice = {
|
|
|
88
88
|
|
|
89
89
|
type BuilderRootConfig = {
|
|
90
90
|
_name: string;
|
|
91
|
+
_category?: string;
|
|
91
92
|
_version?: string;
|
|
92
93
|
_versions?: string[];
|
|
93
94
|
_fields?: {
|
|
@@ -125,6 +126,8 @@ type SoftSubComponent = {
|
|
|
125
126
|
}[];
|
|
126
127
|
}[];
|
|
127
128
|
type SoftComponent = {
|
|
129
|
+
name: string;
|
|
130
|
+
category?: string;
|
|
128
131
|
fields: Fields;
|
|
129
132
|
fieldSettings?: Record<string, any>;
|
|
130
133
|
defaultProps: DefaultComponentProps;
|
|
@@ -135,6 +138,8 @@ type SoftComponent = {
|
|
|
135
138
|
};
|
|
136
139
|
type VersionedSoftComponent = {
|
|
137
140
|
defaultVersion: string;
|
|
141
|
+
name: string;
|
|
142
|
+
category?: string;
|
|
138
143
|
versions: {
|
|
139
144
|
[version: string]: {
|
|
140
145
|
fields: Fields;
|
|
@@ -146,6 +151,13 @@ type VersionedSoftComponent = {
|
|
|
146
151
|
};
|
|
147
152
|
};
|
|
148
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* Dependencies map: version -> Set of component names this component depends on
|
|
156
|
+
* Automatically inferred from component structure but can be overridden
|
|
157
|
+
*/
|
|
158
|
+
dependencies?: {
|
|
159
|
+
[version: string]: Set<string>;
|
|
160
|
+
};
|
|
149
161
|
};
|
|
150
162
|
type SoftComponents = Record<string, VersionedSoftComponent>;
|
|
151
163
|
|
|
@@ -163,8 +175,8 @@ type ActionEventPayload = {
|
|
|
163
175
|
type: "complete";
|
|
164
176
|
payload: {
|
|
165
177
|
id: string;
|
|
166
|
-
componentData:
|
|
167
|
-
softComponent:
|
|
178
|
+
componentData: Record<string, any>;
|
|
179
|
+
softComponent: VersionedSoftComponent["versions"][string];
|
|
168
180
|
};
|
|
169
181
|
} | {
|
|
170
182
|
type: "cancel";
|
|
@@ -205,6 +217,10 @@ type RenderFunc<Props extends {
|
|
|
205
217
|
children: ReactNode;
|
|
206
218
|
}> = (props: Props) => ReactElement;
|
|
207
219
|
type Overrides = {
|
|
220
|
+
componentNameToKey?: (displayName: string, context: {
|
|
221
|
+
existingKeys: string[];
|
|
222
|
+
state: "building" | "remodeling" | "ready" | "inspecting";
|
|
223
|
+
}) => string;
|
|
208
224
|
map?: RenderFunc<{
|
|
209
225
|
rootProps: BuilderRootConfig;
|
|
210
226
|
toOptions: {
|
|
@@ -229,6 +245,16 @@ type Overrides = {
|
|
|
229
245
|
softComponent: VersionedSoftComponent["versions"][string];
|
|
230
246
|
}) => ((inputs: any[], props: DefaultComponentProps) => any) | undefined;
|
|
231
247
|
onActions?: OnActionsCallback;
|
|
248
|
+
name?: Field<string>;
|
|
249
|
+
categories?: Field<string | undefined>;
|
|
250
|
+
onRootsDataChange?: (data: RootData<AsFieldProps<WithChildren<BuilderRootConfig>>>, params: {
|
|
251
|
+
changed: Partial<Record<keyof BuilderRootConfig, boolean> & {
|
|
252
|
+
id: string;
|
|
253
|
+
}>;
|
|
254
|
+
lastData: RootData<AsFieldProps<WithChildren<BuilderRootConfig>>> | null;
|
|
255
|
+
metadata: Metadata;
|
|
256
|
+
trigger: ResolveDataTrigger;
|
|
257
|
+
}) => void;
|
|
232
258
|
};
|
|
233
259
|
|
|
234
260
|
type Status = "building" | "remodeling" | "ready" | "inspecting";
|
|
@@ -269,9 +295,50 @@ type AppStore = {
|
|
|
269
295
|
hydrateTransforms: () => void;
|
|
270
296
|
setSoftComponentDefaultVersion: (key: string, version: string) => void;
|
|
271
297
|
removeSoftComponent: (key: string) => void;
|
|
298
|
+
editingComponentId: string | null;
|
|
299
|
+
editableComponentIds: Set<string>;
|
|
300
|
+
setEditableComponentIds: (ids: Set<string>) => void;
|
|
301
|
+
addEditableComponentId: (id: string) => void;
|
|
302
|
+
clearEditingState: () => void;
|
|
303
|
+
/**
|
|
304
|
+
* Reverse dependency graph: componentName -> Set of components that depend on it
|
|
305
|
+
* Used to efficiently rebuild dependent components when a soft component is updated
|
|
306
|
+
*/
|
|
307
|
+
dependencyGraph: Map<string, Set<string>>;
|
|
308
|
+
/**
|
|
309
|
+
* Rebuild all dependent components after a soft component is updated
|
|
310
|
+
* Only rebuilds components that depend on the changed component
|
|
311
|
+
*
|
|
312
|
+
* @param componentName - The component that was updated
|
|
313
|
+
* @param version - The version that was updated
|
|
314
|
+
*/
|
|
315
|
+
rebuildDependents: (componentName: string, version: string) => void;
|
|
316
|
+
/**
|
|
317
|
+
* Iframe document reference for applying styling and edit visibility
|
|
318
|
+
* Stored as a mutable ref to avoid triggering store updates.
|
|
319
|
+
*/
|
|
320
|
+
iframeDocRef: {
|
|
321
|
+
current: Document | null;
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* Get the current iframe document reference
|
|
325
|
+
*/
|
|
326
|
+
getIframeDoc: () => Document | null;
|
|
327
|
+
/**
|
|
328
|
+
* Set the iframe document reference without causing re-renders
|
|
329
|
+
*/
|
|
330
|
+
setIframeDoc: (doc: Document | null) => void;
|
|
331
|
+
/**
|
|
332
|
+
* Flag to control visibility of version config fields
|
|
333
|
+
*/
|
|
334
|
+
showVersionFields: boolean;
|
|
335
|
+
/**
|
|
336
|
+
* Toggle the visibility of version config fields
|
|
337
|
+
*/
|
|
338
|
+
setShowVersionFields: (show: boolean) => void;
|
|
272
339
|
};
|
|
273
340
|
type AppStoreApi = StoreApi<AppStore>;
|
|
274
|
-
declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides, onActions?: OnActionsCallback) => zustand.UseBoundStore<Omit<
|
|
341
|
+
declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides, onActions?: OnActionsCallback, showVersionFields?: boolean) => zustand.UseBoundStore<Omit<StoreApi<AppStore>, "subscribe"> & {
|
|
275
342
|
subscribe: {
|
|
276
343
|
(listener: (selectedState: AppStore, previousSelectedState: AppStore) => void): () => void;
|
|
277
344
|
<U>(selector: (state: AppStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
|
|
@@ -279,35 +346,20 @@ declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: Soft
|
|
|
279
346
|
fireImmediately?: boolean;
|
|
280
347
|
} | undefined): () => void;
|
|
281
348
|
};
|
|
282
|
-
}, "setState" | "devtools"> & {
|
|
283
|
-
setState(partial: AppStore | Partial<AppStore> | ((state: AppStore) => AppStore | Partial<AppStore>), replace?: false | undefined, action?: (string | {
|
|
284
|
-
[x: string]: unknown;
|
|
285
|
-
[x: number]: unknown;
|
|
286
|
-
[x: symbol]: unknown;
|
|
287
|
-
type: string;
|
|
288
|
-
}) | undefined): void;
|
|
289
|
-
setState(state: AppStore | ((state: AppStore) => AppStore), replace: true, action?: (string | {
|
|
290
|
-
[x: string]: unknown;
|
|
291
|
-
[x: number]: unknown;
|
|
292
|
-
[x: symbol]: unknown;
|
|
293
|
-
type: string;
|
|
294
|
-
}) | undefined): void;
|
|
295
|
-
devtools: {
|
|
296
|
-
cleanup: () => void;
|
|
297
|
-
};
|
|
298
349
|
}>;
|
|
299
350
|
|
|
300
|
-
declare const SoftConfigProvider: ({ children, hardConfig, softComponents, overrides, value, onActions, }: {
|
|
301
|
-
children: (softConfig: Config, softComponents: SoftComponents) => ReactNode;
|
|
351
|
+
declare const SoftConfigProvider: ({ children, hardConfig, softComponents, overrides, value, onActions, useVersioning, }: {
|
|
352
|
+
children: (softConfig: Config, softComponents: SoftComponents, iframeDoc: AppStore["setIframeDoc"], validateAction: (action: PuckAction) => boolean) => ReactNode;
|
|
302
353
|
hardConfig: Config;
|
|
303
354
|
softComponents: SoftComponents;
|
|
304
|
-
overrides
|
|
355
|
+
overrides?: Overrides;
|
|
305
356
|
value?: StoreApi<AppStore>;
|
|
306
357
|
onActions?: OnActionsCallback;
|
|
358
|
+
useVersioning?: boolean;
|
|
307
359
|
}) => react_jsx_runtime.JSX.Element;
|
|
308
360
|
|
|
309
|
-
declare const createUseSoftConfig: () => <T>(selector: (state: AppStore) => T) => T;
|
|
310
|
-
declare const useSoftConfig: <T>(selector: (state: AppStore) => T) => T;
|
|
361
|
+
declare const createUseSoftConfig: () => <T>(selector: (state: AppStore) => T, equalityFn?: (a: T, b: T) => boolean) => T;
|
|
362
|
+
declare const useSoftConfig: <T>(selector: (state: AppStore) => T, equalityFn?: (a: T, b: T) => boolean) => T;
|
|
311
363
|
|
|
312
364
|
declare const useBuild: () => {
|
|
313
365
|
handleBuild: () => void;
|
|
@@ -386,6 +438,15 @@ declare const setConfirmHandler: (handler: ConfirmHandler) => void;
|
|
|
386
438
|
*/
|
|
387
439
|
declare const confirm: (message: string) => Promise<boolean>;
|
|
388
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Create an action callback that validates and handles actions with undo support
|
|
443
|
+
*
|
|
444
|
+
* @param validateAction Function to validate if an action is allowed
|
|
445
|
+
* @param undo Function to undo the last action (from Puck's history)
|
|
446
|
+
* @returns Action handler function
|
|
447
|
+
*/
|
|
448
|
+
declare const createActionCallback: (validateAction: (action: PuckAction) => boolean, undo: PuckApi["history"]["back"]) => (action: PuckAction) => void;
|
|
449
|
+
|
|
389
450
|
/**
|
|
390
451
|
* Resolves soft components in data by dissolving them to hard components only.
|
|
391
452
|
*
|
|
@@ -411,4 +472,4 @@ declare const Modal: ({ children, onClose, isOpen, }: {
|
|
|
411
472
|
isOpen: boolean;
|
|
412
473
|
}) => react_jsx_runtime.JSX.Element;
|
|
413
474
|
|
|
414
|
-
export { ActionBarOverride as ActionBar, type ActionEventPayload, type AppStore, type AppStoreApi, type BuilderComponentConfig, type BuilderConfig, type BuilderRootConfig, ComponentItem, Header, Modal, type OnActionsCallback, type Overrides, type SoftComponent, type SoftComponents, SoftConfigProvider, type VersionedSoftComponent, confirm, createSoftConfigStore, createUseSoftConfig, notify, resolveSoftConfig, setConfirmHandler, setNotificationHandler, useBuild, useCancel, useComplete, useDecompose, useDemolish, useInspect, useRemodel, useSetDefaultVersion, useSoftConfig };
|
|
475
|
+
export { ActionBarOverride as ActionBar, type ActionEventPayload, type AppStore, type AppStoreApi, type BuilderComponentConfig, type BuilderConfig, type BuilderRootConfig, ComponentItem, Header, Modal, type OnActionsCallback, type Overrides, type SoftComponent, type SoftComponents, SoftConfigProvider, type VersionedSoftComponent, confirm, createActionCallback, createSoftConfigStore, createUseSoftConfig, notify, resolveSoftConfig, setConfirmHandler, setNotificationHandler, useBuild, useCancel, useComplete, useDecompose, useDemolish, useInspect, useRemodel, useSetDefaultVersion, useSoftConfig };
|