@alicloud/alfa-react 1.6.0 → 1.6.2-alpha.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Alibaba Cloud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -10,7 +10,7 @@ import { createEventBus } from '@alicloud/alfa-core';
10
10
  import { ConsoleRegion, ConsoleResourceGroup, ConsoleContext } from '@alicloud/xconsole-context';
11
11
  import { forApp } from '@alicloud/console-base-messenger';
12
12
  import Loading from './components/Loading';
13
- import { normalizeName } from './utils';
13
+ import { normalizeName, setNativeProperty } from './utils';
14
14
  import { countRegister } from './utils/counter';
15
15
  import { version as loaderVersion } from './version';
16
16
  var eventBus = createEventBus();
@@ -330,33 +330,31 @@ export default function createApplication(loader) {
330
330
  originalGo = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.go;
331
331
  // update context history according to path
332
332
  if (path) originalReplaceState(getHistoryState(), '', path.replace(/\/+/g, '/'));
333
- if (frameWindow) {
334
- frameWindow.history.pushState = function (data, unused, _url) {
335
- if ($syncHistory.current) {
336
- var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
337
- if ("".concat(nextPath) !== peelPath(window.location)) {
338
- window.history.pushState(data, unused, nextPath);
339
- onSyncHistory && onSyncHistory('push', nextPath, data);
340
- }
341
- originalReplaceState(data, unused, _url);
342
- } else {
343
- originalPushState(data, unused, _url);
344
- }
345
- };
346
- frameWindow.history.replaceState = function (data, unused, _url) {
333
+ frameWindow.history.pushState = function (data, unused, _url) {
334
+ if ($syncHistory.current) {
347
335
  var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
348
- if ($syncHistory.current) {
349
- window.history.replaceState(data, unused, nextPath);
350
- onSyncHistory && onSyncHistory('replace', nextPath, data);
336
+ if ("".concat(nextPath) !== peelPath(window.location)) {
337
+ window.history.pushState(data, unused, nextPath);
338
+ onSyncHistory && onSyncHistory('push', nextPath, data);
351
339
  }
352
340
  originalReplaceState(data, unused, _url);
353
- };
341
+ } else {
342
+ originalPushState(data, unused, _url);
343
+ }
344
+ };
345
+ frameWindow.history.replaceState = function (data, unused, _url) {
346
+ var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
347
+ if ($syncHistory.current) {
348
+ window.history.replaceState(data, unused, nextPath);
349
+ onSyncHistory && onSyncHistory('replace', nextPath, data);
350
+ }
351
+ originalReplaceState(data, unused, _url);
352
+ };
354
353
 
355
- // 劫持微应用的返回
356
- frameWindow.history.go = function (n) {
357
- window.history.go(n);
358
- };
359
- }
354
+ // 劫持微应用的返回
355
+ setNativeProperty(frameWindow.history, 'go', function (n) {
356
+ window.history.go(n);
357
+ });
360
358
  }
361
359
  _context.next = 25;
362
360
  return app.mount(fakeBody, {
@@ -390,10 +388,14 @@ export default function createApplication(loader) {
390
388
  if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
391
389
  if (!App) return;
392
390
  var frameHistory = (_App$context$baseFram3 = App.context.baseFrame) === null || _App$context$baseFram3 === void 0 ? void 0 : (_App$context$baseFram4 = _App$context$baseFram3.contentWindow) === null || _App$context$baseFram4 === void 0 ? void 0 : _App$context$baseFram4.history;
391
+
392
+ // reset method of frame history
393
393
  if (frameHistory) {
394
394
  if (originalPushState !== frameHistory.pushState) frameHistory.pushState = originalPushState;
395
395
  if (originalReplaceState !== frameHistory.replaceState) frameHistory.replaceState = originalReplaceState;
396
- if (originalGo !== frameHistory.go) frameHistory.go = originalGo;
396
+ if (originalGo !== frameHistory.go) {
397
+ setNativeProperty(frameHistory, 'go', originalGo);
398
+ }
397
399
  }
398
400
  App.unmount();
399
401
 
package/es/utils/index.js CHANGED
@@ -17,4 +17,19 @@ export var isOsContext = function isOsContext() {
17
17
  // 降级
18
18
  return !!window.__IS_CONSOLE_OS_CONTEXT__;
19
19
  }
20
+ };
21
+
22
+ /**
23
+ * set native object property
24
+ * @param obj
25
+ * @param propertyName
26
+ * @param value
27
+ * @returns
28
+ */
29
+ export var setNativeProperty = function setNativeProperty(obj, propertyName, value) {
30
+ var desc = Object.getOwnPropertyDescriptor(obj, propertyName);
31
+
32
+ // in strict mode, Cannot set property go of [xx] which has only a getter
33
+ if (desc && typeof desc.set === 'undefined') return;
34
+ obj[propertyName] = value;
20
35
  };
package/es/version.js CHANGED
@@ -1 +1 @@
1
- export var version = '1.6.0';
1
+ export var version = '1.6.2-alpha.0';
@@ -340,33 +340,31 @@ function createApplication(loader) {
340
340
  originalGo = frameWindow === null || frameWindow === void 0 ? void 0 : frameWindow.history.go;
341
341
  // update context history according to path
342
342
  if (path) originalReplaceState(getHistoryState(), '', path.replace(/\/+/g, '/'));
343
- if (frameWindow) {
344
- frameWindow.history.pushState = function (data, unused, _url) {
345
- if ($syncHistory.current) {
346
- var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
347
- if ("".concat(nextPath) !== peelPath(window.location)) {
348
- window.history.pushState(data, unused, nextPath);
349
- onSyncHistory && onSyncHistory('push', nextPath, data);
350
- }
351
- originalReplaceState(data, unused, _url);
352
- } else {
353
- originalPushState(data, unused, _url);
354
- }
355
- };
356
- frameWindow.history.replaceState = function (data, unused, _url) {
343
+ frameWindow.history.pushState = function (data, unused, _url) {
344
+ if ($syncHistory.current) {
357
345
  var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
358
- if ($syncHistory.current) {
359
- window.history.replaceState(data, unused, nextPath);
360
- onSyncHistory && onSyncHistory('replace', nextPath, data);
346
+ if ("".concat(nextPath) !== peelPath(window.location)) {
347
+ window.history.pushState(data, unused, nextPath);
348
+ onSyncHistory && onSyncHistory('push', nextPath, data);
361
349
  }
362
350
  originalReplaceState(data, unused, _url);
363
- };
351
+ } else {
352
+ originalPushState(data, unused, _url);
353
+ }
354
+ };
355
+ frameWindow.history.replaceState = function (data, unused, _url) {
356
+ var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
357
+ if ($syncHistory.current) {
358
+ window.history.replaceState(data, unused, nextPath);
359
+ onSyncHistory && onSyncHistory('replace', nextPath, data);
360
+ }
361
+ originalReplaceState(data, unused, _url);
362
+ };
364
363
 
365
- // 劫持微应用的返回
366
- frameWindow.history.go = function (n) {
367
- window.history.go(n);
368
- };
369
- }
364
+ // 劫持微应用的返回
365
+ (0, _utils.setNativeProperty)(frameWindow.history, 'go', function (n) {
366
+ window.history.go(n);
367
+ });
370
368
  }
371
369
  _context.next = 25;
372
370
  return app.mount(fakeBody, {
@@ -400,10 +398,14 @@ function createApplication(loader) {
400
398
  if ($syncHistory.current) window.removeEventListener('popstate', updateAppHistory);
401
399
  if (!App) return;
402
400
  var frameHistory = (_App$context$baseFram3 = App.context.baseFrame) === null || _App$context$baseFram3 === void 0 ? void 0 : (_App$context$baseFram4 = _App$context$baseFram3.contentWindow) === null || _App$context$baseFram4 === void 0 ? void 0 : _App$context$baseFram4.history;
401
+
402
+ // reset method of frame history
403
403
  if (frameHistory) {
404
404
  if (originalPushState !== frameHistory.pushState) frameHistory.pushState = originalPushState;
405
405
  if (originalReplaceState !== frameHistory.replaceState) frameHistory.replaceState = originalReplaceState;
406
- if (originalGo !== frameHistory.go) frameHistory.go = originalGo;
406
+ if (originalGo !== frameHistory.go) {
407
+ (0, _utils.setNativeProperty)(frameHistory, 'go', originalGo);
408
+ }
407
409
  }
408
410
  App.unmount();
409
411
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.normalizeName = exports.isOsContext = void 0;
6
+ exports.setNativeProperty = exports.normalizeName = exports.isOsContext = void 0;
7
7
  /**
8
8
  * kernel 会为沙箱 context 注入 __IS_CONSOLE_OS_CONTEXT__
9
9
  */
@@ -25,4 +25,20 @@ var isOsContext = function isOsContext() {
25
25
  return !!window.__IS_CONSOLE_OS_CONTEXT__;
26
26
  }
27
27
  };
28
- exports.isOsContext = isOsContext;
28
+
29
+ /**
30
+ * set native object property
31
+ * @param obj
32
+ * @param propertyName
33
+ * @param value
34
+ * @returns
35
+ */
36
+ exports.isOsContext = isOsContext;
37
+ var setNativeProperty = function setNativeProperty(obj, propertyName, value) {
38
+ var desc = Object.getOwnPropertyDescriptor(obj, propertyName);
39
+
40
+ // in strict mode, Cannot set property go of [xx] which has only a getter
41
+ if (desc && typeof desc.set === 'undefined') return;
42
+ obj[propertyName] = value;
43
+ };
44
+ exports.setNativeProperty = setNativeProperty;
package/lib/version.js CHANGED
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.version = void 0;
7
- var version = '1.6.0';
7
+ var version = '1.6.2-alpha.0';
8
8
  exports.version = version;
package/package.json CHANGED
@@ -1,25 +1,12 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-react",
3
- "version": "1.6.0",
3
+ "version": "1.6.2-alpha.0",
4
4
  "description": "Alfa Framework (React Version)",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
7
7
  "types": "types/index.d.ts",
8
8
  "author": "pushiming",
9
9
  "license": "MIT",
10
- "scripts": {
11
- "prepublish": "npm run version && npm run build && npm run babel && npm run babel:esm && npm run types",
12
- "pub": "pnpm publish",
13
- "build": "breezr build --engine webpack",
14
- "babel": "breezr build --engine babel",
15
- "babel:esm": "breezr build --engine babel --es-module",
16
- "types": "tsc --emitDeclarationOnly -d --declarationDir ./types",
17
- "storybook": "breezr start-storybook",
18
- "clean": "rm -rf lib es dist types yarn.lock",
19
- "start": "breezr start-storybook",
20
- "precommit": "npm run version",
21
- "version": "node -p \"'export const version = \\'' + require('./package.json').version + '\\';'\" > src/version.ts && git add src/version.ts"
22
- },
23
10
  "publishConfig": {
24
11
  "access": "public"
25
12
  },
@@ -44,18 +31,31 @@
44
31
  "typescript": "^4.0.0"
45
32
  },
46
33
  "dependencies": {
47
- "@alicloud/alfa-core": "workspace:^",
48
34
  "@alicloud/console-base-messenger": "^1.18.1",
49
- "@alicloud/console-os-loader": "workspace:^",
50
35
  "@alicloud/widget-utils-console": "^0.1.6",
51
36
  "@alicloud/xconsole-context": "^2.4.32",
52
37
  "axios": "^0.21.4",
53
38
  "classnames": "^2.2.6",
54
39
  "crypto-js": "^4.1.1",
55
- "prop-types": "^15.8.1"
40
+ "prop-types": "^15.8.1",
41
+ "@alicloud/console-os-loader": "^1.4.42",
42
+ "@alicloud/alfa-core": "^1.4.37"
56
43
  },
57
44
  "peerDependencies": {
58
45
  "react": ">=16.0.0"
59
46
  },
60
- "gitHead": "ff9294b1d5e08b14691c8aa2bef098da2857f3df"
61
- }
47
+ "gitHead": "ff9294b1d5e08b14691c8aa2bef098da2857f3df",
48
+ "scripts": {
49
+ "prepublish": "npm run version && npm run babel && npm run babel:esm && npm run types",
50
+ "pub": "pnpm publish",
51
+ "build": "breezr build --engine webpack",
52
+ "babel": "breezr build --engine babel",
53
+ "babel:esm": "breezr build --engine babel --es-module",
54
+ "types": "tsc --emitDeclarationOnly -d --declarationDir ./types",
55
+ "storybook": "breezr start-storybook",
56
+ "clean": "rm -rf lib es dist types yarn.lock",
57
+ "start": "breezr start-storybook",
58
+ "precommit": "npm run version",
59
+ "version": "node -p \"'export const version = \\'' + require('./package.json').version + '\\';'\" > src/version.ts && git add src/version.ts"
60
+ }
61
+ }
@@ -3,3 +3,11 @@ export declare const normalizeName: (name: string) => string;
3
3
  * 判断是否在沙箱环境中运行
4
4
  */
5
5
  export declare const isOsContext: () => boolean;
6
+ /**
7
+ * set native object property
8
+ * @param obj
9
+ * @param propertyName
10
+ * @param value
11
+ * @returns
12
+ */
13
+ export declare const setNativeProperty: (obj: any, propertyName: string, value: any) => void;
@@ -1 +1 @@
1
- export declare const version = "1.6.0";
1
+ export declare const version = "1.6.2-alpha.0";