@selfcommunity/react-ui 0.10.2-courses.159 → 0.10.2-courses.161
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/cjs/components/CommentObjectReply/CommentObjectReply.js +11 -5
- package/lib/cjs/components/Composer/Content/ContentLesson/ContentLesson.js +35 -4
- package/lib/cjs/components/CourseDashboard/Teacher/Comments.js +2 -2
- package/lib/cjs/components/CourseParticipantsButton/CourseParticipantsButton.js +1 -1
- package/lib/cjs/components/Editor/Editor.d.ts +13 -1
- package/lib/cjs/components/Editor/Editor.js +3 -4
- package/lib/cjs/components/Editor/nodes/index.d.ts +1 -2
- package/lib/cjs/components/Editor/nodes/index.js +1 -3
- package/lib/cjs/components/Editor/plugins/MediaPlugin.d.ts +2 -1
- package/lib/cjs/components/Editor/plugins/MediaPlugin.js +5 -27
- package/lib/cjs/components/Editor/plugins/ToolbarPlugin.d.ts +2 -0
- package/lib/cjs/components/Editor/plugins/ToolbarPlugin.js +2 -2
- package/lib/cjs/components/LessonCommentObject/LessonCommentObject.d.ts +1 -0
- package/lib/cjs/components/LessonCommentObject/LessonCommentObject.js +8 -2
- package/lib/cjs/components/LessonCommentObjects/LessonCommentObjects.js +5 -1
- package/lib/cjs/components/LessonObject/LessonObject.js +7 -3
- package/lib/cjs/shared/AccordionLessons/AccordionLessons.js +5 -4
- package/lib/cjs/shared/LessonFilePreview/index.d.ts +12 -0
- package/lib/cjs/shared/LessonFilePreview/index.js +29 -0
- package/lib/cjs/shared/Media/Link/UrlTextField/index.js +2 -3
- package/lib/esm/components/CommentObjectReply/CommentObjectReply.js +11 -5
- package/lib/esm/components/Composer/Content/ContentLesson/ContentLesson.js +37 -6
- package/lib/esm/components/CourseDashboard/Teacher/Comments.js +3 -3
- package/lib/esm/components/CourseParticipantsButton/CourseParticipantsButton.js +1 -1
- package/lib/esm/components/Editor/Editor.d.ts +13 -1
- package/lib/esm/components/Editor/Editor.js +3 -4
- package/lib/esm/components/Editor/nodes/index.d.ts +1 -2
- package/lib/esm/components/Editor/nodes/index.js +1 -3
- package/lib/esm/components/Editor/plugins/MediaPlugin.d.ts +2 -1
- package/lib/esm/components/Editor/plugins/MediaPlugin.js +5 -27
- package/lib/esm/components/Editor/plugins/ToolbarPlugin.d.ts +2 -0
- package/lib/esm/components/Editor/plugins/ToolbarPlugin.js +2 -2
- package/lib/esm/components/LessonCommentObject/LessonCommentObject.d.ts +1 -0
- package/lib/esm/components/LessonCommentObject/LessonCommentObject.js +8 -2
- package/lib/esm/components/LessonCommentObjects/LessonCommentObjects.js +5 -1
- package/lib/esm/components/LessonObject/LessonObject.js +8 -4
- package/lib/esm/shared/AccordionLessons/AccordionLessons.js +6 -5
- package/lib/esm/shared/LessonFilePreview/index.d.ts +12 -0
- package/lib/esm/shared/LessonFilePreview/index.js +25 -0
- package/lib/esm/shared/Media/Link/UrlTextField/index.js +3 -4
- package/lib/umd/react-ui.js +1 -1
- package/package.json +8 -8
- package/lib/cjs/components/Editor/nodes/DocNode.d.ts +0 -39
- package/lib/cjs/components/Editor/nodes/DocNode.js +0 -181
- package/lib/esm/components/Editor/nodes/DocNode.d.ts +0 -39
- package/lib/esm/components/Editor/nodes/DocNode.js +0 -175
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfcommunity/react-ui",
|
|
3
|
-
"version": "0.10.2-courses.
|
|
3
|
+
"version": "0.10.2-courses.161+6ee05aeb9",
|
|
4
4
|
"description": "React UI Components to integrate a Community created with SelfCommunity Platform.",
|
|
5
5
|
"author": "SelfCommunity <https://www.selfcommunity.com>",
|
|
6
6
|
"homepage": "https://www.selfcommunity.com",
|
|
@@ -97,12 +97,12 @@
|
|
|
97
97
|
"@rpldy/upload-drop-zone": "^1.7.1",
|
|
98
98
|
"@rpldy/upload-preview": "^1.7.1",
|
|
99
99
|
"@rpldy/uploady": "^1.7.1",
|
|
100
|
-
"@selfcommunity/api-services": "0.6.4-courses.
|
|
101
|
-
"@selfcommunity/react-core": "0.6.4-courses.
|
|
102
|
-
"@selfcommunity/react-i18n": "0.7.4-courses.
|
|
103
|
-
"@selfcommunity/react-theme-default": "0.4.2-courses.
|
|
104
|
-
"@selfcommunity/types": "0.7.4-courses.
|
|
105
|
-
"@selfcommunity/utils": "0.2.61-courses.
|
|
100
|
+
"@selfcommunity/api-services": "0.6.4-courses.209+6ee05aeb9",
|
|
101
|
+
"@selfcommunity/react-core": "0.6.4-courses.163+6ee05aeb9",
|
|
102
|
+
"@selfcommunity/react-i18n": "0.7.4-courses.163+6ee05aeb9",
|
|
103
|
+
"@selfcommunity/react-theme-default": "0.4.2-courses.161+6ee05aeb9",
|
|
104
|
+
"@selfcommunity/types": "0.7.4-courses.209+6ee05aeb9",
|
|
105
|
+
"@selfcommunity/utils": "0.2.61-courses.209+6ee05aeb9",
|
|
106
106
|
"@types/classnames": "^2.3.1",
|
|
107
107
|
"@types/sortablejs": "1",
|
|
108
108
|
"autosuggest-highlight": "^3.3.4",
|
|
@@ -197,5 +197,5 @@
|
|
|
197
197
|
"engines": {
|
|
198
198
|
"node": ">=20.x"
|
|
199
199
|
},
|
|
200
|
-
"gitHead": "
|
|
200
|
+
"gitHead": "6ee05aeb9f43e80c5b7780e8c99e6afcd8cceb5f"
|
|
201
201
|
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { DecoratorNode, DOMExportOutput, EditorConfig, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
|
|
2
|
-
export interface DocPayload {
|
|
3
|
-
name: string;
|
|
4
|
-
src: string;
|
|
5
|
-
type: string;
|
|
6
|
-
className?: string;
|
|
7
|
-
}
|
|
8
|
-
declare function convertDocElement(domNode: HTMLElement): {
|
|
9
|
-
node: DocNode;
|
|
10
|
-
};
|
|
11
|
-
export declare type SerializedDocNode = Spread<{
|
|
12
|
-
src: string;
|
|
13
|
-
name: string;
|
|
14
|
-
type: 'doc';
|
|
15
|
-
version: 1;
|
|
16
|
-
}, SerializedLexicalNode>;
|
|
17
|
-
export declare class DocNode extends DecoratorNode<JSX.Element> {
|
|
18
|
-
__src: string;
|
|
19
|
-
__name: string;
|
|
20
|
-
__type: string;
|
|
21
|
-
static getType(): string;
|
|
22
|
-
static clone(node: DocNode): DocNode;
|
|
23
|
-
constructor(src: string, name: string, type?: string, key?: NodeKey);
|
|
24
|
-
createDOM(config: EditorConfig): HTMLElement;
|
|
25
|
-
updateDOM(): false;
|
|
26
|
-
static importDOM(): {
|
|
27
|
-
div: (node: HTMLElement) => {
|
|
28
|
-
conversion: typeof convertDocElement;
|
|
29
|
-
priority: number;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
exportDOM(): DOMExportOutput;
|
|
33
|
-
decorate(): JSX.Element;
|
|
34
|
-
static importJSON(serializedNode: SerializedDocNode): DocNode;
|
|
35
|
-
exportJSON(): SerializedDocNode;
|
|
36
|
-
}
|
|
37
|
-
export declare function $createDocNode({ src, name, type }: DocPayload): DocNode;
|
|
38
|
-
export declare function $isDocNode(node?: LexicalNode): boolean;
|
|
39
|
-
export {};
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.$isDocNode = exports.$createDocNode = exports.DocNode = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const lexical_1 = require("lexical");
|
|
7
|
-
const thumbnailCoverter_1 = require("../../../utils/thumbnailCoverter");
|
|
8
|
-
const useLexicalNodeSelection_1 = require("@lexical/react/useLexicalNodeSelection");
|
|
9
|
-
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
|
|
10
|
-
const material_1 = require("@mui/material");
|
|
11
|
-
const utils_1 = require("@lexical/utils");
|
|
12
|
-
function DocComponent({ src, name, nodeKey }) {
|
|
13
|
-
const ref = (0, react_1.useRef)(null);
|
|
14
|
-
const buttonRef = (0, react_1.useRef)(null);
|
|
15
|
-
const [isSelected, setSelected, clearSelection] = (0, useLexicalNodeSelection_1.useLexicalNodeSelection)(nodeKey);
|
|
16
|
-
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
17
|
-
const activeEditorRef = (0, react_1.useRef)(null);
|
|
18
|
-
const onDelete = (0, react_1.useCallback)((payload) => {
|
|
19
|
-
if (isSelected && (0, lexical_1.$isNodeSelection)((0, lexical_1.$getSelection)())) {
|
|
20
|
-
const event = payload;
|
|
21
|
-
event.preventDefault();
|
|
22
|
-
const node = (0, lexical_1.$getNodeByKey)(nodeKey);
|
|
23
|
-
if ($isDocNode(node)) {
|
|
24
|
-
node.remove();
|
|
25
|
-
}
|
|
26
|
-
setSelected(false);
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
}, [isSelected, nodeKey, setSelected]);
|
|
30
|
-
const onEnter = (0, react_1.useCallback)((event) => {
|
|
31
|
-
const latestSelection = (0, lexical_1.$getSelection)();
|
|
32
|
-
const buttonElem = buttonRef.current;
|
|
33
|
-
if (isSelected && (0, lexical_1.$isNodeSelection)(latestSelection) && latestSelection.getNodes().length === 1) {
|
|
34
|
-
if (buttonElem !== null && buttonElem !== document.activeElement) {
|
|
35
|
-
event.preventDefault();
|
|
36
|
-
buttonElem.focus();
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}, [isSelected]);
|
|
42
|
-
const onEscape = (0, react_1.useCallback)((event) => {
|
|
43
|
-
if (buttonRef.current === event.target) {
|
|
44
|
-
(0, lexical_1.$setSelection)(null);
|
|
45
|
-
editor.update(() => {
|
|
46
|
-
setSelected(true);
|
|
47
|
-
const parentRootElement = editor.getRootElement();
|
|
48
|
-
if (parentRootElement !== null) {
|
|
49
|
-
parentRootElement.focus();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}, [editor, setSelected]);
|
|
56
|
-
(0, react_1.useEffect)(() => {
|
|
57
|
-
const unregister = (0, utils_1.mergeRegister)(editor.registerCommand(lexical_1.SELECTION_CHANGE_COMMAND, (_, activeEditor) => {
|
|
58
|
-
activeEditorRef.current = activeEditor;
|
|
59
|
-
return false;
|
|
60
|
-
}, lexical_1.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical_1.CLICK_COMMAND, (payload) => {
|
|
61
|
-
const event = payload;
|
|
62
|
-
if (event.target === ref.current) {
|
|
63
|
-
if (event.shiftKey) {
|
|
64
|
-
setSelected(!isSelected);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
clearSelection();
|
|
68
|
-
setSelected(true);
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
return false;
|
|
73
|
-
}, lexical_1.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical_1.KEY_DELETE_COMMAND, onDelete, lexical_1.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical_1.KEY_BACKSPACE_COMMAND, onDelete, lexical_1.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical_1.KEY_ENTER_COMMAND, onEnter, lexical_1.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical_1.KEY_ESCAPE_COMMAND, onEscape, lexical_1.COMMAND_PRIORITY_LOW));
|
|
74
|
-
return () => {
|
|
75
|
-
unregister();
|
|
76
|
-
};
|
|
77
|
-
}, [clearSelection, editor, isSelected, nodeKey, onDelete, onEnter, onEscape, setSelected]);
|
|
78
|
-
return ((0, jsx_runtime_1.jsx)(react_1.Suspense, Object.assign({ fallback: null }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ ref: ref, className: isSelected ? `selected` : null }, { children: (0, jsx_runtime_1.jsxs)(material_1.Link, Object.assign({ href: src, target: "_blank", rel: "noopener noreferrer", underline: "none" }, { children: [(0, jsx_runtime_1.jsx)("img", { src: thumbnailCoverter_1.documentPlaceholder, alt: name }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body1", color: 'text.primary' }, { children: name }))] })) })) })));
|
|
79
|
-
}
|
|
80
|
-
function convertDocElement(domNode) {
|
|
81
|
-
if (domNode instanceof HTMLDivElement && domNode.getAttribute('src')) {
|
|
82
|
-
const src = domNode.getAttribute('src');
|
|
83
|
-
const name = domNode.getAttribute('alt') || 'Untitled Document';
|
|
84
|
-
return { node: $createDocNode({ src, name, type: 'doc' }) };
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
class DocNode extends lexical_1.DecoratorNode {
|
|
91
|
-
constructor(src, name, type, key) {
|
|
92
|
-
super(key);
|
|
93
|
-
this.__src = src;
|
|
94
|
-
this.__name = name;
|
|
95
|
-
this.__type = type;
|
|
96
|
-
}
|
|
97
|
-
static getType() {
|
|
98
|
-
return 'doc';
|
|
99
|
-
}
|
|
100
|
-
static clone(node) {
|
|
101
|
-
return new DocNode(node.__src, node.__name, node.__type, node.__key);
|
|
102
|
-
}
|
|
103
|
-
createDOM(config) {
|
|
104
|
-
const div = document.createElement('div');
|
|
105
|
-
const theme = config.theme;
|
|
106
|
-
const className = theme.document;
|
|
107
|
-
if (className !== undefined) {
|
|
108
|
-
div.className = className;
|
|
109
|
-
}
|
|
110
|
-
return div;
|
|
111
|
-
}
|
|
112
|
-
updateDOM() {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
static importDOM() {
|
|
116
|
-
return {
|
|
117
|
-
div: (node) => {
|
|
118
|
-
if (node.hasAttribute('src')) {
|
|
119
|
-
return {
|
|
120
|
-
conversion: convertDocElement,
|
|
121
|
-
priority: 1
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
exportDOM() {
|
|
129
|
-
const element = document.createElement('div');
|
|
130
|
-
element.setAttribute('src', this.__src);
|
|
131
|
-
element.setAttribute('alt', this.__name);
|
|
132
|
-
element.className = 'SCEditor-document';
|
|
133
|
-
const link = document.createElement('a');
|
|
134
|
-
link.href = this.__src;
|
|
135
|
-
link.target = '_blank';
|
|
136
|
-
link.rel = 'noopener noreferrer';
|
|
137
|
-
link.title = this.__name;
|
|
138
|
-
link.style.textDecoration = 'none';
|
|
139
|
-
// Add an Image
|
|
140
|
-
const img = document.createElement('img');
|
|
141
|
-
img.src = thumbnailCoverter_1.documentPlaceholder;
|
|
142
|
-
img.alt = this.__name;
|
|
143
|
-
img.style.marginRight = '8px';
|
|
144
|
-
// Add a Typography-like Text Node
|
|
145
|
-
const text = document.createElement('span');
|
|
146
|
-
text.textContent = this.__name;
|
|
147
|
-
// Append elements
|
|
148
|
-
link.append(img, text);
|
|
149
|
-
element.appendChild(link);
|
|
150
|
-
return { element };
|
|
151
|
-
}
|
|
152
|
-
decorate() {
|
|
153
|
-
return (0, jsx_runtime_1.jsx)(DocComponent, { src: this.__src, name: this.__name, nodeKey: this.getKey() });
|
|
154
|
-
}
|
|
155
|
-
static importJSON(serializedNode) {
|
|
156
|
-
const { src, name, type } = serializedNode;
|
|
157
|
-
const node = $createDocNode({
|
|
158
|
-
src,
|
|
159
|
-
name,
|
|
160
|
-
type
|
|
161
|
-
});
|
|
162
|
-
return node;
|
|
163
|
-
}
|
|
164
|
-
exportJSON() {
|
|
165
|
-
return {
|
|
166
|
-
src: this.__src,
|
|
167
|
-
name: this.__name,
|
|
168
|
-
type: 'doc',
|
|
169
|
-
version: 1
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.DocNode = DocNode;
|
|
174
|
-
function $createDocNode({ src, name, type }) {
|
|
175
|
-
return new DocNode(src, name, type);
|
|
176
|
-
}
|
|
177
|
-
exports.$createDocNode = $createDocNode;
|
|
178
|
-
function $isDocNode(node) {
|
|
179
|
-
return node.getType() === 'doc';
|
|
180
|
-
}
|
|
181
|
-
exports.$isDocNode = $isDocNode;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { DecoratorNode, DOMExportOutput, EditorConfig, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
|
|
2
|
-
export interface DocPayload {
|
|
3
|
-
name: string;
|
|
4
|
-
src: string;
|
|
5
|
-
type: string;
|
|
6
|
-
className?: string;
|
|
7
|
-
}
|
|
8
|
-
declare function convertDocElement(domNode: HTMLElement): {
|
|
9
|
-
node: DocNode;
|
|
10
|
-
};
|
|
11
|
-
export declare type SerializedDocNode = Spread<{
|
|
12
|
-
src: string;
|
|
13
|
-
name: string;
|
|
14
|
-
type: 'doc';
|
|
15
|
-
version: 1;
|
|
16
|
-
}, SerializedLexicalNode>;
|
|
17
|
-
export declare class DocNode extends DecoratorNode<JSX.Element> {
|
|
18
|
-
__src: string;
|
|
19
|
-
__name: string;
|
|
20
|
-
__type: string;
|
|
21
|
-
static getType(): string;
|
|
22
|
-
static clone(node: DocNode): DocNode;
|
|
23
|
-
constructor(src: string, name: string, type?: string, key?: NodeKey);
|
|
24
|
-
createDOM(config: EditorConfig): HTMLElement;
|
|
25
|
-
updateDOM(): false;
|
|
26
|
-
static importDOM(): {
|
|
27
|
-
div: (node: HTMLElement) => {
|
|
28
|
-
conversion: typeof convertDocElement;
|
|
29
|
-
priority: number;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
exportDOM(): DOMExportOutput;
|
|
33
|
-
decorate(): JSX.Element;
|
|
34
|
-
static importJSON(serializedNode: SerializedDocNode): DocNode;
|
|
35
|
-
exportJSON(): SerializedDocNode;
|
|
36
|
-
}
|
|
37
|
-
export declare function $createDocNode({ src, name, type }: DocPayload): DocNode;
|
|
38
|
-
export declare function $isDocNode(node?: LexicalNode): boolean;
|
|
39
|
-
export {};
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Suspense, useCallback, useEffect, useRef } from 'react';
|
|
3
|
-
import { $getNodeByKey, $getSelection, $isNodeSelection, $setSelection, CLICK_COMMAND, COMMAND_PRIORITY_LOW, DecoratorNode, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, SELECTION_CHANGE_COMMAND } from 'lexical';
|
|
4
|
-
import { documentPlaceholder } from '../../../utils/thumbnailCoverter';
|
|
5
|
-
import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
|
|
6
|
-
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
7
|
-
import { Box, Link, Typography } from '@mui/material';
|
|
8
|
-
import { mergeRegister } from '@lexical/utils';
|
|
9
|
-
function DocComponent({ src, name, nodeKey }) {
|
|
10
|
-
const ref = useRef(null);
|
|
11
|
-
const buttonRef = useRef(null);
|
|
12
|
-
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
13
|
-
const [editor] = useLexicalComposerContext();
|
|
14
|
-
const activeEditorRef = useRef(null);
|
|
15
|
-
const onDelete = useCallback((payload) => {
|
|
16
|
-
if (isSelected && $isNodeSelection($getSelection())) {
|
|
17
|
-
const event = payload;
|
|
18
|
-
event.preventDefault();
|
|
19
|
-
const node = $getNodeByKey(nodeKey);
|
|
20
|
-
if ($isDocNode(node)) {
|
|
21
|
-
node.remove();
|
|
22
|
-
}
|
|
23
|
-
setSelected(false);
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}, [isSelected, nodeKey, setSelected]);
|
|
27
|
-
const onEnter = useCallback((event) => {
|
|
28
|
-
const latestSelection = $getSelection();
|
|
29
|
-
const buttonElem = buttonRef.current;
|
|
30
|
-
if (isSelected && $isNodeSelection(latestSelection) && latestSelection.getNodes().length === 1) {
|
|
31
|
-
if (buttonElem !== null && buttonElem !== document.activeElement) {
|
|
32
|
-
event.preventDefault();
|
|
33
|
-
buttonElem.focus();
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}, [isSelected]);
|
|
39
|
-
const onEscape = useCallback((event) => {
|
|
40
|
-
if (buttonRef.current === event.target) {
|
|
41
|
-
$setSelection(null);
|
|
42
|
-
editor.update(() => {
|
|
43
|
-
setSelected(true);
|
|
44
|
-
const parentRootElement = editor.getRootElement();
|
|
45
|
-
if (parentRootElement !== null) {
|
|
46
|
-
parentRootElement.focus();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
}, [editor, setSelected]);
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
const unregister = mergeRegister(editor.registerCommand(SELECTION_CHANGE_COMMAND, (_, activeEditor) => {
|
|
55
|
-
activeEditorRef.current = activeEditor;
|
|
56
|
-
return false;
|
|
57
|
-
}, COMMAND_PRIORITY_LOW), editor.registerCommand(CLICK_COMMAND, (payload) => {
|
|
58
|
-
const event = payload;
|
|
59
|
-
if (event.target === ref.current) {
|
|
60
|
-
if (event.shiftKey) {
|
|
61
|
-
setSelected(!isSelected);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
clearSelection();
|
|
65
|
-
setSelected(true);
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
return false;
|
|
70
|
-
}, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ENTER_COMMAND, onEnter, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ESCAPE_COMMAND, onEscape, COMMAND_PRIORITY_LOW));
|
|
71
|
-
return () => {
|
|
72
|
-
unregister();
|
|
73
|
-
};
|
|
74
|
-
}, [clearSelection, editor, isSelected, nodeKey, onDelete, onEnter, onEscape, setSelected]);
|
|
75
|
-
return (_jsx(Suspense, Object.assign({ fallback: null }, { children: _jsx(Box, Object.assign({ ref: ref, className: isSelected ? `selected` : null }, { children: _jsxs(Link, Object.assign({ href: src, target: "_blank", rel: "noopener noreferrer", underline: "none" }, { children: [_jsx("img", { src: documentPlaceholder, alt: name }), _jsx(Typography, Object.assign({ variant: "body1", color: 'text.primary' }, { children: name }))] })) })) })));
|
|
76
|
-
}
|
|
77
|
-
function convertDocElement(domNode) {
|
|
78
|
-
if (domNode instanceof HTMLDivElement && domNode.getAttribute('src')) {
|
|
79
|
-
const src = domNode.getAttribute('src');
|
|
80
|
-
const name = domNode.getAttribute('alt') || 'Untitled Document';
|
|
81
|
-
return { node: $createDocNode({ src, name, type: 'doc' }) };
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
export class DocNode extends DecoratorNode {
|
|
88
|
-
constructor(src, name, type, key) {
|
|
89
|
-
super(key);
|
|
90
|
-
this.__src = src;
|
|
91
|
-
this.__name = name;
|
|
92
|
-
this.__type = type;
|
|
93
|
-
}
|
|
94
|
-
static getType() {
|
|
95
|
-
return 'doc';
|
|
96
|
-
}
|
|
97
|
-
static clone(node) {
|
|
98
|
-
return new DocNode(node.__src, node.__name, node.__type, node.__key);
|
|
99
|
-
}
|
|
100
|
-
createDOM(config) {
|
|
101
|
-
const div = document.createElement('div');
|
|
102
|
-
const theme = config.theme;
|
|
103
|
-
const className = theme.document;
|
|
104
|
-
if (className !== undefined) {
|
|
105
|
-
div.className = className;
|
|
106
|
-
}
|
|
107
|
-
return div;
|
|
108
|
-
}
|
|
109
|
-
updateDOM() {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
static importDOM() {
|
|
113
|
-
return {
|
|
114
|
-
div: (node) => {
|
|
115
|
-
if (node.hasAttribute('src')) {
|
|
116
|
-
return {
|
|
117
|
-
conversion: convertDocElement,
|
|
118
|
-
priority: 1
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
exportDOM() {
|
|
126
|
-
const element = document.createElement('div');
|
|
127
|
-
element.setAttribute('src', this.__src);
|
|
128
|
-
element.setAttribute('alt', this.__name);
|
|
129
|
-
element.className = 'SCEditor-document';
|
|
130
|
-
const link = document.createElement('a');
|
|
131
|
-
link.href = this.__src;
|
|
132
|
-
link.target = '_blank';
|
|
133
|
-
link.rel = 'noopener noreferrer';
|
|
134
|
-
link.title = this.__name;
|
|
135
|
-
link.style.textDecoration = 'none';
|
|
136
|
-
// Add an Image
|
|
137
|
-
const img = document.createElement('img');
|
|
138
|
-
img.src = documentPlaceholder;
|
|
139
|
-
img.alt = this.__name;
|
|
140
|
-
img.style.marginRight = '8px';
|
|
141
|
-
// Add a Typography-like Text Node
|
|
142
|
-
const text = document.createElement('span');
|
|
143
|
-
text.textContent = this.__name;
|
|
144
|
-
// Append elements
|
|
145
|
-
link.append(img, text);
|
|
146
|
-
element.appendChild(link);
|
|
147
|
-
return { element };
|
|
148
|
-
}
|
|
149
|
-
decorate() {
|
|
150
|
-
return _jsx(DocComponent, { src: this.__src, name: this.__name, nodeKey: this.getKey() });
|
|
151
|
-
}
|
|
152
|
-
static importJSON(serializedNode) {
|
|
153
|
-
const { src, name, type } = serializedNode;
|
|
154
|
-
const node = $createDocNode({
|
|
155
|
-
src,
|
|
156
|
-
name,
|
|
157
|
-
type
|
|
158
|
-
});
|
|
159
|
-
return node;
|
|
160
|
-
}
|
|
161
|
-
exportJSON() {
|
|
162
|
-
return {
|
|
163
|
-
src: this.__src,
|
|
164
|
-
name: this.__name,
|
|
165
|
-
type: 'doc',
|
|
166
|
-
version: 1
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
export function $createDocNode({ src, name, type }) {
|
|
171
|
-
return new DocNode(src, name, type);
|
|
172
|
-
}
|
|
173
|
-
export function $isDocNode(node) {
|
|
174
|
-
return node.getType() === 'doc';
|
|
175
|
-
}
|