@lowdefy/engine 3.23.2 → 4.0.0-alpha.10

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 (49) hide show
  1. package/dist/Actions.js +229 -309
  2. package/dist/Blocks.js +560 -608
  3. package/dist/Events.js +119 -163
  4. package/dist/Requests.js +105 -144
  5. package/dist/State.js +56 -82
  6. package/dist/actions/createCallMethod.js +29 -0
  7. package/dist/actions/{Reset.js → createDisplayMessage.js} +6 -21
  8. package/dist/actions/createGetActions.js +27 -0
  9. package/dist/actions/createGetBlockId.js +20 -0
  10. package/dist/actions/createGetEvent.js +27 -0
  11. package/dist/actions/createGetGlobal.js +27 -0
  12. package/dist/actions/createGetInput.js +27 -0
  13. package/dist/actions/createGetPageId.js +20 -0
  14. package/dist/actions/createGetRequestDetails.js +27 -0
  15. package/dist/actions/{Message.js → createGetState.js} +13 -23
  16. package/dist/actions/createGetUrlQuery.js +27 -0
  17. package/dist/actions/createGetUser.js +27 -0
  18. package/dist/actions/createLink.js +20 -0
  19. package/dist/actions/createLogin.js +20 -0
  20. package/dist/actions/createLogout.js +20 -0
  21. package/dist/actions/createRequest.js +25 -0
  22. package/dist/actions/createReset.js +23 -0
  23. package/dist/actions/createResetValidation.js +21 -0
  24. package/dist/actions/createSetGlobal.js +25 -0
  25. package/dist/actions/createSetState.js +25 -0
  26. package/dist/actions/createValidate.js +25 -0
  27. package/dist/actions/getActionMethods.js +61 -0
  28. package/dist/actions/getFromObject.js +42 -0
  29. package/dist/createLink.js +53 -60
  30. package/dist/getBlockMatcher.js +47 -59
  31. package/dist/getContext.js +106 -143
  32. package/dist/index.js +10 -71
  33. package/package.json +13 -13
  34. package/dist/actions/CallMethod.js +0 -47
  35. package/dist/actions/JsAction.js +0 -77
  36. package/dist/actions/Link.js +0 -38
  37. package/dist/actions/Login.js +0 -43
  38. package/dist/actions/Logout.js +0 -42
  39. package/dist/actions/Request.js +0 -65
  40. package/dist/actions/ResetValidation.js +0 -32
  41. package/dist/actions/ScrollTo.js +0 -52
  42. package/dist/actions/SetGlobal.js +0 -35
  43. package/dist/actions/SetState.js +0 -35
  44. package/dist/actions/Throw.js +0 -67
  45. package/dist/actions/Validate.js +0 -37
  46. package/dist/actions/Wait.js +0 -34
  47. package/dist/actions/index.js +0 -72
  48. package/dist/getFieldValues.js +0 -49
  49. package/dist/makeContextId.js +0 -44
