@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.
- package/README.md +1 -0
- package/dist/EditorCommands.js +1 -7
- package/dist/EditorCommands.js.flow +0 -4
- package/dist/EditorNodes.js +0 -3
- package/dist/EditorNodes.js.flow +0 -3
- package/dist/bom.xml +225 -227
- package/dist/buildEditorPlugins.js +1 -2
- package/dist/buildEditorPlugins.js.flow +0 -2
- package/dist/client/Licit.js +7 -0
- package/dist/client/Licit.js.flow +9 -0
- package/dist/ui/Editor.js +0 -2
- package/dist/ui/Editor.js.flow +1 -3
- package/dist/ui/EditorToolbarConfig.js +0 -6
- package/dist/ui/EditorToolbarConfig.js.flow +0 -8
- package/package.json +6 -12
- package/src/EditorCommands.js +0 -4
- package/src/EditorNodes.js +0 -3
- package/src/buildEditorPlugins.js +0 -2
- package/src/client/Licit.js +9 -0
- package/src/ui/Editor.js +1 -3
- package/src/ui/EditorToolbarConfig.js +0 -8
- package/dist/ImageFromURLCommand.js +0 -19
- package/dist/ImageFromURLCommand.js.flow +0 -14
- package/dist/ImageNodeSpec.js +0 -109
- package/dist/ImageNodeSpec.js.flow +0 -90
- package/dist/ImageSourceCommand.js +0 -117
- package/dist/ImageSourceCommand.js.flow +0 -117
- package/dist/ImageUploadCommand.js +0 -49
- package/dist/ImageUploadCommand.js.flow +0 -36
- package/dist/ui/ImageAlignEditor.js +0 -71
- package/dist/ui/ImageAlignEditor.js.flow +0 -60
- package/dist/ui/ImageNodeView.js +0 -404
- package/dist/ui/ImageNodeView.js.flow +0 -405
- package/dist/ui/ImageResizeBox.js +0 -206
- package/dist/ui/ImageResizeBox.js.flow +0 -219
- package/dist/ui/ImageURLEditor.js +0 -108
- package/dist/ui/ImageURLEditor.js.flow +0 -119
- package/dist/ui/ImageUploadEditor.js +0 -123
- package/dist/ui/ImageUploadEditor.js.flow +0 -117
- package/src/ImageFromURLCommand.js +0 -14
- package/src/ImageNodeSpec.js +0 -90
- package/src/ImageSourceCommand.js +0 -117
- package/src/ImageUploadCommand.js +0 -36
- package/src/ui/ImageAlignEditor.js +0 -60
- package/src/ui/ImageNodeView.js +0 -405
- package/src/ui/ImageResizeBox.js +0 -219
- package/src/ui/ImageURLEditor.js +0 -119
- package/src/ui/ImageUploadEditor.js +0 -117
|
@@ -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;
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.MIN_SIZE = exports.MAX_SIZE = void 0;
|
|
7
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
|
-
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
9
|
-
var React = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _licitUiCommands = require("@modusoperandi/licit-ui-commands");
|
|
11
|
-
var _uuid = _interopRequireDefault(require("./uuid"));
|
|
12
|
-
require("./czi-image-resize-box.css");
|
|
13
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
19
|
-
const MIN_SIZE = 20;
|
|
20
|
-
exports.MIN_SIZE = MIN_SIZE;
|
|
21
|
-
const MAX_SIZE = 10000;
|
|
22
|
-
exports.MAX_SIZE = MAX_SIZE;
|
|
23
|
-
function setWidth(el, width, height) {
|
|
24
|
-
el.style.width = width + 'px';
|
|
25
|
-
}
|
|
26
|
-
function setHeight(el, width, height) {
|
|
27
|
-
el.style.height = height + 'px';
|
|
28
|
-
}
|
|
29
|
-
function setSize(el, width, height) {
|
|
30
|
-
el.style.width = Math.round(width) + 'px';
|
|
31
|
-
el.style.height = Math.round(height) + 'px';
|
|
32
|
-
}
|
|
33
|
-
const ResizeDirection = {
|
|
34
|
-
top: setHeight,
|
|
35
|
-
top_right: setSize,
|
|
36
|
-
right: setWidth,
|
|
37
|
-
bottom_right: setSize,
|
|
38
|
-
bottom: setHeight,
|
|
39
|
-
bottom_left: setSize,
|
|
40
|
-
left: setWidth,
|
|
41
|
-
top_left: setSize
|
|
42
|
-
};
|
|
43
|
-
class ImageResizeBoxControl extends React.PureComponent {
|
|
44
|
-
constructor() {
|
|
45
|
-
super(...arguments);
|
|
46
|
-
_defineProperty(this, "props", void 0);
|
|
47
|
-
_defineProperty(this, "_active", false);
|
|
48
|
-
_defineProperty(this, "_el", null);
|
|
49
|
-
_defineProperty(this, "_h", '');
|
|
50
|
-
_defineProperty(this, "_rafID", 0);
|
|
51
|
-
_defineProperty(this, "_w", '');
|
|
52
|
-
_defineProperty(this, "_x1", 0);
|
|
53
|
-
_defineProperty(this, "_x2", 0);
|
|
54
|
-
_defineProperty(this, "_y1", 0);
|
|
55
|
-
_defineProperty(this, "_y2", 0);
|
|
56
|
-
_defineProperty(this, "_ww", 0);
|
|
57
|
-
_defineProperty(this, "_hh", 0);
|
|
58
|
-
_defineProperty(this, "_syncSize", () => {
|
|
59
|
-
if (!this._active) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const {
|
|
63
|
-
direction,
|
|
64
|
-
width,
|
|
65
|
-
height
|
|
66
|
-
} = this.props;
|
|
67
|
-
const dx = (this._x2 - this._x1) * (/left/.test(direction) ? -1 : 1);
|
|
68
|
-
const dy = (this._y2 - this._y1) * (/top/.test(direction) ? -1 : 1);
|
|
69
|
-
const el = (0, _nullthrows.default)(this._el);
|
|
70
|
-
const fn = (0, _nullthrows.default)(ResizeDirection[direction]);
|
|
71
|
-
const aspect = width / height;
|
|
72
|
-
let ww = (0, _licitUiCommands.clamp)(MIN_SIZE, width + Math.round(dx), MAX_SIZE);
|
|
73
|
-
let hh = (0, _licitUiCommands.clamp)(MIN_SIZE, height + Math.round(dy), MAX_SIZE);
|
|
74
|
-
if (fn === setSize) {
|
|
75
|
-
hh = Math.max(ww / aspect, MIN_SIZE);
|
|
76
|
-
ww = hh * aspect;
|
|
77
|
-
}
|
|
78
|
-
fn(el, Math.round(ww), Math.round(hh));
|
|
79
|
-
this._ww = ww;
|
|
80
|
-
this._hh = hh;
|
|
81
|
-
});
|
|
82
|
-
_defineProperty(this, "_onMouseDown", e => {
|
|
83
|
-
e.preventDefault();
|
|
84
|
-
e.stopPropagation();
|
|
85
|
-
this._end();
|
|
86
|
-
this._start(e);
|
|
87
|
-
});
|
|
88
|
-
_defineProperty(this, "_onMouseMove", e => {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
e.stopPropagation();
|
|
91
|
-
this._x2 = e.clientX;
|
|
92
|
-
this._y2 = e.clientY;
|
|
93
|
-
this._rafID = requestAnimationFrame(this._syncSize);
|
|
94
|
-
});
|
|
95
|
-
_defineProperty(this, "_onMouseUp", e => {
|
|
96
|
-
e.preventDefault();
|
|
97
|
-
e.stopPropagation();
|
|
98
|
-
this._x2 = e.clientX;
|
|
99
|
-
this._y2 = e.clientY;
|
|
100
|
-
const {
|
|
101
|
-
direction
|
|
102
|
-
} = this.props;
|
|
103
|
-
const el = (0, _nullthrows.default)(this._el);
|
|
104
|
-
el.classList.remove(direction);
|
|
105
|
-
this._end();
|
|
106
|
-
this.props.onResizeEnd(this._ww, this._hh);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
componentWillUnmount() {
|
|
110
|
-
this._end();
|
|
111
|
-
}
|
|
112
|
-
render() {
|
|
113
|
-
const {
|
|
114
|
-
direction
|
|
115
|
-
} = this.props;
|
|
116
|
-
const className = (0, _classnames.default)({
|
|
117
|
-
'czi-image-resize-box-control': true,
|
|
118
|
-
[direction]: true
|
|
119
|
-
});
|
|
120
|
-
return /*#__PURE__*/React.createElement("span", {
|
|
121
|
-
className: className,
|
|
122
|
-
onMouseDown: this._onMouseDown
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
_start(e) {
|
|
126
|
-
if (this._active) {
|
|
127
|
-
this._end();
|
|
128
|
-
}
|
|
129
|
-
this._active = true;
|
|
130
|
-
const {
|
|
131
|
-
boxID,
|
|
132
|
-
direction,
|
|
133
|
-
width,
|
|
134
|
-
height
|
|
135
|
-
} = this.props;
|
|
136
|
-
const el = (0, _nullthrows.default)(document.getElementById(boxID));
|
|
137
|
-
el.className += ' ' + direction;
|
|
138
|
-
this._el = el;
|
|
139
|
-
this._x1 = e.clientX;
|
|
140
|
-
this._y1 = e.clientY;
|
|
141
|
-
this._x2 = this._x1;
|
|
142
|
-
this._y2 = this._y1;
|
|
143
|
-
this._w = this._el.style.width;
|
|
144
|
-
this._h = this._el.style.height;
|
|
145
|
-
this._ww = width;
|
|
146
|
-
this._hh = height;
|
|
147
|
-
document.addEventListener('mousemove', this._onMouseMove, true);
|
|
148
|
-
document.addEventListener('mouseup', this._onMouseUp, true);
|
|
149
|
-
}
|
|
150
|
-
_end() {
|
|
151
|
-
if (!this._active) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
this._active = false;
|
|
155
|
-
document.removeEventListener('mousemove', this._onMouseMove, true);
|
|
156
|
-
document.removeEventListener('mouseup', this._onMouseUp, true);
|
|
157
|
-
const el = (0, _nullthrows.default)(this._el);
|
|
158
|
-
el.style.width = this._w;
|
|
159
|
-
el.style.height = this._h;
|
|
160
|
-
el.className = 'czi-image-resize-box';
|
|
161
|
-
this._el = null;
|
|
162
|
-
this._rafID && cancelAnimationFrame(this._rafID);
|
|
163
|
-
this._rafID = null;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
class ImageResizeBox extends React.PureComponent {
|
|
167
|
-
constructor() {
|
|
168
|
-
super(...arguments);
|
|
169
|
-
_defineProperty(this, "props", void 0);
|
|
170
|
-
_defineProperty(this, "_id", (0, _uuid.default)());
|
|
171
|
-
}
|
|
172
|
-
render() {
|
|
173
|
-
const {
|
|
174
|
-
onResizeEnd,
|
|
175
|
-
width,
|
|
176
|
-
height,
|
|
177
|
-
src
|
|
178
|
-
} = this.props;
|
|
179
|
-
const style = {
|
|
180
|
-
height: height + 'px',
|
|
181
|
-
width: width + 'px'
|
|
182
|
-
};
|
|
183
|
-
const boxID = this._id;
|
|
184
|
-
const controls = Object.keys(ResizeDirection).map(key => {
|
|
185
|
-
return /*#__PURE__*/React.createElement(ImageResizeBoxControl, {
|
|
186
|
-
boxID: boxID,
|
|
187
|
-
config: ResizeDirection[key],
|
|
188
|
-
direction: key,
|
|
189
|
-
height: height,
|
|
190
|
-
key: key,
|
|
191
|
-
onResizeEnd: onResizeEnd,
|
|
192
|
-
width: width
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
return /*#__PURE__*/React.createElement("span", {
|
|
196
|
-
className: "czi-image-resize-box",
|
|
197
|
-
id: boxID,
|
|
198
|
-
style: style
|
|
199
|
-
}, controls, /*#__PURE__*/React.createElement("img", {
|
|
200
|
-
className: "czi-image-resize-box-image",
|
|
201
|
-
src: src
|
|
202
|
-
}));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
var _default = ImageResizeBox;
|
|
206
|
-
exports.default = _default;
|