@grammarly/editor-sdk
Advanced tools
Comparing version 1.0.0-alpha.6 to 1.0.0-alpha.7
@@ -1,3 +0,5 @@ | ||
/** Grammarly writing SDK for web editors @packageDocumentation */ | ||
import { Dialect } from '@grammarly/core-clients/esm/common'; | ||
/** | ||
* Grammarly writing SDK for web editors | ||
* @packageDocumentation | ||
*/ | ||
@@ -14,5 +16,5 @@ /** | ||
wordsChecked: number; | ||
/** Suggestions provided by Grammarly. */ | ||
/** Suggestions provided by Grammarly. See {@link SessionSuggestionBreakdown}. */ | ||
suggestionsSent: SessionSuggestionBreakdown; | ||
/** Suggestions accepted by user. */ | ||
/** Suggestions accepted by user. See {@link SessionSuggestionBreakdown}. */ | ||
suggestionsAccepted: SessionSuggestionBreakdown; | ||
@@ -64,3 +66,3 @@ } | ||
speakingTime: Time; | ||
/** Stats about the overall session. */ | ||
/** Stats about the overall session. See {@link SessionStats}. */ | ||
session: SessionStats; | ||
@@ -72,2 +74,5 @@ } | ||
* | ||
* @remarks | ||
* Related: {@link https://developer.grammarly.com/guide/rate-limits.html | Rate Limits} | ||
* | ||
* @public | ||
@@ -82,9 +87,23 @@ */ | ||
interface GrammarlyOptions { | ||
/** See {@link GrammarlyFeaturesConfig} */ | ||
features?: GrammarlyFeaturesConfig; | ||
/** See {@link GrammarlyDocumentConfig} */ | ||
document?: GrammarlyDocumentConfig; | ||
/** Callback to receive stats about the user-entered text and Grammarly session. */ | ||
/** | ||
* Callback to receive stats about the user-entered text and Grammarly session. | ||
* | ||
* @remarks | ||
* See {@link TextStats} | ||
*/ | ||
onTextStats?: (stats: TextStats) => void; | ||
/** Triggered when the user consciously disables the plugin. Not triggered again once already disabled. */ | ||
/** | ||
* Triggered when the user consciously disables the plugin. Not triggered again once already disabled. | ||
* | ||
* @remarks | ||
* See {@link PluginDisableReason} | ||
*/ | ||
onPluginDisable?: (reason: PluginDisableReason) => void; | ||
/** Callback triggered on fatal error with the plugin. */ | ||
/** | ||
* Callback triggered on fatal error with the plugin. | ||
*/ | ||
onPluginError?: (error: Error) => void; | ||
@@ -115,8 +134,15 @@ } | ||
/** | ||
* Whether to enable full-sentence rewrites. | ||
* @defaultValue true | ||
*/ | ||
fullSentenceRewrite?: boolean; | ||
/** | ||
* Whether to enable plagiarism detection. | ||
* @defaultValue false | ||
* | ||
* @internal | ||
*/ | ||
plagiarism?: boolean; | ||
/** | ||
* Whether to include readability suggestions. | ||
* Whether to identify hard-to-read sentences. | ||
* @defaultValue true | ||
@@ -126,3 +152,3 @@ */ | ||
/** | ||
* Whether to include sentence variety suggestions. | ||
* Whether to flag series of repetitive sentences. | ||
* @defaultValue true | ||
@@ -153,3 +179,3 @@ */ | ||
/** | ||
* Which English dialect should be assumed? | ||
* Which English dialect should be assumed? See {@link Dialect} | ||
* @defaultValue american | ||
@@ -161,3 +187,26 @@ * | ||
dialect?: Dialect | "auto"; | ||
/** | ||
* What is the style or type of writing? See {@link Domain} | ||
* @defaultValue general | ||
*/ | ||
domain?: Domain; | ||
} | ||
/** | ||
* Specific variety of English being written. | ||
* | ||
* @remarks | ||
* See {@link https://support.grammarly.com/hc/en-us/articles/115000089992-Select-between-British-English-American-English-Canadian-English-and-Australian-English | this article} for differences. | ||
* | ||
* @public | ||
*/ | ||
declare type Dialect = "american" | "british" | "canadian" | "australian" | "undefined"; | ||
/** | ||
* The style or type of writing to be checked. | ||
* | ||
* @remarks | ||
* See {@link https://support.grammarly.com/hc/en-us/articles/115000091472-What-is-domain-document-type- | What is domain/document type?}. | ||
* | ||
* @public | ||
*/ | ||
declare type Domain = "academic" | "business" | "general" | "mail" | "casual" | "creative"; | ||
@@ -167,5 +216,9 @@ /** | ||
* | ||
* @remarks | ||
* See {@link GrammarlyOptions}. | ||
* | ||
* @public | ||
*/ | ||
interface EditorConfig extends GrammarlyOptions { | ||
/** @internal */ | ||
cards: { | ||
@@ -177,2 +230,3 @@ offsets: { | ||
}; | ||
/** @internal */ | ||
button: { | ||
@@ -187,5 +241,5 @@ offsets: { | ||
/** | ||
* Grammarly editor public API. | ||
* | ||
* @public | ||
* | ||
* Grammarly editor public API | ||
*/ | ||
@@ -205,12 +259,35 @@ interface Editor { | ||
constructor(clientId?: string, config?: Partial<EditorConfig>); | ||
/** | ||
* Enhance a specific HTML element with Grammarly. | ||
* | ||
* @param element - Element to be enhanced | ||
* @param config - Optional {@link EditorConfig} | ||
* @returns {@link Editor} | ||
*/ | ||
withElement(element: HTMLElement, config?: Partial<EditorConfig>): Editor; | ||
/** | ||
* Enhance elements matching provided selectors with Grammarly. | ||
* | ||
* @param selectors - Selectors as provided to `querySelectorAll` | ||
*/ | ||
withQuerySelector(selectors: string): void; | ||
/** @internal */ | ||
withText(text: string): Editor; | ||
} | ||
/** @public */ | ||
/** | ||
* Initialize Grammarly and start using {@link EditorFactory} to connect editors. | ||
* | ||
* @param clientId - The {@link ClientId} for authentication | ||
* | ||
* @public | ||
*/ | ||
declare function init(clientId: string): Promise<EditorFactory>; | ||
/** @public */ | ||
/** | ||
* Initialize Grammarly. The {@link ClientId} must be passed another way. | ||
* | ||
* @public | ||
*/ | ||
declare function init(): Promise<void>; | ||
export { ClientId, Editor, EditorConfig, EditorFactory, GrammarlyDocumentConfig, GrammarlyFeaturesConfig, GrammarlyOptions, PluginDisableReason, SessionStats, SessionSuggestionBreakdown, TextStats, Time, init }; | ||
export { ClientId, Dialect, Domain, Editor, EditorConfig, EditorFactory, GrammarlyDocumentConfig, GrammarlyFeaturesConfig, GrammarlyOptions, PluginDisableReason, SessionStats, SessionSuggestionBreakdown, TextStats, Time, init }; |
@@ -1,69 +0,17 @@ | ||
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.body.appendChild(script); | ||
return script; | ||
} | ||
const promises = new Map(); | ||
const scripts = new Set(); | ||
async function loadScript(url, clientId) { | ||
if (promises.has(url)) { | ||
return await promises.get(url); | ||
} | ||
else if (scripts.has(url)) { | ||
return window.Grammarly; | ||
} | ||
else { | ||
const grammarlyPromise = new Promise((resolve, reject) => { | ||
if (typeof window === "undefined") { | ||
return resolve(null); | ||
} | ||
try { | ||
let script = findScript(url); | ||
if (script != null) { | ||
console.warn(`<script src="${url}" /> already exists.`); | ||
} | ||
else { | ||
script = injectScript(clientId != null ? `${url}?clientId=${clientId}` : url); | ||
} | ||
script.addEventListener("load", () => { | ||
if (window.Grammarly != null) { | ||
scripts.add(url); | ||
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); | ||
} | ||
}); | ||
promises.set(url, grammarlyPromise); | ||
return grammarlyPromise; | ||
} | ||
} | ||
// const [versionMajor, versionMinor] = "1.0.0-alpha.6".split("."); | ||
const resolvedVersion = "1.0.0-alpha.6"; // after prerelease, we will use: ${versionMajor}.${versionMinor} | ||
/** | ||
* Initialize Grammarly. | ||
* | ||
* @public | ||
* @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. | ||
*/ | ||
async function init(clientId) { | ||
const Grammarly = await loadScript(`${`https://js.grammarly.com/grammarly-editor-sdk@${resolvedVersion}`}`, clientId); | ||
if (clientId != null) { | ||
return new Grammarly.EditorFactory(clientId); | ||
} | ||
} | ||
export { init }; | ||
//# sourceMappingURL=index.esm.js.map | ||
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.body.appendChild(script);return script}const promises=new Map;const scripts=new Set;async function loadScript(url,clientId){if(promises.has(url)){return await promises.get(url)}else if(scripts.has(url)){return window.Grammarly}else{const grammarlyPromise=new Promise(((resolve,reject)=>{if(typeof window==="undefined"){return resolve(null)}try{let script=findScript(url);if(script!=null){console.warn(`<script src="${url}" /> already exists.`)}else{script=injectScript(clientId!=null?`${url}?clientId=${clientId}`:url)}script.addEventListener("load",(()=>{if(window.Grammarly!=null){scripts.add(url);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)}}));promises.set(url,grammarlyPromise);return grammarlyPromise}}const resolvedVersion="1.0.0-alpha.7";async function init(clientId){const Grammarly=await loadScript(`https://js.${"grammarly.com"}/grammarly-editor-sdk@${resolvedVersion}`,clientId);if(clientId!=null){return new Grammarly.EditorFactory(clientId)}}export{init}; |
@@ -1,2 +0,17 @@ | ||
!function(){"use strict";const n=new Map,t=new Set;async function r(r,e){if(n.has(r))return await n.get(r);if(t.has(r))return window.Grammarly;{const c=new Promise(((n,c)=>{if("undefined"==typeof window)return n(null);try{let i=function(n){return document.querySelectorAll(`script[src^="${n}"]`)[0]}(r);null!=i?console.warn(`<script src="${r}" /> already exists.`):i=function(n){const t=document.createElement("script");return t.src=n,document.body.appendChild(t),t}(null!=e?`${r}?clientId=${e}`:r),i.addEventListener("load",(()=>{null!=window.Grammarly?(t.add(r),n(window.Grammarly)):c(new Error("Grammarly not available"))})),i.addEventListener("error",(function(){c(new Error(`Failed to load ${r}`))}))}catch(n){return c(n)}}));return n.set(r,c),c}}async function e(n){const t=await r("https://js.grammarly.com/grammarly-editor-sdk@1.0.0-alpha.6",n);if(null!=n)return new t.EditorFactory(n)}const c=function(){const n=function(){if(document.currentScript instanceof HTMLScriptElement)return document.currentScript}();if(n){const t=n.src;if(t){const n=new URL(t).searchParams.get("clientId");if(null!=n)return n}const r=n.getAttribute("clientId");if(null!=r)return r}}();null!=c?e(c):e()}(); | ||
//# sourceMappingURL=index.iife.js.map | ||
!function(){"use strict"; | ||
/** | ||
* @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. | ||
*/const n=new Map,t=new Set;async function r(r,e){if(n.has(r))return await n.get(r);if(t.has(r))return window.Grammarly;{const c=new Promise(((n,c)=>{if("undefined"==typeof window)return n(null);try{let i=function(n){return document.querySelectorAll(`script[src^="${n}"]`)[0]}(r);null!=i?console.warn(`<script src="${r}" /> already exists.`):i=function(n){const t=document.createElement("script");return t.src=n,document.body.appendChild(t),t}(null!=e?`${r}?clientId=${e}`:r),i.addEventListener("load",(()=>{null!=window.Grammarly?(t.add(r),n(window.Grammarly)):c(new Error("Grammarly not available"))})),i.addEventListener("error",(function(){c(new Error(`Failed to load ${r}`))}))}catch(n){return c(n)}}));return n.set(r,c),c}}async function e(n){const t=await r("https://js.grammarly.com/grammarly-editor-sdk@1.0.0-alpha.7",n);if(null!=n)return new t.EditorFactory(n)}const c=function(){const n=function(){if(document.currentScript instanceof HTMLScriptElement)return document.currentScript}();if(n){const t=n.src;if(t){const n=new URL(t).searchParams.get("clientId");if(null!=n)return n}const r=n.getAttribute("clientId");if(null!=r)return r}}();null!=c?e(c):e()}(); |
@@ -1,73 +0,17 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
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.body.appendChild(script); | ||
return script; | ||
} | ||
const promises = new Map(); | ||
const scripts = new Set(); | ||
async function loadScript(url, clientId) { | ||
if (promises.has(url)) { | ||
return await promises.get(url); | ||
} | ||
else if (scripts.has(url)) { | ||
return window.Grammarly; | ||
} | ||
else { | ||
const grammarlyPromise = new Promise((resolve, reject) => { | ||
if (typeof window === "undefined") { | ||
return resolve(null); | ||
} | ||
try { | ||
let script = findScript(url); | ||
if (script != null) { | ||
console.warn(`<script src="${url}" /> already exists.`); | ||
} | ||
else { | ||
script = injectScript(clientId != null ? `${url}?clientId=${clientId}` : url); | ||
} | ||
script.addEventListener("load", () => { | ||
if (window.Grammarly != null) { | ||
scripts.add(url); | ||
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); | ||
} | ||
}); | ||
promises.set(url, grammarlyPromise); | ||
return grammarlyPromise; | ||
} | ||
} | ||
// const [versionMajor, versionMinor] = "1.0.0-alpha.6".split("."); | ||
const resolvedVersion = "1.0.0-alpha.6"; // after prerelease, we will use: ${versionMajor}.${versionMinor} | ||
"use strict"; | ||
/** | ||
* Initialize Grammarly. | ||
* | ||
* @public | ||
*/ | ||
async function init(clientId) { | ||
const Grammarly = await loadScript(`${`https://js.grammarly.com/grammarly-editor-sdk@${resolvedVersion}`}`, clientId); | ||
if (clientId != null) { | ||
return new Grammarly.EditorFactory(clientId); | ||
} | ||
} | ||
exports.init = init; | ||
//# sourceMappingURL=index.js.map | ||
* @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. | ||
*/Object.defineProperty(exports,"__esModule",{value:true});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.body.appendChild(script);return script}const promises=new Map;const scripts=new Set;async function loadScript(url,clientId){if(promises.has(url)){return await promises.get(url)}else if(scripts.has(url)){return window.Grammarly}else{const grammarlyPromise=new Promise(((resolve,reject)=>{if(typeof window==="undefined"){return resolve(null)}try{let script=findScript(url);if(script!=null){console.warn(`<script src="${url}" /> already exists.`)}else{script=injectScript(clientId!=null?`${url}?clientId=${clientId}`:url)}script.addEventListener("load",(()=>{if(window.Grammarly!=null){scripts.add(url);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)}}));promises.set(url,grammarlyPromise);return grammarlyPromise}}const resolvedVersion="1.0.0-alpha.7";async function init(clientId){const Grammarly=await loadScript(`https://js.${"grammarly.com"}/grammarly-editor-sdk@${resolvedVersion}`,clientId);if(clientId!=null){return new Grammarly.EditorFactory(clientId)}}exports.init=init; |
@@ -5,3 +5,3 @@ { | ||
"description": "Grammarly writing SDK for web editors", | ||
"version": "1.0.0-alpha.6", | ||
"version": "1.0.0-alpha.7", | ||
"main": "lib/index.js", | ||
@@ -11,2 +11,3 @@ "module": "lib/index.esm.js", | ||
"types": "lib/index.d.ts", | ||
"license": "Apache-2.0", | ||
"sideEffects": false, | ||
@@ -26,13 +27,8 @@ "publishConfig": { | ||
], | ||
"scripts": { | ||
"test": "jest", | ||
"test:size": "bundlesize", | ||
"docs:api": "api-extractor run --verbose" | ||
}, | ||
"devDependencies": { | ||
"@grammarly/plugin-core": "1.0.0-alpha.6", | ||
"@grammarly/plugin-editor": "1.0.0-alpha.6", | ||
"@microsoft/api-extractor": "^7.13.0", | ||
"@grammarly/plugin-core": "1.0.0-alpha.7", | ||
"@grammarly/plugin-editor": "1.0.0-alpha.7", | ||
"@microsoft/api-extractor": "^7.15.1", | ||
"@types/jest": "^26.0.22", | ||
"bundlesize": "^0.18.1", | ||
"bundlesize": "github:znck/bundlesize", | ||
"jest": "^26.6.3", | ||
@@ -47,3 +43,8 @@ "ts-jest": "^26.5.4" | ||
} | ||
] | ||
], | ||
"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
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
24843
7
0
338