Skip to content

Commit

Permalink
fixed build
Browse files Browse the repository at this point in the history
- added generate docs script
  • Loading branch information
e11sy committed Aug 16, 2024
1 parent ba0f88a commit 2486a63
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 112 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
"build:caret": "cd packages/caret && yarn build",
"build:keyboard": "cd packages/keyboard && yarn build",
"lint": "eslint",
"lint:fix": "yarn lint --fix"
"lint:fix": "yarn lint --fix",
"generate-docs": "ts-node scripts/generateReadme.ts"
},
"devDependencies": {
"@types/fs-extra": "^11",
"@types/node": "^20.10.7",
"eslint": "^9.0.0",
"eslint-config-codex": "^2.0.0",
"fs-extra": "^11.2.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.9.0"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/caret/README.md
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>
27 changes: 27 additions & 0 deletions packages/dom/README.md
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
2 changes: 1 addition & 1 deletion packages/dom/src/canSetCaret.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNativeInput } from './findAllInputs';
import { isNativeInput } from './isNativeInput';
import { isContentEditable } from './isContentEditable';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dom/src/getContentLength.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNativeInput } from './findAllInputs';
import { isNativeInput } from './isNativeInput';

/**
* Return length of node`s text content
Expand Down
5 changes: 3 additions & 2 deletions packages/dom/src/getDeepestNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isNativeInput } from './findAllInputs';
import { isLineBreakTag, isSingleTag } from './isLineBreakTag';
import { isNativeInput } from './isNativeInput';
import { isLineBreakTag } from './isLineBreakTag';
import { isSingleTag } from './isSingleTag';

/**
* Search for deepest node which is Leaf.
Expand Down
5 changes: 3 additions & 2 deletions packages/dom/src/isNodeEmpty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isSingleTag, isLineBreakTag } from './isLineBreakTag';
import { isLineBreakTag } from './isLineBreakTag';
import { isElement } from './isElement';
import { isNativeInput } from './findAllInputs';
import { isNativeInput } from './isNativeInput';
import { isSingleTag } from './isSingleTag';

/**
* Checks node if it is empty
Expand Down
25 changes: 25 additions & 0 deletions packages/helpers/README.md
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
3 changes: 3 additions & 0 deletions packages/keyboard/README.md
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.
101 changes: 101 additions & 0 deletions packages/keyboard/src/getKeyboardKeyForCode.ts
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;
}
}
102 changes: 2 additions & 100 deletions packages/keyboard/src/index.ts
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 };
Loading

0 comments on commit 2486a63

Please sign in to comment.