@lowdefy/engine 3.23.3 → 4.0.0-alpha.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.
- package/dist/Actions.js +229 -309
- package/dist/Blocks.js +560 -608
- package/dist/Events.js +119 -163
- package/dist/Requests.js +105 -144
- package/dist/State.js +56 -82
- package/dist/actions/createCallMethod.js +29 -0
- package/dist/actions/{Reset.js → createDisplayMessage.js} +6 -21
- package/dist/actions/createGetActions.js +27 -0
- package/dist/actions/createGetBlockId.js +20 -0
- package/dist/actions/createGetEvent.js +27 -0
- package/dist/actions/createGetGlobal.js +27 -0
- package/dist/actions/createGetInput.js +27 -0
- package/dist/actions/createGetPageId.js +20 -0
- package/dist/actions/createGetRequestDetails.js +27 -0
- package/dist/actions/{Message.js → createGetState.js} +13 -23
- package/dist/actions/createGetUrlQuery.js +27 -0
- package/dist/actions/createGetUser.js +27 -0
- package/dist/actions/createLink.js +20 -0
- package/dist/actions/createLogin.js +20 -0
- package/dist/actions/createLogout.js +20 -0
- package/dist/actions/createRequest.js +25 -0
- package/dist/actions/createReset.js +23 -0
- package/dist/actions/createResetValidation.js +21 -0
- package/dist/actions/createSetGlobal.js +25 -0
- package/dist/actions/createSetState.js +25 -0
- package/dist/actions/createValidate.js +25 -0
- package/dist/actions/getActionMethods.js +61 -0
- package/dist/actions/getFromObject.js +42 -0
- package/dist/createLink.js +53 -60
- package/dist/getBlockMatcher.js +47 -59
- package/dist/getContext.js +106 -143
- package/dist/index.js +10 -71
- package/package.json +13 -13
- package/dist/actions/CallMethod.js +0 -47
- package/dist/actions/JsAction.js +0 -77
- package/dist/actions/Link.js +0 -38
- package/dist/actions/Login.js +0 -43
- package/dist/actions/Logout.js +0 -42
- package/dist/actions/Request.js +0 -65
- package/dist/actions/ResetValidation.js +0 -32
- package/dist/actions/ScrollTo.js +0 -52
- package/dist/actions/SetGlobal.js +0 -35
- package/dist/actions/SetState.js +0 -35
- package/dist/actions/Throw.js +0 -67
- package/dist/actions/Validate.js +0 -37
- package/dist/actions/Wait.js +0 -34
- package/dist/actions/index.js +0 -72
- package/dist/getFieldValues.js +0 -49
- package/dist/makeContextId.js +0 -44
package/dist/Blocks.js
CHANGED
|
@@ -1,625 +1,577 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
414
|
+
toDelete.forEach((field)=>{
|
|
415
|
+
if (!toSet.has(field)) {
|
|
416
|
+
this.context._internal.State.del(field);
|
|
417
|
+
}
|
|
396
418
|
});
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
block
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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
|
-
|
|
462
|
-
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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;
|