element-book 3.0.2 → 4.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/dist/data/element-book-entry/element-book-entry.d.ts +2 -0
- package/dist/data/element-book-entry/element-book-entry.js +19 -1
- package/dist/data/element-book-entry/element-book-page/element-book-page-example.d.ts +5 -10
- package/dist/data/element-book-entry/element-book-page/element-book-page-example.js +1 -20
- package/dist/data/element-book-entry/element-book-page/element-book-page.d.ts +6 -1
- package/dist/data/element-book-entry/element-book-page/element-book-page.js +28 -1
- package/dist/data/element-book-entry/entry-tree/entry-tree.d.ts +0 -2
- package/dist/data/element-book-entry/entry-tree/entry-tree.js +2 -19
- package/dist/ui/elements/entry-display/element-book-entry-display.element.js +2 -2
- package/package.json +2 -2
|
@@ -10,3 +10,5 @@ export type ElementBookEntry = ElementBookChapter | ElementBookPage | ElementBoo
|
|
|
10
10
|
export declare function isElementBookEntry<SpecificType extends ElementBookEntryTypeEnum>(entry: unknown, entryType: SpecificType): entry is Extract<ElementBookEntry, {
|
|
11
11
|
entryType: SpecificType;
|
|
12
12
|
}>;
|
|
13
|
+
export declare function listBreadcrumbs(entry: ElementBookEntry, includeSelf?: boolean): string[];
|
|
14
|
+
export declare function titleToBreadcrumb(title: string): string;
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
import { typedHasProperty } from '@augment-vir/common';
|
|
1
|
+
import { collapseWhiteSpace, typedHasProperty } from '@augment-vir/common';
|
|
2
2
|
export function isElementBookEntry(entry, entryType) {
|
|
3
3
|
return typedHasProperty(entry, 'entryType') && entry.entryType === entryType;
|
|
4
4
|
}
|
|
5
|
+
export function listBreadcrumbs(entry, includeSelf) {
|
|
6
|
+
const entryBreadcrumb = titleToBreadcrumb(entry.title);
|
|
7
|
+
if (entry.parent) {
|
|
8
|
+
return [
|
|
9
|
+
titleToBreadcrumb(entry.parent.title),
|
|
10
|
+
...listBreadcrumbs(entry.parent, false),
|
|
11
|
+
].concat(includeSelf ? [entryBreadcrumb] : []);
|
|
12
|
+
}
|
|
13
|
+
else if (includeSelf) {
|
|
14
|
+
return [entryBreadcrumb];
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function titleToBreadcrumb(title) {
|
|
21
|
+
return collapseWhiteSpace(title).toLowerCase().replaceAll(/\s/g, '-');
|
|
22
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { RequireNonVoid } from '@augment-vir/common';
|
|
2
2
|
import { PropertyInitMapBase, RenderParams, TypedEvent } from 'element-vir';
|
|
3
3
|
import { CSSResult } from 'lit';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
controls: PageControlsToValues<PageControlsFromPage<ParentPage>>;
|
|
4
|
+
import { ElementBookPageControlMap, PageControlsToValues } from './element-book-page-controls/element-book-page-control';
|
|
5
|
+
export type ElementBookPageExampleRenderParams<ParentControls extends ElementBookPageControlMap, StateInit extends PropertyInitMapBase> = Pick<RenderParams<any, any, StateInit, any, any, any>, 'state' | 'updateState'> & {
|
|
6
|
+
controls: PageControlsToValues<ParentControls>;
|
|
8
7
|
};
|
|
9
|
-
export type ElementBookPageExampleInit<
|
|
8
|
+
export type ElementBookPageExampleInit<ParentControls extends ElementBookPageControlMap, StateInit extends PropertyInitMapBase, RenderOutput> = {
|
|
10
9
|
/** This example's title. Each title in a page must be unique. */
|
|
11
10
|
title: string;
|
|
12
|
-
/** The page that this example belongs to. */
|
|
13
|
-
parent: ParentPage;
|
|
14
11
|
/** Initialize the state for this example. */
|
|
15
12
|
stateInit?: StateInit;
|
|
16
13
|
/** Specify which events this example should intercept (so the user can see them). */
|
|
@@ -21,7 +18,5 @@ export type ElementBookPageExampleInit<ParentPage extends ElementBookPage<any>,
|
|
|
21
18
|
*/
|
|
22
19
|
styles?: CSSResult;
|
|
23
20
|
/** Render the example. */
|
|
24
|
-
renderCallback: RequireNonVoid<RenderOutput, (renderParams: ElementBookPageExampleRenderParams<
|
|
21
|
+
renderCallback: RequireNonVoid<RenderOutput, (renderParams: ElementBookPageExampleRenderParams<ParentControls, StateInit>) => RenderOutput, 'renderCallback is missing a return statement'>;
|
|
25
22
|
};
|
|
26
|
-
/** Inserts the defined element example into its parent page. */
|
|
27
|
-
export declare function insertElementExample<ParentPage extends ElementBookPage<any>, StateInit extends PropertyInitMapBase = {}, RenderOutput = any>(exampleInit: ElementBookPageExampleInit<ParentPage, StateInit, RenderOutput>): void;
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/** Inserts the defined element example into its parent page. */
|
|
3
|
-
export function insertElementExample(exampleInit) {
|
|
4
|
-
const errors = [];
|
|
5
|
-
const failureMessage = `Failed to define example '${exampleInit.parent.pageBreadcrumbs
|
|
6
|
-
.concat(exampleInit.title)
|
|
7
|
-
.join(' > ')}'`;
|
|
8
|
-
if (exampleInit.parent.examples.hasOwnProperty(exampleInit.title)) {
|
|
9
|
-
errors.push(new Error(`${failureMessage}: title '${exampleInit.title}' is already being used.`));
|
|
10
|
-
}
|
|
11
|
-
else if (!exampleInit.title) {
|
|
12
|
-
errors.push(new Error(`${failureMessage}: example title is missing or empty.`));
|
|
13
|
-
}
|
|
14
|
-
if (errors.length) {
|
|
15
|
-
exampleInit.parent.examples[exampleInit.title] = combineErrors(errors);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
exampleInit.parent.examples[exampleInit.title] = exampleInit;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Overwrite } from '@augment-vir/common';
|
|
2
|
+
import { PropertyInitMapBase } from 'element-vir';
|
|
2
3
|
import { SetOptional } from 'type-fest';
|
|
3
4
|
import { BaseElementBookEntry } from '../element-book-chapter/element-book-chapter';
|
|
4
5
|
import { ElementBookEntryTypeEnum } from '../element-book-entry-type';
|
|
@@ -12,5 +13,9 @@ export type ElementBookPage<Controls extends ElementBookPageControlMap = Element
|
|
|
12
13
|
pageBreadcrumbs: ReadonlyArray<string>;
|
|
13
14
|
};
|
|
14
15
|
export type PageControlsFromPage<Page extends ElementBookPage<any>> = Page extends ElementBookPage<infer Controls> ? Controls : never;
|
|
15
|
-
export type ElementBookPageInit<Controls extends ElementBookPageControlMap> = SetOptional<Omit<ElementBookPage<Controls>, 'entryType' | '
|
|
16
|
+
export type ElementBookPageInit<Controls extends ElementBookPageControlMap> = Overwrite<SetOptional<Omit<ElementBookPage<Controls>, 'entryType' | 'allExampleTitles' | 'pageBreadcrumbs' | 'examples'>, 'controls'>, {
|
|
17
|
+
defineExamplesCallback?: (params: {
|
|
18
|
+
defineExample: <StateInit extends PropertyInitMapBase = {}, RenderOutput = any>(exampleInit: ElementBookPageExampleInit<Controls, StateInit, RenderOutput>) => void;
|
|
19
|
+
}) => void;
|
|
20
|
+
}>;
|
|
16
21
|
export declare function defineElementBookPage<Controls extends ElementBookPageControlMap = {}>(pageSetup: ElementBookPageInit<Controls>): ElementBookPage<Controls>;
|
|
@@ -1,14 +1,41 @@
|
|
|
1
|
+
import { combineErrors } from '@augment-vir/common';
|
|
2
|
+
import { listBreadcrumbs } from '../element-book-entry';
|
|
1
3
|
import { ElementBookEntryTypeEnum } from '../element-book-entry-type';
|
|
4
|
+
function insertElementExample(parentExamples, parentBreadcrumbs, exampleInit) {
|
|
5
|
+
const errors = [];
|
|
6
|
+
const failureMessage = `Failed to define example '${parentBreadcrumbs
|
|
7
|
+
.concat(exampleInit.title)
|
|
8
|
+
.join(' > ')}'`;
|
|
9
|
+
if (parentExamples.hasOwnProperty(exampleInit.title)) {
|
|
10
|
+
errors.push(new Error(`${failureMessage}: title '${exampleInit.title}' is already being used.`));
|
|
11
|
+
}
|
|
12
|
+
else if (!exampleInit.title) {
|
|
13
|
+
errors.push(new Error(`${failureMessage}: example title is missing or empty.`));
|
|
14
|
+
}
|
|
15
|
+
if (errors.length) {
|
|
16
|
+
parentExamples[exampleInit.title] = combineErrors(errors);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
parentExamples[exampleInit.title] = exampleInit;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
2
22
|
export function defineElementBookPage(pageSetup) {
|
|
3
23
|
if (!pageSetup.title) {
|
|
4
24
|
throw new Error(`Cannot have an element-book page with an empty title.`);
|
|
5
25
|
}
|
|
26
|
+
const allExamples = {};
|
|
6
27
|
const page = {
|
|
7
28
|
entryType: ElementBookEntryTypeEnum.Page,
|
|
8
29
|
...pageSetup,
|
|
9
|
-
examples:
|
|
30
|
+
examples: allExamples,
|
|
10
31
|
controls: pageSetup.controls ?? {},
|
|
11
32
|
pageBreadcrumbs: [],
|
|
12
33
|
};
|
|
34
|
+
page.pageBreadcrumbs = listBreadcrumbs(page);
|
|
35
|
+
if (pageSetup.defineExamplesCallback) {
|
|
36
|
+
pageSetup.defineExamplesCallback({
|
|
37
|
+
defineExample: (exampleInit) => insertElementExample(allExamples, page.pageBreadcrumbs, exampleInit),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
13
40
|
return page;
|
|
14
41
|
}
|
|
@@ -13,8 +13,6 @@ export type EntryTreeNode<EntryType extends ElementBookEntryTypeEnum = any> = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare function isEntryNode<SpecificType extends ElementBookEntryTypeEnum>(input: unknown, entryType: SpecificType): input is EntryTreeNode<SpecificType>;
|
|
15
15
|
export declare function createEmptyEntryTreeRoot(title: string | undefined): EntryTreeNode<ElementBookEntryTypeEnum.Root>;
|
|
16
|
-
export declare function titleToBreadcrumb(title: string): string;
|
|
17
16
|
export declare function entriesToTree(entries: ReadonlyArray<ElementBookEntry>, everythingTitle: string | undefined): EntryTreeNode<ElementBookEntryTypeEnum.Root>;
|
|
18
|
-
export declare function listBreadcrumbs(entry: ElementBookEntry, includeSelf?: boolean): string[];
|
|
19
17
|
export declare function findEntryByBreadcrumbs(breadcrumbs: ReadonlyArray<string>, tree: Readonly<EntryTreeNode>): Readonly<EntryTreeNode> | undefined;
|
|
20
18
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isLengthAtLeast, typedHasProperties } from '@augment-vir/common';
|
|
2
|
+
import { listBreadcrumbs, titleToBreadcrumb } from '../element-book-entry';
|
|
2
3
|
import { ElementBookEntryTypeEnum } from '../element-book-entry-type';
|
|
3
4
|
import { addTreeToCache, getTreeFromCache } from './tree-cache';
|
|
4
5
|
export function doesNodeHaveEntryType(node, entryType) {
|
|
@@ -26,9 +27,6 @@ export function createEmptyEntryTreeRoot(title) {
|
|
|
26
27
|
};
|
|
27
28
|
return rootNode;
|
|
28
29
|
}
|
|
29
|
-
export function titleToBreadcrumb(title) {
|
|
30
|
-
return collapseWhiteSpace(title).toLowerCase().replaceAll(/\s/g, '-');
|
|
31
|
-
}
|
|
32
30
|
export function entriesToTree(entries, everythingTitle) {
|
|
33
31
|
const baseTree = createBaseTree(entries, everythingTitle);
|
|
34
32
|
return baseTree;
|
|
@@ -76,21 +74,6 @@ function traverseToImmediateParent(entry, currentTree) {
|
|
|
76
74
|
}, currentTree);
|
|
77
75
|
return immediateParentNode;
|
|
78
76
|
}
|
|
79
|
-
export function listBreadcrumbs(entry, includeSelf) {
|
|
80
|
-
const entryBreadcrumb = titleToBreadcrumb(entry.title);
|
|
81
|
-
if (entry.parent) {
|
|
82
|
-
return [
|
|
83
|
-
titleToBreadcrumb(entry.parent.title),
|
|
84
|
-
...listBreadcrumbs(entry.parent, false),
|
|
85
|
-
].concat(includeSelf ? [entryBreadcrumb] : []);
|
|
86
|
-
}
|
|
87
|
-
else if (includeSelf) {
|
|
88
|
-
return [entryBreadcrumb];
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
77
|
export function findEntryByBreadcrumbs(breadcrumbs, tree) {
|
|
95
78
|
if (!isLengthAtLeast(breadcrumbs, 1)) {
|
|
96
79
|
return tree;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { wait } from '@augment-vir/common';
|
|
2
2
|
import { VirIcon } from '@electrovir/icon-element';
|
|
3
3
|
import { assign, css, html, listen, renderIf } from 'element-vir';
|
|
4
|
-
import { isElementBookEntry } from '../../../data/element-book-entry/element-book-entry';
|
|
4
|
+
import { isElementBookEntry, listBreadcrumbs, } from '../../../data/element-book-entry/element-book-entry';
|
|
5
5
|
import { ElementBookEntryTypeEnum } from '../../../data/element-book-entry/element-book-entry-type';
|
|
6
|
-
import { isEntryNode
|
|
6
|
+
import { isEntryNode } from '../../../data/element-book-entry/entry-tree/entry-tree';
|
|
7
7
|
import { ElementBookMainRoute, defaultElementBookFullRoute, extractSearchQuery, } from '../../../routing/element-book-routing';
|
|
8
8
|
import { colorThemeCssVars } from '../../color-theme/color-theme';
|
|
9
9
|
import { ChangeRouteEvent } from '../../events/change-route.event';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "element-book",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"book",
|
|
6
6
|
"design system",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@augment-vir/common": "^14.2.0",
|
|
42
42
|
"@electrovir/icon-element": "^0.0.2",
|
|
43
43
|
"colorjs.io": "^0.4.3",
|
|
44
|
-
"element-vir": "^12.5.
|
|
44
|
+
"element-vir": "^12.5.4",
|
|
45
45
|
"lit-css-vars": "^2.0.2",
|
|
46
46
|
"spa-router-vir": "^2.1.0",
|
|
47
47
|
"typed-event-target": "^1.2.0"
|