@ecomcx/ecomweb-theme-sdk 1.33.0 → 1.34.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/api.d.ts CHANGED
@@ -21,7 +21,15 @@ export interface FetchOptions {
21
21
  query?: Record<string, unknown>;
22
22
  headers?: Record<string, string>;
23
23
  asUser?: boolean;
24
+ /**
25
+ * Chiều biến thiên cache (core ≥ 1.22.0) mà plugin đang bật khai báo trong plugin.json › cacheVary: `{ device: "mobile", "flag:ab": "b" }`.
26
+ * CMS gộp vào khoá cache công khai, mỗi giá trị một bản; chiều chưa ai khai báo bị bỏ qua. Danh sách chiều: GET /api/public/cache-vary.
27
+ * Đọc header / cookie để biết giá trị sẽ khiến trang thành động — chỉ làm khi plugin thật sự cần.
28
+ */
29
+ vary?: Record<string, string>;
24
30
  }
31
+ /** Header X-CMS-Vary từ `vary` ("device=mobile,flag:ab=b"); rỗng → không gửi. */
32
+ export declare function varyHeader(vary?: Record<string, string>): Record<string, string>;
25
33
  /** Gọi Public API của CMS. Kết quả được cache và gắn tag "cms" để revalidate khi nội dung thay đổi. */
26
34
  export declare function cmsFetch<T>(path: string, opts?: FetchOptions): Promise<T>;
27
35
  /** Thông tin site theo ngôn ngữ của request (hoặc locale truyền vào). */
@@ -223,7 +231,10 @@ export declare const getWidgets: (area: string, locale?: string) => Promise<Widg
223
231
  * Bình luận đã duyệt theo trang (số mỗi trang, thứ tự: Cài đặt › Thảo luận).
224
232
  * Bài có mật khẩu (core >= 1.15): CMS chỉ trả bình luận khi có token mở khoá — unlock = giá trị cookie cms-unlock (không cache).
225
233
  */
226
- export declare const getComments: (postId: number, page?: number, unlock?: string) => Promise<CommentPage>;
234
+ export declare const getComments: (postId: number, page?: number, unlock?: string, opts?: {
235
+ perPage?: number;
236
+ order?: "asc" | "desc";
237
+ }) => Promise<CommentPage>;
227
238
  /** Cookie mở khoá bài có mật khẩu của request hiện tại (server component); ngoài request → undefined. */
228
239
  export declare function requestUnlock(): Promise<string | undefined>;
229
240
  export declare const getArchives: (locale?: string) => Promise<{
package/dist/api.js CHANGED
@@ -52,6 +52,11 @@ export class CmsApiError extends Error {
52
52
  this.status = status;
53
53
  }
54
54
  }
55
+ /** Header X-CMS-Vary từ `vary` ("device=mobile,flag:ab=b"); rỗng → không gửi. */
56
+ export function varyHeader(vary) {
57
+ const parts = Object.entries(vary ?? {}).filter(([k, v]) => /^(device|flag:[a-z][a-z0-9-]{0,23})$/.test(k) && /^[A-Za-z0-9_-]{1,32}$/.test(v)).map(([k, v]) => `${k}=${v.toLowerCase()}`);
58
+ return parts.length ? { "X-CMS-Vary": parts.join(",") } : {};
59
+ }
55
60
  /**
56
61
  * API không phản hồi (thường là đang khởi động lại vài giây khi bật/tắt plugin backend):
57
62
  * mọi request đang chờ cùng đợi một lần dò /api/health (tối đa 20 giây — máy chủ yếu khởi động lại chậm hơn) rồi gọi lại, thay vì trả trang lỗi 500.
@@ -85,9 +90,10 @@ const isUnavailable = (e) => isFetchKitError(e) && (!e.status || e.status === 50
85
90
  export async function cmsFetch(path, opts = {}) {
86
91
  if ((breaker.__cmsApiDownUntil ?? 0) > Date.now())
87
92
  throw new CmsApiError(503, `CMS API tạm thời không phản hồi: ${path}`);
93
+ const headers = { ...opts.headers, ...varyHeader(opts.vary) };
88
94
  const get = () => cmsApi.get(path, opts.noStore
89
- ? { cache: "no-store", query: opts.query, headers: opts.headers }
90
- : { next: { tags: ["cms", ...(opts.tags ?? [])], revalidate: opts.revalidate ?? 3600 }, query: opts.query, headers: opts.headers });
95
+ ? { cache: "no-store", query: opts.query, headers }
96
+ : { next: { tags: ["cms", ...(opts.tags ?? [])], revalidate: opts.revalidate ?? 3600 }, query: opts.query, headers });
91
97
  try {
92
98
  try {
93
99
  return ((await get()).data ?? null);
@@ -191,8 +197,8 @@ export const getWidgets = async (area, locale) => cmsFetch(`/widgets/${area}`, {
191
197
  * Bình luận đã duyệt theo trang (số mỗi trang, thứ tự: Cài đặt › Thảo luận).
192
198
  * Bài có mật khẩu (core >= 1.15): CMS chỉ trả bình luận khi có token mở khoá — unlock = giá trị cookie cms-unlock (không cache).
193
199
  */
