generated from codex-team/typescript-lib-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added generate docs script
- Loading branch information
Showing
16 changed files
with
517 additions
and
112 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# caret | ||
|
||
- [checkContenteditableSliceForEmptiness](https://github.com/editor-js/utils/blob/main/packages/caret/src/checkContenteditableSliceForEmptiness.ts) - Checks content at left or right of the passed node for emptiness. | ||
- [extractContenteditableSlice](https://github.com/editor-js/utils/blob/main/packages/caret/src/extractContenteditableSlice.ts) - Returns slice of the contenteditable html element from caret position to the start or end (depending on direction) | ||
- [focus](https://github.com/editor-js/utils/blob/main/packages/caret/src/focus.ts) - Set focus to contenteditable or native input element | ||
- [getCaretNodeAndOffset](https://github.com/editor-js/utils/blob/main/packages/caret/src/getCaretNodeAndOffset.ts) - Returns TextNode containing a caret and a caret offset in it | ||
- [getRange](https://github.com/editor-js/utils/blob/main/packages/caret/src/getRange.ts) - Returns the first range | ||
- [isCaretAtEndOfInput](https://github.com/editor-js/utils/blob/main/packages/caret/src/isCaretAtEndOfInput.ts) - Checks if caret is at the end of the passed input | ||
- [isCaretAtStartOfInput](https://github.com/editor-js/utils/blob/main/packages/caret/src/isCaretAtStartOfInput.ts) - Checks if caret is at the start of the passed input | ||
- [save](https://github.com/editor-js/utils/blob/main/packages/caret/src/save.ts) - Saves caret position using hidden <span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# dom | ||
|
||
- [allInputsSelector](https://github.com/editor-js/utils/blob/main/packages/dom/src/allInputsSelector.ts) - Returns CSS selector for all text inputs | ||
- [append](https://github.com/editor-js/utils/blob/main/packages/dom/src/append.ts) - Append one or several elements to the parent | ||
- [blockElements](https://github.com/editor-js/utils/blob/main/packages/dom/src/blockElements.ts) - Return array of names of block html elements | ||
- [calculateBaseline](https://github.com/editor-js/utils/blob/main/packages/dom/src/calculateBaseline.ts) - Calculates the Y coordinate of the text baseline from the top of the element's margin box, | ||
- [canSetCaret](https://github.com/editor-js/utils/blob/main/packages/dom/src/canSetCaret.ts) - Checks if we can set caret | ||
- [containsOnlyInlineElements](https://github.com/editor-js/utils/blob/main/packages/dom/src/containsOnlyInlineElements.ts) - Check if passed content includes only inline elements | ||
- [findAllInputs](https://github.com/editor-js/utils/blob/main/packages/dom/src/findAllInputs.ts) - Find all contenteditable, textarea and editable input elements passed holder contains | ||
- [fragmentToString](https://github.com/editor-js/utils/blob/main/packages/dom/src/fragmentToString.ts) - Returns the HTML content of passed Document Fragment | ||
- [getContentLength](https://github.com/editor-js/utils/blob/main/packages/dom/src/getContentLength.ts) - Return length of node`s text content | ||
- [getDeepestBlockElements](https://github.com/editor-js/utils/blob/main/packages/dom/src/getDeepestBlockElements.ts) - Find and return all block elements in the passed parent (including subtree) | ||
- [getDeepestNode](https://github.com/editor-js/utils/blob/main/packages/dom/src/getDeepestNode.ts) - Search for deepest node which is Leaf. | ||
- [isCollapsedWhitespaces](https://github.com/editor-js/utils/blob/main/packages/dom/src/isCollapsedWhitespaces.ts) - Determine whether a passed text content is a collapsed whitespace. | ||
- [isContentEditable](https://github.com/editor-js/utils/blob/main/packages/dom/src/isContentEditable.ts) - Check if passed element is contenteditable | ||
- [isElement](https://github.com/editor-js/utils/blob/main/packages/dom/src/isElement.ts) - Check if object is DOM node | ||
- [isEmpty](https://github.com/editor-js/utils/blob/main/packages/dom/src/isEmpty.ts) - breadth-first search (BFS) | ||
- [isFragment](https://github.com/editor-js/utils/blob/main/packages/dom/src/isFragment.ts) - Check if object is DocumentFragment node | ||
- [isHTMLString](https://github.com/editor-js/utils/blob/main/packages/dom/src/isHtmlString.ts) - Check if string contains html elements | ||
- [isLeaf](https://github.com/editor-js/utils/blob/main/packages/dom/src/isLeaf.ts) - checks node if it is doesn't have any child nodes | ||
- [isLineBreakTag](https://github.com/editor-js/utils/blob/main/packages/dom/src/isLineBreakTag.ts) - Check if element is BR or WBR | ||
- [isNativeInput](https://github.com/editor-js/utils/blob/main/packages/dom/src/isNativeInput.ts) - Checks target if it is native input | ||
- [isNodeEmpty](https://github.com/editor-js/utils/blob/main/packages/dom/src/isNodeEmpty.ts) - Checks node if it is empty | ||
- [isSingleTag](https://github.com/editor-js/utils/blob/main/packages/dom/src/isSingleTag.ts) - Check if passed tag has no closed tag | ||
- [make](https://github.com/editor-js/utils/blob/main/packages/dom/src/make.ts) - Helper for making Elements with class name and attributes | ||
- [offset](https://github.com/editor-js/utils/blob/main/packages/dom/src/offset.ts) - Return element's offset related to the document | ||
- [prepend](https://github.com/editor-js/utils/blob/main/packages/dom/src/prepend.ts) - Append element or a couple to the beginning of the parent elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# helpers | ||
|
||
- [beautifyShortcut](https://github.com/editor-js/utils/blob/main/packages/helpers/src/beautifyShortcut.ts) - Make shortcut command more human-readable | ||
- [cacheable](https://github.com/editor-js/utils/blob/main/packages/helpers/src/cacheable.ts) - Decorator which provides ability to cache method or accessor result | ||
- [capitalize](https://github.com/editor-js/utils/blob/main/packages/helpers/src/capitalize.ts) - Capitalizes first letter of the string | ||
- [copyTextToClipboard](https://github.com/editor-js/utils/blob/main/packages/helpers/src/copyTextToClipboard.ts) - Copies passed text to the clipboard | ||
- [debounce](https://github.com/editor-js/utils/blob/main/packages/helpers/src/debounce.ts) - Debouncing method | ||
- [deepMerge](https://github.com/editor-js/utils/blob/main/packages/helpers/src/deepMerge.ts) - Merge two objects recursively | ||
- [deprecationAssert](https://github.com/editor-js/utils/blob/main/packages/helpers/src/deprecationAssert.ts) - Common method for printing a warning about the usage of deprecated property or method. | ||
- [notEmpty](https://github.com/editor-js/utils/blob/main/packages/helpers/src/empty.ts) - True if passed variable is not null/undefined/''/{} | ||
- [isEmpty](https://github.com/editor-js/utils/blob/main/packages/helpers/src/empty.ts) - True if passed variable is null/undefined/''/{} | ||
- [getValidUrl](https://github.com/editor-js/utils/blob/main/packages/helpers/src/getValidUrl.ts) - Returns valid URL. If it is going outside and valid, it returns itself | ||
- [isPrintableKey](https://github.com/editor-js/utils/blob/main/packages/helpers/src/isPrintableKey.ts) - Returns true if passed key code is printable (a-Z, 0-9, etc) character. | ||
- [throttle](https://github.com/editor-js/utils/blob/main/packages/helpers/src/throttle.ts) - Returns a function, that, when invoked, will only be triggered at most once during a given window of time. | ||
- [typeOf](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Return string representation of the object type | ||
- [isFunction](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Check if passed variable is a function | ||
- [isObject](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Checks if passed argument is an object | ||
- [isString](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Checks if passed argument is a string | ||
- [isBoolean](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Checks if passed argument is boolean | ||
- [isNumber](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Checks if passed argument is number | ||
- [isUndefined](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Checks if passed argument is undefined | ||
- [isClass](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Check if passed function is a class | ||
- [isPromise](https://github.com/editor-js/utils/blob/main/packages/helpers/src/typeOf.ts) - Check if passed object is a Promise | ||
- [getUserOS](https://github.com/editor-js/utils/blob/main/packages/helpers/src/userOS.ts) - Returns object with os name as key and boolean as value. Shows current user OS | ||
- [equals](https://github.com/editor-js/utils/blob/main/packages/helpers/src/userOS.ts) - Compares two values with unknown type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# keyboard | ||
|
||
- [getKeyboardKeyForCode](https://github.com/editor-js/utils/blob/main/packages/keyboard/src/getKeyboardKeyForCode.ts) - Returns real layout-related keyboard key for a given key code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
declare global { | ||
/** | ||
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardLayoutMap | ||
*/ | ||
interface KeyboardLayoutMap { | ||
/** | ||
* Returns the element with the given key from the KeyboardLayoutMap object. | ||
* @param key - key which is used for getting keyboard layout map | ||
*/ | ||
get(key: string): string | undefined; | ||
|
||
/** | ||
* method of the KeyboardLayoutMap interface returns a boolean indicating | ||
* whether the object has an element with the specified key | ||
* @param key - key which is used for gettings element | ||
*/ | ||
has(key: string): boolean; | ||
|
||
/** | ||
* The size read-only property of the KeyboardLayoutMap interface returns the number of elements in the map | ||
*/ | ||
size: number; | ||
|
||
/** | ||
* Method of the KeyboardLayoutMap interface returns a new Iterator object | ||
* that contains the key/value pairs, in the same order as that provided by a for...in loop | ||
* (the difference being that a for-in loop enumerates properties in the prototype chain as well) | ||
*/ | ||
entries(): IterableIterator<[string, string]>; | ||
|
||
/** | ||
* method of the KeyboardLayoutMap interface returns a new Iterator object | ||
* that contains the keys for each index in the KeyboardLayoutMap object | ||
*/ | ||
keys(): IterableIterator<string>; | ||
|
||
/** | ||
* method of the KeyboardLayoutMap interface returns a new Iterator object | ||
* that contains the values for each index in the KeyboardLayoutMap object | ||
*/ | ||
values(): IterableIterator<string>; | ||
|
||
/** | ||
* Executes a provided function once for each element of KeyboardLayoutMap. | ||
* @param callbackfn | ||
* @param thisArg | ||
*/ | ||
forEach(callbackfn: (value: string, key: string, map: KeyboardLayoutMap) => void, thisArg?: unknown): void; | ||
} | ||
|
||
/** | ||
* The getLayoutMap() method of the Keyboard interface returns a Promise | ||
* that resolves with an instance of KeyboardLayoutMap which is a map-like object | ||
* with functions for retrieving the strings associated with specific physical keys. | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/getLayoutMap | ||
*/ | ||
interface Keyboard { | ||
/** | ||
* Method that returns keyboard layout map with functoins | ||
*/ | ||
getLayoutMap(): Promise<KeyboardLayoutMap>; | ||
} | ||
/** | ||
* Navigator interface | ||
*/ | ||
interface Navigator { | ||
/** | ||
* Keyboard API. Not supported by Firefox and Safari. | ||
*/ | ||
keyboard?: Keyboard; | ||
} | ||
} | ||
|
||
/** | ||
* Returns real layout-related keyboard key for a given key code. | ||
* For example, for "Slash" it will return "/" on US keyboard and "-" on Spanish keyboard. | ||
* | ||
* Works with Keyboard API which is not supported by Firefox and Safari. So fallback is used for these browsers. | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Keyboard | ||
* @param code - {@link https://www.w3.org/TR/uievents-code/#key-alphanumeric-writing-system} | ||
* @param fallback - fallback value to be returned if Keyboard API is not supported (Safari, Firefox) | ||
*/ | ||
export async function getKeyboardKeyForCode(code: string, fallback: string): Promise<string> { | ||
const keyboard = navigator.keyboard; | ||
|
||
if (keyboard === null) { | ||
return fallback; | ||
} | ||
|
||
try { | ||
const map = await keyboard.getLayoutMap(); | ||
|
||
const key = map.get(code); | ||
|
||
return key ?? fallback; | ||
} catch (e) { | ||
console.error(e); | ||
|
||
return fallback; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,3 @@ | ||
declare global { | ||
/** | ||
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardLayoutMap | ||
*/ | ||
interface KeyboardLayoutMap { | ||
/** | ||
* Returns the element with the given key from the KeyboardLayoutMap object. | ||
* @param key - key which is used for getting keyboard layout map | ||
*/ | ||
get(key: string): string | undefined; | ||
import { getKeyboardKeyForCode } from './getKeyboardKeyForCode'; | ||
|
||
/** | ||
* method of the KeyboardLayoutMap interface returns a boolean indicating | ||
* whether the object has an element with the specified key | ||
* @param key - key which is used for gettings element | ||
*/ | ||
has(key: string): boolean; | ||
|
||
/** | ||
* The size read-only property of the KeyboardLayoutMap interface returns the number of elements in the map | ||
*/ | ||
size: number; | ||
|
||
/** | ||
* Method of the KeyboardLayoutMap interface returns a new Iterator object | ||
* that contains the key/value pairs, in the same order as that provided by a for...in loop | ||
* (the difference being that a for-in loop enumerates properties in the prototype chain as well) | ||
*/ | ||
entries(): IterableIterator<[string, string]>; | ||
|
||
/** | ||
* method of the KeyboardLayoutMap interface returns a new Iterator object | ||
* that contains the keys for each index in the KeyboardLayoutMap object | ||
*/ | ||
keys(): IterableIterator<string>; | ||
|
||
/** | ||
* method of the KeyboardLayoutMap interface returns a new Iterator object | ||
* that contains the values for each index in the KeyboardLayoutMap object | ||
*/ | ||
values(): IterableIterator<string>; | ||
|
||
/** | ||
* Executes a provided function once for each element of KeyboardLayoutMap. | ||
* @param callbackfn | ||
* @param thisArg | ||
*/ | ||
forEach(callbackfn: (value: string, key: string, map: KeyboardLayoutMap) => void, thisArg?: unknown): void; | ||
} | ||
|
||
/** | ||
* The getLayoutMap() method of the Keyboard interface returns a Promise | ||
* that resolves with an instance of KeyboardLayoutMap which is a map-like object | ||
* with functions for retrieving the strings associated with specific physical keys. | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/getLayoutMap | ||
*/ | ||
interface Keyboard { | ||
/** | ||
* Method that returns keyboard layout map with functoins | ||
*/ | ||
getLayoutMap(): Promise<KeyboardLayoutMap>; | ||
} | ||
/** | ||
* Navigator interface | ||
*/ | ||
interface Navigator { | ||
/** | ||
* Keyboard API. Not supported by Firefox and Safari. | ||
*/ | ||
keyboard?: Keyboard; | ||
} | ||
} | ||
|
||
/** | ||
* Returns real layout-related keyboard key for a given key code. | ||
* For example, for "Slash" it will return "/" on US keyboard and "-" on Spanish keyboard. | ||
* | ||
* Works with Keyboard API which is not supported by Firefox and Safari. So fallback is used for these browsers. | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Keyboard | ||
* @param code - {@link https://www.w3.org/TR/uievents-code/#key-alphanumeric-writing-system} | ||
* @param fallback - fallback value to be returned if Keyboard API is not supported (Safari, Firefox) | ||
*/ | ||
export async function getKeyboardKeyForCode(code: string, fallback: string): Promise<string> { | ||
const keyboard = navigator.keyboard; | ||
|
||
if (keyboard === null) { | ||
return fallback; | ||
} | ||
|
||
try { | ||
const map = await keyboard.getLayoutMap(); | ||
|
||
const key = map.get(code); | ||
|
||
return key ?? fallback; | ||
} catch (e) { | ||
console.error(e); | ||
|
||
return fallback; | ||
} | ||
} | ||
export { getKeyboardKeyForCode }; |
Oops, something went wrong.