clickgo 3.0.7-dev8 → 3.1.1-dev10

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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/app/demo/app.js +93 -0
  3. package/dist/app/demo/form/control/dialog/dialog.js +10 -6
  4. package/dist/app/demo/form/control/form/form.js +21 -20
  5. package/dist/app/demo/form/control/form/form.xml +3 -3
  6. package/dist/app/demo/form/main.js +34 -10
  7. package/dist/app/demo/form/main.xml +4 -4
  8. package/dist/app/demo/form/method/form/form.js +103 -101
  9. package/dist/app/demo/form/method/form/form.xml +9 -10
  10. package/dist/app/task/app.js +46 -0
  11. package/dist/app/task/form/bar/bar.js +84 -88
  12. package/dist/app/task/form/bar/bar.xml +4 -5
  13. package/dist/clickgo.js +1 -10
  14. package/dist/clickgo.ts +0 -8
  15. package/dist/control/common.cgc +0 -0
  16. package/dist/control/form.cgc +0 -0
  17. package/dist/control/monaco.cgc +0 -0
  18. package/dist/control/property.cgc +0 -0
  19. package/dist/control/task.cgc +0 -0
  20. package/dist/index.js +105 -56
  21. package/dist/index.ts +164 -59
  22. package/dist/lib/control.js +363 -240
  23. package/dist/lib/control.ts +497 -284
  24. package/dist/lib/core.js +313 -228
  25. package/dist/lib/core.ts +400 -255
  26. package/dist/lib/dom.ts +1 -3
  27. package/dist/lib/form.js +447 -951
  28. package/dist/lib/form.ts +686 -1097
  29. package/dist/lib/fs.js +42 -39
  30. package/dist/lib/fs.ts +45 -41
  31. package/dist/lib/native.ts +3 -0
  32. package/dist/lib/task.js +708 -182
  33. package/dist/lib/task.ts +778 -200
  34. package/dist/lib/theme.ts +2 -2
  35. package/dist/lib/tool.js +58 -48
  36. package/dist/lib/tool.ts +80 -64
  37. package/dist/theme/familiar.cgt +0 -0
  38. package/package.json +5 -7
  39. package/types/index.d.ts +284 -335
  40. package/dist/app/demo/config.json +0 -106
  41. package/dist/app/task/config.json +0 -32
package/dist/lib/task.js CHANGED
@@ -9,18 +9,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.refreshSystemPosition = exports.clearSystem = exports.setSystem = exports.systemTaskInfo = exports.sleep = exports.removeTimer = exports.createTimer = exports.clearLocaleLang = exports.setLocaleLang = exports.setLocale = exports.clearLocale = exports.loadLocale = exports.loadLocaleData = exports.end = exports.run = exports.getList = exports.get = exports.offFrame = exports.onFrame = exports.lastId = exports.list = void 0;
12
+ exports.refreshSystemPosition = exports.clearSystem = exports.setSystem = exports.systemTaskInfo = exports.sleep = exports.removeTimer = exports.createTimer = exports.clearLocaleLang = exports.setLocaleLang = exports.setLocale = exports.clearLocale = exports.loadLocale = exports.loadLocaleData = exports.end = exports.run = exports.getList = exports.get = exports.offFrame = exports.onFrame = exports.isMain = exports.setMain = exports.lastId = exports.list = void 0;
13
13
  const clickgo = require("../clickgo");
14
14
  const core = require("./core");
15
- const control = require("./control");
16
15
  const dom = require("./dom");
17
16
  const tool = require("./tool");
18
17
  const form = require("./form");
19
- const theme = require("./theme");
18
+ const control = require("./control");
20
19
  const fs = require("./fs");
21
20
  const native = require("./native");
22
21
  exports.list = {};
23
22
  exports.lastId = 0;
