@bigbinary/neeto-themes-frontend 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1776 @@
1
+ import { shallow } from 'zustand/shallow';
2
+ import { createElement, useEffect, useState, useRef, memo, useCallback } from 'react';
3
+ import { t as t$1 } from 'i18next';
4
+ import { isPresent, isNot, filterBy, snakeToCamelCase, findBy, isNotPresent, hyphenate, findIndexBy, toLabelAndValue, humanize, isNotEmpty, noop } from '@bigbinary/neeto-cist';
5
+ import { useMutationWithInvalidation, withT, withTitle } from '@bigbinary/neeto-commons-frontend/react-utils';
6
+ import Spinner from '@bigbinary/neetoui/Spinner';
7
+ import { useQuery } from '@tanstack/react-query';
8
+ import axios from 'axios';
9
+ import { B as BASE_URL, g as getDominantColorFromUrl, i as isFunction, a as scrollElementIntoView } from './index-9e15a8b1.js';
10
+ import { Q as QUERY_KEYS, a as useConfigStore, b as useThemeStore, u as useThemeUtils } from './useThemeUtils-36f2ce5a.js';
11
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
12
+ import Alert from '@bigbinary/neetoui/Alert';
13
+ import { useTranslation, Trans } from 'react-i18next';
14
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
15
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
16
+ import Close from '@bigbinary/neeto-icons/Close';
17
+ import Button from '@bigbinary/neetoui/Button';
18
+ import Popover from '@bigbinary/neetoui/Popover';
19
+ import Typography from '@bigbinary/neetoui/Typography';
20
+ import Form from '@bigbinary/neetoui/formik/Form';
21
+ import * as yup from 'yup';
22
+ import { useFormikContext, Field } from 'formik';
23
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
24
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
25
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
26
+ import { ImageUploader } from '@bigbinary/neeto-image-uploader-frontend';
27
+ import { joinHyphenCase } from '@bigbinary/neeto-commons-frontend/utils';
28
+ import Toastr from '@bigbinary/neetoui/Toastr';
29
+ import { isEmpty, negate } from 'ramda';
30
+ import Select from '@bigbinary/neetoui/Select';
31
+ import CenterAlign from '@bigbinary/neeto-icons/CenterAlign';
32
+ import LeftAlign from '@bigbinary/neeto-icons/LeftAlign';
33
+ import ColorPicker from '@bigbinary/neetoui/ColorPicker';
34
+ import { Slider } from 'antd';
35
+ import classnames from 'classnames';
36
+ import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
37
+ import Switch from '@bigbinary/neetoui/Switch';
38
+ import Input from '@bigbinary/neetoui/formik/Input';
39
+ import Search from '@bigbinary/neeto-molecules/Search';
40
+ import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
41
+ import LeftArrow from '@bigbinary/neeto-icons/LeftArrow';
42
+ import Plus from '@bigbinary/neeto-icons/Plus';
43
+ import 'zustand';
44
+
45
+ var show$1 = function show(entityId) {
46
+ return axios.get("".concat(BASE_URL, "/api/v1/entities/").concat(entityId));
47
+ };
48
+ var entitiesApi = {
49
+ show: show$1
50
+ };
51
+
52
+ var useShowThemeEntity = function useShowThemeEntity(entityId) {
53
+ return useQuery({
54
+ queryKey: [QUERY_KEYS.THEME_ENTITY_DETAILS, entityId],
55
+ queryFn: function queryFn() {
56
+ return entitiesApi.show(entityId);
57
+ },
58
+ enabled: !!entityId
59
+ });
60
+ };
61
+
62
+ var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
63
+
64
+ var css = ".neeto-themes__wrapper{display:flex;width:100%}.neeto-themes__wrapper .neeto-themes-sidebar{background-color:rgb(var(--neeto-ui-white));height:calc(100vh - 64px);width:240px}@media (min-width:1024px){.neeto-themes__wrapper .neeto-themes-sidebar{width:280px}}@media (min-width:1280px){.neeto-themes__wrapper .neeto-themes-sidebar{width:320px}}.neeto-themes__wrapper .neeto-themes-sidebar .neeto-themes-sidebar__header{padding-bottom:8px;padding-top:16px}.neeto-themes__wrapper .neeto-themes-sidebar .neeto-themes-sidebar__scroll{height:calc(100vh - 120px);overflow-y:auto}.neeto-themes__wrapper .neeto-themes-sidebar .neeto-themes-sidebar__scroll .neeto-ui-colorpicker__target .neeto-ui-colorpicker-target__code{display:none}.neeto-themes__wrapper .neeto-themes-preview__wrapper{flex-grow:1;height:calc(100vh - 64px);position:relative}.neeto-themes-theme-thumbnail--preview-active{border-color:rgb(var(--neeto-ui-gray-600))!important;outline:1px solid rgb(var(--neeto-ui-gray-600))!important}.neeto-themes-theme-thumbnail--active{border-color:rgb(var(--neeto-ui-primary-500))!important;outline:2px solid rgb(var(--neeto-ui-primary-500))!important}.neeto-themes-theme-thumbnail--highlight-active{border-color:rgb(var(--neeto-ui-gray-400))!important;outline:2px solid rgb(var(--neeto-ui-gray-400))!important}.neeto-themes-theme-thumbnail__apply-btn{--neeto-ui-btn-padding-x:12px;--neeto-ui-btn-border-radius:100px}.neeto-themes-theme-thumbnail__apply-btn:disabled,.neeto-themes-theme-thumbnail__apply-btn[disabled]{opacity:1!important}\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImFwcC9qYXZhc2NyaXB0L3N0eWxlc2hlZXRzL2NvbXBvbmVudHMvdGhlbWVzLnNjc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsdUJBRUUsWUFBQSxDQURBLFVBQUYsQ0FHRSw2Q0FHRSwyQ0FBQSxDQURBLHlCQUFBLENBREEsV0FDSixDQUdJLDBCQUxGLDZDQU1JLFdBQUosQ0FDRixDQUNJLDBCQVJGLDZDQVNJLFdBRUosQ0FDRixDQUFJLDJFQUVFLGtCQUFBLENBREEsZ0JBR04sQ0FDSSwyRUFDRSwwQkFBQSxDQUNBLGVBQ04sQ0FFUSw0SUFDRSxZQUFWLENBTUUsc0RBR0UsV0FBQSxDQURBLHlCQUFBLENBREEsaUJBRkosQ0FRQSw4Q0FDRSxvREFBQSxDQUNBLHlEQUxGLENBUUEsc0NBQ0UsdURBQUEsQ0FDQSw0REFMRixDQVFBLGdEQUNFLG9EQUFBLENBQ0EseURBTEYsQ0FRQSx5Q0FDRSw2QkFBQSxDQUNBLGtDQUxGLENBTUUscUdBRUUsbUJBTEoiLCJzb3VyY2VzQ29udGVudCI6WyJAaW1wb3J0IFwiLi4vYWJzdHJhY3RzL3ZhcmlhYmxlc1wiO1xuXG4ubmVldG8tdGhlbWVzX193cmFwcGVyIHtcbiAgd2lkdGg6IDEwMCU7XG4gIGRpc3BsYXk6IGZsZXg7XG5cbiAgLm5lZXRvLXRoZW1lcy1zaWRlYmFyIHtcbiAgICB3aWR0aDogJHRoZW1lcy1zaWRlYmFyLXdpZHRoLXNtO1xuICAgIGhlaWdodDogY2FsYygxMDB2aCAtICN7JGJ1aWxkZXItaGVhZGVyLWhlaWdodH0pO1xuICAgIGJhY2tncm91bmQtY29sb3I6IHJnYih2YXIoLS1uZWV0by11aS13aGl0ZSkpO1xuXG4gICAgQHNjcmVlbiBsZyB7XG4gICAgICB3aWR0aDogJHRoZW1lcy1zaWRlYmFyLXdpZHRoLWxnO1xuICAgIH1cbiAgICBAc2NyZWVuIHhsIHtcbiAgICAgIHdpZHRoOiAkdGhlbWVzLXNpZGViYXItd2lkdGgteGw7XG4gICAgfVxuXG4gICAgLm5lZXRvLXRoZW1lcy1zaWRlYmFyX19oZWFkZXIge1xuICAgICAgcGFkZGluZy10b3A6IDE2cHg7XG4gICAgICBwYWRkaW5nLWJvdHRvbTogOHB4O1xuICAgIH1cblxuICAgIC5uZWV0by10aGVtZXMtc2lkZWJhcl9fc2Nyb2xsIHtcbiAgICAgIGhlaWdodDogY2FsYygxMDB2aCAtIDEyMHB4KTtcbiAgICAgIG92ZXJmbG93LXk6IGF1dG87XG5cbiAgICAgIC5uZWV0by11aS1jb2xvcnBpY2tlcl9fdGFyZ2V0IHtcbiAgICAgICAgLm5lZXRvLXVpLWNvbG9ycGlja2VyLXRhcmdldF9fY29kZSB7XG4gICAgICAgICAgZGlzcGxheTogbm9uZTtcbiAgICAgICAgfVxuICAgICAgfVxuICAgIH1cbiAgfVxuXG4gIC5uZWV0by10aGVtZXMtcHJldmlld19fd3JhcHBlciB7XG4gICAgcG9zaXRpb246IHJlbGF0aXZlO1xuICAgIGhlaWdodDogY2FsYygxMDB2aCAtICN7JGJ1aWxkZXItaGVhZGVyLWhlaWdodH0pO1xuICAgIGZsZXgtZ3JvdzogMTtcbiAgfVxufVxuXG4ubmVldG8tdGhlbWVzLXRoZW1lLXRodW1ibmFpbC0tcHJldmlldy1hY3RpdmUge1xuICBib3JkZXItY29sb3I6IHJnYih2YXIoLS1uZWV0by11aS1ncmF5LTYwMCkpICFpbXBvcnRhbnQ7XG4gIG91dGxpbmU6IDFweCBzb2xpZCByZ2IodmFyKC0tbmVldG8tdWktZ3JheS02MDApKSAhaW1wb3J0YW50O1xufVxuXG4ubmVldG8tdGhlbWVzLXRoZW1lLXRodW1ibmFpbC0tYWN0aXZlIHtcbiAgYm9yZGVyLWNvbG9yOiByZ2IodmFyKC0tbmVldG8tdWktcHJpbWFyeS01MDApKSAhaW1wb3J0YW50O1xuICBvdXRsaW5lOiAycHggc29saWQgcmdiKHZhcigtLW5lZXRvLXVpLXByaW1hcnktNTAwKSkgIWltcG9ydGFudDtcbn1cblxuLm5lZXRvLXRoZW1lcy10aGVtZS10aHVtYm5haWwtLWhpZ2hsaWdodC1hY3RpdmUge1xuICBib3JkZXItY29sb3I6IHJnYih2YXIoLS1uZWV0by11aS1ncmF5LTQwMCkpICFpbXBvcnRhbnQ7XG4gIG91dGxpbmU6IDJweCBzb2xpZCByZ2IodmFyKC0tbmVldG8tdWktZ3JheS00MDApKSAhaW1wb3J0YW50O1xufVxuXG4ubmVldG8tdGhlbWVzLXRoZW1lLXRodW1ibmFpbF9fYXBwbHktYnRuIHtcbiAgLS1uZWV0by11aS1idG4tcGFkZGluZy14OiAxMnB4O1xuICAtLW5lZXRvLXVpLWJ0bi1ib3JkZXItcmFkaXVzOiAxMDBweDtcbiAgJjpkaXNhYmxlZCxcbiAgJltkaXNhYmxlZF0ge1xuICAgIG9wYWNpdHk6IDEgIWltcG9ydGFudDtcbiAgfVxufVxuIl19 */";
65
+ n(css,{});
66
+
67
+ var _excluded$1 = ["themeId"];
68
+ var list = function list(entityId) {
69
+ return axios.get("".concat(BASE_URL, "/api/v1/themes"), {
70
+ params: {
71
+ entity_id: entityId
72
+ }
73
+ });
74
+ };
75
+ var show = function show(id) {
76
+ return axios.get("".concat(BASE_URL, "/api/v1/themes/").concat(id));
77
+ };
78
+ var create = function create(payload) {
79
+ return axios.post("".concat(BASE_URL, "/api/v1/themes"), {
80
+ theme: payload
81
+ });
82
+ };
83
+ var update = function update(_ref) {
84
+ var id = _ref.id,
85
+ payload = _ref.payload;
86
+ return axios.put("".concat(BASE_URL, "/api/v1/themes/").concat(id), {
87
+ theme: payload
88
+ });
89
+ };
90
+ var destroy = function destroy(id) {
91
+ return axios["delete"]("".concat(BASE_URL, "/api/v1/themes/").concat(id));
92
+ };
93
+ var clone = function clone(id) {
94
+ return axios.post("".concat(BASE_URL, "/api/v1/themes/").concat(id, "/clone"));
95
+ };
96
+ var apply = function apply(_ref2) {
97
+ var themeId = _ref2.themeId,
98
+ payload = _objectWithoutProperties(_ref2, _excluded$1);
99
+ return axios.post("".concat(BASE_URL, "/api/v1/themes/").concat(themeId, "/apply"), {
100
+ entity: payload
101
+ });
102
+ };
103
+ var themesApi = {
104
+ list: list,
105
+ show: show,
106
+ create: create,
107
+ update: update,
108
+ destroy: destroy,
109
+ clone: clone,
110
+ apply: apply
111
+ };
112
+
113
+ var useListThemes = function useListThemes(entityId) {
114
+ var _useConfigStore = useConfigStore(function (store) {
115
+ return {
116
+ isTemplateThemesEnabled: store["isTemplateThemesEnabled"]
117
+ };
118
+ }, shallow),
119
+ isTemplateThemesEnabled = _useConfigStore.isTemplateThemesEnabled;
120
+ var queryKey = isTemplateThemesEnabled ? [QUERY_KEYS.THEMES_LIST, entityId] : [QUERY_KEYS.THEMES_LIST];
121
+ return useQuery({
122
+ queryKey: queryKey,
123
+ queryFn: function queryFn() {
124
+ return themesApi.list(entityId);
125
+ }
126
+ });
127
+ };
128
+ var useCreateTheme = function useCreateTheme() {
129
+ return useMutationWithInvalidation(themesApi.create, {
130
+ keysToInvalidate: [QUERY_KEYS.THEMES_LIST]
131
+ });
132
+ };
133
+ var useUpdateTheme = function useUpdateTheme(themeId) {
134
+ return useMutationWithInvalidation(function (payload) {
135
+ return themesApi.update({
136
+ id: themeId,
137
+ payload: payload
138
+ });
139
+ }, {
140
+ keysToInvalidate: [[QUERY_KEYS.THEMES_LIST], [QUERY_KEYS.THEME_ENTITY_DETAILS], [QUERY_KEYS.THEME_DETAILS, themeId]]
141
+ });
142
+ };
143
+ var useDeleteTheme = function useDeleteTheme() {
144
+ return useMutationWithInvalidation(themesApi.destroy, {
145
+ keysToInvalidate: [[QUERY_KEYS.THEMES_LIST], [QUERY_KEYS.THEME_ENTITY_DETAILS]]
146
+ });
147
+ };
148
+ var useCloneTheme = function useCloneTheme() {
149
+ return useMutationWithInvalidation(themesApi.clone, {
150
+ keysToInvalidate: [QUERY_KEYS.THEMES_LIST]
151
+ });
152
+ };
153
+ var useApplyTheme = function useApplyTheme(_ref) {
154
+ var onSuccess = _ref.onSuccess;
155
+ return useMutationWithInvalidation(themesApi.apply, {
156
+ keysToInvalidate: [[QUERY_KEYS.THEMES_LIST], [QUERY_KEYS.THEME_ENTITY_DETAILS]],
157
+ onSuccess: onSuccess
158
+ });
159
+ };
160
+
161
+ var POSITION_OPTIONS = [{
162
+ label: "Left",
163
+ value: "left"
164
+ }, {
165
+ label: "Right",
166
+ value: "right"
167
+ }];
168
+ var FONT_OPTIONS = [{
169
+ label: "System UI",
170
+ value: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'
171
+ }, {
172
+ label: "Cedarville Cursive",
173
+ value: "'Cedarville Cursive', cursive"
174
+ }, {
175
+ label: "Poppins",
176
+ value: "Poppins, sans-serif"
177
+ }, {
178
+ label: "Roboto",
179
+ value: "Roboto, sans-serif"
180
+ }, {
181
+ label: "Open Sans",
182
+ value: "Open Sans, sans-serif"
183
+ }, {
184
+ label: "Montserrat",
185
+ value: "Montserrat, sans-serif"
186
+ }, {
187
+ label: "Raleway",
188
+ value: "Raleway, sans-serif"
189
+ }, {
190
+ label: "Quicksand",
191
+ value: "Quicksand, sans-serif"
192
+ }, {
193
+ label: "Inter",
194
+ value: "Inter, sans-serif"
195
+ }, {
196
+ label: "Satoshi",
197
+ value: "Satoshi, sans-serif"
198
+ }, {
199
+ label: "Chillax",
200
+ value: "Chillax, sans-serif"
201
+ }, {
202
+ label: "Clash Display",
203
+ value: "Clash Display, sans-serif"
204
+ }, {
205
+ label: "General Sans",
206
+ value: "General Sans, sans-serif"
207
+ }, {
208
+ label: "Cabinet Grotesk",
209
+ value: "Cabinet Grotesk, sans-serif"
210
+ }, {
211
+ label: "Lora",
212
+ value: "Lora, serif"
213
+ }, {
214
+ label: "Merriweather",
215
+ value: "Merriweather, serif"
216
+ }, {
217
+ label: "Boska",
218
+ value: "Boska, serif"
219
+ }, {
220
+ label: "Playfair Display",
221
+ value: "Playfair Display, serif"
222
+ }, {
223
+ label: "Roboto Slab",
224
+ value: "Roboto Slab, serif"
225
+ }, {
226
+ label: "Dancing Script",
227
+ value: "Dancing Script, cursive"
228
+ }];
229
+ var THEME_VALIDATION_SCHEMA = yup.object().shape({
230
+ name: yup.string().required("Name is required")
231
+ });
232
+ var OVERLAY_OPACITY_SLIDER_MARKS = {
233
+ 0: " "
234
+ };
235
+ var HUNDRED = 100;
236
+
237
+ var buildInitialValues = function buildInitialValues(theme, themePropertiesSchema) {
238
+ if (isPresent(theme)) return theme;
239
+ return {
240
+ name: t$1("neetoThemes.build.leftSideBar.themes.createTheme.newThemeName"),
241
+ properties: themePropertiesSchema.map(function (_ref) {
242
+ var key = _ref.key,
243
+ kind = _ref.kind,
244
+ defaultValue = _ref.defaultValue;
245
+ switch (kind) {
246
+ case "color":
247
+ return {
248
+ value: defaultValue,
249
+ kind: "color",
250
+ key: key
251
+ };
252
+ case "font_family":
253
+ return {
254
+ value: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
255
+ kind: "font_family",
256
+ key: key
257
+ };
258
+ case "overlay_opacity":
259
+ return {
260
+ value: 0,
261
+ kind: "overlay_opacity",
262
+ key: key
263
+ };
264
+ case "slider":
265
+ return {
266
+ value: 0,
267
+ kind: "slider",
268
+ key: key
269
+ };
270
+ case "radius":
271
+ return {
272
+ value: defaultValue,
273
+ kind: "radius",
274
+ key: key
275
+ };
276
+ case "boolean":
277
+ return {
278
+ value: String(defaultValue),
279
+ kind: "boolean",
280
+ key: key
281
+ };
282
+ case "position_selector":
283
+ return {
284
+ value: defaultValue,
285
+ kind: "position_selector",
286
+ key: key
287
+ };
288
+ case "alignment_block":
289
+ return {
290
+ value: defaultValue,
291
+ kind: "alignment_block",
292
+ key: key
293
+ };
294
+ default:
295
+ return null;
296
+ }
297
+ }).filter(isNot(null))
298
+ };
299
+ };
300
+ var buildImageData = function buildImageData(values, themePropertiesSchema) {
301
+ return filterBy({
302
+ kind: "image"
303
+ }, themePropertiesSchema).reduce(function (acc, item) {
304
+ var _values$snakeToCamelC;
305
+ var signedId = (_values$snakeToCamelC = values[snakeToCamelCase(item.key)]) === null || _values$snakeToCamelC === void 0 ? void 0 : _values$snakeToCamelC.signedId;
306
+ acc[item.key] = signedId;
307
+ return acc;
308
+ }, {});
309
+ };
310
+ var isPropertyVisible = function isPropertyVisible(key, formikValues, themePropertiesSchema) {
311
+ var property = findBy({
312
+ key: key
313
+ }, themePropertiesSchema);
314
+ if (isNotPresent(property)) return false;
315
+ if (property !== null && property !== void 0 && property.hidden) return false;
316
+ var conditionalKey = property === null || property === void 0 ? void 0 : property.dependsOn;
317
+ if (isNotPresent(conditionalKey)) return true;
318
+ var dependentPropertySchema = findBy({
319
+ key: conditionalKey
320
+ }, themePropertiesSchema);
321
+ var dependentProperty = findBy({
322
+ key: conditionalKey
323
+ }, formikValues.properties);
324
+ if (dependentPropertySchema.kind === "image") {
325
+ var _formikValues$snakeTo;
326
+ return isPresent((_formikValues$snakeTo = formikValues[snakeToCamelCase(conditionalKey)]) === null || _formikValues$snakeTo === void 0 ? void 0 : _formikValues$snakeTo.url);
327
+ } else if (dependentPropertySchema.kind === "boolean") {
328
+ return (dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value) !== "false";
329
+ }
330
+ return isPresent(dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value);
331
+ };
332
+ var buildLabel = function buildLabel(key, kind) {
333
+ return t$1("neetoThemes.properties.".concat(snakeToCamelCase(kind), ".").concat(snakeToCamelCase(key)));
334
+ };
335
+
336
+ var Card$2 = function Card(_ref) {
337
+ var _ref$title = _ref.title,
338
+ title = _ref$title === void 0 ? "" : _ref$title,
339
+ children = _ref.children;
340
+ return /*#__PURE__*/jsxs("div", {
341
+ className: "neeto-ui-border-gray-300 neeto-ui-rounded-lg neeto-ui-bg-white space-y-3 border p-4",
342
+ "data-cy": "theme-".concat(hyphenate(title), "-properties"),
343
+ children: [title && /*#__PURE__*/jsx("div", {
344
+ className: "flex items-center justify-between",
345
+ children: /*#__PURE__*/jsx(Typography, {
346
+ "data-cy": "theme-properties",
347
+ lineHeight: "normal",
348
+ style: "h4",
349
+ weight: "semibold",
350
+ children: title
351
+ })
352
+ }), children && /*#__PURE__*/jsx("div", {
353
+ className: "space-y-4",
354
+ children: children
355
+ })]
356
+ });
357
+ };
358
+
359
+ var SelectBlock = function SelectBlock(_ref) {
360
+ var label = _ref.label,
361
+ _ref$placeholder = _ref.placeholder,
362
+ placeholder = _ref$placeholder === void 0 ? "" : _ref$placeholder,
363
+ value = _ref.value,
364
+ options = _ref.options,
365
+ onChange = _ref.onChange;
366
+ return /*#__PURE__*/jsxs("div", {
367
+ className: "flex items-center justify-between py-3 first:pt-0 last:pb-0",
368
+ "data-cy": "theme-style-".concat(joinHyphenCase(label)),
369
+ children: [/*#__PURE__*/jsx(Typography, {
370
+ "data-cy": "logo-field-labels",
371
+ style: "body2",
372
+ children: label
373
+ }), /*#__PURE__*/jsx("div", {
374
+ className: "w-40",
375
+ children: /*#__PURE__*/jsx(Select, {
376
+ onChange: onChange,
377
+ options: options,
378
+ placeholder: placeholder,
379
+ value: value
380
+ })
381
+ })]
382
+ });
383
+ };
384
+
385
+ var DESIGN_SCREENS = {
386
+ THEMES: "Themes",
387
+ Customize: "Customize"
388
+ };
389
+ var ONE_MEGABYTE = 1;
390
+
391
+ var ImageBlock = function ImageBlock(_ref) {
392
+ var _findBy;
393
+ var label = _ref.label,
394
+ name = _ref.name,
395
+ _ref$imageData = _ref.imageData,
396
+ imageData = _ref$imageData === void 0 ? {} : _ref$imageData,
397
+ _ref$uploadConfig = _ref.uploadConfig,
398
+ uploadConfig = _ref$uploadConfig === void 0 ? {
399
+ maxImageSize: ONE_MEGABYTE
400
+ } : _ref$uploadConfig,
401
+ attribute = _ref.attribute;
402
+ var _useTranslation = useTranslation(),
403
+ t = _useTranslation.t;
404
+ var _useFormikContext = useFormikContext(),
405
+ setFieldValue = _useFormikContext.setFieldValue,
406
+ values = _useFormikContext.values;
407
+ var _useConfigStore = useConfigStore(function (store) {
408
+ return {
409
+ themePropertiesSchema: store["themePropertiesSchema"]
410
+ };
411
+ }, shallow),
412
+ themePropertiesSchema = _useConfigStore.themePropertiesSchema;
413
+ var propertySchema = findBy({
414
+ key: attribute
415
+ }, themePropertiesSchema);
416
+ var enablePositionChanger = (propertySchema === null || propertySchema === void 0 ? void 0 : propertySchema.enablePositionChanger) || false;
417
+ var options = propertySchema === null || propertySchema === void 0 ? void 0 : propertySchema.options;
418
+ var positionKeyInSchema = findBy({
419
+ key: "".concat(name, "_position")
420
+ }, themePropertiesSchema);
421
+ var isPositionChangerVisible = enablePositionChanger && (imageData === null || imageData === void 0 ? void 0 : imageData.url) && isPresent(positionKeyInSchema);
422
+ var positionKeyIndex = findIndexBy({
423
+ key: "".concat(name, "_position")
424
+ }, values.properties);
425
+ var handleImageChange = /*#__PURE__*/function () {
426
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(image) {
427
+ var dominantColor;
428
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
429
+ while (1) switch (_context.prev = _context.next) {
430
+ case 0:
431
+ _context.prev = 0;
432
+ if (!(isEmpty(image.signedId) || isEmpty(image.url))) {
433
+ _context.next = 4;
434
+ break;
435
+ }
436
+ setFieldValue(name, {
437
+ signedId: null,
438
+ url: image.url
439
+ });
440
+ return _context.abrupt("return");
441
+ case 4:
442
+ _context.next = 6;
443
+ return getDominantColorFromUrl(image.url);
444
+ case 6:
445
+ dominantColor = _context.sent;
446
+ setFieldValue(name, {
447
+ signedId: image.signedId,
448
+ url: image.url,
449
+ dominantColor: dominantColor
450
+ });
451
+ _context.next = 13;
452
+ break;
453
+ case 10:
454
+ _context.prev = 10;
455
+ _context.t0 = _context["catch"](0);
456
+ Toastr.error(_context.t0);
457
+ case 13:
458
+ case "end":
459
+ return _context.stop();
460
+ }
461
+ }, _callee, null, [[0, 10]]);
462
+ }));
463
+ return function handleImageChange(_x) {
464
+ return _ref2.apply(this, arguments);
465
+ };
466
+ }();
467
+ return /*#__PURE__*/jsxs("div", {
468
+ className: "space-y-3 py-3 first:pt-0 last:pb-0",
469
+ "data-cy": "theme-style-".concat(joinHyphenCase(label)),
470
+ children: [label && /*#__PURE__*/jsx("div", {
471
+ className: "flex items-center justify-between",
472
+ children: /*#__PURE__*/jsx(Typography, {
473
+ "data-cy": "style-fields-labels",
474
+ style: "body2",
475
+ children: label
476
+ })
477
+ }), /*#__PURE__*/jsxs("div", {
478
+ className: "space-y-3 divide-y divide-gray-200",
479
+ children: [/*#__PURE__*/createElement(ImageUploader, {
480
+ uploadConfig: uploadConfig,
481
+ className: "h-40 w-full",
482
+ key: imageData === null || imageData === void 0 ? void 0 : imageData.url,
483
+ src: imageData === null || imageData === void 0 ? void 0 : imageData.url,
484
+ onUploadComplete: handleImageChange
485
+ }), isPositionChangerVisible && /*#__PURE__*/jsx(SelectBlock, {
486
+ label: buildLabel("".concat(name, "Position"), "image"),
487
+ options: options || POSITION_OPTIONS,
488
+ placeholder: t("neetoThemes.common.left"),
489
+ value: toLabelAndValue(((_findBy = findBy({
490
+ key: "".concat(name, "_position")
491
+ }, values.properties)) === null || _findBy === void 0 ? void 0 : _findBy.value) || (positionKeyInSchema === null || positionKeyInSchema === void 0 ? void 0 : positionKeyInSchema.defaultValue)),
492
+ onChange: function onChange(option) {
493
+ return setFieldValue("properties[".concat(positionKeyIndex, "].value"), option.value);
494
+ }
495
+ })]
496
+ })]
497
+ });
498
+ };
499
+
500
+ var Images = function Images(_ref) {
501
+ var attribute = _ref.attribute;
502
+ var _useFormikContext = useFormikContext(),
503
+ values = _useFormikContext.values;
504
+ var key = snakeToCamelCase(attribute);
505
+ var title = buildLabel(key, "image");
506
+ var imageData = values[key];
507
+ return /*#__PURE__*/jsx(Card$2, {
508
+ title: title,
509
+ children: /*#__PURE__*/jsx("div", {
510
+ className: "divide-y divide-gray-200",
511
+ children: /*#__PURE__*/jsx(ImageBlock, {
512
+ attribute: attribute,
513
+ imageData: imageData,
514
+ name: key
515
+ })
516
+ })
517
+ });
518
+ };
519
+
520
+ var AlignmentBlock = function AlignmentBlock(_ref) {
521
+ var label = _ref.label,
522
+ name = _ref.name;
523
+ return /*#__PURE__*/jsxs("div", {
524
+ className: "flex items-center justify-between gap-2 py-3 first:pt-0 last:pb-0",
525
+ "data-cy": joinHyphenCase(label),
526
+ children: [/*#__PURE__*/jsx(Typography, {
527
+ "data-cy": "style-fields-labels",
528
+ style: "body2",
529
+ children: label
530
+ }), /*#__PURE__*/jsx(Field, {
531
+ name: name,
532
+ children: function children(_ref2) {
533
+ var value = _ref2.field.value,
534
+ setFieldValue = _ref2.form.setFieldValue;
535
+ return /*#__PURE__*/jsxs("div", {
536
+ className: "flex items-center gap-3",
537
+ children: [/*#__PURE__*/jsx(Button, {
538
+ "data-cy": "alignment-left",
539
+ icon: LeftAlign,
540
+ size: "large",
541
+ style: value === "left" ? "primary" : "text",
542
+ tooltipProps: {
543
+ content: "Left align",
544
+ position: "bottom"
545
+ },
546
+ onClick: function onClick() {
547
+ return setFieldValue(name, "left");
548
+ }
549
+ }), /*#__PURE__*/jsx(Button, {
550
+ "data-cy": "alignment-center",
551
+ icon: CenterAlign,
552
+ size: "large",
553
+ style: value === "center" ? "primary" : "text",
554
+ tooltipProps: {
555
+ content: "Center align",
556
+ position: "bottom"
557
+ },
558
+ onClick: function onClick() {
559
+ return setFieldValue(name, "center");
560
+ }
561
+ })]
562
+ });
563
+ }
564
+ })]
565
+ });
566
+ };
567
+
568
+ var ColorBlock = function ColorBlock(_ref) {
569
+ var label = _ref.label,
570
+ _ref$color = _ref.color,
571
+ color = _ref$color === void 0 ? "#FFFFFF" : _ref$color,
572
+ onChange = _ref.onChange,
573
+ showTransparencyControl = _ref.showTransparencyControl;
574
+ return /*#__PURE__*/jsxs("div", {
575
+ className: "flex items-center justify-between py-3 first:pt-0 last:pb-0",
576
+ "data-cy": "theme-style-".concat(joinHyphenCase(label)),
577
+ children: [/*#__PURE__*/jsx(Typography, {
578
+ "data-cy": "style-fields-labels",
579
+ style: "body2",
580
+ children: label
581
+ }), /*#__PURE__*/jsx(ColorPicker, {
582
+ color: color,
583
+ onChange: onChange,
584
+ showTransparencyControl: showTransparencyControl,
585
+ showEyeDropper: true
586
+ })]
587
+ });
588
+ };
589
+
590
+ function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
591
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
592
+ var FontPickerBlock = function FontPickerBlock(_ref) {
593
+ var label = _ref.label,
594
+ _ref$placeholder = _ref.placeholder,
595
+ placeholder = _ref$placeholder === void 0 ? "" : _ref$placeholder,
596
+ value = _ref.value,
597
+ options = _ref.options,
598
+ onChange = _ref.onChange;
599
+ return /*#__PURE__*/jsxs("div", {
600
+ className: "flex items-center justify-between py-3 first:pt-0 last:pb-0",
601
+ "data-cy": "theme-style-".concat(joinHyphenCase(label)),
602
+ children: [/*#__PURE__*/jsx(Typography, {
603
+ "data-cy": "style-fields-labels",
604
+ style: "body2",
605
+ children: label
606
+ }), /*#__PURE__*/jsx("div", {
607
+ className: "w-40",
608
+ children: /*#__PURE__*/jsx(Select, {
609
+ onChange: onChange,
610
+ options: options,
611
+ placeholder: placeholder,
612
+ value: value,
613
+ menuPosition: "fixed",
614
+ styles: {
615
+ option: function option(styles, _ref2) {
616
+ var data = _ref2.data;
617
+ return _objectSpread$3(_objectSpread$3({}, styles), {}, {
618
+ fontFamily: data.value
619
+ });
620
+ }
621
+ }
622
+ })
623
+ })]
624
+ });
625
+ };
626
+
627
+ var SliderBlock = function SliderBlock(_ref) {
628
+ var label = _ref.label,
629
+ onChange = _ref.onChange,
630
+ value = _ref.value,
631
+ min = _ref.min,
632
+ max = _ref.max,
633
+ marks = _ref.marks;
634
+ return /*#__PURE__*/jsxs("div", {
635
+ className: "flex items-center justify-between gap-3 py-3 first:pt-0 last:pb-0",
636
+ "data-cy": "theme-style-".concat(joinHyphenCase(label)),
637
+ children: [/*#__PURE__*/jsx(Typography, {
638
+ "data-cy": "style-fields-labels",
639
+ style: "body2",
640
+ children: label
641
+ }), /*#__PURE__*/jsx(Slider, {
642
+ marks: marks,
643
+ max: max,
644
+ min: min,
645
+ onChange: onChange,
646
+ value: value,
647
+ className: "my-2 w-20",
648
+ tooltip: {
649
+ formatter: null
650
+ }
651
+ })]
652
+ });
653
+ };
654
+
655
+ var _excluded = ["label", "name"];
656
+ function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
657
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
658
+ var SwitchBlock = function SwitchBlock(_ref) {
659
+ var label = _ref.label,
660
+ name = _ref.name,
661
+ switchProps = _objectWithoutProperties(_ref, _excluded);
662
+ var _useTranslation = useTranslation(),
663
+ t = _useTranslation.t,
664
+ i18n = _useTranslation.i18n;
665
+ var translationKey = "neetoThemes.properties.boolean.".concat(name, "HelpText");
666
+ var doesHelpTextExist = i18n.exists(translationKey);
667
+ return /*#__PURE__*/jsxs("div", {
668
+ className: "flex items-center justify-between py-3 first:pt-0 last:pb-0",
669
+ children: [/*#__PURE__*/jsxs("div", {
670
+ className: "inline-flex items-center gap-4",
671
+ children: [/*#__PURE__*/jsx(Typography, {
672
+ "data-cy": "style-fields-labels",
673
+ style: "body2",
674
+ className: classnames({
675
+ "w-32": doesHelpTextExist,
676
+ "w-auto": !doesHelpTextExist
677
+ }),
678
+ children: label
679
+ }), doesHelpTextExist && /*#__PURE__*/jsx(HelpPopover, {
680
+ className: "flex-shrink-0",
681
+ description: t(translationKey)
682
+ })]
683
+ }), /*#__PURE__*/jsx(Switch, _objectSpread$2(_objectSpread$2({}, _objectSpread$2({
684
+ name: name
685
+ }, switchProps)), {}, {
686
+ "data-cy": "enable-background-color-toggle"
687
+ }))]
688
+ });
689
+ };
690
+
691
+ var Properties = function Properties(_ref) {
692
+ var onPropertiesChange = _ref.onPropertiesChange;
693
+ var _useTranslation = useTranslation(),
694
+ t = _useTranslation.t;
695
+ var _useConfigStore = useConfigStore(function (store) {
696
+ return {
697
+ themePropertiesSchema: store["themePropertiesSchema"]
698
+ };
699
+ }, shallow),
700
+ themePropertiesSchema = _useConfigStore.themePropertiesSchema;
701
+ var _useThemeStore = useThemeStore(function (store) {
702
+ return {
703
+ setThemeState: store["setThemeState"]
704
+ };
705
+ }, shallow),
706
+ setThemeState = _useThemeStore.setThemeState;
707
+ var _useFormikContext = useFormikContext(),
708
+ setFieldValue = _useFormikContext.setFieldValue,
709
+ values = _useFormikContext.values;
710
+ var _useThemeUtils = useThemeUtils(),
711
+ setVariable = _useThemeUtils.setVariable,
712
+ setTheme = _useThemeUtils.setTheme;
713
+ var handleColorChange = function handleColorChange(name) {
714
+ return function (_ref2) {
715
+ var hex = _ref2.hex,
716
+ rgb = _ref2.rgb;
717
+ handleChange(name, hex, "".concat(rgb.r, ", ").concat(rgb.g, ", ").concat(rgb.b, ", ").concat(rgb.a));
718
+ };
719
+ };
720
+ var handleChange = function handleChange(name, value, variableValue) {
721
+ var index = findIndexBy({
722
+ key: name
723
+ }, values.properties);
724
+ if (index !== -1 && values.properties[index].value !== value) {
725
+ setFieldValue("properties[".concat(index, "].value"), value);
726
+ }
727
+ setVariable(snakeToCamelCase(name), variableValue !== null && variableValue !== void 0 ? variableValue : value);
728
+ };
729
+ var handleOverlayChange = function handleOverlayChange(key, value) {
730
+ var index = findIndexBy({
731
+ key: key
732
+ }, values.properties);
733
+ var overlayColorVariable = "".concat(key, "_overlay_color");
734
+ setFieldValue("properties[".concat(index, "].value"), value);
735
+ setVariable("".concat(key, "_overlay_opacity"), Math.abs(value / 100));
736
+ if (value < 0) {
737
+ handleChange(overlayColorVariable, "#000000", "0, 0, 0");
738
+ } else {
739
+ handleChange(overlayColorVariable, "#ffffff", "255, 255, 255");
740
+ }
741
+ };
742
+ useEffect(function () {
743
+ onPropertiesChange === null || onPropertiesChange === void 0 || onPropertiesChange(values, handleChange, handleColorChange);
744
+ setTheme(values);
745
+ setThemeState({
746
+ previewingTheme: values
747
+ });
748
+ }, [values]);
749
+ return /*#__PURE__*/jsx(Card$2, {
750
+ title: t("neetoThemes.common.style"),
751
+ children: /*#__PURE__*/jsxs("div", {
752
+ className: "divide-y divide-gray-200",
753
+ children: [filterBy({
754
+ kind: "font_family"
755
+ }, values.properties).map(function (_ref3) {
756
+ var key = _ref3.key,
757
+ value = _ref3.value,
758
+ kind = _ref3.kind;
759
+ return isPropertyVisible(key, values, themePropertiesSchema) && /*#__PURE__*/jsx(FontPickerBlock, {
760
+ label: buildLabel(key, kind),
761
+ options: FONT_OPTIONS,
762
+ value: findBy({
763
+ value: value || null
764
+ }, FONT_OPTIONS),
765
+ onChange: function onChange(_ref4) {
766
+ var value = _ref4.value;
767
+ handleChange(key, value);
768
+ }
769
+ }, key);
770
+ }), filterBy({
771
+ kind: "color"
772
+ }, values.properties).map(function (_ref5) {
773
+ var _findBy;
774
+ var key = _ref5.key,
775
+ value = _ref5.value,
776
+ kind = _ref5.kind;
777
+ return isPropertyVisible(key, values, themePropertiesSchema) && /*#__PURE__*/jsx(ColorBlock, {
778
+ color: value,
779
+ label: buildLabel(key, kind),
780
+ showTransparencyControl: ((_findBy = findBy({
781
+ key: key
782
+ }, themePropertiesSchema)) === null || _findBy === void 0 ? void 0 : _findBy.showTransparencyControl) || false,
783
+ onChange: handleColorChange(key)
784
+ }, key);
785
+ }), filterBy({
786
+ kind: "radius"
787
+ }, values.properties).map(function (_ref6) {
788
+ var key = _ref6.key,
789
+ value = _ref6.value,
790
+ kind = _ref6.kind;
791
+ return isPropertyVisible(key, values, themePropertiesSchema) && /*#__PURE__*/jsx(SliderBlock, {
792
+ label: buildLabel(key, kind),
793
+ max: 50,
794
+ min: 0,
795
+ value: Number(value) || 0,
796
+ onChange: function onChange(radius) {
797
+ return handleChange(key, radius, "".concat(radius, "px"));
798
+ }
799
+ }, key);
800
+ }), filterBy({
801
+ kind: "overlay_opacity"
802
+ }, values.properties).map(function (_ref7) {
803
+ var key = _ref7.key,
804
+ value = _ref7.value,
805
+ kind = _ref7.kind;
806
+ return isPropertyVisible(key, values, themePropertiesSchema) && /*#__PURE__*/jsx(SliderBlock, {
807
+ label: buildLabel(key, kind),
808
+ marks: OVERLAY_OPACITY_SLIDER_MARKS,
809
+ max: HUNDRED,
810
+ min: negate(HUNDRED),
811
+ value: Number(value) || 0,
812
+ onChange: function onChange(opacity) {
813
+ return handleOverlayChange(key, opacity);
814
+ }
815
+ }, key);
816
+ }), filterBy({
817
+ kind: "position_selector"
818
+ }, values.properties).map(function (_ref8) {
819
+ var _findBy2;
820
+ var key = _ref8.key,
821
+ kind = _ref8.kind,
822
+ value = _ref8.value;
823
+ var index = findIndexBy({
824
+ key: key
825
+ }, values.properties);
826
+ var options = (_findBy2 = findBy({
827
+ key: key
828
+ }, themePropertiesSchema)) === null || _findBy2 === void 0 || (_findBy2 = _findBy2.options) === null || _findBy2 === void 0 ? void 0 : _findBy2.map(toLabelAndValue);
829
+ return isPropertyVisible(key, values, themePropertiesSchema) && /*#__PURE__*/jsx(SelectBlock, {
830
+ label: buildLabel(key, kind),
831
+ options: options || POSITION_OPTIONS,
832
+ placeholder: "left",
833
+ value: toLabelAndValue(value),
834
+ onChange: function onChange(option) {
835
+ return setFieldValue("properties[".concat(index, "].value"), option.value);
836
+ }
837
+ }, key);
838
+ }), filterBy({
839
+ kind: "boolean"
840
+ }, values.properties).map(function (_ref9) {
841
+ var key = _ref9.key,
842
+ kind = _ref9.kind,
843
+ value = _ref9.value;
844
+ var index = findIndexBy({
845
+ key: key
846
+ }, values.properties);
847
+ return isPropertyVisible(key, values, themePropertiesSchema) && /*#__PURE__*/jsx(SwitchBlock, {
848
+ checked: value !== "false",
849
+ label: buildLabel(key, kind),
850
+ name: snakeToCamelCase(key),
851
+ onChange: function onChange(e) {
852
+ return setFieldValue("properties[".concat(index, "].value"), String(e.target.checked));
853
+ }
854
+ }, key);
855
+ }), filterBy({
856
+ kind: "alignment_block"
857
+ }, values.properties).map(function (_ref10) {
858
+ var key = _ref10.key,
859
+ kind = _ref10.kind;
860
+ var index = findIndexBy({
861
+ key: key
862
+ }, values.properties);
863
+ return isPropertyVisible(key, values, themePropertiesSchema) && /*#__PURE__*/jsx(AlignmentBlock, {
864
+ label: buildLabel(key, kind),
865
+ name: "properties[".concat(index, "].value")
866
+ });
867
+ })]
868
+ })
869
+ });
870
+ };
871
+
872
+ var ThemeMeta = withT(function (_ref) {
873
+ var t = _ref.t;
874
+ return /*#__PURE__*/jsx(Card$2, {
875
+ title: t("neetoThemes.common.name"),
876
+ children: /*#__PURE__*/jsx(Input, {
877
+ autoFocus: true,
878
+ "data-cy": "theme-name-property",
879
+ name: "name"
880
+ })
881
+ });
882
+ });
883
+
884
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
885
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
886
+ var Customize = function Customize(_ref) {
887
+ var themeId = _ref.themeId,
888
+ theme = _ref.theme,
889
+ onCreateTheme = _ref.onCreateTheme,
890
+ onApplyTheme = _ref.onApplyTheme,
891
+ isApplyingTheme = _ref.isApplyingTheme,
892
+ onPropertiesChange = _ref.onPropertiesChange,
893
+ onUpdateThemeSuccess = _ref.onUpdateThemeSuccess;
894
+ var _useTranslation = useTranslation(),
895
+ t = _useTranslation.t;
896
+ var _useState = useState({}),
897
+ _useState2 = _slicedToArray(_useState, 2),
898
+ popoverInstance = _useState2[0],
899
+ setPopoverInstance = _useState2[1];
900
+ var _useConfigStore = useConfigStore(function (store) {
901
+ return {
902
+ themePropertiesSchema: store["themePropertiesSchema"],
903
+ entityType: store["entityType"]
904
+ };
905
+ }, shallow),
906
+ themePropertiesSchema = _useConfigStore.themePropertiesSchema,
907
+ entityType = _useConfigStore.entityType;
908
+ var _useThemeUtils = useThemeUtils(),
909
+ currentTheme = _useThemeUtils.currentTheme;
910
+ var isEditingCurrentlyAppliedTheme = themeId === (currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.id);
911
+ var submitBtnRef = useRef(null);
912
+ var _useCreateTheme = useCreateTheme(),
913
+ createTheme = _useCreateTheme.mutate,
914
+ isCreating = _useCreateTheme.isPending;
915
+ var _useUpdateTheme = useUpdateTheme(themeId),
916
+ updateTheme = _useUpdateTheme.mutate,
917
+ isUpdating = _useUpdateTheme.isPending;
918
+ var isSubmitting = isCreating || isUpdating;
919
+ var onSubmit = function onSubmit(values, _ref2) {
920
+ var resetForm = _ref2.resetForm;
921
+ var imageData = buildImageData(values, themePropertiesSchema);
922
+ var themeToSave = _objectSpread$1({
923
+ propertiesAttributes: values.properties,
924
+ name: values.name
925
+ }, imageData);
926
+ if (!themeId) {
927
+ return createTheme(themeToSave, {
928
+ onSuccess: function onSuccess(_ref3) {
929
+ var theme = _ref3.theme;
930
+ resetForm({
931
+ values: theme
932
+ });
933
+ onCreateTheme(theme);
934
+ }
935
+ });
936
+ }
937
+ return updateTheme(themeToSave, {
938
+ onSuccess: function onSuccess() {
939
+ resetForm({
940
+ values: values
941
+ });
942
+ onUpdateThemeSuccess === null || onUpdateThemeSuccess === void 0 || onUpdateThemeSuccess(values);
943
+ }
944
+ });
945
+ };
946
+ return /*#__PURE__*/jsx(Form, {
947
+ formikProps: {
948
+ initialValues: buildInitialValues(theme, themePropertiesSchema),
949
+ validationSchema: THEME_VALIDATION_SCHEMA,
950
+ onSubmit: onSubmit
951
+ },
952
+ children: function children(_ref4) {
953
+ var dirty = _ref4.dirty;
954
+ return /*#__PURE__*/jsxs("div", {
955
+ className: "neeto-themes-sidebar__scroll",
956
+ children: [/*#__PURE__*/jsxs("div", {
957
+ className: "flex flex-col gap-6 p-4",
958
+ children: [/*#__PURE__*/jsx(ThemeMeta, {}), /*#__PURE__*/jsx(Properties, {
959
+ onPropertiesChange: onPropertiesChange
960
+ }), filterBy({
961
+ kind: "image"
962
+ }, themePropertiesSchema).map(function (_ref5) {
963
+ var key = _ref5.key;
964
+ return /*#__PURE__*/jsx(Images, {
965
+ attribute: key
966
+ }, key);
967
+ })]
968
+ }), /*#__PURE__*/jsxs("div", {
969
+ className: "neeto-ui-bg-white neeto-ui-shadow-s sticky bottom-0 left-0 right-0 flex justify-end gap-x-2 px-4 py-6",
970
+ children: [/*#__PURE__*/jsx(Button, {
971
+ "data-cy": "reset-button",
972
+ disabled: !dirty || isSubmitting,
973
+ label: t("neetoThemes.buttons.reset"),
974
+ style: "text",
975
+ type: "reset"
976
+ }), /*#__PURE__*/jsx(Button, {
977
+ "data-cy": "save-changes-button",
978
+ disabled: !dirty && (theme === null || theme === void 0 ? void 0 : theme.id) || isSubmitting,
979
+ label: t("neetoThemes.buttons.save"),
980
+ loading: isSubmitting,
981
+ ref: submitBtnRef,
982
+ type: "submit"
983
+ })]
984
+ }), /*#__PURE__*/jsx(Popover, {
985
+ appendTo: function appendTo() {
986
+ return document.body;
987
+ },
988
+ disabled: isEditingCurrentlyAppliedTheme,
989
+ position: "top",
990
+ reference: submitBtnRef,
991
+ trigger: "click",
992
+ content: /*#__PURE__*/jsxs("div", {
993
+ className: "flex flex-col items-start gap-2",
994
+ children: [/*#__PURE__*/jsx(Button, {
995
+ className: "absolute right-1 top-1 z-0",
996
+ icon: Close,
997
+ size: "small",
998
+ style: "text",
999
+ onClick: function onClick() {
1000
+ var _popoverInstance$hide;
1001
+ return popoverInstance === null || popoverInstance === void 0 || (_popoverInstance$hide = popoverInstance.hide) === null || _popoverInstance$hide === void 0 ? void 0 : _popoverInstance$hide.call(popoverInstance);
1002
+ }
1003
+ }), /*#__PURE__*/jsx(Typography, {
1004
+ className: "w-72 pr-5",
1005
+ style: "body2",
1006
+ weight: "normal",
1007
+ children: /*#__PURE__*/jsx(Trans, {
1008
+ components: {
1009
+ bold: /*#__PURE__*/jsx("strong", {})
1010
+ },
1011
+ i18nKey: "neetoThemes.build.leftSideBar.themes.notAppliedYet",
1012
+ values: {
1013
+ entityType: entityType
1014
+ }
1015
+ })
1016
+ }), /*#__PURE__*/jsx(Button, {
1017
+ disabled: isApplyingTheme,
1018
+ label: t("neetoThemes.buttons.applyThisTheme"),
1019
+ loading: isApplyingTheme,
1020
+ onClick: function onClick() {
1021
+ return onApplyTheme(theme);
1022
+ }
1023
+ })]
1024
+ }),
1025
+ onMount: setPopoverInstance
1026
+ })]
1027
+ });
1028
+ }
1029
+ });
1030
+ };
1031
+
1032
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1033
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1034
+ var Check = function Check(props) {
1035
+ return /*#__PURE__*/jsxs("svg", _objectSpread(_objectSpread({
1036
+ fill: "none",
1037
+ height: "24",
1038
+ viewBox: "0 0 24 24",
1039
+ width: "24",
1040
+ xmlns: "http://www.w3.org/2000/svg"
1041
+ }, props), {}, {
1042
+ children: [/*#__PURE__*/jsxs("g", {
1043
+ filter: "url(#filter0_d_9519_161)",
1044
+ children: [/*#__PURE__*/jsx("rect", {
1045
+ fill: "#008068",
1046
+ height: "20",
1047
+ rx: "10",
1048
+ width: "20",
1049
+ x: "2",
1050
+ y: "2"
1051
+ }), /*#__PURE__*/jsx("rect", {
1052
+ height: "20",
1053
+ rx: "10",
1054
+ stroke: "#fff",
1055
+ strokeWidth: "1.5",
1056
+ width: "20",
1057
+ x: "2",
1058
+ y: "2"
1059
+ }), /*#__PURE__*/jsx("path", {
1060
+ d: "M16.375 9.5l-5.95 6.25-2.8-2.941",
1061
+ stroke: "#fff",
1062
+ strokeLinecap: "round",
1063
+ strokeLinejoin: "round",
1064
+ strokeWidth: "1.25"
1065
+ })]
1066
+ }), /*#__PURE__*/jsx("defs", {
1067
+ children: /*#__PURE__*/jsxs("filter", {
1068
+ colorInterpolationFilters: "sRGB",
1069
+ filterUnits: "userSpaceOnUse",
1070
+ height: "23.5",
1071
+ id: "filter0_d_9519_161",
1072
+ width: "23.5",
1073
+ x: "0.25",
1074
+ y: "0.25",
1075
+ children: [/*#__PURE__*/jsx("feFlood", {
1076
+ floodOpacity: "0",
1077
+ result: "BackgroundImageFix"
1078
+ }), /*#__PURE__*/jsx("feColorMatrix", {
1079
+ "in": "SourceAlpha",
1080
+ result: "hardAlpha",
1081
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
1082
+ }), /*#__PURE__*/jsx("feOffset", {}), /*#__PURE__*/jsx("feGaussianBlur", {
1083
+ stdDeviation: "0.5"
1084
+ }), /*#__PURE__*/jsx("feComposite", {
1085
+ in2: "hardAlpha",
1086
+ operator: "out"
1087
+ }), /*#__PURE__*/jsx("feColorMatrix", {
1088
+ values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.09 0"
1089
+ }), /*#__PURE__*/jsx("feBlend", {
1090
+ in2: "BackgroundImageFix",
1091
+ result: "effect1_dropShadow_9519_161"
1092
+ }), /*#__PURE__*/jsx("feBlend", {
1093
+ "in": "SourceGraphic",
1094
+ in2: "effect1_dropShadow_9519_161",
1095
+ result: "shape"
1096
+ })]
1097
+ })
1098
+ })]
1099
+ }));
1100
+ };
1101
+
1102
+ var Thumbnail = function Thumbnail(_ref) {
1103
+ var _theme$snakeToCamelCa, _findBy, _findBy2;
1104
+ var active = _ref.active,
1105
+ isPreviewing = _ref.isPreviewing,
1106
+ isHighLightedTheme = _ref.isHighLightedTheme,
1107
+ theme = _ref.theme;
1108
+ var _useConfigStore = useConfigStore(function (store) {
1109
+ return {
1110
+ themePropertiesSchema: store["themePropertiesSchema"]
1111
+ };
1112
+ }, shallow),
1113
+ _useConfigStore$theme = _useConfigStore.themePropertiesSchema,
1114
+ themePropertiesSchema = _useConfigStore$theme === void 0 ? [] : _useConfigStore$theme;
1115
+ var _themePropertiesSchem = _slicedToArray(themePropertiesSchema, 2),
1116
+ colorObject1 = _themePropertiesSchem[0],
1117
+ colorObject2 = _themePropertiesSchem[1];
1118
+ var primaryLabel = humanize(colorObject1 === null || colorObject1 === void 0 ? void 0 : colorObject1.key);
1119
+ var secondaryLabel = humanize(colorObject2 === null || colorObject2 === void 0 ? void 0 : colorObject2.key);
1120
+ var primaryColor = findBy({
1121
+ key: colorObject1.key
1122
+ }, theme.properties).value;
1123
+ var secondaryColor = findBy({
1124
+ key: colorObject2.key
1125
+ }, theme.properties).value;
1126
+ var backgroundImageUrl = (_theme$snakeToCamelCa = theme[snakeToCamelCase(findBy({
1127
+ useAsCardBackground: true
1128
+ }, themePropertiesSchema).key)]) === null || _theme$snakeToCamelCa === void 0 ? void 0 : _theme$snakeToCamelCa.url;
1129
+ var buttonBackgroundColor = (_findBy = findBy({
1130
+ key: (_findBy2 = findBy({
1131
+ useAsCardButtonBackground: true
1132
+ }, themePropertiesSchema)) === null || _findBy2 === void 0 ? void 0 : _findBy2.key
1133
+ }, theme.properties)) === null || _findBy === void 0 ? void 0 : _findBy.value;
1134
+ return /*#__PURE__*/jsx("div", {
1135
+ className: classnames("neeto-themes-theme-thumbnail neeto-ui-rounded-lg border transition-all duration-300 ease-in-out", {
1136
+ "neeto-ui-border-gray-400": !active,
1137
+ "neeto-ui-border-gray-800 neeto-themes-theme-thumbnail--active": active,
1138
+ "neeto-themes-theme-thumbnail--preview-active": isPreviewing,
1139
+ "neeto-themes-theme-thumbnail--highlight-active": isHighLightedTheme
1140
+ }),
1141
+ style: {
1142
+ backgroundImage: backgroundImageUrl ? "url(".concat(backgroundImageUrl, ")") : "initial",
1143
+ backgroundSize: "cover"
1144
+ },
1145
+ children: /*#__PURE__*/jsx("div", {
1146
+ className: "neeto-ui-rounded-lg cursor-pointer p-3 transition-all duration-300 ease-in-out group-hover:opacity-85",
1147
+ children: /*#__PURE__*/jsxs("div", {
1148
+ className: "neeto-ui-rounded-lg p-3",
1149
+ children: [/*#__PURE__*/jsxs("div", {
1150
+ className: "mb-3",
1151
+ children: [/*#__PURE__*/jsx(Typography, {
1152
+ style: "h3",
1153
+ weight: "semibold",
1154
+ children: /*#__PURE__*/jsx("span", {
1155
+ style: {
1156
+ color: primaryColor
1157
+ },
1158
+ children: primaryLabel
1159
+ })
1160
+ }), /*#__PURE__*/jsx(Typography, {
1161
+ className: "neeto-ui-text-gray-600",
1162
+ style: "body2",
1163
+ children: /*#__PURE__*/jsx("span", {
1164
+ style: {
1165
+ color: secondaryColor
1166
+ },
1167
+ children: secondaryLabel
1168
+ })
1169
+ })]
1170
+ }), /*#__PURE__*/jsx("div", {
1171
+ className: "neeto-ui-rounded-lg h-5 w-12",
1172
+ style: {
1173
+ backgroundColor: buttonBackgroundColor
1174
+ }
1175
+ })]
1176
+ })
1177
+ })
1178
+ });
1179
+ };
1180
+
1181
+ var Card = function Card(_ref) {
1182
+ var _ref$active = _ref.active,
1183
+ active = _ref$active === void 0 ? false : _ref$active,
1184
+ isPreviewing = _ref.isPreviewing,
1185
+ onSetPreviewTheme = _ref.onSetPreviewTheme,
1186
+ onDeleteTheme = _ref.onDeleteTheme,
1187
+ onEditTheme = _ref.onEditTheme,
1188
+ theme = _ref.theme,
1189
+ isApplyingTheme = _ref.isApplyingTheme,
1190
+ onCloneTheme = _ref.onCloneTheme,
1191
+ isHighLightedTheme = _ref.isHighLightedTheme,
1192
+ onApplyTheme = _ref.onApplyTheme,
1193
+ Thumbnail$1 = _ref.thumbnail;
1194
+ var _useTranslation = useTranslation(),
1195
+ t = _useTranslation.t;
1196
+ var id = theme.id,
1197
+ name = theme.name,
1198
+ appliedCount = theme.appliedCount;
1199
+ var handleCloneTheme = function handleCloneTheme() {
1200
+ return onCloneTheme(theme);
1201
+ };
1202
+ var handleEditTheme = function handleEditTheme() {
1203
+ return onEditTheme(theme);
1204
+ };
1205
+ var handleDeleteTheme = function handleDeleteTheme() {
1206
+ return onDeleteTheme(id, name, appliedCount);
1207
+ };
1208
+ return /*#__PURE__*/jsx("div", {
1209
+ className: "group space-y-2 pt-0.5",
1210
+ "data-cy": active ? "active-theme-card" : "theme-card",
1211
+ id: theme.id,
1212
+ children: /*#__PURE__*/jsxs("div", {
1213
+ className: classnames("neeto-themes-theme-thumbnail neeto-ui-rounded-lg cursor-pointer border transition-all duration-300 ease-in-out", {
1214
+ "neeto-ui-border-gray-200": !active,
1215
+ "neeto-themes-theme-thumbnail--active": active,
1216
+ "neeto-themes-theme-thumbnail--preview-active": isPreviewing,
1217
+ "neeto-themes-theme-thumbnail--highlight-active": isHighLightedTheme
1218
+ }),
1219
+ onClick: function onClick() {
1220
+ return onSetPreviewTheme(theme);
1221
+ },
1222
+ children: [/*#__PURE__*/jsxs("div", {
1223
+ className: "neeto-ui-rounded-lg relative overflow-hidden rounded-bl-none rounded-br-none transition-all duration-300 ease-in-out group-hover:opacity-85",
1224
+ children: [/*#__PURE__*/jsx("div", {
1225
+ className: "absolute right-0 top-0 p-3",
1226
+ children: active ? /*#__PURE__*/jsx(Check, {
1227
+ className: "flex-shrink-0",
1228
+ "data-cy": "active-theme-label"
1229
+ }) : /*#__PURE__*/jsx("div", {
1230
+ className: classnames({
1231
+ hidden: !isPreviewing,
1232
+ "group-hover:block": true
1233
+ }),
1234
+ children: /*#__PURE__*/jsx(Button, {
1235
+ className: "neeto-themes-theme-thumbnail__apply-btn flex-shrink-0",
1236
+ "data-cy": "apply-theme-button",
1237
+ disabled: isApplyingTheme,
1238
+ label: t("neetoThemes.common.apply"),
1239
+ loading: isApplyingTheme,
1240
+ size: "small",
1241
+ style: "tertiary",
1242
+ onClick: function onClick() {
1243
+ return onApplyTheme(theme);
1244
+ }
1245
+ })
1246
+ })
1247
+ }), Thumbnail$1 ? /*#__PURE__*/jsx(Thumbnail$1, {
1248
+ active: active,
1249
+ isHighLightedTheme: isHighLightedTheme,
1250
+ isPreviewing: isPreviewing,
1251
+ theme: theme
1252
+ }) : /*#__PURE__*/jsx(Thumbnail, {
1253
+ active: active,
1254
+ isHighLightedTheme: isHighLightedTheme,
1255
+ isPreviewing: isPreviewing,
1256
+ theme: theme
1257
+ })]
1258
+ }), /*#__PURE__*/jsxs("div", {
1259
+ className: "flex items-start justify-between gap-1 p-3",
1260
+ children: [/*#__PURE__*/jsx(Typography, {
1261
+ className: "line-clamp-2 min-w-0 flex-grow break-words pt-1",
1262
+ "data-cy": "theme-name",
1263
+ lineHeight: "snug",
1264
+ style: "body2",
1265
+ children: name
1266
+ }), /*#__PURE__*/jsx(MoreDropdown, {
1267
+ dropdownButtonProps: {
1268
+ size: "small"
1269
+ },
1270
+ dropdownProps: {
1271
+ strategy: "fixed",
1272
+ onClick: function onClick(e) {
1273
+ return e.stopPropagation();
1274
+ }
1275
+ },
1276
+ menuItems: [{
1277
+ key: "edit",
1278
+ "data-cy": "edit-theme-menu-item",
1279
+ label: t("neetoThemes.common.edit"),
1280
+ isVisible: isPresent(onEditTheme),
1281
+ onClick: handleEditTheme
1282
+ }, {
1283
+ key: "clone",
1284
+ "data-cy": "clone-theme-menu-item",
1285
+ label: t("neetoThemes.build.leftSideBar.themes.themeOptions.clone"),
1286
+ onClick: handleCloneTheme
1287
+ }, {
1288
+ key: "divider",
1289
+ type: "divider",
1290
+ isVisible: isFunction(onDeleteTheme)
1291
+ }, {
1292
+ key: "delete",
1293
+ "data-cy": "delete-theme-menu-item",
1294
+ label: t("neetoThemes.build.leftSideBar.themes.themeOptions.delete"),
1295
+ isVisible: isFunction(onDeleteTheme),
1296
+ onClick: function onClick(e) {
1297
+ e.stopPropagation();
1298
+ handleDeleteTheme();
1299
+ }
1300
+ }]
1301
+ })]
1302
+ })]
1303
+ })
1304
+ });
1305
+ };
1306
+ var Card$1 = /*#__PURE__*/memo(Card);
1307
+
1308
+ var Themes = function Themes(_ref) {
1309
+ var onEditTheme = _ref.onEditTheme,
1310
+ _ref$themes = _ref.themes,
1311
+ themes = _ref$themes === void 0 ? [] : _ref$themes,
1312
+ _ref$defaultThemes = _ref.defaultThemes,
1313
+ defaultThemes = _ref$defaultThemes === void 0 ? [] : _ref$defaultThemes,
1314
+ onDeleteTheme = _ref.onDeleteTheme,
1315
+ themeToHighlight = _ref.themeToHighlight,
1316
+ didScrollActiveThemeIntoView = _ref.didScrollActiveThemeIntoView,
1317
+ isLoading = _ref.isLoading,
1318
+ currentTheme = _ref.currentTheme,
1319
+ isCurrentThemeLoading = _ref.isCurrentThemeLoading,
1320
+ thumbnail = _ref.thumbnail,
1321
+ themeBeingApplied = _ref.themeBeingApplied,
1322
+ onApplyTheme = _ref.onApplyTheme,
1323
+ isApplyingTheme = _ref.isApplyingTheme;
1324
+ var _useTranslation = useTranslation(),
1325
+ t = _useTranslation.t;
1326
+ var _useThemeUtils = useThemeUtils(),
1327
+ setTheme = _useThemeUtils.setTheme;
1328
+ var _useThemeStore = useThemeStore(function (store) {
1329
+ return {
1330
+ setThemeState: store["setThemeState"],
1331
+ previewingTheme: store["previewingTheme"]
1332
+ };
1333
+ }, shallow),
1334
+ setThemeState = _useThemeStore.setThemeState,
1335
+ previewingTheme = _useThemeStore.previewingTheme;
1336
+ var _useState = useState(""),
1337
+ _useState2 = _slicedToArray(_useState, 2),
1338
+ searchQuery = _useState2[0],
1339
+ setSearchQuery = _useState2[1];
1340
+ var _useCloneTheme = useCloneTheme(),
1341
+ cloneTheme = _useCloneTheme.mutate;
1342
+ useEffect(function () {
1343
+ if (didScrollActiveThemeIntoView.current || !(currentTheme !== null && currentTheme !== void 0 && currentTheme.id)) return;
1344
+ didScrollActiveThemeIntoView.current = true;
1345
+ setTimeout(function () {
1346
+ scrollElementIntoView(currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.id);
1347
+ }, 100);
1348
+ }, [didScrollActiveThemeIntoView, currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.id]);
1349
+ var setPreviewTheme = function setPreviewTheme(theme) {
1350
+ setThemeState({
1351
+ previewingTheme: theme
1352
+ });
1353
+ setTheme(theme);
1354
+ };
1355
+ var filteredDefaultThemes = defaultThemes.filter(function (theme) {
1356
+ return theme.name.toLowerCase().includes(searchQuery.toLowerCase());
1357
+ });
1358
+ var filteredThemes = themes.filter(function (theme) {
1359
+ return theme.name.toLowerCase().includes(searchQuery.toLowerCase());
1360
+ });
1361
+ var isSearchFieldVisible = (themes === null || themes === void 0 ? void 0 : themes.length) + (defaultThemes === null || defaultThemes === void 0 ? void 0 : defaultThemes.length) > 10;
1362
+ var handleCloneTheme = function handleCloneTheme(data) {
1363
+ cloneTheme(data.id, {
1364
+ onSuccess: function onSuccess(_ref2) {
1365
+ var clonedTheme = _ref2.theme;
1366
+ onEditTheme(clonedTheme);
1367
+ }
1368
+ });
1369
+ };
1370
+ if (isLoading || isCurrentThemeLoading) {
1371
+ return /*#__PURE__*/jsx("div", {
1372
+ className: "flex h-full w-full items-center justify-center",
1373
+ children: /*#__PURE__*/jsx(Spinner, {})
1374
+ });
1375
+ }
1376
+ return /*#__PURE__*/jsxs("div", {
1377
+ className: "neeto-themes-sidebar__scroll",
1378
+ children: [/*#__PURE__*/jsxs("div", {
1379
+ className: "mb-6 space-y-3",
1380
+ children: [isSearchFieldVisible && /*#__PURE__*/jsx(Search, {
1381
+ autoFocus: true,
1382
+ autoComplete: "off",
1383
+ className: "mb-4 mt-1 px-6",
1384
+ placeholder: t("neetoThemes.common.searchThemes"),
1385
+ onSearch: setSearchQuery
1386
+ }), isEmpty(filteredThemes) && isEmpty(filteredDefaultThemes) && /*#__PURE__*/jsx(Typography, {
1387
+ className: "text-center",
1388
+ style: "body2",
1389
+ children: t("neetoThemes.common.noResultsFound")
1390
+ }), isNotEmpty(filteredDefaultThemes) && /*#__PURE__*/jsxs(Fragment, {
1391
+ children: [/*#__PURE__*/jsx(Typography, {
1392
+ className: "my-4 px-4 uppercase lg:px-5 xl:px-6",
1393
+ "data-cy": "system-themes-header",
1394
+ style: "h6",
1395
+ weight: "semibold",
1396
+ children: t("neetoThemes.build.leftSideBar.themes.systemThemes")
1397
+ }), /*#__PURE__*/jsx("div", {
1398
+ className: "flex flex-col gap-4 px-4 pb-10 lg:px-5 xl:px-6",
1399
+ "data-cy": "system-themes",
1400
+ children: filteredDefaultThemes.map(function (theme) {
1401
+ return /*#__PURE__*/createElement(Card$1, {
1402
+ onApplyTheme: onApplyTheme,
1403
+ theme: theme,
1404
+ thumbnail: thumbnail,
1405
+ active: (currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.id) === theme.id,
1406
+ isPreviewing: (previewingTheme === null || previewingTheme === void 0 ? void 0 : previewingTheme.id) === theme.id,
1407
+ key: theme.id,
1408
+ isApplyingTheme: isApplyingTheme && (themeBeingApplied === null || themeBeingApplied === void 0 ? void 0 : themeBeingApplied.id) === theme.id,
1409
+ onCloneTheme: handleCloneTheme,
1410
+ onSetPreviewTheme: setPreviewTheme
1411
+ });
1412
+ })
1413
+ })]
1414
+ })]
1415
+ }), isNotEmpty(filteredThemes) && /*#__PURE__*/jsxs("div", {
1416
+ className: "mb-6 space-y-3",
1417
+ children: [/*#__PURE__*/jsx(Typography, {
1418
+ className: "my-4 px-6 uppercase",
1419
+ "data-cy": "custom-themes-header",
1420
+ style: "h6",
1421
+ weight: "semibold",
1422
+ children: t("neetoThemes.build.leftSideBar.themes.customThemes")
1423
+ }), /*#__PURE__*/jsx("div", {
1424
+ className: "flex flex-col gap-4 px-6",
1425
+ "data-cy": "custom-themes",
1426
+ children: filteredThemes.map(function (theme) {
1427
+ var isActive = (currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.id) === theme.id;
1428
+ var isPreviewing = (previewingTheme === null || previewingTheme === void 0 ? void 0 : previewingTheme.id) === theme.id;
1429
+ return /*#__PURE__*/createElement(Card$1, {
1430
+ isPreviewing: isPreviewing,
1431
+ onApplyTheme: onApplyTheme,
1432
+ onEditTheme: onEditTheme,
1433
+ theme: theme,
1434
+ thumbnail: thumbnail,
1435
+ active: isActive,
1436
+ isHighLightedTheme: theme.id === themeToHighlight,
1437
+ key: theme.id,
1438
+ isApplyingTheme: isApplyingTheme && (themeBeingApplied === null || themeBeingApplied === void 0 ? void 0 : themeBeingApplied.id) === theme.id,
1439
+ onCloneTheme: handleCloneTheme,
1440
+ onDeleteTheme: !isActive && onDeleteTheme,
1441
+ onSetPreviewTheme: setPreviewTheme
1442
+ });
1443
+ })
1444
+ })]
1445
+ })]
1446
+ });
1447
+ };
1448
+
1449
+ var TitleBar = function TitleBar(_ref) {
1450
+ var currentScreen = _ref.currentScreen,
1451
+ handleBackPress = _ref.handleBackPress,
1452
+ handleCreateNewTheme = _ref.handleCreateNewTheme,
1453
+ isNewTheme = _ref.isNewTheme,
1454
+ themeToEdit = _ref.themeToEdit;
1455
+ var _useTranslation = useTranslation(),
1456
+ t = _useTranslation.t;
1457
+ if (currentScreen === DESIGN_SCREENS.Customize) {
1458
+ return /*#__PURE__*/jsx("div", {
1459
+ className: "neeto-themes-sidebar__header px-4",
1460
+ children: /*#__PURE__*/jsxs("div", {
1461
+ className: "flex items-center justify-start space-x-2",
1462
+ children: [/*#__PURE__*/jsx(Button, {
1463
+ "data-cy": "customize-themes-back-button",
1464
+ icon: LeftArrow,
1465
+ iconPosition: "left",
1466
+ style: "text",
1467
+ tooltipProps: {
1468
+ content: t("neetoThemes.buttons.backToThemes"),
1469
+ position: "top"
1470
+ },
1471
+ onClick: function onClick() {
1472
+ return handleBackPress(themeToEdit);
1473
+ }
1474
+ }), /*#__PURE__*/jsx(Typography, {
1475
+ "data-cy": "themes-header",
1476
+ lineHeight: "normal",
1477
+ style: "h3",
1478
+ weight: "semibold",
1479
+ children: isNewTheme ? t("neetoThemes.build.leftSideBar.themes.createTheme.title") : t("neetoThemes.build.leftSideBar.themes.editTheme.title")
1480
+ })]
1481
+ })
1482
+ });
1483
+ }
1484
+ return /*#__PURE__*/jsx("div", {
1485
+ className: "neeto-themes-sidebar__header px-4 lg:px-5 xl:px-6",
1486
+ children: /*#__PURE__*/jsxs("div", {
1487
+ className: "flex items-center justify-between space-x-2",
1488
+ children: [/*#__PURE__*/jsx(Typography, {
1489
+ "data-cy": "themes-header",
1490
+ lineHeight: "normal",
1491
+ style: "h3",
1492
+ weight: "semibold",
1493
+ children: t("neetoThemes.build.leftSideBar.headerTabs.themes")
1494
+ }), /*#__PURE__*/jsx("div", {
1495
+ className: "self-end",
1496
+ children: /*#__PURE__*/jsx(Button, {
1497
+ "data-cy": "customize-themes-add-theme-button",
1498
+ icon: Plus,
1499
+ iconPosition: "left",
1500
+ style: "text",
1501
+ tooltipProps: {
1502
+ content: t("neetoThemes.buttons.addNewTheme"),
1503
+ position: "top"
1504
+ },
1505
+ onClick: handleCreateNewTheme
1506
+ })
1507
+ })]
1508
+ })
1509
+ });
1510
+ };
1511
+
1512
+ var MemoizedAlert = /*#__PURE__*/memo(Alert);
1513
+ var Sidebar = function Sidebar(_ref) {
1514
+ var _themeToEdit$current, _themeToEdit$current2, _themeToDelete$curren2, _themeToDelete$curren3, _themeToDelete$curren4;
1515
+ var thumbnail = _ref.thumbnail,
1516
+ onPropertiesChange = _ref.onPropertiesChange,
1517
+ onApplyThemeSuccess = _ref.onApplyThemeSuccess,
1518
+ onUpdateThemeSuccess = _ref.onUpdateThemeSuccess;
1519
+ var _useState = useState(DESIGN_SCREENS.THEMES),
1520
+ _useState2 = _slicedToArray(_useState, 2),
1521
+ currentScreen = _useState2[0],
1522
+ setCurrentScreen = _useState2[1];
1523
+ var _useState3 = useState(false),
1524
+ _useState4 = _slicedToArray(_useState3, 2),
1525
+ isDeleteAlertOpen = _useState4[0],
1526
+ setIsDeleteAlertOpen = _useState4[1];
1527
+ var _useState5 = useState(null),
1528
+ _useState6 = _slicedToArray(_useState5, 2),
1529
+ themeToHighlight = _useState6[0],
1530
+ setThemeToHighlight = _useState6[1];
1531
+ var _useState7 = useState({}),
1532
+ _useState8 = _slicedToArray(_useState7, 2),
1533
+ themeBeingApplied = _useState8[0],
1534
+ setThemeBeingApplied = _useState8[1];
1535
+ var _useConfigStore = useConfigStore(function (store) {
1536
+ return {
1537
+ entityType: store["entityType"],
1538
+ entityId: store["entityId"],
1539
+ isFetchingSchema: store["isFetchingSchema"],
1540
+ defaultThemeName: store["defaultThemeName"]
1541
+ };
1542
+ }, shallow),
1543
+ entityType = _useConfigStore.entityType,
1544
+ entityId = _useConfigStore.entityId,
1545
+ isFetchingSchema = _useConfigStore.isFetchingSchema,
1546
+ defaultThemeName = _useConfigStore.defaultThemeName;
1547
+ var _useThemeStore = useThemeStore(function (store) {
1548
+ return {
1549
+ setThemeState: store["setThemeState"]
1550
+ };
1551
+ }, shallow),
1552
+ setThemeState = _useThemeStore.setThemeState;
1553
+ var didScrollActiveThemeIntoView = useRef(null);
1554
+ var _useTranslation = useTranslation(),
1555
+ t = _useTranslation.t;
1556
+ var _useThemeUtils = useThemeUtils(),
1557
+ setTheme = _useThemeUtils.setTheme;
1558
+ var _useListThemes = useListThemes(entityId),
1559
+ _useListThemes$data = _useListThemes.data,
1560
+ _useListThemes$data2 = _useListThemes$data === void 0 ? {} : _useListThemes$data,
1561
+ _useListThemes$data2$ = _useListThemes$data2.themes,
1562
+ themes = _useListThemes$data2$ === void 0 ? [] : _useListThemes$data2$,
1563
+ _useListThemes$data2$2 = _useListThemes$data2.defaultThemes,
1564
+ defaultThemes = _useListThemes$data2$2 === void 0 ? [] : _useListThemes$data2$2,
1565
+ isLoading = _useListThemes.isLoading;
1566
+ var _useShowThemeEntity = useShowThemeEntity(entityId),
1567
+ _useShowThemeEntity$d = _useShowThemeEntity.data,
1568
+ _useShowThemeEntity$d2 = _useShowThemeEntity$d === void 0 ? {} : _useShowThemeEntity$d,
1569
+ _useShowThemeEntity$d3 = _useShowThemeEntity$d2.theme,
1570
+ currentTheme = _useShowThemeEntity$d3 === void 0 ? {} : _useShowThemeEntity$d3,
1571
+ isCurrentThemeLoading = _useShowThemeEntity.isLoading;
1572
+ var _useDeleteTheme = useDeleteTheme(),
1573
+ deleteTheme = _useDeleteTheme.mutate,
1574
+ isDeleting = _useDeleteTheme.isPending;
1575
+ var _useApplyTheme = useApplyTheme({
1576
+ onSuccess: function onSuccess(_ref2) {
1577
+ var theme = _ref2.theme;
1578
+ setTheme(theme);
1579
+ highlightTheme(theme);
1580
+ setThemeState({
1581
+ previewingTheme: theme
1582
+ });
1583
+ setThemeBeingApplied({});
1584
+ setCurrentScreen(DESIGN_SCREENS.THEMES);
1585
+ onApplyThemeSuccess === null || onApplyThemeSuccess === void 0 || onApplyThemeSuccess(theme);
1586
+ }
1587
+ }),
1588
+ applyTheme = _useApplyTheme.mutate,
1589
+ isApplyingTheme = _useApplyTheme.isPending;
1590
+ var themeToDelete = useRef(null);
1591
+ var themeToEdit = useRef(null);
1592
+ var handleEditTheme = function handleEditTheme(theme) {
1593
+ themeToEdit.current = theme;
1594
+ setCurrentScreen(DESIGN_SCREENS.Customize);
1595
+ };
1596
+ var onApplyTheme = function onApplyTheme(theme) {
1597
+ if (isApplyingTheme) return;
1598
+ setThemeBeingApplied(theme);
1599
+ applyTheme({
1600
+ themeId: theme.id,
1601
+ entityId: entityId,
1602
+ entityType: entityType
1603
+ });
1604
+ };
1605
+ var handleBackPress = function handleBackPress(theme) {
1606
+ setTheme(currentTheme);
1607
+ highlightTheme(isPresent(theme) ? theme : currentTheme);
1608
+ setThemeState({
1609
+ previewingTheme: currentTheme
1610
+ });
1611
+ setCurrentScreen(DESIGN_SCREENS.THEMES);
1612
+ themeToEdit.current = null;
1613
+ };
1614
+ var highlightTheme = function highlightTheme(themeToHighlight) {
1615
+ setTimeout(function () {
1616
+ scrollElementIntoView(themeToHighlight.id);
1617
+ }, 1500);
1618
+ setTimeout(function () {
1619
+ setThemeToHighlight(null);
1620
+ }, 4000);
1621
+ setThemeToHighlight(themeToHighlight.id);
1622
+ };
1623
+ var onCreateTheme = function onCreateTheme(createdTheme) {
1624
+ themeToEdit.current = createdTheme;
1625
+ setTheme(createdTheme);
1626
+ setThemeState({
1627
+ previewingTheme: createdTheme
1628
+ });
1629
+ };
1630
+ var handleDelete = function handleDelete(themeId, name, appliedCount) {
1631
+ setIsDeleteAlertOpen(true);
1632
+ themeToDelete.current = {
1633
+ id: themeId,
1634
+ name: name,
1635
+ appliedCount: appliedCount
1636
+ };
1637
+ };
1638
+ var handleCloseDeleteAlert = useCallback(function () {
1639
+ setIsDeleteAlertOpen(false);
1640
+ themeToDelete.current = null;
1641
+ }, [themeToDelete]);
1642
+ var handleDeleteTheme = useCallback(function () {
1643
+ var _themeToDelete$curren;
1644
+ deleteTheme((_themeToDelete$curren = themeToDelete.current) === null || _themeToDelete$curren === void 0 ? void 0 : _themeToDelete$curren.id, {
1645
+ onSuccess: function onSuccess() {
1646
+ setIsDeleteAlertOpen(false);
1647
+ themeToDelete.current = null;
1648
+ }
1649
+ });
1650
+ }, [deleteTheme, themeToDelete]);
1651
+ return /*#__PURE__*/jsxs("div", {
1652
+ className: "neeto-themes-sidebar neeto-ui-border-gray-200 flex-shrink-0 border-r",
1653
+ children: [/*#__PURE__*/jsx(TitleBar, {
1654
+ currentScreen: currentScreen,
1655
+ handleBackPress: handleBackPress,
1656
+ handleCreateNewTheme: function handleCreateNewTheme() {
1657
+ return handleEditTheme({});
1658
+ },
1659
+ isNewTheme: !((_themeToEdit$current = themeToEdit.current) !== null && _themeToEdit$current !== void 0 && _themeToEdit$current.id),
1660
+ themeToEdit: themeToEdit.current
1661
+ }), currentScreen === DESIGN_SCREENS.THEMES ? /*#__PURE__*/jsx(Themes, {
1662
+ currentTheme: currentTheme,
1663
+ defaultThemes: defaultThemes,
1664
+ didScrollActiveThemeIntoView: didScrollActiveThemeIntoView,
1665
+ highlightTheme: highlightTheme,
1666
+ isApplyingTheme: isApplyingTheme,
1667
+ isCurrentThemeLoading: isCurrentThemeLoading,
1668
+ onApplyTheme: onApplyTheme,
1669
+ themeBeingApplied: themeBeingApplied,
1670
+ themeToHighlight: themeToHighlight,
1671
+ themes: themes,
1672
+ thumbnail: thumbnail,
1673
+ isLoading: isLoading || isFetchingSchema,
1674
+ onDeleteTheme: handleDelete,
1675
+ onEditTheme: handleEditTheme
1676
+ }) : /*#__PURE__*/jsx(Customize, {
1677
+ isApplyingTheme: isApplyingTheme,
1678
+ onApplyTheme: onApplyTheme,
1679
+ onCreateTheme: onCreateTheme,
1680
+ onPropertiesChange: onPropertiesChange,
1681
+ onUpdateThemeSuccess: onUpdateThemeSuccess,
1682
+ theme: themeToEdit.current,
1683
+ themeId: (_themeToEdit$current2 = themeToEdit.current) === null || _themeToEdit$current2 === void 0 ? void 0 : _themeToEdit$current2.id
1684
+ }), /*#__PURE__*/jsx(MemoizedAlert, {
1685
+ isOpen: isDeleteAlertOpen,
1686
+ isSubmitting: isDeleting,
1687
+ title: t("neetoThemes.alerts.title.deleteTheme"),
1688
+ message: t("neetoThemes.alerts.message.deleteTheme", {
1689
+ name: (_themeToDelete$curren2 = themeToDelete.current) === null || _themeToDelete$curren2 === void 0 ? void 0 : _themeToDelete$curren2.name,
1690
+ count: (_themeToDelete$curren3 = themeToDelete.current) === null || _themeToDelete$curren3 === void 0 ? void 0 : _themeToDelete$curren3.appliedCount,
1691
+ defaultThemeName: defaultThemeName,
1692
+ entityType: t("neetoThemes.entityType.".concat(entityType.toLowerCase()), {
1693
+ count: (_themeToDelete$curren4 = themeToDelete.current) === null || _themeToDelete$curren4 === void 0 ? void 0 : _themeToDelete$curren4.appliedCount
1694
+ })
1695
+ }),
1696
+ onClose: handleCloseDeleteAlert,
1697
+ onSubmit: handleDeleteTheme
1698
+ })]
1699
+ });
1700
+ };
1701
+
1702
+ var NeetoThemesBuilder = function NeetoThemesBuilder(_ref) {
1703
+ var children = _ref.children,
1704
+ entityType = _ref.entityType,
1705
+ entityId = _ref.entityId,
1706
+ thumbnail = _ref.thumbnail,
1707
+ onPropertiesChange = _ref.onPropertiesChange,
1708
+ _ref$isTemplateThemes = _ref.isTemplateThemesEnabled,
1709
+ isTemplateThemesEnabled = _ref$isTemplateThemes === void 0 ? false : _ref$isTemplateThemes,
1710
+ _ref$onApplyThemeSucc = _ref.onApplyThemeSuccess,
1711
+ onApplyThemeSuccess = _ref$onApplyThemeSucc === void 0 ? noop : _ref$onApplyThemeSucc,
1712
+ _ref$onUpdateThemeSuc = _ref.onUpdateThemeSuccess,
1713
+ onUpdateThemeSuccess = _ref$onUpdateThemeSuc === void 0 ? noop : _ref$onUpdateThemeSuc;
1714
+ var _useThemeStore = useThemeStore(function (store) {
1715
+ return {
1716
+ setThemeState: store["setThemeState"]
1717
+ };
1718
+ }, shallow),
1719
+ setThemeState = _useThemeStore.setThemeState;
1720
+ var _useThemeUtils = useThemeUtils(),
1721
+ setTheme = _useThemeUtils.setTheme;
1722
+ var _useConfigStore = useConfigStore(function (store) {
1723
+ return {
1724
+ setConfigState: store["setConfigState"]
1725
+ };
1726
+ }, shallow),
1727
+ setConfigState = _useConfigStore.setConfigState;
1728
+ var _useShowThemeEntity = useShowThemeEntity(entityId),
1729
+ _useShowThemeEntity$d = _useShowThemeEntity.data,
1730
+ _useShowThemeEntity$d2 = _useShowThemeEntity$d === void 0 ? {} : _useShowThemeEntity$d,
1731
+ _useShowThemeEntity$d3 = _useShowThemeEntity$d2.theme,
1732
+ currentTheme = _useShowThemeEntity$d3 === void 0 ? {} : _useShowThemeEntity$d3,
1733
+ isLoading = _useShowThemeEntity.isLoading,
1734
+ isFetchingCurrentTheme = _useShowThemeEntity.isFetching;
1735
+ var isCurrentThemeLoading = isLoading || isFetchingCurrentTheme;
1736
+ useEffect(function () {
1737
+ setConfigState({
1738
+ entityType: entityType,
1739
+ entityId: entityId,
1740
+ isTemplateThemesEnabled: isTemplateThemesEnabled
1741
+ });
1742
+ }, []);
1743
+ useEffect(function () {
1744
+ if (isNotPresent(currentTheme)) return;
1745
+ setThemeState({
1746
+ previewingTheme: currentTheme
1747
+ });
1748
+ setTheme(currentTheme);
1749
+ }, [isLoading, entityId]);
1750
+ useEffect(function () {
1751
+ if (isNotPresent(currentTheme)) return;
1752
+ setThemeState({
1753
+ currentTheme: currentTheme,
1754
+ isCurrentThemeLoading: isCurrentThemeLoading
1755
+ });
1756
+ }, [currentTheme, isCurrentThemeLoading]);
1757
+ return /*#__PURE__*/jsxs("div", {
1758
+ className: "neeto-themes__wrapper",
1759
+ children: [/*#__PURE__*/jsx(Sidebar, {
1760
+ onApplyThemeSuccess: onApplyThemeSuccess,
1761
+ onPropertiesChange: onPropertiesChange,
1762
+ onUpdateThemeSuccess: onUpdateThemeSuccess,
1763
+ thumbnail: thumbnail
1764
+ }), /*#__PURE__*/jsx("div", {
1765
+ className: "neeto-themes-preview__wrapper",
1766
+ children: isCurrentThemeLoading ? /*#__PURE__*/jsx("div", {
1767
+ className: "m-auto flex h-full w-full items-center justify-center",
1768
+ children: /*#__PURE__*/jsx(Spinner, {})
1769
+ }) : children
1770
+ })]
1771
+ });
1772
+ };
1773
+ var index = withTitle(NeetoThemesBuilder, t$1("neetoThemes.common.design"));
1774
+
1775
+ export { index as default };
1776
+ //# sourceMappingURL=NeetoThemesBuilder.js.map