element-book 26.12.0 → 26.12.1
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.
- package/{src/data/book-entry/base-book-entry.ts → dist/data/book-entry/base-book-entry.d.ts} +2 -3
- package/dist/data/book-entry/base-book-entry.js +1 -0
- package/{src/data/book-entry/book-entry-type.ts → dist/data/book-entry/book-entry-type.d.ts} +5 -9
- package/dist/data/book-entry/book-entry-type.js +14 -0
- package/dist/data/book-entry/book-entry.d.ts +17 -0
- package/dist/data/book-entry/book-entry.js +9 -0
- package/dist/data/book-entry/book-page/book-page-controls.d.ts +92 -0
- package/dist/data/book-entry/book-page/book-page-controls.js +70 -0
- package/dist/data/book-entry/book-page/book-page.d.ts +63 -0
- package/dist/data/book-entry/book-page/book-page.js +2 -0
- package/dist/data/book-entry/book-page/controls-wrapper.d.ts +32 -0
- package/dist/data/book-entry/book-page/controls-wrapper.js +65 -0
- package/dist/data/book-entry/book-page/define-book-page.d.ts +58 -0
- package/dist/data/book-entry/book-page/define-book-page.js +52 -0
- package/dist/data/book-entry/book-root.d.ts +12 -0
- package/dist/data/book-entry/book-root.js +1 -0
- package/dist/data/book-entry/url-breadcrumbs.d.ts +23 -0
- package/{src/data/book-entry/url-breadcrumbs.ts → dist/data/book-entry/url-breadcrumbs.js} +8 -17
- package/dist/data/book-entry/verify-book-entry.d.ts +3 -0
- package/{src/data/book-entry/verify-book-entry.ts → dist/data/book-entry/verify-book-entry.js} +3 -9
- package/{src/data/book-tree/book-tree-node.ts → dist/data/book-tree/book-tree-node.d.ts} +9 -15
- package/dist/data/book-tree/book-tree-node.js +6 -0
- package/dist/data/book-tree/book-tree.d.ts +13 -0
- package/dist/data/book-tree/book-tree.js +136 -0
- package/dist/data/book-tree/search-nodes.d.ts +5 -0
- package/dist/data/book-tree/search-nodes.js +74 -0
- package/dist/data/book-tree/tree-cache.d.ts +4 -0
- package/dist/data/book-tree/tree-cache.js +8 -0
- package/dist/data/unset.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/routing/book-router.d.ts +4 -0
- package/{src/routing/book-router.ts → dist/routing/book-router.js} +12 -16
- package/{src/routing/book-routing.ts → dist/routing/book-routing.d.ts} +6 -21
- package/dist/routing/book-routing.js +33 -0
- package/dist/ui/color-theme/color-theme.d.ts +57 -0
- package/dist/ui/color-theme/color-theme.js +94 -0
- package/dist/ui/color-theme/create-color-theme.d.ts +32 -0
- package/dist/ui/color-theme/create-color-theme.js +93 -0
- package/dist/ui/elements/book-breadcrumbs.element.d.ts +6 -0
- package/dist/ui/elements/book-breadcrumbs.element.js +50 -0
- package/dist/ui/elements/book-nav/book-nav-filter.d.ts +2 -0
- package/dist/ui/elements/book-nav/book-nav-filter.js +15 -0
- package/dist/ui/elements/book-nav/book-nav.element.d.ts +8 -0
- package/{src/ui/elements/book-nav/book-nav.element.ts → dist/ui/elements/book-nav/book-nav.element.js} +44 -65
- package/dist/ui/elements/common/book-error.element.d.ts +3 -0
- package/{src/ui/elements/common/book-error.element.ts → dist/ui/elements/common/book-error.element.js} +8 -12
- package/dist/ui/elements/common/book-route-link.element.d.ts +6 -0
- package/dist/ui/elements/common/book-route-link.element.js +40 -0
- package/dist/ui/elements/define-book-element.d.ts +2 -0
- package/dist/ui/elements/define-book-element.js +2 -0
- package/{src/ui/elements/element-book-app/element-book-app-slots.ts → dist/ui/elements/element-book-app/element-book-app-slots.d.ts} +3 -3
- package/dist/ui/elements/element-book-app/element-book-app-slots.js +18 -0
- package/dist/ui/elements/element-book-app/element-book-app.element.d.ts +35 -0
- package/dist/ui/elements/element-book-app/element-book-app.element.js +301 -0
- package/dist/ui/elements/element-book-app/element-book-config.d.ts +48 -0
- package/dist/ui/elements/element-book-app/element-book-config.js +1 -0
- package/dist/ui/elements/element-book-app/get-current-nodes.d.ts +3 -0
- package/dist/ui/elements/element-book-app/get-current-nodes.js +18 -0
- package/dist/ui/elements/element-book-app/global-values.js +1 -0
- package/dist/ui/elements/entry-display/book-breadcrumbs-bar.element.d.ts +7 -0
- package/dist/ui/elements/entry-display/book-breadcrumbs-bar.element.js +60 -0
- package/dist/ui/elements/entry-display/book-entry-description.element.d.ts +4 -0
- package/{src/ui/elements/entry-display/book-entry-description.element.ts → dist/ui/elements/entry-display/book-entry-description.element.js} +7 -10
- package/dist/ui/elements/entry-display/book-page/book-page-controls.element.d.ts +17 -0
- package/dist/ui/elements/entry-display/book-page/book-page-controls.element.js +172 -0
- package/dist/ui/elements/entry-display/book-page/book-page-wrapper.element.d.ts +10 -0
- package/dist/ui/elements/entry-display/book-page/book-page-wrapper.element.js +86 -0
- package/dist/ui/elements/entry-display/element-example/book-element-example-controls.element.d.ts +7 -0
- package/dist/ui/elements/entry-display/element-example/book-element-example-controls.element.js +34 -0
- package/dist/ui/elements/entry-display/element-example/book-element-example-viewer.element.d.ts +7 -0
- package/dist/ui/elements/entry-display/element-example/book-element-example-viewer.element.js +61 -0
- package/dist/ui/elements/entry-display/element-example/book-element-example-wrapper.element.d.ts +9 -0
- package/dist/ui/elements/entry-display/element-example/book-element-example-wrapper.element.js +50 -0
- package/dist/ui/elements/entry-display/entry-display/book-entry-display.element.d.ts +18 -0
- package/{src/ui/elements/entry-display/entry-display/book-entry-display.element.ts → dist/ui/elements/entry-display/entry-display/book-entry-display.element.js} +27 -49
- package/dist/ui/elements/entry-display/entry-display/create-node-templates.d.ts +13 -0
- package/dist/ui/elements/entry-display/entry-display/create-node-templates.js +113 -0
- package/dist/ui/events/change-route.event.d.ts +1 -0
- package/dist/ui/events/change-route.event.js +2 -0
- package/dist/util/fuzzy-search.d.ts +34 -0
- package/{src/util/fuzzy-search.ts → dist/util/fuzzy-search.js} +5 -13
- package/{src/util/type.ts → dist/util/type.d.ts} +4 -3
- package/dist/util/type.js +1 -0
- package/package.json +5 -5
- package/src/data/book-entry/book-entry.ts +0 -23
- package/src/data/book-entry/book-page/book-page-controls.ts +0 -159
- package/src/data/book-entry/book-page/book-page.ts +0 -110
- package/src/data/book-entry/book-page/controls-wrapper.ts +0 -119
- package/src/data/book-entry/book-page/define-book-page.ts +0 -171
- package/src/data/book-entry/book-root.ts +0 -16
- package/src/data/book-tree/book-tree.ts +0 -225
- package/src/data/book-tree/search-nodes.ts +0 -104
- package/src/data/book-tree/tree-cache.ts +0 -13
- package/src/ui/color-theme/color-theme.ts +0 -152
- package/src/ui/color-theme/create-color-theme.ts +0 -139
- package/src/ui/elements/book-breadcrumbs.element.ts +0 -60
- package/src/ui/elements/book-nav/book-nav-filter.ts +0 -30
- package/src/ui/elements/common/book-route-link.element.ts +0 -48
- package/src/ui/elements/define-book-element.ts +0 -5
- package/src/ui/elements/element-book-app/element-book-app.element.ts +0 -380
- package/src/ui/elements/element-book-app/element-book-config.ts +0 -52
- package/src/ui/elements/element-book-app/get-current-nodes.ts +0 -35
- package/src/ui/elements/entry-display/book-breadcrumbs-bar.element.ts +0 -78
- package/src/ui/elements/entry-display/book-page/book-page-controls.element.ts +0 -219
- package/src/ui/elements/entry-display/book-page/book-page-wrapper.element.ts +0 -105
- package/src/ui/elements/entry-display/element-example/book-element-example-controls.element.ts +0 -42
- package/src/ui/elements/entry-display/element-example/book-element-example-viewer.element.ts +0 -79
- package/src/ui/elements/entry-display/element-example/book-element-example-wrapper.element.ts +0 -61
- package/src/ui/elements/entry-display/entry-display/create-node-templates.ts +0 -183
- package/src/ui/events/change-route.event.ts +0 -6
- /package/{src/data/unset.ts → dist/data/unset.js} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/ui/elements/element-book-app/global-values.ts → dist/ui/elements/element-book-app/global-values.d.ts} +0 -0
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {type Values} from '@augment-vir/common';
|
|
2
|
-
import {type AnyBookEntryType, type BookEntryType} from '../book-entry/book-entry-type.js';
|
|
3
|
-
import {type BookEntry} from '../book-entry/book-entry.js';
|
|
4
|
-
|
|
1
|
+
import { type Values } from '@augment-vir/common';
|
|
2
|
+
import { type AnyBookEntryType, type BookEntryType } from '../book-entry/book-entry-type.js';
|
|
3
|
+
import { type BookEntry } from '../book-entry/book-entry.js';
|
|
5
4
|
/**
|
|
6
5
|
* Property used to mark tree nodes.
|
|
7
6
|
*
|
|
8
7
|
* @category Internal
|
|
9
8
|
*/
|
|
10
|
-
export const isBookTreeNodeMarker =
|
|
11
|
-
|
|
9
|
+
export declare const isBookTreeNodeMarker = "_isBookTreeNode";
|
|
12
10
|
/**
|
|
13
11
|
* The base tree node type for {@link BookTreeNode}.
|
|
14
12
|
*
|
|
@@ -27,20 +25,16 @@ export type InternalBookTreeNodeType<Entry> = {
|
|
|
27
25
|
*/
|
|
28
26
|
manuallyAdded: boolean;
|
|
29
27
|
};
|
|
30
|
-
|
|
31
28
|
/**
|
|
32
29
|
* Any element-book tree node.
|
|
33
30
|
*
|
|
34
31
|
* @category Internal
|
|
35
32
|
*/
|
|
36
|
-
export type BookTreeNode<EntryTypes extends BookEntryType = AnyBookEntryType> =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}>
|
|
42
|
-
| (AnyBookEntryType extends EntryTypes ? InternalBookTreeNodeType<BookEntry> : never);
|
|
43
|
-
|
|
33
|
+
export type BookTreeNode<EntryTypes extends BookEntryType = AnyBookEntryType> = Values<{
|
|
34
|
+
[EntryType in EntryTypes]: InternalBookTreeNodeType<Extract<BookEntry, {
|
|
35
|
+
entryType: EntryType;
|
|
36
|
+
}>>;
|
|
37
|
+
}> | (AnyBookEntryType extends EntryTypes ? InternalBookTreeNodeType<BookEntry> : never);
|
|
44
38
|
/**
|
|
45
39
|
* The full element-book app tree for representing page structure.
|
|
46
40
|
*
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BookEntryType } from '../book-entry/book-entry-type.js';
|
|
2
|
+
import { type BookEntry } from '../book-entry/book-entry.js';
|
|
3
|
+
import { type BookTree, type BookTreeNode } from './book-tree-node.js';
|
|
4
|
+
export declare function doesNodeHaveEntryType<const EntryType extends BookEntryType>(node: unknown, entryType: EntryType): node is BookTreeNode<EntryType>;
|
|
5
|
+
export declare function isBookTreeNode<const SpecificType extends BookEntryType>(input: unknown, entryType: SpecificType): input is BookTreeNode<SpecificType>;
|
|
6
|
+
export declare function isAnyBookTreeNode(input: unknown): input is BookTreeNode<BookEntryType>;
|
|
7
|
+
export declare function createEmptyBookTreeRoot(): BookTreeNode<BookEntryType.Root>;
|
|
8
|
+
export declare function createBookTreeFromEntries({ entries, debug, }: {
|
|
9
|
+
entries: ReadonlyArray<BookEntry>;
|
|
10
|
+
debug: boolean;
|
|
11
|
+
}): BookTree;
|
|
12
|
+
export declare function traverseToImmediateParent(entryOrNode: Readonly<BookEntry> | BookTreeNode, currentTree: Readonly<BookTreeNode>): BookTreeNode | undefined;
|
|
13
|
+
export declare function flattenTree(node: Readonly<BookTreeNode>): BookTreeNode[];
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { BookEntryType } from '../book-entry/book-entry-type.js';
|
|
3
|
+
import { isBookEntry } from '../book-entry/book-entry.js';
|
|
4
|
+
import { listUrlBreadcrumbs, titleToUrlBreadcrumb } from '../book-entry/url-breadcrumbs.js';
|
|
5
|
+
import { bookEntryVerifiers } from '../book-entry/verify-book-entry.js';
|
|
6
|
+
import { isBookTreeNodeMarker } from './book-tree-node.js';
|
|
7
|
+
import { addTreeToCache, getTreeFromCache } from './tree-cache.js';
|
|
8
|
+
export function doesNodeHaveEntryType(node, entryType) {
|
|
9
|
+
return (check.hasKey(node, 'entry') &&
|
|
10
|
+
check.isObject(node.entry) &&
|
|
11
|
+
node.entry.entryType === entryType);
|
|
12
|
+
}
|
|
13
|
+
export function isBookTreeNode(input, entryType) {
|
|
14
|
+
return isAnyBookTreeNode(input) && input.entry.entryType === entryType;
|
|
15
|
+
}
|
|
16
|
+
export function isAnyBookTreeNode(input) {
|
|
17
|
+
return !!(check.hasKeys(input, [
|
|
18
|
+
isBookTreeNodeMarker,
|
|
19
|
+
'entry',
|
|
20
|
+
]) && input[isBookTreeNodeMarker]);
|
|
21
|
+
}
|
|
22
|
+
export function createEmptyBookTreeRoot() {
|
|
23
|
+
const rootNode = {
|
|
24
|
+
[isBookTreeNodeMarker]: true,
|
|
25
|
+
entry: {
|
|
26
|
+
entryType: BookEntryType.Root,
|
|
27
|
+
title: '',
|
|
28
|
+
parent: undefined,
|
|
29
|
+
errors: [],
|
|
30
|
+
descriptionParagraphs: [],
|
|
31
|
+
},
|
|
32
|
+
urlBreadcrumb: '',
|
|
33
|
+
fullUrlBreadcrumbs: [],
|
|
34
|
+
children: {},
|
|
35
|
+
manuallyAdded: true,
|
|
36
|
+
};
|
|
37
|
+
return rootNode;
|
|
38
|
+
}
|
|
39
|
+
export function createBookTreeFromEntries({ entries, debug, }) {
|
|
40
|
+
const cachedTree = getTreeFromCache(entries);
|
|
41
|
+
if (cachedTree) {
|
|
42
|
+
return cachedTree;
|
|
43
|
+
}
|
|
44
|
+
const tree = createEmptyBookTreeRoot();
|
|
45
|
+
entries.forEach((newEntry) => addEntryToTree({ tree, newEntry, debug, manuallyAdded: true }));
|
|
46
|
+
const flattenedNodes = flattenTree(tree);
|
|
47
|
+
const bookTree = {
|
|
48
|
+
tree,
|
|
49
|
+
flattenedNodes,
|
|
50
|
+
};
|
|
51
|
+
addTreeToCache(entries, bookTree);
|
|
52
|
+
if (debug) {
|
|
53
|
+
console.info('element-book tree:', tree);
|
|
54
|
+
}
|
|
55
|
+
return bookTree;
|
|
56
|
+
}
|
|
57
|
+
function getOrAddImmediateParent(tree, entry, debug) {
|
|
58
|
+
if (!entry.parent) {
|
|
59
|
+
return tree;
|
|
60
|
+
}
|
|
61
|
+
const immediateParent = traverseToImmediateParent(entry, tree);
|
|
62
|
+
if (immediateParent) {
|
|
63
|
+
return immediateParent;
|
|
64
|
+
}
|
|
65
|
+
if (debug) {
|
|
66
|
+
console.info(`parent of ${entry.title} not found in tree; adding it now.`);
|
|
67
|
+
}
|
|
68
|
+
addEntryToTree({ tree, newEntry: entry.parent, debug, manuallyAdded: false });
|
|
69
|
+
const immediateParentAfterAdding = traverseToImmediateParent(entry, tree);
|
|
70
|
+
if (!immediateParentAfterAdding) {
|
|
71
|
+
throw new Error(`Failed to find node despite having just added it: ${listUrlBreadcrumbs(entry, false).join(' > ')}`);
|
|
72
|
+
}
|
|
73
|
+
return immediateParentAfterAdding;
|
|
74
|
+
}
|
|
75
|
+
function addEntryToTree({ tree, newEntry, debug, manuallyAdded, }) {
|
|
76
|
+
const errors = bookEntryVerifiers[newEntry.entryType](newEntry);
|
|
77
|
+
newEntry.errors.push(...errors);
|
|
78
|
+
const immediateParent = getOrAddImmediateParent(tree, newEntry, debug);
|
|
79
|
+
const newEntryUrlBreadcrumb = titleToUrlBreadcrumb(newEntry.title);
|
|
80
|
+
const existingChild = immediateParent.children[newEntryUrlBreadcrumb];
|
|
81
|
+
if (existingChild) {
|
|
82
|
+
// ignores multiple entries that have been added by following parent chains
|
|
83
|
+
if (manuallyAdded) {
|
|
84
|
+
if (existingChild.manuallyAdded) {
|
|
85
|
+
existingChild.entry.errors.push(new Error(`Cannot create duplicate '${newEntryUrlBreadcrumb}'${immediateParent.urlBreadcrumb
|
|
86
|
+
? ` in parent '${immediateParent.urlBreadcrumb}'.`
|
|
87
|
+
: ''}`));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
existingChild.manuallyAdded = true;
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const newNode = {
|
|
95
|
+
[isBookTreeNodeMarker]: true,
|
|
96
|
+
children: {},
|
|
97
|
+
urlBreadcrumb: newEntryUrlBreadcrumb,
|
|
98
|
+
fullUrlBreadcrumbs: [
|
|
99
|
+
...immediateParent.fullUrlBreadcrumbs,
|
|
100
|
+
newEntryUrlBreadcrumb,
|
|
101
|
+
],
|
|
102
|
+
entry: newEntry,
|
|
103
|
+
manuallyAdded,
|
|
104
|
+
};
|
|
105
|
+
immediateParent.children[newEntryUrlBreadcrumb] = newNode;
|
|
106
|
+
if (isBookEntry(newEntry, BookEntryType.Page) &&
|
|
107
|
+
Object.values(newEntry.elementExamples).length) {
|
|
108
|
+
Object.values(newEntry.elementExamples).forEach((elementExample) => addEntryToTree({ tree, newEntry: elementExample, debug, manuallyAdded }));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function traverseToImmediateParent(entryOrNode, currentTree) {
|
|
112
|
+
const breadcrumbs = isAnyBookTreeNode(entryOrNode)
|
|
113
|
+
? entryOrNode.fullUrlBreadcrumbs.slice(0, -1)
|
|
114
|
+
: listUrlBreadcrumbs(entryOrNode, false);
|
|
115
|
+
if (!breadcrumbs.length) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
const immediateParentNode = breadcrumbs.reduce((currentAncestor, nextBreadcrumb) => {
|
|
119
|
+
if (!currentAncestor) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
return currentAncestor.children[nextBreadcrumb];
|
|
123
|
+
}, currentTree);
|
|
124
|
+
return immediateParentNode;
|
|
125
|
+
}
|
|
126
|
+
export function flattenTree(node) {
|
|
127
|
+
const hasErrors = !!node.entry.errors.length;
|
|
128
|
+
const childNodes = hasErrors
|
|
129
|
+
? []
|
|
130
|
+
: Object.values(node.children).map((child) => flattenTree(child));
|
|
131
|
+
const entries = [
|
|
132
|
+
node,
|
|
133
|
+
...childNodes,
|
|
134
|
+
].flat();
|
|
135
|
+
return entries;
|
|
136
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { randomString } from '@augment-vir/common';
|
|
3
|
+
import { convertTemplateToString } from 'element-vir';
|
|
4
|
+
import { fuzzySearch } from '../../util/fuzzy-search.js';
|
|
5
|
+
const searchJoin = randomString(32);
|
|
6
|
+
function createBreadcrumbsSearchKey(breadcrumbs) {
|
|
7
|
+
return breadcrumbs.join(searchJoin);
|
|
8
|
+
}
|
|
9
|
+
function getFullTreeKeysToInclude(breadcrumbs) {
|
|
10
|
+
if (!breadcrumbs.length) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const currentKey = createBreadcrumbsSearchKey(breadcrumbs);
|
|
14
|
+
const ancestorKeys = getFullTreeKeysToInclude(breadcrumbs.slice(0, -1));
|
|
15
|
+
return [
|
|
16
|
+
currentKey,
|
|
17
|
+
...ancestorKeys,
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
const errorQueries = [
|
|
21
|
+
'error',
|
|
22
|
+
'errors',
|
|
23
|
+
];
|
|
24
|
+
function isSearchingForErrors(searchQuery) {
|
|
25
|
+
return errorQueries.includes(searchQuery);
|
|
26
|
+
}
|
|
27
|
+
export function searchFlattenedNodes({ flattenedNodes, searchQuery, }) {
|
|
28
|
+
const includeInSearchResults = {};
|
|
29
|
+
function addChildren(treeNode) {
|
|
30
|
+
const childrenKeys = Object.values(treeNode.children).map((child) => {
|
|
31
|
+
addChildren(child);
|
|
32
|
+
return createBreadcrumbsSearchKey(child.fullUrlBreadcrumbs);
|
|
33
|
+
});
|
|
34
|
+
childrenKeys.forEach((keyToInclude) => (includeInSearchResults[keyToInclude] = true));
|
|
35
|
+
}
|
|
36
|
+
flattenedNodes.forEach((treeNode) => {
|
|
37
|
+
const matchesErrors = treeNode.entry.errors.length && isSearchingForErrors(searchQuery);
|
|
38
|
+
const currentNodeSearchKey = createBreadcrumbsSearchKey(treeNode.fullUrlBreadcrumbs);
|
|
39
|
+
const shouldInclude = fuzzySearch({
|
|
40
|
+
searchIn: [
|
|
41
|
+
treeNode.entry.title,
|
|
42
|
+
...treeNode.entry.descriptionParagraphs.map((paragraph) => {
|
|
43
|
+
if (check.isString(paragraph)) {
|
|
44
|
+
return paragraph;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return convertTemplateToString(paragraph);
|
|
48
|
+
}
|
|
49
|
+
}),
|
|
50
|
+
]
|
|
51
|
+
.join(' ')
|
|
52
|
+
.toLowerCase(),
|
|
53
|
+
searchQuery: searchQuery.toLowerCase(),
|
|
54
|
+
}) ||
|
|
55
|
+
matchesErrors ||
|
|
56
|
+
includeInSearchResults[currentNodeSearchKey];
|
|
57
|
+
if (shouldInclude) {
|
|
58
|
+
const keysToInclude = getFullTreeKeysToInclude(treeNode.fullUrlBreadcrumbs);
|
|
59
|
+
addChildren(treeNode);
|
|
60
|
+
keysToInclude.forEach((keyToInclude) => (includeInSearchResults[keyToInclude] = true));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
includeInSearchResults[currentNodeSearchKey] = false;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return flattenedNodes.filter((treeNode) => {
|
|
67
|
+
const inSearchResultsKey = createBreadcrumbsSearchKey(treeNode.fullUrlBreadcrumbs);
|
|
68
|
+
const shouldInclude = includeInSearchResults[inSearchResultsKey];
|
|
69
|
+
if (!check.isBoolean(shouldInclude)) {
|
|
70
|
+
throw new TypeError(`Failed to find '${treeNode.fullUrlBreadcrumbs.join(' > ')}' in includeInSearchResults.`);
|
|
71
|
+
}
|
|
72
|
+
return shouldInclude;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type BookEntry } from '../book-entry/book-entry.js';
|
|
2
|
+
import { type BookTree } from './book-tree-node.js';
|
|
3
|
+
export declare function getTreeFromCache(entries: ReadonlyArray<BookEntry>): BookTree | undefined;
|
|
4
|
+
export declare function addTreeToCache(entries: ReadonlyArray<BookEntry>, tree: BookTree): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getOrSetFromMap } from '@augment-vir/common';
|
|
2
|
+
const treeCache = new Map();
|
|
3
|
+
export function getTreeFromCache(entries) {
|
|
4
|
+
return treeCache.get(entries);
|
|
5
|
+
}
|
|
6
|
+
export function addTreeToCache(entries, tree) {
|
|
7
|
+
getOrSetFromMap(treeCache, entries, () => tree);
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const unsetInternalState: unique symbol;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './data/book-entry/base-book-entry.js';
|
|
2
|
+
export * from './data/book-entry/book-entry-type.js';
|
|
3
|
+
export * from './data/book-entry/book-entry.js';
|
|
4
|
+
export * from './data/book-entry/book-page/book-page-controls.js';
|
|
5
|
+
export * from './data/book-entry/book-page/book-page.js';
|
|
6
|
+
export * from './data/book-entry/book-page/controls-wrapper.js';
|
|
7
|
+
export * from './data/book-entry/book-page/define-book-page.js';
|
|
8
|
+
export * from './data/book-entry/book-root.js';
|
|
9
|
+
export * from './data/book-entry/url-breadcrumbs.js';
|
|
10
|
+
export * from './data/book-tree/book-tree-node.js';
|
|
11
|
+
export * from './routing/book-routing.js';
|
|
12
|
+
export * from './ui/color-theme/color-theme.js';
|
|
13
|
+
export * from './ui/color-theme/create-color-theme.js';
|
|
14
|
+
export * from './ui/elements/element-book-app/element-book-app-slots.js';
|
|
15
|
+
export * from './ui/elements/element-book-app/element-book-app.element.js';
|
|
16
|
+
export * from './ui/elements/element-book-app/element-book-config.js';
|
|
17
|
+
export * from './ui/elements/element-book-app/global-values.js';
|
|
18
|
+
export * from './util/type.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SpaRouter } from 'spa-router-vir';
|
|
2
|
+
import { type ValidBookPaths } from './book-routing.js';
|
|
3
|
+
export declare function createBookRouter(basePath: string | undefined): SpaRouter<ValidBookPaths, undefined, undefined>;
|
|
4
|
+
export type BookRouter = ReturnType<typeof createBookRouter>;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {check} from '@augment-vir/assert';
|
|
2
|
-
import {SpaRouter} from 'spa-router-vir';
|
|
3
|
-
import {BookMainRoute, defaultBookFullRoute
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return new SpaRouter<ValidBookPaths, undefined, undefined>({
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { SpaRouter } from 'spa-router-vir';
|
|
3
|
+
import { BookMainRoute, defaultBookFullRoute } from './book-routing.js';
|
|
4
|
+
export function createBookRouter(basePath) {
|
|
5
|
+
return new SpaRouter({
|
|
7
6
|
basePath,
|
|
8
7
|
sanitizeRoute(rawRoute) {
|
|
9
8
|
const sanitizedPaths = sanitizePaths(rawRoute.paths);
|
|
10
|
-
|
|
11
9
|
return {
|
|
12
10
|
paths: sanitizedPaths,
|
|
13
11
|
hash: undefined,
|
|
@@ -16,32 +14,30 @@ export function createBookRouter(basePath: string | undefined) {
|
|
|
16
14
|
},
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
export type BookRouter = ReturnType<typeof createBookRouter>;
|
|
21
|
-
|
|
22
|
-
function sanitizePaths(paths: ReadonlyArray<string>): ValidBookPaths {
|
|
17
|
+
function sanitizePaths(paths) {
|
|
23
18
|
const firstPath = paths[0];
|
|
24
|
-
|
|
25
19
|
if (!check.isEnumValue(firstPath, BookMainRoute)) {
|
|
26
20
|
return defaultBookFullRoute.paths;
|
|
27
|
-
}
|
|
21
|
+
}
|
|
22
|
+
else if (firstPath === BookMainRoute.Book) {
|
|
28
23
|
return [
|
|
29
24
|
BookMainRoute.Book,
|
|
30
25
|
...paths.slice(1),
|
|
31
26
|
];
|
|
32
|
-
}
|
|
27
|
+
}
|
|
28
|
+
else if (firstPath === BookMainRoute.Search) {
|
|
33
29
|
if (!paths[1]) {
|
|
34
30
|
return [
|
|
35
31
|
BookMainRoute.Book,
|
|
36
32
|
...paths.slice(1),
|
|
37
33
|
];
|
|
38
34
|
}
|
|
39
|
-
|
|
40
35
|
return [
|
|
41
36
|
firstPath,
|
|
42
37
|
paths[1],
|
|
43
38
|
];
|
|
44
|
-
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
45
41
|
throw new Error(`Route path not handled for sanitization: ${paths.join('/')}`);
|
|
46
42
|
}
|
|
47
43
|
}
|
|
@@ -1,49 +1,34 @@
|
|
|
1
|
-
import {type FullSpaRoute} from 'spa-router-vir';
|
|
2
|
-
|
|
1
|
+
import { type FullSpaRoute } from 'spa-router-vir';
|
|
3
2
|
/**
|
|
4
3
|
* Top level routes supported by the element-book app.
|
|
5
4
|
*
|
|
6
5
|
* @category Internal
|
|
7
6
|
*/
|
|
8
|
-
export enum BookMainRoute {
|
|
9
|
-
Search =
|
|
10
|
-
Book =
|
|
7
|
+
export declare enum BookMainRoute {
|
|
8
|
+
Search = "search",
|
|
9
|
+
Book = "book"
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
/**
|
|
14
12
|
* Valid route paths for the element-book app.
|
|
15
13
|
*
|
|
16
14
|
* @category Internal
|
|
17
15
|
*/
|
|
18
16
|
export type ValidBookPaths = [BookMainRoute.Search, string] | [BookMainRoute.Book, ...string[]];
|
|
19
|
-
|
|
20
17
|
/**
|
|
21
18
|
* A full element-book app route. Only paths are supported.
|
|
22
19
|
*
|
|
23
20
|
* @category Internal
|
|
24
21
|
*/
|
|
25
22
|
export type BookFullRoute = Readonly<FullSpaRoute<ValidBookPaths, undefined, undefined>>;
|
|
26
|
-
|
|
27
23
|
/**
|
|
28
24
|
* Extract the current search query from the current route paths.
|
|
29
25
|
*
|
|
30
26
|
* @category Internal
|
|
31
27
|
*/
|
|
32
|
-
export function extractSearchQuery(paths: Readonly<ValidBookPaths>)
|
|
33
|
-
if (paths[0] === BookMainRoute.Book) {
|
|
34
|
-
return '';
|
|
35
|
-
} else {
|
|
36
|
-
return paths[1] ? decodeURIComponent(paths[1]) : '';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
28
|
+
export declare function extractSearchQuery(paths: Readonly<ValidBookPaths>): string;
|
|
40
29
|
/**
|
|
41
30
|
* The default element-book app route.
|
|
42
31
|
*
|
|
43
32
|
* @category Internal
|
|
44
33
|
*/
|
|
45
|
-
export const defaultBookFullRoute: Readonly<BookFullRoute
|
|
46
|
-
hash: undefined,
|
|
47
|
-
paths: [BookMainRoute.Book],
|
|
48
|
-
search: undefined,
|
|
49
|
-
} as const;
|
|
34
|
+
export declare const defaultBookFullRoute: Readonly<BookFullRoute>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Top level routes supported by the element-book app.
|
|
3
|
+
*
|
|
4
|
+
* @category Internal
|
|
5
|
+
*/
|
|
6
|
+
export var BookMainRoute;
|
|
7
|
+
(function (BookMainRoute) {
|
|
8
|
+
BookMainRoute["Search"] = "search";
|
|
9
|
+
BookMainRoute["Book"] = "book";
|
|
10
|
+
})(BookMainRoute || (BookMainRoute = {}));
|
|
11
|
+
/**
|
|
12
|
+
* Extract the current search query from the current route paths.
|
|
13
|
+
*
|
|
14
|
+
* @category Internal
|
|
15
|
+
*/
|
|
16
|
+
export function extractSearchQuery(paths) {
|
|
17
|
+
if (paths[0] === BookMainRoute.Book) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return paths[1] ? decodeURIComponent(paths[1]) : '';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The default element-book app route.
|
|
26
|
+
*
|
|
27
|
+
* @category Internal
|
|
28
|
+
*/
|
|
29
|
+
export const defaultBookFullRoute = {
|
|
30
|
+
hash: undefined,
|
|
31
|
+
paths: [BookMainRoute.Book],
|
|
32
|
+
search: undefined,
|
|
33
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type CSSResult } from 'element-vir';
|
|
2
|
+
/**
|
|
3
|
+
* A single background and foreground color pairing.
|
|
4
|
+
*
|
|
5
|
+
* @category Internal
|
|
6
|
+
*/
|
|
7
|
+
export type ColorPair = {
|
|
8
|
+
background: CSSResult;
|
|
9
|
+
foreground: CSSResult;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Color pairs for everything used by the element-book app.
|
|
13
|
+
*
|
|
14
|
+
* @category Internal
|
|
15
|
+
*/
|
|
16
|
+
export type ColorTheme = {
|
|
17
|
+
nav: {
|
|
18
|
+
hover: ColorPair;
|
|
19
|
+
active: ColorPair;
|
|
20
|
+
selected: ColorPair;
|
|
21
|
+
};
|
|
22
|
+
accent: {
|
|
23
|
+
icon: CSSResult;
|
|
24
|
+
};
|
|
25
|
+
page: ColorPair & {
|
|
26
|
+
backgroundFaint1: CSSResult;
|
|
27
|
+
backgroundFaint2: CSSResult;
|
|
28
|
+
foregroundFaint1: CSSResult;
|
|
29
|
+
foregroundFaint2: CSSResult;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* All color theme CSS vars for the element-book app.
|
|
34
|
+
*
|
|
35
|
+
* @category Internal
|
|
36
|
+
*/
|
|
37
|
+
export declare const colorThemeCssVars: import("lit-css-vars").CssVarDefinitions<{
|
|
38
|
+
readonly 'element-book-nav-hover-background-color': "magenta";
|
|
39
|
+
readonly 'element-book-nav-hover-foreground-color': "magenta";
|
|
40
|
+
readonly 'element-book-nav-active-background-color': "magenta";
|
|
41
|
+
readonly 'element-book-nav-active-foreground-color': "magenta";
|
|
42
|
+
readonly 'element-book-nav-selected-background-color': "magenta";
|
|
43
|
+
readonly 'element-book-nav-selected-foreground-color': "magenta";
|
|
44
|
+
readonly 'element-book-accent-icon-color': "magenta";
|
|
45
|
+
readonly 'element-book-page-background-color': "magenta";
|
|
46
|
+
readonly 'element-book-page-background-faint-level-1-color': "magenta";
|
|
47
|
+
readonly 'element-book-page-background-faint-level-2-color': "magenta";
|
|
48
|
+
readonly 'element-book-page-foreground-color': "magenta";
|
|
49
|
+
readonly 'element-book-page-foreground-faint-level-1-color': "magenta";
|
|
50
|
+
readonly 'element-book-page-foreground-faint-level-2-color': "magenta";
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Sets a new color theme's CSS vars on the given HTML element for the element-book app.
|
|
54
|
+
*
|
|
55
|
+
* @category Internal
|
|
56
|
+
*/
|
|
57
|
+
export declare function setThemeCssVars(element: HTMLElement, theme: ColorTheme): void;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { defineCssVars, setCssVarValue } from 'lit-css-vars';
|
|
3
|
+
/**
|
|
4
|
+
* All color theme CSS vars for the element-book app.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export const colorThemeCssVars = defineCssVars({
|
|
9
|
+
'element-book-nav-hover-background-color': 'magenta',
|
|
10
|
+
'element-book-nav-hover-foreground-color': 'magenta',
|
|
11
|
+
'element-book-nav-active-background-color': 'magenta',
|
|
12
|
+
'element-book-nav-active-foreground-color': 'magenta',
|
|
13
|
+
'element-book-nav-selected-background-color': 'magenta',
|
|
14
|
+
'element-book-nav-selected-foreground-color': 'magenta',
|
|
15
|
+
'element-book-accent-icon-color': 'magenta',
|
|
16
|
+
'element-book-page-background-color': 'magenta',
|
|
17
|
+
'element-book-page-background-faint-level-1-color': 'magenta',
|
|
18
|
+
'element-book-page-background-faint-level-2-color': 'magenta',
|
|
19
|
+
'element-book-page-foreground-color': 'magenta',
|
|
20
|
+
'element-book-page-foreground-faint-level-1-color': 'magenta',
|
|
21
|
+
'element-book-page-foreground-faint-level-2-color': 'magenta',
|
|
22
|
+
});
|
|
23
|
+
const colorThemeCssVarMapping = {
|
|
24
|
+
nav: {
|
|
25
|
+
hover: {
|
|
26
|
+
background: colorThemeCssVars['element-book-nav-hover-background-color'],
|
|
27
|
+
foreground: colorThemeCssVars['element-book-nav-hover-foreground-color'],
|
|
28
|
+
},
|
|
29
|
+
active: {
|
|
30
|
+
background: colorThemeCssVars['element-book-nav-active-background-color'],
|
|
31
|
+
foreground: colorThemeCssVars['element-book-nav-active-foreground-color'],
|
|
32
|
+
},
|
|
33
|
+
selected: {
|
|
34
|
+
background: colorThemeCssVars['element-book-nav-selected-background-color'],
|
|
35
|
+
foreground: colorThemeCssVars['element-book-nav-selected-foreground-color'],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
accent: {
|
|
39
|
+
icon: colorThemeCssVars['element-book-accent-icon-color'],
|
|
40
|
+
},
|
|
41
|
+
page: {
|
|
42
|
+
background: colorThemeCssVars['element-book-page-background-color'],
|
|
43
|
+
backgroundFaint1: colorThemeCssVars['element-book-page-background-faint-level-1-color'],
|
|
44
|
+
backgroundFaint2: colorThemeCssVars['element-book-page-background-faint-level-2-color'],
|
|
45
|
+
foreground: colorThemeCssVars['element-book-page-foreground-color'],
|
|
46
|
+
foregroundFaint1: colorThemeCssVars['element-book-page-foreground-faint-level-1-color'],
|
|
47
|
+
foregroundFaint2: colorThemeCssVars['element-book-page-foreground-faint-level-2-color'],
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Sets a new color theme's CSS vars on the given HTML element for the element-book app.
|
|
52
|
+
*
|
|
53
|
+
* @category Internal
|
|
54
|
+
*/
|
|
55
|
+
export function setThemeCssVars(element, theme) {
|
|
56
|
+
recursiveSetThemeCssVars(element, theme, colorThemeCssVarMapping);
|
|
57
|
+
}
|
|
58
|
+
function isCssResult(input) {
|
|
59
|
+
return check.hasKey(input, '_$cssResult$');
|
|
60
|
+
}
|
|
61
|
+
function isCssVarDefinition(input) {
|
|
62
|
+
return (check.hasKeys(input, [
|
|
63
|
+
'name',
|
|
64
|
+
'value',
|
|
65
|
+
'default',
|
|
66
|
+
]) &&
|
|
67
|
+
check.isString(input.default) &&
|
|
68
|
+
isCssResult(input.name) &&
|
|
69
|
+
isCssResult(input.value));
|
|
70
|
+
}
|
|
71
|
+
function recursiveSetThemeCssVars(element, nestedCssResult, nestedCssVars) {
|
|
72
|
+
Object.entries(nestedCssResult).forEach(([key, value,]) => {
|
|
73
|
+
const nestedCssVar = nestedCssVars[key];
|
|
74
|
+
if (!nestedCssVar) {
|
|
75
|
+
throw new Error(`no nestedCssVar at key '${key}'`);
|
|
76
|
+
}
|
|
77
|
+
if (isCssResult(value)) {
|
|
78
|
+
if (!isCssVarDefinition(nestedCssVar)) {
|
|
79
|
+
throw new Error(`got a CSS result at '${key}' but no CSS var`);
|
|
80
|
+
}
|
|
81
|
+
setCssVarValue({
|
|
82
|
+
forCssVar: nestedCssVar,
|
|
83
|
+
onElement: element,
|
|
84
|
+
toValue: String(value),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (isCssVarDefinition(nestedCssVar)) {
|
|
89
|
+
throw new Error(`got no CSS result at '${key}' but did find a CSS var`);
|
|
90
|
+
}
|
|
91
|
+
recursiveSetThemeCssVars(element, value, nestedCssVar);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
+
import { type ColorTheme } from './color-theme.js';
|
|
3
|
+
/**
|
|
4
|
+
* The default theme color.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const defaultThemeStartColor = "dodgerblue";
|
|
9
|
+
/**
|
|
10
|
+
* Theme style options for the element-book app.
|
|
11
|
+
*
|
|
12
|
+
* @category Internal
|
|
13
|
+
*/
|
|
14
|
+
export declare enum ThemeStyle {
|
|
15
|
+
Dark = "dark",
|
|
16
|
+
Light = "light"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Theme configuration options for the element-book app.
|
|
20
|
+
*
|
|
21
|
+
* @category Internal
|
|
22
|
+
*/
|
|
23
|
+
export type ThemeConfig = PartialWithUndefined<{
|
|
24
|
+
themeColor: string;
|
|
25
|
+
themeStyle: ThemeStyle;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a theme from the given theme configuration.
|
|
29
|
+
*
|
|
30
|
+
* @category Internal
|
|
31
|
+
*/
|
|
32
|
+
export declare function createTheme({ themeColor: inputThemeColor, themeStyle, }?: ThemeConfig): ColorTheme;
|