@bigbinary/neeto-themes-frontend 2.0.7 → 2.0.8

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,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 { findBy, isNotPresent, isPresent, snakeToCamelCase, isNot, filterBy, findIndexBy, toLabelAndValue, humanize, isNotEmpty, noop } from '@bigbinary/neeto-cist';
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 (!isPropertyVisible(property.key, theme, themeConfig)) {
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,