@modusoperandi/licit 0.14.0 → 0.14.2

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 (45) hide show
  1. package/dist/EditorCommands.js +1 -7
  2. package/dist/EditorCommands.js.flow +0 -4
  3. package/dist/EditorNodes.js +0 -3
  4. package/dist/EditorNodes.js.flow +0 -3
  5. package/dist/bom.xml +168 -169
  6. package/dist/buildEditorPlugins.js +1 -2
  7. package/dist/buildEditorPlugins.js.flow +0 -2
  8. package/dist/ui/Editor.js +0 -2
  9. package/dist/ui/Editor.js.flow +1 -3
  10. package/dist/ui/EditorToolbarConfig.js +0 -6
  11. package/dist/ui/EditorToolbarConfig.js.flow +0 -8
  12. package/package.json +3 -3
  13. package/src/EditorCommands.js +0 -4
  14. package/src/EditorNodes.js +0 -3
  15. package/src/buildEditorPlugins.js +0 -2
  16. package/src/ui/Editor.js +1 -3
  17. package/src/ui/EditorToolbarConfig.js +0 -8
  18. package/dist/ImageFromURLCommand.js +0 -19
  19. package/dist/ImageFromURLCommand.js.flow +0 -14
  20. package/dist/ImageNodeSpec.js +0 -109
  21. package/dist/ImageNodeSpec.js.flow +0 -90
  22. package/dist/ImageSourceCommand.js +0 -117
  23. package/dist/ImageSourceCommand.js.flow +0 -117
  24. package/dist/ImageUploadCommand.js +0 -49
  25. package/dist/ImageUploadCommand.js.flow +0 -36
  26. package/dist/ui/ImageAlignEditor.js +0 -71
  27. package/dist/ui/ImageAlignEditor.js.flow +0 -60
  28. package/dist/ui/ImageNodeView.js +0 -403
  29. package/dist/ui/ImageNodeView.js.flow +0 -404
  30. package/dist/ui/ImageResizeBox.js +0 -206
  31. package/dist/ui/ImageResizeBox.js.flow +0 -219
  32. package/dist/ui/ImageURLEditor.js +0 -108
  33. package/dist/ui/ImageURLEditor.js.flow +0 -119
  34. package/dist/ui/ImageUploadEditor.js +0 -123
  35. package/dist/ui/ImageUploadEditor.js.flow +0 -117
  36. package/package-lock.json.old +0 -32889
  37. package/src/ImageFromURLCommand.js +0 -14
  38. package/src/ImageNodeSpec.js +0 -90
  39. package/src/ImageSourceCommand.js +0 -117
  40. package/src/ImageUploadCommand.js +0 -36
  41. package/src/ui/ImageAlignEditor.js +0 -60
  42. package/src/ui/ImageNodeView.js +0 -404
  43. package/src/ui/ImageResizeBox.js +0 -219
  44. package/src/ui/ImageURLEditor.js +0 -119
  45. package/src/ui/ImageUploadEditor.js +0 -117
