Skip to content

Commit 9d2c4e4

Browse files
committed
feature: client: dom: cmd: move out
1 parent 5a2aa70 commit 9d2c4e4

2 files changed

Lines changed: 89 additions & 77 deletions

File tree

client/dom/cmd.mjs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* global DOM */
2+
3+
const SELECTED_FILE = 'selected-file';
4+
const Cmd = {
5+
getSelectedFiles,
6+
isSelected,
7+
unselectFile,
8+
selectFile,
9+
selectAllFiles,
10+
toggleSelectedFile,
11+
toggleAllSelectedFiles,
12+
};
13+
14+
/**
15+
* selected file check
16+
*
17+
* @param currentFile
18+
*/
19+
export function isSelected(currentFile) {
20+
if (!currentFile)
21+
return false;
22+
23+
return DOM.isContainClass(currentFile, SELECTED_FILE);
24+
}
25+
26+
/**
27+
* select current file
28+
* @param currentFile
29+
*/
30+
export function selectFile(currentFile) {
31+
const current = currentFile || DOM.getCurrentFile();
32+
33+
current.classList.add(SELECTED_FILE);
34+
35+
return Cmd;
36+
}
37+
38+
export function unselectFile(currentFile) {
39+
const current = currentFile || DOM.getCurrentFile();
40+
41+
current.classList.remove(SELECTED_FILE);
42+
43+
return Cmd;
44+
}
45+
46+
export function toggleSelectedFile(currentFile) {
47+
const current = currentFile || DOM.getCurrentFile();
48+
const name = DOM.getCurrentName(current);
49+
50+
if (name === '..')
51+
return Cmd;
52+
53+
current.classList.toggle(SELECTED_FILE);
54+
55+
return Cmd;
56+
}
57+
58+
export function toggleAllSelectedFiles() {
59+
DOM
60+
.getAllFiles()
61+
.map(DOM.toggleSelectedFile);
62+
63+
return Cmd;
64+
}
65+
66+
export function selectAllFiles() {
67+
DOM
68+
.getAllFiles()
69+
.map(DOM.selectFile);
70+
71+
return Cmd;
72+
}
73+
74+
/**
75+
* unified way to get selected files
76+
*
77+
* @currentFile
78+
*/
79+
export function getSelectedFiles() {
80+
const panel = DOM.getPanel();
81+
const selected = DOM.getByClassAll(SELECTED_FILE, panel);
82+
83+
return Array.from(selected);
84+
}
85+

client/dom/index.js

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const renameCurrent = require('./operations/rename-current');
1111
const CurrentFile = require('./current-file.mjs');
1212
const DOMTree = require('./dom-tree.mjs');
1313

14-
const Cmd = module.exports;
14+
const Cmd = require('./cmd.mjs');
1515
const DOM = {
1616
...DOMTree,
1717
...CurrentFile,
@@ -47,7 +47,6 @@ DOM.Events = Events;
4747
const _loadRemote = require('./load-remote');
4848
const selectByPattern = require('./select-by-pattern');
4949
const isString = (a) => typeof a === 'string';
50-
const SELECTED_FILE = 'selected-file';
5150

5251
const TabPanel = {
5352
'js-left': null,
@@ -118,7 +117,7 @@ async function promptNew(typeName) {
118117
}
119118

120119
/**
121-
* get current direcotory name
120+
* get current directory name
122121
*/
123122
module.exports.getCurrentDirName = () => {
124123
const href = DOM
@@ -131,7 +130,7 @@ module.exports.getCurrentDirName = () => {
131130
};
132131

133132
/**
134-
* get current direcotory path
133+
* get current directory path
135134
*/
136135
module.exports.getParentDirPath = (panel) => {
137136
const path = DOM.getCurrentDirPath(panel);
@@ -145,7 +144,7 @@ module.exports.getParentDirPath = (panel) => {
145144
};
146145

147146
/**
148-
* get not current direcotory path
147+
* get not current directory path
149148
*/
150149
module.exports.getNotCurrentDirPath = () => {
151150
const panel = DOM.getPanel({
@@ -155,18 +154,6 @@ module.exports.getNotCurrentDirPath = () => {
155154
return DOM.getCurrentDirPath(panel);
156155
};
157156

158-
/**
159-
* unified way to get selected files
160-
*
161-
* @currentFile
162-
*/
163-
module.exports.getSelectedFiles = () => {
164-
const panel = DOM.getPanel();
165-
const selected = DOM.getByClassAll(SELECTED_FILE, panel);
166-
167-
return Array.from(selected);
168-
};
169-
170157
/*
171158
* unselect all files
172159
*/
@@ -340,54 +327,6 @@ module.exports.getRefreshButton = (panel = DOM.getPanel()) => {
340327
return DOM.getByDataName('js-refresh', panel);
341328
};
342329

343-
/**
344-
* select current file
345-
* @param currentFile
346-
*/
347-
module.exports.selectFile = (currentFile) => {
348-
const current = currentFile || DOM.getCurrentFile();
349-
350-
current.classList.add(SELECTED_FILE);
351-
352-
return Cmd;
353-
};
354-
355-
module.exports.unselectFile = (currentFile) => {
356-
const current = currentFile || DOM.getCurrentFile();
357-
358-
current.classList.remove(SELECTED_FILE);
359-
360-
return Cmd;
361-
};
362-
363-
module.exports.toggleSelectedFile = (currentFile) => {
364-
const current = currentFile || DOM.getCurrentFile();
365-
const name = DOM.getCurrentName(current);
366-
367-
if (name === '..')
368-
return Cmd;
369-
370-
current.classList.toggle(SELECTED_FILE);
371-
372-
return Cmd;
373-
};
374-
375-
module.exports.toggleAllSelectedFiles = () => {
376-
DOM
377-
.getAllFiles()
378-
.map(DOM.toggleSelectedFile);
379-
380-
return Cmd;
381-
};
382-
383-
module.exports.selectAllFiles = () => {
384-
DOM
385-
.getAllFiles()
386-
.map(DOM.selectFile);
387-
388-
return Cmd;
389-
};
390-
391330
module.exports.getAllFiles = () => {
392331
const panel = DOM.getPanel();
393332
const files = DOM.getFiles(panel);
@@ -436,18 +375,6 @@ module.exports.setHistory = (data, title, url) => {
436375
return ret;
437376
};
438377

439-
/**
440-
* selected file check
441-
*
442-
* @param currentFile
443-
*/
444-
module.exports.isSelected = (currentFile) => {
445-
if (!currentFile)
446-
return false;
447-
448-
return DOM.isContainClass(currentFile, SELECTED_FILE);
449-
};
450-
451378
/**
452379
* get link from current (or param) file
453380
*

0 commit comments

Comments
 (0)