Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tinymce/tinymce-react

Package Overview
Dependencies
Maintainers
2
Versions
365
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinymce/tinymce-react - npm Package Compare versions

Comparing version 3.7.0 to 3.8.0

3

CHANGELOG.md

@@ -0,1 +1,4 @@

## 3.8.0 (2020-10-08)
* Added types from TinyMCE 5.5 release.
## 3.7.0 (2020-09-28)

@@ -2,0 +5,0 @@ * Added `scriptLoading` prop with settings `async`, `defer` and `delay` to modify the loading behaviour of the TinyMCE script tag

16

lib/cjs/main/ts/components/Editor.d.ts

@@ -9,4 +9,5 @@ /**

import * as React from 'react';
import { EventHandler, IEvents } from '../Events';
import { IEvents } from '../Events';
import { IEditorPropTypes } from './EditorPropTypes';
import { Editor as TinyMCEEditor, RawEditorSettings } from 'tinymce';
export interface IProps {

@@ -17,10 +18,13 @@ apiKey: string;

initialValue: string;
onEditorChange: EventHandler<any>;
onEditorChange: (a: string, editor: TinyMCEEditor) => void;
value: string;
init: Record<string, any>;
init: RawEditorSettings & {
selector?: undefined;
target?: undefined;
};
outputFormat: 'html' | 'text';
tagName: string;
cloudChannel: string;
plugins: string | string[];
toolbar: string | string[];
plugins: NonNullable<RawEditorSettings['plugins']>;
toolbar: NonNullable<RawEditorSettings['toolbar']>;
disabled: boolean;

@@ -51,3 +55,3 @@ textareaName: string;

render(): React.ReactElement<{
ref: React.RefObject<Element>;
ref: React.RefObject<HTMLElement>;
id: string;

@@ -54,0 +58,0 @@ }, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)>;

@@ -43,4 +43,6 @@ "use strict";

function Editor(props) {
var _a, _b, _c;
var _this = _super.call(this, props) || this;
_this.handleEditorChange = function (evt) {
var _a;
var editor = _this.editor;

@@ -52,3 +54,3 @@ if (editor) {

if (Utils_1.isFunction(_this.props.onEditorChange)) {
_this.props.onEditorChange(_this.currentContent, editor);
_this.props.onEditorChange((_a = _this.currentContent) !== null && _a !== void 0 ? _a : '', editor);
}

@@ -72,3 +74,11 @@ }

_this.initialise = function () {
var finalInit = __assign(__assign({}, _this.props.init), { target: _this.elementRef.current, readonly: _this.props.disabled, inline: _this.inline, plugins: Utils_1.mergePlugins(_this.props.init && _this.props.init.plugins, _this.props.plugins), toolbar: _this.props.toolbar || (_this.props.init && _this.props.init.toolbar), setup: function (editor) {
var tinymce = TinyMCE_1.getTinymce();
if (!tinymce) {
throw new Error('tinymce should have been loaded into global scope');
}
var target = _this.elementRef.current;
if (!target) {
throw new Error('Expected target ref');
}
var finalInit = __assign(__assign({}, _this.props.init), { selector: undefined, target: target, readonly: _this.props.disabled, inline: _this.inline, plugins: Utils_1.mergePlugins(_this.props.init && _this.props.init.plugins, _this.props.plugins), toolbar: _this.props.toolbar || (_this.props.init && _this.props.init.toolbar), setup: function (editor) {
_this.editor = editor;

@@ -83,7 +93,7 @@ editor.on('init', _this.handleInit);

}
TinyMCE_1.getTinymce().init(finalInit);
tinymce.init(finalInit);
};
_this.id = _this.props.id || Utils_1.uuid('tiny-react');
_this.elementRef = React.createRef();
_this.inline = _this.props.inline ? _this.props.inline : _this.props.init && _this.props.init.inline;
_this.inline = (_c = (_a = _this.props.inline) !== null && _a !== void 0 ? _a : (_b = _this.props.init) === null || _b === void 0 ? void 0 : _b.inline) !== null && _c !== void 0 ? _c : false;
_this.boundHandlers = {};

@@ -93,5 +103,6 @@ return _this;

Editor.prototype.componentDidUpdate = function (prevProps) {
var _a;
if (this.editor && this.editor.initialized) {
Utils_1.bindHandlers(this.editor, this.props, this.boundHandlers);
this.currentContent = this.currentContent || this.editor.getContent({ format: this.props.outputFormat });
this.currentContent = (_a = this.currentContent) !== null && _a !== void 0 ? _a : this.editor.getContent({ format: this.props.outputFormat });
if (typeof this.props.value === 'string' && this.props.value !== prevProps.value && this.props.value !== this.currentContent) {

@@ -117,3 +128,3 @@ this.editor.setContent(this.props.value);

var editor = this.editor;
if (TinyMCE_1.getTinymce() !== null && editor) {
if (editor) {
editor.off('init', this.handleInit);

@@ -127,3 +138,3 @@ if (editor.initialized) {

}
TinyMCE_1.getTinymce().remove(editor);
editor.remove();
}

@@ -130,0 +141,0 @@ };

@@ -12,3 +12,3 @@ /**

export declare type CopyProps<T> = {
[P in keyof T]: PropTypes.Requireable<any>;
[P in keyof T]: PropTypes.Requireable<unknown>;
};

@@ -15,0 +15,0 @@ export declare type IEventPropTypes = CopyProps<IEvents>;

@@ -8,70 +8,73 @@ /**

*/
export declare type EventHandler<A> = (a: A, editor?: any) => any;
import { Editor as TinyMCEEditor, EditorEvent, Events } from 'tinymce';
export declare type EventHandler<A> = (a: EditorEvent<A>, editor: TinyMCEEditor) => unknown;
declare type EEventHandler<K extends keyof Events.EditorEventMap> = EventHandler<Events.EditorEventMap[K]>;
export interface INativeEvents {
onBeforePaste: EventHandler<ClipboardEvent>;
onBlur: EventHandler<FocusEvent>;
onClick: EventHandler<MouseEvent>;
onContextMenu: EventHandler<MouseEvent>;
onCopy: EventHandler<ClipboardEvent>;
onCut: EventHandler<ClipboardEvent>;
onDblclick: EventHandler<MouseEvent>;
onDrag: EventHandler<DragEvent>;
onDragDrop: EventHandler<DragEvent>;
onDragEnd: EventHandler<DragEvent>;
onDragGesture: EventHandler<DragEvent>;
onDragOver: EventHandler<DragEvent>;
onDrop: EventHandler<DragEvent>;
onFocus: EventHandler<FocusEvent>;
onFocusIn: EventHandler<FocusEvent>;
onFocusOut: EventHandler<FocusEvent>;
onKeyDown: EventHandler<KeyboardEvent>;
onKeyPress: EventHandler<KeyboardEvent>;
onKeyUp: EventHandler<KeyboardEvent>;
onMouseDown: EventHandler<MouseEvent>;
onMouseEnter: EventHandler<MouseEvent>;
onMouseLeave: EventHandler<MouseEvent>;
onMouseMove: EventHandler<MouseEvent>;
onMouseOut: EventHandler<MouseEvent>;
onMouseOver: EventHandler<MouseEvent>;
onMouseUp: EventHandler<MouseEvent>;
onPaste: EventHandler<ClipboardEvent>;
onSelectionChange: EventHandler<Event>;
onBeforePaste: EEventHandler<'beforepaste'>;
onBlur: EEventHandler<'blur'>;
onClick: EEventHandler<'click'>;
onContextMenu: EEventHandler<'contextmenu'>;
onCopy: EEventHandler<'copy'>;
onCut: EEventHandler<'cut'>;
onDblclick: EEventHandler<'dblclick'>;
onDrag: EEventHandler<'drag'>;
onDragDrop: EEventHandler<'dragdrop'>;
onDragEnd: EEventHandler<'dragend'>;
onDragGesture: EEventHandler<'draggesture'>;
onDragOver: EEventHandler<'dragover'>;
onDrop: EEventHandler<'drop'>;
onFocus: EEventHandler<'focus'>;
onFocusIn: EEventHandler<'focusin'>;
onFocusOut: EEventHandler<'focusout'>;
onKeyDown: EEventHandler<'keydown'>;
onKeyPress: EEventHandler<'keypress'>;
onKeyUp: EEventHandler<'keyup'>;
onMouseDown: EEventHandler<'mousedown'>;
onMouseEnter: EEventHandler<'mouseenter'>;
onMouseLeave: EEventHandler<'mouseleave'>;
onMouseMove: EEventHandler<'mousemove'>;
onMouseOut: EEventHandler<'mouseout'>;
onMouseOver: EEventHandler<'mouseover'>;
onMouseUp: EEventHandler<'mouseup'>;
onPaste: EEventHandler<'paste'>;
onSelectionChange: EEventHandler<'selectionchange'>;
}
export interface ITinyEvents {
onActivate: EventHandler<any>;
onAddUndo: EventHandler<any>;
onBeforeAddUndo: EventHandler<any>;
onBeforeExecCommand: EventHandler<any>;
onBeforeGetContent: EventHandler<any>;
onBeforeRenderUI: EventHandler<any>;
onBeforeSetContent: EventHandler<any>;
onChange: EventHandler<any>;
onClearUndos: EventHandler<any>;
onDeactivate: EventHandler<any>;
onDirty: EventHandler<any>;
onExecCommand: EventHandler<any>;
onGetContent: EventHandler<any>;
onHide: EventHandler<any>;
onInit: EventHandler<any>;
onLoadContent: EventHandler<any>;
onNodeChange: EventHandler<any>;
onPostProcess: EventHandler<any>;
onPostRender: EventHandler<any>;
onPreProcess: EventHandler<any>;
onProgressState: EventHandler<any>;
onRedo: EventHandler<any>;
onRemove: EventHandler<any>;
onReset: EventHandler<any>;
onSaveContent: EventHandler<any>;
onSetAttrib: EventHandler<any>;
onObjectResizeStart: EventHandler<any>;
onObjectResized: EventHandler<any>;
onObjectSelected: EventHandler<any>;
onSetContent: EventHandler<any>;
onShow: EventHandler<any>;
onSubmit: EventHandler<any>;
onUndo: EventHandler<any>;
onVisualAid: EventHandler<any>;
onActivate: EEventHandler<'activate'>;
onAddUndo: EEventHandler<'AddUndo'>;
onBeforeAddUndo: EEventHandler<'BeforeAddUndo'>;
onBeforeExecCommand: EEventHandler<'BeforeExecCommand'>;
onBeforeGetContent: EEventHandler<'BeforeGetContent'>;
onBeforeRenderUI: EventHandler<unknown>;
onBeforeSetContent: EEventHandler<'BeforeSetContent'>;
onChange: EventHandler<unknown>;
onClearUndos: EEventHandler<'ClearUndos'>;
onDeactivate: EEventHandler<'deactivate'>;
onDirty: EventHandler<unknown>;
onExecCommand: EEventHandler<'ExecCommand'>;
onGetContent: EEventHandler<'GetContent'>;
onHide: EventHandler<unknown>;
onInit: EEventHandler<'init'>;
onLoadContent: EEventHandler<'LoadContent'>;
onNodeChange: EEventHandler<'NodeChange'>;
onPostProcess: EventHandler<unknown>;
onPostRender: EEventHandler<'PostRender'>;
onPreProcess: EventHandler<unknown>;
onProgressState: EEventHandler<'ProgressState'>;
onRedo: EEventHandler<'Redo'>;
onRemove: EEventHandler<'remove'>;
onReset: EventHandler<unknown>;
onSaveContent: EventHandler<unknown>;
onSetAttrib: EventHandler<unknown>;
onObjectResizeStart: EEventHandler<'ObjectResizeStart'>;
onObjectResized: EEventHandler<'ObjectResized'>;
onObjectSelected: EEventHandler<'ObjectSelected'>;
onSetContent: EEventHandler<'SetContent'>;
onShow: EventHandler<unknown>;
onSubmit: EventHandler<unknown>;
onUndo: EEventHandler<'Undo'>;
onVisualAid: EventHandler<unknown>;
}
export interface IEvents extends INativeEvents, ITinyEvents {
}
export {};