@@ -1,403 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _classnames = _interopRequireDefault(require("classnames"));
8
- var _prosemirrorModel = require("prosemirror-model");
9
- var _prosemirrorView = require("prosemirror-view");
10
- var _prosemirrorState = require("prosemirror-state");
11
- var React = _interopRequireWildcard(require("react"));
12
- var _reactDom = _interopRequireDefault(require("react-dom"));
13
- var _CustomNodeView = _interopRequireWildcard(require("./CustomNodeView"));
14
- var _EditorFrameset = require("./EditorFrameset");
15
- var _Icon = _interopRequireDefault(require("./Icon"));
16
- var _ImageInlineEditor = _interopRequireDefault(require("./ImageInlineEditor"));
17
- var _ImageResizeBox = _interopRequireWildcard(require("./ImageResizeBox"));
18
- var _licitUiCommands = require("@modusoperandi/licit-ui-commands");
19
- var _ResizeObserver = _interopRequireWildcard(require("./ResizeObserver"));
20
- var _resolveImage = _interopRequireDefault(require("./resolveImage"));
21
- var _uuid = _interopRequireDefault(require("./uuid"));
22
- require("./czi-image-view.css");
23
- var _Types = require("../Types");
24
- 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); }
25
- 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; }
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
28
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
29
- 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; }
30
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
31
- 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); }
32
- const EMPTY_SRC = 'data:image/gif;base64,' + 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
33
-
34
- /* This value must be synced with the margin defined at .czi-image-view */
35
- const IMAGE_MARGIN = 2;
36
- const MAX_SIZE = 100000;
37
- const IMAGE_PLACEHOLDER_SIZE = 24;
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) {
47
- // Ideally, the image should bot be wider then its containing element.
48
- let node = el.parentElement;
49
- while (node && !node.offsetParent) {
50
- node = node.parentElement;
51
- }
52
- if (node && node.offsetParent && node.offsetParent.offsetWidth && node.offsetParent.offsetWidth > 0) {
53
- const {
54
- offsetParent
55
- } = node;
56
- const style = el.ownerDocument.defaultView.getComputedStyle(offsetParent);
57
- let width = offsetParent.clientWidth - IMAGE_MARGIN * 2;
58
- if (style.boxSizing === 'border-box') {
59
- const pl = parseInt(style.paddingLeft, 10);
60
- const pr = parseInt(style.paddingRight, 10);
61
- width -= pl + pr;
62
- }
63
- return Math.max(width, _ImageResizeBox.MIN_SIZE);
64
- }
65
- // Let the image resize freely.
66
- return MAX_SIZE;
67
- }
68
- async function resolveURL(runtime, src) {
69
- if (!runtime) {
70
- return src;
71
- }
72
- const {
73
- canProxyImageSrc,
74
- getProxyImageSrc
75
- } = runtime;
76
- if (src && canProxyImageSrc && getProxyImageSrc && canProxyImageSrc(src)) {
77
- return await getProxyImageSrc(src);
78
- }
79
- return src;
80
- }
81
- class ImageViewBody extends React.PureComponent {
82
- constructor() {
83
- super(...arguments);
84
- _defineProperty(this, "props", void 0);
85
- _defineProperty(this, "_body", null);
86
- _defineProperty(this, "_id", (0, _uuid.default)());
87
- _defineProperty(this, "_inlineEditor", null);
88
- _defineProperty(this, "_mounted", false);
89
- _defineProperty(this, "state", {
90
- maxSize: {
91
- width: MAX_SIZE,
92
- height: MAX_SIZE,
93
- complete: false
94
- },
95
- originalSize: DEFAULT_ORIGINAL_SIZE
96
- });
97
- _defineProperty(this, "_resolveOriginalSize", async () => {
98
- if (!this._mounted) {
99
- // unmounted;
100
- return;
101
- }
102
- this.setState({
103
- originalSize: DEFAULT_ORIGINAL_SIZE
104
- });
105
- const src = this.props.node.attrs.src;
106
- const url = await resolveURL(this.props.editorView.runtime, src);
107
- const originalSize = await (0, _resolveImage.default)(url);
108
- if (!this._mounted) {
109
- // unmounted;
110
- return;
111
- }
112
- if (this.props.node.attrs.src !== src) {
113
- // src had changed.
114
- return;
115
- }
116
- if (!originalSize.complete) {
117
- originalSize.width = _ImageResizeBox.MIN_SIZE;
118
- originalSize.height = _ImageResizeBox.MIN_SIZE;
119
- }
120
- this.setState({
121
- originalSize
122
- });
123
- });
124
- _defineProperty(this, "_onResizeEnd", (width, height) => {
125
- const {
126
- getPos,
127
- node,
128
- editorView
129
- } = this.props;
130
- const pos = getPos();
131
- const attrs = _objectSpread(_objectSpread({}, node.attrs), {}, {
132
- // TODO: Support UI for cropping later.
133
- crop: null,
134
- width,
135
- height
136
- });
137
- let tr = editorView.state.tr;
138
- const {
139
- selection
140
- } = editorView.state;
141
- tr = tr.setNodeMarkup(pos, null, attrs);
142
- // [FS] IRAD-1005 2020-07-09
143
- // Upgrade outdated packages.
144
- // reset selection to original using the latest doc.
145
- const origSelection = _prosemirrorState.NodeSelection.create(tr.doc, selection.from);
146
- tr = tr.setSelection(origSelection);
147
- editorView.dispatch(tr);
148
- });
149
- _defineProperty(this, "_onChange", value => {
150
- if (!this._mounted) {
151
- return;
152
- }
153
- const align = value ? value.align : null;
154
- const {
155
- getPos,
156
- node,
157
- editorView
158
- } = this.props;
159
- const pos = getPos();
160
- const attrs = _objectSpread(_objectSpread({}, node.attrs), {}, {
161
- align
162
- });
163
- let tr = editorView.state.tr;
164
- const {
165
- selection
166
- } = editorView.state;
167
- tr = tr.setNodeMarkup(pos, null, attrs);
168
- // [FS] IRAD-1005 2020-07-09
169
- // Upgrade outdated packages.
170
- // reset selection to original using the latest doc.
171
- const origSelection = _prosemirrorState.NodeSelection.create(tr.doc, selection.from);
172
- tr = tr.setSelection(origSelection);
173
- editorView.dispatch(tr);
174
- });
175
- _defineProperty(this, "_onBodyRef", ref => {
176
- if (ref) {
177
- this._body = ref;
178
- // Mounting
179
- const el = _reactDom.default.findDOMNode(ref);
180
- if (el instanceof HTMLElement) {
181
- _ResizeObserver.default.observe(el, this._onBodyResize);
182
- }
183
- } else {
184
- // Unmounting.
185
- const el = this._body && _reactDom.default.findDOMNode(this._body);
186
- if (el instanceof HTMLElement) {
187
- _ResizeObserver.default.unobserve(el);
188
- }
189
- this._body = null;
190
- }
191
- });
192
- _defineProperty(this, "_onBodyResize", info => {
193
- const width = this._body ? getMaxResizeWidth(_reactDom.default.findDOMNode(this._body)) : MAX_SIZE;
194
- this.setState({
195
- maxSize: {
196
- width,
197
- height: MAX_SIZE,
198
- complete: !!this._body
199
- }
200
- });
201
- });
202
- }
203
- componentDidMount() {
204
- this._mounted = true;
205
- this._resolveOriginalSize();
206
- this._renderInlineEditor();
207
- }
208
- componentWillUnmount() {
209
- this._mounted = false;
210
- this._inlineEditor && this._inlineEditor.close();
211
- this._inlineEditor = null;
212
- }
213
- componentDidUpdate(prevProps) {
214
- const prevSrc = prevProps.node.attrs.src;
215
- const {
216
- node
217
- } = this.props;
218
- const {
219
- src
220
- } = node.attrs;
221
- if (prevSrc !== src) {
222
- // A new image is provided, resolve it.
223
- this._resolveOriginalSize();
224
- }
225
- this._renderInlineEditor();
226
- }
227
- render() {
228
- const {
229
- originalSize,
230
- maxSize
231
- } = this.state;
232
- const {
233
- editorView,
234
- node,
235
- selected,
236
- focused
237
- } = this.props;
238
- const {
239
- readOnly
240
- } = editorView;
241
- const {
242
- attrs
243
- } = node;
244
- const {
245
- align,
246
- crop,
247
- rotate
248
- } = attrs;
249
-
250
- // It's only active when the image's fully loaded.
251
- const loading = originalSize === DEFAULT_ORIGINAL_SIZE;
252
- const active = !loading && focused && !readOnly && originalSize.complete;
253
- const src = originalSize.complete ? originalSize.src : EMPTY_SRC;
254
- const aspectRatio = loading ? 1 : originalSize.width / originalSize.height;
255
- const error = !loading && !originalSize.complete;
256
- let {
257
- width,
258
- height
259
- } = attrs;
260
- if (loading) {
261
- width = width || IMAGE_PLACEHOLDER_SIZE;
262
- height = height || IMAGE_PLACEHOLDER_SIZE;
263
- }
264
- if (width && !height) {
265
- height = width / aspectRatio;
266
- } else if (height && !width) {
267
- width = height * aspectRatio;
268
- } else if (!width && !height) {
269
- width = originalSize.width;
270
- height = originalSize.height;
271
- }
272
- let scale = 1;
273
- if (width > maxSize.width && (!crop || crop.width > maxSize.width)) {
274
- // Scale image to fit its containing space.
275
- // If the image is not cropped.
276
- width = maxSize.width;
277
- height = width / aspectRatio;
278
- scale = maxSize.width / width;
279
- }
280
- const className = (0, _classnames.default)('czi-image-view-body', {
281
- active,
282
- error,
283
- focused,
284
- loading,
285
- selected
286
- });
287
- const resizeBox = active && !crop && !rotate ? /*#__PURE__*/React.createElement(_ImageResizeBox.default, {
288
- height: height,
289
- onResizeEnd: this._onResizeEnd,
290
- src: src,
291
- width: width
292
- }) : null;
293
- const imageStyle = {
294
- display: 'inline-block',
295
- height: height + 'px',
296
- left: '0',
297
- top: '0',
298
- width: width + 'px',
299
- position: 'relative'
300
- };
301
- const clipStyle = {};
302
- if (crop) {
303
- const cropped = _objectSpread({}, crop);
304
- if (scale !== 1) {
305
- scale = maxSize.width / cropped.width;
306
- cropped.width *= scale;
307
- cropped.height *= scale;
308
- cropped.left *= scale;
309
- cropped.top *= scale;
310
- }
311
- clipStyle.width = cropped.width + 'px';
312
- clipStyle.height = cropped.height + 'px';
313
- imageStyle.left = cropped.left + 'px';
314
- imageStyle.top = cropped.top + 'px';
315
- }
316
- if (rotate) {
317
- clipStyle.transform = `rotate(${rotate}rad)`;
318
- }
319
- const errorView = error ? _Icon.default.get('error') : null;
320
- const errorTitle = error ? `Unable to load image from ${attrs.src || ''}` : undefined;
321
- return /*#__PURE__*/React.createElement("span", {
322
- className: className,
323
- "data-active": active ? 'true' : undefined,
324
- "data-original-src": String(attrs.src),
325
- id: this._id,
326
- ref: this._onBodyRef,
327
- title: errorTitle
328
- }, /*#__PURE__*/React.createElement("span", {
329
- className: "czi-image-view-body-img-clip",
330
- style: clipStyle
331
- }, /*#__PURE__*/React.createElement("span", {
332
- style: imageStyle
333
- }, /*#__PURE__*/React.createElement("img", {
334
- alt: "",
335
- className: "czi-image-view-body-img",
336
- "data-align": align,
337
- height: height,
338
- id: `${this._id}-img`,
339
- src: src,
340
- width: width
341
- }), errorView)), resizeBox);
342
- }
343
- _renderInlineEditor() {
344
- const el = document.getElementById(this._id);
345
- if (!el || el.getAttribute('data-active') !== 'true') {
346
- this._inlineEditor && this._inlineEditor.close();
347
- return;
348
- }
349
- const {
350
- node
351
- } = this.props;
352
- const editorProps = {
353
- value: node.attrs,
354
- onSelect: this._onChange
355
- };
356
- if (this._inlineEditor) {
357
- this._inlineEditor.update(editorProps);
358
- } else {
359
- this._inlineEditor = (0, _licitUiCommands.createPopUp)(_ImageInlineEditor.default, editorProps, {
360
- anchor: el,
361
- autoDismiss: false,
362
- container: el.closest(`.${_EditorFrameset.FRAMESET_BODY_CLASSNAME}`),
363
- position: _licitUiCommands.atAnchorBottomCenter,
364
- onClose: () => {
365
- this._inlineEditor = null;
366
- }
367
- });
368
- }
369
- }
370
- }
371
- class ImageNodeView extends _CustomNodeView.default {
372
- // @override
373
- createDOMElement() {
374
- const el = document.createElement('span');
375
- el.className = 'czi-image-view';
376
- this._updateDOM(el);
377
- return el;
378
- }
379
-
380
- // @override
381
- update(node, decorations) {
382
- super.update(node, decorations);
383
- this._updateDOM(this.dom);
384
- return true;
385
- }
386
-
387
- // @override
388
- renderReactComponent() {
389
- return /*#__PURE__*/React.createElement(ImageViewBody, this.props);
390
- }
391
- _updateDOM(el) {
392
- const {
393
- align
394
- } = this.props.node.attrs;
395
- let className = 'czi-image-view';
396
- if (align) {
397
- className += ' align-' + align;
398
- }
399
- el.className = className;
400
- }
401
- }
402
- var _default = ImageNodeView;
403
- exports.default = _default;