skandha-facets 0.8.1 → 0.10.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/Addition.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { AdditionCbs, GenericObjectT } from './AdditionCbs';
1
+ import { GenericObjectT } from './AdditionCbs';
2
2
  export type { AdditionCbs } from './AdditionCbs';
3
3
  export declare class Addition<ValueT = any> {
4
4
  static className: () => string;
5
5
  item?: ValueT;
6
6
  parentId?: string;
7
- add(values: GenericObjectT): (cbs: AdditionCbs<ValueT>['add']) => void;
8
- confirm(): (cbs: AdditionCbs<ValueT>['confirm']) => void;
9
- cancel(): (cbs: AdditionCbs<ValueT>['cancel']) => void;
7
+ add(values: GenericObjectT): Promise<void>;
8
+ confirm(): Promise<void>;
9
+ cancel(): Promise<void>;
10
10
  _reset(): void;
11
11
  }
package/Addition.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 { host, maybe } from 'aspiration';
7
+ import { getCallbacks, host } from 'aspiration';
8
8
  import { data, operation } from 'skandha';
9
9
  export class Addition {
10
10
  constructor() {
@@ -22,23 +22,24 @@ export class Addition {
22
22
  });
23
23
  }
24
24
  add(values) {
25
- return (cbs) => {
26
- maybe(cbs.storeLocation).bind(cbs)();
27
- this.item = cbs.createItem();
28
- maybe(cbs.highlightNewItem).bind(cbs)();
29
- };
25
+ const cbs = getCallbacks(this);
26
+ cbs.storeLocation && cbs.storeLocation();
27
+ return Promise.resolve(cbs.createItem()).then((item) => {
28
+ this.item = item;
29
+ cbs.highlightNewItem && cbs.highlightNewItem();
30
+ });
30
31
  }
31
32
  confirm() {
32
- return (cbs) => {
33
- cbs.confirm();
33
+ const cbs = getCallbacks(this);
34
+ return Promise.resolve(cbs.confirm()).then(() => {
34
35
  this._reset();
35
- };
36
+ });
36
37
  }
37
38
  cancel() {
38
- return (cbs) => {
39
- this._reset();
40
- maybe(cbs.restoreLocation).bind(cbs)();
41
- };
39
+ const cbs = getCallbacks(this);
40
+ return Promise.resolve(this._reset()).then(() => {
41
+ cbs.restoreLocation && cbs.restoreLocation();
42
+ });
42
43
  }
43
44
  _reset() {
44
45
  this.item = undefined;
package/AdditionCbs.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { Cbs } from "aspiration";
1
+ import { Cbs } from 'aspiration';
2
2
  export declare type GenericObjectT = any;
3
- export declare class Addition_add<ValueT = any> extends Cbs {
3
+ export interface Addition_add<ValueT> extends Cbs {
4
4
  values: GenericObjectT;
5
5
  storeLocation(): void;
6
6
  createItem(): ValueT;
7
7
  highlightNewItem(): void;
8
8
  }
9
- export declare class Addition_confirm extends Cbs {
9
+ export interface Addition_confirm extends Cbs {
10
10
  confirm(): void;
11
11
  }
12
- export declare class Addition_cancel extends Cbs {
12
+ export interface Addition_cancel extends Cbs {
13
13
  restoreLocation(): void;
14
14
  }
15
- export declare type AdditionCbs<ValueT = any> = {
15
+ export interface AdditionCbs<ValueT = any> {
16
16
  add: Addition_add<ValueT>;
17
17
  confirm: Addition_confirm;
18
18
  cancel: Addition_cancel;
19
- };
19
+ }
package/AdditionCbs.js CHANGED
@@ -1,23 +1 @@
1
- import { stub, Cbs } from "aspiration";
2
- export class Addition_add extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "values", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: void 0
10
- });
11
- }
12
- storeLocation() { }
13
- createItem() {
14
- return stub();
15
- }
16
- highlightNewItem() { }
17
- }
18
- export class Addition_confirm extends Cbs {
19
- confirm() { }
20
- }
21
- export class Addition_cancel extends Cbs {
22
- restoreLocation() { }
23
- }
1
+ export {};
package/Deletion.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { DeletionCbs } from './DeletionCbs';
2
1
  export type { DeletionCbs } from './DeletionCbs';
3
2
  export declare class Deletion {
4
3
  static className: () => string;
5
- delete(itemIds: string[]): (cbs: DeletionCbs['delete']) => any;
4
+ delete(itemIds: string[]): Promise<any>;
6
5
  }
package/Deletion.js CHANGED
@@ -4,13 +4,12 @@ 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 { host } from 'aspiration';
7
+ import { getCallbacks, host } from 'aspiration';
8
8
  import { operation } from 'skandha';