package/dist/Blocks.js CHANGED
@@ -1,625 +1,577 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _helpers = require("@lowdefy/helpers");
9
-
10
- var _Events = _interopRequireDefault(require("./Events"));
11
-
12
- var _getFieldValues = _interopRequireDefault(require("./getFieldValues"));
13
-
14
- var _excluded = ["blocks"];
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
19
-
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
-
22
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
-
24
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
25
-
26
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
27
-
28
- class Blocks {
29
- constructor(_ref) {
30
- var {
31
- arrayIndices,
32
- areas,
33
- context
34
- } = _ref;
35
- this.id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
36
- this.areas = _helpers.serializer.copy(areas || []);
37
- this.arrayIndices = _helpers.type.isArray(arrayIndices) ? arrayIndices : [];
38
- this.context = context;
39
- this.map = {};
40
- this.recCount = 0;
41
- this.subBlocks = {};
42
- this.generateBlockId = this.generateBlockId.bind(this);
43
- this.getValidateRec = this.getValidateRec.bind(this);
44
- this.init = this.init.bind(this);
45
- this.newBlocks = this.newBlocks.bind(this);
46
- this.recContainerDelState = this.recContainerDelState.bind(this);
47
- this.recEval = this.recEval.bind(this);
48
- this.recRemoveBlocksFromMap = this.recRemoveBlocksFromMap.bind(this);
49
- this.recSetUndefined = this.recSetUndefined.bind(this);
50
- this.recUpdateArrayIndices = this.recUpdateArrayIndices.bind(this);
51
- this.reset = this.reset.bind(this);
52
- this.resetValidation = this.resetValidation.bind(this);
53
- this.resetValidationRec = this.resetValidationRec.bind(this);
54
- this.setBlocksCache = this.setBlocksCache.bind(this);
55
- this.setBlocksLoadingCache = this.setBlocksLoadingCache.bind(this);
56
- this.update = this.update.bind(this);
57
- this.updateState = this.updateState.bind(this);
58
- this.updateStateFromRoot = this.updateStateFromRoot.bind(this);
59
- this.validate = this.validate.bind(this);
60
- }
61
-
62
- loopBlocks(fn) {
63
- if (_helpers.type.isObject(this.areas)) {
64
- Object.keys(this.areas).forEach(key => {
65
- if (_helpers.type.isArray(this.areas[key].blocks)) {
66
- this.areas[key].blocks.forEach(fn);
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { applyArrayIndices, get, serializer, swap, type } from '@lowdefy/helpers';
16
+ import Events from './Events.js';
17
+ let Blocks = class Blocks {
18
+ loopBlocks(fn) {
19
+ if (type.isObject(this.areas)) {
20
+ Object.keys(this.areas).forEach((key)=>{
21
+ if (type.isArray(this.areas[key].blocks)) {
22
+ this.areas[key].blocks.forEach(fn);
23
+ }
24
+ });
67
25
  }
68
- });
69
26
  }
70
- }
71
-
72
- init(initState) {
73
- this.loopBlocks(block => {
74
- block.blockIdPattern = block.blockId;
75
- block.id = this.generateBlockId(block.blockIdPattern);
76
- block.fieldPattern = block.field;
77
- block.blockId = (0, _helpers.applyArrayIndices)(this.arrayIndices, block.blockIdPattern);
78
- this.context.RootBlocks.map[block.blockId] = block;
79
- block.field = !_helpers.type.isNone(block.fieldPattern) ? (0, _helpers.applyArrayIndices)(this.arrayIndices, block.fieldPattern) : block.blockId;
80
- block.visible = _helpers.type.isNone(block.visible) ? true : block.visible;
81
- block.required = _helpers.type.isNone(block.required) ? false : block.required;
82
- block.validate = _helpers.type.isArray(block.validate) ? block.validate : [];
83
- block.properties = _helpers.type.isNone(block.properties) ? {} : block.properties;
84
- block.style = _helpers.type.isNone(block.style) ? {} : block.style;
85
- block.layout = _helpers.type.isNone(block.layout) ? {} : block.layout;
86
- block.events = _helpers.type.isNone(block.events) ? {} : block.events;
87
- block.areasLayoutEval = {};
88
- block.layoutEval = {};
89
- block.propertiesEval = {};
90
- block.requiredEval = {};
91
- block.styleEval = {};
92
- block.validationEval = {};
93
- block.visibleEval = {};
94
-
95
- if (!_helpers.type.isNone(block.areas)) {
96
- block.areasLayout = {};
97
- Object.keys(block.areas).forEach(key => {
98
- // eslint-disable-next-line no-unused-vars
99
- var _block$areas$key = block.areas[key],
100
- {
101
- blocks
102
- } = _block$areas$key,
103
- areaLayout = _objectWithoutProperties(_block$areas$key, _excluded);
104
-
105
- block.areasLayout[key] = _objectSpread({}, areaLayout);
106
- });
107
- } else {
108
- block.areasLayout = {};
109
- }
110
-
111
- block.requestKeys = (0, _getFieldValues.default)('_request', block.style, block.properties, block.validate, block.visible, block.required);
112
- block.methods = {};
113
-
114
- block.registerMethod = (methodName, method) => {
115
- block.methods[methodName] = method;
116
- }; // TODO: add callMethod on block to be used by actions and accessible in blocks
117
-
118
-
119
- if ((0, _helpers.get)(block, 'meta.category') === 'list') {
120
- // TODO: to initialize new object in array, the new value should be passed by method to unshiftItem and pushItem
121
- block.unshiftItem = () => {
122
- this.subBlocks[block.id].forEach((bl, i) => {
123
- bl.recUpdateArrayIndices(this.arrayIndices.concat([i]), this.arrayIndices.concat([i + 1]));
124
- });
125
- this.subBlocks[block.id].unshift(this.newBlocks({
126
- arrayIndices: this.arrayIndices.concat([0]),
127
- block,
128
- initState: {}
129
- }));
130
- this.context.State.set(block.field, undefined); // set block and subBlock values undefined, so as not to pass values to new blocks
131
-
132
- this.subBlocks[block.id][0].recSetUndefined();
133
- block.update = true;
134
- this.context.update();
135
- };
136
-
137
- block.pushItem = () => {
138
- this.subBlocks[block.id].push(this.newBlocks({
139
- arrayIndices: this.arrayIndices.concat([this.subBlocks[block.id].length]),
140
- block,
141
- initState: {}
142
- }));
143
- block.update = true;
144
- this.context.update();
145
- };
146
-
147
- block.removeItem = index => {
148
- this.context.State.removeItem(block.blockId, index);
149
- var lastBlock = this.subBlocks[block.id][this.subBlocks[block.id].length - 1];
150
- lastBlock.recRemoveBlocksFromMap();
151
- var largerBlocks = this.subBlocks[block.id].slice(index + 1);
152
- largerBlocks.forEach((bl, i) => {
153
- bl.recUpdateArrayIndices(this.arrayIndices.concat([index + i + 1]), this.arrayIndices.concat([index + i]));
154
- });
155
- this.subBlocks[block.id].splice(index, 1);
156
- block.update = true;
157
- this.context.update();
158
- };
159
-
160
- block.moveItemUp = index => {
161
- if (index === 0) return;
162
- this.context.State.swapItems(block.blockId, index - 1, index);
163
- this.subBlocks[block.id][index - 1].recUpdateArrayIndices(this.arrayIndices.concat([index - 1]), this.arrayIndices.concat([index]));
164
- this.subBlocks[block.id][index].recUpdateArrayIndices(this.arrayIndices.concat([index]), this.arrayIndices.concat([index - 1]));
165
- (0, _helpers.swap)(this.subBlocks[block.id], index - 1, index);
166
- block.update = true;
167
- this.context.update();
168
- };
169
-
170
- block.moveItemDown = index => {
171
- if (index === this.subBlocks[block.id].length - 1) return;
172
- this.context.State.swapItems(block.blockId, index, index + 1);
173
- this.subBlocks[block.id][index + 1].recUpdateArrayIndices(this.arrayIndices.concat([index + 1]), this.arrayIndices.concat([index]));
174
- this.subBlocks[block.id][index].recUpdateArrayIndices(this.arrayIndices.concat([index]), this.arrayIndices.concat([index + 1]));
175
- (0, _helpers.swap)(this.subBlocks[block.id], index, index + 1);
176
- block.update = true;
177
- this.context.update();
178
- };
179
- }
180
-
181
- if ((0, _helpers.get)(block, 'meta.category') === 'input') {
182
- block.setValue = value => {
183
- block.value = _helpers.type.enforceType(block.meta.valueType, value);
184
- this.context.State.set(block.field, block.value);
185
- block.update = true;
186
- this.context.update();
187
- };
188
- }
189
-
190
- block.Events = new _Events.default({
191
- arrayIndices: this.arrayIndices,
192
- block,
193
- context: this.context
194
- });
195
- block.triggerEvent = block.Events.triggerEvent;
196
- block.registerEvent = block.Events.registerEvent;
197
- });
198
- this.reset(initState); // set initial values to blocks.
199
- }
200
-
201
- reset(initWithState) {
202
- var initState = _helpers.serializer.copy(initWithState || this.context.state);
203
-
204
- this.loopBlocks(block => {
205
- block.update = true;
206
- block.showValidation = false;
207
-
208
- if ((0, _helpers.get)(block, 'meta.category') === 'input' || (0, _helpers.get)(block, 'meta.category') === 'list') {
209
- var blockValue = (0, _helpers.get)(initState, block.field);
210
-
211
- if (_helpers.type.isUndefined(blockValue)) {
212
- // default null value for block type
213
- blockValue = _helpers.type.isUndefined(block.meta.initValue) ? _helpers.type.enforceType(block.meta.valueType, null) : block.meta.initValue;
214
- this.context.State.set(block.field, block.value);
215
- }
216
-
217
- if ((0, _helpers.get)(block, 'meta.category') === 'list') {
218
- // load list value into list blocks
219
- if (!_helpers.type.isArray(this.subBlocks[block.id])) {
220
- this.subBlocks[block.id] = [];
221
- }
222
-
223
- if (_helpers.type.isArray(blockValue)) {
224
- blockValue.forEach((item, i) => {
225
- if (!this.subBlocks[block.id][i]) {
226
- this.subBlocks[block.id].push(this.newBlocks({
227
- arrayIndices: this.arrayIndices.concat([i]),
228
- block,
229
- initState
230
- }));
231
- } else {
232
- this.subBlocks[block.id][i].reset(initState);
233
- }
27
+ init(initState) {
28
+ this.loopBlocks((block)=>{
29
+ block.idPattern = block.id;
30
+ block.blockIdPattern = block.blockId;
31
+ block.fieldPattern = block.field;
32
+ block.id = applyArrayIndices(this.arrayIndices, block.idPattern);
33
+ block.blockId = applyArrayIndices(this.arrayIndices, block.blockIdPattern);
34
+ block.field = !type.isNone(block.fieldPattern) ? applyArrayIndices(this.arrayIndices, block.fieldPattern) : block.blockId;
35
+ this.context._internal.RootBlocks.map[block.id] = block;
36
+ block.events = type.isNone(block.events) ? {} : block.events;
37
+ block.layout = type.isNone(block.layout) ? {} : block.layout;
38
+ block.loading = type.isNone(block.loading) ? false : block.loading;
39
+ block.properties = type.isNone(block.properties) ? {} : block.properties;
40
+ block.required = type.isNone(block.required) ? false : block.required;
41
+ block.skeleton = type.isNone(block.skeleton) ? null : block.skeleton;
42
+ block.style = type.isNone(block.style) ? {} : block.style;
43
+ block.validate = type.isNone(block.validate) ? [] : block.validate;
44
+ block.visible = type.isNone(block.visible) ? true : block.visible;
45
+ block.areasLayoutEval = {};
46
+ block.layoutEval = {};
47
+ block.loadingEval = {};
48
+ block.propertiesEval = {};
49
+ block.requiredEval = {};
50
+ block.skeletonEval = {};
51
+ block.styleEval = {};
52
+ block.validationEval = {};
53
+ block.visibleEval = {};
54
+ try {
55
+ block.meta = this.context._internal.lowdefy._internal.blockComponents[block.type].meta;
56
+ } catch (error) {
57
+ throw new Error(`Block type ${block.type} not found at ${block.blockId}. Check your plugins to make sure the block is installed. For more info, see https://docs.lowdefy.com/plugins.`);
58
+ }
59
+ if (!type.isNone(block.areas)) {
60
+ block.areasLayout = {};
61
+ Object.keys(block.areas).forEach((key)=>{
62
+ // eslint-disable-next-line no-unused-vars
63
+ const { blocks , ...areaLayout } = block.areas[key];
64
+ block.areasLayout[key] = {
65
+ ...areaLayout
66
+ };
67
+ });
68
+ } else {
69
+ block.areasLayout = {};
70
+ }
71
+ block.methods = {};
72
+ block.registerMethod = (methodName, method)=>{
73
+ block.methods[methodName] = method;
74
+ };
75
+ // TODO: add callMethod on block to be used by actions and accessible in blocks
76
+ if (get(block, 'meta.category') === 'list') {
77
+ // TODO: to initialize new object in array, the new value should be passed by method to unshiftItem and pushItem
78
+ block.unshiftItem = ()=>{
79
+ this.subBlocks[block.id].forEach((bl, i)=>{
80
+ bl.recUpdateArrayIndices(this.arrayIndices.concat([
81
+ i
82
+ ]), this.arrayIndices.concat([
83
+ i + 1
84
+ ]));
85
+ });
86
+ this.subBlocks[block.id].unshift(this.newBlocks({
87
+ arrayIndices: this.arrayIndices.concat([
88
+ 0
89
+ ]),
90
+ block,
91
+ initState: {}
92
+ }));
93
+ this.context._internal.State.set(block.field, undefined);
94
+ // set block and subBlock values undefined, so as not to pass values to new blocks
95
+ this.subBlocks[block.id][0].recSetUndefined();
96
+ block.update = true;
97
+ this.context._internal.update();
98
+ };
99
+ block.pushItem = ()=>{
100
+ this.subBlocks[block.id].push(this.newBlocks({
101
+ arrayIndices: this.arrayIndices.concat([
102
+ this.subBlocks[block.id].length
103
+ ]),
104
+ block,
105
+ initState: {}
106
+ }));
107
+ block.update = true;
108
+ this.context._internal.update();
109
+ };
110
+ block.removeItem = (index)=>{
111
+ this.context._internal.State.removeItem(block.blockId, index);
112
+ const lastBlock = this.subBlocks[block.id][this.subBlocks[block.id].length - 1];
113
+ lastBlock.recRemoveBlocksFromMap();
114
+ const largerBlocks = this.subBlocks[block.id].slice(index + 1);
115
+ largerBlocks.forEach((bl, i)=>{
116
+ bl.recUpdateArrayIndices(this.arrayIndices.concat([
117
+ index + i + 1
118
+ ]), this.arrayIndices.concat([
119
+ index + i
120
+ ]));
121
+ });
122
+ this.subBlocks[block.id].splice(index, 1);
123
+ block.update = true;
124
+ this.context._internal.update();
125
+ };
126
+ block.moveItemUp = (index)=>{
127
+ if (index === 0) return;
128
+ this.context._internal.State.swapItems(block.blockId, index - 1, index);
129
+ this.subBlocks[block.id][index - 1].recUpdateArrayIndices(this.arrayIndices.concat([
130
+ index - 1
131
+ ]), this.arrayIndices.concat([
132
+ index
133
+ ]));
134
+ this.subBlocks[block.id][index].recUpdateArrayIndices(this.arrayIndices.concat([
135
+ index
136
+ ]), this.arrayIndices.concat([
137
+ index - 1
138
+ ]));
139
+ swap(this.subBlocks[block.id], index - 1, index);
140
+ block.update = true;
141
+ this.context._internal.update();
142
+ };
143
+ block.moveItemDown = (index)=>{
144
+ if (index === this.subBlocks[block.id].length - 1) return;
145
+ this.context._internal.State.swapItems(block.blockId, index, index + 1);
146
+ this.subBlocks[block.id][index + 1].recUpdateArrayIndices(this.arrayIndices.concat([
147
+ index + 1
148
+ ]), this.arrayIndices.concat([
149
+ index
150
+ ]));
151
+ this.subBlocks[block.id][index].recUpdateArrayIndices(this.arrayIndices.concat([
152
+ index
153
+ ]), this.arrayIndices.concat([
154
+ index + 1
155
+ ]));
156
+ swap(this.subBlocks[block.id], index, index + 1);
157
+ block.update = true;
158
+ this.context._internal.update();
159
+ };
160
+ }
161
+ if (get(block, 'meta.category') === 'input') {
162
+ block.setValue = (value)=>{
163
+ block.value = type.enforceType(block.meta.valueType, value);
164
+ this.context._internal.State.set(block.field, block.value);
165
+ block.update = true;
166
+ this.context._internal.update();
167
+ };
168
+ }
169
+ block.Events = new Events({
170
+ arrayIndices: this.arrayIndices,
171
+ block,
172
+ context: this.context
234
173
  });
235
- this.subBlocks[block.id].splice(blockValue.length);
236
- }
237
- } else {
238
- block.value = blockValue;
239
- }
240
- } else if ((0, _helpers.get)(block, 'meta.category') === 'container' || // do not make sub blocks for sub contexts
241
- (0, _helpers.get)(block, 'meta.category') === 'context' && this === this.context.RootBlocks) {
242
- if (!_helpers.type.isArray(this.subBlocks[block.id])) {
243
- this.subBlocks[block.id] = [];
244
- }
245
-
246
- if (!this.subBlocks[block.id][0]) {
247
- this.subBlocks[block.id].push(this.newBlocks({
248
- arrayIndices: this.arrayIndices,
249
- block,
250
- initState
251
- }));
252
- } else {
253
- this.subBlocks[block.id][0].reset(initState);
254
- }
255
- }
256
- });
257
- }
258
-
259
- newBlocks(_ref2) {
260
- var {
261
- arrayIndices,
262
- block,
263
- initState
264
- } = _ref2;
265
- var SubBlocks = new Blocks({
266
- arrayIndices,
267
- areas: block.areas,
268
- context: this.context
269
- });
270
- SubBlocks.init(initState);
271
- return SubBlocks;
272
- } // used for update comparison
273
-
274
-
275
- static blockEvalToString(block) {
276
- return _helpers.serializer.serializeToString({
277
- areasLayoutEval: block.areasLayoutEval,
278
- layoutEval: block.layoutEval,
279
- propertiesEval: block.propertiesEval,
280
- requiredEval: block.requiredEval,
281
- styleEval: block.styleEval,
282
- validationEval: block.validationEval,
283
- value: block.value,
284
- visibleEval: block.visibleEval
285
- });
286
- }
287
-
288
- recEval(visibleParent) {
289
- var repeat = false;
290
- this.loopBlocks(block => {
291
- if (block.meta.category === 'input') {
292
- var stateValue = (0, _helpers.get)(this.context.state, block.field); // TODO: related to #345
293
- // enforce type here? should we reassign value here??
294
-
295
- block.value = _helpers.type.isUndefined(stateValue) ? block.value : stateValue;
296
- }
297
-
298
- var beforeVisible = block.visibleEval ? block.visibleEval.output : true;
299
-
300
- if (visibleParent === false) {
301
- block.visibleEval.output = false;
302
- } else {
303
- block.visibleEval = this.context.parser.parse({
304
- input: block.visible,
305
- location: block.blockId,
306
- arrayIndices: this.arrayIndices
307
- }); // run parser on index combinations to get visible value object
308
- }
309
-
310
- if (beforeVisible !== block.visibleEval.output) {
311
- repeat = true;
312
- } // only evaluate visible blocks
313
-
314
-
315
- if (block.visibleEval.output !== false) {
316
- block.propertiesEval = this.context.parser.parse({
317
- input: block.properties,
318
- location: block.blockId,
319
- arrayIndices: this.arrayIndices
174
+ block.triggerEvent = block.Events.triggerEvent;
175
+ block.registerEvent = block.Events.registerEvent;
320
176
  });
321
- block.requiredEval = this.context.parser.parse({
322
- input: block.required,
323
- location: block.blockId,
324
- arrayIndices: this.arrayIndices
177
+ this.reset(initState); // set initial values to blocks.
178
+ }
179
+ reset(initWithState) {
180
+ const initState = serializer.copy(initWithState || this.context.state);
181
+ this.loopBlocks((block)=>{
182
+ block.update = true;
183
+ block.showValidation = false;
184
+ if (get(block, 'meta.category') === 'input' || get(block, 'meta.category') === 'list') {
185
+ let blockValue = get(initState, block.field);
186
+ if (type.isUndefined(blockValue)) {
187
+ // default null value for block type
188
+ blockValue = type.isUndefined(block.meta.initValue) ? type.enforceType(block.meta.valueType, null) : block.meta.initValue;
189
+ this.context._internal.State.set(block.field, block.value);
190
+ }
191
+ if (get(block, 'meta.category') === 'list') {
192
+ // load list value into list blocks
193
+ if (!type.isArray(this.subBlocks[block.id])) {
194
+ this.subBlocks[block.id] = [];
195
+ }
196
+ if (type.isArray(blockValue)) {
197
+ blockValue.forEach((item, i)=>{
198
+ if (!this.subBlocks[block.id][i]) {
199
+ this.subBlocks[block.id].push(this.newBlocks({
200
+ arrayIndices: this.arrayIndices.concat([
201
+ i
202
+ ]),
203
+ block,
204
+ initState
205
+ }));
206
+ } else {
207
+ this.subBlocks[block.id][i].reset(initState);
208
+ }
209
+ });
210
+ this.subBlocks[block.id].splice(blockValue.length);
211
+ }
212
+ } else {
213
+ block.value = blockValue;
214
+ }
215
+ } else if (get(block, 'meta.category') === 'container') {
216
+ if (!type.isArray(this.subBlocks[block.id])) {
217
+ this.subBlocks[block.id] = [];
218
+ }
219
+ if (!this.subBlocks[block.id][0]) {
220
+ this.subBlocks[block.id].push(this.newBlocks({
221
+ arrayIndices: this.arrayIndices,
222
+ block,
223
+ initState
224
+ }));
225
+ } else {
226
+ this.subBlocks[block.id][0].reset(initState);
227
+ }
228
+ }
229
+ });
230
+ }
231
+ newBlocks({ arrayIndices , block , initState }) {
232
+ const SubBlocks = new Blocks({
233
+ arrayIndices,
234
+ areas: block.areas,
235
+ context: this.context
325
236
  });
326
- var requiredValidation = {
327
- pass: {
328
- _not: {
329
- _type: 'none'
237
+ SubBlocks.init(initState);
238
+ return SubBlocks;
239
+ }
240
+ // used for update comparison
241
+ static blockEvalToString(block) {
242
+ return serializer.serializeToString({
243
+ areasLayoutEval: block.areasLayoutEval,
244
+ layoutEval: block.layoutEval,
245
+ loadingEval: block.loadingEval,
246
+ propertiesEval: block.propertiesEval,
247
+ requiredEval: block.requiredEval,
248
+ skeletonEval: block.skeletonEval,
249
+ styleEval: block.styleEval,
250
+ validationEval: block.validationEval,
251
+ value: block.value,
252
+ visibleEval: block.visibleEval
253
+ });
254
+ }
255
+ recEval(visibleParent) {
256
+ let repeat = false;
257
+ this.loopBlocks((block)=>{
258
+ if (block.meta.category === 'input') {
259
+ const stateValue = get(this.context.state, block.field);
260
+ // TODO: related to #345
261
+ // enforce type here? should we reassign value here??
262
+ block.value = type.isUndefined(stateValue) ? block.value : stateValue;
330
263
  }
331
- },
332
- status: 'error',
333
- message: _helpers.type.isString(block.requiredEval.output) ? block.requiredEval.output : 'This field is required'
334
- };
335
- var validation = block.required === false ? block.validate : [requiredValidation, ...block.validate];
336
- block.validationEval = {
337
- output: {
338
- status: null,
339
- errors: [],
340
- warnings: []
341
- },
342
- errors: []
343
- };
344
- var validationError = false;
345
- var validationWarning = false;
346
- validation.forEach(test => {
347
- var parsed = this.context.parser.parse({
348
- input: test,
349
- location: block.blockId,
350
- arrayIndices: this.arrayIndices
351
- }); // for parser errors
352
-
353
- if (parsed.errors.length > 0) {
354
- block.validationEval.output.errors.push(parsed.output.message);
355
- block.validationEval.errors.push(parsed.errors);
356
- validationError = true;
357
- return;
358
- } // failed validation
359
-
360
-
361
- if (!parsed.output.pass) {
362
- // no status indication on validation tests defaults to error
363
- if (!test.status || test.status === 'error') {
364
- block.validationEval.output.errors.push(parsed.output.message);
365
- validationError = true;
264
+ const beforeVisible = block.visibleEval ? block.visibleEval.output : true;
265
+ if (visibleParent === false) {
266
+ block.visibleEval.output = false;
267
+ } else {
268
+ block.visibleEval = this.context._internal.parser.parse({
269
+ input: block.visible,
270
+ location: block.blockId,
271
+ arrayIndices: this.arrayIndices
272
+ }); // run parser on index combinations to get visible value object
366
273
  }
367
-
368
- if (test.status === 'warning') {
369
- block.validationEval.output.warnings.push(parsed.output.message);
370
- validationWarning = true;
274
+ if (beforeVisible !== block.visibleEval.output) {
275
+ repeat = true;
276
+ }
277
+ // only evaluate visible blocks
278
+ if (block.visibleEval.output !== false) {
279
+ block.propertiesEval = this.context._internal.parser.parse({
280
+ input: block.properties,
281
+ location: block.blockId,
282
+ arrayIndices: this.arrayIndices
283
+ });
284
+ block.requiredEval = this.context._internal.parser.parse({
285
+ input: block.required,
286
+ location: block.blockId,
287
+ arrayIndices: this.arrayIndices
288
+ });
289
+ const requiredValidation = {
290
+ pass: {
291
+ _not: {
292
+ _type: 'none'
293
+ }
294
+ },
295
+ status: 'error',
296
+ message: type.isString(block.requiredEval.output) ? block.requiredEval.output : 'This field is required'
297
+ };
298
+ const validation = block.required === false ? block.validate : [
299
+ requiredValidation,
300
+ ...block.validate
301
+ ];
302
+ block.validationEval = {
303
+ output: {
304
+ status: null,
305
+ errors: [],
306
+ warnings: []
307
+ },
308
+ errors: []
309
+ };
310
+ let validationError = false;
311
+ let validationWarning = false;
312
+ validation.forEach((test)=>{
313
+ const parsed = this.context._internal.parser.parse({
314
+ input: test,
315
+ location: block.blockId,
316
+ arrayIndices: this.arrayIndices
317
+ });
318
+ // for parser errors
319
+ if (parsed.errors.length > 0) {
320
+ block.validationEval.output.errors.push(parsed.output.message);
321
+ block.validationEval.errors.push(parsed.errors);
322
+ validationError = true;
323
+ return;
324
+ }
325
+ // failed validation
326
+ if (!parsed.output.pass) {
327
+ // no status indication on validation tests defaults to error
328
+ if (!test.status || test.status === 'error') {
329
+ block.validationEval.output.errors.push(parsed.output.message);
330
+ validationError = true;
331
+ }
332
+ if (test.status === 'warning') {
333
+ block.validationEval.output.warnings.push(parsed.output.message);
334
+ validationWarning = true;
335
+ }
336
+ }
337
+ });
338
+ if (validation.length > 0) {
339
+ block.validationEval.output.status = 'success';
340
+ }
341
+ if (validationWarning) {
342
+ block.validationEval.output.status = 'warning';
343
+ }
344
+ if (validationError) {
345
+ block.validationEval.output.status = 'error';
346
+ }
347
+ block.styleEval = this.context._internal.parser.parse({
348
+ input: block.style,
349
+ location: block.blockId,
350
+ arrayIndices: this.arrayIndices
351
+ });
352
+ block.layoutEval = this.context._internal.parser.parse({
353
+ input: block.layout,
354
+ location: block.blockId,
355
+ arrayIndices: this.arrayIndices
356
+ });
357
+ block.loadingEval = this.context._internal.parser.parse({
358
+ input: block.loading,
359
+ location: block.blockId,
360
+ arrayIndices: this.arrayIndices
361
+ });
362
+ block.skeletonEval = this.context._internal.parser.parse({
363
+ input: block.skeleton,
364
+ location: block.blockId,
365
+ arrayIndices: this.arrayIndices
366
+ });
367
+ block.areasLayoutEval = this.context._internal.parser.parse({
368
+ input: block.areasLayout,
369
+ location: block.blockId,
370
+ arrayIndices: this.arrayIndices
371
+ });
372
+ }
373
+ if (get(block, 'meta.category') === 'container' || get(block, 'meta.category') === 'list') {
374
+ if (this.subBlocks[block.id] && this.subBlocks[block.id].length > 0) {
375
+ this.subBlocks[block.id].forEach((blockClass)=>{
376
+ repeat = blockClass.recEval(block.visibleEval.output) || repeat;
377
+ });
378
+ }
379
+ }
380
+ const after = Blocks.blockEvalToString(block);
381
+ if (block.before !== after) {
382
+ block.update = true;
383
+ block.before = after;
371
384
  }
372
- }
373
385
  });
374
-
375
- if (validation.length > 0) {
376
- block.validationEval.output.status = 'success';
377
- }
378
-
379
- if (validationWarning) {
380
- block.validationEval.output.status = 'warning';
381
- }
382
-
383
- if (validationError) {
384
- block.validationEval.output.status = 'error';
385
- }
386
-
387
- block.styleEval = this.context.parser.parse({
388
- input: block.style,
389
- location: block.blockId,
390
- arrayIndices: this.arrayIndices
386
+ return repeat;
387
+ }
388
+ updateState() {
389
+ const toSet = new Set();
390
+ const toDelete = new Set();
391
+ this.loopBlocks((block)=>{
392
+ if (block.visibleEval.output !== false) {
393
+ if (get(block, 'meta.category') === 'container' || get(block, 'meta.category') === 'list') {
394
+ if (this.subBlocks[block.id] && this.subBlocks[block.id].length > 0) {
395
+ this.subBlocks[block.id].forEach((blockClass)=>{
396
+ blockClass.updateState();
397
+ });
398
+ } else {
399
+ toSet.add(block.field);
400
+ this.context._internal.State.set(block.field, type.enforceType(block.meta.valueType, null));
401
+ }
402
+ } else if (get(block, 'meta.category') === 'input') {
403
+ toSet.add(block.field);
404
+ this.context._internal.State.set(block.field, block.value);
405
+ }
406
+ } else if (get(block, 'meta.category') === 'container') {
407
+ this.subBlocks[block.id].forEach((blockClass)=>{
408
+ blockClass.recContainerDelState(toDelete);
409
+ });
410
+ } else {
411
+ toDelete.add(block.field);
412
+ }
391
413
  });
392
- block.layoutEval = this.context.parser.parse({
393
- input: block.layout,
394
- location: block.blockId,
395
- arrayIndices: this.arrayIndices
414
+ toDelete.forEach((field)=>{
415
+ if (!toSet.has(field)) {
416
+ this.context._internal.State.del(field);
417
+ }
396
418
  });
397
- block.areasLayoutEval = this.context.parser.parse({
398
- input: block.areasLayout,
399
- location: block.blockId,
400
- arrayIndices: this.arrayIndices
419
+ }
420
+ recContainerDelState(toDelete) {
421
+ this.loopBlocks((block)=>{
422
+ if (get(block, 'meta.category') === 'container') {
423
+ this.subBlocks[block.id].forEach((blockClass)=>{
424
+ blockClass.recContainerDelState(toDelete);
425
+ });
426
+ } else {
427
+ toDelete.add(block.field);
428
+ }
401
429
  });
402
- }
403
-
404
- if ((0, _helpers.get)(block, 'meta.category') === 'container' || (0, _helpers.get)(block, 'meta.category') === 'context' || (0, _helpers.get)(block, 'meta.category') === 'list') {
405
- if (this.subBlocks[block.id] && this.subBlocks[block.id].length > 0) {
406
- this.subBlocks[block.id].forEach(blockClass => {
407
- repeat = blockClass.recEval(block.visibleEval.output) || repeat;
408
- });
430
+ }
431
+ updateStateFromRoot() {
432
+ const repeat = this.recEval(true);
433
+ this.updateState();
434
+ if (repeat && this.recCount < 20) {
435
+ this.recCount += 1;
436
+ this.updateStateFromRoot();
409
437
  }
410
- }
411
-
412
- var after = Blocks.blockEvalToString(block);
413
-
414
- if (block.before !== after) {
415
- block.update = true;
416
- block.before = after;
417
- }
418
- });
419
- return repeat;
420
- }
421
-
422
- updateState() {
423
- var toSet = new Set();
424
- var toDelete = new Set();
425
- this.loopBlocks(block => {
426
- if (block.visibleEval.output !== false) {
427
- if ((0, _helpers.get)(block, 'meta.category') === 'container' || (0, _helpers.get)(block, 'meta.category') === 'context' || (0, _helpers.get)(block, 'meta.category') === 'list') {
428
- if (this.subBlocks[block.id] && this.subBlocks[block.id].length > 0) {
429
- this.subBlocks[block.id].forEach(blockClass => {
430
- blockClass.updateState();
438
+ this.recCount = 0;
439
+ }
440
+ recUpdateArrayIndices(oldIndices, newIndices) {
441
+ newIndices.forEach((index, i)=>{
442
+ this.arrayIndices[i] = newIndices[i];
443
+ });
444
+ this.loopBlocks((block)=>{
445
+ block.blockId = applyArrayIndices(this.arrayIndices, block.blockIdPattern);
446
+ this.context._internal.RootBlocks.map[block.blockId] = block;
447
+ block.field = !type.isNone(block.fieldPattern) ? applyArrayIndices(this.arrayIndices, block.fieldPattern) : block.blockId;
448
+ });
449
+ Object.keys(this.subBlocks).forEach((subKey)=>{
450
+ this.subBlocks[subKey].forEach((subBlock)=>{
451
+ subBlock.recUpdateArrayIndices(oldIndices, newIndices);
431
452
  });
432
- } else {
433
- toSet.add(block.field);
434
- this.context.State.set(block.field, _helpers.type.enforceType(block.meta.valueType, null));
435
- }
436
- } else if ((0, _helpers.get)(block, 'meta.category') === 'input') {
437
- toSet.add(block.field);
438
- this.context.State.set(block.field, block.value);
439
- }
440
- } else if ((0, _helpers.get)(block, 'meta.category') === 'container' || (0, _helpers.get)(block, 'meta.category') === 'context') {
441
- this.subBlocks[block.id].forEach(blockClass => {
442
- blockClass.recContainerDelState(toDelete);
443
453
  });
444
- } else {
445
- toDelete.add(block.field);
446
- }
447
- });
448
- toDelete.forEach(field => {
449
- if (!toSet.has(field)) {
450
- this.context.State.del(field);
451
- }
452
- });
453
- }
454
-
455
- recContainerDelState(toDelete) {
456
- this.loopBlocks(block => {
457
- if ((0, _helpers.get)(block, 'meta.category') === 'container' || (0, _helpers.get)(block, 'meta.category') === 'context') {
458
- this.subBlocks[block.id].forEach(blockClass => {
459
- blockClass.recContainerDelState(toDelete);
454
+ }
455
+ getValidateRec(match, result) {
456
+ this.loopBlocks((block)=>{
457
+ if (match(block.blockId)) {
458
+ block.showValidation = true;
459
+ block.update = true;
460
+ if (block.visibleEval.output !== false && block.validationEval.output && block.validationEval.output.status === 'error') {
461
+ result.push({
462
+ blockId: block.blockId,
463
+ validation: block.validationEval.output
464
+ });
465
+ }
466
+ }
460
467
  });
461
- } else {
462
- toDelete.add(block.field);
463
- }
464
- });
465
- }
466
-
467
- updateStateFromRoot() {
468
- var repeat = this.recEval(true);
469
- this.updateState();
470
-
471
- if (repeat && this.recCount < 20) {
472
- this.recCount += 1;
473
- this.updateStateFromRoot();
468
+ Object.keys(this.subBlocks).forEach((subKey)=>{
469
+ this.subBlocks[subKey].forEach((subBlock)=>{
470
+ subBlock.getValidateRec(match, result);
471
+ });
472
+ });
473
+ return result;
474
474
  }
475
-
476
- this.recCount = 0;
477
- }
478
-
479
- recUpdateArrayIndices(oldIndices, newIndices) {
480
- newIndices.forEach((index, i) => {
481
- this.arrayIndices[i] = newIndices[i];
482
- });
483
- this.loopBlocks(block => {
484
- block.blockId = (0, _helpers.applyArrayIndices)(this.arrayIndices, block.blockIdPattern);
485
- this.context.RootBlocks.map[block.blockId] = block;
486
- block.field = !_helpers.type.isNone(block.fieldPattern) ? (0, _helpers.applyArrayIndices)(this.arrayIndices, block.fieldPattern) : block.blockId;
487
- });
488
- Object.keys(this.subBlocks).forEach(subKey => {
489
- this.subBlocks[subKey].forEach(subBlock => {
490
- subBlock.recUpdateArrayIndices(oldIndices, newIndices);
491
- });
492
- });
493
- }
494
-
495
- getValidateRec(match, result) {
496
- this.loopBlocks(block => {
497
- if (match(block.blockId)) {
498
- block.showValidation = true;
499
- block.update = true;
500
-
501
- if (block.visibleEval.output !== false && block.validationEval.output && block.validationEval.output.status === 'error') {
502
- result.push({
503
- blockId: block.blockId,
504
- validation: block.validationEval.output
505
- });
506
- }
507
- }
508
- });
509
- Object.keys(this.subBlocks).forEach(subKey => {
510
- this.subBlocks[subKey].forEach(subBlock => {
511
- subBlock.getValidateRec(match, result);
512
- });
513
- });
514
- return result;
515
- }
516
-
517
- recSetUndefined() {
518
- this.loopBlocks(block => {
519
- this.context.State.set(block.field, undefined);
520
- });
521
- Object.keys(this.subBlocks).forEach(subKey => {
522
- this.subBlocks[subKey].forEach(subBlock => {
523
- subBlock.recSetUndefined();
524
- });
525
- });
526
- }
527
-
528
- recRemoveBlocksFromMap() {
529
- this.loopBlocks(block => {
530
- delete this.context.RootBlocks.map[block.blockId];
531
- });
532
- Object.keys(this.subBlocks).forEach(subKey => {
533
- this.subBlocks[subKey].forEach(subBlock => {
534
- subBlock.recRemoveBlocksFromMap();
535
- });
536
- });
537
- }
538
-
539
- validate(match) {
540
- this.updateStateFromRoot(); // update to recalculate validationEval to raise block errors
541
-
542
- var validationErrors = this.getValidateRec(match, []); // get all relevant raised block errors and set showValidation
543
-
544
- this.setBlocksCache(); // update cache to render
545
-
546
- return validationErrors;
547
- }
548
-
549
- resetValidationRec(match) {
550
- this.loopBlocks(block => {
551
- if (match(block.blockId)) {
552
- block.showValidation = false;
553
- block.update = true;
554
- }
555
- });
556
- Object.keys(this.subBlocks).forEach(subKey => {
557
- this.subBlocks[subKey].forEach(subBlock => {
558
- subBlock.resetValidationRec(match);
559
- });
560
- });
561
- }
562
-
563
- resetValidation(match) {
564
- this.resetValidationRec(match);
565
- this.setBlocksCache();
566
- }
567
-
568
- update() {
569
- this.updateStateFromRoot(); // update all the blocks
570
-
571
- this.setBlocksCache(); // finally update cache
572
- }
573
-
574
- setBlocksCache() {
575
- this.loopBlocks(block => {
576
- if (block.update) {
577
- block.update = false;
578
- block.loading = block.requestKeys.reduce((acc, key) => acc || (this.context.requests[key] ? this.context.requests[key].loading : true), false);
579
- block.eval = {
580
- areas: block.areasLayoutEval.output,
581
- events: _helpers.type.isNone(block.Events.events) ? null : block.Events.events,
582
- properties: block.propertiesEval.output,
583
- required: block.requiredEval.output,
584
- layout: block.layoutEval.output,
585
- style: block.styleEval.output,
586
- validation: _objectSpread(_objectSpread({}, block.validationEval.output || {}), {}, {
587
- status: block.showValidation ? (block.validationEval.output || {}).status : null
588
- }),
589
- value: _helpers.type.isNone(block.value) ? null : block.value,
590
- visible: block.visibleEval.output
591
- };
592
- this.context.lowdefy.updateBlock(block.id);
593
- }
594
- });
595
- Object.keys(this.subBlocks).forEach(subKey => {
596
- this.subBlocks[subKey].forEach(subBlock => {
597
- subBlock.setBlocksCache();
598
- });
599
- });
600
- }
601
-
602
- setBlocksLoadingCache() {
603
- this.loopBlocks(block => {
604
- block.loading_prev = block.loading;
605
- block.loading = block.requestKeys.reduce((acc, key) => acc || (this.context.requests[key] ? this.context.requests[key].loading : true), false);
606
-
607
- if (block.loading_prev !== block.loading) {
608
- this.context.lowdefy.updateBlock(block.id);
609
- }
610
- });
611
- Object.keys(this.subBlocks).forEach(subKey => {
612
- this.subBlocks[subKey].forEach(subBlock => {
613
- subBlock.setBlocksLoadingCache();
614
- });
615
- });
616
- }
617
-
618
- generateBlockId(blockIdPattern) {
619
- return "".concat(this.context.pageId, ":").concat(blockIdPattern, ":").concat(Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5));
620
- }
621
-
622
- }
623
-
624
- var _default = Blocks;
625
- exports.default = _default;
475
+ recSetUndefined() {
476
+ this.loopBlocks((block)=>{
477
+ this.context._internal.State.set(block.field, undefined);
478
+ });
479
+ Object.keys(this.subBlocks).forEach((subKey)=>{
480
+ this.subBlocks[subKey].forEach((subBlock)=>{
481
+ subBlock.recSetUndefined();
482
+ });
483
+ });
484
+ }
485
+ recRemoveBlocksFromMap() {
486
+ this.loopBlocks((block)=>{
487
+ delete this.context._internal.RootBlocks.map[block.blockId];
488
+ });
489
+ Object.keys(this.subBlocks).forEach((subKey)=>{
490
+ this.subBlocks[subKey].forEach((subBlock)=>{
491
+ subBlock.recRemoveBlocksFromMap();
492
+ });
493
+ });
494
+ }
495
+ validate(match) {
496
+ this.updateStateFromRoot(); // update to recalculate validationEval to raise block errors
497
+ const validationErrors = this.getValidateRec(match, []); // get all relevant raised block errors and set showValidation
498
+ this.setBlocksCache(); // update cache to render
499
+ return validationErrors;
500
+ }
501
+ resetValidationRec(match) {
502
+ this.loopBlocks((block)=>{
503
+ if (match(block.blockId)) {
504
+ block.showValidation = false;
505
+ block.update = true;
506
+ }
507
+ });
508
+ Object.keys(this.subBlocks).forEach((subKey)=>{
509
+ this.subBlocks[subKey].forEach((subBlock)=>{
510
+ subBlock.resetValidationRec(match);
511
+ });
512
+ });
513
+ }
514
+ resetValidation(match) {
515
+ this.resetValidationRec(match);
516
+ this.setBlocksCache();
517
+ }
518
+ update() {
519
+ this.updateStateFromRoot(); // update all the blocks
520
+ this.setBlocksCache(); // finally update cache
521
+ }
522
+ setBlocksCache() {
523
+ this.loopBlocks((block)=>{
524
+ if (block.update) {
525
+ block.update = false;
526
+ block.eval = {
527
+ areas: block.areasLayoutEval.output,
528
+ events: type.isNone(block.Events.events) ? null : block.Events.events,
529
+ properties: block.propertiesEval.output,
530
+ loading: block.loadingEval.output,
531
+ skeleton: block.skeletonEval.output,
532
+ required: block.requiredEval.output,
533
+ layout: block.layoutEval.output,
534
+ style: block.styleEval.output,
535
+ validation: {
536
+ ...block.validationEval.output || {},
537
+ status: block.showValidation ? (block.validationEval.output || {}).status : null
538
+ },
539
+ value: type.isNone(block.value) ? null : block.value,
540
+ visible: block.visibleEval.output
541
+ };
542
+ this.context._internal.lowdefy._internal.updateBlock(block.id);
543
+ }
544
+ });
545
+ Object.keys(this.subBlocks).forEach((subKey)=>{
546
+ this.subBlocks[subKey].forEach((subBlock)=>{
547
+ subBlock.setBlocksCache();
548
+ });
549
+ });
550
+ }
551
+ constructor({ arrayIndices , areas , context }){
552
+ this.id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
553
+ this.areas = serializer.copy(areas || []);
554
+ this.arrayIndices = type.isArray(arrayIndices) ? arrayIndices : [];
555
+ this.context = context;
556
+ this.map = {};
557
+ this.recCount = 0;
558
+ this.subBlocks = {};
559
+ this.getValidateRec = this.getValidateRec.bind(this);
560
+ this.init = this.init.bind(this);
561
+ this.newBlocks = this.newBlocks.bind(this);
562
+ this.recContainerDelState = this.recContainerDelState.bind(this);
563
+ this.recEval = this.recEval.bind(this);
564
+ this.recRemoveBlocksFromMap = this.recRemoveBlocksFromMap.bind(this);
565
+ this.recSetUndefined = this.recSetUndefined.bind(this);
566
+ this.recUpdateArrayIndices = this.recUpdateArrayIndices.bind(this);
567
+ this.reset = this.reset.bind(this);
568
+ this.resetValidation = this.resetValidation.bind(this);
569
+ this.resetValidationRec = this.resetValidationRec.bind(this);
570
+ this.setBlocksCache = this.setBlocksCache.bind(this);
571
+ this.update = this.update.bind(this);
572
+ this.updateState = this.updateState.bind(this);
573
+ this.updateStateFromRoot = this.updateStateFromRoot.bind(this);
574
+ this.validate = this.validate.bind(this);
575
+ }
576
+ };
577
+ export default Blocks;