drab 6.5.1 → 7.0.1

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.
Files changed (39) hide show
  1. package/dist/announcer/index.d.ts +2 -0
  2. package/dist/base/index.d.ts +101 -1536
  3. package/dist/base/index.js +87 -76
  4. package/dist/contextmenu/index.d.ts +1045 -3
  5. package/dist/contextmenu/index.js +15 -15
  6. package/dist/define.d.ts +11 -1
  7. package/dist/define.js +11 -5
  8. package/dist/dialog/index.d.ts +1047 -6
  9. package/dist/dialog/index.js +28 -25
  10. package/dist/editor/index.d.ts +1047 -12
  11. package/dist/editor/index.js +36 -36
  12. package/dist/fullscreen/index.d.ts +1045 -7
  13. package/dist/fullscreen/index.js +8 -8
  14. package/dist/index.d.ts +0 -3
  15. package/dist/index.js +0 -3
  16. package/dist/intersect/index.d.ts +1059 -16
  17. package/dist/intersect/index.js +26 -33
  18. package/dist/prefetch/index.d.ts +706 -25
  19. package/dist/prefetch/index.js +25 -44
  20. package/dist/share/index.d.ts +1413 -11
  21. package/dist/share/index.js +50 -18
  22. package/dist/tablesort/index.d.ts +1390 -5
  23. package/dist/tablesort/index.js +5 -5
  24. package/dist/tabs/index.d.ts +702 -4
  25. package/dist/tabs/index.js +3 -3
  26. package/dist/types/index.d.ts +29 -0
  27. package/dist/wakelock/index.d.ts +1390 -6
  28. package/dist/wakelock/index.js +16 -16
  29. package/package.json +5 -24
  30. package/dist/base/define.js +0 -3
  31. package/dist/copy/define.d.ts +0 -1
  32. package/dist/copy/define.js +0 -3
  33. package/dist/copy/index.d.ts +0 -30
  34. package/dist/copy/index.js +0 -39
  35. package/dist/youtube/define.d.ts +0 -1
  36. package/dist/youtube/define.js +0 -3
  37. package/dist/youtube/index.d.ts +0 -31
  38. package/dist/youtube/index.js +0 -56
  39. /package/dist/{base/define.d.ts → types/index.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { Base } from "../base/index.js";
1
+ import { Content, Lifecycle, Trigger, } from "../base/index.js";
2
2
  /**
3
3
  * Enhances the `textarea` element with controls to add content and keyboard shortcuts. Compared to other WYSIWYG editors, the `text` value is just a `string`, so you can easily store it in a database or manipulate it without learning a separate API.
4
4
  *
@@ -36,14 +36,14 @@ import { Base } from "../base/index.js";
36
36
  * Add a `ctrl`/`meta` keyboard shortcut for the content based on the `data-key` attribute.
37
37
  *
38
38
  */
39
- export class Editor extends Base {
39
+ export class Editor extends Lifecycle(Trigger(Content())) {
40
40
  /** Array of `keyPair` characters that have been opened. */
41
41
  #openChars = [];
42
42
  /** Keys that will reset the type over for keyPairs */
43
43
  #resetKeys = new Set(["ArrowUp", "ArrowDown", "Delete"]);
44
44
  #inputEvent = new Event("input", { bubbles: true, cancelable: true });
45
45
  /** Characters that will be automatically closed when typed. */
46
- keyPairs = {
46
+ #keyPairs = {
47
47
  "(": ")",
48
48
  "{": "}",
49
49
  "[": "]",
@@ -56,55 +56,55 @@ export class Editor extends Base {
56
56
  // add any `type: "wrap"` values from `contentElements` to `keyPairs`
57
57
  for (const element of this.#contentElements) {
58
58
  if (element.type === "wrap")
59
- this.keyPairs[element.value] = element.value;
59
+ this.#keyPairs[element.value] = element.value;
60
60
  }
61
61
  }
62
62
  /** The `content`, expects an `HTMLTextAreaElement`. */
63
- get textArea() {
64
- return this.getContent(HTMLTextAreaElement);
63
+ get #textArea() {
64
+ return this.content(HTMLTextAreaElement);
65
65
  }
66
66
  /** The current `value` of the `textarea`. */
67
- get text() {
68
- return this.textArea.value;
67
+ get #text() {
68
+ return this.#textArea.value;
69
69
  }
70
- set text(value) {
71
- this.textArea.value = value;
72
- this.textArea.dispatchEvent(this.#inputEvent);
70
+ set #text(value) {
71
+ this.#textArea.value = value;
72
+ this.#textArea.dispatchEvent(this.#inputEvent);
73
73
  }
74
74
  /** Array of `ContentElement`s derived from each `trigger`'s data attributes. */
75
75
  get #contentElements() {
76
76
  const contentElements = [];
77
- for (const trigger of this.getTrigger()) {
77
+ for (const trigger of this.triggers()) {
78
78
  contentElements.push(trigger.dataset);
79
79
  }
80
80
  return contentElements;
81
81
  }
82
82
  /** Gets the end position of the selection */
83
83
  get #selEnd() {
84
- return this.textArea.selectionEnd;
84
+ return this.#textArea.selectionEnd;
85
85
  }
86
86
  /** Gets the start position of the selection. */
87
87
  get #selStart() {
88
- return this.textArea.selectionStart;
88
+ return this.#textArea.selectionStart;
89
89
  }
90
90
  /**
91
91
  * @param str string to insert into `text`
92
92
  * @param index where to insert the string
93
93
  */
94
94
  #insertStr(str, index) {
95
- this.text = this.text.slice(0, index) + str + this.text.slice(index);
95
+ this.#text = this.#text.slice(0, index) + str + this.#text.slice(index);
96
96
  }
97
97
  /**
98
98
  * @param start Starting index for removal.
99
99
  * @param end Optional ending index - defaults to start + 1 to remove 1 character.
100
100
  */
101
101
  #removeStr(start, end = start + 1) {
102
- this.text = this.text.slice(0, start) + this.text.slice(end);
102
+ this.#text = this.#text.slice(0, start) + this.#text.slice(end);
103
103
  }
104
104
  /** Sets the current cursor selection in the `textarea` */
105
105
  #setSelection(start, end = start) {
106
- this.textArea.setSelectionRange(start, end);
107
- this.textArea.focus();
106
+ this.#textArea.setSelectionRange(start, end);
107
+ this.#textArea.focus();
108
108
  }
