element-book 22.2.2 → 23.0.0
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/README.md +65 -5
- package/dist/data/book-entry/base-book-entry.d.ts +7 -2
- package/dist/data/book-entry/book-entry-type.d.ts +12 -2
- package/dist/data/book-entry/book-entry-type.js +11 -6
- package/dist/data/book-entry/book-entry.d.ts +14 -4
- package/dist/data/book-entry/book-entry.js +7 -2
- package/dist/data/book-entry/book-page/book-page-controls.d.ts +62 -10
- package/dist/data/book-entry/book-page/book-page-controls.js +38 -16
- package/dist/data/book-entry/book-page/book-page.d.ts +29 -8
- package/dist/data/book-entry/book-page/book-page.js +1 -0
- package/dist/data/book-entry/book-page/controls-wrapper.d.ts +24 -4
- package/dist/data/book-entry/book-page/controls-wrapper.js +18 -3
- package/dist/data/book-entry/book-page/define-book-page.d.ts +44 -12
- package/dist/data/book-entry/book-page/define-book-page.js +19 -12
- package/dist/data/book-entry/book-root.d.ts +8 -3
- package/dist/data/book-entry/url-breadcrumbs.d.ts +17 -1
- package/dist/data/book-entry/url-breadcrumbs.js +16 -0
- package/dist/data/book-entry/verify-book-entry.d.ts +3 -6
- package/dist/data/book-entry/verify-book-entry.js +7 -7
- package/dist/data/book-tree/book-tree-node.d.ts +26 -7
- package/dist/data/book-tree/book-tree-node.js +5 -0
- package/dist/data/book-tree/book-tree.d.ts +7 -7
- package/dist/data/book-tree/book-tree.js +16 -15
- package/dist/data/book-tree/search-nodes.d.ts +1 -1
- package/dist/data/book-tree/search-nodes.js +4 -4
- package/dist/data/book-tree/tree-cache.d.ts +2 -2
- package/dist/index.d.ts +18 -10
- package/dist/index.js +18 -10
- package/dist/routing/book-router.d.ts +1 -1
- package/dist/routing/book-router.js +3 -3
- package/dist/routing/book-routing.d.ts +25 -0
- package/dist/routing/book-routing.js +15 -0
- package/dist/ui/color-theme/color-theme.d.ts +33 -13
- package/dist/ui/color-theme/color-theme.js +14 -5
- package/dist/ui/color-theme/create-color-theme.d.ts +23 -3
- package/dist/ui/color-theme/create-color-theme.js +15 -0
- package/dist/ui/elements/book-breadcrumbs.element.d.ts +3 -3
- package/dist/ui/elements/book-breadcrumbs.element.js +4 -4
- package/dist/ui/elements/book-nav/book-nav-filter.d.ts +1 -1
- package/dist/ui/elements/book-nav/book-nav-filter.js +6 -10
- package/dist/ui/elements/book-nav/book-nav.element.d.ts +3 -3
- package/dist/ui/elements/book-nav/book-nav.element.js +13 -13
- package/dist/ui/elements/common/book-error.element.d.ts +1 -1
- package/dist/ui/elements/common/book-error.element.js +4 -6
- package/dist/ui/elements/common/book-route-link.element.d.ts +3 -3
- package/dist/ui/elements/common/book-route-link.element.js +3 -3
- package/dist/ui/elements/define-book-element.d.ts +1 -1
- package/dist/ui/elements/element-book-app/element-book-app-slots.d.ts +13 -0
- package/dist/ui/elements/element-book-app/element-book-app-slots.js +13 -0
- package/dist/ui/elements/element-book-app/element-book-app.element.d.ts +22 -11
- package/dist/ui/elements/element-book-app/element-book-app.element.js +42 -36
- package/dist/ui/elements/element-book-app/element-book-config.d.ts +26 -16
- package/dist/ui/elements/element-book-app/get-current-nodes.d.ts +2 -2
- package/dist/ui/elements/element-book-app/get-current-nodes.js +3 -8
- package/dist/ui/elements/element-book-app/global-values.d.ts +5 -0
- package/dist/ui/elements/entry-display/book-breadcrumbs-bar.element.d.ts +3 -3
- package/dist/ui/elements/entry-display/book-breadcrumbs-bar.element.js +8 -8
- package/dist/ui/elements/entry-display/book-entry-description.element.d.ts +1 -1
- package/dist/ui/elements/entry-display/book-entry-description.element.js +3 -3
- package/dist/ui/elements/entry-display/book-page/book-page-controls.element.d.ts +6 -6
- package/dist/ui/elements/entry-display/book-page/book-page-controls.element.js +14 -14
- package/dist/ui/elements/entry-display/book-page/book-page-wrapper.element.d.ts +6 -6
- package/dist/ui/elements/entry-display/book-page/book-page-wrapper.element.js +13 -11
- package/dist/ui/elements/entry-display/element-example/book-element-example-controls.element.d.ts +5 -5
- package/dist/ui/elements/entry-display/element-example/book-element-example-controls.element.js +5 -5
- package/dist/ui/elements/entry-display/element-example/book-element-example-viewer.element.d.ts +5 -5
- package/dist/ui/elements/entry-display/element-example/book-element-example-viewer.element.js +13 -9
- package/dist/ui/elements/entry-display/element-example/book-element-example-wrapper.element.d.ts +6 -6
- package/dist/ui/elements/entry-display/element-example/book-element-example-wrapper.element.js +5 -5
- package/dist/ui/elements/entry-display/entry-display/book-entry-display.element.d.ts +9 -9
- package/dist/ui/elements/entry-display/entry-display/book-entry-display.element.js +6 -6
- package/dist/ui/elements/entry-display/entry-display/create-node-templates.d.ts +5 -5
- package/dist/ui/elements/entry-display/entry-display/create-node-templates.js +16 -16
- package/dist/ui/events/change-route.event.d.ts +1 -1
- package/dist/util/fuzzy-search.js +3 -2
- package/dist/util/type.d.ts +7 -0
- package/package.json +31 -29
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BookTreeNode } from '../../../data/book-tree/book-tree-node';
|
|
1
|
+
import { BookTreeNode } from '../../../data/book-tree/book-tree-node.js';
|
|
2
2
|
export declare function shouldShowTreeNodeInNav(currentNode: Readonly<BookTreeNode>, selectedPath: undefined | ReadonlyArray<string>): boolean;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { BookEntryType } from '../../../data/book-entry/book-entry-type.js';
|
|
3
3
|
export function shouldShowTreeNodeInNav(currentNode, selectedPath) {
|
|
4
|
-
if (currentNode.entry.entryType ===
|
|
4
|
+
if (currentNode.entry.entryType === BookEntryType.Root) {
|
|
5
5
|
return false;
|
|
6
6
|
}
|
|
7
|
-
if (currentNode.entry.entryType ===
|
|
7
|
+
if (currentNode.entry.entryType === BookEntryType.Page) {
|
|
8
8
|
return true;
|
|
9
9
|
}
|
|
10
|
-
const isParentSelected =
|
|
10
|
+
const isParentSelected = check.jsonEquals(selectedPath, currentNode.fullUrlBreadcrumbs.slice(0, -1));
|
|
11
11
|
if (isParentSelected) {
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
if (isSiblingSelected) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
return false;
|
|
14
|
+
return check.jsonEquals(selectedPath?.slice(0, -1), currentNode.fullUrlBreadcrumbs.slice(0, -1));
|
|
19
15
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BookTreeNode } from '../../../data/book-tree/book-tree-node';
|
|
2
|
-
import { BookRouter } from '../../../routing/book-router';
|
|
1
|
+
import { BookTreeNode } from '../../../data/book-tree/book-tree-node.js';
|
|
2
|
+
import { BookRouter } from '../../../routing/book-router.js';
|
|
3
3
|
export declare const BookNav: import("element-vir").DeclarativeElementDefinition<"book-nav", {
|
|
4
4
|
flattenedNodes: ReadonlyArray<Readonly<BookTreeNode>>;
|
|
5
5
|
selectedPath: ReadonlyArray<string> | undefined;
|
|
6
6
|
router: BookRouter | undefined;
|
|
7
|
-
}, {}, {},
|
|
7
|
+
}, {}, {}, "book-nav-", "book-nav-internal-indent", readonly []>;
|
|
8
8
|
export declare function scrollSelectedNavElementIntoView(bookNavInstance: typeof BookNav.instanceType): Promise<void>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { checkIfEntirelyInScrollView, waitForAnimationFrame } from '@augment-vir/web';
|
|
2
3
|
import { classMap, css, html, renderIf } from 'element-vir';
|
|
3
|
-
import { isJsonEqual } from 'run-time-assertions';
|
|
4
4
|
import { Element16Icon, ViraIcon } from 'vira';
|
|
5
|
-
import {
|
|
6
|
-
import { isBookTreeNode } from '../../../data/book-tree/book-tree';
|
|
7
|
-
import { BookMainRoute, defaultBookFullRoute } from '../../../routing/book-routing';
|
|
8
|
-
import { colorThemeCssVars } from '../../color-theme/color-theme';
|
|
9
|
-
import { BookRouteLink } from '../common/book-route-link.element';
|
|
10
|
-
import { defineBookElement } from '../define-book-element';
|
|
11
|
-
import { ElementBookSlotName } from '../element-book-app/element-book-app-slots';
|
|
12
|
-
import { shouldShowTreeNodeInNav } from './book-nav-filter';
|
|
5
|
+
import { BookEntryType } from '../../../data/book-entry/book-entry-type.js';
|
|
6
|
+
import { isBookTreeNode } from '../../../data/book-tree/book-tree.js';
|
|
7
|
+
import { BookMainRoute, defaultBookFullRoute } from '../../../routing/book-routing.js';
|
|
8
|
+
import { colorThemeCssVars } from '../../color-theme/color-theme.js';
|
|
9
|
+
import { BookRouteLink } from '../common/book-route-link.element.js';
|
|
10
|
+
import { defineBookElement } from '../define-book-element.js';
|
|
11
|
+
import { ElementBookSlotName } from '../element-book-app/element-book-app-slots.js';
|
|
12
|
+
import { shouldShowTreeNodeInNav } from './book-nav-filter.js';
|
|
13
13
|
export const BookNav = defineBookElement()({
|
|
14
14
|
tagName: 'book-nav',
|
|
15
15
|
cssVars: {
|
|
@@ -70,7 +70,7 @@ export const BookNav = defineBookElement()({
|
|
|
70
70
|
color: ${colorThemeCssVars['element-book-accent-icon-color'].value};
|
|
71
71
|
}
|
|
72
72
|
`,
|
|
73
|
-
|
|
73
|
+
render({ inputs }) {
|
|
74
74
|
const navTreeTemplates = inputs.flattenedNodes.map((treeNode) => {
|
|
75
75
|
if (!shouldShowTreeNodeInNav(treeNode, inputs.selectedPath)) {
|
|
76
76
|
return;
|
|
@@ -92,12 +92,12 @@ export const BookNav = defineBookElement()({
|
|
|
92
92
|
class=${classMap({
|
|
93
93
|
'title-row': true,
|
|
94
94
|
selected: inputs.selectedPath
|
|
95
|
-
?
|
|
95
|
+
? check.jsonEquals(inputs.selectedPath, treeNode.fullUrlBreadcrumbs)
|
|
96
96
|
: false,
|
|
97
97
|
})}
|
|
98
98
|
>
|
|
99
99
|
<div class="title-text">
|
|
100
|
-
${renderIf(isBookTreeNode(treeNode,
|
|
100
|
+
${renderIf(isBookTreeNode(treeNode, BookEntryType.ElementExample), html `
|
|
101
101
|
<${ViraIcon.assign({ icon: Element16Icon })}></${ViraIcon}>
|
|
102
102
|
`)}
|
|
103
103
|
${treeNode.entry.title}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const BookError: import("element-vir").DeclarativeElementDefinition<"book-error", {
|
|
2
2
|
message: string | ReadonlyArray<string>;
|
|
3
|
-
}, {}, {},
|
|
3
|
+
}, {}, {}, "book-error-", "book-error-", readonly []>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
1
2
|
import { css, html } from 'element-vir';
|
|
2
|
-
import {
|
|
3
|
-
import { defineBookElement } from '../define-book-element';
|
|
3
|
+
import { defineBookElement } from '../define-book-element.js';
|
|
4
4
|
export const BookError = defineBookElement()({
|
|
5
5
|
tagName: 'book-error',
|
|
6
6
|
styles: css `
|
|
@@ -16,10 +16,8 @@ export const BookError = defineBookElement()({
|
|
|
16
16
|
padding: 0;
|
|
17
17
|
}
|
|
18
18
|
`,
|
|
19
|
-
|
|
20
|
-
const paragraphs =
|
|
21
|
-
? inputs.message
|
|
22
|
-
: [inputs.message];
|
|
19
|
+
render({ inputs }) {
|
|
20
|
+
const paragraphs = check.isArray(inputs.message) ? inputs.message : [inputs.message];
|
|
23
21
|
return paragraphs.map((paragraph) => html `
|
|
24
22
|
<p>${paragraph}</p>
|
|
25
23
|
`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BookRouter } from '../../../routing/book-router';
|
|
2
|
-
import { BookFullRoute } from '../../../routing/book-routing';
|
|
1
|
+
import { BookRouter } from '../../../routing/book-router.js';
|
|
2
|
+
import { BookFullRoute } from '../../../routing/book-routing.js';
|
|
3
3
|
export declare const BookRouteLink: import("element-vir").DeclarativeElementDefinition<"book-route-link", {
|
|
4
4
|
route: Partial<BookFullRoute>;
|
|
5
5
|
router: Readonly<BookRouter> | undefined;
|
|
6
|
-
}, {}, {},
|
|
6
|
+
}, {}, {}, "book-route-link-", "book-route-link-anchor-padding", readonly []>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { css, html, listen } from 'element-vir';
|
|
2
2
|
import { shouldClickEventTriggerRouteChange } from 'spa-router-vir';
|
|
3
|
-
import { ChangeRouteEvent } from '../../events/change-route.event';
|
|
4
|
-
import { defineBookElement } from '../define-book-element';
|
|
3
|
+
import { ChangeRouteEvent } from '../../events/change-route.event.js';
|
|
4
|
+
import { defineBookElement } from '../define-book-element.js';
|
|
5
5
|
export const BookRouteLink = defineBookElement()({
|
|
6
6
|
tagName: 'book-route-link',
|
|
7
7
|
cssVars: {
|
|
@@ -18,7 +18,7 @@ export const BookRouteLink = defineBookElement()({
|
|
|
18
18
|
width: 100%;
|
|
19
19
|
}
|
|
20
20
|
`,
|
|
21
|
-
|
|
21
|
+
render: ({ inputs, dispatch }) => {
|
|
22
22
|
const linkUrl = inputs.router?.createRouteUrl({
|
|
23
23
|
...inputs.route,
|
|
24
24
|
}) ?? '#';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type BookTagName = `book-${string}`;
|
|
2
|
-
export declare const defineBookElement: <Inputs extends {}>() => <const TagName extends `book-${string}`, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}
|
|
2
|
+
export declare const defineBookElement: <Inputs extends {}>() => <const TagName extends `book-${string}`, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("element-vir").VerifiedElementInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("element-vir").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>, defineBookElementNoInputs: <const TagName extends `book-${string}`, Inputs extends {}, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("element-vir").VerifiedElementNoInputsInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("element-vir").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slots to be used on an element-book app instance for inserting custom HTML into the app.
|
|
3
|
+
*
|
|
4
|
+
* @category Main
|
|
5
|
+
*/
|
|
1
6
|
export declare enum ElementBookSlotName {
|
|
7
|
+
/**
|
|
8
|
+
* Used to specify a footer for the main element example viewer. It always appears at the bottom
|
|
9
|
+
* of the viewer's scroll area.
|
|
10
|
+
*/
|
|
2
11
|
Footer = "book-footer",
|
|
12
|
+
/**
|
|
13
|
+
* Used to specify a header above the navigation sidebar. This is a particularly good place for
|
|
14
|
+
* branding.
|
|
15
|
+
*/
|
|
3
16
|
NavHeader = "book-nav-header"
|
|
4
17
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slots to be used on an element-book app instance for inserting custom HTML into the app.
|
|
3
|
+
*
|
|
4
|
+
* @category Main
|
|
5
|
+
*/
|
|
1
6
|
export var ElementBookSlotName;
|
|
2
7
|
(function (ElementBookSlotName) {
|
|
8
|
+
/**
|
|
9
|
+
* Used to specify a footer for the main element example viewer. It always appears at the bottom
|
|
10
|
+
* of the viewer's scroll area.
|
|
11
|
+
*/
|
|
3
12
|
ElementBookSlotName["Footer"] = "book-footer";
|
|
13
|
+
/**
|
|
14
|
+
* Used to specify a header above the navigation sidebar. This is a particularly good place for
|
|
15
|
+
* branding.
|
|
16
|
+
*/
|
|
4
17
|
ElementBookSlotName["NavHeader"] = "book-nav-header";
|
|
5
18
|
})(ElementBookSlotName || (ElementBookSlotName = {}));
|
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
import { ControlsWrapper } from '../../../data/book-entry/book-page/controls-wrapper';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { ControlsWrapper } from '../../../data/book-entry/book-page/controls-wrapper.js';
|
|
2
|
+
import { BookRouter } from '../../../routing/book-router.js';
|
|
3
|
+
import { ColorTheme } from '../../color-theme/color-theme.js';
|
|
4
|
+
import { ThemeConfig } from '../../color-theme/create-color-theme.js';
|
|
5
|
+
import { ElementBookConfig } from './element-book-config.js';
|
|
6
|
+
import { GlobalValues } from './global-values.js';
|
|
7
|
+
/**
|
|
8
|
+
* Current color theme state used inside of {@link ElementBookApp}.
|
|
9
|
+
*
|
|
10
|
+
* @category Internal
|
|
11
|
+
*/
|
|
12
|
+
export type ColorThemeState = {
|
|
7
13
|
config: ThemeConfig | undefined;
|
|
8
14
|
theme: ColorTheme;
|
|
9
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* The element-book app itself. Instantiate one of these where you want your element-book pages to
|
|
18
|
+
* render. Make sure to also provide an array of pages to actually render!
|
|
19
|
+
*
|
|
20
|
+
* @category Main
|
|
21
|
+
*/
|
|
10
22
|
export declare const ElementBookApp: import("element-vir").DeclarativeElementDefinition<"element-book-app", ElementBookConfig, {
|
|
11
|
-
currentRoute: Readonly<Required<Readonly<import("spa-router-vir").FullRoute<import("../../../routing/book-routing").ValidBookPaths, undefined, undefined>>>>;
|
|
12
|
-
router:
|
|
23
|
+
currentRoute: Readonly<Required<Readonly<import("spa-router-vir").FullRoute<import("../../../routing/book-routing.js").ValidBookPaths, undefined, undefined>>>>;
|
|
24
|
+
router: undefined | BookRouter;
|
|
13
25
|
loading: boolean;
|
|
14
26
|
colors: ColorThemeState;
|
|
15
27
|
treeBasedControls: {
|
|
16
|
-
|
|
28
|
+
pages: ElementBookConfig["pages"];
|
|
17
29
|
lastGlobalInputs: GlobalValues;
|
|
18
30
|
controls: ControlsWrapper;
|
|
19
31
|
} | undefined;
|
|
20
32
|
originalWindowTitle: string | undefined;
|
|
21
33
|
}, {
|
|
22
|
-
pathUpdate: import("element-vir").
|
|
34
|
+
pathUpdate: import("element-vir").DefineEvent<readonly string[]>;
|
|
23
35
|
}, "element-book-app-", "element-book-app-", readonly []>;
|
|
24
|
-
export {};
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { extractErrorMessage,
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { extractErrorMessage, makeWritable } from '@augment-vir/common';
|
|
3
|
+
import { waitForAnimationFrame } from '@augment-vir/web';
|
|
3
4
|
import { css, defineElement, defineElementEvent, html, listen } from 'element-vir';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
5
|
+
import { createNewControls, updateTreeControls, } from '../../../data/book-entry/book-page/controls-wrapper.js';
|
|
6
|
+
import { createBookTreeFromEntries } from '../../../data/book-tree/book-tree.js';
|
|
7
|
+
import { searchFlattenedNodes } from '../../../data/book-tree/search-nodes.js';
|
|
8
|
+
import { createBookRouter } from '../../../routing/book-router.js';
|
|
9
|
+
import { defaultBookFullRoute, extractSearchQuery, } from '../../../routing/book-routing.js';
|
|
10
|
+
import { colorThemeCssVars, setThemeCssVars } from '../../color-theme/color-theme.js';
|
|
11
|
+
import { createTheme } from '../../color-theme/create-color-theme.js';
|
|
12
|
+
import { ChangeRouteEvent } from '../../events/change-route.event.js';
|
|
13
|
+
import { BookNav, scrollSelectedNavElementIntoView } from '../book-nav/book-nav.element.js';
|
|
14
|
+
import { BookError } from '../common/book-error.element.js';
|
|
15
|
+
import { BookPageControls } from '../entry-display/book-page/book-page-controls.element.js';
|
|
16
|
+
import { BookEntryDisplay } from '../entry-display/entry-display/book-entry-display.element.js';
|
|
17
|
+
import { ElementBookSlotName } from './element-book-app-slots.js';
|
|
18
|
+
import { getCurrentNodes } from './get-current-nodes.js';
|
|
19
|
+
/**
|
|
20
|
+
* The element-book app itself. Instantiate one of these where you want your element-book pages to
|
|
21
|
+
* render. Make sure to also provide an array of pages to actually render!
|
|
22
|
+
*
|
|
23
|
+
* @category Main
|
|
24
|
+
*/
|
|
19
25
|
export const ElementBookApp = defineElement()({
|
|
20
26
|
tagName: 'element-book-app',
|
|
21
27
|
events: {
|
|
@@ -71,18 +77,18 @@ export const ElementBookApp = defineElement()({
|
|
|
71
77
|
max-width: min(400px, 40%);
|
|
72
78
|
}
|
|
73
79
|
`,
|
|
74
|
-
|
|
75
|
-
setTimeout(() => {
|
|
76
|
-
scrollNav(host, extractSearchQuery(state.currentRoute.paths), state.currentRoute);
|
|
80
|
+
init({ host, state }) {
|
|
81
|
+
setTimeout(async () => {
|
|
82
|
+
await scrollNav(host, extractSearchQuery(state.currentRoute.paths), state.currentRoute);
|
|
77
83
|
}, 500);
|
|
78
84
|
},
|
|
79
|
-
|
|
85
|
+
cleanup({ state, updateState }) {
|
|
80
86
|
if (state.router) {
|
|
81
87
|
state.router.destroy();
|
|
82
88
|
updateState({ router: undefined });
|
|
83
89
|
}
|
|
84
90
|
},
|
|
85
|
-
|
|
91
|
+
render: ({ state, inputs, host, updateState, dispatch, events }) => {
|
|
86
92
|
if (inputs._debug) {
|
|
87
93
|
console.info('rendering element-book app');
|
|
88
94
|
}
|
|
@@ -94,7 +100,7 @@ export const ElementBookApp = defineElement()({
|
|
|
94
100
|
}
|
|
95
101
|
function areRoutesNew(newRouteInput) {
|
|
96
102
|
const newRoute = mergeRoutes(newRouteInput);
|
|
97
|
-
return !
|
|
103
|
+
return !check.jsonEquals(state.currentRoute, newRoute);
|
|
98
104
|
}
|
|
99
105
|
function updateWindowTitle(topNodeTitle) {
|
|
100
106
|
if (!inputs.preventWindowTitleChange) {
|
|
@@ -105,7 +111,7 @@ export const ElementBookApp = defineElement()({
|
|
|
105
111
|
state.originalWindowTitle,
|
|
106
112
|
topNodeTitle,
|
|
107
113
|
]
|
|
108
|
-
.filter(isTruthy)
|
|
114
|
+
.filter(check.isTruthy)
|
|
109
115
|
.join(' - ');
|
|
110
116
|
}
|
|
111
117
|
}
|
|
@@ -126,14 +132,14 @@ export const ElementBookApp = defineElement()({
|
|
|
126
132
|
});
|
|
127
133
|
}
|
|
128
134
|
if (inputs.elementBookRoutePaths &&
|
|
129
|
-
!
|
|
130
|
-
dispatch(new events.pathUpdate(newRoute.paths
|
|
135
|
+
!check.jsonEquals(inputs.elementBookRoutePaths, state.currentRoute.paths)) {
|
|
136
|
+
dispatch(new events.pathUpdate(newRoute.paths));
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
try {
|
|
134
140
|
if (inputs.elementBookRoutePaths &&
|
|
135
|
-
!
|
|
136
|
-
updateRoutes({ paths: inputs.elementBookRoutePaths });
|
|
141
|
+
!check.jsonEquals(inputs.elementBookRoutePaths, state.currentRoute.paths)) {
|
|
142
|
+
updateRoutes({ paths: makeWritable(inputs.elementBookRoutePaths) });
|
|
137
143
|
}
|
|
138
144
|
if (inputs.internalRouterConfig?.useInternalRouter && !state.router) {
|
|
139
145
|
const router = createBookRouter(inputs.internalRouterConfig.basePath);
|
|
@@ -150,7 +156,7 @@ export const ElementBookApp = defineElement()({
|
|
|
150
156
|
const inputThemeConfig = {
|
|
151
157
|
themeColor: inputs.themeColor,
|
|
152
158
|
};
|
|
153
|
-
if (!
|
|
159
|
+
if (!check.jsonEquals(inputThemeConfig, state.colors.config)) {
|
|
154
160
|
const newTheme = createTheme(inputThemeConfig);
|
|
155
161
|
updateState({
|
|
156
162
|
colors: {
|
|
@@ -162,21 +168,21 @@ export const ElementBookApp = defineElement()({
|
|
|
162
168
|
}
|
|
163
169
|
const debug = inputs._debug ?? false;
|
|
164
170
|
const originalTree = createBookTreeFromEntries({
|
|
165
|
-
entries: inputs.
|
|
171
|
+
entries: inputs.pages,
|
|
166
172
|
debug,
|
|
167
173
|
});
|
|
168
174
|
if (!state.treeBasedControls ||
|
|
169
|
-
state.treeBasedControls.
|
|
175
|
+
state.treeBasedControls.pages !== inputs.pages ||
|
|
170
176
|
state.treeBasedControls.lastGlobalInputs !== inputs.globalValues) {
|
|
171
177
|
if (inputs._debug) {
|
|
172
178
|
console.info('regenerating global controls');
|
|
173
179
|
}
|
|
174
180
|
updateState({
|
|
175
181
|
treeBasedControls: {
|
|
176
|
-
|
|
182
|
+
pages: inputs.pages,
|
|
177
183
|
lastGlobalInputs: inputs.globalValues ?? {},
|
|
178
184
|
controls: updateTreeControls(originalTree.tree, {
|
|
179
|
-
children: state.treeBasedControls?.controls
|
|
185
|
+
children: state.treeBasedControls?.controls.children,
|
|
180
186
|
controls: inputs.globalValues,
|
|
181
187
|
}),
|
|
182
188
|
},
|
|
@@ -215,9 +221,9 @@ export const ElementBookApp = defineElement()({
|
|
|
215
221
|
updateRoutes(newRoute);
|
|
216
222
|
const navElement = host.shadowRoot.querySelector(BookNav.tagName);
|
|
217
223
|
if (!(navElement instanceof BookNav)) {
|
|
218
|
-
throw new
|
|
224
|
+
throw new TypeError(`Failed to find child '${BookNav.tagName}'`);
|
|
219
225
|
}
|
|
220
|
-
scrollNav(host, searchQuery, state.currentRoute);
|
|
226
|
+
await scrollNav(host, searchQuery, state.currentRoute);
|
|
221
227
|
})}
|
|
222
228
|
${listen(BookPageControls.events.controlValueChange, (event) => {
|
|
223
229
|
if (!state.treeBasedControls) {
|
|
@@ -290,7 +296,7 @@ async function scrollNav(host, searchQuery, currentRoutes) {
|
|
|
290
296
|
}
|
|
291
297
|
const navElement = host.shadowRoot.querySelector(BookNav.tagName);
|
|
292
298
|
if (!(navElement instanceof BookNav)) {
|
|
293
|
-
throw new
|
|
299
|
+
throw new TypeError(`Failed to find child '${BookNav.tagName}'`);
|
|
294
300
|
}
|
|
295
301
|
await scrollSelectedNavElementIntoView(navElement);
|
|
296
302
|
}
|
|
@@ -1,38 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PartialWithUndefined } from '@augment-vir/common';
|
|
2
2
|
import { RequireExactlyOne } from 'type-fest';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { BookPage } from '../../../data/book-entry/book-page/book-page.js';
|
|
4
|
+
import { ValidBookPaths } from '../../../routing/book-routing.js';
|
|
5
|
+
import { GlobalValues } from './global-values.js';
|
|
6
|
+
/**
|
|
7
|
+
* Full configuration for an element-book app.
|
|
8
|
+
*
|
|
9
|
+
* @category Type
|
|
10
|
+
*/
|
|
5
11
|
export type ElementBookConfig = {
|
|
6
|
-
/** All element-book
|
|
7
|
-
|
|
8
|
-
} &
|
|
9
|
-
|
|
12
|
+
/** All element-book pages in order. */
|
|
13
|
+
pages: ReadonlyArray<BookPage>;
|
|
14
|
+
} & PartialWithUndefined<OptionalConfig>;
|
|
15
|
+
/**
|
|
16
|
+
* Options for {@link ElementBookConfig} that are optional.
|
|
17
|
+
*
|
|
18
|
+
* @category Internal
|
|
19
|
+
*/
|
|
20
|
+
export type OptionalConfig = {
|
|
10
21
|
/** The base theme color from which all other element-book colors will be generated from. */
|
|
11
22
|
themeColor: string;
|
|
12
23
|
_debug: boolean;
|
|
13
24
|
globalValues: GlobalValues;
|
|
14
25
|
preventWindowTitleChange: boolean;
|
|
15
|
-
} & RequireExactlyOne<{
|
|
26
|
+
} & RequireExactlyOne<Readonly<{
|
|
16
27
|
/**
|
|
17
28
|
* Set this internal router config if element-book is intended to be the current website's
|
|
18
29
|
* entire web app. Meaning, you're not embedded element-book within another website.
|
|
19
30
|
*
|
|
20
|
-
* In this case, element-book will create its own internal router for managing the URL. In
|
|
21
|
-
* cases, when element-book is embedded in another website, use the
|
|
22
|
-
* property instead.
|
|
31
|
+
* In this case, element-book will create its own internal router for managing the URL. In
|
|
32
|
+
* other cases, when element-book is embedded in another website, use the
|
|
33
|
+
* elementBookRoutePaths input property instead.
|
|
23
34
|
*/
|
|
24
|
-
internalRouterConfig: {
|
|
35
|
+
internalRouterConfig: Readonly<{
|
|
25
36
|
useInternalRouter: true;
|
|
26
37
|
/**
|
|
27
38
|
* Path to this page, used for routing. For example, if this page is hosted at
|
|
28
39
|
* www.example.org/my-page then this value should be `my-page`.
|
|
29
40
|
*/
|
|
30
41
|
basePath?: string | undefined;
|
|
31
|
-
}
|
|
42
|
+
}>;
|
|
32
43
|
/**
|
|
33
44
|
* Current route paths for element-book to handle. These are intended to come from a router
|
|
34
45
|
* that's external to the element-book app itself.
|
|
35
46
|
*/
|
|
36
|
-
elementBookRoutePaths:
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
47
|
+
elementBookRoutePaths: Readonly<ValidBookPaths>;
|
|
48
|
+
}>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BookTreeNode } from '../../../data/book-tree/book-tree-node';
|
|
2
|
-
import { BookFullRoute, ValidBookPaths } from '../../../routing/book-routing';
|
|
1
|
+
import { BookTreeNode } from '../../../data/book-tree/book-tree-node.js';
|
|
2
|
+
import { BookFullRoute, ValidBookPaths } from '../../../routing/book-routing.js';
|
|
3
3
|
export declare function getCurrentNodes(flattenedNodes: ReadonlyArray<Readonly<BookTreeNode>>, currentPaths: Readonly<ValidBookPaths>, updateRoutes: (newRoute: Partial<BookFullRoute>) => void): BookTreeNode[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { doBreadcrumbsStartWith } from '../../../data/book-entry/url-breadcrumbs';
|
|
2
|
-
import { defaultBookFullRoute } from '../../../routing/book-routing';
|
|
1
|
+
import { doBreadcrumbsStartWith } from '../../../data/book-entry/url-breadcrumbs.js';
|
|
2
|
+
import { defaultBookFullRoute, } from '../../../routing/book-routing.js';
|
|
3
3
|
export function getCurrentNodes(flattenedNodes, currentPaths, updateRoutes) {
|
|
4
4
|
const filteredNodes = filterNodes(flattenedNodes, currentPaths);
|
|
5
5
|
if (filteredNodes.length) {
|
|
@@ -8,12 +8,7 @@ export function getCurrentNodes(flattenedNodes, currentPaths, updateRoutes) {
|
|
|
8
8
|
else {
|
|
9
9
|
updateRoutes(defaultBookFullRoute);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
if (!filteredNodesFromDefaultPath) {
|
|
13
|
-
throw new Error(`Tried to self-correct for invalid path ${currentPaths.join('/')}
|
|
14
|
-
but failed to do so.`);
|
|
15
|
-
}
|
|
16
|
-
return filteredNodesFromDefaultPath;
|
|
11
|
+
return filterNodes(flattenedNodes, defaultBookFullRoute.paths);
|
|
17
12
|
}
|
|
18
13
|
function filterNodes(flattenedNodes, paths) {
|
|
19
14
|
return flattenedNodes.filter((node) => doBreadcrumbsStartWith({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BookRouter } from '../../../routing/book-router';
|
|
2
|
-
import { BookFullRoute } from '../../../routing/book-routing';
|
|
1
|
+
import { BookRouter } from '../../../routing/book-router.js';
|
|
2
|
+
import { BookFullRoute } from '../../../routing/book-routing.js';
|
|
3
3
|
export declare const BookBreadcrumbsBar: import("element-vir").DeclarativeElementDefinition<"book-breadcrumbs-bar", {
|
|
4
4
|
currentSearch: string;
|
|
5
5
|
currentRoute: Readonly<BookFullRoute>;
|
|
6
6
|
router: Readonly<BookRouter> | undefined;
|
|
7
|
-
}, {}, {},
|
|
7
|
+
}, {}, {}, "book-breadcrumbs-bar-", "book-breadcrumbs-bar-", readonly []>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { wait } from '@augment-vir/common';
|
|
2
2
|
import { css, html, listen, renderIf } from 'element-vir';
|
|
3
|
-
import { BookMainRoute, defaultBookFullRoute } from '../../../routing/book-routing';
|
|
4
|
-
import { colorThemeCssVars } from '../../color-theme/color-theme';
|
|
5
|
-
import { ChangeRouteEvent } from '../../events/change-route.event';
|
|
6
|
-
import { BookBreadcrumbs } from '../book-breadcrumbs.element';
|
|
7
|
-
import { defineBookElement } from '../define-book-element';
|
|
3
|
+
import { BookMainRoute, defaultBookFullRoute } from '../../../routing/book-routing.js';
|
|
4
|
+
import { colorThemeCssVars } from '../../color-theme/color-theme.js';
|
|
5
|
+
import { ChangeRouteEvent } from '../../events/change-route.event.js';
|
|
6
|
+
import { BookBreadcrumbs } from '../book-breadcrumbs.element.js';
|
|
7
|
+
import { defineBookElement } from '../define-book-element.js';
|
|
8
8
|
export const BookBreadcrumbsBar = defineBookElement()({
|
|
9
9
|
tagName: 'book-breadcrumbs-bar',
|
|
10
10
|
styles: css `
|
|
@@ -19,7 +19,7 @@ export const BookBreadcrumbsBar = defineBookElement()({
|
|
|
19
19
|
justify-content: space-between;
|
|
20
20
|
}
|
|
21
21
|
`,
|
|
22
|
-
|
|
22
|
+
render({ inputs, dispatch }) {
|
|
23
23
|
return html `
|
|
24
24
|
${renderIf(!!inputs.currentSearch, html `
|
|
25
25
|
|
|
@@ -35,11 +35,11 @@ export const BookBreadcrumbsBar = defineBookElement()({
|
|
|
35
35
|
${listen('input', async (event) => {
|
|
36
36
|
const inputElement = event.currentTarget;
|
|
37
37
|
if (!(inputElement instanceof HTMLInputElement)) {
|
|
38
|
-
throw new
|
|
38
|
+
throw new TypeError('Failed to find input element for search.');
|
|
39
39
|
}
|
|
40
40
|
const preThrottleValue = inputElement.value;
|
|
41
41
|
// throttle it a bit
|
|
42
|
-
await wait(200);
|
|
42
|
+
await wait({ milliseconds: 200 });
|
|
43
43
|
if (inputElement.value !== preThrottleValue) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const BookEntryDescription: import("element-vir").DeclarativeElementDefinition<"book-entry-description", {
|
|
2
2
|
descriptionParagraphs: ReadonlyArray<string>;
|
|
3
|
-
}, {}, {},
|
|
3
|
+
}, {}, {}, "book-entry-description-", "book-entry-description-", readonly []>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { css, html } from 'element-vir';
|
|
2
|
-
import { colorThemeCssVars } from '../../color-theme/color-theme';
|
|
3
|
-
import { defineBookElement } from '../define-book-element';
|
|
2
|
+
import { colorThemeCssVars } from '../../color-theme/color-theme.js';
|
|
3
|
+
import { defineBookElement } from '../define-book-element.js';
|
|
4
4
|
export const BookEntryDescription = defineBookElement()({
|
|
5
5
|
tagName: 'book-entry-description',
|
|
6
6
|
styles: css `
|
|
@@ -24,7 +24,7 @@ export const BookEntryDescription = defineBookElement()({
|
|
|
24
24
|
margin-top: 8px;
|
|
25
25
|
}
|
|
26
26
|
`,
|
|
27
|
-
|
|
27
|
+
render({ inputs }) {
|
|
28
28
|
return inputs.descriptionParagraphs.map((paragraph) => {
|
|
29
29
|
return html `
|
|
30
30
|
<p>${paragraph}</p>
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BookPageControl, BookPageControlsValues } from '../../../../data/book-entry/book-page/book-page-controls.js';
|
|
2
|
+
import { BookPage } from '../../../../data/book-entry/book-page/book-page.js';
|
|
3
3
|
export declare const BookPageControls: import("element-vir").DeclarativeElementDefinition<"book-page-controls", {
|
|
4
|
-
config: BookPage[
|
|
4
|
+
config: BookPage["controls"];
|
|
5
5
|
/**
|
|
6
6
|
* If an object (or Record) is given for this input, then each key of the object must correspond
|
|
7
7
|
* to one of the controls from the input config and the value for each key will be the
|
|
8
8
|
* breadcrumbs for that specific config.
|
|
9
9
|
*/
|
|
10
10
|
fullUrlBreadcrumbs: ReadonlyArray<string> | Record<string, ReadonlyArray<string>>;
|
|
11
|
-
currentValues: Record<string, BookPageControl[
|
|
11
|
+
currentValues: Record<string, BookPageControl["initValue"]>;
|
|
12
12
|
}, {}, {
|
|
13
|
-
controlValueChange: import("element-vir").
|
|
13
|
+
controlValueChange: import("element-vir").DefineEvent<{
|
|
14
14
|
fullUrlBreadcrumbs: ReadonlyArray<string>;
|
|
15
15
|
newValues: BookPageControlsValues;
|
|
16
16
|
}>;
|
|
17
|
-
}, "book-page-controls-has-controls",
|
|
17
|
+
}, "book-page-controls-has-controls", "book-page-controls-", readonly []>;
|