@agilo/medusa-email-templates-plugin 0.0.0-stage → 1.0.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 (180) hide show
  1. package/.medusa/server/medusa-config.d.ts +2 -0
  2. package/.medusa/server/medusa-config.js +57 -0
  3. package/.medusa/server/src/admin/_chunks/__admin-extensions__-B-Rs6wVu +1412 -0
  4. package/.medusa/server/src/admin/_chunks/__admin-extensions__-Cu08yi-Z +1413 -0
  5. package/.medusa/server/src/admin/_chunks/email-template-editor-JGYZjesE +820 -0
  6. package/.medusa/server/src/admin/_chunks/email-template-editor-_uBb7FNZ +820 -0
  7. package/.medusa/server/src/admin/_chunks/subject-editor-DsSopX-7 +115 -0
  8. package/.medusa/server/src/admin/_chunks/subject-editor-ykrWWMtp +115 -0
  9. package/.medusa/server/src/admin/_chunks/variable-node-BO5f9lJL +353 -0
  10. package/.medusa/server/src/admin/_chunks/variable-node-D2KY7H-p +352 -0
  11. package/.medusa/server/src/admin/index.js +3 -0
  12. package/.medusa/server/src/admin/index.mjs +4 -0
  13. package/.medusa/server/src/admin/tailwind-safelist.js +204 -0
  14. package/.medusa/server/src/api/admin/email/error-response.d.ts +2 -0
  15. package/.medusa/server/src/api/admin/email/error-response.js +26 -0
  16. package/.medusa/server/src/api/admin/email/middlewares.d.ts +2 -0
  17. package/.medusa/server/src/api/admin/email/middlewares.js +34 -0
  18. package/.medusa/server/src/api/admin/email/provider/route.d.ts +4 -0
  19. package/.medusa/server/src/api/admin/email/provider/route.js +36 -0
  20. package/.medusa/server/src/api/admin/email/provider/send-test/route.d.ts +3 -0
  21. package/.medusa/server/src/api/admin/email/provider/send-test/route.js +23 -0
  22. package/.medusa/server/src/api/admin/email/provider/validators.d.ts +25 -0
  23. package/.medusa/server/src/api/admin/email/provider/validators.js +27 -0
  24. package/.medusa/server/src/api/admin/email/templates/[id]/preview/route.d.ts +3 -0
  25. package/.medusa/server/src/api/admin/email/templates/[id]/preview/route.js +16 -0
  26. package/.medusa/server/src/api/admin/email/templates/[id]/route.d.ts +5 -0
  27. package/.medusa/server/src/api/admin/email/templates/[id]/route.js +45 -0
  28. package/.medusa/server/src/api/admin/email/templates/[id]/send-test/route.d.ts +3 -0
  29. package/.medusa/server/src/api/admin/email/templates/[id]/send-test/route.js +25 -0
  30. package/.medusa/server/src/api/admin/email/templates/route.d.ts +2 -0
  31. package/.medusa/server/src/api/admin/email/templates/route.js +12 -0
  32. package/.medusa/server/src/api/admin/email/templates/validators.d.ts +28 -0
  33. package/.medusa/server/src/api/admin/email/templates/validators.js +30 -0
  34. package/.medusa/server/src/api/admin/plugin/route.d.ts +2 -0
  35. package/.medusa/server/src/api/admin/plugin/route.js +7 -0
  36. package/.medusa/server/src/api/middlewares.d.ts +2 -0
  37. package/.medusa/server/src/api/middlewares.js +8 -0
  38. package/.medusa/server/src/api/store/plugin/route.d.ts +2 -0
  39. package/.medusa/server/src/api/store/plugin/route.js +7 -0
  40. package/.medusa/server/src/lib/container.d.ts +8 -0
  41. package/.medusa/server/src/lib/container.js +23 -0
  42. package/.medusa/server/src/lib/content.d.ts +4 -0
  43. package/.medusa/server/src/lib/content.js +9 -0
  44. package/.medusa/server/src/lib/credentials/mask.d.ts +10 -0
  45. package/.medusa/server/src/lib/credentials/mask.js +55 -0
  46. package/.medusa/server/src/lib/credentials/resolve-credential.d.ts +11 -0
  47. package/.medusa/server/src/lib/credentials/resolve-credential.js +34 -0
  48. package/.medusa/server/src/lib/crypto/credential-cipher.d.ts +7 -0
  49. package/.medusa/server/src/lib/crypto/credential-cipher.js +65 -0
  50. package/.medusa/server/src/lib/crypto/encryption-key.d.ts +9 -0
  51. package/.medusa/server/src/lib/crypto/encryption-key.js +45 -0
  52. package/.medusa/server/src/lib/errors.d.ts +18 -0
  53. package/.medusa/server/src/lib/errors.js +40 -0
  54. package/.medusa/server/src/lib/events/built-in/default-templates/account.d.ts +6 -0
  55. package/.medusa/server/src/lib/events/built-in/default-templates/account.js +48 -0
  56. package/.medusa/server/src/lib/events/built-in/default-templates/design.d.ts +67 -0
  57. package/.medusa/server/src/lib/events/built-in/default-templates/design.js +94 -0
  58. package/.medusa/server/src/lib/events/built-in/default-templates/order-placed.d.ts +5 -0
  59. package/.medusa/server/src/lib/events/built-in/default-templates/order-placed.js +59 -0
  60. package/.medusa/server/src/lib/events/built-in/default-templates/repeat.d.ts +3 -0
  61. package/.medusa/server/src/lib/events/built-in/default-templates/repeat.js +23 -0
  62. package/.medusa/server/src/lib/events/built-in/email-verification.d.ts +13 -0
  63. package/.medusa/server/src/lib/events/built-in/email-verification.js +53 -0
  64. package/.medusa/server/src/lib/events/built-in/invite.d.ts +5 -0
  65. package/.medusa/server/src/lib/events/built-in/invite.js +91 -0
  66. package/.medusa/server/src/lib/events/built-in/order-placed.d.ts +4 -0
  67. package/.medusa/server/src/lib/events/built-in/order-placed.js +234 -0
  68. package/.medusa/server/src/lib/events/built-in/password-reset.d.ts +12 -0
  69. package/.medusa/server/src/lib/events/built-in/password-reset.js +83 -0
  70. package/.medusa/server/src/lib/events/built-in/store.d.ts +3 -0
  71. package/.medusa/server/src/lib/events/built-in/store.js +12 -0
  72. package/.medusa/server/src/lib/events/define-email-event.d.ts +6 -0
  73. package/.medusa/server/src/lib/events/define-email-event.js +11 -0
  74. package/.medusa/server/src/lib/events/index.d.ts +8 -0
  75. package/.medusa/server/src/lib/events/index.js +21 -0
  76. package/.medusa/server/src/lib/events/registry.d.ts +9 -0
  77. package/.medusa/server/src/lib/events/registry.js +55 -0
  78. package/.medusa/server/src/lib/events/types.d.ts +82 -0
  79. package/.medusa/server/src/lib/events/types.js +3 -0
  80. package/.medusa/server/src/lib/events/urls.d.ts +23 -0
  81. package/.medusa/server/src/lib/events/urls.js +79 -0
  82. package/.medusa/server/src/lib/provider-configuration.d.ts +51 -0
  83. package/.medusa/server/src/lib/provider-configuration.js +114 -0
  84. package/.medusa/server/src/lib/redact.d.ts +1 -0
  85. package/.medusa/server/src/lib/redact.js +12 -0
  86. package/.medusa/server/src/lib/rendering/format-value.d.ts +21 -0
  87. package/.medusa/server/src/lib/rendering/format-value.js +55 -0
  88. package/.medusa/server/src/lib/rendering/liquid.d.ts +5 -0
  89. package/.medusa/server/src/lib/rendering/liquid.js +52 -0
  90. package/.medusa/server/src/lib/rendering/render-template.d.ts +12 -0
  91. package/.medusa/server/src/lib/rendering/render-template.js +46 -0
  92. package/.medusa/server/src/lib/rendering/sanitize-context.d.ts +1 -0
  93. package/.medusa/server/src/lib/rendering/sanitize-context.js +14 -0
  94. package/.medusa/server/src/lib/rendering/variable-format.d.ts +43 -0
  95. package/.medusa/server/src/lib/rendering/variable-format.js +103 -0
  96. package/.medusa/server/src/lib/resolve-email-content.d.ts +9 -0
  97. package/.medusa/server/src/lib/resolve-email-content.js +35 -0
  98. package/.medusa/server/src/lib/templates.d.ts +55 -0
  99. package/.medusa/server/src/lib/templates.js +161 -0
  100. package/.medusa/server/src/lib/test-email.d.ts +7 -0
  101. package/.medusa/server/src/lib/test-email.js +21 -0
  102. package/.medusa/server/src/lib/transports/address.d.ts +3 -0
  103. package/.medusa/server/src/lib/transports/address.js +16 -0
  104. package/.medusa/server/src/lib/transports/cloud-config.d.ts +13 -0
  105. package/.medusa/server/src/lib/transports/cloud-config.js +30 -0
  106. package/.medusa/server/src/lib/transports/mailgun.d.ts +15 -0
  107. package/.medusa/server/src/lib/transports/mailgun.js +116 -0
  108. package/.medusa/server/src/lib/transports/medusa-cloud.d.ts +15 -0
  109. package/.medusa/server/src/lib/transports/medusa-cloud.js +81 -0
  110. package/.medusa/server/src/lib/transports/registry.d.ts +4 -0
  111. package/.medusa/server/src/lib/transports/registry.js +24 -0
  112. package/.medusa/server/src/lib/transports/resend.d.ts +11 -0
  113. package/.medusa/server/src/lib/transports/resend.js +93 -0
  114. package/.medusa/server/src/lib/transports/types.d.ts +46 -0
  115. package/.medusa/server/src/lib/transports/types.js +10 -0
  116. package/.medusa/server/src/modules/email-templates/index.d.ts +49 -0
  117. package/.medusa/server/src/modules/email-templates/index.js +13 -0
  118. package/.medusa/server/src/modules/email-templates/migrations/Migration20260915141601.d.ts +5 -0
  119. package/.medusa/server/src/modules/email-templates/migrations/Migration20260915141601.js +27 -0
  120. package/.medusa/server/src/modules/email-templates/migrations/Migration20260916090537.d.ts +5 -0
  121. package/.medusa/server/src/modules/email-templates/migrations/Migration20260916090537.js +18 -0
  122. package/.medusa/server/src/modules/email-templates/models/email-provider-configuration.d.ts +24 -0
  123. package/.medusa/server/src/modules/email-templates/models/email-provider-configuration.js +32 -0
  124. package/.medusa/server/src/modules/email-templates/models/email-provider-credential.d.ts +21 -0
  125. package/.medusa/server/src/modules/email-templates/models/email-provider-credential.js +32 -0
  126. package/.medusa/server/src/modules/email-templates/models/email-template.d.ts +11 -0
  127. package/.medusa/server/src/modules/email-templates/models/email-template.js +25 -0
  128. package/.medusa/server/src/modules/email-templates/service.d.ts +70 -0
  129. package/.medusa/server/src/modules/email-templates/service.js +24 -0
  130. package/.medusa/server/src/providers/email/index.d.ts +2 -0
  131. package/.medusa/server/src/providers/email/index.js +11 -0
  132. package/.medusa/server/src/providers/email/service.d.ts +17 -0
  133. package/.medusa/server/src/providers/email/service.js +57 -0
  134. package/.medusa/server/src/registry.d.ts +34 -0
  135. package/.medusa/server/src/registry.js +49 -0
  136. package/.medusa/server/src/subscribers/email-account-events.d.ts +3 -0
  137. package/.medusa/server/src/subscribers/email-account-events.js +31 -0
  138. package/.medusa/server/src/subscribers/email-order-placed.d.ts +5 -0
  139. package/.medusa/server/src/subscribers/email-order-placed.js +26 -0
  140. package/.medusa/server/src/workflows/index.d.ts +6 -0
  141. package/.medusa/server/src/workflows/index.js +23 -0
  142. package/.medusa/server/src/workflows/preview-email-template.d.ts +3 -0
  143. package/.medusa/server/src/workflows/preview-email-template.js +11 -0
  144. package/.medusa/server/src/workflows/reset-email-template.d.ts +6 -0
  145. package/.medusa/server/src/workflows/reset-email-template.js +11 -0
  146. package/.medusa/server/src/workflows/save-email-provider-configuration.d.ts +6 -0
  147. package/.medusa/server/src/workflows/save-email-provider-configuration.js +28 -0
  148. package/.medusa/server/src/workflows/send-email-event.d.ts +3 -0
  149. package/.medusa/server/src/workflows/send-email-event.js +13 -0
  150. package/.medusa/server/src/workflows/send-provider-test-email.d.ts +7 -0
  151. package/.medusa/server/src/workflows/send-provider-test-email.js +11 -0
  152. package/.medusa/server/src/workflows/send-template-test-email.d.ts +12 -0
  153. package/.medusa/server/src/workflows/send-template-test-email.js +30 -0
  154. package/.medusa/server/src/workflows/steps/assert-email-provider-ready.d.ts +5 -0
  155. package/.medusa/server/src/workflows/steps/assert-email-provider-ready.js +21 -0
  156. package/.medusa/server/src/workflows/steps/render-email-template.d.ts +8 -0
  157. package/.medusa/server/src/workflows/steps/render-email-template.js +22 -0
  158. package/.medusa/server/src/workflows/steps/reset-email-template.d.ts +14 -0
  159. package/.medusa/server/src/workflows/steps/reset-email-template.js +69 -0
  160. package/.medusa/server/src/workflows/steps/resolve-email-event.d.ts +20 -0
  161. package/.medusa/server/src/workflows/steps/resolve-email-event.js +56 -0
  162. package/.medusa/server/src/workflows/steps/select-email-provider-configuration.d.ts +27 -0
  163. package/.medusa/server/src/workflows/steps/select-email-provider-configuration.js +62 -0
  164. package/.medusa/server/src/workflows/steps/send-email-event-notification.d.ts +9 -0
  165. package/.medusa/server/src/workflows/steps/send-email-event-notification.js +70 -0
  166. package/.medusa/server/src/workflows/steps/send-test-email.d.ts +15 -0
  167. package/.medusa/server/src/workflows/steps/send-test-email.js +31 -0
  168. package/.medusa/server/src/workflows/steps/send-transport-test-email.d.ts +16 -0
  169. package/.medusa/server/src/workflows/steps/send-transport-test-email.js +49 -0
  170. package/.medusa/server/src/workflows/steps/upsert-email-provider-credential.d.ts +10 -0
  171. package/.medusa/server/src/workflows/steps/upsert-email-provider-credential.js +84 -0
  172. package/.medusa/server/src/workflows/steps/upsert-email-template.d.ts +22 -0
  173. package/.medusa/server/src/workflows/steps/upsert-email-template.js +94 -0
  174. package/.medusa/server/src/workflows/steps/validate-email-provider-configuration.d.ts +20 -0
  175. package/.medusa/server/src/workflows/steps/validate-email-provider-configuration.js +58 -0
  176. package/.medusa/server/src/workflows/upsert-email-template.d.ts +15 -0
  177. package/.medusa/server/src/workflows/upsert-email-template.js +11 -0
  178. package/LICENSE +21 -0
  179. package/README.md +169 -2
  180. package/package.json +130 -4
