@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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const ARCHIVE_KINDS = new Set(["category", "tag", "taxonomy", "author", "date", "archive"]);
|
|
2
|
+
/** Trang chủ của website, dạng bài mới hoặc trang tĩnh — `is_front_page`. */
|
|
3
|
+
export const isFrontPage = (data) => data.kind === "front-page" || (data.kind === "home" && data.templates?.[0] === "front-page");
|
|
4
|
+
/** Danh sách bài của blog — `is_home`: trang chủ dạng bài mới, hoặc trang được chọn làm "Trang bài viết" (Cài đặt › Đọc). */
|
|
5
|
+
export const isHome = (data) => data.kind === "home";
|
|
6
|
+
/** Một bài (không phải trang tĩnh); `type` để kiểm tra loại nội dung, vd `isSingle(data, "product")` — `is_single` / `is_singular($type)`. */
|
|
7
|
+
export const isSingle = (data, type) => data.kind === "single" && (!type || data.post?.type === type);
|
|
8
|
+
/** Trang tĩnh; `slug` để kiểm tra trang cụ thể, vd `isPage(data, "lien-he")` — `is_page`. */
|
|
9
|
+
export const isPage = (data, slug) => (data.kind === "page" || data.kind === "front-page") && (!slug || data.post?.slug === slug);
|
|
10
|
+
/** Bài hoặc trang tĩnh (có `data.post`) — `is_singular`. */
|
|
11
|
+
export const isSingular = (data) => isSingle(data) || isPage(data);
|
|
12
|
+
/** Trang chuyên mục; `slug` để kiểm tra chuyên mục cụ thể — `is_category`. */
|
|
13
|
+
export const isCategory = (data, slug) => data.kind === "category" && (!slug || data.term?.slug === slug);
|
|
14
|
+
/** Trang thẻ; `slug` để kiểm tra thẻ cụ thể — `is_tag`. */
|
|
15
|
+
export const isTag = (data, slug) => data.kind === "tag" && (!slug || data.term?.slug === slug);
|
|
16
|
+
/** Trang của phân loại tuỳ biến; `taxonomy` để kiểm tra phân loại cụ thể — `is_tax`. */
|
|
17
|
+
export const isTax = (data, taxonomy) => data.kind === "taxonomy" && (!taxonomy || data.term?.taxonomy === taxonomy);
|
|
18
|
+
/** Trang tác giả — `is_author`. */
|
|
19
|
+
export const isAuthor = (data) => data.kind === "author";
|
|
20
|
+
/** Trang lưu trữ theo ngày — `is_date`. */
|
|
21
|
+
export const isDate = (data) => data.kind === "date";
|
|
22
|
+
/** Mọi trang lưu trữ: chuyên mục, thẻ, phân loại, tác giả, ngày, lưu trữ theo loại nội dung — `is_archive`. */
|
|
23
|
+
export const isArchive = (data) => ARCHIVE_KINDS.has(data.kind);
|
|
24
|
+
/** Trang kết quả tìm kiếm — `is_search`. */
|
|
25
|
+
export const isSearch = (data) => data.kind === "search";
|
|
26
|
+
/** Trang không tìm thấy — `is_404`. */
|
|
27
|
+
export const is404 = (data) => data.kind === "404";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ConsentCategory } from "./consent.js";
|
|
2
|
+
/**
|
|
3
|
+
* (Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true.
|
|
4
|
+
* Không đọc cookie nên không làm mất cache trang; dùng cho phần không có JS (vd <noscript> của GTM).
|
|
5
|
+
*/
|
|
6
|
+
export declare function consentDefault(category: ConsentCategory): Promise<boolean>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { applyFilters } from "./runtime.js";
|
|
2
|
+
// Tách khỏi consent.ts: file đó dùng chung với client.tsx, còn hàm này cần runtime (server-only).
|
|
3
|
+
/**
|
|
4
|
+
* (Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true.
|
|
5
|
+
* Không đọc cookie nên không làm mất cache trang; dùng cho phần không có JS (vd <noscript> của GTM).
|
|
6
|
+
*/
|
|
7
|
+
export async function consentDefault(category) {
|
|
8
|
+
if (category === "functional")
|
|
9
|
+
return true;
|
|
10
|
+
return (await applyFilters("consent.default", true, { category })) !== false;
|
|
11
|
+
}
|
package/dist/consent.d.ts
CHANGED
|
@@ -22,8 +22,3 @@ export declare function parseConsent(value: string | undefined): ConsentCategory
|
|
|
22
22
|
export declare function serializeConsent(categories: readonly ConsentCategory[]): string;
|
|
23
23
|
/** Quyết định cho một nhóm: khách đã trả lời thì theo câu trả lời, chưa thì theo mặc định của plugin banner. */
|
|
24
24
|
export declare function decideConsent(category: ConsentCategory, choice: ConsentCategory[] | undefined, fallback: boolean): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* (Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true.
|
|
27
|
-
* Không đọc cookie nên không làm mất cache trang; dùng cho phần không có JS (vd <noscript> của GTM).
|
|
28
|
-
*/
|
|
29
|
-
export declare function consentDefault(category: ConsentCategory): Promise<boolean>;
|
package/dist/consent.js
CHANGED
|
@@ -35,14 +35,3 @@ export function decideConsent(category, choice, fallback) {
|
|
|
35
35
|
return true;
|
|
36
36
|
return choice ? choice.includes(category) : fallback;
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* (Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true.
|
|
40
|
-
* Không đọc cookie nên không làm mất cache trang; dùng cho phần không có JS (vd <noscript> của GTM).
|
|
41
|
-
*/
|
|
42
|
-
export async function consentDefault(category) {
|
|
43
|
-
if (category === "functional")
|
|
44
|
-
return true;
|
|
45
|
-
// import động: client.tsx dùng chung file này mà không kéo runtime (server) vào bundle trình duyệt
|
|
46
|
-
const { applyFilters } = await import("./runtime.js");
|
|
47
|
-
return (await applyFilters("consent.default", true, { category })) !== false;
|
|
48
|
-
}
|
package/dist/content.js
CHANGED
|
@@ -100,7 +100,8 @@ export async function contentContext(site, post, data) {
|
|
|
100
100
|
dynamic: renderDynamic,
|
|
101
101
|
parts: async (slug) => (await getTemplates().catch(() => null))?.parts[slug] ?? null,
|
|
102
102
|
region: (name, fallback) => regionOverride(name, fallback, site, data),
|
|
103
|
-
|
|
103
|
+
// Khối mẫu đồng bộ lỗi (CMS lỗi) → ẩn khối đó, không làm sập cả bài
|
|
104
|
+
pattern: (ref) => getPattern(ref).catch((e) => { console.error(`[ecomweb] pattern #${ref}:`, e); return null; }),
|
|
104
105
|
binding: async (source, args, c) => {
|
|
105
106
|
const fn = CORE_BINDING_SOURCES[source] ?? (await getActiveExtensions(site)).map((d) => d.bindingSources?.[source]).find(Boolean);
|
|
106
107
|
// Bài của vòng lặp (query) / bài đang xem / bài của nội dung
|
package/dist/dynamic.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment } from "react";
|
|
3
|
-
import { getArchives, getPosts, getTerms } from "./api.js";
|
|
4
|
-
import { Link, LoginOutLink,
|
|
3
|
+
import { getAdjacentPost, getArchives, getPosts, getTerms } from "./api.js";
|
|
4
|
+
import { Link, LoginOutLink, NavDrawer, QueryFilterBar, ScrollRow } from "./client.js";
|
|
5
|
+
import { buildPostQuery, SORTS } from "./query-filters.js";
|
|
5
6
|
import { Comments, FeaturedImage, LanguageSwitcher, Menu, Pagination, PostDate, SearchForm, TermLinks } from "./components.js";
|
|
6
7
|
import { getT } from "./i18n.js";
|
|
7
8
|
import { applyFilters } from "./runtime.js";
|
|
8
9
|
import { localeHref } from "./locale.js";
|
|
9
10
|
import { renderContent } from "./rich.js";
|
|
10
11
|
import { cx } from "./utils.js";
|
|
12
|
+
import { spacingValue } from "@ecomcx/ecomweb-content";
|
|
11
13
|
const align = (a) => (a.textAlign && a.textAlign !== "left" ? { textAlign: a.textAlign } : undefined);
|
|
12
14
|
const ASPECT = { "16/9": "16 / 9", "4/3": "4 / 3", "1/1": "1 / 1", "3/4": "3 / 4" };
|
|
13
15
|
/**
|
|
@@ -37,12 +39,12 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
37
39
|
const location = String(a.location ?? "primary");
|
|
38
40
|
const menu = _jsx(Menu, { location: location, className: "ecx-navigation-menu" });
|
|
39
41
|
const t = await getT();
|
|
40
|
-
//
|
|
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" && _jsx(
|
|
42
|
+
// overlayMenu never | mobile (≤640px) | tablet (≤1024px) | always; thiếu thì theo `mobile` cũ
|
|
43
|
+
const overlay = ["never", "mobile", "tablet", "always"].includes(a.overlayMenu) ? a.overlayMenu : a.mobile === false ? "never" : "mobile";
|
|
44
|
+
return (_jsxs("div", { className: cx("ecx-navigation", `ecx-navigation-${a.orientation ?? "horizontal"}`, overlay !== "never" && "has-mobile", overlay === "tablet" && "bp-tablet", overlay === "always" && "overlay-always"), children: [overlay !== "always" && _jsx("div", { className: "ecx-navigation-items", children: menu }), overlay !== "never" && _jsx(NavDrawer, { label: t("navigation.menu"), closeLabel: t("navigation.close"), children: menu })] }, key));
|
|
43
45
|
}
|
|
44
46
|
case "search":
|
|
45
|
-
return _jsx("div", { className: "ecx-search", children: _jsx(SearchForm, { defaultValue: ctx.data?.search, placeholder: a.placeholder, buttonLabel: a.buttonText, postType: typeof a.postType === "string" && /^[a-z0-9_-]{1,64}$/i.test(a.postType) ? a.postType : undefined, showLabel: a.showLabel === true, buttonPosition: a.buttonPosition === "left" || a.buttonPosition === "below" ? a.buttonPosition : "right" }) }, key);
|
|
47
|
+
return _jsx("div", { className: "ecx-search", children: _jsx(SearchForm, { defaultValue: ctx.data?.search, placeholder: a.placeholder, buttonLabel: a.buttonText, postType: typeof a.postType === "string" && /^[a-z0-9_-]{1,64}$/i.test(a.postType) ? a.postType : undefined, showLabel: a.showLabel === true, buttonPosition: a.buttonPosition === "left" || a.buttonPosition === "below" ? a.buttonPosition : "right", buttonIcon: a.buttonStyle === "icon", scopes: a.scopeSelect === true ? parseScopes(a.scopes) : undefined, scopeType: ctx.data?.query?.type, collapse: a.collapse === "tablet" || a.collapse === "mobile" ? a.collapse : undefined }) }, key);
|
|
46
48
|
case "languageSwitcher":
|
|
47
49
|
return _jsx(LanguageSwitcher, { className: "ecx-language-switcher", variant: a.display === "dropdown" ? "select" : "list" }, key);
|
|
48
50
|
case "copyright":
|
|
@@ -67,7 +69,7 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
67
69
|
if (!post?.featuredMedia)
|
|
68
70
|
return null;
|
|
69
71
|
const ratio = ASPECT[a.aspect];
|
|
70
|
-
return _jsx("div", { className: "ecx-featured-image", style: ratio ? {
|
|
72
|
+
return _jsx("div", { className: "ecx-featured-image", style: ratio ? { "--ecx-ar": ratio, overflow: "hidden" } : undefined, children: _jsx(FeaturedImage, { media: post.featuredMedia, size: a.size ?? "large", link: a.link ? post.link : undefined, label: post.title }) }, key);
|
|
71
73
|
}
|
|
72
74
|
case "postDate":
|
|
73
75
|
return post ? _jsx("p", { className: "ecx-post-date", style: align(a), children: _jsx(PostDate, { post: a.displayType === "modified" ? { ...post, publishedAt: post.updatedAt } : post, site: site }) }, key) : null;
|
|
@@ -101,7 +103,7 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
101
103
|
const taxonomy = String(a.taxonomy ?? "category");
|
|
102
104
|
if (!/^[a-z0-9_-]{1,64}$/i.test(taxonomy))
|
|
103
105
|
return null;
|
|
104
|
-
const terms = await getTerms(taxonomy, a.hideEmpty !== false).catch(() => []);
|
|
106
|
+
const terms = await getTerms({ taxonomy, hideEmpty: a.hideEmpty !== false }).catch(() => []);
|
|
105
107
|
if (!terms.length)
|
|
106
108
|
return null;
|
|
107
109
|
const label = (t) => _jsxs(_Fragment, { children: [_jsx(Link, { href: t.link, rel: "tag", children: t.name }), a.showCount === true && _jsxs(_Fragment, { children: [" (", t.count, ")"] })] });
|
|
@@ -186,8 +188,8 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
186
188
|
return null;
|
|
187
189
|
const t = await getT();
|
|
188
190
|
const [prev, next] = await Promise.all([
|
|
189
|
-
|
|
190
|
-
|
|
191
|
+
getAdjacentPost(cur, "prev").catch(() => null),
|
|
192
|
+
getAdjacentPost(cur, "next").catch(() => null),
|
|
191
193
|
]);
|
|
192
194
|
if (!prev && !next)
|
|
193
195
|
return null;
|
|
@@ -197,37 +199,51 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
197
199
|
let posts;
|
|
198
200
|
let data;
|
|
199
201
|
let pageParam;
|
|
200
|
-
|
|
202
|
+
const hasUrlFilter = a.urlFilters === true && Object.keys(ctx.data?.query ?? {}).some((k) => k.startsWith("fq_"));
|
|
203
|
+
if (a.inherit !== false && ctx.data?.posts && !hasUrlFilter) {
|
|
201
204
|
posts = ctx.data.posts;
|
|
202
205
|
data = ctx.data;
|
|
203
206
|
}
|
|
204
207
|
else {
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
const res = await getPosts({ page, type: a.postType ?? "post", perPage: a.perPage ?? 10, taxonomy, term: a.category || a.tag || undefined,
|
|
211
|
-
orderBy: a.orderBy ?? "date", order: a.order ?? "desc",
|
|
212
|
-
authorId: typeof a.authorId === "number" ? a.authorId : undefined, search: a.search || undefined, exclude: exclude.length ? exclude : undefined,
|
|
213
|
-
sticky: a.sticky === "only" ? true : a.sticky === "exclude" ? false : undefined, orderByMeta: a.orderByMeta || undefined }).catch(() => null);
|
|
208
|
+
const fromContext = a.inherit !== false && !!ctx.data;
|
|
209
|
+
// paginate: khối nằm trong một trang → phân trang bằng ?qpage=N (không đụng /page/N của chính trang); trang lưu trữ lọc theo URL giữ /page/N
|
|
210
|
+
const paginate = a.paginate === true && !!ctx.data && !fromContext;
|
|
211
|
+
const page = fromContext ? Math.max(1, ctx.data?.page ?? 1) : paginate ? Math.max(1, Math.floor(Number(ctx.data?.query?.qpage)) || 1) : 1;
|
|
212
|
+
const res = await getPosts({ ...buildPostQuery(a, { post: ctx.post ?? ctx.data?.post, data: ctx.data, fromContext }), page }).catch(() => null);
|
|
214
213
|
posts = res?.items ?? [];
|
|
215
|
-
if (paginate && res && ctx.data) {
|
|
214
|
+
if ((paginate || fromContext) && res && ctx.data) {
|
|
216
215
|
data = { ...ctx.data, page: res.page, totalPages: res.totalPages, total: res.total };
|
|
217
|
-
pageParam = "qpage";
|
|
216
|
+
pageParam = fromContext ? undefined : "qpage";
|
|
218
217
|
}
|
|
219
218
|
}
|
|
220
219
|
return _jsx("div", { className: "ecx-query", children: await children({ ...ctx, query: { posts, data, pageParam } }) }, key);
|
|
221
220
|
}
|
|
221
|
+
case "queryFilter": {
|
|
222
|
+
const taxonomy = /^[a-z0-9_-]{1,64}$/i.test(String(a.taxonomy ?? "")) ? String(a.taxonomy) : undefined;
|
|
223
|
+
const style = ["none", "links", "chips", "select"].includes(a.termStyle) ? a.termStyle : "links";
|
|
224
|
+
const [t, terms] = await Promise.all([getT(), taxonomy && style !== "none" ? getTerms({ taxonomy, hideEmpty: true }).catch(() => []) : Promise.resolve([])]);
|
|
225
|
+
const sorts = String(a.sortOptions ?? "date_desc,date_asc,title_asc,title_desc").split(",").map((x) => x.trim()).filter((x) => SORTS[x]);
|
|
226
|
+
return _jsx(QueryFilterBar, { action: String(a.action || ctx.data?.basePath || "/"), taxonomy: taxonomy, termStyle: style, terms: terms.map((x) => ({ slug: x.slug, name: x.name, link: x.link })), currentTerm: ctx.data?.term?.slug, values: ctx.data?.query ?? {}, showSearch: a.showSearch === true, showSort: a.showSort === true, sorts: sorts.map((x) => ({ value: x, label: t(`filter.sort.${x}`) })), labels: { all: String(a.allLabel || t("filter.all")), search: t("search.label"), placeholder: String(a.placeholder || t("filter.search")), submit: String(a.submitText || t("filter.apply")), sort: t("filter.sort") } }, key);
|
|
227
|
+
}
|
|
222
228
|
case "postTemplate": {
|
|
223
229
|
const posts = ctx.query?.posts ?? [];
|
|
224
230
|
if (!posts.length)
|
|
225
231
|
return null;
|
|
226
232
|
const grid = a.layout === "grid";
|
|
233
|
+
const carousel = a.layout === "carousel";
|
|
234
|
+
const per = Math.min(6, Math.max(1, Math.round(Number(a.columns)) || 3));
|
|
235
|
+
const gap = spacingValue(a.gap) ?? "1.5rem";
|
|
227
236
|
// Đúng N cột khi đủ chỗ (như canvas), ít cột hơn khi hẹp (mỗi cột tối thiểu 12rem) — trước đây N chỉ là gợi ý nên 3 cột thành 2
|
|
228
|
-
|
|
237
|
+
// Đặt số cột riêng cho tablet / điện thoại → lưới theo biến CSS (is-responsive); không thì như cũ: tự giảm cột khi hẹp (mỗi cột tối thiểu 12rem)
|
|
238
|
+
const tablet = Math.round(Number(a.columnsTablet)) || 0, mobile = Math.round(Number(a.columnsMobile)) || 0;
|
|
239
|
+
const responsive = grid && (tablet > 0 || mobile > 0);
|
|
240
|
+
const style = responsive ? { "--per": per, "--per-tablet": tablet || Math.min(per, 3), "--per-mobile": mobile || Math.min(per, 2), "--gap": gap }
|
|
241
|
+
: grid ? { display: "grid", gap, gridTemplateColumns: `repeat(auto-fill, minmax(max(12rem, calc((100% - ${per - 1} * ${gap}) / ${per})), 1fr))`, listStyle: "none", padding: 0 }
|
|
242
|
+
: carousel ? { "--per": per, "--per-tablet": Math.min(per, 3), "--per-mobile": Math.min(per, 2), "--gap": gap }
|
|
243
|
+
: { listStyle: "none", padding: 0 };
|
|
229
244
|
const items = await Promise.all(posts.map(async (p) => _jsx("li", { className: "ecx-post", children: await children({ ...ctx, post: p }) }, p.id)));
|
|
230
|
-
|
|
245
|
+
const list = _jsx("ul", { className: cx("ecx-post-template", grid && "is-grid", responsive && "is-responsive", carousel && "is-carousel"), style: style, children: items }, key);
|
|
246
|
+
return carousel ? _jsx(ScrollRow, { arrows: a.arrows !== false, children: list }, key) : list;
|
|
231
247
|
}
|
|
232
248
|
case "pagination":
|
|
233
249
|
return ctx.query?.data ? _jsx(Pagination, { data: ctx.query.data, pageParam: ctx.query.pageParam, type: ["numbers", "prevNext", "both"].includes(a.type) ? a.type : "both", midSize: Math.min(5, Math.max(0, Number.isFinite(Number(a.midSize)) ? Number(a.midSize) : 2)) }, key) : null;
|
|
@@ -253,3 +269,12 @@ export async function renderDynamic(node, key, ctx, children) {
|
|
|
253
269
|
}
|
|
254
270
|
return null;
|
|
255
271
|
}
|
|
272
|
+
/** "product:Sản phẩm, post:Tin tức" → tuỳ chọn của ô chọn phạm vi tìm kiếm (loại không hợp lệ bị bỏ; không ghi nhãn thì lấy chính tên loại). */
|
|
273
|
+
function parseScopes(v) {
|
|
274
|
+
if (typeof v !== "string")
|
|
275
|
+
return [];
|
|
276
|
+
return v.split(",").map((x) => x.trim()).filter(Boolean).slice(0, 10).flatMap((x) => {
|
|
277
|
+
const [value, ...rest] = x.split(":");
|
|
278
|
+
return /^[a-z0-9_-]{1,64}$/i.test(value.trim()) ? [{ value: value.trim(), label: rest.join(":").trim() || value.trim() }] : [];
|
|
279
|
+
});
|
|
280
|
+
}
|
package/dist/i18n.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ export declare const BUILTIN: Record<string, Record<string, string>>;
|
|
|
3
3
|
export type Translator = ((key: string, vars?: Record<string, string | number>) => string) & {
|
|
4
4
|
locale: string;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Hàm dịch phía server theo ngôn ngữ của request: chữ của theme / plugin (`locales/*.json`), cú pháp ICU — tương đương `__()`.
|
|
8
|
+
* @example const t = await getT(); t("readMore"); t("comments.count", { count: 3 })
|
|
9
|
+
*/
|
|
6
10
|
export declare const getT: () => Promise<Translator>;
|
|
7
11
|
/** Chuỗi đã chọn đúng ngôn ngữ để truyền xuống trình duyệt (<TranslationsProvider>). */
|
|
8
12
|
export interface ClientMessages {
|
package/dist/i18n.js
CHANGED
|
@@ -5,7 +5,7 @@ import { formatMessage } from "./i18n-format.js";
|
|
|
5
5
|
/** Chữ mặc định của các component trong SDK (theme có thể ghi đè trong locales/{code}.json). */
|
|
6
6
|
export const BUILTIN = {
|
|
7
7
|
vi: {
|
|
8
|
-
"search.placeholder": "Tìm kiếm…", "search.button": "Tìm", "search.label": "Từ khoá", "navigation.menu": "Menu", "toc.title": "Mục lục", "query.search": "Kết quả tìm kiếm: {q}", "query.category": "Chuyên mục: {name}", "query.tag": "Thẻ: {name}", "query.author": "Tác giả: {name}", "breadcrumbs.home": "Trang chủ", "breadcrumbs.label": "Đường dẫn", "postNav.previous": "Bài trước", "postNav.next": "Bài sau", "postNav.label": "Bài khác",
|
|
8
|
+
"search.placeholder": "Tìm kiếm…", "search.button": "Tìm", "search.label": "Từ khoá", "filter.all": "Tất cả", "filter.search": "Tìm trong danh sách…", "filter.apply": "Lọc", "filter.sort": "Sắp xếp", "filter.sort.date_desc": "Mới nhất", "filter.sort.date_asc": "Cũ nhất", "filter.sort.title_asc": "Tên A → Z", "filter.sort.title_desc": "Tên Z → A", "filter.sort.modified_desc": "Mới cập nhật", "filter.sort.rand": "Ngẫu nhiên", "search.scope": "Phạm vi tìm kiếm", "search.all": "Tất cả", "navigation.menu": "Menu", "navigation.close": "Đóng menu", "toc.title": "Mục lục", "query.search": "Kết quả tìm kiếm: {q}", "query.category": "Chuyên mục: {name}", "query.tag": "Thẻ: {name}", "query.author": "Tác giả: {name}", "breadcrumbs.home": "Trang chủ", "breadcrumbs.label": "Đường dẫn", "postNav.previous": "Bài trước", "postNav.next": "Bài sau", "postNav.label": "Bài khác",
|
|
9
9
|
"post.read_more": "Đọc tiếp", "pagination.prev": "« Trước", "pagination.next": "Sau »", "pagination.label": "Phân trang",
|
|
10
10
|
"comments.title": "Bình luận", "comments.closed": "Bình luận đã đóng.", "countdown.d": "ngày", "countdown.h": "giờ", "countdown.m": "phút", "countdown.s": "giây",
|
|
11
11
|
"comments.form.title": "Để lại bình luận", "comments.form.content": "Bình luận", "comments.form.name": "Tên",
|
|
@@ -31,7 +31,7 @@ export const BUILTIN = {
|
|
|
31
31
|
"styleBook.title": "Mẫu kiểu dáng", "styleBook.h": "Tiêu đề", "styleBook.para": "Đoạn văn mẫu: chữ của bài viết trên website hiển thị như thế này.", "styleBook.bold": "chữ đậm", "styleBook.italic": "chữ nghiêng", "styleBook.link": "liên kết", "styleBook.item": "Mục", "styleBook.quote": "Trích dẫn mẫu: một câu đáng nhớ.", "styleBook.cite": "Tác giả", "styleBook.button": "Nút bấm", "styleBook.callout": "Hộp lưu ý: thông tin cần chú ý.", "styleBook.group": "Nhóm có nền", "styleBook.column": "Cột", "styleBook.details": "Bấm để xem thêm", "styleBook.cover": "Ảnh bìa",
|
|
32
32
|
},
|
|
33
33
|
en: {
|
|
34
|
-
"search.placeholder": "Search…", "search.button": "Search", "search.label": "Keyword", "navigation.menu": "Menu", "toc.title": "Contents", "query.search": "Search results: {q}", "query.category": "Category: {name}", "query.tag": "Tag: {name}", "query.author": "Author: {name}", "breadcrumbs.home": "Home", "breadcrumbs.label": "Breadcrumb", "postNav.previous": "Previous", "postNav.next": "Next", "postNav.label": "More posts",
|
|
34
|
+
"search.placeholder": "Search…", "search.button": "Search", "search.label": "Keyword", "filter.all": "All", "filter.search": "Search this list…", "filter.apply": "Filter", "filter.sort": "Sort by", "filter.sort.date_desc": "Newest", "filter.sort.date_asc": "Oldest", "filter.sort.title_asc": "Name A → Z", "filter.sort.title_desc": "Name Z → A", "filter.sort.modified_desc": "Recently updated", "filter.sort.rand": "Random", "search.scope": "Search in", "search.all": "All", "navigation.menu": "Menu", "navigation.close": "Close menu", "toc.title": "Contents", "query.search": "Search results: {q}", "query.category": "Category: {name}", "query.tag": "Tag: {name}", "query.author": "Author: {name}", "breadcrumbs.home": "Home", "breadcrumbs.label": "Breadcrumb", "postNav.previous": "Previous", "postNav.next": "Next", "postNav.label": "More posts",
|
|
35
35
|
"post.read_more": "Read more", "pagination.prev": "« Previous", "pagination.next": "Next »", "pagination.label": "Pagination",
|
|
36
36
|
"comments.title": "Comments", "comments.closed": "Comments are closed.", "countdown.d": "d", "countdown.h": "h", "countdown.m": "m", "countdown.s": "s",
|
|
37
37
|
"comments.form.title": "Leave a comment", "comments.form.content": "Comment", "comments.form.name": "Name",
|
|
@@ -83,6 +83,10 @@ const getDicts = cache(async () => {
|
|
|
83
83
|
}
|
|
84
84
|
return { site, dicts };
|
|
85
85
|
});
|
|
86
|
+
/**
|
|
87
|
+
* Hàm dịch phía server theo ngôn ngữ của request: chữ của theme / plugin (`locales/*.json`), cú pháp ICU — tương đương `__()`.
|
|
88
|
+
* @example const t = await getT(); t("readMore"); t("comments.count", { count: 3 })
|
|
89
|
+
*/
|
|
86
90
|
export const getT = cache(async () => {
|
|
87
91
|
const { site, dicts } = await getDicts();
|
|
88
92
|
const compiled = new Map();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import "server-only";
|
|
1
2
|
export * from "./types.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export { pluginFetch, cmsFetch, CmsApiError, type FetchOptions, getSite, getPosts, getPostIds, getAdjacentPost, getFacets, getPost, getPostById, getPattern, getTerms, queryTerms, getAuthors, getMedia, getMenu, getMenuById, getWidgets, getComments, requestUnlock, getArchives, getLanguages, type PostQuery, type TaxQueryClause, type MetaQuery, type MetaQueryClause, type ListPage, type FacetValue, type FacetResult, type TermQuery, type AuthorQuery, type MediaQuery, type CommentQuery, } from "./api.js";
|
|
4
|
+
export { formatDate, setting, pageLink, pageLinkWithQuery, cx } from "./utils.js";
|
|
5
|
+
export * from "./conditions.js";
|
|
6
|
+
export { definePlugin, getPlugin, hasPlugin, applyFilters, doAction, BUILTIN_PAGE_TEMPLATES } from "./runtime.js";
|
|
5
7
|
export { PostContent, EditableRegion } from "./content.js";
|
|
6
8
|
export { Img, imageCandidates, type ImgProps } from "./image.js";
|
|
7
9
|
export { Menu, WidgetArea, Slot, SearchForm, Pagination, FeaturedImage, PostDate, TermLinks, Comments, LanguageSwitcher } from "./components.js";
|
|
@@ -9,8 +11,9 @@ export { getT, getClientMessages, BUILTIN as BUILTIN_STRINGS, type Translator, t
|
|
|
9
11
|
export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
|
|
10
12
|
export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, NavToggle, isInternalHref, type LinkProps } from "./client.js";
|
|
11
13
|
export { getPreference } from "./preferences.js";
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
+
export { CONSENT_CATEGORIES, CONSENT_META, type ConsentCategory } from "./consent.js";
|
|
15
|
+
export { consentDefault } from "./consent-server.js";
|
|
16
|
+
export { getCurrentUser, requireUser, userCan, safeRedirect, type CurrentUser } from "./auth.js";
|
|
14
17
|
export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS, type AuthLabels, type AuthPaths, type SignInProvider } from "./auth-forms.js";
|
|
15
18
|
export { buildDocumentMetadata } from "./metadata.js";
|
|
16
19
|
/** Lấy giá trị Customizer của theme đang active. */
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
// Entry chính chỉ chạy ở server (Server Component, route, generateMetadata). File "use client" import từ ".../client";
|
|
2
|
+
// import nhầm thì Next báo lỗi lúc build thay vì kéo phần server (cookie, gọi API) vào bundle trình duyệt.
|
|
3
|
+
import "server-only";
|
|
1
4
|
export * from "./types.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
+
export { pluginFetch, cmsFetch, CmsApiError, getSite, getPosts, getPostIds, getAdjacentPost, getFacets, getPost, getPostById, getPattern, getTerms, queryTerms, getAuthors, getMedia, getMenu, getMenuById, getWidgets, getComments, requestUnlock, getArchives, getLanguages, } from "./api.js";
|
|
6
|
+
export { formatDate, setting, pageLink, pageLinkWithQuery, cx } from "./utils.js";
|
|
7
|
+
export * from "./conditions.js";
|
|
8
|
+
export { definePlugin, getPlugin, hasPlugin, applyFilters, doAction, BUILTIN_PAGE_TEMPLATES } from "./runtime.js";
|
|
5
9
|
export { PostContent, EditableRegion } from "./content.js";
|
|
6
10
|
export { Img, imageCandidates } from "./image.js";
|
|
7
11
|
export { Menu, WidgetArea, Slot, SearchForm, Pagination, FeaturedImage, PostDate, TermLinks, Comments, LanguageSwitcher } from "./components.js";
|
|
@@ -9,8 +13,9 @@ export { getT, getClientMessages, BUILTIN as BUILTIN_STRINGS } from "./i18n.js";
|
|
|
9
13
|
export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
|
|
10
14
|
export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, NavToggle, isInternalHref } from "./client.js";
|
|
11
15
|
export { getPreference } from "./preferences.js";
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
16
|
+
export { CONSENT_CATEGORIES, CONSENT_META } from "./consent.js";
|
|
17
|
+
export { consentDefault } from "./consent-server.js";
|
|
18
|
+
export { getCurrentUser, requireUser, userCan, safeRedirect } from "./auth.js";
|
|
14
19
|
export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
|
|
15
20
|
export { buildDocumentMetadata } from "./metadata.js";
|
|
16
21
|
/** Lấy giá trị Customizer của theme đang active. */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PostQuery } from "./api.js";
|
|
2
|
+
import type { Post, ResolveResult } from "./types.js";
|
|
3
|
+
/** Cách xếp của thanh lọc (?fq_sort=…) → tham số getPosts. */
|
|
4
|
+
export declare const SORTS: Record<string, Pick<PostQuery, "orderBy" | "order">>;
|
|
5
|
+
type Attrs = Record<string, any>;
|
|
6
|
+
/**
|
|
7
|
+
* Thuộc tính khối Query (bộ lọc 1.27) → tham số getPosts. Hàm thuần để thử được; `now` để cố định ngày trong test.
|
|
8
|
+
* `fromContext`: Query "theo trang đang xem" nhưng có nhận bộ lọc URL → lấy loại bài / mục phân loại của trang lưu trữ rồi lọc thêm.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildPostQuery(a: Attrs, env: {
|
|
11
|
+
post?: Post | null;
|
|
12
|
+
data?: ResolveResult | null;
|
|
13
|
+
now?: Date;
|
|
14
|
+
fromContext?: boolean;
|
|
15
|
+
}): PostQuery;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Cách xếp của thanh lọc (?fq_sort=…) → tham số getPosts. */
|
|
2
|
+
export const SORTS = {
|
|
3
|
+
date_desc: { orderBy: "date", order: "desc" }, date_asc: { orderBy: "date", order: "asc" },
|
|
4
|
+
title_asc: { orderBy: "title", order: "asc" }, title_desc: { orderBy: "title", order: "desc" },
|
|
5
|
+
modified_desc: { orderBy: "modified", order: "desc" }, rand: { orderBy: "rand" },
|
|
6
|
+
};
|
|
7
|
+
const SLUG = /^[a-z0-9_-]{1,64}$/i;
|
|
8
|
+
const ids = (v) => String(v ?? "").split(",").map((x) => Number(x.trim())).filter((x) => Number.isInteger(x) && x > 0).slice(0, 100);
|
|
9
|
+
const slugs = (v) => String(v ?? "").split(",").map((x) => x.trim()).filter((x) => SLUG.test(x)).slice(0, 50);
|
|
10
|
+
const scalar = (v) => (v.trim() !== "" && Number.isFinite(Number(v)) ? Number(v) : v === "true" ? true : v === "false" ? false : v);
|
|
11
|
+
/**
|
|
12
|
+
* Thuộc tính khối Query (bộ lọc 1.27) → tham số getPosts. Hàm thuần để thử được; `now` để cố định ngày trong test.
|
|
13
|
+
* `fromContext`: Query "theo trang đang xem" nhưng có nhận bộ lọc URL → lấy loại bài / mục phân loại của trang lưu trữ rồi lọc thêm.
|
|
14
|
+
*/
|
|
15
|
+
export function buildPostQuery(a, env) {
|
|
16
|
+
const data = env.data ?? null, cur = env.post ?? data?.post ?? null;
|
|
17
|
+
const url = a.urlFilters === true ? (data?.query ?? {}) : {};
|
|
18
|
+
const q = { type: env.fromContext ? data?.postType ?? a.postType ?? "post" : a.postType ?? "post", perPage: a.perPage ?? 10, orderBy: a.orderBy ?? "date", order: a.order ?? "desc" };
|
|
19
|
+
const tax = [];
|
|
20
|
+
// Phân loại: ngữ cảnh (trang mục) + ô Phân loại / Mục + category / tag cũ
|
|
21
|
+
if (env.fromContext && data?.term && SLUG.test(data.term.taxonomy))
|
|
22
|
+
tax.push({ taxonomy: data.term.taxonomy, terms: [data.term.slug] });
|
|
23
|
+
const taxonomy = SLUG.test(String(a.taxonomy ?? "")) ? String(a.taxonomy) : undefined;
|
|
24
|
+
const picked = [...slugs(a.terms), ...(a.term && SLUG.test(String(a.term)) ? [String(a.term)] : [])];
|
|
25
|
+
if (taxonomy && picked.length) {
|
|
26
|
+
if (a.termMode === "all")
|
|
27
|
+
for (const t of picked)
|
|
28
|
+
tax.push({ taxonomy, terms: [t] });
|
|
29
|
+
else
|
|
30
|
+
tax.push({ taxonomy, terms: picked, operator: a.termMode === "none" ? "NOT IN" : "IN" });
|
|
31
|
+
}
|
|
32
|
+
if (a.category)
|
|
33
|
+
tax.push({ taxonomy: "category", terms: [String(a.category)] });
|
|
34
|
+
if (a.tag)
|
|
35
|
+
tax.push({ taxonomy: "post_tag", terms: [String(a.tag)] });
|
|
36
|
+
// Nguồn
|
|
37
|
+
if (a.source === "manual") {
|
|
38
|
+
const inc = ids(a.include);
|
|
39
|
+
q.include = inc.length ? inc : [0];
|
|
40
|
+
if (!a.orderBy || a.orderBy === "date") {
|
|
41
|
+
q.orderBy = "include";
|
|
42
|
+
delete q.order;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (a.source === "related" && cur) {
|
|
46
|
+
const tn = taxonomy ?? (cur.type === "post" ? "category" : Object.keys(cur.terms ?? {})[0]);
|
|
47
|
+
const mine = tn ? (cur.terms?.[tn] ?? []).map((t) => t.slug) : [];
|
|
48
|
+
if (tn && mine.length)
|
|
49
|
+
tax.push({ taxonomy: tn, terms: mine });
|
|
50
|
+
q.exclude = [...(q.exclude ?? []), cur.id];
|
|
51
|
+
}
|
|
52
|
+
else if (a.excludeCurrent !== false && cur && (q.type === cur.type || !q.type))
|
|
53
|
+
q.exclude = [...(q.exclude ?? []), cur.id];
|
|
54
|
+
const ex = ids(a.exclude);
|
|
55
|
+
if (ex.length)
|
|
56
|
+
q.exclude = [...(q.exclude ?? []), ...ex];
|
|
57
|
+
// Trường tuỳ biến (một điều kiện)
|
|
58
|
+
if (typeof a.metaKey === "string" && a.metaKey.trim()) {
|
|
59
|
+
const compare = (["=", "!=", ">", ">=", "<", "<=", "LIKE", "EXISTS", "NOT EXISTS"].includes(a.metaCompare) ? a.metaCompare : "=");
|
|
60
|
+
const clause = { key: a.metaKey.trim(), compare };
|
|
61
|
+
if (compare !== "EXISTS" && compare !== "NOT EXISTS")
|
|
62
|
+
clause.value = compare === "LIKE" ? String(a.metaValue ?? "") : scalar(String(a.metaValue ?? ""));
|
|
63
|
+
q.metaQuery = { clauses: [clause] };
|
|
64
|
+
}
|
|
65
|
+
// Ngày
|
|
66
|
+
const days = Number(a.dateRange);
|
|
67
|
+
if (days > 0)
|
|
68
|
+
q.after = new Date((env.now ?? new Date()).getTime() - days * 86_400_000);
|
|
69
|
+
if (a.after)
|
|
70
|
+
q.after = String(a.after);
|
|
71
|
+
if (a.before)
|
|
72
|
+
q.before = String(a.before);
|
|
73
|
+
if (typeof a.parent === "number")
|
|
74
|
+
q.parentId = a.parent;
|
|
75
|
+
if (typeof a.offset === "number" && a.offset > 0)
|
|
76
|
+
q.offset = a.offset;
|
|
77
|
+
if (typeof a.authorId === "number")
|
|
78
|
+
q.authorId = a.authorId;
|
|
79
|
+
if (a.authorCurrent === true && cur?.author?.id)
|
|
80
|
+
q.authorId = cur.author.id;
|
|
81
|
+
if (a.search)
|
|
82
|
+
q.search = String(a.search);
|
|
83
|
+
if (a.sticky === "only")
|
|
84
|
+
q.sticky = true;
|
|
85
|
+
else if (a.sticky === "exclude")
|
|
86
|
+
q.sticky = false;
|
|
87
|
+
if (a.orderByMeta)
|
|
88
|
+
q.orderByMeta = String(a.orderByMeta);
|
|
89
|
+
// Bộ lọc người đọc chọn trên URL (?fq_s, ?fq_sort, ?fq_<phân loại>)
|
|
90
|
+
if (a.urlFilters === true) {
|
|
91
|
+
if (url.fq_s?.trim())
|
|
92
|
+
q.search = url.fq_s.trim().slice(0, 100);
|
|
93
|
+
if (SORTS[url.fq_sort]) {
|
|
94
|
+
delete q.order;
|
|
95
|
+
Object.assign(q, SORTS[url.fq_sort]);
|
|
96
|
+
}
|
|
97
|
+
const tn = taxonomy;
|
|
98
|
+
if (tn && SLUG.test(url[`fq_${tn}`] ?? ""))
|
|
99
|
+
tax.push({ taxonomy: tn, terms: [url[`fq_${tn}`]] });
|
|
100
|
+
}
|
|
101
|
+
if (tax.length)
|
|
102
|
+
q.taxQuery = tax;
|
|
103
|
+
// Mọi ?fq_… còn lại chuyển cho plugin đọc (vd giá, giảm giá, còn hàng của plugin bán hàng)
|
|
104
|
+
if (a.urlFilters === true) {
|
|
105
|
+
const extra = Object.fromEntries(Object.entries(url).filter(([k, v]) => /^fq_[a-z0-9_-]{1,40}$/i.test(k) && typeof v === "string" && v.length <= 100 && k !== "fq_s"));
|
|
106
|
+
if (Object.keys(extra).length)
|
|
107
|
+
q.extra = extra;
|
|
108
|
+
}
|
|
109
|
+
return q;
|
|
110
|
+
}
|
package/dist/rich.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export interface RenderContext {
|
|
|
30
30
|
dynamic?(node: RenderNode, key: string, ctx: RenderContext, children: (ctx: RenderContext, nodes?: RenderNode[]) => Promise<ReactNode[]>): Promise<ReactNode>;
|
|
31
31
|
/** Tên nhóm của khối accordion đang vẽ: các `details` con dùng chung `name` để mở một mục thì mục khác đóng. */
|
|
32
32
|
accordion?: string;
|
|
33
|
+
/** 1.26: thẻ bọc tiêu đề mục accordion (div | h2–h6). */
|
|
34
|
+
accTag?: string;
|
|
33
35
|
/** Bài của vòng lặp `query` gần nhất (+ dữ liệu phân trang khi dùng danh sách của trang). */
|
|
34
36
|
query?: {
|
|
35
37
|
posts: Post[];
|