@ecomcx/ecomweb-theme-sdk 1.39.1 → 1.40.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/browser.d.ts +12 -0
- package/dist/browser.js +81 -0
- package/dist/client.d.ts +18 -2
- package/dist/client.js +30 -4
- package/dist/consent.d.ts +29 -0
- package/dist/consent.js +48 -0
- package/dist/content.js +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/page-landing.d.ts +3 -0
- package/dist/page-landing.js +6 -0
- package/dist/rich.d.ts +13 -2
- package/dist/rich.js +41 -12
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +2 -1
- package/dist/types.d.ts +32 -1
- package/package.json +2 -2
package/dist/browser.d.ts
CHANGED
|
@@ -53,4 +53,16 @@ export declare function TranslationsProvider({ value, children }: {
|
|
|
53
53
|
}): import("react").JSX.Element;
|
|
54
54
|
/** Hàm dịch trong component client — cùng cú pháp ICU với `getT`. Khoá không có trong provider → trả lại chính khoá. */
|
|
55
55
|
export declare function useT(): Translator;
|
|
56
|
+
/** Nạp một script của plugin đúng một lần cho cả phiên (thẻ <script> do React chèn khi chuyển trang bằng Link không tự chạy). */
|
|
57
|
+
export declare function AssetScript({ src }: {
|
|
58
|
+
src: string;
|
|
59
|
+
}): null;
|
|
60
|
+
export type BlockReadyFn = (el: HTMLElement, attrs: Record<string, unknown>) => void | (() => void);
|
|
61
|
+
/**
|
|
62
|
+
* Gọi `fn(el, attrs)` cho mỗi khối loại `type` ("*" = mọi khối mà website gắn dấu) đang có / sẽ xuất hiện trên trang (kể cả sau
|
|
63
|
+
* khi chuyển trang bằng Link); hàm dọn trả về được gọi khi khối rời trang. Website chỉ gắn dấu cho loại khối plugin khai ở
|
|
64
|
+
* `definePlugin({ readyBlocks })` — `attrs` gồm các thuộc tính liệt kê ở đó. Trả hàm huỷ đăng ký.
|
|
65
|
+
* onBlockReady("image", (img) => { const z = startZoom(img); return () => z.stop(); });
|
|
66
|
+
*/
|
|
67
|
+
export declare function onBlockReady(type: string, fn: BlockReadyFn): () => void;
|
|
56
68
|
export {};
|
package/dist/browser.js
CHANGED
|
@@ -130,3 +130,84 @@ export function useT() {
|
|
|
130
130
|
return t;
|
|
131
131
|
}, [ctx]);
|
|
132
132
|
}
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// Chỗ cắm cho plugin (core ≥ 1.29): nạp script theo nhu cầu, khối sẵn sàng phía trình duyệt
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
/** Nạp một script của plugin đúng một lần cho cả phiên (thẻ <script> do React chèn khi chuyển trang bằng Link không tự chạy). */
|
|
137
|
+
export function AssetScript({ src }) {
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if ([...document.scripts].some((s) => s.dataset.ecxAsset === src))
|
|
140
|
+
return;
|
|
141
|
+
const s = document.createElement("script");
|
|
142
|
+
s.src = src;
|
|
143
|
+
s.async = true;
|
|
144
|
+
s.dataset.ecxAsset = src;
|
|
145
|
+
document.head.append(s);
|
|
146
|
+
}, [src]);
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const readyFns = new Set();
|
|
150
|
+
const applied = new WeakMap();
|
|
151
|
+
let readyObserver = null;
|
|
152
|
+
const readyEls = (root) => [
|
|
153
|
+
...(root.dataset?.ecxReady ? [root] : []),
|
|
154
|
+
...root.querySelectorAll("[data-ecx-ready]"),
|
|
155
|
+
];
|
|
156
|
+
function attach(el) {
|
|
157
|
+
const type = el.dataset.ecxReady;
|
|
158
|
+
let attrs = {};
|
|
159
|
+
try {
|
|
160
|
+
attrs = JSON.parse(el.dataset.ecxAttrs || "{}");
|
|
161
|
+
}
|
|
162
|
+
catch { /* thuộc tính hỏng: gọi với {} */ }
|
|
163
|
+
const done = applied.get(el) ?? new Map();
|
|
164
|
+
applied.set(el, done);
|
|
165
|
+
for (const r of readyFns) {
|
|
166
|
+
if ((r.type !== "*" && r.type !== type) || done.has(r.fn))
|
|
167
|
+
continue;
|
|
168
|
+
try {
|
|
169
|
+
done.set(r.fn, r.fn(el, attrs));
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
console.warn("[cms] onBlockReady", type, e);
|
|
173
|
+
done.set(r.fn, undefined);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function detach(el) {
|
|
178
|
+
applied.get(el)?.forEach((cleanup) => { try {
|
|
179
|
+
cleanup?.();
|
|
180
|
+
}
|
|
181
|
+
catch { /* bỏ qua */ } });
|
|
182
|
+
applied.delete(el);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Gọi `fn(el, attrs)` cho mỗi khối loại `type` ("*" = mọi khối mà website gắn dấu) đang có / sẽ xuất hiện trên trang (kể cả sau
|
|
186
|
+
* khi chuyển trang bằng Link); hàm dọn trả về được gọi khi khối rời trang. Website chỉ gắn dấu cho loại khối plugin khai ở
|
|
187
|
+
* `definePlugin({ readyBlocks })` — `attrs` gồm các thuộc tính liệt kê ở đó. Trả hàm huỷ đăng ký.
|
|
188
|
+
* onBlockReady("image", (img) => { const z = startZoom(img); return () => z.stop(); });
|
|
189
|
+
*/
|
|
190
|
+
export function onBlockReady(type, fn) {
|
|
191
|
+
const entry = { type, fn };
|
|
192
|
+
readyFns.add(entry);
|
|
193
|
+
if (typeof document === "undefined")
|
|
194
|
+
return () => { readyFns.delete(entry); };
|
|
195
|
+
readyEls(document).forEach(attach);
|
|
196
|
+
readyObserver ??= new MutationObserver((ms) => {
|
|
197
|
+
for (const m of ms) {
|
|
198
|
+
m.removedNodes.forEach((n) => { if (n.nodeType === 1)
|
|
199
|
+
readyEls(n).forEach((el) => { if (!el.isConnected)
|
|
200
|
+
detach(el); }); });
|
|
201
|
+
m.addedNodes.forEach((n) => { if (n.nodeType === 1)
|
|
202
|
+
readyEls(n).forEach(attach); });
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
readyObserver.observe(document.body, { childList: true, subtree: true });
|
|
206
|
+
return () => {
|
|
207
|
+
readyFns.delete(entry);
|
|
208
|
+
readyEls(document).forEach((el) => { const c = applied.get(el)?.get(fn); try {
|
|
209
|
+
c?.();
|
|
210
|
+
}
|
|
211
|
+
catch { /* bỏ qua */ } applied.get(el)?.delete(fn); });
|
|
212
|
+
};
|
|
213
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { Component } from "react";
|
|
2
2
|
import type { Comment } from "./types.js";
|
|
3
3
|
import type { AnchorHTMLAttributes, CSSProperties, ReactNode } from "react";
|
|
4
|
-
|
|
4
|
+
import { type ConsentCategory } from "./consent.js";
|
|
5
|
+
export { pluginClient, PluginApiError, emit, on, useEvent, TranslationsProvider, useT, onBlockReady, type BlockReadyFn, type PluginClient, type PluginRequestOptions } from "./browser.js";
|
|
5
6
|
/**
|
|
6
7
|
* Bảng tên sự kiện phía trình duyệt → dữ liệu (emit / on / useEvent, core ≥ 1.20.0). Theme / plugin khai báo kiểu cho sự kiện của mình:
|
|
7
8
|
* declare module "@ecomcx/ecomweb-theme-sdk/client" { interface BrowserEvents { "shop.cart.changed": { count: number } } }
|
|
8
9
|
* Tên nên có tiền tố slug plugin (như hook backend).
|
|
9
10
|
*/
|
|
10
11
|
export interface BrowserEvents {
|
|
12
|
+
/** Khách vừa đổi lựa chọn cookie (setConsent). */
|
|
13
|
+
"consent.changed": {
|
|
14
|
+
categories: ConsentCategory[];
|
|
15
|
+
};
|
|
11
16
|
}
|
|
12
17
|
export declare class ExtensionBoundary extends Component<{
|
|
13
18
|
name: string;
|
|
@@ -52,6 +57,15 @@ export declare function SearchFormClient({ action, defaultValue, placeholder, la
|
|
|
52
57
|
}): import("react").JSX.Element;
|
|
53
58
|
/** Ghi tuỳ chọn hiển thị của người đọc (xem getPreference). value = null để xoá. */
|
|
54
59
|
export declare function setPreference(key: string, value: string | null, maxAgeDays?: number): void;
|
|
60
|
+
/** Lựa chọn cookie của khách (xem consent.ts); undefined = chưa trả lời. "functional" luôn có. Chỉ chạy ở trình duyệt. */
|
|
61
|
+
export declare function getConsent(): ConsentCategory[] | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Khách đã cho phép nhóm cookie này chưa (gọi trong useEffect / handler — không gọi lúc render để HTML giống nhau cho mọi khách).
|
|
64
|
+
* Chưa chọn: theo <meta name="cms-consent" content="optin"> của plugin banner; không có banner → true.
|
|
65
|
+
*/
|
|
66
|
+
export declare function hasConsent(category: ConsentCategory): boolean;
|
|
67
|
+
/** Plugin banner ghi lựa chọn của khách rồi phát "consent.changed" (cả tab khác) để bên hỏi nạp / báo lại script ngay. */
|
|
68
|
+
export declare function setConsent(categories: readonly ConsentCategory[]): void;
|
|
55
69
|
/** Client phía trình duyệt: gọi các route proxy /api/cms/* của frontend. */
|
|
56
70
|
declare const browserApi: import("next-fetch-kit").FetchKitInstance;
|
|
57
71
|
/** Form gửi bình luận. Gửi qua route /api/cms/comments của frontend (proxy sang CMS API). */
|
|
@@ -146,7 +160,7 @@ export declare function LightboxClient({ src, alt, children }: {
|
|
|
146
160
|
* Khối form cơ bản của lõi (1.39): các ô đã vẽ sẵn ở máy chủ (children), phần này gửi bài qua /api/cms/forms, báo lỗi đúng ô (422),
|
|
147
161
|
* hiện lời cảm ơn. Chống spam: ô bẫy ẩn (_hp) + thời gian điền (máy chủ kiểm), máy chủ còn giới hạn theo IP.
|
|
148
162
|
*/
|
|
149
|
-
export declare function FormBlockClient({ formId, source, successMessage, labels, button, className, children }: {
|
|
163
|
+
export declare function FormBlockClient({ formId, source, successMessage, labels, button, className, children, fields: extraUi }: {
|
|
150
164
|
formId: string;
|
|
151
165
|
source: string;
|
|
152
166
|
successMessage?: string;
|
|
@@ -155,6 +169,8 @@ export declare function FormBlockClient({ formId, source, successMessage, labels
|
|
|
155
169
|
sending: string;
|
|
156
170
|
error: string;
|
|
157
171
|
};
|
|
172
|
+
/** Ô thêm của plugin (captcha…): <Slot name="form.fields" />. Ô name="extra.*" gửi kèm trong "extra" (hook form.submitting). */
|
|
173
|
+
fields?: ReactNode;
|
|
158
174
|
/** Vỏ nút gửi = nút "primary" của nội dung (cùng màu / bo góc với nút của theme). */
|
|
159
175
|
button?: {
|
|
160
176
|
className?: string;
|
package/dist/client.js
CHANGED
|
@@ -7,7 +7,9 @@ import NextLink, { useLinkStatus } from "next/link";
|
|
|
7
7
|
import NextForm from "next/form";
|
|
8
8
|
import { cx, formatDate } from "./utils.js";
|
|
9
9
|
import { createFetchKit, isFetchKitError } from "next-fetch-kit";
|
|
10
|
-
|
|
10
|
+
import { emit } from "./browser.js";
|
|
11
|
+
import { CONSENT_META, CONSENT_PREF, decideConsent, parseConsent, serializeConsent } from "./consent.js";
|
|
12
|
+
export { pluginClient, PluginApiError, emit, on, useEvent, TranslationsProvider, useT, onBlockReady } from "./browser.js";
|
|
11
13
|
// ---------------------------------------------------------------------------
|
|
12
14
|
// Cô lập lỗi của plugin/theme: phần nào ném lỗi khi hiển thị thì ẩn phần đó, trang vẫn hiện bình thường
|
|
13
15
|
// ---------------------------------------------------------------------------
|
|
@@ -69,6 +71,30 @@ export function setPreference(key, value, maxAgeDays = 365) {
|
|
|
69
71
|
throw new Error("Tuỳ chọn không hợp lệ");
|
|
70
72
|
document.cookie = `cms-pref-${key}=${value ?? ""}; path=/; max-age=${value === null ? 0 : maxAgeDays * 86400}; samesite=lax`;
|
|
71
73
|
}
|
|
74
|
+
/** Lựa chọn cookie của khách (xem consent.ts); undefined = chưa trả lời. "functional" luôn có. Chỉ chạy ở trình duyệt. */
|
|
75
|
+
export function getConsent() {
|
|
76
|
+
if (typeof document === "undefined")
|
|
77
|
+
return undefined;
|
|
78
|
+
const raw = document.cookie.split("; ").find((c) => c.startsWith(`cms-pref-${CONSENT_PREF}=`))?.split("=")[1];
|
|
79
|
+
const choice = parseConsent(raw);
|
|
80
|
+
return choice && ["functional", ...choice];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Khách đã cho phép nhóm cookie này chưa (gọi trong useEffect / handler — không gọi lúc render để HTML giống nhau cho mọi khách).
|
|
84
|
+
* Chưa chọn: theo <meta name="cms-consent" content="optin"> của plugin banner; không có banner → true.
|
|
85
|
+
*/
|
|
86
|
+
export function hasConsent(category) {
|
|
87
|
+
if (typeof document === "undefined")
|
|
88
|
+
return false;
|
|
89
|
+
const optIn = document.querySelector(`meta[name="${CONSENT_META}"]`)?.content === "optin";
|
|
90
|
+
const choice = getConsent();
|
|
91
|
+
return decideConsent(category, choice, !optIn);
|
|
92
|
+
}
|
|
93
|
+
/** Plugin banner ghi lựa chọn của khách rồi phát "consent.changed" (cả tab khác) để bên hỏi nạp / báo lại script ngay. */
|
|
94
|
+
export function setConsent(categories) {
|
|
95
|
+
setPreference(CONSENT_PREF, serializeConsent(categories));
|
|
96
|
+
emit("consent.changed", { categories: getConsent() ?? ["functional"] }, { crossTab: true });
|
|
97
|
+
}
|
|
72
98
|
/** Client phía trình duyệt: gọi các route proxy /api/cms/* của frontend. */
|
|
73
99
|
const browserApi = createFetchKit({ baseURL: "/api/cms", timeout: 15_000 });
|
|
74
100
|
function errorMessage(e, fallback) {
|
|
@@ -251,7 +277,7 @@ export function LightboxClient({ src, alt, children }) {
|
|
|
251
277
|
* Khối form cơ bản của lõi (1.39): các ô đã vẽ sẵn ở máy chủ (children), phần này gửi bài qua /api/cms/forms, báo lỗi đúng ô (422),
|
|
252
278
|
* hiện lời cảm ơn. Chống spam: ô bẫy ẩn (_hp) + thời gian điền (máy chủ kiểm), máy chủ còn giới hạn theo IP.
|
|
253
279
|
*/
|
|
254
|
-
export function FormBlockClient({ formId, source, successMessage, labels, button, className, children }) {
|
|
280
|
+
export function FormBlockClient({ formId, source, successMessage, labels, button, className, children, fields: extraUi }) {
|
|
255
281
|
const started = useRef(Date.now());
|
|
256
282
|
const [state, setState] = useState({ status: "idle" });
|
|
257
283
|
function showErrors(form, errors) {
|
|
@@ -283,7 +309,7 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
|
|
|
283
309
|
showErrors(form, {});
|
|
284
310
|
try {
|
|
285
311
|
const res = await fetch("/api/cms/forms", { method: "POST", headers: { "content-type": "application/json" },
|
|
286
|
-
body: JSON.stringify({ formId, source, fields, hp: String(data.get("_hp") ?? ""), ms: Date.now() - started.current, page: location.pathname }) });
|
|
312
|
+
body: JSON.stringify({ formId, source, fields, hp: String(data.get("_hp") ?? ""), ms: Date.now() - started.current, page: location.pathname, extra: extraFields(data) }) });
|
|
287
313
|
const json = await res.json().catch(() => ({}));
|
|
288
314
|
if (!res.ok) {
|
|
289
315
|
showErrors(form, json.errors ?? {});
|
|
@@ -299,5 +325,5 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
|
|
|
299
325
|
}
|
|
300
326
|
if (state.status === "done")
|
|
301
327
|
return _jsx("p", { className: "ecx-form-status is-success", role: "status", "data-form-done": formId, children: state.message });
|
|
302
|
-
return (_jsxs("form", { className: cx("ecx-form-blocks", className), onSubmit: submit, noValidate: true, "data-form": formId, children: [children, _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 }) })] }));
|
|
328
|
+
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 }) })] }));
|
|
303
329
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consent API (như WP Consent API): hợp đồng chung giữa plugin hỏi khách (banner cookie) và plugin cần biết câu trả lời
|
|
3
|
+
* (analytics, pixel, widget chat, video nhúng…). Core không có banner, không chọn optin/optout thay ai — chỉ là API.
|
|
4
|
+
*
|
|
5
|
+
* Lựa chọn của khách chỉ đọc ở TRÌNH DUYỆT: HTML giống nhau cho mọi khách → trang cache được (không đọc cookie lúc render).
|
|
6
|
+
* Bên hỏi (trình duyệt): hasConsent("statistics") / getConsent() từ "@ecomcx/ecomweb-theme-sdk/client";
|
|
7
|
+
* on("consent.changed", …) để nạp script khi khách vừa cho phép.
|
|
8
|
+
* Plugin banner: setConsent([...]) ở trình duyệt; mặc định khi khách chưa chọn khai ở 2 chỗ (cùng một cài đặt của site):
|
|
9
|
+
* <meta name="cms-consent" content="optin"> trong <head> (trình duyệt đọc)
|
|
10
|
+
* và filter "consent.default" (server, vd quyết định có in <noscript> theo dõi hay không).
|
|
11
|
+
* Chưa có plugin banner → mọi nhóm được phép (website chạy như trước).
|
|
12
|
+
*/
|
|
13
|
+
export declare const CONSENT_CATEGORIES: readonly ["functional", "preferences", "statistics", "statistics-anonymous", "marketing"];
|
|
14
|
+
export type ConsentCategory = (typeof CONSENT_CATEGORIES)[number];
|
|
15
|
+
/** Lưu ở cookie tuỳ chọn "cms-pref-consent" (xem setPreference). */
|
|
16
|
+
export declare const CONSENT_PREF = "consent";
|
|
17
|
+
/** <meta name="cms-consent" content="optin|optout">: plugin banner khai mặc định cho trình duyệt. */
|
|
18
|
+
export declare const CONSENT_META = "cms-consent";
|
|
19
|
+
/** Giá trị cookie → các nhóm khách đã đồng ý; undefined = khách chưa trả lời. */
|
|
20
|
+
export declare function parseConsent(value: string | undefined): ConsentCategory[] | undefined;
|
|
21
|
+
/** Các nhóm → giá trị cookie ("functional" luôn được phép nên không lưu). */
|
|
22
|
+
export declare function serializeConsent(categories: readonly ConsentCategory[]): string;
|
|
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
|
+
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
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consent API (như WP Consent API): hợp đồng chung giữa plugin hỏi khách (banner cookie) và plugin cần biết câu trả lời
|
|
3
|
+
* (analytics, pixel, widget chat, video nhúng…). Core không có banner, không chọn optin/optout thay ai — chỉ là API.
|
|
4
|
+
*
|
|
5
|
+
* Lựa chọn của khách chỉ đọc ở TRÌNH DUYỆT: HTML giống nhau cho mọi khách → trang cache được (không đọc cookie lúc render).
|
|
6
|
+
* Bên hỏi (trình duyệt): hasConsent("statistics") / getConsent() từ "@ecomcx/ecomweb-theme-sdk/client";
|
|
7
|
+
* on("consent.changed", …) để nạp script khi khách vừa cho phép.
|
|
8
|
+
* Plugin banner: setConsent([...]) ở trình duyệt; mặc định khi khách chưa chọn khai ở 2 chỗ (cùng một cài đặt của site):
|
|
9
|
+
* <meta name="cms-consent" content="optin"> trong <head> (trình duyệt đọc)
|
|
10
|
+
* và filter "consent.default" (server, vd quyết định có in <noscript> theo dõi hay không).
|
|
11
|
+
* Chưa có plugin banner → mọi nhóm được phép (website chạy như trước).
|
|
12
|
+
*/
|
|
13
|
+
export const CONSENT_CATEGORIES = ["functional", "preferences", "statistics", "statistics-anonymous", "marketing"];
|
|
14
|
+
/** Lưu ở cookie tuỳ chọn "cms-pref-consent" (xem setPreference). */
|
|
15
|
+
export const CONSENT_PREF = "consent";
|
|
16
|
+
/** <meta name="cms-consent" content="optin|optout">: plugin banner khai mặc định cho trình duyệt. */
|
|
17
|
+
export const CONSENT_META = "cms-consent";
|
|
18
|
+
const NONE = "none";
|
|
19
|
+
/** Giá trị cookie → các nhóm khách đã đồng ý; undefined = khách chưa trả lời. */
|
|
20
|
+
export function parseConsent(value) {
|
|
21
|
+
if (value === undefined || value === "")
|
|
22
|
+
return undefined;
|
|
23
|
+
if (value === NONE)
|
|
24
|
+
return [];
|
|
25
|
+
return value.split("_").filter((c) => CONSENT_CATEGORIES.includes(c));
|
|
26
|
+
}
|
|
27
|
+
/** Các nhóm → giá trị cookie ("functional" luôn được phép nên không lưu). */
|
|
28
|
+
export function serializeConsent(categories) {
|
|
29
|
+
const list = CONSENT_CATEGORIES.filter((c) => c !== "functional" && categories.includes(c));
|
|
30
|
+
return list.length ? list.join("_") : NONE;
|
|
31
|
+
}
|
|
32
|
+
/** 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. */
|
|
33
|
+
export function decideConsent(category, choice, fallback) {
|
|
34
|
+
if (category === "functional")
|
|
35
|
+
return true;
|
|
36
|
+
return choice ? choice.includes(category) : fallback;
|
|
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
|
@@ -88,6 +88,11 @@ export async function contentContext(site, post, data) {
|
|
|
88
88
|
const hasBlockFilter = extensions.some((d) => d.filters?.["block.render"]);
|
|
89
89
|
return {
|
|
90
90
|
site, post, data, blocks, markBlocks,
|
|
91
|
+
controls: extensions.flatMap((d) => d.blockControls ?? []),
|
|
92
|
+
// Nhiều plugin cùng khai một loại khối → gộp danh sách thuộc tính
|
|
93
|
+
ready: extensions.some((d) => d.readyBlocks) ? extensions.reduce((m, d) => { for (const [k, v] of Object.entries(d.readyBlocks ?? {}))
|
|
94
|
+
m[k] = [...new Set([...(m[k] ?? []), ...v])]; return m; }, {}) : undefined,
|
|
95
|
+
assets: extensions.flatMap((d) => d.assets ?? []),
|
|
91
96
|
filterBlock: hasBlockFilter ? (node, el) => applyFilters("block.render", el, { node, site, post }, site) : undefined,
|
|
92
97
|
resolve: { shortcode: (name) => findShortcode(name, site), block: (type) => findBlock(type, site) },
|
|
93
98
|
labels: { download: t("file.download"), toc: t("toc.title") },
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { getT, getClientMessages, BUILTIN as BUILTIN_STRINGS, type Translator, t
|
|
|
9
9
|
export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
|
|
10
10
|
export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, NavToggle, isInternalHref, type LinkProps } from "./client.js";
|
|
11
11
|
export { getPreference } from "./preferences.js";
|
|
12
|
+
export { consentDefault, CONSENT_CATEGORIES, CONSENT_META, type ConsentCategory } from "./consent.js";
|
|
12
13
|
export { getCurrentUser, getAccessToken, requireUser, userCan, safeRedirect, ACCESS_COOKIE, REFRESH_COOKIE, type CurrentUser } from "./auth.js";
|
|
13
14
|
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";
|
|
14
15
|
export { buildDocumentMetadata } from "./metadata.js";
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { getT, getClientMessages, BUILTIN as BUILTIN_STRINGS } from "./i18n.js";
|
|
|
9
9
|
export { getRequestLocale, localeHref, LOCALE_HEADER } from "./locale.js";
|
|
10
10
|
export { CommentForm, CommentList, CommentsMore, ExtensionBoundary, PostPasswordForm, Link, NavToggle, isInternalHref } from "./client.js";
|
|
11
11
|
export { getPreference } from "./preferences.js";
|
|
12
|
+
export { consentDefault, CONSENT_CATEGORIES, CONSENT_META } from "./consent.js";
|
|
12
13
|
export { getCurrentUser, getAccessToken, requireUser, userCan, safeRedirect, ACCESS_COOKIE, REFRESH_COOKIE } from "./auth.js";
|
|
13
14
|
export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
|
|
14
15
|
export { buildDocumentMetadata } from "./metadata.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TemplateProps } from "./types.js";
|
|
2
|
+
/** Template "landing": như "full-width" (giữ header/footer, khối "Toàn trang" tràn màn hình) nhưng không in tiêu đề — section đầu (hero) sát header. */
|
|
3
|
+
export default function Landing({ data }: TemplateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PostContent } from "./content.js";
|
|
3
|
+
/** Template "landing": như "full-width" (giữ header/footer, khối "Toàn trang" tràn màn hình) nhưng không in tiêu đề — section đầu (hero) sát header. */
|
|
4
|
+
export default function Landing({ data }) {
|
|
5
|
+
return (_jsx("div", { className: "ecx-full-width ecx-landing", children: _jsx(PostContent, { post: data.post, className: "entry-content ecx-layout-constrained" }) }));
|
|
6
|
+
}
|
package/dist/rich.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ComponentType, type ReactNode } from "react";
|
|
2
|
-
import { type Block, type BlockDefinition, type ContentDoc, type RichNode } from "@ecomcx/ecomweb-content";
|
|
3
|
-
import type { BlockProps, Post, ResolveResult, ShortcodeProps, Site } from "./types.js";
|
|
2
|
+
import { type BlockControls, type Block, type BlockDefinition, type ContentDoc, type RichNode } from "@ecomcx/ecomweb-content";
|
|
3
|
+
import type { BlockProps, Post, ResolveResult, ShortcodeProps, Site, BlockAsset } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Vẽ nội dung (định dạng của CMS — @ecomcx/ecomweb-content) thành React, không phụ thuộc trình soạn.
|
|
6
6
|
* Hàm thuần: shortcode/khối của plugin tra qua `resolve`, bọc lỗi qua `boundary` → test được không cần Next/runtime.
|
|
@@ -43,6 +43,17 @@ export interface RenderContext {
|
|
|
43
43
|
pattern?(ref: number): Promise<ContentDoc | null>;
|
|
44
44
|
/** Plugin thay vùng (definePlugin → regions): nhận bản template part đã vẽ, trả bản thay thế. Không có = giữ nguyên. */
|
|
45
45
|
region?(name: string, fallback: ReactNode): Promise<ReactNode>;
|
|
46
|
+
/** Ô điều khiển khai CSS của plugin (definePlugin → blockControls): class `ecx-c-…` + CSS gom chung với kiểu dáng khối. */
|
|
47
|
+
controls?: readonly BlockControls[];
|
|
48
|
+
/** Khối plugin nhận ở trình duyệt (definePlugin → readyBlocks, onBlockReady): loại khối / "*" → thuộc tính đưa vào data-ecx-attrs. */
|
|
49
|
+
ready?: Readonly<Record<string, readonly string[]>>;
|
|
50
|
+
/** Script / stylesheet nạp theo nhu cầu (definePlugin → assets): chỉ in khi nội dung có khối / class tương ứng. */
|
|
51
|
+
assets?: readonly BlockAsset[];
|
|
52
|
+
/** (nội bộ) loại khối + class đã vẽ trong lần renderContent ngoài cùng — chọn asset. */
|
|
53
|
+
used?: {
|
|
54
|
+
types: Set<string>;
|
|
55
|
+
classes: Set<string>;
|
|
56
|
+
};
|
|
46
57
|
/** CSS kiểu dáng khối (attrs.style) gom theo class — renderContent ngoài cùng tạo và xuất thành một thẻ <style>. */
|
|
47
58
|
styles?: Map<string, string>;
|
|
48
59
|
/** Đang vẽ bên trong nhóm nút (`buttons`): nút không bọc thêm đoạn văn. */
|
package/dist/rich.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment, cloneElement, createElement, isValidElement } from "react";
|
|
3
3
|
import { ICON_PATHS } from "./icons.js";
|
|
4
|
-
import { DYNAMIC_NODES, widthClass, blockCitation, blockShell, buttonWrapShell, coverParts, linkRel, embedInfo, motionClasses, normalizeContent, safeUrl, styleClass, styleCss } from "@ecomcx/ecomweb-content";
|
|
4
|
+
import { DYNAMIC_NODES, widthClass, blockCitation, blockShell, buttonWrapShell, coverParts, linkRel, embedInfo, motionClasses, normalizeContent, safeUrl, styleClass, styleCss, controlsCss } from "@ecomcx/ecomweb-content";
|
|
5
5
|
import { cx } from "./utils.js";
|
|
6
6
|
import { SOCIAL_ICONS } from "./social-icons.js";
|
|
7
|
-
import { CountdownClient, FormBlockClient, LightboxClient, TabsClient } from "./client.js";
|
|
7
|
+
import { CountdownClient, FormBlockClient, LightboxClient, Link, TabsClient } from "./client.js";
|
|
8
|
+
import { AssetScript } from "./browser.js";
|
|
8
9
|
import { getT } from "./i18n.js";
|
|
10
|
+
import { Slot } from "./components.js";
|
|
11
|
+
import { getSlotItems } from "./runtime.js";
|
|
9
12
|
const DYNAMIC = new Set(DYNAMIC_NODES);
|
|
10
13
|
const SHORTCODE = /^\s*\[([a-z0-9_-]+)((?:\s+[a-z0-9_-]+=(?:"[^"]*"|'[^']*'|[^\s\]]+))*)\s*\]\s*$/i;
|
|
11
14
|
const SHORTCODE_INLINE = /\[([a-z0-9_-]+)((?:\s+[a-z0-9_-]+=(?:"[^"]*"|'[^']*'|[^\s\]]+))*)\s*\]/gi;
|
|
@@ -67,7 +70,9 @@ function alignStyle(attrs) {
|
|
|
67
70
|
/** Vẽ khối theo vỏ markup dùng chung với trình soạn (@ecomcx/ecomweb-content › blockShell): thẻ / class / style cùng một nguồn. */
|
|
68
71
|
function shelled(type, a, key, children, extra, parent) {
|
|
69
72
|
const sh = blockShell(type, a, parent);
|
|
70
|
-
|
|
73
|
+
// Nút / khối có link: Link của SDK (link nội bộ chuyển trang không tải lại; link ngoài, tab mới, file vẫn là <a>)
|
|
74
|
+
const tag = (sh.tag === "a" && typeof extra?.href === "string" ? Link : sh.tag);
|
|
75
|
+
return createElement(tag, { key, className: sh.className, ...extra, style: sh.style, ...sh.attrs }, children);
|
|
71
76
|
}
|
|
72
77
|
function renderMarks(text, marks, key, ctx) {
|
|
73
78
|
let out = text;
|
|
@@ -113,7 +118,8 @@ function renderMarks(text, marks, key, ctx) {
|
|
|
113
118
|
break;
|
|
114
119
|
case "link": {
|
|
115
120
|
const target = m.attrs?.target;
|
|
116
|
-
|
|
121
|
+
const href = safeUrl(m.attrs?.href);
|
|
122
|
+
out = href ? _jsx(Link, { href: href, target: target ?? undefined, rel: linkRel(m.attrs?.rel, target), children: out }, k) : _jsx("a", { children: out }, k);
|
|
117
123
|
break;
|
|
118
124
|
}
|
|
119
125
|
}
|
|
@@ -156,14 +162,16 @@ function overridden(style) {
|
|
|
156
162
|
* Gắn kiểu dáng (class `ecx-s-…`), biến thể (`ecx-is-…`), class riêng và neo (id) của khối vào phần tử đã vẽ
|
|
157
163
|
* (không có phần tử bọc ngoài → thêm div). Giá trị đã được normalizeContent kiểm.
|
|
158
164
|
*/
|
|
159
|
-
function decorate(el, a, key, ctx, type) {
|
|
165
|
+
function decorate(el, a, key, ctx, type, ctrl, data) {
|
|
160
166
|
if (el == null || el === false)
|
|
161
167
|
return el;
|
|
162
168
|
const style = a.style && typeof a.style === "object" ? a.style : null;
|
|
163
169
|
const cls = style ? styleClass(style) : null;
|
|
164
170
|
if (style && cls && ctx.styles && !ctx.styles.has(cls))
|
|
165
171
|
ctx.styles.set(cls, styleCss(style, cls));
|
|
166
|
-
|
|
172
|
+
if (ctrl && ctx.styles && !ctx.styles.has(ctrl.cls))
|
|
173
|
+
ctx.styles.set(ctrl.cls, ctrl.css);
|
|
174
|
+
const extra = cx(cls, ctrl?.cls, motionClasses(style), widthClass(type, a), a.blockStyle && `ecx-is-${a.blockStyle}`, a.className);
|
|
167
175
|
if (isValidElement(el) && el.type !== Fragment && typeof el.type === "string") {
|
|
168
176
|
const e = el;
|
|
169
177
|
let inline = e.props.style;
|
|
@@ -171,9 +179,9 @@ function decorate(el, a, key, ctx, type) {
|
|
|
171
179
|
const drop = new Set(overridden(style));
|
|
172
180
|
inline = Object.fromEntries(Object.entries(inline).filter(([k]) => !drop.has(k)));
|
|
173
181
|
}
|
|
174
|
-
return cloneElement(e, { className: cx(e.props.className, extra) || undefined, style: inline, id: a.anchor ?? e.props.id });
|
|
182
|
+
return cloneElement(e, { className: cx(e.props.className, extra) || undefined, style: inline, id: a.anchor ?? e.props.id, ...data });
|
|
175
183
|
}
|
|
176
|
-
return _jsx("div", { className: extra || undefined, id: a.anchor, children: el }, key);
|
|
184
|
+
return _jsx("div", { className: extra || undefined, id: a.anchor, ...data, children: el }, key);
|
|
177
185
|
}
|
|
178
186
|
/** Thuộc tính gắn được của khối lõi (ngoài danh sách bị bỏ qua). */
|
|
179
187
|
const BINDABLE = { paragraph: ["content"], heading: ["content"], image: ["src", "alt", "caption"], button: ["text", "href"] };
|
|
@@ -221,7 +229,16 @@ async function renderNode(node, key, ctx) {
|
|
|
221
229
|
if (ctx.filterBlock && node.type !== "text" && node.type !== "doc")
|
|
222
230
|
el = await ctx.filterBlock(node, el);
|
|
223
231
|
const a = node.attrs;
|
|
224
|
-
|
|
232
|
+
if (ctx.used && node.type !== "text") {
|
|
233
|
+
ctx.used.types.add(node.type);
|
|
234
|
+
if (typeof a?.className === "string")
|
|
235
|
+
for (const c of a.className.split(/\s+/))
|
|
236
|
+
ctx.used.classes.add(c);
|
|
237
|
+
}
|
|
238
|
+
const ctrl = ctx.controls?.length && node.type !== "text" ? controlsCss(ctx.controls, node.type, a ?? {}) : null;
|
|
239
|
+
const pick = ctx.ready && node.type !== "text" ? ctx.ready[node.type] ?? ctx.ready["*"] : undefined;
|
|
240
|
+
const data = pick ? { "data-ecx-ready": node.type, "data-ecx-attrs": JSON.stringify(Object.fromEntries(pick.filter((k) => a?.[k] !== undefined).map((k) => [k, a[k]]))) } : undefined;
|
|
241
|
+
const out = (a && (a.style || a.blockStyle || a.className || a.anchor || widthClass(node.type, a))) || ctrl || data ? decorate(el, a ?? {}, key, ctx, node.type, ctrl, data) : el;
|
|
225
242
|
return ctx.markBlocks && ctx.source && ctx.pathRoot != null && key.startsWith(ctx.pathRoot + "-") && !UNMARKED.has(node.type)
|
|
226
243
|
? markBlock(out, ctx.source, key.slice(ctx.pathRoot.length + 1), key)
|
|
227
244
|
: out;
|
|
@@ -293,7 +310,7 @@ async function renderNodeInner(node, key, ctx) {
|
|
|
293
310
|
const img = _jsx("img", { src: imgSrc, srcSet: a.srcset || undefined, sizes: a.srcset ? sizes : undefined, alt: a.alt ?? "", title: a.title ?? undefined, width: a.width ?? undefined, height: a.height ?? undefined, loading: "lazy", decoding: "async" });
|
|
294
311
|
const bare = a.webpSrcset ? _jsxs("picture", { children: [_jsx("source", { type: "image/webp", srcSet: a.webpSrcset, sizes: sizes }), img] }) : img;
|
|
295
312
|
// next: ảnh có liên kết (href qua safeUrl; mở tab mới thì noopener)
|
|
296
|
-
const pic = a.lightbox === true && !a.href ? _jsx(LightboxClient, { src: safeUrl(a.src, ""), alt: a.alt ?? "", children: bare }) : a.href ? _jsx(
|
|
313
|
+
const pic = a.lightbox === true && !a.href ? _jsx(LightboxClient, { src: safeUrl(a.src, ""), alt: a.alt ?? "", children: bare }) : a.href ? _jsx(Link, { href: safeUrl(a.href), target: a.linkTarget === "_blank" ? "_blank" : undefined, rel: a.linkTarget === "_blank" ? "noopener noreferrer" : undefined, children: bare }) : bare;
|
|
297
314
|
const cls = blockShell("image", a).className;
|
|
298
315
|
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
316
|
}
|
|
@@ -390,7 +407,7 @@ async function renderNodeInner(node, key, ctx) {
|
|
|
390
407
|
return null;
|
|
391
408
|
const t = await getT();
|
|
392
409
|
const inner = await Promise.all((node.content ?? []).map((c, i) => renderNode(c, `${key}-${i}`, { ...ctx, form: formId })));
|
|
393
|
-
return (_jsx(FormBlockClient, { formId: formId, source: ctx.source, successMessage: a.successMessage ? String(a.successMessage) : undefined, button: { className: blockShell("button", { variant: "primary" })?.className, style: blockShell("button", { variant: "primary" })?.style }, labels: { submit: a.submitText ? String(a.submitText) : t("form.submit"), sending: t("form.sending"), error: t("form.error") }, children: inner }, key));
|
|
410
|
+
return (_jsx(FormBlockClient, { formId: formId, source: ctx.source, successMessage: a.successMessage ? String(a.successMessage) : undefined, fields: (await getSlotItems("form.fields")).length ? _jsx(Slot, { name: "form.fields", props: { form: `core:${ctx.source}/${formId}`, settings: a.ext && typeof a.ext === "object" ? a.ext : {} } }) : undefined, button: { className: blockShell("button", { variant: "primary" })?.className, style: blockShell("button", { variant: "primary" })?.style }, labels: { submit: a.submitText ? String(a.submitText) : t("form.submit"), sending: t("form.sending"), error: t("form.error") }, children: inner }, key));
|
|
394
411
|
}
|
|
395
412
|
case "formField": {
|
|
396
413
|
const name = typeof a.name === "string" && /^[a-z][a-z0-9_]{0,39}$/.test(a.name) ? a.name : "";
|
|
@@ -515,6 +532,16 @@ async function renderBlock(block, key, ctx) {
|
|
|
515
532
|
}
|
|
516
533
|
}
|
|
517
534
|
}
|
|
535
|
+
/** Asset của plugin có điều kiện khớp nội dung vừa vẽ: stylesheet (React gộp + đưa lên <head>) và script (nạp một lần, cả khi chuyển trang bằng Link). */
|
|
536
|
+
function assetsFor(list, used) {
|
|
537
|
+
const hit = (w) => !!w.blocks?.some((b) => used.types.has(b)) || (!!w.className && [...used.classes].some((c) => c.startsWith(w.className)));
|
|
538
|
+
return list.filter((x) => hit(x.when)).map((x, i) => {
|
|
539
|
+
const src = safeUrl(x.src, "");
|
|
540
|
+
if (!src)
|
|
541
|
+
return null;
|
|
542
|
+
return x.kind === "style" ? _jsx("link", { rel: "stylesheet", href: src, precedence: "ecx-asset" }, `ecx-asset-${i}`) : _jsx(AssetScript, { src: src }, `ecx-asset-${i}`);
|
|
543
|
+
});
|
|
544
|
+
}
|
|
518
545
|
function wrap(ctx, name, key, el) {
|
|
519
546
|
return ctx.boundary ? ctx.boundary(name, key, el) : _jsx(Fragment, { children: el }, key);
|
|
520
547
|
}
|
|
@@ -529,11 +556,13 @@ export async function renderContent(content, ctx, transform) {
|
|
|
529
556
|
const own = !ctx.styles;
|
|
530
557
|
if (own) {
|
|
531
558
|
const notes = collectFootnotes(blocks);
|
|
532
|
-
ctx = { ...ctx, styles: new Map(), headings: ctx.headings ?? collectHeadings(blocks), footnotes: ctx.footnotes ?? (notes.length ? { notes, prefix: String(ctx.post?.id ?? "x") } : undefined) };
|
|
559
|
+
ctx = { ...ctx, styles: new Map(), used: ctx.assets?.length ? { types: new Set(), classes: new Set() } : undefined, headings: ctx.headings ?? collectHeadings(blocks), footnotes: ctx.footnotes ?? (notes.length ? { notes, prefix: String(ctx.post?.id ?? "x") } : undefined) };
|
|
533
560
|
}
|
|
534
561
|
const out = await Promise.all(blocks.map((b, i) => renderBlock(b, b.id ?? `b${i}`, ctx)));
|
|
535
562
|
if (own && ctx.styles.size)
|
|
536
563
|
out.unshift(_jsx("style", { "data-ecx-styles": "", children: [...ctx.styles.values()].join("") }, "ecx-styles"));
|
|
564
|
+
if (own && ctx.used)
|
|
565
|
+
out.push(...assetsFor(ctx.assets, ctx.used));
|
|
537
566
|
return out;
|
|
538
567
|
}
|
|
539
568
|
/**
|
package/dist/runtime.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface RuntimeConfig {
|
|
|
8
8
|
export declare function configureRuntime(config: RuntimeConfig): void;
|
|
9
9
|
export declare const FALLBACK_THEME = "default";
|
|
10
10
|
/** Tên template trang có sẵn (theme có template cùng tên thì dùng của theme). */
|
|
11
|
-
export declare const BUILTIN_PAGE_TEMPLATES: readonly ["canvas", "full-width"];
|
|
11
|
+
export declare const BUILTIN_PAGE_TEMPLATES: readonly ["canvas", "full-width", "landing"];
|
|
12
12
|
export interface LoadedTheme {
|
|
13
13
|
slug: string;
|
|
14
14
|
chain: ThemeEntry[];
|
package/dist/runtime.js
CHANGED
|
@@ -17,9 +17,10 @@ const BUILTIN_TEMPLATES = {
|
|
|
17
17
|
auth: () => import("./auth-pages.js"),
|
|
18
18
|
canvas: () => import("./page-canvas.js"),
|
|
19
19
|
"full-width": () => import("./page-full-width.js"),
|
|
20
|
+
landing: () => import("./page-landing.js"),
|
|
20
21
|
};
|
|
21
22
|
/** Tên template trang có sẵn (theme có template cùng tên thì dùng của theme). */
|
|
22
|
-
export const BUILTIN_PAGE_TEMPLATES = ["canvas", "full-width"];
|
|
23
|
+
export const BUILTIN_PAGE_TEMPLATES = ["canvas", "full-width", "landing"];
|
|
23
24
|
/** Theme đang active (kèm theme cha nếu là child theme). Fallback về "default" nếu theme không tồn tại trong bản build. */
|
|
24
25
|
export const getActiveTheme = cache(async (site) => {
|
|
25
26
|
const s = site ?? (await getSite());
|
package/dist/types.d.ts
CHANGED
|
@@ -441,7 +441,9 @@ export type PluginRoute = (req: Request, ctx: {
|
|
|
441
441
|
* auth.login.fields, auth.register.fields, auth.forgot_password.fields (ô thêm trong form tài khoản, vd captcha).
|
|
442
442
|
* Ô thêm có name="extra.*" được gửi kèm trong "extra" — backend đọc ở action auth.attempt / filter comment.data.
|
|
443
443
|
*/
|
|
444
|
-
export type CoreSlotName = "head" | "body.start" | "body.end" | "before.content" | "after.content" | "footer" | "comments.before" | "comments.after" | "comment_form.fields" | "auth.login.fields" | "auth.register.fields" | "auth.forgot_password.fields"
|
|
444
|
+
export type CoreSlotName = "head" | "body.start" | "body.end" | "before.content" | "after.content" | "footer" | "comments.before" | "comments.after" | "comment_form.fields" | "auth.login.fields" | "auth.register.fields" | "auth.forgot_password.fields"
|
|
445
|
+
/** Ô thêm trong mọi form (core + plugin theo hợp đồng chung, CMS ≥ 1.29): props { form, settings }; ô name="extra.*" → hook form.submitting. */
|
|
446
|
+
| "form.fields";
|
|
445
447
|
export type SlotName = CoreSlotName | (string & {});
|
|
446
448
|
/**
|
|
447
449
|
* Vùng chuẩn của core: theme bọc đầu trang / chân trang trong <EditableRegion name="header|footer">
|
|
@@ -504,9 +506,26 @@ export interface FilterMap {
|
|
|
504
506
|
"body.class": (classes: string[], ctx: {
|
|
505
507
|
site: Site;
|
|
506
508
|
}) => string[] | Promise<string[]>;
|
|
509
|
+
/**
|
|
510
|
+
* Consent API: khách CHƯA chọn thì nhóm cookie này có được phép không (mặc định true). Plugin banner theo luật optin (EU,
|
|
511
|
+
* Nghị định 13) trả false (và in <meta name="cms-consent" content="optin"> cho trình duyệt). Xem consentDefault.
|
|
512
|
+
*/
|
|
513
|
+
"consent.default": (allowed: boolean, ctx: {
|
|
514
|
+
category: import("./consent.js").ConsentCategory;
|
|
515
|
+
}) => boolean | Promise<boolean>;
|
|
507
516
|
/** Cho phép các filter tùy biến bất kỳ của plugin/theme */
|
|
508
517
|
[customFilter: string]: ((val: any, ctx?: any) => any) | undefined;
|
|
509
518
|
}
|
|
519
|
+
/** Asset nạp theo nhu cầu: `src` trong website ("/extensions/…") hoặc https. */
|
|
520
|
+
export interface BlockAsset {
|
|
521
|
+
kind: "script" | "style";
|
|
522
|
+
src: string;
|
|
523
|
+
/** Nạp khi nội dung có một trong các khối, hoặc khối có class bắt đầu bằng tiền tố này (vd "mx-"). */
|
|
524
|
+
when: {
|
|
525
|
+
blocks?: string[];
|
|
526
|
+
className?: string;
|
|
527
|
+
};
|
|
528
|
+
}
|
|
510
529
|
export interface PluginDefinition {
|
|
511
530
|
/** [contact-form id="1"] trong nội dung → component. */
|
|
512
531
|
shortcodes?: Record<string, ComponentType<ShortcodeProps>>;
|
|
@@ -532,6 +551,18 @@ export interface PluginDefinition {
|
|
|
532
551
|
blocks?: Record<string, ComponentType<BlockProps>>;
|
|
533
552
|
/** Định nghĩa khối (defineBlock, file dùng chung với phần admin) — website chuẩn hoá thuộc tính + nâng phiên bản trước khi vẽ. */
|
|
534
553
|
blockTypes?: import("@ecomcx/ecomweb-content").BlockDefinition[];
|
|
554
|
+
/**
|
|
555
|
+
* Ô điều khiển khai CSS (core ≥ 1.29, @ecomcx/ecomweb-content defineBlockControls — cùng object đăng ký ở admin bằng registerBlockPanel):
|
|
556
|
+
* website sinh CSS theo class băm của khối, giống hệt khung soạn. Giá trị không hợp lệ bị bỏ.
|
|
557
|
+
*/
|
|
558
|
+
blockControls?: import("@ecomcx/ecomweb-content").BlockControls[];
|
|
559
|
+
/**
|
|
560
|
+
* Khối muốn nhận ở trình duyệt bằng onBlockReady (core ≥ 1.29): { "image": ["acmeZoom"], "*": [] } — website chỉ gắn
|
|
561
|
+
* data-ecx-ready / data-ecx-attrs (các thuộc tính liệt kê) cho các khối này, không phình HTML khi không plugin nào cần.
|
|
562
|
+
*/
|
|
563
|
+
readyBlocks?: Record<string, string[]>;
|
|
564
|
+
/** Script / stylesheet nạp theo nhu cầu (core ≥ 1.29): chỉ in khi nội dung có khối / class tương ứng. */
|
|
565
|
+
assets?: BlockAsset[];
|
|
535
566
|
/**
|
|
536
567
|
* Nguồn gắn dữ liệu (attrs.bindings của khối, @ecomcx/ecomweb-content 1.15): { "shop/product": async ({ id, field }, { post }) => … }.
|
|
537
568
|
* Khối lõi (đoạn văn, tiêu đề, ảnh, nút) hiện giá trị trả về; trả null/undefined → giữ nội dung gõ tay.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-theme-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.40.0",
|
|
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",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@ecomcx/ecomweb-content": "^1.
|
|
36
|
+
"@ecomcx/ecomweb-content": "^1.22.0",
|
|
37
37
|
"intl-messageformat": "12.1.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|