@@ -0,0 +1,820 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const core = require("@react-email/editor/core");
5
+ const extensions = require("@react-email/editor/extensions");
6
+ const plugins = require("@react-email/editor/plugins");
7
+ const ui = require("@react-email/editor/ui");
8
+ require("@react-email/editor/themes/default.css");
9
+ const react = require("@tiptap/react");
10
+ const react$1 = require("react");
11
+ const variableNode = require("./variable-node-D2KY7H-p");
12
+ const __adminExtensions__ = require("./__admin-extensions__-Cu08yi-Z");
13
+ const state = require("@tiptap/pm/state");
14
+ const utils = require("@react-email/editor/utils");
15
+ const SAFE_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
16
+ const LIQUID = /\{\{[^{}]*\}\}/;
17
+ const SCHEME = /^([a-z][a-z0-9+.-]*):/i;
18
+ const isLiquidUrl = (value) => {
19
+ if (!LIQUID.test(value)) {
20
+ return false;
21
+ }
22
+ const scheme = SCHEME.exec(value.trim());
23
+ if (!scheme) {
24
+ return true;
25
+ }
26
+ return SAFE_PROTOCOLS.has(`${scheme[1].toLowerCase()}:`);
27
+ };
28
+ const stockUrl = (value) => {
29
+ if (value === "#") {
30
+ return value;
31
+ }
32
+ try {
33
+ const url = new URL(value);
34
+ return SAFE_PROTOCOLS.has(url.protocol) ? value : null;
35
+ } catch {
36
+ }
37
+ try {
38
+ if (value.includes(".") && !value.includes(" ")) {
39
+ return new URL(`https://${value}`).toString();
40
+ }
41
+ } catch {
42
+ }
43
+ return null;
44
+ };
45
+ const validateUrl = (value) => {
46
+ const trimmed = value.trim();
47
+ if (!trimmed) {
48
+ return null;
49
+ }
50
+ return isLiquidUrl(trimmed) ? trimmed : stockUrl(trimmed);
51
+ };
52
+ const WHOLE_EXPRESSION = /^\{\{\s*([^{}|\s]+)\s*(?:\|[^{}]*)?\}\}$/;
53
+ const wholeValueKey = (href) => WHOLE_EXPRESSION.exec(href.trim())?.[1] ?? null;
54
+ const addressWarning = (href, variables) => {
55
+ const key = wholeValueKey(href);
56
+ if (!key) {
57
+ return null;
58
+ }
59
+ const declared = variables.find((variable) => variable.key === key);
60
+ if (!declared) {
61
+ return `${key} is not a variable in this template.`;
62
+ }
63
+ return declared.type === "url" ? null : `${declared.label} is not marked as a link address.`;
64
+ };
65
+ const CUSTOM_ADDRESS = "";
66
+ const chosenVariableKey = (href, variables) => {
67
+ const key = wholeValueKey(href);
68
+ if (!key) {
69
+ return null;
70
+ }
71
+ const declared = variables.find((variable) => variable.key === key);
72
+ return declared?.type === "url" ? key : null;
73
+ };
74
+ const LinkFields = ({
75
+ href,
76
+ onCommit,
77
+ variables,
78
+ children
79
+ }) => {
80
+ const [collapsed, setCollapsed] = react$1.useState(false);
81
+ const [draft, setDraft] = react$1.useState(href);
82
+ const [committed, setCommitted] = react$1.useState(href);
83
+ const [choice, setChoice] = react$1.useState(
84
+ () => chosenVariableKey(href, variables) ?? CUSTOM_ADDRESS
85
+ );
86
+ if (href !== committed) {
87
+ setCommitted(href);
88
+ setDraft(href);
89
+ setChoice(chosenVariableKey(href, variables) ?? CUSTOM_ADDRESS);
90
+ }
91
+ const linkable = __adminExtensions__.urlVariables(variables);
92
+ const isCustom = choice === CUSTOM_ADDRESS;
93
+ const warning = isCustom ? addressWarning(draft, variables) : null;
94
+ const commit = (value) => {
95
+ const trimmed = value.trim();
96
+ if (!trimmed) {
97
+ onCommit(null);
98
+ return;
99
+ }
100
+ const validated = validateUrl(trimmed);
101
+ if (validated) {
102
+ onCommit(validated);
103
+ }
104
+ };
105
+ const chooseAddress = (next) => {
106
+ setChoice(next);
107
+ if (next === CUSTOM_ADDRESS) {
108
+ setDraft("");
109
+ return;
110
+ }
111
+ const expression = `{{ ${next} }}`;
112
+ setDraft(expression);
113
+ commit(expression);
114
+ };
115
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-section": "", "data-has-title": "", children: [
116
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "data-re-inspector-section-header": "", children: /* @__PURE__ */ jsxRuntime.jsx(
117
+ "button",
118
+ {
119
+ type: "button",
120
+ "data-re-inspector-section-toggle": "",
121
+ onClick: () => setCollapsed((value) => !value),
122
+ children: "Link"
123
+ }
124
+ ) }),
125
+ !collapsed && /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-section-body": "", children: [
126
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-prop-row": "", children: [
127
+ /* @__PURE__ */ jsxRuntime.jsx("label", { "data-re-inspector-label": "", htmlFor: "link-address", children: "Address" }),
128
+ /* @__PURE__ */ jsxRuntime.jsxs(
129
+ "select",
130
+ {
131
+ "data-re-inspector-select": "",
132
+ id: "link-address",
133
+ value: choice,
134
+ onChange: (event) => chooseAddress(event.target.value),
135
+ children: [
136
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: CUSTOM_ADDRESS, children: "Custom URL…" }),
137
+ linkable.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("option", { disabled: true, children: "No link variables" }) : __adminExtensions__.groupVariables(linkable).map(([group, grouped]) => /* @__PURE__ */ jsxRuntime.jsx("optgroup", { label: group, children: grouped.map((variable) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: variable.key, children: variable.label }, variable.key)) }, group))
138
+ ]
139
+ }
140
+ )
141
+ ] }),
142
+ isCustom && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
143
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "data-re-inspector-number": "", "data-link-url-control": "", children: /* @__PURE__ */ jsxRuntime.jsx(
144
+ "input",
145
+ {
146
+ "data-re-inspector-input": "",
147
+ "data-link-url": "",
148
+ id: "link-url",
149
+ type: "text",
150
+ "aria-label": "Link URL",
151
+ value: draft,
152
+ placeholder: "https://",
153
+ onChange: (event) => setDraft(event.target.value),
154
+ onBlur: (event) => commit(event.target.value),
155
+ onKeyDown: (event) => {
156
+ if (event.key === "Enter") {
157
+ event.preventDefault();
158
+ commit(draft);
159
+ }
160
+ }
161
+ }
162
+ ) }),
163
+ warning && /* @__PURE__ */ jsxRuntime.jsx(
164
+ "span",
165
+ {
166
+ "data-re-inspector-text": "",
167
+ "data-color": "muted",
168
+ className: "text-xs",
169
+ children: warning
170
+ }
171
+ )
172
+ ] }),
173
+ children
174
+ ] })
175
+ ] });
176
+ };
177
+ const ButtonLinkSection = ({
178
+ getAttr,
179
+ setAttr,
180
+ variables
181
+ }) => {
182
+ const raw = getAttr("href");
183
+ const href = typeof raw === "string" && raw !== "#" ? raw : "";
184
+ return /* @__PURE__ */ jsxRuntime.jsx(
185
+ LinkFields,
186
+ {
187
+ href,
188
+ variables,
189
+ onCommit: (next) => setAttr("href", next ?? "#")
190
+ }
191
+ );
192
+ };
193
+ const SHORT_HEX = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;
194
+ const LONG_HEX = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
195
+ const normalizeHex = (value) => {
196
+ const trimmed = value.trim();
197
+ const short = SHORT_HEX.exec(trimmed);
198
+ if (short) {
199
+ return `#${short[1]}${short[1]}${short[2]}${short[2]}${short[3]}${short[3]}`;
200
+ }
201
+ return LONG_HEX.test(trimmed) ? trimmed : "#000000";
202
+ };
203
+ const TextLinkSection = ({
204
+ linkHref,
205
+ linkColor,
206
+ setLinkColor,
207
+ variables
208
+ }) => {
209
+ const { editor } = react.useCurrentEditor();
210
+ if (!editor) {
211
+ return null;
212
+ }
213
+ const commit = (next) => {
214
+ if (!next) {
215
+ editor.chain().unsetLink().run();
216
+ return;
217
+ }
218
+ const { from, to } = editor.state.selection;
219
+ if (from === to) {
220
+ editor.chain().extendMarkRange("link").setLink({ href: next }).setTextSelection({ from, to }).run();
221
+ } else {
222
+ editor.chain().setLink({ href: next }).run();
223
+ }
224
+ };
225
+ return /* @__PURE__ */ jsxRuntime.jsx(LinkFields, { href: linkHref, variables, onCommit: commit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-prop-row": "", children: [
226
+ /* @__PURE__ */ jsxRuntime.jsx("label", { "data-re-inspector-label": "", htmlFor: "link-color", children: "Color" }),
227
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { "data-re-inspector-color-control": "", children: [
228
+ /* @__PURE__ */ jsxRuntime.jsx(
229
+ "input",
230
+ {
231
+ type: "color",
232
+ "data-re-inspector-color-trigger": "",
233
+ id: "link-color",
234
+ value: normalizeHex(linkColor),
235
+ onChange: (event) => setLinkColor(event.target.value)
236
+ }
237
+ ),
238
+ /* @__PURE__ */ jsxRuntime.jsx(
239
+ "input",
240
+ {
241
+ type: "text",
242
+ "data-re-inspector-color-hex": "",
243
+ "aria-label": "Link color",
244
+ value: linkColor,
245
+ onChange: (event) => setLinkColor(event.target.value)
246
+ }
247
+ )
248
+ ] })
249
+ ] }) });
250
+ };
251
+ const LinkTextInspector = ({
252
+ variables
253
+ }) => /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Text, { children: (context) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
254
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Typography, { ...context }),
255
+ context.isLinkActive && /* @__PURE__ */ jsxRuntime.jsx(TextLinkSection, { ...context, variables })
256
+ ] }) });
257
+ const REPEAT_ATTRIBUTE = "data-repeat";
258
+ const REPEAT_BODY_ATTRIBUTE = "data-repeat-body";
259
+ const UNSET_REPEAT_LABEL = "Choose what to repeat";
260
+ const FRAME_BASE = "my-2 rounded-md border border-dashed p-2";
261
+ const FRAME_TONES = {
262
+ chosen: "border-ui-border-strong",
263
+ attention: "border-ui-tag-orange-border"
264
+ };
265
+ const LABEL_BASE = "txt-compact-xsmall mb-1 cursor-default select-none";
266
+ const LABEL_TONES = {
267
+ chosen: "text-ui-fg-subtle",
268
+ attention: "text-ui-tag-orange-text"
269
+ };
270
+ const RepeatFrame = ({
271
+ node,
272
+ extension,
273
+ selected,
274
+ editor,
275
+ getPos
276
+ }) => {
277
+ const { variables } = extension.options;
278
+ const source = typeof node.attrs.source === "string" ? node.attrs.source : "";
279
+ const list = __adminExtensions__.listVariables(variables ?? []).find(
280
+ (entry) => entry.key === source
281
+ );
282
+ const tone = list ? "chosen" : "attention";
283
+ const label = !source ? UNSET_REPEAT_LABEL : list ? `Repeats for each: ${list.label}` : `Repeats for each: ${source} — not available for this event`;
284
+ return /* @__PURE__ */ jsxRuntime.jsxs(
285
+ react.NodeViewWrapper,
286
+ {
287
+ className: [
288
+ FRAME_BASE,
289
+ FRAME_TONES[tone],
290
+ selected ? "shadow-borders-focus" : ""
291
+ ].filter(Boolean).join(" "),
292
+ "data-repeat-frame": "",
293
+ "data-repeat-state": tone,
294
+ children: [
295
+ /* @__PURE__ */ jsxRuntime.jsx(
296
+ "div",
297
+ {
298
+ contentEditable: false,
299
+ className: `${LABEL_BASE} ${LABEL_TONES[tone]}`,
300
+ onMouseDown: (event) => {
301
+ const pos = getPos();
302
+ if (typeof pos !== "number") {
303
+ return;
304
+ }
305
+ event.preventDefault();
306
+ editor.chain().setNodeSelection(pos).focus().run();
307
+ },
308
+ children: label
309
+ }
310
+ ),
311
+ /* @__PURE__ */ jsxRuntime.jsx(react.NodeViewContent, {})
312
+ ]
313
+ }
314
+ );
315
+ };
316
+ const RepeatNode = core.EmailNode.create({
317
+ name: "repeat",
318
+ group: "block",
319
+ content: "block+",
320
+ isolating: true,
321
+ defining: true,
322
+ addOptions() {
323
+ return { variables: [] };
324
+ },
325
+ addAttributes() {
326
+ return {
327
+ source: {
328
+ default: null,
329
+ parseHTML: (element) => element.getAttribute(REPEAT_ATTRIBUTE),
330
+ renderHTML: (attributes) => ({
331
+ [REPEAT_ATTRIBUTE]: attributes.source
332
+ })
333
+ }
334
+ };
335
+ },
336
+ addCommands() {
337
+ return {
338
+ setRepeat: ({ source, content }) => ({ state: state2, commands }) => {
339
+ const { $from } = state2.selection;
340
+ for (let depth = $from.depth; depth > 0; depth--) {
341
+ if ($from.node(depth).type.name === this.name) {
342
+ return false;
343
+ }
344
+ }
345
+ return commands.insertContent({
346
+ type: this.name,
347
+ attrs: { source },
348
+ content: content.length ? content : [{ type: "paragraph" }]
349
+ });
350
+ }
351
+ };
352
+ },
353
+ addNodeView() {
354
+ return react.ReactNodeViewRenderer(RepeatFrame);
355
+ },
356
+ parseHTML() {
357
+ return [
358
+ {
359
+ tag: `div[${REPEAT_ATTRIBUTE}]`,
360
+ // Beats the library's `div` rule, which would leave the loop tags as text.
361
+ priority: 1e3,
362
+ // Read only the body, skipping the loop tags around it. Falls back to
363
+ // the element for HTML without a body (e.g. hand-written).
364
+ contentElement: (element) => element.querySelector(
365
+ `:scope > [${REPEAT_BODY_ATTRIBUTE}]`
366
+ ) ?? element
367
+ }
368
+ ];
369
+ },
370
+ renderHTML({ HTMLAttributes }) {
371
+ return ["div", HTMLAttributes, ["div", { [REPEAT_BODY_ATTRIBUTE]: "" }, 0]];
372
+ },
373
+ renderToReactEmail({ node, children }) {
374
+ const source = typeof node.attrs?.source === "string" ? node.attrs.source.trim() : "";
375
+ if (!source) {
376
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
377
+ }
378
+ const { open, close } = __adminExtensions__.toLiquidLoop(source);
379
+ const outer = { [REPEAT_ATTRIBUTE]: source };
380
+ const body = { [REPEAT_BODY_ATTRIBUTE]: "" };
381
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...outer, children: [
382
+ open,
383
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ...body, children }),
384
+ close
385
+ ] });
386
+ }
387
+ });
388
+ const presetFor = (list, extensions2) => {
389
+ if (!list.itemTemplate) {
390
+ return [];
391
+ }
392
+ try {
393
+ return variableNode.deriveEditorContent(list.itemTemplate, extensions2).content ?? [];
394
+ } catch {
395
+ return [];
396
+ }
397
+ };
398
+ const repeatSlashCommands = (variables) => __adminExtensions__.listVariables(variables).map((list) => ({
399
+ title: list.label,
400
+ description: `Repeat content once for each entry in ${list.label.toLowerCase()}`,
401
+ icon: /* @__PURE__ */ jsxRuntime.jsx(ui.ListIcon, { size: 20 }),
402
+ category: "Content",
403
+ searchTerms: ["repeat", "loop", "list", "each", list.key],
404
+ command: ({ editor, range }) => {
405
+ editor.chain().focus().deleteRange(range).setRepeat({
406
+ source: list.key,
407
+ content: presetFor(list, editor.extensionManager.extensions)
408
+ }).run();
409
+ }
410
+ }));
411
+ const snippetSlashCommands = (snippets) => snippets.map((snippet) => ({
412
+ title: snippet.label,
413
+ description: snippet.description ?? `Insert ${snippet.label.toLowerCase()}`,
414
+ icon: /* @__PURE__ */ jsxRuntime.jsx(ui.LayoutIcon, { size: 20 }),
415
+ category: "Content",
416
+ searchTerms: [
417
+ "snippet",
418
+ "preset",
419
+ snippet.key,
420
+ ...snippet.label.split(" ")
421
+ ],
422
+ command: ({ editor, range }) => {
423
+ let content;
424
+ try {
425
+ content = variableNode.deriveEditorContent(snippet.html, editor.extensionManager.extensions).content ?? [];
426
+ } catch {
427
+ content = [];
428
+ }
429
+ editor.chain().focus().deleteRange(range).insertContent(content).run();
430
+ }
431
+ }));
432
+ const claimLinkShortcut = (_view, event) => {
433
+ if (event.key === "k" && (event.metaKey || event.ctrlKey)) {
434
+ event.stopPropagation();
435
+ }
436
+ return false;
437
+ };
438
+ const variableBubbleMenuKey = new state.PluginKey("variableBubbleMenu");
439
+ const isVariableSelected = ({ state: state$1 }) => state$1.selection instanceof state.NodeSelection && state$1.selection.node.type.name === "variable" && !state$1.selection.node.marks.some((mark) => mark.type.name === "link");
440
+ const VariableBubbleMenu = () => /* @__PURE__ */ jsxRuntime.jsxs(
441
+ ui.BubbleMenu.Root,
442
+ {
443
+ trigger: isVariableSelected,
444
+ pluginKey: variableBubbleMenuKey,
445
+ children: [
446
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.BubbleMenu.ItemGroup, { children: [
447
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.Bold, {}),
448
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.Italic, {}),
449
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.Underline, {}),
450
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.Strike, {}),
451
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.Uppercase, {})
452
+ ] }),
453
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.BubbleMenu.ItemGroup, { children: [
454
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.AlignLeft, {}),
455
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.AlignCenter, {}),
456
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.AlignRight, {})
457
+ ] })
458
+ ]
459
+ }
460
+ );
461
+ const SECTIONS_BY_NODE = {
462
+ image: ["attributes", "size", "padding", "border"],
463
+ button: ["link", "typography", "size", "padding", "border", "background"],
464
+ section: ["background", "padding", "border"],
465
+ div: ["background", "padding", "border"],
466
+ codeBlock: ["attributes", "padding", "border"],
467
+ footer: ["typography", "padding", "background"],
468
+ twoColumns: [
469
+ "columnSpacing",
470
+ "typography",
471
+ "padding",
472
+ "background",
473
+ "border"
474
+ ],
475
+ threeColumns: [
476
+ "columnSpacing",
477
+ "typography",
478
+ "padding",
479
+ "background",
480
+ "border"
481
+ ],
482
+ fourColumns: [
483
+ "columnSpacing",
484
+ "typography",
485
+ "padding",
486
+ "background",
487
+ "border"
488
+ ]
489
+ };
490
+ const FALLBACK_SECTIONS = [
491
+ "typography",
492
+ "padding",
493
+ "background",
494
+ "border"
495
+ ];
496
+ const DefaultSections = ({
497
+ context,
498
+ variables
499
+ }) => {
500
+ const sections = SECTIONS_BY_NODE[context.nodeType] ?? FALLBACK_SECTIONS;
501
+ const textContext = context;
502
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: sections.map((section) => {
503
+ switch (section) {
504
+ case "attributes":
505
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Attributes, { ...context }, section);
506
+ case "link":
507
+ return /* @__PURE__ */ jsxRuntime.jsx(
508
+ ButtonLinkSection,
509
+ {
510
+ ...context,
511
+ variables
512
+ },
513
+ section
514
+ );
515
+ case "size":
516
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Size, { ...context }, section);
517
+ case "typography":
518
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Typography, { ...textContext }, section);
519
+ case "padding":
520
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Padding, { ...context }, section);
521
+ case "columnSpacing":
522
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.ColumnSpacing, { ...context }, section);
523
+ case "background":
524
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Background, { ...context }, section);
525
+ case "border":
526
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Border, { ...context }, section);
527
+ default:
528
+ return null;
529
+ }
530
+ }) });
531
+ };
532
+ const VariableSection = ({
533
+ getAttr,
534
+ setAttr,
535
+ nodePos,
536
+ variables: declared
537
+ }) => {
538
+ const { editor } = react.useCurrentEditor();
539
+ const variables = editor ? __adminExtensions__.variablesAt(editor.state.doc, nodePos.pos, declared) : __adminExtensions__.scalarVariables(declared);
540
+ const [collapsed, setCollapsed] = react$1.useState(false);
541
+ const rawKey = getAttr("key");
542
+ const key = typeof rawKey === "string" ? rawKey : "";
543
+ const rawFormat = getAttr("format");
544
+ const format = __adminExtensions__.isVariableFormat(rawFormat) ? rawFormat : "text";
545
+ const chosen = variables.find((entry) => entry.key === key);
546
+ const formats = __adminExtensions__.formatsFor(chosen);
547
+ const chooseVariable = (nextKey) => {
548
+ const next = variables.find((entry) => entry.key === nextKey);
549
+ const attrs = __adminExtensions__.attributesFor(next);
550
+ setAttr("key", attrs.key);
551
+ setAttr("format", attrs.format);
552
+ setAttr("currencySource", attrs.currencySource);
553
+ };
554
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-section": "", "data-has-title": "", children: [
555
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "data-re-inspector-section-header": "", children: /* @__PURE__ */ jsxRuntime.jsx(
556
+ "button",
557
+ {
558
+ type: "button",
559
+ "data-re-inspector-section-toggle": "",
560
+ onClick: () => setCollapsed((value) => !value),
561
+ children: "Attributes"
562
+ }
563
+ ) }),
564
+ !collapsed && /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-section-body": "", children: [
565
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-prop-row": "", children: [
566
+ /* @__PURE__ */ jsxRuntime.jsx("label", { "data-re-inspector-label": "", htmlFor: "variable", children: "Variable" }),
567
+ /* @__PURE__ */ jsxRuntime.jsxs(
568
+ "select",
569
+ {
570
+ "data-re-inspector-select": "",
571
+ id: "variable",
572
+ value: key,
573
+ onChange: (event) => chooseVariable(event.target.value),
574
+ children: [
575
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: "Choose a variable" }),
576
+ __adminExtensions__.groupVariables(variables).map(([group, grouped]) => /* @__PURE__ */ jsxRuntime.jsx("optgroup", { label: group, children: grouped.map((variable) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: variable.key, children: variable.label }, variable.key)) }, group))
577
+ ]
578
+ }
579
+ )
580
+ ] }),
581
+ formats.length > 1 && /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-prop-row": "", children: [
582
+ /* @__PURE__ */ jsxRuntime.jsx("label", { "data-re-inspector-label": "", htmlFor: "variable-format", children: "Format" }),
583
+ /* @__PURE__ */ jsxRuntime.jsx(
584
+ "select",
585
+ {
586
+ "data-re-inspector-select": "",
587
+ id: "variable-format",
588
+ value: format,
589
+ onChange: (event) => setAttr("format", event.target.value),
590
+ children: formats.map((option) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: option, children: __adminExtensions__.FORMAT_LABELS[option] }, option))
591
+ }
592
+ )
593
+ ] })
594
+ ] })
595
+ ] });
596
+ };
597
+ const FORMAT_MARKS = ["bold", "italic", "underline", "strike", "code"];
598
+ const VariableTypography = ({ context }) => {
599
+ const { editor } = react.useCurrentEditor();
600
+ const marks = react.useEditorState({
601
+ editor,
602
+ selector: ({ editor: current }) => Object.fromEntries(
603
+ FORMAT_MARKS.map((mark) => [mark, current?.isActive(mark) ?? false])
604
+ )
605
+ }) ?? {};
606
+ const alignment = react.useEditorState({
607
+ editor,
608
+ selector: ({ editor: current }) => current ? utils.getSelectionAlignment(current) : "left"
609
+ }) ?? "left";
610
+ if (!editor) {
611
+ return null;
612
+ }
613
+ return /* @__PURE__ */ jsxRuntime.jsx(
614
+ ui.Inspector.Typography,
615
+ {
616
+ ...context,
617
+ getStyle: context.getStyle,
618
+ setStyle: context.setStyle,
619
+ marks,
620
+ toggleMark: (mark) => editor.chain().focus().toggleMark(mark).run(),
621
+ alignment,
622
+ setAlignment: (value) => utils.setTextAlignment(editor, value)
623
+ }
624
+ );
625
+ };
626
+ const RepeatSection = ({
627
+ getAttr,
628
+ setAttr,
629
+ variables
630
+ }) => {
631
+ const [collapsed, setCollapsed] = react$1.useState(false);
632
+ const rawSource = getAttr("source");
633
+ const source = typeof rawSource === "string" ? rawSource : "";
634
+ const lists = __adminExtensions__.listVariables(variables);
635
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-section": "", "data-has-title": "", children: [
636
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "data-re-inspector-section-header": "", children: /* @__PURE__ */ jsxRuntime.jsx(
637
+ "button",
638
+ {
639
+ type: "button",
640
+ "data-re-inspector-section-toggle": "",
641
+ onClick: () => setCollapsed((value) => !value),
642
+ children: "Attributes"
643
+ }
644
+ ) }),
645
+ !collapsed && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-re-inspector-section-body": "", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-re-inspector-prop-row": "", children: [
646
+ /* @__PURE__ */ jsxRuntime.jsx("label", { "data-re-inspector-label": "", htmlFor: "repeat-source", children: "Repeat for each" }),
647
+ /* @__PURE__ */ jsxRuntime.jsxs(
648
+ "select",
649
+ {
650
+ "data-re-inspector-select": "",
651
+ id: "repeat-source",
652
+ value: source,
653
+ onChange: (event) => setAttr("source", event.target.value),
654
+ children: [
655
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: "Choose a list" }),
656
+ source && !lists.some((list) => list.key === source) && /* @__PURE__ */ jsxRuntime.jsx("option", { value: source, children: source }),
657
+ lists.map((list) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: list.key, children: list.label }, list.key))
658
+ ]
659
+ }
660
+ )
661
+ ] }) })
662
+ ] });
663
+ };
664
+ const VariableInspector = ({
665
+ variables
666
+ }) => /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Node, { children: (context) => context.nodeType === "variable" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
667
+ /* @__PURE__ */ jsxRuntime.jsx(VariableSection, { ...context, variables }),
668
+ /* @__PURE__ */ jsxRuntime.jsx(VariableTypography, { context })
669
+ ] }) : context.nodeType === "repeat" ? /* @__PURE__ */ jsxRuntime.jsx(RepeatSection, { ...context, variables }) : /* @__PURE__ */ jsxRuntime.jsx(DefaultSections, { context, variables }) });
670
+ const variableSlashCommand = (variables) => ({
671
+ title: "Variable",
672
+ description: variables.length ? "Insert a value such as the order number or customer name" : "No variables are available for this template",
673
+ icon: /* @__PURE__ */ jsxRuntime.jsx(ui.TypeIcon, { size: 20 }),
674
+ category: "Content",
675
+ searchTerms: ["variable", "merge", "field", "placeholder", "value"],
676
+ command: ({ editor, range }) => {
677
+ editor.chain().focus().deleteRange(range).setVariable().run();
678
+ }
679
+ });
680
+ const InspectorBreadcrumb = ui.Inspector.Breadcrumb;
681
+ const EMAIL_THEME = plugins.extendTheme("basic", {
682
+ body: { backgroundColor: variableNode.EMAIL_DESIGN.pageBackground },
683
+ container: {
684
+ backgroundColor: variableNode.EMAIL_DESIGN.cardBackground,
685
+ color: variableNode.EMAIL_DESIGN.textColor,
686
+ width: variableNode.EMAIL_DESIGN.cardWidth,
687
+ borderRadius: variableNode.EMAIL_DESIGN.cardRadius,
688
+ margin: variableNode.CARD_MARGIN,
689
+ /*
690
+ * Both forms are needed. The export reads the longhands (the theme's
691
+ * defaults are longhand zeros). The Inspector reads only `padding`;
692
+ * without it the panel shows the global default of 8 and editing it would
693
+ * write a shorthand over the longhands.
694
+ */
695
+ padding: variableNode.EMAIL_DESIGN.cardPadding,
696
+ paddingTop: variableNode.EMAIL_DESIGN.cardPadding,
697
+ paddingRight: variableNode.EMAIL_DESIGN.cardPadding,
698
+ paddingBottom: variableNode.EMAIL_DESIGN.cardPadding,
699
+ paddingLeft: variableNode.EMAIL_DESIGN.cardPadding
700
+ }
701
+ });
702
+ const INSPECTOR_CLASS = [
703
+ "bg-ui-bg-base border-ui-border-base w-64 shrink-0 overflow-y-auto border-l p-4",
704
+ "[&_[data-re-inspector-input]]:bg-transparent [&_[data-re-inspector-input]]:border-0 [&_[data-re-inspector-input]]:min-w-0",
705
+ "[&_[data-re-inspector-color-hex]]:bg-transparent [&_[data-re-inspector-color-hex]]:border-0 [&_[data-re-inspector-color-hex]]:min-w-0",
706
+ "[&_[data-re-inspector-number]]:overflow-hidden [&_[data-re-inspector-color-control]]:overflow-hidden [&_[data-re-inspector-select]]:overflow-hidden",
707
+ "[&_[data-re-inspector-unit]]:text-xs [&_[data-re-inspector-unit]]:w-auto [&_[data-re-inspector-unit]]:h-auto [&_[data-re-inspector-unit]]:aspect-auto",
708
+ "[&_[data-link-url-control]]:w-full [&_[data-link-url-control]]:min-w-0",
709
+ "[&_[data-link-url]]:max-w-none [&_[data-link-url]]:w-full"
710
+ ].join(" ");
711
+ const CANVAS_CLASS = [
712
+ "p-6",
713
+ "[&_[data-type=container]]:mx-auto",
714
+ "[&_[data-editor-theme-scope]]:flow-root"
715
+ ].join(" ");
716
+ const EmailTemplateEditor = react$1.forwardRef(({ template, onDirty }, ref) => {
717
+ const extensions$1 = react$1.useMemo(
718
+ () => [
719
+ /*
720
+ * Allow Liquid hrefs such as `{{ invite_url }}`, which the stock check
721
+ * rejects for lacking a scheme. Everything else still goes through
722
+ * `ctx.defaultValidate`, so `javascript:` stays blocked.
723
+ */
724
+ extensions.StarterKit.configure({
725
+ Link: {
726
+ isAllowedUri: (url, ctx) => isLiquidUrl(url) || ctx.defaultValidate(url)
727
+ }
728
+ }),
729
+ plugins.EmailTheming.configure({ theme: EMAIL_THEME }),
730
+ variableNode.VariableNode.configure({ variables: template.variables }),
731
+ RepeatNode.configure({ variables: template.variables })
732
+ ],
733
+ [template.variables]
734
+ );
735
+ const sourceHtml = template.html_template ?? template.default_template.html;
736
+ const content = react$1.useMemo(() => {
737
+ if (template.editor_content) {
738
+ return template.editor_content;
739
+ }
740
+ try {
741
+ return variableNode.deriveEditorContent(sourceHtml, extensions$1);
742
+ } catch {
743
+ return "";
744
+ }
745
+ }, [template.editor_content, sourceHtml, extensions$1]);
746
+ const editor = react.useEditor({
747
+ extensions: extensions$1,
748
+ content,
749
+ immediatelyRender: true,
750
+ editorProps: { handleDOMEvents: { keydown: claimLinkShortcut } },
751
+ /*
752
+ * Seeding fires its own updates, so only changes after initialisation
753
+ * count as edits; otherwise the page opens dirty. `EmailTheming` seeds
754
+ * synchronously, before TipTap sets `isInitialized`.
755
+ *
756
+ * Not `isFocused`: Inspector edits happen while focus is in the panel, and
757
+ * they must still mark the page dirty.
758
+ */
759
+ onUpdate: ({ editor: instance, transaction }) => {
760
+ if (transaction.docChanged && instance.isEditable && instance.isInitialized) {
761
+ onDirty();
762
+ }
763
+ }
764
+ });
765
+ react$1.useImperativeHandle(
766
+ ref,
767
+ () => ({
768
+ getBody: async () => {
769
+ if (!editor) {
770
+ throw new Error("The editor is still loading.");
771
+ }
772
+ const composed = await core.composeReactEmail({ editor });
773
+ return {
774
+ // Not `html`: its Prettier formatting bloats nested tables for no
775
+ // benefit in a mail client.
776
+ html_template: composed.unformattedHtml,
777
+ editor_content: editor.getJSON()
778
+ };
779
+ }
780
+ }),
781
+ [editor]
782
+ );
783
+ const slashCommands = react$1.useMemo(
784
+ () => [
785
+ ...ui.defaultSlashCommands,
786
+ variableSlashCommand(template.variables),
787
+ ...repeatSlashCommands(template.variables),
788
+ ...snippetSlashCommands(template.snippets)
789
+ ],
790
+ [template.variables, template.snippets]
791
+ );
792
+ if (!editor) {
793
+ return null;
794
+ }
795
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.EditorContext.Provider, { value: { editor }, children: [
796
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-[32rem]", children: [
797
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(react.EditorContent, { editor, className: CANVAS_CLASS }) }),
798
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Inspector.Root, { className: INSPECTOR_CLASS, children: [
799
+ /* @__PURE__ */ jsxRuntime.jsx(InspectorBreadcrumb, {}),
800
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Inspector.Document, {}),
801
+ /* @__PURE__ */ jsxRuntime.jsx(VariableInspector, { variables: template.variables }),
802
+ /* @__PURE__ */ jsxRuntime.jsx(LinkTextInspector, { variables: template.variables })
803
+ ] })
804
+ ] }),
805
+ /* @__PURE__ */ jsxRuntime.jsx(
806
+ ui.BubbleMenu,
807
+ {
808
+ hideWhenActiveNodes: ["button", "variable"],
809
+ hideWhenActiveMarks: ["link"]
810
+ }
811
+ ),
812
+ /* @__PURE__ */ jsxRuntime.jsx(VariableBubbleMenu, {}),
813
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.LinkDefault, { validateUrl }),
814
+ /* @__PURE__ */ jsxRuntime.jsx(ui.BubbleMenu.ButtonDefault, { validateUrl }),
815
+ /* @__PURE__ */ jsxRuntime.jsx(ui.SlashCommand, { items: slashCommands })
816
+ ] });
817
+ });
818
+ EmailTemplateEditor.displayName = "EmailTemplateEditor";
819
+ exports.EMAIL_THEME = EMAIL_THEME;
820
+ exports.default = EmailTemplateEditor;