-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tag Insertion Dialog for unimplemented Tag Insertion (#267)
- Loading branch information
1 parent
c68cae4
commit 4c83885
Showing
17 changed files
with
308 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
import {TagTree, TagTrees, WarnedTag} from "./types"; | ||
import {TagTree, TagNodes, WarnedTag, RawTagSheet, TagRoot} from "./types"; | ||
|
||
interface ParserOptions { | ||
rows: WarnedTag[][]; | ||
fromRow: number; | ||
depth: number; | ||
trees: TagTrees; | ||
parent?: TagTree; | ||
nodes: TagNodes; | ||
parent: TagTree | TagRoot; | ||
} | ||
|
||
const parseRows = ({rows, fromRow, depth, trees, parent}: ParserOptions): number => { | ||
const parseRows = ({rows, fromRow, depth, nodes, parent}: ParserOptions): number => { | ||
let row = fromRow; | ||
while (row < rows.length) { | ||
const {tag, warning} = rows[row][depth] ?? {}; | ||
if (tag) { | ||
const node = {tag, parent, warning}; | ||
// Keys in the tag trees map are lowercase for ez lookup later | ||
trees.set(tag.toLowerCase(), node); | ||
row = parseRows({rows, fromRow: row + 1, depth: depth + 1, trees, parent: node}); | ||
const trimmedTag = tag.trim(); | ||
const node = {name: trimmedTag, parent, warning, children: [], height: parent.height - 1}; | ||
parent.children.push(node); | ||
// TODO if nodes already contains this tag, we need to emit a warning somehow!!! see #214 | ||
// Keys in the tag nodes map are lowercase for ez lookup later | ||
nodes.set(trimmedTag.toLowerCase(), node); | ||
row = parseRows({rows, fromRow: row + 1, depth: depth + 1, nodes, parent: node}); | ||
} else { | ||
break; | ||
} | ||
} | ||
return row; | ||
}; | ||
|
||
const parseTree = (rows: WarnedTag[][]) => { | ||
const trees: TagTrees = new Map(); | ||
for (let fromRow = 0; fromRow < rows.length; fromRow = parseRows({rows, fromRow, depth: 0, trees}) + 1); | ||
return trees; | ||
const parseTags = (sheets: RawTagSheet[]) => { | ||
const nodes: TagNodes = new Map(); | ||
const roots = sheets.map((sheet) => { | ||
const {values: rows, ...rest} = sheet; | ||
const parent: TagRoot = {...rest, children: []}; | ||
for (let fromRow = 0; fromRow < rows.length; fromRow = parseRows({rows, fromRow, depth: 0, nodes, parent}) + 1); | ||
return parent; | ||
}); | ||
return {nodes, roots}; | ||
}; | ||
|
||
export {parseTree}; | ||
export {parseTags}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import {Range} from "../sheets"; | ||
|
||
type TagMapper = `${string}$TAG${string}`; | ||
type TagSheetDescriptor = {range: Range; mapper: TagMapper; name: string; cwRange?: Range; height: number}; | ||
|
||
type RawTagSheet = TagSheetDescriptor & {values: WarnedTag[][]}; | ||
|
||
type TagRoot = TagSheetDescriptor & {children: TagTree[]}; | ||
|
||
/** | ||
* A tag tree contains the properly cased tag at the root, | ||
* and a pointer to its parent in the tree | ||
*/ | ||
type TagTree = {tag: string; parent?: TagTree; warning: boolean}; | ||
type TagTree = {name: string; parent: TagTree | TagRoot; warning: boolean; children: TagTree[]; height: number}; | ||
|
||
/** | ||
* TagTrees is a map of lowercase tag to the tag subtree at that tag | ||
* TagNodes is a map of lowercase tag to the tag subtree at that tag | ||
* It contains every subtree of the complete tag tree | ||
*/ | ||
type TagTrees = Map<string, TagTree>; | ||
type TagNodes = Map<string, TagTree>; | ||
|
||
type Tags = {nodes: TagNodes; roots: TagRoot[]}; | ||
|
||
interface TagSearchOptions { | ||
noCache: boolean; | ||
} | ||
|
||
type WarnedTag = {tag: string; warning: boolean}; | ||
|
||
export {WarnedTag, TagTree, TagTrees, TagSearchOptions}; | ||
export {WarnedTag, TagTree, TagRoot, TagNodes, TagSearchOptions, RawTagSheet, TagSheetDescriptor, TagMapper, Tags}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.