@blueking/bk-weweb 0.0.21 → 0.0.23
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/dist/collect-source.js +24 -40
- package/dist/collect-source.js.map +1 -1
- package/dist/index.esm.js +24 -40
- package/dist/index.esm.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +4 -6
- package/typings/context/document.d.ts +2 -0
- package/typings/base-app/base-element.d.ts +0 -6
- package/typings/context/memory.d.ts +0 -10
- package/typings/utils/element-event.d.ts +0 -2
package/dist/collect-source.js
CHANGED
|
@@ -164,33 +164,9 @@ const isJsonpUrl = (url) => {
|
|
|
164
164
|
return !pathname.match(/\.js$/);
|
|
165
165
|
};
|
|
166
166
|
|
|
167
|
-
/*
|
|
168
|
-
* Tencent is pleased to support the open source community by making
|
|
169
|
-
* 蓝鲸智云PaaS平台 (BlueKing PaaS) available.
|
|
170
|
-
*
|
|
171
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
|
172
|
-
*
|
|
173
|
-
* 蓝鲸智云PaaS平台 (BlueKing PaaS) is licensed under the MIT License.
|
|
174
|
-
*
|
|
175
|
-
* License for 蓝鲸智云PaaS平台 (BlueKing PaaS):
|
|
176
|
-
*
|
|
177
|
-
* ---------------------------------------------------
|
|
178
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
179
|
-
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
180
|
-
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
181
|
-
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
182
|
-
*
|
|
183
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
|
|
184
|
-
* the Software.
|
|
185
|
-
*
|
|
186
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
|
187
|
-
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
188
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
189
|
-
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
190
|
-
* IN THE SOFTWARE.
|
|
191
|
-
*/
|
|
192
167
|
const { document: document$1 } = window;
|
|
193
168
|
const { createElement, getElementById, getElementsByClassName, getElementsByName, getElementsByTagName, querySelector, querySelectorAll, } = Document.prototype;
|
|
169
|
+
const { querySelector: bodyQuerySelector } = HTMLBodyElement.prototype;
|
|
194
170
|
const SPECIAL_ELEMENT_TAG = ['body', 'html', 'head'];
|
|
195
171
|
let hasRewrite$1 = false;
|
|
196
172
|
function rewriteDocumentPrototypeMethods() {
|
|
@@ -226,11 +202,15 @@ function rewriteDocumentPrototypeMethods() {
|
|
|
226
202
|
if (app?.container instanceof ShadowRoot) {
|
|
227
203
|
return app?.container;
|
|
228
204
|
}
|
|
205
|
+
if (this instanceof HTMLBodyElement)
|
|
206
|
+
return bodyQuerySelector.call(this, selectors);
|
|
229
207
|
// 否则调用原始的 querySelector 方法
|
|
230
208
|
return querySelector.call(this, selectors);
|
|
231
209
|
}
|
|
232
210
|
// 如果没有当前应用程序或选择器为空或文档不是当前文档
|
|
233
|
-
if (!app || !selectors || document$1
|
|
211
|
+
if (!app || !selectors || ![document$1, document$1.body].includes(this)) {
|
|
212
|
+
if (this instanceof HTMLBodyElement)
|
|
213
|
+
return bodyQuerySelector.call(this, selectors);
|
|
234
214
|
// 调用原始的 querySelector 方法
|
|
235
215
|
return querySelector.call(this, selectors);
|
|
236
216
|
}
|
|
@@ -260,6 +240,7 @@ function rewriteDocumentPrototypeMethods() {
|
|
|
260
240
|
}
|
|
261
241
|
Document.prototype.querySelector = querySelectorNew;
|
|
262
242
|
Document.prototype.querySelectorAll = querySelectorAllNew;
|
|
243
|
+
HTMLBodyElement.prototype.querySelector = querySelectorNew;
|
|
263
244
|
Document.prototype.getElementById = function getElementByIdNew(key) {
|
|
264
245
|
return getCurrentRunningApp() ? querySelectorNew.call(this, `#${key}`) : getElementById.call(this, key);
|
|
265
246
|
};
|
|
@@ -281,6 +262,7 @@ function rewriteDocumentPrototypeMethods() {
|
|
|
281
262
|
function resetDocumentPrototypeMethods() {
|
|
282
263
|
Document.prototype.createElement = createElement;
|
|
283
264
|
Document.prototype.querySelector = querySelector;
|
|
265
|
+
HTMLBodyElement.prototype.querySelector = bodyQuerySelector;
|
|
284
266
|
Document.prototype.querySelectorAll = querySelectorAll;
|
|
285
267
|
Document.prototype.getElementById = getElementById;
|
|
286
268
|
Document.prototype.getElementsByClassName = getElementsByClassName;
|
|
@@ -288,6 +270,15 @@ function resetDocumentPrototypeMethods() {
|
|
|
288
270
|
Document.prototype.getElementsByName = getElementsByName;
|
|
289
271
|
hasRewrite$1 = false;
|
|
290
272
|
}
|
|
273
|
+
// vue3.3之后会换成document 这些需要初始化调用的app
|
|
274
|
+
function createRewriteDocument(rawDocument, app) {
|
|
275
|
+
return Object.defineProperty(rawDocument, 'createElement', {
|
|
276
|
+
get() {
|
|
277
|
+
app?.registerRunningApp();
|
|
278
|
+
return Document.prototype.createElement;
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
}
|
|
291
282
|
|
|
292
283
|
/*
|
|
293
284
|
* Tencent is pleased to support the open source community by making
|
|
@@ -708,15 +699,7 @@ class Style {
|
|
|
708
699
|
const rules = Array.from(templateStyle.sheet?.cssRules ?? []);
|
|
709
700
|
const cssPrefix = `#${app.name}`;
|
|
710
701
|
const scopedCss = this.scopeRule(rules, cssPrefix);
|
|
711
|
-
|
|
712
|
-
if (/Safari/.test(navigator.userAgent)) {
|
|
713
|
-
cssText = cssText.replace(/([;{]\s*content:\s*)([^\s"][^";}]*)/gm, (all, $1, $2) => {
|
|
714
|
-
if ($2 === 'none' || /^(url\()|(counter\()|(attr\()|(open-quote)|(close-quote)/.test($2)) {
|
|
715
|
-
return all;
|
|
716
|
-
}
|
|
717
|
-
return `${$1}"${$2}"`;
|
|
718
|
-
});
|
|
719
|
-
}
|
|
702
|
+
const cssText = this.resetUrlHost(scopedCss, app.url, this.url);
|
|
720
703
|
styleElement.textContent = cssText;
|
|
721
704
|
this.scopedCode = cssText;
|
|
722
705
|
}
|
|
@@ -1525,7 +1508,7 @@ function setMarkElement(element, app, keepAlive) {
|
|
|
1525
1508
|
* IN THE SOFTWARE.
|
|
1526
1509
|
*/
|
|
1527
1510
|
const { setAttribute } = Element.prototype;
|
|
1528
|
-
const { append, appendChild: bodyAppendChild, removeChild: bodyRemoveChild } = HTMLBodyElement.prototype;
|
|
1511
|
+
const { append, appendChild: bodyAppendChild, insertBefore: bodyInsertBefore, removeChild: bodyRemoveChild, } = HTMLBodyElement.prototype;
|
|
1529
1512
|
const { appendChild: headAppendChild, insertBefore: headInsertBefore, removeChild: headRemoveChild, } = HTMLHeadElement.prototype;
|
|
1530
1513
|
const rawHead = document.head;
|
|
1531
1514
|
let hasRewrite = false;
|
|
@@ -1563,6 +1546,9 @@ function rewriteBodyAndHeaderMethods() {
|
|
|
1563
1546
|
HTMLHeadElement.prototype.insertBefore = function (newChild, refChild) {
|
|
1564
1547
|
return elementInsertHandler(this, newChild, refChild, headInsertBefore);
|
|
1565
1548
|
};
|
|
1549
|
+
HTMLBodyElement.prototype.insertBefore = function (newChild, refChild) {
|
|
1550
|
+
return elementInsertHandler(this, newChild, refChild, headInsertBefore);
|
|
1551
|
+
};
|
|
1566
1552
|
HTMLBodyElement.prototype.removeChild = function removeChildNew(oldChild) {
|
|
1567
1553
|
const app = appCache.getApp(oldChild.__BK_WEWEB_APP_KEY__);
|
|
1568
1554
|
if (app?.container?.contains(oldChild)) {
|
|
@@ -1582,6 +1568,7 @@ function resetBodyAndHeaderMethods() {
|
|
|
1582
1568
|
HTMLBodyElement.prototype.appendChild = bodyAppendChild;
|
|
1583
1569
|
HTMLBodyElement.prototype.append = append;
|
|
1584
1570
|
HTMLBodyElement.prototype.removeChild = bodyRemoveChild;
|
|
1571
|
+
HTMLBodyElement.prototype.insertBefore = bodyInsertBefore;
|
|
1585
1572
|
HTMLHeadElement.prototype.appendChild = headAppendChild;
|
|
1586
1573
|
HTMLHeadElement.prototype.insertBefore = headInsertBefore;
|
|
1587
1574
|
HTMLHeadElement.prototype.removeChild = headRemoveChild;
|
|
@@ -1949,9 +1936,6 @@ function rewriteDocumentAndBodyEvent() {
|
|
|
1949
1936
|
*/
|
|
1950
1937
|
/* eslint-disable max-len */
|
|
1951
1938
|
/* eslint-disable no-prototype-builtins */
|
|
1952
|
-
/*
|
|
1953
|
-
inspired by https://github.com/umijs/qiankun
|
|
1954
|
-
*/
|
|
1955
1939
|
// 正则表达式,用于匹配类定义
|
|
1956
1940
|
const CLASS_REGEX = /^class\b/;
|
|
1957
1941
|
// 正则表达式,用于匹配以大写字母开头的函数定义
|
|
@@ -2118,7 +2102,7 @@ class SandBox {
|
|
|
2118
2102
|
this.app = app;
|
|
2119
2103
|
const windowDescriptorSet = new Set();
|
|
2120
2104
|
const rawWindow = window;
|
|
2121
|
-
const rawDocument =
|
|
2105
|
+
const rawDocument = createRewriteDocument(document, this.app);
|
|
2122
2106
|
this.fakeWindow.__POWERED_BY_BK_WEWEB__ = true;
|
|
2123
2107
|
this.fakeWindow.__BK_WEWEB_APP_KEY__ = app.appCacheKey;
|
|
2124
2108
|
this.rawWindow = rawWindow;
|