@lowdefy/engine 4.7.3 → 5.1.0
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/Block.js +104 -86
- package/dist/Events.js +1 -0
- package/dist/{Areas.js → Slots.js} +45 -45
- package/dist/actions/createCallMethod.js +1 -1
- package/dist/actions/createReset.js +1 -1
- package/dist/actions/createResetValidation.js +1 -1
- package/dist/actions/createSetGlobal.js +1 -1
- package/dist/actions/createSetState.js +1 -1
- package/dist/actions/createValidate.js +1 -1
- package/dist/getContext.js +9 -9
- package/dist/index.js +2 -2
- package/package.json +12 -12
package/dist/Block.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
/*
|
|
2
15
|
Copyright 2020-2026 Lowdefy, Inc
|
|
3
16
|
|
|
@@ -12,22 +25,9 @@
|
|
|
12
25
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
26
|
See the License for the specific language governing permissions and
|
|
14
27
|
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
if (key in obj) {
|
|
17
|
-
Object.defineProperty(obj, key, {
|
|
18
|
-
value: value,
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true
|
|
22
|
-
});
|
|
23
|
-
} else {
|
|
24
|
-
obj[key] = value;
|
|
25
|
-
}
|
|
26
|
-
return obj;
|
|
27
|
-
}
|
|
28
|
-
import { applyArrayIndices, get, serializer, swap, type } from '@lowdefy/helpers';
|
|
28
|
+
*/ import { applyArrayIndices, get, serializer, swap, type } from '@lowdefy/helpers';
|
|
29
29
|
import Events from './Events.js';
|
|
30
|
-
import
|
|
30
|
+
import Slots from './Slots.js';
|
|
31
31
|
let Block = class Block {
|
|
32
32
|
constructor({ context, arrayIndices }, blockConfig){
|
|
33
33
|
_define_property(this, "_initInput", ()=>{
|
|
@@ -39,91 +39,106 @@ let Block = class Block {
|
|
|
39
39
|
};
|
|
40
40
|
});
|
|
41
41
|
_define_property(this, "_initList", ()=>{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
this.unshiftItem = (initialValue)=>{
|
|
43
|
+
// Save current list state before wipe. Display blocks (Card, Paragraph) read
|
|
44
|
+
// from state via _state operators and don't store values internally, so the
|
|
45
|
+
// state wipe below would lose their data without this save/restore.
|
|
46
|
+
const currentArr = get(this.context.state, this.blockId);
|
|
47
|
+
const savedItems = type.isArray(currentArr) ? currentArr.map((item)=>serializer.copy(item)) : [];
|
|
48
|
+
this.loopSubSlots((slotsClass, i)=>{
|
|
49
|
+
slotsClass.recUpdateArrayIndices(this.arrayIndices.concat([
|
|
46
50
|
i
|
|
47
51
|
]), this.arrayIndices.concat([
|
|
48
52
|
i + 1
|
|
49
53
|
]));
|
|
50
54
|
});
|
|
51
|
-
this.
|
|
55
|
+
this.subSlots.unshift(this.newSlots({
|
|
52
56
|
arrayIndices: this.arrayIndices.concat([
|
|
53
57
|
0
|
|
54
58
|
]),
|
|
55
59
|
initState: {}
|
|
56
60
|
}));
|
|
57
61
|
this.context._internal.State.set(this.blockId, undefined);
|
|
58
|
-
// set
|
|
59
|
-
this.
|
|
62
|
+
// set slot block and sub slots values undefined, so as not to pass values to new blocks
|
|
63
|
+
this.subSlots[0].recSetUndefined();
|
|
64
|
+
// Restore shifted items at their new indices
|
|
65
|
+
savedItems.forEach((item, i)=>{
|
|
66
|
+
this.context._internal.State.set(`${this.blockId}.${i + 1}`, item);
|
|
67
|
+
});
|
|
68
|
+
if (initialValue !== undefined) {
|
|
69
|
+
this.context._internal.State.set(`${this.blockId}.0`, initialValue);
|
|
70
|
+
}
|
|
60
71
|
this.update = true;
|
|
61
72
|
this.context._internal.update();
|
|
62
73
|
};
|
|
63
|
-
this.pushItem = ()=>{
|
|
64
|
-
this.
|
|
74
|
+
this.pushItem = (initialValue)=>{
|
|
75
|
+
const index = this.subSlots.length;
|
|
76
|
+
this.subSlots.push(this.newSlots({
|
|
65
77
|
arrayIndices: this.arrayIndices.concat([
|
|
66
|
-
|
|
78
|
+
index
|
|
67
79
|
]),
|
|
68
80
|
initState: {}
|
|
69
81
|
}));
|
|
82
|
+
if (initialValue !== undefined) {
|
|
83
|
+
this.context._internal.State.set(`${this.blockId}.${index}`, initialValue);
|
|
84
|
+
}
|
|
70
85
|
this.update = true;
|
|
71
86
|
this.context._internal.update();
|
|
72
87
|
};
|
|
73
88
|
this.removeItem = (index)=>{
|
|
74
89
|
this.context._internal.State.removeItem(this.blockId, index);
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
const lastSlot = this.subSlots[this.subSlots.length - 1];
|
|
91
|
+
lastSlot.recRemoveBlocksFromMap();
|
|
92
|
+
const largerSlots = this.subSlots.slice(index + 1);
|
|
93
|
+
largerSlots.forEach((slotsClass, i)=>{
|
|
94
|
+
slotsClass.recUpdateArrayIndices(this.arrayIndices.concat([
|
|
80
95
|
index + i + 1
|
|
81
96
|
]), this.arrayIndices.concat([
|
|
82
97
|
index + i
|
|
83
98
|
]));
|
|
84
99
|
});
|
|
85
|
-
this.
|
|
100
|
+
this.subSlots.splice(index, 1);
|
|
86
101
|
this.update = true;
|
|
87
102
|
this.context._internal.update();
|
|
88
103
|
};
|
|
89
104
|
this.moveItemUp = (index)=>{
|
|
90
105
|
if (index === 0) return;
|
|
91
106
|
this.context._internal.State.swapItems(this.blockId, index - 1, index);
|
|
92
|
-
this.
|
|
107
|
+
this.subSlots[index - 1].recUpdateArrayIndices(this.arrayIndices.concat([
|
|
93
108
|
index - 1
|
|
94
109
|
]), this.arrayIndices.concat([
|
|
95
110
|
index
|
|
96
111
|
]));
|
|
97
|
-
this.
|
|
112
|
+
this.subSlots[index].recUpdateArrayIndices(this.arrayIndices.concat([
|
|
98
113
|
index
|
|
99
114
|
]), this.arrayIndices.concat([
|
|
100
115
|
index - 1
|
|
101
116
|
]));
|
|
102
|
-
swap(this.
|
|
117
|
+
swap(this.subSlots, index - 1, index);
|
|
103
118
|
this.update = true;
|
|
104
119
|
this.context._internal.update();
|
|
105
120
|
};
|
|
106
121
|
this.moveItemDown = (index)=>{
|
|
107
|
-
if (index === this.
|
|
122
|
+
if (index === this.subSlots.length - 1) return;
|
|
108
123
|
this.context._internal.State.swapItems(this.blockId, index, index + 1);
|
|
109
|
-
this.
|
|
124
|
+
this.subSlots[index + 1].recUpdateArrayIndices(this.arrayIndices.concat([
|
|
110
125
|
index + 1
|
|
111
126
|
]), this.arrayIndices.concat([
|
|
112
127
|
index
|
|
113
128
|
]));
|
|
114
|
-
this.
|
|
129
|
+
this.subSlots[index].recUpdateArrayIndices(this.arrayIndices.concat([
|
|
115
130
|
index
|
|
116
131
|
]), this.arrayIndices.concat([
|
|
117
132
|
index + 1
|
|
118
133
|
]));
|
|
119
|
-
swap(this.
|
|
134
|
+
swap(this.subSlots, index, index + 1);
|
|
120
135
|
this.update = true;
|
|
121
136
|
this.context._internal.update();
|
|
122
137
|
};
|
|
123
138
|
});
|
|
124
|
-
_define_property(this, "
|
|
125
|
-
if (this.
|
|
126
|
-
this.
|
|
139
|
+
_define_property(this, "loopSubSlots", (fn)=>{
|
|
140
|
+
if (this.subSlots) {
|
|
141
|
+
this.subSlots.forEach(fn);
|
|
127
142
|
}
|
|
128
143
|
});
|
|
129
144
|
_define_property(this, "isDisplay", ()=>{
|
|
@@ -141,16 +156,16 @@ let Block = class Block {
|
|
|
141
156
|
_define_property(this, "registerMethod", (methodName, method)=>{
|
|
142
157
|
this.methods[methodName] = method;
|
|
143
158
|
});
|
|
144
|
-
_define_property(this, "
|
|
145
|
-
const
|
|
159
|
+
_define_property(this, "newSlots", ({ arrayIndices, initState })=>{
|
|
160
|
+
const slotsClass = new Slots({
|
|
146
161
|
arrayIndices,
|
|
147
|
-
|
|
162
|
+
slots: this.slots,
|
|
148
163
|
context: this.context
|
|
149
164
|
});
|
|
150
|
-
|
|
151
|
-
return
|
|
165
|
+
slotsClass.init(initState);
|
|
166
|
+
return slotsClass;
|
|
152
167
|
});
|
|
153
|
-
_define_property(this, "reset", (
|
|
168
|
+
_define_property(this, "reset", (parentSubSlots, initWithState)=>{
|
|
154
169
|
this.update = true;
|
|
155
170
|
this.showValidation = false;
|
|
156
171
|
if (this.isInput() || this.isList()) {
|
|
@@ -160,41 +175,41 @@ let Block = class Block {
|
|
|
160
175
|
this.context._internal.State.set(this.blockId, blockValue);
|
|
161
176
|
}
|
|
162
177
|
if (this.isList()) {
|
|
163
|
-
if (!type.isArray(this.
|
|
164
|
-
this.
|
|
165
|
-
|
|
178
|
+
if (!type.isArray(this.subSlots)) {
|
|
179
|
+
this.subSlots = [];
|
|
180
|
+
parentSubSlots[this.id] = this.subSlots;
|
|
166
181
|
}
|
|
167
182
|
if (type.isArray(blockValue)) {
|
|
168
183
|
blockValue.forEach((item, i)=>{
|
|
169
|
-
if (!this.
|
|
170
|
-
this.
|
|
184
|
+
if (!this.subSlots[i]) {
|
|
185
|
+
this.subSlots.push(this.newSlots({
|
|
171
186
|
arrayIndices: this.arrayIndices.concat([
|
|
172
187
|
i
|
|
173
188
|
]),
|
|
174
189
|
initState: initWithState
|
|
175
190
|
}));
|
|
176
191
|
} else {
|
|
177
|
-
this.
|
|
192
|
+
this.subSlots[i].reset(initWithState);
|
|
178
193
|
}
|
|
179
194
|
});
|
|
180
|
-
this.
|
|
195
|
+
this.subSlots.splice(blockValue.length);
|
|
181
196
|
}
|
|
182
197
|
} else {
|
|
183
198
|
this.value = blockValue;
|
|
184
199
|
}
|
|
185
200
|
}
|
|
186
201
|
if (this.isContainer()) {
|
|
187
|
-
if (!type.isArray(this.
|
|
188
|
-
this.
|
|
189
|
-
|
|
202
|
+
if (!type.isArray(this.subSlots)) {
|
|
203
|
+
this.subSlots = [];
|
|
204
|
+
parentSubSlots[this.id] = this.subSlots;
|
|
190
205
|
}
|
|
191
|
-
if (!this.
|
|
192
|
-
this.
|
|
206
|
+
if (!this.subSlots[0]) {
|
|
207
|
+
this.subSlots.push(this.newSlots({
|
|
193
208
|
arrayIndices: this.arrayIndices,
|
|
194
209
|
initState: initWithState
|
|
195
210
|
}));
|
|
196
211
|
} else {
|
|
197
|
-
this.
|
|
212
|
+
this.subSlots[0].reset(initWithState);
|
|
198
213
|
}
|
|
199
214
|
}
|
|
200
215
|
});
|
|
@@ -216,15 +231,16 @@ let Block = class Block {
|
|
|
216
231
|
this.propertiesEval = this.parse(this.properties);
|
|
217
232
|
this.requiredEval = this.parse(this.required);
|
|
218
233
|
this.validateEval();
|
|
234
|
+
this.classEval = this.parse(this.class);
|
|
219
235
|
this.styleEval = this.parse(this.style);
|
|
220
236
|
this.layoutEval = this.parse(this.layout);
|
|
221
237
|
this.loadingEval = this.parse(this.loading);
|
|
222
238
|
this.skeletonEval = this.parse(this.skeleton);
|
|
223
|
-
this.
|
|
239
|
+
this.slotsLayoutEval = this.parse(this.slotsLayout);
|
|
224
240
|
}
|
|
225
241
|
if (this.isContainer() || this.isList()) {
|
|
226
|
-
this.
|
|
227
|
-
repeat.value =
|
|
242
|
+
this.loopSubSlots((slotsClass)=>{
|
|
243
|
+
repeat.value = slotsClass.recEval(this.visibleEval.output) || repeat.value;
|
|
228
244
|
});
|
|
229
245
|
}
|
|
230
246
|
const after = this.evalToString();
|
|
@@ -298,7 +314,8 @@ let Block = class Block {
|
|
|
298
314
|
});
|
|
299
315
|
_define_property(this, "evalToString", ()=>{
|
|
300
316
|
return serializer.serializeToString({
|
|
301
|
-
|
|
317
|
+
slotsLayoutEval: this.slotsLayoutEval,
|
|
318
|
+
classEval: this.classEval,
|
|
302
319
|
layoutEval: this.layoutEval,
|
|
303
320
|
loadingEval: this.loadingEval,
|
|
304
321
|
propertiesEval: this.propertiesEval,
|
|
@@ -313,8 +330,8 @@ let Block = class Block {
|
|
|
313
330
|
_define_property(this, "updateState", (toSet)=>{
|
|
314
331
|
if (!this.isVisible()) return;
|
|
315
332
|
if (this.isContainer() || this.isList()) {
|
|
316
|
-
if (this.
|
|
317
|
-
this.
|
|
333
|
+
if (this.subSlots && this.subSlots.length > 0) {
|
|
334
|
+
this.loopSubSlots((subSlotsClass)=>subSlotsClass.updateState());
|
|
318
335
|
return; // Don't add to set
|
|
319
336
|
} else {
|
|
320
337
|
this.context._internal.State.set(this.blockId, type.enforceType(this.meta.valueType, null));
|
|
@@ -330,7 +347,7 @@ let Block = class Block {
|
|
|
330
347
|
});
|
|
331
348
|
_define_property(this, "updateArrayIndices", ()=>{
|
|
332
349
|
this.blockId = applyArrayIndices(this.arrayIndices, this.blockIdPattern);
|
|
333
|
-
this.context._internal.
|
|
350
|
+
this.context._internal.RootSlots.map[this.blockId] = this;
|
|
334
351
|
});
|
|
335
352
|
_define_property(this, "getValidate", (match)=>{
|
|
336
353
|
if (!match(this.blockId)) return null;
|
|
@@ -346,7 +363,7 @@ let Block = class Block {
|
|
|
346
363
|
return null;
|
|
347
364
|
});
|
|
348
365
|
_define_property(this, "deleteFromMap", ()=>{
|
|
349
|
-
delete this.context._internal.
|
|
366
|
+
delete this.context._internal.RootSlots.map[this.blockId];
|
|
350
367
|
});
|
|
351
368
|
_define_property(this, "resetValidation", (match)=>{
|
|
352
369
|
if (!match(this.blockId)) return;
|
|
@@ -359,16 +376,18 @@ let Block = class Block {
|
|
|
359
376
|
// Collect parse errors from all eval results
|
|
360
377
|
const parseErrors = [
|
|
361
378
|
...this.propertiesEval.errors || [],
|
|
379
|
+
...this.classEval.errors || [],
|
|
362
380
|
...this.styleEval.errors || [],
|
|
363
381
|
...this.layoutEval.errors || [],
|
|
364
382
|
...this.visibleEval.errors || [],
|
|
365
383
|
...this.loadingEval.errors || [],
|
|
366
384
|
...this.requiredEval.errors || [],
|
|
367
385
|
...this.skeletonEval.errors || [],
|
|
368
|
-
...this.
|
|
386
|
+
...this.slotsLayoutEval.errors || []
|
|
369
387
|
];
|
|
370
388
|
this.eval = {
|
|
371
|
-
|
|
389
|
+
slots: this.slotsLayoutEval.output,
|
|
390
|
+
class: this.classEval.output,
|
|
372
391
|
configKey: this.configKey,
|
|
373
392
|
events: type.isNone(this.Events.events) ? null : this.Events.events,
|
|
374
393
|
parseErrors: parseErrors.length > 0 ? parseErrors : null,
|
|
@@ -387,7 +406,7 @@ let Block = class Block {
|
|
|
387
406
|
};
|
|
388
407
|
this.context._internal.lowdefy._internal.updateBlock(this.id);
|
|
389
408
|
});
|
|
390
|
-
const { id, blockId, events, layout, loading, properties, required, skeleton, style, validate, visible, type: blockType,
|
|
409
|
+
const { id, blockId, class: blockClass, events, layout, loading, properties, required, skeleton, style, validate, visible, type: blockType, slots } = blockConfig;
|
|
391
410
|
this.context = context;
|
|
392
411
|
this.arrayIndices = arrayIndices;
|
|
393
412
|
this.configKey = blockConfig['~k'];
|
|
@@ -401,12 +420,14 @@ let Block = class Block {
|
|
|
401
420
|
this.properties = type.isNone(properties) ? {} : properties;
|
|
402
421
|
this.required = type.isNone(required) ? false : required;
|
|
403
422
|
this.skeleton = type.isNone(skeleton) ? null : skeleton;
|
|
423
|
+
this.class = type.isNone(blockClass) ? {} : blockClass;
|
|
404
424
|
this.style = type.isNone(style) ? {} : style;
|
|
405
425
|
this.validate = type.isNone(validate) ? [] : validate;
|
|
406
426
|
this.visible = type.isNone(visible) ? true : visible;
|
|
407
427
|
this.type = blockType;
|
|
408
|
-
this.
|
|
409
|
-
this.
|
|
428
|
+
this.slots = slots;
|
|
429
|
+
this.slotsLayoutEval = {};
|
|
430
|
+
this.classEval = {};
|
|
410
431
|
this.layoutEval = {};
|
|
411
432
|
this.loadingEval = {};
|
|
412
433
|
this.propertiesEval = {};
|
|
@@ -415,27 +436,24 @@ let Block = class Block {
|
|
|
415
436
|
this.styleEval = {};
|
|
416
437
|
this.validationEval = {};
|
|
417
438
|
this.visibleEval = {};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
throw new Error(`Block type ${this.type} not found at ${this.blockId}. Check your plugins to make sure the block is installed. For more info, see https://docs.lowdefy.com/plugins.`, {
|
|
422
|
-
cause: error
|
|
423
|
-
});
|
|
439
|
+
this.meta = this.context._internal.lowdefy._internal.blockMetas[this.type];
|
|
440
|
+
if (!this.meta) {
|
|
441
|
+
throw new Error(`Block type ${this.type} not found at ${this.blockId}. Check your plugins to make sure the block is installed. For more info, see https://docs.lowdefy.com/plugins.`);
|
|
424
442
|
}
|
|
425
443
|
if (!this.isContainer() && !this.isDisplay() && !this.isInput() && !this.isList()) {
|
|
426
444
|
throw new Error(`Block type ${this.type}.meta.category must be either "container", "display", "input", "list", or "input-container".`);
|
|
427
445
|
}
|
|
428
|
-
if (!type.isNone(
|
|
429
|
-
this.
|
|
430
|
-
Object.keys(
|
|
446
|
+
if (!type.isNone(slots)) {
|
|
447
|
+
this.slotsLayout = {};
|
|
448
|
+
Object.keys(slots).forEach((key)=>{
|
|
431
449
|
// eslint-disable-next-line no-unused-vars
|
|
432
|
-
const { blocks, ...
|
|
433
|
-
this.
|
|
434
|
-
...
|
|
450
|
+
const { blocks, ...slotLayout } = slots[key];
|
|
451
|
+
this.slotsLayout[key] = {
|
|
452
|
+
...slotLayout
|
|
435
453
|
};
|
|
436
454
|
});
|
|
437
455
|
} else {
|
|
438
|
-
this.
|
|
456
|
+
this.slotsLayout = {};
|
|
439
457
|
}
|
|
440
458
|
this.methods = {};
|
|
441
459
|
if (this.isList()) {
|
package/dist/Events.js
CHANGED
|
@@ -19,6 +19,7 @@ let Events = class Events {
|
|
|
19
19
|
actions: (type.isObject(actions) ? actions.try : actions) || [],
|
|
20
20
|
catchActions: (type.isObject(actions) ? actions.catch : []) || [],
|
|
21
21
|
debounce: type.isObject(actions) ? actions.debounce : null,
|
|
22
|
+
shortcut: type.isObject(actions) ? actions.shortcut ?? null : null,
|
|
22
23
|
history: [],
|
|
23
24
|
loading: false
|
|
24
25
|
};
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
/* eslint-disable no-param-reassign */ /*
|
|
2
15
|
Copyright 2020-2026 Lowdefy, Inc
|
|
3
16
|
|
|
@@ -12,59 +25,46 @@
|
|
|
12
25
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
26
|
See the License for the specific language governing permissions and
|
|
14
27
|
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
if (key in obj) {
|
|
17
|
-
Object.defineProperty(obj, key, {
|
|
18
|
-
value: value,
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true
|
|
22
|
-
});
|
|
23
|
-
} else {
|
|
24
|
-
obj[key] = value;
|
|
25
|
-
}
|
|
26
|
-
return obj;
|
|
27
|
-
}
|
|
28
|
-
import { serializer, type } from '@lowdefy/helpers';
|
|
28
|
+
*/ import { serializer, type } from '@lowdefy/helpers';
|
|
29
29
|
import Block from './Block.js';
|
|
30
|
-
let
|
|
31
|
-
constructor({ arrayIndices = [],
|
|
30
|
+
let Slots = class Slots {
|
|
31
|
+
constructor({ arrayIndices = [], slots, context }){
|
|
32
32
|
_define_property(this, "init", (initState)=>{
|
|
33
|
-
this.
|
|
33
|
+
this.initSlotBlocks();
|
|
34
34
|
this.loopBlocks((block)=>{
|
|
35
|
-
this.context._internal.
|
|
35
|
+
this.context._internal.RootSlots.map[block.blockId] = block;
|
|
36
36
|
});
|
|
37
37
|
this.reset(initState);
|
|
38
38
|
});
|
|
39
|
-
// Replace
|
|
40
|
-
_define_property(this, "
|
|
41
|
-
if (type.isObject(this.
|
|
42
|
-
Object.values(this.
|
|
43
|
-
// Handle
|
|
44
|
-
const blocksConfig =
|
|
45
|
-
const blocks = blocksConfig.map((
|
|
46
|
-
|
|
39
|
+
// Replace Slot blocks array with Block instances
|
|
40
|
+
_define_property(this, "initSlotBlocks", ()=>{
|
|
41
|
+
if (type.isObject(this.slots)) {
|
|
42
|
+
Object.values(this.slots).forEach((slot)=>{
|
|
43
|
+
// Handle slots with no blocks - render as empty
|
|
44
|
+
const blocksConfig = slot.blocks ?? [];
|
|
45
|
+
const blocks = blocksConfig.map((slotBlock)=>new Block(this, slotBlock));
|
|
46
|
+
slot.blocks = blocks;
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
_define_property(this, "loopBlocks", (fn)=>{
|
|
51
|
-
if (type.isObject(this.
|
|
52
|
-
Object.values(this.
|
|
53
|
-
if (type.isArray(
|
|
54
|
-
|
|
51
|
+
if (type.isObject(this.slots)) {
|
|
52
|
+
Object.values(this.slots).forEach((slotArray)=>{
|
|
53
|
+
if (type.isArray(slotArray.blocks)) {
|
|
54
|
+
slotArray.blocks.forEach(fn);
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
|
-
_define_property(this, "
|
|
60
|
-
Object.values(this.
|
|
61
|
-
|
|
59
|
+
_define_property(this, "loopSubSlots", (fn)=>{
|
|
60
|
+
Object.values(this.subSlots).forEach((subSlotsArray)=>{
|
|
61
|
+
subSlotsArray.forEach(fn);
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
_define_property(this, "reset", (initWithState)=>{
|
|
65
65
|
const initState = serializer.copy(initWithState || this.context.state);
|
|
66
66
|
this.loopBlocks((block)=>{
|
|
67
|
-
block.reset(this.
|
|
67
|
+
block.reset(this.subSlots, initState);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
_define_property(this, "recEval", (visibleParent)=>{
|
|
@@ -80,7 +80,7 @@ let Areas = class Areas {
|
|
|
80
80
|
this.loopBlocks((block)=>{
|
|
81
81
|
if (!block.isVisible()) {
|
|
82
82
|
if (block.isContainer()) {
|
|
83
|
-
block.
|
|
83
|
+
block.loopSubSlots((subSlotsClass)=>subSlotsClass.recContainerDelState(toDelete));
|
|
84
84
|
}
|
|
85
85
|
toDelete.add(block.blockId);
|
|
86
86
|
} else {
|
|
@@ -94,7 +94,7 @@ let Areas = class Areas {
|
|
|
94
94
|
_define_property(this, "recContainerDelState", (toDelete)=>{
|
|
95
95
|
this.loopBlocks((block)=>{
|
|
96
96
|
if (block.isContainer()) {
|
|
97
|
-
block.
|
|
97
|
+
block.loopSubSlots((subSlotsClass)=>subSlotsClass.recContainerDelState(toDelete));
|
|
98
98
|
} else {
|
|
99
99
|
toDelete.add(block.blockId);
|
|
100
100
|
}
|
|
@@ -114,25 +114,25 @@ let Areas = class Areas {
|
|
|
114
114
|
this.arrayIndices[i] = newIndices[i];
|
|
115
115
|
});
|
|
116
116
|
this.loopBlocks((block)=>block.updateArrayIndices());
|
|
117
|
-
this.
|
|
117
|
+
this.loopSubSlots((subSlotsClass)=>subSlotsClass.recUpdateArrayIndices(oldIndices, newIndices));
|
|
118
118
|
});
|
|
119
119
|
_define_property(this, "getValidateRec", (match, result)=>{
|
|
120
120
|
this.loopBlocks((block)=>{
|
|
121
121
|
const getValidate = block.getValidate(match);
|
|
122
122
|
if (!type.isNone(getValidate)) result.push(getValidate);
|
|
123
123
|
});
|
|
124
|
-
this.
|
|
124
|
+
this.loopSubSlots((subSlotsClass)=>subSlotsClass.getValidateRec(match, result));
|
|
125
125
|
return result;
|
|
126
126
|
});
|
|
127
127
|
_define_property(this, "recSetUndefined", ()=>{
|
|
128
128
|
this.loopBlocks((block)=>{
|
|
129
129
|
this.context._internal.State.set(block.blockId, undefined);
|
|
130
130
|
});
|
|
131
|
-
this.
|
|
131
|
+
this.loopSubSlots((subSlotsClass)=>subSlotsClass.recSetUndefined());
|
|
132
132
|
});
|
|
133
133
|
_define_property(this, "recRemoveBlocksFromMap", ()=>{
|
|
134
134
|
this.loopBlocks((block)=>block.deleteFromMap());
|
|
135
|
-
this.
|
|
135
|
+
this.loopSubSlots((subSlotsClass)=>subSlotsClass.recRemoveBlocksFromMap());
|
|
136
136
|
});
|
|
137
137
|
_define_property(this, "validate", (match)=>{
|
|
138
138
|
this.updateStateFromRoot(); // update to recalculate validationEval to raise block errors
|
|
@@ -142,7 +142,7 @@ let Areas = class Areas {
|
|
|
142
142
|
});
|
|
143
143
|
_define_property(this, "resetValidationRec", (match)=>{
|
|
144
144
|
this.loopBlocks((block)=>block.resetValidation(match));
|
|
145
|
-
this.
|
|
145
|
+
this.loopSubSlots((subSlotsClass)=>subSlotsClass.resetValidationRec(match));
|
|
146
146
|
});
|
|
147
147
|
_define_property(this, "resetValidation", (match)=>{
|
|
148
148
|
this.resetValidationRec(match);
|
|
@@ -154,15 +154,15 @@ let Areas = class Areas {
|
|
|
154
154
|
});
|
|
155
155
|
_define_property(this, "renderBlocks", ()=>{
|
|
156
156
|
this.loopBlocks((block)=>block.render());
|
|
157
|
-
this.
|
|
157
|
+
this.loopSubSlots((subSlotsClass)=>subSlotsClass.renderBlocks());
|
|
158
158
|
});
|
|
159
159
|
this.id = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 5);
|
|
160
|
-
this.
|
|
160
|
+
this.slots = serializer.copy(slots || []);
|
|
161
161
|
this.arrayIndices = arrayIndices;
|
|
162
162
|
this.context = context;
|
|
163
163
|
this.map = {};
|
|
164
164
|
this.recCount = 0;
|
|
165
|
-
this.
|
|
165
|
+
this.subSlots = {};
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
export default
|
|
168
|
+
export default Slots;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
function createCallMethod({ arrayIndices, context }) {
|
|
17
17
|
return function callMethod(params) {
|
|
18
18
|
const { blockId, method, args = [] } = params;
|
|
19
|
-
const blockMethod = context._internal.
|
|
19
|
+
const blockMethod = context._internal.RootSlots.map[applyArrayIndices(arrayIndices, blockId)].methods[method];
|
|
20
20
|
if (!type.isArray(args)) {
|
|
21
21
|
throw new Error(`Failed to call method "${method}" on block "${blockId}": "args" should be an array.`);
|
|
22
22
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
function createReset({ context }) {
|
|
17
17
|
return function reset() {
|
|
18
18
|
context._internal.State.resetState();
|
|
19
|
-
context._internal.
|
|
19
|
+
context._internal.RootSlots.reset(serializer.deserializeFromString(context._internal.State.frozenState));
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
export default createReset;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/ import getBlockMatcher from '../getBlockMatcher.js';
|
|
16
16
|
function createResetValidation({ context }) {
|
|
17
17
|
return function resetValidation(params) {
|
|
18
|
-
context._internal.
|
|
18
|
+
context._internal.RootSlots.resetValidation(getBlockMatcher(params));
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
export default createResetValidation;
|
|
@@ -18,7 +18,7 @@ const createSetGlobal = ({ arrayIndices, context })=>{
|
|
|
18
18
|
Object.keys(params).forEach((key)=>{
|
|
19
19
|
set(context._internal.lowdefy.lowdefyGlobal, applyArrayIndices(arrayIndices, key), params[key]);
|
|
20
20
|
});
|
|
21
|
-
context._internal.
|
|
21
|
+
context._internal.RootSlots.reset();
|
|
22
22
|
context._internal.update();
|
|
23
23
|
};
|
|
24
24
|
};
|
|
@@ -18,7 +18,7 @@ function createSetState({ arrayIndices, context }) {
|
|
|
18
18
|
Object.keys(params).forEach((key)=>{
|
|
19
19
|
context._internal.State.set(applyArrayIndices(arrayIndices, key), params[key]);
|
|
20
20
|
});
|
|
21
|
-
context._internal.
|
|
21
|
+
context._internal.RootSlots.reset();
|
|
22
22
|
context._internal.update();
|
|
23
23
|
};
|
|
24
24
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import getBlockMatcher from '../getBlockMatcher.js';
|
|
17
17
|
function createValidate({ context }) {
|
|
18
18
|
return function validate(params) {
|
|
19
|
-
const validationErrors = context._internal.
|
|
19
|
+
const validationErrors = context._internal.RootSlots.validate(getBlockMatcher(params));
|
|
20
20
|
if (validationErrors.length > 0) {
|
|
21
21
|
throw new UserError(`Your input has ${validationErrors.length} validation error${validationErrors.length !== 1 ? 's' : ''}.`);
|
|
22
22
|
}
|
package/dist/getContext.js
CHANGED
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { WebParser } from '@lowdefy/operators';
|
|
16
16
|
import Actions from './Actions.js';
|
|
17
|
-
import
|
|
17
|
+
import Slots from './Slots.js';
|
|
18
18
|
import Requests from './Requests.js';
|
|
19
19
|
import State from './State.js';
|
|
20
20
|
const blockData = (config)=>{
|
|
21
|
-
const {
|
|
21
|
+
const { slots, blockId, blocks, events, field, id, layout, pageId, properties, requests, required, style, type, validate, visible } = config;
|
|
22
22
|
const result = {
|
|
23
|
-
|
|
23
|
+
slots,
|
|
24
24
|
blockId,
|
|
25
25
|
blocks,
|
|
26
26
|
events,
|
|
@@ -85,8 +85,8 @@ function getContext({ config, jsMap = {}, lowdefy, resetContext = {
|
|
|
85
85
|
_internal.State = new State(ctx);
|
|
86
86
|
_internal.Actions = new Actions(ctx);
|
|
87
87
|
_internal.Requests = new Requests(ctx);
|
|
88
|
-
_internal.
|
|
89
|
-
|
|
88
|
+
_internal.RootSlots = new Slots({
|
|
89
|
+
slots: {
|
|
90
90
|
root: {
|
|
91
91
|
blocks: [
|
|
92
92
|
_internal.rootBlock
|
|
@@ -95,14 +95,14 @@ function getContext({ config, jsMap = {}, lowdefy, resetContext = {
|
|
|
95
95
|
},
|
|
96
96
|
context: ctx
|
|
97
97
|
});
|
|
98
|
-
_internal.
|
|
98
|
+
_internal.RootSlots.init();
|
|
99
99
|
_internal.update = ()=>{
|
|
100
|
-
_internal.
|
|
100
|
+
_internal.RootSlots.update();
|
|
101
101
|
};
|
|
102
102
|
_internal.runOnInit = async (progress)=>{
|
|
103
103
|
progress();
|
|
104
104
|
if (!_internal.onInitDone) {
|
|
105
|
-
await _internal.
|
|
105
|
+
await _internal.RootSlots.slots.root.blocks[0].triggerEvent({
|
|
106
106
|
name: 'onInit',
|
|
107
107
|
progress
|
|
108
108
|
});
|
|
@@ -113,7 +113,7 @@ function getContext({ config, jsMap = {}, lowdefy, resetContext = {
|
|
|
113
113
|
};
|
|
114
114
|
_internal.runOnInitAsync = async (progress)=>{
|
|
115
115
|
if (_internal.onInitDone && !_internal.onInitAsyncDone) {
|
|
116
|
-
await _internal.
|
|
116
|
+
await _internal.RootSlots.slots.root.blocks[0].triggerEvent({
|
|
117
117
|
name: 'onInitAsync',
|
|
118
118
|
progress
|
|
119
119
|
});
|
package/dist/index.js
CHANGED
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import Actions from './Actions.js';
|
|
16
|
-
import
|
|
16
|
+
import Slots from './Slots.js';
|
|
17
17
|
import createLink from './createLink.js';
|
|
18
18
|
import Events from './Events.js';
|
|
19
19
|
import getContext from './getContext.js';
|
|
20
20
|
import Requests from './Requests.js';
|
|
21
21
|
import State from './State.js';
|
|
22
|
-
export { Actions,
|
|
22
|
+
export { Actions, Slots, createLink, Events, Requests, State };
|
|
23
23
|
export default getContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -30,26 +30,26 @@
|
|
|
30
30
|
"dist/*"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lowdefy/errors": "
|
|
34
|
-
"@lowdefy/helpers": "
|
|
35
|
-
"@lowdefy/operators": "
|
|
33
|
+
"@lowdefy/errors": "5.1.0",
|
|
34
|
+
"@lowdefy/helpers": "5.1.0",
|
|
35
|
+
"@lowdefy/operators": "5.1.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@jest/globals": "28.1.3",
|
|
39
|
-
"@lowdefy/actions-core": "
|
|
40
|
-
"@lowdefy/build": "
|
|
41
|
-
"@lowdefy/operators-js": "
|
|
42
|
-
"@lowdefy/operators-mql": "
|
|
43
|
-
"@swc/cli": "0.
|
|
44
|
-
"@swc/core": "1.
|
|
45
|
-
"@swc/jest": "0.2.
|
|
39
|
+
"@lowdefy/actions-core": "5.1.0",
|
|
40
|
+
"@lowdefy/build": "5.1.0",
|
|
41
|
+
"@lowdefy/operators-js": "5.1.0",
|
|
42
|
+
"@lowdefy/operators-mql": "5.1.0",
|
|
43
|
+
"@swc/cli": "0.8.0",
|
|
44
|
+
"@swc/core": "1.15.18",
|
|
45
|
+
"@swc/jest": "0.2.39",
|
|
46
46
|
"jest": "28.1.3"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
|
-
"build": "swc src --out-dir dist --config-file ../../.swcrc --
|
|
52
|
+
"build": "swc src --out-dir dist --config-file ../../.swcrc --cli-config-file ../../.swc-cli.json",
|
|
53
53
|
"clean": "rm -rf dist",
|
|
54
54
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
55
55
|
}
|