@ecomcx/ecomweb-theme-sdk 2.4.1 → 2.6.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/API.md +1 -1
- package/dist/dynamic.js +2 -2
- package/dist/image.js +2 -2
- package/dist/rich.js +36 -9
- package/dist/types.d.ts +4 -0
- package/package.json +2 -2
package/API.md
CHANGED
|
@@ -1068,7 +1068,7 @@ interface ListPage<T> { items: T[]; total: number; page: number; totalPages: num
|
|
|
1068
1068
|
#### `Media`
|
|
1069
1069
|
|
|
1070
1070
|
```ts
|
|
1071
|
-
interface Media { id: number; url: string; fileName: string; mimeType: string; size: number; width?: number | null; height?: number | null; alt: string; caption: string; sizes: Record<string, MediaSize>; /** Bản WebP của ảnh gốc. */ webpUrl?: string | null; /** Điểm lấy nét 0–1 (object-position). */ focalX?: number | null; focalY?: number | null; title?: string; createdAt?: string; }
|
|
1071
|
+
interface Media { id: number; url: string; fileName: string; mimeType: string; size: number; width?: number | null; height?: number | null; alt: string; caption: string; sizes: Record<string, MediaSize>; /** Bản WebP của ảnh gốc. */ webpUrl?: string | null; /** Video: ảnh poster (CMS ≥ 1.37). */ posterUrl?: string | null; /** Video: thời lượng (giây). */ duration?: number | null; /** Điểm lấy nét 0–1 (object-position). */ focalX?: number | null; focalY?: number | null; title?: string; createdAt?: string; }
|
|
1072
1072
|
```
|
|
1073
1073
|
|
|
1074
1074
|
#### `MediaQuery`
|
package/dist/dynamic.js
CHANGED
|
@@ -9,7 +9,7 @@ import { applyFilters } from "./runtime.js";
|
|
|
9
9
|
import { localeHref } from "./locale.js";
|
|
10
10
|
import { renderContent } from "./rich.js";
|
|
11
11
|
import { cx } from "./utils.js";
|
|
12
|
-
import { applyPatternOverrides, spacingValue } from "@ecomcx/ecomweb-content";
|
|
12
|
+
import { applyPatternOverrides, clipExcerpt, spacingValue } from "@ecomcx/ecomweb-content";
|
|
13
13
|
const align = (a) => (a.textAlign && a.textAlign !== "left" ? { textAlign: a.textAlign } : undefined);
|
|
14
14
|
const ASPECT = { "16/9": "16 / 9", "4/3": "4 / 3", "1/1": "1 / 1", "3/4": "3 / 4" };
|
|
15
15
|
/**
|
|
@@ -64,7 +64,7 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
64
64
|
case "postExcerpt":
|
|
65
65
|
if (!post?.excerpt)
|
|
66
66
|
return null;
|
|
67
|
-
return _jsxs("p", { className: "ecx-post-excerpt", children: [post.excerpt, a.moreText && _jsxs(_Fragment, { children: [" ", _jsx(Link, { href: post.link, className: "ecx-more-link", children: a.moreText })] })] }, key);
|
|
67
|
+
return _jsxs("p", { className: "ecx-post-excerpt", children: [clipExcerpt(post.excerpt, a.length), a.moreText && _jsxs(_Fragment, { children: [" ", _jsx(Link, { href: post.link, className: "ecx-more-link", children: a.moreText })] })] }, key);
|
|
68
68
|
case "featuredImage": {
|
|
69
69
|
if (!post?.featuredMedia)
|
|
70
70
|
return null;
|
package/dist/image.js
CHANGED
|
@@ -26,12 +26,12 @@ export function Img({ media, size = "large", sizes, className, alt, priority, st
|
|
|
26
26
|
const list = imageCandidates(media, size);
|
|
27
27
|
const main = list[list.length - 1] ?? { url: media.url, width: media.width ?? 0, height: media.height ?? 0 };
|
|
28
28
|
const srcSet = list.map((s) => `${s.url} ${s.width}w`).join(", ");
|
|
29
|
-
const webp = list.every((s) => s.webpUrl) ? list.map((s) => `${s.webpUrl} ${s.width}w`).join(", ") : null;
|
|
29
|
+
const webp = media.mimeType !== "image/webp" && list.every((s) => s.webpUrl) ? list.map((s) => `${s.webpUrl} ${s.width}w`).join(", ") : null;
|
|
30
30
|
const sz = sizes ?? (main.width ? `(max-width: ${main.width}px) 100vw, ${main.width}px` : undefined);
|
|
31
31
|
const focal = media.focalX != null && media.focalY != null
|
|
32
32
|
? { objectPosition: `${Math.round(media.focalX * 100)}% ${Math.round(media.focalY * 100)}%` } : undefined;
|
|
33
33
|
const img = (_jsx("img", { src: main.url, srcSet: list.length > 1 ? srcSet : undefined, sizes: list.length > 1 ? sz : undefined, width: main.width || undefined, height: main.height || undefined, alt: alt ?? media.alt ?? "", loading: priority ? "eager" : "lazy", decoding: "async", fetchPriority: priority ? "high" : undefined, className: className, style: { ...focal, ...style } }));
|
|
34
|
-
if (!webp
|
|
34
|
+
if (!webp)
|
|
35
35
|
return img;
|
|
36
36
|
return _jsxs("picture", { className: cx("cms-picture"), children: [_jsx("source", { type: "image/webp", srcSet: webp, sizes: sz }), img] });
|
|
37
37
|
}
|
package/dist/rich.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { Fragment, cloneElement, createElement, isValidElement } from "react";
|
|
3
3
|
import { ICON_LIBRARY } from "@ecomcx/ecomweb-content/icon-library";
|
|
4
4
|
import { iconSvg } from "./icon-svg.js";
|
|
5
|
-
import { lottieConfig, BINDING_URL_ATTRS, CORE_BINDABLE, registerIconLibrary, tableClass, blockBgVideo, typedConfig, coverVideo, scheduleVisible, normalizeStyle, imageFx, countdownRules, testimonialsConfig, testimonialsVars, popupClass, popupConfig, popupPlayStyle, popupVars, carouselConfig, DYNAMIC_NODES, countdownTarget, nodeText, buttonIcon, widgetMarkup, tabsClass, formSizeClass, widthClass, blockCitation, blockShell, buttonWrapShell, coverParts, linkRel, embedInfo, motionClasses, normalizeContent, safeUrl, styleClass, styleCss, controlsCss, CORE_CONTROLS } from "@ecomcx/ecomweb-content";
|
|
5
|
+
import { sizedImage, lottieConfig, BINDING_URL_ATTRS, CORE_BINDABLE, registerIconLibrary, tableClass, blockBgVideo, typedConfig, coverVideo, scheduleVisible, normalizeStyle, imageFx, countdownRules, testimonialsConfig, testimonialsVars, popupClass, popupConfig, popupPlayStyle, popupVars, carouselConfig, DYNAMIC_NODES, countdownTarget, nodeText, buttonIcon, widgetMarkup, tabsClass, formSizeClass, widthClass, blockCitation, blockShell, buttonWrapShell, coverParts, linkRel, embedInfo, motionClasses, normalizeContent, safeUrl, styleClass, styleCss, controlsCss, CORE_CONTROLS } from "@ecomcx/ecomweb-content";
|
|
6
6
|
import { cx } from "./utils.js";
|
|
7
7
|
import { SOCIAL_ICONS } from "./social-icons.js";
|
|
8
8
|
import { GalleryThumbsClient, AudienceGate, TypedText, BgVideo, PopupClient, LottieClient, CarouselClient, CountdownClient, FormBlockClient, LightboxClient, Link, TabsClient, TocSpy } from "./client.js";
|
|
@@ -283,6 +283,8 @@ async function renderNode(node, key, ctx) {
|
|
|
283
283
|
}
|
|
284
284
|
const emptyAttr = (v) => v === undefined || v === null || v === "" || (Array.isArray(v) && !v.length);
|
|
285
285
|
/** Nút không chọn riêng được trong khung soạn (hoặc bọc thêm thẻ sẽ sai cấu trúc HTML: li trong ul, ô trong bảng). */
|
|
286
|
+
/** Độ rộng cột đã kéo trong trình soạn (attrs.colwidth = [px]). */
|
|
287
|
+
const cellWidth = (a) => (Array.isArray(a.colwidth) && Number(a.colwidth[0]) > 0 ? { width: Number(a.colwidth[0]), minWidth: Number(a.colwidth[0]) } : undefined);
|
|
286
288
|
const UNMARKED = new Set(["text", "hardBreak", "listItem", "tableRow", "tableCell", "tableHeader"]);
|
|
287
289
|
/** Gắn vị trí khối: thẻ HTML thì thêm thuộc tính, component thì bọc thẻ display:contents (không đổi bố cục). */
|
|
288
290
|
function markBlock(el, source, path, key) {
|
|
@@ -329,6 +331,24 @@ async function renderNodeInner(node, key, ctx) {
|
|
|
329
331
|
case "blockquote": return shelled("blockquote", a, key, _jsxs(_Fragment, { children: [await children(), blockCitation(a) && _jsx("cite", { children: blockCitation(a) })] }));
|
|
330
332
|
case "codeBlock": return _jsx("pre", { children: _jsx("code", { className: a.language ? `language-${a.language}` : undefined, children: plainText(node) }) }, key);
|
|
331
333
|
case "hardBreak": return _jsx("br", {}, key);
|
|
334
|
+
case "inlineImage": {
|
|
335
|
+
// Ảnh trong dòng chữ: src qua safeUrl; width / height / radius đã được lược đồ chặn dạng lạ; có liên kết thì bọc <a>
|
|
336
|
+
const src = safeUrl(a.src, "");
|
|
337
|
+
if (!src)
|
|
338
|
+
return null;
|
|
339
|
+
const style = {};
|
|
340
|
+
if (typeof a.width === "string")
|
|
341
|
+
style.width = a.width;
|
|
342
|
+
if (typeof a.height === "string")
|
|
343
|
+
style.height = a.height;
|
|
344
|
+
if (typeof a.radius === "string")
|
|
345
|
+
style.borderRadius = a.radius;
|
|
346
|
+
if (typeof a.valign === "string" && a.valign !== "middle")
|
|
347
|
+
style.verticalAlign = a.valign;
|
|
348
|
+
const img = _jsx("img", { className: "ecx-inline-image", src: src, alt: typeof a.alt === "string" ? a.alt : "", loading: "lazy", decoding: "async", style: Object.keys(style).length ? style : undefined });
|
|
349
|
+
const href = safeUrl(a.href, "");
|
|
350
|
+
return href ? _jsx("a", { href: href, target: a.target === "_blank" ? "_blank" : undefined, rel: a.target === "_blank" ? "noopener noreferrer" : undefined, children: img }, key) : _jsx("span", { className: "ecx-inline-image-wrap", children: img }, key);
|
|
351
|
+
}
|
|
332
352
|
case "icon": {
|
|
333
353
|
const size = Math.min(128, Math.max(12, Number(a.size) || 24));
|
|
334
354
|
const stroke = Math.min(4, Math.max(0.5, Number(a.stroke) || 2));
|
|
@@ -346,12 +366,14 @@ async function renderNodeInner(node, key, ctx) {
|
|
|
346
366
|
case "image": {
|
|
347
367
|
// Ảnh chèn từ thư viện mang sẵn srcset (JPEG + WebP) và kích thước → responsive, không nhảy layout
|
|
348
368
|
// Bề rộng hiển thị = cỡ người viết kéo trong trình soạn → trình duyệt chọn file vừa đúng
|
|
349
|
-
|
|
350
|
-
const
|
|
369
|
+
// Cỡ Nhỏ / Vừa (thumbnail / medium): dùng bản thu nhỏ và hiện đúng cỡ đó — chỉ khi người viết chưa kéo tay bề rộng
|
|
370
|
+
const sz = sizedImage(a);
|
|
371
|
+
const sizes = sz ? `${sz.width}px` : a.width ? `(max-width: ${a.width}px) 100vw, ${a.width}px` : (a.sizes || "(max-width: 1024px) 100vw, 1024px");
|
|
372
|
+
const imgSrc = safeUrl(sz?.src ?? a.src, "");
|
|
351
373
|
if (!imgSrc)
|
|
352
374
|
return null; // chưa chọn ảnh: không in <img> không có địa chỉ (hiện icon ảnh hỏng)
|
|
353
375
|
const fx = imageFx(a);
|
|
354
|
-
const img = _jsx("img", { src: imgSrc, srcSet: a.srcset || undefined, sizes: a.srcset ? sizes : undefined, alt: a.alt ?? "", title: a.title ?? undefined, width: a.width ?? undefined, height: a.height ?? undefined, loading: "lazy", decoding: "async", className: fx.className || undefined, style: fx.style });
|
|
376
|
+
const img = _jsx("img", { src: imgSrc, srcSet: a.srcset || undefined, sizes: a.srcset ? sizes : undefined, alt: a.alt ?? "", title: a.title ?? undefined, width: sz?.width ?? a.width ?? undefined, height: sz?.height ?? a.height ?? undefined, loading: "lazy", decoding: "async", className: fx.className || undefined, style: fx.style });
|
|
355
377
|
const bare = a.webpSrcset ? _jsxs("picture", { children: [_jsx("source", { type: "image/webp", srcSet: a.webpSrcset, sizes: sizes }), img] }) : img;
|
|
356
378
|
// next: ảnh có liên kết (href qua safeUrl; mở tab mới thì noopener)
|
|
357
379
|
const pic = a.lightbox === true && !a.href ? _jsx(LightboxClient, { src: safeUrl(a.src, ""), alt: a.alt ?? "", children: bare }) : a.href ? _jsx(Link, { href: safeUrl(a.href), target: a.linkTarget === "_blank" ? "_blank" : undefined, rel: a.linkTarget === "_blank" ? "noopener noreferrer" : undefined, children: bare }) : bare;
|
|
@@ -379,8 +401,13 @@ async function renderNodeInner(node, key, ctx) {
|
|
|
379
401
|
}
|
|
380
402
|
return _jsxs("figure", { className: blockShell("gallery", a).className, style: blockShell("gallery", a).style, children: [items.map((im, i) => galleryItem(im, i)), caption] }, key);
|
|
381
403
|
}
|
|
382
|
-
case "video":
|
|
383
|
-
|
|
404
|
+
case "video": {
|
|
405
|
+
// Link YouTube / Vimeo… dán vào khối Video → khung nhúng (thẻ <video> không phát được trang web)
|
|
406
|
+
const embed = embedInfo(a.src);
|
|
407
|
+
if (embed)
|
|
408
|
+
return _jsxs("figure", { className: "ecx-video cms-video", children: [_jsx("div", { style: embed.aspect ? { position: "relative", aspectRatio: String(embed.aspect) } : { position: "relative", height: embed.height }, children: _jsx("iframe", { src: embed.src, title: a.caption || embed.title, loading: "lazy", allowFullScreen: true, referrerPolicy: "strict-origin-when-cross-origin", allow: "autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture", style: { position: "absolute", inset: 0, width: "100%", height: "100%", border: 0, borderRadius: 8 } }) }), a.caption && _jsx("figcaption", { children: a.caption })] }, key);
|
|
409
|
+
return _jsxs("figure", { className: "ecx-video cms-video", children: [_jsx("video", { src: safeUrl(a.src, ""), poster: a.poster ? safeUrl(a.poster, "") : undefined, controls: a.controls !== false, autoPlay: a.autoplay === true, loop: a.loop === true, muted: a.muted === true || a.autoplay === true, preload: ["none", "metadata", "auto"].includes(a.preload) ? a.preload : "metadata", playsInline: a.playsInline !== false, width: Number(a.width) || undefined, height: Number(a.height) || undefined, style: { width: "100%", height: "auto" } }), a.caption && _jsx("figcaption", { children: a.caption })] }, key);
|
|
410
|
+
}
|
|
384
411
|
case "audio":
|
|
385
412
|
return _jsxs("figure", { className: "ecx-audio cms-audio", children: [_jsx("audio", { src: safeUrl(a.src, ""), controls: true, autoPlay: a.autoplay === true, loop: a.loop === true, preload: ["none", "metadata", "auto"].includes(a.preload) ? a.preload : "metadata", style: { width: "100%" } }), a.caption && _jsx("figcaption", { children: a.caption })] }, key);
|
|
386
413
|
case "file": {
|
|
@@ -398,9 +425,9 @@ async function renderNodeInner(node, key, ctx) {
|
|
|
398
425
|
const body = rows.slice(head ? 1 : 0, foot ? -1 : undefined);
|
|
399
426
|
return _jsx("div", { className: tableClass(a), children: _jsxs("table", { className: a.fixed ? "is-fixed" : undefined, children: [typeof a.caption === "string" && a.caption.trim() && _jsx("caption", { children: a.caption }), head && _jsx("thead", { children: rows[0] }), _jsx("tbody", { children: body }), foot && _jsx("tfoot", { children: rows.at(-1) })] }) }, key);
|
|
400
427
|
}
|
|
401
|
-
case "tableRow": return _jsx("tr", { children: await children() }, key);
|
|
402
|
-
case "tableHeader": return _jsx("th", { colSpan: a.colspan > 1 ? a.colspan : undefined, rowSpan: a.rowspan > 1 ? a.rowspan : undefined, children: await children() }, key);
|
|
403
|
-
case "tableCell": return _jsx("td", { colSpan: a.colspan > 1 ? a.colspan : undefined, rowSpan: a.rowspan > 1 ? a.rowspan : undefined, children: await children() }, key);
|
|
428
|
+
case "tableRow": return _jsx("tr", { style: Number(a.height) > 0 ? { height: Number(a.height) } : undefined, children: await children() }, key);
|
|
429
|
+
case "tableHeader": return _jsx("th", { colSpan: a.colspan > 1 ? a.colspan : undefined, rowSpan: a.rowspan > 1 ? a.rowspan : undefined, style: cellWidth(a), children: await children() }, key);
|
|
430
|
+
case "tableCell": return _jsx("td", { colSpan: a.colspan > 1 ? a.colspan : undefined, rowSpan: a.rowspan > 1 ? a.rowspan : undefined, style: cellWidth(a), children: await children() }, key);
|
|
404
431
|
// Bố cục (@ecomcx/ecomweb-content 1.2). Cấu trúc dùng style trực tiếp → mọi theme hiển thị đúng; class `ecx-*` để theme tạo kiểu thêm (`cms-*` giữ tới 2.0).
|
|
405
432
|
case "columns": {
|
|
406
433
|
const cols = await Promise.all((node.content ?? []).map(async (c, i) => {
|
package/dist/types.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export interface Media {
|
|
|
37
37
|
sizes: Record<string, MediaSize>;
|
|
38
38
|
/** Bản WebP của ảnh gốc. */
|
|
39
39
|
webpUrl?: string | null;
|
|
40
|
+
/** Video: ảnh poster (CMS ≥ 1.37). */
|
|
41
|
+
posterUrl?: string | null;
|
|
42
|
+
/** Video: thời lượng (giây). */
|
|
43
|
+
duration?: number | null;
|
|
40
44
|
/** Điểm lấy nét 0–1 (object-position). */
|
|
41
45
|
focalX?: number | null;
|
|
42
46
|
focalY?: number | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-theme-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "SDK để viết theme và phần frontend của plugin cho Ecomweb",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"API.md"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ecomcx/ecomweb-content": "^1.
|
|
39
|
+
"@ecomcx/ecomweb-content": "^1.30.0",
|
|
40
40
|
"intl-messageformat": "12.1.3",
|
|
41
41
|
"server-only": "0.0.1"
|
|
42
42
|
},
|