@agencecinq/utils 3.0.0 → 4.0.1

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,13 +1,13 @@
1
1
 
2
2
  
3
- > @agencecinq/utils@3.0.0 build /Users/19h47/Sites/agencecinq-shopify/packages/utils
3
+ > @agencecinq/utils@4.0.1 build /Users/19h47/Sites/agencecinq-ui/packages/utils
4
4
  > vite build
5
5
 
6
6
  vite v7.3.1 building client environment for production...
7
- transforming (1) src/index.tstransforming (2) src/events.ts✓ 7 modules transformed.
7
+ transforming (1) src/index.tstransforming (5) src/scroll.ts✓ 7 modules transformed.
8
8
  rendering chunks (1)...
9
9
  [vite:dts] Start generate declaration files...
10
- computing gzip size (0)...computing gzip size (1)...dist/index.js 3.28 kB │ gzip: 1.52 kB
11
- [vite:dts] Declaration files built in 5543ms.
10
+ computing gzip size (0)...computing gzip size (1)...dist/index.js 3.41 kB │ gzip: 1.57 kB
11
+ [vite:dts] Declaration files built in 1952ms.
12
12
  
13
- ✓ built in 5.99s
13
+ ✓ built in 2.35s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @agencecinq/utils
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Add `CART_BEFORE_UPDATE` event constant to coordinate cart pre-update flows. Listeners can call `event.preventDefault()` on the dispatched `CustomEvent` to take ownership of subsequent section rendering (e.g. a free-samples controller batching its own sync into a single render).
8
+
9
+ ## 4.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - Create a new package in @agencecinq/shopify
14
+
3
15
  ## 3.0.0
4
16
 
5
17
  ### Major Changes
package/dist/events.d.ts CHANGED
@@ -2,6 +2,10 @@ export declare const EVENTS: {
2
2
  DRAWER_CLOSE: string;
3
3
  DRAWER_OPEN: string;
4
4
  DRAWER_TOGGLE: string;
5
+ MODAL_CLOSE: string;
6
+ MODAL_OPEN: string;
7
+ MODAL_TOGGLE: string;
8
+ CART_BEFORE_UPDATE: string;
5
9
  CART_UPDATE: string;
6
10
  VARIANT_CHANGE: string;
7
11
  };
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;CAMlB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;CAUlB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"focus-trap.d.ts","sourceRoot":"","sources":["../src/focus-trap.ts"],"names":[],"mappings":"AAaA,iBAAS,oBAAoB,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,EAAE,CAkBnE;AAED,iBAAS,YAAY,CAAC,SAAS,EAAE,WAAW,EAAE,cAAc,GAAE,WAAuB,GAAG,IAAI,CAyC3F;AAED,iBAAS,eAAe,CAAC,cAAc,GAAE,WAAW,GAAG,IAAW,GAAG,IAAI,CAQxE;AAED,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"focus-trap.d.ts","sourceRoot":"","sources":["../src/focus-trap.ts"],"names":[],"mappings":"AAUA,iBAAS,oBAAoB,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,EAAE,CAkBnE;AAED,iBAAS,YAAY,CAAC,SAAS,EAAE,WAAW,EAAE,cAAc,GAAE,WAAuB,GAAG,IAAI,CAoC3F;AAED,iBAAS,eAAe,CAAC,cAAc,GAAE,WAAW,GAAG,IAAW,GAAG,IAAI,CAQxE;AAED,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1,18 +1,22 @@
1
- const O = {
1
+ const D = {
2
2
  DRAWER_CLOSE: "drawer-close",
3
3
  DRAWER_OPEN: "drawer-open",
4
4
  DRAWER_TOGGLE: "drawer-toggle",
5
+ MODAL_CLOSE: "modal-close",
6
+ MODAL_OPEN: "modal-open",
7
+ MODAL_TOGGLE: "modal-toggle",
8
+ CART_BEFORE_UPDATE: "cart-before-update",
5
9
  CART_UPDATE: "cart-update",
6
10
  VARIANT_CHANGE: "variant-change"
7
11
  }, f = (e, t) => {
8
- let n = null, r = null;
12
+ let o = null, r = null;
9
13
  const s = () => {
10
- r && e(...r), n = null;
14
+ r && e(...r), o = null;
11
15
  };
12
16
  return (...c) => {
13
- r = c, n || (n = setTimeout(s, t));
17
+ r = c, o || (o = setTimeout(s, t));
14
18
  };
15
- }, l = document.documentElement, { body: d } = document, W = l.hasAttribute("data-debug"), o = {
19
+ }, l = document.documentElement, { body: i } = document, C = l.hasAttribute("data-debug"), n = {
16
20
  y: 0,
17
21
  x: 0
18
22
  }, a = {
@@ -26,27 +30,27 @@ window.addEventListener(
26
30
  }, 100),
27
31
  { passive: !0 }
28
32
  );
