@grammarly/editor-sdk
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -23,3 +23,2 @@ /** | ||
import { RawAlert, AbsRawTransform, CAPI } from '@grammarly/core-clients'; | ||
import { Emotion } from '@grammarly/core-clients/esm/capi/emotions'; | ||
@@ -45,24 +44,3 @@ /** | ||
/** | ||
* Type of alert used to decide color in UI (eg underlines) | ||
*/ | ||
declare const enum AlertDisplayType { | ||
critical = "critical", | ||
advanced = "advanced", | ||
clarity = "clarity", | ||
engagement = "engagement", | ||
tone = "tone", | ||
originality = "originality", | ||
vox = "vox" | ||
} | ||
declare type Alert = RawAlert.WithPosition & { | ||
displayType: AlertDisplayType; | ||
sortOrder: number; | ||
priority: number; | ||
transformJson?: AbsRawTransform; | ||
}; | ||
/** | ||
* @internal | ||
@@ -176,2 +154,42 @@ */ | ||
/** | ||
* | ||
* @packageDocumentation | ||
* @license | ||
* (c) Copyright 2021 Grammarly, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* Type of alert used to decide color in UI (eg underlines) | ||
*/ | ||
declare const enum AlertDisplayType { | ||
critical = "critical", | ||
advanced = "advanced", | ||
clarity = "clarity", | ||
engagement = "engagement", | ||
tone = "tone", | ||
originality = "originality", | ||
vox = "vox" | ||
} | ||
declare type Alert = RawAlert.WithPosition & { | ||
displayType: AlertDisplayType; | ||
sortOrder: number; | ||
priority: number; | ||
transformJson?: AbsRawTransform; | ||
}; | ||
declare type TextEncoderEvents = { | ||
@@ -675,2 +693,57 @@ change: { | ||
/** | ||
* User settings and preferences. | ||
*/ | ||
declare type UserPreferences = { | ||
/** | ||
* Preferred dialect of English | ||
*/ | ||
dialect: string | null; | ||
/** | ||
* Is Grammarly SDK enabled? | ||
*/ | ||
isEnabled: boolean; | ||
/** | ||
* Should show tone detector? | ||
*/ | ||
showDetectedTone: boolean; | ||
/** | ||
* Should show highlights? | ||
*/ | ||
showUnderlines: boolean; | ||
/** | ||
* Has suggestion card intro already been shown? | ||
*/ | ||
shownCardIntro: boolean; | ||
/** | ||
* Container ID for gnar tracking events | ||
*/ | ||
gnarContainerId: string | null; | ||
/** | ||
* Number of times tone menu is shown | ||
*/ | ||
toneMenuCount: number; | ||
}; | ||
interface ConfigManagerOptions { | ||
window: EventTarget; | ||
sessionStorage: Storage; | ||
localStorage: Storage; | ||
} | ||
declare class PreferencesManager implements Manager<UserPreferences>, Disposable { | ||
private readonly _scope; | ||
private readonly _state; | ||
private readonly _options; | ||
private readonly _logger; | ||
constructor(options: ConfigManagerOptions); | ||
get state(): ReadonlyModel<UserPreferences>; | ||
setSiteState<P extends KeyOf<UserPreferences>>(property: P, value?: UserPreferences[P]): void; | ||
setSessionState<P extends KeyOf<UserPreferences>>(property: P, value?: UserPreferences[P]): void; | ||
private _updateState; | ||
private _read; | ||
private _readFrom; | ||
private _writeTo; | ||
dispose(): void; | ||
} | ||
interface AppClientInfo { | ||
@@ -686,7 +759,2 @@ /** @deprecated Use clientId (appId can be resolved from it) */ | ||
interface OAuthCallbackResponse { | ||
code: string; | ||
codeVerifier: string; | ||
} | ||
interface OAuthRequest { | ||
@@ -698,2 +766,7 @@ origin: string; | ||
interface OAuthCallbackResponse { | ||
code: string; | ||
codeVerifier: string; | ||
} | ||
declare type OAuthAuthorizationMode = "web_message" | "redirect_json"; | ||
@@ -713,3 +786,3 @@ | ||
declare type State = { | ||
declare type State$1$1 = { | ||
clientInfo: AppClientInfo | null; | ||
@@ -720,3 +793,10 @@ user: User$1 | null; | ||
}; | ||
declare class AuthManager implements Manager<State> { | ||
declare type Events$2 = { | ||
/** @deprecated */ | ||
userAccountStatusChange: null; | ||
/** @deprecated */ | ||
userTokenChange: null; | ||
reconnect: "account-connected" | "account-disconnected"; | ||
}; | ||
declare class AuthManager extends EventEmitter<Events$2> implements Manager<State$1$1> { | ||
private readonly _storage; | ||
@@ -729,2 +809,3 @@ private readonly _state; | ||
private readonly _clientId; | ||
private _redirectUri; | ||
/** | ||
@@ -735,3 +816,5 @@ * Resolves when AppInfo is available. | ||
constructor(clientId: string, storage: Storage); | ||
get state(): ReadonlyModel<State>; | ||
get state(): ReadonlyModel<State$1$1>; | ||
setRedirectUri(redirectUri: string): void; | ||
get redirectUri(): string; | ||
/** | ||
@@ -775,3 +858,3 @@ * @deprecated Use `createAccessToken()` | ||
*/ | ||
setActiveOAuthRequest(request: State["activeRequest"]): void; | ||
setActiveOAuthRequest(request: State$1$1["activeRequest"]): void; | ||
private _handleConnectedAccountStatusChange; | ||
@@ -783,20 +866,2 @@ private _onLoginSuccess; | ||
declare type Events = { | ||
userAccountStatusChange: null; | ||
userTokenChange: null; | ||
reconnect: null; | ||
}; | ||
/** | ||
* @deprecated Use `AuthManager` | ||
*/ | ||
declare class AuthService { | ||
private readonly events; | ||
manager: AuthManager; | ||
constructor({ clientId }: { | ||
clientId: string; | ||
}); | ||
addEventListener<E extends string & keyof Events>(event: E, listener: EventListener<Events[E]>): void; | ||
removeEventListener<E extends string & keyof Events>(event: E, listener: EventListener<Events[E]>): void; | ||
} | ||
declare type CAPIConnectionManagerEvents = { | ||
@@ -821,6 +886,6 @@ error: Error; | ||
private isPaused; | ||
private readonly authService; | ||
private readonly auth; | ||
private options; | ||
private context; | ||
constructor(authService: AuthService, options?: Pick<EditorConfig, "suggestions" | "document" | "onTextStats">); | ||
constructor(auth: AuthManager, options?: Pick<EditorConfig, "suggestions" | "document" | "onTextStats">); | ||
setConfig(options: Pick<EditorConfig, "suggestions" | "document" | "onTextStats">): Promise<void>; | ||
@@ -898,5 +963,5 @@ /** | ||
private readonly _logger; | ||
private readonly authService; | ||
private readonly _auth; | ||
private hasRequested; | ||
constructor(authService: AuthService); | ||
constructor(auth: AuthManager); | ||
shouldRequestUserFeedback(actionsObserved: number): boolean; | ||
@@ -916,8 +981,2 @@ submitFeedback(payload: FeedbackPayload): Promise<void>; | ||
interface EncodedText { | ||
delta: Delta; | ||
offsets: Array<[number, Text]>; | ||
inverseOffsets: Map<Text, number>; | ||
} | ||
/** | ||
@@ -943,5 +1002,7 @@ * | ||
declare type EditorElement$1 = HTMLInputElement | HTMLTextAreaElement | HTMLElement; | ||
declare type EditorElement = HTMLInputElement | HTMLTextAreaElement | HTMLElement; | ||
declare class EditorTextManager extends TextManager { | ||
declare class EditorTextManager extends TextManager implements Disposable { | ||
private _editor?; | ||
@@ -952,3 +1013,3 @@ private offsets; | ||
get editor(): EditorElement; | ||
connect(editor: EditorElement): void; | ||
connect(editor: EditorElement): Disposable; | ||
disconnect(): void; | ||
@@ -965,2 +1026,3 @@ setText(originalText: Delta | string, cursor?: number | CursorInfo): void; | ||
private _getTextMapping; | ||
dispose(): void; | ||
} | ||
@@ -1045,6 +1107,12 @@ | ||
declare type EditorKind = "plain" | "rich"; | ||
declare class HighlightManager extends EventEmitter<HighlightManagerEvents> { | ||
private _kind; | ||
interface State$1 { | ||
activeHighlightId: Alert["id"] | null; | ||
displayMode: "all" | "none" | "corrective"; | ||
kind: EditorKind | null; | ||
didRenderFullMode: boolean; | ||
} | ||
declare class HighlightManager extends EventEmitter<HighlightManagerEvents> implements Manager<State$1> { | ||
private readonly _logger; | ||
get kind(): EditorKind; | ||
private readonly _state; | ||
private readonly _cleanup; | ||
private readonly resizeObserver; | ||
@@ -1060,3 +1128,2 @@ private readonly hasViewportWidthChanged; | ||
protected readonly container: HighlightContainer; | ||
protected activeHighlightId?: Alert["id"]; | ||
/** Offset position in text, after which highlights needs rendering. */ | ||
@@ -1068,7 +1135,3 @@ protected dirtyAfterIndex: number; | ||
}; | ||
get editor(): EditorElement; | ||
get viewport(): HTMLElement; | ||
private originalSpellCheck; | ||
get text(): EncodedText; | ||
private _displayMode; | ||
get displayMode(): HighlightDisplayMode; | ||
@@ -1081,5 +1144,13 @@ /** | ||
constructor(textManager: EditorTextManager); | ||
get state(): ReadonlyModel<State$1>; | ||
private _isConnected; | ||
get isConnected(): boolean; | ||
/** | ||
* Mount highlights element to DOM | ||
* @param target | ||
*/ | ||
connect(target?: HTMLElement | null): void; | ||
/** | ||
* Unmount highlights element. | ||
*/ | ||
disconnect(): void; | ||
@@ -1106,2 +1177,4 @@ setViewport(viewport: HTMLElement): void; | ||
private _createRenderTask; | ||
private _getViewport; | ||
private _getViewportOrThrow; | ||
private _shouldDisplayAlert; | ||
@@ -1138,3 +1211,3 @@ private isRendering; | ||
*/ | ||
setActiveHighlight(highlightId?: RawAlert.Id): void; | ||
setActiveHighlight(highlightId?: RawAlert.Id | null): void; | ||
/** | ||
@@ -1151,135 +1224,19 @@ * Fire fake/custom mouse enter/leave event for highlight. | ||
private _getHighlightPosition; | ||
dispose(): void; | ||
} | ||
interface EditorManagerLike extends EventEmitter<EditorManagerEvents> { | ||
instanceId: number; | ||
authService: AuthService; | ||
editor: HTMLElement; | ||
pluginElement: HTMLElement; | ||
alerts: AlertManager; | ||
highlights: HighlightManager; | ||
interface State { | ||
editor: EditorElement$1 | null; | ||
viewport: EditorElement$1 | null; | ||
status: GrammarlyStatus; | ||
connection: CAPIConnectionManager; | ||
disablePlugin: (reason: PluginDisableReason) => void; | ||
showUnderlines: () => void; | ||
hideUnderlines: () => void; | ||
setConfig: (config: Partial<EditorConfig>) => void; | ||
config: EditorConfig; | ||
styleMode: "auto" | "none"; | ||
rootStyles: CSSStyleDeclaration | null; | ||
zIndex: number | null; | ||
} | ||
declare type EditorManagerEvents = { | ||
interface Events { | ||
connected: null; | ||
disconnected: null; | ||
status: GrammarlyStatus; | ||
}; | ||
declare type GButtonManagerEvents = { | ||
alertCount: number; | ||
status: GrammarlyStatus; | ||
open: boolean; | ||
}; | ||
declare class GButtonManager extends EventEmitter<GButtonManagerEvents> { | ||
private readonly managerState; | ||
private _lastLoggedGButtonShowEvent; | ||
private _status; | ||
private readonly _logger; | ||
private static primaryManager; | ||
private static instance?; | ||
static underlinesVisible: boolean; | ||
static getInstance(): GButtonManager; | ||
private constructor(); | ||
get status(): GrammarlyStatus; | ||
hasVisibleAlerts(): boolean; | ||
hasPrimary(): boolean; | ||
isPrimary(manager: EditorManagerLike): boolean; | ||
setPrimary(manager: EditorManagerLike): void; | ||
register(manager: EditorManagerLike): void; | ||
deregister(manager: EditorManagerLike): void; | ||
private _syncManagers; | ||
private _handleStatusChange; | ||
private _publishAlertChanges; | ||
disablePlugin(reason: PluginDisableReason): void; | ||
openGrammarlyButton(): void; | ||
setDialect(dialect: Dialect): void; | ||
updateShowUnderlines(visible: boolean): void; | ||
private _getPageOrderAlerts; | ||
private _scrollToHighlight; | ||
showFirstHighlight(): void; | ||
} | ||
declare type ToneManagerEvents = { | ||
change: { | ||
emotions: Emotion[]; | ||
}; | ||
}; | ||
interface ToneManagerState { | ||
emotions: Emotion[]; | ||
cleanup: () => void; | ||
} | ||
declare class ToneManager extends EventEmitter<ToneManagerEvents> { | ||
private readonly managerState; | ||
private currentState; | ||
private static primaryManager; | ||
private static instance?; | ||
static getInstance(): ToneManager; | ||
private constructor(); | ||
private readonly _logger; | ||
get emotions(): ToneManagerState["emotions"]; | ||
hasPrimary(): boolean; | ||
isPrimary(manager: EditorManagerLike): boolean; | ||
setPrimary(manager: EditorManagerLike): void; | ||
private _emotionsChanged; | ||
register(manager: EditorManagerLike): void; | ||
private _handleFocus; | ||
private _isInsidePlugin; | ||
handleBlur(event: FocusEvent): void; | ||
private _reset; | ||
private _publishCurrent; | ||
deregister(manager: EditorManagerLike): void; | ||
} | ||
declare type ExtensionEvents = { | ||
status: { | ||
detected: boolean; | ||
}; | ||
}; | ||
declare class ExtensionManager extends EventEmitter<ExtensionEvents> { | ||
private readonly extensionLoadedWorker; | ||
private readonly attrObserver; | ||
private readonly elementObserver; | ||
private readonly integrationElementObserver; | ||
private static instance?; | ||
static getInstance(): ExtensionManager; | ||
private constructor(); | ||
private readonly _logger; | ||
connect(): void; | ||
disconnect(): void; | ||
private readonly references; | ||
private isActive; | ||
register(reference: any): void; | ||
deregister(reference: any): void; | ||
private _checkForEnabledGrammarlyExtension; | ||
private _checkIntegrationElementMutations; | ||
private _checkElementMutations; | ||
private _checkAttributeMutations; | ||
private readonly publishStatus; | ||
} | ||
/** | ||
* Coordination with Llama aka Grammarly Desktop | ||
* | ||
* @remarks | ||
* Llama is restricted to only reading ids and CSS classes, so we use CSS classes. | ||
* We currently never get any state _from_ Llama because it cannot modify the page. | ||
*/ | ||
declare class LlamaManager { | ||
/** Element modified with flag that Llama can read. */ | ||
private element; | ||
private readonly cleanups; | ||
private readonly _logger; | ||
connect(manager: EditorManagerLike): void; | ||
private _setClassFlag; | ||
private _onStatusChange; | ||
disconnect(): void; | ||
} | ||
/** | ||
* @private | ||
@@ -1289,51 +1246,29 @@ * | ||
*/ | ||
declare class EditorManager extends EventEmitter<EditorManagerEvents> implements EditorManagerLike { | ||
readonly authService: AuthService; | ||
declare class EditorManager extends EventEmitter<Events> implements Manager<State>, Disposable { | ||
readonly clientId: string; | ||
readonly instanceId: number; | ||
readonly pluginElement: HTMLElement; | ||
readonly auth: AuthManager; | ||
readonly preferences: PreferencesManager; | ||
readonly connection: CAPIConnectionManager; | ||
readonly feedback: FeedbackService; | ||
readonly alerts: AlertManager; | ||
readonly highlights: HighlightManager; | ||
readonly textManager: EditorTextManager; | ||
private readonly _state; | ||
private readonly _cleanup; | ||
private readonly _cleanupForEditor; | ||
private readonly _logger; | ||
readonly clientId: string; | ||
readonly pluginElement: HTMLElement; | ||
constructor(clientId: string, pluginElement: HTMLElement); | ||
readonly instanceId: number; | ||
readonly textManager: EditorTextManager; | ||
readonly extensionManager: ExtensionManager; | ||
readonly llamaManager: LlamaManager; | ||
readonly gbuttonManager: GButtonManager; | ||
readonly toneManager: ToneManager; | ||
readonly alerts: AlertManager; | ||
readonly highlights: HighlightManager; | ||
private _status; | ||
private _config; | ||
private _isConnected; | ||
get state(): ReadonlyModel<State>; | ||
get isConnected(): boolean; | ||
private _cleanups; | ||
private _rootStyles; | ||
private _zIndex; | ||
get editor(): EditorElement$1; | ||
/** | ||
* Should copy styles from viewport to wrapper web component? | ||
* | ||
* `"auto"` is used for [data-grammarly] and `withElement()`. | ||
* `"none"` set `rootStyles` is always `null`, used in declarative web-component/react/vue APIs. | ||
* | ||
* @internal | ||
* Attach editor manager to an {@link editor} | ||
*/ | ||
styleMode: "auto" | "none"; | ||
connect(editor: EditorElement$1, viewport?: HTMLElement): Disposable; | ||
/** | ||
* Styles inherited from viewport. | ||
* Detach from editor. | ||
*/ | ||
get rootStyles(): CSSStyleDeclaration | null; | ||
/** | ||
* z-index for rendering UI above editor | ||
*/ | ||
get zIndex(): number | null; | ||
get editor(): EditorElement; | ||
get viewport(): HTMLElement; | ||
get status(): GrammarlyStatus; | ||
get user(): User$1 | null; | ||
get text(): Delta; | ||
get config(): Readonly<EditorConfig>; | ||
connect(editor: EditorElement, viewport?: HTMLElement): void; | ||
disconnect(): void; | ||
private readonly refreshConnection; | ||
/** | ||
@@ -1347,3 +1282,3 @@ * The plugin begins in "pending" state until user activates eg by focus. | ||
*/ | ||
disablePlugin(reason: PluginDisableReason): void; | ||
disable(reason: PluginDisableReason): void; | ||
/** | ||
@@ -1367,12 +1302,12 @@ * User has chosen to visually hide underlines. | ||
setConfig(config: Partial<EditorConfig>): void; | ||
private _updateStatus; | ||
private _setStatus; | ||
/** | ||
* | ||
* @param mode | ||
*/ | ||
setStyleMode(mode: State["styleMode"]): void; | ||
/** | ||
* Turns off the plugin. Status error can not be recovered from. | ||
*/ | ||
handleFatalError(error: Error): void; | ||
private _handleExtensionStatus; | ||
private _setupManagers; | ||
private readonly onTextStats; | ||
private _syncEditorWithCAPI; | ||
dispose(): void; | ||
} | ||
@@ -1379,0 +1314,0 @@ |
@@ -17,2 +17,2 @@ /** | ||
*/ | ||
var ExceptionCodes={};ExceptionCodes[ExceptionCodes["UNKNOWN"]=1e3]="UNKNOWN";ExceptionCodes[ExceptionCodes["ENVIRONMENT_UNSUPPORTED"]=3001]="ENVIRONMENT_UNSUPPORTED";const messages={[ExceptionCodes.UNKNOWN]:"Unknown error",[ExceptionCodes.ENVIRONMENT_UNSUPPORTED]:"The environment is not supported"};class GrammarlyException extends Error{constructor(code=ExceptionCodes.UNKNOWN,message=messages[code]){super(message);this.code=code}}GrammarlyException.codes=ExceptionCodes;function findScript(url){const scripts=document.querySelectorAll(`script[src^="${url}"]`);return scripts[0]}function injectScript(url){const script=document.createElement("script");script.src=url;document.head.appendChild(script);return script}const promises=new Map;function initGrammarlyGlobalAPI(){if(typeof window==="undefined"){return}if(window.Grammarly!=null)return;window.Grammarly={}}async function loadScript(url,clientId){if(typeof window==="undefined"){return await Promise.reject(new GrammarlyException(GrammarlyException.codes.ENVIRONMENT_UNSUPPORTED,"Cannot load script in non-browser environment"))}initGrammarlyGlobalAPI();if(promises.has(url)){return await promises.get(url)}else{const grammarlyPromise=new Promise(((resolve,reject)=>{try{let script=findScript(url);if(script!=null){resolve(window.Grammarly)}else{script=injectScript(clientId!=null?`${url}?clientId=${clientId}`:url);script.addEventListener("load",(()=>{if(window.Grammarly!=null){resolve(window.Grammarly)}else{reject(new Error("Grammarly not available"))}}));script.addEventListener("error",(function(){reject(new Error(`Failed to load ${url}`))}))}}catch(error){return reject(error)}})).finally((()=>{promises.delete(url)}));promises.set(url,grammarlyPromise);return grammarlyPromise}}const[versionMajor,versionMinor]="1.4.0".split(".");const resolvedVersion=`${versionMajor}.${versionMinor}`;async function init(clientId){var _a,_b;const Grammarly=await loadScript((_a=undefined)!==null&&_a!==void 0?_a:`https://js.${(_b="grammarly.com")!==null&&_b!==void 0?_b:"grammarly.com"}/grammarly-editor-sdk@${resolvedVersion}`,clientId);if(clientId!=null){return new Grammarly.EditorSDK(clientId)}}export{init}; | ||
var ExceptionCodes={};ExceptionCodes[ExceptionCodes["UNKNOWN"]=1e3]="UNKNOWN";ExceptionCodes[ExceptionCodes["ENVIRONMENT_UNSUPPORTED"]=3001]="ENVIRONMENT_UNSUPPORTED";const messages={[ExceptionCodes.UNKNOWN]:"Unknown error",[ExceptionCodes.ENVIRONMENT_UNSUPPORTED]:"The environment is not supported"};class GrammarlyException extends Error{constructor(code=ExceptionCodes.UNKNOWN,message=messages[code]){super(message);this.code=code}}GrammarlyException.codes=ExceptionCodes;function findScript(url){const scripts=document.querySelectorAll(`script[src^="${url}"]`);return scripts[0]}function injectScript(url){const script=document.createElement("script");script.src=url;document.head.appendChild(script);return script}const promises=new Map;function initGrammarlyGlobalAPI(){if(typeof window==="undefined"){return}if(window.Grammarly!=null)return;window.Grammarly={}}async function loadScript(url,clientId){if(typeof window==="undefined"){return await Promise.reject(new GrammarlyException(GrammarlyException.codes.ENVIRONMENT_UNSUPPORTED,"Cannot load script in non-browser environment"))}initGrammarlyGlobalAPI();if(promises.has(url)){return await promises.get(url)}else{const grammarlyPromise=new Promise(((resolve,reject)=>{try{let script=findScript(url);if(script!=null){resolve(window.Grammarly)}else{script=injectScript(clientId!=null?`${url}?clientId=${clientId}`:url);script.addEventListener("load",(()=>{if(window.Grammarly!=null){resolve(window.Grammarly)}else{reject(new Error("Grammarly not available"))}}));script.addEventListener("error",(function(){reject(new Error(`Failed to load ${url}`))}))}}catch(error){return reject(error)}})).finally((()=>{promises.delete(url)}));promises.set(url,grammarlyPromise);return grammarlyPromise}}const[versionMajor,versionMinor]="1.5.0".split(".");const resolvedVersion=`${versionMajor}.${versionMinor}`;async function init(clientId){var _a,_b;const Grammarly=await loadScript((_a=undefined)!==null&&_a!==void 0?_a:`https://js.${(_b="grammarly.com")!==null&&_b!==void 0?_b:"grammarly.com"}/grammarly-editor-sdk@${resolvedVersion}`,clientId);if(clientId!=null){return new Grammarly.EditorSDK(clientId)}}export{init}; |
@@ -17,2 +17,2 @@ /** | ||
*/ | ||
!function(){"use strict";var n={};n[n.UNKNOWN=1e3]="UNKNOWN",n[n.ENVIRONMENT_UNSUPPORTED=3001]="ENVIRONMENT_UNSUPPORTED";const r={[n.UNKNOWN]:"Unknown error",[n.ENVIRONMENT_UNSUPPORTED]:"The environment is not supported"};class t extends Error{constructor(t=n.UNKNOWN,e=r[t]){super(e),this.code=t}}t.codes=n;const e=new Map;async function o(n,r){if("undefined"==typeof window)return await Promise.reject(new t(t.codes.ENVIRONMENT_UNSUPPORTED,"Cannot load script in non-browser environment"));if("undefined"!=typeof window&&null==window.Grammarly&&(window.Grammarly={}),e.has(n))return await e.get(n);{const t=new Promise(((t,e)=>{try{let o=function(n){return document.querySelectorAll(`script[src^="${n}"]`)[0]}(n);null!=o?t(window.Grammarly):(o=function(n){const r=document.createElement("script");return r.src=n,document.head.appendChild(r),r}(null!=r?`${n}?clientId=${r}`:n),o.addEventListener("load",(()=>{null!=window.Grammarly?t(window.Grammarly):e(new Error("Grammarly not available"))})),o.addEventListener("error",(function(){e(new Error(`Failed to load ${n}`))})))}catch(n){return e(n)}})).finally((()=>{e.delete(n)}));return e.set(n,t),t}}const[i,a]="1.4.0".split("."),c=`${i}.${a}`;async function l(n){var r;const t=await o((void 0,`https://js.${null!==(r="grammarly.com")?r:"grammarly.com"}/grammarly-editor-sdk@${c}`),n);if(null!=n)return new t.EditorSDK(n)}const s=function(){const n=function(){if(document.currentScript instanceof HTMLScriptElement)return document.currentScript}();if(n){const r=n.src;if(r){const n=new URL(r).searchParams.get("clientId");if(null!=n)return n}const t=n.getAttribute("clientId");if(null!=t)return t}}(),u=null!=s?l(s):void 0;window.Grammarly.init=async(n=s)=>{const r=s===n?await u:null!=n?await l(n):void 0;if(null==r)throw new Error('A "clientId" is required to init Grammarly SDK.');return r}}(); | ||
!function(){"use strict";var n={};n[n.UNKNOWN=1e3]="UNKNOWN",n[n.ENVIRONMENT_UNSUPPORTED=3001]="ENVIRONMENT_UNSUPPORTED";const r={[n.UNKNOWN]:"Unknown error",[n.ENVIRONMENT_UNSUPPORTED]:"The environment is not supported"};class t extends Error{constructor(t=n.UNKNOWN,e=r[t]){super(e),this.code=t}}t.codes=n;const e=new Map;async function o(n,r){if("undefined"==typeof window)return await Promise.reject(new t(t.codes.ENVIRONMENT_UNSUPPORTED,"Cannot load script in non-browser environment"));if("undefined"!=typeof window&&null==window.Grammarly&&(window.Grammarly={}),e.has(n))return await e.get(n);{const t=new Promise(((t,e)=>{try{let o=function(n){return document.querySelectorAll(`script[src^="${n}"]`)[0]}(n);null!=o?t(window.Grammarly):(o=function(n){const r=document.createElement("script");return r.src=n,document.head.appendChild(r),r}(null!=r?`${n}?clientId=${r}`:n),o.addEventListener("load",(()=>{null!=window.Grammarly?t(window.Grammarly):e(new Error("Grammarly not available"))})),o.addEventListener("error",(function(){e(new Error(`Failed to load ${n}`))})))}catch(n){return e(n)}})).finally((()=>{e.delete(n)}));return e.set(n,t),t}}const[i,a]="1.5.0".split("."),c=`${i}.${a}`;async function l(n){var r;const t=await o((void 0,`https://js.${null!==(r="grammarly.com")?r:"grammarly.com"}/grammarly-editor-sdk@${c}`),n);if(null!=n)return new t.EditorSDK(n)}const s=function(){const n=function(){if(document.currentScript instanceof HTMLScriptElement)return document.currentScript}();if(n){const r=n.src;if(r){const n=new URL(r).searchParams.get("clientId");if(null!=n)return n}const t=n.getAttribute("clientId");if(null!=t)return t}}(),u=null!=s?l(s):void 0;window.Grammarly.init=async(n=s)=>{const r=s===n?await u:null!=n?await l(n):void 0;if(null==r)throw new Error('A "clientId" is required to init Grammarly SDK.');return r}}(); |
@@ -17,2 +17,2 @@ /** | ||
*/ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var ExceptionCodes={};ExceptionCodes[ExceptionCodes["UNKNOWN"]=1e3]="UNKNOWN";ExceptionCodes[ExceptionCodes["ENVIRONMENT_UNSUPPORTED"]=3001]="ENVIRONMENT_UNSUPPORTED";const messages={[ExceptionCodes.UNKNOWN]:"Unknown error",[ExceptionCodes.ENVIRONMENT_UNSUPPORTED]:"The environment is not supported"};class GrammarlyException extends Error{constructor(code=ExceptionCodes.UNKNOWN,message=messages[code]){super(message);this.code=code}}GrammarlyException.codes=ExceptionCodes;function findScript(url){const scripts=document.querySelectorAll(`script[src^="${url}"]`);return scripts[0]}function injectScript(url){const script=document.createElement("script");script.src=url;document.head.appendChild(script);return script}const promises=new Map;function initGrammarlyGlobalAPI(){if(typeof window==="undefined"){return}if(window.Grammarly!=null)return;window.Grammarly={}}async function loadScript(url,clientId){if(typeof window==="undefined"){return await Promise.reject(new GrammarlyException(GrammarlyException.codes.ENVIRONMENT_UNSUPPORTED,"Cannot load script in non-browser environment"))}initGrammarlyGlobalAPI();if(promises.has(url)){return await promises.get(url)}else{const grammarlyPromise=new Promise(((resolve,reject)=>{try{let script=findScript(url);if(script!=null){resolve(window.Grammarly)}else{script=injectScript(clientId!=null?`${url}?clientId=${clientId}`:url);script.addEventListener("load",(()=>{if(window.Grammarly!=null){resolve(window.Grammarly)}else{reject(new Error("Grammarly not available"))}}));script.addEventListener("error",(function(){reject(new Error(`Failed to load ${url}`))}))}}catch(error){return reject(error)}})).finally((()=>{promises.delete(url)}));promises.set(url,grammarlyPromise);return grammarlyPromise}}const[versionMajor,versionMinor]="1.4.0".split(".");const resolvedVersion=`${versionMajor}.${versionMinor}`;async function init(clientId){var _a,_b;const Grammarly=await loadScript((_a=undefined)!==null&&_a!==void 0?_a:`https://js.${(_b="grammarly.com")!==null&&_b!==void 0?_b:"grammarly.com"}/grammarly-editor-sdk@${resolvedVersion}`,clientId);if(clientId!=null){return new Grammarly.EditorSDK(clientId)}}exports.init=init; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var ExceptionCodes={};ExceptionCodes[ExceptionCodes["UNKNOWN"]=1e3]="UNKNOWN";ExceptionCodes[ExceptionCodes["ENVIRONMENT_UNSUPPORTED"]=3001]="ENVIRONMENT_UNSUPPORTED";const messages={[ExceptionCodes.UNKNOWN]:"Unknown error",[ExceptionCodes.ENVIRONMENT_UNSUPPORTED]:"The environment is not supported"};class GrammarlyException extends Error{constructor(code=ExceptionCodes.UNKNOWN,message=messages[code]){super(message);this.code=code}}GrammarlyException.codes=ExceptionCodes;function findScript(url){const scripts=document.querySelectorAll(`script[src^="${url}"]`);return scripts[0]}function injectScript(url){const script=document.createElement("script");script.src=url;document.head.appendChild(script);return script}const promises=new Map;function initGrammarlyGlobalAPI(){if(typeof window==="undefined"){return}if(window.Grammarly!=null)return;window.Grammarly={}}async function loadScript(url,clientId){if(typeof window==="undefined"){return await Promise.reject(new GrammarlyException(GrammarlyException.codes.ENVIRONMENT_UNSUPPORTED,"Cannot load script in non-browser environment"))}initGrammarlyGlobalAPI();if(promises.has(url)){return await promises.get(url)}else{const grammarlyPromise=new Promise(((resolve,reject)=>{try{let script=findScript(url);if(script!=null){resolve(window.Grammarly)}else{script=injectScript(clientId!=null?`${url}?clientId=${clientId}`:url);script.addEventListener("load",(()=>{if(window.Grammarly!=null){resolve(window.Grammarly)}else{reject(new Error("Grammarly not available"))}}));script.addEventListener("error",(function(){reject(new Error(`Failed to load ${url}`))}))}}catch(error){return reject(error)}})).finally((()=>{promises.delete(url)}));promises.set(url,grammarlyPromise);return grammarlyPromise}}const[versionMajor,versionMinor]="1.5.0".split(".");const resolvedVersion=`${versionMajor}.${versionMinor}`;async function init(clientId){var _a,_b;const Grammarly=await loadScript((_a=undefined)!==null&&_a!==void 0?_a:`https://js.${(_b="grammarly.com")!==null&&_b!==void 0?_b:"grammarly.com"}/grammarly-editor-sdk@${resolvedVersion}`,clientId);if(clientId!=null){return new Grammarly.EditorSDK(clientId)}}exports.init=init; |
@@ -5,3 +5,3 @@ { | ||
"description": "Grammarly writing SDK for web editors", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"main": "lib/index.js", | ||
@@ -27,4 +27,5 @@ "module": "lib/index.esm.js", | ||
"devDependencies": { | ||
"@grammarly/plugin-core": "1.4.0", | ||
"@grammarly/plugin-editor": "1.4.0", | ||
"@grammarly/plugin-core": "1.5.0", | ||
"@grammarly/plugin-editor": "1.5.0", | ||
"@grammarly/plugin-reactivity": "1.5.0", | ||
"@microsoft/api-extractor": "^7.15.1", | ||
@@ -31,0 +32,0 @@ "@testing-library/jest-dom": "^5.11.10", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60975
10
1476