Skip to content

Commit 67418d8

Browse files
committed
wip(components): declare host keys renderers read by name (RendererHostProps) and narrow per site
Claude-Session: https://claude.ai/code/session_01GJjkZ6pmdwWoDYH8fE8FAn Co-authored-by: Claude <noreply@anthropic.com>
1 parent e8b74ce commit 67418d8

50 files changed

Lines changed: 144 additions & 53 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import type { CSSProperties } from 'react';
10+
11+
/**
12+
* The host keys a renderer in this package reads BY NAME off its props and
13+
* hands to its root element (#25918).
14+
*
15+
* A renderer's props carry an index signature to `unknown`, not `any`: a key
16+
* the host forwards is still admitted, but the renderer has to narrow it
17+
* before it can use it. These three are the exception that is declared rather
18+
* than narrowed at every site, because they are not authoring keys a renderer
19+
* interprets — `SchemaRenderer` (`@object-ui/react`) writes `data-obj-id` from
20+
* the node's `id` and `data-obj-type` from its `type`, and forwards the node's
21+
* `style` (`BaseSchema.style`) — and every renderer that reads them passes
22+
* them straight to the DOM.
23+
*
24+
* Intersect it into a renderer's props annotation; ⛔ never widen the index
25+
* signature back to `any` to make a by-name read compile.
26+
*/
27+
export interface RendererHostProps {
28+
'data-obj-id'?: string;
29+
'data-obj-type'?: string;
30+
style?: CSSProperties;
31+
}

‎ui/packages/components/src/renderers/action/action-bar.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { cn } from '../../lib/utils';
5757
import { useIsMobile } from '../../hooks/use-mobile';
5858
import { ButtonGroup } from '../../custom/button-group';
5959
import { withEvaluatedProperties } from './static-params';
60+
import type { RendererHostProps } from '../../lib/renderer-host-props';
6061

