@grammarly/editor-sdk
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -21,4 +21,4 @@ /** | ||
import { CAPIConnection } from '@grammarly/core-clients/esm/capi'; | ||
import { Delta } from '@grammarly/core-clients/esm/ot'; | ||
import { RawAlert, AbsRawTransform, CAPI } from '@grammarly/core-clients'; | ||
import { CAPI, RawAlert, AbsRawTransform } from '@grammarly/core-clients'; | ||
import diff from 'fast-diff'; | ||
@@ -44,3 +44,113 @@ /** | ||
interface AttributeMapRaw { | ||
bold: boolean; | ||
italic: boolean; | ||
underline: boolean; | ||
code: boolean; | ||
link: string; | ||
list: "number" | "bullet"; | ||
indent: number; | ||
header: 1 | 2 | 3 | 4 | 5 | 6; | ||
"code-block": boolean; | ||
linebreak: boolean; | ||
} | ||
declare type AttributeMap = { | ||
[P in keyof AttributeMapRaw]?: AttributeMapRaw[P]; | ||
}; | ||
declare type AttributeMapNullable = { | ||
[P in keyof AttributeMapRaw]?: AttributeMapRaw[P] | null; | ||
}; | ||
/** | ||
* @public | ||
*/ | ||
declare type InsertOperation<T extends string | Record<string, unknown> = string | Record<string, unknown>> = { | ||
/** Text to insert */ | ||
insert: T; | ||
/** Metadata or semantics for the operation */ | ||
attributes?: AttributeMap; | ||
}; | ||
/** | ||
* @public | ||
*/ | ||
declare type DeleteOperation = { | ||
/** Number of characters to delete */ | ||
delete: number; | ||
}; | ||
/** | ||
* @public | ||
*/ | ||
declare type RetainOperation = { | ||
/** Number of characters to delete */ | ||
retain: number; | ||
/** Metadata or semantics for the operation */ | ||
attributes?: AttributeMap; | ||
}; | ||
declare type Operation = InsertOperation | DeleteOperation | RetainOperation; | ||
declare type DeltaInit<T extends Operation = Operation> = T[] | { | ||
ops: T[]; | ||
} | Delta; | ||
declare class Delta<T extends Operation = Operation> { | ||
private readonly _ops; | ||
private readonly _length; | ||
private readonly _changeLength; | ||
get ops(): readonly T[]; | ||
get changeLength(): number; | ||
get length(): number; | ||
constructor(init?: DeltaInit<T>); | ||
insert(arg: InsertOperation["insert"], attributes?: AttributeMapNullable): this; | ||
delete(length: number): this; | ||
retain(length: number, attributes?: AttributeMapNullable): this; | ||
push(op: Operation): this; | ||
slice(start?: number, end?: number): Delta<T>; | ||
/** | ||
* Returns a Delta that is equivalent to applying the operations of own Delta, followed by another Delta. | ||
*/ | ||
compose(other: Delta): Delta; | ||
/** | ||
* Transform an index against the delta. Useful for representing cursor/selection positions. | ||
*/ | ||
transformPosition(index: number, priority?: boolean): number; | ||
private _setAttributes; | ||
toJSON(): string; | ||
toRaw(): { | ||
ops: Operation[]; | ||
}; | ||
} | ||
declare class DocumentDelta extends Delta<InsertOperation> { | ||
private readonly _toString; | ||
retain(_length: number, _attributes?: AttributeMap): this; | ||
delete(_length: number, _attributes?: AttributeMap): this; | ||
insert(arg: string | Record<string, unknown>, attributes?: AttributeMap): this; | ||
push(op: InsertOperation): this; | ||
concat(other: DocumentDelta): DocumentDelta; | ||
diff(other: DocumentDelta, cursor?: number | diff.CursorInfo): Delta; | ||
toString(): string; | ||
toPlainText(): string; | ||
slice(start?: number, end?: number): DocumentDelta; | ||
} | ||
/** | ||
* | ||
* @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. | ||
*/ | ||
/** | ||
* @internal | ||
@@ -175,160 +285,2 @@ */ | ||
/** | ||
* 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 = { | ||
change: { | ||
changes: Delta; | ||
previous: { | ||
delta: Delta; | ||
textLength: number; | ||
}; | ||
next: { | ||
delta: Delta; | ||
textLength: number; | ||
}; | ||
}; | ||
}; | ||
interface TextState { | ||
transformedPlainText: string | null; | ||
originalText: Delta; | ||
transformedText: Delta; | ||
length: number; | ||
} | ||
interface CursorInfo { | ||
oldRange: { | ||
index: number; | ||
/** Selection length */ | ||
length: number; | ||
}; | ||
newRange: { | ||
index: number; | ||
length: number; | ||
}; | ||
} | ||
/** | ||
* @experimental | ||
*/ | ||
interface TextTransformer { | ||
encode: (text: Delta) => Delta; | ||
decode: (text: Delta) => Delta; | ||
getOriginalPosition: (position: number) => number; | ||
getTransformedPosition: (position: number) => number; | ||
} | ||
declare class TextManager extends EventEmitter<TextEncoderEvents> { | ||
protected readonly state: TextState; | ||
protected readonly transformer: TextTransformer; | ||
constructor(transformer?: TextTransformer); | ||
/** | ||
* Processed text for CAPI | ||
*/ | ||
get delta(): Delta; | ||
/** | ||
* Length of processed text | ||
*/ | ||
get textLength(): number; | ||
/** | ||
* Update text using transformer. | ||
* | ||
* @param originalText Text as viewed by user. | ||
*/ | ||
setText(originalText: Delta | string, cursor?: number | CursorInfo): void; | ||
/** | ||
* Update text using transformer. | ||
* | ||
* @param changes text changes from previous state | ||
*/ | ||
applyEdits(changes: Delta): void; | ||
toText(): string; | ||
getOriginalText(changesInTransformedText: Delta): Delta; | ||
reset(): void; | ||
} | ||
declare type Suggestion = Alert; | ||
declare type SuggestionId = Suggestion["id"]; | ||
declare type SuggestionProviderEvents = { | ||
suggestionAdded: Suggestion[]; | ||
suggestionRemoved: Suggestion[]; | ||
}; | ||
declare const enum DismissReason { | ||
UNKNOWN = 0, | ||
INCORRECT = 1, | ||
OFFENSIVE = 2 | ||
} | ||
interface SuggestionProvider extends EventEmitter<SuggestionProviderEvents> { | ||
accept: (id: SuggestionId, index?: number) => Promise<void>; | ||
dismiss: (id: SuggestionId, reason?: DismissReason) => Promise<void>; | ||
} | ||
declare type AlertActivationSource = "hover" | "keyboard" | "manual"; | ||
declare type Events$1 = { | ||
/** @deprecated Use `state.active` */ | ||
active: { | ||
alert: Alert | undefined; | ||
source: AlertActivationSource; | ||
}; | ||
/** @deprecated Use `"suggestionAdded"` */ | ||
added: Alert; | ||
/** @deprecated Use `"suggestionRemoved"` */ | ||
removed: Alert; | ||
/** @deprecated Use `state.suggestions` */ | ||
change: Alert[]; | ||
}; | ||
/** @deprecated Use `SuggestionManager` */ | ||
declare class AlertManager extends EventEmitter<Events$1> { | ||
private readonly _compat; | ||
private readonly _suggestions; | ||
constructor(source: TextManager, providers?: SuggestionProvider[]); | ||
private _createFakeSuggestionProvider; | ||
/** | ||
* @deprecated Use `clear()` | ||
*/ | ||
reset(): void; | ||
/** | ||
* @deprecated Use `setActiveSuggestion()` | ||
*/ | ||
setActiveAlert(id: RawAlert.Id | undefined, source: AlertActivationSource): void; | ||
/** | ||
* @deprecated Use `getSuggestion()` | ||
*/ | ||
getAlert(id: Alert["id"]): Alert | null; | ||
/** | ||
* @deprecated Use `SuggestionProvider` | ||
*/ | ||
addRawAlert(rawAlert: RawAlert): void; | ||
/** | ||
* @deprecated Use `SuggestionProvider` | ||
*/ | ||
addAlert(alert: Alert): void; | ||
/** | ||
* @deprecated Use `SuggestionProvider` | ||
*/ | ||
removeAlert(id: Alert["id"]): void; | ||
/** | ||
* @deprecated Use `SuggestionManager.state.suggestions` | ||
*/ | ||
getAllAlerts(): Alert[]; | ||
} | ||
/** | ||
* Categories of suggestions that can be muted. | ||
@@ -783,3 +735,3 @@ * | ||
declare type State$1$1 = { | ||
declare type State$2 = { | ||
clientInfo: AppClientInfo | null; | ||
@@ -797,3 +749,3 @@ user: User$1 | null; | ||
}; | ||
declare class AuthManager extends EventEmitter<Events$2> implements Manager<State$1$1> { | ||
declare class AuthManager extends EventEmitter<Events$2> implements Manager<State$2> { | ||
private readonly _storage; | ||
@@ -812,3 +764,3 @@ private readonly _state; | ||
constructor(clientId: string, storage: Storage); | ||
get state(): ReadonlyModel<State$1$1>; | ||
get state(): ReadonlyModel<State$2>; | ||
setRedirectUri(redirectUri: string): void; | ||
@@ -854,3 +806,3 @@ get redirectUri(): string; | ||
*/ | ||
setActiveOAuthRequest(request: State$1$1["activeRequest"]): void; | ||
setActiveOAuthRequest(request: State$2["activeRequest"]): void; | ||
private _handleConnectedAccountStatusChange; | ||
@@ -901,3 +853,3 @@ private _onLoginSuccess; | ||
*/ | ||
setText(text: string | Delta): void; | ||
setText(text: string | DocumentDelta): void; | ||
/** | ||
@@ -933,2 +885,3 @@ * Stop sending messages to CAPI | ||
private readonly text; | ||
private readonly pending; | ||
private connection?; | ||
@@ -967,2 +920,22 @@ private connectionPromise?; | ||
/** | ||
* 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 const enum GrammarlyStatus { | ||
@@ -977,2 +950,154 @@ pending = "pending", | ||
declare const enum DismissReason { | ||
UNKNOWN = 0, | ||
INCORRECT = 1, | ||
OFFENSIVE = 2 | ||
} | ||
declare type Suggestion = Alert; | ||
declare type SuggestionId = Suggestion["id"]; | ||
declare type SuggestionProviderEvents = { | ||
suggestionAdded: Suggestion[]; | ||
suggestionRemoved: Suggestion[]; | ||
}; | ||
interface SuggestionProvider extends EventEmitter<SuggestionProviderEvents> { | ||
accept: (id: SuggestionId, index?: number) => Promise<void>; | ||
dismiss: (id: SuggestionId, reason?: DismissReason) => Promise<void>; | ||
} | ||
interface Cursor { | ||
index: number; | ||
length: number; | ||
} | ||
declare type TextRange = { | ||
start: number; | ||
end: number; | ||
}; | ||
/** | ||
* @experimental | ||
*/ | ||
interface TextTransformer { | ||
encode: (text: DocumentDelta) => DocumentDelta; | ||
decode: (text: DocumentDelta) => DocumentDelta; | ||
getOriginalPosition: (position: number) => number; | ||
getTransformedPosition: (position: number) => number; | ||
} | ||
declare type TextChangeEventDetail = { | ||
changes: Delta; | ||
previous: { | ||
text: DocumentDelta; | ||
cursor: Cursor | null; | ||
revision: number; | ||
}; | ||
next: { | ||
text: DocumentDelta; | ||
cursor: Cursor | null; | ||
revision: number; | ||
}; | ||
}; | ||
declare type Events$1 = { | ||
change: TextChangeEventDetail; | ||
}; | ||
interface State$1$1 { | ||
revision: number; | ||
/** | ||
* Text as written/read by the user. | ||
*/ | ||
original: DocumentDelta; | ||
/** | ||
* Transformed text by stripping syntax from original text. | ||
*/ | ||
transformed: DocumentDelta; | ||
/** | ||
* Last cursor position. | ||
*/ | ||
cursor: Cursor | null; | ||
/** | ||
* Text in viewport or active text range. | ||
*/ | ||
priority: TextRange; | ||
} | ||
declare class TextManager extends EventEmitter<Events$1> implements Manager<State$1$1> { | ||
private readonly _state; | ||
private readonly _logger2; | ||
readonly transformer: TextTransformer; | ||
constructor(transformer?: TextTransformer); | ||
get state(): ReadonlyModel<State$1$1>; | ||
/** | ||
* Processed text for CAPI | ||
*/ | ||
get text(): State$1$1["transformed"]; | ||
/** | ||
* Cursor position | ||
*/ | ||
get cursor(): State$1$1["cursor"]; | ||
/** | ||
* Active range for text for priortising text operations like | ||
* showing highlights and repositioning alerts. | ||
*/ | ||
setPriorityRange(range: State$1$1["priority"], expandRangeBy?: number): void; | ||
/** | ||
* Update text using transformer. | ||
* | ||
* @param text Text as written/read by the user. | ||
*/ | ||
setText(text: DocumentDelta | string, cursor: Cursor | null): void; | ||
reset(): void; | ||
} | ||
declare type SuggestionActivationSource = "hover" | "keyboard" | "manual"; | ||
declare type State$3 = { | ||
suggestions: Suggestion[]; | ||
active: { | ||
source: SuggestionActivationSource; | ||
suggestion: Suggestion; | ||
} | null; | ||
}; | ||
interface Events$3 { | ||
added: Suggestion[]; | ||
removed: Suggestion[]; | ||
updated: Suggestion[]; | ||
} | ||
declare class SuggestionManager extends EventEmitter<Events$3> implements Manager<State$3>, Disposable { | ||
private readonly _state; | ||
private readonly _cleanup; | ||
private readonly _source; | ||
private readonly _providers; | ||
private readonly _suggestions; | ||
private readonly _logger; | ||
private readonly _syncSuggestionsState; | ||
private _repositionCandidates; | ||
private _isRepositioning; | ||
private _oldestRevision; | ||
private _latestRevision; | ||
private _pendingChanges; | ||
constructor(source: TextManager); | ||
get state(): ReadonlyModel<State$3>; | ||
get suggestions(): Suggestion[]; | ||
dispose(): void; | ||
accept(id: SuggestionId, index?: number): Promise<void>; | ||
dismiss(id: SuggestionId, reason?: DismissReason): Promise<void>; | ||
setActiveSuggestion(id: SuggestionId | null, source: SuggestionActivationSource): void; | ||
getSuggestion(id: SuggestionId): Suggestion | null; | ||
clear(): void; | ||
private _removeById; | ||
private _addWithProvider; | ||
private _remove; | ||
private _update; | ||
private _hasValidTextRange; | ||
private _isForValidText; | ||
private _printSuggestionDebugMessage; | ||
register(provider: SuggestionProvider): void; | ||
private _reposition; | ||
private _scheduleDelayedReposition; | ||
private _rebaseSuggestions; | ||
} | ||
/** | ||
@@ -1000,13 +1125,12 @@ * | ||
declare type EditorElement = HTMLInputElement | HTMLTextAreaElement | HTMLElement; | ||
declare class EditorTextManager extends TextManager implements Disposable { | ||
declare class EditorTextManager extends TextManager { | ||
private readonly _logger; | ||
private readonly _cleanup; | ||
private _editor?; | ||
private offsets; | ||
private cleanup; | ||
private readonly _logger; | ||
get editor(): EditorElement; | ||
connect(editor: EditorElement): Disposable; | ||
private _offsets; | ||
private _inverseOffsets; | ||
connect(editor: EditorElement$1): Disposable; | ||
private _handlePlainTextChange; | ||
private _handleRichTextChange; | ||
disconnect(): void; | ||
setText(originalText: Delta | string, cursor?: number | CursorInfo): void; | ||
/** | ||
@@ -1020,48 +1144,13 @@ * Get DOM Range with transformed position. | ||
getPosition(start: number): Range; | ||
positionAt(node: Node, offset?: number): number | null; | ||
private _getTextMapping; | ||
dispose(): void; | ||
} | ||
declare type EditorElement = HTMLInputElement | HTMLTextAreaElement | HTMLElement; | ||
interface Highlight { | ||
alert: Alert; | ||
suggestion: Suggestion; | ||
element: HTMLDivElement; | ||
} | ||
declare class HighlightContainer { | ||
static create(): HighlightContainer; | ||
/** | ||
* A root container for highlights. | ||
* | ||
* This is a statically positioned block element. | ||
* The static position and block display, place it at the bottom of the editor | ||
* viewport, which enables us to compute the relative offset of highlights | ||
* from the top-left corner of the editor viewport. | ||
*/ | ||
readonly element: HTMLDivElement; | ||
/** | ||
* A wrapper element for scrolling highlights as a group. | ||
* | ||
* `transform: translate()` is synced with scroll position of the editor to scroll | ||
* highlights in the viewport. | ||
*/ | ||
readonly scroller: HTMLDivElement; | ||
/** | ||
* A wrapper element to clip overflowing highlights to match the editor viewport. | ||
*/ | ||
readonly viewport: HTMLDivElement; | ||
/** | ||
* Set viewport height | ||
*/ | ||
setHeight(height: number): void; | ||
/** | ||
* Set viewport width | ||
*/ | ||
setWidth(width: number): void; | ||
/** | ||
* Move vieport such that it's on top the editor | ||
*/ | ||
setOffset(x: number, y: number): void; | ||
constructor(); | ||
} | ||
interface Position { | ||
@@ -1103,3 +1192,3 @@ x: number; | ||
interface State$1 { | ||
activeHighlightId: Alert["id"] | null; | ||
activeHighlightId: Suggestion["id"] | null; | ||
displayMode: "all" | "none" | "corrective"; | ||
@@ -1113,19 +1202,13 @@ kind: EditorKind | null; | ||
private readonly _cleanup; | ||
private readonly resizeObserver; | ||
private readonly hasViewportWidthChanged; | ||
private readonly hasEditorWidthChanged; | ||
private readonly highlights; | ||
private prevAlerts; | ||
private readonly renderWorker; | ||
private readonly _resizeObserver; | ||
private readonly _hasViewportWidthChanged; | ||
private readonly _hasEditorWidthChanged; | ||
private readonly _highlights; | ||
private readonly _renderWorker; | ||
private _target?; | ||
private _editor?; | ||
private _viewport?; | ||
protected readonly container: HighlightContainer; | ||
/** Offset position in text, after which highlights needs rendering. */ | ||
protected dirtyAfterIndex: number; | ||
protected lastScrollState: { | ||
top: number; | ||
left: number; | ||
}; | ||
private originalSpellCheck; | ||
private readonly _container; | ||
private readonly _internal; | ||
private _originalSpellCheck; | ||
get displayMode(): HighlightDisplayMode; | ||
@@ -1136,4 +1219,7 @@ /** | ||
set displayMode(mode: HighlightDisplayMode); | ||
protected readonly textManager: EditorTextManager; | ||
constructor(textManager: EditorTextManager); | ||
private readonly _source; | ||
private readonly _suggestions; | ||
constructor(source: EditorTextManager, suggestions: SuggestionManager); | ||
private _updatePriorityRange; | ||
private _getCaretPosition; | ||
get state(): ReadonlyModel<State$1>; | ||
@@ -1153,8 +1239,8 @@ private _isConnected; | ||
clearViewport(): void; | ||
setEditor(editor: EditorElement): void; | ||
setEditor(editor: EditorElement$1): void; | ||
clearEditor(): void; | ||
render(alerts?: Alert[]): void; | ||
getHighlight(alertId: Alert["id"]): Highlight | undefined; | ||
getHighlightRect(alertId: Alert["id"]): DOMRectLike | null; | ||
setHoverState(alertId: Alert["id"], isHovered: boolean): void; | ||
render(): void; | ||
getHighlight(alertId: Suggestion["id"]): Highlight | undefined; | ||
getHighlightRect(alertId: Suggestion["id"]): DOMRectLike | null; | ||
setHoverState(alertId: Suggestion["id"], isHovered: boolean): void; | ||
/** | ||
@@ -1167,10 +1253,13 @@ * BoundingClientRect of the highlights wrapper element | ||
protected currentReferenceClientRect: DOMRect; | ||
private _updateAll; | ||
private readonly renderCandidates; | ||
private readonly dom; | ||
private _setAlerts; | ||
private readonly _renderCandidates; | ||
private readonly _dom; | ||
private _removeAll; | ||
private _remove; | ||
/** | ||
* @param suggestions null value triggers a re-render of stale highlights | ||
*/ | ||
private _createRenderTask; | ||
private _getViewport; | ||
private _getViewportOrThrow; | ||
private _shouldDisplayAlert; | ||
private _shouldDisplaySuggestion; | ||
private isRendering; | ||
@@ -1182,2 +1271,3 @@ /** | ||
private _updateHighlight; | ||
private _hideHighlight; | ||
private _getHighlightClass; | ||
@@ -1197,5 +1287,2 @@ private _createHighlightElement; | ||
private readonly onMouseLeaveEvent; | ||
private _viewportOffset; | ||
get viewportOffset(): Readonly<Position>; | ||
private prevViewportRect?; | ||
/** | ||
@@ -1208,3 +1295,3 @@ * Callback to handle change in viewport size. | ||
*/ | ||
setActiveHighlight(highlightId?: RawAlert.Id | null): void; | ||
setActiveHighlight(highlightId?: Suggestion["id"] | null): void; | ||
/** | ||
@@ -1225,4 +1312,4 @@ * Fire fake/custom mouse enter/leave event for highlight. | ||
interface State { | ||
editor: EditorElement$1 | null; | ||
viewport: EditorElement$1 | null; | ||
editor: EditorElement | null; | ||
viewport: EditorElement | null; | ||
status: GrammarlyStatus; | ||
@@ -1251,3 +1338,3 @@ config: EditorConfig; | ||
readonly feedback: FeedbackService; | ||
readonly alerts: AlertManager; | ||
readonly suggestions: SuggestionManager; | ||
readonly highlights: HighlightManager; | ||
@@ -1262,7 +1349,7 @@ readonly textManager: EditorTextManager; | ||
get isConnected(): boolean; | ||
get editor(): EditorElement$1; | ||
get editor(): EditorElement; | ||
/** | ||
* Attach editor manager to an {@link editor} | ||
*/ | ||
connect(editor: EditorElement$1, viewport?: HTMLElement): Disposable; | ||
connect(editor: EditorElement, viewport?: HTMLElement): Disposable; | ||
/** | ||
@@ -1295,3 +1382,3 @@ * Detach from editor. | ||
*/ | ||
applyAlertReplacement(alert: Alert, options: { | ||
applyAlertReplacement(alert: Suggestion, options: { | ||
index?: number; | ||
@@ -1330,3 +1417,3 @@ }): Promise<boolean>; | ||
set config(config: Partial<EditorConfig>); | ||
connect(editor: EditorElement, viewport?: HTMLElement): void; | ||
connect(editor: EditorElement$1, viewport?: HTMLElement): void; | ||
connectedCallback(): void; | ||
@@ -1333,0 +1420,0 @@ disconnectedCallback(): void; |
@@ -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.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}; | ||
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.1".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.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}}(); | ||
!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.1".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.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; | ||
"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.1".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; |
{ | ||
"private": false, | ||
"name": "@grammarly/editor-sdk", | ||
"description": "Grammarly writing SDK for web editors", | ||
"version": "1.5.0", | ||
"main": "lib/index.js", | ||
"module": "lib/index.esm.js", | ||
"unpkg": "lib/index.iife.js", | ||
"types": "lib/index.d.ts", | ||
"license": "Apache-2.0", | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/grammarly/grammarly-for-developers.git" | ||
}, | ||
"files": [ | ||
"lib/index.d.ts", | ||
"lib/index.esm.js", | ||
"lib/index.iife.js", | ||
"lib/index.js" | ||
], | ||
"devDependencies": { | ||
"@grammarly/plugin-core": "1.5.0", | ||
"@grammarly/plugin-editor": "1.5.0", | ||
"@grammarly/plugin-reactivity": "1.5.0", | ||
"@microsoft/api-extractor": "^7.15.1", | ||
"@testing-library/jest-dom": "^5.11.10", | ||
"@types/jest": "^26.0.22", | ||
"bundlesize": "github:znck/bundlesize", | ||
"jest": "^26.6.3", | ||
"jest-fetch-mock": "^3.0.3", | ||
"ts-jest": "^26.5.4" | ||
}, | ||
"bundlesize": [ | ||
{ | ||
"path": "./lib/index.js", | ||
"maxSize": "3 kb", | ||
"compression": "none" | ||
} | ||
], | ||
"scripts": { | ||
"test": "jest", | ||
"test:size": "bundlesize", | ||
"docs:api": "api-extractor run --verbose" | ||
} | ||
} | ||
"private": false, | ||
"name": "@grammarly/editor-sdk", | ||
"description": "Grammarly writing SDK for web editors", | ||
"version": "1.5.1", | ||
"main": "lib/index.js", | ||
"module": "lib/index.esm.js", | ||
"unpkg": "lib/index.iife.js", | ||
"types": "lib/index.d.ts", | ||
"license": "Apache-2.0", | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/grammarly/grammarly-for-developers.git" | ||
}, | ||
"files": [ | ||
"lib/index.d.ts", | ||
"lib/index.esm.js", | ||
"lib/index.iife.js", | ||
"lib/index.js" | ||
], | ||
"devDependencies": { | ||
"@grammarly/plugin-core": "1.5.1", | ||
"@grammarly/plugin-editor": "1.5.1", | ||
"@grammarly/plugin-reactivity": "1.5.1", | ||
"@microsoft/api-extractor": "^7.15.1", | ||
"@testing-library/jest-dom": "^5.11.10", | ||
"@types/jest": "^26.0.22", | ||
"bundlesize": "github:znck/bundlesize", | ||
"jest": "^26.6.3", | ||
"jest-fetch-mock": "^3.0.3", | ||
"ts-jest": "^26.5.4" | ||
}, | ||
"bundlesize": [ | ||
{ | ||
"path": "./lib/index.js", | ||
"maxSize": "3 kb", | ||
"compression": "none" | ||
} | ||
], | ||
"scripts": { | ||
"test": "jest", | ||
"test:size": "bundlesize", | ||
"docs:api": "api-extractor run --verbose" | ||
} | ||
} |
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
63848
1554