@schema-element-editor/host-sdk 2.0.3 → 2.1.1
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/LICENSE +21 -0
- package/dist/chunk-3OZ7E3LK.js +391 -0
- package/dist/chunk-432BCQVI.js +0 -0
- package/dist/chunk-5URPGJPF.js +391 -0
- package/dist/chunk-APBK7FQZ.js +437 -0
- package/dist/chunk-BVGJ5UDR.js +390 -0
- package/dist/chunk-D67MT673.js +44 -0
- package/dist/chunk-DGO4Z6NW.js +399 -0
- package/dist/chunk-DLMX4NDA.js +456 -0
- package/dist/chunk-EIQP2PZ6.js +56 -0
- package/dist/chunk-IYQL6QJY.js +60 -0
- package/dist/chunk-LD4OEJ4X.js +56 -0
- package/dist/chunk-LJJYJHOZ.js +450 -0
- package/dist/chunk-MK3EDWC5.js +56 -0
- package/dist/chunk-MQTHVJYR.js +54 -0
- package/dist/chunk-NF4H2OT3.js +355 -0
- package/dist/chunk-NWZVU75I.js +54 -0
- package/dist/chunk-Q6EJUFM6.js +56 -0
- package/dist/chunk-R4LAS3QA.js +54 -0
- package/dist/chunk-XIS7CAP4.js +54 -0
- package/dist/chunk-Y2OF4YA4.js +54 -0
- package/dist/core.cjs +288 -1
- package/dist/core.d.cts +16 -81
- package/dist/core.d.ts +16 -81
- package/dist/core.js +2 -1
- package/dist/index.cjs +307 -7
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/react.cjs +307 -7
- package/dist/react.d.cts +2 -3
- package/dist/react.d.ts +2 -3
- package/dist/react.js +2 -2
- package/dist/types-D2ZJx8T_.d.cts +103 -0
- package/dist/types-D2ZJx8T_.d.ts +103 -0
- package/dist/vue.cjs +306 -5
- package/dist/vue.d.cts +17 -3
- package/dist/vue.d.ts +17 -3
- package/dist/vue.js +20 -4
- package/package.json +5 -6
package/dist/vue.cjs
CHANGED
|
@@ -25,11 +25,12 @@ __export(vue_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(vue_exports);
|
|
26
26
|
var import_vue = require("vue");
|
|
27
27
|
|
|
28
|
-
// src/
|
|
28
|
+
// src/constants.ts
|
|
29
29
|
var DEFAULT_SOURCE_CONFIG = {
|
|
30
30
|
contentSource: "schema-element-editor-content",
|
|
31
31
|
hostSource: "schema-element-editor-host"
|
|
32
32
|
};
|
|
33
|
+
var SDK_COORDINATOR_SOURCE = "schema-element-editor-sdk-coordinator";
|
|
33
34
|
var DEFAULT_MESSAGE_TYPES = {
|
|
34
35
|
getSchema: "GET_SCHEMA",
|
|
35
36
|
updateSchema: "UPDATE_SCHEMA",
|
|
@@ -41,8 +42,245 @@ var DEFAULT_MESSAGE_TYPES = {
|
|
|
41
42
|
stopRecording: "STOP_RECORDING",
|
|
42
43
|
schemaPush: "SCHEMA_PUSH"
|
|
43
44
|
};
|
|
45
|
+
var SDK_COORDINATION_MESSAGE_TYPES = {
|
|
46
|
+
register: "SDK_REGISTER",
|
|
47
|
+
unregister: "SDK_UNREGISTER",
|
|
48
|
+
query: "SDK_QUERY"
|
|
49
|
+
};
|
|
50
|
+
|
|
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
|
+
}
|
|
58
|
+
var SdkCoordinator = class {
|
|
59
|
+
constructor(config) {
|
|
60
|
+
/**
|
|
61
|
+
* SDK 销毁标志
|
|
62
|
+
*
|
|
63
|
+
* 作用:防止在 cleanup() 执行期间,监听器移除前仍然响应请求
|
|
64
|
+
*
|
|
65
|
+
* 场景:cleanup() 中先调用 destroy()(设置 isDestroyed = true),
|
|
66
|
+
* 然后才移除 handleMessage 监听器。在这个微小的时间窗口内,
|
|
67
|
+
* 如果插件请求到达,没有 isDestroyed 检查会导致已销毁的 SDK 仍然响应。
|
|
68
|
+
*/
|
|
69
|
+
this.isDestroyed = false;
|
|
70
|
+
/**
|
|
71
|
+
* 存储比当前 SDK 优先级更高的其他 SDK ID
|
|
72
|
+
* 按方法分类:如果某个方法的集合不为空,说明有更高优先级的 SDK 应该处理该方法
|
|
73
|
+
*
|
|
74
|
+
* 优化:只为当前 SDK 实现了的方法维护优先级集合
|
|
75
|
+
*/
|
|
76
|
+
this.higherLevelSDKs = {};
|
|
77
|
+
/**
|
|
78
|
+
* 存储与当前 SDK 优先级相同的其他 SDK ID
|
|
79
|
+
* 按方法分类:用于判断是否需要在执行失败时跳过响应
|
|
80
|
+
*
|
|
81
|
+
* 当有同级竞争者时,SDK在执行失败/无数据时会跳过响应,让其他SDK有机会响应
|
|
82
|
+
*/
|
|
83
|
+
this.sameLevelSDKs = {};
|
|
84
|
+
/**
|
|
85
|
+
* 处理 SDK 协调消息
|
|
86
|
+
*/
|
|
87
|
+
this.handleCoordinationMessage = (event) => {
|
|
88
|
+
const isFromSelf = event.source === window;
|
|
89
|
+
const isFromParent = window !== window.top && event.source === window.parent;
|
|
90
|
+
if (!isFromSelf && !isFromParent) return;
|
|
91
|
+
const data = event.data;
|
|
92
|
+
if (!data || data.source !== SDK_COORDINATOR_SOURCE) return;
|
|
93
|
+
switch (data.type) {
|
|
94
|
+
case SDK_COORDINATION_MESSAGE_TYPES.query:
|
|
95
|
+
this.sendRegister();
|
|
96
|
+
break;
|
|
97
|
+
case SDK_COORDINATION_MESSAGE_TYPES.register:
|
|
98
|
+
this.handleSdkRegister(data.payload);
|
|
99
|
+
break;
|
|
100
|
+
case SDK_COORDINATION_MESSAGE_TYPES.unregister:
|
|
101
|
+
this.handleSdkUnregister(data.payload.sdkId);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
this.sdkId = config.sdkId || generateSdkId();
|
|
106
|
+
this.messageSource = config.messageSource;
|
|
107
|
+
this.level = config.level ?? 0;
|
|
108
|
+
this.methodLevels = config.methodLevels ?? {};
|
|
109
|
+
this.implementedMethods = config.implementedMethods;
|
|
110
|
+
this.implementedMethods.forEach((method) => {
|
|
111
|
+
this.higherLevelSDKs[method] = /* @__PURE__ */ new Set();
|
|
112
|
+
this.sameLevelSDKs[method] = /* @__PURE__ */ new Set();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 初始化协调器
|
|
117
|
+
*/
|
|
118
|
+
init() {
|
|
119
|
+
window.addEventListener("message", this.handleCoordinationMessage);
|
|
120
|
+
this.sendQuery();
|
|
121
|
+
this.sendRegister();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 销毁协调器
|
|
125
|
+
*/
|
|
126
|
+
destroy() {
|
|
127
|
+
this.isDestroyed = true;
|
|
128
|
+
this.sendUnregister();
|
|
129
|
+
window.removeEventListener("message", this.handleCoordinationMessage);
|
|
130
|
+
Object.values(this.higherLevelSDKs).forEach((set) => set.clear());
|
|
131
|
+
Object.values(this.sameLevelSDKs).forEach((set) => set.clear());
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 判断是否应该响应某个方法的请求
|
|
135
|
+
* @param method - 方法名
|
|
136
|
+
* @returns 是否应该响应
|
|
137
|
+
*/
|
|
138
|
+
shouldRespond(method) {
|
|
139
|
+
if (this.isDestroyed) return false;
|
|
140
|
+
if (!this.implementedMethods.includes(method)) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const higherSDKs = this.higherLevelSDKs[method];
|
|
144
|
+
return !higherSDKs || higherSDKs.size === 0;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 判断某个方法是否有相同优先级的竞争者
|
|
148
|
+
* @param method - 方法名
|
|
149
|
+
* @returns 是否存在同级竞争者
|
|
150
|
+
*/
|
|
151
|
+
hasSameLevelCompetitors(method) {
|
|
152
|
+
const sameSDKs = this.sameLevelSDKs[method];
|
|
153
|
+
return sameSDKs ? sameSDKs.size > 0 : false;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 获取方法的优先级
|
|
157
|
+
*/
|
|
158
|
+
getMethodLevel(method) {
|
|
159
|
+
return this.methodLevels[method] ?? this.level;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 处理其他 SDK 的注册
|
|
163
|
+
*/
|
|
164
|
+
handleSdkRegister(info) {
|
|
165
|
+
if (info.sdkId === this.sdkId) return;
|
|
166
|
+
if (info.messageSource !== this.messageSource) return;
|
|
167
|
+
this.implementedMethods.forEach((method) => {
|
|
168
|
+
if (!info.implementedMethods.includes(method)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const myLevel = this.getMethodLevel(method);
|
|
172
|
+
const otherLevel = info.methodLevels[method] ?? info.level;
|
|
173
|
+
if (otherLevel > myLevel) {
|
|
174
|
+
this.higherLevelSDKs[method].add(info.sdkId);
|
|
175
|
+
this.sameLevelSDKs[method].delete(info.sdkId);
|
|
176
|
+
} else if (otherLevel === myLevel) {
|
|
177
|
+
this.sameLevelSDKs[method].add(info.sdkId);
|
|
178
|
+
this.higherLevelSDKs[method].delete(info.sdkId);
|
|
179
|
+
} else {
|
|
180
|
+
this.higherLevelSDKs[method].delete(info.sdkId);
|
|
181
|
+
this.sameLevelSDKs[method].delete(info.sdkId);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* 处理其他 SDK 的注销
|
|
187
|
+
*/
|
|
188
|
+
handleSdkUnregister(sdkId) {
|
|
189
|
+
Object.values(this.higherLevelSDKs).forEach((set) => {
|
|
190
|
+
set.delete(sdkId);
|
|
191
|
+
});
|
|
192
|
+
Object.values(this.sameLevelSDKs).forEach((set) => {
|
|
193
|
+
set.delete(sdkId);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 发送查询消息
|
|
198
|
+
*/
|
|
199
|
+
sendQuery() {
|
|
200
|
+
const message = {
|
|
201
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
202
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.query,
|
|
203
|
+
payload: { sdkId: this.sdkId }
|
|
204
|
+
};
|
|
205
|
+
this.postCoordinationMessage(message);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 发送注册消息
|
|
209
|
+
*/
|
|
210
|
+
sendRegister() {
|
|
211
|
+
const message = {
|
|
212
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
213
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.register,
|
|
214
|
+
payload: {
|
|
215
|
+
sdkId: this.sdkId,
|
|
216
|
+
messageSource: this.messageSource,
|
|
217
|
+
level: this.level,
|
|
218
|
+
methodLevels: this.methodLevels,
|
|
219
|
+
implementedMethods: this.implementedMethods
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
this.postCoordinationMessage(message);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 发送注销消息
|
|
226
|
+
*/
|
|
227
|
+
sendUnregister() {
|
|
228
|
+
const message = {
|
|
229
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
230
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.unregister,
|
|
231
|
+
payload: { sdkId: this.sdkId }
|
|
232
|
+
};
|
|
233
|
+
this.postCoordinationMessage(message);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 发送协调消息
|
|
237
|
+
*/
|
|
238
|
+
postCoordinationMessage(message) {
|
|
239
|
+
window.postMessage(message, "*");
|
|
240
|
+
if (window.top && window.top !== window) {
|
|
241
|
+
window.top.postMessage(message, "*");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// src/bridge.ts
|
|
247
|
+
var METHOD_NAMES = {
|
|
248
|
+
GET_SCHEMA: "getSchema",
|
|
249
|
+
UPDATE_SCHEMA: "updateSchema",
|
|
250
|
+
CHECK_PREVIEW: "checkPreview",
|
|
251
|
+
RENDER_PREVIEW: "renderPreview",
|
|
252
|
+
CLEANUP_PREVIEW: "cleanupPreview",
|
|
253
|
+
START_RECORDING: "startRecording",
|
|
254
|
+
STOP_RECORDING: "stopRecording"
|
|
255
|
+
};
|
|
256
|
+
function shouldSkipFailedResponse(method, result) {
|
|
257
|
+
switch (method) {
|
|
258
|
+
case METHOD_NAMES.GET_SCHEMA:
|
|
259
|
+
return result.success === true && result.data === void 0;
|
|
260
|
+
case METHOD_NAMES.UPDATE_SCHEMA:
|
|
261
|
+
return result.success === false;
|
|
262
|
+
case METHOD_NAMES.RENDER_PREVIEW:
|
|
263
|
+
case METHOD_NAMES.CLEANUP_PREVIEW:
|
|
264
|
+
return result.success === false;
|
|
265
|
+
case METHOD_NAMES.CHECK_PREVIEW:
|
|
266
|
+
case METHOD_NAMES.START_RECORDING:
|
|
267
|
+
case METHOD_NAMES.STOP_RECORDING:
|
|
268
|
+
return false;
|
|
269
|
+
default:
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
44
273
|
function createSchemaElementEditorBridge(config) {
|
|
45
|
-
const {
|
|
274
|
+
const {
|
|
275
|
+
getSchema,
|
|
276
|
+
updateSchema,
|
|
277
|
+
renderPreview,
|
|
278
|
+
sourceConfig,
|
|
279
|
+
messageTypes,
|
|
280
|
+
sdkId,
|
|
281
|
+
level,
|
|
282
|
+
methodLevels
|
|
283
|
+
} = config;
|
|
46
284
|
const mergedSourceConfig = {
|
|
47
285
|
...DEFAULT_SOURCE_CONFIG,
|
|
48
286
|
...sourceConfig
|
|
@@ -51,9 +289,40 @@ function createSchemaElementEditorBridge(config) {
|
|
|
51
289
|
...DEFAULT_MESSAGE_TYPES,
|
|
52
290
|
...messageTypes
|
|
53
291
|
};
|
|
292
|
+
const implementedMethods = [];
|
|
293
|
+
if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
|
|
294
|
+
if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
|
|
295
|
+
if (typeof renderPreview === "function") {
|
|
296
|
+
implementedMethods.push(
|
|
297
|
+
METHOD_NAMES.CHECK_PREVIEW,
|
|
298
|
+
METHOD_NAMES.RENDER_PREVIEW,
|
|
299
|
+
METHOD_NAMES.CLEANUP_PREVIEW
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
implementedMethods.push(METHOD_NAMES.START_RECORDING, METHOD_NAMES.STOP_RECORDING);
|
|
303
|
+
const coordinator = new SdkCoordinator({
|
|
304
|
+
sdkId,
|
|
305
|
+
messageSource: mergedSourceConfig.contentSource,
|
|
306
|
+
level,
|
|
307
|
+
methodLevels,
|
|
308
|
+
implementedMethods
|
|
309
|
+
});
|
|
310
|
+
coordinator.init();
|
|
54
311
|
let previewCleanupFn = null;
|
|
55
312
|
const recordingParams = /* @__PURE__ */ new Set();
|
|
56
313
|
const currentConfig = { getSchema, updateSchema, renderPreview };
|
|
314
|
+
const methodTypeToName = {
|
|
315
|
+
[mergedMessageTypes.getSchema]: METHOD_NAMES.GET_SCHEMA,
|
|
316
|
+
[mergedMessageTypes.updateSchema]: METHOD_NAMES.UPDATE_SCHEMA,
|
|
317
|
+
[mergedMessageTypes.checkPreview]: METHOD_NAMES.CHECK_PREVIEW,
|
|
318
|
+
[mergedMessageTypes.renderPreview]: METHOD_NAMES.RENDER_PREVIEW,
|
|
319
|
+
[mergedMessageTypes.cleanupPreview]: METHOD_NAMES.CLEANUP_PREVIEW,
|
|
320
|
+
[mergedMessageTypes.startRecording]: METHOD_NAMES.START_RECORDING,
|
|
321
|
+
[mergedMessageTypes.stopRecording]: METHOD_NAMES.STOP_RECORDING
|
|
322
|
+
};
|
|
323
|
+
const getMethodNameByType = (type) => {
|
|
324
|
+
return methodTypeToName[type] ?? null;
|
|
325
|
+
};
|
|
57
326
|
const sendResponse = (requestId, result) => {
|
|
58
327
|
const message = {
|
|
59
328
|
source: mergedSourceConfig.hostSource,
|
|
@@ -86,10 +355,18 @@ function createSchemaElementEditorBridge(config) {
|
|
|
86
355
|
if (!event.data || event.data.source !== mergedSourceConfig.contentSource) return;
|
|
87
356
|
const { type, payload, requestId } = event.data;
|
|
88
357
|
if (!requestId) return;
|
|
358
|
+
const methodName = getMethodNameByType(type);
|
|
359
|
+
if (!methodName) return;
|
|
360
|
+
if (!coordinator.shouldRespond(methodName)) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
89
363
|
const { getSchema: getSchema2, updateSchema: updateSchema2, renderPreview: renderPreview2 } = currentConfig;
|
|
90
364
|
let result;
|
|
91
365
|
switch (type) {
|
|
92
366
|
case mergedMessageTypes.getSchema: {
|
|
367
|
+
if (typeof getSchema2 !== "function") {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
93
370
|
const params = String(payload?.params ?? "");
|
|
94
371
|
try {
|
|
95
372
|
const data = getSchema2(params);
|
|
@@ -103,6 +380,9 @@ function createSchemaElementEditorBridge(config) {
|
|
|
103
380
|
break;
|
|
104
381
|
}
|
|
105
382
|
case mergedMessageTypes.updateSchema: {
|
|
383
|
+
if (typeof updateSchema2 !== "function") {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
106
386
|
const schema = payload?.schema;
|
|
107
387
|
const params = String(payload?.params ?? "");
|
|
108
388
|
try {
|
|
@@ -175,11 +455,16 @@ function createSchemaElementEditorBridge(config) {
|
|
|
175
455
|
default:
|
|
176
456
|
return;
|
|
177
457
|
}
|
|
458
|
+
const hasSameLevelSdks = coordinator.hasSameLevelCompetitors(methodName);
|
|
459
|
+
if (hasSameLevelSdks && shouldSkipFailedResponse(methodName, result)) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
178
462
|
sendResponse(requestId, result);
|
|
179
463
|
};
|
|
180
464
|
window.addEventListener("message", handleMessage);
|
|
181
465
|
return {
|
|
182
466
|
cleanup: () => {
|
|
467
|
+
coordinator.destroy();
|
|
183
468
|
window.removeEventListener("message", handleMessage);
|
|
184
469
|
if (previewCleanupFn) {
|
|
185
470
|
previewCleanupFn();
|
|
@@ -195,7 +480,17 @@ function createSchemaElementEditorBridge(config) {
|
|
|
195
480
|
|
|
196
481
|
// src/vue.ts
|
|
197
482
|
function useSchemaElementEditor(config) {
|
|
198
|
-
const {
|
|
483
|
+
const {
|
|
484
|
+
getSchema,
|
|
485
|
+
updateSchema,
|
|
486
|
+
renderPreview,
|
|
487
|
+
sourceConfig,
|
|
488
|
+
messageTypes,
|
|
489
|
+
enabled,
|
|
490
|
+
sdkId,
|
|
491
|
+
level,
|
|
492
|
+
methodLevels
|
|
493
|
+
} = config;
|
|
199
494
|
let bridge = null;
|
|
200
495
|
const destroyBridge = () => {
|
|
201
496
|
if (bridge) {
|
|
@@ -213,7 +508,10 @@ function useSchemaElementEditor(config) {
|
|
|
213
508
|
updateSchema: (schema, params) => (0, import_vue.toValue)(updateSchema)(schema, params),
|
|
214
509
|
renderPreview: (0, import_vue.toValue)(renderPreview) ? (schema, containerId) => (0, import_vue.toValue)(renderPreview)?.(schema, containerId) : void 0,
|
|
215
510
|
sourceConfig,
|
|
216
|
-
messageTypes
|
|
511
|
+
messageTypes,
|
|
512
|
+
sdkId,
|
|
513
|
+
level,
|
|
514
|
+
methodLevels
|
|
217
515
|
};
|
|
218
516
|
bridge = createSchemaElementEditorBridge(proxyConfig);
|
|
219
517
|
};
|
|
@@ -235,7 +533,10 @@ function useSchemaElementEditor(config) {
|
|
|
235
533
|
messageTypes?.cleanupPreview,
|
|
236
534
|
messageTypes?.startRecording,
|
|
237
535
|
messageTypes?.stopRecording,
|
|
238
|
-
messageTypes?.schemaPush
|
|
536
|
+
messageTypes?.schemaPush,
|
|
537
|
+
sdkId,
|
|
538
|
+
level,
|
|
539
|
+
methodLevels
|
|
239
540
|
],
|
|
240
541
|
() => {
|
|
241
542
|
createBridgeInstance();
|
package/dist/vue.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
-
import { SchemaValue, PostMessageSourceConfig, PostMessageTypeConfig, SchemaElementEditorRecording } from './
|
|
3
|
-
export { SchemaElementEditorBridge, SchemaElementEditorConfig } from './core.cjs';
|
|
2
|
+
import { S as SchemaValue, P as PostMessageSourceConfig, a as PostMessageTypeConfig, M as MethodLevelConfig, d as SchemaElementEditorRecording } from './types-D2ZJx8T_.cjs';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Schema Element Editor Host SDK - Vue
|
|
@@ -34,6 +33,21 @@ interface VueSchemaElementEditorConfig {
|
|
|
34
33
|
sourceConfig?: Partial<PostMessageSourceConfig>;
|
|
35
34
|
/** 消息类型配置(可选,有默认值) */
|
|
36
35
|
messageTypes?: Partial<PostMessageTypeConfig>;
|
|
36
|
+
/**
|
|
37
|
+
* SDK 实例唯一标识(可选,自动生成)
|
|
38
|
+
* 用于多 SDK 实例协调
|
|
39
|
+
*/
|
|
40
|
+
sdkId?: string;
|
|
41
|
+
/**
|
|
42
|
+
* SDK 优先级(可选,默认 0)
|
|
43
|
+
* 数值越大优先级越高,当多个 SDK 实例共存时,优先级高的响应请求
|
|
44
|
+
*/
|
|
45
|
+
level?: number;
|
|
46
|
+
/**
|
|
47
|
+
* 方法级别优先级配置(可选)
|
|
48
|
+
* 可以为每个方法单独配置优先级,未配置的方法使用 level 作为优先级
|
|
49
|
+
*/
|
|
50
|
+
methodLevels?: MethodLevelConfig;
|
|
37
51
|
}
|
|
38
52
|
/** Vue composable 返回值 */
|
|
39
53
|
interface UseSchemaElementEditorReturn {
|
|
@@ -70,4 +84,4 @@ interface UseSchemaElementEditorReturn {
|
|
|
70
84
|
*/
|
|
71
85
|
declare function useSchemaElementEditor(config: VueSchemaElementEditorConfig): UseSchemaElementEditorReturn;
|
|
72
86
|
|
|
73
|
-
export {
|
|
87
|
+
export { type UseSchemaElementEditorReturn, type VueSchemaElementEditorConfig, useSchemaElementEditor };
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
-
import { SchemaValue, PostMessageSourceConfig, PostMessageTypeConfig, SchemaElementEditorRecording } from './
|
|
3
|
-
export { SchemaElementEditorBridge, SchemaElementEditorConfig } from './core.js';
|
|
2
|
+
import { S as SchemaValue, P as PostMessageSourceConfig, a as PostMessageTypeConfig, M as MethodLevelConfig, d as SchemaElementEditorRecording } from './types-D2ZJx8T_.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Schema Element Editor Host SDK - Vue
|
|
@@ -34,6 +33,21 @@ interface VueSchemaElementEditorConfig {
|
|
|
34
33
|
sourceConfig?: Partial<PostMessageSourceConfig>;
|
|
35
34
|
/** 消息类型配置(可选,有默认值) */
|
|
36
35
|
messageTypes?: Partial<PostMessageTypeConfig>;
|
|
36
|
+
/**
|
|
37
|
+
* SDK 实例唯一标识(可选,自动生成)
|
|
38
|
+
* 用于多 SDK 实例协调
|
|
39
|
+
*/
|
|
40
|
+
sdkId?: string;
|
|
41
|
+
/**
|
|
42
|
+
* SDK 优先级(可选,默认 0)
|
|
43
|
+
* 数值越大优先级越高,当多个 SDK 实例共存时,优先级高的响应请求
|
|
44
|
+
*/
|
|
45
|
+
level?: number;
|
|
46
|
+
/**
|
|
47
|
+
* 方法级别优先级配置(可选)
|
|
48
|
+
* 可以为每个方法单独配置优先级,未配置的方法使用 level 作为优先级
|
|
49
|
+
*/
|
|
50
|
+
methodLevels?: MethodLevelConfig;
|
|
37
51
|
}
|
|
38
52
|
/** Vue composable 返回值 */
|
|
39
53
|
interface UseSchemaElementEditorReturn {
|
|
@@ -70,4 +84,4 @@ interface UseSchemaElementEditorReturn {
|
|
|
70
84
|
*/
|
|
71
85
|
declare function useSchemaElementEditor(config: VueSchemaElementEditorConfig): UseSchemaElementEditorReturn;
|
|
72
86
|
|
|
73
|
-
export {
|
|
87
|
+
export { type UseSchemaElementEditorReturn, type VueSchemaElementEditorConfig, useSchemaElementEditor };
|
package/dist/vue.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createSchemaElementEditorBridge
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DLMX4NDA.js";
|
|
4
4
|
|
|
5
5
|
// src/vue.ts
|
|
6
6
|
import { onMounted, onUnmounted, watch, toValue } from "vue";
|
|
7
7
|
function useSchemaElementEditor(config) {
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
getSchema,
|
|
10
|
+
updateSchema,
|
|
11
|
+
renderPreview,
|
|
12
|
+
sourceConfig,
|
|
13
|
+
messageTypes,
|
|
14
|
+
enabled,
|
|
15
|
+
sdkId,
|
|
16
|
+
level,
|
|
17
|
+
methodLevels
|
|
18
|
+
} = config;
|
|
9
19
|
let bridge = null;
|
|
10
20
|
const destroyBridge = () => {
|
|
11
21
|
if (bridge) {
|
|
@@ -23,7 +33,10 @@ function useSchemaElementEditor(config) {
|
|
|
23
33
|
updateSchema: (schema, params) => toValue(updateSchema)(schema, params),
|
|
24
34
|
renderPreview: toValue(renderPreview) ? (schema, containerId) => toValue(renderPreview)?.(schema, containerId) : void 0,
|
|
25
35
|
sourceConfig,
|
|
26
|
-
messageTypes
|
|
36
|
+
messageTypes,
|
|
37
|
+
sdkId,
|
|
38
|
+
level,
|
|
39
|
+
methodLevels
|
|
27
40
|
};
|
|
28
41
|
bridge = createSchemaElementEditorBridge(proxyConfig);
|
|
29
42
|
};
|
|
@@ -45,7 +58,10 @@ function useSchemaElementEditor(config) {
|
|
|
45
58
|
messageTypes?.cleanupPreview,
|
|
46
59
|
messageTypes?.startRecording,
|
|
47
60
|
messageTypes?.stopRecording,
|
|
48
|
-
messageTypes?.schemaPush
|
|
61
|
+
messageTypes?.schemaPush,
|
|
62
|
+
sdkId,
|
|
63
|
+
level,
|
|
64
|
+
methodLevels
|
|
49
65
|
],
|
|
50
66
|
() => {
|
|
51
67
|
createBridgeInstance();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schema-element-editor/host-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Schema Element Editor (SEE) 插件宿主接入 SDK,支持 React/Vue/纯 JS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -31,10 +31,6 @@
|
|
|
31
31
|
"files": [
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
|
-
"scripts": {
|
|
35
|
-
"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",
|
|
36
|
-
"prepublishOnly": "npm run build"
|
|
37
|
-
},
|
|
38
34
|
"peerDependencies": {
|
|
39
35
|
"react": ">=17.0.0",
|
|
40
36
|
"vue": ">=3.0.0"
|
|
@@ -65,5 +61,8 @@
|
|
|
65
61
|
"type": "git",
|
|
66
62
|
"url": "https://github.com/hei-f/schema-element-editor.git",
|
|
67
63
|
"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"
|
|
68
67
|
}
|
|
69
|
-
}
|
|
68
|
+
}
|