|
1 | 1 | // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
2 | 2 |
|
3 | 3 | import { z } from 'zod'; |
4 | | -import { ExpressionSchema } from '../shared/expression.zod'; |
5 | | -import { templateExpressionInput } from '../shared/typed-expression-input'; |
| 4 | +import type { TypedExpressionRefusals } from '../shared/typed-expression-input'; |
6 | 5 | import { InlineLocaleMapSchema } from './i18n.zod'; |
7 | 6 |
|
8 | 7 | /** |
@@ -113,21 +112,35 @@ function dialectOnly(key: ActionCopyKey, localeMap: boolean): string { |
113 | 112 | } |
114 | 113 |
|
115 | 114 | /** |
116 | | - * The slot one copy key declares: ADR-0032's `template` dialect, the input |
117 | | - * `TemplateExpressionInputSchema` takes — a bare string is shorthand for |
118 | | - * `{ dialect: 'template', source }`, an envelope must declare |
119 | | - * `dialect: 'template'` — built from the package-internal constructor so its |
120 | | - * refusal prescribes this key's own sentence; then a blank-string arm, so the |
121 | | - * parse does not narrow (the module note); then, on `ActionSchema`, the |
122 | | - * inline locale map its `I18nLabel` took. |
123 | | - * |
124 | | - * A factory the schemas call, not a shared constant: each key refuses with its |
125 | | - * own sentence, and a schema instance shared between two lazily built rows |
126 | | - * would carry one `describe()` for both. |
| 115 | + * The two sentences one copy key's template input refuses with |
| 116 | + * (`templateExpressionInput`'s `refusals`): both prescribe the key's own |
| 117 | + * sentence, so a refusal names the slot the author wrote. |
127 | 118 | */ |
128 | | -export function actionCopyTemplateSlot(key: ActionCopyKey, options: { localeMap?: boolean } = {}) { |
| 119 | +export function actionCopyRefusals(key: ActionCopyKey, options: { localeMap?: boolean } = {}): TypedExpressionRefusals { |
129 | 120 | const refusal = dialectOnly(key, options.localeMap === true); |
130 | | - const template = templateExpressionInput(ExpressionSchema, { sourceRequired: refusal, dialectOnly: refusal }); |
| 121 | + return { sourceRequired: refusal, dialectOnly: refusal }; |
| 122 | +} |
| 123 | + |
| 124 | +/** |
| 125 | + * The slot one copy key declares, around its `template` input: ADR-0032's |
| 126 | + * `template` dialect, the input `TemplateExpressionInputSchema` takes — a bare |
| 127 | + * string is shorthand for `{ dialect: 'template', source }`, an envelope must |
| 128 | + * declare `dialect: 'template'` — then a blank-string arm, so the parse does |
| 129 | + * not narrow (the module note); then, on `ActionSchema`, the inline locale map |
| 130 | + * its `I18nLabel` took. |
| 131 | + * |
| 132 | + * The `template` input itself is built at each declaring `.zod.ts` file |
| 133 | + * (`templateExpressionInput(ExpressionSchema, actionCopyRefusals(key))`), not |
| 134 | + * here: the expression-surface census (the conformance ledger's scan) reads |
| 135 | + * `.zod.ts` files, and a slot whose input is constructed in a plain module is |
| 136 | + * a declared expression surface that census never sees. |
| 137 | + */ |
| 138 | +export function actionCopyTemplateSlot<T extends z.ZodType>( |
| 139 | + template: T, |
| 140 | + key: ActionCopyKey, |
| 141 | + options: { localeMap?: boolean } = {}, |
| 142 | +) { |
| 143 | + const { dialectOnly: refusal } = actionCopyRefusals(key, options); |
131 | 144 | // `trim()`'s whitespace set is exactly `\s` (ECMA-262), so this arm takes the blank strings |
132 | 145 | // `NON_BLANK_STRING` refuses — as a `pattern` the JSON Schema carries, not a dropped refinement. |
133 | 146 | const blank = z.string().regex(/^\s*$/); |
@@ -168,26 +181,3 @@ export const ACTION_ERROR_MESSAGE_TEMPLATE_DESCRIBE = |
168 | 181 | "a `template` slot (ADR-0032) that binds no root: a bare string is shorthand for `{ dialect: 'template', source }`, " |
169 | 182 | + 'and the text is shown as written, so a `{{ }}` hole, a `${…}` or a `{x}` token in it is literal text. Each of ' |
170 | 183 | + `those, and a blank sentence, is named ${DOORS}`; |
171 | | - |
172 | | -/** |
173 | | - * The three copy keys of a page action row — `action:button`, `action:icon` |
174 | | - * and an `action:group` / `action:menu` member (`ui/component.zod.ts`), each |
175 | | - * of which forwards them to the runner as written. One factory per key, so |
176 | | - * every row names its keys in its own shape. |
177 | | - */ |
178 | | -export function actionRowConfirmText() { |
179 | | - return actionCopyTemplateSlot('confirmText').optional() |
180 | | - .describe(`Confirmation question asked before the action runs — ${ACTION_CONFIRM_TEXT_TEMPLATE_DESCRIBE}`); |
181 | | -} |
182 | | - |
183 | | -/** A page action row's `successMessage` — see {@link actionRowConfirmText}. */ |
184 | | -export function actionRowSuccessMessage() { |
185 | | - return actionCopyTemplateSlot('successMessage').optional() |
186 | | - .describe(`Toast shown when the action succeeds — ${ACTION_SUCCESS_MESSAGE_TEMPLATE_DESCRIBE}`); |
187 | | -} |
188 | | - |
189 | | -/** A page action row's `errorMessage` — see {@link actionRowConfirmText}. */ |
190 | | -export function actionRowErrorMessage() { |
191 | | - return actionCopyTemplateSlot('errorMessage').optional() |
192 | | - .describe(`Toast shown when the action fails, in place of the raw error — ${ACTION_ERROR_MESSAGE_TEMPLATE_DESCRIBE}`); |
193 | | -} |
0 commit comments