@trycourier/react-designer 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/index.js +68 -57
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/styles.css +820 -94
- package/dist/components/Providers/TemplateProvider.d.ts +9 -0
- package/dist/components/Providers/store.d.ts +11 -0
- package/dist/components/TemplateEditor/Channels/Email/Email.d.ts +12 -2
- package/dist/components/TemplateEditor/Channels/Email/EmailLayout.d.ts +3 -1
- package/dist/components/TemplateEditor/Channels/Inbox/InboxLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Inbox/SideBar/useInboxButtonSync.d.ts +27 -0
- package/dist/components/TemplateEditor/Channels/MSTeams/MSTeamsLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Push/PushLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/SMS/SMSLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/Channels/Slack/SlackLayout.d.ts +1 -1
- package/dist/components/TemplateEditor/TemplateEditor.d.ts +17 -0
- package/dist/components/TemplateEditor/hooks/index.d.ts +1 -0
- package/dist/components/TemplateEditor/hooks/useEmailBackgroundColors.d.ts +9 -0
- package/dist/components/TemplateEditor/hooks/useEmailFontFamily.d.ts +10 -0
- package/dist/components/TemplateEditor/hooks/useFonts.d.ts +4 -0
- package/dist/components/TemplateEditor/hooks/useGoogleFontLoader.d.ts +5 -0
- package/dist/components/TemplateEditor/index.d.ts +1 -1
- package/dist/components/TemplateEditor/store.d.ts +17 -0
- package/dist/components/TranslationEditor/TranslationEditor.d.ts +17 -0
- package/dist/components/TranslationEditor/index.d.ts +1 -0
- package/dist/components/extensions/Button/Button.types.d.ts +2 -2
- package/dist/components/extensions/Button/inboxButtonStyle.d.ts +65 -0
- package/dist/components/extensions/ButtonRow/ButtonRow.types.d.ts +4 -0
- package/dist/components/extensions/Color/Color.d.ts +14 -0
- package/dist/components/extensions/ColumnCell/ColumnCell.types.d.ts +32 -0
- package/dist/components/extensions/{CustomCode/CustomCodeForm.d.ts → ColumnCell/ColumnCellForm.d.ts} +2 -2
- package/dist/components/extensions/ColumnCell/index.d.ts +2 -0
- package/dist/components/extensions/HTML/HTML.d.ts +11 -0
- package/dist/components/extensions/{CustomCode/CustomCode.types.d.ts → HTML/HTML.types.d.ts} +2 -2
- package/dist/components/extensions/HTML/HTMLComponent.d.ts +9 -0
- package/dist/components/extensions/HTML/HTMLForm.d.ts +9 -0
- package/dist/components/extensions/HTML/index.d.ts +6 -0
- package/dist/components/extensions/Link/LinkBubble.d.ts +1 -0
- package/dist/components/extensions/List/List.types.d.ts +5 -0
- package/dist/components/extensions/index.d.ts +3 -2
- package/dist/components/extensions/shared/conditionalAttribute.d.ts +19 -0
- package/dist/components/hooks/useVariables.d.ts +12 -7
- package/dist/components/ui/Blocks/HTMLBlock/HTMLBlock.d.ts +3 -0
- package/dist/components/ui/Blocks/HTMLBlock/index.d.ts +1 -0
- package/dist/components/ui/Blocks/index.d.ts +1 -1
- package/dist/components/ui/Conditions/ConditionGroupRow.d.ts +12 -0
- package/dist/components/ui/Conditions/ConditionRow.d.ts +11 -0
- package/dist/components/ui/Conditions/Conditions.d.ts +9 -0
- package/dist/components/ui/Conditions/ConditionsSection.d.ts +18 -0
- package/dist/components/ui/Conditions/index.d.ts +3 -0
- package/dist/components/ui/Conditions/useConditions.d.ts +13 -0
- package/dist/components/ui/ContentIcon/ContentIcon.d.ts +1 -1
- package/dist/components/ui/MainLayout/MainLayout.d.ts +1 -0
- package/dist/components/ui/TextMenu/components/TextColorButton.d.ts +6 -0
- package/dist/components/ui/TextMenu/config.d.ts +1 -0
- package/dist/components/ui/TextMenu/hooks/useTextmenuCommands.d.ts +2 -0
- package/dist/components/ui/TextMenu/hooks/useTextmenuStates.d.ts +1 -0
- package/dist/components/ui/Tooltip/types.d.ts +1 -1
- package/dist/components/ui/VariableEditor/VariableChipBase.d.ts +2 -0
- package/dist/components/ui-kit/Button/Button.d.ts +2 -2
- package/dist/components/ui-kit/FontSelect/FontSelect.d.ts +9 -0
- package/dist/components/ui-kit/FontSelect/index.d.ts +1 -0
- package/dist/components/ui-kit/Form/Form.d.ts +2 -1
- package/dist/components/ui-kit/InputColor/ColorPicker.d.ts +2 -1
- package/dist/components/ui-kit/InputColor/InputColor.d.ts +4 -1
- package/dist/components/ui-kit/PrefixInput/PrefixInput.d.ts +30 -0
- package/dist/components/ui-kit/PrefixInput/index.d.ts +2 -0
- package/dist/components/ui-kit/index.d.ts +2 -0
- package/dist/components/utils/resolveDataPath.d.ts +13 -0
- package/dist/components/utils/validateVariableName.d.ts +5 -2
- package/dist/esm/index.js +68 -57
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/styles.css +820 -94
- package/dist/hooks/useLocalization.d.ts +30 -0
- package/dist/index.d.ts +16 -4
- package/dist/lib/utils/brandColors.d.ts +15 -0
- package/dist/lib/utils/extractTextFields.d.ts +60 -0
- package/dist/lib/utils/fontFamily.d.ts +23 -0
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/styles.css +820 -94
- package/dist/types/conditions.types.d.ts +21 -0
- package/dist/types/elemental.types.d.ts +67 -2
- package/dist/types/font.types.d.ts +8 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/validation.types.d.ts +15 -3
- package/package.json +6 -1
- package/dist/components/extensions/CustomCode/CustomCode.d.ts +0 -11
- package/dist/components/extensions/CustomCode/CustomCodeComponent.d.ts +0 -9
- package/dist/components/extensions/CustomCode/index.d.ts +0 -6
- package/dist/components/ui/Blocks/CustomCodeBlock/CustomCodeBlock.d.ts +0 -3
- package/dist/components/ui/Blocks/CustomCodeBlock/index.d.ts +0 -1
- /package/dist/components/extensions/{CustomCode → HTML}/MonacoCodeEditor.d.ts +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type TranslatableField } from "@/lib/utils/extractTextFields";
|
|
2
|
+
import type { ElementalContent } from "@/types";
|
|
3
|
+
export type { TranslatableField };
|
|
4
|
+
export interface UseLocalizationOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Called when the content should be persisted to the server.
|
|
7
|
+
* The consumer provides this so they can use their own save mechanism
|
|
8
|
+
* (e.g. Apollo Client mutation in CDS).
|
|
9
|
+
*/
|
|
10
|
+
onSave: (content: ElementalContent) => Promise<void>;
|
|
11
|
+
/** Debounce interval in ms (default 500). */
|
|
12
|
+
debounceMs?: number;
|
|
13
|
+
/** Callback when a save fails. */
|
|
14
|
+
onError?: (error: unknown) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface UseLocalizationResult {
|
|
17
|
+
fields: TranslatableField[];
|
|
18
|
+
/**
|
|
19
|
+
* Update a locale translation for a specific field.
|
|
20
|
+
* Empty value removes the locale entry; non-empty adds/replaces it.
|
|
21
|
+
* Automatically triggers a debounced save via the provided onSave.
|
|
22
|
+
*/
|
|
23
|
+
setTranslation: (fieldId: string, localeCode: string, value: string) => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns all translatable text fields extracted from the current template content,
|
|
27
|
+
* plus a `setTranslation` method to persist locale changes back to the atom
|
|
28
|
+
* and auto-save via the consumer-provided `onSave` callback.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useLocalization({ onSave, debounceMs, onError, }: UseLocalizationOptions): UseLocalizationResult;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,22 +2,34 @@ export * from "./components/TemplateEditor";
|
|
|
2
2
|
export * from "./components/BrandEditor";
|
|
3
3
|
export * from "./components/Providers";
|
|
4
4
|
export * from "./components/hooks";
|
|
5
|
-
export type { VariableValidationConfig } from "./types/validation.types";
|
|
5
|
+
export type { VariableValidationConfig, VariableValidationContext } from "./types/validation.types";
|
|
6
|
+
export type { FontEntry, FontProvider } from "./types/font.types";
|
|
6
7
|
export * from "./lib/utils/errors";
|
|
7
8
|
export * from "./components/ui-kit/ErrorBoundary";
|
|
8
9
|
export { CHANNELS } from "@/channels";
|
|
9
10
|
export type { ChannelType } from "@/store";
|
|
10
11
|
export type { ElementalContent } from "@/types";
|
|
11
12
|
export { PreviewPanel } from "@/components/ui/PreviewPanel";
|
|
13
|
+
export { Tooltip } from "@/components/ui/Tooltip";
|
|
12
14
|
export { TextMenu } from "@/components/ui/TextMenu";
|
|
13
15
|
export { VariableInput, VariableTextarea } from "@/components/ui/VariableEditor";
|
|
14
16
|
export { getFlattenedVariables } from "@/components/utils/getFlattenedVariables";
|
|
15
17
|
export { Status as TemplateStatus } from "@/components/ui/Status";
|
|
16
|
-
export { ToggleGroup, ToggleGroupItem, Toggle, Divider, Input, InputColor, } from "@/components/ui-kit";
|
|
18
|
+
export { ToggleGroup, ToggleGroupItem, Toggle, Divider, Input, InputColor, DEFAULT_PRESET_COLORS, FontSelect, Tabs, TabsList, TabsTrigger, TabsContent, } from "@/components/ui-kit";
|
|
19
|
+
export { ThemeProvider, useTheme } from "@/components/ui-kit/ThemeProvider";
|
|
20
|
+
export { defaultTheme, lightTheme, darkTheme, } from "@/components/ui-kit/ThemeProvider/ThemeProvider.types";
|
|
21
|
+
export type { Theme } from "@/components/ui-kit/ThemeProvider/ThemeProvider.types";
|
|
17
22
|
export { FacebookIcon, InstagramIcon, LinkedinIcon, MediumIcon, XIcon, } from "@/components/ui-kit/Icon";
|
|
18
|
-
export { cn, convertElementalToTiptap, convertTiptapToElemental } from "@/lib/utils";
|
|
23
|
+
export { cn, convertElementalToTiptap, convertTiptapToElemental, parseFontFamily, buildFontFamily, } from "@/lib/utils";
|
|
19
24
|
export { blockDefaults } from "@/lib/constants/block-defaults";
|
|
20
25
|
export { EMAIL_EDITOR_TEXT_STYLES, EMAIL_EDITOR_FONT_FAMILY, } from "@/lib/constants/email-editor-tiptap-styles";
|
|
21
26
|
export { useAutoSave } from "@/hooks/useAutoSave";
|
|
22
|
-
export {
|
|
27
|
+
export { useLocalization } from "@/hooks/useLocalization";
|
|
28
|
+
export type { TranslatableField, UseLocalizationOptions, UseLocalizationResult, } from "@/hooks/useLocalization";
|
|
29
|
+
export { extractExistingLocales, extractTextFields, updateLocaleTranslation, updateLocaleTranslationWithElements, } from "@/lib/utils/extractTextFields";
|
|
30
|
+
export { useGoogleFontLoader } from "@/components/TemplateEditor/hooks/useGoogleFontLoader";
|
|
31
|
+
export { TranslationEditor } from "@/components/TranslationEditor";
|
|
32
|
+
export type { TranslationEditorProps } from "@/components/TranslationEditor";
|
|
33
|
+
export { convertElementsArrayToTiptapNodes } from "@/lib/utils/convertElementalToTiptap/convertElementalToTiptap";
|
|
34
|
+
export { MonacoCodeEditor } from "@/components/extensions/HTML/MonacoCodeEditor";
|
|
23
35
|
export { applyShadowDomDndFix } from "@/components/utils/shadowDomDndFix";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type BrandColorKey = "primary" | "secondary" | "tertiary";
|
|
2
|
+
export interface BrandColor {
|
|
3
|
+
key: BrandColorKey;
|
|
4
|
+
hex: string;
|
|
5
|
+
ref: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function isBrandColorRef(value: string): boolean;
|
|
8
|
+
export declare function parseBrandColorRef(value: string): BrandColorKey | null;
|
|
9
|
+
export declare function makeBrandColorRef(key: BrandColorKey): string;
|
|
10
|
+
export declare const BRAND_COLOR_LABELS: Record<BrandColorKey, string>;
|
|
11
|
+
export declare function getBrandColorLabel(value: string): string | null;
|
|
12
|
+
export declare function brandColorRefToCSSVar(ref: string): string;
|
|
13
|
+
export declare function brandColorsToCSSVars(brandColors: BrandColor[]): Record<string, string>;
|
|
14
|
+
export declare function resolveBrandColor(value: string, brandColorMap: Record<string, string>): string;
|
|
15
|
+
export declare function useBrandColorResolver(): (color: string) => string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ElementalContent, ElementalTextContentNode, TextStyle } from "@/types/elemental.types";
|
|
2
|
+
/**
|
|
3
|
+
* FNV-1a hash — fast, non-crypto, good distribution for short strings.
|
|
4
|
+
* Returns a compact base-36 string.
|
|
5
|
+
*/
|
|
6
|
+
export declare function fnv1aHash(str: string): string;
|
|
7
|
+
export interface TranslatableField {
|
|
8
|
+
/** Stable path-based identifier, e.g. "email.0.content" or "email.raw.subject" */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Channel this field belongs to (e.g. "email", "sms", "push") */
|
|
11
|
+
channel: string;
|
|
12
|
+
/** Elemental node type: "text", "action", "quote", "meta" */
|
|
13
|
+
nodeType: string;
|
|
14
|
+
/** Text style hint for text nodes (h1, h2, h3, text, subtext) */
|
|
15
|
+
textStyle?: TextStyle;
|
|
16
|
+
/** The default/source locale text content */
|
|
17
|
+
content: string;
|
|
18
|
+
/** Raw Elemental inline elements for rich text nodes (preserves formatting) */
|
|
19
|
+
elements?: ElementalTextContentNode[];
|
|
20
|
+
/** Existing locale translations keyed by locale code */
|
|
21
|
+
locales: Record<string, string>;
|
|
22
|
+
/** Existing locale translations with rich elements, keyed by locale code */
|
|
23
|
+
localeElements?: Record<string, ElementalTextContentNode[]>;
|
|
24
|
+
/** Locale codes whose translation was made against a different source text */
|
|
25
|
+
staleLocales?: Set<string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extract all translatable text fields from an ElementalContent tree.
|
|
29
|
+
*
|
|
30
|
+
* Walks each channel's element subtree and collects text from:
|
|
31
|
+
* - text nodes (paragraphs, headings)
|
|
32
|
+
* - action nodes (button labels)
|
|
33
|
+
* - quote nodes
|
|
34
|
+
* - meta nodes (titles / email subjects)
|
|
35
|
+
* - channel raw fields (subject, title, text)
|
|
36
|
+
*
|
|
37
|
+
* Skips image alt_text, html content, dividers, and comments.
|
|
38
|
+
*/
|
|
39
|
+
export declare function extractTextFields(content: ElementalContent | null | undefined): TranslatableField[];
|
|
40
|
+
/**
|
|
41
|
+
* Collect all unique locale codes found across every translatable field in the content.
|
|
42
|
+
* Returns a sorted array of locale codes, e.g. ["de", "fr", "ja"].
|
|
43
|
+
*/
|
|
44
|
+
export declare function extractExistingLocales(content: ElementalContent | null | undefined): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Update a locale translation on a specific field in the Elemental content tree.
|
|
47
|
+
* Returns a new content object (immutable update).
|
|
48
|
+
*
|
|
49
|
+
* - Empty `value` removes the locale entry for that field.
|
|
50
|
+
* - Non-empty `value` adds or replaces the locale entry.
|
|
51
|
+
*/
|
|
52
|
+
export declare function updateLocaleTranslation(content: ElementalContent, fieldId: string, localeCode: string, value: string): ElementalContent;
|
|
53
|
+
/**
|
|
54
|
+
* Update a locale translation with rich elements on a specific field.
|
|
55
|
+
* Like `updateLocaleTranslation`, but stores `elements` (not `content`)
|
|
56
|
+
* on the locale entry — preserving inline formatting through AI translation.
|
|
57
|
+
*
|
|
58
|
+
* Only applicable to text nodes (not raw/meta/action/quote).
|
|
59
|
+
*/
|
|
60
|
+
export declare function updateLocaleTranslationWithElements(content: ElementalContent, fieldId: string, localeCode: string, elements: ElementalTextContentNode[]): ElementalContent;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a CSS font-family string into primary font and fallback stack.
|
|
3
|
+
*
|
|
4
|
+
* primary = first comma-separated token
|
|
5
|
+
* fallback = everything after the first token, joined back
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* "Roboto, sans-serif" → { primary: "Roboto", fallback: "sans-serif" }
|
|
9
|
+
* "Roboto, Georgia, serif" → { primary: "Roboto", fallback: "Georgia, serif" }
|
|
10
|
+
* "Helvetica, Arial, sans-serif" → { primary: "Helvetica", fallback: "Arial, sans-serif" }
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseFontFamily(fontFamily: string | null | undefined): {
|
|
13
|
+
primary: string;
|
|
14
|
+
fallback: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Build a CSS font-family string from a primary font and a fallback stack.
|
|
18
|
+
*
|
|
19
|
+
* Examples:
|
|
20
|
+
* buildFontFamily("Roboto", "sans-serif") → "Roboto, sans-serif"
|
|
21
|
+
* buildFontFamily("Roboto", "Georgia, serif") → "Roboto, Georgia, serif"
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildFontFamily(primary: string, fallback: string): string;
|