@os-design/drag-sort 1.0.4 → 1.0.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/dist/cjs/Droppable.js +4 -8
- package/dist/cjs/Droppable.js.map +1 -1
- package/dist/cjs/utils/ListStore.js +1 -1
- package/dist/cjs/utils/ListStore.js.map +1 -1
- package/dist/esm/Droppable.js +4 -8
- package/dist/esm/Droppable.js.map +1 -1
- package/dist/esm/utils/ListStore.js +1 -1
- package/dist/esm/utils/ListStore.js.map +1 -1
- package/dist/types/Droppable.d.ts +1 -1
- package/dist/types/Droppable.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/cjs/Droppable.js
CHANGED
|
@@ -95,16 +95,12 @@ var Droppable = function Droppable(_ref) {
|
|
|
95
95
|
onMouseDown: mouseDownHandler,
|
|
96
96
|
onTouchStart: touchStartHandler
|
|
97
97
|
});
|
|
98
|
-
var renderChildren = (0, _react.useCallback)(function () {
|
|
99
|
-
if (typeof children !== 'function') return children;
|
|
100
|
-
return children({
|
|
101
|
-
ref: ref,
|
|
102
|
-
innerRef: innerRef
|
|
103
|
-
});
|
|
104
|
-
}, [children]);
|
|
105
98
|
return /*#__PURE__*/_react["default"].createElement(_useDroppable.DroppableContext.Provider, {
|
|
106
99
|
value: droppableContext
|
|
107
|
-
},
|
|
100
|
+
}, children({
|
|
101
|
+
ref: ref,
|
|
102
|
+
innerRef: innerRef
|
|
103
|
+
}));
|
|
108
104
|
};
|
|
109
105
|
|
|
110
106
|
var _default = Droppable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Droppable.tsx"],"names":["Droppable","renderDraggedNode","id","horizontal","children","ref","innerRef","generatedId","droppableId","listRef","NodeList","current","registerList","deregisterList","onMouseDown","onTouchStart","listId","registerNode","props","add","deregisterNode","node","remove","mouseDownHandler","e","touchStartHandler","droppableContext"
|
|
1
|
+
{"version":3,"sources":["../../src/Droppable.tsx"],"names":["Droppable","renderDraggedNode","id","horizontal","children","ref","innerRef","generatedId","droppableId","listRef","NodeList","current","registerList","deregisterList","onMouseDown","onTouchStart","listId","registerNode","props","add","deregisterNode","node","remove","mouseDownHandler","e","touchStartHandler","droppableContext"],"mappings":";;;;;;;;;AAAA;;AASA;;AACA;;AAKA;;AACA;;AACA;;;;;;;;AAqCA,IAAMA,SAAmC,GAAG,SAAtCA,SAAsC,OAKtC;AAAA,MAJJC,iBAII,QAJJA,iBAII;AAAA,MAHJC,EAGI,QAHJA,EAGI;AAAA,6BAFJC,UAEI;AAAA,MAFJA,UAEI,gCAFS,KAET;AAAA,MADJC,QACI,QADJA,QACI;AACJ;AACA,MAAMC,GAAG,GAAG,mBAAuB,IAAvB,CAAZ,CAFI,CAGJ;;AACA,MAAMC,QAAQ,GAAG,mBAAuB,IAAvB,CAAjB,CAJI,CAKJ;;AACA,MAAMC,WAAW,GAAG,gCAAe,EAAf,CAApB;AACA,MAAMC,WAAW,GAAG,oBAAQ;AAAA,WAAMN,EAAE,IAAIK,WAAZ;AAAA,GAAR,EAAiC,CAACA,WAAD,EAAcL,EAAd,CAAjC,CAApB,CAPI,CAQJ;;AACA,MAAMO,OAAO,GAAG,mBACd,IAAIC,oBAAJ,CAAa;AACXR,IAAAA,EAAE,EAAEM,WADO;AAEXH,IAAAA,GAAG,EAAHA,GAFW;AAGXC,IAAAA,QAAQ,EAARA,QAHW;AAIXH,IAAAA,UAAU,EAAVA,UAJW;AAKXF,IAAAA,iBAAiB,EAAjBA;AALW,GAAb,CADc,CAAhB,CATI,CAmBJ;;AACA,wBAAU,YAAM;AACdQ,IAAAA,OAAO,CAACE,OAAR,CAAgBT,EAAhB,GAAqBM,WAArB;AACD,GAFD,EAEG,CAACA,WAAD,CAFH,EApBI,CAwBJ;AACA;;AACA,wBAAU,YAAM;AACdC,IAAAA,OAAO,CAACE,OAAR,CAAgBR,UAAhB,GAA6BA,UAA7B;AACD,GAFD,EAEG,CAACA,UAAD,CAFH,EA1BI,CA8BJ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D,CAJwB,CAA1B;AAOA,MAAMW,gBAAgB,GAAG,+BAAc;AACrCT,IAAAA,YAAY,EAAZA,YADqC;AAErCG,IAAAA,cAAc,EAAdA,cAFqC;AAGrCN,IAAAA,WAAW,EAAES,gBAHwB;AAIrCR,IAAAA,YAAY,EAAEU;AAJuB,GAAd,CAAzB;AAOA,sBACE,gCAAC,8BAAD,CAAkB,QAAlB;AAA2B,IAAA,KAAK,EAAEC;AAAlC,KACItB,QAAD,CAAuB;AAAEC,IAAAA,GAAG,EAAHA,GAAF;AAAOC,IAAAA,QAAQ,EAARA;AAAP,GAAvB,CADH,CADF;AAKD,CApFD;;eAsFeN,S","sourcesContent":["import React, {\n RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport useMemoObject from '@os-design/use-memo-object';\nimport NodeList, {\n ExistingNode,\n NodeProps,\n RenderDraggedNode,\n} from './utils/NodeList';\nimport useDragAndDrop from './utils/useDragAndDrop';\nimport { DroppableContext } from './utils/useDroppable';\nimport useGeneratedId from './utils/useGeneratedId';\n\nexport interface DroppableChildrenProps {\n /**\n * The reference to the list.\n * If a virtual list is used, pass it to the outerRef prop.\n */\n ref: RefObject<HTMLDivElement>;\n /**\n * The reference to the container inside the virtual list.\n * Pass it to the innerRef prop.\n */\n innerRef: RefObject<HTMLDivElement>;\n}\n\nexport interface DroppableProps {\n /**\n * The function that renders the dragged node.\n */\n renderDraggedNode: RenderDraggedNode;\n /**\n * The ID of the list with draggable nodes.\n * Used to determine in which list the dragged node was dropped.\n * @default undefined\n */\n id?: string;\n /**\n * Whether the list is horizontal.\n * @default false\n */\n horizontal?: boolean;\n /**\n * The function that renders the list with draggable nodes.\n */\n children: (props: DroppableChildrenProps) => React.ReactNode;\n}\n\nconst Droppable: React.FC<DroppableProps> = ({\n renderDraggedNode,\n id,\n horizontal = false,\n children,\n}) => {\n // The reference to the list\n const ref = useRef<HTMLDivElement>(null);\n // The reference to the container inside the virtual list\n const innerRef = useRef<HTMLDivElement>(null);\n // The unique ID of the list. If no ID was specified, the generated one is used.\n const generatedId = useGeneratedId(10);\n const droppableId = useMemo(() => id || generatedId, [generatedId, id]);\n // The reference to the list of nodes\n const listRef = useRef(\n new NodeList({\n id: droppableId,\n ref,\n innerRef,\n horizontal,\n renderDraggedNode,\n })\n );\n\n // Update the ID of the list if it changes\n useEffect(() => {\n listRef.current.id = droppableId;\n }, [droppableId]);\n\n // Update the list orientation if it changes.\n // There is no need to check the order of the nodes in the list because it will be the same.\n useEffect(() => {\n listRef.current.horizontal = horizontal;\n }, [horizontal]);\n\n // Update the callback that renders the dragged node if it changes\n useEffect(() => {\n listRef.current.renderDraggedNode = renderDraggedNode;\n }, [renderDraggedNode]);\n\n const { registerList, deregisterList, onMouseDown, onTouchStart } =\n useDragAndDrop();\n\n // Register the list in the store\n useEffect(() => {\n registerList(listRef.current);\n const listId = listRef.current.id;\n return () => deregisterList(listId);\n }, [deregisterList, registerList]);\n\n const registerNode = useCallback(\n (props: NodeProps) => listRef.current.add(props),\n []\n );\n const deregisterNode = useCallback((node: ExistingNode) => {\n listRef.current.remove(node);\n }, []);\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent, node: ExistingNode) => {\n onMouseDown(e, listRef.current, node);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent, node: ExistingNode) => {\n onTouchStart(e, listRef.current, node);\n },\n [onTouchStart]\n );\n\n const droppableContext = useMemoObject({\n registerNode,\n deregisterNode,\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n });\n\n return (\n <DroppableContext.Provider value={droppableContext}>\n {(children as Function)({ ref, innerRef })}\n </DroppableContext.Provider>\n );\n};\n\nexport default Droppable;\n"],"file":"Droppable.js"}
|
|
@@ -53,7 +53,7 @@ var ListStore = /*#__PURE__*/function () {
|
|
|
53
53
|
value: function findByPosition(x, y) {
|
|
54
54
|
return this.lists.find(function (list) {
|
|
55
55
|
var current = list.ref.current;
|
|
56
|
-
if (!current) return
|
|
56
|
+
if (!current) return false;
|
|
57
57
|
var rect = current.getBoundingClientRect();
|
|
58
58
|
return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
|
|
59
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/ListStore.ts"],"names":["ListStore","lists","list","push","id","index","findIndex","item","splice","x","y","find","current","ref","rect","getBoundingClientRect","width","height"],"mappings":";;;;;;;;;;;;;AAEA;AACA;AACA;IACMA,S;AAGJ,uBAAqB;AAAA;;AAAA,SAFbC,KAEa;AACnB,SAAKA,KAAL,GAAa,EAAb;AACD;AAED;AACF;AACA;;;;;WACE,aAAWC,IAAX,EAA2B;AACzB,WAAKD,KAAL,CAAWE,IAAX,CAAgBD,IAAhB;AACD;AAED;AACF;AACA;;;;WACE,gBAAcE,EAAd,EAA0B;AACxB,UAAMC,KAAK,GAAG,KAAKJ,KAAL,CAAWK,SAAX,CAAqB,UAACC,IAAD;AAAA,eAAUA,IAAI,CAACH,EAAL,KAAYA,EAAtB;AAAA,OAArB,CAAd;AACA,UAAIC,KAAK,KAAK,CAAC,CAAf,EAAkB;AAClB,WAAKJ,KAAL,CAAWO,MAAX,CAAkBH,KAAlB,EAAyB,CAAzB;AACD;AAED;AACF;AACA;;;;WACE,wBAAsBI,CAAtB,EAAiCC,CAAjC,EAA4C;AAC1C,aAAO,KAAKT,KAAL,CAAWU,IAAX,CAAgB,UAACT,IAAD,EAAU;AAC/B,YAAQU,OAAR,GAAoBV,IAAI,CAACW,GAAzB,CAAQD,OAAR;AACA,YAAI,CAACA,OAAL,EAAc,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/ListStore.ts"],"names":["ListStore","lists","list","push","id","index","findIndex","item","splice","x","y","find","current","ref","rect","getBoundingClientRect","width","height"],"mappings":";;;;;;;;;;;;;AAEA;AACA;AACA;IACMA,S;AAGJ,uBAAqB;AAAA;;AAAA,SAFbC,KAEa;AACnB,SAAKA,KAAL,GAAa,EAAb;AACD;AAED;AACF;AACA;;;;;WACE,aAAWC,IAAX,EAA2B;AACzB,WAAKD,KAAL,CAAWE,IAAX,CAAgBD,IAAhB;AACD;AAED;AACF;AACA;;;;WACE,gBAAcE,EAAd,EAA0B;AACxB,UAAMC,KAAK,GAAG,KAAKJ,KAAL,CAAWK,SAAX,CAAqB,UAACC,IAAD;AAAA,eAAUA,IAAI,CAACH,EAAL,KAAYA,EAAtB;AAAA,OAArB,CAAd;AACA,UAAIC,KAAK,KAAK,CAAC,CAAf,EAAkB;AAClB,WAAKJ,KAAL,CAAWO,MAAX,CAAkBH,KAAlB,EAAyB,CAAzB;AACD;AAED;AACF;AACA;;;;WACE,wBAAsBI,CAAtB,EAAiCC,CAAjC,EAA4C;AAC1C,aAAO,KAAKT,KAAL,CAAWU,IAAX,CAAgB,UAACT,IAAD,EAAU;AAC/B,YAAQU,OAAR,GAAoBV,IAAI,CAACW,GAAzB,CAAQD,OAAR;AACA,YAAI,CAACA,OAAL,EAAc,OAAO,KAAP;AACd,YAAME,IAAI,GAAGF,OAAO,CAACG,qBAAR,EAAb;AACA,eACEN,CAAC,IAAIK,IAAI,CAACL,CAAV,IACAA,CAAC,IAAIK,IAAI,CAACL,CAAL,GAASK,IAAI,CAACE,KADnB,IAEAN,CAAC,IAAII,IAAI,CAACJ,CAFV,IAGAA,CAAC,IAAII,IAAI,CAACJ,CAAL,GAASI,IAAI,CAACG,MAJrB;AAMD,OAVM,CAAP;AAWD;;;;;;eAGYjB,S","sourcesContent":["import NodeList from './NodeList';\n\n/**\n * Stores all the lists where the draggable items is located.\n */\nclass ListStore {\n private lists: NodeList[];\n\n public constructor() {\n this.lists = [];\n }\n\n /**\n * Adds a new list to the store.\n */\n public add(list: NodeList) {\n this.lists.push(list);\n }\n\n /**\n * Removes the list from the store.\n */\n public remove(id: string) {\n const index = this.lists.findIndex((item) => item.id === id);\n if (index === -1) return;\n this.lists.splice(index, 1);\n }\n\n /**\n * Returns the list in which the position is located.\n */\n public findByPosition(x: number, y: number) {\n return this.lists.find((list) => {\n const { current } = list.ref;\n if (!current) return false;\n const rect = current.getBoundingClientRect();\n return (\n x >= rect.x &&\n x <= rect.x + rect.width &&\n y >= rect.y &&\n y <= rect.y + rect.height\n );\n });\n }\n}\n\nexport default ListStore;\n"],"file":"ListStore.js"}
|
package/dist/esm/Droppable.js
CHANGED
|
@@ -68,16 +68,12 @@ const Droppable = ({
|
|
|
68
68
|
onMouseDown: mouseDownHandler,
|
|
69
69
|
onTouchStart: touchStartHandler
|
|
70
70
|
});
|
|
71
|
-
const renderChildren = useCallback(() => {
|
|
72
|
-
if (typeof children !== 'function') return children;
|
|
73
|
-
return children({
|
|
74
|
-
ref,
|
|
75
|
-
innerRef
|
|
76
|
-
});
|
|
77
|
-
}, [children]);
|
|
78
71
|
return /*#__PURE__*/React.createElement(DroppableContext.Provider, {
|
|
79
72
|
value: droppableContext
|
|
80
|
-
},
|
|
73
|
+
}, children({
|
|
74
|
+
ref,
|
|
75
|
+
innerRef
|
|
76
|
+
}));
|
|
81
77
|
};
|
|
82
78
|
|
|
83
79
|
export default Droppable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Droppable.tsx"],"names":["React","useCallback","useEffect","useMemo","useRef","useMemoObject","NodeList","useDragAndDrop","DroppableContext","useGeneratedId","Droppable","renderDraggedNode","id","horizontal","children","ref","innerRef","generatedId","droppableId","listRef","current","registerList","deregisterList","onMouseDown","onTouchStart","listId","registerNode","props","add","deregisterNode","node","remove","mouseDownHandler","e","touchStartHandler","droppableContext"
|
|
1
|
+
{"version":3,"sources":["../../src/Droppable.tsx"],"names":["React","useCallback","useEffect","useMemo","useRef","useMemoObject","NodeList","useDragAndDrop","DroppableContext","useGeneratedId","Droppable","renderDraggedNode","id","horizontal","children","ref","innerRef","generatedId","droppableId","listRef","current","registerList","deregisterList","onMouseDown","onTouchStart","listId","registerN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AArB,CAAZ;AACD,GAHkC,EAInC,CAACN,YAAD,CAJmC,CAArC;AAOA,QAAMW,gBAAgB,GAAG9B,aAAa,CAAC;AACrCqB,IAAAA,YADqC;AAErCG,IAAAA,cAFqC;AAGrCN,IAAAA,WAAW,EAAES,gBAHwB;AAIrCR,IAAAA,YAAY,EAAEU;AAJuB,GAAD,CAAtC;AAOA,sBACE,oBAAC,gBAAD,CAAkB,QAAlB;AAA2B,IAAA,KAAK,EAAEC;AAAlC,KACIrB,QAAD,CAAuB;AAAEC,IAAAA,GAAF;AAAOC,IAAAA;AAAP,GAAvB,CADH,CADF;AAKD,CApFD;;AAsFA,eAAeN,SAAf","sourcesContent":["import React, {\n RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport useMemoObject from '@os-design/use-memo-object';\nimport NodeList, {\n ExistingNode,\n NodeProps,\n RenderDraggedNode,\n} from './utils/NodeList';\nimport useDragAndDrop from './utils/useDragAndDrop';\nimport { DroppableContext } from './utils/useDroppable';\nimport useGeneratedId from './utils/useGeneratedId';\n\nexport interface DroppableChildrenProps {\n /**\n * The reference to the list.\n * If a virtual list is used, pass it to the outerRef prop.\n */\n ref: RefObject<HTMLDivElement>;\n /**\n * The reference to the container inside the virtual list.\n * Pass it to the innerRef prop.\n */\n innerRef: RefObject<HTMLDivElement>;\n}\n\nexport interface DroppableProps {\n /**\n * The function that renders the dragged node.\n */\n renderDraggedNode: RenderDraggedNode;\n /**\n * The ID of the list with draggable nodes.\n * Used to determine in which list the dragged node was dropped.\n * @default undefined\n */\n id?: string;\n /**\n * Whether the list is horizontal.\n * @default false\n */\n horizontal?: boolean;\n /**\n * The function that renders the list with draggable nodes.\n */\n children: (props: DroppableChildrenProps) => React.ReactNode;\n}\n\nconst Droppable: React.FC<DroppableProps> = ({\n renderDraggedNode,\n id,\n horizontal = false,\n children,\n}) => {\n // The reference to the list\n const ref = useRef<HTMLDivElement>(null);\n // The reference to the container inside the virtual list\n const innerRef = useRef<HTMLDivElement>(null);\n // The unique ID of the list. If no ID was specified, the generated one is used.\n const generatedId = useGeneratedId(10);\n const droppableId = useMemo(() => id || generatedId, [generatedId, id]);\n // The reference to the list of nodes\n const listRef = useRef(\n new NodeList({\n id: droppableId,\n ref,\n innerRef,\n horizontal,\n renderDraggedNode,\n })\n );\n\n // Update the ID of the list if it changes\n useEffect(() => {\n listRef.current.id = droppableId;\n }, [droppableId]);\n\n // Update the list orientation if it changes.\n // There is no need to check the order of the nodes in the list because it will be the same.\n useEffect(() => {\n listRef.current.horizontal = horizontal;\n }, [horizontal]);\n\n // Update the callback that renders the dragged node if it changes\n useEffect(() => {\n listRef.current.renderDraggedNode = renderDraggedNode;\n }, [renderDraggedNode]);\n\n const { registerList, deregisterList, onMouseDown, onTouchStart } =\n useDragAndDrop();\n\n // Register the list in the store\n useEffect(() => {\n registerList(listRef.current);\n const listId = listRef.current.id;\n return () => deregisterList(listId);\n }, [deregisterList, registerList]);\n\n const registerNode = useCallback(\n (props: NodeProps) => listRef.current.add(props),\n []\n );\n const deregisterNode = useCallback((node: ExistingNode) => {\n listRef.current.remove(node);\n }, []);\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent, node: ExistingNode) => {\n onMouseDown(e, listRef.current, node);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent, node: ExistingNode) => {\n onTouchStart(e, listRef.current, node);\n },\n [onTouchStart]\n );\n\n const droppableContext = useMemoObject({\n registerNode,\n deregisterNode,\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n });\n\n return (\n <DroppableContext.Provider value={droppableContext}>\n {(children as Function)({ ref, innerRef })}\n </DroppableContext.Provider>\n );\n};\n\nexport default Droppable;\n"],"file":"Droppable.js"}
|
|
@@ -34,7 +34,7 @@ class ListStore {
|
|
|
34
34
|
const {
|
|
35
35
|
current
|
|
36
36
|
} = list.ref;
|
|
37
|
-
if (!current) return
|
|
37
|
+
if (!current) return false;
|
|
38
38
|
const rect = current.getBoundingClientRect();
|
|
39
39
|
return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
|
|
40
40
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/ListStore.ts"],"names":["ListStore","constructor","lists","add","list","push","remove","id","index","findIndex","item","splice","findByPosition","x","y","find","current","ref","rect","getBoundingClientRect","width","height"],"mappings":"AAEA;AACA;AACA;AACA,MAAMA,SAAN,CAAgB;AAGPC,EAAAA,WAAW,GAAG;AAAA,SAFbC,KAEa;AACnB,SAAKA,KAAL,GAAa,EAAb;AACD;AAED;AACF;AACA;;;AACSC,EAAAA,GAAG,CAACC,IAAD,EAAiB;AACzB,SAAKF,KAAL,CAAWG,IAAX,CAAgBD,IAAhB;AACD;AAED;AACF;AACA;;;AACSE,EAAAA,MAAM,CAACC,EAAD,EAAa;AACxB,UAAMC,KAAK,GAAG,KAAKN,KAAL,CAAWO,SAAX,CAAsBC,IAAD,IAAUA,IAAI,CAACH,EAAL,KAAYA,EAA3C,CAAd;AACA,QAAIC,KAAK,KAAK,CAAC,CAAf,EAAkB;AAClB,SAAKN,KAAL,CAAWS,MAAX,CAAkBH,KAAlB,EAAyB,CAAzB;AACD;AAED;AACF;AACA;;;AACSI,EAAAA,cAAc,CAACC,CAAD,EAAYC,CAAZ,EAAuB;AAC1C,WAAO,KAAKZ,KAAL,CAAWa,IAAX,CAAiBX,IAAD,IAAU;AAC/B,YAAM;AAAEY,QAAAA;AAAF,UAAcZ,IAAI,CAACa,GAAzB;AACA,UAAI,CAACD,OAAL,EAAc,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/ListStore.ts"],"names":["ListStore","constructor","lists","add","list","push","remove","id","index","findIndex","item","splice","findByPosition","x","y","find","current","ref","rect","getBoundingClientRect","width","height"],"mappings":"AAEA;AACA;AACA;AACA,MAAMA,SAAN,CAAgB;AAGPC,EAAAA,WAAW,GAAG;AAAA,SAFbC,KAEa;AACnB,SAAKA,KAAL,GAAa,EAAb;AACD;AAED;AACF;AACA;;;AACSC,EAAAA,GAAG,CAACC,IAAD,EAAiB;AACzB,SAAKF,KAAL,CAAWG,IAAX,CAAgBD,IAAhB;AACD;AAED;AACF;AACA;;;AACSE,EAAAA,MAAM,CAACC,EAAD,EAAa;AACxB,UAAMC,KAAK,GAAG,KAAKN,KAAL,CAAWO,SAAX,CAAsBC,IAAD,IAAUA,IAAI,CAACH,EAAL,KAAYA,EAA3C,CAAd;AACA,QAAIC,KAAK,KAAK,CAAC,CAAf,EAAkB;AAClB,SAAKN,KAAL,CAAWS,MAAX,CAAkBH,KAAlB,EAAyB,CAAzB;AACD;AAED;AACF;AACA;;;AACSI,EAAAA,cAAc,CAACC,CAAD,EAAYC,CAAZ,EAAuB;AAC1C,WAAO,KAAKZ,KAAL,CAAWa,IAAX,CAAiBX,IAAD,IAAU;AAC/B,YAAM;AAAEY,QAAAA;AAAF,UAAcZ,IAAI,CAACa,GAAzB;AACA,UAAI,CAACD,OAAL,EAAc,OAAO,KAAP;AACd,YAAME,IAAI,GAAGF,OAAO,CAACG,qBAAR,EAAb;AACA,aACEN,CAAC,IAAIK,IAAI,CAACL,CAAV,IACAA,CAAC,IAAIK,IAAI,CAACL,CAAL,GAASK,IAAI,CAACE,KADnB,IAEAN,CAAC,IAAII,IAAI,CAACJ,CAFV,IAGAA,CAAC,IAAII,IAAI,CAACJ,CAAL,GAASI,IAAI,CAACG,MAJrB;AAMD,KAVM,CAAP;AAWD;;AAtCa;;AAyChB,eAAerB,SAAf","sourcesContent":["import NodeList from './NodeList';\n\n/**\n * Stores all the lists where the draggable items is located.\n */\nclass ListStore {\n private lists: NodeList[];\n\n public constructor() {\n this.lists = [];\n }\n\n /**\n * Adds a new list to the store.\n */\n public add(list: NodeList) {\n this.lists.push(list);\n }\n\n /**\n * Removes the list from the store.\n */\n public remove(id: string) {\n const index = this.lists.findIndex((item) => item.id === id);\n if (index === -1) return;\n this.lists.splice(index, 1);\n }\n\n /**\n * Returns the list in which the position is located.\n */\n public findByPosition(x: number, y: number) {\n return this.lists.find((list) => {\n const { current } = list.ref;\n if (!current) return false;\n const rect = current.getBoundingClientRect();\n return (\n x >= rect.x &&\n x <= rect.x + rect.width &&\n y >= rect.y &&\n y <= rect.y + rect.height\n );\n });\n }\n}\n\nexport default ListStore;\n"],"file":"ListStore.js"}
|
|
@@ -8,7 +8,7 @@ export interface DroppableProps {
|
|
|
8
8
|
renderDraggedNode: RenderDraggedNode;
|
|
9
9
|
id?: string;
|
|
10
10
|
horizontal?: boolean;
|
|
11
|
-
children:
|
|
11
|
+
children: (props: DroppableChildrenProps) => React.ReactNode;
|
|
12
12
|
}
|
|
13
13
|
declare const Droppable: React.FC<DroppableProps>;
|
|
14
14
|
export default Droppable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Droppable.d.ts","sourceRoot":"","sources":["../../src/Droppable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,SAAS,EAOV,MAAM,OAAO,CAAC;AAEf,OAAiB,EAGf,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAK1B,MAAM,WAAW,sBAAsB;IAKrC,GAAG,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAK/B,QAAQ,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,cAAc;IAI7B,iBAAiB,EAAE,iBAAiB,CAAC;IAMrC,EAAE,CAAC,EAAE,MAAM,CAAC;IAKZ,UAAU,CAAC,EAAE,OAAO,CAAC;IAIrB,QAAQ,
|
|
1
|
+
{"version":3,"file":"Droppable.d.ts","sourceRoot":"","sources":["../../src/Droppable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,SAAS,EAOV,MAAM,OAAO,CAAC;AAEf,OAAiB,EAGf,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAK1B,MAAM,WAAW,sBAAsB;IAKrC,GAAG,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAK/B,QAAQ,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,cAAc;IAI7B,iBAAiB,EAAE,iBAAiB,CAAC;IAMrC,EAAE,CAAC,EAAE,MAAM,CAAC;IAKZ,UAAU,CAAC,EAAE,OAAO,CAAC;IAIrB,QAAQ,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,KAAK,CAAC,SAAS,CAAC;CAC9D;AAED,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAoFvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@os-design/drag-sort",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": "git@gitlab.com:os-team/libs/os-design.git",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"react": ">=17",
|
|
46
46
|
"react-dom": ">=17"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "64269f60ac23373277a70d247145ff934f00948c"
|
|
49
49
|
}
|