@trycourier/react-designer 0.5.1 → 0.7.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.
Files changed (66) hide show
  1. package/README.md +75 -3
  2. package/dist/cjs/index.js +66 -58
  3. package/dist/cjs/index.js.map +4 -4
  4. package/dist/cjs/styles.css +579 -249
  5. package/dist/components/BrandEditor/Editor/BrandFooter/BrandFooter.d.ts +3 -1
  6. package/dist/components/Providers/TemplateProvider.d.ts +2 -0
  7. package/dist/components/TemplateEditor/Channels/Email/EmailEditor.d.ts +3 -1
  8. package/dist/components/TemplateEditor/Channels/Inbox/Inbox.d.ts +3 -0
  9. package/dist/components/TemplateEditor/Channels/Inbox/InboxEditor.d.ts +3 -1
  10. package/dist/components/TemplateEditor/Channels/MSTeams/MSTeams.d.ts +6 -1
  11. package/dist/components/TemplateEditor/Channels/MSTeams/MSTeamsEditor.d.ts +3 -1
  12. package/dist/components/TemplateEditor/Channels/MSTeams/SideBar/MSTeamsSideBarItemDetails.d.ts +8 -0
  13. package/dist/components/TemplateEditor/Channels/MSTeams/SideBar/index.d.ts +1 -0
  14. package/dist/components/TemplateEditor/Channels/MSTeams/index.d.ts +1 -1
  15. package/dist/components/TemplateEditor/Channels/Push/PushEditor.d.ts +3 -1
  16. package/dist/components/TemplateEditor/Channels/SMS/SMSEditor.d.ts +3 -1
  17. package/dist/components/TemplateEditor/Channels/Slack/Slack.d.ts +6 -1
  18. package/dist/components/TemplateEditor/Channels/Slack/SlackEditor.d.ts +3 -1
  19. package/dist/components/TemplateEditor/Layout/Layout.d.ts +1 -0
  20. package/dist/components/TemplateEditor/TemplateEditor.d.ts +2 -0
  21. package/dist/components/TemplateEditor/VariableViewModeSync.d.ts +27 -0
  22. package/dist/components/TemplateEditor/index.d.ts +2 -1
  23. package/dist/components/TemplateEditor/store.d.ts +19 -1
  24. package/dist/components/extensions/Blockquote/Blockquote.d.ts +4 -0
  25. package/dist/components/extensions/Button/Button.d.ts +0 -3
  26. package/dist/components/extensions/Button/Button.types.d.ts +8 -4
  27. package/dist/components/extensions/Button/ButtonComponent.d.ts +2 -3
  28. package/dist/components/extensions/Button/buttonUtils.d.ts +13 -0
  29. package/dist/components/extensions/HardBreak/HardBreak.d.ts +12 -0
  30. package/dist/components/extensions/HardBreak/index.d.ts +1 -0
  31. package/dist/components/extensions/ImageBlock/components/ImageBlockView.d.ts +1 -3
  32. package/dist/components/extensions/List/List.d.ts +0 -1
  33. package/dist/components/extensions/List/List.types.d.ts +0 -10
  34. package/dist/components/extensions/List/ListForm.d.ts +6 -1
  35. package/dist/components/extensions/MessagingChannelPaste/MessagingChannelPaste.d.ts +11 -0
  36. package/dist/components/extensions/MessagingChannelPaste/index.d.ts +2 -0
  37. package/dist/components/extensions/Variable/Variable.d.ts +5 -0
  38. package/dist/components/extensions/Variable/index.d.ts +2 -0
  39. package/dist/components/extensions/Variable/variable-storage.types.d.ts +26 -0
  40. package/dist/components/extensions/Variable/variable-storage.utils.d.ts +72 -0
  41. package/dist/components/extensions/extension-kit.d.ts +17 -0
  42. package/dist/components/extensions/index.d.ts +1 -1
  43. package/dist/components/ui/TextMenu/components/ContentTypePicker.d.ts +1 -1
  44. package/dist/components/ui/TextMenu/hooks/useTextmenuCommands.d.ts +0 -1
  45. package/dist/components/ui/TextMenu/hooks/useTextmenuStates.d.ts +1 -0
  46. package/dist/components/ui/VariableEditor/VariableChipBase.d.ts +8 -0
  47. package/dist/components/ui/VariableEditor/VariableInput.d.ts +18 -0
  48. package/dist/components/ui-kit/Button/Button.d.ts +1 -1
  49. package/dist/components/ui-kit/Toggle/Toggle.d.ts +2 -2
  50. package/dist/components/ui-kit/ToggleGroup/ToggleGroup.d.ts +2 -2
  51. package/dist/components/utils/shadowDomDndFix.d.ts +47 -0
  52. package/dist/esm/index.js +65 -57
  53. package/dist/esm/index.js.map +4 -4
  54. package/dist/esm/styles.css +579 -249
  55. package/dist/hooks/useAutoSave.d.ts +1 -0
  56. package/dist/index.d.ts +3 -0
  57. package/dist/lib/constants/block-defaults.d.ts +43 -0
  58. package/dist/lib/constants/email-editor-tiptap-styles.d.ts +62 -0
  59. package/dist/lib/index.d.ts +1 -0
  60. package/dist/lib/testHelpers.d.ts +21 -1
  61. package/dist/lib/utils/convertElementalToTiptap/convertElementalToTiptap.d.ts +6 -1
  62. package/dist/lib/utils/getTitle/index.d.ts +1 -1
  63. package/dist/lib/utils/getTitle/preserveStorageFormat.d.ts +7 -0
  64. package/dist/styles.css +579 -249
  65. package/dist/types/elemental.types.d.ts +3 -6
  66. package/package.json +6 -1
