@ecomcx/ecomweb-theme-sdk 1.32.0 → 1.33.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.d.ts CHANGED
@@ -108,3 +108,20 @@ export declare function LanguageSwitcherClient({ languages, current, defaultLoca
108
108
  }): import("react").JSX.Element;
109
109
  export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS, type AuthLabels, type AuthPaths, type SignInProvider } from "./auth-forms.js";
110
110
  export { safeRedirect, type CurrentUser } from "./auth-shared.js";
111
+ /** Khối countdown: đếm ngược tới `target` (ms). Dựng lần đầu cùng giá trị trên máy chủ, rồi cập nhật mỗi giây. */
112
+ export declare function CountdownClient({ target, label, expiredText }: {
113
+ target: number;
114
+ label?: string;
115
+ expiredText?: string;
116
+ }): import("react").JSX.Element;
117
+ /** Khối tabs: các panel đã vẽ sẵn trên máy chủ (nội dung vẫn có trong HTML cho SEO); chỉ đổi panel đang hiện. */
118
+ export declare function TabsClient({ titles, panels }: {
119
+ titles: string[];
120
+ panels: ReactNode[];
121
+ }): import("react").JSX.Element;
122
+ /** Phóng to ảnh: bấm ảnh mở lớp phủ (Esc hoặc bấm nền để đóng). `src` đã qua safeUrl ở máy chủ. */
123
+ export declare function LightboxClient({ src, alt, children }: {
124
+ src: string;
125
+ alt: string;
126
+ children: ReactNode;
127
+ }): import("react").JSX.Element;
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { extraFields } from "./auth-forms.js";
4
- import { Component, Suspense, useEffect, useState } from "react";
4
+ import { Component, Suspense, useEffect, useId, useState } from "react";
5
5
  import { usePathname, useRouter } from "next/navigation";
6
6
  import NextLink, { useLinkStatus } from "next/link";
7
7
  import NextForm from "next/form";
@@ -190,3 +190,43 @@ export function LanguageSwitcherClient({ languages, current, defaultLocale, labe
190
190
  }
191
191
  export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
192
192
  export { safeRedirect } from "./auth-shared.js";
193
+ /** Khối countdown: đếm ngược tới `target` (ms). Dựng lần đầu cùng giá trị trên máy chủ, rồi cập nhật mỗi giây. */
194
+ export function CountdownClient({ target, label, expiredText }) {
195
+ const [now, setNow] = useState(() => Date.now());
196
+ useEffect(() => { const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, []);
197
+ const left = Math.max(0, target - now);
198
+ if (left === 0 && expiredText)
199
+ return _jsx("div", { className: "ecx-countdown is-expired", children: expiredText });
200
+ const p = (n) => String(n).padStart(2, "0");
201
+ const s = Math.floor(left / 1000);
202
+ const parts = [["d", Math.floor(s / 86400)], ["h", Math.floor(s / 3600) % 24], ["m", Math.floor(s / 60) % 60], ["s", s % 60]];
203
+ return (_jsxs("div", { className: "ecx-countdown", role: "timer", "aria-live": "off", suppressHydrationWarning: true, children: [label && _jsx("p", { className: "ecx-countdown-label", children: label }), _jsx("div", { className: "ecx-countdown-parts", children: parts.map(([u, n]) => _jsxs("span", { className: `ecx-countdown-${u}`, children: [_jsx("strong", { children: p(n) }), _jsx("small", { children: u })] }, u)) })] }));
204
+ }
205
+ /** Khối tabs: các panel đã vẽ sẵn trên máy chủ (nội dung vẫn có trong HTML cho SEO); chỉ đổi panel đang hiện. */
206
+ export function TabsClient({ titles, panels }) {
207
+ const [active, setActive] = useState(0);
208
+ const id = useId();
209
+ const move = (e, i) => {
210
+ const n = titles.length;
211
+ const next = e.key === "ArrowRight" ? (i + 1) % n : e.key === "ArrowLeft" ? (i + n - 1) % n : e.key === "Home" ? 0 : e.key === "End" ? n - 1 : -1;
212
+ if (next < 0)
213
+ return;
214
+ e.preventDefault();
215
+ setActive(next);
216
+ document.getElementById(`${id}-t${next}`)?.focus();
217
+ };
218
+ return (_jsxs("div", { className: "ecx-tabs", children: [_jsx("div", { role: "tablist", className: "ecx-tabs-list", children: titles.map((t, i) => (_jsx("button", { type: "button", role: "tab", id: `${id}-t${i}`, "aria-selected": i === active, "aria-controls": `${id}-p${i}`, tabIndex: i === active ? 0 : -1, className: cx("ecx-tab-button", i === active && "is-active"), onClick: () => setActive(i), onKeyDown: (e) => move(e, i), children: t }, i))) }), panels.map((p, i) => _jsx("div", { role: "tabpanel", id: `${id}-p${i}`, "aria-labelledby": `${id}-t${i}`, hidden: i !== active, className: "ecx-tab-panel", children: p }, i))] }));
219
+ }
220
+ /** Phóng to ảnh: bấm ảnh mở lớp phủ (Esc hoặc bấm nền để đóng). `src` đã qua safeUrl ở máy chủ. */
221
+ export function LightboxClient({ src, alt, children }) {
222
+ const [open, setOpen] = useState(false);
223
+ useEffect(() => {
224
+ if (!open)
225
+ return;
226
+ const onKey = (e) => { if (e.key === "Escape")
227
+ setOpen(false); };
228
+ document.addEventListener("keydown", onKey);
229
+ return () => document.removeEventListener("keydown", onKey);
230
+ }, [open]);
231
+ return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "ecx-lightbox-trigger", "aria-haspopup": "dialog", onClick: () => setOpen(true), style: { all: "unset", display: "block", cursor: "zoom-in" }, children: children }), open && (_jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": alt || "Image", className: "ecx-lightbox", onClick: () => setOpen(false), style: { position: "fixed", inset: 0, zIndex: 9999, background: "rgba(0,0,0,.85)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "zoom-out" }, children: _jsx("img", { src: src, alt: alt, style: { maxWidth: "95vw", maxHeight: "95vh", objectFit: "contain" } }) }))] }));
232
+ }
@@ -24,10 +24,14 @@ export declare function SearchForm({ defaultValue, placeholder, buttonLabel }: {
24
24
  placeholder?: string;
25
25
  buttonLabel?: string;
26
26
  }): Promise<import("react").JSX.Element>;
