@cloudbase/lowcode-builder 1.8.9 → 1.8.11

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 (36) hide show
  1. package/lib/builder/config/index.d.ts +2 -2
  2. package/lib/builder/config/index.js +2 -2
  3. package/lib/builder/core/index.d.ts +1 -1
  4. package/lib/builder/core/index.js +24 -20
  5. package/lib/builder/h5/generate.d.ts +7 -1
  6. package/lib/builder/h5/generate.js +16 -8
  7. package/lib/builder/h5/webpack.js +3 -1
  8. package/lib/builder/mp/BuildContext.d.ts +4 -0
  9. package/lib/builder/mp/index.js +4 -3
  10. package/lib/builder/mp/materials.js +1 -0
  11. package/lib/builder/mp/wxml.js +10 -0
  12. package/lib/builder/util/generateFiles.d.ts +1 -1
  13. package/lib/builder/util/generateFiles.js +13 -8
  14. package/package.json +3 -3
  15. package/template/html/index.html.ejs +5 -3
  16. package/template/mp/common/{event-emitter.ts → event-emitter.js} +25 -21
  17. package/template/mp/common/{flow.ts → flow.js} +11 -50
  18. package/template/mp/common/loading/index.js +30 -0
  19. package/template/mp/common/loading/index.json +4 -0
  20. package/template/mp/common/loading/index.wxml +8 -0
  21. package/template/mp/common/loading/index.wxss +44 -0
  22. package/template/mp/common/{query.ts → query.js} +21 -85
  23. package/template/mp/common/util.js +17 -9
  24. package/template/mp/common/weapp-page.js +20 -9
  25. package/dist/builder.web.js +0 -71
  26. package/lib/.turbo/turbo-build.log +0 -0
  27. package/lib/.turbo/turbo-develop.log +0 -0
  28. package/lib/builder.web.js +0 -71
  29. package/lib/event-emitter.d.ts +0 -32
  30. package/lib/event-emitter.js +0 -88
  31. package/lib/flow.d.ts +0 -32
  32. package/lib/flow.js +0 -60
  33. package/lib/query.d.ts +0 -48
  34. package/lib/query.js +0 -171
  35. package/lib/test.d.ts +0 -11
  36. package/lib/test.js +0 -717
