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.
Files changed (113) hide show
  1. package/{src/data/book-entry/base-book-entry.ts → dist/data/book-entry/base-book-entry.d.ts} +2 -3
  2. package/dist/data/book-entry/base-book-entry.js +1 -0
  3. package/{src/data/book-entry/book-entry-type.ts → dist/data/book-entry/book-entry-type.d.ts} +5 -9
  4. package/dist/data/book-entry/book-entry-type.js +14 -0
  5. package/dist/data/book-entry/book-entry.d.ts +17 -0
  6. package/dist/data/book-entry/book-entry.js +9 -0
  7. package/dist/data/book-entry/book-page/book-page-controls.d.ts +92 -0
  8. package/dist/data/book-entry/book-page/book-page-controls.js +70 -0
  9. package/dist/data/book-entry/book-page/book-page.d.ts +63 -0
  10. package/dist/data/book-entry/book-page/book-page.js +2 -0
  11. package/dist/data/book-entry/book-page/controls-wrapper.d.ts +32 -0
  12. package/dist/data/book-entry/book-page/controls-wrapper.js +65 -0
  13. package/dist/data/book-entry/book-page/define-book-page.d.ts +58 -0
  14. package/dist/data/book-entry/book-page/define-book-page.js +52 -0
  15. package/dist/data/book-entry/book-root.d.ts +12 -0
  16. package/dist/data/book-entry/book-root.js +1 -0
  17. package/dist/data/book-entry/url-breadcrumbs.d.ts +23 -0
  18. package/{src/data/book-entry/url-breadcrumbs.ts → dist/data/book-entry/url-breadcrumbs.js} +8 -17
  19. package/dist/data/book-entry/verify-book-entry.d.ts +3 -0
  20. package/{src/data/book-entry/verify-book-entry.ts → dist/data/book-entry/verify-book-entry.js} +3 -9
  21. package/{src/data/book-tree/book-tree-node.ts → dist/data/book-tree/book-tree-node.d.ts} +9 -15
  22. package/dist/data/book-tree/book-tree-node.js +6 -0
  23. package/dist/data/book-tree/book-tree.d.ts +13 -0
  24. package/dist/data/book-tree/book-tree.js +136 -0
  25. package/dist/data/book-tree/search-nodes.d.ts +5 -0
  26. package/dist/data/book-tree/search-nodes.js +74 -0
  27. package/dist/data/book-tree/tree-cache.d.ts +4 -0
  28. package/dist/data/book-tree/tree-cache.js +8 -0
  29. package/dist/data/unset.d.ts +1 -0
  30. package/dist/index.js +18 -0
  31. package/dist/routing/book-router.d.ts +4 -0
  32. package/{src/routing/book-router.ts → dist/routing/book-router.js} +12 -16
  33. package/{src/routing/book-routing.ts → dist/routing/book-routing.d.ts} +6 -21
  34. package/dist/routing/book-routing.js +33 -0
  35. package/dist/ui/color-theme/color-theme.d.ts +57 -0
  36. package/dist/ui/color-theme/color-theme.js +94 -0
  37. package/dist/ui/color-theme/create-color-theme.d.ts +32 -0
  38. package/dist/ui/color-theme/create-color-theme.js +93 -0
  39. package/dist/ui/elements/book-breadcrumbs.element.d.ts +6 -0
  40. package/dist/ui/elements/book-breadcrumbs.element.js +50 -0
  41. package/dist/ui/elements/book-nav/book-nav-filter.d.ts +2 -0
  42. package/dist/ui/elements/book-nav/book-nav-filter.js +15 -0
  43. package/dist/ui/elements/book-nav/book-nav.element.d.ts +8 -0
  44. package/{src/ui/elements/book-nav/book-nav.element.ts → dist/ui/elements/book-nav/book-nav.element.js} +44 -65
  45. package/dist/ui/elements/common/book-error.element.d.ts +3 -0
  46. package/{src/ui/elements/common/book-error.element.ts → dist/ui/elements/common/book-error.element.js} +8 -12
  47. package/dist/ui/elements/common/book-route-link.element.d.ts +6 -0
  48. package/dist/ui/elements/common/book-route-link.element.js +40 -0
  49. package/dist/ui/elements/define-book-element.d.ts +2 -0
  50. package/dist/ui/elements/define-book-element.js +2 -0
  51. 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
  52. package/dist/ui/elements/element-book-app/element-book-app-slots.js +18 -0
  53. package/dist/ui/elements/element-book-app/element-book-app.element.d.ts +35 -0
  54. package/dist/ui/elements/element-book-app/element-book-app.element.js +301 -0
  55. package/dist/ui/elements/element-book-app/element-book-config.d.ts +48 -0
  56. package/dist/ui/elements/element-book-app/element-book-config.js +1 -0
  57. package/dist/ui/elements/element-book-app/get-current-nodes.d.ts +3 -0
  58. package/dist/ui/elements/element-book-app/get-current-nodes.js +18 -0
  59. package/dist/ui/elements/element-book-app/global-values.js +1 -0
  60. package/dist/ui/elements/entry-display/book-breadcrumbs-bar.element.d.ts +7 -0
  61. package/dist/ui/elements/entry-display/book-breadcrumbs-bar.element.js +60 -0
  62. package/dist/ui/elements/entry-display/book-entry-description.element.d.ts +4 -0
  63. package/{src/ui/elements/entry-display/book-entry-description.element.ts → dist/ui/elements/entry-display/book-entry-description.element.js} +7 -10
  64. package/dist/ui/elements/entry-display/book-page/book-page-controls.element.d.ts +17 -0
  65. package/dist/ui/elements/entry-display/book-page/book-page-controls.element.js +172 -0
  66. package/dist/ui/elements/entry-display/book-page/book-page-wrapper.element.d.ts +10 -0
  67. package/dist/ui/elements/entry-display/book-page/book-page-wrapper.element.js +86 -0
  68. package/dist/ui/elements/entry-display/element-example/book-element-example-controls.element.d.ts +7 -0
  69. package/dist/ui/elements/entry-display/element-example/book-element-example-controls.element.js +34 -0
  70. package/dist/ui/elements/entry-display/element-example/book-element-example-viewer.element.d.ts +7 -0
  71. package/dist/ui/elements/entry-display/element-example/book-element-example-viewer.element.js +61 -0
  72. package/dist/ui/elements/entry-display/element-example/book-element-example-wrapper.element.d.ts +9 -0
  73. package/dist/ui/elements/entry-display/element-example/book-element-example-wrapper.element.js +50 -0
  74. package/dist/ui/elements/entry-display/entry-display/book-entry-display.element.d.ts +18 -0
  75. 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
  76. package/dist/ui/elements/entry-display/entry-display/create-node-templates.d.ts +13 -0
  77. package/dist/ui/elements/entry-display/entry-display/create-node-templates.js +113 -0
  78. package/dist/ui/events/change-route.event.d.ts +1 -0
  79. package/dist/ui/events/change-route.event.js +2 -0
  80. package/dist/util/fuzzy-search.d.ts +34 -0
  81. package/{src/util/fuzzy-search.ts → dist/util/fuzzy-search.js} +5 -13
  82. package/{src/util/type.ts → dist/util/type.d.ts} +4 -3
  83. package/dist/util/type.js +1 -0
  84. package/package.json +5 -5
  85. package/src/data/book-entry/book-entry.ts +0 -23
  86. package/src/data/book-entry/book-page/book-page-controls.ts +0 -159
  87. package/src/data/book-entry/book-page/book-page.ts +0 -110
  88. package/src/data/book-entry/book-page/controls-wrapper.ts +0 -119
  89. package/src/data/book-entry/book-page/define-book-page.ts +0 -171
  90. package/src/data/book-entry/book-root.ts +0 -16
  91. package/src/data/book-tree/book-tree.ts +0 -225
  92. package/src/data/book-tree/search-nodes.ts +0 -104
  93. package/src/data/book-tree/tree-cache.ts +0 -13
  94. package/src/ui/color-theme/color-theme.ts +0 -152
  95. package/src/ui/color-theme/create-color-theme.ts +0 -139
  96. package/src/ui/elements/book-breadcrumbs.element.ts +0 -60
  97. package/src/ui/elements/book-nav/book-nav-filter.ts +0 -30
  98. package/src/ui/elements/common/book-route-link.element.ts +0 -48
  99. package/src/ui/elements/define-book-element.ts +0 -5
  100. package/src/ui/elements/element-book-app/element-book-app.element.ts +0 -380
  101. package/src/ui/elements/element-book-app/element-book-config.ts +0 -52
  102. package/src/ui/elements/element-book-app/get-current-nodes.ts +0 -35
  103. package/src/ui/elements/entry-display/book-breadcrumbs-bar.element.ts +0 -78
  104. package/src/ui/elements/entry-display/book-page/book-page-controls.element.ts +0 -219
  105. package/src/ui/elements/entry-display/book-page/book-page-wrapper.element.ts +0 -105
  106. package/src/ui/elements/entry-display/element-example/book-element-example-controls.element.ts +0 -42
  107. package/src/ui/elements/entry-display/element-example/book-element-example-viewer.element.ts +0 -79
  108. package/src/ui/elements/entry-display/element-example/book-element-example-wrapper.element.ts +0 -61
  109. package/src/ui/elements/entry-display/entry-display/create-node-templates.ts +0 -183
  110. package/src/ui/events/change-route.event.ts +0 -6
  111. /package/{src/data/unset.ts → dist/data/unset.js} +0 -0
  112. /package/{src/index.ts → dist/index.d.ts} +0 -0
  113. /package/{src/ui/elements/element-book-app/global-values.ts → dist/ui/elements/element-book-app/global-values.d.ts} +0 -0
