@cmssy/react 4.7.2 → 5.0.1
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 +51 -260
- package/dist/client.d.cts +6 -9
- package/dist/client.d.ts +6 -9
- package/dist/client.js +5 -225
- package/dist/index.cjs +148 -777
- package/dist/index.d.cts +6 -252
- package/dist/index.d.ts +6 -252
- package/dist/index.js +4 -734
- package/dist/{registry-DBPEDxug.d.cts → registry-DnhIHuzF.d.cts} +1 -1
- package/dist/{registry-DBPEDxug.d.ts → registry-DnhIHuzF.d.ts} +1 -1
- package/package.json +3 -2
package/dist/client.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var react = require('react');
|
|
5
|
+
var core = require('@cmssy/core');
|
|
5
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
7
|
|
|
7
8
|
// src/registry.ts
|
|
@@ -38,100 +39,6 @@ function blocksToMeta(blocks, defaults = {}) {
|
|
|
38
39
|
}
|
|
39
40
|
return out;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
// src/bridge/protocol.ts
|
|
43
|
-
var PROTOCOL_VERSION = 2;
|
|
44
|
-
|
|
45
|
-
// src/bridge/messages.ts
|
|
46
|
-
function normalizeOrigin(origin) {
|
|
47
|
-
const trimmed = origin.trim();
|
|
48
|
-
if (trimmed === "*") return "*";
|
|
49
|
-
try {
|
|
50
|
-
return new URL(trimmed).origin;
|
|
51
|
-
} catch {
|
|
52
|
-
return trimmed;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function postToEditor(target, editorOrigin, message) {
|
|
56
|
-
target.postMessage(message, normalizeOrigin(editorOrigin));
|
|
57
|
-
}
|
|
58
|
-
function isOriginAllowed(origin, allowed) {
|
|
59
|
-
const list = Array.isArray(allowed) ? allowed : [allowed];
|
|
60
|
-
const actual = normalizeOrigin(origin);
|
|
61
|
-
return list.some((candidate) => {
|
|
62
|
-
const expected = normalizeOrigin(candidate);
|
|
63
|
-
return expected === "*" || expected === actual;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function resolveInitialTarget(editorOrigin) {
|
|
67
|
-
const list = (Array.isArray(editorOrigin) ? editorOrigin : [editorOrigin]).map((origin) => normalizeOrigin(origin));
|
|
68
|
-
if (list.includes("*")) return "*";
|
|
69
|
-
if (list.length === 1) return list[0];
|
|
70
|
-
const referrerOrigin = typeof document !== "undefined" && document.referrer ? normalizeOrigin(document.referrer) : "";
|
|
71
|
-
return list.find((origin) => origin === referrerOrigin) ?? list[0];
|
|
72
|
-
}
|
|
73
|
-
function isObject(value) {
|
|
74
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
|
-
}
|
|
76
|
-
function parseEditorMessage(data, origin, expectedOrigin) {
|
|
77
|
-
if (!isOriginAllowed(origin, expectedOrigin)) return null;
|
|
78
|
-
if (!isObject(data)) return null;
|
|
79
|
-
switch (data.type) {
|
|
80
|
-
case "cmssy:select":
|
|
81
|
-
return typeof data.blockId === "string" && data.protocolVersion === PROTOCOL_VERSION ? {
|
|
82
|
-
type: "cmssy:select",
|
|
83
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
84
|
-
blockId: data.blockId
|
|
85
|
-
} : null;
|
|
86
|
-
case "cmssy:patch":
|
|
87
|
-
return typeof data.blockId === "string" && isObject(data.content) && data.protocolVersion === PROTOCOL_VERSION ? {
|
|
88
|
-
type: "cmssy:patch",
|
|
89
|
-
blockId: data.blockId,
|
|
90
|
-
content: data.content,
|
|
91
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
92
|
-
...isObject(data.style) ? { style: data.style } : {},
|
|
93
|
-
...isObject(data.advanced) ? { advanced: data.advanced } : {},
|
|
94
|
-
...typeof data.layoutPosition === "string" ? { layoutPosition: data.layoutPosition } : {}
|
|
95
|
-
} : null;
|
|
96
|
-
case "cmssy:parent-ready":
|
|
97
|
-
return data.protocolVersion === PROTOCOL_VERSION ? { type: "cmssy:parent-ready", protocolVersion: PROTOCOL_VERSION } : null;
|
|
98
|
-
case "cmssy:insert":
|
|
99
|
-
return typeof data.blockId === "string" && typeof data.blockType === "string" && isObject(data.content) && typeof data.index === "number" && data.protocolVersion === PROTOCOL_VERSION ? {
|
|
100
|
-
type: "cmssy:insert",
|
|
101
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
102
|
-
blockId: data.blockId,
|
|
103
|
-
blockType: data.blockType,
|
|
104
|
-
content: data.content,
|
|
105
|
-
...isObject(data.style) ? { style: data.style } : {},
|
|
106
|
-
...isObject(data.advanced) ? { advanced: data.advanced } : {},
|
|
107
|
-
index: data.index
|
|
108
|
-
} : null;
|
|
109
|
-
case "cmssy:reorder":
|
|
110
|
-
return Array.isArray(data.blockIds) && data.blockIds.every((id) => typeof id === "string") && data.protocolVersion === PROTOCOL_VERSION ? {
|
|
111
|
-
type: "cmssy:reorder",
|
|
112
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
113
|
-
blockIds: data.blockIds
|
|
114
|
-
} : null;
|
|
115
|
-
case "cmssy:remove":
|
|
116
|
-
return typeof data.blockId === "string" && data.protocolVersion === PROTOCOL_VERSION ? {
|
|
117
|
-
type: "cmssy:remove",
|
|
118
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
119
|
-
blockId: data.blockId
|
|
120
|
-
} : null;
|
|
121
|
-
case "cmssy:drag-over":
|
|
122
|
-
return typeof data.y === "number" && data.protocolVersion === PROTOCOL_VERSION ? {
|
|
123
|
-
type: "cmssy:drag-over",
|
|
124
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
125
|
-
y: data.y
|
|
126
|
-
} : null;
|
|
127
|
-
case "cmssy:drag-end":
|
|
128
|
-
return data.protocolVersion === PROTOCOL_VERSION ? { type: "cmssy:drag-end", protocolVersion: PROTOCOL_VERSION } : null;
|
|
129
|
-
default:
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/bridge/use-edit-bridge.tsx
|
|
135
42
|
var ZERO_RECT = { x: 0, y: 0, width: 0, height: 0 };
|
|
136
43
|
function collectRects() {
|
|
137
44
|
const rects = /* @__PURE__ */ new Map();
|
|
@@ -201,7 +108,7 @@ function useEditBridge(page, config) {
|
|
|
201
108
|
react.useEffect(() => {
|
|
202
109
|
if (typeof window === "undefined" || window.parent === window) return;
|
|
203
110
|
const { editorOrigin } = config;
|
|
204
|
-
let postTarget = resolveInitialTarget(editorOrigin);
|
|
111
|
+
let postTarget = core.resolveInitialTarget(editorOrigin);
|
|
205
112
|
const isWildcard = Array.isArray(editorOrigin) ? editorOrigin.includes("*") : editorOrigin === "*";
|
|
206
113
|
if (isWildcard && typeof console !== "undefined") {
|
|
207
114
|
console.warn(
|
|
@@ -212,9 +119,9 @@ function useEditBridge(page, config) {
|
|
|
212
119
|
try {
|
|
213
120
|
const rects = collectRects();
|
|
214
121
|
const pageIds = new Set(blocks.map((b) => b.id));
|
|
215
|
-
postToEditor(window.parent, postTarget, {
|
|
122
|
+
core.postToEditor(window.parent, postTarget, {
|
|
216
123
|
type: "cmssy:ready",
|
|
217
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
124
|
+
protocolVersion: core.PROTOCOL_VERSION,
|
|
218
125
|
blocks: [
|
|
219
126
|
...blocks.map((b) => ({
|
|
220
127
|
id: b.id,
|
|
@@ -234,7 +141,7 @@ function useEditBridge(page, config) {
|
|
|
234
141
|
};
|
|
235
142
|
const handler = (event) => {
|
|
236
143
|
if (event.source && event.source !== window.parent) return;
|
|
237
|
-
const message = parseEditorMessage(
|
|
144
|
+
const message = core.parseEditorMessage(
|
|
238
145
|
event.data,
|
|
239
146
|
event.origin,
|
|
240
147
|
editorOrigin
|
|
@@ -302,7 +209,7 @@ function useEditBridge(page, config) {
|
|
|
302
209
|
const r = el.getBoundingClientRect();
|
|
303
210
|
const layoutPosition = el.getAttribute("data-layout-position");
|
|
304
211
|
try {
|
|
305
|
-
postToEditor(window.parent, postTarget, {
|
|
212
|
+
core.postToEditor(window.parent, postTarget, {
|
|
306
213
|
type: "cmssy:click",
|
|
307
214
|
blockId: id,
|
|
308
215
|
rect: { x: r.x, y: r.y, width: r.width, height: r.height },
|
|
@@ -325,7 +232,7 @@ function useEditBridge(page, config) {
|
|
|
325
232
|
if (!el) return;
|
|
326
233
|
const r = el.getBoundingClientRect();
|
|
327
234
|
try {
|
|
328
|
-
postToEditor(window.parent, postTarget, {
|
|
235
|
+
core.postToEditor(window.parent, postTarget, {
|
|
329
236
|
type: "cmssy:bounds",
|
|
330
237
|
blockId: id,
|
|
331
238
|
rect: { x: r.x, y: r.y, width: r.width, height: r.height }
|
|
@@ -415,7 +322,7 @@ function useDragAgent(config) {
|
|
|
415
322
|
react.useEffect(() => {
|
|
416
323
|
if (typeof window === "undefined" || window.parent === window) return;
|
|
417
324
|
const { editorOrigin } = config;
|
|
418
|
-
let postTarget = resolveInitialTarget(editorOrigin);
|
|
325
|
+
let postTarget = core.resolveInitialTarget(editorOrigin);
|
|
419
326
|
const isWildcard = Array.isArray(editorOrigin) ? editorOrigin.includes("*") : editorOrigin === "*";
|
|
420
327
|
if (isWildcard && typeof console !== "undefined") {
|
|
421
328
|
console.warn(
|
|
@@ -453,9 +360,9 @@ function useDragAgent(config) {
|
|
|
453
360
|
updateDropY(null);
|
|
454
361
|
resolver.invalidate();
|
|
455
362
|
try {
|
|
456
|
-
postToEditor(window.parent, postTarget, {
|
|
363
|
+
core.postToEditor(window.parent, postTarget, {
|
|
457
364
|
type: "cmssy:move",
|
|
458
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
365
|
+
protocolVersion: core.PROTOCOL_VERSION,
|
|
459
366
|
blockId,
|
|
460
367
|
index
|
|
461
368
|
});
|
|
@@ -469,7 +376,7 @@ function useDragAgent(config) {
|
|
|
469
376
|
};
|
|
470
377
|
const onMessage = (event) => {
|
|
471
378
|
if (event.source && event.source !== window.parent) return;
|
|
472
|
-
const message = parseEditorMessage(
|
|
379
|
+
const message = core.parseEditorMessage(
|
|
473
380
|
event.data,
|
|
474
381
|
event.origin,
|
|
475
382
|
editorOrigin
|
|
@@ -487,9 +394,9 @@ function useDragAgent(config) {
|
|
|
487
394
|
const { index, y } = resolver.resolve(message.y);
|
|
488
395
|
updateDropY(y);
|
|
489
396
|
try {
|
|
490
|
-
postToEditor(window.parent, postTarget, {
|
|
397
|
+
core.postToEditor(window.parent, postTarget, {
|
|
491
398
|
type: "cmssy:drag-index",
|
|
492
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
399
|
+
protocolVersion: core.PROTOCOL_VERSION,
|
|
493
400
|
index
|
|
494
401
|
});
|
|
495
402
|
} catch {
|
|
@@ -514,48 +421,6 @@ function useDragAgent(config) {
|
|
|
514
421
|
}, [config.editorOrigin]);
|
|
515
422
|
return { dropY };
|
|
516
423
|
}
|
|
517
|
-
|
|
518
|
-
// src/components/block-context.ts
|
|
519
|
-
function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
|
|
520
|
-
return {
|
|
521
|
-
locale: {
|
|
522
|
-
current: locale,
|
|
523
|
-
default: defaultLocale,
|
|
524
|
-
enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
|
|
525
|
-
},
|
|
526
|
-
isPreview: isPreview ?? false,
|
|
527
|
-
forms,
|
|
528
|
-
...{},
|
|
529
|
-
...{}
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// src/content/get-block-content.ts
|
|
534
|
-
function isPlainObject(value) {
|
|
535
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
536
|
-
}
|
|
537
|
-
function looksLikeLocaleKey(key) {
|
|
538
|
-
return /^[a-z]{2}(-[A-Za-z]{2})?$/.test(key);
|
|
539
|
-
}
|
|
540
|
-
function getBlockContentForLanguage(content, locale, defaultLocale = "en", availableLocales) {
|
|
541
|
-
if (!isPlainObject(content)) return {};
|
|
542
|
-
const isLocale = looksLikeLocaleKey;
|
|
543
|
-
const localeEntries = Object.entries(content).filter(
|
|
544
|
-
([key, value]) => isLocale(key) && isPlainObject(value)
|
|
545
|
-
);
|
|
546
|
-
if (localeEntries.length === 0) return { ...content };
|
|
547
|
-
const localeMap = Object.fromEntries(localeEntries);
|
|
548
|
-
const nonTranslatable = {};
|
|
549
|
-
for (const [key, value] of Object.entries(content)) {
|
|
550
|
-
if (!(isLocale(key) && isPlainObject(value))) nonTranslatable[key] = value;
|
|
551
|
-
}
|
|
552
|
-
const fallbackKey = Object.keys(localeMap)[0];
|
|
553
|
-
const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
|
|
554
|
-
return { ...nonTranslatable, ...chosen };
|
|
555
|
-
}
|
|
556
|
-
function asBucket(value) {
|
|
557
|
-
return isPlainObject(value) ? value : {};
|
|
558
|
-
}
|
|
559
424
|
var WARN_CAP = 256;
|
|
560
425
|
var warned = /* @__PURE__ */ new Set();
|
|
561
426
|
function UnknownBlock({ type }) {
|
|
@@ -579,10 +444,10 @@ function CmssyBlock({
|
|
|
579
444
|
context
|
|
580
445
|
}) {
|
|
581
446
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
582
|
-
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
447
|
+
const base = core.getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
583
448
|
const content = patchedContent ? { ...base, ...patchedContent } : base;
|
|
584
|
-
const style = patchedStyle ? { ...asBucket(block.style), ...patchedStyle } : asBucket(block.style);
|
|
585
|
-
const advanced = patchedAdvanced ? { ...asBucket(block.advanced), ...patchedAdvanced } : asBucket(block.advanced);
|
|
449
|
+
const style = patchedStyle ? { ...core.asBucket(block.style), ...patchedStyle } : core.asBucket(block.style);
|
|
450
|
+
const advanced = patchedAdvanced ? { ...core.asBucket(block.advanced), ...patchedAdvanced } : core.asBucket(block.advanced);
|
|
586
451
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
587
452
|
"div",
|
|
588
453
|
{
|
|
@@ -642,7 +507,7 @@ function EditableBlocks({
|
|
|
642
507
|
}) {
|
|
643
508
|
const blockMap = react.useMemo(() => buildBlockMap(blocks), [blocks]);
|
|
644
509
|
const context = react.useMemo(
|
|
645
|
-
() => buildBlockContext(locale, defaultLocale, enabledLocales, true, forms),
|
|
510
|
+
() => core.buildBlockContext(locale, defaultLocale, enabledLocales, true, forms),
|
|
646
511
|
[locale, defaultLocale, enabledLocales, forms]
|
|
647
512
|
);
|
|
648
513
|
const bridgeConfig = react.useMemo(
|
|
@@ -754,7 +619,7 @@ function useLayoutPatchBridge(position, config) {
|
|
|
754
619
|
const { editorOrigin } = config;
|
|
755
620
|
const handler = (event) => {
|
|
756
621
|
if (event.source && event.source !== window.parent) return;
|
|
757
|
-
const message = parseEditorMessage(
|
|
622
|
+
const message = core.parseEditorMessage(
|
|
758
623
|
event.data,
|
|
759
624
|
event.origin,
|
|
760
625
|
editorOrigin
|
|
@@ -788,7 +653,7 @@ function CmssyEditableLayout({
|
|
|
788
653
|
}, [groups, position]);
|
|
789
654
|
const patches = useLayoutPatchBridge(position, edit);
|
|
790
655
|
const context = react.useMemo(
|
|
791
|
-
() => buildBlockContext(locale, defaultLocale, enabledLocales, true),
|
|
656
|
+
() => core.buildBlockContext(locale, defaultLocale, enabledLocales, true),
|
|
792
657
|
[locale, defaultLocale, enabledLocales]
|
|
793
658
|
);
|
|
794
659
|
if (layoutBlocks.length === 0) return null;
|
|
@@ -903,11 +768,11 @@ function CmssyAuthProvider({
|
|
|
903
768
|
[postAction, commitUser]
|
|
904
769
|
);
|
|
905
770
|
const register = react.useCallback(
|
|
906
|
-
async (identity, password,
|
|
771
|
+
async (identity, password, fields3) => {
|
|
907
772
|
const data = await postAction("register", {
|
|
908
773
|
identity,
|
|
909
774
|
password,
|
|
910
|
-
fields:
|
|
775
|
+
fields: fields3 ?? {}
|
|
911
776
|
});
|
|
912
777
|
return { ok: Boolean(data.ok), message: data.message };
|
|
913
778
|
},
|
|
@@ -1100,92 +965,6 @@ function useCart() {
|
|
|
1100
965
|
}
|
|
1101
966
|
return ctx;
|
|
1102
967
|
}
|
|
1103
|
-
|
|
1104
|
-
// src/fields.ts
|
|
1105
|
-
function control(type) {
|
|
1106
|
-
return (opts = {}) => ({
|
|
1107
|
-
type,
|
|
1108
|
-
label: opts.label ?? "",
|
|
1109
|
-
...opts
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
var fields = {
|
|
1113
|
-
text: control("text"),
|
|
1114
|
-
textarea: control("textarea"),
|
|
1115
|
-
richText: control("richText"),
|
|
1116
|
-
markdown: control("markdown"),
|
|
1117
|
-
number: control("number"),
|
|
1118
|
-
date: control("date"),
|
|
1119
|
-
datetime: control("datetime"),
|
|
1120
|
-
boolean: control("boolean"),
|
|
1121
|
-
color: control("color"),
|
|
1122
|
-
media: control("media"),
|
|
1123
|
-
link: control("link"),
|
|
1124
|
-
url: control("url"),
|
|
1125
|
-
email: control("email"),
|
|
1126
|
-
select: control("select"),
|
|
1127
|
-
multiselect: control("multiselect"),
|
|
1128
|
-
radio: control("radio"),
|
|
1129
|
-
repeater: control("repeater"),
|
|
1130
|
-
table: control("table"),
|
|
1131
|
-
json: control("json"),
|
|
1132
|
-
form: control("form"),
|
|
1133
|
-
pageSelector: control("pageSelector")
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
|
-
// src/commerce/money.ts
|
|
1137
|
-
var ZERO_DECIMAL = /* @__PURE__ */ new Set([
|
|
1138
|
-
"BIF",
|
|
1139
|
-
"CLP",
|
|
1140
|
-
"DJF",
|
|
1141
|
-
"GNF",
|
|
1142
|
-
"JPY",
|
|
1143
|
-
"KMF",
|
|
1144
|
-
"KRW",
|
|
1145
|
-
"MGA",
|
|
1146
|
-
"PYG",
|
|
1147
|
-
"RWF",
|
|
1148
|
-
"UGX",
|
|
1149
|
-
"VND",
|
|
1150
|
-
"VUV",
|
|
1151
|
-
"XAF",
|
|
1152
|
-
"XOF",
|
|
1153
|
-
"XPF"
|
|
1154
|
-
]);
|
|
1155
|
-
var THREE_DECIMAL = /* @__PURE__ */ new Set([
|
|
1156
|
-
"BHD",
|
|
1157
|
-
"IQD",
|
|
1158
|
-
"JOD",
|
|
1159
|
-
"KWD",
|
|
1160
|
-
"LYD",
|
|
1161
|
-
"OMR",
|
|
1162
|
-
"TND"
|
|
1163
|
-
]);
|
|
1164
|
-
function fractionDigits(currency) {
|
|
1165
|
-
const code = currency.toUpperCase();
|
|
1166
|
-
if (ZERO_DECIMAL.has(code)) return 0;
|
|
1167
|
-
if (THREE_DECIMAL.has(code)) return 3;
|
|
1168
|
-
return 2;
|
|
1169
|
-
}
|
|
1170
|
-
function fromMinorUnits(minor, currency) {
|
|
1171
|
-
return minor / 10 ** fractionDigits(currency);
|
|
1172
|
-
}
|
|
1173
|
-
function toMinorUnits(amount, currency) {
|
|
1174
|
-
return Math.round(amount * 10 ** fractionDigits(currency));
|
|
1175
|
-
}
|
|
1176
|
-
function formatPrice(minor, currency) {
|
|
1177
|
-
if (!Number.isFinite(minor)) return "";
|
|
1178
|
-
const code = currency ?? "USD";
|
|
1179
|
-
const amount = fromMinorUnits(minor, code);
|
|
1180
|
-
try {
|
|
1181
|
-
return new Intl.NumberFormat(void 0, {
|
|
1182
|
-
style: "currency",
|
|
1183
|
-
currency: code
|
|
1184
|
-
}).format(amount);
|
|
1185
|
-
} catch {
|
|
1186
|
-
return `${amount.toFixed(fractionDigits(code))} ${code}`;
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
968
|
function deriveAxes(variants) {
|
|
1190
969
|
const axes = /* @__PURE__ */ new Map();
|
|
1191
970
|
for (const variant of variants) {
|
|
@@ -1254,7 +1033,7 @@ function ProductComponent({ content }) {
|
|
|
1254
1033
|
const imageUrl = c.imageField ? data[c.imageField] : null;
|
|
1255
1034
|
const hasVariants = product.variants.length > 0;
|
|
1256
1035
|
const currency = data.currency ?? "USD";
|
|
1257
|
-
const priceMinor = hasVariants ? variant?.price : toMinorUnits(Number(data[c.priceField ?? "price"] ?? 0), currency);
|
|
1036
|
+
const priceMinor = hasVariants ? variant?.price : core.toMinorUnits(Number(data[c.priceField ?? "price"] ?? 0), currency);
|
|
1258
1037
|
const showPrice = priceMinor != null && Number.isFinite(priceMinor);
|
|
1259
1038
|
const allAxesSelected = axes.every((axis) => selections[axis.name]);
|
|
1260
1039
|
const outOfStock = variant != null && variant.inventory != null && variant.inventory <= 0;
|
|
@@ -1280,7 +1059,7 @@ function ProductComponent({ content }) {
|
|
|
1280
1059
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-cmssy-product": product.id, children: [
|
|
1281
1060
|
imageUrl ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: imageUrl, alt: name }) : null,
|
|
1282
1061
|
/* @__PURE__ */ jsxRuntime.jsx("h3", { "data-cmssy-product-name": true, children: name }),
|
|
1283
|
-
showPrice ? /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cmssy-product-price": true, children: formatPrice(priceMinor, currency) }) : null,
|
|
1062
|
+
showPrice ? /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cmssy-product-price": true, children: core.formatPrice(priceMinor, currency) }) : null,
|
|
1284
1063
|
axes.map((axis) => /* @__PURE__ */ jsxRuntime.jsxs("label", { "data-cmssy-variant-axis": axis.name, children: [
|
|
1285
1064
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: axis.name }),
|
|
1286
1065
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -1316,12 +1095,12 @@ var productBlock = defineBlock({
|
|
|
1316
1095
|
label: "Product",
|
|
1317
1096
|
category: "Commerce",
|
|
1318
1097
|
props: {
|
|
1319
|
-
modelSlug: fields.text({ label: "Model slug" }),
|
|
1320
|
-
slugField: fields.text({ label: "Slug field" }),
|
|
1321
|
-
slug: fields.text({ label: "Product slug" }),
|
|
1322
|
-
nameField: fields.text({ label: "Name field" }),
|
|
1323
|
-
priceField: fields.text({ label: "Price field" }),
|
|
1324
|
-
imageField: fields.text({ label: "Image field" })
|
|
1098
|
+
modelSlug: core.fields.text({ label: "Model slug" }),
|
|
1099
|
+
slugField: core.fields.text({ label: "Slug field" }),
|
|
1100
|
+
slug: core.fields.text({ label: "Product slug" }),
|
|
1101
|
+
nameField: core.fields.text({ label: "Name field" }),
|
|
1102
|
+
priceField: core.fields.text({ label: "Price field" }),
|
|
1103
|
+
imageField: core.fields.text({ label: "Image field" })
|
|
1325
1104
|
},
|
|
1326
1105
|
component: ProductComponent
|
|
1327
1106
|
});
|
|
@@ -1374,7 +1153,7 @@ function CartComponent() {
|
|
|
1374
1153
|
"data-cmssy-item-qty": true
|
|
1375
1154
|
}
|
|
1376
1155
|
),
|
|
1377
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { "data-cmssy-item-price": true, children: formatPrice(item.snapshot.price * item.quantity, currency) }),
|
|
1156
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "data-cmssy-item-price": true, children: core.formatPrice(item.snapshot.price * item.quantity, currency) }),
|
|
1378
1157
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1379
1158
|
"button",
|
|
1380
1159
|
{
|
|
@@ -1424,11 +1203,11 @@ function CartComponent() {
|
|
|
1424
1203
|
/* @__PURE__ */ jsxRuntime.jsxs("dl", { "data-cmssy-cart-totals": true, children: [
|
|
1425
1204
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1426
1205
|
/* @__PURE__ */ jsxRuntime.jsx("dt", { children: "Subtotal" }),
|
|
1427
|
-
/* @__PURE__ */ jsxRuntime.jsx("dd", { children: formatPrice(cart.subtotal, currency) })
|
|
1206
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { children: core.formatPrice(cart.subtotal, currency) })
|
|
1428
1207
|
] }),
|
|
1429
1208
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1430
1209
|
/* @__PURE__ */ jsxRuntime.jsx("dt", { children: "Total" }),
|
|
1431
|
-
/* @__PURE__ */ jsxRuntime.jsx("dd", { "data-cmssy-cart-total": true, children: formatPrice(cart.discountedTotal, currency) })
|
|
1210
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { "data-cmssy-cart-total": true, children: core.formatPrice(cart.discountedTotal, currency) })
|
|
1432
1211
|
] })
|
|
1433
1212
|
] })
|
|
1434
1213
|
] });
|
|
@@ -1452,7 +1231,7 @@ function CheckoutComponent({ content }) {
|
|
|
1452
1231
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-cmssy-checkout": "done", children: [
|
|
1453
1232
|
/* @__PURE__ */ jsxRuntime.jsx("p", { children: c.successMessage ?? "Order placed - awaiting payment." }),
|
|
1454
1233
|
/* @__PURE__ */ jsxRuntime.jsx("p", { "data-cmssy-order-id": true, children: order.id }),
|
|
1455
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { "data-cmssy-order-total": true, children: formatPrice(order.total, order.currency) })
|
|
1234
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { "data-cmssy-order-total": true, children: core.formatPrice(order.total, order.currency) })
|
|
1456
1235
|
] });
|
|
1457
1236
|
}
|
|
1458
1237
|
if (loading) {
|
|
@@ -1496,7 +1275,7 @@ function CheckoutComponent({ content }) {
|
|
|
1496
1275
|
}
|
|
1497
1276
|
)
|
|
1498
1277
|
] }),
|
|
1499
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { "data-cmssy-checkout-total": true, children: formatPrice(cart.discountedTotal, cart.currency ?? "USD") }),
|
|
1278
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { "data-cmssy-checkout-total": true, children: core.formatPrice(cart.discountedTotal, cart.currency ?? "USD") }),
|
|
1500
1279
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1501
1280
|
"button",
|
|
1502
1281
|
{
|
|
@@ -1515,7 +1294,7 @@ var checkoutBlock = defineBlock({
|
|
|
1515
1294
|
label: "Checkout",
|
|
1516
1295
|
category: "Commerce",
|
|
1517
1296
|
props: {
|
|
1518
|
-
successMessage: fields.text({ label: "Success message" })
|
|
1297
|
+
successMessage: core.fields.text({ label: "Success message" })
|
|
1519
1298
|
},
|
|
1520
1299
|
component: CheckoutComponent
|
|
1521
1300
|
});
|
|
@@ -1608,6 +1387,22 @@ function useCmssyOrder(id, options = {}) {
|
|
|
1608
1387
|
return { order, loading, error, refresh: load };
|
|
1609
1388
|
}
|
|
1610
1389
|
|
|
1390
|
+
Object.defineProperty(exports, "formatPrice", {
|
|
1391
|
+
enumerable: true,
|
|
1392
|
+
get: function () { return core.formatPrice; }
|
|
1393
|
+
});
|
|
1394
|
+
Object.defineProperty(exports, "fractionDigits", {
|
|
1395
|
+
enumerable: true,
|
|
1396
|
+
get: function () { return core.fractionDigits; }
|
|
1397
|
+
});
|
|
1398
|
+
Object.defineProperty(exports, "fromMinorUnits", {
|
|
1399
|
+
enumerable: true,
|
|
1400
|
+
get: function () { return core.fromMinorUnits; }
|
|
1401
|
+
});
|
|
1402
|
+
Object.defineProperty(exports, "toMinorUnits", {
|
|
1403
|
+
enumerable: true,
|
|
1404
|
+
get: function () { return core.toMinorUnits; }
|
|
1405
|
+
});
|
|
1611
1406
|
exports.CmssyAuthProvider = CmssyAuthProvider;
|
|
1612
1407
|
exports.CmssyCommerceProvider = CmssyCommerceProvider;
|
|
1613
1408
|
exports.CmssyEditableLayout = CmssyEditableLayout;
|
|
@@ -1617,11 +1412,7 @@ exports.CmssyLazyLayout = CmssyLazyLayout;
|
|
|
1617
1412
|
exports.CmssyLocaleProvider = CmssyLocaleProvider;
|
|
1618
1413
|
exports.cartBlock = cartBlock;
|
|
1619
1414
|
exports.checkoutBlock = checkoutBlock;
|
|
1620
|
-
exports.formatPrice = formatPrice;
|
|
1621
|
-
exports.fractionDigits = fractionDigits;
|
|
1622
|
-
exports.fromMinorUnits = fromMinorUnits;
|
|
1623
1415
|
exports.productBlock = productBlock;
|
|
1624
|
-
exports.toMinorUnits = toMinorUnits;
|
|
1625
1416
|
exports.useCart = useCart;
|
|
1626
1417
|
exports.useCmssyLocale = useCmssyLocale;
|
|
1627
1418
|
exports.useCmssyOrder = useCmssyOrder;
|
package/dist/client.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { BlockSchema, BlockMeta, CmssyPageData, CmssyFormDefinition, CmssyLayoutGroup, CmssyLocaleContext
|
|
3
|
-
export {
|
|
4
|
-
import { B as BlockDefinition } from './registry-
|
|
2
|
+
import { BlockSchema, BlockMeta, CmssyPageData, CmssyFormDefinition, CmssyLayoutGroup, CmssyLocaleContext } from '@cmssy/core';
|
|
3
|
+
export { CmssyCart, CmssyCartDiscount, CmssyCartItem, CmssyCartItemSnapshot, CmssyOrder, CmssyOrderItem, CmssyProduct, CmssyProductVariant, formatPrice, fractionDigits, fromMinorUnits, toMinorUnits } from '@cmssy/core';
|
|
4
|
+
import { B as BlockDefinition } from './registry-DnhIHuzF.cjs';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
|
+
import { CmssyAuthUser, CmssyAuthActionResult, CmssyCart, CmssyAddToCartOptions, CmssyCheckoutInput, CmssyOrder, CmssyProduct, UseCmssyOrderOptions, UseCmssyOrdersOptions } from '@cmssy/types';
|
|
7
|
+
export { CmssyAddToCartOptions, CmssyAuthActionResult, CmssyAuthUser, CmssyCheckoutInput, UseCmssyOrderOptions, UseCmssyOrdersOptions } from '@cmssy/types';
|
|
6
8
|
|
|
7
9
|
interface EditBridgeConfig {
|
|
8
10
|
editorOrigin: string | string[];
|
|
@@ -161,9 +163,4 @@ interface CmssyOrderState {
|
|
|
161
163
|
}
|
|
162
164
|
declare function useCmssyOrder(id: string | null | undefined, options?: UseCmssyOrderOptions): CmssyOrderState;
|
|
163
165
|
|
|
164
|
-
|
|
165
|
-
declare function fromMinorUnits(minor: number, currency: string): number;
|
|
166
|
-
declare function toMinorUnits(amount: number, currency: string): number;
|
|
167
|
-
declare function formatPrice(minor: number, currency: string | null | undefined): string;
|
|
168
|
-
|
|
169
|
-
export { CmssyAuthProvider, type CmssyAuthProviderProps, type CmssyAuthState, CmssyCommerceProvider, type CmssyCommerceProviderProps, type CmssyCommerceState, CmssyEditableLayout, type CmssyEditableLayoutProps, CmssyEditablePage, type CmssyEditablePageProps, CmssyLazyEditor, type CmssyLazyEditorProps, CmssyLazyLayout, type CmssyLazyLayoutProps, CmssyLocaleProvider, type CmssyLocaleProviderProps, type CmssyOrderState, type CmssyOrdersState, type EditBridgeConfig, type EditBridgeState, type PatchMap, cartBlock, checkoutBlock, formatPrice, fractionDigits, fromMinorUnits, productBlock, toMinorUnits, useCart, useCmssyLocale, useCmssyOrder, useCmssyOrders, useCmssyUser, useEditBridge };
|
|
166
|
+
export { CmssyAuthProvider, type CmssyAuthProviderProps, type CmssyAuthState, CmssyCommerceProvider, type CmssyCommerceProviderProps, type CmssyCommerceState, CmssyEditableLayout, type CmssyEditableLayoutProps, CmssyEditablePage, type CmssyEditablePageProps, CmssyLazyEditor, type CmssyLazyEditorProps, CmssyLazyLayout, type CmssyLazyLayoutProps, CmssyLocaleProvider, type CmssyLocaleProviderProps, type CmssyOrderState, type CmssyOrdersState, type EditBridgeConfig, type EditBridgeState, type PatchMap, cartBlock, checkoutBlock, productBlock, useCart, useCmssyLocale, useCmssyOrder, useCmssyOrders, useCmssyUser, useEditBridge };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { BlockSchema, BlockMeta, CmssyPageData, CmssyFormDefinition, CmssyLayoutGroup, CmssyLocaleContext
|
|
3
|
-
export {
|
|
4
|
-
import { B as BlockDefinition } from './registry-
|
|
2
|
+
import { BlockSchema, BlockMeta, CmssyPageData, CmssyFormDefinition, CmssyLayoutGroup, CmssyLocaleContext } from '@cmssy/core';
|
|
3
|
+
export { CmssyCart, CmssyCartDiscount, CmssyCartItem, CmssyCartItemSnapshot, CmssyOrder, CmssyOrderItem, CmssyProduct, CmssyProductVariant, formatPrice, fractionDigits, fromMinorUnits, toMinorUnits } from '@cmssy/core';
|
|
4
|
+
import { B as BlockDefinition } from './registry-DnhIHuzF.js';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
|
+
import { CmssyAuthUser, CmssyAuthActionResult, CmssyCart, CmssyAddToCartOptions, CmssyCheckoutInput, CmssyOrder, CmssyProduct, UseCmssyOrderOptions, UseCmssyOrdersOptions } from '@cmssy/types';
|
|
7
|
+
export { CmssyAddToCartOptions, CmssyAuthActionResult, CmssyAuthUser, CmssyCheckoutInput, UseCmssyOrderOptions, UseCmssyOrdersOptions } from '@cmssy/types';
|
|
6
8
|
|
|
7
9
|
interface EditBridgeConfig {
|
|
8
10
|
editorOrigin: string | string[];
|
|
@@ -161,9 +163,4 @@ interface CmssyOrderState {
|
|
|
161
163
|
}
|
|
162
164
|
declare function useCmssyOrder(id: string | null | undefined, options?: UseCmssyOrderOptions): CmssyOrderState;
|
|
163
165
|
|
|
164
|
-
|
|
165
|
-
declare function fromMinorUnits(minor: number, currency: string): number;
|
|
166
|
-
declare function toMinorUnits(amount: number, currency: string): number;
|
|
167
|
-
declare function formatPrice(minor: number, currency: string | null | undefined): string;
|
|
168
|
-
|
|
169
|
-
export { CmssyAuthProvider, type CmssyAuthProviderProps, type CmssyAuthState, CmssyCommerceProvider, type CmssyCommerceProviderProps, type CmssyCommerceState, CmssyEditableLayout, type CmssyEditableLayoutProps, CmssyEditablePage, type CmssyEditablePageProps, CmssyLazyEditor, type CmssyLazyEditorProps, CmssyLazyLayout, type CmssyLazyLayoutProps, CmssyLocaleProvider, type CmssyLocaleProviderProps, type CmssyOrderState, type CmssyOrdersState, type EditBridgeConfig, type EditBridgeState, type PatchMap, cartBlock, checkoutBlock, formatPrice, fractionDigits, fromMinorUnits, productBlock, toMinorUnits, useCart, useCmssyLocale, useCmssyOrder, useCmssyOrders, useCmssyUser, useEditBridge };
|
|
166
|
+
export { CmssyAuthProvider, type CmssyAuthProviderProps, type CmssyAuthState, CmssyCommerceProvider, type CmssyCommerceProviderProps, type CmssyCommerceState, CmssyEditableLayout, type CmssyEditableLayoutProps, CmssyEditablePage, type CmssyEditablePageProps, CmssyLazyEditor, type CmssyLazyEditorProps, CmssyLazyLayout, type CmssyLazyLayoutProps, CmssyLocaleProvider, type CmssyLocaleProviderProps, type CmssyOrderState, type CmssyOrdersState, type EditBridgeConfig, type EditBridgeState, type PatchMap, cartBlock, checkoutBlock, productBlock, useCart, useCmssyLocale, useCmssyOrder, useCmssyOrders, useCmssyUser, useEditBridge };
|