tiny-essentials 1.17.1 → 1.18.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.
Files changed (39) hide show
  1. package/dist/v1/TinyBasicsEs.js +164 -21
  2. package/dist/v1/TinyBasicsEs.min.js +1 -1
  3. package/dist/v1/TinyClipboard.js +459 -0
  4. package/dist/v1/TinyClipboard.min.js +1 -0
  5. package/dist/v1/TinyDragger.js +164 -21
  6. package/dist/v1/TinyDragger.min.js +1 -1
  7. package/dist/v1/TinyEssentials.js +1046 -21
  8. package/dist/v1/TinyEssentials.min.js +1 -1
  9. package/dist/v1/TinyHtml.js +164 -21
  10. package/dist/v1/TinyHtml.min.js +1 -1
  11. package/dist/v1/TinySmartScroller.js +164 -21
  12. package/dist/v1/TinySmartScroller.min.js +1 -1
  13. package/dist/v1/TinyTextRangeEditor.js +497 -0
  14. package/dist/v1/TinyTextRangeEditor.min.js +1 -0
  15. package/dist/v1/TinyUploadClicker.js +166 -21
  16. package/dist/v1/TinyUploadClicker.min.js +1 -1
  17. package/dist/v1/build/TinyClipboard.cjs +7 -0
  18. package/dist/v1/build/TinyClipboard.d.mts +3 -0
  19. package/dist/v1/build/TinyClipboard.mjs +2 -0
  20. package/dist/v1/build/TinyTextRangeEditor.cjs +7 -0
  21. package/dist/v1/build/TinyTextRangeEditor.d.mts +3 -0
  22. package/dist/v1/build/TinyTextRangeEditor.mjs +2 -0
  23. package/dist/v1/index.cjs +4 -0
  24. package/dist/v1/index.d.mts +3 -1
  25. package/dist/v1/index.mjs +3 -1
  26. package/dist/v1/libs/TinyClipboard.cjs +420 -0
  27. package/dist/v1/libs/TinyClipboard.d.mts +155 -0
  28. package/dist/v1/libs/TinyClipboard.mjs +398 -0
  29. package/dist/v1/libs/TinyHtml.cjs +164 -21
  30. package/dist/v1/libs/TinyHtml.d.mts +150 -27
  31. package/dist/v1/libs/TinyHtml.mjs +158 -20
  32. package/dist/v1/libs/TinyTextRangeEditor.cjs +458 -0
  33. package/dist/v1/libs/TinyTextRangeEditor.d.mts +200 -0
  34. package/dist/v1/libs/TinyTextRangeEditor.mjs +424 -0
  35. package/docs/v1/README.md +2 -0
  36. package/docs/v1/libs/TinyClipboard.md +213 -0
  37. package/docs/v1/libs/TinyHtml.md +112 -15
  38. package/docs/v1/libs/TinyTextRangeEditor.md +208 -0
  39. package/package.json +1 -1
