@lodashventure/medusa-banner 1.1.5 → 1.1.8
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/.medusa/server/src/admin/index.js +21 -659
- package/.medusa/server/src/admin/index.mjs +6 -642
- package/.medusa/server/src/api/store/banners/route.js +18 -0
- package/.medusa/server/src/workflows/delete-banners.js +36 -5
- package/.medusa/server/src/workflows/upload-banners.js +3 -3
- package/package.json +3 -1
|
@@ -1,650 +1,14 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
3
|
import { Trash, StackPerspective } from "@medusajs/icons";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, closestCenter, DragOverlay } from "@dnd-kit/core";
|
|
5
|
+
import { useSortable, sortableKeyboardCoordinates, SortableContext, rectSortingStrategy, arrayMove } from "@dnd-kit/sortable";
|
|
6
6
|
import { clx, Button, usePrompt, Drawer } from "@medusajs/ui";
|
|
7
7
|
import { Check, Upload, ImageIcon, Trash2, MoveHorizontal, X } from "lucide-react";
|
|
8
|
+
import { useState, useCallback } from "react";
|
|
8
9
|
import { useQuery } from "@tanstack/react-query";
|
|
10
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
9
11
|
import { useDropzone } from "react-dropzone";
|
|
10
|
-
function useCombinedRefs() {
|
|
11
|
-
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
|
-
refs[_key] = arguments[_key];
|
|
13
|
-
}
|
|
14
|
-
return useMemo(
|
|
15
|
-
() => (node) => {
|
|
16
|
-
refs.forEach((ref) => ref(node));
|
|
17
|
-
},
|
|
18
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
-
refs
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
const canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
|
23
|
-
function isWindow(element) {
|
|
24
|
-
const elementString = Object.prototype.toString.call(element);
|
|
25
|
-
return elementString === "[object Window]" || // In Electron context the Window object serializes to [object global]
|
|
26
|
-
elementString === "[object global]";
|
|
27
|
-
}
|
|
28
|
-
function isNode(node) {
|
|
29
|
-
return "nodeType" in node;
|
|
30
|
-
}
|
|
31
|
-
function getWindow(target) {
|
|
32
|
-
var _target$ownerDocument, _target$ownerDocument2;
|
|
33
|
-
if (!target) {
|
|
34
|
-
return window;
|
|
35
|
-
}
|
|
36
|
-
if (isWindow(target)) {
|
|
37
|
-
return target;
|
|
38
|
-
}
|
|
39
|
-
if (!isNode(target)) {
|
|
40
|
-
return window;
|
|
41
|
-
}
|
|
42
|
-
return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
|
|
43
|
-
}
|
|
44
|
-
const useIsomorphicLayoutEffect = canUseDOM ? useLayoutEffect : useEffect;
|
|
45
|
-
let ids = {};
|
|
46
|
-
function useUniqueId(prefix, value) {
|
|
47
|
-
return useMemo(() => {
|
|
48
|
-
if (value) {
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
|
|
52
|
-
ids[prefix] = id;
|
|
53
|
-
return prefix + "-" + id;
|
|
54
|
-
}, [prefix, value]);
|
|
55
|
-
}
|
|
56
|
-
function createAdjustmentFn(modifier) {
|
|
57
|
-
return function(object) {
|
|
58
|
-
for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
59
|
-
adjustments[_key - 1] = arguments[_key];
|
|
60
|
-
}
|
|
61
|
-
return adjustments.reduce((accumulator, adjustment) => {
|
|
62
|
-
const entries = Object.entries(adjustment);
|
|
63
|
-
for (const [key, valueAdjustment] of entries) {
|
|
64
|
-
const value = accumulator[key];
|
|
65
|
-
if (value != null) {
|
|
66
|
-
accumulator[key] = value + modifier * valueAdjustment;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return accumulator;
|
|
70
|
-
}, {
|
|
71
|
-
...object
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
const subtract = /* @__PURE__ */ createAdjustmentFn(-1);
|
|
76
|
-
function isKeyboardEvent(event) {
|
|
77
|
-
if (!event) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
const {
|
|
81
|
-
KeyboardEvent
|
|
82
|
-
} = getWindow(event.target);
|
|
83
|
-
return KeyboardEvent && event instanceof KeyboardEvent;
|
|
84
|
-
}
|
|
85
|
-
const CSS = /* @__PURE__ */ Object.freeze({
|
|
86
|
-
Translate: {
|
|
87
|
-
toString(transform) {
|
|
88
|
-
if (!transform) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const {
|
|
92
|
-
x,
|
|
93
|
-
y
|
|
94
|
-
} = transform;
|
|
95
|
-
return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
Scale: {
|
|
99
|
-
toString(transform) {
|
|
100
|
-
if (!transform) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const {
|
|
104
|
-
scaleX,
|
|
105
|
-
scaleY
|
|
106
|
-
} = transform;
|
|
107
|
-
return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
Transform: {
|
|
111
|
-
toString(transform) {
|
|
112
|
-
if (!transform) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(" ");
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
Transition: {
|
|
119
|
-
toString(_ref) {
|
|
120
|
-
let {
|
|
121
|
-
property,
|
|
122
|
-
duration,
|
|
123
|
-
easing
|
|
124
|
-
} = _ref;
|
|
125
|
-
return property + " " + duration + "ms " + easing;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
function arrayMove(array, from, to) {
|
|
130
|
-
const newArray = array.slice();
|
|
131
|
-
newArray.splice(to < 0 ? newArray.length + to : to, 0, newArray.splice(from, 1)[0]);
|
|
132
|
-
return newArray;
|
|
133
|
-
}
|
|
134
|
-
function getSortedRects(items, rects) {
|
|
135
|
-
return items.reduce((accumulator, id, index) => {
|
|
136
|
-
const rect = rects.get(id);
|
|
137
|
-
if (rect) {
|
|
138
|
-
accumulator[index] = rect;
|
|
139
|
-
}
|
|
140
|
-
return accumulator;
|
|
141
|
-
}, Array(items.length));
|
|
142
|
-
}
|
|
143
|
-
function isValidIndex(index) {
|
|
144
|
-
return index !== null && index >= 0;
|
|
145
|
-
}
|
|
146
|
-
function itemsEqual(a, b) {
|
|
147
|
-
if (a === b) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
if (a.length !== b.length) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
for (let i = 0; i < a.length; i++) {
|
|
154
|
-
if (a[i] !== b[i]) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
function normalizeDisabled(disabled) {
|
|
161
|
-
if (typeof disabled === "boolean") {
|
|
162
|
-
return {
|
|
163
|
-
draggable: disabled,
|
|
164
|
-
droppable: disabled
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
return disabled;
|
|
168
|
-
}
|
|
169
|
-
const rectSortingStrategy = (_ref) => {
|
|
170
|
-
let {
|
|
171
|
-
rects,
|
|
172
|
-
activeIndex,
|
|
173
|
-
overIndex,
|
|
174
|
-
index
|
|
175
|
-
} = _ref;
|
|
176
|
-
const newRects = arrayMove(rects, overIndex, activeIndex);
|
|
177
|
-
const oldRect = rects[index];
|
|
178
|
-
const newRect = newRects[index];
|
|
179
|
-
if (!newRect || !oldRect) {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
return {
|
|
183
|
-
x: newRect.left - oldRect.left,
|
|
184
|
-
y: newRect.top - oldRect.top,
|
|
185
|
-
scaleX: newRect.width / oldRect.width,
|
|
186
|
-
scaleY: newRect.height / oldRect.height
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
const ID_PREFIX = "Sortable";
|
|
190
|
-
const Context = /* @__PURE__ */ React.createContext({
|
|
191
|
-
activeIndex: -1,
|
|
192
|
-
containerId: ID_PREFIX,
|
|
193
|
-
disableTransforms: false,
|
|
194
|
-
items: [],
|
|
195
|
-
overIndex: -1,
|
|
196
|
-
useDragOverlay: false,
|
|
197
|
-
sortedRects: [],
|
|
198
|
-
strategy: rectSortingStrategy,
|
|
199
|
-
disabled: {
|
|
200
|
-
draggable: false,
|
|
201
|
-
droppable: false
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
function SortableContext(_ref) {
|
|
205
|
-
let {
|
|
206
|
-
children,
|
|
207
|
-
id,
|
|
208
|
-
items: userDefinedItems,
|
|
209
|
-
strategy = rectSortingStrategy,
|
|
210
|
-
disabled: disabledProp = false
|
|
211
|
-
} = _ref;
|
|
212
|
-
const {
|
|
213
|
-
active,
|
|
214
|
-
dragOverlay,
|
|
215
|
-
droppableRects,
|
|
216
|
-
over,
|
|
217
|
-
measureDroppableContainers
|
|
218
|
-
} = useDndContext();
|
|
219
|
-
const containerId = useUniqueId(ID_PREFIX, id);
|
|
220
|
-
const useDragOverlay = Boolean(dragOverlay.rect !== null);
|
|
221
|
-
const items = useMemo(() => userDefinedItems.map((item) => typeof item === "object" && "id" in item ? item.id : item), [userDefinedItems]);
|
|
222
|
-
const isDragging = active != null;
|
|
223
|
-
const activeIndex = active ? items.indexOf(active.id) : -1;
|
|
224
|
-
const overIndex = over ? items.indexOf(over.id) : -1;
|
|
225
|
-
const previousItemsRef = useRef(items);
|
|
226
|
-
const itemsHaveChanged = !itemsEqual(items, previousItemsRef.current);
|
|
227
|
-
const disableTransforms = overIndex !== -1 && activeIndex === -1 || itemsHaveChanged;
|
|
228
|
-
const disabled = normalizeDisabled(disabledProp);
|
|
229
|
-
useIsomorphicLayoutEffect(() => {
|
|
230
|
-
if (itemsHaveChanged && isDragging) {
|
|
231
|
-
measureDroppableContainers(items);
|
|
232
|
-
}
|
|
233
|
-
}, [itemsHaveChanged, items, isDragging, measureDroppableContainers]);
|
|
234
|
-
useEffect(() => {
|
|
235
|
-
previousItemsRef.current = items;
|
|
236
|
-
}, [items]);
|
|
237
|
-
const contextValue = useMemo(
|
|
238
|
-
() => ({
|
|
239
|
-
activeIndex,
|
|
240
|
-
containerId,
|
|
241
|
-
disabled,
|
|
242
|
-
disableTransforms,
|
|
243
|
-
items,
|
|
244
|
-
overIndex,
|
|
245
|
-
useDragOverlay,
|
|
246
|
-
sortedRects: getSortedRects(items, droppableRects),
|
|
247
|
-
strategy
|
|
248
|
-
}),
|
|
249
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
250
|
-
[activeIndex, containerId, disabled.draggable, disabled.droppable, disableTransforms, items, overIndex, droppableRects, useDragOverlay, strategy]
|
|
251
|
-
);
|
|
252
|
-
return React.createElement(Context.Provider, {
|
|
253
|
-
value: contextValue
|
|
254
|
-
}, children);
|
|
255
|
-
}
|
|
256
|
-
const defaultNewIndexGetter = (_ref) => {
|
|
257
|
-
let {
|
|
258
|
-
id,
|
|
259
|
-
items,
|
|
260
|
-
activeIndex,
|
|
261
|
-
overIndex
|
|
262
|
-
} = _ref;
|
|
263
|
-
return arrayMove(items, activeIndex, overIndex).indexOf(id);
|
|
264
|
-
};
|
|
265
|
-
const defaultAnimateLayoutChanges = (_ref2) => {
|
|
266
|
-
let {
|
|
267
|
-
containerId,
|
|
268
|
-
isSorting,
|
|
269
|
-
wasDragging,
|
|
270
|
-
index,
|
|
271
|
-
items,
|
|
272
|
-
newIndex,
|
|
273
|
-
previousItems,
|
|
274
|
-
previousContainerId,
|
|
275
|
-
transition
|
|
276
|
-
} = _ref2;
|
|
277
|
-
if (!transition || !wasDragging) {
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
if (previousItems !== items && index === newIndex) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
if (isSorting) {
|
|
284
|
-
return true;
|
|
285
|
-
}
|
|
286
|
-
return newIndex !== index && containerId === previousContainerId;
|
|
287
|
-
};
|
|
288
|
-
const defaultTransition = {
|
|
289
|
-
duration: 200,
|
|
290
|
-
easing: "ease"
|
|
291
|
-
};
|
|
292
|
-
const transitionProperty = "transform";
|
|
293
|
-
const disabledTransition = /* @__PURE__ */ CSS.Transition.toString({
|
|
294
|
-
property: transitionProperty,
|
|
295
|
-
duration: 0,
|
|
296
|
-
easing: "linear"
|
|
297
|
-
});
|
|
298
|
-
const defaultAttributes = {
|
|
299
|
-
roleDescription: "sortable"
|
|
300
|
-
};
|
|
301
|
-
function useDerivedTransform(_ref) {
|
|
302
|
-
let {
|
|
303
|
-
disabled,
|
|
304
|
-
index,
|
|
305
|
-
node,
|
|
306
|
-
rect
|
|
307
|
-
} = _ref;
|
|
308
|
-
const [derivedTransform, setDerivedtransform] = useState(null);
|
|
309
|
-
const previousIndex = useRef(index);
|
|
310
|
-
useIsomorphicLayoutEffect(() => {
|
|
311
|
-
if (!disabled && index !== previousIndex.current && node.current) {
|
|
312
|
-
const initial = rect.current;
|
|
313
|
-
if (initial) {
|
|
314
|
-
const current = getClientRect(node.current, {
|
|
315
|
-
ignoreTransform: true
|
|
316
|
-
});
|
|
317
|
-
const delta = {
|
|
318
|
-
x: initial.left - current.left,
|
|
319
|
-
y: initial.top - current.top,
|
|
320
|
-
scaleX: initial.width / current.width,
|
|
321
|
-
scaleY: initial.height / current.height
|
|
322
|
-
};
|
|
323
|
-
if (delta.x || delta.y) {
|
|
324
|
-
setDerivedtransform(delta);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (index !== previousIndex.current) {
|
|
329
|
-
previousIndex.current = index;
|
|
330
|
-
}
|
|
331
|
-
}, [disabled, index, node, rect]);
|
|
332
|
-
useEffect(() => {
|
|
333
|
-
if (derivedTransform) {
|
|
334
|
-
setDerivedtransform(null);
|
|
335
|
-
}
|
|
336
|
-
}, [derivedTransform]);
|
|
337
|
-
return derivedTransform;
|
|
338
|
-
}
|
|
339
|
-
function useSortable(_ref) {
|
|
340
|
-
let {
|
|
341
|
-
animateLayoutChanges = defaultAnimateLayoutChanges,
|
|
342
|
-
attributes: userDefinedAttributes,
|
|
343
|
-
disabled: localDisabled,
|
|
344
|
-
data: customData,
|
|
345
|
-
getNewIndex = defaultNewIndexGetter,
|
|
346
|
-
id,
|
|
347
|
-
strategy: localStrategy,
|
|
348
|
-
resizeObserverConfig,
|
|
349
|
-
transition = defaultTransition
|
|
350
|
-
} = _ref;
|
|
351
|
-
const {
|
|
352
|
-
items,
|
|
353
|
-
containerId,
|
|
354
|
-
activeIndex,
|
|
355
|
-
disabled: globalDisabled,
|
|
356
|
-
disableTransforms,
|
|
357
|
-
sortedRects,
|
|
358
|
-
overIndex,
|
|
359
|
-
useDragOverlay,
|
|
360
|
-
strategy: globalStrategy
|
|
361
|
-
} = useContext(Context);
|
|
362
|
-
const disabled = normalizeLocalDisabled(localDisabled, globalDisabled);
|
|
363
|
-
const index = items.indexOf(id);
|
|
364
|
-
const data = useMemo(() => ({
|
|
365
|
-
sortable: {
|
|
366
|
-
containerId,
|
|
367
|
-
index,
|
|
368
|
-
items
|
|
369
|
-
},
|
|
370
|
-
...customData
|
|
371
|
-
}), [containerId, customData, index, items]);
|
|
372
|
-
const itemsAfterCurrentSortable = useMemo(() => items.slice(items.indexOf(id)), [items, id]);
|
|
373
|
-
const {
|
|
374
|
-
rect,
|
|
375
|
-
node,
|
|
376
|
-
isOver,
|
|
377
|
-
setNodeRef: setDroppableNodeRef
|
|
378
|
-
} = useDroppable({
|
|
379
|
-
id,
|
|
380
|
-
data,
|
|
381
|
-
disabled: disabled.droppable,
|
|
382
|
-
resizeObserverConfig: {
|
|
383
|
-
updateMeasurementsFor: itemsAfterCurrentSortable,
|
|
384
|
-
...resizeObserverConfig
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
const {
|
|
388
|
-
active,
|
|
389
|
-
activatorEvent,
|
|
390
|
-
activeNodeRect,
|
|
391
|
-
attributes,
|
|
392
|
-
setNodeRef: setDraggableNodeRef,
|
|
393
|
-
listeners,
|
|
394
|
-
isDragging,
|
|
395
|
-
over,
|
|
396
|
-
setActivatorNodeRef,
|
|
397
|
-
transform
|
|
398
|
-
} = useDraggable({
|
|
399
|
-
id,
|
|
400
|
-
data,
|
|
401
|
-
attributes: {
|
|
402
|
-
...defaultAttributes,
|
|
403
|
-
...userDefinedAttributes
|
|
404
|
-
},
|
|
405
|
-
disabled: disabled.draggable
|
|
406
|
-
});
|
|
407
|
-
const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
|
|
408
|
-
const isSorting = Boolean(active);
|
|
409
|
-
const displaceItem = isSorting && !disableTransforms && isValidIndex(activeIndex) && isValidIndex(overIndex);
|
|
410
|
-
const shouldDisplaceDragSource = !useDragOverlay && isDragging;
|
|
411
|
-
const dragSourceDisplacement = shouldDisplaceDragSource && displaceItem ? transform : null;
|
|
412
|
-
const strategy = localStrategy != null ? localStrategy : globalStrategy;
|
|
413
|
-
const finalTransform = displaceItem ? dragSourceDisplacement != null ? dragSourceDisplacement : strategy({
|
|
414
|
-
rects: sortedRects,
|
|
415
|
-
activeNodeRect,
|
|
416
|
-
activeIndex,
|
|
417
|
-
overIndex,
|
|
418
|
-
index
|
|
419
|
-
}) : null;
|
|
420
|
-
const newIndex = isValidIndex(activeIndex) && isValidIndex(overIndex) ? getNewIndex({
|
|
421
|
-
id,
|
|
422
|
-
items,
|
|
423
|
-
activeIndex,
|
|
424
|
-
overIndex
|
|
425
|
-
}) : index;
|
|
426
|
-
const activeId = active == null ? void 0 : active.id;
|
|
427
|
-
const previous = useRef({
|
|
428
|
-
activeId,
|
|
429
|
-
items,
|
|
430
|
-
newIndex,
|
|
431
|
-
containerId
|
|
432
|
-
});
|
|
433
|
-
const itemsHaveChanged = items !== previous.current.items;
|
|
434
|
-
const shouldAnimateLayoutChanges = animateLayoutChanges({
|
|
435
|
-
active,
|
|
436
|
-
containerId,
|
|
437
|
-
isDragging,
|
|
438
|
-
isSorting,
|
|
439
|
-
id,
|
|
440
|
-
index,
|
|
441
|
-
items,
|
|
442
|
-
newIndex: previous.current.newIndex,
|
|
443
|
-
previousItems: previous.current.items,
|
|
444
|
-
previousContainerId: previous.current.containerId,
|
|
445
|
-
transition,
|
|
446
|
-
wasDragging: previous.current.activeId != null
|
|
447
|
-
});
|
|
448
|
-
const derivedTransform = useDerivedTransform({
|
|
449
|
-
disabled: !shouldAnimateLayoutChanges,
|
|
450
|
-
index,
|
|
451
|
-
node,
|
|
452
|
-
rect
|
|
453
|
-
});
|
|
454
|
-
useEffect(() => {
|
|
455
|
-
if (isSorting && previous.current.newIndex !== newIndex) {
|
|
456
|
-
previous.current.newIndex = newIndex;
|
|
457
|
-
}
|
|
458
|
-
if (containerId !== previous.current.containerId) {
|
|
459
|
-
previous.current.containerId = containerId;
|
|
460
|
-
}
|
|
461
|
-
if (items !== previous.current.items) {
|
|
462
|
-
previous.current.items = items;
|
|
463
|
-
}
|
|
464
|
-
}, [isSorting, newIndex, containerId, items]);
|
|
465
|
-
useEffect(() => {
|
|
466
|
-
if (activeId === previous.current.activeId) {
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
if (activeId && !previous.current.activeId) {
|
|
470
|
-
previous.current.activeId = activeId;
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
const timeoutId = setTimeout(() => {
|
|
474
|
-
previous.current.activeId = activeId;
|
|
475
|
-
}, 50);
|
|
476
|
-
return () => clearTimeout(timeoutId);
|
|
477
|
-
}, [activeId]);
|
|
478
|
-
return {
|
|
479
|
-
active,
|
|
480
|
-
activeIndex,
|
|
481
|
-
attributes,
|
|
482
|
-
data,
|
|
483
|
-
rect,
|
|
484
|
-
index,
|
|
485
|
-
newIndex,
|
|
486
|
-
items,
|
|
487
|
-
isOver,
|
|
488
|
-
isSorting,
|
|
489
|
-
isDragging,
|
|
490
|
-
listeners,
|
|
491
|
-
node,
|
|
492
|
-
overIndex,
|
|
493
|
-
over,
|
|
494
|
-
setNodeRef,
|
|
495
|
-
setActivatorNodeRef,
|
|
496
|
-
setDroppableNodeRef,
|
|
497
|
-
setDraggableNodeRef,
|
|
498
|
-
transform: derivedTransform != null ? derivedTransform : finalTransform,
|
|
499
|
-
transition: getTransition()
|
|
500
|
-
};
|
|
501
|
-
function getTransition() {
|
|
502
|
-
if (
|
|
503
|
-
// Temporarily disable transitions for a single frame to set up derived transforms
|
|
504
|
-
derivedTransform || // Or to prevent items jumping to back to their "new" position when items change
|
|
505
|
-
itemsHaveChanged && previous.current.newIndex === index
|
|
506
|
-
) {
|
|
507
|
-
return disabledTransition;
|
|
508
|
-
}
|
|
509
|
-
if (shouldDisplaceDragSource && !isKeyboardEvent(activatorEvent) || !transition) {
|
|
510
|
-
return void 0;
|
|
511
|
-
}
|
|
512
|
-
if (isSorting || shouldAnimateLayoutChanges) {
|
|
513
|
-
return CSS.Transition.toString({
|
|
514
|
-
...transition,
|
|
515
|
-
property: transitionProperty
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
return void 0;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
function normalizeLocalDisabled(localDisabled, globalDisabled) {
|
|
522
|
-
var _localDisabled$dragga, _localDisabled$droppa;
|
|
523
|
-
if (typeof localDisabled === "boolean") {
|
|
524
|
-
return {
|
|
525
|
-
draggable: localDisabled,
|
|
526
|
-
// Backwards compatibility
|
|
527
|
-
droppable: false
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
return {
|
|
531
|
-
draggable: (_localDisabled$dragga = localDisabled == null ? void 0 : localDisabled.draggable) != null ? _localDisabled$dragga : globalDisabled.draggable,
|
|
532
|
-
droppable: (_localDisabled$droppa = localDisabled == null ? void 0 : localDisabled.droppable) != null ? _localDisabled$droppa : globalDisabled.droppable
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
function hasSortableData(entry) {
|
|
536
|
-
if (!entry) {
|
|
537
|
-
return false;
|
|
538
|
-
}
|
|
539
|
-
const data = entry.data.current;
|
|
540
|
-
if (data && "sortable" in data && typeof data.sortable === "object" && "containerId" in data.sortable && "items" in data.sortable && "index" in data.sortable) {
|
|
541
|
-
return true;
|
|
542
|
-
}
|
|
543
|
-
return false;
|
|
544
|
-
}
|
|
545
|
-
const directions = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
|
|
546
|
-
const sortableKeyboardCoordinates = (event, _ref) => {
|
|
547
|
-
let {
|
|
548
|
-
context: {
|
|
549
|
-
active,
|
|
550
|
-
collisionRect,
|
|
551
|
-
droppableRects,
|
|
552
|
-
droppableContainers,
|
|
553
|
-
over,
|
|
554
|
-
scrollableAncestors
|
|
555
|
-
}
|
|
556
|
-
} = _ref;
|
|
557
|
-
if (directions.includes(event.code)) {
|
|
558
|
-
event.preventDefault();
|
|
559
|
-
if (!active || !collisionRect) {
|
|
560
|
-
return;
|
|
561
|
-
}
|
|
562
|
-
const filteredContainers = [];
|
|
563
|
-
droppableContainers.getEnabled().forEach((entry) => {
|
|
564
|
-
if (!entry || entry != null && entry.disabled) {
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
const rect = droppableRects.get(entry.id);
|
|
568
|
-
if (!rect) {
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
switch (event.code) {
|
|
572
|
-
case KeyboardCode.Down:
|
|
573
|
-
if (collisionRect.top < rect.top) {
|
|
574
|
-
filteredContainers.push(entry);
|
|
575
|
-
}
|
|
576
|
-
break;
|
|
577
|
-
case KeyboardCode.Up:
|
|
578
|
-
if (collisionRect.top > rect.top) {
|
|
579
|
-
filteredContainers.push(entry);
|
|
580
|
-
}
|
|
581
|
-
break;
|
|
582
|
-
case KeyboardCode.Left:
|
|
583
|
-
if (collisionRect.left > rect.left) {
|
|
584
|
-
filteredContainers.push(entry);
|
|
585
|
-
}
|
|
586
|
-
break;
|
|
587
|
-
case KeyboardCode.Right:
|
|
588
|
-
if (collisionRect.left < rect.left) {
|
|
589
|
-
filteredContainers.push(entry);
|
|
590
|
-
}
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
const collisions = closestCorners({
|
|
595
|
-
active,
|
|
596
|
-
collisionRect,
|
|
597
|
-
droppableRects,
|
|
598
|
-
droppableContainers: filteredContainers,
|
|
599
|
-
pointerCoordinates: null
|
|
600
|
-
});
|
|
601
|
-
let closestId = getFirstCollision(collisions, "id");
|
|
602
|
-
if (closestId === (over == null ? void 0 : over.id) && collisions.length > 1) {
|
|
603
|
-
closestId = collisions[1].id;
|
|
604
|
-
}
|
|
605
|
-
if (closestId != null) {
|
|
606
|
-
const activeDroppable = droppableContainers.get(active.id);
|
|
607
|
-
const newDroppable = droppableContainers.get(closestId);
|
|
608
|
-
const newRect = newDroppable ? droppableRects.get(newDroppable.id) : null;
|
|
609
|
-
const newNode = newDroppable == null ? void 0 : newDroppable.node.current;
|
|
610
|
-
if (newNode && newRect && activeDroppable && newDroppable) {
|
|
611
|
-
const newScrollAncestors = getScrollableAncestors(newNode);
|
|
612
|
-
const hasDifferentScrollAncestors = newScrollAncestors.some((element, index) => scrollableAncestors[index] !== element);
|
|
613
|
-
const hasSameContainer = isSameContainer(activeDroppable, newDroppable);
|
|
614
|
-
const isAfterActive = isAfter(activeDroppable, newDroppable);
|
|
615
|
-
const offset = hasDifferentScrollAncestors || !hasSameContainer ? {
|
|
616
|
-
x: 0,
|
|
617
|
-
y: 0
|
|
618
|
-
} : {
|
|
619
|
-
x: isAfterActive ? collisionRect.width - newRect.width : 0,
|
|
620
|
-
y: isAfterActive ? collisionRect.height - newRect.height : 0
|
|
621
|
-
};
|
|
622
|
-
const rectCoordinates = {
|
|
623
|
-
x: newRect.left,
|
|
624
|
-
y: newRect.top
|
|
625
|
-
};
|
|
626
|
-
const newCoordinates = offset.x && offset.y ? rectCoordinates : subtract(rectCoordinates, offset);
|
|
627
|
-
return newCoordinates;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
return void 0;
|
|
632
|
-
};
|
|
633
|
-
function isSameContainer(a, b) {
|
|
634
|
-
if (!hasSortableData(a) || !hasSortableData(b)) {
|
|
635
|
-
return false;
|
|
636
|
-
}
|
|
637
|
-
return a.data.current.sortable.containerId === b.data.current.sortable.containerId;
|
|
638
|
-
}
|
|
639
|
-
function isAfter(a, b) {
|
|
640
|
-
if (!hasSortableData(a) || !hasSortableData(b)) {
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
if (!isSameContainer(a, b)) {
|
|
644
|
-
return false;
|
|
645
|
-
}
|
|
646
|
-
return a.data.current.sortable.index < b.data.current.sortable.index;
|
|
647
|
-
}
|
|
648
12
|
const useBanners = () => {
|
|
649
13
|
const getUploadedFiles = async () => {
|
|
650
14
|
try {
|
|
@@ -1062,7 +426,7 @@ const BannerPage = () => {
|
|
|
1062
426
|
cancelText: "Cancel"
|
|
1063
427
|
});
|
|
1064
428
|
if (!isConfirmed) return;
|
|
1065
|
-
const
|
|
429
|
+
const ids = Array.from(selectedIds);
|
|
1066
430
|
setIsLoading(true);
|
|
1067
431
|
try {
|
|
1068
432
|
await fetch("/admin/banners", {
|
|
@@ -1072,7 +436,7 @@ const BannerPage = () => {
|
|
|
1072
436
|
"Content-Type": "application/json",
|
|
1073
437
|
Accept: "application/json"
|
|
1074
438
|
},
|
|
1075
|
-
body: JSON.stringify({ ids
|
|
439
|
+
body: JSON.stringify({ ids })
|
|
1076
440
|
});
|
|
1077
441
|
setSelectedIds(/* @__PURE__ */ new Set());
|
|
1078
442
|
refetch();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET = GET;
|
|
4
|
+
const framework_1 = require("@medusajs/framework");
|
|
5
|
+
const banner_1 = require("../../../modules/banner");
|
|
6
|
+
async function GET(req, res) {
|
|
7
|
+
const bannerService = await framework_1.container.resolve(banner_1.BANNER_MODULE);
|
|
8
|
+
const [banners, count] = await bannerService.listAndCountBanners({}, {
|
|
9
|
+
order: {
|
|
10
|
+
order: "DESC",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
res.json({
|
|
14
|
+
banners,
|
|
15
|
+
count,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL3N0b3JlL2Jhbm5lcnMvcm91dGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFPQSxrQkFtQkM7QUFyQkQsbURBQWdEO0FBQ2hELG9EQUF3RDtBQUNqRCxLQUFLLFVBQVUsR0FBRyxDQUN2QixHQUErQixFQUMvQixHQUFtQjtJQUVuQixNQUFNLGFBQWEsR0FDakIsTUFBTSxxQkFBUyxDQUFDLE9BQU8sQ0FBc0Isc0JBQWEsQ0FBQyxDQUFDO0lBQzlELE1BQU0sQ0FBQyxPQUFPLEVBQUUsS0FBSyxDQUFDLEdBQUcsTUFBTSxhQUFhLENBQUMsbUJBQW1CLENBQzlELEVBQUUsRUFDRjtRQUNFLEtBQUssRUFBRTtZQUNMLEtBQUssRUFBRSxNQUFNO1NBQ2Q7S0FDRixDQUNGLENBQUM7SUFFRixHQUFHLENBQUMsSUFBSSxDQUFDO1FBQ1AsT0FBTztRQUNQLEtBQUs7S0FDTixDQUFDLENBQUM7QUFDTCxDQUFDIn0=
|