@thoughtbot/superglue 1.0.3 → 2.0.0-alpha.10
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/.tool-versions +1 -2
- package/dist/action_creators.d.mts +1 -1
- package/dist/action_creators.mjs +1 -1
- package/dist/{chunk-ENOVWJUC.mjs → chunk-J2XH5QTK.mjs} +565 -68
- package/dist/chunk-J2XH5QTK.mjs.map +1 -0
- package/dist/cjs/action_creators.cjs +535 -66
- package/dist/cjs/action_creators.cjs.map +1 -1
- package/dist/cjs/superglue.cjs +780 -112
- package/dist/cjs/superglue.cjs.map +1 -1
- package/dist/{index-BYr1PoYr.d.mts → index-j0c-9ZLt.d.mts} +69 -18
- package/dist/superglue.d.mts +46 -14
- package/dist/superglue.mjs +267 -54
- package/dist/superglue.mjs.map +1 -1
- package/package.json +16 -8
- package/thoughtbot-superglue-2.0.0-alpha.10.tgz +0 -0
- package/typedoc.json +1 -0
- package/dist/chunk-ENOVWJUC.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action,
|
|
1
|
+
import { Action, EnhancedStore, Tuple, StoreEnhancer, ThunkDispatch, ThunkAction } from '@reduxjs/toolkit';
|
|
2
2
|
import { History } from 'history';
|
|
3
3
|
|
|
4
4
|
type FetchArgs = [string, BasicRequestInit];
|
|
@@ -42,18 +42,18 @@ interface RemoteProps extends BaseProps {
|
|
|
42
42
|
pageKey?: PageKey;
|
|
43
43
|
force?: boolean;
|
|
44
44
|
}
|
|
45
|
-
interface BeforeSave {
|
|
46
|
-
(prevPage:
|
|
45
|
+
interface BeforeSave<T = JSONMappable> {
|
|
46
|
+
<U extends SaveResponse<T> | GraftResponse<T>>(prevPage: Page<T>, receivedPage: U): U;
|
|
47
47
|
}
|
|
48
48
|
interface ApplicationRemote {
|
|
49
|
-
(input: string | PageKey, options
|
|
49
|
+
(input: string | PageKey, options?: RemoteProps & {
|
|
50
50
|
dataset?: {
|
|
51
51
|
[name: string]: string | undefined;
|
|
52
52
|
};
|
|
53
53
|
}): Promise<Meta>;
|
|
54
54
|
}
|
|
55
55
|
interface ApplicationVisit {
|
|
56
|
-
(input: string | PageKey, options
|
|
56
|
+
(input: string | PageKey, options?: VisitProps & {
|
|
57
57
|
dataset?: {
|
|
58
58
|
[name: string]: string | undefined;
|
|
59
59
|
};
|
|
@@ -62,11 +62,24 @@ interface ApplicationVisit {
|
|
|
62
62
|
|
|
63
63
|
declare function pageReducer(state: AllPages | undefined, action: Action): AllPages;
|
|
64
64
|
declare function superglueReducer(state: SuperglueState | undefined, action: Action): SuperglueState;
|
|
65
|
+
declare function fragmentReducer(state: AllFragments | undefined, action: Action): AllFragments;
|
|
65
66
|
declare const rootReducer: {
|
|
66
67
|
superglue: typeof superglueReducer;
|
|
67
68
|
pages: typeof pageReducer;
|
|
69
|
+
fragments: typeof fragmentReducer;
|
|
68
70
|
};
|
|
69
71
|
|
|
72
|
+
type FragmentProxy = {
|
|
73
|
+
__fragment: true;
|
|
74
|
+
};
|
|
75
|
+
type ProxiedContent<T> = T extends Fragment<infer U, true> ? ProxiedContent<U> & FragmentProxy : T extends Fragment<infer U, false | undefined> ? (ProxiedContent<U> & FragmentProxy) | undefined : T extends (infer U)[] ? ProxiedContent<U>[] : T extends object ? {
|
|
76
|
+
[K in keyof T]: ProxiedContent<T[K]>;
|
|
77
|
+
} : T;
|
|
78
|
+
type FragmentRefOrId = FragmentRef | string;
|
|
79
|
+
declare function useContent<T = JSONMappable>(): ProxiedContent<T>;
|
|
80
|
+
declare function useContent<T = JSONMappable>(fragmentRef: FragmentRefOrId): ProxiedContent<T>;
|
|
81
|
+
declare function unproxy<T>(proxy: T): Unproxy<T>;
|
|
82
|
+
|
|
70
83
|
type PageKey = string;
|
|
71
84
|
type RestoreStrategy = 'fromCacheOnly' | 'revisitOnly' | 'fromCacheAndRevisitInBackground';
|
|
72
85
|
type NavigationAction = 'push' | 'replace' | 'none';
|
|
@@ -80,6 +93,14 @@ type JSONObject = {
|
|
|
80
93
|
type JSONMappable = JSONValue[] | JSONObject;
|
|
81
94
|
type JSONKeyable = JSONObject[] | JSONObject;
|
|
82
95
|
type JSONValue = JSONPrimitive | JSONMappable;
|
|
96
|
+
type Fragment<T, Present = false> = {
|
|
97
|
+
__id: string;
|
|
98
|
+
__fragmentType?: T;
|
|
99
|
+
__required?: Present extends boolean ? Present : false;
|
|
100
|
+
};
|
|
101
|
+
type Unproxy<T> = T extends FragmentProxy ? FragmentRef : T extends Fragment<unknown, unknown> ? FragmentRef : T extends (infer U)[] ? Unproxy<U>[] : T extends object ? {
|
|
102
|
+
[K in keyof T]: Unproxy<T[K]>;
|
|
103
|
+
} : T;
|
|
83
104
|
interface ParsedResponse {
|
|
84
105
|
rsp: Response;
|
|
85
106
|
json: PageResponse;
|
|
@@ -91,30 +112,59 @@ type Defer = {
|
|
|
91
112
|
successAction: string;
|
|
92
113
|
failAction: string;
|
|
93
114
|
};
|
|
94
|
-
type
|
|
115
|
+
type SaveResponse<T = JSONMappable> = {
|
|
95
116
|
data: T;
|
|
96
117
|
componentIdentifier: ComponentIdentifier;
|
|
97
118
|
assets: string[];
|
|
98
119
|
csrfToken?: string;
|
|
99
|
-
fragments:
|
|
120
|
+
fragments: FragmentPath[];
|
|
100
121
|
defers: Defer[];
|
|
101
122
|
slices: JSONObject;
|
|
123
|
+
action: 'savePage';
|
|
102
124
|
renderedAt: number;
|
|
103
125
|
restoreStrategy: RestoreStrategy;
|
|
104
126
|
};
|
|
105
|
-
type Page<T = JSONMappable> =
|
|
127
|
+
type Page<T = JSONMappable> = SaveResponse<T> & {
|
|
106
128
|
savedAt: number;
|
|
107
129
|
};
|
|
108
|
-
type GraftResponse<T = JSONMappable> =
|
|
130
|
+
type GraftResponse<T = JSONMappable> = {
|
|
131
|
+
data: T;
|
|
132
|
+
componentIdentifier: ComponentIdentifier;
|
|
133
|
+
assets: string[];
|
|
134
|
+
csrfToken?: string;
|
|
135
|
+
fragments: FragmentPath[];
|
|
136
|
+
defers: Defer[];
|
|
137
|
+
slices: JSONObject;
|
|
109
138
|
action: 'graft';
|
|
139
|
+
renderedAt: number;
|
|
110
140
|
path: Keypath;
|
|
141
|
+
fragmentContext?: string;
|
|
142
|
+
};
|
|
143
|
+
type StreamMessage = {
|
|
144
|
+
data: JSONMappable;
|
|
145
|
+
fragmentIds: string[];
|
|
146
|
+
handler: 'append' | 'prepend' | 'save';
|
|
147
|
+
options: Record<string, string>;
|
|
111
148
|
};
|
|
112
|
-
type
|
|
113
|
-
|
|
114
|
-
|
|
149
|
+
type StreamResponse = {
|
|
150
|
+
data: StreamMessage[];
|
|
151
|
+
fragments: FragmentPath[];
|
|
152
|
+
assets: string[];
|
|
153
|
+
csrfToken?: string;
|
|
154
|
+
action: 'handleStreamResponse';
|
|
155
|
+
renderedAt: number;
|
|
156
|
+
slices: JSONObject;
|
|
157
|
+
};
|
|
158
|
+
type PageResponse = GraftResponse | SaveResponse | StreamResponse;
|
|
159
|
+
type FragmentPath = {
|
|
160
|
+
id: string;
|
|
115
161
|
path: Keypath;
|
|
116
162
|
};
|
|
163
|
+
type FragmentRef = {
|
|
164
|
+
__id: string;
|
|
165
|
+
};
|
|
117
166
|
type AllPages<T = JSONMappable> = Record<PageKey, Page<T>>;
|
|
167
|
+
type AllFragments = Record<string, JSONMappable>;
|
|
118
168
|
interface SuperglueState {
|
|
119
169
|
currentPageKey: PageKey;
|
|
120
170
|
search: Record<string, string | undefined>;
|
|
@@ -124,15 +174,16 @@ interface SuperglueState {
|
|
|
124
174
|
interface RootState<T = JSONMappable> {
|
|
125
175
|
superglue: SuperglueState;
|
|
126
176
|
pages: AllPages<T>;
|
|
177
|
+
fragments: AllFragments;
|
|
127
178
|
[name: string]: unknown;
|
|
128
179
|
}
|
|
129
180
|
interface Meta {
|
|
130
181
|
pageKey: PageKey;
|
|
131
|
-
page:
|
|
182
|
+
page: PageResponse;
|
|
132
183
|
redirected: boolean;
|
|
133
184
|
rsp: Response;
|
|
134
185
|
fetchArgs: FetchArgs;
|
|
135
|
-
componentIdentifier
|
|
186
|
+
componentIdentifier?: ComponentIdentifier;
|
|
136
187
|
needsRefresh: boolean;
|
|
137
188
|
}
|
|
138
189
|
interface VisitMeta extends Meta {
|
|
@@ -201,7 +252,7 @@ interface BuildVisitAndRemote {
|
|
|
201
252
|
};
|
|
202
253
|
}
|
|
203
254
|
interface SetupProps {
|
|
204
|
-
initialPage:
|
|
255
|
+
initialPage: SaveResponse;
|
|
205
256
|
baseUrl: string;
|
|
206
257
|
path: string;
|
|
207
258
|
store: SuperglueStore;
|
|
@@ -212,7 +263,7 @@ interface SetupProps {
|
|
|
212
263
|
} | null>;
|
|
213
264
|
}
|
|
214
265
|
interface ApplicationProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
215
|
-
initialPage:
|
|
266
|
+
initialPage: SaveResponse;
|
|
216
267
|
baseUrl: string;
|
|
217
268
|
path: string;
|
|
218
269
|
buildVisitAndRemote: BuildVisitAndRemote;
|
|
@@ -227,6 +278,6 @@ declare class MismatchedComponentError extends Error {
|
|
|
227
278
|
declare const remote: RemoteCreator;
|
|
228
279
|
declare const visit: VisitCreator;
|
|
229
280
|
|
|
230
|
-
declare function saveAndProcessPage(pageKey: string, page:
|
|
281
|
+
declare function saveAndProcessPage(pageKey: string, page: PageResponse): SaveAndProcessPageThunk;
|
|
231
282
|
|
|
232
|
-
export { type
|
|
283
|
+
export { type BasicRequestInit as $, type ApplicationRemote as A, type AllPages as B, type ComponentIdentifier as C, type Defer as D, type AllFragments as E, type FetchArgs as F, type GraftResponse as G, type Handlers as H, type RootState as I, type JSONMappable as J, type Keypath as K, type VisitCreator as L, type Meta as M, type NavigationProviderProps as N, type RemoteCreator as O, type PageKey as P, type Dispatch as Q, type RestoreStrategy as R, type SuperglueStore as S, type UJSHandlers as T, type Unproxy as U, type VisitMeta as V, type HistoryState as W, type SaveAndProcessPageThunk as X, type MetaThunk as Y, type VisitMetaThunk as Z, type DefermentThunk as _, type JSONValue as a, type BuildStore as a0, type BuildVisitAndRemote as a1, type Visit as a2, type VisitProps as a3, type Remote as a4, type RemoteProps as a5, type BeforeSave as a6, type GraftingSuccessAction as a7, type GraftingErrorAction as a8, useContent as a9, MismatchedComponentError as aa, remote as ab, visit as ac, type NavigateTo as b, type NavigationContextProps as c, type SaveResponse as d, type PageResponse as e, type Fragment as f, type FragmentProxy as g, type SuperglueState as h, type ApplicationProps as i, type SetupProps as j, type ApplicationVisit as k, superglueReducer as l, type NavigationAction as m, type JSONPrimitive as n, type JSONObject as o, pageReducer as p, type JSONKeyable as q, rootReducer as r, saveAndProcessPage as s, type ParsedResponse as t, unproxy as u, type Page as v, type StreamMessage as w, type StreamResponse as x, type FragmentPath as y, type FragmentRef as z };
|
package/dist/superglue.d.mts
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
import * as history from 'history';
|
|
2
|
-
import { J as JSONMappable, K as Keypath, a as JSONValue, P as PageKey,
|
|
3
|
-
export {
|
|
2
|
+
import { J as JSONMappable, K as Keypath, a as JSONValue, P as PageKey, A as ApplicationRemote, S as SuperglueStore, N as NavigationProviderProps, b as NavigateTo, c as NavigationContextProps, F as FetchArgs, d as SaveResponse, e as PageResponse, f as Fragment, U as Unproxy, g as FragmentProxy, h as SuperglueState, i as ApplicationProps, j as SetupProps, k as ApplicationVisit, H as Handlers } from './index-j0c-9ZLt.mjs';
|
|
3
|
+
export { E as AllFragments, B as AllPages, $ as BasicRequestInit, a6 as BeforeSave, a0 as BuildStore, a1 as BuildVisitAndRemote, C as ComponentIdentifier, D as Defer, _ as DefermentThunk, Q as Dispatch, y as FragmentPath, z as FragmentRef, G as GraftResponse, a8 as GraftingErrorAction, a7 as GraftingSuccessAction, W as HistoryState, q as JSONKeyable, o as JSONObject, n as JSONPrimitive, M as Meta, Y as MetaThunk, m as NavigationAction, v as Page, t as ParsedResponse, a4 as Remote, O as RemoteCreator, a5 as RemoteProps, R as RestoreStrategy, I as RootState, X as SaveAndProcessPageThunk, w as StreamMessage, x as StreamResponse, T as UJSHandlers, a2 as Visit, L as VisitCreator, V as VisitMeta, Z as VisitMetaThunk, a3 as VisitProps, p as pageReducer, r as rootReducer, s as saveAndProcessPage, l as superglueReducer, u as unproxy, a9 as useContent } from './index-j0c-9ZLt.mjs';
|
|
4
4
|
import React from 'react';
|
|
5
|
+
import { ChannelNameWithParams, Subscription } from '@rails/actioncable';
|
|
6
|
+
import { DebouncedFunc } from 'lodash';
|
|
5
7
|
import * as _reduxjs_toolkit from '@reduxjs/toolkit';
|
|
6
8
|
|
|
7
9
|
declare function getIn(node: JSONMappable, path: Keypath): JSONValue;
|
|
8
10
|
|
|
9
11
|
declare function urlToPageKey(url: string): PageKey;
|
|
10
12
|
|
|
13
|
+
type StreamSourceProps = string | ChannelNameWithParams;
|
|
14
|
+
declare class StreamActions {
|
|
15
|
+
attributePrefix: string;
|
|
16
|
+
remote: DebouncedFunc<ApplicationRemote>;
|
|
17
|
+
private store;
|
|
18
|
+
constructor({ remote, store, }: {
|
|
19
|
+
remote: ApplicationRemote;
|
|
20
|
+
store: SuperglueStore;
|
|
21
|
+
});
|
|
22
|
+
refresh(pageKey: string): void;
|
|
23
|
+
prepend(fragments: string[], data: JSONMappable, options?: {
|
|
24
|
+
saveAs?: string;
|
|
25
|
+
}): void;
|
|
26
|
+
save(fragment: string, data: JSONMappable): void;
|
|
27
|
+
append(fragments: string[], data: JSONMappable, options?: {
|
|
28
|
+
saveAs?: string;
|
|
29
|
+
}): void;
|
|
30
|
+
handle(rawMessage: string, currentPageKey: string): void;
|
|
31
|
+
}
|
|
32
|
+
declare function useStreamSource(channel: StreamSourceProps): {
|
|
33
|
+
connected: boolean;
|
|
34
|
+
subscription: Subscription | null;
|
|
35
|
+
};
|
|
36
|
+
|
|
11
37
|
declare const NavigationContext: React.Context<NavigationContextProps>;
|
|
12
38
|
declare const NavigationProvider: React.ForwardRefExoticComponent<NavigationProviderProps & React.RefAttributes<{
|
|
13
39
|
navigateTo: NavigateTo | null;
|
|
@@ -17,18 +43,11 @@ declare const GRAFTING_ERROR = "@@superglue/GRAFTING_ERROR";
|
|
|
17
43
|
declare const GRAFTING_SUCCESS = "@@superglue/GRAFTING_SUCCESS";
|
|
18
44
|
declare const saveResponse: _reduxjs_toolkit.ActionCreatorWithPreparedPayload<[{
|
|
19
45
|
pageKey: string;
|
|
20
|
-
page:
|
|
46
|
+
page: SaveResponse;
|
|
21
47
|
}], {
|
|
22
48
|
pageKey: string;
|
|
23
|
-
page:
|
|
49
|
+
page: SaveResponse;
|
|
24
50
|
}, "@@superglue/SAVE_RESPONSE", never, never>;
|
|
25
|
-
declare const updateFragments: _reduxjs_toolkit.ActionCreatorWithPayload<{
|
|
26
|
-
name: string;
|
|
27
|
-
path: Keypath;
|
|
28
|
-
pageKey: PageKey;
|
|
29
|
-
value: JSONMappable;
|
|
30
|
-
previousValue?: JSONMappable;
|
|
31
|
-
}, string>;
|
|
32
51
|
declare const copyPage: _reduxjs_toolkit.ActionCreatorWithPayload<{
|
|
33
52
|
from: PageKey;
|
|
34
53
|
to: PageKey;
|
|
@@ -47,18 +66,31 @@ declare const beforeRemote: _reduxjs_toolkit.ActionCreatorWithPayload<{
|
|
|
47
66
|
currentPageKey: PageKey;
|
|
48
67
|
fetchArgs: FetchArgs;
|
|
49
68
|
}, string>;
|
|
69
|
+
declare const receiveResponse: _reduxjs_toolkit.ActionCreatorWithPreparedPayload<[{
|
|
70
|
+
pageKey: string;
|
|
71
|
+
response: PageResponse;
|
|
72
|
+
}], {
|
|
73
|
+
pageKey: string;
|
|
74
|
+
response: PageResponse;
|
|
75
|
+
}, "@@superglue/RECEIVE_RESPONSE", never, never>;
|
|
76
|
+
|
|
77
|
+
type Unpack<T> = T extends Fragment<infer U, unknown> ? U : T extends FragmentProxy ? T : never;
|
|
78
|
+
declare function useSetFragment(): {
|
|
79
|
+
<T extends Fragment<unknown, unknown>>(fragmentRef: T, updater: (draft: Unproxy<Unpack<T>>) => void): void;
|
|
80
|
+
<T = unknown>(fragmentId: string, updater: (draft: T) => void): void;
|
|
81
|
+
};
|
|
50
82
|
|
|
51
83
|
declare function useSuperglue(): SuperglueState;
|
|
52
|
-
declare function useContent<T = JSONMappable>(): T;
|
|
53
84
|
|
|
54
|
-
declare const prepareStore: (store: SuperglueStore, initialPage:
|
|
85
|
+
declare const prepareStore: (store: SuperglueStore, initialPage: SaveResponse, path: string) => void;
|
|
55
86
|
declare const setup: ({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, navigatorRef, }: SetupProps) => {
|
|
56
87
|
visit: ApplicationVisit;
|
|
57
88
|
remote: ApplicationRemote;
|
|
58
89
|
nextHistory: history.History;
|
|
59
90
|
initialPageKey: string;
|
|
60
91
|
ujs: Handlers;
|
|
92
|
+
streamActions: StreamActions;
|
|
61
93
|
};
|
|
62
94
|
declare function Application({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, mapping, ...rest }: ApplicationProps): React.JSX.Element;
|
|
63
95
|
|
|
64
|
-
export { Application, ApplicationProps, ApplicationRemote, ApplicationVisit, FetchArgs, GRAFTING_ERROR, GRAFTING_SUCCESS, Handlers, JSONMappable, JSONValue, Keypath, NavigateTo, NavigationContext, NavigationContextProps, NavigationProvider, NavigationProviderProps, PageKey, SetupProps, SuperglueState, SuperglueStore,
|
|
96
|
+
export { Application, ApplicationProps, ApplicationRemote, ApplicationVisit, FetchArgs, Fragment, GRAFTING_ERROR, GRAFTING_SUCCESS, Handlers, JSONMappable, JSONValue, Keypath, NavigateTo, NavigationContext, NavigationContextProps, NavigationProvider, NavigationProviderProps, PageKey, PageResponse, SaveResponse, SetupProps, SuperglueState, SuperglueStore, Unproxy, beforeFetch, beforeRemote, beforeVisit, copyPage, getIn, prepareStore, receiveResponse, removePage, saveResponse, setup, urlToPageKey, useSetFragment, useStreamSource, useSuperglue };
|