@unicef-polymer/etools-form-builder 3.2.0 → 3.2.2

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.
@@ -8,4 +8,5 @@ export declare class RichViewer extends LitElement {
8
8
  render(): import("lit-html").TemplateResult<1>;
9
9
  updateSelection(): void;
10
10
  firstUpdated(): void;
11
+ setCaretToEnd(el: any): void;
11
12
  }
@@ -30,17 +30,33 @@ let RichViewer = class RichViewer extends LitElement {
30
30
  fireEvent(this, 'selection', { selection: selection, html: (_b = this.content) === null || _b === void 0 ? void 0 : _b.innerHTML });
31
31
  }
32
32
  firstUpdated() {
33
- document.execCommand('defaultParagraphSeparator', false, 'br');
34
- document.addEventListener('selectionchange', () => {
35
- this.updateSelection();
36
- });
37
- window.addEventListener('selectionchange', () => {
33
+ const mainEl = this.closest('main');
34
+ if (!mainEl) {
35
+ return;
36
+ }
37
+ mainEl.addEventListener('selectionchange', () => {
38
38
  this.updateSelection();
39
39
  });
40
- document.addEventListener('keydown', () => {
40
+ mainEl.addEventListener('keydown', () => {
41
41
  this.updateSelection();
42
42
  });
43
43
  }
44
+ setCaretToEnd(el) {
45
+ if (!el) {
46
+ return;
47
+ }
48
+ el.focus();
49
+ if (window.getSelection && document.createRange) {
50
+ var range = document.createRange();
51
+ range.selectNodeContents(el);
52
+ range.collapse(false); // Collapse to end
53
+ const sel = window.getSelection();
54
+ if (sel) {
55
+ sel.removeAllRanges();
56
+ sel.addRange(range);
57
+ }
58
+ }
59
+ }
44
60
  };
45
61
  RichViewer.styles = css `
46
62
  article {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unicef-polymer/etools-form-builder",
3
3
  "description": "Etools FM Form Builder components",
4
- "version": "3.2.0",
4
+ "version": "3.2.2",
5
5
  "type": "module",
6
6
  "contributors": [
7
7
  "eTools Team"