package/README.md CHANGED
@@ -291,7 +291,9 @@ Type `{{variableName}}` directly in the editor. The variable will be automatical
291
291
 
292
292
  ### Variable Autocomplete
293
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.
294
+ When you provide a `variables` prop, the editor enables variable functionality: typing `{{` creates variable chips, the variable toolbar button is shown, and an autocomplete dropdown guides users to select from available variables.
295
+
296
+ > **Note:** If the `variables` prop is not provided (or is `undefined`), all variable functionality is disabled — the variable toolbar button is hidden and typing `{{` will not create variable chips. To enable variables without autocomplete suggestions, pass an empty object: `variables={{}}`.
295
297
 
296
298
  ```tsx
297
299
  import "@trycourier/react-designer/styles.css";
@@ -789,7 +791,7 @@ The Editor component is the core element that provides the template editing inte
789
791
  | theme | ThemeObj \| cssClass | | Controls the visual appearance of the editor. Can be a Theme object with styling properties or a CSS class name. |
790
792
  | value | ElementalContent | | Initial content for the editor in ElementalContent format. Used as the starting template when the editor loads. |
791
793
  | 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. |
794
+ | variables | Record<string, any> | | Variables available for autocomplete suggestions. When provided, typing `{{` shows a dropdown with matching variables. When not provided (`undefined`), all variable functionality is disabled (toolbar button hidden, `{{` typing does not create chips). Pass `{}` to enable variables without suggestions. See [Variable Autocomplete](#variable-autocomplete) section for details. |
793
795
  | 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. |
794
796
 
795
797
  ### Multi-Channel Routing
@@ -847,7 +849,7 @@ The Brand Editor component accepts properties that allow you to customize its be
847
849
  | theme | ThemeObj \| cssClass | | Controls the visual appearance of the editor. Can be a Theme object with styling properties or a CSS class name. |
848
850
  | value | BrandSettings | | Initial brand settings values to populate the editor with, including colors, logo, social links, and header style preferences. |
849
851
  | 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. |
852
+ | variables | Record<string, any> | | Variables available for autocomplete suggestions. When not provided, all variable functionality is disabled. Pass `{}` to enable without suggestions. |
851
853
  | disableVariablesAutocomplete | boolean | false | When `true`, disables variable autocomplete and allows users to type any variable name directly. |
852
854
 
853
855
  ### Brand Provider
@@ -859,6 +861,76 @@ The Brand Provider component is responsible for managing brand-related state and
859
861
  | tenantId | string | Yes | The unique identifier for the tenant whose brand settings are being edited. |
860
862
  | token | string | Yes | Authentication token (JWT or ClientKey) used to authorize brand-related API requests. |
861
863
 
864
+ ## Shadow DOM Usage
865
+
866
+ If you render the Courier Editor inside a [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM) (e.g., for style isolation), drag-and-drop functionality will not work out of the box. This is a known incompatibility with the underlying [pragmatic-drag-and-drop](https://github.com/atlassian/pragmatic-drag-and-drop) library, which relies on `event.target` to identify dragged elements. Shadow DOM re-targets events to the shadow host, breaking this detection.
867
+
868
+ We provide a utility function `applyShadowDomDndFix` that patches event handling to restore drag-and-drop support inside a Shadow DOM.
869
+
870
+ ### Setup
871
+
872
+ Call `applyShadowDomDndFix(shadowRoot)` **after** creating the shadow root but **before** rendering the editor. Store the returned cleanup function and call it when unmounting.
873
+
874
+ ```tsx
875
+ import { useEffect, useRef } from "react";
876
+ import { createRoot } from "react-dom/client";
877
+ import {
878
+ TemplateEditor,
879
+ TemplateProvider,
880
+ applyShadowDomDndFix,
881
+ } from "@trycourier/react-designer";
882
+ import "@trycourier/react-designer/styles.css";
883
+
884
+ function EditorInShadowDom() {
885
+ const containerRef = useRef<HTMLDivElement>(null);
886
+
887
+ useEffect(() => {
888
+ const container = containerRef.current;
889
+ if (!container) return;
890
+
891
+ // 1. Create Shadow DOM
892
+ const shadowRoot = container.attachShadow({ mode: "open" });
893
+
894
+ // 2. Apply DnD fix BEFORE rendering the editor
895
+ const cleanupDndFix = applyShadowDomDndFix(shadowRoot);
896
+
897
+ // 3. Inject styles into shadow root
898
+ const link = document.createElement("link");
899
+ link.rel = "stylesheet";
900
+ link.href = "/path/to/react-designer/styles.css";
901
+ shadowRoot.appendChild(link);
902
+
903
+ // 4. Render the editor
904
+ const mountPoint = document.createElement("div");
905
+ shadowRoot.appendChild(mountPoint);
906
+
907
+ const root = createRoot(mountPoint);
908
+ root.render(
909
+ <TemplateProvider
910
+ templateId="my-template"
911
+ tenantId="my-tenant"
912
+ token="my-token"
913
+ >
914
+ <TemplateEditor />
915
+ </TemplateProvider>
916
+ );
917
+
918
+ // 5. Cleanup on unmount
919
+ return () => {
920
+ cleanupDndFix();
921
+ root.unmount();
922
+ };
923
+ }, []);
924
+
925
+ return <div ref={containerRef} />;
926
+ }
927
+ ```
928
+
929
+ ### Known Limitations
930
+
931
+ - **Drag handles are disabled in Shadow DOM.** In a normal DOM context, blocks can only be dragged by the grip icon on the left. Inside a Shadow DOM, blocks become draggable from anywhere on the element. This is because pragmatic-drag-and-drop's internal handle validation is not compatible with Shadow DOM event re-targeting.
932
+ - **Global patch.** The fix monkey-patches `Event.prototype.target` while active. Always call the cleanup function when unmounting to restore normal behavior.
933
+
862
934
  # Limitations
863
935
 
864
936
  **React Only**