9
9
  export class Deletion {
10
10
  delete(itemIds) {
11
- return (cbs) => {
12
- return cbs.deleteItems();
13
- };
11
+ const cbs = getCallbacks(this);
12
+ return Promise.resolve(cbs.deleteItems());
14
13
  }
15
14
  }
16
15
  Object.defineProperty(Deletion, "className", {
package/DeletionCbs.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Cbs } from 'aspiration';
2
- export declare class Deletion_delete extends Cbs {
2
+ export interface Deletion_delete extends Cbs {
3
3
  itemIds: string[];
4
- deleteItems(): any;
4
+ deleteItems(): Promise<any>;
5
5
  }
6
6
  export declare type DeletionCbs = {
7
7
  delete: Deletion_delete;
package/DeletionCbs.js CHANGED
@@ -1,13 +1 @@
1
- import { Cbs, stub } from 'aspiration';
2
- export class Deletion_delete extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "itemIds", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: stub()
10
- });
11
- }
12
- deleteItems() { }
13
- }
1
+ export {};
package/DragAndDrop.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { DragAndDropCbs } from './DragAndDropCbs';
2
1
  import { DropPositionT } from './Insertion';
3
2
  export type { DragAndDropCbs } from './DragAndDropCbs';
4
3
  export declare class DragAndDrop {
5
4
  static className: () => string;
6
5
  hoverPosition?: DropPositionT;
7
- drop(dropPosition: DropPositionT): (cbs: DragAndDropCbs['drop']) => void;
6
+ drop(dropPosition: DropPositionT): Promise<void>;
8
7
  setHoverPosition(x?: DropPositionT): void;
9
8
  handle(itemId: string): {
10
9
  draggable: boolean;
@@ -14,3 +13,18 @@ export declare class DragAndDrop {
14
13
  onDrop: () => void;
15
14
  };
16
15
  }
16
+ export declare type DragHandlersT = {
17
+ draggable?: boolean;
18
+ onDragStart?: (event: any) => void;
19
+ onDragOver?: (event: any) => void;
20
+ onDragEnd?: (event: any) => void;
21
+ onDrop?: (event: any) => void;
22
+ };
23
+ export declare function dragState(hoverPosition: any, itemId: string): "before" | "after" | "none";
24
+ export declare function dragHandlers<T extends DragHandlersT>(props: T): {
25
+ draggable: boolean | undefined;
26
+ onDragStart: ((event: any) => void) | undefined;
27
+ onDragOver: ((event: any) => void) | undefined;
28
+ onDrop: ((event: any) => void) | undefined;
29
+ onDragEnd: ((event: any) => void) | undefined;
30
+ };
package/DragAndDrop.js CHANGED
@@ -4,9 +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 { host } from 'aspiration';
7
+ import { getCallbacks, host } from 'aspiration';
8
8
  import { data, operation } from 'skandha';
9
9
  import { isBefore } from './internal/utils';
10
+ import { selectionIsInsertedOnDragAndDrop } from './policies/selectionIsInsertedOnDragAndDrop';
11
+ const dropDefaultCbs = (dragAndDrop) => ({
12
+ drop: function () {
13
+ selectionIsInsertedOnDragAndDrop(dragAndDrop, this.dropPosition);
14
+ },
15
+ });
10
16
  export class DragAndDrop {
11
17
  constructor() {
12
18
  Object.defineProperty(this, "hoverPosition", {
@@ -17,9 +23,8 @@ export class DragAndDrop {
17
23
  });
18
24
  }
19
25
  drop(dropPosition) {
20
- return (cbs) => {
21
- cbs.drop();
22
- };
26
+ const cbs = getCallbacks(this);
27
+ return Promise.resolve(cbs.drop());
23
28
  }
24
29
  setHoverPosition(x) {
25
30
  this.hoverPosition = x;
@@ -40,8 +45,9 @@ export class DragAndDrop {
40
45
  },
41
46
  onDrop: () => {
42
47
  if (this.hoverPosition) {
43
- this.drop(this.hoverPosition);
44
- this.setHoverPosition(undefined);
48
+ this.drop(this.hoverPosition).then(() => {
49
+ this.setHoverPosition(undefined);
50
+ });
45
51
  }
46
52
  },
47
53
  };
@@ -58,8 +64,24 @@ __decorate([
58
64
  ], DragAndDrop.prototype, "hoverPosition", void 0);
59
65
  __decorate([
60
66
  operation,
61
- host(['dropPosition'])
67
+ host(['dropPosition'], dropDefaultCbs)
62
68
  ], DragAndDrop.prototype, "drop", null);
63
69
  __decorate([
64
70
  operation({ log: false })
65
71
  ], DragAndDrop.prototype, "setHoverPosition", null);
72
+ export function dragState(hoverPosition, itemId) {
73
+ return (hoverPosition === null || hoverPosition === void 0 ? void 0 : hoverPosition.targetItemId) === itemId
74
+ ? (hoverPosition === null || hoverPosition === void 0 ? void 0 : hoverPosition.isBefore)
75
+ ? 'before'
76
+ : 'after'
77
+ : 'none';
78
+ }
79
+ export function dragHandlers(props) {
80
+ return {
81
+ draggable: props.draggable,
82
+ onDragStart: props.onDragStart,
83
+ onDragOver: props.onDragOver,
84
+ onDrop: props.onDrop,
85
+ onDragEnd: props.onDragEnd,
86
+ };
87
+ }
@@ -1,9 +1,9 @@
1
- import { Cbs } from "aspiration";
2
- import { DropPositionT } from "./Insertion";
3
- export declare class DragAndDrop_drop extends Cbs {
1
+ import { Cbs } from 'aspiration';
2
+ import { DropPositionT } from './Insertion';
3
+ export interface DragAndDrop_drop extends Cbs {
4
4
  dropPosition: DropPositionT;
5
5
  drop(): void;
6
6
  }
7
- export declare type DragAndDropCbs = {
7
+ export interface DragAndDropCbs {
8
8
  drop: DragAndDrop_drop;
9
- };
9
+ }
package/DragAndDropCbs.js CHANGED
@@ -1,13 +1 @@
1
- import { stub, Cbs } from "aspiration";
2
- export class DragAndDrop_drop extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "dropPosition", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: stub()
10
- });
11
- }
12
- drop() { }
13
- }
1
+ export {};
package/Editing.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { EditingCbs } from './EditingCbs';
2
1
  export type { EditingCbs } from './EditingCbs';
