@ecomcx/ecomweb-theme-sdk 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1,8 +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";
4
- import { extraFields } from "./auth-forms.js";
5
- import { Component, Suspense, useEffect, useId, useRef, useState } from "react";
3
+ import { carouselData, carouselVars, countdownParts, evergreenWindow, nextTarget, SEARCH_ICON_PATH } from "@ecomcx/ecomweb-content";
4
+ import { extraFields, useCurrentUser } from "./auth-forms.js";
5
+ import { Component, Suspense, useCallback, useEffect, useId, useRef, useState } from "react";
6
+ import { createPortal } from "react-dom";
6
7
  import { usePathname, useRouter } from "next/navigation";
7
8
  import NextLink, { useLinkStatus } from "next/link";
8
9
  import NextForm from "next/form";
@@ -66,12 +67,34 @@ export function Link({ href, prefetch = false, activeClassName, matchNested = tr
66
67
  }, children: [children, _jsx(PendingSignal, {})] }));
67
68
  }
68
69
  /** Form tìm kiếm (GET) chuyển trang phía client. */
69
- export function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition = "right", buttonIcon }) {
70
+ export function SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition = "right", buttonIcon, scopes, scopeAllLabel, scopeLabel, scopeValue, collapse }) {
70
71
  const id = useId();
71
72
  const button = buttonIcon
72
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 }) }) })
73
74
  : _jsx("button", { type: "submit", children: buttonLabel });
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] }));
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 })] }));
75
98
  }
76
99
  /** Ghi tuỳ chọn hiển thị của người đọc (xem getPreference). value = null để xoá. */
77
100
  export function setPreference(key, value, maxAgeDays = 365) {
@@ -227,16 +250,50 @@ export function LanguageSwitcherClient({ languages, current, defaultLocale, labe
227
250
  export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
228
251
  export { safeRedirect } from "./auth-shared.js";
229
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. */
230
- export function CountdownClient({ target, label, expiredText, units, serverNow, attrs = {} }) {
253
+ export function CountdownClient({ target, label, expiredText, units, serverNow, rules, storageKey, attrs = {} }) {
231
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)
232
255
  const [now, setNow] = useState(() => serverNow ?? Date.now());
233
- useEffect(() => { setNow(Date.now()); }, []);
234
- useEffect(() => { const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, []);
235
- const left = Math.max(0, target - now);
236
- if (left === 0 && expiredText)
256
+ const [paused, setPaused] = useState(false);
257
+ const [mounted, setMounted] = useState(false);
258
+ // Evergreen: mốc bắt đầu của RIÊNG người xem này nằm trong localStorage (không có thì bắt đầu từ lúc vào trang)
259
+ const [end, setEnd] = useState(null);
260
+ useEffect(() => {
261
+ setNow(Date.now());
262
+ setMounted(true);
263
+ if (rules?.evergreenMs && storageKey) {
264
+ let saved = null;
265
+ try {
266
+ const v = localStorage.getItem(`ecx-cd:${storageKey}`);
267
+ saved = v ? Number(v) : null;
268
+ }
269
+ catch { /* trình duyệt chặn lưu: đếm từ lúc vào trang */ }
270
+ const [start, finish] = evergreenWindow(saved, Date.now(), rules.evergreenMs, rules.evergreenResetDays);
271
+ try {
272
+ if (start !== saved)
273
+ localStorage.setItem(`ecx-cd:${storageKey}`, String(start));
274
+ }
275
+ catch { /* bỏ qua */ }
276
+ setEnd(finish);
277
+ }
278
+ }, [rules?.evergreenMs, rules?.evergreenResetDays, storageKey]);
279
+ useEffect(() => { if (paused)
280
+ return; const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, [paused]);
281
+ const evergreen = !!rules?.evergreenMs;
282
+ const base = evergreen ? (end ?? (serverNow ?? now) + rules.evergreenMs) : target;
283
+ const live = rules && !evergreen ? nextTarget(base, rules.repeat, now) : base;
284
+ const left = Math.max(0, live - now);
285
+ const action = rules?.action ?? (expiredText ? "message" : "zero");
286
+ const expired = left === 0 && mounted;
287
+ const url = rules?.redirectUrl;
288
+ useEffect(() => { if (expired && action === "redirect" && url)
289
+ location.assign(url); }, [expired, action, url]);
290
+ if (left === 0 && action === "hide")
291
+ return null;
292
+ if (left === 0 && action === "message" && expiredText)
237
293
  return _jsx("div", { className: "ecx-countdown is-expired", children: expiredText });
238
294
  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 })] }));
