PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / vendors / imask / esm / controls / html-contenteditable-mask-element.js

html-contenteditable-mask-element.js in Booking Calendar 11.9, at vendors/imask/esm/controls/html-contenteditable-mask-element.js

55 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import HTMLMaskElement from './html-mask-element.js';
2 import IMask from '../core/holder.js';
3 import './mask-element.js';
4
5 class HTMLContenteditableMaskElement extends HTMLMaskElement {
6 /** Returns HTMLElement selection start */
7 get _unsafeSelectionStart() {
8 const root = this.rootElement;
9 const selection = root.getSelection && root.getSelection();
10 const anchorOffset = selection && selection.anchorOffset;
11 const focusOffset = selection && selection.focusOffset;
12 if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) {
13 return anchorOffset;
14 }
15 return focusOffset;
16 }
17
18 /** Returns HTMLElement selection end */
19 get _unsafeSelectionEnd() {
20 const root = this.rootElement;
21 const selection = root.getSelection && root.getSelection();
22 const anchorOffset = selection && selection.anchorOffset;
23 const focusOffset = selection && selection.focusOffset;
24 if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) {
25 return anchorOffset;
26 }
27 return focusOffset;
28 }
29
30 /** Sets HTMLElement selection */
31 _unsafeSelect(start, end) {
32 if (!this.rootElement.createRange) return;
33 const range = this.rootElement.createRange();
34 range.setStart(this.input.firstChild || this.input, start);
35 range.setEnd(this.input.lastChild || this.input, end);
36 const root = this.rootElement;
37 const selection = root.getSelection && root.getSelection();
38 if (selection) {
39 selection.removeAllRanges();
40 selection.addRange(range);
41 }
42 }
43
44 /** HTMLElement value */
45 get value() {
46 return this.input.textContent || '';
47 }
48 set value(value) {
49 this.input.textContent = value;
50 }
51 }
52 IMask.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement;
53
54 export { HTMLContenteditableMaskElement as default };
55