-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetCopyToClipboardContents.ts
48 lines (43 loc) · 1.64 KB
/
getCopyToClipboardContents.ts
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
import generateMarkDownTree from "../generateMarkDownTree/generateMarkDownTree";
import { Core, FilterType } from "../../tree/types";
import { deepCopyFunction } from "../deepCopyFunction";
const NOT_DELETED = -1;
/** Will generate a treeCore recursively excluding the deletedones
* @param {Core[]} deepClonedTreeCore - Deep cloned tree Core including the deleted items
* @returns {Core[]} - Returns the tree Core without the deleted items
*/
export const generateTreeCore = (deepClonedTreeCore: Core[]): Core[] => {
const visibleCoresAsLines: Core[] = [];
deepClonedTreeCore.forEach((core) => {
if (core.deletedOrder === NOT_DELETED) {
if (core.treeCore) {
core.treeCore = generateTreeCore(core.treeCore);
}
visibleCoresAsLines.push(core);
}
});
return visibleCoresAsLines;
};
/** Will be the MarkDownTree without the deletedCore's (Any core with deletedOrder > -1)
* @param {Core[]} treeCore - the whole MarkDownTree
* @param {FilterType} filter - the type of the filter to generate the tree
* @param {boolean} isCollapsible - is it in collapsible format
* @returns {string} - the MarkDownTree without the deletedCore's
*/
export const getCopyToClipboardContents = (
treeCore: Core[],
filter: FilterType = FilterType.NULL,
isCollapsible: boolean = true
): string[] => {
const deepClonedTreeCore = deepCopyFunction(treeCore);
const visibleTreeCore: Core[] = generateTreeCore(deepClonedTreeCore);
const copyToClipboardContents = generateMarkDownTree(
visibleTreeCore,
filter,
false,
treeCore,
isCollapsible
);
return copyToClipboardContents;
};
export default getCopyToClipboardContents;