@cmssy/react 0.12.0 → 0.14.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 +10 -72
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +10 -72
- package/dist/{commerce-queries-ClCU8FZN.d.cts → commerce-queries-D5duQ6QF.d.cts} +7 -1
- package/dist/{commerce-queries-ClCU8FZN.d.ts → commerce-queries-D5duQ6QF.d.ts} +7 -1
- package/dist/index.cjs +20 -83
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +21 -84
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -485,68 +485,8 @@ 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
|
-
|
|
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
|
-
}
|
|
543
|
-
return {
|
|
544
|
-
style: Object.keys(style).length > 0 ? style : void 0,
|
|
545
|
-
className: text(a.className),
|
|
546
|
-
id: text(a.anchorId),
|
|
547
|
-
hidden: a.visible === false,
|
|
548
|
-
css: rules.length > 0 ? rules.join("") : void 0
|
|
549
|
-
};
|
|
488
|
+
function asBucket(value) {
|
|
489
|
+
return isPlainObject(value) ? value : {};
|
|
550
490
|
}
|
|
551
491
|
var WARN_CAP = 256;
|
|
552
492
|
var warned = /* @__PURE__ */ new Set();
|
|
@@ -569,24 +509,22 @@ function CmssyBlock({
|
|
|
569
509
|
context
|
|
570
510
|
}) {
|
|
571
511
|
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
512
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
575
513
|
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
576
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
514
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
577
515
|
"div",
|
|
578
516
|
{
|
|
579
517
|
"data-block-id": block.id,
|
|
580
518
|
"data-block-type": block.type,
|
|
581
519
|
"data-layout-position": layoutPosition,
|
|
582
520
|
draggable: editable || void 0,
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
521
|
+
style: Component ? void 0 : { display: "none" },
|
|
522
|
+
children: Component ? react.createElement(Component, {
|
|
523
|
+
content,
|
|
524
|
+
style: asBucket(block.style),
|
|
525
|
+
advanced: asBucket(block.advanced),
|
|
526
|
+
context
|
|
527
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
590
528
|
}
|
|
591
529
|
);
|
|
592
530
|
}
|
package/dist/client.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyCart, g as CmssyOrder, h as CmssyProduct } from './commerce-queries-
|
|
3
|
-
export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-
|
|
2
|
+
import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyCart, g as CmssyOrder, h as CmssyProduct } from './commerce-queries-D5duQ6QF.cjs';
|
|
3
|
+
export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D5duQ6QF.cjs';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
import '@cmssy/types';
|
|
6
6
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyCart, g as CmssyOrder, h as CmssyProduct } from './commerce-queries-
|
|
3
|
-
export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-
|
|
2
|
+
import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyCart, g as CmssyOrder, h as CmssyProduct } from './commerce-queries-D5duQ6QF.js';
|
|
3
|
+
export { i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, l as CmssyOrderItem, m as CmssyProductVariant } from './commerce-queries-D5duQ6QF.js';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
import '@cmssy/types';
|
|
6
6
|
|
package/dist/client.js
CHANGED
|
@@ -483,68 +483,8 @@ 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
|
-
|
|
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
|
-
}
|
|
541
|
-
return {
|
|
542
|
-
style: Object.keys(style).length > 0 ? style : void 0,
|
|
543
|
-
className: text(a.className),
|
|
544
|
-
id: text(a.anchorId),
|
|
545
|
-
hidden: a.visible === false,
|
|
546
|
-
css: rules.length > 0 ? rules.join("") : void 0
|
|
547
|
-
};
|
|
486
|
+
function asBucket(value) {
|
|
487
|
+
return isPlainObject(value) ? value : {};
|
|
548
488
|
}
|
|
549
489
|
var WARN_CAP = 256;
|
|
550
490
|
var warned = /* @__PURE__ */ new Set();
|
|
@@ -567,24 +507,22 @@ function CmssyBlock({
|
|
|
567
507
|
context
|
|
568
508
|
}) {
|
|
569
509
|
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
510
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
573
511
|
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
574
|
-
return /* @__PURE__ */
|
|
512
|
+
return /* @__PURE__ */ jsx(
|
|
575
513
|
"div",
|
|
576
514
|
{
|
|
577
515
|
"data-block-id": block.id,
|
|
578
516
|
"data-block-type": block.type,
|
|
579
517
|
"data-layout-position": layoutPosition,
|
|
580
518
|
draggable: editable || void 0,
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
519
|
+
style: Component ? void 0 : { display: "none" },
|
|
520
|
+
children: Component ? createElement(Component, {
|
|
521
|
+
content,
|
|
522
|
+
style: asBucket(block.style),
|
|
523
|
+
advanced: asBucket(block.advanced),
|
|
524
|
+
context
|
|
525
|
+
}) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
588
526
|
}
|
|
589
527
|
);
|
|
590
528
|
}
|
|
@@ -340,11 +340,13 @@ interface BlockDefinition {
|
|
|
340
340
|
loader?: BlockLoader;
|
|
341
341
|
component: ComponentType<{
|
|
342
342
|
content: Record<string, unknown>;
|
|
343
|
+
style?: Record<string, unknown>;
|
|
344
|
+
advanced?: Record<string, unknown>;
|
|
343
345
|
context?: CmssyBlockContext;
|
|
344
346
|
data?: unknown;
|
|
345
347
|
}>;
|
|
346
348
|
}
|
|
347
|
-
declare function defineBlock<C extends Record<string, unknown>, D = unknown>(def: {
|
|
349
|
+
declare function defineBlock<C extends Record<string, unknown>, D = unknown, S extends Record<string, unknown> = Record<string, unknown>, A extends Record<string, unknown> = Record<string, unknown>>(def: {
|
|
348
350
|
type: string;
|
|
349
351
|
label?: string;
|
|
350
352
|
category?: string;
|
|
@@ -358,12 +360,16 @@ declare function defineBlock<C extends Record<string, unknown>, D = unknown>(def
|
|
|
358
360
|
}) => Promise<D> | D;
|
|
359
361
|
component: ComponentType<{
|
|
360
362
|
content: C;
|
|
363
|
+
style?: S;
|
|
364
|
+
advanced?: A;
|
|
361
365
|
context?: CmssyBlockContext;
|
|
362
366
|
data?: D;
|
|
363
367
|
}>;
|
|
364
368
|
}): BlockDefinition;
|
|
365
369
|
type BlockMap = Record<string, ComponentType<{
|
|
366
370
|
content: Record<string, unknown>;
|
|
371
|
+
style?: Record<string, unknown>;
|
|
372
|
+
advanced?: Record<string, unknown>;
|
|
367
373
|
context?: CmssyBlockContext;
|
|
368
374
|
data?: unknown;
|
|
369
375
|
}>>;
|
|
@@ -340,11 +340,13 @@ interface BlockDefinition {
|
|
|
340
340
|
loader?: BlockLoader;
|
|
341
341
|
component: ComponentType<{
|
|
342
342
|
content: Record<string, unknown>;
|
|
343
|
+
style?: Record<string, unknown>;
|
|
344
|
+
advanced?: Record<string, unknown>;
|
|
343
345
|
context?: CmssyBlockContext;
|
|
344
346
|
data?: unknown;
|
|
345
347
|
}>;
|
|
346
348
|
}
|
|
347
|
-
declare function defineBlock<C extends Record<string, unknown>, D = unknown>(def: {
|
|
349
|
+
declare function defineBlock<C extends Record<string, unknown>, D = unknown, S extends Record<string, unknown> = Record<string, unknown>, A extends Record<string, unknown> = Record<string, unknown>>(def: {
|
|
348
350
|
type: string;
|
|
349
351
|
label?: string;
|
|
350
352
|
category?: string;
|
|
@@ -358,12 +360,16 @@ declare function defineBlock<C extends Record<string, unknown>, D = unknown>(def
|
|
|
358
360
|
}) => Promise<D> | D;
|
|
359
361
|
component: ComponentType<{
|
|
360
362
|
content: C;
|
|
363
|
+
style?: S;
|
|
364
|
+
advanced?: A;
|
|
361
365
|
context?: CmssyBlockContext;
|
|
362
366
|
data?: D;
|
|
363
367
|
}>;
|
|
364
368
|
}): BlockDefinition;
|
|
365
369
|
type BlockMap = Record<string, ComponentType<{
|
|
366
370
|
content: Record<string, unknown>;
|
|
371
|
+
style?: Record<string, unknown>;
|
|
372
|
+
advanced?: Record<string, unknown>;
|
|
367
373
|
context?: CmssyBlockContext;
|
|
368
374
|
data?: unknown;
|
|
369
375
|
}>>;
|
package/dist/index.cjs
CHANGED
|
@@ -101,6 +101,9 @@ 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 asBucket(value) {
|
|
105
|
+
return isPlainObject(value) ? value : {};
|
|
106
|
+
}
|
|
104
107
|
|
|
105
108
|
// src/components/block-context.ts
|
|
106
109
|
function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
|
|
@@ -116,69 +119,6 @@ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, for
|
|
|
116
119
|
...extra?.workspace ? { workspace: extra.workspace } : {}
|
|
117
120
|
};
|
|
118
121
|
}
|
|
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
122
|
var WARN_CAP = 256;
|
|
183
123
|
var warned = /* @__PURE__ */ new Set();
|
|
184
124
|
function UnknownBlock({ type }) {
|
|
@@ -192,26 +132,25 @@ function UnknownBlock({ type }) {
|
|
|
192
132
|
function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
|
|
193
133
|
const { context, data, resolvedContent, enabledLocales } = options;
|
|
194
134
|
const Component = Object.hasOwn(map, block.type) ? map[block.type] : void 0;
|
|
195
|
-
const attrs = resolveBlockAttrs(block.id, block.style, block.advanced);
|
|
196
|
-
if (attrs.hidden) return null;
|
|
197
135
|
const content = resolvedContent ?? getBlockContentForLanguage(
|
|
198
136
|
block.content,
|
|
199
137
|
locale,
|
|
200
138
|
defaultLocale,
|
|
201
139
|
enabledLocales?.length ? enabledLocales : void 0
|
|
202
140
|
);
|
|
203
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
141
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
204
142
|
"div",
|
|
205
143
|
{
|
|
206
144
|
"data-block-id": block.id,
|
|
207
145
|
"data-block-type": block.type,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
146
|
+
style: Component ? void 0 : { display: "none" },
|
|
147
|
+
children: Component ? react.createElement(Component, {
|
|
148
|
+
content,
|
|
149
|
+
style: asBucket(block.style),
|
|
150
|
+
advanced: asBucket(block.advanced),
|
|
151
|
+
context,
|
|
152
|
+
data
|
|
153
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
215
154
|
},
|
|
216
155
|
block.id
|
|
217
156
|
);
|
|
@@ -958,24 +897,22 @@ function CmssyBlock({
|
|
|
958
897
|
context
|
|
959
898
|
}) {
|
|
960
899
|
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
900
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
964
901
|
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
965
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
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
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
909
|
+
style: Component ? void 0 : { display: "none" },
|
|
910
|
+
children: Component ? react.createElement(Component, {
|
|
911
|
+
content,
|
|
912
|
+
style: asBucket(block.style),
|
|
913
|
+
advanced: asBucket(block.advanced),
|
|
914
|
+
context
|
|
915
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
979
916
|
}
|
|
980
917
|
);
|
|
981
918
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, n as CmssyBlockAuthContext, o as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, p as FetchLike, q as CmssyClientConfig, r as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, s as BlockMap, t as CmssyBlockContext } from './commerce-queries-
|
|
2
|
-
export { a as BlockMeta, u as BlockRect, B as BlockSchema, v as BoundsMessage, w as BuildBlockContextExtra, x as ClickMessage, y as CmssyBlockMember, z as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, D as CmssyFormField, G as CmssyFormSettings, H as CmssyFormSubmitResponse, I as CmssyLocalizedValue, J as CmssyModelDefinition, K as CmssyModelRecord, g as CmssyOrder, L as CmssyPageMeta, M as CmssyPageSummary, h as CmssyProduct, m as CmssyProductVariant, N as CmssyRecordList, O as DEFAULT_CMSSY_API_URL, P as FORM_QUERY, Q as FetchLikeResponse, S as FetchPageOptions, T as MODEL_DEFINITIONS_QUERY, U as MODEL_RECORDS_QUERY, V as PROTOCOL_VERSION, W as ParentReadyMessage, X as PatchMessage, Y as RawLayoutBlock, Z as ReadyMessage, _ as SITE_CONFIG_QUERY, $ as SUBMIT_FORM_MUTATION, a0 as SelectMessage, a1 as SubmitFormInput, a2 as blocksToMeta, a3 as blocksToSchemas, a4 as buildBlockContext, a5 as buildBlockMap, a6 as defineBlock, a7 as fetchLayouts, a8 as fetchPage, a9 as fetchPageById, aa as fetchPageMeta, ab as fetchPages, ac as isProtocolCompatible, ad as normalizeSlug, ae as resolveApiUrl } from './commerce-queries-
|
|
1
|
+
import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, n as CmssyBlockAuthContext, o as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, p as FetchLike, q as CmssyClientConfig, r as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, s as BlockMap, t as CmssyBlockContext } from './commerce-queries-D5duQ6QF.cjs';
|
|
2
|
+
export { a as BlockMeta, u as BlockRect, B as BlockSchema, v as BoundsMessage, w as BuildBlockContextExtra, x as ClickMessage, y as CmssyBlockMember, z as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, D as CmssyFormField, G as CmssyFormSettings, H as CmssyFormSubmitResponse, I as CmssyLocalizedValue, J as CmssyModelDefinition, K as CmssyModelRecord, g as CmssyOrder, L as CmssyPageMeta, M as CmssyPageSummary, h as CmssyProduct, m as CmssyProductVariant, N as CmssyRecordList, O as DEFAULT_CMSSY_API_URL, P as FORM_QUERY, Q as FetchLikeResponse, S as FetchPageOptions, T as MODEL_DEFINITIONS_QUERY, U as MODEL_RECORDS_QUERY, V as PROTOCOL_VERSION, W as ParentReadyMessage, X as PatchMessage, Y as RawLayoutBlock, Z as ReadyMessage, _ as SITE_CONFIG_QUERY, $ as SUBMIT_FORM_MUTATION, a0 as SelectMessage, a1 as SubmitFormInput, a2 as blocksToMeta, a3 as blocksToSchemas, a4 as buildBlockContext, a5 as buildBlockMap, a6 as defineBlock, a7 as fetchLayouts, a8 as fetchPage, a9 as fetchPageById, aa as fetchPageMeta, ab as fetchPages, ac as isProtocolCompatible, ad as normalizeSlug, ae as resolveApiUrl } from './commerce-queries-D5duQ6QF.cjs';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
export { FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldType, evaluateFieldConditionGroup } from '@cmssy/types';
|
|
5
5
|
import 'react';
|
|
@@ -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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, n as CmssyBlockAuthContext, o as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, p as FetchLike, q as CmssyClientConfig, r as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, s as BlockMap, t as CmssyBlockContext } from './commerce-queries-
|
|
2
|
-
export { a as BlockMeta, u as BlockRect, B as BlockSchema, v as BoundsMessage, w as BuildBlockContextExtra, x as ClickMessage, y as CmssyBlockMember, z as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, D as CmssyFormField, G as CmssyFormSettings, H as CmssyFormSubmitResponse, I as CmssyLocalizedValue, J as CmssyModelDefinition, K as CmssyModelRecord, g as CmssyOrder, L as CmssyPageMeta, M as CmssyPageSummary, h as CmssyProduct, m as CmssyProductVariant, N as CmssyRecordList, O as DEFAULT_CMSSY_API_URL, P as FORM_QUERY, Q as FetchLikeResponse, S as FetchPageOptions, T as MODEL_DEFINITIONS_QUERY, U as MODEL_RECORDS_QUERY, V as PROTOCOL_VERSION, W as ParentReadyMessage, X as PatchMessage, Y as RawLayoutBlock, Z as ReadyMessage, _ as SITE_CONFIG_QUERY, $ as SUBMIT_FORM_MUTATION, a0 as SelectMessage, a1 as SubmitFormInput, a2 as blocksToMeta, a3 as blocksToSchemas, a4 as buildBlockContext, a5 as buildBlockMap, a6 as defineBlock, a7 as fetchLayouts, a8 as fetchPage, a9 as fetchPageById, aa as fetchPageMeta, ab as fetchPages, ac as isProtocolCompatible, ad as normalizeSlug, ae as resolveApiUrl } from './commerce-queries-
|
|
1
|
+
import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, n as CmssyBlockAuthContext, o as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, p as FetchLike, q as CmssyClientConfig, r as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, s as BlockMap, t as CmssyBlockContext } from './commerce-queries-D5duQ6QF.js';
|
|
2
|
+
export { a as BlockMeta, u as BlockRect, B as BlockSchema, v as BoundsMessage, w as BuildBlockContextExtra, x as ClickMessage, y as CmssyBlockMember, z as CmssyBranding, f as CmssyCart, i as CmssyCartDiscount, j as CmssyCartItem, k as CmssyCartItemSnapshot, D as CmssyFormField, G as CmssyFormSettings, H as CmssyFormSubmitResponse, I as CmssyLocalizedValue, J as CmssyModelDefinition, K as CmssyModelRecord, g as CmssyOrder, L as CmssyPageMeta, M as CmssyPageSummary, h as CmssyProduct, m as CmssyProductVariant, N as CmssyRecordList, O as DEFAULT_CMSSY_API_URL, P as FORM_QUERY, Q as FetchLikeResponse, S as FetchPageOptions, T as MODEL_DEFINITIONS_QUERY, U as MODEL_RECORDS_QUERY, V as PROTOCOL_VERSION, W as ParentReadyMessage, X as PatchMessage, Y as RawLayoutBlock, Z as ReadyMessage, _ as SITE_CONFIG_QUERY, $ as SUBMIT_FORM_MUTATION, a0 as SelectMessage, a1 as SubmitFormInput, a2 as blocksToMeta, a3 as blocksToSchemas, a4 as buildBlockContext, a5 as buildBlockMap, a6 as defineBlock, a7 as fetchLayouts, a8 as fetchPage, a9 as fetchPageById, aa as fetchPageMeta, ab as fetchPages, ac as isProtocolCompatible, ad as normalizeSlug, ae as resolveApiUrl } from './commerce-queries-D5duQ6QF.js';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
export { FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldType, evaluateFieldConditionGroup } from '@cmssy/types';
|
|
5
5
|
import 'react';
|
|
@@ -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,9 @@ 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 asBucket(value) {
|
|
103
|
+
return isPlainObject(value) ? value : {};
|
|
104
|
+
}
|
|
102
105
|
|
|
103
106
|
// src/components/block-context.ts
|
|
104
107
|
function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
|
|
@@ -114,69 +117,6 @@ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, for
|
|
|
114
117
|
...extra?.workspace ? { workspace: extra.workspace } : {}
|
|
115
118
|
};
|
|
116
119
|
}
|
|
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
120
|
var WARN_CAP = 256;
|
|
181
121
|
var warned = /* @__PURE__ */ new Set();
|
|
182
122
|
function UnknownBlock({ type }) {
|
|
@@ -190,26 +130,25 @@ function UnknownBlock({ type }) {
|
|
|
190
130
|
function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
|
|
191
131
|
const { context, data, resolvedContent, enabledLocales } = options;
|
|
192
132
|
const Component = Object.hasOwn(map, block.type) ? map[block.type] : void 0;
|
|
193
|
-
const attrs = resolveBlockAttrs(block.id, block.style, block.advanced);
|
|
194
|
-
if (attrs.hidden) return null;
|
|
195
133
|
const content = resolvedContent ?? getBlockContentForLanguage(
|
|
196
134
|
block.content,
|
|
197
135
|
locale,
|
|
198
136
|
defaultLocale,
|
|
199
137
|
enabledLocales?.length ? enabledLocales : void 0
|
|
200
138
|
);
|
|
201
|
-
return /* @__PURE__ */
|
|
139
|
+
return /* @__PURE__ */ jsx(
|
|
202
140
|
"div",
|
|
203
141
|
{
|
|
204
142
|
"data-block-id": block.id,
|
|
205
143
|
"data-block-type": block.type,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
144
|
+
style: Component ? void 0 : { display: "none" },
|
|
145
|
+
children: Component ? createElement(Component, {
|
|
146
|
+
content,
|
|
147
|
+
style: asBucket(block.style),
|
|
148
|
+
advanced: asBucket(block.advanced),
|
|
149
|
+
context,
|
|
150
|
+
data
|
|
151
|
+
}) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
213
152
|
},
|
|
214
153
|
block.id
|
|
215
154
|
);
|
|
@@ -956,24 +895,22 @@ function CmssyBlock({
|
|
|
956
895
|
context
|
|
957
896
|
}) {
|
|
958
897
|
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
898
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
962
899
|
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
963
|
-
return /* @__PURE__ */
|
|
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
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
907
|
+
style: Component ? void 0 : { display: "none" },
|
|
908
|
+
children: Component ? createElement(Component, {
|
|
909
|
+
content,
|
|
910
|
+
style: asBucket(block.style),
|
|
911
|
+
advanced: asBucket(block.advanced),
|
|
912
|
+
context
|
|
913
|
+
}) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
977
914
|
}
|
|
978
915
|
);
|
|
979
916
|
}
|