3
2
  export declare class Editing {
4
3
  static className: () => string;
5
4
  isEditing: boolean;
6
- save(values: any): (cbs: EditingCbs['save']) => void;
7
- cancel(): (cbs: EditingCbs['cancel']) => void;
8
- enable(): (cbs: EditingCbs['enable']) => void;
5
+ save(values: any): Promise<void>;
6
+ cancel(): void;
7
+ enable(): void;
9
8
  }
package/Editing.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 { host, maybe } from 'aspiration';
7
+ import { getCallbacks, host } from 'aspiration';
8
8
  import { data, operation } from 'skandha';
9
9
  export class Editing {
10
10
  constructor() {
@@ -16,21 +16,17 @@ export class Editing {
16
16
  });
17
17
  }
18
18
  save(values) {
19
- return (cbs) => {
20
- cbs.saveItem();
19
+ const cbs = getCallbacks(this);
20
+ return Promise.resolve(cbs.saveItem()).then(() => {
21
21
  this.isEditing = false;
22
- maybe(cbs.refreshView).bind(cbs)();
23
- };
22
+ cbs.refreshView && cbs.refreshView();
23
+ });
24
24
  }
25
25
  cancel() {
26
- return (cbs) => {
27
- this.isEditing = false;
28
- };
26
+ this.isEditing = false;
29
27
  }
30
28
  enable() {
31
- return (cbs) => {
32
- this.isEditing = true;
33
- };
29
+ this.isEditing = true;
34
30
  }
35
31
  }
