@poodle64/ui 2026.11.7 → 2026.11.8

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.
@@ -1,10 +1,6 @@
1
- import type { createAjv, JsonSchema } from '@jsonforms/core';
2
- /**
3
- * The Ajv instance `@jsonforms/core` builds. Typed through its own factory so
4
- * this package never names `ajv` — a transitive dependency of the engine, not
5
- * a dependency of ours.
6
- */
7
- export type FormAjv = ReturnType<typeof createAjv>;
1
+ import type { JsonSchema } from '@jsonforms/core';
2
+ import type { FormAjv } from './validator.js';
3
+ export type { FormAjv };
8
4
  /**
9
5
  * The form-wide facts every nested element needs, published once by
10
6
  * `<SchemaForm>` rather than drilled through a recursive component tree.
@@ -22,7 +18,7 @@ export interface SchemaFormContext {
22
18
  readonly idPrefix: string;
23
19
  /** Validation messages by dot path, from the schema itself. */
24
20
  readonly errors: Record<string, string[]>;
25
- /** The shared Ajv instance rule conditions are evaluated with. */
21
+ /** The validator rule conditions are evaluated with. */
26
22
  readonly ajv: FormAjv;
27
23
  /** Commit one field. */
28
24
  change: (path: string, value: unknown) => void;
@@ -1,10 +1,11 @@
1
1
  <script lang="ts">
2
- import { createAjv, Generate, type UISchemaElement } from '@jsonforms/core';
2
+ import { Generate, type UISchemaElement } from '@jsonforms/core';
3
3
  import Panel from '../panel/panel.svelte';
4
4
  import SchemaFormElement from './schema-form-element.svelte';
5
5
  import UnknownField from './widgets/unknown-field.svelte';
6
6
  import { setSchemaFormContext } from './context.js';
7
7
  import { addressedPaths, getAt, setAt, unmappedFields } from './data.js';
8
+ import { createRuleEvaluator, validateValue } from './validator.js';
8
9
  import { cn } from '../../../utils.js';
9
10
  import type { SchemaFormProps } from './types.js';
10
11
 
@@ -41,9 +42,10 @@
41
42
  class: className
42
43
  }: SchemaFormProps = $props();
43
44
 
44
- // One Ajv for the life of the form: rule conditions and validation both use
45
- // it, and compiling per keystroke would be the whole cost of the component.
46
- const ajv = createAjv();
45
+ // Rule conditions and validation both go through the interpreting validator
46
+ // in `validator.ts`: no `new Function`, so the apps' CSP (no `unsafe-eval`)
47
+ // holds.
48
+ const ajv = createRuleEvaluator();
47
49
 
48
50
  // No UI schema is a legitimate mode, not an error: generating one from the
49
51
  // schema is the only arrangement in which a field CANNOT be missing from the
@@ -53,31 +55,19 @@
53
55
  const addressed = $derived(addressedPaths(layout));
54
56
  const unmapped = $derived(unmappedFields(schema, addressed));
55
57
 
