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.
- package/dist/v1/TinyBasicsEs.js +164 -21
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyClipboard.js +459 -0
- package/dist/v1/TinyClipboard.min.js +1 -0
- package/dist/v1/TinyDragger.js +164 -21
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +1046 -21
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +164 -21
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +164 -21
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.js +497 -0
- package/dist/v1/TinyTextRangeEditor.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +166 -21
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/build/TinyClipboard.cjs +7 -0
- package/dist/v1/build/TinyClipboard.d.mts +3 -0
- package/dist/v1/build/TinyClipboard.mjs +2 -0
- package/dist/v1/build/TinyTextRangeEditor.cjs +7 -0
- package/dist/v1/build/TinyTextRangeEditor.d.mts +3 -0
- package/dist/v1/build/TinyTextRangeEditor.mjs +2 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -1
- package/dist/v1/libs/TinyClipboard.cjs +420 -0
- package/dist/v1/libs/TinyClipboard.d.mts +155 -0
- package/dist/v1/libs/TinyClipboard.mjs +398 -0
- package/dist/v1/libs/TinyHtml.cjs +164 -21
- package/dist/v1/libs/TinyHtml.d.mts +150 -27
- package/dist/v1/libs/TinyHtml.mjs +158 -20
- package/dist/v1/libs/TinyTextRangeEditor.cjs +458 -0
- package/dist/v1/libs/TinyTextRangeEditor.d.mts +200 -0
- package/dist/v1/libs/TinyTextRangeEditor.mjs +424 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/libs/TinyClipboard.md +213 -0
- package/docs/v1/libs/TinyHtml.md +112 -15
- package/docs/v1/libs/TinyTextRangeEditor.md +208 -0
- package/package.json +1 -1
package/dist/v1/TinyBasicsEs.js
CHANGED
|
@@ -3782,6 +3782,21 @@ const {
|
|
|
3782
3782
|
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
3783
3783
|
*/
|
|
3784
3784
|
|
|
3785
|
+
/**
|
|
3786
|
+
* Represents a raw DOM element with document or an instance of TinyHtml.
|
|
3787
|
+
* This type is used to abstract interactions with both plain elements
|
|
3788
|
+
* and wrapped elements via the TinyHtml class.
|
|
3789
|
+
*
|
|
3790
|
+
* @typedef {ElementWithDoc|TinyHtml} TinyElementWithDoc
|
|
3791
|
+
*/
|
|
3792
|
+
|
|
3793
|
+
/**
|
|
3794
|
+
* Represents a value that can be either a DOM Element, or the document object.
|
|
3795
|
+
* Useful for functions that operate generically on measurable targets.
|
|
3796
|
+
*
|
|
3797
|
+
* @typedef {Element|Document} ElementWithDoc
|
|
3798
|
+
*/
|
|
3799
|
+
|
|
3785
3800
|
/**
|
|
3786
3801
|
* A parameter type used for filtering or matching elements.
|
|
3787
3802
|
* It can be:
|
|
@@ -3801,12 +3816,6 @@ const {
|
|
|
3801
3816
|
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
3802
3817
|
*/
|
|
3803
3818
|
|
|
3804
|
-
/**
|
|
3805
|
-
* The handler function used in event listeners.
|
|
3806
|
-
*
|
|
3807
|
-
* @typedef {(e: Event) => any} EventRegistryHandle
|
|
3808
|
-
*/
|
|
3809
|
-
|
|
3810
3819
|
/**
|
|
3811
3820
|
* Options passed to `addEventListener` or `removeEventListener`.
|
|
3812
3821
|
* Can be a boolean or an object of type `AddEventListenerOptions`.
|
|
@@ -3818,7 +3827,7 @@ const {
|
|
|
3818
3827
|
* Structure describing a registered event callback and its options.
|
|
3819
3828
|
*
|
|
3820
3829
|
* @typedef {Object} EventRegistryItem
|
|
3821
|
-
* @property {
|
|
3830
|
+
* @property {EventListenerOrEventListenerObject|null} handler - The function to be executed when the event is triggered.
|
|
3822
3831
|
* @property {EventRegistryOptions} [options] - Optional configuration passed to the listener.
|
|
3823
3832
|
*/
|
|
3824
3833
|
|
|
@@ -4377,9 +4386,9 @@ class TinyHtml_TinyHtml {
|
|
|
4377
4386
|
* Ensures the input is returned as an array.
|
|
4378
4387
|
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
4379
4388
|
*
|
|
4380
|
-
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
4389
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
|
|
4381
4390
|
* @param {string} where - The method or context name where validation is being called.
|
|
4382
|
-
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
4391
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/document/window elements.
|
|
4383
4392
|
* @readonly
|
|
4384
4393
|
*/
|
|
4385
4394
|
static _preElemsAndWinAndDoc(elems, where) {
|
|
@@ -4396,9 +4405,9 @@ class TinyHtml_TinyHtml {
|
|
|
4396
4405
|
* Ensures the input is returned as an single element/window/document element.
|
|
4397
4406
|
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
4398
4407
|
*
|
|
4399
|
-
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
4408
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/document/window element or array of html elements.
|
|
4400
4409
|
* @param {string} where - The method or context name where validation is being called.
|
|
4401
|
-
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
4410
|
+
* @returns {ElementAndWindow} - Always returns an single element/document/window element.
|
|
4402
4411
|
* @readonly
|
|
4403
4412
|
*/
|
|
4404
4413
|
static _preElemAndWinAndDoc(elems, where) {
|
|
@@ -4412,6 +4421,32 @@ class TinyHtml_TinyHtml {
|
|
|
4412
4421
|
return result;
|
|
4413
4422
|
}
|
|
4414
4423
|
|
|
4424
|
+
/**
|
|
4425
|
+
* Ensures the input is returned as an array.
|
|
4426
|
+
* Useful to normalize operations across multiple or single element with document elements.
|
|
4427
|
+
*
|
|
4428
|
+
* @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element with document element or array of html elements.
|
|
4429
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
4430
|
+
* @returns {ElementWithDoc[]} - Always returns an array of element with document elements.
|
|
4431
|
+
* @readonly
|
|
4432
|
+
*/
|
|
4433
|
+
static _preElemsWithDoc(elems, where) {
|
|
4434
|
+
return TinyHtml_TinyHtml._preElemsTemplate(elems, where, [Element, Document], ['Element', 'Document']);
|
|
4435
|
+
}
|
|
4436
|
+
|
|
4437
|
+
/**
|
|
4438
|
+
* Ensures the input is returned as an single element with document element.
|
|
4439
|
+
* Useful to normalize operations across multiple or single element with document elements.
|
|
4440
|
+
*
|
|
4441
|
+
* @param {TinyElementWithDoc|TinyElementWithDoc[]} elems - A single element/window element or array of html elements.
|
|
4442
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
4443
|
+
* @returns {ElementWithDoc} - Always returns an single element/window element.
|
|
4444
|
+
* @readonly
|
|
4445
|
+
*/
|
|
4446
|
+
static _preElemWithDoc(elems, where) {
|
|
4447
|
+
return TinyHtml_TinyHtml._preElemTemplate(elems, where, [Element, Document], ['Element', 'Document']);
|
|
4448
|
+
}
|
|
4449
|
+
|
|
4415
4450
|
/**
|
|
4416
4451
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
4417
4452
|
* into an array of `TinyHtml` instances.
|
|
@@ -7671,12 +7706,120 @@ class TinyHtml_TinyHtml {
|
|
|
7671
7706
|
|
|
7672
7707
|
////////////////////////////////////////////
|
|
7673
7708
|
|
|
7709
|
+
/**
|
|
7710
|
+
* Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
|
|
7711
|
+
*
|
|
7712
|
+
* This method allows reacting to pasted content by providing separate callbacks for files and plain text.
|
|
7713
|
+
* Useful for building file upload areas, rich-text editors, or input enhancements.
|
|
7714
|
+
*
|
|
7715
|
+
* @param {TinyElementWithDoc|TinyElementWithDoc[]} el - The target element(s) where the "paste" event will be listened.
|
|
7716
|
+
* @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
|
|
7717
|
+
* @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
|
|
7718
|
+
* @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
|
|
7719
|
+
* @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
|
|
7720
|
+
*/
|
|
7721
|
+
static listenForPaste(el, { onFilePaste, onTextPaste } = {}) {
|
|
7722
|
+
if (typeof onFilePaste !== 'undefined' && typeof onFilePaste !== 'function')
|
|
7723
|
+
throw new TypeError('onFilePaste must be a function.');
|
|
7724
|
+
if (typeof onTextPaste !== 'undefined' && typeof onTextPaste !== 'function')
|
|
7725
|
+
throw new TypeError('onTextPaste must be a function.');
|
|
7726
|
+
|
|
7727
|
+
/** @type {EventListenerOrEventListenerObject} */
|
|
7728
|
+
const pasteEvent = (event) => {
|
|
7729
|
+
if (!(event instanceof ClipboardEvent)) return;
|
|
7730
|
+
const items = event.clipboardData?.items || [];
|
|
7731
|
+
for (const item of items) {
|
|
7732
|
+
if (item.kind === 'file') {
|
|
7733
|
+
if (typeof onFilePaste === 'function') {
|
|
7734
|
+
const file = item.getAsFile();
|
|
7735
|
+
if (file) onFilePaste(item, file);
|
|
7736
|
+
}
|
|
7737
|
+
} else if (item.kind === 'string') {
|
|
7738
|
+
if (typeof onTextPaste === 'function')
|
|
7739
|
+
item.getAsString((text) => onTextPaste(item, text));
|
|
7740
|
+
}
|
|
7741
|
+
}
|
|
7742
|
+
};
|
|
7743
|
+
|
|
7744
|
+
TinyHtml_TinyHtml._preElemsWithDoc(el, 'listenForPaste').forEach((elem) =>
|
|
7745
|
+
TinyHtml_TinyHtml.on(elem, 'paste', pasteEvent),
|
|
7746
|
+
);
|
|
7747
|
+
return pasteEvent;
|
|
7748
|
+
}
|
|
7749
|
+
|
|
7750
|
+
/**
|
|
7751
|
+
* Registers a listener for the "paste" event to extract files and text from the clipboard (e.g., when the user presses Ctrl+V).
|
|
7752
|
+
*
|
|
7753
|
+
* This method allows reacting to pasted content by providing separate callbacks for files and plain text.
|
|
7754
|
+
* Useful for building file upload areas, rich-text editors, or input enhancements.
|
|
7755
|
+
*
|
|
7756
|
+
* @param {Object} [settings={}] - Optional callbacks to handle clipboard content.
|
|
7757
|
+
* @param {(data: DataTransferItem, file: File) => void} [settings.onFilePaste] - Called for each file pasted from the clipboard (e.g., images).
|
|
7758
|
+
* @param {(data: DataTransferItem, text: string) => void} [settings.onTextPaste] - Called when plain text is pasted from the clipboard.
|
|
7759
|
+
* @returns {EventListenerOrEventListenerObject} The internal "paste" event handler used.
|
|
7760
|
+
*/
|
|
7761
|
+
listenForPaste({ onFilePaste, onTextPaste } = {}) {
|
|
7762
|
+
return TinyHtml_TinyHtml.listenForPaste(this, { onFilePaste, onTextPaste });
|
|
7763
|
+
}
|
|
7764
|
+
|
|
7765
|
+
/**
|
|
7766
|
+
* Checks if the element has a listener for a specific event.
|
|
7767
|
+
*
|
|
7768
|
+
* @param {TinyEventTarget} el - The element to check.
|
|
7769
|
+
* @param {string} event - The event name to check.
|
|
7770
|
+
* @returns {boolean}
|
|
7771
|
+
*/
|
|
7772
|
+
static hasEventListener(el, event) {
|
|
7773
|
+
const elem = TinyHtml_TinyHtml._preEventTargetElem(el, 'hasEventListener');
|
|
7774
|
+
if (!__eventRegistry.has(elem)) return false;
|
|
7775
|
+
const events = __eventRegistry.get(elem);
|
|
7776
|
+
return !!(events && Array.isArray(events[event]) && events[event].length > 0);
|
|
7777
|
+
}
|
|
7778
|
+
|
|
7779
|
+
/**
|
|
7780
|
+
* Checks if the element has a listener for a specific event.
|
|
7781
|
+
*
|
|
7782
|
+
* @param {string} event - The event name to check.
|
|
7783
|
+
* @returns {boolean}
|
|
7784
|
+
*/
|
|
7785
|
+
hasEventListener(event) {
|
|
7786
|
+
return TinyHtml_TinyHtml.hasEventListener(this, event);
|
|
7787
|
+
}
|
|
7788
|
+
|
|
7789
|
+
/**
|
|
7790
|
+
* Checks if the element has the exact handler registered for a specific event.
|
|
7791
|
+
*
|
|
7792
|
+
* @param {TinyEventTarget} el - The element to check.
|
|
7793
|
+
* @param {string} event - The event name to check.
|
|
7794
|
+
* @param {EventListenerOrEventListenerObject} handler - The handler function to check.
|
|
7795
|
+
* @returns {boolean}
|
|
7796
|
+
*/
|
|
7797
|
+
static hasExactEventListener(el, event, handler) {
|
|
7798
|
+
const elem = TinyHtml_TinyHtml._preEventTargetElem(el, 'hasExactEventListener');
|
|
7799
|
+
if (typeof handler !== 'function') throw new TypeError('The "handler" must be a function.');
|
|
7800
|
+
if (!__eventRegistry.has(elem)) return false;
|
|
7801
|
+
const events = __eventRegistry.get(elem);
|
|
7802
|
+
if (!events || !Array.isArray(events[event])) return false;
|
|
7803
|
+
return events[event].some((item) => item.handler === handler);
|
|
7804
|
+
}
|
|
7805
|
+
|
|
7806
|
+
/**
|
|
7807
|
+
* Checks if the element has the exact handler registered for a specific event.
|
|
7808
|
+
*
|
|
7809
|
+
* @param {string} event - The event name to check.
|
|
7810
|
+
* @param {EventListenerOrEventListenerObject} handler - The handler function to check.
|
|
7811
|
+
* @returns {boolean}
|
|
7812
|
+
*/
|
|
7813
|
+
hasExactEventListener(event, handler) {
|
|
7814
|
+
return TinyHtml_TinyHtml.hasExactEventListener(this, event, handler);
|
|
7815
|
+
}
|
|
7816
|
+
|
|
7674
7817
|
/**
|
|
7675
7818
|
* Registers an event listener on the specified element.
|
|
7676
7819
|
*
|
|
7677
7820
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
|
|
7678
7821
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
7679
|
-
* @param {
|
|
7822
|
+
* @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
|
|
7680
7823
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
7681
7824
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7682
7825
|
*/
|
|
@@ -7698,7 +7841,7 @@ class TinyHtml_TinyHtml {
|
|
|
7698
7841
|
* Registers an event listener on the specified element.
|
|
7699
7842
|
*
|
|
7700
7843
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
7701
|
-
* @param {
|
|
7844
|
+
* @param {EventListenerOrEventListenerObject|null} handler - The callback function to run on event.
|
|
7702
7845
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
7703
7846
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7704
7847
|
*/
|
|
@@ -7711,17 +7854,17 @@ class TinyHtml_TinyHtml {
|
|
|
7711
7854
|
*
|
|
7712
7855
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target to listen on.
|
|
7713
7856
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
7714
|
-
* @param {
|
|
7857
|
+
* @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
|
|
7715
7858
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
7716
7859
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7717
7860
|
*/
|
|
7718
7861
|
static once(el, event, handler, options = {}) {
|
|
7719
7862
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
7720
7863
|
TinyHtml_TinyHtml._preEventTargetElems(el, 'once').forEach((elem) => {
|
|
7721
|
-
/** @type {
|
|
7864
|
+
/** @type {EventListenerOrEventListenerObject} */
|
|
7722
7865
|
const wrapped = (e) => {
|
|
7723
7866
|
TinyHtml_TinyHtml.off(elem, event, wrapped);
|
|
7724
|
-
handler(e);
|
|
7867
|
+
if (typeof handler === 'function') handler(e);
|
|
7725
7868
|
};
|
|
7726
7869
|
|
|
7727
7870
|
TinyHtml_TinyHtml.on(
|
|
@@ -7738,7 +7881,7 @@ class TinyHtml_TinyHtml {
|
|
|
7738
7881
|
* Registers an event listener that runs only once, then is removed.
|
|
7739
7882
|
*
|
|
7740
7883
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
7741
|
-
* @param {
|
|
7884
|
+
* @param {EventListenerOrEventListenerObject} handler - The callback function to run on event.
|
|
7742
7885
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
7743
7886
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7744
7887
|
*/
|
|
@@ -7751,7 +7894,7 @@ class TinyHtml_TinyHtml {
|
|
|
7751
7894
|
*
|
|
7752
7895
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
7753
7896
|
* @param {string} event - The event type.
|
|
7754
|
-
* @param {
|
|
7897
|
+
* @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
|
|
7755
7898
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
7756
7899
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7757
7900
|
*/
|
|
@@ -7773,7 +7916,7 @@ class TinyHtml_TinyHtml {
|
|
|
7773
7916
|
* Removes a specific event listener from an element.
|
|
7774
7917
|
*
|
|
7775
7918
|
* @param {string} event - The event type.
|
|
7776
|
-
* @param {
|
|
7919
|
+
* @param {EventListenerOrEventListenerObject|null} handler - The function originally bound to the event.
|
|
7777
7920
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
7778
7921
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7779
7922
|
*/
|
|
@@ -7816,7 +7959,7 @@ class TinyHtml_TinyHtml {
|
|
|
7816
7959
|
* Removes all event listeners of all types from the element.
|
|
7817
7960
|
*
|
|
7818
7961
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
7819
|
-
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
7962
|
+
* @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
|
|
7820
7963
|
* Optional filter function to selectively remove specific handlers.
|
|
7821
7964
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7822
7965
|
*/
|
|
@@ -7843,7 +7986,7 @@ class TinyHtml_TinyHtml {
|
|
|
7843
7986
|
/**
|
|
7844
7987
|
* Removes all event listeners of all types from the element.
|
|
7845
7988
|
*
|
|
7846
|
-
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
7989
|
+
* @param {((handler: EventListenerOrEventListenerObject|null, event: string) => boolean)|null} [filterFn=null] -
|
|
7847
7990
|
* Optional filter function to selectively remove specific handlers.
|
|
7848
7991
|
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7849
7992
|
*/
|