@alicloud/alfa-react 1.3.0-canary.1 → 1.3.0-canary.8

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.
@@ -12,25 +12,26 @@ export var getWidgetConfigById = /*#__PURE__*/function () {
12
12
  switch (_context.prev = _context.next) {
13
13
  case 0:
14
14
  env = ENV[option.env || getConsoleEnv()];
15
+ console.log(env.configUrl);
15
16
 
16
17
  if (cachedConfig[option.name]) {
17
- _context.next = 6;
18
+ _context.next = 7;
18
19
  break;
19
20
  }
20
21
 
21
- _context.next = 4;
22
+ _context.next = 5;
22
23
  return axios.get(template(env.configUrl)({
23
24
  id: option.name
24
25
  }));
25
26
 
26
- case 4:
27
+ case 5:
27
28
  resp = _context.sent;
28
29
  cachedConfig[option.name] = resp.data;
29
30
 
30
- case 6:
31
+ case 7:
31
32
  return _context.abrupt("return", cachedConfig[option.name]);
32
33
 
33
- case 7:
34
+ case 8:
34
35
  case "end":
35
36
  return _context.stop();
36
37
  }
@@ -160,7 +160,7 @@ export var getWidgetDeps = /*#__PURE__*/function () {
160
160
  react: react,
161
161
  'react-dom': reactDom,
162
162
  'prop-types': propTypes,
163
- axios: axios
163
+ 'axios': axios
164
164
  }, cachedRuntime[version].default), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, WIDGET_UTILS_PKG_NAME, injectedWidgetUtils), _defineProperty(_objectSpread2, '@ali/widget-utils-config', injectedWidgetUtils), _defineProperty(_objectSpread2, '@ali/widget-loader', createWidget), _objectSpread2)));
165
165
 
166
166
  case 31:
package/es/widget.js CHANGED
@@ -9,17 +9,11 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
9
9
 
10
10
  import React, { lazy, Suspense } from 'react';
11
11
  import { loadBundle } from '@alicloud/console-os-loader';
12
- import { createAlfaApp } from './app';
13
12
  import { getWidgetVersionById, getWidgetDeps, getWidgetConfigById, eventEmitter } from './widget/index';
14
13
  import ErrorBoundary from './components/ErrorBoundary';
15
14
  import Loading from './components/Loading';
16
15
  import { normalizeName } from './utils';
