@cloudbase/lowcode-builder 0.1.5-mp-beta → 0.1.5-mpbeta.2

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.
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "0.1.5-mp-beta",
3
+ "version": "0.1.5-mpbeta.2",
4
4
  "description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
5
5
  "author": "yhsunshining@gmail.com",
6
6
  "homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
@@ -25,28 +25,28 @@
25
25
  "scripts": {
26
26
  "dev": "tsc -w",
27
27
  "develop": "tsc -w",
28
- "build": "rm -rf lib && tsc",
28
+ "build": "rm -rf lib && tsc && npm run build:web",
29
29
  "test": "jest",
30
30
  "test:build": "ts-node ./__test__/build.ts",
31
- "dev:mpweb": "rm -rf dist && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/mpweb.config.js",
32
- "build:mpweb": "rm -rf dist && cross-env NODE_ENV=production webpack --config ./webpack/mpweb.config.js"
31
+ "dev:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/web.config.js",
32
+ "build:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=production webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js"
33
33
  },
34
34
  "bugs": {
35
35
  "url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
36
36
  },
37
37
  "dependencies": {
38
38
  "@cloudbase/cals": "^0.3.3",
39
- "@cloudbase/lowcode-generator": "0.4.22-mp-beta",
39
+ "@cloudbase/lowcode-generator": "0.6.17-mpbeta.1",
40
40
  "axios": "^0.21.0",
41
41
  "browserfs": "^1.4.3",
42
42
  "browserify-zlib": "^0.2.0",
43
43
  "chalk": "^2.4.2",
44
44
  "compare-versions": "^3.6.0",
45
45
  "compressing": "^1.4.0",
46
- "cross-spawn": "^6.0.5",
47
- "fs-extra": "^7.0.1",
48
46
  "constants-browserify": "^1.0.0",
47
+ "cross-spawn": "^6.0.5",
49
48
  "crypto-browserify": "^3.12.0",
49
+ "fs-extra": "^7.0.1",
50
50
  "jszip": "^3.7.1",
51
51
  "lodash": "^4.17.11",
52
52
  "lodash.clone": "^4.5.0",
@@ -60,7 +60,6 @@
60
60
  "xml-js": "^1.6.11"
61
61
  },
62
62
  "devDependencies": {
63
- "worker-loader": "^3.0.8",
64
63
  "@rollup/plugin-alias": "^3.1.9",
65
64
  "@types/archiver": "^3.1.0",
66
65
  "@types/command-exists": "^1.2.0",
@@ -78,7 +77,9 @@
78
77
  "ts-loader": "^8.3.0",
79
78
  "ts-node": "^10.4.0",
80
79
  "typescript": "^4.4.2",
80
+ "uglifyjs-webpack-plugin": "^2.2.0",
81
81
  "webpack-cli": "^4.9.1",
82
- "webpack-dev-server": "^4.7.3"
82
+ "webpack-dev-server": "^4.7.3",
83
+ "worker-loader": "^3.0.8"
83
84
  }
84
85
  }
@@ -27,7 +27,7 @@ export function createComputed(funcs, bindContext = null) {
27
27
  return computed
28
28
  }
29
29
 
