clickgo 3.11.34 → 3.12.0

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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/dist/app/demo/config.json +7 -1
  3. package/dist/app/demo/form/control/select/select.xml +1 -1
  4. package/dist/app/demo/form/control/tuiviewer/tuiviewer.js +35 -0
  5. package/dist/app/demo/form/control/tuiviewer/tuiviewer.xml +14 -0
  6. package/dist/app/demo/form/control/weditor/weditor.js +69 -0
  7. package/dist/app/demo/form/control/weditor/weditor.xml +22 -0
  8. package/dist/app/demo/form/main.js +10 -0
  9. package/dist/app/demo/form/main.xml +2 -0
  10. package/dist/app/demo/form/method/aform/aform.xml +1 -1
  11. package/dist/app/demo/form/method/dom/dom.js +12 -0
  12. package/dist/app/demo/form/method/dom/dom.xml +4 -0
  13. package/dist/app/demo/form/method/form/form.xml +7 -1
  14. package/dist/clickgo.js +1 -1
  15. package/dist/clickgo.ts +1 -1
  16. package/dist/control/arteditor.cgc +0 -0
  17. package/dist/control/box.cgc +0 -0
  18. package/dist/control/common.cgc +0 -0
  19. package/dist/control/desc.cgc +0 -0
  20. package/dist/control/drawer.cgc +0 -0
  21. package/dist/control/echarts.cgc +0 -0
  22. package/dist/control/form.cgc +0 -0
  23. package/dist/control/iconview.cgc +0 -0
  24. package/dist/control/map.cgc +0 -0
  25. package/dist/control/monaco.cgc +0 -0
  26. package/dist/control/nav.cgc +0 -0
  27. package/dist/control/page.cgc +0 -0
  28. package/dist/control/property.cgc +0 -0
  29. package/dist/control/table.cgc +0 -0
  30. package/dist/control/task.cgc +0 -0
  31. package/dist/control/tuieditor.cgc +0 -0
  32. package/dist/control/tuiviewer.cgc +0 -0
  33. package/dist/control/weditor.cgc +0 -0
  34. package/dist/control/xterm.cgc +0 -0
  35. package/dist/lib/control.js +5 -0
  36. package/dist/lib/control.ts +5 -0
  37. package/dist/lib/core.js +17 -0
  38. package/dist/lib/core.ts +15 -0
  39. package/dist/lib/dom.js +163 -6
  40. package/dist/lib/dom.ts +222 -6
  41. package/dist/lib/form.js +78 -15
  42. package/dist/lib/form.ts +93 -17
  43. package/dist/lib/fs.js +1 -1
  44. package/dist/lib/fs.ts +1 -1
  45. package/dist/lib/task.js +13 -0
  46. package/dist/lib/task.ts +19 -0
  47. package/dist/lib/tool.js +6 -11
  48. package/dist/lib/tool.ts +8 -10
  49. package/dist/theme/byterun.cgt +0 -0
  50. package/dist/theme/familiar.cgt +0 -0
  51. package/dist/theme/light.cgt +0 -0
  52. package/package.json +2 -2
  53. package/types/index.d.ts +17 -1
