From 12986a70b54a4d16d66a69edf41d45c619923a39 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 06:33:38 +0000 Subject: [PATCH 1/6] feat(spec, ui): an object takes a colour from a fixed palette, and the navigation draws it as a white glyph on a square of that colour - `ObjectSchema.color` and `BlueprintObjectSchema.color`: one leaf, a closed nine-name palette (`OBJECT_COLORS`); a free value is refused with the names listed. - `ObjectIconTile` in `@object-ui/components`. - Sidebar, app-home and phone menus draw object entries as tiles (`resolveTargetColor` / `useNavTargetColor`). - Object designer: the icon picker carries the palette and previews tiles; the generic object form gains a `color` swatch row (10 locales). Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgT9PKAmy86XfbYbZtW --- .changeset/35985-object-color-tile.md | 19 ++++ .../docs/references/ai/solution-blueprint.mdx | 3 + content/docs/references/api/metadata.mdx | 1 + content/docs/references/data/object.mdx | 1 + content/docs/references/system/migration.mdx | 2 + .../ar.metadata-forms.generated.ts | 4 + .../de.metadata-forms.generated.ts | 4 + .../en.metadata-forms.generated.ts | 4 + .../es-ES.metadata-forms.generated.ts | 4 + .../fr.metadata-forms.generated.ts | 4 + .../ja-JP.metadata-forms.generated.ts | 4 + .../ko.metadata-forms.generated.ts | 4 + ...-collapsed-sections-echo-decisions.test.ts | 5 +- ...ect-lifecycle-panel-echo-decisions.test.ts | 4 +- .../pt-BR.metadata-forms.generated.ts | 4 + .../ru.metadata-forms.generated.ts | 4 + .../zh-CN.metadata-forms.generated.ts | 4 + .../zh-Hant.metadata-forms.generated.ts | 4 + packages/spec/api-surface/data.json | 2 + packages/spec/authorable-surface/ai.json | 1 + packages/spec/authorable-surface/data.json | 1 + packages/spec/export-origins/data.json | 2 + packages/spec/liveness/object.json | 7 ++ packages/spec/liveness/state-counts/object.md | 2 +- .../spec/src/ai/solution-blueprint.test.ts | 68 +++++++++-- .../spec/src/ai/solution-blueprint.zod.ts | 13 ++- packages/spec/src/data/index.ts | 3 + packages/spec/src/data/object-color.test.ts | 35 ++++++ packages/spec/src/data/object-icon.ts | 27 +++++ packages/spec/src/data/object.form.ts | 3 + packages/spec/src/data/object.zod.ts | 4 +- .../app-shell/src/hooks/useNavTargetIcon.ts | 23 +++- .../app-shell/src/layout/UnifiedSidebar.tsx | 4 +- .../metadata-admin/color-variant-field.tsx | 13 ++- ...tDefaultInspector.iconColor-35985.test.tsx | 87 ++++++++++++++ ...DefaultInspector.iconPicker-12531.test.tsx | 4 +- .../ObjectDefaultInspector.test.tsx | 4 +- .../inspectors/ObjectDefaultInspector.tsx | 9 +- .../src/views/metadata-admin/widgets.tsx | 63 ++++++++++- .../app-shell/src/views/nav-menu-renderer.tsx | 16 ++- .../__tests__/object-icon-tile-35985.test.tsx | 92 +++++++++++++++ ui/packages/components/src/custom/index.ts | 7 ++ .../src/custom/object-icon-tile.tsx | 107 ++++++++++++++++++ ui/packages/i18n/src/namespaces/studio/en.ts | 12 ++ ui/packages/i18n/src/namespaces/studio/zh.ts | 12 ++ ui/packages/layout/src/NavigationRenderer.tsx | 49 +++++++- ...hemaRenderer.mobileTabOrder-11395.test.tsx | 14 ++- ...vigationRenderer.objectTile-35985.test.tsx | 73 ++++++++++++ 48 files changed, 800 insertions(+), 36 deletions(-) create mode 100644 .changeset/35985-object-color-tile.md create mode 100644 packages/spec/src/data/object-color.test.ts create mode 100644 ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconColor-35985.test.tsx create mode 100644 ui/packages/components/src/__tests__/object-icon-tile-35985.test.tsx create mode 100644 ui/packages/components/src/custom/object-icon-tile.tsx create mode 100644 ui/packages/layout/src/__tests__/NavigationRenderer.objectTile-35985.test.tsx diff --git a/.changeset/35985-object-color-tile.md b/.changeset/35985-object-color-tile.md new file mode 100644 index 00000000000..27f9c08c27b --- /dev/null +++ b/.changeset/35985-object-color-tile.md @@ -0,0 +1,19 @@ +--- +'@objectstack/spec': minor +'@object-ui/components': minor +'@object-ui/layout': minor +'@object-ui/app-shell': minor +'@object-ui/i18n': minor +--- + +feat(spec, ui): an object takes a colour from a fixed palette, and its icon is drawn as a white glyph on a square of that colour + +Clause-②: yes (widening) +Metadata-protocol: added + +- **`ObjectSchema.color` (new, optional).** One name from a closed palette of nine: `gray`, `blue`, `teal`, `green`, `amber`, `orange`, `red`, `pink`, `purple` (exported as `OBJECT_COLORS` and the `ObjectColor` type from `@objectstack/spec/data`). No free colour values: `color: '#ff0000'` is refused, and the refusal lists the nine names. An object without a `color` is drawn in the neutral `gray`. Nothing to migrate: every existing object stays valid and simply has no colour. +- **The AI blueprint carries it too.** `BlueprintObjectSchema.color` is the same leaf (required-but-nullable on `SolutionBlueprintStrictSchema`, like `icon`), and its rule asks the model to colour every object and give each object of one solution a different colour while the palette lasts. +- **`ObjectIconTile` (new, `@object-ui/components`).** Draws an icon name as a white glyph on a rounded square of a palette colour, in four sizes. Each name has a light-theme and a dark-theme value chosen so the white glyph keeps at least 3:1 contrast. `OBJECT_COLOR_TILE_CLASS` and `objectColorOrDefault` are exported with it. +- **Navigation draws objects as tiles.** In the sidebar, the app-home menu and the phone menu, every entry that opens an object is drawn as that object's tile: the entry's own `icon` when it names one, else the object's, on the object's colour. Dashboards, pages and links keep their line icons. `NavigationRenderer` takes a new `resolveTargetColor` resolver (`NavTargetColorResolver`) beside `resolveTargetIcon`; the console answers it from the object metadata it already holds (`useNavTargetColor`). +- **The designer picks icon and colour together.** In the object's settings, the icon picker shows the nine colour swatches, and the trigger and every icon in the grid are previewed as the tile they become. The picker elsewhere (pages, apps, navigation entries) is unchanged: only objects carry a colour. +- The other places that draw an object's icon (list and record headers, search, related-record chips, the designer's object lists) switch to the tile in a follow-up release. diff --git a/content/docs/references/ai/solution-blueprint.mdx b/content/docs/references/ai/solution-blueprint.mdx index 026d0e26861..9c79140709c 100644 --- a/content/docs/references/ai/solution-blueprint.mdx +++ b/content/docs/references/ai/solution-blueprint.mdx @@ -217,6 +217,7 @@ const result = BlueprintAppSchema.parse(data); | **label** | `string` | optional | Human-readable singular label | | **description** | `string` | optional | What this object represents | | **icon** | `string` | optional | The built object's icon, carried into the object as its `icon`: a Lucide icon name for what the records are (e.g. "users" for contacts, "receipt" for invoices, "ticket" for support tickets). SET it on every object: an object without one is drawn with a generic glyph. | +| **color** | `Enum<'gray' \| 'blue' \| 'teal' \| 'green' \| 'amber' \| 'orange' \| 'red' \| 'pink' \| 'purple'>` | optional | The built object's colour, carried into the object as its `color`: one palette name, the colour of the square its icon is drawn on. SET it on every object, and give each object of the solution a DIFFERENT colour while the palette lasts, so the objects tell apart at a glance in the menu; repeat a colour only once all nine are used. | | **fields** | `{ name: string; label?: string; type: Enum<'text' \| 'textarea' \| 'email' \| 'url' \| 'phone' \| 'password' \| 'secret' \| …>; required?: boolean; … }[]` | ✅ | Fields to create on the object | | **sharingModel** | `Enum<'private' \| 'public_read' \| 'public_read_write' \| 'controlled_by_parent'>` | optional | Org-Wide Default record visibility (OWD) for INTERNAL users — the deliberate sharing choice for this object (ADR-0090). Canonical four only: private (owner-only) \| public_read (everyone reads, owner writes) \| public_read_write (everyone reads+writes) \| controlled_by_parent (derived from the master record — ONLY for an object whose fields include a master_detail reference). SET it when the user's description implies a visibility intent — personal/private data (HR, 绩效, salary, 个人隐私) → "private"; shared reference data everyone edits → "public_read_write". Omit to accept the platform's deterministic default (business object → public_read_write; master-detail child → controlled_by_parent) — omitting on privacy-sensitive data silently over-shares it. | | **nameField** | `string` | optional | The record title field — which field holds the human-readable name shown on cards, lookup chips, breadcrumbs and search (ADR-0079). Set it to the object's text label field (e.g. "product_name"). For a numbered entity (invoice/ticket), set it to a formula field that composes number + name (e.g. a formula "record.order_no + ' · ' + record.customer.name" — a lookup's name is read one hop through it, `record..`). A formula title is computed on read and stored nowhere: it is shown everywhere, but a list cannot sort by it and search does not scan it. Omitting it lets the platform auto-pick a text field, but declaring it is strongly preferred. | @@ -352,6 +353,7 @@ Sort field and direction pair | **label** | `string` | optional | Human-readable singular label | | **description** | `string` | optional | What this object represents | | **icon** | `string` | optional | The built object's icon, carried into the object as its `icon`: a Lucide icon name for what the records are (e.g. "users" for contacts, "receipt" for invoices, "ticket" for support tickets). SET it on every object: an object without one is drawn with a generic glyph. | +| **color** | `Enum<'gray' \| 'blue' \| 'teal' \| 'green' \| 'amber' \| 'orange' \| 'red' \| 'pink' \| 'purple'>` | optional | The built object's colour, carried into the object as its `color`: one palette name, the colour of the square its icon is drawn on. SET it on every object, and give each object of the solution a DIFFERENT colour while the palette lasts, so the objects tell apart at a glance in the menu; repeat a colour only once all nine are used. | | **fields** | `{ name: string; label?: string; type: Enum<'text' \| 'textarea' \| 'email' \| 'url' \| 'phone' \| 'password' \| 'secret' \| …>; required?: boolean; … }[]` | ✅ | Fields to create on the object | | **sharingModel** | `Enum<'private' \| 'public_read' \| 'public_read_write' \| 'controlled_by_parent'>` | optional | Org-Wide Default record visibility (OWD) for INTERNAL users — the deliberate sharing choice for this object (ADR-0090). Canonical four only: private (owner-only) \| public_read (everyone reads, owner writes) \| public_read_write (everyone reads+writes) \| controlled_by_parent (derived from the master record — ONLY for an object whose fields include a master_detail reference). SET it when the user's description implies a visibility intent — personal/private data (HR, 绩效, salary, 个人隐私) → "private"; shared reference data everyone edits → "public_read_write". Omit to accept the platform's deterministic default (business object → public_read_write; master-detail child → controlled_by_parent) — omitting on privacy-sensitive data silently over-shares it. | | **nameField** | `string` | optional | The record title field — which field holds the human-readable name shown on cards, lookup chips, breadcrumbs and search (ADR-0079). Set it to the object's text label field (e.g. "product_name"). For a numbered entity (invoice/ticket), set it to a formula field that composes number + name (e.g. a formula "record.order_no + ' · ' + record.customer.name" — a lookup's name is read one hop through it, `record..`). A formula title is computed on read and stored nowhere: it is shown everywhere, but a list cannot sort by it and search does not scan it. Omitting it lets the platform auto-pick a text field, but declaring it is strongly preferred. | @@ -420,6 +422,7 @@ Sort field and direction pair | **label** | `string \| null` | ✅ | Human-readable singular label, or null | | **description** | `string \| null` | ✅ | What this object represents, or null | | **icon** | `string \| null` | ✅ | The built object's icon, carried into the object as its `icon`: a Lucide icon name for what the records are (e.g. "users" for contacts, "receipt" for invoices, "ticket" for support tickets). SET it on every object: an object without one is drawn with a generic glyph. Null only when no icon fits. | +| **color** | `Enum<'gray' \| 'blue' \| 'teal' \| 'green' \| 'amber' \| 'orange' \| 'red' \| 'pink' \| 'purple'> \| null` | ✅ | The built object's colour, carried into the object as its `color`: one palette name, the colour of the square its icon is drawn on. SET it on every object, and give each object of the solution a DIFFERENT colour while the palette lasts, so the objects tell apart at a glance in the menu; repeat a colour only once all nine are used. Null only to draw the neutral gray. | | **fields** | `{ name: string; label: string \| null; type: Enum<'text' \| 'textarea' \| 'email' \| 'url' \| 'phone' \| 'password' \| 'secret' \| …>; required: boolean \| null; … }[]` | ✅ | Fields to create on the object | | **sharingModel** | `Enum<'private' \| 'public_read' \| 'public_read_write' \| 'controlled_by_parent'> \| null` | ✅ | Org-Wide Default record visibility (OWD) for INTERNAL users (ADR-0090), or null to accept the platform default (business object → public_read_write; master-detail child → controlled_by_parent). SET it when the user's description implies a visibility intent: personal/private data (HR, 绩效, salary, 个人隐私) → "private" (owner-only); "public_read" = everyone reads, owner writes; "public_read_write" = everyone reads+writes; "controlled_by_parent" ONLY for an object with a master_detail reference field. Null on privacy-sensitive data silently over-shares it. | | **nameField** | `string \| null` | ✅ | The record title field — which field holds the human-readable name shown on cards, lookup chips, breadcrumbs and search (ADR-0079), or null to let the platform auto-pick a text field. Set it to the object's text label field (e.g. "product_name") — snake_case. For a numbered entity (invoice/ticket), set it to a formula field that composes number + name (e.g. a formula "record.order_no + ' · ' + record.customer.name" — a lookup's name is read one hop through it, `record..`). A formula title is computed on read and stored nowhere: it is shown everywhere, but a list cannot sort by it and search does not scan it. Declaring it is strongly preferred over null. | diff --git a/content/docs/references/api/metadata.mdx b/content/docs/references/api/metadata.mdx index 5bd07c2600d..4e4fbb8fe4c 100644 --- a/content/docs/references/api/metadata.mdx +++ b/content/docs/references/api/metadata.mdx @@ -938,6 +938,7 @@ Metadata query with filtering, sorting, and pagination | **pluralLabel** | `string` | optional | Human readable plural label (e.g. "Accounts") | | **description** | `string` | optional | Developer documentation / description | | **icon** | `string` | optional | Icon name (Lucide/Material) for UI representation | +| **color** | `Enum<'gray' \| 'blue' \| 'teal' \| 'green' \| 'amber' \| 'orange' \| 'red' \| 'pink' \| 'purple'>` | optional | Object colour, one name from the fixed palette (gray, blue, teal, green, amber, orange, red, pink, purple). The console draws the object's icon as a white glyph on a rounded square of this colour, so one object looks the same wherever its icon appears. No free colour values. Omit to draw the neutral `gray`. | | **isSystem** | `boolean` | optional (default: `false`) | Is system object (protected from deletion; defaults its org-wide sharing to public when no sharingModel is set — plugin-sharing) | | **managedBy** | `Enum<'platform' \| 'config' \| 'system-data' \| 'engine-owned' \| 'append-only' \| …>` | optional | Lifecycle bucket — platform (user CRUD) \| config (admin authored) \| system-data (platform-defined schema, admin/user-writable data) \| engine-owned (engine owns the lifecycle, no user writes) \| append-only (audit) \| synced (rows copied by a pull from a connector or federated source; read-only to members, and userActions cannot open a write) \| better-auth (identity). UI clients honour the resolved affordance matrix. | | **ownership** | `Enum<'user' \| 'business_unit' \| 'org' \| 'none'>` | optional | Record-ownership model: user (default — injects reassignable owner_id plus owning_business_unit_id) \| business_unit (unit-owned: owning_business_unit_id only, no owner_id) \| org \| none (no per-record owner, neither anchor). Distinct from the package own/extend contribution kind. | diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index 2039c7c6511..8992221460a 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -150,6 +150,7 @@ const result = ApiMethod.parse(data); | **pluralLabel** | `string` | optional | Human readable plural label (e.g. "Accounts") | | **description** | `string` | optional | Developer documentation / description | | **icon** | `string` | optional | Icon name (Lucide/Material) for UI representation | +| **color** | `Enum<'gray' \| 'blue' \| 'teal' \| 'green' \| 'amber' \| 'orange' \| 'red' \| 'pink' \| 'purple'>` | optional | Object colour, one name from the fixed palette (gray, blue, teal, green, amber, orange, red, pink, purple). The console draws the object's icon as a white glyph on a rounded square of this colour, so one object looks the same wherever its icon appears. No free colour values. Omit to draw the neutral `gray`. | | **isSystem** | `boolean` | optional (default: `false`) | Is system object (protected from deletion; defaults its org-wide sharing to public when no sharingModel is set — plugin-sharing) | | **managedBy** | `Enum<'platform' \| 'config' \| 'system-data' \| 'engine-owned' \| 'append-only' \| 'synced' \| 'better-auth'>` | optional | Lifecycle bucket — platform (user CRUD) \| config (admin authored) \| system-data (platform-defined schema, admin/user-writable data) \| engine-owned (engine owns the lifecycle, no user writes) \| append-only (audit) \| synced (rows copied by a pull from a connector or federated source; read-only to members, and userActions cannot open a write) \| better-auth (identity). UI clients honour the resolved affordance matrix. | | **ownership** | `Enum<'user' \| 'business_unit' \| 'org' \| 'none'>` | optional | Record-ownership model: user (default — injects reassignable owner_id plus owning_business_unit_id) \| business_unit (unit-owned: owning_business_unit_id only, no owner_id) \| org \| none (no per-record owner, neither anchor). Distinct from the package own/extend contribution kind. | diff --git a/content/docs/references/system/migration.mdx b/content/docs/references/system/migration.mdx index 152ad135927..6721981500d 100644 --- a/content/docs/references/system/migration.mdx +++ b/content/docs/references/system/migration.mdx @@ -330,6 +330,7 @@ Create a new object | **pluralLabel** | `string` | optional | Human readable plural label (e.g. "Accounts") | | **description** | `string` | optional | Developer documentation / description | | **icon** | `string` | optional | Icon name (Lucide/Material) for UI representation | +| **color** | `Enum<'gray' \| 'blue' \| 'teal' \| 'green' \| 'amber' \| 'orange' \| 'red' \| 'pink' \| 'purple'>` | optional | Object colour, one name from the fixed palette (gray, blue, teal, green, amber, orange, red, pink, purple). The console draws the object's icon as a white glyph on a rounded square of this colour, so one object looks the same wherever its icon appears. No free colour values. Omit to draw the neutral `gray`. | | **isSystem** | `boolean` | optional (default: `false`) | Is system object (protected from deletion; defaults its org-wide sharing to public when no sharingModel is set — plugin-sharing) | | **managedBy** | `Enum<'platform' \| 'config' \| 'system-data' \| 'engine-owned' \| 'append-only' \| …>` | optional | Lifecycle bucket — platform (user CRUD) \| config (admin authored) \| system-data (platform-defined schema, admin/user-writable data) \| engine-owned (engine owns the lifecycle, no user writes) \| append-only (audit) \| synced (rows copied by a pull from a connector or federated source; read-only to members, and userActions cannot open a write) \| better-auth (identity). UI clients honour the resolved affordance matrix. | | **ownership** | `Enum<'user' \| 'business_unit' \| 'org' \| 'none'>` | optional | Record-ownership model: user (default — injects reassignable owner_id plus owning_business_unit_id) \| business_unit (unit-owned: owning_business_unit_id only, no owner_id) \| org \| none (no per-record owner, neither anchor). Distinct from the package own/extend contribution kind. | @@ -632,6 +633,7 @@ Create a new object | **pluralLabel** | `string` | optional | Human readable plural label (e.g. "Accounts") | | **description** | `string` | optional | Developer documentation / description | | **icon** | `string` | optional | Icon name (Lucide/Material) for UI representation | +| **color** | `Enum<'gray' \| 'blue' \| 'teal' \| 'green' \| 'amber' \| 'orange' \| 'red' \| 'pink' \| 'purple'>` | optional | Object colour, one name from the fixed palette (gray, blue, teal, green, amber, orange, red, pink, purple). The console draws the object's icon as a white glyph on a rounded square of this colour, so one object looks the same wherever its icon appears. No free colour values. Omit to draw the neutral `gray`. | | **isSystem** | `boolean` | optional (default: `false`) | Is system object (protected from deletion; defaults its org-wide sharing to public when no sharingModel is set — plugin-sharing) | | **managedBy** | `Enum<'platform' \| 'config' \| 'system-data' \| 'engine-owned' \| 'append-only' \| …>` | optional | Lifecycle bucket — platform (user CRUD) \| config (admin authored) \| system-data (platform-defined schema, admin/user-writable data) \| engine-owned (engine owns the lifecycle, no user writes) \| append-only (audit) \| synced (rows copied by a pull from a connector or federated source; read-only to members, and userActions cannot open a write) \| better-auth (identity). UI clients honour the resolved affordance matrix. | | **ownership** | `Enum<'user' \| 'business_unit' \| 'org' \| 'none'>` | optional | Record-ownership model: user (default — injects reassignable owner_id plus owning_business_unit_id) \| business_unit (unit-owned: owning_business_unit_id only, no owner_id) \| org \| none (no per-record owner, neither anchor). Distinct from the package own/extend contribution kind. | diff --git a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts index afaec88ad60..382db759cef 100644 --- a/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ar.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const arMetadataForms: NonNullable = { label: "الأيقونة", helpText: "اسم أيقونة Lucide (مثل \"building\"، \"users\")" }, + color: { + label: "اللون", + helpText: "لون المربع الذي تُرسم عليه الأيقونة، من لوحة الألوان الثابتة. إذا لم يُحدَّد يُرسم باللون الرمادي." + }, description: { label: "الوصف", helpText: "توثيق للمطوّرين" diff --git a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts index 84cebc842b8..c79377cea20 100644 --- a/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/de.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const deMetadataForms: NonNullable = { label: "Symbol", helpText: "Name des Lucide-Symbols (z. B. „building“, „users“)" }, + color: { + label: "Farbe", + helpText: "Farbe des Quadrats, auf dem das Symbol gezeichnet wird, aus der festen Palette. Ohne Angabe wird Grau verwendet." + }, description: { label: "Beschreibung", helpText: "Entwicklerdokumentation" diff --git a/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts index d868abe5c6d..fc9a6a87748 100644 --- a/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const enMetadataForms: NonNullable = { label: "Icon", helpText: "Lucide icon name (e.g. \"building\", \"users\")" }, + color: { + label: "Color", + helpText: "Color of the square the icon is drawn on, from the fixed palette. Unset draws gray." + }, description: { label: "Description", helpText: "Developer documentation" diff --git a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts index c88b022fe85..365233936ea 100644 --- a/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const esESMetadataForms: NonNullable = label: "Icono", helpText: "Nombre de icono Lucide (p. ej. \"building\", \"users\")" }, + color: { + label: "Color del icono", + helpText: "Color del cuadrado sobre el que se dibuja el icono, de la paleta fija. Si no se define, se usa gris." + }, description: { label: "Descripción", helpText: "Documentación para desarrolladores" diff --git a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts index 3747ea47878..cff810271a5 100644 --- a/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/fr.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const frMetadataForms: NonNullable = { label: "Icône", helpText: "Nom d’icône Lucide (par ex. « building », « users »)" }, + color: { + label: "Couleur", + helpText: "Couleur du carré sur lequel l’icône est dessinée, choisie dans la palette fixe. Sans valeur, le gris est utilisé." + }, description: { label: "Description", helpText: "Documentation pour les développeurs" diff --git a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts index 3b16546a11a..7342a1243f3 100644 --- a/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const jaJPMetadataForms: NonNullable = label: "アイコン", helpText: "Lucide アイコン名(例: \"building\", \"users\")" }, + color: { + label: "色", + helpText: "アイコンを描く角丸四角の色。固定パレットから選びます。未設定の場合はグレーになります。" + }, description: { label: "説明", helpText: "開発者向けドキュメント" diff --git a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts index 99c65e7f7d3..8ffd99b282f 100644 --- a/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ko.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const koMetadataForms: NonNullable = { label: "아이콘", helpText: "Lucide 아이콘 이름(예: \"building\", \"users\")" }, + color: { + label: "색상", + helpText: "아이콘이 그려지는 사각형의 색상으로, 고정 팔레트에서 선택합니다. 설정하지 않으면 회색으로 표시됩니다." + }, description: { label: "설명", helpText: "개발자 문서" diff --git a/packages/platform-objects/src/apps/translations/object-collapsed-sections-echo-decisions.test.ts b/packages/platform-objects/src/apps/translations/object-collapsed-sections-echo-decisions.test.ts index 0eb27dced01..55ab3652c0b 100644 --- a/packages/platform-objects/src/apps/translations/object-collapsed-sections-echo-decisions.test.ts +++ b/packages/platform-objects/src/apps/translations/object-collapsed-sections-echo-decisions.test.ts @@ -992,7 +992,10 @@ describe('#19403 round 8 — the population, DERIVED from the form and a shape', // 126 since #35900 gave the `fieldGroups` repeater its `fields` sub-row // (the group's own member list) — label and help text, authored in every // translated locale by that card, so `openEchoes` stays at zero. - expect(OPEN_LEAVES.length).toBe(126); + // 128 since #35985 gave `basics` the `color` row (the object's palette + // colour) — label and help text, authored in every translated locale by + // that card, so `openEchoes` stays at zero. + expect(OPEN_LEAVES.length).toBe(128); expect(PANEL_LEAVES.some((l) => l.path === 'fields.placeholder')).toBe(false); expect(OPEN_LEAVES.some((l) => l.path === 'fields.placeholder')).toBe(true); for (const path of ['name', 'label', 'fields', 'fields.valueDomain', 'fields.deleteBehavior', 'fields.expression']) { diff --git a/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts b/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts index b783b9ef0fe..932796c27ee 100644 --- a/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts +++ b/packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts @@ -1300,7 +1300,9 @@ describe('#19403 round 10 — the verdicts, on the live bundles', () => { // 755 since #35900: the object form's `fieldGroups` repeater offers // `fields` (the group's own member list) — one row label, authored in // all three locales. - expect(translated.length, `${locale} positive control`).toBe(755); + // 756 since #35985: the object form's `basics` offers a `color` row, + // whose label zh-CN translates. + expect(translated.length, `${locale} positive control`).toBe(756); } // ⭐ DARK — the blindness, executable. On a synthetic two-locale catalog the // all-three predicate returns 0 while the per-locale one returns 1, so the diff --git a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts index f82fafe2cd7..22893365000 100644 --- a/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/pt-BR.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const ptBRMetadataForms: NonNullable = label: "Ícone", helpText: "Nome do ícone Lucide (por exemplo \"building\", \"users\")" }, + color: { + label: "Cor", + helpText: "Cor do quadrado em que o ícone é desenhado, da paleta fixa. Sem valor, usa cinza." + }, description: { label: "Descrição", helpText: "Documentação para desenvolvedores" diff --git a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts index b6682e2d2fc..5299aaf0a00 100644 --- a/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/ru.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const ruMetadataForms: NonNullable = { label: "Значок", helpText: "Имя значка Lucide (например, \"building\", \"users\")" }, + color: { + label: "Цвет", + helpText: "Цвет квадрата, на котором рисуется значок, из фиксированной палитры. Если не задан, используется серый." + }, description: { label: "Описание", helpText: "Документация для разработчиков" diff --git a/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts index 34162fdde6c..2dadd950016 100644 --- a/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const zhCNMetadataForms: NonNullable = label: "图标", helpText: "Lucide 图标名称(如:\"building\"、\"users\")" }, + color: { + label: "颜色", + helpText: "图标所在圆角方块的颜色,从固定色板中选择。未设置时为灰色。" + }, description: { label: "描述", helpText: "开发文档说明" diff --git a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts index 3ba2a7996fb..a2f32ae5155 100644 --- a/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts +++ b/packages/platform-objects/src/apps/translations/zh-Hant.metadata-forms.generated.ts @@ -52,6 +52,10 @@ export const zhHantMetadataForms: NonNullable label: "圖示", helpText: "Lucide 圖示名稱(如:\"building\"、\"users\")" }, + color: { + label: "顏色", + helpText: "圖示所在圓角方塊的顏色,從固定色板中選擇。未設定時為灰色。" + }, description: { label: "描述", helpText: "開發文件說明" diff --git a/packages/spec/api-surface/data.json b/packages/spec/api-surface/data.json index 8994ef54081..7c6a5737267 100644 --- a/packages/spec/api-surface/data.json +++ b/packages/spec/api-surface/data.json @@ -573,6 +573,7 @@ "NumericColumnRepresentation (type)", "NumericStringGrammarCase (type)", "NumericStringReading (type)", + "OBJECT_COLORS (const)", "OBJECT_KEY_GUIDANCE (const)", "ORACLE_DEFAULT_PORT (const)", "ORGANIZATION_UNIT_CODE_PATTERN (const)", @@ -584,6 +585,7 @@ "ObjectCapabilities (const)", "ObjectCapabilities (type)", "ObjectCapabilitiesParsed (type)", + "ObjectColor (type)", "ObjectDependencyGraph (type)", "ObjectDependencyGraphParsed (type)", "ObjectDependencyGraphSchema (const)", diff --git a/packages/spec/authorable-surface/ai.json b/packages/spec/authorable-surface/ai.json index 651a1ba4ae8..6768d287b01 100644 --- a/packages/spec/authorable-surface/ai.json +++ b/packages/spec/authorable-surface/ai.json @@ -63,6 +63,7 @@ "ai/BlueprintNavItem:target", "ai/BlueprintNavItem:type", "ai/BlueprintNavItem:viewName", + "ai/BlueprintObject:color", "ai/BlueprintObject:description", "ai/BlueprintObject:fields", "ai/BlueprintObject:icon", diff --git a/packages/spec/authorable-surface/data.json b/packages/spec/authorable-surface/data.json index 9333ae32078..f8b14bebc70 100644 --- a/packages/spec/authorable-surface/data.json +++ b/packages/spec/authorable-surface/data.json @@ -677,6 +677,7 @@ "data/Object:actions", "data/Object:activityMilestones", "data/Object:attachedOnRead", + "data/Object:color", "data/Object:datasource", "data/Object:defaultRowScope", "data/Object:description", diff --git a/packages/spec/export-origins/data.json b/packages/spec/export-origins/data.json index 805daa39943..f83f4e79ce2 100644 --- a/packages/spec/export-origins/data.json +++ b/packages/spec/export-origins/data.json @@ -563,6 +563,7 @@ "NumericColumnRepresentation": "src/data/numeric-column-representation.ts#NumericColumnRepresentation (type)", "NumericStringGrammarCase": "src/data/filter-number-comparand-declared-type.ts#NumericStringGrammarCase (type)", "NumericStringReading": "src/data/filter-number-comparand-declared-type.ts#NumericStringReading (type)", + "OBJECT_COLORS": "src/data/object-icon.ts#OBJECT_COLORS (const)", "OBJECT_KEY_GUIDANCE": "src/data/authoring-key-lint.ts#OBJECT_KEY_GUIDANCE (const)", "ORACLE_DEFAULT_PORT": "src/data/driver/oracle.zod.ts#ORACLE_DEFAULT_PORT (const)", "ORGANIZATION_UNIT_CODE_PATTERN": "src/data/standard-units.ts#ORGANIZATION_UNIT_CODE_PATTERN (const)", @@ -573,6 +574,7 @@ "ObjectAccessConfigSchema": "src/data/object.zod.ts#ObjectAccessConfigSchema (const)", "ObjectCapabilities": "src/data/object.zod.ts#ObjectCapabilities (type)", "ObjectCapabilitiesParsed": "src/data/object.zod.ts#ObjectCapabilitiesParsed (type)", + "ObjectColor": "src/data/object-icon.ts#ObjectColor (type)", "ObjectDependencyGraph": "src/data/seed-loader.zod.ts#ObjectDependencyGraph (type)", "ObjectDependencyGraphParsed": "src/data/seed-loader.zod.ts#ObjectDependencyGraphParsed (type)", "ObjectDependencyGraphSchema": "src/data/seed-loader.zod.ts#ObjectDependencyGraphSchema (const)", diff --git a/packages/spec/liveness/object.json b/packages/spec/liveness/object.json index f1253234e7c..0d8ea0f8c84 100644 --- a/packages/spec/liveness/object.json +++ b/packages/spec/liveness/object.json @@ -23,6 +23,13 @@ "status": "live", "note": "objectui." }, + "color": { + "status": "live", + "verifiedAt": "2026-11-21", + "evidenceScope": "in-repo", + "evidence": "ui/packages/layout/src/NavigationRenderer.tsx#NavigationItemRenderer (an `object` navigation entry draws an ObjectIconTile coloured by `resolveTargetColor`); ui/packages/app-shell/src/hooks/useNavTargetIcon.ts#useNavTargetColor (reads the object's `color` from the metadata cache for the sidebar and the app-home menu); ui/packages/components/src/custom/object-icon-tile.tsx#ObjectIconTile (maps the palette name to the square's colour); ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.tsx#ObjectDefaultInspector (the designer writes it)", + "note": "objectstack#35985: the colour of the rounded square the object's icon is drawn on, from the closed palette `OBJECT_COLORS`. Unset draws the neutral gray. The navigation (sidebar, app-home menu, phone menu) reads it; the other places that draw an object icon follow in the card's second PR." + }, "displayNameField": { "status": "live", "note": "Deprecated alias of nameField (ADR-0079); still read by objectui RecordDetailView + resolveDisplayField back-compat." diff --git a/packages/spec/liveness/state-counts/object.md b/packages/spec/liveness/state-counts/object.md index 05655a3b5b8..be828af2273 100644 --- a/packages/spec/liveness/state-counts/object.md +++ b/packages/spec/liveness/state-counts/object.md @@ -12,4 +12,4 @@ committed anywhere: `check:liveness` sums the shards when it reads them. | Type | live | exp | elsewhere | dead | planned | classified | |---|---|---|---|---|---|---| -| `object` | 84 | 0 | 0 | 2 | 2 | 88 | +| `object` | 85 | 0 | 0 | 2 | 2 | 89 | diff --git a/packages/spec/src/ai/solution-blueprint.test.ts b/packages/spec/src/ai/solution-blueprint.test.ts index 1f095ec280a..dd2ccc8e4f4 100644 --- a/packages/spec/src/ai/solution-blueprint.test.ts +++ b/packages/spec/src/ai/solution-blueprint.test.ts @@ -595,6 +595,7 @@ describe('SolutionBlueprintStrictSchema (OpenAI strict mirror)', () => { label: null, description: null, icon: null, + color: null, sharingModel: null, nameField: null, stageField: null, @@ -638,7 +639,7 @@ describe('SolutionBlueprintStrictSchema (OpenAI strict mirror)', () => { const badField = { ...strictBp, objects: [ - { name: 'x', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'f', type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null }] }, + { name: 'x', label: null, description: null, icon: null, color: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'f', type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null }] }, ], }; // `f` is missing the (nullable, required) `label` key. @@ -660,6 +661,7 @@ describe('SolutionBlueprintStrictSchema (OpenAI strict mirror)', () => { label: null, description: null, icon: null, + color: null, sharingModel: null, nameField: null, stageField: null, @@ -1285,6 +1287,7 @@ describe('strict mirror ↔ lenient schema — VALUE parity', () => { label: null, description: null, icon: null, + color: null, sharingModel: null, nameField: null, stageField: null, @@ -1327,7 +1330,7 @@ describe('blueprint widget `aggregate` and calendar view `startDateField`', () = assumptions: [], questions: null, objects: [{ - name: 'interview', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, + name: 'interview', label: null, description: null, icon: null, color: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'score', label: null, type: 'number', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, @@ -1507,7 +1510,7 @@ describe('blueprint field `defaultValue`', () => { assumptions: [], questions: null, objects: [{ - name: 'task', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, + name: 'task', label: null, description: null, icon: null, color: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'flag', label: null, required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, ...field, @@ -1615,7 +1618,7 @@ describe('blueprint field `defaultValue`', () => { const bare = SolutionBlueprintStrictSchema.safeParse({ summary: 's', assumptions: [], questions: null, views: null, dashboards: null, app: null, objects: [{ - name: 'task', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, + name: 'task', label: null, description: null, icon: null, color: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'flag', label: null, type: 'boolean', required: null, reference: null, options: null, summaryOperations: null, expression: null, multiple: null, accept: null, maxSize: null, @@ -1714,7 +1717,7 @@ describe('blueprint field `expression` — the stored computed value', () => { assumptions: [], questions: null, objects: [{ - name: 'order_line', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, + name: 'order_line', label: null, description: null, icon: null, color: null, sharingModel: null, nameField: null, stageField: null, fields: [{ ...STORED, label: null, required: null, reference: null, options: null, summaryOperations: null, defaultValue: null, multiple: null, accept: null, maxSize: null, }], @@ -1803,7 +1806,7 @@ describe('blueprint object `icon`', () => { it('is required-but-nullable on the strict mirror (OpenAI strict: every key in `required`)', () => { const object = { - name: 'invoice', label: null, description: null, icon: 'receipt', sharingModel: null, nameField: null, stageField: null, + name: 'invoice', label: null, description: null, icon: 'receipt', color: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'title', label: null, type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null }], }; const bp = (o: Record) => ({ summary: 's', assumptions: [], questions: null, objects: [o], views: null, dashboards: null, app: null }); @@ -1816,6 +1819,57 @@ describe('blueprint object `icon`', () => { }); }); +// --------------------------------------------------------------------------- +// [#35985] The blueprint object's `color` — `ObjectSchema.color`'s own leaf. +// --------------------------------------------------------------------------- +describe('blueprint object `color`', () => { + const lenientColor = () => (SolutionBlueprintSchema as any).shape.objects.element.shape.color; + const strictColor = () => (SolutionBlueprintStrictSchema as any).shape.objects.element.shape.color; + const objectColor = () => (ObjectSchema as any).shape.color; + + it('is ObjectSchema.color\'s own leaf, by identity, on both sides', () => { + expect(lenientColor().unwrap()).toBe(objectColor().unwrap()); + expect(strictColor().unwrap()).toBe(objectColor().unwrap()); + }); + + it('tells the model to give every object a colour, a different one per object while the palette lasts', () => { + for (const leaf of [lenientColor(), strictColor()]) { + expect(leaf.description).toMatch(/SET it on every object/); + expect(leaf.description).toMatch(/DIFFERENT colour/); + } + }); + + it('carries a colour through the lenient parse, into a body the object schema accepts', () => { + const parsed = SolutionBlueprintSchema.parse({ + summary: 's', + objects: [{ name: 'invoice', icon: 'receipt', color: 'orange', fields: [{ name: 'title', type: 'text' }] }], + }); + expect(parsed.objects[0].color).toBe('orange'); + const asObject = { name: 'invoice', color: parsed.objects[0].color, fields: { title: { label: 'Title', type: 'text' } } }; + expect(ObjectSchema.safeParse(asObject).success).toBe(true); + }); + + it('refuses a colour outside the palette, at the key', () => { + const result = SolutionBlueprintSchema.safeParse({ summary: 's', objects: [{ name: 'invoice', color: '#ff0000', fields: [] }] }); + expect(result.success).toBe(false); + expect(result.error?.issues.map((i) => i.path.join('.'))).toEqual(['objects.0.color']); + }); + + it('is required-but-nullable on the strict mirror', () => { + const object = { + name: 'invoice', label: null, description: null, icon: 'receipt', color: 'teal', sharingModel: null, nameField: null, stageField: null, + fields: [{ name: 'title', label: null, type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null }], + }; + const bp = (o: Record) => ({ summary: 's', assumptions: [], questions: null, objects: [o], views: null, dashboards: null, app: null }); + expect(SolutionBlueprintStrictSchema.parse(bp(object)).objects[0].color).toBe('teal'); + expect(SolutionBlueprintStrictSchema.parse(bp({ ...object, color: null })).objects[0].color).toBeNull(); + const { color: _omit, ...missing } = object; + const result = SolutionBlueprintStrictSchema.safeParse(bp(missing)); + expect(result.success).toBe(false); + expect(result.error?.issues.map((i) => i.path.join('.'))).toEqual(['objects.0.color']); + }); +}); + // --------------------------------------------------------------------------- // [#32762] A blueprint view's `name`: the bare key, or `OBJECT.KEY` qualified // with the view's own object — the spelling every stored view record carries. @@ -1884,7 +1938,7 @@ describe('blueprint field `multiple`, `accept` and `maxSize`', () => { const strictField = (field: Record) => SolutionBlueprintStrictSchema.safeParse({ summary: 's', assumptions: [], questions: null, views: null, dashboards: null, app: null, objects: [{ - name: 'claim', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, + name: 'claim', label: null, description: null, icon: null, color: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'invoices', label: null, required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, ...field, diff --git a/packages/spec/src/ai/solution-blueprint.zod.ts b/packages/spec/src/ai/solution-blueprint.zod.ts index 0dbf86fe996..64a6ac3ea11 100644 --- a/packages/spec/src/ai/solution-blueprint.zod.ts +++ b/packages/spec/src/ai/solution-blueprint.zod.ts @@ -6,7 +6,7 @@ import { FieldType, SelectOptionSchema, multiDeclarableFieldTypes } from '../dat import { checkLiteralDefaultValue } from '../data/default-value-shape'; import { isRuntimeDefaultToken } from '../data/default-value-tokens'; import { FilterConditionSchema } from '../data/filter.zod'; -import { OBJECT_ICON_SCHEMA } from '../data/object-icon'; +import { OBJECT_COLOR_SCHEMA, OBJECT_ICON_SCHEMA } from '../data/object-icon'; import { refuseStageFieldWithoutKinds } from '../data/stage-field-kinds'; import { SortDirectionEnum, SortItemSchema } from '../shared/enums.zod'; import { VIEW_FILTER_OPERATORS, ViewFilterRuleSchema } from '../ui/view.zod'; @@ -516,6 +516,13 @@ function refuseBlueprintStageFieldWithoutKinds(object: unknown, ctx: z.Refinemen */ const OBJECT_ICON_RULE = 'The built object\'s icon, carried into the object as its `icon`: a Lucide icon name for what the records are (e.g. "users" for contacts, "receipt" for invoices, "ticket" for support tickets). SET it on every object: an object without one is drawn with a generic glyph.'; +/** + * What a blueprint object's `color` is, read on both sides (#35985): the + * object's own palette colour, carried onto the built object as + * `ObjectSchema.color`. + */ +const OBJECT_COLOR_RULE = 'The built object\'s colour, carried into the object as its `color`: one palette name, the colour of the square its icon is drawn on. SET it on every object, and give each object of the solution a DIFFERENT colour while the palette lasts, so the objects tell apart at a glance in the menu; repeat a colour only once all nine are used.'; + /** A proposed business object (table) with its fields. */ export const BlueprintObjectSchema = lazySchema(() => z.object({ name: z.string().regex(SNAKE_CASE).describe('Object machine name (snake_case)'), @@ -524,6 +531,8 @@ export const BlueprintObjectSchema = lazySchema(() => z.object({ // [#32763] `ObjectSchema.icon`'s own leaf, re-described for the blueprint, // so the blueprint accepts exactly the icon the object accepts. icon: OBJECT_ICON_SCHEMA.describe(OBJECT_ICON_RULE), + // [#35985] `ObjectSchema.color`'s own leaf, re-described for the blueprint. + color: OBJECT_COLOR_SCHEMA.describe(OBJECT_COLOR_RULE), fields: z.array(BlueprintFieldSchema).describe('Fields to create on the object'), sharingModel: z.enum(['private', 'public_read', 'public_read_write', 'controlled_by_parent']).optional() .describe('Org-Wide Default record visibility (OWD) for INTERNAL users — the deliberate sharing choice for this object (ADR-0090). Canonical four only: private (owner-only) | public_read (everyone reads, owner writes) | public_read_write (everyone reads+writes) | controlled_by_parent (derived from the master record — ONLY for an object whose fields include a master_detail reference). SET it when the user\'s description implies a visibility intent — personal/private data (HR, 绩效, salary, 个人隐私) → "private"; shared reference data everyone edits → "public_read_write". Omit to accept the platform\'s deterministic default (business object → public_read_write; master-detail child → controlled_by_parent) — omitting on privacy-sensitive data silently over-shares it.'), @@ -906,6 +915,8 @@ const StrictObject = z.object({ // The same `ObjectSchema.icon` leaf, in this mirror's spelling of "optional"; // the object key-parity pin fails if either side drops it. icon: OBJECT_ICON_SCHEMA.unwrap().nullable().describe(`${OBJECT_ICON_RULE} Null only when no icon fits.`), + // ⛔ Lockstep with the lenient `BlueprintObjectSchema.color` (#35985), as `icon` above. + color: OBJECT_COLOR_SCHEMA.unwrap().nullable().describe(`${OBJECT_COLOR_RULE} Null only to draw the neutral gray.`), fields: z.array(StrictField).describe('Fields to create on the object'), sharingModel: z.enum(['private', 'public_read', 'public_read_write', 'controlled_by_parent']).nullable() .describe('Org-Wide Default record visibility (OWD) for INTERNAL users (ADR-0090), or null to accept the platform default (business object → public_read_write; master-detail child → controlled_by_parent). SET it when the user\'s description implies a visibility intent: personal/private data (HR, 绩效, salary, 个人隐私) → "private" (owner-only); "public_read" = everyone reads, owner writes; "public_read_write" = everyone reads+writes; "controlled_by_parent" ONLY for an object with a master_detail reference field. Null on privacy-sensitive data silently over-shares it.'), diff --git a/packages/spec/src/data/index.ts b/packages/spec/src/data/index.ts index a7fcb478b9c..26ced7c8132 100644 --- a/packages/spec/src/data/index.ts +++ b/packages/spec/src/data/index.ts @@ -214,6 +214,9 @@ export * from './default-value-tokens'; // check both `defaultValue` authoring gates run (FieldSchema + ActionParam). export * from './default-value-shape'; export * from './object.zod'; +// [#35985] The object colour palette, named once so a renderer draws exactly +// the names the spec accepts. The `icon` / `color` leaves stay unexported. +export { OBJECT_COLORS, type ObjectColor } from './object-icon'; // API-method derivation — the single source of truth turning an object's // `enable.apiMethods` whitelist into its effective operation set (#3391). export * from './api-derivation'; diff --git a/packages/spec/src/data/object-color.test.ts b/packages/spec/src/data/object-color.test.ts new file mode 100644 index 00000000000..9166eac8fd8 --- /dev/null +++ b/packages/spec/src/data/object-color.test.ts @@ -0,0 +1,35 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { describe, it, expect } from 'vitest'; +import { ObjectSchema } from './object.zod'; +import { OBJECT_COLORS } from './index'; + +/** + * [#35985] `ObjectSchema.color` — one name from a closed palette of nine; the + * console draws the object's icon as a white glyph on a square of it. + */ +describe('ObjectSchema.color', () => { + const base = { name: 'account', fields: { name: { label: 'Name', type: 'text' } } }; + + it('is the nine-name palette, gray first (the neutral an object without a colour is drawn in)', () => { + expect(OBJECT_COLORS).toEqual(['gray', 'blue', 'teal', 'green', 'amber', 'orange', 'red', 'pink', 'purple']); + }); + + it('accepts every palette name, and absence', () => { + for (const color of OBJECT_COLORS) { + expect(ObjectSchema.safeParse({ ...base, color }).success).toBe(true); + } + const parsed = ObjectSchema.parse(base); + expect(parsed.color).toBeUndefined(); + }); + + it('refuses a free colour value, and the refusal names the palette', () => { + for (const color of ['#ff0000', 'rgb(255,0,0)', 'Blue', 'success', 'default', '']) { + const result = ObjectSchema.safeParse({ ...base, color }); + expect(result.success, color).toBe(false); + const issue = result.error!.issues.find((i) => i.path.join('.') === 'color'); + expect(issue, color).toBeDefined(); + for (const name of OBJECT_COLORS) expect(issue!.message).toContain(name); + } + }); +}); diff --git a/packages/spec/src/data/object-icon.ts b/packages/spec/src/data/object-icon.ts index d83153dee89..62c8382c3be 100644 --- a/packages/spec/src/data/object-icon.ts +++ b/packages/spec/src/data/object-icon.ts @@ -14,3 +14,30 @@ import { z } from 'zod'; * graph, and the leaf does not join the package's published exports. */ export const OBJECT_ICON_SCHEMA = z.string().optional().describe('Icon name (Lucide/Material) for UI representation'); + +/** + * The closed palette an object's `color` is picked from (#35985). Nine hue + * names, no free colour values: the console draws the object's icon as a white + * glyph on a rounded square of this colour, with a light-theme and a + * dark-theme value per name chosen so the white glyph stays legible on both. + * `gray` is the neutral every object without a `color` is drawn in. + * + * Status names (`success`, `danger`, …) are deliberately absent: an object's + * colour tells objects apart, it does not mean a state. + */ +export const OBJECT_COLORS = ['gray', 'blue', 'teal', 'green', 'amber', 'orange', 'red', 'pink', 'purple'] as const; + +/** One name from {@link OBJECT_COLORS}. */ +export type ObjectColor = (typeof OBJECT_COLORS)[number]; + +/** + * `ObjectSchema.color` — declared once, beside `icon`, for the same two shapes + * (#35985): the object and the AI blueprint object accept exactly the same + * palette names. + */ +export const OBJECT_COLOR_SCHEMA = z + .enum(OBJECT_COLORS) + .optional() + .describe( + `Object colour, one name from the fixed palette (${OBJECT_COLORS.join(', ')}). The console draws the object's icon as a white glyph on a rounded square of this colour, so one object looks the same wherever its icon appears. No free colour values. Omit to draw the neutral \`gray\`.`, + ); diff --git a/packages/spec/src/data/object.form.ts b/packages/spec/src/data/object.form.ts index f5269a110c4..1156d1bbeb1 100644 --- a/packages/spec/src/data/object.form.ts +++ b/packages/spec/src/data/object.form.ts @@ -38,6 +38,9 @@ export const objectForm = defineForm({ { field: 'label', type: 'text', colSpan: 1, helpText: 'Singular display name (e.g. "Account")' }, { field: 'pluralLabel', type: 'text', colSpan: 1, helpText: 'Plural display name (e.g. "Accounts")' }, { field: 'icon', type: 'text', colSpan: 1, helpText: 'Lucide icon name (e.g. "building", "users")' }, + // [#35985] The colour of the square the icon is drawn on: the swatch row + // (`color-picker`) reads its nine names off the closed enum. + { field: 'color', widget: 'color-picker', colSpan: 1, helpText: 'Color of the square the icon is drawn on, from the fixed palette. Unset draws gray.' }, { field: 'description', type: 'textarea', colSpan: 2, helpText: 'Developer documentation' }, // #19331 — `nameField` is declared by ObjectSchema and was offered by no // control, so the ADR-0079 record-title pointer could only be written diff --git a/packages/spec/src/data/object.zod.ts b/packages/spec/src/data/object.zod.ts index 05ac2fa70f4..746251f7ad4 100644 --- a/packages/spec/src/data/object.zod.ts +++ b/packages/spec/src/data/object.zod.ts @@ -31,7 +31,7 @@ import { FIELD_GROUP_KEY_PATTERN } from './field-group-layout'; // blueprint object (`ai/solution-blueprint.zod.ts`) runs this same refinement. import { refuseStageFieldWithoutKinds } from './stage-field-kinds'; // [#32763] The `icon` leaf, shared with the AI blueprint object. -import { OBJECT_ICON_SCHEMA } from './object-icon'; +import { OBJECT_COLOR_SCHEMA, OBJECT_ICON_SCHEMA } from './object-icon'; // The masked-on-read declaration (#20141); `warnGenericPasswordFields` reads its // `password` exemption rather than restating it. No runtime cycle: that module's // only imports are type-only. @@ -3931,6 +3931,8 @@ const ObjectSchemaBase = strictObject( pluralLabel: z.string().optional().describe('Human readable plural label (e.g. "Accounts")'), description: z.string().optional().describe('Developer documentation / description'), icon: OBJECT_ICON_SCHEMA, + // [#35985] The colour of the square the icon is drawn on, from a closed palette. + color: OBJECT_COLOR_SCHEMA, /** * Taxonomy & Organization diff --git a/ui/packages/app-shell/src/hooks/useNavTargetIcon.ts b/ui/packages/app-shell/src/hooks/useNavTargetIcon.ts index 1233b46740d..63392df6e12 100644 --- a/ui/packages/app-shell/src/hooks/useNavTargetIcon.ts +++ b/ui/packages/app-shell/src/hooks/useNavTargetIcon.ts @@ -20,7 +20,7 @@ */ import { useMemo } from 'react'; -import type { NavIconTarget, NavTargetIconResolver } from '@object-ui/layout'; +import type { NavIconTarget, NavTargetColorResolver, NavTargetIconResolver } from '@object-ui/layout'; import { useMetadata } from '../providers/MetadataProvider.js'; import { readObjectsByName } from './useObjectPresence.js'; @@ -38,3 +38,24 @@ export function useNavTargetIcon(): NavTargetIconResolver { [metadata], ); } + +/** + * useNavTargetColor — the same read for the object's palette `color` + * (objectstack#35985), as a {@link NavTargetColorResolver}: the colour of the + * tile an `object` entry is drawn on. An object with no `color`, or one not + * loaded yet, answers `undefined` and the tile is the neutral gray. + */ +export function useNavTargetColor(): NavTargetColorResolver { + const metadata = useMetadata(); + return useMemo( + () => (target: NavIconTarget) => { + if (target.kind !== 'object') return undefined; + const def = readObjectsByName(metadata, [target.objectName]).find( + (item): item is { name: string; color?: unknown } => + !!item && typeof item === 'object' && (item as { name?: unknown }).name === target.objectName, + ); + return typeof def?.color === 'string' && def.color !== '' ? def.color : undefined; + }, + [metadata], + ); +} diff --git a/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx b/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx index 67829b8674f..d5b3ff716d7 100644 --- a/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx +++ b/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx @@ -51,7 +51,7 @@ import { useFavorites } from '../hooks/useFavorites.js'; import { useNavPins } from '../hooks/useNavPins.js'; import { useNavActionDispatch } from '../hooks/useNavActionDispatch.js'; import { useNavTargetLabel } from '../hooks/useNavTargetLabel.js'; -import { useNavTargetIcon } from '../hooks/useNavTargetIcon.js'; +import { useNavTargetColor, useNavTargetIcon } from '../hooks/useNavTargetIcon.js'; import { useNavDocTargetCheck } from '../hooks/useNavDocTargetCheck.js'; import { useNavMemberGates } from '../hooks/useNavMemberGates.js'; import { matchAppBySegment } from '../utils/index.js'; @@ -188,6 +188,7 @@ export function UnifiedSidebar({ activeAppName, railOverlay = false }: UnifiedSi // hook, so the two surfaces cannot name one entry two ways. const resolveNavTargetLabel = useNavTargetLabel({ byName: true }); const resolveNavTargetIcon = useNavTargetIcon(); + const resolveNavTargetColor = useNavTargetColor(); // Collapsed, the console's sidebar is hidden and its menu floats over the // content (objectstack#35062); below the fold width it collapses on its own // (objectstack#27593), and `useResponsiveSidebar` folds and unfolds it. @@ -663,6 +664,7 @@ export function UnifiedSidebar({ activeAppName, railOverlay = false }: UnifiedSi onPinnedReorder={reorderPins} resolveTargetLabel={resolveNavTargetLabel} resolveTargetIcon={resolveNavTargetIcon} + resolveTargetColor={resolveNavTargetColor} locale={language} onAction={dispatchNavAction} t={t} diff --git a/ui/packages/app-shell/src/views/metadata-admin/color-variant-field.tsx b/ui/packages/app-shell/src/views/metadata-admin/color-variant-field.tsx index 72518440a3f..8265079f5e6 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/color-variant-field.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/color-variant-field.tsx @@ -31,7 +31,18 @@ export const COLOR_VARIANTS: ColorVariant[] = [ { value: 'amber', label: 'Amber', css: '#f59e0b' }, ]; -const CSS_BY_VALUE: Record = Object.fromEntries(COLOR_VARIANTS.map((c) => [c.value, c.css])); +/** + * objectstack#35985 — the two names of the OBJECT palette (`ObjectSchema.color`) + * that no entry above paints, so the object form's `color` row draws each of + * its nine swatches in its own hue. Kept out of {@link COLOR_VARIANTS}: they + * are not colour-variant tokens, nor aliases of one. + */ +const OBJECT_PALETTE_EXTRA_CSS: Record = { gray: '#6b7280', pink: '#db2777' }; + +const CSS_BY_VALUE: Record = { + ...OBJECT_PALETTE_EXTRA_CSS, + ...Object.fromEntries(COLOR_VARIANTS.map((c) => [c.value, c.css])), +}; /** Resolve a token (or hex) to a CSS color; unknown tokens fall back to neutral. */ export function colorVariantCss(value: string | undefined): string { diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconColor-35985.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconColor-35985.test.tsx new file mode 100644 index 00000000000..aafe128c162 --- /dev/null +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconColor-35985.test.tsx @@ -0,0 +1,87 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#35985 — Object Settings › Basics picks the icon and the colour + * together. The icon picker shows the nine palette swatches, and the trigger + * and every icon in the grid are drawn as the tile they become, in the chosen + * colour; picking a swatch patches `color`, and the grid follows it. + * + * Control: the same picker anywhere without a colour host (a page, an app, a + * navigation entry) shows no swatches and line icons, since only objects carry + * a colour. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, screen, fireEvent, cleanup, within } from '@testing-library/react'; +import { OBJECT_COLORS } from '@objectstack/spec/data'; +import { ObjectDefaultInspector } from './ObjectDefaultInspector'; +import { IconPickerWidget } from '../widgets'; +import { t } from '../i18n'; + +afterEach(cleanup); + +const LABEL = t('designer.object.iconAndColor', 'en-US'); + +function mount(draft: Record) { + const onPatch = vi.fn(); + const view = render( + , + ); + return { onPatch, view }; +} + +function open(): HTMLElement { + fireEvent.click(screen.getByRole('combobox', { name: LABEL })); + return screen.getByRole('dialog'); +} + +describe('objectstack#35985 — the object icon picker carries the colour palette', () => { + it('shows the trigger as the object’s tile in its colour, gray when it has none', () => { + const { view } = mount({ icon: 'building', color: 'orange' }); + const trigger = screen.getByRole('combobox', { name: LABEL }); + expect(trigger.querySelector('[data-object-icon-tile]')).toHaveAttribute('data-object-icon-tile', 'orange'); + view.unmount(); + mount({ icon: 'building' }); + expect(screen.getByRole('combobox', { name: LABEL }).querySelector('[data-object-icon-tile]')) + .toHaveAttribute('data-object-icon-tile', 'gray'); + }); + + it('offers the nine palette swatches as one named radio group, the stored colour checked', () => { + mount({ icon: 'building', color: 'teal' }); + const dialog = open(); + const group = within(dialog).getByRole('radiogroup', { name: t('engine.form.iconColor', 'en-US') }); + const radios = within(group).getAllByRole('radio'); + expect(radios.map((r) => r.getAttribute('data-color'))).toEqual([...OBJECT_COLORS]); + expect(within(group).getByRole('radio', { name: t('engine.form.objectColor.teal', 'en-US') })) + .toHaveAttribute('aria-checked', 'true'); + }); + + it('draws every icon in the grid as a tile of the chosen colour; picking a swatch patches color', () => { + const { onPatch } = mount({ icon: 'building', color: 'teal' }); + const dialog = open(); + const tiles = within(dialog).getByRole('listbox').querySelectorAll('[data-object-icon-tile]'); + expect(tiles.length).toBeGreaterThan(0); + for (const tile of Array.from(tiles)) expect(tile).toHaveAttribute('data-object-icon-tile', 'teal'); + + fireEvent.click(within(dialog).getByRole('radio', { name: t('engine.form.objectColor.purple', 'en-US') })); + expect(onPatch).toHaveBeenCalledWith({ color: 'purple' }); + }); + + it('control: the picker with no colour host shows no swatches and line icons', () => { + render(); + fireEvent.click(screen.getByRole('combobox')); + const dialog = screen.getByRole('dialog'); + expect(within(dialog).queryByRole('radiogroup')).toBeNull(); + expect(dialog.querySelector('[data-object-icon-tile]')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconPicker-12531.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconPicker-12531.test.tsx index 2a95733e74f..ce5181fce34 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconPicker-12531.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconPicker-12531.test.tsx @@ -25,7 +25,9 @@ import { t } from '../i18n'; afterEach(cleanup); -const ICON_LABEL = t('designer.object.icon', 'en-US'); +// objectstack#35985: the row picks the icon and the colour together, and is +// labelled for both. +const ICON_LABEL = t('designer.object.iconAndColor', 'en-US'); function mount(draft: Record, readOnly = false) { const onPatch = vi.fn(); diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.test.tsx index 2ed68f1b143..3e6c93d3972 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.test.tsx @@ -77,7 +77,7 @@ describe('ObjectDefaultInspector — basics', () => { fireEvent.change(labelledInput('Plural label'), { target: { value: 'Accounts' } }); expect(onPatch).toHaveBeenCalledWith({ pluralLabel: 'Accounts' }); // The Icon field is the icon picker (objectui#12531): pick, don't type. - fireEvent.click(screen.getByRole('combobox', { name: 'Icon' })); + fireEvent.click(screen.getByRole('combobox', { name: 'Icon and color' })); fireEvent.change(screen.getByLabelText('Search icons…'), { target: { value: 'building' } }); fireEvent.click(screen.getAllByRole('option').find((o) => o.getAttribute('title') === 'building')!); expect(onPatch).toHaveBeenCalledWith({ icon: 'building' }); @@ -182,7 +182,7 @@ describe('ObjectDefaultInspector — read-only', () => { ); expect(labelledInput('Label')).toBeDisabled(); expect(labelledInput('Plural label')).toBeDisabled(); - expect(screen.getByRole('combobox', { name: 'Icon' })).toBeDisabled(); + expect(screen.getByRole('combobox', { name: 'Icon and color' })).toBeDisabled(); }); }); diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.tsx index bea8d8943fc..6d9449f61b6 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.tsx @@ -132,16 +132,23 @@ export function ObjectDefaultInspector({ ships (preview, search, an inline warning on a name that matches no icon) rather than typed blind. Clearing it patches `icon: undefined`, as the text field this replaced did. */} + {/* objectstack#35985 — the icon and the colour are picked together: + the picker shows the nine palette swatches and previews every icon + as the tile it becomes. A colour is written only when picked; an + object without one is drawn in the neutral gray. */}
- + onPatch({ icon: typeof v === 'string' && v !== '' ? v : undefined })} + tileColor={str('color') || undefined} + onTileColorChange={(c) => onPatch({ color: c })} readOnly={readOnly} /> {issueLines('icon', tr('designer.object.icon'))} + {issueLines('color', tr('engine.form.iconColor'))}
diff --git a/ui/packages/app-shell/src/views/metadata-admin/widgets.tsx b/ui/packages/app-shell/src/views/metadata-admin/widgets.tsx index ddec5d78757..5754160da58 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/widgets.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/widgets.tsx @@ -40,7 +40,12 @@ import { DialogContent, DialogHeader, DialogTitle, + ObjectIconTile, + OBJECT_COLOR_TILE_CLASS, + objectColorOrDefault, + cn, } from '@object-ui/components'; +import { OBJECT_COLORS, type ObjectColor } from '@objectstack/spec/data'; import type { RegistryComponentMeta } from '@object-ui/core'; import { builderRulesOfSpecFilter } from '@object-ui/core'; import { AlertTriangle, ChevronDown, ChevronsUpDown, ChevronUp, Eye, EyeOff, Plus, Search, Trash2 } from 'lucide-react'; @@ -2226,7 +2231,21 @@ const ICON_RESULT_LIMIT = 120; * Built inline (no Radix portal) so the search + grid render eagerly — the same * jsdom-friendly choice the other pickers' tests rely on. */ -export function IconPickerWidget({ id, ariaLabelledBy, required, value, onChange, readOnly }: WidgetProps) { +/** + * The object-colour half of the picker (objectstack#35985). A host that edits + * an OBJECT's icon passes both: the dialog then shows the nine palette + * swatches, and the trigger and every grid cell draw the icon as the tile it + * will be, in the chosen colour. Without them (a page, app or navigation icon) + * the picker stays the line-icon picker it was: only objects carry a colour. + */ +export interface IconPickerTileColor { + tileColor?: string; + onTileColorChange?: (color: ObjectColor) => void; +} + +export function IconPickerWidget({ id, ariaLabelledBy, required, value, onChange, readOnly, tileColor, onTileColorChange }: WidgetProps & IconPickerTileColor) { + const tiles = typeof onTileColorChange === 'function'; + const color = objectColorOrDefault(tileColor); const locale = useMetadataLocale(); const current = value == null ? '' : String(value); const [open, setOpen] = React.useState(false); @@ -2263,7 +2282,11 @@ export function IconPickerWidget({ id, ariaLabelledBy, required, value, onChange onClick={() => !readOnly && setOpen(true)} className="flex w-full items-center gap-2 rounded-md border border-input bg-background px-3 py-2 text-sm text-left disabled:cursor-not-allowed disabled:opacity-60" > - + {tiles ? ( + + ) : ( + + )} {current || t('engine.form.selectEllipsis', locale)} @@ -2286,7 +2309,8 @@ export function IconPickerWidget({ id, ariaLabelledBy, required, value, onChange {t('engine.form.chooseIcon', locale)} -
+
+
+ {tiles && ( +
+ {OBJECT_COLORS.map((c) => { + const label = t(`engine.form.objectColor.${c}`, locale); + const checked = c === color; + return ( +
+ )} +
- + {tiles ? : } {name} ); diff --git a/ui/packages/app-shell/src/views/nav-menu-renderer.tsx b/ui/packages/app-shell/src/views/nav-menu-renderer.tsx index c5fcdf1a3d7..cfc74b6795b 100644 --- a/ui/packages/app-shell/src/views/nav-menu-renderer.tsx +++ b/ui/packages/app-shell/src/views/nav-menu-renderer.tsx @@ -122,7 +122,7 @@ import { useMetadata } from '@object-ui/react'; import { useAuth } from '@object-ui/auth'; import { usePermissions } from '@object-ui/permissions'; import { useObjectTranslation } from '@object-ui/i18n'; -import { Badge, Separator, cn } from '@object-ui/components'; +import { Badge, ObjectIconTile, Separator, cn } from '@object-ui/components'; import { hasVisibleNavigationItems, resolveActiveNavItem, @@ -135,7 +135,7 @@ import type { NavigationItem } from '@object-ui/types'; import { useNavVisibility } from '../hooks/useNavMemberGates.js'; import { useNavActionDispatch } from '../hooks/useNavActionDispatch.js'; import { useNavTargetLabel } from '../hooks/useNavTargetLabel.js'; -import { useNavTargetIcon } from '../hooks/useNavTargetIcon.js'; +import { useNavTargetColor, useNavTargetIcon } from '../hooks/useNavTargetIcon.js'; import { useNavDocTargetCheck } from '../hooks/useNavDocTargetCheck.js'; import { withoutUnreadableObjectEntries } from '../utils/navObjectReadGate.js'; import { useNavigationContext } from '../context/NavigationContext.js'; @@ -186,6 +186,7 @@ export const NavMenuRenderer: React.FC = ({ // And the same icon resolver: an `object` entry with no `icon` draws its // object's icon on both surfaces. const targetIcon = useNavTargetIcon(); + const targetColor = useNavTargetColor(); /* ── The three guards, wired to the same providers `UnifiedSidebar` uses ── */ @@ -369,7 +370,8 @@ export const NavMenuRenderer: React.FC = ({ ); } - const Icon = getIcon(resolveNavItemIcon(item, targetIcon)); + const iconName = resolveNavItemIcon(item, targetIcon); + const Icon = getIcon(iconName); const text = label(item); const badge = item.badge !== undefined && item.badge !== null && item.badge !== '' ? ( @@ -379,7 +381,13 @@ export const NavMenuRenderer: React.FC = ({ ) : null; const body = ( <> - + {/* objectstack#35985 — an object entry draws its object's tile, the + same one the sidebar draws; other entries keep the line icon. */} + {item.type === 'object' && item.objectName ? ( + + ) : ( + + )} {text} {badge} diff --git a/ui/packages/components/src/__tests__/object-icon-tile-35985.test.tsx b/ui/packages/components/src/__tests__/object-icon-tile-35985.test.tsx new file mode 100644 index 00000000000..debbbc258e1 --- /dev/null +++ b/ui/packages/components/src/__tests__/object-icon-tile-35985.test.tsx @@ -0,0 +1,92 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#35985 — an object's icon is a white glyph on a rounded square of + * the object's palette colour. These pins hold the tile to the spec's palette + * (every name has a colour, nothing else does), the neutral fallback, and the + * white-glyph contrast each light and dark value was chosen for. + */ + +import { describe, it, expect } from 'vitest'; +import React from 'react'; +import { render } from '@testing-library/react'; +import { OBJECT_COLORS } from '@objectstack/spec/data'; +import { ObjectIconTile, OBJECT_COLOR_TILE_CLASS, objectColorOrDefault } from '../custom/object-icon-tile'; + +/** Tailwind v4's default palette, in the sRGB hex its docs publish, for the shades the tile uses. */ +const HEX: Record = { + 'gray-500': '#6b7280', + 'blue-500': '#3b82f6', 'blue-600': '#2563eb', + 'teal-600': '#0d9488', + 'green-600': '#16a34a', + 'amber-600': '#d97706', + 'orange-600': '#ea580c', + 'red-500': '#ef4444', 'red-600': '#dc2626', + 'pink-500': '#ec4899', 'pink-600': '#db2777', + 'purple-500': '#a855f7', 'purple-600': '#9333ea', +}; + +function luminance(hex: string): number { + const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255) + .map((v) => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4)); + return 0.2126 * r + 0.7152 * g + 0.0722 * b; +} +const contrastWithWhite = (hex: string) => 1.05 / (luminance(hex) + 0.05); + +describe('objectstack#35985 — ObjectIconTile', () => { + it('has exactly one light and one dark background per palette name', () => { + expect(Object.keys(OBJECT_COLOR_TILE_CLASS).sort()).toEqual([...OBJECT_COLORS].sort()); + for (const name of OBJECT_COLORS) { + const classes = OBJECT_COLOR_TILE_CLASS[name].split(' '); + expect(classes.filter((c) => /^bg-/.test(c)), name).toHaveLength(1); + expect(classes.filter((c) => /^dark:bg-/.test(c)), name).toHaveLength(1); + } + }); + + it('keeps the white glyph at 3:1 or better (WCAG 1.4.11) in both themes', () => { + for (const name of OBJECT_COLORS) { + for (const cls of OBJECT_COLOR_TILE_CLASS[name].split(' ')) { + const shade = cls.replace(/^(dark:)?bg-/, ''); + expect(HEX[shade], `${name} ${cls}`).toBeDefined(); + expect(contrastWithWhite(HEX[shade]), `${name} ${cls}`).toBeGreaterThanOrEqual(3); + } + } + }); + + it('draws a palette name in its colour, and anything else (none, a hex, an unknown name) in gray', () => { + expect(objectColorOrDefault('orange')).toBe('orange'); + for (const v of [undefined, '', '#ff0000', 'success', 'Orange', 7]) expect(objectColorOrDefault(v)).toBe('gray'); + + const { container, rerender } = render(); + const tile = container.querySelector('[data-object-icon-tile]')!; + expect(tile.getAttribute('data-object-icon-tile')).toBe('orange'); + expect(tile.className).toContain('bg-orange-600'); + expect(tile.className).toContain('text-white'); + expect(tile.querySelector('svg')).not.toBeNull(); + + rerender(); + expect(container.querySelector('[data-object-icon-tile]')!.getAttribute('data-object-icon-tile')).toBe('gray'); + }); + + it('draws a host-resolved glyph when one is passed, and LazyIcon\'s otherwise', () => { + const Glyph = (props: { className?: string }) => ; + const { getByTestId, container, rerender } = render(); + expect(getByTestId('host-glyph').getAttribute('class')).toContain('h-3'); + rerender(); + expect(container.querySelector('svg')?.getAttribute('class')).toContain('lucide-database'); + }); + + it('is hidden from assistive tech beside a label, and named when it stands alone', () => { + const { container, rerender } = render(); + expect(container.firstElementChild!.getAttribute('aria-hidden')).toBe('true'); + rerender(); + expect(container.firstElementChild!.getAttribute('role')).toBe('img'); + expect(container.firstElementChild!.getAttribute('aria-label')).toBe('Accounts'); + }); +}); diff --git a/ui/packages/components/src/custom/index.ts b/ui/packages/components/src/custom/index.ts index e4046bbac7f..9845fb19ce4 100644 --- a/ui/packages/components/src/custom/index.ts +++ b/ui/packages/components/src/custom/index.ts @@ -40,6 +40,13 @@ export * from './fullscreen-editor'; export * from './input-group'; export * from './item'; export { Kbd } from './kbd'; +export { + ObjectIconTile, + OBJECT_COLOR_TILE_CLASS, + objectColorOrDefault, + type ObjectIconTileProps, + type ObjectIconTileSize, +} from './object-icon-tile'; export { recordOverlayWidthStorageKey, legacyRecordDrawerWidthKey, diff --git a/ui/packages/components/src/custom/object-icon-tile.tsx b/ui/packages/components/src/custom/object-icon-tile.tsx new file mode 100644 index 00000000000..1179505a603 --- /dev/null +++ b/ui/packages/components/src/custom/object-icon-tile.tsx @@ -0,0 +1,107 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * ObjectIconTile — an object's icon as a white glyph on a rounded square of the + * object's palette colour (objectstack#35985). Every place that draws an + * object's icon draws this, so one object looks the same in the menu, its list + * and record headers and the chips that point at it. + * + * The colour is a NAME from the spec's closed palette (`OBJECT_COLORS`, + * `ObjectSchema.color`), never a CSS value. Each name maps to a fixed pair of + * Tailwind utilities, one per theme, chosen so the white glyph keeps at least + * the 3:1 non-text contrast WCAG 1.4.11 asks for on both. Static class strings, + * not an inline colour: the palette is the component's, and `ui/AGENTS.md` + * (Styling) allows an inline colour only for a value the author typed. + * + * No colour, or a name the palette does not hold (metadata written by an older + * or a newer spec), draws the neutral `gray`. + */ + +import * as React from 'react'; +import { OBJECT_COLORS, type ObjectColor } from '@objectstack/spec/data'; +import { LazyIcon } from '../lib/lazy-icon'; +import { cn } from '../lib/utils'; + +/** + * The square's background per palette name, light theme then `.dark`. + * White-glyph contrast (light / dark): gray 4.83 / 4.83, blue 5.17 / 3.68, + * teal 3.74 / 3.74, green 3.30 / 3.30, amber 3.19 / 3.19, orange 3.56 / 3.56, + * red 4.83 / 3.76, pink 4.60 / 3.53, purple 5.38 / 3.96. The names that keep + * 3:1 one shade lighter take it in the dark theme, so they do not sink into a + * dark page; the rest keep their light value. Pinned by + * `__tests__/object-icon-tile-35985.test.tsx`. + */ +export const OBJECT_COLOR_TILE_CLASS: Readonly> = { + gray: 'bg-gray-500 dark:bg-gray-500', + blue: 'bg-blue-600 dark:bg-blue-500', + teal: 'bg-teal-600 dark:bg-teal-600', + green: 'bg-green-600 dark:bg-green-600', + amber: 'bg-amber-600 dark:bg-amber-600', + orange: 'bg-orange-600 dark:bg-orange-600', + red: 'bg-red-600 dark:bg-red-500', + pink: 'bg-pink-600 dark:bg-pink-500', + purple: 'bg-purple-600 dark:bg-purple-500', +}; + +const PALETTE: ReadonlySet = new Set(OBJECT_COLORS); + +/** A stored colour narrowed to a palette name; anything else is `gray`. */ +export function objectColorOrDefault(color: unknown): ObjectColor { + return typeof color === 'string' && PALETTE.has(color) ? (color as ObjectColor) : 'gray'; +} + +/** + * Square edge, glyph edge and corner per size. The corners are pixel values, + * not the theme's `rounded-*` steps: those follow `--radius`, which a theme + * may set large enough to turn the square into a circle. + */ +/** The four tile sizes: 16, 20, 24 and 32px squares. */ +export type ObjectIconTileSize = 'xs' | 'sm' | 'md' | 'lg'; + +const SIZE_CLASS: Readonly> = { + xs: { tile: 'h-4 w-4 rounded-[4px]', glyph: 'h-2.5 w-2.5' }, + sm: { tile: 'h-5 w-5 rounded-[5px]', glyph: 'h-3 w-3' }, + md: { tile: 'h-6 w-6 rounded-[6px]', glyph: 'h-3.5 w-3.5' }, + lg: { tile: 'h-8 w-8 rounded-[8px]', glyph: 'h-5 w-5' }, +}; + +export interface ObjectIconTileProps { + /** Lucide icon name (kebab or Pascal case); none or unknown draws the generic glyph. */ + icon?: string; + /** Palette name (`ObjectSchema.color`); none or unknown draws `gray`. */ + color?: string; + /** Default `sm` (20px), the size a navigation row's 16px line icon is replaced with. */ + size?: ObjectIconTileSize; + className?: string; + /** Accessible name; omit when the object's label sits beside the tile (the tile is then hidden from assistive tech). */ + title?: string; + /** + * The glyph component, when the host already resolved `icon` through its own + * resolver (the navigation's `resolveIcon`, whose generic glyph differs from + * `LazyIcon`'s): the tile then draws exactly the glyph the line icon drew. + * Omitted, the tile resolves `icon` with `LazyIcon`. + */ + glyph?: React.ElementType; +} + +export function ObjectIconTile({ icon, color, size = 'sm', className, title, glyph: Glyph }: ObjectIconTileProps) { + const name = objectColorOrDefault(color); + const s = SIZE_CLASS[size] ?? SIZE_CLASS.sm; + return ( + + {Glyph ? : } + + ); +} diff --git a/ui/packages/i18n/src/namespaces/studio/en.ts b/ui/packages/i18n/src/namespaces/studio/en.ts index e46153a3ab1..13b01082e27 100644 --- a/ui/packages/i18n/src/namespaces/studio/en.ts +++ b/ui/packages/i18n/src/namespaces/studio/en.ts @@ -548,6 +548,7 @@ const STUDIO_EN: Record = { 'designer.object.pluralLabel': 'Plural label', 'designer.object.pluralPlaceholder': 'e.g. Accounts', 'designer.object.icon': 'Icon', + 'designer.object.iconAndColor': 'Icon and color', 'designer.object.description': 'Description', 'designer.object.descriptionPlaceholder': 'What this object represents', // Access controls (ADR-0066 D2/D3/④/⑤) @@ -1796,6 +1797,17 @@ const STUDIO_EN: Record = { 'engine.form.flaggedValue': '{value} {flag}', 'engine.form.searchIcons': 'Search icons…', 'engine.form.chooseIcon': 'Choose an icon', + // objectstack#35985: the object colour palette in the icon picker. + 'engine.form.iconColor': 'Icon color', + 'engine.form.objectColor.gray': 'Gray', + 'engine.form.objectColor.blue': 'Blue', + 'engine.form.objectColor.teal': 'Teal', + 'engine.form.objectColor.green': 'Green', + 'engine.form.objectColor.amber': 'Amber', + 'engine.form.objectColor.orange': 'Orange', + 'engine.form.objectColor.red': 'Red', + 'engine.form.objectColor.pink': 'Pink', + 'engine.form.objectColor.purple': 'Purple', 'engine.form.iconsTruncated': 'Showing the first {shown} of {total} — type to narrow.', 'engine.form.noMatchingIcons': 'No matching icons.', // objectui#12531 — the icon picker's inline warning on a stored name that diff --git a/ui/packages/i18n/src/namespaces/studio/zh.ts b/ui/packages/i18n/src/namespaces/studio/zh.ts index 4077ef6e3fb..4f2f342a8a9 100644 --- a/ui/packages/i18n/src/namespaces/studio/zh.ts +++ b/ui/packages/i18n/src/namespaces/studio/zh.ts @@ -463,6 +463,7 @@ const STUDIO_ZH: Record = { 'designer.object.pluralLabel': '复数显示名', 'designer.object.pluralPlaceholder': '如:客户列表', 'designer.object.icon': '图标', + 'designer.object.iconAndColor': '图标和颜色', 'designer.object.description': '描述', 'designer.object.descriptionPlaceholder': '该对象代表什么', // Access controls (ADR-0066 D2/D3/④/⑤) @@ -1594,6 +1595,17 @@ const STUDIO_ZH: Record = { 'engine.form.flaggedValue': '{value}{flag}', 'engine.form.searchIcons': '搜索图标…', 'engine.form.chooseIcon': '选择图标', + // objectstack#35985: the object colour palette in the icon picker. + 'engine.form.iconColor': '图标颜色', + 'engine.form.objectColor.gray': '灰色', + 'engine.form.objectColor.blue': '蓝色', + 'engine.form.objectColor.teal': '青色', + 'engine.form.objectColor.green': '绿色', + 'engine.form.objectColor.amber': '琥珀色', + 'engine.form.objectColor.orange': '橙色', + 'engine.form.objectColor.red': '红色', + 'engine.form.objectColor.pink': '粉色', + 'engine.form.objectColor.purple': '紫色', 'engine.form.iconsTruncated': '显示前 {shown} 个,共 {total} 个 —— 继续输入以缩小范围。', 'engine.form.noMatchingIcons': '没有匹配的图标。', 'engine.form.unknownIcon': '没有名为“{name}”的图标。请从列表中选择一个。', diff --git a/ui/packages/layout/src/NavigationRenderer.tsx b/ui/packages/layout/src/NavigationRenderer.tsx index 39e8a0c40f1..b8443c99b80 100644 --- a/ui/packages/layout/src/NavigationRenderer.tsx +++ b/ui/packages/layout/src/NavigationRenderer.tsx @@ -35,7 +35,7 @@ import { PinOff, Star, } from 'lucide-react'; -import { getLazyIcon } from '@object-ui/components'; +import { getLazyIcon, ObjectIconTile } from '@object-ui/components'; import { DndContext, closestCenter, @@ -253,6 +253,16 @@ export type NavIconTarget = { kind: 'object'; objectName: string }; */ export type NavTargetIconResolver = (target: NavIconTarget) => string | undefined; +/** + * Answers the palette colour the target declares in the host's metadata (the + * object schema's `color`, objectstack#35985), or `undefined` when it declares + * none or is not loaded. Asked on every render, like + * {@link NavTargetIconResolver}. An `object` entry is always drawn as an + * {@link ObjectIconTile}; without this resolver, or without a colour, the tile + * is the neutral gray. + */ +export type NavTargetColorResolver = (target: NavIconTarget) => string | undefined; + /** * The icon name a navigation entry draws: its own `icon` when it names one, * else, for an `object` entry, the icon its object declares @@ -443,6 +453,15 @@ export interface NavigationRendererProps { */ resolveTargetIcon?: NavTargetIconResolver; + /** + * Resolver for the colour of the tile an `object` entry is drawn on: the + * palette colour its object declares (objectstack#35985). The entry's own + * `icon`, when it names one, is still the glyph; the colour is always the + * object's, so one object looks the same in every menu. See + * {@link NavTargetColorResolver}. + */ + resolveTargetColor?: NavTargetColorResolver; + // RETIRED (`9c60144b5`): `resolveGroupLabel` / `resolveItemLabel`, the two // id-keyed label resolvers. They were unreachable by construction: they sat // behind a text comparison of the label against the node's own `id` @@ -1576,6 +1595,7 @@ interface NavRowProps { renderItemAction?: NavigationRendererProps['renderItemAction']; resolveTargetLabel?: NavTargetLabelResolver; resolveTargetIcon?: NavTargetIconResolver; + resolveTargetColor?: NavTargetColorResolver; locale?: string; t?: NavigationRendererProps['t']; templateContext?: NavTemplateContext; @@ -1748,6 +1768,7 @@ function NavigationItemRenderer({ inList = true, resolveTargetLabel, resolveTargetIcon, + resolveTargetColor, locale, t: tProp, templateContext, @@ -1775,6 +1796,7 @@ function NavigationItemRenderer({ inList?: boolean; resolveTargetLabel?: NavTargetLabelResolver; resolveTargetIcon?: NavTargetIconResolver; + resolveTargetColor?: NavTargetColorResolver; locale?: string; t?: (key: string, options?: any) => string; templateContext?: NavTemplateContext; @@ -1851,6 +1873,7 @@ function NavigationItemRenderer({ renderItemAction, resolveTargetLabel, resolveTargetIcon, + resolveTargetColor, locale, t: tProp, templateContext, @@ -1976,15 +1999,31 @@ function NavigationItemRenderer({ // --- Leaf items (every entry that navigates: object / dashboard / page / report / url / component / doc) --- // An `object` entry with no `icon` draws its object's icon, so each list in // the menu is told apart the way its own page header shows it. - const Icon = resolveIcon(resolveNavItemIcon(item, resolveTargetIcon)); + // objectstack#35985 — an `object` entry is drawn as its object's tile (a + // white glyph on the object's palette colour); every other entry keeps the + // line icon, since only objects carry a colour. + const iconName = resolveNavItemIcon(item, resolveTargetIcon); + const objectTarget: NavIconTarget | null = + item.type === 'object' && item.objectName ? { kind: 'object', objectName: item.objectName } : null; + const Icon = resolveIcon(iconName); const { href, external } = resolveHref(item, basePath, templateContext); const isActive = activeNavId !== null && item.id === activeNavId; const itemLabel = resolveNavItemLabel(item, tProp, resolveTargetLabel, locale); const content = ( <> - {/* eslint-disable-next-line react-hooks/static-components -- resolveIcon returns a stable icon component from a static registry, not a component created during render */} - + {objectTarget ? ( + + ) : ( + // eslint-disable-next-line react-hooks/static-components -- resolveIcon returns a stable icon component from a static registry, not a component created during render + + )} {itemLabel} {item.badge != null && ( @@ -2096,6 +2135,7 @@ export function NavigationRenderer({ onPinnedReorder, resolveTargetLabel, resolveTargetIcon, + resolveTargetColor, locale, t: tProp, templateContext, @@ -2155,6 +2195,7 @@ export function NavigationRenderer({ renderItemAction, resolveTargetLabel, resolveTargetIcon, + resolveTargetColor, locale, t: tProp, templateContext, diff --git a/ui/packages/layout/src/__tests__/AppSchemaRenderer.mobileTabOrder-11395.test.tsx b/ui/packages/layout/src/__tests__/AppSchemaRenderer.mobileTabOrder-11395.test.tsx index 6a933771050..322593afae4 100644 --- a/ui/packages/layout/src/__tests__/AppSchemaRenderer.mobileTabOrder-11395.test.tsx +++ b/ui/packages/layout/src/__tests__/AppSchemaRenderer.mobileTabOrder-11395.test.tsx @@ -84,6 +84,10 @@ const entry = (label: string, order?: number, extra: Partial = { ...extra, }) as NavigationItem; +// objectstack#35985: an object row's first span is its icon tile, which +// carries no text; the row's label is the first span that is not a tile. +const LABEL_SPAN = 'span:not([data-object-icon-tile])'; + function renderShell( navigation: NavigationItem[], props: Partial> = {}, @@ -106,9 +110,9 @@ function renderShell( return b ? Array.from(b.querySelectorAll('a, button')) : []; }; /** Every tab, link or button, in drawn order, by the label it shows. */ - const tabs = () => tabEls().map((el) => el.querySelector('span')?.textContent ?? ''); + const tabs = () => tabEls().map((el) => el.querySelector(LABEL_SPAN)?.textContent ?? ''); const tab = (label: string) => { - const hit = tabEls().filter((el) => el.querySelector('span')?.textContent === label); + const hit = tabEls().filter((el) => el.querySelector(LABEL_SPAN)?.textContent === label); expect(hit.length).toBeLessThanOrEqual(1); return hit[0] ?? null; }; @@ -116,11 +120,11 @@ function renderShell( const sidebarOrder = (labels: string[]) => Array.from(container.querySelectorAll('a, button')) .filter((el) => !bar()?.contains(el)) - .map((el) => el.querySelector('span')?.textContent ?? el.textContent ?? '') + .map((el) => el.querySelector(LABEL_SPAN)?.textContent ?? el.textContent ?? '') .filter((text) => labels.includes(text)); const sidebarRow = (label: string) => { const hit = Array.from(container.querySelectorAll('a, button')).filter( - (el) => !bar()?.contains(el) && el.querySelector('span')?.textContent === label, + (el) => !bar()?.contains(el) && el.querySelector(LABEL_SPAN)?.textContent === label, ); expect(hit.length).toBeLessThanOrEqual(1); return hit[0] ?? null; @@ -303,7 +307,7 @@ describe('objectui#11395 — the enumeration: inputs that are deliberately bar-s const navigation = [entry('Accounts'), entry('Deals', undefined, { pinned: true }), entry('Leads')]; const { tabs, container, bar } = renderShell(navigation, { enablePinning: true, onPinToggle: () => {} }); const sidebarDeals = Array.from(container.querySelectorAll('a')).filter( - (el) => !bar()?.contains(el) && el.querySelector('span')?.textContent === 'Deals', + (el) => !bar()?.contains(el) && el.querySelector(LABEL_SPAN)?.textContent === 'Deals', ); expect(sidebarDeals).toHaveLength(2); expect(tabs()).toEqual(['Accounts', 'Deals', 'Leads']); diff --git a/ui/packages/layout/src/__tests__/NavigationRenderer.objectTile-35985.test.tsx b/ui/packages/layout/src/__tests__/NavigationRenderer.objectTile-35985.test.tsx new file mode 100644 index 00000000000..be3f849f0ea --- /dev/null +++ b/ui/packages/layout/src/__tests__/NavigationRenderer.objectTile-35985.test.tsx @@ -0,0 +1,73 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#35985 — an `object` navigation entry is drawn as its object's + * tile: the glyph `resolveNavItemIcon` answers (the entry's own icon, else the + * object's), on the colour `resolveTargetColor` answers for the object. Other + * entries keep the line icon: only objects carry a colour. + */ + +import { describe, it, expect } from 'vitest'; +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import type { NavigationItem } from '@object-ui/types'; +import { SidebarProvider } from '@object-ui/components'; +import { NavigationRenderer, type NavTargetColorResolver } from '../NavigationRenderer'; + +const COLORS: Record = { account: 'orange', invoice: 'teal' }; +const colors: NavTargetColorResolver = (t) => COLORS[t.objectName]; + +function tileOf(label: string): Element | null { + return screen.getByText(label).closest('[data-sidebar="menu-button"]')!.querySelector('[data-object-icon-tile]'); +} + +function renderNav(items: NavigationItem[], props: Record = {}) { + return render( + + + + + , + ); +} + +describe('objectstack#35985 — object navigation entries are tiles', () => { + const items: NavigationItem[] = [ + { id: 'nav_accounts', type: 'object', objectName: 'account', label: 'Accounts' }, + { id: 'nav_key', type: 'object', objectName: 'account', label: 'Key accounts', icon: 'star' }, + { + id: 'grp_money', type: 'group', label: 'Money', + children: [{ id: 'nav_invoices', type: 'object', objectName: 'invoice', label: 'Invoices' }], + }, + { id: 'nav_notes', type: 'object', objectName: 'note', label: 'Notes' }, + { id: 'nav_dash', type: 'dashboard', dashboardName: 'sales', label: 'Overview' }, + ]; + + it('draws each object row in its object’s colour, inside a group too; an authored icon keeps the object’s colour', () => { + renderNav(items, { resolveTargetColor: colors }); + expect(tileOf('Accounts')?.getAttribute('data-object-icon-tile')).toBe('orange'); + expect(tileOf('Key accounts')?.getAttribute('data-object-icon-tile')).toBe('orange'); + expect(tileOf('Invoices')?.getAttribute('data-object-icon-tile')).toBe('teal'); + }); + + it('an object with no colour, and every object row with no resolver, is the neutral gray tile', () => { + const { unmount } = renderNav(items, { resolveTargetColor: colors }); + expect(tileOf('Notes')?.getAttribute('data-object-icon-tile')).toBe('gray'); + unmount(); + renderNav(items); + expect(tileOf('Accounts')?.getAttribute('data-object-icon-tile')).toBe('gray'); + }); + + it('control: a dashboard row keeps its line icon, no tile', () => { + renderNav(items, { resolveTargetColor: colors }); + expect(tileOf('Overview')).toBeNull(); + expect(screen.getByText('Overview').closest('[data-sidebar="menu-button"]')!.querySelector('svg')).not.toBeNull(); + }); +}); From 29fe282f8fc779a5516adfd06c91c0a7d37be946 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 06:48:41 +0000 Subject: [PATCH 2/6] test(app-shell): pay CEL authoring's dynamic loads at collection in the object inspector tests check:test-source-alias: the three ObjectDefaultInspector test files this change edits reach celAuthoring's dynamic @objectstack/formula and @objectstack/lint imports through the icon picker; a module-top side-effect import moves that first load out of a case's clock. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgT9PKAmy86XfbYbZtW --- .../ObjectDefaultInspector.iconColor-35985.test.tsx | 5 +++++ .../ObjectDefaultInspector.iconPicker-12531.test.tsx | 5 +++++ .../inspectors/ObjectDefaultInspector.test.tsx | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconColor-35985.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconColor-35985.test.tsx index aafe128c162..cb1aa026e79 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconColor-35985.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconColor-35985.test.tsx @@ -19,6 +19,11 @@ import { OBJECT_COLORS } from '@objectstack/spec/data'; import { ObjectDefaultInspector } from './ObjectDefaultInspector'; import { IconPickerWidget } from '../widgets'; import { t } from '../i18n'; +// The inspector reaches the console's dynamic `@objectstack/formula` and +// `@objectstack/lint` imports (CEL authoring); their first load is paid here, +// at collection, never inside a case's clock (`check:test-source-alias`). +import '@objectstack/formula'; +import '@objectstack/lint'; afterEach(cleanup); diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconPicker-12531.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconPicker-12531.test.tsx index ce5181fce34..268550bac69 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconPicker-12531.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.iconPicker-12531.test.tsx @@ -22,6 +22,11 @@ import { describe, it, expect, vi, afterEach } from 'vitest'; import { render, screen, fireEvent, cleanup, within } from '@testing-library/react'; import { ObjectDefaultInspector } from './ObjectDefaultInspector'; import { t } from '../i18n'; +// The inspector reaches the console's dynamic `@objectstack/formula` and +// `@objectstack/lint` imports (CEL authoring); their first load is paid here, +// at collection, never inside a case's clock (`check:test-source-alias`). +import '@objectstack/formula'; +import '@objectstack/lint'; afterEach(cleanup); diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.test.tsx index 3e6c93d3972..86610e49e49 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectDefaultInspector.test.tsx @@ -4,6 +4,11 @@ import * as React from 'react'; import { describe, it, expect, vi, afterEach } from 'vitest'; import { render, screen, fireEvent, cleanup, within } from '@testing-library/react'; import { ObjectDefaultInspector } from './ObjectDefaultInspector'; +// The inspector reaches the console's dynamic `@objectstack/formula` and +// `@objectstack/lint` imports (CEL authoring); their first load is paid here, +// at collection, never inside a case's clock (`check:test-source-alias`). +import '@objectstack/formula'; +import '@objectstack/lint'; // The designer's `designer.*` / `perm.*` rows live in `@object-ui/i18n`'s `studio` // namespace, whose `zh` catalogue is fetched on demand (objectstack#25922). // Resident before any case, so the zh rows below read synchronously. From a2cbd8819f31f5e23035e1234aee29d32a94b746 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 06:54:28 +0000 Subject: [PATCH 3/6] test(metadata-protocol): object serves 51 top-level properties now that it carries color Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgT9PKAmy86XfbYbZtW --- .../src/protocol.meta-types-degenerate-derivation.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts b/packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts index ae22019e18a..85a8a7ca810 100644 --- a/packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts +++ b/packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts @@ -397,9 +397,11 @@ describe('#17501 — /meta/types serves a real schema for `action`, and moves no // packaged-flow switch (a package ships the flow switched off). // [#35489] `field` 83 → 84: `unitConfig`, the unit a quantity is in or // that a text field holds a unit code (ADR-0158 U4, Open item 8). + // [#35985] `object` 50 → 51: `color`, the palette name the console draws + // the object's icon tile in. const CARD_PROPERTY_COUNTS: Record = { agent: 24, app: 24, dashboard: 21, dataset: 17, field: 84, flow: 24, - hook: 24, object: 50, page: 28, position: 14, report: 24, skill: 17, tool: 14, + hook: 24, object: 51, page: 28, position: 14, report: 24, skill: 17, tool: 14, }; it.each(Object.entries(CARD_PROPERTY_COUNTS))( From 834205699cf0979a6652aa3bc2de8137b8125c52 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 07:03:37 +0000 Subject: [PATCH 4/6] fix(metadata-core): classify the object color key in the FLS reference table A palette name names no field, so the FLS scrub keeps it as is. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgT9PKAmy86XfbYbZtW --- .changeset/35985-object-color-tile.md | 3 +++ packages/metadata-core/src/object-schema-fls-references.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.changeset/35985-object-color-tile.md b/.changeset/35985-object-color-tile.md index 27f9c08c27b..78f8e9a9fd3 100644 --- a/.changeset/35985-object-color-tile.md +++ b/.changeset/35985-object-color-tile.md @@ -4,6 +4,7 @@ '@object-ui/layout': minor '@object-ui/app-shell': minor '@object-ui/i18n': minor +'@objectstack/metadata-core': patch --- feat(spec, ui): an object takes a colour from a fixed palette, and its icon is drawn as a white glyph on a square of that colour @@ -17,3 +18,5 @@ Metadata-protocol: added - **Navigation draws objects as tiles.** In the sidebar, the app-home menu and the phone menu, every entry that opens an object is drawn as that object's tile: the entry's own `icon` when it names one, else the object's, on the object's colour. Dashboards, pages and links keep their line icons. `NavigationRenderer` takes a new `resolveTargetColor` resolver (`NavTargetColorResolver`) beside `resolveTargetIcon`; the console answers it from the object metadata it already holds (`useNavTargetColor`). - **The designer picks icon and colour together.** In the object's settings, the icon picker shows the nine colour swatches, and the trigger and every icon in the grid are previewed as the tile they become. The picker elsewhere (pages, apps, navigation entries) is unchanged: only objects carry a colour. - The other places that draw an object's icon (list and record headers, search, related-record chips, the designer's object lists) switch to the tile in a follow-up release. + +`@objectstack/metadata-core`: the field-level-security reference table classifies the new `color` key as `keep` (a palette name names no field). diff --git a/packages/metadata-core/src/object-schema-fls-references.ts b/packages/metadata-core/src/object-schema-fls-references.ts index 10699735dff..0d6b682ef32 100644 --- a/packages/metadata-core/src/object-schema-fls-references.ts +++ b/packages/metadata-core/src/object-schema-fls-references.ts @@ -766,7 +766,7 @@ const LIST_VIEW_NAME_LISTS: Readonly> = { */ export const OBJECT_REFERENCE_POSITIONS: Readonly> = { // Identity and posture — no field names. - name: keep, label: keep, pluralLabel: keep, description: keep, icon: keep, isSystem: keep, + name: keep, label: keep, pluralLabel: keep, description: keep, icon: keep, color: keep, isSystem: keep, managedBy: keep, ownership: keep, systemFields: keep, datasource: keep, access: keep, requiredPermissions: keep, fileAccessDelegate: keep, schemaReadDelegate: keep, editMode: keep, enable: keep, sharingModel: keep, externalSharingModel: keep, protection: keep, From 6fdcf3ee9892aa8e79863374b2ce0cb62d2d467a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 07:52:35 +0000 Subject: [PATCH 5/6] chore(changeset): name platform-objects' new form row, and what a host without a colour resolver sees The object-icon leaf header now says which of its names are exported. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgT9PKAmy86XfbYbZtW --- .changeset/35985-object-color-tile.md | 5 ++++- packages/spec/src/data/object-icon.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.changeset/35985-object-color-tile.md b/.changeset/35985-object-color-tile.md index 78f8e9a9fd3..541332c5c36 100644 --- a/.changeset/35985-object-color-tile.md +++ b/.changeset/35985-object-color-tile.md @@ -5,6 +5,7 @@ '@object-ui/app-shell': minor '@object-ui/i18n': minor '@objectstack/metadata-core': patch +'@objectstack/platform-objects': minor --- feat(spec, ui): an object takes a colour from a fixed palette, and its icon is drawn as a white glyph on a square of that colour @@ -15,8 +16,10 @@ Metadata-protocol: added - **`ObjectSchema.color` (new, optional).** One name from a closed palette of nine: `gray`, `blue`, `teal`, `green`, `amber`, `orange`, `red`, `pink`, `purple` (exported as `OBJECT_COLORS` and the `ObjectColor` type from `@objectstack/spec/data`). No free colour values: `color: '#ff0000'` is refused, and the refusal lists the nine names. An object without a `color` is drawn in the neutral `gray`. Nothing to migrate: every existing object stays valid and simply has no colour. - **The AI blueprint carries it too.** `BlueprintObjectSchema.color` is the same leaf (required-but-nullable on `SolutionBlueprintStrictSchema`, like `icon`), and its rule asks the model to colour every object and give each object of one solution a different colour while the palette lasts. - **`ObjectIconTile` (new, `@object-ui/components`).** Draws an icon name as a white glyph on a rounded square of a palette colour, in four sizes. Each name has a light-theme and a dark-theme value chosen so the white glyph keeps at least 3:1 contrast. `OBJECT_COLOR_TILE_CLASS` and `objectColorOrDefault` are exported with it. -- **Navigation draws objects as tiles.** In the sidebar, the app-home menu and the phone menu, every entry that opens an object is drawn as that object's tile: the entry's own `icon` when it names one, else the object's, on the object's colour. Dashboards, pages and links keep their line icons. `NavigationRenderer` takes a new `resolveTargetColor` resolver (`NavTargetColorResolver`) beside `resolveTargetIcon`; the console answers it from the object metadata it already holds (`useNavTargetColor`). +- **Navigation draws objects as tiles.** In the sidebar, the app-home menu and the phone menu, every entry that opens an object is drawn as that object's tile: the entry's own `icon` when it names one, else the object's, on the object's colour. Dashboards, pages and links keep their line icons. `NavigationRenderer` takes a new `resolveTargetColor` resolver (`NavTargetColorResolver`) beside `resolveTargetIcon`; the console answers it from the object metadata it already holds (`useNavTargetColor`). A host that passes no `resolveTargetColor` gets its object entries as gray tiles where it had line icons. - **The designer picks icon and colour together.** In the object's settings, the icon picker shows the nine colour swatches, and the trigger and every icon in the grid are previewed as the tile they become. The picker elsewhere (pages, apps, navigation entries) is unchanged: only objects carry a colour. - The other places that draw an object's icon (list and record headers, search, related-record chips, the designer's object lists) switch to the tile in a follow-up release. `@objectstack/metadata-core`: the field-level-security reference table classifies the new `color` key as `keep` (a palette name names no field). + +`@objectstack/platform-objects`: the generic object form's metadata-form packs ship the new `color` row's label and help text in all 10 locales. diff --git a/packages/spec/src/data/object-icon.ts b/packages/spec/src/data/object-icon.ts index 62c8382c3be..9e2dd6b119f 100644 --- a/packages/spec/src/data/object-icon.ts +++ b/packages/spec/src/data/object-icon.ts @@ -11,7 +11,10 @@ import { z } from 'zod'; * * Declared in its own module, outside the `data` barrel, so the blueprint * reads this leaf without the object schema joining the AI entry's module - * graph, and the leaf does not join the package's published exports. + * graph. `OBJECT_ICON_SCHEMA` and `OBJECT_COLOR_SCHEMA` stay out of the + * package's published exports; the palette, `OBJECT_COLORS` and its + * `ObjectColor` type, is re-exported from `@objectstack/spec/data` for the + * console's tile and picker. */ export const OBJECT_ICON_SCHEMA = z.string().optional().describe('Icon name (Lucide/Material) for UI representation'); From 0fbfc45244563d5a4acd2e68cf48599b3ca83c3a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 07:53:58 +0000 Subject: [PATCH 6/6] chore(changeset): tell strict-blueprint producers they now send color Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgT9PKAmy86XfbYbZtW --- .changeset/35985-object-color-tile.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/35985-object-color-tile.md b/.changeset/35985-object-color-tile.md index 541332c5c36..658180fc3b5 100644 --- a/.changeset/35985-object-color-tile.md +++ b/.changeset/35985-object-color-tile.md @@ -14,7 +14,7 @@ Clause-②: yes (widening) Metadata-protocol: added - **`ObjectSchema.color` (new, optional).** One name from a closed palette of nine: `gray`, `blue`, `teal`, `green`, `amber`, `orange`, `red`, `pink`, `purple` (exported as `OBJECT_COLORS` and the `ObjectColor` type from `@objectstack/spec/data`). No free colour values: `color: '#ff0000'` is refused, and the refusal lists the nine names. An object without a `color` is drawn in the neutral `gray`. Nothing to migrate: every existing object stays valid and simply has no colour. -- **The AI blueprint carries it too.** `BlueprintObjectSchema.color` is the same leaf (required-but-nullable on `SolutionBlueprintStrictSchema`, like `icon`), and its rule asks the model to colour every object and give each object of one solution a different colour while the palette lasts. +- **The AI blueprint carries it too.** `BlueprintObjectSchema.color` is the same leaf (required-but-nullable on `SolutionBlueprintStrictSchema`, like `icon`), and its rule asks the model to colour every object and give each object of one solution a different colour while the palette lasts. A producer of the STRICT shape must now send `color` on each object, `null` when it has none; the lenient shape a stored blueprint is read with keeps it optional. - **`ObjectIconTile` (new, `@object-ui/components`).** Draws an icon name as a white glyph on a rounded square of a palette colour, in four sizes. Each name has a light-theme and a dark-theme value chosen so the white glyph keeps at least 3:1 contrast. `OBJECT_COLOR_TILE_CLASS` and `objectColorOrDefault` are exported with it. - **Navigation draws objects as tiles.** In the sidebar, the app-home menu and the phone menu, every entry that opens an object is drawn as that object's tile: the entry's own `icon` when it names one, else the object's, on the object's colour. Dashboards, pages and links keep their line icons. `NavigationRenderer` takes a new `resolveTargetColor` resolver (`NavTargetColorResolver`) beside `resolveTargetIcon`; the console answers it from the object metadata it already holds (`useNavTargetColor`). A host that passes no `resolveTargetColor` gets its object entries as gray tiles where it had line icons. - **The designer picks icon and colour together.** In the object's settings, the icon picker shows the nine colour swatches, and the trigger and every icon in the grid are previewed as the tile they become. The picker elsewhere (pages, apps, navigation entries) is unchanged: only objects carry a colour.