@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.cjs.js CHANGED
@@ -5,20 +5,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var shallow = require('zustand/shallow');
6
6
  var react = require('react');
7
7
  var i18next = require('i18next');
8
+ var neetoCist = require('@bigbinary/neeto-cist');
8
9
  var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
9
10
  var Spinner = require('@bigbinary/neetoui/Spinner');
11
+ var reactQuery = require('@tanstack/react-query');
12
+ var axios = require('axios');
13
+ var ramda = require('ramda');
10
14
  var zustand = require('zustand');
11
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
12
- var neetoCist = require('@bigbinary/neeto-cist');
13
- var Alert = require('@bigbinary/neetoui/Alert');
14
- var reactI18next = require('react-i18next');
15
15
  var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
16
16
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
17
17
  var Toastr = require('@bigbinary/neetoui/Toastr');
18
- var reactQuery = require('@tanstack/react-query');
19
- var axios = require('axios');
18
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
19
+ var Alert = require('@bigbinary/neetoui/Alert');
20
+ var reactI18next = require('react-i18next');
20
21
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
21
- var ramda = require('ramda');
22
22
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
23
23
  var Close = require('@bigbinary/neeto-icons/Close');
24
24
  var Button = require('@bigbinary/neetoui/Button');
@@ -65,12 +65,12 @@ function _interopNamespace(e) {
65
65
  }
66
66
 
67
67
  var Spinner__default = /*#__PURE__*/_interopDefaultLegacy(Spinner);
68
- var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
69
- var Alert__default = /*#__PURE__*/_interopDefaultLegacy(Alert);
68
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
70
69
  var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
71
70
  var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
72
71
  var Toastr__default = /*#__PURE__*/_interopDefaultLegacy(Toastr);
73
- var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
72
+ var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
73
+ var Alert__default = /*#__PURE__*/_interopDefaultLegacy(Alert);
74
74
  var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
75
75
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
76
76
  var Close__default = /*#__PURE__*/_interopDefaultLegacy(Close);
@@ -92,6 +92,33 @@ var MoreDropdown__default = /*#__PURE__*/_interopDefaultLegacy(MoreDropdown);
92
92
  var LeftArrow__default = /*#__PURE__*/_interopDefaultLegacy(LeftArrow);
93
93
  var Plus__default = /*#__PURE__*/_interopDefaultLegacy(Plus);
94
94
 
95
+ var BASE_URL = "neeto_themes_engine";
96
+ var WHITE = "255, 255, 255";
97
+ var BLACK = "0, 0, 0";
98
+
99
+ var show$1 = function show(entityId) {
100
+ return axios__default["default"].get("".concat(BASE_URL, "/api/v1/entities/").concat(entityId));
101
+ };
102
+ var entitiesApi = {
103
+ show: show$1
104
+ };
105
+
106
+ var QUERY_KEYS = {
107
+ THEMES_LIST: "themes-list",
108
+ THEME_DETAILS: "theme-details",
109
+ SCHEMA_DETAILS: "schema-details"
110
+ };
111
+
112
+ var useShowThemeEntity = function useShowThemeEntity(entityId) {
113
+ return reactQuery.useQuery({
114
+ queryKey: [QUERY_KEYS.THEME_ENTITY_DETAILS, entityId],
115
+ queryFn: function queryFn() {
116
+ return entitiesApi.show(entityId);
117
+ },
118
+ enabled: !!entityId
119
+ });
120
+ };
121
+
95
122
  /** @type {import("neetocommons/react-utils").ZustandStoreHook} */
