@rohal12/spindle 0.59.23 → 0.59.26
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 +694 -407
- package/dist/pkg/story-variables.js +510 -123
- package/dist/pkg/tooling.js +4 -0
- package/package.json +23 -24
- package/src/automation/load-yaml.ts +1 -1
- package/src/code-check.ts +23 -9
- package/src/components/PassageDialog.tsx +28 -1
- package/src/components/macros/MacroError.tsx +1 -1
- package/src/components/macros/MenubarButtons.tsx +3 -0
- package/src/components/macros/SaveManager.tsx +2 -2
- package/src/components/macros/SettingsControls.tsx +10 -6
- package/src/components/macros/Type.tsx +1 -1
- package/src/components/macros/detached-body.tsx +62 -3
- package/src/components/macros/macro-args.ts +1 -2
- package/src/execute-mutation.ts +4 -3
- package/src/hooks/use-modal-focus.ts +63 -20
- package/src/hooks/use-story-fields.ts +1 -1
- package/src/markup/ast.ts +1 -5
- package/src/markup/code-attributes.ts +1 -3
- package/src/markup/code-end.ts +1 -1
- package/src/markup/line-column.ts +1 -1
- package/src/markup/pair.ts +1 -4
- package/src/markup/render.tsx +25 -13
- package/src/settings.ts +9 -0
- package/src/static-literal.ts +1 -6
- package/src/store.ts +1 -1
- package/src/story-variables.ts +291 -121
- package/src/tooling.ts +89 -1
- package/src/widgets/widget-def.ts +93 -22
- package/types/index.d.ts +2 -10
- package/types/tooling.d.ts +126 -17
package/src/markup/render.tsx
CHANGED
|
@@ -353,11 +353,10 @@ function convertDomNode(
|
|
|
353
353
|
const parts = splitPlaceholderText(value, ph);
|
|
354
354
|
if (parts.every((part) => typeof part === 'string')) continue;
|
|
355
355
|
placeholders ??= {};
|
|
356
|
-
placeholders[name] = parts.map(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
: ph.nodes[part]!,
|
|
356
|
+
placeholders[name] = parts.map((part): ASTNode =>
|
|
357
|
+
typeof part === 'string'
|
|
358
|
+
? { type: 'text', value: part }
|
|
359
|
+
: ph.nodes[part]!,
|
|
361
360
|
);
|
|
362
361
|
}
|
|
363
362
|
|
|
@@ -572,7 +571,7 @@ function splitAttributes(
|
|
|
572
571
|
*/
|
|
573
572
|
function useDirectAttributes(
|
|
574
573
|
direct: [string, string][],
|
|
575
|
-
): RefObject<Element> | undefined {
|
|
574
|
+
): RefObject<Element | null> | undefined {
|
|
576
575
|
const elementRef = useRef<Element>(null);
|
|
577
576
|
const directKey = JSON.stringify(direct);
|
|
578
577
|
useLayoutEffect(() => {
|
|
@@ -680,9 +679,14 @@ function resolveAttributeValue(
|
|
|
680
679
|
return result.text;
|
|
681
680
|
}
|
|
682
681
|
|
|
682
|
+
/** Whether a node shows nothing as text: whitespace, or a closed HTML comment. */
|
|
683
|
+
function isBlankText(n: ASTNode): boolean {
|
|
684
|
+
return n.type === 'text' && (n.comment === true || n.value.trim() === '');
|
|
685
|
+
}
|
|
686
|
+
|
|
683
687
|
/** The index of the summary element opening `nodes`, or -1 when none does. */
|
|
684
688
|
function leadingSummaryIndex(nodes: ASTNode[]): number {
|
|
685
|
-
const at = nodes.findIndex((n) => n
|
|
689
|
+
const at = nodes.findIndex((n) => !isBlankText(n));
|
|
686
690
|
const first = nodes[at];
|
|
687
691
|
return first?.type === 'html' && first.tag.toLowerCase() === 'summary'
|
|
688
692
|
? at
|
|
@@ -703,9 +707,11 @@ function HtmlNodeRenderer({ node }: { node: HtmlNode }) {
|
|
|
703
707
|
const isSvgRoot = tag === 'svg';
|
|
704
708
|
const isRawRoot = !inRaw && (isSvgRoot || PREFORMATTED_ELEMENTS.has(tag));
|
|
705
709
|
const errors: AttributeError[] = [];
|
|
706
|
-
const resolved = Object.entries(node.attributes).map(
|
|
707
|
-
|
|
708
|
-
|
|
710
|
+
const resolved = Object.entries(node.attributes).map(([k, v]): Attribute => [
|
|
711
|
+
k,
|
|
712
|
+
resolveAttributeValue(k, v, scope, errors),
|
|
713
|
+
v,
|
|
714
|
+
]);
|
|
709
715
|
const { props, direct } = splitAttributes(resolved, inSvg || isSvgRoot);
|
|
710
716
|
const ref = useDirectAttributes(direct);
|
|
711
717
|
if (ref) props.ref = ref;
|
|
@@ -719,7 +725,13 @@ function HtmlNodeRenderer({ node }: { node: HtmlNode }) {
|
|
|
719
725
|
let children: preact.ComponentChildren = undefined;
|
|
720
726
|
let structural = false;
|
|
721
727
|
if (node.children.length > 0) {
|
|
722
|
-
if (
|
|
728
|
+
if (tag === 'style') {
|
|
729
|
+
// A raw-text element: its CSS keeps character-reference lookalikes
|
|
730
|
+
// (`?a=1¬ch=2`) as written (#453)
|
|
731
|
+
children = node.children.map((n) =>
|
|
732
|
+
n.type === 'text' ? n.value : renderSingleNode(n),
|
|
733
|
+
);
|
|
734
|
+
} else if (inRaw || isRawRoot) {
|
|
723
735
|
children = renderInlineNodes(node.children);
|
|
724
736
|
} else {
|
|
725
737
|
// A details element's summary stays its direct child: it is rendered
|
|
@@ -730,7 +742,7 @@ function HtmlNodeRenderer({ node }: { node: HtmlNode }) {
|
|
|
730
742
|
renderNodes(nodes, { nobr, locals, inline: isInline });
|
|
731
743
|
structural =
|
|
732
744
|
STRUCTURAL_ELEMENTS.has(tag) &&
|
|
733
|
-
node.children.every((n) => n.type !== 'text' || n
|
|
745
|
+
node.children.every((n) => n.type !== 'text' || isBlankText(n));
|
|
734
746
|
children = structural ? (
|
|
735
747
|
node.children
|
|
736
748
|
.filter((n) => n.type !== 'text')
|
|
@@ -1017,7 +1029,7 @@ export function renderNodes(
|
|
|
1017
1029
|
// paragraphs would pull the elements they produce out of it (#436)
|
|
1018
1030
|
if (
|
|
1019
1031
|
options?.structural &&
|
|
1020
|
-
nodes.every((n) => n.type !== 'text' || n
|
|
1032
|
+
nodes.every((n) => n.type !== 'text' || isBlankText(n))
|
|
1021
1033
|
) {
|
|
1022
1034
|
return nodes.filter((n) => n.type !== 'text').map(renderSingleNode);
|
|
1023
1035
|
}
|
package/src/settings.ts
CHANGED
|
@@ -32,6 +32,14 @@ let values: Record<string, unknown> = createNamespace();
|
|
|
32
32
|
let storageLoaded = false;
|
|
33
33
|
let unsubscribeStoryData: (() => void) | null = null;
|
|
34
34
|
|
|
35
|
+
const listeners = new Set<() => void>();
|
|
36
|
+
|
|
37
|
+
/** Call `listener` after a setting changes; returns the unsubscribe. */
|
|
38
|
+
export function subscribeSettings(listener: () => void): () => void {
|
|
39
|
+
listeners.add(listener);
|
|
40
|
+
return () => listeners.delete(listener);
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
function storageKey(): string {
|
|
36
44
|
const storyData = useStoryStore.getState().storyData;
|
|
37
45
|
const ifid = storyData?.ifid || 'unknown';
|
|
@@ -125,6 +133,7 @@ export const settings = {
|
|
|
125
133
|
set(name: string, value: unknown): void {
|
|
126
134
|
values[name] = value;
|
|
127
135
|
persist();
|
|
136
|
+
for (const listener of [...listeners]) listener();
|
|
128
137
|
},
|
|
129
138
|
|
|
130
139
|
getAll(): Record<string, unknown> {
|
package/src/static-literal.ts
CHANGED
|
@@ -11,12 +11,7 @@ import { scanStringLiteral } from './js-lexer';
|
|
|
11
11
|
|
|
12
12
|
/** The type of a variable by its default (see story-variables.ts VarType). */
|
|
13
13
|
type LiteralType =
|
|
14
|
-
| '
|
|
15
|
-
| 'string'
|
|
16
|
-
| 'boolean'
|
|
17
|
-
| 'array'
|
|
18
|
-
| 'object'
|
|
19
|
-
| 'null';
|
|
14
|
+
'number' | 'string' | 'boolean' | 'array' | 'object' | 'null';
|
|
20
15
|
|
|
21
16
|
/** The shape of a literal (see story-variables.ts FieldSchema). */
|
|
22
17
|
export interface LiteralShape {
|
package/src/store.ts
CHANGED
|
@@ -165,7 +165,7 @@ function computeVarPatches(
|
|
|
165
165
|
}
|
|
166
166
|
// Probe an unchanged variable with a copy of its own: it shares with a
|
|
167
167
|
// recorded one if the copy meets an object already copied
|
|
168
|
-
for (let found = seen.size > 0; found;
|
|
168
|
+
for (let found = seen.size > 0; found;) {
|
|
169
169
|
found = false;
|
|
170
170
|
for (const key of unchanged) {
|
|
171
171
|
const probe = new Map<object, object>();
|