17
16
  export function createAlfaWidget(option) {
18
- if (!option.name.match(/@ali\/widget-/)) {
19
- // TODO load style
20
- return createAlfaApp(option);
21
- }
22
-
23
17
  var AlfaWidget = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
24
18
  var url, config, _yield$getWidgetVersi, version, entryUrl, deps;
25
19
 
@@ -0,0 +1,2 @@
1
+ import { AlfaFactoryOption } from '../types';
2
+ export declare function createIsomorphicAlfaApp<T = any>(option: AlfaFactoryOption): (props: T) => JSX.Element;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.createIsomorphicAlfaApp = createIsomorphicAlfaApp;
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _react = _interopRequireWildcard(require("react"));
15
+
16
+ var _alfaCore = require("@alicloud/alfa-core");
17
+
18
+ var _context = _interopRequireDefault(require("../context"));
19
+
20
+ var _ErrorBoundary = _interopRequireDefault(require("../components/ErrorBoundary"));
21
+
22
+ var _Loading = _interopRequireDefault(require("../components/Loading"));
23
+
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
+
26
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
+
28
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
29
+
30
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
31
+
32
+ var App = function App(props) {
33
+ var env = (0, _react.useContext)(_context.default); // 如果 env 为空,则返回 loading
34
+
35
+ if (!(env !== null && env !== void 0 && env.getJson) || !(env !== null && env !== void 0 && env.fetchBundle) || !(env !== null && env !== void 0 && env.getBundle) || !(env !== null && env !== void 0 && env.fetchJsonResource)) {
36
+ return /*#__PURE__*/_react.default.createElement(_Loading.default, {
37
+ loading: props.loading
38
+ });
39
+ } // get server render string
40
+
41
+
42
+ var renderString = (0, _alfaCore.renderToString)(props, env);
43
+
44
+ if (!renderString) {
45
+ return /*#__PURE__*/_react.default.createElement(_Loading.default, {
46
+ loading: props.loading
47
+ });
48
+ }
49
+
50
+ return /*#__PURE__*/_react.default.createElement(props.name, {
51
+ children: /*#__PURE__*/_react.default.createElement("div", {
52
+ dangerouslySetInnerHTML: {
53
+ __html: renderString
54
+ }
55
+ })
56
+ });
57
+ };
58
+
59
+ function createIsomorphicAlfaApp(option) {
60
+ return function (props) {
61
+ return /*#__PURE__*/_react.default.createElement(_ErrorBoundary.default, props, /*#__PURE__*/_react.default.createElement(App, _objectSpread(_objectSpread({}, props), option)));
62
+ };
63
+ }
@@ -15,7 +15,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
15
15
 
16
16
  var _alfaCore = require("@alicloud/alfa-core");
17
17
 
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
19
19
 
20
20
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
21
 
package/lib/app.js CHANGED
@@ -33,7 +33,9 @@ var _Loading = _interopRequireDefault(require("./components/Loading"));
33
33
 
34
34
  var _ErrorBoundary = _interopRequireDefault(require("./components/ErrorBoundary"));
35
35
 
36
- var _getConsoleConfig = require("./utils/getConsoleConfig");
36
+ var _getConsoleConfig = require("./app/getConsoleConfig");
37
+
38
+ var _createIsomorphicMicroApp = require("./app/createIsomorphicMicroApp");
37
39
 
38
40
  var _utils = require("./utils");
39
41
 
@@ -55,8 +57,10 @@ var getProps = function getProps(props) {
55
57
  delete parcelProps.loading;
56
58
  delete parcelProps.entry;
57
59
  delete parcelProps.container;
58
- delete parcelProps.logger;
59
- delete parcelProps.env;
60
+ delete parcelProps.logger; // @ts-ignore
61
+
62
+ delete parcelProps.env; // @ts-ignore
63
+
60
64
  delete parcelProps.dependencies;
61
65
  return parcelProps;
62
66
  };
@@ -67,8 +71,7 @@ var Application = function Application(props) {
67
71
  loading = props.loading,
68
72
  style = props.style,
69
73
  className = props.className,
70
- consoleConfig = props.consoleConfig,
71
- i18nMessages = props.i18nMessages;
74
+ consoleConfig = props.consoleConfig;
72
75
 
73
76
  var _useState = (0, _react.useState)(false),
74
77
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -83,7 +86,7 @@ var Application = function Application(props) {
83
86
  var appRef = (0, _react.useRef)(null);
84
87
  (0, _react.useEffect)(function () {
85
88
  (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
86
- var App;
89
+ var app;
87
90
  return _regenerator.default.wrap(function _callee$(_context) {
88
91
  while (1) {
89
92
  switch (_context.prev = _context.next) {
@@ -97,35 +100,27 @@ var Application = function Application(props) {
97
100
  });
98
101
 
99
102
  case 2:
100
- App = _context.sent;
103
+ app = _context.sent;
101
104
 
102
- if (App.context && App.context.baseFrame && App.context.baseFrame.contentWindow) {
103
- App.context.baseFrame.contentWindow.ALIYUN_CONSOLE_CONFIG = consoleConfig;
104
- App.context.baseFrame.contentWindow.ALIYUN_CONSOLE_I18N_MESSAGE = i18nMessages;
105
+ if (app.context && app.context.baseFrame) {
106
+ // @ts-ignore
107
+ app.context.baseFrame.contentWindow.ALIYUN_CONSOLE_CONFIG = consoleConfig;
105
108
  }
106
109
 
107
110
  _context.next = 6;
108
- return App.load();
111
+ return app.load();
109
112
 
110
113
  case 6:
111
- if (appRef.current) {
112
- _context.next = 8;
113
- break;
114
- }
115
-
116
- return _context.abrupt("return");
117
-
118
- case 8:
119
- _context.next = 10;
120
- return App.mount(appRef.current, {
114
+ _context.next = 8;
115
+ return app.mount(appRef.current, {
121
116
  customProps: getProps(props)
122
117
  });
123
118
 
124
- case 10:
119
+ case 8:
125
120
  setMounted(true);
126
- setApp(App);
121
+ setApp(app);
127
122
 
128
- case 12:
123
+ case 10:
129
124
  case "end":
130
125
  return _context.stop();
131
126
  }
@@ -148,17 +143,24 @@ var Application = function Application(props) {
148
143
  className: className,
149
144
  ref: appRef,
150
145
  dataId: name
151
- }) : /*#__PURE__*/_react.default.createElement(name, {}, /*#__PURE__*/_react.default.createElement('div', {
152
- ref: appRef
153
- })));
146
+ }) : /*#__PURE__*/_react.default.createElement(name, {
147
+ children: /*#__PURE__*/_react.default.createElement('div', {
148
+ ref: appRef
149
+ })
150
+ }));
154
151
  };
155
152
 
156
153
  function createAlfaApp(option) {
157
154
  var name = option.name,
158
155
  loading = option.loading,
159
156
  manifest = option.manifest;
157
+
158
+ if ((0, _utils.isSSR)()) {
159
+ return (0, _createIsomorphicMicroApp.createIsomorphicAlfaApp)(option);
160
+ }
161
+
160
162
  var AlfaApp = /*#__PURE__*/(0, _react.lazy)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
161
- var resolvedManifest, consoleConfig, messages, i18nMessages, App;
163
+ var resolvedManifest, consoleConfig, AlfaApp;
162
164
  return _regenerator.default.wrap(function _callee2$(_context2) {
163
165
  while (1) {
164
166
  switch (_context2.prev = _context2.next) {
@@ -177,6 +179,7 @@ function createAlfaApp(option) {
177
179
  resolvedManifest = _context2.sent;
178
180
 
179
181
  case 5:
182
+ // @ts-ignore
180
183
  consoleConfig = window.ALIYUN_CONSOLE_CONFIG || {};
181
184
 
182
185
  if (!option.dynamicConfig) {
@@ -191,28 +194,20 @@ function createAlfaApp(option) {
191
194
  consoleConfig = _context2.sent;
192
195
 
193
196
  case 10:
194
- _context2.next = 12;
195
- return (0, _alfaCore.getLocale)(option);
196
-
197
- case 12:
198
- messages = _context2.sent;
199
- i18nMessages = _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_I18N_MESSAGE), messages);
200
-
201
- App = function App(props) {
197
+ AlfaApp = function AlfaApp(props) {
202
198
  return /*#__PURE__*/_react.default.createElement(Application, (0, _extends2.default)({
203
199
  manifest: resolvedManifest
204
200
  }, props, {
205
201
  name: (0, _utils.normalizeName)(name),
206
- consoleConfig: consoleConfig,
207
- i18nMessages: i18nMessages
202
+ consoleConfig: consoleConfig
208
203
  }));
209
204
  };
210
205
 
211
206
  return _context2.abrupt("return", {
212
- default: App
207
+ default: AlfaApp
213
208
  });
214
209
 
215
- case 16:
210
+ case 12:
216
211
  case "end":
217
212
  return _context2.stop();
218
213
  }
package/lib/base.d.ts CHANGED
@@ -3,9 +3,6 @@ import { IAppConfig, IOptions } from '@alicloud/alfa-core';
3
3
  export interface IProps<T = any> extends HTMLAttributes<Element>, IAppConfig, IOptions {
4
4
  loading?: boolean | React.ReactChild;
5
5
  consoleConfig?: any;
6
- i18nMessages?: any;
7
- env?: string;
8
- dependencies?: any;
9
6
  }
10
7
  export default class MicroAppBase<T> extends React.Component<Partial<IProps<T>>> {
11
8
  }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { IIsomorphicEnvironment } from '@alicloud/alfa-core';
3
+ /**
4
+ * 用来提供 ssr 状态下的获取 服务端 manifest & bundle 的实现
5
+ */
6
+ declare const EnvContext: import("react").Context<Partial<IIsomorphicEnvironment>>;
7
+ export default EnvContext;
package/lib/context.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ /**
11
+ * 用来提供 ssr 状态下的获取 服务端 manifest & bundle 的实现
12
+ */
13
+ var EnvContext = /*#__PURE__*/(0, _react.createContext)({});
14
+ var _default = EnvContext;
15
+ exports.default = _default;
package/lib/types.d.ts CHANGED
@@ -24,7 +24,6 @@ declare type OmitKeys = 'manifest';
24
24
  export interface WidgetFactoryOption extends Omit<AlfaFactoryOption, OmitKeys> {
25
25
  runtimeVersion?: string;
26
26
  alfaLoader?: boolean;
27
- theme?: string;
28
27
  }
29
28
  export interface AlfaEnvConfigDescriptor {
30
29
  releaseUrl: string;
package/lib/utils.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare const normalizeName: (name: string) => string;
2
+ export declare const isSSR: () => boolean;
package/lib/utils.js CHANGED
@@ -3,10 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.normalizeName = void 0;
6
+ exports.normalizeName = exports.isSSR = void 0;
7
7
 
8
8
  var normalizeName = function normalizeName(name) {
9
9
  return name.replace(/@/g, '').replace(/\//g, '-');
10
10
  };
11
11
 
12
- exports.normalizeName = normalizeName;
12
+ exports.normalizeName = normalizeName;
13
+
14
+ var isSSR = function isSSR() {
15
+ return typeof document === 'undefined';
16
+ };
17
+
18
+ exports.isSSR = isSSR;
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
3
  declare class WidgetEventEmitter extends EventEmitter {
4
+ constructor();
4
5
  refersh(widgetId: string): boolean;
5
6
  refershWidget(widgetId: string): boolean;
6
7
  }
@@ -30,13 +30,13 @@ var WidgetEventEmitter = /*#__PURE__*/function (_EventEmitter) {
30
30
 
31
31
  function WidgetEventEmitter() {
32
32
  (0, _classCallCheck2.default)(this, WidgetEventEmitter);
33
- return _super.apply(this, arguments);
34
- }
33
+ return _super.call(this);
34
+ } // Compatible with the old api, this may get removed at sometime later.
35
+
35
36
 
36
37
  (0, _createClass2.default)(WidgetEventEmitter, [{
37
38
  key: "refersh",
38
- value: // Compatible with the old api, this may get removed at sometime later.
39
- function refersh(widgetId) {
39
+ value: function refersh(widgetId) {
40
40
  return this.emit("".concat(widgetId, ":REFRESH"));
41
41
  }
42
42
  }, {
@@ -27,25 +27,26 @@ var getWidgetConfigById = /*#__PURE__*/function () {
27
27
  switch (_context.prev = _context.next) {
28
28
  case 0:
29
29
  env = _env.ENV[option.env || (0, _env.getConsoleEnv)()];
30
+ console.log(env.configUrl);
30
31
 
31
32
  if (cachedConfig[option.name]) {
32
- _context.next = 6;
33
+ _context.next = 7;
33
34
  break;
34
35
  }
35
36
 
36
- _context.next = 4;
37
+ _context.next = 5;
37
38
  return _axios.default.get((0, _template.default)(env.configUrl)({
38
39
  id: option.name
39
40
  }));
40
41
 
41
- case 4:
42
+ case 5:
42
43
  resp = _context.sent;
43
44
  cachedConfig[option.name] = resp.data;
44
45
 
45
- case 6:
46
+ case 7:
46
47
  return _context.abrupt("return", cachedConfig[option.name]);
47
48
 
48
- case 7:
49
+ case 8:
49
50
  case "end":
50
51
  return _context.stop();
51
52
  }
@@ -185,7 +185,7 @@ var getWidgetDeps = /*#__PURE__*/function () {
185
185
  react: _react.default,
186
186
  'react-dom': _reactDom.default,
187
187
  'prop-types': propTypes,
188
- axios: _axios.default
188
+ 'axios': _axios.default
189
189
  }, cachedRuntime[version].default), {}, (_objectSpread2 = {}, (0, _defineProperty2.default)(_objectSpread2, WIDGET_UTILS_PKG_NAME, injectedWidgetUtils), (0, _defineProperty2.default)(_objectSpread2, '@ali/widget-utils-config', injectedWidgetUtils), (0, _defineProperty2.default)(_objectSpread2, '@ali/widget-loader', createWidget), _objectSpread2)));
190
190
 
191
191
  case 31:
package/lib/widget.js CHANGED
@@ -21,8 +21,6 @@ var _react = _interopRequireWildcard(require("react"));
21
21
 
22
22
  var _consoleOsLoader = require("@alicloud/console-os-loader");
23
23
 
24
- var _app = require("./app");
25
-
26
24
  var _index = require("./widget/index");
27
25
 
28
26
  var _ErrorBoundary = _interopRequireDefault(require("./components/ErrorBoundary"));
@@ -40,11 +38,6 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
40
38
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
41
39
 
42
40
  function createAlfaWidget(option) {
43
- if (!option.name.match(/@ali\/widget-/)) {
44
- // TODO load style
45
- return (0, _app.createAlfaApp)(option);
46
- }
47
-
48
41
  var AlfaWidget = /*#__PURE__*/(0, _react.lazy)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
49
42
  var url, config, _yield$getWidgetVersi, version, entryUrl, deps;
50
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-react",
3
- "version": "1.3.0-canary.1",
3
+ "version": "1.3.0-canary.8",
4
4
  "description": "Alfa Framework (React Version)",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -9,7 +9,7 @@
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "start": "breezr start-storybook",
12
- "prepublish": "npm run build && npm run babel && npm run babel:esm",
12
+ "prepublish": "npm run clean && npm run build && npm run babel && npm run babel:esm",
13
13
  "babel": "breezr build --engine babel && tsc --emitDeclarationOnly -d --declarationDir ./lib",
14
14
  "babel:esm": "breezr build --engine babel --es-module",
15
15
  "build": "breezr build --engine webpack",
@@ -23,9 +23,7 @@
23
23
  "@alicloud/console-toolkit-preset-wind-component": "^1.0.0",
24
24
  "@types/chai": "^4.1.7",
25
25
  "@types/classnames": "^2.2.9",
26
- "@types/crypto-js": "^4.0.2",
27
26
  "@types/jest": "^23.3.13",
28
- "@types/lodash": "^4.14.176",
29
27
  "@types/react": "^16.9.2",
30
28
  "@types/react-dom": "^16.9.0",
31
29
  "@types/single-spa-react": "^2.8.3",
@@ -37,14 +35,13 @@
37
35
  "typescript": "^3.0.3"
38
36
  },
39
37
  "dependencies": {
40
- "@alicloud/alfa-core": "1.3.0-canary.1",
41
- "@alicloud/console-os-loader": "1.3.0-canary.0",
38
+ "@alicloud/alfa-core": "1.3.0-canary.7",
39
+ "@alicloud/console-os-loader": "1.3.0-canary.5",
42
40
  "@alicloud/widget-utils-console": "^0.1.6",
43
- "classnames": "^2.2.6",
44
- "crypto-js": "^4.1.1"
41
+ "classnames": "^2.2.6"
45
42
  },
46
43
  "peerDependencies": {
47
44
  "react": "^16 | ^17"
48
45
  },
49
- "gitHead": "631484c0b2517e289c8531cc556af11135905674"
46
+ "gitHead": "e91b101eacc118b5bd8d82997540046d16505747"
50
47
  }
@@ -1,2 +0,0 @@
1
- import { AlfaFactoryOption } from '@alicloud/alfa-core';
2
- export declare const getConsoleConfig: (option: AlfaFactoryOption, consoleConfig: any) => Promise<any>;
@@ -1,102 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.getConsoleConfig = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
-
16
- var _alfaCore = require("@alicloud/alfa-core");
17
-
18
- var _md = _interopRequireDefault(require("crypto-js/md5"));
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
-
24
- /**
25
- * transform
26
- * @param features
27
- */
28
- //@ts-ignore
29
- var processFeatures = function processFeatures(features) {
30
- return Object.keys(features).reduce(function (newFeatures, key) {
31
- var _ALIYUN_CONSOLE_CONFI;
32
-
33
- var feature = features[key];
34
- if (!feature) return newFeatures;
35
- var uid = ((_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.CURRENT_PK) || '';
36
- var md5Uid = (0, _md.default)(uid).toString();
37
- var enableBlockList = feature.enableBlockList,
38
- enableSampling = feature.enableSampling,
39
- enableWhiteList = feature.enableWhiteList,
40
- sampling = feature.sampling,
41
- blockList = feature.blockList,
42
- whiteList = feature.whiteList;
43
-
44
- if (enableBlockList && blockList.includes(md5Uid)) {
45
- newFeatures[key] = false;
46
- } else if (enableWhiteList && whiteList.includes(md5Uid)) {
47
- newFeatures[key] = true;
48
- } else if (enableSampling) {
49
- var gray = uid.substring(uid.length - 2);
50
- if (Number(gray) >= sampling * 100 || sampling === 0) newFeatures[key] = false;
51
- newFeatures[key] = true;
52
- } else {
53
- newFeatures[key] = false;
54
- }
55
-
56
- return newFeatures;
57
- }, {});
58
- };
59
-
60
- var mergeConfigDataWithConsoleConfig = function mergeConfigDataWithConsoleConfig(configData, consoleConfig) {
61
- var _window, _window$ALIYUN_CONSOL, _configData$ALL_CHANN, _configData$ALL_CHANN2;
62
-
63
- var channel = ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.CHANNEL) || 'OFFICIAL';
64
- var channelLinks = ((_configData$ALL_CHANN = configData.ALL_CHANNEL_LINKS) === null || _configData$ALL_CHANN === void 0 ? void 0 : _configData$ALL_CHANN[channel]) || {};
65
- var channelFeatures = ((_configData$ALL_CHANN2 = configData.ALL_CHANNEL_FEATURE_STATUS) === null || _configData$ALL_CHANN2 === void 0 ? void 0 : _configData$ALL_CHANN2[channel]) || {}; //@ts-ignore
66
-
67
- var features = configData.ALL_FEATURE_STATUS || {};
68
- return _objectSpread(_objectSpread({}, consoleConfig), {}, {
69
- CHANNEL_LINKS: channelLinks,
70
- CHANNEL_FEATURE_STATUS: channelFeatures,
71
- FEATURE_STATUS: processFeatures(features)
72
- });
73
- };
74
-
75
- var getConsoleConfig = /*#__PURE__*/function () {
76
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(option, consoleConfig) {
77
- var configData;
78
- return _regenerator.default.wrap(function _callee$(_context) {
79
- while (1) {
80
- switch (_context.prev = _context.next) {
81
- case 0:
82
- _context.next = 2;
83
- return (0, _alfaCore.getConfig)(option);
84
-
85
- case 2:
86
- configData = _context.sent;
87
- return _context.abrupt("return", mergeConfigDataWithConsoleConfig(configData, consoleConfig));
88
-
89
- case 4:
90
- case "end":
91
- return _context.stop();
92
- }
93
- }
94
- }, _callee);
95
- }));
96
-
97
- return function getConsoleConfig(_x, _x2) {
98
- return _ref.apply(this, arguments);
99
- };
100
- }();
101
-
102
- exports.getConsoleConfig = getConsoleConfig;