clickgo 3.0.6-dev7 → 3.1.0-dev9

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/form/form.js +21 -20
  4. package/dist/app/demo/form/control/form/form.xml +3 -3
  5. package/dist/app/demo/form/main.js +20 -10
  6. package/dist/app/demo/form/main.xml +1 -1
  7. package/dist/app/task/app.js +46 -0
  8. package/dist/app/task/form/bar/bar.js +85 -86
  9. package/dist/app/task/form/bar/bar.xml +5 -6
  10. package/dist/clickgo.js +1 -10
  11. package/dist/clickgo.ts +0 -8
  12. package/dist/control/common.cgc +0 -0
  13. package/dist/control/form.cgc +0 -0
  14. package/dist/control/monaco.cgc +0 -0
  15. package/dist/control/property.cgc +0 -0
  16. package/dist/control/task.cgc +0 -0
  17. package/dist/global.css +1 -1
  18. package/dist/index.js +105 -56
  19. package/dist/index.ts +164 -59
  20. package/dist/lib/control.js +363 -240
  21. package/dist/lib/control.ts +497 -284
  22. package/dist/lib/core.js +331 -217
  23. package/dist/lib/core.ts +418 -244
  24. package/dist/lib/dom.js +6 -3
  25. package/dist/lib/dom.ts +7 -6
  26. package/dist/lib/form.js +635 -980
  27. package/dist/lib/form.ts +817 -1072
  28. package/dist/lib/fs.js +42 -39
  29. package/dist/lib/fs.ts +45 -41
  30. package/dist/lib/native.js +8 -148
  31. package/dist/lib/native.ts +9 -211
  32. package/dist/lib/task.js +707 -191
  33. package/dist/lib/task.ts +778 -210
  34. package/dist/lib/theme.ts +2 -2
  35. package/dist/lib/tool.js +58 -48
  36. package/dist/lib/tool.ts +79 -64
  37. package/dist/theme/familiar.cgt +0 -0
  38. package/package.json +5 -7
  39. package/types/index.d.ts +286 -324
  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,598 @@ 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
+ escapeHTML: function (html) {
740
+ return clickgo.tool.escapeHTML(html);
741
+ },
742
+ request: function (url, opt) {
743
+ return clickgo.tool.request(url, opt);
744
+ },
745
+ parseUrl: function (url) {
746
+ return clickgo.tool.parseUrl(url);
747
+ },
748
+ urlResolve: function (from, to) {
749
+ return clickgo.tool.urlResolve(from, to);
750
+ },
751
+ blob2Text: function (blob) {
752
+ return clickgo.tool.blob2Text(blob);
753
+ },
754
+ blob2DataUrl: function (blob) {
755
+ return clickgo.tool.blob2DataUrl(blob);
756
+ },
757
+ execCommand: function (ac) {
758
+ clickgo.tool.execCommand(ac);
759
+ }
760
+ },
761
+ 'zip': {
762
+ get: function (data) {
763
+ return clickgo.zip.get(data);
764
+ }
765
+ }
766
+ };
767
+ const preprocess = function (code, path) {
768
+ const exec = /eval\W/.exec(code);
769
+ if (exec) {
770
+ form.notify({
771
+ 'title': 'Error',
772
+ 'content': `The "eval" is prohibited.\nFile: "${path}".`,
773
+ 'type': 'danger'
774
+ });
775
+ return '';
776
+ }
777
+ code = code.replace(/extends[\s\S]+?\.\s*(AbstractApp|AbstractForm)\s*{/, (t) => {
778
+ return t + 'get filename() {return __filename;}';
779
+ });
780
+ return code;
781
+ };
782
+ app.files['/invoke/clickgo.js'] = `module.exports = invokeClickgo;`;
783
+ const path = url;
784
+ const lio = path.endsWith('.cga') ? path.lastIndexOf('/') : path.slice(0, -1).lastIndexOf('/');
785
+ const current = path.slice(0, lio);
189
786
  exports.list[taskId] = {
190
787
  'id': taskId,
191
788
  'app': app,
@@ -194,132 +791,50 @@ function run(url, opt = {}) {
194
791
  'lang': '',
195
792
  'data': {}
196
793
  }),
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': {},
794
+ 'path': path,
795
+ 'current': current,
796
+ 'runtime': clickgo.vue.reactive({
797
+ 'permissions': {},
798
+ 'dialogFormIds': []
799
+ }),
202
800
  'forms': {},
203
- 'objectURLs': [],
204
- 'controls': {
205
- 'loaded': {},
206
- 'layout': {},
207
- 'prep': {}
208
- },
209
- 'timers': {}
801
+ 'controls': {},
802
+ 'timers': {},
803
+ 'invoke': invoke
210
804
  };
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
- }
805
+ let expo = [];
806
+ try {
807
+ expo = loader.require('/app.js', app.files, {
808
+ 'dir': '/',
809
+ 'invoke': invoke,
810
+ 'preprocess': preprocess,
811
+ 'map': {
812
+ 'clickgo': '/invoke/clickgo'
243
813
  }
244
- }
814
+ })[0];
245
815
  }
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
- }
816
+ catch (e) {
817
+ delete exports.list[taskId];
818
+ core.trigger('error', taskId, 0, e, e.message + '(-1)');
819
+ return -2;
267
820
  }
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
- }
821
+ if (!(expo === null || expo === void 0 ? void 0 : expo.default)) {
822
+ delete exports.list[taskId];
823
+ return -3;
301
824
  }
