@milaboratories/uikit 2.4.30 → 2.5.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.
@@ -0,0 +1,476 @@
1
+ import type { FilterSpecType, SimplifiedPColumnSpec } from '@platforma-sdk/model';
2
+ import type { FilterSpecMetadataRecord } from './types';
3
+
4
+ export const filterUiMetadata = {
5
+ equal: {
6
+ label: 'Col = X (Equal)',
7
+ form: {
8
+ column: {
9
+ label: 'Column',
10
+ fieldType: 'SUniversalPColumnId',
11
+ defaultValue: () => undefined,
12
+ },
13
+ type: {
14
+ label: 'Predicate',
15
+ fieldType: 'FilterType',
16
+ defaultValue: () => 'equal',
17
+ },
18
+ x: {
19
+ label: 'X',
20
+ fieldType: 'number',
21
+ defaultValue: () => 0,
22
+ },
23
+ },
24
+ supportedFor: isNumericValueType,
25
+ },
26
+ lessThan: {
27
+ label: 'Col < X (Less Than)',
28
+ form: {
29
+ column: {
30
+ label: 'Column',
31
+ fieldType: 'SUniversalPColumnId',
32
+ defaultValue: () => undefined,
33
+ },
34
+ type: {
35
+ label: 'Predicate',
36
+ fieldType: 'FilterType',
37
+ defaultValue: () => 'lessThan',
38
+ },
39
+ x: {
40
+ label: 'X',
41
+ fieldType: 'number',
42
+ defaultValue: () => 0,
43
+ },
44
+ },
45
+ supportedFor: isNumericValueType,
46
+ },
47
+ greaterThan: {
48
+ label: 'Col > X (Greater Than)',
49
+ form: {
50
+ column: {
51
+ label: 'Column',
52
+ fieldType: 'SUniversalPColumnId',
53
+ defaultValue: () => undefined,
54
+ },
55
+ type: {
56
+ label: 'Predicate',
57
+ fieldType: 'FilterType',
58
+ defaultValue: () => 'greaterThan',
59
+ },
60
+ x: {
61
+ label: 'X',
62
+ fieldType: 'number',
63
+ defaultValue: () => 0,
64
+ },
65
+ },
66
+ supportedFor: isNumericValueType,
67
+ },
68
+ lessThanOrEqual: {
69
+ label: 'Col ≤ X (Less Than or Equal)',
70
+ form: {
71
+ column: {
72
+ label: 'Column',
73
+ fieldType: 'SUniversalPColumnId',
74
+ defaultValue: () => undefined,
75
+ },
76
+ type: {
77
+ label: 'Predicate',
78
+ fieldType: 'FilterType',
79
+ defaultValue: () => 'lessThanOrEqual',
80
+ },
81
+ x: {
82
+ label: 'X',
83
+ fieldType: 'number',
84
+ defaultValue: () => 0,
85
+ },
86
+ },
87
+ supportedFor: isNumericValueType,
88
+ },
89
+ greaterThanOrEqual: {
90
+ label: 'Col ≥ X (Greater Than or Equal)',
91
+ form: {
92
+ column: {
93
+ label: 'Column',
94
+ fieldType: 'SUniversalPColumnId',
95
+ defaultValue: () => undefined,
96
+ },
97
+ type: {
98
+ label: 'Predicate',
99
+ fieldType: 'FilterType',
100
+ defaultValue: () => 'greaterThanOrEqual',
101
+ },
102
+ x: {
103
+ label: 'X',
104
+ fieldType: 'number',
105
+ defaultValue: () => 0,
106
+ },
107
+ },
108
+ supportedFor: isNumericValueType,
109
+ },
110
+ // Columns comparison
111
+ equalToColumn: {
112
+ label: 'Col₁ = Col₂ (Compare Columns)',
113
+ form: {
114
+ column: {
115
+ label: 'Col₁',
116
+ fieldType: 'SUniversalPColumnId',
117
+ defaultValue: () => undefined,
118
+ },
119
+ type: {
120
+ label: 'Predicate',
121
+ fieldType: 'FilterType',
122
+ defaultValue: () => 'equalToColumn',
123
+ },
124
+ rhs: {
125
+ label: 'Col₂',
126
+ fieldType: 'SUniversalPColumnId',
127
+ defaultValue: () => undefined,
128
+ },
129
+ },
130
+ supportedFor: (spec1: SimplifiedPColumnSpec, spec2?: SimplifiedPColumnSpec): boolean => {
131
+ return isNumericValueType(spec1) && (spec2 === undefined || isNumericValueType(spec2));
132
+ },
133
+ },
134
+ lessThanColumn: {
135
+ label: 'Col₁ < Col₂ (Compare Columns)',
136
+ form: {
137
+ column: {
138
+ label: 'Col₁',
139
+ fieldType: 'SUniversalPColumnId',
140
+ defaultValue: () => undefined,
141
+ },
142
+ type: {
143
+ label: 'Predicate',
144
+ fieldType: 'FilterType',
145
+ defaultValue: () => 'lessThanColumn',
146
+ },
147
+ rhs: {
148
+ label: 'Col₂',
149
+ fieldType: 'SUniversalPColumnId',
150
+ defaultValue: () => undefined,
151
+ },
152
+ minDiff: {
153
+ label: 'Margin (positive)',
154
+ fieldType: 'number?',
155
+ defaultValue: () => undefined,
156
+ },
157
+ },
158
+ supportedFor: (spec1: SimplifiedPColumnSpec, spec2?: SimplifiedPColumnSpec): boolean => {
159
+ return isNumericValueType(spec1) && (spec2 === undefined || isNumericValueType(spec2));
160
+ },
161
+ },
162
+ greaterThanColumn: {
163
+ label: 'Col₁ > Col₂ (Compare Columns)',
164
+ form: {
165
+ column: {
166
+ label: 'Col₁',
167
+ fieldType: 'SUniversalPColumnId',
168
+ defaultValue: () => undefined,
169
+ },
170
+ type: {
171
+ label: 'Predicate',
172
+ fieldType: 'FilterType',
173
+ defaultValue: () => 'greaterThanColumn',
174
+ },
175
+ rhs: {
176
+ label: 'Col₂',
177
+ fieldType: 'SUniversalPColumnId',
178
+ defaultValue: () => undefined,
179
+ },
180
+ minDiff: {
181
+ label: 'Margin (positive)',
182
+ fieldType: 'number?',
183
+ defaultValue: () => undefined,
184
+ },
185
+ },
186
+ supportedFor: (spec1: SimplifiedPColumnSpec, spec2?: SimplifiedPColumnSpec): boolean => {
187
+ return isNumericValueType(spec1) && (spec2 === undefined || isNumericValueType(spec2));
188
+ },
189
+ },
190
+ lessThanColumnOrEqual: {
191
+ label: 'Col₁ ≤ Col₂ (Compare Columns)',
192
+ form: {
193
+ column: {
194
+ label: 'Col₁',
195
+ fieldType: 'SUniversalPColumnId',
196
+ defaultValue: () => undefined,
197
+ },
198
+ type: {
199
+ label: 'Predicate',
200
+ fieldType: 'FilterType',
201
+ defaultValue: () => 'lessThanColumnOrEqual',
202
+ },
203
+ rhs: {
204
+ label: 'Col₂',
205
+ fieldType: 'SUniversalPColumnId',
206
+ defaultValue: () => undefined,
207
+ },
208
+ minDiff: {
209
+ label: 'Margin (positive)',
210
+ fieldType: 'number?',
211
+ defaultValue: () => undefined,
212
+ },
213
+ },
214
+ supportedFor: (spec1: SimplifiedPColumnSpec, spec2?: SimplifiedPColumnSpec): boolean => {
215
+ return isNumericValueType(spec1) && (spec2 === undefined || isNumericValueType(spec2));
216
+ },
217
+ },
218
+ greaterThanColumnOrEqual: {
219
+ label: 'Col₁ ≥ Col₂ (Compare Columns)',
220
+ form: {
221
+ column: {
222
+ label: 'Col₁',
223
+ fieldType: 'SUniversalPColumnId',
224
+ defaultValue: () => undefined,
225
+ },
226
+ type: {
227
+ label: 'Predicate',
228
+ fieldType: 'FilterType',
229
+ defaultValue: () => 'greaterThanColumnOrEqual',
230
+ },
231
+ rhs: {
232
+ label: 'Col₂',
233
+ fieldType: 'SUniversalPColumnId',
234
+ defaultValue: () => undefined,
235
+ },
236
+ minDiff: {
237
+ label: 'Margin (positive)',
238
+ fieldType: 'number?',
239
+ defaultValue: () => undefined,
240
+ },
241
+ },
242
+ supportedFor: (spec1: SimplifiedPColumnSpec, spec2?: SimplifiedPColumnSpec): boolean => {
243
+ return isNumericValueType(spec1) && (spec2 === undefined || isNumericValueType(spec2));
244
+ },
245
+ },
246
+ // Ordering filters
247
+ topN: {
248
+ label: 'Top N',
249
+ form: {
250
+ column: {
251
+ label: 'Rank By Column',
252
+ fieldType: 'SUniversalPColumnId',
253
+ defaultValue: () => undefined,
254
+ },
255
+ type: {
256
+ label: 'Predicate',
257
+ fieldType: 'FilterType',
258
+ defaultValue: () => 'topN',
259
+ },
260
+ n: {
261
+ label: 'N',
262
+ fieldType: 'number',
263
+ defaultValue: () => 10,
264
+ },
265
+ },
266
+ supportedFor: isNumericValueType,
267
+ },
268
+ bottomN: {
269
+ label: 'Bottom N',
270
+ form: {
271
+ column: {
272
+ label: 'Rank By Column',
273
+ fieldType: 'SUniversalPColumnId',
274
+ defaultValue: () => undefined,
275
+ },
276
+ type: {
277
+ label: 'Predicate',
278
+ fieldType: 'FilterType',
279
+ defaultValue: () => 'bottomN',
280
+ },
281
+ n: {
282
+ label: 'N',
283
+ fieldType: 'number',
284
+ defaultValue: () => 10,
285
+ },
286
+ },
287
+ supportedFor: isNumericValueType,
288
+ },
289
+ patternContainSubsequence: {
290
+ label: 'Col ~ Seq (Contain Subsequence)',
291
+ form: {
292
+ column: {
293
+ label: 'Column',
294
+ fieldType: 'SUniversalPColumnId',
295
+ defaultValue: () => undefined,
296
+ },
297
+ type: {
298
+ label: 'Predicate',
299
+ fieldType: 'FilterType',
300
+ defaultValue: () => 'patternContainSubsequence',
301
+ },
302
+ value: {
303
+ label: 'Seq',
304
+ fieldType: 'string',
305
+ defaultValue: () => '',
306
+ },
307
+ },
308
+ supportedFor: isStringValueType,
309
+ },
310
+ patternNotContainSubsequence: {
311
+ label: 'Col ≁ Seq (Not Contain Subsequence)',
312
+ form: {
313
+ column: {
314
+ label: 'Column',
315
+ fieldType: 'SUniversalPColumnId',
316
+ defaultValue: () => undefined,
317
+ },
318
+ type: {
319
+ label: 'Predicate',
320
+ fieldType: 'FilterType',
321
+ defaultValue: () => 'patternNotContainSubsequence',
322
+ },
323
+ value: {
324
+ label: 'Seq',
325
+ fieldType: 'string',
326
+ defaultValue: () => '',
327
+ },
328
+ },
329
+ supportedFor: isStringValueType,
330
+ },
331
+ patternEquals: {
332
+ label: 'Col = Seq (Equals)',
333
+ form: {
334
+ column: {
335
+ label: 'Column',
336
+ fieldType: 'SUniversalPColumnId',
337
+ defaultValue: () => undefined,
338
+ },
339
+ type: {
340
+ label: 'Predicate',
341
+ fieldType: 'FilterType',
342
+ defaultValue: () => 'patternEquals',
343
+ },
344
+ value: {
345
+ label: 'Seq',
346
+ fieldType: 'string',
347
+ defaultValue: () => '',
348
+ },
349
+ },
350
+ supportedFor: isStringValueType,
351
+ },
352
+ patternNotEquals: {
353
+ label: 'Col ≠ Seq (Not Equal)',
354
+ form: {
355
+ column: {
356
+ label: 'Column',
357
+ fieldType: 'SUniversalPColumnId',
358
+ defaultValue: () => undefined,
359
+ },
360
+ type: {
361
+ label: 'Predicate',
362
+ fieldType: 'FilterType',
363
+ defaultValue: () => 'patternNotEquals',
364
+ },
365
+ value: {
366
+ label: 'Seq',
367
+ fieldType: 'string',
368
+ defaultValue: () => '',
369
+ },
370
+ },
371
+ supportedFor: isStringValueType,
372
+ },
373
+ isNA: {
374
+ label: 'Is NA',
375
+ form: {
376
+ column: {
377
+ label: 'Column',
378
+ fieldType: 'SUniversalPColumnId',
379
+ defaultValue: () => undefined,
380
+ },
381
+ type: {
382
+ label: 'Predicate',
383
+ fieldType: 'FilterType',
384
+ defaultValue: () => 'isNA',
385
+ },
386
+ },
387
+ supportedFor: () => true,
388
+ },
389
+ isNotNA: {
390
+ label: 'Is Not NA',
391
+ form: {
392
+ column: {
393
+ label: 'Column',
394
+ fieldType: 'SUniversalPColumnId',
395
+ defaultValue: () => undefined,
396
+ },
397
+ type: {
398
+ label: 'Predicate',
399
+ fieldType: 'FilterType',
400
+ defaultValue: () => 'isNotNA',
401
+ },
402
+ },
403
+ supportedFor: () => true,
404
+ },
405
+ or: {
406
+ label: 'Or',
407
+ form: {
408
+ type: {
409
+ fieldType: 'FilterType',
410
+ label: 'Predicate',
411
+ defaultValue: () => 'or',
412
+ },
413
+ filters: {
414
+ fieldType: 'unknown[]',
415
+ label: 'Filters',
416
+ defaultValue: () => [],
417
+ },
418
+ },
419
+ supportedFor: () => false,
420
+ },
421
+ and: {
422
+ label: 'And',
423
+ form: {
424
+ type: {
425
+ fieldType: 'FilterType',
426
+ label: 'Predicate',
427
+ defaultValue: () => 'and',
428
+ },
429
+ filters: {
430
+ fieldType: 'unknown[]',
431
+ label: 'Filters',
432
+ defaultValue: () => [],
433
+ },
434
+ },
435
+ supportedFor: () => false,
436
+ },
437
+ not: {
438
+ label: 'Not',
439
+ form: {
440
+ type: {
441
+ fieldType: 'FilterType',
442
+ label: 'Predicate',
443
+ defaultValue: () => 'not',
444
+ },
445
+ filter: {
446
+ fieldType: 'form',
447
+ label: 'Filter',
448
+ defaultValue: () => undefined,
449
+ },
450
+ },
451
+ supportedFor: () => false,
452
+ },
453
+ } satisfies FilterSpecMetadataRecord<FilterSpecType>;
454
+
455
+ export function getFilterUiTypeOptions(columnSpec?: SimplifiedPColumnSpec) {
456
+ if (!columnSpec) {
457
+ return [];
458
+ }
459
+
460
+ return Object.entries(filterUiMetadata).filter(([_, metadata]) => metadata.supportedFor(columnSpec)).map(([type, metadata]) => ({
461
+ label: metadata.label,
462
+ value: type,
463
+ }));
464
+ }
465
+
466
+ export function getFilterUiMetadata(type: FilterSpecType) {
467
+ return filterUiMetadata[type];
468
+ }
469
+
470
+ function isNumericValueType(spec: SimplifiedPColumnSpec): boolean {
471
+ return spec.valueType === 'Int' || spec.valueType === 'Long' || spec.valueType === 'Float' || spec.valueType === 'Double';
472
+ }
473
+
474
+ function isStringValueType(spec: SimplifiedPColumnSpec): boolean {
475
+ return spec.valueType === 'String';
476
+ }
@@ -0,0 +1,44 @@
1
+ import type { FilterSpec, FilterSpecOfType, FilterSpecType, SimplifiedPColumnSpec, SUniversalPColumnId } from '@platforma-sdk/model';
2
+
3
+ /** Metadata about a single field in FilterSpec */
4
+ export type FilterSpecTypeField<V> = {
5
+ label: string;
6
+ fieldType: FilterSpecTypeToLiteral<V>;
7
+ defaultValue: () => V | undefined;
8
+ };
9
+
10
+ /** Converts each field in FilterSpec to FilterSpecTypeField */
11
+ export type FilterSpecTypeFieldRecord<T extends FilterSpec> = { [K in keyof T]: FilterSpecTypeField<T[K]>; };
12
+
13
+ /** Extracts FilterSpecOfType from FilterSpecType */
14
+ export type FilterSpecFormField<T extends FilterSpec> = {
15
+ [K in keyof T]: FilterSpecTypeField<T[K]>
16
+ };
17
+
18
+ /** Metadata about all supported filter types */
19
+ export type FilterSpecMetadataRecord<T extends FilterSpecType> = {
20
+ [P in T]: {
21
+ label: string;
22
+ labelNot?: string;
23
+ form: FilterSpecFormField<FilterSpecOfType<P>>;
24
+ supportedFor: (spec1: SimplifiedPColumnSpec, spec2: SimplifiedPColumnSpec | undefined) => boolean;
25
+ }
26
+ };
27
+
28
+ /** Converts FilterSpecType to a literal string representing the type */
29
+ export type FilterSpecTypeToLiteral<T> =
30
+ [T] extends [FilterSpecType] ? 'FilterType' :
31
+ [T] extends [SUniversalPColumnId] ? 'SUniversalPColumnId' :
32
+ [T] extends [number] ? 'number' :
33
+ [T] extends [number | undefined] ? 'number?' :
34
+ [T] extends [string] ? 'string' :
35
+ [T] extends [string | undefined] ? 'string?' :
36
+ [T] extends [boolean] ? 'boolean' :
37
+ [T] extends [boolean | undefined] ? 'boolean?' :
38
+ [T] extends [unknown[]] ? 'unknown[]' :
39
+ // this is special
40
+ T extends number ? 'number' :
41
+ T extends string ? 'string' :
42
+ T extends boolean ? 'boolean' :
43
+ T extends Record<string, unknown> ? 'form' :
44
+ 'unknown';
package/src/index.ts CHANGED
@@ -114,9 +114,10 @@ export { useSortable } from './composition/useSortable';
114
114
  export { useSortable2 } from './composition/useSortable2';
