@cometchat/card-builder 2.0.2 → 2.0.3
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/dist/App.d.ts +1 -0
- package/dist/bridge/api.d.ts +79 -0
- package/dist/{assets/index-D9-G0mBH.css → card-builder.css} +1 -0
- package/dist/card-builder.es.js +24019 -0
- package/dist/card-builder.umd.js +20 -0
- package/dist/components/Canvas.d.ts +2 -0
- package/dist/components/CanvasViewToggle.d.ts +6 -0
- package/dist/components/CredentialsModal.d.ts +11 -0
- package/dist/components/EditorLayout.d.ts +2 -0
- package/dist/components/ElementTree.d.ts +2 -0
- package/dist/components/LeftPanel.d.ts +2 -0
- package/dist/components/NotificationPreview.d.ts +3 -0
- package/dist/components/RightPanel.d.ts +2 -0
- package/dist/components/ShortcutsPanel.d.ts +2 -0
- package/dist/components/TemplateLibrary.d.ts +2 -0
- package/dist/components/TopBar.d.ts +2 -0
- package/dist/components/properties/ActionEditor.d.ts +7 -0
- package/dist/components/properties/CardStyleEditor.d.ts +2 -0
- package/dist/components/properties/ElementPropertyEditor.d.ts +8 -0
- package/dist/components/properties/IconPicker.d.ts +7 -0
- package/dist/components/properties/NotificationEditor.d.ts +2 -0
- package/dist/components/properties/VariableEditor.d.ts +2 -0
- package/dist/components/properties/VariableInput.d.ts +10 -0
- package/dist/components/renderers/ElementRenderer.d.ts +20 -0
- package/dist/components/ui/Button.d.ts +8 -0
- package/dist/components/ui/ColorPicker.d.ts +30 -0
- package/dist/components/ui/EmptyState.d.ts +7 -0
- package/dist/components/ui/MaterialIcon.d.ts +9 -0
- package/dist/components/ui/Modal.d.ts +11 -0
- package/dist/config/app-credentials.d.ts +44 -0
- package/dist/config/builder-config.d.ts +56 -0
- package/dist/config/component-templates.d.ts +11 -0
- package/dist/config/element-defaults.d.ts +8 -0
- package/dist/config/icon-library.d.ts +11 -0
- package/dist/config/theme.d.ts +11 -0
- package/dist/config/uikit-theme.d.ts +73 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +1 -0
- package/dist/lib.d.ts +81 -0
- package/dist/store/builder-store.d.ts +128 -0
- package/dist/types/schema.d.ts +338 -0
- package/dist/utils/element-errors.d.ts +9 -0
- package/dist/utils/id.d.ts +4 -0
- package/dist/utils/portal-root.d.ts +2 -0
- package/dist/utils/validate.d.ts +6 -0
- package/package.json +1 -1
- package/dist/assets/index-C8MCucSQ.js +0 -20
- package/dist/index.html +0 -19
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
onClose: () => void;
|
|
3
|
+
/** Called after credentials are saved (for Send flow) */
|
|
4
|
+
onSaved?: () => void;
|
|
5
|
+
/** Title override */
|
|
6
|
+
title?: string;
|
|
7
|
+
/** Label for the save button. Default: "Save & Continue" */
|
|
8
|
+
saveLabel?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const CredentialsModal: import("react").NamedExoticComponent<Props>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CardElement } from '../../types/schema';
|
|
2
|
+
import './PropertyEditors.css';
|
|
3
|
+
interface Props {
|
|
4
|
+
element: CardElement;
|
|
5
|
+
onUpdate: (updates: Partial<CardElement>) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const ElementPropertyEditor: import("react").NamedExoticComponent<Props>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface VariableInputProps {
|
|
2
|
+
value: string;
|
|
3
|
+
onChange: (v: string) => void;
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
multiline?: boolean;
|
|
6
|
+
rows?: number;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
}
|
|
9
|
+
export declare const VariableInput: import("react").NamedExoticComponent<VariableInputProps>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CardElement } from '../../types/schema';
|
|
2
|
+
interface ElementRendererProps {
|
|
3
|
+
element: CardElement;
|
|
4
|
+
path: number[];
|
|
5
|
+
selectedPath: number[] | null;
|
|
6
|
+
selectedPaths: number[][];
|
|
7
|
+
onSelect: (path: number[] | null) => void;
|
|
8
|
+
onToggleSelect: (path: number[]) => void;
|
|
9
|
+
onMove: (path: number[], direction: 'up' | 'down') => void;
|
|
10
|
+
onRemove: (path: number[]) => void;
|
|
11
|
+
onWrap: (path: number[], wrapperType: 'row' | 'column' | 'grid') => void;
|
|
12
|
+
onUnwrap: (path: number[]) => void;
|
|
13
|
+
onDuplicate: (path: number[]) => void;
|
|
14
|
+
isFirst: boolean;
|
|
15
|
+
isLast: boolean;
|
|
16
|
+
inRow?: boolean;
|
|
17
|
+
colorMode?: 'light' | 'dark';
|
|
18
|
+
}
|
|
19
|
+
export declare const ElementRenderer: import("react").NamedExoticComponent<ElementRendererProps>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode, ButtonHTMLAttributes } from 'react';
|
|
2
|
+
type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'link';
|
|
3
|
+
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
4
|
+
variant?: ButtonVariant;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const Button: import("react").NamedExoticComponent<ButtonProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ColorValue } from '../../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Color section with light/dark toggle header + color fields.
|
|
4
|
+
* Usage:
|
|
5
|
+
* ```
|
|
6
|
+
* <ColorSection>
|
|
7
|
+
* {(mode) => (
|
|
8
|
+
* <>
|
|
9
|
+
* <ColorField label="Background" value={el.backgroundColor} onChange={(v) => onUpdate({ backgroundColor: v })} mode={mode} />
|
|
10
|
+
* <ColorField label="Border" value={el.borderColor} onChange={(v) => onUpdate({ borderColor: v })} mode={mode} />
|
|
11
|
+
* </>
|
|
12
|
+
* )}
|
|
13
|
+
* </ColorSection>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function ColorSection({ children }: {
|
|
17
|
+
children: (mode: 'light' | 'dark') => React.ReactNode;
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* Single color field: label + swatch + hex input.
|
|
21
|
+
* Respects light/dark mode to show/edit the correct side of a ColorValue.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ColorField({ label, value, onChange, fallback, transparentValue, mode, }: {
|
|
24
|
+
label: string;
|
|
25
|
+
value: ColorValue | undefined;
|
|
26
|
+
onChange: (v: ColorValue | undefined) => void;
|
|
27
|
+
fallback?: string;
|
|
28
|
+
transparentValue?: ColorValue;
|
|
29
|
+
mode?: 'light' | 'dark';
|
|
30
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode, CSSProperties } from 'react';
|
|
2
|
+
interface ModalProps {
|
|
3
|
+
title: string;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
footer?: ReactNode;
|
|
7
|
+
width?: number;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
}
|
|
10
|
+
export declare const Modal: import("react").NamedExoticComponent<ModalProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified app credentials state.
|
|
3
|
+
*
|
|
4
|
+
* Priority:
|
|
5
|
+
* 1. Props (highest) — passed via mountCardBuilder → read-only, non-editable
|
|
6
|
+
* 2. User-entered — set via App Credentials modal → editable (token cannot be set here)
|
|
7
|
+
* 3. Env vars (lowest, dev only) — from .env, set via builderConfig in App.tsx
|
|
8
|
+
*
|
|
9
|
+
* Note: `token` can only come from props or env (never user-entered).
|
|
10
|
+
*/
|
|
11
|
+
export interface AppCredentials {
|
|
12
|
+
appId: string;
|
|
13
|
+
region: string;
|
|
14
|
+
token: string;
|
|
15
|
+
apiKey: string;
|
|
16
|
+
}
|
|
17
|
+
/** Initialize credentials from mount props (highest priority, read-only) */
|
|
18
|
+
export declare function initCredentials(appId?: string, region?: string, token?: string, apiKey?: string, lock?: boolean): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get resolved credentials (props > user-entered).
|
|
21
|
+
* Each field is resolved independently — props field wins if non-empty.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getCredentials(): AppCredentials;
|
|
24
|
+
/** Whether credentials were provided via props (should be non-editable) */
|
|
25
|
+
export declare function isProvidedByProps(): boolean;
|
|
26
|
+
/** Whether we have enough credentials for template API calls (appId + token) */
|
|
27
|
+
export declare function hasApiCredentials(): boolean;
|
|
28
|
+
/** Whether we have enough credentials for sending messages (appId + region + apiKey) */
|
|
29
|
+
export declare function hasSendCredentials(): boolean;
|
|
30
|
+
/** Legacy: whether all credentials are configured */
|
|
31
|
+
export declare function hasCredentials(): boolean;
|
|
32
|
+
/** Update user-entered credentials (only works if not provided by props) */
|
|
33
|
+
export declare function setCredentials(creds: Partial<AppCredentials>): void;
|
|
34
|
+
/** Get user-entered credentials (for displaying in the modal) */
|
|
35
|
+
export declare function getUserCredentials(): AppCredentials;
|
|
36
|
+
/** Subscribe to credential changes */
|
|
37
|
+
export declare function subscribeCredentials(fn: () => void): () => void;
|
|
38
|
+
/** Reset credentials (used on destroy) */
|
|
39
|
+
export declare function resetCredentials(): void;
|
|
40
|
+
/**
|
|
41
|
+
* React hook: reactively reports whether template/variable (apimgmt) APIs are usable
|
|
42
|
+
* (appId + bearer token). Use this to hide token-requiring UI when no token is present.
|
|
43
|
+
*/
|
|
44
|
+
export declare function useHasApiCredentials(): boolean;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { CardMessage } from '../types/schema';
|
|
2
|
+
export interface CardVariable {
|
|
3
|
+
/** Variable name used in {{name}} tokens, e.g. 'user.name' */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Human-readable label shown in the picker */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** Short description */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Category for grouping in the picker */
|
|
10
|
+
category?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface NotificationConfig {
|
|
13
|
+
/** App name shown in the notification preview */
|
|
14
|
+
appName?: string;
|
|
15
|
+
/** App icon URL shown in the notification preview */
|
|
16
|
+
appIcon?: string;
|
|
17
|
+
/** Show the Data key-value editor in the notification tab */
|
|
18
|
+
enableData?: boolean;
|
|
19
|
+
/** Show the push notification phone preview in the canvas. Default: true */
|
|
20
|
+
showPreview?: boolean;
|
|
21
|
+
/** Called when notification title or body changes */
|
|
22
|
+
onNotificationChange?: (notification: {
|
|
23
|
+
title: string;
|
|
24
|
+
body: string;
|
|
25
|
+
}) => void;
|
|
26
|
+
/** Called when notification data changes */
|
|
27
|
+
onNotificationDataChange?: (data: Record<string, string>) => void;
|
|
28
|
+
}
|
|
29
|
+
/** Which channels the builder supports */
|
|
30
|
+
export type BuilderChannels = 'inapp' | 'push' | 'both';
|
|
31
|
+
/** Module-level config accessible by components */
|
|
32
|
+
export declare const builderConfig: {
|
|
33
|
+
appId?: string;
|
|
34
|
+
region?: string;
|
|
35
|
+
token?: string;
|
|
36
|
+
onSave?: (json: CardMessage, name: string, description: string) => void;
|
|
37
|
+
onChange?: (json: CardMessage) => void;
|
|
38
|
+
hideTopBar?: boolean;
|
|
39
|
+
hideTemplateLibrary?: boolean;
|
|
40
|
+
channels?: BuilderChannels;
|
|
41
|
+
/** Whether channels was explicitly provided by the host app (vs defaulted to 'both') */
|
|
42
|
+
channelsExplicit?: boolean;
|
|
43
|
+
/** Show the variable editor tab for creating/managing variables. Default: true */
|
|
44
|
+
enableVariableEditor?: boolean;
|
|
45
|
+
notification?: NotificationConfig;
|
|
46
|
+
/** Enable the built-in variable creation/management UI. Default: false */
|
|
47
|
+
enableVariableManager?: boolean;
|
|
48
|
+
/** Show the canvas toolbar (zoom, dark mode, preview, JSON). Default: false */
|
|
49
|
+
showCanvasToolbar?: boolean;
|
|
50
|
+
/** Hide the left panel (elements & components palette). Default: false */
|
|
51
|
+
/** Disable all editing interactions — read-only preview mode. Default: false */
|
|
52
|
+
readOnly?: boolean;
|
|
53
|
+
hideElementPalette?: boolean;
|
|
54
|
+
/** Hide the right panel (tree, element properties, card settings). Default: false */
|
|
55
|
+
hidePropertyPanel?: boolean;
|
|
56
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ComponentTemplate {
|
|
2
|
+
name: string;
|
|
3
|
+
category: string;
|
|
4
|
+
icon: string;
|
|
5
|
+
description: string;
|
|
6
|
+
elements: Record<string, unknown>[];
|
|
7
|
+
}
|
|
8
|
+
export declare const COMPONENT_TEMPLATES: ComponentTemplate[];
|
|
9
|
+
export declare const COMPONENT_CATEGORIES: string[];
|
|
10
|
+
export declare const COMPONENT_TEMPLATE_NAMES: readonly ["Product Card", "Order Confirmation", "Announcement", "Quick Reply Buttons", "Order Tracking", "Event Card", "Feedback", "Data Table", "Carousel"];
|
|
11
|
+
export type ComponentTemplateName = typeof COMPONENT_TEMPLATE_NAMES[number];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CardElement } from '../types/schema';
|
|
2
|
+
export declare const ELEMENT_DEFAULTS: Map<string, () => CardElement>;
|
|
3
|
+
export declare const ELEMENT_PALETTE: {
|
|
4
|
+
readonly Layout: readonly ["row", "column", "grid", "accordion", "tabs"];
|
|
5
|
+
readonly Content: readonly ["text", "image", "icon", "avatar", "badge", "divider", "spacer", "chip", "markdown", "codeBlock"];
|
|
6
|
+
readonly 'Data Display': readonly ["table", "progressBar"];
|
|
7
|
+
readonly Actions: readonly ["button", "iconButton", "link"];
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface IconEntry {
|
|
2
|
+
name: string;
|
|
3
|
+
label: string;
|
|
4
|
+
url: string;
|
|
5
|
+
category: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const ICON_LIBRARY: IconEntry[];
|
|
8
|
+
export declare const ICON_MAP: Map<string, IconEntry>;
|
|
9
|
+
export declare const ICON_CATEGORIES: string[];
|
|
10
|
+
/** Resolve an icon name to its URL. Returns the name as-is if it's already a URL. */
|
|
11
|
+
export declare function resolveIconUrl(nameOrUrl: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UIKitColorMode } from './uikit-theme';
|
|
2
|
+
/** Build a flat token map from UIKit theme colors */
|
|
3
|
+
export declare function buildTokensFromUIKit(colors: UIKitColorMode): Record<string, string>;
|
|
4
|
+
export declare const THEME_TOKENS: Record<string, string>;
|
|
5
|
+
export declare const DARK_THEME_TOKENS: Record<string, string>;
|
|
6
|
+
export declare let THEME_TOKEN_NAMES: string[];
|
|
7
|
+
export declare function setActiveTheme(dark: boolean): void;
|
|
8
|
+
/** Sync active theme tokens from the UIKit theme store */
|
|
9
|
+
export declare function syncThemeTokens(lightColors: UIKitColorMode, darkColors: UIKitColorMode, isDark: boolean): void;
|
|
10
|
+
export declare function resolveColor(value: string | undefined, fallback?: string): string;
|
|
11
|
+
export declare const TEXT_VARIANT_STYLES: Record<string, React.CSSProperties>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare function hexToRgb(hex: string): {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function rgbToHex(r: number, g: number, b: number): string;
|
|
7
|
+
export declare const SHADE_KEYS: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
|
|
8
|
+
export declare function generateExtendedPrimary(primary: string): {
|
|
9
|
+
light: Record<number, string>;
|
|
10
|
+
dark: Record<number, string>;
|
|
11
|
+
};
|
|
12
|
+
export declare function generateSpacingScale(baseUnit?: number, steps?: number): Record<string, number>;
|
|
13
|
+
export declare function generatePadding(scale: Record<string, number>): Record<string, number>;
|
|
14
|
+
export declare function generateRadius(scale: Record<string, number>): Record<string, number>;
|
|
15
|
+
export interface UIKitColorMode {
|
|
16
|
+
primary: string;
|
|
17
|
+
extendedPrimary: Record<number, string>;
|
|
18
|
+
neutral: Record<number, string>;
|
|
19
|
+
alert: {
|
|
20
|
+
info: string;
|
|
21
|
+
warning: string;
|
|
22
|
+
success: string;
|
|
23
|
+
error: string;
|
|
24
|
+
};
|
|
25
|
+
staticColors: {
|
|
26
|
+
black: string;
|
|
27
|
+
white: string;
|
|
28
|
+
};
|
|
29
|
+
sendBubble: {
|
|
30
|
+
background: string;
|
|
31
|
+
text: string;
|
|
32
|
+
textHighlight: string;
|
|
33
|
+
link: string;
|
|
34
|
+
timestamp: string;
|
|
35
|
+
icon: string;
|
|
36
|
+
};
|
|
37
|
+
receiveBubble: {
|
|
38
|
+
background: string;
|
|
39
|
+
text: string;
|
|
40
|
+
textHighlight: string;
|
|
41
|
+
link: string;
|
|
42
|
+
timestamp: string;
|
|
43
|
+
icon: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface UIKitTheme {
|
|
47
|
+
name: string;
|
|
48
|
+
version: string;
|
|
49
|
+
spacing: {
|
|
50
|
+
baseUnit: number;
|
|
51
|
+
scale: Record<string, number>;
|
|
52
|
+
padding: Record<string, number>;
|
|
53
|
+
radius: Record<string, number>;
|
|
54
|
+
};
|
|
55
|
+
typography: {
|
|
56
|
+
fontFamily: string;
|
|
57
|
+
scale: Record<string, {
|
|
58
|
+
size: number;
|
|
59
|
+
lineHeight: number;
|
|
60
|
+
weight?: string;
|
|
61
|
+
}>;
|
|
62
|
+
weights: {
|
|
63
|
+
bold: string;
|
|
64
|
+
medium: string;
|
|
65
|
+
regular: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
colors: {
|
|
69
|
+
light: UIKitColorMode;
|
|
70
|
+
dark: UIKitColorMode;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export declare function createDefaultTheme(): UIKitTheme;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useKeyboardShortcuts(): void;
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CardMessage, ElementType } from './types/schema';
|
|
2
|
+
import type { ComponentTemplateName } from './config/component-templates';
|
|
3
|
+
import type { CardVariable, NotificationConfig, BuilderChannels } from './config/builder-config';
|
|
4
|
+
import './index.css';
|
|
5
|
+
export type { CardVariable } from './config/builder-config';
|
|
6
|
+
export type { NotificationConfig, BuilderChannels } from './config/builder-config';
|
|
7
|
+
export interface CardBuilderOptions {
|
|
8
|
+
/** CometChat app ID (required for template save/load APIs) */
|
|
9
|
+
appId?: string;
|
|
10
|
+
/** App region — us, eu, etc. (required for template save/load APIs) */
|
|
11
|
+
region?: string;
|
|
12
|
+
/** Bearer token — legacy; no longer used for template save/load auth (apiKey is). */
|
|
13
|
+
token?: string;
|
|
14
|
+
/** CometChat REST API Key (required for template save/load and sending messages) */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/** Existing card JSON to load for editing */
|
|
17
|
+
card?: CardMessage;
|
|
18
|
+
/** Initial notification title (only used when channels includes push). */
|
|
19
|
+
notificationTitle?: string;
|
|
20
|
+
/** Initial notification body (only used when channels includes push). */
|
|
21
|
+
notificationBody?: string;
|
|
22
|
+
/** Template name */
|
|
23
|
+
templateName?: string;
|
|
24
|
+
/** Called when user clicks Save */
|
|
25
|
+
onSave?: (json: CardMessage, name: string, description: string) => void;
|
|
26
|
+
/** Called whenever the card JSON changes (any edit). Use for real-time sync. */
|
|
27
|
+
onChange?: (json: CardMessage) => void;
|
|
28
|
+
/** Available variables for {{placeholder}} insertion in text/URL fields */
|
|
29
|
+
variables?: CardVariable[];
|
|
30
|
+
/** Hide the top toolbar (save, export, import, undo/redo, template name). Default: false */
|
|
31
|
+
hideTopBar?: boolean;
|
|
32
|
+
/** Hide the template library view — go straight to editor. Default: false */
|
|
33
|
+
hideTemplateLibrary?: boolean;
|
|
34
|
+
/** Disable all editing interactions — read-only preview mode. Default: false */
|
|
35
|
+
readOnly?: boolean;
|
|
36
|
+
/** Show the variable editor tab for creating/managing variables in the builder. Default: true */
|
|
37
|
+
enableVariableEditor?: boolean;
|
|
38
|
+
/** Which channels to show: 'inapp', 'push', or 'both' (default). */
|
|
39
|
+
channels?: BuilderChannels;
|
|
40
|
+
/** Push notification preview config (app name, icon). Only used when channels is 'push' or 'both'. */
|
|
41
|
+
notification?: NotificationConfig;
|
|
42
|
+
/** Element types to hide from the palette (e.g. ['codeBlock', 'table', 'markdown']) */
|
|
43
|
+
hiddenElements?: ElementType[];
|
|
44
|
+
/** Component template names to hide from the palette (e.g. ['Product Card', 'Data Table']) */
|
|
45
|
+
hiddenComponents?: ComponentTemplateName[];
|
|
46
|
+
/** Hide the left panel (elements & components palette). Default: false */
|
|
47
|
+
hideElementPalette?: boolean;
|
|
48
|
+
/** Hide the right panel (tree, element properties, card settings). Default: false */
|
|
49
|
+
hidePropertyPanel?: boolean;
|
|
50
|
+
/** Show the canvas toolbar (zoom, dark mode, preview, JSON). Default: false */
|
|
51
|
+
showCanvasToolbar?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface CardBuilderInstance {
|
|
54
|
+
loadCard: (card: CardMessage, name?: string) => void;
|
|
55
|
+
getCardJSON: () => CardMessage;
|
|
56
|
+
setVariables: (variables: CardVariable[]) => void;
|
|
57
|
+
setChannels: (channels: BuilderChannels) => void;
|
|
58
|
+
setCanvasView: (view: 'card' | 'notification') => void;
|
|
59
|
+
setReadOnly: (readOnly: boolean) => void;
|
|
60
|
+
/** Hide specific element types from the palette. Pass element type names (e.g. 'codeBlock', 'table'). */
|
|
61
|
+
setHiddenElements: (types: ElementType[]) => void;
|
|
62
|
+
/** Hide specific component templates from the palette. Pass template names (e.g. 'Product Card'). */
|
|
63
|
+
setHiddenComponents: (names: ComponentTemplateName[]) => void;
|
|
64
|
+
/** Show or hide the left panel at runtime. */
|
|
65
|
+
setHideElementPalette: (hide: boolean) => void;
|
|
66
|
+
/** Show or hide the right panel at runtime. */
|
|
67
|
+
setHidePropertyPanel: (hide: boolean) => void;
|
|
68
|
+
/** Show or hide the canvas toolbar at runtime. */
|
|
69
|
+
setShowCanvasToolbar: (show: boolean) => void;
|
|
70
|
+
/** Set notification title at runtime. */
|
|
71
|
+
setNotificationTitle: (title: string) => void;
|
|
72
|
+
/** Set notification body at runtime. */
|
|
73
|
+
setNotificationBody: (body: string) => void;
|
|
74
|
+
/** Set API key at runtime. */
|
|
75
|
+
setApiKey: (apiKey: string) => void;
|
|
76
|
+
destroy: () => void;
|
|
77
|
+
}
|
|
78
|
+
export { builderConfig } from './config/builder-config';
|
|
79
|
+
export declare function mountCardBuilder(container: HTMLElement, options: CardBuilderOptions): CardBuilderInstance;
|
|
80
|
+
export type { CardMessage, ElementType } from './types/schema';
|
|
81
|
+
export type { ComponentTemplateName } from './config/component-templates';
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { CardElement, CardStyle, CardMessage, Template, ElementType, MessageData } from '../types/schema';
|
|
2
|
+
import type { ComponentTemplateName } from '../config/component-templates';
|
|
3
|
+
import { type CardVariable } from '../config/builder-config';
|
|
4
|
+
export interface BuilderState {
|
|
5
|
+
templateId: string | null;
|
|
6
|
+
templateName: string;
|
|
7
|
+
templateDescription: string;
|
|
8
|
+
body: CardElement[];
|
|
9
|
+
style: CardStyle;
|
|
10
|
+
fallbackText: string;
|
|
11
|
+
notificationTitle: string;
|
|
12
|
+
notificationBody: string;
|
|
13
|
+
notificationData: Array<{
|
|
14
|
+
key: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** Custom message type for CometChat message structure (e.g. 'product', 'order') */
|
|
18
|
+
messageType: string;
|
|
19
|
+
notificationEnabled: boolean;
|
|
20
|
+
/** Which view the canvas shows: card editor or notification preview */
|
|
21
|
+
canvasView: 'card' | 'notification';
|
|
22
|
+
/** Which channels are available */
|
|
23
|
+
channels: 'inapp' | 'push' | 'both';
|
|
24
|
+
/** Whether channels was explicitly set (vs default) */
|
|
25
|
+
channelsExplicit: boolean;
|
|
26
|
+
/** Read-only mode — disables all editing interactions */
|
|
27
|
+
readOnly: boolean;
|
|
28
|
+
selectedPath: number[] | null;
|
|
29
|
+
selectedPaths: number[][];
|
|
30
|
+
isDirty: boolean;
|
|
31
|
+
useThemePlaceholders: boolean;
|
|
32
|
+
/** Element types hidden from the palette */
|
|
33
|
+
hiddenElements: Set<ElementType>;
|
|
34
|
+
/** Component template names hidden from the palette */
|
|
35
|
+
hiddenComponents: Set<ComponentTemplateName>;
|
|
36
|
+
view: 'library' | 'editor';
|
|
37
|
+
clipboard: CardElement | null;
|
|
38
|
+
showTemplatePicker: boolean;
|
|
39
|
+
/** Hide the left panel (elements & components palette) */
|
|
40
|
+
hideElementPalette: boolean;
|
|
41
|
+
/** Hide the right panel (tree, element properties, card settings) */
|
|
42
|
+
hidePropertyPanel: boolean;
|
|
43
|
+
/** Show the canvas toolbar (zoom, dark mode, preview, JSON). Default: false */
|
|
44
|
+
showCanvasToolbar: boolean;
|
|
45
|
+
/** Show the variable editor tab. Default: true */
|
|
46
|
+
enableVariableEditor: boolean;
|
|
47
|
+
variables: CardVariable[];
|
|
48
|
+
history: {
|
|
49
|
+
body: CardElement[];
|
|
50
|
+
style: CardStyle;
|
|
51
|
+
}[];
|
|
52
|
+
historyIndex: number;
|
|
53
|
+
templates: Template[];
|
|
54
|
+
templatesLoading: boolean;
|
|
55
|
+
templatesMeta: {
|
|
56
|
+
previous?: {
|
|
57
|
+
affix: string;
|
|
58
|
+
createdAt: number;
|
|
59
|
+
};
|
|
60
|
+
next?: {
|
|
61
|
+
affix: string;
|
|
62
|
+
createdAt: number;
|
|
63
|
+
};
|
|
64
|
+
} | null;
|
|
65
|
+
setView: (view: 'library' | 'editor') => void;
|
|
66
|
+
setShowTemplatePicker: (show: boolean) => void;
|
|
67
|
+
setHideElementPalette: (hide: boolean) => void;
|
|
68
|
+
setHidePropertyPanel: (hide: boolean) => void;
|
|
69
|
+
setShowCanvasToolbar: (show: boolean) => void;
|
|
70
|
+
setEnableVariableEditor: (enable: boolean) => void;
|
|
71
|
+
selectElement: (path: number[] | null) => void;
|
|
72
|
+
toggleSelectElement: (path: number[]) => void;
|
|
73
|
+
addElement: (element: CardElement, parentPath?: number[]) => void;
|
|
74
|
+
updateElement: (path: number[], updates: Partial<CardElement>) => void;
|
|
75
|
+
removeElement: (path: number[]) => void;
|
|
76
|
+
moveElement: (path: number[], direction: 'up' | 'down') => void;
|
|
77
|
+
updateStyle: (settings: Partial<CardStyle>) => void;
|
|
78
|
+
setFallbackText: (text: string) => void;
|
|
79
|
+
setNotificationTitle: (text: string) => void;
|
|
80
|
+
setNotificationBody: (text: string) => void;
|
|
81
|
+
setMessageType: (type: string) => void;
|
|
82
|
+
setNotificationData: (data: Array<{
|
|
83
|
+
key: string;
|
|
84
|
+
value: string;
|
|
85
|
+
}>) => void;
|
|
86
|
+
setNotificationEnabled: (enabled: boolean) => void;
|
|
87
|
+
setCanvasView: (view: 'card' | 'notification') => void;
|
|
88
|
+
setChannels: (channels: 'inapp' | 'push' | 'both') => void;
|
|
89
|
+
setReadOnly: (readOnly: boolean) => void;
|
|
90
|
+
setHiddenElements: (types: ElementType[]) => void;
|
|
91
|
+
setHiddenComponents: (names: ComponentTemplateName[]) => void;
|
|
92
|
+
setUseThemePlaceholders: (use: boolean) => void;
|
|
93
|
+
setVariables: (variables: CardVariable[]) => void;
|
|
94
|
+
addVariable: (variable: CardVariable) => void;
|
|
95
|
+
updateVariable: (index: number, variable: CardVariable) => void;
|
|
96
|
+
removeVariable: (index: number) => void;
|
|
97
|
+
setTemplateName: (name: string) => void;
|
|
98
|
+
setTemplateDescription: (desc: string) => void;
|
|
99
|
+
loadCard: (card: CardMessage, templateId?: string, name?: string, desc?: string) => void;
|
|
100
|
+
loadTemplate: (template: Template) => void;
|
|
101
|
+
newCard: () => void;
|
|
102
|
+
getCardJSON: (opts?: {
|
|
103
|
+
stripEmpty?: boolean;
|
|
104
|
+
}) => CardMessage;
|
|
105
|
+
/** Get the full CometChat message structure wrapping the card (used when channels not set) */
|
|
106
|
+
getMessageJSON: () => MessageData;
|
|
107
|
+
setTemplates: (templates: Template[]) => void;
|
|
108
|
+
fetchTemplates: (search?: string) => Promise<void>;
|
|
109
|
+
fetchNextPage: () => Promise<void>;
|
|
110
|
+
fetchPrevPage: () => Promise<void>;
|
|
111
|
+
saveTemplate: () => Promise<void>;
|
|
112
|
+
deleteTemplate: (id: string) => Promise<void>;
|
|
113
|
+
reorderElement: (fromPath: number[], toPath: number[], toIndex: number) => void;
|
|
114
|
+
moveElementToPath: (fromPath: number[], toParentPath: number[], toIndex: number) => void;
|
|
115
|
+
wrapElement: (path: number[], wrapperType: 'row' | 'column' | 'grid') => void;
|
|
116
|
+
unwrapElement: (path: number[]) => void;
|
|
117
|
+
wrapSelected: (wrapperType: 'row' | 'column' | 'grid') => void;
|
|
118
|
+
duplicateElement: (path: number[]) => void;
|
|
119
|
+
copyElement: (path: number[]) => void;
|
|
120
|
+
pasteElement: (targetPath?: number[]) => void;
|
|
121
|
+
undo: () => void;
|
|
122
|
+
redo: () => void;
|
|
123
|
+
canUndo: () => boolean;
|
|
124
|
+
canRedo: () => boolean;
|
|
125
|
+
clearAll: () => void;
|
|
126
|
+
}
|
|
127
|
+
export declare const DEFAULT_STYLE: CardStyle;
|
|
128
|
+
export declare const useBuilderStore: import("zustand").UseBoundStore<import("zustand").StoreApi<BuilderState>>;
|