@ecomcx/ecomweb-theme-sdk 1.43.0 → 2.0.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 +1546 -0
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/api.d.ts +86 -14
- package/dist/api.js +84 -19
- package/dist/auth-shared.d.ts +2 -1
- package/dist/auth-shared.js +2 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +1 -1
- package/dist/client.d.ts +26 -5
- package/dist/client.js +62 -12
- package/dist/components.d.ts +17 -2
- package/dist/components.js +41 -12
- package/dist/conditions.d.ts +45 -0
- package/dist/conditions.js +27 -0
- package/dist/consent-server.d.ts +6 -0
- package/dist/consent-server.js +11 -0
- package/dist/consent.d.ts +0 -5
- package/dist/consent.js +0 -11
- package/dist/content.js +2 -1
- package/dist/dynamic.js +5 -5
- package/dist/i18n.d.ts +4 -0
- package/dist/i18n.js +4 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +10 -5
- package/dist/rich.d.ts +2 -0
- package/dist/rich.js +61 -26
- package/dist/runtime.d.ts +12 -6
- package/dist/runtime.js +14 -5
- package/dist/utils.d.ts +18 -1
- package/dist/utils.js +24 -1
- package/package.json +15 -8
package/dist/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { countdownParts, SEARCH_ICON_PATH } from "@ecomcx/ecomweb-content";
|
|
3
4
|
import { extraFields } from "./auth-forms.js";
|
|
4
5
|
import { Component, Suspense, useEffect, useId, useRef, useState } from "react";
|
|
5
6
|
import { usePathname, useRouter } from "next/navigation";
|
|
@@ -27,6 +28,7 @@ export class ExtensionBoundary extends Component {
|
|
|
27
28
|
// ---------------------------------------------------------------------------
|
|
28
29
|
/** Đường dẫn không phải trang của theme (file, feed, API…) → luôn tải lại bình thường. */
|
|
29
30
|
const NON_PAGE = /^\/(uploads|api|_next|extensions)\/|^\/(feed|sitemap\.xml|robots\.txt)(\?|$)|\.[a-z0-9]{2,5}(\?|$)/i;
|
|
31
|
+
/** `true` nếu link là trang của website (chuyển trang không tải lại); file, feed, API, link ngoài → `false`. */
|
|
30
32
|
export function isInternalHref(href) {
|
|
31
33
|
return href.startsWith("/") && !href.startsWith("//") && !NON_PAGE.test(href);
|
|
32
34
|
}
|
|
@@ -45,6 +47,10 @@ function PendingSignal() {
|
|
|
45
47
|
}, [pending]);
|
|
46
48
|
return null;
|
|
47
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Link chuyển trang không tải lại (bọc `next/link`); link ngoài, file, RSS tự dùng `<a>` thường.
|
|
52
|
+
* `activeClassName` gắn class khi URL hiện tại khớp (`matchNested`: khớp cả trang con). Prefetch mặc định tắt.
|
|
53
|
+
*/
|
|
48
54
|
export function Link({ href, prefetch = false, activeClassName, matchNested = true, className, children, ...rest }) {
|
|
49
55
|
const pathname = usePathname();
|
|
50
56
|
const path = href.split(/[?#]/)[0];
|
|
@@ -60,9 +66,11 @@ export function Link({ href, prefetch = false, activeClassName, matchNested = tr
|
|
|
60
66
|
}, children: [children, _jsx(PendingSignal, {})] }));
|
|
61
67
|
}
|
|
62
68
|
/** Form tìm kiếm (GET) chuyển trang phía client. */
|
|
63
|
-
export function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition = "right" }) {
|
|
69
|
+
export function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition = "right", buttonIcon }) {
|
|
64
70
|
const id = useId();
|
|
65
|
-
const button =
|
|
71
|
+
const button = buttonIcon
|
|
72
|
+
? _jsx("button", { type: "submit", "aria-label": buttonLabel, title: buttonLabel, children: _jsx("svg", { viewBox: "0 0 24 24", width: 18, height: 18, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: SEARCH_ICON_PATH }) }) })
|
|
73
|
+
: _jsx("button", { type: "submit", children: buttonLabel });
|
|
66
74
|
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] }));
|
|
67
75
|
}
|
|
68
76
|
/** Ghi tuỳ chọn hiển thị của người đọc (xem getPreference). value = null để xoá. */
|
|
@@ -219,7 +227,7 @@ export function LanguageSwitcherClient({ languages, current, defaultLocale, labe
|
|
|
219
227
|
export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
|
|
220
228
|
export { safeRedirect } from "./auth-shared.js";
|
|
221
229
|
/** 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. */
|
|
222
|
-
export function CountdownClient({ target, label, expiredText, units, serverNow }) {
|
|
230
|
+
export function CountdownClient({ target, label, expiredText, units, serverNow, attrs = {} }) {
|
|
223
231
|
// Lần render đầu của client dùng ĐÚNG thời điểm máy chủ đã dùng (serverNow) để khớp HTML dựng sẵn / cache; sau đó lấy giờ thật ngay (tránh hydration mismatch #418)
|
|
224
232
|
const [now, setNow] = useState(() => serverNow ?? Date.now());
|
|
225
233
|
useEffect(() => { setNow(Date.now()); }, []);
|
|
@@ -227,10 +235,33 @@ export function CountdownClient({ target, label, expiredText, units, serverNow }
|
|
|
227
235
|
const left = Math.max(0, target - now);
|
|
228
236
|
if (left === 0 && expiredText)
|
|
229
237
|
return _jsx("div", { className: "ecx-countdown is-expired", children: expiredText });
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
238
|
+
const post = typeof attrs.postText === "string" && attrs.postText ? attrs.postText : null;
|
|
239
|
+
return (_jsxs("div", { className: cx("ecx-countdown", attrs.layout === "inline" && "is-inline", attrs.divider === true && "has-divider"), role: "timer", "aria-live": "off", suppressHydrationWarning: true, children: [label && _jsx("p", { className: "ecx-countdown-label", children: label }), _jsx("div", { className: "ecx-countdown-parts", children: countdownParts(attrs, left, units).map((p) => _jsxs("span", { className: `ecx-countdown-${p.u}`, children: [_jsx("strong", { children: p.value }), _jsx("small", { children: p.label })] }, p.u)) }), post && _jsx("p", { className: "ecx-countdown-post", children: post })] }));
|
|
240
|
+
}
|
|
241
|
+
/** Mục lục: tô đậm mục của tiêu đề đang đọc (tiêu đề cuối cùng đã cuộn qua mép trên 120px) — aria-current="location". */
|
|
242
|
+
export function TocSpy() {
|
|
243
|
+
const ref = useRef(null);
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
const nav = ref.current?.closest("nav");
|
|
246
|
+
if (!nav)
|
|
247
|
+
return;
|
|
248
|
+
const links = [...nav.querySelectorAll('a[href^="#"]')];
|
|
249
|
+
const targets = links.map((l) => document.getElementById(decodeURIComponent(l.hash.slice(1))));
|
|
250
|
+
let raf = 0;
|
|
251
|
+
const update = () => {
|
|
252
|
+
raf = 0;
|
|
253
|
+
let cur = -1;
|
|
254
|
+
targets.forEach((t, i) => { if (t && t.getBoundingClientRect().top < 120)
|
|
255
|
+
cur = i; });
|
|
256
|
+
links.forEach((l, i) => (i === cur ? l.setAttribute("aria-current", "location") : l.removeAttribute("aria-current")));
|
|
257
|
+
};
|
|
258
|
+
const onScroll = () => { if (!raf)
|
|
259
|
+
raf = requestAnimationFrame(update); };
|
|
260
|
+
update();
|
|
261
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
262
|
+
return () => { window.removeEventListener("scroll", onScroll); cancelAnimationFrame(raf); };
|
|
263
|
+
}, []);
|
|
264
|
+
return _jsx("span", { ref: ref, hidden: true });
|
|
234
265
|
}
|
|
235
266
|
/** Nút ☰ của menu trên điện thoại: <details> gốc + Escape đóng menu và trả focus về nút. */
|
|
236
267
|
export function NavToggle({ label, children, className = "ecx-navigation-toggle" }) {
|
|
@@ -245,20 +276,34 @@ export function NavToggle({ label, children, className = "ecx-navigation-toggle"
|
|
|
245
276
|
}, []);
|
|
246
277
|
return _jsxs("details", { ref: ref, className: className, children: [_jsx("summary", { "aria-label": label, children: "\u2630" }), children] });
|
|
247
278
|
}
|
|
248
|
-
/**
|
|
249
|
-
|
|
250
|
-
|
|
279
|
+
/**
|
|
280
|
+
* 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.
|
|
281
|
+
* Tab dọc (`vertical`), thành accordion trên điện thoại (`mobileAccordion`, chỉ CSS: tiêu đề nằm ngay trên panel của nó);
|
|
282
|
+
* tab có neo → panel mang id = neo, mở thẳng bằng #neo.
|
|
283
|
+
*/
|
|
284
|
+
export function TabsClient({ titles, panels, initial = 0, icons, subtitles, anchors, vertical, mobileAccordion, extraClass }) {
|
|
285
|
+
const [active, setActive] = useState(initial < titles.length ? initial : 0);
|
|
251
286
|
const id = useId();
|
|
287
|
+
useEffect(() => {
|
|
288
|
+
if (!anchors?.some(Boolean))
|
|
289
|
+
return;
|
|
290
|
+
const open = () => { const i = anchors.indexOf(decodeURIComponent(location.hash.slice(1))); if (i >= 0)
|
|
291
|
+
setActive(i); };
|
|
292
|
+
open();
|
|
293
|
+
window.addEventListener("hashchange", open);
|
|
294
|
+
return () => window.removeEventListener("hashchange", open);
|
|
295
|
+
}, [anchors]);
|
|
252
296
|
const move = (e, i) => {
|
|
253
297
|
const n = titles.length;
|
|
254
|
-
const
|
|
298
|
+
const fwd = vertical ? "ArrowDown" : "ArrowRight", back = vertical ? "ArrowUp" : "ArrowLeft";
|
|
299
|
+
const next = e.key === fwd ? (i + 1) % n : e.key === back ? (i + n - 1) % n : e.key === "Home" ? 0 : e.key === "End" ? n - 1 : -1;
|
|
255
300
|
if (next < 0)
|
|
256
301
|
return;
|
|
257
302
|
e.preventDefault();
|
|
258
303
|
setActive(next);
|
|
259
304
|
document.getElementById(`${id}-t${next}`)?.focus();
|
|
260
305
|
};
|
|
261
|
-
return (_jsxs("div", { className: "ecx-tabs", children: [_jsx("div", { role: "tablist", className: "ecx-tabs-list", children: titles.map((t, i) => (
|
|
306
|
+
return (_jsxs("div", { className: extraClass ?? cx("ecx-tabs", vertical && "is-vertical", mobileAccordion && "has-mobile-accordion"), children: [_jsx("div", { role: "tablist", className: "ecx-tabs-list", "aria-orientation": vertical ? "vertical" : undefined, children: titles.map((t, i) => (_jsxs("button", { type: "button", role: "tab", id: `${id}-t${i}`, "aria-selected": i === active, "aria-controls": anchors?.[i] ?? `${id}-p${i}`, tabIndex: i === active ? 0 : -1, className: cx("ecx-tab-button", i === active && "is-active"), style: { "--i": i }, onClick: () => setActive(i), onKeyDown: (e) => move(e, i), children: [icons?.[i] && _jsx("svg", { className: "ecx-tab-icon", viewBox: "0 0 24 24", width: 18, height: 18, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: icons[i] }) }), _jsxs("span", { className: "ecx-tab-label", children: [t, subtitles?.[i] && _jsx("small", { className: "ecx-tab-subtitle", children: subtitles[i] })] })] }, i))) }), panels.map((p, i) => _jsx("div", { role: "tabpanel", id: anchors?.[i] ?? `${id}-p${i}`, "aria-labelledby": `${id}-t${i}`, hidden: i !== active, className: "ecx-tab-panel", style: { "--i": i }, children: p }, i))] }));
|
|
262
307
|
}
|
|
263
308
|
/** 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ủ. */
|
|
264
309
|
export function LightboxClient({ src, alt, children }) {
|
|
@@ -317,6 +362,11 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
|
|
|
317
362
|
return;
|
|
318
363
|
}
|
|
319
364
|
form.reset();
|
|
365
|
+
// 1.26: chuyển trang sau khi gửi (máy chủ chỉ trả đường dẫn trong site hoặc http(s))
|
|
366
|
+
if (typeof json.redirect === "string" && /^(\/(?![\/\\])|https?:\/\/)/.test(json.redirect)) {
|
|
367
|
+
window.location.assign(json.redirect);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
320
370
|
setState({ status: "done", message: json.message || successMessage || "" });
|
|
321
371
|
}
|
|
322
372
|
catch {
|
package/dist/components.d.ts
CHANGED
|
@@ -7,10 +7,15 @@ export declare function Menu({ location, menuId, currentPath, className, fallbac
|
|
|
7
7
|
className?: string;
|
|
8
8
|
fallback?: ReactNode;
|
|
9
9
|
}): Promise<import("react").JSX.Element>;
|
|
10
|
+
/** Vẽ các widget của một khu vực (`theme.json › widgetAreas`) — tương đương `dynamic_sidebar`. Khu vực trống → không vẽ gì. */
|
|
10
11
|
export declare function WidgetArea({ id, className }: {
|
|
11
12
|
id: string;
|
|
12
13
|
className?: string;
|
|
13
14
|
}): Promise<import("react").JSX.Element | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Điểm cho plugin chèn nội dung (vd `before.content`, `body.end`) — tương đương `do_action` trong template.
|
|
17
|
+
* Mỗi plugin được bọc riêng: plugin lỗi thì phần đó ẩn, trang vẫn hiện.
|
|
18
|
+
*/
|
|
14
19
|
export declare function Slot<P = any>({ name, data, props, fallback, className, }: {
|
|
15
20
|
name: SlotName;
|
|
16
21
|
data?: ResolveResult | null;
|
|
@@ -19,7 +24,8 @@ export declare function Slot<P = any>({ name, data, props, fallback, className,
|
|
|
19
24
|
className?: string;
|
|
20
25
|
}): Promise<import("react").JSX.Element>;
|
|
21
26
|
/** Ô 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, postType, showLabel, buttonPosition }: {
|
|
27
|
+
export declare function SearchForm({ defaultValue, placeholder, buttonLabel, postType, showLabel, buttonPosition, buttonIcon }: {
|
|
28
|
+
buttonIcon?: boolean;
|
|
23
29
|
defaultValue?: string | null;
|
|
24
30
|
placeholder?: string;
|
|
25
31
|
buttonLabel?: string;
|
|
@@ -47,6 +53,10 @@ export declare function FeaturedImage({ media, size, className, link, label, siz
|
|
|
47
53
|
sizes?: string;
|
|
48
54
|
priority?: boolean;
|
|
49
55
|
}): import("react").JSX.Element | null;
|
|
56
|
+
/**
|
|
57
|
+
* Ngày đăng của bài trong thẻ `<time datetime>`, định dạng theo Cài đặt › Chung (xem {@link formatDate}) — tương đương `the_date`.
|
|
58
|
+
* Không truyền `site` thì tự đọc cấu hình của website (`getSite()`, có cache).
|
|
59
|
+
*/
|
|
50
60
|
export declare function PostDate({ post, site }: {
|
|
51
61
|
post: Post;
|
|
52
62
|
site?: {
|
|
@@ -54,7 +64,8 @@ export declare function PostDate({ post, site }: {
|
|
|
54
64
|
timezone: string;
|
|
55
65
|
locale?: string;
|
|
56
66
|
};
|
|
57
|
-
}): import("react").JSX.Element
|
|
67
|
+
}): Promise<import("react").JSX.Element>;
|
|
68
|
+
/** Danh sách link term (chuyên mục, thẻ), phân tách bằng `separator` — tương đương `the_category` / `the_tags`. @example <TermLinks terms={post.terms.category} /> */
|
|
58
69
|
export declare function TermLinks({ terms, separator }: {
|
|
59
70
|
terms?: Array<{
|
|
60
71
|
id: number;
|
|
@@ -63,6 +74,10 @@ export declare function TermLinks({ terms, separator }: {
|
|
|
63
74
|
}>;
|
|
64
75
|
separator?: string;
|
|
65
76
|
}): import("react").JSX.Element | null;
|
|
77
|
+
/**
|
|
78
|
+
* Khu bình luận đầy đủ: danh sách đã duyệt (phân trang + "Xem thêm"), form gửi, ảnh đại diện — tương đương `comments_template`.
|
|
79
|
+
* Tự ẩn với bài có mật khẩu chưa mở khoá. Tự dựng theo ý mình: {@link getComments}, `<CommentList>`, `<CommentForm>`.
|
|
80
|
+
*/
|
|
66
81
|
export declare function Comments({ post, title, perPage, order, avatarSize, showDate }: {
|
|
67
82
|
post: Post;
|
|
68
83
|
title?: string;
|
package/dist/components.js
CHANGED
|
@@ -15,8 +15,22 @@ function MenuItems({ items, currentPath, depth }) {
|
|
|
15
15
|
return (_jsxs("li", { className: cx("menu-item", item.cssClass, active && "current-menu-item", item.children.length > 0 && "has-children"), children: [_jsx(Link, { href: item.url, target: item.target ?? undefined, rel: item.target === "_blank" ? "noopener noreferrer" : undefined, "aria-current": active ? "page" : undefined, activeClassName: "current-menu-link", matchNested: item.url !== "/", children: item.title }), item.children.length > 0 && _jsx(MenuItems, { items: item.children, currentPath: currentPath, depth: depth + 1 })] }, item.id));
|
|
16
16
|
}) }));
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Menu theo vị trí (`location`, khai trong `theme.json › menuLocations`) hoặc theo id (`menuId`) — tương đương `wp_nav_menu`.
|
|
20
|
+
* Link khớp URL hiện tại có class `current-menu-link` + `aria-current="page"`. Chưa gắn menu → `fallback` (mặc định không vẽ gì).
|
|
21
|
+
*/
|
|
22
|
+
/** Phần phụ của trang (menu, widget, bình luận): CMS lỗi thì ghi log và bỏ phần đó, trang vẫn hiện. */
|
|
23
|
+
async function soft(what, p) {
|
|
24
|
+
try {
|
|
25
|
+
return await p;
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
console.error(`[ecomweb] ${what}:`, e);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
18
32
|
export async function Menu({ location, menuId, currentPath, className, fallback }) {
|
|
19
|
-
const menu = menuId ? await getMenuById(menuId) : location ? await getMenu(location) : null;
|
|
33
|
+
const menu = menuId ? await soft(`menu #${menuId}`, getMenuById(menuId)) : location ? await soft(`menu "${location}"`, getMenu(location)) : null;
|
|
20
34
|
if (!menu || menu.items.length === 0)
|
|
21
35
|
return _jsx(_Fragment, { children: fallback ?? null });
|
|
22
36
|
return _jsx("nav", { className: className, "aria-label": menu.name, children: _jsx(MenuItems, { items: menu.items, currentPath: currentPath, depth: 0 }) });
|
|
@@ -35,7 +49,7 @@ async function CoreWidget({ widget }) {
|
|
|
35
49
|
return _jsx("ul", { children: items.map((p) => _jsx("li", { children: _jsx(Link, { href: p.link, children: p.title }) }, p.id)) });
|
|
36
50
|
}
|
|
37
51
|
case "categories": {
|
|
38
|
-
const terms = await getTerms("category"
|
|
52
|
+
const terms = await getTerms({ taxonomy: "category" });
|
|
39
53
|
// Phân cấp: chuyên mục con lồng trong chuyên mục cha
|
|
40
54
|
const ids = new Set(terms.map((t) => t.id));
|
|
41
55
|
const tree = (parent) => {
|
|
@@ -45,7 +59,7 @@ async function CoreWidget({ widget }) {
|
|
|
45
59
|
return tree(null);
|
|
46
60
|
}
|
|
47
61
|
case "tag-cloud": {
|
|
48
|
-
const terms = await getTerms("post_tag"
|
|
62
|
+
const terms = await getTerms({ taxonomy: "post_tag" });
|
|
49
63
|
const max = Math.max(1, ...terms.map((t) => t.count));
|
|
50
64
|
return _jsx("div", { className: "tagcloud", children: terms.map((t) => _jsx(Link, { href: t.link, style: { fontSize: `${0.8 + (t.count / max) * 0.8}em` }, children: t.name }, t.id)) });
|
|
51
65
|
}
|
|
@@ -57,13 +71,14 @@ async function CoreWidget({ widget }) {
|
|
|
57
71
|
default: return null;
|
|
58
72
|
}
|
|
59
73
|
}
|
|
74
|
+
/** Vẽ các widget của một khu vực (`theme.json › widgetAreas`) — tương đương `dynamic_sidebar`. Khu vực trống → không vẽ gì. */
|
|
60
75
|
export async function WidgetArea({ id, className }) {
|
|
61
|
-
const [site, widgets] = await Promise.all([getSite(), getWidgets(id)]);
|
|
62
|
-
if (widgets
|
|
76
|
+
const [site, widgets] = await Promise.all([getSite(), soft(`widget area "${id}"`, getWidgets(id))]);
|
|
77
|
+
if (!widgets?.length)
|
|
63
78
|
return null;
|
|
64
79
|
const rendered = await Promise.all(widgets.map(async (w) => {
|
|
65
80
|
const Plugin = await findWidget(w.type, site);
|
|
66
|
-
const body = Plugin ? _jsx(ExtensionBoundary, { name: `Widget ${w.type}`, children: _jsx(Plugin, { widget: w, settings: w.settings ?? {}, site: site }) }) : await CoreWidget({ widget: w });
|
|
81
|
+
const body = Plugin ? _jsx(ExtensionBoundary, { name: `Widget ${w.type}`, children: _jsx(Plugin, { widget: w, settings: w.settings ?? {}, site: site }) }) : await soft(`widget ${w.type}`, CoreWidget({ widget: w }));
|
|
67
82
|
if (!body)
|
|
68
83
|
return null;
|
|
69
84
|
return (_jsxs("section", { className: cx("widget", `widget-${w.type}`), children: [w.title && _jsx("h2", { className: "widget-title", children: w.title }), body] }, w.id));
|
|
@@ -73,6 +88,10 @@ export async function WidgetArea({ id, className }) {
|
|
|
73
88
|
// ---------------------------------------------------------------------------
|
|
74
89
|
// Slot cho plugin (head, cuối trang, trước/sau nội dung…)
|
|
75
90
|
// ---------------------------------------------------------------------------
|
|
91
|
+
/**
|
|
92
|
+
* Điểm cho plugin chèn nội dung (vd `before.content`, `body.end`) — tương đương `do_action` trong template.
|
|
93
|
+
* Mỗi plugin được bọc riêng: plugin lỗi thì phần đó ẩn, trang vẫn hiện.
|
|
94
|
+
*/
|
|
76
95
|
export async function Slot({ name, data, props, fallback, className, }) {
|
|
77
96
|
const site = await getSite();
|
|
78
97
|
const items = await getSlotItems(name, site);
|
|
@@ -85,9 +104,9 @@ export async function Slot({ name, data, props, fallback, className, }) {
|
|
|
85
104
|
// Tiện ích hiển thị
|
|
86
105
|
// ---------------------------------------------------------------------------
|
|
87
106
|
/** Ô 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, postType, showLabel, buttonPosition }) {
|
|
107
|
+
export async function SearchForm({ defaultValue, placeholder, buttonLabel, postType, showLabel, buttonPosition, buttonIcon }) {
|
|
89
108
|
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"), postType: postType, showLabel: showLabel, buttonPosition: buttonPosition });
|
|
109
|
+
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, buttonIcon: buttonIcon, buttonPosition: buttonPosition });
|
|
91
110
|
}
|
|
92
111
|
function paramLink(data, param, p) {
|
|
93
112
|
const q = new URLSearchParams(Object.entries(data.query ?? {}).filter(([k]) => k !== param));
|
|
@@ -128,9 +147,15 @@ export function FeaturedImage({ media, size = "large", className, link, label, s
|
|
|
128
147
|
const name = link && !media.alt?.trim() && label?.trim() ? label : undefined;
|
|
129
148
|
return _jsx("figure", { className: cx("featured-image", className), children: link ? _jsx(Link, { href: link, "aria-label": name, children: img }) : img });
|
|
130
149
|
}
|
|
131
|
-
|
|
132
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Ngày đăng của bài trong thẻ `<time datetime>`, định dạng theo Cài đặt › Chung (xem {@link formatDate}) — tương đương `the_date`.
|
|
152
|
+
* Không truyền `site` thì tự đọc cấu hình của website (`getSite()`, có cache).
|
|
153
|
+
*/
|
|
154
|
+
export async function PostDate({ post, site }) {
|
|
155
|
+
const s = site ?? (await getSite());
|
|
156
|
+
return _jsx("time", { dateTime: post.publishedAt ?? post.createdAt, children: formatDate(post.publishedAt ?? post.createdAt, s) });
|
|
133
157
|
}
|
|
158
|
+
/** Danh sách link term (chuyên mục, thẻ), phân tách bằng `separator` — tương đương `the_category` / `the_tags`. @example <TermLinks terms={post.terms.category} /> */
|
|
134
159
|
export function TermLinks({ terms, separator = ", " }) {
|
|
135
160
|
if (!terms?.length)
|
|
136
161
|
return null;
|
|
@@ -139,18 +164,22 @@ export function TermLinks({ terms, separator = ", " }) {
|
|
|
139
164
|
// ---------------------------------------------------------------------------
|
|
140
165
|
// Khu bình luận
|
|
141
166
|
// ---------------------------------------------------------------------------
|
|
167
|
+
/**
|
|
168
|
+
* Khu bình luận đầy đủ: danh sách đã duyệt (phân trang + "Xem thêm"), form gửi, ảnh đại diện — tương đương `comments_template`.
|
|
169
|
+
* Tự ẩn với bài có mật khẩu chưa mở khoá. Tự dựng theo ý mình: {@link getComments}, `<CommentList>`, `<CommentForm>`.
|
|
170
|
+
*/
|
|
142
171
|
export async function Comments({ post, title, perPage, order, avatarSize, showDate }) {
|
|
143
172
|
if (post.commentStatus !== "open" && post.commentCount === 0)
|
|
144
173
|
return null;
|
|
145
174
|
if (post.passwordProtected && !post.content)
|
|
146
175
|
return null; // bài có mật khẩu: ẩn bình luận tới khi mở khoá
|
|
147
176
|
const unlock = post.passwordProtected ? await requestUnlock() : undefined;
|
|
148
|
-
const [site, page, t] = await Promise.all([getSite(), getComments(post.id,
|
|
177
|
+
const [site, page, t] = await Promise.all([getSite(), soft(`comments #${post.id}`, getComments(post.id, { unlock, perPage, order })), getT()]);
|
|
149
178
|
const comments = page?.items ?? [];
|
|
150
179
|
const dateSite = { dateFormat: site.dateFormat, timezone: site.timezone, locale: site.locale };
|
|
151
180
|
title ??= t("comments.title");
|
|
152
181
|
const labels = Object.fromEntries(["title", "content", "name", "email", "website", "submit", "sending", "approved", "pending", "error"].map((k) => [k, t(`comments.form.${k}`)]));
|
|
153
|
-
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 }),
|
|
182
|
+
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 && page.totalPages > 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"
|
|
154
183
|
? _jsx(CommentForm, { postId: post.id, labels: labels, fields: _jsx(Slot, { name: "comment_form.fields", props: { post } }) })
|
|
155
184
|
: _jsx("p", { className: "no-comments", children: t("comments.closed") }), _jsx(Slot, { name: "comments.after", props: { post } })] }));
|
|
156
185
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ResolveResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Điều kiện loại trang (tương đương conditional tags của WP: `is_front_page`, `is_single`…), đọc từ `data` của `TemplateProps`.
|
|
4
|
+
* Hàm thuần, không gọi mạng, chạy được ở server và client.
|
|
5
|
+
* @since 1.44.0
|
|
6
|
+
*/
|
|
7
|
+
type Page = Pick<ResolveResult, "kind"> & {
|
|
8
|
+
templates?: string[];
|
|
9
|
+
} & {
|
|
10
|
+
post?: {
|
|
11
|
+
slug?: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
} | null;
|
|
14
|
+
term?: {
|
|
15
|
+
slug?: string;
|
|
16
|
+
taxonomy?: string;
|
|
17
|
+
} | null;
|
|
18
|
+
};
|
|
19
|
+
/** Trang chủ của website, dạng bài mới hoặc trang tĩnh — `is_front_page`. */
|
|
20
|
+
export declare const isFrontPage: (data: Page) => boolean;
|
|
21
|
+
/** Danh sách bài của blog — `is_home`: trang chủ dạng bài mới, hoặc trang được chọn làm "Trang bài viết" (Cài đặt › Đọc). */
|
|
22
|
+
export declare const isHome: (data: Page) => boolean;
|
|
23
|
+
/** Một bài (không phải trang tĩnh); `type` để kiểm tra loại nội dung, vd `isSingle(data, "product")` — `is_single` / `is_singular($type)`. */
|
|
24
|
+
export declare const isSingle: (data: Page, type?: string) => boolean;
|
|
25
|
+
/** Trang tĩnh; `slug` để kiểm tra trang cụ thể, vd `isPage(data, "lien-he")` — `is_page`. */
|
|
26
|
+
export declare const isPage: (data: Page, slug?: string) => boolean;
|
|
27
|
+
/** Bài hoặc trang tĩnh (có `data.post`) — `is_singular`. */
|
|
28
|
+
export declare const isSingular: (data: Page) => boolean;
|
|
29
|
+
/** Trang chuyên mục; `slug` để kiểm tra chuyên mục cụ thể — `is_category`. */
|
|
30
|
+
export declare const isCategory: (data: Page, slug?: string) => boolean;
|
|
31
|
+
/** Trang thẻ; `slug` để kiểm tra thẻ cụ thể — `is_tag`. */
|
|
32
|
+
export declare const isTag: (data: Page, slug?: string) => boolean;
|
|
33
|
+
/** Trang của phân loại tuỳ biến; `taxonomy` để kiểm tra phân loại cụ thể — `is_tax`. */
|
|
34
|
+
export declare const isTax: (data: Page, taxonomy?: string) => boolean;
|
|
35
|
+
/** Trang tác giả — `is_author`. */
|
|
36
|
+
export declare const isAuthor: (data: Page) => boolean;
|
|
37
|
+
/** Trang lưu trữ theo ngày — `is_date`. */
|
|
38
|
+
export declare const isDate: (data: Page) => boolean;
|
|
39
|
+
/** Mọi trang lưu trữ: chuyên mục, thẻ, phân loại, tác giả, ngày, lưu trữ theo loại nội dung — `is_archive`. */
|
|
40
|
+
export declare const isArchive: (data: Page) => boolean;
|
|
41
|
+
/** Trang kết quả tìm kiếm — `is_search`. */
|
|
42
|
+
export declare const isSearch: (data: Page) => boolean;
|
|
43
|
+
/** Trang không tìm thấy — `is_404`. */
|
|
44
|
+
export declare const is404: (data: Page) => boolean;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const ARCHIVE_KINDS = new Set(["category", "tag", "taxonomy", "author", "date", "archive"]);
|
|
2
|
+
/** Trang chủ của website, dạng bài mới hoặc trang tĩnh — `is_front_page`. */
|
|
3
|
+
export const isFrontPage = (data) => data.kind === "front-page" || (data.kind === "home" && data.templates?.[0] === "front-page");
|
|
4
|
+
/** Danh sách bài của blog — `is_home`: trang chủ dạng bài mới, hoặc trang được chọn làm "Trang bài viết" (Cài đặt › Đọc). */
|
|
5
|
+
export const isHome = (data) => data.kind === "home";
|
|
6
|
+
/** Một bài (không phải trang tĩnh); `type` để kiểm tra loại nội dung, vd `isSingle(data, "product")` — `is_single` / `is_singular($type)`. */
|
|
7
|
+
export const isSingle = (data, type) => data.kind === "single" && (!type || data.post?.type === type);
|
|
8
|
+
/** Trang tĩnh; `slug` để kiểm tra trang cụ thể, vd `isPage(data, "lien-he")` — `is_page`. */
|
|
9
|
+
export const isPage = (data, slug) => (data.kind === "page" || data.kind === "front-page") && (!slug || data.post?.slug === slug);
|
|
10
|
+
/** Bài hoặc trang tĩnh (có `data.post`) — `is_singular`. */
|
|
11
|
+
export const isSingular = (data) => isSingle(data) || isPage(data);
|
|
12
|
+
/** Trang chuyên mục; `slug` để kiểm tra chuyên mục cụ thể — `is_category`. */
|
|
13
|
+
export const isCategory = (data, slug) => data.kind === "category" && (!slug || data.term?.slug === slug);
|
|
14
|
+
/** Trang thẻ; `slug` để kiểm tra thẻ cụ thể — `is_tag`. */
|
|
15
|
+
export const isTag = (data, slug) => data.kind === "tag" && (!slug || data.term?.slug === slug);
|
|
16
|
+
/** Trang của phân loại tuỳ biến; `taxonomy` để kiểm tra phân loại cụ thể — `is_tax`. */
|
|
17
|
+
export const isTax = (data, taxonomy) => data.kind === "taxonomy" && (!taxonomy || data.term?.taxonomy === taxonomy);
|
|
18
|
+
/** Trang tác giả — `is_author`. */
|
|
19
|
+
export const isAuthor = (data) => data.kind === "author";
|
|
20
|
+
/** Trang lưu trữ theo ngày — `is_date`. */
|
|
21
|
+
export const isDate = (data) => data.kind === "date";
|
|
22
|
+
/** Mọi trang lưu trữ: chuyên mục, thẻ, phân loại, tác giả, ngày, lưu trữ theo loại nội dung — `is_archive`. */
|
|
23
|
+
export const isArchive = (data) => ARCHIVE_KINDS.has(data.kind);
|
|
24
|
+
/** Trang kết quả tìm kiếm — `is_search`. */
|
|
25
|
+
export const isSearch = (data) => data.kind === "search";
|
|
26
|
+
/** Trang không tìm thấy — `is_404`. */
|
|
27
|
+
export const is404 = (data) => data.kind === "404";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ConsentCategory } from "./consent.js";
|
|
2
|
+
/**
|
|
3
|
+
* (Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true.
|
|
4
|
+
* Không đọc cookie nên không làm mất cache trang; dùng cho phần không có JS (vd <noscript> của GTM).
|
|
5
|
+
*/
|
|
6
|
+
export declare function consentDefault(category: ConsentCategory): Promise<boolean>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { applyFilters } from "./runtime.js";
|
|
2
|
+
// Tách khỏi consent.ts: file đó dùng chung với client.tsx, còn hàm này cần runtime (server-only).
|
|
3
|
+
/**
|
|
4
|
+
* (Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true.
|
|
5
|
+
* Không đọc cookie nên không làm mất cache trang; dùng cho phần không có JS (vd <noscript> của GTM).
|
|
6
|
+
*/
|
|
7
|
+
export async function consentDefault(category) {
|
|
8
|
+
if (category === "functional")
|
|
9
|
+
return true;
|
|
10
|
+
return (await applyFilters("consent.default", true, { category })) !== false;
|
|
11
|
+
}
|
package/dist/consent.d.ts
CHANGED
|
@@ -22,8 +22,3 @@ export declare function parseConsent(value: string | undefined): ConsentCategory
|
|
|
22
22
|
export declare function serializeConsent(categories: readonly ConsentCategory[]): string;
|
|
23
23
|
/** Quyết định cho một nhóm: khách đã trả lời thì theo câu trả lời, chưa thì theo mặc định của plugin banner. */
|
|
24
24
|
export declare function decideConsent(category: ConsentCategory, choice: ConsentCategory[] | undefined, fallback: boolean): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* (Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true.
|
|
27
|
-
* Không đọc cookie nên không làm mất cache trang; dùng cho phần không có JS (vd <noscript> của GTM).
|
|
28
|
-
*/
|
|
29
|
-
export declare function consentDefault(category: ConsentCategory): Promise<boolean>;
|
package/dist/consent.js
CHANGED
|
@@ -35,14 +35,3 @@ export function decideConsent(category, choice, fallback) {
|
|
|
35
35
|
return true;
|
|
36
36
|
return choice ? choice.includes(category) : fallback;
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* (Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true.
|
|
40
|
-
* Không đọc cookie nên không làm mất cache trang; dùng cho phần không có JS (vd <noscript> của GTM).
|
|
41
|
-
*/
|
|
42
|
-
export async function consentDefault(category) {
|
|
43
|
-
if (category === "functional")
|
|
44
|
-
return true;
|
|
45
|
-
// import động: client.tsx dùng chung file này mà không kéo runtime (server) vào bundle trình duyệt
|
|
46
|
-
const { applyFilters } = await import("./runtime.js");
|
|
47
|
-
return (await applyFilters("consent.default", true, { category })) !== false;
|
|
48
|
-
}
|
package/dist/content.js
CHANGED
|
@@ -100,7 +100,8 @@ export async function contentContext(site, post, data) {
|
|
|
100
100
|
dynamic: renderDynamic,
|
|
101
101
|
parts: async (slug) => (await getTemplates().catch(() => null))?.parts[slug] ?? null,
|
|
102
102
|
region: (name, fallback) => regionOverride(name, fallback, site, data),
|
|
103
|
-
|
|
103
|
+
// Khối mẫu đồng bộ lỗi (CMS lỗi) → ẩn khối đó, không làm sập cả bài
|
|
104
|
+
pattern: (ref) => getPattern(ref).catch((e) => { console.error(`[ecomweb] pattern #${ref}:`, e); return null; }),
|
|
104
105
|
binding: async (source, args, c) => {
|
|
105
106
|
const fn = CORE_BINDING_SOURCES[source] ?? (await getActiveExtensions(site)).map((d) => d.bindingSources?.[source]).find(Boolean);
|
|
106
107
|
// Bài của vòng lặp (query) / bài đang xem / bài của nội dung
|
package/dist/dynamic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment } from "react";
|
|
3
|
-
import { getArchives, getPosts, getTerms } from "./api.js";
|
|
3
|
+
import { getAdjacentPost, getArchives, getPosts, getTerms } from "./api.js";
|
|
4
4
|
import { Link, LoginOutLink, NavToggle } from "./client.js";
|
|
5
5
|
import { Comments, FeaturedImage, LanguageSwitcher, Menu, Pagination, PostDate, SearchForm, TermLinks } from "./components.js";
|
|
6
6
|
import { getT } from "./i18n.js";
|
|
@@ -42,7 +42,7 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
42
42
|
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" && _jsx(NavToggle, { label: t("navigation.menu"), children: menu })] }, key));
|
|
43
43
|
}
|
|
44
44
|
case "search":
|
|
45
|
-
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
|
+
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", buttonIcon: a.buttonStyle === "icon" }) }, key);
|
|
46
46
|
case "languageSwitcher":
|
|
47
47
|
return _jsx(LanguageSwitcher, { className: "ecx-language-switcher", variant: a.display === "dropdown" ? "select" : "list" }, key);
|
|
48
48
|
case "copyright":
|
|
@@ -101,7 +101,7 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
101
101
|
const taxonomy = String(a.taxonomy ?? "category");
|
|
102
102
|
if (!/^[a-z0-9_-]{1,64}$/i.test(taxonomy))
|
|
103
103
|
return null;
|
|
104
|
-
const terms = await getTerms(taxonomy, a.hideEmpty !== false).catch(() => []);
|
|
104
|
+
const terms = await getTerms({ taxonomy, hideEmpty: a.hideEmpty !== false }).catch(() => []);
|
|
105
105
|
if (!terms.length)
|
|
106
106
|
return null;
|
|
107
107
|
const label = (t) => _jsxs(_Fragment, { children: [_jsx(Link, { href: t.link, rel: "tag", children: t.name }), a.showCount === true && _jsxs(_Fragment, { children: [" (", t.count, ")"] })] });
|
|
@@ -186,8 +186,8 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
186
186
|
return null;
|
|
187
187
|
const t = await getT();
|
|
188
188
|
const [prev, next] = await Promise.all([
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
getAdjacentPost(cur, "prev").catch(() => null),
|
|
190
|
+
getAdjacentPost(cur, "next").catch(() => null),
|
|
191
191
|
]);
|
|
192
192
|
if (!prev && !next)
|
|
193
193
|
return null;
|
package/dist/i18n.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ export declare const BUILTIN: Record<string, Record<string, string>>;
|
|
|
3
3
|
export type Translator = ((key: string, vars?: Record<string, string | number>) => string) & {
|
|
4
4
|
locale: string;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Hàm dịch phía server theo ngôn ngữ của request: chữ của theme / plugin (`locales/*.json`), cú pháp ICU — tương đương `__()`.
|
|
8
|
+
* @example const t = await getT(); t("readMore"); t("comments.count", { count: 3 })
|
|
9
|
+
*/
|
|
6
10
|
export declare const getT: () => Promise<Translator>;
|
|
7
11
|
/** Chuỗi đã chọn đúng ngôn ngữ để truyền xuống trình duyệt (<TranslationsProvider>). */
|
|
8
12
|
export interface ClientMessages {
|
package/dist/i18n.js
CHANGED
|
@@ -83,6 +83,10 @@ const getDicts = cache(async () => {
|
|
|
83
83
|
}
|
|
84
84
|
return { site, dicts };
|
|
85
85
|
});
|
|
86
|
+
/**
|
|
87
|
+
* Hàm dịch phía server theo ngôn ngữ của request: chữ của theme / plugin (`locales/*.json`), cú pháp ICU — tương đương `__()`.
|
|
88
|
+
* @example const t = await getT(); t("readMore"); t("comments.count", { count: 3 })
|
|
89
|
+
*/
|
|
86
90
|
export const getT = cache(async () => {
|
|
87
91
|
const { site, dicts } = await getDicts();
|
|
88
92
|
const compiled = new Map();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import "server-only";
|
|
1
2
|
export * from "./types.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export { pluginFetch, cmsFetch, CmsApiError, type FetchOptions, getSite, getPosts, getPostIds, getAdjacentPost, getFacets, getPost, getPostById, getPattern, getTerms, queryTerms, getAuthors, getMedia, getMenu, getMenuById, getWidgets, getComments, requestUnlock, getArchives, getLanguages, type PostQuery, type TaxQueryClause, type MetaQuery, type MetaQueryClause, type ListPage, type FacetValue, type FacetResult, type TermQuery, type AuthorQuery, type MediaQuery, type CommentQuery, } from "./api.js";
|
|
4
|
+
export { formatDate, setting, pageLink, pageLinkWithQuery, cx } from "./utils.js";
|
|
5
|
+
export * from "./conditions.js";
|
|
6
|
+
export { definePlugin, getPlugin, hasPlugin, applyFilters, doAction, BUILTIN_PAGE_TEMPLATES } from "./runtime.js";
|
|
5
7
|
export { PostContent, EditableRegion } from "./content.js";
|
|
6
8
|
export { Img, imageCandidates, type ImgProps } from "./image.js";
|
|
7
9
|
export { Menu, WidgetArea, Slot, SearchForm, Pagination, FeaturedImage, PostDate, TermLinks, Comments, LanguageSwitcher } from "./components.js";
|
|
@@ -9,8 +11,9 @@ export { getT, getClientMessages, BUILTIN as BUILTIN_STRINGS, type Translator, t
|
|
|
9
11
|
export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
|
|
10
12
|
export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, NavToggle, isInternalHref, type LinkProps } from "./client.js";
|
|
11
13
|
export { getPreference } from "./preferences.js";
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
+
export { CONSENT_CATEGORIES, CONSENT_META, type ConsentCategory } from "./consent.js";
|
|
15
|
+
export { consentDefault } from "./consent-server.js";
|
|
16
|
+
export { getCurrentUser, requireUser, userCan, safeRedirect, type CurrentUser } from "./auth.js";
|
|
14
17
|
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";
|
|
15
18
|
export { buildDocumentMetadata } from "./metadata.js";
|
|
16
19
|
/** Lấy giá trị Customizer của theme đang active. */
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
// Entry chính chỉ chạy ở server (Server Component, route, generateMetadata). File "use client" import từ ".../client";
|
|
2
|
+
// import nhầm thì Next báo lỗi lúc build thay vì kéo phần server (cookie, gọi API) vào bundle trình duyệt.
|
|
3
|
+
import "server-only";
|
|
1
4
|
export * from "./types.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
+
export { pluginFetch, cmsFetch, CmsApiError, getSite, getPosts, getPostIds, getAdjacentPost, getFacets, getPost, getPostById, getPattern, getTerms, queryTerms, getAuthors, getMedia, getMenu, getMenuById, getWidgets, getComments, requestUnlock, getArchives, getLanguages, } from "./api.js";
|
|
6
|
+
export { formatDate, setting, pageLink, pageLinkWithQuery, cx } from "./utils.js";
|
|
7
|
+
export * from "./conditions.js";
|
|
8
|
+
export { definePlugin, getPlugin, hasPlugin, applyFilters, doAction, BUILTIN_PAGE_TEMPLATES } from "./runtime.js";
|
|
5
9
|
export { PostContent, EditableRegion } from "./content.js";
|
|
6
10
|
export { Img, imageCandidates } from "./image.js";
|
|
7
11
|
export { Menu, WidgetArea, Slot, SearchForm, Pagination, FeaturedImage, PostDate, TermLinks, Comments, LanguageSwitcher } from "./components.js";
|
|
@@ -9,8 +13,9 @@ export { getT, getClientMessages, BUILTIN as BUILTIN_STRINGS } from "./i18n.js";
|
|
|
9
13
|
export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
|
|
10
14
|
export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, NavToggle, isInternalHref } from "./client.js";
|
|
11
15
|
export { getPreference } from "./preferences.js";
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
16
|
+
export { CONSENT_CATEGORIES, CONSENT_META } from "./consent.js";
|
|
17
|
+
export { consentDefault } from "./consent-server.js";
|
|
18
|
+
export { getCurrentUser, requireUser, userCan, safeRedirect } from "./auth.js";
|
|
14
19
|
export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
|
|
15
20
|
export { buildDocumentMetadata } from "./metadata.js";
|
|
16
21
|
/** Lấy giá trị Customizer của theme đang active. */
|
package/dist/rich.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export interface RenderContext {
|
|
|
30
30
|
dynamic?(node: RenderNode, key: string, ctx: RenderContext, children: (ctx: RenderContext, nodes?: RenderNode[]) => Promise<ReactNode[]>): Promise<ReactNode>;
|
|
31
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
32
|
accordion?: string;
|
|
33
|
+
/** 1.26: thẻ bọc tiêu đề mục accordion (div | h2–h6). */
|
|
34
|
+
accTag?: string;
|
|
33
35
|
/** 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). */
|
|
34
36
|
query?: {
|
|
35
37
|
posts: Post[];
|