clickgo 3.1.1-dev10 → 3.1.3-dev12

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 (106) hide show
  1. package/dist/app/demo/app.js +0 -72
  2. package/dist/app/demo/config.json +109 -0
  3. package/dist/app/demo/form/control/button/button.js +12 -11
  4. package/dist/app/demo/form/control/button/button.xml +6 -6
  5. package/dist/app/demo/form/control/check/check.js +14 -10
  6. package/dist/app/demo/form/control/file/file.js +15 -13
  7. package/dist/app/demo/form/control/{overflow/overflow.css → flow/flow.css} +0 -0
  8. package/dist/app/demo/form/control/flow/flow.js +64 -0
  9. package/dist/app/demo/form/control/{overflow/overflow.scss → flow/flow.scss} +0 -0
  10. package/dist/app/demo/form/control/flow/flow.xml +101 -0
  11. package/dist/app/demo/form/control/form/form.js +1 -1
  12. package/dist/app/demo/form/control/form/form.xml +3 -3
  13. package/dist/app/demo/form/control/img/img.xml +2 -2
  14. package/dist/app/demo/form/control/list/list.js +95 -75
  15. package/dist/app/demo/form/control/list/list.xml +15 -11
  16. package/dist/app/demo/form/control/marquee/marquee.js +12 -10
  17. package/dist/app/demo/form/control/menu/menu.js +10 -6
  18. package/dist/app/demo/form/control/monaco/monaco.js +50 -60
  19. package/dist/app/demo/form/control/monaco/monaco.xml +6 -5
  20. package/dist/app/demo/form/control/property/property.js +131 -127
  21. package/dist/app/demo/form/control/radio/radio.js +9 -5
  22. package/dist/app/demo/form/control/scroll/scroll.js +16 -12
  23. package/dist/app/demo/form/control/scroll/scroll.xml +10 -10
  24. package/dist/app/demo/form/control/select/select.js +132 -71
  25. package/dist/app/demo/form/control/select/select.xml +69 -67
  26. package/dist/app/demo/form/control/tab/tab.js +21 -20
  27. package/dist/app/demo/form/control/tab/tab.xml +2 -2
  28. package/dist/app/demo/form/control/text/text.js +53 -45
  29. package/dist/app/demo/form/control/text/text.xml +3 -3
  30. package/dist/app/demo/form/control/{greatview/greatview.css → vflow/vflow.css} +0 -0
  31. package/dist/app/demo/form/control/vflow/vflow.js +79 -0
  32. package/dist/app/demo/form/control/{greatview/greatview.scss → vflow/vflow.scss} +0 -0
  33. package/dist/app/demo/form/control/{greatview/greatview.xml → vflow/vflow.xml} +25 -25
  34. package/dist/app/demo/form/event/form/form.js +58 -56
  35. package/dist/app/demo/form/event/form/form.xml +3 -3
  36. package/dist/app/demo/form/event/screen/screen.js +30 -28
  37. package/dist/app/demo/form/event/screen/screen.xml +2 -2
  38. package/dist/app/demo/form/event/task/task.js +31 -31
  39. package/dist/app/demo/form/event/task/task.xml +3 -3
  40. package/dist/app/demo/form/main.js +166 -5
  41. package/dist/app/demo/form/main.xml +37 -35
  42. package/dist/app/demo/form/method/aform/aform.js +57 -0
  43. package/dist/app/demo/form/method/aform/aform.xml +35 -0
  44. package/dist/app/demo/form/method/aform/test.xml +6 -0
  45. package/dist/app/demo/form/method/core/core.js +11 -8
  46. package/dist/app/demo/form/method/core/core.xml +2 -1
  47. package/dist/app/demo/form/method/dom/dom.js +91 -99
  48. package/dist/app/demo/form/method/dom/dom.xml +6 -7
  49. package/dist/app/demo/form/method/form/form.js +10 -28
  50. package/dist/app/demo/form/method/form/form.xml +8 -15
  51. package/dist/app/demo/form/method/fs/fs.js +34 -33
  52. package/dist/app/demo/form/method/fs/fs.xml +1 -1
  53. package/dist/app/demo/form/method/fs/text.js +12 -12
  54. package/dist/app/demo/form/method/native/native.js +50 -0
  55. package/dist/app/demo/form/method/native/native.xml +12 -0
  56. package/dist/app/demo/form/method/system/system.js +50 -0
  57. package/dist/app/demo/form/method/system/system.xml +11 -0
  58. package/dist/app/demo/form/method/task/task.js +59 -61
  59. package/dist/app/demo/form/method/task/task.xml +4 -6
  60. package/dist/app/demo/form/method/theme/theme.js +14 -14
  61. package/dist/app/demo/form/method/tool/tool.js +29 -28
  62. package/dist/app/demo/form/method/tool/tool.xml +3 -3
  63. package/dist/app/demo/form/method/zip/zip.js +46 -41
  64. package/dist/app/demo/form/method/zip/zip.xml +1 -1
  65. package/dist/app/task/app.js +0 -25
  66. package/dist/app/task/config.json +29 -0
  67. package/dist/app/task/form/bar/bar.js +2 -2
  68. package/dist/app/task/form/bar/bar.xml +1 -1
  69. package/dist/clickgo.js +17 -5
  70. package/dist/clickgo.ts +22 -3
  71. package/dist/control/common.cgc +0 -0
  72. package/dist/control/form.cgc +0 -0
  73. package/dist/control/monaco.cgc +0 -0
  74. package/dist/control/property.cgc +0 -0
  75. package/dist/control/task.cgc +0 -0
  76. package/dist/global.css +1 -1
  77. package/dist/index.js +28 -8
  78. package/dist/index.ts +33 -7
  79. package/dist/lib/control.js +75 -105
  80. package/dist/lib/control.ts +102 -124
  81. package/dist/lib/core.js +108 -252
  82. package/dist/lib/core.ts +122 -268
  83. package/dist/lib/dom.js +564 -483
  84. package/dist/lib/dom.ts +703 -546
  85. package/dist/lib/form.js +170 -153
  86. package/dist/lib/form.ts +132 -99
  87. package/dist/lib/fs.js +1 -1
  88. package/dist/lib/fs.ts +1 -1
  89. package/dist/lib/native.js +135 -8
  90. package/dist/lib/native.ts +176 -12
  91. package/dist/lib/task.js +301 -175
  92. package/dist/lib/task.ts +330 -207
  93. package/dist/lib/tool.js +48 -1
  94. package/dist/lib/tool.ts +61 -0
  95. package/dist/lib/zip.ts +2 -0
  96. package/dist/theme/familiar.cgt +0 -0
  97. package/package.json +1 -1
  98. package/types/index.d.ts +26 -29
  99. package/dist/app/demo/form/control/greatview/greatview.js +0 -92
  100. package/dist/app/demo/form/control/overflow/overflow.js +0 -70
  101. package/dist/app/demo/form/control/overflow/overflow.xml +0 -98
  102. package/dist/app/demo/form/control/view/view.css +0 -1
  103. package/dist/app/demo/form/control/view/view.js +0 -73
  104. package/dist/app/demo/form/control/view/view.scss +0 -18
  105. package/dist/app/demo/form/control/view/view.xml +0 -94
  106. package/dist/app/demo/form/method/form/test.xml +0 -5
