Skip to content

Commit

Permalink
feat(editor) include query parameters as editor params
Browse files Browse the repository at this point in the history
  • Loading branch information
maarten2424 committed Jun 18, 2024
1 parent 35d985c commit d86e458
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/editor/src/EasyblocksEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export function EasyblocksEditor(props: EasyblocksEditorProps) {
onExternalDataChange={props.onExternalDataChange ?? (() => ({}))}
widgets={props.widgets}
components={props.components}
readOnly={props.readOnly}
locale={props.locale}
documentId={props.documentId}
rootTemplate={props.rootTemplate}
rootComponent={props.rootComponent}
/>
)}

Expand Down
5 changes: 5 additions & 0 deletions packages/editor/src/EasyblocksEditorProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export type EasyblocksEditorProps = {
>;

__debug?: boolean;
rootTemplate?: string;
rootComponent?: string;
locale?: string;
documentId?: string;
readOnly?: boolean;
};
19 changes: 14 additions & 5 deletions packages/editor/src/EasyblocksParent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type EasyblocksParentProps = {
| ComponentType<InlineTypeWidgetComponentProps<any>>
>;
components?: Record<string, ComponentType<any>>;
locale?: string;
documentId?: string;
rootComponent?: string;
rootTemplate?: string;
readOnly?: boolean;
};

const shouldForwardProp: ShouldForwardProp<"web"> = (propName, target) => {
Expand Down Expand Up @@ -70,11 +75,15 @@ export function EasyblocksParent(props: EasyblocksParentProps) {
/>
<Editor
config={props.config}
locale={editorSearchParams.locale ?? undefined}
readOnly={editorSearchParams.readOnly ?? true}
documentId={editorSearchParams.documentId}
rootComponentId={editorSearchParams.rootComponentId ?? null}
rootTemplateId={editorSearchParams.rootTemplateId}
locale={props.locale || editorSearchParams.locale || undefined}
readOnly={props.readOnly ?? editorSearchParams.readOnly ?? true}
documentId={props.documentId ?? editorSearchParams.documentId}
rootComponentId={
props.rootComponent ?? editorSearchParams.rootComponentId ?? null
}
rootTemplateId={
props.rootTemplate ?? editorSearchParams.rootTemplateId
}
externalData={props.externalData}
onExternalDataChange={props.onExternalDataChange}
widgets={{
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const EditorWrapper = memo(
(props: EditorProps & { document: Document | null }) => {
if (!props.document) {
if (props.rootTemplateId) {
console.log(props.rootTemplateId);
if (props.rootComponentId) {
throw new Error(
"You can't pass both 'rootContainer' and 'rootTemplate' parameters to the editor"
Expand Down Expand Up @@ -648,7 +649,7 @@ const EditorContent = ({
const sidebarNodeRef = useRef<HTMLDivElement | null>(null);

const [editableData, form] = useForm({
id: "easyblocks-editor",
id: `easyblocks-editor-${initialEntry._id}`,
label: "Edit entry",
fields: [],
initialValues: initialEntry,
Expand Down

0 comments on commit d86e458

Please sign in to comment.