easy-file-system 1.5.15 → 1.5.16

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.
@@ -3,6 +3,7 @@
3
3
  import withStyle from "easy-with-style"; ///
4
4
 
5
5
  import { dragMixins } from "easy-drag-and-drop";
6
+ import { pathUtilities } from "necessary";
6
7
 
7
8
  import EntryItem from "../../item/entry";
8
9
  import NameInput from "../../input/name";
@@ -10,6 +11,8 @@ import NameButton from "../../button/name";
10
11
 
11
12
  import { adjustSourceEntryPath, adjustTargetEntryPath } from "../../utilities/pathMap";
12
13
 
14
+ const { concatenatePaths, pathWithoutBottommostNameFromPath } = pathUtilities;
15
+
13
16
  class DragEntryItem extends EntryItem {
14
17
  svgButtonClickHandler = (event, element) => {
15
18
  const explorer = this.getExplorer(),
@@ -20,13 +23,22 @@ class DragEntryItem extends EntryItem {
20
23
  event.stopPropagation();
21
24
  }
22
25
 
23
- nameChangeHandler = (name) => {
24
- const path = this.getPath(),
26
+ nameChangeHandler = () => {
27
+ const nameChanged = this.hasNameChanged();
28
+
29
+ if (!nameChanged) {
30
+ this.cancel();
31
+
32
+ return;
33
+ }
34
+
35
+ const oldPath = this.getOldPath(),
36
+ newPath = this.getNewPath(),
25
37
  explorer = this.getExplorer();
26
38
 
27
- explorer.callPathChangeHandlersAsync(path, (success) => {
39
+ explorer.callPathChangeHandlersAsync(oldPath, newPath, (success) => {
28
40
  success ?
29
- this.update(name) :
41
+ this.update() :
30
42
  this.cancel();
31
43
  });
32
44
  }
@@ -68,20 +80,47 @@ class DragEntryItem extends EntryItem {
68
80
  markerEntryItemExplorer.dropDragEntryItem(dragEntryItem, done);
69
81
  }
70
82
 
71
- retrieveMarkerEntryItem() {
72
- const { markerEntryItem } = globalThis;
83
+ getName() {
84
+ const nameButtonName = this.getNameButtonName(),
85
+ name = nameButtonName; ///
73
86
 
74
- return markerEntryItem;
87
+ return name;
75
88
  }
76
89
 
77
- getPathMaps(sourceEntryPath, targetEntryPath) {
78
- let pathMaps = [];
90
+ getOldName() {
91
+ const nameButtonName = this.getNameButtonName(),
92
+ oldName = nameButtonName; ///
79
93
 
80
- this.retrievePathMaps(sourceEntryPath, targetEntryPath, pathMaps);
94
+ return oldName;
95
+ }
81
96
 
82
- pathMaps.reverse();
97
+ getNewName() {
98
+ const nameInputName = this.getNameInputName(),
99
+ oldName = nameInputName; ///
83
100
 
84
- return pathMaps;
101
+ return oldName;
102
+ }
103
+
104
+ getOldPath() {
105
+ const path = this.getPath(),
106
+ oldName = this.getOldName(),
107
+ pathWithoutBottommostName = pathWithoutBottommostNameFromPath(path),
108
+ oldPath = (pathWithoutBottommostName === null) ?
109
+ oldName :
110
+ concatenatePaths(pathWithoutBottommostName, oldName);
111
+
112
+ return oldPath;
113
+ }
114
+
115
+ getNewPath() {
116
+ const path = this.getPath(),
117
+ newName = this.getNewName(),
118
+ pathWithoutBottommostName = pathWithoutBottommostNameFromPath(path),
119
+ newPath = (pathWithoutBottommostName === null) ?
120
+ newName :
121
+ concatenatePaths(pathWithoutBottommostName, newName);
122
+
123
+ return newPath;
85
124
  }
86
125
 
87
126
  getPathMap(sourceEntryPath, targetEntryPath) {
@@ -98,6 +137,30 @@ class DragEntryItem extends EntryItem {
98
137
  return pathMap;
99
138
  }
100
139
 
140
+ getPathMaps(sourceEntryPath, targetEntryPath) {
141
+ let pathMaps = [];
142
+
143
+ this.retrievePathMaps(sourceEntryPath, targetEntryPath, pathMaps);
144
+
145
+ pathMaps.reverse();
146
+
147
+ return pathMaps;
148
+ }
149
+
150
+ hasNameChanged() {
151
+ const newName = this.getOldName(),
152
+ oldName = this.getNewName(),
153
+ nameChanged = (newName !== oldName);
154
+
155
+ return nameChanged;
156
+ }
157
+
158
+ retrieveMarkerEntryItem() {
159
+ const { markerEntryItem } = globalThis;
160
+
161
+ return markerEntryItem;
162
+ }
163
+
101
164
  isSelected() {
102
165
  const selected = this.hasClass("selected"); ///
103
166
 
@@ -127,13 +190,22 @@ class DragEntryItem extends EntryItem {
127
190
  this.hideNameInput();
128
191
  }
129
192
 
130
- update(name) {
131
- const nameButtonName = name; ///
193
+ update() {
194
+ const nameInputName = this.getNameInputName(),
195
+ nameButtonName = nameInputName; ///
132
196
 
133
197
  this.setNameButtonName(nameButtonName);
134
198
 
135
199
  this.showNameButton();
136
200
  this.hideNameInput();
201
+
202
+ const parentElement = this.getParentElement(),
203
+ entriesList = parentElement, ///
204
+ entryItem = this; ///
205
+
206
+ entriesList.removeEntryItem(entryItem);
207
+
208
+ entriesList.addEntryItem(entryItem);
137
209
  }
138
210
 
139
211
  didMount() {
@@ -99,7 +99,7 @@ function callMoveHandlersAsync(pathMaps, done) {
99
99
  }, done);
100
100
  }
101
101
 
102
- function callPathChangeHandlersAsync(path, callback) {
102
+ function callPathChangeHandlersAsync(oldPath, newPath, callback) {
103
103
  let notSuccess = false;
104
104
 
105
105
  const done = () => {
@@ -114,7 +114,7 @@ function callPathChangeHandlersAsync(path, callback) {
114
114
  const { handler, element } = eventListener,
115
115
  pathChangeHandler = handler; ///
116
116
 
117
- pathChangeHandler.call(element, path, (success) => {
117
+ pathChangeHandler.call(element, oldPath, newPath, (success) => {
118
118
  notSuccess = !success;
119
119
 
120
120
  next();