@nodehive/nextjs 0.5.1 → 0.5.2

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.
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Whether a wheel event starting at `target` reaches something that can
3
+ * consume it, walking up to and INCLUDING `allow`.
4
+ *
5
+ * Including `allow` is the point: a dialog carries the overflow on its own
6
+ * root, and everything inside it (grids, tiles, images) cannot scroll. A walk
7
+ * that stops one element short never asks the one element that could, and the
8
+ * event gets cancelled although the dialog had room left.
9
+ *
10
+ * Kept free of the DOM so it can be tested without one.
11
+ */
12
+ export declare function wheelIsConsumable<T>(target: T | null, allow: T | null, parentOf: (el: T) => T | null, canConsume: (el: T) => boolean): boolean;
1
13
  /**
2
14
  * Locks the document's background scroll while `active` is true, without
3
15
  * touching <html>/<body> styles — so libraries that mirror those attributes
@@ -5,10 +17,21 @@
5
17
  * iframes' own scroll.
6
18
  *
7
19
  * Works by intercepting wheel and touchmove on the document and only
8
- * letting events through when a scrollable ancestor inside an element
9
- * matching `allowSelector` can consume them. Events anywhere else get
20
+ * letting events through when a scrollable element between the target and the
21
+ * allowed container can consume them. Events anywhere else get
10
22
  * preventDefault'd, so scroll can't chain to the body behind the overlay.
11
23
  *
24
+ * Dialogs count as allowed on top of `allowSelector`: a Radix dialog is
25
+ * portaled to `document.body` and therefore sits outside the overlay, so
26
+ * matching on the selector alone would classify every wheel event inside the
27
+ * media picker as "outside" and cancel it. The picker is then unusable on any
28
+ * window short enough for its list to overflow.
29
+ *
30
+ * The walk includes the allowed container itself. A dialog carries the
31
+ * overflow on its own root, and everything inside it (grids, tiles, images)
32
+ * cannot scroll; stopping one element short meant never asking the one element
33
+ * that could.
34
+ *
12
35
  * Skips in iframes so the preview document isn't affected.
13
36
  */
14
37
  export declare function useScrollLockOutside(active: boolean, allowSelector: string): void;
@@ -2,6 +2,29 @@
2
2
 
3
3
  import { c as _c } from "react/compiler-runtime";
4
4
  import { useEffect } from 'react';
5
+ const DIALOG_SELECTOR = '[role="dialog"]';
6
+
7
+ /**
8
+ * Whether a wheel event starting at `target` reaches something that can
9
+ * consume it, walking up to and INCLUDING `allow`.
10
+ *
11
+ * Including `allow` is the point: a dialog carries the overflow on its own
12
+ * root, and everything inside it (grids, tiles, images) cannot scroll. A walk
13
+ * that stops one element short never asks the one element that could, and the
14
+ * event gets cancelled although the dialog had room left.
15
+ *
16
+ * Kept free of the DOM so it can be tested without one.
17
+ */
18
+ export function wheelIsConsumable(target, allow, parentOf, canConsume) {
19
+ if (!allow) return false;
20
+ let el = target;
21
+ while (el) {
22
+ if (canConsume(el)) return true;
23
+ if (el === allow) break;
24
+ el = parentOf(el);
25
+ }
26
+ return false;
27
+ }
5
28
 
6
29
  /**
7
30
  * Locks the document's background scroll while `active` is true, without
@@ -10,10 +33,21 @@ import { useEffect } from 'react';
10
33
  * iframes' own scroll.
11
34
  *
12
35
  * Works by intercepting wheel and touchmove on the document and only
13
- * letting events through when a scrollable ancestor inside an element
14
- * matching `allowSelector` can consume them. Events anywhere else get
36
+ * letting events through when a scrollable element between the target and the
37
+ * allowed container can consume them. Events anywhere else get
15
38
  * preventDefault'd, so scroll can't chain to the body behind the overlay.
16
39
  *
40
+ * Dialogs count as allowed on top of `allowSelector`: a Radix dialog is
41
+ * portaled to `document.body` and therefore sits outside the overlay, so
42
+ * matching on the selector alone would classify every wheel event inside the
43
+ * media picker as "outside" and cancel it. The picker is then unusable on any
44
+ * window short enough for its list to overflow.
45
+ *
46
+ * The walk includes the allowed container itself. A dialog carries the
47
+ * overflow on its own root, and everything inside it (grids, tiles, images)
48
+ * cannot scroll; stopping one element short meant never asking the one element
49
+ * that could.
50
+ *
17
51
  * Skips in iframes so the preview document isn't affected.
18
52
  */
