@schema-element-editor/host-sdk 2.1.1 → 2.2.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/react.cjs CHANGED
@@ -292,7 +292,7 @@ function createSchemaElementEditorBridge(config) {
292
292
  const implementedMethods = [];
293
293
  if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
294
294
  if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
295
- if (typeof renderPreview === "function") {
295
+ if (renderPreview !== void 0) {
296
296
  implementedMethods.push(
297
297
  METHOD_NAMES.CHECK_PREVIEW,
298
298
  METHOD_NAMES.RENDER_PREVIEW,
@@ -397,7 +397,8 @@ function createSchemaElementEditorBridge(config) {
397
397
  break;
398
398
  }
399
399
  case mergedMessageTypes.checkPreview: {
400
- result = { exists: typeof renderPreview2 === "function" };
400
+ const exists = typeof renderPreview2 === "function";
401
+ result = { exists };
401
402
  break;
402
403
  }
403
404
  case mergedMessageTypes.renderPreview: {
@@ -505,7 +506,11 @@ function useSchemaElementEditor(config) {
505
506
  // 内层使用可选链安全访问,配合类型断言确保类型正确
506
507
  getSchema: configRef.current.getSchema ? (params) => configRef.current.getSchema?.(params) : void 0,
507
508
  updateSchema: configRef.current.updateSchema ? (schema, params) => configRef.current.updateSchema?.(schema, params) : void 0,
508
- renderPreview: configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
509
+ // renderPreview 需要特殊处理:
510
+ // - undefined: 不传递(不参与竞争)
511
+ // - null: 传递 null(参与竞争但阻止预览)
512
+ // - function: 创建代理函数
513
+ renderPreview: configRef.current.renderPreview === null ? null : configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
509
514
  sourceConfig,
510
515
  messageTypes,
511
516
  sdkId,
package/dist/react.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as SchemaElementEditorConfig, d as SchemaElementEditorRecording } from './types-D2ZJx8T_.cjs';
1
+ import { b as SchemaElementEditorConfig, S as SchemaValue, d as SchemaElementEditorRecording } from './types-BSn4QaId.cjs';
2
2
 
3
3
  /**
4
4
  * Schema Element Editor Host SDK - React
@@ -6,7 +6,16 @@ import { b as SchemaElementEditorConfig, d as SchemaElementEditorRecording } fro
6
6
  */
7
7
 
8
8
  /** React 版本的 Schema Element Editor 配置 */
9
- interface ReactSchemaElementEditorConfig extends SchemaElementEditorConfig {
9
+ interface ReactSchemaElementEditorConfig extends Omit<SchemaElementEditorConfig, 'renderPreview'> {
10
+ /**
11
+ * 渲染预览(可选)
12
+ *
13
+ * 特殊值说明:
14
+ * - undefined(默认):不关心预览功能,不参与优先级竞争
15
+ * - null:明确阻止预览功能,参与优先级竞争但告诉插件不支持预览(触发内置预览器)
16
+ * - function:提供预览功能,参与优先级竞争并正常渲染
17
+ */
18
+ renderPreview?: ((schema: SchemaValue, containerId: string) => (() => void) | void) | null;
10
19
  /**
11
20
  * 是否启用桥接(默认 true)
12
21
  * 设为 false 时不创建桥接器,不监听消息
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as SchemaElementEditorConfig, d as SchemaElementEditorRecording } from './types-D2ZJx8T_.js';
1
+ import { b as SchemaElementEditorConfig, S as SchemaValue, d as SchemaElementEditorRecording } from './types-BSn4QaId.js';
2
2
 
3
3
  /**
4
4
  * Schema Element Editor Host SDK - React
@@ -6,7 +6,16 @@ import { b as SchemaElementEditorConfig, d as SchemaElementEditorRecording } fro
6
6
  */
7
7
 
8
8
  /** React 版本的 Schema Element Editor 配置 */
9
- interface ReactSchemaElementEditorConfig extends SchemaElementEditorConfig {
9
+ interface ReactSchemaElementEditorConfig extends Omit<SchemaElementEditorConfig, 'renderPreview'> {
10
+ /**
11
+ * 渲染预览(可选)
12
+ *
13
+ * 特殊值说明:
14
+ * - undefined(默认):不关心预览功能,不参与优先级竞争
15
+ * - null:明确阻止预览功能,参与优先级竞争但告诉插件不支持预览(触发内置预览器)
16
+ * - function:提供预览功能,参与优先级竞争并正常渲染
17
+ */
18
+ renderPreview?: ((schema: SchemaValue, containerId: string) => (() => void) | void) | null;
10
19
  /**
11
20
  * 是否启用桥接(默认 true)
12
21
  * 设为 false 时不创建桥接器,不监听消息
package/dist/react.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useSchemaElementEditor
3
- } from "./chunk-MK3EDWC5.js";
4
- import "./chunk-DLMX4NDA.js";
3
+ } from "./chunk-X4JAISLV.js";
4
+ import "./chunk-H36IVM7V.js";
5
5
  export {
6
6
  useSchemaElementEditor
7
7
  };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Schema Element Editor Host SDK - Types
3
+ * 类型定义
4
+ */
5
+ /**
6
+ * Schema 数据类型
7
+ * 支持所有 JSON.parse 可返回的类型
8
+ */
9
+ type SchemaValue = Record<string, unknown> | unknown[] | string | number | boolean | null;
10
+ /** postMessage 消息标识配置 */
11
+ interface PostMessageSourceConfig {
12
+ /** 插件端发送消息的 source 标识 */
13
+ contentSource: string;
14
+ /** 宿主端响应消息的 source 标识 */
15
+ hostSource: string;
16
+ }
17
+ /** postMessage 消息类型配置 */
18
+ interface PostMessageTypeConfig {
19
+ getSchema: string;
20
+ updateSchema: string;
21
+ checkPreview: string;
22
+ renderPreview: string;
23
+ cleanupPreview: string;
24
+ startRecording: string;
25
+ stopRecording: string;
26
+ schemaPush: string;
27
+ }
28
+ /** SDK 方法级别配置 */
29
+ interface MethodLevelConfig {
30
+ getSchema?: number;
31
+ updateSchema?: number;
32
+ checkPreview?: number;
33
+ renderPreview?: number;
34
+ cleanupPreview?: number;
35
+ startRecording?: number;
36
+ stopRecording?: number;
37
+ }
38
+ /**
39
+ * Schema Element Editor 配置接口
40
+ */
41
+ interface SchemaElementEditorConfig {
42
+ /**
43
+ * 获取 Schema 数据(可选)
44
+ * @param params - 元素参数(通常是 data-id 的值)
45
+ * @returns Schema 数据(支持所有 JSON 类型)
46
+ */
47
+ getSchema?: (params: string) => SchemaValue;
48
+ /**
49
+ * 更新 Schema 数据(可选)
50
+ * @param schema - 新的 Schema 数据(支持所有 JSON 类型)
51
+ * @param params - 元素参数
52
+ * @returns 是否更新成功
53
+ */
54
+ updateSchema?: (schema: SchemaValue, params: string) => boolean;
55
+ /**
56
+ * 渲染预览(可选)
57
+ * @param schema - Schema 数据(支持所有 JSON 类型)
58
+ * @param containerId - 预览容器 ID
59
+ * @returns 清理函数(可选)
60
+ *
61
+ * 特殊值说明:
62
+ * - undefined(默认):不关心预览功能,不参与优先级竞争
63
+ * - null:明确阻止预览功能,参与优先级竞争但告诉插件不支持预览(触发内置预览器)
64
+ * - function:提供预览功能,参与优先级竞争并正常渲染
65
+ */
66
+ renderPreview?: ((schema: SchemaValue, containerId: string) => (() => void) | void) | null;
67
+ /** 消息标识配置(可选,有默认值) */
68
+ sourceConfig?: Partial<PostMessageSourceConfig>;
69
+ /** 消息类型配置(可选,有默认值) */
70
+ messageTypes?: Partial<PostMessageTypeConfig>;
71
+ /**
72
+ * SDK 实例唯一标识(可选,自动生成)
73
+ * 用于多 SDK 实例协调
74
+ */
75
+ sdkId?: string;
76
+ /**
77
+ * SDK 优先级(可选,默认 0)
78
+ * 数值越大优先级越高,当多个 SDK 实例共存时,优先级高的响应请求
79
+ */
80
+ level?: number;
81
+ /**
82
+ * 方法级别优先级配置(可选)
83
+ * 可以为每个方法单独配置优先级,未配置的方法使用 level 作为优先级
84
+ */
85
+ methodLevels?: MethodLevelConfig;
86
+ }
87
+ /**
88
+ * 录制相关方法
89
+ */
90
+ interface SchemaElementEditorRecording {
91
+ /**
92
+ * 推送 Schema 数据(SDK 内部判断是否在录制,未录制时静默忽略)
93
+ * @param params - 元素参数(data-id 的值)
94
+ * @param data - Schema 数据
95
+ */
96
+ push: (params: string, data: SchemaValue) => void;
97
+ }
98
+ /**
99
+ * Schema Element Editor 桥接器返回值
100
+ */
101
+ interface SchemaElementEditorBridge {
102
+ /** 清理桥接器,移除事件监听 */
103
+ cleanup: () => void;
104
+ /** 录制相关方法 */
105
+ recording: SchemaElementEditorRecording;
106
+ }
107
+
108
+ export type { MethodLevelConfig as M, PostMessageSourceConfig as P, SchemaValue as S, PostMessageTypeConfig as a, SchemaElementEditorConfig as b, SchemaElementEditorBridge as c, SchemaElementEditorRecording as d };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Schema Element Editor Host SDK - Types
3
+ * 类型定义
4
+ */
5
+ /**
6
+ * Schema 数据类型
7
+ * 支持所有 JSON.parse 可返回的类型
8
+ */
9
+ type SchemaValue = Record<string, unknown> | unknown[] | string | number | boolean | null;
10
+ /** postMessage 消息标识配置 */
11
+ interface PostMessageSourceConfig {
12
+ /** 插件端发送消息的 source 标识 */
13
+ contentSource: string;
14
+ /** 宿主端响应消息的 source 标识 */
15
+ hostSource: string;
16
+ }
17
+ /** postMessage 消息类型配置 */
18
+ interface PostMessageTypeConfig {
19
+ getSchema: string;
20
+ updateSchema: string;
21
+ checkPreview: string;
22
+ renderPreview: string;
23
+ cleanupPreview: string;
24
+ startRecording: string;
25
+ stopRecording: string;
26
+ schemaPush: string;
27
+ }
28
+ /** SDK 方法级别配置 */
29
+ interface MethodLevelConfig {
30
+ getSchema?: number;
31
+ updateSchema?: number;
32
+ checkPreview?: number;
33
+ renderPreview?: number;
34
+ cleanupPreview?: number;
35
+ startRecording?: number;
36
+ stopRecording?: number;
37
+ }
38
+ /**
39
+ * Schema Element Editor 配置接口
40
+ */
41
+ interface SchemaElementEditorConfig {
42
+ /**
43
+ * 获取 Schema 数据(可选)
44
+ * @param params - 元素参数(通常是 data-id 的值)
45
+ * @returns Schema 数据(支持所有 JSON 类型)
46
+ */
47
+ getSchema?: (params: string) => SchemaValue;
48
+ /**
49
+ * 更新 Schema 数据(可选)
50
+ * @param schema - 新的 Schema 数据(支持所有 JSON 类型)
51
+ * @param params - 元素参数
52
+ * @returns 是否更新成功
53
+ */
54
+ updateSchema?: (schema: SchemaValue, params: string) => boolean;
55
+ /**
56
+ * 渲染预览(可选)
57
+ * @param schema - Schema 数据(支持所有 JSON 类型)
58
+ * @param containerId - 预览容器 ID
59
+ * @returns 清理函数(可选)
60
+ *
61
+ * 特殊值说明:
62
+ * - undefined(默认):不关心预览功能,不参与优先级竞争
63
+ * - null:明确阻止预览功能,参与优先级竞争但告诉插件不支持预览(触发内置预览器)
64
+ * - function:提供预览功能,参与优先级竞争并正常渲染
65
+ */
66
+ renderPreview?: ((schema: SchemaValue, containerId: string) => (() => void) | void) | null;
67
+ /** 消息标识配置(可选,有默认值) */
68
+ sourceConfig?: Partial<PostMessageSourceConfig>;
69
+ /** 消息类型配置(可选,有默认值) */
70
+ messageTypes?: Partial<PostMessageTypeConfig>;
71
+ /**
72
+ * SDK 实例唯一标识(可选,自动生成)
73
+ * 用于多 SDK 实例协调
74
+ */
75
+ sdkId?: string;
76
+ /**
77
+ * SDK 优先级(可选,默认 0)
78
+ * 数值越大优先级越高,当多个 SDK 实例共存时,优先级高的响应请求
79
+ */
80
+ level?: number;
81
+ /**
82
+ * 方法级别优先级配置(可选)
83
+ * 可以为每个方法单独配置优先级,未配置的方法使用 level 作为优先级
84
+ */
85
+ methodLevels?: MethodLevelConfig;
86
+ }
87
+ /**
88
+ * 录制相关方法
89
+ */
90
+ interface SchemaElementEditorRecording {
91
+ /**
92
+ * 推送 Schema 数据(SDK 内部判断是否在录制,未录制时静默忽略)
93
+ * @param params - 元素参数(data-id 的值)
94
+ * @param data - Schema 数据
95
+ */
96
+ push: (params: string, data: SchemaValue) => void;
97
+ }
98
+ /**
99
+ * Schema Element Editor 桥接器返回值
100
+ */
101
+ interface SchemaElementEditorBridge {
102
+ /** 清理桥接器,移除事件监听 */
103
+ cleanup: () => void;
104
+ /** 录制相关方法 */
105
+ recording: SchemaElementEditorRecording;
106
+ }
107
+
108
+ export type { MethodLevelConfig as M, PostMessageSourceConfig as P, SchemaValue as S, PostMessageTypeConfig as a, SchemaElementEditorConfig as b, SchemaElementEditorBridge as c, SchemaElementEditorRecording as d };
package/dist/vue.cjs CHANGED
@@ -292,7 +292,7 @@ function createSchemaElementEditorBridge(config) {
292
292
  const implementedMethods = [];
293
293
  if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
294
294
  if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
295
- if (typeof renderPreview === "function") {
295
+ if (renderPreview !== void 0) {
296
296
  implementedMethods.push(
297
297
  METHOD_NAMES.CHECK_PREVIEW,
298
298
  METHOD_NAMES.RENDER_PREVIEW,
@@ -397,7 +397,8 @@ function createSchemaElementEditorBridge(config) {
397
397
  break;
398
398
  }
399
399
  case mergedMessageTypes.checkPreview: {
400
- result = { exists: typeof renderPreview2 === "function" };
400
+ const exists = typeof renderPreview2 === "function";
401
+ result = { exists };
401
402
  break;
402
403
  }
403
404
  case mergedMessageTypes.renderPreview: {
package/dist/vue.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MaybeRefOrGetter } from 'vue';
2
- import { S as SchemaValue, P as PostMessageSourceConfig, a as PostMessageTypeConfig, M as MethodLevelConfig, d as SchemaElementEditorRecording } from './types-D2ZJx8T_.cjs';
2
+ import { S as SchemaValue, P as PostMessageSourceConfig, a as PostMessageTypeConfig, M as MethodLevelConfig, d as SchemaElementEditorRecording } from './types-BSn4QaId.cjs';
3
3
 
4
4
  /**
5
5
  * Schema Element Editor Host SDK - Vue
@@ -21,8 +21,13 @@ interface VueSchemaElementEditorConfig {
21
21
  updateSchema: MaybeRefOrGetter<(schema: SchemaValue, params: string) => boolean>;
22
22
  /**
23
23
  * 渲染预览(可选)
24
+ *
25
+ * 特殊值说明:
26
+ * - undefined(默认):不关心预览功能,不参与优先级竞争
27
+ * - null:明确阻止预览功能,参与优先级竞争但告诉插件不支持预览(触发内置预览器)
28
+ * - function:提供预览功能,参与优先级竞争并正常渲染
24
29
  */
25
- renderPreview?: MaybeRefOrGetter<((schema: SchemaValue, containerId: string) => (() => void) | void) | undefined>;
30
+ renderPreview?: MaybeRefOrGetter<((schema: SchemaValue, containerId: string) => (() => void) | void) | null | undefined>;
26
31
  /**
27
32
  * 是否启用桥接(默认 true)
28
33
  * 设为 false 时不创建桥接器,不监听消息
package/dist/vue.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MaybeRefOrGetter } from 'vue';
2
- import { S as SchemaValue, P as PostMessageSourceConfig, a as PostMessageTypeConfig, M as MethodLevelConfig, d as SchemaElementEditorRecording } from './types-D2ZJx8T_.js';
2
+ import { S as SchemaValue, P as PostMessageSourceConfig, a as PostMessageTypeConfig, M as MethodLevelConfig, d as SchemaElementEditorRecording } from './types-BSn4QaId.js';
3
3
 
4
4
  /**
5
5
  * Schema Element Editor Host SDK - Vue
@@ -21,8 +21,13 @@ interface VueSchemaElementEditorConfig {
21
21
  updateSchema: MaybeRefOrGetter<(schema: SchemaValue, params: string) => boolean>;
22
22
  /**
23
23
  * 渲染预览(可选)
24
+ *
25
+ * 特殊值说明:
26
+ * - undefined(默认):不关心预览功能,不参与优先级竞争
27
+ * - null:明确阻止预览功能,参与优先级竞争但告诉插件不支持预览(触发内置预览器)
28
+ * - function:提供预览功能,参与优先级竞争并正常渲染
24
29
  */
25
- renderPreview?: MaybeRefOrGetter<((schema: SchemaValue, containerId: string) => (() => void) | void) | undefined>;
30
+ renderPreview?: MaybeRefOrGetter<((schema: SchemaValue, containerId: string) => (() => void) | void) | null | undefined>;
26
31
  /**
27
32
  * 是否启用桥接(默认 true)
28
33
  * 设为 false 时不创建桥接器,不监听消息
package/dist/vue.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSchemaElementEditorBridge
3
- } from "./chunk-DLMX4NDA.js";
3
+ } from "./chunk-H36IVM7V.js";
4
4
 
5
5
  // src/vue.ts
6
6
  import { onMounted, onUnmounted, watch, toValue } from "vue";
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@schema-element-editor/host-sdk",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "Schema Element Editor (SEE) 插件宿主接入 SDK,支持 React/Vue/纯 JS",
5
5
  "type": "module",
6
+ "packageManager": "bun@1.3.5",
6
7
  "main": "./dist/index.cjs",
7
8
  "module": "./dist/index.js",
8
9
  "types": "./dist/index.d.ts",
@@ -31,6 +32,10 @@
31
32
  "files": [
32
33
  "dist"
33
34
  ],
35
+ "scripts": {
36
+ "build": "tsup src/index.ts src/core.ts src/react.ts src/vue.ts --format esm,cjs --dts --out-dir dist --external react --external vue",
37
+ "prepublishOnly": "bun run build"
38
+ },
34
39
  "peerDependencies": {
35
40
  "react": ">=17.0.0",
36
41
  "vue": ">=3.0.0"
@@ -61,8 +66,5 @@
61
66
  "type": "git",
62
67
  "url": "https://github.com/hei-f/schema-element-editor.git",
63
68
  "directory": "packages/schema-element-editor-sdk"
64
- },
65
- "scripts": {
66
- "build": "tsup src/index.ts src/core.ts src/react.ts src/vue.ts --format esm,cjs --dts --out-dir dist --external react --external vue"
67
69
  }
68
- }
70
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 hei-f
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.