@platforma-sdk/model 1.54.10 → 1.55.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/bconfig/normalization.cjs +8 -1
- package/dist/bconfig/normalization.cjs.map +1 -1
- package/dist/bconfig/normalization.d.ts.map +1 -1
- package/dist/bconfig/normalization.js +8 -1
- package/dist/bconfig/normalization.js.map +1 -1
- package/dist/block_api_v3.d.ts +2 -2
- package/dist/block_api_v3.d.ts.map +1 -1
- package/dist/block_migrations.cjs +246 -214
- package/dist/block_migrations.cjs.map +1 -1
- package/dist/block_migrations.d.ts +180 -158
- package/dist/block_migrations.d.ts.map +1 -1
- package/dist/block_migrations.js +247 -214
- package/dist/block_migrations.js.map +1 -1
- package/dist/block_model.cjs +85 -35
- package/dist/block_model.cjs.map +1 -1
- package/dist/block_model.d.ts +66 -38
- package/dist/block_model.d.ts.map +1 -1
- package/dist/block_model.js +86 -36
- package/dist/block_model.js.map +1 -1
- package/dist/{builder.cjs → block_model_legacy.cjs} +2 -2
- package/dist/block_model_legacy.cjs.map +1 -0
- package/dist/{builder.d.ts → block_model_legacy.d.ts} +1 -1
- package/dist/block_model_legacy.d.ts.map +1 -0
- package/dist/{builder.js → block_model_legacy.js} +2 -2
- package/dist/block_model_legacy.js.map +1 -0
- package/dist/block_state_patch.d.ts +11 -1
- package/dist/block_state_patch.d.ts.map +1 -1
- package/dist/block_storage.cjs +126 -109
- package/dist/block_storage.cjs.map +1 -1
- package/dist/block_storage.d.ts +109 -112
- package/dist/block_storage.d.ts.map +1 -1
- package/dist/block_storage.js +126 -101
- package/dist/block_storage.js.map +1 -1
- package/dist/block_storage_callbacks.cjs +227 -0
- package/dist/block_storage_callbacks.cjs.map +1 -0
- package/dist/block_storage_callbacks.d.ts +113 -0
- package/dist/block_storage_callbacks.d.ts.map +1 -0
- package/dist/block_storage_callbacks.js +218 -0
- package/dist/block_storage_callbacks.js.map +1 -0
- package/dist/block_storage_facade.cjs +104 -0
- package/dist/block_storage_facade.cjs.map +1 -0
- package/dist/block_storage_facade.d.ts +168 -0
- package/dist/block_storage_facade.d.ts.map +1 -0
- package/dist/block_storage_facade.js +99 -0
- package/dist/block_storage_facade.js.map +1 -0
- package/dist/components/PlDataTable/state-migration.cjs.map +1 -1
- package/dist/components/PlDataTable/state-migration.js.map +1 -1
- package/dist/components/PlDataTable/table.cjs +11 -2
- package/dist/components/PlDataTable/table.cjs.map +1 -1
- package/dist/components/PlDataTable/table.d.ts.map +1 -1
- package/dist/components/PlDataTable/table.js +12 -3
- package/dist/components/PlDataTable/table.js.map +1 -1
- package/dist/components/PlDataTable/v5.d.ts +7 -4
- package/dist/components/PlDataTable/v5.d.ts.map +1 -1
- package/dist/filters/converters/filterToQuery.cjs +3 -4
- package/dist/filters/converters/filterToQuery.cjs.map +1 -1
- package/dist/filters/converters/filterToQuery.d.ts +1 -1
- package/dist/filters/converters/filterToQuery.d.ts.map +1 -1
- package/dist/filters/converters/filterToQuery.js +3 -4
- package/dist/filters/converters/filterToQuery.js.map +1 -1
- package/dist/filters/distill.cjs.map +1 -1
- package/dist/filters/distill.d.ts +3 -2
- package/dist/filters/distill.d.ts.map +1 -1
- package/dist/filters/distill.js.map +1 -1
- package/dist/filters/traverse.cjs +7 -3
- package/dist/filters/traverse.cjs.map +1 -1
- package/dist/filters/traverse.d.ts +14 -12
- package/dist/filters/traverse.d.ts.map +1 -1
- package/dist/filters/traverse.js +7 -3
- package/dist/filters/traverse.js.map +1 -1
- package/dist/index.cjs +13 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/platforma.d.ts +11 -4
- package/dist/platforma.d.ts.map +1 -1
- package/dist/plugin_model.cjs +171 -0
- package/dist/plugin_model.cjs.map +1 -0
- package/dist/plugin_model.d.ts +162 -0
- package/dist/plugin_model.d.ts.map +1 -0
- package/dist/plugin_model.js +169 -0
- package/dist/plugin_model.js.map +1 -0
- package/dist/render/api.cjs +20 -21
- package/dist/render/api.cjs.map +1 -1
- package/dist/render/api.d.ts +8 -8
- package/dist/render/api.d.ts.map +1 -1
- package/dist/render/api.js +20 -21
- package/dist/render/api.js.map +1 -1
- package/dist/render/internal.cjs.map +1 -1
- package/dist/render/internal.d.ts +1 -1
- package/dist/render/internal.d.ts.map +1 -1
- package/dist/render/internal.js.map +1 -1
- package/dist/version.cjs +4 -0
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.ts +4 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +4 -1
- package/dist/version.js.map +1 -1
- package/package.json +6 -6
- package/src/bconfig/normalization.ts +8 -1
- package/src/block_api_v3.ts +2 -2
- package/src/block_migrations.test.ts +141 -171
- package/src/block_migrations.ts +300 -285
- package/src/block_model.ts +205 -95
- package/src/{builder.ts → block_model_legacy.ts} +1 -1
- package/src/block_state_patch.ts +13 -1
- package/src/block_storage.test.ts +283 -95
- package/src/block_storage.ts +199 -188
- package/src/block_storage_callbacks.ts +326 -0
- package/src/block_storage_facade.ts +199 -0
- package/src/components/PlDataTable/state-migration.ts +4 -4
- package/src/components/PlDataTable/table.ts +16 -3
- package/src/components/PlDataTable/v5.ts +9 -5
- package/src/filters/converters/filterToQuery.ts +8 -7
- package/src/filters/distill.ts +19 -11
- package/src/filters/traverse.ts +44 -24
- package/src/index.ts +7 -3
- package/src/platforma.ts +26 -7
- package/src/plugin_model.test.ts +168 -0
- package/src/plugin_model.ts +242 -0
- package/src/render/api.ts +26 -24
- package/src/render/internal.ts +1 -1
- package/src/typing.test.ts +1 -1
- package/src/version.ts +8 -0
- package/dist/block_storage_vm.cjs +0 -262
- package/dist/block_storage_vm.cjs.map +0 -1
- package/dist/block_storage_vm.d.ts +0 -59
- package/dist/block_storage_vm.d.ts.map +0 -1
- package/dist/block_storage_vm.js +0 -258
- package/dist/block_storage_vm.js.map +0 -1
- package/dist/branding.d.ts +0 -7
- package/dist/branding.d.ts.map +0 -1
- package/dist/builder.cjs.map +0 -1
- package/dist/builder.d.ts.map +0 -1
- package/dist/builder.js.map +0 -1
- package/dist/sdk_info.cjs +0 -10
- package/dist/sdk_info.cjs.map +0 -1
- package/dist/sdk_info.d.ts +0 -5
- package/dist/sdk_info.d.ts.map +0 -1
- package/dist/sdk_info.js +0 -8
- package/dist/sdk_info.js.map +0 -1
- package/dist/unionize.d.ts +0 -12
- package/dist/unionize.d.ts.map +0 -1
- package/src/block_storage_vm.ts +0 -346
- package/src/branding.ts +0 -4
- package/src/sdk_info.ts +0 -9
- package/src/unionize.ts +0 -12
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PluginModel - Builder for creating plugin types with data model and outputs.
|
|
5
|
+
*
|
|
6
|
+
* Plugins are UI components with their own model logic and persistent state.
|
|
7
|
+
* Block developers register plugin instances via BlockModelV3.plugin() method.
|
|
8
|
+
*
|
|
9
|
+
* @module plugin_model
|
|
10
|
+
*/
|
|
11
|
+
/** Symbol for internal builder creation method */
|
|
12
|
+
const FROM_BUILDER = Symbol("fromBuilder");
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Plugin Type
|
|
15
|
+
// =============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Configured plugin instance returned by PluginModelFactory.create().
|
|
18
|
+
* Contains the plugin's name, data model, and output definitions.
|
|
19
|
+
*/
|
|
20
|
+
class PluginModel {
|
|
21
|
+
/** Globally unique plugin name */
|
|
22
|
+
name;
|
|
23
|
+
/** Data model instance for this plugin */
|
|
24
|
+
dataModel;
|
|
25
|
+
/** Output definitions - functions that compute outputs from plugin context */
|
|
26
|
+
outputs;
|
|
27
|
+
constructor(input) {
|
|
28
|
+
this.name = input.name;
|
|
29
|
+
this.dataModel = input.dataModel;
|
|
30
|
+
this.outputs = input.outputs;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Internal method for creating PluginModel from factory.
|
|
34
|
+
* Uses Symbol key to prevent external access.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
static [FROM_BUILDER](input) {
|
|
38
|
+
return new this(input);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new PluginModelBuilder for building plugin definitions.
|
|
42
|
+
*
|
|
43
|
+
* @param options.name - Globally unique plugin name
|
|
44
|
+
* @param options.data - Factory function that creates the data model from config
|
|
45
|
+
* @returns PluginModelBuilder for chaining output definitions
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const dataModelChain = new DataModelBuilder().from<MyData>(DATA_MODEL_DEFAULT_VERSION);
|
|
49
|
+
*
|
|
50
|
+
* const myPlugin = PluginModel.define<MyData, MyParams, MyConfig>({
|
|
51
|
+
* name: 'myPlugin' as PluginName,
|
|
52
|
+
* data: (cfg) => dataModelChain.init(() => ({ value: cfg.defaultValue })),
|
|
53
|
+
* })
|
|
54
|
+
* .output('computed', (ctx) => ctx.data.value * ctx.params.multiplier)
|
|
55
|
+
* .build();
|
|
56
|
+
*/
|
|
57
|
+
static define(options) {
|
|
58
|
+
return PluginModelBuilder[FROM_BUILDER](options);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Plugin factory returned by PluginModelBuilder.build().
|
|
63
|
+
* Call create() with config to get a configured PluginModel instance.
|
|
64
|
+
*/
|
|
65
|
+
class PluginModelFactory {
|
|
66
|
+
name;
|
|
67
|
+
data;
|
|
68
|
+
outputs;
|
|
69
|
+
constructor(input) {
|
|
70
|
+
this.name = input.name;
|
|
71
|
+
this.data = input.data;
|
|
72
|
+
this.outputs = input.outputs;
|
|
73
|
+
}
|
|
74
|
+
/** Create a configured PluginModel instance */
|
|
75
|
+
create(config) {
|
|
76
|
+
return PluginModel[FROM_BUILDER]({
|
|
77
|
+
name: this.name,
|
|
78
|
+
dataModel: this.data(config),
|
|
79
|
+
outputs: this.outputs,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// =============================================================================
|
|
84
|
+
// Plugin Model Builder
|
|
85
|
+
// =============================================================================
|
|
86
|
+
/**
|
|
87
|
+
* Builder for creating PluginType with type-safe output definitions.
|
|
88
|
+
*
|
|
89
|
+
* Use `PluginModel.define()` to create a builder instance.
|
|
90
|
+
*
|
|
91
|
+
* @typeParam Data - Plugin's persistent data type
|
|
92
|
+
* @typeParam Params - Params derived from block's RenderCtx (optional)
|
|
93
|
+
* @typeParam Config - Static configuration passed to plugin factory (optional)
|
|
94
|
+
* @typeParam Outputs - Accumulated output types
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* const dataModelChain = new DataModelBuilder().from<TableData>(DATA_MODEL_DEFAULT_VERSION);
|
|
98
|
+
*
|
|
99
|
+
* const dataTable = PluginModel.define<TableData, TableParams, TableConfig>({
|
|
100
|
+
* name: 'dataTable' as PluginName,
|
|
101
|
+
* data: (cfg) => {
|
|
102
|
+
* return dataModelChain.init(() => ({ state: createInitialState(cfg.ops) }));
|
|
103
|
+
* },
|
|
104
|
+
* })
|
|
105
|
+
* .output('model', (ctx) => createTableModel(ctx))
|
|
106
|
+
* .build();
|
|
107
|
+
*/
|
|
108
|
+
class PluginModelBuilder {
|
|
109
|
+
name;
|
|
110
|
+
data;
|
|
111
|
+
outputs;
|
|
112
|
+
constructor(input) {
|
|
113
|
+
this.name = input.name;
|
|
114
|
+
this.data = input.data;
|
|
115
|
+
this.outputs =
|
|
116
|
+
input.outputs ??
|
|
117
|
+
{};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Internal method for creating PluginModelBuilder.
|
|
121
|
+
* Uses Symbol key to prevent external access.
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
static [FROM_BUILDER](input) {
|
|
125
|
+
return new this(input);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Adds an output to the plugin.
|
|
129
|
+
*
|
|
130
|
+
* @param key - Output name
|
|
131
|
+
* @param fn - Function that computes the output value from plugin context
|
|
132
|
+
* @returns PluginModel with the new output added
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* .output('model', (ctx) => createModel(ctx.params.columns, ctx.data.state))
|
|
136
|
+
* .output('isReady', (ctx) => ctx.params.columns !== undefined)
|
|
137
|
+
*/
|
|
138
|
+
output(key, fn) {
|
|
139
|
+
return new PluginModelBuilder({
|
|
140
|
+
name: this.name,
|
|
141
|
+
data: this.data,
|
|
142
|
+
outputs: {
|
|
143
|
+
...this.outputs,
|
|
144
|
+
[key]: fn,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Finalizes the plugin definition and returns a ConfigurablePluginModel.
|
|
150
|
+
*
|
|
151
|
+
* @returns Callable plugin factory that accepts config and returns PluginModel
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const myPlugin = new PluginModelBuilder('myPlugin', () => dataModel)
|
|
155
|
+
* .output('value', (ctx) => ctx.data.value)
|
|
156
|
+
* .build();
|
|
157
|
+
*
|
|
158
|
+
* // Later, call create() with config to get a configured instance:
|
|
159
|
+
* const configured = myPlugin.create({ defaultValue: 'test' });
|
|
160
|
+
*/
|
|
161
|
+
build() {
|
|
162
|
+
return new PluginModelFactory({
|
|
163
|
+
name: this.name,
|
|
164
|
+
data: this.data,
|
|
165
|
+
outputs: this.outputs,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
exports.PluginModel = PluginModel;
|
|
171
|
+
//# sourceMappingURL=plugin_model.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin_model.cjs","sources":["../src/plugin_model.ts"],"sourcesContent":["/**\n * PluginModel - Builder for creating plugin types with data model and outputs.\n *\n * Plugins are UI components with their own model logic and persistent state.\n * Block developers register plugin instances via BlockModelV3.plugin() method.\n *\n * @module plugin_model\n */\n\nimport type { DataModel } from \"./block_migrations\";\nimport type { PluginName } from \"./block_storage\";\nimport type { ResultPool } from \"./render\";\n\n/** Symbol for internal builder creation method */\nconst FROM_BUILDER = Symbol(\"fromBuilder\");\n\n// =============================================================================\n// Plugin Render Context\n// =============================================================================\n\n/**\n * Context passed to plugin output functions.\n * Provides access to plugin's persistent data, params derived from block context,\n * and the result pool for accessing workflow outputs.\n */\nexport interface PluginRenderCtx<Data, Params = undefined> {\n /** Plugin's persistent data */\n readonly data: Data;\n /** Params derived from block's RenderCtx */\n readonly params: Params;\n /** Result pool for accessing workflow outputs */\n readonly resultPool: ResultPool;\n}\n\n// =============================================================================\n// Plugin Type\n// =============================================================================\n\n/**\n * Configured plugin instance returned by PluginModelFactory.create().\n * Contains the plugin's name, data model, and output definitions.\n */\nexport class PluginModel<Data = unknown, Params = undefined, Outputs = {}> {\n /** Globally unique plugin name */\n readonly name: PluginName;\n /** Data model instance for this plugin */\n readonly dataModel: DataModel<Data>;\n /** Output definitions - functions that compute outputs from plugin context */\n readonly outputs: { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] };\n\n private constructor(input: {\n name: PluginName;\n dataModel: DataModel<Data>;\n outputs: { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] };\n }) {\n this.name = input.name;\n this.dataModel = input.dataModel;\n this.outputs = input.outputs;\n }\n\n /**\n * Internal method for creating PluginModel from factory.\n * Uses Symbol key to prevent external access.\n * @internal\n */\n static [FROM_BUILDER]<D, P, O>(input: {\n name: PluginName;\n dataModel: DataModel<D>;\n outputs: { [K in keyof O]: (ctx: PluginRenderCtx<D, P>) => O[K] };\n }): PluginModel<D, P, O> {\n return new this<D, P, O>(input);\n }\n\n /**\n * Creates a new PluginModelBuilder for building plugin definitions.\n *\n * @param options.name - Globally unique plugin name\n * @param options.data - Factory function that creates the data model from config\n * @returns PluginModelBuilder for chaining output definitions\n *\n * @example\n * const dataModelChain = new DataModelBuilder().from<MyData>(DATA_MODEL_DEFAULT_VERSION);\n *\n * const myPlugin = PluginModel.define<MyData, MyParams, MyConfig>({\n * name: 'myPlugin' as PluginName,\n * data: (cfg) => dataModelChain.init(() => ({ value: cfg.defaultValue })),\n * })\n * .output('computed', (ctx) => ctx.data.value * ctx.params.multiplier)\n * .build();\n */\n static define<Data, Params = undefined, Config = undefined>(options: {\n name: PluginName;\n data: (config?: Config) => DataModel<Data>;\n }): PluginModelBuilder<Data, Params, Config> {\n return PluginModelBuilder[FROM_BUILDER]<Data, Params, Config>(options);\n }\n}\n\n/**\n * Plugin factory returned by PluginModelBuilder.build().\n * Call create() with config to get a configured PluginModel instance.\n */\nclass PluginModelFactory<Data, Params, Config, Outputs> {\n private readonly name: PluginName;\n private readonly data: (config?: Config) => DataModel<Data>;\n private readonly outputs: {\n [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K];\n };\n\n constructor(input: {\n name: PluginName;\n data: (config?: Config) => DataModel<Data>;\n outputs: { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] };\n }) {\n this.name = input.name;\n this.data = input.data;\n this.outputs = input.outputs;\n }\n\n /** Create a configured PluginModel instance */\n create(config?: Config): PluginModel<Data, Params, Outputs> {\n return PluginModel[FROM_BUILDER]<Data, Params, Outputs>({\n name: this.name,\n dataModel: this.data(config),\n outputs: this.outputs,\n });\n }\n}\n\n// =============================================================================\n// Plugin Model Builder\n// =============================================================================\n\n/**\n * Builder for creating PluginType with type-safe output definitions.\n *\n * Use `PluginModel.define()` to create a builder instance.\n *\n * @typeParam Data - Plugin's persistent data type\n * @typeParam Params - Params derived from block's RenderCtx (optional)\n * @typeParam Config - Static configuration passed to plugin factory (optional)\n * @typeParam Outputs - Accumulated output types\n *\n * @example\n * const dataModelChain = new DataModelBuilder().from<TableData>(DATA_MODEL_DEFAULT_VERSION);\n *\n * const dataTable = PluginModel.define<TableData, TableParams, TableConfig>({\n * name: 'dataTable' as PluginName,\n * data: (cfg) => {\n * return dataModelChain.init(() => ({ state: createInitialState(cfg.ops) }));\n * },\n * })\n * .output('model', (ctx) => createTableModel(ctx))\n * .build();\n */\nclass PluginModelBuilder<\n Data,\n Params = undefined,\n Config = undefined,\n Outputs extends Record<string, unknown> = {},\n> {\n private readonly name: PluginName;\n private readonly data: (config?: Config) => DataModel<Data>;\n private readonly outputs: {\n [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K];\n };\n\n private constructor(input: {\n name: PluginName;\n data: (config?: Config) => DataModel<Data>;\n outputs?: { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] };\n }) {\n this.name = input.name;\n this.data = input.data;\n this.outputs =\n input.outputs ??\n ({} as { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] });\n }\n\n /**\n * Internal method for creating PluginModelBuilder.\n * Uses Symbol key to prevent external access.\n * @internal\n */\n static [FROM_BUILDER]<D, P, C, O extends Record<string, unknown> = {}>(input: {\n name: PluginName;\n data: (config?: C) => DataModel<D>;\n outputs?: { [K in keyof O]: (ctx: PluginRenderCtx<D, P>) => O[K] };\n }): PluginModelBuilder<D, P, C, O> {\n return new this<D, P, C, O>(input);\n }\n\n /**\n * Adds an output to the plugin.\n *\n * @param key - Output name\n * @param fn - Function that computes the output value from plugin context\n * @returns PluginModel with the new output added\n *\n * @example\n * .output('model', (ctx) => createModel(ctx.params.columns, ctx.data.state))\n * .output('isReady', (ctx) => ctx.params.columns !== undefined)\n */\n output<const Key extends string, T>(\n key: Key,\n fn: (ctx: PluginRenderCtx<Data, Params>) => T,\n ): PluginModelBuilder<Data, Params, Config, Outputs & { [K in Key]: T }> {\n return new PluginModelBuilder<Data, Params, Config, Outputs & { [K in Key]: T }>({\n name: this.name,\n data: this.data,\n outputs: {\n ...this.outputs,\n [key]: fn,\n } as {\n [K in keyof (Outputs & { [P in Key]: T })]: (\n ctx: PluginRenderCtx<Data, Params>,\n ) => (Outputs & { [P in Key]: T })[K];\n },\n });\n }\n\n /**\n * Finalizes the plugin definition and returns a ConfigurablePluginModel.\n *\n * @returns Callable plugin factory that accepts config and returns PluginModel\n *\n * @example\n * const myPlugin = new PluginModelBuilder('myPlugin', () => dataModel)\n * .output('value', (ctx) => ctx.data.value)\n * .build();\n *\n * // Later, call create() with config to get a configured instance:\n * const configured = myPlugin.create({ defaultValue: 'test' });\n */\n build(): PluginModelFactory<Data, Params, Config, Outputs> {\n return new PluginModelFactory<Data, Params, Config, Outputs>({\n name: this.name,\n data: this.data,\n outputs: this.outputs,\n });\n }\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;AAOG;AAMH;AACA,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC;AAoB1C;AACA;AACA;AAEA;;;AAGG;MACU,WAAW,CAAA;;AAEb,IAAA,IAAI;;AAEJ,IAAA,SAAS;;AAET,IAAA,OAAO;AAEhB,IAAA,WAAA,CAAoB,KAInB,EAAA;AACC,QAAA,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI;AACtB,QAAA,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS;AAChC,QAAA,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO;IAC9B;AAEA;;;;AAIG;AACH,IAAA,QAAQ,YAAY,CAAC,CAAU,KAI9B,EAAA;AACC,QAAA,OAAO,IAAI,IAAI,CAAU,KAAK,CAAC;IACjC;AAEA;;;;;;;;;;;;;;;;AAgBG;IACH,OAAO,MAAM,CAA+C,OAG3D,EAAA;AACC,QAAA,OAAO,kBAAkB,CAAC,YAAY,CAAC,CAAuB,OAAO,CAAC;IACxE;AACD;AAED;;;AAGG;AACH,MAAM,kBAAkB,CAAA;AACL,IAAA,IAAI;AACJ,IAAA,IAAI;AACJ,IAAA,OAAO;AAIxB,IAAA,WAAA,CAAY,KAIX,EAAA;AACC,QAAA,IAAI,CAAC,IAAI,GAAG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,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;AACtB,SAAA,CAAC;IACJ;AACD;;;;"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PluginModel - Builder for creating plugin types with data model and outputs.
|
|
3
|
+
*
|
|
4
|
+
* Plugins are UI components with their own model logic and persistent state.
|
|
5
|
+
* Block developers register plugin instances via BlockModelV3.plugin() method.
|
|
6
|
+
*
|
|
7
|
+
* @module plugin_model
|
|
8
|
+
*/
|
|
9
|
+
import type { DataModel } from "./block_migrations";
|
|
10
|
+
import type { PluginName } from "./block_storage";
|
|
11
|
+
import type { ResultPool } from "./render";
|
|
12
|
+
/** Symbol for internal builder creation method */
|
|
13
|
+
declare const FROM_BUILDER: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* Context passed to plugin output functions.
|
|
16
|
+
* Provides access to plugin's persistent data, params derived from block context,
|
|
17
|
+
* and the result pool for accessing workflow outputs.
|
|
18
|
+
*/
|
|
19
|
+
export interface PluginRenderCtx<Data, Params = undefined> {
|
|
20
|
+
/** Plugin's persistent data */
|
|
21
|
+
readonly data: Data;
|
|
22
|
+
/** Params derived from block's RenderCtx */
|
|
23
|
+
readonly params: Params;
|
|
24
|
+
/** Result pool for accessing workflow outputs */
|
|
25
|
+
readonly resultPool: ResultPool;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Configured plugin instance returned by PluginModelFactory.create().
|
|
29
|
+
* Contains the plugin's name, data model, and output definitions.
|
|
30
|
+
*/
|
|
31
|
+
export declare class PluginModel<Data = unknown, Params = undefined, Outputs = {}> {
|
|
32
|
+
/** Globally unique plugin name */
|
|
33
|
+
readonly name: PluginName;
|
|
34
|
+
/** Data model instance for this plugin */
|
|
35
|
+
readonly dataModel: DataModel<Data>;
|
|
36
|
+
/** Output definitions - functions that compute outputs from plugin context */
|
|
37
|
+
readonly outputs: {
|
|
38
|
+
[K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K];
|
|
39
|
+
};
|
|
40
|
+
private constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Internal method for creating PluginModel from factory.
|
|
43
|
+
* Uses Symbol key to prevent external access.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
static [FROM_BUILDER]<D, P, O>(input: {
|
|
47
|
+
name: PluginName;
|
|
48
|
+
dataModel: DataModel<D>;
|
|
49
|
+
outputs: {
|
|
50
|
+
[K in keyof O]: (ctx: PluginRenderCtx<D, P>) => O[K];
|
|
51
|
+
};
|
|
52
|
+
}): PluginModel<D, P, O>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new PluginModelBuilder for building plugin definitions.
|
|
55
|
+
*
|
|
56
|
+
* @param options.name - Globally unique plugin name
|
|
57
|
+
* @param options.data - Factory function that creates the data model from config
|
|
58
|
+
* @returns PluginModelBuilder for chaining output definitions
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* const dataModelChain = new DataModelBuilder().from<MyData>(DATA_MODEL_DEFAULT_VERSION);
|
|
62
|
+
*
|
|
63
|
+
* const myPlugin = PluginModel.define<MyData, MyParams, MyConfig>({
|
|
64
|
+
* name: 'myPlugin' as PluginName,
|
|
65
|
+
* data: (cfg) => dataModelChain.init(() => ({ value: cfg.defaultValue })),
|
|
66
|
+
* })
|
|
67
|
+
* .output('computed', (ctx) => ctx.data.value * ctx.params.multiplier)
|
|
68
|
+
* .build();
|
|
69
|
+
*/
|
|
70
|
+
static define<Data, Params = undefined, Config = undefined>(options: {
|
|
71
|
+
name: PluginName;
|
|
72
|
+
data: (config?: Config) => DataModel<Data>;
|
|
73
|
+
}): PluginModelBuilder<Data, Params, Config>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Plugin factory returned by PluginModelBuilder.build().
|
|
77
|
+
* Call create() with config to get a configured PluginModel instance.
|
|
78
|
+
*/
|
|
79
|
+
declare class PluginModelFactory<Data, Params, Config, Outputs> {
|
|
80
|
+
private readonly name;
|
|
81
|
+
private readonly data;
|
|
82
|
+
private readonly outputs;
|
|
83
|
+
constructor(input: {
|
|
84
|
+
name: PluginName;
|
|
85
|
+
data: (config?: Config) => DataModel<Data>;
|
|
86
|
+
outputs: {
|
|
87
|
+
[K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K];
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
/** Create a configured PluginModel instance */
|
|
91
|
+
create(config?: Config): PluginModel<Data, Params, Outputs>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Builder for creating PluginType with type-safe output definitions.
|
|
95
|
+
*
|
|
96
|
+
* Use `PluginModel.define()` to create a builder instance.
|
|
97
|
+
*
|
|
98
|
+
* @typeParam Data - Plugin's persistent data type
|
|
99
|
+
* @typeParam Params - Params derived from block's RenderCtx (optional)
|
|
100
|
+
* @typeParam Config - Static configuration passed to plugin factory (optional)
|
|
101
|
+
* @typeParam Outputs - Accumulated output types
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const dataModelChain = new DataModelBuilder().from<TableData>(DATA_MODEL_DEFAULT_VERSION);
|
|
105
|
+
*
|
|
106
|
+
* const dataTable = PluginModel.define<TableData, TableParams, TableConfig>({
|
|
107
|
+
* name: 'dataTable' as PluginName,
|
|
108
|
+
* data: (cfg) => {
|
|
109
|
+
* return dataModelChain.init(() => ({ state: createInitialState(cfg.ops) }));
|
|
110
|
+
* },
|
|
111
|
+
* })
|
|
112
|
+
* .output('model', (ctx) => createTableModel(ctx))
|
|
113
|
+
* .build();
|
|
114
|
+
*/
|
|
115
|
+
declare class PluginModelBuilder<Data, Params = undefined, Config = undefined, Outputs extends Record<string, unknown> = {}> {
|
|
116
|
+
private readonly name;
|
|
117
|
+
private readonly data;
|
|
118
|
+
private readonly outputs;
|
|
119
|
+
private constructor();
|
|
120
|
+
/**
|
|
121
|
+
* Internal method for creating PluginModelBuilder.
|
|
122
|
+
* Uses Symbol key to prevent external access.
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
static [FROM_BUILDER]<D, P, C, O extends Record<string, unknown> = {}>(input: {
|
|
126
|
+
name: PluginName;
|
|
127
|
+
data: (config?: C) => DataModel<D>;
|
|
128
|
+
outputs?: {
|
|
129
|
+
[K in keyof O]: (ctx: PluginRenderCtx<D, P>) => O[K];
|
|
130
|
+
};
|
|
131
|
+
}): PluginModelBuilder<D, P, C, O>;
|
|
132
|
+
/**
|
|
133
|
+
* Adds an output to the plugin.
|
|
134
|
+
*
|
|
135
|
+
* @param key - Output name
|
|
136
|
+
* @param fn - Function that computes the output value from plugin context
|
|
137
|
+
* @returns PluginModel with the new output added
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* .output('model', (ctx) => createModel(ctx.params.columns, ctx.data.state))
|
|
141
|
+
* .output('isReady', (ctx) => ctx.params.columns !== undefined)
|
|
142
|
+
*/
|
|
143
|
+
output<const Key extends string, T>(key: Key, fn: (ctx: PluginRenderCtx<Data, Params>) => T): PluginModelBuilder<Data, Params, Config, Outputs & {
|
|
144
|
+
[K in Key]: T;
|
|
145
|
+
}>;
|
|
146
|
+
/**
|
|
147
|
+
* Finalizes the plugin definition and returns a ConfigurablePluginModel.
|
|
148
|
+
*
|
|
149
|
+
* @returns Callable plugin factory that accepts config and returns PluginModel
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* const myPlugin = new PluginModelBuilder('myPlugin', () => dataModel)
|
|
153
|
+
* .output('value', (ctx) => ctx.data.value)
|
|
154
|
+
* .build();
|
|
155
|
+
*
|
|
156
|
+
* // Later, call create() with config to get a configured instance:
|
|
157
|
+
* const configured = myPlugin.create({ defaultValue: 'test' });
|
|
158
|
+
*/
|
|
159
|
+
build(): PluginModelFactory<Data, Params, Config, Outputs>;
|
|
160
|
+
}
|
|
161
|
+
export {};
|
|
162
|
+
//# sourceMapping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
+
/**
|
|
2
|
+
* PluginModel - Builder for creating plugin types with data model and outputs.
|
|
3
|
+
*
|
|
4
|
+
* Plugins are UI components with their own model logic and persistent state.
|
|
5
|
+
* Block developers register plugin instances via BlockModelV3.plugin() method.
|
|
6
|
+
*
|
|
7
|
+
* @module plugin_model
|
|
8
|
+
*/
|
|
9
|
+
/** Symbol for internal builder creation method */
|
|
10
|
+
const FROM_BUILDER = Symbol("fromBuilder");
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Plugin Type
|
|
13
|
+
// =============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Configured plugin instance returned by PluginModelFactory.create().
|
|
16
|
+
* Contains the plugin's name, data model, and output definitions.
|
|
17
|
+
*/
|
|
18
|
+
class PluginModel {
|
|
19
|
+
/** Globally unique plugin name */
|
|
20
|
+
name;
|
|
21
|
+
/** Data model instance for this plugin */
|
|
22
|
+
dataModel;
|
|
23
|
+
/** Output definitions - functions that compute outputs from plugin context */
|
|
24
|
+
outputs;
|
|
25
|
+
constructor(input) {
|
|
26
|
+
this.name = input.name;
|
|
27
|
+
this.dataModel = input.dataModel;
|
|
28
|
+
this.outputs = input.outputs;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Internal method for creating PluginModel from factory.
|
|
32
|
+
* Uses Symbol key to prevent external access.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
static [FROM_BUILDER](input) {
|
|
36
|
+
return new this(input);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new PluginModelBuilder for building plugin definitions.
|
|
40
|
+
*
|
|
41
|
+
* @param options.name - Globally unique plugin name
|
|
42
|
+
* @param options.data - Factory function that creates the data model from config
|
|
43
|
+
* @returns PluginModelBuilder for chaining output definitions
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const dataModelChain = new DataModelBuilder().from<MyData>(DATA_MODEL_DEFAULT_VERSION);
|
|
47
|
+
*
|
|
48
|
+
* const myPlugin = PluginModel.define<MyData, MyParams, MyConfig>({
|
|
49
|
+
* name: 'myPlugin' as PluginName,
|
|
50
|
+
* data: (cfg) => dataModelChain.init(() => ({ value: cfg.defaultValue })),
|
|
51
|
+
* })
|
|
52
|
+
* .output('computed', (ctx) => ctx.data.value * ctx.params.multiplier)
|
|
53
|
+
* .build();
|
|
54
|
+
*/
|
|
55
|
+
static define(options) {
|
|
56
|
+
return PluginModelBuilder[FROM_BUILDER](options);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Plugin factory returned by PluginModelBuilder.build().
|
|
61
|
+
* Call create() with config to get a configured PluginModel instance.
|
|
62
|
+
*/
|
|
63
|
+
class PluginModelFactory {
|
|
64
|
+
name;
|
|
65
|
+
data;
|
|
66
|
+
outputs;
|
|
67
|
+
constructor(input) {
|
|
68
|
+
this.name = input.name;
|
|
69
|
+
this.data = input.data;
|
|
70
|
+
this.outputs = input.outputs;
|
|
71
|
+
}
|
|
72
|
+
/** Create a configured PluginModel instance */
|
|
73
|
+
create(config) {
|
|
74
|
+
return PluginModel[FROM_BUILDER]({
|
|
75
|
+
name: this.name,
|
|
76
|
+
dataModel: this.data(config),
|
|
77
|
+
outputs: this.outputs,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// =============================================================================
|
|
82
|
+
// Plugin Model Builder
|
|
83
|
+
// =============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* Builder for creating PluginType with type-safe output definitions.
|
|
86
|
+
*
|
|
87
|
+
* Use `PluginModel.define()` to create a builder instance.
|
|
88
|
+
*
|
|
89
|
+
* @typeParam Data - Plugin's persistent data type
|
|
90
|
+
* @typeParam Params - Params derived from block's RenderCtx (optional)
|
|
91
|
+
* @typeParam Config - Static configuration passed to plugin factory (optional)
|
|
92
|
+
* @typeParam Outputs - Accumulated output types
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* const dataModelChain = new DataModelBuilder().from<TableData>(DATA_MODEL_DEFAULT_VERSION);
|
|
96
|
+
*
|
|
97
|
+
* const dataTable = PluginModel.define<TableData, TableParams, TableConfig>({
|
|
98
|
+
* name: 'dataTable' as PluginName,
|
|
99
|
+
* data: (cfg) => {
|
|
100
|
+
* return dataModelChain.init(() => ({ state: createInitialState(cfg.ops) }));
|
|
101
|
+
* },
|
|
102
|
+
* })
|
|
103
|
+
* .output('model', (ctx) => createTableModel(ctx))
|
|
104
|
+
* .build();
|
|
105
|
+
*/
|
|
106
|
+
class PluginModelBuilder {
|
|
107
|
+
name;
|
|
108
|
+
data;
|
|
109
|
+
outputs;
|
|
110
|
+
constructor(input) {
|
|
111
|
+
this.name = input.name;
|
|
112
|
+
this.data = input.data;
|
|
113
|
+
this.outputs =
|
|
114
|
+
input.outputs ??
|
|
115
|
+
{};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Internal method for creating PluginModelBuilder.
|
|
119
|
+
* Uses Symbol key to prevent external access.
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
static [FROM_BUILDER](input) {
|
|
123
|
+
return new this(input);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Adds an output to the plugin.
|
|
127
|
+
*
|
|
128
|
+
* @param key - Output name
|
|
129
|
+
* @param fn - Function that computes the output value from plugin context
|
|
130
|
+
* @returns PluginModel with the new output added
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* .output('model', (ctx) => createModel(ctx.params.columns, ctx.data.state))
|
|
134
|
+
* .output('isReady', (ctx) => ctx.params.columns !== undefined)
|
|
135
|
+
*/
|
|
136
|
+
output(key, fn) {
|
|
137
|
+
return new PluginModelBuilder({
|
|
138
|
+
name: this.name,
|
|
139
|
+
data: this.data,
|
|
140
|
+
outputs: {
|
|
141
|
+
...this.outputs,
|
|
142
|
+
[key]: fn,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Finalizes the plugin definition and returns a ConfigurablePluginModel.
|
|
148
|
+
*
|
|
149
|
+
* @returns Callable plugin factory that accepts config and returns PluginModel
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* const myPlugin = new PluginModelBuilder('myPlugin', () => dataModel)
|
|
153
|
+
* .output('value', (ctx) => ctx.data.value)
|
|
154
|
+
* .build();
|
|
155
|
+
*
|
|
156
|
+
* // Later, call create() with config to get a configured instance:
|
|
157
|
+
* const configured = myPlugin.create({ defaultValue: 'test' });
|
|
158
|
+
*/
|
|
159
|
+
build() {
|
|
160
|
+
return new PluginModelFactory({
|
|
161
|
+
name: this.name,
|
|
162
|
+
data: this.data,
|
|
163
|
+
outputs: this.outputs,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { PluginModel };
|
|
169
|
+
//# sourceMappingURL=plugin_model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin_model.js","sources":["../src/plugin_model.ts"],"sourcesContent":["/**\n * PluginModel - Builder for creating plugin types with data model and outputs.\n *\n * Plugins are UI components with their own model logic and persistent state.\n * Block developers register plugin instances via BlockModelV3.plugin() method.\n *\n * @module plugin_model\n */\n\nimport type { DataModel } from \"./block_migrations\";\nimport type { PluginName } from \"./block_storage\";\nimport type { ResultPool } from \"./render\";\n\n/** Symbol for internal builder creation method */\nconst FROM_BUILDER = Symbol(\"fromBuilder\");\n\n// =============================================================================\n// Plugin Render Context\n// =============================================================================\n\n/**\n * Context passed to plugin output functions.\n * Provides access to plugin's persistent data, params derived from block context,\n * and the result pool for accessing workflow outputs.\n */\nexport interface PluginRenderCtx<Data, Params = undefined> {\n /** Plugin's persistent data */\n readonly data: Data;\n /** Params derived from block's RenderCtx */\n readonly params: Params;\n /** Result pool for accessing workflow outputs */\n readonly resultPool: ResultPool;\n}\n\n// =============================================================================\n// Plugin Type\n// =============================================================================\n\n/**\n * Configured plugin instance returned by PluginModelFactory.create().\n * Contains the plugin's name, data model, and output definitions.\n */\nexport class PluginModel<Data = unknown, Params = undefined, Outputs = {}> {\n /** Globally unique plugin name */\n readonly name: PluginName;\n /** Data model instance for this plugin */\n readonly dataModel: DataModel<Data>;\n /** Output definitions - functions that compute outputs from plugin context */\n readonly outputs: { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] };\n\n private constructor(input: {\n name: PluginName;\n dataModel: DataModel<Data>;\n outputs: { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] };\n }) {\n this.name = input.name;\n this.dataModel = input.dataModel;\n this.outputs = input.outputs;\n }\n\n /**\n * Internal method for creating PluginModel from factory.\n * Uses Symbol key to prevent external access.\n * @internal\n */\n static [FROM_BUILDER]<D, P, O>(input: {\n name: PluginName;\n dataModel: DataModel<D>;\n outputs: { [K in keyof O]: (ctx: PluginRenderCtx<D, P>) => O[K] };\n }): PluginModel<D, P, O> {\n return new this<D, P, O>(input);\n }\n\n /**\n * Creates a new PluginModelBuilder for building plugin definitions.\n *\n * @param options.name - Globally unique plugin name\n * @param options.data - Factory function that creates the data model from config\n * @returns PluginModelBuilder for chaining output definitions\n *\n * @example\n * const dataModelChain = new DataModelBuilder().from<MyData>(DATA_MODEL_DEFAULT_VERSION);\n *\n * const myPlugin = PluginModel.define<MyData, MyParams, MyConfig>({\n * name: 'myPlugin' as PluginName,\n * data: (cfg) => dataModelChain.init(() => ({ value: cfg.defaultValue })),\n * })\n * .output('computed', (ctx) => ctx.data.value * ctx.params.multiplier)\n * .build();\n */\n static define<Data, Params = undefined, Config = undefined>(options: {\n name: PluginName;\n data: (config?: Config) => DataModel<Data>;\n }): PluginModelBuilder<Data, Params, Config> {\n return PluginModelBuilder[FROM_BUILDER]<Data, Params, Config>(options);\n }\n}\n\n/**\n * Plugin factory returned by PluginModelBuilder.build().\n * Call create() with config to get a configured PluginModel instance.\n */\nclass PluginModelFactory<Data, Params, Config, Outputs> {\n private readonly name: PluginName;\n private readonly data: (config?: Config) => DataModel<Data>;\n private readonly outputs: {\n [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K];\n };\n\n constructor(input: {\n name: PluginName;\n data: (config?: Config) => DataModel<Data>;\n outputs: { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] };\n }) {\n this.name = input.name;\n this.data = input.data;\n this.outputs = input.outputs;\n }\n\n /** Create a configured PluginModel instance */\n create(config?: Config): PluginModel<Data, Params, Outputs> {\n return PluginModel[FROM_BUILDER]<Data, Params, Outputs>({\n name: this.name,\n dataModel: this.data(config),\n outputs: this.outputs,\n });\n }\n}\n\n// =============================================================================\n// Plugin Model Builder\n// =============================================================================\n\n/**\n * Builder for creating PluginType with type-safe output definitions.\n *\n * Use `PluginModel.define()` to create a builder instance.\n *\n * @typeParam Data - Plugin's persistent data type\n * @typeParam Params - Params derived from block's RenderCtx (optional)\n * @typeParam Config - Static configuration passed to plugin factory (optional)\n * @typeParam Outputs - Accumulated output types\n *\n * @example\n * const dataModelChain = new DataModelBuilder().from<TableData>(DATA_MODEL_DEFAULT_VERSION);\n *\n * const dataTable = PluginModel.define<TableData, TableParams, TableConfig>({\n * name: 'dataTable' as PluginName,\n * data: (cfg) => {\n * return dataModelChain.init(() => ({ state: createInitialState(cfg.ops) }));\n * },\n * })\n * .output('model', (ctx) => createTableModel(ctx))\n * .build();\n */\nclass PluginModelBuilder<\n Data,\n Params = undefined,\n Config = undefined,\n Outputs extends Record<string, unknown> = {},\n> {\n private readonly name: PluginName;\n private readonly data: (config?: Config) => DataModel<Data>;\n private readonly outputs: {\n [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K];\n };\n\n private constructor(input: {\n name: PluginName;\n data: (config?: Config) => DataModel<Data>;\n outputs?: { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] };\n }) {\n this.name = input.name;\n this.data = input.data;\n this.outputs =\n input.outputs ??\n ({} as { [K in keyof Outputs]: (ctx: PluginRenderCtx<Data, Params>) => Outputs[K] });\n }\n\n /**\n * Internal method for creating PluginModelBuilder.\n * Uses Symbol key to prevent external access.\n * @internal\n */\n static [FROM_BUILDER]<D, P, C, O extends Record<string, unknown> = {}>(input: {\n name: PluginName;\n data: (config?: C) => DataModel<D>;\n outputs?: { [K in keyof O]: (ctx: PluginRenderCtx<D, P>) => O[K] };\n }): PluginModelBuilder<D, P, C, O> {\n return new this<D, P, C, O>(input);\n }\n\n /**\n * Adds an output to the plugin.\n *\n * @param key - Output name\n * @param fn - Function that computes the output value from plugin context\n * @returns PluginModel with the new output added\n *\n * @example\n * .output('model', (ctx) => createModel(ctx.params.columns, ctx.data.state))\n * .output('isReady', (ctx) => ctx.params.columns !== undefined)\n */\n output<const Key extends string, T>(\n key: Key,\n fn: (ctx: PluginRenderCtx<Data, Params>) => T,\n ): PluginModelBuilder<Data, Params, Config, Outputs & { [K in Key]: T }> {\n return new PluginModelBuilder<Data, Params, Config, Outputs & { [K in Key]: T }>({\n name: this.name,\n data: this.data,\n outputs: {\n ...this.outputs,\n [key]: fn,\n } as {\n [K in keyof (Outputs & { [P in Key]: T })]: (\n ctx: PluginRenderCtx<Data, Params>,\n ) => (Outputs & { [P in Key]: T })[K];\n },\n });\n }\n\n /**\n * Finalizes the plugin definition and returns a ConfigurablePluginModel.\n *\n * @returns Callable plugin factory that accepts config and returns PluginModel\n *\n * @example\n * const myPlugin = new PluginModelBuilder('myPlugin', () => dataModel)\n * .output('value', (ctx) => ctx.data.value)\n * .build();\n *\n * // Later, call create() with config to get a configured instance:\n * const configured = myPlugin.create({ defaultValue: 'test' });\n */\n build(): PluginModelFactory<Data, Params, Config, Outputs> {\n return new PluginModelFactory<Data, Params, Config, Outputs>({\n name: this.name,\n data: this.data,\n outputs: this.outputs,\n });\n }\n}\n"],"names":[],"mappings":"AAAA;;;;;;;AAOG;AAMH;AACA,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC;AAoB1C;AACA;A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O;AAIxB,IAAA,WAAA,CAAoB,KAInB,EAAA;AACC,QAAA,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI;AACtB,QAAA,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI;AACtB,QAAA,IAAI,CAAC,OAAO;AACV,YAAA,KAAK,CAAC,OAAO;AACZ,gBAAA,EAAmF;IACxF;AAEA;;;;AAIG;AACH,IAAA,QAAQ,YAAY,CAAC,CAAkD,KAItE,EAAA;AACC,QAAA,OAAO,IAAI,IAAI,CAAa,KAAK,CAAC;IACpC;AAEA;;;;;;;;;;AAUG;IACH,MAAM,CACJ,GAAQ,EACR,EAA6C,EAAA;QAE7C,OAAO,IAAI,kBAAkB,CAAoD;YAC/E,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,YAAA,OAAO,EAAE;gBACP,GAAG,IAAI,CAAC,OAAO;gBACf,CAAC,GAAG,GAAG,EAAE;AAKV,aAAA;AACF,SAAA,CAAC;IACJ;AAEA;;;;;;;;;;;;AAYG;IACH,KAAK,GAAA;QACH,OAAO,IAAI,kBAAkB,CAAgC;YAC3D,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;AACtB,SAAA,CAAC;IACJ;AACD;;;;"}
|
package/dist/render/api.cjs
CHANGED
|
@@ -387,30 +387,30 @@ class RenderCtxBase {
|
|
|
387
387
|
constructor() {
|
|
388
388
|
this.ctx = internal.getCfgRenderCtx();
|
|
389
389
|
}
|
|
390
|
-
|
|
390
|
+
dataCache;
|
|
391
391
|
get data() {
|
|
392
|
-
if (this.
|
|
392
|
+
if (this.dataCache === undefined) {
|
|
393
393
|
const raw = this.ctx.data;
|
|
394
394
|
const value = typeof raw === "function" ? raw() : raw;
|
|
395
|
-
this.
|
|
395
|
+
this.dataCache = { v: value ? JSON.parse(value) : {} };
|
|
396
396
|
}
|
|
397
|
-
return this.
|
|
397
|
+
return this.dataCache.v;
|
|
398
398
|
}
|
|
399
399
|
// lazy rendering because this feature is rarely used
|
|
400
|
-
|
|
400
|
+
activeArgsCache;
|
|
401
401
|
/**
|
|
402
402
|
* Returns args snapshot the block was executed for (i.e. when "Run" button was pressed).
|
|
403
403
|
* Returns undefined, if block was never executed or stopped mid-way execution, so that the result was cleared.
|
|
404
404
|
* */
|
|
405
405
|
get activeArgs() {
|
|
406
|
-
if (this.
|
|
406
|
+
if (this.activeArgsCache === undefined) {
|
|
407
407
|
const raw = this.ctx.activeArgs;
|
|
408
408
|
const value = typeof raw === "function" ? raw() : raw;
|
|
409
|
-
this.
|
|
409
|
+
this.activeArgsCache = {
|
|
410
410
|
v: value ? JSON.parse(value) : undefined,
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
|
-
return this.
|
|
413
|
+
return this.activeArgsCache.v;
|
|
414
414
|
}
|
|
415
415
|
// /** Can be used to determine features provided by the desktop instance. */
|
|
416
416
|
// public get featureFlags() {
|
|
@@ -514,36 +514,35 @@ class RenderCtxBase {
|
|
|
514
514
|
}
|
|
515
515
|
/** Main entry point to the API available within model lambdas (like outputs, sections, etc..) for v3+ blocks */
|
|
516
516
|
class RenderCtx extends RenderCtxBase {
|
|
517
|
-
|
|
517
|
+
argsCache;
|
|
518
518
|
get args() {
|
|
519
|
-
if (this.
|
|
519
|
+
if (this.argsCache === undefined) {
|
|
520
520
|
const raw = this.ctx.args;
|
|
521
521
|
const value = typeof raw === "function" ? raw() : raw;
|
|
522
|
-
|
|
523
|
-
this._argsCache = { v: value === undefined ? undefined : JSON.parse(value) };
|
|
522
|
+
this.argsCache = { v: value === undefined ? undefined : JSON.parse(value) };
|
|
524
523
|
}
|
|
525
|
-
return this.
|
|
524
|
+
return this.argsCache.v;
|
|
526
525
|
}
|
|
527
526
|
}
|
|
528
527
|
/** Render context for legacy v1/v2 blocks - provides backward compatibility */
|
|
529
528
|
class RenderCtxLegacy extends RenderCtxBase {
|
|
530
|
-
|
|
529
|
+
argsCache;
|
|
531
530
|
get args() {
|
|
532
|
-
if (this.
|
|
531
|
+
if (this.argsCache === undefined) {
|
|
533
532
|
const raw = this.ctx.args;
|
|
534
533
|
const value = typeof raw === "function" ? raw() : raw;
|
|
535
|
-
this.
|
|
534
|
+
this.argsCache = { v: JSON.parse(value) };
|
|
536
535
|
}
|
|
537
|
-
return this.
|
|
536
|
+
return this.argsCache.v;
|
|
538
537
|
}
|
|
539
|
-
|
|
538
|
+
uiStateCache;
|
|
540
539
|
get uiState() {
|
|
541
|
-
if (this.
|
|
540
|
+
if (this.uiStateCache === undefined) {
|
|
542
541
|
const raw = this.ctx.uiState;
|
|
543
542
|
const value = typeof raw === "function" ? raw() : raw;
|
|
544
|
-
this.
|
|
543
|
+
this.uiStateCache = { v: value ? JSON.parse(value) : {} };
|
|
545
544
|
}
|
|
546
|
-
return this.
|
|
545
|
+
return this.uiStateCache.v;
|
|
547
546
|
}
|
|
548
547
|
}
|
|
549
548
|
|