Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/micro-zoe/micro-app into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bailicangdu committed May 19, 2023
2 parents cafe520 + be1eca7 commit 6b55d41
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Contact.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
欢迎小伙伴们加入micro-app微信群交流^ ^
![image](https://user-images.githubusercontent.com/14011130/234218181-c9260e8f-4623-47a6-ba6f-656a4759e639.png)
![image](https://github.com/micro-zoe/micro-app/assets/14011130/f467c4dd-eabf-4505-96a3-66fca1ad0b79)







Expand Down
2 changes: 2 additions & 0 deletions src/libs/global_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function initGlobalEnv (): void {
const rawCreateElementNS = rawRootDocument.prototype.createElementNS
const rawCreateDocumentFragment = rawRootDocument.prototype.createDocumentFragment
const rawCreateTextNode = rawRootDocument.prototype.createTextNode
const rawCreateComment = rawRootDocument.prototype.createComment
const rawQuerySelector = rawRootDocument.prototype.querySelector
const rawQuerySelectorAll = rawRootDocument.prototype.querySelectorAll
const rawGetElementById = rawRootDocument.prototype.getElementById
Expand Down Expand Up @@ -151,6 +152,7 @@ export function initGlobalEnv (): void {
rawCreateElementNS,
rawCreateDocumentFragment,
rawCreateTextNode,
rawCreateComment,
rawQuerySelector,
rawQuerySelectorAll,
rawGetElementById,
Expand Down
6 changes: 6 additions & 0 deletions src/sandbox/iframe/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
const microDocument = microAppWindow.document
const rawMicroCreateElement = microRootDocument.prototype.createElement
const rawMicroCreateTextNode = microRootDocument.prototype.createTextNode
const rawMicroCreateComment = microRootDocument.prototype.createComment
const rawMicroQuerySelector = microRootDocument.prototype.querySelector
const rawMicroQuerySelectorAll = microRootDocument.prototype.querySelectorAll
const rawMicroGetElementById = microRootDocument.prototype.getElementById
Expand All @@ -70,6 +71,11 @@ function patchDocumentPrototype (appName: string, microAppWindow: microAppWindow
return updateElementInfo<Text>(element, appName)
}

microRootDocument.prototype.createComment = function createComment (data: string): Comment {
const element = rawMicroCreateComment.call(this, data)
return updateElementInfo<Comment>(element, appName)
}

function getDefaultRawTarget (target: Document): Document {
return microDocument !== target ? target : rawDocument
}
Expand Down
10 changes: 10 additions & 0 deletions src/sandbox/iframe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ export default class IframeSandbox {

private createProxyWindow (microAppWindow: microAppWindowType): void {
const rawWindow = globalEnv.rawWindow
const customProperties: PropertyKey[] = []

return new Proxy(microAppWindow, {
get: (target: microAppWindowType, key: PropertyKey): unknown => {
if (key === 'location') {
Expand All @@ -426,6 +428,10 @@ export default class IframeSandbox {
return this.proxyWindow
}

if (customProperties.includes(key)) {
return Reflect.get(target, key)
}

return bindFunctionToRawTarget(Reflect.get(target, key), target)
},
set: (target: microAppWindowType, key: PropertyKey, value: unknown): boolean => {
Expand All @@ -438,6 +444,10 @@ export default class IframeSandbox {
return Reflect.set(rawWindow, key, value)
}

if (!Reflect.has(target, key)) {
customProperties.push(key)
}

Reflect.set(target, key, value)

if (this.escapeProperties.includes(key)) {
Expand Down
5 changes: 5 additions & 0 deletions src/source/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,11 @@ function patchDocument () {
// return markElement(element)
// }

rawRootDocument.prototype.createComment = function createComment (data: string): Comment {
const element = globalEnv.rawCreateComment.call(getBindTarget(this), data)
return markElement(element)
}

// query element👇
function querySelector (this: Document, selectors: string): any {
const _this = getBindTarget(this)
Expand Down

0 comments on commit 6b55d41

Please sign in to comment.