@ecomcx/ecomweb-admin-sdk 1.30.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 CHANGED
@@ -26,6 +26,19 @@ export declare const useApi: <T = any>(path: string | null) => {
26
26
  error: Error | null;
27
27
  reload(): void;
28
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;
29
42
  export declare const can: (capability: string) => boolean;
30
43
  /**
31
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):
@@ -45,6 +58,13 @@ export declare const registerBlockPanel: (panel: import("./types.js").BlockPanel
45
58
  * CMS cũ (chưa có tab Mẫu) → bỏ qua, không lỗi.
46
59
  */
47
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;
48
68
  export { defineBlock, type BlockDefinition, type BlockDefinitionInput, type BlockAttrSpec } from "@ecomcx/ecomweb-content";
49
69
  /** Thêm node/mark TipTap cho trình soạn (cấp thấp — khối thường dùng registerBlock). */
50
70
  export declare const registerEditorExtension: (pack: import("./types.js").EditorExtensionPack) => void;
package/dist/index.js CHANGED
@@ -21,6 +21,28 @@ export const getMetaBoxes = (postType) => (host().getMetaBoxes ? host().getMetaB
21
21
  /** Hook lấy toàn bộ state plugin UI trong host. */
22
22
  export const usePluginUi = () => (host().usePluginUi ? host().usePluginUi() : { metaBoxes: [], pages: {}, dashboardWidgets: [], postListColumns: [], termMetaBoxes: [], loaded: true, errors: [] });
23
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);
24
46
  export const can = (capability) => host().can(capability);
25
47
  /**
26
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):
@@ -45,6 +67,13 @@ export const registerBlockPanel = (panel) => host().editor.registerBlockPanel?.(
45
67
  * CMS cũ (chưa có tab Mẫu) → bỏ qua, không lỗi.
46
68
  */
47
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);
48
77
  export { defineBlock } from "@ecomcx/ecomweb-content";
49
78
  /** Thêm node/mark TipTap cho trình soạn (cấp thấp — khối thường dùng registerBlock). */
50
79
  export const registerEditorExtension = (pack) => host().editor.register(pack);
package/dist/types.d.ts CHANGED
@@ -166,6 +166,43 @@ export interface AdminPage {
166
166
  path: string;
167
167
  }>;
168
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
+ }
169
206
  export interface DashboardWidget {
170
207
  id: string;
171
208
  title: string;
@@ -284,6 +321,27 @@ export interface PostRowAction {
284
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. */
285
322
  export type AdminListName = "users" | "comments" | "media";
286
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
+ }
287
345
  export interface EditorPattern {
288
346
  /** "slug-plugin/tên". */
289
347
  name: string;
@@ -736,6 +794,14 @@ export interface CmsAdmin {
736
794
  getPostRowActions(postType?: string): Array<PostRowAction>;
737
795
  getMetaBoxes?(postType?: string): MetaBox[];
738
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;
739
805
  /** Hook React lấy dữ liệu đơn giản: const { data, loading, error, reload } = useApi("/admin/...") */
740
806
  useApi<T = any>(path: string | null): {
741
807
  data: T | undefined;
@@ -775,6 +841,8 @@ export interface CmsAdmin {
775
841
  registerBlockPanel?(panel: BlockPanel): void;
776
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). */
777
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;
778
846
  tiptap: {
779
847
  Node: any;
780
848
  Mark: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-admin-sdk",
3
- "version": "1.30.0",
3
+ "version": "1.31.0",
4
4
  "description": "SDK cho phần admin của plugin: đăng ký trang, meta box, widget dashboard và dùng bộ UI của admin.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",