295
+ return (_jsxs("div", { className: cx("ecx-countdown", attrs.layout === "inline" && "is-inline", attrs.divider === true && "has-divider", rules?.pause && "has-pause"), 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 }), rules?.pause && mounted && _jsx("button", { type: "button", className: "ecx-countdown-pause", "aria-pressed": paused, "aria-label": paused ? "▶" : "⏸", onClick: () => { if (paused)
296
+ setNow(Date.now()); setPaused(!paused); }, children: paused ? "▶" : "⏸" })] }));
240
297
  }
241
298
  /** 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
299
  export function TocSpy() {
@@ -303,7 +360,7 @@ export function TabsClient({ titles, panels, initial = 0, icons, subtitles, anch
303
360
  setActive(next);
304
361
  document.getElementById(`${id}-t${next}`)?.focus();
305
362
  };
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))] }));
363
+ 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], _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))] }));
307
364
  }
308
365
  /** 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ủ. */
309
366
  export function LightboxClient({ src, alt, children }) {
@@ -325,6 +382,57 @@ export function LightboxClient({ src, alt, children }) {
325
382
  export function FormBlockClient({ formId, source, successMessage, labels, button, className, children, fields: extraUi }) {
326
383
  const started = useRef(Date.now());
327
384
  const [state, setState] = useState({ status: "idle" });
385
+ const formEl = useRef(null);
386
+ const [step, setStep] = useState(1);
387
+ const [maxStep, setMaxStep] = useState(1);
388
+ // Hiện / ẩn ô theo điều kiện (data-showif) và theo bước (data-step); ô đang ẩn không gửi lên
389
+ const sync = useCallback((cur) => {
390
+ const form = formEl.current;
391
+ if (!form)
392
+ return;
393
+ const value = (name) => {
394
+ const els = Array.from(form.elements).filter((e) => e.name === name);
395
+ if (!els.length)
396
+ return "";
397
+ const first = els[0];
398
+ if (first.type === "checkbox")
399
+ return first.checked ? "1" : "";
400
+ if (first.type === "radio")
401
+ return els.find((r) => r.checked)?.value ?? "";
402
+ return first.value.trim();
403
+ };
404
+ let max = 1;
405
+ form.querySelectorAll("[data-field]").forEach((el) => {
406
+ const s = Number(el.dataset.step) || 1;
407
+ if (s > max)
408
+ max = s;
409
+ let condOff = false;
410
+ const m = /^([a-z][a-z0-9_]*)(!?=)?(.*)$/.exec(el.dataset.showif ?? "");
411
+ if (m) {
412
+ const v = value(m[1]);
413
+ condOff = m[2] === "=" ? v !== m[3] : m[2] === "!=" ? v === m[3] : !v;
414
+ }
415
+ el.hidden = condOff || s !== cur; // ô ở bước khác chỉ ẩn (giữ giá trị); ô bị điều kiện ẩn thì tắt hẳn để không gửi và không bắt buộc
416
+ if (condOff)
417
+ el.dataset.condOff = "1";
418
+ else
419
+ delete el.dataset.condOff;
420
+ el.querySelectorAll("input, textarea, select").forEach((i) => { i.disabled = condOff; });
421
+ });
422
+ setMaxStep((x) => (x === max ? x : max));
423
+ }, []);
424
+ useEffect(() => { sync(step); }, [sync, step, state.status]);
425
+ const goNext = () => {
426
+ const form = formEl.current;
427
+ if (!form)
428
+ return;
429
+ const bad = Array.from(form.querySelectorAll("[data-field]:not([hidden]) input:not([type=hidden]), [data-field]:not([hidden]) textarea, [data-field]:not([hidden]) select")).find((i) => !i.checkValidity());
430
+ if (bad) {
431
+ bad.reportValidity();
432
+ return;
433
+ }
434
+ setStep((s) => Math.min(maxStep, s + 1));
435
+ };
328
436
  function showErrors(form, errors) {
329
437
  form.querySelectorAll("[data-field]").forEach((el) => {
330
438
  const msg = errors[el.dataset.field ?? ""]?.join(" ") ?? "";
@@ -342,11 +450,17 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
342
450
  }
343
451
  async function submit(e) {
344
452
  e.preventDefault();
453
+ if (step < maxStep) {
454
+ goNext();
455
+ return;
456
+ }
345
457
  const form = e.currentTarget;
346
458
  const data = new FormData(form);
347
459
  const fields = {};
348
460
  form.querySelectorAll("[data-field]").forEach((el) => {
349
461
  const name = el.dataset.field;
462
+ if (el.dataset.condOff)
463
+ return; // ô bị điều kiện ẩn không gửi
350
464
  const box = el.querySelector("input[type=checkbox]");
351
465
  fields[name] = box ? box.checked : String(data.get(name) ?? "");
352
466
  });
@@ -375,5 +489,322 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
375
489
  }
376
490
  if (state.status === "done")
377
491
  return _jsx("p", { className: "ecx-form-status is-success", role: "status", "data-form-done": formId, children: state.message });
378
- 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 }) })] }));
492
+ return (_jsxs("form", { ref: formEl, className: cx("ecx-form-blocks", className), onSubmit: submit, onChange: () => sync(step), onInput: () => sync(step), noValidate: true, "data-form": formId, children: [maxStep > 1 && _jsx("p", { className: "ecx-form-step", role: "status", children: (labels.step ?? "{n}/{total}").replace("{n}", String(step)).replace("{total}", String(maxStep)) }), 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 }), _jsxs("div", { className: "ecx-form-actions", children: [step > 1 && _jsx("button", { type: "button", className: "ecx-form-back", onClick: () => setStep((s) => Math.max(1, s - 1)), children: labels.back ?? "←" }), _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 : step < maxStep ? (labels.next ?? "→") : labels.submit })] })] }));
493
+ }
494
+ /**
495
+ * Khối Carousel (slider): track cuộn ngang bám mép slide (vuốt được trên điện thoại, không JS vẫn cuộn), nút trước / sau, chấm theo vị trí,
496
+ * tự chạy tuỳ chọn (dừng khi rê chuột / đang focus / tab ẩn / người dùng tắt hiệu ứng chuyển động, có nút Tạm dừng). Số slide thấy cùng lúc theo khổ máy do CSS (style.css).
497
+ */
498
+ export function CarouselClient({ children, count, config: c, label }) {
499
+ const track = useRef(null);
500
+ const [pos, setPos] = useState({ index: 0, visible: c.per });
501
+ const [held, setHeld] = useState(false);
502
+ const [paused, setPaused] = useState(false);
503
+ const [reduced, setReduced] = useState(true);
504
+ const fade = c.effect === "fade";
505
+ const [ready, setReady] = useState(false);
506
+ const measure = useCallback(() => {
507
+ const el = track.current;
508
+ const first = el?.children[0];
509
+ if (!el || !first || fade)
510
+ return;
511
+ const step = (el.children[1]?.offsetLeft ?? first.offsetLeft + first.offsetWidth) - first.offsetLeft || first.offsetWidth || 1;
512
+ const gap = Math.max(0, step - first.offsetWidth);
513
+ const visible = Math.max(1, Math.min(count, Math.round((el.clientWidth + gap) / step)));
514
+ setPos((p) => { const index = Math.max(0, Math.min(count - visible, Math.round(el.scrollLeft / step))); return p.index === index && p.visible === visible ? p : { index, visible }; });
515
+ }, [count, fade]);
516
+ useEffect(() => {
517
+ setReady(true);
518
+ setReduced(typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches);
519
+ measure();
520
+ const el = track.current;
521
+ if (!el || typeof ResizeObserver === "undefined")
522
+ return;
523
+ const ro = new ResizeObserver(measure);
524
+ ro.observe(el);
525
+ return () => ro.disconnect();
526
+ }, [measure]);
527
+ // Mờ dần: không cuộn — đổi chỉ số, slide đang hiện nhận class is-active (CSS lo phần mờ)
528
+ useEffect(() => {
529
+ if (!fade)
530
+ return;
531
+ Array.from(track.current?.children ?? []).forEach((k, i) => { k.classList.toggle("is-active", i === pos.index); k.classList.toggle("is-off", i !== pos.index); k.setAttribute("aria-hidden", i === pos.index ? "false" : "true"); });
532
+ }, [fade, pos.index, count]);
533
+ const goTo = useCallback((i) => {
534
+ if (fade) {
535
+ setPos((p) => ({ ...p, index: Math.max(0, Math.min(count - 1, i)) }));
536
+ return;
537
+ }
538
+ const el = track.current, kid = el?.children[i];
539
+ if (el && kid)
540
+ el.scrollTo({ left: kid.offsetLeft - el.children[0].offsetLeft, behavior: reduced ? "auto" : "smooth" });
541
+ }, [reduced, fade, count]);
542
+ const last = Math.max(0, count - (fade ? 1 : pos.visible));
543
+ const next = useCallback(() => { if (pos.index >= last) {
544
+ if (c.loop)
545
+ goTo(0);
546
+ }
547
+ else
548
+ goTo(pos.index + 1); }, [pos.index, last, c.loop, goTo]);
549
+ const prev = useCallback(() => { if (pos.index <= 0) {
550
+ if (c.loop)
551
+ goTo(last);
552
+ }
553
+ else
554
+ goTo(pos.index - 1); }, [pos.index, last, c.loop, goTo]);
555
+ const running = c.autoplay && !reduced && !paused && !held && last > 0;
556
+ useEffect(() => {
557
+ if (!running)
558
+ return;
559
+ const t = setInterval(() => { if (document.visibilityState === "visible")
560
+ next(); }, c.interval * 1000);
561
+ return () => clearInterval(t);
562
+ }, [running, next, c.interval]);
563
+ const chevron = (d) => _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: d }) });
564
+ const many = last > 0;
565
+ return (_jsxs("div", { className: "ecx-carousel", role: "region", "aria-roledescription": "carousel", "aria-label": label, style: carouselVars(c), ...carouselData(c), "data-ready": ready ? "" : undefined, onMouseEnter: () => c.hoverPause && setHeld(true), onMouseLeave: () => setHeld(false), onFocus: () => c.hoverPause && setHeld(true), onBlur: () => setHeld(false), children: [_jsx("div", { className: "ecx-carousel-track", ref: track, onScroll: measure, tabIndex: 0, "aria-live": running ? "off" : "polite", onKeyDown: (e) => { if (e.key === "ArrowRight") {
566
+ e.preventDefault();
567
+ next();
568
+ }
569
+ else if (e.key === "ArrowLeft") {
570
+ e.preventDefault();
571
+ prev();
572
+ } }, children: children }), c.arrows && many && _jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "ecx-carousel-arrow is-prev", "aria-label": "\u2190", disabled: !c.loop && pos.index <= 0, onClick: prev, children: chevron("m15 18-6-6 6-6") }), _jsx("button", { type: "button", className: "ecx-carousel-arrow is-next", "aria-label": "\u2192", disabled: !c.loop && pos.index >= last, onClick: next, children: chevron("m9 18 6-6-6-6") })] }), many && (c.dots || c.autoplay) && (_jsxs("div", { className: "ecx-carousel-dots", children: [c.dots && Array.from({ length: last + 1 }, (_, i) => _jsx("button", { type: "button", className: "ecx-carousel-dot", "aria-label": `${i + 1} / ${last + 1}`, "aria-current": i === pos.index ? "true" : undefined, onClick: () => goTo(i) }, i)), c.autoplay && !reduced && _jsx("button", { type: "button", className: "ecx-carousel-pause", "aria-label": paused ? "▶" : "⏸", "aria-pressed": paused, onClick: () => setPaused(!paused), children: paused ? "▶" : "⏸" })] }))] }));
573
+ }
574
+ /**
575
+ * Popup: nút mở + hộp thoại <dialog> gốc của trình duyệt (khoá focus trong hộp, Esc đóng, trả focus về nút) — nội dung nằm sẵn trong HTML.
576
+ * Bấm nền tối để đóng (khi cho phép), khoá cuộn trang khi mở.
577
+ */
578
+ export function PopupClient({ trigger, triggerClass, triggerStyle, className, style, label, closeButton, closeOnOverlay, children, popupId, auto, autoDelay = 5, autoScroll = 50, onceDays = 0 }) {
579
+ const dlg = useRef(null);
580
+ const root = typeof document !== "undefined" ? document.documentElement : null;
581
+ const close = useCallback(() => dlg.current?.close(), []);
582
+ const onClose = useCallback(() => root?.classList.remove("ecx-popup-open"), [root]);
583
+ useEffect(() => () => root?.classList.remove("ecx-popup-open"), [root]);
584
+ const open = useCallback(() => { const d = dlg.current; if (d && !d.open) {
585
+ d.showModal();
586
+ root?.classList.add("ecx-popup-open");
587
+ } }, [root]);
588
+ // Mở bằng liên kết #popup-<id> / phần tử data-popup-open="<id>" ở bất kỳ đâu, và khi địa chỉ trang có #popup-<id>
589
+ useEffect(() => {
590
+ if (!popupId)
591
+ return;
592
+ const hash = `#popup-${popupId}`;
593
+ const onClick = (e) => {
594
+ const el = e.target?.closest?.(`a[href="${hash}"], [data-popup-open="${popupId}"]`);
595
+ if (el) {
596
+ e.preventDefault();
597
+ open();
598
+ }
599
+ };
600
+ document.addEventListener("click", onClick);
601
+ if (location.hash === hash)
602
+ open();
603
+ return () => document.removeEventListener("click", onClick);
604
+ }, [popupId, open]);
605
+ // Tự mở (một lần theo ngày nếu đặt): trễ / cuộn % / thoát trang / không hoạt động
606
+ useEffect(() => {
607
+ if (!auto || auto === "none")
608
+ return;
609
+ const key = popupId ? `ecx-popup:${popupId}` : "";
610
+ if (key && onceDays > 0) {
611
+ try {
612
+ const t = Number(localStorage.getItem(key));
613
+ if (t && Date.now() - t < onceDays * 864e5)
614
+ return;
615
+ }
616
+ catch { /* trình duyệt chặn lưu trữ: coi như chưa hiện */ }
617
+ }
618
+ let done = false;
619
+ const fire = () => { if (done)
620
+ return; done = true; open(); if (key && onceDays > 0) {
621
+ try {
622
+ localStorage.setItem(key, String(Date.now()));
623
+ }
624
+ catch { /* bỏ qua */ }
625
+ } };
626
+ const off = [];
627
+ if (auto === "delay") {
628
+ const t = setTimeout(fire, autoDelay * 1000);
629
+ off.push(() => clearTimeout(t));
630
+ }
631
+ if (auto === "scroll") {
632
+ const on = () => { const h = document.documentElement; const pct = ((h.scrollTop + window.innerHeight) / Math.max(1, h.scrollHeight)) * 100; if (pct >= autoScroll)
633
+ fire(); };
634
+ window.addEventListener("scroll", on, { passive: true });
635
+ on();
636
+ off.push(() => window.removeEventListener("scroll", on));
637
+ }
638
+ if (auto === "exit") {
639
+ const on = (e) => { if (e.clientY <= 0 && !e.relatedTarget)
640
+ fire(); };
641
+ document.addEventListener("mouseout", on);
642
+ off.push(() => document.removeEventListener("mouseout", on));
643
+ }
644
+ if (auto === "idle") {
645
+ let t = setTimeout(fire, autoDelay * 1000);
646
+ const reset = () => { clearTimeout(t); t = setTimeout(fire, autoDelay * 1000); };
647
+ for (const ev of ["mousemove", "keydown", "scroll", "touchstart", "click"])
648
+ window.addEventListener(ev, reset, { passive: true });
649
+ off.push(() => { clearTimeout(t); for (const ev of ["mousemove", "keydown", "scroll", "touchstart", "click"])
650
+ window.removeEventListener(ev, reset); });
651
+ }
652
+ return () => off.forEach((f) => f());
653
+ }, [auto, autoDelay, autoScroll, onceDays, popupId, open]);
654
+ return (_jsxs("div", { className: className, style: style, children: [trigger !== null && trigger !== undefined && trigger !== "" && _jsx("button", { type: "button", className: triggerClass, style: triggerStyle, "aria-haspopup": "dialog", onClick: (e) => { const d = dlg.current; if (d && !d.open) {
655
+ e.currentTarget.focus(); /* Safari không lấy nét nút khi bấm chuột → đóng popup không có chỗ trả focus */
656
+ d.showModal();
657
+ root?.classList.add("ecx-popup-open");
658
+ } }, children: trigger }), _jsxs("dialog", { ref: dlg, id: popupId ? `popup-${popupId}` : undefined, className: "ecx-popup-dialog", "aria-label": label || undefined, onClose: onClose, onClick: (e) => { if (closeOnOverlay && e.target === dlg.current)
659
+ close(); }, children: [closeButton && _jsx("button", { type: "button", className: "ecx-popup-close", "aria-label": "\u00D7", onClick: close, children: _jsx("svg", { viewBox: "0 0 24 24", width: 18, height: 18, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M18 6 6 18M6 6l12 12" }) }) }), _jsx("div", { className: "ecx-popup-body", children: children })] })] }));
660
+ }
661
+ /**
662
+ * Chữ gõ ở cuối Tiêu đề: gõ từng ký tự, dừng, xoá, sang từ kế (lặp hoặc dừng ở từ cuối). HTML dựng sẵn là từ đầu tiên;
663
+ * người xem bật giảm chuyển động thì giữ nguyên từ đầu. Trình đọc màn hình đọc cả nhóm từ một lần (aria-label), không đọc từng ký tự.
664
+ */
665
+ export function TypedText({ words, speed, pause, loop }) {
666
+ const [text, setText] = useState(words[0] ?? "");
667
+ useEffect(() => {
668
+ if (words.length < 2 || (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches))
669
+ return;
670
+ let i = 0, len = words[0].length, deleting = true, stop = false;
671
+ let t = setTimeout(function tick() {
672
+ if (stop)
673
+ return;
674
+ const w = words[i];
675
+ if (deleting) {
676
+ len--;
677
+ setText(w.slice(0, Math.max(0, len)));
678
+ if (len <= 0) {
679
+ deleting = false;
680
+ i = (i + 1) % words.length;
681
+ if (!loop && i === 0) {
682
+ setText(words[words.length - 1]);
683
+ return;
684
+ }
685
+ }
686
+ t = setTimeout(tick, speed / 2);
687
+ }
688
+ else {
689
+ len++;
690
+ setText(words[i].slice(0, len));
691
+ if (len >= words[i].length) {
692
+ deleting = true;
693
+ if (!loop && i === words.length - 1)
694
+ return;
695
+ t = setTimeout(tick, pause);
696
+ return;
697
+ }
698
+ t = setTimeout(tick, speed);
699
+ }
700
+ }, pause);
701
+ return () => { stop = true; clearTimeout(t); };
702
+ }, [words, speed, pause, loop]);
703
+ return _jsx("span", { className: "ecx-typed", "aria-label": words.join(", "), children: _jsx("span", { "aria-hidden": "true", children: text }) });
704
+ }
705
+ /** Video nền (Ảnh bìa): tự phát, tắt tiếng, lặp, không có điều khiển; người xem bật "giảm chuyển động" thì dừng và chỉ hiện ảnh (poster). */
706
+ export function BgVideo({ src, poster, className, style }) {
707
+ const ref = useRef(null);
708
+ useEffect(() => {
709
+ const v = ref.current;
710
+ if (!v || typeof matchMedia !== "function")
711
+ return;
712
+ const mq = matchMedia("(prefers-reduced-motion: reduce)");
713
+ const apply = () => { if (mq.matches)
714
+ v.pause();
715
+ else
716
+ void v.play().catch(() => { }); };
717
+ apply();
718
+ mq.addEventListener?.("change", apply);
719
+ return () => mq.removeEventListener?.("change", apply);
720
+ }, []);
721
+ return _jsx("video", { ref: ref, className: className, style: style, src: src, poster: poster, autoPlay: true, muted: true, loop: true, playsInline: true, preload: "metadata", "aria-hidden": "true", tabIndex: -1 });
722
+ }
723
+ /** 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. */
724
+ export function ScrollRow({ children, arrows = true }) {
725
+ const ref = useRef(null);
726
+ const [edge, setEdge] = useState({ start: true, end: false });
727
+ const update = useCallback(() => {
728
+ const el = ref.current;
729
+ if (el)
730
+ setEdge({ start: el.scrollLeft <= 2, end: el.scrollLeft + el.clientWidth >= el.scrollWidth - 2 });
731
+ }, []);
732
+ useEffect(() => {
733
+ update();
734
+ const el = ref.current;
735
+ if (!el || typeof ResizeObserver === "undefined")
736
+ return;
737
+ const ro = new ResizeObserver(update);
738
+ ro.observe(el);
739
+ return () => ro.disconnect();
740
+ }, [update]);
741
+ const go = (dir) => ref.current?.scrollBy({ left: dir * ref.current.clientWidth, behavior: "smooth" });
742
+ 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" }) }) })] }));
743
+ }
744
+ 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" }) });
745
+ 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" }) });
746
+ /**
747
+ * 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,
748
+ * 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>).
749
+ */
750
+ export function NavDrawer({ label, closeLabel, children }) {
751
+ const [open, setOpen] = useState(false);
752
+ const [mounted, setMounted] = useState(false);
753
+ useEffect(() => setMounted(true), []);
754
+ const id = useId();
755
+ const button = useRef(null);
756
+ const close = useCallback(() => { setOpen(false); button.current?.focus(); }, []);
757
+ useEffect(() => {
758
+ if (!open)
759
+ return;
760
+ const prev = document.body.style.overflow;
761
+ document.body.style.overflow = "hidden";
762
+ const onKey = (e) => { if (e.key === "Escape")
763
+ close(); };
764
+ document.addEventListener("keydown", onKey);
765
+ return () => { document.body.style.overflow = prev; document.removeEventListener("keydown", onKey); };
766
+ }, [open, close]);
767
+ 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"))
768
+ setOpen(false); }, children: children })] })] }), document.body)] }));
769
+ }
770
+ /**
771
+ * 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.
772
+ * 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.
773
+ */
774
+ export function QueryFilterBar({ action, taxonomy, termStyle, terms, currentTerm, values, showSearch, showSort, showYear, showReset, years, sorts, labels, range }) {
775
+ const formRef = useRef(null);
776
+ const termKey = taxonomy ? `fq_${taxonomy}` : "";
777
+ const picked = termKey ? values[termKey] ?? "" : "";
778
+ const submit = () => formRef.current?.requestSubmit();
779
+ // Checkbox nhiều lựa chọn: giữ tập đã chọn, gửi dạng ?fq_<phân loại>=a,b,c
780
+ const [checked, setChecked] = useState(() => picked.split(",").map((x) => x.trim()).filter(Boolean));
781
+ const toggle = (slug) => setChecked((c) => (c.includes(slug) ? c.filter((x) => x !== slug) : [...c, slug]));
782
+ 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 === "checks" && terms.length > 0 && (_jsxs("fieldset", { className: "ecx-filter-terms is-checks", children: [_jsx("legend", { className: "ecx-visually-hidden", children: taxonomy }), terms.map((t) => _jsxs("label", { className: checked.includes(t.slug) ? "is-active" : undefined, children: [_jsx("input", { type: "checkbox", checked: checked.includes(t.slug), onChange: () => { toggle(t.slug); setTimeout(submit, 0); } }), t.name] }, t.slug)), _jsx("input", { type: "hidden", name: termKey, value: checked.join(",") })] })), range && (_jsxs("fieldset", { className: "ecx-filter-range", children: [_jsx("legend", { children: range.label ?? "" }), _jsx("input", { type: "number", inputMode: "numeric", min: 0, max: range.max, name: `fq_${range.param}_min`, defaultValue: values[`fq_${range.param}_min`] ?? "", placeholder: labels.from ?? "Từ", "aria-label": `${range.label ?? range.param}: ${labels.from ?? "Từ"}` }), _jsx("span", { "aria-hidden": "true", children: "\u2013" }), _jsx("input", { type: "number", inputMode: "numeric", min: 0, max: range.max, name: `fq_${range.param}_max`, defaultValue: values[`fq_${range.param}_max`] ?? "", placeholder: labels.to ?? "Đến", "aria-label": `${range.label ?? range.param}: ${labels.to ?? "Đến"}` })] })), 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)) }), showYear && years.length > 0 && _jsxs("select", { name: "fq_year", "aria-label": labels.year, defaultValue: values.fq_year ?? "", onChange: submit, children: [_jsx("option", { value: "", children: labels.year }), years.map((y) => _jsx("option", { value: y, children: y }, y))] }), (showSearch || termStyle === "chips" || !!range) && _jsx("button", { type: "submit", children: labels.submit }), showReset && (Object.keys(values).some((k) => k.startsWith("fq_")) || !!currentTerm) && _jsx(NextLink, { href: action, className: "ecx-filter-reset", children: labels.reset })] }));
783
+ }
784
+ /** Khối theo nhóm người xem: kiểm ở trình duyệt (trang vẫn cache được). Chưa biết người xem → ẩn; khớp nhóm → hiện. */
785
+ export function AudienceGate({ audience, children }) {
786
+ const user = useCurrentUser();
787
+ const show = user !== undefined && (audience === "user") === !!user;
788
+ return _jsx("div", { className: "ecx-aud", "data-aud": audience, hidden: !show, children: children });
789
+ }
790
+ /** Gallery dạng thumbnail slider: ảnh lớn + dải ảnh nhỏ bấm / bàn phím (← → Home End) đổi ảnh lớn. */
791
+ export function GalleryThumbsClient({ mains, thumbs, label }) {
792
+ const [active, setActive] = useState(0);
793
+ const go = (n) => setActive(((n % mains.length) + mains.length) % mains.length);
794
+ return (_jsxs("div", { className: "ecx-gallery-thumbs", "aria-roledescription": "carousel", "aria-label": label, children: [_jsx("div", { className: "ecx-gt-main", role: "tabpanel", "aria-live": "polite", children: mains[active] }), _jsx("div", { className: "ecx-gt-strip", role: "tablist", "aria-label": label, onKeyDown: (e) => { const k = e.key; if (k === "ArrowRight" || k === "ArrowDown") {
795
+ e.preventDefault();
796
+ go(active + 1);
797
+ }
798
+ else if (k === "ArrowLeft" || k === "ArrowUp") {
799
+ e.preventDefault();
800
+ go(active - 1);
801
+ }
802
+ else if (k === "Home") {
803
+ e.preventDefault();
804
+ go(0);
805
+ }
806
+ else if (k === "End") {
807
+ e.preventDefault();
808
+ go(mains.length - 1);
809
+ } }, children: thumbs.map((t, i) => _jsx("button", { type: "button", role: "tab", className: "ecx-gt-thumb", "aria-selected": i === active, tabIndex: i === active ? 0 : -1, "aria-label": `${i + 1} / ${thumbs.length}`, onClick: () => setActive(i), children: t }, i)) })] }));
379
810
  }
