@thoughtbot/superglue 2.0.0-alpha.10 → 2.0.0-alpha.11

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.
@@ -72,14 +72,12 @@ declare const rootReducer: {
72
72
  type FragmentProxy = {
73
73
  __fragment: true;
74
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
75
  type FragmentRefOrId = FragmentRef | string;
79
- declare function useContent<T = JSONMappable>(): ProxiedContent<T>;
80
- declare function useContent<T = JSONMappable>(fragmentRef: FragmentRefOrId): ProxiedContent<T>;
76
+ declare function useContent<T = JSONMappable>(): T;
77
+ declare function useContent<T = JSONMappable>(fragmentRef: FragmentRefOrId): T;
81
78
  declare function unproxy<T>(proxy: T): Unproxy<T>;
82
79
 
80
+ type ReceiveType<T> = unknown;
83
81
  type PageKey = string;
84
82
  type RestoreStrategy = 'fromCacheOnly' | 'revisitOnly' | 'fromCacheAndRevisitInBackground';
85
83
  type NavigationAction = 'push' | 'replace' | 'none';
@@ -93,11 +91,11 @@ type JSONObject = {
93
91
  type JSONMappable = JSONValue[] | JSONObject;
94
92
  type JSONKeyable = JSONObject[] | JSONObject;
95
93
  type JSONValue = JSONPrimitive | JSONMappable;
96
- type Fragment<T, Present = false> = {
94
+ type Fragment<T, Present = false> = Present extends true ? T & {
97
95
  __id: string;
98
- __fragmentType?: T;
99
- __required?: Present extends boolean ? Present : false;
100
- };
96
+ } : (T & {
97
+ __id: string;
98
+ }) | undefined;
101
99
  type Unproxy<T> = T extends FragmentProxy ? FragmentRef : T extends Fragment<unknown, unknown> ? FragmentRef : T extends (infer U)[] ? Unproxy<U>[] : T extends object ? {
102
100
  [K in keyof T]: Unproxy<T[K]>;
103
101
  } : T;
@@ -280,4 +278,4 @@ declare const visit: VisitCreator;
280
278
 
281
279
  declare function saveAndProcessPage(pageKey: string, page: PageResponse): SaveAndProcessPageThunk;
282
280
 
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 };
281
+ export { type DefermentThunk as $, type ApplicationRemote as A, type FragmentRef as B, type ComponentIdentifier as C, type Defer as D, type AllPages as E, type FetchArgs as F, type GraftResponse as G, type Handlers as H, type AllFragments as I, type JSONMappable as J, type Keypath as K, type RootState as L, type Meta as M, type NavigationProviderProps as N, type VisitCreator as O, type PageKey as P, type RemoteCreator as Q, type ReceiveType as R, type SuperglueStore as S, type Dispatch as T, type Unproxy as U, type VisitMeta as V, type UJSHandlers as W, type HistoryState as X, type SaveAndProcessPageThunk as Y, type MetaThunk as Z, type VisitMetaThunk as _, type JSONValue as a, type BasicRequestInit as a0, type BuildStore as a1, type BuildVisitAndRemote as a2, type Visit as a3, type VisitProps as a4, type Remote as a5, type RemoteProps as a6, type BeforeSave as a7, type GraftingSuccessAction as a8, type GraftingErrorAction as a9, useContent as aa, MismatchedComponentError as ab, remote as ac, visit as ad, 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 RestoreStrategy as m, type NavigationAction as n, type JSONPrimitive as o, pageReducer as p, type JSONObject as q, rootReducer as r, saveAndProcessPage as s, type JSONKeyable as t, unproxy as u, type ParsedResponse as v, type Page as w, type StreamMessage as x, type StreamResponse as y, type FragmentPath as z };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./cjs/superglue.cjs')
5
+ } else {
6
+ module.exports = require('./cjs/superglue.development.cjs')
7
+ }
@@ -1,6 +1,6 @@
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 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';
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-DwEjetER.mjs';
3
+ export { I as AllFragments, E as AllPages, a0 as BasicRequestInit, a7 as BeforeSave, a1 as BuildStore, a2 as BuildVisitAndRemote, C as ComponentIdentifier, D as Defer, $ as DefermentThunk, T as Dispatch, z as FragmentPath, B as FragmentRef, G as GraftResponse, a9 as GraftingErrorAction, a8 as GraftingSuccessAction, X as HistoryState, t as JSONKeyable, q as JSONObject, o as JSONPrimitive, M as Meta, Z as MetaThunk, n as NavigationAction, w as Page, v as ParsedResponse, R as ReceiveType, a5 as Remote, Q as RemoteCreator, a6 as RemoteProps, m as RestoreStrategy, L as RootState, Y as SaveAndProcessPageThunk, x as StreamMessage, y as StreamResponse, W as UJSHandlers, a3 as Visit, O as VisitCreator, V as VisitMeta, _ as VisitMetaThunk, a4 as VisitProps, p as pageReducer, r as rootReducer, s as saveAndProcessPage, l as superglueReducer, u as unproxy, aa as useContent } from './index-DwEjetER.mjs';
4
4
  import React from 'react';
5
5
  import { ChannelNameWithParams, Subscription } from '@rails/actioncable';
6
6
  import { DebouncedFunc } from 'lodash';
@@ -0,0 +1,417 @@
1
+ import {
2
+ CableContext,
3
+ GRAFTING_ERROR,
4
+ GRAFTING_SUCCESS,
5
+ StreamActions,
6
+ __ΩAllFragments,
7
+ __ΩAllPages,
8
+ __ΩApplicationProps,
9
+ __ΩApplicationRemote,
10
+ __ΩApplicationVisit,
11
+ __ΩBasicRequestInit,
12
+ __ΩBeforeSave,
13
+ __ΩBuildStore,
14
+ __ΩBuildVisitAndRemote,
15
+ __ΩComponentIdentifier,
16
+ __ΩDefer,
17
+ __ΩDefermentThunk,
18
+ __ΩDispatch,
19
+ __ΩFetchArgs,
20
+ __ΩFragment,
21
+ __ΩFragmentPath,
22
+ __ΩFragmentRef,
23
+ __ΩGraftResponse,
24
+ __ΩGraftingErrorAction,
25
+ __ΩGraftingSuccessAction,
26
+ __ΩHandlers,
27
+ __ΩHistoryState,
28
+ __ΩJSONKeyable,
29
+ __ΩJSONMappable,
30
+ __ΩJSONObject,
31
+ __ΩJSONPrimitive,
32
+ __ΩJSONValue,
33
+ __ΩKeypath,
34
+ __ΩMeta,
35
+ __ΩMetaThunk,
36
+ __ΩNavigateTo,
37
+ __ΩNavigationAction,
38
+ __ΩNavigationContextProps,
39
+ __ΩNavigationProviderProps,
40
+ __ΩPage,
41
+ __ΩPageKey,
42
+ __ΩPageResponse,
43
+ __ΩParsedResponse,
44
+ __ΩReceiveType,
45
+ __ΩRemote,
46
+ __ΩRemoteCreator,
47
+ __ΩRemoteProps,
48
+ __ΩRestoreStrategy,
49
+ __ΩRootState,
50
+ __ΩSaveAndProcessPageThunk,
51
+ __ΩSaveResponse,
52
+ __ΩSetupProps,
53
+ __ΩStreamMessage,
54
+ __ΩStreamResponse,
55
+ __ΩSuperglueState,
56
+ __ΩSuperglueStore,
57
+ __ΩUJSHandlers,
58
+ __ΩUnproxy,
59
+ __ΩVisit,
60
+ __ΩVisitCreator,
61
+ __ΩVisitMeta,
62
+ __ΩVisitMetaThunk,
63
+ __ΩVisitProps,
64
+ argsForHistory,
65
+ beforeFetch,
66
+ beforeRemote,
67
+ beforeVisit,
68
+ config,
69
+ copyPage,
70
+ getIn,
71
+ historyChange,
72
+ pageReducer,
73
+ receiveResponse,
74
+ removePage,
75
+ rootReducer,
76
+ saveAndProcessPage,
77
+ saveResponse,
78
+ setActivePage,
79
+ setCSRFToken,
80
+ superglueReducer,
81
+ ujsHandlers,
82
+ unproxy,
83
+ urlToPageKey,
84
+ useContent,
85
+ useSetFragment,
86
+ useStreamSource,
87
+ useSuperglue
88
+ } from "./chunk-AEIBTV6M.development.mjs";
89
+
90
+ // lib/index.tsx
91
+ import React2, { useRef, useMemo } from "react";
92
+ import { Provider } from "react-redux";
93
+ import { createConsumer } from "@rails/actioncable";
94
+ import { createBrowserHistory, createMemoryHistory } from "history";
95
+
96
+ // lib/components/Navigation.tsx
97
+ import React, { createContext, useEffect, useLayoutEffect, forwardRef, useImperativeHandle } from "react";
98
+ import { useDispatch, useSelector, useStore } from "react-redux";
99
+ function __assignType(fn, args) {
100
+ fn.__type = args;
101
+ return fn;
102
+ }
103
+ var NavigationContext = (createContext.\u03A9 = [[() => __\u03A9NavigationContextProps, "n!"]], createContext({}));
104
+ var hasWindow = typeof window !== "undefined";
105
+ var setWindowScroll = __assignType((posX, posY) => {
106
+ hasWindow && window.scrollTo(posX, posY);
107
+ }, ["posX", "posY", "", `P'2!'2"$/#`]);
108
+ var notFound = __assignType((identifier) => {
109
+ let reminder = "";
110
+ if (!identifier) {
111
+ reminder = "Did you forget to add `json.componentIdentifier` in your application.json.props layout?";
112
+ }
113
+ const error = new Error(`Superglue Nav component was looking for ${identifier} but could not find it in your mapping. ${reminder}`);
114
+ throw error;
115
+ }, ["identifier", "", 'PP&-J2!!/"']);
116
+ var NavigationProvider = forwardRef(__assignType(function NavigationProvider2({ history, visit, remote, mapping }, ref) {
117
+ const dispatch = useDispatch();
118
+ const pages = (useSelector.\u03A9 = [[() => __\u03A9RootState, "n!"], [() => __\u03A9AllPages, "n!"]], useSelector(__assignType((state) => state.pages, ["state", "", 'P"2!"/"'])));
119
+ const superglue = (useSelector.\u03A9 = [[() => __\u03A9RootState, "n!"], [() => __\u03A9SuperglueState, "n!"]], useSelector(__assignType((state) => state.superglue, ["state", "", 'P"2!"/"'])));
120
+ const currentPageKey = (useSelector.\u03A9 = [[() => __\u03A9RootState, "n!"], ["&"]], useSelector(__assignType((state) => state.superglue.currentPageKey, ["state", "", 'P"2!"/"'])));
121
+ const store = (useStore.\u03A9 = [[() => __\u03A9RootState, "n!"]], useStore());
122
+ useEffect(() => {
123
+ return history.listen(onHistoryChange);
124
+ }, []);
125
+ useLayoutEffect(() => {
126
+ const state = history.location.state;
127
+ if (state && "superglue" in state) {
128
+ const { posX, posY } = state;
129
+ setWindowScroll(posX, posY);
130
+ }
131
+ }, [currentPageKey]);
132
+ useImperativeHandle(ref, () => {
133
+ return {
134
+ navigateTo
135
+ };
136
+ }, []);
137
+ const onHistoryChange = __assignType(({ location, action }) => {
138
+ const state = location.state;
139
+ if (action !== "POP") {
140
+ return;
141
+ }
142
+ if (!state && location.hash !== "") {
143
+ const nextPageKey = urlToPageKey(location.pathname + location.search);
144
+ const containsKey = !!pages[nextPageKey];
145
+ if (containsKey) {
146
+ history.replace({
147
+ pathname: location.pathname,
148
+ search: location.search,
149
+ hash: location.hash
150
+ }, {
151
+ superglue: true,
152
+ posY: window.pageYOffset,
153
+ posX: window.pageXOffset
154
+ });
155
+ }
156
+ }
157
+ if (state && "superglue" in state) {
158
+ const pageKey = urlToPageKey(location.pathname + location.search);
159
+ const prevPageKey = store.getState().superglue.currentPageKey;
160
+ const containsKey = !!pages[pageKey];
161
+ if (containsKey) {
162
+ const { restoreStrategy } = pages[pageKey];
163
+ switch (restoreStrategy) {
164
+ case "fromCacheOnly":
165
+ dispatch(setActivePage({ pageKey }));
166
+ break;
167
+ case "fromCacheAndRevisitInBackground":
168
+ dispatch(setActivePage({ pageKey }));
169
+ visit(pageKey, { revisit: true });
170
+ break;
171
+ case "revisitOnly":
172
+ default:
173
+ visit(pageKey, { revisit: true }).then(() => {
174
+ const noNav = prevPageKey === store.getState().superglue.currentPageKey;
175
+ if (noNav) {
176
+ dispatch(setActivePage({ pageKey }));
177
+ }
178
+ });
179
+ }
180
+ } else {
181
+ visit(pageKey, { revisit: true }).then(() => {
182
+ const noNav = prevPageKey === store.getState().superglue.currentPageKey;
183
+ if (noNav) {
184
+ dispatch(setActivePage({ pageKey }));
185
+ }
186
+ });
187
+ }
188
+ }
189
+ }, ["Update", "param0", "", 'P"w!2"$/#']);
190
+ const navigateTo = __assignType((path, { action } = {
191
+ action: "push"
192
+ }) => {
193
+ if (action === "none") {
194
+ return false;
195
+ }
196
+ const nextPageKey = urlToPageKey(path);
197
+ const hasPage = Object.prototype.hasOwnProperty.call(store.getState().pages, nextPageKey);
198
+ if (hasPage) {
199
+ const location = history.location;
200
+ const state = location.state;
201
+ const historyArgs = [
202
+ path,
203
+ {
204
+ superglue: true,
205
+ posY: 0,
206
+ posX: 0
207
+ }
208
+ ];
209
+ if (action === "push") {
210
+ if (hasWindow) {
211
+ history.replace({
212
+ pathname: location.pathname,
213
+ search: location.search,
214
+ hash: location.hash
215
+ }, {
216
+ ...state,
217
+ posY: window.scrollY,
218
+ posX: window.scrollX
219
+ });
220
+ }
221
+ history.push(...historyArgs);
222
+ dispatch(setActivePage({ pageKey: nextPageKey }));
223
+ }
224
+ if (action === "replace") {
225
+ history.replace(...historyArgs);
226
+ if (currentPageKey !== nextPageKey) {
227
+ dispatch(setActivePage({ pageKey: nextPageKey }));
228
+ dispatch(removePage({ pageKey: currentPageKey }));
229
+ }
230
+ }
231
+ return true;
232
+ } else {
233
+ console.warn(`\`navigateTo\` was called , but could not find
234
+ the pageKey in the store. This may happen when the wrong
235
+ content_location was set in your non-get controller action.
236
+ No navigation will take place`);
237
+ return false;
238
+ }
239
+ }, ["path", "param1", "", 'P"2!"2""/#']);
240
+ const { search } = superglue;
241
+ const { componentIdentifier } = pages[currentPageKey];
242
+ const Component = mapping[componentIdentifier];
243
+ if (Component) {
244
+ return /* @__PURE__ */ React.createElement(NavigationContext.Provider, { value: { pageKey: currentPageKey, search, navigateTo, visit, remote } }, /* @__PURE__ */ React.createElement(Component, null));
245
+ } else {
246
+ notFound(componentIdentifier);
247
+ }
248
+ }, [() => __\u03A9NavigationProviderProps, "param0", "ref", "NavigationProvider", 'Pn!2"!2#"/$']));
249
+
250
+ // lib/index.tsx
251
+ function __assignType2(fn, args) {
252
+ fn.__type = args;
253
+ return fn;
254
+ }
255
+ function getConfig(name) {
256
+ if (typeof document !== "undefined") {
257
+ const element = document.head.querySelector(`meta[name='action-cable-${name}']`);
258
+ if (element) {
259
+ return element.getAttribute("content") || "/cable";
260
+ } else {
261
+ return "/cable";
262
+ }
263
+ } else {
264
+ return "/cable";
265
+ }
266
+ }
267
+ getConfig.__type = ["name", "getConfig", 'P&2!"/"'];
268
+ var cable = createConsumer(getConfig("url"));
269
+ var hasWindow2 = typeof window !== "undefined";
270
+ var createHistory = () => {
271
+ if (hasWindow2) {
272
+ return createBrowserHistory({});
273
+ } else {
274
+ return createMemoryHistory({});
275
+ }
276
+ };
277
+ var prepareStore = __assignType2(
278
+ (store, initialPage, path) => {
279
+ const initialPageKey = urlToPageKey(path);
280
+ const { csrfToken } = initialPage;
281
+ store.dispatch(historyChange({
282
+ pageKey: initialPageKey
283
+ }));
284
+ store.dispatch(receiveResponse({ pageKey: initialPageKey, response: initialPage }));
285
+ store.dispatch(saveAndProcessPage(initialPageKey, initialPage));
286
+ store.dispatch(setCSRFToken({ csrfToken }));
287
+ },
288
+ [() => __\u03A9SuperglueStore, "store", () => __\u03A9SaveResponse, "initialPage", "path", "", 'Pn!2"n#2$&2%"/&']
289
+ );
290
+ var setup = __assignType2(({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, navigatorRef }) => {
291
+ config.baseUrl = baseUrl;
292
+ const { visit, remote } = buildVisitAndRemote(navigatorRef, store);
293
+ const initialPageKey = urlToPageKey(path);
294
+ const nextHistory = history || createHistory();
295
+ nextHistory.replace(...argsForHistory(path));
296
+ prepareStore(store, initialPage, path);
297
+ const handlers = ujsHandlers({
298
+ visit,
299
+ remote,
300
+ ujsAttributePrefix: "data-sg",
301
+ store
302
+ });
303
+ const streamActions = new StreamActions({ remote, store });
304
+ return {
305
+ visit,
306
+ remote,
307
+ nextHistory,
308
+ initialPageKey,
309
+ ujs: handlers,
310
+ streamActions
311
+ };
312
+ }, [() => __\u03A9SetupProps, "param0", "", 'Pn!2""/#']);
313
+ if (process.env.NODE_ENV !== "production") {
314
+ console.info("%cSuperglue Development Mode: Remember to build for production before deploying.", "font-weight:bold");
315
+ }
316
+ function Application({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, mapping, ...rest }) {
317
+ const navigatorRef = (useRef.\u03A9 = [[() => __\u03A9NavigateTo, "navigateTo", 'PPn!4"M,J']], useRef(null));
318
+ const { visit, remote, nextHistory, initialPageKey, ujs, streamActions } = useMemo(() => {
319
+ return setup({
320
+ initialPage,
321
+ baseUrl,
322
+ path,
323
+ store,
324
+ buildVisitAndRemote,
325
+ history,
326
+ navigatorRef
327
+ });
328
+ }, []);
329
+ return /* @__PURE__ */ React2.createElement("div", { onClick: ujs.onClick, onSubmit: ujs.onSubmit, ...rest }, /* @__PURE__ */ React2.createElement(Provider, { store }, /* @__PURE__ */ React2.createElement(CableContext.Provider, { value: { streamActions, cable } }, /* @__PURE__ */ React2.createElement(NavigationProvider, { ref: navigatorRef, visit, remote, mapping, history: nextHistory, initialPageKey }))));
330
+ }
331
+ Application.__type = [() => __\u03A9ApplicationProps, "param0", "Application", 'Pn!2""/#'];
332
+ export {
333
+ Application,
334
+ GRAFTING_ERROR,
335
+ GRAFTING_SUCCESS,
336
+ NavigationContext,
337
+ NavigationProvider,
338
+ __\u03A9AllFragments,
339
+ __\u03A9AllPages,
340
+ __\u03A9ApplicationProps,
341
+ __\u03A9ApplicationRemote,
342
+ __\u03A9ApplicationVisit,
343
+ __\u03A9BasicRequestInit,
344
+ __\u03A9BeforeSave,
345
+ __\u03A9BuildStore,
346
+ __\u03A9BuildVisitAndRemote,
347
+ __\u03A9ComponentIdentifier,
348
+ __\u03A9Defer,
349
+ __\u03A9DefermentThunk,
350
+ __\u03A9Dispatch,
351
+ __\u03A9FetchArgs,
352
+ __\u03A9Fragment,
353
+ __\u03A9FragmentPath,
354
+ __\u03A9FragmentRef,
355
+ __\u03A9GraftResponse,
356
+ __\u03A9GraftingErrorAction,
357
+ __\u03A9GraftingSuccessAction,
358
+ __\u03A9Handlers,
359
+ __\u03A9HistoryState,
360
+ __\u03A9JSONKeyable,
361
+ __\u03A9JSONMappable,
362
+ __\u03A9JSONObject,
363
+ __\u03A9JSONPrimitive,
364
+ __\u03A9JSONValue,
365
+ __\u03A9Keypath,
366
+ __\u03A9Meta,
367
+ __\u03A9MetaThunk,
368
+ __\u03A9NavigateTo,
369
+ __\u03A9NavigationAction,
370
+ __\u03A9NavigationContextProps,
371
+ __\u03A9NavigationProviderProps,
372
+ __\u03A9Page,
373
+ __\u03A9PageKey,
374
+ __\u03A9PageResponse,
375
+ __\u03A9ParsedResponse,
376
+ __\u03A9ReceiveType,
377
+ __\u03A9Remote,
378
+ __\u03A9RemoteCreator,
379
+ __\u03A9RemoteProps,
380
+ __\u03A9RestoreStrategy,
381
+ __\u03A9RootState,
382
+ __\u03A9SaveAndProcessPageThunk,
383
+ __\u03A9SaveResponse,
384
+ __\u03A9SetupProps,
385
+ __\u03A9StreamMessage,
386
+ __\u03A9StreamResponse,
387
+ __\u03A9SuperglueState,
388
+ __\u03A9SuperglueStore,
389
+ __\u03A9UJSHandlers,
390
+ __\u03A9Unproxy,
391
+ __\u03A9Visit,
392
+ __\u03A9VisitCreator,
393
+ __\u03A9VisitMeta,
394
+ __\u03A9VisitMetaThunk,
395
+ __\u03A9VisitProps,
396
+ beforeFetch,
397
+ beforeRemote,
398
+ beforeVisit,
399
+ copyPage,
400
+ getIn,
401
+ pageReducer,
402
+ prepareStore,
403
+ receiveResponse,
404
+ removePage,
405
+ rootReducer,
406
+ saveAndProcessPage,
407
+ saveResponse,
408
+ setup,
409
+ superglueReducer,
410
+ unproxy,
411
+ urlToPageKey,
412
+ useContent,
413
+ useSetFragment,
414
+ useStreamSource,
415
+ useSuperglue
416
+ };
417
+ //# sourceMappingURL=superglue.development.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../lib/index.tsx","../lib/components/Navigation.tsx"],"sourcesContent":["function __assignType(fn, args) {\n fn.__type = args;\n return fn;\n}\nimport React, { useRef, useMemo } from 'react';\nimport { config } from './config';\nimport { urlToPageKey, ujsHandlers, argsForHistory } from './utils';\nimport { saveAndProcessPage } from './action_creators';\nimport { historyChange, setCSRFToken, receiveResponse } from './actions';\nimport { Provider } from 'react-redux';\nimport { CableContext, StreamActions } from './hooks/useStreamSource';\nimport { createConsumer } from '@rails/actioncable';\nimport { createBrowserHistory, createMemoryHistory } from 'history';\nimport { NavigationProvider } from './components/Navigation';\nexport { NavigationProvider, NavigationContext } from './components/Navigation';\nexport { saveAndProcessPage } from './action_creators';\nexport { beforeFetch, beforeVisit, beforeRemote, copyPage, removePage, saveResponse, receiveResponse, GRAFTING_ERROR, GRAFTING_SUCCESS, } from './actions';\nexport * from './types';\n/*@ts-ignore*/\nimport { __ΩSuperglueStore, __ΩSaveResponse, __ΩSetupProps, __ΩNavigateTo, __ΩApplicationProps } from './types';\nimport { SaveResponse, ApplicationProps, NavigateTo, SuperglueStore, SetupProps, } from './types';\nexport { superglueReducer, pageReducer, rootReducer } from './reducers';\nexport { getIn } from './utils/immutability';\nexport { urlToPageKey };\nexport * from './hooks';\nexport { unproxy } from './hooks/useContent';\nfunction getConfig(name: string) {\n if (typeof document !== 'undefined') {\n const element = document.head.querySelector(`meta[name='action-cable-${name}']`);\n if (element) {\n return element.getAttribute('content') || '/cable';\n }\n else {\n return '/cable';\n }\n }\n else {\n return '/cable';\n }\n}\ngetConfig.__type = ['name', 'getConfig', 'P&2!\"/\"'];\nconst cable = createConsumer(getConfig('url'));\nconst hasWindow = typeof window !== 'undefined';\nconst createHistory = () => {\n if (hasWindow) {\n // This is used for client side rendering\n return createBrowserHistory({});\n }\n else {\n // This is used for server side rendering\n return createMemoryHistory({});\n }\n};\nexport const prepareStore = __assignType((store: SuperglueStore, initialPage: SaveResponse, path: string) => {\n const initialPageKey = urlToPageKey(path);\n const { csrfToken } = initialPage;\n store.dispatch(historyChange({\n pageKey: initialPageKey,\n }));\n store.dispatch(receiveResponse({ pageKey: initialPageKey, response: initialPage }));\n store.dispatch(saveAndProcessPage(initialPageKey, initialPage));\n store.dispatch(setCSRFToken({ csrfToken }));\n}\n/**\n * This is the setup function that the Application calls. Use this function if\n * you like to build your own Application component.\n */\n, [() => __ΩSuperglueStore, 'store', () => __ΩSaveResponse, 'initialPage', 'path', '', 'Pn!2\"n#2$&2%\"/&']);\n/**\n * This is the setup function that the Application calls. Use this function if\n * you like to build your own Application component.\n */\nexport const setup = __assignType(({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, navigatorRef, }: SetupProps) => {\n config.baseUrl = baseUrl;\n const { visit, remote } = buildVisitAndRemote(navigatorRef, store);\n const initialPageKey = urlToPageKey(path);\n const nextHistory = history || createHistory();\n nextHistory.replace(...argsForHistory(path));\n prepareStore(store, initialPage, path);\n const handlers = ujsHandlers({\n visit,\n remote,\n ujsAttributePrefix: 'data-sg',\n store,\n });\n const streamActions = new StreamActions({ remote, store });\n return {\n visit,\n remote,\n nextHistory,\n initialPageKey,\n ujs: handlers,\n streamActions,\n };\n}, [() => __ΩSetupProps, 'param0', '', 'Pn!2\"\"/#']);\nif (process.env.NODE_ENV !== 'production') {\n console.info('%cSuperglue Development Mode: ' +\n 'Remember to build for production before deploying.', 'font-weight:bold');\n}\n/**\n * The entry point to your superglue application. It sets up the redux Provider,\n * redux state and the Navigation component.\n *\n * This is a simple component, you can override this by copying the source code and\n * use the exported methods used by this component (`start` and `ujsHandler`).\n */\nfunction Application({ initialPage, baseUrl, path, store, buildVisitAndRemote, history, mapping, ...rest }: ApplicationProps) {\n const navigatorRef = (useRef.Ω = [[() => __ΩNavigateTo, 'navigateTo', 'PPn!4\"M,J']], useRef<{\n navigateTo: NavigateTo;\n } | null>(null));\n const { visit, remote, nextHistory, initialPageKey, ujs, streamActions } = useMemo(() => {\n return setup({\n initialPage,\n baseUrl,\n path,\n store,\n buildVisitAndRemote,\n history,\n navigatorRef,\n });\n }, []);\n // The Nav component is pretty bare and can be inherited from for custom\n // behavior or replaced with your own.\n return (<div onClick={ujs.onClick} onSubmit={ujs.onSubmit} {...rest}>\n <Provider store={store}>\n <CableContext.Provider value={{ streamActions, cable }}>\n <NavigationProvider ref={navigatorRef} visit={visit} remote={remote} mapping={mapping} history={nextHistory} initialPageKey={initialPageKey}/>\n </CableContext.Provider>\n </Provider>\n </div>);\n}\nApplication.__type = [() => __ΩApplicationProps, 'param0', 'Application', 'Pn!2\"\"/#'];\nexport { Application };\n","function __assignType(fn, args) {\n fn.__type = args;\n return fn;\n}\nimport React, { createContext, useEffect, useLayoutEffect, forwardRef, useImperativeHandle, ForwardedRef, } from 'react';\nimport { urlToPageKey } from '../utils';\nimport { removePage, setActivePage } from '../actions';\n/*@ts-ignore*/\nimport { __ΩNavigationContextProps, __ΩRootState, __ΩAllPages, __ΩSuperglueState, __ΩNavigationProviderProps } from '../types';\nimport { HistoryState, RootState, NavigateTo, NavigationContextProps, NavigationProviderProps, AllPages, SuperglueState, } from '../types';\nimport { Update } from 'history';\nimport { useDispatch, useSelector, useStore } from 'react-redux';\nconst NavigationContext = (createContext.Ω = [[() => __ΩNavigationContextProps, 'n!']], createContext<NavigationContextProps>({} as NavigationContextProps));\nconst hasWindow = typeof window !== 'undefined';\nconst setWindowScroll = __assignType((posX: number, posY: number): void => {\n hasWindow && window.scrollTo(posX, posY);\n}, ['posX', 'posY', '', 'P\\'2!\\'2\"$/#']);\nconst notFound = __assignType((identifier: string | undefined): never => {\n let reminder = '';\n if (!identifier) {\n reminder =\n 'Did you forget to add `json.componentIdentifier` in your application.json.props layout?';\n }\n const error = new Error(`Superglue Nav component was looking for ${identifier} but could not find it in your mapping. ${reminder}`);\n throw error;\n}, ['identifier', '', 'PP&-J2!!/\"']);\nconst NavigationProvider = forwardRef(__assignType(function NavigationProvider({ history, visit, remote, mapping }: NavigationProviderProps, ref: ForwardedRef<{\n navigateTo: NavigateTo | null;\n}>) {\n const dispatch = useDispatch();\n const pages = (useSelector.Ω = [[() => __ΩRootState, 'n!'], [() => __ΩAllPages, 'n!']], useSelector<RootState, AllPages>(__assignType((state) => state.pages, ['state', '', 'P\"2!\"/\"'])));\n const superglue = (useSelector.Ω = [[() => __ΩRootState, 'n!'], [() => __ΩSuperglueState, 'n!']], useSelector<RootState, SuperglueState>(__assignType((state) => state.superglue, ['state', '', 'P\"2!\"/\"'])));\n const currentPageKey = (useSelector.Ω = [[() => __ΩRootState, 'n!'], ['&']], useSelector<RootState, string>(__assignType((state) => state.superglue.currentPageKey, ['state', '', 'P\"2!\"/\"'])));\n const store = (useStore.Ω = [[() => __ΩRootState, 'n!']], useStore<RootState>());\n useEffect(() => {\n return history.listen(onHistoryChange);\n }, []);\n useLayoutEffect(() => {\n const state = history.location.state as HistoryState;\n if (state && 'superglue' in state) {\n const { posX, posY } = state;\n setWindowScroll(posX, posY);\n }\n }, [currentPageKey]);\n useImperativeHandle(ref, () => {\n return {\n navigateTo,\n };\n }, []);\n const onHistoryChange = __assignType(({ location, action }: Update): void => {\n const state = location.state as HistoryState;\n if (action !== 'POP') {\n return;\n }\n if (!state && location.hash !== '') {\n const nextPageKey = urlToPageKey(location.pathname + location.search);\n const containsKey = !!pages[nextPageKey];\n if (containsKey) {\n history.replace({\n pathname: location.pathname,\n search: location.search,\n hash: location.hash,\n }, {\n superglue: true,\n posY: window.pageYOffset,\n posX: window.pageXOffset,\n });\n }\n }\n if (state && 'superglue' in state) {\n const pageKey = urlToPageKey(location.pathname + location.search);\n const prevPageKey = store.getState().superglue.currentPageKey;\n const containsKey = !!pages[pageKey];\n if (containsKey) {\n const { restoreStrategy } = pages[pageKey];\n switch (restoreStrategy) {\n case 'fromCacheOnly':\n dispatch(setActivePage({ pageKey }));\n break;\n case 'fromCacheAndRevisitInBackground':\n dispatch(setActivePage({ pageKey }));\n visit(pageKey, { revisit: true });\n break;\n case 'revisitOnly':\n default:\n visit(pageKey, { revisit: true }).then(() => {\n const noNav = prevPageKey === store.getState().superglue.currentPageKey;\n if (noNav) {\n // When \"POP'ed\", revisiting (using revisit: true) a page can result in\n // a redirect, or a render of the same page.\n //\n // When its a redirect, calculateNavAction will correctly set the\n // navigationAction to `replace` this is the noop scenario.\n //\n // When its the same page, navigationAction is set to `none` and\n // no navigation took place. In that case, we have to set the\n // activePage otherwise the user is stuck on the original page.\n dispatch(setActivePage({ pageKey }));\n }\n });\n }\n }\n else {\n visit(pageKey, { revisit: true }).then(() => {\n const noNav = prevPageKey === store.getState().superglue.currentPageKey;\n if (noNav) {\n dispatch(setActivePage({ pageKey }));\n }\n });\n }\n }\n }, ['Update', 'param0', '', 'P\"w!2\"$/#']);\n const navigateTo: NavigateTo = __assignType((path, { action } = {\n action: 'push',\n }) => {\n if (action === 'none') {\n return false;\n }\n const nextPageKey = urlToPageKey(path);\n const hasPage = Object.prototype.hasOwnProperty.call(store.getState().pages, nextPageKey);\n if (hasPage) {\n const location = history.location;\n const state = location.state as HistoryState;\n const historyArgs = [\n path,\n {\n superglue: true,\n posY: 0,\n posX: 0,\n },\n ] as const;\n if (action === 'push') {\n if (hasWindow) {\n history.replace({\n pathname: location.pathname,\n search: location.search,\n hash: location.hash,\n }, {\n ...state,\n posY: window.scrollY,\n posX: window.scrollX,\n });\n }\n history.push(...historyArgs);\n dispatch(setActivePage({ pageKey: nextPageKey }));\n }\n if (action === 'replace') {\n history.replace(...historyArgs);\n if (currentPageKey !== nextPageKey) {\n dispatch(setActivePage({ pageKey: nextPageKey }));\n dispatch(removePage({ pageKey: currentPageKey }));\n }\n }\n return true;\n }\n else {\n console.warn(`\\`navigateTo\\` was called , but could not find\n the pageKey in the store. This may happen when the wrong\n content_location was set in your non-get controller action.\n No navigation will take place`);\n return false;\n }\n }, ['path', 'param1', '', 'P\"2!\"2\"\"/#']);\n const { search } = superglue;\n const { componentIdentifier } = pages[currentPageKey];\n const Component = mapping[componentIdentifier];\n if (Component) {\n return (<NavigationContext.Provider value={{ pageKey: currentPageKey, search, navigateTo, visit, remote }}>\n <Component />\n </NavigationContext.Provider>);\n }\n else {\n notFound(componentIdentifier);\n }\n}, [() => __ΩNavigationProviderProps, 'param0', 'ref', 'NavigationProvider', 'Pn!2\"!2#\"/$']));\nexport { NavigationContext, NavigationProvider };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,OAAOA,UAAS,QAAQ,eAAe;AAKvC,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB,2BAA2B;;;ACR1D,OAAO,SAAS,eAAe,WAAW,iBAAiB,YAAY,2BAA0C;AAOjH,SAAS,aAAa,aAAa,gBAAgB;AAXnD,SAAS,aAAa,IAAI,MAAM;AAC5B,KAAG,SAAS;AACZ,SAAO;AACX;AASA,IAAM,qBAAqB,cAAc,SAAI,CAAC,CAAC,MAAM,gCAA2B,IAAI,CAAC,GAAG,cAAsC,CAAC,CAA2B;AAC1J,IAAM,YAAY,OAAO,WAAW;AACpC,IAAM,kBAAkB,aAAa,CAAC,MAAc,SAAuB;AACvE,eAAa,OAAO,SAAS,MAAM,IAAI;AAC3C,GAAG,CAAC,QAAQ,QAAQ,IAAI,YAAc,CAAC;AACvC,IAAM,WAAW,aAAa,CAAC,eAA0C;AACrE,MAAI,WAAW;AACf,MAAI,CAAC,YAAY;AACb,eACI;AAAA,EACR;AACA,QAAM,QAAQ,IAAI,MAAM,2CAA2C,UAAU,2CAA2C,QAAQ,EAAE;AAClI,QAAM;AACV,GAAG,CAAC,cAAc,IAAI,YAAY,CAAC;AACnC,IAAM,qBAAqB,WAAW,aA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OAAA,cAAC,SAAI,SAAS,IAAI,SAAS,UAAU,IAAI,UAAW,GAAG,QAC7D,gBAAAA,OAAA,cAAC,YAAS,SACR,gBAAAA,OAAA,cAAC,aAAa,UAAb,EAAsB,OAAO,EAAE,eAAe,MAAM,KACnD,gBAAAA,OAAA,cAAC,sBAAmB,KAAK,cAAc,OAAc,QAAgB,SAAkB,SAAS,aAAa,gBAA+B,CAC9I,CACF,CACF;AACJ;AACA,YAAY,SAAS,CAAC,MAAM,0BAAqB,UAAU,eAAe,UAAU;","names":["React","NavigationProvider","__assignType","hasWindow","__assignType","React"]}
@@ -31,7 +31,7 @@ import {
31
31
  ujsHandlers,
32
32
  unproxy,
33
33
  urlToPageKey
34
- } from "./chunk-J2XH5QTK.mjs";
34
+ } from "./chunk-ILWYFGLA.mjs";
35
35
 