96
123
  var useConfigStore = zustand.create(reactUtils.withImmutableActions(function (set) {
97
124
  return {
@@ -181,35 +208,101 @@ var hexToRgba = function hexToRgba(hex) {
181
208
  return "".concat(r, ", ").concat(g, ", ").concat(b).concat(a !== undefined ? ", ".concat(a) : "");
182
209
  };
183
210
 
184
- var BASE_URL = "neeto_themes_engine";
185
- var WHITE = "255, 255, 255";
186
- var BLACK = "0, 0, 0";
187
-
188
- var show$1 = function show(entityId) {
189
- return axios__default["default"].get("".concat(BASE_URL, "/api/v1/entities/").concat(entityId));
211
+ var root = document.querySelector(":root");
212
+ var setVariable = function setVariable(name, value, variableNamesMap) {
213
+ var variableName = variableNamesMap[name];
214
+ if (!variableName) return;
215
+ root.style.setProperty(variableName, value);
190
216
  };
191
- var entitiesApi = {
192
- show: show$1
217
+ var setTheme = function setTheme(theme, variableNamesMap, themeConfig) {
218
+ if (neetoCist.isNotPresent(theme === null || theme === void 0 ? void 0 : theme.properties)) return;
219
+ theme.properties.forEach(function (property) {
220
+ var attribute = neetoCist.snakeToCamelCase(property.key);
221
+ if (property.kind === "color") {
222
+ setVariable(attribute, hexToRgba(property.value), variableNamesMap);
223
+ } else if (property.kind === "overlay_opacity") {
224
+ var overlayOpacity = Number(property.value);
225
+ setVariable(neetoCist.snakeToCamelCase("".concat(property.key, "_overlay_opacity")), Math.abs(overlayOpacity / 100), variableNamesMap);
226
+ setVariable(neetoCist.snakeToCamelCase("".concat(property.key, "_overlay_color")), overlayOpacity < 0 ? BLACK : WHITE, variableNamesMap);
227
+ } else if (property.kind === "radius") {
228
+ setVariable(attribute, "".concat(property.value, "px"), variableNamesMap);
229
+ } else {
230
+ setVariable(attribute, property.value, variableNamesMap);
231
+ }
232
+ });
233
+ neetoCist.filterBy({
234
+ kind: "image"
235
+ }, themeConfig).forEach(function (_ref) {
236
+ var _theme$attribute;
237
+ var key = _ref.key;
238
+ var attribute = neetoCist.snakeToCamelCase(key);
239
+ setVariable(attribute, "url(".concat((_theme$attribute = theme[attribute]) === null || _theme$attribute === void 0 ? void 0 : _theme$attribute.url, ")"), variableNamesMap);
240
+ });
193
241
  };
194
242
 
195
- var QUERY_KEYS = {
196
- THEMES_LIST: "themes-list",
197
- THEME_DETAILS: "theme-details",
198
- SCHEMA_DETAILS: "schema-details"
243
+ var list$1 = function list() {
244
+ return axios__default["default"].get("".concat(BASE_URL, "/api/v1/schema"));
245
+ };
246
+ var schemasApi = {
247
+ list: list$1
199
248
  };
200
249
 
201
- var useShowThemeEntity = function useShowThemeEntity(entityId) {
250
+ var useListSchema = function useListSchema() {
202
251
  return reactQuery.useQuery({
203
- queryKey: [QUERY_KEYS.THEME_ENTITY_DETAILS, entityId],
204
- queryFn: function queryFn() {
205
- return entitiesApi.show(entityId);
206
- },
207
- enabled: !!entityId
252
+ queryKey: [QUERY_KEYS.SCHEMA_DETAILS],
253
+ queryFn: schemasApi.list
208
254
  });
209
255
  };
210
256
 
257
+ var useThemeUtils = function useThemeUtils() {
258
+ var setConfigState = useConfigStore(ramda.prop("setConfigState"));
259
+ var _useThemeStore = useThemeStore(function (store) {
260
+ return {
261
+ previewingTheme: store["previewingTheme"],
262
+ currentTheme: store["currentTheme"]
263
+ };
264
+ }, shallow.shallow),
265
+ previewingTheme = _useThemeStore.previewingTheme,
266
+ currentTheme = _useThemeStore.currentTheme;
267
+ var _useListSchema = useListSchema(),
268
+ isFetchingSchema = _useListSchema.isLoading,
269
+ data = _useListSchema.data;
270
+ var _ref = data || {},
271
+ _ref$schema = _ref.schema,
272
+ themePropertiesSchema = _ref$schema === void 0 ? [] : _ref$schema,
273
+ _ref$variableNamesMap = _ref.variableNamesMap,
274
+ variableNamesMap = _ref$variableNamesMap === void 0 ? {} : _ref$variableNamesMap;
275
+ react.useEffect(function () {
276
+ if (data) {
277
+ setConfigState({
278
+ themePropertiesSchema: data === null || data === void 0 ? void 0 : data.schema,
279
+ variableNamesMap: data === null || data === void 0 ? void 0 : data.variableNamesMap,
280
+ defaultThemeName: data === null || data === void 0 ? void 0 : data.defaultThemeName
281
+ });
282
+ }
283
+ }, [data]);
284
+ react.useEffect(function () {
285
+ return setConfigState({
286
+ isFetchingSchema: isFetchingSchema
287
+ });
288
+ }, [isFetchingSchema]);
289
+ var setVariable$1 = function setVariable$1(name, value) {
290
+ return setVariable(name, value, variableNamesMap);
291
+ };
292
+ var setTheme$1 = function setTheme$1(theme) {
293
+ return setTheme(theme, variableNamesMap, themePropertiesSchema);
294
+ };
295
+ return {
296
+ setTheme: setTheme$1,
297
+ setVariable: setVariable$1,
298
+ previewingTheme: previewingTheme,
299
+ currentTheme: currentTheme,
300
+ isFetchingSchema: isFetchingSchema
301
+ };
302
+ };
303
+
211
304
  var _excluded$1 = ["themeId"];
212
- var list$1 = function list(entityId) {
305
+ var list = function list(entityId) {
213
306
  return axios__default["default"].get("".concat(BASE_URL, "/api/v1/themes"), {
214
307
  params: {
215
308
  entity_id: entityId
@@ -245,7 +338,7 @@ var apply = function apply(_ref2) {
245
338
  });
246
339
  };
247
340
  var themesApi = {
248
- list: list$1,
341
+ list: list,
249
342
  show: show,
250
343
  create: create,
251
344
  update: update,
@@ -302,99 +395,6 @@ var useApplyTheme = function useApplyTheme(_ref) {
302
395
  });
303
396
  };
304
397
 
305
- var root = document.querySelector(":root");
306
- var setVariable = function setVariable(name, value, variableNamesMap) {
307
- var variableName = variableNamesMap[name];
308
- if (!variableName) return;
309
- root.style.setProperty(variableName, value);
310
- };
311
- var setTheme = function setTheme(theme, variableNamesMap, themeConfig) {
312
- if (neetoCist.isNotPresent(theme === null || theme === void 0 ? void 0 : theme.properties)) return;
313
- theme.properties.forEach(function (property) {
314
- var attribute = neetoCist.snakeToCamelCase(property.key);
315
- if (property.kind === "color") {
316
- setVariable(attribute, hexToRgba(property.value), variableNamesMap);
317
- } else if (property.kind === "overlay_opacity") {
318
- var overlayOpacity = Number(property.value);
319
- setVariable(neetoCist.snakeToCamelCase("".concat(property.key, "_overlay_opacity")), Math.abs(overlayOpacity / 100), variableNamesMap);
320
- setVariable(neetoCist.snakeToCamelCase("".concat(property.key, "_overlay_color")), overlayOpacity < 0 ? BLACK : WHITE, variableNamesMap);
321
- } else if (property.kind === "radius") {
322
- setVariable(attribute, "".concat(property.value, "px"), variableNamesMap);
323
- } else {
324
- setVariable(attribute, property.value, variableNamesMap);
325
- }
326
- });
327
- neetoCist.filterBy({
328
- kind: "image"
329
- }, themeConfig).forEach(function (_ref) {
330
- var _theme$attribute;
331
- var key = _ref.key;
332
- var attribute = neetoCist.snakeToCamelCase(key);
333
- setVariable(attribute, "url(".concat((_theme$attribute = theme[attribute]) === null || _theme$attribute === void 0 ? void 0 : _theme$attribute.url, ")"), variableNamesMap);
334
- });
335
- };
336
-
337
- var list = function list() {
338
- return axios__default["default"].get("".concat(BASE_URL, "/api/v1/schema"));
339
- };
340
- var schemasApi = {
341
- list: list
342
- };
343
-
344
- var useListSchema = function useListSchema() {
345
- return reactQuery.useQuery({
346
- queryKey: [QUERY_KEYS.SCHEMA_DETAILS],
347
- queryFn: schemasApi.list
348
- });
349
- };
350
-
351
- var useThemeUtils = function useThemeUtils() {
352
- var setConfigState = useConfigStore(ramda.prop("setConfigState"));
353
- var _useThemeStore = useThemeStore(function (store) {
354
- return {
355
- previewingTheme: store["previewingTheme"],
356
- currentTheme: store["currentTheme"]
357
- };
358
- }, shallow.shallow),
359
- previewingTheme = _useThemeStore.previewingTheme,
360
- currentTheme = _useThemeStore.currentTheme;
361
- var _useListSchema = useListSchema(),
362
- isFetchingSchema = _useListSchema.isLoading,
363
- data = _useListSchema.data;
364
- var _ref = data || {},
365
- _ref$schema = _ref.schema,
366
- themePropertiesSchema = _ref$schema === void 0 ? [] : _ref$schema,
367
- _ref$variableNamesMap = _ref.variableNamesMap,
368
- variableNamesMap = _ref$variableNamesMap === void 0 ? {} : _ref$variableNamesMap;
369
- react.useEffect(function () {
370
- if (data) {
371
- setConfigState({
372
- themePropertiesSchema: data === null || data === void 0 ? void 0 : data.schema,
373
- variableNamesMap: data === null || data === void 0 ? void 0 : data.variableNamesMap,
374
- defaultThemeName: data === null || data === void 0 ? void 0 : data.defaultThemeName
375
- });
376
- }
377
- }, [data]);
378
- react.useEffect(function () {
379
- return setConfigState({
380
- isFetchingSchema: isFetchingSchema
381
- });
382
- }, [isFetchingSchema]);
383
- var setVariable$1 = function setVariable$1(name, value) {
384
- return setVariable(name, value, variableNamesMap);
385
- };
386
- var setTheme$1 = function setTheme$1(theme) {
387
- return setTheme(theme, variableNamesMap, themePropertiesSchema);
388
- };
389
- return {
390
- setTheme: setTheme$1,
391
- setVariable: setVariable$1,
392
- previewingTheme: previewingTheme,
393
- currentTheme: currentTheme,
394
- isFetchingSchema: isFetchingSchema
395
- };
396
- };
397
-
398
398
  var POSITION_OPTIONS = [{
399
399
  label: "Left",
400
400
  value: "left"
@@ -722,9 +722,9 @@ var ImageBlock = function ImageBlock(_ref) {
722
722
  label: buildLabel("".concat(name, "Position"), "image"),
723
723
  options: options || POSITION_OPTIONS,
724
724
  placeholder: t("neetoThemes.common.left"),
725
- value: neetoCist.toLabelAndValue((_findBy = neetoCist.findBy({
725
+ value: neetoCist.toLabelAndValue(((_findBy = neetoCist.findBy({
726
726
  key: "".concat(name, "_position")
727
- }, values.properties)) === null || _findBy === void 0 ? void 0 : _findBy.value),
727
+ }, values.properties)) === null || _findBy === void 0 ? void 0 : _findBy.value) || (positionKeyInSchema === null || positionKeyInSchema === void 0 ? void 0 : positionKeyInSchema.defaultValue)),
728
728
  onChange: function onChange(option) {
729
729
  return setFieldValue("properties[".concat(positionKeyIndex, "].value"), option.value);
730
730
  }
@@ -1523,7 +1523,10 @@ var Card = function Card(_ref) {
1523
1523
  "data-cy": "delete-theme-menu-item",
1524
1524
  label: t("neetoThemes.build.leftSideBar.themes.themeOptions.delete"),
1525
1525
  isVisible: isFunction(onDeleteTheme),
1526
- onClick: handleDeleteTheme
1526
+ onClick: function onClick(e) {
1527
+ e.stopPropagation();
1528
+ handleDeleteTheme();
1529
+ }
1527
1530
  }]
1528
1531
  })]
1529
1532
  })]
@@ -1808,7 +1811,7 @@ var Sidebar = function Sidebar(_ref) {
1808
1811
  }
1809
1812
  }),
1810
1813
  applyTheme = _useApplyTheme.mutate,
1811
- isApplyingTheme = _useApplyTheme.isLoading;
1814
+ isApplyingTheme = _useApplyTheme.isPending;
1812
1815
  var themeToDelete = react.useRef(null);
1813
1816
  var themeToEdit = react.useRef(null);
1814
1817
  var handleEditTheme = function handleEditTheme(theme) {
@@ -1836,10 +1839,10 @@ var Sidebar = function Sidebar(_ref) {
1836
1839
  var highlightTheme = function highlightTheme(themeToHighlight) {
1837
1840
  setTimeout(function () {
1838
1841
  scrollElementIntoView(themeToHighlight.id);
1839
- }, 1000);
1842
+ }, 1500);
1840
1843
  setTimeout(function () {
1841
1844
  setThemeToHighlight(null);
1842
- }, 3500);
1845
+ }, 4000);
1843
1846
  setThemeToHighlight(themeToHighlight.id);
1844
1847
  };
1845
1848
  var onCreateTheme = function onCreateTheme(createdTheme) {
@@ -1870,18 +1873,6 @@ var Sidebar = function Sidebar(_ref) {
1870
1873
  }
1871
1874
  });
1872
1875
  }, [deleteTheme, themeToDelete]);