115
115
  export { useTheme } from './composition/useTheme';
116
116
 
117
+ export * from './composition/computedCached';
118
+ export * from './composition/filters';
117
119
  export * from './composition/useWatchFetch';
118
120
  export * from './composition/watchCached';
119
- export * from './composition/computedCached';
120
121
 
121
122
  /**
122
123
  * Utils/Partials
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpandTransition.vue.js","sources":["../../../src/components/PlAccordion/ExpandTransition.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nconst onStart = (el: Element) => {\n el.classList.add('expand-collapse-fix');\n (el as HTMLElement).style.setProperty('--component-height', el.scrollHeight + 'px');\n};\n\nconst onAfter = (el: Element) => {\n (el as HTMLElement).style.removeProperty('--component-height');\n el.classList.remove('expand-collapse-fix');\n};\n</script>\n\n<template>\n <Transition name=\"expand-collapse\" @enter=\"onStart\" @leave=\"onStart\" @after-enter=\"onAfter\" @after-leave=\"onAfter\">\n <slot/>\n </Transition>\n</template>\n\n<style>\n.expand-collapse-fix {\n overflow: hidden;\n}\n\n.expand-collapse-enter-active,\n.expand-collapse-leave-active {\n transition:\n height 0.2s ease-in-out,\n opacity 0.2s ease-in-out;\n height: var(--component-height);\n}\n\n.expand-collapse-enter-from,\n.expand-collapse-leave-to {\n opacity: 0.5;\n height: 0;\n}\n</style>\n"],"names":["onStart","el","onAfter"],"mappings":";;;;AACA,UAAMA,IAAU,CAACC,MAAgB;AAC/B,MAAAA,EAAG,UAAU,IAAI,qBAAqB,GACrCA,EAAmB,MAAM,YAAY,sBAAsBA,EAAG,eAAe,IAAI;AAAA,IACpF,GAEMC,IAAU,CAACD,MAAgB;AAC9B,MAAAA,EAAmB,MAAM,eAAe,oBAAoB,GAC7DA,EAAG,UAAU,OAAO,qBAAqB;AAAA,IAC3C;;;;;;;;;;;;;;;"}