@very-simple/ajax 1.0.0-beta.2 → 1.0.0-beta.4

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/README.md CHANGED
@@ -74,6 +74,9 @@ start({
74
74
  progressHideDelay: 500,
75
75
  // Prefix used for the `data-ajax-*` attributes.
76
76
  prefix: 'data-ajax-',
77
+ // Default selectors to swap instead of the whole `<body>`, used for visits
78
+ // that don't specify their own `regions` (e.g. via `data-ajax-regions`).
79
+ regions: [],
77
80
  // Custom scroll handling, e.g. restoring position on back/forward visits.
78
81
  scrollBehavior: ({ isBackForward, savedPosition }) =>
79
82
  isBackForward ? savedPosition : { top: 0 },
package/dist/index.d.ts CHANGED
@@ -36,6 +36,8 @@ interface Config {
36
36
  progressHideDelay?: number;
37
37
  /** Prefix used for the `data-ajax-*` attributes. */
38
38
  prefix?: string;
39
+ /** Default regions used for visits that don't specify their own. */
40
+ regions?: string[];
39
41
  /** Called after an element is added to the DOM by a merge. */
40
42
  mount?: (el: Element) => void;
41
43
  /** Called before an element is removed from the DOM by a merge. */
package/dist/index.js CHANGED
@@ -6,7 +6,8 @@ var config = {
6
6
  viewTransitions: false,
7
7
  loadingDelay: 500,
8
8
  progressHideDelay: 500,
9
- prefix: "data-ajax-"
9
+ prefix: "data-ajax-",
10
+ regions: []
10
11
  };
11
12
 
12
13
  // src/load.ts
@@ -222,7 +223,7 @@ var visit = async (url, {
222
223
  autoFocus = true,
223
224
  request,
224
225
  state,
225
- regions = [],
226
+ regions = config.regions,
226
227
  morphHeads = config.morphHeads,
227
228
  merge: mergeStrategy = config.merge,
228
229
  executeScripts: shouldExecuteScripts = config.executeScripts,
@@ -267,7 +268,6 @@ var visit = async (url, {
267
268
  const to = { url, state, document: newDocument };
268
269
  await emit("before-swap", { from, to, isBackForward, signal });
269
270
  if (signal.aborted) return;
270
- if (morphHeads) Idiomorph2.morph(document.head, newDocument.head);
271
271
  const getMergeStrategy = (oldEl, newEl) => newEl.getAttribute(`${config.prefix}merge`) || oldEl.getAttribute(`${config.prefix}merge`) || mergeStrategy;
272
272
  let autoFocusEl;
273
273
  const hasMatchingRegions = regions?.some(
@@ -313,14 +313,17 @@ var visit = async (url, {
313
313
  if (position) window.scrollTo(position);
314
314
  };
315
315
  if (config.render) {
316
+ if (morphHeads) Idiomorph2.morph(document.head, newDocument.head);
316
317
  await config.render(newDocument);
317
318
  } else if (viewTransitions && document.startViewTransition) {
318
319
  await document.startViewTransition(async () => {
320
+ if (morphHeads) Idiomorph2.morph(document.head, newDocument.head);
319
321
  await mergeRegions();
320
322
  await emit("after-swap", { from, to, isBackForward, signal });
321
323
  applyScrollBehavior();
322
324
  }).ready;
323
325
  } else {
326
+ if (morphHeads) Idiomorph2.morph(document.head, newDocument.head);
324
327
  await mergeRegions();
325
328
  await emit("after-swap", { from, to, isBackForward, signal });
326
329
  applyScrollBehavior();
@@ -377,7 +380,7 @@ var interceptHistory = () => {
377
380
  visit(window.location.href, {
378
381
  history: "none",
379
382
  isBackForward: true,
380
- regions: currentState?.regions ?? [],
383
+ regions: currentState?.regions ?? config.regions,
381
384
  state: event.state
382
385
  });
383
386
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@very-simple/ajax",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "A very simple turbolinks inspired ajax library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",