@zhongguo168a/yxeditor-common 0.0.65 → 0.0.67
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 +12 -19
- package/dist/index.esm.js +401 -416
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1029,280 +1029,6 @@ 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
|
-
|
|
1306
1032
|
class ConvertUtil {
|
|
1307
1033
|
anyToBoolean(val, defaultValue = false) {
|
|
1308
1034
|
if (val == null) {
|
|
@@ -1395,42 +1121,27 @@ class ConvertUtil {
|
|
|
1395
1121
|
}
|
|
1396
1122
|
const convertutil = new ConvertUtil();
|
|
1397
1123
|
|
|
1398
|
-
class MapObject extends
|
|
1399
|
-
|
|
1400
|
-
|
|
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;
|
|
1124
|
+
class MapObject extends Object {
|
|
1125
|
+
set(key, val) {
|
|
1126
|
+
this[key] = val;
|
|
1416
1127
|
}
|
|
1417
|
-
|
|
1418
|
-
this
|
|
1128
|
+
delete(key) {
|
|
1129
|
+
delete this[key];
|
|
1419
1130
|
}
|
|
1420
|
-
isUndefined() {
|
|
1421
|
-
return this
|
|
1131
|
+
isUndefined(key) {
|
|
1132
|
+
return this[key] == undefined;
|
|
1422
1133
|
}
|
|
1423
|
-
|
|
1424
|
-
return maputil.number(this
|
|
1134
|
+
getNumber(key) {
|
|
1135
|
+
return maputil.number(this, key);
|
|
1425
1136
|
}
|
|
1426
|
-
|
|
1427
|
-
return maputil.string(this
|
|
1137
|
+
getString(key) {
|
|
1138
|
+
return maputil.string(this, key);
|
|
1428
1139
|
}
|
|
1429
|
-
|
|
1430
|
-
return maputil.boolean(this
|
|
1140
|
+
getBoolean(key) {
|
|
1141
|
+
return maputil.boolean(this, key);
|
|
1431
1142
|
}
|
|
1432
|
-
|
|
1433
|
-
return this
|
|
1143
|
+
get(key) {
|
|
1144
|
+
return this[key];
|
|
1434
1145
|
}
|
|
1435
1146
|
}
|
|
1436
1147
|
class MapUtil {
|
|
@@ -2924,145 +2635,419 @@ class ListSource extends EventDispatcher {
|
|
|
2924
2635
|
if (this.contains(node)) {
|
|
2925
2636
|
return;
|
|
2926
2637
|
}
|
|
2927
|
-
this._data.push(node);
|
|
2928
|
-
node.root = this;
|
|
2929
|
-
if (enableDispatch) {
|
|
2930
|
-
this.dispatch(ListSource.EVENT_ADD, { node: node });
|
|
2638
|
+
this._data.push(node);
|
|
2639
|
+
node.root = this;
|
|
2640
|
+
if (enableDispatch) {
|
|
2641
|
+
this.dispatch(ListSource.EVENT_ADD, { node: node });
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
getById(id) {
|
|
2645
|
+
for (let i = 0; i < this._data.length; i++) {
|
|
2646
|
+
let node = this._data[i];
|
|
2647
|
+
if (node.id == id) {
|
|
2648
|
+
return node;
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
return null;
|
|
2652
|
+
}
|
|
2653
|
+
remove(node) {
|
|
2654
|
+
let index = this._data.indexOf(node);
|
|
2655
|
+
if (index == -1) {
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
node.root = null;
|
|
2659
|
+
this._data.splice(index, 1);
|
|
2660
|
+
this.dispatch(ListSource.EVENT_REMOVE, { node: node, index: index });
|
|
2661
|
+
}
|
|
2662
|
+
removeAll() {
|
|
2663
|
+
this._data.length = 0;
|
|
2664
|
+
this.dispatch(ListSource.EVENT_REMOVE_ALL);
|
|
2665
|
+
}
|
|
2666
|
+
swap(a, b) {
|
|
2667
|
+
let aidx = this.indexOf(a);
|
|
2668
|
+
let bidx = this.indexOf(b);
|
|
2669
|
+
let d = this._data;
|
|
2670
|
+
[d[aidx], d[bidx]] = [d[bidx], a[aidx]];
|
|
2671
|
+
this.dispatch(ListSource.EVENT_SWAP, { nodes: [a, b], indexs: [aidx, bidx] });
|
|
2672
|
+
}
|
|
2673
|
+
contains(node) {
|
|
2674
|
+
return this.indexOf(node) != -1;
|
|
2675
|
+
}
|
|
2676
|
+
containsById(id) {
|
|
2677
|
+
return this.indexOfById(id) != -1;
|
|
2678
|
+
}
|
|
2679
|
+
indexOf(node) {
|
|
2680
|
+
for (let i = 0; i < this._data.length; i++) {
|
|
2681
|
+
let item = this._data[i];
|
|
2682
|
+
if (item.id == node.id) {
|
|
2683
|
+
return i;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
return -1;
|
|
2687
|
+
}
|
|
2688
|
+
indexOfById(id) {
|
|
2689
|
+
for (let i = 0; i < this._data.length; i++) {
|
|
2690
|
+
let item = this._data[i];
|
|
2691
|
+
if (item.id == id) {
|
|
2692
|
+
return i;
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
return -1;
|
|
2696
|
+
}
|
|
2697
|
+
setData(node, data) {
|
|
2698
|
+
if (!node) {
|
|
2699
|
+
return;
|
|
2700
|
+
}
|
|
2701
|
+
node.data = data;
|
|
2702
|
+
this.dispatch(ListSource.EVENT_DATA_SET, { node: node, data: data });
|
|
2703
|
+
}
|
|
2704
|
+
setNodeTags(node, tag, value) {
|
|
2705
|
+
let tags = node.getTags();
|
|
2706
|
+
if (tags[tag] === value) {
|
|
2707
|
+
return;
|
|
2708
|
+
}
|
|
2709
|
+
tags[tag] = value;
|
|
2710
|
+
this.dispatch(ListSource.EVENT_TAGS_SET, { node: node, tag: tag, value: value });
|
|
2711
|
+
}
|
|
2712
|
+
/**
|
|
2713
|
+
* 派发 refresh 消息
|
|
2714
|
+
* @param node
|
|
2715
|
+
*/
|
|
2716
|
+
refresh(node) {
|
|
2717
|
+
this.dispatch(ListSource.EVENT_REFRESH, { node: node });
|
|
2718
|
+
}
|
|
2719
|
+
walk(f) {
|
|
2720
|
+
for (let i = 0; i < this.length(); i++) {
|
|
2721
|
+
let item = this._data[i];
|
|
2722
|
+
if (!f(item)) {
|
|
2723
|
+
return false;
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
walkPrev(node, f) {
|
|
2728
|
+
let index = this.indexOf(node);
|
|
2729
|
+
if (index == -1) {
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2732
|
+
for (let i = index; i >= 0; i--) {
|
|
2733
|
+
let item = this._data[i];
|
|
2734
|
+
if (!f(item)) {
|
|
2735
|
+
return false;
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
get data() {
|
|
2740
|
+
return this._data;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
/**
|
|
2744
|
+
* 设置数据时触发
|
|
2745
|
+
* dispatchParams = {node:ListNode}
|
|
2746
|
+
*/
|
|
2747
|
+
ListSource.EVENT_ADD = "add";
|
|
2748
|
+
/**
|
|
2749
|
+
* 设置数据时触发
|
|
2750
|
+
* dispatchParams = {node:ListNode, index:number}
|
|
2751
|
+
*/
|
|
2752
|
+
ListSource.EVENT_REMOVE = "remove";
|
|
2753
|
+
/**
|
|
2754
|
+
* 设置数据时触发
|
|
2755
|
+
*/
|
|
2756
|
+
ListSource.EVENT_REMOVE_ALL = "remove_all";
|
|
2757
|
+
/**
|
|
2758
|
+
* 刷新数据节点
|
|
2759
|
+
* dispatchParams = {node:ListNode}
|
|
2760
|
+
*/
|
|
2761
|
+
ListSource.EVENT_REFRESH = "refresh";
|
|
2762
|
+
/**
|
|
2763
|
+
* 设置数据时触发
|
|
2764
|
+
* dispatchParams = nodes: [ListNode], indexs: [number]
|
|
2765
|
+
*/
|
|
2766
|
+
ListSource.EVENT_SWAP = "swap";
|
|
2767
|
+
/**
|
|
2768
|
+
* 设置数据时触发
|
|
2769
|
+
* dispatchParams = {node:ListNode, data:any}
|
|
2770
|
+
*/
|
|
2771
|
+
ListSource.EVENT_DATA_SET = "data_set";
|
|
2772
|
+
/**
|
|
2773
|
+
* 设置数据时触发
|
|
2774
|
+
* dispatchParams = {node:ListNode, tag:string, value:any}
|
|
2775
|
+
*/
|
|
2776
|
+
ListSource.EVENT_TAGS_SET = "tags_set";
|
|
2777
|
+
|
|
2778
|
+
class DictIterator {
|
|
2779
|
+
break() {
|
|
2780
|
+
this._isBreak = true;
|
|
2781
|
+
}
|
|
2782
|
+
isBreak() {
|
|
2783
|
+
return this._isBreak;
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
class Dictionary {
|
|
2787
|
+
constructor(data) {
|
|
2788
|
+
this.size = 0;
|
|
2789
|
+
if (data) {
|
|
2790
|
+
this._data = data;
|
|
2791
|
+
}
|
|
2792
|
+
else {
|
|
2793
|
+
this._data = {};
|
|
2794
|
+
}
|
|
2795
|
+
this._onSet = null;
|
|
2796
|
+
this._onDelete = null;
|
|
2797
|
+
}
|
|
2798
|
+
reset(data) {
|
|
2799
|
+
this._reset(data);
|
|
2800
|
+
}
|
|
2801
|
+
_reset(data, size) {
|
|
2802
|
+
this._data = data;
|
|
2803
|
+
if (size == undefined) {
|
|
2804
|
+
for (let _ in data) {
|
|
2805
|
+
size++;
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
this.size = size;
|
|
2809
|
+
}
|
|
2810
|
+
getData() {
|
|
2811
|
+
return this._data;
|
|
2812
|
+
}
|
|
2813
|
+
/**
|
|
2814
|
+
* 如果使用了 onSet or onDelete,需要注意清理
|
|
2815
|
+
*/
|
|
2816
|
+
clear() {
|
|
2817
|
+
this._data = {};
|
|
2818
|
+
this.size = 0;
|
|
2819
|
+
}
|
|
2820
|
+
/**
|
|
2821
|
+
* 克隆自身所有项到【target】对象,并返回【target】对象
|
|
2822
|
+
* @param target
|
|
2823
|
+
*/
|
|
2824
|
+
clone(target) {
|
|
2825
|
+
for (const key in this._data) {
|
|
2826
|
+
let item = this._data[key];
|
|
2827
|
+
// @ts-ignore
|
|
2828
|
+
target.setData(key, item);
|
|
2829
|
+
}
|
|
2830
|
+
return target;
|
|
2831
|
+
}
|
|
2832
|
+
resetByDict(dict) {
|
|
2833
|
+
this._data = dict._data;
|
|
2834
|
+
this.size = dict.size;
|
|
2835
|
+
}
|
|
2836
|
+
onSet(caller, handler) {
|
|
2837
|
+
this._onSetCaller = caller;
|
|
2838
|
+
this._onSet = handler;
|
|
2839
|
+
}
|
|
2840
|
+
onDelete(caller, handler) {
|
|
2841
|
+
this._onDelete = handler;
|
|
2842
|
+
this._onDeleteCaller = caller;
|
|
2843
|
+
}
|
|
2844
|
+
/**
|
|
2845
|
+
* 设置键值对,如果没有发生变化,不会触发onSet函数
|
|
2846
|
+
* @param key
|
|
2847
|
+
* @param value
|
|
2848
|
+
*/
|
|
2849
|
+
set(key, value) {
|
|
2850
|
+
this.setData(key, value);
|
|
2851
|
+
}
|
|
2852
|
+
setData(key, value) {
|
|
2853
|
+
if (this._data.hasOwnProperty(key)) ;
|
|
2854
|
+
else {
|
|
2855
|
+
this.size++;
|
|
2856
|
+
}
|
|
2857
|
+
let existed = this._data[key];
|
|
2858
|
+
if (existed == value) {
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2861
|
+
this._data[key] = value;
|
|
2862
|
+
if (this._onSet !== null) {
|
|
2863
|
+
this._onSet.call(this._onSetCaller, key, value);
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
setByMap(m) {
|
|
2867
|
+
for (const key in m) {
|
|
2868
|
+
let item = m[key];
|
|
2869
|
+
// @ts-ignore
|
|
2870
|
+
this.setData(key, item);
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
addDictionary(other) {
|
|
2874
|
+
if (other.length() == 0) {
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2877
|
+
for (const key in other._data) {
|
|
2878
|
+
let item = other._data[key];
|
|
2879
|
+
// @ts-ignore
|
|
2880
|
+
this.setData(key, item);
|
|
2931
2881
|
}
|
|
2932
2882
|
}
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2883
|
+
deleteDictionary(other) {
|
|
2884
|
+
if (other.length() == 0) {
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2887
|
+
for (const key in other._data) {
|
|
2888
|
+
// @ts-ignore
|
|
2889
|
+
this.delete(key);
|
|
2939
2890
|
}
|
|
2940
|
-
return null;
|
|
2941
2891
|
}
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2892
|
+
/**
|
|
2893
|
+
* 如果不存在,返回 undefined
|
|
2894
|
+
* @param key
|
|
2895
|
+
*/
|
|
2896
|
+
get(key) {
|
|
2897
|
+
return this._data[key];
|
|
2898
|
+
}
|
|
2899
|
+
exist(key) {
|
|
2900
|
+
return !!this._data[key];
|
|
2901
|
+
}
|
|
2902
|
+
delete(key) {
|
|
2903
|
+
this.deleteData(key);
|
|
2904
|
+
}
|
|
2905
|
+
deleteData(key) {
|
|
2906
|
+
const value = this._data[key];
|
|
2907
|
+
if (value === undefined) {
|
|
2945
2908
|
return;
|
|
2946
2909
|
}
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2910
|
+
if (this._onDelete !== null) {
|
|
2911
|
+
this._onDelete.call(this._onDeleteCaller, key, value);
|
|
2912
|
+
}
|
|
2913
|
+
this._data[key] = null;
|
|
2914
|
+
delete this._data[key];
|
|
2915
|
+
this.size--;
|
|
2950
2916
|
}
|
|
2951
|
-
|
|
2952
|
-
this._data
|
|
2953
|
-
this.dispatch(ListSource.EVENT_REMOVE_ALL);
|
|
2917
|
+
exists(key) {
|
|
2918
|
+
return !!this._data[key];
|
|
2954
2919
|
}
|
|
2955
|
-
|
|
2956
|
-
|
|
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] });
|
|
2920
|
+
length() {
|
|
2921
|
+
return this.size;
|
|
2961
2922
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
2923
|
+
pop(key) {
|
|
2924
|
+
const value = this._data[key];
|
|
2925
|
+
this.deleteData(key);
|
|
2926
|
+
return [value, value !== undefined];
|
|
2964
2927
|
}
|
|
2965
|
-
|
|
2966
|
-
return this.
|
|
2928
|
+
isEmpty() {
|
|
2929
|
+
return this.length() === 0;
|
|
2967
2930
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
}
|
|
2931
|
+
items() {
|
|
2932
|
+
const items = [];
|
|
2933
|
+
for (const key in this._data) {
|
|
2934
|
+
let item = this._data[key];
|
|
2935
|
+
items.push(item);
|
|
2974
2936
|
}
|
|
2975
|
-
return
|
|
2937
|
+
return items;
|
|
2976
2938
|
}
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
return i;
|
|
2982
|
-
}
|
|
2939
|
+
keys() {
|
|
2940
|
+
const keys = [];
|
|
2941
|
+
for (const key in this._data) {
|
|
2942
|
+
keys.push(key);
|
|
2983
2943
|
}
|
|
2984
|
-
return
|
|
2944
|
+
return keys;
|
|
2985
2945
|
}
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2946
|
+
/**
|
|
2947
|
+
*
|
|
2948
|
+
* @param handler 可以使用【iterator】中断遍历
|
|
2949
|
+
* @return iterator 获取是否中断了
|
|
2950
|
+
*/
|
|
2951
|
+
forEach(handler) {
|
|
2952
|
+
let iterator = new DictIterator();
|
|
2953
|
+
for (const key in this._data) {
|
|
2954
|
+
let val = this._data[key];
|
|
2955
|
+
// @ts-ignore
|
|
2956
|
+
handler(key, val, iterator);
|
|
2957
|
+
if (iterator.isBreak()) {
|
|
2958
|
+
return iterator;
|
|
2959
|
+
}
|
|
2989
2960
|
}
|
|
2990
|
-
|
|
2991
|
-
this.dispatch(ListSource.EVENT_DATA_SET, { node: node, data: data });
|
|
2961
|
+
return iterator;
|
|
2992
2962
|
}
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2963
|
+
/**
|
|
2964
|
+
*/
|
|
2965
|
+
first() {
|
|
2966
|
+
for (const key in this._data) {
|
|
2967
|
+
return this._data[key];
|
|
2997
2968
|
}
|
|
2998
|
-
|
|
2999
|
-
this.dispatch(ListSource.EVENT_TAGS_SET, { node: node, tag: tag, value: value });
|
|
2969
|
+
return undefined;
|
|
3000
2970
|
}
|
|
3001
2971
|
/**
|
|
3002
|
-
*
|
|
3003
|
-
* @param node
|
|
2972
|
+
* @param handler 返回true结束迭代
|
|
3004
2973
|
*/
|
|
3005
|
-
|
|
3006
|
-
|
|
2974
|
+
firstByCondition(handler) {
|
|
2975
|
+
for (const key in this._data) {
|
|
2976
|
+
let val = this._data[key];
|
|
2977
|
+
// @ts-ignore
|
|
2978
|
+
if (handler(key, val)) {
|
|
2979
|
+
return val;
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
3007
2982
|
}
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
2983
|
+
/**
|
|
2984
|
+
* 移除符合条件的项
|
|
2985
|
+
* @param cond 可以使用【iterator】中断遍历
|
|
2986
|
+
*/
|
|
2987
|
+
removeByCondition(cond) {
|
|
2988
|
+
let newdata = this._data;
|
|
2989
|
+
let newsize = this.size;
|
|
2990
|
+
let iterator = new DictIterator();
|
|
2991
|
+
for (const key in this._data) {
|
|
2992
|
+
let val = this._data[key];
|
|
2993
|
+
// @ts-ignore
|
|
2994
|
+
if (cond(key, val, iterator)) {
|
|
2995
|
+
newsize--;
|
|
2996
|
+
delete newdata[key];
|
|
2997
|
+
}
|
|
2998
|
+
if (iterator.isBreak()) {
|
|
2999
|
+
break;
|
|
3013
3000
|
}
|
|
3014
3001
|
}
|
|
3002
|
+
this.size = newsize;
|
|
3015
3003
|
}
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3004
|
+
/**
|
|
3005
|
+
* 查找符合条件的项保存到【target】对象中,并返回【target】对象
|
|
3006
|
+
* @param cond 可以使用【iterator】中断遍历
|
|
3007
|
+
* @param target 存到目标对象中
|
|
3008
|
+
*/
|
|
3009
|
+
findByCondition(cond, target) {
|
|
3010
|
+
if (!target) {
|
|
3011
|
+
throw new Error("需要设置目标对象");
|
|
3020
3012
|
}
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3013
|
+
let iterator = new DictIterator();
|
|
3014
|
+
let newdata = {};
|
|
3015
|
+
let newsize = 0;
|
|
3016
|
+
for (const key in this._data) {
|
|
3017
|
+
let val = this._data[key];
|
|
3018
|
+
// @ts-ignore
|
|
3019
|
+
if (cond(key, val, iterator)) {
|
|
3020
|
+
newsize++;
|
|
3021
|
+
newdata[key] = val;
|
|
3022
|
+
}
|
|
3023
|
+
if (iterator.isBreak()) {
|
|
3024
|
+
break;
|
|
3025
3025
|
}
|
|
3026
3026
|
}
|
|
3027
|
+
target._reset(newdata, newsize);
|
|
3028
|
+
return target;
|
|
3027
3029
|
}
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
+
groupByCondition(createKey, ITEM_CLASS) {
|
|
3031
|
+
let newdata = {};
|
|
3032
|
+
for (const key in this._data) {
|
|
3033
|
+
let val = this._data[key];
|
|
3034
|
+
// @ts-ignore
|
|
3035
|
+
let newkey = createKey(key, val);
|
|
3036
|
+
let dict = newdata[newkey];
|
|
3037
|
+
if (!dict) {
|
|
3038
|
+
if (ITEM_CLASS) {
|
|
3039
|
+
dict = new ITEM_CLASS();
|
|
3040
|
+
}
|
|
3041
|
+
else {
|
|
3042
|
+
dict = new Dictionary();
|
|
3043
|
+
}
|
|
3044
|
+
newdata[newkey] = dict;
|
|
3045
|
+
}
|
|
3046
|
+
dict.set(key, val);
|
|
3047
|
+
}
|
|
3048
|
+
return newdata;
|
|
3030
3049
|
}
|
|
3031
3050
|
}
|
|
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";
|
|
3066
3051
|
|
|
3067
3052
|
class DictNode {
|
|
3068
3053
|
static create(id, data) {
|
|
@@ -3887,10 +3872,10 @@ class ViewRepo extends ViewDict {
|
|
|
3887
3872
|
return list;
|
|
3888
3873
|
}
|
|
3889
3874
|
/**
|
|
3890
|
-
*
|
|
3891
|
-
* @param
|
|
3875
|
+
* 往上追踪,返回第一个包含 RouteComponent 的节点, 返回节点中的 RouteView
|
|
3876
|
+
* @param node
|
|
3892
3877
|
*/
|
|
3893
|
-
|
|
3878
|
+
tailNode(node) {
|
|
3894
3879
|
let current = node;
|
|
3895
3880
|
while (current != null) {
|
|
3896
3881
|
let com = node.getComponent(RouteComponent);
|
|
@@ -6453,5 +6438,5 @@ class WidgetUtil {
|
|
|
6453
6438
|
}
|
|
6454
6439
|
var widgetutil = new WidgetUtil();
|
|
6455
6440
|
|
|
6456
|
-
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,
|
|
6441
|
+
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, 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 };
|
|
6457
6442
|
//# sourceMappingURL=index.esm.js.map
|