@bigbinary/neeto-themes-frontend 2.0.7 → 2.0.9
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 +135 -105
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +136 -106
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/types.d.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
4
|
+
import { isNotPresent, snakeToCamelCase, filterBy, findBy, isPresent, isNot, findIndexBy, toLabelAndValue, humanize, isNotEmpty, noop } from '@bigbinary/neeto-cist';
|
|
5
5
|
import { withImmutableActions, useMutationWithInvalidation, withT, withTitle } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
6
6
|
import Spinner from '@bigbinary/neetoui/Spinner';
|
|
7
7
|
import { useQuery } from '@tanstack/react-query';
|
|
@@ -91,105 +91,6 @@ var useThemeStore = create$1(withImmutableActions(function (set) {
|
|
|
91
91
|
};
|
|
92
92
|
}));
|
|
93
93
|
|
|
94
|
-
var buildInitialValues = function buildInitialValues(theme, themePropertiesSchema) {
|
|
95
|
-
if (isPresent(theme)) return theme;
|
|
96
|
-
return {
|
|
97
|
-
name: t$1("neetoThemes.build.leftSideBar.themes.createTheme.newThemeName"),
|
|
98
|
-
properties: themePropertiesSchema.map(function (_ref) {
|
|
99
|
-
var key = _ref.key,
|
|
100
|
-
kind = _ref.kind,
|
|
101
|
-
defaultValue = _ref.defaultValue;
|
|
102
|
-
switch (kind) {
|
|
103
|
-
case "color":
|
|
104
|
-
return {
|
|
105
|
-
value: defaultValue,
|
|
106
|
-
kind: "color",
|
|
107
|
-
key: key
|
|
108
|
-
};
|
|
109
|
-
case "font_family":
|
|
110
|
-
return {
|
|
111
|
-
value: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
|
|
112
|
-
kind: "font_family",
|
|
113
|
-
key: key
|
|
114
|
-
};
|
|
115
|
-
case "overlay_opacity":
|
|
116
|
-
return {
|
|
117
|
-
value: 0,
|
|
118
|
-
kind: "overlay_opacity",
|
|
119
|
-
key: key
|
|
120
|
-
};
|
|
121
|
-
case "slider":
|
|
122
|
-
return {
|
|
123
|
-
value: 0,
|
|
124
|
-
kind: "slider",
|
|
125
|
-
key: key
|
|
126
|
-
};
|
|
127
|
-
case "radius":
|
|
128
|
-
return {
|
|
129
|
-
value: defaultValue,
|
|
130
|
-
kind: "radius",
|
|
131
|
-
key: key
|
|
132
|
-
};
|
|
133
|
-
case "boolean":
|
|
134
|
-
return {
|
|
135
|
-
value: String(defaultValue),
|
|
136
|
-
kind: "boolean",
|
|
137
|
-
key: key
|
|
138
|
-
};
|
|
139
|
-
case "position_selector":
|
|
140
|
-
return {
|
|
141
|
-
value: defaultValue,
|
|
142
|
-
kind: "position_selector",
|
|
143
|
-
key: key
|
|
144
|
-
};
|
|
145
|
-
case "alignment_block":
|
|
146
|
-
return {
|
|
147
|
-
value: defaultValue,
|
|
148
|
-
kind: "alignment_block",
|
|
149
|
-
key: key
|
|
150
|
-
};
|
|
151
|
-
default:
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
}).filter(isNot(null))
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
var buildImageData = function buildImageData(values, themePropertiesSchema) {
|
|
158
|
-
return filterBy({
|
|
159
|
-
kind: "image"
|
|
160
|
-
}, themePropertiesSchema).reduce(function (acc, item) {
|
|
161
|
-
var _values$snakeToCamelC;
|
|
162
|
-
var signedId = (_values$snakeToCamelC = values[snakeToCamelCase(item.key)]) === null || _values$snakeToCamelC === void 0 ? void 0 : _values$snakeToCamelC.signedId;
|
|
163
|
-
acc[item.key] = signedId;
|
|
164
|
-
return acc;
|
|
165
|
-
}, {});
|
|
166
|
-
};
|
|
167
|
-
var isPropertyVisible = function isPropertyVisible(key, formikValues, themePropertiesSchema) {
|
|
168
|
-
var property = findBy({
|
|
169
|
-
key: key
|
|
170
|
-
}, themePropertiesSchema);
|
|
171
|
-
if (isNotPresent(property)) return false;
|
|
172
|
-
if (property !== null && property !== void 0 && property.hidden) return false;
|
|
173
|
-
var conditionalKey = property === null || property === void 0 ? void 0 : property.dependsOn;
|
|
174
|
-
if (isNotPresent(conditionalKey)) return true;
|
|
175
|
-
var dependentPropertySchema = findBy({
|
|
176
|
-
key: conditionalKey
|
|
177
|
-
}, themePropertiesSchema);
|
|
178
|
-
var dependentProperty = findBy({
|
|
179
|
-
key: conditionalKey
|
|
180
|
-
}, formikValues.properties);
|
|
181
|
-
if (dependentPropertySchema.kind === "image") {
|
|
182
|
-
var _formikValues$snakeTo;
|
|
183
|
-
return isPresent((_formikValues$snakeTo = formikValues[snakeToCamelCase(conditionalKey)]) === null || _formikValues$snakeTo === void 0 ? void 0 : _formikValues$snakeTo.url);
|
|
184
|
-
} else if (dependentPropertySchema.kind === "boolean") {
|
|
185
|
-
return (dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value) !== "false";
|
|
186
|
-
}
|
|
187
|
-
return isPresent(dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value);
|
|
188
|
-
};
|
|
189
|
-
var buildLabel = function buildLabel(key, kind) {
|
|
190
|
-
return t$1("neetoThemes.properties.".concat(snakeToCamelCase(kind), ".").concat(snakeToCamelCase(key)));
|
|
191
|
-
};
|
|
192
|
-
|
|
193
94
|
var getImageFromUrl = function getImageFromUrl(source) {
|
|
194
95
|
var image = new Image();
|
|
195
96
|
image.crossOrigin = "anonymous";
|
|
@@ -261,11 +162,32 @@ var setVariable = function setVariable(name, value, variableNamesMap) {
|
|
|
261
162
|
if (!variableName) return;
|
|
262
163
|
root.style.setProperty(variableName, value);
|
|
263
164
|
};
|
|
165
|
+
var isPropertyIndependent = function isPropertyIndependent(key, theme, schema) {
|
|
166
|
+
var property = findBy({
|
|
167
|
+
key: key
|
|
168
|
+
}, schema);
|
|
169
|
+
if (isNotPresent(property)) return false;
|
|
170
|
+
var conditionalKey = property === null || property === void 0 ? void 0 : property.dependsOn;
|
|
171
|
+
if (isNotPresent(conditionalKey)) return true;
|
|
172
|
+
var dependentPropertySchema = findBy({
|
|
173
|
+
key: conditionalKey
|
|
174
|
+
}, schema);
|
|
175
|
+
var dependentProperty = findBy({
|
|
176
|
+
key: conditionalKey
|
|
177
|
+
}, theme.properties);
|
|
178
|
+
if (dependentPropertySchema.kind === "image") {
|
|
179
|
+
var _theme$snakeToCamelCa;
|
|
180
|
+
return isPresent((_theme$snakeToCamelCa = theme[snakeToCamelCase(conditionalKey)]) === null || _theme$snakeToCamelCa === void 0 ? void 0 : _theme$snakeToCamelCa.url);
|
|
181
|
+
} else if (dependentPropertySchema.kind === "boolean") {
|
|
182
|
+
return (dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value) !== "false";
|
|
183
|
+
}
|
|
184
|
+
return isPresent(dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value);
|
|
185
|
+
};
|
|
264
186
|
var setTheme = function setTheme(theme, variableNamesMap, themeConfig) {
|
|
265
187
|
if (isNotPresent(theme === null || theme === void 0 ? void 0 : theme.properties)) return;
|
|
266
188
|
theme.properties.forEach(function (property) {
|
|
267
189
|
var attribute = snakeToCamelCase(property.key);
|
|
268
|
-
if (!
|
|
190
|
+
if (!isPropertyIndependent(property.key, theme, themeConfig)) {
|
|
269
191
|
setVariable(attribute, "", variableNamesMap);
|
|
270
192
|
return;
|
|
271
193
|
}
|
|
@@ -522,6 +444,105 @@ var OVERLAY_OPACITY_SLIDER_MARKS = {
|
|
|
522
444
|
};
|
|
523
445
|
var HUNDRED = 100;
|
|
524
446
|
|
|
447
|
+
var buildInitialValues = function buildInitialValues(theme, themePropertiesSchema) {
|
|
448
|
+
if (isPresent(theme)) return theme;
|
|
449
|
+
return {
|
|
450
|
+
name: t$1("neetoThemes.build.leftSideBar.themes.createTheme.newThemeName"),
|
|
451
|
+
properties: themePropertiesSchema.map(function (_ref) {
|
|
452
|
+
var key = _ref.key,
|
|
453
|
+
kind = _ref.kind,
|
|
454
|
+
defaultValue = _ref.defaultValue;
|
|
455
|
+
switch (kind) {
|
|
456
|
+
case "color":
|
|
457
|
+
return {
|
|
458
|
+
value: defaultValue,
|
|
459
|
+
kind: "color",
|
|
460
|
+
key: key
|
|
461
|
+
};
|
|
462
|
+
case "font_family":
|
|
463
|
+
return {
|
|
464
|
+
value: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
|
|
465
|
+
kind: "font_family",
|
|
466
|
+
key: key
|
|
467
|
+
};
|
|
468
|
+
case "overlay_opacity":
|
|
469
|
+
return {
|
|
470
|
+
value: 0,
|
|
471
|
+
kind: "overlay_opacity",
|
|
472
|
+
key: key
|
|
473
|
+
};
|
|
474
|
+
case "slider":
|
|
475
|
+
return {
|
|
476
|
+
value: 0,
|
|
477
|
+
kind: "slider",
|
|
478
|
+
key: key
|
|
479
|
+
};
|
|
480
|
+
case "radius":
|
|
481
|
+
return {
|
|
482
|
+
value: defaultValue,
|
|
483
|
+
kind: "radius",
|
|
484
|
+
key: key
|
|
485
|
+
};
|
|
486
|
+
case "boolean":
|
|
487
|
+
return {
|
|
488
|
+
value: String(defaultValue),
|
|
489
|
+
kind: "boolean",
|
|
490
|
+
key: key
|
|
491
|
+
};
|
|
492
|
+
case "position_selector":
|
|
493
|
+
return {
|
|
494
|
+
value: defaultValue,
|
|
495
|
+
kind: "position_selector",
|
|
496
|
+
key: key
|
|
497
|
+
};
|
|
498
|
+
case "alignment_block":
|
|
499
|
+
return {
|
|
500
|
+
value: defaultValue,
|
|
501
|
+
kind: "alignment_block",
|
|
502
|
+
key: key
|
|
503
|
+
};
|
|
504
|
+
default:
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
}).filter(isNot(null))
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
var buildImageData = function buildImageData(values, themePropertiesSchema) {
|
|
511
|
+
return filterBy({
|
|
512
|
+
kind: "image"
|
|
513
|
+
}, themePropertiesSchema).reduce(function (acc, item) {
|
|
514
|
+
var _values$snakeToCamelC;
|
|
515
|
+
var signedId = (_values$snakeToCamelC = values[snakeToCamelCase(item.key)]) === null || _values$snakeToCamelC === void 0 ? void 0 : _values$snakeToCamelC.signedId;
|
|
516
|
+
acc[item.key] = signedId;
|
|
517
|
+
return acc;
|
|
518
|
+
}, {});
|
|
519
|
+
};
|
|
520
|
+
var isPropertyVisible = function isPropertyVisible(key, formikValues, themePropertiesSchema) {
|
|
521
|
+
var property = findBy({
|
|
522
|
+
key: key
|
|
523
|
+
}, themePropertiesSchema);
|
|
524
|
+
if (isNotPresent(property)) return false;
|
|
525
|
+
if (property !== null && property !== void 0 && property.hidden) return false;
|
|
526
|
+
var conditionalKey = property === null || property === void 0 ? void 0 : property.dependsOn;
|
|
527
|
+
if (isNotPresent(conditionalKey)) return true;
|
|
528
|
+
var dependentPropertySchema = findBy({
|
|
529
|
+
key: conditionalKey
|
|
530
|
+
}, themePropertiesSchema);
|
|
531
|
+
var dependentProperty = findBy({
|
|
532
|
+
key: conditionalKey
|
|
533
|
+
}, formikValues.properties);
|
|
534
|
+
if (dependentPropertySchema.kind === "image") {
|
|
535
|
+
var _formikValues$snakeTo;
|
|
536
|
+
return isPresent((_formikValues$snakeTo = formikValues[snakeToCamelCase(conditionalKey)]) === null || _formikValues$snakeTo === void 0 ? void 0 : _formikValues$snakeTo.url);
|
|
537
|
+
} else if (dependentPropertySchema.kind === "boolean") {
|
|
538
|
+
return (dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value) !== "false";
|
|
539
|
+
}
|
|
540
|
+
return isPresent(dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value);
|
|
541
|
+
};
|
|
542
|
+
var buildLabel = function buildLabel(key, kind) {
|
|
543
|
+
return t$1("neetoThemes.properties.".concat(snakeToCamelCase(kind), ".").concat(snakeToCamelCase(key)));
|
|
544
|
+
};
|
|
545
|
+
|
|
525
546
|
var Card$2 = function Card(_ref) {
|
|
526
547
|
var _ref$title = _ref.title,
|
|
527
548
|
title = _ref$title === void 0 ? "" : _ref$title,
|
|
@@ -1075,7 +1096,8 @@ var Customize = function Customize(_ref) {
|
|
|
1075
1096
|
onCreateTheme = _ref.onCreateTheme,
|
|
1076
1097
|
onApplyTheme = _ref.onApplyTheme,
|
|
1077
1098
|
isApplyingTheme = _ref.isApplyingTheme,
|
|
1078
|
-
onPropertiesChange = _ref.onPropertiesChange
|
|
1099
|
+
onPropertiesChange = _ref.onPropertiesChange,
|
|
1100
|
+
onUpdateThemeSuccess = _ref.onUpdateThemeSuccess;
|
|
1079
1101
|
var _useTranslation = useTranslation(),
|
|
1080
1102
|
t = _useTranslation.t;
|
|
1081
1103
|
var _useState = useState({}),
|
|
@@ -1121,9 +1143,10 @@ var Customize = function Customize(_ref) {
|
|
|
1121
1143
|
}
|
|
1122
1144
|
return updateTheme(themeToSave, {
|
|
1123
1145
|
onSuccess: function onSuccess() {
|
|
1124
|
-
|
|
1146
|
+
resetForm({
|
|
1125
1147
|
values: values
|
|
1126
1148
|
});
|
|
1149
|
+
onUpdateThemeSuccess === null || onUpdateThemeSuccess === void 0 || onUpdateThemeSuccess(values);
|
|
1127
1150
|
}
|
|
1128
1151
|
});
|
|
1129
1152
|
};
|
|
@@ -1459,11 +1482,13 @@ var Card = function Card(_ref) {
|
|
|
1459
1482
|
},
|
|
1460
1483
|
menuItems: [{
|
|
1461
1484
|
key: "edit",
|
|
1485
|
+
"data-cy": "edit-theme-menu-item",
|
|
1462
1486
|
label: t("neetoThemes.common.edit"),
|
|
1463
1487
|
isVisible: isPresent(onEditTheme),
|
|
1464
1488
|
onClick: handleEditTheme
|
|
1465
1489
|
}, {
|
|
1466
1490
|
key: "clone",
|
|
1491
|
+
"data-cy": "clone-theme-menu-item",
|
|
1467
1492
|
label: t("neetoThemes.build.leftSideBar.themes.themeOptions.clone"),
|
|
1468
1493
|
onClick: handleCloneTheme
|
|
1469
1494
|
}, {
|
|
@@ -1694,7 +1719,8 @@ var Sidebar = function Sidebar(_ref) {
|
|
|
1694
1719
|
var _themeToEdit$current, _themeToEdit$current2, _themeToDelete$curren2, _themeToDelete$curren3, _themeToDelete$curren4;
|
|
1695
1720
|
var thumbnail = _ref.thumbnail,
|
|
1696
1721
|
onPropertiesChange = _ref.onPropertiesChange,
|
|
1697
|
-
onApplyThemeSuccess = _ref.onApplyThemeSuccess
|
|
1722
|
+
onApplyThemeSuccess = _ref.onApplyThemeSuccess,
|
|
1723
|
+
onUpdateThemeSuccess = _ref.onUpdateThemeSuccess;
|
|
1698
1724
|
var _useState = useState(DESIGN_SCREENS.THEMES),
|
|
1699
1725
|
_useState2 = _slicedToArray(_useState, 2),
|
|
1700
1726
|
currentScreen = _useState2[0],
|
|
@@ -1761,7 +1787,7 @@ var Sidebar = function Sidebar(_ref) {
|
|
|
1761
1787
|
});
|
|
1762
1788
|
setThemeBeingApplied({});
|
|
1763
1789
|
setCurrentScreen(DESIGN_SCREENS.THEMES);
|
|
1764
|
-
onApplyThemeSuccess === null || onApplyThemeSuccess === void 0 || onApplyThemeSuccess();
|
|
1790
|
+
onApplyThemeSuccess === null || onApplyThemeSuccess === void 0 || onApplyThemeSuccess(theme);
|
|
1765
1791
|
}
|
|
1766
1792
|
}),
|
|
1767
1793
|
applyTheme = _useApplyTheme.mutate,
|
|
@@ -1857,6 +1883,7 @@ var Sidebar = function Sidebar(_ref) {
|
|
|
1857
1883
|
onApplyTheme: onApplyTheme,
|
|
1858
1884
|
onCreateTheme: onCreateTheme,
|
|
1859
1885
|
onPropertiesChange: onPropertiesChange,
|
|
1886
|
+
onUpdateThemeSuccess: onUpdateThemeSuccess,
|
|
1860
1887
|
theme: themeToEdit.current,
|
|
1861
1888
|
themeId: (_themeToEdit$current2 = themeToEdit.current) === null || _themeToEdit$current2 === void 0 ? void 0 : _themeToEdit$current2.id
|
|
1862
1889
|
}), /*#__PURE__*/jsx(MemoizedAlert, {
|
|
@@ -1886,7 +1913,9 @@ var NeetoThemesBuilder = function NeetoThemesBuilder(_ref) {
|
|
|
1886
1913
|
_ref$isTemplateThemes = _ref.isTemplateThemesEnabled,
|
|
1887
1914
|
isTemplateThemesEnabled = _ref$isTemplateThemes === void 0 ? false : _ref$isTemplateThemes,
|
|
1888
1915
|
_ref$onApplyThemeSucc = _ref.onApplyThemeSuccess,
|
|
1889
|
-
onApplyThemeSuccess = _ref$onApplyThemeSucc === void 0 ? noop : _ref$onApplyThemeSucc
|
|
1916
|
+
onApplyThemeSuccess = _ref$onApplyThemeSucc === void 0 ? noop : _ref$onApplyThemeSucc,
|
|
1917
|
+
_ref$onUpdateThemeSuc = _ref.onUpdateThemeSuccess,
|
|
1918
|
+
onUpdateThemeSuccess = _ref$onUpdateThemeSuc === void 0 ? noop : _ref$onUpdateThemeSuc;
|
|
1890
1919
|
var _useThemeStore = useThemeStore(function (store) {
|
|
1891
1920
|
return {
|
|
1892
1921
|
setThemeState: store["setThemeState"]
|
|
@@ -1935,6 +1964,7 @@ var NeetoThemesBuilder = function NeetoThemesBuilder(_ref) {
|
|
|
1935
1964
|
children: [/*#__PURE__*/jsx(Sidebar, {
|
|
1936
1965
|
onApplyThemeSuccess: onApplyThemeSuccess,
|
|
1937
1966
|
onPropertiesChange: onPropertiesChange,
|
|
1967
|
+
onUpdateThemeSuccess: onUpdateThemeSuccess,
|
|
1938
1968
|
thumbnail: thumbnail
|
|
1939
1969
|
}), /*#__PURE__*/jsx("div", {
|
|
1940
1970
|
className: "neeto-themes-preview__wrapper",
|