Skip to content

Commit

Permalink
Improve JSDoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Oct 29, 2023
1 parent 35a594b commit 9d338d3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
28 changes: 14 additions & 14 deletions package/src/tooltips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export type ShowTooltip = (preferPlacingAboveCursor?: boolean) => void
export type HideTooltip = () => void

/**
* Utility making it easy to add tolltips to an editor. In order to
* use this, a the {@link cursorPosition} must be added to the editor.
* Utility making it easy to add tolltips to an editor. Before you can show the tooltip,
* a {@link cursorPosition} extension must be added to the editor.
* @param editor Editor you want to add the tooltip to.
* @param element Element for the tooltip.
* @param fixedWidth If false, the tooltip will shrink instead of getting offset to
Expand Down Expand Up @@ -60,18 +60,18 @@ export const addTooltip = (
]
}

const observer = window.ResizeObserver
? /* @__PURE__ */ new ResizeObserver(e =>
e.forEach(entry => {
const el = entry.target
const wrapper = el.querySelector<HTMLDivElement>(".pce-wrapper")!
const style = getComputedStyle(wrapper)
wrapper.style.paddingBottom = `${
el.clientHeight - parseFloat(style.marginBottom) - parseFloat(style.lineHeight)
}px`
}),
)
: null
const observer =
window.ResizeObserver &&
/* @__PURE__ */ new ResizeObserver(e =>
e.forEach(entry => {
const el = entry.target
const wrapper = el.querySelector<HTMLDivElement>(".pce-wrapper")!
const style = getComputedStyle(wrapper)
wrapper.style.paddingBottom = `${
el.clientHeight - parseFloat(style.marginBottom) - parseFloat(style.lineHeight)
}px`
}),
)

/** Allows users to scroll past the last line in the editor by adding padding to the wrapper. */
export const addOverscroll = (editor: PrismEditor) => {
Expand Down
12 changes: 7 additions & 5 deletions package/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ export interface EventHandler<EventMap extends Record<string, (...args: any) =>
}

export interface PrismEditor extends EventHandler<EditorEventMap> {
/** Scroll container for the editor. */
/** This is the outermost element of the editor. */
readonly scrollContainer: HTMLDivElement
/** Element wrapping the lines and overlays. */
readonly wrapper: HTMLDivElement
/** Element containing the overlays. */
/**
* Element containing overlays that are absolutely positioned ontop or underneath the code.
* It is completely safe to append your own overlays to this element, but they will get
* some default styles.
*/
readonly overlays: HTMLDivElement
/** Underlying `<textarea>` in the editor. */
readonly textarea: HTMLTextAreaElement
Expand Down Expand Up @@ -137,9 +141,7 @@ export interface PrismEditor extends EventHandler<EditorEventMap> {
codeFold?: ReadOnlyCodeFolding
}
/**
* Set new options for the editor.
* Ommitted properties will use their previous value.
* Passing `undefined` to a property returns it to its default value.
* Set new options for the editor. Ommitted properties will use their previous value.
* @param options New options for the editor
*/
setOptions(options: Partial<EditorOptions>): void
Expand Down
6 changes: 3 additions & 3 deletions package/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getLines = (text: string, start: number, end: number) =>
] as const

/**
* Searches a full line for a token that matches a selector and includes selectionStart
* Searches a full line for a token that matches a selector and contains `position`
* within the specified margins. Tokens are searched in reverse document order which means
* children are searched before their parents.
* @param editor Editor you want to search in.
Expand Down Expand Up @@ -79,8 +79,8 @@ const getLanguage = (editor: PrismEditor, position?: number) =>
* Focuses the `textarea` if it isn't already.
* @param editor Target editor.
* @param text Text to insert.
* @param start Index to start the insertion. Defaults to `selectionStart`.
* @param end Index to end the insertion. Defaults to `start` if specified, else `selectionEnd`.
* @param start Position to start the insertion. Defaults to `selectionStart`.
* @param end Position to end the insertion. Defaults to `start` if specified, else `selectionEnd`.
* @param newCursorStart New starting position for the cursor. Defaults to the end of the inserted text.
* @param newCursorEnd New ending position for the cursor. Defaults to `newCursorStart`.
*/
Expand Down
8 changes: 4 additions & 4 deletions package/src/webComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,25 @@ export interface PrismEditorElement extends HTMLElement {
}

/**
* Adds a custom element wrapping the editor with no extensions.
* Adds a custom element wrapping the {@link minimalEditor} setup.
* @param name Name of the custom element. Must be a valid custom element name.
*/
export const addMinimalEditor = (name: string) =>
addComponent(name, minimalEditor)
/**
* Adds a custom element wrapping the editor with indent guides and selection match highlighting.
* Adds a custom element wrapping the {@link basicEditor} setup.
* @param name Name of the custom element. Must be a valid custom element name.
*/
export const addBasicEditor = (name: string) =>
addComponent(name, basicEditor)
/**
* Adds a custom element wrapping the editor with all extensions.
* Adds a custom element wrapping the {@link fullEditor} setup.
* @param name Name of the custom element. Must be a valid custom element name.
*/
export const addFullEditor = (name: string) =>
addComponent(name, fullEditor)
/**
* Adds a custom element wrapping the editor with all extensions.
* Adds a custom element wrapping the {@link readonlyEditor} setup.
* @param name Name of the custom element. Must be a valid custom element name.
*/
export const addReadonlyEditor = (name: string) =>
Expand Down

0 comments on commit 9d338d3

Please sign in to comment.