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
@@ -1,172 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cgInnerReceive = exports.cgInnerGetSends = exports.size = exports.restore = exports.min = exports.max = exports.clearListener = exports.off = exports.once = exports.on = exports.send = exports.getListeners = exports.getToken = void 0;
3
+ exports.size = exports.restore = exports.min = exports.max = exports.invoke = exports.getToken = void 0;
4
4
  const clickgo = require("../clickgo");
5
- let sendId = 0;
6
- let sendList = [];
7
- const listeners = {};
8
5
  const token = (Math.random() * 100000000000000 * (100 + Math.round(Math.random() * (999 - 100)))).toString(32);
9
6
  function getToken() {
10
7
  return token;
11
8
  }
12
9
  exports.getToken = getToken;
13
- function getListeners() {
14
- const list = [];
15
- for (const name in listeners) {
16
- for (const item of listeners[name]) {
17
- list.push({
18
- 'id': item.id,
19
- 'name': name,
20
- 'once': item.once,
21
- 'taskId': item.taskId
22
- });
23
- }
24
- }
25
- return list;
26
- }
27
- exports.getListeners = getListeners;
28
- function send(name, param, handler, taskId) {
29
- if (!clickgo.getNative()) {
30
- return 0;
31
- }
32
- const id = ++sendId;
33
- sendList.push({
34
- 'id': id,
35
- 'name': name,
36
- 'param': param
37
- });
38
- if (handler) {
39
- on(name, handler, id, true, taskId);
40
- }
41
- return id;
42
- }
43
- exports.send = send;
44
- function on(name, handler, id, once = false, taskId) {
10
+ function invoke(name, ...param) {
45
11
  if (!clickgo.getNative()) {
46
12
  return;
47
13
  }
48
- if (!listeners[name]) {
49
- listeners[name] = [];
50
- }
51
- listeners[name].push({
52
- 'id': id !== null && id !== void 0 ? id : 0,
53
- 'once': once,
54
- 'taskId': taskId,
55
- 'handler': handler
56
- });
57
- }
58
- exports.on = on;
59
- function once(name, handler, id, taskId) {
60
- on(name, handler, id, true, taskId);
14
+ return window.clickgoNative.invoke(name, ...param);
61
15
  }
62
- exports.once = once;
63
- function off(name, handler, taskId) {
64
- if (!listeners[name]) {
65
- return;
66
- }
67
- for (let i = 0; i < listeners[name].length; ++i) {
68
- if (listeners[name][i].handler !== handler) {
69
- continue;
70
- }
71
- if (taskId && (listeners[name][i].taskId !== taskId)) {
72
- continue;
73
- }
74
- listeners[name].splice(i, 1);
75
- if (listeners[name].length === 0) {
76
- delete listeners[name];
77
- break;
78
- }
79
- --i;
80
- }
81
- }
82
- exports.off = off;
83
- function clearListener(taskId) {
84
- if (!taskId) {
85
- return;
86
- }
87
- for (const name in listeners) {
88
- for (let i = 0; i < listeners[name].length; ++i) {
89
- if (listeners[name][i].taskId !== taskId) {
90
- continue;
91
- }
92
- listeners[name].splice(i, 1);
93
- if (listeners[name].length === 0) {
94
- delete listeners[name];
95
- break;
96
- }
97
- }
98
- }
99
- }
100
- exports.clearListener = clearListener;
16
+ exports.invoke = invoke;
101
17
  function max() {
102
- send('cg-set-state', JSON.stringify({
103
- 'token': token,
104
- 'state': 'max'
105
- }));
18
+ invoke('cg-set-state', token, 'max');
106
19
  }
107
20
  exports.max = max;
108
21
  function min() {
109
- send('cg-set-state', JSON.stringify({
110
- 'token': token,
111
- 'state': 'min'
112
- }));
22
+ invoke('cg-set-state', token, 'min');
113
23
  }
114
24
  exports.min = min;
115
25
  function restore() {
116
- send('cg-set-state', JSON.stringify({
117
- 'token': token,
118
- 'state': 'restore'
119
- }));
26
+ invoke('cg-set-state', token, 'restore');
120
27
  }
121
28
  exports.restore = restore;
122
29
  function size(width, height) {
123
- send('cg-set-size', JSON.stringify({
124
- 'token': token,
125
- 'width': width,
126
- 'height': height
127
- }));
30
+ invoke('cg-set-size', token, width, height);
128
31
  }
129
32
  exports.size = size;
130
- function cgInnerGetSends() {
131
- const json = JSON.stringify(sendList);
132
- sendList = [];
133
- return json;
134
- }
135
- exports.cgInnerGetSends = cgInnerGetSends;
136
- function cgInnerReceive(id, name, result) {
137
- if (!listeners[name]) {
138
- return;
139
- }
140
- for (let i = 0; i < listeners[name].length; ++i) {
141
- const item = listeners[name][i];
142
- if (item.id > 0) {
143
- if (item.id !== id) {
144
- continue;
145
- }
146
- const r = item.handler(result);
147
- if (r instanceof Promise) {
148
- r.catch(function (e) {
149
- console.log(e);
150
- });
151
- }
152
- }
153
- else {
154
- const r = item.handler(result);
155
- if (r instanceof Promise) {
156
- r.catch(function (e) {
157
- console.log(e);
158
- });
159
- }
160
- }
161
- if (item.once) {
162
- listeners[name].splice(i, 1);
163
- --i;
164
- }
165
- }
166
- }
167
- exports.cgInnerReceive = cgInnerReceive;
168
- window.clickGoNative = {
169
- isReady: true,
170
- cgInnerGetSends: cgInnerGetSends,
171
- cgInnerReceive: cgInnerReceive
172
- };
@@ -15,23 +15,6 @@
15
15
  */
16
16
  import * as clickgo from '../clickgo';
17
17
 
18
- /** --- 最后一个 send ID --- */
19
- let sendId = 0;
20
- // --- sendList 一定会被清理 ---
21
- let sendList: Array<{
22
- 'id': number;
23
- 'name': string;
24
- 'param': string | undefined;
25
- }> = [];
26
-
27
- /** --- 监听的 listener,需要调用者手动清理(或者 task 结束后自动会被清理,未设置 taskId 的则不会自动清理) --- */
28
- const listeners: Record<string, Array<{
29
- 'id': number;
30
- 'once': boolean;
31
- 'taskId'?: number;
32
- 'handler': (param?: string) => void | Promise<void>;
33
- }>> = {};
34
-
35
18
  const token = (Math.random() * 100000000000000 * (100 + Math.round(Math.random() * (999 - 100)))).toString(32);
36
19
  /**
37
20
  * --- 获取 native 通讯 token,app 模式下无效 ---
@@ -40,217 +23,32 @@ export function getToken(): string {
40
23
  return token;
41
24
  }
42
25
 
43
- /**
44
- * --- 获取已经创建的监听列表 ---
45
- */
46
- export function getListeners(): Array<{ 'id': number; 'name': string; 'once': boolean; 'taskId'?: number; }> {
47
- const list = [];
48
- for (const name in listeners) {
49
- for (const item of listeners[name]) {
50
- list.push({
51
- 'id': item.id,
52
- 'name': name,
53
- 'once': item.once,
54
- 'taskId': item.taskId
55
- });
56
- }
57
- }
58
- return list;
59
- }
60
-
61
26
  /**
62
27
  * --- 向 native 发送指令 ---
63
28
  * @param name 指令名
64
29
  * @param param 参数
65
- * @param handler 回调
66
- * @param taskId 仅在任务活跃时可监听,App 模式下无效
67
- */
68
- export function send(
69
- name: string,
70
- param?: string,
71
- handler?: (param?: string) => void | Promise<void>,
72
- taskId?: number
73
- ): number {
74
- if (!clickgo.getNative()) {
75
- return 0;
76
- }
77
- const id = ++sendId;
78
- sendList.push({
79
- 'id': id,
80
- 'name': name,
81
- 'param': param
82
- });
83
- if (handler) {
84
- on(name, handler, id, true, taskId);
85
- }
86
- return id;
87
- }
88
-
89
- /**
90
- * --- 监听 native 传递的指令 ---
91
- * @param name 指令名
92
- * @param handler 指令接收回调
93
- * @param id 可选,监听特定 id 的指令
94
- * @param once 可选,默认为非一次性监听
95
- * @param taskId 仅在任务活跃时可监听,App 模式下无效
96
30
  */
97
- export function on(
98
- name: string,
99
- handler: (param?: string) => void | Promise<void>,
100
- id?: number,
101
- once: boolean = false,
102
- taskId?: number
103
- ): void {
31
+ export function invoke(name: string, ...param: any[]): any {
104
32
  if (!clickgo.getNative()) {
105
33
  return;
106
34
  }
107
- if (!listeners[name]) {
108
- listeners[name] = [];
109
- }
110
- listeners[name].push({
111
- 'id': id ?? 0,
112
- 'once': once,
113
- 'taskId': taskId,
114
- 'handler': handler
115
- });
116
- }
117
-
118
- /**
119
- * --- 监听一次 native 传递的指令 ---
120
- * @param name 指令名
121
- * @param handler 指令接收回调
122
- * @param id 可选,监听特定 id 的指令
123
- * @param taskId 仅在任务活跃时可监听,App 模式下无效
124
- */
125
- export function once(
126
- name: string,
127
- handler: (param?: string) => void | Promise<void>,
128
- id?: number,
129
- taskId?: number
130
- ): void {
131
- on(name, handler, id, true, taskId);
132
- }
133
-
134
- /**
135
- * --- 取消监听 native 指令 ---
136
- * @param name 指令名
137
- * @param handler 绑定监听时的回调函数
138
- * @param taskId 校验 taskId,为空则不校验,但 App 模式下无效
139
- */
140
- export function off(name: string, handler: (param?: string) => void | Promise<void>, taskId?: number): void {
141
- if (!listeners[name]) {
142
- return;
143
- }
144
- for (let i = 0; i < listeners[name].length; ++i) {
145
- if (listeners[name][i].handler !== handler) {
146
- continue;
147
- }
148
- if (taskId && (listeners[name][i].taskId !== taskId)) {
149
- continue;
150
- }
151
- listeners[name].splice(i, 1);
152
- if (listeners[name].length === 0) {
153
- delete listeners[name];
154
- break;
155
- }
156
- --i;
157
- }
158
- }
159
-
160
- /**
161
- * --- 清除某个 task 当中的全部本地监听 ---
162
- * @param taskId 要清除的 task id,App 模式下无效
163
- */
164
- export function clearListener(taskId?: number): void {
165
- if (!taskId) {
166
- return;
167
- }
168
- for (const name in listeners) {
169
- for (let i = 0; i < listeners[name].length; ++i) {
170
- if (listeners[name][i].taskId !== taskId) {
171
- continue;
172
- }
173
- listeners[name].splice(i, 1);
174
- if (listeners[name].length === 0) {
175
- delete listeners[name];
176
- break;
177
- }
178
- }
179
- }
35
+ return (window as any).clickgoNative.invoke(name, ...param);
180
36
  }
181
37
 
182
38
  // --- 常见操作 ---
183
39
 
184
40
  export function max(): void {
185
- send('cg-set-state', JSON.stringify({
186
- 'token': token,
187
- 'state': 'max'
188
- }));
41
+ invoke('cg-set-state', token, 'max');
189
42
  }
43
+
190
44
  export function min(): void {
191
- send('cg-set-state', JSON.stringify({
192
- 'token': token,
193
- 'state': 'min'
194
- }));
195
- }
196
- export function restore(): void {
197
- send('cg-set-state', JSON.stringify({
198
- 'token': token,
199
- 'state': 'restore'
200
- }));
45
+ invoke('cg-set-state', token, 'min');
201
46
  }
202
- export function size(width: number, height: number): void {
203
- send('cg-set-size', JSON.stringify({
204
- 'token': token,
205
- 'width': width,
206
- 'height': height
207
- }));
208
- }
209
-
210
- // --- 以下为供 native 调用的内部函数 ---
211
47
 
212
- // --- send 值全部提交给 native ---
213
- export function cgInnerGetSends(): string {
214
- const json = JSON.stringify(sendList);
215
- sendList = [];
216
- return json;
48
+ export function restore(): void {
49
+ invoke('cg-set-state', token, 'restore');
217
50
  }
218
51
 
219
- // --- native 调用的回调数据(执行结果) ---
220
- export function cgInnerReceive(id: number, name: string, result?: string): void {
221
- if (!listeners[name]) {
222
- return;
223
- }
224
- for (let i = 0; i < listeners[name].length; ++i) {
225
- const item = listeners[name][i];
226
- if (item.id > 0) {
227
- if (item.id !== id) {
228
- continue;
229
- }
230
- const r = item.handler(result);
231
- if (r instanceof Promise) {
232
- r.catch(function(e) {
233
- console.log(e);
234
- });
235
- }
236
- }
237
- else {
238
- const r = item.handler(result);
239
- if (r instanceof Promise) {
240
- r.catch(function(e) {
241
- console.log(e);
242
- });
243
- }
244
- }
245
- if (item.once) {
246
- listeners[name].splice(i, 1);
247
- --i;
248
- }
249
- }
52
+ export function size(width: number, height: number): void {
53
+ invoke('cg-set-size', token, width, height);
250
54
  }
251
-
252
- (window as any).clickGoNative = {
253
- isReady: true,
254
- cgInnerGetSends: cgInnerGetSends,
255
- cgInnerReceive: cgInnerReceive
256
- };