alinea 2.0.0-preview.3 → 2.0.0-preview.4

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.
Files changed (154) hide show
  1. package/dist/.init/content/pages/welcome.json +1 -1
  2. package/dist/LICENSES.md +144 -90
  3. package/dist/adapter/next/DevRemote.js +10 -2
  4. package/dist/adapter/next/previews.js +1 -0
  5. package/dist/backend/Handler.js +14 -7
  6. package/dist/backend/api/BasicAuth.d.ts +1 -1
  7. package/dist/backend/api/BasicAuth.js +14 -14
  8. package/dist/backend/api/OAuth2.d.ts +3 -3
  9. package/dist/backend/api/OAuth2.js +7 -4
  10. package/dist/bundled.d.ts +96 -25
  11. package/dist/chunks/{chunk-Y7XOMJOC.js → chunk-CFNRVI3Y.js} +220 -247
  12. package/dist/chunks/chunk-D6UJHBJJ.js +183 -0
  13. package/dist/chunks/chunk-TIJTT5ZI.js +228 -0
  14. package/dist/chunks/{chunk-HFBZMKIN.js → chunk-XMOVGDFI.js} +1 -1
  15. package/dist/cli/Serve.js +1 -1
  16. package/dist/cli/bin.js +1 -1
  17. package/dist/cli/serve/LocalAuth.js +1 -1
  18. package/dist/cloud/AuthResult.d.ts +2 -0
  19. package/dist/cloud/CloudHandshake.d.ts +7 -0
  20. package/dist/cloud/CloudHandshake.js +64 -0
  21. package/dist/cloud/CloudRemote.d.ts +4 -1
  22. package/dist/cloud/CloudRemote.js +21 -3
  23. package/dist/components/Calendar.js +6 -6
  24. package/dist/components/Checkbox.js +2 -2
  25. package/dist/components/ComboBox.js +12 -12
  26. package/dist/components/DatePicker.js +4 -4
  27. package/dist/components/DateRangePicker.js +4 -4
  28. package/dist/components/Disclosure.js +6 -6
  29. package/dist/components/Label.js +6 -6
  30. package/dist/components/List.js +37 -37
  31. package/dist/components/Menu.js +4 -4
  32. package/dist/components/Modal.js +2 -2
  33. package/dist/components/MultipleSelect.js +23 -23
  34. package/dist/components/NumberField.js +5 -5
  35. package/dist/components/ProgressCircle.js +4 -4
  36. package/dist/components/SearchField.js +7 -7
  37. package/dist/components/Select.js +6 -6
  38. package/dist/components/Surface.js +1 -1
  39. package/dist/components/Table.js +8 -8
  40. package/dist/components/TextField.js +4 -4
  41. package/dist/components/TimeField.js +4 -4
  42. package/dist/components/Toggle.d.ts +1 -1
  43. package/dist/components/Toggle.js +2 -2
  44. package/dist/components/Toolbar.js +3 -3
  45. package/dist/components/Tooltip.js +2 -2
  46. package/dist/components/Tree.js +6 -6
  47. package/dist/core/Connection.d.ts +7 -4
  48. package/dist/core/Entry.d.ts +6 -0
  49. package/dist/core/Entry.js +10 -0
  50. package/dist/core/Id.d.ts +1 -0
  51. package/dist/core/Id.js +8 -0
  52. package/dist/core/db/Operation.js +4 -3
  53. package/dist/dashboard/App.js +30 -16
  54. package/dist/dashboard/StoryProvider.js +2 -2
  55. package/dist/dashboard/app/AccessDenied.js +3 -3
  56. package/dist/dashboard/app/ActivityStatus.js +23 -23
  57. package/dist/dashboard/app/AppShell.js +2 -2
  58. package/dist/dashboard/app/AppearanceToggle.d.ts +1 -0
  59. package/dist/dashboard/app/AppearanceToggle.js +43 -0
  60. package/dist/dashboard/app/AuthView.d.ts +1 -1
  61. package/dist/dashboard/app/AuthView.js +17 -19
  62. package/dist/dashboard/app/Badge.js +2 -2
  63. package/dist/dashboard/app/CompactField.js +17 -17
  64. package/dist/dashboard/app/DashboardErrorBoundary.js +23 -11
  65. package/dist/dashboard/app/DashboardLayout.js +15 -8
  66. package/dist/dashboard/app/DashboardMeta.d.ts +2 -1
  67. package/dist/dashboard/app/DashboardMeta.js +20 -5
  68. package/dist/dashboard/app/EntryFields.js +6 -6
  69. package/dist/dashboard/app/EntryHeader.js +27 -27
  70. package/dist/dashboard/app/EntryReferences.js +15 -15
  71. package/dist/dashboard/app/EntrySidebar.js +24 -24
  72. package/dist/dashboard/app/EntrySidebarPreview.js +20 -19
  73. package/dist/dashboard/app/EntryTranslationBanner.js +5 -5
  74. package/dist/dashboard/app/Explorer.js +64 -64
  75. package/dist/dashboard/app/ExplorerCards.js +46 -46
  76. package/dist/dashboard/app/ExplorerFileCard.js +19 -19
  77. package/dist/dashboard/app/ExplorerList.js +20 -20
  78. package/dist/dashboard/app/ExplorerModal.js +5 -5
  79. package/dist/dashboard/app/ExplorerPickerContent.js +2 -2
  80. package/dist/dashboard/app/ExplorerTable.js +63 -63
  81. package/dist/dashboard/app/ImagePicker.js +7 -7
  82. package/dist/dashboard/app/LinkPicker.js +17 -22
  83. package/dist/dashboard/app/LocaleMenu.js +10 -12
  84. package/dist/dashboard/app/SidebarLayout.js +4 -4
  85. package/dist/dashboard/app/SidebarTree.js +58 -58
  86. package/dist/dashboard/app/WorkspaceMenu.d.ts +10 -3
  87. package/dist/dashboard/app/WorkspaceMenu.js +88 -67
  88. package/dist/dashboard/app/WorkspaceMenu.stories.d.ts +2 -0
  89. package/dist/dashboard/app/WorkspaceRoots.d.ts +3 -1
  90. package/dist/dashboard/app/WorkspaceRoots.js +86 -111
  91. package/dist/dashboard/app/editor/FileEditor.js +29 -29
  92. package/dist/dashboard/app/editor/FilePreview.js +6 -6
  93. package/dist/dashboard/app/editor/MediaAltField.view.js +4 -4
  94. package/dist/dashboard/app/modals/CreateEntry.js +15 -15
  95. package/dist/dashboard/app/pages/EntryPage.js +29 -31
  96. package/dist/dashboard/app/pages/RootPage.js +4 -4
  97. package/dist/dashboard/app/pages/SplashPage.d.ts +3 -0
  98. package/dist/dashboard/app/pages/SplashPage.js +414 -0
  99. package/dist/dashboard/app/pages/UsersPage.js +42 -42
  100. package/dist/dashboard/app/ui/DashboardModal.js +16 -16
  101. package/dist/dashboard/app/ui/Rail.js +3 -3
  102. package/dist/dashboard/app/ui/Sidebar.js +2 -2
  103. package/dist/dashboard/atoms/ReactiveNode.js +1 -1
  104. package/dist/dashboard/atoms/activity.js +2 -3
  105. package/dist/dashboard/atoms/auth.d.ts +2 -0
  106. package/dist/dashboard/atoms/auth.js +6 -2
  107. package/dist/dashboard/atoms/config.js +1 -1
  108. package/dist/dashboard/atoms/core.js +2 -2
  109. package/dist/dashboard/atoms/create.js +1 -1
  110. package/dist/dashboard/atoms/dashboard.js +2 -2
  111. package/dist/dashboard/atoms/editor.js +1 -1
  112. package/dist/dashboard/atoms/entry.js +2 -2
  113. package/dist/dashboard/atoms/explorer.d.ts +1 -3
  114. package/dist/dashboard/atoms/explorer.js +7 -9
  115. package/dist/dashboard/atoms/graph.d.ts +1 -0
  116. package/dist/dashboard/atoms/graph.js +7 -2
  117. package/dist/dashboard/atoms/link.js +2 -2
  118. package/dist/dashboard/atoms/nav.d.ts +4 -3
  119. package/dist/dashboard/atoms/nav.js +10 -5
  120. package/dist/dashboard/atoms/preview.js +1 -1
  121. package/dist/dashboard/atoms/root.js +2 -2
  122. package/dist/dashboard/atoms/upload.js +1 -1
  123. package/dist/dashboard/atoms/user.d.ts +1 -1
  124. package/dist/dashboard/atoms/user.js +8 -6
  125. package/dist/dashboard/atoms/utils.js +2 -2
  126. package/dist/dashboard/boot/Boot.js +2 -4
  127. package/dist/dashboard/boot/DashboardWorker.js +34 -29
  128. package/dist/dashboard/editor/UseField.js +6 -6
  129. package/dist/dashboard/fixture/cms.d.ts +12 -0
  130. package/dist/dashboard/fixture/cms.js +53 -2
  131. package/dist/dashboard/hook/UseGraph.js +4 -4
  132. package/dist/dashboard/hook/UseRoot.js +4 -4
  133. package/dist/dashboard/hooks.js +16 -16
  134. package/dist/field/code/CodeField.view.js +12 -12
  135. package/dist/field/link/LinkField.view.js +56 -56
  136. package/dist/field/list/ListField.view.js +24 -24
  137. package/dist/field/localiser/LocalisedField.view.js +76 -5
  138. package/dist/field/metadata/MetadataField.view.js +19 -19
  139. package/dist/field/richtext/PickTextLink.js +6 -6
  140. package/dist/field/richtext/RichTextBlock.js +4 -4
  141. package/dist/field/richtext/RichTextBlocks.js +1 -1
  142. package/dist/field/richtext/RichTextExtensions.js +19 -19
  143. package/dist/field/richtext/RichTextField.view.js +6 -6
  144. package/dist/field/richtext/RichTextInsertMenu.js +3 -3
  145. package/dist/field/richtext/RichTextState.js +1 -1
  146. package/dist/field/text/TextField.view.js +2 -2
  147. package/dist/index.css +415 -28
  148. package/dist/preview/RegisterPreview.d.ts +1 -1
  149. package/dist/preview/RegisterPreview.js +4 -6
  150. package/dist/preview/react.d.ts +5 -1
  151. package/dist/preview/react.js +12 -9
  152. package/package.json +1 -1
  153. package/dist/chunks/chunk-STAJCW4Z.js +0 -322
  154. package/dist/chunks/chunk-U4VOHNR2.js +0 -210
