cdp-material-sdk 0.0.5

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -0
  3. package/dist/DataScope-B7ffH5qN.js +106 -0
  4. package/dist/components/core/types.d.ts +16 -0
  5. package/dist/components/data-scope/DataScope.d.ts +45 -0
  6. package/dist/constants/event.d.ts +22 -0
  7. package/dist/context/DataContainerRuntimeContext.d.ts +16 -0
  8. package/dist/context/DataScopeContext.d.ts +51 -0
  9. package/dist/context/PageContext.d.ts +26 -0
  10. package/dist/hooks/useConcurrentLoading.d.ts +16 -0
  11. package/dist/hooks/useDataContainer.d.ts +61 -0
  12. package/dist/hooks/useDualLoading.d.ts +22 -0
  13. package/dist/host-react.d.ts +15 -0
  14. package/dist/host-react.js +11 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.js +42 -0
  17. package/dist/plugin.d.ts +45 -0
  18. package/dist/portable.d.ts +20 -0
  19. package/dist/portable.js +33 -0
  20. package/dist/protocol/adapter.d.ts +50 -0
  21. package/dist/protocol/common-schemas.d.ts +64 -0
  22. package/dist/protocol/events.d.ts +48 -0
  23. package/dist/protocol/manifest-types.d.ts +10 -0
  24. package/dist/protocol/manifest.d.ts +144 -0
  25. package/dist/protocol/traits.d.ts +7 -0
  26. package/dist/types/category.d.ts +15 -0
  27. package/dist/utils/mergeInitialValue.d.ts +10 -0
  28. package/dist/validateManifest-CYqjvQe_.js +355 -0
  29. package/dist/validation/validateManifest.d.ts +59 -0
  30. package/docs/component-development/FAQ.md +203 -0
  31. package/docs/component-development/README.md +176 -0
  32. package/docs/component-development/getting-started/01-/345/210/233/345/273/272/346/210/226/346/216/245/345/205/245/347/273/204/344/273/266/345/272/223/345/267/245/347/250/213.md +172 -0
  33. package/docs/component-development/getting-started/02-/345/210/233/345/273/272/347/273/204/344/273/266/345/214/205/345/271/266/346/263/250/345/206/214.md +185 -0
  34. package/docs/component-development/getting-started/03-/345/274/200/345/217/221/346/234/200/345/260/217/345/217/257/350/277/220/350/241/214/347/273/204/344/273/266.md +196 -0
  35. package/docs/component-development/getting-started/04-/346/236/204/345/273/272/345/217/221/345/270/203/344/270/216/345/256/277/344/270/273/346/216/245/345/205/245.md +147 -0
  36. package/docs/component-development/getting-started/05-/350/207/252/346/243/200/344/270/216/346/216/222/351/224/231.md +186 -0
  37. package/docs/component-development/recipes//344/275/277/347/224/250Adapter/351/200/202/351/205/215/347/273/204/344/273/266API.md +131 -0
  38. package/docs/component-development/recipes//345/243/260/346/230/216/344/272/213/344/273/266.md +229 -0
  39. package/docs/component-development/recipes//345/243/260/346/230/216/345/212/250/344/275/234/344/270/216/347/212/266/346/200/201.md +188 -0
  40. package/docs/component-development/recipes//345/243/260/346/230/216/345/270/203/345/261/200/345/256/271/345/231/250/347/273/204/344/273/266.md +221 -0
  41. package/docs/component-development/recipes//345/243/260/346/230/216/346/217/222/346/247/275.md +141 -0
  42. package/docs/component-development/recipes//345/243/260/346/230/216/346/225/260/346/215/256/345/255/227/346/256/265/347/273/204/344/273/266.md +147 -0
  43. package/docs/component-development/recipes//345/243/260/346/230/216/346/225/260/346/215/256/345/256/271/345/231/250/347/273/204/344/273/266.md +258 -0
  44. package/docs/component-development/recipes//346/216/245/345/205/245/347/254/254/344/270/211/346/226/271React/347/273/204/344/273/266/345/272/223.md +209 -0
  45. package/docs/component-development/recipes//351/205/215/347/275/256DOM/346/240/271/350/212/202/347/202/271/346/263/250/345/205/245.md +222 -0
  46. package/docs/component-development/recipes//351/205/215/347/275/256Loading/347/255/226/347/225/245.md +198 -0
  47. package/docs/component-development/recipes//351/205/215/347/275/256/350/256/276/350/256/241/345/231/250/345/205/203/344/277/241/346/201/257.md +153 -0
  48. package/docs/component-development/reference/ActionsState/346/250/241/345/236/213.md +124 -0
  49. package/docs/component-development/reference/DOM/346/240/271/350/212/202/347/202/271/346/263/250/345/205/245/346/250/241/345/236/213.md +125 -0
  50. package/docs/component-development/reference/Events/346/250/241/345/236/213.md +170 -0
  51. package/docs/component-development/reference/Loading/347/255/226/347/225/245/346/250/241/345/236/213.md +140 -0
  52. package/docs/component-development/reference/Manifest/345/255/227/346/256/265/345/217/202/350/200/203.md +251 -0
  53. package/docs/component-development/reference/SDK/345/257/274/345/205/245/350/276/271/347/225/214.md +119 -0
  54. package/docs/component-development/reference/Slots/346/250/241/345/236/213.md +110 -0
  55. package/docs/component-development/reference/Traits/350/203/275/345/212/233/346/250/241/345/236/213.md +165 -0
  56. package/docs/component-development/reference/validateManifest/346/240/241/351/252/214/350/247/204/345/210/231.md +171 -0
  57. package/docs/component-development/reference//345/274/225/346/223/216/345/237/272/347/241/200/350/203/275/345/212/233/346/250/241/345/236/213.md +70 -0
  58. package/docs/component-development/reference//347/244/272/344/276/213/344/273/243/347/240/201/347/264/242/345/274/225.md +163 -0
  59. package/package.json +67 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cdp-material-sdk contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # cdp-material-sdk
