@mirrormedia/lilith-draft-editor 1.1.0-alpha.25 → 1.1.0-alpha.27
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.
|
@@ -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
|
})));
|
|
@@ -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;
|
|
@@ -67,6 +67,8 @@ var _postSelector = require("./selector/post-selector");
|
|
|
67
67
|
|
|
68
68
|
var _audioSelector = require("./selector/audio-selector");
|
|
69
69
|
|
|
70
|
+
var _sharedStyle = require("./shared-style");
|
|
71
|
+
|
|
70
72
|
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); }
|
|
71
73
|
|
|
72
74
|
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; }
|
|
@@ -273,6 +275,12 @@ const DraftEditorWrapper = _styledComponents.default.div`
|
|
|
273
275
|
padding: 0 1rem 1rem;
|
|
274
276
|
font-size: 18px;
|
|
275
277
|
line-height: 2;
|
|
278
|
+
letter-spacing: 0.3px;
|
|
279
|
+
|
|
280
|
+
.public-DraftStyleDefault-block {
|
|
281
|
+
${_sharedStyle.defaultMarginBottom}
|
|
282
|
+
}
|
|
283
|
+
|
|
276
284
|
/* Draft built-in buttons' style */
|
|
277
285
|
.public-DraftStyleDefault-header-two {
|
|
278
286
|
font-size: 36px;
|
|
@@ -287,10 +295,12 @@ const DraftEditorWrapper = _styledComponents.default.div`
|
|
|
287
295
|
.public-DraftStyleDefault-blockquote {
|
|
288
296
|
}
|
|
289
297
|
.public-DraftStyleDefault-ul {
|
|
298
|
+
${_sharedStyle.defaultMarginBottom}
|
|
290
299
|
}
|
|
291
300
|
.public-DraftStyleDefault-unorderedListItem {
|
|
292
301
|
}
|
|
293
302
|
.public-DraftStyleDefault-ol {
|
|
303
|
+
${_sharedStyle.defaultMarginBottom}
|
|
294
304
|
}
|
|
295
305
|
.public-DraftStyleDefault-orderedListItem {
|
|
296
306
|
}
|
|
@@ -803,6 +813,7 @@ class RichTextEditor extends _react.default.Component {
|
|
|
803
813
|
var _this$refs$editor;
|
|
804
814
|
|
|
805
815
|
// eslint-disable-next-line prettier/prettier
|
|
816
|
+
;
|
|
806
817
|
(_this$refs$editor = this.refs.editor) === null || _this$refs$editor === void 0 ? void 0 : _this$refs$editor.focus();
|
|
807
818
|
}
|
|
808
819
|
}, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaultMarginTop = exports.defaultMarginBottom = void 0;
|
|
7
|
+
|
|
8
|
+
var _styledComponents = require("styled-components");
|
|
9
|
+
|
|
10
|
+
const defaultMarginTop = (0, _styledComponents.css)`
|
|
11
|
+
margin-top: 32px;
|
|
12
|
+
`;
|
|
13
|
+
exports.defaultMarginTop = defaultMarginTop;
|
|
14
|
+
const defaultMarginBottom = (0, _styledComponents.css)`
|
|
15
|
+
margin-bottom: 32px;
|
|
16
|
+
`;
|
|
17
|
+
exports.defaultMarginBottom = defaultMarginBottom;
|