@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.
- 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 +168 -169
- package/dist/buildEditorPlugins.js +1 -2
- package/dist/buildEditorPlugins.js.flow +0 -2
- 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 +3 -3
- package/src/EditorCommands.js +0 -4
- package/src/EditorNodes.js +0 -3
- package/src/buildEditorPlugins.js +0 -2
- 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 -403
- package/dist/ui/ImageNodeView.js.flow +0 -404
- 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/package-lock.json.old +0 -32889
- 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 -404
- package/src/ui/ImageResizeBox.js +0 -219
- package/src/ui/ImageURLEditor.js +0 -119
- package/src/ui/ImageUploadEditor.js +0 -117
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
|
|
5
|
-
import ImageSourceCommand from './ImageSourceCommand';
|
|
6
|
-
import ImageURLEditor from './ui/ImageURLEditor';
|
|
7
|
-
|
|
8
|
-
class ImageFromURLCommand extends ImageSourceCommand {
|
|
9
|
-
getEditor(): Class<React.Component<any, any>> {
|
|
10
|
-
return ImageURLEditor;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default ImageFromURLCommand;
|
package/src/ImageNodeSpec.js
DELETED
|
@@ -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;
|