@thoughtbot/superglue 2.0.0-alpha.5 → 2.0.0-alpha.8
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/dist/action_creators.d.mts +1 -1
- package/dist/action_creators.mjs +1 -1
- package/dist/{chunk-Q76JBI63.mjs → chunk-ZATKIRIF.mjs} +22 -16
- package/dist/chunk-ZATKIRIF.mjs.map +1 -0
- package/dist/cjs/action_creators.cjs +21 -15
- package/dist/cjs/action_creators.cjs.map +1 -1
- package/dist/cjs/superglue.cjs +38 -25
- package/dist/cjs/superglue.cjs.map +1 -1
- package/dist/{index-O_srQ3Nm.d.mts → index-CsQ3b41B.d.mts} +27 -16
- package/dist/superglue.d.mts +9 -25
- package/dist/superglue.mjs +24 -14
- package/dist/superglue.mjs.map +1 -1
- package/package.json +3 -3
- package/typedoc.json +1 -0
- package/dist/chunk-Q76JBI63.mjs.map +0 -1
|
@@ -42,8 +42,8 @@ interface RemoteProps extends BaseProps {
|
|
|
42
42
|
pageKey?: PageKey;
|
|
43
43
|
force?: boolean;
|
|
44
44
|
}
|
|
45
|
-
interface BeforeSave {
|
|
46
|
-
<
|
|
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
49
|
(input: string | PageKey, options?: RemoteProps & {
|
|
@@ -69,6 +69,17 @@ declare const rootReducer: {
|
|
|
69
69
|
fragments: typeof fragmentReducer;
|
|
70
70
|
};
|
|
71
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
|
+
|
|
72
83
|
type PageKey = string;
|
|
73
84
|
type RestoreStrategy = 'fromCacheOnly' | 'revisitOnly' | 'fromCacheAndRevisitInBackground';
|
|
74
85
|
type NavigationAction = 'push' | 'replace' | 'none';
|
|
@@ -82,15 +93,13 @@ type JSONObject = {
|
|
|
82
93
|
type JSONMappable = JSONValue[] | JSONObject;
|
|
83
94
|
type JSONKeyable = JSONObject[] | JSONObject;
|
|
84
95
|
type JSONValue = JSONPrimitive | JSONMappable;
|
|
85
|
-
type Fragment<T> = {
|
|
96
|
+
type Fragment<T, Present = false> = {
|
|
86
97
|
__id: string;
|
|
87
|
-
} & {
|
|
88
98
|
__fragmentType?: T;
|
|
99
|
+
__required?: Present extends boolean ? Present : false;
|
|
89
100
|
};
|
|
90
|
-
type
|
|
91
|
-
|
|
92
|
-
} : T extends (infer U)[] ? Unproxied<U>[] : T extends object ? {
|
|
93
|
-
[K in keyof T]: Unproxied<T[K]>;
|
|
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]>;
|
|
94
103
|
} : T;
|
|
95
104
|
interface ParsedResponse {
|
|
96
105
|
rsp: Response;
|
|
@@ -108,7 +117,7 @@ type SaveResponse<T = JSONMappable> = {
|
|
|
108
117
|
componentIdentifier: ComponentIdentifier;
|
|
109
118
|
assets: string[];
|
|
110
119
|
csrfToken?: string;
|
|
111
|
-
fragments:
|
|
120
|
+
fragments: FragmentPath[];
|
|
112
121
|
defers: Defer[];
|
|
113
122
|
slices: JSONObject;
|
|
114
123
|
action: 'savePage';
|
|
@@ -123,24 +132,23 @@ type GraftResponse<T = JSONMappable> = {
|
|
|
123
132
|
componentIdentifier: ComponentIdentifier;
|
|
124
133
|
assets: string[];
|
|
125
134
|
csrfToken?: string;
|
|
126
|
-
fragments:
|
|
135
|
+
fragments: FragmentPath[];
|
|
127
136
|
defers: Defer[];
|
|
128
137
|
slices: JSONObject;
|
|
129
138
|
action: 'graft';
|
|
130
139
|
renderedAt: number;
|
|
131
|
-
restoreStrategy: RestoreStrategy;
|
|
132
140
|
path: Keypath;
|
|
133
141
|
fragmentContext?: string;
|
|
134
142
|
};
|
|
135
|
-
type
|
|
143
|
+
type StreamMessage = {
|
|
136
144
|
data: JSONMappable;
|
|
137
145
|
fragmentIds: string[];
|
|
138
146
|
handler: 'append' | 'prepend' | 'save';
|
|
139
147
|
options: Record<string, string>;
|
|
140
148
|
};
|
|
141
149
|
type StreamResponse = {
|
|
142
|
-
data:
|
|
143
|
-
fragments:
|
|
150
|
+
data: StreamMessage[];
|
|
151
|
+
fragments: FragmentPath[];
|
|
144
152
|
assets: string[];
|
|
145
153
|
csrfToken?: string;
|
|
146
154
|
action: 'handleStreamResponse';
|
|
@@ -148,10 +156,13 @@ type StreamResponse = {
|
|
|
148
156
|
slices: JSONObject;
|
|
149
157
|
};
|
|
150
158
|
type PageResponse = GraftResponse | SaveResponse | StreamResponse;
|
|
151
|
-
type
|
|
159
|
+
type FragmentPath = {
|
|
152
160
|
id: string;
|
|
153
161
|
path: Keypath;
|
|
154
162
|
};
|
|
163
|
+
type FragmentRef = {
|
|
164
|
+
__id: string;
|
|
165
|
+
};
|
|
155
166
|
type AllPages<T = JSONMappable> = Record<PageKey, Page<T>>;
|
|
156
167
|
type AllFragments = Record<string, JSONMappable>;
|
|
157
168
|
interface SuperglueState {
|
|
@@ -269,4 +280,4 @@ declare const visit: VisitCreator;
|
|
|
269
280
|
|
|
270
281
|
declare function saveAndProcessPage(pageKey: string, page: PageResponse): SaveAndProcessPageThunk;
|
|
271
282
|
|
|
272
|
-
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 NavigationContextProps 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 NavigationProviderProps as b, type NavigateTo as c, type SaveResponse as d, type PageResponse as e, type Fragment as f, type FragmentProxy as g, type SuperglueState as h, type SetupProps as i, type ApplicationVisit as j, type ApplicationProps 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,8 +1,8 @@
|
|
|
1
1
|
import * as history from 'history';
|
|
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
|
|
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, f as Fragment, U as Unproxy, g as FragmentProxy, h as SuperglueState, i as SetupProps, j as ApplicationVisit, H as Handlers, k as ApplicationProps } from './index-CsQ3b41B.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-CsQ3b41B.mjs';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { Subscription,
|
|
5
|
+
import { Subscription, ChannelNameWithParams } from '@rails/actioncable';
|
|
6
6
|
import { DebouncedFunc } from 'lodash';
|
|
7
7
|
import * as _reduxjs_toolkit from '@reduxjs/toolkit';
|
|
8
8
|
|
|
@@ -31,7 +31,7 @@ declare class StreamActions {
|
|
|
31
31
|
}
|
|
32
32
|
declare function useStreamSource(channel: StreamSourceProps): {
|
|
33
33
|
connected: boolean;
|
|
34
|
-
subscription: Subscription
|
|
34
|
+
subscription: Subscription | null;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
declare const NavigationContext: React.Context<NavigationContextProps>;
|
|
@@ -74,27 +74,11 @@ declare const receiveResponse: _reduxjs_toolkit.ActionCreatorWithPreparedPayload
|
|
|
74
74
|
response: PageResponse;
|
|
75
75
|
}, "@@superglue/RECEIVE_RESPONSE", never, never>;
|
|
76
76
|
|
|
77
|
-
type
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
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;
|
|
98
82
|
|
|
99
83
|
declare function useSuperglue(): SuperglueState;
|
|
100
84
|
|
|
@@ -109,4 +93,4 @@ declare const setup: ({ initialPage, baseUrl, path, store, buildVisitAndRemote,
|
|
|
109
93
|
};
|
|
110
94
|
declare function Application({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, mapping, ...rest }: ApplicationProps): React.JSX.Element;
|
|
111
95
|
|
|
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,
|
|
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 };
|
package/dist/superglue.mjs
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
ujsHandlers,
|
|
34
34
|
unproxy,
|
|
35
35
|
urlToPageKey
|
|
36
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-ZATKIRIF.mjs";
|
|
37
37
|
|
|
38
38
|
// node_modules/lodash/lodash.js
|
|
39
39
|
var require_lodash = __commonJS({
|
|
@@ -5529,7 +5529,7 @@ import { useSelector as useSelector3 } from "react-redux";
|
|
|
5529
5529
|
// lib/hooks/useContent.tsx
|
|
5530
5530
|
import { useSelector, useStore } from "react-redux";
|
|
5531
5531
|
import { useMemo, useRef } from "react";
|
|
5532
|
-
function useContent(fragmentRef
|
|
5532
|
+
function useContent(fragmentRef) {
|
|
5533
5533
|
const superglueState = useSuperglue();
|
|
5534
5534
|
const currentPageKey = superglueState.currentPageKey;
|
|
5535
5535
|
const dependencies = useRef(/* @__PURE__ */ new Set());
|
|
@@ -5554,16 +5554,11 @@ function useContent(fragmentRef, options) {
|
|
|
5554
5554
|
});
|
|
5555
5555
|
}
|
|
5556
5556
|
);
|
|
5557
|
-
const raiseOnMissing = !(options?.optional ?? false);
|
|
5558
5557
|
const store = useStore();
|
|
5559
5558
|
const proxy = useMemo(() => {
|
|
5560
5559
|
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
5561
5560
|
if (fragmentId && !sourceData) {
|
|
5562
|
-
|
|
5563
|
-
throw new Error(`Fragment with id "${fragmentId}" not found`);
|
|
5564
|
-
} else {
|
|
5565
|
-
return void 0;
|
|
5566
|
-
}
|
|
5561
|
+
return void 0;
|
|
5567
5562
|
}
|
|
5568
5563
|
return createProxy(
|
|
5569
5564
|
sourceData,
|
|
@@ -5571,7 +5566,7 @@ function useContent(fragmentRef, options) {
|
|
|
5571
5566
|
dependencies.current,
|
|
5572
5567
|
proxyCache
|
|
5573
5568
|
);
|
|
5574
|
-
}, [sourceData, trackedFragments
|
|
5569
|
+
}, [sourceData, trackedFragments]);
|
|
5575
5570
|
return proxy;
|
|
5576
5571
|
}
|
|
5577
5572
|
function unproxy2(proxy) {
|
|
@@ -5584,8 +5579,8 @@ import { produce } from "immer";
|
|
|
5584
5579
|
function useSetFragment() {
|
|
5585
5580
|
const dispatch = useDispatch();
|
|
5586
5581
|
const fragments = useSelector2((state) => state.fragments);
|
|
5587
|
-
|
|
5588
|
-
const fragmentId = typeof
|
|
5582
|
+
function setter(fragmentRefOrId, updater) {
|
|
5583
|
+
const fragmentId = typeof fragmentRefOrId === "string" ? fragmentRefOrId : fragmentRefOrId.__id;
|
|
5589
5584
|
const currentFragment = fragments[fragmentId];
|
|
5590
5585
|
if (currentFragment === void 0) {
|
|
5591
5586
|
throw new Error(`Fragment with id "${fragmentId}" not found`);
|
|
@@ -5597,7 +5592,8 @@ function useSetFragment() {
|
|
|
5597
5592
|
data: updatedFragment
|
|
5598
5593
|
})
|
|
5599
5594
|
);
|
|
5600
|
-
}
|
|
5595
|
+
}
|
|
5596
|
+
return setter;
|
|
5601
5597
|
}
|
|
5602
5598
|
|
|
5603
5599
|
// lib/hooks/index.ts
|
|
@@ -5669,7 +5665,7 @@ function useStreamSource(channel) {
|
|
|
5669
5665
|
return () => {
|
|
5670
5666
|
};
|
|
5671
5667
|
}
|
|
5672
|
-
}, [cable2, channel, currentPageKey]);
|
|
5668
|
+
}, [cable2, JSON.stringify(channel), currentPageKey]);
|
|
5673
5669
|
return {
|
|
5674
5670
|
connected,
|
|
5675
5671
|
subscription: subscriptionRef.current
|
|
@@ -6059,7 +6055,21 @@ var rootReducer = {
|
|
|
6059
6055
|
};
|
|
6060
6056
|
|
|
6061
6057
|
// lib/index.tsx
|
|
6062
|
-
|
|
6058
|
+
function getConfig(name) {
|
|
6059
|
+
if (typeof document !== "undefined") {
|
|
6060
|
+
const element = document.head.querySelector(
|
|
6061
|
+
`meta[name='action-cable-${name}']`
|
|
6062
|
+
);
|
|
6063
|
+
if (element) {
|
|
6064
|
+
return element.getAttribute("content") || "/cable";
|
|
6065
|
+
} else {
|
|
6066
|
+
return "/cable";
|
|
6067
|
+
}
|
|
6068
|
+
} else {
|
|
6069
|
+
return "/cable";
|
|
6070
|
+
}
|
|
6071
|
+
}
|
|
6072
|
+
var cable = createConsumer(getConfig("url"));
|
|
6063
6073
|
var hasWindow2 = typeof window !== "undefined";
|
|
6064
6074
|
var createHistory = () => {
|
|
6065
6075
|
if (hasWindow2) {
|