19
53
  export function useScrollLockOutside(active, allowSelector) {
@@ -29,25 +63,16 @@ export function useScrollLockOutside(active, allowSelector) {
29
63
  return;
30
64
  }
31
65
  const canConsumeScroll = _temp;
66
+ const isAllowed = target => target?.closest?.(`${allowSelector}, ${DIALOG_SELECTOR}`) ?? null;
32
67
  const onWheel = e => {
33
- const target = e.target;
34
- const allow = target?.closest?.(allowSelector);
35
- if (!allow) {
68
+ const target_0 = e.target;
69
+ const consumable = wheelIsConsumable(target_0, isAllowed(target_0), _temp2, el_1 => canConsumeScroll(el_1, e.deltaY));
70
+ if (!consumable) {
36
71
  e.preventDefault();
37
- return;
38
72
  }
39
- let el_0 = target;
40
- while (el_0 && el_0 !== allow) {
41
- if (canConsumeScroll(el_0, e.deltaY)) {
42
- return;
43
- }
44
- el_0 = el_0.parentElement;
45
- }
46
- e.preventDefault();
47
73
  };
48
74
  const onTouchMove = e_0 => {
49
- const target_0 = e_0.target;
50
- if (!target_0?.closest?.(allowSelector)) {
75
+ if (!isAllowed(e_0.target)) {
51
76
  e_0.preventDefault();
52
77
  }
53
78
  };
@@ -73,6 +98,9 @@ export function useScrollLockOutside(active, allowSelector) {
73
98
  }
74
99
  useEffect(t0, t1);
75
100
  }
101
+ function _temp2(el_0) {
102
+ return el_0.parentElement;
103
+ }
76
104
  function _temp(el, deltaY) {
77
105
  const style = getComputedStyle(el);
78
106
  if (!/auto|scroll|overlay/.test(style.overflowY)) {
@@ -1 +1 @@
1
- {"version":3,"file":"use-scroll-lock-outside.js","names":["c","_c","useEffect","useScrollLockOutside","active","allowSelector","$","t0","t1","window","self","top","canConsumeScroll","_temp","onWheel","e","target","allow","closest","preventDefault","el_0","el","deltaY","parentElement","onTouchMove","e_0","target_0","document","addEventListener","passive","removeEventListener","style","getComputedStyle","test","overflowY","he","scrollHeight","clientHeight","scrollTop"],"sources":["../../../../src/puck-editor/internal/editor/use-scroll-lock-outside.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\n\n/**\n * Locks the document's background scroll while `active` is true, without\n * touching <html>/<body> styles — so libraries that mirror those attributes\n * into child iframes (e.g. Puck's CopyHostStyles) don't freeze those\n * iframes' own scroll.\n *\n * Works by intercepting wheel and touchmove on the document and only\n * letting events through when a scrollable ancestor inside an element\n * matching `allowSelector` can consume them. Events anywhere else get\n * preventDefault'd, so scroll can't chain to the body behind the overlay.\n *\n * Skips in iframes so the preview document isn't affected.\n */\nexport function useScrollLockOutside(\n active: boolean,\n allowSelector: string\n): void {\n useEffect(() => {\n if (!active) return;\n if (typeof window !== 'undefined' && window.self !== window.top) return;\n\n const canConsumeScroll = (el: Element, deltaY: number): boolean => {\n const style = getComputedStyle(el);\n if (!/auto|scroll|overlay/.test(style.overflowY)) return false;\n const he = el as HTMLElement;\n if (he.scrollHeight <= he.clientHeight) return false;\n if (deltaY < 0 && he.scrollTop <= 0) return false;\n if (deltaY > 0 && he.scrollTop + he.clientHeight >= he.scrollHeight)\n return false;\n return true;\n };\n\n const onWheel = (e: WheelEvent) => {\n const target = e.target as Element | null;\n const allow = target?.closest?.(allowSelector);\n if (!allow) {\n e.preventDefault();\n return;\n }\n let el: Element | null = target;\n while (el && el !== allow) {\n if (canConsumeScroll(el, e.deltaY)) return;\n el = el.parentElement;\n }\n e.preventDefault();\n };\n\n const onTouchMove = (e: TouchEvent) => {\n const target = e.target as Element | null;\n if (!target?.closest?.(allowSelector)) {\n e.preventDefault();\n }\n };\n\n document.addEventListener('wheel', onWheel, { passive: false });\n document.addEventListener('touchmove', onTouchMove, { passive: false });\n return () => {\n document.removeEventListener('wheel', onWheel);\n document.removeEventListener('touchmove', onTouchMove);\n };\n }, [active, allowSelector]);\n}\n"],"mappings":"AAAA,YAAY;;AAAC,SAAAA,CAAA,IAAAC,EAAA;AAEb,SAASC,SAAS,QAAQ,OAAO;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAAC,qBAAAC,MAAA,EAAAC,aAAA;EAAA,MAAAC,CAAA,GAAAL,EAAA;EAAA,IAAAM,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAF,CAAA,QAAAF,MAAA,IAAAE,CAAA,QAAAD,aAAA;IAIKE,EAAA,GAAAA,C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,EAAA,IAACJ,MAAM,EAAEC,aAAa,CAAC;IAAAC,CAAA,MAAAF,MAAA;IAAAE,CAAA,MAAAD,aAAA;IAAAC,CAAA,MAAAC,EAAA;IAAAD,CAAA,MAAAE,EAAA;EAAA;IAAAD,EAAA,GAAAD,CAAA;IAAAE,EAAA,GAAAF,CAAA;EAAA;EA3C1BJ,SAAS,CAACK,EA2CT,EAAEC,EAAuB,CAAC;AAAA;AA/CtB,SAAAK,MAAAQ,EAAA,EAAAC,MAAA;EASD,MAAAS,KAAA,GAAcC,gBAAgB,CAACX,EAAE,CAAC;EAClC,IAAI,CAAC,qBAAqB,CAAAY,IAAK,CAACF,KAAK,CAAAG,SAAU,CAAC;IAAA,OAAS,KAAK;EAAA;EAC9D,MAAAC,EAAA,GAAWd,EAAE;EACb,IAAIc,EAAE,CAAAC,YAAa,IAAID,EAAE,CAAAE,YAAa;IAAA,OAAS,KAAK;EAAA;EACpD,IAAIf,MAAM,GAAG,CAAsB,IAAjBa,EAAE,CAAAG,SAAU,IAAI,CAAC;IAAA,OAAS,KAAK;EAAA;EACjD,IAAIhB,MAAM,GAAG,CAAsD,IAAjDa,EAAE,CAAAG,SAAU,GAAGH,EAAE,CAAAE,YAAa,IAAIF,EAAE,CAAAC,YAAa;IAAA,OAC1D,KAAK;EAAA;EAAC,OACR,IAAI;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"use-scroll-lock-outside.js","names":["c","_c","useEffect","DIALOG_SELECTOR","wheelIsConsumable","target","allow","parentOf","canConsume","el","useScrollLockOutside","active","allowSelector","$","t0","t1","window","self","top","canConsumeScroll","_temp","isAllowed","closest","onWheel","e","target_0","consumable","_temp2","el_1","deltaY","preventDefault","onTouchMove","e_0","document","addEventListener","passive","removeEventListener","el_0","parentElement","style","getComputedStyle","test","overflowY","he","scrollHeight","clientHeight","scrollTop"],"sources":["../../../../src/puck-editor/internal/editor/use-scroll-lock-outside.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\n\nconst DIALOG_SELECTOR = '[role=\"dialog\"]';\n\n/**\n * Whether a wheel event starting at `target` reaches something that can\n * consume it, walking up to and INCLUDING `allow`.\n *\n * Including `allow` is the point: a dialog carries the overflow on its own\n * root, and everything inside it (grids, tiles, images) cannot scroll. A walk\n * that stops one element short never asks the one element that could, and the\n * event gets cancelled although the dialog had room left.\n *\n * Kept free of the DOM so it can be tested without one.\n */\nexport function wheelIsConsumable<T>(\n target: T | null,\n allow: T | null,\n parentOf: (el: T) => T | null,\n canConsume: (el: T) => boolean\n): boolean {\n if (!allow) return false;\n let el = target;\n while (el) {\n if (canConsume(el)) return true;\n if (el === allow) break;\n el = parentOf(el);\n }\n return false;\n}\n\n/**\n * Locks the document's background scroll while `active` is true, without\n * touching <html>/<body> styles — so libraries that mirror those attributes\n * into child iframes (e.g. Puck's CopyHostStyles) don't freeze those\n * iframes' own scroll.\n *\n * Works by intercepting wheel and touchmove on the document and only\n * letting events through when a scrollable element between the target and the\n * allowed container can consume them. Events anywhere else get\n * preventDefault'd, so scroll can't chain to the body behind the overlay.\n *\n * Dialogs count as allowed on top of `allowSelector`: a Radix dialog is\n * portaled to `document.body` and therefore sits outside the overlay, so\n * matching on the selector alone would classify every wheel event inside the\n * media picker as \"outside\" and cancel it. The picker is then unusable on any\n * window short enough for its list to overflow.\n *\n * The walk includes the allowed container itself. A dialog carries the\n * overflow on its own root, and everything inside it (grids, tiles, images)\n * cannot scroll; stopping one element short meant never asking the one element\n * that could.\n *\n * Skips in iframes so the preview document isn't affected.\n */\nexport function useScrollLockOutside(\n active: boolean,\n allowSelector: string\n): void {\n useEffect(() => {\n if (!active) return;\n if (typeof window !== 'undefined' && window.self !== window.top) return;\n\n const canConsumeScroll = (el: Element, deltaY: number): boolean => {\n const style = getComputedStyle(el);\n if (!/auto|scroll|overlay/.test(style.overflowY)) return false;\n const he = el as HTMLElement;\n if (he.scrollHeight <= he.clientHeight) return false;\n if (deltaY < 0 && he.scrollTop <= 0) return false;\n if (deltaY > 0 && he.scrollTop + he.clientHeight >= he.scrollHeight)\n return false;\n return true;\n };\n\n const isAllowed = (target: Element | null): Element | null =>\n target?.closest?.(`${allowSelector}, ${DIALOG_SELECTOR}`) ?? null;\n\n const onWheel = (e: WheelEvent) => {\n const target = e.target as Element | null;\n const consumable = wheelIsConsumable(\n target,\n isAllowed(target),\n (el) => el.parentElement,\n (el) => canConsumeScroll(el, e.deltaY)\n );\n if (!consumable) {\n e.preventDefault();\n }\n };\n\n const onTouchMove = (e: TouchEvent) => {\n if (!isAllowed(e.target as Element | null)) {\n e.preventDefault();\n }\n };\n\n document.addEventListener('wheel', onWheel, { passive: false });\n document.addEventListener('touchmove', onTouchMove, { passive: false });\n return () => {\n document.removeEventListener('wheel', onWheel);\n document.removeEventListener('touchmove', onTouchMove);\n };\n }, [active, allowSelector]);\n}\n"],"mappings":"AAAA,YAAY;;AAAC,SAAAA,CAAA,IAAAC,EAAA;AAEb,SAASC,SAAS,QAAQ,OAAO;AAEjC,MAAMC,eAAe,GAAG,iBAAiB;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAC/BC,MAAgB,EAChBC,KAAe,EACfC,QAA6B,EAC7BC,UAA8B,EACrB;EACT,IAAI,CAACF,KAAK,EAAE,OAAO,KAAK;EACxB,IAAIG,EAAE,GAAGJ,MAAM;EACf,OAAOI,EAAE,EAAE;IACT,IAAID,UAAU,CAACC,EAAE,CAAC,EAAE,OAAO,IAAI;IAC/B,IAAIA,EAAE,KAAKH,KAAK,EAAE;IAClBG,EAAE,GAAGF,QAAQ,CAACE,EAAE,CAAC;EACnB;EACA,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAAC,qBAAAC,MAAA,EAAAC,aAAA;EAAA,MAAAC,CAAA,GAAAZ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L,WAAW,CAAC;MAAA,CACvD;IAAA,CACF;IAAEhB,EAAA,IAACJ,MAAM,EAAEC,aAAa,CAAC;IAAAC,CAAA,MAAAF,MAAA;IAAAE,CAAA,MAAAD,aAAA;IAAAC,CAAA,MAAAC,EAAA;IAAAD,CAAA,MAAAE,EAAA;EAAA;IAAAD,EAAA,GAAAD,CAAA;IAAAE,EAAA,GAAAF,CAAA;EAAA;EA3C1BX,SAAS,CAACY,EA2CT,EAAEC,EAAuB,CAAC;AAAA;AA/CtB,SAAAY,OAAAU,IAAA;EAAA,OA2BS5B,IAAE,CAAA6B,aAAc;AAAA;AA3BzB,SAAAlB,MAAAX,EAAA,EAAAoB,MAAA;EASD,MAAAU,KAAA,GAAcC,gBAAgB,CAAC/B,EAAE,CAAC;EAClC,IAAI,CAAC,qBAAqB,CAAAgC,IAAK,CAACF,KAAK,CAAAG,SAAU,CAAC;IAAA,OAAS,KAAK;EAAA;EAC9D,MAAAC,EAAA,GAAWlC,EAAE;EACb,IAAIkC,EAAE,CAAAC,YAAa,IAAID,EAAE,CAAAE,YAAa;IAAA,OAAS,KAAK;EAAA;EACpD,IAAIhB,MAAM,GAAG,CAAsB,IAAjBc,EAAE,CAAAG,SAAU,IAAI,CAAC;IAAA,OAAS,KAAK;EAAA;EACjD,IAAIjB,MAAM,GAAG,CAAsD,IAAjDc,EAAE,CAAAG,SAAU,GAAGH,EAAE,CAAAE,YAAa,IAAIF,EAAE,CAAAC,YAAa;IAAA,OAC1D,KAAK;EAAA;EAAC,OACR,IAAI;AAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodehive/nextjs",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "NodeHive Next.js infrastructure modules: auth, puck-editor, visual-editor, smart-actions",
5
5
  "license": "MIT",
6
6
  "author": "NETNODE AG <info@netnode.ch>",