@thoughtbot/superglue 2.0.0-alpha.1 → 2.0.0-alpha.3
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-YS477OKK.mjs → chunk-EU2SLL5L.mjs} +246 -2
- package/dist/chunk-EU2SLL5L.mjs.map +1 -0
- package/dist/cjs/action_creators.cjs +236 -1
- package/dist/cjs/action_creators.cjs.map +1 -1
- package/dist/cjs/superglue.cjs +130 -108
- package/dist/cjs/superglue.cjs.map +1 -1
- package/dist/{index-MyfFLe4E.d.mts → index-O_srQ3Nm.d.mts} +2 -1
- package/dist/superglue.d.mts +10 -3
- package/dist/superglue.mjs +12 -228
- package/dist/superglue.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-YS477OKK.mjs.map +0 -1
- package/thoughtbot-superglue-2.0.0-alpha.1.tgz +0 -0
package/dist/cjs/superglue.cjs
CHANGED
|
@@ -5526,6 +5526,7 @@ __export(lib_exports, {
|
|
|
5526
5526
|
getIn: () => getIn,
|
|
5527
5527
|
pageReducer: () => pageReducer,
|
|
5528
5528
|
prepareStore: () => prepareStore,
|
|
5529
|
+
receiveResponse: () => receiveResponse,
|
|
5529
5530
|
removePage: () => removePage,
|
|
5530
5531
|
rootReducer: () => rootReducer,
|
|
5531
5532
|
saveAndProcessPage: () => saveAndProcessPage,
|
|
@@ -6024,6 +6025,18 @@ var saveFragment = (0, import_toolkit.createAction)(
|
|
|
6024
6025
|
};
|
|
6025
6026
|
}
|
|
6026
6027
|
);
|
|
6028
|
+
var receiveResponse = (0, import_toolkit.createAction)(
|
|
6029
|
+
"@@superglue/RECEIVE_RESPONSE",
|
|
6030
|
+
({ pageKey, response }) => {
|
|
6031
|
+
pageKey = urlToPageKey(pageKey);
|
|
6032
|
+
return {
|
|
6033
|
+
payload: {
|
|
6034
|
+
pageKey,
|
|
6035
|
+
response
|
|
6036
|
+
}
|
|
6037
|
+
};
|
|
6038
|
+
}
|
|
6039
|
+
);
|
|
6027
6040
|
var appendToFragment = (0, import_toolkit.createAction)(
|
|
6028
6041
|
"@@superglue/APPEND_TO_FRAGMENT",
|
|
6029
6042
|
({ data, fragmentId }) => {
|
|
@@ -6120,6 +6133,7 @@ the same page. Or if you're sure you want to proceed, use force: true.
|
|
|
6120
6133
|
throw new MismatchedComponentError(message);
|
|
6121
6134
|
}
|
|
6122
6135
|
}
|
|
6136
|
+
dispatch(receiveResponse({ pageKey, response: json }));
|
|
6123
6137
|
const page = beforeSave(pages[pageKey], json);
|
|
6124
6138
|
return dispatch(saveAndProcessPage(pageKey, page)).then(() => meta);
|
|
6125
6139
|
}).catch((e) => handleFetchErr(e, fetchArgs, dispatch));
|
|
@@ -6286,95 +6300,6 @@ var handleStreamResponse = (response) => {
|
|
|
6286
6300
|
};
|
|
6287
6301
|
};
|
|
6288
6302
|
|
|
6289
|
-
// lib/action_creators/index.ts
|
|
6290
|
-
function fetchDeferments(pageKey, defers = []) {
|
|
6291
|
-
pageKey = urlToPageKey(pageKey);
|
|
6292
|
-
return (dispatch) => {
|
|
6293
|
-
const fetches = defers.filter(({ type }) => type === "auto").map(function({
|
|
6294
|
-
url,
|
|
6295
|
-
successAction = GRAFTING_SUCCESS,
|
|
6296
|
-
failAction = GRAFTING_ERROR
|
|
6297
|
-
}) {
|
|
6298
|
-
const keyPath = propsAtParam(url);
|
|
6299
|
-
return dispatch(remote(url, { pageKey })).then(() => {
|
|
6300
|
-
dispatch({
|
|
6301
|
-
type: successAction,
|
|
6302
|
-
payload: {
|
|
6303
|
-
pageKey,
|
|
6304
|
-
keyPath
|
|
6305
|
-
}
|
|
6306
|
-
});
|
|
6307
|
-
}).catch((err) => {
|
|
6308
|
-
dispatch({
|
|
6309
|
-
type: failAction,
|
|
6310
|
-
payload: {
|
|
6311
|
-
url,
|
|
6312
|
-
err,
|
|
6313
|
-
pageKey,
|
|
6314
|
-
keyPath
|
|
6315
|
-
}
|
|
6316
|
-
});
|
|
6317
|
-
});
|
|
6318
|
-
});
|
|
6319
|
-
return Promise.all(fetches);
|
|
6320
|
-
};
|
|
6321
|
-
}
|
|
6322
|
-
function saveAndProcessPage(pageKey, page) {
|
|
6323
|
-
return (dispatch) => {
|
|
6324
|
-
pageKey = urlToPageKey(pageKey);
|
|
6325
|
-
let nextPage = page;
|
|
6326
|
-
page.fragments.reverse().forEach((fragment) => {
|
|
6327
|
-
const { id, path } = fragment;
|
|
6328
|
-
const node = getIn(nextPage, path);
|
|
6329
|
-
nextPage = setIn(page, path, { __id: id });
|
|
6330
|
-
dispatch(
|
|
6331
|
-
saveFragment({
|
|
6332
|
-
fragmentId: id,
|
|
6333
|
-
data: node
|
|
6334
|
-
})
|
|
6335
|
-
);
|
|
6336
|
-
});
|
|
6337
|
-
if (nextPage.action === "graft") {
|
|
6338
|
-
if (typeof nextPage.fragmentContext === "string") {
|
|
6339
|
-
dispatch(
|
|
6340
|
-
handleFragmentGraft({
|
|
6341
|
-
fragmentId: nextPage.fragmentContext,
|
|
6342
|
-
response: nextPage
|
|
6343
|
-
})
|
|
6344
|
-
);
|
|
6345
|
-
} else {
|
|
6346
|
-
dispatch(handleGraft({ pageKey, page: nextPage }));
|
|
6347
|
-
}
|
|
6348
|
-
} else if (nextPage.action === "handleStreamResponse") {
|
|
6349
|
-
dispatch(handleStreamResponse(nextPage));
|
|
6350
|
-
return Promise.resolve();
|
|
6351
|
-
} else {
|
|
6352
|
-
dispatch(saveResponse({ pageKey, page: nextPage }));
|
|
6353
|
-
}
|
|
6354
|
-
const hasFetch = typeof fetch != "undefined";
|
|
6355
|
-
if (hasFetch) {
|
|
6356
|
-
return dispatch(fetchDeferments(pageKey, nextPage.defers)).then(
|
|
6357
|
-
() => Promise.resolve()
|
|
6358
|
-
);
|
|
6359
|
-
} else {
|
|
6360
|
-
return Promise.resolve();
|
|
6361
|
-
}
|
|
6362
|
-
};
|
|
6363
|
-
}
|
|
6364
|
-
|
|
6365
|
-
// lib/index.tsx
|
|
6366
|
-
var import_react_redux5 = require("react-redux");
|
|
6367
|
-
|
|
6368
|
-
// lib/hooks/useStreamSource.tsx
|
|
6369
|
-
var import_react2 = require("react");
|
|
6370
|
-
|
|
6371
|
-
// lib/hooks/index.ts
|
|
6372
|
-
var import_react_redux3 = require("react-redux");
|
|
6373
|
-
|
|
6374
|
-
// lib/hooks/useContent.tsx
|
|
6375
|
-
var import_react_redux = require("react-redux");
|
|
6376
|
-
var import_react = require("react");
|
|
6377
|
-
|
|
6378
6303
|
// lib/utils/proxy.ts
|
|
6379
6304
|
var ORIGINAL_TARGET = Symbol("@@originalTarget");
|
|
6380
6305
|
var ARRAY_GETTER_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -6579,7 +6504,117 @@ function unproxy(proxy) {
|
|
|
6579
6504
|
return proxy;
|
|
6580
6505
|
}
|
|
6581
6506
|
|
|
6507
|
+
// lib/action_creators/index.ts
|
|
6508
|
+
function fetchDeferments(pageKey, defers = []) {
|
|
6509
|
+
pageKey = urlToPageKey(pageKey);
|
|
6510
|
+
return (dispatch) => {
|
|
6511
|
+
const fetches = defers.filter(({ type }) => type === "auto").map(function({
|
|
6512
|
+
url,
|
|
6513
|
+
successAction = GRAFTING_SUCCESS,
|
|
6514
|
+
failAction = GRAFTING_ERROR
|
|
6515
|
+
}) {
|
|
6516
|
+
const keyPath = propsAtParam(url);
|
|
6517
|
+
return dispatch(remote(url, { pageKey })).then(() => {
|
|
6518
|
+
dispatch({
|
|
6519
|
+
type: successAction,
|
|
6520
|
+
payload: {
|
|
6521
|
+
pageKey,
|
|
6522
|
+
keyPath
|
|
6523
|
+
}
|
|
6524
|
+
});
|
|
6525
|
+
}).catch((err) => {
|
|
6526
|
+
dispatch({
|
|
6527
|
+
type: failAction,
|
|
6528
|
+
payload: {
|
|
6529
|
+
url,
|
|
6530
|
+
err,
|
|
6531
|
+
pageKey,
|
|
6532
|
+
keyPath
|
|
6533
|
+
}
|
|
6534
|
+
});
|
|
6535
|
+
});
|
|
6536
|
+
});
|
|
6537
|
+
return Promise.all(fetches);
|
|
6538
|
+
};
|
|
6539
|
+
}
|
|
6540
|
+
function addPlaceholdersToDeferredNodes(existingPage, page) {
|
|
6541
|
+
const { defers = [] } = existingPage;
|
|
6542
|
+
const prevDefers = defers.map(({ path }) => {
|
|
6543
|
+
const node = getIn(existingPage, path);
|
|
6544
|
+
const copy = JSON.stringify(node);
|
|
6545
|
+
return [path, JSON.parse(copy)];
|
|
6546
|
+
});
|
|
6547
|
+
return prevDefers.reduce((memo, [path, node]) => {
|
|
6548
|
+
return setIn(page, path, node);
|
|
6549
|
+
}, page);
|
|
6550
|
+
}
|
|
6551
|
+
function saveAndProcessPage(pageKey, page) {
|
|
6552
|
+
return (dispatch, getState) => {
|
|
6553
|
+
pageKey = urlToPageKey(pageKey);
|
|
6554
|
+
let nextPage = page;
|
|
6555
|
+
const state = getState();
|
|
6556
|
+
if (page.action === "savePage" && state.pages[pageKey]) {
|
|
6557
|
+
const existingPage = createProxy(
|
|
6558
|
+
state.pages[pageKey],
|
|
6559
|
+
{ current: state.fragments },
|
|
6560
|
+
/* @__PURE__ */ new Set(),
|
|
6561
|
+
/* @__PURE__ */ new WeakMap()
|
|
6562
|
+
);
|
|
6563
|
+
nextPage = JSON.parse(
|
|
6564
|
+
JSON.stringify(addPlaceholdersToDeferredNodes(existingPage, nextPage))
|
|
6565
|
+
);
|
|
6566
|
+
}
|
|
6567
|
+
page.fragments.reverse().forEach((fragment) => {
|
|
6568
|
+
const { id, path } = fragment;
|
|
6569
|
+
const node = getIn(nextPage, path);
|
|
6570
|
+
nextPage = setIn(page, path, { __id: id });
|
|
6571
|
+
dispatch(
|
|
6572
|
+
saveFragment({
|
|
6573
|
+
fragmentId: id,
|
|
6574
|
+
data: node
|
|
6575
|
+
})
|
|
6576
|
+
);
|
|
6577
|
+
});
|
|
6578
|
+
if (nextPage.action === "graft") {
|
|
6579
|
+
if (typeof nextPage.fragmentContext === "string") {
|
|
6580
|
+
dispatch(
|
|
6581
|
+
handleFragmentGraft({
|
|
6582
|
+
fragmentId: nextPage.fragmentContext,
|
|
6583
|
+
response: nextPage
|
|
6584
|
+
})
|
|
6585
|
+
);
|
|
6586
|
+
} else {
|
|
6587
|
+
dispatch(handleGraft({ pageKey, page: nextPage }));
|
|
6588
|
+
}
|
|
6589
|
+
} else if (nextPage.action === "handleStreamResponse") {
|
|
6590
|
+
dispatch(handleStreamResponse(nextPage));
|
|
6591
|
+
return Promise.resolve();
|
|
6592
|
+
} else {
|
|
6593
|
+
dispatch(saveResponse({ pageKey, page: nextPage }));
|
|
6594
|
+
}
|
|
6595
|
+
const hasFetch = typeof fetch != "undefined";
|
|
6596
|
+
if (hasFetch) {
|
|
6597
|
+
return dispatch(fetchDeferments(pageKey, nextPage.defers)).then(
|
|
6598
|
+
() => Promise.resolve()
|
|
6599
|
+
);
|
|
6600
|
+
} else {
|
|
6601
|
+
return Promise.resolve();
|
|
6602
|
+
}
|
|
6603
|
+
};
|
|
6604
|
+
}
|
|
6605
|
+
|
|
6606
|
+
// lib/index.tsx
|
|
6607
|
+
var import_react_redux5 = require("react-redux");
|
|
6608
|
+
|
|
6609
|
+
// lib/hooks/useStreamSource.tsx
|
|
6610
|
+
var import_react2 = require("react");
|
|
6611
|
+
|
|
6612
|
+
// lib/hooks/index.ts
|
|
6613
|
+
var import_react_redux3 = require("react-redux");
|
|
6614
|
+
|
|
6582
6615
|
// lib/hooks/useContent.tsx
|
|
6616
|
+
var import_react_redux = require("react-redux");
|
|
6617
|
+
var import_react = require("react");
|
|
6583
6618
|
function useContent(fragmentRef, options) {
|
|
6584
6619
|
const superglueState = useSuperglue();
|
|
6585
6620
|
const currentPageKey = superglueState.currentPageKey;
|
|
@@ -6797,7 +6832,6 @@ var NavigationProvider = (0, import_react3.forwardRef)(function NavigationProvid
|
|
|
6797
6832
|
hash: location.hash
|
|
6798
6833
|
},
|
|
6799
6834
|
{
|
|
6800
|
-
pageKey: nextPageKey,
|
|
6801
6835
|
superglue: true,
|
|
6802
6836
|
posY: window.pageYOffset,
|
|
6803
6837
|
posX: window.pageXOffset
|
|
@@ -6806,7 +6840,7 @@ var NavigationProvider = (0, import_react3.forwardRef)(function NavigationProvid
|
|
|
6806
6840
|
}
|
|
6807
6841
|
}
|
|
6808
6842
|
if (state && "superglue" in state) {
|
|
6809
|
-
const
|
|
6843
|
+
const pageKey = urlToPageKey(location.pathname + location.search);
|
|
6810
6844
|
const prevPageKey = store.getState().superglue.currentPageKey;
|
|
6811
6845
|
const containsKey = !!pages[pageKey];
|
|
6812
6846
|
if (containsKey) {
|
|
@@ -6855,7 +6889,6 @@ var NavigationProvider = (0, import_react3.forwardRef)(function NavigationProvid
|
|
|
6855
6889
|
const historyArgs = [
|
|
6856
6890
|
path,
|
|
6857
6891
|
{
|
|
6858
|
-
pageKey: nextPageKey,
|
|
6859
6892
|
superglue: true,
|
|
6860
6893
|
posY: 0,
|
|
6861
6894
|
posX: 0
|
|
@@ -6914,17 +6947,6 @@ var NavigationProvider = (0, import_react3.forwardRef)(function NavigationProvid
|
|
|
6914
6947
|
});
|
|
6915
6948
|
|
|
6916
6949
|
// lib/reducers/index.ts
|
|
6917
|
-
function addPlaceholdersToDeferredNodes(existingPage, page) {
|
|
6918
|
-
const { defers = [] } = existingPage;
|
|
6919
|
-
const prevDefers = defers.map(({ path }) => {
|
|
6920
|
-
const node = getIn(existingPage, path);
|
|
6921
|
-
const copy = JSON.stringify(node);
|
|
6922
|
-
return [path, JSON.parse(copy)];
|
|
6923
|
-
});
|
|
6924
|
-
return prevDefers.reduce((memo, [path, node]) => {
|
|
6925
|
-
return setIn(page, path, node);
|
|
6926
|
-
}, page);
|
|
6927
|
-
}
|
|
6928
6950
|
function constrainPagesSize(state) {
|
|
6929
6951
|
const { maxPages } = config;
|
|
6930
6952
|
const allPageKeys = Object.keys(state);
|
|
@@ -6937,14 +6959,10 @@ function constrainPagesSize(state) {
|
|
|
6937
6959
|
}
|
|
6938
6960
|
function handleSaveResponse(state, pageKey, page) {
|
|
6939
6961
|
state = { ...state };
|
|
6940
|
-
|
|
6962
|
+
const nextPage = {
|
|
6941
6963
|
...page,
|
|
6942
6964
|
savedAt: Date.now()
|
|
6943
6965
|
};
|
|
6944
|
-
const existingPage = state[pageKey];
|
|
6945
|
-
if (existingPage) {
|
|
6946
|
-
nextPage = addPlaceholdersToDeferredNodes(existingPage, nextPage);
|
|
6947
|
-
}
|
|
6948
6966
|
constrainPagesSize(state);
|
|
6949
6967
|
state[pageKey] = nextPage;
|
|
6950
6968
|
return state;
|
|
@@ -7139,6 +7157,9 @@ var prepareStore = (store, initialPage, path) => {
|
|
|
7139
7157
|
pageKey: initialPageKey
|
|
7140
7158
|
})
|
|
7141
7159
|
);
|
|
7160
|
+
store.dispatch(
|
|
7161
|
+
receiveResponse({ pageKey: initialPageKey, response: initialPage })
|
|
7162
|
+
);
|
|
7142
7163
|
store.dispatch(saveAndProcessPage(initialPageKey, initialPage));
|
|
7143
7164
|
store.dispatch(setCSRFToken({ csrfToken }));
|
|
7144
7165
|
};
|
|
@@ -7221,6 +7242,7 @@ function Application({
|
|
|
7221
7242
|
getIn,
|
|
7222
7243
|
pageReducer,
|
|
7223
7244
|
prepareStore,
|
|
7245
|
+
receiveResponse,
|
|
7224
7246
|
removePage,
|
|
7225
7247
|
rootReducer,
|
|
7226
7248
|
saveAndProcessPage,
|