element-book 26.13.1 → 26.14.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.
@@ -1,4 +1,4 @@
1
- import { type EmptyObject } from 'type-fest';
1
+ import { type HtmlInterpolation } from 'element-vir';
2
2
  /**
3
3
  * Adds a control to an element-book page.
4
4
  *
@@ -6,12 +6,20 @@ import { type EmptyObject } from 'type-fest';
6
6
  */
7
7
  export type BookPageControl<ControlType extends BookPageControlType = BookPageControlType> = {
8
8
  controlType: ControlType;
9
- initValue: BookPageControlValueType[ControlType];
10
9
  /** The name and label for the control. */
11
10
  controlName: string;
12
- } & (ControlType extends BookPageControlType.Dropdown ? {
11
+ } & (ControlType extends BookPageControlType.Custom ? {
12
+ /** Custom HTML template to render for this control. */
13
+ content: HtmlInterpolation;
14
+ initValue?: never;
15
+ } : {
16
+ initValue: BookPageControlValueType[ControlType];
17
+ content?: never;
18
+ }) & (ControlType extends BookPageControlType.Dropdown ? {
13
19
  options: string[];
14
- } : EmptyObject);
20
+ } : {
21
+ options?: never;
22
+ });
15
23
  /**
16
24
  * Initialization options for an element-book page control.
17
25
  *
@@ -23,7 +31,7 @@ export type BookPageControlInit<ControlType extends BookPageControlType> = Omit<
23
31
  *
24
32
  * @category Internal
25
33
  */
26
- export declare function isControlInitType<const SpecificControlType extends BookPageControlType>(controlInit: BookPageControlInit<any>, specificType: SpecificControlType): controlInit is BookPageControlInit<SpecificControlType>;
34
+ export declare function isControlInitType<const SpecificControlType extends BookPageControlType>(controlInit: BookPageControlInit<BookPageControlType>, specificType: SpecificControlType): controlInit is BookPageControlInit<SpecificControlType>;
27
35
  /**
28
36
  * Define a page control. This doesn't do anything fancy (in fact it only returns the input) but it
29
37
  * helps immensely with type inference.
@@ -59,6 +67,8 @@ export type BookPageControlsValues = ControlsToValues<BookPageControlsInitBase>;
59
67
  export declare enum BookPageControlType {
60
68
  Checkbox = "checkbox",
61
69
  Color = "color",
70
+ /** Custom controls render user-provided HTML directly. They have no editable value. */
71
+ Custom = "custom",
62
72
  Dropdown = "dropdown",
63
73
  /** Hidden controls allow any values but they aren't displayed to the user for editing. */
64
74
  Hidden = "hidden",
@@ -73,6 +83,8 @@ export declare enum BookPageControlType {
73
83
  export declare const controlValueTypes: {
74
84
  checkbox: boolean;
75
85
  color: string;
86
+ /** Custom controls don't have a user-editable value. */
87
+ custom: undefined;
76
88
  dropdown: string;
77
89
  hidden: any;
78
90
  number: number;
@@ -24,6 +24,8 @@ export var BookPageControlType;
24
24
  (function (BookPageControlType) {
25
25
  BookPageControlType["Checkbox"] = "checkbox";
26
26
  BookPageControlType["Color"] = "color";
27
+ /** Custom controls render user-provided HTML directly. They have no editable value. */
28
+ BookPageControlType["Custom"] = "custom";
27
29
  BookPageControlType["Dropdown"] = "dropdown";
28
30
  /** Hidden controls allow any values but they aren't displayed to the user for editing. */
29
31
  BookPageControlType["Hidden"] = "hidden";
@@ -39,6 +41,8 @@ const anySymbol = Symbol('any-type');
39
41
  export const controlValueTypes = {
40
42
  [BookPageControlType.Checkbox]: false,
41
43
  [BookPageControlType.Color]: '',
44
+ /** Custom controls don't have a user-editable value. */
45
+ [BookPageControlType.Custom]: undefined,
42
46
  [BookPageControlType.Dropdown]: '',
43
47
  [BookPageControlType.Hidden]: anySymbol,
44
48
  [BookPageControlType.Number]: 0,
@@ -55,6 +59,9 @@ export function checkControls(controlsInit, pageName) {
55
59
  }
56
60
  const errors = [];
57
61
  Object.entries(controlsInit).forEach(([controlName, controlEntry,]) => {
62
+ if (controlEntry.controlType === BookPageControlType.Custom) {
63
+ return;
64
+ }
58
65
  const expectedInitDefault = controlValueTypes[controlEntry.controlType];
59
66
  if (expectedInitDefault === anySymbol) {
60
67
  return;
@@ -84,7 +84,13 @@ export const BookPageControls = defineBookElement()({
84
84
  ></${ViraIcon}>
85
85
  `)}
86
86
  <label class="control-wrapper">
87
- <span>${controlName}</span>
87
+ <span>
88
+ ${controlInit.controlType === BookPageControlType.Custom
89
+ ? html `
90
+ &nbsp;
91
+ `
92
+ : controlName}
93
+ </span>
88
94
  ${controlInputTemplate}
89
95
  </label>
90
96
  </div>
@@ -164,9 +170,14 @@ function createControlInput(value, controlInit, valueChange) {
164
170
  </select>
165
171
  `;
166
172
  }
173
+ else if (isControlInitType(controlInit, BookPageControlType.Custom)) {
174
+ return controlInit.content;
175
+ }
167
176
  else {
168
177
  return html `
169
- <p class="error">${controlInit.controlType} controls are not implemented yet.</p>
178
+ <p class="error">
179
+ ${controlInit.controlType} controls are not implemented yet.
180
+ </p>
170
181
  `;
171
182
  }
172
183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-book",
3
- "version": "26.13.1",
3
+ "version": "26.14.0",
4
4
  "keywords": [
5
5
  "book",
6
6
  "design system",
@@ -57,7 +57,7 @@
57
57
  "@web/test-runner-commands": "^0.9.0",
58
58
  "@web/test-runner-playwright": "^0.11.1",
59
59
  "@web/test-runner-visual-regression": "^0.10.0",
60
- "element-vir": "^26.13.1",
60
+ "element-vir": "^26.14.0",
61
61
  "istanbul-smart-text-reporter": "^1.1.5",
62
62
  "markdown-code-example-inserter": "^3.0.3",
63
63
  "type-fest": "^5.3.1",