Browse Source

Merge pull request #141 in FUI/fineui from ~GUY/fineui:master to master

* commit 'dfe5f49660a2e92388ec1d71a976aca9b1453de3':
  update
  update
es6
guy 7 years ago
parent
commit
f459426214
  1. 642
      bi/base.js
  2. 199
      bi/core.js
  3. 33
      demo/js/core/abstract/demo.virtual_group.js
  4. 199
      dist/bundle.js
  5. 80
      dist/bundle.min.js
  6. 199
      dist/core.js
  7. 33
      dist/demo.js
  8. 199
      src/core/wrapper/layout.js

642
bi/base.js

@ -16400,68 +16400,68 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, {
key: function (e) { key: function (e) {
} }
});/** });/**
* 颜色选择 * 颜色选择
* *
* Created by GUY on 2015/11/26. * Created by GUY on 2015/11/26.
* @class BI.RichEditorTextToolbar * @class BI.RichEditorTextToolbar
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { BI.RichEditorTextToolbar = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.RichEditorTextToolbar.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.RichEditorTextToolbar.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-rich-editor-text-toolbar bi-background", baseCls: "bi-rich-editor-text-toolbar bi-background",
buttons: [ buttons: [
{type: "bi.rich_editor_size_chooser"}, {type: "bi.rich_editor_size_chooser"},
{type: "bi.rich_editor_bold_button"}, {type: "bi.rich_editor_bold_button"},
{type: "bi.rich_editor_italic_button"}, {type: "bi.rich_editor_italic_button"},
{type: "bi.rich_editor_underline_button"}, {type: "bi.rich_editor_underline_button"},
{type: "bi.rich_editor_color_chooser"}, {type: "bi.rich_editor_color_chooser"},
{type: "bi.rich_editor_background_color_chooser"}, {type: "bi.rich_editor_background_color_chooser"},
{type: "bi.rich_editor_align_left_button"}, {type: "bi.rich_editor_align_left_button"},
{type: "bi.rich_editor_align_center_button"}, {type: "bi.rich_editor_align_center_button"},
{type: "bi.rich_editor_align_right_button"}, {type: "bi.rich_editor_align_right_button"},
{type: "bi.rich_editor_param_button"}, {type: "bi.rich_editor_param_button"},
], ],
height: 28 height: 28
}); });
}, },
_init: function () { _init: function () {
BI.RichEditorTextToolbar.superclass._init.apply(this, arguments); BI.RichEditorTextToolbar.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
BI.createWidget({ BI.createWidget({
type: "bi.left", type: "bi.left",
element: this, element: this,
items: BI.map(o.buttons, function (i, btn) { items: BI.map(o.buttons, function (i, btn) {
return BI.extend(btn, { return BI.extend(btn, {
editor: o.editor editor: o.editor
}); });
}), }),
hgap: 3, hgap: 3,
vgap: 3 vgap: 3
}) })
}, },
mounted: function () { mounted: function () {
var self = this; var self = this;
if (BI.isIE9Below()) {//IE8下必须要设置unselectable才能不blur输入框 if (BI.isIE9Below()) {//IE8下必须要设置unselectable才能不blur输入框
this.element.mousedown(function () { this.element.mousedown(function () {
self._noSelect(self.element[0]); self._noSelect(self.element[0]);
}); });
this._noSelect(this.element[0]); this._noSelect(this.element[0]);
} }
}, },
_noSelect: function (element) { _noSelect: function (element) {
if (element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') { if (element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') {
element.setAttribute('unselectable', 'on'); element.setAttribute('unselectable', 'on');
} }
for (var i = 0; i < element.childNodes.length; i++) { for (var i = 0; i < element.childNodes.length; i++) {
this._noSelect(element.childNodes[i]); this._noSelect(element.childNodes[i]);
} }
} }
}); });
BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/** BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/**
* 富文本编辑器 * 富文本编辑器
* *
@ -16742,57 +16742,57 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/**
} }
}); });
}()); }());
/** /**
* 颜色选择trigger * 颜色选择trigger
* *
* Created by GUY on 2015/11/26. * Created by GUY on 2015/11/26.
* @class BI.RichEditorBackgroundChooserTrigger * @class BI.RichEditorBackgroundChooserTrigger
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.RichEditorBackgroundChooserTrigger = BI.inherit(BI.Widget, { BI.RichEditorBackgroundChooserTrigger = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.RichEditorBackgroundChooserTrigger.superclass._defaultConfig.apply(this, arguments); var conf = BI.RichEditorBackgroundChooserTrigger.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
width: 20, width: 20,
height: 20 height: 20
}); });
}, },
_init: function () { _init: function () {
BI.RichEditorBackgroundChooserTrigger.superclass._init.apply(this, arguments); BI.RichEditorBackgroundChooserTrigger.superclass._init.apply(this, arguments);
this.font = BI.createWidget({ this.font = BI.createWidget({
type: "bi.icon_button", type: "bi.icon_button",
cls: "text-background-font" cls: "text-background-font"
}); });
this.underline = BI.createWidget({ this.underline = BI.createWidget({
type: "bi.icon_button", type: "bi.icon_button",
cls: "text-color-underline-font" cls: "text-color-underline-font"
}); });
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
element: this, element: this,
items: [{ items: [{
el: this.font, el: this.font,
top: 2, top: 2,
left: 2 left: 2
}, { }, {
el: this.underline, el: this.underline,
top: 7, top: 7,
left: 2 left: 2
}] }]
}) })
}, },
setValue: function (color) { setValue: function (color) {
this.underline.element.css("color", color); this.underline.element.css("color", color);
}, },
getValue: function () { getValue: function () {
return this.font.element.css("color"); return this.font.element.css("color");
} }
}); });
BI.shortcut('bi.rich_editor_background_color_chooser_trigger', BI.RichEditorBackgroundChooserTrigger);/** BI.shortcut('bi.rich_editor_background_color_chooser_trigger', BI.RichEditorBackgroundChooserTrigger);/**
* *
* Created by GUY on 2015/11/26. * Created by GUY on 2015/11/26.
@ -17060,214 +17060,214 @@ BI.RichEditorUnderlineButton = BI.inherit(BI.RichEditorAction, {
this.underline.setSelected(false); this.underline.setSelected(false);
}, },
}); });
BI.shortcut("bi.rich_editor_underline_button", BI.RichEditorUnderlineButton)/** BI.shortcut("bi.rich_editor_underline_button", BI.RichEditorUnderlineButton)/**
* 颜色选择trigger * 颜色选择trigger
* *
* Created by GUY on 2015/11/26. * Created by GUY on 2015/11/26.
* @class BI.RichEditorColorChooserTrigger * @class BI.RichEditorColorChooserTrigger
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.RichEditorColorChooserTrigger = BI.inherit(BI.Widget, { BI.RichEditorColorChooserTrigger = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.RichEditorColorChooserTrigger.superclass._defaultConfig.apply(this, arguments); var conf = BI.RichEditorColorChooserTrigger.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
width: 20, width: 20,
height: 20 height: 20
}); });
}, },
_init: function () { _init: function () {
BI.RichEditorColorChooserTrigger.superclass._init.apply(this, arguments); BI.RichEditorColorChooserTrigger.superclass._init.apply(this, arguments);
this.font = BI.createWidget({ this.font = BI.createWidget({
type: "bi.icon_button", type: "bi.icon_button",
cls: "text-color-font" cls: "text-color-font"
}); });
this.underline = BI.createWidget({ this.underline = BI.createWidget({
type: "bi.icon_button", type: "bi.icon_button",
cls: "text-color-underline-font" cls: "text-color-underline-font"
}); });
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
element: this, element: this,
items: [{ items: [{
el: this.font, el: this.font,
top: 2, top: 2,
left: 2 left: 2
}, { }, {
el: this.underline, el: this.underline,
top: 7, top: 7,
left: 2 left: 2
}] }]
}) })
}, },
setValue: function (color) { setValue: function (color) {
this.underline.element.css("color", color); this.underline.element.css("color", color);
}, },
getValue: function () { getValue: function () {
return this.font.element.css("color"); return this.font.element.css("color");
} }
}); });
BI.shortcut('bi.rich_editor_color_chooser_trigger', BI.RichEditorColorChooserTrigger);/** BI.shortcut('bi.rich_editor_color_chooser_trigger', BI.RichEditorColorChooserTrigger);/**
* 颜色选择 * 颜色选择
* *
* Created by GUY on 2015/11/26. * Created by GUY on 2015/11/26.
* @class BI.RichEditorBackgroundColorChooser * @class BI.RichEditorBackgroundColorChooser
* @extends BI.RichEditorAction * @extends BI.RichEditorAction
*/ */
BI.RichEditorBackgroundColorChooser = BI.inherit(BI.RichEditorAction, { BI.RichEditorBackgroundColorChooser = BI.inherit(BI.RichEditorAction, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.RichEditorBackgroundColorChooser.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.RichEditorBackgroundColorChooser.superclass._defaultConfig.apply(this, arguments), {
width: 20, width: 20,
height: 20, height: 20,
}); });
}, },
_init: function () { _init: function () {
BI.RichEditorBackgroundColorChooser.superclass._init.apply(this, arguments); BI.RichEditorBackgroundColorChooser.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.colorchooser = BI.createWidget({ this.colorchooser = BI.createWidget({
type: "bi.color_chooser", type: "bi.color_chooser",
element: this, element: this,
width: o.width, width: o.width,
height: o.height, height: o.height,
el: { el: {
type: "bi.rich_editor_background_color_chooser_trigger", type: "bi.rich_editor_background_color_chooser_trigger",
title: BI.i18nText("BI-Widget_Background_Colour"), title: BI.i18nText("BI-Widget_Background_Colour"),
cls: "text-toolbar-button" cls: "text-toolbar-button"
} }
}); });
this.colorchooser.on(BI.ColorChooser.EVENT_CHANGE, function () { this.colorchooser.on(BI.ColorChooser.EVENT_CHANGE, function () {
var backgroundColor = this.getValue(); var backgroundColor = this.getValue();
o.editor.element.css({ o.editor.element.css({
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
color: BI.DOM.getContrastColor(backgroundColor) color: BI.DOM.getContrastColor(backgroundColor)
}); });
this.setValue(""); this.setValue("");
}); });
}, },
deactivate: function () { deactivate: function () {
} }
}); });
BI.shortcut('bi.rich_editor_background_color_chooser', BI.RichEditorBackgroundColorChooser);/** BI.shortcut('bi.rich_editor_background_color_chooser', BI.RichEditorBackgroundColorChooser);/**
* 颜色选择 * 颜色选择
* *
* Created by GUY on 2015/11/26. * Created by GUY on 2015/11/26.
* @class BI.RichEditorColorChooser * @class BI.RichEditorColorChooser
* @extends BI.RichEditorAction * @extends BI.RichEditorAction
*/ */
BI.RichEditorColorChooser = BI.inherit(BI.RichEditorAction, { BI.RichEditorColorChooser = BI.inherit(BI.RichEditorAction, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.RichEditorColorChooser.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.RichEditorColorChooser.superclass._defaultConfig.apply(this, arguments), {
width: 20, width: 20,
height: 20, height: 20,
command: "foreColor" command: "foreColor"
}); });
}, },
_init: function () { _init: function () {
BI.RichEditorColorChooser.superclass._init.apply(this, arguments); BI.RichEditorColorChooser.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.colorchooser = BI.createWidget({ this.colorchooser = BI.createWidget({
type: "bi.color_chooser", type: "bi.color_chooser",
element: this, element: this,
width: o.width, width: o.width,
height: o.height, height: o.height,
el: { el: {
type: "bi.rich_editor_color_chooser_trigger", type: "bi.rich_editor_color_chooser_trigger",
title: BI.i18nText("BI-Font_Colour"), title: BI.i18nText("BI-Font_Colour"),
cls: "text-toolbar-button" cls: "text-toolbar-button"
} }
}); });
this.colorchooser.on(BI.ColorChooser.EVENT_CHANGE, function () { this.colorchooser.on(BI.ColorChooser.EVENT_CHANGE, function () {
self.doCommand(this.getValue()); self.doCommand(this.getValue());
}); });
}, },
deactivate: function () { deactivate: function () {
this.colorchooser.setValue(""); this.colorchooser.setValue("");
} }
}); });
BI.shortcut('bi.rich_editor_color_chooser', BI.RichEditorColorChooser);/** BI.shortcut('bi.rich_editor_color_chooser', BI.RichEditorColorChooser);/**
* 字体大小选择 * 字体大小选择
* *
* Created by GUY on 2015/11/26. * Created by GUY on 2015/11/26.
* @class BI.RichEditorSizeChooser * @class BI.RichEditorSizeChooser
* @extends BI.RichEditorAction * @extends BI.RichEditorAction
*/ */
BI.RichEditorSizeChooser = BI.inherit(BI.RichEditorAction, { BI.RichEditorSizeChooser = BI.inherit(BI.RichEditorAction, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.RichEditorSizeChooser.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.RichEditorSizeChooser.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-rich-editor-size-chooser bi-border bi-card", baseCls: "bi-rich-editor-size-chooser bi-border bi-card",
command: "FontSize", command: "FontSize",
width: 50, width: 50,
height: 20 height: 20
}); });
}, },
_items: [{ _items: [{
value: 1, value: 1,
text: "1(8pt)" text: "1(8pt)"
}, { }, {
value: 2, value: 2,
text: "2(10pt)" text: "2(10pt)"
}, { }, {
value: 3, value: 3,
text: "3(12pt)" text: "3(12pt)"
}, { }, {
value: 4, value: 4,
text: "4(14pt)" text: "4(14pt)"
}, { }, {
value: 5, value: 5,
text: "5(18pt)" text: "5(18pt)"
}, { }, {
value: 6, value: 6,
text: "6(24pt)" text: "6(24pt)"
}], }],
_init: function () { _init: function () {
BI.RichEditorSizeChooser.superclass._init.apply(this, arguments); BI.RichEditorSizeChooser.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.trigger = BI.createWidget({ this.trigger = BI.createWidget({
type: "bi.text_trigger", type: "bi.text_trigger",
readonly: true, readonly: true,
height: o.height, height: o.height,
triggerWidth: 12, triggerWidth: 12,
text: BI.i18nText("BI-Font_Size") text: BI.i18nText("BI-Font_Size")
}); });
this.combo = BI.createWidget({ this.combo = BI.createWidget({
type: "bi.combo", type: "bi.combo",
element: this, element: this,
el: this.trigger, el: this.trigger,
adjustLength: 1, adjustLength: 1,
popup: { popup: {
maxWidth: 70, maxWidth: 70,
minWidth: 70, minWidth: 70,
el: { el: {
type: "bi.button_group", type: "bi.button_group",
items: BI.createItems(this._items, { items: BI.createItems(this._items, {
type: "bi.single_select_item" type: "bi.single_select_item"
}), }),
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical"
}] }]
} }
} }
}); });
this.combo.on(BI.Combo.EVENT_CHANGE, function () { this.combo.on(BI.Combo.EVENT_CHANGE, function () {
var val = this.getValue()[0]; var val = this.getValue()[0];
self.doCommand(val); self.doCommand(val);
this.hideView(); this.hideView();
this.setValue([]); this.setValue([]);
}) })
} }
}); });
BI.shortcut('bi.rich_editor_size_chooser', BI.RichEditorSizeChooser);/** BI.shortcut('bi.rich_editor_size_chooser', BI.RichEditorSizeChooser);/**
* 富文本编辑器 * 富文本编辑器
* *

199
bi/core.js

@ -11527,31 +11527,192 @@ BI.Layout = BI.inherit(BI.Widget, {
}) })
}, },
update: function (opt) { patchItem: function (oldVnode, vnode, index) {
var o = this.options; if (!this._compare(oldVnode, vnode)) {
var items = opt.items || []; return this.updateItemAt(index, vnode);
var updated, i, len; }
for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { },
if (!this._compare(o.items[i], items[i])) {
updated = this.updateItemAt(i, items[i]) || updated; updateChildren: function (oldCh, newCh) {
var self = this;
var oldStartIdx = 0, newStartIdx = 0;
var oldEndIdx = oldCh.length - 1;
var oldStartVnode = oldCh[0];
var oldEndVnode = oldCh[oldEndIdx];
var newEndIdx = newCh.length - 1;
var newStartVnode = newCh[0];
var newEndVnode = newCh[newEndIdx];
var oldKeyToIdx;
var idxInOld;
var elmToMove;
var before;
var updated;
var children = {};
BI.each(oldCh, function (i, child) {
child = self._getOptions(child);
var key = child.key == null ? i : child.key;
if (BI.isKey(key)) {
children[key] = self._children[self._getChildName(i)];
}
});
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
if (BI.isNull(oldStartVnode)) {
oldStartVnode = oldCh[++oldStartIdx];
} else if (BI.isNull(oldEndVnode)) {
oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated;
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated;
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated;
insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated;
insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx];
} else {
if (oldKeyToIdx === undefined) {
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
}
idxInOld = oldKeyToIdx[newStartVnode.key];
if (BI.isNull(idxInOld)) {
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
newStartVnode = newCh[++newStartIdx];
} else {
elmToMove = oldCh[idxInOld];
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
// if (elmToMove.sel !== newStartVnode.sel) {
// api.insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
// } else {
// updated = this.patchItem(elmToMove, newStartVnode, idxInOld) || updated;
// oldCh[idxInOld] = undefined;
// api.insertBefore(parentElm, (elmToMove.elm), oldStartVnode.elm);
// }
newStartVnode = newCh[++newStartIdx];
}
} }
} }
if (o.items.length > items.length) { if (oldStartIdx > oldEndIdx) {
var deleted = []; before = BI.isNull(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;
for (i = items.length; i < o.items.length; i++) { addVnodes(before, newCh, newStartIdx, newEndIdx);
deleted.push(this._children[this._getChildName(i)]); } else if (newStartIdx > newEndIdx) {
delete this._children[this._getChildName(i)]; removeVnodes(oldCh, oldStartIdx, oldEndIdx);
}
this._children = {};
BI.each(newCh, function (i, child) {
var node = self._getOptions(child);
var key = node.key == null ? i : node.key;
self._children[self._getChildName(i)] = children[key];
});
function sameVnode(vnode1, vnode2, oldIndex, newIndex) {
vnode1 = self._getOptions(vnode1);
vnode2 = self._getOptions(vnode2);
if (BI.isKey(vnode1.key)) {
return vnode1.key === vnode2.key;
} }
o.items.splice(items.length); if (oldIndex >= 0) {
BI.each(deleted, function (i, w) { return oldIndex === newIndex
w._destroy(); }
}) }
} else if (items.length > o.items.length) {
for (i = o.items.length; i < items.length; i++) { function addNode(vnode, index) {
this.addItemAt(i, items[i]); var opt = self._getOptions(vnode);
var key = opt.key == null ? i : opt.key;
return children[key] = self._addElement(key, vnode);
}
function addVnodes(before, vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var node = addNode(vnodes[startIdx], startIdx);
insertBefore(node, before);
}
}
function removeVnodes(vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var node = self._getOptions(vnodes[startIdx]);
var key = node.key == null ? startIdx : node.key;
children[key]._destroy();
}
}
function insertBefore(insert, before, isNext) {
insert = self._getOptions(insert);
before = before && self._getOptions(before);
if (BI.isKey(insert.key)) {
if (before && children[before.key]) {
var next;
if (isNext) {
next = children[before.key].element.next();
} else {
next = children[before.key].element;
}
if (next.length > 0) {
next.before(children[insert.key].element);
} else {
self._getWrapper().append(children[insert.key].element);
}
} else {
self._getWrapper().append(children[insert.key].element);
}
} else {
throw "key is not defined";
}
}
function createKeyToOldIdx(children, beginIdx, endIdx) {
var i, map = {}, key;
for (i = beginIdx; i <= endIdx; ++i) {
key = children[i].key;
if (key !== undefined) map[key] = i;
} }
return map;
} }
return updated;
},
update: function (opt) {
var o = this.options;
var items = opt.items || [];
var updated = this.updateChildren(o.items, items);
this.options.items = items;
return updated; return updated;
// var updated, i, len;
// for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) {
// if (!this._compare(o.items[i], items[i])) {
// updated = this.updateItemAt(i, items[i]) || updated;
// }
// }
// if (o.items.length > items.length) {
// var deleted = [];
// for (i = items.length; i < o.items.length; i++) {
// deleted.push(this._children[this._getChildName(i)]);
// delete this._children[this._getChildName(i)];
// }
// o.items.splice(items.length);
// BI.each(deleted, function (i, w) {
// w._destroy();
// })
// } else if (items.length > o.items.length) {
// for (i = o.items.length; i < items.length; i++) {
// this.addItemAt(i, items[i]);
// }
// }
// return updated;
}, },
stroke: function (items) { stroke: function (items) {

33
demo/js/core/abstract/demo.virtual_group.js

@ -4,19 +4,28 @@ Demo.Func = BI.inherit(BI.Widget, {
}, },
_createItems: function () { _createItems: function () {
var items = BI.makeArray(1000, { var items = BI.map(BI.range(1000), function (i) {
type: "demo.virtual_group_item" return {
type: "demo.virtual_group_item",
key: i + 1
}
}); });
items[0].value = BI.UUID();
return items; return items;
}, },
render: function () { render: function () {
var self = this; var self = this;
var buttonGroupItems = self._createItems();
var virtualGroupItems = self._createItems();
return { return {
type: "bi.vertical", type: "bi.vertical",
vgap: 20, vgap: 20,
items: [{ items: [{
type: "bi.label",
cls: "layout-bg5",
height: 50,
text: "共1000个元素,演示button_group和virtual_group每次删除第一个元素"
}, {
type: "bi.button_group", type: "bi.button_group",
width: 500, width: 500,
height: 300, height: 300,
@ -26,17 +35,14 @@ Demo.Func = BI.inherit(BI.Widget, {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI,
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical"
}, {
type: "bi.center_adapt",
}], }],
items: this._createItems() items: this._createItems()
}, { }, {
type: "bi.button", type: "bi.button",
text: "演示button_group的刷新", text: "演示button_group的刷新",
handler: function () { handler: function () {
var items = self._createItems(); buttonGroupItems.shift();
items.pop(); self.buttonGroup.populate(BI.deepClone(buttonGroupItems));
self.buttonGroup.populate(items);
} }
}, { }, {
type: "bi.virtual_group", type: "bi.virtual_group",
@ -48,17 +54,14 @@ Demo.Func = BI.inherit(BI.Widget, {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI,
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical"
}, {
type: "bi.center_adapt",
}], }],
items: this._createItems() items: this._createItems()
}, { }, {
type: "bi.button", type: "bi.button",
text: "演示virtual_group的刷新", text: "演示virtual_group的刷新",
handler: function () { handler: function () {
var items = self._createItems(); virtualGroupItems.shift();
items.pop(); self.virtualGroup.populate(BI.deepClone(virtualGroupItems));
self.virtualGroup.populate(items);
} }
}] }]
@ -74,14 +77,14 @@ Demo.Item = BI.inherit(BI.Widget, {
}, },
render: function () { render: function () {
var self = this; var self = this, o = this.options;
return { return {
type: "bi.label", type: "bi.label",
ref: function () { ref: function () {
self.label = this; self.label = this;
}, },
height: this.options.height, height: this.options.height,
text: "这是一个测试项" + BI.UUID() text: "key:" + o.key + ",随机数" + BI.UUID()
} }
}, },

199
dist/bundle.js vendored

@ -19883,31 +19883,192 @@ BI.Layout = BI.inherit(BI.Widget, {
}) })
}, },
update: function (opt) { patchItem: function (oldVnode, vnode, index) {
var o = this.options; if (!this._compare(oldVnode, vnode)) {
var items = opt.items || []; return this.updateItemAt(index, vnode);
var updated, i, len; }
for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { },
if (!this._compare(o.items[i], items[i])) {
updated = this.updateItemAt(i, items[i]) || updated; updateChildren: function (oldCh, newCh) {
var self = this;
var oldStartIdx = 0, newStartIdx = 0;
var oldEndIdx = oldCh.length - 1;
var oldStartVnode = oldCh[0];
var oldEndVnode = oldCh[oldEndIdx];
var newEndIdx = newCh.length - 1;
var newStartVnode = newCh[0];
var newEndVnode = newCh[newEndIdx];
var oldKeyToIdx;
var idxInOld;
var elmToMove;
var before;
var updated;
var children = {};
BI.each(oldCh, function (i, child) {
child = self._getOptions(child);
var key = child.key == null ? i : child.key;
if (BI.isKey(key)) {
children[key] = self._children[self._getChildName(i)];
}
});
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
if (BI.isNull(oldStartVnode)) {
oldStartVnode = oldCh[++oldStartIdx];
} else if (BI.isNull(oldEndVnode)) {
oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated;
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated;
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated;
insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated;
insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx];
} else {
if (oldKeyToIdx === undefined) {
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
}
idxInOld = oldKeyToIdx[newStartVnode.key];
if (BI.isNull(idxInOld)) {
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
newStartVnode = newCh[++newStartIdx];
} else {
elmToMove = oldCh[idxInOld];
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
// if (elmToMove.sel !== newStartVnode.sel) {
// api.insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
// } else {
// updated = this.patchItem(elmToMove, newStartVnode, idxInOld) || updated;
// oldCh[idxInOld] = undefined;
// api.insertBefore(parentElm, (elmToMove.elm), oldStartVnode.elm);
// }
newStartVnode = newCh[++newStartIdx];
}
}
}
if (oldStartIdx > oldEndIdx) {
before = BI.isNull(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;
addVnodes(before, newCh, newStartIdx, newEndIdx);
} else if (newStartIdx > newEndIdx) {
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
}
this._children = {};
BI.each(newCh, function (i, child) {
var node = self._getOptions(child);
var key = node.key == null ? i : node.key;
self._children[self._getChildName(i)] = children[key];
});
function sameVnode(vnode1, vnode2, oldIndex, newIndex) {
vnode1 = self._getOptions(vnode1);
vnode2 = self._getOptions(vnode2);
if (BI.isKey(vnode1.key)) {
return vnode1.key === vnode2.key;
}
if (oldIndex >= 0) {
return oldIndex === newIndex
} }
} }
if (o.items.length > items.length) {
var deleted = []; function addNode(vnode, index) {
for (i = items.length; i < o.items.length; i++) { var opt = self._getOptions(vnode);
deleted.push(this._children[this._getChildName(i)]); var key = opt.key == null ? i : opt.key;
delete this._children[this._getChildName(i)]; return children[key] = self._addElement(key, vnode);
}
function addVnodes(before, vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var node = addNode(vnodes[startIdx], startIdx);
insertBefore(node, before);
} }
o.items.splice(items.length); }
BI.each(deleted, function (i, w) {
w._destroy(); function removeVnodes(vnodes, startIdx, endIdx) {
}) for (; startIdx <= endIdx; ++startIdx) {
} else if (items.length > o.items.length) { var node = self._getOptions(vnodes[startIdx]);
for (i = o.items.length; i < items.length; i++) { var key = node.key == null ? startIdx : node.key;
this.addItemAt(i, items[i]); children[key]._destroy();
}
}
function insertBefore(insert, before, isNext) {
insert = self._getOptions(insert);
before = before && self._getOptions(before);
if (BI.isKey(insert.key)) {
if (before && children[before.key]) {
var next;
if (isNext) {
next = children[before.key].element.next();
} else {
next = children[before.key].element;
}
if (next.length > 0) {
next.before(children[insert.key].element);
} else {
self._getWrapper().append(children[insert.key].element);
}
} else {
self._getWrapper().append(children[insert.key].element);
}
} else {
throw "key is not defined";
}
}
function createKeyToOldIdx(children, beginIdx, endIdx) {
var i, map = {}, key;
for (i = beginIdx; i <= endIdx; ++i) {
key = children[i].key;
if (key !== undefined) map[key] = i;
} }
return map;
} }
return updated;
},
update: function (opt) {
var o = this.options;
var items = opt.items || [];
var updated = this.updateChildren(o.items, items);
this.options.items = items;
return updated; return updated;
// var updated, i, len;
// for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) {
// if (!this._compare(o.items[i], items[i])) {
// updated = this.updateItemAt(i, items[i]) || updated;
// }
// }
// if (o.items.length > items.length) {
// var deleted = [];
// for (i = items.length; i < o.items.length; i++) {
// deleted.push(this._children[this._getChildName(i)]);
// delete this._children[this._getChildName(i)];
// }
// o.items.splice(items.length);
// BI.each(deleted, function (i, w) {
// w._destroy();
// })
// } else if (items.length > o.items.length) {
// for (i = o.items.length; i < items.length; i++) {
// this.addItemAt(i, items[i]);
// }
// }
// return updated;
}, },
stroke: function (items) { stroke: function (items) {

80
dist/bundle.min.js vendored

File diff suppressed because one or more lines are too long

199
dist/core.js vendored

@ -19832,31 +19832,192 @@ BI.Layout = BI.inherit(BI.Widget, {
}) })
}, },
update: function (opt) { patchItem: function (oldVnode, vnode, index) {
var o = this.options; if (!this._compare(oldVnode, vnode)) {
var items = opt.items || []; return this.updateItemAt(index, vnode);
var updated, i, len; }
for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { },
if (!this._compare(o.items[i], items[i])) {
updated = this.updateItemAt(i, items[i]) || updated; updateChildren: function (oldCh, newCh) {
var self = this;
var oldStartIdx = 0, newStartIdx = 0;
var oldEndIdx = oldCh.length - 1;
var oldStartVnode = oldCh[0];
var oldEndVnode = oldCh[oldEndIdx];
var newEndIdx = newCh.length - 1;
var newStartVnode = newCh[0];
var newEndVnode = newCh[newEndIdx];
var oldKeyToIdx;
var idxInOld;
var elmToMove;
var before;
var updated;
var children = {};
BI.each(oldCh, function (i, child) {
child = self._getOptions(child);
var key = child.key == null ? i : child.key;
if (BI.isKey(key)) {
children[key] = self._children[self._getChildName(i)];
}
});
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
if (BI.isNull(oldStartVnode)) {
oldStartVnode = oldCh[++oldStartIdx];
} else if (BI.isNull(oldEndVnode)) {
oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated;
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated;
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated;
insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated;
insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx];
} else {
if (oldKeyToIdx === undefined) {
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
}
idxInOld = oldKeyToIdx[newStartVnode.key];
if (BI.isNull(idxInOld)) {
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
newStartVnode = newCh[++newStartIdx];
} else {
elmToMove = oldCh[idxInOld];
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
// if (elmToMove.sel !== newStartVnode.sel) {
// api.insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
// } else {
// updated = this.patchItem(elmToMove, newStartVnode, idxInOld) || updated;
// oldCh[idxInOld] = undefined;
// api.insertBefore(parentElm, (elmToMove.elm), oldStartVnode.elm);
// }
newStartVnode = newCh[++newStartIdx];
}
} }
} }
if (o.items.length > items.length) { if (oldStartIdx > oldEndIdx) {
var deleted = []; before = BI.isNull(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;
for (i = items.length; i < o.items.length; i++) { addVnodes(before, newCh, newStartIdx, newEndIdx);
deleted.push(this._children[this._getChildName(i)]); } else if (newStartIdx > newEndIdx) {
delete this._children[this._getChildName(i)]; removeVnodes(oldCh, oldStartIdx, oldEndIdx);
}
this._children = {};
BI.each(newCh, function (i, child) {
var node = self._getOptions(child);
var key = node.key == null ? i : node.key;
self._children[self._getChildName(i)] = children[key];
});
function sameVnode(vnode1, vnode2, oldIndex, newIndex) {
vnode1 = self._getOptions(vnode1);
vnode2 = self._getOptions(vnode2);
if (BI.isKey(vnode1.key)) {
return vnode1.key === vnode2.key;
} }
o.items.splice(items.length); if (oldIndex >= 0) {
BI.each(deleted, function (i, w) { return oldIndex === newIndex
w._destroy(); }
}) }
} else if (items.length > o.items.length) {
for (i = o.items.length; i < items.length; i++) { function addNode(vnode, index) {
this.addItemAt(i, items[i]); var opt = self._getOptions(vnode);
var key = opt.key == null ? i : opt.key;
return children[key] = self._addElement(key, vnode);
}
function addVnodes(before, vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var node = addNode(vnodes[startIdx], startIdx);
insertBefore(node, before);
}
}
function removeVnodes(vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var node = self._getOptions(vnodes[startIdx]);
var key = node.key == null ? startIdx : node.key;
children[key]._destroy();
}
}
function insertBefore(insert, before, isNext) {
insert = self._getOptions(insert);
before = before && self._getOptions(before);
if (BI.isKey(insert.key)) {
if (before && children[before.key]) {
var next;
if (isNext) {
next = children[before.key].element.next();
} else {
next = children[before.key].element;
}
if (next.length > 0) {
next.before(children[insert.key].element);
} else {
self._getWrapper().append(children[insert.key].element);
}
} else {
self._getWrapper().append(children[insert.key].element);
}
} else {
throw "key is not defined";
}
}
function createKeyToOldIdx(children, beginIdx, endIdx) {
var i, map = {}, key;
for (i = beginIdx; i <= endIdx; ++i) {
key = children[i].key;
if (key !== undefined) map[key] = i;
} }
return map;
} }
return updated;
},
update: function (opt) {
var o = this.options;
var items = opt.items || [];
var updated = this.updateChildren(o.items, items);
this.options.items = items;
return updated; return updated;
// var updated, i, len;
// for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) {
// if (!this._compare(o.items[i], items[i])) {
// updated = this.updateItemAt(i, items[i]) || updated;
// }
// }
// if (o.items.length > items.length) {
// var deleted = [];
// for (i = items.length; i < o.items.length; i++) {
// deleted.push(this._children[this._getChildName(i)]);
// delete this._children[this._getChildName(i)];
// }
// o.items.splice(items.length);
// BI.each(deleted, function (i, w) {
// w._destroy();
// })
// } else if (items.length > o.items.length) {
// for (i = o.items.length; i < items.length; i++) {
// this.addItemAt(i, items[i]);
// }
// }
// return updated;
}, },
stroke: function (items) { stroke: function (items) {

33
dist/demo.js vendored

@ -6872,19 +6872,28 @@ BI.shortcut("demo.list_view", Demo.Func);Demo.Func = BI.inherit(BI.Widget, {
}, },
_createItems: function () { _createItems: function () {
var items = BI.makeArray(1000, { var items = BI.map(BI.range(1000), function (i) {
type: "demo.virtual_group_item" return {
type: "demo.virtual_group_item",
key: i + 1
}
}); });
items[0].value = BI.UUID();
return items; return items;
}, },
render: function () { render: function () {
var self = this; var self = this;
var buttonGroupItems = self._createItems();
var virtualGroupItems = self._createItems();
return { return {
type: "bi.vertical", type: "bi.vertical",
vgap: 20, vgap: 20,
items: [{ items: [{
type: "bi.label",
cls: "layout-bg5",
height: 50,
text: "共1000个元素,演示button_group和virtual_group每次删除第一个元素"
}, {
type: "bi.button_group", type: "bi.button_group",
width: 500, width: 500,
height: 300, height: 300,
@ -6894,17 +6903,14 @@ BI.shortcut("demo.list_view", Demo.Func);Demo.Func = BI.inherit(BI.Widget, {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI,
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical"
}, {
type: "bi.center_adapt",
}], }],
items: this._createItems() items: this._createItems()
}, { }, {
type: "bi.button", type: "bi.button",
text: "演示button_group的刷新", text: "演示button_group的刷新",
handler: function () { handler: function () {
var items = self._createItems(); buttonGroupItems.shift();
items.pop(); self.buttonGroup.populate(BI.deepClone(buttonGroupItems));
self.buttonGroup.populate(items);
} }
}, { }, {
type: "bi.virtual_group", type: "bi.virtual_group",
@ -6916,17 +6922,14 @@ BI.shortcut("demo.list_view", Demo.Func);Demo.Func = BI.inherit(BI.Widget, {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI,
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical"
}, {
type: "bi.center_adapt",
}], }],
items: this._createItems() items: this._createItems()
}, { }, {
type: "bi.button", type: "bi.button",
text: "演示virtual_group的刷新", text: "演示virtual_group的刷新",
handler: function () { handler: function () {
var items = self._createItems(); virtualGroupItems.shift();
items.pop(); self.virtualGroup.populate(BI.deepClone(virtualGroupItems));
self.virtualGroup.populate(items);
} }
}] }]
@ -6942,14 +6945,14 @@ Demo.Item = BI.inherit(BI.Widget, {
}, },
render: function () { render: function () {
var self = this; var self = this, o = this.options;
return { return {
type: "bi.label", type: "bi.label",
ref: function () { ref: function () {
self.label = this; self.label = this;
}, },
height: this.options.height, height: this.options.height,
text: "这是一个测试项" + BI.UUID() text: "key:" + o.key + ",随机数" + BI.UUID()
} }
}, },

199
src/core/wrapper/layout.js

@ -347,31 +347,192 @@ BI.Layout = BI.inherit(BI.Widget, {
}) })
}, },
update: function (opt) { patchItem: function (oldVnode, vnode, index) {
var o = this.options; if (!this._compare(oldVnode, vnode)) {
var items = opt.items || []; return this.updateItemAt(index, vnode);
var updated, i, len; }
for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { },
if (!this._compare(o.items[i], items[i])) {
updated = this.updateItemAt(i, items[i]) || updated; updateChildren: function (oldCh, newCh) {
var self = this;
var oldStartIdx = 0, newStartIdx = 0;
var oldEndIdx = oldCh.length - 1;
var oldStartVnode = oldCh[0];
var oldEndVnode = oldCh[oldEndIdx];
var newEndIdx = newCh.length - 1;
var newStartVnode = newCh[0];
var newEndVnode = newCh[newEndIdx];
var oldKeyToIdx;
var idxInOld;
var elmToMove;
var before;
var updated;
var children = {};
BI.each(oldCh, function (i, child) {
child = self._getOptions(child);
var key = child.key == null ? i : child.key;
if (BI.isKey(key)) {
children[key] = self._children[self._getChildName(i)];
} }
});
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
if (BI.isNull(oldStartVnode)) {
oldStartVnode = oldCh[++oldStartIdx];
} else if (BI.isNull(oldEndVnode)) {
oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVnode(oldStartVnode, newStartVnode, oldStartIdx, newStartIdx)) {
updated = this.patchItem(oldStartVnode, newStartVnode, oldStartIdx) || updated;
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVnode(oldEndVnode, newEndVnode, oldEndIdx, newEndIdx)) {
updated = this.patchItem(oldEndVnode, newEndVnode, oldEndIdx) || updated;
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldStartVnode, newEndVnode)) {
updated = this.patchItem(oldStartVnode, newEndVnode, oldStartIdx) || updated;
insertBefore(oldStartVnode, oldEndVnode, true);
oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVnode(oldEndVnode, newStartVnode)) {
updated = this.patchItem(oldEndVnode, newStartVnode, oldEndIdx) || updated;
insertBefore(oldEndVnode, oldStartVnode);
oldEndVnode = oldCh[--oldEndIdx];
newStartVnode = newCh[++newStartIdx];
} else {
if (oldKeyToIdx === undefined) {
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
}
idxInOld = oldKeyToIdx[newStartVnode.key];
if (BI.isNull(idxInOld)) {
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
newStartVnode = newCh[++newStartIdx];
} else {
elmToMove = oldCh[idxInOld];
var node = addNode(newStartVnode);
insertBefore(node, oldStartVnode);
// if (elmToMove.sel !== newStartVnode.sel) {
// api.insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
// } else {
// updated = this.patchItem(elmToMove, newStartVnode, idxInOld) || updated;
// oldCh[idxInOld] = undefined;
// api.insertBefore(parentElm, (elmToMove.elm), oldStartVnode.elm);
// }
newStartVnode = newCh[++newStartIdx];
}
}
}
if (oldStartIdx > oldEndIdx) {
before = BI.isNull(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm;
addVnodes(before, newCh, newStartIdx, newEndIdx);
} else if (newStartIdx > newEndIdx) {
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
} }
if (o.items.length > items.length) {
var deleted = []; this._children = {};
for (i = items.length; i < o.items.length; i++) { BI.each(newCh, function (i, child) {
deleted.push(this._children[this._getChildName(i)]); var node = self._getOptions(child);
delete this._children[this._getChildName(i)]; var key = node.key == null ? i : node.key;
self._children[self._getChildName(i)] = children[key];
});
function sameVnode(vnode1, vnode2, oldIndex, newIndex) {
vnode1 = self._getOptions(vnode1);
vnode2 = self._getOptions(vnode2);
if (BI.isKey(vnode1.key)) {
return vnode1.key === vnode2.key;
} }
o.items.splice(items.length); if (oldIndex >= 0) {
BI.each(deleted, function (i, w) { return oldIndex === newIndex
w._destroy();
})
} else if (items.length > o.items.length) {
for (i = o.items.length; i < items.length; i++) {
this.addItemAt(i, items[i]);
} }
} }
function addNode(vnode, index) {
var opt = self._getOptions(vnode);
var key = opt.key == null ? i : opt.key;
return children[key] = self._addElement(key, vnode);
}
function addVnodes(before, vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var node = addNode(vnodes[startIdx], startIdx);
insertBefore(node, before);
}
}
function removeVnodes(vnodes, startIdx, endIdx) {
for (; startIdx <= endIdx; ++startIdx) {
var node = self._getOptions(vnodes[startIdx]);
var key = node.key == null ? startIdx : node.key;
children[key]._destroy();
}
}
function insertBefore(insert, before, isNext) {
insert = self._getOptions(insert);
before = before && self._getOptions(before);
if (BI.isKey(insert.key)) {
if (before && children[before.key]) {
var next;
if (isNext) {
next = children[before.key].element.next();
} else {
next = children[before.key].element;
}
if (next.length > 0) {
next.before(children[insert.key].element);
} else {
self._getWrapper().append(children[insert.key].element);
}
} else {
self._getWrapper().append(children[insert.key].element);
}
} else {
throw "key is not defined";
}
}
function createKeyToOldIdx(children, beginIdx, endIdx) {
var i, map = {}, key;
for (i = beginIdx; i <= endIdx; ++i) {
key = children[i].key;
if (key !== undefined) map[key] = i;
}
return map;
}
return updated;
},
update: function (opt) {
var o = this.options;
var items = opt.items || [];
var updated = this.updateChildren(o.items, items);
this.options.items = items;
return updated; return updated;
// var updated, i, len;
// for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) {
// if (!this._compare(o.items[i], items[i])) {
// updated = this.updateItemAt(i, items[i]) || updated;
// }
// }
// if (o.items.length > items.length) {
// var deleted = [];
// for (i = items.length; i < o.items.length; i++) {
// deleted.push(this._children[this._getChildName(i)]);
// delete this._children[this._getChildName(i)];
// }
// o.items.splice(items.length);
// BI.each(deleted, function (i, w) {
// w._destroy();
// })
// } else if (items.length > o.items.length) {
// for (i = o.items.length; i < items.length; i++) {
// this.addItemAt(i, items[i]);
// }
// }
// return updated;
}, },
stroke: function (items) { stroke: function (items) {

Loading…
Cancel
Save