@chaibuilder/sdk 2.0.12 → 2.1.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/dist/core.d.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  import { ChaiBlock as ChaiBlock_2 } from '@chaibuilder/runtime';
2
2
  import { ClassValue } from 'clsx';
3
+ import { ComponentType } from 'react';
3
4
  import { default as default_2 } from 'react';
4
- import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
5
5
  import { default as i18n } from 'i18next';
6
6
  import { JSX as JSX_2 } from 'react/jsx-runtime';
7
7
  import * as React_2 from 'react';
8
- import { ReactNode } from 'react';
9
- import { registerChaiBlock } from '@chaibuilder/runtime';
10
8
  import { RESET } from 'jotai/utils';
11
9
  import { ThrottledFunction } from '@react-hookz/web';
12
10
  import { useTranslation } from 'react-i18next';
@@ -16,20 +14,11 @@ declare type AddBlocks = {
16
14
  addPredefinedBlock: any;
17
15
  };
18
16
 
19
- export declare const AddBlocksDialog: () => JSX_2.Element;
20
-
21
- export declare const AddBlocksPanel: ({ className, showHeading, parentId, position, }: {
22
- parentId?: string;
23
- showHeading?: boolean;
24
- className?: string;
25
- position?: number;
26
- }) => JSX_2.Element;
27
-
28
- export declare const AISetContext: () => JSX_2.Element;
29
-
30
- export declare const AIUserPrompt: ({ blockId }: {
31
- blockId: string | undefined;
32
- }) => JSX_2.Element;
17
+ declare type AddBlockTab = {
18
+ id: string;
19
+ tab: React.ComponentType;
20
+ tabContent: React.ComponentType;
21
+ };
33
22
 
