sur-onlyoffice 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sur-onlyoffice",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "文档",
5
5
  "main": "dist/onlyoffice.umd.js",
6
6
  "module": "dist/onlyoffice.es.js",
@@ -313,28 +313,14 @@ async function createEditor() {
313
313
  editor = new DocsAPI.DocEditor('editor', cfg)
314
314
 
315
315
 
316
- window.addEventListener('message', (event) => {
317
- // 安全检查:验证消息来源
318
- // if (event.origin !== 'https://iframe-domain.com') return;
319
316
 
320
-
321
- console.log(event,'event123')
322
-
323
- if (event.data.eventType === 'customEventReplay') {
324
- console.info(event,'DDD1')
325
- }
326
-
327
- if (event.data.eventType === 'customEventCommon') {
328
- console.info(event,'DDD2')
329
- }
330
- });
331
317
  }
332
318
 
333
319
  function autoOpenPluginSidePanel() {
334
320
  try {
335
321
  editor.executeCommand && editor.executeCommand('focus');
336
322
 
337
- console.log('123autoOpenPluginSidePanel',editor)
323
+ console.log('autoOpenPluginSidePanel',editor)
338
324
 
339
325
  // 先收起左侧面板
340
326
  // editor.frame?.contentWindow?.Common?.UI?.SidePanel?.hide?.();
@@ -1139,7 +1125,36 @@ function handleBindingClicked(data: any) {
1139
1125
  }
1140
1126
 
1141
1127
 
1142
- onMounted(() => createEditor())
1128
+
1129
+ // 使用标志确保监听器只注册一次
1130
+ let messageListenerRegistered = false;
1131
+ const messageHandler = (event) => {
1132
+ // 您的业务逻辑...
1133
+ if (event.data.eventType === 'customEventReplay') {
1134
+ console.info(event,'DDD1')
1135
+ }
1136
+
1137
+ if (event.data.eventType === 'customEventCommon') {
1138
+ console.info(event,'DDD2')
1139
+ }
1140
+ };
1141
+
1142
+
1143
+ onMounted(() =>{
1144
+
1145
+ createEditor()
1146
+
1147
+ if (!messageListenerRegistered) {
1148
+ window.addEventListener('message', messageHandler);
1149
+ messageListenerRegistered = true;
1150
+ console.log('✅ 消息监听器已注册');
1151
+ } else {
1152
+ console.warn('⚠️ 消息监听器已存在,跳过重复注册');
1153
+ }
1154
+
1155
+ })
1156
+
1157
+
1143
1158
  onBeforeUnmount(() => {
1144
1159
  if (editor?.destroyEditor) editor.destroyEditor()
1145
1160
  if (flushTimer !== null) clearInterval(flushTimer)