Blame view

天文台pc/tianwentai-ui/node_modules/react-dnd/dist/internals/SourceConnector.js 5.58 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  import { shallowEqual } from '@react-dnd/shallowequal';
  import { isRef } from './isRef.js';
  import { wrapConnectorHooks } from './wrapConnectorHooks.js';
  export class SourceConnector {
      receiveHandlerId(newHandlerId) {
          if (this.handlerId === newHandlerId) {
              return;
          }
          this.handlerId = newHandlerId;
          this.reconnect();
      }
      get connectTarget() {
          return this.dragSource;
      }
      get dragSourceOptions() {
          return this.dragSourceOptionsInternal;
      }
      set dragSourceOptions(options) {
          this.dragSourceOptionsInternal = options;
      }
      get dragPreviewOptions() {
          return this.dragPreviewOptionsInternal;
      }
      set dragPreviewOptions(options) {
          this.dragPreviewOptionsInternal = options;
      }
      reconnect() {
          const didChange = this.reconnectDragSource();
          this.reconnectDragPreview(didChange);
      }
      reconnectDragSource() {
          const dragSource = this.dragSource;
          // if nothing has changed then don't resubscribe
          const didChange = this.didHandlerIdChange() || this.didConnectedDragSourceChange() || this.didDragSourceOptionsChange();
          if (didChange) {
              this.disconnectDragSource();
          }
          if (!this.handlerId) {
              return didChange;
          }
          if (!dragSource) {
              this.lastConnectedDragSource = dragSource;
              return didChange;
          }
          if (didChange) {
              this.lastConnectedHandlerId = this.handlerId;
              this.lastConnectedDragSource = dragSource;
              this.lastConnectedDragSourceOptions = this.dragSourceOptions;
              this.dragSourceUnsubscribe = this.backend.connectDragSource(this.handlerId, dragSource, this.dragSourceOptions);
          }
          return didChange;
      }
      reconnectDragPreview(forceDidChange = false) {
          const dragPreview = this.dragPreview;
          // if nothing has changed then don't resubscribe
          const didChange = forceDidChange || this.didHandlerIdChange() || this.didConnectedDragPreviewChange() || this.didDragPreviewOptionsChange();
          if (didChange) {
              this.disconnectDragPreview();
          }
          if (!this.handlerId) {
              return;
          }
          if (!dragPreview) {
              this.lastConnectedDragPreview = dragPreview;
              return;
          }
          if (didChange) {
              this.lastConnectedHandlerId = this.handlerId;
              this.lastConnectedDragPreview = dragPreview;
              this.lastConnectedDragPreviewOptions = this.dragPreviewOptions;
              this.dragPreviewUnsubscribe = this.backend.connectDragPreview(this.handlerId, dragPreview, this.dragPreviewOptions);
          }
      }
      didHandlerIdChange() {
          return this.lastConnectedHandlerId !== this.handlerId;
      }
      didConnectedDragSourceChange() {
          return this.lastConnectedDragSource !== this.dragSource;
      }
      didConnectedDragPreviewChange() {
          return this.lastConnectedDragPreview !== this.dragPreview;
      }
      didDragSourceOptionsChange() {
          return !shallowEqual(this.lastConnectedDragSourceOptions, this.dragSourceOptions);
      }
      didDragPreviewOptionsChange() {
          return !shallowEqual(this.lastConnectedDragPreviewOptions, this.dragPreviewOptions);
      }
      disconnectDragSource() {
          if (this.dragSourceUnsubscribe) {
              this.dragSourceUnsubscribe();
              this.dragSourceUnsubscribe = undefined;
          }
      }
      disconnectDragPreview() {
          if (this.dragPreviewUnsubscribe) {
              this.dragPreviewUnsubscribe();
              this.dragPreviewUnsubscribe = undefined;
              this.dragPreviewNode = null;
              this.dragPreviewRef = null;
          }
      }
      get dragSource() {
          return this.dragSourceNode || this.dragSourceRef && this.dragSourceRef.current;
      }
      get dragPreview() {
          return this.dragPreviewNode || this.dragPreviewRef && this.dragPreviewRef.current;
      }
      clearDragSource() {
          this.dragSourceNode = null;
          this.dragSourceRef = null;
      }
      clearDragPreview() {
          this.dragPreviewNode = null;
          this.dragPreviewRef = null;
      }
      constructor(backend){
          this.hooks = wrapConnectorHooks({
              dragSource: (node, options)=>{
                  this.clearDragSource();
                  this.dragSourceOptions = options || null;
                  if (isRef(node)) {
                      this.dragSourceRef = node;
                  } else {
                      this.dragSourceNode = node;
                  }
                  this.reconnectDragSource();
              },
              dragPreview: (node, options)=>{
                  this.clearDragPreview();
                  this.dragPreviewOptions = options || null;
                  if (isRef(node)) {
                      this.dragPreviewRef = node;
                  } else {
                      this.dragPreviewNode = node;
                  }
                  this.reconnectDragPreview();
              }
          });
          this.handlerId = null;
          // The drop target may either be attached via ref or connect function
          this.dragSourceRef = null;
          this.dragSourceOptionsInternal = null;
          // The drag preview may either be attached via ref or connect function
          this.dragPreviewRef = null;
          this.dragPreviewOptionsInternal = null;
          this.lastConnectedHandlerId = null;
          this.lastConnectedDragSource = null;
          this.lastConnectedDragSourceOptions = null;
          this.lastConnectedDragPreview = null;
          this.lastConnectedDragPreviewOptions = null;
          this.backend = backend;
      }
  }
  
  //# sourceMappingURL=SourceConnector.js.map