@@ -8,3 +8,4 @@ /**

*/
declare const getTinymce: () => any;
import { TinyMCE as TinyMCEGlobal } from 'tinymce';
declare const getTinymce: () => TinyMCEGlobal | null;
export { getTinymce };

@@ -9,6 +9,7 @@ /**

import { IAllProps } from './components/Editor';
export declare const isFunction: (x: any) => x is Function;
export declare const bindHandlers: (editor: any, props: Partial<IAllProps>, boundHandlers: Record<string, Function>) => void;
import { Editor as TinyMCEEditor, EditorEvent } from 'tinymce';
export declare const isFunction: (x: unknown) => x is Function;
export declare const bindHandlers: (editor: TinyMCEEditor, props: Partial<IAllProps>, boundHandlers: Record<string, (event: EditorEvent<unknown>) => unknown>) => void;
export declare const uuid: (prefix: string) => string;
export declare const isTextarea: (element: Element | null) => element is HTMLTextAreaElement;
export declare const mergePlugins: (initPlugins: string | string[], inputPlugins?: string | string[] | undefined) => string[];
export declare const mergePlugins: (initPlugins: string | string[] | undefined, inputPlugins: string | string[] | undefined) => string[];

@@ -40,4 +40,3 @@ "use strict";

exports.uuid = function (prefix) {
var date = new Date();
var time = date.getTime();
var time = Date.now();
var random = Math.floor(Math.random() * 1000000000);

@@ -44,0 +43,0 @@ unique++;

import { Chain } from '@ephox/agar';
import * as React from 'react';
import { Editor, IAllProps } from '../../../main/ts/components/Editor';
import { Editor as TinyMCEEditor } from 'tinymce';
export interface Context {
DOMNode: Element;
editor: any;
DOMNode: HTMLElement;
editor: TinyMCEEditor;
ref: React.RefObject<Editor>;
}
declare const cRender: (props: IAllProps) => Chain<Context, Context>;
declare const cRender: (props: IAllProps) => Chain<unknown, Context>;
declare const cReRender: (props: IAllProps) => Chain<Context, Context>;
declare const cRemove: Chain<unknown, unknown>;
declare const cNamedChainDirect: (name: keyof Context) => Chain<Record<string, any>, Record<string, any>>;
declare const cDOMNode: (chain: Chain<any, any>) => Chain<unknown, any>;
declare const cEditor: (chain: Chain<any, any>) => Chain<unknown, any>;
export { cRender, cReRender, cRemove, cNamedChainDirect, cDOMNode, cEditor };
declare const cDOMNode: (chain: Chain<Context['DOMNode'], unknown>) => Chain<Context, Context>;
declare const cEditor: (chain: Chain<Context['editor'], unknown>) => Chain<Context, Context>;
export { cRender, cReRender, cRemove, cDOMNode, cEditor };

@@ -14,5 +14,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.cEditor = exports.cDOMNode = exports.cNamedChainDirect = exports.cRemove = exports.cReRender = exports.cRender = void 0;
exports.cEditor = exports.cDOMNode = exports.cRemove = exports.cReRender = exports.cRender = void 0;
var agar_1 = require("@ephox/agar");
var katamari_1 = require("@ephox/katamari");
var sugar_1 = require("@ephox/sugar");
var React = require("react");

@@ -22,3 +23,3 @@ var ReactDOM = require("react-dom");

var getRoot = function () {
return katamari_1.Option.from(document.getElementById('root')).getOrThunk(function () {
return katamari_1.Optional.from(document.getElementById('root')).getOrThunk(function () {
var root = document.createElement('div');

@@ -39,5 +40,8 @@ root.id = 'root';

setTimeout(function () {
katamari_1.Option.from(ref.current)
katamari_1.Optional.from(ref.current)
.map(ReactDOM.findDOMNode)
.filter(function (val) { return val instanceof Element; })
.bind(katamari_1.Optional.from)
.map(sugar_1.SugarElement.fromDom)
.filter(sugar_1.SugarNode.isHTMLElement)
.map(function (val) { return val.dom; })
.fold(function () { return die('Could not find DOMNode'); }, function (DOMNode) {

@@ -78,3 +82,2 @@ next({

var cNamedChainDirect = function (name) { return agar_1.NamedChain.direct(agar_1.NamedChain.inputName(), agar_1.Chain.mapper(function (res) { return res[name]; }), name); };
exports.cNamedChainDirect = cNamedChainDirect;
var cDOMNode = function (chain) {

@@ -81,0 +84,0 @@ return agar_1.NamedChain.asChain([

import { Chain } from '@ephox/agar';
import { EventHandler } from 'src/main/ts/Events';
import { Editor as TinyMCEEditor } from 'tinymce';
interface EventHandlerArgs<T> {
editorEvent: T;
editor: any;
editor: TinyMCEEditor;
}
declare type HandlerType<A> = (a: A, editor: TinyMCEEditor) => unknown;
declare const EventStore: () => {
cEach: (name: string, assertState: (state: EventHandlerArgs<any>[]) => void) => Chain<any, any>;
createHandler: <T = any>(name: string) => EventHandler<T>;
cEach: <T>(name: string, assertState: (state: EventHandlerArgs<T>[]) => void) => Chain<any, any>;
createHandler: <T_1>(name: string) => HandlerType<T_1>;
cClearState: Chain<unknown, unknown>;
};
export { EventStore };
declare const cSetContent: (content: string) => Chain<TinyMCEEditor, TinyMCEEditor>;
declare const cAssertContent: (content: string) => Chain<TinyMCEEditor, TinyMCEEditor>;
export { EventStore, cSetContent, cAssertContent };

@@ -14,5 +14,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.EventStore = void 0;
exports.cAssertContent = exports.cSetContent = exports.EventStore = void 0;
var agar_1 = require("@ephox/agar");
var katamari_1 = require("@ephox/katamari");
var mcagar_1 = require("@ephox/mcagar");
var EventStore = function () {

@@ -48,1 +49,6 @@ var state = katamari_1.Cell({});

exports.EventStore = EventStore;
// casting needed due to fake types used in mcagar
var cSetContent = function (content) { return mcagar_1.ApiChains.cSetContent(content); };
exports.cSetContent = cSetContent;
var cAssertContent = function (content) { return mcagar_1.ApiChains.cAssertContent(content); };
exports.cAssertContent = cAssertContent;

@@ -6,3 +6,2 @@ "use strict";

var Loader_1 = require("../alien/Loader");
var mcagar_1 = require("@ephox/mcagar");
var miniature_1 = require("@tinymce/miniature");

@@ -13,3 +12,7 @@ var TinyMCE_1 = require("../../../main/ts/TinyMCE");

var isEditor = function (val) {
return val instanceof TinyMCE_1.getTinymce().Editor;
var tinymce = TinyMCE_1.getTinymce();
if (!tinymce) {
return false;
}
return val instanceof tinymce.Editor;
};

@@ -23,3 +26,3 @@ var eventStore = TestHelpers_1.EventStore();

}),
Loader_1.cEditor(mcagar_1.ApiChains.cSetContent('<p>Initial Content</p>')),
Loader_1.cEditor(TestHelpers_1.cSetContent('<p>Initial Content</p>')),
// tinymce native event

@@ -42,4 +45,4 @@ eventStore.cEach('onSetContent', function (events) {

}),
Loader_1.cEditor(mcagar_1.ApiChains.cSetContent('<p>Initial Content</p>')),
Loader_1.cEditor(mcagar_1.ApiChains.cSetContent('<p>Initial Content</p>')),
Loader_1.cEditor(TestHelpers_1.cSetContent('<p>Initial Content</p>')),
Loader_1.cEditor(TestHelpers_1.cSetContent('<p>Initial Content</p>')),
eventStore.cEach('onEditorChange', function (events) {

@@ -54,4 +57,4 @@ agar_1.Assertions.assertEq('onEditorChange should have been fired once', 1, events.length);

Loader_1.cReRender({ onSetContent: eventStore.createHandler('onSetContent') }),
Loader_1.cEditor(mcagar_1.ApiChains.cAssertContent('<p>Initial Content</p>')),
Loader_1.cEditor(mcagar_1.ApiChains.cSetContent('<p>New Content</p>')),
Loader_1.cEditor(TestHelpers_1.cAssertContent('<p>Initial Content</p>')),
Loader_1.cEditor(TestHelpers_1.cSetContent('<p>New Content</p>')),
eventStore.cEach('onSetContent', function (events) {

@@ -65,5 +68,5 @@ agar_1.Assertions.assertEq('Should have bound handler, hence new content', '<p>New Content</p>', events[0].editorEvent.content);

Loader_1.cRender({ onSetContent: eventStore.createHandler('InitialHandler') }),
Loader_1.cEditor(mcagar_1.ApiChains.cSetContent('<p>Initial Content</p>')),
Loader_1.cEditor(TestHelpers_1.cSetContent('<p>Initial Content</p>')),
Loader_1.cReRender({ onSetContent: eventStore.createHandler('NewHandler') }),
Loader_1.cEditor(mcagar_1.ApiChains.cSetContent('<p>New Content</p>')),
Loader_1.cEditor(TestHelpers_1.cSetContent('<p>New Content</p>')),
eventStore.cEach('InitialHandler', function (events) {

@@ -70,0 +73,0 @@ agar_1.Assertions.assertEq('Initial handler should have been unbound, hence initial content', '<p>Initial Content</p>', events[0].editorEvent.content);

@@ -5,5 +5,5 @@ "use strict";

var bedrock_client_1 = require("@ephox/bedrock-client");
var mcagar_1 = require("@ephox/mcagar");
var miniature_1 = require("@tinymce/miniature");
var Loader_1 = require("../alien/Loader");
var TestHelpers_1 = require("../alien/TestHelpers");
bedrock_client_1.UnitTest.asynctest('Editor.test', function (success, failure) {

@@ -73,5 +73,5 @@ var cAssertProperty = function (propName, expected) {

Loader_1.cRender({ value: '<p>Initial Value</p>' }),
Loader_1.cEditor(mcagar_1.ApiChains.cAssertContent('<p>Initial Value</p>')),
Loader_1.cEditor(TestHelpers_1.cAssertContent('<p>Initial Value</p>')),
Loader_1.cReRender({ value: '<p>New Value</p>' }),
Loader_1.cEditor(mcagar_1.ApiChains.cAssertContent('<p>New Value</p>')),
Loader_1.cEditor(TestHelpers_1.cAssertContent('<p>New Value</p>')),
Loader_1.cRemove

@@ -78,0 +78,0 @@ ])),

@@ -15,3 +15,3 @@ "use strict";

var hasTinymceUri = function (attrName) { return function (elm) {
return sugar_1.Attr.getOpt(elm, attrName).exists(function (src) { return katamari_1.Strings.contains(src, 'tinymce'); });
return sugar_1.Attribute.getOpt(elm, attrName).exists(function (src) { return katamari_1.Strings.contains(src, 'tinymce'); });
}; };

@@ -18,0 +18,0 @@ var elements = katamari_1.Arr.flatten([

@@ -9,4 +9,5 @@ /**

import * as React from 'react';
import { EventHandler, IEvents } from '../Events';
import { IEvents } from '../Events';
import { IEditorPropTypes } from './EditorPropTypes';
import { Editor as TinyMCEEditor, RawEditorSettings } from 'tinymce';
export interface IProps {

@@ -17,10 +18,13 @@ apiKey: string;

initialValue: string;
onEditorChange: EventHandler<any>;
onEditorChange: (a: string, editor: TinyMCEEditor) => void;
value: string;
init: Record<string, any>;
init: RawEditorSettings & {
selector?: undefined;
target?: undefined;
};
outputFormat: 'html' | 'text';
tagName: string;
cloudChannel: string;
plugins: string | string[];
toolbar: string | string[];
plugins: NonNullable<RawEditorSettings['plugins']>;
toolbar: NonNullable<RawEditorSettings['toolbar']>;
disabled: boolean;

@@ -51,3 +55,3 @@ textareaName: string;

render(): React.ReactElement<{
ref: React.RefObject<Element>;
ref: React.RefObject<HTMLElement>;
id: string;

@@ -54,0 +58,0 @@ }, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)>;

@@ -40,4 +40,6 @@ /**

function Editor(props) {
var _a, _b, _c;
var _this = _super.call(this, props) || this;
_this.handleEditorChange = function (evt) {
var _a;
var editor = _this.editor;

@@ -49,3 +51,3 @@ if (editor) {

if (isFunction(_this.props.onEditorChange)) {
_this.props.onEditorChange(_this.currentContent, editor);
_this.props.onEditorChange((_a = _this.currentContent) !== null && _a !== void 0 ? _a : '', editor);
}

@@ -69,3 +71,11 @@ }

_this.initialise = function () {
var finalInit = __assign(__assign({}, _this.props.init), { target: _this.elementRef.current, readonly: _this.props.disabled, inline: _this.inline, plugins: mergePlugins(_this.props.init && _this.props.init.plugins, _this.props.plugins), toolbar: _this.props.toolbar || (_this.props.init && _this.props.init.toolbar), setup: function (editor) {
var tinymce = getTinymce();
if (!tinymce) {
throw new Error('tinymce should have been loaded into global scope');
}
var target = _this.elementRef.current;
if (!target) {
throw new Error('Expected target ref');
}
var finalInit = __assign(__assign({}, _this.props.init), { selector: undefined, target: target, readonly: _this.props.disabled, inline: _this.inline, plugins: mergePlugins(_this.props.init && _this.props.init.plugins, _this.props.plugins), toolbar: _this.props.toolbar || (_this.props.init && _this.props.init.toolbar), setup: function (editor) {
_this.editor = editor;

@@ -80,7 +90,7 @@ editor.on('init', _this.handleInit);

}
getTinymce().init(finalInit);
tinymce.init(finalInit);
};
_this.id = _this.props.id || uuid('tiny-react');
_this.elementRef = React.createRef();
_this.inline = _this.props.inline ? _this.props.inline : _this.props.init && _this.props.init.inline;
_this.inline = (_c = (_a = _this.props.inline) !== null && _a !== void 0 ? _a : (_b = _this.props.init) === null || _b === void 0 ? void 0 : _b.inline) !== null && _c !== void 0 ? _c : false;
_this.boundHandlers = {};

@@ -90,5 +100,6 @@ return _this;

Editor.prototype.componentDidUpdate = function (prevProps) {
var _a;
if (this.editor && this.editor.initialized) {
bindHandlers(this.editor, this.props, this.boundHandlers);
this.currentContent = this.currentContent || this.editor.getContent({ format: this.props.outputFormat });
this.currentContent = (_a = this.currentContent) !== null && _a !== void 0 ? _a : this.editor.getContent({ format: this.props.outputFormat });
if (typeof this.props.value === 'string' && this.props.value !== prevProps.value && this.props.value !== this.currentContent) {

@@ -114,3 +125,3 @@ this.editor.setContent(this.props.value);

var editor = this.editor;
if (getTinymce() !== null && editor) {
if (editor) {
editor.off('init', this.handleInit);

@@ -124,3 +135,3 @@ if (editor.initialized) {

}
getTinymce().remove(editor);
editor.remove();
}

@@ -127,0 +138,0 @@ };

@@ -12,3 +12,3 @@ /**

export declare type CopyProps<T> = {
[P in keyof T]: PropTypes.Requireable<any>;
[P in keyof T]: PropTypes.Requireable<unknown>;
};

@@ -15,0 +15,0 @@ export declare type IEventPropTypes = CopyProps<IEvents>;

@@ -8,70 +8,73 @@ /**

*/
export declare type EventHandler<A> = (a: A, editor?: any) => any;
import { Editor as TinyMCEEditor, EditorEvent, Events } from 'tinymce';
export declare type EventHandler<A> = (a: EditorEvent<A>, editor: TinyMCEEditor) => unknown;
declare type EEventHandler<K extends keyof Events.EditorEventMap> = EventHandler<Events.EditorEventMap[K]>;
export interface INativeEvents {
onBeforePaste: EventHandler<ClipboardEvent>;
onBlur: EventHandler<FocusEvent>;
onClick: EventHandler<MouseEvent>;
onContextMenu: EventHandler<MouseEvent>;
onCopy: EventHandler<ClipboardEvent>;
onCut: EventHandler<ClipboardEvent>;
onDblclick: EventHandler<MouseEvent>;
onDrag: EventHandler<DragEvent>;
onDragDrop: EventHandler<DragEvent>;
onDragEnd: EventHandler<DragEvent>;
onDragGesture: EventHandler<DragEvent>;
onDragOver: EventHandler<DragEvent>;
onDrop: EventHandler<DragEvent>;
onFocus: EventHandler<FocusEvent>;
onFocusIn: EventHandler<FocusEvent>;
onFocusOut: EventHandler<FocusEvent>;
onKeyDown: EventHandler<KeyboardEvent>;
onKeyPress: EventHandler<KeyboardEvent>;
onKeyUp: EventHandler<KeyboardEvent>;
onMouseDown: EventHandler<MouseEvent>;
onMouseEnter: EventHandler<MouseEvent>;
onMouseLeave: EventHandler<MouseEvent>;
onMouseMove: EventHandler<MouseEvent>;
onMouseOut: EventHandler<MouseEvent>;
onMouseOver: EventHandler<MouseEvent>;
onMouseUp: EventHandler<MouseEvent>;
onPaste: EventHandler<ClipboardEvent>;
onSelectionChange: EventHandler<Event>;
onBeforePaste: EEventHandler<'beforepaste'>;
onBlur: EEventHandler<'blur'>;
onClick: EEventHandler<'click'>;
onContextMenu: EEventHandler<'contextmenu'>;
onCopy: EEventHandler<'copy'>;
onCut: EEventHandler<'cut'>;
onDblclick: EEventHandler<'dblclick'>;
onDrag: EEventHandler<'drag'>;
onDragDrop: EEventHandler<'dragdrop'>;
onDragEnd: EEventHandler<'dragend'>;
onDragGesture: EEventHandler<'draggesture'>;
onDragOver: EEventHandler<'dragover'>;
onDrop: EEventHandler<'drop'>;
onFocus: EEventHandler<'focus'>;
onFocusIn: EEventHandler<'focusin'>;
onFocusOut: EEventHandler<'focusout'>;
onKeyDown: EEventHandler<'keydown'>;
onKeyPress: EEventHandler<'keypress'>;
onKeyUp: EEventHandler<'keyup'>;
onMouseDown: EEventHandler<'mousedown'>;
onMouseEnter: EEventHandler<'mouseenter'>;
onMouseLeave: EEventHandler<'mouseleave'>;
onMouseMove: EEventHandler<'mousemove'>;
onMouseOut: EEventHandler<'mouseout'>;
onMouseOver: EEventHandler<'mouseover'>;
onMouseUp: EEventHandler<'mouseup'>;
onPaste: EEventHandler<'paste'>;
onSelectionChange: EEventHandler<'selectionchange'>;
}
export interface ITinyEvents {
onActivate: EventHandler<any>;
onAddUndo: EventHandler<any>;
onBeforeAddUndo: EventHandler<any>;
onBeforeExecCommand: EventHandler<any>;
onBeforeGetContent: EventHandler<any>;
onBeforeRenderUI: EventHandler<any>;
onBeforeSetContent: EventHandler<any>;
onChange: EventHandler<any>;
onClearUndos: EventHandler<any>;
onDeactivate: EventHandler<any>;
onDirty: EventHandler<any>;
onExecCommand: EventHandler<any>;
onGetContent: EventHandler<any>;
onHide: EventHandler<any>;
onInit: EventHandler<any>;
onLoadContent: EventHandler<any>;
onNodeChange: EventHandler<any>;
onPostProcess: EventHandler<any>;
onPostRender: EventHandler<any>;
onPreProcess: EventHandler<any>;
onProgressState: EventHandler<any>;
onRedo: EventHandler<any>;
onRemove: EventHandler<any>;
onReset: EventHandler<any>;
onSaveContent: EventHandler<any>;
onSetAttrib: EventHandler<any>;
onObjectResizeStart: EventHandler<any>;
onObjectResized: EventHandler<any>;
onObjectSelected: EventHandler<any>;
onSetContent: EventHandler<any>;
onShow: EventHandler<any>;
onSubmit: EventHandler<any>;
onUndo: EventHandler<any>;
onVisualAid: EventHandler<any>;
onActivate: EEventHandler<'activate'>;
onAddUndo: EEventHandler<'AddUndo'>;
onBeforeAddUndo: EEventHandler<'BeforeAddUndo'>;
onBeforeExecCommand: EEventHandler<'BeforeExecCommand'>;
onBeforeGetContent: EEventHandler<'BeforeGetContent'>;
onBeforeRenderUI: EventHandler<unknown>;
onBeforeSetContent: EEventHandler<'BeforeSetContent'>;
onChange: EventHandler<unknown>;
onClearUndos: EEventHandler<'ClearUndos'>;
onDeactivate: EEventHandler<'deactivate'>;
onDirty: EventHandler<unknown>;
onExecCommand: EEventHandler<'ExecCommand'>;
onGetContent: EEventHandler<'GetContent'>;
onHide: EventHandler<unknown>;
onInit: EEventHandler<'init'>;
onLoadContent: EEventHandler<'LoadContent'>;
onNodeChange: EEventHandler<'NodeChange'>;
onPostProcess: EventHandler<unknown>;
onPostRender: EEventHandler<'PostRender'>;
onPreProcess: EventHandler<unknown>;
onProgressState: EEventHandler<'ProgressState'>;
onRedo: EEventHandler<'Redo'>;
onRemove: EEventHandler<'remove'>;
onReset: EventHandler<unknown>;
onSaveContent: EventHandler<unknown>;
onSetAttrib: EventHandler<unknown>;
onObjectResizeStart: EEventHandler<'ObjectResizeStart'>;
onObjectResized: EEventHandler<'ObjectResized'>;
onObjectSelected: EEventHandler<'ObjectSelected'>;
onSetContent: EEventHandler<'SetContent'>;
onShow: EventHandler<unknown>;
onSubmit: EventHandler<unknown>;
onUndo: EEventHandler<'Undo'>;
onVisualAid: EventHandler<unknown>;
}
export interface IEvents extends INativeEvents, ITinyEvents {
}
export {};

