@milaboratories/milaboratories.ui-examples.model 1.2.24 → 1.2.26

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/index.js CHANGED
@@ -1,301 +1,312 @@
1
1
  import { BlockModel, createPlDataTableStateV2, stringifyJson, ValueType, Annotation, PColumnName, createPlDataTableV2 } from '@platforma-sdk/model';
2
2
  import { z } from 'zod';
3
3
 
4
- // src/index.ts
5
- var ImportFileHandleSchema = z.string().optional().refine(
6
- (_a) => true
7
- );
4
+ const ImportFileHandleSchema = z
5
+ .string()
6
+ .optional()
7
+ .refine(((_a) => true));
8
8
  function* range(from, to, step = 1) {
9
- for (let i = from; i < to; i += step) {
10
- yield i;
11
- }
9
+ for (let i = from; i < to; i += step) {
10
+ yield i;
11
+ }
12
12
  }
13
13
  function toList(iterable) {
14
- const lst = [];
15
- for (const it of iterable) {
16
- lst.push(it);
17
- }
18
- return lst;
14
+ const lst = [];
15
+ for (const it of iterable) {
16
+ lst.push(it);
17
+ }
18
+ return lst;
19
19
  }
20
20
  function times(n, cb) {
21
- return toList(range(0, n)).map(cb);
21
+ return toList(range(0, n)).map(cb);
22
22
  }
