Back to reference

EditorSDK

Overall API for the Editor SDK which can be used to create Editors, which represent HTML editors enhanced with Grammarly.

declare class EditorSDK {
  addPlugin(element: HTMLElement, config?: EditorConfig, viewport?: HTMLElement): GrammarlyEditorPluginElement;
  handleOAuthCallback(url: string): Promise<void>;
  withElement(element: HTMLElement, config?: EditorConfig, viewport?: HTMLElement): Editor;
  withQuerySelector(selectors: string, config?: EditorConfig): void;
}

Examples

const Grammarly = await init("YOUR_CLIENT_ID");
const plugin = Grammarly.addPlugin(document.querySelector("textarea"));

Methods

addPlugin()

Enhance a specific HTML element with Grammarly.

addPlugin(element: HTMLElement, config?: EditorConfig, viewport?: HTMLElement): GrammarlyEditorPluginElement;

Parameters

NameTypeDescription
elementHTMLElementElement to be enhanced
configEditorConfigOptional EditorConfig
viewportHTMLElementParent scrolling element, if different from editor element (since 1.6.7)

handleOAuthCallback()

Process OAuth callback and complete account connection.

handleOAuthCallback(url: string): Promise<void>;

Parameters

NameTypeDescription
urlstring

withElement() deprecated

Enhance a specific HTML element with Grammarly.

Deprecated: since v1.9.0 - renamed to EditorSDKaddPlugin

withElement(element: HTMLElement, config?: EditorConfig, viewport?: HTMLElement): Editor;

Parameters

NameTypeDescription
elementHTMLElementElement to be enhanced
configEditorConfigOptional EditorConfig
viewportHTMLElementParent scrolling element, if different from editor element (since 1.6.7)

withQuerySelector() deprecated

Enhance all elements that match provided selectors with Grammarly.

Deprecated: since v1.9.0 - use document.querySelectorAll(selector).forEach(el => Grammarly.addPlugin(el, config))

withQuerySelector(selectors: string, config?: EditorConfig): void;

Parameters

NameTypeDescription
selectorsstringSelectors as provided to querySelectorAllopen in new window
configEditorConfigOptional EditorConfig
Last Updated: 4/12/2023, 3:24:55 PM