@cloudbase/lowcode-builder 1.8.106 → 1.8.108

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 (48) hide show
  1. package/lib/builder/config/dependencies.d.ts +10 -0
  2. package/lib/builder/config/dependencies.js +46 -0
  3. package/lib/builder/config/index.d.ts +1 -0
  4. package/lib/builder/config/index.js +5 -3
  5. package/lib/builder/core/index.d.ts +1 -1
  6. package/lib/builder/core/index.js +13 -13
  7. package/lib/builder/h5/generate.js +1 -0
  8. package/lib/builder/mp/BuildContext.d.ts +1 -0
  9. package/lib/builder/mp/index.d.ts +1 -2
  10. package/lib/builder/mp/index.js +13 -38
  11. package/lib/builder/mp/lowcode.js +5 -1
  12. package/lib/builder/mp/materials.d.ts +2 -3
  13. package/lib/builder/mp/materials.js +28 -26
  14. package/lib/builder/mp/mp_config.js +2 -1
  15. package/lib/builder/mp/util.d.ts +5 -2
  16. package/lib/builder/mp/util.js +14 -6
  17. package/lib/builder/mp/wxml.d.ts +3 -1
  18. package/lib/builder/mp/wxml.js +20 -7
  19. package/lib/builder.web.js +8 -8
  20. package/package.json +4 -4
  21. package/template/html/index.html.ejs +4 -2
  22. package/template/mp/app/common.js +0 -2
  23. package/template/mp/app/weapps-api.js +1 -20
  24. package/template/mp/common/info/index.js +4 -2
  25. package/template/mp/common/util.js +33 -774
  26. package/template/mp/common/weapp-page.js +12 -514
  27. package/template/mp/component/index.js +52 -19
  28. package/template/mp/component/index.json +1 -1
  29. package/template/mp/datasources/index.js.tpl +3 -99
  30. package/template/mp/package.json +4 -15
  31. package/template/mp/packages/$wd_system/pages/login/index.json +1 -1
  32. package/template/mp/packages/$wd_system/pages/login/methods/loginByWXPhone.js +6 -3
  33. package/template/mp/page/index.js +1 -2
  34. package/template/mp/common/constant.js +0 -1
  35. package/template/mp/common/data-patch-test.js +0 -60
  36. package/template/mp/common/data-patch.js +0 -66
  37. package/template/mp/common/event-emitter.js +0 -124
  38. package/template/mp/common/flow.js +0 -65
  39. package/template/mp/common/merge-renderer.js +0 -75
  40. package/template/mp/common/placeholder/index.js +0 -1
  41. package/template/mp/common/placeholder/index.json +0 -4
  42. package/template/mp/common/placeholder/index.wxml +0 -1
  43. package/template/mp/common/placeholder/index.wxss +0 -1
  44. package/template/mp/common/query.js +0 -300
  45. package/template/mp/common/style.js +0 -34
  46. package/template/mp/common/watch.js +0 -70
  47. package/template/mp/common/weapp-component.js +0 -289
  48. package/template/mp/common/widget.js +0 -872
