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
@@ -9,13 +9,152 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.init = exports.read = void 0;
12
+ exports.buildComponents = exports.init = exports.read = exports.AbstractControl = void 0;
13
13
  const core = require("./core");
14
14
  const zip = require("./zip");
15
15
  const tool = require("./tool");
16
16
  const task = require("./task");
17
17
  const dom = require("./dom");
18
18
  const form = require("./form");
19
+ const fs = require("./fs");
20
+ class AbstractControl {
21
+ constructor() {
22
+ this.props = {};
23
+ }
24
+ get filename() {
25
+ return '';
26
+ }
27
+ get controlName() {
28
+ return '';
29
+ }
30
+ get taskId() {
31
+ return 0;
32
+ }
33
+ get formId() {
34
+ return 0;
35
+ }
36
+ get formFocus() {
37
+ return this.props.formFocus;
38
+ }
39
+ get path() {
40
+ return '';
41
+ }
42
+ get prep() {
43
+ return '';
44
+ }
45
+ get locale() {
46
+ return task.list[this.taskId].locale.lang || core.config.locale;
47
+ }
48
+ get l() {
49
+ return (key, data) => {
50
+ var _a, _b, _c, _d, _e, _f;
51
+ if (data) {
52
+ return (_c = (_b = (_a = data[this.locale]) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : data['en'][key]) !== null && _c !== void 0 ? _c : 'LocaleError';
53
+ }
54
+ else if (this.localeData) {
55
+ return (_f = (_e = (_d = this.localeData[this.locale]) === null || _d === void 0 ? void 0 : _d[key]) !== null && _e !== void 0 ? _e : this.localeData['en'][key]) !== null && _f !== void 0 ? _f : 'LocaleError';
56
+ }
57
+ else {
58
+ return 'LocaleError';
59
+ }
60
+ };
61
+ }
62
+ get classPrepend() {
63
+ return (cla) => {
64
+ if (typeof cla !== 'string') {
65
+ return cla;
66
+ }
67
+ return `cg-theme-task${this.taskId}-${this.controlName}_${cla}${this.prep ? (' ' + this.prep + cla) : ''}`;
68
+ };
69
+ }
70
+ watch(name, cb, opt = {}) {
71
+ return this.$watch(name, cb, opt);
72
+ }
73
+ get refs() {
74
+ return this.$refs;
75
+ }
76
+ get nextTick() {
77
+ return this.$nextTick;
78
+ }
79
+ allowEvent(e) {
80
+ return dom.allowEvent(e);
81
+ }
82
+ trigger(name, param1 = '', param2 = '') {
83
+ if (!['formTitleChanged', 'formIconChanged', 'formStateMinChanged', 'formStateMaxChanged', 'formShowChanged'].includes(name)) {
84
+ return;
85
+ }
86
+ core.trigger(name, this.taskId, this.formId, param1, param2);
87
+ }
88
+ get element() {
89
+ return this.$el;
90
+ }
91
+ emit(name, ...v) {
92
+ this.$emit(name, ...v);
93
+ }
94
+ get slots() {
95
+ return (name = 'default') => {
96
+ const d = this.$slots[name];
97
+ if (!d) {
98
+ return [];
99
+ }
100
+ const slots = [];
101
+ const list = d();
102
+ for (const item of list) {
103
+ if (typeof item.type === 'symbol') {
104
+ for (const item2 of item.children) {
105
+ slots.push(item2);
106
+ }
107
+ }
108
+ else {
109
+ slots.push(item);
110
+ }
111
+ }
112
+ return slots;
113
+ };
114
+ }
115
+ get parent() {
116
+ return this.$parent;
117
+ }
118
+ get parentByName() {
119
+ return (controlName) => {
120
+ let parent = this.$parent;
121
+ while (true) {
122
+ if (!parent) {
123
+ return null;
124
+ }
125
+ if (parent.controlName === controlName) {
126
+ return parent;
127
+ }
128
+ parent = parent.$parent;
129
+ }
130
+ };
131
+ }
132
+ onBeforeCreate() {
133
+ return;
134
+ }
135
+ onCreated() {
136
+ return;
137
+ }
138
+ onBeforeMount() {
139
+ return;
140
+ }
141
+ onMounted() {
142
+ return;
143
+ }
144
+ onBeforeUpdate() {
145
+ return;
146
+ }
147
+ onUpdated() {
148
+ return;
149
+ }
150
+ onBeforeUnmount() {
151
+ return;
152
+ }
153
+ onUnmounted() {
154
+ return;
155
+ }
156
+ }
157
+ exports.AbstractControl = AbstractControl;
19
158
  function read(blob) {
20
159
  return __awaiter(this, void 0, void 0, function* () {
21
160
  const z = yield zip.get(blob);
@@ -102,264 +241,248 @@ function read(blob) {
102
241
  });
103
242
  }
104
243
  exports.read = read;
105
- function init(taskId, formId, path, preprocess, invoke) {
244
+ function init(taskId) {
106
245
  return __awaiter(this, void 0, void 0, function* () {
107
246
  const t = task.list[taskId];
108
247
  if (!t) {
109
248
  return false;
110
249
  }
111
- const components = {};
112
- for (let cpath of t.app.config.controls) {
113
- if (!cpath.endsWith('.cgc')) {
114
- cpath += '.cgc';
115
- }
116
- const control = t.controls.loaded[cpath];
117
- if (!control) {
118
- return false;
250
+ for (let path of t.config.controls) {
251
+ if (!path.endsWith('.cgc')) {
252
+ path += '.cgc';
119
253
  }
120
- for (const name in control) {
121
- const item = control[name];
122
- let props = {};
123
- let data = {};
124
- let methods = {};
125
- let computed = {};
126
- let watch = {};
127
- let beforeCreate = undefined;
128
- let created = undefined;
129
- let beforeMount = undefined;
130
- let mounted = undefined;
131
- let beforeUpdate = undefined;
132
- let updated = undefined;
133
- let beforeUnmount = undefined;
134
- let unmounted = undefined;
135
- let layout = '', prep = '';
136
- if (t.controls.layout[name]) {
137
- layout = t.controls.layout[name];
138
- prep = t.controls.prep[name];
139
- }
140
- else {
141
- layout = item.files[item.config.layout + '.html'];
142
- if (layout === undefined) {
143
- return false;
144
- }
145
- layout = layout.replace(/^(<[a-zA-Z0-9-]+)( |>)/, '$1 data-cg-control-' + name + '$2');
146
- const style = item.files[item.config.style + '.css'];
147
- if (style) {
148
- const r = tool.stylePrepend(style);
149
- prep = r.prep;
150
- dom.pushStyle(t.id, yield tool.styleUrl2DataUrl(item.config.style, r.style, item.files), 'control', name);
151
- }
152
- const prepList = [
153
- 'cg-theme-task' + t.id.toString() + '-' + name + '_'
154
- ];
155
- if (prep !== '') {
156
- prepList.push(prep);
157
- }
158
- layout = tool.layoutAddTagClassAndReTagName(layout, false);
159
- layout = tool.layoutClassPrepend(layout, prepList);
160
- if (layout.includes('<cg-')) {
161
- layout = tool.layoutInsertAttr(layout, ':cg-focus=\'cgFocus\'', {
162
- 'include': [/^cg-.+/]
163
- });
164
- }
165
- layout = tool.eventsAttrWrap(layout);
166
- t.controls.layout[name] = layout;
167
- t.controls.prep[name] = prep;
168
- }
169
- if (item.files[item.config.code + '.js']) {
170
- item.files['/invoke/clickgo.js'] = `module.exports = invokeClickgo;`;
171
- const expo = loader.require(item.config.code, item.files, {
172
- 'dir': '/',
173
- 'invoke': invoke,
174
- 'preprocess': preprocess,
175
- 'map': {
176
- 'clickgo': '/invoke/clickgo'
254
+ path = tool.urlResolve('/', path);
255
+ const file = yield fs.getContent(path, {
256
+ 'files': t.app.files,
257
+ 'current': t.current
258
+ });
259
+ if (file && typeof file !== 'string') {
260
+ const c = yield read(file);
261
+ if (c) {
262
+ for (const name in c) {
263
+ const item = c[name];
264
+ let prep = '';
265
+ t.controls[name] = {
266
+ 'layout': '',
267
+ 'props': {
268
+ 'formFocus': {
269
+ 'default': false
270
+ }
271
+ },
272
+ 'data': {},
273
+ 'access': {},
274
+ 'methods': {},
275
+ 'computed': {}
276
+ };
277
+ t.controls[name].layout = item.files[item.config.layout + '.html'];
278
+ if (t.controls[name].layout === undefined) {
279
+ return false;
177
280
  }
178
- })[0];
179
- if (expo) {
180
- props = expo.props || {};
181
- data = expo.data || {};
182
- methods = expo.methods || {};
183
- computed = expo.computed || {};
184
- watch = expo.watch || {};
185
- beforeCreate = expo.beforeCreate;
186
- created = expo.created;
187
- beforeMount = expo.beforeMount;
188
- mounted = expo.mounted;
189
- beforeUpdate = expo.beforeUpdate;
190
- updated = expo.updated;
191
- beforeUnmount = expo.beforeUnmount;
192
- unmounted = expo.unmounted;
193
- }
194
- }
195
- props.cgFocus = {
196
- 'default': false
197
- };
198
- computed.taskId = {
199
- get: function () {
200
- return taskId;
201
- },
202
- set: function () {
203
- form.notify({
204
- 'title': 'Error',
205
- 'content': `The control tries to modify the system variable "taskId".\nPath: ${this.cgPath}\nControl: ${name}`,
206
- 'type': 'danger'
207
- });
208
- return;
209
- }
210
- };
211
- computed.controlName = {
212
- get: function () {
213
- return name;
214
- },
215
- set: function () {
216
- form.notify({
217
- 'title': 'Error',
218
- 'content': `The control tries to modify the system variable "controlName".\nPath: ${this.cgPath}\nControl: ${name}`,
219
- 'type': 'danger'
220
- });
221
- return;
222
- }
223
- };
224
- computed.cgPrep = {
225
- get: function () {
226
- return prep;
227
- },
228
- set: function () {
229
- form.notify({
230
- 'title': 'Error',
231
- 'content': `The control tries to modify the system variable "cgPrep".\nPath: ${this.cgPath}\nControl: ${name}`,
232
- 'type': 'danger'
233
- });
234
- return;
235
- }
236
- };
237
- computed.cgSlots = function () {
238
- return (name = 'default') => {
239
- const d = this.$slots[name];
240
- if (!d) {
241
- return [];
281
+ t.controls[name].layout = t.controls[name].layout.replace(/^(<[a-zA-Z0-9-]+)( |>)/, '$1 data-cg-control-' + name + '$2');
282
+ const style = item.files[item.config.style + '.css'];
283
+ if (style) {
284
+ const r = tool.stylePrepend(style);
285
+ prep = r.prep;
286
+ dom.pushStyle(t.id, yield tool.styleUrl2DataUrl(item.config.style, r.style, item.files), 'control', name);
242
287
  }
243
- const slots = [];
244
- const list = d();
245
- for (const item of list) {
246
- if (typeof item.type === 'symbol') {
247
- for (const item2 of item.children) {
248
- slots.push(item2);
249
- }
250
- }
251
- else {
252
- slots.push(item);
253
- }
288
+ const prepList = [
289
+ 'cg-theme-task' + t.id.toString() + '-' + name + '_'
290
+ ];
291
+ if (prep !== '') {
292
+ prepList.push(prep);
254
293
  }
255
- return slots;
256
- };
257
- };
258
- computed.cgLocale = function () {
259
- if (task.list[this.taskId].locale.lang === '') {
260
- return core.config.locale;
261
- }
262
- return task.list[this.taskId].locale.lang;
263
- };
264
- computed.l = function () {
265
- return (key, data) => {
266
- var _a, _b, _c, _d, _e, _f;
267
- if (data) {
268
- return (_c = (_b = (_a = data[this.cgLocale]) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : data['en'][key]) !== null && _c !== void 0 ? _c : 'LocaleError';
294
+ t.controls[name].layout = tool.layoutAddTagClassAndReTagName(t.controls[name].layout, false);
295
+ t.controls[name].layout = tool.layoutClassPrepend(t.controls[name].layout, prepList);
296
+ if (t.controls[name].layout.includes('<cg-')) {
297
+ t.controls[name].layout = tool.layoutInsertAttr(t.controls[name].layout, ':form-focus=\'formFocus\'', {
298
+ 'include': [/^cg-.+/]
299
+ });
269
300
  }
270
- else if (this.localeData) {
271
- return (_f = (_e = (_d = this.localeData[this.cgLocale]) === null || _d === void 0 ? void 0 : _d[key]) !== null && _e !== void 0 ? _e : this.localeData['en'][key]) !== null && _f !== void 0 ? _f : 'LocaleError';
301
+ t.controls[name].layout = tool.eventsAttrWrap(t.controls[name].layout);
302
+ let cls;
303
+ if (item.files[item.config.code + '.js']) {
304
+ item.files['/invoke/clickgo.js'] = `module.exports = invokeClickgo;`;
305
+ let expo = [];
306
+ try {
307
+ expo = loader.require(item.config.code, item.files, {
308
+ 'dir': '/',
309
+ 'invoke': t.invoke,
310
+ 'preprocess': function (code, path) {
311
+ const exec = /eval\W/.exec(code);
312
+ if (exec) {
313
+ form.notify({
314
+ 'title': 'Error',
315
+ 'content': `The "eval" is prohibited.\nFile: "${path}".`,
316
+ 'type': 'danger'
317
+ });
318
+ return '';
319
+ }
320
+ code = code.replace(/extends[\s\S]+?\.\s*AbstractControl\s*{/, (t) => {
321
+ return t + 'get filename() {return __filename;}';
322
+ });
323
+ return code;
324
+ },
325
+ 'map': {
326
+ 'clickgo': '/invoke/clickgo'
327
+ }
328
+ })[0];
329
+ }
330
+ catch (e) {
331
+ core.trigger('error', taskId, 0, e, e.message + '(-4)');
332
+ return false;
333
+ }
334
+ if (!(expo === null || expo === void 0 ? void 0 : expo.default)) {
335
+ const msg = '"default" not found on "' + item.config.code + '" of "' + name + '" control.';
336
+ core.trigger('error', taskId, 0, new Error(msg), msg);
337
+ return false;
338
+ }
339
+ cls = new expo.default();
272
340
  }
273
341
  else {
274
- return 'LocaleError';
342
+ cls = new (class extends AbstractControl {
343
+ get taskId() {
344
+ return taskId;
345
+ }
346
+ })();
275
347
  }
276
- };
277
- };
278
- computed.cgParentByName = function () {
279
- return (controlName) => {
280
- let parent = this.$parent;
281
- while (true) {
282
- if (!parent) {
283
- return null;
348
+ if (cls.props) {
349
+ for (const key in cls.props) {
350
+ t.controls[name].props[key] = {
351
+ 'default': cls.props[key]
352
+ };
284
353
  }
285
- if (parent.controlName === controlName) {
286
- return parent;
354
+ }
355
+ const cdata = Object.entries(cls);
356
+ for (const item of cdata) {
357
+ if (item[0] === 'access') {
358
+ t.controls[name].access = item[1];
359
+ continue;
287
360
  }
288
- parent = parent.$parent;
361
+ t.controls[name].data[item[0]] = item[1];
289
362
  }
290
- };
291
- };
292
- computed.formId = {
293
- get: function () {
294
- return formId;
295
- },
296
- set: function () {
297
- form.notify({
298
- 'title': 'Error',
299
- 'content': `The control tries to modify the system variable "formId".\nPath: ${this.cgPath}\nControl: ${name}`,
300
- 'type': 'danger'
301
- });
302
- }
303
- };
304
- computed.cgPath = {
305
- get: function () {
306
- return path;
307
- },
308
- set: function () {
309
- form.notify({
310
- 'title': 'Error',
311
- 'content': `The control tries to modify the system variable "cgPath".\nPath: ${this.cgPath}\nControl: ${name}`,
312
- 'type': 'danger'
313
- });
314
- }
315
- };
316
- methods.cgClassPrepend = function (cla) {
317
- if (typeof cla !== 'string') {
318
- return cla;
319
- }
320
- return `cg-theme-task${this.taskId}-${this.controlName}_${cla}${this.cgPrep ? (' ' + this.cgPrep + cla) : ''}`;
321
- };
322
- methods.cgAllowEvent = function (e) {
323
- return dom.allowEvent(e);
324
- };
325
- components['cg-' + name] = {
326
- 'template': layout,
327
- 'props': props,
328
- 'data': function () {
329
- return tool.clone(data);
330
- },
331
- 'methods': methods,
332
- 'computed': computed,
333
- 'watch': watch,
334
- 'beforeCreate': beforeCreate,
335
- 'created': created,
336
- 'beforeMount': beforeMount,
337
- 'mounted': function () {
338
- return __awaiter(this, void 0, void 0, function* () {
339
- yield this.$nextTick();
340
- mounted === null || mounted === void 0 ? void 0 : mounted.call(this);
341
- });
342
- },
343
- 'beforeUpdate': beforeUpdate,
344
- 'updated': function () {
345
- return __awaiter(this, void 0, void 0, function* () {
346
- yield this.$nextTick();
347
- updated === null || updated === void 0 ? void 0 : updated.call(this);
348
- });
349
- },
350
- 'beforeUnmount': function () {
351
- beforeUnmount === null || beforeUnmount === void 0 ? void 0 : beforeUnmount.call(this);
352
- },
353
- 'unmounted': function () {
354
- return __awaiter(this, void 0, void 0, function* () {
355
- yield this.$nextTick();
356
- unmounted === null || unmounted === void 0 ? void 0 : unmounted.call(this);
357
- });
363
+ const prot = tool.getClassPrototype(cls);
364
+ t.controls[name].methods = prot.method;
365
+ Object.assign(t.controls[name].computed, prot.access);
366
+ t.controls[name].computed.controlName = {
367
+ get: function () {
368
+ return name;
369
+ },
370
+ set: function () {
371
+ form.notify({
372
+ 'title': 'Error',
373
+ 'content': `The software tries to modify the system variable "controlName".\nControl: ${name}`,
374
+ 'type': 'danger'
375
+ });
376
+ return;
377
+ }
378
+ };
379
+ t.controls[name].computed.prep = {
380
+ get: function () {
381
+ return prep;
382
+ },
383
+ set: function () {
384
+ form.notify({
385
+ 'title': 'Error',
386
+ 'content': `The software tries to modify the system variable "prep".\nControl: ${name}`,
387
+ 'type': 'danger'
388
+ });
389
+ return;
390
+ }
391
+ };
358
392
  }
359
- };
393
+ }
394
+ else {
395
+ form.notify({
396
+ 'title': 'Error',
397
+ 'content': 'Control failed to load.\nTask id: ' + t.id.toString() + '\nPath: ' + path,
398
+ 'type': 'danger'
399
+ });
400
+ return false;
401
+ }
360
402
  }
361
403
  }
362
- return components;
404
+ t.invoke = undefined;
405
+ delete t.invoke;
406
+ return true;
363
407
  });
364
408
  }
365
409
  exports.init = init;
410
+ function buildComponents(taskId, formId, path) {
411
+ const t = task.list[taskId];
412
+ if (!t) {
413
+ return false;
414
+ }
415
+ const components = {};
416
+ for (const name in t.controls) {
417
+ const control = t.controls[name];
418
+ const computed = Object.assign({}, control.computed);
419
+ computed.formId = {
420
+ get: function () {
421
+ return formId;
422
+ },
423
+ set: function () {
424
+ form.notify({
425
+ 'title': 'Error',
426
+ 'content': `The control tries to modify the system variable "formId".\nControl: ${name}`,
427
+ 'type': 'danger'
428
+ });
429
+ }
430
+ };
431
+ computed.path = {
432
+ get: function () {
433
+ return path;
434
+ },
435
+ set: function () {
436
+ form.notify({
437
+ 'title': 'Error',
438
+ 'content': `The control tries to modify the system variable "path".\nControl: ${name}`,
439
+ 'type': 'danger'
440
+ });
441
+ }
442
+ };
443
+ components['cg-' + name] = {
444
+ 'template': control.layout,
445
+ 'props': control.props,
446
+ 'data': function () {
447
+ return tool.clone(control.data);
448
+ },
449
+ 'methods': control.methods,
450
+ 'computed': computed,
451
+ beforeCreate: control.methods.onBeforeCreate,
452
+ created: function () {
453
+ this.props = this.$props;
454
+ this.access = tool.clone(control.access);
455
+ this.onCreated();
456
+ },
457
+ beforeMount: function () {
458
+ this.onBeforeMount();
459
+ },
460
+ mounted: function () {
461
+ return __awaiter(this, void 0, void 0, function* () {
462
+ yield this.$nextTick();
463
+ this.onMounted();
464
+ });
465
+ },
466
+ beforeUpdate: function () {
467
+ this.onBeforeUpdate();
468
+ },
469
+ updated: function () {
470
+ return __awaiter(this, void 0, void 0, function* () {
471
+ yield this.$nextTick();
472
+ this.onUpdated();
473
+ });
474
+ },
475
+ beforeUnmount: function () {
476
+ this.onBeforeUnmount();
477
+ },
478
+ unmounted: function () {
479
+ return __awaiter(this, void 0, void 0, function* () {
480
+ yield this.$nextTick();
481
+ this.onUnmounted();
482
+ });
483
+ }
484
+ };
485
+ }
486
+ return components;
487
+ }
488
+ exports.buildComponents = buildComponents;