@thoughtbot/superglue 1.0.1 → 2.0.0-alpha.1
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-LGUVOEZ3.mjs → chunk-YS477OKK.mjs} +341 -137
- package/dist/chunk-YS477OKK.mjs.map +1 -0
- package/dist/cjs/action_creators.cjs +287 -126
- package/dist/cjs/action_creators.cjs.map +1 -1
- package/dist/cjs/superglue.cjs +6242 -168
- package/dist/cjs/superglue.cjs.map +1 -1
- package/dist/{index-BYr1PoYr.d.mts → index-MyfFLe4E.d.mts} +55 -16
- package/dist/superglue.d.mts +55 -14
- package/dist/superglue.mjs +5949 -40
- package/dist/superglue.mjs.map +1 -1
- package/package.json +12 -7
- package/thoughtbot-superglue-2.0.0-alpha.1.tgz +0 -0
- package/dist/chunk-LGUVOEZ3.mjs.map +0 -1
- package/thoughtbot-superglue-1.0.0.tgz +0 -0
- package/thoughtbot-superglue-1.0.0a.tgz +0 -0
- package/thoughtbot-superglue-1.0.0b.tgz +0 -0
- package/thoughtbot-superglue-1.0.0d.tgz +0 -0
- package/thoughtbot-superglue-1.0.1.tgz +0 -0
|
@@ -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,56 @@ 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>;
|
|
111
140
|
};
|
|
112
|
-
type
|
|
113
|
-
|
|
114
|
-
|
|
141
|
+
type StreamResponse = {
|
|
142
|
+
data: StreamMutateMessage[];
|
|
143
|
+
fragments: FragmentRef[];
|
|
144
|
+
assets: string[];
|
|
145
|
+
csrfToken?: string;
|
|
146
|
+
action: 'handleStreamResponse';
|
|
147
|
+
renderedAt: number;
|
|
148
|
+
};
|
|
149
|
+
type PageResponse = GraftResponse | SaveResponse | StreamResponse;
|
|
150
|
+
type FragmentRef = {
|
|
151
|
+
id: string;
|
|
115
152
|
path: Keypath;
|
|
116
153
|
};
|
|
117
154
|
type AllPages<T = JSONMappable> = Record<PageKey, Page<T>>;
|
|
155
|
+
type AllFragments = Record<string, JSONMappable>;
|
|
118
156
|
interface SuperglueState {
|
|
119
157
|
currentPageKey: PageKey;
|
|
120
158
|
search: Record<string, string | undefined>;
|
|
@@ -124,15 +162,16 @@ interface SuperglueState {
|
|
|
124
162
|
interface RootState<T = JSONMappable> {
|
|
125
163
|
superglue: SuperglueState;
|
|
126
164
|
pages: AllPages<T>;
|
|
165
|
+
fragments: AllFragments;
|
|
127
166
|
[name: string]: unknown;
|
|
128
167
|
}
|
|
129
168
|
interface Meta {
|
|
130
169
|
pageKey: PageKey;
|
|
131
|
-
page:
|
|
170
|
+
page: PageResponse;
|
|
132
171
|
redirected: boolean;
|
|
133
172
|
rsp: Response;
|
|
134
173
|
fetchArgs: FetchArgs;
|
|
135
|
-
componentIdentifier
|
|
174
|
+
componentIdentifier?: ComponentIdentifier;
|
|
136
175
|
needsRefresh: boolean;
|
|
137
176
|
}
|
|
138
177
|
interface VisitMeta extends Meta {
|
|
@@ -201,7 +240,7 @@ interface BuildVisitAndRemote {
|
|
|
201
240
|
};
|
|
202
241
|
}
|
|
203
242
|
interface SetupProps {
|
|
204
|
-
initialPage:
|
|
243
|
+
initialPage: SaveResponse;
|
|
205
244
|
baseUrl: string;
|
|
206
245
|
path: string;
|
|
207
246
|
store: SuperglueStore;
|
|
@@ -212,7 +251,7 @@ interface SetupProps {
|
|
|
212
251
|
} | null>;
|
|
213
252
|
}
|
|
214
253
|
interface ApplicationProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
215
|
-
initialPage:
|
|
254
|
+
initialPage: SaveResponse;
|
|
216
255
|
baseUrl: string;
|
|
217
256
|
path: string;
|
|
218
257
|
buildVisitAndRemote: BuildVisitAndRemote;
|
|
@@ -227,6 +266,6 @@ declare class MismatchedComponentError extends Error {
|
|
|
227
266
|
declare const remote: RemoteCreator;
|
|
228
267
|
declare const visit: VisitCreator;
|
|
229
268
|
|
|
230
|
-
declare function saveAndProcessPage(pageKey: string, page:
|
|
269
|
+
declare function saveAndProcessPage(pageKey: string, page: PageResponse): SaveAndProcessPageThunk;
|
|
231
270
|
|
|
232
|
-
export { type
|
|
271
|
+
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 SuperglueState as e, type SetupProps as f, type ApplicationVisit as g, type ApplicationProps as h, superglueReducer as i, type NavigationAction as j, type JSONPrimitive as k, type JSONObject as l, type JSONKeyable as m, type Fragment as n, type ParsedResponse as o, pageReducer as p, type Page as q, rootReducer as r, saveAndProcessPage as s, type StreamMutateMessage as t, type StreamResponse as u, type PageResponse 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, U as Unproxied, e as SuperglueState, f as SetupProps, g as ApplicationVisit, H as Handlers, h as ApplicationProps } from './index-MyfFLe4E.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, n as Fragment, w as FragmentRef, G as GraftResponse, a5 as GraftingErrorAction, a4 as GraftingSuccessAction, O as HistoryState, m as JSONKeyable, l as JSONObject, k as JSONPrimitive, M as Meta, T as MetaThunk, j as NavigationAction, q as Page, v as PageResponse, o as ParsedResponse, a1 as Remote, E as RemoteCreator, a2 as RemoteProps, R as RestoreStrategy, z as RootState, Q as SaveAndProcessPageThunk, t as StreamMutateMessage, u 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, i as superglueReducer } from './index-MyfFLe4E.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;
|
|
@@ -48,17 +67,39 @@ declare const beforeRemote: _reduxjs_toolkit.ActionCreatorWithPayload<{
|
|
|
48
67
|
fetchArgs: FetchArgs;
|
|
49
68
|
}, string>;
|
|
50
69
|
|
|
70
|
+
type ProxiedContent<T> = T & {
|
|
71
|
+
readonly [K in keyof T]: T[K] extends {
|
|
72
|
+
__id: string;
|
|
73
|
+
} ? unknown : T[K] extends (infer U)[] ? ProxiedContent<U>[] : T[K] extends object ? ProxiedContent<T[K]> : T[K];
|
|
74
|
+
};
|
|
75
|
+
type FragmentRef = {
|
|
76
|
+
__id: string;
|
|
77
|
+
} | string;
|
|
78
|
+
declare function useContent<T = JSONMappable>(): ProxiedContent<T>;
|
|
79
|
+
declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef): ProxiedContent<T>;
|
|
80
|
+
declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef, options: {
|
|
81
|
+
optional: false;
|
|
82
|
+
}): ProxiedContent<T>;
|
|
83
|
+
declare function useContent<T = JSONMappable>(fragmentRef: FragmentRef, options: {
|
|
84
|
+
optional: true;
|
|
85
|
+
}): ProxiedContent<T> | undefined;
|
|
86
|
+
declare function unproxy<T>(proxy: T): Unproxied<T>;
|
|
87
|
+
|
|
88
|
+
declare function useSetFragment(): (fragmentRef: {
|
|
89
|
+
__id: string;
|
|
90
|
+
} | string, updater: (draft: unknown) => void) => void;
|
|
91
|
+
|
|
51
92
|
declare function useSuperglue(): SuperglueState;
|
|
52
|
-
declare function useContent<T = JSONMappable>(): T;
|
|
53
93
|
|
|
54
|
-
declare const prepareStore: (store: SuperglueStore, initialPage:
|
|
94
|
+
declare const prepareStore: (store: SuperglueStore, initialPage: SaveResponse, path: string) => void;
|
|
55
95
|
declare const setup: ({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, navigatorRef, }: SetupProps) => {
|
|
56
96
|
visit: ApplicationVisit;
|
|
57
97
|
remote: ApplicationRemote;
|
|
58
98
|
nextHistory: history.History;
|
|
59
99
|
initialPageKey: string;
|
|
60
100
|
ujs: Handlers;
|
|
101
|
+
streamActions: StreamActions;
|
|
61
102
|
};
|
|
62
103
|
declare function Application({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, mapping, ...rest }: ApplicationProps): React.JSX.Element;
|
|
63
104
|
|
|
64
|
-
export { Application, ApplicationProps, ApplicationRemote, ApplicationVisit, FetchArgs, GRAFTING_ERROR, GRAFTING_SUCCESS, Handlers, JSONMappable, JSONValue, Keypath, NavigateTo, NavigationContext, NavigationContextProps, NavigationProvider, NavigationProviderProps, PageKey, SetupProps, SuperglueState, SuperglueStore,
|
|
105
|
+
export { Application, ApplicationProps, ApplicationRemote, ApplicationVisit, FetchArgs, GRAFTING_ERROR, GRAFTING_SUCCESS, Handlers, JSONMappable, JSONValue, Keypath, NavigateTo, NavigationContext, NavigationContextProps, NavigationProvider, NavigationProviderProps, PageKey, SaveResponse, SetupProps, SuperglueState, SuperglueStore, Unproxied, beforeFetch, beforeRemote, beforeVisit, copyPage, getIn, prepareStore, removePage, saveResponse, setup, unproxy, urlToPageKey, useContent, useSetFragment, useStreamSource, useSuperglue };
|