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

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.
Files changed (43) hide show
  1. package/dist/index.js +6 -6
  2. package/es/app/createIsomorphicMicroApp.js +36 -0
  3. package/es/app/getConsoleConfig.js +1 -1
  4. package/es/app.js +29 -41
  5. package/es/context.js +7 -0
  6. package/es/createAlfaApp.js +116 -0
  7. package/es/createAlfaWidget.js +125 -0
  8. package/es/createApplication.js +113 -0
  9. package/es/types/base.js +26 -0
  10. package/es/types/index.js +1 -0
  11. package/es/utils/getConsoleConfig.js +2 -2
  12. package/es/utils/index.js +3 -0
  13. package/es/widget/emitter.js +4 -4
  14. package/es/widget/getWidgetConfigById.js +6 -5
  15. package/es/widget/getWidgetDeps.js +1 -1
  16. package/es/widget.js +0 -6
  17. package/lib/app/createIsomorphicMicroApp.js +55 -0
  18. package/lib/app/getConsoleConfig.js +1 -1
  19. package/lib/app.js +28 -40
  20. package/lib/base.d.ts +0 -3
  21. package/lib/context.d.ts +7 -0
  22. package/lib/context.js +15 -0
  23. package/lib/createAlfaApp.d.ts +4 -0
  24. package/lib/createAlfaApp.js +135 -0
  25. package/lib/createAlfaWidget.d.ts +4 -0
  26. package/lib/createAlfaWidget.js +145 -0
  27. package/lib/createApplication.d.ts +12 -0
  28. package/lib/createApplication.js +133 -0
  29. package/lib/types/base.d.ts +11 -0
  30. package/lib/types/base.js +37 -0
  31. package/lib/types/index.d.ts +86 -0
  32. package/lib/types/index.js +5 -0
  33. package/lib/types.d.ts +0 -1
  34. package/lib/utils/getConsoleConfig.d.ts +21 -2
  35. package/lib/utils/getConsoleConfig.js +2 -2
  36. package/lib/utils/index.d.ts +1 -0
  37. package/lib/utils/index.js +12 -0
  38. package/lib/widget/emitter.d.ts +1 -0
  39. package/lib/widget/emitter.js +4 -4
  40. package/lib/widget/getWidgetConfigById.js +6 -5
  41. package/lib/widget/getWidgetDeps.js +1 -1
  42. package/lib/widget.js +0 -7
  43. package/package.json +5 -8