36
32
  Object.defineProperty(Editing, "className", {
package/EditingCbs.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { Cbs } from "aspiration";
2
- export declare class Editing_save extends Cbs {
1
+ import type { Cbs } from 'aspiration';
2
+ export interface Editing_save extends Cbs {
3
3
  values: any;
4
- saveItem(): void;
4
+ saveItem(): Promise<any>;
5
5
  refreshView(): void;
6
6
  }
7
- export declare class Editing_cancel extends Cbs {
7
+ export interface Editing_cancel extends Cbs {
8
8
  }
9
- export declare class Editing_enable extends Cbs {
9
+ export interface Editing_enable extends Cbs {
10
10
  }
11
- export declare type EditingCbs = {
11
+ export interface EditingCbs {
12
12
  save: Editing_save;
13
13
  cancel: Editing_cancel;
14
14
  enable: Editing_enable;
15
- };
15
+ }
package/EditingCbs.js CHANGED
@@ -1,18 +1 @@
1
- import { Cbs } from "aspiration";
2
- export class Editing_save extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "values", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: void 0
10
- });
11
- }
12
- saveItem() { }
13
- refreshView() { }
14
- }
15
- export class Editing_cancel extends Cbs {
16
- }
17
- export class Editing_enable extends Cbs {
18
- }
1
+ export {};
package/Filtering.d.ts CHANGED
@@ -1,13 +1,11 @@
1
- import { GetterT } from 'skandha';
2
- import { FilteringCbs, FilterT } from './FilteringCbs';
1
+ import { FilterT } from './FilteringCbs';
3
2
  export type { FilteringCbs } from './FilteringCbs';
4
3
  export declare class Filtering<ValueT = any> {
5
4
  static className: () => string;
6
5
  isEnabled: boolean;
7
- filter: FilterT;
6
+ filter: FilterT<ValueT>;
8
7
  inputItems: Array<ValueT>;
9
- get filteredItems(): any[];
10
- apply(filter: FilterT): (cbs: FilteringCbs['apply']) => void;
11
- setEnabled(flag: boolean): (cbs: FilteringCbs['setEnabled']) => void;
8
+ get filteredItems(): ValueT[];
9
+ apply(filter: FilterT<ValueT>): void;
10
+ setEnabled(flag: boolean): void;
12
11
  }
13
- export declare const filteringUsesInputItems: (getItems: GetterT, transform?: Function) => (ctr: any) => void;
package/Filtering.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 { host, stub } from 'aspiration';
8
- import { data, mapDataToFacet, operation } from 'skandha';
8
+ import { data, operation } from 'skandha';
9
9
  export class Filtering {
10
10
  constructor() {
11
11
  Object.defineProperty(this, "isEnabled", {
@@ -24,22 +24,18 @@ export class Filtering {
24
24
  enumerable: true,
25
25
  configurable: true,
26
26
  writable: true,
27
- value: stub()
27
+ value: stub
28
28
  });
29
29
  }
30
30
  get filteredItems() {
31
31
  return this.isEnabled ? this.filter(this.inputItems) : this.inputItems;
32
32
  }
33
33
  apply(filter) {
34
- return (cbs) => {
35
- this.filter = filter;
36
- this.setEnabled(true);
37
- };
34
+ this.filter = filter;
35
+ this.setEnabled(true);
38
36
  }
39
37
  setEnabled(flag) {
40
- return (cbs) => {
41
- this.isEnabled = flag;
42
- };
38
+ this.isEnabled = flag;
43
39
  }
44
40
  }
45
41
  Object.defineProperty(Filtering, "className", {
@@ -68,4 +64,3 @@ __decorate([
68
64
  operation,
69
65
  host(['flag'])
70
66
  ], Filtering.prototype, "setEnabled", null);
71
- export const filteringUsesInputItems = (getItems, transform) => mapDataToFacet([Filtering, 'inputItems'], getItems, transform);
package/FilteringCbs.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { Cbs } from "aspiration";
2
- export declare type FilterT = (x: any) => Array<any>;
3
- export declare class Filtering_apply extends Cbs {
4
- filter: FilterT;
1
+ import { Cbs } from 'aspiration';
2
+ export declare type FilterT<ValueT> = (x: ValueT[]) => ValueT[];
3
+ export interface Filtering_apply<ValueT> extends Cbs {
4
+ filter: FilterT<ValueT>;
5
5
  }
6
- export declare class Filtering_setEnabled extends Cbs {
6
+ export interface Filtering_setEnabled<ValueT> extends Cbs {
7
7
  flag: boolean;
8
8
  }
9
- export declare type FilteringCbs = {
10
- apply: Filtering_apply;
11
- setEnabled: Filtering_setEnabled;
12
- };
9
+ export interface FilteringCbs<ValueT = any> {
10
+ apply: Filtering_apply<ValueT>;
11
+ setEnabled: Filtering_setEnabled<ValueT>;
12
+ }
package/FilteringCbs.js CHANGED
@@ -1,23 +1 @@
1
- import { stub, Cbs } from "aspiration";
2
- export class Filtering_apply extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "filter", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: stub()
10
- });
11
- }
12
- }
13
- export class Filtering_setEnabled extends Cbs {
14
- constructor() {
15
- super(...arguments);
16
- Object.defineProperty(this, "flag", {
17
- enumerable: true,
18
- configurable: true,
19
- writable: true,
20
- value: stub()
21
- });
22
- }
23
- }
1
+ export {};
package/Highlight.d.ts CHANGED
@@ -1,10 +1,7 @@
1
- import { GetterT } from 'skandha';
2
- import { HighlightCbs } from './HighlightCbs';
3
1
  export type { HighlightCbs } from './HighlightCbs';
4
2
  export declare class Highlight<ValueT = any> {
5
3
  static className: () => string;
6
4
  id: string | undefined;
7
5
  item?: ValueT;
8
- highlightItem(id: string): (cbs: HighlightCbs['highlightItem']) => void;
6
+ highlightItem(id: string | undefined): void;
9
7
  }
10
- export declare const highlightUsesItemLookUpTable: (getItemById: GetterT) => (ctr: any) => void;
package/Highlight.js CHANGED
@@ -4,8 +4,9 @@ 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 { host, maybe } from 'aspiration';
8
- import { data, getm, mapDatasToFacet, operation, output, } from 'skandha';
7
+ import { getCallbacks, host } from 'aspiration';
8
+ import { data, operation, output } from 'skandha';
9
+ const highlightItemDefaultCbs = (highlight) => ({});
9
10
  export class Highlight {
10
11
  constructor() {
11
12
  Object.defineProperty(this, "id", {
@@ -22,10 +23,9 @@ export class Highlight {
22
23
  });
23
24
  }
24
25
  highlightItem(id) {
25
- return (cbs) => {
26
- this.id = id;
27
- maybe(cbs.scrollItemIntoView).bind(cbs)();
28
- };
26
+ const cbs = getCallbacks(this);
27
+ this.id = id;
28
+ cbs.scrollItemIntoView && cbs.scrollItemIntoView();
29
29
  }
30
30
  }
31
31
  Object.defineProperty(Highlight, "className", {
@@ -42,12 +42,5 @@ __decorate([
42
42
  ], Highlight.prototype, "item", void 0);
43
43
  __decorate([
44
44
  operation,
45
- host(['id'])
45
+ host(['id'], highlightItemDefaultCbs)
46
46
  ], Highlight.prototype, "highlightItem", null);
47
- export const highlightUsesItemLookUpTable = (getItemById) => mapDatasToFacet([Highlight, 'item'], [
48
- //
49
- getItemById,
50
- getm([Highlight, 'id']),
51
- ], (itemById, id) => {
52
- return itemById[id];
53
- });
package/HighlightCbs.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Cbs } from "aspiration";
2
- export declare class Highlight_highlightItem extends Cbs {
1
+ import { Cbs } from 'aspiration';
2
+ export interface Highlight_highlightItem extends Cbs {
3
3
  id: string;
4
4
  scrollItemIntoView(): void;
5
5
  }
6
- export declare type HighlightCbs = {
6
+ export interface HighlightCbs {
7
7
  highlightItem: Highlight_highlightItem;
8
- };
8
+ }
package/HighlightCbs.js CHANGED
@@ -1,13 +1 @@
1
- import { Cbs, stub } from "aspiration";
2
- export class Highlight_highlightItem extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "id", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: stub()
10
- });
11
- }
12
- scrollItemIntoView() { }
13
- }
1
+ export {};
package/Insertion.d.ts CHANGED
@@ -1,11 +1,9 @@
1
- import { GetterT } from 'skandha';
2
- import { DragT, InsertionCbs } from './InsertionCbs';
1
+ import { DragT } from './InsertionCbs';
3
2
  export type { DragT, DropPositionT, InsertionCbs } from './InsertionCbs';
4
3
  export declare type DragSourceT = (ctr: any) => DragT | undefined;
5
4
  export declare class Insertion<ValueT = any> {
6
5
  static className: () => string;
7
6
  inputItems: Array<ValueT>;
8
7
  preview: Array<ValueT>;
9
- insertItems(drag: DragT): (cbs: InsertionCbs['insertItems']) => void;
8
+ insertItems(drag: DragT): Promise<any>;
10
9
  }
11
- export declare const insertionUsesInputItems: (getItems: GetterT, transform?: Function) => (ctr: any) => void;
package/Insertion.js CHANGED
@@ -4,8 +4,8 @@ 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 { host, stub } from 'aspiration';
8
- import { input, mapDataToFacet, operation, output } from 'skandha';
7
+ import { getCallbacks, host, stub } from 'aspiration';
8
+ import { input, operation, output } from 'skandha';
9
9
  import { getPreview } from './lib/getPreview';
10
10
  export class Insertion {
11
11
  constructor() {
@@ -13,22 +13,22 @@ export class Insertion {
13
13
  enumerable: true,
14
14
  configurable: true,
15
15
  writable: true,
16
- value: stub()
16
+ value: stub
17
17
  });
18
18
  Object.defineProperty(this, "preview", {
19
19
  enumerable: true,
20
20
  configurable: true,
21
21
  writable: true,
22
- value: stub()
22
+ value: stub
23
23
  });
24
24
  }
25
25
  insertItems(drag) {
26
- return (cbs) => {
27
- if (this.inputItems) {
28
- const preview = getPreview(this.inputItems, drag.targetItemId, drag.isBefore, drag.payload);
29
- cbs.insertItems(preview);
30
- }
31
- };
26
+ const cbs = getCallbacks(this);
27
+ if (this.inputItems) {
28
+ const preview = getPreview(this.inputItems, drag.targetItemId, drag.isBefore, drag.payload);
29
+ return Promise.resolve(cbs.insertItems(preview));
30
+ }
31
+ return Promise.resolve();
32
32
  }
33
33
  }
