@bigbinary/neeto-themes-frontend 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import { shallow } from 'zustand/shallow';
2
2
  import { useEffect, createElement, useState, useRef, memo, useCallback } from 'react';
3
3
  import { t as t$1 } from 'i18next';
4
+ import { isNotPresent, snakeToCamelCase, filterBy, isPresent, isNot, findBy, findIndexBy, toLabelAndValue, humanize, isNotEmpty } from '@bigbinary/neeto-cist';
4
5
  import { withImmutableActions, useMutationWithInvalidation, withT, withTitle } from '@bigbinary/neeto-commons-frontend/react-utils';
5
6
  import Spinner from '@bigbinary/neetoui/Spinner';
7
+ import { useQuery } from '@tanstack/react-query';
8
+ import axios from 'axios';
9
+ import { prop, isEmpty, negate } from 'ramda';
6
10
  import { create as create$1 } from 'zustand';
7
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
8
- import { isNotPresent, snakeToCamelCase, filterBy, isPresent, isNot, findBy, findIndexBy, toLabelAndValue, humanize, isNotEmpty } from '@bigbinary/neeto-cist';
9
- import Alert from '@bigbinary/neetoui/Alert';
10
- import { useTranslation, Trans } from 'react-i18next';
11
11
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
12
12
  import _regeneratorRuntime from '@babel/runtime/regenerator';
13
13
  import Toastr from '@bigbinary/neetoui/Toastr';
14
- import { useQuery } from '@tanstack/react-query';
15
- import axios from 'axios';
14
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
15
+ import Alert from '@bigbinary/neetoui/Alert';
16
+ import { useTranslation, Trans } from 'react-i18next';
16
17
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
17
- import { prop, isEmpty, negate } from 'ramda';
18
18
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
19
19
  import Close from '@bigbinary/neeto-icons/Close';
20
20
  import Button from '@bigbinary/neetoui/Button';
@@ -40,6 +40,33 @@ import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
40
40
  import LeftArrow from '@bigbinary/neeto-icons/LeftArrow';
41
41
  import Plus from '@bigbinary/neeto-icons/Plus';
42
42
 
43
+ var BASE_URL = "neeto_themes_engine";
44
+ var WHITE = "255, 255, 255";
45
+ var BLACK = "0, 0, 0";
46
+
47
+ var show$1 = function show(entityId) {
48
+ return axios.get("".concat(BASE_URL, "/api/v1/entities/").concat(entityId));
49
+ };
50
+ var entitiesApi = {
51
+ show: show$1
52
+ };
53
+
54
+ var QUERY_KEYS = {
55
+ THEMES_LIST: "themes-list",
56
+ THEME_DETAILS: "theme-details",
57
+ SCHEMA_DETAILS: "schema-details"
58
+ };
59
+
60
+ var useShowThemeEntity = function useShowThemeEntity(entityId) {
61
+ return useQuery({
62
+ queryKey: [QUERY_KEYS.THEME_ENTITY_DETAILS, entityId],
63
+ queryFn: function queryFn() {
64
+ return entitiesApi.show(entityId);
65
+ },
66
+ enabled: !!entityId
67
+ });
68
+ };
69
+
43
70
  /** @type {import("neetocommons/react-utils").ZustandStoreHook} */
