@netlisian/softconfig 0.0.7 → 0.0.9
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/puck/index.d.mts +56 -3
- package/dist/puck/index.d.ts +56 -3
- package/dist/puck/index.js +119 -20
- package/dist/puck/index.mjs +107 -8
- package/package.json +1 -1
package/dist/puck/index.d.mts
CHANGED
|
@@ -149,6 +149,56 @@ type VersionedSoftComponent = {
|
|
|
149
149
|
};
|
|
150
150
|
type SoftComponents = Record<string, VersionedSoftComponent>;
|
|
151
151
|
|
|
152
|
+
type ActionEventPayload = {
|
|
153
|
+
type: "build";
|
|
154
|
+
payload: {
|
|
155
|
+
id: string;
|
|
156
|
+
};
|
|
157
|
+
} | {
|
|
158
|
+
type: "remodel";
|
|
159
|
+
payload: {
|
|
160
|
+
id: string;
|
|
161
|
+
};
|
|
162
|
+
} | {
|
|
163
|
+
type: "complete";
|
|
164
|
+
payload: {
|
|
165
|
+
id: string;
|
|
166
|
+
componentData: DefaultComponentProps;
|
|
167
|
+
softComponent: SoftComponent;
|
|
168
|
+
};
|
|
169
|
+
} | {
|
|
170
|
+
type: "cancel";
|
|
171
|
+
payload: Record<string, never>;
|
|
172
|
+
} | {
|
|
173
|
+
type: "demolish";
|
|
174
|
+
payload: {
|
|
175
|
+
id: string;
|
|
176
|
+
};
|
|
177
|
+
} | {
|
|
178
|
+
type: "setDefaultVersion";
|
|
179
|
+
payload: {
|
|
180
|
+
id: string;
|
|
181
|
+
version: string;
|
|
182
|
+
};
|
|
183
|
+
} | {
|
|
184
|
+
type: "inspect";
|
|
185
|
+
payload: {
|
|
186
|
+
id: string;
|
|
187
|
+
};
|
|
188
|
+
} | {
|
|
189
|
+
type: "decompose";
|
|
190
|
+
payload: {
|
|
191
|
+
id: string;
|
|
192
|
+
};
|
|
193
|
+
} | {
|
|
194
|
+
type: "publish";
|
|
195
|
+
payload: {
|
|
196
|
+
id: string;
|
|
197
|
+
version: string;
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
type OnActionsCallback = (event: ActionEventPayload) => void | Promise<void>;
|
|
201
|
+
|
|
152
202
|
type RenderFunc<Props extends {
|
|
153
203
|
[key: string]: any;
|
|
154
204
|
} = {
|
|
@@ -178,6 +228,7 @@ type Overrides = {
|
|
|
178
228
|
subComponentPath: string[];
|
|
179
229
|
softComponent: VersionedSoftComponent["versions"][string];
|
|
180
230
|
}) => ((inputs: any[], props: DefaultComponentProps) => any) | undefined;
|
|
231
|
+
onActions?: OnActionsCallback;
|
|
181
232
|
};
|
|
182
233
|
|
|
183
234
|
type Status = "building" | "remodeling" | "ready" | "inspecting";
|
|
@@ -189,6 +240,7 @@ type AppStore = {
|
|
|
189
240
|
originalHistory: History[];
|
|
190
241
|
storedConfig?: Config;
|
|
191
242
|
overrides: Overrides;
|
|
243
|
+
onActions?: OnActionsCallback;
|
|
192
244
|
itemSelector: {
|
|
193
245
|
index: number;
|
|
194
246
|
zone: string;
|
|
@@ -217,7 +269,7 @@ type AppStore = {
|
|
|
217
269
|
removeSoftComponent: (key: string) => void;
|
|
218
270
|
};
|
|
219
271
|
type AppStoreApi = StoreApi<AppStore>;
|
|
220
|
-
declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides) => zustand.UseBoundStore<Omit<Omit<StoreApi<AppStore>, "subscribe"> & {
|
|
272
|
+
declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides, onActions?: OnActionsCallback) => zustand.UseBoundStore<Omit<Omit<StoreApi<AppStore>, "subscribe"> & {
|
|
221
273
|
subscribe: {
|
|
222
274
|
(listener: (selectedState: AppStore, previousSelectedState: AppStore) => void): () => void;
|
|
223
275
|
<U>(selector: (state: AppStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
|
|
@@ -243,12 +295,13 @@ declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: Soft
|
|
|
243
295
|
};
|
|
244
296
|
}>;
|
|
245
297
|
|
|
246
|
-
declare const SoftConfigProvider: ({ children, hardConfig, softComponents, overrides, value, }: {
|
|
298
|
+
declare const SoftConfigProvider: ({ children, hardConfig, softComponents, overrides, value, onActions, }: {
|
|
247
299
|
children: (softConfig: Config, softComponents: SoftComponents) => ReactNode;
|
|
248
300
|
hardConfig: Config;
|
|
249
301
|
softComponents: SoftComponents;
|
|
250
302
|
overrides: Overrides;
|
|
251
303
|
value?: StoreApi<AppStore>;
|
|
304
|
+
onActions?: OnActionsCallback;
|
|
252
305
|
}) => react_jsx_runtime.JSX.Element;
|
|
253
306
|
|
|
254
307
|
declare const createUseSoftConfig: () => <T>(selector: (state: AppStore) => T) => T;
|
|
@@ -356,4 +409,4 @@ declare const Modal: ({ children, onClose, isOpen, }: {
|
|
|
356
409
|
isOpen: boolean;
|
|
357
410
|
}) => react_jsx_runtime.JSX.Element;
|
|
358
411
|
|
|
359
|
-
export { ActionBarOverride as ActionBar, type AppStore, type AppStoreApi, type BuilderComponentConfig, type BuilderConfig, type BuilderRootConfig, ComponentItem, Header, Modal, type Overrides, type SoftComponent, type SoftComponents, SoftConfigProvider, confirm, createSoftConfigStore, createUseSoftConfig, notify, resolveSoftConfig, setConfirmHandler, setNotificationHandler, useBuild, useCancel, useComplete, useDecompose, useDemolish, useInspect, useRemodel, useSetDefaultVersion, useSoftConfig };
|
|
412
|
+
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 };
|
package/dist/puck/index.d.ts
CHANGED
|
@@ -149,6 +149,56 @@ type VersionedSoftComponent = {
|
|
|
149
149
|
};
|
|
150
150
|
type SoftComponents = Record<string, VersionedSoftComponent>;
|
|
151
151
|
|
|
152
|
+
type ActionEventPayload = {
|
|
153
|
+
type: "build";
|
|
154
|
+
payload: {
|
|
155
|
+
id: string;
|
|
156
|
+
};
|
|
157
|
+
} | {
|
|
158
|
+
type: "remodel";
|
|
159
|
+
payload: {
|
|
160
|
+
id: string;
|
|
161
|
+
};
|
|
162
|
+
} | {
|
|
163
|
+
type: "complete";
|
|
164
|
+
payload: {
|
|
165
|
+
id: string;
|
|
166
|
+
componentData: DefaultComponentProps;
|
|
167
|
+
softComponent: SoftComponent;
|
|
168
|
+
};
|
|
169
|
+
} | {
|
|
170
|
+
type: "cancel";
|
|
171
|
+
payload: Record<string, never>;
|
|
172
|
+
} | {
|
|
173
|
+
type: "demolish";
|
|
174
|
+
payload: {
|
|
175
|
+
id: string;
|
|
176
|
+
};
|
|
177
|
+
} | {
|
|
178
|
+
type: "setDefaultVersion";
|
|
179
|
+
payload: {
|
|
180
|
+
id: string;
|
|
181
|
+
version: string;
|
|
182
|
+
};
|
|
183
|
+
} | {
|
|
184
|
+
type: "inspect";
|
|
185
|
+
payload: {
|
|
186
|
+
id: string;
|
|
187
|
+
};
|
|
188
|
+
} | {
|
|
189
|
+
type: "decompose";
|
|
190
|
+
payload: {
|
|
191
|
+
id: string;
|
|
192
|
+
};
|
|
193
|
+
} | {
|
|
194
|
+
type: "publish";
|
|
195
|
+
payload: {
|
|
196
|
+
id: string;
|
|
197
|
+
version: string;
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
type OnActionsCallback = (event: ActionEventPayload) => void | Promise<void>;
|
|
201
|
+
|
|
152
202
|
type RenderFunc<Props extends {
|
|
153
203
|
[key: string]: any;
|
|
154
204
|
} = {
|
|
@@ -178,6 +228,7 @@ type Overrides = {
|
|
|
178
228
|
subComponentPath: string[];
|
|
179
229
|
softComponent: VersionedSoftComponent["versions"][string];
|
|
180
230
|
}) => ((inputs: any[], props: DefaultComponentProps) => any) | undefined;
|
|
231
|
+
onActions?: OnActionsCallback;
|
|
181
232
|
};
|
|
182
233
|
|
|
183
234
|
type Status = "building" | "remodeling" | "ready" | "inspecting";
|
|
@@ -189,6 +240,7 @@ type AppStore = {
|
|
|
189
240
|
originalHistory: History[];
|
|
190
241
|
storedConfig?: Config;
|
|
191
242
|
overrides: Overrides;
|
|
243
|
+
onActions?: OnActionsCallback;
|
|
192
244
|
itemSelector: {
|
|
193
245
|
index: number;
|
|
194
246
|
zone: string;
|
|
@@ -217,7 +269,7 @@ type AppStore = {
|
|
|
217
269
|
removeSoftComponent: (key: string) => void;
|
|
218
270
|
};
|
|
219
271
|
type AppStoreApi = StoreApi<AppStore>;
|
|
220
|
-
declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides) => zustand.UseBoundStore<Omit<Omit<StoreApi<AppStore>, "subscribe"> & {
|
|
272
|
+
declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: SoftComponents, overrides?: Overrides, onActions?: OnActionsCallback) => zustand.UseBoundStore<Omit<Omit<StoreApi<AppStore>, "subscribe"> & {
|
|
221
273
|
subscribe: {
|
|
222
274
|
(listener: (selectedState: AppStore, previousSelectedState: AppStore) => void): () => void;
|
|
223
275
|
<U>(selector: (state: AppStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
|
|
@@ -243,12 +295,13 @@ declare const createSoftConfigStore: (hardConfig?: Config, softComponents?: Soft
|
|
|
243
295
|
};
|
|
244
296
|
}>;
|
|
245
297
|
|
|
246
|
-
declare const SoftConfigProvider: ({ children, hardConfig, softComponents, overrides, value, }: {
|
|
298
|
+
declare const SoftConfigProvider: ({ children, hardConfig, softComponents, overrides, value, onActions, }: {
|
|
247
299
|
children: (softConfig: Config, softComponents: SoftComponents) => ReactNode;
|
|
248
300
|
hardConfig: Config;
|
|
249
301
|
softComponents: SoftComponents;
|
|
250
302
|
overrides: Overrides;
|
|
251
303
|
value?: StoreApi<AppStore>;
|
|
304
|
+
onActions?: OnActionsCallback;
|
|
252
305
|
}) => react_jsx_runtime.JSX.Element;
|
|
253
306
|
|
|
254
307
|
declare const createUseSoftConfig: () => <T>(selector: (state: AppStore) => T) => T;
|
|
@@ -356,4 +409,4 @@ declare const Modal: ({ children, onClose, isOpen, }: {
|
|
|
356
409
|
isOpen: boolean;
|
|
357
410
|
}) => react_jsx_runtime.JSX.Element;
|
|
358
411
|
|
|
359
|
-
export { ActionBarOverride as ActionBar, type AppStore, type AppStoreApi, type BuilderComponentConfig, type BuilderConfig, type BuilderRootConfig, ComponentItem, Header, Modal, type Overrides, type SoftComponent, type SoftComponents, SoftConfigProvider, confirm, createSoftConfigStore, createUseSoftConfig, notify, resolveSoftConfig, setConfirmHandler, setNotificationHandler, useBuild, useCancel, useComplete, useDecompose, useDemolish, useInspect, useRemodel, useSetDefaultVersion, useSoftConfig };
|
|
412
|
+
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 };
|
package/dist/puck/index.js
CHANGED
|
@@ -1863,7 +1863,7 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
|
1863
1863
|
// src/puck/store/index.tsx
|
|
1864
1864
|
var createSoftConfigStore = (hardConfig = {
|
|
1865
1865
|
components: {}
|
|
1866
|
-
}, softComponents = {}, overrides = {}) => {
|
|
1866
|
+
}, softComponents = {}, overrides = {}, onActions) => {
|
|
1867
1867
|
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
|
|
1868
1868
|
softComponents,
|
|
1869
1869
|
overrides.hydrateMapTransform
|
|
@@ -1874,6 +1874,7 @@ var createSoftConfigStore = (hardConfig = {
|
|
|
1874
1874
|
state: "ready",
|
|
1875
1875
|
originalHistory: [],
|
|
1876
1876
|
overrides,
|
|
1877
|
+
onActions,
|
|
1877
1878
|
storeHistory: (history) => set({ originalHistory: history }),
|
|
1878
1879
|
removeHistory: () => set({ originalHistory: [] }),
|
|
1879
1880
|
itemSelector: null,
|
|
@@ -2035,11 +2036,12 @@ var SoftConfigProvider = ({
|
|
|
2035
2036
|
hardConfig,
|
|
2036
2037
|
softComponents,
|
|
2037
2038
|
overrides,
|
|
2038
|
-
value
|
|
2039
|
+
value,
|
|
2040
|
+
onActions
|
|
2039
2041
|
}) => {
|
|
2040
2042
|
const store = value != null ? value : (0, import_react5.useMemo)(
|
|
2041
|
-
() => createSoftConfigStore(hardConfig, softComponents, overrides),
|
|
2042
|
-
[hardConfig, softComponents, overrides]
|
|
2043
|
+
() => createSoftConfigStore(hardConfig, softComponents, overrides, onActions),
|
|
2044
|
+
[hardConfig, softComponents, overrides, onActions]
|
|
2043
2045
|
);
|
|
2044
2046
|
const [softConfig, setSoftConfig] = (0, import_react5.useState)(
|
|
2045
2047
|
() => store.getState().softConfig
|
|
@@ -2085,6 +2087,25 @@ var notify = {
|
|
|
2085
2087
|
}
|
|
2086
2088
|
};
|
|
2087
2089
|
|
|
2090
|
+
// src/puck/hooks/useActionEvent.ts
|
|
2091
|
+
var import_react6 = require("react");
|
|
2092
|
+
var useActionEvent = () => {
|
|
2093
|
+
const onActions = useSoftConfig((s) => s.onActions);
|
|
2094
|
+
const triggerAction = (0, import_react6.useCallback)(
|
|
2095
|
+
(event) => __async(null, null, function* () {
|
|
2096
|
+
if (onActions) {
|
|
2097
|
+
try {
|
|
2098
|
+
yield onActions(event);
|
|
2099
|
+
} catch (error) {
|
|
2100
|
+
console.error("Error in onActions callback:", error);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
}),
|
|
2104
|
+
[onActions]
|
|
2105
|
+
);
|
|
2106
|
+
return { triggerAction };
|
|
2107
|
+
};
|
|
2108
|
+
|
|
2088
2109
|
// src/puck/actions/useBuild.tsx
|
|
2089
2110
|
var useCustomPuck2 = (0, import_puck4.createUsePuck)();
|
|
2090
2111
|
var useBuild = () => {
|
|
@@ -2094,6 +2115,7 @@ var useBuild = () => {
|
|
|
2094
2115
|
const itemSelector = useCustomPuck2((s) => s.appState.ui.itemSelector);
|
|
2095
2116
|
const dispatch = useCustomPuck2((s) => s.dispatch);
|
|
2096
2117
|
const status = useSoftConfig((s) => s.state);
|
|
2118
|
+
const { triggerAction } = useActionEvent();
|
|
2097
2119
|
const handleBuild = () => {
|
|
2098
2120
|
if (status !== "ready") {
|
|
2099
2121
|
notify.error("Can only build when in ready state.");
|
|
@@ -2101,6 +2123,14 @@ var useBuild = () => {
|
|
|
2101
2123
|
}
|
|
2102
2124
|
try {
|
|
2103
2125
|
build(history, selectedItem, itemSelector, dispatch);
|
|
2126
|
+
if (selectedItem == null ? void 0 : selectedItem.type) {
|
|
2127
|
+
triggerAction({
|
|
2128
|
+
type: "build",
|
|
2129
|
+
payload: {
|
|
2130
|
+
id: selectedItem.type
|
|
2131
|
+
}
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2104
2134
|
} catch (error) {
|
|
2105
2135
|
console.error("Failed to build:", error);
|
|
2106
2136
|
notify.error(
|
|
@@ -2122,6 +2152,7 @@ var useRemodel = () => {
|
|
|
2122
2152
|
const dispatch = useCustomPuck3((s) => s.dispatch);
|
|
2123
2153
|
const status = useSoftConfig((s) => s.state);
|
|
2124
2154
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2155
|
+
const { triggerAction } = useActionEvent();
|
|
2125
2156
|
const handleRemodel = (componentName) => {
|
|
2126
2157
|
if (status !== "ready") {
|
|
2127
2158
|
notify.error("Can only remodel when in ready state.");
|
|
@@ -2134,6 +2165,12 @@ var useRemodel = () => {
|
|
|
2134
2165
|
}
|
|
2135
2166
|
try {
|
|
2136
2167
|
remodel(history, selectedItem, itemSelector, dispatch);
|
|
2168
|
+
triggerAction({
|
|
2169
|
+
type: "remodel",
|
|
2170
|
+
payload: {
|
|
2171
|
+
id: name
|
|
2172
|
+
}
|
|
2173
|
+
});
|
|
2137
2174
|
} catch (error) {
|
|
2138
2175
|
console.error("Failed to remodel:", error);
|
|
2139
2176
|
notify.error(
|
|
@@ -2150,15 +2187,18 @@ var useRemodel = () => {
|
|
|
2150
2187
|
|
|
2151
2188
|
// src/puck/actions/useComplete.tsx
|
|
2152
2189
|
var import_puck6 = require("@measured/puck");
|
|
2153
|
-
var
|
|
2190
|
+
var import_react7 = require("react");
|
|
2154
2191
|
var useCustomPuck4 = (0, import_puck6.createUsePuck)();
|
|
2155
2192
|
var useComplete = () => {
|
|
2156
2193
|
const complete = useSoftConfig((s) => s.builder.complete);
|
|
2157
2194
|
const appState = useCustomPuck4((s) => s.appState);
|
|
2158
2195
|
const setHistories = useCustomPuck4((s) => s.history.setHistories);
|
|
2159
2196
|
const status = useSoftConfig((s) => s.state);
|
|
2160
|
-
const
|
|
2161
|
-
const
|
|
2197
|
+
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2198
|
+
const [newComponent, setNewComponent] = (0, import_react7.useState)(null);
|
|
2199
|
+
const { triggerAction } = useActionEvent();
|
|
2200
|
+
const handleComplete = (0, import_react7.useCallback)(() => {
|
|
2201
|
+
var _a, _b;
|
|
2162
2202
|
if (status === "ready") {
|
|
2163
2203
|
notify.error("Not building or remodeling a component.");
|
|
2164
2204
|
return null;
|
|
@@ -2166,6 +2206,18 @@ var useComplete = () => {
|
|
|
2166
2206
|
try {
|
|
2167
2207
|
const componentName = complete(appState, setHistories);
|
|
2168
2208
|
setNewComponent(componentName);
|
|
2209
|
+
const componentData = appState.data.root;
|
|
2210
|
+
const softComponent = (_b = softComponents[componentName]) == null ? void 0 : _b.versions[(_a = softComponents[componentName]) == null ? void 0 : _a.defaultVersion];
|
|
2211
|
+
if (softComponent && componentData) {
|
|
2212
|
+
triggerAction({
|
|
2213
|
+
type: "complete",
|
|
2214
|
+
payload: {
|
|
2215
|
+
id: componentName,
|
|
2216
|
+
componentData,
|
|
2217
|
+
softComponent
|
|
2218
|
+
}
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2169
2221
|
return componentName;
|
|
2170
2222
|
} catch (error) {
|
|
2171
2223
|
console.error("Failed to complete:", error);
|
|
@@ -2174,7 +2226,7 @@ var useComplete = () => {
|
|
|
2174
2226
|
);
|
|
2175
2227
|
return null;
|
|
2176
2228
|
}
|
|
2177
|
-
}, [complete, appState, setHistories, status]);
|
|
2229
|
+
}, [complete, appState, setHistories, status, softComponents, triggerAction]);
|
|
2178
2230
|
const canComplete = status === "building" || status === "remodeling";
|
|
2179
2231
|
return { handleComplete, canComplete, newComponent, setNewComponent };
|
|
2180
2232
|
};
|
|
@@ -2186,6 +2238,7 @@ var useCancel = () => {
|
|
|
2186
2238
|
const cancel = useSoftConfig((s) => s.builder.cancel);
|
|
2187
2239
|
const setHistories = useCustomPuck5((s) => s.history.setHistories);
|
|
2188
2240
|
const status = useSoftConfig((s) => s.state);
|
|
2241
|
+
const { triggerAction } = useActionEvent();
|
|
2189
2242
|
const handleCancel = () => {
|
|
2190
2243
|
if (status === "ready") {
|
|
2191
2244
|
notify.error("Nothing to cancel.");
|
|
@@ -2193,6 +2246,10 @@ var useCancel = () => {
|
|
|
2193
2246
|
}
|
|
2194
2247
|
try {
|
|
2195
2248
|
cancel(setHistories);
|
|
2249
|
+
triggerAction({
|
|
2250
|
+
type: "cancel",
|
|
2251
|
+
payload: {}
|
|
2252
|
+
});
|
|
2196
2253
|
} catch (error) {
|
|
2197
2254
|
console.error("Failed to cancel:", error);
|
|
2198
2255
|
notify.error(
|
|
@@ -2206,13 +2263,14 @@ var useCancel = () => {
|
|
|
2206
2263
|
|
|
2207
2264
|
// src/puck/actions/useInspect.tsx
|
|
2208
2265
|
var import_puck8 = require("@measured/puck");
|
|
2209
|
-
var
|
|
2266
|
+
var import_react8 = require("react");
|
|
2210
2267
|
var useCustomPuck6 = (0, import_puck8.createUsePuck)();
|
|
2211
2268
|
var useInspect = (componentName) => {
|
|
2212
2269
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
2213
2270
|
const dispatch = useCustomPuck6((s) => s.dispatch);
|
|
2214
2271
|
const status = useSoftConfig((s) => s.state);
|
|
2215
|
-
|
|
2272
|
+
const { triggerAction } = useActionEvent();
|
|
2273
|
+
(0, import_react8.useEffect)(() => {
|
|
2216
2274
|
if (status !== "inspecting") return;
|
|
2217
2275
|
if (!componentName) {
|
|
2218
2276
|
notify.error("No component to inspect.");
|
|
@@ -2220,13 +2278,19 @@ var useInspect = (componentName) => {
|
|
|
2220
2278
|
}
|
|
2221
2279
|
try {
|
|
2222
2280
|
inspect(componentName, dispatch);
|
|
2281
|
+
triggerAction({
|
|
2282
|
+
type: "inspect",
|
|
2283
|
+
payload: {
|
|
2284
|
+
id: componentName
|
|
2285
|
+
}
|
|
2286
|
+
});
|
|
2223
2287
|
} catch (error) {
|
|
2224
2288
|
console.error("Failed to inspect:", error);
|
|
2225
2289
|
notify.error(
|
|
2226
2290
|
"Failed to inspect: " + (error instanceof Error ? error.message : String(error))
|
|
2227
2291
|
);
|
|
2228
2292
|
}
|
|
2229
|
-
}, [status, componentName, inspect, dispatch]);
|
|
2293
|
+
}, [status, componentName, inspect, dispatch, triggerAction]);
|
|
2230
2294
|
};
|
|
2231
2295
|
|
|
2232
2296
|
// src/puck/actions/useDecompose.tsx
|
|
@@ -2240,6 +2304,7 @@ var useDecompose = () => {
|
|
|
2240
2304
|
const status = useSoftConfig((s) => s.state);
|
|
2241
2305
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2242
2306
|
const config = useSoftConfig((s) => s.softConfig);
|
|
2307
|
+
const { triggerAction } = useActionEvent();
|
|
2243
2308
|
const handleDecompose = (componentData) => {
|
|
2244
2309
|
if (status !== "ready") {
|
|
2245
2310
|
notify.error("Can only decompose when in ready state.");
|
|
@@ -2272,6 +2337,12 @@ var useDecompose = () => {
|
|
|
2272
2337
|
type: "setData",
|
|
2273
2338
|
data: newData
|
|
2274
2339
|
});
|
|
2340
|
+
triggerAction({
|
|
2341
|
+
type: "decompose",
|
|
2342
|
+
payload: {
|
|
2343
|
+
id: componentName
|
|
2344
|
+
}
|
|
2345
|
+
});
|
|
2275
2346
|
} catch (error) {
|
|
2276
2347
|
console.error("Failed to decompose:", error);
|
|
2277
2348
|
notify.error(
|
|
@@ -2295,6 +2366,7 @@ var useDemolish = () => {
|
|
|
2295
2366
|
const data = useCustomPuck8((s) => s.appState.data);
|
|
2296
2367
|
const status = useSoftConfig((s) => s.state);
|
|
2297
2368
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2369
|
+
const { triggerAction } = useActionEvent();
|
|
2298
2370
|
const handleDemolish = (componentName) => {
|
|
2299
2371
|
if (status !== "ready") {
|
|
2300
2372
|
notify.error("Can only demolish when in ready state.");
|
|
@@ -2306,6 +2378,12 @@ var useDemolish = () => {
|
|
|
2306
2378
|
}
|
|
2307
2379
|
try {
|
|
2308
2380
|
demolish(componentName, data, dispatch);
|
|
2381
|
+
triggerAction({
|
|
2382
|
+
type: "demolish",
|
|
2383
|
+
payload: {
|
|
2384
|
+
id: componentName
|
|
2385
|
+
}
|
|
2386
|
+
});
|
|
2309
2387
|
} catch (error) {
|
|
2310
2388
|
console.error("Failed to demolish:", error);
|
|
2311
2389
|
notify.error(
|
|
@@ -2326,6 +2404,7 @@ var useSetDefaultVersion = () => {
|
|
|
2326
2404
|
);
|
|
2327
2405
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2328
2406
|
const status = useSoftConfig((s) => s.state);
|
|
2407
|
+
const { triggerAction } = useActionEvent();
|
|
2329
2408
|
const handleSetDefaultVersion = (componentName, version) => {
|
|
2330
2409
|
if (status !== "ready") {
|
|
2331
2410
|
return;
|
|
@@ -2338,6 +2417,13 @@ var useSetDefaultVersion = () => {
|
|
|
2338
2417
|
return;
|
|
2339
2418
|
}
|
|
2340
2419
|
setSoftComponentDefaultVersion(componentName, version);
|
|
2420
|
+
triggerAction({
|
|
2421
|
+
type: "setDefaultVersion",
|
|
2422
|
+
payload: {
|
|
2423
|
+
id: componentName,
|
|
2424
|
+
version
|
|
2425
|
+
}
|
|
2426
|
+
});
|
|
2341
2427
|
};
|
|
2342
2428
|
const canSetDefaultVersion = (componentName, version) => {
|
|
2343
2429
|
const component = softComponents[componentName];
|
|
@@ -2372,7 +2458,9 @@ var usePublish = () => {
|
|
|
2372
2458
|
const components = useSoftConfig((s) => s.softComponents);
|
|
2373
2459
|
const data = useCustomPuck9((s) => s.appState.data);
|
|
2374
2460
|
const status = useSoftConfig((s) => s.state);
|
|
2461
|
+
const { triggerAction } = useActionEvent();
|
|
2375
2462
|
const handlePublish = (publish) => {
|
|
2463
|
+
var _a, _b;
|
|
2376
2464
|
if (status !== "ready") {
|
|
2377
2465
|
notify.error("Can only publish when in ready state.");
|
|
2378
2466
|
return;
|
|
@@ -2382,6 +2470,17 @@ var usePublish = () => {
|
|
|
2382
2470
|
return;
|
|
2383
2471
|
}
|
|
2384
2472
|
publish(data, components);
|
|
2473
|
+
const rootComponentType = (_a = data.root) == null ? void 0 : _a.type;
|
|
2474
|
+
const rootVersion = (_b = components[rootComponentType]) == null ? void 0 : _b.defaultVersion;
|
|
2475
|
+
if (rootComponentType && rootVersion) {
|
|
2476
|
+
triggerAction({
|
|
2477
|
+
type: "publish",
|
|
2478
|
+
payload: {
|
|
2479
|
+
id: rootComponentType,
|
|
2480
|
+
version: rootVersion
|
|
2481
|
+
}
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2385
2484
|
};
|
|
2386
2485
|
const canPublish = status === "ready";
|
|
2387
2486
|
return { handlePublish, canPublish };
|
|
@@ -2474,7 +2573,7 @@ var ActionBarOverride = (props) => {
|
|
|
2474
2573
|
};
|
|
2475
2574
|
|
|
2476
2575
|
// src/puck/overrides/ComponentItem.tsx
|
|
2477
|
-
var
|
|
2576
|
+
var import_react10 = require("react");
|
|
2478
2577
|
var import_puck14 = require("@measured/puck");
|
|
2479
2578
|
var import_lucide_react2 = require("lucide-react");
|
|
2480
2579
|
|
|
@@ -2499,7 +2598,7 @@ var confirm = (message) => __async(null, null, function* () {
|
|
|
2499
2598
|
var ComponentItem_module_default = { "ComponentItem": "_ComponentItem_lp9eh_1", "ComponentItem-content": "_ComponentItem-content_lp9eh_14", "ComponentItem-name": "_ComponentItem-name_lp9eh_24", "ComponentItem-version": "_ComponentItem-version_lp9eh_28", "ComponentItem-actions": "_ComponentItem-actions_lp9eh_33", "ComponentItem-settingsButton": "_ComponentItem-settingsButton_lp9eh_39", "ComponentItem-grip": "_ComponentItem-grip_lp9eh_49", "ComponentItem-modal": "_ComponentItem-modal_lp9eh_56", "ComponentItem-modalHeader": "_ComponentItem-modalHeader_lp9eh_63", "ComponentItem-modalTitle": "_ComponentItem-modalTitle_lp9eh_68", "ComponentItem-modalSubtitle": "_ComponentItem-modalSubtitle_lp9eh_75", "ComponentItem-modalBody": "_ComponentItem-modalBody_lp9eh_81", "ComponentItem-section": "_ComponentItem-section_lp9eh_90", "ComponentItem-sectionTitle": "_ComponentItem-sectionTitle_lp9eh_96", "ComponentItem-sectionDescription": "_ComponentItem-sectionDescription_lp9eh_103", "ComponentItem-versionList": "_ComponentItem-versionList_lp9eh_109", "ComponentItem-versionRow": "_ComponentItem-versionRow_lp9eh_115", "ComponentItem-versionRow--isDefault": "_ComponentItem-versionRow--isDefault_lp9eh_126", "ComponentItem-versionRow--isMarkedForDeletion": "_ComponentItem-versionRow--isMarkedForDeletion_lp9eh_131", "ComponentItem-versionInfo": "_ComponentItem-versionInfo_lp9eh_136", "ComponentItem-versionNumber": "_ComponentItem-versionNumber_lp9eh_143", "ComponentItem-defaultBadge": "_ComponentItem-defaultBadge_lp9eh_149", "ComponentItem-deleteBadge": "_ComponentItem-deleteBadge_lp9eh_160", "ComponentItem-versionActions": "_ComponentItem-versionActions_lp9eh_171", "ComponentItem-migrationOptions": "_ComponentItem-migrationOptions_lp9eh_177", "ComponentItem-select": "_ComponentItem-select_lp9eh_181", "ComponentItem-modalFooter": "_ComponentItem-modalFooter_lp9eh_202", "ComponentItem-footerLeft": "_ComponentItem-footerLeft_lp9eh_211", "ComponentItem-footerRight": "_ComponentItem-footerRight_lp9eh_216" };
|
|
2500
2599
|
|
|
2501
2600
|
// src/puck/components/modal/index.tsx
|
|
2502
|
-
var
|
|
2601
|
+
var import_react9 = require("react");
|
|
2503
2602
|
var import_react_dom = require("react-dom");
|
|
2504
2603
|
|
|
2505
2604
|
// css-module:D:\osamuProjects\netlisian\packages\soft-config\src\puck\components\modal\styles.module.css#css-module
|
|
@@ -2513,8 +2612,8 @@ var Modal = ({
|
|
|
2513
2612
|
onClose,
|
|
2514
2613
|
isOpen
|
|
2515
2614
|
}) => {
|
|
2516
|
-
const [rootEl, setRootEl] = (0,
|
|
2517
|
-
(0,
|
|
2615
|
+
const [rootEl, setRootEl] = (0, import_react9.useState)(null);
|
|
2616
|
+
(0, import_react9.useEffect)(() => {
|
|
2518
2617
|
setRootEl(document.getElementById("puck-portal-root"));
|
|
2519
2618
|
}, []);
|
|
2520
2619
|
if (!rootEl) {
|
|
@@ -2545,13 +2644,13 @@ var ComponentItem = (props) => {
|
|
|
2545
2644
|
);
|
|
2546
2645
|
const { handleDemolish } = useDemolish();
|
|
2547
2646
|
const { handleSetDefaultVersion, getVersions, getDefaultVersion } = useSetDefaultVersion();
|
|
2548
|
-
const [isEditing, setIsEditing] = (0,
|
|
2549
|
-
const [isHovering, setIsHovering] = (0,
|
|
2550
|
-
const [selectedVersion, setSelectedVersion] = (0,
|
|
2551
|
-
const [versionsToDelete, setVersionsToDelete] = (0,
|
|
2647
|
+
const [isEditing, setIsEditing] = (0, import_react10.useState)(false);
|
|
2648
|
+
const [isHovering, setIsHovering] = (0, import_react10.useState)(false);
|
|
2649
|
+
const [selectedVersion, setSelectedVersion] = (0, import_react10.useState)("");
|
|
2650
|
+
const [versionsToDelete, setVersionsToDelete] = (0, import_react10.useState)(
|
|
2552
2651
|
/* @__PURE__ */ new Set()
|
|
2553
2652
|
);
|
|
2554
|
-
const [migrateVersionMap, setMigrateVersionMap] = (0,
|
|
2653
|
+
const [migrateVersionMap, setMigrateVersionMap] = (0, import_react10.useState)({});
|
|
2555
2654
|
const versions = getVersions(props.name);
|
|
2556
2655
|
const defaultVersion = getDefaultVersion(props.name);
|
|
2557
2656
|
const handleApply = () => __async(null, null, function* () {
|
package/dist/puck/index.mjs
CHANGED
|
@@ -1813,7 +1813,7 @@ function buildInitialSoftComponents(hardConfig, softComponents, overrides) {
|
|
|
1813
1813
|
// src/puck/store/index.tsx
|
|
1814
1814
|
var createSoftConfigStore = (hardConfig = {
|
|
1815
1815
|
components: {}
|
|
1816
|
-
}, softComponents = {}, overrides = {}) => {
|
|
1816
|
+
}, softComponents = {}, overrides = {}, onActions) => {
|
|
1817
1817
|
const hydratedSoftComponents = (overrides == null ? void 0 : overrides.hydrateMapTransform) ? hydrateSoftComponentsTransforms(
|
|
1818
1818
|
softComponents,
|
|
1819
1819
|
overrides.hydrateMapTransform
|
|
@@ -1824,6 +1824,7 @@ var createSoftConfigStore = (hardConfig = {
|
|
|
1824
1824
|
state: "ready",
|
|
1825
1825
|
originalHistory: [],
|
|
1826
1826
|
overrides,
|
|
1827
|
+
onActions,
|
|
1827
1828
|
storeHistory: (history) => set({ originalHistory: history }),
|
|
1828
1829
|
removeHistory: () => set({ originalHistory: [] }),
|
|
1829
1830
|
itemSelector: null,
|
|
@@ -1985,11 +1986,12 @@ var SoftConfigProvider = ({
|
|
|
1985
1986
|
hardConfig,
|
|
1986
1987
|
softComponents,
|
|
1987
1988
|
overrides,
|
|
1988
|
-
value
|
|
1989
|
+
value,
|
|
1990
|
+
onActions
|
|
1989
1991
|
}) => {
|
|
1990
1992
|
const store = value != null ? value : useMemo2(
|
|
1991
|
-
() => createSoftConfigStore(hardConfig, softComponents, overrides),
|
|
1992
|
-
[hardConfig, softComponents, overrides]
|
|
1993
|
+
() => createSoftConfigStore(hardConfig, softComponents, overrides, onActions),
|
|
1994
|
+
[hardConfig, softComponents, overrides, onActions]
|
|
1993
1995
|
);
|
|
1994
1996
|
const [softConfig, setSoftConfig] = useState2(
|
|
1995
1997
|
() => store.getState().softConfig
|
|
@@ -2035,6 +2037,25 @@ var notify = {
|
|
|
2035
2037
|
}
|
|
2036
2038
|
};
|
|
2037
2039
|
|
|
2040
|
+
// src/puck/hooks/useActionEvent.ts
|
|
2041
|
+
import { useCallback } from "react";
|
|
2042
|
+
var useActionEvent = () => {
|
|
2043
|
+
const onActions = useSoftConfig((s) => s.onActions);
|
|
2044
|
+
const triggerAction = useCallback(
|
|
2045
|
+
(event) => __async(null, null, function* () {
|
|
2046
|
+
if (onActions) {
|
|
2047
|
+
try {
|
|
2048
|
+
yield onActions(event);
|
|
2049
|
+
} catch (error) {
|
|
2050
|
+
console.error("Error in onActions callback:", error);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
}),
|
|
2054
|
+
[onActions]
|
|
2055
|
+
);
|
|
2056
|
+
return { triggerAction };
|
|
2057
|
+
};
|
|
2058
|
+
|
|
2038
2059
|
// src/puck/actions/useBuild.tsx
|
|
2039
2060
|
var useCustomPuck2 = createUsePuck2();
|
|
2040
2061
|
var useBuild = () => {
|
|
@@ -2044,6 +2065,7 @@ var useBuild = () => {
|
|
|
2044
2065
|
const itemSelector = useCustomPuck2((s) => s.appState.ui.itemSelector);
|
|
2045
2066
|
const dispatch = useCustomPuck2((s) => s.dispatch);
|
|
2046
2067
|
const status = useSoftConfig((s) => s.state);
|
|
2068
|
+
const { triggerAction } = useActionEvent();
|
|
2047
2069
|
const handleBuild = () => {
|
|
2048
2070
|
if (status !== "ready") {
|
|
2049
2071
|
notify.error("Can only build when in ready state.");
|
|
@@ -2051,6 +2073,14 @@ var useBuild = () => {
|
|
|
2051
2073
|
}
|
|
2052
2074
|
try {
|
|
2053
2075
|
build(history, selectedItem, itemSelector, dispatch);
|
|
2076
|
+
if (selectedItem == null ? void 0 : selectedItem.type) {
|
|
2077
|
+
triggerAction({
|
|
2078
|
+
type: "build",
|
|
2079
|
+
payload: {
|
|
2080
|
+
id: selectedItem.type
|
|
2081
|
+
}
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2054
2084
|
} catch (error) {
|
|
2055
2085
|
console.error("Failed to build:", error);
|
|
2056
2086
|
notify.error(
|
|
@@ -2072,6 +2102,7 @@ var useRemodel = () => {
|
|
|
2072
2102
|
const dispatch = useCustomPuck3((s) => s.dispatch);
|
|
2073
2103
|
const status = useSoftConfig((s) => s.state);
|
|
2074
2104
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2105
|
+
const { triggerAction } = useActionEvent();
|
|
2075
2106
|
const handleRemodel = (componentName) => {
|
|
2076
2107
|
if (status !== "ready") {
|
|
2077
2108
|
notify.error("Can only remodel when in ready state.");
|
|
@@ -2084,6 +2115,12 @@ var useRemodel = () => {
|
|
|
2084
2115
|
}
|
|
2085
2116
|
try {
|
|
2086
2117
|
remodel(history, selectedItem, itemSelector, dispatch);
|
|
2118
|
+
triggerAction({
|
|
2119
|
+
type: "remodel",
|
|
2120
|
+
payload: {
|
|
2121
|
+
id: name
|
|
2122
|
+
}
|
|
2123
|
+
});
|
|
2087
2124
|
} catch (error) {
|
|
2088
2125
|
console.error("Failed to remodel:", error);
|
|
2089
2126
|
notify.error(
|
|
@@ -2100,15 +2137,18 @@ var useRemodel = () => {
|
|
|
2100
2137
|
|
|
2101
2138
|
// src/puck/actions/useComplete.tsx
|
|
2102
2139
|
import { createUsePuck as createUsePuck4 } from "@measured/puck";
|
|
2103
|
-
import { useState as useState3, useCallback } from "react";
|
|
2140
|
+
import { useState as useState3, useCallback as useCallback2 } from "react";
|
|
2104
2141
|
var useCustomPuck4 = createUsePuck4();
|
|
2105
2142
|
var useComplete = () => {
|
|
2106
2143
|
const complete = useSoftConfig((s) => s.builder.complete);
|
|
2107
2144
|
const appState = useCustomPuck4((s) => s.appState);
|
|
2108
2145
|
const setHistories = useCustomPuck4((s) => s.history.setHistories);
|
|
2109
2146
|
const status = useSoftConfig((s) => s.state);
|
|
2147
|
+
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2110
2148
|
const [newComponent, setNewComponent] = useState3(null);
|
|
2111
|
-
const
|
|
2149
|
+
const { triggerAction } = useActionEvent();
|
|
2150
|
+
const handleComplete = useCallback2(() => {
|
|
2151
|
+
var _a, _b;
|
|
2112
2152
|
if (status === "ready") {
|
|
2113
2153
|
notify.error("Not building or remodeling a component.");
|
|
2114
2154
|
return null;
|
|
@@ -2116,6 +2156,18 @@ var useComplete = () => {
|
|
|
2116
2156
|
try {
|
|
2117
2157
|
const componentName = complete(appState, setHistories);
|
|
2118
2158
|
setNewComponent(componentName);
|
|
2159
|
+
const componentData = appState.data.root;
|
|
2160
|
+
const softComponent = (_b = softComponents[componentName]) == null ? void 0 : _b.versions[(_a = softComponents[componentName]) == null ? void 0 : _a.defaultVersion];
|
|
2161
|
+
if (softComponent && componentData) {
|
|
2162
|
+
triggerAction({
|
|
2163
|
+
type: "complete",
|
|
2164
|
+
payload: {
|
|
2165
|
+
id: componentName,
|
|
2166
|
+
componentData,
|
|
2167
|
+
softComponent
|
|
2168
|
+
}
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2119
2171
|
return componentName;
|
|
2120
2172
|
} catch (error) {
|
|
2121
2173
|
console.error("Failed to complete:", error);
|
|
@@ -2124,7 +2176,7 @@ var useComplete = () => {
|
|
|
2124
2176
|
);
|
|
2125
2177
|
return null;
|
|
2126
2178
|
}
|
|
2127
|
-
}, [complete, appState, setHistories, status]);
|
|
2179
|
+
}, [complete, appState, setHistories, status, softComponents, triggerAction]);
|
|
2128
2180
|
const canComplete = status === "building" || status === "remodeling";
|
|
2129
2181
|
return { handleComplete, canComplete, newComponent, setNewComponent };
|
|
2130
2182
|
};
|
|
@@ -2136,6 +2188,7 @@ var useCancel = () => {
|
|
|
2136
2188
|
const cancel = useSoftConfig((s) => s.builder.cancel);
|
|
2137
2189
|
const setHistories = useCustomPuck5((s) => s.history.setHistories);
|
|
2138
2190
|
const status = useSoftConfig((s) => s.state);
|
|
2191
|
+
const { triggerAction } = useActionEvent();
|
|
2139
2192
|
const handleCancel = () => {
|
|
2140
2193
|
if (status === "ready") {
|
|
2141
2194
|
notify.error("Nothing to cancel.");
|
|
@@ -2143,6 +2196,10 @@ var useCancel = () => {
|
|
|
2143
2196
|
}
|
|
2144
2197
|
try {
|
|
2145
2198
|
cancel(setHistories);
|
|
2199
|
+
triggerAction({
|
|
2200
|
+
type: "cancel",
|
|
2201
|
+
payload: {}
|
|
2202
|
+
});
|
|
2146
2203
|
} catch (error) {
|
|
2147
2204
|
console.error("Failed to cancel:", error);
|
|
2148
2205
|
notify.error(
|
|
@@ -2162,6 +2219,7 @@ var useInspect = (componentName) => {
|
|
|
2162
2219
|
const inspect = useSoftConfig((s) => s.builder.inspect);
|
|
2163
2220
|
const dispatch = useCustomPuck6((s) => s.dispatch);
|
|
2164
2221
|
const status = useSoftConfig((s) => s.state);
|
|
2222
|
+
const { triggerAction } = useActionEvent();
|
|
2165
2223
|
useEffect3(() => {
|
|
2166
2224
|
if (status !== "inspecting") return;
|
|
2167
2225
|
if (!componentName) {
|
|
@@ -2170,13 +2228,19 @@ var useInspect = (componentName) => {
|
|
|
2170
2228
|
}
|
|
2171
2229
|
try {
|
|
2172
2230
|
inspect(componentName, dispatch);
|
|
2231
|
+
triggerAction({
|
|
2232
|
+
type: "inspect",
|
|
2233
|
+
payload: {
|
|
2234
|
+
id: componentName
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2173
2237
|
} catch (error) {
|
|
2174
2238
|
console.error("Failed to inspect:", error);
|
|
2175
2239
|
notify.error(
|
|
2176
2240
|
"Failed to inspect: " + (error instanceof Error ? error.message : String(error))
|
|
2177
2241
|
);
|
|
2178
2242
|
}
|
|
2179
|
-
}, [status, componentName, inspect, dispatch]);
|
|
2243
|
+
}, [status, componentName, inspect, dispatch, triggerAction]);
|
|
2180
2244
|
};
|
|
2181
2245
|
|
|
2182
2246
|
// src/puck/actions/useDecompose.tsx
|
|
@@ -2190,6 +2254,7 @@ var useDecompose = () => {
|
|
|
2190
2254
|
const status = useSoftConfig((s) => s.state);
|
|
2191
2255
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2192
2256
|
const config = useSoftConfig((s) => s.softConfig);
|
|
2257
|
+
const { triggerAction } = useActionEvent();
|
|
2193
2258
|
const handleDecompose = (componentData) => {
|
|
2194
2259
|
if (status !== "ready") {
|
|
2195
2260
|
notify.error("Can only decompose when in ready state.");
|
|
@@ -2222,6 +2287,12 @@ var useDecompose = () => {
|
|
|
2222
2287
|
type: "setData",
|
|
2223
2288
|
data: newData
|
|
2224
2289
|
});
|
|
2290
|
+
triggerAction({
|
|
2291
|
+
type: "decompose",
|
|
2292
|
+
payload: {
|
|
2293
|
+
id: componentName
|
|
2294
|
+
}
|
|
2295
|
+
});
|
|
2225
2296
|
} catch (error) {
|
|
2226
2297
|
console.error("Failed to decompose:", error);
|
|
2227
2298
|
notify.error(
|
|
@@ -2245,6 +2316,7 @@ var useDemolish = () => {
|
|
|
2245
2316
|
const data = useCustomPuck8((s) => s.appState.data);
|
|
2246
2317
|
const status = useSoftConfig((s) => s.state);
|
|
2247
2318
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2319
|
+
const { triggerAction } = useActionEvent();
|
|
2248
2320
|
const handleDemolish = (componentName) => {
|
|
2249
2321
|
if (status !== "ready") {
|
|
2250
2322
|
notify.error("Can only demolish when in ready state.");
|
|
@@ -2256,6 +2328,12 @@ var useDemolish = () => {
|
|
|
2256
2328
|
}
|
|
2257
2329
|
try {
|
|
2258
2330
|
demolish(componentName, data, dispatch);
|
|
2331
|
+
triggerAction({
|
|
2332
|
+
type: "demolish",
|
|
2333
|
+
payload: {
|
|
2334
|
+
id: componentName
|
|
2335
|
+
}
|
|
2336
|
+
});
|
|
2259
2337
|
} catch (error) {
|
|
2260
2338
|
console.error("Failed to demolish:", error);
|
|
2261
2339
|
notify.error(
|
|
@@ -2276,6 +2354,7 @@ var useSetDefaultVersion = () => {
|
|
|
2276
2354
|
);
|
|
2277
2355
|
const softComponents = useSoftConfig((s) => s.softComponents);
|
|
2278
2356
|
const status = useSoftConfig((s) => s.state);
|
|
2357
|
+
const { triggerAction } = useActionEvent();
|
|
2279
2358
|
const handleSetDefaultVersion = (componentName, version) => {
|
|
2280
2359
|
if (status !== "ready") {
|
|
2281
2360
|
return;
|
|
@@ -2288,6 +2367,13 @@ var useSetDefaultVersion = () => {
|
|
|
2288
2367
|
return;
|
|
2289
2368
|
}
|
|
2290
2369
|
setSoftComponentDefaultVersion(componentName, version);
|
|
2370
|
+
triggerAction({
|
|
2371
|
+
type: "setDefaultVersion",
|
|
2372
|
+
payload: {
|
|
2373
|
+
id: componentName,
|
|
2374
|
+
version
|
|
2375
|
+
}
|
|
2376
|
+
});
|
|
2291
2377
|
};
|
|
2292
2378
|
const canSetDefaultVersion = (componentName, version) => {
|
|
2293
2379
|
const component = softComponents[componentName];
|
|
@@ -2322,7 +2408,9 @@ var usePublish = () => {
|
|
|
2322
2408
|
const components = useSoftConfig((s) => s.softComponents);
|
|
2323
2409
|
const data = useCustomPuck9((s) => s.appState.data);
|
|
2324
2410
|
const status = useSoftConfig((s) => s.state);
|
|
2411
|
+
const { triggerAction } = useActionEvent();
|
|
2325
2412
|
const handlePublish = (publish) => {
|
|
2413
|
+
var _a, _b;
|
|
2326
2414
|
if (status !== "ready") {
|
|
2327
2415
|
notify.error("Can only publish when in ready state.");
|
|
2328
2416
|
return;
|
|
@@ -2332,6 +2420,17 @@ var usePublish = () => {
|
|
|
2332
2420
|
return;
|
|
2333
2421
|
}
|
|
2334
2422
|
publish(data, components);
|
|
2423
|
+
const rootComponentType = (_a = data.root) == null ? void 0 : _a.type;
|
|
2424
|
+
const rootVersion = (_b = components[rootComponentType]) == null ? void 0 : _b.defaultVersion;
|
|
2425
|
+
if (rootComponentType && rootVersion) {
|
|
2426
|
+
triggerAction({
|
|
2427
|
+
type: "publish",
|
|
2428
|
+
payload: {
|
|
2429
|
+
id: rootComponentType,
|
|
2430
|
+
version: rootVersion
|
|
2431
|
+
}
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2335
2434
|
};
|
|
2336
2435
|
const canPublish = status === "ready";
|
|
2337
2436
|
return { handlePublish, canPublish };
|