@@ -24,7 +24,13 @@ export declare function Slot<P = any>({ name, data, props, fallback, className,
24
24
  className?: string;
25
25
  }): Promise<import("react").JSX.Element>;
26
26
  /** Ô tìm kiếm — gửi về trang chủ của ngôn ngữ hiện tại (/?s= hoặc /en?s=). */
27
- export declare function SearchForm({ defaultValue, placeholder, buttonLabel, postType, showLabel, buttonPosition, buttonIcon }: {
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;
28
34
  buttonIcon?: boolean;
29
35
  defaultValue?: string | null;
30
36
  placeholder?: string;
@@ -104,9 +104,9 @@ export async function Slot({ name, data, props, fallback, className, }) {
104
104
  // Tiện ích hiển thị
105
105
  // ---------------------------------------------------------------------------
106
106
  /** Ô tìm kiếm — gửi về trang chủ của ngôn ngữ hiện tại (/?s= hoặc /en?s=). */
107
- export async function SearchForm({ defaultValue, placeholder, buttonLabel, postType, showLabel, buttonPosition, buttonIcon }) {
107
+ export async function SearchForm({ defaultValue, placeholder, buttonLabel, postType, showLabel, buttonPosition, buttonIcon, scopes, scopeType, collapse }) {
108
108
  const [t, site] = await Promise.all([getT(), getSite()]);
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 });
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 });
110
110
  }
