import { Action, ThunkDispatch, EnhancedStore, Tuple, StoreEnhancer, ThunkAction } from '@reduxjs/toolkit';
import { History } from 'history';
type FetchArgs = [string, BasicRequestInit];
type USER_SPECIFIED_STRING = string;
interface GraftingSuccessAction extends Action {
type: '@@superglue/GRAFTING_SUCCESS' | USER_SPECIFIED_STRING;
payload: {
pageKey: string;
keyPath: string;
};
}
interface GraftingErrorAction extends Action {
type: '@@superglue/GRAFTING_ERROR' | USER_SPECIFIED_STRING;
payload: {
pageKey: string;
url: string;
err: unknown;
keyPath: string;
};
}
interface Visit {
(input: string | PageKey, options: VisitProps): Promise;
}
interface VisitProps extends Omit {
placeholderKey?: PageKey;
revisit?: boolean;
}
interface Remote {
(input: string | PageKey, options: RemoteProps): Promise;
}
interface BaseProps extends RequestInit {
method?: string;
body?: BodyInit;
headers?: {
[key: string]: string;
};
beforeSave?: BeforeSave;
}
interface RemoteProps extends BaseProps {
pageKey?: PageKey;
force?: boolean;
}
interface BeforeSave {
(prevPage: VisitResponse, receivedPage: VisitResponse): VisitResponse;
}
interface ApplicationRemote {
(input: string | PageKey, options: RemoteProps & {
dataset?: {
[name: string]: string | undefined;
};
}): Promise;
}
interface ApplicationVisit {
(input: string | PageKey, options: VisitProps & {
dataset?: {
[name: string]: string | undefined;
};
}): Promise;
}
declare function pageReducer(state: AllPages | undefined, action: Action): AllPages;
declare function superglueReducer(state: SuperglueState | undefined, action: Action): SuperglueState;
declare const rootReducer: {
superglue: typeof superglueReducer;
pages: typeof pageReducer;
};
type PageKey = string;
type RestoreStrategy = 'fromCacheOnly' | 'revisitOnly' | 'fromCacheAndRevisitInBackground';
type NavigationAction = 'push' | 'replace' | 'none';
type ComponentIdentifier = string;
type Keypath = string;
type JSONPrimitive = string | number | boolean | null | undefined;
type JSONObject = {
[key: string]: JSONValue;
};
type JSONMappable = JSONValue[] | JSONObject;
type JSONKeyable = JSONObject[] | JSONObject;
type JSONValue = JSONPrimitive | JSONMappable;
interface ParsedResponse {
rsp: Response;
json: PageResponse;
}
type Defer = {
url: string;
type: 'auto' | 'manual';
path: Keypath;
successAction: string;
failAction: string;
};
type VisitResponse = {
data: T;
componentIdentifier: ComponentIdentifier;
assets: string[];
csrfToken?: string;
fragments: Fragment[];
defers: Defer[];
slices: JSONObject;
renderedAt: number;
restoreStrategy: RestoreStrategy;
};
type Page = VisitResponse & {
savedAt: number;
};
type GraftResponse = VisitResponse & {
action: 'graft';
path: Keypath;
};
type PageResponse = GraftResponse | VisitResponse;
type Fragment = {
type: string;
path: Keypath;
};
type AllPages = Record>;
interface SuperglueState {
currentPageKey: PageKey;
search: Record;
csrfToken?: string;
assets: string[];
}
interface RootState {
superglue: SuperglueState;
pages: AllPages;
[name: string]: unknown;
}
interface Meta {
pageKey: PageKey;
page: VisitResponse;
redirected: boolean;
rsp: Response;
fetchArgs: FetchArgs;
componentIdentifier: ComponentIdentifier;
needsRefresh: boolean;
}
interface VisitMeta extends Meta {
navigationAction: NavigationAction;
}
type VisitCreator = (input: string | PageKey, options: VisitProps) => VisitMetaThunk;
type RemoteCreator = (input: string | PageKey, options: RemoteProps) => MetaThunk;
type Dispatch = ThunkDispatch;
type SuperglueStore = EnhancedStore,
StoreEnhancer
]>>;
interface Handlers {
onClick: (event: React.MouseEvent) => void;
onSubmit: (event: React.FormEvent) => void;
}
type UJSHandlers = ({ ujsAttributePrefix, visit, remote, store, }: {
ujsAttributePrefix: string;
visit: ApplicationVisit;
remote: ApplicationRemote;
store: SuperglueStore;
}) => Handlers;
interface HistoryState {
superglue: true;
pageKey: PageKey;
posX: number;
posY: number;
}
type SaveAndProcessPageThunk = ThunkAction, RootState, undefined, Action>;
type MetaThunk = ThunkAction, RootState, undefined, Action>;
type VisitMetaThunk = ThunkAction, RootState, undefined, Action>;
type DefermentThunk = ThunkAction, RootState, undefined, Action>;
interface BasicRequestInit extends RequestInit {
headers?: {
[key: string]: string;
};
}
type NavigateTo = (path: Keypath, options: {
action: NavigationAction;
}) => boolean;
type NavigationContextProps = {
navigateTo: NavigateTo;
visit: ApplicationVisit;
remote: ApplicationRemote;
pageKey: SuperglueState['currentPageKey'];
search: SuperglueState['search'];
};
type NavigationProviderProps = {
history: History;
visit: ApplicationVisit;
remote: ApplicationRemote;
mapping: Record;
initialPageKey: PageKey;
};
interface BuildStore {
(initialState: RootState, reducer: typeof rootReducer): SuperglueStore;
}
interface BuildVisitAndRemote {
(navigatorRef: React.RefObject<{
navigateTo: NavigateTo;
} | null>, store: SuperglueStore): {
visit: ApplicationVisit;
remote: ApplicationRemote;
};
}
interface SetupProps {
initialPage: VisitResponse;
baseUrl: string;
path: string;
store: SuperglueStore;
buildVisitAndRemote: BuildVisitAndRemote;
history?: History;
navigatorRef: React.RefObject<{
navigateTo: NavigateTo;
} | null>;
}
interface ApplicationProps extends React.ComponentPropsWithoutRef<'div'> {
initialPage: VisitResponse;
baseUrl: string;
path: string;
buildVisitAndRemote: BuildVisitAndRemote;
mapping: Record;
history?: History;
store: SuperglueStore;
}
declare class MismatchedComponentError extends Error {
constructor(message: string);
}
declare const remote: RemoteCreator;
declare const visit: VisitCreator;
declare function saveAndProcessPage(pageKey: string, page: VisitResponse | GraftResponse): SaveAndProcessPageThunk;
export { type GraftingSuccessAction as $, type ApplicationVisit as A, type SaveAndProcessPageThunk as B, type ComponentIdentifier as C, type Defer as D, type MetaThunk as E, type FetchArgs as F, type GraftResponse as G, type Handlers as H, type VisitMetaThunk as I, type JSONMappable as J, type Keypath as K, type DefermentThunk as L, type Meta as M, type NavigationContextProps as N, type BasicRequestInit as O, type PageKey as P, type BuildStore as Q, type RestoreStrategy as R, type SuperglueState as S, type BuildVisitAndRemote as T, type UJSHandlers as U, type VisitResponse as V, type Visit as W, type VisitProps as X, type Remote as Y, type RemoteProps as Z, type BeforeSave as _, type JSONValue as a, type GraftingErrorAction as a0, MismatchedComponentError as a1, remote as a2, visit as a3, type NavigationProviderProps as b, type NavigateTo as c, type SuperglueStore as d, type SetupProps as e, type ApplicationRemote as f, type ApplicationProps as g, superglueReducer as h, type NavigationAction as i, type JSONPrimitive as j, type JSONObject as k, type JSONKeyable as l, type ParsedResponse as m, type Page as n, type PageResponse as o, pageReducer as p, type Fragment as q, rootReducer as r, saveAndProcessPage as s, type AllPages as t, type RootState as u, type VisitMeta as v, type VisitCreator as w, type RemoteCreator as x, type Dispatch as y, type HistoryState as z };