@chaibuilder/sdk 2.0.12 → 2.1.1

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,35 +1,26 @@
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';
13
11
 
12
+ export declare const ADD_BLOCK_TABS: Record<string, AddBlockTab>;
13
+
14
14
  declare type AddBlocks = {
15
15
  addCoreBlock: any;
16
16
  addPredefinedBlock: any;
17
17
  };
18
18
 
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;
19
+ declare type AddBlockTab = {
20
+ id: string;
21
+ tab: React.ComponentType;
22
+ tabContent: React.ComponentType;
23
+ };
33
24
 
34
25
  declare type AskAiResponse = {
35
26
  blocks?: Array<{
@@ -39,16 +30,6 @@ declare type AskAiResponse = {
39
30
  error?: any;
40
31
  };
41
32
 
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
33
  declare type BorderRadiusValue = false | string;
53
34
 
54
35
  declare type Breakpoint = {
@@ -59,11 +40,22 @@ declare type Breakpoint = {
59
40
  width: number;
60
41
  };
61
42
 
62
- export declare const CHAI_BUILDER_EVENTS: {
63
- OPEN_ADD_BLOCK: string;
64
- CLOSE_ADD_BLOCK: string;
65
- SHOW_BLOCK_SETTINGS: string;
66
- };
43
+ export declare const CHAI_BUILDER_PANELS: Record<string, ChaiSidebarPanel<any>>;
44
+
45
+ export declare const ChaiAddBlocksDialog: () => JSX_2.Element;
46
+
47
+ export declare const ChaiAddBlocksPanel: ({ className, showHeading, parentId, position, }: {
48
+ parentId?: string;
49
+ showHeading?: boolean;
50
+ className?: string;
51
+ position?: number;
52
+ }) => JSX_2.Element;
53
+
54
+ export declare const ChaiAskAiPanel: () => JSX_2.Element;
55
+
56
+ export declare const ChaiAskAiUserPrompt: ({ blockId }: {
57
+ blockId: string | undefined;
58
+ }) => JSX_2.Element;
67
59
 
68
60
  export declare type ChaiBlock<T = Record<string, any>> = {
69
61
  _id: string;
@@ -71,8 +63,19 @@ export declare type ChaiBlock<T = Record<string, any>> = {
71
63
  _parent?: string | null | undefined;
72
64
  _bindings?: Record<string, string>;
73
65
  _type: string;
66
+ _libBlock?: string;
74
67
  } & T;
75
68
 
69
+ export declare const ChaiBlockAttributesEditor: React_2.MemoExoticComponent<() => JSX_2.Element>;
70
+
71
+ /**
72
+ *
73
+ * @returns Block Setting
74
+ */
75
+ export declare function ChaiBlockPropsEditor(): JSX_2.Element;
76
+
77
+ export declare function ChaiBlockStyleEditor(): JSX_2.Element;
78
+
76
79
  export declare const ChaiBuilderCanvas: default_2.FC;
77
80
 
78
81
  /**
@@ -82,23 +85,43 @@ export declare const ChaiBuilderEditor: default_2.FC<ChaiBuilderEditorProps>;
82
85
 
83
86
  export declare interface ChaiBuilderEditorProps {
84
87
  /**
85
- * Permissions
88
+ * User
86
89
  */
87
- permissions?: string[];
90
+ user?: {
91
+ id: string;
92
+ name: string;
93
+ email: string;
94
+ avatar?: string;
95
+ role: string;
96
+ };
88
97
  /**
89
- * RJSF Fields and Widgets
98
+ * Permissions
90
99
  */
91
- rjsfFields?: Record<string, default_2.ComponentType<any>>;
92
- rjsfWidgets?: Record<string, default_2.ComponentType<any>>;
93
- rjsfTemplates?: Record<string, default_2.ComponentType<any>>;
100
+ permissions?: string[];
94
101
  /**
95
102
  * Optional pageId. If not provided, a random pageId will be generated
96
103
  */
97
104
  pageId?: string;
105
+ /**
106
+ * Page external data
107
+ */
98
108
  pageExternalData?: Record<string, any>;
109
+ /**
110
+ * Theme presets
111
+ */
99
112
  themePresets?: Record<string, Partial<ChaiBuilderThemeValues>>[];
113
+ /**
114
+ * Theme options
115
+ */
100
116
  themeOptions?: (defaultThemeOptions: ChaiBuilderThemeOptions) => ChaiBuilderThemeOptions;
117
+ /**
118
+ * Theme
119
+ */
101
120
  theme?: Partial<ChaiBuilderThemeValues>;
121
+ /**
122
+ * Theme panel component
123
+ * TODO: Move to registerChaiThemePanelComponent()
124
+ */
102
125
  themePanelComponent?: ReactComponentType;
103
126
  /**
104
127
  * onError callback function
@@ -109,45 +132,19 @@ export declare interface ChaiBuilderEditorProps {
109
132
  * Translations object
110
133
  */
111
134
  translations?: Record<string, Record<string, any>>;
112
- /**
113
- * onLoad callback function
114
- * @param editorInstance
115
- */
116
- onLoad?: (editorInstance: ChaiBuilderInstance) => void;
117
135
  /**
118
136
  * Custom layout component
137
+ * TODO: Move to registerChaiLayoutComponent()
119
138
  */
120
139
  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
140
  /**
140
141
  * HTML direction.
141
142
  */
142
143
  htmlDir?: "ltr" | "rtl";
143
- /**
144
- * Filter function for blocks to be shown in the builder
145
- */
146
- filterChaiBlock?: (block: any) => boolean;
147
144
  /**
148
145
  * Show debug logs
149
146
  */
150
- showDebugLogs?: boolean;
147
+ debugLogs?: boolean;
151
148
  /**
152
149
  * Auto save support
153
150
  */
@@ -160,10 +157,6 @@ export declare interface ChaiBuilderEditorProps {
160
157
  * Breakpoints
161
158
  */
162
159
  breakpoints?: Breakpoint[];
163
- /**
164
- * Editable
165
- */
166
- editable?: boolean;
167
160
  /**
168
161
  * Loading state
169
162
  */
@@ -173,27 +166,47 @@ export declare interface ChaiBuilderEditorProps {
173
166
  */
174
167
  locale?: string;
175
168
  /**
176
- * Non editable component
169
+ * Dark mode
177
170
  */
178
- nonEditableComponent?: ReactComponentType;
171
+ darkMode?: boolean;
179
172
  /**
180
- * Canvas component. Not supported with custom layout
173
+ * Import HTML support
181
174
  */
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
175
  importHTMLSupport?: boolean;
176
+ /**
177
+ * AI context
178
+ */
179
+ aiContext?: string;
180
+ /**
181
+ * Ask AI callback
182
+ */
191
183
  askAiCallBack?: (type: "styles" | "content", prompt: string, blocks: ChaiBlock[], lang: string) => Promise<AskAiResponse>;
192
184
  saveAiContextCallback?: (content: string) => Promise<true | Error>;
193
- aiContext?: string;
185
+ /**
186
+ * UI libraries
187
+ */
194
188
  uiLibraries?: Omit<ChaiUILibrary, "blocks">[];
189
+ /**
190
+ * Get library blocks
191
+ */
195
192
  getUILibraryBlocks?: (library: ChaiUILibrary) => Promise<ChaiUILibraryBlock[]>;
193
+ /**
194
+ * Get library block
195
+ */
196
196
  getUILibraryBlock?: (library: ChaiUILibrary, uiLibBlock: ChaiUILibraryBlock) => Promise<ChaiBlock[]>;
197
+ /**
198
+ * Upsert library block
199
+ */
200
+ upsertLibraryBlock?: (params: {
201
+ id?: string;
202
+ description: string;
203
+ group: string;
204
+ library: string;
205
+ name: string;
206
+ preview?: string;
207
+ }) => Promise<{
208
+ id: string;
209
+ } | Error>;
197
210
  getPartialBlocks?: () => Promise<Record<string, {
198
211
  type: string;
199
212
  name: string;
@@ -207,6 +220,10 @@ export declare interface ChaiBuilderEditorProps {
207
220
  * Blocks for the page
208
221
  */
209
222
  blocks?: ChaiBlock[];
223
+ /**
224
+ * onSave callback function
225
+ * @param saveData
226
+ */
210
227
  onSave?: ({ blocks, theme, autoSave }: SavePageData) => Promise<boolean | Error>;
211
228
  /**
212
229
  * onSaveStateChange callback function
@@ -215,48 +232,27 @@ export declare interface ChaiBuilderEditorProps {
215
232
  onSaveStateChange?: (syncStatus: "SAVED" | "SAVING" | "UNSAVED") => void;
216
233
  /**
217
234
  * Preview component
235
+ * TODO: Move to registerChaiPreviewComponent()
218
236
  */
219
237
  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
238
  /**
245
239
  * Content locale
246
240
  */
247
241
  fallbackLang?: string;
242
+ /**
243
+ * Languages
244
+ */
248
245
  languages?: Array<string>;
249
246
  /**
250
247
  * Page Types props
251
248
  */
252
249
  pageTypes?: PageType[];
250
+ /**
251
+ * Search page type items
252
+ */
253
253
  searchPageTypeItems?: (pageTypeKey: string, query: string) => Promise<PageTypeItem[] | Error>;
254
254
  }
255
255
 
256
- declare type ChaiBuilderInstance = {
257
- setBlocks: (blocks: ChaiBlock[]) => void;
258
- };
259
-
260
256
  declare type ChaiBuilderThemeOptions = {
261
257
  fontFamily: false | Record<VariableKey, string>;
262
258
  borderRadius: BorderRadiusValue;
@@ -272,6 +268,46 @@ declare type ChaiBuilderThemeValues = {
272
268
  colors: Record<string, string[]>;
273
269
  };
274
270
 
271
+ export declare function ChaiDarkModeSwitcher(): JSX_2.Element;
272
+
273
+ export declare const ChaiDefaultBlocks: ({ parentId, position, gridCols, }: {
274
+ parentId?: string;
275
+ position?: number;
276
+ gridCols?: string;
277
+ }) => JSX_2.Element;
278
+
279
+ export declare const ChaiImportHTML: ({ parentId, position }: {
280
+ parentId?: string;
281
+ position?: number;
282
+ }) => JSX_2.Element;
283
+
284
+ export declare const ChaiOutline: () => JSX_2.Element;
285
+
286
+ export declare const ChaiScreenSizes: ({ openDelay, canvas, tooltip, }: {
287
+ openDelay?: number;
288
+ canvas?: boolean;
289
+ tooltip?: boolean;
290
+ }) => JSX_2.Element;
291
+
292
+ export declare interface ChaiSidebarPanel<T> {
293
+ id: string;
294
+ position: "top" | "bottom";
295
+ view?: "standard" | "modal" | "overlay" | "drawer";
296
+ icon: React.ReactNode;
297
+ label: string;
298
+ component: ComponentType;
299
+ showIf?: (params: T) => boolean;
300
+ width?: number;
301
+ isInternal?: boolean;
302
+ }
303
+
304
+ export declare const ChaiThemeConfigPanel: React_2.FC<ThemeConfigProps>;
305
+
306
+ export declare const ChaiUILibrariesPanel: ({ parentId, position }: {
307
+ parentId?: string;
308
+ position?: number;
309
+ }) => JSX_2.Element;
310
+
275
311
  declare type ChaiUILibrary<T = Record<string, any>> = {
276
312
  id: string;
277
313
  name: string;
@@ -288,6 +324,8 @@ declare type ChaiUILibraryBlock<T = Record<string, any>> = {
288
324
  description?: string;
289
325
  } & T;
290
326
 
327
+ export declare const ChaiUndoRedo: () => JSX_2.Element;
328
+
291
329
  declare type ClassDerivedObject = {
292
330
  cls: string;
293
331
  dark: boolean;
@@ -308,18 +346,6 @@ declare type CopiedValue = string | null;
308
346
 
309
347
  declare type CopyFn = (text: string) => Promise<boolean>;
310
348
 
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
349
  declare type ExcludedBuilderProps = "blocks" | "subPages" | "brandingOptions" | "dataProviders";
324
350
 
325
351
  /**
@@ -332,40 +358,21 @@ export declare function generateBlockId(length?: number, chars?: string): string
332
358
  * @param html
333
359
  * @returns Blocks JSON
334
360
  */
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
- };
361
+ declare const getBlocksFromHTML: (html: string) => ChaiBlock[];
362
+ export { getBlocksFromHTML as convertHTMLToChaiBlocks }
363
+ export { getBlocksFromHTML }
345
364
 
346
365
  declare type HSLColor = string;
347
366
 
348
367
  export { i18n }
349
368
 
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;
369
+ declare type MediaManagerProps = {
370
+ close: () => void;
371
+ onSelect: (urls: string[]) => void;
372
+ mode?: "image" | "video" | "audio";
366
373
  };
367
374
 
368
- declare type OutlineMenuItems = OutlineMenuItem[];
375
+ export declare const mergeClasses: (...inputs: ClassValue[]) => string;
369
376
 
370
377
  declare type PageType = {
371
378
  key: string;
@@ -393,11 +400,35 @@ export declare const PERMISSIONS: {
393
400
  SAVE_PAGE: string;
394
401
  EDIT_STYLES: string;
395
402
  IMPORT_HTML: string;
403
+ CREATE_LIBRARY_BLOCK: string;
404
+ CREATE_LIBRARY_GROUP: string;
405
+ EDIT_LIBRARY_BLOCK: string;
406
+ EDIT_LIBRARY_GROUP: string;
407
+ DELETE_LIBRARY_BLOCK: string;
408
+ DELETE_LIBRARY_GROUP: string;
396
409
  };
397
410
 
398
411
  declare type ReactComponentType = default_2.ComponentType<any>;
399
412
 
400
- export { registerChaiBlock }
413
+ export declare const registerBlockSettingField: (id: string, component: React.ComponentType<any>) => void;
414
+
415
+ export declare const registerBlockSettingTemplate: (id: string, component: React.ComponentType<any>) => void;
416
+
417
+ export declare const registerBlockSettingWidget: (id: string, component: React.ComponentType<any>) => void;
418
+
419
+ export declare const registerChaiAddBlockTab: (id: string, tab: Omit<AddBlockTab, "id">) => void;
420
+
421
+ export declare const registerChaiMediaManager: (component: React.ComponentType<MediaManagerProps>) => void;
422
+
423
+ export declare const registerChaiSidebarPanel: <T extends Record<string, any>>(panelId: string, panelOptions: Omit<ChaiSidebarPanel<T>, "id">) => void;
424
+
425
+ export declare const registerChaiTopBar: (component: React.ComponentType) => void;
426
+
427
+ export declare const RJSF_EXTENSIONS: Record<string, {
428
+ id: string;
429
+ component: React.ComponentType<any>;
430
+ type: string;
431
+ }>;
401
432
 
402
433
  declare type SavePageData = {
403
434
  autoSave: boolean;
@@ -405,14 +436,6 @@ declare type SavePageData = {
405
436
  theme?: ChaiBuilderThemeValues;
406
437
  };
407
438
 
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
439
  declare interface ThemeConfigProps {
417
440
  className?: string;
418
441
  }
@@ -425,13 +448,6 @@ declare type TStyleBlock = {
425
448
  prop: string;
426
449
  };
427
450
 
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
451
  export declare const useAddBlock: () => AddBlocks;
436
452
 
437
453
  export declare const useAddClassesToBlocks: () => (blockIds: Array<string>, newClasses: Array<string>, undo?: boolean) => void;
@@ -448,6 +464,8 @@ export declare const useBlockHighlight: () => {
448
464
  lastHighlighted: HTMLElement;
449
465
  };
450
466
 
467
+ export declare const useBlockSettingComponents: (type: "widget" | "field" | "template") => Record<string, React.ComponentType<any>>;
468
+
451
469
  export declare const useBlocksStore: () => [any[], (args_0: any[] | ((prev: any[]) => any[])) => void];
452
470
 
453
471
  export declare const useBlocksStoreUndoableActions: () => {
@@ -467,7 +485,7 @@ export declare const useBlocksStoreUndoableActions: () => {
467
485
  */
468
486
  export declare const useBrandingOptions: () => readonly [any, (args_0: any) => void];
469
487
 
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;
488
+ export declare const useBuilderProp: <T>(propKey: keyof Omit<ChaiBuilderEditorProps, ExcludedBuilderProps> | "languages", defaultValue?: T) => T;
471
489
 
472
490
  export declare const useBuilderReset: () => () => void;
473
491
 
@@ -478,6 +496,8 @@ export declare const useCanvasDisplayWidth: () => readonly [number, (args_0: num
478
496
  */
479
497
  export declare const useCanvasZoom: () => [number, (args_0: number | RESET | ((prev: number) => number | RESET)) => void];
480
498
 
499
+ export declare const useChaiSidebarPanels: (position: "top" | "bottom") => any;
500
+
481
501
  /**
482
502
  * Custom hook to access the current state of the code editor.
483
503
  * @category Hooks
@@ -519,8 +539,6 @@ export declare const useLanguages: () => {
519
539
  setSelectedLang: (lang: string) => void;
520
540
  };
521
541
 
522
- export declare const useLayoutVariant: () => readonly [LayoutVariant, (args_0: RESET | LayoutVariant | ((prev: LayoutVariant) => RESET | LayoutVariant)) => void];
523
-
524
542
  export declare const useLibraryBlocks: (library?: Partial<ChaiUILibrary> & {
525
543
  id: string;
526
544
  }) => {
@@ -529,6 +547,8 @@ export declare const useLibraryBlocks: (library?: Partial<ChaiUILibrary> & {
529
547
  resetLibrary: () => void;
530
548
  };
531
549
 
550
+ export declare const useMediaManagerComponent: () => ComponentType<MediaManagerProps>;
551
+
532
552
  export declare const usePartailBlocksStore: () => {
533
553
  getPartailBlocks: (partailBlock: string) => any;
534
554
  reset: () => void;
@@ -602,6 +622,8 @@ export declare const useSelectedBreakpoints: () => [string[], Function];
602
622
  */
603
623
  export declare const useSelectedStylingBlocks: () => [TStyleBlock[], (args_0: TStyleBlock[] | ((prev: TStyleBlock[]) => TStyleBlock[])) => void];
604
624
 
625
+ export declare const useSidebarActivePanel: () => [string, (args_0: string | ((prev: string) => string)) => void];
626
+
605
627
  export declare const useStylingBreakpoint: () => [string, (args_0: string | RESET | ((prev: string) => string | RESET)) => void];
606
628
 
607
629
  export declare const useStylingState: () => [unknown, (...args: unknown[]) => unknown];
@@ -618,6 +640,8 @@ export declare const useTheme: () => readonly [{
618
640
 
619
641
  export declare const useThemeOptions: () => ChaiBuilderThemeOptions;
620
642
 
643
+ export declare const useTopBarComponent: () => ComponentType< {}>;
644
+
621
645
  export { useTranslation }
622
646
 
623
647
  export declare const useUILibraryBlocks: () => {