@rohal12/spindle 0.64.25 → 0.64.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 +18 -28
- package/package.json +1 -1
- package/src/components/macros/Button.tsx +2 -10
- package/src/components/macros/Cycle.tsx +6 -12
- package/src/components/macros/Dialog.tsx +2 -8
- package/src/components/macros/PassageDisplay.tsx +14 -7
- package/src/hooks/use-action.ts +15 -0
package/dist/pkg/headless.js
CHANGED
|
@@ -9548,6 +9548,14 @@ function actionAttributes(action, control) {
|
|
|
9548
9548
|
ref: action.ref
|
|
9549
9549
|
};
|
|
9550
9550
|
}
|
|
9551
|
+
/** Render a native macro button with its registered action and label. */
|
|
9552
|
+
function renderActionButton(action, control, onClick, label) {
|
|
9553
|
+
return h("button", {
|
|
9554
|
+
type: "button",
|
|
9555
|
+
...actionAttributes(action, control),
|
|
9556
|
+
onClick
|
|
9557
|
+
}, label);
|
|
9558
|
+
}
|
|
9551
9559
|
/**
|
|
9552
9560
|
* While true, controls rendered underneath do not register actions or reserve
|
|
9553
9561
|
* IDs. Used for display-only content mounted off-screen, so it never shows up
|
|
@@ -24395,10 +24403,8 @@ function cloneSnapshotTree(source, ids, pseudoRules = [], svgMarker = String(++s
|
|
|
24395
24403
|
clone,
|
|
24396
24404
|
ids
|
|
24397
24405
|
});
|
|
24398
|
-
if (html && source.
|
|
24399
|
-
|
|
24400
|
-
clone.removeAttribute("form");
|
|
24401
|
-
}
|
|
24406
|
+
if (html && source.matches("button, fieldset, input, object, output, select, textarea")) clone.setAttribute("form", "");
|
|
24407
|
+
if (html && (source.localName === "details" || source.localName === "input" && source.type === "radio")) clone.removeAttribute("name");
|
|
24402
24408
|
const computed = getComputedStyle(source);
|
|
24403
24409
|
if (!svg) copyComputedStyle(computed, clone.style, ids);
|
|
24404
24410
|
let pseudoId;
|
|
@@ -25348,19 +25354,13 @@ defineMacro({
|
|
|
25348
25354
|
const label = ctx.resolve?.(ctx.args.label ?? "") ?? rawArgs;
|
|
25349
25355
|
const runBody = useDetachedBody();
|
|
25350
25356
|
const handleClick = () => runBody(children);
|
|
25351
|
-
|
|
25357
|
+
return renderActionButton(useControlAction({
|
|
25352
25358
|
type: "button",
|
|
25353
25359
|
key: rawArgs,
|
|
25354
25360
|
authorId: ctx.id,
|
|
25355
25361
|
label,
|
|
25356
25362
|
perform: handleClick
|
|
25357
|
-
});
|
|
25358
|
-
return /* @__PURE__ */ jsx("button", {
|
|
25359
|
-
type: "button",
|
|
25360
|
-
...actionAttributes(action, ctx),
|
|
25361
|
-
onClick: handleClick,
|
|
25362
|
-
children: label
|
|
25363
|
-
});
|
|
25363
|
+
}), ctx, handleClick, label);
|
|
25364
25364
|
}
|
|
25365
25365
|
});
|
|
25366
25366
|
// src/components/macros/MacroLink.tsx
|
|
@@ -25817,12 +25817,7 @@ defineMacro({
|
|
|
25817
25817
|
target: passageName,
|
|
25818
25818
|
perform: openDialog
|
|
25819
25819
|
});
|
|
25820
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(
|
|
25821
|
-
type: "button",
|
|
25822
|
-
...actionAttributes(action, ctx),
|
|
25823
|
-
onClick: openDialog,
|
|
25824
|
-
children: label
|
|
25825
|
-
}), open && /* @__PURE__ */ jsx(PassageDialog, {
|
|
25820
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [renderActionButton(action, ctx, openDialog, label), open && /* @__PURE__ */ jsx(PassageDialog, {
|
|
25826
25821
|
passageName,
|
|
25827
25822
|
onClose: () => setOpen(false),
|
|
25828
25823
|
showCloseButton: !noclose
|
|
@@ -26623,27 +26618,22 @@ defineMacro({
|
|
|
26623
26618
|
parameters: [VARIABLE_PARAMETER],
|
|
26624
26619
|
render({ children = [] }, ctx) {
|
|
26625
26620
|
const options = ctx.extractOptions(children);
|
|
26621
|
+
const label = ctx.value == null ? "Choose an option" : String(ctx.value);
|
|
26626
26622
|
const handleClick = () => {
|
|
26627
26623
|
if (options.length === 0) return;
|
|
26628
26624
|
const current = ctx.getValue();
|
|
26629
|
-
const nextIndex = (options.indexOf(String(current)) + 1) % options.length;
|
|
26625
|
+
const nextIndex = ((current == null ? -1 : options.indexOf(String(current))) + 1) % options.length;
|
|
26630
26626
|
ctx.setValue(options[nextIndex]);
|
|
26631
26627
|
};
|
|
26632
|
-
|
|
26628
|
+
return renderActionButton(useVariableAction(ctx, {
|
|
26633
26629
|
type: "cycle",
|
|
26634
|
-
label
|
|
26630
|
+
label,
|
|
26635
26631
|
options,
|
|
26636
26632
|
perform: (v) => {
|
|
26637
26633
|
if (v !== void 0) ctx.setValue(v);
|
|
26638
26634
|
else handleClick();
|
|
26639
26635
|
}
|
|
26640
|
-
});
|
|
26641
|
-
return /* @__PURE__ */ jsx("button", {
|
|
26642
|
-
type: "button",
|
|
26643
|
-
...actionAttributes(action, ctx),
|
|
26644
|
-
onClick: handleClick,
|
|
26645
|
-
children: ctx.value == null ? options[0] || "" : String(ctx.value)
|
|
26646
|
-
});
|
|
26636
|
+
}), ctx, handleClick, label);
|
|
26647
26637
|
}
|
|
26648
26638
|
});
|
|
26649
26639
|
// src/components/macros/Span.tsx
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderActionButton, useControlAction } from '../../hooks/use-action';
|
|
2
2
|
import { defineMacro } from '../../define-macro';
|
|
3
3
|
import { useDetachedBody } from './detached-body';
|
|
4
4
|
|
|
@@ -25,14 +25,6 @@ defineMacro({
|
|
|
25
25
|
perform: handleClick,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
return (
|
|
29
|
-
<button
|
|
30
|
-
type="button"
|
|
31
|
-
{...actionAttributes(action, ctx)}
|
|
32
|
-
onClick={handleClick}
|
|
33
|
-
>
|
|
34
|
-
{label}
|
|
35
|
-
</button>
|
|
36
|
-
);
|
|
28
|
+
return renderActionButton(action, ctx, handleClick, label);
|
|
37
29
|
},
|
|
38
30
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderActionButton } from '../../hooks/use-action';
|
|
2
2
|
import { defineMacro } from '../../define-macro';
|
|
3
3
|
import { VARIABLE_PARAMETER, useVariableAction } from './input-macro';
|
|
4
4
|
import { OPTION_CLAUSE } from './option-clauses';
|
|
@@ -12,18 +12,20 @@ defineMacro({
|
|
|
12
12
|
parameters: [VARIABLE_PARAMETER],
|
|
13
13
|
render({ children = [] }, ctx) {
|
|
14
14
|
const options = ctx.extractOptions(children);
|
|
15
|
+
const label = ctx.value == null ? 'Choose an option' : String(ctx.value);
|
|
15
16
|
|
|
16
17
|
const handleClick = () => {
|
|
17
18
|
if (options.length === 0) return;
|
|
18
19
|
const current = ctx.getValue!();
|
|
19
|
-
const currentIndex =
|
|
20
|
+
const currentIndex =
|
|
21
|
+
current == null ? -1 : options.indexOf(String(current));
|
|
20
22
|
const nextIndex = (currentIndex + 1) % options.length;
|
|
21
23
|
ctx.setValue!(options[nextIndex]);
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
const action = useVariableAction(ctx, {
|
|
25
27
|
type: 'cycle',
|
|
26
|
-
label
|
|
28
|
+
label,
|
|
27
29
|
options,
|
|
28
30
|
perform: (v) => {
|
|
29
31
|
if (v !== undefined) {
|
|
@@ -34,14 +36,6 @@ defineMacro({
|
|
|
34
36
|
},
|
|
35
37
|
});
|
|
36
38
|
|
|
37
|
-
return (
|
|
38
|
-
<button
|
|
39
|
-
type="button"
|
|
40
|
-
{...actionAttributes(action, ctx)}
|
|
41
|
-
onClick={handleClick}
|
|
42
|
-
>
|
|
43
|
-
{ctx.value == null ? options[0] || '' : String(ctx.value)}
|
|
44
|
-
</button>
|
|
45
|
-
);
|
|
39
|
+
return renderActionButton(action, ctx, handleClick, label);
|
|
46
40
|
},
|
|
47
41
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderActionButton, useControlAction } from '../../hooks/use-action';
|
|
2
2
|
import { defineMacro } from '../../define-macro';
|
|
3
3
|
import { PassageDialog } from '../PassageDialog';
|
|
4
4
|
|
|
@@ -33,13 +33,7 @@ defineMacro({
|
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
35
|
<>
|
|
36
|
-
|
|
37
|
-
type="button"
|
|
38
|
-
{...actionAttributes(action, ctx)}
|
|
39
|
-
onClick={openDialog}
|
|
40
|
-
>
|
|
41
|
-
{label}
|
|
42
|
-
</button>
|
|
36
|
+
{renderActionButton(action, ctx, openDialog, label)}
|
|
43
37
|
{open && (
|
|
44
38
|
<PassageDialog
|
|
45
39
|
passageName={passageName}
|
|
@@ -525,16 +525,23 @@ function cloneSnapshotTree(
|
|
|
525
525
|
if (custom) clone.setAttribute('data-spindle-snapshot-tag', source.localName);
|
|
526
526
|
if (svg) clone.setAttribute('data-spindle-snapshot-svg', svgMarker);
|
|
527
527
|
if (svg) svgState.copies.push({ source, clone: clone as SVGElement, ids });
|
|
528
|
-
//
|
|
529
|
-
//
|
|
528
|
+
// An explicit empty form reference prevents both external association and
|
|
529
|
+
// fallback to an ancestor form, including forms inside the snapshot.
|
|
530
|
+
// Inert controls otherwise still submit values and participate in validation.
|
|
530
531
|
if (
|
|
531
532
|
html &&
|
|
532
|
-
source.
|
|
533
|
-
|
|
534
|
-
|
|
533
|
+
source.matches('button, fieldset, input, object, output, select, textarea')
|
|
534
|
+
)
|
|
535
|
+
clone.setAttribute('form', '');
|
|
536
|
+
// Passive radios and details must not join live or other snapshot groups.
|
|
537
|
+
// Removing the name preserves their state when either tree is inserted.
|
|
538
|
+
if (
|
|
539
|
+
html &&
|
|
540
|
+
(source.localName === 'details' ||
|
|
541
|
+
(source.localName === 'input' &&
|
|
542
|
+
(source as HTMLInputElement).type === 'radio'))
|
|
543
|
+
)
|
|
535
544
|
clone.removeAttribute('name');
|
|
536
|
-
clone.removeAttribute('form');
|
|
537
|
-
}
|
|
538
545
|
// IDs and the passage class are removed, and custom tags become spans.
|
|
539
546
|
// Freeze native and custom content before those selectors stop matching.
|
|
540
547
|
const computed = getComputedStyle(source);
|
package/src/hooks/use-action.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext } from 'preact';
|
|
2
2
|
import { useCallback, useContext, useLayoutEffect, useRef } from 'preact/hooks';
|
|
3
|
+
import { h, type ComponentChildren } from 'preact';
|
|
3
4
|
import {
|
|
4
5
|
registerAction,
|
|
5
6
|
generateActionId,
|
|
@@ -52,6 +53,20 @@ export function actionAttributes(
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
/** Render a native macro button with its registered action and label. */
|
|
57
|
+
export function renderActionButton(
|
|
58
|
+
action: ControlAction,
|
|
59
|
+
control: { id?: string; cls?: string },
|
|
60
|
+
onClick: () => void,
|
|
61
|
+
label: ComponentChildren,
|
|
62
|
+
) {
|
|
63
|
+
return h(
|
|
64
|
+
'button',
|
|
65
|
+
{ type: 'button', ...actionAttributes(action, control), onClick },
|
|
66
|
+
label,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
55
70
|
/**
|
|
56
71
|
* While true, controls rendered underneath do not register actions or reserve
|
|
57
72
|
* IDs. Used for display-only content mounted off-screen, so it never shows up
|