34
34
  Object.defineProperty(Insertion, "className", {
@@ -47,4 +47,3 @@ __decorate([
47
47
  operation,
48
48
  host(['drag'])
49
49
  ], Insertion.prototype, "insertItems", null);
50
- export const insertionUsesInputItems = (getItems, transform) => mapDataToFacet([Insertion, 'inputItems'], getItems, transform);
package/InsertionCbs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Cbs } from "aspiration";
1
+ import { Cbs } from 'aspiration';
2
2
  export declare type DropPositionT = {
3
3
  isBefore: boolean;
4
4
  targetItemId: string;
@@ -6,10 +6,10 @@ export declare type DropPositionT = {
6
6
  export declare type DragT = DropPositionT & {
7
7
  payload: any;
8
8
  };
9
- export declare class Insertion_insertItems<ValueT = any> extends Cbs {
9
+ export interface Insertion_insertItems<ValueT> extends Cbs {
10
10
  drag: DragT;
11
- insertItems(preview: Array<ValueT>): void;
11
+ insertItems(preview: Array<ValueT>): Promise<any>;
12
+ }
13
+ export interface InsertionCbs<ValueT = any> {
14
+ insertItems: Insertion_insertItems<ValueT>;
12
15
  }
13
- export declare type InsertionCbs = {
14
- insertItems: Insertion_insertItems;
15
- };
package/InsertionCbs.js CHANGED
@@ -1,13 +1 @@
1
- import { Cbs, stub } from "aspiration";
2
- export class Insertion_insertItems extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "drag", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: stub()
10
- });
11
- }
12
- insertItems(preview) { }
13
- }
1
+ export {};
package/Labelling.d.ts CHANGED
@@ -1,11 +1,9 @@
1
- import { GetterT } from 'skandha';
2
- import { IdsByLabelT, ItemsByLabelT, LabellingCbs, LabelValueT } from './LabellingCbs';
1
+ import { IdsByLabelT, ItemsByLabelT, LabelValueT } from './LabellingCbs';
3
2
  export type { LabellingCbs } from './LabellingCbs';
