@mirrormedia/lilith-draft-editor 1.1.0-alpha.24 → 1.1.0-alpha.26
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/lib/draft-js/buttons/link.js +49 -22
- package/lib/draft-js/buttons/video.js +3 -2
- package/lib/draft-js/draft-converter/atomic-block-processor.js +1 -0
- package/lib/draft-js/draft-converter/entities.js +3 -0
- package/lib/draft-js/util.js +32 -0
- package/lib/website/mirrormedia/block-renderer-fn.js +6 -0
- package/lib/website/mirrormedia/selector/video-selector.js +3 -3
- package/package.json +2 -2
|
@@ -7,32 +7,40 @@ exports.LinkButton = LinkButton;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
|
|
10
12
|
var _modals = require("@keystone-ui/modals");
|
|
11
13
|
|
|
12
14
|
var _draftJs = require("draft-js");
|
|
13
15
|
|
|
14
16
|
var _fields = require("@keystone-ui/fields");
|
|
15
17
|
|
|
18
|
+
var _util = require("../util");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
16
22
|
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); }
|
|
17
23
|
|
|
18
24
|
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; }
|
|
19
25
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
};
|
|
26
|
+
const StyledTextInput = (0, _styledComponents.default)(_fields.TextInput)`
|
|
27
|
+
fontfamily: Georgia, serif;
|
|
28
|
+
marginright: 10;
|
|
29
|
+
padding: 10;
|
|
30
|
+
`;
|
|
27
31
|
|
|
28
32
|
function LinkButton(props) {
|
|
29
33
|
const {
|
|
30
|
-
isActive,
|
|
31
34
|
editorState,
|
|
32
35
|
onChange
|
|
33
36
|
} = props;
|
|
37
|
+
const entityData = (0, _util.getSelectionEntityData)(editorState);
|
|
38
|
+
const url = (entityData === null || entityData === void 0 ? void 0 : entityData.url) || '';
|
|
39
|
+
(0, _react.useEffect)(() => {
|
|
40
|
+
setLinkUrl(url);
|
|
41
|
+
}, [url]);
|
|
34
42
|
const [toShowUrlInput, setToShowUrlInput] = (0, _react.useState)(false);
|
|
35
|
-
const [
|
|
43
|
+
const [linkUrl, setLinkUrl] = (0, _react.useState)(url || '');
|
|
36
44
|
|
|
37
45
|
const promptForLink = e => {
|
|
38
46
|
e.preventDefault();
|
|
@@ -46,7 +54,7 @@ function LinkButton(props) {
|
|
|
46
54
|
const confirmLink = () => {
|
|
47
55
|
const contentState = editorState.getCurrentContent();
|
|
48
56
|
const contentStateWithEntity = contentState.createEntity('LINK', 'MUTABLE', {
|
|
49
|
-
url:
|
|
57
|
+
url: linkUrl
|
|
50
58
|
});
|
|
51
59
|
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
52
60
|
|
|
@@ -54,9 +62,11 @@ function LinkButton(props) {
|
|
|
54
62
|
currentContent: contentStateWithEntity
|
|
55
63
|
});
|
|
56
64
|
|
|
57
|
-
|
|
65
|
+
const selection = newEditorState.getSelection(); // RichUtils.toggleLink will reset selection back to first block and cause
|
|
66
|
+
// the editor scroll to top. Use `forceSelection` to hold the selection.
|
|
67
|
+
|
|
68
|
+
onChange(_draftJs.EditorState.forceSelection(_draftJs.RichUtils.toggleLink(newEditorState, selection, entityKey), selection));
|
|
58
69
|
setToShowUrlInput(false);
|
|
59
|
-
setUrlValue('');
|
|
60
70
|
};
|
|
61
71
|
|
|
62
72
|
const onLinkInputKeyDown = e => {
|
|
@@ -70,16 +80,28 @@ function LinkButton(props) {
|
|
|
70
80
|
const selection = editorState.getSelection();
|
|
71
81
|
|
|
72
82
|
if (!selection.isCollapsed()) {
|
|
73
|
-
|
|
83
|
+
// RichUtils.toggleLink will reset selection back to first block and cause
|
|
84
|
+
// the editor scroll to top. Use `forceSelection` to hold the selection.
|
|
85
|
+
onChange(_draftJs.EditorState.forceSelection(_draftJs.RichUtils.toggleLink(editorState, selection, null), selection));
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
setToShowUrlInput(false);
|
|
77
|
-
setUrlValue('');
|
|
78
89
|
};
|
|
79
90
|
|
|
80
|
-
const
|
|
81
|
-
title:
|
|
82
|
-
|
|
91
|
+
const alertProps = linkUrl ? {
|
|
92
|
+
title: 'Update Link',
|
|
93
|
+
actions: {
|
|
94
|
+
cancel: {
|
|
95
|
+
label: 'Remove',
|
|
96
|
+
action: removeLink
|
|
97
|
+
},
|
|
98
|
+
confirm: {
|
|
99
|
+
label: 'Update',
|
|
100
|
+
action: confirmLink
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} : {
|
|
104
|
+
title: 'Insert Link',
|
|
83
105
|
actions: {
|
|
84
106
|
cancel: {
|
|
85
107
|
label: 'Cancel',
|
|
@@ -90,17 +112,22 @@ function LinkButton(props) {
|
|
|
90
112
|
action: confirmLink
|
|
91
113
|
}
|
|
92
114
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const urlInput = /*#__PURE__*/_react.default.createElement(_modals.AlertDialog, {
|
|
118
|
+
title: alertProps.title,
|
|
119
|
+
isOpen: toShowUrlInput,
|
|
120
|
+
actions: alertProps.actions
|
|
121
|
+
}, /*#__PURE__*/_react.default.createElement(StyledTextInput, {
|
|
122
|
+
onChange: e => setLinkUrl(e.target.value),
|
|
123
|
+
value: linkUrl,
|
|
96
124
|
type: "text",
|
|
97
|
-
value: urlValue,
|
|
98
125
|
onKeyDown: onLinkInputKeyDown
|
|
99
126
|
}));
|
|
100
127
|
|
|
101
128
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, urlInput, /*#__PURE__*/_react.default.createElement("div", {
|
|
102
129
|
className: props.className,
|
|
103
|
-
onMouseDown:
|
|
130
|
+
onMouseDown: promptForLink
|
|
104
131
|
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
105
132
|
className: "fas fa-link"
|
|
106
133
|
})));
|
|
@@ -38,8 +38,9 @@ function VideoButton(props) {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const contentState = editorState.getCurrentContent();
|
|
42
|
-
|
|
41
|
+
const contentState = editorState.getCurrentContent(); // since 202310, only VIDEO-V2 will be created
|
|
42
|
+
|
|
43
|
+
const contentStateWithEntity = contentState.createEntity('VIDEO-V2', 'IMMUTABLE', {
|
|
43
44
|
video
|
|
44
45
|
});
|
|
45
46
|
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
@@ -138,6 +138,7 @@ const processor = {
|
|
|
138
138
|
case _entities.default.SLIDESHOW.type:
|
|
139
139
|
case _entities.default['SLIDESHOW-V2'].type:
|
|
140
140
|
case _entities.default.VIDEO.type:
|
|
141
|
+
case _entities.default['VIDEO-V2'].type:
|
|
141
142
|
case _entities.default.YOUTUBE.type:
|
|
142
143
|
case _entities.default.BACKGROUNDIMAGE.type:
|
|
143
144
|
case _entities.default.BACKGROUNDVIDEO.type:
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelectionEntityData = void 0;
|
|
7
|
+
|
|
8
|
+
const getSelectionEntityData = editorState => {
|
|
9
|
+
const selection = editorState.getSelection();
|
|
10
|
+
const startOffset = selection.getStartOffset();
|
|
11
|
+
const startBlock = editorState.getCurrentContent().getBlockForKey(selection.getStartKey());
|
|
12
|
+
let data;
|
|
13
|
+
let entityInstance;
|
|
14
|
+
let entityKey;
|
|
15
|
+
|
|
16
|
+
if (!selection.isCollapsed()) {
|
|
17
|
+
entityKey = startBlock.getEntityAt(startOffset);
|
|
18
|
+
} else {
|
|
19
|
+
entityKey = startBlock.getEntityAt(0);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const contentState = editorState.getCurrentContent();
|
|
23
|
+
|
|
24
|
+
if (entityKey !== null) {
|
|
25
|
+
entityInstance = contentState.getEntity(entityKey);
|
|
26
|
+
data = entityInstance.getData();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return data;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.getSelectionEntityData = getSelectionEntityData;
|
|
@@ -32,6 +32,7 @@ const {
|
|
|
32
32
|
DividerBlock,
|
|
33
33
|
RelatedPostBlock,
|
|
34
34
|
VideoBlock,
|
|
35
|
+
VideoBlockV2,
|
|
35
36
|
AudioBlock,
|
|
36
37
|
YoutubeBlock
|
|
37
38
|
} = _mirrormedia.default.blockRenderers;
|
|
@@ -113,6 +114,11 @@ const AtomicBlock = props => {
|
|
|
113
114
|
return VideoBlock(entity);
|
|
114
115
|
}
|
|
115
116
|
|
|
117
|
+
case 'VIDEO-V2':
|
|
118
|
+
{
|
|
119
|
+
return VideoBlockV2(entity);
|
|
120
|
+
}
|
|
121
|
+
|
|
116
122
|
case 'AUDIO':
|
|
117
123
|
{
|
|
118
124
|
return AudioBlock(entity);
|
|
@@ -34,7 +34,7 @@ const videosQuery = (0, _apollo.gql)`
|
|
|
34
34
|
) {
|
|
35
35
|
id
|
|
36
36
|
name
|
|
37
|
-
|
|
37
|
+
videoSrc
|
|
38
38
|
file {
|
|
39
39
|
filename
|
|
40
40
|
filesize
|
|
@@ -136,7 +136,7 @@ function VideoGrid(props) {
|
|
|
136
136
|
muted: true,
|
|
137
137
|
loop: true
|
|
138
138
|
}, /*#__PURE__*/_react.default.createElement("source", {
|
|
139
|
-
src: video === null || video === void 0 ? void 0 : video.
|
|
139
|
+
src: video === null || video === void 0 ? void 0 : video.videoSrc
|
|
140
140
|
}), /*#__PURE__*/_react.default.createElement("source", {
|
|
141
141
|
src: video === null || video === void 0 ? void 0 : (_video$file = video.file) === null || _video$file === void 0 ? void 0 : _video$file.url
|
|
142
142
|
})));
|
|
@@ -170,7 +170,7 @@ function VideoMetaGrid(props) {
|
|
|
170
170
|
autoPlay: true,
|
|
171
171
|
loop: true
|
|
172
172
|
}, /*#__PURE__*/_react.default.createElement("source", {
|
|
173
|
-
src: video === null || video === void 0 ? void 0 : video.
|
|
173
|
+
src: video === null || video === void 0 ? void 0 : video.videoSrc
|
|
174
174
|
}), /*#__PURE__*/_react.default.createElement("source", {
|
|
175
175
|
src: video === null || video === void 0 ? void 0 : (_video$file2 = video.file) === null || _video$file2 === void 0 ? void 0 : _video$file2.url
|
|
176
176
|
})), /*#__PURE__*/_react.default.createElement(VideoName, null, video === null || video === void 0 ? void 0 : video.name));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirrormedia/lilith-draft-editor",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"draft-js": "^0.11.7",
|
|
26
|
-
"@mirrormedia/lilith-draft-renderer": "1.3.0-alpha.
|
|
26
|
+
"@mirrormedia/lilith-draft-renderer": "1.3.0-alpha.7"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "18.2.0",
|