easy-file-system 1.5.24 → 1.5.26

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.
Files changed (42) hide show
  1. package/example.js +451 -365
  2. package/lib/button/name.js +5 -3
  3. package/lib/button/svg.js +27 -1
  4. package/lib/constants.js +9 -1
  5. package/lib/div/item/entry/directoryName.js +5 -13
  6. package/lib/div/item/entry/fileName.js +5 -13
  7. package/lib/eventTypes.js +17 -2
  8. package/lib/example/view/button.js +39 -0
  9. package/lib/example/view/explorer/first.js +2 -2
  10. package/lib/example/view.js +35 -14
  11. package/lib/explorer.js +73 -4
  12. package/lib/input/name.js +17 -38
  13. package/lib/item/entry/drag/directoryName.js +2 -12
  14. package/lib/item/entry/drag/fileName.js +2 -12
  15. package/lib/item/entry/drag.js +58 -23
  16. package/lib/list/entries.js +17 -15
  17. package/lib/mixins/explorer.js +22 -4
  18. package/lib/mixins/nameInput.js +52 -0
  19. package/lib/utilities/path.js +19 -0
  20. package/lib/utilities/pathMap.js +7 -8
  21. package/package.json +1 -1
  22. package/src/button/name.js +6 -2
  23. package/src/button/svg.js +10 -0
  24. package/src/constants.js +2 -0
  25. package/src/div/item/entry/directoryName.js +4 -10
  26. package/src/div/item/entry/fileName.js +4 -10
  27. package/src/eventTypes.js +7 -1
  28. package/src/example/view/button.js +14 -0
  29. package/src/example/view/explorer/first.js +2 -1
  30. package/src/example/view.js +44 -11
  31. package/src/explorer.js +89 -5
  32. package/src/input/name.js +27 -20
  33. package/src/item/entry/drag/directoryName.js +0 -9
  34. package/src/item/entry/drag/fileName.js +0 -9
  35. package/src/item/entry/drag.js +82 -32
  36. package/src/list/entries.js +17 -16
  37. package/src/mixins/explorer.js +38 -8
  38. package/src/mixins/nameInput.js +66 -0
  39. package/src/utilities/path.js +16 -0
  40. package/src/utilities/pathMap.js +10 -15
  41. package/lib/example/view/button/editSelected.js +0 -157
  42. package/src/example/view/button/editSelected.js +0 -23
package/src/constants.js CHANGED
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ export const NONE = "none";
4
+ export const PERIOD = ".";
3
5
  export const EMPTY_STRING = "";
4
6
  export const INLINE_BLOCK = "inline-block";
@@ -24,21 +24,18 @@ export default class DirectoryNameEntryItemDiv extends EntryItemDiv {
24
24
  }
25
25
 
