@molecule/app-drag-drop-dndkit-angular 0.0.0-stage → 0.0.1-stage
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/LICENSE +202 -0
- package/README.md +395 -2
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/sortable-item-controller.d.ts +89 -0
- package/dist/sortable-item-controller.d.ts.map +1 -0
- package/dist/sortable-item-controller.js +127 -0
- package/dist/sortable-item-controller.js.map +1 -0
- package/dist/sortable-item.d.ts +73 -0
- package/dist/sortable-item.d.ts.map +1 -0
- package/dist/sortable-item.js +136 -0
- package/dist/sortable-item.js.map +1 -0
- package/dist/sortable-list-context.d.ts +24 -0
- package/dist/sortable-list-context.d.ts.map +1 -0
- package/dist/sortable-list-context.js +9 -0
- package/dist/sortable-list-context.js.map +1 -0
- package/dist/sortable-list.d.ts +86 -0
- package/dist/sortable-list.d.ts.map +1 -0
- package/dist/sortable-list.js +140 -0
- package/dist/sortable-list.js.map +1 -0
- package/dist/use-sortable-item.d.ts +48 -0
- package/dist/use-sortable-item.d.ts.map +1 -0
- package/dist/use-sortable-item.js +50 -0
- package/dist/use-sortable-item.js.map +1 -0
- package/package.json +70 -4
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Angular sortable list.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { Directive, effect, forwardRef, input } from '@angular/core';
|
|
7
|
+
import { DragDropManager } from '@dnd-kit/dom';
|
|
8
|
+
import { coreDragOver, coreDragStart, resolveSortableAxis, sortableListDrop, sortableListModifiers, sortableListPlugins, sortableListSensors, } from '@molecule/app-drag-drop-dndkit';
|
|
9
|
+
import { SORTABLE_LIST } from './sortable-list-context.js';
|
|
10
|
+
import * as i0 from "@angular/core";
|
|
11
|
+
/**
|
|
12
|
+
* A list the user reorders with the pointer, touch or the keyboard (Space or
|
|
13
|
+
* Enter to pick an item up, the arrow keys to move it, Space or Enter to drop
|
|
14
|
+
* it, Escape to cancel). A screen reader hears translated instructions and
|
|
15
|
+
* where the item is as it moves. A drop that moves an item calls `onReorder`
|
|
16
|
+
* with the new order; render `items` from your state.
|
|
17
|
+
*
|
|
18
|
+
* The callbacks are inputs, not outputs, so a consumer passes the same
|
|
19
|
+
* functions a React list takes (`[onReorder]="save"`). Each row carries
|
|
20
|
+
* {@link SortableItem} (`[molSortableItem]`, or `useSortableItem` in a
|
|
21
|
+
* component's field initializer).
|
|
22
|
+
*
|
|
23
|
+
* @template T - The item type. Items must have a stable string `id`.
|
|
24
|
+
*/
|
|
25
|
+
export class SortableList {
|
|
26
|
+
/** The items, in their current order. */
|
|
27
|
+
items = input([], /* @ts-ignore */
|
|
28
|
+
...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
|
|
29
|
+
/**
|
|
30
|
+
* Called with the whole list in its new order when a drop moves an item. Not
|
|
31
|
+
* called when the drag is cancelled, the list is disabled, or the item is
|
|
32
|
+
* dropped where it started. Persist the order here; the list renders `items`.
|
|
33
|
+
*/
|
|
34
|
+
onReorder = input.required(/* @ts-ignore */
|
|
35
|
+
...(ngDevMode ? [{ debugName: "onReorder" }] : /* istanbul ignore next */ []));
|
|
36
|
+
/** The axis an item may move along. Defaults to `strategy`'s axis, else `'vertical'`. */
|
|
37
|
+
axis = input(/* @ts-ignore */
|
|
38
|
+
...(ngDevMode ? [undefined, { debugName: "axis" }] : /* istanbul ignore next */ []));
|
|
39
|
+
/** The layout: `'grid'` lets items move in any direction. Used when `axis` is absent. */
|
|
40
|
+
strategy = input(/* @ts-ignore */
|
|
41
|
+
...(ngDevMode ? [undefined, { debugName: "strategy" }] : /* istanbul ignore next */ []));
|
|
42
|
+
/** Disables dragging every item. Defaults to `false`. */
|
|
43
|
+
disabled = input(false, /* @ts-ignore */
|
|
44
|
+
...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
45
|
+
/** Pointer activation thresholds and the Escape behavior. */
|
|
46
|
+
config = input(/* @ts-ignore */
|
|
47
|
+
...(ngDevMode ? [undefined, { debugName: "config" }] : /* istanbul ignore next */ []));
|
|
48
|
+
/**
|
|
49
|
+
* The name a screen reader hears for an item in the drag announcements
|
|
50
|
+
* ("Picked up {label}, position 2 of 5."). Defaults to the item's `id`.
|
|
51
|
+
*/
|
|
52
|
+
getItemLabel = input(/* @ts-ignore */
|
|
53
|
+
...(ngDevMode ? [undefined, { debugName: "getItemLabel" }] : /* istanbul ignore next */ []));
|
|
54
|
+
/** Called when a drag starts. */
|
|
55
|
+
onDragStart = input(/* @ts-ignore */
|
|
56
|
+
...(ngDevMode ? [undefined, { debugName: "onDragStart" }] : /* istanbul ignore next */ []));
|
|
57
|
+
/** Called while a dragged item is over another item. */
|
|
58
|
+
onDragOver = input(/* @ts-ignore */
|
|
59
|
+
...(ngDevMode ? [undefined, { debugName: "onDragOver" }] : /* istanbul ignore next */ []));
|
|
60
|
+
/** Called when a drag ends, before `onReorder`. `overId` is the item whose place it took. */
|
|
61
|
+
onDragEnd = input(/* @ts-ignore */
|
|
62
|
+
...(ngDevMode ? [undefined, { debugName: "onDragEnd" }] : /* istanbul ignore next */ []));
|
|
63
|
+
/** The dnd-kit manager this list owns. */
|
|
64
|
+
manager;
|
|
65
|
+
/**
|
|
66
|
+
* Creates the list's manager with the shared sensors, modifiers and
|
|
67
|
+
* translated plugins, and reports the manager's drag events to the inputs.
|
|
68
|
+
*/
|
|
69
|
+
constructor() {
|
|
70
|
+
this.manager = new DragDropManager({
|
|
71
|
+
plugins: sortableListPlugins({
|
|
72
|
+
labelOf: (id) => {
|
|
73
|
+
const item = this.items().find((candidate) => candidate.id === id);
|
|
74
|
+
const getItemLabel = this.getItemLabel();
|
|
75
|
+
return item && getItemLabel ? getItemLabel(item) : id;
|
|
76
|
+
},
|
|
77
|
+
count: () => this.items().length,
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
this.manager.monitor.addEventListener('dragstart', ({ operation }) => {
|
|
81
|
+
const started = coreDragStart(operation.source);
|
|
82
|
+
if (started)
|
|
83
|
+
this.onDragStart()?.(started);
|
|
84
|
+
});
|
|
85
|
+
this.manager.monitor.addEventListener('dragover', ({ operation }) => {
|
|
86
|
+
const over = coreDragOver(operation.source, operation.target);
|
|
87
|
+
if (over)
|
|
88
|
+
this.onDragOver()?.(over);
|
|
89
|
+
});
|
|
90
|
+
this.manager.monitor.addEventListener('dragend', (event) => {
|
|
91
|
+
const drop = sortableListDrop(this.items(), event, this.disabled());
|
|
92
|
+
if (drop.event)
|
|
93
|
+
this.onDragEnd()?.(drop.event);
|
|
94
|
+
if (drop.reordered)
|
|
95
|
+
this.onReorder()(drop.reordered);
|
|
96
|
+
});
|
|
97
|
+
// Inputs are bound after the constructor, so the sensors and modifiers are
|
|
98
|
+
// rebuilt here, once their inputs are available, the way React's memos do.
|
|
99
|
+
effect(() => {
|
|
100
|
+
const { activationDelay, activationDistance, cancelOnEscape } = this.config() ?? {};
|
|
101
|
+
const sensors = sortableListSensors({
|
|
102
|
+
activationDelay,
|
|
103
|
+
activationDistance,
|
|
104
|
+
cancelOnEscape,
|
|
105
|
+
});
|
|
106
|
+
// The shared helper is typed as a list or a function of the defaults; it returns a list.
|
|
107
|
+
if (Array.isArray(sensors))
|
|
108
|
+
this.manager.sensors = sensors;
|
|
109
|
+
});
|
|
110
|
+
effect(() => {
|
|
111
|
+
const modifiers = sortableListModifiers(resolveSortableAxis(this.axis(), this.strategy()));
|
|
112
|
+
if (Array.isArray(modifiers))
|
|
113
|
+
this.manager.modifiers = modifiers;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The item's index in the list's current `items`.
|
|
118
|
+
*
|
|
119
|
+
* @param id - The item's id.
|
|
120
|
+
* @returns Its index, or `-1` when the list has no such item.
|
|
121
|
+
*/
|
|
122
|
+
indexOf(id) {
|
|
123
|
+
return this.items().findIndex((item) => item.id === id);
|
|
124
|
+
}
|
|
125
|
+
/** Destroys the manager, which removes the instructions and the live region. */
|
|
126
|
+
ngOnDestroy() {
|
|
127
|
+
this.manager.destroy();
|
|
128
|
+
}
|
|
129
|
+
static ɵfac = function SortableList_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || SortableList)(); };
|
|
130
|
+
static ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: SortableList, selectors: [["", "molSortableList", ""]], inputs: { items: [1, "items"], onReorder: [1, "onReorder"], axis: [1, "axis"], strategy: [1, "strategy"], disabled: [1, "disabled"], config: [1, "config"], getItemLabel: [1, "getItemLabel"], onDragStart: [1, "onDragStart"], onDragOver: [1, "onDragOver"], onDragEnd: [1, "onDragEnd"] }, features: [i0.ɵɵProvidersFeature([{ provide: SORTABLE_LIST, useExisting: forwardRef(() => SortableList) }])] });
|
|
131
|
+
}
|
|
132
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SortableList, [{
|
|
133
|
+
type: Directive,
|
|
134
|
+
args: [{
|
|
135
|
+
selector: '[molSortableList]',
|
|
136
|
+
standalone: true,
|
|
137
|
+
providers: [{ provide: SORTABLE_LIST, useExisting: forwardRef(() => SortableList) }],
|
|
138
|
+
}]
|
|
139
|
+
}], () => [], { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], onReorder: [{ type: i0.Input, args: [{ isSignal: true, alias: "onReorder", required: true }] }], axis: [{ type: i0.Input, args: [{ isSignal: true, alias: "axis", required: false }] }], strategy: [{ type: i0.Input, args: [{ isSignal: true, alias: "strategy", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: false }] }], getItemLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "getItemLabel", required: false }] }], onDragStart: [{ type: i0.Input, args: [{ isSignal: true, alias: "onDragStart", required: false }] }], onDragOver: [{ type: i0.Input, args: [{ isSignal: true, alias: "onDragOver", required: false }] }], onDragEnd: [{ type: i0.Input, args: [{ isSignal: true, alias: "onDragEnd", required: false }] }] }); })();
|
|
140
|
+
//# sourceMappingURL=sortable-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortable-list.js","sourceRoot":"","sources":["../src/sortable-list.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAkB,MAAM,eAAe,CAAA;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAU9C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EAAE,aAAa,EAAyB,MAAM,4BAA4B,CAAA;;AAUjF;;;;;;;;;;;;;GAaG;AAMH,MAAM,OAAO,YAAY;IAGvB,yCAAyC;IAChC,KAAK,GAAG,KAAK,CAAM,EAAE;8EAAC,CAAA;IAC/B;;;;OAIG;IACM,SAAS,GAAG,KAAK,CAAC,QAAQ;kFAAwB,CAAA;IAC3D,yFAAyF;IAChF,IAAI,GAAG,KAAK;wFAAgB,CAAA;IACrC,yFAAyF;IAChF,QAAQ,GAAG,KAAK;4FAAoB,CAAA;IAC7C,yDAAyD;IAChD,QAAQ,GAAG,KAAK,CAAC,KAAK;iFAAC,CAAA;IAChC,6DAA6D;IACpD,MAAM,GAAG,KAAK;0FAAgB,CAAA;IACvC;;;OAGG;IACM,YAAY,GAAG,KAAK;gGAAuB,CAAA;IACpD,iCAAiC;IACxB,WAAW,GAAG,KAAK;+FAAmC,CAAA;IAC/D,wDAAwD;IAC/C,UAAU,GAAG,KAAK;8FAAkC,CAAA;IAC7D,6FAA6F;IACpF,SAAS,GAAG,KAAK;6FAAiC,CAAA;IAE3D,0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;IAED,gFAAgF;IAChF,WAAW;QACT,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC;sGA7FU,YAAY;6DAAZ,YAAY,2WAFZ,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC;;iFAEzE,YAAY;cALxB,SAAS;eAAC;gBACT,QAAQ,EAAE,mBAAmB;gBAC7B,UAAU,EAAE,IAAI;gBAChB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,CAAC;aACrF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The injection-context function form of one row of an Angular sortable list.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type Signal } from '@angular/core';
|
|
7
|
+
import type { SortableItemOptions } from '@molecule/app-drag-drop-dndkit';
|
|
8
|
+
/** What {@link useSortableItem} returns for one row. */
|
|
9
|
+
export interface SortableItemState {
|
|
10
|
+
/**
|
|
11
|
+
* Attach to the row's element. dnd-kit makes it focusable and sets its
|
|
12
|
+
* `role`, `aria-roledescription`, `aria-describedby`, `aria-pressed` and
|
|
13
|
+
* `aria-disabled`.
|
|
14
|
+
*
|
|
15
|
+
* @param element - The row's element, or `null` on unmount.
|
|
16
|
+
*/
|
|
17
|
+
ref: (element: Element | null) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Attach to a drag handle inside the row so only the handle starts a drag;
|
|
20
|
+
* leave it unused to drag by the whole row.
|
|
21
|
+
*
|
|
22
|
+
* @param element - The handle's element, or `null` on unmount.
|
|
23
|
+
*/
|
|
24
|
+
handleRef: (element: Element | null) => void;
|
|
25
|
+
/** `true` while this row is being dragged. */
|
|
26
|
+
isDragging: Signal<boolean>;
|
|
27
|
+
/** `true` while another dragged row is over this one. */
|
|
28
|
+
isDropTarget: Signal<boolean>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Makes one row of a `[molSortableList]` draggable. Call it in a component's
|
|
32
|
+
* field initializer (or constructor) inside the list, then attach `ref` to the
|
|
33
|
+
* row's element:
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* readonly row = useSortableItem({ id: 'a' })
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* The list's current order and disabled flag are read through signals, so the
|
|
40
|
+
* row follows them as the list changes without being remounted.
|
|
41
|
+
*
|
|
42
|
+
* @param options - The row's item id, drag data and disabled flag.
|
|
43
|
+
* @returns The refs to attach and the row's drag state.
|
|
44
|
+
* @throws {Error} When called outside a `[molSortableList]`, since the row has
|
|
45
|
+
* no list to register with.
|
|
46
|
+
*/
|
|
47
|
+
export declare function useSortableItem(options: SortableItemOptions): SortableItemState;
|
|
48
|
+
//# sourceMappingURL=use-sortable-item.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-sortable-item.d.ts","sourceRoot":"","sources":["../src/use-sortable-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAA8B,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAA;AAKzE,wDAAwD;AACxD,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;IACtC;;;;;OAKG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;IAC5C,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IAC3B,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;CAC9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,iBAAiB,CAsB/E"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The injection-context function form of one row of an Angular sortable list.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { DestroyRef, effect, inject } from '@angular/core';
|
|
7
|
+
import { SortableItemController } from './sortable-item-controller.js';
|
|
8
|
+
import { SORTABLE_LIST } from './sortable-list-context.js';
|
|
9
|
+
/**
|
|
10
|
+
* Makes one row of a `[molSortableList]` draggable. Call it in a component's
|
|
11
|
+
* field initializer (or constructor) inside the list, then attach `ref` to the
|
|
12
|
+
* row's element:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* readonly row = useSortableItem({ id: 'a' })
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* The list's current order and disabled flag are read through signals, so the
|
|
19
|
+
* row follows them as the list changes without being remounted.
|
|
20
|
+
*
|
|
21
|
+
* @param options - The row's item id, drag data and disabled flag.
|
|
22
|
+
* @returns The refs to attach and the row's drag state.
|
|
23
|
+
* @throws {Error} When called outside a `[molSortableList]`, since the row has
|
|
24
|
+
* no list to register with.
|
|
25
|
+
*/
|
|
26
|
+
export function useSortableItem(options) {
|
|
27
|
+
const list = inject(SORTABLE_LIST, { optional: true });
|
|
28
|
+
if (!list)
|
|
29
|
+
throw new Error('useSortableItem must be called inside a [molSortableList].');
|
|
30
|
+
const controller = new SortableItemController({
|
|
31
|
+
manager: list.manager,
|
|
32
|
+
list,
|
|
33
|
+
options,
|
|
34
|
+
});
|
|
35
|
+
const destroyRef = inject(DestroyRef);
|
|
36
|
+
destroyRef.onDestroy(() => controller.destroy());
|
|
37
|
+
effect(() => {
|
|
38
|
+
controller.setId(options.id);
|
|
39
|
+
controller.setIndex(list.indexOf(options.id));
|
|
40
|
+
controller.setDisabled((options.disabled ?? false) || list.disabled());
|
|
41
|
+
controller.setData(options.data);
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
ref: (element) => controller.setElement(element ?? undefined),
|
|
45
|
+
handleRef: (element) => controller.setHandle(element ?? undefined),
|
|
46
|
+
isDragging: controller.isDragging.asReadonly(),
|
|
47
|
+
isDropTarget: controller.isDropTarget.asReadonly(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=use-sortable-item.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-sortable-item.js","sourceRoot":"","sources":["../src/use-sortable-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,eAAe,CAAA;AAIvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAyB1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAAC,OAA4B;IAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IACtD,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAA;IACxF,MAAM,UAAU,GAAG,IAAI,sBAAsB,CAAC;QAC5C,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI;QACJ,OAAO;KACR,CAAC,CAAA;IACF,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;IACrC,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAA;IAChD,MAAM,CAAC,GAAG,EAAE;QACV,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC5B,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;QAC7C,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QACtE,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IACF,OAAO;QACL,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,IAAI,SAAS,CAAC;QAC7D,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC;QAClE,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,UAAU,EAAE;QAC9C,YAAY,EAAE,UAAU,CAAC,YAAY,CAAC,UAAU,EAAE;KACnD,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-drag-drop-dndkit-angular",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-stage",
|
|
4
|
+
"description": "Angular binding for @molecule/app-drag-drop-dndkit — a sortable list that reorders with the pointer, touch and the keyboard, with translated screen-reader announcements.",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-drag-drop-dndkit-angular",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "ngc",
|
|
21
|
+
"dev": "ngc --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"molecule",
|
|
27
|
+
"drag",
|
|
28
|
+
"drop",
|
|
29
|
+
"sortable",
|
|
30
|
+
"dnd-kit",
|
|
31
|
+
"angular"
|
|
32
|
+
],
|
|
33
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
34
|
+
"license": "Apache-2.0",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
38
|
+
"directory": "packages/app/bonds/drag-drop/dndkit-angular"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=20"
|
|
42
|
+
},
|
|
43
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@angular/core": "^22.0.0",
|
|
49
|
+
"@molecule/app-drag-drop": "^1.0.1",
|
|
50
|
+
"@molecule/app-drag-drop-dndkit": "^2.0.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@dnd-kit/dom": "0.5.3"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@angular/common": "22.2.3",
|
|
57
|
+
"@angular/compiler": "22.2.3",
|
|
58
|
+
"@angular/compiler-cli": "22.2.3",
|
|
59
|
+
"@angular/core": "22.2.3",
|
|
60
|
+
"@angular/platform-browser": "22.2.3",
|
|
61
|
+
"@molecule/app-drag-drop": "1.0.4",
|
|
62
|
+
"@molecule/app-drag-drop-dndkit": "2.0.0",
|
|
63
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
64
|
+
"@molecule/app-i18n": "1.2.2",
|
|
65
|
+
"@types/node": "26.6.5",
|
|
66
|
+
"jsdom": "30.1.3",
|
|
67
|
+
"rxjs": "7.8.2",
|
|
68
|
+
"typescript": "6.0.3",
|
|
69
|
+
"vitest": "4.1.12",
|
|
70
|
+
"zone.js": "0.16.3"
|
|
71
|
+
}
|
|
72
|
+
}
|