@ecomcx/ecomweb-admin-sdk 1.29.0 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +29 -0
- package/dist/index.js +38 -0
- package/dist/types.d.ts +106 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ export declare const registerDashboardWidget: (w: DashboardWidget) => void;
|
|
|
9
9
|
export declare const registerPostListColumn: (c: import("./types.js").PostListColumn) => void;
|
|
10
10
|
/** Thêm hộp vào form sửa chuyên mục/thẻ (dữ liệu lưu trong term.meta). */
|
|
11
11
|
export declare const registerTermMetaBox: (b: import("./types.js").TermMetaBox) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Thêm hộp vào trang sửa đối tượng của plugin khác (đơn hàng, mã giảm giá, dòng bảng [PluginTable] có cột [ObjectMeta]…) —
|
|
14
|
+
* giá trị đặt qua setMeta được plugin chủ lưu cùng đối tượng. CMS < 1.18.0: bỏ qua.
|
|
15
|
+
*/
|
|
16
|
+
export declare const registerObjectMetaBox: (b: import("./types.js").ObjectMetaBox) => void | undefined;
|
|
17
|
+
/** Hộp đã đăng ký cho một đối tượng (bỏ trống = tất cả). */
|
|
18
|
+
export declare const getObjectMetaBoxes: (object?: string) => import("./types.js").ObjectMetaBox[];
|
|
12
19
|
/** Lấy các MetaBox đã đăng ký trong hệ thống (tùy chọn lọc theo postType). */
|
|
13
20
|
export declare const getMetaBoxes: (postType?: string) => MetaBox[];
|
|
14
21
|
/** Hook lấy toàn bộ state plugin UI trong host. */
|
|
@@ -19,6 +26,19 @@ export declare const useApi: <T = any>(path: string | null) => {
|
|
|
19
26
|
error: Error | null;
|
|
20
27
|
reload(): void;
|
|
21
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Đường dẫn của trang plugin: tham số theo mẫu đã đăng ký, query, điều hướng (CMS ≥ 1.20.0):
|
|
31
|
+
* registerPage({ path: "/orders/:id", component: OrderPage });
|
|
32
|
+
* function OrderPage() { const { params, navigate } = useAdminRoute(); … navigate("/orders"); }
|
|
33
|
+
* CMS cũ: params rỗng, navigate tải lại trang.
|
|
34
|
+
*/
|
|
35
|
+
export declare const useAdminRoute: () => import("./types.js").AdminRoute;
|
|
36
|
+
/** Điều hướng trong admin từ bất kỳ đâu (kể cả ngoài component) — CMS < 1.20.0: tải lại trang. */
|
|
37
|
+
export declare const navigate: (to: string, opts?: {
|
|
38
|
+
replace?: boolean;
|
|
39
|
+
}) => void;
|
|
40
|
+
/** Loại trường của plugin cho form tự sinh (settings, widget) — CMS < 1.20.0: bỏ qua (form hiện ô chữ). */
|
|
41
|
+
export declare const registerFieldType: (def: import("./types.js").FieldTypeDefinition) => void | undefined;
|
|
22
42
|
export declare const can: (capability: string) => boolean;
|
|
23
43
|
/**
|
|
24
44
|
* Khối cho trình soạn nội dung, khai báo bằng defineBlock (file dùng chung với phần website của plugin):
|
|
@@ -38,6 +58,13 @@ export declare const registerBlockPanel: (panel: import("./types.js").BlockPanel
|
|
|
38
58
|
* CMS cũ (chưa có tab Mẫu) → bỏ qua, không lỗi.
|
|
39
59
|
*/
|
|
40
60
|
export declare const registerPattern: (pattern: import("./types.js").EditorPattern) => void | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Nguồn dữ liệu cho mục "Gắn dữ liệu" của trình soạn (đoạn văn, tiêu đề, ảnh, nút…):
|
|
63
|
+
* registerBindingSource({ name: "shop/product", label: "%binding.product%", fields: [{ value: "price", label: "%binding.price%" }] })
|
|
64
|
+
* Website lấy giá trị bằng definePlugin({ bindingSources: { "shop/product": (args, ctx) => … } }) của theme-sdk.
|
|
65
|
+
* CMS cũ → bỏ qua, không lỗi.
|
|
66
|
+
*/
|
|
67
|
+
export declare const registerBindingSource: (source: import("./types.js").EditorBindingSource) => void | undefined;
|
|
41
68
|
export { defineBlock, type BlockDefinition, type BlockDefinitionInput, type BlockAttrSpec } from "@ecomcx/ecomweb-content";
|
|
42
69
|
/** Thêm node/mark TipTap cho trình soạn (cấp thấp — khối thường dùng registerBlock). */
|
|
43
70
|
export declare const registerEditorExtension: (pack: import("./types.js").EditorExtensionPack) => void;
|
|
@@ -241,6 +268,8 @@ export declare const Tabs: NonNullable<import("react").ComponentType<{
|
|
|
241
268
|
}>;
|
|
242
269
|
}>>;
|
|
243
270
|
export declare const MetaBoxes: NonNullable<import("react").ComponentType<import("./types.js").MetaBoxesProps>>;
|
|
271
|
+
/** Plugin chủ vẽ chỗ cho hộp của plugin khác trong trang sửa đối tượng của mình (CMS < 1.18.0: không vẽ gì). */
|
|
272
|
+
export declare const ObjectMetaBoxes: NonNullable<import("react").ComponentType<import("./types.js").ObjectMetaBoxesProps> | undefined>;
|
|
244
273
|
export declare const Slot: NonNullable<import("react").ComponentType<{
|
|
245
274
|
name: string;
|
|
246
275
|
props?: any;
|
package/dist/index.js
CHANGED
|
@@ -9,11 +9,40 @@ export const registerDashboardWidget = (w) => host().registerDashboardWidget(w);
|
|
|
9
9
|
export const registerPostListColumn = (c) => host().registerPostListColumn(c);
|
|
10
10
|
/** Thêm hộp vào form sửa chuyên mục/thẻ (dữ liệu lưu trong term.meta). */
|
|
11
11
|
export const registerTermMetaBox = (b) => host().registerTermMetaBox(b);
|
|
12
|
+
/**
|
|
13
|
+
* Thêm hộp vào trang sửa đối tượng của plugin khác (đơn hàng, mã giảm giá, dòng bảng [PluginTable] có cột [ObjectMeta]…) —
|
|
14
|
+
* giá trị đặt qua setMeta được plugin chủ lưu cùng đối tượng. CMS < 1.18.0: bỏ qua.
|
|
15
|
+
*/
|
|
16
|
+
export const registerObjectMetaBox = (b) => host().registerObjectMetaBox?.(b);
|
|
17
|
+
/** Hộp đã đăng ký cho một đối tượng (bỏ trống = tất cả). */
|
|
18
|
+
export const getObjectMetaBoxes = (object) => host().getObjectMetaBoxes?.(object) ?? [];
|
|
12
19
|
/** Lấy các MetaBox đã đăng ký trong hệ thống (tùy chọn lọc theo postType). */
|
|
13
20
|
export const getMetaBoxes = (postType) => (host().getMetaBoxes ? host().getMetaBoxes(postType) : []);
|
|
14
21
|
/** Hook lấy toàn bộ state plugin UI trong host. */
|
|
15
22
|
export const usePluginUi = () => (host().usePluginUi ? host().usePluginUi() : { metaBoxes: [], pages: {}, dashboardWidgets: [], postListColumns: [], termMetaBoxes: [], loaded: true, errors: [] });
|
|
16
23
|
export const useApi = (path) => host().useApi(path);
|
|
24
|
+
/**
|
|
25
|
+
* Đường dẫn của trang plugin: tham số theo mẫu đã đăng ký, query, điều hướng (CMS ≥ 1.20.0):
|
|
26
|
+
* registerPage({ path: "/orders/:id", component: OrderPage });
|
|
27
|
+
* function OrderPage() { const { params, navigate } = useAdminRoute(); … navigate("/orders"); }
|
|
28
|
+
* CMS cũ: params rỗng, navigate tải lại trang.
|
|
29
|
+
*/
|
|
30
|
+
export const useAdminRoute = () => host().useAdminRoute?.() ?? {
|
|
31
|
+
path: typeof location === "undefined" ? "/" : location.pathname, params: {},
|
|
32
|
+
query: typeof location === "undefined" ? {} : Object.fromEntries(new URLSearchParams(location.search)),
|
|
33
|
+
navigate: (to) => { if (typeof location !== "undefined")
|
|
34
|
+
location.assign(to); },
|
|
35
|
+
};
|
|
36
|
+
/** Điều hướng trong admin từ bất kỳ đâu (kể cả ngoài component) — CMS < 1.20.0: tải lại trang. */
|
|
37
|
+
export const navigate = (to, opts) => {
|
|
38
|
+
const h = host();
|
|
39
|
+
if (h.navigate)
|
|
40
|
+
h.navigate(to, opts);
|
|
41
|
+
else if (typeof location !== "undefined")
|
|
42
|
+
location.assign(to);
|
|
43
|
+
};
|
|
44
|
+
/** Loại trường của plugin cho form tự sinh (settings, widget) — CMS < 1.20.0: bỏ qua (form hiện ô chữ). */
|
|
45
|
+
export const registerFieldType = (def) => host().registerFieldType?.(def);
|
|
17
46
|
export const can = (capability) => host().can(capability);
|
|
18
47
|
/**
|
|
19
48
|
* Khối cho trình soạn nội dung, khai báo bằng defineBlock (file dùng chung với phần website của plugin):
|
|
@@ -38,6 +67,13 @@ export const registerBlockPanel = (panel) => host().editor.registerBlockPanel?.(
|
|
|
38
67
|
* CMS cũ (chưa có tab Mẫu) → bỏ qua, không lỗi.
|
|
39
68
|
*/
|
|
40
69
|
export const registerPattern = (pattern) => host().editor.registerPattern?.(pattern);
|
|
70
|
+
/**
|
|
71
|
+
* Nguồn dữ liệu cho mục "Gắn dữ liệu" của trình soạn (đoạn văn, tiêu đề, ảnh, nút…):
|
|
72
|
+
* registerBindingSource({ name: "shop/product", label: "%binding.product%", fields: [{ value: "price", label: "%binding.price%" }] })
|
|
73
|
+
* Website lấy giá trị bằng definePlugin({ bindingSources: { "shop/product": (args, ctx) => … } }) của theme-sdk.
|
|
74
|
+
* CMS cũ → bỏ qua, không lỗi.
|
|
75
|
+
*/
|
|
76
|
+
export const registerBindingSource = (source) => host().editor.registerBindingSource?.(source);
|
|
41
77
|
export { defineBlock } from "@ecomcx/ecomweb-content";
|
|
42
78
|
/** Thêm node/mark TipTap cho trình soạn (cấp thấp — khối thường dùng registerBlock). */
|
|
43
79
|
export const registerEditorExtension = (pack) => host().editor.register(pack);
|
|
@@ -137,6 +173,8 @@ export const IconButton = ui("IconButton");
|
|
|
137
173
|
export const Section = ui("Section");
|
|
138
174
|
export const Tabs = ui("Tabs");
|
|
139
175
|
export const MetaBoxes = ui("MetaBoxes");
|
|
176
|
+
/** Plugin chủ vẽ chỗ cho hộp của plugin khác trong trang sửa đối tượng của mình (CMS < 1.18.0: không vẽ gì). */
|
|
177
|
+
export const ObjectMetaBoxes = ui("ObjectMetaBoxes", () => null);
|
|
140
178
|
export const Slot = ui("Slot");
|
|
141
179
|
export const Fill = ui("Fill");
|
|
142
180
|
// ----- UI kit v2 (xem trang /ui-kit trong admin) -----
|
package/dist/types.d.ts
CHANGED
|
@@ -91,6 +91,40 @@ export interface TermMetaBox {
|
|
|
91
91
|
taxonomies?: string[];
|
|
92
92
|
component: ComponentType<TermMetaBoxProps>;
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Đối tượng của plugin lưu trong bảng riêng (vd "ecomcx-ecommerce/order") — plugin chủ khai báo bằng ctx.Objects.Register ở backend
|
|
96
|
+
* (hoặc bảng [PluginTable] có cột [ObjectMeta]); danh sách nằm trong bootstrap của admin (`objectTypes`).
|
|
97
|
+
*/
|
|
98
|
+
export interface ObjectMetaBoxProps {
|
|
99
|
+
/** Tên đối tượng "{slug}/{name}". */
|
|
100
|
+
object: string;
|
|
101
|
+
/** Mã đối tượng; bỏ trống khi đang tạo mới. */
|
|
102
|
+
id?: string | number;
|
|
103
|
+
/** Dữ liệu đang sửa của đối tượng (chỉ để đọc, vd tổng tiền đơn hàng) — tuỳ plugin chủ. */
|
|
104
|
+
record?: Record<string, any>;
|
|
105
|
+
/** Meta hiện tại (đã gồm thay đổi chưa lưu). */
|
|
106
|
+
meta: Record<string, any>;
|
|
107
|
+
/** Đặt meta — plugin chủ lưu cùng đối tượng khi bấm Lưu. */
|
|
108
|
+
setMeta(key: string, value: any): void;
|
|
109
|
+
}
|
|
110
|
+
/** Hộp thêm vào trang sửa đối tượng của plugin khác (CMS ≥ 1.18.0), vd trường tuỳ biến cho đơn hàng. */
|
|
111
|
+
export interface ObjectMetaBox {
|
|
112
|
+
id: string;
|
|
113
|
+
title: string;
|
|
114
|
+
/** Tên đối tượng "{slug}/{name}"; bỏ trống = mọi đối tượng. */
|
|
115
|
+
objects?: string[];
|
|
116
|
+
context?: "main" | "side";
|
|
117
|
+
priority?: number;
|
|
118
|
+
/** Trả false để ẩn hộp với đối tượng này (vd không có nhóm trường nào áp dụng). */
|
|
119
|
+
visible?(props: ObjectMetaBoxProps): boolean;
|
|
120
|
+
component: ComponentType<ObjectMetaBoxProps>;
|
|
121
|
+
}
|
|
122
|
+
/** Chỗ vẽ hộp của plugin khác trong trang sửa đối tượng của mình (plugin chủ dùng). */
|
|
123
|
+
export interface ObjectMetaBoxesProps extends ObjectMetaBoxProps {
|
|
124
|
+
context?: "main" | "side" | "all";
|
|
125
|
+
excludeIds?: string[];
|
|
126
|
+
className?: string;
|
|
127
|
+
}
|
|
94
128
|
export interface MetaBox {
|
|
95
129
|
id: string;
|
|
96
130
|
title: string;
|
|
@@ -132,6 +166,43 @@ export interface AdminPage {
|
|
|
132
166
|
path: string;
|
|
133
167
|
}>;
|
|
134
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Đường dẫn hiện tại của trang plugin (useAdminRoute, CMS ≥ 1.20.0). registerPage nhận mẫu "/orders/:id" (một đoạn)
|
|
171
|
+
* hoặc "/orders/*" (phần còn lại, params["*"]).
|
|
172
|
+
*/
|
|
173
|
+
export interface AdminRoute {
|
|
174
|
+
/** Đường dẫn trong admin, vd "/orders/12". */
|
|
175
|
+
path: string;
|
|
176
|
+
params: Record<string, string>;
|
|
177
|
+
/** Tham số sau "?" của URL. */
|
|
178
|
+
query: Record<string, string>;
|
|
179
|
+
/** Điều hướng trong admin (không tải lại trang). */
|
|
180
|
+
navigate(to: string, opts?: {
|
|
181
|
+
replace?: boolean;
|
|
182
|
+
}): void;
|
|
183
|
+
}
|
|
184
|
+
/** Props component của loại trường plugin (registerFieldType, CMS ≥ 1.20.0). */
|
|
185
|
+
export interface FieldTypeProps {
|
|
186
|
+
field: {
|
|
187
|
+
key: string;
|
|
188
|
+
type: string;
|
|
189
|
+
label: string;
|
|
190
|
+
options?: string[];
|
|
191
|
+
help?: string;
|
|
192
|
+
default?: unknown;
|
|
193
|
+
};
|
|
194
|
+
value: any;
|
|
195
|
+
onChange(value: any): void;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Loại trường cho form tự sinh của admin (settings plugin — ISettingsRegistry / plugin.json "settings", widget):
|
|
199
|
+
* khai báo trường với Type = tên này ở backend, vd new FieldDefinition("brand", "shop/color-range", "Màu").
|
|
200
|
+
*/
|
|
201
|
+
export interface FieldTypeDefinition {
|
|
202
|
+
/** Tên dạng "slug/tên" để không trùng loại có sẵn của core. */
|
|
203
|
+
type: string;
|
|
204
|
+
component: ComponentType<FieldTypeProps>;
|
|
205
|
+
}
|
|
135
206
|
export interface DashboardWidget {
|
|
136
207
|
id: string;
|
|
137
208
|
title: string;
|
|
@@ -250,6 +321,27 @@ export interface PostRowAction {
|
|
|
250
321
|
/** Danh sách khác (ngoài bài viết) cho plugin mở rộng: người dùng, bình luận, media. */
|
|
251
322
|
export type AdminListName = "users" | "comments" | "media";
|
|
252
323
|
/** Mẫu (pattern): đoạn nội dung dựng sẵn, chèn = chép khối vào bài. */
|
|
324
|
+
/**
|
|
325
|
+
* Nguồn dữ liệu để gắn vào thuộc tính của khối (mục "Gắn dữ liệu" trong trình soạn). Tên trùng với nguồn plugin cung cấp
|
|
326
|
+
* cho website qua definePlugin({ bindingSources }) của theme-sdk — trình soạn chỉ hiện lựa chọn + xem trước, website lấy giá trị thật.
|
|
327
|
+
*/
|
|
328
|
+
export interface EditorBindingSource {
|
|
329
|
+
/** "slug/tên". */
|
|
330
|
+
name: string;
|
|
331
|
+
/** Nhận "%khoá%" (locales của plugin). */
|
|
332
|
+
label: string;
|
|
333
|
+
/** Trường chọn được (đặt vào args[argKey]); nhãn nhận "%khoá%". Không có → ô nhập tự do. */
|
|
334
|
+
fields?: Array<{
|
|
335
|
+
value: string;
|
|
336
|
+
label: string;
|
|
337
|
+
}>;
|
|
338
|
+
/** Tên tham số (mặc định "field"). */
|
|
339
|
+
argKey?: string;
|
|
340
|
+
/** Chỉ cho các thuộc tính này (vd ["src"]). */
|
|
341
|
+
attributes?: string[];
|
|
342
|
+
/** Giá trị xem trước trong trình soạn. */
|
|
343
|
+
preview?(args: Record<string, string | number | boolean>): string | undefined | Promise<string | undefined>;
|
|
344
|
+
}
|
|
253
345
|
export interface EditorPattern {
|
|
254
346
|
/** "slug-plugin/tên". */
|
|
255
347
|
name: string;
|
|
@@ -520,6 +612,8 @@ export interface UiKit {
|
|
|
520
612
|
}>;
|
|
521
613
|
}>;
|
|
522
614
|
MetaBoxes: ComponentType<MetaBoxesProps>;
|
|
615
|
+
/** Hộp của plugin khác cho đối tượng trong bảng riêng (CMS ≥ 1.18.0). */
|
|
616
|
+
ObjectMetaBoxes?: ComponentType<ObjectMetaBoxesProps>;
|
|
523
617
|
Slot: ComponentType<{
|
|
524
618
|
name: string;
|
|
525
619
|
props?: any;
|
|
@@ -686,6 +780,8 @@ export interface CmsAdmin {
|
|
|
686
780
|
registerDashboardWidget(widget: DashboardWidget): void;
|
|
687
781
|
registerPostListColumn(column: PostListColumn): void;
|
|
688
782
|
registerTermMetaBox(box: TermMetaBox): void;
|
|
783
|
+
registerObjectMetaBox?(box: ObjectMetaBox): void;
|
|
784
|
+
getObjectMetaBoxes?(object?: string): ObjectMetaBox[];
|
|
689
785
|
registerSlot(slot: AdminSlotItem): void;
|
|
690
786
|
getSlots(slot: string, postType?: string): Array<AdminSlotItem>;
|
|
691
787
|
registerPostRowAction(action: PostRowAction): void;
|
|
@@ -698,6 +794,14 @@ export interface CmsAdmin {
|
|
|
698
794
|
getPostRowActions(postType?: string): Array<PostRowAction>;
|
|
699
795
|
getMetaBoxes?(postType?: string): MetaBox[];
|
|
700
796
|
usePluginUi?(): any;
|
|
797
|
+
/** CMS ≥ 1.20.0 */
|
|
798
|
+
useAdminRoute?(): AdminRoute;
|
|
799
|
+
/** CMS ≥ 1.20.0 */
|
|
800
|
+
navigate?(to: string, opts?: {
|
|
801
|
+
replace?: boolean;
|
|
802
|
+
}): void;
|
|
803
|
+
/** CMS ≥ 1.20.0 */
|
|
804
|
+
registerFieldType?(def: FieldTypeDefinition): void;
|
|
701
805
|
/** Hook React lấy dữ liệu đơn giản: const { data, loading, error, reload } = useApi("/admin/...") */
|
|
702
806
|
useApi<T = any>(path: string | null): {
|
|
703
807
|
data: T | undefined;
|
|
@@ -737,6 +841,8 @@ export interface CmsAdmin {
|
|
|
737
841
|
registerBlockPanel?(panel: BlockPanel): void;
|
|
738
842
|
/** Mẫu — đoạn nội dung dựng sẵn trong tab "Mẫu" của trình chèn (CMS ≥ 1.12.0). */
|
|
739
843
|
registerPattern?(pattern: EditorPattern): void;
|
|
844
|
+
/** Nguồn gắn dữ liệu cho khối (CMS có trình soạn v2 — @ecomcx/ecomweb-editor ≥ 1.19). */
|
|
845
|
+
registerBindingSource?(source: EditorBindingSource): void;
|
|
740
846
|
tiptap: {
|
|
741
847
|
Node: any;
|
|
742
848
|
Mark: any;
|
package/package.json
CHANGED