@progress/kendo-react-editor 4.10.0-dev.202109290558 → 4.10.0-dev.202110050931

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,137 +1,8 @@
1
1
  /// <reference types="prosemirror-model" />
2
2
  import * as React from 'react';
3
3
  import * as PropTypes from 'prop-types';
4
- import { EditorState, Plugin, Transaction, EditorView, Schema, Node } from '@progress/kendo-editor-common';
5
- import { EditorUtils } from './utils';
6
- /**
7
- * Represents the object of the `onChange` Editor event.
8
- */
9
- export interface EditorChangeEvent {
10
- /**
11
- * An event target.
12
- */
13
- target: Editor;
14
- /**
15
- * Represents the [Editor document](https://prosemirror.net/docs/guide/#doc).
16
- */
17
- value: Node;
18
- /**
19
- * A getter of the Editor HTML content.
20
- * Once called, it will convert the Editor document into HTML string.
21
- * Note that, since onChange event is triggered on every key while typing,
22
- * this conversion may not be suitable if the Editor is dealing with large amount of content.
23
- */
24
- html: string;
25
- /**
26
- * The Editor Schema object.
27
- */
28
- schema: Schema;
29
- /**
30
- * The Transaction which causes the change.
31
- */
32
- transaction: Transaction;
33
- }
34
- /**
35
- * Represents the props of the [KendoReact Editor component]({% slug overview_editor %}).
36
- */
37
- export interface EditorProps {
38
- /**
39
- * Sets the default HTML content of the Editor.
40
- */
41
- defaultContent?: string;
42
- /**
43
- * Sets the initial edit mode of the Editor. Defaults to `iframe`.
44
- */
45
- defaultEditMode?: 'iframe' | 'div';
46
- /**
47
- * Sets styles to the content element wrapper of the Editor.
48
- */
49
- contentStyle?: React.CSSProperties;
50
- /**
51
- * Represents the `dir` HTML attribute.
52
- */
53
- dir?: string;
54
- /**
55
- * Sets additional classes to the Editor.
56
- */
57
- className?: string;
58
- /**
59
- * Sets styles to the Editor.
60
- */
61
- style?: React.CSSProperties;
62
- /**
63
- * Sets the tools of the Editor. By default, the Editor renders no tools.
64
- */
65
- tools?: Array<any>;
66
- /**
67
- * Fires each time the Editor is about to mount.
68
- * Useful for configuring the `EditorView` object.
69
- * To initialize `EditorView`, use the properties of the `event` object.
70
- */
71
- onMount?: (event: {
72
- target: Editor;
73
- dom: HTMLDivElement;
74
- plugins: Array<Plugin>;
75
- shortcuts: EditorUtils.Shortcuts;
76
- viewProps: {
77
- state: EditorState;
78
- [key: string]: any;
79
- };
80
- }) => EditorView | void;
81
- /**
82
- * Fires each time the Editor is about to insert pasted content.
83
- * Useful for modifying pasted content.
84
- */
85
- onPasteHtml?: (event: {
86
- target: Editor;
87
- pastedHtml: string;
88
- nativeEvent: ClipboardEvent;
89
- }) => string | void;
90
- /**
91
- * Fires each time the Editor is about to apply a transaction.
92
- * To prevent the transaction, return `false`.
93
- */
94
- onExecute?: (event: {
95
- target: Editor;
96
- transaction: Transaction;
97
- state: EditorState;
98
- }) => boolean | void;
99
- /**
100
- * Fires when the Editor's content element has received focus.
101
- */
102
- onFocus?: (event: {
103
- target: Editor;
104
- nativeEvent: any;
105
- }) => void;
106
- /**
107
- * Fires when the Editor's content element has lost focus.
108
- */
109
- onBlur?: (event: {
110
- target: Editor;
111
- nativeEvent: any;
112
- }) => void;
113
- /**
114
- * Fires each time the value of the Editor is about to change.
115
- */
116
- onChange?: (event: EditorChangeEvent) => void;
117
- /**
118
- * The value of the Editor.
119
- */
120
- value?: Node | string;
121
- /**
122
- * If set to `false`, it will turn off the built-in keyboard navigation of the Editor's Toolbar.
123
- */
124
- keyboardNavigation?: boolean;
125
- /**
126
- * Defines the options that will be used for parsing the HTML.
127
- * If `false` is set, the whitespace is collapsed as per HTML's rules.
128
- * Pass `true` to preserve whitespace, but normalize newlines to spaces.
129
- * `full` will preserve whitespace entirely.
130
- *
131
- * Defaults to `full`.
132
- */
133
- preserveWhitespace?: boolean | 'full';
134
- }
4
+ import { EditorView, Node } from '@progress/kendo-editor-common';
5
+ import { EditorProps } from './EditorProps';
135
6
  /**
136
7
  * @hidden
137
8
  */
