@ecomcx/ecomweb-theme-sdk 1.43.0 → 2.0.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 +1546 -0
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/api.d.ts +86 -14
- package/dist/api.js +84 -19
- 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 +26 -5
- package/dist/client.js +62 -12
- package/dist/components.d.ts +17 -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 +5 -5
- package/dist/i18n.d.ts +4 -0
- package/dist/i18n.js +4 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +10 -5
- package/dist/rich.d.ts +2 -0
- package/dist/rich.js +61 -26
- 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
package/API.md
ADDED
|
@@ -0,0 +1,1546 @@
|
|
|
1
|
+
# API của @ecomcx/ecomweb-theme-sdk
|
|
2
|
+
|
|
3
|
+
Sinh tự động từ mã nguồn (`node scripts/api-docs.mjs`), không sửa tay. Hướng dẫn: `docs/theme-guide.md` của core.
|
|
4
|
+
|
|
5
|
+
## `@ecomcx/ecomweb-theme-sdk`
|
|
6
|
+
|
|
7
|
+
### Component
|
|
8
|
+
|
|
9
|
+
#### `ChangePasswordForm`
|
|
10
|
+
|
|
11
|
+
Đổi mật khẩu của thành viên đang đăng nhập (core ≥ 1.20.0); các thiết bị khác bị đăng xuất.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
ChangePasswordForm({ labels }: { labels?: Partial<AuthLabels>; }): JSX.Element
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
#### `CommentForm`
|
|
18
|
+
|
|
19
|
+
fields: ô thêm của plugin (captcha…) — Comments của SDK truyền <Slot name="comment_form.fields" />. Ô name="extra.*" gửi kèm trong "extra".
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
CommentForm({ postId, parentId, labels, fields }: { postId: number; parentId?: number; labels?: Partial<CommentLabels>; fields?: ReactNode; }): JSX.Element
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
#### `CommentList`
|
|
26
|
+
|
|
27
|
+
Danh sách bình luận lồng nhau (render được cả ở server lẫn client).
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
CommentList({ comments, site, avatarSize, showDate }: { comments: Comment[]; site: DateSite; avatarSize?: number; showDate?: boolean; }): JSX.Element
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### `Comments`
|
|
34
|
+
|
|
35
|
+
Khu bình luận đầy đủ: danh sách đã duyệt (phân trang + "Xem thêm"), form gửi, ảnh đại diện — tương đương `comments_template`. Tự ẩn với bài có mật khẩu chưa mở khoá. Tự dựng theo ý mình: {@link getComments}, `<CommentList>`, `<CommentForm>`.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
Comments({ post, title, perPage, order, avatarSize, showDate }: { post: Post; title?: string; perPage?: number; order?: "asc" | "desc"; avatarSize?: number; showDate?: boolean; }): Promise<JSX.Element | null>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### `CommentsMore`
|
|
42
|
+
|
|
43
|
+
Nút "Xem thêm bình luận": tải các trang tiếp theo qua /api/cms/comments.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
CommentsMore({ postId, totalPages, site, labels, perPage, order, avatarSize, showDate }: { postId: number; totalPages: number; site: DateSite; labels: { more: string; loading: string; error: string; }; perPage?: number; order?: "asc" | "desc"; avatarSize?: number; showDate?: boolean; }): JSX.Element
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### `DeleteAccountForm`
|
|
50
|
+
|
|
51
|
+
Thành viên tự xoá tài khoản (core ≥ 1.20.0): nhập lại mật khẩu và đánh dấu xác nhận. Tài khoản quản trị không xoá được ở đây. Xong thì đăng xuất và chuyển về <paramref name="redirectTo"/>.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
DeleteAccountForm({ labels, redirectTo }: { labels?: Partial<AuthLabels>; redirectTo?: string; }): JSX.Element
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### `EditableRegion`
|
|
58
|
+
|
|
59
|
+
Vùng của theme: header, footer (vùng chuẩn của core — nên luôn bọc) và vùng hybrid khai báo ở theme.json › regions. Thứ tự: plugin thay vùng (definePlugin → regions) → bản sửa trong Trình dựng / `parts/{name}.json` → `children` (bản code của theme). `<EditableRegion name="header" data={data}><Header /></EditableRegion>`
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
EditableRegion({ name, data, className, children }: { name: string; data?: ResolveResult; className?: string; children?: ReactNode; }): Promise<JSX.Element>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### `FeaturedImage`
|
|
66
|
+
|
|
67
|
+
`label`: tên của link khi ảnh chưa có alt (thường là tiêu đề bài) — không có thì trình đọc màn hình chỉ đọc "liên kết".
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
FeaturedImage({ media, size, className, link, label, sizes, priority }: { media?: Media | null; size?: string; className?: string; link?: string; label?: string; sizes?: string; priority?: boolean; }): JSX.Element | null
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### `ForgotPasswordForm`
|
|
74
|
+
|
|
75
|
+
Gửi email đặt lại mật khẩu (liên kết trỏ về /reset-password của website).
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
ForgotPasswordForm({ labels, paths, fields }: { labels?: Partial<AuthLabels>; paths?: Partial<AuthPaths>; fields?: ReactNode; }): JSX.Element
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### `Img`
|
|
82
|
+
|
|
83
|
+
Ảnh responsive: <picture> với WebP + ảnh gốc, srcset nhiều cỡ, width/height chống nhảy layout, object-position theo điểm lấy nét chọn trong thư viện media.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
Img({ media, size, sizes, className, alt, priority, style }: ImgProps): JSX.Element | null
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### `LanguageSwitcher`
|
|
90
|
+
|
|
91
|
+
Nút chuyển ngôn ngữ. Đặt ở layout của theme. Ẩn khi site chỉ có một ngôn ngữ. Liên kết tới đúng bản dịch của trang hiện tại (đọc thẻ hreflang), không có thì về trang chủ ngôn ngữ đó.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
LanguageSwitcher({ className, variant }: { className?: string; variant?: "list" | "select"; }): Promise<JSX.Element | null>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### `Link`
|
|
98
|
+
|
|
99
|
+
Link chuyển trang không tải lại (bọc `next/link`); link ngoài, file, RSS tự dùng `<a>` thường. `activeClassName` gắn class khi URL hiện tại khớp (`matchNested`: khớp cả trang con). Prefetch mặc định tắt.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
Link({ href, prefetch, activeClassName, matchNested, className, children, ...rest }: LinkProps): JSX.Element
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### `LoginForm`
|
|
106
|
+
|
|
107
|
+
fields: ô thêm của plugin (captcha…), thường là <Slot name="auth.login.fields" /> — template có sẵn của SDK tự truyền.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
LoginForm({ redirectTo, labels, links, paths, fields }: { redirectTo?: string; labels?: Partial<AuthLabels>; links?: boolean; paths?: Partial<AuthPaths>; fields?: ReactNode; }): JSX.Element
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### `LoginOutLink`
|
|
114
|
+
|
|
115
|
+
Liên kết "Đăng nhập" / nút "Đăng xuất" theo phiên; kiểm ở client nên trang vẫn cache được. Đang tải → chưa hiện gì.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
LoginOutLink({ loginHref, loginText, logoutText, className }: { loginHref: string; loginText: string; logoutText: string; className?: string; }): JSX.Element
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### `LogoutButton`
|
|
122
|
+
|
|
123
|
+
Nút đăng xuất: thu hồi phiên ở CMS, xoá cookie rồi chuyển về <paramref name="redirectTo"/>.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
LogoutButton({ redirectTo, className, children }: { redirectTo?: string; className?: string; children?: ReactNode; }): JSX.Element
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### `Menu`
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
Menu({ location, menuId, currentPath, className, fallback }: { location?: string; menuId?: number; currentPath?: string; className?: string; fallback?: ReactNode; }): Promise<JSX.Element>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### `NavToggle`
|
|
136
|
+
|
|
137
|
+
Nút ☰ của menu trên điện thoại: <details> gốc + Escape đóng menu và trả focus về nút.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
NavToggle({ label, children, className }: { label: string; children: ReactNode; className?: string; }): JSX.Element
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### `Pagination`
|
|
144
|
+
|
|
145
|
+
`pageParam`: phân trang bằng tham số URL (?qpage=2) thay cho /page/2 — dùng cho khối Query nằm trong trang, không phải trang lưu trữ.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
Pagination({ data, prevLabel, nextLabel, pageParam, type, midSize }: { data: ResolveResult; prevLabel?: string; nextLabel?: string; pageParam?: string; type?: "numbers" | "prevNext" | "both"; midSize?: number; }): Promise<JSX.Element | null>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### `PluginForm`
|
|
152
|
+
|
|
153
|
+
Form tự sinh cho bảng EF của plugin có [PublicCreate] (form liên hệ, đặt lịch, đăng ký…): <PluginForm plugin="lien-he" table="messages" /> — hoặc shortcode [cms-form plugin="lien-he" table="messages"] Ô nhập, nhãn, ràng buộc lấy từ kiểu dữ liệu C# của plugin; máy chủ kiểm tra lại và giới hạn số lần gửi. Class CSS: cms-form, cms-form-field, cms-form-{kiểu}, form-error, form-success.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
PluginForm({ plugin, table, submitLabel, className }: { plugin: string; table: string; submitLabel?: string; className?: string; }): Promise<JSX.Element | null>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### `PostContent`
|
|
160
|
+
|
|
161
|
+
Render nội dung bài viết (định dạng của CMS —
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
PostContent({ post, content, className, page }: { post?: Post | null; content?: PostContentDoc | null; className?: string; page?: number; }): Promise<JSX.Element | null>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### `PostDate`
|
|
168
|
+
|
|
169
|
+
Ngày đăng của bài trong thẻ `<time datetime>`, định dạng theo Cài đặt › Chung (xem {@link formatDate}) — tương đương `the_date`. Không truyền `site` thì tự đọc cấu hình của website (`getSite()`, có cache).
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
PostDate({ post, site }: { post: Post; site?: { dateFormat: string; timezone: string; locale?: string; }; }): Promise<JSX.Element>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### `PostPasswordForm`
|
|
176
|
+
|
|
177
|
+
Form mật khẩu của bài được bảo vệ. Đúng mật khẩu → cookie httpOnly, tải lại nội dung trang.
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
PostPasswordForm({ postId, labels }: { postId: number; labels: { intro: string; label: string; submit: string; wrong: string; }; }): JSX.Element
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### `ProfileForm`
|
|
184
|
+
|
|
185
|
+
Sửa hồ sơ của thành viên đang đăng nhập (core ≥ 1.20.0): tên hiển thị, giới thiệu, email. Đổi email cần mật khẩu hiện tại. Đặt trong trang tài khoản của theme (vd template "account"); khách chưa đăng nhập thấy lời nhắn.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
ProfileForm({ labels, fields, onSaved }: { labels?: Partial<AuthLabels>; fields?: ReactNode; onSaved?(user: CurrentUser): void; }): JSX.Element | null
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### `RegisterForm`
|
|
192
|
+
|
|
193
|
+
Đăng ký thành viên (chỉ khi quản trị viên bật "Ai cũng có thể đăng ký"). Vai trò = vai trò mặc định trong Cài đặt.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
RegisterForm({ labels, links, paths, fields }: { labels?: Partial<AuthLabels>; links?: boolean; paths?: Partial<AuthPaths>; fields?: ReactNode; }): JSX.Element
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### `ResetPasswordForm`
|
|
200
|
+
|
|
201
|
+
Đặt mật khẩu mới từ liên kết trong email (?token=…).
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
ResetPasswordForm({ labels, paths }: { labels?: Partial<AuthLabels>; paths?: Partial<AuthPaths>; }): JSX.Element
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### `SearchForm`
|
|
208
|
+
|
|
209
|
+
Ô tìm kiếm — gửi về trang chủ của ngôn ngữ hiện tại (/?s= hoặc /en?s=).
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
SearchForm({ defaultValue, placeholder, buttonLabel, postType, showLabel, buttonPosition, buttonIcon }: { buttonIcon?: boolean; defaultValue?: string | null; placeholder?: string; buttonLabel?: string; postType?: string; showLabel?: boolean; buttonPosition?: "right" | "left" | "below"; }): Promise<JSX.Element>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### `Slot`
|
|
216
|
+
|
|
217
|
+
Điểm cho plugin chèn nội dung (vd `before.content`, `body.end`) — tương đương `do_action` trong template. Mỗi plugin được bọc riêng: plugin lỗi thì phần đó ẩn, trang vẫn hiện.
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
Slot<P = any>({ name, data, props, fallback, className, }: { name: SlotName; data?: ResolveResult | null; props?: P; fallback?: ReactNode; className?: string; }): Promise<JSX.Element>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### `TermLinks`
|
|
224
|
+
|
|
225
|
+
Danh sách link term (chuyên mục, thẻ), phân tách bằng `separator` — tương đương `the_category` / `the_tags`.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
TermLinks({ terms, separator }: { terms?: Array<{ id: number; name: string; link: string; }>; separator?: string; }): JSX.Element | null
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
<TermLinks terms={post.terms.category} />
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### `WidgetArea`
|
|
236
|
+
|
|
237
|
+
Vẽ các widget của một khu vực (`theme.json › widgetAreas`) — tương đương `dynamic_sidebar`. Khu vực trống → không vẽ gì.
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
WidgetArea({ id, className }: { id: string; className?: string; }): Promise<JSX.Element | null>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Hàm
|
|
244
|
+
|
|
245
|
+
#### `applyFilters`
|
|
246
|
+
|
|
247
|
+
Chạy filter của các plugin/theme đang bật theo thứ tự, bỏ qua filter bị lỗi.
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
applyFilters<K extends keyof FilterMap>(name: K, value: Parameters<NonNullable<FilterMap[K]>>[0], ctx?: Parameters<NonNullable<FilterMap[K]>>[1], site?: Site): Promise<Parameters<NonNullable<FilterMap[K]>>[0]>
|
|
251
|
+
applyFilters<T = any>(name: string, value: T, ctx?: any, site?: Site): Promise<T>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### `buildDocumentMetadata`
|
|
255
|
+
|
|
256
|
+
Metadata mặc định cho trang + cho plugin (vd SEO) sửa qua filter "document.metadata".
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
buildDocumentMetadata(data: ResolveResult, site: Site): Promise<DocumentMetadata>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### `cmsFetch`
|
|
263
|
+
|
|
264
|
+
Gọi thẳng một endpoint của Public API (`/api/public/...`) khi SDK chưa có hàm riêng — lối thoát có cam kết cho theme / plugin. Ưu tiên các hàm `get*`. Lỗi → ném `CmsApiError` (`status` = mã HTTP). Kết quả được cache và gắn tag "cms" để revalidate khi nội dung thay đổi.
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
cmsFetch<T>(path: string, opts?: FetchOptions): Promise<T>
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
#### `consentDefault`
|
|
271
|
+
|
|
272
|
+
(Server) Mặc định của site khi khách CHƯA chọn — filter "consent.default", không có plugin banner → true. 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).
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
consentDefault(category: ConsentCategory): Promise<boolean>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
#### `cx`
|
|
279
|
+
|
|
280
|
+
Ghép class CSS, bỏ giá trị rỗng / false (như `clsx`).
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
cx(...classes: Array<string | false | null | undefined>): string
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
```tsx
|
|
287
|
+
cx("card", active && "is-active")
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
#### `defineBlock`
|
|
291
|
+
|
|
292
|
+
Khai báo một khối — dùng chung cho trình soạn (admin) và website: cùng một file định nghĩa, import ở cả hai phía. Chỉ là dữ liệu (không phụ thuộc trình soạn nào): trình soạn tự sinh node + form cài đặt + mục slash menu, website chuẩn hoá thuộc tính rồi đưa cho component hiển thị của plugin. Khối của plugin đã tắt: dữ liệu giữ nguyên.
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
defineBlock(input: BlockDefinitionInput): BlockDefinition
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
#### `definePlugin`
|
|
299
|
+
|
|
300
|
+
Dùng trong file entry của plugin/theme: export default definePlugin({...}).
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
definePlugin(def: PluginDefinition): PluginDefinition
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
#### `doAction`
|
|
307
|
+
|
|
308
|
+
Phát action tới các plugin/theme đang bật.
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
doAction(name: string, arg?: any, site?: Site): Promise<void>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
#### `formatDate`
|
|
315
|
+
|
|
316
|
+
Định dạng một ngày theo cấu hình ngày của website (Cài đặt › Chung: `site.dateFormat`, `site.timezone`) — tương đương `date_i18n`. Token: `yyyy`, `MMMM` (tên tháng theo `site.locale`), `MM`, `dd`, `d`. Luôn truyền `site` (có trong `TemplateProps`): thiếu thì dùng `dd/MM/yyyy` + `Asia/Ho_Chi_Minh`, không theo cấu hình admin. Giá trị rỗng → `""`. Chạy được ở server và client.
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
formatDate(value: string | null | undefined, site?: Pick<Site, "dateFormat" | "timezone"> & { locale?: string; }): string
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
```tsx
|
|
323
|
+
formatDate(post.publishedAt, site) // "16/11/2026"
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
#### `getAdjacentPost` · từ 1.44.0
|
|
327
|
+
|
|
328
|
+
Bài liền trước (`"prev"`, đăng sớm hơn) hoặc liền sau (`"next"`) cùng loại nội dung (tương đương `get_adjacent_post`). `query` lọc thêm, vd cùng chuyên mục: `{ taxQuery: [{ taxonomy: "category", terms: [slug] }] }`. Không có → `null`.
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
getAdjacentPost(post: Pick<Post, "id" | "type" | "publishedAt">, direction: "prev" | "next", query?: Omit<PostQuery, "after" | "before" | "orderBy" | "order" | "perPage" | "page" | "offset">): Promise<Post | null>
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
```tsx
|
|
335
|
+
const [prev, next] = await Promise.all([getAdjacentPost(post, "prev"), getAdjacentPost(post, "next")]);
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### `getArchives`
|
|
339
|
+
|
|
340
|
+
Số bài theo tháng, mới nhất trước, kèm link trang lưu trữ (tương đương `wp_get_archives`).
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
getArchives(locale?: string): Promise<{ year: number; month: number; count: number; link: string; }[]>
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
#### `getAuthors`
|
|
347
|
+
|
|
348
|
+
Danh sách tác giả công khai (trang "Đội ngũ", danh bạ): mặc định thành viên có bài đã đăng; plugin mở rộng qua filter authors.query. Chỉ có tên, slug, ảnh, tiểu sử, meta công khai — không bao giờ có email.
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
getAuthors({ params, ...q }?: AuthorQuery): Promise<ListPage<Author>>
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
#### `getClientMessages`
|
|
355
|
+
|
|
356
|
+
Lấy các chuỗi cần cho component client (core ≥ 1.20.0) — chỉ khoá bắt đầu bằng một trong <paramref name="prefixes"/> (vd ["cart.", "auth."]) để không gửi cả từ điển xuống trình duyệt. Truyền kết quả vào <TranslationsProvider value={…}>.
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
getClientMessages(prefixes: string[]): Promise<ClientMessages>
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
#### `getComments`
|
|
363
|
+
|
|
364
|
+
Bình luận đã duyệt của một bài, theo trang → `{ items, total, count, page, totalPages }` (tương đương `get_comments`). Bài có mật khẩu: CMS chỉ trả bình luận khi có `unlock`.
|
|
365
|
+
|
|
366
|
+
```ts
|
|
367
|
+
getComments(postId: number, query?: CommentQuery): Promise<CommentPage>
|
|
368
|
+
/** @deprecated */ getComments(postId: number, page: number, unlock?: string, opts?: { perPage?: number; order?: "asc" | "desc"; }): Promise<CommentPage>
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
> Chữ ký cũ: Từ 2.0: dùng `getComments(postId, { page, unlock, perPage, order })`. Dạng tham số vị trí bị bỏ ở 3.0.
|
|
372
|
+
|
|
373
|
+
```tsx
|
|
374
|
+
const { items } = await getComments(post.id, { page: 2 });
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
#### `getCurrentUser`
|
|
378
|
+
|
|
379
|
+
Người đang đăng nhập trên website, null nếu là khách. Dùng trong Server Component, route, generateMetadata. Component client: dùng useCurrentUser() hoặc nhận qua props.
|
|
380
|
+
|
|
381
|
+
```ts
|
|
382
|
+
getCurrentUser(): Promise<CurrentUser | null>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### `getFacets`
|
|
386
|
+
|
|
387
|
+
Đếm số bài theo từng giá trị (bộ lọc có số đếm: "Khoa CNTT (12)") trên đúng tập bài mà {@link getPosts} trả về với cùng điều kiện. `facets`: tên phân loại công khai ("category") và/hoặc `"meta:khoá"` (khoá khai báo `filterable`). Tối đa 5 facet × 100 giá trị, đếm trong PostgreSQL.
|
|
388
|
+
|
|
389
|
+
```ts
|
|
390
|
+
getFacets(facets: string[], query?: Omit<PostQuery, "page" | "perPage" | "withContent" | "orderBy" | "order" | "orderByMeta">): Promise<FacetResult>
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
```tsx
|
|
394
|
+
const { facets } = await getFacets(["khoa", "meta:hoc-ky"], { type: "khoa-hoc", taxQuery })
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
#### `getLanguages`
|
|
398
|
+
|
|
399
|
+
Ngôn ngữ đang bật của website và ngôn ngữ mặc định.
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
getLanguages(): Promise<{ defaultLocale: string; languages: Array<{ code: string; name: string; isDefault: boolean; flag?: string; }>; }>
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
#### `getMedia`
|
|
406
|
+
|
|
407
|
+
Danh sách media (thư viện ảnh, tài liệu tải về) — plugin giới hạn / mở rộng qua filter media.query.
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
getMedia({ params, ...q }?: MediaQuery): Promise<ListPage<Media>>
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
#### `getMenu`
|
|
414
|
+
|
|
415
|
+
Menu gắn ở một vị trí của theme (`theme.json › menuLocations`), ngôn ngữ của request (tương đương `wp_get_nav_menu_items` theo location). Chưa gắn menu → `null`. Vẽ sẵn: `<Menu location="primary" />`.
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
getMenu(location: string, locale?: string): Promise<Menu | null>
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
#### `getMenuById`
|
|
422
|
+
|
|
423
|
+
Menu theo id (khối Điều hướng chọn menu cụ thể). Không có → `null`.
|
|
424
|
+
|
|
425
|
+
```ts
|
|
426
|
+
getMenuById(id: number): Promise<Menu | null>
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
#### `getPattern`
|
|
430
|
+
|
|
431
|
+
Nội dung mẫu đồng bộ (khối syncedPattern). Mẫu đã xoá / chưa xuất bản → `null`; CMS lỗi → ném `CmsApiError`.
|
|
432
|
+
|
|
433
|
+
```ts
|
|
434
|
+
getPattern(id: number): Promise<PostContentDoc | null>
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
#### `getPlugin`
|
|
438
|
+
|
|
439
|
+
Hàm mà plugin đang bật công bố qua definePlugin({ exports }). null nếu plugin chưa cài/chưa bật — luôn kiểm tra: const shop = await getPlugin<ShopApi>("shop"); if (shop) cart = await shop.getCart(); Chỉ dùng phía server (Server Component, route, generateMetadata). Component client nhận dữ liệu qua props.
|
|
440
|
+
|
|
441
|
+
```ts
|
|
442
|
+
getPlugin<T = Record<string, unknown>>(slug: string, site?: Site): Promise<T | null>
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
#### `getPost`
|
|
446
|
+
|
|
447
|
+
Bài đã đăng theo loại nội dung + slug, ngôn ngữ của request hiện tại (tương đương `get_page_by_path`). Không có / chưa đăng → `null`. CMS lỗi → ném `CmsApiError`.
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
getPost(type: string, slug: string, locale?: string): Promise<Post | null>
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
```tsx
|
|
454
|
+
const about = await getPost("page", "gioi-thieu");
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
#### `getPostById` · từ 1.31.0
|
|
458
|
+
|
|
459
|
+
Bài đã đăng theo id (tương đương `get_post($id)`). Không có / chưa đăng → `null`. CMS lỗi → ném `CmsApiError`.
|
|
460
|
+
|
|
461
|
+
```ts
|
|
462
|
+
getPostById(id: number): Promise<Post | null>
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
#### `getPostIds` · từ 1.44.0
|
|
466
|
+
|
|
467
|
+
Chỉ lấy id bài (tương đương `WP_Query` với `fields => 'ids'`): cùng điều kiện như {@link getPosts}, máy chủ không dựng đối tượng bài.
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
getPostIds({ withContent: _w, ...q }?: PostQuery): Promise<{ items: number[]; total: number; page: number; totalPages: number; }>
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
#### `getPosts`
|
|
474
|
+
|
|
475
|
+
Danh sách bài đã đăng theo điều kiện (tương đương `WP_Query`). Mặc định không kèm nội dung đầy đủ (`withContent`). Trả `{ items, total, page, totalPages }`; `noTotal: true` bỏ bước đếm tổng.
|
|
476
|
+
|
|
477
|
+
```ts
|
|
478
|
+
getPosts({ withContent, ...q }?: PostQuery): Promise<{ items: Post[]; total: number; page: number; totalPages: number; }>
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
```tsx
|
|
482
|
+
const { items } = await getPosts({ type: "post", taxQuery: [{ taxonomy: "category", terms: ["tin-tuc"] }], perPage: 6 });
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
#### `getPreference`
|
|
486
|
+
|
|
487
|
+
Đọc tuỳ chọn ở Server Component (layout/template).
|
|
488
|
+
|
|
489
|
+
```ts
|
|
490
|
+
getPreference(key: string): Promise<string | undefined>
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### `getRequestLocale`
|
|
494
|
+
|
|
495
|
+
Ngôn ngữ của request hiện tại (undefined = ngôn ngữ mặc định của site).
|
|
496
|
+
|
|
497
|
+
```ts
|
|
498
|
+
getRequestLocale(): Promise<string | undefined>
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
#### `getSite`
|
|
502
|
+
|
|
503
|
+
Thông tin site theo ngôn ngữ của request (hoặc locale truyền vào).
|
|
504
|
+
|
|
505
|
+
```ts
|
|
506
|
+
getSite(locale?: string): Promise<Site>
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
#### `getT`
|
|
510
|
+
|
|
511
|
+
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 `__()`.
|
|
512
|
+
|
|
513
|
+
```ts
|
|
514
|
+
getT(): Promise<Translator>
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
```tsx
|
|
518
|
+
const t = await getT(); t("readMore"); t("comments.count", { count: 3 })
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
#### `getTerms`
|
|
522
|
+
|
|
523
|
+
Mọi term của một phân loại (không phân trang), ngôn ngữ của request (tương đương `get_terms`). `hideEmpty` mặc định `true` = bỏ term chưa có bài. Cần lọc / phân trang / sắp xếp → {@link queryTerms}.
|
|
524
|
+
|
|
525
|
+
```ts
|
|
526
|
+
getTerms(query: { taxonomy: string; hideEmpty?: boolean; locale?: string; }): Promise<Term[]>
|
|
527
|
+
/** @deprecated */ getTerms(taxonomy: string, hideEmpty?: boolean, locale?: string): Promise<Term[]>
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
> Chữ ký cũ: Từ 2.0: dùng `getTerms({ taxonomy, hideEmpty, locale })`. Dạng tham số vị trí bị bỏ ở 3.0.
|
|
531
|
+
|
|
532
|
+
```tsx
|
|
533
|
+
const cats = await getTerms({ taxonomy: "category" });
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
#### `getThemeSettings`
|
|
537
|
+
|
|
538
|
+
Lấy giá trị Customizer của theme đang active.
|
|
539
|
+
|
|
540
|
+
```ts
|
|
541
|
+
getThemeSettings(): Promise<JsonObject>
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
#### `getWidgets`
|
|
545
|
+
|
|
546
|
+
Widget trong một khu vực (`theme.json › widgetAreas`), theo thứ tự. Vẽ sẵn: `<WidgetArea id="sidebar" />`.
|
|
547
|
+
|
|
548
|
+
```ts
|
|
549
|
+
getWidgets(area: string, locale?: string): Promise<WidgetInstance[]>
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
#### `hasPlugin`
|
|
553
|
+
|
|
554
|
+
Plugin có đang bật không.
|
|
555
|
+
|
|
556
|
+
```ts
|
|
557
|
+
hasPlugin(slug: string, site?: Site): Promise<boolean>
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
#### `imageCandidates`
|
|
561
|
+
|
|
562
|
+
Các cỡ ảnh dùng cho srcset: cỡ được chọn + mọi cỡ cùng tỉ lệ (không bị cắt) nhỏ hơn, để trình duyệt tự chọn file vừa đủ cho màn hình.
|
|
563
|
+
|
|
564
|
+
```ts
|
|
565
|
+
imageCandidates(media: Media, size?: string): MediaSize[]
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
#### `is404`
|
|
569
|
+
|
|
570
|
+
Trang không tìm thấy — `is_404`.
|
|
571
|
+
|
|
572
|
+
```ts
|
|
573
|
+
is404(data: Page): boolean
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
#### `isArchive`
|
|
577
|
+
|
|
578
|
+
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`.
|
|
579
|
+
|
|
580
|
+
```ts
|
|
581
|
+
isArchive(data: Page): boolean
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
#### `isAuthor`
|
|
585
|
+
|
|
586
|
+
Trang tác giả — `is_author`.
|
|
587
|
+
|
|
588
|
+
```ts
|
|
589
|
+
isAuthor(data: Page): boolean
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
#### `isCategory`
|
|
593
|
+
|
|
594
|
+
Trang chuyên mục; `slug` để kiểm tra chuyên mục cụ thể — `is_category`.
|
|
595
|
+
|
|
596
|
+
```ts
|
|
597
|
+
isCategory(data: Page, slug?: string): boolean
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
#### `isDate`
|
|
601
|
+
|
|
602
|
+
Trang lưu trữ theo ngày — `is_date`.
|
|
603
|
+
|
|
604
|
+
```ts
|
|
605
|
+
isDate(data: Page): boolean
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
#### `isFrontPage`
|
|
609
|
+
|
|
610
|
+
Trang chủ của website, dạng bài mới hoặc trang tĩnh — `is_front_page`.
|
|
611
|
+
|
|
612
|
+
```ts
|
|
613
|
+
isFrontPage(data: Page): boolean
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
#### `isHome`
|
|
617
|
+
|
|
618
|
+
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).
|
|
619
|
+
|
|
620
|
+
```ts
|
|
621
|
+
isHome(data: Page): boolean
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
#### `isInternalHref`
|
|
625
|
+
|
|
626
|
+
`true` nếu link là trang của website (chuyển trang không tải lại); file, feed, API, link ngoài → `false`.
|
|
627
|
+
|
|
628
|
+
```ts
|
|
629
|
+
isInternalHref(href: string): boolean
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
#### `isPage`
|
|
633
|
+
|
|
634
|
+
Trang tĩnh; `slug` để kiểm tra trang cụ thể, vd `isPage(data, "lien-he")` — `is_page`.
|
|
635
|
+
|
|
636
|
+
```ts
|
|
637
|
+
isPage(data: Page, slug?: string): boolean
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
#### `isSearch`
|
|
641
|
+
|
|
642
|
+
Trang kết quả tìm kiếm — `is_search`.
|
|
643
|
+
|
|
644
|
+
```ts
|
|
645
|
+
isSearch(data: Page): boolean
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
#### `isSingle`
|
|
649
|
+
|
|
650
|
+
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)`.
|
|
651
|
+
|
|
652
|
+
```ts
|
|
653
|
+
isSingle(data: Page, type?: string): boolean
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
#### `isSingular`
|
|
657
|
+
|
|
658
|
+
Bài hoặc trang tĩnh (có `data.post`) — `is_singular`.
|
|
659
|
+
|
|
660
|
+
```ts
|
|
661
|
+
isSingular(data: Page): boolean
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
#### `isTag`
|
|
665
|
+
|
|
666
|
+
Trang thẻ; `slug` để kiểm tra thẻ cụ thể — `is_tag`.
|
|
667
|
+
|
|
668
|
+
```ts
|
|
669
|
+
isTag(data: Page, slug?: string): boolean
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
#### `isTax`
|
|
673
|
+
|
|
674
|
+
Trang của phân loại tuỳ biến; `taxonomy` để kiểm tra phân loại cụ thể — `is_tax`.
|
|
675
|
+
|
|
676
|
+
```ts
|
|
677
|
+
isTax(data: Page, taxonomy?: string): boolean
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
#### `localeHref`
|
|
681
|
+
|
|
682
|
+
Đường dẫn có tiền tố ngôn ngữ: localeHref(site, "/author/an") → "/en/author/an" khi đang ở tiếng Anh.
|
|
683
|
+
|
|
684
|
+
```ts
|
|
685
|
+
localeHref(site: { locale: string; defaultLocale: string; }, path: string): string
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
#### `pageLink`
|
|
689
|
+
|
|
690
|
+
Đường dẫn trang thứ `page` của một danh sách (`/tin-tuc/page/2`), giữ từ khoá tìm kiếm nếu có. Trang 1 → đường dẫn gốc. Danh sách có bộ lọc khác → {@link pageLinkWithQuery}.
|
|
691
|
+
|
|
692
|
+
```ts
|
|
693
|
+
pageLink(basePath: string, page: number, search?: string | null): string
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
#### `pageLinkWithQuery`
|
|
697
|
+
|
|
698
|
+
Link của một trang trong danh sách CÓ bộ lọc: giữ nguyên mọi tham số truy vấn hiện có (phòng ban, mức lương, từ khoá…) và chỉ đổi số trang. Truyền `data.query` của trang vào. <Link href={pageLinkWithQuery(data.basePath, 2, data.query)}>2</Link>
|
|
699
|
+
|
|
700
|
+
```ts
|
|
701
|
+
pageLinkWithQuery(basePath: string, page: number, query?: Record<string, string> | null): string
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
#### `pluginFetch`
|
|
705
|
+
|
|
706
|
+
Gọi endpoint public của plugin khi render trên server: pluginFetch("ecomcx-seo", "/sitemap/news"). Cache theo tag "cms" (+ tags) như dữ liệu khác của CMS; noStore để luôn lấy mới. asUser: gửi kèm phiên của người đang xem (endpoint nhận ICurrentUser) — luôn không cache: pluginFetch("shop", "/cart", { asUser: true }).
|
|
707
|
+
|
|
708
|
+
```ts
|
|
709
|
+
pluginFetch<T>(slug: string, path: string, opts?: FetchOptions): Promise<T>
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
#### `queryTerms`
|
|
713
|
+
|
|
714
|
+
Danh sách term có phân trang, lọc theo cha / từ khoá / meta, sắp xếp — bản đầy đủ của {@link getTerms}.
|
|
715
|
+
|
|
716
|
+
```ts
|
|
717
|
+
queryTerms({ params, ...q }: TermQuery): Promise<ListPage<Term>>
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
#### `requestUnlock`
|
|
721
|
+
|
|
722
|
+
Cookie mở khoá bài có mật khẩu của request hiện tại (server component); ngoài request → undefined.
|
|
723
|
+
|
|
724
|
+
```ts
|
|
725
|
+
requestUnlock(): Promise<string | undefined>
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
#### `requireUser`
|
|
729
|
+
|
|
730
|
+
Bắt buộc đăng nhập: khách bị chuyển tới /login, đăng nhập xong quay lại <paramref name="returnTo"/>. const user = await requireUser("/account");
|
|
731
|
+
|
|
732
|
+
```ts
|
|
733
|
+
requireUser(returnTo?: string): Promise<CurrentUser>
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
#### `safeRedirect`
|
|
737
|
+
|
|
738
|
+
Chỉ nhận đường dẫn nội bộ ("/account") — chặn chuyển hướng ra trang ngoài (?redirect=https://lừa-đảo). Trình duyệt bỏ tab / xuống dòng và coi "\" như "/" khi phân tích URL, nên "/<TAB>/evil.com" hay "/\evil.com" thành "//evil.com": chặn mọi ký tự điều khiển và dấu "\" ở bất kỳ vị trí nào, không chỉ ở đầu.
|
|
739
|
+
|
|
740
|
+
```ts
|
|
741
|
+
safeRedirect(target: string | null | undefined, fallback?: string): string
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
#### `setting`
|
|
745
|
+
|
|
746
|
+
Đọc một giá trị Tuỳ biến của theme (`theme.json › settings`) từ `settings` của `TemplateProps` / `LayoutProps`, kèm giá trị dự phòng (tương đương `get_theme_mod`). Rỗng / chưa đặt → `fallback`. Không gọi mạng.
|
|
747
|
+
|
|
748
|
+
```ts
|
|
749
|
+
setting<T = string>(settings: Record<string, unknown>, key: string, fallback: T): T
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
```tsx
|
|
753
|
+
setting(settings, "showComments", true)
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
#### `useCurrentUser`
|
|
757
|
+
|
|
758
|
+
Người đang đăng nhập, dùng trong component client (null = khách, undefined = đang tải). Server Component nên dùng getCurrentUser() để khỏi tốn thêm một request.
|
|
759
|
+
|
|
760
|
+
```ts
|
|
761
|
+
useCurrentUser(): CurrentUser | null | undefined
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
#### `userCan`
|
|
765
|
+
|
|
766
|
+
Người dùng có quyền này không — current_user_can().
|
|
767
|
+
|
|
768
|
+
```ts
|
|
769
|
+
userCan(user: CurrentUser | null | undefined, capability: string): boolean
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
### Class
|
|
773
|
+
|
|
774
|
+
#### `CmsApiError`
|
|
775
|
+
|
|
776
|
+
Lỗi khi gọi Public API của CMS. `status` = mã HTTP (0 = lỗi mạng / hết thời gian chờ).
|
|
777
|
+
|
|
778
|
+
```ts
|
|
779
|
+
class CmsApiError
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
#### `ExtensionBoundary`
|
|
783
|
+
|
|
784
|
+
```ts
|
|
785
|
+
class ExtensionBoundary
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
### Hằng
|
|
789
|
+
|
|
790
|
+
#### `AUTH_LABELS`
|
|
791
|
+
|
|
792
|
+
```ts
|
|
793
|
+
const AUTH_LABELS: { login: string; password: string; submitLogin: string; code: string; verify: string; userName: string; email: string; displayName: string; submitRegister: string; submitForgot: string; newPassword: string; submitReset: string; sending: string; error: string; logout: string; noAccount: string; register: string; forgot: string; haveAccount: string; login2: string; registerClosed: string; missingToken: string; bio: string; currentPassword: string; currentPasswordForEmail: string; submitProfile: string; submitPassword: string; notSignedIn: string; deleteWarning: string; deleteConfirm: string; submitDelete: string; }
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
#### `AUTH_PATHS`
|
|
797
|
+
|
|
798
|
+
```ts
|
|
799
|
+
const AUTH_PATHS: AuthPaths
|
|
800
|
+
```
|
|
801
|
+
|
|
802
|
+
#### `BINDABLE`
|
|
803
|
+
|
|
804
|
+
Thuộc tính gắn được của khối lõi: tên trong bindings → nơi đặt giá trị.
|
|
805
|
+
|
|
806
|
+
```ts
|
|
807
|
+
const BINDABLE: Record<string, readonly string[]>
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
#### `BUILTIN_PAGE_TEMPLATES`
|
|
811
|
+
|
|
812
|
+
Tên template trang có sẵn (theme có template cùng tên thì dùng của theme).
|
|
813
|
+
|
|
814
|
+
```ts
|
|
815
|
+
const BUILTIN_PAGE_TEMPLATES: readonly ["canvas", "full-width", "landing"]
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
#### `BUILTIN_STRINGS`
|
|
819
|
+
|
|
820
|
+
Chữ mặc định của các component trong SDK (theme có thể ghi đè trong locales/{code}.json).
|
|
821
|
+
|
|
822
|
+
```ts
|
|
823
|
+
const BUILTIN_STRINGS: Record<string, Record<string, string>>
|
|
824
|
+
```
|
|
825
|
+
|
|
826
|
+
#### `CONSENT_CATEGORIES`
|
|
827
|
+
|
|
828
|
+
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 (analytics, pixel, widget chat, video nhúng…). Core không có banner, không chọn optin/optout thay ai — chỉ là API. 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). Bên hỏi (trình duyệt): hasConsent("statistics") / getConsent() từ "@ecomcx/ecomweb-theme-sdk/client"; on("consent.changed", …) để nạp script khi khách vừa cho phép. 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): <meta name="cms-consent" content="optin"> trong <head> (trình duyệt đọc) và filter "consent.default" (server, vd quyết định có in <noscript> theo dõi hay không). Chưa có plugin banner → mọi nhóm được phép (website chạy như trước).
|
|
829
|
+
|
|
830
|
+
```ts
|
|
831
|
+
const CONSENT_CATEGORIES: readonly ["functional", "preferences", "statistics", "statistics-anonymous", "marketing"]
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
#### `CONSENT_META`
|
|
835
|
+
|
|
836
|
+
<meta name="cms-consent" content="optin|optout">: plugin banner khai mặc định cho trình duyệt.
|
|
837
|
+
|
|
838
|
+
```ts
|
|
839
|
+
const CONSENT_META: "cms-consent"
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
#### `CORE_BINDING_SOURCES`
|
|
843
|
+
|
|
844
|
+
```ts
|
|
845
|
+
const CORE_BINDING_SOURCES: Record<string, BindingSource>
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
#### `LOCALE_HEADER`
|
|
849
|
+
|
|
850
|
+
Header do proxy.ts của frontend gắn vào request: mã ngôn ngữ lấy từ tiền tố URL (/en/...).
|
|
851
|
+
|
|
852
|
+
```ts
|
|
853
|
+
const LOCALE_HEADER: "x-cms-locale"
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
### Kiểu
|
|
857
|
+
|
|
858
|
+
#### `AuthLabels`
|
|
859
|
+
|
|
860
|
+
```ts
|
|
861
|
+
type AuthLabels = typeof AUTH_LABELS;
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
#### `Author`
|
|
865
|
+
|
|
866
|
+
```ts
|
|
867
|
+
interface Author { id: number; name: string; slug: string; avatarUrl?: string | null; bio?: string | null; /** Meta công khai của thành viên (plugin khai báo `UserMeta` Public), vd `{ khoa: "cntt" }`. */ meta?: JsonObject; /** Số bài đã đăng — chỉ có trong danh sách {@link getAuthors}. */ postCount?: number | null; /** Dữ liệu plugin thêm qua filter api.author.response. */ extra?: JsonObject; }
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
#### `AuthorQuery`
|
|
871
|
+
|
|
872
|
+
```ts
|
|
873
|
+
interface AuthorQuery { locale?: string; /** Tìm theo tên hiển thị, không phân biệt dấu. */ search?: string; include?: number[]; exclude?: number[]; /** Lọc theo meta công khai (khoá khai báo `UserMeta` Public), vd metaKey "khoa". Khoá không công khai → 422. */ metaKey?: string; metaValue?: string; orderBy?: "name" | "post_count" | "id"; order?: "asc" | "desc"; /** perPage 1–100 (mặc định 20). */ page?: number; perPage?: number; /** Tham số thêm cho plugin (filter authors.query), vd plugin danh bạ thêm vai trò "giang-vien". */ params?: Record<string, string>; }
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
#### `AuthPaths`
|
|
877
|
+
|
|
878
|
+
Đường dẫn các trang tài khoản. Website nhiều ngôn ngữ truyền bản có tiền tố (localeHref(site, "/login") → "/en/login"); template có sẵn của SDK tự truyền.
|
|
879
|
+
|
|
880
|
+
```ts
|
|
881
|
+
interface AuthPaths { login: string; register: string; forgotPassword: string; home: string }
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
#### `BindingContext`
|
|
885
|
+
|
|
886
|
+
Gắn dữ liệu (@ecomcx/ecomweb-content 1.15 — `attrs.bindings`): thuộc tính của khối lấy giá trị lúc hiển thị. Nguồn lõi: core/post (trường của bài đang vẽ / bài trong vòng lặp), core/post-meta (trường meta), core/site. Plugin thêm nguồn: definePlugin({ bindingSources: { "shop/product": async (args, ctx) => … } }).
|
|
887
|
+
|
|
888
|
+
```ts
|
|
889
|
+
interface BindingContext { site: Site; post?: Post | null; data?: ResolveResult | null }
|
|
890
|
+
```
|
|
891
|
+
|
|
892
|
+
#### `BindingSource`
|
|
893
|
+
|
|
894
|
+
```ts
|
|
895
|
+
type BindingSource = (args: Record<string, string | number | boolean>, ctx: BindingContext) => unknown | Promise<unknown>;
|
|
896
|
+
```
|
|
897
|
+
|
|
898
|
+
#### `Block`
|
|
899
|
+
|
|
900
|
+
Khối cấp cao nhất. - `richtext`: `data` là cây {@link RichNode} gốc `type: "doc"` (nội dung soạn bằng trình soạn). - `html`: `data.html` là HTML (nội dung nhập từ hệ thống cũ). - tên khác: khối của plugin, `data` do plugin định nghĩa. Plugin không có/đã tắt → giữ nguyên dữ liệu, website bỏ qua.
|
|
901
|
+
|
|
902
|
+
```ts
|
|
903
|
+
interface Block { id?: string; type: string; data: any; }
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
#### `BlockAsset`
|
|
907
|
+
|
|
908
|
+
Asset nạp theo nhu cầu: `src` trong website ("/extensions/…") hoặc https.
|
|
909
|
+
|
|
910
|
+
```ts
|
|
911
|
+
interface BlockAsset { kind: "script" | "style"; src: string; /** 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-"). */ when: { blocks?: string[]; className?: string }; }
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
#### `BlockAttrSpec`
|
|
915
|
+
|
|
916
|
+
```ts
|
|
917
|
+
interface BlockAttrSpec extends AttrSpec { /** Nhãn trong form cài đặt (chữ hoặc "%khoá%" dịch theo locales của plugin). */ label?: string; control?: AttrControl; /** Nhãn cho từng giá trị của enum (cùng thứ tự). */ enumLabels?: readonly string[]; help?: string; }
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
#### `BlockDefinition`
|
|
921
|
+
|
|
922
|
+
```ts
|
|
923
|
+
interface BlockDefinition extends Required<Pick<BlockDefinitionInput, "name" | "title" | "content" | "version">> { description?: string; icon?: string; keywords: string; category?: string; attributes: Record<string, BlockAttrSpec>; migrate: Record<number, (attrs: Record<string, unknown>) => Record<string, unknown>>; placeholder?: BlockPlaceholder; }
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
#### `BlockDefinitionInput`
|
|
927
|
+
|
|
928
|
+
```ts
|
|
929
|
+
interface BlockDefinitionInput { /** Tên khối, duy nhất trong mọi plugin — nên đặt tiền tố plugin: "ten-plugin/callout" hoặc "tenPluginCallout". */ name: string; /** Tên hiển thị (slash menu, khung khối). */ title: string; description?: string; /** Biểu tượng (tên icon lucide, vd "star") — trình soạn hiển thị nếu có. */ icon?: string; /** Từ khoá tìm trong slash menu (không dấu, cách nhau bởi khoảng trắng). */ keywords?: string; category?: string; content?: BlockContent; attributes?: Record<string, BlockAttrSpec>; /** * Phiên bản cấu trúc thuộc tính (mặc định 1). Đổi cấu trúc → tăng version +
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
#### `BlockProps`
|
|
933
|
+
|
|
934
|
+
Renderer khối của plugin. Dùng cho cả khối cấp cao nhất (`data` = dữ liệu khối) và nút trong nội dung soạn thảo (`data` = thuộc tính của nút, `children` = nội dung bên trong đã vẽ — vd hộp lưu ý chứa đoạn văn).
|
|
935
|
+
|
|
936
|
+
```ts
|
|
937
|
+
interface BlockProps<D = any> { block: Block; data: D; site: Site; post?: Post | null; children?: ReactNode }
|
|
938
|
+
```
|
|
939
|
+
|
|
940
|
+
#### `ClientMessages`
|
|
941
|
+
|
|
942
|
+
Chuỗi đã chọn đúng ngôn ngữ để truyền xuống trình duyệt (<TranslationsProvider>).
|
|
943
|
+
|
|
944
|
+
```ts
|
|
945
|
+
interface ClientMessages { locale: string; messages: Record<string, { code: string; text: string }> }
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
#### `Comment`
|
|
949
|
+
|
|
950
|
+
```ts
|
|
951
|
+
interface Comment { id: number; postId: number; parentId?: number | null; authorName: string; authorUrl?: string | null; content: string; status: string; createdAt: string; replies: Comment[]; /** Ảnh đại diện (ảnh của thành viên hoặc Gravatar); null khi site tắt hiển thị avatar. */ avatarUrl?: string | null; }
|
|
952
|
+
```
|
|
953
|
+
|
|
954
|
+
#### `CommentPage`
|
|
955
|
+
|
|
956
|
+
Một trang bình luận gốc (kèm trả lời). total = số bình luận gốc, count = tổng kể cả trả lời.
|
|
957
|
+
|
|
958
|
+
```ts
|
|
959
|
+
interface CommentPage { items: Comment[]; total: number; count: number; page: number; totalPages: number }
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
#### `CommentQuery`
|
|
963
|
+
|
|
964
|
+
Tham số của {@link getComments}. Bỏ trống = theo Cài đặt › Thảo luận.
|
|
965
|
+
|
|
966
|
+
```ts
|
|
967
|
+
interface CommentQuery { page?: number; perPage?: number; order?: "asc" | "desc"; /** Bài có mật khẩu: token mở khoá (giá trị cookie, xem {@link requestUnlock}). Có thì không cache. */ unlock?: string; }
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
#### `ConsentCategory`
|
|
971
|
+
|
|
972
|
+
```ts
|
|
973
|
+
type ConsentCategory = (typeof CONSENT_CATEGORIES)[number];
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
#### `CoreSlotName`
|
|
977
|
+
|
|
978
|
+
Slot chuẩn. Core: head, body.start, body.end, footer. Theme: before.content, after.content. Component của SDK: comments.before / comments.after (khu bình luận), comment_form.fields (ô thêm trong form bình luận), auth.login.fields, auth.register.fields, auth.forgot_password.fields (ô thêm trong form tài khoản, vd captcha). Ô thêm có name="extra.*" được gửi kèm trong "extra" — backend đọc ở action auth.attempt / filter comment.data.
|
|
979
|
+
|
|
980
|
+
```ts
|
|
981
|
+
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" /** Ô thêm trong mọi form (core + plugin theo hợp đồng chung, CMS ≥ 1.29): props { form, settings }; ô name="extra.*" → hook form.submitting. */ | "form.fields";
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
#### `CurrentUser`
|
|
985
|
+
|
|
986
|
+
Người dùng đang đăng nhập trên website.
|
|
987
|
+
|
|
988
|
+
```ts
|
|
989
|
+
interface CurrentUser { id: number; email: string; userName: string; displayName: string; roles: string[]; capabilities: string[]; /** Giới thiệu (core ≥ 1.20.0). */ bio?: string | null; }
|
|
990
|
+
```
|
|
991
|
+
|
|
992
|
+
#### `DocumentMetadata`
|
|
993
|
+
|
|
994
|
+
```ts
|
|
995
|
+
interface DocumentMetadata { title: string; description?: string; canonical?: string; /** Bản dịch của trang: { vi: "/chao-mung", en: "/en/welcome" } → thẻ hreflang. */ alternates?: Record<string, string>; robots?: string; openGraph?: { title?: string; description?: string; image?: string; type?: string; url?: string; /** Nhiều ảnh kèm kích thước (ưu tiên hơn `image`). */ images?: Array<{ url: string; width?: number; height?: number; alt?: string }>; siteName?: string; locale?: string; /** Bài viết (type = article). */ publishedTime?: string; modifiedTime?: string; section?: string; tags?: str
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
#### `FacetResult`
|
|
999
|
+
|
|
1000
|
+
```ts
|
|
1001
|
+
interface FacetResult { total: number; facets: Record<string, FacetValue[]> }
|
|
1002
|
+
```
|
|
1003
|
+
|
|
1004
|
+
#### `FacetValue`
|
|
1005
|
+
|
|
1006
|
+
Một giá trị facet: slug term (facet phân loại) hoặc giá trị meta, kèm số bài.
|
|
1007
|
+
|
|
1008
|
+
```ts
|
|
1009
|
+
interface FacetValue { value: string; count: number; termId?: number | null; name?: string | null; parentId?: number | null }
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
#### `FetchOptions`
|
|
1013
|
+
|
|
1014
|
+
```ts
|
|
1015
|
+
interface FetchOptions { tags?: string[]; noStore?: boolean; revalidate?: number; query?: Record<string, unknown>; headers?: Record<string, string>; asUser?: boolean; /** * Chiều biến thiên cache (core ≥ 1.22.0) mà plugin đang bật khai báo trong plugin.json › cacheVary: `{ device: "mobile", "flag:ab": "b" }`. * CMS gộp vào khoá cache công khai, mỗi giá trị một bản; chiều chưa ai khai báo bị bỏ qua. Danh sách chiều: GET /api/public/cache-vary. * Đọc header / cookie để biết giá trị sẽ khiến trang thành động — chỉ làm khi plugin thật sự cần. */ vary?: Record<string, string>; }
|
|
1016
|
+
```
|
|
1017
|
+
|
|
1018
|
+
#### `FilterMap`
|
|
1019
|
+
|
|
1020
|
+
```ts
|
|
1021
|
+
interface FilterMap { /** Sửa metadata của trang (title, description, og…). */ "document.metadata": (meta: DocumentMetadata, ctx: { site: Site; data: ResolveResult }) => DocumentMetadata | Promise<DocumentMetadata>; /** Sửa danh sách block trước khi render nội dung bài viết. */ "post.blocks": (blocks: Block[], ctx: { site: Site; post?: Post | null }) => Block[] | Promise<Block[]>; /** Sửa nội dung robots.txt (văn bản). */ "robots.txt": (content: string, ctx: { site: Site }) => string | Promise<string>; /** Sửa danh sách URL của sitemap.xml. */ "sitemap.entries": (entries: SitemapEntry[], ctx:
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
#### `ImgProps`
|
|
1025
|
+
|
|
1026
|
+
```ts
|
|
1027
|
+
interface ImgProps { media?: Media | null; /** Cỡ lớn nhất cần dùng: thumbnail, medium, medium_large, large, 1536x1536, 2048x2048 hoặc cỡ theme tự khai báo. */ size?: string; /** Thuộc tính sizes của HTML, vd "(max-width: 768px) 100vw, 50vw". Mặc định: rộng tối đa bằng cỡ ảnh. */ sizes?: string; className?: string; alt?: string; /** Ảnh đầu trang (LCP): tải ngay, ưu tiên cao. */ priority?: boolean; style?: CSSProperties; }
|
|
1028
|
+
```
|
|
1029
|
+
|
|
1030
|
+
#### `JsonObject`
|
|
1031
|
+
|
|
1032
|
+
```ts
|
|
1033
|
+
type JsonObject = { [k: string]: JsonValue };
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
#### `JsonValue`
|
|
1037
|
+
|
|
1038
|
+
```ts
|
|
1039
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | { [k: string]: JsonValue };
|
|
1040
|
+
```
|
|
1041
|
+
|
|
1042
|
+
#### `Language`
|
|
1043
|
+
|
|
1044
|
+
```ts
|
|
1045
|
+
interface Language { code: string; name: string; isDefault: boolean; flag?: string | null }
|
|
1046
|
+
```
|
|
1047
|
+
|
|
1048
|
+
#### `LayoutProps`
|
|
1049
|
+
|
|
1050
|
+
```ts
|
|
1051
|
+
interface LayoutProps { site: Site; settings: JsonObject; children: ReactNode; /** Trang đang xem — truyền cho <EditableRegion data={data}> để vùng (và plugin thay vùng) biết trang nào. */ data?: ResolveResult; }
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
#### `LinkProps`
|
|
1055
|
+
|
|
1056
|
+
```ts
|
|
1057
|
+
type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href"> & { href: string; children?: ReactNode; /** * Prefetch của Next.js. Mặc định false: mọi trang của CMS là trang động, mỗi lần prefetch là một lần render trên server * (trang chủ báo có thể có cả trăm link). Bật cho vài link quan trọng nếu muốn chuyển trang tức thì. */ prefetch?: boolean | null; /** Đặt aria-current và class này khi URL hiện tại khớp href (dùng cho menu). */ activeClassName?: string; /** Khớp cả trang con (vd /category/a/page/2 vẫn active cho /category/a). Mặc định true, trừ trang chủ. */ matchNested?: boolea
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
#### `ListPage`
|
|
1061
|
+
|
|
1062
|
+
Một trang của danh sách công khai (term, tác giả, media).
|
|
1063
|
+
|
|
1064
|
+
```ts
|
|
1065
|
+
interface ListPage<T> { items: T[]; total: number; page: number; totalPages: number }
|
|
1066
|
+
```
|
|
1067
|
+
|
|
1068
|
+
#### `Media`
|
|
1069
|
+
|
|
1070
|
+
```ts
|
|
1071
|
+
interface Media { id: number; url: string; fileName: string; mimeType: string; size: number; width?: number | null; height?: number | null; alt: string; caption: string; sizes: Record<string, MediaSize>; /** Bản WebP của ảnh gốc. */ webpUrl?: string | null; /** Điểm lấy nét 0–1 (object-position). */ focalX?: number | null; focalY?: number | null; title?: string; createdAt?: string; }
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
#### `MediaQuery`
|
|
1075
|
+
|
|
1076
|
+
```ts
|
|
1077
|
+
interface MediaQuery { /** Tìm theo tiêu đề, alt, chú thích, tên file — không phân biệt dấu. */ search?: string; /** Tiền tố kiểu file: "image/", "video/", "application/pdf". */ mime?: string; folder?: number; include?: number[]; exclude?: number[]; orderBy?: "date" | "title" | "id" | "size"; order?: "asc" | "desc"; /** perPage 1–100 (mặc định 20). */ page?: number; perPage?: number; /** Tham số thêm cho plugin (filter media.query). */ params?: Record<string, string>; }
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
#### `MediaSize`
|
|
1081
|
+
|
|
1082
|
+
```ts
|
|
1083
|
+
interface MediaSize { url: string; width: number; height: number; webpUrl?: string | null }
|
|
1084
|
+
```
|
|
1085
|
+
|
|
1086
|
+
#### `MenuItem`
|
|
1087
|
+
|
|
1088
|
+
```ts
|
|
1089
|
+
interface MenuItem { id: number; parentId?: number | null; title: string; url: string; kind: string; objectId?: number | null; target?: string | null; cssClass?: string | null; order: number; children: MenuItem[]; }
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
#### `MetaQuery`
|
|
1093
|
+
|
|
1094
|
+
```ts
|
|
1095
|
+
interface MetaQuery { /** Mặc định "AND". */ relation?: "AND" | "OR"; clauses: MetaQueryClause[]; }
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
#### `MetaQueryClause`
|
|
1099
|
+
|
|
1100
|
+
Một điều kiện lọc theo trường tuỳ biến (post.meta). Giá trị so sánh phải đúng kiểu JSON (số là số). So bằng (`=`, `!=`, `IN`, `NOT IN`, `EXISTS`, `NOT EXISTS`) chạy trên chỉ mục GIN sẵn có — dùng được với mọi khoá meta. So khoảng (`>`, `>=`, `<`, `<=`, `BETWEEN`, `LIKE`) **chỉ dùng được với khoá đã khai báo `filterable`** (backend tạo chỉ mục B-tree cho khoá đó lúc khởi động); khoá chưa khai báo trả 422. Với khoá kiểu số, giá trị phải là số JSON (chuỗi số cũng được, core tự chuyển) — nếu không phép so sẽ so chuỗi ("100" < "20").
|
|
1101
|
+
|
|
1102
|
+
```ts
|
|
1103
|
+
interface MetaQueryClause { key: string; compare: "=" | "!=" | "IN" | "NOT IN" | "EXISTS" | "NOT EXISTS" | ">" | ">=" | "<" | "<=" | "BETWEEN" | "LIKE"; /** Bỏ trống với EXISTS / NOT EXISTS. Với LIKE: mẫu có `%` / `_`. */ value?: string | number | boolean | (string | number | boolean)[]; /** Cận trên của BETWEEN (bắt buộc với BETWEEN). */ value2?: string | number; }
|
|
1104
|
+
```
|
|
1105
|
+
|
|
1106
|
+
#### `PluginDefinition`
|
|
1107
|
+
|
|
1108
|
+
```ts
|
|
1109
|
+
interface PluginDefinition { /** [contact-form id="1"] trong nội dung → component. */ shortcodes?: Record<string, ComponentType<ShortcodeProps>>; /** Renderer cho loại widget đã khai báo ở backend (IWidgetRegistry). */ widgets?: Record<string, ComponentType<WidgetProps>>; /** Chèn component vào vị trí cố định của trang (hỗ trợ tên tự do, ưu tiên priority). */ slots?: Record<string, SlotRegistration<any>>; /** * Thay cả một vùng của theme (header, footer hoặc vùng theme khai báo): { header: MyHeader }. * Nhiều plugin cùng thay một vùng → priority nhỏ nhất thắng (mặc định 10; bằng nhau thì plugi
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
#### `PluginFormField`
|
|
1113
|
+
|
|
1114
|
+
```ts
|
|
1115
|
+
interface PluginFormField { key: string; type: string; label: string; required: boolean; maxLength?: number | null; minLength?: number | null; min?: string | null; max?: string | null; options?: string[] | null; pattern?: string | null; default?: unknown; }
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
#### `PluginLoader`
|
|
1119
|
+
|
|
1120
|
+
```ts
|
|
1121
|
+
type PluginLoader = Loader<PluginDefinition>;
|
|
1122
|
+
```
|
|
1123
|
+
|
|
1124
|
+
#### `PluginRoute`
|
|
1125
|
+
|
|
1126
|
+
Route gốc do plugin cung cấp (vd /news-sitemap.xml): nhận Request, trả Response. Khai báo đường dẫn trong plugin.json → frontend.routes.
|
|
1127
|
+
|
|
1128
|
+
```ts
|
|
1129
|
+
type PluginRoute = (req: Request, ctx: { site: Site; path: string }) => Response | Promise<Response>;
|
|
1130
|
+
```
|
|
1131
|
+
|
|
1132
|
+
#### `Post`
|
|
1133
|
+
|
|
1134
|
+
```ts
|
|
1135
|
+
interface Post { id: number; type: string; title: string; slug: string; status: string; /** Mã ngôn ngữ của bài, vd "vi". */ locale: string; /** Bản dịch đã đăng ở ngôn ngữ khác. */ translations: TranslationRef[]; content?: PostContentDoc | null; excerpt: string; authorId?: number | null; author?: Author | null; parentId?: number | null; menuOrder: number; template?: string | null; featuredMedia?: Media | null; commentStatus: string; commentCount: number; /** Bài ghim / nổi bật. */ sticky: boolean; /** Bài có mật khẩu: chưa mở khoá thì content = null, excerpt rỗng — PostContent tự hiện form nh
|
|
1136
|
+
```
|
|
1137
|
+
|
|
1138
|
+
#### `PostContentDoc`
|
|
1139
|
+
|
|
1140
|
+
Nội dung một bài viết / trang: danh sách khối cấp cao nhất.
|
|
1141
|
+
|
|
1142
|
+
```ts
|
|
1143
|
+
interface ContentDoc { version: number; blocks: Block[]; }
|
|
1144
|
+
```
|
|
1145
|
+
|
|
1146
|
+
#### `PostQuery`
|
|
1147
|
+
|
|
1148
|
+
```ts
|
|
1149
|
+
interface PostQuery { /** Mặc định: ngôn ngữ của request hiện tại. */ locale?: string; type?: string; taxonomy?: string; term?: string; authorId?: number; search?: string; /** Lọc nhiều post type cùng lúc (bài viết + trang + job...). Gộp với `type`. */ types?: string[]; /** Lọc nhiều taxonomy cùng lúc — thay cho taxonomy/term khi cần AND/OR nhiều điều kiện. */ taxQuery?: TaxQueryClause[]; /** Lọc theo trường tuỳ biến; chạy trong cơ sở dữ liệu trên chỉ mục GIN của posts.meta. */ metaQuery?: MetaQuery; /** Chỉ lấy bài thuộc ngữ cảnh này (plugin tự lọc thêm qua filter posts.query). */ context?: s
|
|
1150
|
+
```
|
|
1151
|
+
|
|
1152
|
+
#### `RegionName`
|
|
1153
|
+
|
|
1154
|
+
Vùng chuẩn của core: theme bọc đầu trang / chân trang trong <EditableRegion name="header|footer"> (theme khối: khối templatePart cùng slug) → plugin thay được bằng definePlugin({ regions }) với mọi theme.
|
|
1155
|
+
|
|
1156
|
+
```ts
|
|
1157
|
+
type RegionName = "header" | "footer" | (string & {});
|
|
1158
|
+
```
|
|
1159
|
+
|
|
1160
|
+
#### `RegionProps`
|
|
1161
|
+
|
|
1162
|
+
Component thay vùng của plugin. `children` = bản vùng sẽ vẽ nếu không có plugin (Trình dựng / theme) — trả lại `children` để giữ nguyên.
|
|
1163
|
+
|
|
1164
|
+
```ts
|
|
1165
|
+
interface RegionProps { name: string; site: Site; data?: ResolveResult | null; children?: ReactNode }
|
|
1166
|
+
```
|
|
1167
|
+
|
|
1168
|
+
#### `ResolveKind`
|
|
1169
|
+
|
|
1170
|
+
```ts
|
|
1171
|
+
type ResolveKind = | "front-page" | "home" | "single" | "page" | "category" | "tag" | "taxonomy" | "author" | "date" | "archive" | "search" | "route" | "404" | "redirect";
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
#### `ResolveResult`
|
|
1175
|
+
|
|
1176
|
+
```ts
|
|
1177
|
+
interface ResolveResult { kind: ResolveKind; templates: string[]; title: string; locale: string; /** Trang tương ứng ở các ngôn ngữ (dùng cho hreflang, nút chuyển ngôn ngữ). */ alternates: Array<{ locale: string; link: string }>; post?: Post | null; posts?: Post[] | null; term?: Term | null; author?: Author | null; postType?: string | null; search?: string | null; page: number; totalPages: number; total: number; basePath: string; redirect?: { location: string; statusCode: number } | null; isPreview?: boolean; /** Trang ảo (kind = "route") do core/plugin đăng ký: /login, /account/orders/12 → {
|
|
1178
|
+
```
|
|
1179
|
+
|
|
1180
|
+
#### `RichMark`
|
|
1181
|
+
|
|
1182
|
+
```ts
|
|
1183
|
+
interface RichMark { type: string; attrs?: Record<string, unknown>; }
|
|
1184
|
+
```
|
|
1185
|
+
|
|
1186
|
+
#### `RichNode`
|
|
1187
|
+
|
|
1188
|
+
Nút trong nội dung soạn thảo: khối (đoạn, tiêu đề, ảnh…) hoặc chữ (`type: "text"`).
|
|
1189
|
+
|
|
1190
|
+
```ts
|
|
1191
|
+
interface RichNode { type: string; attrs?: Record<string, unknown>; content?: RichNode[]; /** Chỉ có ở `type: "text"`, không rỗng. */ text?: string; /** Định dạng chữ (đậm, liên kết…), chỉ có ở `type: "text"`. */ marks?: RichMark[]; }
|
|
1192
|
+
```
|
|
1193
|
+
|
|
1194
|
+
#### `ShortcodeProps`
|
|
1195
|
+
|
|
1196
|
+
```ts
|
|
1197
|
+
interface ShortcodeProps { attrs: Record<string, string>; content?: string; site: Site; post?: Post | null }
|
|
1198
|
+
```
|
|
1199
|
+
|
|
1200
|
+
#### `SignInProvider`
|
|
1201
|
+
|
|
1202
|
+
Nút "Đăng nhập bằng …" của plugin (ISignInProvider, core ≥ 1.20.0). Core cũ không trả providers → không có nút.
|
|
1203
|
+
|
|
1204
|
+
```ts
|
|
1205
|
+
interface SignInProvider { id: string; label: string; iconUrl?: string | null; url: string }
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
#### `Site`
|
|
1209
|
+
|
|
1210
|
+
```ts
|
|
1211
|
+
interface Site { title: string; tagline: string; url: string; language: string; timezone: string; dateFormat: string; /** Ngôn ngữ của request hiện tại. */ locale: string; defaultLocale: string; languages: Language[]; postsPerPage: number; showOnFront: "posts" | "page"; pageOnFront?: number | null; pageForPosts?: number | null; activeTheme: string; themeSettings: JsonObject; activePlugins: string[]; menuLocations: Record<string, number>; extra: JsonObject; /** Preset kiểu dáng đã gộp (theme.json › styles + bản sửa trong Giao diện › Kiểu dáng) — core sinh biến CSS --ecx-*. */ themeStyles?: { co
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
#### `SitemapEntry`
|
|
1215
|
+
|
|
1216
|
+
Một URL trong sitemap.xml (filter "sitemap.entries").
|
|
1217
|
+
|
|
1218
|
+
```ts
|
|
1219
|
+
interface SitemapEntry { url: string; lastModified?: string | Date; changeFrequency?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never"; priority?: number; images?: string[]; alternates?: { languages?: Record<string, string> }; }
|
|
1220
|
+
```
|
|
1221
|
+
|
|
1222
|
+
#### `SlotComponent`
|
|
1223
|
+
|
|
1224
|
+
```ts
|
|
1225
|
+
type SlotComponent<P = any> = ComponentType<P> | SlotHandler<P>;
|
|
1226
|
+
```
|
|
1227
|
+
|
|
1228
|
+
#### `SlotHandler`
|
|
1229
|
+
|
|
1230
|
+
Một handler gắn vào Slot, kèm priority (mặc định 10, số nhỏ chạy trước).
|
|
1231
|
+
|
|
1232
|
+
```ts
|
|
1233
|
+
interface SlotHandler<P = any> { component: ComponentType<P>; priority?: number; }
|
|
1234
|
+
```
|
|
1235
|
+
|
|
1236
|
+
#### `SlotName`
|
|
1237
|
+
|
|
1238
|
+
```ts
|
|
1239
|
+
type SlotName = CoreSlotName | (string & {});
|
|
1240
|
+
```
|
|
1241
|
+
|
|
1242
|
+
#### `SlotProps`
|
|
1243
|
+
|
|
1244
|
+
```ts
|
|
1245
|
+
interface SlotProps { site: Site; data?: ResolveResult | null }
|
|
1246
|
+
```
|
|
1247
|
+
|
|
1248
|
+
#### `SlotRegistration`
|
|
1249
|
+
|
|
1250
|
+
```ts
|
|
1251
|
+
type SlotRegistration<P = any> = SlotComponent<P> | Array<SlotComponent<P>>;
|
|
1252
|
+
```
|
|
1253
|
+
|
|
1254
|
+
#### `TaxQueryClause`
|
|
1255
|
+
|
|
1256
|
+
Một điều kiện lọc theo taxonomy: bài phải khớp (hoặc không khớp) các term này.
|
|
1257
|
+
|
|
1258
|
+
```ts
|
|
1259
|
+
interface TaxQueryClause { taxonomy: string; terms: string[]; /** Mặc định "IN". "NOT IN" = loại bài thuộc các term này. */ operator?: "IN" | "NOT IN"; }
|
|
1260
|
+
```
|
|
1261
|
+
|
|
1262
|
+
#### `TemplateProps`
|
|
1263
|
+
|
|
1264
|
+
Props mà mọi template của theme nhận được.
|
|
1265
|
+
|
|
1266
|
+
```ts
|
|
1267
|
+
interface TemplateProps { data: ResolveResult; site: Site; settings: JsonObject; /** Tên template đã được chọn (vd "single"). */ template: string; }
|
|
1268
|
+
```
|
|
1269
|
+
|
|
1270
|
+
#### `Term`
|
|
1271
|
+
|
|
1272
|
+
```ts
|
|
1273
|
+
interface Term { id: number; taxonomy: string; name: string; slug: string; locale: string; description: string; parentId?: number | null; count: number; link: string; meta: JsonObject; /** Dữ liệu plugin thêm vào qua filter api.term.response (vd extra.seo). */ extra?: JsonObject; }
|
|
1274
|
+
```
|
|
1275
|
+
|
|
1276
|
+
#### `TermQuery`
|
|
1277
|
+
|
|
1278
|
+
```ts
|
|
1279
|
+
interface TermQuery { taxonomy: string; locale?: string; /** Tìm theo tên, không phân biệt dấu. */ search?: string; /** Chỉ term con trực tiếp của term này; 0 = chỉ term gốc. */ parent?: number; include?: number[]; exclude?: number[]; hideEmpty?: boolean; /** Chỉ term có meta khoá này (và đúng giá trị nếu có metaValue). */ metaKey?: string; metaValue?: string; orderBy?: "name" | "slug" | "count" | "id"; order?: "asc" | "desc"; /** perPage 1–500 (mặc định 100). */ page?: number; perPage?: number; /** Tham số thêm cho plugin (filter terms.query đọc trong Query). */ params?: Record<string, string
|
|
1280
|
+
```
|
|
1281
|
+
|
|
1282
|
+
#### `ThemeEntry`
|
|
1283
|
+
|
|
1284
|
+
```ts
|
|
1285
|
+
interface ThemeEntry { manifest: ThemeManifest; layout?: Loader<ComponentType<LayoutProps>>; templates: Record<string, Loader<ComponentType<TemplateProps>>>; /** Theme cũng có thể đăng ký shortcode, widget, slot, filter. */ extend?: Loader<PluginDefinition>; /** Bản dịch chữ của theme: locales/{code}.json */ locales?: Record<string, Loader<Record<string, string>>>; }
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
#### `ThemeManifest`
|
|
1289
|
+
|
|
1290
|
+
```ts
|
|
1291
|
+
interface ThemeManifest { name: string; slug: string; version: string; author?: string; description?: string; parent?: string | null; menuLocations?: Record<string, string>; widgetAreas?: Record<string, string>; supports?: string[]; settings?: Array<{ key: string; type: string; label: string; default?: JsonValue; options?: string[]; section?: string; help?: string; /** Ô màu trùng một màu preset (`primary`, `text`, `background`…): chỉnh ở tab Phong cách, ô ẩn khỏi Cài đặt (CMS ≥ 1.23). */ preset?: string }>; /** Cỡ ảnh riêng của theme: { "card": { "width": 600, "height": 400, "crop": true } }.
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1294
|
+
#### `ThemeStyles`
|
|
1295
|
+
|
|
1296
|
+
```ts
|
|
1297
|
+
interface ThemeStyles { colors?: Record<string, ThemeStyleValue>; fontSizes?: Record<string, ThemeStyleValue>; spacing?: Record<string, ThemeStyleValue>; fonts?: Record<string, ThemeStyleValue>; gradients?: Record<string, ThemeStyleValue>; shadows?: Record<string, ThemeStyleValue>; variations?: ThemeStyleVariation[]; /** Kiểu mặc định theo loại khối / phần tử (Global Styles). */ blocks?: Record<string, unknown>; elements?: Record<string, unknown>; [group: string]: unknown; }
|
|
1298
|
+
```
|
|
1299
|
+
|
|
1300
|
+
#### `ThemeStyleValue`
|
|
1301
|
+
|
|
1302
|
+
Một giá trị preset: chuỗi, hoặc { label, value } để hiện tên trong Thiết kế.
|
|
1303
|
+
|
|
1304
|
+
```ts
|
|
1305
|
+
type ThemeStyleValue = string | { label?: string; value: string };
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
#### `ThemeStyleVariation`
|
|
1309
|
+
|
|
1310
|
+
Bộ phối sẵn của theme (CMS ≥ 1.23): bấm một lần là đổi màu / phông ở Thiết kế › Phong cách.
|
|
1311
|
+
|
|
1312
|
+
```ts
|
|
1313
|
+
interface ThemeStyleVariation { id: string; title: string; colors?: Record<string, string>; fonts?: Record<string, string> }
|
|
1314
|
+
```
|
|
1315
|
+
|
|
1316
|
+
#### `TranslationRef`
|
|
1317
|
+
|
|
1318
|
+
```ts
|
|
1319
|
+
interface TranslationRef { locale: string; id: number; title: string; status: string; link: string }
|
|
1320
|
+
```
|
|
1321
|
+
|
|
1322
|
+
#### `Translator`
|
|
1323
|
+
|
|
1324
|
+
```ts
|
|
1325
|
+
type Translator = ((key: string, vars?: Record<string, string | number>) => string) & { locale: string };
|
|
1326
|
+
```
|
|
1327
|
+
|
|
1328
|
+
#### `WidgetInstance`
|
|
1329
|
+
|
|
1330
|
+
```ts
|
|
1331
|
+
interface WidgetInstance { id: number; area: string; type: string; title: string; settings: any; order: number }
|
|
1332
|
+
```
|
|
1333
|
+
|
|
1334
|
+
#### `WidgetProps`
|
|
1335
|
+
|
|
1336
|
+
```ts
|
|
1337
|
+
interface WidgetProps<S = any> { widget: WidgetInstance; settings: S; site: Site }
|
|
1338
|
+
```
|
|
1339
|
+
|
|
1340
|
+
## `@ecomcx/ecomweb-theme-sdk/client`
|
|
1341
|
+
|
|
1342
|
+
Dùng trong file `"use client"`. Tên đã có ở entry chính (component client dùng được từ Server Component) không lặp lại ở đây.
|
|
1343
|
+
|
|
1344
|
+
### Component
|
|
1345
|
+
|
|
1346
|
+
#### `CountdownClient`
|
|
1347
|
+
|
|
1348
|
+
Khối countdown: đếm ngược tới `target` (ms). Dựng lần đầu cùng giá trị trên máy chủ, rồi cập nhật mỗi giây.
|
|
1349
|
+
|
|
1350
|
+
```ts
|
|
1351
|
+
CountdownClient({ target, label, expiredText, units, serverNow, attrs }: { target: number; label?: string; expiredText?: string; units?: Partial<Record<CountdownUnit, string>>; serverNow?: number; attrs?: Record<string, unknown>; }): JSX.Element
|
|
1352
|
+
```
|
|
1353
|
+
|
|
1354
|
+
#### `FormBlockClient`
|
|
1355
|
+
|
|
1356
|
+
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), 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.
|
|
1357
|
+
|
|
1358
|
+
```ts
|
|
1359
|
+
FormBlockClient({ formId, source, successMessage, labels, button, className, children, fields: extraUi }: { formId: string; source: string; successMessage?: string; labels: { submit: string; sending: string; error: string; }; fields?: ReactNode; button?: { className?: string; style?: CSSProperties; }; className?: string; children?: ReactNode; }): JSX.Element
|
|
1360
|
+
```
|
|
1361
|
+
|
|
1362
|
+
#### `LanguageSwitcherClient`
|
|
1363
|
+
|
|
1364
|
+
Phần client của LanguageSwitcher: lấy link bản dịch từ <link rel="alternate" hreflang> do metadata của trang sinh ra.
|
|
1365
|
+
|
|
1366
|
+
```ts
|
|
1367
|
+
LanguageSwitcherClient({ languages, current, defaultLocale, label, className, variant }: { languages: Lang[]; current: string; defaultLocale: string; label: string; className?: string; variant: "list" | "select"; }): JSX.Element
|
|
1368
|
+
```
|
|
1369
|
+
|
|
1370
|
+
#### `LightboxClient`
|
|
1371
|
+
|
|
1372
|
+
Phóng to ảnh: bấm ảnh mở lớp phủ (Esc hoặc bấm nền để đóng). `src` đã qua safeUrl ở máy chủ.
|
|
1373
|
+
|
|
1374
|
+
```ts
|
|
1375
|
+
LightboxClient({ src, alt, children }: { src: string; alt: string; children: ReactNode; }): JSX.Element
|
|
1376
|
+
```
|
|
1377
|
+
|
|
1378
|
+
#### `SearchFormClient`
|
|
1379
|
+
|
|
1380
|
+
Form tìm kiếm (GET) chuyển trang phía client.
|
|
1381
|
+
|
|
1382
|
+
```ts
|
|
1383
|
+
SearchFormClient({ action, defaultValue, placeholder, label, buttonLabel, postType, showLabel, buttonPosition, buttonIcon }: { buttonIcon?: boolean; action: string; defaultValue?: string | null; placeholder: string; label: string; buttonLabel: string; postType?: string; showLabel?: boolean; buttonPosition?: "right" | "left" | "below"; }): JSX.Element
|
|
1384
|
+
```
|
|
1385
|
+
|
|
1386
|
+
#### `TabsClient`
|
|
1387
|
+
|
|
1388
|
+
Khối tabs: các panel đã vẽ sẵn trên máy chủ (nội dung vẫn có trong HTML cho SEO); chỉ đổi panel đang hiện. Tab dọc (`vertical`), thành accordion trên điện thoại (`mobileAccordion`, chỉ CSS: tiêu đề nằm ngay trên panel của nó); tab có neo → panel mang id = neo, mở thẳng bằng #neo.
|
|
1389
|
+
|
|
1390
|
+
```ts
|
|
1391
|
+
TabsClient({ titles, panels, initial, icons, subtitles, anchors, vertical, mobileAccordion, extraClass }: { titles: string[]; panels: ReactNode[]; initial?: number; icons?: Array<string | undefined>; subtitles?: Array<string | undefined>; anchors?: Array<string | undefined>; vertical?: boolean; mobileAccordion?: boolean; extraClass?: string; }): JSX.Element
|
|
1392
|
+
```
|
|
1393
|
+
|
|
1394
|
+
#### `TocSpy`
|
|
1395
|
+
|
|
1396
|
+
Mục lục: tô đậm mục của tiêu đề đang đọc (tiêu đề cuối cùng đã cuộn qua mép trên 120px) — aria-current="location".
|
|
1397
|
+
|
|
1398
|
+
```ts
|
|
1399
|
+
TocSpy(): JSX.Element
|
|
1400
|
+
```
|
|
1401
|
+
|
|
1402
|
+
#### `TranslationsProvider`
|
|
1403
|
+
|
|
1404
|
+
Chuyển chuỗi đã dịch xuống component client. Server Component lấy bằng `getClientMessages(["cart."])` rồi bọc: <TranslationsProvider value={await getClientMessages(["cart."])}><CartButton /></TranslationsProvider> Nhiều provider lồng nhau được gộp (provider trong thắng).
|
|
1405
|
+
|
|
1406
|
+
```ts
|
|
1407
|
+
TranslationsProvider({ value, children }: { value: ClientMessages; children: ReactNode; }): JSX.Element
|
|
1408
|
+
```
|
|
1409
|
+
|
|
1410
|
+
### Hàm
|
|
1411
|
+
|
|
1412
|
+
#### `emit`
|
|
1413
|
+
|
|
1414
|
+
Phát sự kiện cho mọi component trên trang (vd plugin giỏ hàng báo "đã thêm" để mini-cart của theme cập nhật). `crossTab: true`: các tab khác của cùng website cũng nhận (BroadcastChannel).
|
|
1415
|
+
|
|
1416
|
+
```ts
|
|
1417
|
+
emit<K extends EventName>(name: K, detail?: EventData<K>, opts?: { crossTab?: boolean; }): void
|
|
1418
|
+
```
|
|
1419
|
+
|
|
1420
|
+
#### `extraFields`
|
|
1421
|
+
|
|
1422
|
+
Dữ liệu thêm của plugin (vd token captcha): mọi ô trong form có name bắt đầu bằng "extra." — gửi lên CMS trong "extra", plugin backend đọc ở action auth.attempt / filter comment.data. Plugin chèn ô qua slot (auth.login.fields, comment_form.fields…).
|
|
1423
|
+
|
|
1424
|
+
```ts
|
|
1425
|
+
extraFields(fd: FormData): Record<string, string> | undefined
|
|
1426
|
+
```
|
|
1427
|
+
|
|
1428
|
+
#### `getConsent`
|
|
1429
|
+
|
|
1430
|
+
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.
|
|
1431
|
+
|
|
1432
|
+
```ts
|
|
1433
|
+
getConsent(): ConsentCategory[] | undefined
|
|
1434
|
+
```
|
|
1435
|
+
|
|
1436
|
+
#### `hasConsent`
|
|
1437
|
+
|
|
1438
|
+
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). Chưa chọn: theo <meta name="cms-consent" content="optin"> của plugin banner; không có banner → true.
|
|
1439
|
+
|
|
1440
|
+
```ts
|
|
1441
|
+
hasConsent(category: ConsentCategory): boolean
|
|
1442
|
+
```
|
|
1443
|
+
|
|
1444
|
+
#### `on`
|
|
1445
|
+
|
|
1446
|
+
Nghe sự kiện; trả hàm huỷ. Nhận cả sự kiện từ tab khác nếu bên phát dùng crossTab.
|
|
1447
|
+
|
|
1448
|
+
```ts
|
|
1449
|
+
on<K extends EventName>(name: K, handler: (detail: EventData<K>) => void): () => void
|
|
1450
|
+
```
|
|
1451
|
+
|
|
1452
|
+
#### `onBlockReady`
|
|
1453
|
+
|
|
1454
|
+
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 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 ở `definePlugin({ readyBlocks })` — `attrs` gồm các thuộc tính liệt kê ở đó. Trả hàm huỷ đăng ký. onBlockReady("image", (img) => { const z = startZoom(img); return () => z.stop(); });
|
|
1455
|
+
|
|
1456
|
+
```ts
|
|
1457
|
+
onBlockReady(type: string, fn: BlockReadyFn): () => void
|
|
1458
|
+
```
|
|
1459
|
+
|
|
1460
|
+
#### `pluginClient`
|
|
1461
|
+
|
|
1462
|
+
Gọi endpoint của plugin từ component client — cùng endpoint với `pluginFetch` phía server, qua proxy của website (`/api/cms/plugins/{slug}/…`): gửi kèm phiên của người đang đăng nhập (ICurrentUser ở backend), chặn gọi từ trang khác. Lỗi → `PluginApiError` (status, title, errors theo trường). const shop = pluginClient("shop"); const cart = await shop.post<Cart>("/cart/items", { productId, qty: 1 });
|
|
1463
|
+
|
|
1464
|
+
```ts
|
|
1465
|
+
pluginClient(slug: string): PluginClient
|
|
1466
|
+
```
|
|
1467
|
+
|
|
1468
|
+
#### `setConsent`
|
|
1469
|
+
|
|
1470
|
+
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.
|
|
1471
|
+
|
|
1472
|
+
```ts
|
|
1473
|
+
setConsent(categories: readonly ConsentCategory[]): void
|
|
1474
|
+
```
|
|
1475
|
+
|
|
1476
|
+
#### `setPreference`
|
|
1477
|
+
|
|
1478
|
+
Ghi tuỳ chọn hiển thị của người đọc (xem getPreference). value = null để xoá.
|
|
1479
|
+
|
|
1480
|
+
```ts
|
|
1481
|
+
setPreference(key: string, value: string | null, maxAgeDays?: number): void
|
|
1482
|
+
```
|
|
1483
|
+
|
|
1484
|
+
#### `useEvent`
|
|
1485
|
+
|
|
1486
|
+
Hook React của `on`: tự huỷ khi component gỡ; handler mới nhất luôn được gọi (không cần useCallback).
|
|
1487
|
+
|
|
1488
|
+
```ts
|
|
1489
|
+
useEvent<K extends EventName>(name: K, handler: (detail: EventData<K>) => void): void
|
|
1490
|
+
```
|
|
1491
|
+
|
|
1492
|
+
#### `useT`
|
|
1493
|
+
|
|
1494
|
+
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á.
|
|
1495
|
+
|
|
1496
|
+
```ts
|
|
1497
|
+
useT(): Translator
|
|
1498
|
+
```
|
|
1499
|
+
|
|
1500
|
+
### Class
|
|
1501
|
+
|
|
1502
|
+
#### `PluginApiError`
|
|
1503
|
+
|
|
1504
|
+
Lỗi trả về từ endpoint của plugin: status HTTP, lời nhắn (title), lỗi theo từng trường (422), mã lỗi (code).
|
|
1505
|
+
|
|
1506
|
+
```ts
|
|
1507
|
+
class PluginApiError
|
|
1508
|
+
```
|
|
1509
|
+
|
|
1510
|
+
### Hằng
|
|
1511
|
+
|
|
1512
|
+
#### `browserApi`
|
|
1513
|
+
|
|
1514
|
+
Client phía trình duyệt: gọi các route proxy /api/cms/* của frontend.
|
|
1515
|
+
|
|
1516
|
+
```ts
|
|
1517
|
+
const browserApi: FetchKitInstance
|
|
1518
|
+
```
|
|
1519
|
+
|
|
1520
|
+
### Kiểu
|
|
1521
|
+
|
|
1522
|
+
#### `BlockReadyFn`
|
|
1523
|
+
|
|
1524
|
+
```ts
|
|
1525
|
+
type BlockReadyFn = (el: HTMLElement, attrs: Record<string, unknown>) => void | (() => void);
|
|
1526
|
+
```
|
|
1527
|
+
|
|
1528
|
+
#### `BrowserEvents`
|
|
1529
|
+
|
|
1530
|
+
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: declare module "@ecomcx/ecomweb-theme-sdk/client" { interface BrowserEvents { "shop.cart.changed": { count: number } } } Tên nên có tiền tố slug plugin (như hook backend).
|
|
1531
|
+
|
|
1532
|
+
```ts
|
|
1533
|
+
interface BrowserEvents { /** Khách vừa đổi lựa chọn cookie (setConsent). */ "consent.changed": { categories: ConsentCategory[] }; }
|
|
1534
|
+
```
|
|
1535
|
+
|
|
1536
|
+
#### `PluginClient`
|
|
1537
|
+
|
|
1538
|
+
```ts
|
|
1539
|
+
interface PluginClient { get<T = unknown>(path: string, opts?: PluginRequestOptions): Promise<T>; post<T = unknown>(path: string, body?: unknown, opts?: PluginRequestOptions): Promise<T>; put<T = unknown>(path: string, body?: unknown, opts?: PluginRequestOptions): Promise<T>; delete<T = unknown>(path: string, opts?: PluginRequestOptions): Promise<T>; }
|
|
1540
|
+
```
|
|
1541
|
+
|
|
1542
|
+
#### `PluginRequestOptions`
|
|
1543
|
+
|
|
1544
|
+
```ts
|
|
1545
|
+
interface PluginRequestOptions { query?: Record<string, string | number | boolean | null | undefined>; headers?: Record<string, string>; signal?: AbortSignal; }
|
|
1546
|
+
```
|