package/dist/lib/dom.js CHANGED
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.createElement = exports.exitFullscreen = exports.fullscreen = exports.siblingsData = exports.siblings = exports.index = exports.findParentByTag = exports.findParentByClass = exports.findParentByData = exports.bindResize = exports.bindMove = exports.is = exports.bindDrag = exports.setDragData = exports.bindLong = exports.allowEvent = exports.bindGesture = exports.bindDown = exports.bindDblClick = exports.bindClick = exports.getWatchInfo = exports.clearWatchProperty = exports.isWatchProperty = exports.watchProperty = exports.clearWatchStyle = exports.isWatchStyle = exports.watchStyle = exports.clearWatch = exports.isWatch = exports.unwatch = exports.watch = exports.getWatchCount = exports.clearWatchSize = exports.isWatchSize = exports.unwatchSize = exports.watchSize = exports.getWatchSizeCount = exports.getStyleCount = exports.removeStyle = exports.pushStyle = exports.removeFromStyleList = exports.createToStyleList = exports.hasTouchButMouse = exports.setGlobalCursor = exports.inPage = void 0;
35
+ exports.createElement = exports.exitFullscreen = exports.fullscreen = exports.siblingsData = exports.siblings = exports.index = exports.findParentByTag = exports.findParentByClass = exports.findParentByData = exports.bindResize = exports.bindMove = exports.is = exports.bindDrag = exports.setDragData = exports.bindLong = exports.allowEvent = exports.bindGesture = exports.bindDown = exports.bindDblClick = exports.bindClick = exports.getWatchInfo = exports.clearWatchProperty = exports.isWatchProperty = exports.watchProperty = exports.clearWatchStyle = exports.isWatchStyle = exports.watchStyle = exports.clearWatch = exports.isWatch = exports.unwatch = exports.watch = exports.getWatchCount = exports.clearWatchSize = exports.isWatchSize = exports.unwatchSize = exports.watchSize = exports.getWatchSizeCount = exports.clearWatchPosition = exports.isWatchPosition = exports.unwatchPosition = exports.watchPosition = exports.getStyleCount = exports.removeStyle = exports.pushStyle = exports.removeFromStyleList = exports.createToStyleList = exports.hasTouchButMouse = exports.setGlobalCursor = exports.inPage = void 0;
36
36
  const clickgo = __importStar(require("../clickgo"));
37
37
  const form = __importStar(require("./form"));
38
38
  const core = __importStar(require("./core"));
@@ -162,6 +162,102 @@ function getStyleCount(taskId, type) {
162
162
  return document.querySelectorAll(`#cg-style-task${taskId} > .cg-style-${type} > style`).length;
163
163
  }
164
164
  exports.getStyleCount = getStyleCount;
165
+ const watchPositionObjects = {};
166
+ let watchPositionIndex = 0;
167
+ function watchPosition(el, cb, immediate = false) {
168
+ if (isWatchPosition(el)) {
169
+ return false;
170
+ }
171
+ if (immediate) {
172
+ try {
173
+ const r = cb({
174
+ 'position': false,
175
+ 'size': false
176
+ });
177
+ if (r instanceof Promise) {
178
+ r.catch(function (e) {
179
+ console.log('dom.watchPosition', e);
180
+ });
181
+ }
182
+ }
183
+ catch (e) {
184
+ console.log('dom.watchPosition', e);
185
+ }
186
+ }
187
+ const formWrap = findParentByData(el, 'form-id');
188
+ if (!formWrap) {
189
+ return false;
190
+ }
191
+ const formId = formWrap.dataset.formId;
192
+ const panelWrap = findParentByData(el, 'panel-id');
193
+ const panelId = panelWrap ? panelWrap.dataset.panelId : 'default';
194
+ if (!watchPositionObjects[formId]) {
195
+ watchPositionObjects[formId] = {};
196
+ }
197
+ if (!watchPositionObjects[formId][panelId]) {
198
+ watchPositionObjects[formId][panelId] = {};
199
+ }
200
+ watchPositionObjects[formId][panelId][watchPositionIndex] = {
201
+ 'el': el,
202
+ 'rect': el.getBoundingClientRect(),
203
+ 'handler': cb
204
+ };
205
+ el.dataset.cgPoindex = watchPositionIndex.toString();
206
+ ++watchPositionIndex;
207
+ return true;
208
+ }
209
+ exports.watchPosition = watchPosition;
210
+ function unwatchPosition(el) {
211
+ const index = el.dataset.cgPoindex;
212
+ if (index === undefined) {
213
+ return;
214
+ }
215
+ const formWrap = findParentByData(el, 'form-id');
216
+ if (!formWrap) {
217
+ return;
218
+ }
219
+ const formId = formWrap.dataset.formId;
220
+ const panelWrap = findParentByData(el, 'panel-id');
221
+ const panelId = panelWrap ? panelWrap.dataset.panelId : 'default';
222
+ const item = watchPositionObjects[formId][panelId][index];
223
+ el.removeAttribute('data-cg-poindex');
224
+ delete watchPositionObjects[formId][panelId][index];
225
+ if (Object.keys(watchPositionObjects[formId][panelId]).length) {
226
+ return;
227
+ }
228
+ delete watchPositionObjects[formId][panelId];
229
+ if (Object.keys(watchPositionObjects[formId]).length) {
230
+ return;
231
+ }
232
+ delete watchPositionObjects[formId];
233
+ }
234
+ exports.unwatchPosition = unwatchPosition;
235
+ function isWatchPosition(el) {
236
+ return el.dataset.cgPoindex ? true : false;
237
+ }
238
+ exports.isWatchPosition = isWatchPosition;
239
+ function clearWatchPosition(formId, panelId) {
240
+ if (!watchPositionObjects[formId]) {
241
+ return;
242
+ }
243
+ for (const panel in watchPositionObjects[formId]) {
244
+ if (panelId) {
245
+ if (panel !== panelId.toString()) {
246
+ continue;
247
+ }
248
+ }
249
+ for (const index in watchPositionObjects[formId][panel]) {
250
+ const item = watchPositionObjects[formId][panel][index];
251
+ item.el.removeAttribute('data-cg-poindex');
252
+ }
253
+ delete watchPositionObjects[formId][panel];
254
+ }
255
+ if (Object.keys(watchPositionObjects[formId]).length) {
256
+ return;
257
+ }
258
+ delete watchPositionObjects[formId];
259
+ }
260
+ exports.clearWatchPosition = clearWatchPosition;
165
261
  const watchSizeList = {};
