Skip to content

Commit c16ff45

Browse files
committed
feat(canvas): fix types
1 parent c5507b5 commit c16ff45

File tree

7 files changed

+36
-18
lines changed

7 files changed

+36
-18
lines changed

packages/core/src/compiler/builtins/$richText/$richText.editor.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ interface RichTextProps extends InternalNoCodeComponentProps {
7171
}
7272

7373
function RichTextEditor(props: RichTextProps) {
74-
const { editorContext } = (window.parent as any).editorWindowAPI;
74+
// const { editorContext } = (window.parent as any).editorWindowAPI;
7575
const { formValues, locales, locale, focussedField, definitions } =
7676
useEasyblocksCanvasContext();
7777

@@ -754,7 +754,10 @@ function RichTextEditor(props: RichTextProps) {
754754
function handleEditableCopy(event: React.ClipboardEvent) {
755755
const selectedRichTextComponentConfig = getRichTextComponentConfigFragment(
756756
richTextConfig,
757-
editorContext
757+
focussedField,
758+
locale,
759+
formValues,
760+
definitions
758761
);
759762

760763
event.clipboardData.setData(
@@ -775,8 +778,9 @@ function RichTextEditor(props: RichTextProps) {
775778
event.preventDefault();
776779

777780
const nextSlateValue = convertRichTextElementsToEditorValue(
778-
duplicateConfig(selectedRichTextComponentConfig, editorContext)
779-
.elements[locale]
781+
duplicateConfig(selectedRichTextComponentConfig, definitions).elements[
782+
locale
783+
]
780784
);
781785

782786
const temporaryEditor = createTemporaryEditor(editor);

packages/core/src/compiler/builtins/$richText/utils/getRichTextComponentConfigFragment.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,35 @@ import { stripRichTextPartSelection } from "./stripRichTextTextPartSelection";
1111

1212
function getRichTextComponentConfigFragment(
1313
sourceRichTextComponentConfig: RichTextComponentConfig,
14-
editorContext: EditorContextType
14+
focussedField: EditorContextType["focussedField"],
15+
locale: EditorContextType["contextParams"]["locale"],
16+
formValues: EditorContextType["form"]["values"],
17+
definitions: EditorContextType["definitions"]
1518
): RichTextComponentConfig & {
1619
_itemProps?: Record<string, unknown>;
1720
} {
18-
const { focussedField, form, contextParams } = editorContext;
19-
2021
const newRichTextComponentConfig: RichTextComponentConfig = {
2122
...sourceRichTextComponentConfig,
2223
elements: {
23-
[contextParams.locale]: [],
24+
[locale]: [],
2425
},
2526
};
2627

2728
focussedField.forEach((focusedField) => {
2829
const textPartConfig: RichTextPartComponentConfig = get(
29-
form.values,
30+
formValues,
3031
stripRichTextPartSelection(focusedField)
3132
);
3233

3334
const { path, range } = parseFocusedRichTextPartConfigPath(focusedField);
3435

35-
const newTextPartConfig = duplicateConfig(textPartConfig, editorContext);
36+
const newTextPartConfig = duplicateConfig(textPartConfig, definitions);
3637

3738
if (range) {
3839
newTextPartConfig.value = textPartConfig.value.slice(...range);
3940
}
4041

41-
let lastParentConfigPath = `elements.${contextParams.locale}`;
42+
let lastParentConfigPath = `elements.${locale}`;
4243

4344
path.slice(0, -1).forEach((pathIndex, index) => {
4445
let currentConfigPath = lastParentConfigPath;

packages/core/src/compiler/duplicateConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { deepClone, uniqueId } from "@easyblocks/utils";
22
import { NoCodeComponentEntry } from "../types";
33
import { configTraverse } from "./configTraverse";
44
import { traverseComponents } from "./traverseComponents";
5-
import { CompilationContextType } from "./types";
5+
import { AnyContextWithDefinitions } from "./types";
66

77
export function duplicateConfig<
88
ConfigType extends NoCodeComponentEntry = NoCodeComponentEntry
9-
>(inputConfig: ConfigType, compilationContext: CompilationContextType) {
9+
>(inputConfig: ConfigType, compilationContext: AnyContextWithDefinitions) {
1010
// deep copy first
1111
const config = deepClone(inputConfig);
1212

packages/core/src/compiler/traverseComponents.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NoCodeComponentEntry } from "../types";
22
import { findComponentDefinition } from "./findComponentDefinition";
33
import { isSchemaPropComponent } from "./schema";
4-
import { CompilationContextType } from "./types";
4+
import { AnyContextWithDefinitions } from "./types";
55

66
type TraverseComponentsCallback = (arg: {
77
path: string;
@@ -12,15 +12,15 @@ type TraverseComponentsCallback = (arg: {
1212
*/
1313
function traverseComponents(
1414
config: NoCodeComponentEntry,
15-
context: CompilationContextType,
15+
context: AnyContextWithDefinitions,
1616
callback: TraverseComponentsCallback
1717
): void {
1818
traverseComponentsInternal(config, context, callback, "");
1919
}
2020

2121
function traverseComponentsArray(
2222
array: NoCodeComponentEntry[],
23-
context: CompilationContextType,
23+
context: AnyContextWithDefinitions,
2424
callback: TraverseComponentsCallback,
2525
path: string
2626
) {
@@ -31,7 +31,7 @@ function traverseComponentsArray(
3131

3232
function traverseComponentsInternal(
3333
componentConfig: NoCodeComponentEntry,
34-
context: CompilationContextType,
34+
context: AnyContextWithDefinitions,
3535
callback: TraverseComponentsCallback,
3636
path: string
3737
) {

packages/core/src/compiler/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ export type EditorContextType = CompilationContextType & {
168168
actions: EditorActions;
169169
templates?: Template[];
170170
};
171+
172+
export type AnyContextWithDefinitions = {
173+
definitions: InternalComponentDefinitions;
174+
};

packages/editor/src/Editor.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,6 @@ const EditorContent = ({
873873
}, []);
874874

875875
useEffect(() => {
876-
sendCanvasData();
877876
if (window.editorWindowAPI.onUpdate) {
878877
window.editorWindowAPI.onUpdate();
879878
}
@@ -1124,6 +1123,11 @@ const EditorContent = ({
11241123
height={iframeSize.height}
11251124
transform={iframeSize.transform}
11261125
containerRef={iframeContainerRef}
1126+
onIframeLoaded={() => {
1127+
setTimeout(() => {
1128+
sendCanvasData();
1129+
}, 10);
1130+
}}
11271131
/>
11281132
{isEditing && (
11291133
<SelectionFrame

packages/editor/src/EditorIframe.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface EditorIframeWrapperProps {
1010
height: number;
1111
transform: string;
1212
containerRef: React.RefObject<HTMLDivElement>;
13+
onIframeLoaded?: () => void;
1314
}
1415

1516
function EditorIframe({
@@ -19,11 +20,15 @@ function EditorIframe({
1920
height,
2021
transform,
2122
containerRef,
23+
onIframeLoaded,
2224
}: EditorIframeWrapperProps) {
2325
const [isIframeReady, setIframeReady] = useState(false);
2426

2527
const handleIframeLoaded = () => {
2628
setIframeReady(true);
29+
if (onIframeLoaded) {
30+
onIframeLoaded();
31+
}
2732
};
2833

2934
useWindowKeyDown("z", onEditorHistoryUndo, {

0 commit comments

Comments
 (0)