@chaibuilder/sdk 4.0.0-beta.7 → 4.0.0-beta.8

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.
Files changed (127) hide show
  1. package/README.md +1 -3
  2. package/dist/{2SSKDMRQ-DDOgISWg.cjs → 2SSKDMRQ-DHv4u_0i.cjs} +1 -1
  3. package/dist/{2SSKDMRQ-hL7THuKW.js → 2SSKDMRQ-DewwiCoQ.js} +2 -2
  4. package/dist/{AP7HFJJL-BsLQ13V_.js → AP7HFJJL-ComnZw7J.js} +1 -1
  5. package/dist/{AP7HFJJL-tcAhVllC.cjs → AP7HFJJL-cz754qhG.cjs} +1 -1
  6. package/dist/{IconPicker-FLSVAZxx.js → IconPicker-2H9IGKMS.js} +2 -2
  7. package/dist/{IconPicker-J1KLNrSB.cjs → IconPicker-U0Z2dWeR.cjs} +1 -1
  8. package/dist/{WDYDFRGG-BTj8AXV6.cjs → WDYDFRGG-BfRX3M58.cjs} +1 -1
  9. package/dist/{WDYDFRGG-Yi0eNS2V.js → WDYDFRGG-vy7nMYD4.js} +2 -2
  10. package/dist/{active-in-another-tab-Dozn833d.js → active-in-another-tab-5hn17Jeq.js} +3 -3
  11. package/dist/{active-in-another-tab-BtAiatqq.cjs → active-in-another-tab-ijahI5qu.cjs} +1 -1
  12. package/dist/{add-new-language-page-DD-CAoAQ.js → add-new-language-page-DmOyPy0u.js} +4 -4
  13. package/dist/{add-new-language-page-9AMizlES.cjs → add-new-language-page-vmNKNx-e.cjs} +1 -1
  14. package/dist/{add-new-page-uZKCk9eB.js → add-new-page-NHScAQn8.js} +2 -2
  15. package/dist/{add-new-page-BS9vPnFG.cjs → add-new-page-XDuCkOyb.cjs} +1 -1
  16. package/dist/{ai-panel-content-PovaKJaj.cjs → ai-panel-content-BDqW16AW.cjs} +1 -1
  17. package/dist/{ai-panel-content-CK4XOkEh.js → ai-panel-content-CHJ0JcQI.js} +4 -4
  18. package/dist/{ai-panel-default-lang-BtLjUl9d.js → ai-panel-default-lang-BIomgsN0.js} +4 -4
  19. package/dist/{ai-panel-default-lang-B37k5ADH.cjs → ai-panel-default-lang-HeYWpbMu.cjs} +2 -2
  20. package/dist/{ai-panel-other-lang-CdQmASqv.cjs → ai-panel-other-lang-BMelEs3p.cjs} +1 -1
  21. package/dist/{ai-panel-other-lang-Dp1MNaLi.js → ai-panel-other-lang-CbAgG-qX.js} +3 -3
  22. package/dist/{ai-prompt-input-BT-mEdTX.js → ai-prompt-input-BH8LOVT4.js} +2 -2
  23. package/dist/{ai-prompt-input-Dtym4w8J.cjs → ai-prompt-input-C_GG6nwq.cjs} +1 -1
  24. package/dist/{ai-translation-prompt-B-lH7emI.cjs → ai-translation-prompt-CkHaFv5I.cjs} +1 -1
  25. package/dist/{ai-translation-prompt-B17GK1QR.js → ai-translation-prompt-DxsNw8YR.js} +2 -2
  26. package/dist/{code-display-DloSPyPr.cjs → code-display-9Onx6RCq.cjs} +1 -1
  27. package/dist/{code-display-Ck81Id9K.js → code-display-oa1j0ri7.js} +1 -1
  28. package/dist/{code-editor-EZT2pMsU.js → code-editor-CGBAc-A6.js} +1 -1
  29. package/dist/{code-editor-CUeNiMzA.cjs → code-editor-GV8ibQ4h.cjs} +1 -1
  30. package/dist/{continue-editing-in-this-client-DMZOc36k.cjs → continue-editing-in-this-client-DKHP0pq8.cjs} +1 -1
  31. package/dist/{continue-editing-in-this-client-CS7C6h9Q.js → continue-editing-in-this-client-Da8ab_9d.js} +3 -3
  32. package/dist/core.cjs +1 -1
  33. package/dist/core.d.ts +1 -90
  34. package/dist/core.js +22 -34
  35. package/dist/css-import-modal-B4j26_cO.cjs +13 -0
  36. package/dist/{css-import-modal-s7t5gZQo.js → css-import-modal-CcZVLsF9.js} +5 -4
  37. package/dist/{delete-design-token-Mbw_6sYI.cjs → delete-design-token-3-WwqXMO.cjs} +1 -1
  38. package/dist/{delete-design-token-C1smbx4E.js → delete-design-token-DzINIVtO.js} +1 -1
  39. package/dist/{delete-page-B7J3t0FN.cjs → delete-page-B7ODELqM.cjs} +1 -1
  40. package/dist/{delete-page-2GfBi8Iv.js → delete-page-DwZDMwfI.js} +3 -3
  41. package/dist/{design-token-usage-DyO3xM-F.js → design-token-usage-DQf180Lg.js} +2 -2
  42. package/dist/{design-token-usage-BoGOULG8.cjs → design-token-usage-Dy08kcIc.cjs} +1 -1
  43. package/dist/{digital-asset-manager-DDk2ucTE.cjs → digital-asset-manager-C7subULa.cjs} +1 -1
  44. package/dist/{digital-asset-manager-Cz3Nlrzl.js → digital-asset-manager-CDy9kHZO.js} +4 -4
  45. package/dist/{duplicate-page-Dw3U4wTT.cjs → duplicate-page-CWQ9aMd9.cjs} +1 -1
  46. package/dist/{duplicate-page-BwAY4Ssm.js → duplicate-page-DTnSztlr.js} +4 -4
  47. package/dist/{dynamic-page-selector-CvBFyX2F.cjs → dynamic-page-selector-DJuxLcsM.cjs} +1 -1
  48. package/dist/{dynamic-page-selector-sViJuQlU.js → dynamic-page-selector-DYW3ov_u.js} +3 -3
  49. package/dist/{image-editor-AIsccrqC.cjs → image-editor-C4H3AkZK.cjs} +1 -1
  50. package/dist/{image-editor-BgGQuESa.js → image-editor-DLeSST0K.js} +1 -1
  51. package/dist/{index-RYr8kQdI.js → index-BK0xWO1z.js} +5132 -5602
  52. package/dist/{index-BwH1mRm_.cjs → index-BRJCj7c_.cjs} +2 -2
  53. package/dist/index-Bm8iS2OH.cjs +160 -0
  54. package/dist/{index-B7eWP_hB.js → index-D5d4QDq7.js} +19 -21
  55. package/dist/{json-diff-viewer-Svw-kbhe.js → json-diff-viewer-BYHieVod.js} +3 -3
  56. package/dist/{json-diff-viewer-B2A78udz.cjs → json-diff-viewer-g6SY62bl.cjs} +1 -1
  57. package/dist/{lang-panel-Bnc-9wkM.js → lang-panel-BG1GMn-1.js} +4 -4
  58. package/dist/{lang-panel-AmEkoWid.cjs → lang-panel-Dm1eOO2J.cjs} +1 -1
  59. package/dist/{manage-design-tokens-BBkh1t4w.js → manage-design-tokens-BdWQUHhw.js} +3 -3
  60. package/dist/{manage-design-tokens-B2fG80bi.cjs → manage-design-tokens-XWs_B6jo.cjs} +1 -1
  61. package/dist/{mark-as-template-0CPzZnk-.js → mark-as-template-D2XxagVO.js} +3 -3
  62. package/dist/{mark-as-template-CE6tRoQy.cjs → mark-as-template-DUFnfVM3.cjs} +1 -1
  63. package/dist/{nested-path-selector-content-SmfjElr-.cjs → nested-path-selector-content-CQOx2L9C.cjs} +1 -1
  64. package/dist/{nested-path-selector-content-kGznHufl.js → nested-path-selector-content-Wd6-Eql0.js} +2 -2
  65. package/dist/{no-language-page-content-DXsAPDZd.js → no-language-page-content-BOv6TZIk.js} +3 -3
  66. package/dist/{no-language-page-content-B4bQLc4K.cjs → no-language-page-content-C11uF6hs.cjs} +1 -1
  67. package/dist/{no-language-page-dialog-BC8NHzK2.cjs → no-language-page-dialog-CY5XhXsC.cjs} +1 -1
  68. package/dist/{no-language-page-dialog-BpPqmw9a.js → no-language-page-dialog-DIXyKRJq.js} +2 -2
  69. package/dist/{page-creator-Bazn6yH4.js → page-creator-WX9lMrJY.js} +4 -4
  70. package/dist/{page-creator-82qTbBj4.cjs → page-creator-zSUFF4eT.cjs} +1 -1
  71. package/dist/{page-lock-CRFyqKZE.js → page-lock-D9miLZjm.js} +2 -2
  72. package/dist/{page-lock-D2iFZDUK.cjs → page-lock-DGhR_url.cjs} +1 -1
  73. package/dist/{page-locked-dialog-GKfQEOmk.js → page-locked-dialog-CNCUCcvH.js} +3 -3
  74. package/dist/{page-locked-dialog-xLqvKzax.cjs → page-locked-dialog-DTLnbfuP.cjs} +1 -1
  75. package/dist/{page-manager-new-DItY2hjd.js → page-manager-new-BFFOLh-l.js} +4 -4
  76. package/dist/{page-manager-new-Bn2QKjbf.cjs → page-manager-new-Dd2c-Q_O.cjs} +1 -1
  77. package/dist/{page-manager-search-and-filter-Dc4ky-qV.cjs → page-manager-search-and-filter-BKdQUJ2W.cjs} +1 -1
  78. package/dist/{page-manager-search-and-filter-CPa8IXdd.js → page-manager-search-and-filter-C1IWF_4d.js} +3 -3
  79. package/dist/page-revisions-content-D0cflnj1.cjs +1 -0
  80. package/dist/{page-revisions-content-CH-PZK0O.js → page-revisions-content-DHapiLck.js} +75 -67
  81. package/dist/pages.cjs +1 -1
  82. package/dist/pages.d.ts +2 -1
  83. package/dist/pages.js +1 -1
  84. package/dist/{publish-pages-content-CSJCFElu.js → publish-pages-content-Bd2zJHtK.js} +4 -4
  85. package/dist/{publish-pages-content-BzJDObqr.cjs → publish-pages-content-BqLcnKry.cjs} +1 -1
  86. package/dist/{register-chai-top-bar-ESJHs5s-.js → register-chai-top-bar-CX_JkRJn.js} +78 -78
  87. package/dist/register-chai-top-bar-DWTuRU53.cjs +1 -0
  88. package/dist/render.d.ts +2 -1
  89. package/dist/{rte-widget-modal-BfXcA7OP.cjs → rte-widget-modal-DiB5BjH1.cjs} +1 -1
  90. package/dist/{rte-widget-modal-5T81P_hg.js → rte-widget-modal-RS8PMKOn.js} +7 -7
  91. package/dist/runtime-client.cjs +1 -0
  92. package/dist/runtime-client.d.ts +158 -0
  93. package/dist/runtime-client.js +32 -0
  94. package/dist/runtime.cjs +1 -1
  95. package/dist/runtime.d.ts +1 -163
  96. package/dist/runtime.js +71 -72
  97. package/dist/{save-to-lib-MtWKSVeN.js → save-to-lib--6ZXHEbC.js} +3 -3
  98. package/dist/{save-to-lib-DGAdSa-0.cjs → save-to-lib-BXJvaC1N.cjs} +1 -1
  99. package/dist/{selected-block-display-DLt_nMn9.cjs → selected-block-display-BfpJda4h.cjs} +1 -1
  100. package/dist/{selected-block-display-CB1-hVR5.js → selected-block-display-CUnCqXQw.js} +3 -3
  101. package/dist/{seo-panel-CRzzw4FW.js → seo-panel-Bs-FcY1A.js} +3 -3
  102. package/dist/{seo-panel-_kGXE9MC.cjs → seo-panel-CQITMfZ6.cjs} +1 -1
  103. package/dist/{shared-json-ld-CXukkDeS.js → shared-json-ld-7EujD341.js} +3 -3
  104. package/dist/{shared-json-ld-DoRgzDPC.cjs → shared-json-ld-DDXXi-Mj.cjs} +1 -1
  105. package/dist/{slug-input-Dp187Tiy.cjs → slug-input-CsVJAr7r.cjs} +1 -1
  106. package/dist/{slug-input-CeEQ0zyv.js → slug-input-DoEIq5rs.js} +2 -2
  107. package/dist/{take-over-request-C9J3_rev.js → take-over-request-C14kJ356.js} +3 -3
  108. package/dist/{take-over-request-CXuakFBm.cjs → take-over-request-D5Oo3MPo.cjs} +1 -1
  109. package/dist/{theme-panel-footer-DvwsyHNQ.js → theme-panel-footer-Dvknelm8.js} +3 -3
  110. package/dist/{theme-panel-footer-CWZ0qs13.cjs → theme-panel-footer-Eeibz2JA.cjs} +1 -1
  111. package/dist/{translation-warning-modal-DEt_ExQp.cjs → translation-warning-modal-CPzdHzqq.cjs} +1 -1
  112. package/dist/{translation-warning-modal-_aBp5ZZQ.js → translation-warning-modal-YlzP2XoO.js} +2 -2
  113. package/dist/{unmark-as-template-BYL5naYx.cjs → unmark-as-template-BGDwuCnv.cjs} +1 -1
  114. package/dist/{unmark-as-template-JN-cDUV_.js → unmark-as-template-CPJvQk7L.js} +3 -3
  115. package/dist/{unpublish-page-B06iZEIO.cjs → unpublish-page-BMowW5wT.cjs} +1 -1
  116. package/dist/{unpublish-page-DqwBY2yI.js → unpublish-page-DlFHLlmI.js} +3 -3
  117. package/dist/web-blocks.cjs +1 -1
  118. package/dist/web-blocks.js +43 -43
  119. package/dist/{web-preview-h39D3TUh.js → web-preview-BUnv3jIc.js} +2 -2
  120. package/dist/{web-preview-wRgRY3Tv.cjs → web-preview-D8GQHCjs.cjs} +1 -1
  121. package/package.json +8 -7
  122. package/dist/css-import-modal-kHB0ramf.cjs +0 -13
  123. package/dist/index-B-rSiAp_.cjs +0 -1
  124. package/dist/index-Dxfyt4d4.js +0 -39
  125. package/dist/index-xYnNKovy.cjs +0 -160
  126. package/dist/page-revisions-content-CcLFI4YK.cjs +0 -1
  127. package/dist/register-chai-top-bar-BqwKw4uy.cjs +0 -1
