@modusoperandi/licit 0.14.1 → 0.14.3

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.
Files changed (48) hide show
  1. package/README.md +1 -0
  2. package/dist/EditorCommands.js +1 -7
  3. package/dist/EditorCommands.js.flow +0 -4
  4. package/dist/EditorNodes.js +0 -3
  5. package/dist/EditorNodes.js.flow +0 -3
  6. package/dist/bom.xml +225 -227
  7. package/dist/buildEditorPlugins.js +1 -2
  8. package/dist/buildEditorPlugins.js.flow +0 -2
  9. package/dist/client/Licit.js +7 -0
  10. package/dist/client/Licit.js.flow +9 -0
  11. package/dist/ui/Editor.js +0 -2
  12. package/dist/ui/Editor.js.flow +1 -3
  13. package/dist/ui/EditorToolbarConfig.js +0 -6
  14. package/dist/ui/EditorToolbarConfig.js.flow +0 -8
  15. package/package.json +6 -12
  16. package/src/EditorCommands.js +0 -4
  17. package/src/EditorNodes.js +0 -3
  18. package/src/buildEditorPlugins.js +0 -2
  19. package/src/client/Licit.js +9 -0
  20. package/src/ui/Editor.js +1 -3
  21. package/src/ui/EditorToolbarConfig.js +0 -8
  22. package/dist/ImageFromURLCommand.js +0 -19
  23. package/dist/ImageFromURLCommand.js.flow +0 -14
  24. package/dist/ImageNodeSpec.js +0 -109
  25. package/dist/ImageNodeSpec.js.flow +0 -90
  26. package/dist/ImageSourceCommand.js +0 -117
  27. package/dist/ImageSourceCommand.js.flow +0 -117
  28. package/dist/ImageUploadCommand.js +0 -49
  29. package/dist/ImageUploadCommand.js.flow +0 -36
  30. package/dist/ui/ImageAlignEditor.js +0 -71
  31. package/dist/ui/ImageAlignEditor.js.flow +0 -60
  32. package/dist/ui/ImageNodeView.js +0 -404
  33. package/dist/ui/ImageNodeView.js.flow +0 -405
  34. package/dist/ui/ImageResizeBox.js +0 -206
  35. package/dist/ui/ImageResizeBox.js.flow +0 -219
  36. package/dist/ui/ImageURLEditor.js +0 -108
  37. package/dist/ui/ImageURLEditor.js.flow +0 -119
  38. package/dist/ui/ImageUploadEditor.js +0 -123
  39. package/dist/ui/ImageUploadEditor.js.flow +0 -117
  40. package/src/ImageFromURLCommand.js +0 -14
  41. package/src/ImageNodeSpec.js +0 -90
  42. package/src/ImageSourceCommand.js +0 -117
  43. package/src/ImageUploadCommand.js +0 -36
  44. package/src/ui/ImageAlignEditor.js +0 -60
  45. package/src/ui/ImageNodeView.js +0 -405
  46. package/src/ui/ImageResizeBox.js +0 -219
  47. package/src/ui/ImageURLEditor.js +0 -119
  48. package/src/ui/ImageUploadEditor.js +0 -117
