@zhongguo168a/yxeditor-common 0.0.59 → 0.0.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +17 -1
- package/dist/index.esm.js +552 -549
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1029,6 +1029,280 @@ let eventItemPool = new Pool({
|
|
|
1029
1029
|
}
|
|
1030
1030
|
});
|
|
1031
1031
|
|
|
1032
|
+
class DictIterator {
|
|
1033
|
+
break() {
|
|
1034
|
+
this._isBreak = true;
|
|
1035
|
+
}
|
|
1036
|
+
isBreak() {
|
|
1037
|
+
return this._isBreak;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
class Dictionary {
|
|
1041
|
+
constructor(data) {
|
|
1042
|
+
this.size = 0;
|
|
1043
|
+
if (data) {
|
|
1044
|
+
this._data = data;
|
|
1045
|
+
}
|
|
1046
|
+
else {
|
|
1047
|
+
this._data = {};
|
|
1048
|
+
}
|
|
1049
|
+
this._onSet = null;
|
|
1050
|
+
this._onDelete = null;
|
|
1051
|
+
}
|
|
1052
|
+
reset(data) {
|
|
1053
|
+
this._reset(data);
|
|
1054
|
+
}
|
|
1055
|
+
_reset(data, size) {
|
|
1056
|
+
this._data = data;
|
|
1057
|
+
if (size == undefined) {
|
|
1058
|
+
for (let _ in data) {
|
|
1059
|
+
size++;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
this.size = size;
|
|
1063
|
+
}
|
|
1064
|
+
getData() {
|
|
1065
|
+
return this._data;
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* 如果使用了 onSet or onDelete,需要注意清理
|
|
1069
|
+
*/
|
|
1070
|
+
clear() {
|
|
1071
|
+
this._data = {};
|
|
1072
|
+
this.size = 0;
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* 克隆自身所有项到【target】对象,并返回【target】对象
|
|
1076
|
+
* @param target
|
|
1077
|
+
*/
|
|
1078
|
+
clone(target) {
|
|
1079
|
+
for (const key in this._data) {
|
|
1080
|
+
let item = this._data[key];
|
|
1081
|
+
// @ts-ignore
|
|
1082
|
+
target.setData(key, item);
|
|
1083
|
+
}
|
|
1084
|
+
return target;
|
|
1085
|
+
}
|
|
1086
|
+
resetByDict(dict) {
|
|
1087
|
+
this._data = dict._data;
|
|
1088
|
+
this.size = dict.size;
|
|
1089
|
+
}
|
|
1090
|
+
onSet(caller, handler) {
|
|
1091
|
+
this._onSetCaller = caller;
|
|
1092
|
+
this._onSet = handler;
|
|
1093
|
+
}
|
|
1094
|
+
onDelete(caller, handler) {
|
|
1095
|
+
this._onDelete = handler;
|
|
1096
|
+
this._onDeleteCaller = caller;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* 设置键值对,如果没有发生变化,不会触发onSet函数
|
|
1100
|
+
* @param key
|
|
1101
|
+
* @param value
|
|
1102
|
+
*/
|
|
1103
|
+
set(key, value) {
|
|
1104
|
+
this.setData(key, value);
|
|
1105
|
+
}
|
|
1106
|
+
setData(key, value) {
|
|
1107
|
+
if (this._data.hasOwnProperty(key)) ;
|
|
1108
|
+
else {
|
|
1109
|
+
this.size++;
|
|
1110
|
+
}
|
|
1111
|
+
let existed = this._data[key];
|
|
1112
|
+
if (existed == value) {
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
this._data[key] = value;
|
|
1116
|
+
if (this._onSet !== null) {
|
|
1117
|
+
this._onSet.call(this._onSetCaller, key, value);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
setByMap(m) {
|
|
1121
|
+
for (const key in m) {
|
|
1122
|
+
let item = m[key];
|
|
1123
|
+
// @ts-ignore
|
|
1124
|
+
this.setData(key, item);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
addDictionary(other) {
|
|
1128
|
+
if (other.length() == 0) {
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
for (const key in other._data) {
|
|
1132
|
+
let item = other._data[key];
|
|
1133
|
+
// @ts-ignore
|
|
1134
|
+
this.setData(key, item);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
deleteDictionary(other) {
|
|
1138
|
+
if (other.length() == 0) {
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
for (const key in other._data) {
|
|
1142
|
+
// @ts-ignore
|
|
1143
|
+
this.delete(key);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* 如果不存在,返回 undefined
|
|
1148
|
+
* @param key
|
|
1149
|
+
*/
|
|
1150
|
+
get(key) {
|
|
1151
|
+
return this._data[key];
|
|
1152
|
+
}
|
|
1153
|
+
exist(key) {
|
|
1154
|
+
return !!this._data[key];
|
|
1155
|
+
}
|
|
1156
|
+
delete(key) {
|
|
1157
|
+
this.deleteData(key);
|
|
1158
|
+
}
|
|
1159
|
+
deleteData(key) {
|
|
1160
|
+
const value = this._data[key];
|
|
1161
|
+
if (value === undefined) {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
if (this._onDelete !== null) {
|
|
1165
|
+
this._onDelete.call(this._onDeleteCaller, key, value);
|
|
1166
|
+
}
|
|
1167
|
+
this._data[key] = null;
|
|
1168
|
+
delete this._data[key];
|
|
1169
|
+
this.size--;
|
|
1170
|
+
}
|
|
1171
|
+
exists(key) {
|
|
1172
|
+
return !!this._data[key];
|
|
1173
|
+
}
|
|
1174
|
+
length() {
|
|
1175
|
+
return this.size;
|
|
1176
|
+
}
|
|
1177
|
+
pop(key) {
|
|
1178
|
+
const value = this._data[key];
|
|
1179
|
+
this.deleteData(key);
|
|
1180
|
+
return [value, value !== undefined];
|
|
1181
|
+
}
|
|
1182
|
+
isEmpty() {
|
|
1183
|
+
return this.length() === 0;
|
|
1184
|
+
}
|
|
1185
|
+
items() {
|
|
1186
|
+
const items = [];
|
|
1187
|
+
for (const key in this._data) {
|
|
1188
|
+
let item = this._data[key];
|
|
1189
|
+
items.push(item);
|
|
1190
|
+
}
|
|
1191
|
+
return items;
|
|
1192
|
+
}
|
|
1193
|
+
keys() {
|
|
1194
|
+
const keys = [];
|
|
1195
|
+
for (const key in this._data) {
|
|
1196
|
+
keys.push(key);
|
|
1197
|
+
}
|
|
1198
|
+
return keys;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
*
|
|
1202
|
+
* @param handler 可以使用【iterator】中断遍历
|
|
1203
|
+
* @return iterator 获取是否中断了
|
|
1204
|
+
*/
|
|
1205
|
+
forEach(handler) {
|
|
1206
|
+
let iterator = new DictIterator();
|
|
1207
|
+
for (const key in this._data) {
|
|
1208
|
+
let val = this._data[key];
|
|
1209
|
+
// @ts-ignore
|
|
1210
|
+
handler(key, val, iterator);
|
|
1211
|
+
if (iterator.isBreak()) {
|
|
1212
|
+
return iterator;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return iterator;
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
*/
|
|
1219
|
+
first() {
|
|
1220
|
+
for (const key in this._data) {
|
|
1221
|
+
return this._data[key];
|
|
1222
|
+
}
|
|
1223
|
+
return undefined;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* @param handler 返回true结束迭代
|
|
1227
|
+
*/
|
|
1228
|
+
firstByCondition(handler) {
|
|
1229
|
+
for (const key in this._data) {
|
|
1230
|
+
let val = this._data[key];
|
|
1231
|
+
// @ts-ignore
|
|
1232
|
+
if (handler(key, val)) {
|
|
1233
|
+
return val;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* 移除符合条件的项
|
|
1239
|
+
* @param cond 可以使用【iterator】中断遍历
|
|
1240
|
+
*/
|
|
1241
|
+
removeByCondition(cond) {
|
|
1242
|
+
let newdata = this._data;
|
|
1243
|
+
let newsize = this.size;
|
|
1244
|
+
let iterator = new DictIterator();
|
|
1245
|
+
for (const key in this._data) {
|
|
1246
|
+
let val = this._data[key];
|
|
1247
|
+
// @ts-ignore
|
|
1248
|
+
if (cond(key, val, iterator)) {
|
|
1249
|
+
newsize--;
|
|
1250
|
+
delete newdata[key];
|
|
1251
|
+
}
|
|
1252
|
+
if (iterator.isBreak()) {
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
this.size = newsize;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* 查找符合条件的项保存到【target】对象中,并返回【target】对象
|
|
1260
|
+
* @param cond 可以使用【iterator】中断遍历
|
|
1261
|
+
* @param target 存到目标对象中
|
|
1262
|
+
*/
|
|
1263
|
+
findByCondition(cond, target) {
|
|
1264
|
+
if (!target) {
|
|
1265
|
+
throw new Error("需要设置目标对象");
|
|
1266
|
+
}
|
|
1267
|
+
let iterator = new DictIterator();
|
|
1268
|
+
let newdata = {};
|
|
1269
|
+
let newsize = 0;
|
|
1270
|
+
for (const key in this._data) {
|
|
1271
|
+
let val = this._data[key];
|
|
1272
|
+
// @ts-ignore
|
|
1273
|
+
if (cond(key, val, iterator)) {
|
|
1274
|
+
newsize++;
|
|
1275
|
+
newdata[key] = val;
|
|
1276
|
+
}
|
|
1277
|
+
if (iterator.isBreak()) {
|
|
1278
|
+
break;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
target._reset(newdata, newsize);
|
|
1282
|
+
return target;
|
|
1283
|
+
}
|
|
1284
|
+
groupByCondition(createKey, ITEM_CLASS) {
|
|
1285
|
+
let newdata = {};
|
|
1286
|
+
for (const key in this._data) {
|
|
1287
|
+
let val = this._data[key];
|
|
1288
|
+
// @ts-ignore
|
|
1289
|
+
let newkey = createKey(key, val);
|
|
1290
|
+
let dict = newdata[newkey];
|
|
1291
|
+
if (!dict) {
|
|
1292
|
+
if (ITEM_CLASS) {
|
|
1293
|
+
dict = new ITEM_CLASS();
|
|
1294
|
+
}
|
|
1295
|
+
else {
|
|
1296
|
+
dict = new Dictionary();
|
|
1297
|
+
}
|
|
1298
|
+
newdata[newkey] = dict;
|
|
1299
|
+
}
|
|
1300
|
+
dict.set(key, val);
|
|
1301
|
+
}
|
|
1302
|
+
return newdata;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1032
1306
|
class ConvertUtil {
|
|
1033
1307
|
anyToBoolean(val, defaultValue = false) {
|
|
1034
1308
|
if (val == null) {
|
|
@@ -1121,41 +1395,44 @@ class ConvertUtil {
|
|
|
1121
1395
|
}
|
|
1122
1396
|
const convertutil = new ConvertUtil();
|
|
1123
1397
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1398
|
+
class MapObject extends Dictionary {
|
|
1399
|
+
constructor(object) {
|
|
1400
|
+
super();
|
|
1401
|
+
this.object = object;
|
|
1402
|
+
}
|
|
1403
|
+
getValue(key) {
|
|
1404
|
+
let value = this.get(key);
|
|
1405
|
+
if (!value) {
|
|
1406
|
+
value = new MapValue(this, key);
|
|
1407
|
+
this.set(key, value);
|
|
1408
|
+
}
|
|
1409
|
+
return value;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
class MapValue {
|
|
1413
|
+
constructor(obj, key) {
|
|
1414
|
+
this.obj = obj;
|
|
1415
|
+
this.key = key;
|
|
1416
|
+
}
|
|
1417
|
+
set(value) {
|
|
1418
|
+
this.obj[this.key] = value;
|
|
1419
|
+
}
|
|
1420
|
+
isUndefined() {
|
|
1421
|
+
return this.obj[this.key] == undefined;
|
|
1422
|
+
}
|
|
1423
|
+
toNumber() {
|
|
1424
|
+
return maputil.number(this.obj, this.key);
|
|
1425
|
+
}
|
|
1426
|
+
toString() {
|
|
1427
|
+
return maputil.string(this.obj, this.key);
|
|
1428
|
+
}
|
|
1429
|
+
toBoolean() {
|
|
1430
|
+
return maputil.boolean(this.obj, this.key);
|
|
1431
|
+
}
|
|
1432
|
+
toAny() {
|
|
1433
|
+
return this.obj[this.key];
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1159
1436
|
class MapUtil {
|
|
1160
1437
|
/**
|
|
1161
1438
|
* 获取所欲的值
|
|
@@ -2469,597 +2746,323 @@ class TreeRoot extends EventDispatcher {
|
|
|
2469
2746
|
let child = children[i];
|
|
2470
2747
|
child.id = i.toString();
|
|
2471
2748
|
child.setTag("title", i.toString());
|
|
2472
|
-
this.refresh(child);
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
this.dispatch(TreeRoot.EVENT_INSERT, { node: node, before: before });
|
|
2476
|
-
}
|
|
2477
|
-
walk(f, inChild) {
|
|
2478
|
-
this.origin.walk(f, inChild);
|
|
2479
|
-
}
|
|
2480
|
-
walkPrev(f, inChild) {
|
|
2481
|
-
this.origin.walkPrev(f, inChild);
|
|
2482
|
-
}
|
|
2483
|
-
/**
|
|
2484
|
-
* 派发 refresh 消息
|
|
2485
|
-
* @param node
|
|
2486
|
-
*/
|
|
2487
|
-
refresh(node) {
|
|
2488
|
-
this.dispatch(TreeRoot.EVENT_REFRESH, { node: node });
|
|
2489
|
-
}
|
|
2490
|
-
/**
|
|
2491
|
-
* 克隆当前的树结
|
|
2492
|
-
* * 新的tags克隆旧的data
|
|
2493
|
-
* * 新的data指向旧的data
|
|
2494
|
-
*/
|
|
2495
|
-
clone() {
|
|
2496
|
-
let root = TreeRoot.create();
|
|
2497
|
-
root.origin = this.origin.clone();
|
|
2498
|
-
root.origin.fixDepthAndRoot(0, root);
|
|
2499
|
-
return root;
|
|
2500
|
-
}
|
|
2501
|
-
toString() {
|
|
2502
|
-
return `TreeRoot`;
|
|
2503
|
-
}
|
|
2504
|
-
createNode(id, isLeaf) {
|
|
2505
|
-
let node = new TreeNode(id, isLeaf);
|
|
2506
|
-
node.setRoot(this);
|
|
2507
|
-
return node;
|
|
2508
|
-
}
|
|
2509
|
-
/**
|
|
2510
|
-
* origin的第一个child
|
|
2511
|
-
*/
|
|
2512
|
-
get firstNode() {
|
|
2513
|
-
if (!this.origin) {
|
|
2514
|
-
return null;
|
|
2515
|
-
}
|
|
2516
|
-
if (!this.origin.children) {
|
|
2517
|
-
return null;
|
|
2518
|
-
}
|
|
2519
|
-
return this.origin.children[0];
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
/**
|
|
2523
|
-
* 添加数据节点
|
|
2524
|
-
* dispatchParams = {node:TreeNode, parent:TreeNode|TreeRoot}
|
|
2525
|
-
*/
|
|
2526
|
-
TreeRoot.EVENT_ADD = "add";
|
|
2527
|
-
/**
|
|
2528
|
-
* 移除数据节点
|
|
2529
|
-
* dispatchParams = {node:TreeNode, parent:TreeNode|TreeRoot}
|
|
2530
|
-
*/
|
|
2531
|
-
TreeRoot.EVENT_REMOVE = "remove";
|
|
2532
|
-
/**
|
|
2533
|
-
* 插入数据节点
|
|
2534
|
-
* dispatchParams = {node:TreeNode, before:TreeNode}
|
|
2535
|
-
*/
|
|
2536
|
-
TreeRoot.EVENT_INSERT = "insert";
|
|
2537
|
-
/**
|
|
2538
|
-
* 刷新数据节点
|
|
2539
|
-
* dispatchParams = {node:TreeNode}
|
|
2540
|
-
*/
|
|
2541
|
-
TreeRoot.EVENT_REFRESH = "refresh";
|
|
2542
|
-
/**
|
|
2543
|
-
* 设置数据时触发
|
|
2544
|
-
* dispatchParams = {node:TreeNode}
|
|
2545
|
-
*/
|
|
2546
|
-
TreeRoot.EVENT_DATA_SET = "data_set";
|
|
2547
|
-
/**
|
|
2548
|
-
* 设置数据时触发
|
|
2549
|
-
* dispatchParams = {node:TreeNode, tag:string, value:any}
|
|
2550
|
-
*/
|
|
2551
|
-
TreeRoot.EVENT_TAGS_SET = "tags_set";
|
|
2552
|
-
///////////////////////////
|
|
2553
|
-
class TreeRootPlugin {
|
|
2554
|
-
}
|
|
2555
|
-
class TreeNodePlugin {
|
|
2556
|
-
}
|
|
2557
|
-
|
|
2558
|
-
class ListNode {
|
|
2559
|
-
static create(id, data) {
|
|
2560
|
-
let node = new ListNode();
|
|
2561
|
-
node.id = id;
|
|
2562
|
-
node.data = data;
|
|
2563
|
-
return node;
|
|
2564
|
-
}
|
|
2565
|
-
constructor() {
|
|
2566
|
-
this.tags = {};
|
|
2567
|
-
this.uuid = identutil.genOne();
|
|
2568
|
-
}
|
|
2569
|
-
getTags() {
|
|
2570
|
-
if (!this.tags) {
|
|
2571
|
-
this.tags = {};
|
|
2572
|
-
}
|
|
2573
|
-
return this.tags;
|
|
2574
|
-
}
|
|
2575
|
-
setTags(tags) {
|
|
2576
|
-
let obj = this.getTags();
|
|
2577
|
-
for (const key in tags) {
|
|
2578
|
-
obj[key] = tags[key];
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
getTag(name) {
|
|
2582
|
-
return this.getTags()[name];
|
|
2583
|
-
}
|
|
2584
|
-
setTag(name, value) {
|
|
2585
|
-
this.getTags()[name] = value;
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
class ListSource extends EventDispatcher {
|
|
2589
|
-
constructor() {
|
|
2590
|
-
super(...arguments);
|
|
2591
|
-
this._data = [];
|
|
2592
|
-
}
|
|
2593
|
-
/**
|
|
2594
|
-
* 通过数组创建 ListSource。ListSource的id自动生成。如果需要指定编号,可设置 idCreator
|
|
2595
|
-
* @param arr
|
|
2596
|
-
* @param idCreator
|
|
2597
|
-
*/
|
|
2598
|
-
static createByArray(arr, idCreator) {
|
|
2599
|
-
let root = new ListSource();
|
|
2600
|
-
for (let i = 0; i < arr.length; i++) {
|
|
2601
|
-
let item = arr[i];
|
|
2602
|
-
let id = "";
|
|
2603
|
-
if (idCreator) {
|
|
2604
|
-
id = idCreator(item);
|
|
2605
|
-
}
|
|
2606
|
-
else {
|
|
2607
|
-
id = identutil.genOne();
|
|
2608
|
-
}
|
|
2609
|
-
let node = ListNode.create(id, item);
|
|
2610
|
-
root.add(node, false);
|
|
2611
|
-
}
|
|
2612
|
-
return root;
|
|
2613
|
-
}
|
|
2614
|
-
static createByListItem(arr, target) {
|
|
2615
|
-
if (!target) {
|
|
2616
|
-
target = new ListSource();
|
|
2617
|
-
}
|
|
2618
|
-
for (let i = 0; i < arr.length; i++) {
|
|
2619
|
-
let item = arr[i];
|
|
2620
|
-
let id = "";
|
|
2621
|
-
let node = ListNode.create(id);
|
|
2622
|
-
node.id = item.id;
|
|
2623
|
-
node.tags = item.tags;
|
|
2624
|
-
node.data = item.data;
|
|
2625
|
-
target.add(node, false);
|
|
2626
|
-
}
|
|
2627
|
-
return target;
|
|
2628
|
-
}
|
|
2629
|
-
at(index) {
|
|
2630
|
-
return this._data[index];
|
|
2631
|
-
}
|
|
2632
|
-
first() {
|
|
2633
|
-
return this._data[0];
|
|
2634
|
-
}
|
|
2635
|
-
last() {
|
|
2636
|
-
return this._data[this._data.length - 1];
|
|
2637
|
-
}
|
|
2638
|
-
length() {
|
|
2639
|
-
return this._data.length;
|
|
2640
|
-
}
|
|
2641
|
-
/**
|
|
2642
|
-
* 添加项,无法添加相同的项
|
|
2643
|
-
* @param node
|
|
2644
|
-
* @param enableDispatch 默认为true
|
|
2645
|
-
*/
|
|
2646
|
-
add(node, enableDispatch = true) {
|
|
2647
|
-
if (this.contains(node)) {
|
|
2648
|
-
return;
|
|
2649
|
-
}
|
|
2650
|
-
this._data.push(node);
|
|
2651
|
-
node.root = this;
|
|
2652
|
-
if (enableDispatch) {
|
|
2653
|
-
this.dispatch(ListSource.EVENT_ADD, { node: node });
|
|
2654
|
-
}
|
|
2655
|
-
}
|
|
2656
|
-
getById(id) {
|
|
2657
|
-
for (let i = 0; i < this._data.length; i++) {
|
|
2658
|
-
let node = this._data[i];
|
|
2659
|
-
if (node.id == id) {
|
|
2660
|
-
return node;
|
|
2661
|
-
}
|
|
2662
|
-
}
|
|
2663
|
-
return null;
|
|
2664
|
-
}
|
|
2665
|
-
remove(node) {
|
|
2666
|
-
let index = this._data.indexOf(node);
|
|
2667
|
-
if (index == -1) {
|
|
2668
|
-
return;
|
|
2669
|
-
}
|
|
2670
|
-
node.root = null;
|
|
2671
|
-
this._data.splice(index, 1);
|
|
2672
|
-
this.dispatch(ListSource.EVENT_REMOVE, { node: node, index: index });
|
|
2673
|
-
}
|
|
2674
|
-
removeAll() {
|
|
2675
|
-
this._data.length = 0;
|
|
2676
|
-
this.dispatch(ListSource.EVENT_REMOVE_ALL);
|
|
2677
|
-
}
|
|
2678
|
-
swap(a, b) {
|
|
2679
|
-
let aidx = this.indexOf(a);
|
|
2680
|
-
let bidx = this.indexOf(b);
|
|
2681
|
-
let d = this._data;
|
|
2682
|
-
[d[aidx], d[bidx]] = [d[bidx], a[aidx]];
|
|
2683
|
-
this.dispatch(ListSource.EVENT_SWAP, { nodes: [a, b], indexs: [aidx, bidx] });
|
|
2684
|
-
}
|
|
2685
|
-
contains(node) {
|
|
2686
|
-
return this.indexOf(node) != -1;
|
|
2687
|
-
}
|
|
2688
|
-
containsById(id) {
|
|
2689
|
-
return this.indexOfById(id) != -1;
|
|
2690
|
-
}
|
|
2691
|
-
indexOf(node) {
|
|
2692
|
-
for (let i = 0; i < this._data.length; i++) {
|
|
2693
|
-
let item = this._data[i];
|
|
2694
|
-
if (item.id == node.id) {
|
|
2695
|
-
return i;
|
|
2696
|
-
}
|
|
2697
|
-
}
|
|
2698
|
-
return -1;
|
|
2699
|
-
}
|
|
2700
|
-
indexOfById(id) {
|
|
2701
|
-
for (let i = 0; i < this._data.length; i++) {
|
|
2702
|
-
let item = this._data[i];
|
|
2703
|
-
if (item.id == id) {
|
|
2704
|
-
return i;
|
|
2705
|
-
}
|
|
2706
|
-
}
|
|
2707
|
-
return -1;
|
|
2708
|
-
}
|
|
2709
|
-
setData(node, data) {
|
|
2710
|
-
if (!node) {
|
|
2711
|
-
return;
|
|
2749
|
+
this.refresh(child);
|
|
2750
|
+
}
|
|
2712
2751
|
}
|
|
2713
|
-
|
|
2714
|
-
this.dispatch(ListSource.EVENT_DATA_SET, { node: node, data: data });
|
|
2752
|
+
this.dispatch(TreeRoot.EVENT_INSERT, { node: node, before: before });
|
|
2715
2753
|
}
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
tags[tag] = value;
|
|
2722
|
-
this.dispatch(ListSource.EVENT_TAGS_SET, { node: node, tag: tag, value: value });
|
|
2754
|
+
walk(f, inChild) {
|
|
2755
|
+
this.origin.walk(f, inChild);
|
|
2756
|
+
}
|
|
2757
|
+
walkPrev(f, inChild) {
|
|
2758
|
+
this.origin.walkPrev(f, inChild);
|
|
2723
2759
|
}
|
|
2724
2760
|
/**
|
|
2725
2761
|
* 派发 refresh 消息
|
|
2726
2762
|
* @param node
|
|
2727
2763
|
*/
|
|
2728
2764
|
refresh(node) {
|
|
2729
|
-
this.dispatch(
|
|
2765
|
+
this.dispatch(TreeRoot.EVENT_REFRESH, { node: node });
|
|
2730
2766
|
}
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2767
|
+
/**
|
|
2768
|
+
* 克隆当前的树结
|
|
2769
|
+
* * 新的tags克隆旧的data
|
|
2770
|
+
* * 新的data指向旧的data
|
|
2771
|
+
*/
|
|
2772
|
+
clone() {
|
|
2773
|
+
let root = TreeRoot.create();
|
|
2774
|
+
root.origin = this.origin.clone();
|
|
2775
|
+
root.origin.fixDepthAndRoot(0, root);
|
|
2776
|
+
return root;
|
|
2738
2777
|
}
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2778
|
+
toString() {
|
|
2779
|
+
return `TreeRoot`;
|
|
2780
|
+
}
|
|
2781
|
+
createNode(id, isLeaf) {
|
|
2782
|
+
let node = new TreeNode(id, isLeaf);
|
|
2783
|
+
node.setRoot(this);
|
|
2784
|
+
return node;
|
|
2785
|
+
}
|
|
2786
|
+
/**
|
|
2787
|
+
* origin的第一个child
|
|
2788
|
+
*/
|
|
2789
|
+
get firstNode() {
|
|
2790
|
+
if (!this.origin) {
|
|
2791
|
+
return null;
|
|
2743
2792
|
}
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
if (!f(item)) {
|
|
2747
|
-
return false;
|
|
2748
|
-
}
|
|
2793
|
+
if (!this.origin.children) {
|
|
2794
|
+
return null;
|
|
2749
2795
|
}
|
|
2750
|
-
|
|
2751
|
-
get data() {
|
|
2752
|
-
return this._data;
|
|
2796
|
+
return this.origin.children[0];
|
|
2753
2797
|
}
|
|
2754
2798
|
}
|
|
2755
2799
|
/**
|
|
2756
|
-
*
|
|
2757
|
-
* dispatchParams = {node:
|
|
2800
|
+
* 添加数据节点
|
|
2801
|
+
* dispatchParams = {node:TreeNode, parent:TreeNode|TreeRoot}
|
|
2758
2802
|
*/
|
|
2759
|
-
|
|
2803
|
+
TreeRoot.EVENT_ADD = "add";
|
|
2760
2804
|
/**
|
|
2761
|
-
*
|
|
2762
|
-
* dispatchParams = {node:
|
|
2805
|
+
* 移除数据节点
|
|
2806
|
+
* dispatchParams = {node:TreeNode, parent:TreeNode|TreeRoot}
|
|
2763
2807
|
*/
|
|
2764
|
-
|
|
2808
|
+
TreeRoot.EVENT_REMOVE = "remove";
|
|
2765
2809
|
/**
|
|
2766
|
-
*
|
|
2810
|
+
* 插入数据节点
|
|
2811
|
+
* dispatchParams = {node:TreeNode, before:TreeNode}
|
|
2767
2812
|
*/
|
|
2768
|
-
|
|
2813
|
+
TreeRoot.EVENT_INSERT = "insert";
|
|
2769
2814
|
/**
|
|
2770
2815
|
* 刷新数据节点
|
|
2771
|
-
* dispatchParams = {node:
|
|
2772
|
-
*/
|
|
2773
|
-
ListSource.EVENT_REFRESH = "refresh";
|
|
2774
|
-
/**
|
|
2775
|
-
* 设置数据时触发
|
|
2776
|
-
* dispatchParams = nodes: [ListNode], indexs: [number]
|
|
2816
|
+
* dispatchParams = {node:TreeNode}
|
|
2777
2817
|
*/
|
|
2778
|
-
|
|
2818
|
+
TreeRoot.EVENT_REFRESH = "refresh";
|
|
2779
2819
|
/**
|
|
2780
2820
|
* 设置数据时触发
|
|
2781
|
-
* dispatchParams = {node:
|
|
2821
|
+
* dispatchParams = {node:TreeNode}
|
|
2782
2822
|
*/
|
|
2783
|
-
|
|
2823
|
+
TreeRoot.EVENT_DATA_SET = "data_set";
|
|
2784
2824
|
/**
|
|
2785
2825
|
* 设置数据时触发
|
|
2786
|
-
* dispatchParams = {node:
|
|
2826
|
+
* dispatchParams = {node:TreeNode, tag:string, value:any}
|
|
2787
2827
|
*/
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
class
|
|
2791
|
-
break() {
|
|
2792
|
-
this._isBreak = true;
|
|
2793
|
-
}
|
|
2794
|
-
isBreak() {
|
|
2795
|
-
return this._isBreak;
|
|
2796
|
-
}
|
|
2828
|
+
TreeRoot.EVENT_TAGS_SET = "tags_set";
|
|
2829
|
+
///////////////////////////
|
|
2830
|
+
class TreeRootPlugin {
|
|
2797
2831
|
}
|
|
2798
|
-
class
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
this._onSet = null;
|
|
2808
|
-
this._onDelete = null;
|
|
2832
|
+
class TreeNodePlugin {
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
class ListNode {
|
|
2836
|
+
static create(id, data) {
|
|
2837
|
+
let node = new ListNode();
|
|
2838
|
+
node.id = id;
|
|
2839
|
+
node.data = data;
|
|
2840
|
+
return node;
|
|
2809
2841
|
}
|
|
2810
|
-
|
|
2811
|
-
this.
|
|
2842
|
+
constructor() {
|
|
2843
|
+
this.tags = {};
|
|
2844
|
+
this.uuid = identutil.genOne();
|
|
2812
2845
|
}
|
|
2813
|
-
|
|
2814
|
-
this.
|
|
2815
|
-
|
|
2816
|
-
for (let _ in data) {
|
|
2817
|
-
size++;
|
|
2818
|
-
}
|
|
2846
|
+
getTags() {
|
|
2847
|
+
if (!this.tags) {
|
|
2848
|
+
this.tags = {};
|
|
2819
2849
|
}
|
|
2820
|
-
this.
|
|
2821
|
-
}
|
|
2822
|
-
getData() {
|
|
2823
|
-
return this._data;
|
|
2824
|
-
}
|
|
2825
|
-
/**
|
|
2826
|
-
* 如果使用了 onSet or onDelete,需要注意清理
|
|
2827
|
-
*/
|
|
2828
|
-
clear() {
|
|
2829
|
-
this._data = {};
|
|
2830
|
-
this.size = 0;
|
|
2850
|
+
return this.tags;
|
|
2831
2851
|
}
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
clone(target) {
|
|
2837
|
-
for (const key in this._data) {
|
|
2838
|
-
let item = this._data[key];
|
|
2839
|
-
// @ts-ignore
|
|
2840
|
-
target.setData(key, item);
|
|
2852
|
+
setTags(tags) {
|
|
2853
|
+
let obj = this.getTags();
|
|
2854
|
+
for (const key in tags) {
|
|
2855
|
+
obj[key] = tags[key];
|
|
2841
2856
|
}
|
|
2842
|
-
return target;
|
|
2843
2857
|
}
|
|
2844
|
-
|
|
2845
|
-
this.
|
|
2846
|
-
this.size = dict.size;
|
|
2858
|
+
getTag(name) {
|
|
2859
|
+
return this.getTags()[name];
|
|
2847
2860
|
}
|
|
2848
|
-
|
|
2849
|
-
this.
|
|
2850
|
-
this._onSet = handler;
|
|
2861
|
+
setTag(name, value) {
|
|
2862
|
+
this.getTags()[name] = value;
|
|
2851
2863
|
}
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2864
|
+
}
|
|
2865
|
+
class ListSource extends EventDispatcher {
|
|
2866
|
+
constructor() {
|
|
2867
|
+
super(...arguments);
|
|
2868
|
+
this._data = [];
|
|
2855
2869
|
}
|
|
2856
2870
|
/**
|
|
2857
|
-
*
|
|
2858
|
-
* @param
|
|
2859
|
-
* @param
|
|
2871
|
+
* 通过数组创建 ListSource。ListSource的id自动生成。如果需要指定编号,可设置 idCreator
|
|
2872
|
+
* @param arr
|
|
2873
|
+
* @param idCreator
|
|
2860
2874
|
*/
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
if (this._onSet !== null) {
|
|
2875
|
-
this._onSet.call(this._onSetCaller, key, value);
|
|
2876
|
-
}
|
|
2877
|
-
}
|
|
2878
|
-
setByMap(m) {
|
|
2879
|
-
for (const key in m) {
|
|
2880
|
-
let item = m[key];
|
|
2881
|
-
// @ts-ignore
|
|
2882
|
-
this.setData(key, item);
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
addDictionary(other) {
|
|
2886
|
-
if (other.length() == 0) {
|
|
2887
|
-
return;
|
|
2888
|
-
}
|
|
2889
|
-
for (const key in other._data) {
|
|
2890
|
-
let item = other._data[key];
|
|
2891
|
-
// @ts-ignore
|
|
2892
|
-
this.setData(key, item);
|
|
2875
|
+
static createByArray(arr, idCreator) {
|
|
2876
|
+
let root = new ListSource();
|
|
2877
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2878
|
+
let item = arr[i];
|
|
2879
|
+
let id = "";
|
|
2880
|
+
if (idCreator) {
|
|
2881
|
+
id = idCreator(item);
|
|
2882
|
+
}
|
|
2883
|
+
else {
|
|
2884
|
+
id = identutil.genOne();
|
|
2885
|
+
}
|
|
2886
|
+
let node = ListNode.create(id, item);
|
|
2887
|
+
root.add(node, false);
|
|
2893
2888
|
}
|
|
2889
|
+
return root;
|
|
2894
2890
|
}
|
|
2895
|
-
|
|
2896
|
-
if (
|
|
2897
|
-
|
|
2891
|
+
static createByListItem(arr, target) {
|
|
2892
|
+
if (!target) {
|
|
2893
|
+
target = new ListSource();
|
|
2898
2894
|
}
|
|
2899
|
-
for (
|
|
2900
|
-
|
|
2901
|
-
|
|
2895
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2896
|
+
let item = arr[i];
|
|
2897
|
+
let id = "";
|
|
2898
|
+
let node = ListNode.create(id);
|
|
2899
|
+
node.id = item.id;
|
|
2900
|
+
node.tags = item.tags;
|
|
2901
|
+
node.data = item.data;
|
|
2902
|
+
target.add(node, false);
|
|
2902
2903
|
}
|
|
2904
|
+
return target;
|
|
2903
2905
|
}
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
* @param key
|
|
2907
|
-
*/
|
|
2908
|
-
get(key) {
|
|
2909
|
-
return this._data[key];
|
|
2906
|
+
at(index) {
|
|
2907
|
+
return this._data[index];
|
|
2910
2908
|
}
|
|
2911
|
-
|
|
2912
|
-
return
|
|
2909
|
+
first() {
|
|
2910
|
+
return this._data[0];
|
|
2913
2911
|
}
|
|
2914
|
-
|
|
2915
|
-
this.
|
|
2912
|
+
last() {
|
|
2913
|
+
return this._data[this._data.length - 1];
|
|
2916
2914
|
}
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2915
|
+
length() {
|
|
2916
|
+
return this._data.length;
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* 添加项,无法添加相同的项
|
|
2920
|
+
* @param node
|
|
2921
|
+
* @param enableDispatch 默认为true
|
|
2922
|
+
*/
|
|
2923
|
+
add(node, enableDispatch = true) {
|
|
2924
|
+
if (this.contains(node)) {
|
|
2920
2925
|
return;
|
|
2921
2926
|
}
|
|
2922
|
-
|
|
2923
|
-
|
|
2927
|
+
this._data.push(node);
|
|
2928
|
+
node.root = this;
|
|
2929
|
+
if (enableDispatch) {
|
|
2930
|
+
this.dispatch(ListSource.EVENT_ADD, { node: node });
|
|
2924
2931
|
}
|
|
2925
|
-
this._data[key] = null;
|
|
2926
|
-
delete this._data[key];
|
|
2927
|
-
this.size--;
|
|
2928
2932
|
}
|
|
2929
|
-
|
|
2930
|
-
|
|
2933
|
+
getById(id) {
|
|
2934
|
+
for (let i = 0; i < this._data.length; i++) {
|
|
2935
|
+
let node = this._data[i];
|
|
2936
|
+
if (node.id == id) {
|
|
2937
|
+
return node;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
return null;
|
|
2931
2941
|
}
|
|
2932
|
-
|
|
2933
|
-
|
|
2942
|
+
remove(node) {
|
|
2943
|
+
let index = this._data.indexOf(node);
|
|
2944
|
+
if (index == -1) {
|
|
2945
|
+
return;
|
|
2946
|
+
}
|
|
2947
|
+
node.root = null;
|
|
2948
|
+
this._data.splice(index, 1);
|
|
2949
|
+
this.dispatch(ListSource.EVENT_REMOVE, { node: node, index: index });
|
|
2934
2950
|
}
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
this.
|
|
2938
|
-
return [value, value !== undefined];
|
|
2951
|
+
removeAll() {
|
|
2952
|
+
this._data.length = 0;
|
|
2953
|
+
this.dispatch(ListSource.EVENT_REMOVE_ALL);
|
|
2939
2954
|
}
|
|
2940
|
-
|
|
2941
|
-
|
|
2955
|
+
swap(a, b) {
|
|
2956
|
+
let aidx = this.indexOf(a);
|
|
2957
|
+
let bidx = this.indexOf(b);
|
|
2958
|
+
let d = this._data;
|
|
2959
|
+
[d[aidx], d[bidx]] = [d[bidx], a[aidx]];
|
|
2960
|
+
this.dispatch(ListSource.EVENT_SWAP, { nodes: [a, b], indexs: [aidx, bidx] });
|
|
2942
2961
|
}
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
for (const key in this._data) {
|
|
2946
|
-
let item = this._data[key];
|
|
2947
|
-
items.push(item);
|
|
2948
|
-
}
|
|
2949
|
-
return items;
|
|
2962
|
+
contains(node) {
|
|
2963
|
+
return this.indexOf(node) != -1;
|
|
2950
2964
|
}
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2965
|
+
containsById(id) {
|
|
2966
|
+
return this.indexOfById(id) != -1;
|
|
2967
|
+
}
|
|
2968
|
+
indexOf(node) {
|
|
2969
|
+
for (let i = 0; i < this._data.length; i++) {
|
|
2970
|
+
let item = this._data[i];
|
|
2971
|
+
if (item.id == node.id) {
|
|
2972
|
+
return i;
|
|
2973
|
+
}
|
|
2955
2974
|
}
|
|
2956
|
-
return
|
|
2975
|
+
return -1;
|
|
2957
2976
|
}
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
forEach(handler) {
|
|
2964
|
-
let iterator = new DictIterator();
|
|
2965
|
-
for (const key in this._data) {
|
|
2966
|
-
let val = this._data[key];
|
|
2967
|
-
// @ts-ignore
|
|
2968
|
-
handler(key, val, iterator);
|
|
2969
|
-
if (iterator.isBreak()) {
|
|
2970
|
-
return iterator;
|
|
2977
|
+
indexOfById(id) {
|
|
2978
|
+
for (let i = 0; i < this._data.length; i++) {
|
|
2979
|
+
let item = this._data[i];
|
|
2980
|
+
if (item.id == id) {
|
|
2981
|
+
return i;
|
|
2971
2982
|
}
|
|
2972
2983
|
}
|
|
2973
|
-
return
|
|
2984
|
+
return -1;
|
|
2974
2985
|
}
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
for (const key in this._data) {
|
|
2979
|
-
return this._data[key];
|
|
2986
|
+
setData(node, data) {
|
|
2987
|
+
if (!node) {
|
|
2988
|
+
return;
|
|
2980
2989
|
}
|
|
2981
|
-
|
|
2990
|
+
node.data = data;
|
|
2991
|
+
this.dispatch(ListSource.EVENT_DATA_SET, { node: node, data: data });
|
|
2982
2992
|
}
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
for (const key in this._data) {
|
|
2988
|
-
let val = this._data[key];
|
|
2989
|
-
// @ts-ignore
|
|
2990
|
-
if (handler(key, val)) {
|
|
2991
|
-
return val;
|
|
2992
|
-
}
|
|
2993
|
+
setNodeTags(node, tag, value) {
|
|
2994
|
+
let tags = node.getTags();
|
|
2995
|
+
if (tags[tag] === value) {
|
|
2996
|
+
return;
|
|
2993
2997
|
}
|
|
2998
|
+
tags[tag] = value;
|
|
2999
|
+
this.dispatch(ListSource.EVENT_TAGS_SET, { node: node, tag: tag, value: value });
|
|
2994
3000
|
}
|
|
2995
3001
|
/**
|
|
2996
|
-
*
|
|
2997
|
-
* @param
|
|
3002
|
+
* 派发 refresh 消息
|
|
3003
|
+
* @param node
|
|
2998
3004
|
*/
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
for (
|
|
3004
|
-
let
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
newsize--;
|
|
3008
|
-
delete newdata[key];
|
|
3009
|
-
}
|
|
3010
|
-
if (iterator.isBreak()) {
|
|
3011
|
-
break;
|
|
3005
|
+
refresh(node) {
|
|
3006
|
+
this.dispatch(ListSource.EVENT_REFRESH, { node: node });
|
|
3007
|
+
}
|
|
3008
|
+
walk(f) {
|
|
3009
|
+
for (let i = 0; i < this.length(); i++) {
|
|
3010
|
+
let item = this._data[i];
|
|
3011
|
+
if (!f(item)) {
|
|
3012
|
+
return false;
|
|
3012
3013
|
}
|
|
3013
3014
|
}
|
|
3014
|
-
this.size = newsize;
|
|
3015
3015
|
}
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
*/
|
|
3021
|
-
findByCondition(cond, target) {
|
|
3022
|
-
if (!target) {
|
|
3023
|
-
throw new Error("需要设置目标对象");
|
|
3016
|
+
walkPrev(node, f) {
|
|
3017
|
+
let index = this.indexOf(node);
|
|
3018
|
+
if (index == -1) {
|
|
3019
|
+
return;
|
|
3024
3020
|
}
|
|
3025
|
-
let
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
let val = this._data[key];
|
|
3030
|
-
// @ts-ignore
|
|
3031
|
-
if (cond(key, val, iterator)) {
|
|
3032
|
-
newsize++;
|
|
3033
|
-
newdata[key] = val;
|
|
3034
|
-
}
|
|
3035
|
-
if (iterator.isBreak()) {
|
|
3036
|
-
break;
|
|
3021
|
+
for (let i = index; i >= 0; i--) {
|
|
3022
|
+
let item = this._data[i];
|
|
3023
|
+
if (!f(item)) {
|
|
3024
|
+
return false;
|
|
3037
3025
|
}
|
|
3038
3026
|
}
|
|
3039
|
-
target._reset(newdata, newsize);
|
|
3040
|
-
return target;
|
|
3041
3027
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
for (const key in this._data) {
|
|
3045
|
-
let val = this._data[key];
|
|
3046
|
-
// @ts-ignore
|
|
3047
|
-
let newkey = createKey(key, val);
|
|
3048
|
-
let dict = newdata[newkey];
|
|
3049
|
-
if (!dict) {
|
|
3050
|
-
if (ITEM_CLASS) {
|
|
3051
|
-
dict = new ITEM_CLASS();
|
|
3052
|
-
}
|
|
3053
|
-
else {
|
|
3054
|
-
dict = new Dictionary();
|
|
3055
|
-
}
|
|
3056
|
-
newdata[newkey] = dict;
|
|
3057
|
-
}
|
|
3058
|
-
dict.set(key, val);
|
|
3059
|
-
}
|
|
3060
|
-
return newdata;
|
|
3028
|
+
get data() {
|
|
3029
|
+
return this._data;
|
|
3061
3030
|
}
|
|
3062
3031
|
}
|
|
3032
|
+
/**
|
|
3033
|
+
* 设置数据时触发
|
|
3034
|
+
* dispatchParams = {node:ListNode}
|
|
3035
|
+
*/
|
|
3036
|
+
ListSource.EVENT_ADD = "add";
|
|
3037
|
+
/**
|
|
3038
|
+
* 设置数据时触发
|
|
3039
|
+
* dispatchParams = {node:ListNode, index:number}
|
|
3040
|
+
*/
|
|
3041
|
+
ListSource.EVENT_REMOVE = "remove";
|
|
3042
|
+
/**
|
|
3043
|
+
* 设置数据时触发
|
|
3044
|
+
*/
|
|
3045
|
+
ListSource.EVENT_REMOVE_ALL = "remove_all";
|
|
3046
|
+
/**
|
|
3047
|
+
* 刷新数据节点
|
|
3048
|
+
* dispatchParams = {node:ListNode}
|
|
3049
|
+
*/
|
|
3050
|
+
ListSource.EVENT_REFRESH = "refresh";
|
|
3051
|
+
/**
|
|
3052
|
+
* 设置数据时触发
|
|
3053
|
+
* dispatchParams = nodes: [ListNode], indexs: [number]
|
|
3054
|
+
*/
|
|
3055
|
+
ListSource.EVENT_SWAP = "swap";
|
|
3056
|
+
/**
|
|
3057
|
+
* 设置数据时触发
|
|
3058
|
+
* dispatchParams = {node:ListNode, data:any}
|
|
3059
|
+
*/
|
|
3060
|
+
ListSource.EVENT_DATA_SET = "data_set";
|
|
3061
|
+
/**
|
|
3062
|
+
* 设置数据时触发
|
|
3063
|
+
* dispatchParams = {node:ListNode, tag:string, value:any}
|
|
3064
|
+
*/
|
|
3065
|
+
ListSource.EVENT_TAGS_SET = "tags_set";
|
|
3063
3066
|
|
|
3064
3067
|
class DictNode {
|
|
3065
3068
|
static create(id, data) {
|
|
@@ -6388,5 +6391,5 @@ class WidgetUtil {
|
|
|
6388
6391
|
}
|
|
6389
6392
|
var widgetutil = new WidgetUtil();
|
|
6390
6393
|
|
|
6391
|
-
export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, CameraUtil, CanvasUtil, Controller, ControllerDict, ControllerRepo, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, DocUtil, ErrorUtil, EventDispatcher, EventItem, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LOGGER_EVENT, LinkError, List, ListIterator, ListNode, ListSource, Listener, LogLevel, LogManager, Logger, MapUtil, MathUtil, Model, NetUtil, PathUtil, Pool, RandUtil, Route, RouteController, RouteList, RouteView, SampleCallbackList, SamplePool, SamplePoolSet, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, TreeUtil, UIManager, UIObjectRepo, UIPoolConfig, UISingleConfig, UIUtil, ViewDict, ViewEvent, ViewHistory, ViewList, ViewRepo, ViewState, WidgetAlign, WidgetUtil, XAssetManager, XEvent, arrayutil, assetx, bitutil, camerautil, canvasutil, convertutil, ctrlrepo, docutil, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, logmgr, maputil, mathutil, netutil, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, treeutil, uimgr, uirepo, uiutil, viewhistorys, viewrepo, widgetutil };
|
|
6394
|
+
export { ArrayUtil, AssetLoader, AssetURI, BitUtil, CallbackList, CameraUtil, CanvasUtil, Controller, ControllerDict, ControllerRepo, ConvertUtil, DictIterator, DictNode, DictSource, Dictionary, Dispatcher, DocUtil, ErrorUtil, EventDispatcher, EventItem, EventUtil, Factory, FloatUtil, GeometryUtil, IdentUtil, LOGGER_EVENT, LinkError, List, ListIterator, ListNode, ListSource, Listener, LogLevel, LogManager, Logger, MapObject, MapUtil, MapValue, MathUtil, Model, NetUtil, PathUtil, Pool, RandUtil, Route, RouteController, RouteList, RouteView, SampleCallbackList, SamplePool, SamplePoolSet, ScaleUtil, SimpleModel, StringUtil, TimeUtil, Timer, TreeIterator, TreeNode, TreeNodePlugin, TreeRoot, TreeRootPlugin, TreeUtil, UIManager, UIObjectRepo, UIPoolConfig, UISingleConfig, UIUtil, ViewDict, ViewEvent, ViewHistory, ViewList, ViewRepo, ViewState, WidgetAlign, WidgetUtil, XAssetManager, XEvent, arrayutil, assetx, bitutil, camerautil, canvasutil, convertutil, ctrlrepo, docutil, errorutil, eventmgr, eventutil, floatutil, formatutil, geoutil, identutil, loadAtlas, logmgr, maputil, mathutil, netutil, parseAtlas, parsePlist, pathutil, randutil, resutil, scaleutil, stringutil, timer, timeutil, treeutil, uimgr, uirepo, uiutil, viewhistorys, viewrepo, widgetutil };
|
|
6392
6395
|
//# sourceMappingURL=index.esm.js.map
|