1 | "use strict";
|
2 |
|
3 | var _class, _temp;
|
4 |
|
5 | const {
|
6 | UIPlugin
|
7 | } = require('@uppy/core');
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | module.exports = (_temp = _class = class ReduxDevTools extends UIPlugin {
|
21 | constructor(uppy, opts) {
|
22 | super(uppy, opts);
|
23 | this.type = 'debugger';
|
24 | this.id = this.opts.id || 'ReduxDevTools';
|
25 | this.title = 'Redux DevTools';
|
26 |
|
27 | const defaultOptions = {};
|
28 |
|
29 | this.opts = { ...defaultOptions,
|
30 | ...opts
|
31 | };
|
32 | this.handleStateChange = this.handleStateChange.bind(this);
|
33 | this.initDevTools = this.initDevTools.bind(this);
|
34 | }
|
35 |
|
36 | handleStateChange(prevState, nextState) {
|
37 | this.devTools.send('UPPY_STATE_UPDATE', nextState);
|
38 | }
|
39 |
|
40 | initDevTools() {
|
41 | this.devTools = window.devToolsExtension.connect();
|
42 | this.devToolsUnsubscribe = this.devTools.subscribe(message => {
|
43 | if (message.type === 'DISPATCH') {
|
44 |
|
45 | switch (message.payload.type) {
|
46 | case 'RESET':
|
47 | this.uppy.reset();
|
48 | return;
|
49 |
|
50 | case 'IMPORT_STATE':
|
51 | {
|
52 | const {
|
53 | computedStates
|
54 | } = message.payload.nextLiftedState;
|
55 | this.uppy.store.state = { ...this.uppy.getState(),
|
56 | ...computedStates[computedStates.length - 1].state
|
57 | };
|
58 | this.uppy.updateAll(this.uppy.getState());
|
59 | return;
|
60 | }
|
61 |
|
62 | case 'JUMP_TO_STATE':
|
63 | case 'JUMP_TO_ACTION':
|
64 | this.uppy.store.state = { ...this.uppy.getState(),
|
65 | ...JSON.parse(message.state)
|
66 | };
|
67 | this.uppy.updateAll(this.uppy.getState());
|
68 | }
|
69 | }
|
70 | });
|
71 | }
|
72 |
|
73 | install() {
|
74 |
|
75 | this.withDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__;
|
76 |
|
77 | if (this.withDevTools) {
|
78 | this.initDevTools();
|
79 | this.uppy.on('state-update', this.handleStateChange);
|
80 | }
|
81 | }
|
82 |
|
83 | uninstall() {
|
84 | if (this.withDevTools) {
|
85 | this.devToolsUnsubscribe();
|
86 | this.uppy.off('state-update', this.handleStateUpdate);
|
87 | }
|
88 | }
|
89 |
|
90 | }, _class.VERSION = "2.0.3", _temp); |
\ | No newline at end of file |