166
262
  function getWatchSizeCount(taskId) {
167
263
  if (!taskId) {
@@ -582,7 +678,7 @@ function clearWatchProperty(formId, panelId) {
582
678
  }
583
679
  exports.clearWatchProperty = clearWatchProperty;
584
680
  function getWatchInfo() {
585
- var _a;
681
+ var _a, _b;
586
682
  const rtn = {
587
683
  'formId': 0,
588
684
  'default': {},
@@ -612,15 +708,20 @@ function getWatchInfo() {
612
708
  'property': {
613
709
  'count': 0,
614
710
  'list': []
711
+ },
712
+ 'position': {
713
+ 'count': 0
615
714
  }
616
715
  };
617
716
  }
618
717
  ++ritem[cname][type].count;
619
- for (const name in item.names) {
620
- if (ritem[cname][type].list.includes(name)) {
621
- continue;
718
+ if (item.names && type !== 'position') {
719
+ for (const name in item.names) {
720
+ if (ritem[cname][type].list.includes(name)) {
721
+ continue;
722
+ }
723
+ ritem[cname][type].list.push(name);
622
724
  }
623
- ritem[cname][type].list.push(name);
624
725
  }
625
726
  };
626
727
  if (watchStyleList[formId]) {
@@ -651,6 +752,20 @@ function getWatchInfo() {
651
752
  }
652
753
  }
653
754
  }
755
+ if (watchPositionObjects[formId]) {
756
+ if (watchPositionObjects[formId].default) {
757
+ for (const index in watchPositionObjects[formId].default) {
758
+ handler(watchPositionObjects[formId].default[index], 'position');
759
+ }
760
+ }
761
+ for (const id of panelIds) {
762
+ if ((_b = watchPositionObjects[formId]) === null || _b === void 0 ? void 0 : _b[id]) {
763
+ for (const index in watchPositionObjects[formId][id]) {
764
+ handler(watchPositionObjects[formId][id][index], 'position', id.toString());
765
+ }
766
+ }
767
+ }
768
+ }
654
769
  return rtn;
655
770
  }
656
771
  exports.getWatchInfo = getWatchInfo;
@@ -731,6 +846,48 @@ const watchTimerHandler = function () {
731
846
  }
732
847
  }
733
848
  }
