@thoughtbot/superglue 1.0.2 → 2.0.0-alpha.2
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 -1
- package/dist/action_creators.d.mts +1 -1
- package/dist/action_creators.mjs +1 -1
- package/dist/{chunk-7OMO5P27.mjs → chunk-EU2SLL5L.mjs} +555 -63
- package/dist/chunk-EU2SLL5L.mjs.map +1 -0
- package/dist/cjs/action_creators.cjs +497 -61
- package/dist/cjs/action_creators.cjs.map +1 -1
- package/dist/cjs/superglue.cjs +6258 -125
- package/dist/cjs/superglue.cjs.map +1 -1
- package/dist/{index-BYr1PoYr.d.mts → index-O_srQ3Nm.d.mts} +56 -16
- package/dist/superglue.d.mts +62 -14
- package/dist/superglue.mjs +5747 -53
- package/dist/superglue.mjs.map +1 -1
- package/package.json +11 -4
- package/dist/chunk-7OMO5P27.mjs.map +0 -1
|
@@ -43,17 +43,17 @@ interface RemoteProps extends BaseProps {
|
|
|
43
43
|
force?: boolean;
|
|
44
44
|
}
|
|
45
45
|
interface BeforeSave {
|
|
46
|
-
(prevPage:
|
|
46
|
+
<T extends PageResponse>(prevPage: SaveResponse, receivedPage: T): T;
|
|
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,9 +62,11 @@ 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
|
|
|
70
72
|
type PageKey = string;
|
|
@@ -80,6 +82,16 @@ type JSONObject = {
|
|
|
80
82
|
type JSONMappable = JSONValue[] | JSONObject;
|
|
81
83
|
type JSONKeyable = JSONObject[] | JSONObject;
|
|
82
84
|
type JSONValue = JSONPrimitive | JSONMappable;
|
|
85
|
+
type Fragment<T> = {
|
|
86
|
+
__id: string;
|
|
87
|
+
} & {
|
|
88
|
+
__fragmentType?: T;
|
|
89
|
+
};
|
|
90
|
+
type Unproxied<T> = T extends Fragment<unknown> ? {
|
|
91
|
+
__id: string;
|
|
92
|
+
} : T extends (infer U)[] ? Unproxied<U>[] : T extends object ? {
|
|
93
|
+
[K in keyof T]: Unproxied<T[K]>;
|
|
94
|
+
} : T;
|
|
83
95
|
interface ParsedResponse {
|
|
84
96
|
rsp: Response;
|
|
85
97
|
json: PageResponse;
|
|
@@ -91,30 +103,57 @@ type Defer = {
|
|
|
91
103
|
successAction: string;
|
|
92
104
|
failAction: string;
|
|
93
105
|
};
|
|
94
|
-
type
|
|
106
|
+
type SaveResponse<T = JSONMappable> = {
|
|
95
107
|
data: T;
|
|
96
108
|
componentIdentifier: ComponentIdentifier;
|
|
97
109
|
assets: string[];
|
|
98
110
|
csrfToken?: string;
|
|
99
|
-
fragments:
|
|
111
|
+
fragments: FragmentRef[];
|
|
100
112
|
defers: Defer[];
|
|
101
113
|
slices: JSONObject;
|
|
114
|
+
action: 'savePage';
|
|
102
115
|
renderedAt: number;
|
|
103
116
|
restoreStrategy: RestoreStrategy;
|
|
104
117
|
};
|
|
105
|
-
type Page<T = JSONMappable> =
|
|
118
|
+
type Page<T = JSONMappable> = SaveResponse<T> & {
|
|
106
119
|
savedAt: number;
|
|
107
120
|
};
|
|
108
|
-
type GraftResponse<T = JSONMappable> =
|
|
121
|
+
type GraftResponse<T = JSONMappable> = {
|
|
122
|
+
data: T;
|
|
123
|
+
componentIdentifier: ComponentIdentifier;
|
|
124
|
+
assets: string[];
|
|
125
|
+
csrfToken?: string;
|
|
126
|
+
fragments: FragmentRef[];
|
|
127
|
+
defers: Defer[];
|
|
128
|
+
slices: JSONObject;
|
|
109
129
|
action: 'graft';
|
|
130
|
+
renderedAt: number;
|
|
131
|
+
restoreStrategy: RestoreStrategy;
|
|
110
132
|
path: Keypath;
|
|
133
|
+
fragmentContext?: string;
|
|
134
|
+
};
|
|
135
|
+
type StreamMutateMessage = {
|
|
136
|
+
data: JSONMappable;
|
|
137
|
+
fragmentIds: string[];
|
|
138
|
+
handler: 'append' | 'prepend' | 'save';
|
|
139
|
+
options: Record<string, string>;
|
|
140
|
+
};
|
|
141
|
+
type StreamResponse = {
|
|
142
|
+
data: StreamMutateMessage[];
|
|
143
|
+
fragments: FragmentRef[];
|
|
144
|
+
assets: string[];
|
|
145
|
+
csrfToken?: string;
|
|
146
|
+
action: 'handleStreamResponse';
|
|
147
|
+
renderedAt: number;
|
|
148
|
+
slices: JSONObject;
|
|
111
149
|
};
|
|
112
|
-
type PageResponse = GraftResponse |
|
|
113
|
-
type
|
|
114
|
-
|
|
150
|
+
type PageResponse = GraftResponse | SaveResponse | StreamResponse;
|
|
151
|
+
type FragmentRef = {
|
|
152
|
+
id: string;
|
|
115
153
|
path: Keypath;
|
|
116
154
|
};
|
|
117
155
|
type AllPages<T = JSONMappable> = Record<PageKey, Page<T>>;
|
|
156
|
+
type AllFragments = Record<string, JSONMappable>;
|
|
118
157
|
interface SuperglueState {
|
|
119
158
|
currentPageKey: PageKey;
|
|
120
159
|
search: Record<string, string | undefined>;
|
|
@@ -124,15 +163,16 @@ interface SuperglueState {
|
|
|
124
163
|
interface RootState<T = JSONMappable> {
|
|
125
164
|
superglue: SuperglueState;
|
|
126
165
|
pages: AllPages<T>;
|
|
166
|
+
fragments: AllFragments;
|
|
127
167
|
[name: string]: unknown;
|
|
128
168
|
}
|
|
129
169
|
interface Meta {
|
|
130
170
|
pageKey: PageKey;
|
|
131
|
-
page:
|
|
171
|
+
page: PageResponse;
|
|
132
172
|
redirected: boolean;
|
|
133
173
|
rsp: Response;
|
|
134
174
|
fetchArgs: FetchArgs;
|
|
135
|
-
componentIdentifier
|
|
175
|
+
componentIdentifier?: ComponentIdentifier;
|
|
136
176
|
needsRefresh: boolean;
|
|
137
177
|
}
|
|
138
178
|
interface VisitMeta extends Meta {
|
|
@@ -201,7 +241,7 @@ interface BuildVisitAndRemote {
|
|
|
201
241
|
};
|
|
202
242
|
}
|
|
203
243
|
interface SetupProps {
|
|
204
|
-
initialPage:
|
|
244
|
+
initialPage: SaveResponse;
|
|
205
245
|
baseUrl: string;
|
|
206
246
|
path: string;
|
|
207
247
|
store: SuperglueStore;
|
|
@@ -212,7 +252,7 @@ interface SetupProps {
|
|
|
212
252
|
} | null>;
|
|
213
253
|
}
|
|
214
254
|
interface ApplicationProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
215
|
-
initialPage:
|
|
255
|
+
initialPage: SaveResponse;
|
|
216
256
|
baseUrl: string;
|
|
217
257
|
path: string;
|
|
218
258
|
buildVisitAndRemote: BuildVisitAndRemote;
|
|
@@ -227,6 +267,6 @@ declare class MismatchedComponentError extends Error {
|
|
|
227
267
|
declare const remote: RemoteCreator;
|
|
228
268
|
declare const visit: VisitCreator;
|
|
229
269
|
|
|
230
|
-
declare function saveAndProcessPage(pageKey: string, page:
|
|
270
|
+
declare function saveAndProcessPage(pageKey: string, page: PageResponse): SaveAndProcessPageThunk;
|
|
231
271
|
|
|
232
|
-
export { type
|
|
272
|
+
export { type Visit as $, type ApplicationRemote as A, type VisitCreator as B, type ComponentIdentifier as C, type Defer as D, type RemoteCreator as E, type FetchArgs as F, type GraftResponse as G, type Handlers as H, type Dispatch as I, type JSONMappable as J, type Keypath as K, type UJSHandlers as L, type Meta as M, type NavigationContextProps as N, type HistoryState as O, type PageKey as P, type SaveAndProcessPageThunk as Q, type RestoreStrategy as R, type SuperglueStore as S, type MetaThunk as T, type Unproxied as U, type VisitMeta as V, type VisitMetaThunk as W, type DefermentThunk as X, type BasicRequestInit as Y, type BuildStore as Z, type BuildVisitAndRemote as _, type JSONValue as a, type VisitProps as a0, type Remote as a1, type RemoteProps as a2, type BeforeSave as a3, type GraftingSuccessAction as a4, type GraftingErrorAction as a5, MismatchedComponentError as a6, remote as a7, visit as a8, type NavigationProviderProps as b, type NavigateTo as c, type SaveResponse as d, type PageResponse as e, type SuperglueState as f, type SetupProps as g, type ApplicationVisit as h, type ApplicationProps as i, superglueReducer as j, type NavigationAction as k, type JSONPrimitive as l, type JSONObject as m, type JSONKeyable as n, type Fragment as o, pageReducer as p, type ParsedResponse as q, rootReducer as r, saveAndProcessPage as s, type Page as t, type StreamMutateMessage as u, type StreamResponse as v, type FragmentRef as w, type AllPages as x, type AllFragments as y, type RootState 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, N as NavigationContextProps, b as NavigationProviderProps, c as NavigateTo,
|
|
3
|
-
export {
|
|
2
|
+
import { J as JSONMappable, K as Keypath, a as JSONValue, P as PageKey, A as ApplicationRemote, S as SuperglueStore, N as NavigationContextProps, b as NavigationProviderProps, c as NavigateTo, d as SaveResponse, F as FetchArgs, e as PageResponse, U as Unproxied, f as SuperglueState, g as SetupProps, h as ApplicationVisit, H as Handlers, i as ApplicationProps } from './index-O_srQ3Nm.mjs';
|
|
3
|
+
export { y as AllFragments, x as AllPages, Y as BasicRequestInit, a3 as BeforeSave, Z as BuildStore, _ as BuildVisitAndRemote, C as ComponentIdentifier, D as Defer, X as DefermentThunk, I as Dispatch, o as Fragment, w as FragmentRef, G as GraftResponse, a5 as GraftingErrorAction, a4 as GraftingSuccessAction, O as HistoryState, n as JSONKeyable, m as JSONObject, l as JSONPrimitive, M as Meta, T as MetaThunk, k as NavigationAction, t as Page, q as ParsedResponse, a1 as Remote, E as RemoteCreator, a2 as RemoteProps, R as RestoreStrategy, z as RootState, Q as SaveAndProcessPageThunk, u as StreamMutateMessage, v as StreamResponse, L as UJSHandlers, $ as Visit, B as VisitCreator, V as VisitMeta, W as VisitMetaThunk, a0 as VisitProps, p as pageReducer, r as rootReducer, s as saveAndProcessPage, j as superglueReducer } from './index-O_srQ3Nm.mjs';
|
|
4
4
|
import React from 'react';
|
|
5
|
+
import { Subscription, Consumer, ChannelNameWithParams } 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<Consumer> | 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,47 @@ 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 ProxiedContent<T> = T & {
|
|
78
|
+
readonly [K in keyof T]: T[K] extends {
|
|
79
|
+
__id: string;
|
|
80
|
+
} ? unknown : T[K] extends (infer U)[] ? ProxiedContent<U>[] : T[K] extends object ? ProxiedContent<T[K]> : T[K];
|
|
81
|
+
};
|
|
82
|
+
type FragmentRef = {
|
|
83
|
+
__id: string;
|
|
84
|
+
} | string;
|
|
85
|
+
declare function useContent<T = JSONMappable>(): ProxiedContent<T>;
|
|
86
|
+
declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef): ProxiedContent<T>;
|
|
87
|
+
declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef, options: {
|
|
88
|
+
optional: false;
|
|
89
|
+
}): ProxiedContent<T>;
|
|
90
|
+
declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef, options: {
|
|
91
|
+
optional: true;
|
|
92
|
+
}): ProxiedContent<T> | undefined;
|
|
93
|
+
declare function unproxy<T>(proxy: T): Unproxied<T>;
|
|
94
|
+
|
|
95
|
+
declare function useSetFragment(): (fragmentRef: {
|
|
96
|
+
__id: string;
|
|
97
|
+
} | string, updater: (draft: unknown) => void) => void;
|
|
50
98
|
|
|
51
99
|
declare function useSuperglue(): SuperglueState;
|
|
52
|
-
declare function useContent<T = JSONMappable>(): T;
|
|
53
100
|
|
|
54
|
-
declare const prepareStore: (store: SuperglueStore, initialPage:
|
|
101
|
+
declare const prepareStore: (store: SuperglueStore, initialPage: SaveResponse, path: string) => void;
|
|
55
102
|
declare const setup: ({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, navigatorRef, }: SetupProps) => {
|
|
56
103
|
visit: ApplicationVisit;
|
|
57
104
|
remote: ApplicationRemote;
|
|
58
105
|
nextHistory: history.History;
|
|
59
106
|
initialPageKey: string;
|
|
60
107
|
ujs: Handlers;
|
|
108
|
+
streamActions: StreamActions;
|
|
61
109
|
};
|
|
62
110
|
declare function Application({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, mapping, ...rest }: ApplicationProps): React.JSX.Element;
|
|
63
111
|
|
|
64
|
-
export { Application, ApplicationProps, ApplicationRemote, ApplicationVisit, FetchArgs, GRAFTING_ERROR, GRAFTING_SUCCESS, Handlers, JSONMappable, JSONValue, Keypath, NavigateTo, NavigationContext, NavigationContextProps, NavigationProvider, NavigationProviderProps, PageKey, SetupProps, SuperglueState, SuperglueStore,
|
|
112
|
+
export { Application, ApplicationProps, ApplicationRemote, ApplicationVisit, FetchArgs, GRAFTING_ERROR, GRAFTING_SUCCESS, Handlers, JSONMappable, JSONValue, Keypath, NavigateTo, NavigationContext, NavigationContextProps, NavigationProvider, NavigationProviderProps, PageKey, PageResponse, SaveResponse, SetupProps, SuperglueState, SuperglueStore, Unproxied, beforeFetch, beforeRemote, beforeVisit, copyPage, getIn, prepareStore, receiveResponse, removePage, saveResponse, setup, unproxy, urlToPageKey, useContent, useSetFragment, useStreamSource, useSuperglue };
|