23
+ let mainTaskId = 0;
24
+ function setMain(taskId) {
25
+ if (mainTaskId > 0) {
26
+ return false;
27
+ }
28
+ mainTaskId = taskId;
29
+ return true;
30
+ }
31
+ exports.setMain = setMain;
32
+ function isMain(taskId) {
33
+ return taskId === mainTaskId;
34
+ }
35
+ exports.isMain = isMain;
24
36
  const localeData = {
25
37
  'en': {
26
38
  'loading': 'Loading...',
@@ -38,33 +50,37 @@ const localeData = {
38
50
  let frameTimer = 0;
39
51
  const frameMaps = {};
40
52
  function onFrame(fun, opt = {}) {
41
- var _a, _b;
53
+ var _a;
42
54
  const taskId = opt.taskId;
43
55
  const formId = opt.formId;
44
- if (!taskId || !formId) {
56
+ if (!taskId) {
57
+ return 0;
58
+ }
59
+ const task = exports.list[taskId];
60
+ if (!task) {
61
+ return 0;
62
+ }
63
+ if (formId && !task.forms[formId]) {
45
64
  return 0;
46
65
  }
47
66
  const ft = ++frameTimer;
48
- const scope = (_a = opt.scope) !== null && _a !== void 0 ? _a : 'form';
49
- const count = (_b = opt.count) !== null && _b !== void 0 ? _b : 0;
67
+ const count = (_a = opt.count) !== null && _a !== void 0 ? _a : 0;
50
68
  let c = 0;
51
69
  let timer;
52
70
  const timerHandler = () => __awaiter(this, void 0, void 0, function* () {
53
71
  ++c;
54
- if (exports.list[taskId].forms[formId] === undefined) {
55
- if (scope === 'form') {
56
- delete exports.list[taskId].timers['1x' + ft.toString()];
57
- delete frameMaps[ft];
58
- return;
59
- }
72
+ if (formId && task.forms[formId] === undefined) {
73
+ delete task.timers['1x' + ft.toString()];
74
+ delete frameMaps[ft];
75
+ return;
60
76
  }
61
77
  yield fun();
62
- if (exports.list[taskId].timers['1x' + ft.toString()] == undefined) {
78
+ if (task.timers['1x' + ft.toString()] == undefined) {
63
79
  return;
64
80
  }
65
81
  if (count > 1) {
66
82
  if (c === count) {
67
- delete exports.list[taskId].timers['1x' + ft.toString()];
83
+ delete task.timers['1x' + ft.toString()];
68
84
  delete frameMaps[ft];
69
85
  return;
70
86
  }
@@ -78,7 +94,7 @@ function onFrame(fun, opt = {}) {
78
94
  }
79
95
  }
80
96
  else if (count === 1) {
81
- delete exports.list[taskId].timers['1x' + ft.toString()];
97
+ delete task.timers['1x' + ft.toString()];
82
98
  delete frameMaps[ft];
83
99
  }
84
100
  else {
@@ -96,7 +112,7 @@ function onFrame(fun, opt = {}) {
96
112
  });
97
113
  });
98
114
  frameMaps[ft] = timer;
99
- exports.list[taskId].timers['1x' + ft.toString()] = formId;
115
+ task.timers['1x' + ft.toString()] = formId !== null && formId !== void 0 ? formId : 0;
100
116
  return ft;
101
117
  }
102
118
  exports.onFrame = onFrame;
@@ -105,6 +121,9 @@ function offFrame(ft, opt = {}) {
105
121
  if (!taskId) {
106
122
  return;
107
123
  }
124
+ if (!exports.list[taskId]) {
125
+ return;
126
+ }
108
127
  const formId = exports.list[taskId].timers['1x' + ft.toString()];
109
128
  if (formId === undefined) {
110
129
  return;
@@ -119,12 +138,13 @@ function get(tid) {
119
138
  return null;
120
139
  }
121
140
  return {
122
- 'name': exports.list[tid].app.config.name,
141
+ 'name': exports.list[tid].config.name,
123
142
  'locale': exports.list[tid].locale.lang,
124
143
  'customTheme': exports.list[tid].customTheme,
125
144
  'formCount': Object.keys(exports.list[tid].forms).length,
126
- 'icon': exports.list[tid].icon,
127
- 'path': exports.list[tid].path
145
+ 'icon': exports.list[tid].app.icon,
146
+ 'path': exports.list[tid].path,
147
+ 'current': exports.list[tid].current
128
148
  };
129
149
  }
130
150
  exports.get = get;
@@ -133,19 +153,20 @@ function getList() {
133
153
  for (const tid in exports.list) {
134
154
  const item = exports.list[tid];
135
155
  rtn[tid] = {
136
- 'name': item.app.config.name,
156
+ 'name': item.config.name,
137
157
  'locale': item.locale.lang,
138
158
  'customTheme': item.customTheme,
139
159
  'formCount': Object.keys(item.forms).length,
140
- 'icon': item.icon,
141
- 'path': item.path
160
+ 'icon': item.app.icon,
161
+ 'path': item.path,
162
+ 'current': item.current
142
163
  };
143
164
  }
144
165
  return rtn;
145
166
  }
146
167
  exports.getList = getList;
147
168
  function run(url, opt = {}) {
148
- var _a, _b, _c, _d;
169
+ var _a, _b, _c;
149
170
  return __awaiter(this, void 0, void 0, function* () {
150
171
  let ntask = null;
151
172
  if (opt.taskId) {
@@ -170,22 +191,601 @@ function run(url, opt = {}) {
170
191
  }) : undefined;
171
192
  const app = yield core.fetchApp(url, {
172
193
  'notifyId': notifyId,
173
- 'current': ntask ? ntask.path : undefined,
194
+ 'current': ntask ? ntask.current : undefined,
174
195
  'progress': opt.progress
175
196
  });
176
- if (notifyId) {
197
+ if (!app) {
198
+ if (notifyId) {
199
+ setTimeout(function () {
200
+ form.hideNotify(notifyId);
201
+ }, 2000);
202
+ }
203
+ return -1;
204
+ }
205
+ if (notifyId && !app.net) {
177
206
  setTimeout(function () {
178
207
  form.hideNotify(notifyId);
179
208
  }, 2000);
180
209
  }
181
- if (!app) {
182
- return -1;
210
+ const taskId = ++exports.lastId;
211
+ const unblock = (_c = opt.unblock) !== null && _c !== void 0 ? _c : [];
212
+ const invoke = {};
213
+ if (!unblock.includes('window')) {
214
+ invoke.window = undefined;
183
215
  }
184
- const files = {};
185
- for (const fpath in app.files) {
186
- files[fpath] = app.files[fpath];
216
+ const ks = Object.getOwnPropertyNames(window);
217
+ for (const k of ks) {
218
+ if (k.includes('Event')) {
219
+ continue;
220
+ }
221
+ if (k.includes('-')) {
222
+ continue;
223
+ }
224
+ if (/^[0-9]+$/.test(k)) {
225
+ continue;
226
+ }
227
+ if ([
228
+ 'require',
229
+ '__awaiter', 'eval', 'Math', 'Array', 'Blob', 'Infinity', 'parseInt', 'parseFloat', 'Promise', 'Date', 'JSON', 'fetch'
230
+ ].includes(k)) {
231
+ continue;
232
+ }
233
+ if (unblock.includes(k)) {
234
+ continue;
235
+ }
236
+ invoke[k] = undefined;
187
237
  }
188
- const taskId = ++exports.lastId;
238
+ invoke.console = {
239
+ log: function (message, ...optionalParams) {
240
+ console.log(message, ...optionalParams);
241
+ }
242
+ };
243
+ invoke.loader = {
244
+ require: function (paths, files, opt) {
245
+ return loader.require(paths, files, opt);
246
+ }
247
+ };
248
+ if (!unblock.includes('Object')) {
249
+ invoke.Object = {
250
+ defineProperty: function () {
251
+ return;
252
+ },
253
+ keys: function (o) {
254
+ return Object.keys(o);
255
+ },
256
+ assign: function (o, o2) {
257
+ if (o.controlName !== undefined) {
258
+ return o;
259
+ }
260
+ return Object.assign(o, o2);
261
+ }
262
+ };
263
+ }
264
+ invoke.navigator = {};
265
+ if (navigator.clipboard) {
266
+ invoke.navigator.clipboard = navigator.clipboard;
267
+ }
268
+ invoke.invokeClickgo = {
269
+ getVersion: function () {
270
+ return clickgo.getVersion();
271
+ },
272
+ getNative() {
273
+ return clickgo.getNative();
274
+ },
275
+ getPlatform() {
276
+ return clickgo.getPlatform();
277
+ },
278
+ 'control': {
279
+ 'AbstractControl': class extends control.AbstractControl {
280
+ get taskId() {
281
+ return taskId;
282
+ }
283
+ },
284
+ read: function (blob) {
285
+ return control.read(blob);
286
+ }
287
+ },
288
+ 'core': {
289
+ 'config': clickgo.core.config,
290
+ 'AbstractApp': class extends core.AbstractApp {
291
+ main() {
292
+ return __awaiter(this, void 0, void 0, function* () {
293
+ return;
294
+ });
295
+ }
296
+ get taskId() {
297
+ return taskId;
298
+ }
299
+ },
300
+ getCdn: function () {
301
+ return core.getCdn();
302
+ },
303
+ initModules: function (names) {
304
+ return clickgo.core.initModules(names);
305
+ },
306
+ getModule: function (name) {
307
+ return clickgo.core.getModule(name);
308
+ },
309
+ readApp: function (blob) {
310
+ return clickgo.core.readApp(blob);
311
+ },
312
+ getAvailArea: function () {
313
+ return clickgo.core.getAvailArea();
314
+ }
315
+ },
316
+ 'dom': {
317
+ setGlobalCursor: function (type) {
318
+ clickgo.dom.setGlobalCursor(type);
319
+ },
320
+ hasTouchButMouse: function (e) {
321
+ return clickgo.dom.hasTouchButMouse(e);
322
+ },
323
+ getStyleCount: function (taskId, type) {
324
+ return clickgo.dom.getStyleCount(taskId, type);
325
+ },
326
+ getSize: function (el) {
327
+ return clickgo.dom.getSize(el);
328
+ },
329
+ watchSize: function (el, cb, immediate = false) {
330
+ return clickgo.dom.watchSize(el, cb, immediate, taskId);
331
+ },
332
+ unwatchSize: function (el) {
333
+ clickgo.dom.unwatchSize(el, taskId);
334
+ },
335
+ clearWatchSize() {
336
+ clickgo.dom.clearWatchSize(taskId);
337
+ },
338
+ watch: function (el, cb, mode = 'default', immediate = false) {
339
+ clickgo.dom.watch(el, cb, mode, immediate, taskId);
340
+ },
341
+ unwatch: function (el) {
342
+ clickgo.dom.unwatch(el, taskId);
343
+ },
344
+ clearWatch: function () {
345
+ clickgo.dom.clearWatch(taskId);
346
+ },
347
+ watchStyle: function (el, name, cb, immediate = false) {
348
+ clickgo.dom.watchStyle(el, name, cb, immediate);
349
+ },
350
+ isWatchStyle: function (el) {
351
+ return clickgo.dom.isWatchStyle(el);
352
+ },
353
+ bindDown: function (oe, opt) {
354
+ clickgo.dom.bindDown(oe, opt);
355
+ },
356
+ bindGesture: function (e, opt) {
357
+ clickgo.dom.bindGesture(e, opt);
358
+ },
359
+ bindLong: function (e, long) {
360
+ clickgo.dom.bindLong(e, long);
361
+ },
362
+ bindDrag: function (e, opt) {
363
+ clickgo.dom.bindDrag(e, opt);
364
+ },
365
+ 'is': clickgo.dom.is,
366
+ bindMove: function (e, opt) {
367
+ return clickgo.dom.bindMove(e, opt);
368
+ },
369
+ bindResize: function (e, opt) {
370
+ clickgo.dom.bindResize(e, opt);
371
+ },
372
+ findParentByData: function (el, name) {
373
+ return clickgo.dom.findParentByData(el, name);
374
+ },
375
+ findParentByClass: function (el, name) {
376
+ return clickgo.dom.findParentByClass(el, name);
377
+ },
378
+ siblings: function (el) {
379
+ return clickgo.dom.siblings(el);
380
+ },
381
+ siblingsData: function (el, name) {
382
+ return clickgo.dom.siblingsData(el, name);
383
+ },
384
+ fullscreen: function () {
385
+ return clickgo.dom.fullscreen();
386
+ }
387
+ },
388
+ 'form': {
389
+ 'AbstractForm': class extends form.AbstractForm {
390
+ get taskId() {
391
+ return taskId;
392
+ }
393
+ },
394
+ min: function (fid) {
395
+ return clickgo.form.min(fid);
396
+ },
397
+ max: function max(fid) {
398
+ return clickgo.form.max(fid);
399
+ },
400
+ close: function (fid) {
401
+ return clickgo.form.close(fid);
402
+ },
403
+ bindResize: function (e, border) {
404
+ clickgo.form.bindResize(e, border);
405
+ },
406
+ bindDrag: function (e) {
407
+ clickgo.form.bindDrag(e);
408
+ },
409
+ getTaskId: function (fid) {
410
+ return clickgo.form.getTaskId(fid);
411
+ },
412
+ get: function (fid) {
413
+ return clickgo.form.get(fid);
414
+ },
415
+ getList: function (tid) {
416
+ return clickgo.form.getList(tid);
417
+ },
418
+ changeFocus: function (fid = 0) {
419
+ clickgo.form.changeFocus(fid);
420
+ },
421
+ getMaxZIndexID: function (out) {
422
+ return clickgo.form.getMaxZIndexID(out);
423
+ },
424
+ getRectByBorder: function (border) {
425
+ return clickgo.form.getRectByBorder(border);
426
+ },
427
+ showCircular: function (x, y) {
428
+ clickgo.form.showCircular(x, y);
429
+ },
430
+ moveRectangle: function (border) {
431
+ clickgo.form.moveRectangle(border);
432
+ },
433
+ showRectangle: function (x, y, border) {
434
+ clickgo.form.showRectangle(x, y, border);
435
+ },
436
+ hideRectangle: function () {
437
+ clickgo.form.hideRectangle();
438
+ },
439
+ showDrag: function () {
440
+ clickgo.form.showDrag();
441
+ },
442
+ moveDrag: function (opt) {
443
+ clickgo.form.moveDrag(opt);
444
+ },
445
+ hideDrag: function () {
446
+ clickgo.form.hideDrag();
447
+ },
448
+ notify: function (opt) {
449
+ return clickgo.form.notify(opt);
450
+ },
451
+ notifyProgress: function (notifyId, per) {
452
+ clickgo.form.notifyProgress(notifyId, per);
453
+ },
454
+ hideNotify: function (notifyId) {
455
+ clickgo.form.hideNotify(notifyId);
456
+ },
457
+ showPop: function (el, pop, direction, opt = {}) {
458
+ clickgo.form.showPop(el, pop, direction, opt);
459
+ },
460
+ hidePop: function (pop) {
461
+ clickgo.form.hidePop(pop);
462
+ },
463
+ dialog: function (opt) {
464
+ if (typeof opt === 'string') {
465
+ opt = {
466
+ 'content': opt
467
+ };
468
+ }
469
+ opt.taskId = taskId;
470
+ return clickgo.form.dialog(opt);
471
+ },
472
+ confirm: function (opt) {
473
+ if (typeof opt === 'string') {
474
+ opt = {
475
+ 'content': opt
476
+ };
477
+ }
478
+ opt.taskId = taskId;
479
+ return clickgo.form.confirm(opt);
480
+ },
481
+ flash: function (fid) {
482
+ clickgo.form.flash(fid, taskId);
483
+ },
484
+ showLauncher: function () {
485
+ clickgo.form.showLauncher();
486
+ },
487
+ hideLauncher: function () {
488
+ clickgo.form.hideLauncher();
489
+ }
490
+ },
491
+ 'fs': {
492
+ getContent: function (path, options = {}) {
493
+ if (!options.files) {
494
+ options.files = exports.list[taskId].app.files;
495
+ }
496
+ if (!options.current) {
497
+ options.current = exports.list[taskId].current;
498
+ }
499
+ return clickgo.fs.getContent(path, options);
500
+ },
501
+ putContent: function (path, data, options = {}) {
502
+ if (!options.current) {
503
+ options.current = exports.list[taskId].current;
504
+ }
505
+ return clickgo.fs.putContent(path, data, options);
506
+ },
507
+ readLink: function (path, options = {}) {
508
+ if (!options.current) {
509
+ options.current = exports.list[taskId].current;
510
+ }
511
+ return clickgo.fs.readLink(path, options);
512
+ },
513
+ symlink: function (fPath, linkPath, options = {}) {
514
+ if (!options.current) {
515
+ options.current = exports.list[taskId].current;
516
+ }
517
+ return clickgo.fs.symlink(fPath, linkPath, options);
518
+ },
519
+ unlink: function (path, options = {}) {
520
+ if (!options.current) {
521
+ options.current = exports.list[taskId].current;
522
+ }
523
+ return clickgo.fs.unlink(path, options);
524
+ },
525
+ stats: function (path, options = {}) {
526
+ if (!options.files) {
527
+ options.files = exports.list[taskId].app.files;
528
+ }
529
+ if (!options.current) {
530
+ options.current = exports.list[taskId].current;
531
+ }
532
+ return clickgo.fs.stats(path, options);
533
+ },
534
+ isDir: function (path, options = {}) {
535
+ if (!options.files) {
536
+ options.files = exports.list[taskId].app.files;
537
+ }
538
+ if (!options.current) {
539
+ options.current = exports.list[taskId].current;
540
+ }
541
+ return clickgo.fs.isDir(path, options);
542
+ },
543
+ isFile: function (path, options = {}) {
544
+ if (!options.files) {
545
+ options.files = exports.list[taskId].app.files;
546
+ }
547
+ if (!options.current) {
548
+ options.current = exports.list[taskId].current;
549
+ }
550
+ return clickgo.fs.isFile(path, options);
551
+ },
552
+ mkdir: function (path, mode, options = {}) {
553
+ if (!options.current) {
554
+ options.current = exports.list[taskId].current;
555
+ }
556
+ return clickgo.fs.mkdir(path, mode, options);
557
+ },
558
+ rmdir: function (path, options = {}) {
559
+ if (!options.current) {
560
+ options.current = exports.list[taskId].current;
561
+ }
562
+ return clickgo.fs.rmdir(path, options);
563
+ },
564
+ rmdirDeep: function (path, options = {}) {
565
+ if (!options.current) {
566
+ options.current = exports.list[taskId].current;
567
+ }
568
+ return clickgo.fs.rmdirDeep(path, options);
569
+ },
570
+ chmod: function (path, mod, options = {}) {
571
+ if (!options.current) {
572
+ options.current = exports.list[taskId].current;
573
+ }
574
+ return clickgo.fs.chmod(path, mod, options);
575
+ },
576
+ rename(oldPath, newPath, options = {}) {
577
+ if (!options.current) {
578
+ options.current = exports.list[taskId].current;
579
+ }
580
+ return clickgo.fs.rename(oldPath, newPath, options);
581
+ },
582
+ readDir(path, options = {}) {
583
+ if (!options.files) {
584
+ options.files = exports.list[taskId].app.files;
585
+ }
586
+ if (!options.current) {
587
+ options.current = exports.list[taskId].current;
588
+ }
589
+ return clickgo.fs.readDir(path, options);
590
+ },
591
+ copyFolder(from, to, options = {}) {
592
+ if (!options.current) {
593
+ options.current = exports.list[taskId].current;
594
+ }
595
+ return clickgo.fs.copyFolder(from, to, options);
596
+ },
597
+ copyFile(src, dest, options = {}) {
598
+ if (!options.current) {
599
+ options.current = exports.list[taskId].current;
600
+ }
601
+ return clickgo.fs.copyFile(src, dest, options);
602
+ }
603
+ },
604
+ 'native': {
605
+ invoke: function (name, ...param) {
606
+ return clickgo.native.invoke(name, ...param);
607
+ },
608
+ max: function () {
609
+ clickgo.native.max();
610
+ },
611
+ min: function () {
612
+ clickgo.native.min();
613
+ },
614
+ restore: function () {
615
+ clickgo.native.restore();
616
+ },
617
+ size: function (width, height) {
618
+ clickgo.native.size(width, height);
619
+ }
620
+ },
621
+ 'task': {
622
+ isMain(taskId) {
623
+ return isMain(taskId);
624
+ },
625
+ onFrame: function (fun, opt = {}) {
626
+ opt.taskId = taskId;
627
+ return clickgo.task.onFrame(fun, opt);
628
+ },
629
+ offFrame: function (ft, opt = {}) {
630
+ opt.taskId = taskId;
631
+ clickgo.task.offFrame(ft, opt);
632
+ },
633
+ get: function (tid) {
634
+ return clickgo.task.get(tid);
635
+ },
636
+ getList: function () {
637
+ return clickgo.task.getList();
638
+ },
639
+ run: function (url, opt = {}) {
640
+ opt.taskId = taskId;
641
+ opt.main = false;
642
+ return clickgo.task.run(url, opt);
643
+ },
644
+ end: function (tid) {
645
+ return clickgo.task.end(tid !== null && tid !== void 0 ? tid : taskId);
646
+ },
647
+ loadLocaleData: function (lang, data, pre = '') {
648
+ clickgo.task.loadLocaleData(lang, data, pre, taskId);
649
+ },
650
+ loadLocale: function (lang, path) {
651
+ return clickgo.task.loadLocale(lang, path, taskId);
652
+ },
653
+ clearLocale: function () {
654
+ clickgo.task.clearLocale(taskId);
655
+ },
656
+ setLocale: function (lang, path) {
657
+ return clickgo.task.setLocale(lang, path, taskId);
658
+ },
659
+ setLocaleLang: function (lang) {
660
+ clickgo.task.setLocaleLang(lang, taskId);
661
+ },
662
+ clearLocaleLang: function () {
663
+ clickgo.task.clearLocaleLang(taskId);
664
+ },
665
+ createTimer: function (fun, delay, opt = {}) {
666
+ opt.taskId = taskId;
667
+ return clickgo.task.createTimer(fun, delay, opt);
668
+ },
669
+ removeTimer: function (timer) {
670
+ clickgo.task.removeTimer(timer, taskId);
671
+ },
672
+ sleep: function (fun, delay) {
673
+ return clickgo.task.sleep(fun, delay, taskId);
674
+ },
675
+ systemTaskInfo: clickgo.task.systemTaskInfo,
676
+ setSystem: function (fid) {
677
+ return clickgo.task.setSystem(fid, taskId);
678
+ },
679
+ clearSystem: function () {
680
+ return clickgo.task.clearSystem(taskId);
681
+ }
682
+ },
683
+ 'theme': {
684
+ read: function (blob) {
685
+ return clickgo.theme.read(blob);
686
+ },
687
+ load: function (theme) {
688
+ return __awaiter(this, void 0, void 0, function* () {
689
+ if (!theme) {
690
+ return false;
691
+ }
692
+ return clickgo.theme.load(theme, taskId);
693
+ });
694
+ },
695
+ remove: function (name) {
696
+ return clickgo.theme.remove(name, taskId);
697
+ },
698
+ clear: function () {
699
+ return clickgo.theme.clear(taskId);
700
+ },
701
+ setGlobal: function (theme) {
702
+ return clickgo.theme.setGlobal(theme);
703
+ },
704
+ clearGlobal: function () {
705
+ clickgo.theme.clearGlobal();
706
+ }
707
+ },
708
+ 'tool': {
709
+ blob2ArrayBuffer: function (blob) {
710
+ return clickgo.tool.blob2ArrayBuffer(blob);
711
+ },
712
+ clone: function (obj) {
713
+ return clickgo.tool.clone(obj);
714
+ },
715
+ sleep: function (ms = 0) {
716
+ return clickgo.tool.sleep(ms);
717
+ },
718
+ purify: function (text) {
719
+ return clickgo.tool.purify(text);
720
+ },
721
+ rand: function (min, max) {
722
+ return clickgo.tool.rand(min, max);
723
+ },
724
+ 'RANDOM_N': clickgo.tool.RANDOM_N,
725
+ 'RANDOM_U': clickgo.tool.RANDOM_U,
726
+ 'RANDOM_L': clickgo.tool.RANDOM_L,
727
+ 'RANDOM_UN': clickgo.tool.RANDOM_UN,
728
+ 'RANDOM_LN': clickgo.tool.RANDOM_LN,
729
+ 'RANDOM_LU': clickgo.tool.RANDOM_LU,
730
+ 'RANDOM_LUN': clickgo.tool.RANDOM_LUN,
731
+ 'RANDOM_V': clickgo.tool.RANDOM_V,
732
+ 'RANDOM_LUNS': clickgo.tool.RANDOM_LUNS,
733
+ random: function (length = 8, source = clickgo.tool.RANDOM_LN, block = '') {
734
+ return clickgo.tool.random(length, source, block);
735
+ },
736
+ getBoolean: function (param) {
737
+ return clickgo.tool.getBoolean(param);
738
+ },
739
+ getNumber: function (param) {
740
+ return clickgo.tool.getNumber(param);
741
+ },
742
+ escapeHTML: function (html) {
743
+ return clickgo.tool.escapeHTML(html);
744
+ },
745
+ request: function (url, opt) {
746
+ return clickgo.tool.request(url, opt);
747
+ },
748
+ parseUrl: function (url) {
749
+ return clickgo.tool.parseUrl(url);
750
+ },
751
+ urlResolve: function (from, to) {
752
+ return clickgo.tool.urlResolve(from, to);
753
+ },
754
+ blob2Text: function (blob) {
755
+ return clickgo.tool.blob2Text(blob);
756
+ },
757
+ blob2DataUrl: function (blob) {
758
+ return clickgo.tool.blob2DataUrl(blob);
759
+ },
760
+ execCommand: function (ac) {
761
+ clickgo.tool.execCommand(ac);
762
+ }
763
+ },
764
+ 'zip': {
765
+ get: function (data) {
766
+ return clickgo.zip.get(data);
767
+ }
768
+ }
769
+ };
770
+ const preprocess = function (code, path) {
771
+ const exec = /eval\W/.exec(code);
772
+ if (exec) {
773
+ form.notify({
774
+ 'title': 'Error',
775
+ 'content': `The "eval" is prohibited.\nFile: "${path}".`,
776
+ 'type': 'danger'
777
+ });
778
+ return '';
779
+ }
780
+ code = code.replace(/extends[\s\S]+?\.\s*(AbstractApp|AbstractForm)\s*{/, (t) => {
781
+ return t + 'get filename() {return __filename;}';
782
+ });
783
+ return code;
784
+ };
785
+ app.files['/invoke/clickgo.js'] = `module.exports = invokeClickgo;`;
786
+ const path = url;
787
+ const lio = path.endsWith('.cga') ? path.lastIndexOf('/') : path.slice(0, -1).lastIndexOf('/');
788
+ const current = path.slice(0, lio);
189
789
  exports.list[taskId] = {
190
790
  'id': taskId,
191
791
  'app': app,
@@ -194,128 +794,50 @@ function run(url, opt = {}) {
194
794
  'lang': '',
195
795
  'data': {}
196
796
  }),
197
- 'icon': (_c = app.icon) !== null && _c !== void 0 ? _c : icon,
198
- 'path': url,
199
- 'files': files,
200
- 'main': (_d = opt.main) !== null && _d !== void 0 ? _d : false,
201
- 'permissions': {},
797
+ 'path': path,
798
+ 'current': current,
799
+ 'runtime': clickgo.vue.reactive({
800
+ 'permissions': {},
801
+ 'dialogFormIds': []
802
+ }),
202
803
  'forms': {},
203
- 'objectURLs': [],
204
- 'controls': {
205
- 'loaded': {},
206
- 'layout': {},
207
- 'prep': {}
208
- },
209
- 'timers': {}
804
+ 'controls': {},
805
+ 'timers': {},
806
+ 'invoke': invoke
210
807
  };
211
- const task = exports.list[taskId];
212
- for (let path of app.config.controls) {
213
- path += '.cgc';
214
- path = tool.urlResolve('/', path);
215
- const file = yield fs.getContent(path, {
216
- 'files': task.files
217
- });
218
- if (file && typeof file !== 'string') {
219
- const c = yield control.read(file);
220
- if (c) {
221
- task.controls.loaded[path] = c;
222
- }
223
- else {
224
- form.notify({
225
- 'title': 'Control failed to load',
226
- 'content': path
227
- });
228
- }
229
- }
230
- }
231
- if (app.config.themes) {
232
- for (let path of app.config.themes) {
233
- path += '.cgt';
234
- path = tool.urlResolve('/', path);
235
- const file = yield fs.getContent(path, {
236
- 'files': task.files
237
- });
238
- if (file && typeof file !== 'string') {
239
- const th = yield theme.read(file);
240
- if (th) {
241
- yield theme.load(th, taskId);
242
- }
808
+ let expo = [];
809
+ try {
810
+ expo = loader.require('/app.js', app.files, {
811
+ 'dir': '/',
812
+ 'invoke': invoke,
813
+ 'preprocess': preprocess,
814
+ 'map': {
815
+ 'clickgo': '/invoke/clickgo'
243
816
  }
244
- }
817
+ })[0];
245
818
  }
246
- if (app.config.locales) {
247
- for (let path in app.config.locales) {
248
- const locale = app.config.locales[path];
249
- if (!path.endsWith('.json')) {
250
- path += '.json';
251
- }
252
- const lcontent = yield fs.getContent(path, {
253
- 'encoding': 'utf8',
254
- 'files': task.files,
255
- 'current': task.path
256
- });
257
- if (!lcontent) {
258
- continue;
259
- }
260
- try {
261
- const data = JSON.parse(lcontent);
262
- loadLocaleData(locale, data, '', task.id);
263
- }
264
- catch (_e) {
265
- }
266
- }
819
+ catch (e) {
820
+ delete exports.list[taskId];
821
+ core.trigger('error', taskId, 0, e, e.message + '(-1)');
822
+ return -2;
267
823
  }
268
- core.trigger('taskStarted', task.id);
269
- dom.createToStyleList(task.id);
270
- const f = yield form.create({
271
- 'taskId': task.id,
272
- 'file': app.config.main
273
- });
274
- if (typeof f === 'number') {
275
- delete exports.list[task.id];
276
- dom.removeFromStyleList(task.id);
277
- core.trigger('taskEnded', task.id);
278
- return f - 100;
279
- }
280
- if (app.config.style && app.files[app.config.style + '.css']) {
281
- const style = app.files[app.config.style + '.css'];
282
- const r = tool.stylePrepend(style, 'cg-task' + task.id.toString() + '_');
283
- dom.pushStyle(task.id, yield tool.styleUrl2DataUrl(app.config.style, r.style, app.files));
284
- }
285
- if (app.config.themes && app.config.themes.length > 0) {
286
- task.customTheme = true;
287
- for (const path of app.config.themes) {
288
- const blob = yield fs.getContent(path, {
289
- 'files': task.files,
290
- 'current': task.path
291
- });
292
- if (!(blob instanceof Blob)) {
293
- continue;
294
- }
295
- const th = yield theme.read(blob);
296
- if (!th) {
297
- continue;
298
- }
299
- yield theme.load(th, task.id);
300
- }
824
+ if (!(expo === null || expo === void 0 ? void 0 : expo.default)) {
825
+ delete exports.list[taskId];
826
+ return -3;
301
827
  }
302
- else {
303
- if (theme.global) {
304
- yield theme.load(undefined, task.id);
305
- }
828
+ dom.createToStyleList(taskId);
829
+ const appCls = new expo.default();
830
+ yield appCls.main();
831
+ if (!exports.list[taskId].class) {
832
+ delete exports.list[taskId];
833
+ dom.removeFromStyleList(taskId);
834
+ return -4;
306
835
  }
307
- if (task.id === 1) {
836
+ core.trigger('taskStarted', taskId);
837
+ if (taskId === 1) {
308
838
  native.invoke('cg-init', native.getToken());
309
839
  }
310
- if (clickgo.getNative() && opt.sync) {
311
- f.vroot.$refs.form.isNativeSync = true;
312
- native.invoke('cg-set-size', native.getToken(), f.vroot.$refs.form.widthData, f.vroot.$refs.form.heightData);
313
- window.addEventListener('resize', function () {
314
- f.vroot.$refs.form.setPropData('width', window.innerWidth);
315
- f.vroot.$refs.form.setPropData('height', window.innerHeight);
316
- });
317
- }
318
- return task.id;
840
+ return taskId;
319
841
  });
320
842
  }
321
843
  exports.run = run;
@@ -324,7 +846,7 @@ function end(taskId) {
324
846
  if (!task) {
325
847
  return true;
326
848
  }
327
- if (clickgo.getNative() && task.main) {
849
+ if (clickgo.getNative() && isMain(taskId)) {
328
850
  native.invoke('cg-close', native.getToken());
329
851
  }
330
852
  const fid = form.getMaxZIndexID({
@@ -339,13 +861,25 @@ function end(taskId) {
339
861
  for (const fid in task.forms) {
340
862
  const f = task.forms[fid];
341
863
  core.trigger('formRemoved', taskId, f.id, f.vroot.$refs.form.title, f.vroot.$refs.form.iconData);
342
- f.vapp.unmount();
864
+ try {
865
+ f.vapp.unmount();
866
+ }
867
+ catch (err) {
868
+ const msg = `Message: ${err.message}\nTask id: ${task.id}\nForm id: ${fid}\nFunction: task.end, unmount.`;
869
+ form.notify({
870
+ 'title': 'Runtime Error',
871
+ 'content': msg,
872
+ 'type': 'danger'
873
+ });
874
+ console.log('Runtime Error', msg, err);
875
+ }
343
876
  f.vapp._container.remove();
344
877
  }
345
- dom.removeFromStyleList(taskId);
346
- for (const url of task.objectURLs) {
347
- tool.revokeObjectURL(url, task.id);
878
+ const flist = document.querySelectorAll('#cg-form-list > [data-task-id="' + taskId.toString() + '"]');
879
+ for (const f of flist) {
880
+ f.remove();
348
881
  }
882
+ dom.removeFromStyleList(taskId);
349
883
  for (const timer in exports.list[taskId].timers) {
350
884
  if (timer.startsWith('1x')) {
351
885
  const ft = timer.slice(2);
@@ -381,7 +915,7 @@ function loadLocaleData(lang, data, pre = '', taskId) {
381
915
  }
382
916
  }
383
917
  exports.loadLocaleData = loadLocaleData;
384
- function loadLocale(lang, path, taskId, formId) {
918
+ function loadLocale(lang, path, taskId) {
385
919
  return __awaiter(this, void 0, void 0, function* () {
386
920
  if (!taskId) {
387
921
  return false;
@@ -390,19 +924,11 @@ function loadLocale(lang, path, taskId, formId) {
390
924
  if (!task) {
391
925
  return false;
392
926
  }
393
- let form = null;
394
- if (formId) {
395
- if (!task.forms[formId]) {
396
- return false;
397
- }
398
- form = task.forms[formId];
399
- }
400
- const base = form ? form.vroot.cgPath : '/';
401
- path = tool.urlResolve(base, path) + '.json';
927
+ path = tool.urlResolve(task.current + '/', path) + '.json';
402
928
  const fcontent = yield fs.getContent(path, {
403
929
  'encoding': 'utf8',
404
- 'files': task.files,
405
- 'current': task.path
930
+ 'files': task.app.files,
931
+ 'current': task.current
406
932
  });
407
933
  if (!fcontent) {
408
934
  return false;
@@ -429,9 +955,9 @@ function clearLocale(taskId) {
429
955
  task.locale.data = {};
430
956
  }
431
957
  exports.clearLocale = clearLocale;
432
- function setLocale(lang, path, taskId, formId) {
958
+ function setLocale(lang, path, taskId) {
433
959
  clearLocale(taskId);
434
- return loadLocale(lang, path, taskId, formId);
960
+ return loadLocale(lang, path, taskId);
435
961
  }
436
962
  exports.setLocale = setLocale;
437
963
  function setLocaleLang(lang, taskId) {
@@ -457,17 +983,20 @@ function clearLocaleLang(taskId) {
457
983
  }
458
984
  exports.clearLocaleLang = clearLocaleLang;
459
985
  function createTimer(fun, delay, opt = {}) {
460
- var _a, _b;
986
+ var _a;
461
987
  const taskId = opt.taskId;
988
+ const formId = opt.formId;
462
989
  if (!taskId) {
463
990
  return 0;
464
991
  }
465
- const formId = opt.formId;
466
- if (!formId) {
992
+ const task = exports.list[taskId];
993
+ if (!task) {
467
994
  return 0;
468
995
  }
469
- const scope = (_a = opt.scope) !== null && _a !== void 0 ? _a : 'form';
470
- const count = (_b = opt.count) !== null && _b !== void 0 ? _b : 0;
996
+ if (formId && !task.forms[formId]) {
997
+ return 0;
998
+ }
999
+ const count = (_a = opt.count) !== null && _a !== void 0 ? _a : 0;
471
1000
  let c = 0;
472
1001
  if (opt.immediate) {
473
1002
  const r = fun();
@@ -484,12 +1013,10 @@ function createTimer(fun, delay, opt = {}) {
484
1013
  let timer;
485
1014
  const timerHandler = () => {
486
1015
  ++c;
487
- if (exports.list[taskId].forms[formId] === undefined) {
488
- if (scope === 'form') {
489
- clearTimeout(timer);
490
- delete exports.list[taskId].timers[timer];
491
- return;
492
- }
1016
+ if (formId && task.forms[formId] === undefined) {
1017
+ clearTimeout(timer);
1018
+ delete task.timers[timer];
1019
+ return;
493
1020
  }
494
1021
  const r = fun();
495
1022
  if (r instanceof Promise) {
@@ -499,7 +1026,7 @@ function createTimer(fun, delay, opt = {}) {
499
1026
  }
500
1027
  if (count > 0 && c === count) {
501
1028
  clearTimeout(timer);
502
- delete exports.list[taskId].timers[timer];
1029
+ delete task.timers[timer];
503
1030
  return;
504
1031
  }
505
1032
  };
@@ -509,7 +1036,7 @@ function createTimer(fun, delay, opt = {}) {
509
1036
  else {
510
1037
  timer = window.setInterval(timerHandler, delay);
511
1038
  }
512
- exports.list[taskId].timers[timer] = formId;
1039
+ task.timers[timer] = formId !== null && formId !== void 0 ? formId : 0;
513
1040
  return timer;
514
1041
  }
515
1042
  exports.createTimer = createTimer;
@@ -528,10 +1055,9 @@ function removeTimer(timer, taskId) {
528
1055
  delete exports.list[taskId].timers[timer];
529
1056
  }
530
1057
  exports.removeTimer = removeTimer;
531
- function sleep(fun, delay, taskId, formId) {
1058
+ function sleep(fun, delay, taskId) {
532
1059
  return createTimer(fun, delay, {
533
1060
  'taskId': taskId,
534
- 'formId': formId,
535
1061
  'count': 1
536
1062
  });
537
1063
  }
@@ -579,7 +1105,7 @@ clickgo.vue.watch(exports.systemTaskInfo, function (n, o) {
579
1105
  'deep': true
580
1106
  });
581
1107
  function setSystem(formId, taskId) {
582
- if (!formId || !taskId) {
1108
+ if (!taskId) {
583
1109
  return false;
584
1110
  }
585
1111
  const task = exports.list[taskId];
@@ -654,14 +1180,14 @@ function refreshSystemPosition() {
654
1180
  switch (core.config['task.position']) {
655
1181
  case 'left':
656
1182
  case 'right': {
657
- form.vroot.$refs.form.setPropData('width', 'auto');
1183
+ form.vroot.$refs.form.setPropData('width', 0);
658
1184
  form.vroot.$refs.form.setPropData('height', window.innerHeight);
659
1185
  break;
660
1186
  }
661
1187
  case 'top':
662
1188
  case 'bottom': {
663
1189
  form.vroot.$refs.form.setPropData('width', window.innerWidth);
664
- form.vroot.$refs.form.setPropData('height', 'auto');
1190
+ form.vroot.$refs.form.setPropData('height', 0);
665
1191
  break;
666
1192
  }
667
1193
  }