302
- else {
303
- if (theme.global) {
304
- yield theme.load(undefined, task.id);
305
- }
825
+ dom.createToStyleList(taskId);
826
+ const appCls = new expo.default();
827
+ yield appCls.main();
828
+ if (!exports.list[taskId].class) {
829
+ delete exports.list[taskId];
830
+ dom.removeFromStyleList(taskId);
831
+ return -4;
306
832
  }
307
- if (task.id === 1) {
308
- clickgo.native.send('cg-init', clickgo.native.getToken());
309
- }
310
- if (clickgo.getNative() && opt.sync) {
311
- f.vroot.$refs.form.isNativeSync = true;
312
- clickgo.native.send('cg-set-size', JSON.stringify({
313
- 'token': clickgo.native.getToken(),
314
- 'width': f.vroot.$refs.form.widthData,
315
- 'height': f.vroot.$refs.form.heightData
316
- }));
317
- window.addEventListener('resize', function () {
318
- f.vroot.$refs.form.setPropData('width', window.innerWidth);
319
- f.vroot.$refs.form.setPropData('height', window.innerHeight);
320
- });
833
+ core.trigger('taskStarted', taskId);
834
+ if (taskId === 1) {
835
+ native.invoke('cg-init', native.getToken());
321
836
  }
322
- return task.id;
837
+ return taskId;
323
838
  });
324
839
  }
325
840
  exports.run = run;
