diff --git a/Contact.md b/Contact.md index 6375ae34..d49e9bf0 100644 --- a/Contact.md +++ b/Contact.md @@ -1,6 +1,9 @@ 欢迎小伙伴们加入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) + + + @@ -8,7 +11,10 @@ 欢迎小伙伴们加入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) + + + diff --git a/src/sandbox/iframe/document.ts b/src/sandbox/iframe/document.ts index d9b9f0bb..d85c3674 100644 --- a/src/sandbox/iframe/document.ts +++ b/src/sandbox/iframe/document.ts @@ -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 (