diff --git a/src/main/ts/ScriptLoader2.ts b/src/main/ts/ScriptLoader2.ts index f507a7c4..adc58620 100644 --- a/src/main/ts/ScriptLoader2.ts +++ b/src/main/ts/ScriptLoader2.ts @@ -6,6 +6,7 @@ export interface ScriptItem { src: string; async?: boolean; defer?: boolean; + nonce?: string; } interface Id { @@ -20,6 +21,7 @@ const injectScriptTag = (doc: Document, item: ScriptItem & Id, handler: (id: str scriptTag.src = item.src; scriptTag.async = item.async ?? false; scriptTag.defer = item.defer ?? false; + scriptTag.nonce = item.nonce; const loadHandler = () => { scriptTag.removeEventListener('load', loadHandler); @@ -158,4 +160,4 @@ const createScriptLoader = () => { }; }; -export const ScriptLoader = createScriptLoader(); \ No newline at end of file +export const ScriptLoader = createScriptLoader(); diff --git a/src/main/ts/components/Editor.tsx b/src/main/ts/components/Editor.tsx index b9d3876d..bc6e412c 100644 --- a/src/main/ts/components/Editor.tsx +++ b/src/main/ts/components/Editor.tsx @@ -122,6 +122,7 @@ export interface IProps { async?: boolean; defer?: boolean; delay?: number; + nonce?: string; }; /** * @see {@link https://www.tiny.cloud/docs/tinymce/7/react-ref/#licenseKey React Tech Ref - licenseKey} @@ -294,16 +295,17 @@ export class Editor extends React.Component { private getScriptSources(): ScriptItem[] { const async = this.props.scriptLoading?.async; const defer = this.props.scriptLoading?.defer; + const nonce = this.props.scriptLoading?.nonce; if (this.props.tinymceScriptSrc !== undefined) { if (typeof this.props.tinymceScriptSrc === 'string') { - return [{ src: this.props.tinymceScriptSrc, async, defer }]; + return [{ src: this.props.tinymceScriptSrc, async, defer, nonce }]; } // multiple scripts can be specified which allows for hybrid mode return this.props.tinymceScriptSrc.map((item) => { if (typeof item === 'string') { // async does not make sense for multiple items unless // they are not dependent (which will be unlikely) - return { src: item, async, defer }; + return { src: item, async, defer, nonce }; } else { return item; } @@ -313,7 +315,7 @@ export class Editor extends React.Component { const channel = this.props.cloudChannel as Version; // `cloudChannel` is in `defaultProps`, so it's always defined. const apiKey = this.props.apiKey ? this.props.apiKey : 'no-api-key'; const cloudTinyJs = `https://cdn.tiny.cloud/1/${apiKey}/tinymce/${channel}/tinymce.min.js`; - return [{ src: cloudTinyJs, async, defer }]; + return [{ src: cloudTinyJs, async, defer, nonce }]; } private getInitialValue() {