@mirrormedia/lilith-draft-editor 1.0.0-beta4 → 1.0.1
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/README.md +51 -0
- package/lib/draft-js/buttons/annotation.js +17 -17
- package/lib/draft-js/buttons/background-color.js +6 -7
- package/lib/draft-js/buttons/background-image.js +18 -17
- package/lib/draft-js/buttons/background-video.js +18 -17
- package/lib/draft-js/buttons/color-box.js +19 -18
- package/lib/draft-js/buttons/font-color.js +6 -7
- package/lib/draft-js/buttons/info-box.js +18 -17
- package/lib/draft-js/buttons/text-align.js +1 -1
- package/lib/draft-js/const.js +18 -0
- package/lib/draft-js/{editor/draft-converter → draft-converter}/api-data-instance.js +0 -0
- package/lib/draft-js/{editor/draft-converter → draft-converter}/atomic-block-processor.js +0 -0
- package/lib/draft-js/{editor/draft-converter → draft-converter}/entities.js +0 -0
- package/lib/draft-js/{editor/draft-converter → draft-converter}/index.js +0 -0
- package/lib/draft-js/{editor/draft-converter → draft-converter}/inline-styles-processor.js +6 -8
- package/lib/draft-js/{editor/modifier.js → modifier.js} +0 -0
- package/lib/index.js +1 -1
- package/lib/website/{readr/custom → mirrormedia}/block-renderer/background-image-block.js +7 -5
- package/lib/website/{readr/custom → mirrormedia}/block-renderer/background-video-block.js +7 -5
- package/lib/website/{readr/custom → mirrormedia}/block-renderer/color-box-block.js +7 -5
- package/lib/website/mirrormedia/{custom/block-renderer → block-renderer}/info-box-block.js +7 -5
- package/lib/website/mirrormedia/{custom/block-renderer → block-renderer}/side-index-block.js +3 -3
- package/lib/website/mirrormedia/{custom/block-renderer → block-renderer}/table-block.js +0 -0
- package/lib/website/mirrormedia/{draft-editor/block-renderer-fn.js → block-renderer-fn.js} +10 -8
- package/lib/website/mirrormedia/{draft-editor/index.js → draft-editor.js} +126 -33
- package/lib/website/mirrormedia/{draft-editor/entity-decorator.js → entity-decorator.js} +4 -2
- package/lib/website/mirrormedia/{custom/selector → selector}/align-selector.js +0 -0
- package/lib/website/mirrormedia/{custom/selector → selector}/image-selector.js +0 -0
- package/lib/website/mirrormedia/{custom/selector → selector}/pagination.js +0 -0
- package/lib/website/mirrormedia/{custom/selector → selector}/post-selector.js +0 -0
- package/lib/website/mirrormedia/{custom/selector → selector}/search-box.js +0 -0
- package/lib/website/mirrormedia/{custom/selector → selector}/video-selector.js +0 -0
- package/lib/website/{mirrormedia/custom → readr}/block-renderer/background-image-block.js +7 -5
- package/lib/website/{mirrormedia/custom → readr}/block-renderer/background-video-block.js +7 -5
- package/lib/website/{mirrormedia/custom → readr}/block-renderer/color-box-block.js +7 -5
- package/lib/website/readr/{custom/block-renderer → block-renderer}/info-box-block.js +7 -5
- package/lib/website/readr/{custom/block-renderer → block-renderer}/side-index-block.js +3 -3
- package/lib/website/readr/{custom/block-renderer → block-renderer}/table-block.js +0 -0
- package/lib/website/readr/{draft-editor/block-renderer-fn.js → block-renderer-fn.js} +10 -8
- package/lib/website/readr/{draft-editor/index.js → draft-editor.js} +126 -33
- package/lib/website/readr/{draft-editor/entity-decorator.js → entity-decorator.js} +4 -2
- package/lib/website/readr/{custom/selector → selector}/align-selector.js +0 -0
- package/lib/website/readr/{custom/selector → selector}/image-selector.js +0 -0
- package/lib/website/readr/{custom/selector → selector}/pagination.js +0 -0
- package/lib/website/readr/{custom/selector → selector}/post-selector.js +0 -0
- package/lib/website/readr/{custom/selector → selector}/search-box.js +0 -0
- package/lib/website/readr/{custom/selector → selector}/video-selector.js +0 -0
- package/package.json +4 -4
- package/lib/draft-js/block-renderer/background-image-block.js +0 -123
- package/lib/draft-js/block-renderer/background-video-block.js +0 -133
- package/lib/draft-js/block-renderer/color-box-block.js +0 -92
- package/lib/draft-js/block-renderer/divider-block.js +0 -24
- package/lib/draft-js/block-renderer/embedded-code-block.js +0 -63
- package/lib/draft-js/block-renderer/image-block.js +0 -47
- package/lib/draft-js/block-renderer/info-box-block.js +0 -89
- package/lib/draft-js/block-renderer/media-block.js +0 -65
- package/lib/draft-js/block-renderer/related-post-block.js +0 -51
- package/lib/draft-js/block-renderer/side-index-block.js +0 -103
- package/lib/draft-js/block-renderer/slideshow-block.js +0 -71
- package/lib/draft-js/block-renderer/table-block.js +0 -408
- package/lib/draft-js/editor/basic-editor.js +0 -366
- package/lib/draft-js/editor/block-renderer-fn.js +0 -117
- package/lib/draft-js/editor/entity-decorator.js +0 -16
- package/lib/draft-js/entity-decorator/annotation-decorator.js +0 -86
- package/lib/draft-js/entity-decorator/link-decorator.js +0 -39
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# [@mirrormedia/lilith-core](https://www.npmjs.com/package/@mirrormedia/lilith-draft-editor) · 
|
|
2
|
+
|
|
3
|
+
### Installation
|
|
4
|
+
|
|
5
|
+
`yarn install`
|
|
6
|
+
|
|
7
|
+
### Development
|
|
8
|
+
|
|
9
|
+
`@mirrormedia/lilith-draft-editor` export `@mirrormedia/lilith-core` 所需要的 `RichTextEditor`,而 `@mirrormedia/lilith-core` 則是被 `@mirrormedia/lilith-(mirrormedia|readr|mesh|editools)` 所使用,因此在開發上會以各網站的角度去切入,在本套件中修改 editor 相關的程式碼,並在 lilith-(mirrormedia|readr|mesh|editools) 中測試開發狀況。
|
|
10
|
+
|
|
11
|
+
舉 lilith-mirrormedia 為例,要修改 mirrormedia 相關的 RichTextEditor 需要在 `packages/lilith-draft-editor` 中進行改動,改動完之後跑 `yarn build` 產生 transpiled 後的程式碼,若 `packages/lilith-draft-editor` 有修改 package.json 中的套件版本時,則需要同時修改 `packages/core` 中 import `@mirrormedia/lilith-draft-editor` 的版本; 同理,若是因此 `packages/core` 有修改版本號的話也需要跑 `yarn build`, `packages/mirrormedia` 也同樣需要修改 import `@mirrormedia/lilith-core` 的版本。
|
|
12
|
+
|
|
13
|
+
因為 lilith-mirrormedia, lilith-core, lilith-draft-editor 都在 monorepo 中,yarn workspaces 會為 lilith-core, lilith-draft-editor pkg 建立 soft link,將 `node_modules/@mirrormedia/lilith-core` 指到 `packages/core` 而 `node_modules/@mirrormedia/lilith-draft-editor` 指到 `packages/draft-editor`,所以 `yarn build` 產生的新的程式碼,可以不需要透過 npm publish 和 yarn install 的方式,立即讓 lilith-mirrormedia, lilith-core 使用。
|
|
14
|
+
|
|
15
|
+
等到確定程式碼修改完畢後,我們再將最新的程式碼上傳(`npm publish`)到 npm registry 去,讓 lilith-editools 的 CI/CD 可以下載到最新的版本。
|
|
16
|
+
|
|
17
|
+
### File Structure
|
|
18
|
+
|
|
19
|
+
在 `src` 資料夾下有兩大類的檔案
|
|
20
|
+
|
|
21
|
+
1. 共用的 draft.js 程式碼: 主要是 draft.js button UI, draft-converter 和其他 helper function
|
|
22
|
+
2. 各網站客製化的改動:
|
|
23
|
+
|
|
24
|
+
依照各網站需求修改`src/website/${website}/`中的檔案
|
|
25
|
+
|
|
26
|
+
- block-renderer : 在既有(注 1)的 block-renderer 上附加可編輯的 wrapper,僅有部分 block renderers 適用
|
|
27
|
+
- selector: 依照各網站 keystone list 來調整 photo, video 和 post 的 gql query
|
|
28
|
+
- draft-editor: 主要 export 出 RichTextEditor 的檔案,實際使用在 lilith-core 對應的 webiste 中,可直接決定 RichTextEditor 樣式(注 2)
|
|
29
|
+
|
|
30
|
+
\*注 1: lilith-draft-editor 各個 buttons 對應的 block-renderers, entity-decorators 會 maintain 在 lilith-draft-renderer,由各網站 Next.js 專案開發人員實作,在本專案中會直接將 lilith-draft-renderer 中定義好的 block-renderers, entity-decorators 直接使用(除了少數需要再編輯的 block-renderer,參考 `src/website/${website}/block-renderer`中的 editor wrapper component)。
|
|
31
|
+
|
|
32
|
+
\*注 2: 雖然各個網站都 maintain 了一個 draft-editor,可以自行決定 import 進來的 buttons,不過因為 lilith-core 中實作 disalbedButtons 的功能,所以目前一率將所有的 buttons 加入 RichTextEditor 中,由 lilith-(mirrormedia|readr|mesh|editools) 來控制所使用的 buttons。
|
|
33
|
+
|
|
34
|
+
### Build
|
|
35
|
+
|
|
36
|
+
`yarn build`
|
|
37
|
+
|
|
38
|
+
### Publish
|
|
39
|
+
|
|
40
|
+
`npm run publish`
|
|
41
|
+
|
|
42
|
+
在 publish 前,請根據 conventional commits 的規範,將 package.json#version 升版。
|
|
43
|
+
|
|
44
|
+
### Notable Details
|
|
45
|
+
|
|
46
|
+
#### For those files under `views/` folder, we transpile them specifically.
|
|
47
|
+
|
|
48
|
+
For those files under `views/` folder, we transpile them by babel according to different configuation.
|
|
49
|
+
The specific babel configuration is `.views.babelrc.js`.
|
|
50
|
+
In `.views.babelrc.js`, we tell babel not to transpile `import` and `export` es6 codes into commonJS codes.
|
|
51
|
+
The Keystone server won't start server well if those files under `views/` are transpiled into commonJS codes.
|
|
@@ -7,15 +7,11 @@ exports.AnnotationButton = AnnotationButton;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
|
-
var _basicEditor = require("../editor/basic-editor");
|
|
11
|
-
|
|
12
10
|
var _draftJs = require("draft-js");
|
|
13
11
|
|
|
14
12
|
var _modals = require("@keystone-ui/modals");
|
|
15
13
|
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
var _draftConverter = _interopRequireDefault(require("../editor/draft-converter"));
|
|
14
|
+
var _draftConverter = _interopRequireDefault(require("../draft-converter"));
|
|
19
15
|
|
|
20
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
17
|
|
|
@@ -32,11 +28,13 @@ function AnnotationButton(props) {
|
|
|
32
28
|
const {
|
|
33
29
|
isActive,
|
|
34
30
|
editorState,
|
|
35
|
-
onChange
|
|
31
|
+
onChange,
|
|
32
|
+
renderBasicEditor,
|
|
33
|
+
decorators
|
|
36
34
|
} = props;
|
|
37
35
|
const [toShowInput, setToShowInput] = (0, _react.useState)(false);
|
|
38
36
|
const [inputValue, setInputValue] = (0, _react.useState)({
|
|
39
|
-
editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(
|
|
37
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(decorators)
|
|
40
38
|
});
|
|
41
39
|
|
|
42
40
|
const promptForAnnotation = e => {
|
|
@@ -68,7 +66,7 @@ function AnnotationButton(props) {
|
|
|
68
66
|
onChange(toggleEntity(newEditorState, newEditorState.getSelection(), entityKey));
|
|
69
67
|
setToShowInput(false);
|
|
70
68
|
setInputValue({
|
|
71
|
-
editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(
|
|
69
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(decorators)
|
|
72
70
|
});
|
|
73
71
|
};
|
|
74
72
|
|
|
@@ -81,10 +79,19 @@ function AnnotationButton(props) {
|
|
|
81
79
|
|
|
82
80
|
setToShowInput(false);
|
|
83
81
|
setInputValue({
|
|
84
|
-
editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(
|
|
82
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createEmpty(decorators)
|
|
85
83
|
});
|
|
86
84
|
};
|
|
87
85
|
|
|
86
|
+
const basicEditorJsx = renderBasicEditor({
|
|
87
|
+
editorState: inputValue.editorStateOfBasicEditor,
|
|
88
|
+
onChange: editorStateOfBasicEditor => {
|
|
89
|
+
setInputValue({
|
|
90
|
+
editorStateOfBasicEditor
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
88
95
|
const urlInput = /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
|
|
89
96
|
isOpen: toShowInput
|
|
90
97
|
}, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
|
|
@@ -99,14 +106,7 @@ function AnnotationButton(props) {
|
|
|
99
106
|
action: confirmAnnotation
|
|
100
107
|
}
|
|
101
108
|
}
|
|
102
|
-
},
|
|
103
|
-
editorState: inputValue.editorStateOfBasicEditor,
|
|
104
|
-
onChange: editorStateOfBasicEditor => {
|
|
105
|
-
setInputValue({
|
|
106
|
-
editorStateOfBasicEditor
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
})));
|
|
109
|
+
}, basicEditorJsx));
|
|
110
110
|
|
|
111
111
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, urlInput, /*#__PURE__*/_react.default.createElement("div", {
|
|
112
112
|
className: props.className,
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BackgroundColorButton = BackgroundColorButton;
|
|
7
|
-
exports.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR = void 0;
|
|
8
7
|
|
|
9
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
9
|
|
|
@@ -16,7 +15,9 @@ var _fields = require("@keystone-ui/fields");
|
|
|
16
15
|
|
|
17
16
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
18
17
|
|
|
19
|
-
var _modifier = require("../
|
|
18
|
+
var _modifier = require("../modifier");
|
|
19
|
+
|
|
20
|
+
var _const = require("../const");
|
|
20
21
|
|
|
21
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
23
|
|
|
@@ -29,8 +30,6 @@ const ColorHexInput = (0, _styledComponents.default)(_fields.TextInput)`
|
|
|
29
30
|
margin-right: 10px;
|
|
30
31
|
padding: 10px;
|
|
31
32
|
`;
|
|
32
|
-
const CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR = 'BACKGROUND_COLOR_';
|
|
33
|
-
exports.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR = CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR;
|
|
34
33
|
|
|
35
34
|
function BackgroundColorButton(props) {
|
|
36
35
|
const {
|
|
@@ -54,10 +53,10 @@ function BackgroundColorButton(props) {
|
|
|
54
53
|
const selection = editorState.getSelection();
|
|
55
54
|
const contentState = editorState.getCurrentContent();
|
|
56
55
|
|
|
57
|
-
let newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR);
|
|
56
|
+
let newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR);
|
|
58
57
|
|
|
59
58
|
if (colorValue) {
|
|
60
|
-
newContentState = _modifier.Modifier.applyInlineStyle(newContentState, selection, CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR + colorValue);
|
|
59
|
+
newContentState = _modifier.Modifier.applyInlineStyle(newContentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR + colorValue);
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
|
|
@@ -78,7 +77,7 @@ function BackgroundColorButton(props) {
|
|
|
78
77
|
if (!selection.isCollapsed()) {
|
|
79
78
|
const contentState = editorState.getCurrentContent();
|
|
80
79
|
|
|
81
|
-
const newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR);
|
|
80
|
+
const newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR);
|
|
82
81
|
|
|
83
82
|
onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
|
|
84
83
|
}
|
|
@@ -8,17 +8,13 @@ exports.BGImageInput = BGImageInput;
|
|
|
8
8
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
|
|
11
|
-
var _entityDecorator = _interopRequireDefault(require("../editor/entity-decorator"));
|
|
12
|
-
|
|
13
11
|
var _draftJs = require("draft-js");
|
|
14
12
|
|
|
15
|
-
var _basicEditor = require("../editor/basic-editor");
|
|
16
|
-
|
|
17
13
|
var _modals = require("@keystone-ui/modals");
|
|
18
14
|
|
|
19
15
|
var _button = require("@keystone-ui/button");
|
|
20
16
|
|
|
21
|
-
var _draftConverter = _interopRequireDefault(require("../
|
|
17
|
+
var _draftConverter = _interopRequireDefault(require("../draft-converter"));
|
|
22
18
|
|
|
23
19
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
24
20
|
|
|
@@ -52,7 +48,9 @@ function BGImageInput(props) {
|
|
|
52
48
|
textBlockAlign,
|
|
53
49
|
image,
|
|
54
50
|
rawContentStateForBGImageEditor,
|
|
55
|
-
ImageSelector = _imageSelector.ImageSelector
|
|
51
|
+
ImageSelector = _imageSelector.ImageSelector,
|
|
52
|
+
renderBasicEditor,
|
|
53
|
+
decorators
|
|
56
54
|
} = props;
|
|
57
55
|
const rawContentState = rawContentStateForBGImageEditor || {
|
|
58
56
|
blocks: [],
|
|
@@ -79,7 +77,7 @@ function BGImageInput(props) {
|
|
|
79
77
|
textBlockAlign: textBlockAlign || 'fixed',
|
|
80
78
|
image: image || undefined,
|
|
81
79
|
// create an `editorState` from raw content state object
|
|
82
|
-
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState),
|
|
80
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState), decorators)
|
|
83
81
|
};
|
|
84
82
|
const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
|
|
85
83
|
const [toShowImageSelector, setToShowImageSelector] = (0, _react.useState)(false);
|
|
@@ -89,7 +87,7 @@ function BGImageInput(props) {
|
|
|
89
87
|
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)({
|
|
90
88
|
blocks: [],
|
|
91
89
|
entityMap: {}
|
|
92
|
-
}),
|
|
90
|
+
}), decorators)
|
|
93
91
|
}));
|
|
94
92
|
};
|
|
95
93
|
|
|
@@ -109,6 +107,14 @@ function BGImageInput(props) {
|
|
|
109
107
|
setToShowImageSelector(false);
|
|
110
108
|
};
|
|
111
109
|
|
|
110
|
+
const basicEditorJsx = renderBasicEditor({
|
|
111
|
+
editorState: inputValue.editorStateOfBasicEditor,
|
|
112
|
+
onChange: editorStateOfBasicEditor => {
|
|
113
|
+
setInputValue(oldInputValue => ({ ...oldInputValue,
|
|
114
|
+
editorStateOfBasicEditor
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
112
118
|
(0, _react.useEffect)(() => {
|
|
113
119
|
if (isOpen) {
|
|
114
120
|
setInputValue(initialInputValue);
|
|
@@ -153,14 +159,7 @@ function BGImageInput(props) {
|
|
|
153
159
|
textBlockAlign
|
|
154
160
|
}));
|
|
155
161
|
}
|
|
156
|
-
}), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"),
|
|
157
|
-
editorState: inputValue.editorStateOfBasicEditor,
|
|
158
|
-
onChange: editorStateOfBasicEditor => {
|
|
159
|
-
setInputValue(oldInputValue => ({ ...oldInputValue,
|
|
160
|
-
editorStateOfBasicEditor
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
}))));
|
|
162
|
+
}), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx)));
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
function BGImageButton(props) {
|
|
@@ -169,7 +168,8 @@ function BGImageButton(props) {
|
|
|
169
168
|
className,
|
|
170
169
|
editorState,
|
|
171
170
|
onChange: onEditorStateChange,
|
|
172
|
-
ImageSelector
|
|
171
|
+
ImageSelector,
|
|
172
|
+
renderBasicEditor
|
|
173
173
|
} = props;
|
|
174
174
|
|
|
175
175
|
const onChange = ({
|
|
@@ -198,6 +198,7 @@ function BGImageButton(props) {
|
|
|
198
198
|
};
|
|
199
199
|
|
|
200
200
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(BGImageInput, {
|
|
201
|
+
renderBasicEditor: renderBasicEditor,
|
|
201
202
|
onChange: onChange,
|
|
202
203
|
onCancel: () => {
|
|
203
204
|
setToShowInput(false);
|
|
@@ -8,17 +8,13 @@ exports.BGVideoInput = BGVideoInput;
|
|
|
8
8
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
|
|
11
|
-
var _entityDecorator = _interopRequireDefault(require("../editor/entity-decorator"));
|
|
12
|
-
|
|
13
11
|
var _draftJs = require("draft-js");
|
|
14
12
|
|
|
15
|
-
var _basicEditor = require("../editor/basic-editor");
|
|
16
|
-
|
|
17
13
|
var _modals = require("@keystone-ui/modals");
|
|
18
14
|
|
|
19
15
|
var _button = require("@keystone-ui/button");
|
|
20
16
|
|
|
21
|
-
var _draftConverter = _interopRequireDefault(require("../
|
|
17
|
+
var _draftConverter = _interopRequireDefault(require("../draft-converter"));
|
|
22
18
|
|
|
23
19
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
24
20
|
|
|
@@ -52,7 +48,9 @@ function BGVideoInput(props) {
|
|
|
52
48
|
textBlockAlign,
|
|
53
49
|
video,
|
|
54
50
|
rawContentStateForBGVideoEditor,
|
|
55
|
-
VideoSelector = _videoSelector.VideoSelector
|
|
51
|
+
VideoSelector = _videoSelector.VideoSelector,
|
|
52
|
+
renderBasicEditor,
|
|
53
|
+
decorators
|
|
56
54
|
} = props;
|
|
57
55
|
const rawContentState = rawContentStateForBGVideoEditor || {
|
|
58
56
|
blocks: [],
|
|
@@ -79,7 +77,7 @@ function BGVideoInput(props) {
|
|
|
79
77
|
textBlockAlign: textBlockAlign || 'fixed',
|
|
80
78
|
video: video || undefined,
|
|
81
79
|
// create an `editorState` from raw content state object
|
|
82
|
-
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState),
|
|
80
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState), decorators)
|
|
83
81
|
};
|
|
84
82
|
const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
|
|
85
83
|
const [toShowVideoSelector, setToShowVideoSelector] = (0, _react.useState)(false);
|
|
@@ -89,7 +87,7 @@ function BGVideoInput(props) {
|
|
|
89
87
|
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)({
|
|
90
88
|
blocks: [],
|
|
91
89
|
entityMap: {}
|
|
92
|
-
}),
|
|
90
|
+
}), decorators)
|
|
93
91
|
}));
|
|
94
92
|
};
|
|
95
93
|
|
|
@@ -109,6 +107,14 @@ function BGVideoInput(props) {
|
|
|
109
107
|
setToShowVideoSelector(false);
|
|
110
108
|
};
|
|
111
109
|
|
|
110
|
+
const basicEditorJsx = renderBasicEditor({
|
|
111
|
+
editorState: inputValue.editorStateOfBasicEditor,
|
|
112
|
+
onChange: editorStateOfBasicEditor => {
|
|
113
|
+
setInputValue(oldInputValue => ({ ...oldInputValue,
|
|
114
|
+
editorStateOfBasicEditor
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
112
118
|
(0, _react.useEffect)(() => {
|
|
113
119
|
if (isOpen) {
|
|
114
120
|
setInputValue(initialInputValue);
|
|
@@ -153,14 +159,7 @@ function BGVideoInput(props) {
|
|
|
153
159
|
textBlockAlign
|
|
154
160
|
}));
|
|
155
161
|
}
|
|
156
|
-
}), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"),
|
|
157
|
-
editorState: inputValue.editorStateOfBasicEditor,
|
|
158
|
-
onChange: editorStateOfBasicEditor => {
|
|
159
|
-
setInputValue(oldInputValue => ({ ...oldInputValue,
|
|
160
|
-
editorStateOfBasicEditor
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
}))));
|
|
162
|
+
}), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx)));
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
function BGVideoButton(props) {
|
|
@@ -169,7 +168,8 @@ function BGVideoButton(props) {
|
|
|
169
168
|
className,
|
|
170
169
|
editorState,
|
|
171
170
|
onChange: onEditorStateChange,
|
|
172
|
-
VideoSelector
|
|
171
|
+
VideoSelector,
|
|
172
|
+
renderBasicEditor
|
|
173
173
|
} = props;
|
|
174
174
|
|
|
175
175
|
const onChange = ({
|
|
@@ -198,6 +198,7 @@ function BGVideoButton(props) {
|
|
|
198
198
|
};
|
|
199
199
|
|
|
200
200
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(BGVideoInput, {
|
|
201
|
+
renderBasicEditor: renderBasicEditor,
|
|
201
202
|
onChange: onChange,
|
|
202
203
|
onCancel: () => {
|
|
203
204
|
setToShowInput(false);
|
|
@@ -8,17 +8,13 @@ exports.ColorBoxInput = ColorBoxInput;
|
|
|
8
8
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
|
|
11
|
-
var _entityDecorator = _interopRequireDefault(require("../editor/entity-decorator"));
|
|
12
|
-
|
|
13
11
|
var _draftJs = require("draft-js");
|
|
14
12
|
|
|
15
|
-
var _basicEditor = require("../editor/basic-editor");
|
|
16
|
-
|
|
17
13
|
var _modals = require("@keystone-ui/modals");
|
|
18
14
|
|
|
19
15
|
var _fields = require("@keystone-ui/fields");
|
|
20
16
|
|
|
21
|
-
var _draftConverter = _interopRequireDefault(require("../
|
|
17
|
+
var _draftConverter = _interopRequireDefault(require("../draft-converter"));
|
|
22
18
|
|
|
23
19
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
24
20
|
|
|
@@ -43,7 +39,9 @@ function ColorBoxInput(props) {
|
|
|
43
39
|
onChange,
|
|
44
40
|
onCancel,
|
|
45
41
|
color,
|
|
46
|
-
rawContentStateForColorBoxEditor
|
|
42
|
+
rawContentStateForColorBoxEditor,
|
|
43
|
+
renderBasicEditor,
|
|
44
|
+
decorators
|
|
47
45
|
} = props;
|
|
48
46
|
const rawContentState = rawContentStateForColorBoxEditor || {
|
|
49
47
|
blocks: [],
|
|
@@ -52,7 +50,7 @@ function ColorBoxInput(props) {
|
|
|
52
50
|
const initialInputValue = {
|
|
53
51
|
color: color || '',
|
|
54
52
|
// create an `editorState` from raw content state object
|
|
55
|
-
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState),
|
|
53
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState), decorators)
|
|
56
54
|
};
|
|
57
55
|
const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
|
|
58
56
|
|
|
@@ -62,7 +60,7 @@ function ColorBoxInput(props) {
|
|
|
62
60
|
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)({
|
|
63
61
|
blocks: [],
|
|
64
62
|
entityMap: {}
|
|
65
|
-
}),
|
|
63
|
+
}), decorators)
|
|
66
64
|
});
|
|
67
65
|
};
|
|
68
66
|
|
|
@@ -71,6 +69,15 @@ function ColorBoxInput(props) {
|
|
|
71
69
|
setInputValue(initialInputValue);
|
|
72
70
|
}
|
|
73
71
|
}, [isOpen]);
|
|
72
|
+
const basicEditorJsx = renderBasicEditor({
|
|
73
|
+
editorState: inputValue.editorStateOfBasicEditor,
|
|
74
|
+
onChange: editorStateOfBasicEditor => {
|
|
75
|
+
setInputValue({
|
|
76
|
+
color: inputValue.color,
|
|
77
|
+
editorStateOfBasicEditor
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
74
81
|
return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
|
|
75
82
|
isOpen: isOpen
|
|
76
83
|
}, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
|
|
@@ -103,15 +110,7 @@ function ColorBoxInput(props) {
|
|
|
103
110
|
type: "text",
|
|
104
111
|
placeholder: "Color",
|
|
105
112
|
value: inputValue.color
|
|
106
|
-
}), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"),
|
|
107
|
-
editorState: inputValue.editorStateOfBasicEditor,
|
|
108
|
-
onChange: editorStateOfBasicEditor => {
|
|
109
|
-
setInputValue({
|
|
110
|
-
color: inputValue.color,
|
|
111
|
-
editorStateOfBasicEditor
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
})));
|
|
113
|
+
}), /*#__PURE__*/_react.default.createElement(Label, null, "\u5167\u6587"), basicEditorJsx));
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
function ColorBoxButton(props) {
|
|
@@ -119,7 +118,8 @@ function ColorBoxButton(props) {
|
|
|
119
118
|
const {
|
|
120
119
|
className,
|
|
121
120
|
editorState,
|
|
122
|
-
onChange: onEditorStateChange
|
|
121
|
+
onChange: onEditorStateChange,
|
|
122
|
+
renderBasicEditor
|
|
123
123
|
} = props;
|
|
124
124
|
|
|
125
125
|
const onChange = ({
|
|
@@ -146,6 +146,7 @@ function ColorBoxButton(props) {
|
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ColorBoxInput, {
|
|
149
|
+
renderBasicEditor: renderBasicEditor,
|
|
149
150
|
onChange: onChange,
|
|
150
151
|
onCancel: () => {
|
|
151
152
|
setToShowInput(false);
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.CUSTOM_STYLE_PREFIX_FONT_COLOR = void 0;
|
|
7
6
|
exports.FontColorButton = FontColorButton;
|
|
8
7
|
|
|
9
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -16,7 +15,9 @@ var _fields = require("@keystone-ui/fields");
|
|
|
16
15
|
|
|
17
16
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
18
17
|
|
|
19
|
-
var _modifier = require("../
|
|
18
|
+
var _modifier = require("../modifier");
|
|
19
|
+
|
|
20
|
+
var _const = require("../const");
|
|
20
21
|
|
|
21
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
23
|
|
|
@@ -29,8 +30,6 @@ const ColorHexInput = (0, _styledComponents.default)(_fields.TextInput)`
|
|
|
29
30
|
margin-right: 10px;
|
|
30
31
|
padding: 10px;
|
|
31
32
|
`;
|
|
32
|
-
const CUSTOM_STYLE_PREFIX_FONT_COLOR = 'FONT_COLOR_';
|
|
33
|
-
exports.CUSTOM_STYLE_PREFIX_FONT_COLOR = CUSTOM_STYLE_PREFIX_FONT_COLOR;
|
|
34
33
|
|
|
35
34
|
function FontColorButton(props) {
|
|
36
35
|
const {
|
|
@@ -54,10 +53,10 @@ function FontColorButton(props) {
|
|
|
54
53
|
const selection = editorState.getSelection();
|
|
55
54
|
const contentState = editorState.getCurrentContent();
|
|
56
55
|
|
|
57
|
-
let newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, CUSTOM_STYLE_PREFIX_FONT_COLOR);
|
|
56
|
+
let newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_FONT_COLOR);
|
|
58
57
|
|
|
59
58
|
if (colorValue) {
|
|
60
|
-
newContentState = _modifier.Modifier.applyInlineStyle(newContentState, selection, CUSTOM_STYLE_PREFIX_FONT_COLOR + colorValue);
|
|
59
|
+
newContentState = _modifier.Modifier.applyInlineStyle(newContentState, selection, _const.CUSTOM_STYLE_PREFIX_FONT_COLOR + colorValue);
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
|
|
@@ -78,7 +77,7 @@ function FontColorButton(props) {
|
|
|
78
77
|
if (!selection.isCollapsed()) {
|
|
79
78
|
const contentState = editorState.getCurrentContent();
|
|
80
79
|
|
|
81
|
-
const newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, CUSTOM_STYLE_PREFIX_FONT_COLOR);
|
|
80
|
+
const newContentState = _modifier.Modifier.removeInlineStyleByPrefix(contentState, selection, _const.CUSTOM_STYLE_PREFIX_FONT_COLOR);
|
|
82
81
|
|
|
83
82
|
onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-inline-style'));
|
|
84
83
|
}
|
|
@@ -8,17 +8,13 @@ exports.InfoBoxInput = InfoBoxInput;
|
|
|
8
8
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
|
|
11
|
-
var _entityDecorator = _interopRequireDefault(require("../editor/entity-decorator"));
|
|
12
|
-
|
|
13
11
|
var _draftJs = require("draft-js");
|
|
14
12
|
|
|
15
|
-
var _basicEditor = require("../editor/basic-editor");
|
|
16
|
-
|
|
17
13
|
var _modals = require("@keystone-ui/modals");
|
|
18
14
|
|
|
19
15
|
var _fields = require("@keystone-ui/fields");
|
|
20
16
|
|
|
21
|
-
var _draftConverter = _interopRequireDefault(require("../
|
|
17
|
+
var _draftConverter = _interopRequireDefault(require("../draft-converter"));
|
|
22
18
|
|
|
23
19
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
24
20
|
|
|
@@ -39,7 +35,9 @@ function InfoBoxInput(props) {
|
|
|
39
35
|
onChange,
|
|
40
36
|
onCancel,
|
|
41
37
|
title,
|
|
42
|
-
rawContentStateForInfoBoxEditor
|
|
38
|
+
rawContentStateForInfoBoxEditor,
|
|
39
|
+
renderBasicEditor,
|
|
40
|
+
decorators
|
|
43
41
|
} = props;
|
|
44
42
|
const rawContentState = rawContentStateForInfoBoxEditor || {
|
|
45
43
|
blocks: [],
|
|
@@ -48,7 +46,7 @@ function InfoBoxInput(props) {
|
|
|
48
46
|
const initialInputValue = {
|
|
49
47
|
title: title || '',
|
|
50
48
|
// create an `editorState` from raw content state object
|
|
51
|
-
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState),
|
|
49
|
+
editorStateOfBasicEditor: _draftJs.EditorState.createWithContent((0, _draftJs.convertFromRaw)(rawContentState), decorators)
|
|
52
50
|
};
|
|
53
51
|
const [inputValue, setInputValue] = (0, _react.useState)(initialInputValue);
|
|
54
52
|
|
|
@@ -56,6 +54,15 @@ function InfoBoxInput(props) {
|
|
|
56
54
|
setInputValue(initialInputValue);
|
|
57
55
|
};
|
|
58
56
|
|
|
57
|
+
const basicEditorJsx = renderBasicEditor({
|
|
58
|
+
editorState: inputValue.editorStateOfBasicEditor,
|
|
59
|
+
onChange: editorStateOfBasicEditor => {
|
|
60
|
+
setInputValue({
|
|
61
|
+
title: inputValue.title,
|
|
62
|
+
editorStateOfBasicEditor
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
59
66
|
return /*#__PURE__*/_react.default.createElement(_modals.DrawerController, {
|
|
60
67
|
isOpen: isOpen
|
|
61
68
|
}, /*#__PURE__*/_react.default.createElement(_modals.Drawer, {
|
|
@@ -88,15 +95,7 @@ function InfoBoxInput(props) {
|
|
|
88
95
|
type: "text",
|
|
89
96
|
placeholder: "Title",
|
|
90
97
|
value: inputValue.title
|
|
91
|
-
}),
|
|
92
|
-
editorState: inputValue.editorStateOfBasicEditor,
|
|
93
|
-
onChange: editorStateOfBasicEditor => {
|
|
94
|
-
setInputValue({
|
|
95
|
-
title: inputValue.title,
|
|
96
|
-
editorStateOfBasicEditor
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
})));
|
|
98
|
+
}), basicEditorJsx));
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
function InfoBoxButton(props) {
|
|
@@ -104,7 +103,8 @@ function InfoBoxButton(props) {
|
|
|
104
103
|
const {
|
|
105
104
|
className,
|
|
106
105
|
editorState,
|
|
107
|
-
onChange: onEditorStateChange
|
|
106
|
+
onChange: onEditorStateChange,
|
|
107
|
+
renderBasicEditor
|
|
108
108
|
} = props;
|
|
109
109
|
|
|
110
110
|
const onChange = ({
|
|
@@ -131,6 +131,7 @@ function InfoBoxButton(props) {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(InfoBoxInput, {
|
|
134
|
+
renderBasicEditor: renderBasicEditor,
|
|
134
135
|
onChange: onChange,
|
|
135
136
|
onCancel: () => {
|
|
136
137
|
setToShowInput(false);
|
|
@@ -11,7 +11,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
11
11
|
|
|
12
12
|
var _draftJs = require("draft-js");
|
|
13
13
|
|
|
14
|
-
var _modifier = require("../
|
|
14
|
+
var _modifier = require("../modifier");
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _const = require("@mirrormedia/lilith-draft-renderer/lib/draft-js/const");
|
|
8
|
+
|
|
9
|
+
Object.keys(_const).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _const[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _const[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -7,26 +7,24 @@ exports.convertToHtml = convertToHtml;
|
|
|
7
7
|
|
|
8
8
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _backgroundColor = require("../../buttons/background-color");
|
|
10
|
+
var _const = require("../const");
|
|
13
11
|
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
13
|
|
|
16
14
|
// Modified from https://github.com/dburrows/draft-js-basic-html-editor/blob/master/src/utils/processInlineStylesAndEntities.js
|
|
17
15
|
function tagForCustomInlineStyle(style) {
|
|
18
|
-
const customInlineStylePrefixs = [
|
|
16
|
+
const customInlineStylePrefixs = [_const.CUSTOM_STYLE_PREFIX_FONT_COLOR, _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR];
|
|
19
17
|
const stylePrefix = customInlineStylePrefixs.find(prefix => style.startsWith(prefix));
|
|
20
18
|
let tag, value;
|
|
21
19
|
|
|
22
20
|
switch (stylePrefix) {
|
|
23
|
-
case
|
|
24
|
-
value = style.split(
|
|
21
|
+
case _const.CUSTOM_STYLE_PREFIX_FONT_COLOR:
|
|
22
|
+
value = style.split(_const.CUSTOM_STYLE_PREFIX_FONT_COLOR)[1];
|
|
25
23
|
tag = [`<span style="color: ${value}">`, '</span>'];
|
|
26
24
|
break;
|
|
27
25
|
|
|
28
|
-
case
|
|
29
|
-
value = style.split(
|
|
26
|
+
case _const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR:
|
|
27
|
+
value = style.split(_const.CUSTOM_STYLE_PREFIX_BACKGROUND_COLOR)[1];
|
|
30
28
|
tag = [`<span style="background-color: ${value}">`, '</span>'];
|
|
31
29
|
break;
|
|
32
30
|
|