@box-kite/react 2.2.3 → 2.2.5
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/.claude/rules/box-kite-rules.md +8 -0
- package/.claude/skills/box-kite/SKILL.md +8 -0
- package/.claude/skills/box-kite/references/components.md +49 -3
- package/.cursor/rules/box-kite.mdc +8 -0
- package/AGENTS.md +8 -0
- package/BOX_AI_CONTEXT.md +276 -20
- package/BOX_KITE_AI_CONTEXT.md +276 -20
- package/behavior.cjs +1 -1
- package/behavior.mjs +57 -57
- package/box.cjs +1 -1
- package/box.d.ts +5 -0
- package/box.mjs +17 -17
- package/catalog.cjs +1 -1
- package/catalog.mjs +385 -0
- package/client.cjs +1 -1
- package/client.mjs +113 -87
- package/components/dashboard.cjs +1 -1
- package/components/dashboard.mjs +1 -1
- package/components/dataGrid/components/dataGridList.d.ts +12 -0
- package/components/dataGrid/components/dataGridListAggregate.d.ts +7 -0
- package/components/dataGrid/components/dataGridListFilter.d.ts +7 -0
- package/components/dataGrid/components/dataGridListFilterSheet.d.ts +11 -0
- package/components/dataGrid/components/dataGridListFooter.d.ts +13 -0
- package/components/dataGrid/components/dataGridListGroup.d.ts +13 -0
- package/components/dataGrid/components/dataGridListItem.d.ts +21 -0
- package/components/dataGrid/components/dataGridListLayout.d.ts +20 -0
- package/components/dataGrid/components/dataGridListRecord.d.ts +11 -0
- package/components/dataGrid/components/dataGridListSelectionBar.d.ts +11 -0
- package/components/dataGrid/components/dataGridListSheet.d.ts +30 -0
- package/components/dataGrid/components/dataGridListSortSheet.d.ts +10 -0
- package/components/dataGrid/components/dataGridListToolbar.d.ts +10 -0
- package/components/dataGrid/components/dataGridListValue.d.ts +12 -0
- package/components/dataGrid/contracts/dataGridContract.d.ts +32 -0
- package/components/dataGrid/models/gridModel.d.ts +3 -0
- package/components/dataGrid/models/listModel.d.ts +129 -0
- package/components/dataGrid/models/localeText.d.ts +32 -0
- package/components/dataGrid/models/viewportModel.d.ts +0 -2
- package/components/dataGrid/useListLayout.d.ts +13 -0
- package/components/dataGrid.cjs +3 -3
- package/components/dataGrid.mjs +1052 -788
- package/components/dialog.cjs +1 -1
- package/components/dialog.mjs +85 -97
- package/components/list/listItemParts.d.ts +9 -0
- package/components/list.cjs +1 -0
- package/components/list.d.ts +118 -0
- package/components/list.mjs +391 -0
- package/components/menu.cjs +1 -1
- package/components/menu.mjs +25 -25
- package/components/overlay.cjs +1 -1
- package/components/overlay.mjs +12 -12
- package/components/semantics.d.ts +29 -29
- package/components/slider.cjs +1 -1
- package/components/slider.mjs +1 -1
- package/components/sortableList.cjs +1 -0
- package/components/sortableList.d.ts +49 -0
- package/components/sortableList.mjs +384 -0
- package/components/swipeItem.cjs +1 -0
- package/components/swipeItem.d.ts +52 -0
- package/components/swipeItem.mjs +321 -0
- package/components/tabs.cjs +1 -1
- package/components/tabs.mjs +1 -1
- package/components/toaster.cjs +1 -1
- package/components/toaster.mjs +24 -24
- package/components/virtualList.cjs +1 -0
- package/components/virtualList.d.ts +32 -0
- package/components/virtualList.mjs +188 -0
- package/dataGridList.cjs +1 -0
- package/dataGridList.mjs +1351 -0
- package/docs/components.md +5 -1
- package/icons/closeIcon.d.ts +2 -0
- package/icons/filterIcon.d.ts +2 -0
- package/layer.cjs +1 -1
- package/layer.mjs +1 -1
- package/mcp/src/data.d.ts +2 -0
- package/package.json +86 -22
- package/placement.cjs +1 -1
- package/placement.mjs +10 -10
- package/platform.cjs +1 -1
- package/platform.mjs +4 -1
- package/react/a11y/useControllableState.d.ts +2 -1
- package/react/componentsContext.d.ts +4 -0
- package/react/componentsProvider.d.ts +10 -0
- package/react/resolveStyles.d.ts +2 -1
- package/react/theme/theme.d.ts +6 -1
- package/react-shared.cjs +1 -1
- package/react-shared.mjs +40 -29
- package/registry/blocks/dashboard-shell/dashboard-shell.d.ts +3 -1
- package/registry/designs/store/address-form.d.ts +11 -0
- package/registry/designs/store/cart-items.d.ts +10 -0
- package/registry/designs/store/cart-page.d.ts +4 -0
- package/registry/designs/store/checkout-page.d.ts +7 -0
- package/registry/designs/store/credit-card-form.d.ts +10 -0
- package/registry/designs/store/form-field.d.ts +19 -0
- package/registry/designs/store/order-summary.d.ts +18 -0
- package/registry/designs/store/product-art.d.ts +26 -0
- package/registry/designs/store/product-card.d.ts +11 -0
- package/registry/designs/store/product-gallery.d.ts +11 -0
- package/registry/designs/store/product-grid.d.ts +10 -0
- package/registry/designs/store/product-page.d.ts +5 -0
- package/registry/designs/store/quantity-stepper.d.ts +13 -0
- package/registry/designs/store/shipping-method.d.ts +14 -0
- package/registry/designs/store/store-data.d.ts +53 -0
- package/registry/designs/store/store-design.d.ts +63 -0
- package/registry/designs/store/store-shell.d.ts +12 -0
- package/registry/designs/store/storefront-page.d.ts +4 -0
- package/registry/designs/store/variant-picker.d.ts +15 -0
- package/rsc.cjs +1 -1
- package/rsc.d.ts +2 -0
- package/rsc.mjs +1 -1
- package/scrolling.cjs +1 -0
- package/scrolling.mjs +22 -0
- package/ssg.cjs +1 -1
- package/ssg.mjs +1 -1
- package/utils/scroll/scrollUtils.d.ts +6 -0
- package/utils/sortable/sortableUtils.d.ts +25 -0
- package/utils/swipe/swipeUtils.d.ts +53 -0
- package/utils/virtual/measuredWindow.d.ts +28 -0
- package/utils/virtual/rowSearch.d.ts +11 -0
package/components/slider.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../platform.cjs"),t=require("../box.cjs"),n=require("../behavior.cjs");let r=require("react"),i=require("react/jsx-runtime");var a;(function(e){function t(e){let t=String(Math.abs(e));if(t.includes(`e`))return 12;let n=t.indexOf(`.`);return n===-1?0:t.length-n-1}e.decimals=t;function n(e,t){return Number(e.toFixed(Math.min(t,15)))}function r(e,t,n){return Math.min(Math.max(e,t),n)}e.clamp=r;function i(e,i){let{min:a,max:o,step:s}=i,c=r(e,a,o);return s>0?r(n(a+Math.round((c-a)/s)*s,t(s)+t(a)),a,o):c}e.snap=i;function a(e,t,n){return n<=t?0:(r(e,t,n)-t)*(100/(n-t))}e.percent=a;function o(e,t,n){return`${Math.round(a(e,t,n)*100)/100}%`}e.percentage=o;function s(e){return typeof e==`number`?[e]:[...e]}e.thumbs=s;function c(e,t){return typeof e==`number`?t[0]:[...t]}e.shaped=c;function l(e,t,n,a){let o=t>0?e[t-1]:a.min,s=t<e.length-1?e[t+1]:a.max,c=[...e];return c[t]=r(i(n,a),o,s),c}e.move=l;function u(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}e.same=u;function d(e,t){let n=0,r=1/0;return e.forEach((e,i)=>{let a=Math.abs(e-t);a<=r&&(n=i,r=a)}),n}e.nearest=d;function f(e,t,n,r,i){let a=r===`vertical`?e.height===0?0:(e.bottom-n)/e.height:e.width===0?0:i?(e.right-t)/e.width:(t-e.left)/e.width;return Math.min(Math.max(a,0),1)}e.valueAt=f;function p(e,t=!1){if(e===`Home`)return{kind:`edge`,delta:-1};if(e===`End`)return{kind:`edge`,delta:1};if(e===`PageUp`)return{kind:`page`,delta:1};if(e===`PageDown`)return{kind:`page`,delta:-1};if(e===`ArrowUp`)return{kind:`step`,delta:1};if(e===`ArrowDown`)return{kind:`step`,delta:-1};if(e===`ArrowRight`)return{kind:`step`,delta:t?-1:1};if(e===`ArrowLeft`)return{kind:`step`,delta:t?1:-1}}e.moveFor=p;function m(e,t,n,r){if(t.kind===`edge`)return t.delta>0?n.max:n.min;let i=t.kind===`page`?r:n.step;return e+t.delta*i}e.moved=m})(a||={});var o=a,s=`data-index`;function c(e,t,n){return{min:e,max:t,step:n}}function l(e,t){return t?{insetBlockEnd:e}:{insetInlineStart:e}}function u(e,t,n){let r=e.length>1?Math.min(...e):t.min,i=Math.max(...e),a=o.percent(r,t.min,t.max),s=`${Math.round((o.percent(i,t.min,t.max)-a)*100)/100}%`;return n?{insetBlockEnd:`${Math.round(a*100)/100}%`,blockSize:s}:{insetInlineStart:`${Math.round(a*100)/100}%`,inlineSize:s}}function d(a){let{value:d,defaultValue:f,onValueChange:p,onValueCommit:m,min:h=0,max:g=100,step:_=1,largeStep:v=_*10,orientation:y=`horizontal`,disabled:b=!1,label:x,labelledBy:S,thumbLabels:C,format:w,name:T,props:E,...D}=a,O=(0,r.useRef)(null),k=(0,r.useRef)(null),A=(0,r.useRef)(null),j=(0,r.useRef)(!1),[M,N]=(0,r.useState)(!1),[P,F]=n.i({value:d,defaultValue:f??h,onChange:p}),I=c(h,g,_),L=y===`vertical`,R=o.thumbs(P),z=n.o(P),B=n.a(m),V=n.a((e,t)=>{F(t=>o.same(o.thumbs(t),e)?t:o.shaped(t,e),t)}),H=t=>{let n=k.current;if(!n)return;let r=o.valueAt(n.getBoundingClientRect(),t.clientX,t.clientY,y,e.
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../platform.cjs"),t=require("../box.cjs"),n=require("../behavior.cjs");let r=require("react"),i=require("react/jsx-runtime");var a;(function(e){function t(e){let t=String(Math.abs(e));if(t.includes(`e`))return 12;let n=t.indexOf(`.`);return n===-1?0:t.length-n-1}e.decimals=t;function n(e,t){return Number(e.toFixed(Math.min(t,15)))}function r(e,t,n){return Math.min(Math.max(e,t),n)}e.clamp=r;function i(e,i){let{min:a,max:o,step:s}=i,c=r(e,a,o);return s>0?r(n(a+Math.round((c-a)/s)*s,t(s)+t(a)),a,o):c}e.snap=i;function a(e,t,n){return n<=t?0:(r(e,t,n)-t)*(100/(n-t))}e.percent=a;function o(e,t,n){return`${Math.round(a(e,t,n)*100)/100}%`}e.percentage=o;function s(e){return typeof e==`number`?[e]:[...e]}e.thumbs=s;function c(e,t){return typeof e==`number`?t[0]:[...t]}e.shaped=c;function l(e,t,n,a){let o=t>0?e[t-1]:a.min,s=t<e.length-1?e[t+1]:a.max,c=[...e];return c[t]=r(i(n,a),o,s),c}e.move=l;function u(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}e.same=u;function d(e,t){let n=0,r=1/0;return e.forEach((e,i)=>{let a=Math.abs(e-t);a<=r&&(n=i,r=a)}),n}e.nearest=d;function f(e,t,n,r,i){let a=r===`vertical`?e.height===0?0:(e.bottom-n)/e.height:e.width===0?0:i?(e.right-t)/e.width:(t-e.left)/e.width;return Math.min(Math.max(a,0),1)}e.valueAt=f;function p(e,t=!1){if(e===`Home`)return{kind:`edge`,delta:-1};if(e===`End`)return{kind:`edge`,delta:1};if(e===`PageUp`)return{kind:`page`,delta:1};if(e===`PageDown`)return{kind:`page`,delta:-1};if(e===`ArrowUp`)return{kind:`step`,delta:1};if(e===`ArrowDown`)return{kind:`step`,delta:-1};if(e===`ArrowRight`)return{kind:`step`,delta:t?-1:1};if(e===`ArrowLeft`)return{kind:`step`,delta:t?1:-1}}e.moveFor=p;function m(e,t,n,r){if(t.kind===`edge`)return t.delta>0?n.max:n.min;let i=t.kind===`page`?r:n.step;return e+t.delta*i}e.moved=m})(a||={});var o=a,s=`data-index`;function c(e,t,n){return{min:e,max:t,step:n}}function l(e,t){return t?{insetBlockEnd:e}:{insetInlineStart:e}}function u(e,t,n){let r=e.length>1?Math.min(...e):t.min,i=Math.max(...e),a=o.percent(r,t.min,t.max),s=`${Math.round((o.percent(i,t.min,t.max)-a)*100)/100}%`;return n?{insetBlockEnd:`${Math.round(a*100)/100}%`,blockSize:s}:{insetInlineStart:`${Math.round(a*100)/100}%`,inlineSize:s}}function d(a){let{value:d,defaultValue:f,onValueChange:p,onValueCommit:m,min:h=0,max:g=100,step:_=1,largeStep:v=_*10,orientation:y=`horizontal`,disabled:b=!1,label:x,labelledBy:S,thumbLabels:C,format:w,name:T,props:E,...D}=a,O=(0,r.useRef)(null),k=(0,r.useRef)(null),A=(0,r.useRef)(null),j=(0,r.useRef)(!1),[M,N]=(0,r.useState)(!1),[P,F]=n.i({value:d,defaultValue:f??h,onChange:p}),I=c(h,g,_),L=y===`vertical`,R=o.thumbs(P),z=n.o(P),B=n.a(m),V=n.a((e,t)=>{F(t=>o.same(o.thumbs(t),e)?t:o.shaped(t,e),t)}),H=t=>{let n=k.current;if(!n)return;let r=o.valueAt(n.getBoundingClientRect(),t.clientX,t.clientY,y,e.d(n));return h+r*(g-h)},U=e=>O.current?.querySelectorAll(`[role="slider"]`)[e],W=n.a(e=>{if(b||e.button!==0||e.defaultPrevented)return;let t=H(e);if(t===void 0)return;let n=o.thumbs(z.current),r=o.nearest(n,t);A.current=r,e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),U(r)?.focus(),V(o.move(n,r,t,I),{reason:`pointer`,event:e})}),G=n.a(e=>{let t=A.current;if(t===null)return;let n=H(e);n!==void 0&&(N(!0),V(o.move(o.thumbs(z.current),t,n,I),{reason:`pointer`,event:e}))}),K=n.a(e=>{A.current!==null&&(A.current=null,N(!1),e.currentTarget.releasePointerCapture?.(e.pointerId),B(z.current,{reason:`pointer`,event:e}))}),q=n.a(t=>{if(b||t.defaultPrevented)return;let n=t.target?.closest(`[role="slider"]`),r=Number(n?.getAttribute(s)??-1);if(!n||r<0)return;let i=o.moveFor(t.key,e.d(n));if(!i)return;t.preventDefault(),j.current=!0,N(!0);let a=o.thumbs(z.current);V(o.move(a,r,o.moved(a[r],i,I,v),I),{reason:`keyboard`,event:t})}),J=n.a(e=>{j.current&&(j.current=!1,N(!1),B(z.current,{reason:`keyboard`,event:e}))}),Y=R.length>1;return(0,i.jsxs)(t.default,{ref:O,component:`slider`,...D,variant:[D.variant,{vertical:L,disabled:b}],props:{role:Y?`group`:void 0,"aria-label":Y?x:void 0,"aria-labelledby":Y?S:void 0,...E,onPointerDown:W,onPointerMove:G,onPointerUp:K,onPointerCancel:K,onKeyDown:q,onKeyUp:J},children:[(0,i.jsx)(t.default,{ref:k,component:`slider.track`,variant:{vertical:L},children:(0,i.jsx)(t.default,{component:`slider.fill`,variant:{vertical:L,tracking:M},style:u(R,I,L)})}),R.map((e,n)=>(0,i.jsx)(t.default,{component:`slider.thumb`,variant:{vertical:L,disabled:b,tracking:M},style:l(o.percentage(e,h,g),L),props:{role:`slider`,tabIndex:b?-1:0,"aria-valuemin":h,"aria-valuemax":g,"aria-valuenow":e,"aria-valuetext":w?.(e),"aria-orientation":y,"aria-label":C?.[n]??(Y?void 0:x),"aria-labelledby":C?.[n]||Y?void 0:S,"aria-disabled":b||void 0,[s]:n}},n)),T!==void 0&&R.map((e,t)=>(0,i.jsx)(`input`,{type:`hidden`,name:T,value:e,readOnly:!0},t))]})}var f=d;f.displayName=`Slider`,exports.default=f;
|
package/components/slider.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../react-shared.cjs"),t=require("../effects.cjs"),n=require("../box.cjs"),r=require("../behavior.cjs"),i=require("./svg.cjs"),a=require("./visuallyHidden.cjs"),o=require("../scrolling.cjs"),s=require("./list.cjs");let c=require("react"),l=require("react/jsx-runtime");var u;(function(e){e.SLOP=4;function t(e){return e.top+e.height/2}function n(e,n,r){let i=e[n];if(!i)return n;let a=t(i)+r,o=n;if(r>0)for(let r=n+1;r<e.length&&a>t(e[r]);r++)o=r;else for(let r=n-1;r>=0&&a<t(e[r]);r--)o=r;return o}e.targetIndex=n;function r(e,t){let n=e[t];if(!n)return 0;let r=e.length>1?Math.max(0,e[1].top-e[0].top-e[0].height):0;return n.height+r}e.pitchOf=r;function i(e,t,n,i){return t<n&&i>t&&i<=n?-r(e,t):n<t&&i>=n&&i<t?r(e,t):0}e.shiftOf=i;function a(e,t,n){let r=e.slice();if(t===n||t<0||t>=r.length)return r;let[i]=r.splice(t,1);return r.splice(Math.max(0,Math.min(n,r.length)),0,i),r}e.move=a;function o(e,t,n){switch(e){case`ArrowUp`:return Math.max(0,t-1);case`ArrowDown`:return Math.min(n-1,t+1);case`Home`:return 0;case`End`:return n-1;default:return null}}e.keyTarget=o})(u||={});var d=u,f=(0,c.createContext)(null),p=(0,c.createContext)(null),m=48,h=12,g=`:scope > [data-sortable-value]`;function _(e){return e?Array.from(e.querySelectorAll(g)):[]}function v(e){return _(e).map(e=>e.dataset.sortableValue??``)}function y(e){return new Map(_(e).map(e=>[e.dataset.sortableValue??``,e.getBoundingClientRect().top]))}function b(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function x(e,n){let{onOrderChange:i,onOrderCommit:u,children:p,variant:g,props:x,...S}=e,C=(0,c.useRef)(null),w=(0,c.useRef)(null),T=(0,c.useRef)(null),[E,D]=(0,c.useState)(null),[O,k]=(0,c.useState)(0),[A,j]=(0,c.useState)(!1),[M,N]=(0,c.useState)(``),P=`${(0,c.useId)()}-sortable`,F=r.o(E),I=r.a(i),L=r.a(u),R=(0,c.useCallback)(e=>{C.current=e,typeof n==`function`?n(e):n&&(n.current=e)},[n]),z=(e,t)=>`position ${e.indexOf(t)+1} of ${e.length}`,B=(e,t)=>{T.current=y(C.current),I(e,t)};t.n(()=>{let e=T.current;if(e){T.current=null;for(let t of _(C.current)){let n=e.get(t.dataset.sortableValue??``),r=n===void 0?0:n-t.getBoundingClientRect().top,i=parseFloat(getComputedStyle(t).transitionDuration)*1e3||0;Math.abs(r)<1||i===0||typeof t.animate!=`function`||t.animate([{translate:`0 ${r}px`},{translate:`0 0`}],{duration:i,easing:`ease-out`})}}}),(0,c.useEffect)(()=>{if(!A)return;let e=requestAnimationFrame(()=>j(!1));return()=>cancelAnimationFrame(e)},[A]),t.n(()=>{if(!E||E.pointer)return;let e=_(C.current).find(e=>e.dataset.sortableValue===E.value)?.querySelector(`[data-sortable-handle]`);e&&e.ownerDocument.activeElement!==e&&e.focus()});let V=r.a((e,t)=>{let n=e.pointer,r=C.current;if(!n||!r)return;n.lastY=t;let i=t-r.getBoundingClientRect().top-(n.startY-n.startTop),a=n.order.indexOf(e.value);n.to=d.targetIndex(n.slots,a,i),k(i)}),H=(e,t)=>{let n=C.current;if(!n)return;let r=n.getBoundingClientRect().top,i=_(n),a=i.map(e=>e.dataset.sortableValue??``),o=i.map(e=>{let t=e.getBoundingClientRect();return{top:t.top-r,height:t.height}}),s={value:t.value,name:t.name,origin:a,pointer:{id:t.id,startY:t.y,startTop:r,lastY:e.clientY,slots:o,order:a,to:a.indexOf(t.value)}};D(s),V(s,e.clientY)},U=E?.pointer!==void 0;(0,c.useEffect)(()=>{if(!U)return;let e=o.t(C.current),t=0,n=()=>{let r=F.current;if(r?.pointer){let t=r.pointer.lastY,n=e?e.getBoundingClientRect().top:0,i=e?e.getBoundingClientRect().bottom:window.innerHeight,a=t<n+m?-12:t>i-m?h:0;a&&((e??window).scrollBy(0,a),V(r,t))}t=requestAnimationFrame(n)};return t=requestAnimationFrame(n),()=>cancelAnimationFrame(t)},[U,V,F]);let W=(e,t,n)=>{let r=v(C.current);D({value:e,name:t,origin:r}),N(`${t} picked up at ${z(r,e)}. Use the arrow keys to move it, Enter to drop it.`),n.preventDefault()},G=(e,t,n=v(C.current))=>{let r=n.indexOf(e.value);D(null),L(n,{reason:`keyboard`,event:t,value:e.value,from:e.origin.indexOf(e.value),to:r}),N(`${e.name} dropped at ${z(n,e.value)}.`)},K=r.a((e,t)=>{let n=v(C.current);D(null),k(0),b(n,e.origin)||B(e.origin,{reason:e.pointer?`pointer`:`keyboard`,event:t,value:e.value,from:n.indexOf(e.value),to:e.origin.indexOf(e.value)}),N(`${e.name} put back at ${z(e.origin,e.value)}.`)}),q=(e,t,n)=>{let r=v(C.current),i=r.indexOf(e.value);if(i<0||t===i)return r;let a=d.move(r,i,t);return B(a,{reason:`keyboard`,event:n,value:e.value,from:i,to:t}),N(`${e.name}, ${z(a,e.value)}.`),a},J=r.a((e,t,n)=>{e.button!==0||e.defaultPrevented||(e.preventDefault(),e.currentTarget.focus(),e.currentTarget.setPointerCapture?.(e.pointerId),w.current={id:e.pointerId,x:e.clientX,y:e.clientY,value:t,name:n})}),Y=r.a(e=>{let t=F.current;if(t?.pointer&&t.pointer.id===e.pointerId){V(t,e.clientY);return}let n=w.current;!n||n.id!==e.pointerId||Math.hypot(e.clientX-n.x,e.clientY-n.y)<d.SLOP||(w.current=null,H(e,n))}),X=r.a(e=>{let t=w.current;w.current=null;let n=F.current;if(t&&t.id===e.pointerId&&e.type===`pointerup`){n&&!n.pointer?n.value===t.value&&G(n,e):W(t.value,t.name,e);return}let r=n?.pointer;if(!n||!r||r.id!==e.pointerId)return;if(e.currentTarget.releasePointerCapture?.(e.pointerId),j(!0),e.type===`pointercancel`){T.current=y(C.current),K(n,e);return}let i=r.order.indexOf(n.value),a=d.move(r.order,i,r.to),o={reason:`pointer`,event:e,value:n.value,from:i,to:r.to};T.current=y(C.current),D(null),k(0),r.to!==i&&I(a,o),L(a,o),N(`${n.name} dropped at ${z(a,n.value)}.`)}),Z=r.a((e,t,n)=>{if(e.defaultPrevented)return;let r=F.current,i=r&&r.value===t&&!r.pointer?r:void 0;if(!i){(e.key===`Enter`||e.key===` `)&&W(t,n,e);return}if(e.key===`Escape`){e.preventDefault(),K(i,e);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),G(i,e);return}let a=v(C.current),o=d.keyTarget(e.key,a.indexOf(t),a.length);o!==null&&(e.preventDefault(),q(i,o,e))}),Q=r.a(e=>{setTimeout(()=>{let t=F.current,n=C.current;!t||t.pointer||t.value!==e||!n||n.ownerDocument.activeElement?.closest(`[data-sortable-value]`)?.getAttribute(`data-sortable-value`)!==e&&K(t,new Event(`blur`))})}),$=e=>{let t=F.current;if(!t||t.pointer||!(e.target instanceof Element))return null;let n=e.target.closest(`[data-sortable-value]`);return n&&n.parentElement===C.current&&n.dataset.sortableValue!==t.value?n:null},ee=e=>{$(e)&&e.preventDefault()},te=e=>{let t=$(e),n=F.current;!t||!n||(e.preventDefault(),e.stopPropagation(),G(n,e,q(n,v(C.current).indexOf(t.dataset.sortableValue??``),e)))},ne=(0,c.useMemo)(()=>{let e=E?.pointer,t=e?e.order.indexOf(E.value):-1;return{heldOf:e=>E&&E.value===e?E.pointer?`pointer`:`keyboard`:void 0,translateOf:n=>{if(!e)return;if(n===E.value)return`0 ${Math.round(O)}px`;let r=d.shiftOf(e.slots,t,e.to,e.order.indexOf(n));return r?`0 ${r}px`:void 0},settling:A,instructionsId:P,handleProps:(e,t)=>({type:`button`,"data-sortable-handle":``,"aria-label":`Move ${t}`,"aria-pressed":E?.value===e,"aria-describedby":P,onPointerDown:n=>J(n,e,t),onPointerMove:Y,onPointerUp:X,onPointerCancel:X,onKeyDown:n=>Z(n,e,t),onBlur:()=>Q(e)})}},[E,O,A,P,J,Y,X,Z,Q]);return(0,l.jsxs)(f.Provider,{value:ne,children:[(0,l.jsx)(s.default,{ref:R,...S,variant:g,userSelect:U?`none`:void 0,props:{...x,onMouseDownCapture:ee,onClickCapture:te},children:p}),(0,l.jsx)(a.default,{props:{role:`status`},children:M}),(0,l.jsx)(a.default,{id:P,children:`Press Enter or Space to pick the item up, the arrow keys to move it, Enter to drop it and Escape to put it back.`})]})}function S(e,t){let{value:n,label:r,disabled:i=!1,variant:a,props:o,...u}=e,d=(0,c.useContext)(f),m=d?.heldOf(n),h=d?.translateOf(n),g=(0,c.useMemo)(()=>({value:n,name:r??n,disabled:i}),[n,r,i]);return(0,l.jsx)(p.Provider,{value:g,children:(0,l.jsx)(s.default.Item,{ref:t,...u,variant:[a,{lifted:m===`pointer`,grabbed:m===`keyboard`,settling:d?.settling??!1}],style:h?{translate:h}:void 0,props:{...o,"data-sortable-value":n}})})}function C(){return(0,l.jsx)(i.Svg,{viewBox:`0 0 16 16`,width:`1rem`,fill:`currentColor`,children:[5,11].flatMap(e=>[3,8,13].map(t=>(0,l.jsx)(i.Circle,{cx:e,cy:t,r:1.4},`${e}-${t}`)))})}function w(e,t){let{children:r,variant:i,props:a,...o}=e,s=(0,c.useContext)(f),u=(0,c.useContext)(p),d=u&&s?s.handleProps(u.value,u.name):{};return n.useBoxElement({tag:`button`,component:`sortableList.handle`,display:`flex`,ai:`center`,jc:`center`,flexShrink:0,width:10,height:10,position:`relative`,zIndex:1,css:{touchAction:`none`},...o,variant:[i,{grabbed:u?s?.heldOf(u.value)!==void 0:!1}],props:{...d,...u?.disabled?{disabled:!0}:{},...a},children:r??(0,l.jsx)(C,{})},t)}var T=e.f(x,`SortableList`);T.Item=e.f(S,`SortableList.Item`),T.Handle=e.f(w,`SortableList.Handle`),exports.SortableUtils=d,exports.default=T;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RefAttributes } from 'react';
|
|
2
|
+
import { BoxProps } from '../box';
|
|
3
|
+
import { ChangeDetails, ChangeHandler } from '../react/a11y/useControllableState';
|
|
4
|
+
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
5
|
+
import { default as SortableUtils } from '../utils/sortable/sortableUtils';
|
|
6
|
+
import { ListItemProps, ListProps } from './list';
|
|
7
|
+
export { SortableUtils };
|
|
8
|
+
/** What moved an item. The device is the reason here, since a drag and the keyboard are told apart by what they announce. */
|
|
9
|
+
export type SortableReason = 'pointer' | 'keyboard';
|
|
10
|
+
export interface SortableChangeDetails extends ChangeDetails<SortableReason> {
|
|
11
|
+
/** The item that moved. */
|
|
12
|
+
value: string;
|
|
13
|
+
/** Where it was, and where it is now, as indices into the order. */
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
}
|
|
17
|
+
export interface SortableListProps<TKey extends keyof ComponentsAndVariants = 'list'> extends ListProps<TKey> {
|
|
18
|
+
/** The items: `SortableList.Item`s, each with a `value`, rendered in the order the app holds. */
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* The new order, as the items' `value`s. Fires once for a drop and on every step the keyboard takes, so the
|
|
22
|
+
* list moves as the arrows do. The app owns the order: render the items in it and the list follows.
|
|
23
|
+
*/
|
|
24
|
+
onOrderChange?: ChangeHandler<string[], SortableReason, SortableChangeDetails>;
|
|
25
|
+
/** The order once it has settled — a drop, or Enter after the arrows. The one to save. */
|
|
26
|
+
onOrderCommit?: ChangeHandler<string[], SortableReason, SortableChangeDetails>;
|
|
27
|
+
}
|
|
28
|
+
export interface SortableItemProps<TKey extends keyof ComponentsAndVariants = 'list.item'> extends ListItemProps<TKey> {
|
|
29
|
+
/** Who the item is in the order `onOrderChange` reports. Unique within the list. */
|
|
30
|
+
value: string;
|
|
31
|
+
/** What the handle and the announcements call the item: "Move Ada Lovelace". Defaults to `value`. */
|
|
32
|
+
label?: string;
|
|
33
|
+
/** Leaves the item where it is: its handle is disabled. Others may still move past it. */
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface SortableHandleProps<TKey extends keyof ComponentsAndVariants = 'sortableList.handle'> extends Omit<BoxProps<'button', TKey>, 'tag'> {
|
|
37
|
+
/** What the handle shows. Six dots unless given something else; its name is "Move" and the item's `label` either way. */
|
|
38
|
+
children?: React.ReactNode;
|
|
39
|
+
}
|
|
40
|
+
interface SortableListType {
|
|
41
|
+
<TKey extends keyof ComponentsAndVariants = 'list'>(props: SortableListProps<TKey> & RefAttributes<HTMLUListElement>): React.ReactNode;
|
|
42
|
+
/** One item in the order. Takes everything `List.Item` does, plus its `value`. */
|
|
43
|
+
Item: <TKey extends keyof ComponentsAndVariants = 'list.item'>(props: SortableItemProps<TKey> & RefAttributes<HTMLLIElement>) => React.ReactNode;
|
|
44
|
+
/** The button a drag starts from, and the one the keyboard picks the item up with. Six dots unless given children. */
|
|
45
|
+
Handle: <TKey extends keyof ComponentsAndVariants = 'sortableList.handle'>(props: SortableHandleProps<TKey> & RefAttributes<HTMLButtonElement>) => React.ReactNode;
|
|
46
|
+
displayName?: string;
|
|
47
|
+
}
|
|
48
|
+
declare const SortableList: SortableListType;
|
|
49
|
+
export default SortableList;
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { f as e } from "../react-shared.mjs";
|
|
3
|
+
import { n as t } from "../effects.mjs";
|
|
4
|
+
import { useBoxElement as n } from "../box.mjs";
|
|
5
|
+
import { a as r, o as i } from "../behavior.mjs";
|
|
6
|
+
import { Circle as a, Svg as o } from "./svg.mjs";
|
|
7
|
+
import s from "./visuallyHidden.mjs";
|
|
8
|
+
import { t as c } from "../scrolling.mjs";
|
|
9
|
+
import l from "./list.mjs";
|
|
10
|
+
import { createContext as u, useCallback as d, useContext as f, useEffect as p, useId as ee, useMemo as m, useRef as h, useState as g } from "react";
|
|
11
|
+
import { jsx as _, jsxs as te } from "react/jsx-runtime";
|
|
12
|
+
//#region src/utils/sortable/sortableUtils.ts
|
|
13
|
+
var v;
|
|
14
|
+
(function(e) {
|
|
15
|
+
e.SLOP = 4;
|
|
16
|
+
function t(e) {
|
|
17
|
+
return e.top + e.height / 2;
|
|
18
|
+
}
|
|
19
|
+
function n(e, n, r) {
|
|
20
|
+
let i = e[n];
|
|
21
|
+
if (!i) return n;
|
|
22
|
+
let a = t(i) + r, o = n;
|
|
23
|
+
if (r > 0) for (let r = n + 1; r < e.length && a > t(e[r]); r++) o = r;
|
|
24
|
+
else for (let r = n - 1; r >= 0 && a < t(e[r]); r--) o = r;
|
|
25
|
+
return o;
|
|
26
|
+
}
|
|
27
|
+
e.targetIndex = n;
|
|
28
|
+
function r(e, t) {
|
|
29
|
+
let n = e[t];
|
|
30
|
+
if (!n) return 0;
|
|
31
|
+
let r = e.length > 1 ? Math.max(0, e[1].top - e[0].top - e[0].height) : 0;
|
|
32
|
+
return n.height + r;
|
|
33
|
+
}
|
|
34
|
+
e.pitchOf = r;
|
|
35
|
+
function i(e, t, n, i) {
|
|
36
|
+
return t < n && i > t && i <= n ? -r(e, t) : n < t && i >= n && i < t ? r(e, t) : 0;
|
|
37
|
+
}
|
|
38
|
+
e.shiftOf = i;
|
|
39
|
+
function a(e, t, n) {
|
|
40
|
+
let r = e.slice();
|
|
41
|
+
if (t === n || t < 0 || t >= r.length) return r;
|
|
42
|
+
let [i] = r.splice(t, 1);
|
|
43
|
+
return r.splice(Math.max(0, Math.min(n, r.length)), 0, i), r;
|
|
44
|
+
}
|
|
45
|
+
e.move = a;
|
|
46
|
+
function o(e, t, n) {
|
|
47
|
+
switch (e) {
|
|
48
|
+
case "ArrowUp": return Math.max(0, t - 1);
|
|
49
|
+
case "ArrowDown": return Math.min(n - 1, t + 1);
|
|
50
|
+
case "Home": return 0;
|
|
51
|
+
case "End": return n - 1;
|
|
52
|
+
default: return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
e.keyTarget = o;
|
|
56
|
+
})(v ||= {});
|
|
57
|
+
var y = v, b = u(null), x = u(null), S = 48, ne = 12, C = ":scope > [data-sortable-value]";
|
|
58
|
+
function w(e) {
|
|
59
|
+
return e ? Array.from(e.querySelectorAll(C)) : [];
|
|
60
|
+
}
|
|
61
|
+
function T(e) {
|
|
62
|
+
return w(e).map((e) => e.dataset.sortableValue ?? "");
|
|
63
|
+
}
|
|
64
|
+
function E(e) {
|
|
65
|
+
return new Map(w(e).map((e) => [e.dataset.sortableValue ?? "", e.getBoundingClientRect().top]));
|
|
66
|
+
}
|
|
67
|
+
function re(e, t) {
|
|
68
|
+
return e.length === t.length && e.every((e, n) => e === t[n]);
|
|
69
|
+
}
|
|
70
|
+
function D(e, n) {
|
|
71
|
+
let { onOrderChange: a, onOrderCommit: o, children: u, variant: f, props: v, ...x } = e, C = h(null), D = h(null), O = h(null), [k, A] = g(null), [j, M] = g(0), [N, P] = g(!1), [ie, F] = g(""), I = `${ee()}-sortable`, L = i(k), R = r(a), z = r(o), ae = d((e) => {
|
|
72
|
+
C.current = e, typeof n == "function" ? n(e) : n && (n.current = e);
|
|
73
|
+
}, [n]), B = (e, t) => `position ${e.indexOf(t) + 1} of ${e.length}`, V = (e, t) => {
|
|
74
|
+
O.current = E(C.current), R(e, t);
|
|
75
|
+
};
|
|
76
|
+
t(() => {
|
|
77
|
+
let e = O.current;
|
|
78
|
+
if (e) {
|
|
79
|
+
O.current = null;
|
|
80
|
+
for (let t of w(C.current)) {
|
|
81
|
+
let n = e.get(t.dataset.sortableValue ?? ""), r = n === void 0 ? 0 : n - t.getBoundingClientRect().top, i = parseFloat(getComputedStyle(t).transitionDuration) * 1e3 || 0;
|
|
82
|
+
Math.abs(r) < 1 || i === 0 || typeof t.animate != "function" || t.animate([{ translate: `0 ${r}px` }, { translate: "0 0" }], {
|
|
83
|
+
duration: i,
|
|
84
|
+
easing: "ease-out"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}), p(() => {
|
|
89
|
+
if (!N) return;
|
|
90
|
+
let e = requestAnimationFrame(() => P(!1));
|
|
91
|
+
return () => cancelAnimationFrame(e);
|
|
92
|
+
}, [N]), t(() => {
|
|
93
|
+
if (!k || k.pointer) return;
|
|
94
|
+
let e = w(C.current).find((e) => e.dataset.sortableValue === k.value)?.querySelector("[data-sortable-handle]");
|
|
95
|
+
e && e.ownerDocument.activeElement !== e && e.focus();
|
|
96
|
+
});
|
|
97
|
+
let H = r((e, t) => {
|
|
98
|
+
let n = e.pointer, r = C.current;
|
|
99
|
+
if (!n || !r) return;
|
|
100
|
+
n.lastY = t;
|
|
101
|
+
let i = t - r.getBoundingClientRect().top - (n.startY - n.startTop), a = n.order.indexOf(e.value);
|
|
102
|
+
n.to = y.targetIndex(n.slots, a, i), M(i);
|
|
103
|
+
}), oe = (e, t) => {
|
|
104
|
+
let n = C.current;
|
|
105
|
+
if (!n) return;
|
|
106
|
+
let r = n.getBoundingClientRect().top, i = w(n), a = i.map((e) => e.dataset.sortableValue ?? ""), o = i.map((e) => {
|
|
107
|
+
let t = e.getBoundingClientRect();
|
|
108
|
+
return {
|
|
109
|
+
top: t.top - r,
|
|
110
|
+
height: t.height
|
|
111
|
+
};
|
|
112
|
+
}), s = {
|
|
113
|
+
value: t.value,
|
|
114
|
+
name: t.name,
|
|
115
|
+
origin: a,
|
|
116
|
+
pointer: {
|
|
117
|
+
id: t.id,
|
|
118
|
+
startY: t.y,
|
|
119
|
+
startTop: r,
|
|
120
|
+
lastY: e.clientY,
|
|
121
|
+
slots: o,
|
|
122
|
+
order: a,
|
|
123
|
+
to: a.indexOf(t.value)
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
A(s), H(s, e.clientY);
|
|
127
|
+
}, U = k?.pointer !== void 0;
|
|
128
|
+
p(() => {
|
|
129
|
+
if (!U) return;
|
|
130
|
+
let e = c(C.current), t = 0, n = () => {
|
|
131
|
+
let r = L.current;
|
|
132
|
+
if (r?.pointer) {
|
|
133
|
+
let t = r.pointer.lastY, n = e ? e.getBoundingClientRect().top : 0, i = e ? e.getBoundingClientRect().bottom : window.innerHeight, a = t < n + S ? -12 : t > i - S ? ne : 0;
|
|
134
|
+
a && ((e ?? window).scrollBy(0, a), H(r, t));
|
|
135
|
+
}
|
|
136
|
+
t = requestAnimationFrame(n);
|
|
137
|
+
};
|
|
138
|
+
return t = requestAnimationFrame(n), () => cancelAnimationFrame(t);
|
|
139
|
+
}, [
|
|
140
|
+
U,
|
|
141
|
+
H,
|
|
142
|
+
L
|
|
143
|
+
]);
|
|
144
|
+
let W = (e, t, n) => {
|
|
145
|
+
let r = T(C.current);
|
|
146
|
+
A({
|
|
147
|
+
value: e,
|
|
148
|
+
name: t,
|
|
149
|
+
origin: r
|
|
150
|
+
}), F(`${t} picked up at ${B(r, e)}. Use the arrow keys to move it, Enter to drop it.`), n.preventDefault();
|
|
151
|
+
}, G = (e, t, n = T(C.current)) => {
|
|
152
|
+
let r = n.indexOf(e.value);
|
|
153
|
+
A(null), z(n, {
|
|
154
|
+
reason: "keyboard",
|
|
155
|
+
event: t,
|
|
156
|
+
value: e.value,
|
|
157
|
+
from: e.origin.indexOf(e.value),
|
|
158
|
+
to: r
|
|
159
|
+
}), F(`${e.name} dropped at ${B(n, e.value)}.`);
|
|
160
|
+
}, K = r((e, t) => {
|
|
161
|
+
let n = T(C.current);
|
|
162
|
+
A(null), M(0), re(n, e.origin) || V(e.origin, {
|
|
163
|
+
reason: e.pointer ? "pointer" : "keyboard",
|
|
164
|
+
event: t,
|
|
165
|
+
value: e.value,
|
|
166
|
+
from: n.indexOf(e.value),
|
|
167
|
+
to: e.origin.indexOf(e.value)
|
|
168
|
+
}), F(`${e.name} put back at ${B(e.origin, e.value)}.`);
|
|
169
|
+
}), q = (e, t, n) => {
|
|
170
|
+
let r = T(C.current), i = r.indexOf(e.value);
|
|
171
|
+
if (i < 0 || t === i) return r;
|
|
172
|
+
let a = y.move(r, i, t);
|
|
173
|
+
return V(a, {
|
|
174
|
+
reason: "keyboard",
|
|
175
|
+
event: n,
|
|
176
|
+
value: e.value,
|
|
177
|
+
from: i,
|
|
178
|
+
to: t
|
|
179
|
+
}), F(`${e.name}, ${B(a, e.value)}.`), a;
|
|
180
|
+
}, J = r((e, t, n) => {
|
|
181
|
+
e.button !== 0 || e.defaultPrevented || (e.preventDefault(), e.currentTarget.focus(), e.currentTarget.setPointerCapture?.(e.pointerId), D.current = {
|
|
182
|
+
id: e.pointerId,
|
|
183
|
+
x: e.clientX,
|
|
184
|
+
y: e.clientY,
|
|
185
|
+
value: t,
|
|
186
|
+
name: n
|
|
187
|
+
});
|
|
188
|
+
}), Y = r((e) => {
|
|
189
|
+
let t = L.current;
|
|
190
|
+
if (t?.pointer && t.pointer.id === e.pointerId) {
|
|
191
|
+
H(t, e.clientY);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
let n = D.current;
|
|
195
|
+
!n || n.id !== e.pointerId || Math.hypot(e.clientX - n.x, e.clientY - n.y) < y.SLOP || (D.current = null, oe(e, n));
|
|
196
|
+
}), X = r((e) => {
|
|
197
|
+
let t = D.current;
|
|
198
|
+
D.current = null;
|
|
199
|
+
let n = L.current;
|
|
200
|
+
if (t && t.id === e.pointerId && e.type === "pointerup") {
|
|
201
|
+
n && !n.pointer ? n.value === t.value && G(n, e) : W(t.value, t.name, e);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let r = n?.pointer;
|
|
205
|
+
if (!n || !r || r.id !== e.pointerId) return;
|
|
206
|
+
if (e.currentTarget.releasePointerCapture?.(e.pointerId), P(!0), e.type === "pointercancel") {
|
|
207
|
+
O.current = E(C.current), K(n, e);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
let i = r.order.indexOf(n.value), a = y.move(r.order, i, r.to), o = {
|
|
211
|
+
reason: "pointer",
|
|
212
|
+
event: e,
|
|
213
|
+
value: n.value,
|
|
214
|
+
from: i,
|
|
215
|
+
to: r.to
|
|
216
|
+
};
|
|
217
|
+
O.current = E(C.current), A(null), M(0), r.to !== i && R(a, o), z(a, o), F(`${n.name} dropped at ${B(a, n.value)}.`);
|
|
218
|
+
}), Z = r((e, t, n) => {
|
|
219
|
+
if (e.defaultPrevented) return;
|
|
220
|
+
let r = L.current, i = r && r.value === t && !r.pointer ? r : void 0;
|
|
221
|
+
if (!i) {
|
|
222
|
+
(e.key === "Enter" || e.key === " ") && W(t, n, e);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (e.key === "Escape") {
|
|
226
|
+
e.preventDefault(), K(i, e);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
230
|
+
e.preventDefault(), G(i, e);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
let a = T(C.current), o = y.keyTarget(e.key, a.indexOf(t), a.length);
|
|
234
|
+
o !== null && (e.preventDefault(), q(i, o, e));
|
|
235
|
+
}), Q = r((e) => {
|
|
236
|
+
setTimeout(() => {
|
|
237
|
+
let t = L.current, n = C.current;
|
|
238
|
+
!t || t.pointer || t.value !== e || !n || n.ownerDocument.activeElement?.closest("[data-sortable-value]")?.getAttribute("data-sortable-value") !== e && K(t, new Event("blur"));
|
|
239
|
+
});
|
|
240
|
+
}), $ = (e) => {
|
|
241
|
+
let t = L.current;
|
|
242
|
+
if (!t || t.pointer || !(e.target instanceof Element)) return null;
|
|
243
|
+
let n = e.target.closest("[data-sortable-value]");
|
|
244
|
+
return n && n.parentElement === C.current && n.dataset.sortableValue !== t.value ? n : null;
|
|
245
|
+
}, se = (e) => {
|
|
246
|
+
$(e) && e.preventDefault();
|
|
247
|
+
}, ce = (e) => {
|
|
248
|
+
let t = $(e), n = L.current;
|
|
249
|
+
!t || !n || (e.preventDefault(), e.stopPropagation(), G(n, e, q(n, T(C.current).indexOf(t.dataset.sortableValue ?? ""), e)));
|
|
250
|
+
}, le = m(() => {
|
|
251
|
+
let e = k?.pointer, t = e ? e.order.indexOf(k.value) : -1;
|
|
252
|
+
return {
|
|
253
|
+
heldOf: (e) => k && k.value === e ? k.pointer ? "pointer" : "keyboard" : void 0,
|
|
254
|
+
translateOf: (n) => {
|
|
255
|
+
if (!e) return;
|
|
256
|
+
if (n === k.value) return `0 ${Math.round(j)}px`;
|
|
257
|
+
let r = y.shiftOf(e.slots, t, e.to, e.order.indexOf(n));
|
|
258
|
+
return r ? `0 ${r}px` : void 0;
|
|
259
|
+
},
|
|
260
|
+
settling: N,
|
|
261
|
+
instructionsId: I,
|
|
262
|
+
handleProps: (e, t) => ({
|
|
263
|
+
type: "button",
|
|
264
|
+
"data-sortable-handle": "",
|
|
265
|
+
"aria-label": `Move ${t}`,
|
|
266
|
+
"aria-pressed": k?.value === e,
|
|
267
|
+
"aria-describedby": I,
|
|
268
|
+
onPointerDown: (n) => J(n, e, t),
|
|
269
|
+
onPointerMove: Y,
|
|
270
|
+
onPointerUp: X,
|
|
271
|
+
onPointerCancel: X,
|
|
272
|
+
onKeyDown: (n) => Z(n, e, t),
|
|
273
|
+
onBlur: () => Q(e)
|
|
274
|
+
})
|
|
275
|
+
};
|
|
276
|
+
}, [
|
|
277
|
+
k,
|
|
278
|
+
j,
|
|
279
|
+
N,
|
|
280
|
+
I,
|
|
281
|
+
J,
|
|
282
|
+
Y,
|
|
283
|
+
X,
|
|
284
|
+
Z,
|
|
285
|
+
Q
|
|
286
|
+
]);
|
|
287
|
+
return /* @__PURE__ */ te(b.Provider, {
|
|
288
|
+
value: le,
|
|
289
|
+
children: [
|
|
290
|
+
/* @__PURE__ */ _(l, {
|
|
291
|
+
ref: ae,
|
|
292
|
+
...x,
|
|
293
|
+
variant: f,
|
|
294
|
+
userSelect: U ? "none" : void 0,
|
|
295
|
+
props: {
|
|
296
|
+
...v,
|
|
297
|
+
onMouseDownCapture: se,
|
|
298
|
+
onClickCapture: ce
|
|
299
|
+
},
|
|
300
|
+
children: u
|
|
301
|
+
}),
|
|
302
|
+
/* @__PURE__ */ _(s, {
|
|
303
|
+
props: { role: "status" },
|
|
304
|
+
children: ie
|
|
305
|
+
}),
|
|
306
|
+
/* @__PURE__ */ _(s, {
|
|
307
|
+
id: I,
|
|
308
|
+
children: "Press Enter or Space to pick the item up, the arrow keys to move it, Enter to drop it and Escape to put it back."
|
|
309
|
+
})
|
|
310
|
+
]
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function O(e, t) {
|
|
314
|
+
let { value: n, label: r, disabled: i = !1, variant: a, props: o, ...s } = e, c = f(b), u = c?.heldOf(n), d = c?.translateOf(n), p = m(() => ({
|
|
315
|
+
value: n,
|
|
316
|
+
name: r ?? n,
|
|
317
|
+
disabled: i
|
|
318
|
+
}), [
|
|
319
|
+
n,
|
|
320
|
+
r,
|
|
321
|
+
i
|
|
322
|
+
]);
|
|
323
|
+
return /* @__PURE__ */ _(x.Provider, {
|
|
324
|
+
value: p,
|
|
325
|
+
children: /* @__PURE__ */ _(l.Item, {
|
|
326
|
+
ref: t,
|
|
327
|
+
...s,
|
|
328
|
+
variant: [a, {
|
|
329
|
+
lifted: u === "pointer",
|
|
330
|
+
grabbed: u === "keyboard",
|
|
331
|
+
settling: c?.settling ?? !1
|
|
332
|
+
}],
|
|
333
|
+
style: d ? { translate: d } : void 0,
|
|
334
|
+
props: {
|
|
335
|
+
...o,
|
|
336
|
+
"data-sortable-value": n
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function k() {
|
|
342
|
+
return /* @__PURE__ */ _(o, {
|
|
343
|
+
viewBox: "0 0 16 16",
|
|
344
|
+
width: "1rem",
|
|
345
|
+
fill: "currentColor",
|
|
346
|
+
children: [5, 11].flatMap((e) => [
|
|
347
|
+
3,
|
|
348
|
+
8,
|
|
349
|
+
13
|
|
350
|
+
].map((t) => /* @__PURE__ */ _(a, {
|
|
351
|
+
cx: e,
|
|
352
|
+
cy: t,
|
|
353
|
+
r: 1.4
|
|
354
|
+
}, `${e}-${t}`)))
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
function A(e, t) {
|
|
358
|
+
let { children: r, variant: i, props: a, ...o } = e, s = f(b), c = f(x), l = c && s ? s.handleProps(c.value, c.name) : {};
|
|
359
|
+
return n({
|
|
360
|
+
tag: "button",
|
|
361
|
+
component: "sortableList.handle",
|
|
362
|
+
display: "flex",
|
|
363
|
+
ai: "center",
|
|
364
|
+
jc: "center",
|
|
365
|
+
flexShrink: 0,
|
|
366
|
+
width: 10,
|
|
367
|
+
height: 10,
|
|
368
|
+
position: "relative",
|
|
369
|
+
zIndex: 1,
|
|
370
|
+
css: { touchAction: "none" },
|
|
371
|
+
...o,
|
|
372
|
+
variant: [i, { grabbed: c ? s?.heldOf(c.value) !== void 0 : !1 }],
|
|
373
|
+
props: {
|
|
374
|
+
...l,
|
|
375
|
+
...c?.disabled ? { disabled: !0 } : {},
|
|
376
|
+
...a
|
|
377
|
+
},
|
|
378
|
+
children: r ?? /* @__PURE__ */ _(k, {})
|
|
379
|
+
}, t);
|
|
380
|
+
}
|
|
381
|
+
var j = e(D, "SortableList");
|
|
382
|
+
j.Item = e(O, "SortableList.Item"), j.Handle = e(A, "SortableList.Handle");
|
|
383
|
+
//#endregion
|
|
384
|
+
export { y as SortableUtils, j as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../react-shared.cjs"),t=require("../platform.cjs"),n=require("../effects.cjs"),r=require("../box.cjs"),i=require("../behavior.cjs"),a=require("../motion.cjs"),o=require("./list.cjs");let s=require("react"),c=require("react/jsx-runtime");var l;(function(e){let t=e.SLOP=8,n=e.FLICK=.4,r=e.FULL_RATIO=.6;function i(e,n){return Math.max(Math.abs(e),Math.abs(n))<t?null:Math.abs(e)>Math.abs(n)?`swipe`:`scroll`}e.intent=i;function a(e,t){return(1-1/(e*.55/t+1))*t}function o(e,t,n,r,i){let o=e+t,s=o<0?-1:1,c=o<0?n.end:n.start,l=Math.abs(o);return c===0?0:l<=c?o:i?s*Math.min(l,r):s*(c+a(l-c,Math.max(r,1)))}e.offsetFor=o;function s(e,n,i,a){if(!a||e===0)return null;let o=e>0?`start`:`end`,s=n[o];return s===0?null:Math.abs(e)>=Math.max(s+t*4,i*r)?o:null}e.armed=s;function c(e,t,r,i,a){let o=s(e,r,i,a);if(o)return{open:null,full:o};if(e===0)return{open:null,full:null};let c=e>0?`start`:`end`,l=r[c];return l===0?{open:null,full:null}:Math.abs(t)>=n?{open:Math.sign(t)===Math.sign(e)?c:null,full:null}:{open:Math.abs(e)>=l/2?c:null,full:null}}e.settle=c;let l=e.VELOCITY_WINDOW=100;function u(e,t){return[...e.filter(e=>t.t-e.t<=l),t]}e.track=u;function d(e){let t=e[0],n=e[e.length-1];return!t||!n||n.t-t.t<16?0:(n.x-t.x)/(n.t-t.t)}e.velocity=d;function f(e,t){return e===`start`?t.start:e===`end`?-t.end:0}e.restOffset=f})(l||={});var u=l,d=(0,s.createContext)(null),f={start:0,end:0};function p(e,l){let{size:p=`md`,wrap:g=!1,selected:_=!1,chevron:v=!1,startActions:y,endActions:b,fullSwipe:x=!1,open:S,defaultOpen:ee=null,onOpenChange:te,variant:ne,children:C,props:w,...T}=e,E=(0,s.useRef)(null),D=(0,s.useRef)(null),O=(0,s.useRef)(null),k=(0,s.useRef)(null),A=(0,s.useRef)(!1),[j,M]=i.i({value:S,defaultValue:ee,onChange:te}),[N,P]=(0,s.useState)(null),[F,I]=(0,s.useState)(null),[L,re]=(0,s.useState)({trays:f,width:0,rtl:!1}),R=i.o(L),z=(0,s.useCallback)(e=>{E.current=e,typeof l==`function`?l(e):l&&(l.current=e)},[l]),B=i.a(()=>{let e=e=>e?.firstElementChild?.offsetWidth??0,n={trays:{start:y?e(D.current):0,end:b?e(O.current):0},width:E.current?.offsetWidth??0,rtl:t.d(E.current)},r=R.current;return(r.trays.start!==n.trays.start||r.trays.end!==n.trays.end||r.width!==n.width||r.rtl!==n.rtl)&&re(n),n});n.n(()=>{j&&B()},[j,B]);let V=i.a(e=>M(null,e));(0,s.useEffect)(()=>{let e=t.t();if(!j||!e)return;let n=e=>{t.u(e,[E])||V({reason:`outside-pointer`,event:e})};return e.addEventListener(`pointerdown`,n,!0),()=>e.removeEventListener(`pointerdown`,n,!0)},[j,V]),(0,s.useEffect)(()=>{if(!F)return;let e=(F===`start`?D:O).current,t=E.current?.firstElementChild,n=t&&typeof getComputedStyle==`function`?a.n.activeDuration(getComputedStyle(t)):0,r=setTimeout(()=>{I(null),e?.querySelector(`[data-swipe-action]`)?.click()},n+a.n.SETTLE_FRAME);return()=>clearTimeout(r)},[F]);let H=i.a(e=>{if(A.current=!1,e.button!==0||F||!y&&!b)return;let{trays:t}=B();k.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,rest:u.restOffset(j,t),intent:null,samples:[{t:e.timeStamp,x:e.clientX}]}}),U=i.a(e=>{let n=k.current;if(!n||n.pointerId!==e.pointerId||n.intent===`scroll`)return;let r=e.clientX-n.x;if(!n.intent){if(n.intent=u.intent(r,e.clientY-n.y),n.intent!==`swipe`)return;e.currentTarget.setPointerCapture?.(e.pointerId),t.s(e.currentTarget)}let{trays:i,width:a,rtl:o}=R.current;n.samples=u.track(n.samples,{t:e.timeStamp,x:e.clientX}),P(u.offsetFor(n.rest,o?-r:r,i,a,x))}),W=i.a(e=>{let t=k.current;if(!t||t.pointerId!==e.pointerId||(k.current=null,t.intent!==`swipe`||N===null))return;e.currentTarget.releasePointerCapture?.(e.pointerId),A.current=!0;let{trays:n,width:r,rtl:i}=R.current,a=u.velocity(t.samples)*(i?-1:1),o=e.type===`pointercancel`?{open:j,full:null}:u.settle(N,a,n,r,x);P(null),o.full?(I(o.full),M(null,{reason:`swipe`,event:e})):M(o.open,{reason:`swipe`,event:e})}),G=i.a(e=>{if(A.current){A.current=!1,e.preventDefault(),e.stopPropagation();return}j&&(e.preventDefault(),e.stopPropagation(),V({reason:`outside-pointer`,event:e}))}),K=i.a(e=>{let t=D.current?.contains(e.target)?`start`:O.current?.contains(e.target)?`end`:null;t&&t!==j&&(B(),M(t,{reason:`focus`,event:e}))}),q=i.a(e=>{let t=e.relatedTarget;j&&(!t||!E.current?.contains(t))&&V({reason:`focus`,event:e})}),J=i.a(e=>{e.key!==`Escape`||!j||e.defaultPrevented||(e.preventDefault(),V({reason:`escape`,event:e}),E.current?.querySelector(`[data-list-action]`)?.focus())}),{trays:Y,width:X,rtl:ie}=L,Z=N??(F?F===`start`?X:-X:u.restOffset(j,Y)),ae=N===null?F:u.armed(N,Y,X,x),Q=N!==null,$=(e,t)=>(0,c.jsx)(h,{side:e,trayRef:e===`start`?D:O,width:e===`start`?Math.max(0,Z):Math.max(0,-Z),dragging:Q,children:(0,c.jsx)(d.Provider,{value:{side:e,armed:ae===e,close:V},children:t})});return r.useBoxElement({tag:`li`,component:`list.item`,...o.i({...o.t,css:{...o.t.css,overflow:`clip`}},T),variant:[ne,{selected:_}],props:{...w,onFocus:K,onBlur:q,onKeyDown:J},children:(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(m,{size:p,wrap:g,dragging:Q,translate:Z===0?void 0:`${Math.round(ie?-Z:Z)}px`,handlers:{onPointerDown:H,onPointerMove:U,onPointerUp:W,onPointerCancel:W,onClickCapture:G,onDragStart:e=>e.preventDefault()},children:[C,v&&(0,c.jsx)(o.default.Chevron,{})]}),y?$(`start`,y):null,b?$(`end`,b):null]})},z)}function m({size:e,wrap:t,dragging:n,translate:i,handlers:a,children:s}){return r.useBoxElement({component:`swipeItem.row`,...o.n,...o.r[e],...t?{flexWrap:`wrap`}:{},position:`relative`,css:{touchAction:`pan-y`},variant:{dragging:n},style:i?{translate:i}:void 0,props:a,children:s})}function h({side:e,trayRef:t,width:n,dragging:i,children:a}){let o=r.useBoxElement({display:`flex`,d:e===`end`?`row-reverse`:`row`,position:`absolute`,top:0,bottom:0,...e===`start`?{insetStart:0}:{insetEnd:0},minWidth:`fit`,css:{width:`max-content`},children:a});return r.useBoxElement({component:`swipeItem.tray`,position:`absolute`,top:0,bottom:0,...e===`start`?{insetStart:0}:{insetEnd:0},overflow:`hidden`,variant:{dragging:i},style:{width:`${Math.round(n)}px`},children:o},t)}function g(e,t){let{icon:n,onClick:i,closeOnSelect:a=!0,variant:o,children:l,props:u,...f}=e,p=(0,s.useContext)(d),m=e=>{i?.(e),a&&!e.defaultPrevented&&p?.close({reason:`action`,event:e})};return r.useBoxElement({tag:`button`,component:`swipeItem.action`,display:`flex`,d:`column`,ai:`center`,jc:`center`,gap:1,px:4,minWidth:18,flexGrow:1,flexShrink:0,fontSize:14,lineHeight:18,fontWeight:500,cursor:`pointer`,...f,variant:[o,{armed:p?.armed??!1}],props:{type:`button`,"data-swipe-action":``,...u,onClick:m},children:n?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(_,{children:n}),l]}):l},t)}function _({children:e}){return r.useBoxElement({tag:`span`,display:`flex`,props:{"aria-hidden":!0},children:e})}var v=e.f(p,`SwipeItem`);v.Action=e.f(g,`SwipeItem.Action`),exports.SwipeUtils=u,exports.default=v;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { RefAttributes } from 'react';
|
|
2
|
+
import { BoxProps } from '../box';
|
|
3
|
+
import { ChangeHandler } from '../react/a11y/useControllableState';
|
|
4
|
+
import { ComponentsAndVariants } from '@box-kite/core/types';
|
|
5
|
+
import { default as SwipeUtils, SwipeSide } from '../utils/swipe/swipeUtils';
|
|
6
|
+
import { ListItemSize } from './list/listItemParts';
|
|
7
|
+
export type { SwipeSide };
|
|
8
|
+
export { SwipeUtils };
|
|
9
|
+
/** Why a tray opened or closed. A swipe, focus reaching a tray's button, a press elsewhere, Escape, an action chosen. */
|
|
10
|
+
export type SwipeReason = 'swipe' | 'focus' | 'outside-pointer' | 'escape' | 'action';
|
|
11
|
+
export interface SwipeItemProps<TKey extends keyof ComponentsAndVariants = 'list.item'> extends Omit<BoxProps<'li', TKey>, 'open'> {
|
|
12
|
+
/** The item's parts, exactly as in a `List.Item`: `List.Media`, `List.Content`, `List.End`, `List.Actions`. */
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
/** `SwipeItem.Action`s under the inline start edge — a swipe towards the end of the line reveals them. The first is outermost. */
|
|
15
|
+
startActions?: React.ReactNode;
|
|
16
|
+
/** `SwipeItem.Action`s under the inline end edge — a swipe towards the start reveals them. The first is outermost. */
|
|
17
|
+
endActions?: React.ReactNode;
|
|
18
|
+
/** A swipe carried most of the way across performs the outermost action instead of stopping at the tray — iOS's archive. */
|
|
19
|
+
fullSwipe?: boolean;
|
|
20
|
+
/** Which tray is open. Controlled; `null` is closed. */
|
|
21
|
+
open?: SwipeSide | null;
|
|
22
|
+
/** Which tray is open to begin with. */
|
|
23
|
+
defaultOpen?: SwipeSide | null;
|
|
24
|
+
/** Which tray is open now, and why: a `swipe`, `focus`, an `outside-pointer` press, `escape`, or an `action` chosen. */
|
|
25
|
+
onOpenChange?: ChangeHandler<SwipeSide | null, SwipeReason>;
|
|
26
|
+
/** The item's spacing, as on `List.Item`. */
|
|
27
|
+
size?: ListItemSize;
|
|
28
|
+
/** Lets the item's parts wrap onto a second line, as on `List.Item`. */
|
|
29
|
+
wrap?: boolean;
|
|
30
|
+
/** Tints the item as chosen, as on `List.Item`. */
|
|
31
|
+
selected?: boolean;
|
|
32
|
+
/** Ends the item with a chevron, as on `List.Item`. */
|
|
33
|
+
chevron?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface SwipeActionProps<TKey extends keyof ComponentsAndVariants = 'swipeItem.action'> extends Omit<BoxProps<'button', TKey>, 'tag'> {
|
|
36
|
+
/** What it does, in a word: "Archive", "Delete". It is the button's name. */
|
|
37
|
+
children?: React.ReactNode;
|
|
38
|
+
/** An icon over the label. Decoration — the label names the button. */
|
|
39
|
+
icon?: React.ReactNode;
|
|
40
|
+
/** Runs the command. The tray closes after it unless `closeOnSelect` is `false`. */
|
|
41
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
42
|
+
/** Whether choosing the action closes the tray. Default `true`. */
|
|
43
|
+
closeOnSelect?: boolean;
|
|
44
|
+
}
|
|
45
|
+
interface SwipeItemType {
|
|
46
|
+
<TKey extends keyof ComponentsAndVariants = 'list.item'>(props: SwipeItemProps<TKey> & RefAttributes<HTMLLIElement>): React.ReactNode;
|
|
47
|
+
/** One command in a tray. `variant` is `accent`, `warning` or `danger`; unset, it is neutral. */
|
|
48
|
+
Action: <TKey extends keyof ComponentsAndVariants = 'swipeItem.action'>(props: SwipeActionProps<TKey> & RefAttributes<HTMLButtonElement>) => React.ReactNode;
|
|
49
|
+
displayName?: string;
|
|
50
|
+
}
|
|
51
|
+
declare const SwipeItem: SwipeItemType;
|
|
52
|
+
export default SwipeItem;
|