109
109
  /**
110
110
  * Inserts text and sets selection based on the `ContentElement` selected.
@@ -128,7 +128,7 @@ export class Editor extends Base {
128
128
  else if (type === "wrap") {
129
129
  const end = this.#selEnd + value.length;
130
130
  this.#insertStr(value, start);
131
- this.#insertStr(this.keyPairs[value], end);
131
+ this.#insertStr(this.#keyPairs[value], end);
132
132
  this.#setSelection(start + value.length, end);
133
133
  // if single char, add to opened
134
134
  if (value.length === 1)
@@ -144,7 +144,7 @@ export class Editor extends Base {
144
144
  }
145
145
  // add the string to the beginning of the line
146
146
  lines[lineNumber] = value + lines[lineNumber];
147
- this.text = lines.join("\n");
147
+ this.#text = lines.join("\n");
148
148
  this.#setSelection(start + value.length);
149
149
  }
150
150
  }
@@ -175,7 +175,7 @@ export class Editor extends Base {
175
175
  * @returns Metadata describing the current position of the selection.
176
176
  */
177
177
  #lineMeta() {
178
- const lines = this.text.split("\n");
178
+ const lines = this.#text.split("\n");
179
179
  let charCount = 0;
180
180
  for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
181
181
  const line = lines[lineNumber];
@@ -235,21 +235,21 @@ export class Editor extends Base {
235
235
  }
236
236
  }
237
237
  const start = this.#selStart;