1873
- react.useEffect(function () {
1874
- if (neetoCist.isNotPresent(currentTheme)) return;
1875
- setTheme(currentTheme);
1876
- }, [currentTheme, entityId]);
1877
- react.useEffect(function () {
1878
- if (neetoCist.isNotPresent(currentTheme)) return;
1879
- setThemeState({
1880
- currentTheme: currentTheme,
1881
- isCurrentThemeLoading: isCurrentThemeLoading,
1882
- previewingTheme: currentTheme
1883
- });
1884
- }, [currentTheme, isCurrentThemeLoading]);
1885
1876
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
1886
1877
  className: "neeto-themes-sidebar neeto-ui-border-gray-200 flex-shrink-0 border-r",
1887
1878
  children: [/*#__PURE__*/jsxRuntime.jsx(TitleBar, {
@@ -1942,16 +1933,26 @@ var NeetoThemesBuilder = function NeetoThemesBuilder(_ref) {
1942
1933
  isTemplateThemesEnabled = _ref$isTemplateThemes === void 0 ? false : _ref$isTemplateThemes;
1943
1934
  var _useThemeStore = useThemeStore(function (store) {
1944
1935
  return {
1945
- isCurrentThemeLoading: store["isCurrentThemeLoading"]
1936
+ setThemeState: store["setThemeState"]
1946
1937
  };
1947
1938
  }, shallow.shallow),
1948
- isCurrentThemeLoading = _useThemeStore.isCurrentThemeLoading;
1939
+ setThemeState = _useThemeStore.setThemeState;
1940
+ var _useThemeUtils = useThemeUtils(),
1941
+ setTheme = _useThemeUtils.setTheme;
1949
1942
  var _useConfigStore = useConfigStore(function (store) {
1950
1943
  return {
1951
1944
  setConfigState: store["setConfigState"]
1952
1945
  };
1953
1946
  }, shallow.shallow),
1954
1947
  setConfigState = _useConfigStore.setConfigState;
1948
+ var _useShowThemeEntity = useShowThemeEntity(entityId),
1949
+ _useShowThemeEntity$d = _useShowThemeEntity.data,
1950
+ _useShowThemeEntity$d2 = _useShowThemeEntity$d === void 0 ? {} : _useShowThemeEntity$d,
1951
+ _useShowThemeEntity$d3 = _useShowThemeEntity$d2.theme,
1952
+ currentTheme = _useShowThemeEntity$d3 === void 0 ? {} : _useShowThemeEntity$d3,
1953
+ isLoading = _useShowThemeEntity.isLoading,
1954
+ isFetchingCurrentTheme = _useShowThemeEntity.isFetching;
1955
+ var isCurrentThemeLoading = isLoading || isFetchingCurrentTheme;
1955
1956
  react.useEffect(function () {
1956
1957
  setConfigState({
1957
1958
  entityType: entityType,
@@ -1959,6 +1960,18 @@ var NeetoThemesBuilder = function NeetoThemesBuilder(_ref) {
1959
1960
  isTemplateThemesEnabled: isTemplateThemesEnabled
1960
1961
  });
1961
1962
  }, []);
1963
+ react.useEffect(function () {
1964
+ if (neetoCist.isNotPresent(currentTheme)) return;
1965
+ setThemeState({
1966
+ currentTheme: currentTheme,
1967
+ isCurrentThemeLoading: isCurrentThemeLoading,
1968
+ previewingTheme: currentTheme
1969
+ });
1970
+ }, [currentTheme, isCurrentThemeLoading]);
1971
+ react.useEffect(function () {
1972
+ if (neetoCist.isNotPresent(currentTheme)) return;
1973
+ setTheme(currentTheme);
1974
+ }, [currentTheme, entityId]);
1962
1975
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
1963
1976
  className: "neeto-themes__wrapper",
1964
1977
  children: [/*#__PURE__*/jsxRuntime.jsx(Sidebar, {