@contember/react-repeater-dnd-kit 1.3.0-alpha.14
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/development/components/RepeaterSortable.cjs +55 -0
- package/dist/development/components/RepeaterSortable.cjs.map +1 -0
- package/dist/development/components/RepeaterSortable.js +55 -0
- package/dist/development/components/RepeaterSortable.js.map +1 -0
- package/dist/development/components/RepeaterSortableDragOverlay.cjs +17 -0
- package/dist/development/components/RepeaterSortableDragOverlay.cjs.map +1 -0
- package/dist/development/components/RepeaterSortableDragOverlay.js +17 -0
- package/dist/development/components/RepeaterSortableDragOverlay.js.map +1 -0
- package/dist/development/components/RepeaterSortableDropIndicator.cjs +14 -0
- package/dist/development/components/RepeaterSortableDropIndicator.cjs.map +1 -0
- package/dist/development/components/RepeaterSortableDropIndicator.js +14 -0
- package/dist/development/components/RepeaterSortableDropIndicator.js.map +1 -0
- package/dist/development/components/RepeaterSortableEachItem.cjs +20 -0
- package/dist/development/components/RepeaterSortableEachItem.cjs.map +1 -0
- package/dist/development/components/RepeaterSortableEachItem.js +20 -0
- package/dist/development/components/RepeaterSortableEachItem.js.map +1 -0
- package/dist/development/components/RepeaterSortableItemActivator.cjs +13 -0
- package/dist/development/components/RepeaterSortableItemActivator.cjs.map +1 -0
- package/dist/development/components/RepeaterSortableItemActivator.js +13 -0
- package/dist/development/components/RepeaterSortableItemActivator.js.map +1 -0
- package/dist/development/components/RepeaterSortableItemNode.cjs +11 -0
- package/dist/development/components/RepeaterSortableItemNode.cjs.map +1 -0
- package/dist/development/components/RepeaterSortableItemNode.js +11 -0
- package/dist/development/components/RepeaterSortableItemNode.js.map +1 -0
- package/dist/development/index.cjs +23 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +16 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/internal/contexts.cjs +10 -0
- package/dist/development/internal/contexts.cjs.map +1 -0
- package/dist/development/internal/contexts.js +10 -0
- package/dist/development/internal/contexts.js.map +1 -0
- package/dist/production/components/RepeaterSortable.cjs +55 -0
- package/dist/production/components/RepeaterSortable.cjs.map +1 -0
- package/dist/production/components/RepeaterSortable.js +55 -0
- package/dist/production/components/RepeaterSortable.js.map +1 -0
- package/dist/production/components/RepeaterSortableDragOverlay.cjs +17 -0
- package/dist/production/components/RepeaterSortableDragOverlay.cjs.map +1 -0
- package/dist/production/components/RepeaterSortableDragOverlay.js +17 -0
- package/dist/production/components/RepeaterSortableDragOverlay.js.map +1 -0
- package/dist/production/components/RepeaterSortableDropIndicator.cjs +14 -0
- package/dist/production/components/RepeaterSortableDropIndicator.cjs.map +1 -0
- package/dist/production/components/RepeaterSortableDropIndicator.js +14 -0
- package/dist/production/components/RepeaterSortableDropIndicator.js.map +1 -0
- package/dist/production/components/RepeaterSortableEachItem.cjs +20 -0
- package/dist/production/components/RepeaterSortableEachItem.cjs.map +1 -0
- package/dist/production/components/RepeaterSortableEachItem.js +20 -0
- package/dist/production/components/RepeaterSortableEachItem.js.map +1 -0
- package/dist/production/components/RepeaterSortableItemActivator.cjs +13 -0
- package/dist/production/components/RepeaterSortableItemActivator.cjs.map +1 -0
- package/dist/production/components/RepeaterSortableItemActivator.js +13 -0
- package/dist/production/components/RepeaterSortableItemActivator.js.map +1 -0
- package/dist/production/components/RepeaterSortableItemNode.cjs +11 -0
- package/dist/production/components/RepeaterSortableItemNode.cjs.map +1 -0
- package/dist/production/components/RepeaterSortableItemNode.js +11 -0
- package/dist/production/components/RepeaterSortableItemNode.js.map +1 -0
- package/dist/production/index.cjs +23 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +16 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/internal/contexts.cjs +10 -0
- package/dist/production/internal/contexts.cjs.map +1 -0
- package/dist/production/internal/contexts.js +10 -0
- package/dist/production/internal/contexts.js.map +1 -0
- package/dist/types/components/RepeaterSortable.d.ts +5 -0
- package/dist/types/components/RepeaterSortable.d.ts.map +1 -0
- package/dist/types/components/RepeaterSortableDragOverlay.d.ts +5 -0
- package/dist/types/components/RepeaterSortableDragOverlay.d.ts.map +1 -0
- package/dist/types/components/RepeaterSortableDropIndicator.d.ts +6 -0
- package/dist/types/components/RepeaterSortableDropIndicator.d.ts.map +1 -0
- package/dist/types/components/RepeaterSortableEachItem.d.ts +5 -0
- package/dist/types/components/RepeaterSortableEachItem.d.ts.map +1 -0
- package/dist/types/components/RepeaterSortableItemActivator.d.ts +5 -0
- package/dist/types/components/RepeaterSortableItemActivator.d.ts.map +1 -0
- package/dist/types/components/RepeaterSortableItemNode.d.ts +5 -0
- package/dist/types/components/RepeaterSortableItemNode.d.ts.map +1 -0
- package/dist/types/components/index.d.ts +7 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/internal/contexts.d.ts +53 -0
- package/dist/types/internal/contexts.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +60 -0
- package/src/components/RepeaterSortable.tsx +74 -0
- package/src/components/RepeaterSortableDragOverlay.tsx +26 -0
- package/src/components/RepeaterSortableDropIndicator.tsx +15 -0
- package/src/components/RepeaterSortableEachItem.tsx +35 -0
- package/src/components/RepeaterSortableItemActivator.tsx +11 -0
- package/src/components/RepeaterSortableItemNode.tsx +10 -0
- package/src/components/index.ts +6 -0
- package/src/index.ts +3 -0
- package/src/internal/contexts.ts +6 -0
- package/src/tsconfig.json +11 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const core = require("@dnd-kit/core");
|
|
6
|
+
const contexts = require("../internal/contexts.cjs");
|
|
7
|
+
const sortable = require("@dnd-kit/sortable");
|
|
8
|
+
const reactRepeater = require("@contember/react-repeater");
|
|
9
|
+
const RepeaterSortable = ({ children }) => {
|
|
10
|
+
const [activeId, setActiveId] = react.useState(null);
|
|
11
|
+
const { moveItem } = reactRepeater.useRepeaterMethods();
|
|
12
|
+
const entities = reactRepeater.useRepeaterSortedEntities();
|
|
13
|
+
const activeItem = react.useMemo(() => {
|
|
14
|
+
if (!activeId) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
return entities.find((it) => it.id === activeId);
|
|
18
|
+
}, [activeId, entities]);
|
|
19
|
+
const sensors = core.useSensors(
|
|
20
|
+
core.useSensor(core.MouseSensor),
|
|
21
|
+
core.useSensor(core.TouchSensor),
|
|
22
|
+
core.useSensor(core.KeyboardSensor)
|
|
23
|
+
);
|
|
24
|
+
const onDragCancel = () => {
|
|
25
|
+
setActiveId(null);
|
|
26
|
+
};
|
|
27
|
+
const onDragEnd = react.useCallback(({ active, over }) => {
|
|
28
|
+
setActiveId(null);
|
|
29
|
+
const activeEntity = entities.find((it) => it.id === active.id);
|
|
30
|
+
const overIndex = over ? entities.findIndex((it) => it.id === over.id) : void 0;
|
|
31
|
+
if (!activeEntity || overIndex === void 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
moveItem?.(activeEntity, overIndex);
|
|
35
|
+
}, [entities, moveItem]);
|
|
36
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
37
|
+
core.DndContext,
|
|
38
|
+
{
|
|
39
|
+
sensors,
|
|
40
|
+
measuring: {
|
|
41
|
+
droppable: {
|
|
42
|
+
strategy: core.MeasuringStrategy.Always
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
onDragStart: ({ active }) => {
|
|
46
|
+
setActiveId(active.id);
|
|
47
|
+
},
|
|
48
|
+
onDragEnd,
|
|
49
|
+
onDragCancel,
|
|
50
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(contexts.RepeaterActiveEntityContext.Provider, { value: activeItem, children: /* @__PURE__ */ jsxRuntime.jsx(sortable.SortableContext, { items: entities, strategy: sortable.verticalListSortingStrategy, children }) })
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
exports.RepeaterSortable = RepeaterSortable;
|
|
55
|
+
//# sourceMappingURL=RepeaterSortable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortable.cjs","sources":["../../../src/components/RepeaterSortable.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo, useState } from 'react'\nimport {\n\tDndContext,\n\tDragEndEvent,\n\tKeyboardSensor,\n\tMeasuringStrategy,\n\tMouseSensor,\n\tTouchSensor,\n\tUniqueIdentifier,\n\tuseSensor,\n\tuseSensors,\n} from '@dnd-kit/core'\nimport { RepeaterActiveEntityContext } from '../internal/contexts'\nimport { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'\nimport { useRepeaterSortedEntities } from '@contember/react-repeater'\nimport { useRepeaterMethods } from '@contember/react-repeater'\n\nexport const RepeaterSortable = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst [activeId, setActiveId] = useState<UniqueIdentifier | null>(null)\n\tconst { moveItem } = useRepeaterMethods()\n\tconst entities = useRepeaterSortedEntities()\n\n\n\tconst activeItem = useMemo(() => {\n\t\tif (!activeId) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn entities.find(it => it.id === activeId)\n\t}, [activeId, entities])\n\n\tconst sensors = useSensors(\n\t\tuseSensor(MouseSensor),\n\t\tuseSensor(TouchSensor),\n\t\tuseSensor(KeyboardSensor),\n\t)\n\n\tconst onDragCancel = () => {\n\t\tsetActiveId(null)\n\t}\n\n\tconst onDragEnd = useCallback(({ active, over }: DragEndEvent) => {\n\t\tsetActiveId(null)\n\t\tconst activeEntity = entities.find(it => it.id === active.id)\n\t\tconst overIndex = over ? entities.findIndex(it => it.id === over.id) : undefined\n\t\tif (!activeEntity || overIndex === undefined) {\n\t\t\treturn\n\t\t}\n\t\tmoveItem?.(activeEntity, overIndex)\n\t}, [entities, moveItem])\n\n\treturn (\n\t\t<DndContext\n\t\t\tsensors={sensors}\n\t\t\tmeasuring={{\n\t\t\t\tdroppable: {\n\t\t\t\t\tstrategy: MeasuringStrategy.Always,\n\t\t\t\t},\n\t\t\t}}\n\t\t\tonDragStart={({ active }) => {\n\t\t\t\tsetActiveId(active.id)\n\t\t\t}}\n\t\t\tonDragEnd={onDragEnd}\n\t\t\tonDragCancel={onDragCancel}\n\t\t>\n\t\t\t<RepeaterActiveEntityContext.Provider value={activeItem}>\n\t\t\t\t<SortableContext items={entities} strategy={verticalListSortingStrategy}>\n\t\t\t\t\t{children}\n\t\t\t\t</SortableContext>\n\t\t\t</RepeaterActiveEntityContext.Provider>\n\t\t</DndContext>\n\t)\n}\n"],"names":["useState","useRepeaterMethods","useRepeaterSortedEntities","useMemo","useSensors","useSensor","MouseSensor","TouchSensor","KeyboardSensor","useCallback","jsx","DndContext","MeasuringStrategy","RepeaterActiveEntityContext","SortableContext","verticalListSortingStrategy"],"mappings":";;;;;;;;AAiBO,MAAM,mBAAmB,CAAC,EAAE,eAE7B;AACL,QAAM,CAAC,UAAU,WAAW,IAAIA,eAAkC,IAAI;AAChE,QAAA,EAAE,aAAaC,cAAAA;AACrB,QAAM,WAAWC,cAAAA;AAGX,QAAA,aAAaC,MAAAA,QAAQ,MAAM;AAChC,QAAI,CAAC,UAAU;AACP,aAAA;AAAA,IACR;AACA,WAAO,SAAS,KAAK,CAAM,OAAA,GAAG,OAAO,QAAQ;AAAA,EAAA,GAC3C,CAAC,UAAU,QAAQ,CAAC;AAEvB,QAAM,UAAUC,KAAA;AAAA,IACfC,KAAAA,UAAUC,KAAAA,WAAW;AAAA,IACrBD,KAAAA,UAAUE,KAAAA,WAAW;AAAA,IACrBF,KAAAA,UAAUG,KAAAA,cAAc;AAAA,EAAA;AAGzB,QAAM,eAAe,MAAM;AAC1B,gBAAY,IAAI;AAAA,EAAA;AAGjB,QAAM,YAAYC,MAAY,YAAA,CAAC,EAAE,QAAQ,WAAyB;AACjE,gBAAY,IAAI;AAChB,UAAM,eAAe,SAAS,KAAK,QAAM,GAAG,OAAO,OAAO,EAAE;AACtD,UAAA,YAAY,OAAO,SAAS,UAAU,QAAM,GAAG,OAAO,KAAK,EAAE,IAAI;AACnE,QAAA,CAAC,gBAAgB,cAAc,QAAW;AAC7C;AAAA,IACD;AACA,eAAW,cAAc,SAAS;AAAA,EAAA,GAChC,CAAC,UAAU,QAAQ,CAAC;AAGtB,SAAAC,2BAAA;AAAA,IAACC,KAAA;AAAA,IAAA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACV,WAAW;AAAA,UACV,UAAUC,KAAkB,kBAAA;AAAA,QAC7B;AAAA,MACD;AAAA,MACA,aAAa,CAAC,EAAE,aAAa;AAC5B,oBAAY,OAAO,EAAE;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MAEA,UAACF,2BAAA,IAAAG,qCAA4B,UAA5B,EAAqC,OAAO,YAC5C,UAACH,2BAAAA,IAAAI,SAAAA,iBAAA,EAAgB,OAAO,UAAU,UAAUC,SAAAA,6BAC1C,SACF,CAAA,GACD;AAAA,IAAA;AAAA,EAAA;AAGH;;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useMemo, useCallback } from "react";
|
|
3
|
+
import { useSensors, useSensor, MouseSensor, TouchSensor, KeyboardSensor, DndContext, MeasuringStrategy } from "@dnd-kit/core";
|
|
4
|
+
import { RepeaterActiveEntityContext } from "../internal/contexts.js";
|
|
5
|
+
import { SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
6
|
+
import { useRepeaterMethods, useRepeaterSortedEntities } from "@contember/react-repeater";
|
|
7
|
+
const RepeaterSortable = ({ children }) => {
|
|
8
|
+
const [activeId, setActiveId] = useState(null);
|
|
9
|
+
const { moveItem } = useRepeaterMethods();
|
|
10
|
+
const entities = useRepeaterSortedEntities();
|
|
11
|
+
const activeItem = useMemo(() => {
|
|
12
|
+
if (!activeId) {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
return entities.find((it) => it.id === activeId);
|
|
16
|
+
}, [activeId, entities]);
|
|
17
|
+
const sensors = useSensors(
|
|
18
|
+
useSensor(MouseSensor),
|
|
19
|
+
useSensor(TouchSensor),
|
|
20
|
+
useSensor(KeyboardSensor)
|
|
21
|
+
);
|
|
22
|
+
const onDragCancel = () => {
|
|
23
|
+
setActiveId(null);
|
|
24
|
+
};
|
|
25
|
+
const onDragEnd = useCallback(({ active, over }) => {
|
|
26
|
+
setActiveId(null);
|
|
27
|
+
const activeEntity = entities.find((it) => it.id === active.id);
|
|
28
|
+
const overIndex = over ? entities.findIndex((it) => it.id === over.id) : void 0;
|
|
29
|
+
if (!activeEntity || overIndex === void 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
moveItem?.(activeEntity, overIndex);
|
|
33
|
+
}, [entities, moveItem]);
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
DndContext,
|
|
36
|
+
{
|
|
37
|
+
sensors,
|
|
38
|
+
measuring: {
|
|
39
|
+
droppable: {
|
|
40
|
+
strategy: MeasuringStrategy.Always
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
onDragStart: ({ active }) => {
|
|
44
|
+
setActiveId(active.id);
|
|
45
|
+
},
|
|
46
|
+
onDragEnd,
|
|
47
|
+
onDragCancel,
|
|
48
|
+
children: /* @__PURE__ */ jsx(RepeaterActiveEntityContext.Provider, { value: activeItem, children: /* @__PURE__ */ jsx(SortableContext, { items: entities, strategy: verticalListSortingStrategy, children }) })
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
RepeaterSortable
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=RepeaterSortable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortable.js","sources":["../../../src/components/RepeaterSortable.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo, useState } from 'react'\nimport {\n\tDndContext,\n\tDragEndEvent,\n\tKeyboardSensor,\n\tMeasuringStrategy,\n\tMouseSensor,\n\tTouchSensor,\n\tUniqueIdentifier,\n\tuseSensor,\n\tuseSensors,\n} from '@dnd-kit/core'\nimport { RepeaterActiveEntityContext } from '../internal/contexts'\nimport { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'\nimport { useRepeaterSortedEntities } from '@contember/react-repeater'\nimport { useRepeaterMethods } from '@contember/react-repeater'\n\nexport const RepeaterSortable = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst [activeId, setActiveId] = useState<UniqueIdentifier | null>(null)\n\tconst { moveItem } = useRepeaterMethods()\n\tconst entities = useRepeaterSortedEntities()\n\n\n\tconst activeItem = useMemo(() => {\n\t\tif (!activeId) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn entities.find(it => it.id === activeId)\n\t}, [activeId, entities])\n\n\tconst sensors = useSensors(\n\t\tuseSensor(MouseSensor),\n\t\tuseSensor(TouchSensor),\n\t\tuseSensor(KeyboardSensor),\n\t)\n\n\tconst onDragCancel = () => {\n\t\tsetActiveId(null)\n\t}\n\n\tconst onDragEnd = useCallback(({ active, over }: DragEndEvent) => {\n\t\tsetActiveId(null)\n\t\tconst activeEntity = entities.find(it => it.id === active.id)\n\t\tconst overIndex = over ? entities.findIndex(it => it.id === over.id) : undefined\n\t\tif (!activeEntity || overIndex === undefined) {\n\t\t\treturn\n\t\t}\n\t\tmoveItem?.(activeEntity, overIndex)\n\t}, [entities, moveItem])\n\n\treturn (\n\t\t<DndContext\n\t\t\tsensors={sensors}\n\t\t\tmeasuring={{\n\t\t\t\tdroppable: {\n\t\t\t\t\tstrategy: MeasuringStrategy.Always,\n\t\t\t\t},\n\t\t\t}}\n\t\t\tonDragStart={({ active }) => {\n\t\t\t\tsetActiveId(active.id)\n\t\t\t}}\n\t\t\tonDragEnd={onDragEnd}\n\t\t\tonDragCancel={onDragCancel}\n\t\t>\n\t\t\t<RepeaterActiveEntityContext.Provider value={activeItem}>\n\t\t\t\t<SortableContext items={entities} strategy={verticalListSortingStrategy}>\n\t\t\t\t\t{children}\n\t\t\t\t</SortableContext>\n\t\t\t</RepeaterActiveEntityContext.Provider>\n\t\t</DndContext>\n\t)\n}\n"],"names":[],"mappings":";;;;;;AAiBO,MAAM,mBAAmB,CAAC,EAAE,eAE7B;AACL,QAAM,CAAC,UAAU,WAAW,IAAI,SAAkC,IAAI;AAChE,QAAA,EAAE,aAAa;AACrB,QAAM,WAAW;AAGX,QAAA,aAAa,QAAQ,MAAM;AAChC,QAAI,CAAC,UAAU;AACP,aAAA;AAAA,IACR;AACA,WAAO,SAAS,KAAK,CAAM,OAAA,GAAG,OAAO,QAAQ;AAAA,EAAA,GAC3C,CAAC,UAAU,QAAQ,CAAC;AAEvB,QAAM,UAAU;AAAA,IACf,UAAU,WAAW;AAAA,IACrB,UAAU,WAAW;AAAA,IACrB,UAAU,cAAc;AAAA,EAAA;AAGzB,QAAM,eAAe,MAAM;AAC1B,gBAAY,IAAI;AAAA,EAAA;AAGjB,QAAM,YAAY,YAAY,CAAC,EAAE,QAAQ,WAAyB;AACjE,gBAAY,IAAI;AAChB,UAAM,eAAe,SAAS,KAAK,QAAM,GAAG,OAAO,OAAO,EAAE;AACtD,UAAA,YAAY,OAAO,SAAS,UAAU,QAAM,GAAG,OAAO,KAAK,EAAE,IAAI;AACnE,QAAA,CAAC,gBAAgB,cAAc,QAAW;AAC7C;AAAA,IACD;AACA,eAAW,cAAc,SAAS;AAAA,EAAA,GAChC,CAAC,UAAU,QAAQ,CAAC;AAGtB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACV,WAAW;AAAA,UACV,UAAU,kBAAkB;AAAA,QAC7B;AAAA,MACD;AAAA,MACA,aAAa,CAAC,EAAE,aAAa;AAC5B,oBAAY,OAAO,EAAE;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MAEA,UAAC,oBAAA,4BAA4B,UAA5B,EAAqC,OAAO,YAC5C,UAAC,oBAAA,iBAAA,EAAgB,OAAO,UAAU,UAAU,6BAC1C,SACF,CAAA,GACD;AAAA,IAAA;AAAA,EAAA;AAGH;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const contexts = require("../internal/contexts.cjs");
|
|
5
|
+
const reactPortal = require("@radix-ui/react-portal");
|
|
6
|
+
const core = require("@dnd-kit/core");
|
|
7
|
+
const reactBinding = require("@contember/react-binding");
|
|
8
|
+
const RepeaterSortableDragOverlay = ({ children }) => {
|
|
9
|
+
const activeItem = contexts.useRepeaterActiveEntity();
|
|
10
|
+
const accessorTreeState = reactBinding.useAccessorTreeState();
|
|
11
|
+
if (!activeItem) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactPortal.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(core.DragOverlay, { children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.AccessorTree, { state: accessorTreeState, children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Entity, { accessor: activeItem, children }) }) }) });
|
|
15
|
+
};
|
|
16
|
+
exports.RepeaterSortableDragOverlay = RepeaterSortableDragOverlay;
|
|
17
|
+
//# sourceMappingURL=RepeaterSortableDragOverlay.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableDragOverlay.cjs","sources":["../../../src/components/RepeaterSortableDragOverlay.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useRepeaterActiveEntity } from '../internal/contexts'\nimport { Portal } from '@radix-ui/react-portal'\nimport { DragOverlay } from '@dnd-kit/core'\nimport { AccessorTree, Entity, useAccessorTreeState } from '@contember/react-binding'\n\nexport const RepeaterSortableDragOverlay = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst activeItem = useRepeaterActiveEntity()\n\tconst accessorTreeState = useAccessorTreeState()\n\tif (!activeItem) {\n\t\treturn null\n\t}\n\treturn (\n\t\t<Portal>\n\t\t\t<DragOverlay>\n\t\t\t\t<AccessorTree state={accessorTreeState}>\n\t\t\t\t\t<Entity accessor={activeItem}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</Entity>\n\t\t\t\t</AccessorTree>\n\t\t\t</DragOverlay>\n\t\t</Portal>\n\t)\n}\n"],"names":["useRepeaterActiveEntity","useAccessorTreeState","jsx","Portal","DragOverlay","AccessorTree","Entity"],"mappings":";;;;;;;AAMO,MAAM,8BAA8B,CAAC,EAAE,eAExC;AACL,QAAM,aAAaA,SAAAA;AACnB,QAAM,oBAAoBC,aAAAA;AAC1B,MAAI,CAAC,YAAY;AACT,WAAA;AAAA,EACR;AACA,SACEC,+BAAAC,YAAAA,QAAA,EACA,UAACD,2BAAA,IAAAE,kBAAA,EACA,yCAACC,aAAa,cAAA,EAAA,OAAO,mBACpB,UAAAH,2BAAA,IAACI,uBAAO,UAAU,YAChB,SACF,CAAA,EACD,CAAA,GACD,EACD,CAAA;AAEF;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRepeaterActiveEntity } from "../internal/contexts.js";
|
|
3
|
+
import { Portal } from "@radix-ui/react-portal";
|
|
4
|
+
import { DragOverlay } from "@dnd-kit/core";
|
|
5
|
+
import { useAccessorTreeState, AccessorTree, Entity } from "@contember/react-binding";
|
|
6
|
+
const RepeaterSortableDragOverlay = ({ children }) => {
|
|
7
|
+
const activeItem = useRepeaterActiveEntity();
|
|
8
|
+
const accessorTreeState = useAccessorTreeState();
|
|
9
|
+
if (!activeItem) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(DragOverlay, { children: /* @__PURE__ */ jsx(AccessorTree, { state: accessorTreeState, children: /* @__PURE__ */ jsx(Entity, { accessor: activeItem, children }) }) }) });
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
RepeaterSortableDragOverlay
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=RepeaterSortableDragOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableDragOverlay.js","sources":["../../../src/components/RepeaterSortableDragOverlay.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useRepeaterActiveEntity } from '../internal/contexts'\nimport { Portal } from '@radix-ui/react-portal'\nimport { DragOverlay } from '@dnd-kit/core'\nimport { AccessorTree, Entity, useAccessorTreeState } from '@contember/react-binding'\n\nexport const RepeaterSortableDragOverlay = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst activeItem = useRepeaterActiveEntity()\n\tconst accessorTreeState = useAccessorTreeState()\n\tif (!activeItem) {\n\t\treturn null\n\t}\n\treturn (\n\t\t<Portal>\n\t\t\t<DragOverlay>\n\t\t\t\t<AccessorTree state={accessorTreeState}>\n\t\t\t\t\t<Entity accessor={activeItem}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</Entity>\n\t\t\t\t</AccessorTree>\n\t\t\t</DragOverlay>\n\t\t</Portal>\n\t)\n}\n"],"names":[],"mappings":";;;;;AAMO,MAAM,8BAA8B,CAAC,EAAE,eAExC;AACL,QAAM,aAAa;AACnB,QAAM,oBAAoB;AAC1B,MAAI,CAAC,YAAY;AACT,WAAA;AAAA,EACR;AACA,SACE,oBAAA,QAAA,EACA,UAAC,oBAAA,aAAA,EACA,8BAAC,cAAa,EAAA,OAAO,mBACpB,UAAA,oBAAC,UAAO,UAAU,YAChB,SACF,CAAA,EACD,CAAA,GACD,EACD,CAAA;AAEF;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const contexts = require("../internal/contexts.cjs");
|
|
5
|
+
const RepeaterSortableDropIndicator = ({ children, position }) => {
|
|
6
|
+
const sortable = contexts.useRepeaterSortableItem();
|
|
7
|
+
const isOver = sortable.isOver;
|
|
8
|
+
const activeSortable = sortable.active?.data.current?.sortable;
|
|
9
|
+
const isAfter = (sortable.data?.sortable.index ?? 0) > activeSortable?.index;
|
|
10
|
+
const renderedPosition = isAfter ? "after" : "before";
|
|
11
|
+
return renderedPosition === position && isOver ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }) : null;
|
|
12
|
+
};
|
|
13
|
+
exports.RepeaterSortableDropIndicator = RepeaterSortableDropIndicator;
|
|
14
|
+
//# sourceMappingURL=RepeaterSortableDropIndicator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableDropIndicator.cjs","sources":["../../../src/components/RepeaterSortableDropIndicator.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useRepeaterSortableItem } from '../internal/contexts'\n\nexport const RepeaterSortableDropIndicator = ({ children, position }: {\n\tchildren: ReactNode\n\tposition: 'before' | 'after'\n}) => {\n\tconst sortable = useRepeaterSortableItem()\n\tconst isOver = sortable.isOver\n\tconst activeSortable = sortable.active?.data.current?.sortable\n\tconst isAfter = (sortable.data?.sortable.index ?? 0) > activeSortable?.index\n\tconst renderedPosition = isAfter ? 'after' : 'before'\n\n\treturn renderedPosition === position && isOver ? <>{children}</> : null\n}\n"],"names":["useRepeaterSortableItem","jsx","Fragment"],"mappings":";;;;AAGO,MAAM,gCAAgC,CAAC,EAAE,UAAU,eAGpD;AACL,QAAM,WAAWA,SAAAA;AACjB,QAAM,SAAS,SAAS;AACxB,QAAM,iBAAiB,SAAS,QAAQ,KAAK,SAAS;AACtD,QAAM,WAAW,SAAS,MAAM,SAAS,SAAS,KAAK,gBAAgB;AACjE,QAAA,mBAAmB,UAAU,UAAU;AAE7C,SAAO,qBAAqB,YAAY,SAASC,2BAAAA,IAAAC,WAAAA,UAAA,EAAG,UAAS,IAAM;AACpE;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRepeaterSortableItem } from "../internal/contexts.js";
|
|
3
|
+
const RepeaterSortableDropIndicator = ({ children, position }) => {
|
|
4
|
+
const sortable = useRepeaterSortableItem();
|
|
5
|
+
const isOver = sortable.isOver;
|
|
6
|
+
const activeSortable = sortable.active?.data.current?.sortable;
|
|
7
|
+
const isAfter = (sortable.data?.sortable.index ?? 0) > activeSortable?.index;
|
|
8
|
+
const renderedPosition = isAfter ? "after" : "before";
|
|
9
|
+
return renderedPosition === position && isOver ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
RepeaterSortableDropIndicator
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=RepeaterSortableDropIndicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableDropIndicator.js","sources":["../../../src/components/RepeaterSortableDropIndicator.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useRepeaterSortableItem } from '../internal/contexts'\n\nexport const RepeaterSortableDropIndicator = ({ children, position }: {\n\tchildren: ReactNode\n\tposition: 'before' | 'after'\n}) => {\n\tconst sortable = useRepeaterSortableItem()\n\tconst isOver = sortable.isOver\n\tconst activeSortable = sortable.active?.data.current?.sortable\n\tconst isAfter = (sortable.data?.sortable.index ?? 0) > activeSortable?.index\n\tconst renderedPosition = isAfter ? 'after' : 'before'\n\n\treturn renderedPosition === position && isOver ? <>{children}</> : null\n}\n"],"names":[],"mappings":";;AAGO,MAAM,gCAAgC,CAAC,EAAE,UAAU,eAGpD;AACL,QAAM,WAAW;AACjB,QAAM,SAAS,SAAS;AACxB,QAAM,iBAAiB,SAAS,QAAQ,KAAK,SAAS;AACtD,QAAM,WAAW,SAAS,MAAM,SAAS,SAAS,KAAK,gBAAgB;AACjE,QAAA,mBAAmB,UAAU,UAAU;AAE7C,SAAO,qBAAqB,YAAY,SAAS,oBAAA,UAAA,EAAG,UAAS,IAAM;AACpE;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const sortable = require("@dnd-kit/sortable");
|
|
5
|
+
const reactRepeater = require("@contember/react-repeater");
|
|
6
|
+
const contexts = require("../internal/contexts.cjs");
|
|
7
|
+
const reactBinding = require("@contember/react-binding");
|
|
8
|
+
const RepeaterSortableEachItem = ({ children }) => {
|
|
9
|
+
const entities = reactRepeater.useRepeaterSortedEntities();
|
|
10
|
+
return /* @__PURE__ */ jsxRuntime.jsx(sortable.SortableContext, { items: entities, strategy: sortable.verticalListSortingStrategy, children: /* @__PURE__ */ jsxRuntime.jsx(reactRepeater.RepeaterEachItem, { children: /* @__PURE__ */ jsxRuntime.jsx(RepeaterSortableEachItemInner, { children }) }) });
|
|
11
|
+
};
|
|
12
|
+
const RepeaterSortableEachItemInner = ({ children }) => {
|
|
13
|
+
const entity = reactBinding.useEntity();
|
|
14
|
+
const sortable$1 = sortable.useSortable({
|
|
15
|
+
id: entity.id
|
|
16
|
+
});
|
|
17
|
+
return /* @__PURE__ */ jsxRuntime.jsx(contexts.RepeaterSortableItemContext.Provider, { value: sortable$1, children });
|
|
18
|
+
};
|
|
19
|
+
exports.RepeaterSortableEachItem = RepeaterSortableEachItem;
|
|
20
|
+
//# sourceMappingURL=RepeaterSortableEachItem.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableEachItem.cjs","sources":["../../../src/components/RepeaterSortableEachItem.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable'\nimport { RepeaterEachItem, useRepeaterSortedEntities } from '@contember/react-repeater'\nimport { RepeaterSortableItemContext } from '../internal/contexts'\nimport { useEntity } from '@contember/react-binding'\n\nexport const RepeaterSortableEachItem = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst entities = useRepeaterSortedEntities()\n\n\treturn (\n\t\t<SortableContext items={entities} strategy={verticalListSortingStrategy}>\n\t\t\t<RepeaterEachItem>\n\t\t\t\t<RepeaterSortableEachItemInner>\n\t\t\t\t\t{children}\n\t\t\t\t</RepeaterSortableEachItemInner>\n\n\t\t\t</RepeaterEachItem>\n\t\t</SortableContext>\n\t)\n}\nconst RepeaterSortableEachItemInner = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst entity = useEntity()\n\tconst sortable = useSortable({\n\t\tid: entity.id,\n\t})\n\treturn (\n\t\t<RepeaterSortableItemContext.Provider value={sortable}>\n\t\t\t{children}\n\t\t</RepeaterSortableItemContext.Provider>\n\t)\n}\n"],"names":["useRepeaterSortedEntities","jsx","SortableContext","verticalListSortingStrategy","RepeaterEachItem","useEntity","sortable","useSortable","RepeaterSortableItemContext"],"mappings":";;;;;;;AAMO,MAAM,2BAA2B,CAAC,EAAE,eAErC;AACL,QAAM,WAAWA,cAAAA;AAEjB,SACEC,2BAAAA,IAAAC,SAAAA,iBAAA,EAAgB,OAAO,UAAU,UAAUC,SAAA,6BAC3C,UAACF,2BAAAA,IAAAG,cAAAA,kBAAA,EACA,UAACH,2BAAAA,IAAA,+BAAA,EACC,UACF,EAAA,CAED,EACD,CAAA;AAEF;AACA,MAAM,gCAAgC,CAAC,EAAE,eAEnC;AACL,QAAM,SAASI,aAAAA;AACf,QAAMC,aAAWC,SAAAA,YAAY;AAAA,IAC5B,IAAI,OAAO;AAAA,EAAA,CACX;AACD,wCACEC,SAAAA,4BAA4B,UAA5B,EAAqC,OAAOF,YAC3C,SACF,CAAA;AAEF;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { SortableContext, verticalListSortingStrategy, useSortable } from "@dnd-kit/sortable";
|
|
3
|
+
import { useRepeaterSortedEntities, RepeaterEachItem } from "@contember/react-repeater";
|
|
4
|
+
import { RepeaterSortableItemContext } from "../internal/contexts.js";
|
|
5
|
+
import { useEntity } from "@contember/react-binding";
|
|
6
|
+
const RepeaterSortableEachItem = ({ children }) => {
|
|
7
|
+
const entities = useRepeaterSortedEntities();
|
|
8
|
+
return /* @__PURE__ */ jsx(SortableContext, { items: entities, strategy: verticalListSortingStrategy, children: /* @__PURE__ */ jsx(RepeaterEachItem, { children: /* @__PURE__ */ jsx(RepeaterSortableEachItemInner, { children }) }) });
|
|
9
|
+
};
|
|
10
|
+
const RepeaterSortableEachItemInner = ({ children }) => {
|
|
11
|
+
const entity = useEntity();
|
|
12
|
+
const sortable = useSortable({
|
|
13
|
+
id: entity.id
|
|
14
|
+
});
|
|
15
|
+
return /* @__PURE__ */ jsx(RepeaterSortableItemContext.Provider, { value: sortable, children });
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
RepeaterSortableEachItem
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=RepeaterSortableEachItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableEachItem.js","sources":["../../../src/components/RepeaterSortableEachItem.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable'\nimport { RepeaterEachItem, useRepeaterSortedEntities } from '@contember/react-repeater'\nimport { RepeaterSortableItemContext } from '../internal/contexts'\nimport { useEntity } from '@contember/react-binding'\n\nexport const RepeaterSortableEachItem = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst entities = useRepeaterSortedEntities()\n\n\treturn (\n\t\t<SortableContext items={entities} strategy={verticalListSortingStrategy}>\n\t\t\t<RepeaterEachItem>\n\t\t\t\t<RepeaterSortableEachItemInner>\n\t\t\t\t\t{children}\n\t\t\t\t</RepeaterSortableEachItemInner>\n\n\t\t\t</RepeaterEachItem>\n\t\t</SortableContext>\n\t)\n}\nconst RepeaterSortableEachItemInner = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst entity = useEntity()\n\tconst sortable = useSortable({\n\t\tid: entity.id,\n\t})\n\treturn (\n\t\t<RepeaterSortableItemContext.Provider value={sortable}>\n\t\t\t{children}\n\t\t</RepeaterSortableItemContext.Provider>\n\t)\n}\n"],"names":[],"mappings":";;;;;AAMO,MAAM,2BAA2B,CAAC,EAAE,eAErC;AACL,QAAM,WAAW;AAEjB,SACE,oBAAA,iBAAA,EAAgB,OAAO,UAAU,UAAU,6BAC3C,UAAC,oBAAA,kBAAA,EACA,UAAC,oBAAA,+BAAA,EACC,UACF,EAAA,CAED,EACD,CAAA;AAEF;AACA,MAAM,gCAAgC,CAAC,EAAE,eAEnC;AACL,QAAM,SAAS;AACf,QAAM,WAAW,YAAY;AAAA,IAC5B,IAAI,OAAO;AAAA,EAAA,CACX;AACD,6BACE,4BAA4B,UAA5B,EAAqC,OAAO,UAC3C,SACF,CAAA;AAEF;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const contexts = require("../internal/contexts.cjs");
|
|
6
|
+
const reactSlot = require("@radix-ui/react-slot");
|
|
7
|
+
const reactUtils = require("@contember/react-utils");
|
|
8
|
+
const RepeaterSortableItemActivator = react.forwardRef((props, ref) => {
|
|
9
|
+
const { setActivatorNodeRef, listeners } = contexts.useRepeaterSortableItem();
|
|
10
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactSlot.Slot, { ref: reactUtils.useComposeRef(ref, setActivatorNodeRef), ...listeners, ...props });
|
|
11
|
+
});
|
|
12
|
+
exports.RepeaterSortableItemActivator = RepeaterSortableItemActivator;
|
|
13
|
+
//# sourceMappingURL=RepeaterSortableItemActivator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableItemActivator.cjs","sources":["../../../src/components/RepeaterSortableItemActivator.tsx"],"sourcesContent":["import React, { forwardRef, ReactNode } from 'react'\nimport { useRepeaterSortableItem } from '../internal/contexts'\nimport { Slot } from '@radix-ui/react-slot'\nimport { useComposeRef } from '@contember/react-utils'\n\nexport const RepeaterSortableItemActivator = forwardRef<HTMLElement, {\n\tchildren: ReactNode\n}>((props, ref) => {\n\tconst { setActivatorNodeRef, listeners } = useRepeaterSortableItem()\n\treturn <Slot ref={useComposeRef(ref, setActivatorNodeRef)} {...listeners} {...props} />\n})\n"],"names":["forwardRef","useRepeaterSortableItem","jsx","Slot","useComposeRef"],"mappings":";;;;;;;AAKO,MAAM,gCAAgCA,MAAA,WAE1C,CAAC,OAAO,QAAQ;AAClB,QAAM,EAAE,qBAAqB,UAAU,IAAIC,SAAwB,wBAAA;AAC5D,SAAAC,+BAACC,UAAAA,MAAK,EAAA,KAAKC,WAAAA,cAAc,KAAK,mBAAmB,GAAI,GAAG,WAAY,GAAG,MAAO,CAAA;AACtF,CAAC;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { useRepeaterSortableItem } from "../internal/contexts.js";
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
5
|
+
import { useComposeRef } from "@contember/react-utils";
|
|
6
|
+
const RepeaterSortableItemActivator = forwardRef((props, ref) => {
|
|
7
|
+
const { setActivatorNodeRef, listeners } = useRepeaterSortableItem();
|
|
8
|
+
return /* @__PURE__ */ jsx(Slot, { ref: useComposeRef(ref, setActivatorNodeRef), ...listeners, ...props });
|
|
9
|
+
});
|
|
10
|
+
export {
|
|
11
|
+
RepeaterSortableItemActivator
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=RepeaterSortableItemActivator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableItemActivator.js","sources":["../../../src/components/RepeaterSortableItemActivator.tsx"],"sourcesContent":["import React, { forwardRef, ReactNode } from 'react'\nimport { useRepeaterSortableItem } from '../internal/contexts'\nimport { Slot } from '@radix-ui/react-slot'\nimport { useComposeRef } from '@contember/react-utils'\n\nexport const RepeaterSortableItemActivator = forwardRef<HTMLElement, {\n\tchildren: ReactNode\n}>((props, ref) => {\n\tconst { setActivatorNodeRef, listeners } = useRepeaterSortableItem()\n\treturn <Slot ref={useComposeRef(ref, setActivatorNodeRef)} {...listeners} {...props} />\n})\n"],"names":[],"mappings":";;;;;AAKO,MAAM,gCAAgC,WAE1C,CAAC,OAAO,QAAQ;AAClB,QAAM,EAAE,qBAAqB,UAAU,IAAI,wBAAwB;AAC5D,SAAA,oBAAC,MAAK,EAAA,KAAK,cAAc,KAAK,mBAAmB,GAAI,GAAG,WAAY,GAAG,MAAO,CAAA;AACtF,CAAC;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const contexts = require("../internal/contexts.cjs");
|
|
5
|
+
const reactSlot = require("@radix-ui/react-slot");
|
|
6
|
+
const RepeaterSortableItemNode = ({ children }) => {
|
|
7
|
+
const { setNodeRef } = contexts.useRepeaterSortableItem();
|
|
8
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactSlot.Slot, { ref: setNodeRef, children });
|
|
9
|
+
};
|
|
10
|
+
exports.RepeaterSortableItemNode = RepeaterSortableItemNode;
|
|
11
|
+
//# sourceMappingURL=RepeaterSortableItemNode.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableItemNode.cjs","sources":["../../../src/components/RepeaterSortableItemNode.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useRepeaterSortableItem } from '../internal/contexts'\nimport { Slot } from '@radix-ui/react-slot'\n\nexport const RepeaterSortableItemNode = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst { setNodeRef } = useRepeaterSortableItem()\n\treturn <Slot ref={setNodeRef}>{children}</Slot>\n}\n"],"names":["useRepeaterSortableItem","jsx","Slot"],"mappings":";;;;;AAIO,MAAM,2BAA2B,CAAC,EAAE,eAErC;AACC,QAAA,EAAE,eAAeA,SAAAA;AACvB,SAAQC,2BAAAA,IAAAC,UAAAA,MAAA,EAAK,KAAK,YAAa,SAAS,CAAA;AACzC;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRepeaterSortableItem } from "../internal/contexts.js";
|
|
3
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
4
|
+
const RepeaterSortableItemNode = ({ children }) => {
|
|
5
|
+
const { setNodeRef } = useRepeaterSortableItem();
|
|
6
|
+
return /* @__PURE__ */ jsx(Slot, { ref: setNodeRef, children });
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
RepeaterSortableItemNode
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=RepeaterSortableItemNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableItemNode.js","sources":["../../../src/components/RepeaterSortableItemNode.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useRepeaterSortableItem } from '../internal/contexts'\nimport { Slot } from '@radix-ui/react-slot'\n\nexport const RepeaterSortableItemNode = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst { setNodeRef } = useRepeaterSortableItem()\n\treturn <Slot ref={setNodeRef}>{children}</Slot>\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,2BAA2B,CAAC,EAAE,eAErC;AACC,QAAA,EAAE,eAAe;AACvB,SAAQ,oBAAA,MAAA,EAAK,KAAK,YAAa,SAAS,CAAA;AACzC;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const reactRepeater = require("@contember/react-repeater");
|
|
4
|
+
const RepeaterSortable = require("./components/RepeaterSortable.cjs");
|
|
5
|
+
const RepeaterSortableDragOverlay = require("./components/RepeaterSortableDragOverlay.cjs");
|
|
6
|
+
const RepeaterSortableDropIndicator = require("./components/RepeaterSortableDropIndicator.cjs");
|
|
7
|
+
const RepeaterSortableItemActivator = require("./components/RepeaterSortableItemActivator.cjs");
|
|
8
|
+
const RepeaterSortableItemNode = require("./components/RepeaterSortableItemNode.cjs");
|
|
9
|
+
const RepeaterSortableEachItem = require("./components/RepeaterSortableEachItem.cjs");
|
|
10
|
+
exports.RepeaterSortable = RepeaterSortable.RepeaterSortable;
|
|
11
|
+
exports.RepeaterSortableDragOverlay = RepeaterSortableDragOverlay.RepeaterSortableDragOverlay;
|
|
12
|
+
exports.RepeaterSortableDropIndicator = RepeaterSortableDropIndicator.RepeaterSortableDropIndicator;
|
|
13
|
+
exports.RepeaterSortableItemActivator = RepeaterSortableItemActivator.RepeaterSortableItemActivator;
|
|
14
|
+
exports.RepeaterSortableItemNode = RepeaterSortableItemNode.RepeaterSortableItemNode;
|
|
15
|
+
exports.RepeaterSortableEachItem = RepeaterSortableEachItem.RepeaterSortableEachItem;
|
|
16
|
+
Object.keys(reactRepeater).forEach((k) => {
|
|
17
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
|
|
18
|
+
Object.defineProperty(exports, k, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => reactRepeater[k]
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "@contember/react-repeater";
|
|
2
|
+
import { RepeaterSortable } from "./components/RepeaterSortable.js";
|
|
3
|
+
import { RepeaterSortableDragOverlay } from "./components/RepeaterSortableDragOverlay.js";
|
|
4
|
+
import { RepeaterSortableDropIndicator } from "./components/RepeaterSortableDropIndicator.js";
|
|
5
|
+
import { RepeaterSortableItemActivator } from "./components/RepeaterSortableItemActivator.js";
|
|
6
|
+
import { RepeaterSortableItemNode } from "./components/RepeaterSortableItemNode.js";
|
|
7
|
+
import { RepeaterSortableEachItem } from "./components/RepeaterSortableEachItem.js";
|
|
8
|
+
export {
|
|
9
|
+
RepeaterSortable,
|
|
10
|
+
RepeaterSortableDragOverlay,
|
|
11
|
+
RepeaterSortableDropIndicator,
|
|
12
|
+
RepeaterSortableEachItem,
|
|
13
|
+
RepeaterSortableItemActivator,
|
|
14
|
+
RepeaterSortableItemNode
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const reactUtils = require("@contember/react-utils");
|
|
4
|
+
const [RepeaterSortableItemContext, useRepeaterSortableItem] = reactUtils.createRequiredContext("RepeaterSortableItemContext");
|
|
5
|
+
const [RepeaterActiveEntityContext, useRepeaterActiveEntity] = reactUtils.createContext("RepeaterActiveEntityContext", void 0);
|
|
6
|
+
exports.RepeaterActiveEntityContext = RepeaterActiveEntityContext;
|
|
7
|
+
exports.RepeaterSortableItemContext = RepeaterSortableItemContext;
|
|
8
|
+
exports.useRepeaterActiveEntity = useRepeaterActiveEntity;
|
|
9
|
+
exports.useRepeaterSortableItem = useRepeaterSortableItem;
|
|
10
|
+
//# sourceMappingURL=contexts.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contexts.cjs","sources":["../../../src/internal/contexts.ts"],"sourcesContent":["import { createRequiredContext, createContext } from '@contember/react-utils'\nimport { EntityAccessor } from '@contember/react-binding'\nimport { useSortable } from '@dnd-kit/sortable'\n\nexport const [RepeaterSortableItemContext, useRepeaterSortableItem] = createRequiredContext<ReturnType<typeof useSortable>>('RepeaterSortableItemContext')\nexport const [RepeaterActiveEntityContext, useRepeaterActiveEntity] = createContext<EntityAccessor | undefined>('RepeaterActiveEntityContext', undefined)\n"],"names":["createRequiredContext","createContext"],"mappings":";;;AAIO,MAAM,CAAC,6BAA6B,uBAAuB,IAAIA,WAAAA,sBAAsD,6BAA6B;AAClJ,MAAM,CAAC,6BAA6B,uBAAuB,IAAIC,WAAAA,cAA0C,+BAA+B,MAAS;;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createRequiredContext, createContext } from "@contember/react-utils";
|
|
2
|
+
const [RepeaterSortableItemContext, useRepeaterSortableItem] = createRequiredContext("RepeaterSortableItemContext");
|
|
3
|
+
const [RepeaterActiveEntityContext, useRepeaterActiveEntity] = createContext("RepeaterActiveEntityContext", void 0);
|
|
4
|
+
export {
|
|
5
|
+
RepeaterActiveEntityContext,
|
|
6
|
+
RepeaterSortableItemContext,
|
|
7
|
+
useRepeaterActiveEntity,
|
|
8
|
+
useRepeaterSortableItem
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=contexts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contexts.js","sources":["../../../src/internal/contexts.ts"],"sourcesContent":["import { createRequiredContext, createContext } from '@contember/react-utils'\nimport { EntityAccessor } from '@contember/react-binding'\nimport { useSortable } from '@dnd-kit/sortable'\n\nexport const [RepeaterSortableItemContext, useRepeaterSortableItem] = createRequiredContext<ReturnType<typeof useSortable>>('RepeaterSortableItemContext')\nexport const [RepeaterActiveEntityContext, useRepeaterActiveEntity] = createContext<EntityAccessor | undefined>('RepeaterActiveEntityContext', undefined)\n"],"names":[],"mappings":";AAIO,MAAM,CAAC,6BAA6B,uBAAuB,IAAI,sBAAsD,6BAA6B;AAClJ,MAAM,CAAC,6BAA6B,uBAAuB,IAAI,cAA0C,+BAA+B,MAAS;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const core = require("@dnd-kit/core");
|
|
6
|
+
const contexts = require("../internal/contexts.cjs");
|
|
7
|
+
const sortable = require("@dnd-kit/sortable");
|
|
8
|
+
const reactRepeater = require("@contember/react-repeater");
|
|
9
|
+
const RepeaterSortable = ({ children }) => {
|
|
10
|
+
const [activeId, setActiveId] = react.useState(null);
|
|
11
|
+
const { moveItem } = reactRepeater.useRepeaterMethods();
|
|
12
|
+
const entities = reactRepeater.useRepeaterSortedEntities();
|
|
13
|
+
const activeItem = react.useMemo(() => {
|
|
14
|
+
if (!activeId) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
return entities.find((it) => it.id === activeId);
|
|
18
|
+
}, [activeId, entities]);
|
|
19
|
+
const sensors = core.useSensors(
|
|
20
|
+
core.useSensor(core.MouseSensor),
|
|
21
|
+
core.useSensor(core.TouchSensor),
|
|
22
|
+
core.useSensor(core.KeyboardSensor)
|
|
23
|
+
);
|
|
24
|
+
const onDragCancel = () => {
|
|
25
|
+
setActiveId(null);
|
|
26
|
+
};
|
|
27
|
+
const onDragEnd = react.useCallback(({ active, over }) => {
|
|
28
|
+
setActiveId(null);
|
|
29
|
+
const activeEntity = entities.find((it) => it.id === active.id);
|
|
30
|
+
const overIndex = over ? entities.findIndex((it) => it.id === over.id) : void 0;
|
|
31
|
+
if (!activeEntity || overIndex === void 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
moveItem?.(activeEntity, overIndex);
|
|
35
|
+
}, [entities, moveItem]);
|
|
36
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
37
|
+
core.DndContext,
|
|
38
|
+
{
|
|
39
|
+
sensors,
|
|
40
|
+
measuring: {
|
|
41
|
+
droppable: {
|
|
42
|
+
strategy: core.MeasuringStrategy.Always
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
onDragStart: ({ active }) => {
|
|
46
|
+
setActiveId(active.id);
|
|
47
|
+
},
|
|
48
|
+
onDragEnd,
|
|
49
|
+
onDragCancel,
|
|
50
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(contexts.RepeaterActiveEntityContext.Provider, { value: activeItem, children: /* @__PURE__ */ jsxRuntime.jsx(sortable.SortableContext, { items: entities, strategy: sortable.verticalListSortingStrategy, children }) })
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
exports.RepeaterSortable = RepeaterSortable;
|
|
55
|
+
//# sourceMappingURL=RepeaterSortable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortable.cjs","sources":["../../../src/components/RepeaterSortable.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo, useState } from 'react'\nimport {\n\tDndContext,\n\tDragEndEvent,\n\tKeyboardSensor,\n\tMeasuringStrategy,\n\tMouseSensor,\n\tTouchSensor,\n\tUniqueIdentifier,\n\tuseSensor,\n\tuseSensors,\n} from '@dnd-kit/core'\nimport { RepeaterActiveEntityContext } from '../internal/contexts'\nimport { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'\nimport { useRepeaterSortedEntities } from '@contember/react-repeater'\nimport { useRepeaterMethods } from '@contember/react-repeater'\n\nexport const RepeaterSortable = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst [activeId, setActiveId] = useState<UniqueIdentifier | null>(null)\n\tconst { moveItem } = useRepeaterMethods()\n\tconst entities = useRepeaterSortedEntities()\n\n\n\tconst activeItem = useMemo(() => {\n\t\tif (!activeId) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn entities.find(it => it.id === activeId)\n\t}, [activeId, entities])\n\n\tconst sensors = useSensors(\n\t\tuseSensor(MouseSensor),\n\t\tuseSensor(TouchSensor),\n\t\tuseSensor(KeyboardSensor),\n\t)\n\n\tconst onDragCancel = () => {\n\t\tsetActiveId(null)\n\t}\n\n\tconst onDragEnd = useCallback(({ active, over }: DragEndEvent) => {\n\t\tsetActiveId(null)\n\t\tconst activeEntity = entities.find(it => it.id === active.id)\n\t\tconst overIndex = over ? entities.findIndex(it => it.id === over.id) : undefined\n\t\tif (!activeEntity || overIndex === undefined) {\n\t\t\treturn\n\t\t}\n\t\tmoveItem?.(activeEntity, overIndex)\n\t}, [entities, moveItem])\n\n\treturn (\n\t\t<DndContext\n\t\t\tsensors={sensors}\n\t\t\tmeasuring={{\n\t\t\t\tdroppable: {\n\t\t\t\t\tstrategy: MeasuringStrategy.Always,\n\t\t\t\t},\n\t\t\t}}\n\t\t\tonDragStart={({ active }) => {\n\t\t\t\tsetActiveId(active.id)\n\t\t\t}}\n\t\t\tonDragEnd={onDragEnd}\n\t\t\tonDragCancel={onDragCancel}\n\t\t>\n\t\t\t<RepeaterActiveEntityContext.Provider value={activeItem}>\n\t\t\t\t<SortableContext items={entities} strategy={verticalListSortingStrategy}>\n\t\t\t\t\t{children}\n\t\t\t\t</SortableContext>\n\t\t\t</RepeaterActiveEntityContext.Provider>\n\t\t</DndContext>\n\t)\n}\n"],"names":["useState","useRepeaterMethods","useRepeaterSortedEntities","useMemo","useSensors","useSensor","MouseSensor","TouchSensor","KeyboardSensor","useCallback","jsx","DndContext","MeasuringStrategy","RepeaterActiveEntityContext","SortableContext","verticalListSortingStrategy"],"mappings":";;;;;;;;AAiBO,MAAM,mBAAmB,CAAC,EAAE,eAE7B;AACL,QAAM,CAAC,UAAU,WAAW,IAAIA,eAAkC,IAAI;AAChE,QAAA,EAAE,aAAaC,cAAAA;AACrB,QAAM,WAAWC,cAAAA;AAGX,QAAA,aAAaC,MAAAA,QAAQ,MAAM;AAChC,QAAI,CAAC,UAAU;AACP,aAAA;AAAA,IACR;AACA,WAAO,SAAS,KAAK,CAAM,OAAA,GAAG,OAAO,QAAQ;AAAA,EAAA,GAC3C,CAAC,UAAU,QAAQ,CAAC;AAEvB,QAAM,UAAUC,KAAA;AAAA,IACfC,KAAAA,UAAUC,KAAAA,WAAW;AAAA,IACrBD,KAAAA,UAAUE,KAAAA,WAAW;AAAA,IACrBF,KAAAA,UAAUG,KAAAA,cAAc;AAAA,EAAA;AAGzB,QAAM,eAAe,MAAM;AAC1B,gBAAY,IAAI;AAAA,EAAA;AAGjB,QAAM,YAAYC,MAAY,YAAA,CAAC,EAAE,QAAQ,WAAyB;AACjE,gBAAY,IAAI;AAChB,UAAM,eAAe,SAAS,KAAK,QAAM,GAAG,OAAO,OAAO,EAAE;AACtD,UAAA,YAAY,OAAO,SAAS,UAAU,QAAM,GAAG,OAAO,KAAK,EAAE,IAAI;AACnE,QAAA,CAAC,gBAAgB,cAAc,QAAW;AAC7C;AAAA,IACD;AACA,eAAW,cAAc,SAAS;AAAA,EAAA,GAChC,CAAC,UAAU,QAAQ,CAAC;AAGtB,SAAAC,2BAAA;AAAA,IAACC,KAAA;AAAA,IAAA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACV,WAAW;AAAA,UACV,UAAUC,KAAkB,kBAAA;AAAA,QAC7B;AAAA,MACD;AAAA,MACA,aAAa,CAAC,EAAE,aAAa;AAC5B,oBAAY,OAAO,EAAE;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MAEA,UAACF,2BAAA,IAAAG,qCAA4B,UAA5B,EAAqC,OAAO,YAC5C,UAACH,2BAAAA,IAAAI,SAAAA,iBAAA,EAAgB,OAAO,UAAU,UAAUC,SAAAA,6BAC1C,SACF,CAAA,GACD;AAAA,IAAA;AAAA,EAAA;AAGH;;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useMemo, useCallback } from "react";
|
|
3
|
+
import { useSensors, useSensor, MouseSensor, TouchSensor, KeyboardSensor, DndContext, MeasuringStrategy } from "@dnd-kit/core";
|
|
4
|
+
import { RepeaterActiveEntityContext } from "../internal/contexts.js";
|
|
5
|
+
import { SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
6
|
+
import { useRepeaterMethods, useRepeaterSortedEntities } from "@contember/react-repeater";
|
|
7
|
+
const RepeaterSortable = ({ children }) => {
|
|
8
|
+
const [activeId, setActiveId] = useState(null);
|
|
9
|
+
const { moveItem } = useRepeaterMethods();
|
|
10
|
+
const entities = useRepeaterSortedEntities();
|
|
11
|
+
const activeItem = useMemo(() => {
|
|
12
|
+
if (!activeId) {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
return entities.find((it) => it.id === activeId);
|
|
16
|
+
}, [activeId, entities]);
|
|
17
|
+
const sensors = useSensors(
|
|
18
|
+
useSensor(MouseSensor),
|
|
19
|
+
useSensor(TouchSensor),
|
|
20
|
+
useSensor(KeyboardSensor)
|
|
21
|
+
);
|
|
22
|
+
const onDragCancel = () => {
|
|
23
|
+
setActiveId(null);
|
|
24
|
+
};
|
|
25
|
+
const onDragEnd = useCallback(({ active, over }) => {
|
|
26
|
+
setActiveId(null);
|
|
27
|
+
const activeEntity = entities.find((it) => it.id === active.id);
|
|
28
|
+
const overIndex = over ? entities.findIndex((it) => it.id === over.id) : void 0;
|
|
29
|
+
if (!activeEntity || overIndex === void 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
moveItem?.(activeEntity, overIndex);
|
|
33
|
+
}, [entities, moveItem]);
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
DndContext,
|
|
36
|
+
{
|
|
37
|
+
sensors,
|
|
38
|
+
measuring: {
|
|
39
|
+
droppable: {
|
|
40
|
+
strategy: MeasuringStrategy.Always
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
onDragStart: ({ active }) => {
|
|
44
|
+
setActiveId(active.id);
|
|
45
|
+
},
|
|
46
|
+
onDragEnd,
|
|
47
|
+
onDragCancel,
|
|
48
|
+
children: /* @__PURE__ */ jsx(RepeaterActiveEntityContext.Provider, { value: activeItem, children: /* @__PURE__ */ jsx(SortableContext, { items: entities, strategy: verticalListSortingStrategy, children }) })
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
RepeaterSortable
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=RepeaterSortable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortable.js","sources":["../../../src/components/RepeaterSortable.tsx"],"sourcesContent":["import React, { ReactNode, useCallback, useMemo, useState } from 'react'\nimport {\n\tDndContext,\n\tDragEndEvent,\n\tKeyboardSensor,\n\tMeasuringStrategy,\n\tMouseSensor,\n\tTouchSensor,\n\tUniqueIdentifier,\n\tuseSensor,\n\tuseSensors,\n} from '@dnd-kit/core'\nimport { RepeaterActiveEntityContext } from '../internal/contexts'\nimport { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'\nimport { useRepeaterSortedEntities } from '@contember/react-repeater'\nimport { useRepeaterMethods } from '@contember/react-repeater'\n\nexport const RepeaterSortable = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst [activeId, setActiveId] = useState<UniqueIdentifier | null>(null)\n\tconst { moveItem } = useRepeaterMethods()\n\tconst entities = useRepeaterSortedEntities()\n\n\n\tconst activeItem = useMemo(() => {\n\t\tif (!activeId) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn entities.find(it => it.id === activeId)\n\t}, [activeId, entities])\n\n\tconst sensors = useSensors(\n\t\tuseSensor(MouseSensor),\n\t\tuseSensor(TouchSensor),\n\t\tuseSensor(KeyboardSensor),\n\t)\n\n\tconst onDragCancel = () => {\n\t\tsetActiveId(null)\n\t}\n\n\tconst onDragEnd = useCallback(({ active, over }: DragEndEvent) => {\n\t\tsetActiveId(null)\n\t\tconst activeEntity = entities.find(it => it.id === active.id)\n\t\tconst overIndex = over ? entities.findIndex(it => it.id === over.id) : undefined\n\t\tif (!activeEntity || overIndex === undefined) {\n\t\t\treturn\n\t\t}\n\t\tmoveItem?.(activeEntity, overIndex)\n\t}, [entities, moveItem])\n\n\treturn (\n\t\t<DndContext\n\t\t\tsensors={sensors}\n\t\t\tmeasuring={{\n\t\t\t\tdroppable: {\n\t\t\t\t\tstrategy: MeasuringStrategy.Always,\n\t\t\t\t},\n\t\t\t}}\n\t\t\tonDragStart={({ active }) => {\n\t\t\t\tsetActiveId(active.id)\n\t\t\t}}\n\t\t\tonDragEnd={onDragEnd}\n\t\t\tonDragCancel={onDragCancel}\n\t\t>\n\t\t\t<RepeaterActiveEntityContext.Provider value={activeItem}>\n\t\t\t\t<SortableContext items={entities} strategy={verticalListSortingStrategy}>\n\t\t\t\t\t{children}\n\t\t\t\t</SortableContext>\n\t\t\t</RepeaterActiveEntityContext.Provider>\n\t\t</DndContext>\n\t)\n}\n"],"names":[],"mappings":";;;;;;AAiBO,MAAM,mBAAmB,CAAC,EAAE,eAE7B;AACL,QAAM,CAAC,UAAU,WAAW,IAAI,SAAkC,IAAI;AAChE,QAAA,EAAE,aAAa;AACrB,QAAM,WAAW;AAGX,QAAA,aAAa,QAAQ,MAAM;AAChC,QAAI,CAAC,UAAU;AACP,aAAA;AAAA,IACR;AACA,WAAO,SAAS,KAAK,CAAM,OAAA,GAAG,OAAO,QAAQ;AAAA,EAAA,GAC3C,CAAC,UAAU,QAAQ,CAAC;AAEvB,QAAM,UAAU;AAAA,IACf,UAAU,WAAW;AAAA,IACrB,UAAU,WAAW;AAAA,IACrB,UAAU,cAAc;AAAA,EAAA;AAGzB,QAAM,eAAe,MAAM;AAC1B,gBAAY,IAAI;AAAA,EAAA;AAGjB,QAAM,YAAY,YAAY,CAAC,EAAE,QAAQ,WAAyB;AACjE,gBAAY,IAAI;AAChB,UAAM,eAAe,SAAS,KAAK,QAAM,GAAG,OAAO,OAAO,EAAE;AACtD,UAAA,YAAY,OAAO,SAAS,UAAU,QAAM,GAAG,OAAO,KAAK,EAAE,IAAI;AACnE,QAAA,CAAC,gBAAgB,cAAc,QAAW;AAC7C;AAAA,IACD;AACA,eAAW,cAAc,SAAS;AAAA,EAAA,GAChC,CAAC,UAAU,QAAQ,CAAC;AAGtB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACV,WAAW;AAAA,UACV,UAAU,kBAAkB;AAAA,QAC7B;AAAA,MACD;AAAA,MACA,aAAa,CAAC,EAAE,aAAa;AAC5B,oBAAY,OAAO,EAAE;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MAEA,UAAC,oBAAA,4BAA4B,UAA5B,EAAqC,OAAO,YAC5C,UAAC,oBAAA,iBAAA,EAAgB,OAAO,UAAU,UAAU,6BAC1C,SACF,CAAA,GACD;AAAA,IAAA;AAAA,EAAA;AAGH;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const contexts = require("../internal/contexts.cjs");
|
|
5
|
+
const reactPortal = require("@radix-ui/react-portal");
|
|
6
|
+
const core = require("@dnd-kit/core");
|
|
7
|
+
const reactBinding = require("@contember/react-binding");
|
|
8
|
+
const RepeaterSortableDragOverlay = ({ children }) => {
|
|
9
|
+
const activeItem = contexts.useRepeaterActiveEntity();
|
|
10
|
+
const accessorTreeState = reactBinding.useAccessorTreeState();
|
|
11
|
+
if (!activeItem) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactPortal.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(core.DragOverlay, { children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.AccessorTree, { state: accessorTreeState, children: /* @__PURE__ */ jsxRuntime.jsx(reactBinding.Entity, { accessor: activeItem, children }) }) }) });
|
|
15
|
+
};
|
|
16
|
+
exports.RepeaterSortableDragOverlay = RepeaterSortableDragOverlay;
|
|
17
|
+
//# sourceMappingURL=RepeaterSortableDragOverlay.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepeaterSortableDragOverlay.cjs","sources":["../../../src/components/RepeaterSortableDragOverlay.tsx"],"sourcesContent":["import React, { ReactNode } from 'react'\nimport { useRepeaterActiveEntity } from '../internal/contexts'\nimport { Portal } from '@radix-ui/react-portal'\nimport { DragOverlay } from '@dnd-kit/core'\nimport { AccessorTree, Entity, useAccessorTreeState } from '@contember/react-binding'\n\nexport const RepeaterSortableDragOverlay = ({ children }: {\n\tchildren: ReactNode\n}) => {\n\tconst activeItem = useRepeaterActiveEntity()\n\tconst accessorTreeState = useAccessorTreeState()\n\tif (!activeItem) {\n\t\treturn null\n\t}\n\treturn (\n\t\t<Portal>\n\t\t\t<DragOverlay>\n\t\t\t\t<AccessorTree state={accessorTreeState}>\n\t\t\t\t\t<Entity accessor={activeItem}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</Entity>\n\t\t\t\t</AccessorTree>\n\t\t\t</DragOverlay>\n\t\t</Portal>\n\t)\n}\n"],"names":["useRepeaterActiveEntity","useAccessorTreeState","jsx","Portal","DragOverlay","AccessorTree","Entity"],"mappings":";;;;;;;AAMO,MAAM,8BAA8B,CAAC,EAAE,eAExC;AACL,QAAM,aAAaA,SAAAA;AACnB,QAAM,oBAAoBC,aAAAA;AAC1B,MAAI,CAAC,YAAY;AACT,WAAA;AAAA,EACR;AACA,SACEC,+BAAAC,YAAAA,QAAA,EACA,UAACD,2BAAA,IAAAE,kBAAA,EACA,yCAACC,aAAa,cAAA,EAAA,OAAO,mBACpB,UAAAH,2BAAA,IAACI,uBAAO,UAAU,YAChB,SACF,CAAA,EACD,CAAA,GACD,EACD,CAAA;AAEF;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRepeaterActiveEntity } from "../internal/contexts.js";
|
|
3
|
+
import { Portal } from "@radix-ui/react-portal";
|
|
4
|
+
import { DragOverlay } from "@dnd-kit/core";
|
|
5
|
+
import { useAccessorTreeState, AccessorTree, Entity } from "@contember/react-binding";
|
|
6
|
+
const RepeaterSortableDragOverlay = ({ children }) => {
|
|
7
|
+
const activeItem = useRepeaterActiveEntity();
|
|
8
|
+
const accessorTreeState = useAccessorTreeState();
|
|
9
|
+
if (!activeItem) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(DragOverlay, { children: /* @__PURE__ */ jsx(AccessorTree, { state: accessorTreeState, children: /* @__PURE__ */ jsx(Entity, { accessor: activeItem, children }) }) }) });
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
RepeaterSortableDragOverlay
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=RepeaterSortableDragOverlay.js.map
|