diff --git a/.changeset/embed-default-override.md b/.changeset/embed-default-override.md new file mode 100644 index 0000000..9baa1d0 --- /dev/null +++ b/.changeset/embed-default-override.md @@ -0,0 +1,5 @@ +--- +'@monad-inc/embed': minor +--- + +Add a `default` key to `configMetaOverrides` fields so hosts can prefill a value on new connectors. diff --git a/packages/embed/USAGE.md b/packages/embed/USAGE.md index 7b465af..5e0e7d9 100644 --- a/packages/embed/USAGE.md +++ b/packages/embed/USAGE.md @@ -120,7 +120,7 @@ controls the surrounding chrome. | `isDescriptionEditable` | `boolean` | ⛔ | `false` | Show an editable description input in the iframe (prefilled with `description` if provided). | | `appearance` | `Appearance` | ⛔ | Monad defaults | Theming tokens (see below). | | `stylesheets` | `string[]` | ⛔ | Monad's built-in stylesheet | Your own stylesheet URLs. All-or-nothing: if set, Monad's defaults are not loaded (see below). | -| `configMetaOverrides` | `ConfigMetaOverrides` | ⛔ | the connector's own copy | Per-field label / description / placeholder overrides (see below). | +| `configMetaOverrides` | `ConfigMetaOverrides` | ⛔ | the connector's own copy | Per-field label / description / placeholder / default overrides (see below). | | `synthetic` | `boolean` | ⛔ | `false` | Exposes Monad's internal synthetic-data toggle. Keep off in production. | | `frameOrigin` | `string` | ⛔ | `https://app.monad.com/embed` | Override only for non-prod testing. | | `apiBase` | `string` | ⛔ | `https://app.monad.com/api` | Override only for non-prod testing. | @@ -190,13 +190,25 @@ original copy. **`placeholder` is a hint, not a default.** It shows as grey text and disappears as soon as the user types. A field the user never touches -still submits an empty value. There is no option to pre-fill a real -value, because that would change the data your connector is configured -with. +still submits an empty value. To pre-fill a real value, use `default`. ### What you can override -Per field: `name`, `description`, `placeholder`. +Per field: `name`, `description`, `placeholder`, `default`. + +`default` pre-fills the field when a user creates a connector. The value +is editable and is submitted like any other. It is ignored when editing an +existing connector, so the saved value always wins. It works on string +(including dropdowns — the value must be one of the options), number, and +boolean fields; anything else, or a value of the wrong type, is ignored. + +```ts +configMetaOverrides: { + settings: { + summary_config: { children: { alert_source: { default: 'northstar' } } }, + }, +} +``` Nested fields are reached with `children`, and the variants of a multiple-choice field with `discriminator.one_of`: @@ -217,8 +229,8 @@ configMetaOverrides: { } ``` -A field's type, whether it is required, its allowed values, and its -default are fixed by the connector and cannot be overridden. Some +A field's type, whether it is required, and its allowed values are fixed +by the connector and cannot be overridden. Some controls have nowhere to show a placeholder — dropdowns, checkboxes, and code editors ignore it. If you need a field to _behave_ differently, that's a change to the connector itself; file an issue. diff --git a/packages/embed/src/connect/protocol.ts b/packages/embed/src/connect/protocol.ts index ec41d7e..f41597a 100644 --- a/packages/embed/src/connect/protocol.ts +++ b/packages/embed/src/connect/protocol.ts @@ -44,12 +44,11 @@ export interface Appearance { /** * Copy overrides for a single field of a connector's config form. * - * Only copy can be overridden. A field's type, requiredness, allowed - * values, and default are fixed by the connector and cannot be changed - * here. + * Only copy and a scalar `default` can be overridden. A field's type, + * requiredness, and allowed values are fixed by the connector. * - * `placeholder` is a hint, not a default: a field the user never touches - * still submits an empty value. + * `placeholder` is a hint: a field the user never touches still submits + * an empty value. Use `default` to prefill a real value. * * Keys mirror the config shape returned for the connector type, so they * are snake_case — unlike the camelCase options on @@ -64,6 +63,12 @@ export interface FieldMetaOverride { description?: string; /** Ephemeral hint text inside the control. Empty string blanks it. */ placeholder?: string; + /** + * Prefilled value for a new connector. Stays editable and is submitted. + * Ignored when editing, so the saved value wins. Applies to string + * (within its allowed values), number and boolean fields only. + */ + default?: string | number | boolean; /** Overrides for a nested object's child fields, keyed by child wire key. */ children?: Record; /** Overrides for a discriminated-union (one_of) field. */