44
71
  var useConfigStore = create$1(withImmutableActions(function (set) {
45
72
  return {
@@ -129,35 +156,101 @@ var hexToRgba = function hexToRgba(hex) {
129
156
  return "".concat(r, ", ").concat(g, ", ").concat(b).concat(a !== undefined ? ", ".concat(a) : "");
130
157
  };
131
158
 
132
- var BASE_URL = "neeto_themes_engine";
133
- var WHITE = "255, 255, 255";
134
- var BLACK = "0, 0, 0";
135
-
136
- var show$1 = function show(entityId) {
137
- return axios.get("".concat(BASE_URL, "/api/v1/entities/").concat(entityId));
159
+ var root = document.querySelector(":root");
160
+ var setVariable = function setVariable(name, value, variableNamesMap) {
161
+ var variableName = variableNamesMap[name];
162
+ if (!variableName) return;
163
+ root.style.setProperty(variableName, value);
138
164
  };
139
- var entitiesApi = {
140
- show: show$1
165
+ var setTheme = function setTheme(theme, variableNamesMap, themeConfig) {
166
+ if (isNotPresent(theme === null || theme === void 0 ? void 0 : theme.properties)) return;
167
+ theme.properties.forEach(function (property) {
168
+ var attribute = snakeToCamelCase(property.key);
169
+ if (property.kind === "color") {
170
+ setVariable(attribute, hexToRgba(property.value), variableNamesMap);
171
+ } else if (property.kind === "overlay_opacity") {
172
+ var overlayOpacity = Number(property.value);
173
+ setVariable(snakeToCamelCase("".concat(property.key, "_overlay_opacity")), Math.abs(overlayOpacity / 100), variableNamesMap);
174
+ setVariable(snakeToCamelCase("".concat(property.key, "_overlay_color")), overlayOpacity < 0 ? BLACK : WHITE, variableNamesMap);
175
+ } else if (property.kind === "radius") {
176
+ setVariable(attribute, "".concat(property.value, "px"), variableNamesMap);
177
+ } else {
178
+ setVariable(attribute, property.value, variableNamesMap);
179
+ }
180
+ });
181
+ filterBy({
182
+ kind: "image"
183
+ }, themeConfig).forEach(function (_ref) {
184
+ var _theme$attribute;
185
+ var key = _ref.key;
186
+ var attribute = snakeToCamelCase(key);
187
+ setVariable(attribute, "url(".concat((_theme$attribute = theme[attribute]) === null || _theme$attribute === void 0 ? void 0 : _theme$attribute.url, ")"), variableNamesMap);
188
+ });
141
189
  };
142
190
 
143
- var QUERY_KEYS = {
144
- THEMES_LIST: "themes-list",
145
- THEME_DETAILS: "theme-details",
146
- SCHEMA_DETAILS: "schema-details"
191
+ var list$1 = function list() {
192
+ return axios.get("".concat(BASE_URL, "/api/v1/schema"));
193
+ };
194
+ var schemasApi = {
195
+ list: list$1
147
196
  };
148
197
 
149
- var useShowThemeEntity = function useShowThemeEntity(entityId) {
198
+ var useListSchema = function useListSchema() {
150
199
  return useQuery({
151
- queryKey: [QUERY_KEYS.THEME_ENTITY_DETAILS, entityId],
152
- queryFn: function queryFn() {
153
- return entitiesApi.show(entityId);
154
- },
155
- enabled: !!entityId
200
+ queryKey: [QUERY_KEYS.SCHEMA_DETAILS],
201
+ queryFn: schemasApi.list
156
202
  });
157
203
  };
158
204
 
205
+ var useThemeUtils = function useThemeUtils() {
206
+ var setConfigState = useConfigStore(prop("setConfigState"));
207
+ var _useThemeStore = useThemeStore(function (store) {
208
+ return {
209
+ previewingTheme: store["previewingTheme"],
210
+ currentTheme: store["currentTheme"]
211
+ };
212
+ }, shallow),
213
+ previewingTheme = _useThemeStore.previewingTheme,
214
+ currentTheme = _useThemeStore.currentTheme;
215
+ var _useListSchema = useListSchema(),
216
+ isFetchingSchema = _useListSchema.isLoading,
217
+ data = _useListSchema.data;
218
+ var _ref = data || {},
219
+ _ref$schema = _ref.schema,
220
+ themePropertiesSchema = _ref$schema === void 0 ? [] : _ref$schema,
221
+ _ref$variableNamesMap = _ref.variableNamesMap,
222
+ variableNamesMap = _ref$variableNamesMap === void 0 ? {} : _ref$variableNamesMap;
223
+ useEffect(function () {
224
+ if (data) {
225
+ setConfigState({
226
+ themePropertiesSchema: data === null || data === void 0 ? void 0 : data.schema,
227
+ variableNamesMap: data === null || data === void 0 ? void 0 : data.variableNamesMap,
228
+ defaultThemeName: data === null || data === void 0 ? void 0 : data.defaultThemeName
229
+ });
230
+ }
231
+ }, [data]);
232
+ useEffect(function () {
233
+ return setConfigState({
234
+ isFetchingSchema: isFetchingSchema
235
+ });
236
+ }, [isFetchingSchema]);
237
+ var setVariable$1 = function setVariable$1(name, value) {
238
+ return setVariable(name, value, variableNamesMap);
239
+ };
240
+ var setTheme$1 = function setTheme$1(theme) {
241
+ return setTheme(theme, variableNamesMap, themePropertiesSchema);
242
+ };
243
+ return {
244
+ setTheme: setTheme$1,
245
+ setVariable: setVariable$1,
246
+ previewingTheme: previewingTheme,
247
+ currentTheme: currentTheme,
248
+ isFetchingSchema: isFetchingSchema
249
+ };
250
+ };
251
+
159
252
  var _excluded$1 = ["themeId"];
160
- var list$1 = function list(entityId) {
253
+ var list = function list(entityId) {
161
254
  return axios.get("".concat(BASE_URL, "/api/v1/themes"), {
162
255
  params: {
163
256
  entity_id: entityId
@@ -193,7 +286,7 @@ var apply = function apply(_ref2) {
193
286
  });
194
287
  };
195
288
  var themesApi = {
196
- list: list$1,
289
+ list: list,
197
290
  show: show,
198
291
  create: create,
199
292
  update: update,
@@ -250,99 +343,6 @@ var useApplyTheme = function useApplyTheme(_ref) {
250
343
  });
251
344
  };
252
345
 
253
- var root = document.querySelector(":root");
254
- var setVariable = function setVariable(name, value, variableNamesMap) {
255
- var variableName = variableNamesMap[name];
256
- if (!variableName) return;
257
- root.style.setProperty(variableName, value);
258
- };
259
- var setTheme = function setTheme(theme, variableNamesMap, themeConfig) {
260
- if (isNotPresent(theme === null || theme === void 0 ? void 0 : theme.properties)) return;
261
- theme.properties.forEach(function (property) {
262
- var attribute = snakeToCamelCase(property.key);
263
- if (property.kind === "color") {
264
- setVariable(attribute, hexToRgba(property.value), variableNamesMap);
265
- } else if (property.kind === "overlay_opacity") {
266
- var overlayOpacity = Number(property.value);
267
- setVariable(snakeToCamelCase("".concat(property.key, "_overlay_opacity")), Math.abs(overlayOpacity / 100), variableNamesMap);
268
- setVariable(snakeToCamelCase("".concat(property.key, "_overlay_color")), overlayOpacity < 0 ? BLACK : WHITE, variableNamesMap);
269
- } else if (property.kind === "radius") {
270
- setVariable(attribute, "".concat(property.value, "px"), variableNamesMap);
271
- } else {
272
- setVariable(attribute, property.value, variableNamesMap);
273
- }
274
- });
275
- filterBy({
276
- kind: "image"
277
- }, themeConfig).forEach(function (_ref) {
278
- var _theme$attribute;
279
- var key = _ref.key;
280
- var attribute = snakeToCamelCase(key);
281
- setVariable(attribute, "url(".concat((_theme$attribute = theme[attribute]) === null || _theme$attribute === void 0 ? void 0 : _theme$attribute.url, ")"), variableNamesMap);
282
- });
283
- };
284
-
285
- var list = function list() {
286
- return axios.get("".concat(BASE_URL, "/api/v1/schema"));
287
- };
288
- var schemasApi = {
289
- list: list
290
- };
291
-
292
- var useListSchema = function useListSchema() {
293
- return useQuery({
294
- queryKey: [QUERY_KEYS.SCHEMA_DETAILS],
295
- queryFn: schemasApi.list
296
- });
297
- };
298
-
299
- var useThemeUtils = function useThemeUtils() {
300
- var setConfigState = useConfigStore(prop("setConfigState"));
301
- var _useThemeStore = useThemeStore(function (store) {
302
- return {
303
- previewingTheme: store["previewingTheme"],
304
- currentTheme: store["currentTheme"]
305
- };
306
- }, shallow),
307
- previewingTheme = _useThemeStore.previewingTheme,
308
- currentTheme = _useThemeStore.currentTheme;
309
- var _useListSchema = useListSchema(),
310
- isFetchingSchema = _useListSchema.isLoading,
311
- data = _useListSchema.data;
312
- var _ref = data || {},
313
- _ref$schema = _ref.schema,
314
- themePropertiesSchema = _ref$schema === void 0 ? [] : _ref$schema,
315
- _ref$variableNamesMap = _ref.variableNamesMap,
316
- variableNamesMap = _ref$variableNamesMap === void 0 ? {} : _ref$variableNamesMap;
317
- useEffect(function () {
318
- if (data) {
319
- setConfigState({
320
- themePropertiesSchema: data === null || data === void 0 ? void 0 : data.schema,
321
- variableNamesMap: data === null || data === void 0 ? void 0 : data.variableNamesMap,
322
- defaultThemeName: data === null || data === void 0 ? void 0 : data.defaultThemeName
323
- });
324
- }
325
- }, [data]);
326
- useEffect(function () {
327
- return setConfigState({
328
- isFetchingSchema: isFetchingSchema
329
- });
330
- }, [isFetchingSchema]);
331
- var setVariable$1 = function setVariable$1(name, value) {
332
- return setVariable(name, value, variableNamesMap);
333
- };
334
- var setTheme$1 = function setTheme$1(theme) {
335
- return setTheme(theme, variableNamesMap, themePropertiesSchema);
336
- };
337
- return {
338
- setTheme: setTheme$1,
339
- setVariable: setVariable$1,
340
- previewingTheme: previewingTheme,
341
- currentTheme: currentTheme,
342
- isFetchingSchema: isFetchingSchema
343
- };
344
- };
345
-
346
346
  var POSITION_OPTIONS = [{
347
347
  label: "Left",
348
348
  value: "left"
@@ -670,9 +670,9 @@ var ImageBlock = function ImageBlock(_ref) {
670
670
  label: buildLabel("".concat(name, "Position"), "image"),
671
671
  options: options || POSITION_OPTIONS,
672
672
  placeholder: t("neetoThemes.common.left"),
673
- value: toLabelAndValue((_findBy = findBy({
673
+ value: toLabelAndValue(((_findBy = findBy({
674
674
  key: "".concat(name, "_position")
675
- }, values.properties)) === null || _findBy === void 0 ? void 0 : _findBy.value),
675
+ }, values.properties)) === null || _findBy === void 0 ? void 0 : _findBy.value) || (positionKeyInSchema === null || positionKeyInSchema === void 0 ? void 0 : positionKeyInSchema.defaultValue)),
676
676
  onChange: function onChange(option) {
677
677
  return setFieldValue("properties[".concat(positionKeyIndex, "].value"), option.value);
678
678
  }
@@ -1471,7 +1471,10 @@ var Card = function Card(_ref) {
1471
1471
  "data-cy": "delete-theme-menu-item",
1472
1472
  label: t("neetoThemes.build.leftSideBar.themes.themeOptions.delete"),
1473
1473
  isVisible: isFunction(onDeleteTheme),
1474
- onClick: handleDeleteTheme
1474
+ onClick: function onClick(e) {
1475
+ e.stopPropagation();
1476
+ handleDeleteTheme();
1477
+ }
1475
1478
  }]
1476
1479
  })]
1477
1480
  })]
@@ -1756,7 +1759,7 @@ var Sidebar = function Sidebar(_ref) {
1756
1759
  }
1757
1760
  }),
1758
1761
  applyTheme = _useApplyTheme.mutate,
1759
- isApplyingTheme = _useApplyTheme.isLoading;
1762
+ isApplyingTheme = _useApplyTheme.isPending;
1760
1763
  var themeToDelete = useRef(null);
1761
1764
  var themeToEdit = useRef(null);
1762
1765
  var handleEditTheme = function handleEditTheme(theme) {
@@ -1784,10 +1787,10 @@ var Sidebar = function Sidebar(_ref) {
1784
1787
  var highlightTheme = function highlightTheme(themeToHighlight) {
1785
1788
  setTimeout(function () {
1786
1789
  scrollElementIntoView(themeToHighlight.id);
1787
- }, 1000);
1790
+ }, 1500);
1788
1791
  setTimeout(function () {
1789
1792
  setThemeToHighlight(null);
1790
- }, 3500);
1793
+ }, 4000);
1791
1794
  setThemeToHighlight(themeToHighlight.id);
1792
1795
  };
1793
1796
  var onCreateTheme = function onCreateTheme(createdTheme) {
@@ -1818,18 +1821,6 @@ var Sidebar = function Sidebar(_ref) {
1818
1821
  }
1819
1822
  });
1820
1823
  }, [deleteTheme, themeToDelete]);
