Skip to content

Commit 4d4a81c

Browse files
committed
feat(editor) include query parameters as editor params
1 parent 35d985c commit 4d4a81c

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

packages/editor/src/EasyblocksEditor.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export function EasyblocksEditor(props: EasyblocksEditorProps) {
6262
onExternalDataChange={props.onExternalDataChange ?? (() => ({}))}
6363
widgets={props.widgets}
6464
components={props.components}
65+
readOnly={props.readOnly}
66+
locale={props.locale}
67+
documentId={props.documentId}
68+
rootTemplate={props.rootTemplate}
69+
rootComponent={props.rootComponent}
6570
/>
6671
)}
6772

packages/editor/src/EasyblocksEditorProps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ export type EasyblocksEditorProps = {
2525
>;
2626

2727
__debug?: boolean;
28+
rootTemplate?: string;
29+
rootComponent?: string;
30+
locale?: string;
31+
documentId?: string;
32+
readOnly?: boolean;
2833
};

packages/editor/src/EasyblocksParent.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ type EasyblocksParentProps = {
3131
| ComponentType<InlineTypeWidgetComponentProps<any>>
3232
>;
3333
components?: Record<string, ComponentType<any>>;
34+
locale?: string;
35+
documentId?: string;
36+
rootComponent?: string;
37+
rootTemplate?: string;
38+
readOnly?: boolean;
3439
};
3540

3641
const shouldForwardProp: ShouldForwardProp<"web"> = (propName, target) => {
@@ -70,11 +75,15 @@ export function EasyblocksParent(props: EasyblocksParentProps) {
7075
/>
7176
<Editor
7277
config={props.config}
73-
locale={editorSearchParams.locale ?? undefined}
74-
readOnly={editorSearchParams.readOnly ?? true}
75-
documentId={editorSearchParams.documentId}
76-
rootComponentId={editorSearchParams.rootComponentId ?? null}
77-
rootTemplateId={editorSearchParams.rootTemplateId}
78+
locale={props.locale || editorSearchParams.locale || undefined}
79+
readOnly={props.readOnly ?? editorSearchParams.readOnly ?? true}
80+
documentId={props.documentId ?? editorSearchParams.documentId}
81+
rootComponentId={
82+
props.rootComponent ?? editorSearchParams.rootComponentId ?? null
83+
}
84+
rootTemplateId={
85+
props.rootTemplate ?? editorSearchParams.rootTemplateId
86+
}
7887
externalData={props.externalData}
7988
onExternalDataChange={props.onExternalDataChange}
8089
widgets={{

packages/editor/src/Editor.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ function EditorBackendInitializer(props: EditorProps) {
196196
}
197197

198198
setDocument(document);
199+
} else {
200+
setDocument(null);
199201
}
200202
} catch (error) {
201203
console.error(error);
@@ -209,7 +211,7 @@ function EditorBackendInitializer(props: EditorProps) {
209211
}
210212

211213
run();
212-
}, []);
214+
}, [props.documentId]);
213215

214216
if (!enabled) {
215217
return <AuthenticationScreen>Loading...</AuthenticationScreen>;
@@ -648,7 +650,7 @@ const EditorContent = ({
648650
const sidebarNodeRef = useRef<HTMLDivElement | null>(null);
649651

650652
const [editableData, form] = useForm({
651-
id: "easyblocks-editor",
653+
id: `easyblocks-editor-${initialEntry._id}`,
652654
label: "Edit entry",
653655
fields: [],
654656
initialValues: initialEntry,

packages/editor/src/useDataSaver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function useDataSaver(
1717
editorContext: EditorContextType
1818
) {
1919
const remoteDocument = useRef<Document | null>(initialDocument);
20+
remoteDocument.current = initialDocument;
2021

2122
/**
2223
* This state variable is going to be used ONLY for comparison with local config in case of missing document.
@@ -168,9 +169,10 @@ export function useDataSaver(
168169
}, 5000);
169170

170171
return () => {
172+
console.log("clearing");
171173
clearInterval(interval);
172174
};
173-
}, []);
175+
}, [initialDocument]);
174176

175177
return {
176178
saveNow: async () => {

0 commit comments

Comments
 (0)