diff --git a/src/dom.ts b/src/dom.ts index 672a0033..87271fef 100644 --- a/src/dom.ts +++ b/src/dom.ts @@ -1,5 +1,8 @@ import { refKey } from "./utils"; +/** + * @internal + */ export const isSafari = (): boolean => { const ua = navigator.userAgent.toLowerCase(); return ua.indexOf("safari") > -1 && ua.indexOf("chrome") <= -1; @@ -68,14 +71,23 @@ const getValueFromStyle = (style: CSSStyleDeclaration, key: string): number => { } }; +/** + * @internal + */ export const getStyle = (e: Element) => getComputedStyle(e); +/** + * @internal + */ export const hasPercentageUnit = ( widthOrHeight: React.CSSProperties["width"] | React.CSSProperties["height"] ): boolean => { return typeof widthOrHeight === "string" && widthOrHeight.endsWith("%"); }; +/** + * @internal + */ export const getVerticalPadding = (style: CSSStyleDeclaration): number => { return ( getValueFromStyle(style, "padding-top") + @@ -85,6 +97,9 @@ export const getVerticalPadding = (style: CSSStyleDeclaration): number => { ); }; +/** + * @internal + */ export const getHorizontalPadding = (style: CSSStyleDeclaration): number => { return ( getValueFromStyle(style, "padding-left") + @@ -94,6 +109,9 @@ export const getHorizontalPadding = (style: CSSStyleDeclaration): number => { ); }; +/** + * @internal + */ export const getPointedElement = ( textarea: HTMLElement, backdrop: HTMLElement, @@ -136,6 +154,9 @@ const dispatchMouseEvent = ( target.dispatchEvent(new MouseEvent(type, init)); }; +/** + * @internal + */ export const dispatchClonedMouseEvent = ( pointed: HTMLElement, e: MouseEvent @@ -143,6 +164,9 @@ export const dispatchClonedMouseEvent = ( dispatchMouseEvent(pointed, e.type, e); }; +/** + * @internal + */ export const dispatchMouseMoveEvent = ( pointed: HTMLElement | null, prevPointed: HTMLElement | null, @@ -160,6 +184,9 @@ export const dispatchMouseMoveEvent = ( } }; +/** + * @internal + */ export const dispatchMouseOutEvent = ( prevPointed: HTMLElement | null, e: MouseEvent @@ -169,10 +196,16 @@ export const dispatchMouseOutEvent = ( } }; +/** + * @internal + */ export const stopPropagation = (event: React.MouseEvent) => { event.stopPropagation(); }; +/** + * @internal + */ export const syncBackdropStyle = ( textarea: HTMLElement, backdrop: HTMLElement, @@ -193,9 +226,12 @@ export const syncBackdropStyle = ( textareaStyle.caretColor = style?.caretColor || caretColorRef[refKey]; }; +/** + * @internal + */ export const listenEvent = < E extends HTMLElement | Document, - K extends keyof GlobalEventHandlersEventMap + K extends keyof GlobalEventHandlersEventMap, >( el: E, key: K, diff --git a/src/observer.ts b/src/observer.ts index c0a04071..0af23fc0 100644 --- a/src/observer.ts +++ b/src/observer.ts @@ -10,13 +10,19 @@ import { } from "./dom"; import { SelectionStore } from "./selection"; +/** + * @internal + */ export type TextareaRect = [ width: number, height: number, hPadding: number, - vPadding: number + vPadding: number, ]; +/** + * @internal + */ export const createTextareaObserver = ( textarea: HTMLTextAreaElement | HTMLInputElement, backdrop: HTMLDivElement, diff --git a/src/regex.ts b/src/regex.ts index 51485a59..bcb644d6 100644 --- a/src/regex.ts +++ b/src/regex.ts @@ -1,3 +1,6 @@ +/** + * @internal + */ export const execReg = (reg: RegExp, text: string): RegExpExecArray[] => { const results: RegExpExecArray[] = []; let match: RegExpExecArray | null = null; diff --git a/src/selection.ts b/src/selection.ts index 64ece6b4..f860a250 100644 --- a/src/selection.ts +++ b/src/selection.ts @@ -1,7 +1,13 @@ import { refKey } from "./utils"; +/** + * @internal + */ export type SelectionRange = [number | null, number | null]; +/** + * @internal + */ export const initSelectionStore = ( ref: React.RefObject, onSelectionUpdate: (range: SelectionRange) => void @@ -49,4 +55,7 @@ export const initSelectionStore = ( return handle; }; +/** + * @internal + */ export type SelectionStore = ReturnType; diff --git a/src/useIsomorphicLayoutEffect.ts b/src/useIsomorphicLayoutEffect.ts index 4985c224..8090025b 100644 --- a/src/useIsomorphicLayoutEffect.ts +++ b/src/useIsomorphicLayoutEffect.ts @@ -1,5 +1,8 @@ import { useEffect, useLayoutEffect } from "react"; -// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85 +/** + * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85 + * @internal + */ export const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect; diff --git a/src/useStatic.ts b/src/useStatic.ts index 3cdc18b3..c8433918 100644 --- a/src/useStatic.ts +++ b/src/useStatic.ts @@ -1,6 +1,9 @@ import { useRef } from "react"; import { refKey } from "./utils"; +/** + * @internal + */ export const useStatic = (init: () => T): T => { const ref = useRef(); return ref[refKey] || (ref[refKey] = init()); diff --git a/src/utils.tsx b/src/utils.tsx index 69790dde..72fa02e6 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -1,6 +1,12 @@ +/** + * @internal + */ export const refKey = "current"; -// for caret position detection +/** + * for caret position detection + * @internal + */ export const CARET_DETECTOR = ( {"\u200b"} ); diff --git a/tsconfig.json b/tsconfig.json index d7673df1..20920d15 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,7 +22,8 @@ "noFallthroughCasesInSwitch": true, "allowUnreachableCode": false, "allowUnusedLabels": false, - "exactOptionalPropertyTypes": true + "exactOptionalPropertyTypes": true, + "stripInternal": true }, "include": ["src"], "exclude": ["node_modules"]