23
- var $BlockArgs = z.object({
24
- numbers: z.array(z.coerce.number()),
25
- handles: z.array(ImportFileHandleSchema)
23
+ const $BlockArgs = z.object({
24
+ numbers: z.array(z.coerce.number()),
25
+ handles: z.array(ImportFileHandleSchema),
26
26
  });
27
- var platforma = BlockModel.create("Heavy").withArgs({ numbers: [1, 2, 3, 4], handles: [] }).withUiState({
28
- dataTableV2: {
29
- sourceId: "source_1",
30
- numRows: 200,
31
- state: createPlDataTableStateV2()
32
- },
33
- dynamicSections: [],
34
- datasets: []
35
- }).argsValid((ctx) => {
36
- if (ctx.args.numbers.length === 5) {
37
- throw new Error("argsValid: test error");
38
- }
39
- return ctx.args.numbers.length > 0;
40
- }).output("numbers", (ctx) => ctx.outputs?.resolve("numbers")?.getDataAsJson()).output("progresses", (ctx) => {
41
- const m = ctx.outputs?.resolve("progresses");
42
- const progresses = m?.mapFields((name, val) => [name, val?.getImportProgress()]);
43
- return Object.fromEntries(progresses ?? []);
44
- }).output("ptV2Sheets", (ctx) => {
45
- const rowCount = ctx.uiState.dataTableV2.numRows ?? 0;
46
- const sheets = [
47
- {
48
- axis: {
49
- type: ValueType.Int,
50
- name: "part",
51
- annotations: {
52
- [Annotation.Label]: "Partitioned axis",
53
- [Annotation.DiscreteValues]: stringifyJson([0, 1])
54
- }
55
- },
56
- options: [
57
- { value: 0, label: "Partition 1" },
58
- { value: 1, label: "Partition 2" }
59
- ]
27
+ const platforma = BlockModel.create('Heavy')
28
+ .withArgs({ numbers: [1, 2, 3, 4], handles: [] })
29
+ .withUiState({
30
+ dataTableV2: {
31
+ sourceId: 'source_1',
32
+ numRows: 200,
33
+ state: createPlDataTableStateV2(),
34
+ },
35
+ dynamicSections: [],
36
+ datasets: [],
37
+ })
38
+ .argsValid((ctx) => {
39
+ if (ctx.args.numbers.length === 5) {
40
+ throw new Error('argsValid: test error');
60
41
  }
61
- ];
62
- return rowCount > 0 ? sheets : [];
63
- }).output("ptV2", (ctx) => {
64
- const rowCount = ctx.uiState.dataTableV2.numRows ?? 0;
65
- const makePartitionId = (rowCount2, i) => Math.floor(2 * i / (rowCount2 + 1));
66
- const columns = [
67
- {
68
- id: "column1",
69
- spec: {
70
- kind: "PColumn",
71
- valueType: ValueType.String,
72
- name: "example",
73
- annotations: {
74
- [Annotation.Label]: "String column",
75
- [Annotation.DiscreteValues]: stringifyJson(["up", "down"]),
76
- [Annotation.Table.OrderPriority]: stringifyJson(101)
42
+ return ctx.args.numbers.length > 0;
43
+ })
44
+ .output('numbers', (ctx) => ctx.outputs?.resolve('numbers')?.getDataAsJson())
45
+ .output('progresses', (ctx) => {
46
+ const m = ctx.outputs?.resolve('progresses');
47
+ const progresses = m?.mapFields((name, val) => [name, val?.getImportProgress()]);
48
+ return Object.fromEntries(progresses ?? []);
49
+ })
50
+ .output('ptV2Sheets', (ctx) => {
51
+ const rowCount = ctx.uiState.dataTableV2.numRows ?? 0;
52
+ const sheets = [
53
+ {
54
+ axis: {
55
+ type: ValueType.Int,
56
+ name: 'part',
57
+ annotations: {
58
+ [Annotation.Label]: 'Partitioned axis',
59
+ [Annotation.DiscreteValues]: stringifyJson([0, 1]),
60
+ },
61
+ },
62
+ options: [
63
+ { value: 0, label: 'Partition 1' },
64
+ { value: 1, label: 'Partition 2' },
65
+ ],
77
66
  },
78
- axesSpec: [
79
- {
80
- type: ValueType.Int,
81
- name: "part",
82
- annotations: {
83
- [Annotation.Label]: "Partitioned axis",
84
- [Annotation.DiscreteValues]: stringifyJson([0, 1])
85
- }
86
- },
87
- {
88
- type: ValueType.Int,
89
- name: "index",
90
- annotations: {
91
- [Annotation.Label]: "Int axis"
92
- }
93
- }
94
- ]
95
- },
96
- data: times(rowCount, (i) => {
97
- const v = i + 1;
98
- return {
99
- key: [makePartitionId(rowCount, v), v],
100
- val: v.toString()
101
- };
102
- })
103
- },
104
- {
105
- id: "column2",
106
- spec: {
107
- kind: "PColumn",
108
- valueType: ValueType.Float,
109
- name: "value",
110
- annotations: {
111
- [Annotation.Label]: "Float column",
112
- [Annotation.Table.Visibility]: "optional",
113
- [Annotation.Table.OrderPriority]: stringifyJson(100)
67
+ ];
68
+ return rowCount > 0 ? sheets : [];
69
+ })
70
+ .output('ptV2', (ctx) => {
71
+ const rowCount = ctx.uiState.dataTableV2.numRows ?? 0;
72
+ const makePartitionId = (rowCount, i) => Math.floor((2 * i) / (rowCount + 1));
73
+ const columns = [
74
+ {
75
+ id: 'column1',
76
+ spec: {
77
+ kind: 'PColumn',
78
+ valueType: ValueType.String,
79
+ name: 'example',
80
+ annotations: {
81
+ [Annotation.Label]: 'String column',
82
+ [Annotation.DiscreteValues]: stringifyJson(['up', 'down']),
83
+ [Annotation.Table.OrderPriority]: stringifyJson(101),
84
+ },
85
+ axesSpec: [
86
+ {
87
+ type: ValueType.Int,
88
+ name: 'part',
89
+ annotations: {
90
+ [Annotation.Label]: 'Partitioned axis',
91
+ [Annotation.DiscreteValues]: stringifyJson([0, 1]),
92
+ },
93
+ },
94
+ {
95
+ type: ValueType.Int,
96
+ name: 'index',
97
+ annotations: {
98
+ [Annotation.Label]: 'Int axis',
99
+ },
100
+ },
101
+ ],
102
+ },
103
+ data: times(rowCount, (i) => {
104
+ const v = i + 1;
105
+ return {
106
+ key: [makePartitionId(rowCount, v), v],
107
+ val: v.toString(),
108
+ };
109
+ }),
114
110
  },
115
- axesSpec: [
116
- {
117
- type: ValueType.Int,
118
- name: "part",
119
- annotations: {
120
- [Annotation.Label]: "Partitioned axis",
121
- [Annotation.DiscreteValues]: stringifyJson([0, 1])
122
- }
123
- },
124
- {
125
- type: ValueType.Int,
126
- name: "index",
127
- annotations: {
128
- [Annotation.Label]: "Int axis"
129
- }
130
- }
131
- ]
132
- },
133
- data: times(rowCount, (i) => {
134
- const v = i + 1;
135
- return {
136
- key: [makePartitionId(rowCount, v), v],
137
- val: v + 0.1
138
- };
139
- })
140
- },
141
- {
142
- id: "labelColumn",
143
- spec: {
144
- kind: "PColumn",
145
- valueType: ValueType.Int,
146
- name: PColumnName.Label,
147
- annotations: {
148
- [Annotation.Label]: "Int axis labels"
111
+ {
112
+ id: 'column2',
113
+ spec: {
114
+ kind: 'PColumn',
115
+ valueType: ValueType.Float,
116
+ name: 'value',
117
+ annotations: {
118
+ [Annotation.Label]: 'Float column',
119
+ [Annotation.Table.Visibility]: 'optional',
120
+ [Annotation.Table.OrderPriority]: stringifyJson(100),
121
+ },
122
+ axesSpec: [
123
+ {
124
+ type: ValueType.Int,
125
+ name: 'part',
126
+ annotations: {
127
+ [Annotation.Label]: 'Partitioned axis',
128
+ [Annotation.DiscreteValues]: stringifyJson([0, 1]),
129
+ },
130
+ },
131
+ {
132
+ type: ValueType.Int,
133
+ name: 'index',
134
+ annotations: {
135
+ [Annotation.Label]: 'Int axis',
136
+ },
137
+ },
138
+ ],
139
+ },
140
+ data: times(rowCount, (i) => {
141
+ const v = i + 1;
142
+ return {
143
+ key: [makePartitionId(rowCount, v), v],
144
+ val: v + 0.1,
145
+ };
146
+ }),
149
147
  },
150
- axesSpec: [
151
- {
152
- type: ValueType.Int,
153
- name: "index",
154
- annotations: {
155
- [Annotation.Label]: "Int axis"
156
- }
157
- }
158
- ]
159
- },
160
- data: times(rowCount, (i) => {
161
- const v = i + 1;
162
- return {
163
- key: [v],
164
- val: 1e5 - v
165
- };
166
- })
167
- },
168
- {
169
- id: "linkerColumn",
170
- spec: {
171
- kind: "PColumn",
172
- valueType: ValueType.Int,
173
- name: "linker",
174
- annotations: {
175
- [Annotation.Label]: "Index axis linker",
176
- [Annotation.IsLinkerColumn]: stringifyJson(true),
177
- [Annotation.Table.Visibility]: "hidden"
148
+ {
149
+ id: 'labelColumn',
150
+ spec: {
151
+ kind: 'PColumn',
152
+ valueType: ValueType.Int,
153
+ name: PColumnName.Label,
154
+ annotations: {
155
+ [Annotation.Label]: 'Int axis labels',
156
+ },
157
+ axesSpec: [
158
+ {
159
+ type: ValueType.Int,
160
+ name: 'index',
161
+ annotations: {
162
+ [Annotation.Label]: 'Int axis',
163
+ },
164
+ },
165
+ ],
166
+ },
167
+ data: times(rowCount, (i) => {
168
+ const v = i + 1;
169
+ return {
170
+ key: [v],
171
+ val: 100000 - v,
172
+ };
173
+ }),
178
174
  },
179
- axesSpec: [
180
- {
181
- type: ValueType.Int,
182
- name: "index",
183
- annotations: {
184
- [Annotation.Label]: "Int axis"
185
- }
186
- },
187
- {
188
- type: ValueType.Int,
189
- name: "linkedIndex",
190
- annotations: {
191
- [Annotation.Label]: "Linked int axis"
192
- }
193
- }
194
- ]
195
- },
196
- data: times(rowCount, (i) => {
197
- const v = i + 1;
198
- return {
199
- key: [v, v],
200
- val: 1
201
- };
202
- })
203
- }
204
- ];
205
- for (let j = 1; j < 10; ++j) {
206
- columns.push({
207
- id: `alphabeticalColumn${j}`,
208
- spec: {
209
- kind: "PColumn",
210
- valueType: ValueType.String,
211
- name: "value",
212
- annotations: {
213
- [Annotation.Label]: `Alphabetical column ${j}`,
214
- [Annotation.Table.Visibility]: "optional",
215
- [Annotation.Table.OrderPriority]: stringifyJson(10 - j)
175
+ {
176
+ id: 'linkerColumn',
177
+ spec: {
178
+ kind: 'PColumn',
179
+ valueType: ValueType.Int,
180
+ name: 'linker',
181
+ annotations: {
182
+ [Annotation.Label]: 'Index axis linker',
183
+ [Annotation.IsLinkerColumn]: stringifyJson(true),
184
+ [Annotation.Table.Visibility]: 'hidden',
185
+ },
186
+ axesSpec: [
187
+ {
188
+ type: ValueType.Int,
189
+ name: 'index',
190
+ annotations: {
191
+ [Annotation.Label]: 'Int axis',
192
+ },
193
+ },
194
+ {
195
+ type: ValueType.Int,
196
+ name: 'linkedIndex',
197
+ annotations: {
198
+ [Annotation.Label]: 'Linked int axis',
199
+ },
200
+ },
201
+ ],
202
+ },
203
+ data: times(rowCount, (i) => {
204
+ const v = i + 1;
205
+ return {
206
+ key: [v, v],
207
+ val: 1,
208
+ };
209
+ }),
216
210
  },
217
- axesSpec: [
218
- {
219
- type: ValueType.Int,
220
- name: "linkedIndex",
221
- annotations: {
222
- [Annotation.Label]: "Linked int axis"
223
- }
224
- }
225
- ]
226
- },
227
- data: times(rowCount, (i) => {
228
- const v = i + 1;
229
- return {
230
- key: [v],
231
- val: v.toString().repeat(j)
232
- };
233
- })
234
- });
235
- }
236
- return createPlDataTableV2(
237
- ctx,
238
- columns,
239
- ctx.uiState.dataTableV2.state
240
- );
241
- }).title((ctx) => {
242
- if (ctx.args.numbers.length === 5) {
243
- throw new Error("block title: test error");
244
- }
245
- return "Ui Examples";
246
- }).sections((ctx) => {
247
- const dynamicSections = (ctx.uiState.dynamicSections ?? []).map((it) => ({
248
- type: "link",
249
- href: `/section?id=${it.id}`,
250
- label: it.label
251
- }));
252
- if (dynamicSections.some((it) => it.label === "Error")) {
253
- throw new Error("sections: test error");
254
- }
255
- return [
256
- { type: "link", href: "/loaders", label: "Loaders" },
257
- { type: "link", href: "/", label: "Icons/Masks" },
258
- { type: "link", href: "/state", label: "State" },
259
- { type: "link", href: "/layout", label: "Layout" },
260
- { type: "link", href: "/form-components", label: "Form Components" },
261
- { type: "link", href: "/log-view", label: "PlLogView" },
262
- { type: "link", href: "/modals", label: "Modals" },
263
- { type: "link", href: "/select-files", label: "Select Files" },
264
- { type: "link", href: "/inject-env", label: "Inject env" },
265
- { type: "link", href: "/use-watch-fetch", label: "useWatchFetch" },
266
- { type: "link", href: "/typography", label: "Typography" },
267
- { type: "link", href: "/ag-grid-vue", label: "AgGridVue" },
268
- { type: "link", href: "/ag-grid-vue-with-builder", label: "AgGridVue with builder" },
269
- { type: "link", href: "/pl-ag-data-table-v2", label: "PlAgDataTableV2" },
270
- { type: "link", href: "/pl-splash-page", label: "PlSplashPage" },
271
- { type: "link", href: "/pl-file-input-page", label: "PlFileInputPage" },
272
- { type: "link", href: "/pl-number-field-page", label: "PlNumberFieldPage" },
273
- { type: "link", href: "/pl-error-boundary-page", label: "PlErrorBoundaryPage" },
274
- { type: "link", href: "/pl-element-list-page", label: "PlElementList" },
275
- { type: "link", href: "/errors", label: "Errors" },
276
- { type: "link", href: "/text-fields", label: "PlTextField" },
277
- { type: "link", href: "/tabs", label: "PlTabs" },
278
- { type: "link", href: "/stacked-bar", label: "PlChartStackedBar" },
279
- { type: "link", href: "/histogram", label: "PlChartHistogram" },
280
- { type: "link", href: "/buttons", label: "ButtonsPage" },
281
- { type: "link", href: "/notifications", label: "Notifications" },
282
- { type: "link", href: "/drafts", label: "Drafts" },
283
- { type: "link", href: "/pl-autocomplete", label: "PlAutocomplete" },
284
- { type: "link", href: "/radio", label: "PlRadio" },
285
- ...dynamicSections.length ? [
286
- { type: "delimiter" },
287
- ...dynamicSections,
288
- { type: "delimiter" }
289
- ] : [],
290
- {
291
- type: "link",
292
- href: "/add-section",
293
- appearance: "add-section",
294
- label: "New Dynamic section"
211
+ ];
212
+ for (let j = 1; j < 10; ++j) {
213
+ columns.push({
214
+ id: `alphabeticalColumn${j}`,
215
+ spec: {
216
+ kind: 'PColumn',
217
+ valueType: ValueType.String,
218
+ name: 'value',
219
+ annotations: {
220
+ [Annotation.Label]: `Alphabetical column ${j}`,
221
+ [Annotation.Table.Visibility]: 'optional',
222
+ [Annotation.Table.OrderPriority]: stringifyJson(10 - j),
223
+ },
224
+ axesSpec: [
225
+ {
226
+ type: ValueType.Int,
227
+ name: 'linkedIndex',
228
+ annotations: {
229
+ [Annotation.Label]: 'Linked int axis',
230
+ },
231
+ },
232
+ ],
233
+ },
234
+ data: times(rowCount, (i) => {
235
+ const v = i + 1;
236
+ return {
237
+ key: [v],
238
+ val: v.toString().repeat(j),
239
+ };
240
+ }),
241
+ });
242
+ }
243
+ return createPlDataTableV2(ctx, columns, ctx.uiState.dataTableV2.state);
244
+ })
245
+ .title((ctx) => {
246
+ if (ctx.args.numbers.length === 5) {
247
+ throw new Error('block title: test error');
295
248
  }
296
- ];
297
- }).done(2);
249
+ return 'Ui Examples';
250
+ })
251
+ .sections((ctx) => {
252
+ const dynamicSections = (ctx.uiState.dynamicSections ?? []).map((it) => ({
253
+ type: 'link',
254
+ href: `/section?id=${it.id}`,
255
+ label: it.label,
256
+ }));
257
+ if (dynamicSections.some((it) => it.label === 'Error')) {
258
+ throw new Error('sections: test error');
259
+ }
260
+ return [
261
+ { type: 'link', href: '/loaders', label: 'Loaders' },
262
+ { type: 'link', href: '/', label: 'Icons/Masks' },
263
+ { type: 'link', href: '/state', label: 'State' },
264
+ { type: 'link', href: '/layout', label: 'Layout' },
265
+ { type: 'link', href: '/form-components', label: 'Form Components' },
266
+ { type: 'link', href: '/log-view', label: 'PlLogView' },
267
+ { type: 'link', href: '/modals', label: 'Modals' },
268
+ { type: 'link', href: '/select-files', label: 'Select Files' },
269
+ { type: 'link', href: '/inject-env', label: 'Inject env' },
270
+ { type: 'link', href: '/use-watch-fetch', label: 'useWatchFetch' },
271
+ { type: 'link', href: '/typography', label: 'Typography' },
272
+ { type: 'link', href: '/ag-grid-vue', label: 'AgGridVue' },
273
+ { type: 'link', href: '/ag-grid-vue-with-builder', label: 'AgGridVue with builder' },
274
+ { type: 'link', href: '/pl-ag-data-table-v2', label: 'PlAgDataTableV2' },
275
+ { type: 'link', href: '/pl-splash-page', label: 'PlSplashPage' },
276
+ { type: 'link', href: '/pl-file-input-page', label: 'PlFileInputPage' },
277
+ { type: 'link', href: '/pl-number-field-page', label: 'PlNumberFieldPage' },
278
+ { type: 'link', href: '/pl-error-boundary-page', label: 'PlErrorBoundaryPage' },
279
+ { type: 'link', href: '/pl-element-list-page', label: 'PlElementList' },
280
+ { type: 'link', href: '/text-fields', label: 'PlTextField' },
281
+ { type: 'link', href: '/tabs', label: 'PlTabs' },
282
+ { type: 'link', href: '/pl-autocomplete', label: 'PlAutocomplete' },
283
+ { type: 'link', href: '/radio', label: 'PlRadio' },
284
+ { type: 'link', href: '/stacked-bar', label: 'PlChartStackedBar' },
285
+ { type: 'link', href: '/histogram', label: 'PlChartHistogram' },
286
+ { type: 'link', href: '/buttons', label: 'ButtonsPage' },
287
+ { type: 'link', href: '/errors', label: 'Errors' },
288
+ { type: 'link', href: '/downloads', label: 'Downloads' },
289
+ { type: 'link', href: '/notifications', label: 'Notifications' },
290
+ { type: 'link', href: '/drafts', label: 'Drafts' },
291
+ { type: 'link', href: '/pl-autocomplete', label: 'PlAutocomplete' },
292
+ { type: 'link', href: '/pl-autocomplete-multi', label: 'PlAutocompleteMulti' },
293
+ { type: 'link', href: '/radio', label: 'PlRadio' },
294
+ ...(dynamicSections.length
295
+ ? [
296
+ { type: 'delimiter' },
297
+ ...dynamicSections,
298
+ { type: 'delimiter' }
299
+ ]
300
+ : []),
301
+ {
302
+ type: 'link',
303
+ href: '/add-section',
304
+ appearance: 'add-section',
305
+ label: 'New Dynamic section',
306
+ },
307
+ ];
308
+ })
309
+ .done(); // api version 2
298
310
 
299
311
  export { $BlockArgs, ImportFileHandleSchema, platforma, range, times, toList };
300
312
  //# sourceMappingURL=index.js.map
301
- //# sourceMappingURL=index.js.map