(editor: T)
| 39 | * See https://docs.slatejs.org/concepts/11-typescript to learn how. |
| 40 | */ |
| 41 | export const withEditable = <T extends Editor>(editor: T) => { |
| 42 | const e = editor as T & Editable |
| 43 | |
| 44 | withInput(e) |
| 45 | |
| 46 | withKeydown(e) |
| 47 | |
| 48 | withNormalizeNode(e) |
| 49 | |
| 50 | withDataTransfer(e) |
| 51 | |
| 52 | const { apply, onChange, deleteBackward, deleteForward } = e |
| 53 | |
| 54 | // The WeakMap which maps a key to a specific HTMLElement must be scoped to the editor instance to |
| 55 | // avoid collisions between editors in the DOM that share the same value. |
| 56 | EDITOR_TO_KEY_TO_ELEMENT.set(e, new WeakMap()) |
| 57 | |
| 58 | e.deleteForward = unit => { |
| 59 | const { selection } = editor |
| 60 | |
| 61 | if (selection && Range.isCollapsed(selection)) { |
| 62 | const [cell] = Editor.nodes(editor, { |
| 63 | match: n => e.isGridCell(n), |
| 64 | }) |
| 65 | |
| 66 | if (cell) { |
| 67 | const [, cellPath] = cell |
| 68 | const end = Editor.end(editor, cellPath) |
| 69 | if (Point.equals(selection.anchor, end)) { |
| 70 | return |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | deleteForward(unit) |
| 75 | } |
| 76 | |
| 77 | e.deleteBackward = unit => { |
| 78 | const { selection } = editor |
| 79 | |
| 80 | if (selection && Range.isCollapsed(selection)) { |
| 81 | const [cell] = Editor.nodes(editor, { |
| 82 | match: n => e.isGridCell(n), |
| 83 | }) |
| 84 | |
| 85 | if (cell) { |
| 86 | const [, cellPath] = cell |
| 87 | const start = Editor.start(editor, cellPath) |
| 88 | |
| 89 | if (Point.equals(selection.anchor, start)) { |
| 90 | return |
| 91 | } |
| 92 | } |
| 93 | const list = List.above(e) |
| 94 | if (list && Editor.isStart(e, selection.focus, list[1])) { |
| 95 | List.unwrapList(e) |
| 96 | return |
| 97 | } |
| 98 | } |
no test coverage detected