@trycourier/react-designer 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -2
- package/dist/cjs/index.js +61 -57
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/styles.css +454 -145
- package/dist/components/BrandEditor/Editor/Editor.d.ts +16 -1
- package/dist/components/Providers/useTemplateActions.d.ts +2 -2
- package/dist/components/TemplateEditor/Channels/Email/Email.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Email/EmailEditor.d.ts +2 -1
- package/dist/components/TemplateEditor/Channels/Email/EmailLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Email/SideBar/SideBarItemDetails/SideBarItemDetails.d.ts +2 -1
- package/dist/components/TemplateEditor/Channels/Inbox/Inbox.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Inbox/InboxLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/MSTeams/MSTeams.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/MSTeams/MSTeamsLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Push/Push.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Push/PushLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/SMS/SMS.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/SMS/SMSLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Slack/Slack.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Slack/SlackLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/useChannels.d.ts +8 -0
- package/dist/components/TemplateEditor/TemplateEditor.d.ts +16 -1
- package/dist/components/TemplateEditor/index.d.ts +2 -14
- package/dist/components/TemplateEditor/store.d.ts +10 -0
- package/dist/components/extensions/Blockquote/BlockquoteForm.d.ts +2 -1
- package/dist/components/extensions/Button/ButtonForm.d.ts +2 -1
- package/dist/components/extensions/Column/ColumnForm.d.ts +2 -1
- package/dist/components/extensions/CustomCode/CustomCodeForm.d.ts +2 -1
- package/dist/components/extensions/Divider/DividerForm.d.ts +2 -1
- package/dist/components/extensions/ImageBlock/components/ImageBlockForm.d.ts +2 -1
- package/dist/components/extensions/List/List.d.ts +15 -0
- package/dist/components/extensions/List/List.types.d.ts +38 -0
- package/dist/components/extensions/List/ListComponent.d.ts +12 -0
- package/dist/components/extensions/List/ListForm.d.ts +9 -0
- package/dist/components/extensions/List/index.d.ts +4 -0
- package/dist/components/extensions/ListItem/ListItem.d.ts +34 -0
- package/dist/components/extensions/ListItem/ListItem.types.d.ts +7 -0
- package/dist/components/extensions/ListItem/ListItemComponent.d.ts +7 -0
- package/dist/components/extensions/ListItem/index.d.ts +2 -0
- package/dist/components/extensions/TextBlock/TextBlockForm.d.ts +2 -1
- package/dist/components/extensions/Variable/Variable.d.ts +8 -4
- package/dist/components/extensions/Variable/Variable.types.d.ts +3 -14
- package/dist/components/extensions/Variable/VariableSuggestions.d.ts +7 -0
- package/dist/components/extensions/Variable/index.d.ts +1 -0
- package/dist/components/extensions/Variable/suggestion.d.ts +2 -0
- package/dist/components/extensions/extension-kit.d.ts +7 -2
- package/dist/components/extensions/index.d.ts +2 -0
- package/dist/components/ui/Blocks/ListBlock/ListBlock.d.ts +2 -0
- package/dist/components/ui/Blocks/ListBlock/index.d.ts +1 -0
- package/dist/components/ui/Blocks/index.d.ts +1 -0
- package/dist/components/ui/FormHeader/FormHeader.d.ts +3 -2
- package/dist/components/ui/SortableItemWrapper/SortableItemWrapper.d.ts +3 -1
- package/dist/components/ui/TextMenu/config.d.ts +2 -0
- package/dist/components/ui/TextMenu/hooks/useTextmenuCommands.d.ts +4 -0
- package/dist/components/ui/TextMenu/hooks/useTextmenuStates.d.ts +2 -0
- package/dist/components/ui/VariableEditor/VariableAutocomplete.d.ts +16 -0
- package/dist/components/ui/VariableEditor/VariableChipBase.d.ts +2 -0
- package/dist/components/ui-kit/Icon/UnorderedListIcon.d.ts +3 -0
- package/dist/components/ui-kit/Icon/index.d.ts +1 -1
- package/dist/esm/index.js +61 -57
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/styles.css +454 -145
- package/dist/index.d.ts +14 -0
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/styles.css +454 -145
- package/dist/types/elemental.types.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/validation.types.d.ts +53 -0
- package/package.json +1 -1
- package/dist/components/ui-kit/Icon/BulletListIcon.d.ts +0 -3
package/README.md
CHANGED
|
@@ -289,6 +289,114 @@ The Courier Editor supports any valid variable name, including nested structures
|
|
|
289
289
|
|
|
290
290
|
Type `{{variableName}}` directly in the editor. The variable will be automatically converted to a variable node when you finish typing. Variable names must follow valid JSON property naming conventions (e.g., `user.firstName`, `company.name`).
|
|
291
291
|
|
|
292
|
+
### Variable Autocomplete
|
|
293
|
+
|
|
294
|
+
When you provide a `variables` prop, the editor shows an autocomplete dropdown when users type `{{`. This guides users to select from available variables and helps prevent typos.
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
import "@trycourier/react-designer/styles.css";
|
|
298
|
+
import { TemplateEditor, TemplateProvider } from "@trycourier/react-designer";
|
|
299
|
+
|
|
300
|
+
function App() {
|
|
301
|
+
// Define available variables (can be nested objects)
|
|
302
|
+
const variables = {
|
|
303
|
+
user: {
|
|
304
|
+
firstName: "",
|
|
305
|
+
lastName: "",
|
|
306
|
+
email: "",
|
|
307
|
+
},
|
|
308
|
+
order: {
|
|
309
|
+
id: "",
|
|
310
|
+
total: "",
|
|
311
|
+
date: "",
|
|
312
|
+
},
|
|
313
|
+
company: {
|
|
314
|
+
name: "",
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
return (
|
|
319
|
+
<TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
|
|
320
|
+
<TemplateEditor variables={variables} />
|
|
321
|
+
</TemplateProvider>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
When users type `{{` in the editor, they'll see a dropdown with:
|
|
327
|
+
- `user.firstName`
|
|
328
|
+
- `user.lastName`
|
|
329
|
+
- `user.email`
|
|
330
|
+
- `order.id`
|
|
331
|
+
- `order.total`
|
|
332
|
+
- `order.date`
|
|
333
|
+
- `company.name`
|
|
334
|
+
|
|
335
|
+
The dropdown filters as the user types, making it easy to find the right variable.
|
|
336
|
+
|
|
337
|
+
**Disabling Autocomplete:**
|
|
338
|
+
|
|
339
|
+
If you want to allow users to type any variable name without suggestions, use the `disableVariablesAutocomplete` prop:
|
|
340
|
+
|
|
341
|
+
```tsx
|
|
342
|
+
<TemplateEditor disableVariablesAutocomplete />
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
This is useful when you don't have a predefined list of variables and want to allow any variable name.
|
|
346
|
+
|
|
347
|
+
### Variable Validation
|
|
348
|
+
|
|
349
|
+
The editor supports custom variable validation, allowing you to restrict which variable names users can enter. This is useful when you have a specific set of allowed replacement variables and want to prevent users from entering arbitrary names that could cause errors downstream.
|
|
350
|
+
|
|
351
|
+
```tsx
|
|
352
|
+
import "@trycourier/react-designer/styles.css";
|
|
353
|
+
import { TemplateEditor, TemplateProvider } from "@trycourier/react-designer";
|
|
354
|
+
import type { VariableValidationConfig } from "@trycourier/react-designer";
|
|
355
|
+
|
|
356
|
+
const ALLOWED_VARIABLES = [
|
|
357
|
+
"user.firstName",
|
|
358
|
+
"user.lastName",
|
|
359
|
+
"user.email",
|
|
360
|
+
"order.id",
|
|
361
|
+
"order.total",
|
|
362
|
+
];
|
|
363
|
+
|
|
364
|
+
function App() {
|
|
365
|
+
const variableValidation: VariableValidationConfig = {
|
|
366
|
+
// Custom validator - return true if variable is allowed
|
|
367
|
+
validate: (name) => ALLOWED_VARIABLES.includes(name),
|
|
368
|
+
|
|
369
|
+
// Behavior when validation fails: "mark" (default) or "remove"
|
|
370
|
+
onInvalid: "mark",
|
|
371
|
+
|
|
372
|
+
// Toast message shown on invalid variable
|
|
373
|
+
invalidMessage: (name) =>
|
|
374
|
+
`Variable "${name}" is not allowed. Available: ${ALLOWED_VARIABLES.join(", ")}`,
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
return (
|
|
378
|
+
<TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
|
|
379
|
+
<TemplateEditor variableValidation={variableValidation} />
|
|
380
|
+
</TemplateProvider>
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**VariableValidationConfig Options:**
|
|
386
|
+
|
|
387
|
+
| Option | Type | Default | Description |
|
|
388
|
+
|--------|------|---------|-------------|
|
|
389
|
+
| `validate` | `(name: string) => boolean` | - | Custom validator function. Returns `true` if the variable is allowed. Runs after built-in format validation. |
|
|
390
|
+
| `onInvalid` | `"mark" \| "remove"` | `"mark"` | Behavior when validation fails. `"mark"` keeps the chip with invalid styling (red). `"remove"` deletes the chip. |
|
|
391
|
+
| `invalidMessage` | `string \| ((name: string) => string)` | - | Message to show as a toast when validation fails. Can be a static string or a function for dynamic messages. |
|
|
392
|
+
| `overrideFormatValidation` | `boolean` | `false` | If `true`, bypasses built-in format validation entirely. Only the custom `validate` function is used. Use with caution. |
|
|
393
|
+
|
|
394
|
+
**Validation Flow:**
|
|
395
|
+
|
|
396
|
+
1. **Built-in format validation** runs first (unless `overrideFormatValidation` is `true`), ensuring the variable name follows valid JSON property conventions.
|
|
397
|
+
2. **Custom validation** runs second (if `validate` is provided), checking against your allowed list or custom rules.
|
|
398
|
+
3. If validation fails, the `onInvalid` behavior is applied and a toast is shown if `invalidMessage` is configured.
|
|
399
|
+
|
|
292
400
|
### Block Library Customization
|
|
293
401
|
|
|
294
402
|
The `useBlockConfig` hook allows you to customize the blocks available in the sidebar, set default attributes, and create pre-configured block presets.
|
|
@@ -680,7 +788,9 @@ The Editor component is the core element that provides the template editing inte
|
|
|
680
788
|
| routing | { method: string; channels: string[] } | | Configures multi-channel routing and delivery behavior. The `method` property determines delivery strategy: "single" (deliver via first available channel) or "all" (deliver via all configured channels). The `channels` array defines which delivery channels are available in the editor. |
|
|
681
789
|
| theme | ThemeObj \| cssClass | | Controls the visual appearance of the editor. Can be a Theme object with styling properties or a CSS class name. |
|
|
682
790
|
| value | ElementalContent | | Initial content for the editor in ElementalContent format. Used as the starting template when the editor loads. |
|
|
683
|
-
|
|
|
791
|
+
| variableValidation | VariableValidationConfig | | Configuration for custom variable validation. Allows restricting which variable names are allowed and defining behavior on validation failure. See [Variable Validation](#variable-validation) section for details. |
|
|
792
|
+
| variables | Record<string, any> | | Variables available for autocomplete suggestions. When provided, typing `{{` shows a dropdown with matching variables. See [Variable Autocomplete](#variable-autocomplete) section for details. |
|
|
793
|
+
| disableVariablesAutocomplete | boolean | false | When `true`, disables variable autocomplete and allows users to type any variable name directly. When `false` (default), shows autocomplete dropdown with variables from the `variables` prop. |
|
|
684
794
|
|
|
685
795
|
### Multi-Channel Routing
|
|
686
796
|
|
|
@@ -736,7 +846,9 @@ The Brand Editor component accepts properties that allow you to customize its be
|
|
|
736
846
|
| onChange | (value: BrandSettings) => void | | Callback function that fires whenever brand settings are modified, providing the updated brand configuration values. |
|
|
737
847
|
| theme | ThemeObj \| cssClass | | Controls the visual appearance of the editor. Can be a Theme object with styling properties or a CSS class name. |
|
|
738
848
|
| value | BrandSettings | | Initial brand settings values to populate the editor with, including colors, logo, social links, and header style preferences. |
|
|
739
|
-
|
|
|
849
|
+
| variableValidation | VariableValidationConfig | | Configuration for custom variable validation. See [Variable Validation](#variable-validation) section for details. |
|
|
850
|
+
| variables | Record<string, any> | | Variables available for autocomplete suggestions. When provided, typing `{{` shows a dropdown with matching variables. |
|
|
851
|
+
| disableVariablesAutocomplete | boolean | false | When `true`, disables variable autocomplete and allows users to type any variable name directly. |
|
|
740
852
|
|
|
741
853
|
### Brand Provider
|
|
742
854
|
|