@carbon/utilities 0.16.0 → 0.17.0
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/es/carousel/carousel.js +1 -1
- package/es/overflowHandler/overflowHandler.js +1 -1
- package/lib/carousel/carousel.js +1 -1
- package/lib/carousel/types.js +1 -1
- package/lib/overflowHandler/overflowHandler.js +1 -1
- package/package.json +2 -2
- package/types/carousel/carousel.d.ts +2 -2
- package/types/carousel/types.d.ts +2 -5
- package/types/overflowHandler/overflowHandler.d.ts +3 -3
- package/es/makeDraggable/makeDraggable.test.js +0 -1
- package/lib/makeDraggable/makeDraggable.test.js +0 -1
- package/types/makeDraggable/makeDraggable.test.d.ts +0 -1
package/es/carousel/carousel.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{registerSwipeEvents as C}from"./swipeEvents";const
|
|
1
|
+
import{registerSwipeEvents as C}from"./swipeEvents";const X=(l,k)=>{const r="carousel";let s=[0],f=[0];const a={},u=new WeakMap,E=4,{onViewChangeStart:$,onViewChangeEnd:w,excludeSwipeSupport:L,useMaxHeight:V}=k||{},A=(e,t)=>{a[e]=t},R=(e,t)=>{if(e.querySelector(`.${t}`))return;const n=document.createElement("div");for(n.classList.add(`${t}`);e.firstChild;)n.appendChild(e.firstChild);e.appendChild(n)},I=()=>s.reduce((e,t)=>{const n=a[t];return n&&e.push({id:t,elem:n}),e},[]),H=()=>{const e=Object.keys(a).length,t=a[e-1],n=I();return{currentIndex:s[0],lastIndex:parseInt(t?.dataset.index||s[0].toString(),10),totalViews:e,historyStack:n}},y=()=>{f=[...s];const e=H();$?.(e)},M=e=>{if(!e)return;const t=e.dataset.index;if(t&&s[0]===parseInt(t,10)){const n=H();w?.(n)}},W=e=>{const n=Object.keys(a).length-1;return Math.max(0,Math.min(e,n))},T=e=>{const t=W(e);s[0]!==t&&(y(),s=[t,...s],m(!1))},q=e=>{M(e)},z=(e,t,n,o,i)=>{e.classList.add(`${r}__view`),e.classList.toggle(`${r}__view-in-stack`,t&&!n),e.classList.toggle(`${r}__view-active`,t&&n),i&&!o&&e.classList.add(`${r}__view-recycle-in`),!i&&o&&e.classList.add(`${r}__view-recycle-out`)},b=e=>{e.classList.remove(`${r}__view-recycle-in`,`${r}__view-recycle-out`)},x=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),_=e=>{const t=x(E);if(l.clientHeight<t){e<t&&(e=t);const o=l.querySelector(`.${r}__itemsWrapper`);o&&(o.style.blockSize=`${e}px`)}},m=e=>{let t=0,n=0;Array.from(d).forEach((o,i)=>{const P=s.findIndex(c=>c===i),v=f.filter(c=>c===i).length,B=f.length>s.length&&f[0]===i&&v>0,G=f.length<s.length&&s[0]===i&&v>0,J=P>-1,K=i===s[0];if(z(o,J,K,B,G),e){A(i,o),setTimeout(()=>{if(V){const h=Array.from(d).map(Q=>Q.scrollHeight);n=Math.max(...h),o.style.position="absolute",_(n)}else(!t||o.offsetHeight<t&&t>x(E))&&(t=o.offsetHeight),o.style.position="absolute",_(t)});const c=h=>{b(o),h.target===a[s[0]]&&q(o)};u.set(o,c),o.addEventListener("animationend",c),o.addEventListener("transitionend",c),o.setAttribute("data-index",i.toString())}}),e&&M(Array.from(d)[0])},p=()=>{const e=s[0]+1;T(e)},g=()=>{s.length-1>=1&&(y(),s=s.slice(1),m(!1))},j=e=>{T(e)},D=()=>({index:s[0],item:a[s[0]]}),O=()=>{Array.from(d).forEach(e=>{b(e)}),f=[0],s=[0],m(!1)},F=()=>{Object.values(a).forEach(e=>{if(!e)return;const t=u.get(e);t&&(e.removeEventListener("animationend",t),e.removeEventListener("transitionend",t)),u.delete(e)}),L||C(l,p,g,!0)},N=e=>{const t=e.querySelector("slot");return t instanceof HTMLSlotElement?t.assignedElements({flatten:!0}).filter(n=>n instanceof HTMLElement):Array.from(e.children).filter(n=>n instanceof HTMLElement)};R(l,`${r}__itemsWrapper`);const S=l.querySelector(`.${r}__itemsWrapper`);if(!(S instanceof HTMLElement))throw new Error("Carousel items wrapper not found");const d=N(S);return l.classList.add(`${r}__view-stack`),m(!0),L||C(l,p,g,!1),{next:p,prev:g,reset:O,goToIndex:j,getActiveItem:D,destroyEvents:F,allViews:a}};export{X as initCarousel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function v(e,
|
|
1
|
+
function v(e,n){if(!e)return 0;const f=e.style.display;!e.offsetParent&&getComputedStyle(e).display==="none"&&(e.style.display="inline-block");const o=e.getBoundingClientRect()[n];return e.style.display=f,o}function w({container:e,items:n,offset:f,sizes:o,fixedSizes:a,offsetSize:c,maxVisibleItems:l,dimension:m,onChange:E,previousHiddenItems:u=[]}){const H=m==="width"?e.clientWidth:e.clientHeight;let d=[],i=[];const p=o.reduce((r,s)=>r+s,0),t=a.reduce((r,s)=>r+s,0);if(p+t<=H)d=l?n.slice(0,l):[...n],i=l?n.slice(l):[];else{const r=H-c;let s=0;for(let h=0;h<n.length;h++){const g=o[h];s+g+t<=r&&(!l||d.length<l)?(d.push(n[h]),s+=g):i.push(n[h])}}return u.length===i.length&&u.every((r,s)=>r===i[s])?u:(d.forEach(r=>r.removeAttribute("data-hidden")),i.forEach(r=>r.setAttribute("data-hidden","")),f&&f.toggleAttribute("data-hidden",i.length===0),E(d,i),i)}function b({container:e,maxVisibleItems:n,onChange:f,dimension:o="width"}){if(!(e instanceof HTMLElement))throw new Error("container must be an HTMLElement");if(typeof f!="function")throw new Error("onChange must be a function");if(n!==void 0&&(!Number.isInteger(n)||n<=0))throw new Error("maxVisibleItems must be a positive integer");const a=Array.from(e.children).filter(t=>t instanceof HTMLElement),c=a.find(t=>t.hasAttribute("data-offset")),l=a.filter(t=>t.hasAttribute("data-fixed")),m=a.filter(t=>t!==c&&!l.includes(t)),E=l.map(t=>v(t,o)),u=m.map(t=>v(t,o)),H=v(c,o);let d=[];function i(){d=w({container:e,items:m,offset:c,sizes:u,fixedSizes:E,offsetSize:H,maxVisibleItems:n,dimension:o,onChange:f,previousHiddenItems:d})}const p=new ResizeObserver(()=>requestAnimationFrame(i));return p.observe(e),requestAnimationFrame(i),{disconnect(){p.disconnect()}}}export{b as createOverflowHandler,v as getSize,w as updateOverflowHandler};
|
package/lib/carousel/carousel.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var L=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=(i,l)=>{for(var r in l)L(i,r,{get:l[r],enumerable:!0})},te=(i,l,r,n)=>{if(l&&typeof l=="object"||typeof l=="function")for(let a of Y(l))!Z.call(i,a)&&a!==r&&L(i,a,{get:()=>l[a],enumerable:!(n=X(l,a))||n.enumerable});return i};var ne=i=>te(L({},"__esModule",{value:!0}),i);var oe={};ee(oe,{initCarousel:()=>se});module.exports=ne(oe);var H=require("./swipeEvents");const se=(i,l)=>{const r="carousel";let n=[0],a=[0];const f={},p=new WeakMap,y=4,{onViewChangeStart:w,onViewChangeEnd:V,excludeSwipeSupport:M,useMaxHeight:A}=l||{},R=(e,t)=>{f[e]=t},I=(e,t)=>{if(e.querySelector(`.${t}`))return;const s=document.createElement("div");for(s.classList.add(`${t}`);e.firstChild;)s.appendChild(e.firstChild);e.appendChild(s)},W=()=>n.reduce((e,t)=>{const s=f[t];return s&&e.push({id:t,elem:s}),e},[]),T=()=>{const e=Object.keys(f).length,t=f[e-1],s=W();return{currentIndex:n[0],lastIndex:parseInt(t?.dataset.index||n[0].toString(),10),totalViews:e,historyStack:s}},b=()=>{a=[...n];const e=T();w?.(e)},x=e=>{if(!e)return;const t=e.dataset.index;if(t&&n[0]===parseInt(t,10)){const s=T();V?.(s)}},q=e=>{const s=Object.keys(f).length-1;return Math.max(0,Math.min(e,s))},_=e=>{const t=q(e);n[0]!==t&&(b(),n=[t,...n],d(!1))},z=e=>{x(e)},j=(e,t,s,o,c)=>{e.classList.add(`${r}__view`),e.classList.toggle(`${r}__view-in-stack`,t&&!s),e.classList.toggle(`${r}__view-active`,t&&s),c&&!o&&e.classList.add(`${r}__view-recycle-in`),!c&&o&&e.classList.add(`${r}__view-recycle-out`)},S=e=>{e.classList.remove(`${r}__view-recycle-in`,`${r}__view-recycle-out`)},v=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),C=e=>{const t=v(y);if(i.clientHeight<t){e<t&&(e=t);const o=i.querySelector(`.${r}__itemsWrapper`);o&&(o.style.blockSize=`${e}px`)}},d=e=>{let t=0,s=0;Array.from(u).forEach((o,c)=>{const B=n.findIndex(m=>m===c),$=a.filter(m=>m===c).length,G=a.length>n.length&&a[0]===c&&$>0,J=a.length<n.length&&n[0]===c&&$>0,K=B>-1,Q=c===n[0];if(j(o,K,Q,G,J),e){R(c,o),setTimeout(()=>{if(A){const E=Array.from(u).map(U=>U.scrollHeight);s=Math.max(...E),o.style.position="absolute",C(s)}else(!t||o.offsetHeight<t&&t>v(y))&&(t=o.offsetHeight),o.style.position="absolute",C(t)});const m=E=>{S(o),E.target===f[n[0]]&&z(o)};p.set(o,m),o.addEventListener("animationend",m),o.addEventListener("transitionend",m),o.setAttribute("data-index",c.toString())}}),e&&x(Array.from(u)[0])},g=()=>{const e=n[0]+1;_(e)},h=()=>{n.length-1>=1&&(b(),n=n.slice(1),d(!1))},D=e=>{_(e)},O=()=>({index:n[0],item:f[n[0]]}),F=()=>{Array.from(u).forEach(e=>{S(e)}),a=[0],n=[0],d(!1)},N=()=>{Object.values(f).forEach(e=>{if(!e)return;const t=p.get(e);t&&(e.removeEventListener("animationend",t),e.removeEventListener("transitionend",t)),p.delete(e)}),M||(0,H.registerSwipeEvents)(i,g,h,!0)},P=e=>{const t=e.querySelector("slot");return t instanceof HTMLSlotElement?t.assignedElements({flatten:!0}).filter(s=>s instanceof HTMLElement):Array.from(e.children).filter(s=>s instanceof HTMLElement)};I(i,`${r}__itemsWrapper`);const k=i.querySelector(`.${r}__itemsWrapper`);if(!(k instanceof HTMLElement))throw new Error("Carousel items wrapper not found");const u=P(k);return i.classList.add(`${r}__view-stack`),d(!0),M||(0,H.registerSwipeEvents)(i,g,h,!1),{next:g,prev:h,reset:F,goToIndex:D,getActiveItem:O,destroyEvents:N,allViews:f}};
|
package/lib/carousel/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var u=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of a(e))!l.call(t,o)&&o!==s&&r(t,o,{get:()=>e[o],enumerable:!(n=i(e,o))||n.enumerable});return t};var d=t=>u(r({},"__esModule",{value:!0}),t);var m={};module.exports=d(m);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var
|
|
1
|
+
"use strict";var g=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var O=(e,t)=>{for(var i in t)g(e,i,{get:t[i],enumerable:!0})},z=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of M(t))!T.call(e,o)&&o!==i&&g(e,o,{get:()=>t[o],enumerable:!(r=L(t,o))||r.enumerable});return e};var y=e=>z(g({},"__esModule",{value:!0}),e);var A={};O(A,{createOverflowHandler:()=>S,getSize:()=>E,updateOverflowHandler:()=>b});module.exports=y(A);function E(e,t){if(!e)return 0;const i=e.style.display;!e.offsetParent&&getComputedStyle(e).display==="none"&&(e.style.display="inline-block");const r=e.getBoundingClientRect()[t];return e.style.display=i,r}function b({container:e,items:t,offset:i,sizes:r,fixedSizes:o,offsetSize:c,maxVisibleItems:s,dimension:m,onChange:v,previousHiddenItems:u=[]}){const H=m==="width"?e.clientWidth:e.clientHeight;let f=[],l=[];const p=r.reduce((d,a)=>d+a,0),n=o.reduce((d,a)=>d+a,0);if(p+n<=H)f=s?t.slice(0,s):[...t],l=s?t.slice(s):[];else{const d=H-c;let a=0;for(let h=0;h<t.length;h++){const w=r[h];a+w+n<=d&&(!s||f.length<s)?(f.push(t[h]),a+=w):l.push(t[h])}}return u.length===l.length&&u.every((d,a)=>d===l[a])?u:(f.forEach(d=>d.removeAttribute("data-hidden")),l.forEach(d=>d.setAttribute("data-hidden","")),i&&i.toggleAttribute("data-hidden",l.length===0),v(f,l),l)}function S({container:e,maxVisibleItems:t,onChange:i,dimension:r="width"}){if(!(e instanceof HTMLElement))throw new Error("container must be an HTMLElement");if(typeof i!="function")throw new Error("onChange must be a function");if(t!==void 0&&(!Number.isInteger(t)||t<=0))throw new Error("maxVisibleItems must be a positive integer");const o=Array.from(e.children).filter(n=>n instanceof HTMLElement),c=o.find(n=>n.hasAttribute("data-offset")),s=o.filter(n=>n.hasAttribute("data-fixed")),m=o.filter(n=>n!==c&&!s.includes(n)),v=s.map(n=>E(n,r)),u=m.map(n=>E(n,r)),H=E(c,r);let f=[];function l(){f=b({container:e,items:m,offset:c,sizes:u,fixedSizes:v,offsetSize:H,maxVisibleItems:t,dimension:r,onChange:i,previousHiddenItems:f})}const p=new ResizeObserver(()=>requestAnimationFrame(l));return p.observe(e),requestAnimationFrame(l),{disconnect(){p.disconnect()}}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon/utilities",
|
|
3
3
|
"description": "Utilities and helpers to drive consistency across software products using the Carbon Design System",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "es/index.js",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"@ibm/telemetry-js": "^1.6.1",
|
|
50
50
|
"@internationalized/number": "^3.6.1"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "443fbe43ff4bd1df327997b8b0b0ebeee634d002"
|
|
53
53
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright IBM Corp. 2025
|
|
2
|
+
* Copyright IBM Corp. 2025, 2026
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import type { Config, InitCarousel } from './types';
|
|
8
8
|
/**
|
|
9
9
|
* Initializes a carousel with the given configuration.
|
|
10
10
|
* @param carouselContainer - The HTMLElement representing the carousel container.
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright IBM Corp. 2025
|
|
2
|
+
* Copyright IBM Corp. 2025, 2026
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
interface CarouselStackHistory {
|
|
8
8
|
id: number;
|
|
9
|
-
elem:
|
|
10
|
-
}
|
|
11
|
-
export interface CarouselHTMLElement extends HTMLElement {
|
|
12
|
-
_carouselListener?: EventListener;
|
|
9
|
+
elem: HTMLElement;
|
|
13
10
|
}
|
|
14
11
|
type CarouselResponse = {
|
|
15
12
|
currentIndex: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright IBM Corp. 2025
|
|
2
|
+
* Copyright IBM Corp. 2025, 2026
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @param dimension - The dimension to measure ('width' or 'height').
|
|
16
16
|
* @returns The size of the element in pixels. Returns 0 if the element is not provided.
|
|
17
17
|
*/
|
|
18
|
-
export declare function getSize(el: HTMLElement, dimension: 'width' | 'height'): number;
|
|
18
|
+
export declare function getSize(el: HTMLElement | undefined, dimension: 'width' | 'height'): number;
|
|
19
19
|
/**
|
|
20
20
|
* Options for updating the overflow handler.
|
|
21
21
|
* Determines which items should be visible and which should be hidden
|
|
@@ -27,7 +27,7 @@ export interface UpdateOverflowHandlerOptions {
|
|
|
27
27
|
/** An array of item elements to be managed for overflow. */
|
|
28
28
|
items: HTMLElement[];
|
|
29
29
|
/** An element that represents the offset, which can be shown or hidden based on overflow. Identified by `data-offset` attribute. */
|
|
30
|
-
offset: HTMLElement;
|
|
30
|
+
offset: HTMLElement | undefined;
|
|
31
31
|
/** An array of sizes corresponding to each item in the `items` array. */
|
|
32
32
|
sizes: number[];
|
|
33
33
|
/** An array of sizes corresponding to each item in the fixed items array. */
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{makeDraggable as s}from"../makeDraggable";import{fireEvent as n}from"@testing-library/react";function o(e={}){const t=document.createElement("div");t.style.position="absolute",t.style.left="0px",t.style.top="0px";const l=document.createElement("div"),p=document.createElement("button");return t.appendChild(l),t.appendChild(p),document.body.appendChild(t),s({el:t,dragHandle:l,focusableDragHandle:p,dragStep:e.dragStep,shiftDragStep:e.shiftDragStep}),{el:t,handle:l,focusableHandle:p}}describe("makeDraggable",()=>{it("should set cursor style on handle",()=>{const{el:e,handle:t}=o();expect(t.style.cursor).toBe("move"),expect(e.style.cursor).toBe("default")}),it("should keep position as absolute when already absolute",()=>{const{el:e}=o();expect(e.style.position).toBe("absolute")}),it("should move element with arrowRight with default dragStep value",()=>{const{el:e,focusableHandle:t}=o();t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight"})),expect(e.style.left).toBe("8px"),expect(e.style.top).toBe("0px")}),it("should move element with arrowUp with default dragStep value",()=>{const{el:e,focusableHandle:t}=o();t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowUp"})),expect(e.style.left).toBe("0px"),expect(e.style.top).toBe("-8px")}),it("should move element with arrowLeft with default dragStep value",()=>{const{el:e,focusableHandle:t}=o();t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowLeft"})),expect(e.style.left).toBe("-8px"),expect(e.style.top).toBe("0px")}),it("should move element with arrowDown with default shiftDragStep value",()=>{const{el:e,focusableHandle:t}=o();t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight",shiftKey:!0})),expect(e.style.left).toBe("32px"),expect(e.style.top).toBe("0px")}),it("should move element with arrow keys(dragStep)",()=>{const{el:e,focusableHandle:t}=o({dragStep:10});t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight"})),expect(e.style.left).toBe("10px"),expect(e.style.top).toBe("0px"),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowLeft"})),expect(e.style.left).toBe("0px"),expect(e.style.top).toBe("0px")},0),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowDown"})),expect(e.style.top).toBe("10px"),expect(e.style.left).toBe("0px")},0),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowUp"})),expect(e.style.top).toBe("0px"),expect(e.style.left).toBe("0px")},0)}),it("should move element with shift + arrow keys (shiftDragStep)",()=>{const{el:e,focusableHandle:t}=o({shiftDragStep:20});t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowDown",shiftKey:!0})),expect(e.style.top).toBe("20px"),expect(e.style.left).toBe("0px"),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowUp",shiftKey:!0})),expect(e.style.top).toBe("0px"),expect(e.style.left).toBe("0px")},0),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight",shiftKey:!0})),expect(e.style.top).toBe("0px"),expect(e.style.left).toBe("20px")},0),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight",shiftKey:!0})),expect(e.style.top).toBe("0px"),expect(e.style.left).toBe("0px")},0)}),it("should move element with mouse drag",()=>{const{el:e,handle:t}=o();n.mouseDown(t,{clientX:50,clientY:50}),n.mouseMove(document,{clientX:100,clientY:120}),expect(e.style.left).toBe("50px"),expect(e.style.top).toBe("70px"),n.mouseUp(t),n.mouseMove(document,{clientX:100,clientY:120}),expect(e.style.left).toBe("50px"),expect(e.style.top).toBe("70px")})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var s=require("../makeDraggable"),n=require("@testing-library/react");function o(e={}){const t=document.createElement("div");t.style.position="absolute",t.style.left="0px",t.style.top="0px";const l=document.createElement("div"),p=document.createElement("button");return t.appendChild(l),t.appendChild(p),document.body.appendChild(t),(0,s.makeDraggable)({el:t,dragHandle:l,focusableDragHandle:p,dragStep:e.dragStep,shiftDragStep:e.shiftDragStep}),{el:t,handle:l,focusableHandle:p}}describe("makeDraggable",()=>{it("should set cursor style on handle",()=>{const{el:e,handle:t}=o();expect(t.style.cursor).toBe("move"),expect(e.style.cursor).toBe("default")}),it("should keep position as absolute when already absolute",()=>{const{el:e}=o();expect(e.style.position).toBe("absolute")}),it("should move element with arrowRight with default dragStep value",()=>{const{el:e,focusableHandle:t}=o();t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight"})),expect(e.style.left).toBe("8px"),expect(e.style.top).toBe("0px")}),it("should move element with arrowUp with default dragStep value",()=>{const{el:e,focusableHandle:t}=o();t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowUp"})),expect(e.style.left).toBe("0px"),expect(e.style.top).toBe("-8px")}),it("should move element with arrowLeft with default dragStep value",()=>{const{el:e,focusableHandle:t}=o();t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowLeft"})),expect(e.style.left).toBe("-8px"),expect(e.style.top).toBe("0px")}),it("should move element with arrowDown with default shiftDragStep value",()=>{const{el:e,focusableHandle:t}=o();t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight",shiftKey:!0})),expect(e.style.left).toBe("32px"),expect(e.style.top).toBe("0px")}),it("should move element with arrow keys(dragStep)",()=>{const{el:e,focusableHandle:t}=o({dragStep:10});t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight"})),expect(e.style.left).toBe("10px"),expect(e.style.top).toBe("0px"),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowLeft"})),expect(e.style.left).toBe("0px"),expect(e.style.top).toBe("0px")},0),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowDown"})),expect(e.style.top).toBe("10px"),expect(e.style.left).toBe("0px")},0),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowUp"})),expect(e.style.top).toBe("0px"),expect(e.style.left).toBe("0px")},0)}),it("should move element with shift + arrow keys (shiftDragStep)",()=>{const{el:e,focusableHandle:t}=o({shiftDragStep:20});t.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter"})),t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowDown",shiftKey:!0})),expect(e.style.top).toBe("20px"),expect(e.style.left).toBe("0px"),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowUp",shiftKey:!0})),expect(e.style.top).toBe("0px"),expect(e.style.left).toBe("0px")},0),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight",shiftKey:!0})),expect(e.style.top).toBe("0px"),expect(e.style.left).toBe("20px")},0),setTimeout(()=>{t.dispatchEvent(new KeyboardEvent("keydown",{key:"ArrowRight",shiftKey:!0})),expect(e.style.top).toBe("0px"),expect(e.style.left).toBe("0px")},0)}),it("should move element with mouse drag",()=>{const{el:e,handle:t}=o();n.fireEvent.mouseDown(t,{clientX:50,clientY:50}),n.fireEvent.mouseMove(document,{clientX:100,clientY:120}),expect(e.style.left).toBe("50px"),expect(e.style.top).toBe("70px"),n.fireEvent.mouseUp(t),n.fireEvent.mouseMove(document,{clientX:100,clientY:120}),expect(e.style.left).toBe("50px"),expect(e.style.top).toBe("70px")})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|