@@ -1,322 +0,0 @@
1
- import {
2
- atom
3
- } from "./chunk-Y7XOMJOC.js";
4
-
5
- // node_modules/jotai/esm/vanilla/utils.mjs
6
- var RESET = /* @__PURE__ */ Symbol(
7
- (import.meta.env ? "production" : void 0) !== "production" ? "RESET" : ""
8
- );
9
- var didWarnDeprecation$1 = false;
10
- function atomFamily(initializeAtom, areEqual) {
11
- if ((import.meta.env ? "production" : void 0) !== "production" && !didWarnDeprecation$1) {
12
- console.warn(
13
- "[DEPRECATED] atomFamily is deprecated and will be removed in v3. Please use the `jotai-family` package instead: https://github.com/jotaijs/jotai-family"
14
- );
15
- didWarnDeprecation$1 = true;
16
- }
17
- let shouldRemove = null;
18
- const atoms = /* @__PURE__ */ new Map();
19
- const listeners = /* @__PURE__ */ new Set();
20
- const createAtom = (param) => {
21
- let item;
22
- if (areEqual === void 0) {
23
- item = atoms.get(param);
24
- } else {
25
- for (const [key, value] of atoms) {
26
- if (areEqual(key, param)) {
27
- item = value;
28
- break;
29
- }
30
- }
31
- }
32
- if (item !== void 0) {
33
- if (shouldRemove == null ? void 0 : shouldRemove(item[1], param)) {
34
- createAtom.remove(param);
35
- } else {
36
- return item[0];
37
- }
38
- }
39
- const newAtom = initializeAtom(param);
40
- atoms.set(param, [newAtom, Date.now()]);
41
- notifyListeners("CREATE", param, newAtom);
42
- return newAtom;
43
- };
44
- const notifyListeners = (type, param, atom2) => {
45
- for (const listener of listeners) {
46
- listener({ type, param, atom: atom2 });
47
- }
48
- };
49
- createAtom.unstable_listen = (callback) => {
50
- listeners.add(callback);
51
- return () => {
52
- listeners.delete(callback);
53
- };
54
- };
55
- createAtom.getParams = () => atoms.keys();
56
- createAtom.remove = (param) => {
57
- if (areEqual === void 0) {
58
- if (!atoms.has(param)) return;
59
- const [atom2] = atoms.get(param);
60
- atoms.delete(param);
61
- notifyListeners("REMOVE", param, atom2);
62
- } else {
63
- for (const [key, [atom2]] of atoms) {
64
- if (areEqual(key, param)) {
65
- atoms.delete(key);
66
- notifyListeners("REMOVE", key, atom2);
67
- break;
68
- }
69
- }
70
- }
71
- };
72
- createAtom.setShouldRemove = (fn) => {
73
- shouldRemove = fn;
74
- if (!shouldRemove) return;
75
- for (const [key, [atom2, createdAt]] of atoms) {
76
- if (shouldRemove(createdAt, key)) {
77
- atoms.delete(key);
78
- notifyListeners("REMOVE", key, atom2);
79
- }
80
- }
81
- };
82
- return createAtom;
83
- }
84
- var getCached$2 = (c, m, k) => (m.has(k) ? m : m.set(k, c())).get(k);
85
- var cache1$3 = /* @__PURE__ */ new WeakMap();
86
- var memo3 = (create, dep1, dep2, dep3) => {
87
- const cache2 = getCached$2(() => /* @__PURE__ */ new WeakMap(), cache1$3, dep1);
88
- const cache3 = getCached$2(() => /* @__PURE__ */ new WeakMap(), cache2, dep2);
89
- return getCached$2(create, cache3, dep3);
90
- };
91
- function selectAtom(anAtom, selector, equalityFn = Object.is) {
92
- return memo3(
93
- () => {
94
- const EMPTY = /* @__PURE__ */ Symbol();
95
- const selectValue = ([value, prevSlice]) => {
96
- if (prevSlice === EMPTY) {
97
- return selector(value);
98
- }
99
- const slice = selector(value, prevSlice);
100
- return equalityFn(prevSlice, slice) ? prevSlice : slice;
101
- };
102
- const derivedAtom = atom((get) => {
103
- const prev = get(derivedAtom);
104
- const value = get(anAtom);
105
- return selectValue([value, prev]);
106
- });
107
- derivedAtom.init = EMPTY;
108
- return derivedAtom;
109
- },
110
- anAtom,
111
- selector,
112
- equalityFn
113
- );
114
- }
115
- var isPromiseLike$2 = (x) => typeof (x == null ? void 0 : x.then) === "function";
116
- function createJSONStorage(getStringStorage = () => {
117
- try {
118
- return window.localStorage;
119
- } catch (e) {
120
- if ((import.meta.env ? "production" : void 0) !== "production") {
121
- if (typeof window !== "undefined") {
122
- console.warn(e);
123
- }
124
- }
125
- return void 0;
126
- }
127
- }, options) {
128
- var _a;
129
- let lastStr;
130
- let lastValue;
131
- const storage = {
132
- getItem: (key, initialValue) => {
133
- var _a2, _b;
134
- const parse = (str2) => {
135
- str2 = str2 || "";
136
- if (lastStr !== str2) {
137
- try {
138
- lastValue = JSON.parse(str2, options == null ? void 0 : options.reviver);
139
- } catch (e) {
140
- return initialValue;
141
- }
142
- lastStr = str2;
143
- }
144
- return lastValue;
145
- };
146
- const str = (_b = (_a2 = getStringStorage()) == null ? void 0 : _a2.getItem(key)) != null ? _b : null;
147
- if (isPromiseLike$2(str)) {
148
- return str.then(parse);
149
- }
150
- return parse(str);
151
- },
152
- setItem: (key, newValue) => {
153
- var _a2;
154
- return (_a2 = getStringStorage()) == null ? void 0 : _a2.setItem(
155
- key,
156
- JSON.stringify(newValue, options == null ? void 0 : options.replacer)
157
- );
158
- },
159
- removeItem: (key) => {
160
- var _a2;
161
- return (_a2 = getStringStorage()) == null ? void 0 : _a2.removeItem(key);
162
- }
163
- };
164
- const createHandleSubscribe = (subscriber2) => (key, callback, initialValue) => subscriber2(key, (v) => {
165
- let newValue;
166
- try {
167
- newValue = JSON.parse(v || "", options == null ? void 0 : options.reviver);
168
- } catch (e) {
169
- newValue = initialValue;
170
- }
171
- callback(newValue);
172
- });
173
- let subscriber;
174
- try {
175
- subscriber = (_a = getStringStorage()) == null ? void 0 : _a.subscribe;
176
- } catch (e) {
177
- }
178
- if (!subscriber && typeof window !== "undefined" && typeof window.addEventListener === "function" && window.Storage) {
179
- subscriber = (key, callback) => {
180
- if (!(getStringStorage() instanceof window.Storage)) {
181
- return () => {
182
- };
183
- }
184
- const storageEventCallback = (e) => {
185
- if (e.storageArea === getStringStorage() && e.key === key) {
186
- callback(e.newValue);
187
- }
188
- };
189
- window.addEventListener("storage", storageEventCallback);
190
- return () => {
191
- window.removeEventListener("storage", storageEventCallback);
192
- };
193
- };
194
- }
195
- if (subscriber) {
196
- storage.subscribe = createHandleSubscribe(subscriber);
197
- }
198
- return storage;
199
- }
200
- var defaultStorage = createJSONStorage();
201
- function atomWithStorage(key, initialValue, storage = defaultStorage, options) {
202
- const getOnInit = options == null ? void 0 : options.getOnInit;
203
- const baseAtom = atom(
204
- getOnInit ? storage.getItem(key, initialValue) : initialValue
205
- );
206
- if ((import.meta.env ? "production" : void 0) !== "production") {
207
- baseAtom.debugPrivate = true;
208
- }
209
- baseAtom.onMount = (setAtom) => {
210
- var _a;
211
- setAtom(storage.getItem(key, initialValue));
212
- return (_a = storage.subscribe) == null ? void 0 : _a.call(storage, key, setAtom, initialValue);
213
- };
214
- const anAtom = atom(
215
- (get) => get(baseAtom),
216
- (get, set, update) => {
217
- const nextValue = typeof update === "function" ? update(get(baseAtom)) : update;
218
- if (nextValue === RESET) {
219
- set(baseAtom, initialValue);
220
- return storage.removeItem(key);
221
- }
222
- if (isPromiseLike$2(nextValue)) {
223
- return nextValue.then((resolvedValue) => {
224
- set(baseAtom, resolvedValue);
225
- return storage.setItem(key, resolvedValue);
226
- });
227
- }
228
- set(baseAtom, nextValue);
229
- return storage.setItem(key, nextValue);
230
- }
231
- );
232
- return anAtom;
233
- }
234
- var getCached = (c, m, k) => (m.has(k) ? m : m.set(k, c())).get(k);
235
- var cache1$1 = /* @__PURE__ */ new WeakMap();
236
- var memo2 = (create, dep1, dep2) => {
237
- const cache2 = getCached(() => /* @__PURE__ */ new WeakMap(), cache1$1, dep1);
238
- return getCached(create, cache2, dep2);
239
- };
240
- var isPromiseLike = (p) => typeof (p == null ? void 0 : p.then) === "function";
241
- var defaultFallback = () => void 0;
242
- function unwrap(anAtom, fallback = defaultFallback) {
243
- return memo2(
244
- () => {
245
- const promiseErrorCache = /* @__PURE__ */ new WeakMap();
246
- const promiseResultCache = /* @__PURE__ */ new WeakMap();
247
- const refreshAtom = atom(0);
248
- const triggerRefreshAtom = atom([]);
249
- triggerRefreshAtom.INTERNAL_onInit = (store) => {
250
- store.set(triggerRefreshAtom, [
251
- () => store.set(refreshAtom, (c) => c + 1)
252
- ]);
253
- };
254
- if ((import.meta.env ? "production" : void 0) !== "production") {
255
- refreshAtom.debugPrivate = true;
256
- triggerRefreshAtom.debugPrivate = true;
257
- }
258
- const promiseAndValueAtom = atom((get) => {
259
- get(refreshAtom);
260
- let prev;
261
- try {
262
- prev = get(promiseAndValueAtom);
263
- } catch (e) {
264
- }
265
- const promise = get(anAtom);
266
- if (!isPromiseLike(promise)) {
267
- return { v: promise };
268
- }
269
- if (promise !== (prev == null ? void 0 : prev.p)) {
270
- promise.then(
271
- (v) => {
272
- promiseResultCache.set(promise, v);
273
- const [triggerRefresh] = get(triggerRefreshAtom);
274
- triggerRefresh();
275
- },
276
- (e) => {
277
- promiseErrorCache.set(promise, e);
278
- const [triggerRefresh] = get(triggerRefreshAtom);
279
- triggerRefresh();
280
- }
281
- );
282
- }
283
- if (promiseErrorCache.has(promise)) {
284
- throw promiseErrorCache.get(promise);
285
- }
286
- if (promiseResultCache.has(promise)) {
287
- return {
288
- p: promise,
289
- v: promiseResultCache.get(promise)
290
- };
291
- }
292
- if (prev && "v" in prev) {
293
- return { p: promise, f: fallback(prev.v), v: prev.v };
294
- }
295
- return { p: promise, f: fallback() };
296
- });
297
- promiseAndValueAtom.init = void 0;
298
- if ((import.meta.env ? "production" : void 0) !== "production") {
299
- promiseAndValueAtom.debugPrivate = true;
300
- }
301
- return atom(
302
- (get) => {
303
- const state = get(promiseAndValueAtom);
304
- if ("f" in state) {
305
- return state.f;
306
- }
307
- return state.v;
308
- },
309
- (_get, set, ...args) => set(anAtom, ...args)
310
- );
311
- },
312
- anAtom,
313
- fallback
314
- );
315
- }
316
-
317
- export {
318
- atomFamily,
319
- selectAtom,
320
- atomWithStorage,
321
- unwrap
322
- };
@@ -1,210 +0,0 @@
1
- import {
2
- createStore,
3
- getBuildingBlocks,
4
- getDefaultStore
5
- } from "./chunk-Y7XOMJOC.js";
6
-
7
- // node_modules/jotai/esm/react.mjs
8
- import React, { createContext, useContext, useRef, createElement, useReducer, useEffect, useDebugValue, useCallback } from "react";
9
- var StoreContext = createContext(
10
- void 0
11
- );
12
- function useStore(options) {
13
- const store = useContext(StoreContext);
14
- return (options == null ? void 0 : options.store) || store || getDefaultStore();
15
- }
16
- function Provider({
17
- children,
18
- store
19
- }) {
20
- const storeRef = useRef(null);
21
- if (store) {
22
- return createElement(StoreContext.Provider, { value: store }, children);
23
- }
24
- if (storeRef.current === null) {
25
- storeRef.current = createStore();
26
- }
27
- return createElement(
28
- StoreContext.Provider,
29
- {
30
- // TODO: If this is not a false positive, consider using useState instead of useRef like https://github.com/pmndrs/jotai/pull/2771
31
- // eslint-disable-next-line react-hooks/refs
32
- value: storeRef.current
33
- },
34
- children
35
- );
36
- }
37
- var isPromiseLike = (x) => typeof (x == null ? void 0 : x.then) === "function";
38
- var attachPromiseStatus = (promise) => {
39
- if (!promise.status) {
40
- promise.status = "pending";
41
- promise.then(
42
- (v) => {
43
- promise.status = "fulfilled";
44
- promise.value = v;
45
- },
46
- (e) => {
47
- promise.status = "rejected";
48
- promise.reason = e;
49
- }
50
- );
51
- }
52
- };
53
- var use = React.use || // A shim for older React versions
54
- ((promise) => {
55
- if (promise.status === "pending") {
56
- throw promise;
57
- } else if (promise.status === "fulfilled") {
58
- return promise.value;
59
- } else if (promise.status === "rejected") {
60
- throw promise.reason;
61
- } else {
62
- attachPromiseStatus(promise);
63
- throw promise;
64
- }
65
- });
66
- var continuablePromiseMap = /* @__PURE__ */ new WeakMap();
67
- var createContinuablePromise = (store, promise, getValue) => {
68
- const buildingBlocks = getBuildingBlocks(store);
69
- const registerAbortHandler = buildingBlocks[26];
70
- let continuablePromise = continuablePromiseMap.get(promise);
71
- if (!continuablePromise) {
72
- continuablePromise = new Promise((resolve, reject) => {
73
- let curr = promise;
74
- const onFulfilled = (me) => (v) => {
75
- if (curr === me) {
76
- resolve(v);
77
- }
78
- };
79
- const onRejected = (me) => (e) => {
80
- if (curr === me) {
81
- reject(e);
82
- }
83
- };
84
- const onAbort = () => {
85
- try {
86
- const nextValue = getValue();
87
- if (isPromiseLike(nextValue)) {
88
- continuablePromiseMap.set(nextValue, continuablePromise);
89
- curr = nextValue;
90
- nextValue.then(onFulfilled(nextValue), onRejected(nextValue));
91
- registerAbortHandler(buildingBlocks, store, nextValue, onAbort);
92
- } else {
93
- resolve(nextValue);
94
- }
95
- } catch (e) {
96
- reject(e);
97
- }
98
- };
99
- promise.then(onFulfilled(promise), onRejected(promise));
100
- registerAbortHandler(buildingBlocks, store, promise, onAbort);
101
- });
102
- continuablePromiseMap.set(promise, continuablePromise);
103
- }
104
- return continuablePromise;
105
- };
106
- function useAtomValue(atom, options) {
107
- const { delay, unstable_promiseStatus: promiseStatus = !React.use } = options || {};
108
- const store = useStore(options);
109
- const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = useReducer(
110
- (prev) => {
111
- const nextValue = store.get(atom);
112
- if (Object.is(prev[0], nextValue) && prev[1] === store && prev[2] === atom) {
113
- return prev;
114
- }
115
- return [nextValue, store, atom];
116
- },
117
- void 0,
118
- () => [store.get(atom), store, atom]
119
- );
120
- let value = valueFromReducer;
121
- if (storeFromReducer !== store || atomFromReducer !== atom) {
122
- rerender();
123
- value = store.get(atom);
124
- }
125
- useEffect(() => {
126
- const unsub = store.sub(atom, () => {
127
- if (promiseStatus) {
128
- try {
129
- const value2 = store.get(atom);
130
- if (isPromiseLike(value2)) {
131
- attachPromiseStatus(
132
- createContinuablePromise(store, value2, () => store.get(atom))
133
- );
134
- }
135
- } catch (e) {
136
- }
137
- }
138
- if (typeof delay === "number") {
139
- console.warn(`[DEPRECATED] delay option is deprecated and will be removed in v3.
140
-
141
- Migration guide:
142
-
143
- Create a custom hook like the following.
144
-
145
- function useAtomValueWithDelay<Value>(
146
- atom: Atom<Value>,
147
- options: { delay: number },
148
- ): Value {
149
- const { delay } = options
150
- const store = useStore(options)
151
- const [value, setValue] = useState(() => store.get(atom))
152
- useEffect(() => {
153
- const unsub = store.sub(atom, () => {
154
- setTimeout(() => setValue(store.get(atom)), delay)
155
- })
156
- return unsub
157
- }, [store, atom, delay])
158
- return value
159
- }
160
- `);
161
- setTimeout(rerender, delay);
162
- return;
163
- }
164
- rerender();
165
- });
166
- rerender();
167
- return unsub;
168
- }, [store, atom, delay, promiseStatus]);
169
- useDebugValue(value);
170
- if (isPromiseLike(value)) {
171
- const promise = createContinuablePromise(
172
- store,
173
- value,
174
- () => store.get(atom)
175
- );
176
- if (promiseStatus) {
177
- attachPromiseStatus(promise);
178
- }
179
- return use(promise);
180
- }
181
- return value;
182
- }
183
- function useSetAtom(atom, options) {
184
- const store = useStore(options);
185
- const setAtom = useCallback(
186
- (...args) => {
187
- if ((import.meta.env ? "production" : void 0) !== "production" && !("write" in atom)) {
188
- throw new Error("not writable atom");
189
- }
190
- return store.set(atom, ...args);
191
- },
192
- [store, atom]
193
- );
194
- return setAtom;
195
- }
196
- function useAtom(atom, options) {
197
- return [
198
- useAtomValue(atom, options),
199
- // We do wrong type assertion here, which results in throwing an error.
200
- useSetAtom(atom, options)
201
- ];
202
- }
203
-
204
- export {
205
- useStore,
206
- Provider,
207
- useAtomValue,
208
- useSetAtom,
209
- useAtom
210
- };