2
+
3
+ `cdp-material-sdk` 是面向独立仓库外部作者的公开 SDK,用于编写真实 React 组件包并向宿主注册 `ComponentManifest`、`EngineComponentPackage` 与 `EngineComponentPlugin`。
4
+
5
+ ## 适用对象
6
+
7
+ - 在独立仓库中开发第三方 React 组件包的作者
8
+ - 需要基于稳定公开边界验证宿主集成的工程团队
9
+
10
+ ## 安装
11
+
12
+ 从 npm 安装最新版(推荐):
13
+
14
+ ```bash
15
+ npm install cdp-material-sdk@latest react react-dom
16
+ ```
17
+
18
+ 如需锁定到精确版本:
19
+
20
+ ```bash
21
+ npm install cdp-material-sdk@<version> react react-dom
22
+ ```
23
+
24
+ 无 npm 访问时,可回退到 GitHub Release `.tgz`:
25
+
26
+ ```bash
27
+ npm install https://github.com/GroovyKetchup/cdp-material-sdk/releases/download/v<version>/cdp-material-sdk-<version>.tgz
28
+ ```
29
+
30
+ `react` 与 `react-dom` 是 peer dependency,需要由组件作者侧显式安装(建议 19.x)。
31
+
32
+ ## 推荐入口
33
+
34
+ - `cdp-material-sdk/portable`
35
+ - 独立仓库作者默认入口
36
+ - 适合直接打入外部 bundle
37
+ - `cdp-material-sdk/host-react`
38
+ - 仅用于需要与宿主共享 React runtime / Context identity 的 helper(如 `DataScope`、`useDataContainer`、`useDataContainerApi`)
39
+ - 不作为独立 bundle 的可移植保证范围
40
+ - `cdp-material-sdk`
41
+ - 兼容根入口
42
+
43
+ ## 起步与组件开发指南
44
+
45
+ 完整的组件开发流程、能力 Recipe、模型 Reference 与 FAQ 见 [`docs/component-development`](./docs/component-development/README.md)。
46
+
47
+ 新接入作者建议按以下顺序阅读:
48
+
49
+ 1. [创建或接入组件库工程](./docs/component-development/getting-started/01-创建或接入组件库工程.md)
50
+ 2. [创建组件包并注册](./docs/component-development/getting-started/02-创建组件包并注册.md)
51
+ 3. [开发最小可运行组件](./docs/component-development/getting-started/03-开发最小可运行组件.md)
52
+ 4. [构建发布与宿主接入](./docs/component-development/getting-started/04-构建发布与宿主接入.md)
53
+ 5. [自检与排错](./docs/component-development/getting-started/05-自检与排错.md)
54
+
55
+ 按需启用的能力 Recipe(数据字段 / 数据容器 / 布局容器 / 事件 / 动作与状态 / 插槽 / 设计器元信息 / Adapter / Loading 等)见 [`docs/component-development/recipes`](./docs/component-development/recipes/),模型与字段参考见 [`docs/component-development/reference`](./docs/component-development/reference/)。
56
+
57
+ ## 仓库维护与发布
58
+
59
+ - `npm run release:check`:发布前自检(build + `npm pack --dry-run`)
60
+ - `npm pack`:生成 `cdp-material-sdk-<version>.tgz` 用于离线分发
61
+ - `.github/workflows/release.yml`:在打 `v*` tag 时自动 build、上传 GitHub Release artifact,并通过 `npm publish --provenance --access public` 发布到 npm(依赖仓库 secret `NPM_TOKEN`)
62
+
63
+ ## 边界说明
64
+
65
+ - `public/external-packages/*` 在宿主仓库中仅承担 transport smoke demo 角色
66
+ - 独立仓库作者应优先使用 `cdp-material-sdk/portable`
67
+ - `cdp-material-sdk/host-react` 只适用于宿主 React runtime / Context 身份已统一的场景
@@ -0,0 +1,106 @@
1
+ import { createContext as D, useContext as f, useCallback as l, useRef as j, useMemo as E } from "react";
2
+ import { useStore as O } from "zustand";
3
+ import { cloneDeep as i, has as g, set as M } from "lodash-es";
4
+ import { jsx as k } from "react/jsx-runtime";
5
+ const b = D(null), d = D(null), x = "value", m = (t) => t !== null && typeof t == "object" && !Array.isArray(t), p = (t) => Array.isArray(t) && t.every((n) => n === void 0 || m(n)), C = (t, n, e = [x]) => {
6
+ if (!g(t, e)) {
7
+ M(t, e, i(n));
8
+ return;
9
+ }
10
+ if (p(n)) {
11
+ n.forEach((r, o) => {
12
+ C(t, r, [...e, o]);
13
+ });
14
+ return;
15
+ }
16
+ if (m(n))
17
+ for (const [r, o] of Object.entries(n))
18
+ C(
19
+ t,
20
+ o,
21
+ [...e, r]
22
+ );
23
+ }, $ = (t, n) => {
24
+ if (n === void 0)
25
+ return t;
26
+ if (t === void 0)
27
+ return i(n);
28
+ const e = p(n), r = p(t), o = Array.isArray(n), s = Array.isArray(t), u = m(n), a = m(t);
29
+ if (o !== s || u !== a)
30
+ return i(n);
31
+ if ((o || s) && (!e || !r))
32
+ return i(n);
33
+ if (e !== r || u !== a)
34
+ return i(n);
35
+ if (!e && !u)
36
+ return i(n);
37
+ const c = { value: i(n) };
38
+ return C(c, t), c.value;
39
+ }, P = (t) => t === void 0 || t !== null && typeof t == "object", K = (t, n, e) => !t || !n || t !== n.componentId || n.hasInitializedRef.current || n.initialDefaultValueRef.current === void 0 ? !1 : P(e), I = (t, n, e) => K(t, n, e) ? $(e, n?.initialDefaultValueRef.current) : e;
40
+ function U(t) {
41
+ const n = f(b), e = f(d), r = n?.store ?? null, o = t ?? e?.componentId, s = l(() => {
42
+ const c = r && o ? r.getState().components[o]?.value : void 0;
43
+ return I(o, e, c);
44
+ }, [o, e, r]), u = l((c) => {
45
+ !r || !o || r.getState().setComponentData(o, c);
46
+ }, [o, r]), a = l(() => {
47
+ !r || !o || r.getState().resetComponentData(o);
48
+ }, [o, r]);
49
+ return { getContainerData: s, setContainerData: u, resetContainerData: a };
50
+ }
51
+ function T(t) {
52
+ const n = U(t), e = f(b), r = f(d), o = e?.store ?? null, s = t ?? r?.componentId;
53
+ return {
54
+ containerData: o ? I(
55
+ s,
56
+ r,
57
+ O(o, (a) => s ? a.components[s]?.value : void 0)
58
+ ) : void 0,
59
+ ...n
60
+ };
61
+ }
62
+ const Y = D(null), _ = "components", h = "value", w = (t, n) => `${_}.${t}.${h}.${n}`, q = ({
63
+ relativePath: t,
64
+ record: n,
65
+ getRecord: e,
66
+ index: r,
67
+ registerField: o,
68
+ unregisterField: s,
69
+ children: u
70
+ }) => {
71
+ const a = f(d);
72
+ if (!a?.componentId)
73
+ throw new Error(
74
+ "[cdp-material-sdk] DataScope 必须在数据容器组件内部使用,请确保上层提供 DataContainerRuntimeContext。"
75
+ );
76
+ const c = a.componentId, y = l(
77
+ (v) => {
78
+ const S = t ? t(v) : v;
79
+ return w(c, S);
80
+ },
81
+ [c, t]
82
+ ), A = j(n);
83
+ A.current = n;
84
+ const R = E(
85
+ () => ({
86
+ resolvePath: y,
87
+ inScope: !0,
88
+ getRecord: e ?? (() => A.current),
89
+ index: r,
90
+ registerField: o,
91
+ unregisterField: s
92
+ }),
93
+ [y, e, r, o, s]
94
+ );
95
+ return /* @__PURE__ */ k(Y.Provider, { value: R, children: u });
96
+ };
97
+ export {
98
+ d as D,
99
+ b as P,
100
+ q as a,
101
+ Y as b,
102
+ U as c,
103
+ I as r,
104
+ K as s,
105
+ T as u
106
+ };
@@ -0,0 +1,16 @@
1
+ import type { HTMLAttributes, RefAttributes } from 'react';
2
+ /**
3
+ * 宿主注入根 DOM 属性时使用的标准路径。
4
+ * 外部作者组件应将 `slotProps.root` 透传到实际渲染的根节点,
5
+ * 以便宿主挂载 ref 和 DOM 属性。
6
+ */
7
+ export declare const INJECT_PATH_SLOT_PROPS = "slotProps.root";
8
+ /**
9
+ * 支持宿主注入 slot props 的基础属性结构。
10
+ */
11
+ export interface BaseUIProps<RootDOM extends HTMLElement = HTMLElement> {
12
+ slotProps?: {
13
+ root?: HTMLAttributes<RootDOM> & RefAttributes<RootDOM>;
14
+ [key: string]: any;
15
+ };
16
+ }
@@ -0,0 +1,45 @@
1
+ import type { ReactNode } from 'react';
2
+ import { type FieldState } from '../../context/DataScopeContext';
3
+ export interface DataScopeProps {
4
+ /**
5
+ * 相对路径函数,决定子字段在数据容器值内的访问位置。
6
+ *
7
+ * 例:
8
+ * - Form: `(childId) => childId` → `components.X.value.fieldName`
9
+ * - TableRow: `(childId) => `[${i}].${childId}`` → `components.X.value[0].fieldName`
10
+ *
11
+ * 默认值: `(childId) => childId`。
12
+ */
13
+ relativePath?: (childId: string) => string;
14
+ /**
15
+ * 数据实体(适用于会随数据重新 render 的组件,如 Table 行)。
16
+ * 与 `getRecord` 二选一。
17
+ */
18
+ record?: unknown;
19
+ /**
20
+ * 数据实体获取函数(适用于不会随数据重新 render 的组件,如 Form)。
21
+ * 与 `record` 二选一。
22
+ */
23
+ getRecord?: () => unknown;
24
+ /** 当前作用域索引(如表格行索引)。 */
25
+ index?: number;
26
+ /** 字段注册接口,由数据容器组件实现。 */
27
+ registerField?: (field: FieldState) => void;
28
+ unregisterField?: (id: string) => void;
29
+ children: ReactNode;
30
+ }
31
+ /**
32
+ * `DataScope` 用于建立数据作用域:
33
+ *
34
+ * 1. 路径解析 — 自动用最近一层 `DataContainerRuntimeContext` 的 `componentId`,
35
+ * 结合 `relativePath` 拼接出页面 store 绝对路径。
36
+ * 2. 数据实体注入 — 使用 Ref + Getter 模式,让 `record` 变化不会触发后代重渲染。
37
+ * 3. 索引注入 — 暴露当前作用域索引(排序/增删时合理触发更新)。
38
+ * 4. 字段状态注册 — 透传 `registerField` / `unregisterField`,便于容器聚合字段元信息。
39
+ *
40
+ * 设计约束:
41
+ * - `DataScope` 必须被包裹在数据容器组件内部,由数据容器经
42
+ * `DataContainerRuntimeContext` 提供 `componentId`。组件作者无需也不应
43
+ * 显式传入 `componentId`。
44
+ */
45
+ export declare const DataScope: ({ relativePath, record, getRecord: getRecordProp, index, registerField, unregisterField, children, }: DataScopeProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ export declare const NOTIFY_TIMING: {
2
+ readonly BEFORE: "before";
3
+ readonly AFTER: "after";
4
+ readonly BOTH: "both";
5
+ };
6
+ export declare const NOTIFY_ERROR_STRATEGY: {
7
+ readonly IGNORE: "ignore";
8
+ readonly STOP: "stop";
9
+ };
10
+ export declare const ENGINE_EVENT_TYPE: {
11
+ readonly MOUNT: "mount";
12
+ readonly UNMOUNT: "unmount";
13
+ readonly CLICK: "click";
14
+ readonly FOCUS: "focus";
15
+ readonly BLUR: "blur";
16
+ readonly VALUE_CHANGE: "valueChange";
17
+ readonly ITEM_CLICK: "itemClick";
18
+ readonly ITEM_DOUBLE_CLICK: "itemDoubleClick";
19
+ readonly ITEM_RIGHT_CLICK: "itemRightClick";
20
+ readonly ITEM_LONG_PRESS: "itemLongPress";
21
+ readonly DATA_FETCH: "dataFetch";
22
+ };
@@ -0,0 +1,16 @@
1
+ import type { RefObject } from 'react';
2
+ /**
3
+ * 由宿主数据容器组件提供的运行时元数据。
4
+ *
5
+ * 它让 host-react 辅助函数能够推断当前生效的 `componentId`,并在
6
+ * 容器首次把值写入页面 store 之前,先暴露初始默认值。
7
+ */
8
+ export interface DataContainerRuntimeContextValue<T = unknown> {
9
+ componentId: string;
10
+ initialDefaultValueRef: RefObject<T | undefined>;
11
+ hasInitializedRef: RefObject<boolean>;
12
+ }
13
+ /**
14
+ * 承载当前数据容器运行时元数据的 React context。
15
+ */
16
+ export declare const DataContainerRuntimeContext: import("react").Context<DataContainerRuntimeContextValue<unknown> | null>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * 把 DataScope 内部使用的相对字段名解析为页面 store 绝对路径。
3
+ */
4
+ export type PathResolver = (childId: string) => string;
5
+ /**
6
+ * 用于在组件间传递的延迟作用域,避免在数据频繁变化时触发下游重渲染。
7
+ */
8
+ export interface LazyScope {
9
+ /** 数据实体获取器。 */
10
+ getRecord: () => unknown;
11
+ /** 当前作用域索引(如表格行索引)。 */
12
+ index?: number;
13
+ }
14
+ /**
15
+ * 由数据字段组件向上注册的字段状态。
16
+ * 数据容器组件可以据此聚合字段元信息,例如校验态、读写态、显隐态等。
17
+ */
18
+ export interface FieldState {
19
+ /** 字段唯一 ID,可能是组件 ID 或嵌套字段 fullPath。 */
20
+ id: string;
21
+ /** props 上的字段名。 */
22
+ name?: string;
23
+ /** props 上的字段标签。 */
24
+ label?: string;
25
+ hidden: boolean;
26
+ /** 组件内部 readOnly 状态,不包含 Form 全局状态。 */
27
+ readOnly: boolean;
28
+ /** 组件 props 上的 required 可能被动作修改,需要上报。 */
29
+ required?: boolean;
30
+ }
31
+ /**
32
+ * DataScope 提供给后代组件的上下文值。
33
+ */
34
+ export interface DataScopeContextValue {
35
+ resolvePath: PathResolver;
36
+ inScope: boolean;
37
+ /**
38
+ * 数据实体获取函数,引用稳定,避免数据变化触发下游重渲染。
39
+ */
40
+ getRecord: () => unknown;
41
+ /** 当前作用域索引(如表格行索引)。 */
42
+ index?: number;
43
+ /** 字段注册接口,由数据容器组件提供。 */
44
+ registerField?: (field: FieldState) => void;
45
+ unregisterField?: (id: string) => void;
46
+ }
47
+ /**
48
+ * 当前数据作用域的 React context。
49
+ * 数据字段组件通过它解析字段路径、读取记录和注册字段状态。
50
+ */
51
+ export declare const DataScopeContext: import("react").Context<DataScopeContextValue | null>;
@@ -0,0 +1,26 @@
1
+ import type { StoreApi } from 'zustand';
2
+ /**
3
+ * 宿主页面状态树中每个组件对应的最小状态结构。
4
+ */
5
+ export interface MaterialSdkComponentState {
6
+ value?: unknown;
7
+ }
8
+ /**
9
+ * `cdp-material-sdk/host-react` 辅助函数依赖的宿主页面 store 结构。
10
+ */
11
+ export interface MaterialSdkPageStoreState {
12
+ components: Record<string, MaterialSdkComponentState>;
13
+ setComponentData: (componentId: string, data: unknown) => void;
14
+ resetComponentData: (componentId: string) => void;
15
+ }
16
+ export type MaterialSdkPageStoreApi = StoreApi<MaterialSdkPageStoreState>;
17
+ /**
18
+ * 为 host-react 辅助函数暴露宿主页面 store 的 React context 值。
19
+ */
20
+ export interface MaterialSdkPageContextValue {
21
+ store: MaterialSdkPageStoreApi | null;
22
+ }
23
+ /**
24
+ * 供 host-react 辅助函数读写组件数据的 React context。
25
+ */
26
+ export declare const PageContext: import("react").Context<MaterialSdkPageContextValue | null>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 面向重叠异步操作的引用计数式 loading 控制器。
3
+ */
4
+ export interface useConcurrentLoadingReturn {
5
+ isLoading: boolean;
6
+ loadingText: string | undefined;
7
+ startLoading: (text?: string) => boolean;
8
+ stopLoading: () => boolean;
9
+ getLoading: () => boolean;
10
+ resetLoading: () => void;
11
+ }
12
+ /**
13
+ * 在多次并发 `startLoading` / `stopLoading` 调用之间维护 loading 状态,
14
+ * 并为当前活跃任务暴露共享的 loading 文案。
15
+ */
16
+ export declare const useConcurrentLoading: () => useConcurrentLoadingReturn;
@@ -0,0 +1,61 @@
1
+ import { type DataContainerRuntimeContextValue } from '../context/DataContainerRuntimeContext';
2
+ /**
3
+ * 面向数据容器的命令式访问接口。
4
+ * 可通过显式 `componentId`,或最近一层 `DataContainerRuntimeContext`
5
+ * 自动解析目标数据容器。
6
+ */
7
+ export interface UseDataContainerApiResult<T = any> {
8
+ /**
9
+ * 获取当前数据容器的值。
10
+ */
11
+ getContainerData: () => T | undefined;
12
+ /**
13
+ * 设置数据容器的值。
14
+ */
15
+ setContainerData: (data: T) => void;
16
+ /**
17
+ * 将数据容器的值重置到初始状态。
18
+ */
19
+ resetContainerData: () => void;
20
+ }
21
+ /**
22
+ * 响应式的数据容器访问结果,并附带 `useDataContainerApi` 返回的
23
+ * 命令式辅助函数。
24
+ */
25
+ export interface UseDataContainerResult<T = any> extends UseDataContainerApiResult<T> {
26
+ /**
27
+ * 当前数据容器的值。
28
+ */
29
+ containerData: T | undefined;
30
+ }
31
+ /**
32
+ * 判断主机 React 数据容器辅助函数当前是否应临时回退到运行时提供的
33
+ * 初始默认值。
34
+ *
35
+ * 只有当运行时上下文匹配,且容器尚未把首个值写入 store 时,才会触发
36
+ * 这一路径。
37
+ */
38
+ export declare const shouldUseDataContainerRuntimeFallback: (componentId: string | undefined, runtimeContext: DataContainerRuntimeContextValue | null, currentValue: unknown) => boolean;
39
+ /**
40
+ * 将 runtime fallback 与当前 store 值按 initComponentData 的同一套语义合并。
41
+ * 维护要求:任何初始值合并规则的调整都应复用 mergeComponentInitialValue,
42
+ * 避免 getContainerData()/containerData 与 initComponentData 的语义漂移。
43
+ */
44
+ export declare const resolveDataContainerRuntimeValue: <T = any>(componentId: string | undefined, runtimeContext: DataContainerRuntimeContextValue | null, currentValue: T | undefined) => T | undefined;
45
+ /**
46
+ * 提供对数据容器值的命令式读取、写入与重置能力。
47
+ * 如果未传入 `componentId`,则自动使用最近一层
48
+ * `DataContainerRuntimeContext` 中的目标组件。
49
+ */
50
+ export declare function useDataContainerApi<T = any>(): UseDataContainerApiResult<T>;
51
+ export declare function useDataContainerApi<T = any>(componentId: string): UseDataContainerApiResult<T>;
52
+ export declare function useDataContainerApi<T = any>(componentId?: string | undefined): UseDataContainerApiResult<T>;
53
+ /**
54
+ * 订阅数据容器值,并同时返回当前值与 `useDataContainerApi` 提供的
55
+ * 命令式辅助函数。
56
+ * 如果未传入 `componentId`,则自动使用最近一层
57
+ * `DataContainerRuntimeContext` 中的目标组件。
58
+ */
59
+ export declare function useDataContainer<T = any>(): UseDataContainerResult<T>;
60
+ export declare function useDataContainer<T = any>(componentId: string): UseDataContainerResult<T>;
61
+ export declare function useDataContainer<T = any>(componentId?: string | undefined): UseDataContainerResult<T>;
@@ -0,0 +1,22 @@
1
+ import type { RefObject } from 'react';
2
+ /**
3
+ * 将动作触发的 loading 与后台数据 loading 分离建模,
4
+ * 同时仍然对外暴露统一的组合 loading 状态。
5
+ */
6
+ export interface UseDualLoadingReturn {
7
+ actionLoading: boolean;
8
+ actionLoadingText: string | undefined;
9
+ startActionLoading: (text?: string) => boolean;
10
+ stopActionLoading: () => boolean;
11
+ getActionLoading: () => boolean;
12
+ resetActionLoading: () => void;
13
+ dataLoading: boolean;
14
+ setDataLoading: (loading: boolean) => void;
15
+ isLoading: boolean;
16
+ isLoadingRef: RefObject<boolean>;
17
+ }
18
+ /**
19
+ * 将 `useConcurrentLoading` 与显式的数据 loading 标记组合起来,
20
+ * 让 UI 代码可以区分动作 loading 与后台数据获取。
21
+ */
22
+ export declare const useDualLoading: () => UseDualLoadingReturn;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 宿主耦合的辅助导出,要求与宿主应用共享 React context 与运行时实例。
3
+ * 除非你明确需要接入 `PageContext` 或 `DataContainerRuntimeContext`,
4
+ * 否则应优先使用 `cdp-material-sdk/portable`。
5
+ */
6
+ export { PageContext } from './context/PageContext';
7
+ export type { MaterialSdkPageContextValue, MaterialSdkPageStoreApi, MaterialSdkPageStoreState } from './context/PageContext';
8
+ export { DataContainerRuntimeContext } from './context/DataContainerRuntimeContext';
9
+ export type { DataContainerRuntimeContextValue } from './context/DataContainerRuntimeContext';
10
+ export { useDataContainer, useDataContainerApi, resolveDataContainerRuntimeValue, shouldUseDataContainerRuntimeFallback } from './hooks/useDataContainer';
11
+ export type { UseDataContainerApiResult, UseDataContainerResult } from './hooks/useDataContainer';
12
+ export { DataScope } from './components/data-scope/DataScope';
13
+ export type { DataScopeProps } from './components/data-scope/DataScope';
14
+ export { DataScopeContext } from './context/DataScopeContext';
15
+ export type { DataScopeContextValue, FieldState, LazyScope, PathResolver } from './context/DataScopeContext';
@@ -0,0 +1,11 @@
1
+ import { D as e, a as n, b as o, P as s, r as i, s as r, u, c as C } from "./DataScope-B7ffH5qN.js";
2
+ export {
3
+ e as DataContainerRuntimeContext,
4
+ n as DataScope,
5
+ o as DataScopeContext,
6
+ s as PageContext,
7
+ i as resolveDataContainerRuntimeValue,
8
+ r as shouldUseDataContainerRuntimeFallback,
9
+ u as useDataContainer,
10
+ C as useDataContainerApi
11
+ };
@@ -0,0 +1,2 @@
1
+ export * from './portable';
2
+ export * from './host-react';
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import { C as e, a as t, b as n, c as i, D as o, E, I as T, d as _, L as O, e as N, f as R, N as r, g as A, O as C, h as S, R as l, S as u, i as D, j as m, k as I, l as P, m as d, n as p, o as Y, p as M, q as c, u as g, r as L, v as G, s as v } from "./validateManifest-CYqjvQe_.js";
2
+ import { D as K, a as h, b as x, P as V, r as b, s as y, u as F, c as k } from "./DataScope-B7ffH5qN.js";
3
+ export {
4
+ e as CATEGORY_LABELS,
5
+ t as COMPONENT_CATEGORY,
6
+ n as COMPONENT_STATE_KEY,
7
+ i as COMPONENT_TRAIT,
8
+ o as DYNAMIC_ENUM_KEY,
9
+ K as DataContainerRuntimeContext,
10
+ h as DataScope,
11
+ x as DataScopeContext,
12
+ E as ENGINE_EVENT_TYPE,
13
+ T as INJECT_PATH_ROOT,
14
+ _ as INJECT_PATH_SLOT_PROPS,
15
+ O as LOADING_PROP_NAME,
16
+ N as LOADING_STRATEGY,
17
+ R as LOADING_WRAPPER_TYPE,
18
+ r as NOTIFY_ERROR_STRATEGY,
19
+ A as NOTIFY_TIMING,
20
+ C as OptionItemSchema,
21
+ S as OptionsSchema,
22
+ V as PageContext,
23
+ l as RemoteOptionConfigSchema,
24
+ u as SLOT_KEY,
25
+ D as STANDARD_EVENT_KEYS,
26
+ m as diagnoseMissingActionImpls,
27
+ I as diagnoseMissingStateKeys,
28
+ P as isCustomEventKey,
29
+ d as isStandardEventKey,
30
+ p as normalizeAdapterEvents,
31
+ Y as normalizeManifestEvents,
32
+ M as printSingleValidationResult,
33
+ c as printValidationResult,
34
+ b as resolveDataContainerRuntimeValue,
35
+ y as shouldUseDataContainerRuntimeFallback,
36
+ g as useConcurrentLoading,
37
+ F as useDataContainer,
38
+ k as useDataContainerApi,
39
+ L as useDualLoading,
40
+ G as validateManifest,
41
+ v as validateManifests
42
+ };
@@ -0,0 +1,45 @@
1
+ import type { ComponentType } from 'react';
2
+ import type { ComponentManifest } from './protocol/manifest';
3
+ /**
4
+ * 将组件清单与其对应的 React 实现绑定在一起。
5
+ */
6
+ export interface EngineComponentRegistration {
7
+ manifest: ComponentManifest;
8
+ component: ComponentType<any>;
9
+ }
10
+ /**
11
+ * 可选的版本兼容提示,供消费方判断当前 SDK 或引擎版本是否可接受。
12
+ */
13
+ export interface EngineComponentPackageCompatibility {
14
+ sdkVersion?: string;
15
+ engineVersion?: string;
16
+ }
17
+ /**
18
+ * 由作者定义组件组成、可作为一个物料包统一分发的发布单元。
19
+ */
20
+ export interface EngineComponentPackage {
21
+ id: string;
22
+ version: string;
23
+ components: EngineComponentRegistration[];
24
+ compatibility?: EngineComponentPackageCompatibility;
25
+ }
26
+ /**
27
+ * 插件在安装阶段可以调用的宿主侧回调。
28
+ */
29
+ export interface EnginePluginAPI {
30
+ registerComponent: (manifest: ComponentManifest, component: ComponentType<any>) => void;
31
+ registerPackage: (pkg: EngineComponentPackage) => void;
32
+ unregisterPackage: (packageId: string) => void;
33
+ }
34
+ /**
35
+ * 可被宿主运行时消费的插件入口。
36
+ *
37
+ * 插件通常会在 `install` 中注册一个或多个组件,或直接注册整个
38
+ * `EngineComponentPackage`。
39
+ */
40
+ export interface EngineComponentPlugin {
41
+ id: string;
42
+ version: string;
43
+ compatibility?: EngineComponentPackageCompatibility;
44
+ install: (api: EnginePluginAPI) => void | Promise<void>;
45
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 面向独立分发物料包的公开 authoring 入口。
3
+ * 第三方组件与插件默认应优先从这里导入。
4
+ */
5
+ export * from './plugin';
6
+ export * from './hooks/useConcurrentLoading';
7
+ export * from './hooks/useDualLoading';
8
+ export * from './protocol/adapter';
9
+ export * from './protocol/common-schemas';
10
+ export * from './protocol/events';
11
+ export * from './protocol/manifest';
12
+ export * from './protocol/manifest-types';
13
+ export * from './protocol/traits';
14
+ export { ENGINE_EVENT_TYPE, NOTIFY_ERROR_STRATEGY, NOTIFY_TIMING } from './constants/event';
15
+ export { COMPONENT_CATEGORY, CATEGORY_LABELS } from './types/category';
16
+ export type { ComponentCategory } from './types/category';
17
+ export { INJECT_PATH_SLOT_PROPS } from './components/core/types';
18
+ export type { BaseUIProps } from './components/core/types';
19
+ export { validateManifest, validateManifests, diagnoseMissingActionImpls, diagnoseMissingStateKeys, printValidationResult, printSingleValidationResult, } from './validation/validateManifest';
20
+ export type { ValidationError, ValidationResult } from './validation/validateManifest';
@@ -0,0 +1,33 @@
1
+ import { C as e, a as E, b as i, c as n, D as t, E as T, I as _, d as O, L as N, e as o, f as A, N as R, g as S, O as I, h as P, R as Y, S as d, i as l, j as C, k as M, l as m, m as r, n as L, o as g, p, q as G, u, r as D, v, s as K } from "./validateManifest-CYqjvQe_.js";
2
+ export {
3
+ e as CATEGORY_LABELS,
4
+ E as COMPONENT_CATEGORY,
5
+ i as COMPONENT_STATE_KEY,
6
+ n as COMPONENT_TRAIT,
7
+ t as DYNAMIC_ENUM_KEY,
8
+ T as ENGINE_EVENT_TYPE,
9
+ _ as INJECT_PATH_ROOT,
10
+ O as INJECT_PATH_SLOT_PROPS,
11
+ N as LOADING_PROP_NAME,
12
+ o as LOADING_STRATEGY,
13
+ A as LOADING_WRAPPER_TYPE,
14
+ R as NOTIFY_ERROR_STRATEGY,
15
+ S as NOTIFY_TIMING,
16
+ I as OptionItemSchema,
17
+ P as OptionsSchema,
18
+ Y as RemoteOptionConfigSchema,
19
+ d as SLOT_KEY,
20
+ l as STANDARD_EVENT_KEYS,
21
+ C as diagnoseMissingActionImpls,
22
+ M as diagnoseMissingStateKeys,
23
+ m as isCustomEventKey,
24
+ r as isStandardEventKey,
25
+ L as normalizeAdapterEvents,
26
+ g as normalizeManifestEvents,
27
+ p as printSingleValidationResult,
28
+ G as printValidationResult,
29
+ u as useConcurrentLoading,
30
+ D as useDualLoading,
31
+ v as validateManifest,
32
+ K as validateManifests
33
+ };