@bigbinary/neeto-themes-frontend 2.0.6 → 2.0.7
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 +110 -104
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +111 -105
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
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 { findBy, isNotPresent, isPresent, snakeToCamelCase, isNot, filterBy, 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,6 +91,105 @@ 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
|
+
|
|
94
193
|
var getImageFromUrl = function getImageFromUrl(source) {
|
|
95
194
|
var image = new Image();
|
|
96
195
|
image.crossOrigin = "anonymous";
|
|
@@ -166,6 +265,10 @@ var setTheme = function setTheme(theme, variableNamesMap, themeConfig) {
|
|
|
166
265
|
if (isNotPresent(theme === null || theme === void 0 ? void 0 : theme.properties)) return;
|
|
167
266
|
theme.properties.forEach(function (property) {
|
|
168
267
|
var attribute = snakeToCamelCase(property.key);
|
|
268
|
+
if (!isPropertyVisible(property.key, theme, themeConfig)) {
|
|
269
|
+
setVariable(attribute, "", variableNamesMap);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
169
272
|
if (property.kind === "color") {
|
|
170
273
|
setVariable(attribute, hexToRgba(property.value), variableNamesMap);
|
|
171
274
|
} else if (property.kind === "overlay_opacity") {
|
|
@@ -419,105 +522,6 @@ var OVERLAY_OPACITY_SLIDER_MARKS = {
|
|
|
419
522
|
};
|
|
420
523
|
var HUNDRED = 100;
|
|
421
524
|
|
|
422
|
-
var buildInitialValues = function buildInitialValues(theme, themePropertiesSchema) {
|
|
423
|
-
if (isPresent(theme)) return theme;
|
|
424
|
-
return {
|
|
425
|
-
name: t$1("neetoThemes.build.leftSideBar.themes.createTheme.newThemeName"),
|
|
426
|
-
properties: themePropertiesSchema.map(function (_ref) {
|
|
427
|
-
var key = _ref.key,
|
|
428
|
-
kind = _ref.kind,
|
|
429
|
-
defaultValue = _ref.defaultValue;
|
|
430
|
-
switch (kind) {
|
|
431
|
-
case "color":
|
|
432
|
-
return {
|
|
433
|
-
value: defaultValue,
|
|
434
|
-
kind: "color",
|
|
435
|
-
key: key
|
|
436
|
-
};
|
|
437
|
-
case "font_family":
|
|
438
|
-
return {
|
|
439
|
-
value: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
|
|
440
|
-
kind: "font_family",
|
|
441
|
-
key: key
|
|
442
|
-
};
|
|
443
|
-
case "overlay_opacity":
|
|
444
|
-
return {
|
|
445
|
-
value: 0,
|
|
446
|
-
kind: "overlay_opacity",
|
|
447
|
-
key: key
|
|
448
|
-
};
|
|
449
|
-
case "slider":
|
|
450
|
-
return {
|
|
451
|
-
value: 0,
|
|
452
|
-
kind: "slider",
|
|
453
|
-
key: key
|
|
454
|
-
};
|
|
455
|
-
case "radius":
|
|
456
|
-
return {
|
|
457
|
-
value: defaultValue,
|
|
458
|
-
kind: "radius",
|
|
459
|
-
key: key
|
|
460
|
-
};
|
|
461
|
-
case "boolean":
|
|
462
|
-
return {
|
|
463
|
-
value: String(defaultValue),
|
|
464
|
-
kind: "boolean",
|
|
465
|
-
key: key
|
|
466
|
-
};
|
|
467
|
-
case "position_selector":
|
|
468
|
-
return {
|
|
469
|
-
value: defaultValue,
|
|
470
|
-
kind: "position_selector",
|
|
471
|
-
key: key
|
|
472
|
-
};
|
|
473
|
-
case "alignment_block":
|
|
474
|
-
return {
|
|
475
|
-
value: defaultValue,
|
|
476
|
-
kind: "alignment_block",
|
|
477
|
-
key: key
|
|
478
|
-
};
|
|
479
|
-
default:
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
}).filter(isNot(null))
|
|
483
|
-
};
|
|
484
|
-
};
|
|
485
|
-
var buildImageData = function buildImageData(values, themePropertiesSchema) {
|
|
486
|
-
return filterBy({
|
|
487
|
-
kind: "image"
|
|
488
|
-
}, themePropertiesSchema).reduce(function (acc, item) {
|
|
489
|
-
var _values$snakeToCamelC;
|
|
490
|
-
var signedId = (_values$snakeToCamelC = values[snakeToCamelCase(item.key)]) === null || _values$snakeToCamelC === void 0 ? void 0 : _values$snakeToCamelC.signedId;
|
|
491
|
-
acc[item.key] = signedId;
|
|
492
|
-
return acc;
|
|
493
|
-
}, {});
|
|
494
|
-
};
|
|
495
|
-
var isPropertyVisible = function isPropertyVisible(key, formikValues, themePropertiesSchema) {
|
|
496
|
-
var property = findBy({
|
|
497
|
-
key: key
|
|
498
|
-
}, themePropertiesSchema);
|
|
499
|
-
if (isNotPresent(property)) return false;
|
|
500
|
-
if (property !== null && property !== void 0 && property.hidden) return false;
|
|
501
|
-
var conditionalKey = property === null || property === void 0 ? void 0 : property.dependsOn;
|
|
502
|
-
if (isNotPresent(conditionalKey)) return true;
|
|
503
|
-
var dependentPropertySchema = findBy({
|
|
504
|
-
key: conditionalKey
|
|
505
|
-
}, themePropertiesSchema);
|
|
506
|
-
var dependentProperty = findBy({
|
|
507
|
-
key: conditionalKey
|
|
508
|
-
}, formikValues.properties);
|
|
509
|
-
if (dependentPropertySchema.kind === "image") {
|
|
510
|
-
var _formikValues$snakeTo;
|
|
511
|
-
return isPresent((_formikValues$snakeTo = formikValues[snakeToCamelCase(conditionalKey)]) === null || _formikValues$snakeTo === void 0 ? void 0 : _formikValues$snakeTo.url);
|
|
512
|
-
} else if (dependentPropertySchema.kind === "boolean") {
|
|
513
|
-
return (dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value) !== "false";
|
|
514
|
-
}
|
|
515
|
-
return isPresent(dependentProperty === null || dependentProperty === void 0 ? void 0 : dependentProperty.value);
|
|
516
|
-
};
|
|
517
|
-
var buildLabel = function buildLabel(key, kind) {
|
|
518
|
-
return t$1("neetoThemes.properties.".concat(snakeToCamelCase(kind), ".").concat(snakeToCamelCase(key)));
|
|
519
|
-
};
|
|
520
|
-
|
|
521
525
|
var Card$2 = function Card(_ref) {
|
|
522
526
|
var _ref$title = _ref.title,
|
|
523
527
|
title = _ref$title === void 0 ? "" : _ref$title,
|
|
@@ -1915,15 +1919,17 @@ var NeetoThemesBuilder = function NeetoThemesBuilder(_ref) {
|
|
|
1915
1919
|
useEffect(function () {
|
|
1916
1920
|
if (isNotPresent(currentTheme)) return;
|
|
1917
1921
|
setThemeState({
|
|
1918
|
-
currentTheme: currentTheme,
|
|
1919
|
-
isCurrentThemeLoading: isCurrentThemeLoading,
|
|
1920
1922
|
previewingTheme: currentTheme
|
|
1921
1923
|
});
|
|
1922
|
-
|
|
1924
|
+
setTheme(currentTheme);
|
|
1925
|
+
}, [isLoading, entityId]);
|
|
1923
1926
|
useEffect(function () {
|
|
1924
1927
|
if (isNotPresent(currentTheme)) return;
|
|
1925
|
-
|
|
1926
|
-
|
|
1928
|
+
setThemeState({
|
|
1929
|
+
currentTheme: currentTheme,
|
|
1930
|
+
isCurrentThemeLoading: isCurrentThemeLoading
|
|
1931
|
+
});
|
|
1932
|
+
}, [currentTheme, isCurrentThemeLoading]);
|
|
1927
1933
|
return /*#__PURE__*/jsxs("div", {
|
|
1928
1934
|
className: "neeto-themes__wrapper",
|
|
1929
1935
|
children: [/*#__PURE__*/jsx(Sidebar, {
|