@rohal12/spindle 0.62.6 → 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 +15208 -15138
- package/dist/pkg/story-variables.js +289 -162
- package/dist/pkg/tooling.js +1 -0
- package/package.json +1 -1
- package/src/action-registry.ts +9 -6
- package/src/components/macros/macro-args.ts +84 -1
- package/src/define-macro.ts +3 -57
- 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/story-variables.ts +58 -26
- package/src/tooling.ts +22 -7
- package/src/types-drift-check.ts +9 -0
- 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/types/tooling.d.ts +35 -1
|
@@ -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
|
|
package/types/tooling.d.ts
CHANGED
|
@@ -712,6 +712,12 @@ export interface VariableReference {
|
|
|
712
712
|
/** Where `$a.b.c` is written: `[start, end)` UTF-16 offsets into the markup. */
|
|
713
713
|
start: number;
|
|
714
714
|
end: number;
|
|
715
|
+
/**
|
|
716
|
+
* For an input binding, its decoded identity and editable root span.
|
|
717
|
+
* Offsets are into the markup, including inside escaped labels. The sigil
|
|
718
|
+
* is semantically `$` even when `binding.explicitSigil` is false.
|
|
719
|
+
*/
|
|
720
|
+
binding?: BoundVariable;
|
|
715
721
|
}
|
|
716
722
|
|
|
717
723
|
/**
|
|
@@ -749,10 +755,12 @@ export interface VariableDiagnostic {
|
|
|
749
755
|
* The variable references the markup of a passage evaluates, in source order,
|
|
750
756
|
* with their positions. Malformed tags are skipped. The macros are those the
|
|
751
757
|
* markup may use (`builtinMacros` and the user-defined ones).
|
|
758
|
+
* Input bindings include decoded root/path names and editable `binding` spans.
|
|
752
759
|
*
|
|
753
760
|
* These are the references the story start checks. With `all: true` the list
|
|
754
761
|
* is complete (the checked ones are among it, in source order): it also has
|
|
755
|
-
*
|
|
762
|
+
* sigilless input bindings (`{textbox "name"}`), the variable a macro names
|
|
763
|
+
* in a `variable` parameter, such as the target of
|
|
756
764
|
* `{unset}` and `{computed}`, and the `{$name}` in the selectors of a link,
|
|
757
765
|
* display or expression (`[[.c{$name} Go->T]]`).
|
|
758
766
|
*/
|
|
@@ -1227,6 +1235,32 @@ export interface ParsedCode {
|
|
|
1227
1235
|
*/
|
|
1228
1236
|
export declare function parseCode(src: string, goal?: JsGoal): ParsedCode;
|
|
1229
1237
|
|
|
1238
|
+
/** A runtime input binding, with UTF-16 spans into the raw arguments. */
|
|
1239
|
+
export interface BoundVariable {
|
|
1240
|
+
/** Decoded story-variable root and dot members. */
|
|
1241
|
+
name: string;
|
|
1242
|
+
path: string[];
|
|
1243
|
+
/** Whether the author wrote the optional literal `$` sigil. */
|
|
1244
|
+
explicitSigil: boolean;
|
|
1245
|
+
/** The binding spelling, excluding quotes and including any sigil. */
|
|
1246
|
+
start: number;
|
|
1247
|
+
end: number;
|
|
1248
|
+
/** Editable root spelling, excluding quotes, sigil and dot members. */
|
|
1249
|
+
nameStart: number;
|
|
1250
|
+
nameEnd: number;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* Read the first term as the runtime's story-variable binding. Quotes are
|
|
1255
|
+
* stripped, but this is an identifier path, not a JavaScript string literal:
|
|
1256
|
+
* only identifier escapes are decoded. Returns null for a missing binding;
|
|
1257
|
+
* throws for rejected namespaces, invalid escapes and reserved path names.
|
|
1258
|
+
* All offsets are UTF-16 offsets into rawArgs.
|
|
1259
|
+
*/
|
|
1260
|
+
export declare function parseBoundVariable(
|
|
1261
|
+
rawArgs: string,
|
|
1262
|
+
): BoundVariable | null;
|
|
1263
|
+
|
|
1230
1264
|
/** A consumed argument and its original parameter (including option keywords). */
|
|
1231
1265
|
export interface MacroArgumentSpan {
|
|
1232
1266
|
parameter: ParameterDef;
|