@@ -328,10 +843,8 @@ function end(taskId) {
328
843
  if (!task) {
329
844
  return true;
330
845
  }
331
- if (clickgo.getNative() && task.main) {
332
- clickgo.native.send('cg-main-close', JSON.stringify({
333
- 'token': clickgo.native.getToken()
334
- }));
846
+ if (clickgo.getNative() && isMain(taskId)) {
847
+ native.invoke('cg-close', native.getToken());
335
848
  }
336
849
  const fid = form.getMaxZIndexID({
337
850
  'taskIds': [task.id]
@@ -345,13 +858,25 @@ function end(taskId) {
345
858
  for (const fid in task.forms) {
346
859
  const f = task.forms[fid];
347
860
  core.trigger('formRemoved', taskId, f.id, f.vroot.$refs.form.title, f.vroot.$refs.form.iconData);
348
- f.vapp.unmount();
861
+ try {
862
+ f.vapp.unmount();
863
+ }
864
+ catch (err) {
865
+ const msg = `Message: ${err.message}\nTask id: ${task.id}\nForm id: ${fid}\nFunction: task.end, unmount.`;
866
+ form.notify({
867
+ 'title': 'Runtime Error',
868
+ 'content': msg,
869
+ 'type': 'danger'
870
+ });
871
+ console.log('Runtime Error', msg, err);
872
+ }
349
873
  f.vapp._container.remove();
350
874
  }
351
- dom.removeFromStyleList(taskId);
352
- for (const url of task.objectURLs) {
353
- tool.revokeObjectURL(url, task.id);
875
+ const flist = document.querySelectorAll('#cg-form-list > [data-task-id="' + taskId.toString() + '"]');
876
+ for (const f of flist) {
877
+ f.remove();
354
878
  }
879
+ dom.removeFromStyleList(taskId);
355
880
  for (const timer in exports.list[taskId].timers) {
356
881
  if (timer.startsWith('1x')) {
357
882
  const ft = timer.slice(2);
@@ -362,7 +887,6 @@ function end(taskId) {
362
887
  clearTimeout(parseFloat(timer));
363
888
  }
364
889
  }
365
- native.clearListener(taskId);
366
890
  dom.clearWatchSize(taskId);
367
891
  delete exports.list[taskId];
368
892
  core.trigger('taskEnded', taskId);
@@ -388,7 +912,7 @@ function loadLocaleData(lang, data, pre = '', taskId) {
388
912
  }
389
913
  }
390
914
  exports.loadLocaleData = loadLocaleData;
391
- function loadLocale(lang, path, taskId, formId) {
915
+ function loadLocale(lang, path, taskId) {
392
916
  return __awaiter(this, void 0, void 0, function* () {
393
917
  if (!taskId) {
394
918
  return false;
@@ -397,19 +921,11 @@ function loadLocale(lang, path, taskId, formId) {
397
921
  if (!task) {
398
922
  return false;
399
923
  }
400
- let form = null;
401
- if (formId) {
402
- if (!task.forms[formId]) {
403
- return false;
404
- }
405
- form = task.forms[formId];
406
- }
407
- const base = form ? form.vroot.cgPath : '/';
408
- path = tool.urlResolve(base, path) + '.json';
924
+ path = tool.urlResolve(task.current + '/', path) + '.json';
409
925
  const fcontent = yield fs.getContent(path, {
410
926
  'encoding': 'utf8',
411
- 'files': task.files,
412
- 'current': task.path
927
+ 'files': task.app.files,
928
+ 'current': task.current
413
929
  });
414
930
  if (!fcontent) {
415
931
  return false;
@@ -436,9 +952,9 @@ function clearLocale(taskId) {
436
952
  task.locale.data = {};
437
953
  }
438
954
  exports.clearLocale = clearLocale;
439
- function setLocale(lang, path, taskId, formId) {
955
+ function setLocale(lang, path, taskId) {
440
956
  clearLocale(taskId);
441
- return loadLocale(lang, path, taskId, formId);
957
+ return loadLocale(lang, path, taskId);
442
958
  }
443
959
  exports.setLocale = setLocale;
444
960
  function setLocaleLang(lang, taskId) {
@@ -464,17 +980,20 @@ function clearLocaleLang(taskId) {
464
980
  }
465
981
  exports.clearLocaleLang = clearLocaleLang;
466
982
  function createTimer(fun, delay, opt = {}) {
467
- var _a, _b;
983
+ var _a;
468
984
  const taskId = opt.taskId;
985
+ const formId = opt.formId;
469
986
  if (!taskId) {
470
987
  return 0;
471
988
  }
472
- const formId = opt.formId;
473
- if (!formId) {
989
+ const task = exports.list[taskId];
990
+ if (!task) {
474
991
  return 0;
475
992
  }
476
- const scope = (_a = opt.scope) !== null && _a !== void 0 ? _a : 'form';
477
- const count = (_b = opt.count) !== null && _b !== void 0 ? _b : 0;
993
+ if (formId && !task.forms[formId]) {
994
+ return 0;
995
+ }
996
+ const count = (_a = opt.count) !== null && _a !== void 0 ? _a : 0;
478
997
  let c = 0;
479
998
  if (opt.immediate) {
480
999
  const r = fun();
@@ -491,12 +1010,10 @@ function createTimer(fun, delay, opt = {}) {
491
1010
  let timer;
492
1011
  const timerHandler = () => {
493
1012
  ++c;
494
- if (exports.list[taskId].forms[formId] === undefined) {
495
- if (scope === 'form') {
496
- clearTimeout(timer);
497
- delete exports.list[taskId].timers[timer];
498
- return;
499
- }
1013
+ if (formId && task.forms[formId] === undefined) {
1014
+ clearTimeout(timer);
1015
+ delete task.timers[timer];
1016
+ return;
500
1017
  }
501
1018
  const r = fun();
502
1019
  if (r instanceof Promise) {
@@ -506,7 +1023,7 @@ function createTimer(fun, delay, opt = {}) {
506
1023
  }
507
1024
  if (count > 0 && c === count) {
508
1025
  clearTimeout(timer);
509
- delete exports.list[taskId].timers[timer];
1026
+ delete task.timers[timer];
510
1027
  return;
511
1028
  }
512
1029
  };
@@ -516,7 +1033,7 @@ function createTimer(fun, delay, opt = {}) {
516
1033
  else {
517
1034
  timer = window.setInterval(timerHandler, delay);
518
1035
  }
519
- exports.list[taskId].timers[timer] = formId;
1036
+ task.timers[timer] = formId !== null && formId !== void 0 ? formId : 0;
520
1037
  return timer;
521
1038
  }
522
1039
  exports.createTimer = createTimer;
@@ -535,10 +1052,9 @@ function removeTimer(timer, taskId) {
535
1052
  delete exports.list[taskId].timers[timer];
536
1053
  }
537
1054
  exports.removeTimer = removeTimer;
538
- function sleep(fun, delay, taskId, formId) {
1055
+ function sleep(fun, delay, taskId) {
539
1056
  return createTimer(fun, delay, {
540
1057
  'taskId': taskId,
541
- 'formId': formId,
542
1058
  'count': 1
543
1059
  });
544
1060
  }
@@ -586,7 +1102,7 @@ clickgo.vue.watch(exports.systemTaskInfo, function (n, o) {
586
1102
  'deep': true
587
1103
  });
588
1104
  function setSystem(formId, taskId) {
589
- if (!formId || !taskId) {
1105
+ if (!taskId) {
590
1106
  return false;
591
1107
  }
592
1108
  const task = exports.list[taskId];
@@ -661,14 +1177,14 @@ function refreshSystemPosition() {
661
1177
  switch (core.config['task.position']) {
662
1178
  case 'left':
663
1179
  case 'right': {
664
- form.vroot.$refs.form.setPropData('width', 'auto');
1180
+ form.vroot.$refs.form.setPropData('width', 0);
665
1181
  form.vroot.$refs.form.setPropData('height', window.innerHeight);
666
1182
  break;
667
1183
  }
668
1184
  case 'top':
669
1185
  case 'bottom': {
670
1186
  form.vroot.$refs.form.setPropData('width', window.innerWidth);
671
- form.vroot.$refs.form.setPropData('height', 'auto');
1187
+ form.vroot.$refs.form.setPropData('height', 0);
672
1188
  break;
673
1189
  }
674
1190
  }