skandha-facets 0.11.0 → 0.12.1

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.
@@ -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
- }): Promise<any>;
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;
@@ -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, decorateCb, operation } from 'skandha';
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
- return Promise.resolve(newItem).then(decorateCb((item) => {
30
- this.item = item;
31
- cbs.highlightNewItem && cbs.highlightNewItem();
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(decorateCb(() => {
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.item = undefined;
51
- this.parentId = undefined;
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()
@@ -2,6 +2,8 @@ import { DefineCbs } from 'aspiration';
2
2
  export declare class Deletion {
3
3
  static className: () => string;
4
4
  disabled?: boolean;
5
+ isDeleting: boolean;
6
+ setIsDeleting(isDeleting: boolean): void;
5
7
  delete(args: {
6
8
  itemIds: string[];
7
9
  moveToTrash?: boolean;
@@ -14,10 +14,23 @@ class Deletion {
14
14
  writable: true,
15
15
  value: undefined
16
16
  });
17
+ Object.defineProperty(this, "isDeleting", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: false
22
+ });
23
+ }
24
+ setIsDeleting(isDeleting) {
25
+ this.isDeleting = isDeleting;
17
26
  }
18
27
  delete(args) {
19
28
  const cbs = getCallbacks(this);
20
- return Promise.resolve(cbs.deleteItems());
29
+ this.setIsDeleting(true);
30
+ return Promise.resolve(cbs.deleteItems()).then((response) => {
31
+ this.setIsDeleting(false);
32
+ return response;
33
+ });
21
34
  }
22
35
  }
23
36
  Object.defineProperty(Deletion, "className", {
@@ -29,6 +42,12 @@ Object.defineProperty(Deletion, "className", {
29
42
  __decorate([
30
43
  data
31
44
  ], Deletion.prototype, "disabled", void 0);
45
+ __decorate([
46
+ data
47
+ ], Deletion.prototype, "isDeleting", void 0);
48
+ __decorate([
49
+ operation({ log: false })
50
+ ], Deletion.prototype, "setIsDeleting", null);
32
51
  __decorate([
33
52
  operation,
34
53
  withCbs()
@@ -1,10 +1,12 @@
1
1
  import { DefineCbs } from 'aspiration';
2
- import { DropPositionT } from './Insertion';
2
+ import { HoverPositionT } from './Hovering';
3
3
  export declare class DragAndDrop {
4
4
  static className: () => string;
5
+ isDropping: boolean;
6
+ setIsDropping(isDropping: boolean): void;
5
7
  drop(args: {
6
- dropPosition: DropPositionT;
7
- }): Promise<void>;
8
+ hoverPosition: HoverPositionT;
9
+ }): Promise<any>;
8
10
  }
9
11
  type Cbs = {
10
12
  drop: {
@@ -5,17 +5,32 @@ 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 { operation } from 'skandha';
8
+ import { data, operation } from 'skandha';
9
9
  import { selectionIsInsertedOnDragAndDrop } from '../policies/selectionIsInsertedOnDragAndDrop';
10
10
  const dropDefaultCbs = (dragAndDrop) => ({
11
11
  drop: function () {
12
- selectionIsInsertedOnDragAndDrop(dragAndDrop, this.args.dropPosition);
12
+ selectionIsInsertedOnDragAndDrop(dragAndDrop, this.args.hoverPosition);
13
13
  },
14
14
  });
15
15
  class DragAndDrop {
16
+ constructor() {
17
+ Object.defineProperty(this, "isDropping", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: false
22
+ });
23
+ }
24
+ setIsDropping(isDropping) {
25
+ this.isDropping = isDropping;
26
+ }
16
27
  drop(args) {
17
28
  const cbs = getCallbacks(this);
18
- return Promise.resolve(cbs.drop());
29
+ this.setIsDropping(true);
30
+ return Promise.resolve(cbs.drop()).then((response) => {
31
+ this.setIsDropping(false);
32
+ return response;
33
+ });
19
34
  }
20
35
  }
21
36
  Object.defineProperty(DragAndDrop, "className", {
@@ -24,6 +39,12 @@ Object.defineProperty(DragAndDrop, "className", {
24
39
  writable: true,
25
40
  value: () => 'DragAndDrop'
26
41
  });
42
+ __decorate([
43
+ data
44
+ ], DragAndDrop.prototype, "isDropping", void 0);
45
+ __decorate([
46
+ operation({ log: false })
47
+ ], DragAndDrop.prototype, "setIsDropping", null);
27
48
  __decorate([
28
49
  operation,
29
50
  withCbs(dropDefaultCbs)
@@ -1,18 +1,15 @@
1
1
  import { DragAndDrop } from './DragAndDrop';
2
- import { DropPositionT } from './Insertion';
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,3 @@ 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;
@@ -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
- if (this.hoverPosition) {
27
+ const hoverPosition = this.props.hovering.hoverPosition;
28
+ if (hoverPosition) {
44
29
  this.props.dragAndDrop
45
- .drop({ dropPosition: this.hoverPosition })
46
- .then(decorateCb(() => {
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,3 @@ export function dragAndDropUIHandlers(props) {
74
53
  onDragEnd: props.onDragEnd,
75
54
  };
76
55
  }
77
- export function createDragAndDropUIConnector(dragAndDrop) {
78
- return new DragAndDropUIConnector({ dragAndDrop });
79
- }
package/facets/Edit.d.ts CHANGED
@@ -2,6 +2,9 @@ import { DefineCbs } from 'aspiration';
2
2
  export declare class Edit {
3
3
  static className: () => string;
4
4
  isEditing: boolean;
5
+ isSaving: boolean;
6
+ reset(): void;
7
+ setIsSaving(isSaving: boolean): void;
5
8
  save(args: {
6
9
  values: any;
7
10
  }): Promise<any>;
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, decorateCb, operation } from 'skandha';
8
+ import { data, operation } from 'skandha';
9
9
  class Edit {
10
10
  constructor() {
11
11
  Object.defineProperty(this, "isEditing", {
@@ -14,18 +14,32 @@ class Edit {
14
14
  writable: true,
15
15
  value: false
16
16
  });
17
+ Object.defineProperty(this, "isSaving", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: false
22
+ });
23
+ }
24
+ reset() {
25
+ this.isEditing = false;
26
+ }
27
+ setIsSaving(isSaving) {
28
+ this.isSaving = isSaving;
17
29
  }
18
30
  save(args) {
19
31
  const cbs = getCallbacks(this);
20
- return Promise.resolve(cbs.saveItem()).then(decorateCb((localItem) => {
21
- this.isEditing = false;
22
- return localItem;
23
- }));
32
+ this.setIsSaving(true);
33
+ return Promise.resolve(cbs.saveItem()).then((savedObj) => {
34
+ this.reset();
35
+ this.setIsSaving(false);
36
+ return savedObj;
37
+ });
24
38
  }
25
39
  cancel() {
26
40
  const cbs = getCallbacks(this);
27
41
  if (this.isEditing) {
28
- this.isEditing = false;
42
+ this.reset();
29
43
  cbs.onCancel && cbs.onCancel();
30
44
  }
31
45
  }
@@ -46,6 +60,15 @@ Object.defineProperty(Edit, "className", {
46
60
  __decorate([
47
61
  data
48
62
  ], Edit.prototype, "isEditing", void 0);
63
+ __decorate([
64
+ data
65
+ ], Edit.prototype, "isSaving", void 0);
66
+ __decorate([
67
+ operation
68
+ ], Edit.prototype, "reset", null);
69
+ __decorate([
70
+ operation({ log: false })
71
+ ], Edit.prototype, "setIsSaving", null);
49
72
  __decorate([
50
73
  operation,
51
74
  withCbs()
@@ -1,36 +1,29 @@
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, options?: HighlightUIConnectorOptionsT): HighlightUIConnector;
23
+ export declare const createHighlightKeyHandlers: (highlight: Highlight, options?: {
24
+ keyDown?: string;
25
+ keyUp?: string;
26
+ getHighlightableIds?: () => string[];
27
+ }) => {
28
+ [x: string]: () => void;
29
+ };
@@ -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,39 @@ 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
- var _a, _b, _c, _d;
80
- const mouseHandlers = ((_b = (_a = this.props.options) === null || _a === void 0 ? void 0 : _a.useMouse) !== null && _b !== void 0 ? _b : true)
81
- ? {
82
- onMouseDown: (e) => this._handleMouseDown(e, itemId),
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, options) {
100
- return new HighlightUIConnector({
101
- highlight,
102
- options,
103
- });
104
- }
42
+ export const createHighlightKeyHandlers = (highlight, options) => {
43
+ var _a, _b;
44
+ const down = (_a = options === null || options === void 0 ? void 0 : options.keyDown) !== null && _a !== void 0 ? _a : 'down';
45
+ const up = (_b = options === null || options === void 0 ? void 0 : options.keyUp) !== null && _b !== void 0 ? _b : 'up';
46
+ const getAnchor = () => highlight.id;
47
+ const getHighlightableIds = () => {
48
+ var _a;
49
+ return (options === null || options === void 0 ? void 0 : options.getHighlightableIds)
50
+ ? options === null || options === void 0 ? void 0 : options.getHighlightableIds()
51
+ : (_a = highlight.highlightableIds) !== null && _a !== void 0 ? _a : [];
52
+ };
53
+ return {
54
+ [down]: () => highlightNext(highlight, getAnchor(), true, getHighlightableIds()),
55
+ [up]: () => highlightNext(highlight, getAnchor(), false, getHighlightableIds()),
56
+ };
57
+ };
58
+ const highlightNext = (highlight, currentItemId, isDown, highlightableIds) => {
59
+ const highlightItemById = (itemId) => {
60
+ highlight.highlightItem({ id: itemId });
61
+ };
62
+ if (currentItemId !== undefined) {
63
+ pickNeighbour(highlightableIds, currentItemId, isDown, highlightItemById);
64
+ }
65
+ };
@@ -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 };
@@ -1,18 +1,14 @@
1
1
  import { DefineCbs } from 'aspiration';
2
- export type DropPositionT = {
3
- isBefore: boolean;
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;
6
+ isInserting: boolean;
12
7
  inputItems: Array<T>;
13
8
  preview: Array<T>;
9
+ setIsInserting(isInserting: boolean): void;
14
10
  insertItems(args: {
15
- drag: DragT;
11
+ hoverPosition: HoverPositionT;
16
12
  }): Promise<any>;
17
13
  }
18
14
  type Cbs<T> = {
@@ -5,10 +5,16 @@ 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, stub, withCbs } from 'aspiration';
8
- import { input, operation, output } from 'skandha';
8
+ import { data, input, operation, output } from 'skandha';
9
9
  import { getPreview } from '../lib/getPreview';
10
10
  class Insertion {
11
11
  constructor() {
12
+ Object.defineProperty(this, "isInserting", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: false
17
+ });
12
18
  Object.defineProperty(this, "inputItems", {
13
19
  enumerable: true,
14
20
  configurable: true,
@@ -22,11 +28,18 @@ class Insertion {
22
28
  value: stub
23
29
  });
24
30
  }
31
+ setIsInserting(isInserting) {
32
+ this.isInserting = isInserting;
33
+ }
25
34
  insertItems(args) {
26
35
  const cbs = getCallbacks(this);
27
36
  if (this.inputItems) {
28
- const preview = getPreview(this.inputItems, args.drag.targetItemId, args.drag.isBefore, args.drag.payload);
29
- return Promise.resolve(cbs.insertItems(preview));
37
+ this.setIsInserting(true);
38
+ const preview = getPreview(this.inputItems, args.hoverPosition.targetItemId, args.hoverPosition.isBefore, args.hoverPosition.payload);
39
+ return Promise.resolve(cbs.insertItems(preview)).then((response) => {
40
+ this.setIsInserting(false);
41
+ return response;
42
+ });
30
43
  }
31
44
  return Promise.resolve();
32
45
  }
@@ -37,12 +50,18 @@ Object.defineProperty(Insertion, "className", {
37
50
  writable: true,
38
51
  value: () => 'Insertion'
39
52
  });
53
+ __decorate([
54
+ data
55
+ ], Insertion.prototype, "isInserting", void 0);
40
56
  __decorate([
41
57
  input
42
58
  ], Insertion.prototype, "inputItems", void 0);
43
59
  __decorate([
44
60
  output
45
61
  ], Insertion.prototype, "preview", void 0);
62
+ __decorate([
63
+ operation({ log: false })
64
+ ], Insertion.prototype, "setIsInserting", null);
46
65
  __decorate([
47
66
  operation,
48
67
  withCbs()
@@ -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(Math.min(startIdx, stopIdx), 1 + Math.max(startIdx, stopIdx));
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
- options?: SelectionUIConnectorOptionsT;
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 function createSelectionUIConnector(selection: Selection, options?: SelectionUIConnectorOptionsT): SelectionUIConnector;
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
- ((_b = (_a = props.options) === null || _a === void 0 ? void 0 : _a.useMouse) !== null && _b !== void 0 ? _b : true)
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: e.shiftKey,
51
- isCtrl: e.ctrlKey,
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
- var _a, _b, _c, _d;
111
- const mouseHandlers = ((_b = (_a = this.props.options) === null || _a === void 0 ? void 0 : _a.useMouse) !== null && _b !== void 0 ? _b : true)
112
- ? {
113
- onMouseDown: (e) => this._handleMouseDown(e, itemId),
114
- onMouseUp: (e) => this._handleMouseUp(e, itemId),
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 function createSelectionUIConnector(selection, options) {
133
- return new SelectionUIConnector({
134
- selection,
135
- options,
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
@@ -4,4 +4,5 @@ export declare class Store<T = any> {
4
4
  get itemById(): {
5
5
  [id: string]: T;
6
6
  };
7
+ setItems(items: T[]): void;
7
8
  }
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
@@ -2,12 +2,14 @@ export { Addition, type AdditionCbs } from './facets/Addition';
2
2
  export { Deletion, type DeletionCbs } from './facets/Deletion';
3
3
  export { Display } from './facets/Display';
4
4
  export { DragAndDrop, type DragAndDropCbs } from './facets/DragAndDrop';
5
- export { createDragAndDropUIConnector, dragAndDropUIHandlers, type DragAndDropUIConnectorT, type DragAndDropUIPropsT, } from './facets/DragAndDropUIConnector';
5
+ export { DragAndDropUIConnector, dragAndDropUIHandlers, type DragAndDropUIConnectorT, type DragAndDropUIPropsT, } from './facets/DragAndDropUIConnector';
6
6
  export { Edit, type EditCbs } from './facets/Edit';
7
+ export { Filtering, type FilteringCbs } from './facets/Filtering';
7
8
  export { Highlight, type HighlightCbs } from './facets/Highlight';
8
- export { createHighlightUIConnector, highlightUIHandlers, type HighlightUIConnectorOptionsT, type HighlightUIConnectorT, type HighlightUIPropsT, } from './facets/HighlightUIConnector';
9
+ export { HighlightUIConnector, createHighlightKeyHandlers, highlightUIHandlers, type HighlightUIConnectorT, type HighlightUIPropsT, } from './facets/HighlightUIConnector';
10
+ export { Hovering, type HoverPositionT } from './facets/Hovering';
9
11
  export { Insertion, type InsertionCbs } from './facets/Insertion';
10
12
  export { Selection, handleSelectItem, type SelectionCbs, } from './facets/Selection';
11
- export { createSelectionUIConnector, selectionUIHandlers, type SelectionUIConnectorOptionsT, type SelectionUIConnectorT, type SelectionUIPropsT, } from './facets/SelectionUIConnector';
13
+ export { SelectionUIConnector, createSelectionKeyHandlers, selectionUIHandlers, type SelectionUIConnectorT, type SelectionUIPropsT, } from './facets/SelectionUIConnector';
12
14
  export { Store } from './facets/Store';
13
15
  export { topOfTheList } from './lib/getPreview';
package/index.js CHANGED
@@ -2,12 +2,14 @@ export { Addition } from './facets/Addition';
2
2
  export { Deletion } from './facets/Deletion';
3
3
  export { Display } from './facets/Display';
4
4
  export { DragAndDrop } from './facets/DragAndDrop';
5
- export { createDragAndDropUIConnector, dragAndDropUIHandlers, } from './facets/DragAndDropUIConnector';
5
+ export { DragAndDropUIConnector, dragAndDropUIHandlers, } from './facets/DragAndDropUIConnector';
6
6
  export { Edit } from './facets/Edit';
7
+ export { Filtering } from './facets/Filtering';
7
8
  export { Highlight } from './facets/Highlight';
8
- export { createHighlightUIConnector, highlightUIHandlers, } from './facets/HighlightUIConnector';
9
+ export { HighlightUIConnector, createHighlightKeyHandlers, highlightUIHandlers, } from './facets/HighlightUIConnector';
10
+ export { Hovering } from './facets/Hovering';
9
11
  export { Insertion } from './facets/Insertion';
10
12
  export { Selection, handleSelectItem, } from './facets/Selection';
11
- export { createSelectionUIConnector, selectionUIHandlers, } from './facets/SelectionUIConnector';
13
+ export { SelectionUIConnector, createSelectionKeyHandlers, selectionUIHandlers, } from './facets/SelectionUIConnector';
12
14
  export { Store } from './facets/Store';
13
15
  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
- for (let i = start; i < stop; i++) {
7
- ans.push(i);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "skandha-facets",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
4
  "description": "Facets for use with the skandha library",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/mnieber/skandha-facets.git",
@@ -1,2 +1,2 @@
1
- import { DragT } from '../facets/Insertion';
2
- export declare const DragSourceFromNewItem: (ctr: any) => DragT | undefined;
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
- if (newIdx) {
10
- highlight.highlightItem({ id: allItemIds[newIdx.result] });
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 drag = findMap((dragSource) => dragSource(ctr), dragSources);
5
- return drag
6
- ? getPreview(inputItems !== null && inputItems !== void 0 ? inputItems : [], drag.targetItemId, drag.isBefore, drag.payload)
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 drag = DragSourceFromNewItem(ctr);
7
- if (drag) {
8
- getf(Insertion, ctr).insertItems({ drag });
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 { DropPositionT } from '../facets/Insertion';
3
- export declare function selectionIsInsertedOnDragAndDrop(facet: DragAndDrop, dropPosition: DropPositionT): void;
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, dropPosition) {
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
- drag: Object.assign(Object.assign({}, dropPosition), { payload: getf(Selection, ctr).items }),
10
+ hoverPosition: Object.assign(Object.assign({}, hoverPosition), { payload: items }),
8
11
  });
9
12
  }
@@ -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 {};
@@ -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 };