Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Contact.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@

欢迎小伙伴们加入micro-app微信群交流^ ^
![d9954f365a194cab1408e95846e0f98c](https://github.com/user-attachments/assets/8dd1826e-8e47-4557-b06b-26fbbfd06e4d)
![d41ddc5fce71b2d9127b1d908091f9b0](https://github.com/user-attachments/assets/07511474-187b-4faf-a6de-0ab4e1073d33)









欢迎小伙伴们加入micro-app-DevTools开发交流群^ ^
![20aab719ed36bb0eee4025ea957031da](https://github.com/user-attachments/assets/3872f24e-58a8-4848-bb92-7035f83edde2)
![682a80d5b3d6e250dfc269383c5ab9c7](https://github.com/user-attachments/assets/e16b4efa-ef2d-47e5-bb4b-a23d02e4d33e)






Expand Down
38 changes: 29 additions & 9 deletions src/sandbox/iframe/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,36 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
const rawMicroGetElementsByName = microRootDocument.prototype.getElementsByName
const rawMicroElementFromPoint = microRootDocument.prototype.elementFromPoint
const rawMicroCaretRangeFromPoint = microRootDocument.prototype.caretRangeFromPoint
const rawMicroCaretPositionFromPoint = microRootDocument.prototype.caretPositionFromPoint

microRootDocument.prototype.caretRangeFromPoint = function caretRangeFromPoint (
x: number,
y: number,
): Range {
// 这里this指向document才可以获取到子应用的document实例,range才可以被成功生成
const element = rawMicroElementFromPoint.call(rawDocument, x, y)
const range = rawMicroCaretRangeFromPoint.call(rawDocument, x, y)
updateElementInfo(element, appName)
return range
/**
* Firefox does not support caretRangeFromPoint
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/caretRangeFromPoint
*/
if (isFunction(rawMicroCaretRangeFromPoint)) {
microRootDocument.prototype.caretRangeFromPoint = function caretRangeFromPoint (
x: number,
y: number,
): Range {
// 这里this指向document才可以获取到子应用的document实例,range才可以被成功生成
const element = rawMicroElementFromPoint.call(rawDocument, x, y)
const range = rawMicroCaretRangeFromPoint.call(rawDocument, x, y)
updateElementInfo(element, appName)
return range
}
}

if (isFunction(rawMicroCaretPositionFromPoint)) {
microRootDocument.prototype.caretPositionFromPoint = function caretPositionFromPoint (
x: number,
y: number,
): CaretPosition {
// 这里this指向document才可以获取到子应用的document实例,range才可以被成功生成
const element = rawMicroElementFromPoint.call(rawDocument, x, y)
const range = rawMicroCaretPositionFromPoint.call(rawDocument, x, y)
updateElementInfo(element, appName)
return range
}
}

microRootDocument.prototype.createElement = function createElement (
Expand Down