56
- /**
57
- * Validation messages by dot path. Ajv is asked about a CLONE, because
58
- * `createAjv` enables `useDefaults` and would otherwise write defaults into
59
- * the caller's value behind its back.
60
- */
58
+ /** Validation messages by dot path, from the schema itself. */
61
59
  const errors = $derived.by(() => {
62
60
  const byPath: Record<string, string[]> = {};
63
61
  if (!validate) return byPath;
64
62
  try {
65
- const check = ajv.compile(schema as object);
66
- const probe = structuredClone($state.snapshot(value));
67
- if (check(probe)) return byPath;
68
- for (const error of check.errors ?? []) {
69
- const missing = (error.params as { missingProperty?: string })?.missingProperty;
70
- const instance = error.instancePath.replace(/^\//, '').split('/').filter(Boolean).join('.');
71
- const path = missing ? [instance, missing].filter(Boolean).join('.') : instance;
72
- if (!path) continue;
73
- (byPath[path] ??= []).push(missing ? 'Required' : (error.message ?? 'is invalid'));
74
- }
63
+ for (const { path, message } of validateValue(schema as object, $state.snapshot(value)))
64
+ (byPath[path] ??= []).push(message);
75
65
  } catch {
76
- // A schema Ajv will not compile, or a value it will not clone, is still
77
- // a form this renderer can lay out — it simply cannot be validated.
78
- // Never let a validation problem blank the form: that is the failure
79
- // mode this whole component exists to remove.
80
- return byPath;
66
+ // A schema the validator will not read is still a form this renderer
67
+ // can lay out — it simply cannot be validated. Never let a validation
68
+ // problem blank the form: that is the failure mode this whole
69
+ // component exists to remove.
70
+ return {};
81
71
  }
82
72
  return byPath;
83
73
  });
@@ -0,0 +1,12 @@
1
+ import type { isVisible } from '@jsonforms/core';
2
+ /** The `ajv` slot `@jsonforms/core`'s rule helpers take. */
3
+ export type FormAjv = NonNullable<Parameters<typeof isVisible>[3]>;
4
+ export interface FieldError {
5
+ /** Dot path of the offending field (the missing one, for `required`). */
6
+ path: string;
7
+ message: string;
8
+ }
9
+ /** What `@jsonforms/core` calls for a rule's schema condition. */
10
+ export declare const createRuleEvaluator: () => FormAjv;
11
+ /** Field errors for `value` against `schema`, empty when valid. */
12
+ export declare const validateValue: (schema: object, value: unknown) => FieldError[];
@@ -0,0 +1,36 @@
1
+ import { Validator } from '@cfworker/json-schema';
2
+ /**
3
+ * The form's validator. It INTERPRETS the schema; Ajv's `compile` and
4
+ * `validate` generate source and run it through `new Function`, which the
5
+ * apps' `script-src 'self'` (no `unsafe-eval`) refuses. The schema arrives at
6
+ * runtime from the server, so Ajv's build-time standalone mode cannot help.
7
+ */
8
+ const check = (schema, value) => {
9
+ // JSON round trip: an `undefined` property is absent, as Ajv read it.
10
+ const result = new Validator(schema, '2019-09', false).validate(JSON.parse(JSON.stringify(value ?? null)));
11
+ return result.valid ? [] : result.errors;
12
+ };
13
+ /** What `@jsonforms/core` calls for a rule's schema condition. */
14
+ export const createRuleEvaluator = () => ({ validate: (schema, value) => check(schema, value).length === 0 });
15
+ const dotPath = (location) => location.replace(/^#\/?/, '').split('/').filter(Boolean).join('.');
16
+ /** Field errors for `value` against `schema`, empty when valid. */
17
+ export const validateValue = (schema, value) => {
18
+ const out = [];
19
+ for (const error of check(schema, value)) {
20
+ // Only leaf keywords name a field; container keywords (properties,
21
+ // allOf...) restate their children's failures.
22
+ if (['properties', 'items', 'allOf', 'anyOf', 'oneOf', '$ref', '$recursiveRef'].includes(error.keyword))
23
+ continue;
24
+ const instance = dotPath(error.instanceLocation);
25
+ if (error.keyword === 'required') {
26
+ const missing = /"([^"]+)"/.exec(error.error)?.[1];
27
+ const path = [instance, missing].filter(Boolean).join('.');
28
+ if (path)
29
+ out.push({ path, message: 'Required' });
30
+ continue;
31
+ }
32
+ if (instance)
33
+ out.push({ path: instance, message: error.error });
34
+ }
35
+ return out;
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poodle64/ui",
3
- "version": "2026.11.7",
3
+ "version": "2026.11.8",
4
4
  "description": "Household shared component layer: shadcn-svelte primitives (bits-ui) plus the composed page chrome every app builds its routes from, restyled by each app's @poodle64/design-tokens alias layer. One fix reaches every app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -77,6 +77,7 @@
77
77
  }
78
78
  },
79
79
  "dependencies": {
80
+ "@cfworker/json-schema": "^4.1.6",
80
81
  "@grafana/faro-web-sdk": "^2.11.0",
81
82
  "@grafana/faro-web-tracing": "^2.11.0",
82
83
  "@jsonforms/core": "^3.8.0",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "package": "@poodle64/ui",
4
- "version": "2026.11.7",
4
+ "version": "2026.11.8",
5
5
  "generatedBy": "scripts/generate-registry.mjs",
6
6
  "source": "scripts/situations.json + package source (DO NOT EDIT the outputs by hand)",
7
7
  "componentCount": 76,
@@ -1,7 +1,7 @@
1
1
  # @poodle64/ui — situation → component map
2
2
 
3
3
  <!-- GENERATED by scripts/generate-registry.mjs from scripts/situations.json + package source. DO NOT EDIT. -->
4
- Generated from `@poodle64/ui@2026.11.7`. 76 components, 20 situations.
4
+ Generated from `@poodle64/ui@2026.11.8`. 76 components, 20 situations.
5
5
 
6
6
  **Read this before writing a `<div>`.** Find the SITUATION you are in below, then compose the component named for it — do not hand-build it from raw `Card` or utility classes. Import is `import { Name } from '<import path>'`. Props marked `?` are optional. This map is the retrieval step the [`design-frontend` skill] makes mandatory; the [CHI 2026 study] measured composing-from-a-registry at 95% design-system compliance against 71% for writing the CSS from a prose style guide.
7
7