@@ -202,6 +73,7 @@ export default class Editor extends React.Component<EditorProps, EditorStateInte
202
73
  */
203
74
  readonly view: EditorView<any>;
204
75
  private _element;
76
+ private _view?;
205
77
  private _contentElement;
206
78
  private iframe;
207
79
  private trOnChange;
@@ -232,6 +104,7 @@ export default class Editor extends React.Component<EditorProps, EditorStateInte
232
104
  private renderTool;
233
105
  private updateTools;
234
106
  private initialize;
107
+ private filterTransaction;
235
108
  private onPasteHtml;
236
109
  private dispatchTransaction;
237
110
  private onFocus;
package/dist/es/Editor.js CHANGED
@@ -25,7 +25,7 @@ var __assign = (this && this.__assign) || function () {
25
25
  import * as React from 'react';
26
26
  import * as PropTypes from 'prop-types';
27
27
  import { ButtonGroup, Toolbar, ToolbarSeparator } from '@progress/kendo-react-buttons';
28
- import { EditorState, Plugin, PluginKey, EditorView, Schema, baseKeymap, keymap, history, dropCursor, gapCursor, getMark, spacesFix, tableEditing, trimWhitespace } from '@progress/kendo-editor-common';
28
+ import { EditorState, Plugin, PluginKey, EditorView, Schema, baseKeymap, keymap, history, dropCursor, gapCursor, getMark, spacesFix, tableEditing } from '@progress/kendo-editor-common';
29
29
  import { marks, nodes } from './config/schema';
30
30
  import { defaultStyle, tablesStyles, rtlStyles } from './config/defaultStyles';
31
31
  import { EditorToolsSettings } from './config/toolsSettings';
@@ -74,30 +74,36 @@ var Editor = /** @class */ (function (_super) {
74
74
  * @hidden
75
75
  */
76
76
  _this.focus = function () {
77
- if (_this.state.view) {
78
- _this.state.view.focus();
77
+ if (_this.view) {
78
+ _this.view.focus();
79
79
  }
80
80
  };
81
81
  _this.renderDialog = function (Component, settings, stateFlag) {
82
- return _this.state[stateFlag] && (React.createElement(Component, { view: _this.state.view, settings: settings, dir: _this.props.dir, onClose: function () {
82
+ return _this.state[stateFlag] && (React.createElement(Component, { view: _this.view, settings: settings, dir: _this.props.dir, onClose: function () {
83
83
  var _a;
84
84
  return _this.setState((_a = {}, _a[stateFlag] = false, _a));
85
85
  } }));
86
86
  };
87
87
  _this.renderTool = function (Tool, index) {
88
- var tool = (React.createElement(Tool, { view: _this.state.view, dir: _this.props.dir, key: index }));
88
+ var tool = (React.createElement(Tool, { view: _this.view, dir: _this.props.dir, key: index }));
89
89
  return tool.type === ToolbarSeparator ? React.createElement(Tool, { key: index }) : tool;
90
90
  };
91
91
  _this.updateTools = function (view, _prevViewState) {
92
92
  _this.setState({ view: view });
93
93
  };
94
+ _this.filterTransaction = function (transaction, state) {
95
+ var event = { target: _this, transaction: transaction, state: state };
96
+ return (_this.props.onExecute &&
97
+ _this.props.onExecute.call(undefined, event)) !== false;
98
+ };
94
99
  _this.onPasteHtml = function (html) {
95
- if (_this.props.onPasteHtml) {
96
- var newHtml = _this.props.onPasteHtml.call(undefined, {
100
+ if (_this.props.onPasteHtml && _this.pasteEvent) {
101
+ var event_1 = {
97
102
  target: _this,
98
103
  pastedHtml: html,
99
104
  nativeEvent: _this.pasteEvent
100
- });
105
+ };
106
+ var newHtml = _this.props.onPasteHtml.call(undefined, event_1);
101
107
  _this.pasteEvent = undefined;
102
108
  if (typeof newHtml === 'string') {
103
109
  return newHtml;
@@ -111,7 +117,7 @@ var Editor = /** @class */ (function (_super) {
111
117
  _this.trOnChange = transaction;
112
118
  var doc_1 = transaction.doc, schema_1 = transaction.doc.type.schema;
113
119
  var target_1 = _this;
114
- _this.props.onChange.call(undefined, {
120
+ var event_2 = {
115
121
  target: target_1,
116
122
  value: doc_1,
117
123
  get html() {
@@ -120,7 +126,8 @@ var Editor = /** @class */ (function (_super) {
120
126
  },
121
127
  transaction: transaction,
122
128
  schema: schema_1
123
- });
129
+ };
130
+ _this.props.onChange.call(undefined, event_2);
124
131
  }
125
132
  if (_this.view && (_this.props.value === undefined || !docChanged)) {
126
133
  _this.view.updateState(_this.view.state.apply(transaction));
@@ -128,13 +135,21 @@ var Editor = /** @class */ (function (_super) {
128
135
  };
129
136
  _this.onFocus = function (_view, nativeEvent) {
130
137
  if (_this.props.onFocus) {
131
- _this.props.onFocus.call(undefined, { target: _this, nativeEvent: nativeEvent });
138
+ var event_3 = {
139
+ target: _this,
140
+ nativeEvent: nativeEvent
141
+ };
142
+ _this.props.onFocus.call(undefined, event_3);
132
143
  }
133
144
  return false;
134
145
  };
135
146
  _this.onBlur = function (_view, nativeEvent) {
136
147
  if (_this.props.onBlur) {
137
- _this.props.onBlur.call(undefined, { target: _this, nativeEvent: nativeEvent });
148
+ var event_4 = {
149
+ target: _this,
150
+ nativeEvent: nativeEvent
151
+ };
152
+ _this.props.onBlur.call(undefined, event_4);
138
153
  }
139
154
  return false;
140
155
  };
@@ -199,7 +214,7 @@ var Editor = /** @class */ (function (_super) {
199
214
  * Returns the `view` object of the Editor.
200
215
  */
201
216
  get: function () {
202
- return this.state.view;
217
+ return this._view;
203
218
  },
204
219
  enumerable: true,
205
220
  configurable: true
@@ -229,9 +244,10 @@ var Editor = /** @class */ (function (_super) {
229
244
  * @hidden
230
245
  */
231
246
  Editor.prototype.componentWillUnmount = function () {
232
- if (this.state.view) {
233
- this.state.view.destroy();
247
+ if (this.view) {
248
+ this.view.destroy();
234
249
  }
250
+ this._view = undefined;
235
251
  };
236
252
  /**
237
253
  * @hidden
@@ -296,10 +312,7 @@ var Editor = /** @class */ (function (_super) {
296
312
  key: new PluginKey('toolbar-tools-update-plugin')
297
313
  }),
298
314
  new Plugin({
299
- filterTransaction: function (transaction, state) {
300
- return (_this.props.onExecute &&
301
- _this.props.onExecute.call(undefined, { target: target, transaction: transaction, state: state })) !== false;
302
- },
315
+ filterTransaction: this.filterTransaction,
303
316
  key: new PluginKey('onExecute-event-plugin')
304
317
  }),
305
318
  new Plugin({
@@ -319,7 +332,8 @@ var Editor = /** @class */ (function (_super) {
319
332
  types: { listItem: 'list_item', hardBreak: 'hard_break' },
320
333
  toolsSettings: { bold: bold, italic: italic, underline: underline }
321
334
  }), { 'Mod-k': function () {
322
- var _a = _this.state, linkDialog = _a.linkDialog, editorView = _a.view;
335
+ var linkDialog = _this.state.linkDialog;
336
+ var editorView = _this.view;
323
337
  if (editorView) {
324
338
  var editorState = editorView.state;
325
339
  var collapsed = editorState.selection.empty;
@@ -333,7 +347,7 @@ var Editor = /** @class */ (function (_super) {
333
347
  } });
334
348
  var _b = this.props, _c = _b.defaultContent, defaultContent = _c === void 0 ? '' : _c, value = _b.value, onMount = _b.onMount;
335
349
  var doc = (value && typeof value !== 'string') ? value :
336
- EditorUtils.createDocument(new Schema({ nodes: nodes, marks: marks }), trimWhitespace(value || defaultContent), { preserveWhitespace: preserveWhitespace });
350
+ EditorUtils.createDocument(new Schema({ nodes: nodes, marks: marks }), value || defaultContent, { preserveWhitespace: preserveWhitespace });
337
351
  var viewProps = {
338
352
  state: EditorState.create({
339
353
  plugins: plugins.concat([keymap(shortcuts), keymap(baseKeymap)]),
@@ -347,8 +361,8 @@ var Editor = /** @class */ (function (_super) {
347
361
  paste: this.onPaste
348
362
  }
349
363
  };
350
- var view = (onMount && onMount.call(undefined, { plugins: plugins, shortcuts: shortcuts, target: target, viewProps: viewProps, dom: dom })) ||
351
- new EditorView({ mount: dom }, viewProps);
364
+ var mountEvent = { plugins: plugins, shortcuts: shortcuts, target: target, viewProps: viewProps, dom: dom };
365
+ var view = this._view = (onMount && onMount.call(undefined, mountEvent)) || new EditorView({ mount: dom }, viewProps);
352
366
  this.setState({
353
367
  view: view
354
368
  });
@@ -0,0 +1,182 @@
1
+ /// <reference types="prosemirror-model" />
2
+ /// <reference types="react" />
3
+ import { EditorState, Plugin, Transaction, EditorView, Schema, Node } from '@progress/kendo-editor-common';
4
+ import { EditorUtils } from './utils';
5
+ import Editor from './Editor';
6
+ interface EditorEvent {
7
+ /**
8
+ * An event target.
9
+ */
10
+ target: Editor;
11
+ }
12
+ /**
13
+ * Represents the object of the `onChange` Editor event.
14
+ */
15
+ export interface EditorChangeEvent extends EditorEvent {
16
+ /**
17
+ * Represents the [Editor document](https://prosemirror.net/docs/guide/#doc).
18
+ */
19
+ value: Node;
20
+ /**
21
+ * A getter of the Editor HTML content.
22
+ * Once called, it will convert the Editor document into HTML string.
23
+ * Note that, since onChange event is triggered on every key while typing,
24
+ * this conversion may not be suitable if the Editor is dealing with large amount of content.
25
+ */
26
+ html: string;
27
+ /**
28
+ * The Editor Schema object.
29
+ */
30
+ schema: Schema;
31
+ /**
32
+ * The Transaction which causes the change.
33
+ */
34
+ transaction: Transaction;
35
+ }
36
+ /**
37
+ * Represents the object of the `onMount` Editor event.
38
+ */
39
+ export interface EditorMountEvent extends EditorEvent {
40
+ /**
41
+ * The content-editable DOM element of the Editor.
42
+ */
43
+ dom: HTMLDivElement;
44
+ /**
45
+ * The default plugins collection of the Editor.
46
+ */
47
+ plugins: Array<Plugin>;
48
+ /**
49
+ * The default key bindings of the Editor.
50
+ */
51
+ shortcuts: EditorUtils.Shortcuts;
52
+ /**
53
+ * The default [viewProps](https://prosemirror.net/docs/ref/#view.DirectEditorProps) object of the Editor.
54
+ */
55
+ viewProps: {
56
+ state: EditorState;
57
+ [key: string]: any;
58
+ };
59
+ }
60
+ /**
61
+ * Represents the object of the `onPaste` Editor event.
62
+ */
63
+ export interface EditorPasteEvent extends EditorEvent {
64
+ /**
65
+ * The HTML that will be pasted in the Editor.
66
+ */
67
+ pastedHtml: string;
68
+ /**
69
+ * The native paste event.
70
+ */
71
+ nativeEvent: ClipboardEvent;
72
+ }
73
+ /**
74
+ * Represents the object of the `onExecute` Editor event.
75
+ */
76
+ export interface EditorExecuteEvent extends EditorEvent {
77
+ /**
78
+ * The transaction that will be executed.
79
+ */
80
+ transaction: Transaction;
81
+ /**
82
+ * The state of the Editor.
83
+ */
84
+ state: EditorState;
85
+ }
86
+ /**
87
+ * Represents the object of the `onFocus` Editor event.
88
+ */
89
+ export interface EditorFocusEvent extends EditorEvent {
90
+ /**
91
+ * The native focus event.
92
+ */
93
+ nativeEvent: FocusEvent;
94
+ }
95
+ /**
96
+ * Represents the object of the `onBlur` Editor event.
97
+ */
98
+ export interface EditorBlurEvent extends EditorEvent {
99
+ /**
100
+ * The native blur event.
101
+ */
102
+ nativeEvent: FocusEvent;
103
+ }
104
+ /**
105
+ * Represents the props of the [KendoReact Editor component]({% slug overview_editor %}).
106
+ */
107
+ export interface EditorProps {
108
+ /**
109
+ * Sets the default HTML content of the Editor.
110
+ */
111
+ defaultContent?: string;
112
+ /**
113
+ * Sets the initial edit mode of the Editor. Defaults to `iframe`.
114
+ */
115
+ defaultEditMode?: 'iframe' | 'div';
116
+ /**
117
+ * Sets styles to the content element wrapper of the Editor.
118
+ */
119
+ contentStyle?: React.CSSProperties;
120
+ /**
121
+ * Represents the `dir` HTML attribute.
122
+ */
123
+ dir?: string;
124
+ /**
125
+ * Sets additional classes to the Editor.
126
+ */
127
+ className?: string;
128
+ /**
129
+ * Sets styles to the Editor.
130
+ */
131
+ style?: React.CSSProperties;
132
+ /**
133
+ * Sets the tools of the Editor. By default, the Editor renders no tools.
134
+ */
135
+ tools?: Array<any>;
136
+ /**
137
+ * Fires each time the Editor is about to mount.
138
+ * Useful for configuring the `EditorView` object.
139
+ * To initialize `EditorView`, use the properties of the `event` object.
140
+ */
141
+ onMount?: (event: EditorMountEvent) => EditorView | void;
142
+ /**
143
+ * Fires each time the Editor is about to insert pasted content.
144
+ * Useful for modifying pasted content.
145
+ */
146
+ onPasteHtml?: (event: EditorPasteEvent) => string | void;
147
+ /**
148
+ * Fires each time the Editor is about to apply a transaction.
149
+ * To prevent the transaction, return `false`.
150
+ */
151
+ onExecute?: (event: EditorExecuteEvent) => boolean | void;
152
+ /**
153
+ * Fires when the Editor's content element has received focus.
154
+ */
155
+ onFocus?: (event: EditorFocusEvent) => void;
156
+ /**
157
+ * Fires when the Editor's content element has lost focus.
158
+ */
159
+ onBlur?: (event: EditorBlurEvent) => void;
160
+ /**
161
+ * Fires each time the value of the Editor is about to change.
162
+ */
163
+ onChange?: (event: EditorChangeEvent) => void;
164
+ /**
165
+ * The value of the Editor.
166
+ */
167
+ value?: Node | string;
168
+ /**
169
+ * If set to `false`, it will turn off the built-in keyboard navigation of the Editor's Toolbar.
170
+ */
171
+ keyboardNavigation?: boolean;
172
+ /**
173
+ * Defines the options that will be used for parsing the HTML.
174
+ * If `false` is set, the whitespace is collapsed as per HTML's rules.
175
+ * Pass `true` to preserve whitespace, but normalize newlines to spaces.
176
+ * `full` will preserve whitespace entirely.
177
+ *
178
+ * Defaults to `full`.
179
+ */
180
+ preserveWhitespace?: boolean | 'full';
181
+ }
182
+ export {};
File without changes
package/dist/es/main.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /// <reference types="prosemirror-model" />
2
- import Editor, { EditorProps } from './Editor';
2
+ import Editor from './Editor';
3
+ import { EditorProps, EditorMountEvent, EditorPasteEvent, EditorChangeEvent, EditorExecuteEvent, EditorFocusEvent, EditorBlurEvent } from './EditorProps';
3
4
  import { EditorTools } from './tools/main';
4
5
  import { EditorToolsSettings } from './config/toolsSettings';
5
6
  import { EditorUtils } from './utils';
6
7
  import { EditorDialogs } from './dialogs/main';
7
8
  import { Selection, SelectionRange, TextSelection, NodeSelection, AllSelection, EditorState, Plugin, PluginKey, Transaction, Decoration, DecorationSet, EditorView, Node, ResolvedPos, NodeRange, Fragment, Slice, ReplaceError, Mark, Schema, NodeType, MarkType, ContentMatch, DOMParser, DOMSerializer, Transform, Step, StepResult, joinPoint, canJoin, canSplit, insertPoint, dropPoint, liftTarget, findWrapping, StepMap, MapResult, Mapping, AddMarkStep, RemoveMarkStep, ReplaceStep, ReplaceAroundStep, replaceStep, deleteSelection, joinBackward, selectNodeBackward, joinForward, selectNodeForward, joinUp, joinDown, lift, newlineInCode, exitCode, createParagraphNear, liftEmptyBlock, splitBlock, splitBlockKeepMarks, selectParentNode, selectAll, wrapIn, setBlockType, toggleMark, autoJoin, chainCommands, history, undo, redo, undoDepth, redoDepth, InputRule, inputRules, undoInputRule, wrappingInputRule, textblockTypeInputRule, keymap, keydownHandler, addListNodes, wrapInList, splitListItem, liftListItem, sinkListItem, dropCursor, gapCursor, tableEditing, fixTables, cellAround, isInTable, selectionCell, moveCellForward, inSameTable, findCell, colCount, nextCell, removeColSpan, addColSpan, columnIsHeader, tableNodes, tableNodeTypes, CellSelection, TableMap, columnResizing, updateColumnsOnResize, selectedRect, addColumn, addColumnBefore, addColumnAfter, deleteColumn, rowIsHeader, addRow, addRowBefore, addRowAfter, deleteRow, mergeCells, splitCell, splitCellWithType, setCellAttr, toggleHeader, toggleHeaderRow, toggleHeaderColumn, toggleHeaderCell, goToNextCell, deleteTable } from '@progress/kendo-editor-common';
8
9
  export { PasteCleanupSettings } from './config/pasteSettings';
9
- export { EditorChangeEvent } from './Editor';
10
10
  /**
11
11
  * An object containing the content of ProseMirror packages used at the Editor component.
12
12
  *
@@ -163,4 +163,4 @@ export declare const ProseMirror: {
163
163
  goToNextCell: typeof goToNextCell;
164
164
  deleteTable: typeof deleteTable;
165
165
  };
166
- export { Editor, EditorProps, EditorTools, EditorToolsSettings, EditorUtils, EditorDialogs };
166
+ export { Editor, EditorProps, EditorMountEvent, EditorPasteEvent, EditorChangeEvent, EditorExecuteEvent, EditorFocusEvent, EditorBlurEvent, EditorTools, EditorToolsSettings, EditorUtils, EditorDialogs };
@@ -5,7 +5,7 @@ export var packageMetadata = {
5
5
  name: '@progress/kendo-react-editor',
6
6
  productName: 'KendoReact',
7
7
  productCodes: ['KENDOUIREACT', 'KENDOUICOMPLETE'],
8
- publishDate: 1632894490,
8
+ publishDate: 1633425702,
9
9
  version: '',
10
10
  licensingDocsUrl: 'https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning'
11
11
  };
@@ -93,7 +93,7 @@ export var EditorUtils;
93
93
  * @returns {Node} - The `document` object of the Editor.
94
94
  */
95
95
  function createDocument(schema, html, parseOptions) {
96
- return parseContent(html, schema, parseOptions !== undefined ? parseOptions : { preserveWhitespace: 'full' });
96
+ return parseContent(trimWhitespace(html), schema, parseOptions !== undefined ? parseOptions : { preserveWhitespace: 'full' });
97
97
  }
98
98
  EditorUtils.createDocument = createDocument;
99
99
  /**