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