@leafer-ui/interaction-web 2.0.3 → 2.0.4

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": "@leafer-ui/interaction-web",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "@leafer-ui/interaction-web",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "2.0.3",
26
- "@leafer-ui/core": "2.0.3"
25
+ "@leafer/core": "2.0.4",
26
+ "@leafer-ui/core": "2.0.4"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "2.0.3"
29
+ "@leafer/interface": "2.0.4"
30
30
  }
31
31
  }
@@ -22,6 +22,10 @@ export class Interaction extends InteractionBase {
22
22
  protected viewEvents: IObject
23
23
  protected windowEvents: IObject
24
24
 
25
+ // 使用 ownerDocument 替代 window,以支持微前端环境(如 wujie)
26
+ // 在 wujie 中,ownerDocument 被代理到 shadow root,可以正常接收事件
27
+ protected get windowTarget(): EventTarget { const { view } = this; return (view && view.ownerDocument) || window }
28
+
25
29
  protected usePointer: boolean
26
30
  protected useMultiTouch: boolean
27
31
  protected useTouch: boolean
@@ -81,9 +85,10 @@ export class Interaction extends InteractionBase {
81
85
  view.addEventListener(name, viewEvents[name])
82
86
  }
83
87
 
88
+
84
89
  for (let name in windowEvents) {
85
90
  windowEvents[name] = windowEvents[name].bind(this)
86
- window.addEventListener(name, windowEvents[name])
91
+ this.windowTarget.addEventListener(name, windowEvents[name])
87
92
  }
88
93
  }
89
94
 
@@ -98,7 +103,7 @@ export class Interaction extends InteractionBase {
98
103
  }
99
104
 
100
105
  for (let name in windowEvents) {
101
- window.removeEventListener(name, windowEvents[name])
106
+ this.windowTarget.removeEventListener(name, windowEvents[name])
102
107
  this.windowEvents = {}
103
108
  }
104
109
  }
@@ -123,7 +128,10 @@ export class Interaction extends InteractionBase {
123
128
  }
124
129
 
125
130
  protected preventWindowPointer(e: UIEvent) {
126
- return !this.downData && e.target !== this.view
131
+ // 在微前端环境(如 wujie) shadow DOM 中,事件目标可能不是 canvas 本身
132
+ // 可使用 composedPath 检查事件路径中是否包含 canvas
133
+ if (this.downData || e.target === this.view) return false
134
+ return (this.config.shadowDOM && e.composedPath) ? !e.composedPath().includes(this.view) : true
127
135
  }
128
136
 
129
137
  // key
package/types/index.d.ts CHANGED
@@ -10,6 +10,7 @@ declare class Interaction extends InteractionBase {
10
10
  protected view: HTMLElement;
11
11
  protected viewEvents: IObject;
12
12
  protected windowEvents: IObject;
13
+ protected get windowTarget(): EventTarget;
13
14
  protected usePointer: boolean;
14
15
  protected useMultiTouch: boolean;
15
16
  protected useTouch: boolean;