6162
function useActionsLabel(): string {
6263
// useObjectTranslation is provider-safe (never throws); no try/catch, which
@@ -94,7 +95,7 @@ function useActionsLabel(): string {
9495
// exported and never appears in JSX, and `Registry.register` takes
9596
// `ComponentRenderer<T = any> = T`.
9697
const ActionBarRenderer = forwardRef<HTMLDivElement, { schema: ActionBarSchema; className?: string }>(
97-
({ schema, className, ...props }: { schema: ActionBarSchema; className?: string; [key: string]: unknown }, ref) => {
98+
({ schema, className, ...props }: { schema: ActionBarSchema; className?: string; [key: string]: unknown } & RendererHostProps, ref) => {
9899
const actionsAriaLabel = useActionsLabel();
99100
const {
100101
'data-obj-id': dataObjId,

‎ui/packages/components/src/renderers/action/action-button.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { hasDeclaredVisibilityGate } from './visibility-gate';
3232
import { useAutoTriggerOnce } from './auto-trigger';
3333
import { readStaticParamValues } from './static-params';
3434
import { DisabledReasonTrigger, describedByWithReason, useDisabledReason } from './disabled-reason';
35+
import type { RendererHostProps } from '../../lib/renderer-host-props';
3536

3637
/** A record value: a plain object, never `null` or an array. */
3738
function asRecord(value: unknown): Record<string, unknown> | undefined {
@@ -97,7 +98,7 @@ function withUndoBaseline(
9798
// `ActionButtonProps` as the block's AUTHORED property bag (`actionType`, `label`, `variant`, …).
9899
// This is the React envelope that carries a node (`schema`, `context`, `disabled`, an open
99100
// tail) — a different layer, named as objectui#7265 named `RecordAlertRendererProps`.
100-
export interface ActionButtonRendererProps {
101+
export interface ActionButtonRendererProps extends RendererHostProps {
101102
schema: UIActionSchema & { type: string; className?: string; actionType?: string };
102103
className?: string;
103104
/** Override context for this specific action */

‎ui/packages/components/src/renderers/action/action-group.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
menuItemReasonAria,
4343
useDisabledReason,
4444
} from './disabled-reason';
45+
import type { RendererHostProps } from '../../lib/renderer-host-props';
4546

4647
// No group-level `name` (objectui#11168): nothing renders, forwards or keys on
4748
// it, and `@objectstack/spec` refuses it on this block, so the registration
@@ -66,7 +67,7 @@ export interface ActionGroupSchema {
6667
size?: string;
6768
/** Custom CSS class */
6869
className?: string;
69-
[key: string]: unknown;
70+
[key: string]: any;
7071
}
7172

7273
/**
@@ -275,7 +276,7 @@ DropdownActionItem.displayName = 'DropdownActionItem';
275276
// host-EVALUATED enablement verdict, declared rather than left to the index
276277
// signature, as `ActionButtonRendererProps` declares it (objectui#9131).
277278
const ActionGroupRenderer = forwardRef<HTMLDivElement, { schema: ActionGroupSchema; className?: string }>(
278-
({ schema, className, ...props }: { schema: ActionGroupSchema; className?: string; disabled?: boolean; [key: string]: unknown }, ref) => {
279+
({ schema, className, ...props }: { schema: ActionGroupSchema; className?: string; disabled?: boolean; [key: string]: unknown } & RendererHostProps, ref) => {
279280
const {
280281
'data-obj-id': dataObjId,
281282
'data-obj-type': dataObjType,

‎ui/packages/components/src/renderers/action/action-icon.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { hasDeclaredVisibilityGate } from './visibility-gate';
2828
import { useAutoTriggerOnce } from './auto-trigger';
2929
import { readStaticParamValues } from './static-params';
3030
import { DisabledReasonTrigger, describedByWithReason, useDisabledReason } from './disabled-reason';
31+
import type { RendererHostProps } from '../../lib/renderer-host-props';
3132

3233
/**
3334
* The declared props. `schema` is `UIActionSchema` (objectui#4418) for the same
@@ -44,7 +45,7 @@ import { DisabledReasonTrigger, describedByWithReason, useDisabledReason } from
4445
// `ActionIconProps` as the block's AUTHORED property bag (`actionType`, `label`, `variant`, …).
4546
// This is the React envelope that carries a node (`schema`, `context`, `disabled`, an open
4647
// tail) — a different layer, named as objectui#7265 named `RecordAlertRendererProps`.
47-
export interface ActionIconRendererProps {
48+
export interface ActionIconRendererProps extends RendererHostProps {
4849
schema: UIActionSchema & { type: string; className?: string; actionType?: string };
4950
className?: string;
5051
context?: Record<string, any>;

‎ui/packages/components/src/renderers/action/action-menu.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { hasDeclaredVisibilityGate } from './visibility-gate';
3535
import { useAutoTriggerOnce } from './auto-trigger';
3636
import { readActionEntryParamValues } from './static-params';
3737
import { DisabledReasonMenuLabel, menuItemReasonAria, useDisabledReason } from './disabled-reason';
38+
import type { RendererHostProps } from '../../lib/renderer-host-props';
3839

3940
function useMoreActionsLabel(): string {
4041
// useObjectTranslation is provider-safe (never throws); no try/catch, which
@@ -61,7 +62,7 @@ export interface ActionMenuSchema {
6162
visible?: boolean | string | { dialect: string; source?: string };
6263
/** Custom CSS class */
6364
className?: string;
64-
[key: string]: unknown;
65+
[key: string]: any;
6566
}
6667

6768
/**
@@ -207,7 +208,7 @@ ActionAutoTrigger.displayName = 'ActionAutoTrigger';
207208
// host-EVALUATED enablement verdict, declared rather than left to the index
208209
// signature, as `ActionButtonRendererProps` declares it (objectui#9131).
209210
const ActionMenuRenderer = forwardRef<HTMLButtonElement, { schema: ActionMenuSchema; className?: string }>(
210-
({ schema, className, ...props }: { schema: ActionMenuSchema; className?: string; disabled?: boolean; [key: string]: unknown }, ref) => {
211+
({ schema, className, ...props }: { schema: ActionMenuSchema; className?: string; disabled?: boolean; [key: string]: unknown } & RendererHostProps, ref) => {
211212
const {
212213
'data-obj-id': dataObjId,
213214
'data-obj-type': dataObjType,

‎ui/packages/components/src/renderers/basic/button-group.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import { ComponentRegistry } from '@object-ui/core';
1010
import type { ButtonGroupSchema } from '@object-ui/types';
1111
import { Button } from '../../ui';
1212
import { cn } from '../../lib/utils';
13+
import type { RendererHostProps } from '../../lib/renderer-host-props';
1314

1415
ComponentRegistry.register('button-group',
15-
({ schema, ...props }: { schema: ButtonGroupSchema; [key: string]: unknown }) => {
16+
({ schema, ...props }: { schema: ButtonGroupSchema; [key: string]: unknown } & RendererHostProps) => {
1617
const {
1718
'data-obj-id': dataObjId,
1819
'data-obj-type': dataObjType,

‎ui/packages/components/src/renderers/basic/div.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ComponentRegistry } from '@object-ui/core';
1010
import type { DivSchema } from '@object-ui/types';
1111
import { renderChildren } from '../../lib/utils';
1212
import { forwardRef } from 'react';
13+
import type { RendererHostProps } from '../../lib/renderer-host-props';
1314

1415
/**
1516
* Deprecated types already reported in this module instance — the notice is a
@@ -128,7 +129,7 @@ const DIV_DEPRECATION_NOTICE =
128129
// argument — mechanism note on `action:bar` (objectui#4422), pinned by
129130
// `__tests__/forwardref-props-annotation.guard.test.ts`.
130131
const DivRenderer = forwardRef<HTMLDivElement, { schema: DivSchema; className?: string }>(
131-
({ schema, className, ...props }: { schema: DivSchema; className?: string; [key: string]: unknown }, ref) => {
132+
({ schema, className, ...props }: { schema: DivSchema; className?: string; [key: string]: unknown } & RendererHostProps, ref) => {
132133
// Deprecation notice, once per module load (objectui#3965, see
133134
// warnDeprecatedOnce). There is no provenance exemption any more: the
134135
// declaration below names both authoring surfaces (objectui#10757), so a

‎ui/packages/components/src/renderers/basic/icon.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SquareDashed } from 'lucide-react';
1212
import React, { forwardRef } from 'react';
1313
import { cn } from '../../lib/utils';
1414
import { describeIconLookup, resolveIcon } from '../action/resolve-icon';
15+
import type { RendererHostProps } from '../../lib/renderer-host-props';
1516

1617
/**
1718
* The glyph rendered when the requested one does not resolve (objectui#5631).
@@ -108,7 +109,7 @@ import { describeIconLookup, resolveIcon } from '../action/resolve-icon';
108109
// argument — mechanism note on `action:bar` (objectui#4422), pinned by
109110
// `__tests__/forwardref-props-annotation.guard.test.ts`.
110111
const IconRenderer = forwardRef<SVGSVGElement, { schema: IconSchema; className?: string }>(
111-
({ schema, className, ...props }: { schema: IconSchema; className?: string; [key: string]: unknown }, ref) => {
112+
({ schema, className, ...props }: { schema: IconSchema; className?: string; [key: string]: unknown } & RendererHostProps, ref) => {
112113
// Extract designer-related props
113114
const {
114115
'data-obj-id': dataObjId,

‎ui/packages/components/src/renderers/basic/image.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
import { ComponentRegistry } from '@object-ui/core';
1010
import type { ImageSchema } from '@object-ui/types';
11+
import type { RendererHostProps } from '../../lib/renderer-host-props';
1112

1213
ComponentRegistry.register('image',
13-
({ schema, className, ...props }: { schema: ImageSchema; className?: string; [key: string]: unknown }) => {
14+
({ schema, className, ...props }: { schema: ImageSchema; className?: string; [key: string]: unknown } & RendererHostProps) => {
1415
// Extract designer-related props
1516
const {
1617
'data-obj-id': dataObjId,

0 commit comments

Comments
 (0)