29
- const k = {
33
+ const W = {
30
34
  lg: window.matchMedia("(width >= 64rem)"),
31
35
  xl: window.matchMedia("(min-width: 1280px)"),
32
36
  "2xl": window.matchMedia("(min-width: 1440px)"),
33
37
  "3xl": window.matchMedia("(min-width: 1920px)")
34
- }, C = !0, u = (e, t) => {
35
- typeof e < "u" && (o.x = e), typeof t < "u" && (o.y = t), window.scrollTo(o.x, o.y);
38
+ }, k = !0, u = (e, t) => {
39
+ typeof e < "u" && (n.x = e), typeof t < "u" && (n.y = t), window.scrollTo(n.x, n.y);
36
40
  };
37
- function N() {
38
- const e = l.scrollLeft, t = l.scrollTop, n = d.scrollLeft, r = d.scrollTop;
39
- o.x = window.scrollX || e || n, o.y = window.scrollY || t || r || 0, l.style.setProperty("overflow", "hidden"), l.style.setProperty("height", "100%"), l.style.setProperty("scroll-padding-top", "0px"), u(o.x, o.y);
41
+ function M() {
42
+ const e = l.scrollLeft, t = l.scrollTop, o = i.scrollLeft, r = i.scrollTop;
43
+ n.x = window.scrollX || e || o, n.y = window.scrollY || t || r || 0, l.style.setProperty("overflow", "hidden"), l.style.setProperty("height", "100%"), l.style.setProperty("scroll-padding-top", "0px"), u(n.x, n.y);
40
44
  }
41
- function H(e = 0) {
42
- let t = !0, n = o.y;
43
- typeof e == "number" ? n = e : typeof e == "boolean" && e === !1 && (t = !1), l.style.removeProperty("overflow"), l.style.removeProperty("height"), l.style.removeProperty("scroll-padding-top"), t && u(o.x, n);
45
+ function N(e = 0) {
46
+ let t = !0, o = n.y;
47
+ typeof e == "number" ? o = e : typeof e == "boolean" && e === !1 && (t = !1), l.style.removeProperty("overflow"), l.style.removeProperty("height"), l.style.removeProperty("scroll-padding-top"), t && u(n.x, o);
44
48
  }
45
- const i = {};
46
- function y(e) {
49
+ const d = {};
50
+ function m(e) {
47
51
  return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
48
52
  }
49
- function m(e) {
53
+ function y(e) {
50
54
  if (!e) return [];
51
55
  const t = [
52
56
  "summary",
@@ -60,50 +64,50 @@ function m(e) {
60
64
  "iframe",
61
65
  "[contenteditable]"
62
66
  ].join(",");
63
- return Array.from(e.querySelectorAll(t)).filter((n) => y(n) && n.getAttribute("tabindex") !== "-1");
67
+ return Array.from(e.querySelectorAll(t)).filter((o) => m(o) && o.getAttribute("tabindex") !== "-1");
64
68
  }
65
69
  function G(e, t = e) {
66
- const n = m(e);
67
- if (n.length === 0) return;
68
- const r = n[0], s = n[n.length - 1];
69
- E(), i.keydown = (c) => {
70
+ const o = y(e);
71
+ if (o.length === 0) return;
72
+ const r = o[0], s = o[o.length - 1];
73
+ E(), d.keydown = (c) => {
70
74
  c.key === "Tab" && (c.shiftKey ? (document.activeElement === r || document.activeElement === e) && (c.preventDefault(), s.focus()) : document.activeElement === s && (c.preventDefault(), r.focus()));
71
- }, document.addEventListener("keydown", i.keydown), t.focus(), t instanceof HTMLInputElement && ["search", "text", "email", "url"].includes(t.type) && t.value && t.setSelectionRange(0, t.value.length);
75
+ }, document.addEventListener("keydown", d.keydown), t.focus(), t instanceof HTMLInputElement && ["search", "text", "email", "url"].includes(t.type) && t.value && t.setSelectionRange(0, t.value.length);
72
76
  }
73
77
  function E(e = null) {
74
- i.keydown && document.removeEventListener("keydown", i.keydown), e && e.focus();
78
+ d.keydown && document.removeEventListener("keydown", d.keydown), e && e.focus();
75
79
  }
76
- const p = 8, w = 9, h = 13, b = 16, A = 27, x = 32, g = 33, R = 34, v = 35, P = 36, S = 37, T = 38, L = 39, D = 40, _ = 46, M = {
80
+ const p = 8, w = 9, A = 13, h = 16, b = 27, g = 32, R = 33, x = 34, P = 35, T = 36, v = 37, L = 38, O = 39, S = 40, _ = 46, H = {
77
81
  BACKSPACE: p,
78
82
  TAB: w,
79
- ENTER: h,
80
- SHIFT: b,
81
- ESCAPE: A,
82
- SPACE: x,
83
- PAGE_UP: g,
84
- PAGE_DOWN: R,
85
- END: v,
86
- HOME: P,
87
- ARROW_LEFT: S,
88
- ARROW_UP: T,
89
- ARROW_RIGHT: L,
90
- ARROW_DOWN: D,
83
+ ENTER: A,
84
+ SHIFT: h,
85
+ ESCAPE: b,
86
+ SPACE: g,
87
+ PAGE_UP: R,
88
+ PAGE_DOWN: x,
89
+ END: P,
90
+ HOME: T,
91
+ ARROW_LEFT: v,
92
+ ARROW_UP: L,
93
+ ARROW_RIGHT: O,
94
+ ARROW_DOWN: S,
91
95
  DELETE: _
92
96
  };
93
97
  export {
94
- O as EVENTS,
98
+ D as EVENTS,
95
99
  G as addTrapFocus,
96
- d as body,
97
- k as breakpoints,
98
- N as disableScroll,
99
- H as enableScroll,
100
- m as getFocusableElements,
100
+ i as body,
101
+ W as breakpoints,
102
+ M as disableScroll,
103
+ N as enableScroll,
104
+ y as getFocusableElements,
101
105
  l as html,
102
- W as isDebug,
103
- M as keycode,
106
+ C as isDebug,
107
+ H as keycode,
104
108
  a as mouse,
105
- C as production,
109
+ k as production,
106
110
  E as removeTrapFocus,
107
- o as scroll,
111
+ n as scroll,
108
112
  f as throttle
109
113
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agencecinq/utils",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/src/events.ts CHANGED
@@ -2,6 +2,10 @@ export const EVENTS = {
2
2
  DRAWER_CLOSE: 'drawer-close',
3
3
  DRAWER_OPEN: 'drawer-open',
4
4
  DRAWER_TOGGLE: 'drawer-toggle',
5
+ MODAL_CLOSE: 'modal-close',
6
+ MODAL_OPEN: 'modal-open',
7
+ MODAL_TOGGLE: 'modal-toggle',
8
+ CART_BEFORE_UPDATE: 'cart-before-update',
5
9
  CART_UPDATE: 'cart-update',
6
10
  VARIANT_CHANGE: 'variant-change',
7
11
  };
package/src/focus-trap.ts CHANGED
@@ -4,9 +4,6 @@ const trapFocusHandlers: {
4
4
  keydown?: (event: KeyboardEvent) => void;
5
5
  } = {};
6
6
 
7
- /**
8
- * Filtre les éléments réellement visibles et focalisables
9
- */
10
7
  function isVisible(el: HTMLElement): boolean {
11
8
  return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
12
9
  }
@@ -38,20 +35,17 @@ function addTrapFocus(container: HTMLElement, elementToFocus: HTMLElement = cont
38
35
  const first = elements[0];
39
36
  const last = elements[elements.length - 1];
40
37
 
41
- // Nettoyage avant d'ajouter (pour éviter les doublons)
42
38
  removeTrapFocus();
43
39
 
44
40
  trapFocusHandlers.keydown = (event: KeyboardEvent): void => {
45
41
  if (event.key !== 'Tab') return;
46
42
 
47
43
  if (event.shiftKey) {
48
- // Tab arrière
49
44
  if (document.activeElement === first || document.activeElement === container) {
50
45
  event.preventDefault();
51
46
  last.focus();
52
47
  }
53
48
  } else {
54
- // Tab avant
55
49
  if (document.activeElement === last) {
56
50
  event.preventDefault();
57
51
  first.focus();
@@ -61,10 +55,8 @@ function addTrapFocus(container: HTMLElement, elementToFocus: HTMLElement = cont
61
55
 
62
56
  document.addEventListener('keydown', trapFocusHandlers.keydown);
63
57
 
64
- // Focus initial
65
58
  elementToFocus.focus();
66
59
 
67
- // Support spécifique pour les inputs texte (sélection du contenu)
68
60
  if (
69
61
  elementToFocus instanceof HTMLInputElement &&
70
62
  ['search', 'text', 'email', 'url'].includes(elementToFocus.type) &&
@@ -84,4 +76,4 @@ function removeTrapFocus(elementToFocus: HTMLElement | null = null): void {
84
76
  }
85
77
  }
86
78
 
87
- export { addTrapFocus, removeTrapFocus, getFocusableElements };
79
+ export { addTrapFocus, removeTrapFocus, getFocusableElements };