27
- export declare function Pagination({ data, prevLabel, nextLabel }: {
27
+ /** `pageParam`: phân trang bằng tham số URL (?qpage=2) thay cho /page/2 — dùng cho khối Query nằm trong trang, không phải trang lưu trữ. */
28
+ export declare function Pagination({ data, prevLabel, nextLabel, pageParam, type, midSize }: {
28
29
  data: ResolveResult;
29
30
  prevLabel?: string;
30
31
  nextLabel?: string;
32
+ pageParam?: string;
33
+ type?: "numbers" | "prevNext" | "both";
34
+ midSize?: number;
31
35
  }): Promise<import("react").JSX.Element | null>;
32
36
  /** Ảnh đại diện: responsive, WebP, srcset. */
33
37
  export declare function FeaturedImage({ media, size, className, link, sizes, priority }: {
@@ -89,7 +89,15 @@ export async function SearchForm({ defaultValue, placeholder, buttonLabel }) {
89
89
  const [t, site] = await Promise.all([getT(), getSite()]);
90
90
  return _jsx(SearchFormClient, { action: localeHref(site, "/"), defaultValue: defaultValue, placeholder: placeholder ?? t("search.placeholder"), label: t("search.label"), buttonLabel: buttonLabel ?? t("search.button") });
91
91
  }
92
- export async function Pagination({ data, prevLabel, nextLabel }) {
92
+ function paramLink(data, param, p) {
93
+ const q = new URLSearchParams(Object.entries(data.query ?? {}).filter(([k]) => k !== param));
94
+ if (p > 1)
95
+ q.set(param, String(p));
96
+ const s = q.toString();
97
+ return s ? `${data.basePath}?${s}` : data.basePath;
98
+ }
99
+ /** `pageParam`: phân trang bằng tham số URL (?qpage=2) thay cho /page/2 — dùng cho khối Query nằm trong trang, không phải trang lưu trữ. */
100
+ export async function Pagination({ data, prevLabel, nextLabel, pageParam, type = "both", midSize = 2 }) {
93
101
  if (data.totalPages <= 1)
94
102
  return null;
95
103
  const t = await getT();
@@ -97,19 +105,19 @@ export async function Pagination({ data, prevLabel, nextLabel }) {
97
105
  nextLabel ??= t("pagination.next");
98
106
  const pages = [];
99
107
  for (let i = 1; i <= data.totalPages; i++) {
100
- if (i === 1 || i === data.totalPages || Math.abs(i - data.page) <= 2)
108
+ if (i === 1 || i === data.totalPages || Math.abs(i - data.page) <= midSize)
101
109
  pages.push(i);
102
110
  else if (pages[pages.length - 1] !== "…")
103
111
  pages.push("…");
104
112
  }
105
113
  // Danh sách có bộ lọc (?phong-ban=…, ?muc-luong=…) → giữ nguyên bộ lọc khi chuyển trang
106
114
  const hasFilters = Object.keys(data.query ?? {}).some((k) => k !== "s" && k !== "page");
107
- const link = (p) => hasFilters
115
+ const link = (p) => pageParam ? paramLink(data, pageParam, p) : hasFilters
108
116
  ? pageLinkWithQuery(data.basePath, p, data.query)
109
117
  : pageLink(data.basePath, p, data.kind === "search" ? data.search : null);
110
- return (_jsxs("nav", { className: "pagination", "aria-label": t("pagination.label"), children: [data.page > 1 && _jsx(Link, { className: "prev", href: link(data.page - 1), children: prevLabel }), pages.map((p, i) => p === "…" ? _jsx("span", { className: "dots", children: "\u2026" }, `e${i}`)
118
+ return (_jsxs("nav", { className: "pagination", "aria-label": t("pagination.label"), children: [type !== "numbers" && data.page > 1 && _jsx(Link, { className: "prev", href: link(data.page - 1), children: prevLabel }), type !== "prevNext" && pages.map((p, i) => p === "…" ? _jsx("span", { className: "dots", children: "\u2026" }, `e${i}`)
111
119
  : p === data.page ? _jsx("span", { className: "current", "aria-current": "page", children: p }, p)
112
- : _jsx(Link, { href: link(p), children: p }, p)), data.page < data.totalPages && _jsx(Link, { className: "next", href: link(data.page + 1), children: nextLabel })] }));
120
+ : _jsx(Link, { href: link(p), children: p }, p)), type !== "numbers" && data.page < data.totalPages && _jsx(Link, { className: "next", href: link(data.page + 1), children: nextLabel })] }));
113
121
  }
114
122
  /** Ảnh đại diện: responsive, WebP, srcset. */
115
123
  export function FeaturedImage({ media, size = "large", className, link, sizes, priority }) {
package/dist/content.js CHANGED
@@ -48,9 +48,13 @@ export async function contentContext(site, post, data) {
48
48
  const t = await getT();
49
49
  // Bản nháp (xem trực tiếp / Trình dựng) không vào cache công khai → được gắn vị trí khối cho khung soạn
50
50
  const markBlocks = await import("next/headers").then(async ({ draftMode }) => (await draftMode()).isEnabled).catch(() => false);
51
- const blocks = (await getActiveExtensions(site)).flatMap((d) => d.blockTypes ?? []);
51
+ const extensions = await getActiveExtensions(site);
52
+ const blocks = extensions.flatMap((d) => d.blockTypes ?? []);
53
+ // Không plugin nào đăng ký "block.render" thì không tốn một lần gọi filter cho mỗi khối
54
+ const hasBlockFilter = extensions.some((d) => d.filters?.["block.render"]);
52
55
  return {
53
56
  site, post, data, blocks, markBlocks,
57
+ filterBlock: hasBlockFilter ? (node, el) => applyFilters("block.render", el, { node, site, post }, site) : undefined,
54
58
  resolve: { shortcode: (name) => findShortcode(name, site), block: (type) => findBlock(type, site) },
55
59
  labels: { download: t("file.download"), toc: t("toc.title") },
56
60
  boundary: (name, key, el) => _jsx(ExtensionBoundary, { name: name, children: el }, key),
package/dist/dynamic.js CHANGED
@@ -36,12 +36,14 @@ export async function renderDynamic(node, key, ctx, children) {
36
36
  const location = String(a.location ?? "primary");
37
37
  const menu = _jsx(Menu, { location: location, className: "ecx-navigation-menu" });
38
38
  const t = await getT();
39
- return (_jsxs("div", { className: cx("ecx-navigation", `ecx-navigation-${a.orientation ?? "horizontal"}`, a.mobile !== false && "has-mobile"), children: [_jsx("div", { className: "ecx-navigation-items", children: menu }), a.mobile !== false && _jsxs("details", { className: "ecx-navigation-toggle", children: [_jsx("summary", { "aria-label": t("navigation.menu"), children: "\u2630" }), menu] })] }, key));
39
+ // next: overlayMenu never|mobile|always; thiếu thì theo `mobile` cũ
40
+ const overlay = ["never", "mobile", "always"].includes(a.overlayMenu) ? a.overlayMenu : a.mobile === false ? "never" : "mobile";
41
+ return (_jsxs("div", { className: cx("ecx-navigation", `ecx-navigation-${a.orientation ?? "horizontal"}`, overlay !== "never" && "has-mobile", overlay === "always" && "overlay-always"), children: [overlay !== "always" && _jsx("div", { className: "ecx-navigation-items", children: menu }), overlay !== "never" && _jsxs("details", { className: "ecx-navigation-toggle", children: [_jsx("summary", { "aria-label": t("navigation.menu"), children: "\u2630" }), menu] })] }, key));
40
42
  }
41
43
  case "search":
42
44
  return _jsx("div", { className: "ecx-search", children: _jsx(SearchForm, { defaultValue: ctx.data?.search, placeholder: a.placeholder, buttonLabel: a.buttonText }) }, key);
43
45
  case "languageSwitcher":
44
- return _jsx(LanguageSwitcher, { className: "ecx-language-switcher" }, key);
46
+ return _jsx(LanguageSwitcher, { className: "ecx-language-switcher", variant: a.display === "dropdown" ? "select" : "list" }, key);
45
47
  case "copyright":
46
48
  return _jsxs("p", { className: "ecx-copyright", style: align(a), children: ["\u00A9 ", new Date().getFullYear(), " ", a.text || site.title] }, key);
47
49
  case "postTitle": {
@@ -67,17 +69,35 @@ export async function renderDynamic(node, key, ctx, children) {
67
69
  return _jsx("div", { className: "ecx-featured-image", style: ratio ? { aspectRatio: ratio, overflow: "hidden" } : undefined, children: _jsx(FeaturedImage, { media: post.featuredMedia, size: a.size ?? "large", link: a.link ? post.link : undefined }) }, key);
68
70
  }
69
71
  case "postDate":
70
- return post ? _jsx("p", { className: "ecx-post-date", style: align(a), children: _jsx(PostDate, { post: post, site: site }) }, key) : null;
72
+ return post ? _jsx("p", { className: "ecx-post-date", style: align(a), children: _jsx(PostDate, { post: a.displayType === "modified" ? { ...post, publishedAt: post.updatedAt } : post, site: site }) }, key) : null;
71
73
  case "postAuthor":
72
74
  if (!post?.author)
73
75
  return null;
74
- return _jsxs("p", { className: "ecx-post-author", children: [a.avatar && post.author.avatarUrl && _jsx("img", { src: post.author.avatarUrl, alt: "", width: 32, height: 32, style: { borderRadius: "50%", verticalAlign: "middle", marginRight: 8 } }), _jsx(Link, { href: localeHref(site, `/author/${post.author.slug}`), rel: "author", children: post.author.name })] }, key);
76
+ {
77
+ const size = Math.min(128, Math.max(16, Number(a.avatarSize) || 32));
78
+ const name = a.showName === false ? null : a.link === false ? _jsx("span", { children: post.author.name }) : _jsx(Link, { href: localeHref(site, `/author/${post.author.slug}`), rel: "author", children: post.author.name });
79
+ return _jsxs("p", { className: "ecx-post-author", children: [a.avatar && post.author.avatarUrl && _jsx("img", { src: post.author.avatarUrl, alt: a.showName === false ? post.author.name : "", width: size, height: size, style: { borderRadius: "50%", verticalAlign: "middle", marginRight: name ? 8 : 0 } }), name, a.showBio === true && post.author.bio && _jsxs("span", { className: "ecx-post-author-bio", children: [" ", post.author.bio] })] }, key);
80
+ }
81
+ case "readMore":
82
+ return post ? _jsx("p", { className: "ecx-read-more", style: align(a), children: _jsx(Link, { href: post.link, children: a.text || (await getT())("post.read_more") }) }, key) : null;
83
+ case "commentsCount":
84
+ return post ? _jsx("p", { className: "ecx-comments-count", style: align(a), children: post.commentCount }, key) : null;
85
+ case "avatar": {
86
+ const size = Math.min(256, Math.max(16, Number(a.size) || 48));
87
+ const au = post?.author;
88
+ if (!au?.avatarUrl)
89
+ return null;
90
+ const img = _jsx("img", { src: au.avatarUrl, alt: au.name, width: size, height: size, loading: "lazy", style: { borderRadius: "50%" } });
91
+ return _jsx("span", { className: "ecx-avatar", children: a.link === false ? img : _jsx(Link, { href: localeHref(site, `/author/${au.slug}`), rel: "author", children: img }) }, key);
92
+ }
93
+ case "queryTotal":
94
+ return ctx.query?.data ? _jsx("p", { className: "ecx-query-total", style: align(a), children: ctx.query.data.total }, key) : null;
75
95
  case "postTerms": {
76
96
  const terms = post?.terms?.[a.taxonomy ?? "category"];
77
97
  return terms?.length ? _jsx("p", { className: "ecx-post-terms", children: _jsx(TermLinks, { terms: terms, separator: a.separator ?? ", " }) }, key) : null;
78
98
  }
79
99
  case "comments":
80
- return post && ctx.data?.post?.id === post.id ? _jsx(Comments, { post: post }, key) : null;
100
+ return post && ctx.data?.post?.id === post.id ? _jsx(Comments, { post: post, title: a.title ? String(a.title) : undefined }, key) : null;
81
101
  // H1 của trang lưu trữ / tìm kiếm / tác giả (trang chủ dạng danh sách bài: tên trang)
82
102
  case "queryTitle": {
83
103
  const d = ctx.data;
@@ -130,17 +150,28 @@ export async function renderDynamic(node, key, ctx, children) {
130
150
  case "query": {
131
151
  let posts;
132
152
  let data;
153
+ let pageParam;
133
154
  if (a.inherit !== false && ctx.data?.posts) {
134
155
  posts = ctx.data.posts;
135
156
  data = ctx.data;
136
157
  }
137
158
  else {
138
159
  const taxonomy = a.category ? "category" : a.tag ? "post_tag" : undefined;
139
- const res = await getPosts({ type: a.postType ?? "post", perPage: a.perPage ?? 10, taxonomy, term: a.category || a.tag || undefined,
140
- orderBy: a.orderBy ?? "date", order: a.order ?? "desc" }).catch(() => null);
160
+ const exclude = String(a.exclude ?? "").split(",").map((x) => Number(x.trim())).filter((x) => Number.isInteger(x) && x > 0);
161
+ // paginate: khối nằm trong một trang → phân trang bằng ?qpage=N (không đụng /page/N của chính trang)
162
+ const paginate = a.paginate === true && !!ctx.data;
163
+ const page = paginate ? Math.max(1, Math.floor(Number(ctx.data?.query?.qpage)) || 1) : 1;
164
+ const res = await getPosts({ page, type: a.postType ?? "post", perPage: a.perPage ?? 10, taxonomy, term: a.category || a.tag || undefined,
165
+ orderBy: a.orderBy ?? "date", order: a.order ?? "desc",
166
+ authorId: typeof a.authorId === "number" ? a.authorId : undefined, search: a.search || undefined, exclude: exclude.length ? exclude : undefined,
167
+ sticky: a.sticky === "only" ? true : a.sticky === "exclude" ? false : undefined, orderByMeta: a.orderByMeta || undefined }).catch(() => null);
141
168
  posts = res?.items ?? [];
169
+ if (paginate && res && ctx.data) {
170
+ data = { ...ctx.data, page: res.page, totalPages: res.totalPages, total: res.total };
171
+ pageParam = "qpage";
172
+ }
142
173
  }
143
- return _jsx("div", { className: "ecx-query", children: await children({ ...ctx, query: { posts, data } }) }, key);
174
+ return _jsx("div", { className: "ecx-query", children: await children({ ...ctx, query: { posts, data, pageParam } }) }, key);
144
175
  }
145
176
  case "postTemplate": {
146
177
  const posts = ctx.query?.posts ?? [];
@@ -152,7 +183,7 @@ export async function renderDynamic(node, key, ctx, children) {
152
183
  return _jsx("ul", { className: cx("ecx-post-template", grid && "is-grid"), style: style, children: items }, key);
153
184
  }
154
185
  case "pagination":
155
- return ctx.query?.data ? _jsx(Pagination, { data: ctx.query.data }, key) : null;
186
+ return ctx.query?.data ? _jsx(Pagination, { data: ctx.query.data, pageParam: ctx.query.pageParam, type: ["numbers", "prevNext", "both"].includes(a.type) ? a.type : "both", midSize: Math.min(5, Math.max(0, Number.isFinite(Number(a.midSize)) ? Number(a.midSize) : 2)) }, key) : null;
156
187
  case "queryEmpty":
157
188
  return ctx.query && !ctx.query.posts.length ? _jsx("div", { className: "ecx-query-empty", children: await children(ctx) }, key) : null;
158
189
  case "syncedPattern": {
package/dist/i18n.js CHANGED
@@ -6,7 +6,7 @@ import { formatMessage } from "./i18n-format.js";
6
6
  export const BUILTIN = {
7
7
  vi: {
8
8
  "search.placeholder": "Tìm kiếm…", "search.button": "Tìm", "search.label": "Từ khoá", "navigation.menu": "Menu", "toc.title": "Mục lục", "query.search": "Kết quả tìm kiếm: {q}", "query.category": "Chuyên mục: {name}", "query.tag": "Thẻ: {name}", "query.author": "Tác giả: {name}", "breadcrumbs.home": "Trang chủ", "breadcrumbs.label": "Đường dẫn", "postNav.previous": "Bài trước", "postNav.next": "Bài sau", "postNav.label": "Bài khác",
9
- "pagination.prev": "« Trước", "pagination.next": "Sau »", "pagination.label": "Phân trang",
9
+ "post.read_more": "Đọc tiếp", "pagination.prev": "« Trước", "pagination.next": "Sau »", "pagination.label": "Phân trang",
10
10
  "comments.title": "Bình luận", "comments.closed": "Bình luận đã đóng.",
11
11
  "comments.form.title": "Để lại bình luận", "comments.form.content": "Bình luận", "comments.form.name": "Tên",
12
12
  "comments.form.email": "Email", "comments.form.website": "Website", "comments.form.submit": "Gửi bình luận",
@@ -31,7 +31,7 @@ export const BUILTIN = {
31
31
  },
32
32
  en: {
33
33
  "search.placeholder": "Search…", "search.button": "Search", "search.label": "Keyword", "navigation.menu": "Menu", "toc.title": "Contents", "query.search": "Search results: {q}", "query.category": "Category: {name}", "query.tag": "Tag: {name}", "query.author": "Author: {name}", "breadcrumbs.home": "Home", "breadcrumbs.label": "Breadcrumb", "postNav.previous": "Previous", "postNav.next": "Next", "postNav.label": "More posts",
34
- "pagination.prev": "« Previous", "pagination.next": "Next »", "pagination.label": "Pagination",
34
+ "post.read_more": "Read more", "pagination.prev": "« Previous", "pagination.next": "Next »", "pagination.label": "Pagination",
35
35
  "comments.title": "Comments", "comments.closed": "Comments are closed.",
36
36
  "comments.form.title": "Leave a comment", "comments.form.content": "Comment", "comments.form.name": "Name",
37
37
  "comments.form.email": "Email", "comments.form.website": "Website", "comments.form.submit": "Post comment",
package/dist/rich.d.ts CHANGED
@@ -13,6 +13,8 @@ export interface RenderContext {
13
13
  /** Khối của plugin: khối cấp cao nhất và nút trong nội dung soạn thảo dùng chung một renderer (definePlugin → blocks). */
14
14
  block(type: string): Promise<ComponentType<BlockProps> | null>;
15
15
  };
16
+ /** Filter "block.render": plugin bọc / thay phần tử đã vẽ của MỌI khối (kể cả khối lõi). Chỉ có khi có plugin đăng ký filter này. */
17
+ filterBlock?(node: Node, el: ReactNode): Promise<ReactNode>;
16
18
  /** Bọc component của plugin (lỗi chỉ ẩn phần đó). Mặc định: không bọc. */
17
19
  boundary?(name: string, key: string, el: ReactNode): ReactNode;
18
20
  /** Khối của plugin (defineBlock) — chuẩn hoá thuộc tính + nâng phiên bản khối lưu bằng bản cũ. */
@@ -26,10 +28,13 @@ export interface RenderContext {
26
28
  data?: ResolveResult;
27
29
  /** Vẽ khối động (@ecomcx/ecomweb-content DYNAMIC_NODES). Không có → khối động bị bỏ qua. */
28
30
  dynamic?(node: RenderNode, key: string, ctx: RenderContext, children: (ctx: RenderContext, nodes?: RenderNode[]) => Promise<ReactNode[]>): Promise<ReactNode>;
31
+ /** Tên nhóm của khối accordion đang vẽ: các `details` con dùng chung `name` để mở một mục thì mục khác đóng. */
32
+ accordion?: string;
29
33
  /** Bài của vòng lặp `query` gần nhất (+ dữ liệu phân trang khi dùng danh sách của trang). */
30
34
  query?: {
31
35
  posts: Post[];
32
36
  data?: ResolveResult;
37
+ pageParam?: string;
33
38
  };
34
39
  /** Nội dung template part theo slug (khối templatePart). */
35
40
  parts?(slug: string): Promise<ContentDoc | null>;
package/dist/rich.js CHANGED
@@ -3,6 +3,7 @@ import { Fragment, cloneElement, isValidElement } from "react";
3
3
  import { DYNAMIC_NODES, colorCss, embedInfo, motionClasses, normalizeContent, safeUrl, spacingValue, styleClass, styleCss } from "@ecomcx/ecomweb-content";
4
4
  import { cx } from "./utils.js";
5
5
  import { SOCIAL_ICONS } from "./social-icons.js";
6
+ import { CountdownClient, LightboxClient, TabsClient } from "./client.js";
6
7
  const DYNAMIC = new Set(DYNAMIC_NODES);
7
8
  const SHORTCODE = /^\s*\[([a-z0-9_-]+)((?:\s+[a-z0-9_-]+=(?:"[^"]*"|'[^']*'|[^\s\]]+))*)\s*\]\s*$/i;
8
9
  const SHORTCODE_INLINE = /\[([a-z0-9_-]+)((?:\s+[a-z0-9_-]+=(?:"[^"]*"|'[^']*'|[^\s\]]+))*)\s*\]/gi;
@@ -191,7 +192,9 @@ async function applyBindings(node, ctx) {
191
192
  async function renderNode(node, key, ctx) {
192
193
  if (node.attrs?.bindings)
193
194
  node = await applyBindings(node, ctx);
194
- const el = await renderNodeInner(node, key, ctx);
195
+ let el = await renderNodeInner(node, key, ctx);
196
+ if (ctx.filterBlock && node.type !== "text" && node.type !== "doc")
197
+ el = await ctx.filterBlock(node, el);
195
198
  const a = node.attrs;
196
199
  const out = a && (a.style || a.blockStyle || a.className || a.anchor) ? decorate(el, a, key, ctx) : el;
197
200
  return ctx.markBlocks && ctx.source && ctx.pathRoot != null && key.startsWith(ctx.pathRoot + "-") && !UNMARKED.has(node.type)
@@ -236,11 +239,11 @@ async function renderNodeInner(node, key, ctx) {
236
239
  return _jsx(Tag, { id: id || undefined, style: alignStyle(a), children: await children() }, key);
237
240
  }
238
241
  case "bulletList": return _jsx("ul", { children: await children() }, key);
239
- case "orderedList": return _jsx("ol", { start: a.start && a.start !== 1 ? a.start : undefined, children: await children() }, key);
242
+ case "orderedList": return _jsx("ol", { start: a.start && a.start !== 1 ? a.start : undefined, reversed: a.reversed === true || undefined, children: await children() }, key);
240
243
  case "listItem": return _jsx("li", { children: await children() }, key);
241
244
  case "taskList": return _jsx("ul", { className: "ecx-task-list task-list", children: await children() }, key);
242
245
  case "taskItem": return _jsxs("li", { className: "ecx-task-item task-item", children: [_jsx("input", { type: "checkbox", checked: !!a.checked, readOnly: true }), " ", await children()] }, key);
243
- case "blockquote": return _jsx("blockquote", { children: await children() }, key);
246
+ case "blockquote": return _jsxs("blockquote", { children: [await children(), a.citation && _jsx("cite", { children: a.citation })] }, key);
244
247
  case "codeBlock": return _jsx("pre", { children: _jsx("code", { className: a.language ? `language-${a.language}` : undefined, children: plainText(node) }) }, key);
245
248
  case "hardBreak": return _jsx("br", {}, key);
246
249
  case "horizontalRule": return _jsx("hr", {}, key);
@@ -249,23 +252,26 @@ async function renderNodeInner(node, key, ctx) {
249
252
  // 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
250
253
  const sizes = a.width ? `(max-width: ${a.width}px) 100vw, ${a.width}px` : (a.sizes || "(max-width: 1024px) 100vw, 1024px");
251
254
  const img = _jsx("img", { src: safeUrl(a.src, ""), 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" });
252
- const pic = a.webpSrcset ? _jsxs("picture", { children: [_jsx("source", { type: "image/webp", srcSet: a.webpSrcset, sizes: sizes }), img] }) : img;
255
+ const bare = a.webpSrcset ? _jsxs("picture", { children: [_jsx("source", { type: "image/webp", srcSet: a.webpSrcset, sizes: sizes }), img] }) : img;
256
+ // next: ảnh có liên kết (href qua safeUrl; mở tab mới thì noopener)
257
+ const pic = a.lightbox === true && !a.href ? _jsx(LightboxClient, { src: safeUrl(a.src, ""), alt: a.alt ?? "", children: bare }) : a.href ? _jsx("a", { href: safeUrl(a.href), target: a.linkTarget === "_blank" ? "_blank" : undefined, rel: a.linkTarget === "_blank" ? "noopener noreferrer" : undefined, children: bare }) : bare;
253
258
  const cls = cx("ecx-image cms-image", a.align && `ecx-align-${a.align} align${a.align}`, a.mediaId && `ecx-image-${a.mediaId} cms-image-${a.mediaId}`);
254
259
  return a.caption || a.align ? _jsxs("figure", { className: cls, children: [pic, a.caption && _jsx("figcaption", { children: a.caption })] }, key) : _jsx(Fragment, { children: pic }, key);
255
260
  }
256
261
  case "gallery": {
257
262
  const items = (a.images ?? []);
258
263
  const cols = Math.min(6, Math.max(1, Number(a.columns) || 3));
264
+ const crop = a.imageCrop !== false; // next: imageCrop=false giữ nguyên tỉ lệ ảnh
259
265
  return (_jsxs("figure", { className: cx("ecx-gallery cms-gallery", `ecx-gallery-columns-${cols} columns-${cols}`), style: { display: "grid", gap: 8, gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))` }, children: [items.map((im, i) => {
260
- const el = _jsx("img", { src: safeUrl(im.src, ""), srcSet: im.srcset || undefined, sizes: `(max-width: 768px) 50vw, ${Math.round(100 / cols)}vw`, alt: im.alt ?? "", width: im.width, height: im.height, loading: "lazy", decoding: "async", style: { width: "100%", height: "100%", objectFit: "cover", aspectRatio: "1" } });
266
+ const el = _jsx("img", { src: safeUrl(im.src, ""), srcSet: im.srcset || undefined, sizes: `(max-width: 768px) 50vw, ${Math.round(100 / cols)}vw`, alt: im.alt ?? "", width: im.width, height: im.height, loading: "lazy", decoding: "async", style: crop ? { width: "100%", height: "100%", objectFit: "cover", aspectRatio: "1" } : { width: "100%", height: "auto" } });
261
267
  const pic = im.webpSrcset ? _jsxs("picture", { children: [_jsx("source", { type: "image/webp", srcSet: im.webpSrcset, sizes: `(max-width: 768px) 50vw, ${Math.round(100 / cols)}vw` }), el] }) : el;
262
- return _jsxs("figure", { className: "ecx-gallery-item cms-gallery-item", style: { margin: 0 }, children: [im.full ? _jsx("a", { href: safeUrl(im.full), children: pic }) : pic, im.caption && _jsx("figcaption", { children: im.caption })] }, i);
268
+ return _jsxs("figure", { className: "ecx-gallery-item cms-gallery-item", style: { margin: 0 }, children: [a.lightbox === true ? _jsx(LightboxClient, { src: safeUrl(im.full || im.src, ""), alt: im.alt ?? "", children: pic }) : im.full && a.linkTo !== "none" ? _jsx("a", { href: safeUrl(im.full), children: pic }) : pic, im.caption && _jsx("figcaption", { children: im.caption })] }, i);
263
269
  }), a.caption && _jsx("figcaption", { className: "ecx-gallery-caption cms-gallery-caption", style: { gridColumn: "1 / -1" }, children: a.caption })] }, key));
264
270
  }
265
271
  case "video":
266
- return _jsxs("figure", { className: "ecx-video cms-video", children: [_jsx("video", { src: safeUrl(a.src, ""), poster: a.poster ? safeUrl(a.poster, "") : undefined, controls: true, preload: "metadata", playsInline: true, style: { width: "100%", height: "auto" } }), a.caption && _jsx("figcaption", { children: a.caption })] }, key);
272
+ 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, style: { width: "100%", height: "auto" } }), a.caption && _jsx("figcaption", { children: a.caption })] }, key);
267
273
  case "audio":
268
- return _jsxs("figure", { className: "ecx-audio cms-audio", children: [_jsx("audio", { src: safeUrl(a.src, ""), controls: true, preload: "metadata", style: { width: "100%" } }), a.caption && _jsx("figcaption", { children: a.caption })] }, key);
274
+ 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);
269
275
  case "file": {
270
276
  const isPdf = String(a.mime ?? "").includes("pdf") || /\.pdf($|\?)/i.test(String(a.src ?? ""));
271
277
  return (_jsxs("div", { className: "ecx-file cms-file", children: [isPdf && a.embed !== false && _jsx("object", { data: safeUrl(a.src, ""), type: "application/pdf", style: { width: "100%", height: 600 }, "aria-label": a.name, children: _jsx("a", { href: safeUrl(a.src), children: a.name }) }), _jsx("a", { className: "ecx-file-link cms-file-link", href: safeUrl(a.src), download: a.download ? "" : undefined, target: "_blank", rel: "noopener", children: a.name || ctx.labels?.download || "Download" })] }, key));
@@ -347,8 +353,44 @@ async function renderNodeInner(node, key, ctx) {
347
353
  }
348
354
  case "pullquote":
349
355
  return _jsxs("figure", { className: "ecx-pullquote", children: [_jsx("blockquote", { children: _jsx("p", { children: await children() }) }), a.citation && _jsx("figcaption", { children: a.citation })] }, key);
356
+ case "accordion": {
357
+ const sub = a.multiple === true ? ctx : { ...ctx, accordion: `ecx-acc-${key}` };
358
+ return _jsx("div", { className: "ecx-accordion", children: await Promise.all((node.content ?? []).map((c, i) => renderNode(c, `${key}-${i}`, sub))) }, key);
359
+ }
360
+ case "countdown": {
361
+ const ms = Date.parse(String(a.target ?? ""));
362
+ if (!Number.isFinite(ms))
363
+ return null;
364
+ return _jsx(CountdownClient, { target: ms, label: a.label ? String(a.label) : undefined, expiredText: a.expiredText ? String(a.expiredText) : undefined }, key);
365
+ }
366
+ case "rating": {
367
+ const max = Math.min(10, Math.max(1, Math.round(Number(a.max) || 5)));
368
+ const v = Math.min(max, Math.max(0, Number(a.value) || 0));
369
+ return (_jsxs("div", { className: "ecx-rating", role: "img", "aria-label": `${v}/${max}`, children: [Array.from({ length: max }, (_, i) => _jsx("span", { "aria-hidden": "true", className: i < Math.round(v) ? "is-on" : "is-off", style: { color: i < Math.round(v) ? "#f59e0b" : "#d4d4d8" }, children: "\u2605" }, i)), a.label && _jsxs("span", { className: "ecx-rating-label", children: [" ", String(a.label)] })] }, key));
370
+ }
371
+ case "tabs": {
372
+ const tabs = (node.content ?? []).filter((c) => c.type === "tab");
373
+ if (!tabs.length)
374
+ return null;
375
+ const panels = await Promise.all(tabs.map(async (t, i) => _jsx(Fragment, { children: await Promise.all((t.content ?? []).map((c, j) => renderNode(c, `${key}-${i}-${j}`, ctx))) }, i)));
376
+ return _jsx(TabsClient, { titles: tabs.map((t, i) => String(t.attrs?.title || `Tab ${i + 1}`)), panels: panels }, key);
377
+ }
378
+ case "tab":
379
+ return _jsx("div", { className: "ecx-tab", children: await children() }, key);
380
+ case "carousel": {
381
+ const per = Math.min(4, Math.max(1, Math.round(Number(a.slidesPerView) || 1)));
382
+ const kids = await Promise.all((node.content ?? []).map(async (c, i) => _jsx("div", { className: "ecx-carousel-slide", style: { scrollSnapAlign: "start" }, children: await renderNode(c, `${key}-${i}`, ctx) }, i)));
383
+ return _jsx("div", { className: "ecx-carousel", role: "region", "aria-roledescription": "carousel", tabIndex: 0, style: { display: "grid", gridAutoFlow: "column", gridAutoColumns: `calc((100% - ${(per - 1) * 16}px) / ${per})`, gap: 16, overflowX: "auto", scrollSnapType: "x mandatory" }, children: kids }, key);
384
+ }
385
+ case "shortcode": {
386
+ const name = String(a.name ?? "");
387
+ if (!/^[a-z0-9_-]{1,64}$/i.test(name))
388
+ return null;
389
+ const Comp = await ctx.resolve.shortcode(name);
390
+ return Comp ? _jsx(Comp, { attrs: (a.args && typeof a.args === "object" ? a.args : {}), site: ctx.site, post: ctx.post }, key) : null;
391
+ }
350
392
  case "details":
351
- return _jsxs("details", { className: "ecx-details", open: a.open === true || undefined, children: [_jsx("summary", { children: a.summary || "…" }), await children()] }, key);
393
+ return _jsxs("details", { className: "ecx-details", name: ctx.accordion, open: a.open === true || undefined, children: [_jsx("summary", { children: a.summary || "…" }), await children()] }, key);
352
394
  case "customHtml":
353
395
  // Máy chủ đã lọc HTML khi người soạn thiếu quyền unfiltered_html (ContentSanitizer)
354
396
  return a.html ? _jsx("div", { className: "ecx-html", dangerouslySetInnerHTML: { __html: String(a.html) } }, key) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-theme-sdk",
3
- "version": "1.32.0",
3
+ "version": "1.33.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",
@@ -33,7 +33,7 @@
33
33
  "README.md"
34
34
  ],
35
35
  "dependencies": {
36
- "@ecomcx/ecomweb-content": "^1.16.0",
36
+ "@ecomcx/ecomweb-content": "^1.17.0",
37
37
  "intl-messageformat": "12.1.3"
38
38
  },
39
39
  "peerDependencies": {