@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,404 +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
- const imageSrc = await getProxyImageSrc(src);
78
- return imageSrc;
79
- }
80
- return src;
81
- }
82
- class ImageViewBody extends React.PureComponent {
83
- constructor() {
84
- super(...arguments);
85
- _defineProperty(this, "props", void 0);
86
- _defineProperty(this, "_body", null);
87
- _defineProperty(this, "_id", (0, _uuid.default)());
88
- _defineProperty(this, "_inlineEditor", null);
89
- _defineProperty(this, "_mounted", false);
90
- _defineProperty(this, "state", {
91
- maxSize: {
92
- width: MAX_SIZE,
93
- height: MAX_SIZE,
94
- complete: false
95
- },
96
- originalSize: DEFAULT_ORIGINAL_SIZE
97
- });
98
- _defineProperty(this, "_resolveOriginalSize", async () => {
99
- if (!this._mounted) {
100
- // unmounted;
101
- return;
102
- }
103
- this.setState({
104
- originalSize: DEFAULT_ORIGINAL_SIZE
105
- });
106
- const src = this.props.node.attrs.src;
107
- const url = await resolveURL(this.props.editorView.runtime, src);
108
- const originalSize = await (0, _resolveImage.default)(url);
109
- if (!this._mounted) {
110
- // unmounted;
111
- return;
112
- }
113
- if (this.props.node.attrs.src !== src) {
114
- // src had changed.
115
- return;
116
- }
117
- if (!originalSize.complete) {
118
- originalSize.width = _ImageResizeBox.MIN_SIZE;
119
- originalSize.height = _ImageResizeBox.MIN_SIZE;
120
- }
121
- this.setState({
122
- originalSize
123
- });
124
- });
125
- _defineProperty(this, "_onResizeEnd", (width, height) => {
126
- const {
127
- getPos,
128
- node,
129
- editorView
130
- } = this.props;
131
- const pos = getPos();
132
- const attrs = _objectSpread(_objectSpread({}, node.attrs), {}, {
133
- // TODO: Support UI for cropping later.
134
- crop: null,
135
- width,
136
- height
137
- });
138
- let tr = editorView.state.tr;
139
- const {
140
- selection
141
- } = editorView.state;
142
- tr = tr.setNodeMarkup(pos, null, attrs);
143
- // [FS] IRAD-1005 2020-07-09
144
- // Upgrade outdated packages.
145
- // reset selection to original using the latest doc.
146
- const origSelection = _prosemirrorState.NodeSelection.create(tr.doc, selection.from);
147
- tr = tr.setSelection(origSelection);
148
- editorView.dispatch(tr);
149
- });
150
- _defineProperty(this, "_onChange", value => {
151
- if (!this._mounted) {
152
- return;
153
- }
154
- const align = value ? value.align : null;
155
- const {
156
- getPos,
157
- node,
158
- editorView
159
- } = this.props;
160
- const pos = getPos();
161
- const attrs = _objectSpread(_objectSpread({}, node.attrs), {}, {
162
- align
163
- });
164
- let tr = editorView.state.tr;
165
- const {
166
- selection
167
- } = editorView.state;
168
- tr = tr.setNodeMarkup(pos, null, attrs);
169
- // [FS] IRAD-1005 2020-07-09
170
- // Upgrade outdated packages.
171
- // reset selection to original using the latest doc.
172
- const origSelection = _prosemirrorState.NodeSelection.create(tr.doc, selection.from);
173
- tr = tr.setSelection(origSelection);
174
- editorView.dispatch(tr);
175
- });
176
- _defineProperty(this, "_onBodyRef", ref => {
177
- if (ref) {
178
- this._body = ref;
179
- // Mounting
180
- const el = _reactDom.default.findDOMNode(ref);
181
- if (el instanceof HTMLElement) {
182
- _ResizeObserver.default.observe(el, this._onBodyResize);
183
- }
184
- } else {
185
- // Unmounting.
186
- const el = this._body && _reactDom.default.findDOMNode(this._body);
187
- if (el instanceof HTMLElement) {
188
- _ResizeObserver.default.unobserve(el);
189
- }
190
- this._body = null;
191
- }
192
- });
193
- _defineProperty(this, "_onBodyResize", info => {
194
- const width = this._body ? getMaxResizeWidth(_reactDom.default.findDOMNode(this._body)) : MAX_SIZE;
195
- this.setState({
196
- maxSize: {
197
- width,
198
- height: MAX_SIZE,
199
- complete: !!this._body
200
- }
201
- });
202
- });
203
- }
204
- componentDidMount() {
205
- this._mounted = true;
206
- this._resolveOriginalSize();
207
- this._renderInlineEditor();
208
- }
209
- componentWillUnmount() {
210
- this._mounted = false;
211
- this._inlineEditor && this._inlineEditor.close();
212
- this._inlineEditor = null;
213
- }
214
- componentDidUpdate(prevProps) {
215
- const prevSrc = prevProps.node.attrs.src;
216
- const {
217
- node
218
- } = this.props;
219
- const {
220
- src
221
- } = node.attrs;
222
- if (prevSrc !== src) {
223
- // A new image is provided, resolve it.
224
- this._resolveOriginalSize();
225
- }
226
- this._renderInlineEditor();
227
- }
228
- render() {
229
- const {
230
- originalSize,
231
- maxSize
232
- } = this.state;
233
- const {
234
- editorView,
235
- node,
236
- selected,
237
- focused
238
- } = this.props;
239
- const {
240
- readOnly
241
- } = editorView;
242
- const {
243
- attrs
244
- } = node;
245
- const {
246
- align,
247
- crop,
248
- rotate
249
- } = attrs;
250
-
251
- // It's only active when the image's fully loaded.
252
- const loading = originalSize === DEFAULT_ORIGINAL_SIZE;
253
- const active = !loading && focused && !readOnly && originalSize.complete;
254
- const src = originalSize.complete ? originalSize.src : EMPTY_SRC;
255
- const aspectRatio = loading ? 1 : originalSize.width / originalSize.height;
256
- const error = !loading && !originalSize.complete;
257
- let {
258
- width,
259
- height
260
- } = attrs;
261
- if (loading) {
262
- width = width || IMAGE_PLACEHOLDER_SIZE;
263
- height = height || IMAGE_PLACEHOLDER_SIZE;
264
- }
265
- if (width && !height) {
266
- height = width / aspectRatio;
267
- } else if (height && !width) {
268
- width = height * aspectRatio;
269
- } else if (!width && !height) {
270
- width = originalSize.width;
271
- height = originalSize.height;
272
- }
273
- let scale = 1;
274
- if (width > maxSize.width && (!crop || crop.width > maxSize.width)) {
275
- // Scale image to fit its containing space.
276
- // If the image is not cropped.
277
- width = maxSize.width;
278
- height = width / aspectRatio;
279
- scale = maxSize.width / width;
280
- }
281
- const className = (0, _classnames.default)('czi-image-view-body', {
282
- active,
283
- error,
284
- focused,
285
- loading,
286
- selected
287
- });
288
- const resizeBox = active && !crop && !rotate ? /*#__PURE__*/React.createElement(_ImageResizeBox.default, {
289
- height: height,
290
- onResizeEnd: this._onResizeEnd,
291
- src: src,
292
- width: width
293
- }) : null;
294
- const imageStyle = {
295
- display: 'inline-block',
296
- height: height + 'px',
297
- left: '0',
298
- top: '0',
299
- width: width + 'px',
300
- position: 'relative'
301
- };
302
- const clipStyle = {};
303
- if (crop) {
304
- const cropped = _objectSpread({}, crop);
305
- if (scale !== 1) {
306
- scale = maxSize.width / cropped.width;
307
- cropped.width *= scale;
308
- cropped.height *= scale;
309
- cropped.left *= scale;
310
- cropped.top *= scale;
311
- }
312
- clipStyle.width = cropped.width + 'px';
313
- clipStyle.height = cropped.height + 'px';
314
- imageStyle.left = cropped.left + 'px';
315
- imageStyle.top = cropped.top + 'px';
316
- }
317
- if (rotate) {
318
- clipStyle.transform = `rotate(${rotate}rad)`;
319
- }
320
- const errorView = error ? _Icon.default.get('error') : null;
321
- const errorTitle = error ? `Unable to load image from ${attrs.src || ''}` : undefined;
322
- return /*#__PURE__*/React.createElement("span", {
323
- className: className,
324
- "data-active": active ? 'true' : undefined,
325
- "data-original-src": String(attrs.src),
326
- id: this._id,
327
- ref: this._onBodyRef,
328
- title: errorTitle
329
- }, /*#__PURE__*/React.createElement("span", {
330
- className: "czi-image-view-body-img-clip",
331
- style: clipStyle
332
- }, /*#__PURE__*/React.createElement("span", {
333
- style: imageStyle
334
- }, /*#__PURE__*/React.createElement("img", {
335
- alt: "",
336
- className: "czi-image-view-body-img",
337
- "data-align": align,
338
- height: height,
339
- id: `${this._id}-img`,
340
- src: src,
341
- width: width
342
- }), errorView)), resizeBox);
343
- }
344
- _renderInlineEditor() {
345
- const el = document.getElementById(this._id);
346
- if (!el || el.getAttribute('data-active') !== 'true') {
347
- this._inlineEditor && this._inlineEditor.close();
348
- return;
349
- }
350
- const {
351
- node
352
- } = this.props;
353
- const editorProps = {
354
- value: node.attrs,
355
- onSelect: this._onChange
356
- };
357
- if (this._inlineEditor) {
358
- this._inlineEditor.update(editorProps);
359
- } else {
360
- this._inlineEditor = (0, _licitUiCommands.createPopUp)(_ImageInlineEditor.default, editorProps, {
361
- anchor: el,
362
- autoDismiss: false,
363
- container: el.closest(`.${_EditorFrameset.FRAMESET_BODY_CLASSNAME}`),
364
- position: _licitUiCommands.atAnchorBottomCenter,
365
- onClose: () => {
366
- this._inlineEditor = null;
367
- }
368
- });
369
- }
370
- }
371
- }
372
- class ImageNodeView extends _CustomNodeView.default {
373
- // @override
374
- createDOMElement() {
375
- const el = document.createElement('span');
376
- el.className = 'czi-image-view';
377
- this._updateDOM(el);
378
- return el;
379
- }
380
-
381
- // @override
382
- update(node, decorations) {
383
- super.update(node, decorations);
384
- this._updateDOM(this.dom);
385
- return true;
386
- }
387
-
388
- // @override
389
- renderReactComponent() {
390
- return /*#__PURE__*/React.createElement(ImageViewBody, this.props);
391
- }
392
- _updateDOM(el) {
393
- const {
394
- align
395
- } = this.props.node.attrs;
396
- let className = 'czi-image-view';
397
- if (align) {
398
- className += ' align-' + align;
399
- }
400
- el.className = className;
401
- }
402
- }
403
- var _default = ImageNodeView;
404
- exports.default = _default;