@@ -1,6 +1,5 @@
1
- import {type HTMLTemplateResult} from 'element-vir';
2
- import {type BookEntryType} from './book-entry-type.js';
3
-
1
+ import { type HTMLTemplateResult } from 'element-vir';
2
+ import { type BookEntryType } from './book-entry-type.js';
4
3
  /**
5
4
  * Base properties for all book entry types.
6
5
  *
@@ -0,0 +1 @@
1
+ export {};
@@ -3,21 +3,17 @@
3
3
  *
4
4
  * @category Internal
5
5
  */
6
- export enum BookEntryType {
6
+ export declare enum BookEntryType {
7
7
  /** A single element example. */
8
- ElementExample = 'element-example',
8
+ ElementExample = "element-example",
9
9
  /** An individual book page with element examples and/or sub-pages. */
10
- Page = 'page',
10
+ Page = "page",
11
11
  /** Tree root. Not for external use. */
12
- Root = 'root',
12
+ Root = "root"
13
13
  }
14
-
15
14
  /**
16
15
  * A union of all possible element-book entry types.
17
16
  *
18
17
  * @category Internal
19
18
  */
20
- export type AnyBookEntryType =
21
- | BookEntryType.ElementExample
22
- | BookEntryType.Page
23
- | BookEntryType.Root;
19
+ export type AnyBookEntryType = BookEntryType.ElementExample | BookEntryType.Page | BookEntryType.Root;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * All possible types for element-book entries.
3
+ *
4
+ * @category Internal
5
+ */
6
+ export var BookEntryType;
7
+ (function (BookEntryType) {
8
+ /** A single element example. */
9
+ BookEntryType["ElementExample"] = "element-example";
10
+ /** An individual book page with element examples and/or sub-pages. */
11
+ BookEntryType["Page"] = "page";
12
+ /** Tree root. Not for external use. */
13
+ BookEntryType["Root"] = "root";
14
+ })(BookEntryType || (BookEntryType = {}));
@@ -0,0 +1,17 @@
1
+ import { type BookEntryType } from './book-entry-type.js';
2
+ import { type BookElementExample, type BookPage } from './book-page/book-page.js';
3
+ import { type BookRoot } from './book-root.js';
4
+ /**
5
+ * All possible book entries.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export type BookEntry = BookPage | BookRoot | BookElementExample;
10
+ /**
11
+ * Check if the input is a book entry of the given type.
12
+ *
13
+ * @internal
14
+ */
15
+ export declare function isBookEntry<const SpecificType extends BookEntryType>(entry: unknown, entryType: SpecificType): entry is Extract<BookEntry, {
16
+ entryType: SpecificType;
17
+ }>;
@@ -0,0 +1,9 @@
1
+ import { check } from '@augment-vir/assert';
2
+ /**
3
+ * Check if the input is a book entry of the given type.
4
+ *
5
+ * @internal
6
+ */
7
+ export function isBookEntry(entry, entryType) {
8
+ return check.hasKey(entry, 'entryType') && entry.entryType === entryType;
9
+ }
@@ -0,0 +1,92 @@
1
+ import { type EmptyObject } from 'type-fest';
2
+ /**
3
+ * Adds a control to an element-book page.
4
+ *
5
+ * @category Internal
6
+ */
7
+ export type BookPageControl<ControlType extends BookPageControlType = BookPageControlType> = {
8
+ controlType: ControlType;
9
+ initValue: BookPageControlValueType[ControlType];
10
+ /** The name and label for the control. */
11
+ controlName: string;
12
+ } & (ControlType extends BookPageControlType.Dropdown ? {
13
+ options: string[];
14
+ } : EmptyObject);
15
+ /**
16
+ * Initialization options for an element-book page control.
17
+ *
18
+ * @category Internal
19
+ */
20
+ export type BookPageControlInit<ControlType extends BookPageControlType> = Omit<BookPageControl<ControlType>, 'controlName'>;
21
+ /**
22
+ * Checks and type guards that the input page control init is of the given type.
23
+ *
24
+ * @internal
25
+ */
26
+ export declare function isControlInitType<const SpecificControlType extends BookPageControlType>(controlInit: BookPageControlInit<any>, specificType: SpecificControlType): controlInit is BookPageControlInit<SpecificControlType>;
27
+ /**
28
+ * Define a page control. This doesn't do anything fancy (in fact it only returns the input) but it
29
+ * helps immensely with type inference.
30
+ *
31
+ * @category Main
32
+ */
33
+ export declare function definePageControl<const ControlType extends BookPageControlType>(controlInit: BookPageControlInit<ControlType>): BookPageControlInit<ControlType>;
34
+ /**
35
+ * Maps an object of user-defined controls to their initial values.
36
+ *
37
+ * @category Internal
38
+ */
39
+ export type ControlsToValues<ControlsInit extends BookPageControlsInitBase> = {
40
+ [ControlName in keyof ControlsInit]: ControlsInit[ControlName]['initValue'];
41
+ };
42
+ /**
43
+ * Base type for a arbitrary, user-defined object of page controls.
44
+ *
45
+ * @category Internal
46
+ */
47
+ export type BookPageControlsInitBase = Record<string, BookPageControlInit<BookPageControlType>>;
48
+ /**
49
+ * Base type for a arbitrary, user-defined object of page control values.
50
+ *
51
+ * @category Internal
52
+ */
53
+ export type BookPageControlsValues = ControlsToValues<BookPageControlsInitBase>;
54
+ /**
55
+ * All the supported page control types. One of these must be chosen when defining a page control.
56
+ *
57
+ * @category Main
58
+ */
59
+ export declare enum BookPageControlType {
60
+ Checkbox = "checkbox",
61
+ Color = "color",
62
+ Dropdown = "dropdown",
63
+ /** Hidden controls allow any values but they aren't displayed to the user for editing. */
64
+ Hidden = "hidden",
65
+ Number = "number",
66
+ Text = "text"
67
+ }
68
+ /**
69
+ * Specifies the default value for each page control type, as well as its type.
70
+ *
71
+ * @category Internal
72
+ */
73
+ export declare const controlValueTypes: {
74
+ checkbox: boolean;
75
+ color: string;
76
+ dropdown: string;
77
+ hidden: any;
78
+ number: number;
79
+ text: string;
80
+ };
81
+ /**
82
+ * Each page control type mapped to the type of their value.
83
+ *
84
+ * @category Internal
85
+ */
86
+ export type BookPageControlValueType = typeof controlValueTypes;
87
+ /**
88
+ * Checks that the given control init object is valid.
89
+ *
90
+ * @internal
91
+ */
92
+ export declare function checkControls(controlsInit: BookPageControlsInitBase | undefined, pageName: string): Error[];
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Checks and type guards that the input page control init is of the given type.
3
+ *
4
+ * @internal
5
+ */
6
+ export function isControlInitType(controlInit, specificType) {
7
+ return controlInit.controlType === specificType;
8
+ }
9
+ /**
10
+ * Define a page control. This doesn't do anything fancy (in fact it only returns the input) but it
11
+ * helps immensely with type inference.
12
+ *
13
+ * @category Main
14
+ */
15
+ export function definePageControl(controlInit) {
16
+ return controlInit;
17
+ }
18
+ /**
19
+ * All the supported page control types. One of these must be chosen when defining a page control.
20
+ *
21
+ * @category Main
22
+ */
23
+ export var BookPageControlType;
24
+ (function (BookPageControlType) {
25
+ BookPageControlType["Checkbox"] = "checkbox";
26
+ BookPageControlType["Color"] = "color";
27
+ BookPageControlType["Dropdown"] = "dropdown";
28
+ /** Hidden controls allow any values but they aren't displayed to the user for editing. */
29
+ BookPageControlType["Hidden"] = "hidden";
30
+ BookPageControlType["Number"] = "number";
31
+ BookPageControlType["Text"] = "text";
32
+ })(BookPageControlType || (BookPageControlType = {}));
33
+ const anySymbol = Symbol('any-type');
34
+ /**
35
+ * Specifies the default value for each page control type, as well as its type.
36
+ *
37
+ * @category Internal
38
+ */
39
+ export const controlValueTypes = {
40
+ [BookPageControlType.Checkbox]: false,
41
+ [BookPageControlType.Color]: '',
42
+ [BookPageControlType.Dropdown]: '',
43
+ [BookPageControlType.Hidden]: anySymbol,
44
+ [BookPageControlType.Number]: 0,
45
+ [BookPageControlType.Text]: '',
46
+ };
47
+ /**
48
+ * Checks that the given control init object is valid.
49
+ *
50
+ * @internal
51
+ */
52
+ export function checkControls(controlsInit, pageName) {
53
+ if (!controlsInit) {
54
+ return [];
55
+ }
56
+ const errors = [];
57
+ Object.entries(controlsInit).forEach(([controlName, controlEntry,]) => {
58
+ const expectedInitDefault = controlValueTypes[controlEntry.controlType];
59
+ if (expectedInitDefault === anySymbol) {
60
+ return;
61
+ }
62
+ if (typeof expectedInitDefault !== typeof controlEntry.initValue) {
63
+ errors.push(new Error(`Control '${controlName}' in page '${pageName}' has invalid initValue '${controlEntry.initValue}': expected initValue of type ${typeof expectedInitDefault} because the control is of type ${controlEntry.controlType}.`));
64
+ }
65
+ if (!controlName) {
66
+ errors.push(new Error(`'${pageName}' cannot have an empty control name.`));
67
+ }
68
+ });
69
+ return errors;
70
+ }
@@ -0,0 +1,63 @@
1
+ import { type Overwrite, type PartialWithUndefined, type SetOptionalAndNullable } from '@augment-vir/common';
2
+ import { type CSSResult, type HtmlInterpolation, type PropertyInitMapBase, type RenderParams, type TypedEvent } from 'element-vir';
3
+ import { type GlobalValues } from '../../../ui/elements/element-book-app/global-values.js';
4
+ import { type BaseBookEntry } from '../base-book-entry.js';
5
+ import { type BookEntryType } from '../book-entry-type.js';
6
+ import { type BookPageControlsInitBase, type ControlsToValues } from './book-page-controls.js';
7
+ /**
8
+ * An individual element-book page.
9
+ *
10
+ * @category Type
11
+ */
12
+ export type BookPage<GlobalValuesType extends GlobalValues = {}, ParentPage extends BookPage | undefined = any, ControlsInit extends BookPageControlsInitBase = BookPageControlsInitBase> = Overwrite<BaseBookEntry, {
13
+ /**
14
+ * The parent page of this page. If this page is meant to be at the top-level, set this to
15
+ * `undefined`.
16
+ */
17
+ parent: ParentPage;
18
+ entryType: BookEntryType.Page;
19
+ }> & {
20
+ controls: ControlsInit;
21
+ elementExamples: Record<string, BookElementExample>;
22
+ useVerticalExamples: boolean;
23
+ };
24
+ /**
25
+ * All parameters required for rendering an element-book page.
26
+ *
27
+ * @category Internal
28
+ */
29
+ export type BookPageExampleRenderParams<GlobalValuesType extends GlobalValues, ControlsInit extends BookPageControlsInitBase, State extends PropertyInitMapBase> = Pick<RenderParams<any, any, State, any, any, any, any, any>, 'state' | 'updateState'> & {
30
+ controls: ControlsToValues<ControlsInit> & GlobalValuesType;
31
+ };
32
+ /**
33
+ * An individual element example for an element-book page.
34
+ *
35
+ * @category Internal
36
+ */
37
+ export type BookElementExample<GlobalValuesType extends GlobalValues = {}, ControlsInit extends BookPageControlsInitBase = {}, State extends PropertyInitMapBase = {}> = Overwrite<BaseBookEntry, {
38
+ parent: BookPage | undefined;
39
+ entryType: BookEntryType.ElementExample;
40
+ isVertical: boolean;
41
+ /** Render the example. */
42
+ render: (renderParams: BookPageExampleRenderParams<GlobalValuesType, ControlsInit, State>) => HtmlInterpolation;
43
+ } & PartialWithUndefined<{
44
+ /**
45
+ * Initialize the state for this example. This is only called once, before the first render
46
+ * of the example.
47
+ */
48
+ state: () => State;
49
+ /** Specify which events this example should intercept (so the user can see them). */
50
+ showEvents: ReadonlyArray<string | TypedEvent>;
51
+ /**
52
+ * Style the element example. You can even use the :host selector to style this specific
53
+ * example's wrapper element!
54
+ */
55
+ styles: CSSResult;
56
+ }>>;
57
+ /**
58
+ * The properties that are necessary to initialize an element example. Missing properties will be
59
+ * filled in by the parent.
60
+ *
61
+ * @category Internal
62
+ */
63
+ export type BookElementExampleInit<GlobalValuesType extends GlobalValues, Controls extends BookPageControlsInitBase, State extends PropertyInitMapBase> = SetOptionalAndNullable<Omit<BookElementExample<GlobalValuesType, Controls, State>, 'entryType' | 'parent' | 'errors' | 'isVertical'>, 'descriptionParagraphs'>;
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
2
+ export {};
@@ -0,0 +1,32 @@
1
+ import { type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type BookTreeNode } from '../../book-tree/book-tree-node.js';
3
+ import { type BookPageControlsValues } from './book-page-controls.js';
4
+ /**
5
+ * Nested page controls.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export type ControlsWrapper = {
10
+ children: {
11
+ [Breadcrumb: string]: ControlsWrapper;
12
+ };
13
+ controls: BookPageControlsValues;
14
+ };
15
+ /**
16
+ * Find the controls at the given breadcrumbs.
17
+ *
18
+ * @category Internal
19
+ */
20
+ export declare function traverseControls(controlsWrapper: ControlsWrapper, fullUrlBreadcrumbs: ReadonlyArray<string>): BookPageControlsValues;
21
+ /**
22
+ * Add new controls at the given breadcrumbs.
23
+ *
24
+ * @category Internal
25
+ */
26
+ export declare function createNewControls(controlsWrapper: Readonly<ControlsWrapper>, breadcrumbsForNewValue: ReadonlyArray<string>, newValues: BookPageControlsValues): ControlsWrapper;
27
+ /**
28
+ * Add new controls from the given tree node.
29
+ *
30
+ * @category Internal
31
+ */
32
+ export declare function updateTreeControls(node: BookTreeNode, existingControls: PartialWithUndefined<ControlsWrapper> | undefined): ControlsWrapper;
@@ -0,0 +1,65 @@
1
+ import { mapObjectValues } from '@augment-vir/common';
2
+ import { isBookTreeNode } from '../../book-tree/book-tree.js';
3
+ import { BookEntryType } from '../book-entry-type.js';
4
+ /**
5
+ * Find the controls at the given breadcrumbs.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export function traverseControls(controlsWrapper, fullUrlBreadcrumbs) {
10
+ return traverseAndInsertNewControls(controlsWrapper, [
11
+ /** Empty string represents the breadcrumb for the root node */
12
+ '',
13
+ ...fullUrlBreadcrumbs,
14
+ ], undefined);
15
+ }
16
+ function traverseAndInsertNewControls(controlsWrapper, urlBreadcrumbs, newValues) {
17
+ const nextBreadcrumbs = urlBreadcrumbs.slice(1);
18
+ const nextBreadcrumb = nextBreadcrumbs[0];
19
+ /** If we're at the end of the breadcrumbs, then it's time to insert the new controls. */
20
+ if (!nextBreadcrumb && newValues) {
21
+ controlsWrapper.controls = newValues;
22
+ }
23
+ const childControlsWrapper = controlsWrapper.children[nextBreadcrumb || ''];
24
+ const childrenControls = childControlsWrapper &&
25
+ traverseAndInsertNewControls(childControlsWrapper, nextBreadcrumbs, newValues);
26
+ const allControls = {
27
+ ...controlsWrapper.controls,
28
+ ...childrenControls,
29
+ };
30
+ return allControls;
31
+ }
32
+ /**
33
+ * Add new controls at the given breadcrumbs.
34
+ *
35
+ * @category Internal
36
+ */
37
+ export function createNewControls(controlsWrapper, breadcrumbsForNewValue, newValues) {
38
+ const newControls = { ...controlsWrapper };
39
+ traverseAndInsertNewControls(newControls, [
40
+ /** Empty string represents the breadcrumb for the root node */
41
+ '',
42
+ ...breadcrumbsForNewValue,
43
+ ], newValues);
44
+ return newControls;
45
+ }
46
+ /**
47
+ * Add new controls from the given tree node.
48
+ *
49
+ * @category Internal
50
+ */
51
+ export function updateTreeControls(node, existingControls) {
52
+ const controls = existingControls?.controls ||
53
+ (isBookTreeNode(node, BookEntryType.Page)
54
+ ? mapObjectValues(node.entry.controls, (name, setup) => {
55
+ return setup.initValue;
56
+ })
57
+ : {});
58
+ const controlsWrapper = {
59
+ children: mapObjectValues(node.children, (childName, childTreeNode) => {
60
+ return updateTreeControls(childTreeNode, existingControls?.children?.[childTreeNode.urlBreadcrumb]);
61
+ }),
62
+ controls,
63
+ };
64
+ return controlsWrapper;
65
+ }
@@ -0,0 +1,58 @@
1
+ import { type SetOptionalAndNullable } from '@augment-vir/common';
2
+ import { type PropertyInitMapBase } from 'element-vir';
3
+ import { type EmptyObject } from 'type-fest';
4
+ import { type GlobalValues } from '../../../ui/elements/element-book-app/global-values.js';
5
+ import { type InfiniteRecursionLimiter } from '../../../util/type.js';
6
+ import { type BookPageControlsInitBase } from './book-page-controls.js';
7
+ import { type BookElementExampleInit, type BookPage } from './book-page.js';
8
+ /**
9
+ * The callback type for a book page definition's `defineExample` callback.
10
+ *
11
+ * @category Internal
12
+ */
13
+ export type DefineExampleCallback<GlobalValuesType extends GlobalValues = {}, ControlsInit extends BookPageControlsInitBase = BookPageControlsInitBase> = <State extends PropertyInitMapBase>(exampleInit: BookElementExampleInit<GlobalValuesType, ControlsInit, State>) => void;
14
+ /**
15
+ * Used for `defineExamples` in a book page's init.
16
+ *
17
+ * @category Internal
18
+ */
19
+ export type ElementExamplesDefiner<GlobalValuesType extends GlobalValues = {}, ControlsInit extends BookPageControlsInitBase = BookPageControlsInitBase> = (params: {
20
+ defineExample: DefineExampleCallback<GlobalValuesType, ControlsInit>;
21
+ }) => void;
22
+ /**
23
+ * Collapses all element-book control inits into a single flag object.
24
+ *
25
+ * @category Internal
26
+ */
27
+ export type CollapseControlsInit<ParentPage extends BookPage | undefined, CurrentControlsInit extends BookPageControlsInitBase,
28
+ /** Prevent infinite recursion TypeScript errors. */
29
+ RecursionDepth = InfiniteRecursionLimiter> = CurrentControlsInit & (RecursionDepth extends [any, ...infer RemainingDepth] ? ParentPage extends BookPage<infer GlobalValuesType, infer GrandParentPage, infer ParentControls> ? CollapseControlsInit<GrandParentPage, ParentControls, RemainingDepth> : EmptyObject : EmptyObject);
30
+ /**
31
+ * Collapses all element-book global values into a single flag object.
32
+ *
33
+ * @category Internal
34
+ */
35
+ export type CollapseGlobalValuesType<ParentPage extends BookPage | undefined, GlobalValuesType extends GlobalValues,
36
+ /** Prevent infinite recursion TypeScript errors. */
37
+ RecursionDepth = InfiniteRecursionLimiter> = GlobalValuesType & (RecursionDepth extends [any, ...infer RemainingDepth] ? ParentPage extends BookPage<infer GlobalValuesType, infer GrandParentPage, infer ParentControls> ? CollapseGlobalValuesType<GrandParentPage, GlobalValuesType, RemainingDepth> : EmptyObject : EmptyObject);
38
+ /**
39
+ * The parameters for initializing a new element-book page.
40
+ *
41
+ * @category Type
42
+ */
43
+ export type BookPageInit<GlobalValuesType extends GlobalValues, ParentPage extends BookPage | undefined, CurrentControlsInit extends BookPageControlsInitBase> = SetOptionalAndNullable<Omit<BookPage<any, ParentPage, CurrentControlsInit>, 'entryType' | 'elementExamples' | 'errors'>, 'controls' | 'descriptionParagraphs' | 'useVerticalExamples'> & {
44
+ defineExamples?: ElementExamplesDefiner<CollapseGlobalValuesType<ParentPage, GlobalValuesType>, CollapseControlsInit<ParentPage, CurrentControlsInit>> | undefined;
45
+ };
46
+ /**
47
+ * A variant of {@link defineBookPage} that allows you specify what the expected global element-book
48
+ * values are for the page that you are defining.
49
+ *
50
+ * @category Main
51
+ */
52
+ export declare function defineBookPageWithGlobals<const GlobalValuesType extends GlobalValues = {}>(): <const ParentPage extends BookPage | undefined = undefined, const ControlsInit extends BookPageControlsInitBase = {}>(pageInit: BookPageInit<GlobalValuesType, ParentPage, ControlsInit>) => BookPage<GlobalValuesType, ParentPage, ControlsInit>;
53
+ /**
54
+ * Define an element-book page. This is how you create new entries for your element-book instance.
55
+ *
56
+ * @category Main
57
+ */
58
+ export declare function defineBookPage<const GlobalValuesType extends GlobalValues = {}, const ParentPage extends BookPage | undefined = undefined, const ControlsInit extends BookPageControlsInitBase = {}>(pageInit: BookPageInit<GlobalValuesType, ParentPage, ControlsInit>): BookPage<GlobalValuesType, ParentPage, ControlsInit>;
@@ -0,0 +1,52 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
2
+ import { check } from '@augment-vir/assert';
3
+ import { BookEntryType } from '../book-entry-type.js';
4
+ import { titleToUrlBreadcrumb } from '../url-breadcrumbs.js';
5
+ /**
6
+ * A variant of {@link defineBookPage} that allows you specify what the expected global element-book
7
+ * values are for the page that you are defining.
8
+ *
9
+ * @category Main
10
+ */
11
+ export function defineBookPageWithGlobals() {
12
+ return (pageInit) => {
13
+ return defineBookPage(pageInit);
14
+ };
15
+ }
16
+ /**
17
+ * Define an element-book page. This is how you create new entries for your element-book instance.
18
+ *
19
+ * @category Main
20
+ */
21
+ export function defineBookPage(pageInit) {
22
+ const page = {
23
+ ...pageInit,
24
+ entryType: BookEntryType.Page,
25
+ useVerticalExamples: !!pageInit.useVerticalExamples,
26
+ elementExamples: {},
27
+ descriptionParagraphs: pageInit.descriptionParagraphs ?? [],
28
+ controls: pageInit.controls ?? {},
29
+ errors: [],
30
+ };
31
+ const alreadyTakenElementExampleNames = new Set();
32
+ if (pageInit.defineExamples) {
33
+ pageInit.defineExamples({
34
+ defineExample(elementExampleInit) {
35
+ const newExample = {
36
+ ...elementExampleInit,
37
+ isVertical: page.useVerticalExamples,
38
+ entryType: BookEntryType.ElementExample,
39
+ parent: page,
40
+ descriptionParagraphs: elementExampleInit.descriptionParagraphs ?? [],
41
+ errors: [
42
+ alreadyTakenElementExampleNames.has(elementExampleInit.title) &&
43
+ new Error(`Example title '${elementExampleInit.title}' in page '${pageInit.title}' is already taken.`),
44
+ ].filter(check.isTruthy),
45
+ };
46
+ alreadyTakenElementExampleNames.add(elementExampleInit.title);
47
+ page.elementExamples[titleToUrlBreadcrumb(newExample.title)] = newExample;
48
+ },
49
+ });
50
+ }
51
+ return page;
52
+ }
@@ -0,0 +1,12 @@
1
+ import { type Overwrite } from '@augment-vir/common';
2
+ import { type BaseBookEntry } from './base-book-entry.js';
3
+ import { type BookEntryType } from './book-entry-type.js';
4
+ /**
5
+ * The root of a book tree.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export type BookRoot = Overwrite<BaseBookEntry, {
10
+ entryType: BookEntryType.Root;
11
+ parent: undefined;
12
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { type BookEntry } from './book-entry.js';
2
+ /**
3
+ * Create a list of URL breadcrumbs for the given element-book entry.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare function listUrlBreadcrumbs(entry: BookEntry, includeSelf: boolean): string[];
8
+ /**
9
+ * Convert an element-book entry's title to a URL-safe breadcrumb title.
10
+ *
11
+ * @internal
12
+ */
13
+ export declare function titleToUrlBreadcrumb(title: string): string;
14
+ /**
15
+ * Check if a full list of URL breadcrumbs (`searchIn`) starts with the subset list of URL
16
+ * breadcrumbs (`searchFor`).
17
+ *
18
+ * @internal
19
+ */
20
+ export declare function doBreadcrumbsStartWith({ searchFor, searchIn, }: {
21
+ searchIn: ReadonlyArray<string>;
22
+ searchFor: ReadonlyArray<string>;
23
+ }): boolean;
@@ -1,48 +1,39 @@
1
- import {collapseWhiteSpace} from '@augment-vir/common';
2
- import {type BookEntry} from './book-entry.js';
3
-
1
+ import { collapseWhiteSpace } from '@augment-vir/common';
4
2
  /**
5
3
  * Create a list of URL breadcrumbs for the given element-book entry.
6
4
  *
7
5
  * @internal
8
6
  */
