@ecomcx/ecomweb-theme-sdk 1.38.2 → 1.38.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -118,11 +118,18 @@ export declare function LanguageSwitcherClient({ languages, current, defaultLoca
118
118
  export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS, type AuthLabels, type AuthPaths, type SignInProvider } from "./auth-forms.js";
119
119
  export { safeRedirect, type CurrentUser } from "./auth-shared.js";
120
120
  /** Khối countdown: đếm ngược tới `target` (ms). Dựng lần đầu cùng giá trị trên máy chủ, rồi cập nhật mỗi giây. */
121
- export declare function CountdownClient({ target, label, expiredText, units }: {
121
+ export declare function CountdownClient({ target, label, expiredText, units, serverNow }: {
122
122
  target: number;
123
123
  label?: string;
124
124
  expiredText?: string;
125
125
  units?: Partial<Record<"d" | "h" | "m" | "s", string>>;
126
+ serverNow?: number;
127
+ }): import("react").JSX.Element;
128
+ /** Nút ☰ của menu trên điện thoại: <details> gốc + Escape đóng menu và trả focus về nút. */
129
+ export declare function NavToggle({ label, children, className }: {
130
+ label: string;
131
+ children: ReactNode;
132
+ className?: string;
126
133
  }): import("react").JSX.Element;
127
134
  /** 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. */
128
135
  export declare function TabsClient({ titles, panels }: {
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { extraFields } from "./auth-forms.js";
4
- import { Component, Suspense, useEffect, useId, useState } from "react";
4
+ import { Component, Suspense, useEffect, useId, useRef, useState } from "react";
5
5
  import { usePathname, useRouter } from "next/navigation";
6
6
  import NextLink, { useLinkStatus } from "next/link";
7
7
  import NextForm from "next/form";
@@ -193,8 +193,10 @@ export function LanguageSwitcherClient({ languages, current, defaultLocale, labe
193
193
  export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
194
194
  export { safeRedirect } from "./auth-shared.js";
195
195
  /** Khối countdown: đếm ngược tới `target` (ms). Dựng lần đầu cùng giá trị trên máy chủ, rồi cập nhật mỗi giây. */
196
- export function CountdownClient({ target, label, expiredText, units }) {
197
- const [now, setNow] = useState(() => Date.now());
196
+ export function CountdownClient({ target, label, expiredText, units, serverNow }) {
197
+ // 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)
198
+ const [now, setNow] = useState(() => serverNow ?? Date.now());
199
+ useEffect(() => { setNow(Date.now()); }, []);
198
200
  useEffect(() => { const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, []);
199
201
  const left = Math.max(0, target - now);
200
202
  if (left === 0 && expiredText)
@@ -204,6 +206,19 @@ export function CountdownClient({ target, label, expiredText, units }) {
204
206
  const parts = [["d", Math.floor(s / 86400)], ["h", Math.floor(s / 3600) % 24], ["m", Math.floor(s / 60) % 60], ["s", s % 60]];
205
207
  return (_jsxs("div", { className: "ecx-countdown", role: "timer", "aria-live": "off", suppressHydrationWarning: true, children: [label && _jsx("p", { className: "ecx-countdown-label", children: label }), _jsx("div", { className: "ecx-countdown-parts", children: parts.map(([u, n]) => _jsxs("span", { className: `ecx-countdown-${u}`, children: [_jsx("strong", { children: p(n) }), _jsx("small", { children: units?.[u] ?? u })] }, u)) })] }));
206
208
  }
209
+ /** Nút ☰ của menu trên điện thoại: <details> gốc + Escape đóng menu và trả focus về nút. */
210
+ export function NavToggle({ label, children, className = "ecx-navigation-toggle" }) {
211
+ const ref = useRef(null);
212
+ useEffect(() => {
213
+ const onKey = (e) => { const d = ref.current; if (e.key === "Escape" && d?.open) {
214
+ d.open = false;
215
+ d.querySelector("summary")?.focus();
216
+ } };
217
+ document.addEventListener("keydown", onKey);
218
+ return () => document.removeEventListener("keydown", onKey);
219
+ }, []);
220
+ return _jsxs("details", { ref: ref, className: className, children: [_jsx("summary", { "aria-label": label, children: "\u2630" }), children] });
221
+ }
207
222
  /** 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. */
208
223
  export function TabsClient({ titles, panels }) {
209
224
  const [active, setActive] = useState(0);
package/dist/dynamic.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Fragment } from "react";
3
3
  import { getArchives, getPosts, getTerms } from "./api.js";
4
- import { Link, LoginOutLink } from "./client.js";
4
+ import { Link, LoginOutLink, NavToggle } from "./client.js";
5
5
  import { Comments, FeaturedImage, LanguageSwitcher, Menu, Pagination, PostDate, SearchForm, TermLinks } from "./components.js";
6
6
  import { getT } from "./i18n.js";
7
7
  import { applyFilters } from "./runtime.js";
@@ -39,7 +39,7 @@ export async function renderDynamic(node, key, ctx, children) {
39
39
  const t = await getT();
40
40
  // next: overlayMenu never|mobile|always; thiếu thì theo `mobile` cũ
41
41
  const overlay = ["never", "mobile", "always"].includes(a.overlayMenu) ? a.overlayMenu : a.mobile === false ? "never" : "mobile";
42
- return (_jsxs("div", { className: cx("ecx-navigation", `ecx-navigation-${a.orientation ?? "horizontal"}`, overlay !== "never" && "has-mobile", overlay === "always" && "overlay-always"), children: [overlay !== "always" && _jsx("div", { className: "ecx-navigation-items", children: menu }), overlay !== "never" && _jsxs("details", { className: "ecx-navigation-toggle", children: [_jsx("summary", { "aria-label": t("navigation.menu"), children: "\u2630" }), menu] })] }, key));
42
+ return (_jsxs("div", { className: cx("ecx-navigation", `ecx-navigation-${a.orientation ?? "horizontal"}`, overlay !== "never" && "has-mobile", overlay === "always" && "overlay-always"), children: [overlay !== "always" && _jsx("div", { className: "ecx-navigation-items", children: menu }), overlay !== "never" && _jsx(NavToggle, { label: t("navigation.menu"), children: menu })] }, key));
43
43
  }
44
44
  case "search":
45
45
  return _jsx("div", { className: "ecx-search", children: _jsx(SearchForm, { defaultValue: ctx.data?.search, placeholder: a.placeholder, buttonLabel: a.buttonText, postType: typeof a.postType === "string" && /^[a-z0-9_-]{1,64}$/i.test(a.postType) ? a.postType : undefined, showLabel: a.showLabel === true, buttonPosition: a.buttonPosition === "left" || a.buttonPosition === "below" ? a.buttonPosition : "right" }) }, key);
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { Img, imageCandidates, type ImgProps } from "./image.js";
7
7
  export { Menu, WidgetArea, Slot, SearchForm, Pagination, FeaturedImage, PostDate, TermLinks, Comments, LanguageSwitcher } from "./components.js";
8
8
  export { getT, getClientMessages, BUILTIN as BUILTIN_STRINGS, type Translator, type ClientMessages } from "./i18n.js";
9
9
  export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
10
- export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, isInternalHref, type LinkProps } from "./client.js";
10
+ export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, NavToggle, isInternalHref, type LinkProps } from "./client.js";
11
11
  export { getPreference } from "./preferences.js";
12
12
  export { getCurrentUser, getAccessToken, requireUser, userCan, safeRedirect, ACCESS_COOKIE, REFRESH_COOKIE, type CurrentUser } from "./auth.js";
13
13
  export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS, type AuthLabels, type AuthPaths, type SignInProvider } from "./auth-forms.js";
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ export { Img, imageCandidates } from "./image.js";
7
7
  export { Menu, WidgetArea, Slot, SearchForm, Pagination, FeaturedImage, PostDate, TermLinks, Comments, LanguageSwitcher } from "./components.js";
8
8
  export { getT, getClientMessages, BUILTIN as BUILTIN_STRINGS } from "./i18n.js";
9
9
  export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
10
- export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, isInternalHref } from "./client.js";
10
+ export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, NavToggle, isInternalHref } from "./client.js";
11
11
  export { getPreference } from "./preferences.js";
12
12
  export { getCurrentUser, getAccessToken, requireUser, userCan, safeRedirect, ACCESS_COOKIE, REFRESH_COOKIE } from "./auth.js";
13
13
  export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
package/dist/rich.js CHANGED
@@ -298,7 +298,7 @@ async function renderNodeInner(node, key, ctx) {
298
298
  return a.caption || a.align ? _jsxs("figure", { className: cls, children: [pic, a.caption && _jsx("figcaption", { children: a.caption })] }, key) : _jsx(Fragment, { children: pic }, key);
299
299
  }
300
300
  case "gallery": {
301
- const items = (a.images ?? []);
301
+ const items = (a.images ?? []).filter((im) => !!im?.src); // ảnh chưa chọn (không src) không vẽ <img> hỏng
302
302
  const cols = Math.min(6, Math.max(1, Number(a.columns) || 3));
303
303
  const crop = a.imageCrop !== false; // next: imageCrop=false giữ nguyên tỉ lệ ảnh
304
304
  return (_jsxs("figure", { className: blockShell("gallery", a).className, style: blockShell("gallery", a).style, children: [items.map((im, i) => {
@@ -318,6 +318,8 @@ async function renderNodeInner(node, key, ctx) {
318
318
  case "table": {
319
319
  // Hàng đầu toàn ô tiêu đề → <thead>
320
320
  const rows = await children();
321
+ if (!rows.length)
322
+ return null; // bảng không có hàng nào → không vẽ <table> rỗng
321
323
  const head = node.content?.[0]?.content?.length && node.content[0].content.every((c) => c.type === "tableHeader");
322
324
  // Hàng cuối là chân bảng (attrs.footer) → <tfoot>
323
325
  const foot = a.footer === true && rows.length > (head ? 2 : 1);
@@ -379,7 +381,7 @@ async function renderNodeInner(node, key, ctx) {
379
381
  return null;
380
382
  const t = await getT();
381
383
  const units = { d: t("countdown.d"), h: t("countdown.h"), m: t("countdown.m"), s: t("countdown.s") }; // theo ngôn ngữ của trang (vi: ngày/giờ/phút/giây)
382
- return _jsx(CountdownClient, { target: ms, units: units, label: a.label ? String(a.label) : undefined, expiredText: a.expiredText ? String(a.expiredText) : undefined }, key);
384
+ return _jsx(CountdownClient, { target: ms, serverNow: Date.now(), units: units, label: a.label ? String(a.label) : undefined, expiredText: a.expiredText ? String(a.expiredText) : undefined }, key);
383
385
  }
384
386
  case "rating": {
385
387
  const max = Math.min(10, Math.max(1, Math.round(Number(a.max) || 5)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-theme-sdk",
3
- "version": "1.38.2",
3
+ "version": "1.38.4",
4
4
  "description": "SDK để viết theme và phần frontend của plugin cho Ecomweb",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",