@@ -1,90 +0,0 @@
1
- // @flow
2
-
3
- import type { NodeSpec } from './Types';
4
-
5
- const CSS_ROTATE_PATTERN = /rotate\(([0-9\.]+)rad\)/i;
6
- const EMPTY_CSS_VALUE = new Set(['0%', '0pt', '0px']);
7
-
8
- function getAttrs(dom: HTMLElement) {
9
- const { cssFloat, display, marginTop, marginLeft } = dom.style;
10
- let { width, height } = dom.style;
11
- let align = dom.getAttribute('data-align') || dom.getAttribute('align');
12
- if (align) {
13
- align = /(left|right|center)/.test(align) ? align : null;
14
- } else if (cssFloat === 'left' && !display) {
15
- align = 'left';
16
- } else if (cssFloat === 'right' && !display) {
17
- align = 'right';
18
- } else if (!cssFloat && display === 'block') {
19
- align = 'block';
20
- }
21
-
22
- width = width || dom.getAttribute('width');
23
- height = height || dom.getAttribute('height');
24
-
25
- let crop = null;
26
- let rotate = null;
27
- const { parentElement } = dom;
28
- if (parentElement instanceof HTMLElement) {
29
- // Special case for Google doc's image.
30
- const ps = parentElement.style;
31
- if (
32
- ps.display === 'inline-block' &&
33
- ps.overflow === 'hidden' &&
34
- ps.width &&
35
- ps.height &&
36
- marginLeft &&
37
- !EMPTY_CSS_VALUE.has(marginLeft) &&
38
- marginTop &&
39
- !EMPTY_CSS_VALUE.has(marginTop)
40
- ) {
41
- crop = {
42
- width: parseInt(ps.width, 10) || 0,
43
- height: parseInt(ps.height, 10) || 0,
44
- left: parseInt(marginLeft, 10) || 0,
45
- top: parseInt(marginTop, 10) || 0,
46
- };
47
- }
48
- if (ps.transform) {
49
- // example: `rotate(1.57rad) translateZ(0px)`;
50
- const mm = ps.transform.match(CSS_ROTATE_PATTERN);
51
- if (mm && mm[1]) {
52
- rotate = parseFloat(mm[1]) || null;
53
- }
54
- }
55
- }
56
-
57
- return {
58
- align,
59
- alt: dom.getAttribute('alt') || null,
60
- crop,
61
- height: parseInt(height, 10) || null,
62
- rotate,
63
- src: dom.getAttribute('src') || null,
64
- title: dom.getAttribute('title') || null,
65
- width: parseInt(width, 10) || null,
66
- };
67
- }
68
-
69
- // https://github.com/ProseMirror/prosemirror-schema-basic/blob/master/src/schema-basic.js
70
- const ImageNodeSpec: NodeSpec = {
71
- inline: true,
72
- attrs: {
73
- align: { default: null },
74
- alt: { default: '' },
75
- crop: { default: null },
76
- height: { default: null },
77
- rotate: { default: null },
78
- src: { default: null },
79
- title: { default: '' },
80
- width: { default: null },
81
- },
82
- group: 'inline',
83
- draggable: true,
84
- parseDOM: [{ tag: 'img[src]', getAttrs }],
85
- toDOM(node) {
86
- return ['img', node.attrs];
87
- },
88
- };
89
-
90
- export default ImageNodeSpec;
@@ -1,117 +0,0 @@
1
- // @flow
2
-
3
- import { Fragment, Schema } from 'prosemirror-model';
4
- import { EditorState } from 'prosemirror-state';
5
- import { TextSelection } from 'prosemirror-state';
6
- import { Transform } from 'prosemirror-transform';
7
- import { EditorView } from 'prosemirror-view';
8
- import * as React from 'react';
9
- import {
10
- hideCursorPlaceholder,
11
- showCursorPlaceholder,
12
- } from './CursorPlaceholderPlugin';
13
- import { IMAGE } from './NodeNames';
14
- import { UICommand } from '@modusoperandi/licit-doc-attrs-step';
15
- import { createPopUp } from '@modusoperandi/licit-ui-commands';
16
-
17
- import type { ImageLike } from './Types';
18
-
19
- function insertImage(tr: Transform, schema: Schema, src: ?string): Transform {
20
- const { selection } = tr;
21
- if (!selection) {
22
- return tr;
23
- }
24
- const { from, to } = selection;
25
- if (from !== to) {
26
- return tr;
27
- }
28
-
29
- const image = schema.nodes[IMAGE];
30
- if (!image) {
31
- return tr;
32
- }
33
-
34
- const attrs = {
35
- src: src || '',
36
- alt: '',
37
- title: '',
38
- };
39
-
40
- const node = image.create(attrs, null, null);
41
- const frag = Fragment.from(node);
42
- tr = tr.insert(from, frag);
43
- return tr;
44
- }
45
-
46
- class ImageSourceCommand extends UICommand {
47
- _popUp = null;
48
-
49
- getEditor(): Class<React.Component<any, any>> {
50
- throw new Error('Not implemented');
51
- }
52
-
53
- isEnabled = (state: EditorState, view: ?EditorView): boolean => {
54
- return this.__isEnabled(state, view);
55
- };
56
-
57
- waitForUserInput = (
58
- state: EditorState,
59
- dispatch: ?(tr: Transform) => void,
60
- view: ?EditorView,
61
- event: ?SyntheticEvent<>
62
- ): Promise<any> => {
63
- if (this._popUp) {
64
- return Promise.resolve(undefined);
65
- }
66
-
67
- if (dispatch) {
68
- dispatch(showCursorPlaceholder(state));
69
- }
70
-
71
- return new Promise((resolve) => {
72
- const props = { runtime: view ? view.runtime : null };
73
- this._popUp = createPopUp(this.getEditor(), props, {
74
- modal: true,
75
- onClose: (val) => {
76
- if (this._popUp) {
77
- this._popUp = null;
78
- resolve(val);
79
- }
80
- },
81
- });
82
- });
83
- };
84
-
85
- executeWithUserInput = (
86
- state: EditorState,
87
- dispatch: ?(tr: Transform) => void,
88
- view: ?EditorView,
89
- inputs: ?ImageLike
90
- ): boolean => {
91
- if (dispatch) {
92
- const { selection, schema } = state;
93
- let { tr } = state;
94
- tr = view ? hideCursorPlaceholder(view.state) : tr;
95
- tr = tr.setSelection(selection);
96
- if (inputs) {
97
- const { src } = inputs;
98
- tr = insertImage(tr, schema, src);
99
- }
100
- dispatch(tr);
101
- view && view.focus();
102
- }
103
-
104
- return false;
105
- };
106
-
107
- __isEnabled = (state: EditorState, view: ?EditorView): boolean => {
108
- const tr = state;
109
- const { selection } = tr;
110
- if (selection instanceof TextSelection) {
111
- return selection.from === selection.to;
112
- }
113
- return false;
114
- };
115
- }
116
-
117
- export default ImageSourceCommand;
@@ -1,36 +0,0 @@
1
- // @flow
2
-
3
- import { EditorState } from 'prosemirror-state';
4
- import { EditorView } from 'prosemirror-view';
5
- import * as React from 'react';
6
-
7
- import ImageSourceCommand from './ImageSourceCommand';
8
- import ImageUploadEditor from './ui/ImageUploadEditor';
9
-
10
- class ImageUploadCommand extends ImageSourceCommand {
11
- isEnabled = (state: EditorState, view: ?EditorView): boolean => {
12
- if (!view) {
13
- return false;
14
- }
15
-
16
- const { runtime } = view;
17
- if (!runtime) {
18
- return false;
19
- }
20
-
21
- const { canUploadImage, uploadImage } = runtime;
22
- if (!canUploadImage || !uploadImage) {
23
- return false;
24
- }
25
- if (!canUploadImage()) {
26
- return false;
27
- }
28
-
29
- return this.__isEnabled(state, view);
30
- };
31
-
32
- getEditor(): Class<React.Component<any, any>> {
33
- return ImageUploadEditor;
34
- }
35
- }
36
- export default ImageUploadCommand;
@@ -1,60 +0,0 @@
1
- // @flow
2
-
3
- import './czi-inline-editor.css';
4
- import { CustomButton } from '@modusoperandi/licit-ui-commands';
5
- import * as React from 'react';
6
-
7
- const ImageAlignValues = {
8
- NONE: {
9
- value: null,
10
- text: 'Inline',
11
- },
12
- LEFT: {
13
- value: 'left',
14
- text: 'Float left',
15
- },
16
- CENTER: {
17
- value: 'center',
18
- text: 'Center',
19
- },
20
- RIGHT: {
21
- value: 'right',
22
- text: 'Float right',
23
- },
24
- };
25
-
26
- export type ImageInlineEditorValue = {
27
- align: ?string,
28
- };
29
-
30
- class ImageInlineEditor extends React.PureComponent<any, any> {
31
- props: {
32
- onSelect: (val: ImageInlineEditorValue) => void,
33
- value: ?ImageInlineEditorValue,
34
- };
35
-
36
- render(): React.Element<any> {
37
- const align = this.props.value ? this.props.value.align : null;
38
- const onClick = this._onClick;
39
- const buttons = Object.keys(ImageAlignValues).map((key) => {
40
- const { value, text } = ImageAlignValues[key];
41
- return (
42
- <CustomButton
43
- active={align === value}
44
- key={key}
45
- label={text}
46
- onClick={onClick}
47
- value={value}
48
- />
49
- );
50
- });
51
-
52
- return <div className="czi-inline-editor custom-">{buttons}</div>;
53
- }
54
-
55
- _onClick = (align: ?string): void => {
56
- this.props.onSelect({ align: align });
57
- };
58
- }
59
-
60
- export default ImageInlineEditor;
@@ -1,405 +0,0 @@
1
- // @flow
2
-
3
- import cx from 'classnames';
4
- import { Node } from 'prosemirror-model';
5
- import { Decoration } from 'prosemirror-view';
6
- import { NodeSelection } from 'prosemirror-state';
7
- import * as React from 'react';
8
- import ReactDOM from 'react-dom';
9
-
10
- import CustomNodeView from './CustomNodeView';
11
- import { FRAMESET_BODY_CLASSNAME } from './EditorFrameset';
12
- import Icon from './Icon';
13
- import ImageInlineEditor from './ImageInlineEditor';
14
- import ImageResizeBox from './ImageResizeBox';
15
- import { MIN_SIZE } from './ImageResizeBox';
16
- import { atAnchorBottomCenter } from '@modusoperandi/licit-ui-commands';
17
- import ResizeObserver from './ResizeObserver';
18
- import { createPopUp } from '@modusoperandi/licit-ui-commands';
19
- import resolveImage from './resolveImage';
20
- import uuid from './uuid';
21
-
22
- import './czi-image-view.css';
23
-
24
- import type { EditorRuntime } from '../Types';
25
- import type { NodeViewProps } from './CustomNodeView';
26
- import type { ResizeObserverEntry } from './ResizeObserver';
27
-
28
- const EMPTY_SRC =
29
- 'data:image/gif;base64,' +
30
- 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
31
-
32
- /* This value must be synced with the margin defined at .czi-image-view */
33
- const IMAGE_MARGIN = 2;
34
-
35
- const MAX_SIZE = 100000;
36
- const IMAGE_PLACEHOLDER_SIZE = 24;
37
-
38
- const DEFAULT_ORIGINAL_SIZE = {
39
- src: '',
40
- complete: false,
41
- height: 0,
42
- width: 0,
43
- };
44
-
45
- // Get the maxWidth that the image could be resized to.
46
- function getMaxResizeWidth(el: any): number {
47
- // Ideally, the image should bot be wider then its containing element.
48
- let node: any = el.parentElement;
49
- while (node && !node.offsetParent) {
50
- node = node.parentElement;
51
- }
52
- if (
53
- node &&
54
- node.offsetParent &&
55
- node.offsetParent.offsetWidth &&
56
- node.offsetParent.offsetWidth > 0
57
- ) {
58
- const { offsetParent } = node;
59
- const style = el.ownerDocument.defaultView.getComputedStyle(offsetParent);
60
- let width = offsetParent.clientWidth - IMAGE_MARGIN * 2;
61
- if (style.boxSizing === 'border-box') {
62
- const pl = parseInt(style.paddingLeft, 10);
63
- const pr = parseInt(style.paddingRight, 10);
64
- width -= pl + pr;
65
- }
66
- return Math.max(width, MIN_SIZE);
67
- }
68
- // Let the image resize freely.
69
- return MAX_SIZE;
70
- }
71
-
72
- async function resolveURL(runtime: ?EditorRuntime, src: ?string): ?string {
73
- if (!runtime) {
74
- return src;
75
- }
76
- const { canProxyImageSrc, getProxyImageSrc } = runtime;
77
- if (src && canProxyImageSrc && getProxyImageSrc && canProxyImageSrc(src)) {
78
- const imageSrc = await getProxyImageSrc(src);
79
- return imageSrc;
80
- }
81
- return src;
82
- }
83
-
84
- class ImageViewBody extends React.PureComponent<any, any> {
85
- props: NodeViewProps;
86
-
87
- _body = null;
88
- _id = uuid();
89
- _inlineEditor = null;
90
- _mounted = false;
91
-
92
- state = {
93
- maxSize: {
94
- width: MAX_SIZE,
95
- height: MAX_SIZE,
96
- complete: false,
97
- },
98
- originalSize: DEFAULT_ORIGINAL_SIZE,
99
- };
100
-
101
- componentDidMount(): void {
102
- this._mounted = true;
103
- this._resolveOriginalSize();
104
- this._renderInlineEditor();
105
- }
106
-
107
- componentWillUnmount(): void {
108
- this._mounted = false;
109
- this._inlineEditor && this._inlineEditor.close();
110
- this._inlineEditor = null;
111
- }
112
-
113
- componentDidUpdate(prevProps: NodeViewProps): void {
114
- const prevSrc = prevProps.node.attrs.src;
115
- const { node } = this.props;
116
- const { src } = node.attrs;
117
- if (prevSrc !== src) {
118
- // A new image is provided, resolve it.
119
- this._resolveOriginalSize();
120
- }
121
- this._renderInlineEditor();
122
- }
123
-
124
- render(): React.Element<any> {
125
- const { originalSize, maxSize } = this.state;
126
- const { editorView, node, selected, focused } = this.props;
127
- const { readOnly } = editorView;
128
- const { attrs } = node;
129
- const { align, crop, rotate } = attrs;
130
-
131
- // It's only active when the image's fully loaded.
132
- const loading = originalSize === DEFAULT_ORIGINAL_SIZE;
133
- const active = !loading && focused && !readOnly && originalSize.complete;
134
- const src = originalSize.complete ? originalSize.src : EMPTY_SRC;
135
- const aspectRatio = loading ? 1 : originalSize.width / originalSize.height;
136
- const error = !loading && !originalSize.complete;
137
-
138
- let { width, height } = attrs;
139
-
140
- if (loading) {
141
- width = width || IMAGE_PLACEHOLDER_SIZE;
142
- height = height || IMAGE_PLACEHOLDER_SIZE;
143
- }
144
-
145
- if (width && !height) {
146
- height = width / aspectRatio;
147
- } else if (height && !width) {
148
- width = height * aspectRatio;
149
- } else if (!width && !height) {
150
- width = originalSize.width;
151
- height = originalSize.height;
152
- }
153
-
154
- let scale = 1;
155
- if (width > maxSize.width && (!crop || crop.width > maxSize.width)) {
156
- // Scale image to fit its containing space.
157
- // If the image is not cropped.
158
- width = maxSize.width;
159
- height = width / aspectRatio;
160
- scale = maxSize.width / width;
161
- }
162
-
163
- const className = cx('czi-image-view-body', {
164
- active,
165
- error,
166
- focused,
167
- loading,
168
- selected,
169
- });
170
-
171
- const resizeBox =
172
- active && !crop && !rotate ? (
173
- <ImageResizeBox
174
- height={height}
175
- onResizeEnd={this._onResizeEnd}
176
- src={src}
177
- width={width}
178
- />
179
- ) : null;
180
-
181
- const imageStyle: Object = {
182
- display: 'inline-block',
183
- height: height + 'px',
184
- left: '0',
185
- top: '0',
186
- width: width + 'px',
187
- position: 'relative',
188
- };
189
-
190
- const clipStyle: Object = {};
191
- if (crop) {
192
- const cropped = { ...crop };
193
- if (scale !== 1) {
194
- scale = maxSize.width / cropped.width;
195
- cropped.width *= scale;
196
- cropped.height *= scale;
197
- cropped.left *= scale;
198
- cropped.top *= scale;
199
- }
200
- clipStyle.width = cropped.width + 'px';
201
- clipStyle.height = cropped.height + 'px';
202
- imageStyle.left = cropped.left + 'px';
203
- imageStyle.top = cropped.top + 'px';
204
- }
205
-
206
- if (rotate) {
207
- clipStyle.transform = `rotate(${rotate}rad)`;
208
- }
209
-
210
- const errorView = error ? Icon.get('error') : null;
211
- const errorTitle = error
212
- ? `Unable to load image from ${attrs.src || ''}`
213
- : undefined;
214
-
215
- return (
216
- <span
217
- className={className}
218
- data-active={active ? 'true' : undefined}
219
- data-original-src={String(attrs.src)}
220
- id={this._id}
221
- ref={this._onBodyRef}
222
- title={errorTitle}
223
- >
224
- <span className="czi-image-view-body-img-clip" style={clipStyle}>
225
- <span style={imageStyle}>
226
- <img
227
- alt=""
228
- className="czi-image-view-body-img"
229
- data-align={align}
230
- height={height}
231
- id={`${this._id}-img`}
232
- src={src}
233
- width={width}
234
- />
235
- {errorView}
236
- </span>
237
- </span>
238
- {resizeBox}
239
- </span>
240
- );
241
- }
242
-
243
- _renderInlineEditor(): void {
244
- const el = document.getElementById(this._id);
245
- if (!el || el.getAttribute('data-active') !== 'true') {
246
- this._inlineEditor && this._inlineEditor.close();
247
- return;
248
- }
249
-
250
- const { node } = this.props;
251
- const editorProps = {
252
- value: node.attrs,
253
- onSelect: this._onChange,
254
- };
255
- if (this._inlineEditor) {
256
- this._inlineEditor.update(editorProps);
257
- } else {
258
- this._inlineEditor = createPopUp(ImageInlineEditor, editorProps, {
259
- anchor: el,
260
- autoDismiss: false,
261
- container: el.closest(`.${FRAMESET_BODY_CLASSNAME}`),
262
- position: atAnchorBottomCenter,
263
- onClose: () => {
264
- this._inlineEditor = null;
265
- },
266
- });
267
- }
268
- }
269
-
270
- _resolveOriginalSize = async (): Promise<void> => {
271
- if (!this._mounted) {
272
- // unmounted;
273
- return;
274
- }
275
-
276
- this.setState({ originalSize: DEFAULT_ORIGINAL_SIZE });
277
- const src = this.props.node.attrs.src;
278
- const url = await resolveURL(this.props.editorView.runtime, src);
279
- const originalSize = await resolveImage(url);
280
- if (!this._mounted) {
281
- // unmounted;
282
- return;
283
- }
284
- if (this.props.node.attrs.src !== src) {
285
- // src had changed.
286
- return;
287
- }
288
- if (!originalSize.complete) {
289
- originalSize.width = MIN_SIZE;
290
- originalSize.height = MIN_SIZE;
291
- }
292
- this.setState({ originalSize });
293
- };
294
-
295
- _onResizeEnd = (width: number, height: number): void => {
296
- const { getPos, node, editorView } = this.props;
297
- const pos = getPos();
298
- const attrs = {
299
- ...node.attrs,
300
- // TODO: Support UI for cropping later.
301
- crop: null,
302
- width,
303
- height,
304
- };
305
-
306
- let tr = editorView.state.tr;
307
- const { selection } = editorView.state;
308
- tr = tr.setNodeMarkup(pos, null, attrs);
309
- // [FS] IRAD-1005 2020-07-09
310
- // Upgrade outdated packages.
311
- // reset selection to original using the latest doc.
312
- const origSelection = NodeSelection.create(tr.doc, selection.from);
313
- tr = tr.setSelection(origSelection);
314
- editorView.dispatch(tr);
315
- };
316
-
317
- _onChange = (value: ?{ align: ?string }): void => {
318
- if (!this._mounted) {
319
- return;
320
- }
321
-
322
- const align = value ? value.align : null;
323
- const { getPos, node, editorView } = this.props;
324
- const pos = getPos();
325
- const attrs = {
326
- ...node.attrs,
327
- align,
328
- };
329
-
330
- let tr = editorView.state.tr;
331
- const { selection } = editorView.state;
332
- tr = tr.setNodeMarkup(pos, null, attrs);
333
- // [FS] IRAD-1005 2020-07-09
334
- // Upgrade outdated packages.
335
- // reset selection to original using the latest doc.
336
- const origSelection = NodeSelection.create(tr.doc, selection.from);
337
- tr = tr.setSelection(origSelection);
338
- editorView.dispatch(tr);
339
- };
340
-
341
- _onBodyRef = (ref: any): void => {
342
- if (ref) {
343
- this._body = ref;
344
- // Mounting
345
- const el = ReactDOM.findDOMNode(ref);
346
- if (el instanceof HTMLElement) {
347
- ResizeObserver.observe(el, this._onBodyResize);
348
- }
349
- } else {
350
- // Unmounting.
351
- const el = this._body && ReactDOM.findDOMNode(this._body);
352
- if (el instanceof HTMLElement) {
353
- ResizeObserver.unobserve(el);
354
- }
355
- this._body = null;
356
- }
357
- };
358
-
359
- _onBodyResize = (info: ResizeObserverEntry): void => {
360
- const width = this._body
361
- ? getMaxResizeWidth(ReactDOM.findDOMNode(this._body))
362
- : MAX_SIZE;
363
-
364
- this.setState({
365
- maxSize: {
366
- width,
367
- height: MAX_SIZE,
368
- complete: !!this._body,
369
- },
370
- });
371
- };
372
- }
373
-
374
- class ImageNodeView extends CustomNodeView {
375
- // @override
376
- createDOMElement(): HTMLElement {
377
- const el = document.createElement('span');
378
- el.className = 'czi-image-view';
379
- this._updateDOM(el);
380
- return el;
381
- }
382
-
383
- // @override
384
- update(node: Node, decorations: Array<Decoration>): boolean {
385
- super.update(node, decorations);
386
- this._updateDOM(this.dom);
387
- return true;
388
- }
389
-
390
- // @override
391
- renderReactComponent(): React.Element<any> {
392
- return <ImageViewBody {...this.props} />;
393
- }
394
-
395
- _updateDOM(el: HTMLElement): void {
396
- const { align } = this.props.node.attrs;
397
- let className = 'czi-image-view';
398
- if (align) {
399
- className += ' align-' + align;
400
- }
401
- el.className = className;
402
- }
403
- }
404
-
405
- export default ImageNodeView;