4
3
  export declare class Labelling {
5
4
  static className: () => string;
6
5
  idsByLabel: IdsByLabelT;
7
6
  ids: (label: string) => any[];
8
7
  itemsByLabel: ItemsByLabelT;
9
- setLabel(labelValue: LabelValueT): (cbs: LabellingCbs['setLabel']) => void;
8
+ setLabel(labelValue: LabelValueT): Promise<any>;
10
9
  }
11
- export declare const labellingActsOnItems: (getItemById: GetterT) => (ctr: any) => void;
package/Labelling.js CHANGED
@@ -4,9 +4,8 @@ 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 { host, stub } from 'aspiration';
8
- import { data, getm, input, mapDatasToFacet, operation, } from 'skandha';
9
- import { lookUp } from './internal/utils';
7
+ import { getCallbacks, host, stub } from 'aspiration';
8
+ import { data, input, operation } from 'skandha';
10
9
  export class Labelling {
11
10
  constructor() {
12
11
  Object.defineProperty(this, "idsByLabel", {
@@ -25,22 +24,22 @@ export class Labelling {
25
24
  enumerable: true,
26
25
  configurable: true,
27
26
  writable: true,
28
- value: stub()
27
+ value: stub
29
28
  });
30
29
  }
31
30
  setLabel(labelValue) {
32
- return (cbs) => {
33
- const { label, id, flag } = labelValue;
34
- this.idsByLabel[label] = this.idsByLabel[label] || [];
35
- if (flag && !this.idsByLabel[label].includes(id)) {
36
- this.idsByLabel[label].push(id);
37
- cbs.saveIds(label, this.idsByLabel[label]);
38
- }
39
- if (!flag && this.idsByLabel[label].includes(id)) {
40
- this.idsByLabel[label] = this.idsByLabel[label].filter((x) => x !== id);
41
- cbs.saveIds(label, this.idsByLabel[label]);
42
- }
43
- };
31
+ const cbs = getCallbacks(this);
32
+ const { label, id, flag } = 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();
44
43
  }
45
44
  }
46
45
  Object.defineProperty(Labelling, "className", {
@@ -59,10 +58,3 @@ __decorate([
59
58
  operation,
60
59
  host(['labelValue'])
61
60
  ], Labelling.prototype, "setLabel", null);
62
- export const labellingActsOnItems = (getItemById) => {
63
- return mapDatasToFacet([Labelling, 'itemsByLabel'], [
64
- //
65
- getItemById,
66
- getm([Labelling, 'idsByLabel']),
67
- ], (itemById, idsByLabel) => Object.fromEntries(Object.entries(idsByLabel).map(([label, ids]) => lookUp(ids, itemById))));
68
- };
package/LabellingCbs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Cbs } from "aspiration";
1
+ import { Cbs } from 'aspiration';
2
2
  export declare type LabelValueT = {
3
3
  label: string;
4
4
  id: string;
@@ -10,10 +10,10 @@ export declare type IdsByLabelT = {
10
10
  export declare type ItemsByLabelT = {
11
11
  [label: string]: Array<any>;
12
12
  };
13
- export declare class Labelling_setLabel extends Cbs {
13
+ export interface Labelling_setLabel extends Cbs {
14
14
  labelValue: LabelValueT;
15
- saveIds(label: string, ids: string[]): void;
15
+ saveIds(label: string, ids: string[]): Promise<any>;
16
16
  }
17
- export declare type LabellingCbs = {
17
+ export interface LabellingCbs {
18
18
  setLabel: Labelling_setLabel;
19
- };
19
+ }
package/LabellingCbs.js CHANGED
@@ -1,13 +1 @@
1
- import { Cbs, stub } from "aspiration";
2
- export class Labelling_setLabel extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "labelValue", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: stub()
10
- });
11
- }
12
- saveIds(label, ids) { }
13
- }
1
+ export {};
package/Selection.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { GetterT } from 'skandha';
2
- import { SelectionCbs, SelectionParamsT } from './SelectionCbs';
1
+ import { SelectionParamsT } from './SelectionCbs';
3
2
  export type { SelectionCbs, SelectionParamsT } from './SelectionCbs';
4
3
  export declare class Selection<ValueT = any> {
5
4
  static className: () => string;
@@ -7,8 +6,6 @@ export declare class Selection<ValueT = any> {
7
6
  ids: Array<string>;
8
7
  anchorId?: string;
9
8
  items: Array<ValueT>;
10
- selectItem(selectionParams: SelectionParamsT): (cbs: SelectionCbs['selectItem']) => void;
9
+ selectItem(selectionParams: SelectionParamsT): void;
11
10
  }
12
11
  export declare function handleSelectItem(facet: Selection, { itemId, isShift, isCtrl }: SelectionParamsT): void;
13
- export declare const selectionUsesItemLookUpTable: (getItemById: GetterT) => (ctr: any) => void;
14
- export declare const selectionUsesSelectableIds: (getIds: GetterT, transform?: ((x: any) => string[]) | undefined) => (ctr: any) => void;
package/Selection.js CHANGED
@@ -4,9 +4,9 @@ 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 { host, stub } from 'aspiration';
8
- import { data, getm, input, mapDatasToFacet, mapDataToFacet, operation, output, } from 'skandha';
9
- import { lookUp, range } from './internal/utils';
7
+ import { getCallbacks, host, stub } from 'aspiration';
8
+ import { data, input, operation, output } from 'skandha';
9
+ import { range } from './internal/utils';
10
10
  const selectItemDefaultCbs = (selection) => ({
11
11
  selectItem: function () {
12
12
  handleSelectItem(selection, this.selectionParams);
@@ -18,7 +18,7 @@ export class Selection {
18
18
  enumerable: true,
19
19
  configurable: true,
20
20
  writable: true,
21
- value: stub()
21
+ value: stub
22
22
  });
23
23
  Object.defineProperty(this, "ids", {
24
24
  enumerable: true,
@@ -36,13 +36,12 @@ export class Selection {
36
36
  enumerable: true,
37
37
  configurable: true,
38
38
  writable: true,
39
- value: stub()
39
+ value: stub
40
40
  });
41
41
  }
42
42
  selectItem(selectionParams) {
43
- return (cbs) => {
44
- cbs.selectItem();
45
- };
43
+ const cbs = getCallbacks(this);
44
+ cbs.selectItem();
46
45
  }
47
46
  }
48
47
  Object.defineProperty(Selection, "className", {
@@ -98,11 +97,3 @@ export function handleSelectItem(facet, { itemId, isShift, isCtrl }) {
98
97
  facet.anchorId = itemId;
99
98
  }
100
99
  }
101
- export const selectionUsesItemLookUpTable = (getItemById) => mapDatasToFacet([Selection, 'items'], [
102
- //
103
- getItemById,
104
- getm([Selection, 'ids']),
105
- ], (itemById, ids) => {
106
- return lookUp(ids, itemById);
107
- });
108
- export const selectionUsesSelectableIds = (getIds, transform) => mapDataToFacet([Selection, 'selectableIds'], getIds, transform);
package/SelectionCbs.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { Cbs } from "aspiration";
1
+ import { Cbs } from 'aspiration';
2
2
  export declare type SelectionParamsT = {
3
3
  itemId: string | undefined;
4
4
  isShift?: boolean;
5
5
  isCtrl?: boolean;
6
6
  context?: any;
7
7
  };
8
- export declare class Selection_selectItem extends Cbs {
8
+ export interface Selection_selectItem extends Cbs {
9
9
  selectionParams: SelectionParamsT;
10
10
  selectItem(): void;
11
11
  }
12
- export declare type SelectionCbs = {
12
+ export interface SelectionCbs {
13
13
  selectItem: Selection_selectItem;
14
- };
14
+ }
package/SelectionCbs.js CHANGED
@@ -1,13 +1 @@
1
- import { Cbs, stub } from "aspiration";
2
- export class Selection_selectItem extends Cbs {
3
- constructor() {
4
- super(...arguments);
5
- Object.defineProperty(this, "selectionParams", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: stub()
10
- });
11
- }
12
- selectItem() { }
13
- }
1
+ export {};
@@ -11,3 +11,13 @@ export declare class ClickToSelectItems {
11
11
  onMouseUp: (e: any) => void;
12
12
  };
13
13
  }
14
+ export declare type ClickHandlersT = {
15
+ onClick?: any;
16
+ onMouseDown?: any;
17
+ onMouseUp?: any;
18
+ };
19
+ export declare function clickHandlers<T extends ClickHandlersT>(props: T): {
20
+ onClick: any;
21
+ onMouseDown: any;
22
+ onMouseUp: any;
23
+ };
@@ -44,3 +44,10 @@ export class ClickToSelectItems {
44
44
  };
45
45
  }
46
46
  }
47
+ export function clickHandlers(props) {
48
+ return {
49
+ onClick: props.onClick,
50
+ onMouseDown: props.onMouseDown,
51
+ onMouseUp: props.onMouseUp,
52
+ };
53
+ }
package/index.d.ts CHANGED
@@ -1,4 +1 @@
1
- export { selectionUsesItemLookUpTable, selectionUsesSelectableIds, } from "./Selection";
2
- export { highlightUsesItemLookUpTable } from "./Highlight";
3
- export { filteringUsesInputItems } from "./Filtering";
4
- export { insertionUsesInputItems } from "./Insertion";
1
+ export {};
package/index.js CHANGED
@@ -1,4 +1 @@
1
- export { selectionUsesItemLookUpTable, selectionUsesSelectableIds, } from "./Selection";
2
- export { highlightUsesItemLookUpTable } from "./Highlight";
3
- export { filteringUsesInputItems } from "./Filtering";
4
- export { insertionUsesInputItems } from "./Insertion";
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skandha-facets",
3
- "version": "0.8.1",
3
+ "version": "0.10.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.7.0",
13
- "aspiration": ">=0.3.0"
12
+ "skandha": ">=0.10.1",
13
+ "aspiration": ">=0.4.0"
14
14
  },