36
36
  // lib/index.tsx
37
37
  import React2, { useRef as useRef3, useMemo as useMemo2 } from "react";
@@ -46,7 +46,7 @@ import { useSelector as useSelector3 } from "react-redux";
46
46
  // lib/hooks/useContent.tsx
47
47
  import { useSelector, useStore } from "react-redux";
48
48
  import { useMemo, useRef } from "react";
49
- function useContent(fragmentRef) {
49
+ function useContent(fragmentRef, __type) {
50
50
  const superglueState = useSuperglue();
51
51
  const currentPageKey = superglueState.currentPageKey;
52
52
  const dependencies = useRef(/* @__PURE__ */ new Set());
@@ -77,12 +77,37 @@ function useContent(fragmentRef) {
77
77
  if (fragmentId && !sourceData) {
78
78
  return void 0;
79
79
  }
80
- return createProxy(
80
+ const proxy2 = createProxy(
81
81
  sourceData,
82
82
  { current: store.getState().fragments },
83
83
  dependencies.current,
84
84
  proxyCache
85
85
  );
86
+ if (process.env.NODE_ENV !== "production" && __type) {
87
+ const proxyForValidation = createProxy(
88
+ sourceData,
89
+ { current: store.getState().fragments },
90
+ /* @__PURE__ */ new Set(),
91
+ /* @__PURE__ */ new WeakMap()
92
+ );
93
+ import("@deepkit/type").then(({ resolveReceiveType, validate }) => {
94
+ const resolvedType = resolveReceiveType(__type);
95
+ const errors = validate(proxyForValidation, resolvedType);
96
+ if (errors.length > 0) {
97
+ const formattedErrors = errors.map((e) => ({
98
+ path: e.path,
99
+ message: e.message,
100
+ code: String(e.code)
101
+ }));
102
+ console.error(
103
+ `[Superglue] Content validation failed for ${fragmentId || "page"}:`,
104
+ formattedErrors
105
+ );
106
+ }
107
+ }).catch(() => {
108
+ });
109
+ }
110
+ return proxy2;
86
111
  }, [sourceData, trackedFragments]);
87
112
  return proxy;
88
113
  }
@@ -642,6 +667,12 @@ var setup = ({
642
667
  streamActions
643
668
  };
644
669
  };
670
+ if (process.env.NODE_ENV !== "production") {
671
+ console.info(
672
+ "%cSuperglue Development Mode: Remember to build for production before deploying.",
673
+ "font-weight:bold"
674
+ );
675
+ }
645
676
  function Application({
646
677
  initialPage,
647
678
  baseUrl,