mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-07 18:39:45 +08:00
fix(editor): 指定父节点添加组件
This commit is contained in:
parent
923e8ea5ab
commit
d334b697ae
@ -36,18 +36,13 @@ const doAction = async (
|
|||||||
let beforeArgs = args;
|
let beforeArgs = args;
|
||||||
|
|
||||||
for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
|
for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
|
||||||
let beforeReturnValue = (await beforeMethod(...beforeArgs)) || [];
|
beforeArgs = (await beforeMethod(...beforeArgs)) || [];
|
||||||
|
|
||||||
if (isError(beforeReturnValue)) throw beforeReturnValue;
|
if (isError(beforeArgs)) throw beforeArgs;
|
||||||
|
|
||||||
if (!Array.isArray(beforeReturnValue)) {
|
if (!Array.isArray(beforeArgs)) {
|
||||||
beforeReturnValue = [beforeReturnValue];
|
beforeArgs = [beforeArgs];
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeArgs = beforeArgs.map((v: any, index: number) => {
|
|
||||||
if (typeof beforeReturnValue[index] === 'undefined') return v;
|
|
||||||
return beforeReturnValue[index];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let returnValue: any = await fn(beforeArgs, sourceMethod.bind(scope));
|
let returnValue: any = await fn(beforeArgs, sourceMethod.bind(scope));
|
||||||
|
@ -303,7 +303,7 @@ class Editor extends BaseService {
|
|||||||
const stage = this.get<StageCore | null>('stage');
|
const stage = this.get<StageCore | null>('stage');
|
||||||
const root = this.get<MApp>('root');
|
const root = this.get<MApp>('root');
|
||||||
|
|
||||||
await stage?.add({ config: cloneDeep(newNode), root: cloneDeep(root) });
|
await stage?.add({ config: cloneDeep(newNode), parent: cloneDeep(parentNode), root: cloneDeep(root) });
|
||||||
|
|
||||||
if (layout === Layout.ABSOLUTE) {
|
if (layout === Layout.ABSOLUTE) {
|
||||||
const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
|
const fixedLeft = fixNodeLeft(newNode, parentNode, stage?.renderer.contentWindow?.document);
|
||||||
|
@ -223,7 +223,8 @@ export const fixNodeLeft = (config: MNode, parent: MContainer, doc?: Document) =
|
|||||||
const el = doc.getElementById(`${config.id}`);
|
const el = doc.getElementById(`${config.id}`);
|
||||||
const parentEl = doc.getElementById(`${parent.id}`);
|
const parentEl = doc.getElementById(`${parent.id}`);
|
||||||
|
|
||||||
if (el && parentEl && el.offsetWidth + config.style?.left > parentEl.offsetWidth) {
|
const left = Number(config.style?.left) || 0;
|
||||||
|
if (el && parentEl && el.offsetWidth + left > parentEl.offsetWidth) {
|
||||||
return parentEl.offsetWidth - el.offsetWidth;
|
return parentEl.offsetWidth - el.offsetWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user