@doreamonjs/plugin-shared 0.3.5 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.3.8](https://github.com/zcorky/zodash/compare/v0.3.7...v0.3.8) (2022-08-31)
7
+
8
+ **Note:** Version bump only for package @doreamonjs/plugin-shared
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.3.7](https://github.com/zcorky/zodash/compare/v0.3.6...v0.3.7) (2022-08-31)
15
+
16
+ **Note:** Version bump only for package @doreamonjs/plugin-shared
17
+
18
+
19
+
20
+
21
+
22
+ ## [0.3.6](https://github.com/zcorky/zodash/compare/v0.3.5...v0.3.6) (2022-08-31)
23
+
24
+ **Note:** Version bump only for package @doreamonjs/plugin-shared
25
+
26
+
27
+
28
+
29
+
6
30
  ## [0.3.5](https://github.com/zcorky/zodash/compare/v0.3.4...v0.3.5) (2022-08-31)
7
31
 
8
32
  **Note:** Version bump only for package @doreamonjs/plugin-shared
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './type';
2
+ export * from './shared';
2
3
  export * from './message';
4
+ export * from './notification';
3
5
  export * from './router';
package/lib/index.js CHANGED
@@ -10,6 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ const shared_1 = require("./shared");
13
14
  __exportStar(require("./type"), exports);
15
+ __exportStar(require("./shared"), exports);
14
16
  __exportStar(require("./message"), exports);
17
+ __exportStar(require("./notification"), exports);
15
18
  __exportStar(require("./router"), exports);
19
+ window.__doreamonjs = shared_1.shared;
package/lib/message.d.ts CHANGED
@@ -6,6 +6,16 @@ export interface IMessage {
6
6
  warning(content: string, duration?: number, onClose?: () => void): void | Promise<void>;
7
7
  loading(content: string, duration?: number, onClose?: () => void): void | Promise<void>;
8
8
  open(config: OpenConfig): void | Promise<void>;
9
+ config(options: ConfigMessageOptions): void;
10
+ }
11
+ export interface ConfigMessageOptions {
12
+ top?: number;
13
+ duration?: number;
14
+ prefixCls?: string;
15
+ getContainer?: () => HTMLElement;
16
+ transitionName?: string;
17
+ maxCount?: number;
18
+ rtl?: boolean;
9
19
  }
10
20
  export interface OpenConfig {
11
21
  content: ReactNode;
@@ -36,4 +46,6 @@ export declare class Message implements IMessage {
36
46
  warning(content: string, duration?: number, onClose?: () => void): void | Promise<void>;
37
47
  loading(content: string, duration?: number, onClose?: () => void): void | Promise<void>;
38
48
  open(config: OpenConfig): void | Promise<void>;
49
+ config(options: ConfigMessageOptions): void;
39
50
  }
51
+ export declare const message: Message;
package/lib/message.js CHANGED
@@ -1,15 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Message = void 0;
3
+ exports.message = exports.Message = void 0;
4
+ const shared_1 = require("./shared");
4
5
  class Message {
5
6
  constructor(options) {
6
7
  this.options = options;
7
8
  }
8
9
  get messager() {
10
+ var _a, _b;
9
11
  if (this._messager)
10
12
  return this._messager;
11
- if (window.__doreamonjs.message) {
12
- this._messager = window.__doreamonjs.message;
13
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.messager) {
14
+ this._messager = (_b = this.options) === null || _b === void 0 ? void 0 : _b.messager;
15
+ }
16
+ else if (shared_1.shared.has('message')) {
17
+ this._messager = shared_1.shared.get('message');
18
+ }
19
+ else {
20
+ throw new Error('[doreamonjs] message is not registered');
13
21
  }
14
22
  return this._messager;
15
23
  }
@@ -32,5 +40,10 @@ class Message {
32
40
  open(config) {
33
41
  return this.messager.open(config);
34
42
  }
43
+ config(options) {
44
+ var _a, _b;
45
+ return (_b = (_a = this.messager) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.call(_a, options);
46
+ }
35
47
  }
36
48
  exports.Message = Message;
49
+ exports.message = new Message();
@@ -0,0 +1,57 @@
1
+ import type { ReactNode, CSSProperties } from 'react';
2
+ export interface INotification {
3
+ success(cfg: ArgsProps): void;
4
+ error(cfg: ArgsProps): void;
5
+ info(cfg: ArgsProps): void;
6
+ warning(cfg: ArgsProps): void;
7
+ open(cfg: ArgsProps): void;
8
+ config(options: ConfigNotificationOptions): void;
9
+ }
10
+ export interface ArgsProps {
11
+ message: ReactNode;
12
+ description?: ReactNode;
13
+ btn?: ReactNode;
14
+ key?: string;
15
+ onClose?: () => void;
16
+ duration?: number | null;
17
+ icon?: ReactNode;
18
+ placement?: NotificationPlacement;
19
+ style?: CSSProperties;
20
+ prefixCls?: string;
21
+ className?: string;
22
+ readonly type?: IconType;
23
+ onClick?: () => void;
24
+ top?: number;
25
+ bottom?: number;
26
+ getContainer?: () => HTMLElement;
27
+ closeIcon?: ReactNode;
28
+ }
29
+ export interface ConfigNotificationOptions {
30
+ top?: number;
31
+ bottom?: number;
32
+ duration?: number;
33
+ prefixCls?: string;
34
+ placement?: NotificationPlacement;
35
+ getContainer?: () => HTMLElement;
36
+ closeIcon?: ReactNode;
37
+ rtl?: boolean;
38
+ maxCount?: number;
39
+ }
40
+ export declare type NotificationPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
41
+ export declare type IconType = 'success' | 'info' | 'error' | 'warning';
42
+ export interface NotificationConfig {
43
+ notifier?: INotification;
44
+ }
45
+ export declare class Notification implements INotification {
46
+ private readonly options?;
47
+ private _notifier;
48
+ constructor(options?: NotificationConfig);
49
+ private get notifier();
50
+ success(cfg: ArgsProps): void;
51
+ error(cfg: ArgsProps): void;
52
+ info(cfg: ArgsProps): void;
53
+ warning(cfg: ArgsProps): void;
54
+ open(cfg: ArgsProps): void;
55
+ config(options: ConfigNotificationOptions): void;
56
+ }
57
+ export declare const notification: Notification;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.notification = exports.Notification = void 0;
4
+ const shared_1 = require("./shared");
5
+ class Notification {
6
+ constructor(options) {
7
+ this.options = options;
8
+ }
9
+ get notifier() {
10
+ var _a, _b;
11
+ if (this._notifier)
12
+ return this._notifier;
13
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.notifier) {
14
+ this._notifier = (_b = this.options) === null || _b === void 0 ? void 0 : _b.notifier;
15
+ }
16
+ else if (shared_1.shared.has('notification')) {
17
+ this._notifier = shared_1.shared.get('notification');
18
+ }
19
+ else {
20
+ throw new Error('[doreamonjs] nitification is not registered');
21
+ }
22
+ return this._notifier;
23
+ }
24
+ success(cfg) {
25
+ return this.notifier.success(cfg);
26
+ }
27
+ error(cfg) {
28
+ return this.notifier.error(cfg);
29
+ }
30
+ info(cfg) {
31
+ return this.notifier.info(cfg);
32
+ }
33
+ warning(cfg) {
34
+ return this.notifier.warning(cfg);
35
+ }
36
+ //
37
+ open(cfg) {
38
+ return this.notifier.open(cfg);
39
+ }
40
+ config(options) {
41
+ var _a, _b;
42
+ return (_b = (_a = this.notifier) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.call(_a, options);
43
+ }
44
+ }
45
+ exports.Notification = Notification;
46
+ exports.notification = new Notification();
package/lib/router.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { History } from 'history';
2
1
  export interface IRouter {
3
2
  push: (path: string | RouteData, state?: any) => void;
4
3
  replace: (path: string | RouteData, state?: any) => void;
@@ -12,13 +11,13 @@ export interface RouteData {
12
11
  state?: any;
13
12
  }
14
13
  export interface RouterOptions {
15
- history?: History;
14
+ router?: IRouter;
16
15
  }
17
16
  export declare class Router implements IRouter {
18
17
  private readonly options?;
19
- private _history;
18
+ private _router;
20
19
  constructor(options?: RouterOptions);
21
- private get history();
20
+ private get router();
22
21
  push(path: string | RouteData, state?: any): void;
23
22
  replace(path: string | RouteData, state?: any): void;
24
23
  go(count: number): void;
package/lib/router.js CHANGED
@@ -1,42 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.router = exports.Router = void 0;
4
- const history_1 = require("history");
4
+ const shared_1 = require("./shared");
5
5
  class Router {
6
6
  constructor(options) {
7
7
  this.options = options;
8
8
  }
9
- get history() {
9
+ get router() {
10
10
  var _a, _b;
11
- if (this._history)
12
- return this._history;
13
- if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.history) {
14
- this._history = (_b = this.options) === null || _b === void 0 ? void 0 : _b.history;
11
+ if (this._router)
12
+ return this._router;
13
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.router) {
14
+ this._router = (_b = this.options) === null || _b === void 0 ? void 0 : _b.router;
15
15
  }
16
- else if (window.__doreamonjs.history) {
16
+ else if (shared_1.shared.has('router')) {
17
17
  // doreamonjs
18
- this._history = window.__doreamonjs.history;
19
- }
20
- else if (window.g_history) {
21
- // umi
22
- this._history = window.g_history;
18
+ this._router = shared_1.shared.get('router');
23
19
  }
24
20
  else {
25
- this._history = history_1.createBrowserHistory();
21
+ throw new Error('[doreamonjs] router is not registered');
26
22
  }
27
- return this._history;
23
+ return this._router;
28
24
  }
29
25
  push(path, state) {
30
- this.history.push(path, state);
26
+ this.router.push(path, state);
31
27
  }
32
28
  replace(path, state) {
33
- this.history.replace(path, state);
29
+ this.router.replace(path, state);
34
30
  }
35
31
  go(count) {
36
- this.history.go(count);
32
+ this.router.go(count);
37
33
  }
38
34
  goBack() {
39
- this.history.back();
35
+ this.router.goBack();
40
36
  }
41
37
  }
42
38
  exports.Router = Router;
@@ -0,0 +1,8 @@
1
+ export declare type SharedServiceKey = 'message' | 'notification' | 'router';
2
+ export declare class Shared {
3
+ private store;
4
+ register(key: SharedServiceKey, value: any): void;
5
+ get(key: SharedServiceKey): any;
6
+ has(key: SharedServiceKey): boolean;
7
+ }
8
+ export declare const shared: Shared;
package/lib/shared.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shared = exports.Shared = void 0;
4
+ class Shared {
5
+ constructor() {
6
+ this.store = {};
7
+ }
8
+ register(key, value) {
9
+ this.store[key] = value;
10
+ }
11
+ get(key) {
12
+ const service = this.store[key];
13
+ if (!service) {
14
+ throw new Error(`Shared service ${key} not registered`);
15
+ }
16
+ return service;
17
+ }
18
+ has(key) {
19
+ return !!this.store[key];
20
+ }
21
+ }
22
+ exports.Shared = Shared;
23
+ exports.shared = new Shared();
package/lib/type.d.ts CHANGED
@@ -1,9 +1,8 @@
1
+ import { Shared } from './shared';
1
2
  declare global {
2
3
  interface Window {
3
- __doreamonjs: DoreamonJS;
4
+ __doreamonjs: DoreamonJSShared;
4
5
  }
5
6
  }
6
- export interface DoreamonJS {
7
- message: any;
8
- history: any;
7
+ export interface DoreamonJSShared extends Shared {
9
8
  }
package/lib/type.js CHANGED
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- window.__doreamonjs = window.__doreamonjs || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doreamonjs/plugin-shared",
3
- "version": "0.3.5",
3
+ "version": "0.3.8",
4
4
  "description": "shared plugin for doreamonjs",
5
5
  "keywords": [
6
6
  "doreamonjs",
@@ -64,10 +64,12 @@
64
64
  "bugs": {
65
65
  "url": "https://github.com/zcorky/zodash/issues"
66
66
  },
67
+ "devDependencies": {
68
+ "@types/react": "^16"
69
+ },
67
70
  "dependencies": {
68
- "@zcorky/query-string": "^1.0.2",
69
71
  "@zodash/doreamon": "^1.0.17",
70
72
  "history": "^5.3.0"
71
73
  },
72
- "gitHead": "b98aa80b724d635801ecdb8044f2256bf186abe4"
74
+ "gitHead": "38b601ea285643d97ae0f5adaab938b5dd7b5b4b"
73
75
  }