atom.io 0.33.16 → 0.33.18
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/react/index.d.ts +24 -6
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +54 -9
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts +3 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js +33 -18
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +4 -4
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js +17 -17
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts +3 -3
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/{use-o-BrXc7Qro.js → use-o-DXPncKmZ.js} +8 -8
- package/dist/use-o-DXPncKmZ.js.map +1 -0
- package/package.json +5 -5
- package/src/react/index.ts +1 -0
- package/src/react/use-loadable.ts +79 -0
- package/src/react-devtools/AtomIODevtools.tsx +85 -77
- package/src/react-devtools/store.ts +32 -10
- package/dist/use-o-BrXc7Qro.js.map +0 -1
|
@@ -24,9 +24,10 @@ import { createContext } from "react"
|
|
|
24
24
|
type DevtoolsView = `atoms` | `selectors` | `timelines` | `transactions`
|
|
25
25
|
|
|
26
26
|
export type DevtoolsStates = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
devtoolsAreHiddenAtom: RegularAtomToken<boolean>
|
|
28
|
+
devtoolsAreOpenAtom: RegularAtomToken<boolean>
|
|
29
|
+
devtoolsViewSelectionAtom: RegularAtomToken<DevtoolsView>
|
|
30
|
+
devtoolsViewOptionsAtom: RegularAtomToken<DevtoolsView[]>
|
|
30
31
|
viewIsOpenAtoms: RegularAtomFamilyToken<boolean, readonly (number | string)[]>
|
|
31
32
|
openCloseAllTX: TransactionToken<
|
|
32
33
|
(path: readonly (number | string)[], current?: boolean) => void
|
|
@@ -35,10 +36,30 @@ export type DevtoolsStates = {
|
|
|
35
36
|
|
|
36
37
|
export function attachDevtoolsStates(
|
|
37
38
|
store: Store,
|
|
39
|
+
hideByDefault = false,
|
|
38
40
|
): DevtoolsStates & IntrospectionStates & { store: Store } {
|
|
39
41
|
const introspectionStates = attachIntrospectionStates(store)
|
|
40
42
|
|
|
41
|
-
const
|
|
43
|
+
const devtoolsAreHiddenAtom = createStandaloneAtom<boolean>(store, {
|
|
44
|
+
key: `🔍 Devtools Are Hidden`,
|
|
45
|
+
default: hideByDefault,
|
|
46
|
+
effects:
|
|
47
|
+
typeof window === `undefined`
|
|
48
|
+
? []
|
|
49
|
+
: [
|
|
50
|
+
persistSync(window.localStorage, JSON, `🔍 Devtools Are Hidden`),
|
|
51
|
+
({ setSelf }) => {
|
|
52
|
+
window.addEventListener(`keydown`, (e) => {
|
|
53
|
+
if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === `a`) {
|
|
54
|
+
e.preventDefault()
|
|
55
|
+
setSelf((state) => !state)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const devtoolsAreOpenAtom = createStandaloneAtom<boolean>(store, {
|
|
42
63
|
key: `🔍 Devtools Are Open`,
|
|
43
64
|
default: true,
|
|
44
65
|
effects:
|
|
@@ -47,7 +68,7 @@ export function attachDevtoolsStates(
|
|
|
47
68
|
: [persistSync(window.localStorage, JSON, `🔍 Devtools Are Open`)],
|
|
48
69
|
})
|
|
49
70
|
|
|
50
|
-
const
|
|
71
|
+
const devtoolsViewSelectionAtom = createStandaloneAtom<DevtoolsView>(store, {
|
|
51
72
|
key: `🔍 Devtools View Selection`,
|
|
52
73
|
default: `atoms`,
|
|
53
74
|
effects:
|
|
@@ -56,7 +77,7 @@ export function attachDevtoolsStates(
|
|
|
56
77
|
: [persistSync(window.localStorage, JSON, `🔍 Devtools View`)],
|
|
57
78
|
})
|
|
58
79
|
|
|
59
|
-
const
|
|
80
|
+
const devtoolsViewOptionsAtom = createStandaloneAtom<DevtoolsView[]>(store, {
|
|
60
81
|
key: `🔍 Devtools View Options`,
|
|
61
82
|
default: [`atoms`, `selectors`, `transactions`, `timelines`],
|
|
62
83
|
effects:
|
|
@@ -84,7 +105,7 @@ export function attachDevtoolsStates(
|
|
|
84
105
|
>(store, {
|
|
85
106
|
key: `🔍 Open Close All`,
|
|
86
107
|
do: ({ get, set }, path, current) => {
|
|
87
|
-
const currentView = get(
|
|
108
|
+
const currentView = get(devtoolsViewSelectionAtom)
|
|
88
109
|
let states:
|
|
89
110
|
| WritableTokenIndex<AtomToken<unknown>>
|
|
90
111
|
| WritableTokenIndex<SelectorToken<unknown>>
|
|
@@ -153,9 +174,10 @@ export function attachDevtoolsStates(
|
|
|
153
174
|
|
|
154
175
|
return {
|
|
155
176
|
...introspectionStates,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
177
|
+
devtoolsAreHiddenAtom,
|
|
178
|
+
devtoolsAreOpenAtom,
|
|
179
|
+
devtoolsViewSelectionAtom,
|
|
180
|
+
devtoolsViewOptionsAtom,
|
|
159
181
|
viewIsOpenAtoms,
|
|
160
182
|
openCloseAllTX,
|
|
161
183
|
store,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-o-BrXc7Qro.js","names":["StoreContext: React.Context<Store>","StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}>","store: Store","token: ReadableToken<any>","setter: React.RefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t>"],"sources":["../src/react/store-context.tsx","../src/react/parse-state-overloads.ts","../src/react/use-i.ts","../src/react/use-o.ts"],"sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext: React.Context<Store> = React.createContext(\n\tIMPLICIT.STORE,\n)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\n\nexport function parseStateOverloads<T, K extends Canonical>(\n\tstore: Store,\n\t...rest: [WritableFamilyToken<T, K>, K] | [WritableToken<T>]\n): WritableToken<T>\n\nexport function parseStateOverloads<T, K extends Canonical>(\n\tstore: Store,\n\t...rest: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]\n): ReadableToken<T>\n\nexport function parseStateOverloads<T, K extends Canonical>(\n\tstore: Store,\n\t...rest: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]\n): ReadableToken<T> {\n\tlet token: ReadableToken<any>\n\tif (rest.length === 2) {\n\t\tconst family = rest[0]\n\t\tconst key = rest[1]\n\n\t\ttoken = findInStore(store, family, key)\n\t} else {\n\t\ttoken = rest[0]\n\t}\n\treturn token\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { setIntoStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { parseStateOverloads } from \"./parse-state-overloads\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: WritableToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Canonical>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Canonical>(\n\t...params: [WritableFamilyToken<T, K>, K] | [WritableToken<T>]\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\tconst token = parseStateOverloads(store, ...params)\n\tconst setter: React.RefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tsetter.current ??= (next) => {\n\t\tsetIntoStore(store, token, next)\n\t}\n\treturn setter.current\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport { getFromStore, subscribeToState } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { parseStateOverloads } from \"./parse-state-overloads\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useO<T>(token: ReadableToken<T>): T\n\nexport function useO<T, K extends Canonical>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): T\n\nexport function useO<T, K extends Canonical>(\n\t...params: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]\n): T {\n\tconst store = React.useContext(StoreContext)\n\tconst token = parseStateOverloads(store, ...params)\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(store, token, `use-o:${id}`, dispatch),\n\t\t() => getFromStore(store, token),\n\t\t() => getFromStore(store, token),\n\t)\n}\n"],"mappings":";;;;;AAIA,MAAaA,eAAqC,MAAM,cACvD,SAAS,MACT;AAED,MAAaC,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,OAAO,yBACxC,aAAa;CAAS,OAAO;CAAQ;EAAiC;;;;ACQxE,SAAgB,oBACfC,OACA,GAAG,MACgB;CACnB,IAAIC;AACJ,KAAI,KAAK,WAAW,GAAG;EACtB,MAAM,SAAS,KAAK;EACpB,MAAM,MAAM,KAAK;EAEjB,QAAQ,YAAY,OAAO,QAAQ,IAAI;CACvC,OACA,QAAQ,KAAK;AAEd,QAAO;AACP;;;;ACjBD,SAAgB,KACf,GAAG,QACsD;CACzD,MAAM,QAAQ,MAAM,WAAW,aAAa;CAC5C,MAAM,QAAQ,oBAAoB,OAAO,GAAG,OAAO;CACnD,MAAMC,SAEF,MAAM,OAAO,KAAK;CACtB,OAAO,YAAY,CAAC,SAAS;EAC5B,aAAa,OAAO,OAAO,KAAK;CAChC;AACD,QAAO,OAAO;AACd;;;;ACdD,SAAgB,KACf,GAAG,QACC;CACJ,MAAM,QAAQ,MAAM,WAAW,aAAa;CAC5C,MAAM,QAAQ,oBAAoB,OAAO,GAAG,OAAO;CACnD,MAAM,KAAK,MAAM,OAAO;AACxB,QAAO,MAAM,qBACZ,CAAC,aAAa,iBAAiB,OAAO,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EACrE,MAAM,aAAa,OAAO,MAAM,EAChC,MAAM,aAAa,OAAO,MAAM,CAChC;AACD"}
|