@chaibuilder/sdk 1.3.0-beta.7 → 1.3.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 (62) hide show
  1. package/dist/CodeEditor-1LboGb1I.cjs +91 -0
  2. package/dist/CodeEditor-BKgZeXwz.js +91 -0
  3. package/dist/STRINGS-3Sn_NeX1.cjs +9 -0
  4. package/dist/STRINGS-DdpfVlsV.js +10 -0
  5. package/dist/Topbar-B8IS6y4H.js +135 -0
  6. package/dist/Topbar-DXC7DFU1.cjs +135 -0
  7. package/dist/UnsplashImages-CjJ5szAy.cjs +215 -0
  8. package/dist/UnsplashImages-Ck9qpKR0.js +215 -0
  9. package/dist/UploadImages-DW1mj4MB.cjs +117 -0
  10. package/dist/UploadImages-DgAMZ8GR.js +117 -0
  11. package/dist/context-menu-BLbuduri.cjs +1073 -0
  12. package/dist/context-menu-BgtRnByf.js +1042 -0
  13. package/dist/controls-8EZmm0Ns.js +234 -0
  14. package/dist/controls-DaW52RjX.cjs +233 -0
  15. package/dist/core.cjs +82 -1
  16. package/dist/core.js +74 -74
  17. package/dist/iconBase-BSrIcOaG.cjs +146 -0
  18. package/dist/iconBase-CWgVxu0A.js +147 -0
  19. package/dist/index-Bjw2sUN2.cjs +12139 -0
  20. package/dist/index-D8_rAW8B.js +12124 -0
  21. package/dist/jsx-runtime-B6vEU3CM.cjs +925 -0
  22. package/dist/jsx-runtime-ClFauRgV.js +926 -0
  23. package/dist/plugin-BYwesM58.cjs +54 -0
  24. package/dist/plugin-BiDLHDo3.cjs +114 -0
  25. package/dist/plugin-BukD7GJR.js +115 -0
  26. package/dist/plugin-tVAEvXiS.js +55 -0
  27. package/dist/render.cjs +208 -2
  28. package/dist/render.js +171 -125
  29. package/dist/runtime.cjs +26 -1
  30. package/dist/runtime.js +16 -16
  31. package/dist/style.css +1529 -2
  32. package/dist/tailwind.cjs +78 -1
  33. package/dist/tailwind.js +21 -19
  34. package/dist/ui.cjs +392 -1
  35. package/dist/ui.js +268 -257
  36. package/dist/web-blocks.cjs +1241 -3
  37. package/dist/web-blocks.js +764 -555
  38. package/package.json +1 -1
  39. package/dist/CodeEditor-CLJIUsvL.js +0 -77
  40. package/dist/CodeEditor-DrVE5UwR.cjs +0 -1
  41. package/dist/STRINGS-eiGM83kj.js +0 -7
  42. package/dist/STRINGS-ew98weUe.cjs +0 -1
  43. package/dist/Topbar-BvLH3BD9.cjs +0 -1
  44. package/dist/Topbar-D3bfoa2h.js +0 -113
  45. package/dist/UnsplashImages-3SDmSL-g.js +0 -189
  46. package/dist/UnsplashImages-Cx6vImSl.cjs +0 -1
  47. package/dist/UploadImages-CkjdUS7T.js +0 -101
  48. package/dist/UploadImages-aqkH-8LC.cjs +0 -1
  49. package/dist/context-menu-BbqLeYFX.js +0 -979
  50. package/dist/context-menu-DfAXjmc8.cjs +0 -1
  51. package/dist/controls-C4n5ycp4.cjs +0 -1
  52. package/dist/controls-Com-zYCq.js +0 -234
  53. package/dist/iconBase-Cn2BsTrq.cjs +0 -1
  54. package/dist/iconBase-DHfFLkem.js +0 -124
  55. package/dist/index-BlcnqLh_.js +0 -9236
  56. package/dist/index-DUJxGeyq.cjs +0 -63
  57. package/dist/jsx-runtime-BYECrxsp.cjs +0 -30
  58. package/dist/jsx-runtime-DGlMoOmv.js +0 -630
  59. package/dist/plugin-BOEoR5jk.js +0 -44
  60. package/dist/plugin-COMQcYlW.cjs +0 -1
  61. package/dist/plugin-Dw854zFv.js +0 -107
  62. package/dist/plugin-I9XxF65G.cjs +0 -1
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("./jsx-runtime-B6vEU3CM.cjs");
4
+ const Editor = require("@monaco-editor/react");
5
+ const contextMenu = require("./context-menu-BLbuduri.cjs");
6
+ const reactI18next = require("react-i18next");
7
+ const React = require("react");
8
+ const core = require("./index-Bjw2sUN2.cjs");
9
+ const reactIcons = require("@radix-ui/react-icons");
10
+ const web = require("@react-hookz/web");
11
+ const sanitizeHTML = (html) => {
12
+ const doc = document.createElement("div");
13
+ doc.innerHTML = html;
14
+ return doc.innerHTML;
15
+ };
16
+ function CodeEditor() {
17
+ const { t } = reactI18next.useTranslation();
18
+ const [dirty, setDirty] = React.useState(false);
19
+ const [code, setCode] = React.useState("");
20
+ const [codeEditor, setCodeEditor] = core.useCodeEditor();
21
+ const [ids] = core.useSelectedBlockIds();
22
+ const updateBlockProps = core.useUpdateBlocksProps();
23
+ const updateRealTime = core.useUpdateBlocksPropsRealtime();
24
+ const saveCodeContentRealTime = web.useThrottledCallback(
25
+ (value) => {
26
+ const html = sanitizeHTML(value);
27
+ updateRealTime([codeEditor.blockId], { [codeEditor.blockProp]: html });
28
+ },
29
+ [],
30
+ 300
31
+ );
32
+ const saveCodeContent = React.useCallback(() => {
33
+ if (dirty) {
34
+ const html = sanitizeHTML(code);
35
+ updateBlockProps([codeEditor.blockId], { [codeEditor.blockProp]: html });
36
+ }
37
+ }, [dirty, code]);
38
+ React.useEffect(() => {
39
+ if (!ids.includes(codeEditor == null ? void 0 : codeEditor.blockId)) {
40
+ saveCodeContent();
41
+ setCodeEditor(null);
42
+ }
43
+ }, [ids]);
44
+ const handleClickOutside = () => {
45
+ setCodeEditor(null);
46
+ };
47
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("div", { className: "h-full rounded-t-lg border-t-4 border-black bg-black text-white", children: [
48
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("button", { onClick: handleClickOutside, className: "fixed inset-0 z-[100000] cursor-default bg-gray-400/20" }),
49
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("div", { className: "relative z-[100001] h-full w-full flex-col gap-y-1", children: [
50
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("div", { className: "-mt-1 flex items-center justify-between px-2 py-2", children: [
51
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("h3", { className: "space-x-3 text-sm font-semibold", children: [
52
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("span", { children: t("HTML Code Editor |") }),
53
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("span", { className: "text-xs text-gray-400", children: t("Scripts will be only executed in preview and live mode.") })
54
+ ] }),
55
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("div", { className: "flex gap-x-2", children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
56
+ contextMenu.Button,
57
+ {
58
+ onClick: () => setCodeEditor(null),
59
+ size: "sm",
60
+ variant: "destructive",
61
+ className: "h-6 w-fit",
62
+ children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(reactIcons.Cross2Icon, {})
63
+ }
64
+ ) })
65
+ ] }),
66
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
67
+ Editor,
68
+ {
69
+ onMount: (editor) => {
70
+ editor.setValue(codeEditor.initialCode);
71
+ },
72
+ onChange: (value) => {
73
+ setDirty(true);
74
+ setCode(value);
75
+ saveCodeContentRealTime(value);
76
+ },
77
+ height: "100%",
78
+ defaultLanguage: "html",
79
+ theme: "vs-dark",
80
+ defaultValue: "",
81
+ options: {
82
+ minimap: {
83
+ enabled: false
84
+ }
85
+ }
86
+ }
87
+ )
88
+ ] })
89
+ ] });
90
+ }
91
+ exports.default = CodeEditor;
@@ -0,0 +1,91 @@
1
+ import { j as jsxRuntimeExports } from "./jsx-runtime-ClFauRgV.js";
2
+ import Editor from "@monaco-editor/react";
3
+ import { B as Button } from "./context-menu-BgtRnByf.js";
4
+ import { useTranslation } from "react-i18next";
5
+ import { useState, useCallback, useEffect } from "react";
6
+ import { u as useCodeEditor, a as useSelectedBlockIds, b as useUpdateBlocksProps, c as useUpdateBlocksPropsRealtime } from "./index-D8_rAW8B.js";
7
+ import { Cross2Icon } from "@radix-ui/react-icons";
8
+ import { useThrottledCallback } from "@react-hookz/web";
9
+ const sanitizeHTML = (html) => {
10
+ const doc = document.createElement("div");
11
+ doc.innerHTML = html;
12
+ return doc.innerHTML;
13
+ };
14
+ function CodeEditor() {
15
+ const { t } = useTranslation();
16
+ const [dirty, setDirty] = useState(false);
17
+ const [code, setCode] = useState("");
18
+ const [codeEditor, setCodeEditor] = useCodeEditor();
19
+ const [ids] = useSelectedBlockIds();
20
+ const updateBlockProps = useUpdateBlocksProps();
21
+ const updateRealTime = useUpdateBlocksPropsRealtime();
22
+ const saveCodeContentRealTime = useThrottledCallback(
23
+ (value) => {
24
+ const html = sanitizeHTML(value);
25
+ updateRealTime([codeEditor.blockId], { [codeEditor.blockProp]: html });
26
+ },
27
+ [],
28
+ 300
29
+ );
30
+ const saveCodeContent = useCallback(() => {
31
+ if (dirty) {
32
+ const html = sanitizeHTML(code);
33
+ updateBlockProps([codeEditor.blockId], { [codeEditor.blockProp]: html });
34
+ }
35
+ }, [dirty, code]);
36
+ useEffect(() => {
37
+ if (!ids.includes(codeEditor == null ? void 0 : codeEditor.blockId)) {
38
+ saveCodeContent();
39
+ setCodeEditor(null);
40
+ }
41
+ }, [ids]);
42
+ const handleClickOutside = () => {
43
+ setCodeEditor(null);
44
+ };
45
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "h-full rounded-t-lg border-t-4 border-black bg-black text-white", children: [
46
+ /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: handleClickOutside, className: "fixed inset-0 z-[100000] cursor-default bg-gray-400/20" }),
47
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative z-[100001] h-full w-full flex-col gap-y-1", children: [
48
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "-mt-1 flex items-center justify-between px-2 py-2", children: [
49
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "space-x-3 text-sm font-semibold", children: [
50
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: t("HTML Code Editor |") }),
51
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs text-gray-400", children: t("Scripts will be only executed in preview and live mode.") })
52
+ ] }),
53
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex gap-x-2", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
54
+ Button,
55
+ {
56
+ onClick: () => setCodeEditor(null),
57
+ size: "sm",
58
+ variant: "destructive",
59
+ className: "h-6 w-fit",
60
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Cross2Icon, {})
61
+ }
62
+ ) })
63
+ ] }),
64
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
65
+ Editor,
66
+ {
67
+ onMount: (editor) => {
68
+ editor.setValue(codeEditor.initialCode);
69
+ },
70
+ onChange: (value) => {
71
+ setDirty(true);
72
+ setCode(value);
73
+ saveCodeContentRealTime(value);
74
+ },
75
+ height: "100%",
76
+ defaultLanguage: "html",
77
+ theme: "vs-dark",
78
+ defaultValue: "",
79
+ options: {
80
+ minimap: {
81
+ enabled: false
82
+ }
83
+ }
84
+ }
85
+ )
86
+ ] })
87
+ ] });
88
+ }
89
+ export {
90
+ CodeEditor as default
91
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ const STYLES_KEY = "#styles:";
3
+ const SLOT_KEY = "#slots:";
4
+ const I18N_KEY = "#i18n";
5
+ const ROOT_TEMP_KEY = "__ADD_BLOCK_INTERNAL_ROOT";
6
+ exports.I18N_KEY = I18N_KEY;
7
+ exports.ROOT_TEMP_KEY = ROOT_TEMP_KEY;
8
+ exports.SLOT_KEY = SLOT_KEY;
9
+ exports.STYLES_KEY = STYLES_KEY;
@@ -0,0 +1,10 @@
1
+ const STYLES_KEY = "#styles:";
2
+ const SLOT_KEY = "#slots:";
3
+ const I18N_KEY = "#i18n";
4
+ const ROOT_TEMP_KEY = "__ADD_BLOCK_INTERNAL_ROOT";
5
+ export {
6
+ I18N_KEY as I,
7
+ ROOT_TEMP_KEY as R,
8
+ STYLES_KEY as S,
9
+ SLOT_KEY as a
10
+ };
@@ -0,0 +1,135 @@
1
+ import { j as jsxRuntimeExports } from "./jsx-runtime-ClFauRgV.js";
2
+ import React__default, { useMemo, Suspense } from "react";
3
+ import { B as Button, a6 as DropdownMenu, a7 as DropdownMenuTrigger, a8 as DropdownMenuContent, a9 as DropdownMenuItem, aq as Skeleton, al as Separator } from "./context-menu-BgtRnByf.js";
4
+ import { e as useSavePage, F as FaCheck, d as useBuilderProp, f as usePreviewMode, g as useLanguages, L as LANGUAGES, h as FaLanguage, i as FaStar } from "./index-D8_rAW8B.js";
5
+ import { useTranslation } from "react-i18next";
6
+ import { c as cn } from "./iconBase-CWgVxu0A.js";
7
+ import { EyeOpenIcon, ChevronDownIcon } from "@radix-ui/react-icons";
8
+ import { forEach, uniq, get, isEmpty, map } from "lodash-es";
9
+ import "@chaibuilder/runtime";
10
+ const SaveButton = () => {
11
+ const { savePage, saveState } = useSavePage();
12
+ const { t } = useTranslation();
13
+ const button = /* @__PURE__ */ jsxRuntimeExports.jsxs(
14
+ Button,
15
+ {
16
+ disabled: saveState === "SAVING",
17
+ onClick: (e) => {
18
+ e.preventDefault();
19
+ savePage();
20
+ },
21
+ className: cn(
22
+ "flex h-auto w-fit items-center gap-x-2 p-1 px-2",
23
+ // UNSAVED sate
24
+ "bg-gray-200 text-gray-500 hover:bg-gray-100 dark:bg-gray-800 dark:text-gray-400",
25
+ {
26
+ "animate-pulse bg-gray-300 text-gray-900": saveState === "SAVING",
27
+ "bg-green-500 text-white hover:bg-green-600 hover:text-white dark:bg-green-600 dark:text-white": saveState === "SAVED"
28
+ }
29
+ ),
30
+ size: "sm",
31
+ variant: "outline",
32
+ children: [
33
+ /* @__PURE__ */ jsxRuntimeExports.jsx(FaCheck, { className: "text-sm text-white" }),
34
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm", children: saveState === "SAVING" ? t("Saving") : saveState === "SAVED" ? t("Saved") : t("Unsaved") })
35
+ ]
36
+ }
37
+ );
38
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center", children: button });
39
+ };
40
+ const Preview = function Preview2() {
41
+ const preview = useBuilderProp("previewComponent");
42
+ const [, setPreviewMode] = usePreviewMode();
43
+ const { t } = useTranslation();
44
+ if (!preview) return null;
45
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
46
+ Button,
47
+ {
48
+ onClick: (e) => {
49
+ e.preventDefault();
50
+ setPreviewMode(true);
51
+ },
52
+ className: `flex h-auto w-fit items-center gap-x-2 p-1 px-2`,
53
+ size: "sm",
54
+ variant: "outline",
55
+ children: [
56
+ /* @__PURE__ */ jsxRuntimeExports.jsx(EyeOpenIcon, { className: "text-xs" }),
57
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm", children: t("Preview") })
58
+ ]
59
+ }
60
+ );
61
+ };
62
+ const LanguageSelector = () => {
63
+ const { fallbackLang, languages, selectedLang, setSelectedLang } = useLanguages();
64
+ const currentLang = (selectedLang == null ? void 0 : selectedLang.length) > 0 ? selectedLang : fallbackLang;
65
+ const langOptions = useMemo(() => {
66
+ const options = [];
67
+ forEach(uniq([fallbackLang, ...languages]), (key) => {
68
+ const value = get(LANGUAGES, key);
69
+ if (value) options.push({ key, value, default: key === fallbackLang });
70
+ });
71
+ return options;
72
+ }, [fallbackLang, languages]);
73
+ if (isEmpty(languages) && currentLang === "en") {
74
+ return null;
75
+ }
76
+ if (isEmpty(languages) && currentLang !== "en") {
77
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-x-1 text-sm text-blue-500 hover:text-blue-600", children: [
78
+ /* @__PURE__ */ jsxRuntimeExports.jsx(FaLanguage, { className: "h-4 w-4" }),
79
+ get(LANGUAGES, currentLang)
80
+ ] });
81
+ }
82
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(DropdownMenu, { children: [
83
+ /* @__PURE__ */ jsxRuntimeExports.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Button, { size: "sm", variant: "outline", className: "flex items-center gap-x-1 text-blue-500 hover:text-blue-600", children: [
84
+ /* @__PURE__ */ jsxRuntimeExports.jsx(FaLanguage, { className: "h-4 w-4" }),
85
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-2", children: [
86
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
87
+ " ",
88
+ get(LANGUAGES, currentLang)
89
+ ] }),
90
+ /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronDownIcon, { className: "h-4 w-4" })
91
+ ] })
92
+ ] }) }),
93
+ /* @__PURE__ */ jsxRuntimeExports.jsx(DropdownMenuContent, { className: "border-border", children: map(langOptions, (option) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
94
+ DropdownMenuItem,
95
+ {
96
+ className: cn(
97
+ "flex cursor-pointer items-center text-sm",
98
+ option.key === currentLang && "!bg-blue-500 text-white hover:!text-white"
99
+ ),
100
+ onClick: () => setSelectedLang(option.key),
101
+ children: [
102
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: option.value }),
103
+ option.key === fallbackLang ? /* @__PURE__ */ jsxRuntimeExports.jsx(FaStar, { className: "ml-2 h-4 w-4 text-yellow-400" }) : null
104
+ ]
105
+ }
106
+ )) })
107
+ ] });
108
+ };
109
+ const Topbar = () => {
110
+ const leftComponents = useBuilderProp("topBarComponents.left", []);
111
+ const centerComponents = useBuilderProp("topBarComponents.center", []);
112
+ const rightComponents = useBuilderProp("topBarComponents.right", []);
113
+ const editable = useBuilderProp("editable", true);
114
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex h-14 items-center justify-between px-2", children: [
115
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center space-x-2", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center space-x-2 font-bold", children: React__default.Children.toArray(
116
+ leftComponents.map((Component) => /* @__PURE__ */ jsxRuntimeExports.jsx(Suspense, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { className: "h-10" }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Component, {}) }))
117
+ ) }) }),
118
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center space-x-2", children: React__default.Children.toArray(
119
+ centerComponents.map((Component) => /* @__PURE__ */ jsxRuntimeExports.jsx(Suspense, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { className: "h-10" }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Component, {}) }))
120
+ ) }),
121
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-1", children: [
122
+ /* @__PURE__ */ jsxRuntimeExports.jsx(LanguageSelector, {}),
123
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Separator, { orientation: "vertical" }),
124
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Preview, {}),
125
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Separator, { orientation: "vertical" }),
126
+ editable ? /* @__PURE__ */ jsxRuntimeExports.jsx(SaveButton, {}) : null,
127
+ React__default.Children.toArray(
128
+ rightComponents.map((Component) => /* @__PURE__ */ jsxRuntimeExports.jsx(Suspense, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { className: "h-10" }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Component, {}) }))
129
+ )
130
+ ] })
131
+ ] });
132
+ };
133
+ export {
134
+ Topbar as default
135
+ };
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("./jsx-runtime-B6vEU3CM.cjs");
4
+ const React = require("react");
5
+ const contextMenu = require("./context-menu-BLbuduri.cjs");
6
+ const core = require("./index-Bjw2sUN2.cjs");
7
+ const reactI18next = require("react-i18next");
8
+ const iconBase = require("./iconBase-BSrIcOaG.cjs");
9
+ const reactIcons = require("@radix-ui/react-icons");
10
+ const lodashEs = require("lodash-es");
11
+ require("@chaibuilder/runtime");
12
+ const SaveButton = () => {
13
+ const { savePage, saveState } = core.useSavePage();
14
+ const { t } = reactI18next.useTranslation();
15
+ const button = /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(
16
+ contextMenu.Button,
17
+ {
18
+ disabled: saveState === "SAVING",
19
+ onClick: (e) => {
20
+ e.preventDefault();
21
+ savePage();
22
+ },
23
+ className: iconBase.cn(
24
+ "flex h-auto w-fit items-center gap-x-2 p-1 px-2",
25
+ // UNSAVED sate
26
+ "bg-gray-200 text-gray-500 hover:bg-gray-100 dark:bg-gray-800 dark:text-gray-400",
27
+ {
28
+ "animate-pulse bg-gray-300 text-gray-900": saveState === "SAVING",
29
+ "bg-green-500 text-white hover:bg-green-600 hover:text-white dark:bg-green-600 dark:text-white": saveState === "SAVED"
30
+ }
31
+ ),
32
+ size: "sm",
33
+ variant: "outline",
34
+ children: [
35
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(core.FaCheck, { className: "text-sm text-white" }),
36
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("span", { className: "text-sm", children: saveState === "SAVING" ? t("Saving") : saveState === "SAVED" ? t("Saved") : t("Unsaved") })
37
+ ]
38
+ }
39
+ );
40
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("div", { className: "flex items-center", children: button });
41
+ };
42
+ const Preview = function Preview2() {
43
+ const preview = core.useBuilderProp("previewComponent");
44
+ const [, setPreviewMode] = core.usePreviewMode();
45
+ const { t } = reactI18next.useTranslation();
46
+ if (!preview) return null;
47
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(
48
+ contextMenu.Button,
49
+ {
50
+ onClick: (e) => {
51
+ e.preventDefault();
52
+ setPreviewMode(true);
53
+ },
54
+ className: `flex h-auto w-fit items-center gap-x-2 p-1 px-2`,
55
+ size: "sm",
56
+ variant: "outline",
57
+ children: [
58
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(reactIcons.EyeOpenIcon, { className: "text-xs" }),
59
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("span", { className: "text-sm", children: t("Preview") })
60
+ ]
61
+ }
62
+ );
63
+ };
64
+ const LanguageSelector = () => {
65
+ const { fallbackLang, languages, selectedLang, setSelectedLang } = core.useLanguages();
66
+ const currentLang = (selectedLang == null ? void 0 : selectedLang.length) > 0 ? selectedLang : fallbackLang;
67
+ const langOptions = React.useMemo(() => {
68
+ const options = [];
69
+ lodashEs.forEach(lodashEs.uniq([fallbackLang, ...languages]), (key) => {
70
+ const value = lodashEs.get(core.LANGUAGES, key);
71
+ if (value) options.push({ key, value, default: key === fallbackLang });
72
+ });
73
+ return options;
74
+ }, [fallbackLang, languages]);
75
+ if (lodashEs.isEmpty(languages) && currentLang === "en") {
76
+ return null;
77
+ }
78
+ if (lodashEs.isEmpty(languages) && currentLang !== "en") {
79
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-x-1 text-sm text-blue-500 hover:text-blue-600", children: [
80
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(core.FaLanguage, { className: "h-4 w-4" }),
81
+ lodashEs.get(core.LANGUAGES, currentLang)
82
+ ] });
83
+ }
84
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(contextMenu.DropdownMenu, { children: [
85
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(contextMenu.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(contextMenu.Button, { size: "sm", variant: "outline", className: "flex items-center gap-x-1 text-blue-500 hover:text-blue-600", children: [
86
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(core.FaLanguage, { className: "h-4 w-4" }),
87
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-2", children: [
88
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("div", { children: [
89
+ " ",
90
+ lodashEs.get(core.LANGUAGES, currentLang)
91
+ ] }),
92
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(reactIcons.ChevronDownIcon, { className: "h-4 w-4" })
93
+ ] })
94
+ ] }) }),
95
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(contextMenu.DropdownMenuContent, { className: "border-border", children: lodashEs.map(langOptions, (option) => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(
96
+ contextMenu.DropdownMenuItem,
97
+ {
98
+ className: iconBase.cn(
99
+ "flex cursor-pointer items-center text-sm",
100
+ option.key === currentLang && "!bg-blue-500 text-white hover:!text-white"
101
+ ),
102
+ onClick: () => setSelectedLang(option.key),
103
+ children: [
104
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("div", { children: option.value }),
105
+ option.key === fallbackLang ? /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(core.FaStar, { className: "ml-2 h-4 w-4 text-yellow-400" }) : null
106
+ ]
107
+ }
108
+ )) })
109
+ ] });
110
+ };
111
+ const Topbar = () => {
112
+ const leftComponents = core.useBuilderProp("topBarComponents.left", []);
113
+ const centerComponents = core.useBuilderProp("topBarComponents.center", []);
114
+ const rightComponents = core.useBuilderProp("topBarComponents.right", []);
115
+ const editable = core.useBuilderProp("editable", true);
116
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("div", { className: "flex h-14 items-center justify-between px-2", children: [
117
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("div", { className: "flex items-center space-x-2", children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("div", { className: "flex items-center space-x-2 font-bold", children: React.Children.toArray(
118
+ leftComponents.map((Component) => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(React.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(contextMenu.Skeleton, { className: "h-10" }), children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Component, {}) }))
119
+ ) }) }),
120
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx("div", { className: "flex items-center space-x-2", children: React.Children.toArray(
121
+ centerComponents.map((Component) => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(React.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(contextMenu.Skeleton, { className: "h-10" }), children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Component, {}) }))
122
+ ) }),
123
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-1", children: [
124
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(LanguageSelector, {}),
125
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(contextMenu.Separator, { orientation: "vertical" }),
126
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Preview, {}),
127
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(contextMenu.Separator, { orientation: "vertical" }),
128
+ editable ? /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(SaveButton, {}) : null,
129
+ React.Children.toArray(
130
+ rightComponents.map((Component) => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(React.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(contextMenu.Skeleton, { className: "h-10" }), children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Component, {}) }))
131
+ )
132
+ ] })
133
+ ] });
134
+ };
135
+ exports.default = Topbar;