26
26
  childElements() {
27
- const { name, NameInput, NameButton, ToggleButton, DirectoryNameSVG, onNameChange, onNameCancel, onSVGButtonClick } = this.properties,
28
- changeHandler = onNameChange, ///
29
- cancelHandler = onNameCancel, ///
30
- svgButtonClickHandler = onSVGButtonClick; ///
27
+ const { name, NameInput, NameButton, ToggleButton, DirectoryNameSVG } = this.properties;
31
28
 
32
29
  return ([
33
30
 
34
31
  <ToggleButton onMouseDown={this.toggleButtonMouseDownHandler} />,
35
- <SVGButton onClick={svgButtonClickHandler} >
32
+ <SVGButton>
36
33
  <DirectoryNameSVG/>
37
34
  </SVGButton>,
38
35
  <NameButton onDoubleClick={this.nameButtonDoubleClickHandler} >
39
36
  {name}
40
37
  </NameButton>,
41
- <NameInput onChange={changeHandler} onCancel={cancelHandler} >
38
+ <NameInput>
42
39
  {name}
43
40
  </NameInput>,
44
41
  <BackgroundDiv/>
@@ -51,10 +48,7 @@ export default class DirectoryNameEntryItemDiv extends EntryItemDiv {
51
48
  "NameInput",
52
49
  "NameButton",
53
50
  "ToggleButton",
54
- "DirectoryNameSVG",
55
- "onNameChange",
56
- "onNameCancel",
57
- "onSVGButtonClick"
51
+ "DirectoryNameSVG"
58
52
  ];
59
53
 
60
54
  static defaultProperties = {
@@ -16,20 +16,17 @@ export default class FileNameEntryItemDiv extends EntryItemDiv {
16
16
  }
17
17
 
18
18
  childElements() {
19
- const { name, NameInput, NameButton, FileNameSVG, onNameChange, onNameCancel, onSVGButtonClick } = this.properties,
20
- changeHandler = onNameChange, ///
21
- cancelHandler = onNameCancel, ///
22
- svgButtonClickHandler = onSVGButtonClick; ///
19
+ const { name, NameInput, NameButton, FileNameSVG } = this.properties;
23
20
 
24
21
  return ([
25
22
 
26
- <SVGButton onClick={svgButtonClickHandler} >
23
+ <SVGButton>
27
24
  <FileNameSVG/>
28
25
  </SVGButton>,
29
26
  <NameButton onDoubleClick={this.nameButtonDoubleClickHandler} >
30
27
  {name}
31
28
  </NameButton>,
32
- <NameInput onChange={changeHandler} onCancel={cancelHandler} >
29
+ <NameInput>
33
30
  {name}
34
31
  </NameInput>,
35
32
  <BackgroundDiv/>
@@ -41,10 +38,7 @@ export default class FileNameEntryItemDiv extends EntryItemDiv {
41
38
  "name",
42
39
  "NameInput",
43
40
  "NameButton",
44
- "FileNameSVG",
45
- "onNameChange",
46
- "onNameCancel",
47
- "onSVGButtonClick"
41
+ "FileNameSVG"
48
42
  ];
49
43
 
50
44
  static defaultProperties = {
package/src/eventTypes.js CHANGED
@@ -2,14 +2,20 @@
2
2
 
3
3
  export const OPEN_EVENT_TYPE = "open";
4
4
  export const MOVE_EVENT_TYPE = "move";
5
+ export const CHANGE_EVENT_TYPE = "change";
6
+ export const CANCEL_EVENT_TYPE = "cancel";
5
7
  export const RENAME_EVENT_TYPE = "rename";
6
8
  export const REMOVE_EVENT_TYPE = "remove";
7
9
  export const SELECT_EVENT_TYPE = "select";
10
+ export const CREATE_EVENT_TYPE = "create";
8
11
 
9
12
  export default {
10
13
  OPEN_EVENT_TYPE,
11
14
  MOVE_EVENT_TYPE,
15
+ CHANGE_EVENT_TYPE,
16
+ CANCEL_EVENT_TYPE,
12
17
  RENAME_EVENT_TYPE,
13
18
  REMOVE_EVENT_TYPE,
14
- SELECT_EVENT_TYPE
19
+ SELECT_EVENT_TYPE,
20
+ CREATE_EVENT_TYPE
15
21
  };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ import withStyle from "easy-with-style"; ///
4
+
5
+ import { Button } from "easy";
6
+
7
+ export default withStyle(Button)`
8
+
9
+ border: 1px solid black;
10
+ cursor: pointer;
11
+ padding: 1rem;
12
+ margin-left: 1rem;
13
+
14
+ `;
@@ -8,7 +8,8 @@ export default class FirstExplorer extends Explorer {
8
8
 
9
9
  this.addFilePath("directory1/file1.txt");
10
10
  this.addFilePath("directory1/file2.txt");
11
- this.addFilePath("directory1/file3.txt");
11
+
12
+ this.addDirectoryPath("directory1/directory3");
12
13
  }
13
14
 
14
15
  static defaultProperties = {
@@ -3,21 +3,30 @@
3
3
  import { Element } from "easy";
4
4
  import { arrayUtilities } from "necessary";
5
5
 
6
+ import Button from "./view/button";
6
7
  import RubbishBin from "./view/rubbishBin";
7
8
  import FirstExplorer from "./view/explorer/first";
8
9
  import SecondExplorer from "./view/explorer/second";
9
- import EditSelectedButton from "./view/button/editSelected";
10
10
 
11
11
  const { first, second } = arrayUtilities;
12
12
 
13
13
  export default class View extends Element {
14
- clickHandler = (event, element) => {
15
- const firstExplorer = this.getFirstExplorer(),
16
- secondExplorer = this.getSecondExplorer();
14
+ createFilePathButtonClickHandler = (event, element) => {
15
+ const firstExplorer = this.getFirstExplorer();
17
16
 
18
- firstExplorer.editSelectedPath();
17
+ firstExplorer.createFilePath();
18
+ }
19
+
20
+ createDirectoryPathButtonClickHandler = (event, element) => {
21
+ const Explorer = this.getFirstExplorer();
22
+
23
+ Explorer.createDirectoryPath();
24
+ }
25
+
26
+ editSelectedPathButtonClickHandler = (event, element) => {
27
+ const firstExplorer = this.getFirstExplorer();
19
28
 
20
- secondExplorer.editSelectedPath();
29
+ firstExplorer.editSelectedPath();
21
30
  }
22
31
 
23
32
  openHandler = (filePath) => {
@@ -30,14 +39,20 @@ export default class View extends Element {
30
39
  done();
31
40
  }
32
41
 
42
+ removeHandler = (pathMaps, done) => {
43
+ console.log("remove", JSON.stringify(pathMaps, null, " "))
44
+
45
+ done();
46
+ }
47
+
33
48
  renameHandler = (pathMaps, done) => {
34
49
  console.log("rename", JSON.stringify(pathMaps, null, " "))
35
50
 
36
51
  done();
37
52
  }
38
53
 
39
- removeHandler = (pathMaps, done) => {
40
- console.log("remove", JSON.stringify(pathMaps, null, " "))
54
+ createHandler = (pathMaps, done) => {
55
+ console.log("create", JSON.stringify(pathMaps, null, " "))
41
56
 
42
57
  done();
43
58
  }
@@ -67,9 +82,27 @@ export default class View extends Element {
67
82
  return ([
68
83
 
69
84
  <RubbishBin onRemove={this.removeHandler} />,
70
- <FirstExplorer onMove={this.moveHandler} onOpen={this.openHandler} onRename={this.renameHandler} />,
71
- <SecondExplorer onMove={this.moveHandler} onOpen={this.openHandler} onRename={this.renameHandler} />,
72
- <EditSelectedButton onClick={this.clickHandler} />
85
+ <FirstExplorer onOpen={this.openHandler}
86
+ onMove={this.moveHandler}
87
+ onRemove={this.removeHandler}
88
+ onRename={this.renameHandler}
89
+ onCreate={this.createHandler}
90
+ />,
91
+ <SecondExplorer onOpen={this.openHandler}
92
+ onMove={this.moveHandler}
93
+ onRemove={this.removeHandler}
94
+ onRename={this.renameHandler}
95
+ onCreate={this.createHandler}
96
+ />,
97
+ <Button onClick={this.createFilePathButtonClickHandler}>
98
+ Create file path
99
+ </Button>,
100
+ <Button onClick={this.createDirectoryPathButtonClickHandler}>
101
+ Create directory path
102
+ </Button>,
103
+ <Button onClick={this.editSelectedPathButtonClickHandler}>
104
+ Edit selected path
105
+ </Button>
73
106
 
74
107
  ]);
75
108
  }
package/src/explorer.js CHANGED
@@ -4,6 +4,7 @@ import withStyle from "easy-with-style"; ///
4
4
 
5
5
  import { Element } from "easy";
6
6
  import { dropMixins } from "easy-drag-and-drop";
7
+ import { pathUtilities } from "necessary";
7
8
 
8
9
  import EntriesList from "./list/entries";
9
10
  import DragEntryItem from "./item/entry/drag";
@@ -13,11 +14,15 @@ import FileNameMarkerEntryItem from "./item/entry/marker/fileName";
13
14
  import DirectoryNameDragEntryItem from "./item/entry/drag/directoryName";
14
15
  import DirectoryNameMarkerEntryItem from "./item/entry/marker/directoryName";
15
16
 
17
+ import { PERIOD } from "./constants";
16
18
  import { explorerPadding } from "./styles";
17
19
  import { DELETE_KEY_CODE, BACKSPACE_KEY_CODE } from "./keyCodes";
20
+ import { nonNullPathWithoutBottommostNameFromPath } from "./utilities/path";
18
21
  import { FILE_NAME_DRAG_ENTRY_TYPE, DIRECTORY_NAME_DRAG_ENTRY_TYPE } from "./entryTypes";
19
22
  import { sourceEntryPathFromEntryItem, targetEntryPathFromEntryItem } from "./utilities/pathMap";
20
23
 
24
+ const { concatenatePaths } = pathUtilities;
25
+
21
26
  class Explorer extends Element {
22
27
  constructor(selector, mounted) {
23
28
  super(selector);
@@ -98,7 +103,13 @@ class Explorer extends Element {
98
103
 
99
104
  if (selectedDragEntryItem !== null) {
100
105
  const dragEntryItem = selectedDragEntryItem, ///
101
- sourceEntryPath = sourceEntryPathFromEntryItem(dragEntryItem),
106
+ dragEntryItemEdited = dragEntryItem.isEdited();
107
+
108
+ if (dragEntryItemEdited) {
109
+ return;
110
+ }
111
+
112
+ const sourceEntryPath = sourceEntryPathFromEntryItem(dragEntryItem),
102
113
  targetEntryPath = null,
103
114
  pathMaps = dragEntryItem.getPathMaps(sourceEntryPath, targetEntryPath),
104
115
  explorer = this; ///
@@ -106,6 +117,8 @@ class Explorer extends Element {
106
117
  this.removeDragEntryItems(pathMaps, explorer, () => {
107
118
  ///
108
119
  });
120
+
121
+ event.preventDefault();
109
122
  }
110
123
  }
111
124
  }
@@ -216,6 +229,57 @@ class Explorer extends Element {
216
229
  this.callOpenHandlers(filePath);
217
230
  }
218
231
 
232
+ createPath() {
233
+ let path;
234
+
235
+ const name = PERIOD, ///
236
+ selectedDragEntryItem = this.retrieveSelectedDragEntryItem();
237
+
238
+ if (selectedDragEntryItem === null) {
239
+ path = name; ///
240
+ } else {
241
+ const selectedDragEntryItemDirectoryDragEntryItem = selectedDragEntryItem.isDirectoryNameDragEntryItem();
242
+
243
+ if (selectedDragEntryItemDirectoryDragEntryItem) {
244
+ const directoryNameDragEntryItem = selectedDragEntryItem, ///
245
+ directoryNameDragEntryItemPath = directoryNameDragEntryItem.getPath();
246
+
247
+ path = concatenatePaths(directoryNameDragEntryItemPath, name);
248
+ } else {
249
+ const fileDragEntryItem = selectedDragEntryItem, ///
250
+ fileDragEntryItemPath = fileDragEntryItem.getPath(), ///
251
+ fileDragEntryItemPathWithoutBottommostName = nonNullPathWithoutBottommostNameFromPath(fileDragEntryItemPath);
252
+
253
+ path = concatenatePaths(fileDragEntryItemPathWithoutBottommostName, name);
254
+ }
255
+ }
256
+
257
+ return path;
258
+ }
259
+
260
+ createFilePath() {
261
+ const path = this.createPath(),
262
+ created = true,
263
+ filePath = path, ///
264
+ fileNameDragEntryItem = this.addFilePath(filePath, created);
265
+
266
+ this.selectDragEntryItem(fileNameDragEntryItem);
267
+
268
+ this.editSelectedPath();
269
+ }
270
+
271
+ createDirectoryPath() {
272
+ const path = this.createPath(),
273
+ created = true,
274
+ collapsed = false,
275
+ directoryPath = path, ///
276
+ directoryNameDragEntryItem = this.addDirectoryPath(directoryPath, collapsed, created);
277
+
278
+ this.selectDragEntryItem(directoryNameDragEntryItem);
279
+
280
+ this.editSelectedPath();
281
+ }
282
+
219
283
  editSelectedPath() {
220
284
  const selectedDragEntryItem = this.retrieveSelectedDragEntryItem();
221
285
 
@@ -243,17 +307,27 @@ class Explorer extends Element {
243
307
  }
244
308
 
245
309
  renameDragEntryItem(dragEntryItem, done) {
246
- const dragEntryItemExplorer = dragEntryItem.getExplorer(),
247
- sourceEntryPath = sourceEntryPathFromEntryItem(dragEntryItem),
310
+ const sourceEntryPath = sourceEntryPathFromEntryItem(dragEntryItem),
248
311
  targetEntryPath = targetEntryPathFromEntryItem(dragEntryItem),
249
312
  pathMaps = dragEntryItem.getPathMaps(sourceEntryPath, targetEntryPath),
250
- explorer = dragEntryItemExplorer; ///
313
+ explorer = this; ///
251
314
 
252
315
  this.renameDragEntryItems(pathMaps, explorer, () => {
253
316
  done();
254
317
  });
255
318
  }
256
319
 
320
+ createDragEntryItem(dragEntryItem, done) {
321
+ const sourceEntryPath = sourceEntryPathFromEntryItem(dragEntryItem),
322
+ targetEntryPath = targetEntryPathFromEntryItem(dragEntryItem),
323
+ pathMaps = dragEntryItem.getPathMaps(sourceEntryPath, targetEntryPath),
324
+ explorer = this; ///
325
+
326
+ this.createDragEntryItems(pathMaps, explorer, () => {
327
+ done();
328
+ });
329
+ }
330
+
257
331
  dropDragEntryItem(dragEntryItem, done) {
258
332
  const markerEntryItem = this.retrieveMarkerEntryItem(),
259
333
  dragEntryItemExplorer = dragEntryItem.getExplorer(),
@@ -297,6 +371,16 @@ class Explorer extends Element {
297
371
  });
298
372
  }
299
373
 
374
+ createDragEntryItems(pathMaps, explorer, done) {
375
+ this.callCreateHandlersAsync(pathMaps, () => {
376
+ pathMaps.forEach((pathMap) => this.removeDragEntryItem(pathMap, explorer));
377
+
378
+ pathMaps.forEach((pathMap) => this.addDragEntryItem(pathMap, explorer));
379
+
380
+ done();
381
+ });
382
+ }
383
+
300
384
  removeDragEntryItem(pathMap, explorer) {
301
385
  const { entryDirectory } = pathMap;
302
386
 
@@ -418,7 +502,7 @@ class Explorer extends Element {
418
502
  }
419
503
 
420
504
  childElements() {
421
- const explorer = this;
505
+ const explorer = this; ///
422
506
 
423
507
  return (
424
508
 
package/src/input/name.js CHANGED
@@ -4,7 +4,9 @@ import withStyle from "easy-with-style"; ///
4
4
 
5
5
  import { arrayUtilities } from "necessary";
6
6
 
7
- import { INLINE_BLOCK } from "../constants";
7
+ import nameInputMixins from "../mixins/nameInput";
8
+
9
+ import { NONE, INLINE_BLOCK } from "../constants";
8
10
  import { Element, window, document } from "easy";
9
11
  import { ENTER_KEY_CODE, ESCAPE_KEY_CODE } from "../keyCodes";
10
12
 
@@ -15,19 +17,13 @@ class NameInput extends Element {
15
17
  const { keyCode } = event;
16
18
 
17
19
  if (keyCode === ENTER_KEY_CODE) {
18
- const { onChange } = this.properties,
19
- changeHandler = onChange; ///
20
-
21
- changeHandler();
20
+ this.callChangeHandlers();
22
21
 
23
22
  event.preventDefault();
24
23
  }
25
24
 
26
25
  if (keyCode === ESCAPE_KEY_CODE) {
27
- const { onCancel } = this.properties,
28
- cancelHandler = onCancel; ///
29
-
30
- cancelHandler();
26
+ this.callCancelHandlers();
31
27
 
32
28
  event.preventDefault();
33
29
  }
@@ -41,9 +37,12 @@ class NameInput extends Element {
41
37
  }
42
38
 
43
39
  setName(name) {
44
- const html = name; ///
40
+ const domElement = this.getDOMElement(),
41
+ { childNodes } = domElement,
42
+ firstChildNode = first(childNodes),
43
+ textNode = firstChildNode; ///
45
44
 
46
- this.html(html);
45
+ textNode.nodeValue = name; ///
47
46
  }
48
47
 
49
48
  show() {
@@ -72,7 +71,9 @@ class NameInput extends Element {
72
71
  }
73
72
 
74
73
  hide() {
75
- super.hide();
74
+ const display = NONE;
75
+
76
+ this.display(display);
76
77
  }
77
78
 
78
79
  didMount() {
@@ -87,23 +88,28 @@ class NameInput extends Element {
87
88
  const showNameInput = this.show.bind(this), ///
88
89
  hideNameInput = this.hide.bind(this), ///
89
90
  getNameInputName = this.getName.bind(this), ///
90
- setNameInputName = this.setName.bind(this); ///
91
+ setNameInputName = this.setName.bind(this), ///
92
+ onNameInputChange = this.onChange.bind(this), ///
93
+ onNameInputCancel = this.onCancel.bind(this), ///
94
+ offNameInputChange = this.offChange.bind(this), ///
95
+ offNameInputCancel = this.offCancel.bind(this), ///
96
+ isNameInputDisplayed = this.isDisplayed.bind(this); ///
91
97
 
92
98
  return ({
93
99
  showNameInput,
94
100
  hideNameInput,
95
101
  getNameInputName,
96
- setNameInputName
102
+ setNameInputName,
103
+ onNameInputChange,
104
+ onNameInputCancel,
105
+ offNameInputChange,
106
+ offNameInputCancel,
107
+ isNameInputDisplayed
97
108
  });
98
109
  }
99
110
 
100
111
  static tagName = "span"; ///
101
112
 
102
- static ignoredProperties = [
103
- "onChange",
104
- "onCancel"
105
- ];
106
-
107
113
  static defaultProperties = {
108
114
  role: "textbox",
109
115
  className: "name",
@@ -111,10 +117,11 @@ class NameInput extends Element {
111
117
  };
112
118
  }
113
119
 
120
+ Object.assign(NameInput.prototype, nameInputMixins);
121
+
114
122
  export default withStyle(NameInput)`
115
123
 
116
124
  outline: none;
117
- display: inline-block;
118
125
  font-size: inherit;
119
126
  text-align: left;
120
127
  font-weight: inherit;
@@ -114,12 +114,6 @@ export default class DirectoryNameDragEntryItem extends DragEntryItem {
114
114
  return collapsed;
115
115
  }
116
116
 
117
- isEntryDirectory() {
118
- const entryDirectory = true;
119
-
120
- return entryDirectory;
121
- }
122
-
123
117
  retrievePathMaps(sourceEntryPath, targetEntryPath, pathMaps) {
124
118
  const name = this.getName(),
125
119
  pathMap = this.getPathMap(sourceEntryPath, targetEntryPath),
@@ -198,9 +192,6 @@ export default class DirectoryNameDragEntryItem extends DragEntryItem {
198
192
  NameButton={NameButton}
199
193
  ToggleButton={ToggleButton}
200
194
  DirectoryNameSVG={DirectoryNameSVG}
201
- onNameChange={this.nameChangeHandler}
202
- onNameCancel={this.nameCancelHandler}
203
- onSVGButtonClick={this.svgButtonClickHandler}
204
195
  />,
205
196
  <EntriesList explorer={explorer} />
206
197
 
@@ -46,12 +46,6 @@ export default class FileNameDragEntryItem extends DragEntryItem {
46
46
  return collapsed;
47
47
  }
48
48
 
49
- isEntryDirectory() {
50
- const entryDirectory = false;
51
-
52
- return entryDirectory;
53
- }
54
-
55
49
  retrievePathMaps(sourceEntryPath, targetEntryPath, pathMaps) {
56
50
  const pathMap = this.getPathMap(sourceEntryPath, targetEntryPath);
57
51
 
@@ -70,9 +64,6 @@ export default class FileNameDragEntryItem extends DragEntryItem {
70
64
  NameInput={NameInput}
71
65
  NameButton={NameButton}
72
66
  FileNameSVG={FileNameSVG}
73
- onNameChange={this.nameChangeHandler}
74
- onNameCancel={this.nameCancelHandler}
75
- onSVGButtonClick={this.svgButtonClickHandler}
76
67
  />
77
68
  );
78
69
  }