@cmssy/react 0.12.0 → 0.13.0
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/client.cjs +9 -71
- package/dist/client.js +9 -71
- package/dist/index.cjs +17 -85
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -86
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -485,67 +485,11 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
|
|
|
485
485
|
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
486
486
|
return { ...nonTranslatable, ...chosen };
|
|
487
487
|
}
|
|
488
|
-
|
|
489
|
-
// src/components/block-attrs.ts
|
|
490
|
-
var PADDING_SCALE = {
|
|
491
|
-
none: "0",
|
|
492
|
-
sm: "0.5rem",
|
|
493
|
-
md: "1rem",
|
|
494
|
-
lg: "2rem",
|
|
495
|
-
xl: "4rem"
|
|
496
|
-
};
|
|
497
|
-
var MAX_WIDTH_SCALE = {
|
|
498
|
-
sm: "640px",
|
|
499
|
-
md: "768px",
|
|
500
|
-
lg: "1024px",
|
|
501
|
-
full: "100%"
|
|
502
|
-
};
|
|
503
|
-
var TEXT_ALIGN = /* @__PURE__ */ new Set(["left", "center", "right"]);
|
|
504
|
-
function asRecord(value) {
|
|
505
|
-
return value && typeof value === "object" ? value : {};
|
|
506
|
-
}
|
|
507
|
-
function text(value) {
|
|
508
|
-
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
509
|
-
}
|
|
510
|
-
function resolveBlockAttrs(blockId, styleBucket, advancedBucket) {
|
|
511
|
-
const s = asRecord(styleBucket);
|
|
512
|
-
const a = asRecord(advancedBucket);
|
|
513
|
-
const style = {};
|
|
514
|
-
const background = text(s.background);
|
|
515
|
-
if (background) style.background = background;
|
|
516
|
-
const padding = text(s.padding);
|
|
517
|
-
if (padding && PADDING_SCALE[padding]) {
|
|
518
|
-
style.paddingTop = PADDING_SCALE[padding];
|
|
519
|
-
style.paddingBottom = PADDING_SCALE[padding];
|
|
520
|
-
}
|
|
521
|
-
const align = text(s.align);
|
|
522
|
-
if (align && TEXT_ALIGN.has(align)) {
|
|
523
|
-
style.textAlign = align;
|
|
524
|
-
}
|
|
525
|
-
const maxWidth = text(s.maxWidth);
|
|
526
|
-
if (maxWidth && MAX_WIDTH_SCALE[maxWidth]) {
|
|
527
|
-
style.maxWidth = MAX_WIDTH_SCALE[maxWidth];
|
|
528
|
-
style.marginLeft = "auto";
|
|
529
|
-
style.marginRight = "auto";
|
|
530
|
-
}
|
|
531
|
-
const selector = `[data-block-id="${blockId.replace(/["\\]/g, "\\$&")}"]`;
|
|
532
|
-
const rules = [];
|
|
533
|
-
const customCss = text(a.customCss);
|
|
534
|
-
if (customCss) {
|
|
535
|
-
const safe = customCss.replace(/[{}]/g, "").replace(/<\/style/gi, "");
|
|
536
|
-
rules.push(`${selector}{${safe}}`);
|
|
537
|
-
}
|
|
538
|
-
if (a.hideOnMobile === true) {
|
|
539
|
-
rules.push(
|
|
540
|
-
`@media (max-width:767px){${selector}{display:none !important}}`
|
|
541
|
-
);
|
|
542
|
-
}
|
|
488
|
+
function mergeBlockValues(content, style, advanced) {
|
|
543
489
|
return {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
hidden: a.visible === false,
|
|
548
|
-
css: rules.length > 0 ? rules.join("") : void 0
|
|
490
|
+
...content,
|
|
491
|
+
...isPlainObject(style) ? style : {},
|
|
492
|
+
...isPlainObject(advanced) ? advanced : {}
|
|
549
493
|
};
|
|
550
494
|
}
|
|
551
495
|
var WARN_CAP = 256;
|
|
@@ -569,24 +513,18 @@ function CmssyBlock({
|
|
|
569
513
|
context
|
|
570
514
|
}) {
|
|
571
515
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
572
|
-
const attrs = resolveBlockAttrs(block.id, block.style, block.advanced);
|
|
573
|
-
if (attrs.hidden && !editable) return null;
|
|
574
516
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
575
|
-
const
|
|
576
|
-
|
|
517
|
+
const resolved = patchedContent ? { ...base, ...patchedContent } : base;
|
|
518
|
+
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
519
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
577
520
|
"div",
|
|
578
521
|
{
|
|
579
522
|
"data-block-id": block.id,
|
|
580
523
|
"data-block-type": block.type,
|
|
581
524
|
"data-layout-position": layoutPosition,
|
|
582
525
|
draggable: editable || void 0,
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
style: Component ? attrs.style : { ...attrs.style, display: "none" },
|
|
586
|
-
children: [
|
|
587
|
-
attrs.css ? /* @__PURE__ */ jsxRuntime.jsx("style", { dangerouslySetInnerHTML: { __html: attrs.css } }) : null,
|
|
588
|
-
Component ? react.createElement(Component, { content, context }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
589
|
-
]
|
|
526
|
+
style: Component ? void 0 : { display: "none" },
|
|
527
|
+
children: Component ? react.createElement(Component, { content, context }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
590
528
|
}
|
|
591
529
|
);
|
|
592
530
|
}
|
package/dist/client.js
CHANGED
|
@@ -483,67 +483,11 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
|
|
|
483
483
|
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
484
484
|
return { ...nonTranslatable, ...chosen };
|
|
485
485
|
}
|
|
486
|
-
|
|
487
|
-
// src/components/block-attrs.ts
|
|
488
|
-
var PADDING_SCALE = {
|
|
489
|
-
none: "0",
|
|
490
|
-
sm: "0.5rem",
|
|
491
|
-
md: "1rem",
|
|
492
|
-
lg: "2rem",
|
|
493
|
-
xl: "4rem"
|
|
494
|
-
};
|
|
495
|
-
var MAX_WIDTH_SCALE = {
|
|
496
|
-
sm: "640px",
|
|
497
|
-
md: "768px",
|
|
498
|
-
lg: "1024px",
|
|
499
|
-
full: "100%"
|
|
500
|
-
};
|
|
501
|
-
var TEXT_ALIGN = /* @__PURE__ */ new Set(["left", "center", "right"]);
|
|
502
|
-
function asRecord(value) {
|
|
503
|
-
return value && typeof value === "object" ? value : {};
|
|
504
|
-
}
|
|
505
|
-
function text(value) {
|
|
506
|
-
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
507
|
-
}
|
|
508
|
-
function resolveBlockAttrs(blockId, styleBucket, advancedBucket) {
|
|
509
|
-
const s = asRecord(styleBucket);
|
|
510
|
-
const a = asRecord(advancedBucket);
|
|
511
|
-
const style = {};
|
|
512
|
-
const background = text(s.background);
|
|
513
|
-
if (background) style.background = background;
|
|
514
|
-
const padding = text(s.padding);
|
|
515
|
-
if (padding && PADDING_SCALE[padding]) {
|
|
516
|
-
style.paddingTop = PADDING_SCALE[padding];
|
|
517
|
-
style.paddingBottom = PADDING_SCALE[padding];
|
|
518
|
-
}
|
|
519
|
-
const align = text(s.align);
|
|
520
|
-
if (align && TEXT_ALIGN.has(align)) {
|
|
521
|
-
style.textAlign = align;
|
|
522
|
-
}
|
|
523
|
-
const maxWidth = text(s.maxWidth);
|
|
524
|
-
if (maxWidth && MAX_WIDTH_SCALE[maxWidth]) {
|
|
525
|
-
style.maxWidth = MAX_WIDTH_SCALE[maxWidth];
|
|
526
|
-
style.marginLeft = "auto";
|
|
527
|
-
style.marginRight = "auto";
|
|
528
|
-
}
|
|
529
|
-
const selector = `[data-block-id="${blockId.replace(/["\\]/g, "\\$&")}"]`;
|
|
530
|
-
const rules = [];
|
|
531
|
-
const customCss = text(a.customCss);
|
|
532
|
-
if (customCss) {
|
|
533
|
-
const safe = customCss.replace(/[{}]/g, "").replace(/<\/style/gi, "");
|
|
534
|
-
rules.push(`${selector}{${safe}}`);
|
|
535
|
-
}
|
|
536
|
-
if (a.hideOnMobile === true) {
|
|
537
|
-
rules.push(
|
|
538
|
-
`@media (max-width:767px){${selector}{display:none !important}}`
|
|
539
|
-
);
|
|
540
|
-
}
|
|
486
|
+
function mergeBlockValues(content, style, advanced) {
|
|
541
487
|
return {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
hidden: a.visible === false,
|
|
546
|
-
css: rules.length > 0 ? rules.join("") : void 0
|
|
488
|
+
...content,
|
|
489
|
+
...isPlainObject(style) ? style : {},
|
|
490
|
+
...isPlainObject(advanced) ? advanced : {}
|
|
547
491
|
};
|
|
548
492
|
}
|
|
549
493
|
var WARN_CAP = 256;
|
|
@@ -567,24 +511,18 @@ function CmssyBlock({
|
|
|
567
511
|
context
|
|
568
512
|
}) {
|
|
569
513
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
570
|
-
const attrs = resolveBlockAttrs(block.id, block.style, block.advanced);
|
|
571
|
-
if (attrs.hidden && !editable) return null;
|
|
572
514
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
573
|
-
const
|
|
574
|
-
|
|
515
|
+
const resolved = patchedContent ? { ...base, ...patchedContent } : base;
|
|
516
|
+
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
517
|
+
return /* @__PURE__ */ jsx(
|
|
575
518
|
"div",
|
|
576
519
|
{
|
|
577
520
|
"data-block-id": block.id,
|
|
578
521
|
"data-block-type": block.type,
|
|
579
522
|
"data-layout-position": layoutPosition,
|
|
580
523
|
draggable: editable || void 0,
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
style: Component ? attrs.style : { ...attrs.style, display: "none" },
|
|
584
|
-
children: [
|
|
585
|
-
attrs.css ? /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: attrs.css } }) : null,
|
|
586
|
-
Component ? createElement(Component, { content, context }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
587
|
-
]
|
|
524
|
+
style: Component ? void 0 : { display: "none" },
|
|
525
|
+
children: Component ? createElement(Component, { content, context }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
588
526
|
}
|
|
589
527
|
);
|
|
590
528
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -101,6 +101,13 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
|
|
|
101
101
|
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
102
102
|
return { ...nonTranslatable, ...chosen };
|
|
103
103
|
}
|
|
104
|
+
function mergeBlockValues(content, style, advanced) {
|
|
105
|
+
return {
|
|
106
|
+
...content,
|
|
107
|
+
...isPlainObject(style) ? style : {},
|
|
108
|
+
...isPlainObject(advanced) ? advanced : {}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
104
111
|
|
|
105
112
|
// src/components/block-context.ts
|
|
106
113
|
function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
|
|
@@ -116,69 +123,6 @@ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, for
|
|
|
116
123
|
...extra?.workspace ? { workspace: extra.workspace } : {}
|
|
117
124
|
};
|
|
118
125
|
}
|
|
119
|
-
|
|
120
|
-
// src/components/block-attrs.ts
|
|
121
|
-
var PADDING_SCALE = {
|
|
122
|
-
none: "0",
|
|
123
|
-
sm: "0.5rem",
|
|
124
|
-
md: "1rem",
|
|
125
|
-
lg: "2rem",
|
|
126
|
-
xl: "4rem"
|
|
127
|
-
};
|
|
128
|
-
var MAX_WIDTH_SCALE = {
|
|
129
|
-
sm: "640px",
|
|
130
|
-
md: "768px",
|
|
131
|
-
lg: "1024px",
|
|
132
|
-
full: "100%"
|
|
133
|
-
};
|
|
134
|
-
var TEXT_ALIGN = /* @__PURE__ */ new Set(["left", "center", "right"]);
|
|
135
|
-
function asRecord(value) {
|
|
136
|
-
return value && typeof value === "object" ? value : {};
|
|
137
|
-
}
|
|
138
|
-
function text(value) {
|
|
139
|
-
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
140
|
-
}
|
|
141
|
-
function resolveBlockAttrs(blockId, styleBucket, advancedBucket) {
|
|
142
|
-
const s = asRecord(styleBucket);
|
|
143
|
-
const a = asRecord(advancedBucket);
|
|
144
|
-
const style = {};
|
|
145
|
-
const background = text(s.background);
|
|
146
|
-
if (background) style.background = background;
|
|
147
|
-
const padding = text(s.padding);
|
|
148
|
-
if (padding && PADDING_SCALE[padding]) {
|
|
149
|
-
style.paddingTop = PADDING_SCALE[padding];
|
|
150
|
-
style.paddingBottom = PADDING_SCALE[padding];
|
|
151
|
-
}
|
|
152
|
-
const align = text(s.align);
|
|
153
|
-
if (align && TEXT_ALIGN.has(align)) {
|
|
154
|
-
style.textAlign = align;
|
|
155
|
-
}
|
|
156
|
-
const maxWidth = text(s.maxWidth);
|
|
157
|
-
if (maxWidth && MAX_WIDTH_SCALE[maxWidth]) {
|
|
158
|
-
style.maxWidth = MAX_WIDTH_SCALE[maxWidth];
|
|
159
|
-
style.marginLeft = "auto";
|
|
160
|
-
style.marginRight = "auto";
|
|
161
|
-
}
|
|
162
|
-
const selector = `[data-block-id="${blockId.replace(/["\\]/g, "\\$&")}"]`;
|
|
163
|
-
const rules = [];
|
|
164
|
-
const customCss = text(a.customCss);
|
|
165
|
-
if (customCss) {
|
|
166
|
-
const safe = customCss.replace(/[{}]/g, "").replace(/<\/style/gi, "");
|
|
167
|
-
rules.push(`${selector}{${safe}}`);
|
|
168
|
-
}
|
|
169
|
-
if (a.hideOnMobile === true) {
|
|
170
|
-
rules.push(
|
|
171
|
-
`@media (max-width:767px){${selector}{display:none !important}}`
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
style: Object.keys(style).length > 0 ? style : void 0,
|
|
176
|
-
className: text(a.className),
|
|
177
|
-
id: text(a.anchorId),
|
|
178
|
-
hidden: a.visible === false,
|
|
179
|
-
css: rules.length > 0 ? rules.join("") : void 0
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
126
|
var WARN_CAP = 256;
|
|
183
127
|
var warned = /* @__PURE__ */ new Set();
|
|
184
128
|
function UnknownBlock({ type }) {
|
|
@@ -192,26 +136,20 @@ function UnknownBlock({ type }) {
|
|
|
192
136
|
function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
|
|
193
137
|
const { context, data, resolvedContent, enabledLocales } = options;
|
|
194
138
|
const Component = Object.hasOwn(map, block.type) ? map[block.type] : void 0;
|
|
195
|
-
const
|
|
196
|
-
if (attrs.hidden) return null;
|
|
197
|
-
const content = resolvedContent ?? getBlockContentForLanguage(
|
|
139
|
+
const resolved = resolvedContent ?? getBlockContentForLanguage(
|
|
198
140
|
block.content,
|
|
199
141
|
locale,
|
|
200
142
|
defaultLocale,
|
|
201
143
|
enabledLocales?.length ? enabledLocales : void 0
|
|
202
144
|
);
|
|
203
|
-
|
|
145
|
+
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
146
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
204
147
|
"div",
|
|
205
148
|
{
|
|
206
149
|
"data-block-id": block.id,
|
|
207
150
|
"data-block-type": block.type,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
style: Component ? attrs.style : { ...attrs.style, display: "none" },
|
|
211
|
-
children: [
|
|
212
|
-
attrs.css ? /* @__PURE__ */ jsxRuntime.jsx("style", { dangerouslySetInnerHTML: { __html: attrs.css } }) : null,
|
|
213
|
-
Component ? react.createElement(Component, { content, context, data }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
214
|
-
]
|
|
151
|
+
style: Component ? void 0 : { display: "none" },
|
|
152
|
+
children: Component ? react.createElement(Component, { content, context, data }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
215
153
|
},
|
|
216
154
|
block.id
|
|
217
155
|
);
|
|
@@ -958,24 +896,18 @@ function CmssyBlock({
|
|
|
958
896
|
context
|
|
959
897
|
}) {
|
|
960
898
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
961
|
-
const attrs = resolveBlockAttrs(block.id, block.style, block.advanced);
|
|
962
|
-
if (attrs.hidden && !editable) return null;
|
|
963
899
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
964
|
-
const
|
|
965
|
-
|
|
900
|
+
const resolved = patchedContent ? { ...base, ...patchedContent } : base;
|
|
901
|
+
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
902
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
966
903
|
"div",
|
|
967
904
|
{
|
|
968
905
|
"data-block-id": block.id,
|
|
969
906
|
"data-block-type": block.type,
|
|
970
907
|
"data-layout-position": layoutPosition,
|
|
971
908
|
draggable: editable || void 0,
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
style: Component ? attrs.style : { ...attrs.style, display: "none" },
|
|
975
|
-
children: [
|
|
976
|
-
attrs.css ? /* @__PURE__ */ jsxRuntime.jsx("style", { dangerouslySetInnerHTML: { __html: attrs.css } }) : null,
|
|
977
|
-
Component ? react.createElement(Component, { content, context }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
978
|
-
]
|
|
909
|
+
style: Component ? void 0 : { display: "none" },
|
|
910
|
+
children: Component ? react.createElement(Component, { content, context }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
979
911
|
}
|
|
980
912
|
);
|
|
981
913
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -133,7 +133,7 @@ interface CmssyBlockProps {
|
|
|
133
133
|
layoutPosition?: string;
|
|
134
134
|
context?: CmssyBlockContext;
|
|
135
135
|
}
|
|
136
|
-
declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element
|
|
136
|
+
declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
|
|
137
137
|
|
|
138
138
|
interface UnknownBlockProps {
|
|
139
139
|
type: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -133,7 +133,7 @@ interface CmssyBlockProps {
|
|
|
133
133
|
layoutPosition?: string;
|
|
134
134
|
context?: CmssyBlockContext;
|
|
135
135
|
}
|
|
136
|
-
declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element
|
|
136
|
+
declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
|
|
137
137
|
|
|
138
138
|
interface UnknownBlockProps {
|
|
139
139
|
type: string;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
|
-
import { jsx, Fragment
|
|
2
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
export { evaluateFieldConditionGroup } from '@cmssy/types';
|
|
4
4
|
|
|
5
5
|
// src/fields.ts
|
|
@@ -99,6 +99,13 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
|
|
|
99
99
|
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
100
100
|
return { ...nonTranslatable, ...chosen };
|
|
101
101
|
}
|
|
102
|
+
function mergeBlockValues(content, style, advanced) {
|
|
103
|
+
return {
|
|
104
|
+
...content,
|
|
105
|
+
...isPlainObject(style) ? style : {},
|
|
106
|
+
...isPlainObject(advanced) ? advanced : {}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
102
109
|
|
|
103
110
|
// src/components/block-context.ts
|
|
104
111
|
function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
|
|
@@ -114,69 +121,6 @@ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, for
|
|
|
114
121
|
...extra?.workspace ? { workspace: extra.workspace } : {}
|
|
115
122
|
};
|
|
116
123
|
}
|
|
117
|
-
|
|
118
|
-
// src/components/block-attrs.ts
|
|
119
|
-
var PADDING_SCALE = {
|
|
120
|
-
none: "0",
|
|
121
|
-
sm: "0.5rem",
|
|
122
|
-
md: "1rem",
|
|
123
|
-
lg: "2rem",
|
|
124
|
-
xl: "4rem"
|
|
125
|
-
};
|
|
126
|
-
var MAX_WIDTH_SCALE = {
|
|
127
|
-
sm: "640px",
|
|
128
|
-
md: "768px",
|
|
129
|
-
lg: "1024px",
|
|
130
|
-
full: "100%"
|
|
131
|
-
};
|
|
132
|
-
var TEXT_ALIGN = /* @__PURE__ */ new Set(["left", "center", "right"]);
|
|
133
|
-
function asRecord(value) {
|
|
134
|
-
return value && typeof value === "object" ? value : {};
|
|
135
|
-
}
|
|
136
|
-
function text(value) {
|
|
137
|
-
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
138
|
-
}
|
|
139
|
-
function resolveBlockAttrs(blockId, styleBucket, advancedBucket) {
|
|
140
|
-
const s = asRecord(styleBucket);
|
|
141
|
-
const a = asRecord(advancedBucket);
|
|
142
|
-
const style = {};
|
|
143
|
-
const background = text(s.background);
|
|
144
|
-
if (background) style.background = background;
|
|
145
|
-
const padding = text(s.padding);
|
|
146
|
-
if (padding && PADDING_SCALE[padding]) {
|
|
147
|
-
style.paddingTop = PADDING_SCALE[padding];
|
|
148
|
-
style.paddingBottom = PADDING_SCALE[padding];
|
|
149
|
-
}
|
|
150
|
-
const align = text(s.align);
|
|
151
|
-
if (align && TEXT_ALIGN.has(align)) {
|
|
152
|
-
style.textAlign = align;
|
|
153
|
-
}
|
|
154
|
-
const maxWidth = text(s.maxWidth);
|
|
155
|
-
if (maxWidth && MAX_WIDTH_SCALE[maxWidth]) {
|
|
156
|
-
style.maxWidth = MAX_WIDTH_SCALE[maxWidth];
|
|
157
|
-
style.marginLeft = "auto";
|
|
158
|
-
style.marginRight = "auto";
|
|
159
|
-
}
|
|
160
|
-
const selector = `[data-block-id="${blockId.replace(/["\\]/g, "\\$&")}"]`;
|
|
161
|
-
const rules = [];
|
|
162
|
-
const customCss = text(a.customCss);
|
|
163
|
-
if (customCss) {
|
|
164
|
-
const safe = customCss.replace(/[{}]/g, "").replace(/<\/style/gi, "");
|
|
165
|
-
rules.push(`${selector}{${safe}}`);
|
|
166
|
-
}
|
|
167
|
-
if (a.hideOnMobile === true) {
|
|
168
|
-
rules.push(
|
|
169
|
-
`@media (max-width:767px){${selector}{display:none !important}}`
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
style: Object.keys(style).length > 0 ? style : void 0,
|
|
174
|
-
className: text(a.className),
|
|
175
|
-
id: text(a.anchorId),
|
|
176
|
-
hidden: a.visible === false,
|
|
177
|
-
css: rules.length > 0 ? rules.join("") : void 0
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
124
|
var WARN_CAP = 256;
|
|
181
125
|
var warned = /* @__PURE__ */ new Set();
|
|
182
126
|
function UnknownBlock({ type }) {
|
|
@@ -190,26 +134,20 @@ function UnknownBlock({ type }) {
|
|
|
190
134
|
function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
|
|
191
135
|
const { context, data, resolvedContent, enabledLocales } = options;
|
|
192
136
|
const Component = Object.hasOwn(map, block.type) ? map[block.type] : void 0;
|
|
193
|
-
const
|
|
194
|
-
if (attrs.hidden) return null;
|
|
195
|
-
const content = resolvedContent ?? getBlockContentForLanguage(
|
|
137
|
+
const resolved = resolvedContent ?? getBlockContentForLanguage(
|
|
196
138
|
block.content,
|
|
197
139
|
locale,
|
|
198
140
|
defaultLocale,
|
|
199
141
|
enabledLocales?.length ? enabledLocales : void 0
|
|
200
142
|
);
|
|
201
|
-
|
|
143
|
+
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
144
|
+
return /* @__PURE__ */ jsx(
|
|
202
145
|
"div",
|
|
203
146
|
{
|
|
204
147
|
"data-block-id": block.id,
|
|
205
148
|
"data-block-type": block.type,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
style: Component ? attrs.style : { ...attrs.style, display: "none" },
|
|
209
|
-
children: [
|
|
210
|
-
attrs.css ? /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: attrs.css } }) : null,
|
|
211
|
-
Component ? createElement(Component, { content, context, data }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
212
|
-
]
|
|
149
|
+
style: Component ? void 0 : { display: "none" },
|
|
150
|
+
children: Component ? createElement(Component, { content, context, data }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
213
151
|
},
|
|
214
152
|
block.id
|
|
215
153
|
);
|
|
@@ -956,24 +894,18 @@ function CmssyBlock({
|
|
|
956
894
|
context
|
|
957
895
|
}) {
|
|
958
896
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
959
|
-
const attrs = resolveBlockAttrs(block.id, block.style, block.advanced);
|
|
960
|
-
if (attrs.hidden && !editable) return null;
|
|
961
897
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
962
|
-
const
|
|
963
|
-
|
|
898
|
+
const resolved = patchedContent ? { ...base, ...patchedContent } : base;
|
|
899
|
+
const content = mergeBlockValues(resolved, block.style, block.advanced);
|
|
900
|
+
return /* @__PURE__ */ jsx(
|
|
964
901
|
"div",
|
|
965
902
|
{
|
|
966
903
|
"data-block-id": block.id,
|
|
967
904
|
"data-block-type": block.type,
|
|
968
905
|
"data-layout-position": layoutPosition,
|
|
969
906
|
draggable: editable || void 0,
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
style: Component ? attrs.style : { ...attrs.style, display: "none" },
|
|
973
|
-
children: [
|
|
974
|
-
attrs.css ? /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: attrs.css } }) : null,
|
|
975
|
-
Component ? createElement(Component, { content, context }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
976
|
-
]
|
|
907
|
+
style: Component ? void 0 : { display: "none" },
|
|
908
|
+
children: Component ? createElement(Component, { content, context }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
977
909
|
}
|
|
978
910
|
);
|
|
979
911
|
}
|