194
- export const getComments = (postId, page = 1, unlock) => cmsFetch(`/comments/${postId}`, {
195
- tags: [`comments:${postId}`], noStore: !!unlock, query: page > 1 ? { page } : undefined, headers: unlock ? { [UNLOCK_HEADER]: unlock } : undefined,
200
+ export const getComments = (postId, page = 1, unlock, opts = {}) => cmsFetch(`/comments/${postId}`, {
201
+ tags: [`comments:${postId}`], noStore: !!unlock, query: clean({ page: page > 1 ? page : undefined, perPage: opts.perPage, order: opts.order }), headers: unlock ? { [UNLOCK_HEADER]: unlock } : undefined,
196
202
  });
197
203
  /** Cookie mở khoá bài có mật khẩu của request hiện tại (server component); ngoài request → undefined. */
198
204
  export async function requestUnlock() {
@@ -92,6 +92,13 @@ export declare function LogoutButton({ redirectTo, className, children }: {
92
92
  className?: string;
93
93
  children?: ReactNode;
94
94
  }): import("react").JSX.Element;
95
+ /** Liên kết "Đăng nhập" / nút "Đăng xuất" theo phiên; kiểm ở client nên trang vẫn cache được. Đang tải → chưa hiện gì. */
96
+ export declare function LoginOutLink({ loginHref, loginText, logoutText, className }: {
97
+ loginHref: string;
98
+ loginText: string;
99
+ logoutText: string;
100
+ className?: string;
101
+ }): import("react").JSX.Element;
95
102
  /**
96
103
  * Người đang đăng nhập, dùng trong component client (null = khách, undefined = đang tải).
97
104
  * Server Component nên dùng getCurrentUser() để khỏi tốn thêm một request.
@@ -86,7 +86,8 @@ export function LoginForm({ redirectTo, labels, links = true, paths, fields }) {
86
86
  return;
87
87
  }
88
88
  // Tải lại hẳn trang đích: mọi Server Component đọc được cookie phiên mới
89
- window.location.assign(safeRedirect(redirectParam, redirectTo ?? P.home));
89
+ // redirectTo từ máy chủ (plugin chọn qua filter auth.login_redirect) thắng đích mặc định của form
90
+ window.location.assign(safeRedirect(data.redirectTo ?? redirectParam, redirectTo ?? P.home));
90
91
  }
91
92
  catch (err) {
92
93
  setError(errorMessage(err, L.error));
@@ -206,6 +207,15 @@ export function LogoutButton({ redirectTo = "/", className, children }) {
206
207
  }
207
208
  }, children: children ?? AUTH_LABELS.logout }));
208
209
  }
210
+ /** Liên kết "Đăng nhập" / nút "Đăng xuất" theo phiên; kiểm ở client nên trang vẫn cache được. Đang tải → chưa hiện gì. */
211
+ export function LoginOutLink({ loginHref, loginText, logoutText, className }) {
212
+ const user = useCurrentUser();
213
+ if (user === undefined)
214
+ return _jsx("span", { className: className, "aria-hidden": "true" });
215
+ return user
216
+ ? _jsx(LogoutButton, { className: className, redirectTo: "/", children: logoutText })
217
+ : _jsx("a", { className: className, href: loginHref, children: loginText });
218
+ }
209
219
  /**
210
220
  * Người đang đăng nhập, dùng trong component client (null = khách, undefined = đang tải).
211
221
  * Server Component nên dùng getCurrentUser() để khỏi tốn thêm một request.
package/dist/client.d.ts CHANGED
@@ -40,12 +40,15 @@ export type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> &
40
40
  };
41
41
  export declare function Link({ href, prefetch, activeClassName, matchNested, className, children, ...rest }: LinkProps): import("react").JSX.Element;
42
42
  /** Form tìm kiếm (GET) chuyển trang phía client. */
43
- export declare function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel }: {
43
+ export declare function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition }: {
44
44
  action: string;
45
45
  defaultValue?: string | null;
46
46
  placeholder: string;
47
47
  label: string;
48
48
  buttonLabel: string;
49
+ postType?: string;
50
+ showLabel?: boolean;
51
+ buttonPosition?: "right" | "left" | "below";
49
52
  }): import("react").JSX.Element;
50
53
  /** Ghi tuỳ chọn hiển thị của người đọc (xem getPreference). value = null để xoá. */
51
54
  export declare function setPreference(key: string, value: string | null, maxAgeDays?: number): void;
@@ -67,12 +70,14 @@ type DateSite = {
67
70
  locale?: string;
68
71
  };
69
72
  /** Danh sách bình luận lồng nhau (render được cả ở server lẫn client). */
70
- export declare function CommentList({ comments, site }: {
73
+ export declare function CommentList({ comments, site, avatarSize, showDate }: {
71
74
  comments: Comment[];
72
75
  site: DateSite;
76
+ avatarSize?: number;
77
+ showDate?: boolean;
73
78
  }): import("react").JSX.Element;
74
79
  /** Nút "Xem thêm bình luận": tải các trang tiếp theo qua /api/cms/comments. */
75
- export declare function CommentsMore({ postId, totalPages, site, labels }: {
80
+ export declare function CommentsMore({ postId, totalPages, site, labels, perPage, order, avatarSize, showDate }: {
76
81
  postId: number;
77
82
  totalPages: number;
78
83
  site: DateSite;
@@ -81,6 +86,10 @@ export declare function CommentsMore({ postId, totalPages, site, labels }: {
81
86
  loading: string;
82
87
  error: string;
83
88
  };
89
+ perPage?: number;
90
+ order?: "asc" | "desc";
91
+ avatarSize?: number;
92
+ showDate?: boolean;
84
93
  }): import("react").JSX.Element;
85
94
  /** Form mật khẩu của bài được bảo vệ. Đúng mật khẩu → cookie httpOnly, tải lại nội dung trang. */
86
95
  export declare function PostPasswordForm({ postId, labels }: {
@@ -106,7 +115,7 @@ export declare function LanguageSwitcherClient({ languages, current, defaultLoca
106
115
  className?: string;
107
116
  variant: "list" | "select";
108
117
  }): import("react").JSX.Element;
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";
118
+ export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS, type AuthLabels, type AuthPaths, type SignInProvider } from "./auth-forms.js";
110
119
  export { safeRedirect, type CurrentUser } from "./auth-shared.js";
111
120
  /** 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
121
  export declare function CountdownClient({ target, label, expiredText }: {
package/dist/client.js CHANGED
@@ -58,8 +58,10 @@ export function Link({ href, prefetch = false, activeClassName, matchNested = tr
58
58
  }, children: [children, _jsx(PendingSignal, {})] }));
59
59
  }
60
60
  /** Form tìm kiếm (GET) chuyển trang phía client. */
61
- export function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel }) {
62
- return (_jsxs(NextForm, { action: action, role: "search", className: "search-form", children: [_jsx("input", { type: "search", name: "s", defaultValue: defaultValue ?? "", placeholder: placeholder, "aria-label": label, required: true }), _jsx("button", { type: "submit", children: buttonLabel })] }));
61
+ export function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition = "right" }) {
62
+ const id = useId();
63
+ const button = _jsx("button", { type: "submit", children: buttonLabel });
64
+ return (_jsxs(NextForm, { action: action, role: "search", style: buttonPosition === "below" ? { display: "flex", flexDirection: "column", gap: 8 } : undefined, className: `search-form${buttonPosition !== "right" ? ` search-button-${buttonPosition}` : ""}`, children: [showLabel && _jsx("label", { htmlFor: id, className: "search-label", children: label }), buttonPosition === "left" && button, _jsx("input", { id: id, type: "search", name: "s", defaultValue: defaultValue ?? "", placeholder: placeholder, "aria-label": showLabel ? undefined : label, required: true }), postType && _jsx("input", { type: "hidden", name: "type", value: postType }), buttonPosition !== "left" && button] }));
63
65
  }
64
66
  /** Ghi tuỳ chọn hiển thị của người đọc (xem getPreference). value = null để xoá. */
65
67
  export function setPreference(key, value, maxAgeDays = 365) {
@@ -115,11 +117,11 @@ export function CommentForm({ postId, parentId, labels, fields }) {
115
117
  return (_jsxs("form", { className: "comment-form", onSubmit: onSubmit, children: [_jsx("h3", { children: L.title }), _jsx("p", { children: _jsxs("label", { children: [L.content, " *", _jsx("textarea", { name: "content", required: true, rows: 5, maxLength: 5000 })] }) }), _jsxs("p", { className: "comment-form-row", children: [_jsxs("label", { children: [L.name, " *", _jsx("input", { name: "authorName", required: true, maxLength: 100 })] }), _jsxs("label", { children: [L.email, " *", _jsx("input", { name: "authorEmail", type: "email", required: true, maxLength: 200 })] })] }), _jsx("p", { children: _jsxs("label", { children: [L.website, _jsx("input", { name: "authorUrl", type: "url", maxLength: 200 })] }) }), _jsx("input", { name: "website2", tabIndex: -1, autoComplete: "off", style: { position: "absolute", left: "-9999px" }, "aria-hidden": true }), fields, _jsx("p", { children: _jsx("button", { type: "submit", disabled: state === "sending", children: state === "sending" ? L.sending : L.submit }) }), message && _jsx("p", { className: state === "error" ? "form-error" : "form-success", role: "status", children: message })] }));
116
118
  }
117
119
  /** Danh sách bình luận lồng nhau (render được cả ở server lẫn client). */
118
- export function CommentList({ comments, site }) {
119
- return (_jsx("ol", { className: "comment-list", children: comments.map((c) => (_jsxs("li", { id: `comment-${c.id}`, className: "comment", children: [_jsxs("article", { children: [_jsxs("header", { className: "comment-meta", children: [c.avatarUrl && _jsx("img", { className: "comment-avatar avatar", src: c.avatarUrl, alt: "", width: 40, height: 40, loading: "lazy", decoding: "async" }), _jsx("b", { className: "comment-author", children: c.authorUrl ? _jsx("a", { href: c.authorUrl, rel: "nofollow ugc", children: c.authorName }) : c.authorName }), " · ", _jsx("time", { dateTime: c.createdAt, children: formatDate(c.createdAt, site) })] }), _jsx("div", { className: "comment-content", children: c.content.split("\n").map((l, i) => _jsx("p", { children: l }, i)) })] }), c.replies.length > 0 && _jsx(CommentList, { comments: c.replies, site: site })] }, c.id))) }));
120
+ export function CommentList({ comments, site, avatarSize = 40, showDate = true }) {
121
+ return (_jsx("ol", { className: "comment-list", children: comments.map((c) => (_jsxs("li", { id: `comment-${c.id}`, className: "comment", children: [_jsxs("article", { children: [_jsxs("header", { className: "comment-meta", children: [c.avatarUrl && _jsx("img", { className: "comment-avatar avatar", src: c.avatarUrl, alt: "", width: avatarSize, height: avatarSize, loading: "lazy", decoding: "async" }), _jsx("b", { className: "comment-author", children: c.authorUrl ? _jsx("a", { href: c.authorUrl, rel: "nofollow ugc", children: c.authorName }) : c.authorName }), showDate && _jsxs(_Fragment, { children: [" · ", _jsx("time", { dateTime: c.createdAt, children: formatDate(c.createdAt, site) })] })] }), _jsx("div", { className: "comment-content", children: c.content.split("\n").map((l, i) => _jsx("p", { children: l }, i)) })] }), c.replies.length > 0 && _jsx(CommentList, { comments: c.replies, site: site, avatarSize: avatarSize, showDate: showDate })] }, c.id))) }));
120
122
  }
121
123
  /** Nút "Xem thêm bình luận": tải các trang tiếp theo qua /api/cms/comments. */
122
- export function CommentsMore({ postId, totalPages, site, labels }) {
124
+ export function CommentsMore({ postId, totalPages, site, labels, perPage, order, avatarSize, showDate }) {
123
125
  const [pages, setPages] = useState([]);
124
126
  const [loading, setLoading] = useState(false);
125
127
  const [error, setError] = useState("");
@@ -128,7 +130,7 @@ export function CommentsMore({ postId, totalPages, site, labels }) {
128
130
  setLoading(true);
129
131
  setError("");
130
132
  try {
131
- const { data } = await browserApi.get("/comments", { query: { postId, page: next } });
133
+ const { data } = await browserApi.get("/comments", { query: { postId, page: next, ...(perPage ? { perPage } : {}), ...(order ? { order } : {}) } });
132
134
  setPages((p) => [...p, data.items]);
133
135
  }
134
136
  catch (e) {
@@ -138,7 +140,7 @@ export function CommentsMore({ postId, totalPages, site, labels }) {
138
140
  setLoading(false);
139
141
  }
140
142
  }
141
- return (_jsxs(_Fragment, { children: [pages.map((items, i) => _jsx(CommentList, { comments: items, site: site }, i)), next <= totalPages && _jsx("p", { className: "comments-more", children: _jsx("button", { type: "button", onClick: load, disabled: loading, children: loading ? labels.loading : labels.more }) }), error && _jsx("p", { className: "form-error", role: "alert", children: error })] }));
143
+ return (_jsxs(_Fragment, { children: [pages.map((items, i) => _jsx(CommentList, { comments: items, site: site, avatarSize: avatarSize, showDate: showDate }, i)), next <= totalPages && _jsx("p", { className: "comments-more", children: _jsx("button", { type: "button", onClick: load, disabled: loading, children: loading ? labels.loading : labels.more }) }), error && _jsx("p", { className: "form-error", role: "alert", children: error })] }));
142
144
  }
143
145
  /** Form mật khẩu của bài được bảo vệ. Đúng mật khẩu → cookie httpOnly, tải lại nội dung trang. */
144
146
  export function PostPasswordForm({ postId, labels }) {
@@ -188,7 +190,7 @@ export function LanguageSwitcherClient({ languages, current, defaultLocale, labe
188
190
  return (_jsx("select", { className: className ?? "lang-switcher", "aria-label": label, value: current, onChange: (e) => { window.location.href = href(e.target.value); }, children: languages.map((l) => _jsxs("option", { value: l.code, children: [l.flag ? `${l.flag} ` : "", l.name] }, l.code)) }));
189
191
  return (_jsx("nav", { className: className ?? "lang-switcher", "aria-label": label, children: _jsx("ul", { children: languages.map((l) => (_jsx("li", { className: l.code === current ? "current-lang" : undefined, children: _jsxs("a", { href: href(l.code), hrefLang: l.code, lang: l.code, "aria-current": l.code === current ? "true" : undefined, children: [l.flag && _jsxs("span", { "aria-hidden": true, children: [l.flag, " "] }), l.code.toUpperCase()] }) }, l.code))) }) }));
190
192
  }
191
- export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
193
+ export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
192
194
  export { safeRedirect } from "./auth-shared.js";
193
195
  /** 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
196
  export function CountdownClient({ target, label, expiredText }) {
@@ -19,10 +19,13 @@ export declare function Slot<P = any>({ name, data, props, fallback, className,
19
19
  className?: string;
20
20
  }): Promise<import("react").JSX.Element>;
21
21
  /** Ô tìm kiếm — gửi về trang chủ của ngôn ngữ hiện tại (/?s= hoặc /en?s=). */
22
- export declare function SearchForm({ defaultValue, placeholder, buttonLabel }: {
22
+ export declare function SearchForm({ defaultValue, placeholder, buttonLabel, postType, showLabel, buttonPosition }: {
23
23
  defaultValue?: string | null;
24
24
  placeholder?: string;
25
25
  buttonLabel?: string;
26
+ postType?: string;
27
+ showLabel?: boolean;
28
+ buttonPosition?: "right" | "left" | "below";
26
29
  }): Promise<import("react").JSX.Element>;
27
30
  /** `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
31
  export declare function Pagination({ data, prevLabel, nextLabel, pageParam, type, midSize }: {
@@ -58,9 +61,13 @@ export declare function TermLinks({ terms, separator }: {
58
61
  }>;
59
62
  separator?: string;
60
63
  }): import("react").JSX.Element | null;
61
- export declare function Comments({ post, title }: {
64
+ export declare function Comments({ post, title, perPage, order, avatarSize, showDate }: {
62
65
  post: Post;
63
66
  title?: string;
67
+ perPage?: number;
68
+ order?: "asc" | "desc";
69
+ avatarSize?: number;
70
+ showDate?: boolean;
64
71
  }): Promise<import("react").JSX.Element | null>;
65
72
  /**
66
73
  * Nút chuyển ngôn ngữ. Đặt ở layout của theme. Ẩn khi site chỉ có một ngôn ngữ.
@@ -85,9 +85,9 @@ export async function Slot({ name, data, props, fallback, className, }) {
85
85
  // Tiện ích hiển thị
86
86
  // ---------------------------------------------------------------------------
87
87
  /** Ô tìm kiếm — gửi về trang chủ của ngôn ngữ hiện tại (/?s= hoặc /en?s=). */
88
- export async function SearchForm({ defaultValue, placeholder, buttonLabel }) {
88
+ export async function SearchForm({ defaultValue, placeholder, buttonLabel, postType, showLabel, buttonPosition }) {
89
89
  const [t, site] = await Promise.all([getT(), getSite()]);
90
- return _jsx(SearchFormClient, { action: localeHref(site, "/"), defaultValue: defaultValue, placeholder: placeholder ?? t("search.placeholder"), label: t("search.label"), buttonLabel: buttonLabel ?? t("search.button") });
90
+ return _jsx(SearchFormClient, { action: localeHref(site, "/"), defaultValue: defaultValue, placeholder: placeholder ?? t("search.placeholder"), label: t("search.label"), buttonLabel: buttonLabel ?? t("search.button"), postType: postType, showLabel: showLabel, buttonPosition: buttonPosition });
91
91
  }
92
92
  function paramLink(data, param, p) {
93
93
  const q = new URLSearchParams(Object.entries(data.query ?? {}).filter(([k]) => k !== param));
@@ -137,18 +137,18 @@ export function TermLinks({ terms, separator = ", " }) {
137
137
  // ---------------------------------------------------------------------------
138
138
  // Khu bình luận
139
139
  // ---------------------------------------------------------------------------
140
- export async function Comments({ post, title }) {
140
+ export async function Comments({ post, title, perPage, order, avatarSize, showDate }) {
141
141
  if (post.commentStatus !== "open" && post.commentCount === 0)
142
142
  return null;
143
143
  if (post.passwordProtected && !post.content)
144
144
  return null; // bài có mật khẩu: ẩn bình luận tới khi mở khoá
145
145
  const unlock = post.passwordProtected ? await requestUnlock() : undefined;
146
- const [site, page, t] = await Promise.all([getSite(), getComments(post.id, 1, unlock), getT()]);
146
+ const [site, page, t] = await Promise.all([getSite(), getComments(post.id, 1, unlock, { perPage, order }), getT()]);
147
147
  const comments = page?.items ?? [];
148
148
  const dateSite = { dateFormat: site.dateFormat, timezone: site.timezone, locale: site.locale };
149
149
  title ??= t("comments.title");
150
150
  const labels = Object.fromEntries(["title", "content", "name", "email", "website", "submit", "sending", "approved", "pending", "error"].map((k) => [k, t(`comments.form.${k}`)]));
151
- return (_jsxs("section", { id: "comments", className: "comments-area", children: [_jsx(Slot, { name: "comments.before", props: { post } }), _jsxs("h2", { className: "comments-title", children: [title, " (", post.commentCount, ")"] }), comments.length > 0 && _jsx(CommentList, { comments: comments, site: dateSite }), (page?.totalPages ?? 1) > 1 && _jsx(CommentsMore, { postId: post.id, totalPages: page.totalPages, site: dateSite, labels: { more: t("comments.more"), loading: t("comments.loading"), error: t("comments.form.error") } }), post.commentStatus === "open"
151
+ return (_jsxs("section", { id: "comments", className: "comments-area", children: [_jsx(Slot, { name: "comments.before", props: { post } }), _jsxs("h2", { className: "comments-title", children: [title, " (", post.commentCount, ")"] }), comments.length > 0 && _jsx(CommentList, { comments: comments, site: dateSite, avatarSize: avatarSize, showDate: showDate }), (page?.totalPages ?? 1) > 1 && _jsx(CommentsMore, { postId: post.id, totalPages: page.totalPages, site: dateSite, perPage: perPage, order: order, avatarSize: avatarSize, showDate: showDate, labels: { more: t("comments.more"), loading: t("comments.loading"), error: t("comments.form.error") } }), post.commentStatus === "open"
152
152
  ? _jsx(CommentForm, { postId: post.id, labels: labels, fields: _jsx(Slot, { name: "comment_form.fields", props: { post } }) })
153
153
  : _jsx("p", { className: "no-comments", children: t("comments.closed") }), _jsx(Slot, { name: "comments.after", props: { post } })] }));
154
154
  }
package/dist/content.d.ts CHANGED
@@ -5,10 +5,11 @@ import { type RenderContext } from "./rich.js";
5
5
  * Render nội dung bài viết (định dạng của CMS — @ecomcx/ecomweb-content; phần vẽ ở rich.tsx, không phụ thuộc trình soạn).
6
6
  * Luôn có class `ecx-content` (giao diện nền trong @ecomcx/ecomweb-content/style.css, theme ghi đè được); `className` thay cho `entry-content`.
7
7
  */
8
- export declare function PostContent({ post, content, className }: {
8
+ export declare function PostContent({ post, content, className, page }: {
9
9
  post?: Post | null;
10
10
  content?: PostContentDoc | null;
11
11
  className?: string;
12
+ page?: number;
12
13
  }): Promise<import("react").JSX.Element | null>;
13
14
  /**
14
15
  * Vùng của theme: header, footer (vùng chuẩn của core — nên luôn bọc) và vùng hybrid khai báo ở theme.json › regions.
package/dist/content.js CHANGED
@@ -1,5 +1,5 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { ExtensionBoundary, PostPasswordForm } from "./client.js";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { ExtensionBoundary, Link, PostPasswordForm } from "./client.js";
3
3
  import { applyFilters, findBlock, findRegion, findShortcode, getActiveExtensions } from "./runtime.js";
4
4
  import { getPattern, getSite, getTemplates } from "./api.js";
5
5
  import { CORE_BINDING_SOURCES } from "./bindings.js";
@@ -11,7 +11,7 @@ import { cx } from "./utils.js";
11
11
  * Render nội dung bài viết (định dạng của CMS — @ecomcx/ecomweb-content; phần vẽ ở rich.tsx, không phụ thuộc trình soạn).
12
12
  * Luôn có class `ecx-content` (giao diện nền trong @ecomcx/ecomweb-content/style.css, theme ghi đè được); `className` thay cho `entry-content`.
13
13
  */
14
- export async function PostContent({ post, content, className }) {
14
+ export async function PostContent({ post, content, className, page }) {
15
15
  const site = await getSite();
16
16
  const doc = content ?? post?.content;
17
17
  if (!content && post?.passwordProtected && !post.content) {
@@ -20,8 +20,42 @@ export async function PostContent({ post, content, className }) {
20
20
  }
21
21
  if (!doc?.blocks?.length)
22
22
  return null;
23
- const rendered = await renderContent(doc, { ...(await contentContext(site, post)), source: post ? `post:${post.id}` : undefined }, (blocks) => applyFilters("post.blocks", blocks, { site, post }, site));
24
- return _jsx("div", { className: cx(className ?? "entry-content", "ecx-content"), children: rendered });
23
+ // Khối pageBreak chia bài thành nhiều trang (?trang=N): chỉ vẽ trang đang xem + thanh chuyển trang
24
+ let total = 1;
25
+ const current = Math.max(1, Math.floor(Number(page)) || 1);
26
+ const rendered = await renderContent(doc, { ...(await contentContext(site, post)), source: post ? `post:${post.id}` : undefined }, async (blocks) => {
27
+ const pages = splitPages(await applyFilters("post.blocks", blocks, { site, post }, site));
28
+ total = pages.length;
29
+ return pages[Math.min(current, total) - 1];
30
+ });
31
+ const n = Math.min(current, total);
32
+ const t = total > 1 ? await getT() : null;
33
+ const href = (i) => (post?.link ?? "") + (i > 1 ? `?trang=${i}` : "");
34
+ return (_jsxs("div", { className: cx(className ?? "entry-content", "ecx-content"), children: [rendered, t && post && (_jsxs("nav", { className: "ecx-page-links", "aria-label": t("pagination.label"), children: [n > 1 && _jsx(Link, { href: href(n - 1), rel: "prev", children: t("pagination.prev") }), Array.from({ length: total }, (_, i) => i + 1).map((i) => i === n ? _jsx("span", { "aria-current": "page", children: i }, i) : _jsx(Link, { href: href(i), children: i }, i)), n < total && _jsx(Link, { href: href(n + 1), rel: "next", children: t("pagination.next") })] }))] }));
35
+ }
36
+ /** Cắt khối richtext tại mỗi `pageBreak` cấp cao nhất; khối khác nằm ở trang đang mở. Không có pageBreak → một trang. */
37
+ function splitPages(blocks) {
38
+ const pages = [[]];
39
+ for (const b of blocks) {
40
+ const nodes = b.type === "richtext" ? (b.data?.content ?? []) : [];
41
+ if (!nodes.some((x) => x.type === "pageBreak")) {
42
+ pages[pages.length - 1].push(b);
43
+ continue;
44
+ }
45
+ let seg = [];
46
+ const flush = () => { if (seg.length)
47
+ pages[pages.length - 1].push({ ...b, data: { ...b.data, content: seg } }); seg = []; };
48
+ for (const x of nodes) {
49
+ if (x.type === "pageBreak") {
50
+ flush();
51
+ pages.push([]);
52
+ }
53
+ else
54
+ seg.push(x);
55
+ }
56
+ flush();
57
+ }
58
+ return pages.filter((p, i) => p.length || i === 0);
25
59
  }
26
60
  /**
27
61
  * Vùng của theme: header, footer (vùng chuẩn của core — nên luôn bọc) và vùng hybrid khai báo ở theme.json › regions.
package/dist/dynamic.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Fragment } from "react";
3
- import { getPosts } from "./api.js";
4
- import { Link } from "./client.js";
3
+ import { getArchives, getPosts, getTerms } from "./api.js";
4
+ import { Link, LoginOutLink } from "./client.js";
5
5
  import { Comments, FeaturedImage, LanguageSwitcher, Menu, Pagination, PostDate, SearchForm, TermLinks } from "./components.js";
6
6
  import { getT } from "./i18n.js";
7
7
  import { localeHref } from "./locale.js";
@@ -41,7 +41,7 @@ export async function renderDynamic(node, key, ctx, children) {
41
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));
42
42
  }
43
43
  case "search":
44
- return _jsx("div", { className: "ecx-search", children: _jsx(SearchForm, { defaultValue: ctx.data?.search, placeholder: a.placeholder, buttonLabel: a.buttonText }) }, key);
44
+ return _jsx("div", { className: "ecx-search", children: _jsx(SearchForm, { defaultValue: ctx.data?.search, placeholder: a.placeholder, buttonLabel: a.buttonText, postType: typeof a.postType === "string" && /^[a-z0-9_-]{1,64}$/i.test(a.postType) ? a.postType : undefined, showLabel: a.showLabel === true, buttonPosition: a.buttonPosition === "left" || a.buttonPosition === "below" ? a.buttonPosition : "right" }) }, key);
45
45
  case "languageSwitcher":
46
46
  return _jsx(LanguageSwitcher, { className: "ecx-language-switcher", variant: a.display === "dropdown" ? "select" : "list" }, key);
47
47
  case "copyright":
@@ -56,7 +56,7 @@ export async function renderDynamic(node, key, ctx, children) {
56
56
  if (!post || !ctx.data)
57
57
  return null;
58
58
  const { PostContent } = await import("./content.js");
59
- return _jsx(PostContent, { post: post }, key);
59
+ return _jsx(PostContent, { post: post, page: Number(ctx.data.query?.trang) }, key);
60
60
  }
61
61
  case "postExcerpt":
62
62
  if (!post?.excerpt)
@@ -92,12 +92,56 @@ export async function renderDynamic(node, key, ctx, children) {
92
92
  }
93
93
  case "queryTotal":
94
94
  return ctx.query?.data ? _jsx("p", { className: "ecx-query-total", style: align(a), children: ctx.query.data.total }, key) : null;
95
+ case "loginout": {
96
+ const t = await getT();
97
+ return _jsx("p", { className: "ecx-loginout", style: align(a), children: _jsx(LoginOutLink, { loginHref: localeHref(site, "/login"), loginText: a.loginText || t("auth.submitLogin"), logoutText: a.logoutText || t("auth.logout") }) }, key);
98
+ }
99
+ case "termList": {
100
+ const taxonomy = String(a.taxonomy ?? "category");
101
+ if (!/^[a-z0-9_-]{1,64}$/i.test(taxonomy))
102
+ return null;
103
+ const terms = await getTerms(taxonomy, a.hideEmpty !== false).catch(() => []);
104
+ if (!terms.length)
105
+ return null;
106
+ const label = (t) => _jsxs(_Fragment, { children: [_jsx(Link, { href: t.link, rel: "tag", children: t.name }), a.showCount === true && _jsxs(_Fragment, { children: [" (", t.count, ")"] })] });
107
+ if (a.display === "cloud") {
108
+ const max = Math.max(...terms.map((t) => t.count), 1);
109
+ return _jsx("p", { className: "ecx-term-list is-cloud", children: terms.map((t) => _jsx("span", { style: { fontSize: `${(0.8 + (t.count / max) * 0.9).toFixed(2)}em`, marginRight: "0.5em" }, children: label(t) }, t.id)) }, key);
110
+ }
111
+ if (a.hierarchical === true) {
112
+ const ids = new Set(terms.map((t) => t.id));
113
+ const tree = (parent, depth) => {
114
+ const rows = terms.filter((t) => (parent === null ? !t.parentId || !ids.has(t.parentId) : t.parentId === parent));
115
+ return rows.length && depth < 5 ? _jsx("ul", { children: rows.map((t) => _jsxs("li", { children: [label(t), tree(t.id, depth + 1)] }, t.id)) }) : null;
116
+ };
117
+ return _jsx("nav", { className: "ecx-term-list", children: tree(null, 0) }, key);
118
+ }
119
+ return _jsx("ul", { className: "ecx-term-list", children: terms.map((t) => _jsx("li", { children: label(t) }, t.id)) }, key);
120
+ }
121
+ case "pageList": {
122
+ const pages = (await getPosts({ type: "page", perPage: 50, orderBy: "menu_order", order: "asc" }).catch(() => null))?.items ?? [];
123
+ const rootId = typeof a.parentId === "number" ? a.parentId : null;
124
+ const maxDepth = Math.min(3, Math.max(1, Number(a.depth) || 2));
125
+ const ids = new Set(pages.map((p) => p.id));
126
+ const tree = (parent, depth) => {
127
+ const rows = pages.filter((p) => (parent === null ? !p.parentId || !ids.has(p.parentId) : p.parentId === parent));
128
+ return rows.length && depth < maxDepth ? _jsx("ul", { children: rows.map((p) => _jsxs("li", { children: [_jsx(Link, { href: p.link, children: p.title }), tree(p.id, depth + 1)] }, p.id)) }) : null;
129
+ };
130
+ const list = tree(rootId, 0);
131
+ return list ? _jsx("nav", { className: "ecx-page-list", children: list }, key) : null;
132
+ }
133
+ case "archives": {
134
+ const [rows, t] = await Promise.all([getArchives().catch(() => []), getT()]);
135
+ if (!rows.length)
136
+ return null;
137
+ return _jsx("ul", { className: "ecx-archives", children: rows.slice(0, Math.min(60, Math.max(1, Number(a.limit) || 12))).map((r) => _jsxs("li", { children: [_jsx(Link, { href: r.link, children: t("archives.month", { month: r.month, year: r.year }) }), a.showCount !== false && _jsxs(_Fragment, { children: [" (", r.count, ")"] })] }, r.link)) }, key);
138
+ }
95
139
  case "postTerms": {
96
140
  const terms = post?.terms?.[a.taxonomy ?? "category"];
97
141
  return terms?.length ? _jsx("p", { className: "ecx-post-terms", children: _jsx(TermLinks, { terms: terms, separator: a.separator ?? ", " }) }, key) : null;
98
142
  }
99
143
  case "comments":
100
- return post && ctx.data?.post?.id === post.id ? _jsx(Comments, { post: post, title: a.title ? String(a.title) : undefined }, key) : null;
144
+ return post && ctx.data?.post?.id === post.id ? _jsx(Comments, { post: post, title: a.title ? String(a.title) : undefined, perPage: typeof a.perPage === "number" ? a.perPage : undefined, order: a.order === "asc" || a.order === "desc" ? a.order : undefined, avatarSize: typeof a.avatarSize === "number" ? a.avatarSize : undefined, showDate: a.showDate === false ? false : undefined }, key) : null;
101
145
  // 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)
102
146
  case "queryTitle": {
103
147
  const d = ctx.data;
@@ -0,0 +1,2 @@
1
+ /** Tập icon cố định cho khối `icon` (24×24, nét 2, lucide). Chỉ nhận tên trong bảng này — không nhận SVG tuỳ ý (chống XSS). */
2
+ export declare const ICON_PATHS: Record<string, string>;
package/dist/icons.js ADDED
@@ -0,0 +1,15 @@
1
+ /** Tập icon cố định cho khối `icon` (24×24, nét 2, lucide). Chỉ nhận tên trong bảng này — không nhận SVG tuỳ ý (chống XSS). */
2
+ export const ICON_PATHS = {
3
+ check: "M20 6 9 17l-5-5",
4
+ x: "M18 6 6 18M6 6l12 12",
5
+ star: "M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z",
6
+ heart: "M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",
7
+ arrowRight: "M5 12h14M12 5l7 7-7 7",
8
+ phone: "M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z",
9
+ mail: "M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zM22 6l-10 7L2 6",
10
+ mapPin: "M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0zM12 7a3 3 0 1 0 0 6 3 3 0 0 0 0-6z",
11
+ clock: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM12 6v6l4 2",
12
+ info: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM12 16v-4M12 8h.01",
13
+ alert: "M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0zM12 9v4M12 17h.01",
14
+ externalLink: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14 21 3",
15
+ };
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
10
10
  export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, isInternalHref, type LinkProps } from "./client.js";
11
11
  export { getPreference } from "./preferences.js";
12
12
  export { getCurrentUser, getAccessToken, requireUser, userCan, safeRedirect, ACCESS_COOKIE, REFRESH_COOKIE, type CurrentUser } from "./auth.js";
13
- export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS, type AuthLabels, type AuthPaths, type SignInProvider } from "./auth-forms.js";
13
+ export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS, type AuthLabels, type AuthPaths, type SignInProvider } from "./auth-forms.js";
14
14
  export { buildDocumentMetadata } from "./metadata.js";
15
15
  /** Lấy giá trị Customizer của theme đang active. */
16
16
  export declare function getThemeSettings(): Promise<import("./types.js").JsonObject>;
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
10
10
  export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, isInternalHref } from "./client.js";
11
11
  export { getPreference } from "./preferences.js";
12
12
  export { getCurrentUser, getAccessToken, requireUser, userCan, safeRedirect, ACCESS_COOKIE, REFRESH_COOKIE } from "./auth.js";
13
- export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
13
+ export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
14
14
  export { buildDocumentMetadata } from "./metadata.js";
15
15
  /** Lấy giá trị Customizer của theme đang active. */
16
16
  export async function getThemeSettings() {
package/dist/metadata.js CHANGED
@@ -5,7 +5,7 @@ export async function buildDocumentMetadata(data, site) {
5
5
  const base = {
6
6
  title: isHome ? `${site.title}${site.tagline ? ` – ${site.tagline}` : ""}` : `${data.title} – ${site.title}`,
7
7
  description: data.post?.excerpt || (data.term?.description || undefined) || site.tagline,
8
- canonical: data.post?.link ?? (data.basePath || undefined),
8
+ canonical: data.post?.link ? data.post.link + (Number(data.query?.trang) > 1 ? `?trang=${Math.floor(Number(data.query?.trang))}` : "") : (data.basePath || undefined),
9
9
  alternates: Object.fromEntries((data.alternates ?? []).map((a) => [a.locale, a.link])),
10
10
  openGraph: {
11
11
  title: data.post?.title ?? data.title,
package/dist/rich.d.ts CHANGED
@@ -55,6 +55,14 @@ export interface RenderContext {
55
55
  id: string;
56
56
  text: string;
57
57
  }>;
58
+ /** Chú thích của mark `footnote` trong nội dung đang vẽ (đánh số theo thứ tự xuất hiện). shortcut: chỉ gom trong một lần renderContent, mẫu đồng bộ lồng vào không có số. */
59
+ footnotes?: {
60
+ notes: Array<{
61
+ note: string;
62
+ mark: object;
63
+ }>;
64
+ prefix: string;
65
+ };
58
66
  /**
59
67
  * Đang xem bản nháp (Trình dựng / xem trực tiếp): gắn data-ecx-doc + data-ecx-path cho từng khối để khung soạn ở admin
60
68
  * biết người dùng bấm vào khối nào. `source` = tài liệu đang vẽ ("template:single", "part:header", "post:12", "pattern:3").
package/dist/rich.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Fragment, cloneElement, isValidElement } from "react";
3
+ import { ICON_PATHS } from "./icons.js";
3
4
  import { DYNAMIC_NODES, colorCss, embedInfo, motionClasses, normalizeContent, safeUrl, spacingValue, styleClass, styleCss } from "@ecomcx/ecomweb-content";
4
5
  import { cx } from "./utils.js";
5
6
  import { SOCIAL_ICONS } from "./social-icons.js";
@@ -35,6 +36,20 @@ function collectHeadings(blocks) {
35
36
  walk(b.data);
36
37
  return out;
37
38
  }
39
+ function collectFootnotes(blocks) {
40
+ const out = [];
41
+ const walk = (n) => {
42
+ for (const m of n.marks ?? [])
43
+ if (m.type === "footnote" && typeof m.attrs?.note === "string" && m.attrs.note)
44
+ out.push({ note: m.attrs.note, mark: m });
45
+ for (const c of n.content ?? [])
46
+ walk(c);
47
+ };
48
+ for (const b of blocks)
49
+ if (b.type === "richtext" && b.data)
50
+ walk(b.data);
51
+ return out;
52
+ }
38
53
  function plainText(node) {
39
54
  if (node.type === "text")
40
55
  return node.text ?? "";
@@ -48,7 +63,7 @@ const TONES = { info: "#2563eb", success: "#16a34a", warning: "#d97706", danger:
48
63
  function alignStyle(attrs) {
49
64
  return attrs?.textAlign && attrs.textAlign !== "left" ? { textAlign: attrs.textAlign } : undefined;
50
65
  }
51
- function renderMarks(text, marks, key) {
66
+ function renderMarks(text, marks, key, ctx) {
52
67
  let out = text;
53
68
  for (const [i, m] of (marks ?? []).entries()) {
54
69
  const k = `${key}-m${i}`;
@@ -68,6 +83,16 @@ function renderMarks(text, marks, key) {
68
83
  case "code":
69
84
  out = _jsx("code", { children: out }, k);
70
85
  break;
86
+ case "footnote": {
87
+ const f = ctx?.footnotes;
88
+ const n = f ? f.notes.findIndex((x) => x.mark === m) + 1 : 0;
89
+ if (n > 0)
90
+ out = _jsxs(Fragment, { children: [out, _jsx("sup", { className: "ecx-footnote-ref", id: `fnref-${f.prefix}-${n}`, children: _jsxs("a", { href: `#fn-${f.prefix}-${n}`, children: ["[", n, "]"] }) })] }, k);
91
+ break;
92
+ }
93
+ case "kbd":
94
+ out = _jsx("kbd", { children: out }, k);
95
+ break;
71
96
  case "subscript":
72
97
  out = _jsx("sub", { children: out }, k);
73
98
  break;
@@ -217,7 +242,7 @@ async function renderNodeInner(node, key, ctx) {
217
242
  const a = node.attrs ?? {};
218
243
  switch (node.type) {
219
244
  case "doc": return _jsx(Fragment, { children: await children() }, key);
220
- case "text": return renderMarks(node.text ?? "", node.marks, key);
245
+ case "text": return renderMarks(node.text ?? "", node.marks, key, ctx);
221
246
  case "paragraph": {
222
247
  // Đoạn văn chỉ chứa shortcode → render component của plugin.
223
248
  const text = plainText(node);
@@ -246,6 +271,20 @@ async function renderNodeInner(node, key, ctx) {
246
271
  case "blockquote": return _jsxs("blockquote", { children: [await children(), a.citation && _jsx("cite", { children: a.citation })] }, key);
247
272
  case "codeBlock": return _jsx("pre", { children: _jsx("code", { className: a.language ? `language-${a.language}` : undefined, children: plainText(node) }) }, key);
248
273
  case "hardBreak": return _jsx("br", {}, key);
274
+ case "pageBreak": return null;
275
+ case "footnotes": {
276
+ const f = ctx.footnotes;
277
+ if (!f?.notes.length)
278
+ return null;
279
+ return (_jsxs("aside", { className: "ecx-footnotes", children: [a.title && _jsx("p", { className: "ecx-footnotes-title", children: a.title }), _jsx("ol", { children: f.notes.map((x, i) => _jsxs("li", { id: `fn-${f.prefix}-${i + 1}`, children: [x.note, " ", _jsx("a", { href: `#fnref-${f.prefix}-${i + 1}`, "aria-label": "\u21A9", children: "\u21A9" })] }, i)) })] }, key));
280
+ }
281
+ case "icon": {
282
+ const path = ICON_PATHS[String(a.name)];
283
+ if (!path)
284
+ return null;
285
+ const size = Math.min(128, Math.max(12, Number(a.size) || 24));
286
+ return _jsx("div", { className: "ecx-icon-block", style: alignStyle(a), children: _jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", role: a.label ? "img" : undefined, "aria-label": a.label || undefined, "aria-hidden": a.label ? undefined : true, children: _jsx("path", { d: path }) }) }, key);
287
+ }
249
288
  case "horizontalRule": return _jsx("hr", {}, key);
250
289
  case "image": {
251
290
  // Ảnh chèn từ thư viện mang sẵn srcset (JPEG + WebP) và kích thước → responsive, không nhảy layout
@@ -476,8 +515,10 @@ export async function renderContent(content, ctx, transform) {
476
515
  const blocks = transform ? await transform(doc.blocks) : doc.blocks;
477
516
  // Lần vẽ ngoài cùng gom CSS kiểu dáng của mọi khối (kể cả phần lồng bên trong) thành một thẻ <style>
478
517
  const own = !ctx.styles;
479
- if (own)
480
- ctx = { ...ctx, styles: new Map(), headings: ctx.headings ?? collectHeadings(blocks) };
518
+ if (own) {
519
+ const notes = collectFootnotes(blocks);
520
+ ctx = { ...ctx, styles: new Map(), headings: ctx.headings ?? collectHeadings(blocks), footnotes: ctx.footnotes ?? (notes.length ? { notes, prefix: String(ctx.post?.id ?? "x") } : undefined) };
521
+ }
481
522
  const out = await Promise.all(blocks.map((b, i) => renderBlock(b, b.id ?? `b${i}`, ctx)));
482
523
  if (own && ctx.styles.size)
483
524
  out.unshift(_jsx("style", { "data-ecx-styles": "", children: [...ctx.styles.values()].join("") }, "ecx-styles"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-theme-sdk",
3
- "version": "1.33.0",
3
+ "version": "1.34.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.17.0",
36
+ "@ecomcx/ecomweb-content": "^1.18.0",
37
37
  "intl-messageformat": "12.1.3"
38
38
  },
39
39
  "peerDependencies": {