111
111
  function paramLink(data, param, p) {
112
112
  const q = new URLSearchParams(Object.entries(data.query ?? {}).filter(([k]) => k !== param));
package/dist/content.js CHANGED
@@ -1,5 +1,5 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { ExtensionBoundary, Link, PostPasswordForm } from "./client.js";
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { ExtensionBoundary, PostPasswordForm } from "./client.js";
3
3
  import { applyFilters, findBlock, findRegion, findShortcode, getActiveExtensions, getActiveTheme } from "./runtime.js";
4
4
  import { getPattern, getSite, getTemplates } from "./api.js";
5
5
  import { CORE_BINDING_SOURCES } from "./bindings.js";
@@ -20,42 +20,10 @@ export async function PostContent({ post, content, className, page }) {
20
20
  }
21
21
  if (!doc?.blocks?.length)
22
22
  return null;
23
- // Khối pageBreak chia bài thành nhiều trang (?trang=N): chỉ vẽ trang đang xem + thanh chuyển trang
24
- let total = 1;
25
- const current = Math.max(1, Math.floor(Number(page)) || 1);
26
- const rendered = await renderContent(doc, { ...(await contentContext(site, post)), source: post ? `post:${post.id}` : undefined }, async (blocks) => {
27
- const pages = splitPages(await applyFilters("post.blocks", blocks, { site, post }, site));
28
- total = pages.length;
29
- return pages[Math.min(current, total) - 1];
30
- });
31
- const n = Math.min(current, total);
32
- const t = total > 1 ? await getT() : null;
33
- const href = (i) => (post?.link ?? "") + (i > 1 ? `?trang=${i}` : "");
34
- return (_jsxs("div", { className: cx(className ?? "entry-content", "ecx-content"), children: [rendered, t && post && (_jsxs("nav", { className: "ecx-page-links", "aria-label": t("pagination.label"), children: [n > 1 && _jsx(Link, { href: href(n - 1), rel: "prev", children: t("pagination.prev") }), Array.from({ length: total }, (_, i) => i + 1).map((i) => i === n ? _jsx("span", { "aria-current": "page", children: i }, i) : _jsx(Link, { href: href(i), children: i }, i)), n < total && _jsx(Link, { href: href(n + 1), rel: "next", children: t("pagination.next") })] }))] }));
35
- }
36
- /** Cắt khối richtext tại mỗi `pageBreak` cấp cao nhất; khối khác nằm ở trang đang mở. Không có pageBreak → một trang. */
37
- function splitPages(blocks) {
38
- const pages = [[]];
39
- for (const b of blocks) {
40
- const nodes = b.type === "richtext" ? (b.data?.content ?? []) : [];
41
- if (!nodes.some((x) => x.type === "pageBreak")) {
42
- pages[pages.length - 1].push(b);
43
- continue;
44
- }
45
- let seg = [];
46
- const flush = () => { if (seg.length)
47
- pages[pages.length - 1].push({ ...b, data: { ...b.data, content: seg } }); seg = []; };
48
- for (const x of nodes) {
49
- if (x.type === "pageBreak") {
50
- flush();
51
- pages.push([]);
52
- }
53
- else
54
- seg.push(x);
55
- }
56
- flush();
57
- }
58
- return pages.filter((p, i) => p.length || i === 0);
23
+ // 2 (v3): khối "Ngắt trang" đã bỏ — bài luôn hiện trên một trang (`page` giữ lại cho theme cũ, không còn tác dụng)
24
+ void page;
25
+ const rendered = await renderContent(doc, { ...(await contentContext(site, post)), source: post ? `post:${post.id}` : undefined }, async (blocks) => applyFilters("post.blocks", blocks, { site, post }, site));
26
+ return _jsx("div", { className: cx(className ?? "entry-content", "ecx-content"), children: rendered });
59
27
  }
60
28
  /**
61
29
  * Vùng của theme: header, footer (vùng chuẩn của core — nên luôn bọc) và vùng hybrid khai báo ở theme.json › regions.