34
23
  declare type AskAiResponse = {
35
24
  blocks?: Array<{
@@ -39,16 +28,6 @@ declare type AskAiResponse = {
39
28
  error?: any;
40
29
  };
41
30
 
42
- export declare const BlockAttributesEditor: React_2.MemoExoticComponent<() => JSX_2.Element>;
43
-
44
- /**
45
- *
46
- * @returns Block Setting
47
- */
48
- export declare function BlockPropsEditor(): JSX_2.Element;
49
-
50
- export declare function BlockStyleEditor(): JSX_2.Element;
51
-
52
31
  declare type BorderRadiusValue = false | string;
53
32
 
54
33
  declare type Breakpoint = {
@@ -59,11 +38,20 @@ declare type Breakpoint = {
59
38
  width: number;
60
39
  };
61
40
 
62
- export declare const CHAI_BUILDER_EVENTS: {
63
- OPEN_ADD_BLOCK: string;
64
- CLOSE_ADD_BLOCK: string;
65
- SHOW_BLOCK_SETTINGS: string;
66
- };
41
+ export declare const ChaiAddBlocksDialog: () => JSX_2.Element;
42
+
43
+ export declare const ChaiAddBlocksPanel: ({ className, showHeading, parentId, position, }: {
44
+ parentId?: string;
45
+ showHeading?: boolean;
46
+ className?: string;
47
+ position?: number;
48
+ }) => JSX_2.Element;
49
+
50
+ export declare const ChaiAskAiPanel: () => JSX_2.Element;
51
+
52
+ export declare const ChaiAskAiUserPrompt: ({ blockId }: {
53
+ blockId: string | undefined;
54
+ }) => JSX_2.Element;
67
55
 
68
56
  export declare type ChaiBlock<T = Record<string, any>> = {
69
57
  _id: string;
@@ -71,8 +59,19 @@ export declare type ChaiBlock<T = Record<string, any>> = {
71
59
  _parent?: string | null | undefined;
72
60
  _bindings?: Record<string, string>;
73
61
  _type: string;
62
+ _libBlock?: string;
74
63
  } & T;
75
64
 
65
+ export declare const ChaiBlockAttributesEditor: React_2.MemoExoticComponent<() => JSX_2.Element>;
66
+
67
+ /**
68
+ *
69
+ * @returns Block Setting
70
+ */
71
+ export declare function ChaiBlockPropsEditor(): JSX_2.Element;
72
+
73
+ export declare function ChaiBlockStyleEditor(): JSX_2.Element;
74
+
76
75
  export declare const ChaiBuilderCanvas: default_2.FC;
77
76
 
78
77
  /**
@@ -82,23 +81,43 @@ export declare const ChaiBuilderEditor: default_2.FC<ChaiBuilderEditorProps>;
82
81
 
83
82
  export declare interface ChaiBuilderEditorProps {
84
83
  /**
85
- * Permissions
84
+ * User
86
85
  */
87
- permissions?: string[];
86
+ user?: {
87
+ id: string;
88
+ name: string;
89
+ email: string;
90
+ avatar?: string;
91
+ role: string;
92
+ };
88
93
  /**
89
- * RJSF Fields and Widgets
94
+ * Permissions
90
95
  */
91
- rjsfFields?: Record<string, default_2.ComponentType<any>>;
92
- rjsfWidgets?: Record<string, default_2.ComponentType<any>>;
93
- rjsfTemplates?: Record<string, default_2.ComponentType<any>>;
96
+ permissions?: string[];
94
97
  /**
95
98
  * Optional pageId. If not provided, a random pageId will be generated
96
99
  */
97
100
  pageId?: string;
101
+ /**
102
+ * Page external data
103
+ */
98
104
  pageExternalData?: Record<string, any>;
105
+ /**
106
+ * Theme presets
107
+ */
99
108
  themePresets?: Record<string, Partial<ChaiBuilderThemeValues>>[];
109
+ /**
110
+ * Theme options
111
+ */
100
112
  themeOptions?: (defaultThemeOptions: ChaiBuilderThemeOptions) => ChaiBuilderThemeOptions;
113
+ /**
114
+ * Theme
115
+ */
101
116
  theme?: Partial<ChaiBuilderThemeValues>;
117
+ /**
118
+ * Theme panel component
119
+ * TODO: Move to registerChaiThemePanelComponent()
120
+ */
102
121
  themePanelComponent?: ReactComponentType;
103
122
  /**
104
123
  * onError callback function
@@ -109,45 +128,19 @@ export declare interface ChaiBuilderEditorProps {
109
128
  * Translations object
110
129
  */
111
130
  translations?: Record<string, Record<string, any>>;
112
- /**
113
- * onLoad callback function
114
- * @param editorInstance
115
- */
116
- onLoad?: (editorInstance: ChaiBuilderInstance) => void;
117
131
  /**
118
132
  * Custom layout component
133
+ * TODO: Move to registerChaiLayoutComponent()
119
134
  */
120
135
  layout?: default_2.ComponentType;
121
- /**
122
- * Layout variant. Not supported with custom layout
123
- */
124
- layoutVariant?: LayoutVariant;
125
- /**
126
- * Custom media Manager component
127
- */
128
- mediaManagerComponent?: default_2.ComponentType<{
129
- onSelect: (url: string) => void;
130
- }>;
131
- /**
132
- * Add blocks dialog components
133
- */
134
- addBlocksDialogTabs?: {
135
- key: string;
136
- tab: ReactComponentType;
137
- tabContent: ReactComponentType;
138
- }[];
139
136
  /**
140
137
  * HTML direction.
141
138
  */
142
139
  htmlDir?: "ltr" | "rtl";
143
- /**
144
- * Filter function for blocks to be shown in the builder
145
- */
146
- filterChaiBlock?: (block: any) => boolean;
147
140
  /**
148
141
  * Show debug logs
149
142
  */
150
- showDebugLogs?: boolean;
143
+ debugLogs?: boolean;
151
144
  /**
152
145
  * Auto save support
153
146
  */
@@ -160,10 +153,6 @@ export declare interface ChaiBuilderEditorProps {
160
153
  * Breakpoints
161
154
  */
162
155
  breakpoints?: Breakpoint[];
163
- /**
164
- * Editable
165
- */
166
- editable?: boolean;
167
156
  /**
168
157
  * Loading state
169
158
  */
@@ -173,27 +162,47 @@ export declare interface ChaiBuilderEditorProps {
173
162
  */
174
163
  locale?: string;
175
164
  /**
176
- * Non editable component
165
+ * Dark mode
177
166
  */
178
- nonEditableComponent?: ReactComponentType;
167
+ darkMode?: boolean;
179
168
  /**
180
- * Canvas component. Not supported with custom layout
169
+ * Import HTML support
181
170
  */
182
- canvasTopBarComponents?: {
183
- right?: ReactComponentType[];
184
- };
185
- blockMoreOptions?: Array<(props: {
186
- block: ChaiBlock;
187
- }) => default_2.ReactElement<typeof DropdownMenuItem>>;
188
- previewLink?: string;
189
- darkMode?: boolean;
190
171
  importHTMLSupport?: boolean;
172
+ /**
173
+ * AI context
174
+ */
175
+ aiContext?: string;
176
+ /**
177
+ * Ask AI callback
178
+ */
191
179
  askAiCallBack?: (type: "styles" | "content", prompt: string, blocks: ChaiBlock[], lang: string) => Promise<AskAiResponse>;
192
180
  saveAiContextCallback?: (content: string) => Promise<true | Error>;
193
- aiContext?: string;
181
+ /**
182
+ * UI libraries
183
+ */
194
184
  uiLibraries?: Omit<ChaiUILibrary, "blocks">[];
185
+ /**
186
+ * Get library blocks
187
+ */
195
188
  getUILibraryBlocks?: (library: ChaiUILibrary) => Promise<ChaiUILibraryBlock[]>;
189
+ /**
190
+ * Get library block
191
+ */
196
192
  getUILibraryBlock?: (library: ChaiUILibrary, uiLibBlock: ChaiUILibraryBlock) => Promise<ChaiBlock[]>;
193
+ /**
194
+ * Upsert library block
195
+ */
196
+ upsertLibraryBlock?: (params: {
197
+ id?: string;
198
+ description: string;
199
+ group: string;
200
+ library: string;
201
+ name: string;
202
+ preview?: string;
203
+ }) => Promise<{
204
+ id: string;
205
+ } | Error>;
197
206
  getPartialBlocks?: () => Promise<Record<string, {
198
207
  type: string;
199
208
  name: string;
@@ -207,6 +216,10 @@ export declare interface ChaiBuilderEditorProps {
207
216
  * Blocks for the page
208
217
  */
209
218
  blocks?: ChaiBlock[];
219
+ /**
220
+ * onSave callback function
221
+ * @param saveData
222
+ */
210
223
  onSave?: ({ blocks, theme, autoSave }: SavePageData) => Promise<boolean | Error>;
211
224
  /**
212
225
  * onSaveStateChange callback function
@@ -215,48 +228,27 @@ export declare interface ChaiBuilderEditorProps {
215
228
  onSaveStateChange?: (syncStatus: "SAVED" | "SAVING" | "UNSAVED") => void;
216
229
  /**
217
230
  * Preview component
231
+ * TODO: Move to registerChaiPreviewComponent()
218
232
  */
219
233
  previewComponent?: ReactComponentType;
220
- /**
221
- * Sidebar components. Not supported with custom layout
222
- */
223
- sideBarComponents?: {
224
- bottom?: ReactComponentType[];
225
- top?: {
226
- icon: ReactNode;
227
- label: string;
228
- component: ReactComponentType;
229
- }[];
230
- };
231
- /**
232
- * Topbar components. Not supported with custom layout
233
- */
234
- topBarComponents?: {
235
- center?: ReactComponentType[];
236
- left?: ReactComponentType[];
237
- right?: ReactComponentType[];
238
- };
239
- /**
240
- * Outline menu items
241
- */
242
- outlineMenuItems?: OutlineMenuItems;
243
- _flags?: Record<string, boolean>;
244
234
  /**
245
235
  * Content locale
246
236
  */
247
237
  fallbackLang?: string;
238
+ /**
239
+ * Languages
240
+ */
248
241
  languages?: Array<string>;
249
242
  /**
250
243
  * Page Types props
251
244
  */
252
245
  pageTypes?: PageType[];
246
+ /**
247
+ * Search page type items
248
+ */
253
249
  searchPageTypeItems?: (pageTypeKey: string, query: string) => Promise<PageTypeItem[] | Error>;
254
250
  }
255
251
 
256
- declare type ChaiBuilderInstance = {
257
- setBlocks: (blocks: ChaiBlock[]) => void;
258
- };
259
-
260
252
  declare type ChaiBuilderThemeOptions = {
261
253
  fontFamily: false | Record<VariableKey, string>;
262
254
  borderRadius: BorderRadiusValue;
@@ -272,6 +264,46 @@ declare type ChaiBuilderThemeValues = {
272
264
  colors: Record<string, string[]>;
273
265
  };
274
266
 
267
+ export declare function ChaiDarkModeSwitcher(): JSX_2.Element;
268
+
269
+ export declare const ChaiDefaultBlocks: ({ parentId, position, gridCols, }: {
270
+ parentId?: string;
271
+ position?: number;
272
+ gridCols?: string;
273
+ }) => JSX_2.Element;
274
+
275
+ export declare const ChaiImportHTML: ({ parentId, position }: {
276
+ parentId?: string;
277
+ position?: number;
278
+ }) => JSX_2.Element;
279
+
280
+ export declare const ChaiOutline: () => JSX_2.Element;
281
+
282
+ export declare const ChaiScreenSizes: ({ openDelay, canvas, tooltip, }: {
283
+ openDelay?: number;
284
+ canvas?: boolean;
285
+ tooltip?: boolean;
286
+ }) => JSX_2.Element;
287
+
288
+ declare interface ChaiSidebarPanel<T> {
289
+ id: string;
290
+ position: "top" | "bottom";
291
+ view?: "standard" | "modal" | "overlay" | "drawer";
292
+ icon: React.ReactNode;
293
+ label: string;
294
+ component: ComponentType;
295
+ showIf?: (params: T) => boolean;
296
+ width?: number;
297
+ isInternal?: boolean;
298
+ }
299
+
300
+ export declare const ChaiThemeConfigPanel: React_2.FC<ThemeConfigProps>;
301
+
302
+ export declare const ChaiUILibrariesPanel: ({ parentId, position }: {
303
+ parentId?: string;
304
+ position?: number;
305
+ }) => JSX_2.Element;
306
+
275
307
  declare type ChaiUILibrary<T = Record<string, any>> = {
276
308
  id: string;
277
309
  name: string;
@@ -288,6 +320,8 @@ declare type ChaiUILibraryBlock<T = Record<string, any>> = {
288
320
  description?: string;
289
321
  } & T;
290
322
 
323
+ export declare const ChaiUndoRedo: () => JSX_2.Element;
324
+
291
325
  declare type ClassDerivedObject = {
292
326
  cls: string;
293
327
  dark: boolean;
@@ -308,18 +342,6 @@ declare type CopiedValue = string | null;
308
342
 
309
343
  declare type CopyFn = (text: string) => Promise<boolean>;
310
344
 
311
- export declare function DarkModeSwitcher(): JSX_2.Element;
312
-
313
- export declare const DefaultChaiBlocks: ({ parentId, position, gridCols, }: {
314
- parentId?: string;
315
- position?: number;
316
- gridCols?: string;
317
- }) => JSX_2.Element;
318
-
319
- declare const DropdownMenuItem: React_2.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuItemProps & React_2.RefAttributes<HTMLDivElement>, "ref"> & {
320
- inset?: boolean;
321
- } & React_2.RefAttributes<HTMLDivElement>>;
322
-
323
345
  declare type ExcludedBuilderProps = "blocks" | "subPages" | "brandingOptions" | "dataProviders";
324
346
 
325
347
  /**
@@ -332,40 +354,21 @@ export declare function generateBlockId(length?: number, chars?: string): string
332
354
  * @param html
333
355
  * @returns Blocks JSON
334
356
  */
335
- export declare const getBlocksFromHTML: (html: string) => ChaiBlock[];
336
-
337
- /**
338
- * Get the value and unit for a tw class
339
- * @param className
340
- */
341
- export declare const getClassValueAndUnit: (className: string) => {
342
- unit: string;
343
- value: string;
344
- };
357
+ declare const getBlocksFromHTML: (html: string) => ChaiBlock[];
358
+ export { getBlocksFromHTML as convertHTMLToChaiBlocks }
359
+ export { getBlocksFromHTML }
345
360
 
346
361
  declare type HSLColor = string;
347
362
 
348
363
  export { i18n }
349
364
 
350
- export declare const ImportHTML: ({ parentId, position }: {
351
- parentId?: string;
352
- position?: number;
353
- }) => JSX_2.Element;
354
-
355
- declare type LayoutVariant = "SINGLE_SIDE_PANEL" | "DUAL_SIDE_PANEL" | "DUAL_SIDE_PANEL_ADVANCED";
356
-
357
- export declare const mergeClasses: (...inputs: ClassValue[]) => string;
358
-
359
- export declare const Outline: () => JSX_2.Element;
360
-
361
- declare type OutlineMenuItem = {
362
- item: default_2.ComponentType<{
363
- blockId: string;
364
- }>;
365
- tooltip: string | ReactNode;
365
+ declare type MediaManagerProps = {
366
+ close: () => void;
367
+ onSelect: (urls: string[]) => void;
368
+ mode?: "image" | "video" | "audio";
366
369
  };
367
370
 
368
- declare type OutlineMenuItems = OutlineMenuItem[];
371
+ export declare const mergeClasses: (...inputs: ClassValue[]) => string;
369
372
 
370
373
  declare type PageType = {
371
374
  key: string;
@@ -393,11 +396,29 @@ export declare const PERMISSIONS: {
393
396
  SAVE_PAGE: string;
394
397
  EDIT_STYLES: string;
395
398
  IMPORT_HTML: string;
399
+ CREATE_LIBRARY_BLOCK: string;
400
+ CREATE_LIBRARY_GROUP: string;
401
+ EDIT_LIBRARY_BLOCK: string;
402
+ EDIT_LIBRARY_GROUP: string;
403
+ DELETE_LIBRARY_BLOCK: string;
404
+ DELETE_LIBRARY_GROUP: string;
396
405
  };
397
406
 
398
407
  declare type ReactComponentType = default_2.ComponentType<any>;
399
408
 
400
- export { registerChaiBlock }
409
+ export declare const registerBlockSettingField: (id: string, component: React.ComponentType<any>) => void;
410
+
411
+ export declare const registerBlockSettingTemplate: (id: string, component: React.ComponentType<any>) => void;
412
+
413
+ export declare const registerBlockSettingWidget: (id: string, component: React.ComponentType<any>) => void;
414
+
415
+ export declare const registerChaiAddBlockTab: (id: string, tab: Omit<AddBlockTab, "id">) => void;
416
+
417
+ export declare const registerChaiMediaManager: (component: React.ComponentType<MediaManagerProps>) => void;
418
+
419
+ export declare const registerChaiSidebarPanel: <T extends Record<string, any>>(panelId: string, panelOptions: Omit<ChaiSidebarPanel<T>, "id">) => void;
420
+
421
+ export declare const registerChaiTopBar: (component: React.ComponentType) => void;
401
422
 
402
423
  declare type SavePageData = {
403
424
  autoSave: boolean;
@@ -405,14 +426,6 @@ declare type SavePageData = {
405
426
  theme?: ChaiBuilderThemeValues;
406
427
  };
407
428
 
408
- export declare const ScreenSizes: ({ openDelay, canvas, tooltip, }: {
409
- openDelay?: number;
410
- canvas?: boolean;
411
- tooltip?: boolean;
412
- }) => JSX_2.Element;
413
-
414
- export declare const ThemeConfigPanel: React_2.FC<ThemeConfigProps>;
415
-
416
429
  declare interface ThemeConfigProps {
417
430
  className?: string;
418
431
  }
@@ -425,13 +438,6 @@ declare type TStyleBlock = {
425
438
  prop: string;
426
439
  };
427
440
 
428
- export declare const UILibrariesPanel: ({ parentId, position }: {
429
- parentId?: string;
430
- position?: number;
431
- }) => JSX_2.Element;
432
-
433
- export declare const UndoRedo: () => JSX_2.Element;
434
-
435
441
  export declare const useAddBlock: () => AddBlocks;
436
442
 
437
443
  export declare const useAddClassesToBlocks: () => (blockIds: Array<string>, newClasses: Array<string>, undo?: boolean) => void;
@@ -467,7 +473,7 @@ export declare const useBlocksStoreUndoableActions: () => {
467
473
  */
468
474
  export declare const useBrandingOptions: () => readonly [any, (args_0: any) => void];
469
475
 
470
- export declare const useBuilderProp: <T>(propKey: keyof Omit<ChaiBuilderEditorProps, ExcludedBuilderProps> | "sideBarComponents.top" | "sideBarComponents.bottom" | "topBarComponents.left" | "topBarComponents.right" | "topBarComponents.center" | "languages", defaultValue?: T) => T;
476
+ export declare const useBuilderProp: <T>(propKey: keyof Omit<ChaiBuilderEditorProps, ExcludedBuilderProps> | "languages", defaultValue?: T) => T;
471
477
 
472
478
  export declare const useBuilderReset: () => () => void;
473
479
 
@@ -519,8 +525,6 @@ export declare const useLanguages: () => {
519
525
  setSelectedLang: (lang: string) => void;
520
526
  };
521
527
 
522
- export declare const useLayoutVariant: () => readonly [LayoutVariant, (args_0: RESET | LayoutVariant | ((prev: LayoutVariant) => RESET | LayoutVariant)) => void];
523
-
524
528
  export declare const useLibraryBlocks: (library?: Partial<ChaiUILibrary> & {
525
529
  id: string;
526
530
  }) => {
@@ -602,6 +606,8 @@ export declare const useSelectedBreakpoints: () => [string[], Function];
602
606
  */
603
607
  export declare const useSelectedStylingBlocks: () => [TStyleBlock[], (args_0: TStyleBlock[] | ((prev: TStyleBlock[]) => TStyleBlock[])) => void];
604
608
 
609
+ export declare const useSidebarActivePanel: () => [string, (args_0: string | ((prev: string) => string)) => void];
610
+
605
611
  export declare const useStylingBreakpoint: () => [string, (args_0: string | RESET | ((prev: string) => string | RESET)) => void];
606
612
 
607
613
  export declare const useStylingState: () => [unknown, (...args: unknown[]) => unknown];