package/dist/runtime.d.ts CHANGED
@@ -1,46 +1,18 @@
1
- import { ComponentType } from 'react';
2
1
  import { default as default_2 } from 'react';
3
- import { ReactNode } from 'react';
4
2
  import { RJSFSchema } from '@rjsf/utils';
5
3
  import { UiSchema } from '@rjsf/utils';
6
4
 
7
- export declare const ADD_BLOCK_TABS: Record<string, AddBlockTab>;
8
-
9
- export declare type AddBlockTab = {
10
- id: string;
11
- tab: React.ComponentType;
12
- tabContent: React.ComponentType;
13
- };
14
-
15
5
  export declare const builderProp: (options: ChaiBlockPropSchema) => ChaiBlockPropSchema;
16
6
 
17
- export declare const CHAI_BUILDER_PANELS: Record<string, ChaiSidebarPanel>;
18
-
19
7
  export declare let CHAI_GLOBAL_DATA_PROVIDER: (args: {
20
8
  lang: string;
21
9
  draft: boolean;
22
10
  inBuilder: boolean;
23
11
  }) => Promise<any>;
24
12
 
25
- declare type ChaiAsset = {
26
- url: string;
27
- id?: string;
28
- thumbnailUrl?: string;
29
- description?: string;
30
- width?: number;
31
- height?: number;
32
- };
33
-
34
13
  export declare type ChaiAsyncProp<T> = T | undefined;
35
14
 
