@platforma-sdk/model 1.48.14 → 1.49.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/builder.cjs +139 -77
- package/dist/builder.cjs.map +1 -1
- package/dist/builder.d.ts +8 -14
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +139 -77
- package/dist/builder.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +5 -5
- package/src/builder.ts +145 -187
package/src/builder.ts
CHANGED
|
@@ -57,22 +57,28 @@ export class BlockModel<
|
|
|
57
57
|
Href extends `/${string}` = '/',
|
|
58
58
|
> {
|
|
59
59
|
private constructor(
|
|
60
|
-
private
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
private config: {
|
|
61
|
+
readonly renderingMode: BlockRenderingMode;
|
|
62
|
+
readonly initialArgs?: Args;
|
|
63
|
+
readonly initialUiState: UiState;
|
|
64
|
+
readonly outputs: OutputsCfg;
|
|
65
|
+
readonly inputsValid: TypedConfigOrConfigLambda;
|
|
66
|
+
readonly sections: TypedConfigOrConfigLambda;
|
|
67
|
+
readonly title?: ConfigRenderLambda;
|
|
68
|
+
readonly subtitle?: ConfigRenderLambda;
|
|
69
|
+
readonly tags?: ConfigRenderLambda;
|
|
70
|
+
readonly enrichmentTargets?: ConfigRenderLambda;
|
|
71
|
+
readonly featureFlags: BlockCodeKnownFeatureFlags;
|
|
72
|
+
},
|
|
69
73
|
) {}
|
|
70
74
|
|
|
71
|
-
public static
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
public static get INITIAL_BLOCK_FEATURE_FLAGS(): BlockCodeKnownFeatureFlags {
|
|
76
|
+
return {
|
|
77
|
+
supportsLazyState: true,
|
|
78
|
+
requiresUIAPIVersion: 1,
|
|
79
|
+
requiresModelAPIVersion: 1,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
76
82
|
|
|
77
83
|
/** Initiates configuration builder */
|
|
78
84
|
public static create(renderingMode: BlockRenderingMode): BlockModel<NoOb, {}, NoOb>;
|
|
@@ -89,17 +95,14 @@ export class BlockModel<
|
|
|
89
95
|
*/
|
|
90
96
|
public static create<Args>(): BlockModel<Args, {}, NoOb>;
|
|
91
97
|
public static create(renderingMode: BlockRenderingMode = 'Heavy'): BlockModel<NoOb, {}, NoOb> {
|
|
92
|
-
return new BlockModel<NoOb, {}, NoOb>(
|
|
98
|
+
return new BlockModel<NoOb, {}, NoOb>({
|
|
93
99
|
renderingMode,
|
|
94
|
-
|
|
95
|
-
{},
|
|
96
|
-
|
|
97
|
-
getImmediate(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
undefined,
|
|
101
|
-
{ ...BlockModel.INITIAL_BLOCK_FEATURE_FLAGS },
|
|
102
|
-
);
|
|
100
|
+
initialUiState: {},
|
|
101
|
+
outputs: {},
|
|
102
|
+
inputsValid: getImmediate(true),
|
|
103
|
+
sections: getImmediate([]),
|
|
104
|
+
featureFlags: BlockModel.INITIAL_BLOCK_FEATURE_FLAGS,
|
|
105
|
+
});
|
|
103
106
|
}
|
|
104
107
|
|
|
105
108
|
/**
|
|
@@ -140,39 +143,26 @@ export class BlockModel<
|
|
|
140
143
|
if (typeof cfgOrRf === 'function') {
|
|
141
144
|
const handle = `output#${key}`;
|
|
142
145
|
tryRegisterCallback(handle, () => cfgOrRf(new RenderCtx()));
|
|
143
|
-
return new BlockModel(
|
|
144
|
-
this.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
{
|
|
148
|
-
...this._outputs,
|
|
146
|
+
return new BlockModel({
|
|
147
|
+
...this.config,
|
|
148
|
+
outputs: {
|
|
149
|
+
...this.config.outputs,
|
|
149
150
|
[key]: {
|
|
150
151
|
__renderLambda: true,
|
|
151
152
|
handle,
|
|
152
153
|
...flags,
|
|
153
|
-
}
|
|
154
|
+
},
|
|
154
155
|
},
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
} else
|
|
162
|
-
return new BlockModel(
|
|
163
|
-
this._renderingMode,
|
|
164
|
-
this._initialArgs,
|
|
165
|
-
this._initialUiState,
|
|
166
|
-
{
|
|
167
|
-
...this._outputs,
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
return new BlockModel({
|
|
159
|
+
...this.config,
|
|
160
|
+
outputs: {
|
|
161
|
+
...this.config.outputs,
|
|
168
162
|
[key]: cfgOrRf,
|
|
169
163
|
},
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
this._title,
|
|
173
|
-
this._enrichmentTargets,
|
|
174
|
-
this._featureFlags,
|
|
175
|
-
);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
176
166
|
}
|
|
177
167
|
|
|
178
168
|
/** Shortcut for {@link output} with retentive flag set to true. */
|
|
@@ -202,32 +192,19 @@ export class BlockModel<
|
|
|
202
192
|
): BlockModel<Args, OutputsCfg, UiState, `/${string}`> {
|
|
203
193
|
if (typeof cfgOrRf === 'function') {
|
|
204
194
|
tryRegisterCallback('inputsValid', () => cfgOrRf(new RenderCtx()));
|
|
205
|
-
return new BlockModel<Args, OutputsCfg, UiState>(
|
|
206
|
-
this.
|
|
207
|
-
|
|
208
|
-
this._initialUiState,
|
|
209
|
-
this._outputs,
|
|
210
|
-
{
|
|
195
|
+
return new BlockModel<Args, OutputsCfg, UiState>({
|
|
196
|
+
...this.config,
|
|
197
|
+
inputsValid: {
|
|
211
198
|
__renderLambda: true,
|
|
212
199
|
handle: 'inputsValid',
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this._renderingMode,
|
|
222
|
-
this._initialArgs,
|
|
223
|
-
this._initialUiState,
|
|
224
|
-
this._outputs,
|
|
225
|
-
cfgOrRf,
|
|
226
|
-
this._sections,
|
|
227
|
-
this._title,
|
|
228
|
-
this._enrichmentTargets,
|
|
229
|
-
this._featureFlags,
|
|
230
|
-
);
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
203
|
+
return new BlockModel<Args, OutputsCfg, UiState>({
|
|
204
|
+
...this.config,
|
|
205
|
+
inputsValid: cfgOrRf,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
231
208
|
}
|
|
232
209
|
|
|
233
210
|
/** Sets the config to generate list of section in the left block overviews panel
|
|
@@ -255,29 +232,19 @@ export class BlockModel<
|
|
|
255
232
|
return this.sections(getImmediate(arrOrCfgOrRf));
|
|
256
233
|
} else if (typeof arrOrCfgOrRf === 'function') {
|
|
257
234
|
tryRegisterCallback('sections', () => arrOrCfgOrRf(new RenderCtx()));
|
|
258
|
-
return new BlockModel<Args, OutputsCfg, UiState>(
|
|
259
|
-
this.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
this.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
this._renderingMode,
|
|
272
|
-
this._initialArgs,
|
|
273
|
-
this._initialUiState,
|
|
274
|
-
this._outputs,
|
|
275
|
-
this._inputsValid,
|
|
276
|
-
arrOrCfgOrRf as TypedConfig,
|
|
277
|
-
this._title,
|
|
278
|
-
this._enrichmentTargets,
|
|
279
|
-
this._featureFlags,
|
|
280
|
-
);
|
|
235
|
+
return new BlockModel<Args, OutputsCfg, UiState>({
|
|
236
|
+
...this.config,
|
|
237
|
+
sections: {
|
|
238
|
+
__renderLambda: true,
|
|
239
|
+
handle: 'sections',
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
return new BlockModel<Args, OutputsCfg, UiState>({
|
|
244
|
+
...this.config,
|
|
245
|
+
sections: arrOrCfgOrRf as TypedConfig,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
281
248
|
}
|
|
282
249
|
|
|
283
250
|
/** Sets a rendering function to derive block title, shown for the block in the left blocks-overview panel. */
|
|
@@ -285,17 +252,39 @@ export class BlockModel<
|
|
|
285
252
|
rf: RenderFunction<Args, UiState, string>,
|
|
286
253
|
): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
287
254
|
tryRegisterCallback('title', () => rf(new RenderCtx()));
|
|
288
|
-
return new BlockModel<Args, OutputsCfg, UiState, Href>(
|
|
289
|
-
this.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
255
|
+
return new BlockModel<Args, OutputsCfg, UiState, Href>({
|
|
256
|
+
...this.config,
|
|
257
|
+
title: {
|
|
258
|
+
__renderLambda: true,
|
|
259
|
+
handle: 'title',
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public subtitle(
|
|
265
|
+
rf: RenderFunction<Args, UiState, string>,
|
|
266
|
+
): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
267
|
+
tryRegisterCallback('subtitle', () => rf(new RenderCtx()));
|
|
268
|
+
return new BlockModel<Args, OutputsCfg, UiState, Href>({
|
|
269
|
+
...this.config,
|
|
270
|
+
subtitle: {
|
|
271
|
+
__renderLambda: true,
|
|
272
|
+
handle: 'subtitle',
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
public tags(
|
|
278
|
+
rf: RenderFunction<Args, UiState, string[]>,
|
|
279
|
+
): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
280
|
+
tryRegisterCallback('tags', () => rf(new RenderCtx()));
|
|
281
|
+
return new BlockModel<Args, OutputsCfg, UiState, Href>({
|
|
282
|
+
...this.config,
|
|
283
|
+
tags: {
|
|
284
|
+
__renderLambda: true,
|
|
285
|
+
handle: 'tags',
|
|
286
|
+
},
|
|
287
|
+
});
|
|
299
288
|
}
|
|
300
289
|
|
|
301
290
|
/**
|
|
@@ -303,62 +292,34 @@ export class BlockModel<
|
|
|
303
292
|
* @deprecated use {@link withArgs}
|
|
304
293
|
* */
|
|
305
294
|
public initialArgs(value: Args): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
306
|
-
return
|
|
307
|
-
this._renderingMode,
|
|
308
|
-
value,
|
|
309
|
-
this._initialUiState,
|
|
310
|
-
this._outputs,
|
|
311
|
-
this._inputsValid,
|
|
312
|
-
this._sections,
|
|
313
|
-
this._title,
|
|
314
|
-
this._enrichmentTargets,
|
|
315
|
-
this._featureFlags,
|
|
316
|
-
);
|
|
295
|
+
return this.withArgs(value);
|
|
317
296
|
}
|
|
318
297
|
|
|
319
298
|
/** Sets initial args for the block, this value must be specified. */
|
|
320
|
-
public withArgs<Args>(
|
|
321
|
-
return new BlockModel<Args, OutputsCfg, UiState, Href>(
|
|
322
|
-
this.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
this._outputs,
|
|
326
|
-
this._inputsValid,
|
|
327
|
-
this._sections,
|
|
328
|
-
this._title,
|
|
329
|
-
this._enrichmentTargets,
|
|
330
|
-
this._featureFlags,
|
|
331
|
-
);
|
|
299
|
+
public withArgs<Args>(initialArgs: Args): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
300
|
+
return new BlockModel<Args, OutputsCfg, UiState, Href>({
|
|
301
|
+
...this.config,
|
|
302
|
+
initialArgs,
|
|
303
|
+
});
|
|
332
304
|
}
|
|
333
305
|
|
|
334
306
|
/** Defines type and sets initial value for block UiState. */
|
|
335
|
-
public withUiState<UiState>(
|
|
336
|
-
return new BlockModel<Args, OutputsCfg, UiState, Href>(
|
|
337
|
-
this.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
this._outputs,
|
|
341
|
-
this._inputsValid,
|
|
342
|
-
this._sections,
|
|
343
|
-
this._title,
|
|
344
|
-
this._enrichmentTargets,
|
|
345
|
-
this._featureFlags,
|
|
346
|
-
);
|
|
307
|
+
public withUiState<UiState>(initialUiState: UiState): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
308
|
+
return new BlockModel<Args, OutputsCfg, UiState, Href>({
|
|
309
|
+
...this.config,
|
|
310
|
+
initialUiState,
|
|
311
|
+
});
|
|
347
312
|
}
|
|
348
313
|
|
|
349
314
|
/** Sets or overrides feature flags for the block. */
|
|
350
315
|
public withFeatureFlags(flags: Partial<BlockCodeKnownFeatureFlags>): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
351
|
-
return new BlockModel<Args, OutputsCfg, UiState, Href>(
|
|
352
|
-
this.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
this._title,
|
|
359
|
-
this._enrichmentTargets,
|
|
360
|
-
{ ...this._featureFlags, ...flags },
|
|
361
|
-
);
|
|
316
|
+
return new BlockModel<Args, OutputsCfg, UiState, Href>({
|
|
317
|
+
...this.config,
|
|
318
|
+
featureFlags: {
|
|
319
|
+
...this.config.featureFlags,
|
|
320
|
+
...flags,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
362
323
|
}
|
|
363
324
|
|
|
364
325
|
/**
|
|
@@ -369,17 +330,13 @@ export class BlockModel<
|
|
|
369
330
|
lambda: (args: Args) => PlRef[],
|
|
370
331
|
): BlockModel<Args, OutputsCfg, UiState, Href> {
|
|
371
332
|
tryRegisterCallback('enrichmentTargets', lambda);
|
|
372
|
-
return new BlockModel<Args, OutputsCfg, UiState, Href>(
|
|
373
|
-
this.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
this._title,
|
|
380
|
-
{ __renderLambda: true, handle: 'enrichmentTargets' } as ConfigRenderLambda,
|
|
381
|
-
this._featureFlags,
|
|
382
|
-
);
|
|
333
|
+
return new BlockModel<Args, OutputsCfg, UiState, Href>({
|
|
334
|
+
...this.config,
|
|
335
|
+
enrichmentTargets: {
|
|
336
|
+
__renderLambda: true,
|
|
337
|
+
handle: 'enrichmentTargets',
|
|
338
|
+
},
|
|
339
|
+
});
|
|
383
340
|
}
|
|
384
341
|
|
|
385
342
|
public done(apiVersion?: 1): PlatformaV1<
|
|
@@ -399,53 +356,54 @@ export class BlockModel<
|
|
|
399
356
|
/** Renders all provided block settings into a pre-configured platforma API
|
|
400
357
|
* instance, that can be used in frontend to interact with block state, and
|
|
401
358
|
* other features provided by the platforma to the block. */
|
|
402
|
-
public done(apiVersion
|
|
359
|
+
public done(apiVersion: PlatformaApiVersion = 1): Platforma<
|
|
403
360
|
Args,
|
|
404
361
|
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
405
362
|
UiState,
|
|
406
363
|
Href
|
|
407
364
|
> {
|
|
408
|
-
const requiresUIAPIVersion = apiVersion ?? 1;
|
|
409
365
|
return this.withFeatureFlags({
|
|
410
|
-
...this.
|
|
411
|
-
requiresUIAPIVersion,
|
|
412
|
-
})
|
|
366
|
+
...this.config.featureFlags,
|
|
367
|
+
requiresUIAPIVersion: apiVersion,
|
|
368
|
+
}).#done();
|
|
413
369
|
}
|
|
414
370
|
|
|
415
|
-
|
|
371
|
+
#done(): Platforma<
|
|
416
372
|
Args,
|
|
417
373
|
InferOutputsFromConfigs<Args, OutputsCfg, UiState>,
|
|
418
374
|
UiState,
|
|
419
375
|
Href
|
|
420
376
|
> {
|
|
421
|
-
if (this.
|
|
377
|
+
if (this.config.initialArgs === undefined) throw new Error('Initial arguments not set.');
|
|
422
378
|
|
|
423
379
|
const config: BlockConfigContainer = {
|
|
424
380
|
v3: {
|
|
425
381
|
sdkVersion: PlatformaSDKVersion,
|
|
426
|
-
renderingMode: this.
|
|
427
|
-
initialArgs: this.
|
|
428
|
-
initialUiState: this.
|
|
429
|
-
inputsValid: this.
|
|
430
|
-
sections: this.
|
|
431
|
-
title: this.
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
382
|
+
renderingMode: this.config.renderingMode,
|
|
383
|
+
initialArgs: this.config.initialArgs,
|
|
384
|
+
initialUiState: this.config.initialUiState,
|
|
385
|
+
inputsValid: this.config.inputsValid,
|
|
386
|
+
sections: this.config.sections,
|
|
387
|
+
title: this.config.title,
|
|
388
|
+
subtitle: this.config.subtitle,
|
|
389
|
+
tags: this.config.tags,
|
|
390
|
+
outputs: this.config.outputs,
|
|
391
|
+
enrichmentTargets: this.config.enrichmentTargets,
|
|
392
|
+
featureFlags: this.config.featureFlags,
|
|
435
393
|
},
|
|
436
394
|
|
|
437
395
|
// fields below are added to allow previous desktop versions read generated configs
|
|
438
396
|
sdkVersion: PlatformaSDKVersion,
|
|
439
|
-
renderingMode: this.
|
|
440
|
-
initialArgs: this.
|
|
441
|
-
inputsValid: downgradeCfgOrLambda(this.
|
|
442
|
-
sections: downgradeCfgOrLambda(this.
|
|
397
|
+
renderingMode: this.config.renderingMode,
|
|
398
|
+
initialArgs: this.config.initialArgs,
|
|
399
|
+
inputsValid: downgradeCfgOrLambda(this.config.inputsValid),
|
|
400
|
+
sections: downgradeCfgOrLambda(this.config.sections),
|
|
443
401
|
outputs: Object.fromEntries(
|
|
444
|
-
Object.entries(this.
|
|
402
|
+
Object.entries(this.config.outputs).map(([key, value]) => [key, downgradeCfgOrLambda(value)]),
|
|
445
403
|
),
|
|
446
404
|
};
|
|
447
405
|
|
|
448
|
-
globalThis.platformaApiVersion =
|
|
406
|
+
globalThis.platformaApiVersion = this.config.featureFlags.requiresUIAPIVersion as PlatformaApiVersion;
|
|
449
407
|
|
|
450
408
|
if (!isInUI())
|
|
451
409
|
// we are in the configuration rendering routine, not in actual UI
|