849
+ if (watchPositionObjects[formId]) {
850
+ const handler = (item, panelId, index) => {
851
+ if (!document.body.contains(item.el)) {
852
+ delete watchPositionObjects[formId][panelId][index];
853
+ if (!Object.keys(watchPositionObjects[formId][panelId]).length) {
854
+ delete watchPositionObjects[formId][panelId];
855
+ }
856
+ if (!Object.keys(watchPositionObjects[formId]).length) {
857
+ delete watchPositionObjects[formId];
858
+ }
859
+ return;
860
+ }
861
+ const rect = item.el.getBoundingClientRect();
862
+ let position = false;
863
+ let size = false;
864
+ if (item.rect.left !== rect.left || item.rect.top !== rect.top) {
865
+ position = true;
866
+ }
867
+ if (item.rect.width !== rect.width || item.rect.height !== rect.height) {
868
+ size = true;
869
+ }
870
+ if (position || size) {
871
+ item.handler({
872
+ 'position': position,
873
+ 'size': size
874
+ });
875
+ }
876
+ watchPositionObjects[formId][panelId][index].rect = rect;
877
+ };
878
+ if (watchPositionObjects[formId].default) {
879
+ for (const index in watchPositionObjects[formId].default) {
880
+ handler(watchPositionObjects[formId].default[index], 'default', index);
881
+ }
882
+ }
883
+ for (const id of panelIds) {
884
+ if (watchPositionObjects[formId][id]) {
885
+ for (const index in watchPositionObjects[formId][id]) {
886
+ handler(watchPositionObjects[formId][id][index], id.toString(), index);
887
+ }
888
+ }
889
+ }
890
+ }
734
891
  }
735
892
  }
736
893
  watchTimer = requestAnimationFrame(watchTimerHandler);
package/dist/lib/dom.ts CHANGED
@@ -193,6 +193,153 @@ export function getStyleCount(taskId: number, type: 'theme' | 'control' | 'form'
193
193
  return document.querySelectorAll(`#cg-style-task${taskId} > .cg-style-${type} > style`).length;
194
194
  }
195
195
 