238
- this.text = lines.join("\n");
238
+ this.#text = lines.join("\n");
239
239
  this.#setSelection(start);
240
240
  }
241
241
  mount() {
242
- this.textArea.addEventListener("keydown", (e) => {
243
- const nextChar = this.text[this.#selEnd] ?? "";
242
+ this.#textArea.addEventListener("keydown", (e) => {
243
+ const nextChar = this.#text[this.#selEnd] ?? "";
244
244
  const notHighlighted = this.#selStart === this.#selEnd;
245
245
  if (this.#resetKeys.has(e.key)) {
246
246
  this.#openChars = [];
247
247
  }
248
248
  else if (e.key === "Backspace") {
249
- const prevChar = this.text[this.#selStart - 1];
249
+ const prevChar = this.#text[this.#selStart - 1];
250
250
  if (prevChar &&
251
- prevChar in this.keyPairs &&
252
- nextChar === this.keyPairs[prevChar]) {
251
+ prevChar in this.#keyPairs &&
252
+ nextChar === this.#keyPairs[prevChar]) {
253
253
  // remove both characters if the next one is the match of the prev
254
254
  e.preventDefault();
255
255
  const start = this.#selStart - 1;
@@ -268,7 +268,7 @@ export class Editor extends Base {
268
268
  }
269
269
  }
270
270
  else if (e.key === "Tab") {
271
- const blocks = this.text.split("```");
271
+ const blocks = this.#text.split("```");
272
272
  let totalChars = 0;
273
273
  for (const [i, block] of blocks.entries()) {
274
274
  totalChars += block.length + 3;
@@ -328,7 +328,7 @@ export class Editor extends Base {
328
328
  if (e.key === "x") {
329
329
  const newPos = this.#selStart - columnNumber;
330
330
  lines.splice(lineNumber, 1);
331
- this.text = lines.join("\n");
331
+ this.#text = lines.join("\n");
332
332
  this.#setSelection(newPos, newPos);
333
333
  }
334
334
  }
@@ -339,30 +339,30 @@ export class Editor extends Base {
339
339
  else if (this.#openChars.length &&
340
340
  notHighlighted &&
341
341
  (nextChar === e.key || e.key === "ArrowRight") &&
342
- Object.values(this.keyPairs).includes(nextChar)) {
342
+ Object.values(this.#keyPairs).includes(nextChar)) {
343
343
  // type over the next character instead of inserting
344
344
  e.preventDefault();
345
345
  this.#setSelection(this.#selStart + 1, this.#selEnd + 1);
346
346
  this.#openChars.pop();
347
347
  }
348
- else if (e.key in this.keyPairs) {
348
+ else if (e.key in this.#keyPairs) {
349
349
  e.preventDefault();
350
350
  this.#addContent({ type: "wrap", value: e.key });
351
351
  }
352
352
  });
353
353
  // trims the selection if there is an extra space around it
354
- this.textArea.addEventListener("dblclick", () => {
354
+ this.#textArea.addEventListener("dblclick", () => {
355
355
  if (this.#selStart !== this.#selEnd) {
356
- if (this.text[this.#selStart] === " ") {
356
+ if (this.#text[this.#selStart] === " ") {
357
357
  this.#setSelection(this.#selStart + 1, this.#selEnd);
358
358
  }
359
- if (this.text[this.#selEnd - 1] === " ") {
359
+ if (this.#text[this.#selEnd - 1] === " ") {
360
360
  this.#setSelection(this.#selStart, this.#selEnd - 1);
361
361
  }
362
362
  }
363
363
  });
364
364
  // reset #openChars on click since the cursor has changed position
365
- this.textArea.addEventListener("click", () => (this.#openChars = []));
366
- this.triggerListener((e) => this.#addContent(e.currentTarget.dataset));
365
+ this.#textArea.addEventListener("click", () => (this.#openChars = []));
366
+ this.listener((e) => this.#addContent(e.currentTarget.dataset));
367
367
  }
368
368
  }