@@ -8,3 +8,4 @@ /**

*/
declare const getTinymce: () => any;
import { TinyMCE as TinyMCEGlobal } from 'tinymce';
declare const getTinymce: () => TinyMCEGlobal | null;
export { getTinymce };

@@ -9,6 +9,7 @@ /**

import { IAllProps } from './components/Editor';
export declare const isFunction: (x: any) => x is Function;
export declare const bindHandlers: (editor: any, props: Partial<IAllProps>, boundHandlers: Record<string, Function>) => void;
import { Editor as TinyMCEEditor, EditorEvent } from 'tinymce';
export declare const isFunction: (x: unknown) => x is Function;
export declare const bindHandlers: (editor: TinyMCEEditor, props: Partial<IAllProps>, boundHandlers: Record<string, (event: EditorEvent<unknown>) => unknown>) => void;
export declare const uuid: (prefix: string) => string;
export declare const isTextarea: (element: Element | null) => element is HTMLTextAreaElement;
export declare const mergePlugins: (initPlugins: string | string[], inputPlugins?: string | string[] | undefined) => string[];
export declare const mergePlugins: (initPlugins: string | string[] | undefined, inputPlugins: string | string[] | undefined) => string[];

@@ -37,4 +37,3 @@ /**

export var uuid = function (prefix) {
var date = new Date();
var time = date.getTime();
var time = Date.now();
var random = Math.floor(Math.random() * 1000000000);

@@ -41,0 +40,0 @@ unique++;

import { Chain } from '@ephox/agar';
import * as React from 'react';
import { Editor, IAllProps } from '../../../main/ts/components/Editor';
import { Editor as TinyMCEEditor } from 'tinymce';
export interface Context {
DOMNode: Element;
editor: any;
DOMNode: HTMLElement;
editor: TinyMCEEditor;
ref: React.RefObject<Editor>;
}
declare const cRender: (props: IAllProps) => Chain<Context, Context>;
declare const cRender: (props: IAllProps) => Chain<unknown, Context>;
declare const cReRender: (props: IAllProps) => Chain<Context, Context>;
declare const cRemove: Chain<unknown, unknown>;
declare const cNamedChainDirect: (name: keyof Context) => Chain<Record<string, any>, Record<string, any>>;
declare const cDOMNode: (chain: Chain<any, any>) => Chain<unknown, any>;
declare const cEditor: (chain: Chain<any, any>) => Chain<unknown, any>;
export { cRender, cReRender, cRemove, cNamedChainDirect, cDOMNode, cEditor };
declare const cDOMNode: (chain: Chain<Context['DOMNode'], unknown>) => Chain<Context, Context>;
declare const cEditor: (chain: Chain<Context['editor'], unknown>) => Chain<Context, Context>;
export { cRender, cReRender, cRemove, cDOMNode, cEditor };

@@ -13,3 +13,4 @@ var __assign = (this && this.__assign) || function () {

import { Chain, NamedChain } from '@ephox/agar';
import { Fun, Option } from '@ephox/katamari';
import { Fun, Optional } from '@ephox/katamari';
import { SugarElement, SugarNode } from '@ephox/sugar';
import * as React from 'react';

@@ -19,3 +20,3 @@ import * as ReactDOM from 'react-dom';

var getRoot = function () {
return Option.from(document.getElementById('root')).getOrThunk(function () {
return Optional.from(document.getElementById('root')).getOrThunk(function () {
var root = document.createElement('div');

@@ -36,5 +37,8 @@ root.id = 'root';

setTimeout(function () {
Option.from(ref.current)
Optional.from(ref.current)
.map(ReactDOM.findDOMNode)
.filter(function (val) { return val instanceof Element; })
.bind(Optional.from)
.map(SugarElement.fromDom)
.filter(SugarNode.isHTMLElement)
.map(function (val) { return val.dom; })
.fold(function () { return die('Could not find DOMNode'); }, function (DOMNode) {

@@ -86,2 +90,2 @@ next({

};
export { cRender, cReRender, cRemove, cNamedChainDirect, cDOMNode, cEditor };
export { cRender, cReRender, cRemove, cDOMNode, cEditor };
import { Chain } from '@ephox/agar';
import { EventHandler } from 'src/main/ts/Events';
import { Editor as TinyMCEEditor } from 'tinymce';
interface EventHandlerArgs<T> {
editorEvent: T;
editor: any;
editor: TinyMCEEditor;
}
declare type HandlerType<A> = (a: A, editor: TinyMCEEditor) => unknown;
declare const EventStore: () => {
cEach: (name: string, assertState: (state: EventHandlerArgs<any>[]) => void) => Chain<any, any>;
createHandler: <T = any>(name: string) => EventHandler<T>;
cEach: <T>(name: string, assertState: (state: EventHandlerArgs<T>[]) => void) => Chain<any, any>;
createHandler: <T_1>(name: string) => HandlerType<T_1>;
cClearState: Chain<unknown, unknown>;
};
export { EventStore };
declare const cSetContent: (content: string) => Chain<TinyMCEEditor, TinyMCEEditor>;
declare const cAssertContent: (content: string) => Chain<TinyMCEEditor, TinyMCEEditor>;
export { EventStore, cSetContent, cAssertContent };

@@ -14,2 +14,3 @@ var __assign = (this && this.__assign) || function () {

import { Cell, Obj } from '@ephox/katamari';
import { ApiChains } from '@ephox/mcagar';
var EventStore = function () {

@@ -44,2 +45,5 @@ var state = Cell({});

};
export { EventStore };
// casting needed due to fake types used in mcagar
var cSetContent = function (content) { return ApiChains.cSetContent(content); };
var cAssertContent = function (content) { return ApiChains.cAssertContent(content); };
export { EventStore, cSetContent, cAssertContent };
import { Assertions, Chain, Logger, Pipeline, GeneralSteps } from '@ephox/agar';
import { UnitTest } from '@ephox/bedrock-client';
import { cRemove, cRender, cEditor, cReRender } from '../alien/Loader';
import { ApiChains } from '@ephox/mcagar';
import { VersionLoader } from '@tinymce/miniature';
import { getTinymce } from '../../../main/ts/TinyMCE';
import { EventStore } from '../alien/TestHelpers';
import { EventStore, cAssertContent, cSetContent } from '../alien/TestHelpers';
UnitTest.asynctest('EditorBehaviorTest', function (success, failure) {
var isEditor = function (val) {
return val instanceof getTinymce().Editor;
var tinymce = getTinymce();
if (!tinymce) {
return false;
}
return val instanceof tinymce.Editor;
};

@@ -19,3 +22,3 @@ var eventStore = EventStore();

}),
cEditor(ApiChains.cSetContent('<p>Initial Content</p>')),
cEditor(cSetContent('<p>Initial Content</p>')),
// tinymce native event

@@ -38,4 +41,4 @@ eventStore.cEach('onSetContent', function (events) {

}),
cEditor(ApiChains.cSetContent('<p>Initial Content</p>')),
cEditor(ApiChains.cSetContent('<p>Initial Content</p>')),
cEditor(cSetContent('<p>Initial Content</p>')),
cEditor(cSetContent('<p>Initial Content</p>')),
eventStore.cEach('onEditorChange', function (events) {

@@ -50,4 +53,4 @@ Assertions.assertEq('onEditorChange should have been fired once', 1, events.length);

cReRender({ onSetContent: eventStore.createHandler('onSetContent') }),
cEditor(ApiChains.cAssertContent('<p>Initial Content</p>')),
cEditor(ApiChains.cSetContent('<p>New Content</p>')),
cEditor(cAssertContent('<p>Initial Content</p>')),
cEditor(cSetContent('<p>New Content</p>')),
eventStore.cEach('onSetContent', function (events) {

@@ -61,5 +64,5 @@ Assertions.assertEq('Should have bound handler, hence new content', '<p>New Content</p>', events[0].editorEvent.content);

cRender({ onSetContent: eventStore.createHandler('InitialHandler') }),
cEditor(ApiChains.cSetContent('<p>Initial Content</p>')),
cEditor(cSetContent('<p>Initial Content</p>')),
cReRender({ onSetContent: eventStore.createHandler('NewHandler') }),
cEditor(ApiChains.cSetContent('<p>New Content</p>')),
cEditor(cSetContent('<p>New Content</p>')),
eventStore.cEach('InitialHandler', function (events) {

@@ -66,0 +69,0 @@ Assertions.assertEq('Initial handler should have been unbound, hence initial content', '<p>Initial Content</p>', events[0].editorEvent.content);

import { Assertions, Chain, GeneralSteps, Logger, Pipeline } from '@ephox/agar';
import { UnitTest } from '@ephox/bedrock-client';
import { ApiChains } from '@ephox/mcagar';
import { VersionLoader } from '@tinymce/miniature';
import { cRemove, cRender, cDOMNode, cEditor, cReRender } from '../alien/Loader';
import { cAssertContent } from '../alien/TestHelpers';
UnitTest.asynctest('Editor.test', function (success, failure) {

@@ -70,5 +70,5 @@ var cAssertProperty = function (propName, expected) {

cRender({ value: '<p>Initial Value</p>' }),
cEditor(ApiChains.cAssertContent('<p>Initial Value</p>')),
cEditor(cAssertContent('<p>Initial Value</p>')),
cReRender({ value: '<p>New Value</p>' }),
cEditor(ApiChains.cAssertContent('<p>New Value</p>')),
cEditor(cAssertContent('<p>New Value</p>')),
cRemove

@@ -75,0 +75,0 @@ ])),

import { Chain, Log, Pipeline, Assertions } from '@ephox/agar';
import { UnitTest } from '@ephox/bedrock-client';
import { Arr, Strings, Global } from '@ephox/katamari';
import { SelectorFilter, Attr, Remove } from '@ephox/sugar';
import { SelectorFilter, Attribute, Remove } from '@ephox/sugar';
import { ScriptLoader } from '../../../main/ts/ScriptLoader';

@@ -13,3 +13,3 @@ import { cRemove, cRender } from '../alien/Loader';

var hasTinymceUri = function (attrName) { return function (elm) {
return Attr.getOpt(elm, attrName).exists(function (src) { return Strings.contains(src, 'tinymce'); });
return Attribute.getOpt(elm, attrName).exists(function (src) { return Strings.contains(src, 'tinymce'); });
}; };

@@ -16,0 +16,0 @@ var elements = Arr.flatten([

{
"name": "@tinymce/tinymce-react",
"version": "3.7.0",
"version": "3.8.0",
"description": "Official TinyMCE React Component",

@@ -31,3 +31,4 @@ "repository": {

"dependencies": {
"prop-types": "^15.6.2"
"prop-types": "^15.6.2",
"tinymce": "^5.5.0"
},

@@ -40,6 +41,7 @@ "peerDependencies": {

"@babel/core": "^7.11.6",
"@ephox/agar": "^4.17.2",
"@ephox/agar": "^5.0.1",
"@ephox/bedrock-client": "^9.6.1",
"@ephox/bedrock-server": "^9.6.3",
"@ephox/mcagar": "^4.2.4",
"@ephox/mcagar": "^5.0.1",
"@ephox/sugar": "^7.0.1",
"@ephox/tslint-rules": "^1.0.7",

@@ -49,3 +51,3 @@ "@storybook/addon-info": "^5.3.21",

"@storybook/storybook-deployer": "^2.8.6",
"@tinymce/miniature": "^2.2.2",
"@tinymce/miniature": "^3.0.1",
"@types/node": "^14.11.2",

@@ -64,3 +66,2 @@ "@types/prop-types": "^15.5.8",

"rimraf": "^3.0.2",
"tinymce": "npm:tinymce@^5",
"tinymce-4": "npm:tinymce@^4",

@@ -67,0 +68,0 @@ "tinymce-5": "npm:tinymce@^5",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc