|
@@ -1,7 +1,7 @@
|
|
|
import { useEditor } from "@/modules/editor";
|
|
|
import { DesignComp } from "@/modules/editor/defines/DesignTemp/DesignComp";
|
|
|
import { Background, Layout } from "@/modules/editor/typings";
|
|
|
-import { cloneDeep } from "lodash";
|
|
|
+import { cloneDeep, defaultsDeep } from "lodash";
|
|
|
import { AnyFun } from "queenjs/typing";
|
|
|
import { addCacheToMap } from "./createCompId";
|
|
|
|
|
@@ -15,14 +15,16 @@ type IOptions<T, C> = {
|
|
|
export function createCompHooks<T, C extends { [name: string]: AnyFun }>(
|
|
|
defaultOpts: IOptions<T, C>
|
|
|
) {
|
|
|
+
|
|
|
function createComp(opts: any) {
|
|
|
const defData: any = cloneDeep(defaultOpts);
|
|
|
if (defData.children) {
|
|
|
Object.entries(defData.children).forEach(([key, fn]: any) => {
|
|
|
- defData.children[key] = fn();
|
|
|
+ defData.children[key] = fn(defData);
|
|
|
});
|
|
|
}
|
|
|
- const options = Object.assign(defData, opts);
|
|
|
+ const options = defaultsDeep(opts, defData)
|
|
|
+
|
|
|
return new DesignComp(options);
|
|
|
}
|
|
|
|
|
@@ -38,7 +40,7 @@ export function createCompHooks<T, C extends { [name: string]: AnyFun }>(
|
|
|
function useCreateChild<T extends keyof C>(key: T) {
|
|
|
const editor = useEditor();
|
|
|
const createChild: any = (...args: any) => {
|
|
|
- const result = (defaultOpts as any).children[key](...args);
|
|
|
+ const result = (defaultOpts as any).children[key](defaultOpts, ...args);
|
|
|
addCacheToMap(editor.store.designData.compMap);
|
|
|
return result;
|
|
|
};
|