36
- export declare type ChaiBlock<BlockProps = Record<string, any>> = {
37
- _id: string;
38
- _type: string;
39
- _name?: string;
40
- _parent?: string | null;
41
- } & BlockProps;
42
-
43
- declare type ChaiBlock_2<T = Record<string, any>> = {
15
+ declare type ChaiBlock<T = Record<string, any>> = {
44
16
  _id: string;
45
17
  _name?: string;
46
18
  _parent?: string | null | undefined;
@@ -49,14 +21,6 @@ declare type ChaiBlock_2<T = Record<string, any>> = {
49
21
  partialBlockId?: string;
50
22
  } & T;
51
23
 
52
- declare type ChaiBlock_3<T = Record<string, any>> = {
53
- _id: string;
54
- _name?: string;
55
- _parent?: string | null | undefined;
56
- _type: string;
57
- _libBlock?: string;
58
- } & T;
59
-
60
24
  export declare type ChaiBlockComponentProps<BlockProps, PageData = Record<string, unknown>> = ChaiBlock<BlockProps> & {
61
25
  $loading?: boolean;
62
26
  blockProps: Record<string, string>;
@@ -169,12 +133,6 @@ declare type ChaiDynamicPage = {
169
133
  primaryPage?: string;
170
134
  };
171
135
 
172
- declare type ChaiFlagOptions = {
173
- key: string;
174
- value?: any;
175
- description?: string;
176
- };
177
-
178
136
  export declare type ChaiFont = ChaiFontViaUrl | ChaiFontViaSrc;
179
137
 
180
138
  export declare type ChaiFontViaSrc = {
@@ -196,33 +154,6 @@ export declare type ChaiFontViaUrl = {
196
154
  fallback: string;
197
155
  };
198
156
 
199
- declare type ChaiLibrary<T = Record<string, any>> = {
200
- id: string;
201
- name: string;
202
- blocks?: ChaiLibraryBlock[];
203
- description?: string;
204
- } & T;
205
-
206
- declare type ChaiLibraryBlock<T = Record<string, any>> = {
207
- id: string;
208
- group: string;
209
- name: string;
210
- preview?: string;
211
- tags?: string[];
212
- description?: string;
213
- } & T;
214
-
215
- declare type ChaiLibraryConfig<T> = {
216
- id: string;
217
- name: string;
218
- description: string;
219
- getBlocksList: (library: ChaiLibrary) => Promise<ChaiLibraryBlock<T>[]>;
220
- getBlock: ({ library, block, }: {
221
- library: ChaiLibrary;
222
- block: ChaiLibraryBlock<T>;
223
- }) => Promise<HTMLString | ChaiBlock_2[]>;
224
- };
225
-
226
157
  export declare interface ChaiPageProps {
227
158
  slug: string;
228
159
  searchParams?: Record<string, string>;
@@ -244,23 +175,6 @@ export declare interface ChaiServerBlockDefinition<T = Record<string, any>, K =
244
175
  suspenseFallback?: default_2.ComponentType<any>;
245
176
  }
246
177
 
247
- export declare interface ChaiSidebarPanel {
248
- id: string;
249
- position: "top" | "bottom";
250
- view?: "standard" | "modal" | "overlay" | "drawer";
251
- button: React.ComponentType<{
252
- isActive: boolean;
253
- show: () => void;
254
- panelId: string;
255
- position: "top" | "bottom";
256
- }>;
257
- label: string;
258
- panel?: ComponentType;
259
- width?: number;
260
- isInternal?: boolean;
261
- icon?: React.ReactNode;
262
- }
263
-
264
178
  export declare type ChaiStyles = {
265
179
  [key: string]: string;
266
180
  };
@@ -320,8 +234,6 @@ export declare const getChaiGlobalData: (args: {
320
234
  inBuilder: boolean;
321
235
  }) => Promise<any>;
322
236
 
323
- export declare const getChaiLibrary: (id: string) => ChaiLibraryConfig<any>;
324
-
325
237
  export declare const getChaiPageType: (key: keyof typeof PAGE_TYPES) => ChaiBuilderPageType;
326
238
 
327
239
  export declare const getChaiPageTypes: () => ChaiBuilderPageType[];
@@ -330,26 +242,10 @@ export declare const getDefaultBlockProps: (type: keyof typeof REGISTERED_CHAI_B
330
242
 
331
243
  export declare const getI18nBlockProps: (type: keyof typeof REGISTERED_CHAI_BLOCKS) => ChaiBlockDefinition<Record<string, any>, Record<string, any>> | ChaiServerBlockDefinition<Record<string, any>, Record<string, any>> | never[];
332
244
 
333
- export declare const getPreImportHTML: (code: string) => Promise<string>;
334
-
335
245
  export declare const getRegisteredChaiBlock: (type: keyof typeof REGISTERED_CHAI_BLOCKS) => ChaiBlockDefinition | null;
336
246
 
337
247
  export declare const getRegisteredFont: (family: string) => ChaiFont | undefined;
338
248
 
339
- declare type HTMLString = string;
340
-
341
- export declare const IfChaiFeatureFlag: ({ flagKey, children }: {
342
- flagKey: string;
343
- children: React.ReactNode;
344
- }) => ReactNode;
345
-
346
- export declare type MediaManagerProps = {
347
- assetId?: string;
348
- close: () => void;
349
- onSelect: (assets: ChaiAsset | ChaiAsset[]) => void;
350
- mode?: "image" | "video" | "audio";
351
- };
352
-
353
249
  export declare const PAGE_TYPES: Record<string, ChaiBuilderPageType>;
354
250
 
355
251
  declare type PageTypeSearchResult = {
@@ -358,24 +254,12 @@ declare type PageTypeSearchResult = {
358
254
  slug?: string;
359
255
  };
360
256
 
361
- export declare const registerBlockSettingField: (id: string, component: React.ComponentType<any>) => void;
362
-
363
- export declare const registerBlockSettingTemplate: (id: string, component: React.ComponentType<any>) => void;
364
-
365
- export declare const registerBlockSettingWidget: (id: string, component: React.ComponentType<any>) => void;
366
-
367
- export declare const registerChaiAddBlockTab: (id: string, tab: Omit<AddBlockTab, "id">) => void;
368
-
369
257
  export declare const registerChaiBlock: <T extends Record<string, any> = Record<string, any>, K extends Record<string, any> = Record<string, any>>(component: default_2.ComponentType<ChaiBlockComponentProps<T>>, options: ChaiBlockDefinitionOptions<T, K>) => void;
370
258
 
371
259
  export declare const registerChaiBlockSchema: (blockSchema: ChaiBlockSchema) => ChaiBlockSchemas;
372
260
 
373
261
  export declare function registerChaiCollection<T = Record<any, any>>(id: string, collection: Omit<CollectionConfig<T>, "id">): void;
374
262
 
375
- export declare const registerChaiFeatureFlag: (key: string, flagOptions: Omit<ChaiFlagOptions, "key">) => void;
376
-
377
- export declare const registerChaiFeatureFlags: (flags: Record<string, Omit<ChaiFlagOptions, "key">>) => void;
378
-
379
263
  export declare const registerChaiFont: (family: string, font: Omit<ChaiFont, "family">) => void;
380
264
 
381
265
  export declare const registerChaiGlobalDataProvider: <T>(globalDataProvider: (args: {
@@ -384,42 +268,16 @@ export declare const registerChaiGlobalDataProvider: <T>(globalDataProvider: (ar
384
268
  inBuilder: boolean;
385
269
  }) => Promise<T>) => void;
386
270
 
387
- export declare const registerChaiLibrary: <T extends Record<string, any> = Record<string, any>>(id: string, library: Omit<ChaiLibraryConfig<T>, "id">) => void;
388
-
389
- export declare const registerChaiMediaManager: (component: React.ComponentType<MediaManagerProps>) => void;
390
-
391
271
  export declare const registerChaiPageType: (key: string, pageTypeOptions: Omit<ChaiBuilderPageType, "key" | "hasSlug">) => void;
392
272
 
393
273
  export declare const registerChaiPartialType: (key: string, pageTypeOptions: Omit<ChaiBuilderPageType, "key">) => void;
394
274
 
395
- export declare const registerChaiPreImportHTMLHook: (fn: (code: string) => Promise<string>) => void;
396
-
397
- export declare const registerChaiSaveToLibrary: (component: ComponentType<SaveToLibraryProps>) => void;
398
-
399
275
  export declare const registerChaiServerBlock: <T extends Record<string, any> = Record<string, any>, K extends Record<string, any> = Record<string, any>>(component: default_2.ComponentType<ChaiBlockComponentProps<T>>, options: Pick<ChaiBlockDefinition<T, K>, "type" | "dataProvider" | "i18nProps" | "aiProps">) => void;
400
276
 
401
- export declare const registerChaiSidebarPanel: (panelId: string, panelOptions: Omit<ChaiSidebarPanel, "id">) => void;
402
-
403
- export declare const registerChaiTopBar: (component: React.ComponentType) => void;
404
-
405
277
  declare const REGISTERED_CHAI_BLOCKS: Record<string, ChaiBlockDefinition | ChaiServerBlockDefinition>;
406
278
 
407
- export declare const resetSaveToLibrary: () => void;
408
-
409
- export declare const RJSF_EXTENSIONS: Record<string, {
410
- id: string;
411
- component: React.ComponentType<any>;
412
- type: string;
413
- }>;
414
-
415
279
  export declare const runtimeProp: (options: ChaiBlockPropSchema) => ChaiBlockPropSchema;
416
280
 
417
- export declare type SaveToLibraryProps = {
418
- blockId: string;
419
- blocks: ChaiBlock_3[];
420
- close: () => void;
421
- };
422
-
423
281
  export declare const setChaiBlockComponent: <T extends Record<string, any> = Record<string, any>>(type: keyof typeof REGISTERED_CHAI_BLOCKS, component: default_2.ComponentType<ChaiBlockComponentProps<T>>) => void;
424
282
 
425
283
  export declare const setChaiBlockDataProvider: <K extends Record<string, any> = Record<string, any>>(type: string, dataProvider: (args: {
@@ -444,30 +302,10 @@ export declare const stylesProp: (defaultClasses?: string) => ChaiBlockPropSchem
444
302
 
445
303
  export declare const syncBlocksWithDefaults: (blocks: ChaiBlock[]) => ChaiBlock[];
446
304
 
447
- export declare const useBlockSettingComponents: (type: "widget" | "field" | "template") => Record<string, React.ComponentType<any>>;
448
-
449
- export declare const useChaiAddBlockTabs: () => AddBlockTab[];
450
-
451
- export declare const useChaiFeatureFlag: (flagKey: string) => boolean;
452
-
453
- export declare const useChaiFeatureFlags: () => Record<string, ChaiFlagOptions>;
454
-
455
- export declare const useChaiLibraries: () => ChaiLibraryConfig<any>[];
456
-
457
- export declare const useChaiSidebarPanels: (position: "top" | "bottom") => ChaiSidebarPanel[];
458
-
459
- export declare const useMediaManagerComponent: () => ComponentType<MediaManagerProps>;
460
-
461
305
  export declare const useRegisteredChaiBlock: (type: keyof typeof REGISTERED_CHAI_BLOCKS) => ChaiBlockDefinition<Record<string, any>, Record<string, any>> | ChaiServerBlockDefinition<Record<string, any>, Record<string, any>> | null;
462
306
 
463
307
  export declare const useRegisteredChaiBlocks: () => Record<string, ChaiBlockDefinition<Record<string, any>, Record<string, any>> | ChaiServerBlockDefinition<Record<string, any>, Record<string, any>>>;
464
308
 
465
309
  export declare const useRegisteredFonts: () => ChaiFont[];
466
310
 
467
- export declare const useSaveToLibraryComponent: () => ComponentType<SaveToLibraryProps> | null;
468
-
469
- export declare const useToggleChaiFeatureFlag: (flagKey: string) => () => void;
470
-
471
- export declare const useTopBarComponent: () => ComponentType< {}>;
472
-
473
311
  export { }
package/dist/runtime.js CHANGED
@@ -1,74 +1,73 @@
1
- import { S as i, b as o, d as g, r as l, a as C, s as h } from "./index-Dxfyt4d4.js";
2
- import { A as n, C as p, I as u, R as B, k as d, o as P, a as k, b as S, r as m, c as T, e as F, f as b, j as L, m as y, p as A, q as f, v as I, x as D, t as R, u as v, d as _, h as E, g as x, l as M, w as O, n as H, s as G, i as N, y as j } from "./register-chai-top-bar-ESJHs5s-.js";
3
- import { b as q, C as w, P as J, a as K, g as U, d as V, f as X, e as Y, r as z, c as Q, h as Z, i as $ } from "./register-partial-type-BjtdfKHE.js";
4
- import { a as ae, g as se, r as re, u as te } from "./fonts-DRly3Wzd.js";
5
- import { s as e } from "./core-Dr7QYemB.js";
6
- import { c as oe, g as ge, a as le, b as Ce, d as he, e as ce, r as ne, f as pe, h as ue, i as Be, u as de, j as Pe } from "./core-Dr7QYemB.js";
7
- const s = e;
1
+ import { keys as u, intersection as r, get as c, each as d, isEmpty as p, omit as h } from "lodash-es";
2
+ import { b as S, C as $, P as T, a as v, g as A, d as b, f as F, e as I, r as L, c as x, h as G, i as O } from "./register-partial-type-BjtdfKHE.js";
3
+ import { s as C } from "./core-Dr7QYemB.js";
4
+ import { c as Y, g as K, a as H, b as N, d as V, e as W, r as q, f as z, h as J, i as M, u as Q, j as U } from "./core-Dr7QYemB.js";
5
+ import { a as Z, g as ee, r as te, u as re } from "./fonts-DRly3Wzd.js";
6
+ const B = C, a = "#styles:", f = (e) => {
7
+ const i = ["_type", "_id", "_parent", "_bindings", "_name"], o = ["$loading", "blockProps", "inBuilder", "lang", "draft", "pageProps", "pageData", "children"], t = u(e.properties);
8
+ if (r(t, i).length > 0)
9
+ throw new Error(`Reserved props are not allowed: ${r(t, i).join(", ")}`);
10
+ if (r(t, o).length > 0)
11
+ throw new Error(`Runtime props are not allowed in schema: ${r(t, o).join(", ")}`);
12
+ const s = c(e, "properties", {}), n = {};
13
+ return d(s, (l, g) => {
14
+ p(l.ui) || (n[g] = { ...l.ui }, delete s[g].ui);
15
+ }), {
16
+ schema: p(s) ? {} : { ...h(e, ["ui"]) },
17
+ uiSchema: { ...c(e, "ui", {}), ...n }
18
+ };
19
+ }, y = (e = "") => ({
20
+ type: "string",
21
+ styles: !0,
22
+ default: `${a},${e}`,
23
+ ui: { "ui:widget": "hidden" }
24
+ }), k = (e = "") => ({
25
+ type: "string",
26
+ styles: !0,
27
+ default: `${a},${e}`,
28
+ ui: { "ui:widget": "hidden" }
29
+ }), R = (e) => (console.warn("runtimeProp is deprecated, use builderProp instead"), {
30
+ runtime: !0,
31
+ ...e
32
+ }), _ = (e) => ({
33
+ builderProp: !0,
34
+ ...e
35
+ }), w = (e) => `${a},${e}`;
8
36
  export {
9
- n as ADD_BLOCK_TABS,
10
- p as CHAI_BUILDER_PANELS,
11
- q as CHAI_GLOBAL_DATA_PROVIDER,
12
- w as COLLECTIONS,
13
- u as IfChaiFeatureFlag,
14
- J as PAGE_TYPES,
15
- B as RJSF_EXTENSIONS,
16
- i as StylesProp,
17
- o as builderProp,
18
- oe as closestBlockProp,
19
- g as defaultChaiStyles,
20
- ge as getAIBlockProps,
21
- ae as getAllRegisteredFonts,
22
- le as getBlockFormSchemas,
23
- K as getChaiCollection,
24
- U as getChaiCollections,
25
- V as getChaiGlobalData,
26
- d as getChaiLibrary,
27
- X as getChaiPageType,
28
- Y as getChaiPageTypes,
29
- Ce as getDefaultBlockProps,
30
- he as getI18nBlockProps,
31
- P as getPreImportHTML,
32
- ce as getRegisteredChaiBlock,
33
- se as getRegisteredFont,
34
- k as registerBlockSettingField,
35
- S as registerBlockSettingTemplate,
36
- m as registerBlockSettingWidget,
37
- T as registerChaiAddBlockTab,
38
- ne as registerChaiBlock,
39
- l as registerChaiBlockSchema,
40
- z as registerChaiCollection,
41
- F as registerChaiFeatureFlag,
42
- b as registerChaiFeatureFlags,
43
- re as registerChaiFont,
44
- Q as registerChaiGlobalDataProvider,
45
- L as registerChaiLibrary,
46
- y as registerChaiMediaManager,
47
- Z as registerChaiPageType,
48
- $ as registerChaiPartialType,
49
- A as registerChaiPreImportHTMLHook,
50
- f as registerChaiSaveToLibrary,
51
- pe as registerChaiServerBlock,
52
- I as registerChaiSidebarPanel,
53
- D as registerChaiTopBar,
54
- R as resetSaveToLibrary,
55
- C as runtimeProp,
56
- ue as setChaiBlockComponent,
57
- s as setChaiBlockDataProvider,
58
- e as setChaiServerBlockDataProvider,
59
- h as stylesProp,
60
- Be as syncBlocksWithDefaults,
61
- v as useBlockSettingComponents,
62
- _ as useChaiAddBlockTabs,
63
- E as useChaiFeatureFlag,
64
- x as useChaiFeatureFlags,
65
- M as useChaiLibraries,
66
- O as useChaiSidebarPanels,
67
- H as useMediaManagerComponent,
68
- de as useRegisteredChaiBlock,
69
- Pe as useRegisteredChaiBlocks,
70
- te as useRegisteredFonts,
71
- G as useSaveToLibraryComponent,
72
- N as useToggleChaiFeatureFlag,
73
- j as useTopBarComponent
37
+ S as CHAI_GLOBAL_DATA_PROVIDER,
38
+ $ as COLLECTIONS,
39
+ T as PAGE_TYPES,
40
+ y as StylesProp,
41
+ _ as builderProp,
42
+ Y as closestBlockProp,
43
+ w as defaultChaiStyles,
44
+ K as getAIBlockProps,
45
+ Z as getAllRegisteredFonts,
46
+ H as getBlockFormSchemas,
47
+ v as getChaiCollection,
48
+ A as getChaiCollections,
49
+ b as getChaiGlobalData,
50
+ F as getChaiPageType,
51
+ I as getChaiPageTypes,
52
+ N as getDefaultBlockProps,
53
+ V as getI18nBlockProps,
54
+ W as getRegisteredChaiBlock,
55
+ ee as getRegisteredFont,
56
+ q as registerChaiBlock,
57
+ f as registerChaiBlockSchema,
58
+ L as registerChaiCollection,
59
+ te as registerChaiFont,
60
+ x as registerChaiGlobalDataProvider,
61
+ G as registerChaiPageType,
62
+ O as registerChaiPartialType,
63
+ z as registerChaiServerBlock,
64
+ R as runtimeProp,
65
+ J as setChaiBlockComponent,
66
+ B as setChaiBlockDataProvider,
67
+ C as setChaiServerBlockDataProvider,
68
+ k as stylesProp,
69
+ M as syncBlocksWithDefaults,
70
+ Q as useRegisteredChaiBlock,
71
+ U as useRegisteredChaiBlocks,
72
+ re as useRegisteredFonts
74
73
  };
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
- import { B as b, z as L } from "./register-chai-top-bar-ESJHs5s-.js";
3
- import { c as j, a6 as se, a7 as ie, P as oe, az as le, ai as ce, aA as de, L as P } from "./index-RYr8kQdI.js";
4
- import { ar as D, as as G, A as _, ay as ue } from "./index-B7eWP_hB.js";
2
+ import { B as b, z as L } from "./register-chai-top-bar-CX_JkRJn.js";
3
+ import { c as j, a6 as se, a7 as ie, P as oe, az as le, ai as ce, aA as de, L as P } from "./index-BK0xWO1z.js";
4
+ import { ar as D, as as G, A as _, ay as ue } from "./index-D5d4QDq7.js";
5
5
  import { useQuery as K, useMutation as U, useQueryClient as me } from "@tanstack/react-query";
6
6
  import { toast as N } from "sonner";
7
7
  import { Trash2 as Y, Plus as pe, ImageIcon as fe, X as he, AlertCircle as ge } from "lucide-react";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./register-chai-top-bar-BqwKw4uy.cjs"),b=require("./index-xYnNKovy.cjs"),x=require("./index-BwH1mRm_.cjs"),C=require("@tanstack/react-query"),j=require("sonner"),E=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=s=>{const r=x.useApiUrl(),l=x.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{s?s(t):j.toast.success("Block saved successfully")},onError:t=>{console.error("Error saving block:",t),j.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=s=>{const r=x.useApiUrl(),l=x.useFetch();return C.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,s],enabled:!!s,queryFn:async()=>{if(!s)return null;try{return await l(r,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:s}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=s=>{const r=x.useApiUrl(),l=x.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{s?s():j.toast.success("Block deleted successfully")},onError:t=>{console.error("Error deleting block:",t),j.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:s,libBlockId:r,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[d,o]=i.useState(!1),c=b.useUpdateBlocksPropsRealtime(),y=ee(()=>{c([s],{_libBlockId:void 0}),j.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),y.mutate(r)},g=e.jsxs(u.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:d,children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]});return e.jsxs(b.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(b.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(b.PopoverContent,{className:"z-[9999] w-72 p-4",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',m,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(u.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:d,children:"Cancel"}),e.jsx(u.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:d,children:d?"Deleting...":"Delete"})]})]})})]})},se=({blockId:s,libBlockId:r,blockName:l,size:t="sm",className:m="",close:f})=>{const[d,o]=i.useState(!1);return e.jsx(te,{blockId:s,libBlockId:r,isOpen:d,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(u.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})},re=()=>{const s=x.useApiUrl(),r=x.useFetch(),l=C.useQueryClient(),{data:t=[],isLoading:m,error:f}=C.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await r(s,{action:"GET_LIBRARY_GROUPS"})||[]}catch(c){return console.error("Error fetching library groups:",c),[]}}}),{mutateAsync:d,isPending:o}=C.useMutation({mutationFn:async c=>{if(!c.trim())throw new Error("Group name is required");return r(s,{action:"CREATE_BLOCK_GROUP",data:{name:c}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),j.toast.success("Group created successfully")},onError:c=>{console.error("Error creating group:",c),j.toast.error("Failed to create group",{description:c instanceof Error?c.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:d,isCreating:o}},ne=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),d=i.useRef(null),{groups:o}=re(),[c,y]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),p=i.useMemo(()=>[...o,...c.filter(n=>!o.some(B=>B.id===n.id))],[o,c]),g=()=>{const n=m.trim();if(!n)return;const B={id:n,name:n};y(w=>[...w,B]),r(B.id),f(""),t(!1)};i.useEffect(()=>{l&&d.current&&d.current.focus()},[l]);const h=n=>{n.key==="Enter"&&(n.preventDefault(),g())};return i.useEffect(()=>{s&&!p.some(n=>n.id===s)&&r("")},[s,p,r]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(u.Input,{ref:d,placeholder:"Enter new group name",value:m,onChange:n=>f(n.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(u.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:s,onChange:n=>r(n.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(n=>e.jsx("option",{value:n.id,children:n.name},`lib-${n.id}`))}),c.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:c.filter(n=>!o.some(B=>B.id===n.id)).map(n=>e.jsx("option",{value:n.id,children:n.name},`local-${n.id}`))})]}),e.jsx(u.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(E.Plus,{className:"h-4 w-4"})})]})},ae=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async c=>{var p;const y=(p=c.target.files)==null?void 0:p[0];if(y)try{t(!0);let g=y;y.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(y));const h=new FileReader;h.onloadend=()=>{r(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),j.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[r]),d=()=>{r(""),m.current&&(m.current.value="")},o=()=>{var c;(c=m.current)==null||c.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(u.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(E.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),s&&e.jsx(u.Button,{type:"button",variant:"outline",size:"icon",onClick:d,children:e.jsx(E.X,{className:"h-4 w-4"})})]}),s&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:s,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=s=>{const{blocks:r,close:l,blockId:t}=s,{getPartailBlocks:m}=b.usePartialBlocksStore(),f=r.find(a=>a._id===t),d=f==null?void 0:f._libBlockId,o=!!d,c=i.useMemo(()=>r.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[r]),y=i.useMemo(()=>{let a=[];for(const v of r)if(v._type==="PartialBlock"||v._type==="GlobalBlock"){let k=m(v.partialBlockId);v._parent&&(k==null?void 0:k.length)>0&&(k=k.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",v._parent),T))),a=[...a,...k]}else a.push(v);return a},[r,m]),[p,g]=i.useState(""),[h,n]=i.useState(""),[B,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=b.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=b.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),j.toast.success("Block delinked from library"),l()},{data:I,isLoading:P,isError:G}=Z(d);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{I&&!P&&(g(I.name||""),n(I.group||""),w(I.description||""),_(I.preview||""),F(!1))},[I,P]),i.useEffect(()=>{const a=p.trim().length>=2,v=h.trim()!=="";M(a&&v)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=b.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),j.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const v=y.map(k=>(R.has(k,"_libBlockId")&&delete k._libBlockId,k));U.mutate({name:p.trim(),group:h,blocks:v,description:B.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:d}:{}})},L=U.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(u.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(u.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[c&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(E.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(u.Input,{id:"name",placeholder:"Enter block name",value:p,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:n}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(u.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:B,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:d,blockName:p,className:"mr-auto",close:l}),e.jsx(u.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(u.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./register-chai-top-bar-DWTuRU53.cjs"),b=require("./index-Bm8iS2OH.cjs"),x=require("./index-BRJCj7c_.cjs"),C=require("@tanstack/react-query"),j=require("sonner"),E=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=s=>{const r=x.useApiUrl(),l=x.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{s?s(t):j.toast.success("Block saved successfully")},onError:t=>{console.error("Error saving block:",t),j.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=s=>{const r=x.useApiUrl(),l=x.useFetch();return C.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,s],enabled:!!s,queryFn:async()=>{if(!s)return null;try{return await l(r,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:s}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=s=>{const r=x.useApiUrl(),l=x.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{s?s():j.toast.success("Block deleted successfully")},onError:t=>{console.error("Error deleting block:",t),j.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:s,libBlockId:r,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[d,o]=i.useState(!1),c=b.useUpdateBlocksPropsRealtime(),y=ee(()=>{c([s],{_libBlockId:void 0}),j.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),y.mutate(r)},g=e.jsxs(u.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:d,children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]});return e.jsxs(b.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(b.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(b.PopoverContent,{className:"z-[9999] w-72 p-4",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',m,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(u.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:d,children:"Cancel"}),e.jsx(u.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:d,children:d?"Deleting...":"Delete"})]})]})})]})},se=({blockId:s,libBlockId:r,blockName:l,size:t="sm",className:m="",close:f})=>{const[d,o]=i.useState(!1);return e.jsx(te,{blockId:s,libBlockId:r,isOpen:d,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(u.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})},re=()=>{const s=x.useApiUrl(),r=x.useFetch(),l=C.useQueryClient(),{data:t=[],isLoading:m,error:f}=C.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await r(s,{action:"GET_LIBRARY_GROUPS"})||[]}catch(c){return console.error("Error fetching library groups:",c),[]}}}),{mutateAsync:d,isPending:o}=C.useMutation({mutationFn:async c=>{if(!c.trim())throw new Error("Group name is required");return r(s,{action:"CREATE_BLOCK_GROUP",data:{name:c}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),j.toast.success("Group created successfully")},onError:c=>{console.error("Error creating group:",c),j.toast.error("Failed to create group",{description:c instanceof Error?c.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:d,isCreating:o}},ne=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),d=i.useRef(null),{groups:o}=re(),[c,y]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),p=i.useMemo(()=>[...o,...c.filter(n=>!o.some(B=>B.id===n.id))],[o,c]),g=()=>{const n=m.trim();if(!n)return;const B={id:n,name:n};y(w=>[...w,B]),r(B.id),f(""),t(!1)};i.useEffect(()=>{l&&d.current&&d.current.focus()},[l]);const h=n=>{n.key==="Enter"&&(n.preventDefault(),g())};return i.useEffect(()=>{s&&!p.some(n=>n.id===s)&&r("")},[s,p,r]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(u.Input,{ref:d,placeholder:"Enter new group name",value:m,onChange:n=>f(n.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(u.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:s,onChange:n=>r(n.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(n=>e.jsx("option",{value:n.id,children:n.name},`lib-${n.id}`))}),c.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:c.filter(n=>!o.some(B=>B.id===n.id)).map(n=>e.jsx("option",{value:n.id,children:n.name},`local-${n.id}`))})]}),e.jsx(u.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(E.Plus,{className:"h-4 w-4"})})]})},ae=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async c=>{var p;const y=(p=c.target.files)==null?void 0:p[0];if(y)try{t(!0);let g=y;y.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(y));const h=new FileReader;h.onloadend=()=>{r(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),j.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[r]),d=()=>{r(""),m.current&&(m.current.value="")},o=()=>{var c;(c=m.current)==null||c.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(u.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(E.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),s&&e.jsx(u.Button,{type:"button",variant:"outline",size:"icon",onClick:d,children:e.jsx(E.X,{className:"h-4 w-4"})})]}),s&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:s,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=s=>{const{blocks:r,close:l,blockId:t}=s,{getPartailBlocks:m}=b.usePartialBlocksStore(),f=r.find(a=>a._id===t),d=f==null?void 0:f._libBlockId,o=!!d,c=i.useMemo(()=>r.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[r]),y=i.useMemo(()=>{let a=[];for(const v of r)if(v._type==="PartialBlock"||v._type==="GlobalBlock"){let k=m(v.partialBlockId);v._parent&&(k==null?void 0:k.length)>0&&(k=k.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",v._parent),T))),a=[...a,...k]}else a.push(v);return a},[r,m]),[p,g]=i.useState(""),[h,n]=i.useState(""),[B,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=b.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=b.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),j.toast.success("Block delinked from library"),l()},{data:I,isLoading:P,isError:G}=Z(d);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{I&&!P&&(g(I.name||""),n(I.group||""),w(I.description||""),_(I.preview||""),F(!1))},[I,P]),i.useEffect(()=>{const a=p.trim().length>=2,v=h.trim()!=="";M(a&&v)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=b.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),j.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const v=y.map(k=>(R.has(k,"_libBlockId")&&delete k._libBlockId,k));U.mutate({name:p.trim(),group:h,blocks:v,description:B.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:d}:{}})},L=U.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(u.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(u.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[c&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(E.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(u.Input,{id:"name",placeholder:"Enter block name",value:p,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:n}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(u.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:B,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:d,blockName:p,className:"mr-auto",close:l}),e.jsx(u.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(u.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
@@ -1,4 +1,4 @@
1
- "use strict";const o=require("react/jsx-runtime"),r=require("./register-chai-top-bar-BqwKw4uy.cjs"),m=require("lucide-react"),i=require("react"),p=require("use-stick-to-bottom"),T=require("streamdown");require("@radix-ui/react-slot");const P=require("class-variance-authority"),_=require("./index-xYnNKovy.cjs");require("clsx");require("tailwind-merge");const z=require("@radix-ui/react-tooltip"),j=require("@radix-ui/react-use-controllable-state"),B=require("@radix-ui/react-collapsible"),D=require("framer-motion"),f=require("./index-BwH1mRm_.cjs"),I=require("react-i18next");function h(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const L=h(i),S=h(z),b=h(B),G=({className:e,...t})=>o.jsx(p.StickToBottom,{className:r.cn("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),$=({className:e,...t})=>o.jsx(p.StickToBottom.Content,{className:r.cn("flex flex-col gap-8 p-4",e),...t}),F=({className:e,title:t="No messages yet",description:s="Start a conversation to see messages here",icon:n,children:a,...l})=>o.jsx("div",{className:r.cn("flex size-full flex-col items-center justify-center gap-3 p-8 text-center",e),...l,children:a??o.jsxs(o.Fragment,{children:[n&&o.jsx("div",{className:"text-muted-foreground",children:n}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("h3",{className:"text-sm font-medium",children:t}),s&&o.jsx("p",{className:"text-sm text-muted-foreground",children:s})]})]})}),Q=({className:e,...t})=>{const{isAtBottom:s,scrollToBottom:n}=p.useStickToBottomContext(),a=i.useCallback(()=>{n()},[n]);return!s&&o.jsx(r.Button,{className:r.cn("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",e),onClick:a,size:"icon",type:"button",variant:"outline",...t,children:o.jsx(m.ArrowDownIcon,{className:"size-4"})})};P.cva("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",{variants:{orientation:{horizontal:"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",vertical:"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"}},defaultVariants:{orientation:"horizontal"}});const V=L.forwardRef(({className:e,sideOffset:t=4,...s},n)=>o.jsx(S.Content,{ref:n,sideOffset:t,className:r.cn("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",e),...s}));V.displayName=S.Content.displayName;const K=({className:e,from:t,...s})=>o.jsx("div",{className:r.cn("group flex w-full max-w-[80%] flex-col gap-2",t==="user"?"is-user ml-auto justify-end":"is-assistant",e),...s}),Y=({children:e,className:t,...s})=>o.jsx("div",{className:r.cn("is-user:dark flex w-fit flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",t),...s,children:e});i.createContext(null);const w=i.memo(({className:e,...t})=>o.jsx(T.Streamdown,{className:r.cn("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),...t}),(e,t)=>e.children===t.children);w.displayName="MessageResponse";const J=b.Root,X=b.CollapsibleTrigger,H=b.CollapsibleContent,W=({children:e,as:t="p",className:s,duration:n=2,spread:a=2})=>{const l=D.motion.create(t),g=i.useMemo(()=>((e==null?void 0:e.length)??0)*a,[e,a]);return o.jsx(l,{animate:{backgroundPosition:"0% center"},className:r.cn("relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",s),initial:{backgroundPosition:"100% center"},style:{"--spread":`${g}px`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},transition:{repeat:Number.POSITIVE_INFINITY,duration:n,ease:"linear"},children:e})},E=i.memo(W),R=i.createContext(null),Z=()=>{const e=i.useContext(R);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},ee=1e3,te=1e3,y=i.memo(({className:e,isStreaming:t=!1,open:s,defaultOpen:n=!0,onOpenChange:a,duration:l,children:g,...U})=>{const[c,d]=j.useControllableState({prop:s,defaultProp:n,onChange:a}),[M,v]=j.useControllableState({prop:l,defaultProp:void 0}),[N,q]=i.useState(!1),[u,C]=i.useState(null);i.useEffect(()=>{t?u===null&&C(Date.now()):u!==null&&(v(Math.ceil((Date.now()-u)/te)),C(null))},[t,u,v]),i.useEffect(()=>{if(n&&!t&&c&&!N){const x=setTimeout(()=>{d(!1),q(!0)},ee);return()=>clearTimeout(x)}},[t,c,n,d,N]);const O=x=>{d(x)};return o.jsx(R.Provider,{value:{isStreaming:t,isOpen:c,setIsOpen:d,duration:M},children:o.jsx(J,{className:r.cn("not-prose mb-4",e),onOpenChange:O,open:c,...U,children:g})})}),oe=(e,t)=>e||t===0?o.jsx(E,{duration:1,children:"Thinking..."}):t===void 0?o.jsx("p",{children:"Thought for a few seconds"}):o.jsxs("p",{children:["Thought for ",t," seconds"]}),A=i.memo(({className:e,children:t,...s})=>{const{isStreaming:n,isOpen:a,duration:l}=Z();return o.jsx(X,{className:r.cn("flex w-full items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground",e),...s,children:t??o.jsxs(o.Fragment,{children:[o.jsx(m.BrainIcon,{className:"size-4"}),oe(n,l),o.jsx(m.ChevronDownIcon,{className:r.cn("size-4 transition-transform",a?"rotate-180":"rotate-0")})]})})}),k=i.memo(({className:e,children:t,...s})=>o.jsx(H,{className:r.cn("mt-4 text-sm","text-muted-foreground outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2",e),...s,children:o.jsx(T.Streamdown,{...s,children:t})}));y.displayName="Reasoning";A.displayName="ReasoningTrigger";k.displayName="ReasoningContent";const se=({className:e,content:t,isLoading:s=!1,...n})=>o.jsx("div",{className:r.cn("is-assistant flex w-full max-w-[80%] flex-col gap-2",e),...n,children:o.jsx("div",{className:"flex w-fit flex-col gap-2 overflow-hidden text-sm",children:o.jsx("div",{className:"flex items-center gap-2 rounded-lg border border-muted-foreground/20 bg-muted/50 p-3",children:o.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[s&&o.jsx(E,{duration:1.5,children:t}),!s&&o.jsx("div",{className:"text-xs text-muted-foreground",children:t})]})})})});function ne({userInput:e,language:t="en",currentHtml:s}){const n=f.LANGUAGES[t]||"English";return s&&s.trim().length>0?`
1
+ "use strict";const o=require("react/jsx-runtime"),r=require("./register-chai-top-bar-DWTuRU53.cjs"),m=require("lucide-react"),i=require("react"),p=require("use-stick-to-bottom"),T=require("streamdown");require("@radix-ui/react-slot");const P=require("class-variance-authority"),_=require("./index-Bm8iS2OH.cjs");require("clsx");require("tailwind-merge");const z=require("@radix-ui/react-tooltip"),j=require("@radix-ui/react-use-controllable-state"),B=require("@radix-ui/react-collapsible"),D=require("framer-motion"),f=require("./index-BRJCj7c_.cjs"),I=require("react-i18next");function h(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const L=h(i),S=h(z),b=h(B),G=({className:e,...t})=>o.jsx(p.StickToBottom,{className:r.cn("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),$=({className:e,...t})=>o.jsx(p.StickToBottom.Content,{className:r.cn("flex flex-col gap-8 p-4",e),...t}),F=({className:e,title:t="No messages yet",description:s="Start a conversation to see messages here",icon:n,children:a,...l})=>o.jsx("div",{className:r.cn("flex size-full flex-col items-center justify-center gap-3 p-8 text-center",e),...l,children:a??o.jsxs(o.Fragment,{children:[n&&o.jsx("div",{className:"text-muted-foreground",children:n}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("h3",{className:"text-sm font-medium",children:t}),s&&o.jsx("p",{className:"text-sm text-muted-foreground",children:s})]})]})}),Q=({className:e,...t})=>{const{isAtBottom:s,scrollToBottom:n}=p.useStickToBottomContext(),a=i.useCallback(()=>{n()},[n]);return!s&&o.jsx(r.Button,{className:r.cn("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",e),onClick:a,size:"icon",type:"button",variant:"outline",...t,children:o.jsx(m.ArrowDownIcon,{className:"size-4"})})};P.cva("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",{variants:{orientation:{horizontal:"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",vertical:"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"}},defaultVariants:{orientation:"horizontal"}});const V=L.forwardRef(({className:e,sideOffset:t=4,...s},n)=>o.jsx(S.Content,{ref:n,sideOffset:t,className:r.cn("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",e),...s}));V.displayName=S.Content.displayName;const K=({className:e,from:t,...s})=>o.jsx("div",{className:r.cn("group flex w-full max-w-[80%] flex-col gap-2",t==="user"?"is-user ml-auto justify-end":"is-assistant",e),...s}),Y=({children:e,className:t,...s})=>o.jsx("div",{className:r.cn("is-user:dark flex w-fit flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",t),...s,children:e});i.createContext(null);const w=i.memo(({className:e,...t})=>o.jsx(T.Streamdown,{className:r.cn("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),...t}),(e,t)=>e.children===t.children);w.displayName="MessageResponse";const J=b.Root,X=b.CollapsibleTrigger,H=b.CollapsibleContent,W=({children:e,as:t="p",className:s,duration:n=2,spread:a=2})=>{const l=D.motion.create(t),g=i.useMemo(()=>((e==null?void 0:e.length)??0)*a,[e,a]);return o.jsx(l,{animate:{backgroundPosition:"0% center"},className:r.cn("relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",s),initial:{backgroundPosition:"100% center"},style:{"--spread":`${g}px`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},transition:{repeat:Number.POSITIVE_INFINITY,duration:n,ease:"linear"},children:e})},E=i.memo(W),R=i.createContext(null),Z=()=>{const e=i.useContext(R);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},ee=1e3,te=1e3,y=i.memo(({className:e,isStreaming:t=!1,open:s,defaultOpen:n=!0,onOpenChange:a,duration:l,children:g,...U})=>{const[c,d]=j.useControllableState({prop:s,defaultProp:n,onChange:a}),[M,v]=j.useControllableState({prop:l,defaultProp:void 0}),[N,q]=i.useState(!1),[u,C]=i.useState(null);i.useEffect(()=>{t?u===null&&C(Date.now()):u!==null&&(v(Math.ceil((Date.now()-u)/te)),C(null))},[t,u,v]),i.useEffect(()=>{if(n&&!t&&c&&!N){const x=setTimeout(()=>{d(!1),q(!0)},ee);return()=>clearTimeout(x)}},[t,c,n,d,N]);const O=x=>{d(x)};return o.jsx(R.Provider,{value:{isStreaming:t,isOpen:c,setIsOpen:d,duration:M},children:o.jsx(J,{className:r.cn("not-prose mb-4",e),onOpenChange:O,open:c,...U,children:g})})}),oe=(e,t)=>e||t===0?o.jsx(E,{duration:1,children:"Thinking..."}):t===void 0?o.jsx("p",{children:"Thought for a few seconds"}):o.jsxs("p",{children:["Thought for ",t," seconds"]}),A=i.memo(({className:e,children:t,...s})=>{const{isStreaming:n,isOpen:a,duration:l}=Z();return o.jsx(X,{className:r.cn("flex w-full items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground",e),...s,children:t??o.jsxs(o.Fragment,{children:[o.jsx(m.BrainIcon,{className:"size-4"}),oe(n,l),o.jsx(m.ChevronDownIcon,{className:r.cn("size-4 transition-transform",a?"rotate-180":"rotate-0")})]})})}),k=i.memo(({className:e,children:t,...s})=>o.jsx(H,{className:r.cn("mt-4 text-sm","text-muted-foreground outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2",e),...s,children:o.jsx(T.Streamdown,{...s,children:t})}));y.displayName="Reasoning";A.displayName="ReasoningTrigger";k.displayName="ReasoningContent";const se=({className:e,content:t,isLoading:s=!1,...n})=>o.jsx("div",{className:r.cn("is-assistant flex w-full max-w-[80%] flex-col gap-2",e),...n,children:o.jsx("div",{className:"flex w-fit flex-col gap-2 overflow-hidden text-sm",children:o.jsx("div",{className:"flex items-center gap-2 rounded-lg border border-muted-foreground/20 bg-muted/50 p-3",children:o.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[s&&o.jsx(E,{duration:1.5,children:t}),!s&&o.jsx("div",{className:"text-xs text-muted-foreground",children:t})]})})})});function ne({userInput:e,language:t="en",currentHtml:s}){const n=f.LANGUAGES[t]||"English";return s&&s.trim().length>0?`
2
2
  MODE: EDIT
3
3
  CURRENT HTML:
4
4
  ${s}
@@ -1,5 +1,5 @@
1
1
  import { jsx as o, jsxs as l, Fragment as f } from "react/jsx-runtime";
2
- import { E as r, B as E } from "./register-chai-top-bar-ESJHs5s-.js";
2
+ import { E as r, B as E } from "./register-chai-top-bar-CX_JkRJn.js";
3
3
  import { ArrowDownIcon as O, BrainIcon as D, ChevronDownIcon as P, X as $ } from "lucide-react";
4
4
  import * as B from "react";
5
5
  import { useCallback as _, memo as d, createContext as S, useMemo as G, useState as C, useEffect as T, useContext as j } from "react";
@@ -7,14 +7,14 @@ import { StickToBottom as R, useStickToBottomContext as Q } from "use-stick-to-b
7
7
  import { Streamdown as y } from "streamdown";
8
8
  import "@radix-ui/react-slot";
9
9
  import { cva as F } from "class-variance-authority";
10
- import { ao as K } from "./index-RYr8kQdI.js";
10
+ import { ao as K } from "./index-BK0xWO1z.js";
11
11
  import "clsx";
12
12
  import "tailwind-merge";
13
13
  import * as A from "@radix-ui/react-tooltip";
14
14
  import { useControllableState as w } from "@radix-ui/react-use-controllable-state";
15
15
  import * as x from "@radix-ui/react-collapsible";
16
16
  import { motion as V } from "framer-motion";
17
- import { L as h } from "./index-B7eWP_hB.js";
17
+ import { L as h } from "./index-D5d4QDq7.js";
18
18
  import { useTranslation as Y } from "react-i18next";
19
19
  const Te = ({ className: e, ...t }) => /* @__PURE__ */ o(
20
20
  R,
@@ -1,9 +1,9 @@
1
1
  import { jsx as t, jsxs as o } from "react/jsx-runtime";
2
- import { l as ve, as as xe, ar as Ne, A as we, L as ee, aw as Se, aK as De, aL as Oe, i as be, ay as je, aM as Le, aN as Ie, aO as T, aP as Ee, aE as te } from "./index-B7eWP_hB.js";
3
- import { n as z, D as ke, d as Te, e as Ce, f as Fe, p as Je, o as Ae, ai as Pe, as as Re, at as Be, au as $, L as S, T as se } from "./index-RYr8kQdI.js";
2
+ import { l as ve, as as xe, ar as Ne, A as we, L as ee, aw as Se, aK as De, aL as Oe, i as be, ay as je, aM as Le, aN as Ie, aO as T, aP as Ee, aE as te } from "./index-D5d4QDq7.js";
3
+ import { n as z, D as ke, d as Te, e as Ce, f as Fe, p as Je, o as Ae, ai as Pe, as as Re, at as Be, au as $, L as S, T as se } from "./index-BK0xWO1z.js";
4
4
  import { find as qe, get as g, isEqual as ne, isEmpty as Ue } from "lodash-es";
5
5
  import { useMemo as _e, useRef as ae, useState as J, useEffect as oe } from "react";
6
- import { B as R, D as Ve, F as Ge, z as A } from "./register-chai-top-bar-ESJHs5s-.js";
6
+ import { B as R, D as Ve, F as Ge, z as A } from "./register-chai-top-bar-CX_JkRJn.js";
7
7
  import { useTranslation as Me } from "react-i18next";
8
8
  import { toast as b } from "sonner";
9
9
  import { useMutation as He } from "@tanstack/react-query";
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-BwH1mRm_.cjs"),r=require("./index-xYnNKovy.cjs"),u=require("lodash-es"),w=require("react"),f=require("./register-chai-top-bar-BqwKw4uy.cjs"),ie=require("react-i18next"),O=require("sonner"),de=require("@tanstack/react-query"),K=require("lucide-react"),G=require("./get-seo-defaults-Cw7vFt-B.cjs"),ue=()=>{const{selectedLang:t}=r.useLanguages(),{data:p,isFetching:n}=i.useLanguagePages();return{data:w.useMemo(()=>u.find(p,{lang:t||""})||{},[p,t]),isFetching:n}},pe=()=>{var x;const p=(x=document.getElementById("canvas-iframe").contentDocument)==null?void 0:x.body.innerHTML;if(!p)return null;const d=new DOMParser().parseFromString(p,"text/html");d.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(h=>h.remove()),d.querySelectorAll("*").forEach(h=>{Array.from(h.attributes).forEach(g=>h.removeAttribute(g.name))});const l=d.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(l).map(h=>`<${h.tagName.toLowerCase()}>${h.innerHTML}</${h.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},R=({keyword:t,onComplete:p,field:n})=>{const d=i.useFetch(),l=i.useApiUrl(),{selectedLang:N,fallbackLang:x}=r.useLanguages(),{mutate:h,isPending:g}=de.useMutation({mutationFn:async()=>{const I=pe();return await d(l,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:n,lang:N||x,pageContent:I,keyword:t}})},onSuccess:I=>{p({fieldValue:I.field})},onError:I=>{p({fieldValue:null,error:I.message})}});return e.jsx(f.Button,{disabled:g,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>h(),children:g?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},he=(t,p)=>{if(!t)return{success:!1,error:"Empty response from AI"};try{let n=t;if(typeof n=="string"&&(/^".*"$/.test(n)&&(n=n.replace(/^"(.*)"$/,"$1"),n=n.replace(/\\\\/g,"___DOUBLE_BACKSLASH___").replace(/\\n/g,`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-BRJCj7c_.cjs"),r=require("./index-Bm8iS2OH.cjs"),u=require("lodash-es"),w=require("react"),f=require("./register-chai-top-bar-DWTuRU53.cjs"),ie=require("react-i18next"),O=require("sonner"),de=require("@tanstack/react-query"),K=require("lucide-react"),G=require("./get-seo-defaults-Cw7vFt-B.cjs"),ue=()=>{const{selectedLang:t}=r.useLanguages(),{data:p,isFetching:n}=i.useLanguagePages();return{data:w.useMemo(()=>u.find(p,{lang:t||""})||{},[p,t]),isFetching:n}},pe=()=>{var x;const p=(x=document.getElementById("canvas-iframe").contentDocument)==null?void 0:x.body.innerHTML;if(!p)return null;const d=new DOMParser().parseFromString(p,"text/html");d.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(h=>h.remove()),d.querySelectorAll("*").forEach(h=>{Array.from(h.attributes).forEach(g=>h.removeAttribute(g.name))});const l=d.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(l).map(h=>`<${h.tagName.toLowerCase()}>${h.innerHTML}</${h.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},R=({keyword:t,onComplete:p,field:n})=>{const d=i.useFetch(),l=i.useApiUrl(),{selectedLang:N,fallbackLang:x}=r.useLanguages(),{mutate:h,isPending:g}=de.useMutation({mutationFn:async()=>{const I=pe();return await d(l,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:n,lang:N||x,pageContent:I,keyword:t}})},onSuccess:I=>{p({fieldValue:I.field})},onError:I=>{p({fieldValue:null,error:I.message})}});return e.jsx(f.Button,{disabled:g,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>h(),children:g?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},he=(t,p)=>{if(!t)return{success:!1,error:"Empty response from AI"};try{let n=t;if(typeof n=="string"&&(/^".*"$/.test(n)&&(n=n.replace(/^"(.*)"$/,"$1"),n=n.replace(/\\\\/g,"___DOUBLE_BACKSLASH___").replace(/\\n/g,`
2
2
  `).replace(/\\"/g,'"').replace(/___DOUBLE_BACKSLASH___/g,"\\")),p==="jsonLD"||p==="metaOther")){n.includes("```")&&(n=n.replace(/^```json\s*/i,"").replace(/^```\s*/,"").replace(/\s*```$/m,"")),n=n.trim();try{JSON.parse(n)}catch{return{success:!1,error:"The AI response is not valid JSON. Please try again or edit manually."}}}return{success:!0,value:n}}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ge=({isOpen:t,onClose:p,onSave:n,onDiscard:d,isSaving:l=!1,fromLanguage:N,toLanguage:x})=>{const h=i.LANGUAGES[N]||N,g=i.LANGUAGES[x]||x;return e.jsx(r.Dialog,{open:t,onOpenChange:p,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(r.DialogDescription,{children:['You have unsaved changes in the SEO for "',h,'" version. Do you want to save these changes before switching to "',g,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(f.Button,{variant:"outline",onClick:d,disabled:l,children:"Discard Changes"}),e.jsx(f.Button,{onClick:n,disabled:l,children:l?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},xe=(t,p)=>{const n=t.selectionStart||0,d=t.selectionEnd||0,l=t.value,N=l.substring(0,n),x=l.substring(d),h=`{{${p}}}`,g=N+""+h+x,I=n+0+h.length;return{value:g,newCursorPos:I}},Q=()=>{const{t}=ie.useTranslation(),[,p]=r.useSidebarActivePanel(),{data:n}=i.useChaiCurrentPage(),{data:d}=i.useBuilderPageData(),{data:l,isFetching:N}=ue(),x=l==null?void 0:l.seo,h=w.useRef(null),[g,I]=w.useState("seo"),F=n==null?void 0:n.id,Y=n==null?void 0:n.pageType,E=i.usePageType(Y),{selectedLang:M,fallbackLang:X}=r.useLanguages(),m=M||X,[H,P]=w.useState(!1),[Z,$]=w.useState(!1),[ee,q]=w.useState(!1),[b,B]=w.useState(null),[o,D]=w.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...x}),A=w.useRef({}),{mutate:se,isPending:U}=i.useUpdatePage(),y=U||H||Z,{hasPermission:te}=r.usePermissions(),a=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ne]=i.usePagesProps(),oe=u.get(ne,"features.canResetSeoToDefault",!1),W=!M||o.jsonLD!=="{}";w.useEffect(()=>{if(!N&&x&&F){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...x};D(s),A.current[m]=s}},[N,x,m,F]),w.useEffect(()=>{const s=c=>{const{fromLang:j,toLang:J,switchHandler:v}=c.detail,_=A.current[m];(_?!u.isEqual(_,o):!1)?(B({fromLang:j,toLang:J,switchHandler:v}),q(!0)):v()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[F,o,m]);const ae=async()=>{if(!(!E||!m))try{P(!0);const s=G.getSeoDefaults(E,m),c={...o,keyword:u.get(s,"seo.keyword",""),title:u.get(s,"seo.title",""),description:u.get(s,"seo.description",""),cononicalUrl:u.get(s,"seo.canonicalUrl",""),noIndex:u.get(s,"seo.noIndex",!1),noFollow:u.get(s,"seo.noFollow",!1),ogTitle:u.get(s,"seo.ogTitle",""),ogDescription:u.get(s,"seo.ogDescription","")};D(c),O.toast.success(t("SEO fields reset to defaults"))}catch(s){O.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{P(!1)}},re=async()=>{if(!(!E||!m))try{$(!0);const s=G.getSeoDefaults(E,m),c={...o,jsonLD:u.get(s,"seo.jsonLD","")};D(c),O.toast.success(t("JSON-LD reset to default"))}catch(s){O.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{$(!1)}},le=async()=>{if(!(!E||!m))try{P(!0);const s=G.getSeoDefaults(E,m),c={...o,ogTitle:u.get(s,"seo.ogTitle",""),ogDescription:u.get(s,"seo.ogDescription",""),ogImage:u.get(s,"seo.ogImage",""),ogImageId:u.get(s,"seo.ogImageId",""),metaOther:u.get(s,"seo.metaOther","{}")};D(c),O.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){O.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{P(!1)}},z=async()=>{se({id:l==null?void 0:l.id,seo:o,primaryPage:F},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",o),A.current[m]=o,O.toast.success("SEO & JSON-LD updated successfully")}})},L=(s,c)=>{const j=document.getElementById(c);if(j){const{value:J,newCursorPos:v}=xe(j,s);h.current={id:c,position:v},j.tagName.toLowerCase()==="input"?(j.value=J,D(k=>({...k,[j.name]:J})),j.focus(),j.setSelectionRange(v,v),[0,10,50,100,200].forEach(k=>{setTimeout(()=>{const V=document.getElementById(c);V&&(V.focus(),V.setSelectionRange(v,v))},k)})):(D(T=>({...T,[j.name]:J})),requestAnimationFrame(()=>{const T=document.getElementById(c);T&&(T.focus(),T.setSelectionRange(v,v),setTimeout(()=>{const k=document.getElementById(c);k&&(k.focus(),k.setSelectionRange(v,v))},50))}))}},S=s=>{const c={...o,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};D(c)},C=s=>c=>{if(!u.isEmpty(c.fieldValue)){const j=he(c.fieldValue,s);j.success?S({target:{name:s,value:j.value}}):O.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to process AI response:"}),e.jsx("p",{children:j.error})]}))}c.error&&O.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:c.error})]}))},ce=()=>{const s=u.get(n,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){O.toast.error("Default page JSON-LD is empty");return}S({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!a&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(f.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(f.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:l==null?void 0:l.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:l==null?void 0:l.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(r.Tabs,{value:g,onValueChange:I,className:"w-full",children:[e.jsxs(r.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(r.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(r.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(r.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:g==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"keyword")})]}),e.jsx(f.Input,{type:"text",id:"keyword",name:"keyword",value:o.keyword,onChange:S,disabled:y||!a,placeholder:t("Enter keyword"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("title"),field:"title"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"title")})]})]}),e.jsx(f.Input,{type:"text",id:"title",name:"title",value:o.title,onChange:S,disabled:y||!a,placeholder:t("Enter SEO title"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("description"),field:"description"}),a&&e.jsx(i.NestedPathSelector,{data:d??{},onSelect:s=>L(s,"description")})]})]}),e.jsx(r.Textarea,{id:"description",name:"description",rows:5,value:o.description,onChange:S,disabled:y||!a,placeholder:t("Enter SEO description"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"canonicalUrl")})]}),e.jsx(f.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:o.canonicalUrl,onChange:S,disabled:y||!a,placeholder:t("Enter Canonical URL"),readOnly:!a})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(f.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:o.noIndex,onChange:S,disabled:y||!a,className:"h-4 w-4"}),e.jsx(r.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(f.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:o.noFollow,onChange:S,disabled:y||!a,className:"h-4 w-4"}),e.jsx(r.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:g==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("ogTitle"),field:"ogTitle"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"ogTitle")})]})]}),e.jsx(f.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:o.ogTitle,onChange:S,disabled:y||!a,placeholder:t("Enter OG title"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("ogDescription"),field:"ogDescription"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"ogDescription")})]})]}),e.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:o.ogDescription,onChange:S,disabled:y||!a,placeholder:t("Enter OG description"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>{D({...o,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:o.ogImageId,assetUrl:o.ogImage,onChange:s=>{D({...o,ogImage:s.url,ogImageId:s.id})},disabled:y||!a,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(R,{keyword:o.keyword,onComplete:C("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:o.metaOther,onChange:s=>{S({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:y||!a,readOnly:!a,pageData:d||{},rows:8,handleFieldInsert:L})]})]})]})})}),e.jsx("div",{className:g==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),W&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(R,{keyword:o.keyword,onComplete:C("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(d)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:o.jsonLD,onChange:s=>{S({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:y||!a,readOnly:!a,pageData:d||{},rows:12,handleFieldInsert:L,hasJsonLdForSelectedLang:W,copyJsonLDFromDefaultPage:ce})]})})})]})})]}),a&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[oe?e.jsx(f.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{g==="jsonld"?re():g==="opengraph"?le():ae()},disabled:y||!a||!E,children:t(H?"Resetting...":`Reset to ${g==="jsonld"?"Default JSON-LD":g==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(f.Button,{onClick:z,disabled:!me(o==null?void 0:o.jsonLD)||(A.current[m]?u.isEqual(A.current[m],o):!1)||y||!a,children:t(U?"Saving...":"Save")}),e.jsx(f.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>p("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{q(!1),B(null)},onSave:async()=>{b&&(await z(),b.switchHandler(),q(!1),B(null))},onDiscard:()=>{if(b){const s=A.current[m];s&&D(s),b.switchHandler(),q(!1),B(null)}},isSaving:U,fromLanguage:(b==null?void 0:b.fromLang)||m,toLanguage:(b==null?void 0:b.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;