196
+ // ---------------------
197
+ // --- watchPosition ---
198
+ // ---------------------
199
+
200
+ /**
201
+ * --- 监听中的标签对象,对应 formId -> 数组列表 ---
202
+ */
203
+ const watchPositionObjects: Record<
204
+ /** --- formId --- */
205
+ string,
206
+ Record<
207
+ /** --- panelId 或 default --- */
208
+ string,
209
+ Record<
210
+ /** --- index 值 --- */
211
+ string,
212
+ types.IWatchPositionItem
213
+ >
214
+ >
215
+ > = {};
216
+
217
+ /** --- 监视元素的 data-cg-poindex --- */
218
+ let watchPositionIndex: number = 0;
219
+
220
+ /**
221
+ * --- 添加监视 Element 对象位置,元素移除后自动停止监视,已经监视中的不会再次监视,请短时间使用(虽然本方法也可以监听 element 的大小改变,但这是监听位置改变的副产品,如果仅仅监听大小改变请使用效率更高的 watch size) ---
222
+ * @param el 要监视的大小
223
+ * @param cb 回调函数
224
+ * @param immediate 立刻先执行一次回调
225
+ */
226
+ export function watchPosition(
227
+ el: HTMLElement,
228
+ cb: (state: {
229
+ 'position': boolean;
230
+ 'size': boolean;
231
+ }) => void | Promise<void>,
232
+ immediate: boolean = false
233
+ ): boolean {
234
+ if (isWatchPosition(el)) {
235
+ return false;
236
+ }
237
+ if (immediate) {
238
+ try {
239
+ const r = cb({
240
+ 'position': false,
241
+ 'size': false
242
+ });
243
+ if (r instanceof Promise) {
244
+ r.catch(function(e) {
245
+ console.log('dom.watchPosition', e);
246
+ });
247
+ }
248
+ }
249
+ catch (e) {
250
+ console.log('dom.watchPosition', e);
251
+ }
252
+ }
253
+ const formWrap = findParentByData(el, 'form-id');
254
+ if (!formWrap) {
255
+ return false;
256
+ }
257
+ const formId = formWrap.dataset.formId!;
258
+ // --- 获取监视标签的所属 panel ---
259
+ const panelWrap = findParentByData(el, 'panel-id');
260
+ const panelId = panelWrap ? panelWrap.dataset.panelId! : 'default';
261
+ // --- 创建 object ---
262
+ if (!watchPositionObjects[formId]) {
263
+ watchPositionObjects[formId] = {};
264
+ }
265
+ if (!watchPositionObjects[formId][panelId]) {
266
+ watchPositionObjects[formId][panelId] = {};
267
+ }
268
+ watchPositionObjects[formId][panelId][watchPositionIndex] = {
269
+ 'el': el,
270
+ 'rect': el.getBoundingClientRect(),
271
+ 'handler': cb
272
+ };
273
+ el.dataset.cgPoindex = watchPositionIndex.toString();
274
+ ++watchPositionIndex;
275
+ return true;
276
+ }
277
+
278
+ /**
279
+ * --- 移除监视 Element 对象位置 ---
280
+ * @param el 要移除监视
281
+ */
282
+ export function unwatchPosition(el: HTMLElement): void {
283
+ const index = el.dataset.cgPoindex;
284
+ if (index === undefined) {
285
+ return;
286
+ }
287
+ const formWrap = findParentByData(el, 'form-id');
288
+ if (!formWrap) {
289
+ return;
290
+ }
291
+ const formId = formWrap.dataset.formId!;
292
+ // --- 获取监视标签的所属 panel ---
293
+ const panelWrap = findParentByData(el, 'panel-id');
294
+ const panelId = panelWrap ? panelWrap.dataset.panelId! : 'default';
295
+ const item = watchPositionObjects[formId][panelId][index];
296
+ el.removeAttribute('data-cg-poindex');
297
+ delete watchPositionObjects[formId][panelId][index];
298
+ if (Object.keys(watchPositionObjects[formId][panelId]).length) {
299
+ return;
300
+ }
301
+ delete watchPositionObjects[formId][panelId];
302
+ if (Object.keys(watchPositionObjects[formId]).length) {
303
+ return;
304
+ }
305
+ delete watchPositionObjects[formId];
306
+ }
307
+
308
+ /**
309
+ * --- 检测一个标签是否正在被 watchSize ---
310
+ * @param el 要检测的标签
311
+ */
312
+ export function isWatchPosition(el: HTMLElement): boolean {
313
+ return el.dataset.cgPoindex ? true : false;
314
+ }
315
+
316
+ /**
317
+ * --- 清除某个窗体的所有 watch position 监视,虽然窗体结束后相关监视永远不会再被执行,但是会形成冗余,App 模式下无效 ---
318
+ * @param formId 窗体 id
319
+ * @param panelId 若指定则只清除当前窗体的某个 panel 的 watch
320
+ */
321
+ export function clearWatchPosition(formId: number | string, panelId?: number): void {
322
+ if (!watchPositionObjects[formId]) {
323
+ return;
324
+ }
325
+ for (const panel in watchPositionObjects[formId]) {
326
+ if (panelId) {
327
+ if (panel !== panelId.toString()) {
328
+ continue;
329
+ }
330
+ }
331
+ for (const index in watchPositionObjects[formId][panel]) {
332
+ const item = watchPositionObjects[formId][panel][index];
333
+ item.el.removeAttribute('data-cg-poindex');
334
+ }
335
+ delete watchPositionObjects[formId][panel];
336
+ }
337
+ if (Object.keys(watchPositionObjects[formId]).length) {
338
+ return;
339
+ }
340
+ delete watchPositionObjects[formId];
341
+ }
342
+
196
343
  // -----------------
197
344
  // --- watchSize ---
198
345
  // -----------------
