Skip to content

Commit 19c5fbc

Browse files
committed
feat: insert
1 parent 90d8140 commit 19c5fbc

File tree

8 files changed

+267
-294
lines changed

8 files changed

+267
-294
lines changed

demos/noengine/engine.js

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,34 +6310,8 @@ var Layout = /** @class */ (function (_super) {
63106310
};
63116311
Layout.prototype.init = function (template, style, attrValueProcessor) {
63126312
debugInfo.start('init');
6313-
var parseConfig = {
6314-
attributeNamePrefix: '',
6315-
attrNodeName: 'attr', // default is 'false'
6316-
textNodeName: '#text',
6317-
ignoreAttributes: false,
6318-
ignoreNameSpace: true,
6319-
allowBooleanAttributes: true,
6320-
parseNodeValue: false,
6321-
parseAttributeValue: false,
6322-
trimValues: true,
6323-
parseTrueNumberOnly: false,
6324-
alwaysCreateTextNode: true,
6325-
};
6326-
if (attrValueProcessor && typeof attrValueProcessor === 'function') {
6327-
// @ts-ignore
6328-
parseConfig.attrValueProcessor = attrValueProcessor;
6329-
}
6330-
debugInfo.start('init_xmlParse');
6331-
// 将xml字符串解析成xml节点树
6332-
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6333-
// console.log(jsonObj)
6334-
debugInfo.end('init_xmlParse');
6335-
var xmlTree = jsonObj.children[0];
6336-
// XML树生成渲染树
6337-
debugInfo.start('init_xml2Layout');
6338-
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(this, xmlTree, style);
6339-
debugInfo.end('init_xml2Layout');
6340-
this.add(layoutTree);
6313+
var elementArray = this.insertElementArray(template, style, attrValueProcessor, true);
6314+
this.add(elementArray[0]);
63416315
this.state = _common_util__WEBPACK_IMPORTED_MODULE_5__.STATE.INITED;
63426316
this.ticker.add(this.tickerFunc, true);
63436317
this.ticker.start();
@@ -6574,37 +6548,14 @@ var Layout = /** @class */ (function (_super) {
65746548
* 创建节点,创建之后会返回Element列表,可以传入parent立刻插入节点,也可以稍后主动appendChild到需要的节点下
65756549
*/
65766550
Layout.prototype.insertElement = function (template, style, parent) {
6577-
var _this = this;
6578-
var parseConfig = {
6579-
attributeNamePrefix: '',
6580-
attrNodeName: 'attr', // default is 'false'
6581-
textNodeName: '#text',
6582-
ignoreAttributes: false,
6583-
ignoreNameSpace: true,
6584-
allowBooleanAttributes: true,
6585-
parseNodeValue: false,
6586-
parseAttributeValue: false,
6587-
trimValues: true,
6588-
parseTrueNumberOnly: false,
6589-
alwaysCreateTextNode: true,
6590-
};
6591-
debugInfo.start('create_xmlParse');
6592-
// 将xml字符串解析成xml节点树
6593-
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6594-
// console.log(jsonObj)
6595-
debugInfo.end('create_xmlParse');
6596-
var getElements = [];
6597-
jsonObj.children.forEach(function (xmlTree) {
6598-
// XML树生成渲染树
6599-
debugInfo.start('create_xml2Layout');
6600-
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(_this, xmlTree, style);
6601-
debugInfo.end('create_xml2Layout');
6551+
var elementArray = this.insertElementArray(template, style);
6552+
elementArray.forEach(function (it) {
6553+
(0,_common_vd__WEBPACK_IMPORTED_MODULE_10__.iterateTree)(it, function (element) { return element.observeStyleAndEvent(); });
66026554
if (parent) {
6603-
parent.appendChild(layoutTree);
6555+
parent.appendChild(it);
66046556
}
6605-
getElements.push(layoutTree);
66066557
});
6607-
return getElements;
6558+
return elementArray;
66086559
};
66096560
/**
66106561
* 克隆节点,克隆后的节点可以添加到 Layout 的某个节点中
@@ -6649,6 +6600,46 @@ var Layout = /** @class */ (function (_super) {
66496600
// console.log(`[Layout] 插件 ${plugin.name || ''} 已卸载`)
66506601
Layout.installedPlugins.splice(pluginIndex, 1);
66516602
};
6603+
/**
6604+
* 创建节点,创建之后会返回Element列表
6605+
*/
6606+
Layout.prototype.insertElementArray = function (template, style, attrValueProcessor, onlyFirst) {
6607+
var _this = this;
6608+
var parseConfig = {
6609+
attributeNamePrefix: '',
6610+
attrNodeName: 'attr', // default is 'false'
6611+
textNodeName: '#text',
6612+
ignoreAttributes: false,
6613+
ignoreNameSpace: true,
6614+
allowBooleanAttributes: true,
6615+
parseNodeValue: false,
6616+
parseAttributeValue: false,
6617+
trimValues: true,
6618+
parseTrueNumberOnly: false,
6619+
alwaysCreateTextNode: true,
6620+
};
6621+
if (attrValueProcessor && typeof attrValueProcessor === 'function') {
6622+
// @ts-ignore
6623+
parseConfig.attrValueProcessor = attrValueProcessor;
6624+
}
6625+
debugInfo.start('insert_xmlParse');
6626+
// 将xml字符串解析成xml节点树
6627+
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6628+
// console.log(jsonObj)
6629+
debugInfo.end('insert_xmlParse');
6630+
var getElements = [];
6631+
jsonObj.children.forEach(function (xmlTree, index) {
6632+
if (onlyFirst && index > 0) {
6633+
return;
6634+
}
6635+
// XML树生成渲染树
6636+
debugInfo.start('insert_xml2Layout');
6637+
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(_this, xmlTree, style);
6638+
debugInfo.end('insert_xml2Layout');
6639+
getElements.push(layoutTree);
6640+
});
6641+
return getElements;
6642+
};
66526643
Layout.installedPlugins = [];
66536644
return Layout;
66546645
}(_components_elements__WEBPACK_IMPORTED_MODULE_1__["default"]));

demos/noengine/sub/engine.js

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,34 +6310,8 @@ var Layout = /** @class */ (function (_super) {
63106310
};
63116311
Layout.prototype.init = function (template, style, attrValueProcessor) {
63126312
debugInfo.start('init');
6313-
var parseConfig = {
6314-
attributeNamePrefix: '',
6315-
attrNodeName: 'attr', // default is 'false'
6316-
textNodeName: '#text',
6317-
ignoreAttributes: false,
6318-
ignoreNameSpace: true,
6319-
allowBooleanAttributes: true,
6320-
parseNodeValue: false,
6321-
parseAttributeValue: false,
6322-
trimValues: true,
6323-
parseTrueNumberOnly: false,
6324-
alwaysCreateTextNode: true,
6325-
};
6326-
if (attrValueProcessor && typeof attrValueProcessor === 'function') {
6327-
// @ts-ignore
6328-
parseConfig.attrValueProcessor = attrValueProcessor;
6329-
}
6330-
debugInfo.start('init_xmlParse');
6331-
// 将xml字符串解析成xml节点树
6332-
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6333-
// console.log(jsonObj)
6334-
debugInfo.end('init_xmlParse');
6335-
var xmlTree = jsonObj.children[0];
6336-
// XML树生成渲染树
6337-
debugInfo.start('init_xml2Layout');
6338-
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(this, xmlTree, style);
6339-
debugInfo.end('init_xml2Layout');
6340-
this.add(layoutTree);
6313+
var elementArray = this.insertElementArray(template, style, attrValueProcessor, true);
6314+
this.add(elementArray[0]);
63416315
this.state = _common_util__WEBPACK_IMPORTED_MODULE_5__.STATE.INITED;
63426316
this.ticker.add(this.tickerFunc, true);
63436317
this.ticker.start();
@@ -6574,37 +6548,14 @@ var Layout = /** @class */ (function (_super) {
65746548
* 创建节点,创建之后会返回Element列表,可以传入parent立刻插入节点,也可以稍后主动appendChild到需要的节点下
65756549
*/
65766550
Layout.prototype.insertElement = function (template, style, parent) {
6577-
var _this = this;
6578-
var parseConfig = {
6579-
attributeNamePrefix: '',
6580-
attrNodeName: 'attr', // default is 'false'
6581-
textNodeName: '#text',
6582-
ignoreAttributes: false,
6583-
ignoreNameSpace: true,
6584-
allowBooleanAttributes: true,
6585-
parseNodeValue: false,
6586-
parseAttributeValue: false,
6587-
trimValues: true,
6588-
parseTrueNumberOnly: false,
6589-
alwaysCreateTextNode: true,
6590-
};
6591-
debugInfo.start('create_xmlParse');
6592-
// 将xml字符串解析成xml节点树
6593-
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6594-
// console.log(jsonObj)
6595-
debugInfo.end('create_xmlParse');
6596-
var getElements = [];
6597-
jsonObj.children.forEach(function (xmlTree) {
6598-
// XML树生成渲染树
6599-
debugInfo.start('create_xml2Layout');
6600-
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(_this, xmlTree, style);
6601-
debugInfo.end('create_xml2Layout');
6551+
var elementArray = this.insertElementArray(template, style);
6552+
elementArray.forEach(function (it) {
6553+
(0,_common_vd__WEBPACK_IMPORTED_MODULE_10__.iterateTree)(it, function (element) { return element.observeStyleAndEvent(); });
66026554
if (parent) {
6603-
parent.appendChild(layoutTree);
6555+
parent.appendChild(it);
66046556
}
6605-
getElements.push(layoutTree);
66066557
});
6607-
return getElements;
6558+
return elementArray;
66086559
};
66096560
/**
66106561
* 克隆节点,克隆后的节点可以添加到 Layout 的某个节点中
@@ -6649,6 +6600,46 @@ var Layout = /** @class */ (function (_super) {
66496600
// console.log(`[Layout] 插件 ${plugin.name || ''} 已卸载`)
66506601
Layout.installedPlugins.splice(pluginIndex, 1);
66516602
};
6603+
/**
6604+
* 创建节点,创建之后会返回Element列表
6605+
*/
6606+
Layout.prototype.insertElementArray = function (template, style, attrValueProcessor, onlyFirst) {
6607+
var _this = this;
6608+
var parseConfig = {
6609+
attributeNamePrefix: '',
6610+
attrNodeName: 'attr', // default is 'false'
6611+
textNodeName: '#text',
6612+
ignoreAttributes: false,
6613+
ignoreNameSpace: true,
6614+
allowBooleanAttributes: true,
6615+
parseNodeValue: false,
6616+
parseAttributeValue: false,
6617+
trimValues: true,
6618+
parseTrueNumberOnly: false,
6619+
alwaysCreateTextNode: true,
6620+
};
6621+
if (attrValueProcessor && typeof attrValueProcessor === 'function') {
6622+
// @ts-ignore
6623+
parseConfig.attrValueProcessor = attrValueProcessor;
6624+
}
6625+
debugInfo.start('insert_xmlParse');
6626+
// 将xml字符串解析成xml节点树
6627+
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6628+
// console.log(jsonObj)
6629+
debugInfo.end('insert_xmlParse');
6630+
var getElements = [];
6631+
jsonObj.children.forEach(function (xmlTree, index) {
6632+
if (onlyFirst && index > 0) {
6633+
return;
6634+
}
6635+
// XML树生成渲染树
6636+
debugInfo.start('insert_xml2Layout');
6637+
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(_this, xmlTree, style);
6638+
debugInfo.end('insert_xml2Layout');
6639+
getElements.push(layoutTree);
6640+
});
6641+
return getElements;
6642+
};
66526643
Layout.installedPlugins = [];
66536644
return Layout;
66546645
}(_components_elements__WEBPACK_IMPORTED_MODULE_1__["default"]));

dist/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ declare class Layout extends Element {
718718
* 卸载给定插件
719719
*/
720720
unUse(plugin: IPlugin<Layout>, ...options: any[]): void;
721+
/**
722+
* 创建节点,创建之后会返回Element列表
723+
*/
724+
private insertElementArray;
721725
}
722726
declare const layout: Layout;
723727

dist/index.js

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,34 +6310,8 @@ var Layout = /** @class */ (function (_super) {
63106310
};
63116311
Layout.prototype.init = function (template, style, attrValueProcessor) {
63126312
debugInfo.start('init');
6313-
var parseConfig = {
6314-
attributeNamePrefix: '',
6315-
attrNodeName: 'attr', // default is 'false'
6316-
textNodeName: '#text',
6317-
ignoreAttributes: false,
6318-
ignoreNameSpace: true,
6319-
allowBooleanAttributes: true,
6320-
parseNodeValue: false,
6321-
parseAttributeValue: false,
6322-
trimValues: true,
6323-
parseTrueNumberOnly: false,
6324-
alwaysCreateTextNode: true,
6325-
};
6326-
if (attrValueProcessor && typeof attrValueProcessor === 'function') {
6327-
// @ts-ignore
6328-
parseConfig.attrValueProcessor = attrValueProcessor;
6329-
}
6330-
debugInfo.start('init_xmlParse');
6331-
// 将xml字符串解析成xml节点树
6332-
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6333-
// console.log(jsonObj)
6334-
debugInfo.end('init_xmlParse');
6335-
var xmlTree = jsonObj.children[0];
6336-
// XML树生成渲染树
6337-
debugInfo.start('init_xml2Layout');
6338-
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(this, xmlTree, style);
6339-
debugInfo.end('init_xml2Layout');
6340-
this.add(layoutTree);
6313+
var elementArray = this.insertElementArray(template, style, attrValueProcessor, true);
6314+
this.add(elementArray[0]);
63416315
this.state = _common_util__WEBPACK_IMPORTED_MODULE_5__.STATE.INITED;
63426316
this.ticker.add(this.tickerFunc, true);
63436317
this.ticker.start();
@@ -6574,37 +6548,14 @@ var Layout = /** @class */ (function (_super) {
65746548
* 创建节点,创建之后会返回Element列表,可以传入parent立刻插入节点,也可以稍后主动appendChild到需要的节点下
65756549
*/
65766550
Layout.prototype.insertElement = function (template, style, parent) {
6577-
var _this = this;
6578-
var parseConfig = {
6579-
attributeNamePrefix: '',
6580-
attrNodeName: 'attr', // default is 'false'
6581-
textNodeName: '#text',
6582-
ignoreAttributes: false,
6583-
ignoreNameSpace: true,
6584-
allowBooleanAttributes: true,
6585-
parseNodeValue: false,
6586-
parseAttributeValue: false,
6587-
trimValues: true,
6588-
parseTrueNumberOnly: false,
6589-
alwaysCreateTextNode: true,
6590-
};
6591-
debugInfo.start('create_xmlParse');
6592-
// 将xml字符串解析成xml节点树
6593-
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6594-
// console.log(jsonObj)
6595-
debugInfo.end('create_xmlParse');
6596-
var getElements = [];
6597-
jsonObj.children.forEach(function (xmlTree) {
6598-
// XML树生成渲染树
6599-
debugInfo.start('create_xml2Layout');
6600-
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(_this, xmlTree, style);
6601-
debugInfo.end('create_xml2Layout');
6551+
var elementArray = this.insertElementArray(template, style);
6552+
elementArray.forEach(function (it) {
6553+
(0,_common_vd__WEBPACK_IMPORTED_MODULE_10__.iterateTree)(it, function (element) { return element.observeStyleAndEvent(); });
66026554
if (parent) {
6603-
parent.appendChild(layoutTree);
6555+
parent.appendChild(it);
66046556
}
6605-
getElements.push(layoutTree);
66066557
});
6607-
return getElements;
6558+
return elementArray;
66086559
};
66096560
/**
66106561
* 克隆节点,克隆后的节点可以添加到 Layout 的某个节点中
@@ -6649,6 +6600,46 @@ var Layout = /** @class */ (function (_super) {
66496600
// console.log(`[Layout] 插件 ${plugin.name || ''} 已卸载`)
66506601
Layout.installedPlugins.splice(pluginIndex, 1);
66516602
};
6603+
/**
6604+
* 创建节点,创建之后会返回Element列表
6605+
*/
6606+
Layout.prototype.insertElementArray = function (template, style, attrValueProcessor, onlyFirst) {
6607+
var _this = this;
6608+
var parseConfig = {
6609+
attributeNamePrefix: '',
6610+
attrNodeName: 'attr', // default is 'false'
6611+
textNodeName: '#text',
6612+
ignoreAttributes: false,
6613+
ignoreNameSpace: true,
6614+
allowBooleanAttributes: true,
6615+
parseNodeValue: false,
6616+
parseAttributeValue: false,
6617+
trimValues: true,
6618+
parseTrueNumberOnly: false,
6619+
alwaysCreateTextNode: true,
6620+
};
6621+
if (attrValueProcessor && typeof attrValueProcessor === 'function') {
6622+
// @ts-ignore
6623+
parseConfig.attrValueProcessor = attrValueProcessor;
6624+
}
6625+
debugInfo.start('insert_xmlParse');
6626+
// 将xml字符串解析成xml节点树
6627+
var jsonObj = _libs_fast_xml_parser_parser_js__WEBPACK_IMPORTED_MODULE_6__.parse(template, parseConfig, true);
6628+
// console.log(jsonObj)
6629+
debugInfo.end('insert_xmlParse');
6630+
var getElements = [];
6631+
jsonObj.children.forEach(function (xmlTree, index) {
6632+
if (onlyFirst && index > 0) {
6633+
return;
6634+
}
6635+
// XML树生成渲染树
6636+
debugInfo.start('insert_xml2Layout');
6637+
var layoutTree = _common_vd__WEBPACK_IMPORTED_MODULE_10__.create.call(_this, xmlTree, style);
6638+
debugInfo.end('insert_xml2Layout');
6639+
getElements.push(layoutTree);
6640+
});
6641+
return getElements;
6642+
};
66526643
Layout.installedPlugins = [];
66536644
return Layout;
66546645
}(_components_elements__WEBPACK_IMPORTED_MODULE_1__["default"]));

0 commit comments

Comments
 (0)