@enyxs/wikex-components 0.11.46 → 0.11.47
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/README.md +4 -0
- package/assets/partner-assets/broker-close.svg +11 -0
- package/assets/partner-assets/broker-dropdown.svg +5 -0
- package/assets/partner-assets/broker-light-large.svg +16 -0
- package/assets/partner-assets/broker-light-small.svg +16 -0
- package/assets/partner-assets/broker-option-selected.svg +6 -0
- package/assets/partner-assets/broker-upload-plus.svg +5 -0
- package/dist/chrome-model.d.mts +1 -1
- package/dist/chrome-model.d.ts +1 -1
- package/dist/consultation-model.d.mts +10 -1
- package/dist/consultation-model.d.ts +10 -1
- package/dist/index.d.mts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +2677 -1817
- package/dist/index.mjs +2437 -1598
- package/dist/layout-model.d.mts +57 -0
- package/dist/layout-model.d.ts +57 -0
- package/dist/layout-model.js +346 -0
- package/dist/layout-model.mjs +300 -0
- package/dist/manifest.json +366 -16
- package/dist/page-templates.js +2 -3
- package/dist/page-templates.mjs +2 -3
- package/dist/partner.d.mts +2 -2
- package/dist/partner.d.ts +2 -2
- package/dist/partner.js +993 -378
- package/dist/partner.mjs +989 -374
- package/dist/{types-BAA7ZHwV.d.mts → types-BZB7u3ZZ.d.mts} +4 -0
- package/dist/{types-CfkAIdsg.d.ts → types-t5i1N00U.d.ts} +4 -0
- package/package.json +15 -5
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Persisted presentation profiles. Content and semantic text metadata remain shared. */
|
|
2
|
+
declare class CmsLayoutValidationError extends Error {
|
|
3
|
+
}
|
|
4
|
+
type CmsDevice = 'desktop' | 'tablet' | 'mobile';
|
|
5
|
+
declare const CMS_DEVICES: CmsDevice[];
|
|
6
|
+
declare const CMS_DEVICE_WIDTHS: {
|
|
7
|
+
readonly desktop: 1440;
|
|
8
|
+
readonly tablet: 768;
|
|
9
|
+
readonly mobile: 390;
|
|
10
|
+
};
|
|
11
|
+
declare const CMS_DEVICE_MEDIA: {
|
|
12
|
+
readonly desktop: "(min-width:1024px)";
|
|
13
|
+
readonly tablet: "(min-width:768px) and (max-width:1023.98px)";
|
|
14
|
+
readonly mobile: "(max-width:767.98px)";
|
|
15
|
+
};
|
|
16
|
+
declare const CMS_LAYOUT_KEYS: {
|
|
17
|
+
readonly desktop: "__cmsLayoutDesktop";
|
|
18
|
+
readonly tablet: "__cmsLayoutTablet";
|
|
19
|
+
readonly mobile: "__cmsLayoutMobile";
|
|
20
|
+
};
|
|
21
|
+
declare const CMS_ITEM_ID = "__cmsItemId";
|
|
22
|
+
type RecordValue = Record<string, unknown>;
|
|
23
|
+
type CmsLayoutProfile = Record<string, string>;
|
|
24
|
+
type CmsLayoutField = {
|
|
25
|
+
key: string;
|
|
26
|
+
type: string;
|
|
27
|
+
itemFields?: CmsLayoutField[];
|
|
28
|
+
};
|
|
29
|
+
declare function cmsDevice(width: number): CmsDevice;
|
|
30
|
+
declare function isCmsLayoutField(key: string): boolean;
|
|
31
|
+
declare function cmsVisualValue(key: string, value: unknown): string;
|
|
32
|
+
declare function cmsLayoutProfile(record: RecordValue, device: CmsDevice): CmsLayoutProfile;
|
|
33
|
+
declare function cmsLayoutManaged(record: RecordValue, key: string): boolean;
|
|
34
|
+
declare function cmsLayoutValue(record: RecordValue, key: string, device: CmsDevice): string;
|
|
35
|
+
/** Pass device only to editor controls. Public/rendering uses media-scoped styles. */
|
|
36
|
+
declare function projectCmsLayoutContent<T extends RecordValue>(content: T, device?: CmsDevice, fields?: CmsLayoutField[]): T;
|
|
37
|
+
declare function applyCmsLayoutEdit<T extends RecordValue>(content: T, field: string, value: unknown, device: CmsDevice, fields?: CmsLayoutField[]): T;
|
|
38
|
+
declare function cmsLayoutHash(value: string): string;
|
|
39
|
+
declare function cmsTextLayoutId(value: unknown): string | undefined;
|
|
40
|
+
declare function cmsResponsiveTextCss(content: RecordValue): string;
|
|
41
|
+
/** Reject invalid stored profiles at every BE write boundary; never accept arbitrary CSS. */
|
|
42
|
+
declare function validateCmsLayoutContent(content: RecordValue, depth?: number): void;
|
|
43
|
+
type CmsBoxLayout = {
|
|
44
|
+
padding?: number;
|
|
45
|
+
margin?: number;
|
|
46
|
+
gap?: number;
|
|
47
|
+
widthPercent?: number;
|
|
48
|
+
columns?: number;
|
|
49
|
+
order?: number;
|
|
50
|
+
hidden?: boolean;
|
|
51
|
+
align?: 'left' | 'center' | 'right';
|
|
52
|
+
};
|
|
53
|
+
declare function cmsBoxStyle(value: unknown): Record<string, string | number>;
|
|
54
|
+
/** Explicit profile operations, including records inside nested lists. */
|
|
55
|
+
declare function changeCmsLayoutDevice<T extends RecordValue>(content: T, target: CmsDevice, source?: CmsDevice, fields?: CmsLayoutField[]): T;
|
|
56
|
+
|
|
57
|
+
export { CMS_DEVICES, CMS_DEVICE_MEDIA, CMS_DEVICE_WIDTHS, CMS_ITEM_ID, CMS_LAYOUT_KEYS, type CmsBoxLayout, type CmsDevice, type CmsLayoutField, type CmsLayoutProfile, CmsLayoutValidationError, applyCmsLayoutEdit, changeCmsLayoutDevice, cmsBoxStyle, cmsDevice, cmsLayoutHash, cmsLayoutManaged, cmsLayoutProfile, cmsLayoutValue, cmsResponsiveTextCss, cmsTextLayoutId, cmsVisualValue, isCmsLayoutField, projectCmsLayoutContent, validateCmsLayoutContent };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Persisted presentation profiles. Content and semantic text metadata remain shared. */
|
|
2
|
+
declare class CmsLayoutValidationError extends Error {
|
|
3
|
+
}
|
|
4
|
+
type CmsDevice = 'desktop' | 'tablet' | 'mobile';
|
|
5
|
+
declare const CMS_DEVICES: CmsDevice[];
|
|
6
|
+
declare const CMS_DEVICE_WIDTHS: {
|
|
7
|
+
readonly desktop: 1440;
|
|
8
|
+
readonly tablet: 768;
|
|
9
|
+
readonly mobile: 390;
|
|
10
|
+
};
|
|
11
|
+
declare const CMS_DEVICE_MEDIA: {
|
|
12
|
+
readonly desktop: "(min-width:1024px)";
|
|
13
|
+
readonly tablet: "(min-width:768px) and (max-width:1023.98px)";
|
|
14
|
+
readonly mobile: "(max-width:767.98px)";
|
|
15
|
+
};
|
|
16
|
+
declare const CMS_LAYOUT_KEYS: {
|
|
17
|
+
readonly desktop: "__cmsLayoutDesktop";
|
|
18
|
+
readonly tablet: "__cmsLayoutTablet";
|
|
19
|
+
readonly mobile: "__cmsLayoutMobile";
|
|
20
|
+
};
|
|
21
|
+
declare const CMS_ITEM_ID = "__cmsItemId";
|
|
22
|
+
type RecordValue = Record<string, unknown>;
|
|
23
|
+
type CmsLayoutProfile = Record<string, string>;
|
|
24
|
+
type CmsLayoutField = {
|
|
25
|
+
key: string;
|
|
26
|
+
type: string;
|
|
27
|
+
itemFields?: CmsLayoutField[];
|
|
28
|
+
};
|
|
29
|
+
declare function cmsDevice(width: number): CmsDevice;
|
|
30
|
+
declare function isCmsLayoutField(key: string): boolean;
|
|
31
|
+
declare function cmsVisualValue(key: string, value: unknown): string;
|
|
32
|
+
declare function cmsLayoutProfile(record: RecordValue, device: CmsDevice): CmsLayoutProfile;
|
|
33
|
+
declare function cmsLayoutManaged(record: RecordValue, key: string): boolean;
|
|
34
|
+
declare function cmsLayoutValue(record: RecordValue, key: string, device: CmsDevice): string;
|
|
35
|
+
/** Pass device only to editor controls. Public/rendering uses media-scoped styles. */
|
|
36
|
+
declare function projectCmsLayoutContent<T extends RecordValue>(content: T, device?: CmsDevice, fields?: CmsLayoutField[]): T;
|
|
37
|
+
declare function applyCmsLayoutEdit<T extends RecordValue>(content: T, field: string, value: unknown, device: CmsDevice, fields?: CmsLayoutField[]): T;
|
|
38
|
+
declare function cmsLayoutHash(value: string): string;
|
|
39
|
+
declare function cmsTextLayoutId(value: unknown): string | undefined;
|
|
40
|
+
declare function cmsResponsiveTextCss(content: RecordValue): string;
|
|
41
|
+
/** Reject invalid stored profiles at every BE write boundary; never accept arbitrary CSS. */
|
|
42
|
+
declare function validateCmsLayoutContent(content: RecordValue, depth?: number): void;
|
|
43
|
+
type CmsBoxLayout = {
|
|
44
|
+
padding?: number;
|
|
45
|
+
margin?: number;
|
|
46
|
+
gap?: number;
|
|
47
|
+
widthPercent?: number;
|
|
48
|
+
columns?: number;
|
|
49
|
+
order?: number;
|
|
50
|
+
hidden?: boolean;
|
|
51
|
+
align?: 'left' | 'center' | 'right';
|
|
52
|
+
};
|
|
53
|
+
declare function cmsBoxStyle(value: unknown): Record<string, string | number>;
|
|
54
|
+
/** Explicit profile operations, including records inside nested lists. */
|
|
55
|
+
declare function changeCmsLayoutDevice<T extends RecordValue>(content: T, target: CmsDevice, source?: CmsDevice, fields?: CmsLayoutField[]): T;
|
|
56
|
+
|
|
57
|
+
export { CMS_DEVICES, CMS_DEVICE_MEDIA, CMS_DEVICE_WIDTHS, CMS_ITEM_ID, CMS_LAYOUT_KEYS, type CmsBoxLayout, type CmsDevice, type CmsLayoutField, type CmsLayoutProfile, CmsLayoutValidationError, applyCmsLayoutEdit, changeCmsLayoutDevice, cmsBoxStyle, cmsDevice, cmsLayoutHash, cmsLayoutManaged, cmsLayoutProfile, cmsLayoutValue, cmsResponsiveTextCss, cmsTextLayoutId, cmsVisualValue, isCmsLayoutField, projectCmsLayoutContent, validateCmsLayoutContent };
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/layout-model.ts
|
|
21
|
+
var layout_model_exports = {};
|
|
22
|
+
__export(layout_model_exports, {
|
|
23
|
+
CMS_DEVICES: () => CMS_DEVICES,
|
|
24
|
+
CMS_DEVICE_MEDIA: () => CMS_DEVICE_MEDIA,
|
|
25
|
+
CMS_DEVICE_WIDTHS: () => CMS_DEVICE_WIDTHS,
|
|
26
|
+
CMS_ITEM_ID: () => CMS_ITEM_ID,
|
|
27
|
+
CMS_LAYOUT_KEYS: () => CMS_LAYOUT_KEYS,
|
|
28
|
+
CmsLayoutValidationError: () => CmsLayoutValidationError,
|
|
29
|
+
applyCmsLayoutEdit: () => applyCmsLayoutEdit,
|
|
30
|
+
changeCmsLayoutDevice: () => changeCmsLayoutDevice,
|
|
31
|
+
cmsBoxStyle: () => cmsBoxStyle,
|
|
32
|
+
cmsDevice: () => cmsDevice,
|
|
33
|
+
cmsLayoutHash: () => cmsLayoutHash,
|
|
34
|
+
cmsLayoutManaged: () => cmsLayoutManaged,
|
|
35
|
+
cmsLayoutProfile: () => cmsLayoutProfile,
|
|
36
|
+
cmsLayoutValue: () => cmsLayoutValue,
|
|
37
|
+
cmsResponsiveTextCss: () => cmsResponsiveTextCss,
|
|
38
|
+
cmsTextLayoutId: () => cmsTextLayoutId,
|
|
39
|
+
cmsVisualValue: () => cmsVisualValue,
|
|
40
|
+
isCmsLayoutField: () => isCmsLayoutField,
|
|
41
|
+
projectCmsLayoutContent: () => projectCmsLayoutContent,
|
|
42
|
+
validateCmsLayoutContent: () => validateCmsLayoutContent
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(layout_model_exports);
|
|
45
|
+
|
|
46
|
+
// src/shared/responsive-layout.ts
|
|
47
|
+
var CmsLayoutValidationError = class extends Error {
|
|
48
|
+
};
|
|
49
|
+
var CMS_DEVICES = ["desktop", "tablet", "mobile"];
|
|
50
|
+
var CMS_DEVICE_WIDTHS = { desktop: 1440, tablet: 768, mobile: 390 };
|
|
51
|
+
var CMS_DEVICE_MEDIA = { desktop: "(min-width:1024px)", tablet: "(min-width:768px) and (max-width:1023.98px)", mobile: "(max-width:767.98px)" };
|
|
52
|
+
var CMS_LAYOUT_KEYS = { desktop: "__cmsLayoutDesktop", tablet: "__cmsLayoutTablet", mobile: "__cmsLayoutMobile" };
|
|
53
|
+
var CMS_ITEM_ID = "__cmsItemId";
|
|
54
|
+
var own = (record, key) => Object.prototype.hasOwnProperty.call(record, key);
|
|
55
|
+
var unsafe = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
56
|
+
var fonts = ["Inter, sans-serif", "Arial, sans-serif", "Georgia, serif", '"Times New Roman", serif', '"Courier New", monospace', '"Public Sans Variable", Arial, sans-serif'];
|
|
57
|
+
function cmsDevice(width) {
|
|
58
|
+
return width < 768 ? "mobile" : width < 1024 ? "tablet" : "desktop";
|
|
59
|
+
}
|
|
60
|
+
function object(value) {
|
|
61
|
+
try {
|
|
62
|
+
const parsed = typeof value === "string" ? JSON.parse(value) : value;
|
|
63
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
64
|
+
} catch {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function array(value) {
|
|
69
|
+
if (typeof value !== "string" || !value.trimStart().startsWith("[")) return null;
|
|
70
|
+
try {
|
|
71
|
+
const parsed = JSON.parse(value);
|
|
72
|
+
return Array.isArray(parsed) && parsed.every((item) => item && typeof item === "object" && !Array.isArray(item)) ? parsed : null;
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function isCmsLayoutField(key) {
|
|
78
|
+
return !unsafe.has(key) && (/(?:TextLayout|ImageLayout|Color|BoxLayout)$/.test(key) || key === "sectionBackgroundColor" || key === "backgroundColor" || key === "__cmsBoxLayout");
|
|
79
|
+
}
|
|
80
|
+
var color = (value) => typeof value === "string" && /^#[0-9a-fA-F]{6}$/.test(value);
|
|
81
|
+
function number(value, min, max) {
|
|
82
|
+
return typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
|
|
83
|
+
}
|
|
84
|
+
function cmsVisualValue(key, value) {
|
|
85
|
+
if (key.endsWith("Color") || key === "backgroundColor") return color(value) ? String(value) : "";
|
|
86
|
+
const raw = object(value), result = {};
|
|
87
|
+
if (key.endsWith("TextLayout")) {
|
|
88
|
+
for (const prop of ["width", "height"]) if (number(raw[prop], 16, 1e4)) result[prop] = raw[prop];
|
|
89
|
+
if (number(raw.fontSize, 8, 300)) result.fontSize = raw.fontSize;
|
|
90
|
+
if (number(raw.lineHeight, 0.5, 5)) result.lineHeight = raw.lineHeight;
|
|
91
|
+
if (fonts.includes(String(raw.fontFamily))) result.fontFamily = raw.fontFamily;
|
|
92
|
+
if (["left", "center", "right"].includes(String(raw.textAlign))) result.textAlign = raw.textAlign;
|
|
93
|
+
} else if (key.endsWith("ImageLayout")) {
|
|
94
|
+
for (const prop of ["width", "height"]) if (number(raw[prop], 16, 8e3)) result[prop] = Math.round(Number(raw[prop]));
|
|
95
|
+
if (raw.auto === true) result.auto = true;
|
|
96
|
+
if (typeof raw.lockRatio === "boolean") result.lockRatio = raw.lockRatio;
|
|
97
|
+
if (["contain", "cover"].includes(String(raw.fit))) result.fit = raw.fit;
|
|
98
|
+
} else {
|
|
99
|
+
for (const prop of ["padding", "margin", "gap"]) if (number(raw[prop], 0, 300)) result[prop] = raw[prop];
|
|
100
|
+
if (number(raw.widthPercent, 1, 100)) result.widthPercent = raw.widthPercent;
|
|
101
|
+
if (number(raw.columns, 1, 12) && Number.isInteger(raw.columns)) result.columns = raw.columns;
|
|
102
|
+
if (number(raw.order, -1e3, 1e3) && Number.isInteger(raw.order)) result.order = raw.order;
|
|
103
|
+
if (typeof raw.hidden === "boolean") result.hidden = raw.hidden;
|
|
104
|
+
if (["left", "center", "right"].includes(String(raw.align))) result.align = raw.align;
|
|
105
|
+
}
|
|
106
|
+
return Object.keys(result).length ? JSON.stringify(result) : "";
|
|
107
|
+
}
|
|
108
|
+
var profileCache = /* @__PURE__ */ new WeakMap();
|
|
109
|
+
function readProfile(record, device) {
|
|
110
|
+
let cached = profileCache.get(record);
|
|
111
|
+
if (!cached) {
|
|
112
|
+
cached = /* @__PURE__ */ new Map();
|
|
113
|
+
profileCache.set(record, cached);
|
|
114
|
+
}
|
|
115
|
+
const source = record[CMS_LAYOUT_KEYS[device]];
|
|
116
|
+
const previous = cached.get(device);
|
|
117
|
+
if (previous && previous.source === source) return previous.value;
|
|
118
|
+
const value = Object.fromEntries(Object.entries(object(source)).filter(([key, value2]) => key.length <= 500 && isCmsLayoutField(key) && typeof value2 === "string").map(([key, value2]) => [key, cmsVisualValue(key, value2)]));
|
|
119
|
+
cached.set(device, { source, value });
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function cmsLayoutProfile(record, device) {
|
|
123
|
+
return { ...readProfile(record, device) };
|
|
124
|
+
}
|
|
125
|
+
function cmsLayoutManaged(record, key) {
|
|
126
|
+
return CMS_DEVICES.some((device) => own(readProfile(record, device), key));
|
|
127
|
+
}
|
|
128
|
+
function cmsLayoutValue(record, key, device) {
|
|
129
|
+
const profile = readProfile(record, device);
|
|
130
|
+
return own(profile, key) ? profile[key] : cmsVisualValue(key, record[key]);
|
|
131
|
+
}
|
|
132
|
+
function semantic(value) {
|
|
133
|
+
const raw = object(value);
|
|
134
|
+
return Object.fromEntries(Object.entries(raw).filter(([key]) => ["richText", "blockType", "listType"].includes(key)));
|
|
135
|
+
}
|
|
136
|
+
function writeValue(record, key, value, device) {
|
|
137
|
+
const next = { ...record, __cmsLayoutVersion: 1 };
|
|
138
|
+
for (const mode of CMS_DEVICES) {
|
|
139
|
+
const profile = cmsLayoutProfile(record, mode);
|
|
140
|
+
if (!own(profile, key)) profile[key] = cmsVisualValue(key, record[key]);
|
|
141
|
+
if (mode === device) profile[key] = cmsVisualValue(key, value);
|
|
142
|
+
next[CMS_LAYOUT_KEYS[mode]] = JSON.stringify(profile);
|
|
143
|
+
}
|
|
144
|
+
if (key.endsWith("TextLayout")) next[key] = JSON.stringify({ ...semantic(record[key]), ...semantic(value) });
|
|
145
|
+
else delete next[key];
|
|
146
|
+
return next;
|
|
147
|
+
}
|
|
148
|
+
function stableId(path, index) {
|
|
149
|
+
return `legacy-${cmsLayoutHash(path)}-${index}`;
|
|
150
|
+
}
|
|
151
|
+
function projectRecord(record, device, path, depth, fields) {
|
|
152
|
+
if (depth > 10) return record;
|
|
153
|
+
const next = { ...record };
|
|
154
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(record), ...CMS_DEVICES.flatMap((mode) => Object.keys(cmsLayoutProfile(record, mode)))]);
|
|
155
|
+
for (const key of keys) {
|
|
156
|
+
if (isCmsLayoutField(key) && cmsLayoutManaged(record, key)) {
|
|
157
|
+
if (device) {
|
|
158
|
+
const active = cmsLayoutValue(record, key, device);
|
|
159
|
+
next[key] = key.endsWith("TextLayout") ? JSON.stringify({ ...semantic(record[key]), ...object(active) }) : active;
|
|
160
|
+
} else if (key.endsWith("BoxLayout") && key !== "__cmsBoxLayout" || key.endsWith("TextLayout") || key.endsWith("Color") && key !== "sectionBackgroundColor" && key !== "backgroundColor") {
|
|
161
|
+
const field = key.replace(/(?:TextLayout|Color|BoxLayout)$/, "");
|
|
162
|
+
const textKey = `${field}TextLayout`, colorKey = `${field}Color`, boxKey = `${field}BoxLayout`;
|
|
163
|
+
const profiles = Object.fromEntries(CMS_DEVICES.map((mode) => [mode, {
|
|
164
|
+
...cmsLayoutManaged(record, textKey) ? object(cmsLayoutValue(record, textKey, mode)) : object(cmsVisualValue(textKey, record[textKey])),
|
|
165
|
+
...cmsLayoutManaged(record, boxKey) ? { box: object(cmsLayoutValue(record, boxKey, mode)) } : {},
|
|
166
|
+
...cmsLayoutManaged(record, colorKey) && cmsLayoutValue(record, colorKey, mode) ? { color: cmsLayoutValue(record, colorKey, mode) } : {}
|
|
167
|
+
}]));
|
|
168
|
+
next[textKey] = JSON.stringify({ ...semantic(record[textKey]), __responsive: profiles });
|
|
169
|
+
if (cmsLayoutManaged(record, colorKey)) delete next[colorKey];
|
|
170
|
+
} else delete next[key];
|
|
171
|
+
}
|
|
172
|
+
const list = fields && fields.find((field) => field.key === key)?.type !== "list" ? null : array(record[key]);
|
|
173
|
+
if (list) next[key] = JSON.stringify(list.map((item, index) => projectRecord({ ...item, [CMS_ITEM_ID]: item[CMS_ITEM_ID] ?? stableId(`${path}/${key}`, index) }, device, `${path}/${key}/${item[CMS_ITEM_ID] ?? stableId(`${path}/${key}`, index)}`, depth + 1, fields?.find((field) => field.key === key)?.itemFields)));
|
|
174
|
+
}
|
|
175
|
+
return next;
|
|
176
|
+
}
|
|
177
|
+
function projectCmsLayoutContent(content, device, fields) {
|
|
178
|
+
return projectRecord(content, device, "", 0, fields);
|
|
179
|
+
}
|
|
180
|
+
function captureRecord(raw, incoming, device, path, depth, complete = false, fields) {
|
|
181
|
+
if (depth > 10) return incoming;
|
|
182
|
+
let next = { ...raw };
|
|
183
|
+
const projected = projectRecord(raw, device, path, depth, fields);
|
|
184
|
+
const edits = { ...incoming };
|
|
185
|
+
if (complete) for (const key of Object.keys(projected)) {
|
|
186
|
+
if (isCmsLayoutField(key) && !(key in incoming)) edits[key] = "";
|
|
187
|
+
}
|
|
188
|
+
for (const [key, value] of Object.entries(edits)) {
|
|
189
|
+
if (unsafe.has(key) || Object.values(CMS_LAYOUT_KEYS).includes(key) || key === "__cmsLayoutVersion") continue;
|
|
190
|
+
if (isCmsLayoutField(key)) {
|
|
191
|
+
if (value !== projected[key]) next = writeValue(next, key, value, device);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const list = fields && fields.find((field) => field.key === key)?.type !== "list" ? null : array(value);
|
|
195
|
+
if (list) {
|
|
196
|
+
const previous = array(raw[key]) ?? [];
|
|
197
|
+
const byId = new Map(previous.map((item, index) => [item[CMS_ITEM_ID] ?? stableId(`${path}/${key}`, index), item]));
|
|
198
|
+
const seen = /* @__PURE__ */ new Set();
|
|
199
|
+
next[key] = JSON.stringify(list.map((item, index) => {
|
|
200
|
+
let id = item[CMS_ITEM_ID] ?? `item-${globalThis.crypto.randomUUID()}`;
|
|
201
|
+
if (seen.has(id)) id = `item-${globalThis.crypto.randomUUID()}`;
|
|
202
|
+
seen.add(id);
|
|
203
|
+
const before = byId.get(item[CMS_ITEM_ID]) ?? (item[CMS_ITEM_ID] ? void 0 : previous[index]);
|
|
204
|
+
const base = before ?? Object.fromEntries(Object.entries(item).filter(([name]) => !isCmsLayoutField(name)));
|
|
205
|
+
return { ...captureRecord(base, item, device, `${path}/${key}/${id}`, depth + 1, true, fields?.find((field) => field.key === key)?.itemFields), [CMS_ITEM_ID]: id };
|
|
206
|
+
}));
|
|
207
|
+
} else next[key] = value;
|
|
208
|
+
}
|
|
209
|
+
return next;
|
|
210
|
+
}
|
|
211
|
+
function applyCmsLayoutEdit(content, field, value, device, fields) {
|
|
212
|
+
return captureRecord(content, { [field]: value }, device, "", 0, false, fields);
|
|
213
|
+
}
|
|
214
|
+
function cmsLayoutHash(value) {
|
|
215
|
+
let a = 2166136261, b = 5381;
|
|
216
|
+
for (let i = 0; i < value.length; i++) {
|
|
217
|
+
a = Math.imul(a ^ value.charCodeAt(i), 16777619);
|
|
218
|
+
b = Math.imul(b, 33) ^ value.charCodeAt(i);
|
|
219
|
+
}
|
|
220
|
+
return `${(a >>> 0).toString(36)}${(b >>> 0).toString(36)}`;
|
|
221
|
+
}
|
|
222
|
+
function cmsTextLayoutId(value) {
|
|
223
|
+
const profiles = object(value).__responsive;
|
|
224
|
+
return profiles && typeof profiles === "object" ? `r${cmsLayoutHash(JSON.stringify(profiles))}` : void 0;
|
|
225
|
+
}
|
|
226
|
+
function cmsResponsiveTextCss(content) {
|
|
227
|
+
const styles = /* @__PURE__ */ new Map();
|
|
228
|
+
const walk = (record, depth) => {
|
|
229
|
+
if (depth > 10) return;
|
|
230
|
+
for (const [key, value] of Object.entries(record)) {
|
|
231
|
+
if (key.endsWith("TextLayout")) {
|
|
232
|
+
const id = cmsTextLayoutId(value);
|
|
233
|
+
if (!id || styles.has(id)) continue;
|
|
234
|
+
const profiles = object(object(value).__responsive);
|
|
235
|
+
styles.set(id, CMS_DEVICES.map((mode) => {
|
|
236
|
+
const raw = object(profiles[mode]), layout = object(cmsVisualValue("xTextLayout", JSON.stringify(raw)));
|
|
237
|
+
const declarations = [
|
|
238
|
+
...layout.width ? [`width:${layout.width}px`, "max-width:100%", "box-sizing:border-box", "flex-shrink:1"] : [],
|
|
239
|
+
...layout.height ? [`min-height:${layout.height}px`, "height:auto"] : [],
|
|
240
|
+
...layout.fontSize ? [`font-size:${layout.fontSize}px`] : [],
|
|
241
|
+
...layout.fontFamily ? [`font-family:${layout.fontFamily}`] : [],
|
|
242
|
+
...layout.lineHeight ? [`line-height:${layout.lineHeight}`] : [],
|
|
243
|
+
...layout.textAlign ? [`text-align:${layout.textAlign}`, `justify-content:${layout.textAlign === "center" ? "center" : layout.textAlign === "right" ? "flex-end" : "flex-start"}`] : [],
|
|
244
|
+
...color(raw.color) ? [`color:${raw.color}`] : [],
|
|
245
|
+
...Object.entries(cmsBoxStyle(JSON.stringify(raw.box))).map(([name, value2]) => `${name.replace(/[A-Z]/g, (letter) => "-" + letter.toLowerCase())}:${value2}`)
|
|
246
|
+
];
|
|
247
|
+
const box = object(raw.box);
|
|
248
|
+
const inlineSize = (layout.width || layout.height || box.widthPercent) && !box.hidden && !box.columns ? `:is(span,a,strong,small,label)[data-cms-text-layout="${id}"]{display:${layout.textAlign ? "block" : "inline-block"}!important}` : "";
|
|
249
|
+
return declarations.length ? `@media ${CMS_DEVICE_MEDIA[mode]}{[data-cms-text-layout="${id}"]{${declarations.map((rule) => `${rule}!important`).join(";")}}${inlineSize}}` : "";
|
|
250
|
+
}).join(""));
|
|
251
|
+
}
|
|
252
|
+
const list = array(value);
|
|
253
|
+
if (list) list.forEach((item) => walk(item, depth + 1));
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
walk(content, 0);
|
|
257
|
+
return [...styles.values()].join("");
|
|
258
|
+
}
|
|
259
|
+
function validateCmsLayoutContent(content, depth = 0) {
|
|
260
|
+
if (depth > 10) throw new CmsLayoutValidationError("Layout l\u1ED3ng nhau v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n.");
|
|
261
|
+
if (content.__cmsLayoutVersion !== void 0 && content.__cmsLayoutVersion !== 1) throw new CmsLayoutValidationError("Phi\xEAn b\u1EA3n layout kh\xF4ng \u0111\u01B0\u1EE3c h\u1ED7 tr\u1EE3.");
|
|
262
|
+
for (const [key, value] of Object.entries(content)) {
|
|
263
|
+
if (Object.values(CMS_LAYOUT_KEYS).includes(key)) {
|
|
264
|
+
if (typeof value !== "string" || value.length > 2e5) throw new CmsLayoutValidationError("C\u1EA5u h\xECnh layout kh\xF4ng h\u1EE3p l\u1EC7.");
|
|
265
|
+
let parsed;
|
|
266
|
+
try {
|
|
267
|
+
parsed = JSON.parse(value);
|
|
268
|
+
} catch {
|
|
269
|
+
throw new CmsLayoutValidationError("C\u1EA5u h\xECnh layout kh\xF4ng h\u1EE3p l\u1EC7.");
|
|
270
|
+
}
|
|
271
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || Object.keys(parsed).length > 2e3) throw new CmsLayoutValidationError("C\u1EA5u h\xECnh layout kh\xF4ng h\u1EE3p l\u1EC7.");
|
|
272
|
+
for (const [name, entry] of Object.entries(parsed)) {
|
|
273
|
+
if (name.length > 500 || !isCmsLayoutField(name) || typeof entry !== "string") throw new CmsLayoutValidationError("Thu\u1ED9c t\xEDnh layout kh\xF4ng h\u1EE3p l\u1EC7.");
|
|
274
|
+
if (entry && !(name.endsWith("Color") || name === "backgroundColor")) {
|
|
275
|
+
let parsedEntry;
|
|
276
|
+
try {
|
|
277
|
+
parsedEntry = JSON.parse(entry);
|
|
278
|
+
} catch {
|
|
279
|
+
throw new CmsLayoutValidationError("Gi\xE1 tr\u1ECB layout kh\xF4ng h\u1EE3p l\u1EC7.");
|
|
280
|
+
}
|
|
281
|
+
if (!parsedEntry || typeof parsedEntry !== "object" || Array.isArray(parsedEntry)) throw new CmsLayoutValidationError("Gi\xE1 tr\u1ECB layout kh\xF4ng h\u1EE3p l\u1EC7.");
|
|
282
|
+
}
|
|
283
|
+
if (entry && cmsVisualValue(name, entry) !== entry) {
|
|
284
|
+
const source = object(entry), safe = object(cmsVisualValue(name, entry));
|
|
285
|
+
if (name.endsWith("Color") || name === "backgroundColor" || JSON.stringify(Object.keys(source).sort()) !== JSON.stringify(Object.keys(safe).sort()) || Object.keys(source).some((prop) => source[prop] !== safe[prop])) throw new CmsLayoutValidationError("Gi\xE1 tr\u1ECB layout kh\xF4ng h\u1EE3p l\u1EC7.");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
const list = array(value);
|
|
290
|
+
if (list) list.forEach((item) => validateCmsLayoutContent(item, depth + 1));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function cmsBoxStyle(value) {
|
|
295
|
+
const box = object(cmsVisualValue("xBoxLayout", value));
|
|
296
|
+
return {
|
|
297
|
+
...box.widthPercent ? { width: `${box.widthPercent}%`, maxWidth: "100%", minWidth: 0 } : {},
|
|
298
|
+
...box.padding !== void 0 ? { padding: `${box.padding}px`, boxSizing: "border-box" } : {},
|
|
299
|
+
...box.margin !== void 0 ? { margin: `${box.margin}px` } : {},
|
|
300
|
+
...box.gap !== void 0 ? { gap: `${box.gap}px` } : {},
|
|
301
|
+
...box.columns ? { display: "grid", gridTemplateColumns: `repeat(${box.columns},minmax(0,1fr))` } : {},
|
|
302
|
+
...box.order !== void 0 ? { order: Number(box.order) } : {},
|
|
303
|
+
...box.align ? { textAlign: String(box.align), justifyItems: box.align === "left" ? "start" : box.align === "right" ? "end" : "center" } : {},
|
|
304
|
+
...box.hidden === true ? { display: "none" } : {}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function changeCmsLayoutDevice(content, target, source, fields) {
|
|
308
|
+
const walk = (record, depth, schema) => {
|
|
309
|
+
if (depth > 10) return record;
|
|
310
|
+
let next = { ...record };
|
|
311
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(record).filter(isCmsLayoutField), ...CMS_DEVICES.flatMap((mode) => Object.keys(cmsLayoutProfile(record, mode)))]);
|
|
312
|
+
for (const key of keys) {
|
|
313
|
+
const value = source ? cmsLayoutValue(record, key, source) : "";
|
|
314
|
+
next = writeValue(next, key, key.endsWith("TextLayout") ? JSON.stringify({ ...semantic(record[key]), ...object(value) }) : value, target);
|
|
315
|
+
}
|
|
316
|
+
for (const [key, value] of Object.entries(record)) {
|
|
317
|
+
const list = schema && schema.find((field) => field.key === key)?.type !== "list" ? null : array(value);
|
|
318
|
+
if (list) next[key] = JSON.stringify(list.map((item) => walk(item, depth + 1, schema?.find((field) => field.key === key)?.itemFields)));
|
|
319
|
+
}
|
|
320
|
+
return next;
|
|
321
|
+
};
|
|
322
|
+
return walk(content, 0, fields);
|
|
323
|
+
}
|
|
324
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
325
|
+
0 && (module.exports = {
|
|
326
|
+
CMS_DEVICES,
|
|
327
|
+
CMS_DEVICE_MEDIA,
|
|
328
|
+
CMS_DEVICE_WIDTHS,
|
|
329
|
+
CMS_ITEM_ID,
|
|
330
|
+
CMS_LAYOUT_KEYS,
|
|
331
|
+
CmsLayoutValidationError,
|
|
332
|
+
applyCmsLayoutEdit,
|
|
333
|
+
changeCmsLayoutDevice,
|
|
334
|
+
cmsBoxStyle,
|
|
335
|
+
cmsDevice,
|
|
336
|
+
cmsLayoutHash,
|
|
337
|
+
cmsLayoutManaged,
|
|
338
|
+
cmsLayoutProfile,
|
|
339
|
+
cmsLayoutValue,
|
|
340
|
+
cmsResponsiveTextCss,
|
|
341
|
+
cmsTextLayoutId,
|
|
342
|
+
cmsVisualValue,
|
|
343
|
+
isCmsLayoutField,
|
|
344
|
+
projectCmsLayoutContent,
|
|
345
|
+
validateCmsLayoutContent
|
|
346
|
+
});
|