@ecomcx/ecomweb-theme-sdk 1.40.0 → 1.41.1
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 +8 -0
- package/dist/browser.js +3 -0
- package/dist/content.d.ts +5 -0
- package/dist/content.js +12 -1
- package/dist/counter-client.d.ts +11 -0
- package/dist/counter-client.js +36 -0
- package/dist/page-full-width.d.ts +1 -1
- package/dist/page-full-width.js +5 -4
- package/dist/page-landing.d.ts +1 -1
- package/dist/page-landing.js +5 -4
- package/dist/rich.js +25 -3
- package/package.json +2 -2
- package/dist/icons.d.ts +0 -2
- package/dist/icons.js +0 -15
package/dist/browser.d.ts
CHANGED
|
@@ -65,4 +65,12 @@ export type BlockReadyFn = (el: HTMLElement, attrs: Record<string, unknown>) =>
|
|
|
65
65
|
* onBlockReady("image", (img) => { const z = startZoom(img); return () => z.stop(); });
|
|
66
66
|
*/
|
|
67
67
|
export declare function onBlockReady(type: string, fn: BlockReadyFn): () => void;
|
|
68
|
+
declare global {
|
|
69
|
+
interface Window {
|
|
70
|
+
/** API ổn định cho script thuần nạp bằng `assets` (không qua bundle Next) — theme-sdk 1.41 / CMS ≥ 1.30. */
|
|
71
|
+
ecx?: {
|
|
72
|
+
onBlockReady?: typeof onBlockReady;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
68
76
|
export {};
|
package/dist/browser.js
CHANGED
|
@@ -211,3 +211,6 @@ export function onBlockReady(type, fn) {
|
|
|
211
211
|
catch { /* bỏ qua */ } applied.get(el)?.delete(fn); });
|
|
212
212
|
};
|
|
213
213
|
}
|
|
214
|
+
// Có sẵn trước khi script của `assets` chạy (AssetScript chèn script sau khi module này nạp)
|
|
215
|
+
if (typeof window !== "undefined")
|
|
216
|
+
(window.ecx ??= {}).onBlockReady ??= onBlockReady;
|
package/dist/content.d.ts
CHANGED
|
@@ -24,3 +24,8 @@ export declare function EditableRegion({ name, data, className, children }: {
|
|
|
24
24
|
}): Promise<import("react").JSX.Element>;
|
|
25
25
|
/** Ngữ cảnh vẽ nội dung dùng chung cho bài viết và template khối. */
|
|
26
26
|
export declare function contentContext(site: Site, post?: Post | null, data?: ResolveResult): Promise<RenderContext>;
|
|
27
|
+
/**
|
|
28
|
+
* Header / footer của theme dựng bằng khối cho template có sẵn của SDK (full-width, landing): theme khối không có header/footer
|
|
29
|
+
* trong layout mà ở template part trong từng template khối → template có sẵn phải tự vẽ part "header" / "footer". Theme thường: null.
|
|
30
|
+
*/
|
|
31
|
+
export declare function blockThemeParts(site: Site, data?: ResolveResult): Promise<[ReactNode, ReactNode]>;
|
package/dist/content.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { ExtensionBoundary, Link, PostPasswordForm } from "./client.js";
|
|
3
|
-
import { applyFilters, findBlock, findRegion, findShortcode, getActiveExtensions } from "./runtime.js";
|
|
3
|
+
import { applyFilters, findBlock, findRegion, findShortcode, getActiveExtensions, getActiveTheme } from "./runtime.js";
|
|
4
4
|
import { getPattern, getSite, getTemplates } from "./api.js";
|
|
5
5
|
import { CORE_BINDING_SOURCES } from "./bindings.js";
|
|
6
6
|
import { getT } from "./i18n.js";
|
|
@@ -108,3 +108,14 @@ export async function contentContext(site, post, data) {
|
|
|
108
108
|
},
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Header / footer của theme dựng bằng khối cho template có sẵn của SDK (full-width, landing): theme khối không có header/footer
|
|
113
|
+
* trong layout mà ở template part trong từng template khối → template có sẵn phải tự vẽ part "header" / "footer". Theme thường: null.
|
|
114
|
+
*/
|
|
115
|
+
export async function blockThemeParts(site, data) {
|
|
116
|
+
if ((await getActiveTheme(site)).chain[0]?.manifest.editing !== "blocks")
|
|
117
|
+
return [null, null];
|
|
118
|
+
const ctx = await contentContext(site, data?.post, data);
|
|
119
|
+
const part = async (slug) => _jsx(_Fragment, { children: await renderContent({ type: "doc", content: [{ type: "templatePart", attrs: { slug, tagName: slug } }] }, ctx) });
|
|
120
|
+
return [await part("header"), await part("footer")];
|
|
121
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Data = Record<string, string | number | boolean | undefined>;
|
|
2
|
+
/**
|
|
3
|
+
* Số của khối Counter: HTML có sẵn số cuối (không JS / máy tìm kiếm thấy đúng số). Trên trình duyệt: về số đầu rồi đếm lên khi
|
|
4
|
+
* khối vào màn hình (IntersectionObserver, một lần). Người dùng chọn giảm chuyển động hoặc duration = 0 → giữ nguyên số cuối.
|
|
5
|
+
*/
|
|
6
|
+
export declare function CounterClient({ className, data, text }: {
|
|
7
|
+
className?: string;
|
|
8
|
+
data: Data;
|
|
9
|
+
text: string;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { formatCounter } from "@ecomcx/ecomweb-content";
|
|
5
|
+
/**
|
|
6
|
+
* Số của khối Counter: HTML có sẵn số cuối (không JS / máy tìm kiếm thấy đúng số). Trên trình duyệt: về số đầu rồi đếm lên khi
|
|
7
|
+
* khối vào màn hình (IntersectionObserver, một lần). Người dùng chọn giảm chuyển động hoặc duration = 0 → giữ nguyên số cuối.
|
|
8
|
+
*/
|
|
9
|
+
export function CounterClient({ className, data, text }) {
|
|
10
|
+
const ref = useRef(null);
|
|
11
|
+
const start = Number(data["data-start"]) || 0, end = Number(data["data-end"]) || 0, dec = Number(data["data-decimals"]) || 0;
|
|
12
|
+
const sep = data["data-separator"], ms = Number(data["data-duration"]) || 0;
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const el = ref.current;
|
|
15
|
+
if (!el || ms <= 0 || start === end || typeof IntersectionObserver === "undefined" || matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
16
|
+
return;
|
|
17
|
+
let raf = 0;
|
|
18
|
+
el.textContent = formatCounter(start, dec, sep);
|
|
19
|
+
const io = new IntersectionObserver(([e]) => {
|
|
20
|
+
if (!e?.isIntersecting)
|
|
21
|
+
return;
|
|
22
|
+
io.disconnect();
|
|
23
|
+
const t0 = performance.now();
|
|
24
|
+
const step = (now) => {
|
|
25
|
+
const p = Math.min(1, (now - t0) / ms);
|
|
26
|
+
el.textContent = formatCounter(start + (end - start) * (1 - (1 - p) ** 3), dec, sep);
|
|
27
|
+
if (p < 1)
|
|
28
|
+
raf = requestAnimationFrame(step);
|
|
29
|
+
};
|
|
30
|
+
raf = requestAnimationFrame(step);
|
|
31
|
+
});
|
|
32
|
+
io.observe(el);
|
|
33
|
+
return () => { io.disconnect(); cancelAnimationFrame(raf); el.textContent = text; };
|
|
34
|
+
}, [start, end, dec, sep, ms, text]);
|
|
35
|
+
return _jsx("span", { ref: ref, className: className, ...data, children: text });
|
|
36
|
+
}
|
|
@@ -3,4 +3,4 @@ import type { TemplateProps } from "./types.js";
|
|
|
3
3
|
* Template "full-width": giữ header/footer của theme, vùng bài trải hết chiều ngang màn hình. Như WordPress: chữ vẫn ở cột giữa
|
|
4
4
|
* (--ecx-content-width), chỉ khối đặt độ rộng "Rộng" / "Toàn trang" mới tràn ra.
|
|
5
5
|
*/
|
|
6
|
-
export default function FullWidth({ data }: TemplateProps): import("react").JSX.Element
|
|
6
|
+
export default function FullWidth({ data, site }: TemplateProps): Promise<import("react").JSX.Element>;
|
package/dist/page-full-width.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { PostContent } from "./content.js";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { blockThemeParts, PostContent } from "./content.js";
|
|
3
3
|
/**
|
|
4
4
|
* Template "full-width": giữ header/footer của theme, vùng bài trải hết chiều ngang màn hình. Như WordPress: chữ vẫn ở cột giữa
|
|
5
5
|
* (--ecx-content-width), chỉ khối đặt độ rộng "Rộng" / "Toàn trang" mới tràn ra.
|
|
6
6
|
*/
|
|
7
|
-
export default function FullWidth({ data }) {
|
|
8
|
-
|
|
7
|
+
export default async function FullWidth({ data, site }) {
|
|
8
|
+
const [header, footer] = await blockThemeParts(site, data);
|
|
9
|
+
return (_jsxs(_Fragment, { children: [header, _jsxs("div", { className: "ecx-full-width", children: [data.post?.title && _jsx("h1", { className: "entry-title ecx-page-title", children: data.post.title }), _jsx(PostContent, { post: data.post, className: "entry-content ecx-layout-constrained" })] }), footer] }));
|
|
9
10
|
}
|
package/dist/page-landing.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TemplateProps } from "./types.js";
|
|
2
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
|
|
3
|
+
export default function Landing({ data, site }: TemplateProps): Promise<import("react").JSX.Element>;
|
package/dist/page-landing.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { PostContent } from "./content.js";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { blockThemeParts, PostContent } from "./content.js";
|
|
3
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
|
-
|
|
4
|
+
export default async function Landing({ data, site }) {
|
|
5
|
+
const [header, footer] = await blockThemeParts(site, data);
|
|
6
|
+
return (_jsxs(_Fragment, { children: [header, _jsx("div", { className: "ecx-full-width ecx-landing", children: _jsx(PostContent, { post: data.post, className: "entry-content ecx-layout-constrained" }) }), footer] }));
|
|
6
7
|
}
|
package/dist/rich.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
-
import { ICON_PATHS } from "
|
|
4
|
-
import { DYNAMIC_NODES, widthClass, blockCitation, blockShell, buttonWrapShell, coverParts, linkRel, embedInfo, motionClasses, normalizeContent, safeUrl, styleClass, styleCss, controlsCss } from "@ecomcx/ecomweb-content";
|
|
3
|
+
import { DYNAMIC_NODES, ICON_PATHS, widgetMarkup, widthClass, blockCitation, blockShell, buttonWrapShell, coverParts, linkRel, embedInfo, motionClasses, normalizeContent, safeUrl, styleClass, styleCss, controlsCss } from "@ecomcx/ecomweb-content";
|
|
5
4
|
import { cx } from "./utils.js";
|
|
6
5
|
import { SOCIAL_ICONS } from "./social-icons.js";
|
|
7
6
|
import { CountdownClient, FormBlockClient, LightboxClient, Link, TabsClient } from "./client.js";
|
|
7
|
+
import { CounterClient } from "./counter-client.js";
|
|
8
8
|
import { AssetScript } from "./browser.js";
|
|
9
9
|
import { getT } from "./i18n.js";
|
|
10
10
|
import { Slot } from "./components.js";
|
|
@@ -183,6 +183,16 @@ function decorate(el, a, key, ctx, type, ctrl, data) {
|
|
|
183
183
|
}
|
|
184
184
|
return _jsx("div", { className: extra || undefined, id: a.anchor, ...data, children: el }, key);
|
|
185
185
|
}
|
|
186
|
+
/** Widget lõi: cây markup chung với khung soạn (@ecomcx/ecomweb-content widgetMarkup) → React; số của Counter đếm lên trên trình duyệt. */
|
|
187
|
+
function widgetEl(el, key) {
|
|
188
|
+
if (typeof el === "string")
|
|
189
|
+
return el;
|
|
190
|
+
const kids = (el.children ?? []).map((c, i) => widgetEl(c, i));
|
|
191
|
+
if (el.client === "counter")
|
|
192
|
+
return _jsx(CounterClient, { className: el.className, data: el.props ?? {}, text: String(el.children?.[0] ?? "") }, key);
|
|
193
|
+
const props = { key, ...el.props, className: el.className, style: el.style };
|
|
194
|
+
return el.tag === "a" ? _jsx(Link, { ...props, href: String(el.props?.href ?? ""), children: kids }) : createElement(el.tag, props, ...kids);
|
|
195
|
+
}
|
|
186
196
|
/** Thuộc tính gắn được của khối lõi (ngoài danh sách bị bỏ qua). */
|
|
187
197
|
const BINDABLE = { paragraph: ["content"], heading: ["content"], image: ["src", "alt", "caption"], button: ["text", "href"] };
|
|
188
198
|
const URL_ATTRS = new Set(["src", "href"]);
|
|
@@ -237,12 +247,15 @@ async function renderNode(node, key, ctx) {
|
|
|
237
247
|
}
|
|
238
248
|
const ctrl = ctx.controls?.length && node.type !== "text" ? controlsCss(ctx.controls, node.type, a ?? {}) : null;
|
|
239
249
|
const pick = ctx.ready && node.type !== "text" ? ctx.ready[node.type] ?? ctx.ready["*"] : undefined;
|
|
240
|
-
|
|
250
|
+
// Có liệt kê thuộc tính → chỉ gắn khi khối có ít nhất một giá trị (không phình HTML mọi nhóm / bìa); [] = mọi khối loại đó
|
|
251
|
+
const given = pick?.filter((k) => !emptyAttr(a?.[k]));
|
|
252
|
+
const data = pick && (!pick.length || given.length) ? { "data-ecx-ready": node.type, "data-ecx-attrs": JSON.stringify(Object.fromEntries(given.map((k) => [k, a[k]]))) } : undefined;
|
|
241
253
|
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;
|
|
242
254
|
return ctx.markBlocks && ctx.source && ctx.pathRoot != null && key.startsWith(ctx.pathRoot + "-") && !UNMARKED.has(node.type)
|
|
243
255
|
? markBlock(out, ctx.source, key.slice(ctx.pathRoot.length + 1), key)
|
|
244
256
|
: out;
|
|
245
257
|
}
|
|
258
|
+
const emptyAttr = (v) => v === undefined || v === null || v === "" || (Array.isArray(v) && !v.length);
|
|
246
259
|
/** Nút không chọn riêng được trong khung soạn (hoặc bọc thêm thẻ sẽ sai cấu trúc HTML: li trong ul, ô trong bảng). */
|
|
247
260
|
const UNMARKED = new Set(["text", "hardBreak", "listItem", "taskItem", "tableRow", "tableCell", "tableHeader"]);
|
|
248
261
|
/** Gắn vị trí khối: thẻ HTML thì thêm thuộc tính, component thì bọc thẻ display:contents (không đổi bố cục). */
|
|
@@ -431,6 +444,15 @@ async function renderNodeInner(node, key, ctx) {
|
|
|
431
444
|
: check || kind === "radio" ? null
|
|
432
445
|
: _jsx("input", { type: types[kind] ?? "text", maxLength: kind === "number" || kind === "date" ? undefined : 500, autoComplete: { name: "name", email: "email", phone: "tel" }[name] ?? (kind === "email" ? "email" : kind === "tel" ? "tel" : undefined), ...common }), a.help ? _jsx("span", { className: "ecx-field-help", id: `${id}-help`, children: String(a.help) }) : null, _jsx("span", { className: "ecx-field-error", id: `${id}-error`, "aria-live": "polite" })] }, key));
|
|
433
446
|
}
|
|
447
|
+
case "iconBox":
|
|
448
|
+
case "imageBox":
|
|
449
|
+
case "iconList":
|
|
450
|
+
case "counter":
|
|
451
|
+
case "testimonial":
|
|
452
|
+
case "progressBar": {
|
|
453
|
+
const tree = widgetMarkup(node.type, a);
|
|
454
|
+
return tree ? widgetEl(tree, key) : null;
|
|
455
|
+
}
|
|
434
456
|
case "rating": {
|
|
435
457
|
const max = Math.min(10, Math.max(1, Math.round(Number(a.max) || 5)));
|
|
436
458
|
const v = Math.min(max, Math.max(0, Number(a.value) || 0));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-theme-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.1",
|
|
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.23.1",
|
|
37
37
|
"intl-messageformat": "12.1.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
package/dist/icons.d.ts
DELETED
package/dist/icons.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** Tập icon cố định cho khối `icon` (24×24, nét 2, lucide). Chỉ nhận tên trong bảng này — không nhận SVG tuỳ ý (chống XSS). */
|
|
2
|
-
export const ICON_PATHS = {
|
|
3
|
-
check: "M20 6 9 17l-5-5",
|
|
4
|
-
x: "M18 6 6 18M6 6l12 12",
|
|
5
|
-
star: "M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z",
|
|
6
|
-
heart: "M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",
|
|
7
|
-
arrowRight: "M5 12h14M12 5l7 7-7 7",
|
|
8
|
-
phone: "M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z",
|
|
9
|
-
mail: "M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zM22 6l-10 7L2 6",
|
|
10
|
-
mapPin: "M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0zM12 7a3 3 0 1 0 0 6 3 3 0 0 0 0-6z",
|
|
11
|
-
clock: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM12 6v6l4 2",
|
|
12
|
-
info: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM12 16v-4M12 8h.01",
|
|
13
|
-
alert: "M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0zM12 9v4M12 17h.01",
|
|
14
|
-
externalLink: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14 21 3",
|
|
15
|
-
};
|