skandha-facets 0.12.1 → 0.14.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.
@@ -1,7 +1,20 @@
1
- import { DefineCbs } from 'aspiration';
1
+ import { CallbackMap } from 'aspiration';
2
2
  export type GenericObjectT = any;
3
3
  export declare class Addition<T = any> {
4
4
  static className: () => string;
5
+ callbackMap: CallbackMap<{
6
+ add: {
7
+ stageAdd?: () => void;
8
+ createItem?: () => T;
9
+ highlightNewItem?: () => void;
10
+ };
11
+ cancel: {
12
+ unstageAdd(parentId: string | undefined): void;
13
+ };
14
+ confirm: {
15
+ confirmAdd(): void;
16
+ };
17
+ }>;
5
18
  item?: T;
6
19
  parentId?: string;
7
20
  setParentId(parentId?: string): void;
@@ -9,22 +22,7 @@ export declare class Addition<T = any> {
9
22
  add(args: {
10
23
  values?: GenericObjectT;
11
24
  }): any;
12
- confirm(): Promise<void>;
13
- cancel(): void;
25
+ confirm(): any;
26
+ cancel(): any;
14
27
  _reset(): void;
15
28
  }
16
- type Cbs<T> = {
17
- add: {
18
- stageAdd(): void;
19
- createItem(): T;
20
- highlightNewItem(): void;
21
- };
22
- cancel: {
23
- unstageAdd(parentId: string | undefined): void;
24
- };
25
- confirm: {
26
- confirmAdd(): void;
27
- };
28
- };
29
- export type AdditionCbs<T = any> = DefineCbs<Addition<T>, Cbs<T>>;
30
- export {};
@@ -4,10 +4,16 @@ 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 { getCallbacks, withCbs } from 'aspiration';
7
+ import { withCbs } from 'aspiration';
8
8
  import { data, operation } from 'skandha';
9
9
  class Addition {
10
10
  constructor() {
11
+ Object.defineProperty(this, "callbackMap", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: {}
16
+ });
11
17
  Object.defineProperty(this, "item", {
12
18
  enumerable: true,
13
19
  configurable: true,
@@ -28,28 +34,31 @@ class Addition {
28
34
  this.item = item;
29
35
  }
30
36
  add(args) {
31
- var _a;
32
- const cbs = getCallbacks(this);
33
- cbs.stageAdd && cbs.stageAdd();
34
- const newItem = (_a = args.values) !== null && _a !== void 0 ? _a : cbs.createItem();
35
- this.setItem(newItem);
36
- cbs.highlightNewItem && cbs.highlightNewItem();
37
- return newItem;
37
+ return withCbs(this.callbackMap, 'add', args, (cbs) => {
38
+ var _a;
39
+ cbs.stageAdd && cbs.stageAdd();
40
+ const newItem = (_a = args.values) !== null && _a !== void 0 ? _a : cbs.createItem();
41
+ this.setItem(newItem);
42
+ cbs.highlightNewItem && cbs.highlightNewItem();
43
+ return newItem;
44
+ });
38
45
  }
39
46
  confirm() {
40
- const cbs = getCallbacks(this);
41
- const result = cbs.confirmAdd ? cbs.confirmAdd() : undefined;
42
- return Promise.resolve(result).then(() => {
43
- this._reset();
47
+ return withCbs(this.callbackMap, 'confirm', {}, (cbs) => {
48
+ const result = cbs.confirmAdd ? cbs.confirmAdd() : undefined;
49
+ return Promise.resolve(result).then(() => {
50
+ this._reset();
51
+ });
44
52
  });
45
53
  }
46
54
  cancel() {
47
- const cbs = getCallbacks(this);
48
- if (this.item) {
49
- const parentId = this.parentId;
50
- this._reset();
51
- cbs.unstageAdd && cbs.unstageAdd(parentId);
52
- }
55
+ return withCbs(this.callbackMap, 'cancel', {}, (cbs) => {
56
+ if (this.item) {
57
+ const parentId = this.parentId;
58
+ this._reset();
59
+ cbs.unstageAdd && cbs.unstageAdd(parentId);
60
+ }
61
+ });
53
62
  }
54
63
  _reset() {
55
64
  this.setItem(undefined);
@@ -75,16 +84,13 @@ __decorate([
75
84
  operation({ log: false })
76
85
  ], Addition.prototype, "setItem", null);
77
86
  __decorate([
78
- operation,
79
- withCbs()
87
+ operation
80
88
  ], Addition.prototype, "add", null);
81
89
  __decorate([
82
- operation,
83
- withCbs()
90
+ operation
84
91
  ], Addition.prototype, "confirm", null);
85
92
  __decorate([
86
- operation,
87
- withCbs()
93
+ operation
88
94
  ], Addition.prototype, "cancel", null);
89
95
  __decorate([
90
96
  operation({ log: false })
@@ -1,18 +1,15 @@
1
- import { DefineCbs } from 'aspiration';
1
+ import { type CallbackMap } from 'aspiration';
2
2
  export declare class Deletion {
3
3
  static className: () => string;
4
- disabled?: boolean;
4
+ callbackMap: CallbackMap<{
5
+ delete: {
6
+ deleteItems: () => {};
7
+ };
8
+ }>;
5
9
  isDeleting: boolean;
6
10
  setIsDeleting(isDeleting: boolean): void;
7
11
  delete(args: {
8
12
  itemIds: string[];
9
13
  moveToTrash?: boolean;
10
- }): Promise<any>;
14
+ }): any;
11
15
  }
12
- type Cbs = {
13
- delete: {
14
- deleteItems(): any;
15
- };
16
- };
17
- export type DeletionCbs = DefineCbs<Deletion, Cbs>;
18
- export {};
@@ -4,15 +4,15 @@ 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 { getCallbacks, withCbs } from 'aspiration';
7
+ import { withCbs } from 'aspiration';
8
8
  import { data, operation } from 'skandha';
9
9
  class Deletion {
10
10
  constructor() {
11
- Object.defineProperty(this, "disabled", {
11
+ Object.defineProperty(this, "callbackMap", {
12
12
  enumerable: true,
13
13
  configurable: true,
14
14
  writable: true,
15
- value: undefined
15
+ value: {}
16
16
  });
17
17
  Object.defineProperty(this, "isDeleting", {
18
18
  enumerable: true,
@@ -25,11 +25,12 @@ class Deletion {
25
25
  this.isDeleting = isDeleting;
26
26
  }
27
27
  delete(args) {
28
- const cbs = getCallbacks(this);
29
- this.setIsDeleting(true);
30
- return Promise.resolve(cbs.deleteItems()).then((response) => {
31
- this.setIsDeleting(false);
32
- return response;
28
+ return withCbs(this.callbackMap, 'delete', args, (cbs) => {
29
+ this.setIsDeleting(true);
30
+ return Promise.resolve(cbs.deleteItems()).then((response) => {
31
+ this.setIsDeleting(false);
32
+ return response;
33
+ });
33
34
  });
34
35
  }
35
36
  }
@@ -39,9 +40,6 @@ Object.defineProperty(Deletion, "className", {
39
40
  writable: true,
40
41
  value: () => 'Deletion'
41
42
  });
42
- __decorate([
43
- data
44
- ], Deletion.prototype, "disabled", void 0);
45
43
  __decorate([
46
44
  data
47
45
  ], Deletion.prototype, "isDeleting", void 0);
@@ -49,7 +47,6 @@ __decorate([
49
47
  operation({ log: false })
50
48
  ], Deletion.prototype, "setIsDeleting", null);
51
49
  __decorate([
52
- operation,
53
- withCbs()
50
+ operation
54
51
  ], Deletion.prototype, "delete", null);
55
52
  export { Deletion };
package/facets/Display.js CHANGED
@@ -4,8 +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 { stub } from 'aspiration';
8
- import { data, output } from 'skandha';
7
+ import { data, output, stub } from 'skandha';
9
8
  import { listToItemById } from '../internal/utils';
10
9
  class Display {
11
10
  constructor() {
@@ -1,17 +1,22 @@
1
- import { DefineCbs } from 'aspiration';
1
+ import { type CallbackMap, type Cbs } from 'aspiration';
2
2
  import { HoverPositionT } from './Hovering';
3
+ export declare const defaultCallbackMap: (dragAndDrop: DragAndDrop) => {
4
+ drop: {
5
+ drop: (this: Cbs<DragAndDrop['drop']>) => void;
6
+ };
7
+ };
3
8
  export declare class DragAndDrop {
4
9
  static className: () => string;
10
+ callbackMap_: CallbackMap<{
11
+ drop?: {
12
+ drop?: (() => void) | undefined;
13
+ } | undefined;
14
+ }>;
15
+ get callbackMap(): typeof this.callbackMap_;
16
+ set callbackMap(cbs: typeof this.callbackMap_);
5
17
  isDropping: boolean;
6
18
  setIsDropping(isDropping: boolean): void;
7
19
  drop(args: {
8
20
  hoverPosition: HoverPositionT;
9
- }): Promise<any>;
21
+ }): any;
10
22
  }
11
- type Cbs = {
12
- drop: {
13
- drop(): void;
14
- };
15
- };
16
- export type DragAndDropCbs = DefineCbs<DragAndDrop, Cbs>;
17
- export {};
@@ -4,16 +4,24 @@ 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 { getCallbacks, withCbs } from 'aspiration';
7
+ import { mergeDeepLeft, withCbs } from 'aspiration';
8
8
  import { data, operation } from 'skandha';
9
9
  import { selectionIsInsertedOnDragAndDrop } from '../policies/selectionIsInsertedOnDragAndDrop';
10
- const dropDefaultCbs = (dragAndDrop) => ({
11
- drop: function () {
12
- selectionIsInsertedOnDragAndDrop(dragAndDrop, this.args.hoverPosition);
10
+ export const defaultCallbackMap = (dragAndDrop) => ({
11
+ drop: {
12
+ drop: function () {
13
+ selectionIsInsertedOnDragAndDrop(dragAndDrop, this.args.hoverPosition);
14
+ },
13
15
  },
14
16
  });
15
17
  class DragAndDrop {
16
18
  constructor() {
19
+ Object.defineProperty(this, "callbackMap_", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: {}
24
+ });
17
25
  Object.defineProperty(this, "isDropping", {
18
26
  enumerable: true,
19
27
  configurable: true,
@@ -21,15 +29,22 @@ class DragAndDrop {
21
29
  value: false
22
30
  });
23
31
  }
32
+ get callbackMap() {
33
+ return this.callbackMap_;
34
+ }
35
+ set callbackMap(cbs) {
36
+ this.callbackMap_ = mergeDeepLeft(cbs, defaultCallbackMap(this));
37
+ }
24
38
  setIsDropping(isDropping) {
25
39
  this.isDropping = isDropping;
26
40
  }
27
41
  drop(args) {
28
- const cbs = getCallbacks(this);
29
- this.setIsDropping(true);
30
- return Promise.resolve(cbs.drop()).then((response) => {
31
- this.setIsDropping(false);
32
- return response;
42
+ return withCbs(this.callbackMap, 'drop', args, (cbs) => {
43
+ this.setIsDropping(true);
44
+ return Promise.resolve(cbs.drop()).then((response) => {
45
+ this.setIsDropping(false);
46
+ return response;
47
+ });
33
48
  });
34
49
  }
35
50
  }
@@ -46,7 +61,6 @@ __decorate([
46
61
  operation({ log: false })
47
62
  ], DragAndDrop.prototype, "setIsDropping", null);
48
63
  __decorate([
49
- operation,
50
- withCbs(dropDefaultCbs)
64
+ operation
51
65
  ], DragAndDrop.prototype, "drop", null);
52
66
  export { DragAndDrop };
package/facets/Edit.d.ts CHANGED
@@ -1,25 +1,24 @@
1
- import { DefineCbs } from 'aspiration';
1
+ import { CallbackMap } from 'aspiration';
2
2
  export declare class Edit {
3
3
  static className: () => string;
4
+ callbackMap: CallbackMap<{
5
+ save: {
6
+ saveItem: () => any;
7
+ };
8
+ cancel?: {
9
+ onCancel?: (() => void) | undefined;
10
+ } | undefined;
11
+ enable?: {
12
+ onEnable?: (() => void) | undefined;
13
+ } | undefined;
14
+ }>;
4
15
  isEditing: boolean;
5
16
  isSaving: boolean;
6
17
  reset(): void;
7
18
  setIsSaving(isSaving: boolean): void;
8
19
  save(args: {
9
20
  values: any;
10
- }): Promise<any>;
11
- cancel(): void;
12
- enable(): void;
21
+ }): any;
22
+ cancel(): any;
23
+ enable(): any;
13
24
  }
14
- export type Cbs = {
15
- save: {
16
- saveItem(): any;
17
- };
18
- cancel: {
19
- onCancel(): void;
20
- };
21
- enable: {
22
- onEnable(): void;
23
- };
24
- };
25
- export type EditCbs = DefineCbs<Edit, Cbs>;
package/facets/Edit.js CHANGED
@@ -4,10 +4,16 @@ 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 { getCallbacks, withCbs } from 'aspiration';
7
+ import { withCbs } from 'aspiration';
8
8
  import { data, operation } from 'skandha';
9
9
  class Edit {
10
10
  constructor() {
11
+ Object.defineProperty(this, "callbackMap", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: {}
16
+ });
11
17
  Object.defineProperty(this, "isEditing", {
12
18
  enumerable: true,
13
19
  configurable: true,
@@ -28,27 +34,30 @@ class Edit {
28
34
  this.isSaving = isSaving;
29
35
  }
30
36
  save(args) {
31
- const cbs = getCallbacks(this);
32
- this.setIsSaving(true);
33
- return Promise.resolve(cbs.saveItem()).then((savedObj) => {
34
- this.reset();
35
- this.setIsSaving(false);
36
- return savedObj;
37
+ return withCbs(this.callbackMap, 'save', args, (cbs) => {
38
+ this.setIsSaving(true);
39
+ return Promise.resolve(cbs.saveItem()).then((savedObj) => {
40
+ this.reset();
41
+ this.setIsSaving(false);
42
+ return savedObj;
43
+ });
37
44
  });
38
45
  }
39
46
  cancel() {
40
- const cbs = getCallbacks(this);
41
- if (this.isEditing) {
42
- this.reset();
43
- cbs.onCancel && cbs.onCancel();
44
- }
47
+ return withCbs(this.callbackMap, 'cancel', {}, (cbs) => {
48
+ if (this.isEditing) {
49
+ this.reset();
50
+ (cbs === null || cbs === void 0 ? void 0 : cbs.onCancel) && cbs.onCancel();
51
+ }
52
+ });
45
53
  }
46
54
  enable() {
47
- const cbs = getCallbacks(this);
48
- if (!this.isEditing) {
49
- this.isEditing = true;
50
- cbs.onEnable && cbs.onEnable();
51
- }
55
+ return withCbs(this.callbackMap, 'enable', {}, (cbs) => {
56
+ if (!this.isEditing) {
57
+ this.isEditing = true;
58
+ (cbs === null || cbs === void 0 ? void 0 : cbs.onEnable) && cbs.onEnable();
59
+ }
60
+ });
52
61
  }
53
62
  }
54
63
  Object.defineProperty(Edit, "className", {
@@ -70,15 +79,12 @@ __decorate([
70
79
  operation({ log: false })
71
80
  ], Edit.prototype, "setIsSaving", null);
72
81
  __decorate([
73
- operation,
74
- withCbs()
82
+ operation
75
83
  ], Edit.prototype, "save", null);
76
84
  __decorate([
77
- operation,
78
- withCbs()
85
+ operation
79
86
  ], Edit.prototype, "cancel", null);
80
87
  __decorate([
81
- operation,
82
- withCbs()
88
+ operation
83
89
  ], Edit.prototype, "enable", null);
84
90
  export { Edit };
@@ -1,7 +1,8 @@
1
- import { DefineCbs } from 'aspiration';
1
+ import { type CallbackMap } from 'aspiration';
2
2
  export type FilterT<T> = (x: T[]) => T[];
3
3
  export declare class Filtering<T = any> {
4
4
  static className: () => string;
5
+ callbackMap: CallbackMap<{}>;
5
6
  isEnabled: boolean;
6
7
  filter: FilterT<T>;
7
8
  inputItems: Array<T>;
@@ -13,9 +14,3 @@ export declare class Filtering<T = any> {
13
14
  flag: boolean;
14
15
  }): void;
15
16
  }
16
- type Cbs<T> = {
17
- apply: {};
18
- setEnabled: {};
19
- };
20
- export type FilteringCbs<T = any> = DefineCbs<Filtering<T>, Cbs<T>>;
21
- export {};
@@ -4,10 +4,15 @@ 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 { stub, withCbs } from 'aspiration';
8
- import { data, operation } from 'skandha';
7
+ import { data, operation, stub } from 'skandha';
9
8
  class Filtering {
10
9
  constructor() {
10
+ Object.defineProperty(this, "callbackMap", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: {}
15
+ });
11
16
  Object.defineProperty(this, "isEnabled", {
12
17
  enumerable: true,
13
18
  configurable: true,
@@ -57,11 +62,9 @@ __decorate([
57
62
  data
58
63
  ], Filtering.prototype, "filteredItems", null);
59
64
  __decorate([
60
- operation,
61
- withCbs()
65
+ operation
62
66
  ], Filtering.prototype, "apply", null);
63
67
  __decorate([
64
- operation,
65
- withCbs()
68
+ operation
66
69
  ], Filtering.prototype, "setEnabled", null);
67
70
  export { Filtering };
@@ -1,17 +1,15 @@
1
- import { DefineCbs } from 'aspiration';
1
+ import { type CallbackMap } from 'aspiration';
2
2
  export declare class Highlight<T = any> {
3
3
  static className: () => string;
4
+ callbackMap: CallbackMap<{
5
+ set: {
6
+ scrollItemIntoView?: () => void;
7
+ };
8
+ }>;
4
9
  highlightableIds: Array<string>;
5
- id: string | undefined;
10
+ itemId: string | undefined;
6
11
  item?: T;
7
- highlightItem(args: {
8
- id: string | undefined;
9
- }): void;
12
+ set(args: {
13
+ itemId: string | undefined;
14
+ }): any;
10
15
  }
11
- type Cbs<T> = {
12
- highlightItem: {
13
- scrollItemIntoView(): void;
14
- };
15
- };
16
- export type HighlightCbs<T = any> = DefineCbs<Highlight<T>, Cbs<T>>;
17
- export {};
@@ -4,18 +4,23 @@ 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 { getCallbacks, stub, withCbs } from 'aspiration';
8
- import { data, input, operation, output } from 'skandha';
9
- const highlightItemDefaultCbs = (highlight) => ({});
7
+ import { withCbs } from 'aspiration';
8
+ import { data, input, operation, output, stub } from 'skandha';
10
9
  class Highlight {
11
10
  constructor() {
11
+ Object.defineProperty(this, "callbackMap", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: {}
16
+ });
12
17
  Object.defineProperty(this, "highlightableIds", {
13
18
  enumerable: true,
14
19
  configurable: true,
15
20
  writable: true,
16
21
  value: stub
17
22
  });
18
- Object.defineProperty(this, "id", {
23
+ Object.defineProperty(this, "itemId", {
19
24
  enumerable: true,
20
25
  configurable: true,
21
26
  writable: true,
@@ -28,10 +33,11 @@ class Highlight {
28
33
  value: void 0
29
34
  });
30
35
  }
31
- highlightItem(args) {
32
- const cbs = getCallbacks(this);
33
- this.id = args.id;
34
- cbs.scrollItemIntoView && cbs.scrollItemIntoView();
36
+ set(args) {
37
+ return withCbs(this.callbackMap, 'set', args, (cbs) => {
38
+ this.itemId = args.itemId;
39
+ cbs.scrollItemIntoView && cbs.scrollItemIntoView();
40
+ });
35
41
  }
36
42
  }
37
43
  Object.defineProperty(Highlight, "className", {
@@ -45,12 +51,11 @@ __decorate([
45
51
  ], Highlight.prototype, "highlightableIds", void 0);
46
52
  __decorate([
47
53
  data
48
- ], Highlight.prototype, "id", void 0);
54
+ ], Highlight.prototype, "itemId", void 0);
49
55
  __decorate([
50
56
  output
51
57
  ], Highlight.prototype, "item", void 0);
52
58
  __decorate([
53
- operation,
54
- withCbs(highlightItemDefaultCbs)
55
- ], Highlight.prototype, "highlightItem", null);
59
+ operation
60
+ ], Highlight.prototype, "set", null);
56
61
  export { Highlight };
@@ -17,11 +17,11 @@ export class HighlightUIConnector {
17
17
  this._handleMouseDown = this._createMouseDownHandler();
18
18
  }
19
19
  _highlight(e, itemId) {
20
- this.props.highlight.highlightItem({ id: itemId });
20
+ this.props.highlight.set({ itemId });
21
21
  }
22
22
  _createMouseDownHandler() {
23
23
  return (e, itemId) => {
24
- const isHighlighted = this.props.highlight.id === itemId;
24
+ const isHighlighted = this.props.highlight.itemId === itemId;
25
25
  if (!isHighlighted) {
26
26
  this._highlight(e, itemId);
27
27
  }
@@ -31,7 +31,7 @@ export class HighlightUIConnector {
31
31
  const mouseHandlers = {
32
32
  onMouseDown: (e) => this._handleMouseDown(e, itemId),
33
33
  };
34
- return Object.assign({ isHighlighted: this.props.highlight.id === itemId }, mouseHandlers);
34
+ return Object.assign({ isHighlighted: this.props.highlight.itemId === itemId }, mouseHandlers);
35
35
  }
36
36
  }
37
37
  export function highlightUIHandlers(props) {
@@ -43,7 +43,7 @@ export const createHighlightKeyHandlers = (highlight, options) => {
43
43
  var _a, _b;
44
44
  const down = (_a = options === null || options === void 0 ? void 0 : options.keyDown) !== null && _a !== void 0 ? _a : 'down';
45
45
  const up = (_b = options === null || options === void 0 ? void 0 : options.keyUp) !== null && _b !== void 0 ? _b : 'up';
46
- const getAnchor = () => highlight.id;
46
+ const getAnchor = () => highlight.itemId;
47
47
  const getHighlightableIds = () => {
48
48
  var _a;
49
49
  return (options === null || options === void 0 ? void 0 : options.getHighlightableIds)
@@ -57,7 +57,7 @@ export const createHighlightKeyHandlers = (highlight, options) => {
57
57
  };
58
58
  const highlightNext = (highlight, currentItemId, isDown, highlightableIds) => {
59
59
  const highlightItemById = (itemId) => {
60
- highlight.highlightItem({ id: itemId });
60
+ highlight.set({ itemId });
61
61
  };
62
62
  if (currentItemId !== undefined) {
63
63
  pickNeighbour(highlightableIds, currentItemId, isDown, highlightItemById);
@@ -1,20 +1,18 @@
1
- import { DefineCbs } from 'aspiration';
1
+ import { type CallbackMap } from 'aspiration';
2
2
  import { HoverPositionT } from './Hovering';
3
3
  export type DragSourceT = (ctr: any) => HoverPositionT | undefined;
4
4
  export declare class Insertion<T = any> {
5
5
  static className: () => string;
6
+ callbackMap: CallbackMap<{
7
+ insertItems: {
8
+ insertItems: (preview: Array<T>) => any;
9
+ };
10
+ }>;
6
11
  isInserting: boolean;
7
12
  inputItems: Array<T>;
8
13
  preview: Array<T>;
9
14
  setIsInserting(isInserting: boolean): void;
10
15
  insertItems(args: {
11
16
  hoverPosition: HoverPositionT;
12
- }): Promise<any>;
17
+ }): any;
13
18
  }
14
- type Cbs<T> = {
15
- insertItems: {
16
- insertItems(preview: Array<T>): any;
17
- };
18
- };
19
- export type InsertionCbs<T = any> = DefineCbs<Insertion<T>, Cbs<T>>;
20
- export {};
@@ -4,11 +4,17 @@ 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 { getCallbacks, stub, withCbs } from 'aspiration';
8
- import { data, input, operation, output } from 'skandha';
7
+ import { withCbs } from 'aspiration';
8
+ import { data, input, operation, output, stub } from 'skandha';
9
9
  import { getPreview } from '../lib/getPreview';
10
10
  class Insertion {
11
11
  constructor() {
12
+ Object.defineProperty(this, "callbackMap", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: {}
17
+ });
12
18
  Object.defineProperty(this, "isInserting", {
13
19
  enumerable: true,
14
20
  configurable: true,
@@ -32,16 +38,17 @@ class Insertion {
32
38
  this.isInserting = isInserting;
33
39
  }
34
40
  insertItems(args) {
35
- const cbs = getCallbacks(this);
36
- if (this.inputItems) {
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
- });
43
- }
44
- return Promise.resolve();
41
+ return withCbs(this.callbackMap, 'insertItems', args, (cbs) => {
42
+ if (this.inputItems) {
43
+ this.setIsInserting(true);
44
+ const preview = getPreview(this.inputItems, args.hoverPosition.targetItemId, args.hoverPosition.isBefore, args.hoverPosition.payload);
45
+ return Promise.resolve(cbs.insertItems(preview)).then((response) => {
46
+ this.setIsInserting(false);
47
+ return response;
48
+ });
49
+ }
50
+ return Promise.resolve();
51
+ });
45
52
  }
46
53
  }
47
54
  Object.defineProperty(Insertion, "className", {
@@ -63,7 +70,6 @@ __decorate([
63
70
  operation({ log: false })
64
71
  ], Insertion.prototype, "setIsInserting", null);
65
72
  __decorate([
66
- operation,
67
- withCbs()
73
+ operation
68
74
  ], Insertion.prototype, "insertItems", null);
69
75
  export { Insertion };
@@ -1,8 +1,15 @@
1
- import { DefineCbs } from 'aspiration';
1
+ import { type CallbackMap } from 'aspiration';
2
2
  export declare class Selection<T = any> {
3
3
  static className: () => string;
4
+ callbackMap_: CallbackMap<{
5
+ selectItem?: {
6
+ selectItem: () => void;
7
+ } | undefined;
8
+ }>;
9
+ get callbackMap(): typeof this.callbackMap_;
10
+ set callbackMap(cbs: typeof this.callbackMap_);
4
11
  selectableIds: Array<string>;
5
- ids: Array<string>;
12
+ itemIds: Array<string>;
6
13
  anchorId?: string;
7
14
  items: Array<T>;
8
15
  selectItem(args: {
@@ -10,17 +17,10 @@ export declare class Selection<T = any> {
10
17
  isShift?: boolean;
11
18
  isCtrl?: boolean;
12
19
  context?: any;
13
- }): void;
20
+ }): any;
14
21
  }
15
- type Cbs<T> = {
16
- selectItem: {
17
- selectItem(): void;
18
- };
19
- };
20
- export type SelectionCbs<T = any> = DefineCbs<Selection<T>, Cbs<T>>;
21
22
  export declare function handleSelectItem(facet: Selection, args: {
22
23
  itemId: string | undefined;
23
24
  isShift?: boolean;
24
25
  isCtrl?: boolean;
25
26
  }): void;
26
- export {};
@@ -4,23 +4,24 @@ 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 { getCallbacks, stub, withCbs } from 'aspiration';
8
- import { data, input, operation, output } from 'skandha';
7
+ import { mergeDeepLeft, withCbs } from 'aspiration';
8
+ import { data, input, operation, output, stub } from 'skandha';
9
9
  import { range } from '../internal/utils';
10
- const selectItemDefaultCbs = (selection) => ({
11
- selectItem: function () {
12
- handleSelectItem(selection, this.args);
13
- },
14
- });
15
10
  class Selection {
16
11
  constructor() {
12
+ Object.defineProperty(this, "callbackMap_", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: {}
17
+ });
17
18
  Object.defineProperty(this, "selectableIds", {
18
19
  enumerable: true,
19
20
  configurable: true,
20
21
  writable: true,
21
22
  value: stub
22
23
  });
23
- Object.defineProperty(this, "ids", {
24
+ Object.defineProperty(this, "itemIds", {
24
25
  enumerable: true,
25
26
  configurable: true,
26
27
  writable: true,
@@ -39,9 +40,16 @@ class Selection {
39
40
  value: stub
40
41
  });
41
42
  }
43
+ get callbackMap() {
44
+ return this.callbackMap_;
45
+ }
46
+ set callbackMap(cbs) {
47
+ this.callbackMap_ = mergeDeepLeft(cbs, defaultCallbackMap(this));
48
+ }
42
49
  selectItem(args) {
43
- const cbs = getCallbacks(this);
44
- cbs.selectItem();
50
+ return withCbs(this.callbackMap, 'selectItem', args, (cbs) => {
51
+ cbs.selectItem();
52
+ });
45
53
  }
46
54
  }
47
55
  Object.defineProperty(Selection, "className", {
@@ -55,7 +63,7 @@ __decorate([
55
63
  ], Selection.prototype, "selectableIds", void 0);
56
64
  __decorate([
57
65
  data
58
- ], Selection.prototype, "ids", void 0);
66
+ ], Selection.prototype, "itemIds", void 0);
59
67
  __decorate([
60
68
  data
61
69
  ], Selection.prototype, "anchorId", void 0);
@@ -63,17 +71,16 @@ __decorate([
63
71
  output
64
72
  ], Selection.prototype, "items", void 0);
65
73
  __decorate([
66
- operation,
67
- withCbs(selectItemDefaultCbs)
74
+ operation
68
75
  ], Selection.prototype, "selectItem", null);
69
76
  export { Selection };
70
77
  export function handleSelectItem(facet, args) {
71
78
  if (args.itemId === undefined) {
72
- facet.ids = [];
79
+ facet.itemIds = [];
73
80
  facet.anchorId = undefined;
74
81
  return;
75
82
  }
76
- const hasItem = facet.ids.includes(args.itemId);
83
+ const hasItem = facet.itemIds.includes(args.itemId);
77
84
  const selectableIds = facet.selectableIds;
78
85
  if (!selectableIds) {
79
86
  throw Error('logical error');
@@ -83,18 +90,25 @@ export function handleSelectItem(facet, args) {
83
90
  const startIdx = selectableIds.indexOf(startItemId);
84
91
  const stopIdx = selectableIds.indexOf(args.itemId);
85
92
  const idxRange = range(startIdx, stopIdx);
86
- facet.ids = idxRange.map((idx) => selectableIds[idx]);
93
+ facet.itemIds = idxRange.map((idx) => selectableIds[idx]);
87
94
  }
88
95
  else if (args.isCtrl) {
89
- facet.ids = hasItem
90
- ? facet.ids.filter((x) => x !== args.itemId)
91
- : [...facet.ids, args.itemId];
96
+ facet.itemIds = hasItem
97
+ ? facet.itemIds.filter((x) => x !== args.itemId)
98
+ : [...facet.itemIds, args.itemId];
92
99
  }
93
100
  else {
94
- facet.ids = [args.itemId];
101
+ facet.itemIds = [args.itemId];
95
102
  }
96
103
  // Move the anchor
97
104
  if (!facet.anchorId || !(args.isCtrl || args.isShift)) {
98
105
  facet.anchorId = args.itemId;
99
106
  }
100
107
  }
108
+ const defaultCallbackMap = (selection) => ({
109
+ selectItem: {
110
+ selectItem: function () {
111
+ handleSelectItem(selection, this.args);
112
+ },
113
+ },
114
+ });
@@ -44,7 +44,7 @@ export class SelectionUIConnector {
44
44
  }
45
45
  _createMouseDownHandler() {
46
46
  return (e, itemId) => {
47
- const isSelected = this.props.selection.ids.includes(itemId);
47
+ const isSelected = this.props.selection.itemIds.includes(itemId);
48
48
  if (!isSelected) {
49
49
  this._selectOnMouseUp = undefined;
50
50
  this._select(e, itemId);
@@ -56,7 +56,7 @@ export class SelectionUIConnector {
56
56
  }
57
57
  _createMouseUpHandler() {
58
58
  return (e, itemId) => {
59
- const isSelected = this.props.selection.ids.includes(itemId);
59
+ const isSelected = this.props.selection.itemIds.includes(itemId);
60
60
  // If the item was already selected and we left-click it without the ctrl key,
61
61
  // then we want to singly select it.
62
62
  if (this._selectOnMouseUp === itemId &&
@@ -71,7 +71,7 @@ export class SelectionUIConnector {
71
71
  onMouseDown: (e) => this._handleMouseDown(e, itemId),
72
72
  onMouseUp: (e) => this._handleMouseUp(e, itemId),
73
73
  };
74
- return Object.assign({ isSelected: this.props.selection.ids.includes(itemId) }, mouseHandlers);
74
+ return Object.assign({ isSelected: this.props.selection.itemIds.includes(itemId) }, mouseHandlers);
75
75
  }
76
76
  }
77
77
  export function selectionUIHandlers(props) {
@@ -84,7 +84,7 @@ export const createSelectionKeyHandlers = (selection, options) => {
84
84
  var _a, _b;
85
85
  const down = (_a = options === null || options === void 0 ? void 0 : options.keyDown) !== null && _a !== void 0 ? _a : 'down';
86
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];
87
+ const getAnchor = () => selection.itemIds[selection.itemIds.length - 1];
88
88
  const getSelectableIds = () => {
89
89
  var _a;
90
90
  return (options === null || options === void 0 ? void 0 : options.getSelectableIds)
package/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export { Addition, type AdditionCbs } from './facets/Addition';
2
- export { Deletion, type DeletionCbs } from './facets/Deletion';
1
+ export { Addition } from './facets/Addition';
2
+ export { Deletion } from './facets/Deletion';
3
3
  export { Display } from './facets/Display';
4
- export { DragAndDrop, type DragAndDropCbs } from './facets/DragAndDrop';
4
+ export { DragAndDrop } from './facets/DragAndDrop';
5
5
  export { DragAndDropUIConnector, dragAndDropUIHandlers, type DragAndDropUIConnectorT, type DragAndDropUIPropsT, } from './facets/DragAndDropUIConnector';
6
- export { Edit, type EditCbs } from './facets/Edit';
7
- export { Filtering, type FilteringCbs } from './facets/Filtering';
8
- export { Highlight, type HighlightCbs } from './facets/Highlight';
6
+ export { Edit } from './facets/Edit';
7
+ export { Filtering } from './facets/Filtering';
8
+ export { Highlight } from './facets/Highlight';
9
9
  export { HighlightUIConnector, createHighlightKeyHandlers, highlightUIHandlers, type HighlightUIConnectorT, type HighlightUIPropsT, } from './facets/HighlightUIConnector';
10
10
  export { Hovering, type HoverPositionT } from './facets/Hovering';
11
- export { Insertion, type InsertionCbs } from './facets/Insertion';
12
- export { Selection, handleSelectItem, type SelectionCbs, } from './facets/Selection';
11
+ export { Insertion } from './facets/Insertion';
12
+ export { Selection, handleSelectItem } from './facets/Selection';
13
13
  export { SelectionUIConnector, createSelectionKeyHandlers, selectionUIHandlers, type SelectionUIConnectorT, type SelectionUIPropsT, } from './facets/SelectionUIConnector';
14
14
  export { Store } from './facets/Store';
15
15
  export { topOfTheList } from './lib/getPreview';
package/index.js CHANGED
@@ -9,7 +9,7 @@ export { Highlight } from './facets/Highlight';
9
9
  export { HighlightUIConnector, createHighlightKeyHandlers, highlightUIHandlers, } from './facets/HighlightUIConnector';
10
10
  export { Hovering } from './facets/Hovering';
11
11
  export { Insertion } from './facets/Insertion';
12
- export { Selection, handleSelectItem, } from './facets/Selection';
12
+ export { Selection, handleSelectItem } from './facets/Selection';
13
13
  export { SelectionUIConnector, createSelectionKeyHandlers, selectionUIHandlers, } from './facets/SelectionUIConnector';
14
14
  export { Store } from './facets/Store';
15
15
  export { topOfTheList } from './lib/getPreview';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skandha-facets",
3
- "version": "0.12.1",
3
+ "version": "0.14.0",
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",
@@ -9,8 +9,8 @@
9
9
  "types": "index.d.ts",
10
10
  "prepublish": "tsc",
11
11
  "peerDependencies": {
12
- "skandha": ">=0.11.0",
13
- "aspiration": ">=0.5.0"
12
+ "skandha": ">=0.14.0",
13
+ "aspiration": ">=0.6.0"
14
14
  },
15
15
  "devDependencies": {
16
16
  "typescript": "^4.0.3"
@@ -1,2 +1,2 @@
1
1
  import { Highlight } from '../facets/Highlight';
2
- export declare function cancelNewItemOnHighlightChange(facet: Highlight, id: string): void;
2
+ export declare function cancelNewItemOnHighlightChange(facet: Highlight, itemId: string): void;
@@ -1,10 +1,10 @@
1
1
  import { getc, getf } from 'skandha';
2
2
  import { Addition } from '../facets/Addition';
3
- export function cancelNewItemOnHighlightChange(facet, id) {
3
+ export function cancelNewItemOnHighlightChange(facet, itemId) {
4
4
  var _a;
5
5
  const ctr = getc(facet);
6
6
  const addedItemId = (_a = getf(Addition, ctr).item) === null || _a === void 0 ? void 0 : _a.id;
7
- if (addedItemId && addedItemId !== id) {
7
+ if (addedItemId && addedItemId !== itemId) {
8
8
  getf(Addition, ctr).cancel();
9
9
  }
10
10
  }
@@ -1,13 +1,13 @@
1
1
  export function correctHighlight(highlight, allItemIds, highlightableIds) {
2
2
  highlightableIds = highlightableIds !== null && highlightableIds !== void 0 ? highlightableIds : highlight.highlightableIds;
3
- if (highlight.id &&
4
- allItemIds.includes(highlight.id) &&
5
- !highlightableIds.includes(highlight.id)) {
6
- const highlightedItemIdx = allItemIds.indexOf(highlight.id);
3
+ if (highlight.itemId &&
4
+ allItemIds.includes(highlight.itemId) &&
5
+ !highlightableIds.includes(highlight.itemId)) {
6
+ const highlightedItemIdx = allItemIds.indexOf(highlight.itemId);
7
7
  const newIdx = _findNeighbourIdx(highlightableIds, allItemIds, highlightedItemIdx, allItemIds.length, 1) ||
8
8
  _findNeighbourIdx(highlightableIds, allItemIds, highlightedItemIdx, -1, -1);
9
- highlight.highlightItem({
10
- id: newIdx ? allItemIds[newIdx.result] : undefined,
9
+ highlight.set({
10
+ itemId: newIdx ? allItemIds[newIdx.result] : undefined,
11
11
  });
12
12
  }
13
13
  }
@@ -3,6 +3,6 @@ import { Highlight } from '../facets/Highlight';
3
3
  export function highlightFollowsSelection(facet, args) {
4
4
  const ctr = getc(facet);
5
5
  if (!args.isCtrl && !args.isShift) {
6
- getf(Highlight, ctr).highlightItem({ id: args.itemId });
6
+ getf(Highlight, ctr).set({ itemId: args.itemId });
7
7
  }
8
8
  }
@@ -3,6 +3,6 @@ import { Highlight } from '../facets/Highlight';
3
3
  export function highlightNewItem(facet) {
4
4
  const ctr = getc(facet);
5
5
  if (facet.item) {
6
- getf(Highlight, ctr).highlightItem({ id: facet.item.id });
6
+ getf(Highlight, ctr).set({ itemId: facet.item.id });
7
7
  }
8
8
  }
@@ -3,5 +3,5 @@ import { Highlight } from '../facets/Highlight';
3
3
  import { topOfTheList } from '../lib/getPreview';
4
4
  export function newItemsAreAddedBelowTheHighlight(facet) {
5
5
  const ctr = getc(facet);
6
- facet.parentId = getf(Highlight, ctr).id || topOfTheList;
6
+ facet.parentId = getf(Highlight, ctr).itemId || topOfTheList;
7
7
  }