@rohal12/spindle 0.59.12 → 0.59.13
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 +96 -20
- package/dist/pkg/story-variables.js +2 -1
- package/package.json +1 -1
- package/src/components/macros/Computed.tsx +23 -3
- package/src/components/macros/For.tsx +6 -3
- package/src/components/macros/Type.tsx +8 -4
- package/src/define-macro.ts +1 -1
- package/src/execute-mutation.ts +26 -0
- package/src/hooks/use-modal-focus.ts +21 -1
- package/src/markup/render.tsx +28 -3
- package/src/story-api.ts +2 -1
- package/src/story-variables.ts +12 -2
- package/src/utils/control-edits.ts +36 -3
- package/types/tooling.d.ts +7 -1
|
@@ -1,15 +1,48 @@
|
|
|
1
|
+
import { getByPath } from './object-path';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
4
|
+
* Records the edits a reader made through a control bound to a story
|
|
3
5
|
* variable (`{textbox}`, `{checkbox}`, ...). {for} tells these apart from a
|
|
4
6
|
* list that is replaced: typing into a control inside an iteration changes
|
|
5
7
|
* its item, but must not remount the iteration and drop the control's focus.
|
|
8
|
+
* An edit is attributed to the variable path it wrote, so a replacement made
|
|
9
|
+
* elsewhere (a watcher reacting to the edit) still remounts.
|
|
6
10
|
*/
|
|
7
11
|
let version = 0;
|
|
12
|
+
const MAX_LOG = 256;
|
|
13
|
+
const log: { version: number; segments: readonly string[] }[] = [];
|
|
8
14
|
|
|
9
|
-
export function noteControlEdit(): void {
|
|
10
|
-
version
|
|
15
|
+
export function noteControlEdit(segments: readonly string[]): void {
|
|
16
|
+
log.push({ version: ++version, segments });
|
|
17
|
+
if (log.length > MAX_LOG) log.shift();
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
export function controlEditVersion(): number {
|
|
14
21
|
return version;
|
|
15
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Whether an edit since `since` wrote inside `item`, element `index` of
|
|
26
|
+
* `list`: the path leads through the item (compared by reference in
|
|
27
|
+
* `variables`), or, for a primitive item, ends at its slot in the list.
|
|
28
|
+
*/
|
|
29
|
+
export function editedItem(
|
|
30
|
+
since: number,
|
|
31
|
+
variables: object,
|
|
32
|
+
list: readonly unknown[],
|
|
33
|
+
item: unknown,
|
|
34
|
+
index: number,
|
|
35
|
+
): boolean {
|
|
36
|
+
return log.some(({ version: v, segments }) => {
|
|
37
|
+
if (v <= since) return false;
|
|
38
|
+
if (typeof item === 'object' && item !== null) {
|
|
39
|
+
return segments.some(
|
|
40
|
+
(_, n) => getByPath(variables, segments.slice(0, n + 1)) === item,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return (
|
|
44
|
+
segments[segments.length - 1] === String(index) &&
|
|
45
|
+
getByPath(variables, segments.slice(0, -1)) === list
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
}
|
package/types/tooling.d.ts
CHANGED
|
@@ -100,7 +100,13 @@ export declare function defineMacro(config: MacroDefinition): void;
|
|
|
100
100
|
export declare function getMacroRegistry(): MacroMetadata[];
|
|
101
101
|
|
|
102
102
|
/** Variable type inferred from a StoryVariables/StoryTransients default value. */
|
|
103
|
-
export type VarType =
|
|
103
|
+
export type VarType =
|
|
104
|
+
| 'number'
|
|
105
|
+
| 'string'
|
|
106
|
+
| 'boolean'
|
|
107
|
+
| 'array'
|
|
108
|
+
| 'object'
|
|
109
|
+
| 'null';
|
|
104
110
|
|
|
105
111
|
/** Inferred shape of a declared variable (or one of its object fields). */
|
|
106
112
|
export interface FieldSchema {
|