@mirrormedia/lilith-draft-editor 1.1.0-alpha.15 → 1.1.0-alpha.17
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.
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.YoutubeButton = YoutubeButton;
|
|
7
|
+
exports.YoutubeInput = YoutubeInput;
|
|
8
|
+
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
|
|
11
|
+
var _draftJs = require("draft-js");
|
|
12
|
+
|
|
13
|
+
var _modals = require("@keystone-ui/modals");
|
|
14
|
+
|
|
15
|
+
var _fields = require("@keystone-ui/fields");
|
|
16
|
+
|
|
17
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
18
|
+
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
|
|
21
|
+
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); }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
25
|
+
const Label = _styledComponents.default.label`
|
|
26
|
+
display: block;
|
|
27
|
+
font-weight: 600;
|
|
28
|
+
margin: 10px 0;
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
function YoutubeInput(props) {
|
|
32
|
+
const {
|
|
33
|
+
isOpen,
|
|
34
|
+
onChange,
|
|
35
|
+
onCancel
|
|
36
|
+
} = props;
|
|
37
|
+
const initialInputValue = {
|
|
38
|
+
description: '',
|
|
39
|
+
youtubeId: ''
|
|
40
|
+
};
|
|
41
|
+
const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
|
|
42
|
+
|
|
43
|
+
const clearInputValue = () => {
|
|
44
|
+
setInputValue(initialInputValue);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
|
|
48
|
+
isOpen: isOpen
|
|
49
|
+
}, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
|
|
50
|
+
title: `Insert Youtube video`,
|
|
51
|
+
actions: {
|
|
52
|
+
cancel: {
|
|
53
|
+
label: 'Cancel',
|
|
54
|
+
action: () => {
|
|
55
|
+
clearInputValue();
|
|
56
|
+
onCancel();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
confirm: {
|
|
60
|
+
label: 'Confirm',
|
|
61
|
+
action: () => {
|
|
62
|
+
onChange({
|
|
63
|
+
description: inputValue.description,
|
|
64
|
+
youtubeId: inputValue.youtubeId
|
|
65
|
+
});
|
|
66
|
+
clearInputValue();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, /*#__PURE__*/_react.default.createElement(Label, {
|
|
71
|
+
htmlFor: "description"
|
|
72
|
+
}, "Youtube Description"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
|
|
73
|
+
onChange: e => setInputValue({
|
|
74
|
+
description: e.target.value,
|
|
75
|
+
youtubeId: inputValue.youtubeId
|
|
76
|
+
}),
|
|
77
|
+
type: "text",
|
|
78
|
+
placeholder: "description",
|
|
79
|
+
id: "description",
|
|
80
|
+
value: inputValue.description
|
|
81
|
+
}), /*#__PURE__*/_react.default.createElement(Label, {
|
|
82
|
+
htmlFor: "youtubeId"
|
|
83
|
+
}, "Youtube Videi Id"), /*#__PURE__*/_react.default.createElement(_fields.TextInput, {
|
|
84
|
+
onChange: e => setInputValue({
|
|
85
|
+
description: inputValue.description,
|
|
86
|
+
youtubeId: e.target.value
|
|
87
|
+
}),
|
|
88
|
+
type: "text",
|
|
89
|
+
placeholder: "youtubeId",
|
|
90
|
+
id: "youtubeId",
|
|
91
|
+
value: inputValue.youtubeId
|
|
92
|
+
})));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function YoutubeButton(props) {
|
|
96
|
+
const [toShowInput, setToShowInput] = (0, _react.useState)(false);
|
|
97
|
+
const {
|
|
98
|
+
className,
|
|
99
|
+
editorState,
|
|
100
|
+
onChange: onEditorStateChange
|
|
101
|
+
} = props;
|
|
102
|
+
|
|
103
|
+
const onChange = ({
|
|
104
|
+
description,
|
|
105
|
+
youtubeId
|
|
106
|
+
}) => {
|
|
107
|
+
const contentState = editorState.getCurrentContent(); // create an InfoBox entity
|
|
108
|
+
|
|
109
|
+
const contentStateWithEntity = contentState.createEntity('YOUTUBE', 'IMMUTABLE', {
|
|
110
|
+
description,
|
|
111
|
+
youtubeId
|
|
112
|
+
});
|
|
113
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
114
|
+
|
|
115
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
116
|
+
currentContent: contentStateWithEntity
|
|
117
|
+
}); //The third parameter here is a space string, not an empty string
|
|
118
|
+
//If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
onEditorStateChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
122
|
+
setToShowInput(false);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(YoutubeInput, {
|
|
126
|
+
onChange: onChange,
|
|
127
|
+
onCancel: () => {
|
|
128
|
+
setToShowInput(false);
|
|
129
|
+
},
|
|
130
|
+
isOpen: toShowInput
|
|
131
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
132
|
+
className: className,
|
|
133
|
+
onClick: () => {
|
|
134
|
+
setToShowInput(true);
|
|
135
|
+
}
|
|
136
|
+
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
137
|
+
height: "16px",
|
|
138
|
+
width: "14px",
|
|
139
|
+
version: "1.1",
|
|
140
|
+
id: "Layer_1",
|
|
141
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
142
|
+
viewBox: "0 0 461.001 461.001"
|
|
143
|
+
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
144
|
+
fill: "#6b7280",
|
|
145
|
+
d: "M365.257,67.393H95.744C42.866,67.393,0,110.259,0,163.137v134.728 c0,52.878,42.866,95.744,95.744,95.744h269.513c52.878,0,95.744-42.866,95.744-95.744V163.137 C461.001,110.259,418.135,67.393,365.257,67.393z M300.506,237.056l-126.06,60.123c-3.359,1.602-7.239-0.847-7.239-4.568V168.607 c0-3.774,3.982-6.22,7.348-4.514l126.06,63.881C304.363,229.873,304.298,235.248,300.506,237.056z"
|
|
146
|
+
})), /*#__PURE__*/_react.default.createElement("span", null, "Youtube")));
|
|
147
|
+
}
|
|
@@ -55,6 +55,8 @@ var _video = require("../../draft-js/buttons/video");
|
|
|
55
55
|
|
|
56
56
|
var _audio = require("../../draft-js/buttons/audio");
|
|
57
57
|
|
|
58
|
+
var _youtube = require("../../draft-js/buttons/youtube");
|
|
59
|
+
|
|
58
60
|
var _const = require("../../draft-js/const");
|
|
59
61
|
|
|
60
62
|
var _imageSelector = require("./selector/image-selector");
|
|
@@ -105,10 +107,11 @@ const buttonNames = {
|
|
|
105
107
|
relatedPost: 'related-post',
|
|
106
108
|
sideIndex: 'side-index',
|
|
107
109
|
video: 'video',
|
|
108
|
-
audio: 'audio'
|
|
110
|
+
audio: 'audio',
|
|
111
|
+
youtube: 'youtube'
|
|
109
112
|
};
|
|
110
113
|
exports.buttonNames = buttonNames;
|
|
111
|
-
const disabledButtonsOnBasicEditor = [buttonNames.annotation, buttonNames.divider, buttonNames.embed, buttonNames.image, buttonNames.infoBox, buttonNames.slideshow, buttonNames.table, buttonNames.textAlign, buttonNames.colorBox, buttonNames.backgroundColor, buttonNames.backgroundImage, buttonNames.backgroundVideo, buttonNames.relatedPost, buttonNames.sideIndex, buttonNames.video, buttonNames.audio];
|
|
114
|
+
const disabledButtonsOnBasicEditor = [buttonNames.annotation, buttonNames.divider, buttonNames.embed, buttonNames.image, buttonNames.infoBox, buttonNames.slideshow, buttonNames.table, buttonNames.textAlign, buttonNames.colorBox, buttonNames.backgroundColor, buttonNames.backgroundImage, buttonNames.backgroundVideo, buttonNames.relatedPost, buttonNames.sideIndex, buttonNames.video, buttonNames.audio, buttonNames.youtube];
|
|
112
115
|
const buttonStyle = (0, _styledComponents.css)`
|
|
113
116
|
border-radius: 6px;
|
|
114
117
|
text-align: center;
|
|
@@ -250,6 +253,7 @@ const CustomAlignCenterButton = createButtonWithoutProps(_textAlign.AlignCenterB
|
|
|
250
253
|
const CustomAlignLeftButton = createButtonWithoutProps(_textAlign.AlignLeftButton, true);
|
|
251
254
|
const CustomVideoButton = createButtonWithoutProps(_video.VideoButton);
|
|
252
255
|
const CustomAudioButton = createButtonWithoutProps(_audio.AudioButton);
|
|
256
|
+
const CustomYoutubeButton = createButtonWithoutProps(_youtube.YoutubeButton);
|
|
253
257
|
const DraftEditorWrapper = _styledComponents.default.div`
|
|
254
258
|
/* Rich-editor default setting (.RichEditor-root)*/
|
|
255
259
|
background: #fff;
|
|
@@ -703,6 +707,11 @@ class RichTextEditor extends _react.default.Component {
|
|
|
703
707
|
onChange: this.onChange,
|
|
704
708
|
readOnly: this.state.readOnly,
|
|
705
709
|
VideoSelector: _videoSelector.VideoSelector
|
|
710
|
+
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomYoutubeButton, {
|
|
711
|
+
isDisabled: disabledButtons.includes(buttonNames.youtube),
|
|
712
|
+
editorState: editorState,
|
|
713
|
+
onChange: this.onChange,
|
|
714
|
+
readOnly: this.state.readOnly
|
|
706
715
|
})), /*#__PURE__*/_react.default.createElement(ButtonGroup, null, /*#__PURE__*/_react.default.createElement(CustomAudioButton, {
|
|
707
716
|
isDisabled: disabledButtons.includes(buttonNames.audio),
|
|
708
717
|
editorState: editorState,
|
|
@@ -11,10 +11,17 @@ var _mirrormedia = _interopRequireDefault(require("@mirrormedia/lilith-draft-ren
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
+
//Because `annotationDecorator` and `linkDecorator` is generated by different `contentLayout`,
|
|
15
|
+
//so it is needed to generate decorators by using function `decoratorsGenerator`.
|
|
14
16
|
const {
|
|
15
17
|
annotationDecorator,
|
|
16
18
|
linkDecorator
|
|
17
19
|
} = _mirrormedia.default.entityDecorators;
|
|
18
|
-
|
|
20
|
+
|
|
21
|
+
const decoratorsGenerator = (contentLayout = 'normal') => {
|
|
22
|
+
return new _draftJs.CompositeDecorator([annotationDecorator(contentLayout), linkDecorator(contentLayout)]);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const decorators = decoratorsGenerator('normal');
|
|
19
26
|
var _default = decorators;
|
|
20
27
|
exports.default = _default;
|
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.17",
|
|
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.2.0-alpha.
|
|
26
|
+
"@mirrormedia/lilith-draft-renderer": "1.2.0-alpha.31"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "18.2.0",
|