package/dist/lib/core.ts CHANGED
@@ -19,10 +19,7 @@ import * as fs from './fs';
19
19
  import * as form from './form';
20
20
  import * as task from './task';
21
21
  import * as tool from './tool';
22
- import * as control from './control';
23
- import * as theme from './theme';
24
22
  import * as zip from './zip';
25
- import * as dom from './dom';
26
23
 
27
24
  /** --- Config 原始参考对象 --- */
28
25
  const configOrigin: types.IConfig = {
@@ -72,153 +69,6 @@ export abstract class AbstractApp {
72
69
  /** --- App 的入口文件 --- */
73
70
  public abstract main(): Promise<void>;
74
71
 
75
- /**
76
- * --- 先设置 App 的配置信息 ---
77
- * @param config 配置对象
78
- */
79
- public async config(config: types.IAppConfig): Promise<boolean> {
80
- const t = task.list[this.taskId];
81
- if (!t) {
82
- return false;
83
- }
84
- t.config = config;
85
- // --- 加载余下的 xml 等静态包内资源,仅限 net 的 app 模式 ---
86
- if (t.app.net) {
87
- if (!t.config.files) {
88
- return false;
89
- }
90
- const files = t.config.files;
91
- const net = t.app.net;
92
- await new Promise<void>(function(resolve) {
93
- let loaded = 0;
94
- const total = files.length;
95
- const beforeTotal = Object.keys(t.app.files).length;
96
- net.progress?.(loaded + beforeTotal, total + beforeTotal) as unknown;
97
- for (const file of files) {
98
- fs.getContent(net.url + file.slice(1), {
99
- 'current': net.current
100
- }).then(async function(blob) {
101
- if (blob === null || typeof blob === 'string') {
102
- clickgo.form.notify({
103
- 'title': 'File not found',
104
- 'content': net.url + file.slice(1),
105
- 'type': 'danger'
106
- });
107
- return;
108
- }
109
- const mime = tool.getMimeByPath(file);
110
- if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
111
- t.app.files[file] = (await tool.blob2Text(blob)).replace(/^\ufeff/, '');
112
- }
113
- else {
114
- t.app.files[file] = blob;
115
- }
116
- ++loaded;
117
- net.progress?.(loaded + beforeTotal, total + beforeTotal) as unknown;
118
- if (net.notify) {
119
- form.notifyProgress(net.notify, (loaded / total) / 2 + 0.5);
120
- }
121
- if (loaded < total) {
122
- return;
123
- }
124
- resolve();
125
- }).catch(function() {
126
- ++loaded;
127
- net.progress?.(loaded + beforeTotal, total + beforeTotal) as unknown;
128
- if (net.notify) {
129
- form.notifyProgress(net.notify, (loaded / total) / 2 + 0.5);
130
- }
131
- if (loaded < total) {
132
- return;
133
- }
134
- resolve();
135
- });
136
- }
137
- });
138
- if (net.notify) {
139
- setTimeout(function(): void {
140
- form.hideNotify(net.notify!);
141
- }, 2000);
142
- }
143
- }
144
- // --- 要加载 control ---
145
- if (!await control.init(this.taskId)) {
146
- return false;
147
- }
148
- // --- theme ---
149
- if (config.themes?.length) {
150
- for (let path of config.themes) {
151
- path += '.cgt';
152
- path = tool.urlResolve('/', path);
153
- const file = await fs.getContent(path, {
154
- 'files': t.app.files,
155
- 'current': t.current
156
- });
157
- if (file && typeof file !== 'string') {
158
- const th = await theme.read(file);
159
- if (th) {
160
- await theme.load(th, t.id);
161
- }
162
- }
163
- }
164
- }
165
- else {
166
- // --- 加载全局主题 ---
167
- if (theme.global) {
168
- await theme.load(undefined, this.taskId);
169
- }
170
- }
171
- // --- locale ---
172
- if (config.locales) {
173
- for (let path in config.locales) {
174
- const locale = config.locales[path];
175
- if (!path.endsWith('.json')) {
176
- path += '.json';
177
- }
178
- const lcontent = await fs.getContent(path, {
179
- 'encoding': 'utf8',
180
- 'files': t.app.files,
181
- 'current': t.current
182
- });
183
- if (!lcontent) {
184
- continue;
185
- }
186
- try {
187
- const data = JSON.parse(lcontent);
188
- task.loadLocaleData(locale, data, '', t.id);
189
- }
190
- catch {
191
- // --- 无所谓 ---
192
- }
193
- }
194
- }
195
- // --- 加载任务级全局样式 ---
196
- if (config.style) {
197
- const style = await fs.getContent(config.style + '.css', {
198
- 'encoding': 'utf8',
199
- 'files': t.app.files,
200
- 'current': t.current
201
- });
202
- if (style) {
203
- const r = tool.stylePrepend(style, 'cg-task' + this.taskId.toString() + '_');
204
- dom.pushStyle(this.taskId, await tool.styleUrl2DataUrl(config.style, r.style, t.app.files));
205
- }
206
- }
207
- // --- 加载图标 ---
208
- if (config.icon) {
209
- const icon = await fs.getContent(config.icon, {
210
- 'files': t.app.files,
211
- 'current': t.current
212
- });
213
- if (icon && typeof icon !== 'string') {
214
- t.app.icon = await tool.blob2DataUrl(icon);
215
- }
216
- }
217
- // --- 全部成功,设置 t.class 为自己 ---
218
- t.class = this;
219
- return true;
220
- }
221
-
222
72
  /**
223
73
  * --- 以某个窗体进行正式启动这个 app(入口 form),不启动则任务也启动失败 ---
224
74
  * @param form 窗体对象
@@ -392,7 +242,12 @@ clickgo.vue.watch(config, function() {
392
242
  });
393
243
 
394
244
  /** --- module 列表 --- */
395
- const modules: Record<string, { func: () => any | Promise<any>; 'obj': null | any; 'loading': boolean; }> = {
245
+ const modules: Record<string, {
246
+ func: () => any | Promise<any>;
247
+ 'obj': null | any;
248
+ 'loading': boolean;
249
+ 'resolve': Array<() => void | Promise<void>>;
250
+ }> = {
396
251
  'monaco': {
397
252
  func: async function() {
398
253
  return new Promise(function(resolve, reject) {
@@ -408,7 +263,8 @@ const modules: Record<string, { func: () => any | Promise<any>; 'obj': null | an
408
263
  });
409
264
  },
410
265
  'obj': null,
411
- 'loading': false
266
+ 'loading': false,
267
+ 'resolve': []
412
268
  }
413
269
  };
414
270
 
@@ -424,97 +280,61 @@ export function regModule(name: string, func: () => any | Promise<any>): boolean
424
280
  modules[name] = {
425
281
  func: func,
426
282
  'obj': null,
427
- 'loading': false
283
+ 'loading': false,
284
+ 'resolve': []
428
285
  };
429
286
  return true;
430
287
  }
431
288
 
432
289
  /**
433
- * --- 外接模块需要 init 后才能使用 ---
434
- * @param names 要加载的模块名
290
+ * --- 获取外接模块 ---
291
+ * @param name 模块名
435
292
  */
436
- export function initModules(names: string | string[]): Promise<number> {
437
- return new Promise(function(resolve) {
438
- if (typeof names === 'string') {
439
- names = [names];
440
- }
441
- if (names.length === 0) {
442
- resolve(0);
443
- return;
293
+ export function getModule(name: string): Promise<null | any> {
294
+ return new Promise((resolve) => {
295
+ if (!modules[name]) {
296
+ return null;
444
297
  }
445
- let loaded = 0;
446
- let successful = 0;
447
- for (const name of names) {
448
- if (!modules[name]) {
449
- ++loaded;
450
- if (loaded === names.length) {
451
- resolve(successful);
452
- return;
453
- }
454
- continue;
455
- }
456
- if (modules[name].obj) {
457
- ++loaded;
458
- ++successful;
459
- if (loaded === names.length) {
460
- resolve(successful);
461
- return;
462
- }
463
- continue;
464
- }
298
+ if (!modules[name].obj) {
299
+ // --- obj 是 null 判断是否要初始化 ---
465
300
  if (modules[name].loading) {
466
- ++loaded;
467
- if (loaded === names.length) {
468
- resolve(successful);
469
- return;
470
- }
471
- continue;
472
- }
473
- // --- 正式开始加载 init ---
474
- modules[name].loading = true;
475
- const rtn = modules[name].func();
476
- if (rtn instanceof Promise) {
477
- rtn.then(function(obj) {
478
- modules[name].obj = obj;
479
- modules[name].loading = false;
480
- ++loaded;
481
- ++successful;
482
- if (loaded === names.length) {
483
- resolve(successful);
484
- return;
485
- }
486
- }).catch(function() {
487
- modules[name].loading = false;
488
- ++loaded;
489
- if (loaded === names.length) {
490
- resolve(successful);
491
- }
301
+ // --- 加载中,等待 ---
302
+ modules[name].resolve.push(() => {
303
+ resolve(modules[name].obj);
492
304
  });
493
305
  }
494
306
  else {
495
- modules[name].obj = rtn;
496
- modules[name].loading = false;
497
- ++loaded;
498
- ++successful;
499
- if (loaded === names.length) {
500
- resolve(successful);
307
+ // --- 没加载,开始加载 ---
308
+ const rtn = modules[name].func();
309
+ if (rtn instanceof Promise) {
310
+ modules[name].loading = true;
311
+ rtn.then(function(obj) {
312
+ modules[name].obj = obj;
313
+ modules[name].loading = false;
314
+ resolve(obj);
315
+ for (const r of modules[name].resolve) {
316
+ r() as any;
317
+ }
318
+ }).catch(function() {
319
+ modules[name].loading = false;
320
+ resolve(null);
321
+ for (const r of modules[name].resolve) {
322
+ r() as any;
323
+ }
324
+ });
325
+ }
326
+ else {
327
+ modules[name].obj = rtn;
328
+ resolve(rtn);
501
329
  }
502
330
  }
331
+ return;
503
332
  }
333
+ resolve(modules[name].obj);
334
+ return;
504
335
  });
505
336
  }
506
337
 
507
- /**
508
- * --- 获取外接模块 ---
509
- * @param name 模块名
510
- */
511
- export function getModule(name: string): null | any {
512
- if (!modules[name]) {
513
- return null;
514
- }
515
- return modules[name].obj;
516
- }
517
-
518
338
  /** --- 系统要处理的全局响应事件 --- */
519
339
  const globalEvents = {
520
340
  screenResize: function(): void {
@@ -707,6 +527,13 @@ export async function readApp(blob: Blob): Promise<false | types.IApp> {
707
527
  }
708
528
  // --- 开始读取文件 ---
709
529
  const files: Record<string, Blob | string> = {};
530
+ /** --- 配置文件 --- */
531
+ const configContent = await z.getContent('/config.json');
532
+ if (!configContent) {
533
+ return false;
534
+ }
535
+ const config: types.IAppConfig = JSON.parse(configContent);
536
+ // --- 读取包 ---
710
537
  const list = z.readDir('/', {
711
538
  'hasChildren': true
712
539
  });
@@ -730,8 +557,10 @@ export async function readApp(blob: Blob): Promise<false | types.IApp> {
730
557
  }
731
558
  }
732
559
  return {
733
- 'icon': icon,
734
- 'files': files
560
+ 'type': 'app',
561
+ 'config': config,
562
+ 'files': files,
563
+ 'icon': icon
735
564
  };
736
565
  }
737
566
 
@@ -798,53 +627,78 @@ export async function fetchApp(
798
627
  return null;
799
628
  }
800
629
  }
801
- // --- 从网络嗅探 ---
802
- let loaded = 0;
803
- let total = 30;
804
- // --- 网络嗅探,不知道文件总数,先暂定 30,不过超出 30 文件的建议打包为 cga ---
805
- const files = await loader.sniffFiles(url + 'app.js', {
806
- 'dir': '/',
807
- adapter: async (url) => {
808
- const r = await fs.getContent(url, {
809
- 'encoding': 'utf8',
810
- 'current': current
811
- });
812
- return r;
813
- },
814
- 'loaded': () => {
815
- ++loaded;
816
- if (loaded === total) {
817
- ++total;
818
- }
819
- if (opt.notifyId) {
820
- form.notifyProgress(opt.notifyId, (loaded / total) / 2);
630
+ // --- 从网络加载 app ---
631
+ let config: types.IAppConfig;
632
+ /** --- 已加载的 files --- */
633
+ const files: Record<string, Blob | string> = {};
634
+ try {
635
+ const blob = await fs.getContent(url + 'config.json', {
636
+ 'current': current
637
+ });
638
+ if (blob === null || typeof blob === 'string') {
639
+ return null;
640
+ }
641
+ config = JSON.parse(await tool.blob2Text(blob));
642
+ await new Promise<void>(function(resolve) {
643
+ if (!config.files) {
644
+ return;
821
645
  }
822
- if (opt.progress) {
823
- opt.progress(loaded, total) as unknown;
646
+ const total = config.files.length;
647
+ let loaded = 0;
648
+ for (const file of config.files) {
649
+ fs.getContent(url + file.slice(1), {
650
+ 'current': current
651
+ }).then(async function(blob) {
652
+ if (blob === null || typeof blob === 'string') {
653
+ clickgo.form.notify({
654
+ 'title': 'File not found',
655
+ 'content': url + file.slice(1),
656
+ 'type': 'danger'
657
+ });
658
+ return;
659
+ }
660
+ const mime = tool.getMimeByPath(file);
661
+ if (['txt', 'json', 'js', 'css', 'xml', 'html'].includes(mime.ext)) {
662
+ files[file] = (await tool.blob2Text(blob)).replace(/^\ufeff/, '');
663
+ }
664
+ else {
665
+ files[file] = blob;
666
+ }
667
+ ++loaded;
668
+ if (opt.notifyId) {
669
+ form.notifyProgress(opt.notifyId, loaded / total);
670
+ }
671
+ if (loaded < total) {
672
+ return;
673
+ }
674
+ resolve();
675
+ }).catch(function() {
676
+ ++loaded;
677
+ if (opt.notifyId) {
678
+ form.notifyProgress(opt.notifyId, loaded / total);
679
+ }
680
+ if (loaded < total) {
681
+ return;
682
+ }
683
+ resolve();
684
+ });
824
685
  }
825
- }
826
- });
827
- // --- net 模式此处加载完只算到 50%,因为还有 app 类当中 config 中的静态部分,暂定预留 50% ---
828
- if (opt.notifyId) {
829
- form.notifyProgress(opt.notifyId, 0.5);
686
+ });
830
687
  }
831
- if (Object.keys(files).length === 0) {
688
+ catch {
832
689
  return null;
833
690
  }
834
- const ul = url.length - 1;
835
- for (const fn in files) {
836
- files[fn.slice(ul)] = files[fn];
837
- delete files[fn];
691
+
692
+ let icon = '/clickgo/icon.png';
693
+ if (config.icon && (files[config.icon] instanceof Blob)) {
694
+ icon = await tool.blob2DataUrl(files[config.icon] as Blob);
838
695
  }
696
+
839
697
  return {
840
- 'net': {
841
- 'current': current,
842
- 'notify': opt.notifyId,
843
- 'url': url,
844
- 'progress': opt.progress
845
- },
846
- 'icon': '',
847
- 'files': files
698
+ 'type': 'app',
699
+ 'config': config,
700
+ 'files': files,
701
+ 'icon': icon
848
702
  };
849
703
  }
850
704