atom.io 0.6.8 → 0.6.9
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/index.d.mts +226 -258
- package/dist/index.d.ts +226 -258
- package/dist/index.js +28 -1917
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1877
- package/dist/index.mjs.map +1 -1
- package/introspection/dist/index.d.mts +117 -171
- package/introspection/dist/index.d.ts +117 -171
- package/introspection/dist/index.js +6 -346
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +5 -324
- package/introspection/dist/index.mjs.map +1 -1
- package/json/dist/index.d.mts +32 -1
- package/json/dist/index.d.ts +32 -1
- package/json/dist/index.js +31 -48
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +6 -14
- package/json/dist/index.mjs.map +1 -1
- package/package.json +22 -14
- package/react/dist/index.js +34 -83
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +7 -43
- package/react/dist/index.mjs.map +1 -1
- package/react-devtools/dist/index.css +1 -50
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +124 -188
- package/react-devtools/dist/index.d.ts +124 -188
- package/react-devtools/dist/index.js +56 -4674
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +19 -4642
- package/react-devtools/dist/index.mjs.map +1 -1
- package/realtime/dist/index.d.mts +1 -3
- package/realtime/dist/index.d.ts +1 -3
- package/realtime/dist/index.js +26 -184
- package/realtime/dist/index.js.map +1 -1
- package/realtime/dist/index.mjs +4 -148
- package/realtime/dist/index.mjs.map +1 -1
- package/realtime-react/dist/index.d.mts +2 -4
- package/realtime-react/dist/index.d.ts +2 -4
- package/realtime-react/dist/index.js +41 -214
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +9 -169
- package/realtime-react/dist/index.mjs.map +1 -1
- package/src/atom.ts +4 -3
- package/src/index.ts +12 -9
- package/src/logger.ts +5 -5
- package/src/selector.ts +3 -3
- package/src/silo.ts +36 -39
- package/src/subscribe.ts +24 -19
- package/src/timeline.ts +9 -4
- package/src/transaction.ts +3 -4
- package/src/internal/atom-internal.ts +0 -54
- package/src/internal/families-internal.ts +0 -144
- package/src/internal/get.ts +0 -129
- package/src/internal/index.ts +0 -15
- package/src/internal/is-default.ts +0 -35
- package/src/internal/operation.ts +0 -139
- package/src/internal/selector/create-read-write-selector.ts +0 -68
- package/src/internal/selector/create-readonly-selector.ts +0 -48
- package/src/internal/selector/index.ts +0 -4
- package/src/internal/selector/lookup-selector-sources.ts +0 -16
- package/src/internal/selector/register-selector.ts +0 -57
- package/src/internal/selector/trace-selector-atoms.ts +0 -43
- package/src/internal/selector/update-selector-atoms.ts +0 -33
- package/src/internal/selector-internal.ts +0 -58
- package/src/internal/set.ts +0 -99
- package/src/internal/store.ts +0 -151
- package/src/internal/subscribe-internal.ts +0 -88
- package/src/internal/time-travel-internal.ts +0 -91
- package/src/internal/timeline/add-atom-to-timeline.ts +0 -168
- package/src/internal/timeline/index.ts +0 -1
- package/src/internal/timeline-internal.ts +0 -107
- package/src/internal/transaction/abort-transaction.ts +0 -12
- package/src/internal/transaction/apply-transaction.ts +0 -57
- package/src/internal/transaction/build-transaction.ts +0 -33
- package/src/internal/transaction/index.ts +0 -25
- package/src/internal/transaction/redo-transaction.ts +0 -23
- package/src/internal/transaction/undo-transaction.ts +0 -23
- package/src/internal/transaction-internal.ts +0 -61
- package/src/introspection/attach-atom-index.ts +0 -73
- package/src/introspection/attach-introspection-states.ts +0 -42
- package/src/introspection/attach-selector-index.ts +0 -77
- package/src/introspection/attach-timeline-family.ts +0 -59
- package/src/introspection/attach-timeline-index.ts +0 -36
- package/src/introspection/attach-transaction-index.ts +0 -38
- package/src/introspection/attach-transaction-logs.ts +0 -40
- package/src/introspection/index.ts +0 -20
- package/src/json/index.ts +0 -1
- package/src/json/select-json.ts +0 -18
- package/src/react/index.ts +0 -2
- package/src/react/store-context.tsx +0 -13
- package/src/react/store-hooks.ts +0 -47
- package/src/react-devtools/AtomIODevtools.tsx +0 -107
- package/src/react-devtools/Button.tsx +0 -24
- package/src/react-devtools/StateEditor.tsx +0 -74
- package/src/react-devtools/StateIndex.tsx +0 -156
- package/src/react-devtools/TimelineIndex.tsx +0 -92
- package/src/react-devtools/TransactionIndex.tsx +0 -70
- package/src/react-devtools/Updates.tsx +0 -145
- package/src/react-devtools/devtools.scss +0 -310
- package/src/react-devtools/index.ts +0 -72
- package/src/react-explorer/AtomIOExplorer.tsx +0 -218
- package/src/react-explorer/explorer-effects.ts +0 -20
- package/src/react-explorer/explorer-states.ts +0 -217
- package/src/react-explorer/index.ts +0 -23
- package/src/react-explorer/space-states.ts +0 -72
- package/src/react-explorer/view-states.ts +0 -41
- package/src/realtime/README.md +0 -33
- package/src/realtime/hook-composition/expose-family.ts +0 -101
- package/src/realtime/hook-composition/expose-single.ts +0 -38
- package/src/realtime/hook-composition/expose-timeline.ts +0 -60
- package/src/realtime/hook-composition/index.ts +0 -12
- package/src/realtime/hook-composition/receive-state.ts +0 -29
- package/src/realtime/hook-composition/receive-transaction.ts +0 -18
- package/src/realtime/index.ts +0 -1
- package/src/realtime-react/index.ts +0 -3
- package/src/realtime-react/realtime-context.tsx +0 -30
- package/src/realtime-react/realtime-hooks.ts +0 -39
- package/src/realtime-react/realtime-state.ts +0 -10
- package/src/realtime-react/use-pull-family-member.ts +0 -26
- package/src/realtime-react/use-pull-family.ts +0 -24
- package/src/realtime-react/use-pull.ts +0 -24
- package/src/realtime-react/use-push.ts +0 -27
- package/src/realtime-react/use-server-action.ts +0 -33
- package/src/realtime-testing/index.ts +0 -1
- package/src/realtime-testing/setup-realtime-test.tsx +0 -159
- package/src/tracker/index.ts +0 -3
- package/src/tracker/tracker.ts +0 -61
- package/src/web-effects/index.ts +0 -1
- package/src/web-effects/storage.ts +0 -30
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
main.atom_io_devtools {
|
|
2
|
-
--fg-color: #eee;
|
|
3
|
-
--bg-color: #111;
|
|
4
|
-
--bg-tint1: #222;
|
|
5
|
-
--fg-border: 1px solid var(--fg-color);
|
|
6
|
-
@media (prefers-color-scheme: light) {
|
|
7
|
-
--fg-color: #444;
|
|
8
|
-
--bg-color: #ddd;
|
|
9
|
-
--bg-tint1: #e3e3e3;
|
|
10
|
-
}
|
|
11
|
-
box-sizing: border-box;
|
|
12
|
-
color: var(--fg-color);
|
|
13
|
-
background-color: var(--bg-color);
|
|
14
|
-
border: 2px solid var(--fg-color);
|
|
15
|
-
position: fixed;
|
|
16
|
-
right: 0;
|
|
17
|
-
bottom: 0;
|
|
18
|
-
height: 100%;
|
|
19
|
-
display: flex;
|
|
20
|
-
flex-flow: column;
|
|
21
|
-
max-height: 800px;
|
|
22
|
-
width: 100%;
|
|
23
|
-
max-width: 500px;
|
|
24
|
-
overflow-y: scroll;
|
|
25
|
-
* {
|
|
26
|
-
font-size: 16px;
|
|
27
|
-
font-family: theia, monospace;
|
|
28
|
-
}
|
|
29
|
-
> header {
|
|
30
|
-
padding: 5px;
|
|
31
|
-
padding-left: 10px;
|
|
32
|
-
padding-bottom: 0;
|
|
33
|
-
display: flex;
|
|
34
|
-
justify-content: space-between;
|
|
35
|
-
h1 {
|
|
36
|
-
font-size: inherit;
|
|
37
|
-
margin: 0;
|
|
38
|
-
font-size: 24px;
|
|
39
|
-
font-family: charter;
|
|
40
|
-
}
|
|
41
|
-
nav {
|
|
42
|
-
display: flex;
|
|
43
|
-
flex-flow: row nowrap;
|
|
44
|
-
button {
|
|
45
|
-
cursor: pointer;
|
|
46
|
-
background: none;
|
|
47
|
-
border: none;
|
|
48
|
-
padding: none;
|
|
49
|
-
margin-bottom: -2px;
|
|
50
|
-
z-index: 1000;
|
|
51
|
-
&:disabled {
|
|
52
|
-
cursor: default;
|
|
53
|
-
background-color: var(--bg-tint1);
|
|
54
|
-
color: var(--fg-color);
|
|
55
|
-
border: var(--fg-border);
|
|
56
|
-
border-bottom: none;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
> main {
|
|
62
|
-
background: var(--bg-tint1);
|
|
63
|
-
}
|
|
64
|
-
main {
|
|
65
|
-
overflow-y: scroll;
|
|
66
|
-
flex-grow: 1;
|
|
67
|
-
display: flex;
|
|
68
|
-
flex-flow: column;
|
|
69
|
-
gap: 0;
|
|
70
|
-
article.index {
|
|
71
|
-
.node .node {
|
|
72
|
-
border-right: var(--fg-border);
|
|
73
|
-
padding-right: 0;
|
|
74
|
-
background: #fff3;
|
|
75
|
-
}
|
|
76
|
-
.node > .node {
|
|
77
|
-
margin: 5px 0;
|
|
78
|
-
margin-left: 12px;
|
|
79
|
-
border-left: var(--fg-border);
|
|
80
|
-
}
|
|
81
|
-
.node {
|
|
82
|
-
border-top: var(--fg-border);
|
|
83
|
-
overflow-x: scroll;
|
|
84
|
-
padding: 5px;
|
|
85
|
-
&:last-of-type {
|
|
86
|
-
border-bottom: var(--fg-border);
|
|
87
|
-
}
|
|
88
|
-
&.transaction_update {
|
|
89
|
-
padding: 0;
|
|
90
|
-
}
|
|
91
|
-
header {
|
|
92
|
-
display: flex;
|
|
93
|
-
flex-flow: row;
|
|
94
|
-
gap: 5px;
|
|
95
|
-
position: sticky;
|
|
96
|
-
z-index: 999;
|
|
97
|
-
top: 0;
|
|
98
|
-
button.carat {
|
|
99
|
-
cursor: pointer;
|
|
100
|
-
background: none;
|
|
101
|
-
border: none;
|
|
102
|
-
width: 20px;
|
|
103
|
-
&.open {
|
|
104
|
-
transform: rotate(90deg);
|
|
105
|
-
}
|
|
106
|
-
&:disabled {
|
|
107
|
-
cursor: default;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
label {
|
|
111
|
-
display: flex;
|
|
112
|
-
flex-flow: row;
|
|
113
|
-
gap: 5px;
|
|
114
|
-
cursor: help;
|
|
115
|
-
h2 {
|
|
116
|
-
display: inline-block;
|
|
117
|
-
margin: 0;
|
|
118
|
-
}
|
|
119
|
-
.detail {
|
|
120
|
-
color: #777;
|
|
121
|
-
@media (prefers-color-scheme: light) {
|
|
122
|
-
color: #999;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
main {
|
|
128
|
-
margin-left: 15px;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
section.transaction_log {
|
|
132
|
-
margin-top: 0;
|
|
133
|
-
header: {
|
|
134
|
-
padding: 5px;
|
|
135
|
-
}
|
|
136
|
-
main {
|
|
137
|
-
display: flex;
|
|
138
|
-
flex-flow: row wrap;
|
|
139
|
-
gap: 5px;
|
|
140
|
-
.transaction_update {
|
|
141
|
-
width: 100%;
|
|
142
|
-
display: flex;
|
|
143
|
-
flex-flow: row;
|
|
144
|
-
align-items: flex-start;
|
|
145
|
-
justify-content: flex-start;
|
|
146
|
-
justify-items: flex-start;
|
|
147
|
-
align-content: flex-start;
|
|
148
|
-
border-left: var(--fg-border);
|
|
149
|
-
border-top: var(--fg-border);
|
|
150
|
-
header {
|
|
151
|
-
padding: 5px;
|
|
152
|
-
h4 {
|
|
153
|
-
margin: 0;
|
|
154
|
-
padding: 0;
|
|
155
|
-
font-size: inherit;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
main {
|
|
159
|
-
margin-left: 0;
|
|
160
|
-
display: flex;
|
|
161
|
-
flex-flow: column;
|
|
162
|
-
gap: 0px;
|
|
163
|
-
border-left: 1px solid #333;
|
|
164
|
-
section ~ section {
|
|
165
|
-
border-top: 1px solid #333;
|
|
166
|
-
}
|
|
167
|
-
section {
|
|
168
|
-
padding: 5px;
|
|
169
|
-
&.transaction_output {
|
|
170
|
-
border-right: none;
|
|
171
|
-
}
|
|
172
|
-
&.transaction_impact {
|
|
173
|
-
padding: 5px;
|
|
174
|
-
}
|
|
175
|
-
margin: 0;
|
|
176
|
-
article {
|
|
177
|
-
border-left: var(--fg-border);
|
|
178
|
-
border-right: var(--fg-border);
|
|
179
|
-
.summary {
|
|
180
|
-
white-space: nowrap;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
section.timeline_log {
|
|
189
|
-
header {
|
|
190
|
-
display: flex;
|
|
191
|
-
label {
|
|
192
|
-
display: flex;
|
|
193
|
-
width: 100%;
|
|
194
|
-
flex-grow: 1;
|
|
195
|
-
.gap {
|
|
196
|
-
flex-grow: 1;
|
|
197
|
-
}
|
|
198
|
-
nav {
|
|
199
|
-
display: flex;
|
|
200
|
-
flex-flow: row nowrap;
|
|
201
|
-
gap: 5px;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
.timeline_update {
|
|
206
|
-
padding: 5px;
|
|
207
|
-
border-left: var(--fg-border);
|
|
208
|
-
h4 {
|
|
209
|
-
margin: 0;
|
|
210
|
-
padding: 0;
|
|
211
|
-
font-size: inherit;
|
|
212
|
-
}
|
|
213
|
-
main {
|
|
214
|
-
margin: 0;
|
|
215
|
-
.node.atom_update {
|
|
216
|
-
border-left: var(--fg-border);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
.you_are_here {
|
|
221
|
-
background: var(--fg-color);
|
|
222
|
-
color: var(--bg-color);
|
|
223
|
-
text-align: center;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
footer {
|
|
229
|
-
display: flex;
|
|
230
|
-
justify-content: flex-end;
|
|
231
|
-
button {
|
|
232
|
-
cursor: pointer;
|
|
233
|
-
background: none;
|
|
234
|
-
border: none;
|
|
235
|
-
padding: none;
|
|
236
|
-
position: absolute;
|
|
237
|
-
right: 0;
|
|
238
|
-
bottom: 0;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
.json_editor {
|
|
243
|
-
input {
|
|
244
|
-
font-family: theia;
|
|
245
|
-
border: none;
|
|
246
|
-
border-bottom: 1px solid;
|
|
247
|
-
background: none;
|
|
248
|
-
&:disabled {
|
|
249
|
-
border: none;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
button {
|
|
253
|
-
background: none;
|
|
254
|
-
margin-left: auto;
|
|
255
|
-
color: #777;
|
|
256
|
-
border: none;
|
|
257
|
-
font-family: theia;
|
|
258
|
-
font-size: 14px;
|
|
259
|
-
margin: none;
|
|
260
|
-
padding: 4px;
|
|
261
|
-
padding-bottom: 6px;
|
|
262
|
-
cursor: pointer;
|
|
263
|
-
&:hover {
|
|
264
|
-
color: #333;
|
|
265
|
-
background-color: #aaa;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
select {
|
|
269
|
-
font-family: theia;
|
|
270
|
-
font-size: 14px;
|
|
271
|
-
background: none;
|
|
272
|
-
border: none;
|
|
273
|
-
color: #777;
|
|
274
|
-
@media (prefers-color-scheme: light) {
|
|
275
|
-
color: #999;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
.json_editor_unofficial {
|
|
279
|
-
background-color: #777;
|
|
280
|
-
button {
|
|
281
|
-
color: #333;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
.json_editor_missing {
|
|
285
|
-
background-color: #f055;
|
|
286
|
-
}
|
|
287
|
-
.json_editor_key {
|
|
288
|
-
padding-right: 10px;
|
|
289
|
-
input {
|
|
290
|
-
color: #999;
|
|
291
|
-
@media (prefers-color-scheme: light) {
|
|
292
|
-
color: #777;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
.json_editor_object {
|
|
297
|
-
border-left: 2px solid #333;
|
|
298
|
-
padding-left: 20px;
|
|
299
|
-
@media (prefers-color-scheme: light) {
|
|
300
|
-
border-color: #ccc;
|
|
301
|
-
}
|
|
302
|
-
.json_editor_properties {
|
|
303
|
-
> * {
|
|
304
|
-
border-bottom: var(--fg-border);
|
|
305
|
-
margin-bottom: 2px;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { isPlainObject } from "~/packages/anvl/src/object"
|
|
2
|
-
import { Refinery } from "~/packages/anvl/src/refinement/refinery"
|
|
3
|
-
import {
|
|
4
|
-
diffArray,
|
|
5
|
-
diffBoolean,
|
|
6
|
-
diffNumber,
|
|
7
|
-
diffObject,
|
|
8
|
-
diffString,
|
|
9
|
-
Differ,
|
|
10
|
-
} from "~/packages/anvl/src/tree/differ"
|
|
11
|
-
|
|
12
|
-
import { atom, atomFamily } from ".."
|
|
13
|
-
import { attachIntrospectionStates } from "../introspection"
|
|
14
|
-
import { lazyLocalStorageEffect } from "../web-effects"
|
|
15
|
-
|
|
16
|
-
export * from "./AtomIODevtools"
|
|
17
|
-
|
|
18
|
-
export const {
|
|
19
|
-
atomIndex,
|
|
20
|
-
selectorIndex,
|
|
21
|
-
transactionIndex,
|
|
22
|
-
findTransactionLogState,
|
|
23
|
-
timelineIndex,
|
|
24
|
-
findTimelineState,
|
|
25
|
-
} = attachIntrospectionStates()
|
|
26
|
-
|
|
27
|
-
export const devtoolsAreOpenState = atom<boolean>({
|
|
28
|
-
key: `👁🗨 Devtools Are Open`,
|
|
29
|
-
default: true,
|
|
30
|
-
effects: [lazyLocalStorageEffect(`👁🗨 Devtools Are Open`)],
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
type DevtoolsView = `atoms` | `selectors` | `timelines` | `transactions`
|
|
34
|
-
|
|
35
|
-
export const devtoolsViewSelectionState = atom<DevtoolsView>({
|
|
36
|
-
key: `👁🗨 Devtools View Selection`,
|
|
37
|
-
default: `atoms`,
|
|
38
|
-
effects: [lazyLocalStorageEffect(`👁🗨 Devtools View`)],
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
export const devtoolsViewOptionsState = atom<DevtoolsView[]>({
|
|
42
|
-
key: `👁🗨 Devtools View Options`,
|
|
43
|
-
default: [`atoms`, `selectors`, `transactions`, `timelines`],
|
|
44
|
-
effects: [lazyLocalStorageEffect(`👁🗨 Devtools View Options`)],
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
export const findViewIsOpenState = atomFamily<boolean, string>({
|
|
48
|
-
key: `👁🗨 Devtools View Is Open`,
|
|
49
|
-
default: false,
|
|
50
|
-
effects: (key) => [lazyLocalStorageEffect(key + `:view-is-open`)],
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
export const primitiveRefinery = new Refinery({
|
|
54
|
-
number: (input: unknown): input is number => typeof input === `number`,
|
|
55
|
-
string: (input: unknown): input is string => typeof input === `string`,
|
|
56
|
-
boolean: (input: unknown): input is boolean => typeof input === `boolean`,
|
|
57
|
-
null: (input: unknown): input is null => input === null,
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
export const jsonTreeRefinery = new Refinery({
|
|
61
|
-
object: isPlainObject,
|
|
62
|
-
array: (input: unknown): input is unknown[] => Array.isArray(input),
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
export const prettyJson = new Differ(primitiveRefinery, jsonTreeRefinery, {
|
|
66
|
-
number: diffNumber,
|
|
67
|
-
string: diffString,
|
|
68
|
-
boolean: diffBoolean,
|
|
69
|
-
null: () => ({ summary: `No Change` }),
|
|
70
|
-
object: diffObject,
|
|
71
|
-
array: diffArray,
|
|
72
|
-
})
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import type { StoreHooks } from "atom.io/react"
|
|
2
|
-
import type { FC, ReactNode } from "react"
|
|
3
|
-
import { useEffect } from "react"
|
|
4
|
-
import { Link, MemoryRouter, useLocation } from "react-router-dom"
|
|
5
|
-
|
|
6
|
-
import { RecoverableErrorBoundary } from "~/packages/hamr/src/react-error-boundary"
|
|
7
|
-
import type { WC } from "~/packages/hamr/src/react-json-editor"
|
|
8
|
-
|
|
9
|
-
import { attachExplorerState } from "./explorer-states"
|
|
10
|
-
import { setState } from ".."
|
|
11
|
-
import { runTransaction } from "../transaction"
|
|
12
|
-
|
|
13
|
-
export type ExplorerOptions = {
|
|
14
|
-
key: string
|
|
15
|
-
Components?: {
|
|
16
|
-
SpaceWrapper: WC
|
|
17
|
-
CloseSpaceButton: FC<{ onClick: () => void }>
|
|
18
|
-
}
|
|
19
|
-
storeHooks: StoreHooks
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const DEFAULT_COMPONENTS: ExplorerOptions[`Components`] = {
|
|
23
|
-
SpaceWrapper: ({ children }) => <div>{children}</div>,
|
|
24
|
-
CloseSpaceButton: ({ onClick }) => (
|
|
25
|
-
<button type="button" onClick={onClick}>
|
|
26
|
-
X
|
|
27
|
-
</button>
|
|
28
|
-
),
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const composeExplorer = ({
|
|
32
|
-
key,
|
|
33
|
-
Components,
|
|
34
|
-
storeHooks: { useO, useIO },
|
|
35
|
-
}: ExplorerOptions): ReturnType<typeof attachExplorerState> & {
|
|
36
|
-
Explorer: FC<{ children: ReactNode }>
|
|
37
|
-
useSetTitle: (viewId: string) => void
|
|
38
|
-
} => {
|
|
39
|
-
const { SpaceWrapper, CloseSpaceButton } = {
|
|
40
|
-
...DEFAULT_COMPONENTS,
|
|
41
|
-
...Components,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const state = attachExplorerState(key)
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
addSpace,
|
|
48
|
-
addView,
|
|
49
|
-
allViewsState,
|
|
50
|
-
findSpaceFocusedViewState,
|
|
51
|
-
findSpaceLayoutNode,
|
|
52
|
-
findSpaceViewsState,
|
|
53
|
-
findViewFocusedState,
|
|
54
|
-
findViewState,
|
|
55
|
-
removeSpace,
|
|
56
|
-
removeView,
|
|
57
|
-
spaceLayoutState,
|
|
58
|
-
viewIndexState,
|
|
59
|
-
} = state
|
|
60
|
-
|
|
61
|
-
const View: FC<{
|
|
62
|
-
children: ReactNode
|
|
63
|
-
viewId: string
|
|
64
|
-
}> = ({ children, viewId }) => {
|
|
65
|
-
const location = useLocation()
|
|
66
|
-
const viewState = findViewState(viewId)
|
|
67
|
-
const [view, setView] = useIO(viewState)
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
setView((view) => ({ ...view, location }))
|
|
70
|
-
}, [location.key])
|
|
71
|
-
return (
|
|
72
|
-
<div className="view">
|
|
73
|
-
<header>
|
|
74
|
-
<h1>{view.title}</h1>
|
|
75
|
-
<CloseSpaceButton onClick={() => runTransaction(removeView)(viewId)} />
|
|
76
|
-
</header>
|
|
77
|
-
<main>{children}</main>
|
|
78
|
-
<footer>
|
|
79
|
-
<nav>
|
|
80
|
-
{location.pathname.split(`/`).map((pathPiece, idx, array) =>
|
|
81
|
-
pathPiece === `` && idx === 1 ? null : (
|
|
82
|
-
<Link
|
|
83
|
-
to={array.slice(0, idx + 1).join(`/`)}
|
|
84
|
-
key={`${pathPiece}_${viewId}`}
|
|
85
|
-
>
|
|
86
|
-
{idx === 0 ? `home` : pathPiece}/
|
|
87
|
-
</Link>
|
|
88
|
-
),
|
|
89
|
-
)}
|
|
90
|
-
</nav>
|
|
91
|
-
</footer>
|
|
92
|
-
</div>
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const Tab: FC<{ viewId: string; spaceId: string }> = ({ viewId, spaceId }) => {
|
|
97
|
-
const view = useO(findViewState(viewId))
|
|
98
|
-
const [spaceFocusedView, setSpaceFocusedView] = useIO(
|
|
99
|
-
findSpaceFocusedViewState(spaceId),
|
|
100
|
-
)
|
|
101
|
-
const handleClick = () => setSpaceFocusedView(viewId)
|
|
102
|
-
return (
|
|
103
|
-
<div
|
|
104
|
-
className={`tab ${spaceFocusedView === viewId ? `focused` : ``}`}
|
|
105
|
-
onClick={handleClick}
|
|
106
|
-
onKeyUp={handleClick}
|
|
107
|
-
>
|
|
108
|
-
{view.title}
|
|
109
|
-
</div>
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const TabBar: FC<{
|
|
114
|
-
spaceId: string
|
|
115
|
-
viewIds: string[]
|
|
116
|
-
}> = ({ spaceId, viewIds }) => {
|
|
117
|
-
return (
|
|
118
|
-
<nav className="tab-bar">
|
|
119
|
-
{viewIds.map((viewId) => (
|
|
120
|
-
<Tab key={viewId} viewId={viewId} spaceId={spaceId} />
|
|
121
|
-
))}
|
|
122
|
-
</nav>
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const Space: FC<{
|
|
127
|
-
children: ReactNode
|
|
128
|
-
focusedViewId: string
|
|
129
|
-
spaceId: string
|
|
130
|
-
viewIds: string[]
|
|
131
|
-
}> = ({ children, focusedViewId, spaceId, viewIds }) => {
|
|
132
|
-
const view = useO(findViewState(focusedViewId))
|
|
133
|
-
return (
|
|
134
|
-
<div className="space">
|
|
135
|
-
<RecoverableErrorBoundary>
|
|
136
|
-
<MemoryRouter
|
|
137
|
-
initialEntries={view.location ? [view.location.pathname] : []}
|
|
138
|
-
>
|
|
139
|
-
<TabBar spaceId={spaceId} viewIds={viewIds} />
|
|
140
|
-
<View viewId={focusedViewId}>{children}</View>
|
|
141
|
-
</MemoryRouter>
|
|
142
|
-
</RecoverableErrorBoundary>
|
|
143
|
-
</div>
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const Spaces: FC<{ children: ReactNode; spaceId?: string }> = ({
|
|
148
|
-
children,
|
|
149
|
-
spaceId = `root`,
|
|
150
|
-
}) => {
|
|
151
|
-
const spaceLayout = useO(findSpaceLayoutNode(spaceId))
|
|
152
|
-
const viewIds = useO(findSpaceViewsState(spaceId))
|
|
153
|
-
const focusedViewId = useO(findSpaceFocusedViewState(spaceId))
|
|
154
|
-
return (
|
|
155
|
-
<div className="spaces">
|
|
156
|
-
{spaceLayout.childSpaceIds.length === 0 ? (
|
|
157
|
-
focusedViewId ? (
|
|
158
|
-
<Space
|
|
159
|
-
focusedViewId={focusedViewId}
|
|
160
|
-
spaceId={spaceId}
|
|
161
|
-
viewIds={viewIds}
|
|
162
|
-
>
|
|
163
|
-
{children}
|
|
164
|
-
</Space>
|
|
165
|
-
) : (
|
|
166
|
-
`no view`
|
|
167
|
-
)
|
|
168
|
-
) : (
|
|
169
|
-
spaceLayout.childSpaceIds.map((childSpaceId) => (
|
|
170
|
-
<Spaces key={childSpaceId} spaceId={childSpaceId}>
|
|
171
|
-
{children}
|
|
172
|
-
</Spaces>
|
|
173
|
-
))
|
|
174
|
-
)}
|
|
175
|
-
<button
|
|
176
|
-
type="button"
|
|
177
|
-
onClick={() => runTransaction(addView)({ spaceId })}
|
|
178
|
-
>
|
|
179
|
-
+ View
|
|
180
|
-
</button>
|
|
181
|
-
<button
|
|
182
|
-
type="button"
|
|
183
|
-
onClick={() => runTransaction(addSpace)({ parentId: spaceId })}
|
|
184
|
-
>
|
|
185
|
-
+ Space
|
|
186
|
-
</button>
|
|
187
|
-
</div>
|
|
188
|
-
)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const Explorer: FC<{ children: ReactNode }> = ({ children }) => {
|
|
192
|
-
return <Spaces>{children}</Spaces>
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const useSetTitle = (title: string): void => {
|
|
196
|
-
let location: ReturnType<typeof useLocation>
|
|
197
|
-
try {
|
|
198
|
-
location = useLocation()
|
|
199
|
-
} catch (thrown) {
|
|
200
|
-
console.warn(
|
|
201
|
-
`Failed to set title to "${title}"; useSetTitle must be called within the children of Explorer`,
|
|
202
|
-
)
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
const views = useO(allViewsState)
|
|
206
|
-
const locationView = views.find(
|
|
207
|
-
([, view]) => view.location.key === location.key,
|
|
208
|
-
)
|
|
209
|
-
const viewId = locationView?.[0] ?? null
|
|
210
|
-
useEffect(() => {
|
|
211
|
-
if (viewId) {
|
|
212
|
-
setState(findViewState(viewId), (v) => ({ ...v, title }))
|
|
213
|
-
}
|
|
214
|
-
}, [viewId])
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return { Explorer, useSetTitle, ...state }
|
|
218
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { isArray } from "~/packages/anvl/src/array"
|
|
2
|
-
import { parseJson, stringifyJson } from "~/packages/anvl/src/json"
|
|
3
|
-
|
|
4
|
-
import { persistAtom } from "../web-effects"
|
|
5
|
-
|
|
6
|
-
export const persistStringSetAtom = persistAtom<Set<string>>(localStorage)({
|
|
7
|
-
stringify: (set) => stringifyJson([...set]),
|
|
8
|
-
parse: (string) => {
|
|
9
|
-
try {
|
|
10
|
-
const json = parseJson(string)
|
|
11
|
-
const array = isArray((v): v is string => typeof v === `string`)(json)
|
|
12
|
-
? json
|
|
13
|
-
: []
|
|
14
|
-
return new Set(array)
|
|
15
|
-
} catch (thrown) {
|
|
16
|
-
console.error(`Error parsing spaceIndexState from localStorage`)
|
|
17
|
-
return new Set()
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
})
|