15
15
  "devDependencies": {
16
16
  "typescript": "^4.0.3"
@@ -1,2 +1,2 @@
1
- import { DragSourceT } from "../Insertion";
2
- export declare const insertionPreviewUsesDragSources: (dragSources: DragSourceT[]) => (ctr: any) => void;
1
+ import { DragSourceT } from '../Insertion';
2
+ export declare const insertionPreviewUsesDragSources: (dragSources: DragSourceT[], ctr: any) => (inputItems: any[]) => any[];
@@ -1,13 +1,8 @@
1
- import { Insertion } from "../Insertion";
2
- import { findMap } from "../internal/utils";
3
- import { getPreview } from "../lib/getPreview";
4
- import { mapDataToFacet, getf, getc } from "skandha";
5
- export const insertionPreviewUsesDragSources = (dragSources) => mapDataToFacet([Insertion, "preview"], getf(Insertion), (insertion) => {
6
- const ctr = getc(insertion);
1
+ import { findMap } from '../internal/utils';
2
+ import { getPreview } from '../lib/getPreview';
3
+ export const insertionPreviewUsesDragSources = (dragSources, ctr) => (inputItems) => {
7
4
  const drag = findMap((dragSource) => dragSource(ctr), dragSources);
8
- const inputItems = insertion.inputItems;
9
- const preview = drag
5
+ return drag
10
6
  ? getPreview(inputItems !== null && inputItems !== void 0 ? inputItems : [], drag.targetItemId, drag.isBefore, drag.payload)
11
7
  : inputItems !== null && inputItems !== void 0 ? inputItems : [];
12
- return preview;
13
- });
8
+ };