@xwadex/fesd-next 0.3.4-7.20 → 0.3.4-7.22
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/components/content-builders/blocks/base-block.d.ts +8 -0
- package/dist/components/content-builders/blocks/base-block.js +95 -0
- package/dist/components/content-builders/blocks/index.d.ts +4 -0
- package/dist/components/content-builders/blocks/index.js +4 -0
- package/dist/components/content-builders/blocks/media-content.d.ts +7 -0
- package/dist/components/content-builders/blocks/media-content.js +23 -0
- package/dist/components/content-builders/blocks/root-header.d.ts +19 -0
- package/dist/components/content-builders/blocks/root-header.js +84 -0
- package/dist/components/content-builders/blocks/roots.d.ts +8 -0
- package/dist/components/content-builders/blocks/roots.js +18 -0
- package/dist/components/content-builders/blocks/text-content.d.ts +20 -0
- package/dist/components/content-builders/blocks/text-content.js +126 -0
- package/dist/components/content-builders/content-builder-actionbar.d.ts +2 -0
- package/dist/components/content-builders/content-builder-actionbar.js +21 -0
- package/dist/components/content-builders/content-builder-blocks.d.ts +4 -0
- package/dist/components/content-builders/content-builder-blocks.js +15 -0
- package/dist/components/content-builders/content-builder-configs.d.ts +10 -0
- package/dist/components/content-builders/content-builder-configs.js +55 -0
- package/dist/components/content-builders/content-builder-context.d.ts +22 -0
- package/dist/components/content-builders/content-builder-context.js +46 -0
- package/dist/components/content-builders/content-builder-fields.d.ts +1 -0
- package/dist/components/content-builders/content-builder-fields.js +5 -0
- package/dist/components/content-builders/content-builder-functionbar.d.ts +1 -0
- package/dist/components/content-builders/content-builder-functionbar.js +25 -0
- package/dist/components/content-builders/content-builder-helpers.d.ts +14 -0
- package/dist/components/content-builders/content-builder-helpers.js +45 -0
- package/dist/components/content-builders/content-builder-hooks.d.ts +32 -0
- package/dist/components/content-builders/content-builder-hooks.js +65 -0
- package/dist/components/content-builders/content-builder-iframe.d.ts +1 -0
- package/dist/components/content-builders/content-builder-iframe.js +8 -0
- package/dist/components/content-builders/content-builder-initial.d.ts +84 -0
- package/dist/components/content-builders/content-builder-initial.js +135 -0
- package/dist/components/content-builders/content-builder-overlay.d.ts +1 -0
- package/dist/components/content-builders/content-builder-overlay.js +21 -0
- package/dist/components/content-builders/content-builder-panels.d.ts +10 -0
- package/dist/components/content-builders/content-builder-panels.js +162 -0
- package/dist/components/content-builders/content-builder-preview.d.ts +4 -0
- package/dist/components/content-builders/content-builder-preview.js +20 -0
- package/dist/components/content-builders/content-builder-pucks-context.d.ts +12 -0
- package/dist/components/content-builders/content-builder-pucks-context.js +17 -0
- package/dist/components/content-builders/content-builder-pucks-hooks.d.ts +17 -0
- package/dist/components/content-builders/content-builder-pucks-hooks.js +89 -0
- package/dist/components/content-builders/content-builder-roots.d.ts +15 -0
- package/dist/components/content-builders/content-builder-roots.js +13 -0
- package/dist/components/content-builders/content-builder.d.ts +7 -0
- package/dist/components/content-builders/content-builder.js +17 -0
- package/dist/components/content-builders/content-render.d.ts +7 -0
- package/dist/components/content-builders/content-render.js +8 -0
- package/dist/components/content-builders/fields/fields-tabs.d.ts +5 -0
- package/dist/components/content-builders/fields/fields-tabs.js +9 -0
- package/dist/components/content-builders/index.d.ts +6 -0
- package/dist/components/content-builders/index.js +6 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/puck-contents/puck-contents-editor.d.ts +1 -0
- package/dist/components/puck-contents/puck-contents-editor.js +2 -2
- package/dist/components/puck-contents/puck-contents-rander.js +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, memo, use } from "react";
|
|
4
|
+
import { useBuilderPucks } from "./content-builder-pucks-hooks";
|
|
5
|
+
import { useBuilderContext } from "./content-builder-context";
|
|
6
|
+
const BuilderPucksContext = createContext(null);
|
|
7
|
+
export const BuilderPucksContextProviders = memo(({ children }) => {
|
|
8
|
+
const { builderProps } = useBuilderContext();
|
|
9
|
+
const BuilderRoots = useBuilderPucks({ config: builderProps.config });
|
|
10
|
+
return _jsx(BuilderPucksContext, { value: BuilderRoots, children: children });
|
|
11
|
+
});
|
|
12
|
+
export const useBuilderPucksContext = () => {
|
|
13
|
+
const context = use(BuilderPucksContext);
|
|
14
|
+
if (!context)
|
|
15
|
+
throw new Error("BuilderPucksContext must be used inside BuilderPucksContextProviders");
|
|
16
|
+
return context;
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { scrollToBlock } from "./content-builder-helpers";
|
|
2
|
+
import type { Config, PuckApi } from "@puckeditor/core";
|
|
3
|
+
type UsePuckHook<C extends Config = Config> = <T = PuckApi<C>>(selector: (state: PuckApi<C>) => T) => T;
|
|
4
|
+
export declare const usePuck: UsePuckHook<Config>;
|
|
5
|
+
export declare const getPuckSelectedItem: () => import("@puckeditor/core").ComponentData<any, string, import("@puckeditor/core").DefaultComponents> | null;
|
|
6
|
+
export declare const getPuckPreviewMode: () => "edit" | "interactive";
|
|
7
|
+
export interface BuilderRootsHooks {
|
|
8
|
+
config: Config;
|
|
9
|
+
}
|
|
10
|
+
export declare const useBuilderPucks: ({ config }: BuilderRootsHooks) => {
|
|
11
|
+
setPreviewMode: (state: "edit" | "interactive" | ((previewMode: "edit" | "interactive") => typeof previewMode)) => void;
|
|
12
|
+
setComponentData: ({ propsKey, value }: any) => void;
|
|
13
|
+
selectBlock: (id?: string | null) => void;
|
|
14
|
+
insterBlock: (inster?: "before" | "after") => Promise<void>;
|
|
15
|
+
scrollToBlock: typeof scrollToBlock;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
|
+
import { createUsePuck, setDeep, useGetPuck, walkTree } from "@puckeditor/core";
|
|
4
|
+
import { createComponentId, scrollToBlock } from "./content-builder-helpers";
|
|
5
|
+
import { useBuilderContext } from "./content-builder-context";
|
|
6
|
+
export const usePuck = createUsePuck();
|
|
7
|
+
export const getPuckSelectedItem = () => usePuck((api) => api.selectedItem);
|
|
8
|
+
export const getPuckPreviewMode = () => usePuck((api) => api.appState.ui.previewMode);
|
|
9
|
+
export const useBuilderPucks = ({ config }) => {
|
|
10
|
+
const getPuck = useGetPuck();
|
|
11
|
+
const { selectBuilderBlocks, setBuilderPanels } = useBuilderContext();
|
|
12
|
+
const selectBlock = useCallback((id) => {
|
|
13
|
+
const { dispatch, getSelectorForId } = getPuck();
|
|
14
|
+
const selector = id ? getSelectorForId(id) : null;
|
|
15
|
+
dispatch({ type: "setUi", ui: { itemSelector: selector } });
|
|
16
|
+
}, []);
|
|
17
|
+
const unSelectBlock = useCallback(() => {
|
|
18
|
+
const { dispatch } = getPuck();
|
|
19
|
+
dispatch({ type: "setUi", ui: { itemSelector: undefined } });
|
|
20
|
+
}, []);
|
|
21
|
+
const onAfterInsterBlock = useCallback((id) => {
|
|
22
|
+
selectBlock(id);
|
|
23
|
+
requestAnimationFrame(() => scrollToBlock(id));
|
|
24
|
+
}, []);
|
|
25
|
+
const insterBlock = useCallback(async (inster) => {
|
|
26
|
+
const { appState, dispatch, selectedItem, getParentById } = getPuck();
|
|
27
|
+
const blockType = await selectBuilderBlocks?.();
|
|
28
|
+
if (typeof blockType !== "string")
|
|
29
|
+
return;
|
|
30
|
+
const { id: itemId } = selectedItem?.props ?? {};
|
|
31
|
+
const itemParent = itemId ? getParentById(itemId) : { type: "root" };
|
|
32
|
+
if (itemParent?.type !== "root")
|
|
33
|
+
return;
|
|
34
|
+
const nextContent = [...appState.data.content];
|
|
35
|
+
const selectedIndex = nextContent.findIndex((item) => item.props.id == itemId);
|
|
36
|
+
const safeIndex = selectedIndex < 0 ? nextContent.length : selectedIndex;
|
|
37
|
+
const insertIndex = inster === "before" ? safeIndex : safeIndex + 1;
|
|
38
|
+
const blockId = createComponentId(blockType);
|
|
39
|
+
dispatch({
|
|
40
|
+
type: "insert",
|
|
41
|
+
componentType: blockType,
|
|
42
|
+
destinationIndex: insertIndex,
|
|
43
|
+
destinationZone: "root:default-zone",
|
|
44
|
+
id: blockId,
|
|
45
|
+
});
|
|
46
|
+
requestAnimationFrame(() => onAfterInsterBlock(blockId));
|
|
47
|
+
}, [selectBuilderBlocks]);
|
|
48
|
+
const setComponentData = useCallback(({ propsKey, value }) => {
|
|
49
|
+
const { appState, dispatch, selectedItem, getParentById } = getPuck();
|
|
50
|
+
if (!selectedItem)
|
|
51
|
+
return;
|
|
52
|
+
const { id: itemId } = selectedItem.props;
|
|
53
|
+
const { id: parentId } = getParentById(itemId)?.props ?? {};
|
|
54
|
+
const nextData = walkTree(appState.data, config, (content, options) => parentId == options.parentId
|
|
55
|
+
? content.map((child) => child.props.id == itemId
|
|
56
|
+
? setDeep(child, propsKey, value)
|
|
57
|
+
: child)
|
|
58
|
+
: content);
|
|
59
|
+
dispatch({ type: "setData", data: nextData });
|
|
60
|
+
}, [config]);
|
|
61
|
+
const setPreviewMode = (state) => {
|
|
62
|
+
const { appState, dispatch } = getPuck();
|
|
63
|
+
const ui = {
|
|
64
|
+
previewMode: typeof state == "function" ? state(appState.ui.previewMode) : state,
|
|
65
|
+
itemSelector: null
|
|
66
|
+
};
|
|
67
|
+
dispatch({ type: "setUi", ui });
|
|
68
|
+
requestAnimationFrame(() => {
|
|
69
|
+
setBuilderPanels((panels) => Object.keys(panels).reduce((init, key) => {
|
|
70
|
+
const nextValue = { ...panels[key], active: false };
|
|
71
|
+
return { ...init, [key]: nextValue };
|
|
72
|
+
}, {}));
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const BuilderRoots = useMemo(() => ({
|
|
76
|
+
setPreviewMode,
|
|
77
|
+
setComponentData,
|
|
78
|
+
selectBlock,
|
|
79
|
+
insterBlock,
|
|
80
|
+
scrollToBlock
|
|
81
|
+
}), [
|
|
82
|
+
setPreviewMode,
|
|
83
|
+
setComponentData,
|
|
84
|
+
selectBlock,
|
|
85
|
+
insterBlock,
|
|
86
|
+
scrollToBlock
|
|
87
|
+
]);
|
|
88
|
+
return BuilderRoots;
|
|
89
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentData, Config, RootData } from "@puckeditor/core";
|
|
2
|
+
export interface PuckProps {
|
|
3
|
+
data: {
|
|
4
|
+
root: RootData;
|
|
5
|
+
content: ComponentData[];
|
|
6
|
+
};
|
|
7
|
+
overrides: Record<string, any>;
|
|
8
|
+
config: Config;
|
|
9
|
+
height?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface BuilderPuckRootProps extends PuckProps {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export declare const BuilderPuckRoot: React.FC<BuilderPuckRootProps>;
|
|
15
|
+
export declare const BuilderRoots: React.FC<React.ComponentProps<"div">>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { Puck, } from "@puckeditor/core";
|
|
4
|
+
import { useBuilderContext } from "./content-builder-context";
|
|
5
|
+
import { cn } from "../../shadcns/index.js";
|
|
6
|
+
export const BuilderPuckRoot = memo(({ height = "100%", ...props }) => {
|
|
7
|
+
return (_jsx(Puck, { height: height, ...props }));
|
|
8
|
+
});
|
|
9
|
+
export const BuilderRoots = memo((props) => {
|
|
10
|
+
const { builderRef, viewport } = useBuilderContext();
|
|
11
|
+
const isFullScreen = viewport.view == "fullscreen";
|
|
12
|
+
return (_jsx("div", { ref: builderRef, className: cn("w-full h-full relative", "data-[drag=true]:pointer-events-none!", isFullScreen && ["fixed top-0 w-screen h-screen"]), ...props }));
|
|
13
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PuckProps } from "./content-builder-roots";
|
|
2
|
+
import type { BuildersViewport } from "./content-builder-hooks";
|
|
3
|
+
export interface ContentBuilderProps extends PuckProps {
|
|
4
|
+
defaultViewport?: BuildersViewport["view"];
|
|
5
|
+
}
|
|
6
|
+
declare const ContentBuilder: React.FC<ContentBuilderProps>;
|
|
7
|
+
export { ContentBuilder };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { memo } from "react";
|
|
4
|
+
import { BuilderFunctionBar } from "./content-builder-functionbar";
|
|
5
|
+
import { BuilderContextProviders } from "./content-builder-context";
|
|
6
|
+
import { BuilderEditorPannel, BuilderPanelsContext } from "./content-builder-panels";
|
|
7
|
+
import { BuilderRoots, BuilderPuckRoot, } from "./content-builder-roots";
|
|
8
|
+
import { BuilderPreview } from "./content-builder-preview";
|
|
9
|
+
import { BuilderPucksContextProviders } from "./content-builder-pucks-context";
|
|
10
|
+
import { BuilderBlocks } from "./content-builder-blocks";
|
|
11
|
+
const ContentBuilder = memo((props) => {
|
|
12
|
+
if (!props?.data || !props?.config)
|
|
13
|
+
return null;
|
|
14
|
+
return (_jsx(BuilderContextProviders, { ...props, children: _jsx(BuilderRoots, { children: _jsx(BuilderPuckRoot, { ...props, children: _jsxs(BuilderPucksContextProviders, { children: [_jsx(BuilderPanelsContext, { children: _jsx(BuilderEditorPannel, {}) }), _jsx(BuilderBlocks, {}), _jsx(BuilderFunctionBar, {}), _jsx(BuilderPreview, {})] }) }) }) }));
|
|
15
|
+
});
|
|
16
|
+
ContentBuilder.displayName = "ContentBuilder";
|
|
17
|
+
export { ContentBuilder };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AutoField, FieldLabel } from "@puckeditor/core";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
const FieldsTabs = ({ onChange, value }) => {
|
|
5
|
+
const [tab, setTab] = useState("A");
|
|
6
|
+
return (_jsxs(FieldLabel, { label: "Title2", readOnly: true, children: [_jsxs("div", { className: "flex gap-2", children: [_jsx("button", { onClick: () => setTab("A"), className: "flex-1 p-2 border", children: "A" }), _jsx("button", { onClick: () => setTab("B"), className: "flex-1 p-2 border", children: "B" })] }), tab == "A" && _jsx("div", { children: _jsx(AutoField, { field: { type: "text" }, onChange: onChange, value: value ?? "wade", readOnly: true }) }), tab == "B" && _jsx("div", { children: "B" })] }));
|
|
7
|
+
};
|
|
8
|
+
FieldsTabs.displayName = "FieldsTabs";
|
|
9
|
+
export default FieldsTabs;
|
package/dist/components/index.js
CHANGED
|
@@ -4,13 +4,13 @@ import { Puck } from "@puckeditor/core";
|
|
|
4
4
|
import { editorConfig, editorConfigOverrides } from "./puck-configs";
|
|
5
5
|
import { useState } from "react";
|
|
6
6
|
import { useRouter } from "next/navigation";
|
|
7
|
-
const PuckContentsEditor = () => {
|
|
7
|
+
const PuckContentsEditor = ({ previewRoute = "/puck/previews" }) => {
|
|
8
8
|
const [state, setstate] = useState({});
|
|
9
9
|
const router = useRouter();
|
|
10
10
|
const save = (data) => {
|
|
11
11
|
console.log(data);
|
|
12
12
|
setstate(prev => ({ ...prev, data }));
|
|
13
|
-
router.push("/
|
|
13
|
+
router.push(`${previewRoute ?? "/previews"}?data=` + JSON.stringify(data));
|
|
14
14
|
};
|
|
15
15
|
return (_jsx(Puck, { config: editorConfig, data: {}, onPublish: save, overrides: editorConfigOverrides, height: "100%",
|
|
16
16
|
// _experimentalFullScreenCanvas
|
|
@@ -3,7 +3,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { Render } from "@puckeditor/core";
|
|
4
4
|
import { renderConfig } from "./puck-configs";
|
|
5
5
|
import { initialData } from "./puck-inital-datas";
|
|
6
|
+
import { useEffect } from "react";
|
|
6
7
|
const PuckContentsRander = ({ datas }) => {
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
console.log(datas);
|
|
10
|
+
}, [datas]);
|
|
7
11
|
return (_jsx(Render, { "data-id": "wade", config: renderConfig, data: datas ?? initialData }));
|
|
8
12
|
};
|
|
9
13
|
PuckContentsRander.displayName = "PuckContentsRander";
|