@team-monolith/cds 1.46.2 → 1.47.0
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/dist/patterns/LexicalEditor/LexicalCustomConfigContext.d.ts +0 -1
- package/dist/patterns/LexicalEditor/LexicalCustomConfigContext.js +0 -1
- package/dist/patterns/LexicalEditor/LexicalEditor.d.ts +0 -2
- package/dist/patterns/LexicalEditor/LexicalEditor.js +6 -2
- package/dist/patterns/LexicalEditor/Plugins.js +2 -1
- package/dist/patterns/LexicalEditor/nodes/LayoutContainerNode.d.ts +30 -0
- package/dist/patterns/LexicalEditor/nodes/LayoutContainerNode.js +88 -0
- package/dist/patterns/LexicalEditor/nodes/LayoutItemNode.d.ts +22 -0
- package/dist/patterns/LexicalEditor/nodes/LayoutItemNode.js +45 -0
- package/dist/patterns/LexicalEditor/nodes/ProblemInputNode/InputComponent.js +3 -3
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectBox/SelectBoxView.d.ts +0 -1
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectBox/SelectBoxView.js +5 -4
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectComponent.js +30 -30
- package/dist/patterns/LexicalEditor/plugins/ComponentPickerMenuPlugin/ComponentPickerMenuPlugin.js +11 -1
- package/dist/patterns/LexicalEditor/plugins/LayoutPlugin/InsertLayoutDialog.d.ts +17 -0
- package/dist/patterns/LexicalEditor/plugins/LayoutPlugin/InsertLayoutDialog.js +21 -0
- package/dist/patterns/LexicalEditor/plugins/LayoutPlugin/LayoutPlugin.d.ts +14 -0
- package/dist/patterns/LexicalEditor/plugins/LayoutPlugin/LayoutPlugin.js +125 -0
- package/package.json +1 -1
|
@@ -12,8 +12,6 @@ export interface LexicalEditorProps {
|
|
|
12
12
|
/** freeze. 문제 블록을 수정하지 못하도록 함
|
|
13
13
|
*/
|
|
14
14
|
freezeProblemNode?: boolean;
|
|
15
|
-
/** 퀴즈 정답이 공개되는지 여부. false가 default입니다. 공개하고자 하는곳에서 true로 설정해야 합니다. */
|
|
16
|
-
showQuizSolution?: boolean;
|
|
17
15
|
/** 퀴즈 노드가 허용되는지 여부. false가 디폴트이고, 전달하지 않아도 로컬스토리지 devMode로도 노출시킬 수 있습니다. */
|
|
18
16
|
isQuizEnabled?: boolean;
|
|
19
17
|
/** 외부에서 플러그인을 주입하는 경우 활용함 */
|
|
@@ -13,6 +13,8 @@ import Plugins from "./Plugins";
|
|
|
13
13
|
import { ColoredQuoteNode, ProblemInputNode } from "./nodes";
|
|
14
14
|
import { LexicalCustomConfigContext } from "./LexicalCustomConfigContext";
|
|
15
15
|
import { ProblemSelectNode } from "./nodes/ProblemSelectNode";
|
|
16
|
+
import { LayoutContainerNode } from "./nodes/LayoutContainerNode";
|
|
17
|
+
import { LayoutItemNode } from "./nodes/LayoutItemNode";
|
|
16
18
|
function validateValue(value) {
|
|
17
19
|
var _a, _b;
|
|
18
20
|
if (value && typeof value !== "object") {
|
|
@@ -30,7 +32,7 @@ function validateValue(value) {
|
|
|
30
32
|
return true;
|
|
31
33
|
}
|
|
32
34
|
export function LexicalEditor(props) {
|
|
33
|
-
const { className, contentEditableClassName, value, onChange, editable = true,
|
|
35
|
+
const { className, contentEditableClassName, value, onChange, editable = true, freezeProblemNode, isQuizEnabled = false, children, } = props;
|
|
34
36
|
const theme = useTheme();
|
|
35
37
|
const initialConfig = {
|
|
36
38
|
namespace: "CodleLexicalEditor",
|
|
@@ -52,6 +54,8 @@ export function LexicalEditor(props) {
|
|
|
52
54
|
ImageNode,
|
|
53
55
|
HorizontalRuleNode,
|
|
54
56
|
ColoredQuoteNode,
|
|
57
|
+
LayoutContainerNode,
|
|
58
|
+
LayoutItemNode,
|
|
55
59
|
{
|
|
56
60
|
replace: QuoteNode,
|
|
57
61
|
with: (_node) => {
|
|
@@ -63,5 +67,5 @@ export function LexicalEditor(props) {
|
|
|
63
67
|
editorState: validateValue(value) ? JSON.stringify(value) : undefined,
|
|
64
68
|
editable: editable,
|
|
65
69
|
};
|
|
66
|
-
return (_jsx(LexicalCustomConfigContext.Provider, Object.assign({ value: { freezeProblemNode
|
|
70
|
+
return (_jsx(LexicalCustomConfigContext.Provider, Object.assign({ value: { freezeProblemNode: freezeProblemNode !== null && freezeProblemNode !== void 0 ? freezeProblemNode : false } }, { children: _jsxs(LexicalComposer, Object.assign({ initialConfig: initialConfig }, { children: [_jsx(Plugins, { className: className, contentEditableClassName: contentEditableClassName, onChange: onChange, isQuizEnabled: isQuizEnabled }), _jsx(_Fragment, { children: children })] })) })));
|
|
67
71
|
}
|
|
@@ -29,6 +29,7 @@ import ListMaxIndentLevelPlugin from "./plugins/ListMaxIndentLevelPlugin";
|
|
|
29
29
|
import styled from "@emotion/styled";
|
|
30
30
|
import ProblemInputPlugin from "./plugins/ProblemInputPlugin";
|
|
31
31
|
import ProblemSelectPlugin from "./plugins/ProblemSelectPlugin";
|
|
32
|
+
import { LayoutPlugin } from "./plugins/LayoutPlugin/LayoutPlugin";
|
|
32
33
|
export default function Plugins(props) {
|
|
33
34
|
const { className, contentEditableClassName, onChange, isQuizEnabled } = props;
|
|
34
35
|
const isEditable = useLexicalEditable();
|
|
@@ -43,7 +44,7 @@ export default function Plugins(props) {
|
|
|
43
44
|
onChange === null || onChange === void 0 ? void 0 : onChange(editorState.toJSON());
|
|
44
45
|
},
|
|
45
46
|
// ignore 하지 않으면 Form에서 수정하지 않았는데 Dirty로 처리됨.
|
|
46
|
-
ignoreSelectionChange: true }), _jsx(AutoFocusPlugin, {}), isEditable && (_jsxs(_Fragment, { children: [_jsx(TabIndentationPlugin, {}), _jsx(ComponentPickerMenuPlugin, { isQuizEnabled: isQuizEnabled }), _jsx(MarkdownShortcutPlugin, { transformers: CODLE_TRANSFORMERS }), _jsx(HistoryPlugin, {})] })), floatingAnchorElem && isEditable && (_jsxs(_Fragment, { children: [_jsx(ComponentAdderPlugin, { anchorElem: floatingAnchorElem, isQuizEnabled: isQuizEnabled }), _jsx(FloatingTextFormatToolbarPlugin, { anchorElem: floatingAnchorElem }), _jsx(FloatingLinkEditorPlugin, { anchorElem: floatingAnchorElem, isLinkEditMode: isLinkEditMode, setIsLinkEditMode: setIsLinkEditMode })] })), !isEditable && _jsx(LexicalClickableLinkPlugin, {}), _jsx(ListPlugin, {}), _jsx(HorizontalRulePlugin, {}), _jsx(ImagesPlugin, {}), _jsx(TablePlugin, {}), _jsx(LinkPlugin, {}), _jsx(ListMaxIndentLevelPlugin, { maxDepth: 5 }), _jsx(ProblemInputPlugin, {}), _jsx(ProblemSelectPlugin, {})] }));
|
|
47
|
+
ignoreSelectionChange: true }), _jsx(AutoFocusPlugin, {}), isEditable && (_jsxs(_Fragment, { children: [_jsx(TabIndentationPlugin, {}), _jsx(ComponentPickerMenuPlugin, { isQuizEnabled: isQuizEnabled }), _jsx(MarkdownShortcutPlugin, { transformers: CODLE_TRANSFORMERS }), _jsx(HistoryPlugin, {})] })), floatingAnchorElem && isEditable && (_jsxs(_Fragment, { children: [_jsx(ComponentAdderPlugin, { anchorElem: floatingAnchorElem, isQuizEnabled: isQuizEnabled }), _jsx(FloatingTextFormatToolbarPlugin, { anchorElem: floatingAnchorElem }), _jsx(FloatingLinkEditorPlugin, { anchorElem: floatingAnchorElem, isLinkEditMode: isLinkEditMode, setIsLinkEditMode: setIsLinkEditMode })] })), !isEditable && _jsx(LexicalClickableLinkPlugin, {}), _jsx(ListPlugin, {}), _jsx(HorizontalRulePlugin, {}), _jsx(ImagesPlugin, {}), _jsx(TablePlugin, {}), _jsx(LinkPlugin, {}), _jsx(ListMaxIndentLevelPlugin, { maxDepth: 5 }), _jsx(ProblemInputPlugin, {}), _jsx(ProblemSelectPlugin, {}), _jsx(LayoutPlugin, {})] }));
|
|
47
48
|
}
|
|
48
49
|
const ScrollArea = styled.div `
|
|
49
50
|
min-height: 150px;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalNode, NodeKey, SerializedElementNode, Spread } from "lexical";
|
|
9
|
+
import { ElementNode } from "lexical";
|
|
10
|
+
export type SerializedLayoutContainerNode = Spread<{
|
|
11
|
+
templateColumns: string;
|
|
12
|
+
}, SerializedElementNode>;
|
|
13
|
+
export declare class LayoutContainerNode extends ElementNode {
|
|
14
|
+
__templateColumns: string;
|
|
15
|
+
constructor(templateColumns: string, key?: NodeKey);
|
|
16
|
+
static getType(): string;
|
|
17
|
+
static clone(node: LayoutContainerNode): LayoutContainerNode;
|
|
18
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
19
|
+
exportDOM(): DOMExportOutput;
|
|
20
|
+
updateDOM(prevNode: LayoutContainerNode, dom: HTMLElement): boolean;
|
|
21
|
+
static importDOM(): DOMConversionMap | null;
|
|
22
|
+
static importJSON(json: SerializedLayoutContainerNode): LayoutContainerNode;
|
|
23
|
+
isShadowRoot(): boolean;
|
|
24
|
+
canBeEmpty(): boolean;
|
|
25
|
+
exportJSON(): SerializedLayoutContainerNode;
|
|
26
|
+
getTemplateColumns(): string;
|
|
27
|
+
setTemplateColumns(templateColumns: string): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function $createLayoutContainerNode(templateColumns: string): LayoutContainerNode;
|
|
30
|
+
export declare function $isLayoutContainerNode(node: LexicalNode | null | undefined): node is LayoutContainerNode;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { addClassNamesToElement } from "@lexical/utils";
|
|
9
|
+
import { ElementNode } from "lexical";
|
|
10
|
+
function $convertLayoutContainerElement(domNode) {
|
|
11
|
+
const styleAttributes = window.getComputedStyle(domNode);
|
|
12
|
+
const templateColumns = styleAttributes.getPropertyValue("grid-template-columns");
|
|
13
|
+
if (templateColumns) {
|
|
14
|
+
const node = $createLayoutContainerNode(templateColumns);
|
|
15
|
+
return { node };
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
export class LayoutContainerNode extends ElementNode {
|
|
20
|
+
constructor(templateColumns, key) {
|
|
21
|
+
super(key);
|
|
22
|
+
this.__templateColumns = templateColumns;
|
|
23
|
+
}
|
|
24
|
+
static getType() {
|
|
25
|
+
return "layout-container";
|
|
26
|
+
}
|
|
27
|
+
static clone(node) {
|
|
28
|
+
return new LayoutContainerNode(node.__templateColumns, node.__key);
|
|
29
|
+
}
|
|
30
|
+
createDOM(config) {
|
|
31
|
+
const dom = document.createElement("div");
|
|
32
|
+
dom.style.display = "grid";
|
|
33
|
+
dom.style.gridTemplateColumns = this.__templateColumns;
|
|
34
|
+
if (typeof config.theme.layoutContainer === "string") {
|
|
35
|
+
addClassNamesToElement(dom, config.theme.layoutContainer);
|
|
36
|
+
}
|
|
37
|
+
return dom;
|
|
38
|
+
}
|
|
39
|
+
exportDOM() {
|
|
40
|
+
const element = document.createElement("div");
|
|
41
|
+
element.style.gridTemplateColumns = this.__templateColumns;
|
|
42
|
+
element.setAttribute("data-lexical-layout-container", "true");
|
|
43
|
+
return { element };
|
|
44
|
+
}
|
|
45
|
+
updateDOM(prevNode, dom) {
|
|
46
|
+
if (prevNode.__templateColumns !== this.__templateColumns) {
|
|
47
|
+
dom.style.gridTemplateColumns = this.__templateColumns;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
static importDOM() {
|
|
52
|
+
return {
|
|
53
|
+
div: (domNode) => {
|
|
54
|
+
if (!domNode.hasAttribute("data-lexical-layout-container")) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
conversion: $convertLayoutContainerElement,
|
|
59
|
+
priority: 2,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
static importJSON(json) {
|
|
65
|
+
return $createLayoutContainerNode(json.templateColumns);
|
|
66
|
+
}
|
|
67
|
+
isShadowRoot() {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
canBeEmpty() {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
exportJSON() {
|
|
74
|
+
return Object.assign(Object.assign({}, super.exportJSON()), { templateColumns: this.__templateColumns, type: "layout-container", version: 1 });
|
|
75
|
+
}
|
|
76
|
+
getTemplateColumns() {
|
|
77
|
+
return this.getLatest().__templateColumns;
|
|
78
|
+
}
|
|
79
|
+
setTemplateColumns(templateColumns) {
|
|
80
|
+
this.getWritable().__templateColumns = templateColumns;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function $createLayoutContainerNode(templateColumns) {
|
|
84
|
+
return new LayoutContainerNode(templateColumns);
|
|
85
|
+
}
|
|
86
|
+
export function $isLayoutContainerNode(node) {
|
|
87
|
+
return node instanceof LayoutContainerNode;
|
|
88
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { DOMConversionMap, EditorConfig, LexicalNode, SerializedElementNode } from "lexical";
|
|
9
|
+
import { ElementNode } from "lexical";
|
|
10
|
+
export type SerializedLayoutItemNode = SerializedElementNode;
|
|
11
|
+
export declare class LayoutItemNode extends ElementNode {
|
|
12
|
+
static getType(): string;
|
|
13
|
+
static clone(node: LayoutItemNode): LayoutItemNode;
|
|
14
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
15
|
+
updateDOM(): boolean;
|
|
16
|
+
static importDOM(): DOMConversionMap | null;
|
|
17
|
+
static importJSON(): LayoutItemNode;
|
|
18
|
+
isShadowRoot(): boolean;
|
|
19
|
+
exportJSON(): SerializedLayoutItemNode;
|
|
20
|
+
}
|
|
21
|
+
export declare function $createLayoutItemNode(): LayoutItemNode;
|
|
22
|
+
export declare function $isLayoutItemNode(node: LexicalNode | null | undefined): node is LayoutItemNode;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { addClassNamesToElement } from "@lexical/utils";
|
|
9
|
+
import { ElementNode } from "lexical";
|
|
10
|
+
export class LayoutItemNode extends ElementNode {
|
|
11
|
+
static getType() {
|
|
12
|
+
return "layout-item";
|
|
13
|
+
}
|
|
14
|
+
static clone(node) {
|
|
15
|
+
return new LayoutItemNode(node.__key);
|
|
16
|
+
}
|
|
17
|
+
createDOM(config) {
|
|
18
|
+
const dom = document.createElement("div");
|
|
19
|
+
if (typeof config.theme.layoutItem === "string") {
|
|
20
|
+
addClassNamesToElement(dom, config.theme.layoutItem);
|
|
21
|
+
}
|
|
22
|
+
return dom;
|
|
23
|
+
}
|
|
24
|
+
updateDOM() {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
static importDOM() {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
static importJSON() {
|
|
31
|
+
return $createLayoutItemNode();
|
|
32
|
+
}
|
|
33
|
+
isShadowRoot() {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
exportJSON() {
|
|
37
|
+
return Object.assign(Object.assign({}, super.exportJSON()), { type: "layout-item", version: 1 });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function $createLayoutItemNode() {
|
|
41
|
+
return new LayoutItemNode();
|
|
42
|
+
}
|
|
43
|
+
export function $isLayoutItemNode(node) {
|
|
44
|
+
return node instanceof LayoutItemNode;
|
|
45
|
+
}
|
|
@@ -35,7 +35,7 @@ export function InputComponent(props) {
|
|
|
35
35
|
// SoT를 내부 State로 관리하고 EditorState를 따로 설정.
|
|
36
36
|
// 문제를 더 파악하고 추후 개선 필요.
|
|
37
37
|
const [answerInput, setAnswerInput] = useState(answer);
|
|
38
|
-
const
|
|
38
|
+
const lexicalCustomConfig = useContext(LexicalCustomConfigContext);
|
|
39
39
|
// "** ***" 같은 형태입니다.
|
|
40
40
|
const answerFormat = solutions[0].value;
|
|
41
41
|
const handleChange = (value) => {
|
|
@@ -51,9 +51,9 @@ export function InputComponent(props) {
|
|
|
51
51
|
// 학생 view
|
|
52
52
|
if (!isEditable) {
|
|
53
53
|
if (showCharacterNumber) {
|
|
54
|
-
return (_jsx(SegmentedInput, { readOnly: freezeProblemNode, isCorrect: isCorrect, answerFormat: answerFormat, placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: handleChange }));
|
|
54
|
+
return (_jsx(SegmentedInput, { readOnly: lexicalCustomConfig.freezeProblemNode, isCorrect: isCorrect, answerFormat: answerFormat, placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: handleChange }));
|
|
55
55
|
}
|
|
56
|
-
return (_jsx(TextInput, { readOnly: freezeProblemNode, isCorrect: isCorrect, size: "small", color: "default", placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: (e) => {
|
|
56
|
+
return (_jsx(TextInput, { readOnly: lexicalCustomConfig.freezeProblemNode, isCorrect: isCorrect, size: "small", color: "default", placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: (e) => {
|
|
57
57
|
handleChange(e.target.value);
|
|
58
58
|
}, fullWidth: true }));
|
|
59
59
|
}
|
|
@@ -19,7 +19,7 @@ const TYPE_TO_INDEX_ICON = (type) => ({
|
|
|
19
19
|
` })),
|
|
20
20
|
})[type];
|
|
21
21
|
export function SelectBoxView(props) {
|
|
22
|
-
const { index, isSelected,
|
|
22
|
+
const { index, isSelected, isAnswer, image, text, onClick } = props;
|
|
23
23
|
const selectBoxType = isSelected
|
|
24
24
|
? isAnswer === undefined
|
|
25
25
|
? "primary"
|
|
@@ -29,10 +29,11 @@ export function SelectBoxView(props) {
|
|
|
29
29
|
: undefined;
|
|
30
30
|
return (_jsx(SelectBoxComponent, { css: css `
|
|
31
31
|
width: 100%;
|
|
32
|
-
`, type: selectBoxType, index: selectBoxType ? TYPE_TO_INDEX_ICON(selectBoxType) : index, image: image, text: text,
|
|
32
|
+
`, type: selectBoxType, index: selectBoxType ? TYPE_TO_INDEX_ICON(selectBoxType) : index, image: image, text: text,
|
|
33
|
+
// isAnswer가 존재하면 채점 후의 상태이므로 unclickable을 위해 onClick을 전달하지 않음
|
|
34
|
+
onClick: isAnswer === undefined ? onClick : undefined,
|
|
33
35
|
// 선택되지 않았으나 정답일 때 정답 태그를 표시
|
|
34
|
-
endIcon:
|
|
35
|
-
isAnswer &&
|
|
36
|
+
endIcon: isAnswer &&
|
|
36
37
|
!isSelected && (_jsx(Tag, { label: "\uC815\uB2F5", icon: _jsx(CheckboxCircleFillIcon, {}), color: "green", css: css `
|
|
37
38
|
span {
|
|
38
39
|
font-weight: 700;
|
|
@@ -29,40 +29,40 @@ export function SelectComponent(props) {
|
|
|
29
29
|
const [editor] = useLexicalComposerContext();
|
|
30
30
|
const [settingOpen, setSettingOpen] = useState(false);
|
|
31
31
|
const isEditable = useLexicalEditable();
|
|
32
|
-
const
|
|
33
|
-
// view
|
|
32
|
+
const lexicalCustomConfig = useContext(LexicalCustomConfigContext);
|
|
33
|
+
// 학생 view
|
|
34
34
|
if (!isEditable) {
|
|
35
35
|
return (_jsxs(_Fragment, { children: [hasMultipleAnswers && (_jsxs(Alert, { children: [_jsx(AlarmWarningFillIcon, { css: css `
|
|
36
36
|
width: 14px;
|
|
37
37
|
height: 14px;
|
|
38
|
-
` }), "\uC9C8\uBB38\uC5D0 \uD574\uB2F9\uD558\uB294 \uB2F5\uC744 \uBAA8\uB450 \uACE0\uB974\uB294 \uBB38\uC81C\uC785\uB2C8\uB2E4."] })), selections.map((selection, index) => (_jsx(SelectBoxView, { index: index + 1,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
38
|
+
` }), "\uC9C8\uBB38\uC5D0 \uD574\uB2F9\uD558\uB294 \uB2F5\uC744 \uBAA8\uB450 \uACE0\uB974\uB294 \uBB38\uC81C\uC785\uB2C8\uB2E4."] })), selections.map((selection, index) => (_jsx(SelectBoxView, { index: index + 1, isAnswer: selection.isAnswer, isSelected: selected.includes(selection.value), image: selection.show.image, text: selection.show.text, onClick: () => {
|
|
39
|
+
if (lexicalCustomConfig.freezeProblemNode)
|
|
40
|
+
return;
|
|
41
|
+
const isSelected = selected.includes(selection.value);
|
|
42
|
+
if (isSelected) {
|
|
43
|
+
editor.update(() => {
|
|
44
|
+
const node = $getNodeByKey(nodeKey);
|
|
45
|
+
if (!$isProblemSelectNode(node)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
node.setSelected(selected.filter((v) => v !== selection.value));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
editor.update(() => {
|
|
53
|
+
const node = $getNodeByKey(nodeKey);
|
|
54
|
+
if (!$isProblemSelectNode(node)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (hasMultipleAnswers) {
|
|
58
|
+
node.setSelected([...selected, selection.value]);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
node.setSelected([selection.value]);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
} }, index)))] }));
|
|
66
66
|
}
|
|
67
67
|
// 교사 edit view
|
|
68
68
|
return (_jsxs(_Fragment, { children: [_jsxs("div", Object.assign({ css: css `
|
package/dist/patterns/LexicalEditor/plugins/ComponentPickerMenuPlugin/ComponentPickerMenuPlugin.js
CHANGED
|
@@ -26,6 +26,7 @@ import { ZINDEX } from "../../../../utils/zIndex";
|
|
|
26
26
|
import { css, useTheme } from "@emotion/react";
|
|
27
27
|
import { INSERT_PROBLEM_INPUT_COMMAND } from "../ProblemInputPlugin";
|
|
28
28
|
import { INSERT_PROBLEM_SELECT_COMMAND } from "../ProblemSelectPlugin";
|
|
29
|
+
import { INSERT_LAYOUT_COMMAND } from "../LayoutPlugin/LayoutPlugin";
|
|
29
30
|
// import useModal from "../../hooks/useModal";
|
|
30
31
|
// import catTypingGif from "../../images/cat-typing.gif";
|
|
31
32
|
// import { INSERT_IMAGE_COMMAND, InsertImageDialog } from "../ImagesPlugin";
|
|
@@ -196,8 +197,17 @@ export function getBaseOptions(props) {
|
|
|
196
197
|
onSelect: () => setImageOpen(true),
|
|
197
198
|
}),
|
|
198
199
|
];
|
|
200
|
+
// 로컬스토리지 devMode가 true이면 칼럼 나누기 컨텍스트 메뉴를 추가합니다.
|
|
201
|
+
const isDevMode = localStorage.getItem("devMode") === "true";
|
|
202
|
+
if (isDevMode) {
|
|
203
|
+
baseOptions.push(new ComponentPickerOption("칼럼 나누기", {
|
|
204
|
+
icon: _jsx("i", { className: "icon columns" }),
|
|
205
|
+
keywords: ["columns", "layout", "grid"],
|
|
206
|
+
onSelect: () => editor.dispatchCommand(INSERT_LAYOUT_COMMAND, "1fr 1fr"),
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
199
209
|
// isQuizEnabled이거나 로컬스토리지 devMode가 true이면 퀴즈 컨텍스트 메뉴를 추가합니다.
|
|
200
|
-
if (isQuizEnabled ||
|
|
210
|
+
if (isQuizEnabled || isDevMode) {
|
|
201
211
|
return [...getQuizContextOptions(editor, theme), ...baseOptions];
|
|
202
212
|
}
|
|
203
213
|
return baseOptions;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import { LexicalEditor } from "lexical";
|
|
10
|
+
export declare const LAYOUTS: {
|
|
11
|
+
label: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[];
|
|
14
|
+
export default function InsertLayoutDialog({ activeEditor, onClose, }: {
|
|
15
|
+
activeEditor: LexicalEditor;
|
|
16
|
+
onClose: () => void;
|
|
17
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { INSERT_LAYOUT_COMMAND } from "./LayoutPlugin";
|
|
4
|
+
import Button from "../../../../components/Button";
|
|
5
|
+
export const LAYOUTS = [
|
|
6
|
+
{ label: "2 columns (equal width)", value: "1fr 1fr" },
|
|
7
|
+
{ label: "2 columns (25% - 75%)", value: "1fr 3fr" },
|
|
8
|
+
{ label: "3 columns (equal width)", value: "1fr 1fr 1fr" },
|
|
9
|
+
{ label: "3 columns (25% - 50% - 25%)", value: "1fr 2fr 1fr" },
|
|
10
|
+
{ label: "4 columns (equal width)", value: "1fr 1fr 1fr 1fr" },
|
|
11
|
+
];
|
|
12
|
+
export default function InsertLayoutDialog({ activeEditor, onClose, }) {
|
|
13
|
+
var _a;
|
|
14
|
+
const [layout, setLayout] = useState(LAYOUTS[0].value);
|
|
15
|
+
const buttonLabel = (_a = LAYOUTS.find((item) => item.value === layout)) === null || _a === void 0 ? void 0 : _a.label;
|
|
16
|
+
const onClick = () => {
|
|
17
|
+
activeEditor.dispatchCommand(INSERT_LAYOUT_COMMAND, LAYOUTS[0].value);
|
|
18
|
+
onClose();
|
|
19
|
+
};
|
|
20
|
+
return (_jsx(_Fragment, { children: _jsx(Button, Object.assign({ onClick: onClick, color: "grey", size: "small", label: undefined }, { children: "Insert" })) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { LexicalCommand, NodeKey } from "lexical";
|
|
9
|
+
export declare const INSERT_LAYOUT_COMMAND: LexicalCommand<string>;
|
|
10
|
+
export declare const UPDATE_LAYOUT_COMMAND: LexicalCommand<{
|
|
11
|
+
template: string;
|
|
12
|
+
nodeKey: NodeKey;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function LayoutPlugin(): null;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
9
|
+
import { $findMatchingParent, $insertNodeToNearestRoot, mergeRegister, } from "@lexical/utils";
|
|
10
|
+
import { $createParagraphNode, $getNodeByKey, $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, createCommand, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, } from "lexical";
|
|
11
|
+
import { useEffect } from "react";
|
|
12
|
+
import { $createLayoutContainerNode, $isLayoutContainerNode, LayoutContainerNode, } from "../../nodes/LayoutContainerNode";
|
|
13
|
+
import { $createLayoutItemNode, $isLayoutItemNode, LayoutItemNode, } from "../../nodes/LayoutItemNode";
|
|
14
|
+
export const INSERT_LAYOUT_COMMAND = createCommand();
|
|
15
|
+
export const UPDATE_LAYOUT_COMMAND = createCommand();
|
|
16
|
+
export function LayoutPlugin() {
|
|
17
|
+
const [editor] = useLexicalComposerContext();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!editor.hasNodes([LayoutContainerNode, LayoutItemNode])) {
|
|
20
|
+
throw new Error("LayoutPlugin: LayoutContainerNode, or LayoutItemNode not registered on editor");
|
|
21
|
+
}
|
|
22
|
+
const $onEscape = (before) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const selection = $getSelection();
|
|
25
|
+
if ($isRangeSelection(selection) &&
|
|
26
|
+
selection.isCollapsed() &&
|
|
27
|
+
selection.anchor.offset === 0) {
|
|
28
|
+
const container = $findMatchingParent(selection.anchor.getNode(), $isLayoutContainerNode);
|
|
29
|
+
if ($isLayoutContainerNode(container)) {
|
|
30
|
+
const parent = container.getParent();
|
|
31
|
+
const child = parent &&
|
|
32
|
+
(before
|
|
33
|
+
? parent.getFirstChild()
|
|
34
|
+
: parent === null || parent === void 0 ? void 0 : parent.getLastChild());
|
|
35
|
+
const descendant = before
|
|
36
|
+
? (_a = container.getFirstDescendant()) === null || _a === void 0 ? void 0 : _a.getKey()
|
|
37
|
+
: (_b = container.getLastDescendant()) === null || _b === void 0 ? void 0 : _b.getKey();
|
|
38
|
+
if (parent !== null &&
|
|
39
|
+
child === container &&
|
|
40
|
+
selection.anchor.key === descendant) {
|
|
41
|
+
if (before) {
|
|
42
|
+
container.insertBefore($createParagraphNode());
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
container.insertAfter($createParagraphNode());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
return mergeRegister(
|
|
53
|
+
// When layout is the last child pressing down/right arrow will insert paragraph
|
|
54
|
+
// below it to allow adding more content. It's similar what $insertBlockNode
|
|
55
|
+
// (mainly for decorators), except it'll always be possible to continue adding
|
|
56
|
+
// new content even if trailing paragraph is accidentally deleted
|
|
57
|
+
editor.registerCommand(KEY_ARROW_DOWN_COMMAND, () => $onEscape(false), COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, () => $onEscape(false), COMMAND_PRIORITY_LOW),
|
|
58
|
+
// When layout is the first child pressing up/left arrow will insert paragraph
|
|
59
|
+
// above it to allow adding more content. It's similar what $insertBlockNode
|
|
60
|
+
// (mainly for decorators), except it'll always be possible to continue adding
|
|
61
|
+
// new content even if leading paragraph is accidentally deleted
|
|
62
|
+
editor.registerCommand(KEY_ARROW_UP_COMMAND, () => $onEscape(true), COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_LEFT_COMMAND, () => $onEscape(true), COMMAND_PRIORITY_LOW), editor.registerCommand(INSERT_LAYOUT_COMMAND, (template) => {
|
|
63
|
+
editor.update(() => {
|
|
64
|
+
const container = $createLayoutContainerNode(template);
|
|
65
|
+
const itemsCount = getItemsCountFromTemplate(template);
|
|
66
|
+
for (let i = 0; i < itemsCount; i++) {
|
|
67
|
+
container.append($createLayoutItemNode().append($createParagraphNode()));
|
|
68
|
+
}
|
|
69
|
+
$insertNodeToNearestRoot(container);
|
|
70
|
+
container.selectStart();
|
|
71
|
+
});
|
|
72
|
+
return true;
|
|
73
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(UPDATE_LAYOUT_COMMAND, ({ template, nodeKey }) => {
|
|
74
|
+
editor.update(() => {
|
|
75
|
+
const container = $getNodeByKey(nodeKey);
|
|
76
|
+
if (!$isLayoutContainerNode(container)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const itemsCount = getItemsCountFromTemplate(template);
|
|
80
|
+
const prevItemsCount = getItemsCountFromTemplate(container.getTemplateColumns());
|
|
81
|
+
// Add or remove extra columns if new template does not match existing one
|
|
82
|
+
if (itemsCount > prevItemsCount) {
|
|
83
|
+
for (let i = prevItemsCount; i < itemsCount; i++) {
|
|
84
|
+
container.append($createLayoutItemNode().append($createParagraphNode()));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (itemsCount < prevItemsCount) {
|
|
88
|
+
for (let i = prevItemsCount - 1; i >= itemsCount; i--) {
|
|
89
|
+
const layoutItem = container.getChildAtIndex(i);
|
|
90
|
+
if ($isLayoutItemNode(layoutItem)) {
|
|
91
|
+
layoutItem.remove();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
container.setTemplateColumns(template);
|
|
96
|
+
});
|
|
97
|
+
return true;
|
|
98
|
+
}, COMMAND_PRIORITY_EDITOR),
|
|
99
|
+
// Structure enforcing transformers for each node type. In case nesting structure is not
|
|
100
|
+
// "Container > Item" it'll unwrap nodes and convert it back
|
|
101
|
+
// to regular content.
|
|
102
|
+
editor.registerNodeTransform(LayoutItemNode, (node) => {
|
|
103
|
+
const parent = node.getParent();
|
|
104
|
+
if (!$isLayoutContainerNode(parent)) {
|
|
105
|
+
const children = node.getChildren();
|
|
106
|
+
for (const child of children) {
|
|
107
|
+
node.insertBefore(child);
|
|
108
|
+
}
|
|
109
|
+
node.remove();
|
|
110
|
+
}
|
|
111
|
+
}), editor.registerNodeTransform(LayoutContainerNode, (node) => {
|
|
112
|
+
const children = node.getChildren();
|
|
113
|
+
if (!children.every($isLayoutItemNode)) {
|
|
114
|
+
for (const child of children) {
|
|
115
|
+
node.insertBefore(child);
|
|
116
|
+
}
|
|
117
|
+
node.remove();
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
}, [editor]);
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
function getItemsCountFromTemplate(template) {
|
|
124
|
+
return template.trim().split(/\s+/).length;
|
|
125
|
+
}
|