@voidhash/mimic-react 1.0.0-beta.13 → 1.0.0-beta.14
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/.turbo/turbo-build.log +36 -36
- package/dist/zustand/middleware.d.cts +1 -1
- package/dist/zustand/middleware.d.mts +1 -1
- package/dist/zustand/types.d.cts +1 -1
- package/dist/zustand/types.d.mts +1 -1
- package/dist/zustand/useDraft.cjs +14 -11
- package/dist/zustand/useDraft.d.cts +6 -5
- package/dist/zustand/useDraft.d.cts.map +1 -1
- package/dist/zustand/useDraft.d.mts +6 -5
- package/dist/zustand/useDraft.d.mts.map +1 -1
- package/dist/zustand/useDraft.mjs +14 -11
- package/dist/zustand/useDraft.mjs.map +1 -1
- package/dist/zustand-commander/commander.cjs +59 -22
- package/dist/zustand-commander/commander.d.cts +16 -6
- package/dist/zustand-commander/commander.d.cts.map +1 -1
- package/dist/zustand-commander/commander.d.mts +16 -6
- package/dist/zustand-commander/commander.d.mts.map +1 -1
- package/dist/zustand-commander/commander.mjs +57 -22
- package/dist/zustand-commander/commander.mjs.map +1 -1
- package/dist/zustand-commander/hooks.cjs +18 -4
- package/dist/zustand-commander/hooks.d.cts +2 -1
- package/dist/zustand-commander/hooks.d.cts.map +1 -1
- package/dist/zustand-commander/hooks.d.mts +2 -1
- package/dist/zustand-commander/hooks.d.mts.map +1 -1
- package/dist/zustand-commander/hooks.mjs +18 -4
- package/dist/zustand-commander/hooks.mjs.map +1 -1
- package/dist/zustand-commander/index.cjs +2 -0
- package/dist/zustand-commander/index.d.cts +2 -2
- package/dist/zustand-commander/index.d.mts +2 -2
- package/dist/zustand-commander/index.mjs +2 -2
- package/dist/zustand-commander/types.d.cts +23 -14
- package/dist/zustand-commander/types.d.cts.map +1 -1
- package/dist/zustand-commander/types.d.mts +23 -14
- package/dist/zustand-commander/types.d.mts.map +1 -1
- package/dist/zustand-commander/types.mjs.map +1 -1
- package/package.json +3 -3
- package/src/zustand/useDraft.ts +15 -19
- package/src/zustand-commander/commander.ts +107 -21
- package/src/zustand-commander/hooks.ts +38 -12
- package/src/zustand-commander/index.ts +2 -0
- package/src/zustand-commander/types.ts +34 -24
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @voidhash/mimic-react@1.0.0-beta.
|
|
2
|
+
> @voidhash/mimic-react@1.0.0-beta.14 build /home/runner/work/mimic/mimic/packages/mimic-react
|
|
3
3
|
> tsdown
|
|
4
4
|
|
|
5
5
|
[34mℹ[39m tsdown [2mv0.18.2[22m powered by rolldown [2mv1.0.0-beta.55[22m
|
|
@@ -8,69 +8,69 @@
|
|
|
8
8
|
[34mℹ[39m target: [34mes2017[39m
|
|
9
9
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
10
10
|
[34mℹ[39m Build start
|
|
11
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mzustand-commander/index.cjs[22m [2m0.
|
|
11
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mzustand-commander/index.cjs[22m [2m0.90 kB[22m [2m│ gzip: 0.26 kB[22m
|
|
12
12
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mzustand/index.cjs[22m [2m0.20 kB[22m [2m│ gzip: 0.11 kB[22m
|
|
13
13
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [2m0.00 kB[22m [2m│ gzip: 0.02 kB[22m
|
|
14
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/commander.cjs [
|
|
15
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/hooks.cjs [2m4.
|
|
14
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/commander.cjs [2m7.57 kB[22m [2m│ gzip: 1.89 kB[22m
|
|
15
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/hooks.cjs [2m4.85 kB[22m [2m│ gzip: 1.67 kB[22m
|
|
16
16
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand/middleware.cjs [2m3.17 kB[22m [2m│ gzip: 1.14 kB[22m
|
|
17
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand/useDraft.cjs [
|
|
17
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand/useDraft.cjs [2m2.13 kB[22m [2m│ gzip: 0.74 kB[22m
|
|
18
18
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.cjs [2m0.95 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
19
19
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/types.cjs [2m0.91 kB[22m [2m│ gzip: 0.34 kB[22m
|
|
20
20
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.cjs [2m0.53 kB[22m [2m│ gzip: 0.29 kB[22m
|
|
21
21
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.cjs [2m0.52 kB[22m [2m│ gzip: 0.32 kB[22m
|
|
22
22
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs [2m0.40 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
23
23
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.cjs [2m0.37 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
24
|
-
[34mℹ[39m [33m[CJS][39m 13 files, total:
|
|
25
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/types.d.cts.map [
|
|
24
|
+
[34mℹ[39m [33m[CJS][39m 13 files, total: 22.47 kB
|
|
25
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/types.d.cts.map [2m3.96 kB[22m [2m│ gzip: 1.61 kB[22m
|
|
26
26
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand/types.d.cts.map [2m1.24 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
27
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand/
|
|
28
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/
|
|
27
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/hooks.d.cts.map [2m0.59 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
28
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand-commander/commander.d.cts.map [2m0.54 kB[22m [2m│ gzip: 0.31 kB[22m
|
|
29
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand/useDraft.d.cts.map [2m0.49 kB[22m [2m│ gzip: 0.27 kB[22m
|
|
29
30
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mzustand/middleware.d.cts.map [2m0.38 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
30
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[
|
|
31
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mzustand-commander/index.d.cts[22m[39m [2m1.14 kB[22m [2m│ gzip: 0.36 kB[22m
|
|
31
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mzustand-commander/index.d.cts[22m[39m [2m1.21 kB[22m [2m│ gzip: 0.38 kB[22m
|
|
32
32
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mzustand/index.d.cts[22m[39m [2m0.34 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
33
33
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
34
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand-commander/types.d.cts[39m [
|
|
34
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand-commander/types.d.cts[39m [2m8.14 kB[22m [2m│ gzip: 2.30 kB[22m
|
|
35
35
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand/types.d.cts[39m [2m3.23 kB[22m [2m│ gzip: 1.04 kB[22m
|
|
36
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand-commander/hooks.d.cts[39m [2m2.
|
|
36
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand-commander/hooks.d.cts[39m [2m2.63 kB[22m [2m│ gzip: 0.93 kB[22m
|
|
37
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand-commander/commander.d.cts[39m [2m2.28 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
37
38
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand/middleware.d.cts[39m [2m2.13 kB[22m [2m│ gzip: 0.85 kB[22m
|
|
38
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand
|
|
39
|
-
[34mℹ[39m [33m[CJS][39m
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mzustand-commander/index.mjs[22m [2m 0.47 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
39
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mzustand/useDraft.d.cts[39m [2m1.54 kB[22m [2m│ gzip: 0.66 kB[22m
|
|
40
|
+
[34mℹ[39m [33m[CJS][39m 15 files, total: 28.71 kB
|
|
41
|
+
[32m✔[39m Build complete in [32m4092ms[39m
|
|
42
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mzustand-commander/index.mjs[22m [2m 0.53 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
43
43
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mzustand/index.mjs[22m [2m 0.11 kB[22m [2m│ gzip: 0.09 kB[22m
|
|
44
44
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m 0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
45
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/commander.mjs.map [
|
|
46
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/types.mjs.map [
|
|
47
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/hooks.mjs.map [
|
|
45
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/commander.mjs.map [2m15.04 kB[22m [2m│ gzip: 3.77 kB[22m
|
|
46
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/types.mjs.map [2m11.30 kB[22m [2m│ gzip: 2.83 kB[22m
|
|
47
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/hooks.mjs.map [2m10.68 kB[22m [2m│ gzip: 3.27 kB[22m
|
|
48
48
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/middleware.mjs.map [2m 6.89 kB[22m [2m│ gzip: 2.11 kB[22m
|
|
49
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/commander.mjs [2m
|
|
50
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/useDraft.mjs.map [2m 4.
|
|
51
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/hooks.mjs [2m
|
|
49
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/commander.mjs [2m 6.83 kB[22m [2m│ gzip: 1.88 kB[22m
|
|
50
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/useDraft.mjs.map [2m 4.64 kB[22m [2m│ gzip: 1.59 kB[22m
|
|
51
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/hooks.mjs [2m 4.57 kB[22m [2m│ gzip: 1.66 kB[22m
|
|
52
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/types.d.mts.map [2m 3.96 kB[22m [2m│ gzip: 1.61 kB[22m
|
|
52
53
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/middleware.mjs [2m 3.10 kB[22m [2m│ gzip: 1.15 kB[22m
|
|
53
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand
|
|
54
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/useDraft.mjs [2m 1.81 kB[22m [2m│ gzip: 0.66 kB[22m
|
|
54
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/useDraft.mjs [2m 2.04 kB[22m [2m│ gzip: 0.76 kB[22m
|
|
55
55
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/types.d.mts.map [2m 1.24 kB[22m [2m│ gzip: 0.59 kB[22m
|
|
56
56
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.mjs [2m 0.90 kB[22m [2m│ gzip: 0.42 kB[22m
|
|
57
57
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/types.mjs [2m 0.84 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
58
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/
|
|
59
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/
|
|
58
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/hooks.d.mts.map [2m 0.59 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
59
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand-commander/commander.d.mts.map [2m 0.54 kB[22m [2m│ gzip: 0.31 kB[22m
|
|
60
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/useDraft.d.mts.map [2m 0.49 kB[22m [2m│ gzip: 0.27 kB[22m
|
|
60
61
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs [2m 0.47 kB[22m [2m│ gzip: 0.30 kB[22m
|
|
61
62
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs [2m 0.43 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
62
63
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mzustand/middleware.d.mts.map [2m 0.38 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
63
64
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs [2m 0.35 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
64
65
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs [2m 0.30 kB[22m [2m│ gzip: 0.21 kB[22m
|
|
65
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[
|
|
66
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mzustand-commander/index.d.mts[22m[39m [2m 1.14 kB[22m [2m│ gzip: 0.36 kB[22m
|
|
66
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mzustand-commander/index.d.mts[22m[39m [2m 1.21 kB[22m [2m│ gzip: 0.38 kB[22m
|
|
67
67
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mzustand/index.d.mts[22m[39m [2m 0.34 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
68
68
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 0.01 kB[22m [2m│ gzip: 0.03 kB[22m
|
|
69
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand-commander/types.d.mts[39m [2m
|
|
69
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand-commander/types.d.mts[39m [2m 8.14 kB[22m [2m│ gzip: 2.30 kB[22m
|
|
70
70
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand/types.d.mts[39m [2m 3.23 kB[22m [2m│ gzip: 1.04 kB[22m
|
|
71
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand-commander/hooks.d.mts[39m [2m 2.
|
|
71
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand-commander/hooks.d.mts[39m [2m 2.63 kB[22m [2m│ gzip: 0.93 kB[22m
|
|
72
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand-commander/commander.d.mts[39m [2m 2.28 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
72
73
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand/middleware.d.mts[39m [2m 2.13 kB[22m [2m│ gzip: 0.85 kB[22m
|
|
73
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand
|
|
74
|
-
[34mℹ[39m [34m[ESM][39m
|
|
75
|
-
[
|
|
76
|
-
[32m✔[39m Build complete in [32m3628ms[39m
|
|
74
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mzustand/useDraft.d.mts[39m [2m 1.54 kB[22m [2m│ gzip: 0.66 kB[22m
|
|
75
|
+
[34mℹ[39m [34m[ESM][39m 33 files, total: 97.77 kB
|
|
76
|
+
[32m✔[39m Build complete in [32m4138ms[39m
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MimicMiddlewareOptions, MimicSlice } from "./types.cjs";
|
|
2
2
|
import { StateCreator, StoreMutatorIdentifier } from "zustand";
|
|
3
|
-
import { ClientDocument } from "@voidhash/mimic/client";
|
|
4
3
|
import { Presence, Primitive } from "@voidhash/mimic";
|
|
4
|
+
import { ClientDocument } from "@voidhash/mimic/client";
|
|
5
5
|
|
|
6
6
|
//#region src/zustand/middleware.d.ts
|
|
7
7
|
type MimicMiddleware = <TSchema extends Primitive.AnyPrimitive, TPresence extends Presence.AnyPresence | undefined = undefined, T extends object = object, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = []>(document: ClientDocument.ClientDocument<TSchema, TPresence>, config: StateCreator<T & MimicSlice<TSchema, TPresence>, Mps, Mcs, T>, options?: MimicMiddlewareOptions) => StateCreator<T & MimicSlice<TSchema, TPresence>, Mps, Mcs, T & MimicSlice<TSchema, TPresence>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MimicMiddlewareOptions, MimicSlice } from "./types.mjs";
|
|
2
2
|
import { StateCreator, StoreMutatorIdentifier } from "zustand";
|
|
3
|
-
import { ClientDocument } from "@voidhash/mimic/client";
|
|
4
3
|
import { Presence, Primitive } from "@voidhash/mimic";
|
|
4
|
+
import { ClientDocument } from "@voidhash/mimic/client";
|
|
5
5
|
|
|
6
6
|
//#region src/zustand/middleware.d.ts
|
|
7
7
|
type MimicMiddleware = <TSchema extends Primitive.AnyPrimitive, TPresence extends Presence.AnyPresence | undefined = undefined, T extends object = object, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = []>(document: ClientDocument.ClientDocument<TSchema, TPresence>, config: StateCreator<T & MimicSlice<TSchema, TPresence>, Mps, Mcs, T>, options?: MimicMiddlewareOptions) => StateCreator<T & MimicSlice<TSchema, TPresence>, Mps, Mcs, T & MimicSlice<TSchema, TPresence>>;
|
package/dist/zustand/types.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StateCreator, StoreMutatorIdentifier } from "zustand";
|
|
2
|
-
import { ClientDocument } from "@voidhash/mimic/client";
|
|
3
2
|
import { Presence, Primitive } from "@voidhash/mimic";
|
|
3
|
+
import { ClientDocument } from "@voidhash/mimic/client";
|
|
4
4
|
|
|
5
5
|
//#region src/zustand/types.d.ts
|
|
6
6
|
|
package/dist/zustand/types.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StateCreator, StoreMutatorIdentifier } from "zustand";
|
|
2
|
-
import { ClientDocument } from "@voidhash/mimic/client";
|
|
3
2
|
import { Presence, Primitive } from "@voidhash/mimic";
|
|
3
|
+
import { ClientDocument } from "@voidhash/mimic/client";
|
|
4
4
|
|
|
5
5
|
//#region src/zustand/types.d.ts
|
|
6
6
|
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
const require_commander = require('../zustand-commander/commander.cjs');
|
|
1
2
|
let react = require("react");
|
|
2
3
|
|
|
3
4
|
//#region src/zustand/useDraft.ts
|
|
4
5
|
/**
|
|
5
6
|
* React hook for managing a draft lifecycle with auto-cleanup on unmount.
|
|
7
|
+
* Links the draft to the commander so that `ctx.transaction()` routes through the draft
|
|
8
|
+
* and undo/redo is disabled while the draft is active.
|
|
6
9
|
*
|
|
7
|
-
* @param store - The zustand store containing the mimic slice
|
|
10
|
+
* @param store - The zustand store containing the mimic slice and commander slice
|
|
8
11
|
* @returns Draft control methods
|
|
9
12
|
*/
|
|
10
13
|
const useDraft = (store) => {
|
|
@@ -22,41 +25,41 @@ const useDraft = (store) => {
|
|
|
22
25
|
}, []);
|
|
23
26
|
const begin = (0, react.useCallback)(() => {
|
|
24
27
|
if (draftRef.current !== null) throw new Error("A draft is already active. Commit or discard it first.");
|
|
25
|
-
|
|
28
|
+
const draft = store.getState().mimic.document.createDraft();
|
|
29
|
+
draftRef.current = draft;
|
|
30
|
+
require_commander.setActiveDraft(store, draft);
|
|
26
31
|
bumpVersion();
|
|
27
32
|
}, [store, bumpVersion]);
|
|
28
33
|
const commit = (0, react.useCallback)(() => {
|
|
29
34
|
if (draftRef.current === null) return;
|
|
35
|
+
require_commander.clearActiveDraft(store);
|
|
30
36
|
draftRef.current.commit();
|
|
31
37
|
draftRef.current = null;
|
|
32
38
|
bumpVersion();
|
|
33
|
-
}, [bumpVersion]);
|
|
39
|
+
}, [store, bumpVersion]);
|
|
34
40
|
const discard = (0, react.useCallback)(() => {
|
|
35
41
|
if (draftRef.current === null) return;
|
|
42
|
+
require_commander.clearActiveDraft(store);
|
|
36
43
|
draftRef.current.discard();
|
|
37
44
|
draftRef.current = null;
|
|
38
45
|
bumpVersion();
|
|
39
|
-
}, [bumpVersion]);
|
|
40
|
-
const update = (0, react.useCallback)((fn) => {
|
|
41
|
-
if (draftRef.current === null) throw new Error("No active draft. Call begin() first.");
|
|
42
|
-
draftRef.current.update(fn);
|
|
43
|
-
}, []);
|
|
46
|
+
}, [store, bumpVersion]);
|
|
44
47
|
(0, react.useEffect)(() => {
|
|
45
48
|
return () => {
|
|
46
49
|
if (draftRef.current !== null) {
|
|
47
50
|
try {
|
|
51
|
+
require_commander.clearActiveDraft(store);
|
|
48
52
|
draftRef.current.discard();
|
|
49
53
|
} catch (_unused) {}
|
|
50
54
|
draftRef.current = null;
|
|
51
55
|
}
|
|
52
56
|
};
|
|
53
|
-
}, []);
|
|
57
|
+
}, [store]);
|
|
54
58
|
return {
|
|
55
59
|
draft: draftRef.current,
|
|
56
60
|
begin,
|
|
57
61
|
commit,
|
|
58
|
-
discard
|
|
59
|
-
update
|
|
62
|
+
discard
|
|
60
63
|
};
|
|
61
64
|
};
|
|
62
65
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { CommanderSlice } from "../zustand-commander/types.cjs";
|
|
1
2
|
import { MimicSlice } from "./types.cjs";
|
|
2
3
|
import { StoreApi } from "zustand";
|
|
3
|
-
import { ClientDocument } from "@voidhash/mimic/client";
|
|
4
4
|
import * as _voidhash_mimic0 from "@voidhash/mimic";
|
|
5
5
|
import { Primitive } from "@voidhash/mimic";
|
|
6
|
+
import { ClientDocument } from "@voidhash/mimic/client";
|
|
6
7
|
|
|
7
8
|
//#region src/zustand/useDraft.d.ts
|
|
8
9
|
/**
|
|
@@ -17,16 +18,16 @@ interface UseDraftReturn<TSchema extends Primitive.AnyPrimitive> {
|
|
|
17
18
|
readonly commit: () => void;
|
|
18
19
|
/** Discards the active draft. No-op if no draft is active. */
|
|
19
20
|
readonly discard: () => void;
|
|
20
|
-
/** Runs an update on the active draft. Throws if no draft is active. */
|
|
21
|
-
readonly update: (fn: (root: Primitive.InferProxy<TSchema>) => void) => void;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
23
|
* React hook for managing a draft lifecycle with auto-cleanup on unmount.
|
|
24
|
+
* Links the draft to the commander so that `ctx.transaction()` routes through the draft
|
|
25
|
+
* and undo/redo is disabled while the draft is active.
|
|
25
26
|
*
|
|
26
|
-
* @param store - The zustand store containing the mimic slice
|
|
27
|
+
* @param store - The zustand store containing the mimic slice and commander slice
|
|
27
28
|
* @returns Draft control methods
|
|
28
29
|
*/
|
|
29
|
-
declare const useDraft: <TSchema extends Primitive.AnyPrimitive, TPresence extends _voidhash_mimic0.Presence.AnyPresence | undefined = undefined>(store: StoreApi<MimicSlice<TSchema, TPresence
|
|
30
|
+
declare const useDraft: <TSchema extends Primitive.AnyPrimitive, TPresence extends _voidhash_mimic0.Presence.AnyPresence | undefined = undefined>(store: StoreApi<MimicSlice<TSchema, TPresence> & CommanderSlice>) => UseDraftReturn<TSchema>;
|
|
30
31
|
//#endregion
|
|
31
32
|
export { UseDraftReturn, useDraft };
|
|
32
33
|
//# sourceMappingURL=useDraft.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDraft.d.cts","names":[],"sources":["../../src/zustand/useDraft.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDraft.d.cts","names":[],"sources":["../../src/zustand/useDraft.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAYiB,UAAA,cAAc,CAAA,gBAAiB,SAAA,CAAU,YAA3B,CAAA,CAAA;EAAiB;EAEH,SAAA,KAAA,EAA3B,cAAA,CAAe,WAAY,CAAA,OAAA,CAAA,GAAA,IAAA;EAA3B;EAA0B,SAAA,KAAA,EAAA,GAAA,GAAA,IAAA;EAiB/B;EACK,SAAU,MAAA,EAAA,GAAA,GAAA,IAAA;EACkB;EAEjB,SAAA,OAAA,EAAA,GAAA,GAAA,IAAA;;;;;;;;;;cAJhB,2BACK,SAAA,CAAU,gCACkB,gBAAA,CAAA,QAAA,CAAS,WAAA,iCAE9C,SAAS,WAAW,SAAS,aAAa,oBAChD,eAAe"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { CommanderSlice } from "../zustand-commander/types.mjs";
|
|
1
2
|
import { MimicSlice } from "./types.mjs";
|
|
2
3
|
import { StoreApi } from "zustand";
|
|
3
|
-
import { ClientDocument } from "@voidhash/mimic/client";
|
|
4
4
|
import * as _voidhash_mimic0 from "@voidhash/mimic";
|
|
5
5
|
import { Primitive } from "@voidhash/mimic";
|
|
6
|
+
import { ClientDocument } from "@voidhash/mimic/client";
|
|
6
7
|
|
|
7
8
|
//#region src/zustand/useDraft.d.ts
|
|
8
9
|
/**
|
|
@@ -17,16 +18,16 @@ interface UseDraftReturn<TSchema extends Primitive.AnyPrimitive> {
|
|
|
17
18
|
readonly commit: () => void;
|
|
18
19
|
/** Discards the active draft. No-op if no draft is active. */
|
|
19
20
|
readonly discard: () => void;
|
|
20
|
-
/** Runs an update on the active draft. Throws if no draft is active. */
|
|
21
|
-
readonly update: (fn: (root: Primitive.InferProxy<TSchema>) => void) => void;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
23
|
* React hook for managing a draft lifecycle with auto-cleanup on unmount.
|
|
24
|
+
* Links the draft to the commander so that `ctx.transaction()` routes through the draft
|
|
25
|
+
* and undo/redo is disabled while the draft is active.
|
|
25
26
|
*
|
|
26
|
-
* @param store - The zustand store containing the mimic slice
|
|
27
|
+
* @param store - The zustand store containing the mimic slice and commander slice
|
|
27
28
|
* @returns Draft control methods
|
|
28
29
|
*/
|
|
29
|
-
declare const useDraft: <TSchema extends Primitive.AnyPrimitive, TPresence extends _voidhash_mimic0.Presence.AnyPresence | undefined = undefined>(store: StoreApi<MimicSlice<TSchema, TPresence
|
|
30
|
+
declare const useDraft: <TSchema extends Primitive.AnyPrimitive, TPresence extends _voidhash_mimic0.Presence.AnyPresence | undefined = undefined>(store: StoreApi<MimicSlice<TSchema, TPresence> & CommanderSlice>) => UseDraftReturn<TSchema>;
|
|
30
31
|
//#endregion
|
|
31
32
|
export { UseDraftReturn, useDraft };
|
|
32
33
|
//# sourceMappingURL=useDraft.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDraft.d.mts","names":[],"sources":["../../src/zustand/useDraft.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDraft.d.mts","names":[],"sources":["../../src/zustand/useDraft.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAYiB,UAAA,cAAc,CAAA,gBAAiB,SAAA,CAAU,YAA3B,CAAA,CAAA;EAAiB;EAEH,SAAA,KAAA,EAA3B,cAAA,CAAe,WAAY,CAAA,OAAA,CAAA,GAAA,IAAA;EAA3B;EAA0B,SAAA,KAAA,EAAA,GAAA,GAAA,IAAA;EAiB/B;EACK,SAAU,MAAA,EAAA,GAAA,GAAA,IAAA;EACkB;EAEjB,SAAA,OAAA,EAAA,GAAA,GAAA,IAAA;;;;;;;;;;cAJhB,2BACK,SAAA,CAAU,gCACkB,gBAAA,CAAA,QAAA,CAAS,WAAA,iCAE9C,SAAS,WAAW,SAAS,aAAa,oBAChD,eAAe"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { clearActiveDraft, setActiveDraft } from "../zustand-commander/commander.mjs";
|
|
1
2
|
import { useCallback, useEffect, useRef, useSyncExternalStore } from "react";
|
|
2
3
|
|
|
3
4
|
//#region src/zustand/useDraft.ts
|
|
4
5
|
/**
|
|
5
6
|
* React hook for managing a draft lifecycle with auto-cleanup on unmount.
|
|
7
|
+
* Links the draft to the commander so that `ctx.transaction()` routes through the draft
|
|
8
|
+
* and undo/redo is disabled while the draft is active.
|
|
6
9
|
*
|
|
7
|
-
* @param store - The zustand store containing the mimic slice
|
|
10
|
+
* @param store - The zustand store containing the mimic slice and commander slice
|
|
8
11
|
* @returns Draft control methods
|
|
9
12
|
*/
|
|
10
13
|
const useDraft = (store) => {
|
|
@@ -22,41 +25,41 @@ const useDraft = (store) => {
|
|
|
22
25
|
}, []);
|
|
23
26
|
const begin = useCallback(() => {
|
|
24
27
|
if (draftRef.current !== null) throw new Error("A draft is already active. Commit or discard it first.");
|
|
25
|
-
|
|
28
|
+
const draft = store.getState().mimic.document.createDraft();
|
|
29
|
+
draftRef.current = draft;
|
|
30
|
+
setActiveDraft(store, draft);
|
|
26
31
|
bumpVersion();
|
|
27
32
|
}, [store, bumpVersion]);
|
|
28
33
|
const commit = useCallback(() => {
|
|
29
34
|
if (draftRef.current === null) return;
|
|
35
|
+
clearActiveDraft(store);
|
|
30
36
|
draftRef.current.commit();
|
|
31
37
|
draftRef.current = null;
|
|
32
38
|
bumpVersion();
|
|
33
|
-
}, [bumpVersion]);
|
|
39
|
+
}, [store, bumpVersion]);
|
|
34
40
|
const discard = useCallback(() => {
|
|
35
41
|
if (draftRef.current === null) return;
|
|
42
|
+
clearActiveDraft(store);
|
|
36
43
|
draftRef.current.discard();
|
|
37
44
|
draftRef.current = null;
|
|
38
45
|
bumpVersion();
|
|
39
|
-
}, [bumpVersion]);
|
|
40
|
-
const update = useCallback((fn) => {
|
|
41
|
-
if (draftRef.current === null) throw new Error("No active draft. Call begin() first.");
|
|
42
|
-
draftRef.current.update(fn);
|
|
43
|
-
}, []);
|
|
46
|
+
}, [store, bumpVersion]);
|
|
44
47
|
useEffect(() => {
|
|
45
48
|
return () => {
|
|
46
49
|
if (draftRef.current !== null) {
|
|
47
50
|
try {
|
|
51
|
+
clearActiveDraft(store);
|
|
48
52
|
draftRef.current.discard();
|
|
49
53
|
} catch (_unused) {}
|
|
50
54
|
draftRef.current = null;
|
|
51
55
|
}
|
|
52
56
|
};
|
|
53
|
-
}, []);
|
|
57
|
+
}, [store]);
|
|
54
58
|
return {
|
|
55
59
|
draft: draftRef.current,
|
|
56
60
|
begin,
|
|
57
61
|
commit,
|
|
58
|
-
discard
|
|
59
|
-
update
|
|
62
|
+
discard
|
|
60
63
|
};
|
|
61
64
|
};
|
|
62
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDraft.mjs","names":[],"sources":["../../src/zustand/useDraft.ts"],"sourcesContent":["import { useRef, useCallback, useEffect } from \"react\";\nimport { useSyncExternalStore } from \"react\";\nimport type { StoreApi } from \"zustand\";\nimport type { ClientDocument } from \"@voidhash/mimic/client\";\nimport type { Primitive } from \"@voidhash/mimic\";\nimport type { MimicSlice } from \"./types\";\n\n/**\n * Return type of the useDraft hook.\n */\nexport interface UseDraftReturn<TSchema extends Primitive.AnyPrimitive> {\n /** The active draft handle, or null if no draft is active */\n readonly draft: ClientDocument.DraftHandle<TSchema> | null;\n /** Creates a new draft. Throws if a draft is already active. */\n readonly begin: () => void;\n /** Commits the active draft. No-op if no draft is active. */\n readonly commit: () => void;\n /** Discards the active draft. No-op if no draft is active. */\n readonly discard: () => void;\n
|
|
1
|
+
{"version":3,"file":"useDraft.mjs","names":[],"sources":["../../src/zustand/useDraft.ts"],"sourcesContent":["import { useRef, useCallback, useEffect } from \"react\";\nimport { useSyncExternalStore } from \"react\";\nimport type { StoreApi } from \"zustand\";\nimport type { ClientDocument } from \"@voidhash/mimic/client\";\nimport type { Primitive } from \"@voidhash/mimic\";\nimport type { MimicSlice } from \"./types\";\nimport type { CommanderSlice } from \"../zustand-commander/types\";\nimport { setActiveDraft, clearActiveDraft } from \"../zustand-commander/commander\";\n\n/**\n * Return type of the useDraft hook.\n */\nexport interface UseDraftReturn<TSchema extends Primitive.AnyPrimitive> {\n /** The active draft handle, or null if no draft is active */\n readonly draft: ClientDocument.DraftHandle<TSchema> | null;\n /** Creates a new draft. Throws if a draft is already active. */\n readonly begin: () => void;\n /** Commits the active draft. No-op if no draft is active. */\n readonly commit: () => void;\n /** Discards the active draft. No-op if no draft is active. */\n readonly discard: () => void;\n}\n\n/**\n * React hook for managing a draft lifecycle with auto-cleanup on unmount.\n * Links the draft to the commander so that `ctx.transaction()` routes through the draft\n * and undo/redo is disabled while the draft is active.\n *\n * @param store - The zustand store containing the mimic slice and commander slice\n * @returns Draft control methods\n */\nexport const useDraft = <\n TSchema extends Primitive.AnyPrimitive,\n TPresence extends import(\"@voidhash/mimic\").Presence.AnyPresence | undefined = undefined,\n>(\n store: StoreApi<MimicSlice<TSchema, TPresence> & CommanderSlice>\n): UseDraftReturn<TSchema> => {\n const draftRef = useRef<ClientDocument.DraftHandle<TSchema> | null>(null);\n // Use a counter to force re-renders when draft state changes\n const versionRef = useRef(0);\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n // We piggyback on the zustand store subscription to know when drafts change\n return store.subscribe(onStoreChange);\n },\n [store]\n );\n\n const getSnapshot = useCallback(() => {\n return versionRef.current;\n }, []);\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n const bumpVersion = useCallback(() => {\n versionRef.current++;\n }, []);\n\n const begin = useCallback(() => {\n if (draftRef.current !== null) {\n throw new Error(\"A draft is already active. Commit or discard it first.\");\n }\n const document = store.getState().mimic.document;\n const draft = document.createDraft();\n draftRef.current = draft;\n setActiveDraft(store, draft);\n bumpVersion();\n }, [store, bumpVersion]);\n\n const commit = useCallback(() => {\n if (draftRef.current === null) return;\n clearActiveDraft(store);\n draftRef.current.commit();\n draftRef.current = null;\n bumpVersion();\n }, [store, bumpVersion]);\n\n const discard = useCallback(() => {\n if (draftRef.current === null) return;\n clearActiveDraft(store);\n draftRef.current.discard();\n draftRef.current = null;\n bumpVersion();\n }, [store, bumpVersion]);\n\n // Auto-discard on unmount\n useEffect(() => {\n return () => {\n if (draftRef.current !== null) {\n try {\n clearActiveDraft(store);\n draftRef.current.discard();\n } catch {\n // Draft may already be consumed\n }\n draftRef.current = null;\n }\n };\n }, [store]);\n\n return {\n draft: draftRef.current,\n begin,\n commit,\n discard,\n };\n};\n"],"mappings":";;;;;;;;;;;;AA+BA,MAAa,YAIX,UAC4B;CAC5B,MAAM,WAAW,OAAmD,KAAK;CAEzE,MAAM,aAAa,OAAO,EAAE;CAE5B,MAAM,YAAY,aACf,kBAA8B;AAE7B,SAAO,MAAM,UAAU,cAAc;IAEvC,CAAC,MAAM,CACR;CAED,MAAM,cAAc,kBAAkB;AACpC,SAAO,WAAW;IACjB,EAAE,CAAC;AAEN,sBAAqB,WAAW,aAAa,YAAY;CAEzD,MAAM,cAAc,kBAAkB;AACpC,aAAW;IACV,EAAE,CAAC;CAEN,MAAM,QAAQ,kBAAkB;AAC9B,MAAI,SAAS,YAAY,KACvB,OAAM,IAAI,MAAM,yDAAyD;EAG3E,MAAM,QADW,MAAM,UAAU,CAAC,MAAM,SACjB,aAAa;AACpC,WAAS,UAAU;AACnB,iBAAe,OAAO,MAAM;AAC5B,eAAa;IACZ,CAAC,OAAO,YAAY,CAAC;CAExB,MAAM,SAAS,kBAAkB;AAC/B,MAAI,SAAS,YAAY,KAAM;AAC/B,mBAAiB,MAAM;AACvB,WAAS,QAAQ,QAAQ;AACzB,WAAS,UAAU;AACnB,eAAa;IACZ,CAAC,OAAO,YAAY,CAAC;CAExB,MAAM,UAAU,kBAAkB;AAChC,MAAI,SAAS,YAAY,KAAM;AAC/B,mBAAiB,MAAM;AACvB,WAAS,QAAQ,SAAS;AAC1B,WAAS,UAAU;AACnB,eAAa;IACZ,CAAC,OAAO,YAAY,CAAC;AAGxB,iBAAgB;AACd,eAAa;AACX,OAAI,SAAS,YAAY,MAAM;AAC7B,QAAI;AACF,sBAAiB,MAAM;AACvB,cAAS,QAAQ,SAAS;sBACpB;AAGR,aAAS,UAAU;;;IAGtB,CAAC,MAAM,CAAC;AAEX,QAAO;EACL,OAAO,SAAS;EAChB;EACA;EACA;EACD"}
|
|
@@ -4,6 +4,21 @@ const require_types = require('./types.cjs');
|
|
|
4
4
|
//#region src/zustand-commander/commander.ts
|
|
5
5
|
const DEFAULT_OPTIONS = { maxUndoStackSize: 100 };
|
|
6
6
|
/**
|
|
7
|
+
* Build a transaction function that routes to draft or document.
|
|
8
|
+
*/
|
|
9
|
+
function buildTransaction(storeApi) {
|
|
10
|
+
return (fn) => {
|
|
11
|
+
const state = storeApi.getState();
|
|
12
|
+
const draft = state._commander.activeDraft;
|
|
13
|
+
if (draft) draft.update(fn);
|
|
14
|
+
else {
|
|
15
|
+
const mimic = state.mimic;
|
|
16
|
+
if (!(mimic === null || mimic === void 0 ? void 0 : mimic.document)) throw new Error("Commander: No active draft and no mimic document found on the store.");
|
|
17
|
+
mimic.document.transaction(fn);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
7
22
|
* Creates a commander instance bound to a specific store type.
|
|
8
23
|
*
|
|
9
24
|
* @example
|
|
@@ -15,8 +30,7 @@ const DEFAULT_OPTIONS = { maxUndoStackSize: 100 };
|
|
|
15
30
|
* const addItem = commander.action(
|
|
16
31
|
* Schema.Struct({ name: Schema.String }),
|
|
17
32
|
* (ctx, params) => {
|
|
18
|
-
*
|
|
19
|
-
* mimic.document.transaction(root => {
|
|
33
|
+
* ctx.transaction(root => {
|
|
20
34
|
* // add item
|
|
21
35
|
* });
|
|
22
36
|
* }
|
|
@@ -45,10 +59,12 @@ function createCommander(options = {}) {
|
|
|
45
59
|
const ctx = {
|
|
46
60
|
getState: () => _storeApi.getState(),
|
|
47
61
|
setState: (partial) => _storeApi.setState(partial),
|
|
48
|
-
dispatch: createDispatch()
|
|
62
|
+
dispatch: createDispatch(),
|
|
63
|
+
transaction: buildTransaction(_storeApi)
|
|
49
64
|
};
|
|
50
65
|
const result = command.fn(ctx, params);
|
|
51
|
-
|
|
66
|
+
const hasDraft = _storeApi.getState()._commander.activeDraft !== null;
|
|
67
|
+
if (require_types.isUndoableCommand(command) && !hasDraft) {
|
|
52
68
|
const entry = {
|
|
53
69
|
command,
|
|
54
70
|
params,
|
|
@@ -56,12 +72,12 @@ function createCommander(options = {}) {
|
|
|
56
72
|
timestamp: Date.now()
|
|
57
73
|
};
|
|
58
74
|
_storeApi.setState((state) => {
|
|
59
|
-
const { undoStack, redoStack } = state._commander;
|
|
75
|
+
const { undoStack, redoStack: _redoStack } = state._commander;
|
|
60
76
|
const newUndoStack = [...undoStack, entry].slice(-maxUndoStackSize);
|
|
61
|
-
return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: {
|
|
77
|
+
return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state._commander), {}, {
|
|
62
78
|
undoStack: newUndoStack,
|
|
63
79
|
redoStack: []
|
|
64
|
-
} });
|
|
80
|
+
}) });
|
|
65
81
|
});
|
|
66
82
|
}
|
|
67
83
|
return result;
|
|
@@ -96,7 +112,8 @@ function createCommander(options = {}) {
|
|
|
96
112
|
_storeApi = api;
|
|
97
113
|
return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, config(set, get, api)), {}, { _commander: {
|
|
98
114
|
undoStack: [],
|
|
99
|
-
redoStack: []
|
|
115
|
+
redoStack: [],
|
|
116
|
+
activeDraft: null
|
|
100
117
|
} });
|
|
101
118
|
};
|
|
102
119
|
};
|
|
@@ -107,39 +124,56 @@ function createCommander(options = {}) {
|
|
|
107
124
|
};
|
|
108
125
|
}
|
|
109
126
|
/**
|
|
127
|
+
* Set the active draft on the commander slice.
|
|
128
|
+
* While a draft is active, transactions route through `draft.update()` and undo is disabled.
|
|
129
|
+
*/
|
|
130
|
+
function setActiveDraft(storeApi, draft) {
|
|
131
|
+
storeApi.setState((state) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state._commander), {}, { activeDraft: draft }) }));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Clear the active draft from the commander slice.
|
|
135
|
+
*/
|
|
136
|
+
function clearActiveDraft(storeApi) {
|
|
137
|
+
storeApi.setState((state) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state._commander), {}, { activeDraft: null }) }));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
110
140
|
* Perform an undo operation on the store.
|
|
111
|
-
* Returns true if an undo was performed, false if undo stack was empty.
|
|
141
|
+
* Returns true if an undo was performed, false if undo stack was empty or a draft is active.
|
|
112
142
|
*/
|
|
113
143
|
function performUndo(storeApi) {
|
|
114
|
-
const { undoStack, redoStack } = storeApi.getState()._commander;
|
|
144
|
+
const { undoStack, redoStack, activeDraft } = storeApi.getState()._commander;
|
|
145
|
+
if (activeDraft) return false;
|
|
115
146
|
const entry = undoStack[undoStack.length - 1];
|
|
116
147
|
if (!entry) return false;
|
|
117
148
|
const newUndoStack = undoStack.slice(0, -1);
|
|
118
149
|
const ctx = {
|
|
119
150
|
getState: () => storeApi.getState(),
|
|
120
151
|
setState: (partial) => storeApi.setState(partial),
|
|
121
|
-
dispatch: createDispatchForUndo(storeApi)
|
|
152
|
+
dispatch: createDispatchForUndo(storeApi),
|
|
153
|
+
transaction: buildTransaction(storeApi)
|
|
122
154
|
};
|
|
123
155
|
entry.command.revert(ctx, entry.params, entry.result);
|
|
124
|
-
storeApi.setState((state) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: {
|
|
156
|
+
storeApi.setState((state) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state._commander), {}, {
|
|
125
157
|
undoStack: newUndoStack,
|
|
126
158
|
redoStack: [...redoStack, entry]
|
|
127
|
-
} }));
|
|
159
|
+
}) }));
|
|
128
160
|
return true;
|
|
129
161
|
}
|
|
130
162
|
/**
|
|
131
163
|
* Perform a redo operation on the store.
|
|
132
|
-
* Returns true if a redo was performed, false if redo stack was empty.
|
|
164
|
+
* Returns true if a redo was performed, false if redo stack was empty or a draft is active.
|
|
133
165
|
*/
|
|
134
166
|
function performRedo(storeApi) {
|
|
135
|
-
const { undoStack, redoStack } = storeApi.getState()._commander;
|
|
167
|
+
const { undoStack, redoStack, activeDraft } = storeApi.getState()._commander;
|
|
168
|
+
if (activeDraft) return false;
|
|
136
169
|
const entry = redoStack[redoStack.length - 1];
|
|
137
170
|
if (!entry) return false;
|
|
138
171
|
const newRedoStack = redoStack.slice(0, -1);
|
|
139
172
|
const ctx = {
|
|
140
173
|
getState: () => storeApi.getState(),
|
|
141
174
|
setState: (partial) => storeApi.setState(partial),
|
|
142
|
-
dispatch: createDispatchForUndo(storeApi)
|
|
175
|
+
dispatch: createDispatchForUndo(storeApi),
|
|
176
|
+
transaction: buildTransaction(storeApi)
|
|
143
177
|
};
|
|
144
178
|
const result = entry.command.fn(ctx, entry.params);
|
|
145
179
|
const newEntry = {
|
|
@@ -148,10 +182,10 @@ function performRedo(storeApi) {
|
|
|
148
182
|
result,
|
|
149
183
|
timestamp: Date.now()
|
|
150
184
|
};
|
|
151
|
-
storeApi.setState((state) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: {
|
|
185
|
+
storeApi.setState((state) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state._commander), {}, {
|
|
152
186
|
undoStack: [...undoStack, newEntry],
|
|
153
187
|
redoStack: newRedoStack
|
|
154
|
-
} }));
|
|
188
|
+
}) }));
|
|
155
189
|
return true;
|
|
156
190
|
}
|
|
157
191
|
/**
|
|
@@ -164,7 +198,8 @@ function createDispatchForUndo(storeApi) {
|
|
|
164
198
|
const ctx = {
|
|
165
199
|
getState: () => storeApi.getState(),
|
|
166
200
|
setState: (partial) => storeApi.setState(partial),
|
|
167
|
-
dispatch: createDispatchForUndo(storeApi)
|
|
201
|
+
dispatch: createDispatchForUndo(storeApi),
|
|
202
|
+
transaction: buildTransaction(storeApi)
|
|
168
203
|
};
|
|
169
204
|
return command.fn(ctx, params);
|
|
170
205
|
};
|
|
@@ -174,14 +209,16 @@ function createDispatchForUndo(storeApi) {
|
|
|
174
209
|
* Clear the undo and redo stacks.
|
|
175
210
|
*/
|
|
176
211
|
function clearUndoHistory(storeApi) {
|
|
177
|
-
storeApi.setState((state) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: {
|
|
212
|
+
storeApi.setState((state) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state), {}, { _commander: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, state._commander), {}, {
|
|
178
213
|
undoStack: [],
|
|
179
214
|
redoStack: []
|
|
180
|
-
} }));
|
|
215
|
+
}) }));
|
|
181
216
|
}
|
|
182
217
|
|
|
183
218
|
//#endregion
|
|
219
|
+
exports.clearActiveDraft = clearActiveDraft;
|
|
184
220
|
exports.clearUndoHistory = clearUndoHistory;
|
|
185
221
|
exports.createCommander = createCommander;
|
|
186
222
|
exports.performRedo = performRedo;
|
|
187
|
-
exports.performUndo = performUndo;
|
|
223
|
+
exports.performUndo = performUndo;
|
|
224
|
+
exports.setActiveDraft = setActiveDraft;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Commander, CommanderOptions, CommanderSlice } from "./types.cjs";
|
|
2
2
|
import { StoreApi } from "zustand";
|
|
3
|
+
import { Primitive } from "@voidhash/mimic";
|
|
4
|
+
import { ClientDocument } from "@voidhash/mimic/client";
|
|
3
5
|
|
|
4
6
|
//#region src/zustand-commander/commander.d.ts
|
|
5
7
|
|
|
@@ -15,8 +17,7 @@ import { StoreApi } from "zustand";
|
|
|
15
17
|
* const addItem = commander.action(
|
|
16
18
|
* Schema.Struct({ name: Schema.String }),
|
|
17
19
|
* (ctx, params) => {
|
|
18
|
-
*
|
|
19
|
-
* mimic.document.transaction(root => {
|
|
20
|
+
* ctx.transaction(root => {
|
|
20
21
|
* // add item
|
|
21
22
|
* });
|
|
22
23
|
* }
|
|
@@ -32,15 +33,24 @@ import { StoreApi } from "zustand";
|
|
|
32
33
|
* );
|
|
33
34
|
* ```
|
|
34
35
|
*/
|
|
35
|
-
declare function createCommander<TStore extends object>(options?: CommanderOptions): Commander<TStore & CommanderSlice>;
|
|
36
|
+
declare function createCommander<TStore extends object, TSchema extends Primitive.AnyPrimitive = Primitive.AnyPrimitive>(options?: CommanderOptions): Commander<TStore & CommanderSlice, TSchema>;
|
|
37
|
+
/**
|
|
38
|
+
* Set the active draft on the commander slice.
|
|
39
|
+
* While a draft is active, transactions route through `draft.update()` and undo is disabled.
|
|
40
|
+
*/
|
|
41
|
+
declare function setActiveDraft<TStore extends CommanderSlice>(storeApi: StoreApi<TStore>, draft: ClientDocument.DraftHandle<any>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Clear the active draft from the commander slice.
|
|
44
|
+
*/
|
|
45
|
+
declare function clearActiveDraft<TStore extends CommanderSlice>(storeApi: StoreApi<TStore>): void;
|
|
36
46
|
/**
|
|
37
47
|
* Perform an undo operation on the store.
|
|
38
|
-
* Returns true if an undo was performed, false if undo stack was empty.
|
|
48
|
+
* Returns true if an undo was performed, false if undo stack was empty or a draft is active.
|
|
39
49
|
*/
|
|
40
50
|
declare function performUndo<TStore extends CommanderSlice>(storeApi: StoreApi<TStore>): boolean;
|
|
41
51
|
/**
|
|
42
52
|
* Perform a redo operation on the store.
|
|
43
|
-
* Returns true if a redo was performed, false if redo stack was empty.
|
|
53
|
+
* Returns true if a redo was performed, false if redo stack was empty or a draft is active.
|
|
44
54
|
*/
|
|
45
55
|
declare function performRedo<TStore extends CommanderSlice>(storeApi: StoreApi<TStore>): boolean;
|
|
46
56
|
/**
|
|
@@ -48,5 +58,5 @@ declare function performRedo<TStore extends CommanderSlice>(storeApi: StoreApi<T
|
|
|
48
58
|
*/
|
|
49
59
|
declare function clearUndoHistory<TStore extends CommanderSlice>(storeApi: StoreApi<TStore>): void;
|
|
50
60
|
//#endregion
|
|
51
|
-
export { clearUndoHistory, createCommander, performRedo, performUndo };
|
|
61
|
+
export { clearActiveDraft, clearUndoHistory, createCommander, performRedo, performUndo, setActiveDraft };
|
|
52
62
|
//# sourceMappingURL=commander.d.cts.map
|