@ecomcx/ecomweb-theme-sdk 1.43.0 → 2.1.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 +1570 -0
- package/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/api.d.ts +92 -14
- package/dist/api.js +86 -20
- 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 +77 -5
- package/dist/client.js +145 -14
- package/dist/components.d.ts +23 -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 +49 -24
- package/dist/i18n.d.ts +4 -0
- package/dist/i18n.js +6 -2
- package/dist/index.d.ts +8 -5
- package/dist/index.js +10 -5
- package/dist/query-filters.d.ts +16 -0
- package/dist/query-filters.js +110 -0
- package/dist/rich.d.ts +2 -0
- package/dist/rich.js +71 -29
- 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.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CountdownUnit } from "@ecomcx/ecomweb-content";
|
|
1
2
|
import { Component } from "react";
|
|
2
3
|
import type { Comment } from "./types.js";
|
|
3
4
|
import type { AnchorHTMLAttributes, CSSProperties, ReactNode } from "react";
|
|
@@ -29,6 +30,7 @@ export declare class ExtensionBoundary extends Component<{
|
|
|
29
30
|
componentDidCatch(error: unknown): void;
|
|
30
31
|
render(): import("react").JSX.Element | null;
|
|
31
32
|
}
|
|
33
|
+
/** `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`. */
|
|
32
34
|
export declare function isInternalHref(href: string): boolean;
|
|
33
35
|
export type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> & {
|
|
34
36
|
href: string;
|
|
@@ -43,9 +45,22 @@ export type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> &
|
|
|
43
45
|
/** Khớp cả trang con (vd /category/a/page/2 vẫn active cho /category/a). Mặc định true, trừ trang chủ. */
|
|
44
46
|
matchNested?: boolean;
|
|
45
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* 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.
|
|
50
|
+
* `activeClassName` gắn class khi URL hiện tại khớp (`matchNested`: khớp cả trang con). Prefetch mặc định tắt.
|
|
51
|
+
*/
|
|
46
52
|
export declare function Link({ href, prefetch, activeClassName, matchNested, className, children, ...rest }: LinkProps): import("react").JSX.Element;
|
|
47
53
|
/** Form tìm kiếm (GET) chuyển trang phía client. */
|
|
48
|
-
export declare function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition }: {
|
|
54
|
+
export declare function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition, buttonIcon, scopes, scopeAllLabel, scopeLabel, scopeValue, collapse }: {
|
|
55
|
+
collapse?: "tablet" | "mobile";
|
|
56
|
+
scopes?: Array<{
|
|
57
|
+
value: string;
|
|
58
|
+
label: string;
|
|
59
|
+
}>;
|
|
60
|
+
scopeAllLabel?: string;
|
|
61
|
+
scopeLabel?: string;
|
|
62
|
+
scopeValue?: string;
|
|
63
|
+
buttonIcon?: boolean;
|
|
49
64
|
action: string;
|
|
50
65
|
defaultValue?: string | null;
|
|
51
66
|
placeholder: string;
|
|
@@ -132,23 +147,37 @@ export declare function LanguageSwitcherClient({ languages, current, defaultLoca
|
|
|
132
147
|
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";
|
|
133
148
|
export { safeRedirect, type CurrentUser } from "./auth-shared.js";
|
|
134
149
|
/** 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. */
|
|
135
|
-
export declare function CountdownClient({ target, label, expiredText, units, serverNow }: {
|
|
150
|
+
export declare function CountdownClient({ target, label, expiredText, units, serverNow, attrs }: {
|
|
136
151
|
target: number;
|
|
137
152
|
label?: string;
|
|
138
153
|
expiredText?: string;
|
|
139
|
-
units?: Partial<Record<
|
|
154
|
+
units?: Partial<Record<CountdownUnit, string>>;
|
|
140
155
|
serverNow?: number;
|
|
156
|
+
attrs?: Record<string, unknown>;
|
|
141
157
|
}): import("react").JSX.Element;
|
|
158
|
+
/** 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". */
|
|
159
|
+
export declare function TocSpy(): import("react").JSX.Element;
|
|
142
160
|
/** Nút ☰ của menu trên điện thoại: <details> gốc + Escape đóng menu và trả focus về nút. */
|
|
143
161
|
export declare function NavToggle({ label, children, className }: {
|
|
144
162
|
label: string;
|
|
145
163
|
children: ReactNode;
|
|
146
164
|
className?: string;
|
|
147
165
|
}): import("react").JSX.Element;
|
|
148
|
-
/**
|
|
149
|
-
|
|
166
|
+
/**
|
|
167
|
+
* 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.
|
|
168
|
+
* 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ó);
|
|
169
|
+
* tab có neo → panel mang id = neo, mở thẳng bằng #neo.
|
|
170
|
+
*/
|
|
171
|
+
export declare function TabsClient({ titles, panels, initial, icons, subtitles, anchors, vertical, mobileAccordion, extraClass }: {
|
|
150
172
|
titles: string[];
|
|
151
173
|
panels: ReactNode[];
|
|
174
|
+
initial?: number;
|
|
175
|
+
icons?: Array<string | undefined>;
|
|
176
|
+
subtitles?: Array<string | undefined>;
|
|
177
|
+
anchors?: Array<string | undefined>;
|
|
178
|
+
vertical?: boolean;
|
|
179
|
+
mobileAccordion?: boolean; /** Class đầy đủ của khối (tabsClass): thay cho class tự ghép. */
|
|
180
|
+
extraClass?: string;
|
|
152
181
|
}): import("react").JSX.Element;
|
|
153
182
|
/** 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ủ. */
|
|
154
183
|
export declare function LightboxClient({ src, alt, children }: {
|
|
@@ -179,3 +208,46 @@ export declare function FormBlockClient({ formId, source, successMessage, labels
|
|
|
179
208
|
className?: string;
|
|
180
209
|
children?: ReactNode;
|
|
181
210
|
}): import("react").JSX.Element;
|
|
211
|
+
/** Hàng cuộn ngang có nút trước / sau (Query dạng carousel): cuộn đúng một "trang" mỗi lần bấm, ẩn nút ở hai đầu. Không có JS vẫn vuốt / cuộn được. */
|
|
212
|
+
export declare function ScrollRow({ children, arrows }: {
|
|
213
|
+
children: ReactNode;
|
|
214
|
+
arrows?: boolean;
|
|
215
|
+
}): import("react").JSX.Element;
|
|
216
|
+
/**
|
|
217
|
+
* Menu di động của khối Menu: nút burger mở ngăn trượt từ trái (nền mờ, nút đóng, khoá cuộn trang, Esc / bấm nền / bấm liên kết để đóng,
|
|
218
|
+
* trả focus về nút). Menu con hiện thụt vào ngay dưới mục cha. Khác NavToggle (giữ nguyên cho theme cũ dùng <details>).
|
|
219
|
+
*/
|
|
220
|
+
export declare function NavDrawer({ label, closeLabel, children }: {
|
|
221
|
+
label: string;
|
|
222
|
+
closeLabel: string;
|
|
223
|
+
children: ReactNode;
|
|
224
|
+
}): import("react").JSX.Element;
|
|
225
|
+
/**
|
|
226
|
+
* Thanh lọc của khối Query (GET): ô tìm, mục phân loại (liên kết tới trang mục / nút lọc / ô chọn), sắp xếp.
|
|
227
|
+
* Giá trị lên URL dạng ?fq_s, ?fq_sort, ?fq_<phân loại>; khối Query bật "Nhận bộ lọc từ thanh lọc" đọc lại. Ô chọn tự gửi khi đổi.
|
|
228
|
+
*/
|
|
229
|
+
export declare function QueryFilterBar({ action, taxonomy, termStyle, terms, currentTerm, values, showSearch, showSort, sorts, labels }: {
|
|
230
|
+
action: string;
|
|
231
|
+
taxonomy?: string;
|
|
232
|
+
termStyle: "none" | "links" | "chips" | "select";
|
|
233
|
+
terms: Array<{
|
|
234
|
+
slug: string;
|
|
235
|
+
name: string;
|
|
236
|
+
link: string;
|
|
237
|
+
}>;
|
|
238
|
+
currentTerm?: string;
|
|
239
|
+
values: Record<string, string>;
|
|
240
|
+
showSearch: boolean;
|
|
241
|
+
showSort: boolean;
|
|
242
|
+
sorts: Array<{
|
|
243
|
+
value: string;
|
|
244
|
+
label: string;
|
|
245
|
+
}>;
|
|
246
|
+
labels: {
|
|
247
|
+
all: string;
|
|
248
|
+
search: string;
|
|
249
|
+
placeholder: string;
|
|
250
|
+
submit: string;
|
|
251
|
+
sort: string;
|
|
252
|
+
};
|
|
253
|
+
}): import("react").JSX.Element;
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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
|
-
import { Component, Suspense, useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import { Component, Suspense, useCallback, useEffect, useId, useRef, useState } from "react";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
5
7
|
import { usePathname, useRouter } from "next/navigation";
|
|
6
8
|
import NextLink, { useLinkStatus } from "next/link";
|
|
7
9
|
import NextForm from "next/form";
|
|
@@ -27,6 +29,7 @@ export class ExtensionBoundary extends Component {
|
|
|
27
29
|
// ---------------------------------------------------------------------------
|
|
28
30
|
/** Đườ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
31
|
const NON_PAGE = /^\/(uploads|api|_next|extensions)\/|^\/(feed|sitemap\.xml|robots\.txt)(\?|$)|\.[a-z0-9]{2,5}(\?|$)/i;
|
|
32
|
+
/** `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
33
|
export function isInternalHref(href) {
|
|
31
34
|
return href.startsWith("/") && !href.startsWith("//") && !NON_PAGE.test(href);
|
|
32
35
|
}
|
|
@@ -45,6 +48,10 @@ function PendingSignal() {
|
|
|
45
48
|
}, [pending]);
|
|
46
49
|
return null;
|
|
47
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* 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.
|
|
53
|
+
* `activeClassName` gắn class khi URL hiện tại khớp (`matchNested`: khớp cả trang con). Prefetch mặc định tắt.
|
|
54
|
+
*/
|
|
48
55
|
export function Link({ href, prefetch = false, activeClassName, matchNested = true, className, children, ...rest }) {
|
|
49
56
|
const pathname = usePathname();
|
|
50
57
|
const path = href.split(/[?#]/)[0];
|
|
@@ -60,10 +67,34 @@ export function Link({ href, prefetch = false, activeClassName, matchNested = tr
|
|
|
60
67
|
}, children: [children, _jsx(PendingSignal, {})] }));
|
|
61
68
|
}
|
|
62
69
|
/** 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" }) {
|
|
70
|
+
export function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition = "right", buttonIcon, scopes, scopeAllLabel, scopeLabel, scopeValue, collapse }) {
|
|
64
71
|
const id = useId();
|
|
65
|
-
const button =
|
|
66
|
-
|
|
72
|
+
const button = buttonIcon
|
|
73
|
+
? _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 }) }) })
|
|
74
|
+
: _jsx("button", { type: "submit", children: buttonLabel });
|
|
75
|
+
const form = (_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 }), scopes && scopes.length > 0
|
|
76
|
+
? _jsxs("select", { name: "type", className: "search-scope", "aria-label": scopeLabel, defaultValue: scopeValue ?? "any", children: [_jsx("option", { value: "any", children: scopeAllLabel }), scopes.map((s) => _jsx("option", { value: s.value, children: s.label }, s.value))] })
|
|
77
|
+
: postType && _jsx("input", { type: "hidden", name: "type", value: postType }), buttonPosition !== "left" && button] }));
|
|
78
|
+
if (!collapse)
|
|
79
|
+
return form;
|
|
80
|
+
return _jsx(SearchCollapse, { collapse: collapse, label: buttonLabel, children: form });
|
|
81
|
+
}
|
|
82
|
+
/** Ô tìm kiếm thu thành nút kính lúp ở tablet / điện thoại (CSS quyết định ngưỡng); bấm mở ô nhập thả xuống, Esc hoặc bấm ra ngoài để đóng. */
|
|
83
|
+
function SearchCollapse({ collapse, label, children }) {
|
|
84
|
+
const [open, setOpen] = useState(false);
|
|
85
|
+
const ref = useRef(null);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (!open)
|
|
88
|
+
return;
|
|
89
|
+
const onDown = (e) => { if (ref.current && !ref.current.contains(e.target))
|
|
90
|
+
setOpen(false); };
|
|
91
|
+
const onKey = (e) => { if (e.key === "Escape")
|
|
92
|
+
setOpen(false); };
|
|
93
|
+
document.addEventListener("mousedown", onDown);
|
|
94
|
+
document.addEventListener("keydown", onKey);
|
|
95
|
+
return () => { document.removeEventListener("mousedown", onDown); document.removeEventListener("keydown", onKey); };
|
|
96
|
+
}, [open]);
|
|
97
|
+
return (_jsxs("div", { ref: ref, className: cx("ecx-search-collapse", `collapse-${collapse}`, open && "is-open"), children: [_jsx("button", { type: "button", className: "ecx-search-toggle", "aria-label": label, "aria-expanded": open, onClick: () => setOpen((o) => !o), children: _jsx("svg", { viewBox: "0 0 24 24", width: 20, height: 20, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: SEARCH_ICON_PATH }) }) }), _jsx("div", { className: "ecx-search-panel", children: children })] }));
|
|
67
98
|
}
|
|
68
99
|
/** Ghi tuỳ chọn hiển thị của người đọc (xem getPreference). value = null để xoá. */
|
|
69
100
|
export function setPreference(key, value, maxAgeDays = 365) {
|
|
@@ -219,7 +250,7 @@ export function LanguageSwitcherClient({ languages, current, defaultLocale, labe
|
|
|
219
250
|
export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
|
|
220
251
|
export { safeRedirect } from "./auth-shared.js";
|
|
221
252
|
/** 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 }) {
|
|
253
|
+
export function CountdownClient({ target, label, expiredText, units, serverNow, attrs = {} }) {
|
|
223
254
|
// 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
255
|
const [now, setNow] = useState(() => serverNow ?? Date.now());
|
|
225
256
|
useEffect(() => { setNow(Date.now()); }, []);
|
|
@@ -227,10 +258,33 @@ export function CountdownClient({ target, label, expiredText, units, serverNow }
|
|
|
227
258
|
const left = Math.max(0, target - now);
|
|
228
259
|
if (left === 0 && expiredText)
|
|
229
260
|
return _jsx("div", { className: "ecx-countdown is-expired", children: expiredText });
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
261
|
+
const post = typeof attrs.postText === "string" && attrs.postText ? attrs.postText : null;
|
|
262
|
+
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 })] }));
|
|
263
|
+
}
|
|
264
|
+
/** 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". */
|
|
265
|
+
export function TocSpy() {
|
|
266
|
+
const ref = useRef(null);
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
const nav = ref.current?.closest("nav");
|
|
269
|
+
if (!nav)
|
|
270
|
+
return;
|
|
271
|
+
const links = [...nav.querySelectorAll('a[href^="#"]')];
|
|
272
|
+
const targets = links.map((l) => document.getElementById(decodeURIComponent(l.hash.slice(1))));
|
|
273
|
+
let raf = 0;
|
|
274
|
+
const update = () => {
|
|
275
|
+
raf = 0;
|
|
276
|
+
let cur = -1;
|
|
277
|
+
targets.forEach((t, i) => { if (t && t.getBoundingClientRect().top < 120)
|
|
278
|
+
cur = i; });
|
|
279
|
+
links.forEach((l, i) => (i === cur ? l.setAttribute("aria-current", "location") : l.removeAttribute("aria-current")));
|
|
280
|
+
};
|
|
281
|
+
const onScroll = () => { if (!raf)
|
|
282
|
+
raf = requestAnimationFrame(update); };
|
|
283
|
+
update();
|
|
284
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
285
|
+
return () => { window.removeEventListener("scroll", onScroll); cancelAnimationFrame(raf); };
|
|
286
|
+
}, []);
|
|
287
|
+
return _jsx("span", { ref: ref, hidden: true });
|
|
234
288
|
}
|
|
235
289
|
/** Nút ☰ của menu trên điện thoại: <details> gốc + Escape đóng menu và trả focus về nút. */
|
|
236
290
|
export function NavToggle({ label, children, className = "ecx-navigation-toggle" }) {
|
|
@@ -245,20 +299,34 @@ export function NavToggle({ label, children, className = "ecx-navigation-toggle"
|
|
|
245
299
|
}, []);
|
|
246
300
|
return _jsxs("details", { ref: ref, className: className, children: [_jsx("summary", { "aria-label": label, children: "\u2630" }), children] });
|
|
247
301
|
}
|
|
248
|
-
/**
|
|
249
|
-
|
|
250
|
-
|
|
302
|
+
/**
|
|
303
|
+
* 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.
|
|
304
|
+
* 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ó);
|
|
305
|
+
* tab có neo → panel mang id = neo, mở thẳng bằng #neo.
|
|
306
|
+
*/
|
|
307
|
+
export function TabsClient({ titles, panels, initial = 0, icons, subtitles, anchors, vertical, mobileAccordion, extraClass }) {
|
|
308
|
+
const [active, setActive] = useState(initial < titles.length ? initial : 0);
|
|
251
309
|
const id = useId();
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
if (!anchors?.some(Boolean))
|
|
312
|
+
return;
|
|
313
|
+
const open = () => { const i = anchors.indexOf(decodeURIComponent(location.hash.slice(1))); if (i >= 0)
|
|
314
|
+
setActive(i); };
|
|
315
|
+
open();
|
|
316
|
+
window.addEventListener("hashchange", open);
|
|
317
|
+
return () => window.removeEventListener("hashchange", open);
|
|
318
|
+
}, [anchors]);
|
|
252
319
|
const move = (e, i) => {
|
|
253
320
|
const n = titles.length;
|
|
254
|
-
const
|
|
321
|
+
const fwd = vertical ? "ArrowDown" : "ArrowRight", back = vertical ? "ArrowUp" : "ArrowLeft";
|
|
322
|
+
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
323
|
if (next < 0)
|
|
256
324
|
return;
|
|
257
325
|
e.preventDefault();
|
|
258
326
|
setActive(next);
|
|
259
327
|
document.getElementById(`${id}-t${next}`)?.focus();
|
|
260
328
|
};
|
|
261
|
-
return (_jsxs("div", { className: "ecx-tabs", children: [_jsx("div", { role: "tablist", className: "ecx-tabs-list", children: titles.map((t, i) => (
|
|
329
|
+
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
330
|
}
|
|
263
331
|
/** 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
332
|
export function LightboxClient({ src, alt, children }) {
|
|
@@ -317,6 +385,11 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
|
|
|
317
385
|
return;
|
|
318
386
|
}
|
|
319
387
|
form.reset();
|
|
388
|
+
// 1.26: chuyển trang sau khi gửi (máy chủ chỉ trả đường dẫn trong site hoặc http(s))
|
|
389
|
+
if (typeof json.redirect === "string" && /^(\/(?![\/\\])|https?:\/\/)/.test(json.redirect)) {
|
|
390
|
+
window.location.assign(json.redirect);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
320
393
|
setState({ status: "done", message: json.message || successMessage || "" });
|
|
321
394
|
}
|
|
322
395
|
catch {
|
|
@@ -327,3 +400,61 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
|
|
|
327
400
|
return _jsx("p", { className: "ecx-form-status is-success", role: "status", "data-form-done": formId, children: state.message });
|
|
328
401
|
return (_jsxs("form", { className: cx("ecx-form-blocks", className), onSubmit: submit, noValidate: true, "data-form": formId, children: [children, extraUi, _jsx("p", { className: "ecx-form-hp", "aria-hidden": "true", children: _jsxs("label", { children: ["Website", _jsx("input", { type: "text", name: "_hp", tabIndex: -1, autoComplete: "off" })] }) }), state.status === "error" && _jsx("p", { className: "ecx-form-status is-error", role: "alert", children: state.message }), _jsx("div", { className: "ecx-form-actions", children: _jsx("button", { type: "submit", className: button?.className ?? "ecx-button", style: { border: 0, cursor: "pointer", font: "inherit", ...button?.style }, disabled: state.status === "sending", children: state.status === "sending" ? labels.sending : labels.submit }) })] }));
|
|
329
402
|
}
|
|
403
|
+
/** Hàng cuộn ngang có nút trước / sau (Query dạng carousel): cuộn đúng một "trang" mỗi lần bấm, ẩn nút ở hai đầu. Không có JS vẫn vuốt / cuộn được. */
|
|
404
|
+
export function ScrollRow({ children, arrows = true }) {
|
|
405
|
+
const ref = useRef(null);
|
|
406
|
+
const [edge, setEdge] = useState({ start: true, end: false });
|
|
407
|
+
const update = useCallback(() => {
|
|
408
|
+
const el = ref.current;
|
|
409
|
+
if (el)
|
|
410
|
+
setEdge({ start: el.scrollLeft <= 2, end: el.scrollLeft + el.clientWidth >= el.scrollWidth - 2 });
|
|
411
|
+
}, []);
|
|
412
|
+
useEffect(() => {
|
|
413
|
+
update();
|
|
414
|
+
const el = ref.current;
|
|
415
|
+
if (!el || typeof ResizeObserver === "undefined")
|
|
416
|
+
return;
|
|
417
|
+
const ro = new ResizeObserver(update);
|
|
418
|
+
ro.observe(el);
|
|
419
|
+
return () => ro.disconnect();
|
|
420
|
+
}, [update]);
|
|
421
|
+
const go = (dir) => ref.current?.scrollBy({ left: dir * ref.current.clientWidth, behavior: "smooth" });
|
|
422
|
+
return (_jsxs("div", { className: "ecx-scroller", children: [_jsx("div", { className: "ecx-scroller-track", ref: ref, onScroll: update, tabIndex: 0, children: children }), arrows && !edge.start && _jsx("button", { type: "button", className: "ecx-scroller-arrow is-prev", "aria-label": "\u2190", onClick: () => go(-1), children: _jsx("svg", { viewBox: "0 0 24 24", width: 20, height: 20, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m15 18-6-6 6-6" }) }) }), arrows && !edge.end && _jsx("button", { type: "button", className: "ecx-scroller-arrow is-next", "aria-label": "\u2192", onClick: () => go(1), children: _jsx("svg", { viewBox: "0 0 24 24", width: 20, height: 20, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m9 18 6-6-6-6" }) }) })] }));
|
|
423
|
+
}
|
|
424
|
+
const BURGER = _jsx("svg", { viewBox: "0 0 24 24", width: 24, height: 24, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M4 7h16M4 12h16M4 17h16" }) });
|
|
425
|
+
const CLOSE = _jsx("svg", { viewBox: "0 0 24 24", width: 22, height: 22, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M18 6 6 18M6 6l12 12" }) });
|
|
426
|
+
/**
|
|
427
|
+
* Menu di động của khối Menu: nút burger mở ngăn trượt từ trái (nền mờ, nút đóng, khoá cuộn trang, Esc / bấm nền / bấm liên kết để đóng,
|
|
428
|
+
* trả focus về nút). Menu con hiện thụt vào ngay dưới mục cha. Khác NavToggle (giữ nguyên cho theme cũ dùng <details>).
|
|
429
|
+
*/
|
|
430
|
+
export function NavDrawer({ label, closeLabel, children }) {
|
|
431
|
+
const [open, setOpen] = useState(false);
|
|
432
|
+
const [mounted, setMounted] = useState(false);
|
|
433
|
+
useEffect(() => setMounted(true), []);
|
|
434
|
+
const id = useId();
|
|
435
|
+
const button = useRef(null);
|
|
436
|
+
const close = useCallback(() => { setOpen(false); button.current?.focus(); }, []);
|
|
437
|
+
useEffect(() => {
|
|
438
|
+
if (!open)
|
|
439
|
+
return;
|
|
440
|
+
const prev = document.body.style.overflow;
|
|
441
|
+
document.body.style.overflow = "hidden";
|
|
442
|
+
const onKey = (e) => { if (e.key === "Escape")
|
|
443
|
+
close(); };
|
|
444
|
+
document.addEventListener("keydown", onKey);
|
|
445
|
+
return () => { document.body.style.overflow = prev; document.removeEventListener("keydown", onKey); };
|
|
446
|
+
}, [open, close]);
|
|
447
|
+
return (_jsxs("div", { className: cx("ecx-nav-drawer", open && "is-open"), children: [_jsx("button", { ref: button, type: "button", className: "ecx-nav-burger", "aria-label": label, "aria-expanded": open, "aria-controls": id, onClick: () => setOpen(true), children: BURGER }), mounted && createPortal(_jsxs("div", { className: cx("ecx-nav-drawer", "is-portal", open && "is-open"), children: [_jsx("div", { className: "ecx-nav-backdrop", onClick: close, "aria-hidden": "true" }), _jsxs("div", { id: id, className: "ecx-nav-panel", role: "dialog", "aria-modal": "true", "aria-label": label, "aria-hidden": !open, ...(!open ? { inert: true } : {}), children: [_jsx("button", { type: "button", className: "ecx-nav-close", "aria-label": closeLabel, onClick: close, children: CLOSE }), _jsx("div", { className: "ecx-nav-panel-body", onClick: (e) => { if (e.target.closest("a"))
|
|
448
|
+
setOpen(false); }, children: children })] })] }), document.body)] }));
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Thanh lọc của khối Query (GET): ô tìm, mục phân loại (liên kết tới trang mục / nút lọc / ô chọn), sắp xếp.
|
|
452
|
+
* Giá trị lên URL dạng ?fq_s, ?fq_sort, ?fq_<phân loại>; khối Query bật "Nhận bộ lọc từ thanh lọc" đọc lại. Ô chọn tự gửi khi đổi.
|
|
453
|
+
*/
|
|
454
|
+
export function QueryFilterBar({ action, taxonomy, termStyle, terms, currentTerm, values, showSearch, showSort, sorts, labels }) {
|
|
455
|
+
const formRef = useRef(null);
|
|
456
|
+
const termKey = taxonomy ? `fq_${taxonomy}` : "";
|
|
457
|
+
const picked = termKey ? values[termKey] ?? "" : "";
|
|
458
|
+
const submit = () => formRef.current?.requestSubmit();
|
|
459
|
+
return (_jsxs(NextForm, { ref: formRef, action: action, className: "ecx-query-filter", role: "search", children: [termStyle === "links" && terms.length > 0 && (_jsxs("nav", { className: "ecx-filter-terms", "aria-label": taxonomy, children: [_jsx(NextLink, { href: action, className: !currentTerm ? "is-active" : undefined, "aria-current": !currentTerm ? "true" : undefined, children: labels.all }), terms.map((t) => _jsx(NextLink, { href: t.link, className: t.slug === currentTerm ? "is-active" : undefined, "aria-current": t.slug === currentTerm ? "true" : undefined, children: t.name }, t.slug))] })), termStyle === "chips" && terms.length > 0 && (_jsxs("fieldset", { className: "ecx-filter-terms", children: [_jsx("legend", { className: "ecx-visually-hidden", children: taxonomy }), _jsxs("label", { className: !picked ? "is-active" : undefined, children: [_jsx("input", { type: "radio", name: termKey, value: "", defaultChecked: !picked, onChange: submit }), labels.all] }), terms.map((t) => _jsxs("label", { className: picked === t.slug ? "is-active" : undefined, children: [_jsx("input", { type: "radio", name: termKey, value: t.slug, defaultChecked: picked === t.slug, onChange: submit }), t.name] }, t.slug))] })), termStyle === "select" && terms.length > 0 && (_jsxs("select", { name: termKey, "aria-label": taxonomy, defaultValue: picked, onChange: submit, children: [_jsx("option", { value: "", children: labels.all }), terms.map((t) => _jsx("option", { value: t.slug, children: t.name }, t.slug))] })), showSearch && _jsx("input", { type: "search", name: "fq_s", defaultValue: values.fq_s ?? "", placeholder: labels.placeholder, "aria-label": labels.search }), showSort && sorts.length > 0 && _jsx("select", { name: "fq_sort", "aria-label": labels.sort, defaultValue: values.fq_sort ?? sorts[0].value, onChange: submit, children: sorts.map((s) => _jsx("option", { value: s.value, children: s.label }, s.value)) }), (showSearch || termStyle === "chips") && _jsx("button", { type: "submit", children: labels.submit })] }));
|
|
460
|
+
}
|
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,14 @@ 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, scopes, scopeType, collapse }: {
|
|
28
|
+
collapse?: "tablet" | "mobile";
|
|
29
|
+
scopes?: Array<{
|
|
30
|
+
value: string;
|
|
31
|
+
label: string;
|
|
32
|
+
}>;
|
|
33
|
+
scopeType?: string;
|
|
34
|
+
buttonIcon?: boolean;
|
|
23
35
|
defaultValue?: string | null;
|
|
24
36
|
placeholder?: string;
|
|
25
37
|
buttonLabel?: string;
|
|
@@ -47,6 +59,10 @@ export declare function FeaturedImage({ media, size, className, link, label, siz
|
|
|
47
59
|
sizes?: string;
|
|
48
60
|
priority?: boolean;
|
|
49
61
|
}): import("react").JSX.Element | null;
|
|
62
|
+
/**
|
|
63
|
+
* 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`.
|
|
64
|
+
* Không truyền `site` thì tự đọc cấu hình của website (`getSite()`, có cache).
|
|
65
|
+
*/
|
|
50
66
|
export declare function PostDate({ post, site }: {
|
|
51
67
|
post: Post;
|
|
52
68
|
site?: {
|
|
@@ -54,7 +70,8 @@ export declare function PostDate({ post, site }: {
|
|
|
54
70
|
timezone: string;
|
|
55
71
|
locale?: string;
|
|
56
72
|
};
|
|
57
|
-
}): import("react").JSX.Element
|
|
73
|
+
}): Promise<import("react").JSX.Element>;
|
|
74
|
+
/** 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
75
|
export declare function TermLinks({ terms, separator }: {
|
|
59
76
|
terms?: Array<{
|
|
60
77
|
id: number;
|
|
@@ -63,6 +80,10 @@ export declare function TermLinks({ terms, separator }: {
|
|
|
63
80
|
}>;
|
|
64
81
|
separator?: string;
|
|
65
82
|
}): import("react").JSX.Element | null;
|
|
83
|
+
/**
|
|
84
|
+
* 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`.
|
|
85
|
+
* 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>`.
|
|
86
|
+
*/
|
|
66
87
|
export declare function Comments({ post, title, perPage, order, avatarSize, showDate }: {
|
|
67
88
|
post: Post;
|
|
68
89
|
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, scopes, scopeType, collapse }) {
|
|
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, scopes: scopes, scopeAllLabel: t("search.all"), scopeLabel: t("search.scope"), scopeValue: scopeType, collapse: collapse });
|
|
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 {};
|