skandha-facets 0.11.0 → 0.12.0
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/facets/Addition.d.ts +4 -2
- package/facets/Addition.js +22 -11
- package/facets/DragAndDrop.d.ts +2 -2
- package/facets/DragAndDrop.js +1 -1
- package/facets/DragAndDropUIConnector.d.ts +3 -6
- package/facets/DragAndDropUIConnector.js +14 -32
- package/facets/Edit.d.ts +1 -0
- package/facets/Edit.js +12 -6
- package/facets/HighlightUIConnector.d.ts +8 -14
- package/facets/HighlightUIConnector.js +30 -64
- package/facets/Hovering.d.ts +10 -0
- package/facets/Hovering.js +33 -0
- package/facets/Insertion.d.ts +3 -9
- package/facets/Insertion.js +1 -1
- package/facets/Selection.js +1 -1
- package/facets/SelectionUIConnector.d.ts +12 -12
- package/facets/SelectionUIConnector.js +40 -69
- package/facets/Store.d.ts +1 -0
- package/facets/Store.js +7 -1
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/internal/utils.js +9 -2
- package/package.json +1 -1
- package/policies/DragSourceFromNewItem.d.ts +2 -2
- package/policies/correctHighlight.js +3 -3
- package/policies/createInsertionPreview.js +3 -3
- package/policies/newItemsAreInsertedWhenConfirmed.js +3 -3
- package/policies/selectionIsInsertedOnDragAndDrop.d.ts +2 -2
- package/policies/selectionIsInsertedOnDragAndDrop.js +5 -2
- package/facets/Labelling.d.ts +0 -28
- package/facets/Labelling.js +0 -61
package/facets/Addition.d.ts
CHANGED
|
@@ -4,9 +4,11 @@ export declare class Addition<T = any> {
|
|
|
4
4
|
static className: () => string;
|
|
5
5
|
item?: T;
|
|
6
6
|
parentId?: string;
|
|
7
|
+
setParentId(parentId?: string): void;
|
|
8
|
+
setItem(item?: T): void;
|
|
7
9
|
add(args: {
|
|
8
10
|
values?: GenericObjectT;
|
|
9
|
-
}):
|
|
11
|
+
}): any;
|
|
10
12
|
confirm(): Promise<void>;
|
|
11
13
|
cancel(): void;
|
|
12
14
|
_reset(): void;
|
|
@@ -18,7 +20,7 @@ type Cbs<T> = {
|
|
|
18
20
|
highlightNewItem(): void;
|
|
19
21
|
};
|
|
20
22
|
cancel: {
|
|
21
|
-
unstageAdd(): void;
|
|
23
|
+
unstageAdd(parentId: string | undefined): void;
|
|
22
24
|
};
|
|
23
25
|
confirm: {
|
|
24
26
|
confirmAdd(): void;
|
package/facets/Addition.js
CHANGED
|
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { getCallbacks, withCbs } from 'aspiration';
|
|
8
|
-
import { data,
|
|
8
|
+
import { data, operation } from 'skandha';
|
|
9
9
|
class Addition {
|
|
10
10
|
constructor() {
|
|
11
11
|
Object.defineProperty(this, "item", {
|
|
@@ -21,34 +21,39 @@ class Addition {
|
|
|
21
21
|
value: void 0
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
setParentId(parentId) {
|
|
25
|
+
this.parentId = parentId;
|
|
26
|
+
}
|
|
27
|
+
setItem(item) {
|
|
28
|
+
this.item = item;
|
|
29
|
+
}
|
|
24
30
|
add(args) {
|
|
25
31
|
var _a;
|
|
26
32
|
const cbs = getCallbacks(this);
|
|
27
33
|
cbs.stageAdd && cbs.stageAdd();
|
|
28
34
|
const newItem = (_a = args.values) !== null && _a !== void 0 ? _a : cbs.createItem();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return item;
|
|
33
|
-
}));
|
|
35
|
+
this.setItem(newItem);
|
|
36
|
+
cbs.highlightNewItem && cbs.highlightNewItem();
|
|
37
|
+
return newItem;
|
|
34
38
|
}
|
|
35
39
|
confirm() {
|
|
36
40
|
const cbs = getCallbacks(this);
|
|
37
41
|
const result = cbs.confirmAdd ? cbs.confirmAdd() : undefined;
|
|
38
|
-
return Promise.resolve(result).then(
|
|
42
|
+
return Promise.resolve(result).then(() => {
|
|
39
43
|
this._reset();
|
|
40
|
-
})
|
|
44
|
+
});
|
|
41
45
|
}
|
|
42
46
|
cancel() {
|
|
43
47
|
const cbs = getCallbacks(this);
|
|
44
48
|
if (this.item) {
|
|
49
|
+
const parentId = this.parentId;
|
|
45
50
|
this._reset();
|
|
46
|
-
cbs.unstageAdd && cbs.unstageAdd();
|
|
51
|
+
cbs.unstageAdd && cbs.unstageAdd(parentId);
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
_reset() {
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
55
|
+
this.setItem(undefined);
|
|
56
|
+
this.setParentId(undefined);
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
Object.defineProperty(Addition, "className", {
|
|
@@ -63,6 +68,12 @@ __decorate([
|
|
|
63
68
|
__decorate([
|
|
64
69
|
data
|
|
65
70
|
], Addition.prototype, "parentId", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
operation({ log: false })
|
|
73
|
+
], Addition.prototype, "setParentId", null);
|
|
74
|
+
__decorate([
|
|
75
|
+
operation({ log: false })
|
|
76
|
+
], Addition.prototype, "setItem", null);
|
|
66
77
|
__decorate([
|
|
67
78
|
operation,
|
|
68
79
|
withCbs()
|
package/facets/DragAndDrop.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DefineCbs } from 'aspiration';
|
|
2
|
-
import {
|
|
2
|
+
import { HoverPositionT } from './Hovering';
|
|
3
3
|
export declare class DragAndDrop {
|
|
4
4
|
static className: () => string;
|
|
5
5
|
drop(args: {
|
|
6
|
-
|
|
6
|
+
hoverPosition: HoverPositionT;
|
|
7
7
|
}): Promise<void>;
|
|
8
8
|
}
|
|
9
9
|
type Cbs = {
|
package/facets/DragAndDrop.js
CHANGED
|
@@ -9,7 +9,7 @@ import { operation } from 'skandha';
|
|
|
9
9
|
import { selectionIsInsertedOnDragAndDrop } from '../policies/selectionIsInsertedOnDragAndDrop';
|
|
10
10
|
const dropDefaultCbs = (dragAndDrop) => ({
|
|
11
11
|
drop: function () {
|
|
12
|
-
selectionIsInsertedOnDragAndDrop(dragAndDrop, this.args.
|
|
12
|
+
selectionIsInsertedOnDragAndDrop(dragAndDrop, this.args.hoverPosition);
|
|
13
13
|
},
|
|
14
14
|
});
|
|
15
15
|
class DragAndDrop {
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { DragAndDrop } from './DragAndDrop';
|
|
2
|
-
import {
|
|
2
|
+
import { Hovering } from './Hovering';
|
|
3
3
|
export interface DragAndDropUIConnectorT {
|
|
4
|
-
hoverPosition?: DropPositionT;
|
|
5
|
-
setHoverPosition(x?: DropPositionT): void;
|
|
6
4
|
handle(itemId: string): DragAndDropUIPropsT;
|
|
7
5
|
}
|
|
8
6
|
export type PropsT = {
|
|
9
7
|
dragAndDrop: DragAndDrop;
|
|
8
|
+
hovering: Hovering;
|
|
10
9
|
};
|
|
11
10
|
export declare class DragAndDropUIConnector implements DragAndDropUIConnectorT {
|
|
12
11
|
props: PropsT;
|
|
13
|
-
hoverPosition?: DropPositionT;
|
|
14
12
|
constructor(props: PropsT);
|
|
15
|
-
setHoverPosition(x?: DropPositionT): void;
|
|
16
13
|
handle(itemId: string): DragAndDropUIPropsT;
|
|
17
14
|
}
|
|
18
15
|
export declare function getDragState(hoverPosition: any, itemId: string): "before" | "after" | "none";
|
|
@@ -31,4 +28,4 @@ export declare function dragAndDropUIHandlers<T extends DragAndDropUIPropsT>(pro
|
|
|
31
28
|
onDrop: ((event: any) => void) | undefined;
|
|
32
29
|
onDragEnd: ((event: any) => void) | undefined;
|
|
33
30
|
};
|
|
34
|
-
export declare function createDragAndDropUIConnector(dragAndDrop: DragAndDrop): DragAndDropUIConnector;
|
|
31
|
+
export declare function createDragAndDropUIConnector(dragAndDrop: DragAndDrop, hovering: Hovering): DragAndDropUIConnector;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { data, decorateCb, operation } from 'skandha';
|
|
8
1
|
import { isBefore } from '../internal/utils';
|
|
9
2
|
export class DragAndDropUIConnector {
|
|
10
3
|
constructor(props) {
|
|
@@ -14,50 +7,36 @@ export class DragAndDropUIConnector {
|
|
|
14
7
|
writable: true,
|
|
15
8
|
value: void 0
|
|
16
9
|
});
|
|
17
|
-
Object.defineProperty(this, "hoverPosition", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: void 0
|
|
22
|
-
});
|
|
23
10
|
this.props = props;
|
|
24
11
|
}
|
|
25
|
-
setHoverPosition(x) {
|
|
26
|
-
this.hoverPosition = x;
|
|
27
|
-
}
|
|
28
12
|
handle(itemId) {
|
|
29
13
|
return {
|
|
30
14
|
draggable: true,
|
|
31
15
|
onDragStart: () => { },
|
|
32
16
|
onDragOver: (e) => {
|
|
33
17
|
e.preventDefault();
|
|
34
|
-
this.setHoverPosition({
|
|
18
|
+
this.props.hovering.setHoverPosition({
|
|
35
19
|
targetItemId: itemId,
|
|
36
20
|
isBefore: isBefore(e),
|
|
37
21
|
});
|
|
38
22
|
},
|
|
39
23
|
onDragEnd: () => {
|
|
40
|
-
this.setHoverPosition(undefined);
|
|
24
|
+
this.props.hovering.setHoverPosition(undefined);
|
|
41
25
|
},
|
|
42
26
|
onDrop: () => {
|
|
43
|
-
|
|
27
|
+
const hoverPosition = this.props.hovering.hoverPosition;
|
|
28
|
+
if (hoverPosition) {
|
|
44
29
|
this.props.dragAndDrop
|
|
45
|
-
.drop({
|
|
46
|
-
.then(
|
|
47
|
-
this.setHoverPosition(undefined);
|
|
48
|
-
})
|
|
30
|
+
.drop({ hoverPosition: hoverPosition })
|
|
31
|
+
.then(() => {
|
|
32
|
+
this.props.hovering.setHoverPosition(undefined);
|
|
33
|
+
});
|
|
49
34
|
}
|
|
50
35
|
},
|
|
51
|
-
dragState: getDragState(this.hoverPosition, itemId),
|
|
36
|
+
dragState: getDragState(this.props.hovering.hoverPosition, itemId),
|
|
52
37
|
};
|
|
53
38
|
}
|
|
54
39
|
}
|
|
55
|
-
__decorate([
|
|
56
|
-
data
|
|
57
|
-
], DragAndDropUIConnector.prototype, "hoverPosition", void 0);
|
|
58
|
-
__decorate([
|
|
59
|
-
operation({ log: false })
|
|
60
|
-
], DragAndDropUIConnector.prototype, "setHoverPosition", null);
|
|
61
40
|
export function getDragState(hoverPosition, itemId) {
|
|
62
41
|
return (hoverPosition === null || hoverPosition === void 0 ? void 0 : hoverPosition.targetItemId) === itemId
|
|
63
42
|
? (hoverPosition === null || hoverPosition === void 0 ? void 0 : hoverPosition.isBefore)
|
|
@@ -74,6 +53,9 @@ export function dragAndDropUIHandlers(props) {
|
|
|
74
53
|
onDragEnd: props.onDragEnd,
|
|
75
54
|
};
|
|
76
55
|
}
|
|
77
|
-
export function createDragAndDropUIConnector(dragAndDrop) {
|
|
78
|
-
return new DragAndDropUIConnector({
|
|
56
|
+
export function createDragAndDropUIConnector(dragAndDrop, hovering) {
|
|
57
|
+
return new DragAndDropUIConnector({
|
|
58
|
+
dragAndDrop,
|
|
59
|
+
hovering,
|
|
60
|
+
});
|
|
79
61
|
}
|
package/facets/Edit.d.ts
CHANGED
package/facets/Edit.js
CHANGED
|
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { getCallbacks, withCbs } from 'aspiration';
|
|
8
|
-
import { data,
|
|
8
|
+
import { data, operation } from 'skandha';
|
|
9
9
|
class Edit {
|
|
10
10
|
constructor() {
|
|
11
11
|
Object.defineProperty(this, "isEditing", {
|
|
@@ -15,17 +15,20 @@ class Edit {
|
|
|
15
15
|
value: false
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
+
reset() {
|
|
19
|
+
this.isEditing = false;
|
|
20
|
+
}
|
|
18
21
|
save(args) {
|
|
19
22
|
const cbs = getCallbacks(this);
|
|
20
|
-
return Promise.resolve(cbs.saveItem()).then(
|
|
21
|
-
this.
|
|
22
|
-
return
|
|
23
|
-
})
|
|
23
|
+
return Promise.resolve(cbs.saveItem()).then((savedObj) => {
|
|
24
|
+
this.reset();
|
|
25
|
+
return savedObj;
|
|
26
|
+
});
|
|
24
27
|
}
|
|
25
28
|
cancel() {
|
|
26
29
|
const cbs = getCallbacks(this);
|
|
27
30
|
if (this.isEditing) {
|
|
28
|
-
this.
|
|
31
|
+
this.reset();
|
|
29
32
|
cbs.onCancel && cbs.onCancel();
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -46,6 +49,9 @@ Object.defineProperty(Edit, "className", {
|
|
|
46
49
|
__decorate([
|
|
47
50
|
data
|
|
48
51
|
], Edit.prototype, "isEditing", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
operation
|
|
54
|
+
], Edit.prototype, "reset", null);
|
|
49
55
|
__decorate([
|
|
50
56
|
operation,
|
|
51
57
|
withCbs()
|
|
@@ -1,36 +1,30 @@
|
|
|
1
1
|
import { Highlight } from './Highlight';
|
|
2
|
-
export type HighlightUIConnectorOptionsT = {
|
|
3
|
-
useMouse?: boolean;
|
|
4
|
-
useKeys?: boolean;
|
|
5
|
-
getDomElement?: (id: string, idx: number) => Element | null;
|
|
6
|
-
isKeyDown?: (e: any) => boolean;
|
|
7
|
-
isKeyUp?: (e: any) => boolean;
|
|
8
|
-
getHighlightableIds?: (e: any) => string[];
|
|
9
|
-
};
|
|
10
2
|
export interface HighlightUIConnectorT {
|
|
11
3
|
handle(itemId: string): HighlightUIPropsT;
|
|
12
4
|
}
|
|
13
5
|
export type PropsT = {
|
|
14
6
|
highlight: Highlight;
|
|
15
|
-
options?: HighlightUIConnectorOptionsT;
|
|
16
7
|
};
|
|
17
8
|
export declare class HighlightUIConnector implements HighlightUIConnectorT {
|
|
18
9
|
props: PropsT;
|
|
19
|
-
_handleKeyDown: any;
|
|
20
10
|
_handleMouseDown: any;
|
|
21
11
|
constructor(props: PropsT);
|
|
22
12
|
_highlight(e: any, itemId: string): void;
|
|
23
13
|
_createMouseDownHandler(): (e: any, itemId: string) => void;
|
|
24
|
-
_createKeyDownHandler(options?: HighlightUIConnectorOptionsT): (e: any, itemId: string, getDomElement: HighlightUIConnectorOptionsT['getDomElement']) => void;
|
|
25
14
|
handle(itemId: any): HighlightUIPropsT;
|
|
26
15
|
}
|
|
27
16
|
export type HighlightUIPropsT = {
|
|
28
17
|
isHighlighted: boolean;
|
|
29
18
|
onMouseDown?: any;
|
|
30
|
-
onKeyDown?: any;
|
|
31
19
|
};
|
|
32
20
|
export declare function highlightUIHandlers<T extends HighlightUIPropsT>(props: T): {
|
|
33
21
|
onMouseDown: any;
|
|
34
|
-
onKeyDown: any;
|
|
35
22
|
};
|
|
36
|
-
export declare function createHighlightUIConnector(highlight: Highlight
|
|
23
|
+
export declare function createHighlightUIConnector(highlight: Highlight): HighlightUIConnector;
|
|
24
|
+
export declare const createHighlightKeyHandlers: (highlight: Highlight, options?: {
|
|
25
|
+
keyDown?: string;
|
|
26
|
+
keyUp?: string;
|
|
27
|
+
getHighlightableIds?: () => string[];
|
|
28
|
+
}) => {
|
|
29
|
+
[x: string]: () => void;
|
|
30
|
+
};
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { pickNeighbour } from '../internal/utils';
|
|
2
2
|
export class HighlightUIConnector {
|
|
3
3
|
constructor(props) {
|
|
4
|
-
var _a, _b, _c, _d;
|
|
5
4
|
Object.defineProperty(this, "props", {
|
|
6
5
|
enumerable: true,
|
|
7
6
|
configurable: true,
|
|
8
7
|
writable: true,
|
|
9
8
|
value: void 0
|
|
10
9
|
});
|
|
11
|
-
Object.defineProperty(this, "_handleKeyDown", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: undefined
|
|
16
|
-
});
|
|
17
10
|
Object.defineProperty(this, "_handleMouseDown", {
|
|
18
11
|
enumerable: true,
|
|
19
12
|
configurable: true,
|
|
@@ -21,14 +14,7 @@ export class HighlightUIConnector {
|
|
|
21
14
|
value: undefined
|
|
22
15
|
});
|
|
23
16
|
this.props = props;
|
|
24
|
-
this._handleMouseDown =
|
|
25
|
-
((_b = (_a = props.options) === null || _a === void 0 ? void 0 : _a.useMouse) !== null && _b !== void 0 ? _b : true)
|
|
26
|
-
? this._createMouseDownHandler()
|
|
27
|
-
: undefined;
|
|
28
|
-
this._handleKeyDown =
|
|
29
|
-
((_d = (_c = props.options) === null || _c === void 0 ? void 0 : _c.useKeys) !== null && _d !== void 0 ? _d : true)
|
|
30
|
-
? this._createKeyDownHandler(props.options)
|
|
31
|
-
: undefined;
|
|
17
|
+
this._handleMouseDown = this._createMouseDownHandler();
|
|
32
18
|
}
|
|
33
19
|
_highlight(e, itemId) {
|
|
34
20
|
this.props.highlight.highlightItem({ id: itemId });
|
|
@@ -41,64 +27,44 @@ export class HighlightUIConnector {
|
|
|
41
27
|
}
|
|
42
28
|
};
|
|
43
29
|
}
|
|
44
|
-
_createKeyDownHandler(options) {
|
|
45
|
-
return (e, itemId, getDomElement) => {
|
|
46
|
-
var _a, _b;
|
|
47
|
-
const keysDown = ['ArrowDown'];
|
|
48
|
-
const keysUp = ['ArrowUp'];
|
|
49
|
-
const isDown = (options === null || options === void 0 ? void 0 : options.isKeyDown)
|
|
50
|
-
? options === null || options === void 0 ? void 0 : options.isKeyDown(e)
|
|
51
|
-
: keysDown.includes(e.key);
|
|
52
|
-
const isUp = (options === null || options === void 0 ? void 0 : options.isKeyUp)
|
|
53
|
-
? options === null || options === void 0 ? void 0 : options.isKeyUp(e)
|
|
54
|
-
: keysUp.includes(e.key);
|
|
55
|
-
if (isUp || isDown) {
|
|
56
|
-
e.preventDefault();
|
|
57
|
-
e.stopPropagation();
|
|
58
|
-
const highlightItemById = (itemId) => {
|
|
59
|
-
this._highlight(Object.assign(Object.assign({}, e), { ctrlKey: false }), itemId);
|
|
60
|
-
};
|
|
61
|
-
const highlightableIds = ((_a = this.props.options) === null || _a === void 0 ? void 0 : _a.getHighlightableIds)
|
|
62
|
-
? (_b = this.props.options) === null || _b === void 0 ? void 0 : _b.getHighlightableIds(e)
|
|
63
|
-
: this.props.highlight.highlightableIds || [];
|
|
64
|
-
// Select the neighbour item
|
|
65
|
-
const newItemId = pickNeighbour(highlightableIds, this.props.highlight.id, isDown, highlightItemById);
|
|
66
|
-
// Move the focus to the neighbour item. We assume that the
|
|
67
|
-
// list of UI elements reflects the list of selectable items (that
|
|
68
|
-
// is stored in highlight.selectableIds).
|
|
69
|
-
if (newItemId !== itemId && getDomElement) {
|
|
70
|
-
const idx = this.props.highlight.highlightableIds.indexOf(newItemId);
|
|
71
|
-
const nextElm = getDomElement(itemId, idx);
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
nextElm && nextElm.focus();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
30
|
handle(itemId) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
: {};
|
|
85
|
-
const keyDownHandler = ((_d = (_c = this.props.options) === null || _c === void 0 ? void 0 : _c.useKeys) !== null && _d !== void 0 ? _d : true)
|
|
86
|
-
? {
|
|
87
|
-
onKeyDown: (e) => { var _a; return this._handleKeyDown(e, itemId, (_a = this.props.options) === null || _a === void 0 ? void 0 : _a.getDomElement); },
|
|
88
|
-
}
|
|
89
|
-
: {};
|
|
90
|
-
return Object.assign(Object.assign({ isHighlighted: this.props.highlight.id === itemId }, mouseHandlers), keyDownHandler);
|
|
31
|
+
const mouseHandlers = {
|
|
32
|
+
onMouseDown: (e) => this._handleMouseDown(e, itemId),
|
|
33
|
+
};
|
|
34
|
+
return Object.assign({ isHighlighted: this.props.highlight.id === itemId }, mouseHandlers);
|
|
91
35
|
}
|
|
92
36
|
}
|
|
93
37
|
export function highlightUIHandlers(props) {
|
|
94
38
|
return {
|
|
95
39
|
onMouseDown: props.onMouseDown,
|
|
96
|
-
onKeyDown: props.onKeyDown,
|
|
97
40
|
};
|
|
98
41
|
}
|
|
99
|
-
export function createHighlightUIConnector(highlight
|
|
42
|
+
export function createHighlightUIConnector(highlight) {
|
|
100
43
|
return new HighlightUIConnector({
|
|
101
44
|
highlight,
|
|
102
|
-
options,
|
|
103
45
|
});
|
|
104
46
|
}
|
|
47
|
+
export const createHighlightKeyHandlers = (highlight, options) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
const down = (_a = options === null || options === void 0 ? void 0 : options.keyDown) !== null && _a !== void 0 ? _a : 'down';
|
|
50
|
+
const up = (_b = options === null || options === void 0 ? void 0 : options.keyUp) !== null && _b !== void 0 ? _b : 'up';
|
|
51
|
+
const getAnchor = () => highlight.id;
|
|
52
|
+
const getHighlightableIds = () => {
|
|
53
|
+
var _a;
|
|
54
|
+
return (options === null || options === void 0 ? void 0 : options.getHighlightableIds)
|
|
55
|
+
? options === null || options === void 0 ? void 0 : options.getHighlightableIds()
|
|
56
|
+
: (_a = highlight.highlightableIds) !== null && _a !== void 0 ? _a : [];
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
[down]: () => highlightNext(highlight, getAnchor(), true, getHighlightableIds()),
|
|
60
|
+
[up]: () => highlightNext(highlight, getAnchor(), false, getHighlightableIds()),
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const highlightNext = (highlight, currentItemId, isDown, highlightableIds) => {
|
|
64
|
+
const highlightItemById = (itemId) => {
|
|
65
|
+
highlight.highlightItem({ id: itemId });
|
|
66
|
+
};
|
|
67
|
+
if (currentItemId !== undefined) {
|
|
68
|
+
pickNeighbour(highlightableIds, currentItemId, isDown, highlightItemById);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type HoverPositionT = {
|
|
2
|
+
isBefore: boolean;
|
|
3
|
+
targetItemId: string;
|
|
4
|
+
payload?: any;
|
|
5
|
+
};
|
|
6
|
+
export declare class Hovering {
|
|
7
|
+
static className: () => string;
|
|
8
|
+
hoverPosition?: HoverPositionT;
|
|
9
|
+
setHoverPosition(hoverPosition?: HoverPositionT): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { data, operation } from 'skandha';
|
|
8
|
+
class Hovering {
|
|
9
|
+
constructor() {
|
|
10
|
+
Object.defineProperty(this, "hoverPosition", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: void 0
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
setHoverPosition(hoverPosition) {
|
|
18
|
+
this.hoverPosition = hoverPosition;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(Hovering, "className", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: () => 'Hovering'
|
|
26
|
+
});
|
|
27
|
+
__decorate([
|
|
28
|
+
data
|
|
29
|
+
], Hovering.prototype, "hoverPosition", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
operation({ log: false })
|
|
32
|
+
], Hovering.prototype, "setHoverPosition", null);
|
|
33
|
+
export { Hovering };
|
package/facets/Insertion.d.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import { DefineCbs } from 'aspiration';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
targetItemId: string;
|
|
5
|
-
};
|
|
6
|
-
export type DragT = DropPositionT & {
|
|
7
|
-
payload: any;
|
|
8
|
-
};
|
|
9
|
-
export type DragSourceT = (ctr: any) => DragT | undefined;
|
|
2
|
+
import { HoverPositionT } from './Hovering';
|
|
3
|
+
export type DragSourceT = (ctr: any) => HoverPositionT | undefined;
|
|
10
4
|
export declare class Insertion<T = any> {
|
|
11
5
|
static className: () => string;
|
|
12
6
|
inputItems: Array<T>;
|
|
13
7
|
preview: Array<T>;
|
|
14
8
|
insertItems(args: {
|
|
15
|
-
|
|
9
|
+
hoverPosition: HoverPositionT;
|
|
16
10
|
}): Promise<any>;
|
|
17
11
|
}
|
|
18
12
|
type Cbs<T> = {
|
package/facets/Insertion.js
CHANGED
|
@@ -25,7 +25,7 @@ class Insertion {
|
|
|
25
25
|
insertItems(args) {
|
|
26
26
|
const cbs = getCallbacks(this);
|
|
27
27
|
if (this.inputItems) {
|
|
28
|
-
const preview = getPreview(this.inputItems, args.
|
|
28
|
+
const preview = getPreview(this.inputItems, args.hoverPosition.targetItemId, args.hoverPosition.isBefore, args.hoverPosition.payload);
|
|
29
29
|
return Promise.resolve(cbs.insertItems(preview));
|
|
30
30
|
}
|
|
31
31
|
return Promise.resolve();
|
package/facets/Selection.js
CHANGED
|
@@ -82,7 +82,7 @@ export function handleSelectItem(facet, args) {
|
|
|
82
82
|
const startItemId = facet.anchorId || args.itemId;
|
|
83
83
|
const startIdx = selectableIds.indexOf(startItemId);
|
|
84
84
|
const stopIdx = selectableIds.indexOf(args.itemId);
|
|
85
|
-
const idxRange = range(
|
|
85
|
+
const idxRange = range(startIdx, stopIdx);
|
|
86
86
|
facet.ids = idxRange.map((idx) => selectableIds[idx]);
|
|
87
87
|
}
|
|
88
88
|
else if (args.isCtrl) {
|
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import { Selection } from './Selection';
|
|
2
|
-
export type SelectionUIConnectorOptionsT = {
|
|
3
|
-
useMouse?: boolean;
|
|
4
|
-
useKeys?: boolean;
|
|
5
|
-
getDomElement?: (id: string, idx: number) => Element | null;
|
|
6
|
-
getSelectableIds?: (e: any) => string[];
|
|
7
|
-
};
|
|
8
2
|
export interface SelectionUIConnectorT {
|
|
9
3
|
handle(itemId: string): SelectionUIPropsT;
|
|
10
4
|
}
|
|
11
5
|
export type PropsT = {
|
|
12
6
|
selection: Selection;
|
|
13
|
-
|
|
7
|
+
onSelect?: (selectionParams: {
|
|
8
|
+
itemId: string | undefined;
|
|
9
|
+
isShift?: boolean;
|
|
10
|
+
isCtrl?: boolean;
|
|
11
|
+
}) => void;
|
|
14
12
|
};
|
|
15
13
|
export declare class SelectionUIConnector implements SelectionUIConnectorT {
|
|
16
14
|
props: PropsT;
|
|
17
15
|
_selectOnMouseUp?: string;
|
|
18
|
-
_handleKeyDown: any;
|
|
19
16
|
_handleMouseUp: any;
|
|
20
17
|
_handleMouseDown: any;
|
|
21
18
|
constructor(props: PropsT);
|
|
22
19
|
_select(e: any, itemId: string): void;
|
|
23
20
|
_createMouseDownHandler(): (e: any, itemId: string) => void;
|
|
24
21
|
_createMouseUpHandler(): (e: any, itemId: string) => void;
|
|
25
|
-
_createKeyDownHandler(): (e: any, itemId: string, getDomElement: SelectionUIConnectorOptionsT['getDomElement']) => void;
|
|
26
22
|
handle(itemId: any): SelectionUIPropsT;
|
|
27
23
|
}
|
|
28
24
|
export type SelectionUIPropsT = {
|
|
29
25
|
isSelected: boolean;
|
|
30
26
|
onMouseDown?: any;
|
|
31
27
|
onMouseUp?: any;
|
|
32
|
-
onKeyDown?: any;
|
|
33
28
|
};
|
|
34
29
|
export declare function selectionUIHandlers<T extends SelectionUIPropsT>(props: T): {
|
|
35
30
|
onMouseDown: any;
|
|
36
31
|
onMouseUp: any;
|
|
37
|
-
onKeyDown: any;
|
|
38
32
|
};
|
|
39
|
-
export declare
|
|
33
|
+
export declare const createSelectionKeyHandlers: (selection: Selection, options?: {
|
|
34
|
+
keyDown?: string;
|
|
35
|
+
keyUp?: string;
|
|
36
|
+
getSelectableIds?: () => string[];
|
|
37
|
+
}) => {
|
|
38
|
+
[x: string]: () => void;
|
|
39
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { pickNeighbour } from '../internal/utils';
|
|
2
2
|
export class SelectionUIConnector {
|
|
3
3
|
constructor(props) {
|
|
4
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5
4
|
Object.defineProperty(this, "props", {
|
|
6
5
|
enumerable: true,
|
|
7
6
|
configurable: true,
|
|
@@ -14,12 +13,6 @@ export class SelectionUIConnector {
|
|
|
14
13
|
writable: true,
|
|
15
14
|
value: undefined
|
|
16
15
|
});
|
|
17
|
-
Object.defineProperty(this, "_handleKeyDown", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: undefined
|
|
22
|
-
});
|
|
23
16
|
Object.defineProperty(this, "_handleMouseUp", {
|
|
24
17
|
enumerable: true,
|
|
25
18
|
configurable: true,
|
|
@@ -33,24 +26,21 @@ export class SelectionUIConnector {
|
|
|
33
26
|
value: undefined
|
|
34
27
|
});
|
|
35
28
|
this.props = props;
|
|
36
|
-
this._handleMouseDown =
|
|
37
|
-
|
|
38
|
-
? this._createMouseDownHandler()
|
|
39
|
-
: undefined;
|
|
40
|
-
this._handleMouseUp =
|
|
41
|
-
((_d = (_c = props.options) === null || _c === void 0 ? void 0 : _c.useMouse) !== null && _d !== void 0 ? _d : true)
|
|
42
|
-
? this._createMouseUpHandler()
|
|
43
|
-
: undefined;
|
|
44
|
-
this._handleKeyDown =
|
|
45
|
-
((_f = (_e = props.options) === null || _e === void 0 ? void 0 : _e.useKeys) !== null && _f !== void 0 ? _f : true) ? this._createKeyDownHandler() : undefined;
|
|
29
|
+
this._handleMouseDown = this._createMouseDownHandler();
|
|
30
|
+
this._handleMouseUp = this._createMouseUpHandler();
|
|
46
31
|
}
|
|
47
32
|
_select(e, itemId) {
|
|
33
|
+
const isShift = e.shiftKey;
|
|
34
|
+
const isCtrl = e.ctrlKey;
|
|
48
35
|
const selectionParams = {
|
|
49
36
|
itemId: itemId,
|
|
50
|
-
isShift:
|
|
51
|
-
isCtrl:
|
|
37
|
+
isShift: isShift,
|
|
38
|
+
isCtrl: isCtrl,
|
|
52
39
|
};
|
|
53
40
|
this.props.selection.selectItem(selectionParams);
|
|
41
|
+
if (this.props.onSelect) {
|
|
42
|
+
this.props.onSelect(selectionParams);
|
|
43
|
+
}
|
|
54
44
|
}
|
|
55
45
|
_createMouseDownHandler() {
|
|
56
46
|
return (e, itemId) => {
|
|
@@ -76,62 +66,43 @@ export class SelectionUIConnector {
|
|
|
76
66
|
this._selectOnMouseUp = undefined;
|
|
77
67
|
};
|
|
78
68
|
}
|
|
79
|
-
_createKeyDownHandler() {
|
|
80
|
-
return (e, itemId, getDomElement) => {
|
|
81
|
-
var _a, _b;
|
|
82
|
-
const keysDown = ['ArrowDown'];
|
|
83
|
-
const keysUp = ['ArrowUp'];
|
|
84
|
-
const isDown = keysDown.includes(e.key);
|
|
85
|
-
const isUp = keysUp.includes(e.key);
|
|
86
|
-
if (isUp || isDown) {
|
|
87
|
-
e.preventDefault();
|
|
88
|
-
e.stopPropagation();
|
|
89
|
-
const selectItemById = (itemId) => {
|
|
90
|
-
this._select(Object.assign(Object.assign({}, e), { ctrlKey: false }), itemId);
|
|
91
|
-
};
|
|
92
|
-
const selectableIds = ((_a = this.props.options) === null || _a === void 0 ? void 0 : _a.getSelectableIds)
|
|
93
|
-
? (_b = this.props.options) === null || _b === void 0 ? void 0 : _b.getSelectableIds(e)
|
|
94
|
-
: this.props.selection.selectableIds || [];
|
|
95
|
-
// Select the neighbour item
|
|
96
|
-
const newItemId = pickNeighbour(selectableIds, itemId, isDown, selectItemById);
|
|
97
|
-
// Move the focus to the neighbour item. We assume that the
|
|
98
|
-
// list of UI elements reflects the list of selectable items (that
|
|
99
|
-
// is stored in selection.selectableIds).
|
|
100
|
-
if (newItemId !== itemId && getDomElement) {
|
|
101
|
-
const idx = this.props.selection.selectableIds.indexOf(newItemId);
|
|
102
|
-
const nextElm = getDomElement(itemId, idx);
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
nextElm && nextElm.focus();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
69
|
handle(itemId) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
: {};
|
|
117
|
-
const keyDownHandler = ((_d = (_c = this.props.options) === null || _c === void 0 ? void 0 : _c.useKeys) !== null && _d !== void 0 ? _d : true)
|
|
118
|
-
? {
|
|
119
|
-
onKeyDown: (e) => { var _a; return this._handleKeyDown(e, itemId, (_a = this.props.options) === null || _a === void 0 ? void 0 : _a.getDomElement); },
|
|
120
|
-
}
|
|
121
|
-
: {};
|
|
122
|
-
return Object.assign(Object.assign({ isSelected: this.props.selection.ids.includes(itemId) }, mouseHandlers), keyDownHandler);
|
|
70
|
+
const mouseHandlers = {
|
|
71
|
+
onMouseDown: (e) => this._handleMouseDown(e, itemId),
|
|
72
|
+
onMouseUp: (e) => this._handleMouseUp(e, itemId),
|
|
73
|
+
};
|
|
74
|
+
return Object.assign({ isSelected: this.props.selection.ids.includes(itemId) }, mouseHandlers);
|
|
123
75
|
}
|
|
124
76
|
}
|
|
125
77
|
export function selectionUIHandlers(props) {
|
|
126
78
|
return {
|
|
127
79
|
onMouseDown: props.onMouseDown,
|
|
128
80
|
onMouseUp: props.onMouseUp,
|
|
129
|
-
onKeyDown: props.onKeyDown,
|
|
130
81
|
};
|
|
131
82
|
}
|
|
132
|
-
export
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
83
|
+
export const createSelectionKeyHandlers = (selection, options) => {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const down = (_a = options === null || options === void 0 ? void 0 : options.keyDown) !== null && _a !== void 0 ? _a : 'down';
|
|
86
|
+
const up = (_b = options === null || options === void 0 ? void 0 : options.keyUp) !== null && _b !== void 0 ? _b : 'up';
|
|
87
|
+
const getAnchor = () => selection.ids[selection.ids.length - 1];
|
|
88
|
+
const getSelectableIds = () => {
|
|
89
|
+
var _a;
|
|
90
|
+
return (options === null || options === void 0 ? void 0 : options.getSelectableIds)
|
|
91
|
+
? options === null || options === void 0 ? void 0 : options.getSelectableIds()
|
|
92
|
+
: (_a = selection.selectableIds) !== null && _a !== void 0 ? _a : [];
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
[down]: () => selectNext(selection, getAnchor(), true, false, getSelectableIds()),
|
|
96
|
+
[`shift+${down}`]: () => selectNext(selection, getAnchor(), true, true, getSelectableIds()),
|
|
97
|
+
[up]: () => selectNext(selection, getAnchor(), false, false, getSelectableIds()),
|
|
98
|
+
[`shift+${up}`]: () => selectNext(selection, getAnchor(), false, true, getSelectableIds()),
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const selectNext = (selection, currentItemId, isDown, isShift, selectableIds) => {
|
|
102
|
+
const selectItemById = (itemId) => {
|
|
103
|
+
selection.selectItem({ itemId, isShift, isCtrl: false });
|
|
104
|
+
};
|
|
105
|
+
if (currentItemId !== undefined) {
|
|
106
|
+
pickNeighbour(selectableIds, currentItemId, isDown, selectItemById);
|
|
107
|
+
}
|
|
108
|
+
};
|
package/facets/Store.d.ts
CHANGED
package/facets/Store.js
CHANGED
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { data, output } from 'skandha';
|
|
7
|
+
import { data, operation, output } from 'skandha';
|
|
8
8
|
import { listToItemById } from '../internal/utils';
|
|
9
9
|
class Store {
|
|
10
10
|
constructor() {
|
|
@@ -19,6 +19,9 @@ class Store {
|
|
|
19
19
|
var _a;
|
|
20
20
|
return listToItemById((_a = this.items) !== null && _a !== void 0 ? _a : []);
|
|
21
21
|
}
|
|
22
|
+
setItems(items) {
|
|
23
|
+
this.items = items;
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
Object.defineProperty(Store, "className", {
|
|
24
27
|
enumerable: true,
|
|
@@ -32,4 +35,7 @@ __decorate([
|
|
|
32
35
|
__decorate([
|
|
33
36
|
output
|
|
34
37
|
], Store.prototype, "itemById", null);
|
|
38
|
+
__decorate([
|
|
39
|
+
operation
|
|
40
|
+
], Store.prototype, "setItems", null);
|
|
35
41
|
export { Store };
|
package/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ export { DragAndDrop, type DragAndDropCbs } from './facets/DragAndDrop';
|
|
|
5
5
|
export { createDragAndDropUIConnector, dragAndDropUIHandlers, type DragAndDropUIConnectorT, type DragAndDropUIPropsT, } from './facets/DragAndDropUIConnector';
|
|
6
6
|
export { Edit, type EditCbs } from './facets/Edit';
|
|
7
7
|
export { Highlight, type HighlightCbs } from './facets/Highlight';
|
|
8
|
-
export { createHighlightUIConnector, highlightUIHandlers, type
|
|
8
|
+
export { createHighlightKeyHandlers, createHighlightUIConnector, highlightUIHandlers, type HighlightUIConnectorT, type HighlightUIPropsT, } from './facets/HighlightUIConnector';
|
|
9
|
+
export { Hovering, type HoverPositionT } from './facets/Hovering';
|
|
9
10
|
export { Insertion, type InsertionCbs } from './facets/Insertion';
|
|
10
11
|
export { Selection, handleSelectItem, type SelectionCbs, } from './facets/Selection';
|
|
11
|
-
export {
|
|
12
|
+
export { SelectionUIConnector, createSelectionKeyHandlers, selectionUIHandlers, type SelectionUIConnectorT, type SelectionUIPropsT, } from './facets/SelectionUIConnector';
|
|
12
13
|
export { Store } from './facets/Store';
|
|
13
14
|
export { topOfTheList } from './lib/getPreview';
|
package/index.js
CHANGED
|
@@ -5,9 +5,10 @@ export { DragAndDrop } from './facets/DragAndDrop';
|
|
|
5
5
|
export { createDragAndDropUIConnector, dragAndDropUIHandlers, } from './facets/DragAndDropUIConnector';
|
|
6
6
|
export { Edit } from './facets/Edit';
|
|
7
7
|
export { Highlight } from './facets/Highlight';
|
|
8
|
-
export { createHighlightUIConnector, highlightUIHandlers, } from './facets/HighlightUIConnector';
|
|
8
|
+
export { createHighlightKeyHandlers, createHighlightUIConnector, highlightUIHandlers, } from './facets/HighlightUIConnector';
|
|
9
|
+
export { Hovering } from './facets/Hovering';
|
|
9
10
|
export { Insertion } from './facets/Insertion';
|
|
10
11
|
export { Selection, handleSelectItem, } from './facets/Selection';
|
|
11
|
-
export {
|
|
12
|
+
export { SelectionUIConnector, createSelectionKeyHandlers, selectionUIHandlers, } from './facets/SelectionUIConnector';
|
|
12
13
|
export { Store } from './facets/Store';
|
|
13
14
|
export { topOfTheList } from './lib/getPreview';
|
package/internal/utils.js
CHANGED
|
@@ -3,8 +3,15 @@ export function lookUp(keys, obj) {
|
|
|
3
3
|
}
|
|
4
4
|
export function range(start, stop) {
|
|
5
5
|
var ans = [];
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
if (stop >= start) {
|
|
7
|
+
for (let i = start; i <= stop; i++) {
|
|
8
|
+
ans.push(i);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
for (let i = start; i >= stop; i--) {
|
|
13
|
+
ans.push(i);
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
16
|
return ans;
|
|
10
17
|
}
|
package/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const DragSourceFromNewItem: (ctr: any) =>
|
|
1
|
+
import { HoverPositionT } from '../facets/Hovering';
|
|
2
|
+
export declare const DragSourceFromNewItem: (ctr: any) => HoverPositionT | undefined;
|
|
@@ -6,9 +6,9 @@ export function correctHighlight(highlight, allItemIds, highlightableIds) {
|
|
|
6
6
|
const highlightedItemIdx = allItemIds.indexOf(highlight.id);
|
|
7
7
|
const newIdx = _findNeighbourIdx(highlightableIds, allItemIds, highlightedItemIdx, allItemIds.length, 1) ||
|
|
8
8
|
_findNeighbourIdx(highlightableIds, allItemIds, highlightedItemIdx, -1, -1);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
highlight.highlightItem({
|
|
10
|
+
id: newIdx ? allItemIds[newIdx.result] : undefined,
|
|
11
|
+
});
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
function _findNeighbourIdx(filteredItems, allItems, beginIndex, endIndex, step) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { findMap } from '../internal/utils';
|
|
2
2
|
import { getPreview } from '../lib/getPreview';
|
|
3
3
|
export const createInsertionPreview = (dragSources, ctr) => (inputItems) => {
|
|
4
|
-
const
|
|
5
|
-
return
|
|
6
|
-
? getPreview(inputItems !== null && inputItems !== void 0 ? inputItems : [],
|
|
4
|
+
const hoverPosition = findMap((dragSource) => dragSource(ctr), dragSources);
|
|
5
|
+
return hoverPosition
|
|
6
|
+
? getPreview(inputItems !== null && inputItems !== void 0 ? inputItems : [], hoverPosition.targetItemId, hoverPosition.isBefore, hoverPosition.payload)
|
|
7
7
|
: inputItems !== null && inputItems !== void 0 ? inputItems : [];
|
|
8
8
|
};
|
|
@@ -3,8 +3,8 @@ import { Insertion } from '../facets/Insertion';
|
|
|
3
3
|
import { DragSourceFromNewItem } from './DragSourceFromNewItem';
|
|
4
4
|
export function newItemsAreInsertedWhenConfirmed(facet) {
|
|
5
5
|
const ctr = getc(facet);
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
getf(Insertion, ctr).insertItems({
|
|
6
|
+
const hoverPosition = DragSourceFromNewItem(ctr);
|
|
7
|
+
if (hoverPosition) {
|
|
8
|
+
getf(Insertion, ctr).insertItems({ hoverPosition: hoverPosition });
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DragAndDrop } from '../facets/DragAndDrop';
|
|
2
|
-
import {
|
|
3
|
-
export declare function selectionIsInsertedOnDragAndDrop(facet: DragAndDrop,
|
|
2
|
+
import { HoverPositionT } from '../facets/Hovering';
|
|
3
|
+
export declare function selectionIsInsertedOnDragAndDrop(facet: DragAndDrop, hoverPosition: HoverPositionT): void;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { getc, getf } from 'skandha';
|
|
2
2
|
import { Insertion } from '../facets/Insertion';
|
|
3
3
|
import { Selection } from '../facets/Selection';
|
|
4
|
-
export function selectionIsInsertedOnDragAndDrop(facet,
|
|
4
|
+
export function selectionIsInsertedOnDragAndDrop(facet, hoverPosition) {
|
|
5
5
|
const ctr = getc(facet);
|
|
6
|
+
const selection = getf(Selection, ctr);
|
|
7
|
+
const selectableIds = selection.selectableIds || [];
|
|
8
|
+
const items = [...selection.items].sort((a, b) => selectableIds.indexOf(a.id) - selectableIds.indexOf(b.id));
|
|
6
9
|
getf(Insertion, ctr).insertItems({
|
|
7
|
-
|
|
10
|
+
hoverPosition: Object.assign(Object.assign({}, hoverPosition), { payload: items }),
|
|
8
11
|
});
|
|
9
12
|
}
|
package/facets/Labelling.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { DefineCbs } from 'aspiration';
|
|
2
|
-
export type LabelValueT = {
|
|
3
|
-
label: string;
|
|
4
|
-
id: string;
|
|
5
|
-
flag: boolean;
|
|
6
|
-
};
|
|
7
|
-
export type IdsByLabelT = {
|
|
8
|
-
[label: string]: Array<any>;
|
|
9
|
-
};
|
|
10
|
-
export type ItemsByLabelT = {
|
|
11
|
-
[label: string]: Array<any>;
|
|
12
|
-
};
|
|
13
|
-
export declare class Labelling {
|
|
14
|
-
static className: () => string;
|
|
15
|
-
idsByLabel: IdsByLabelT;
|
|
16
|
-
ids: (label: string) => any[];
|
|
17
|
-
itemsByLabel: ItemsByLabelT;
|
|
18
|
-
setLabel(args: {
|
|
19
|
-
labelValue: LabelValueT;
|
|
20
|
-
}): Promise<any>;
|
|
21
|
-
}
|
|
22
|
-
type Cbs = {
|
|
23
|
-
setLabel: {
|
|
24
|
-
saveIds(label: string, ids: string[]): any;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export type LabellingCbs = DefineCbs<Labelling, Cbs>;
|
|
28
|
-
export {};
|
package/facets/Labelling.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { getCallbacks, stub, withCbs } from 'aspiration';
|
|
8
|
-
import { data, input, operation } from 'skandha';
|
|
9
|
-
class Labelling {
|
|
10
|
-
constructor() {
|
|
11
|
-
Object.defineProperty(this, "idsByLabel", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: {}
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(this, "ids", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: (label) => this.idsByLabel[label] || []
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(this, "itemsByLabel", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: stub
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
setLabel(args) {
|
|
31
|
-
const cbs = getCallbacks(this);
|
|
32
|
-
const { label, id, flag } = args.labelValue;
|
|
33
|
-
this.idsByLabel[label] = this.idsByLabel[label] || [];
|
|
34
|
-
if (flag && !this.idsByLabel[label].includes(id)) {
|
|
35
|
-
this.idsByLabel[label].push(id);
|
|
36
|
-
return Promise.resolve(cbs.saveIds(label, this.idsByLabel[label]));
|
|
37
|
-
}
|
|
38
|
-
if (!flag && this.idsByLabel[label].includes(id)) {
|
|
39
|
-
this.idsByLabel[label] = this.idsByLabel[label].filter((x) => x !== id);
|
|
40
|
-
return Promise.resolve(cbs.saveIds(label, this.idsByLabel[label]));
|
|
41
|
-
}
|
|
42
|
-
return Promise.resolve();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
Object.defineProperty(Labelling, "className", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value: () => 'Labelling'
|
|
50
|
-
});
|
|
51
|
-
__decorate([
|
|
52
|
-
data
|
|
53
|
-
], Labelling.prototype, "idsByLabel", void 0);
|
|
54
|
-
__decorate([
|
|
55
|
-
input
|
|
56
|
-
], Labelling.prototype, "itemsByLabel", void 0);
|
|
57
|
-
__decorate([
|
|
58
|
-
operation,
|
|
59
|
-
withCbs()
|
|
60
|
-
], Labelling.prototype, "setLabel", null);
|
|
61
|
-
export { Labelling };
|