@doreamonjs/plugin-popup 1.6.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/CHANGELOG.md ADDED
@@ -0,0 +1,106 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.6.0](https://github.com/doreamonjs/doreamon/compare/v1.5.0...v1.6.0) (2023-06-27)
7
+
8
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.2.13](https://github.com/doreamonjs/doreamon/compare/v1.2.12...v1.2.13) (2022-11-14)
15
+
16
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
17
+
18
+ ## [1.2.5](https://github.com/doreamonjs/doreamon/compare/v1.2.4...v1.2.5) (2022-10-17)
19
+
20
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
21
+
22
+ ## [1.1.36](https://github.com/doreamonjs/doreamon/compare/v1.1.35...v1.1.36) (2022-10-10)
23
+
24
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
25
+
26
+ ## [1.1.35](https://github.com/doreamonjs/doreamon/compare/v1.1.34...v1.1.35) (2022-10-10)
27
+
28
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
29
+
30
+ ## [1.1.34](https://github.com/doreamonjs/doreamon/compare/v1.1.33...v1.1.34) (2022-10-10)
31
+
32
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
33
+
34
+ ## [1.1.33](https://github.com/doreamonjs/doreamon/compare/v1.1.32...v1.1.33) (2022-10-10)
35
+
36
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
37
+
38
+ ## [1.1.32](https://github.com/doreamonjs/doreamon/compare/v1.1.31...v1.1.32) (2022-10-10)
39
+
40
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
41
+
42
+ ## [1.1.31](https://github.com/doreamonjs/doreamon/compare/v1.1.30...v1.1.31) (2022-10-10)
43
+
44
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
45
+
46
+ ## [1.1.28](https://github.com/doreamonjs/doreamon/compare/v1.1.27...v1.1.28) (2022-09-29)
47
+
48
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
49
+
50
+ ## [1.1.22](https://github.com/doreamonjs/doreamon/compare/v1.1.21...v1.1.22) (2022-09-16)
51
+
52
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
53
+
54
+ ## [1.1.8](https://github.com/doreamonjs/doreamon/compare/v1.1.7...v1.1.8) (2022-09-09)
55
+
56
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
57
+
58
+ # [1.1.0](https://github.com/doreamonjs/doreamon/compare/v1.0.3...v1.1.0) (2022-09-06)
59
+
60
+ ### Features
61
+
62
+ - **plugin-popup:** service use promise for sdk ([21b9026](https://github.com/doreamonjs/doreamon/commit/21b9026b8108498e524ce1a30a666eb62253f49c))
63
+
64
+ ## [1.0.1](https://github.com/doreamonjs/doreamon/compare/v0.6.13...v1.0.1) (2022-09-04)
65
+
66
+ ### Bug Fixes
67
+
68
+ - update dependencies versions ([77fb520](https://github.com/doreamonjs/doreamon/commit/77fb520f652d2bb1a6ffe25399d14bd204b3f87e))
69
+
70
+ ## [0.6.10](https://github.com/doreamonjs/doreamon/compare/v0.6.9...v0.6.10) (2022-09-04)
71
+
72
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
73
+
74
+ ## [0.6.4](https://github.com/doreamonjs/doreamon/compare/v0.6.3...v0.6.4) (2022-09-03)
75
+
76
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
77
+
78
+ # [0.6.0](https://github.com/doreamonjs/doreamon/compare/v0.5.0...v0.6.0) (2022-09-03)
79
+
80
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
81
+
82
+ # [0.5.0](https://github.com/doreamonjs/doreamon/compare/v0.4.5...v0.5.0) (2022-09-02)
83
+
84
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
85
+
86
+ ## [0.4.2](https://github.com/doreamonjs/doreamon/compare/v0.4.1...v0.4.2) (2022-08-31)
87
+
88
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
89
+
90
+ ## [0.4.1](https://github.com/doreamonjs/doreamon/compare/v0.4.0...v0.4.1) (2022-08-31)
91
+
92
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
93
+
94
+ # [0.4.0](https://github.com/doreamonjs/doreamon/compare/v0.3.17...v0.4.0) (2022-08-31)
95
+
96
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
97
+
98
+ ## [0.3.16](https://github.com/doreamonjs/doreamon/compare/v0.3.15...v0.3.16) (2022-08-31)
99
+
100
+ **Note:** Version bump only for package @doreamonjs/plugin-popup
101
+
102
+ ## [0.3.15](https://github.com/doreamonjs/doreamon/compare/v0.3.14...v0.3.15) (2022-08-31)
103
+
104
+ ### Bug Fixes
105
+
106
+ - merge confict and clean changelog ([b5b0428](https://github.com/doreamonjs/doreamon/commit/b5b042803ef660e6c8faf214bd24fc27934deb91))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Eason
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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@doreamonjs/plugin-popup`
2
+
3
+ > TODO: description
@@ -0,0 +1,2 @@
1
+ export declare const NAMESPACE = "popups";
2
+ export declare function namespace(): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.namespace = exports.NAMESPACE = void 0;
4
+ exports.NAMESPACE = 'popups';
5
+ function namespace() {
6
+ return exports.NAMESPACE;
7
+ }
8
+ exports.namespace = namespace;
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './types';
2
+ export * from './constants';
3
+ export * from './model';
4
+ export * from './service';
5
+ export * from './instance';
package/lib/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./types"), exports);
14
+ __exportStar(require("./constants"), exports);
15
+ __exportStar(require("./model"), exports);
16
+ __exportStar(require("./service"), exports);
17
+ __exportStar(require("./instance"), exports);
@@ -0,0 +1,4 @@
1
+ import { Model } from './model';
2
+ import { Service } from './service';
3
+ export declare const model: Model;
4
+ export declare const service: Service;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.service = exports.model = void 0;
4
+ const model_1 = require("./model");
5
+ const service_1 = require("./service");
6
+ exports.model = new model_1.Model();
7
+ exports.service = new service_1.Service();
package/lib/model.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { Model as DvaModel } from 'dva';
2
+ export interface ModelOptions {
3
+ }
4
+ export declare class Model {
5
+ readonly options?: ModelOptions;
6
+ constructor(options?: ModelOptions);
7
+ get namespace(): string;
8
+ build(): DvaModel;
9
+ toDva(): DvaModel;
10
+ }
package/lib/model.js ADDED
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Model = void 0;
4
+ const doreamon_1 = require("@zodash/doreamon");
5
+ const constants_1 = require("./constants");
6
+ class Model {
7
+ constructor(options) {
8
+ this.options = options;
9
+ }
10
+ get namespace() {
11
+ return constants_1.NAMESPACE;
12
+ }
13
+ build() {
14
+ return {
15
+ namespace: constants_1.NAMESPACE,
16
+ state: {
17
+ visible: false,
18
+ attributes: {
19
+ type: 'modal',
20
+ title: '授权',
21
+ submitText: '确认',
22
+ //
23
+ // render
24
+ },
25
+ datasets: {
26
+ values: {}, // data is here
27
+ },
28
+ // callback function
29
+ callback: null,
30
+ // queue
31
+ queue: [],
32
+ },
33
+ reducers: {
34
+ save: (state, { payload }) => ({ ...state, ...payload }),
35
+ 'value/change'(state, { payload }) {
36
+ return { ...state, datasets: { ...state.datasets, ...payload } };
37
+ },
38
+ },
39
+ effects: {
40
+ // ui
41
+ *open({ payload }, { select, put }) {
42
+ const visible = yield select((state) => state[constants_1.NAMESPACE].visible);
43
+ if (visible) {
44
+ return yield put({
45
+ type: 'queue/in',
46
+ payload,
47
+ });
48
+ }
49
+ const { attributes, datasets = {}, callback, } = payload || {};
50
+ const { target, render } = attributes || {};
51
+ if (callback) {
52
+ callback(null, 'open');
53
+ }
54
+ else if (!target) {
55
+ throw new Error(`attributes.target is required`);
56
+ }
57
+ else if (!(datasets === null || datasets === void 0 ? void 0 : datasets.values)) {
58
+ throw new Error(`datasets.values is required`);
59
+ }
60
+ if (!render) {
61
+ throw new Error(`attributes.render is required`);
62
+ }
63
+ yield put({
64
+ type: 'save',
65
+ payload: {
66
+ visible: true,
67
+ attributes,
68
+ datasets,
69
+ //
70
+ callback,
71
+ },
72
+ });
73
+ },
74
+ // data
75
+ *submit({ payload: { values: updates } }, { select, put, call, take }) {
76
+ var _a;
77
+ const { attributes, datasets: originals, callback, } = yield select((state) => state[constants_1.NAMESPACE]);
78
+ const { target } = attributes || {};
79
+ if (callback) {
80
+ //
81
+ }
82
+ else if (!target) {
83
+ throw new Error(`require attributes.target`);
84
+ }
85
+ const { namespace, effect, props } = target || {};
86
+ const nextEffect = `${namespace}/${effect}`;
87
+ const datasets = doreamon_1.default.immer.produce(originals, (draft) => {
88
+ draft.values = {
89
+ ...originals.values,
90
+ ...updates,
91
+ };
92
+ });
93
+ yield put({ type: 'save', payload: { datasets } });
94
+ // @TODO business
95
+ yield call(doreamon_1.default.delay, 300);
96
+ if (callback) {
97
+ yield put({ type: 'close' });
98
+ callback(null, 'ok', (_a = datasets) === null || _a === void 0 ? void 0 : _a.values);
99
+ yield put({ type: 'queue/out' });
100
+ return;
101
+ }
102
+ yield put({ ...props, type: nextEffect, payload: datasets });
103
+ yield take(`${nextEffect}/@@end`);
104
+ yield put({ type: 'close' });
105
+ yield put({ type: 'queue/out' });
106
+ },
107
+ *cancel(action, { select, put }) {
108
+ const { callback } = yield select((state) => state.confirms);
109
+ yield put({ type: 'save', payload: { visible: false } });
110
+ callback === null || callback === void 0 ? void 0 : callback(null, 'cancel');
111
+ yield put({ type: 'queue/out' });
112
+ },
113
+ //
114
+ *close({ payload }, { put }) {
115
+ var _a;
116
+ yield put({ type: 'save', payload: { visible: false } });
117
+ yield put({ type: 'queue/out' });
118
+ (_a = payload === null || payload === void 0 ? void 0 : payload.onOk) === null || _a === void 0 ? void 0 : _a.call(payload);
119
+ },
120
+ //
121
+ *'queue/in'({ payload }, { select, put }) {
122
+ const state = yield select((state) => state[constants_1.NAMESPACE]);
123
+ yield put({
124
+ type: 'save',
125
+ payload: {
126
+ ...state,
127
+ queue: !state.queue ? [payload] : [...state.queue, payload],
128
+ },
129
+ });
130
+ },
131
+ *'queue/out'(action, { select, put, call }) {
132
+ yield call(doreamon_1.default.delay, 500);
133
+ const { queue } = yield select((state) => state[constants_1.NAMESPACE]);
134
+ if ((queue === null || queue === void 0 ? void 0 : queue.length) > 0) {
135
+ yield put({
136
+ type: 'save',
137
+ payload: {
138
+ queue: queue.slice(1),
139
+ },
140
+ });
141
+ yield put({
142
+ type: 'open',
143
+ payload: queue[0],
144
+ });
145
+ }
146
+ },
147
+ },
148
+ };
149
+ }
150
+ toDva() {
151
+ return this.build();
152
+ }
153
+ }
154
+ exports.Model = Model;
@@ -0,0 +1,22 @@
1
+ /// <reference types="react" />
2
+ export interface OpenConfig {
3
+ title: string;
4
+ render: (props: any) => React.ReactNode;
5
+ type?: 'drawer' | 'modal';
6
+ confirmText?: string;
7
+ onError?: (err: any) => void;
8
+ onOpen?: () => void;
9
+ onOk?: () => void;
10
+ onCancel?: () => void;
11
+ }
12
+ export interface OpenResult {
13
+ status: FinishStatus;
14
+ }
15
+ export declare type FinishStatus = 'ok' | 'cancel';
16
+ export declare class Service {
17
+ private logger;
18
+ get namespace(): string;
19
+ private dispatch;
20
+ open(cfg: OpenConfig): Promise<OpenResult>;
21
+ close(): Promise<void>;
22
+ }
package/lib/service.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Service = void 0;
4
+ const shared = require("@doreamonjs/plugin-shared");
5
+ const constants_1 = require("./constants");
6
+ class Service {
7
+ constructor() {
8
+ this.logger = shared.logger;
9
+ }
10
+ get namespace() {
11
+ return constants_1.NAMESPACE;
12
+ }
13
+ dispatch(type, payload) {
14
+ shared.store.dispatch({
15
+ type: `${constants_1.NAMESPACE}/${type}`,
16
+ payload,
17
+ });
18
+ }
19
+ open(cfg) {
20
+ return new Promise((resolve, reject) => {
21
+ try {
22
+ this.dispatch('open', {
23
+ attributes: cfg,
24
+ //
25
+ callback: (err, status, values) => {
26
+ var _a, _b, _c, _d;
27
+ if (err) {
28
+ return (_a = cfg.onError) === null || _a === void 0 ? void 0 : _a.call(cfg, err);
29
+ }
30
+ switch (status) {
31
+ case 'open':
32
+ (_b = cfg.onOpen) === null || _b === void 0 ? void 0 : _b.call(cfg);
33
+ return;
34
+ case 'ok':
35
+ (_c = cfg.onOk) === null || _c === void 0 ? void 0 : _c.call(cfg);
36
+ return resolve({ status });
37
+ case 'cancel':
38
+ (_d = cfg.onCancel) === null || _d === void 0 ? void 0 : _d.call(cfg);
39
+ return resolve({ status });
40
+ default:
41
+ throw new Error(`unknown status: ${status}`);
42
+ }
43
+ },
44
+ });
45
+ }
46
+ catch (error) {
47
+ reject(error);
48
+ }
49
+ });
50
+ }
51
+ close() {
52
+ return new Promise((resolve, reject) => {
53
+ try {
54
+ this.dispatch('close', {
55
+ onOk: resolve,
56
+ });
57
+ }
58
+ catch (error) {
59
+ reject(error);
60
+ }
61
+ });
62
+ }
63
+ }
64
+ exports.Service = Service;
package/lib/types.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ export interface State {
2
+ visible: boolean;
3
+ attributes: Attributes;
4
+ datasets: Datasets;
5
+ queue: State[];
6
+ callback?: (err: Error | null, type: 'open' | 'close' | 'cancel' | 'ok', vallues?: any) => void;
7
+ }
8
+ export interface Attributes {
9
+ type?: Type;
10
+ title?: string;
11
+ submitText: string;
12
+ target: AttributeTarget;
13
+ }
14
+ export interface Datasets {
15
+ origin: object;
16
+ values: object;
17
+ }
18
+ export interface AttributeTarget {
19
+ namespace: string;
20
+ effect: string;
21
+ props: any;
22
+ }
23
+ export declare type Type = 'modal' | 'drawer';
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@doreamonjs/plugin-popup",
3
+ "version": "1.6.0",
4
+ "description": "popup plugin for doreamonjs",
5
+ "keywords": [
6
+ "doreamonjs",
7
+ "plugin"
8
+ ],
9
+ "author": "whatwewant <tobewhatwewant@gmail.com>",
10
+ "homepage": "https://github.com/doreamonjs/doreamon#readme",
11
+ "license": "MIT",
12
+ "main": "lib/index.js",
13
+ "typings": "lib/index.d.ts",
14
+ "directories": {
15
+ "lib": "lib"
16
+ },
17
+ "files": [
18
+ "lib"
19
+ ],
20
+ "jest": {
21
+ "roots": [
22
+ "__tests__"
23
+ ],
24
+ "transform": {
25
+ "^.+\\.tsx?$": "ts-jest"
26
+ },
27
+ "testRegex": ".*\\.(spec|test)\\.(ts|tsx)$",
28
+ "moduleDirectories": [
29
+ "node_modules",
30
+ "src"
31
+ ],
32
+ "moduleFileExtensions": [
33
+ "ts",
34
+ "tsx",
35
+ "js",
36
+ "jsx"
37
+ ],
38
+ "coverageDirectory": "./coverage/",
39
+ "collectCoverage": true,
40
+ "collectCoverageFrom": [
41
+ "src/**/*.{ts,tsx}"
42
+ ],
43
+ "coverageThreshold": {
44
+ "global": {
45
+ "branches": 60,
46
+ "functions": 60,
47
+ "lines": 60,
48
+ "statements": -10
49
+ }
50
+ }
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "git+https://github.com/doreamonjs/doreamon.git"
58
+ },
59
+ "scripts": {
60
+ "build": "tsc",
61
+ "test": "jest -w 1",
62
+ "coverage": "codecov"
63
+ },
64
+ "bugs": {
65
+ "url": "https://github.com/doreamonjs/doreamon/issues"
66
+ },
67
+ "dependencies": {
68
+ "@doreamonjs/plugin-shared": "^1.1.28",
69
+ "@doreamonjs/request": "^1.2.13",
70
+ "@sentry/browser": "^7.11.1",
71
+ "@sentry/tracing": "^7.11.1",
72
+ "@zcorky/delay": "^1.0.1",
73
+ "@zcorky/query-string": "^1.0.2",
74
+ "@zodash/doreamon": "^1.1.5",
75
+ "dva": "^2.4.1",
76
+ "immer": "^9.0.15",
77
+ "mixpanel-browser": "^2.45.0",
78
+ "thinkingdata-browser": "^1.6.0"
79
+ },
80
+ "gitHead": "fb004a1079919e1e83f91610c2fb700aba079d66"
81
+ }