@@ -0,0 +1,133 @@
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.default = createApplication;
11
+
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
16
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
+
18
+ var _react = _interopRequireWildcard(require("react"));
19
+
20
+ var _Loading = _interopRequireDefault(require("./components/Loading"));
21
+
22
+ var _utils = require("./utils");
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
+ /**
29
+ * container for microApp mount
30
+ * @param loader alfa-core loader
31
+ * @returns
32
+ */
33
+ function createApplication(loader) {
34
+ function Application(props) {
35
+ var name = props.name,
36
+ manifest = props.manifest,
37
+ loading = props.loading,
38
+ sandbox = props.sandbox,
39
+ customProps = props.customProps,
40
+ className = props.className,
41
+ style = props.style;
42
+
43
+ var _useState = (0, _react.useState)(null),
44
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
45
+ app = _useState2[0],
46
+ setApp = _useState2[1];
47
+
48
+ var appRef = (0, _react.useRef)(null);
49
+ var tagName = (0, _utils.normalizeName)(props.name);
50
+ (0, _react.useEffect)(function () {
51
+ // eslint-disable-next-line no-useless-catch
52
+ (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
53
+ var _yield$loader$registe, App;
54
+
55
+ return _regenerator.default.wrap(function _callee$(_context) {
56
+ while (1) {
57
+ switch (_context.prev = _context.next) {
58
+ case 0:
59
+ _context.next = 2;
60
+ return loader.register({
61
+ name: name,
62
+ manifest: manifest,
63
+ container: appRef.current,
64
+ props: customProps,
65
+ sandbox: sandbox
66
+ });
67
+
68
+ case 2:
69
+ _yield$loader$registe = _context.sent;
70
+ App = _yield$loader$registe.app;
71
+
72
+ if (App) {
73
+ _context.next = 6;
74
+ break;
75
+ }
76
+
77
+ throw new Error('[alfa-react] load app failed.');
78
+
79
+ case 6:
80
+ _context.next = 8;
81
+ return App.load();
82
+
83
+ case 8:
84
+ if (appRef.current) {
85
+ _context.next = 10;
86
+ break;
87
+ }
88
+
89
+ throw new Error('[alfa-react] container not found');
90
+
91
+ case 10:
92
+ _context.next = 12;
93
+ return App.mount(appRef.current, {
94
+ customProps: customProps
95
+ });
96
+
97
+ case 12:
98
+ setApp(App);
99
+ return _context.abrupt("return", function () {
100
+ App && App.unmount();
101
+ });
102
+
103
+ case 14:
104
+ case "end":
105
+ return _context.stop();
106
+ }
107
+ }
108
+ }, _callee);
109
+ }))().catch(function (e) {
110
+ throw e;
111
+ });
112
+ }, [name, manifest, customProps, sandbox]);
113
+
114
+ if (app) {
115
+ app.update(customProps);
116
+ }
117
+
118
+ return /*#__PURE__*/_react.default.createElement(_react.Suspense, {
119
+ fallback: /*#__PURE__*/_react.default.createElement(_Loading.default, {
120
+ loading: loading
121
+ })
122
+ }, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, sandbox && sandbox !== true && sandbox.disableFakeBody ? /*#__PURE__*/_react.default.createElement(tagName, {
123
+ style: style,
124
+ className: className,
125
+ ref: appRef,
126
+ dataId: name
127
+ }) : /*#__PURE__*/_react.default.createElement(tagName, {}, /*#__PURE__*/_react.default.createElement('div', {
128
+ ref: appRef
129
+ }))));
130
+ }
131
+
132
+ return Application;
133
+ }
@@ -0,0 +1,11 @@
1
+ import React, { HTMLAttributes } from 'react';
2
+ import { IAppConfig, IOptions, AlfaEnvEnum } from '@alicloud/alfa-core';
3
+ export interface IProps<T = any> extends HTMLAttributes<Element>, IAppConfig, IOptions {
4
+ loading?: boolean | React.ReactChild;
5
+ consoleConfig?: any;
6
+ i18nMessages?: any;
7
+ env?: AlfaEnvEnum;
8
+ dependencies?: any;
9
+ }
10
+ export default class MicroAppBase<T> extends React.Component<Partial<IProps<T>>> {
11
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
+
14
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
+
16
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
+
18
+ var _react = _interopRequireDefault(require("react"));
19
+
20
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
21
+
22
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
23
+
24
+ var MicroAppBase = /*#__PURE__*/function (_React$Component) {
25
+ (0, _inherits2.default)(MicroAppBase, _React$Component);
26
+
27
+ var _super = _createSuper(MicroAppBase);
28
+
29
+ function MicroAppBase() {
30
+ (0, _classCallCheck2.default)(this, MicroAppBase);
31
+ return _super.apply(this, arguments);
32
+ }
33
+
34
+ return MicroAppBase;
35
+ }(_react.default.Component);
36
+
37
+ exports.default = MicroAppBase;
@@ -0,0 +1,86 @@
1
+ /// <reference types="react" />
2
+ import React from 'React';
3
+ import { createMicroApp, IAppConfig } from '@alicloud/alfa-core';
4
+ export interface AlfaVersion {
5
+ entry: string;
6
+ }
7
+ declare type Version = string;
8
+ export interface AlfaReleaseConfig {
9
+ versions: Record<Version, AlfaVersion>;
10
+ 'dist-tag': Record<string, string>;
11
+ }
12
+ export declare type EnvEnum = 'prod' | 'local' | 'pre' | 'daily';
13
+ export interface AlfaFactoryOption extends IAppConfig {
14
+ loading?: boolean | React.ReactChild;
15
+ dependencies?: Record<string, any>;
16
+ className?: string;
17
+ style?: Record<string, any>;
18
+ unstable_runtime?: {
19
+ css?: Record<string, string>;
20
+ js?: Record<string, string>;
21
+ };
22
+ }
23
+ declare type OmitKeys = 'manifest';
24
+ export interface WidgetFactoryOption extends Omit<AlfaFactoryOption, OmitKeys> {
25
+ runtimeVersion?: string;
26
+ alfaLoader?: boolean;
27
+ theme?: string;
28
+ }
29
+ export interface AlfaEnvConfigDescriptor {
30
+ releaseUrl: string;
31
+ configUrl?: string;
32
+ cdnBackupUrl?: string;
33
+ resourceUrl?: string;
34
+ }
35
+ export interface AlfaEnvConfig {
36
+ daily: AlfaEnvConfigDescriptor;
37
+ local: AlfaEnvConfigDescriptor;
38
+ pre: AlfaEnvConfigDescriptor;
39
+ prod: AlfaEnvConfigDescriptor;
40
+ }
41
+ export interface WidgetReleaseConfig {
42
+ [id: string]: {
43
+ [version: string]: {
44
+ latest: string;
45
+ };
46
+ };
47
+ }
48
+ export interface WidgetCWSConfig {
49
+ conf: {
50
+ [channel: string]: {
51
+ [key: string]: string;
52
+ };
53
+ };
54
+ features: {
55
+ [channel: string]: {
56
+ [key: string]: boolean;
57
+ };
58
+ };
59
+ links: {
60
+ [channel: string]: {
61
+ [key: string]: string;
62
+ };
63
+ };
64
+ locales: {
65
+ [locale: string]: {
66
+ messages: {
67
+ [key: string]: string;
68
+ };
69
+ };
70
+ };
71
+ }
72
+ export interface WidgetRuntime {
73
+ react: any;
74
+ reactDom: any;
75
+ axios: any;
76
+ 'prop-types': any;
77
+ '@ali/wind': any;
78
+ '@ali/wind-utils-console': any;
79
+ '@ali/wind-intl': any;
80
+ '@ali/wind-intl/lib/Provider': any;
81
+ '@ali/wind-intl/lib/withRcIntl': any;
82
+ '@ali/widget-utils-console': any;
83
+ }
84
+ declare type ThenArg<T> = T extends PromiseLike<infer U> ? U : T;
85
+ export declare type MicroApplication = ThenArg<ReturnType<typeof createMicroApp>>;
86
+ export {};
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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;
@@ -1,2 +1,21 @@
1
- import { AlfaFactoryOption } from '@alicloud/alfa-core';
2
- export declare const getConsoleConfig: (option: AlfaFactoryOption, consoleConfig: any) => Promise<any>;
1
+ import { IAppConfig } from '@alicloud/alfa-core';
2
+ export declare const getConsoleConfig: (config: IAppConfig, consoleConfig: any) => Promise<{
3
+ CHANNEL_LINKS: Partial<Record<string, string>>;
4
+ CHANNEL_FEATURE_STATUS: Partial<Record<string, {
5
+ status: boolean;
6
+ attribute: {
7
+ customAttrs: Record<string, unknown>;
8
+ regions: {
9
+ region: string[];
10
+ };
11
+ };
12
+ }>>;
13
+ FEATURE_STATUS: Partial<Record<string, boolean>>;
14
+ fEnv?: string | undefined;
15
+ LOCALE?: string | undefined;
16
+ CHANNEL?: string | undefined;
17
+ SEC_TOKEN?: string | undefined;
18
+ portalType?: string | undefined;
19
+ MAIN_ACCOUNT_PK?: string | undefined;
20
+ CURRENT_PK?: string | undefined;
21
+ }>;
@@ -73,14 +73,14 @@ var mergeConfigDataWithConsoleConfig = function mergeConfigDataWithConsoleConfig
73
73
  };
74
74
 
75
75
  var getConsoleConfig = /*#__PURE__*/function () {
76
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(option, consoleConfig) {
76
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(config, consoleConfig) {
77
77
  var configData;
78
78
  return _regenerator.default.wrap(function _callee$(_context) {
79
79
  while (1) {
80
80
  switch (_context.prev = _context.next) {
81
81
  case 0:
82
82
  _context.next = 2;
83
- return (0, _alfaCore.getConfig)(option);
83
+ return (0, _alfaCore.getConfig)(config);
84
84
 
85
85
  case 2:
86
86
  configData = _context.sent;
@@ -0,0 +1 @@
1
+ export declare const normalizeName: (name: string) => string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeName = void 0;
7
+
8
+ var normalizeName = function normalizeName(name) {
9
+ return name.replace(/@/g, '').replace(/\//g, '-');
10
+ };
11
+
12
+ exports.normalizeName = normalizeName;
@@ -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.5",
4
4
  "description": "Alfa Framework (React Version)",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -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.5",
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": "02863a2388162a395d3e51f54d122745d10e2a75"
50
47
  }