30
- export function createEventHandlers(evtListeners) {
30
+ export function createEventHandlers(evtListeners, context) {
31
31
  const evtHandlers = {}
32
32
  for (const name in evtListeners) {
33
33
  const listeners = evtListeners[name]
@@ -45,7 +45,7 @@ export function createEventHandlers(evtListeners) {
45
45
  let { data = {}, boundData = {} } = l
46
46
  data = { ...data }
47
47
  for (const k in boundData) {
48
- set(data, k, boundData[k].call(owner, owner, lists, itemsById, event))
48
+ set(data, k, boundData[k].call(owner, owner, lists, itemsById, event, context))
49
49
  }
50
50
  try {
51
51
  let res = await l.handler.call(owner, { event, lists, forItems: itemsById, data })
@@ -10,7 +10,7 @@ import sdk from './weapp-sdk'
10
10
  */
11
11
  export const compLowcodes = {}
12
12
 
13
- export function createComponent(key, behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes) {
13
+ export function createComponent(key, behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes, undefined, context) {
14
14
 
15
15
  compLowcodes[key] = {
16
16
  index,
@@ -56,7 +56,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
56
56
 
57
57
  $comp.props.events = createPropEvents(events, this)
58
58
  $comp.widgets = {}
59
- const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBinds, $comp.widgets, this)
59
+ const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBinds, $comp.widgets, context, this)
60
60
  this._virtualRootWidget = virtualRootWidget
61
61
 
62
62
  try {
@@ -104,7 +104,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
104
104
  },
105
105
 
106
106
  methods: {
107
- ...createEventHandlers(evtListeners),
107
+ ...createEventHandlers(evtListeners, context),
108
108
  ...mergeRenderer,
109
109
  getWeAppInst() {
110
110
  const $comp = this.$WEAPPS_COMP
@@ -17,9 +17,10 @@ export function createPage(
17
17
  dataBinds,
18
18
  app,
19
19
  handler,
20
- pageContext = {}
20
+ pageContext = {},
21
+ context
21
22
  ) {
22
- const evtHandlers = createEventHandlers(evtListeners);
23
+ const evtHandlers = createEventHandlers(evtListeners, context);
23
24
 
24
25
  function extractLifecyles() {
25
26
  const result = { };
@@ -144,7 +145,7 @@ export function createPage(
144
145
  });
145
146
  };
146
147
 
147
- const { rootWidget } = createWidgets(widgetProps, dataBinds, $page.widgets, this)
148
+ const { rootWidget } = createWidgets(widgetProps, dataBinds, $page.widgets, context, this)
148
149
  $page._rootWidget = rootWidget
149
150
 
150
151
  return $page
@@ -35,10 +35,10 @@ export function resolveWidgetData(props) {
35
35
  }
36
36
 
37
37
 
38
- export function createWidgets(widgetProps, dataBinds, widgetHolder, ownerMpInst) {
38
+ export function createWidgets(widgetProps, dataBinds, widgetHolder, context, ownerMpInst) {
39
39
  const rootNode = createWidgetDataTree(widgetProps, dataBinds)
40
40
  const failedBinds = []
41
- const result = createSubWidgetTree(rootNode, widgetProps, dataBinds, ownerMpInst, widgetHolder, 0, {}, null, failedBinds)
41
+ const result = createSubWidgetTree(rootNode, widgetProps, dataBinds, ownerMpInst, widgetHolder, 0, {}, null, failedBinds, undefined, context)
42
42
  retryFailedBinds(failedBinds, true)
43
43
  return result
44
44
  }
@@ -51,7 +51,7 @@ export function createWidgets(widgetProps, dataBinds, widgetHolder, ownerMpInst)
51
51
  */
52
52
  function createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, widgetHolder = {},
53
53
  index = 0, forItems = {}, ownerForWidgetHolder = null,
54
- failedBinds = [], defaultParent = { children: observable([]), _disposers: [] }) {
54
+ failedBinds = [], defaultParent = { children: observable([]), _disposers: [] }, context) {
55
55
  const indexPostfix = (forItems.lists || []).slice().reverse().map(list => idSeparator + list.currentIndex).join('')
56
56
 
57
57
  // traverse down the tree to set up all widgets
@@ -75,7 +75,7 @@ function createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, wi
75
75
  } else {
76
76
  disposeWidget(existedWidget, true)
77
77
  }
78
- setUpWidgetDataBinds(w, dataBinds[node.id], forItems, failedBinds, ownerMpInst.getWeAppInst())
78
+ setUpWidgetDataBinds(w, dataBinds[node.id], forItems, failedBinds, ownerMpInst.getWeAppInst(), context)
79
79
  widgetHolder[node.id] = w
80
80
  } else if (!existedWidget) {
81
81
  const len = parentForWidgetArr.push(observable([]))
@@ -91,7 +91,7 @@ function createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, wi
91
91
  if (node.forCount === curForNode.forCount + 1 && dataBinds[node.id] && dataBinds[node.id]._waFor) {
92
92
  // find the node bound with next level for
93
93
  const parent = node.parent ? widgetHolder[node.parent.id] : defaultParent
94
- const dispose = runFor(node, widgetProps, dataBinds, ownerMpInst, forItems, widgetHolder, failedBinds, parent)
94
+ const dispose = runFor(node, widgetProps, dataBinds, ownerMpInst, forItems, widgetHolder, failedBinds, parent, context)
95
95
  parent._disposers.push(dispose) // Add the for bind dispose to the parent node of forNode
96
96
  }
97
97
  })
@@ -119,12 +119,12 @@ function retryFailedBinds(failedBinds, finalTry) {
119
119
  * @param {*} parentWidget
120
120
  * @returns top level widgets or for dispose
121
121
  */
122
- function runFor(curForNode, widgetProps, dataBinds, ownerMpInst, forItems, ownerForWidgetHolder, failedBinds, defaultParent) {
122
+ function runFor(curForNode, widgetProps, dataBinds, ownerMpInst, forItems, ownerForWidgetHolder, failedBinds, defaultParent, context) {
123
123
  const nodeId = curForNode.id
124
124
  const dispose = autorun(() => {
125
125
  let forList = []
126
126
  try {
127
- forList = dataBinds[nodeId]._waFor.call(ownerMpInst.getWeAppInst(), ownerMpInst.getWeAppInst(), forItems.lists, forItems.itemsById)
127
+ forList = dataBinds[nodeId]._waFor.call(ownerMpInst.getWeAppInst(), ownerMpInst.getWeAppInst(), forItems.lists, forItems.itemsById, undefined, context)
128
128
  if (!Array.isArray(forList)) {
129
129
  forList = []
130
130
  }
@@ -162,7 +162,7 @@ function runFor(curForNode, widgetProps, dataBinds, ownerMpInst, forItems, owner
162
162
  lists: [{ currentItem: item, currentIndex: index }, ...lists],
163
163
  itemsById: { ...itemsById, [nodeId]: item },
164
164
  }
165
- const { rootWidget } = createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, {}, index, _forItems, ownerForWidgetHolder, failedBinds, defaultParent)
165
+ const { rootWidget } = createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, {}, index, _forItems, ownerForWidgetHolder, failedBinds, defaultParent, context)
166
166
  rootWidget._forItems = _forItems
167
167
  })
168
168
  })
@@ -198,7 +198,7 @@ function createAWidget(props, id, parent, ownerMpInst) {
198
198
  return w
199
199
  }
200
200
 
201
- function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx) {
201
+ function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx, context) {
202
202
  Object.keys(dataBinds || {}).map(prop => {
203
203
  if (prop === '_waFor') { return }
204
204
  const setUpDataBind = (isFinalTry) => {
@@ -207,7 +207,7 @@ function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx) {
207
207
  const dispose = autorun((reaction) => {
208
208
  try {
209
209
  // Computed data bind in the next tick since data bind may read widgets data
210
- w[prop] = dataBinds[prop].call(ctx,ctx,forItems.lists, forItems.itemsById)
210
+ w[prop] = dataBinds[prop].call(ctx,ctx,forItems.lists, forItems.itemsById, undefined, context)
211
211
  } catch (e) {
212
212
  if (prop === '_waIf') {
213
213
  w[prop] = false
@@ -1,3 +1,4 @@
1
+ import { observable } from 'mobx';
1
2
  import { createComponent } from '../../../common/weapp-component'
2
3
  import { concatClassList, px2rpx } from '../../../common/style'
3
4
  import app from '../../../common/weapp-sdk'
@@ -11,6 +12,7 @@ import * as constObj from '../libCommonRes/const'
11
12
  import * as toolsObj from '../libCommonRes/tools'
12
13
 
13
14
  const libCode = '<%= materialName %>'
15
+ const context = observable({});
14
16
 
15
17
  const widgetProps = <%= stringifyObj(widgetProps, {depth: null}) %>
16
18
 
@@ -18,9 +20,9 @@ const evtListeners = {<% Object.entries(eventHandlers).map(([handlerName, listen
18
20
  <%= handlerName%>: [
19
21
  <%listeners.map(l=> { %>{
20
22
  key: '<%= l.key %>',
21
- handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else if (l.type === 'inline') {%> function({event, lists, forItems}, $comp){ <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
23
+ handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else if (l.type === 'inline') {%> function({event, lists, forItems, $context}, $comp){ <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
22
24
  data: <%= stringifyObj(l.data, {depth: null}) %>,
23
- boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($comp, lists, forItems, event) => {const $for=forItems;return (
25
+ boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($comp, lists, forItems, event, $context) => {const $for=forItems;return (
24
26
  <%= expr %>
25
27
  )},
26
28
  <%}) %>}
@@ -50,7 +52,7 @@ const handler = {<% handlers.forEach(h => {%>
50
52
 
51
53
  const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
52
54
  <%= id %>: { <% Object.entries(widgetBinds).map(([prop, expr]) => { %>
53
- <%= prop %>: function ($comp, lists, forItems, event) {const $for=forItems; return (
55
+ <%= prop %>: function ($comp, lists, forItems, event, $context) {const $for=forItems; return (
54
56
  <%= expr %>
55
57
  ); },<% }) %>
56
58
  },<%}) %>
@@ -59,4 +61,4 @@ const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
59
61
  const config = <%= JSON.stringify(config || {})%>
60
62
 
61
63
  createComponent('<%= key %>', behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps,
62
- index, lifeCycle, stateFn, computedFuncs, config, { const: constObj, tools: toolsObj }, libCode)
64
+ index, lifeCycle, stateFn, computedFuncs, config, { const: constObj, tools: toolsObj }, libCode, context)
@@ -1,3 +1,4 @@
1
+ import { observable } from 'mobx';
1
2
  import { createPage } from '<%= subLevelPath %>../../common/weapp-page'
2
3
  import { concatClassList, px2rpx } from '<%= subLevelPath %>../../common/style'
3
4
  import { app } from '<%= subLevelPath %>../../app/weapps-api'
@@ -7,7 +8,9 @@ import lifecyle from '../../lowcode/<%= pageName %>/lifecycle'
7
8
  import state from '../../lowcode/<%= pageName %>/state'
8
9
  import computed from '../../lowcode/<%= pageName %>/computed'
9
10
  import { $page } from './api'
11
+
10
12
  const $app = app;
13
+ const context = observable({});
11
14
 
12
15
  const widgetProps = <%= stringifyObj(widgetProps, {depth: null}) %>
13
16
  /** widget event listeners **/
@@ -15,9 +18,9 @@ const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listen
15
18
  <%= handlerName%>: [
16
19
  <%listeners.map(l=> { %>{
17
20
  key: '<%= l.key %>',
18
- handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else if (l.type == 'inline') {%> function({event, lists, forItems}, $page){const $for = forItems; return <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
21
+ handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else if (l.type == 'inline') {%> function({event, lists, forItems, $context}, $page){const $for = forItems; return <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
19
22
  data: <%= stringifyObj(l.data, {depth: null}) %>,
20
- boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($page, lists, forItems, event) => {const $for = forItems; return (
23
+ boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($page, lists, forItems, event, $context) => {const $for = forItems; return (
21
24
  <%= expr %>
22
25
  )},
23
26
  <%}) %>}
@@ -26,10 +29,10 @@ const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listen
26
29
  }
27
30
  const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
28
31
  <%= id %>: { <% Object.entries(widgetBinds).map(([prop, expr]) => { %>
29
- <%= prop %>: function ($page, lists, forItems, event) {const $for = forItems; return (
32
+ <%= prop %>: function ($page, lists, forItems, event, $context) {const $for = forItems; return (
30
33
  <%= expr %>
31
34
  ); },<% }) %>
32
35
  },<%}) %>
33
36
  }
34
37
 
35
- createPage('<%= pageName %>', '<%= pageUUID %>', widgetProps, {}, lifecyle, state, computed, evtListeners, dataBinds, app, handlers, $page)
38
+ createPage('<%= pageName %>', '<%= pageUUID %>', widgetProps, {}, lifecyle, state, computed, evtListeners, dataBinds, app, handlers, $page, context)