@@ -1,32 +0,0 @@
1
- export default class EventEmitter {
2
- constructor();
3
- on(eventName: any, listener: any): void;
4
- off(eventName: any, listener: any): void;
5
- emit(eventName: any, ...args: any[]): void;
6
- clear(): void;
7
- }
8
- export declare class Event {
9
- type: string;
10
- detail: any;
11
- /**
12
- * 类别应当为 typeof UserWidget
13
- * 当前类别为 typeof $page.widgets.xxxx
14
- * 添加上报确定用量
15
- */
16
- currentTarget: any;
17
- target?: any;
18
- /**
19
- * 内部实现
20
- * 外部不应该进行访问
21
- */
22
- _isCapturePhase: boolean;
23
- origin: Event;
24
- constructor({ type, detail, currentTarget, target, _isCapturePhase, origin, }: {
25
- type: string;
26
- currentTarget: any;
27
- target?: any;
28
- detail?: any;
29
- _isCapturePhase?: boolean;
30
- origin?: Event;
31
- });
32
- }
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Event = void 0;
4
- function checkFunc(listener) {
5
- if (!listener instanceof Function) {
6
- throw new Error(' The listener argument must be of type Function. ');
7
- }
8
- }
9
- class EventEmitter {
10
- constructor() {
11
- this.listeners = {};
12
- }
13
- on(eventName, listener) {
14
- checkFunc(listener);
15
- let listeners = this.listeners[eventName];
16
- if (!listeners) {
17
- this.listeners[eventName] = [listener];
18
- }
19
- else {
20
- listeners.push(listener);
21
- }
22
- }
23
- off(eventName, listener) {
24
- let listeners = this.listeners[eventName];
25
- if (listeners && listeners.length) {
26
- const index = listeners.indexOf(listener);
27
- index > -1 && listeners.splice(index, 1);
28
- }
29
- }
30
- emit(eventName, ...args) {
31
- let listeners = this.listeners[eventName] || [];
32
- listeners.forEach((fn) => {
33
- try {
34
- fn.call(this, ...args);
35
- }
36
- catch (err) {
37
- console.error(err);
38
- }
39
- });
40
- }
41
- clear() {
42
- this.listeners = {};
43
- }
44
- }
45
- exports.default = EventEmitter;
46
- class Event {
47
- constructor({ type = '', detail = undefined, currentTarget = undefined, target = undefined, _isCapturePhase = false, origin, }) {
48
- function proxyWrapper(target, key) {
49
- try {
50
- return new Proxy(target, {
51
- get(target, p) {
52
- if (p !== 'id') {
53
- // reportEvent(`event.${key}.${String(p)}`);
54
- }
55
- return target[p];
56
- },
57
- });
58
- }
59
- catch (e) {
60
- return target;
61
- }
62
- }
63
- this.type = type;
64
- this.detail = detail;
65
- this.currentTarget = proxyWrapper(currentTarget, 'currentTarget');
66
- this.target = proxyWrapper(target, 'target');
67
- this.origin = proxyWrapper(origin, 'origin');
68
- this._isCapturePhase = _isCapturePhase;
69
- return new Proxy(this, {
70
- get(target, prop) {
71
- switch (prop) {
72
- case 'name': {
73
- console.warn('[deprecated] event.name 将在未来版本放弃支持,请使用 event.type 替代');
74
- return target.type;
75
- }
76
- case 'origin':
77
- case 'target':
78
- case 'currentTarget': {
79
- return target[prop];
80
- break;
81
- }
82
- }
83
- return target[prop];
84
- },
85
- });
86
- }
87
- }
88
- exports.Event = Event;
package/lib/flow.d.ts DELETED
@@ -1,32 +0,0 @@
1
- declare type IGenerateContext = any;
2
- export interface IEventFlowContext extends IGenerateContext {
3
- $w?: any;
4
- target?: any;
5
- }
6
- interface IMPEventFlowGenerateOptions {
7
- looseError?: boolean;
8
- isComposite?: boolean;
9
- }
10
- export declare class EventFlow {
11
- id: string;
12
- description: string;
13
- private _eventHandlerMap;
14
- private _context;
15
- constructor({ schema, context, options, }: {
16
- schema: {
17
- id?: string;
18
- description?: string;
19
- /**
20
- * 预处理后 event handler listeners
21
- */
22
- eventHandlers?: Record<string, any>;
23
- };
24
- context: IEventFlowContext;
25
- options?: IMPEventFlowGenerateOptions;
26
- });
27
- trigger(additionalScope: any, options?: Partial<IEventFlowContext>): any;
28
- }
29
- export declare function generateEventFlows(flows: {
30
- id: string;
31
- }[] | undefined, context: IEventFlowContext, options?: IMPEventFlowGenerateOptions): {};
32
- export {};
package/lib/flow.js DELETED
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateEventFlows = exports.EventFlow = void 0;
4
- const util_1 = require("./util");
5
- const event_emitter_1 = require("./event-emitter");
6
- class EventFlow {
7
- constructor({ schema, context, options, }) {
8
- this._eventHandlerMap = {};
9
- this._context = context;
10
- const { id, description, eventHandlers = {} } = schema || {};
11
- this.id = id || '';
12
- this.description = description || '';
13
- const handlers = (0, util_1.createEventHandlers)(eventHandlers, {
14
- looseError: (options === null || options === void 0 ? void 0 : options.looseError) || false,
15
- isComposite: (options === null || options === void 0 ? void 0 : options.isComposite) || false,
16
- });
17
- this._eventHandlerMap = Object.entries(handlers).reduce((map, [key, fn]) => {
18
- map[key] = fn.bind(this);
19
- return map;
20
- }, {
21
- _getInstance: () => this._context.$page || this._context.$app,
22
- });
23
- return this;
24
- }
25
- trigger(additionalScope, options = {}) {
26
- const mergedContext = {
27
- ...this._context,
28
- ...options,
29
- };
30
- const { $w, target } = mergedContext;
31
- return this._eventHandlerMap[(0, util_1.getMpEventHandlerName)(this.id, 'start')](new event_emitter_1.Event({
32
- type: `${this.id}.start`,
33
- detail: additionalScope,
34
- target,
35
- currentTarget: target,
36
- }));
37
- // const emit = (trigger, eventData, originalEvent?) =>
38
- // generateEmit($w, target)(
39
- // trigger,
40
- // this._listenerInstances,
41
- // eventData,
42
- // forContext,
43
- // originalEvent,
44
- // scopeContext,
45
- // dataContext,
46
- // $w.page.id,
47
- // true,
48
- // );
49
- // return emit(`${this.id}.start`, additionalScope);
50
- }
51
- }
52
- exports.EventFlow = EventFlow;
53
- function generateEventFlows(flows = [], context, options) {
54
- const result = {};
55
- for (let flow of flows) {
56
- result[flow.id] = new EventFlow({ schema: flow, context, options });
57
- }
58
- return result;
59
- }
60
- exports.generateEventFlows = generateEventFlows;
package/lib/query.d.ts DELETED
@@ -1,48 +0,0 @@
1
- interface IMPDataSourceQuery {
2
- id: string;
3
- label?: string;
4
- description?: string;
5
- trigger: 'auto' | 'manual';
6
- type: 'model' | 'apis' | 'sql';
7
- dataSourceName: string;
8
- methodName: string;
9
- data: object;
10
- dataBinds: Record<string, Function>;
11
- /**
12
- * 预处理后 event handler listeners
13
- */
14
- eventHandlers?: Record<string, any>;
15
- }
16
- declare type IQueryContext = any;
17
- declare type IGenerateOptions = any;
18
- export declare class Query {
19
- private _schema;
20
- private _context;
21
- private _disposes;
22
- private _dataBinds;
23
- private _triggered;
24
- private _action;
25
- private _paramsRef;
26
- private _currentRequestKey;
27
- private _observableValue;
28
- private _eventHandlerMap;
29
- private _timer;
30
- constructor({ schema, context, options, }: {
31
- schema: IMPDataSourceQuery;
32
- context: IQueryContext;
33
- options?: IGenerateOptions;
34
- });
35
- get id(): string;
36
- get label(): string;
37
- get description(): string;
38
- get data(): any;
39
- get error(): Error | null;
40
- trigger(additionalScope?: any, options?: {}): Promise<any>;
41
- _innerTrigger(data: any, additionalScope?: any, options?: {}): Promise<any>;
42
- private _debounceTrigger;
43
- destroy(): void;
44
- private _resolveParams;
45
- private _emit;
46
- }
47
- export declare function generateDatasetQuery(schema: any, context: IQueryContext, options: IGenerateOptions): {};
48
- export {};
package/lib/query.js DELETED
@@ -1,171 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateDatasetQuery = exports.Query = void 0;
4
- const mobx_1 = require("mobx");
5
- const util_1 = require("./util");
6
- const event_emitter_1 = require("./event-emitter");
7
- class Query {
8
- constructor({ schema, context, options = {}, }) {
9
- var _a, _b;
10
- this._disposes = [];
11
- this._dataBinds = {};
12
- this._triggered = false;
13
- this._paramsRef = (0, mobx_1.observable)({ current: null });
14
- this._currentRequestKey = null;
15
- this._observableValue = (0, mobx_1.observable)({ data: null, error: null });
16
- this._eventHandlerMap = {};
17
- const { looseError = false, useScopeWidgetData = false } = options;
18
- const { $w, $app, $page } = context;
19
- this._schema = schema;
20
- this._context = context;
21
- if (((_a = this._schema) === null || _a === void 0 ? void 0 : _a.trigger) === 'auto') {
22
- this._disposes.push((0, mobx_1.autorun)((r) => {
23
- try {
24
- const data = this._resolveParams();
25
- if (this._triggered) {
26
- this._debounceTrigger(data);
27
- }
28
- }
29
- catch (e) {
30
- console.error(e);
31
- }
32
- }, { delay: 50 }));
33
- }
34
- const baseParam = {
35
- dataSourceName: this._schema.dataSourceName,
36
- };
37
- if (((_b = this._schema) === null || _b === void 0 ? void 0 : _b.type) === 'sql') {
38
- baseParam.sqlTemplateId = this._schema.methodName;
39
- }
40
- else {
41
- baseParam.methodName = this._schema.methodName;
42
- }
43
- this._paramsRef.current = this._schema.data;
44
- this._dataBinds = this._schema.dataBinds;
45
- this._action = async (data) => {
46
- return $w.cloud.callDataSource({
47
- ...baseParam,
48
- params: data,
49
- });
50
- };
51
- this._eventHandlerMap = Object.entries((0, util_1.createEventHandlers)(this._schema.eventHandlers || {}, {
52
- looseError: looseError,
53
- isComposite: false,
54
- })).reduce((map, [key, fn]) => {
55
- map[key] = fn.bind(this);
56
- return map;
57
- }, {
58
- _getInstance: () => this._context.$page || this._context.$app,
59
- });
60
- // this._emit = async (trigger, eventData, originalEvent?) =>
61
- // generateEmit($w)(
62
- // trigger,
63
- // generateListnerInstances(
64
- // {
65
- // $app,
66
- // $page,
67
- // actionsMap: (this._context as any).actionsMap,
68
- // },
69
- // this._schema.listeners || [],
70
- // ),
71
- // eventData,
72
- // {},
73
- // originalEvent,
74
- // {},
75
- // {},
76
- // $w.page.id,
77
- // true,
78
- // );
79
- return this;
80
- }
81
- get id() {
82
- var _a;
83
- return ((_a = this._schema) === null || _a === void 0 ? void 0 : _a.id) || '';
84
- }
85
- get label() {
86
- var _a;
87
- return ((_a = this._schema) === null || _a === void 0 ? void 0 : _a.label) || '';
88
- }
89
- get description() {
90
- var _a;
91
- return ((_a = this._schema) === null || _a === void 0 ? void 0 : _a.description) || '';
92
- }
93
- get data() {
94
- return this._observableValue.data;
95
- }
96
- get error() {
97
- return this._observableValue.error;
98
- }
99
- async trigger(additionalScope, options = {}) {
100
- this._triggered = true;
101
- return this._innerTrigger(this._resolveParams(), additionalScope, options);
102
- }
103
- async _innerTrigger(data, additionalScope, options = {}) {
104
- this._currentRequestKey = Date.now();
105
- const key = this._currentRequestKey;
106
- try {
107
- const res = await this._action(data);
108
- if (key === this._currentRequestKey) {
109
- this._observableValue.data = res;
110
- this._observableValue.error = null;
111
- this._emit(`success`, res);
112
- }
113
- return res;
114
- }
115
- catch (e) {
116
- if (key === this._currentRequestKey) {
117
- this._observableValue.data = null;
118
- this._observableValue.error = e;
119
- this._emit(`fail`, e);
120
- }
121
- throw e;
122
- }
123
- }
124
- _debounceTrigger(...args) {
125
- if (this._timer) {
126
- clearTimeout(this._timer);
127
- }
128
- this._timer = setTimeout(() => {
129
- this._innerTrigger(...args);
130
- }, 300);
131
- }
132
- destroy() {
133
- this._disposes.forEach((dispose) => dispose());
134
- }
135
- _resolveParams() {
136
- var _a;
137
- /**
138
- * 这里万一其中某个字段计算失败
139
- * 好像会阻塞其他字段的计算
140
- * 从而导致 autorun 没有添加依赖
141
- */
142
- return (_a = (0, util_1.mergeDynamic2StaticData)((0, mobx_1.toJS)(this._paramsRef.current), this._dataBinds, {
143
- codeContext: {
144
- /**
145
- * $page 或 $comp 实例
146
- */
147
- instance: this._context.$page,
148
- },
149
- $w: this._context.$w,
150
- // may be additional scope
151
- })) === null || _a === void 0 ? void 0 : _a.params;
152
- }
153
- async _emit(eventName, data) {
154
- var _a, _b;
155
- return (_b = (_a = this._eventHandlerMap)[(0, util_1.getMpEventHandlerName)(this.id, eventName)]) === null || _b === void 0 ? void 0 : _b.call(_a, new event_emitter_1.Event({
156
- type: eventName,
157
- detail: data,
158
- target: undefined,
159
- currentTarget: undefined,
160
- }));
161
- }
162
- }
163
- exports.Query = Query;
164
- function generateDatasetQuery(schema, context, options) {
165
- const result = {};
166
- for (const key in schema) {
167
- result[key] = new Query({ schema: schema[key], context, options });
168
- }
169
- return result;
170
- }
171
- exports.generateDatasetQuery = generateDatasetQuery;
package/lib/test.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare function resolveWidgetData(props: any): any;
2
- export declare function createWidgets(widgetProps: any, dataBinds: any, ownerMpInst: any): {
3
- widgets: {};
4
- rootWidget: any;
5
- };
6
- export declare function generateForContextOfWidget(widget: any): any;
7
- export declare const ID_SEPARATOR = "-";
8
- export declare function getWidget(widgets: any, id: any): any;
9
- export declare function disposeWidget(widget: any, noRecursive?: boolean): void;
10
- export declare function createInitData(widgets: any, dataBinds: any, keyPrefix?: string): {};
11
- export declare function generateWidgetAPIContext($w: {} | undefined, widget: any, forContext: any): {};