@@ -830,8 +977,8 @@ export function getWatchInfo(): types.IGetWatchInfoResult {
830
977
  const panelIds = form.getActivePanel(formId);
831
978
  const handler = (item: {
832
979
  'el': HTMLElement;
833
- 'names': Record<string, any>;
834
- }, type: 'style' | 'property', panelId?: string): void => {
980
+ 'names'?: Record<string, any>;
981
+ }, type: 'style' | 'property' | 'position', panelId?: string): void => {
835
982
  if (panelId) {
836
983
  if (!rtn.panels[panelId]) {
837
984
  rtn.panels[panelId] = {};
@@ -849,15 +996,20 @@ export function getWatchInfo(): types.IGetWatchInfoResult {
849
996
  'property': {
850
997
  'count': 0,
851
998
  'list': []
999
+ },
1000
+ 'position': {
1001
+ 'count': 0
852
1002
  }
853
1003
  };
854
1004
  }
855
1005
  ++ritem[cname][type].count;
856
- for (const name in item.names) {
857
- if (ritem[cname][type].list.includes(name)) {
858
- continue;
1006
+ if (item.names && type !== 'position') {
1007
+ for (const name in item.names) {
1008
+ if (ritem[cname][type].list.includes(name)) {
1009
+ continue;
1010
+ }
1011
+ ritem[cname][type].list.push(name);
859
1012
  }
860
- ritem[cname][type].list.push(name);
861
1013
  }
862
1014
  };
863
1015
  // --- 先执行窗体默认的 ---
@@ -892,6 +1044,22 @@ export function getWatchInfo(): types.IGetWatchInfoResult {
892
1044
  }
893
1045
  }
894
1046
  }
1047
+ // --- 先执行窗体默认的 ---
1048
+ if (watchPositionObjects[formId]) {
1049
+ if (watchPositionObjects[formId].default) {
1050
+ for (const index in watchPositionObjects[formId].default) {
1051
+ handler(watchPositionObjects[formId].default[index], 'position');
1052
+ }
1053
+ }
1054
+ // --- 再执行活跃的 panel 的 ---
1055
+ for (const id of panelIds) {
1056
+ if (watchPositionObjects[formId]?.[id]) {
1057
+ for (const index in watchPositionObjects[formId][id]) {
1058
+ handler(watchPositionObjects[formId][id][index], 'position', id.toString());
1059
+ }
1060
+ }
1061
+ }
1062
+ }
895
1063
  return rtn;
896
1064
  }
897
1065
 
@@ -945,6 +1113,7 @@ const watchTimerHandler = function(): void {
945
1113
  }
946
1114
  }
947
1115
  }
1116
+ // --- property ---
948
1117
  if (watchPropertyObjects[formId]) {
949
1118
  // --- property ---
950
1119
  const handler = (item: IWatchPropertyItem, panelId: string, index: string): void => {
@@ -984,6 +1153,53 @@ const watchTimerHandler = function(): void {
984
1153
  }
985
1154
  }
986
1155
  }
1156
+ // --- position ---
1157
+ if (watchPositionObjects[formId]) {
1158
+ // --- position ---
1159
+ const handler = (item: types.IWatchPositionItem, panelId: string, index: string): void => {
1160
+ if (!document.body.contains(item.el)) {
1161
+ delete watchPositionObjects[formId][panelId][index];
1162
+ if (!Object.keys(watchPositionObjects[formId][panelId]).length) {
1163
+ delete watchPositionObjects[formId][panelId];
1164
+ }
1165
+ if (!Object.keys(watchPositionObjects[formId]).length) {
1166
+ delete watchPositionObjects[formId];
1167
+ }
1168
+ return;
1169
+ }
1170
+ // --- 执行 cb ---
1171
+ const rect = item.el.getBoundingClientRect();
1172
+ let position = false;
1173
+ let size = false;
1174
+ if (item.rect.left !== rect.left || item.rect.top !== rect.top) {
1175
+ position = true;
1176
+ }
1177
+ if (item.rect.width !== rect.width || item.rect.height !== rect.height) {
1178
+ size = true;
1179
+ }
1180
+ if (position || size) {
1181
+ item.handler({
1182
+ 'position': position,
1183
+ 'size': size
1184
+ });
1185
+ }
1186
+ watchPositionObjects[formId][panelId][index].rect = rect;
1187
+ };
1188
+ // --- 先执行窗体默认的 ---
1189
+ if (watchPositionObjects[formId].default) {
1190
+ for (const index in watchPositionObjects[formId].default) {
1191
+ handler(watchPositionObjects[formId].default[index], 'default', index);
1192
+ }
1193
+ }
1194
+ // --- 再执行活跃的 panel 的 ---
1195
+ for (const id of panelIds) {
1196
+ if (watchPositionObjects[formId][id]) {
1197
+ for (const index in watchPositionObjects[formId][id]) {
1198
+ handler(watchPositionObjects[formId][id][index], id.toString(), index);
1199
+ }
1200
+ }
1201
+ }
1202
+ }
987
1203
  }
988
1204
  }
989
1205
  watchTimer = requestAnimationFrame(watchTimerHandler);