mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-07 10:57:19 +00:00
fix: getSuitablePlace
This commit is contained in:
parent
f9d4ff61af
commit
db2b6d5218
@ -1,9 +1,7 @@
|
|||||||
{
|
{
|
||||||
"entry": {
|
"entry": {
|
||||||
"index": "src/index",
|
|
||||||
"editor-preset-vision": "../editor-preset-vision/src/index.ts",
|
"editor-preset-vision": "../editor-preset-vision/src/index.ts",
|
||||||
"react-simulator-renderer": "../react-simulator-renderer/src/index.ts",
|
"react-simulator-renderer": "../react-simulator-renderer/src/index.ts"
|
||||||
"rax-simulator-renderer": "../rax-simulator-renderer/src/index.ts"
|
|
||||||
},
|
},
|
||||||
"vendor": false,
|
"vendor": false,
|
||||||
"devServer": {
|
"devServer": {
|
||||||
|
|||||||
@ -108,7 +108,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
private _addons: { [key: string]: { exportData: () => any; isProp: boolean; } } = {};
|
private _addons: { [key: string]: { exportData: () => any; isProp: boolean } } = {};
|
||||||
|
|
||||||
@obx.ref private _parent: ParentalNode | null = null;
|
@obx.ref private _parent: ParentalNode | null = null;
|
||||||
|
|
||||||
@ -173,7 +173,10 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
this.settingEntry = this.document.designer.createSettingEntry([this]);
|
this.settingEntry = this.document.designer.createSettingEntry([this]);
|
||||||
this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children));
|
this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children));
|
||||||
this._children.internalInitParent();
|
this._children.internalInitParent();
|
||||||
this.props.import(this.upgradeProps(this.initProps(props || {})), this.upgradeProps(extras || {}));
|
this.props.import(
|
||||||
|
this.upgradeProps(this.initProps(props || {})),
|
||||||
|
this.upgradeProps(extras || {}),
|
||||||
|
);
|
||||||
this.setupAutoruns();
|
this.setupAutoruns();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,15 +599,21 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
import(data: Schema, checkId = false) {
|
import(data: Schema, checkId = false) {
|
||||||
const { componentName, id, children, props, ...extras } = data;
|
const { componentName, id, children, props, ...extras } = data;
|
||||||
if (this.isSlot()) {
|
if (this.isSlot()) {
|
||||||
foreachReverse(this.children, (subNode: Node) => {
|
foreachReverse(
|
||||||
subNode.remove(true, true);
|
this.children,
|
||||||
}, (iterable, idx) => (iterable as NodeChildren).get(idx));
|
(subNode: Node) => {
|
||||||
|
subNode.remove(true, true);
|
||||||
|
},
|
||||||
|
(iterable, idx) => (iterable as NodeChildren).get(idx),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (this.isParental()) {
|
if (this.isParental()) {
|
||||||
this.props.import(props, extras);
|
this.props.import(props, extras);
|
||||||
(this._children as NodeChildren).import(children, checkId);
|
(this._children as NodeChildren).import(children, checkId);
|
||||||
} else {
|
} else {
|
||||||
this.props.get('children', true)!.setValue(isDOMText(children) || isJSExpression(children) ? children : '');
|
this.props
|
||||||
|
.get('children', true)!
|
||||||
|
.setValue(isDOMText(children) || isJSExpression(children) ? children : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -768,7 +777,8 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
* 是否可执行某action
|
* 是否可执行某action
|
||||||
*/
|
*/
|
||||||
canPerformAction(action: string): boolean {
|
canPerformAction(action: string): boolean {
|
||||||
const availableActions = this.componentMeta?.availableActions?.map((action) => action.name) || [];
|
const availableActions =
|
||||||
|
this.componentMeta?.availableActions?.map((action) => action.name) || [];
|
||||||
return availableActions.indexOf(action) >= 0;
|
return availableActions.indexOf(action) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -837,7 +847,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
return this.children?.onChange(fn);
|
return this.children?.onChange(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeChildren(remover: () => any, adder: (children: Node[]) => NodeData[] | null, sorter: () => any) {
|
mergeChildren(
|
||||||
|
remover: () => any,
|
||||||
|
adder: (children: Node[]) => NodeData[] | null,
|
||||||
|
sorter: () => any,
|
||||||
|
) {
|
||||||
this.children?.mergeChildren(remover, adder, sorter);
|
this.children?.mergeChildren(remover, adder, sorter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -894,37 +908,60 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
getSuitablePlace(node: Node, ref: any): any {
|
getSuitablePlace(node: Node, ref: any): any {
|
||||||
|
const focusNode = this.document.focusNode;
|
||||||
|
if (!ref && this.contains(focusNode)) {
|
||||||
|
const rootCanDropIn = focusNode.componentMeta?.prototype?.options?.canDropIn;
|
||||||
|
if (
|
||||||
|
rootCanDropIn === undefined ||
|
||||||
|
rootCanDropIn === true ||
|
||||||
|
(typeof rootCanDropIn === 'function' && rootCanDropIn(node))
|
||||||
|
) {
|
||||||
|
return { container: focusNode };
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: remove these dirty code (for legao tranditional scene)
|
||||||
if (this.isRoot() && this.children) {
|
if (this.isRoot() && this.children) {
|
||||||
const dropElement = this.children.filter((c: Node) => {
|
const rootCanDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
||||||
|
if (
|
||||||
|
rootCanDropIn === undefined ||
|
||||||
|
rootCanDropIn === true ||
|
||||||
|
(typeof rootCanDropIn === 'function' && rootCanDropIn(node))
|
||||||
|
) {
|
||||||
|
return { container: this, ref };
|
||||||
|
}
|
||||||
|
|
||||||
|
const dropElement = this.children.filter((c) => {
|
||||||
if (!c.isContainer()) {
|
if (!c.isContainer()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const canDropIn = c.componentMeta?.prototype?.options?.canDropIn;
|
const canDropIn = c.componentMeta?.prototype?.options?.canDropIn;
|
||||||
if (typeof canDropIn === 'function') {
|
if (
|
||||||
return canDropIn(node);
|
canDropIn === undefined ||
|
||||||
} else if (typeof canDropIn === 'boolean') {
|
canDropIn === true ||
|
||||||
return canDropIn;
|
(typeof canDropIn === 'function' && canDropIn(node))
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
})[0];
|
})[0];
|
||||||
|
|
||||||
if (dropElement) {
|
if (dropElement) {
|
||||||
return { container: dropElement, ref };
|
return { container: dropElement };
|
||||||
}
|
}
|
||||||
const rootCanDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
|
||||||
if (rootCanDropIn === undefined
|
return null;
|
||||||
|| rootCanDropIn === true
|
|
||||||
|| (typeof rootCanDropIn === 'function' && rootCanDropIn(node))) {
|
|
||||||
return { container: this, ref };
|
|
||||||
}
|
|
||||||
// 假如最后找不到合适位置,返回 undefined 阻止继续插入节点
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const canDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
const canDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
||||||
if (this.isContainer()) {
|
if (this.isContainer()) {
|
||||||
if (canDropIn === undefined ||
|
if (
|
||||||
(typeof canDropIn === 'boolean' && canDropIn) ||
|
canDropIn === undefined ||
|
||||||
(typeof canDropIn === 'function' && canDropIn(node))) {
|
canDropIn === true ||
|
||||||
|
(typeof canDropIn === 'function' && canDropIn(node))
|
||||||
|
) {
|
||||||
return { container: this, ref };
|
return { container: this, ref };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1077,7 +1114,12 @@ export function comparePosition(node1: Node, node2: Node): PositionNO {
|
|||||||
return PositionNO.BeforeOrAfter;
|
return PositionNO.BeforeOrAfter;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function insertChild(container: ParentalNode, thing: Node | NodeData, at?: number | null, copy?: boolean): Node {
|
export function insertChild(
|
||||||
|
container: ParentalNode,
|
||||||
|
thing: Node | NodeData,
|
||||||
|
at?: number | null,
|
||||||
|
copy?: boolean,
|
||||||
|
): Node {
|
||||||
let node: Node;
|
let node: Node;
|
||||||
if (isNode(thing) && (copy || thing.isSlot())) {
|
if (isNode(thing) && (copy || thing.isSlot())) {
|
||||||
thing = thing.export(TransformStage.Clone);
|
thing = thing.export(TransformStage.Clone);
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# FIXME! do not run build
|
# FIXME! do not run build
|
||||||
lerna exec --scope @ali/lowcode-rax-renderer -- npm run build
|
|
||||||
lerna exec --scope @ali/lowcode-react-renderer -- npm run build
|
lerna exec --scope @ali/lowcode-react-renderer -- npm run build
|
||||||
lerna exec --scope @ali/lowcode-demo -- npm start
|
lerna exec --scope @ali/lowcode-demo -- npm start
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user