skandha-facets 0.12.1 → 0.13.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.
@@ -2,14 +2,14 @@ import { DefineCbs } from 'aspiration';
2
2
  export declare class Highlight<T = any> {
3
3
  static className: () => string;
4
4
  highlightableIds: Array<string>;
5
- id: string | undefined;
5
+ itemId: string | undefined;
6
6
  item?: T;
7
- highlightItem(args: {
8
- id: string | undefined;
7
+ set(args: {
8
+ itemId: string | undefined;
9
9
  }): void;
10
10
  }
11
11
  type Cbs<T> = {
12
- highlightItem: {
12
+ set: {
13
13
  scrollItemIntoView(): void;
14
14
  };
15
15
  };
@@ -15,7 +15,7 @@ class Highlight {
15
15
  writable: true,
16
16
  value: stub
17
17
  });
18
- Object.defineProperty(this, "id", {
18
+ Object.defineProperty(this, "itemId", {
19
19
  enumerable: true,
20
20
  configurable: true,
21
21
  writable: true,
@@ -28,9 +28,9 @@ class Highlight {
28
28
  value: void 0
29
29
  });
30
30
  }
31
- highlightItem(args) {
31
+ set(args) {
32
32
  const cbs = getCallbacks(this);
33
- this.id = args.id;
33
+ this.itemId = args.itemId;
34
34
  cbs.scrollItemIntoView && cbs.scrollItemIntoView();
35
35
  }
36
36
  }
@@ -45,12 +45,12 @@ __decorate([
45
45
  ], Highlight.prototype, "highlightableIds", void 0);
46
46
  __decorate([
47
47
  data
48
- ], Highlight.prototype, "id", void 0);
48
+ ], Highlight.prototype, "itemId", void 0);
49
49
  __decorate([
50
50
  output
51
51
  ], Highlight.prototype, "item", void 0);
52
52
  __decorate([
53
53
  operation,
54
54
  withCbs(highlightItemDefaultCbs)
55
- ], Highlight.prototype, "highlightItem", null);
55
+ ], Highlight.prototype, "set", null);
56
56
  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);
@@ -2,7 +2,7 @@ import { DefineCbs } from 'aspiration';
2
2
  export declare class Selection<T = any> {
3
3
  static className: () => string;
4
4
  selectableIds: Array<string>;
5
- ids: Array<string>;
5
+ itemIds: Array<string>;
6
6
  anchorId?: string;
7
7
  items: Array<T>;
8
8
  selectItem(args: {
@@ -20,7 +20,7 @@ class Selection {
20
20
  writable: true,
21
21
  value: stub
22
22
  });
23
- Object.defineProperty(this, "ids", {
23
+ Object.defineProperty(this, "itemIds", {
24
24
  enumerable: true,
25
25
  configurable: true,
26
26
  writable: true,
@@ -55,7 +55,7 @@ __decorate([
55
55
  ], Selection.prototype, "selectableIds", void 0);
56
56
  __decorate([
57
57
  data
58
- ], Selection.prototype, "ids", void 0);
58
+ ], Selection.prototype, "itemIds", void 0);
59
59
  __decorate([
60
60
  data
61
61
  ], Selection.prototype, "anchorId", void 0);
@@ -69,11 +69,11 @@ __decorate([
69
69
  export { Selection };
70
70
  export function handleSelectItem(facet, args) {
71
71
  if (args.itemId === undefined) {
72
- facet.ids = [];
72
+ facet.itemIds = [];
73
73
  facet.anchorId = undefined;
74
74
  return;
75
75
  }
76
- const hasItem = facet.ids.includes(args.itemId);
76
+ const hasItem = facet.itemIds.includes(args.itemId);
77
77
  const selectableIds = facet.selectableIds;
78
78
  if (!selectableIds) {
79
79
  throw Error('logical error');
@@ -83,15 +83,15 @@ export function handleSelectItem(facet, args) {
83
83
  const startIdx = selectableIds.indexOf(startItemId);
84
84
  const stopIdx = selectableIds.indexOf(args.itemId);
85
85
  const idxRange = range(startIdx, stopIdx);
86
- facet.ids = idxRange.map((idx) => selectableIds[idx]);
86
+ facet.itemIds = idxRange.map((idx) => selectableIds[idx]);
87
87
  }
88
88
  else if (args.isCtrl) {
89
- facet.ids = hasItem
90
- ? facet.ids.filter((x) => x !== args.itemId)
91
- : [...facet.ids, args.itemId];
89
+ facet.itemIds = hasItem
90
+ ? facet.itemIds.filter((x) => x !== args.itemId)
91
+ : [...facet.itemIds, args.itemId];
92
92
  }
93
93
  else {
94
- facet.ids = [args.itemId];
94
+ facet.itemIds = [args.itemId];
95
95
  }
96
96
  // Move the anchor
97
97
  if (!facet.anchorId || !(args.isCtrl || args.isShift)) {
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skandha-facets",
3
- "version": "0.12.1",
3
+ "version": "0.13.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.13.0",
13
+ "aspiration": ">=0.5.2"
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
  }