@@ -1,300 +0,0 @@
1
- import { observable, autorun, toJS } from 'mobx';
2
- import { createEventHandlers, getMpEventHandlerName, mergeDynamic2StaticData } from './util';
3
- import { Event } from './event-emitter';
4
-
5
-
6
- const QUERY_RESOURCE = {
7
- SQL : 'mysql-plugin',
8
- SQLSERVER : 'mssql-plugin',
9
- CLOUDCONNECTOR : 'apis-plugin',
10
- }
11
-
12
- const QUERY_PATH = {
13
- SQL : '/WeDa/Query/V1/RunPluginQuery',
14
- SQLSERVER : '/WeDa/Query/V1/RunPluginQuery',
15
- CLOUDCONNECTOR : '/WeDa/Connector/v1/RunApisQuery',
16
- }
17
-
18
- const KEYS = ['id', 'label', 'description', 'data', 'error', 'isFetching', 'trigger', 'reset'];
19
-
20
- const GENERALFUNC = 'general-func'
21
-
22
- export class Query {
23
- _schema = {};
24
- #schema;
25
- #context = {};
26
- #disposes = [];
27
- #dataBinds = {};
28
- #triggered = false;
29
- initPromise;
30
- #initedResolver = (value) => {};
31
- #paramsRef = observable({ current: null });
32
- #currentRequestKey = null;
33
- #observableValue = observable({ data: null, error: null, isFetching: false });
34
- #eventHandlerMap = {};
35
- #action = () => {};
36
- #runQueryMap = {
37
- sql: { QueryResource: QUERY_RESOURCE.SQL, QueryPath: QUERY_PATH.SQL },
38
- sqlserver: { QueryResource: QUERY_RESOURCE.SQLSERVER, QueryPath: QUERY_PATH.SQLSERVER },
39
- 'cloud-connector': { QueryResource: QUERY_RESOURCE.CLOUDCONNECTOR, QueryPath: QUERY_PATH.CLOUDCONNECTOR },
40
- };
41
- constructor({ schema, context, options = {} }) {
42
- const { looseError = false } = options;
43
- this.#schema = schema;
44
- this._schema = {
45
- trigger: schema.trigger,
46
- };
47
- this.#context = context;
48
-
49
- this.initPromise = new Promise((resolve) => {
50
- this.#initedResolver = resolve;
51
- });
52
-
53
- if (this.#schema?.trigger === 'auto') {
54
- this.#disposes.push(
55
- autorun(
56
- (r) => {
57
- try {
58
- const data = this.#resolveParams({}, { combainErrors: true });
59
- if (this.#triggered) {
60
- this.#debounceTrigger(data);
61
- }
62
- } catch (e) {
63
- console.error(e);
64
- } finally {
65
- this.#initedResolver(true);
66
- }
67
- },
68
- { delay: 50 },
69
- ),
70
- );
71
- } else {
72
- this.#initedResolver(true);
73
- }
74
- this.#paramsRef.current = this.#schema.data;
75
- this.#dataBinds = Object.entries(this.#schema.dataBinds || {}).reduce((map, [prop, fn]) => {
76
- if (!/[\s+\-*/!&|%]*?SERVER\./.test(prop)) {
77
- map[prop] = fn;
78
- }
79
- return map;
80
- }, {});
81
-
82
- const { $w } = this.#context;
83
-
84
- const runQueryType = async function (data) {
85
- const requestData = {
86
- EnvId: $w.env.envId,
87
- Name: data.sqlTemplateId,
88
- Parameter: JSON.stringify(
89
- Object.entries(data.params || {}).reduce((list, [key, value]) => {
90
- if (value !== undefined) {
91
- let type = 'OBJECT';
92
- const typeofValue = typeof value;
93
- switch (typeofValue) {
94
- case 'boolean': {
95
- type = 'BOOLEAN';
96
- break;
97
- }
98
- case 'number': {
99
- type = 'NUMBER';
100
- break;
101
- }
102
- case 'string': {
103
- type = 'STRING';
104
- break;
105
- }
106
- default: {
107
- if (Array.isArray(value)) {
108
- type = 'ARRAY';
109
- } else {
110
- type = 'OBJECT';
111
- }
112
- }
113
- }
114
-
115
- list.push({
116
- Key: key,
117
- Type: type,
118
- Value: type === 'STRING' ? value : JSON.stringify(value),
119
- });
120
- }
121
-
122
- return list;
123
- }, []) || [],
124
- ),
125
- };
126
-
127
- const Data = await $w.cloud.callWedaApi({
128
- action: 'RunQuery',
129
- CallQuery: true,
130
- ...(this.#runQueryMap[this.#schema.type] || this.#runQueryMap['sql']),
131
- EnvId: requestData.EnvId,
132
- QueryName: requestData.Name,
133
- data: requestData,
134
- });
135
-
136
- // const Data = await $w.cloud.callWedaApi({
137
- // action: 'RunPluginQuery',
138
- // data: {
139
- // MainAppId: $w.app.id,
140
- // ...requestData
141
- // },
142
- // });
143
-
144
- const { ExecuteResultList = [], Total, Payload } = Data || {};
145
-
146
- let payload = Payload;
147
- try {
148
- if (Payload) {
149
- payload = JSON.parse(Payload);
150
- }
151
- } catch (e) {}
152
- return {
153
- ...(this.#schema.type === 'cloud-connector'
154
- ? payload
155
- : {
156
- records: ExecuteResultList.map((item) => JSON.parse(item)),
157
- total: Total || ExecuteResultList.length,
158
- }),
159
- };
160
- }
161
-
162
- this.#action = async function (data,additionalScope){
163
- return this.#isRunQueryType
164
- ? runQueryType.call(this,data)
165
- : this.#schema.type === GENERALFUNC
166
- ? this.#schema.handler.call(this,data,additionalScope)
167
- : this.#schema.handler.call(this,data);
168
- }
169
-
170
-
171
- this.#eventHandlerMap = Object.entries(
172
- createEventHandlers(this.#schema.eventHandlers || {}, {
173
- looseError: looseError,
174
- isComposite: false,
175
- }),
176
- ).reduce(
177
- (map, [key, fn]) => {
178
- // map[key] = fn.bind(this);
179
- map[key] = fn;
180
- return map;
181
- },
182
- {
183
- _getInstance: () => this.#context.$page || this.#context.$app,
184
- },
185
- );
186
- return this;
187
- }
188
- get id() {
189
- return this.#schema?.id || '';
190
- }
191
- get label() {
192
- return this.#schema?.label || '';
193
- }
194
- get description() {
195
- return this.#schema?.description || '';
196
- }
197
- get data() {
198
- return this.#observableValue.data;
199
- }
200
- get error() {
201
- return this.#observableValue.error;
202
- }
203
- get isFetching() {
204
- return this.#observableValue.isFetching;
205
- }
206
- get #isRunQueryType() {
207
- return !!this.#runQueryMap[this.#schema.type];
208
- }
209
- async trigger(additionalScope, options = {}) {
210
- this.#triggered = true;
211
- return this.#innerTrigger(this.#resolveParams(additionalScope),additionalScope, options);
212
- }
213
- reset() {
214
- this.#observableValue.data = null;
215
- this.#observableValue.error = null;
216
- this.#observableValue.isFetching = false;
217
- }
218
- destroy() {
219
- this.#disposes.forEach((dispose) => dispose());
220
- }
221
-
222
- /**
223
- * 用于调试
224
- */
225
- _toSchema() {
226
- console.warn('调试使用,结构可能发生更改,请不要用于生产环境');
227
- return this.#schema;
228
- }
229
-
230
- async #innerTrigger(args, additionalScope,options = {}) {
231
- this.#currentRequestKey = Date.now();
232
- const key = this.#currentRequestKey;
233
- try {
234
- this.#observableValue.isFetching = true;
235
- const res = await this.#action(args?.[0],additionalScope);
236
- if (key === this.#currentRequestKey) {
237
- this.#observableValue.isFetching = false;
238
- this.#observableValue.data = res;
239
- this.#observableValue.error = null;
240
- this.#emit(`success`, res);
241
- }
242
- return res;
243
- } catch (e) {
244
- if (key === this.#currentRequestKey) {
245
- this.#observableValue.isFetching = false;
246
- this.#observableValue.data = null;
247
- this.#observableValue.error = e;
248
- this.#emit(`fail`, e);
249
- }
250
- throw e;
251
- }
252
- }
253
- #debounceTrigger(...args) {
254
- if (this._timer) {
255
- clearTimeout(this._timer);
256
- }
257
- this._timer = setTimeout(() => {
258
- this.#innerTrigger(...args);
259
- }, 300);
260
- }
261
-
262
- #resolveParams(additionalScope = {}, options = {}) {
263
- /**
264
- * 这里万一其中某个字段计算失败
265
- * 好像会阻塞其他字段的计算
266
- * 从而导致 autorun 没有添加依赖
267
- */
268
- let { params = [] } =
269
- mergeDynamic2StaticData(toJS(this.#paramsRef.current), this.#dataBinds, {
270
- $w: this.#context.$w,
271
- paramsContext: additionalScope,
272
- }, options?.combainErrors) || {};
273
-
274
- return params;
275
- }
276
- async #emit(eventName, data) {
277
- return this.#eventHandlerMap[getMpEventHandlerName(this.id, eventName)]?.(
278
- new Event({
279
- type: eventName,
280
- detail: data,
281
- target: undefined,
282
- currentTarget: undefined,
283
- }),
284
- );
285
- }
286
-
287
- toJSON() {
288
- return KEYS.reduce((obj, key) => {
289
- obj[key] = this[key];
290
- return obj;
291
- }, {});
292
- }
293
- }
294
- export function generateDatasetQuery(schema, context, options) {
295
- const result = {};
296
- for (const key in schema) {
297
- result[key] = new Query({ schema: schema[key], context, options });
298
- }
299
- return result;
300
- }
@@ -1,34 +0,0 @@
1
- import { toDash } from './util'
2
- /**
3
- * Convert HtmlElement.style object to css declarations
4
- */
5
- export function styleToCss(style) {
6
- const styleDeclars = [] // ['color: red;', 'background-color: green']
7
- for (const key in style) {
8
- styleDeclars.push(`${/^--/.test(key) ? key : toDash(key)}:${style[key]};`)
9
- }
10
- return styleDeclars.join('')
11
- }
12
-
13
- export function concatClassList(classList1 = [], classList2 = []) {
14
- if (!Array.isArray(classList1)) {
15
- classList1 = [classList1]
16
- }
17
- if (!Array.isArray(classList2)) {
18
- classList2 = [classList2]
19
- }
20
- return classList1.concat(classList2)
21
- }
22
-
23
- export function px2rpx(object) {
24
- let reg = /\b(\d+(\.\d+)?)px\b/g
25
- for (const key in object) {
26
- let value = object[key]
27
- if (typeof value === 'string') {
28
- object[key] = value.replace(reg, function (item, value) {
29
- return `${value}rpx`
30
- })
31
- }
32
- }
33
- return object
34
- }
@@ -1,70 +0,0 @@
1
- import { autorun, reaction } from 'mobx'
2
- import { getDeep } from './util'
3
- import { getDatasetProfiles, setLocalDatasetState } from './cloud-sdk';
4
-
5
- /**
6
- *
7
- * @param {*} param
8
- * @returns Dipsonsers
9
- */
10
- export function runWatchers({ watchEffects = {}, watch = {}, watchState = {}, watchWidget = {} }, mpInst) {
11
- const weappInst = mpInst._getInstance()
12
- const disposers = []
13
- Object.keys(watchEffects).map(name => {
14
- const fn = watchEffects[name]
15
- if (fn instanceof Function) {
16
- disposers.push(autorun(fn.bind(weappInst)))
17
- } else {
18
- console.error(`WatchEffect(${name}) of ${mpInst.is} is not a function.`)
19
- }
20
- })
21
-
22
- // # watch props
23
- Object.keys(watch).map(key => runWatcher(parseWatcher(watch[key]), weappInst.node, key, 'watch'))
24
-
25
- // # watch state
26
- Object.keys(watchState).map(key => runWatcher(parseWatcher(watchState[key]), weappInst.state, key, 'watchState'))
27
-
28
- // # watch widgets
29
- Object.keys(watchWidget).map(key => runWatcher(parseWatcher(watchWidget[key]), weappInst.widgets, key, 'watchWidgets'))
30
-
31
- return disposers
32
-
33
- function runWatcher({ handler, immediate } = {}, target, key, label) {
34
- if (!handler) {
35
- console.error(`Invalid ${label}(${key}) of ${mpInst.is}, watch must a function or {handler: function}`)
36
- return
37
- }
38
- const disposer = reaction(() => getDeep(target, key), handler.bind(weappInst), { fireImmediately: immediate })
39
- disposers.push(disposer)
40
- }
41
- }
42
-
43
- function parseWatcher(watcher) {
44
- if (!watcher) return
45
- if (watcher instanceof Function) {
46
- return { handler: watcher, immediate: false }
47
- }
48
- const { handler, immediate = false } = watcher
49
- if (!(handler instanceof Function)) return
50
- return { handler, immediate }
51
- }
52
-
53
- export function watchAndSyncDatasetState2Local(appId, datasetProfileKey, dataset) {
54
- const disposes = [];
55
- const stateProfile = getDatasetProfiles(datasetProfileKey)?.state || {};
56
- for (const key in stateProfile) {
57
- const config = stateProfile[key];
58
- if (config.enableSyncLocal) {
59
- const dispose = autorun((r) => {
60
- try {
61
- setLocalDatasetState(appId, datasetProfileKey, key, dataset[key]);
62
- } catch (e) {
63
- console.error('setLocalDatasetState error:', e);
64
- }
65
- });
66
- disposes.push(dispose);
67
- }
68
- }
69
- return disposes;
70
- }
@@ -1,289 +0,0 @@
1
- import { observable } from 'mobx'
2
- import { createEventHandlers, createComputed, patchWdigetPropsWithEvtListeners } from './util'
3
- import { createWidgets, getWidget, disposeWidget } from './widget'
4
- import mergeRenderer from './merge-renderer'
5
- import { runWatchers } from './watch'
6
- import lodashGet from 'lodash.get';
7
- import { createInitData, createWidget } from './widget';
8
- import { commonCompBehavior, getWedaAPI } from '@cloudbase/weda-client';
9
-
10
- /**
11
- * Lowcodes of all components
12
- */
13
- export const compLowcodes = {}
14
-
15
- export function createComponent(key, behaviors, properties={}, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes, libCode) {
16
- widgetProps = patchWdigetPropsWithEvtListeners(widgetProps, evtListeners)
17
-
18
- compLowcodes[key] = {
19
- index,
20
- stateFn,
21
- computedFuncs,
22
- handler,
23
- // events,
24
- lib: libCommonRes,
25
- config,
26
- }
27
-
28
- return Component({
29
- options: {
30
- virtualHost: true,
31
- multipleSlots: true,
32
- styleIsolation: 'shared',
33
- },
34
- /**
35
- * commonCompBehavior 生命周期最先执行
36
- */
37
- behaviors: [commonCompBehavior, ...behaviors,],
38
- // externalClasses: ['class'],
39
- properties: {
40
- style: {
41
- type: String
42
- },
43
- className: {
44
- type: String,
45
- },
46
- ...properties,
47
- },
48
-
49
- data: createInitData(widgetProps, dataBinds, ''),
50
-
51
- lifetimes: {
52
- created() {
53
- this._pageActive = true
54
- this._disposers = []
55
- this._nativeObserver = false
56
- this._nativeMode = <%= !!nativeMode %>
57
- },
58
- attached() {
59
- const $comp = this._getInstance()
60
- if(!$comp) return
61
- $comp.__internal__.active = this._pageActive
62
-
63
- $comp.props.events = createPropEvents(events, this)
64
- const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBinds, this, $comp.widgets)
65
- $comp.widgets = widgets
66
- this._virtualRootWidget = virtualRootWidget
67
-
68
- try {
69
- lifeCycle.onAttached && lifeCycle.onAttached.call($comp)
70
- this.__mnt__ = (e) => {
71
- const widget = getWidget($comp.widgets, e.target.id)
72
- widget._methods = e.detail.methods;
73
- }
74
- this.__unmnt__ = (e) => {
75
- const widget = lodashGet($comp.widgets, e.target.id);
76
- widget._methods = {}
77
- }
78
- if ($comp.methods) {
79
- this.triggerEvent('attached', {
80
- 'methods': $comp.methods
81
- })
82
- }
83
- } catch (e) {
84
- console.error('Component lifecycle(attached) error', this.is, e)
85
- }
86
-
87
- this._disposers = this.initMergeRenderer($comp.widgets)
88
- },
89
- ready() {
90
- const $comp = this._getInstance()
91
- if(!$comp) return
92
- this._disposers.push(...runWatchers(index, this))
93
- lifeCycle.onReady && lifeCycle.onReady.call($comp)
94
- },
95
- detached() {
96
- const $comp = this._getInstance()
97
- if(!$comp) return
98
- this._pageActive = false
99
- $comp.__internal__.active = this._pageActive
100
-
101
- $comp.widgets = null
102
- $comp.node._eventListeners?.clear?.();
103
- disposeWidget(this._virtualRootWidget)
104
- this._disposers.forEach(dispose => dispose())
105
- lifeCycle.onDetached && lifeCycle.onDetached.call($comp)
106
- if ($comp?.methods) {
107
- this.triggerEvent('detached');
108
- }
109
- }
110
- },
111
-
112
- pageLifetimes: {
113
- show() {
114
- const $comp = this._getInstance()
115
- if(!$comp) return
116
- lifeCycle.onPageShow && lifeCycle.onPageShow.call($comp)
117
- },
118
- hide() {
119
- const $comp = this._getInstance()
120
- if(!$comp) return
121
- lifeCycle.onPageHide && lifeCycle.onPageHide.call($comp)
122
- },
123
- resize(size) {
124
- const $comp = this._getInstance()
125
- if(!$comp) return
126
- lifeCycle.onPageResize && lifeCycle.onPageResize.call($comp, size)
127
- }
128
- },
129
-
130
- methods: {
131
- ...createEventHandlers(evtListeners, { looseError: true, isComposite: true }),
132
- ...mergeRenderer,
133
- _getInstance() {
134
- if (!this.$WEAPPS_COMP) {
135
- let widget = this.$node
136
- if (!widget) {
137
- if ((this.selectOwnerComponent && !this.selectOwnerComponent?.()) || this._nativeMode) {
138
- const widgetValue = {}
139
- for (const key in properties) {
140
- if (properties[key]?.value !== undefined) {
141
- widgetValue[key] = properties[key]?.value
142
- }
143
- if (this.data[key] !== undefined) {
144
- widgetValue[key] = this.data[key]
145
- }
146
- }
147
- this.$node = createWidget({ widgetType: key, ...widgetValue }, this.id || `id${Date.now()}`, '', undefined, {})
148
- widget = this.$node
149
- this._nativeObserver = true;
150
- } else {
151
- console.error('Fatal error: weapps component instance not created', this.is, this.id);
152
- return
153
- }
154
- }
155
- widget.getDom = (fields) => this._virtualRootWidget.children[0].getDom(fields)
156
- this.$WEAPPS_COMP = create$comp(widget)
157
- }
158
- return this.$WEAPPS_COMP
159
- },
160
- },
161
- observers: createObservers(Object.keys(properties))
162
- })
163
- }
164
-
165
- // The component instance for lowcode
166
- function create$comp(w) {
167
- const lowcode = compLowcodes[w.widgetType]
168
- if (!lowcode) {
169
- return
170
- }
171
- const { stateFn, computedFuncs, handler, lib } = lowcode
172
-
173
- const $comp = {
174
- __internal__: {
175
- },
176
- state: {},
177
- computed: {},
178
- widgets: {},
179
- node: w || {},
180
- props: {
181
- data: w || {},
182
- events: {},
183
- get style() { return w.style },
184
- get classList() { return w.classList },
185
- },
186
- handler: {},
187
- lib
188
- }
189
- $comp.$WEAPPS_COMP = $comp // TODO $comp will replaced to this.$WEAPPS_COMP
190
- $comp.computed = createComputed(computedFuncs, $comp)
191
- $comp.handler = Object.keys(handler).reduce((result, key) => {
192
- result[key] = handler[key].bind($comp)
193
- return result
194
- }, {})
195
- $comp.state = observable(stateFn.call($comp)) // May depend on this.props.data.xxx
196
-
197
-
198
- $comp.__internal__.$w = new Proxy(
199
- getWedaAPI()?.$w || {},
200
- {
201
- get(target, prop) {
202
- if (prop === '$comp') {
203
- return $comp
204
- }
205
- // 尝试代理组件级别组件实例
206
- const childWidget = $comp.widgets?.[prop];
207
- if (childWidget) {
208
- return childWidget._userWidget;
209
- }
210
- return target[prop]
211
- },
212
- },
213
- );
214
-
215
- return $comp
216
- }
217
-
218
- function createObservers(props) {
219
- const MAP = {
220
- className: {
221
- alias: 'classList',
222
- format: function(value='') {
223
- return Array.from(new Set(value.split(' ').filter(item=>!!item)))
224
- }
225
- },
226
- }
227
- return props.reduce((observers, prop) => {
228
- observers[prop] = function (value) {
229
- if (!this._nativeObserver) {
230
- return;
231
- }
232
- const $comp = this._getInstance()
233
- if ($comp) {
234
- const data = $comp.props.data || {}
235
- const dataKey = MAP[prop]?.alias || prop;
236
- const formatValue = MAP[prop]?.format ? MAP[prop].format(value) : value;
237
- // if (!deepEqual(data[prop], formatValue)) {
238
- data[dataKey] = formatValue
239
- // } else {
240
- // // console.log(`Same comp prop will not trigger observer. ${prop}->${dataKey}`, formatValue)
241
- // }
242
- }
243
- }
244
- return observers
245
- }, {})
246
- }
247
-
248
- function dataBindsBindContext(dataBinds, self) {
249
- return Object.keys(dataBinds).reduce((result, widgetId) => {
250
- result[widgetId] = Object.keys(dataBinds[widgetId]).reduce((result, prop) => {
251
- result[prop] = dataBinds[widgetId][prop].bind(self)
252
- return result
253
- }, {})
254
- return result
255
- }, {})
256
- }
257
-
258
- function createPropEvents(events, mpInst) {
259
- const protectEventKeys = [
260
- 'touchstart', // 手指触摸动作开始
261
- 'touchmove', // 手指触摸后移动
262
- 'touchcancel', // 手指触摸动作被打断,如来电提醒,弹窗
263
- 'touchend', // 手指触摸动作结束
264
- 'tap', // 手指触摸后马上离开
265
- 'longpress', // 手指触摸后,超过350ms再离开,如果指定了事件回调函数并触发了这个事件,tap事件将不被触发 1.5.0
266
- 'longtap', // 手指触摸后,超过350ms再离开(推荐使用longpress事件代替)
267
- 'transitionend', // 会在 WXSS transition 或 wx.createAnimation 动画结束后触发
268
- 'animationstart', // 会在一个 WXSS animation 动画开始时触发
269
- 'animationiteration', // 会在一个 WXSS animation 一次迭代结束时触发
270
- 'animationend', // 会在一个 WXSS animation 动画完成时触发
271
- 'touchforcechange', // 在支持 3D Touch 的 iPhone 设备,重按时会触发
272
- ]
273
- const result = {}
274
- events.forEach(evt => {
275
- const isProtectKey = protectEventKeys.some(key => key === evt.name)
276
- if (isProtectKey) {
277
- result[evt.name] = function () { }
278
- } else {
279
- result[evt.name] = function (evtDetail) {
280
- if (evt.getValueFromEvent) {
281
- mpInst.setData({ value: evt.getValueFromEvent({ detail: evtDetail }) })
282
- }
283
- mpInst.triggerEvent(evt.name, evtDetail)
284
- mpInst._getInstance().node?._eventListeners?.emit?.(evt.name, evtDetail)
285
- }
286
- }
287
- })
288
- return result
289
- }