atom.io 0.15.3 → 0.15.5
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/data/dist/index.cjs +29 -16
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.js +30 -17
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +15 -2
- package/dist/index.cjs +32 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +153 -85
- package/dist/index.js +157 -1
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +98 -159
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +44 -32
- package/internal/dist/index.js +89 -105
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-regular-atom.ts +1 -1
- package/internal/src/get-environment-data.ts +18 -0
- package/internal/src/index.ts +2 -0
- package/internal/src/ingest-updates/index.ts +3 -0
- package/internal/src/ingest-updates/ingest-atom-update.ts +14 -0
- package/internal/src/ingest-updates/ingest-selector-update.ts +17 -0
- package/internal/src/ingest-updates/ingest-transaction-update.ts +22 -0
- package/internal/src/mutable/tracker.ts +4 -4
- package/internal/src/not-found-error.ts +3 -8
- package/internal/src/operation.ts +4 -4
- package/internal/src/selector/create-read-write-selector.ts +6 -4
- package/internal/src/selector/create-readonly-selector.ts +3 -3
- package/internal/src/selector/register-selector.ts +6 -4
- package/internal/src/selector/update-selector-atoms.ts +2 -2
- package/internal/src/store/deposit.ts +5 -5
- package/internal/src/store/store.ts +4 -4
- package/internal/src/store/withdraw-new-family-member.ts +8 -11
- package/internal/src/store/withdraw.ts +11 -12
- package/internal/src/subscribe/subscribe-to-state.ts +2 -2
- package/internal/src/subscribe/subscribe-to-timeline.ts +4 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +7 -7
- package/internal/src/timeline/create-timeline.ts +29 -21
- package/internal/src/timeline/time-travel.ts +19 -45
- package/internal/src/transaction/apply-transaction.ts +5 -51
- package/internal/src/transaction/build-transaction.ts +9 -2
- package/internal/src/transaction/create-transaction.ts +4 -4
- package/internal/src/transaction/index.ts +2 -2
- package/introspection/dist/index.cjs +9 -9
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +6 -6
- package/introspection/dist/index.js +9 -9
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +4 -4
- package/introspection/src/attach-introspection-states.ts +2 -2
- package/introspection/src/attach-selector-index.ts +4 -4
- package/introspection/src/attach-timeline-family.ts +6 -6
- package/introspection/src/attach-timeline-index.ts +6 -4
- package/introspection/src/attach-transaction-index.ts +1 -1
- package/introspection/src/index.ts +1 -1
- package/package.json +11 -12
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +4 -4
- package/react/dist/index.js.map +1 -1
- package/react/src/store-hooks.ts +5 -5
- package/react-devtools/dist/index.cjs +7 -9
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.ts +10 -265
- package/react-devtools/dist/index.js +7 -9
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +3 -3
- package/react-devtools/src/StateIndex.tsx +3 -3
- package/react-devtools/src/TimelineIndex.tsx +2 -2
- package/react-devtools/src/Updates.tsx +1 -1
- package/realtime-client/dist/index.cjs +68 -66
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +8 -7
- package/realtime-client/dist/index.js +63 -62
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/pull-family-member.ts +1 -1
- package/realtime-client/src/pull.ts +1 -1
- package/realtime-client/src/push.ts +2 -3
- package/realtime-client/src/realtime-state.ts +11 -3
- package/realtime-client/src/server-action.ts +65 -65
- package/realtime-react/dist/index.cjs +90 -56
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +11 -6
- package/realtime-react/dist/index.js +89 -55
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/on-mount.ts +23 -0
- package/realtime-react/src/realtime-context.tsx +14 -6
- package/realtime-react/src/use-pull-family-member.ts +5 -8
- package/realtime-react/src/use-pull-mutable-family-member.ts +4 -7
- package/realtime-react/src/use-pull-mutable.ts +4 -7
- package/realtime-react/src/use-pull.ts +5 -8
- package/realtime-react/src/use-push.ts +5 -9
- package/realtime-react/src/use-realtime-service.ts +30 -0
- package/realtime-react/src/use-server-action.ts +8 -8
- package/realtime-server/dist/index.cjs +109 -40
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +7 -6
- package/realtime-server/dist/index.js +90 -39
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/hook-composition/expose-family.ts +2 -2
- package/realtime-server/src/hook-composition/expose-mutable-family.ts +1 -1
- package/realtime-server/src/hook-composition/expose-single.ts +1 -1
- package/realtime-server/src/hook-composition/index.ts +2 -1
- package/realtime-server/src/hook-composition/receive-state.ts +2 -2
- package/realtime-server/src/hook-composition/receive-transaction.ts +13 -32
- package/realtime-server/src/hook-composition/sync-transaction.ts +92 -0
- package/realtime-testing/dist/index.cjs +3 -3
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.js +2 -2
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +4 -3
- package/src/atom.ts +30 -7
- package/src/dispose.ts +2 -2
- package/src/find-state.ts +64 -0
- package/src/get-state.ts +2 -2
- package/src/index.ts +23 -0
- package/src/logger.ts +1 -0
- package/src/selector.ts +16 -0
- package/src/set-state.ts +2 -2
- package/src/silo.ts +2 -2
- package/src/subscribe.ts +7 -11
- package/src/timeline.ts +20 -12
- package/src/transaction.ts +31 -12
- package/src/validators.ts +74 -0
- package/dist/chunk-K22LR3V6.js +0 -138
- package/dist/chunk-K22LR3V6.js.map +0 -1
- package/internal/src/set-state/copy-mutable-into-new-store.ts +0 -34
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
newest,
|
|
8
8
|
} from "atom.io/internal"
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type { WritableTokenIndex } from "."
|
|
11
11
|
|
|
12
|
-
export type AtomTokenIndex =
|
|
12
|
+
export type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>
|
|
13
13
|
|
|
14
14
|
export const attachAtomIndex = (
|
|
15
15
|
store: Store = IMPLICIT.STORE,
|
|
@@ -28,7 +28,7 @@ export const attachAtomIndex = (
|
|
|
28
28
|
},
|
|
29
29
|
effects: [
|
|
30
30
|
({ setSelf }) => {
|
|
31
|
-
store.
|
|
31
|
+
store.on.atomCreation.subscribe(`introspection`, (atomToken) => {
|
|
32
32
|
if (atomToken.key.includes(`👁🗨`)) {
|
|
33
33
|
return
|
|
34
34
|
}
|
|
@@ -61,7 +61,7 @@ export const attachAtomIndex = (
|
|
|
61
61
|
}
|
|
62
62
|
})
|
|
63
63
|
if (newest(store).operation.open) {
|
|
64
|
-
const unsubscribe = store.
|
|
64
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
65
65
|
`introspection: waiting to update atom index`,
|
|
66
66
|
() => {
|
|
67
67
|
unsubscribe()
|
|
@@ -24,8 +24,8 @@ export const attachIntrospectionStates = (
|
|
|
24
24
|
selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>
|
|
25
25
|
transactionIndex: ReadonlySelectorToken<TransactionToken<ƒn>[]>
|
|
26
26
|
findTransactionLogState: ReadonlySelectorFamily<TransactionUpdate<ƒn>[]>
|
|
27
|
-
timelineIndex: ReadonlySelectorToken<TimelineToken[]>
|
|
28
|
-
findTimelineState: ReadonlySelectorFamily<Timeline
|
|
27
|
+
timelineIndex: ReadonlySelectorToken<TimelineToken<any>[]>
|
|
28
|
+
findTimelineState: ReadonlySelectorFamily<Timeline<any>>
|
|
29
29
|
} => {
|
|
30
30
|
return {
|
|
31
31
|
atomIndex: attachAtomIndex(store),
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
newest,
|
|
8
8
|
} from "atom.io/internal"
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type { WritableTokenIndex } from "."
|
|
11
11
|
|
|
12
|
-
export type SelectorTokenIndex =
|
|
12
|
+
export type SelectorTokenIndex = WritableTokenIndex<
|
|
13
13
|
ReadonlySelectorToken<unknown> | SelectorToken<unknown>
|
|
14
14
|
>
|
|
15
15
|
|
|
@@ -35,7 +35,7 @@ export const attachSelectorIndex = (
|
|
|
35
35
|
),
|
|
36
36
|
effects: [
|
|
37
37
|
({ setSelf }) => {
|
|
38
|
-
store.
|
|
38
|
+
store.on.selectorCreation.subscribe(
|
|
39
39
|
`introspection`,
|
|
40
40
|
(selectorToken) => {
|
|
41
41
|
if (selectorToken.key.includes(`👁🗨`)) {
|
|
@@ -70,7 +70,7 @@ export const attachSelectorIndex = (
|
|
|
70
70
|
}
|
|
71
71
|
})
|
|
72
72
|
if (newest(store).operation.open) {
|
|
73
|
-
const unsubscribe = store.
|
|
73
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
74
74
|
`introspection: waiting to update selector index`,
|
|
75
75
|
() => {
|
|
76
76
|
unsubscribe()
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
|
|
10
10
|
export const attachTimelineFamily = (
|
|
11
11
|
store: Store = IMPLICIT.STORE,
|
|
12
|
-
): ReadonlySelectorFamily<Timeline
|
|
12
|
+
): ReadonlySelectorFamily<Timeline<any>> => {
|
|
13
13
|
const findTimelineLogState__INTERNAL = createRegularAtomFamily<
|
|
14
|
-
Timeline
|
|
14
|
+
Timeline<any>,
|
|
15
15
|
string
|
|
16
16
|
>(
|
|
17
17
|
{
|
|
@@ -33,10 +33,10 @@ export const attachTimelineFamily = (
|
|
|
33
33
|
const tl = store.timelines.get(key)
|
|
34
34
|
tl?.subject.subscribe(`introspection`, (_) => {
|
|
35
35
|
if (store.operation.open === true) {
|
|
36
|
-
const unsubscribe = store.
|
|
36
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
37
37
|
`introspection`,
|
|
38
|
-
(
|
|
39
|
-
if (
|
|
38
|
+
(operationClose) => {
|
|
39
|
+
if (operationClose.open === false) {
|
|
40
40
|
unsubscribe()
|
|
41
41
|
setSelf({ ...tl })
|
|
42
42
|
}
|
|
@@ -51,7 +51,7 @@ export const attachTimelineFamily = (
|
|
|
51
51
|
},
|
|
52
52
|
store,
|
|
53
53
|
)
|
|
54
|
-
const findTimelineLogState = createSelectorFamily<Timeline
|
|
54
|
+
const findTimelineLogState = createSelectorFamily<Timeline<any>, string>(
|
|
55
55
|
{
|
|
56
56
|
key: `👁🗨 Timeline Update Log`,
|
|
57
57
|
get:
|
|
@@ -4,17 +4,19 @@ import { IMPLICIT, createRegularAtom, createSelector } from "atom.io/internal"
|
|
|
4
4
|
|
|
5
5
|
export const attachTimelineIndex = (
|
|
6
6
|
store: Store = IMPLICIT.STORE,
|
|
7
|
-
): ReadonlySelectorToken<TimelineToken[]> => {
|
|
8
|
-
const timelineTokenIndexState__INTERNAL = createRegularAtom<
|
|
7
|
+
): ReadonlySelectorToken<TimelineToken<any>[]> => {
|
|
8
|
+
const timelineTokenIndexState__INTERNAL = createRegularAtom<
|
|
9
|
+
TimelineToken<any>[]
|
|
10
|
+
>(
|
|
9
11
|
{
|
|
10
12
|
key: `👁🗨 Timeline Token Index (Internal)`,
|
|
11
13
|
default: () =>
|
|
12
|
-
[...store.timelines].map(([key]): TimelineToken => {
|
|
14
|
+
[...store.timelines].map(([key]): TimelineToken<any> => {
|
|
13
15
|
return { key, type: `timeline` }
|
|
14
16
|
}),
|
|
15
17
|
effects: [
|
|
16
18
|
({ setSelf }) => {
|
|
17
|
-
store.
|
|
19
|
+
store.on.timelineCreation.subscribe(
|
|
18
20
|
`introspection`,
|
|
19
21
|
(timelineToken) => {
|
|
20
22
|
setSelf((state) => [...state, timelineToken])
|
|
@@ -16,7 +16,7 @@ export const attachTransactionIndex = (
|
|
|
16
16
|
}),
|
|
17
17
|
effects: [
|
|
18
18
|
({ setSelf }) => {
|
|
19
|
-
store.
|
|
19
|
+
store.on.transactionCreation.subscribe(
|
|
20
20
|
`introspection`,
|
|
21
21
|
(transactionToken) => {
|
|
22
22
|
setSelf((state) => [...state, transactionToken])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.5",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,19 +48,18 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@emotion/react": "11.11.3",
|
|
52
51
|
"@testing-library/react": "14.1.2",
|
|
53
52
|
"@types/http-proxy": "1.17.14",
|
|
54
53
|
"@types/npmlog": "7.0.0",
|
|
55
|
-
"@types/react": "18.2.
|
|
54
|
+
"@types/react": "18.2.47",
|
|
56
55
|
"@types/tmp": "0.2.6",
|
|
57
|
-
"@vitest/coverage-v8": "1.1.
|
|
58
|
-
"@vitest/ui": "1.1.
|
|
56
|
+
"@vitest/coverage-v8": "1.1.3",
|
|
57
|
+
"@vitest/ui": "1.1.3",
|
|
59
58
|
"concurrently": "8.2.2",
|
|
60
|
-
"drizzle-kit": "0.20.
|
|
61
|
-
"drizzle-orm": "0.29.
|
|
59
|
+
"drizzle-kit": "0.20.10",
|
|
60
|
+
"drizzle-orm": "0.29.3",
|
|
62
61
|
"eslint": "8.56.0",
|
|
63
|
-
"framer-motion": "10.
|
|
62
|
+
"framer-motion": "10.17.9",
|
|
64
63
|
"happy-dom": "12.10.3",
|
|
65
64
|
"http-proxy": "1.18.1",
|
|
66
65
|
"npmlog": "7.0.1",
|
|
@@ -69,14 +68,14 @@
|
|
|
69
68
|
"react": "18.2.0",
|
|
70
69
|
"react-dom": "18.2.0",
|
|
71
70
|
"react-router-dom": "6.21.1",
|
|
72
|
-
"socket.io": "4.7.
|
|
73
|
-
"socket.io-client": "4.7.
|
|
71
|
+
"socket.io": "4.7.3",
|
|
72
|
+
"socket.io-client": "4.7.3",
|
|
74
73
|
"tmp": "0.2.1",
|
|
75
74
|
"tsup": "8.0.1",
|
|
76
75
|
"typescript": "5.3.3",
|
|
77
|
-
"vite": "5.0.
|
|
76
|
+
"vite": "5.0.11",
|
|
78
77
|
"vite-tsconfig-paths": "4.2.3",
|
|
79
|
-
"vitest": "1.1.
|
|
78
|
+
"vitest": "1.1.3"
|
|
80
79
|
},
|
|
81
80
|
"main": "dist/index.js",
|
|
82
81
|
"types": "dist/index.d.ts",
|
package/react/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store-context.tsx","../src/store-hooks.ts"],"names":["React"],"mappings":";AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACVhD,YAAYA,YAAW;AAEvB,SAAS,UAAU,MAAM,UAAU,YAAY;AAQ/C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAIA,SAAS,KACf,OACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,SAAS,OAAO,MAAM,KAAK;AAAA,EACvD;AACA,SAAO,OAAO;AACf;AAEO,SAAS,KAAQ,
|
|
1
|
+
{"version":3,"sources":["../src/store-context.tsx","../src/store-hooks.ts"],"names":["React"],"mappings":";AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,M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,WAC1C,SAAS,YAAY,OACpB;AACD,eAAS,UAAU;AACnB,WAAK,UAAU,YAAY;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EACb;AACA,SAAa;AAAA,IACZ,CAAC,aAAa,oBAAoB,OAAO,UAAU,UAAU,EAAE,IAAI,KAAK;AAAA,IACxE;AAAA,IACA;AAAA,EACD;AACD","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\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 * as React from \"react\"\n\nimport { getState, redo, setState, undo } from \"atom.io\"\nimport type {\n\tMutableAtomToken,\n\tReadableToken,\n\tTimelineToken,\n\tWritableToken,\n} from \"atom.io\"\n\nimport {\n\tgetJsonToken,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\twithdraw,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\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\tconst store = React.useContext(StoreContext)\n\tconst setter: React.MutableRefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tif (setter.current === null) {\n\t\tsetter.current = (next) => setState(token, next, store)\n\t}\n\treturn setter.current\n}\n\nexport function useO<T>(token: ReadableToken<T>): T {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),\n\t\t() => getState(token, store),\n\t\t() => getState(token, store),\n\t)\n}\n\nexport function useJSON<Serializable extends Json.Serializable>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable {\n\tconst jsonToken = getJsonToken(token)\n\treturn useO(jsonToken)\n}\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken<any>): TimelineMeta {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\tconst timeline = withdraw(token, store)\n\tconst tokenRef = React.useRef(token)\n\tconst rebuildMeta = () => {\n\t\treturn {\n\t\t\tat: timeline?.at ?? NaN,\n\t\t\tlength: timeline?.history.length ?? NaN,\n\t\t\tundo: () => undo(token),\n\t\t\tredo: () => redo(token),\n\t\t}\n\t}\n\tconst meta = React.useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = () => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length ||\n\t\t\ttokenRef.current !== token\n\t\t) {\n\t\t\ttokenRef.current = token\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}\n\treturn React.useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"]}
|
package/react/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Store } from 'atom.io/internal';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { WritableToken, ReadableToken, MutableAtomToken, TimelineToken } from 'atom.io';
|
|
4
4
|
import { Json } from 'atom.io/json';
|
|
5
5
|
|
|
6
6
|
declare const StoreContext: React.Context<Store>;
|
|
@@ -9,8 +9,8 @@ declare const StoreProvider: React.FC<{
|
|
|
9
9
|
store?: Store;
|
|
10
10
|
}>;
|
|
11
11
|
|
|
12
|
-
declare function useI<T>(token:
|
|
13
|
-
declare function useO<T>(token:
|
|
12
|
+
declare function useI<T>(token: WritableToken<T>): <New extends T>(next: New | ((old: T) => New)) => void;
|
|
13
|
+
declare function useO<T>(token: ReadableToken<T>): T;
|
|
14
14
|
declare function useJSON<Serializable extends Json.Serializable>(token: MutableAtomToken<any, Serializable>): Serializable;
|
|
15
15
|
type TimelineMeta = {
|
|
16
16
|
at: number;
|
|
@@ -18,6 +18,6 @@ type TimelineMeta = {
|
|
|
18
18
|
undo: () => void;
|
|
19
19
|
redo: () => void;
|
|
20
20
|
};
|
|
21
|
-
declare function useTL(token: TimelineToken): TimelineMeta;
|
|
21
|
+
declare function useTL(token: TimelineToken<any>): TimelineMeta;
|
|
22
22
|
|
|
23
23
|
export { StoreContext, StoreProvider, type TimelineMeta, useI, useJSON, useO, useTL };
|
package/react/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store-context.tsx","../src/store-hooks.ts"],"names":["React"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACVhD,YAAYA,YAAW;AAEvB,SAAS,UAAU,MAAM,UAAU,YAAY;AAQ/C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAIA,SAAS,KACf,OACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,SAAS,OAAO,MAAM,KAAK;AAAA,EACvD;AACA,SAAO,OAAO;AACf;AAEO,SAAS,KAAQ,
|
|
1
|
+
{"version":3,"sources":["../src/store-context.tsx","../src/store-hooks.ts"],"names":["React"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gB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C9B,KAAK,QAAQ,YAAW,qCAAU,QAAQ,WAC1C,SAAS,YAAY,OACpB;AACD,eAAS,UAAU;AACnB,WAAK,UAAU,YAAY;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EACb;AACA,SAAa;AAAA,IACZ,CAAC,aAAa,oBAAoB,OAAO,UAAU,UAAU,EAAE,IAAI,KAAK;AAAA,IACxE;AAAA,IACA;AAAA,EACD;AACD","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\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 * as React from \"react\"\n\nimport { getState, redo, setState, undo } from \"atom.io\"\nimport type {\n\tMutableAtomToken,\n\tReadableToken,\n\tTimelineToken,\n\tWritableToken,\n} from \"atom.io\"\n\nimport {\n\tgetJsonToken,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\twithdraw,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\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\tconst store = React.useContext(StoreContext)\n\tconst setter: React.MutableRefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tif (setter.current === null) {\n\t\tsetter.current = (next) => setState(token, next, store)\n\t}\n\treturn setter.current\n}\n\nexport function useO<T>(token: ReadableToken<T>): T {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),\n\t\t() => getState(token, store),\n\t\t() => getState(token, store),\n\t)\n}\n\nexport function useJSON<Serializable extends Json.Serializable>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable {\n\tconst jsonToken = getJsonToken(token)\n\treturn useO(jsonToken)\n}\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken<any>): TimelineMeta {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\tconst timeline = withdraw(token, store)\n\tconst tokenRef = React.useRef(token)\n\tconst rebuildMeta = () => {\n\t\treturn {\n\t\t\tat: timeline?.at ?? NaN,\n\t\t\tlength: timeline?.history.length ?? NaN,\n\t\t\tundo: () => undo(token),\n\t\t\tredo: () => redo(token),\n\t\t}\n\t}\n\tconst meta = React.useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = () => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length ||\n\t\t\ttokenRef.current !== token\n\t\t) {\n\t\t\ttokenRef.current = token\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}\n\treturn React.useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"]}
|
package/react/src/store-hooks.ts
CHANGED
|
@@ -3,9 +3,9 @@ import * as React from "react"
|
|
|
3
3
|
import { getState, redo, setState, undo } from "atom.io"
|
|
4
4
|
import type {
|
|
5
5
|
MutableAtomToken,
|
|
6
|
-
|
|
7
|
-
StateToken,
|
|
6
|
+
ReadableToken,
|
|
8
7
|
TimelineToken,
|
|
8
|
+
WritableToken,
|
|
9
9
|
} from "atom.io"
|
|
10
10
|
|
|
11
11
|
import {
|
|
@@ -18,7 +18,7 @@ import type { Json } from "atom.io/json"
|
|
|
18
18
|
import { StoreContext } from "./store-context"
|
|
19
19
|
|
|
20
20
|
export function useI<T>(
|
|
21
|
-
token:
|
|
21
|
+
token: WritableToken<T>,
|
|
22
22
|
): <New extends T>(next: New | ((old: T) => New)) => void {
|
|
23
23
|
const store = React.useContext(StoreContext)
|
|
24
24
|
const setter: React.MutableRefObject<
|
|
@@ -30,7 +30,7 @@ export function useI<T>(
|
|
|
30
30
|
return setter.current
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function useO<T>(token:
|
|
33
|
+
export function useO<T>(token: ReadableToken<T>): T {
|
|
34
34
|
const store = React.useContext(StoreContext)
|
|
35
35
|
const id = React.useId()
|
|
36
36
|
return React.useSyncExternalStore<T>(
|
|
@@ -54,7 +54,7 @@ export type TimelineMeta = {
|
|
|
54
54
|
redo: () => void
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export function useTL(token: TimelineToken): TimelineMeta {
|
|
57
|
+
export function useTL(token: TimelineToken<any>): TimelineMeta {
|
|
58
58
|
const store = React.useContext(StoreContext)
|
|
59
59
|
const id = React.useId()
|
|
60
60
|
const timeline = withdraw(token, store)
|
|
@@ -947,7 +947,6 @@ var valueToText = (numericValue) => {
|
|
|
947
947
|
};
|
|
948
948
|
var NumberInput = ({
|
|
949
949
|
autoSize = false,
|
|
950
|
-
customCss,
|
|
951
950
|
decimalPlaces,
|
|
952
951
|
disabled = false,
|
|
953
952
|
label,
|
|
@@ -996,7 +995,7 @@ var NumberInput = ({
|
|
|
996
995
|
}
|
|
997
996
|
};
|
|
998
997
|
const displayValue = temporaryEntry != null ? temporaryEntry : valueToText(value ? refine(value) : value);
|
|
999
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span", {
|
|
998
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
1000
999
|
label && /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, children: label }),
|
|
1001
1000
|
autoSize ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1002
1001
|
ElasticInput,
|
|
@@ -1034,10 +1033,9 @@ var TextInput = ({
|
|
|
1034
1033
|
set,
|
|
1035
1034
|
label,
|
|
1036
1035
|
placeholder,
|
|
1037
|
-
customCss,
|
|
1038
1036
|
autoSize = false
|
|
1039
1037
|
}) => {
|
|
1040
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span", {
|
|
1038
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
1041
1039
|
/* @__PURE__ */ jsxRuntime.jsx("label", { children: label }),
|
|
1042
1040
|
autoSize ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1043
1041
|
ElasticInput,
|
|
@@ -1081,7 +1079,7 @@ var JsonEditor_INTERNAL = ({
|
|
|
1081
1079
|
isReadonly = () => false,
|
|
1082
1080
|
isHidden = () => false,
|
|
1083
1081
|
className,
|
|
1084
|
-
|
|
1082
|
+
style,
|
|
1085
1083
|
Header: HeaderDisplay,
|
|
1086
1084
|
Components
|
|
1087
1085
|
}) => {
|
|
@@ -1089,7 +1087,7 @@ var JsonEditor_INTERNAL = ({
|
|
|
1089
1087
|
const refined = dataIsJson ? refineJsonType(data) : { type: `non-json`, data };
|
|
1090
1088
|
const SubEditor = dataIsJson ? SubEditors[refined.type] : NonJsonEditor;
|
|
1091
1089
|
const disabled = isReadonly(path);
|
|
1092
|
-
return isHidden(path) ? null : /* @__PURE__ */ jsxRuntime.jsx(Components.ErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsxs(Components.EditorWrapper, { className,
|
|
1090
|
+
return isHidden(path) ? null : /* @__PURE__ */ jsxRuntime.jsx(Components.ErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsxs(Components.EditorWrapper, { className, style, children: [
|
|
1093
1091
|
remove && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1094
1092
|
Components.Button,
|
|
1095
1093
|
{
|
|
@@ -1874,7 +1872,7 @@ var DEFAULT_JSON_EDITOR_COMPONENTS = {
|
|
|
1874
1872
|
children
|
|
1875
1873
|
}
|
|
1876
1874
|
),
|
|
1877
|
-
EditorWrapper: ({ children,
|
|
1875
|
+
EditorWrapper: ({ children, className }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: `json_editor ` + className, children }),
|
|
1878
1876
|
EditorLayout: ({
|
|
1879
1877
|
DeleteButton,
|
|
1880
1878
|
Header,
|
|
@@ -1916,8 +1914,8 @@ var JsonEditor = ({
|
|
|
1916
1914
|
isHidden = () => false,
|
|
1917
1915
|
// isIllegal = () => false,
|
|
1918
1916
|
className,
|
|
1919
|
-
customCss,
|
|
1920
1917
|
Header,
|
|
1918
|
+
style,
|
|
1921
1919
|
Components: CustomComponents = {}
|
|
1922
1920
|
}) => {
|
|
1923
1921
|
const Components = __spreadValues(__spreadValues({}, DEFAULT_JSON_EDITOR_COMPONENTS), CustomComponents);
|
|
@@ -1934,8 +1932,8 @@ var JsonEditor = ({
|
|
|
1934
1932
|
isReadonly,
|
|
1935
1933
|
isHidden,
|
|
1936
1934
|
className,
|
|
1937
|
-
customCss,
|
|
1938
1935
|
Header,
|
|
1936
|
+
style,
|
|
1939
1937
|
Components
|
|
1940
1938
|
}
|
|
1941
1939
|
);
|