@@ -2656,6 +2656,21 @@ const {
2656
2656
  * @typedef {Element|Window|Document} ElementAndWinAndDoc
2657
2657
  */
2658
2658
 
2659
+ /**
2660
+ * Represents a raw DOM element with document or an instance of TinyHtml.
2661
+ * This type is used to abstract interactions with both plain elements
2662
+ * and wrapped elements via the TinyHtml class.
2663
+ *
2664
+ * @typedef {ElementWithDoc|TinyHtml} TinyElementWithDoc
2665
+ */
2666
+
2667
+ /**
2668
+ * Represents a value that can be either a DOM Element, or the document object.
2669
+ * Useful for functions that operate generically on measurable targets.
2670
+ *
2671
+ * @typedef {Element|Document} ElementWithDoc
2672
+ */
2673
+
2659
2674
  /**
2660
2675
  * A parameter type used for filtering or matching elements.
2661
2676
  * It can be:
@@ -2675,12 +2690,6 @@ const {
2675
2690
  * @typedef {Window|Element|Document|Text} ConstructorElValues
2676
2691
  */
2677
2692
 
2678
- /**
2679
- * The handler function used in event listeners.
2680
- *
2681
- * @typedef {(e: Event) => any} EventRegistryHandle
2682
- */
2683
-
2684
2693
  /**
2685
2694
  * Options passed to `addEventListener` or `removeEventListener`.
2686
2695
  * Can be a boolean or an object of type `AddEventListenerOptions`.
@@ -2692,7 +2701,7 @@ const {
2692
2701
  * Structure describing a registered event callback and its options.
2693
2702
  *
2694
2703
  * @typedef {Object} EventRegistryItem
2695
- * @property {EventRegistryHandle} handler - The function to be executed when the event is triggered.
2704
+ * @property {EventListenerOrEventListenerObject|null} handler - The function to be executed when the event is triggered.
2696
2705
  * @property {EventRegistryOptions} [options] - Optional configuration passed to the listener.
2697
2706
  */
2698
2707
 
@@ -3251,9 +3260,9 @@ class TinyHtml {
3251
3260
  * Ensures the input is returned as an array.
3252
3261
  * Useful to normalize operations across multiple or single element/window/document elements.
3253
3262
  *
3254
- * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
3263
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
3255
3264
  * @param {string} where - The method or context name where validation is being called.
3256
- * @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
3265
+ * @returns {ElementAndWindow[]} - Always returns an array of element/document/window elements.
3257
3266
  * @readonly
3258
3267
  */
3259
3268
  static _preElemsAndWinAndDoc(elems, where) {
@@ -3270,9 +3279,9 @@ class TinyHtml {
3270
3279
  * Ensures the input is returned as an single element/window/document element.
3271
3280
  * Useful to normalize operations across multiple or single element/window/document elements.
3272
3281
  *
3273
- * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
3282
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
3274
3283
  * @param {string} where - The method or context name where validation is being called.
3275
- * @returns {ElementAndWindow} - Always returns an single element/window element.
3284
+ * @returns {ElementAndWindow} - Always returns an single element/document/window element.
3276
3285
  * @readonly
3277
3286
  */
3278
3287
  static _preElemAndWinAndDoc(elems, where) {
@@ -3286,6 +3295,32 @@ class TinyHtml {
3286
3295
  return result;
3287
3296
  }
3288
3297
 
3298
+ /**
3299
+ * Ensures the input is returned as an array.
3300
+ * Useful to normalize operations across multiple or single element with document elements.
3301
+ *
3302
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element with document element or array of html elements.
3303
+ * @param {string} where - The method or context name where validation is being called.
3304
+ * @returns {ElementWithDoc[]} - Always returns an array of element with document elements.
3305
+ * @readonly
3306
+ */
3307
+ static _preElemsWithDoc(elems, where) {
3308
+ return TinyHtml._preElemsTemplate(elems, where, [Element, Document], ['Element', 'Document']);
3309
+ }
3310
+
3311
+ /**
3312
+ * Ensures the input is returned as an single element with document element.
3313
+ * Useful to normalize operations across multiple or single element with document elements.
3314
+ *
3315
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element/window element or array of html elements.
3316
+ * @param {string} where - The method or context name where validation is being called.
3317
+ * @returns {ElementWithDoc} - Always returns an single element/window element.
3318
+ * @readonly
3319
+ */
3320
+ static _preElemWithDoc(elems, where) {
3321
+ return TinyHtml._preElemTemplate(elems, where, [Element, Document], ['Element', 'Document']);
3322
+ }
3323
+
3289
3324
  /**
3290
3325
  * Normalizes and converts one or more DOM elements (or TinyHtml instances)
3291
3326
  * into an array of `TinyHtml` instances.
@@ -6545,12 +6580,120 @@ class TinyHtml {
6545
6580
 
6546
6581
  ////////////////////////////////////////////
6547
6582
 
6583
+ /**
6584
+ * Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
6585
+ *
6586
+ * This method allows reacting to pasted content by providing separate callbacks for files and plain text.
6587
+ * Useful for building file upload areas, rich-text editors, or input enhancements.
6588
+ *
6589
+ * @param {TinyElementWithDoc|TinyElementWithDoc[]} el - The target element(s) where the "paste" event will be listened.
6590
+ * @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
6591
+ * @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
6592
+ * @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
6593
+ * @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
6594
+ */
6595
+ static listenForPaste(el, { onFilePaste, onTextPaste } = {}) {
6596
+ if (typeof onFilePaste !== 'undefined' && typeof onFilePaste !== 'function')
6597
+ throw new TypeError('onFilePaste must be a function.');
6598
+ if (typeof onTextPaste !== 'undefined' && typeof onTextPaste !== 'function')
6599
+ throw new TypeError('onTextPaste must be a function.');
6600
+
6601
+ /** @type {EventListenerOrEventListenerObject} */
6602
+ const pasteEvent = (event) => {
6603
+ if (!(event instanceof ClipboardEvent)) return;
6604
+ const items = event.clipboardData?.items || [];
6605
+ for (const item of items) {
6606
+ if (item.kind === 'file') {
6607
+ if (typeof onFilePaste === 'function') {
6608
+ const file = item.getAsFile();
6609
+ if (file) onFilePaste(item, file);
6610
+ }
6611
+ } else if (item.kind === 'string') {
6612
+ if (typeof onTextPaste === 'function')
6613
+ item.getAsString((text) => onTextPaste(item, text));
6614
+ }
6615
+ }
6616
+ };
6617
+
6618
+ TinyHtml._preElemsWithDoc(el, 'listenForPaste').forEach((elem) =>
6619
+ TinyHtml.on(elem, 'paste', pasteEvent),
6620
+ );
6621
+ return pasteEvent;
6622
+ }
6623
+
6624
+ /**
6625
+ * Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
6626
+ *
6627
+ * This method allows reacting to pasted content by providing separate callbacks for files and plain text.
6628
+ * Useful for building file upload areas, rich-text editors, or input enhancements.
6629
+ *
6630
+ * @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
6631
+ * @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
6632
+ * @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
6633
+ * @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
6634
+ */
6635
+ listenForPaste({ onFilePaste, onTextPaste } = {}) {
6636
+ return TinyHtml.listenForPaste(this, { onFilePaste, onTextPaste });
6637
+ }
6638
+
6639
+ /**
6640
+ * Checks if the element has a listener for a specific event.
6641
+ *
6642
+ * @param {TinyEventTarget} el - The element to check.
6643
+ * @param {string} event - The event name to check.
6644
+ * @returns {boolean}
6645
+ */
6646
+ static hasEventListener(el, event) {
6647
+ const elem = TinyHtml._preEventTargetElem(el, 'hasEventListener');
6648
+ if (!__eventRegistry.has(elem)) return false;
6649
+ const events = __eventRegistry.get(elem);
6650
+ return !!(events && Array.isArray(events[event]) && events[event].length > 0);
6651
+ }
6652
+
6653
+ /**
6654
+ * Checks if the element has a listener for a specific event.
6655
+ *
6656
+ * @param {string} event - The event name to check.
6657
+ * @returns {boolean}
6658
+ */
6659
+ hasEventListener(event) {
6660
+ return TinyHtml.hasEventListener(this, event);
6661
+ }
6662
+
6663
+ /**
6664
+ * Checks if the element has the exact handler registered for a specific event.
6665
+ *
6666
+ * @param {TinyEventTarget} el - The element to check.
6667
+ * @param {string} event - The event name to check.
6668
+ * @param {EventListenerOrEventListenerObject} handler - The handler function to check.
6669
+ * @returns {boolean}
6670
+ */
6671
+ static hasExactEventListener(el, event, handler) {
6672
+ const elem = TinyHtml._preEventTargetElem(el, 'hasExactEventListener');
6673
+ if (typeof handler !== 'function') throw new TypeError('The "handler" must be a function.');
6674
+ if (!__eventRegistry.has(elem)) return false;
6675
+ const events = __eventRegistry.get(elem);
6676
+ if (!events || !Array.isArray(events[event])) return false;
6677
+ return events[event].some((item) => item.handler === handler);
6678
+ }
6679
+
6680
+ /**
6681
+ * Checks if the element has the exact handler registered for a specific event.
6682
+ *
6683
+ * @param {string} event - The event name to check.
6684
+ * @param {EventListenerOrEventListenerObject} handler - The handler function to check.
6685
+ * @returns {boolean}
6686
+ */
6687
+ hasExactEventListener(event, handler) {
6688
+ return TinyHtml.hasExactEventListener(this, event, handler);
6689
+ }
6690
+
6548
6691
  /**
6549
6692
  * Registers an event listener on the specified element.
6550
6693
  *
6551
6694
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
6552
6695
  * @param {string} event - The event type (e.g. 'click', 'keydown').
6553
- * @param {EventRegistryHandle} handler - The callback function to run on event.
6696
+ * @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
6554
6697
  * @param {EventRegistryOptions} [options] - Optional event listener options.
6555
6698
  * @returns {TinyEventTarget|TinyEventTarget[]}
6556
6699
  */
@@ -6572,7 +6715,7 @@ class TinyHtml {
6572
6715
  * Registers an event listener on the specified element.
6573
6716
  *
6574
6717
  * @param {string} event - The event type (e.g. 'click', 'keydown').
6575
- * @param {EventRegistryHandle} handler - The callback function to run on event.
6718
+ * @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
6576
6719
  * @param {EventRegistryOptions} [options] - Optional event listener options.
6577
6720
  * @returns {TinyEventTarget|TinyEventTarget[]}
6578
6721
  */
@@ -6585,17 +6728,17 @@ class TinyHtml {
6585
6728
  *
6586
6729
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
6587
6730
  * @param {string} event - The event type (e.g. 'click', 'keydown').
6588
- * @param {EventRegistryHandle} handler - The callback function to run on event.
6731
+ * @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
6589
6732
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
6590
6733
  * @returns {TinyEventTarget|TinyEventTarget[]}
6591
6734
  */
6592
6735
  static once(el, event, handler, options = {}) {
6593
6736
  if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
6594
6737
  TinyHtml._preEventTargetElems(el, 'once').forEach((elem) => {
6595
- /** @type {EventRegistryHandle} e */
6738
+ /** @type {EventListenerOrEventListenerObject} */
6596
6739
  const wrapped = (e) => {
6597
6740
  TinyHtml.off(elem, event, wrapped);
6598
- handler(e);
6741
+ if (typeof handler === 'function') handler(e);
6599
6742
  };
6600
6743
 
6601
6744
  TinyHtml.on(
@@ -6612,7 +6755,7 @@ class TinyHtml {
6612
6755
  * Registers an event listener that runs only once, then is removed.
6613
6756
  *
6614
6757
  * @param {string} event - The event type (e.g. 'click', 'keydown').
6615
- * @param {EventRegistryHandle} handler - The callback function to run on event.
6758
+ * @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
6616
6759
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
6617
6760
  * @returns {TinyEventTarget|TinyEventTarget[]}
6618
6761
  */
@@ -6625,7 +6768,7 @@ class TinyHtml {
6625
6768
  *
6626
6769
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
6627
6770
  * @param {string} event - The event type.
6628
- * @param {EventRegistryHandle} handler - The function originally bound to the event.
6771
+ * @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
6629
6772
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
6630
6773
  * @returns {TinyEventTarget|TinyEventTarget[]}
6631
6774
  */
@@ -6647,7 +6790,7 @@ class TinyHtml {
6647
6790
  * Removes a specific event listener from an element.
6648
6791
  *
6649
6792
  * @param {string} event - The event type.
6650
- * @param {EventRegistryHandle} handler - The function originally bound to the event.
6793
+ * @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
6651
6794
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
6652
6795
  * @returns {TinyEventTarget|TinyEventTarget[]}
6653
6796
  */
@@ -6690,7 +6833,7 @@ class TinyHtml {
6690
6833
  * Removes all event listeners of all types from the element.
6691
6834
  *
6692
6835
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
6693
- * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
6836
+ * @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
6694
6837
  * Optional filter function to selectively remove specific handlers.
6695
6838
  * @returns {TinyEventTarget|TinyEventTarget[]}
6696
6839
  */
@@ -6717,7 +6860,7 @@ class TinyHtml {
6717
6860
  /**
6718
6861
  * Removes all event listeners of all types from the element.
6719
6862
  *
6720
- * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
6863
+ * @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
6721
6864
  * Optional filter function to selectively remove specific handlers.
6722
6865
  * @returns {TinyEventTarget|TinyEventTarget[]}
6723
6866
  */