9
- export function listUrlBreadcrumbs(entry: BookEntry, includeSelf: boolean): string[] {
7
+ export function listUrlBreadcrumbs(entry, includeSelf) {
10
8
  const entryBreadcrumb = titleToUrlBreadcrumb(entry.title);
11
-
12
9
  if (entry.parent) {
13
10
  return [
14
11
  ...listUrlBreadcrumbs(entry.parent, false),
15
12
  titleToUrlBreadcrumb(entry.parent.title),
16
13
  ].concat(includeSelf ? [entryBreadcrumb] : []);
17
- } else if (includeSelf) {
14
+ }
15
+ else if (includeSelf) {
18
16
  return [entryBreadcrumb];
19
- } else {
17
+ }
18
+ else {
20
19
  return [];
21
20
  }
22
21
  }
23
-
24
22
  /**
25
23
  * Convert an element-book entry's title to a URL-safe breadcrumb title.
26
24
  *
27
25
  * @internal
28
26
  */
29
- export function titleToUrlBreadcrumb(title: string): string {
27
+ export function titleToUrlBreadcrumb(title) {
30
28
  return collapseWhiteSpace(title).toLowerCase().replaceAll(/\s/g, '-');
31
29
  }
32
-
33
30
  /**
34
31
  * Check if a full list of URL breadcrumbs (`searchIn`) starts with the subset list of URL
35
32
  * breadcrumbs (`searchFor`).
36
33
  *
37
34
  * @internal
38
35
  */
39
- export function doBreadcrumbsStartWith({
40
- searchFor,
41
- searchIn,
42
- }: {
43
- searchIn: ReadonlyArray<string>;
44
- searchFor: ReadonlyArray<string>;
45
- }): boolean {
36
+ export function doBreadcrumbsStartWith({ searchFor, searchIn, }) {
46
37
  return searchFor.every((breadcrumb, index) => {
47
38
  return searchIn[index] === breadcrumb;
48
39
  });
@@ -0,0 +1,3 @@
1
+ import { BookEntryType } from './book-entry-type.js';
2
+ import { type BookEntry } from './book-entry.js';
3
+ export declare const bookEntryVerifiers: { [EntryType in BookEntryType]: (entry: BookEntry) => Error[]; };
@@ -1,8 +1,6 @@
1
- import {check} from '@augment-vir/assert';
2
- import {BookEntryType} from './book-entry-type.js';
3
- import {type BookEntry} from './book-entry.js';
4
- import {checkControls} from './book-page/book-page-controls.js';
5
-
1
+ import { check } from '@augment-vir/assert';
2
+ import { BookEntryType } from './book-entry-type.js';
3
+ import { checkControls } from './book-page/book-page-controls.js';
6
4
  export const bookEntryVerifiers = {
7
5
  [BookEntryType.ElementExample]: () => {
8
6
  // currently all element example checking happens on page definition
@@ -17,8 +15,4 @@ export const bookEntryVerifiers = {
17
15
  [BookEntryType.Root]: () => {
18
16
  return [];
19
17
  },
20
- } satisfies {
21
- [EntryType in BookEntryType]: (entry: Extract<BookEntry, {entryType: EntryType}>) => Error[];
22
- } as {
23
- [EntryType in BookEntryType]: (entry: BookEntry) => Error[];
24
18
  };