@rohal12/spindle 0.62.7 → 0.62.8
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/pkg/format.js +1 -1
- package/dist/pkg/headless.js +15194 -15159
- package/dist/pkg/story-variables.js +133 -107
- package/package.json +1 -1
- package/src/action-registry.ts +9 -6
- package/src/headless.ts +4 -3
- package/src/hooks/use-modal-focus.ts +6 -19
- package/src/markup/ast.ts +5 -1
- package/src/markup/code-attributes.ts +11 -3
- package/src/markup/line-column.ts +3 -8
- package/src/markup/parse.ts +13 -2
- package/src/markup/render.tsx +1 -1
- package/src/observe/observable-text.ts +20 -8
- package/src/registry.ts +6 -2
- package/src/tooling.ts +16 -5
- package/src/utils/element-visibility.ts +35 -0
- package/src/utils/macro-names.ts +9 -0
- package/src/utils/sorted.ts +11 -0
- package/types/headless.d.ts +2 -2
package/src/tooling.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NameMap } from './utils/macro-names';
|
|
1
|
+
import { effectiveNamedDefinitions, NameMap } from './utils/macro-names';
|
|
2
2
|
export {
|
|
3
3
|
completionContext,
|
|
4
4
|
type CompletionContext,
|
|
@@ -208,11 +208,22 @@ export interface ParseMarkupOptions extends RuntimeParseMarkupOptions {
|
|
|
208
208
|
macros?: Iterable<ToolingMacro>;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/** Widgets take precedence over macros regardless of metadata input order. */
|
|
212
|
+
function effectiveToolingMacros(
|
|
213
|
+
macros: Iterable<ToolingMacro>,
|
|
214
|
+
): ToolingMacro[] {
|
|
215
|
+
const list = [...macros];
|
|
216
|
+
return effectiveNamedDefinitions([
|
|
217
|
+
...list.filter((m) => !m.widget),
|
|
218
|
+
...list.filter((m) => m.widget),
|
|
219
|
+
]);
|
|
220
|
+
}
|
|
221
|
+
|
|
211
222
|
function tokenizationOptions(
|
|
212
223
|
options: ParseMarkupOptions,
|
|
213
224
|
): RuntimeParseMarkupOptions {
|
|
214
225
|
if (!options.macros) return options;
|
|
215
|
-
const macros =
|
|
226
|
+
const macros = effectiveToolingMacros(options.macros);
|
|
216
227
|
const parametersOf = parameterLookup(macros);
|
|
217
228
|
return {
|
|
218
229
|
...options,
|
|
@@ -254,7 +265,7 @@ export function validateStoryMarkup(
|
|
|
254
265
|
options: ValidateMarkupOptions = {},
|
|
255
266
|
): MarkupDiagnostic[] {
|
|
256
267
|
const list = [...passages];
|
|
257
|
-
const all =
|
|
268
|
+
const all = effectiveToolingMacros(macros);
|
|
258
269
|
const known = new Set<string>();
|
|
259
270
|
// The calls of widgets that declare what their arguments hold are checked
|
|
260
271
|
const widgets = effectiveWidgetDefinitions(
|
|
@@ -313,7 +324,7 @@ export function passagePieces(
|
|
|
313
324
|
source: string,
|
|
314
325
|
macros: Iterable<ToolingMacro> = [],
|
|
315
326
|
): Piece[] {
|
|
316
|
-
const all =
|
|
327
|
+
const all = effectiveToolingMacros(macros);
|
|
317
328
|
const parametersOf = parameterLookup(all);
|
|
318
329
|
return passagePiecesOfTokens(
|
|
319
330
|
source,
|
|
@@ -337,7 +348,7 @@ export function passagePiecesOfTokens(
|
|
|
337
348
|
macros: Iterable<ToolingMacro>,
|
|
338
349
|
tokens: readonly Token[],
|
|
339
350
|
): Piece[] {
|
|
340
|
-
const all =
|
|
351
|
+
const all = effectiveToolingMacros(macros);
|
|
341
352
|
return [
|
|
342
353
|
...passagePiecesOf(source, tokens, parameterLookup(all), {
|
|
343
354
|
isBlock: blockLookup(all),
|
|
@@ -8,6 +8,31 @@ export function composedParent(el: Element): Element | null {
|
|
|
8
8
|
);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** Rendered child nodes: shadow content, slot assignments, or fallback. */
|
|
12
|
+
export function composedChildNodes(root: ParentNode): Node[] {
|
|
13
|
+
if ((root as Element).localName === 'slot') {
|
|
14
|
+
// Visit nested slots themselves so their visibility and filters apply.
|
|
15
|
+
const assigned = (root as HTMLSlotElement).assignedNodes();
|
|
16
|
+
if (assigned.length) return assigned;
|
|
17
|
+
}
|
|
18
|
+
return Array.from(((root as Element).shadowRoot ?? root).childNodes);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The elements among a container's rendered child nodes. */
|
|
22
|
+
export function composedChildren(root: ParentNode): Element[] {
|
|
23
|
+
return composedChildNodes(root).filter(
|
|
24
|
+
(node): node is Element => node.nodeType === 1,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Authored elements in rendered order; unassigned light DOM is omitted. */
|
|
29
|
+
export function* composedElements(root: ParentNode): Generator<HTMLElement> {
|
|
30
|
+
for (const el of composedChildren(root)) {
|
|
31
|
+
yield el as HTMLElement;
|
|
32
|
+
yield* composedElements(el);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
11
36
|
/** Elements whose content is never text the reader reads. */
|
|
12
37
|
const NOT_TEXT = new Set(['SCRIPT', 'STYLE', 'TEMPLATE', 'NOSCRIPT']);
|
|
13
38
|
|
|
@@ -65,6 +90,16 @@ export function isRendered(el: Element, root?: Element): boolean {
|
|
|
65
90
|
for (let e: Element | null = el; e; e = composedParent(e)) {
|
|
66
91
|
if (style(e)?.display === 'none') return false;
|
|
67
92
|
if (e === root) break;
|
|
93
|
+
const parent = e.parentElement;
|
|
94
|
+
// Connected light DOM may have no place in its host's rendered tree.
|
|
95
|
+
if (parent?.shadowRoot && !e.assignedSlot) return false;
|
|
96
|
+
// Slot fallback disappears whenever any light-DOM nodes are assigned.
|
|
97
|
+
if (
|
|
98
|
+
parent?.localName === 'slot' &&
|
|
99
|
+
(parent as HTMLSlotElement).assignedNodes().length > 0 &&
|
|
100
|
+
e.assignedSlot !== parent
|
|
101
|
+
)
|
|
102
|
+
return false;
|
|
68
103
|
}
|
|
69
104
|
return !inClosedDetails(el, root);
|
|
70
105
|
}
|
package/src/utils/macro-names.ts
CHANGED
|
@@ -18,6 +18,15 @@ export class NameMap<V> extends Map<string, V> {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** The latest definition of each name, using runtime replacement precedence. */
|
|
22
|
+
export function effectiveNamedDefinitions<T extends { name: string }>(
|
|
23
|
+
definitions: Iterable<T>,
|
|
24
|
+
): T[] {
|
|
25
|
+
const latest = new NameMap<T>();
|
|
26
|
+
for (const definition of definitions) latest.set(definition.name, definition);
|
|
27
|
+
return [...latest.values()];
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
/** A set of macro or widget names (see NameMap). */
|
|
22
31
|
export class NameSet {
|
|
23
32
|
private readonly names = new NameMap<true>();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Index of the first sorted value greater than `value` (or the length). */
|
|
2
|
+
export function upperBound(sorted: readonly number[], value: number): number {
|
|
3
|
+
let low = 0;
|
|
4
|
+
let high = sorted.length;
|
|
5
|
+
while (low < high) {
|
|
6
|
+
const mid = (low + high) >>> 1;
|
|
7
|
+
if (sorted[mid]! <= value) low = mid + 1;
|
|
8
|
+
else high = mid;
|
|
9
|
+
}
|
|
10
|
+
return low;
|
|
11
|
+
}
|
package/types/headless.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export interface BootStoryOptions {
|
|
|
25
25
|
export function bootStory(options: BootStoryOptions): Promise<StoryAPI>;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* The story's `$` variables
|
|
29
|
-
*
|
|
28
|
+
* The story's `$` variables, keyed by name without the `$`. Mutable values
|
|
29
|
+
* are copied together, preserving aliases without exposing live state.
|
|
30
30
|
*/
|
|
31
31
|
export function storyVariables(): Record<string, unknown>;
|
|
32
32
|
|