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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-book",
3
- "version": "26.12.0",
3
+ "version": "26.12.1",
4
4
  "keywords": [
5
5
  "book",
6
6
  "design system",
@@ -29,9 +29,9 @@
29
29
  },
30
30
  "sideEffects": false,
31
31
  "type": "module",
32
- "main": "src/index.ts",
33
- "module": "src/index.ts",
34
- "types": "src/index.ts",
32
+ "main": "dist/index.js",
33
+ "module": "dist/index.js",
34
+ "types": "dist/index.d.ts",
35
35
  "scripts": {
36
36
  "build": "npm run docs",
37
37
  "compile": "virmator compile",
@@ -56,7 +56,7 @@
56
56
  "@web/test-runner-commands": "^0.9.0",
57
57
  "@web/test-runner-playwright": "^0.11.1",
58
58
  "@web/test-runner-visual-regression": "^0.10.0",
59
- "element-vir": "^26.12.0",
59
+ "element-vir": "^26.12.1",
60
60
  "istanbul-smart-text-reporter": "^1.1.5",
61
61
  "markdown-code-example-inserter": "^3.0.3",
62
62
  "type-fest": "^5.3.1",
@@ -1,23 +0,0 @@
1
- import {check} from '@augment-vir/assert';
2
- import {type BookEntryType} from './book-entry-type.js';
3
- import {type BookElementExample, type BookPage} from './book-page/book-page.js';
4
- import {type BookRoot} from './book-root.js';
5
-
6
- /**
7
- * All possible book entries.
8
- *
9
- * @category Internal
10
- */
11
- export type BookEntry = BookPage | BookRoot | BookElementExample;
12
-
13
- /**
14
- * Check if the input is a book entry of the given type.
15
- *
16
- * @internal
17
- */
18
- export function isBookEntry<const SpecificType extends BookEntryType>(
19
- entry: unknown,
20
- entryType: SpecificType,
21
- ): entry is Extract<BookEntry, {entryType: SpecificType}> {
22
- return check.hasKey(entry, 'entryType') && entry.entryType === entryType;
23
- }
@@ -1,159 +0,0 @@
1
- import {type EmptyObject} from 'type-fest';
2
-
3
- /**
4
- * Adds a control to an element-book page.
5
- *
6
- * @category Internal
7
- */
8
- export type BookPageControl<ControlType extends BookPageControlType = BookPageControlType> = {
9
- controlType: ControlType;
10
- initValue: BookPageControlValueType[ControlType];
11
- /** The name and label for the control. */
12
- controlName: string;
13
- } & (ControlType extends BookPageControlType.Dropdown
14
- ? {
15
- options: string[];
16
- }
17
- : EmptyObject);
18
-
19
- /**
20
- * Initialization options for an element-book page control.
21
- *
22
- * @category Internal
23
- */
24
- export type BookPageControlInit<ControlType extends BookPageControlType> = Omit<
25
- BookPageControl<ControlType>,
26
- // 'controlName' will be inserted later by the page
27
- 'controlName'
28
- >;
29
-
30
- /**
31
- * Checks and type guards that the input page control init is of the given type.
32
- *
33
- * @internal
34
- */
35
- export function isControlInitType<const SpecificControlType extends BookPageControlType>(
36
- controlInit: BookPageControlInit<any>,
37
- specificType: SpecificControlType,
38
- ): controlInit is BookPageControlInit<SpecificControlType> {
39
- return controlInit.controlType === specificType;
40
- }
41
-
42
- /**
43
- * Define a page control. This doesn't do anything fancy (in fact it only returns the input) but it
44
- * helps immensely with type inference.
45
- *
46
- * @category Main
47
- */
48
- export function definePageControl<const ControlType extends BookPageControlType>(
49
- controlInit: BookPageControlInit<ControlType>,
50
- ) {
51
- return controlInit;
52
- }
53
-
54
- /**
55
- * Maps an object of user-defined controls to their initial values.
56
- *
57
- * @category Internal
58
- */
59
- export type ControlsToValues<ControlsInit extends BookPageControlsInitBase> = {
60
- [ControlName in keyof ControlsInit]: ControlsInit[ControlName]['initValue'];
61
- };
62
-
63
- /**
64
- * Base type for a arbitrary, user-defined object of page controls.
65
- *
66
- * @category Internal
67
- */
68
- export type BookPageControlsInitBase = Record<string, BookPageControlInit<BookPageControlType>>;
69
-
70
- /**
71
- * Base type for a arbitrary, user-defined object of page control values.
72
- *
73
- * @category Internal
74
- */
75
- export type BookPageControlsValues = ControlsToValues<BookPageControlsInitBase>;
76
-
77
- /**
78
- * All the supported page control types. One of these must be chosen when defining a page control.
79
- *
80
- * @category Main
81
- */
82
- export enum BookPageControlType {
83
- Checkbox = 'checkbox',
84
- Color = 'color',
85
- Dropdown = 'dropdown',
86
- /** Hidden controls allow any values but they aren't displayed to the user for editing. */
87
- Hidden = 'hidden',
88
- Number = 'number',
89
- Text = 'text',
90
- }
91
-
92
- const anySymbol = Symbol('any-type');
93
-
94
- /**
95
- * Specifies the default value for each page control type, as well as its type.
96
- *
97
- * @category Internal
98
- */
99
- export const controlValueTypes = {
100
- [BookPageControlType.Checkbox]: false,
101
- [BookPageControlType.Color]: '',
102
- [BookPageControlType.Dropdown]: '',
103
- [BookPageControlType.Hidden]: anySymbol as any,
104
- [BookPageControlType.Number]: 0,
105
- [BookPageControlType.Text]: '',
106
- } satisfies Readonly<Record<BookPageControlType, any>>;
107
-
108
- /**
109
- * Each page control type mapped to the type of their value.
110
- *
111
- * @category Internal
112
- */
113
- export type BookPageControlValueType = typeof controlValueTypes;
114
-
115
- /**
116
- * Checks that the given control init object is valid.
117
- *
118
- * @internal
119
- */
120
- export function checkControls(
121
- controlsInit: BookPageControlsInitBase | undefined,
122
- pageName: string,
123
- ): Error[] {
124
- if (!controlsInit) {
125
- return [];
126
- }
127
-
128
- const errors: Error[] = [];
129
-
130
- Object.entries(controlsInit).forEach(
131
- ([
132
- controlName,
133
- controlEntry,
134
- ]) => {
135
- const expectedInitDefault = controlValueTypes[controlEntry.controlType];
136
-
137
- if (expectedInitDefault === anySymbol) {
138
- return;
139
- }
140
-
141
- if (typeof expectedInitDefault !== typeof controlEntry.initValue) {
142
- errors.push(
143
- new Error(
144
- `Control '${controlName}' in page '${pageName}' has invalid initValue '${
145
- controlEntry.initValue
146
- }': expected initValue of type ${typeof expectedInitDefault} because the control is of type ${
147
- controlEntry.controlType
148
- }.`,
149
- ),
150
- );
151
- }
152
- if (!controlName) {
153
- errors.push(new Error(`'${pageName}' cannot have an empty control name.`));
154
- }
155
- },
156
- );
157
-
158
- return errors;
159
- }
@@ -1,110 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-object-type */
2
-
3
- import {
4
- type Overwrite,
5
- type PartialWithUndefined,
6
- type SetOptionalAndNullable,
7
- } from '@augment-vir/common';
8
- import {
9
- type CSSResult,
10
- type HtmlInterpolation,
11
- type PropertyInitMapBase,
12
- type RenderParams,
13
- type TypedEvent,
14
- } from 'element-vir';
15
- import {type GlobalValues} from '../../../ui/elements/element-book-app/global-values.js';
16
- import {type BaseBookEntry} from '../base-book-entry.js';
17
- import {type BookEntryType} from '../book-entry-type.js';
18
- import {type BookPageControlsInitBase, type ControlsToValues} from './book-page-controls.js';
19
-
20
- /**
21
- * An individual element-book page.
22
- *
23
- * @category Type
24
- */
25
- export type BookPage<
26
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
- GlobalValuesType extends GlobalValues = {},
28
- ParentPage extends BookPage | undefined = any,
29
- ControlsInit extends BookPageControlsInitBase = BookPageControlsInitBase,
30
- > = Overwrite<
31
- BaseBookEntry,
32
- {
33
- /**
34
- * The parent page of this page. If this page is meant to be at the top-level, set this to
35
- * `undefined`.
36
- */
37
- parent: ParentPage;
38
- entryType: BookEntryType.Page;
39
- }
40
- > & {
41
- controls: ControlsInit;
42
- elementExamples: Record<string, BookElementExample>;
43
- useVerticalExamples: boolean;
44
- };
45
-
46
- /**
47
- * All parameters required for rendering an element-book page.
48
- *
49
- * @category Internal
50
- */
51
- export type BookPageExampleRenderParams<
52
- GlobalValuesType extends GlobalValues,
53
- ControlsInit extends BookPageControlsInitBase,
54
- State extends PropertyInitMapBase,
55
- > = Pick<RenderParams<any, any, State, any, any, any, any, any>, 'state' | 'updateState'> & {
56
- controls: ControlsToValues<ControlsInit> & GlobalValuesType;
57
- };
58
-
59
- /**
60
- * An individual element example for an element-book page.
61
- *
62
- * @category Internal
63
- */
64
- export type BookElementExample<
65
- GlobalValuesType extends GlobalValues = {},
66
- ControlsInit extends BookPageControlsInitBase = {},
67
- State extends PropertyInitMapBase = {},
68
- > = Overwrite<
69
- BaseBookEntry,
70
- {
71
- parent: BookPage | undefined;
72
- entryType: BookEntryType.ElementExample;
73
- isVertical: boolean;
74
- /** Render the example. */
75
- render: (
76
- renderParams: BookPageExampleRenderParams<GlobalValuesType, ControlsInit, State>,
77
- ) => HtmlInterpolation;
78
- } & PartialWithUndefined<{
79
- /**
80
- * Initialize the state for this example. This is only called once, before the first render
81
- * of the example.
82
- */
83
- state: () => State;
84
- /** Specify which events this example should intercept (so the user can see them). */
85
- showEvents: ReadonlyArray<string | TypedEvent>;
86
- /**
87
- * Style the element example. You can even use the :host selector to style this specific
88
- * example's wrapper element!
89
- */
90
- styles: CSSResult;
91
- }>
92
- >;
93
-
94
- /**
95
- * The properties that are necessary to initialize an element example. Missing properties will be
96
- * filled in by the parent.
97
- *
98
- * @category Internal
99
- */
100
- export type BookElementExampleInit<
101
- GlobalValuesType extends GlobalValues,
102
- Controls extends BookPageControlsInitBase,
103
- State extends PropertyInitMapBase,
104
- > = SetOptionalAndNullable<
105
- Omit<
106
- BookElementExample<GlobalValuesType, Controls, State>,
107
- 'entryType' | 'parent' | 'errors' | 'isVertical'
108
- >,
109
- 'descriptionParagraphs'
110
- >;
@@ -1,119 +0,0 @@
1
- import {type PartialWithUndefined, mapObjectValues} from '@augment-vir/common';
2
- import {type BookTreeNode} from '../../book-tree/book-tree-node.js';
3
- import {isBookTreeNode} from '../../book-tree/book-tree.js';
4
- import {BookEntryType} from '../book-entry-type.js';
5
- import {type BookPageControlsValues} from './book-page-controls.js';
6
-
7
- /**
8
- * Nested page controls.
9
- *
10
- * @category Internal
11
- */
12
- export type ControlsWrapper = {
13
- children: {
14
- [Breadcrumb: string]: ControlsWrapper;
15
- };
16
- controls: BookPageControlsValues;
17
- };
18
-
19
- /**
20
- * Find the controls at the given breadcrumbs.
21
- *
22
- * @category Internal
23
- */
24
- export function traverseControls(
25
- controlsWrapper: ControlsWrapper,
26
- fullUrlBreadcrumbs: ReadonlyArray<string>,
27
- ): BookPageControlsValues {
28
- return traverseAndInsertNewControls(
29
- controlsWrapper,
30
- [
31
- /** Empty string represents the breadcrumb for the root node */
32
- '',
33
- ...fullUrlBreadcrumbs,
34
- ],
35
- undefined,
36
- );
37
- }
38
-
39
- function traverseAndInsertNewControls(
40
- controlsWrapper: ControlsWrapper,
41
- urlBreadcrumbs: ReadonlyArray<string>,
42
- newValues: BookPageControlsValues | undefined,
43
- ): BookPageControlsValues {
44
- const nextBreadcrumbs = urlBreadcrumbs.slice(1);
45
- const nextBreadcrumb = nextBreadcrumbs[0];
46
- /** If we're at the end of the breadcrumbs, then it's time to insert the new controls. */
47
- if (!nextBreadcrumb && newValues) {
48
- controlsWrapper.controls = newValues;
49
- }
50
-
51
- const childControlsWrapper: ControlsWrapper | undefined =
52
- controlsWrapper.children[nextBreadcrumb || ''];
53
-
54
- const childrenControls =
55
- childControlsWrapper &&
56
- traverseAndInsertNewControls(childControlsWrapper, nextBreadcrumbs, newValues);
57
-
58
- const allControls = {
59
- ...controlsWrapper.controls,
60
- ...childrenControls,
61
- };
62
-
63
- return allControls;
64
- }
65
-
66
- /**
67
- * Add new controls at the given breadcrumbs.
68
- *
69
- * @category Internal
70
- */
71
- export function createNewControls(
72
- controlsWrapper: Readonly<ControlsWrapper>,
73
- breadcrumbsForNewValue: ReadonlyArray<string>,
74
- newValues: BookPageControlsValues,
75
- ): ControlsWrapper {
76
- const newControls = {...controlsWrapper};
77
-
78
- traverseAndInsertNewControls(
79
- newControls,
80
- [
81
- /** Empty string represents the breadcrumb for the root node */
82
- '',
83
- ...breadcrumbsForNewValue,
84
- ],
85
- newValues,
86
- );
87
-
88
- return newControls;
89
- }
90
-
91
- /**
92
- * Add new controls from the given tree node.
93
- *
94
- * @category Internal
95
- */
96
- export function updateTreeControls(
97
- node: BookTreeNode,
98
- existingControls: PartialWithUndefined<ControlsWrapper> | undefined,
99
- ): ControlsWrapper {
100
- const controls =
101
- existingControls?.controls ||
102
- (isBookTreeNode(node, BookEntryType.Page)
103
- ? mapObjectValues(node.entry.controls, (name, setup) => {
104
- return setup.initValue;
105
- })
106
- : {});
107
-
108
- const controlsWrapper: ControlsWrapper = {
109
- children: mapObjectValues(node.children, (childName, childTreeNode): ControlsWrapper => {
110
- return updateTreeControls(
111
- childTreeNode,
112
- existingControls?.children?.[childTreeNode.urlBreadcrumb],
113
- );
114
- }),
115
- controls,
116
- };
117
-
118
- return controlsWrapper;
119
- }
@@ -1,171 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-object-type */
2
-
3
- import {check} from '@augment-vir/assert';
4
- import {type SetOptionalAndNullable, type Values} from '@augment-vir/common';
5
- import {type PropertyInitMapBase} from 'element-vir';
6
- import {type EmptyObject} from 'type-fest';
7
- import {type GlobalValues} from '../../../ui/elements/element-book-app/global-values.js';
8
- import {type InfiniteRecursionLimiter} from '../../../util/type.js';
9
- import {BookEntryType} from '../book-entry-type.js';
10
- import {titleToUrlBreadcrumb} from '../url-breadcrumbs.js';
11
- import {type BookPageControlsInitBase} from './book-page-controls.js';
12
- import {type BookElementExample, type BookElementExampleInit, type BookPage} from './book-page.js';
13
-
14
- /**
15
- * The callback type for a book page definition's `defineExample` callback.
16
- *
17
- * @category Internal
18
- */
19
- export type DefineExampleCallback<
20
- GlobalValuesType extends GlobalValues = {},
21
- ControlsInit extends BookPageControlsInitBase = BookPageControlsInitBase,
22
- > = <State extends PropertyInitMapBase>(
23
- exampleInit: BookElementExampleInit<GlobalValuesType, ControlsInit, State>,
24
- ) => void;
25
-
26
- /**
27
- * Used for `defineExamples` in a book page's init.
28
- *
29
- * @category Internal
30
- */
31
- export type ElementExamplesDefiner<
32
- GlobalValuesType extends GlobalValues = {},
33
- ControlsInit extends BookPageControlsInitBase = BookPageControlsInitBase,
34
- > = (params: {defineExample: DefineExampleCallback<GlobalValuesType, ControlsInit>}) => void;
35
-
36
- /**
37
- * Collapses all element-book control inits into a single flag object.
38
- *
39
- * @category Internal
40
- */
41
- export type CollapseControlsInit<
42
- ParentPage extends BookPage | undefined,
43
- CurrentControlsInit extends BookPageControlsInitBase,
44
- /** Prevent infinite recursion TypeScript errors. */
45
- RecursionDepth = InfiniteRecursionLimiter,
46
- > = CurrentControlsInit &
47
- (RecursionDepth extends [any, ...infer RemainingDepth]
48
- ? ParentPage extends BookPage<
49
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
50
- infer GlobalValuesType,
51
- infer GrandParentPage,
52
- infer ParentControls
53
- >
54
- ? CollapseControlsInit<GrandParentPage, ParentControls, RemainingDepth>
55
- : EmptyObject
56
- : EmptyObject);
57
-
58
- /**
59
- * Collapses all element-book global values into a single flag object.
60
- *
61
- * @category Internal
62
- */
63
- export type CollapseGlobalValuesType<
64
- ParentPage extends BookPage | undefined,
65
- GlobalValuesType extends GlobalValues,
66
- /** Prevent infinite recursion TypeScript errors. */
67
- RecursionDepth = InfiniteRecursionLimiter,
68
- > = GlobalValuesType &
69
- (RecursionDepth extends [any, ...infer RemainingDepth]
70
- ? ParentPage extends BookPage<
71
- infer GlobalValuesType,
72
- infer GrandParentPage,
73
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
- infer ParentControls
75
- >
76
- ? CollapseGlobalValuesType<GrandParentPage, GlobalValuesType, RemainingDepth>
77
- : EmptyObject
78
- : EmptyObject);
79
-
80
- /**
81
- * The parameters for initializing a new element-book page.
82
- *
83
- * @category Type
84
- */
85
- export type BookPageInit<
86
- GlobalValuesType extends GlobalValues,
87
- ParentPage extends BookPage | undefined,
88
- CurrentControlsInit extends BookPageControlsInitBase,
89
- > = SetOptionalAndNullable<
90
- Omit<
91
- BookPage<any, ParentPage, CurrentControlsInit>,
92
- 'entryType' | 'elementExamples' | 'errors'
93
- >,
94
- 'controls' | 'descriptionParagraphs' | 'useVerticalExamples'
95
- > & {
96
- defineExamples?:
97
- | ElementExamplesDefiner<
98
- CollapseGlobalValuesType<ParentPage, GlobalValuesType>,
99
- CollapseControlsInit<ParentPage, CurrentControlsInit>
100
- >
101
- | undefined;
102
- };
103
-
104
- /**
105
- * A variant of {@link defineBookPage} that allows you specify what the expected global element-book
106
- * values are for the page that you are defining.
107
- *
108
- * @category Main
109
- */
110
- export function defineBookPageWithGlobals<const GlobalValuesType extends GlobalValues = {}>() {
111
- return <
112
- const ParentPage extends BookPage | undefined = undefined,
113
- const ControlsInit extends BookPageControlsInitBase = {},
114
- >(
115
- pageInit: BookPageInit<GlobalValuesType, ParentPage, ControlsInit>,
116
- ): BookPage<GlobalValuesType, ParentPage, ControlsInit> => {
117
- return defineBookPage(pageInit);
118
- };
119
- }
120
-
121
- /**
122
- * Define an element-book page. This is how you create new entries for your element-book instance.
123
- *
124
- * @category Main
125
- */
126
- export function defineBookPage<
127
- const GlobalValuesType extends GlobalValues = {},
128
- const ParentPage extends BookPage | undefined = undefined,
129
- const ControlsInit extends BookPageControlsInitBase = {},
130
- >(
131
- pageInit: BookPageInit<GlobalValuesType, ParentPage, ControlsInit>,
132
- ): BookPage<GlobalValuesType, ParentPage, ControlsInit> {
133
- const page: BookPage<GlobalValuesType, ParentPage, ControlsInit> = {
134
- ...pageInit,
135
- entryType: BookEntryType.Page,
136
- useVerticalExamples: !!pageInit.useVerticalExamples,
137
- elementExamples: {},
138
- descriptionParagraphs: pageInit.descriptionParagraphs ?? [],
139
- controls: pageInit.controls ?? ({} as ControlsInit),
140
- errors: [],
141
- };
142
-
143
- const alreadyTakenElementExampleNames = new Set<string>();
144
-
145
- if (pageInit.defineExamples) {
146
- pageInit.defineExamples({
147
- defineExample(elementExampleInit) {
148
- const newExample: BookElementExample<any, any, any> = {
149
- ...elementExampleInit,
150
- isVertical: page.useVerticalExamples,
151
- entryType: BookEntryType.ElementExample,
152
- parent: page,
153
- descriptionParagraphs: elementExampleInit.descriptionParagraphs ?? [],
154
- errors: [
155
- alreadyTakenElementExampleNames.has(elementExampleInit.title) &&
156
- new Error(
157
- `Example title '${elementExampleInit.title}' in page '${pageInit.title}' is already taken.`,
158
- ),
159
- ].filter(check.isTruthy),
160
- };
161
- alreadyTakenElementExampleNames.add(elementExampleInit.title);
162
-
163
- page.elementExamples[titleToUrlBreadcrumb(newExample.title)] = newExample as Values<
164
- (typeof page)['elementExamples']
165
- >;
166
- },
167
- });
168
- }
169
-
170
- return page;
171
- }
@@ -1,16 +0,0 @@
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
- /**
6
- * The root of a book tree.
7
- *
8
- * @category Internal
9
- */
10
- export type BookRoot = Overwrite<
11
- BaseBookEntry,
12
- {
13
- entryType: BookEntryType.Root;
14
- parent: undefined;
15
- }
16
- >;