1821
- useEffect(function () {
1822
- if (isNotPresent(currentTheme)) return;
1823
- setTheme(currentTheme);
1824
- }, [currentTheme, entityId]);
1825
- useEffect(function () {
1826
- if (isNotPresent(currentTheme)) return;
1827
- setThemeState({
1828
- currentTheme: currentTheme,
1829
- isCurrentThemeLoading: isCurrentThemeLoading,
1830
- previewingTheme: currentTheme
1831
- });
1832
- }, [currentTheme, isCurrentThemeLoading]);
1833
1824
  return /*#__PURE__*/jsxs("div", {
1834
1825
  className: "neeto-themes-sidebar neeto-ui-border-gray-200 flex-shrink-0 border-r",
1835
1826
  children: [/*#__PURE__*/jsx(TitleBar, {
@@ -1890,16 +1881,26 @@ var NeetoThemesBuilder = function NeetoThemesBuilder(_ref) {
1890
1881
  isTemplateThemesEnabled = _ref$isTemplateThemes === void 0 ? false : _ref$isTemplateThemes;
1891
1882
  var _useThemeStore = useThemeStore(function (store) {
1892
1883
  return {
1893
- isCurrentThemeLoading: store["isCurrentThemeLoading"]
1884
+ setThemeState: store["setThemeState"]
1894
1885
  };
1895
1886
  }, shallow),
1896
- isCurrentThemeLoading = _useThemeStore.isCurrentThemeLoading;
1887
+ setThemeState = _useThemeStore.setThemeState;
1888
+ var _useThemeUtils = useThemeUtils(),
1889
+ setTheme = _useThemeUtils.setTheme;
1897
1890
  var _useConfigStore = useConfigStore(function (store) {
1898
1891
  return {
1899
1892
  setConfigState: store["setConfigState"]
1900
1893
  };
1901
1894
  }, shallow),
1902
1895
  setConfigState = _useConfigStore.setConfigState;
1896
+ var _useShowThemeEntity = useShowThemeEntity(entityId),
1897
+ _useShowThemeEntity$d = _useShowThemeEntity.data,
1898
+ _useShowThemeEntity$d2 = _useShowThemeEntity$d === void 0 ? {} : _useShowThemeEntity$d,
1899
+ _useShowThemeEntity$d3 = _useShowThemeEntity$d2.theme,
1900
+ currentTheme = _useShowThemeEntity$d3 === void 0 ? {} : _useShowThemeEntity$d3,
1901
+ isLoading = _useShowThemeEntity.isLoading,
1902
+ isFetchingCurrentTheme = _useShowThemeEntity.isFetching;
1903
+ var isCurrentThemeLoading = isLoading || isFetchingCurrentTheme;
1903
1904
  useEffect(function () {
1904
1905
  setConfigState({
1905
1906
  entityType: entityType,
@@ -1907,6 +1908,18 @@ var NeetoThemesBuilder = function NeetoThemesBuilder(_ref) {
1907
1908
  isTemplateThemesEnabled: isTemplateThemesEnabled
1908
1909
  });
1909
1910
  }, []);
1911
+ useEffect(function () {
1912
+ if (isNotPresent(currentTheme)) return;
1913
+ setThemeState({
1914
+ currentTheme: currentTheme,
1915
+ isCurrentThemeLoading: isCurrentThemeLoading,
1916
+ previewingTheme: currentTheme
1917
+ });
1918
+ }, [currentTheme, isCurrentThemeLoading]);
1919
+ useEffect(function () {
1920
+ if (isNotPresent(currentTheme)) return;
1921
+ setTheme(currentTheme);
1922
+ }, [currentTheme, entityId]);
1910
1923
  return /*#__PURE__*/jsxs("div", {
1911
1924
  className: "neeto-themes__wrapper",
1912
1925
  children: [/*#__PURE__*/jsx(Sidebar, {