@tai42/studio-sdk 19.2.0 → 19.3.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.
Files changed (57) hide show
  1. package/dist/hooks/useApi.d.ts +9 -0
  2. package/dist/hooks/useApi.d.ts.map +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/schema-form/classify.d.ts.map +1 -1
  8. package/dist/schema-form/classify.js +49 -4
  9. package/dist/schema-form/classify.js.map +1 -1
  10. package/dist/schema-form/default-value.js +1 -0
  11. package/dist/schema-form/default-value.js.map +1 -1
  12. package/dist/schema-form/enum-field.d.ts.map +1 -1
  13. package/dist/schema-form/enum-field.js +3 -1
  14. package/dist/schema-form/enum-field.js.map +1 -1
  15. package/dist/schema-form/field-model.d.ts +23 -0
  16. package/dist/schema-form/field-model.d.ts.map +1 -1
  17. package/dist/schema-form/field-node.d.ts.map +1 -1
  18. package/dist/schema-form/field-node.js +31 -3
  19. package/dist/schema-form/field-node.js.map +1 -1
  20. package/dist/schema-form/index.d.ts +1 -0
  21. package/dist/schema-form/index.d.ts.map +1 -1
  22. package/dist/schema-form/index.js +1 -0
  23. package/dist/schema-form/index.js.map +1 -1
  24. package/dist/schema-form/multiselect-field.d.ts +20 -0
  25. package/dist/schema-form/multiselect-field.d.ts.map +1 -0
  26. package/dist/schema-form/multiselect-field.js +24 -0
  27. package/dist/schema-form/multiselect-field.js.map +1 -0
  28. package/dist/schema-form/object-fields.d.ts.map +1 -1
  29. package/dist/schema-form/object-fields.js +5 -0
  30. package/dist/schema-form/object-fields.js.map +1 -1
  31. package/dist/schema-form/string-field.d.ts +3 -2
  32. package/dist/schema-form/string-field.d.ts.map +1 -1
  33. package/dist/schema-form/string-field.js +6 -2
  34. package/dist/schema-form/string-field.js.map +1 -1
  35. package/dist/schema-form/types.d.ts +38 -0
  36. package/dist/schema-form/types.d.ts.map +1 -1
  37. package/dist/schema-form/validate.d.ts.map +1 -1
  38. package/dist/schema-form/validate.js +156 -2
  39. package/dist/schema-form/validate.js.map +1 -1
  40. package/dist/schema-form/visibility.d.ts +21 -0
  41. package/dist/schema-form/visibility.d.ts.map +1 -0
  42. package/dist/schema-form/visibility.js +37 -0
  43. package/dist/schema-form/visibility.js.map +1 -0
  44. package/package.json +5 -5
  45. package/src/index.ts +1 -0
  46. package/src/schema-form/classify.ts +52 -3
  47. package/src/schema-form/default-value.ts +1 -0
  48. package/src/schema-form/enum-field.tsx +3 -1
  49. package/src/schema-form/field-model.ts +29 -0
  50. package/src/schema-form/field-node.tsx +61 -2
  51. package/src/schema-form/index.ts +1 -0
  52. package/src/schema-form/multiselect-field.tsx +58 -0
  53. package/src/schema-form/object-fields.tsx +4 -0
  54. package/src/schema-form/string-field.tsx +8 -1
  55. package/src/schema-form/types.ts +39 -0
  56. package/src/schema-form/validate.ts +176 -3
  57. package/src/schema-form/visibility.ts +47 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The single evaluator for a property's `visibleWhen` predicate — a static,
3
+ * declarative field-visibility rule (scope B). The renderer (`ObjectFields`) and the
4
+ * validator both call it so a field shown by the form is exactly the field validated at
5
+ * submit, and a hidden field is neither rendered nor required. It reads only sibling
6
+ * values already in the object; it never calls a consumer handler (that is scope A).
7
+ *
8
+ * A malformed predicate degrades to VISIBLE: the send-time server validation rejects a
9
+ * malformed predicate loudly, so one never reaches a well-formed render, and showing a
10
+ * field is the safe non-hiding default (a hidden-by-accident required field would dead-
11
+ * end a form).
12
+ */
13
+ import type { JsonSchema } from './types';
14
+
15
+ function isRecord(value: unknown): value is Record<string, unknown> {
16
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
17
+ }
18
+
19
+ /** A value is "empty" for a `notEmpty` test: absent/null, a blank string, an empty array. */
20
+ function isEmptyValue(value: unknown): boolean {
21
+ if (value === undefined || value === null) return true;
22
+ if (typeof value === 'string') return value.trim() === '';
23
+ if (Array.isArray(value)) return value.length === 0;
24
+ return false;
25
+ }
26
+
27
+ /**
28
+ * Whether a property carrying `schema.visibleWhen` is visible against the current
29
+ * `values` of its enclosing object. Absent predicate ⇒ always visible. Exactly one of
30
+ * `equals`/`in`/`notEmpty` must be present; otherwise the predicate is malformed and the
31
+ * field stays visible.
32
+ */
33
+ export function isFieldVisible(schema: JsonSchema, values: Record<string, unknown>): boolean {
34
+ const predicate: unknown = schema.visibleWhen;
35
+ if (!isRecord(predicate) || typeof predicate.field !== 'string') return true;
36
+ const current = values[predicate.field];
37
+
38
+ const inList = predicate.in;
39
+ const hasEquals = 'equals' in predicate;
40
+ const hasIn = Array.isArray(inList);
41
+ const hasNotEmpty = predicate.notEmpty === true;
42
+ if (Number(hasEquals) + Number(hasIn) + Number(hasNotEmpty) !== 1) return true;
43
+
44
+ if (hasEquals) return current === predicate.equals;
45
+ if (hasIn) return (inList as readonly unknown[]).some((candidate) => candidate === current);
46
+ return !isEmptyValue(current);
47
+ }