5htp-core 0.4.9-2 → 0.4.9-6
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/package.json +4 -1
- package/src/client/assets/css/components/lists.less +3 -3
- package/src/client/components/Form.ts +1 -1
- package/src/client/components/Select/ChoiceElement.tsx +20 -27
- package/src/client/components/Select/index.tsx +24 -42
- package/src/client/components/inputv3/Rte/Editor.tsx +16 -8
- package/src/client/components/inputv3/Rte/ToolbarPlugin/index.tsx +8 -12
- package/src/client/components/inputv3/Rte/nodes/HeadingNode.ts +55 -0
- package/src/client/components/inputv3/Rte/plugins/ComponentPickerPlugin/index.tsx +9 -6
- package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.css +23 -23
- package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.tsx +26 -24
- package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.css +10 -38
- package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.tsx +349 -356
- package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.css +80 -84
- package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.tsx +308 -347
- package/src/client/components/inputv3/Rte/style.less +0 -2
- package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.css +0 -11
- package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.ts +2 -2
- package/src/client/components/inputv3/base.less +0 -6
- package/src/client/components/inputv3/file/index.tsx +50 -48
- package/src/client/components/inputv3/index.tsx +1 -1
- package/src/client/services/router/request/api.ts +29 -13
- package/src/common/data/rte/nodes.ts +9 -1
- package/src/common/router/request/api.ts +6 -4
- package/src/server/services/disks/driver.ts +2 -0
- package/src/server/services/disks/drivers/s3/index.ts +30 -1
- package/src/server/utils/rte.ts +316 -46
- package/src/server/utils/slug.ts +67 -0
- package/src/client/components/inputv3/Rte/nodes/PlaygroundNodes.ts +0 -76
- package/src/server/services/schema/rte.ts +0 -110
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.4.9-
|
|
4
|
+
"version": "0.4.9-6",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"dayjs": "^1.11.5",
|
|
35
35
|
"deep-extend": "^0.6.0",
|
|
36
36
|
"dottie": "^2.0.2",
|
|
37
|
+
"escape-regexp": "^0.0.1",
|
|
37
38
|
"express": "^4.17.1",
|
|
38
39
|
"express-csp-header": "^5.0.0",
|
|
39
40
|
"express-fileupload": "^1.2.1",
|
|
@@ -74,7 +75,9 @@
|
|
|
74
75
|
"regenerator-runtime": "^0.13.9",
|
|
75
76
|
"request": "^2.88.2",
|
|
76
77
|
"sharp": "^0.29.1",
|
|
78
|
+
"slugify": "^1.6.6",
|
|
77
79
|
"sql-formatter": "^4.0.2",
|
|
80
|
+
"stopword": "^3.1.1",
|
|
78
81
|
"tslog": "^4.9.1",
|
|
79
82
|
"uuid": "^8.3.2",
|
|
80
83
|
"uuid-by-string": "^3.0.4",
|
|
@@ -94,9 +94,9 @@ ol.steps {
|
|
|
94
94
|
// Stepnumber = at the left
|
|
95
95
|
&:not(.col) {
|
|
96
96
|
|
|
97
|
-
padding-left: /*@sizeStep + */
|
|
97
|
+
padding-left: /*@sizeStep + */1.5em;
|
|
98
98
|
padding-top: (@sizeStep - @itemLineHeight) / 2;
|
|
99
|
-
line-height: @itemLineHeight;
|
|
99
|
+
//line-height: @itemLineHeight;
|
|
100
100
|
margin: 5px 0;
|
|
101
101
|
|
|
102
102
|
&:before {
|
|
@@ -124,7 +124,7 @@ strong.step {
|
|
|
124
124
|
font-weight: bold;
|
|
125
125
|
|
|
126
126
|
font-size: 1em;
|
|
127
|
-
line-height:
|
|
127
|
+
line-height: 2.2em;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/*----------------------------------
|
|
@@ -17,7 +17,7 @@ export type { TValidationResult, TSchemaData } from '@common/validation/schema';
|
|
|
17
17
|
/*----------------------------------
|
|
18
18
|
- TYPES
|
|
19
19
|
----------------------------------*/
|
|
20
|
-
type TFormOptions<TFormData extends {}> = {
|
|
20
|
+
export type TFormOptions<TFormData extends {}> = {
|
|
21
21
|
data?: Partial<TFormData>,
|
|
22
22
|
submit?: (data: TFormData) => Promise<void>,
|
|
23
23
|
autoValidateOnly?: (keyof TFormData)[],
|
|
@@ -34,7 +34,7 @@ export default ({ choice, currentList, onChange, multiple, includeCurrent, forma
|
|
|
34
34
|
|
|
35
35
|
return format === 'list' ? (
|
|
36
36
|
<li>
|
|
37
|
-
<Button
|
|
37
|
+
<Button active={isCurrent} onClick={() => onChange( current => multiple
|
|
38
38
|
? (isCurrent
|
|
39
39
|
? currentList.filter(item => item.value !== choice.value)
|
|
40
40
|
: [...(current || []), choice]
|
|
@@ -44,34 +44,27 @@ export default ({ choice, currentList, onChange, multiple, includeCurrent, forma
|
|
|
44
44
|
{choice.label}
|
|
45
45
|
</Button>
|
|
46
46
|
</li>
|
|
47
|
-
) : isCurrent ? (
|
|
48
|
-
<li class={"badge bg primary"+ (showRemoveButton ? ' pdr-05' : '')}>
|
|
49
|
-
{choice.label}
|
|
50
|
-
|
|
51
|
-
{showRemoveButton && (
|
|
52
|
-
<span class="badge xs clickable" onClick={(e) => {
|
|
53
|
-
e.stopPropagation();
|
|
54
|
-
onChange( current => current.filter( c => c.value !== choice.value))
|
|
55
|
-
return false;
|
|
56
|
-
}}>
|
|
57
|
-
x
|
|
58
|
-
</span>
|
|
59
|
-
)}
|
|
60
|
-
</li>
|
|
61
47
|
) : (
|
|
62
|
-
<li
|
|
63
|
-
onChange(
|
|
64
|
-
?
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
<strong>{search.keywords}</strong>{choice.label.slice( search.keywords.length )}
|
|
48
|
+
<li>
|
|
49
|
+
<Button type="secondary" active={isCurrent} onClick={() => onChange(current => multiple
|
|
50
|
+
? (isCurrent
|
|
51
|
+
? currentList.filter(item => item.value !== choice.value)
|
|
52
|
+
: [...(current || []), choice]
|
|
53
|
+
)
|
|
54
|
+
: isCurrent ? undefined : choice
|
|
55
|
+
)}>
|
|
56
|
+
{choice.label}
|
|
72
57
|
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
{showRemoveButton && (
|
|
59
|
+
<span class="badge xs clickable" onClick={(e) => {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
onChange( current => current.filter( c => c.value !== choice.value))
|
|
62
|
+
return false;
|
|
63
|
+
}}>
|
|
64
|
+
x
|
|
65
|
+
</span>
|
|
66
|
+
)}
|
|
67
|
+
</Button>
|
|
75
68
|
</li>
|
|
76
69
|
)
|
|
77
70
|
}
|
|
@@ -250,51 +250,33 @@ export default (props: Props) => {
|
|
|
250
250
|
) : (
|
|
251
251
|
<div class="col sp-05">
|
|
252
252
|
<div class={className} onMouseDown={() => refInputSearch.current?.focus()}>
|
|
253
|
-
|
|
254
|
-
<div class="row al-left wrap pd-1">
|
|
255
|
-
|
|
256
|
-
{icon !== undefined && (
|
|
257
|
-
<i src={icon} />
|
|
258
|
-
)}
|
|
259
|
-
|
|
260
|
-
<div class="col al-left sp-05">
|
|
261
|
-
|
|
262
|
-
<label>{title}{isRequired && (
|
|
263
|
-
<span class="fg error"> *</span>
|
|
264
|
-
)}</label>
|
|
265
|
-
|
|
266
|
-
<div class="row al-left wrap sp-05">
|
|
267
|
-
|
|
268
|
-
{selectedItems.map( choice => (
|
|
269
|
-
<ChoiceElement format='badge' choice={choice}
|
|
270
|
-
currentList={currentList}
|
|
271
|
-
onChange={onChange}
|
|
272
|
-
multiple={multiple}
|
|
273
|
-
includeCurrent
|
|
274
|
-
/>
|
|
275
|
-
))}
|
|
276
|
-
|
|
277
|
-
{Search}
|
|
278
|
-
</div>
|
|
279
|
-
</div>
|
|
280
253
|
|
|
281
|
-
|
|
254
|
+
<div class="row al-left wrap sp-05">
|
|
282
255
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
includeCurrent
|
|
294
|
-
/>
|
|
295
|
-
))}
|
|
296
|
-
</ul>
|
|
256
|
+
{selectedItems.map( choice => (
|
|
257
|
+
<ChoiceElement format='badge' choice={choice}
|
|
258
|
+
currentList={currentList}
|
|
259
|
+
onChange={onChange}
|
|
260
|
+
multiple={multiple}
|
|
261
|
+
includeCurrent
|
|
262
|
+
/>
|
|
263
|
+
))}
|
|
264
|
+
|
|
265
|
+
{Search}
|
|
297
266
|
</div>
|
|
267
|
+
|
|
268
|
+
<ul class="row al-left wrap sp-05" style={{
|
|
269
|
+
maxHeight: '30vh',
|
|
270
|
+
}}>
|
|
271
|
+
{choices.map( choice => (
|
|
272
|
+
<ChoiceElement format='badge' choice={choice}
|
|
273
|
+
currentList={currentList}
|
|
274
|
+
onChange={onChange}
|
|
275
|
+
multiple={multiple}
|
|
276
|
+
includeCurrent
|
|
277
|
+
/>
|
|
278
|
+
))}
|
|
279
|
+
</ul>
|
|
298
280
|
|
|
299
281
|
</div>
|
|
300
282
|
{errors?.length && (
|
|
@@ -119,6 +119,12 @@ export default ({ value, setValue, props }: {
|
|
|
119
119
|
// Trigger onchange oly when finished typing
|
|
120
120
|
const refCommit = React.useRef<NodeJS.Timeout | null>(null);
|
|
121
121
|
|
|
122
|
+
const onRef = (_floatingAnchorElem: HTMLDivElement) => {
|
|
123
|
+
if (_floatingAnchorElem !== null) {
|
|
124
|
+
setFloatingAnchorElem(_floatingAnchorElem);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
122
128
|
const { historyState } = useSharedHistoryContext();
|
|
123
129
|
const {
|
|
124
130
|
settings: {
|
|
@@ -176,16 +182,18 @@ export default ({ value, setValue, props }: {
|
|
|
176
182
|
}}>
|
|
177
183
|
<div className="editor-container">
|
|
178
184
|
<ToolbarPlugin setIsLinkEditMode={setIsLinkEditMode} />
|
|
179
|
-
<div className="editor-inner
|
|
185
|
+
<div className="editor-inner">
|
|
180
186
|
<RichTextPlugin
|
|
181
187
|
contentEditable={
|
|
182
|
-
<
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
<div className="editor pdh-2" ref={onRef}>
|
|
189
|
+
<ContentEditable
|
|
190
|
+
className="editor-input reading col"
|
|
191
|
+
aria-placeholder={"Type text here ..."}
|
|
192
|
+
placeholder={
|
|
193
|
+
<div className="editor-placeholder">Type text here ...</div>
|
|
194
|
+
}
|
|
195
|
+
/>
|
|
196
|
+
</div>
|
|
189
197
|
}
|
|
190
198
|
ErrorBoundary={LexicalErrorBoundary}
|
|
191
199
|
/>
|
|
@@ -16,7 +16,6 @@ import ElementFormatDropdown from './ElementFormat';
|
|
|
16
16
|
import BlockFormatDropDown, { blockTypeNames, rootTypeToRootName } from './BlockFormat';
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
|
-
$createCodeNode,
|
|
20
19
|
$isCodeNode,
|
|
21
20
|
CODE_LANGUAGE_FRIENDLY_NAME_MAP,
|
|
22
21
|
CODE_LANGUAGE_MAP,
|
|
@@ -25,9 +24,6 @@ import {
|
|
|
25
24
|
import { $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
|
|
26
25
|
import {
|
|
27
26
|
$isListNode,
|
|
28
|
-
INSERT_CHECK_LIST_COMMAND,
|
|
29
|
-
INSERT_ORDERED_LIST_COMMAND,
|
|
30
|
-
INSERT_UNORDERED_LIST_COMMAND,
|
|
31
27
|
ListNode,
|
|
32
28
|
} from '@lexical/list';
|
|
33
29
|
import { INSERT_EMBED_COMMAND } from '@lexical/react/LexicalAutoEmbedPlugin';
|
|
@@ -35,17 +31,13 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
|
|
|
35
31
|
import { $isDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
|
|
36
32
|
import { INSERT_HORIZONTAL_RULE_COMMAND } from '@lexical/react/LexicalHorizontalRuleNode';
|
|
37
33
|
import {
|
|
38
|
-
$createHeadingNode,
|
|
39
|
-
$createQuoteNode,
|
|
40
34
|
$isHeadingNode,
|
|
41
35
|
$isQuoteNode,
|
|
42
|
-
HeadingTagType,
|
|
43
36
|
} from '@lexical/rich-text';
|
|
44
37
|
import {
|
|
45
38
|
$getSelectionStyleValueForProperty,
|
|
46
39
|
$isParentElementRTL,
|
|
47
40
|
$patchStyleText,
|
|
48
|
-
$setBlocksType,
|
|
49
41
|
} from '@lexical/selection';
|
|
50
42
|
import { $isTableNode, $isTableSelection } from '@lexical/table';
|
|
51
43
|
import {
|
|
@@ -126,7 +118,7 @@ function dropDownActiveClass(active: boolean) {
|
|
|
126
118
|
|
|
127
119
|
|
|
128
120
|
|
|
129
|
-
function Divider(): JSX.Element {
|
|
121
|
+
function Divider(): React.JSX.Element {
|
|
130
122
|
return <div className="divider" />;
|
|
131
123
|
}
|
|
132
124
|
|
|
@@ -134,7 +126,7 @@ export default function ToolbarPlugin({
|
|
|
134
126
|
setIsLinkEditMode,
|
|
135
127
|
}: {
|
|
136
128
|
setIsLinkEditMode: Dispatch<boolean>;
|
|
137
|
-
}): JSX.Element {
|
|
129
|
+
}): React.JSX.Element {
|
|
138
130
|
|
|
139
131
|
const { modal } = useContext();
|
|
140
132
|
|
|
@@ -482,7 +474,12 @@ export default function ToolbarPlugin({
|
|
|
482
474
|
const canViewerSeeInsertCodeButton = !isImageCaption;
|
|
483
475
|
|
|
484
476
|
return (
|
|
485
|
-
<div className="row menu al-left"
|
|
477
|
+
<div className="row menu al-left" style={{
|
|
478
|
+
position: 'sticky',
|
|
479
|
+
top: 0,
|
|
480
|
+
background: 'white',
|
|
481
|
+
'zIndex': 5
|
|
482
|
+
}}>
|
|
486
483
|
|
|
487
484
|
{/* <Button icon="undo" size="s"
|
|
488
485
|
disabled={!canUndo || !isEditable}
|
|
@@ -598,7 +595,6 @@ export default function ToolbarPlugin({
|
|
|
598
595
|
<DropDown popover={{ tag: 'li' }} icon="font" size="s"
|
|
599
596
|
disabled={!isEditable}
|
|
600
597
|
title="Formatting options for additional text styles"
|
|
601
|
-
buttonIconClassName="icon dropdown-more"
|
|
602
598
|
>
|
|
603
599
|
|
|
604
600
|
<Button icon="strikethrough" size="s"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
import { HeadingNode, HeadingTagType } from '@lexical/rich-text';
|
|
3
|
+
|
|
4
|
+
export default class HeadingWithAnchorNode extends HeadingNode {
|
|
5
|
+
|
|
6
|
+
public anchor?: string;
|
|
7
|
+
|
|
8
|
+
constructor( tag: HeadingTagType, key?: string ) {
|
|
9
|
+
super(tag, key);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Adding a static method to register the custom node
|
|
13
|
+
static getType() {
|
|
14
|
+
return 'anchored-heading';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static clone(node) {
|
|
18
|
+
return new HeadingWithAnchorNode(node.getTag(), node.__key);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Add a `anchor` attribute to the serialized JSON
|
|
22
|
+
static importJSON(serializedNode) {
|
|
23
|
+
const node = new HeadingWithAnchorNode(serializedNode.tag);
|
|
24
|
+
node.anchor = serializedNode.anchor;
|
|
25
|
+
return node;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Ensure the `anchor` attribute is serialized in JSON
|
|
29
|
+
exportJSON() {
|
|
30
|
+
return {
|
|
31
|
+
...super.exportJSON(),
|
|
32
|
+
type: HeadingWithAnchorNode.getType(),
|
|
33
|
+
anchor: this.anchor,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Override createDOM to set the `anchor` attribute
|
|
38
|
+
createDOM(config) {
|
|
39
|
+
const dom = super.createDOM(config);
|
|
40
|
+
if (this.anchor) {
|
|
41
|
+
dom.setAttribute('id', this.anchor);
|
|
42
|
+
}
|
|
43
|
+
return dom;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Update the DOM to reflect changes in the `anchor` attribute
|
|
47
|
+
updateDOM(prevNode, dom) {
|
|
48
|
+
const updated = super.updateDOM(prevNode, dom);
|
|
49
|
+
if (this.anchor !== prevNode.anchor) {
|
|
50
|
+
dom.setAttribute('id', this.anchor);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return updated;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -36,7 +36,10 @@ import * as React from 'react';
|
|
|
36
36
|
import * as ReactDOM from 'react-dom';
|
|
37
37
|
|
|
38
38
|
// Core
|
|
39
|
-
import useContext from '@/client/context';
|
|
39
|
+
import useContext, { ClientContext } from '@/client/context';
|
|
40
|
+
|
|
41
|
+
// Custom Nodes
|
|
42
|
+
import AnchoredHeadingNode from '@client/components/inputv3/Rte/nodes/HeadingNode';
|
|
40
43
|
|
|
41
44
|
import { EmbedConfigs } from '../AutoEmbedPlugin';
|
|
42
45
|
import { INSERT_COLLAPSIBLE_COMMAND } from '../CollapsiblePlugin';
|
|
@@ -50,7 +53,7 @@ class ComponentPickerOption extends MenuOption {
|
|
|
50
53
|
// What shows up in the editor
|
|
51
54
|
title: string;
|
|
52
55
|
// Icon for display
|
|
53
|
-
icon?: JSX.Element;
|
|
56
|
+
icon?: React.JSX.Element;
|
|
54
57
|
// For extra searching.
|
|
55
58
|
keywords: Array<string>;
|
|
56
59
|
// TBD
|
|
@@ -61,7 +64,7 @@ class ComponentPickerOption extends MenuOption {
|
|
|
61
64
|
constructor(
|
|
62
65
|
title: string,
|
|
63
66
|
options: {
|
|
64
|
-
icon?: JSX.Element;
|
|
67
|
+
icon?: React.JSX.Element;
|
|
65
68
|
keywords?: Array<string>;
|
|
66
69
|
keyboardShortcut?: string;
|
|
67
70
|
onSelect: (queryString: string) => void;
|
|
@@ -141,7 +144,7 @@ function getDynamicOptions(editor: LexicalEditor, queryString: string) {
|
|
|
141
144
|
return options;
|
|
142
145
|
}
|
|
143
146
|
|
|
144
|
-
function getBaseOptions(editor: LexicalEditor, { modal }:
|
|
147
|
+
function getBaseOptions(editor: LexicalEditor, { modal }: ClientContext) {
|
|
145
148
|
return [
|
|
146
149
|
new ComponentPickerOption('Paragraph', {
|
|
147
150
|
icon: <i className="icon paragraph" />,
|
|
@@ -163,7 +166,7 @@ function getBaseOptions(editor: LexicalEditor, { modal }: TContext) {
|
|
|
163
166
|
editor.update(() => {
|
|
164
167
|
const selection = $getSelection();
|
|
165
168
|
if ($isRangeSelection(selection)) {
|
|
166
|
-
$setBlocksType(selection, () =>
|
|
169
|
+
$setBlocksType(selection, () => new AnchoredHeadingNode(`h${n}`));
|
|
167
170
|
}
|
|
168
171
|
}),
|
|
169
172
|
}),
|
|
@@ -281,7 +284,7 @@ function getBaseOptions(editor: LexicalEditor, { modal }: TContext) {
|
|
|
281
284
|
];
|
|
282
285
|
}
|
|
283
286
|
|
|
284
|
-
export default function ComponentPickerMenuPlugin(): JSX.Element {
|
|
287
|
+
export default function ComponentPickerMenuPlugin(): React.JSX.Element {
|
|
285
288
|
|
|
286
289
|
const [editor] = useLexicalComposerContext();
|
|
287
290
|
const { modal, context } = useContext();
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
.draggable-block-menu {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
border-radius: 4px;
|
|
3
|
+
padding: 2px 1px;
|
|
4
|
+
cursor: grab;
|
|
5
|
+
opacity: 0;
|
|
6
|
+
position: absolute;
|
|
7
|
+
left: 0;
|
|
8
|
+
top: 0;
|
|
9
|
+
will-change: transform;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
.draggable-block-menu .icon {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
width: 16px;
|
|
14
|
+
height: 16px;
|
|
15
|
+
opacity: 0.3;
|
|
16
|
+
background-image: url(../../images/icons/draggable-block-menu.svg);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
.draggable-block-menu:active {
|
|
20
|
-
|
|
20
|
+
cursor: grabbing;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
.draggable-block-menu:hover {
|
|
24
|
-
|
|
24
|
+
background-color: #efefef;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
.draggable-block-target-line {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
background: deepskyblue;
|
|
30
|
+
height: 4px;
|
|
31
|
+
position: absolute;
|
|
32
|
+
left: 0;
|
|
33
|
+
top: 0;
|
|
34
|
+
opacity: 0;
|
|
35
|
+
will-change: transform;
|
|
36
|
+
}
|
|
@@ -7,37 +7,39 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import './index.css';
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
|
|
10
|
+
import React from 'react';
|
|
11
|
+
|
|
12
|
+
import { DraggableBlockPlugin_EXPERIMENTAL } from '@lexical/react/LexicalDraggableBlockPlugin';
|
|
13
|
+
import { useRef } from 'react';
|
|
12
14
|
|
|
13
15
|
const DRAGGABLE_BLOCK_MENU_CLASSNAME = 'draggable-block-menu';
|
|
14
16
|
|
|
15
17
|
function isOnMenu(element: HTMLElement): boolean {
|
|
16
|
-
|
|
18
|
+
return !!element.closest(`.${DRAGGABLE_BLOCK_MENU_CLASSNAME}`);
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export default function DraggableBlockPlugin({
|
|
20
|
-
|
|
22
|
+
anchorElem = document.body,
|
|
21
23
|
}: {
|
|
22
|
-
|
|
23
|
-
}): JSX.Element {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
anchorElem?: HTMLElement;
|
|
25
|
+
}): React.JSX.Element {
|
|
26
|
+
const menuRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
const targetLineRef = useRef<HTMLDivElement>(null);
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
return (
|
|
30
|
+
<DraggableBlockPlugin_EXPERIMENTAL
|
|
31
|
+
anchorElem={anchorElem}
|
|
32
|
+
menuRef={menuRef}
|
|
33
|
+
targetLineRef={targetLineRef}
|
|
34
|
+
menuComponent={
|
|
35
|
+
<div ref={menuRef} className="icon draggable-block-menu">
|
|
36
|
+
<div className="icon" />
|
|
37
|
+
</div>
|
|
38
|
+
}
|
|
39
|
+
targetLineComponent={
|
|
40
|
+
<div ref={targetLineRef} className="draggable-block-target-line" />
|
|
41
|
+
}
|
|
42
|
+
isOnMenu={isOnMenu}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
43
45
|
}
|
|
@@ -1,41 +1,13 @@
|
|
|
1
1
|
.link-editor {
|
|
2
|
-
display: flex;
|
|
3
|
-
position: absolute;
|
|
4
|
-
top: 0;
|
|
5
|
-
left: 0;
|
|
6
|
-
z-index: 10;
|
|
7
|
-
max-width: 400px;
|
|
8
|
-
width: 100%;
|
|
9
|
-
opacity: 0;
|
|
10
|
-
background-color: #fff;
|
|
11
|
-
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
|
|
12
|
-
border-radius: 0 0 8px 8px;
|
|
13
|
-
transition: opacity 0.5s;
|
|
14
|
-
will-change: transform;
|
|
15
|
-
}
|
|
16
2
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
cursor: pointer;
|
|
24
|
-
margin: 0 2px;
|
|
25
|
-
}
|
|
3
|
+
position: absolute;
|
|
4
|
+
top: 0;
|
|
5
|
+
left: 0;
|
|
6
|
+
z-index: 10;
|
|
7
|
+
max-width: 400px;
|
|
8
|
+
width: 100%;
|
|
26
9
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
background-color: #eee;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.link-editor .button i,
|
|
35
|
-
.actions i {
|
|
36
|
-
background-size: contain;
|
|
37
|
-
display: inline-block;
|
|
38
|
-
height: 20px;
|
|
39
|
-
width: 20px;
|
|
40
|
-
vertical-align: -0.25em;
|
|
41
|
-
}
|
|
10
|
+
opacity: 0;
|
|
11
|
+
transition: opacity 0.5s;
|
|
12
|
+
will-change: transform;
|
|
13
|
+
}
|