@schema-element-editor/host-sdk 2.1.0 → 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/chunk-47WAIVL6.js +492 -0
- package/dist/chunk-4TXQK4JI.js +456 -0
- package/dist/chunk-7FYOUPVO.js +60 -0
- package/dist/chunk-7REKUAOO.js +56 -0
- package/dist/chunk-DLMX4NDA.js +456 -0
- package/dist/chunk-H36IVM7V.js +457 -0
- package/dist/chunk-MK3EDWC5.js +56 -0
- package/dist/chunk-TBIBZD62.js +56 -0
- package/dist/chunk-X4JAISLV.js +60 -0
- package/dist/core.cjs +10 -3
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/index.cjs +15 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/react.cjs +15 -4
- package/dist/react.d.cts +11 -2
- package/dist/react.d.ts +11 -2
- package/dist/react.js +2 -2
- package/dist/types-BSn4QaId.d.cts +108 -0
- package/dist/types-BSn4QaId.d.ts +108 -0
- package/dist/vue.cjs +10 -3
- package/dist/vue.d.cts +7 -2
- package/dist/vue.d.ts +7 -2
- package/dist/vue.js +1 -1
- package/package.json +7 -5
- package/LICENSE +0 -21
package/dist/index.cjs
CHANGED
|
@@ -52,6 +52,12 @@ var SDK_COORDINATION_MESSAGE_TYPES = {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
// src/coordinator.ts
|
|
55
|
+
function generateSdkId() {
|
|
56
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
57
|
+
return crypto.randomUUID();
|
|
58
|
+
}
|
|
59
|
+
return `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
60
|
+
}
|
|
55
61
|
var SdkCoordinator = class {
|
|
56
62
|
constructor(config) {
|
|
57
63
|
/**
|
|
@@ -99,7 +105,7 @@ var SdkCoordinator = class {
|
|
|
99
105
|
break;
|
|
100
106
|
}
|
|
101
107
|
};
|
|
102
|
-
this.sdkId = config.sdkId ||
|
|
108
|
+
this.sdkId = config.sdkId || generateSdkId();
|
|
103
109
|
this.messageSource = config.messageSource;
|
|
104
110
|
this.level = config.level ?? 0;
|
|
105
111
|
this.methodLevels = config.methodLevels ?? {};
|
|
@@ -289,7 +295,7 @@ function createSchemaElementEditorBridge(config) {
|
|
|
289
295
|
const implementedMethods = [];
|
|
290
296
|
if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
|
|
291
297
|
if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
|
|
292
|
-
if (
|
|
298
|
+
if (renderPreview !== void 0) {
|
|
293
299
|
implementedMethods.push(
|
|
294
300
|
METHOD_NAMES.CHECK_PREVIEW,
|
|
295
301
|
METHOD_NAMES.RENDER_PREVIEW,
|
|
@@ -394,7 +400,8 @@ function createSchemaElementEditorBridge(config) {
|
|
|
394
400
|
break;
|
|
395
401
|
}
|
|
396
402
|
case mergedMessageTypes.checkPreview: {
|
|
397
|
-
|
|
403
|
+
const exists = typeof renderPreview2 === "function";
|
|
404
|
+
result = { exists };
|
|
398
405
|
break;
|
|
399
406
|
}
|
|
400
407
|
case mergedMessageTypes.renderPreview: {
|
|
@@ -502,7 +509,11 @@ function useSchemaElementEditor(config) {
|
|
|
502
509
|
// 内层使用可选链安全访问,配合类型断言确保类型正确
|
|
503
510
|
getSchema: configRef.current.getSchema ? (params) => configRef.current.getSchema?.(params) : void 0,
|
|
504
511
|
updateSchema: configRef.current.updateSchema ? (schema, params) => configRef.current.updateSchema?.(schema, params) : void 0,
|
|
505
|
-
|
|
512
|
+
// renderPreview 需要特殊处理:
|
|
513
|
+
// - undefined: 不传递(不参与竞争)
|
|
514
|
+
// - null: 传递 null(参与竞争但阻止预览)
|
|
515
|
+
// - function: 创建代理函数
|
|
516
|
+
renderPreview: configRef.current.renderPreview === null ? null : configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
|
|
506
517
|
sourceConfig,
|
|
507
518
|
messageTypes,
|
|
508
519
|
sdkId,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { useSchemaElementEditor } from './react.cjs';
|
|
1
|
+
export { ReactSchemaElementEditorConfig, useSchemaElementEditor } from './react.cjs';
|
|
2
2
|
export { createSchemaElementEditorBridge } from './core.cjs';
|
|
3
|
-
export { M as MethodLevelConfig, P as PostMessageSourceConfig, a as PostMessageTypeConfig, c as SchemaElementEditorBridge, b as SchemaElementEditorConfig, d as SchemaElementEditorRecording, S as SchemaValue } from './types-
|
|
3
|
+
export { M as MethodLevelConfig, P as PostMessageSourceConfig, a as PostMessageTypeConfig, c as SchemaElementEditorBridge, b as SchemaElementEditorConfig, d as SchemaElementEditorRecording, S as SchemaValue } from './types-BSn4QaId.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { useSchemaElementEditor } from './react.js';
|
|
1
|
+
export { ReactSchemaElementEditorConfig, useSchemaElementEditor } from './react.js';
|
|
2
2
|
export { createSchemaElementEditorBridge } from './core.js';
|
|
3
|
-
export { M as MethodLevelConfig, P as PostMessageSourceConfig, a as PostMessageTypeConfig, c as SchemaElementEditorBridge, b as SchemaElementEditorConfig, d as SchemaElementEditorRecording, S as SchemaValue } from './types-
|
|
3
|
+
export { M as MethodLevelConfig, P as PostMessageSourceConfig, a as PostMessageTypeConfig, c as SchemaElementEditorBridge, b as SchemaElementEditorConfig, d as SchemaElementEditorRecording, S as SchemaValue } from './types-BSn4QaId.js';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./chunk-432BCQVI.js";
|
|
2
2
|
import {
|
|
3
3
|
useSchemaElementEditor
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-X4JAISLV.js";
|
|
5
5
|
import {
|
|
6
6
|
createSchemaElementEditorBridge
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-H36IVM7V.js";
|
|
8
8
|
export {
|
|
9
9
|
createSchemaElementEditorBridge,
|
|
10
10
|
useSchemaElementEditor
|
package/dist/react.cjs
CHANGED
|
@@ -49,6 +49,12 @@ var SDK_COORDINATION_MESSAGE_TYPES = {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
// src/coordinator.ts
|
|
52
|
+
function generateSdkId() {
|
|
53
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
54
|
+
return crypto.randomUUID();
|
|
55
|
+
}
|
|
56
|
+
return `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
57
|
+
}
|
|
52
58
|
var SdkCoordinator = class {
|
|
53
59
|
constructor(config) {
|
|
54
60
|
/**
|
|
@@ -96,7 +102,7 @@ var SdkCoordinator = class {
|
|
|
96
102
|
break;
|
|
97
103
|
}
|
|
98
104
|
};
|
|
99
|
-
this.sdkId = config.sdkId ||
|
|
105
|
+
this.sdkId = config.sdkId || generateSdkId();
|
|
100
106
|
this.messageSource = config.messageSource;
|
|
101
107
|
this.level = config.level ?? 0;
|
|
102
108
|
this.methodLevels = config.methodLevels ?? {};
|
|
@@ -286,7 +292,7 @@ function createSchemaElementEditorBridge(config) {
|
|
|
286
292
|
const implementedMethods = [];
|
|
287
293
|
if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
|
|
288
294
|
if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
|
|
289
|
-
if (
|
|
295
|
+
if (renderPreview !== void 0) {
|
|
290
296
|
implementedMethods.push(
|
|
291
297
|
METHOD_NAMES.CHECK_PREVIEW,
|
|
292
298
|
METHOD_NAMES.RENDER_PREVIEW,
|
|
@@ -391,7 +397,8 @@ function createSchemaElementEditorBridge(config) {
|
|
|
391
397
|
break;
|
|
392
398
|
}
|
|
393
399
|
case mergedMessageTypes.checkPreview: {
|
|
394
|
-
|
|
400
|
+
const exists = typeof renderPreview2 === "function";
|
|
401
|
+
result = { exists };
|
|
395
402
|
break;
|
|
396
403
|
}
|
|
397
404
|
case mergedMessageTypes.renderPreview: {
|
|
@@ -499,7 +506,11 @@ function useSchemaElementEditor(config) {
|
|
|
499
506
|
// 内层使用可选链安全访问,配合类型断言确保类型正确
|
|
500
507
|
getSchema: configRef.current.getSchema ? (params) => configRef.current.getSchema?.(params) : void 0,
|
|
501
508
|
updateSchema: configRef.current.updateSchema ? (schema, params) => configRef.current.updateSchema?.(schema, params) : void 0,
|
|
502
|
-
|
|
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,
|
|
503
514
|
sourceConfig,
|
|
504
515
|
messageTypes,
|
|
505
516
|
sdkId,
|
package/dist/react.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as SchemaElementEditorConfig, d as SchemaElementEditorRecording } from './types-
|
|
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-
|
|
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
|
@@ -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
|
@@ -49,6 +49,12 @@ var SDK_COORDINATION_MESSAGE_TYPES = {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
// src/coordinator.ts
|
|
52
|
+
function generateSdkId() {
|
|
53
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
54
|
+
return crypto.randomUUID();
|
|
55
|
+
}
|
|
56
|
+
return `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
57
|
+
}
|
|
52
58
|
var SdkCoordinator = class {
|
|
53
59
|
constructor(config) {
|
|
54
60
|
/**
|
|
@@ -96,7 +102,7 @@ var SdkCoordinator = class {
|
|
|
96
102
|
break;
|
|
97
103
|
}
|
|
98
104
|
};
|
|
99
|
-
this.sdkId = config.sdkId ||
|
|
105
|
+
this.sdkId = config.sdkId || generateSdkId();
|
|
100
106
|
this.messageSource = config.messageSource;
|
|
101
107
|
this.level = config.level ?? 0;
|
|
102
108
|
this.methodLevels = config.methodLevels ?? {};
|
|
@@ -286,7 +292,7 @@ function createSchemaElementEditorBridge(config) {
|
|
|
286
292
|
const implementedMethods = [];
|
|
287
293
|
if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
|
|
288
294
|
if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
|
|
289
|
-
if (
|
|
295
|
+
if (renderPreview !== void 0) {
|
|
290
296
|
implementedMethods.push(
|
|
291
297
|
METHOD_NAMES.CHECK_PREVIEW,
|
|
292
298
|
METHOD_NAMES.RENDER_PREVIEW,
|
|
@@ -391,7 +397,8 @@ function createSchemaElementEditorBridge(config) {
|
|
|
391
397
|
break;
|
|
392
398
|
}
|
|
393
399
|
case mergedMessageTypes.checkPreview: {
|
|
394
|
-
|
|
400
|
+
const exists = typeof renderPreview2 === "function";
|
|
401
|
+
result = { exists };
|
|
395
402
|
break;
|
|
396
403
|
}
|
|
397
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-
|
|
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-
|
|
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
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schema-element-editor/host-sdk",
|
|
3
|
-
"version": "2.
|
|
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.
|