@uipath/apollo-wind 2.23.0 → 2.24.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/components/ui/index.cjs +96 -86
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/components/ui/prompt-editor/components/EditorToolbar.cjs +156 -0
- package/dist/components/ui/prompt-editor/components/EditorToolbar.d.ts +9 -0
- package/dist/components/ui/prompt-editor/components/EditorToolbar.js +122 -0
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.cjs +205 -0
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.d.ts +14 -0
- package/dist/components/ui/prompt-editor/components/MarkdownPreview.js +161 -0
- package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.cjs +194 -0
- package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.d.ts +28 -0
- package/dist/components/ui/prompt-editor/components/PromptEditorAutocompleteMenu.js +160 -0
- package/dist/components/ui/prompt-editor/components/TokenPill.cjs +119 -0
- package/dist/components/ui/prompt-editor/components/TokenPill.d.ts +15 -0
- package/dist/components/ui/prompt-editor/components/TokenPill.js +85 -0
- package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.cjs +138 -0
- package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.d.ts +13 -0
- package/dist/components/ui/prompt-editor/components/TokenPillWithTooltip.js +104 -0
- package/dist/components/ui/prompt-editor/components/token-icon-markup.cjs +138 -0
- package/dist/components/ui/prompt-editor/components/token-icon-markup.d.ts +16 -0
- package/dist/components/ui/prompt-editor/components/token-icon-markup.js +104 -0
- package/dist/components/ui/prompt-editor/index.cjs +40 -0
- package/dist/components/ui/prompt-editor/index.d.ts +4 -0
- package/dist/components/ui/prompt-editor/index.js +3 -0
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.cjs +145 -0
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.d.ts +30 -0
- package/dist/components/ui/prompt-editor/nodes/InputTokenNode.js +105 -0
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.cjs +145 -0
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.d.ts +30 -0
- package/dist/components/ui/prompt-editor/nodes/OutputTokenNode.js +105 -0
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.cjs +145 -0
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.d.ts +30 -0
- package/dist/components/ui/prompt-editor/nodes/ResourceTokenNode.js +105 -0
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.cjs +145 -0
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.d.ts +30 -0
- package/dist/components/ui/prompt-editor/nodes/StateTokenNode.js +105 -0
- package/dist/components/ui/prompt-editor/nodes/index.cjs +72 -0
- package/dist/components/ui/prompt-editor/nodes/index.d.ts +8 -0
- package/dist/components/ui/prompt-editor/nodes/index.js +5 -0
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.cjs +242 -0
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.d.ts +15 -0
- package/dist/components/ui/prompt-editor/plugins/AutocompletePlugin.js +208 -0
- package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.cjs +164 -0
- package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.d.ts +1 -0
- package/dist/components/ui/prompt-editor/plugins/CopyPastePlugin.js +130 -0
- package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.cjs +50 -0
- package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.d.ts +4 -0
- package/dist/components/ui/prompt-editor/plugins/EditorRefPlugin.js +16 -0
- package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.cjs +108 -0
- package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.d.ts +3 -0
- package/dist/components/ui/prompt-editor/plugins/MultilinePlugin.js +74 -0
- package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.cjs +313 -0
- package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.d.ts +7 -0
- package/dist/components/ui/prompt-editor/plugins/NodeSelectionFixPlugin.js +276 -0
- package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.cjs +186 -0
- package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.d.ts +7 -0
- package/dist/components/ui/prompt-editor/plugins/RenameTokensPlugin.js +152 -0
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.cjs +132 -0
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.d.ts +7 -0
- package/dist/components/ui/prompt-editor/plugins/ToolbarActionsPlugin.js +98 -0
- package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.cjs +85 -0
- package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.d.ts +4 -0
- package/dist/components/ui/prompt-editor/plugins/ValidateTokensPlugin.js +51 -0
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.cjs +98 -0
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.d.ts +8 -0
- package/dist/components/ui/prompt-editor/plugins/ValueSyncPlugin.js +64 -0
- package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.cjs +137 -0
- package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.d.ts +19 -0
- package/dist/components/ui/prompt-editor/plugins/VariableDropPlugin.js +100 -0
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.cjs +49 -0
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.d.ts +8 -0
- package/dist/components/ui/prompt-editor/plugins/shared/token-nodes.js +12 -0
- package/dist/components/ui/prompt-editor/prompt-editor.cjs +402 -0
- package/dist/components/ui/prompt-editor/prompt-editor.d.ts +35 -0
- package/dist/components/ui/prompt-editor/prompt-editor.js +368 -0
- package/dist/components/ui/prompt-editor/types.cjs +74 -0
- package/dist/components/ui/prompt-editor/types.d.ts +58 -0
- package/dist/components/ui/prompt-editor/types.js +31 -0
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.cjs +60 -0
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.d.ts +29 -0
- package/dist/components/ui/prompt-editor/utils/autocomplete-segments.js +20 -0
- package/dist/components/ui/prompt-editor/utils/comparison.cjs +39 -0
- package/dist/components/ui/prompt-editor/utils/comparison.d.ts +3 -0
- package/dist/components/ui/prompt-editor/utils/comparison.js +5 -0
- package/dist/components/ui/prompt-editor/utils/index.cjs +68 -0
- package/dist/components/ui/prompt-editor/utils/index.d.ts +3 -0
- package/dist/components/ui/prompt-editor/utils/index.js +4 -0
- package/dist/components/ui/prompt-editor/utils/insert-token.cjs +103 -0
- package/dist/components/ui/prompt-editor/utils/insert-token.d.ts +12 -0
- package/dist/components/ui/prompt-editor/utils/insert-token.js +66 -0
- package/dist/components/ui/prompt-editor/utils/serialization.cjs +255 -0
- package/dist/components/ui/prompt-editor/utils/serialization.d.ts +16 -0
- package/dist/components/ui/prompt-editor/utils/serialization.js +200 -0
- package/dist/index.cjs +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -1
- package/dist/styles.css +42 -0
- package/dist/tailwind.utilities.css +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { $generateNodesFromSerializedNodes, $getLexicalContent, $insertGeneratedNodes } from "@lexical/clipboard";
|
|
3
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
4
|
+
import { mergeRegister } from "@lexical/utils";
|
|
5
|
+
import { $createRangeSelectionFromDom, $getSelection, $isRangeSelection, COMMAND_PRIORITY_CRITICAL, COPY_COMMAND, CUT_COMMAND, PASTE_COMMAND } from "lexical";
|
|
6
|
+
import { createInputTokenNode, createOutputTokenNode, createResourceTokenNode, createStateTokenNode } from "../nodes/index.js";
|
|
7
|
+
import { clipboardStringToTokens, getEditorTokensFromSelection, tokensToClipboardString } from "../utils/index.js";
|
|
8
|
+
const LEXICAL_MIME = 'application/x-lexical-editor';
|
|
9
|
+
const copySelectionToClipboard = (editor, clipboardData, selection)=>{
|
|
10
|
+
const tokens = getEditorTokensFromSelection(selection);
|
|
11
|
+
if (0 === tokens.length) return false;
|
|
12
|
+
clipboardData.setData('text/plain', tokensToClipboardString(tokens));
|
|
13
|
+
const lexicalJson = $getLexicalContent(editor, selection);
|
|
14
|
+
if (lexicalJson) clipboardData.setData(LEXICAL_MIME, lexicalJson);
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
17
|
+
const tryPasteLexicalContent = (editor, clipboardData, selection)=>{
|
|
18
|
+
const lexicalJson = clipboardData.getData(LEXICAL_MIME);
|
|
19
|
+
if (!lexicalJson) return false;
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(lexicalJson);
|
|
22
|
+
if (!parsed.nodes || !Array.isArray(parsed.nodes)) return false;
|
|
23
|
+
const nodes = $generateNodesFromSerializedNodes(parsed.nodes);
|
|
24
|
+
if (0 === nodes.length) return false;
|
|
25
|
+
$insertGeneratedNodes(editor, nodes, selection);
|
|
26
|
+
return true;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const insertTokensAtSelection = (tokens, selection)=>{
|
|
32
|
+
if (!$isRangeSelection(selection)) return;
|
|
33
|
+
if (!selection.isCollapsed()) selection.removeText();
|
|
34
|
+
for (const token of tokens)if ('text' === token.type) {
|
|
35
|
+
const lines = token.value.split('\n');
|
|
36
|
+
for(let i = 0; i < lines.length; i++){
|
|
37
|
+
if (lines[i]) selection.insertText(lines[i]);
|
|
38
|
+
if (i < lines.length - 1) selection.insertParagraph();
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
let tokenNode;
|
|
42
|
+
switch(token.type){
|
|
43
|
+
case 'input':
|
|
44
|
+
tokenNode = createInputTokenNode(token.value);
|
|
45
|
+
break;
|
|
46
|
+
case 'output':
|
|
47
|
+
tokenNode = createOutputTokenNode(token.value);
|
|
48
|
+
break;
|
|
49
|
+
case 'state':
|
|
50
|
+
tokenNode = createStateTokenNode(token.value);
|
|
51
|
+
break;
|
|
52
|
+
case 'resource':
|
|
53
|
+
tokenNode = createResourceTokenNode(token.value);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error('Unknown token type');
|
|
57
|
+
}
|
|
58
|
+
if (tokenNode) selection.insertNodes([
|
|
59
|
+
tokenNode
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const pasteTextContent = (text, selection)=>{
|
|
64
|
+
if (!text) return false;
|
|
65
|
+
const tokens = clipboardStringToTokens(text);
|
|
66
|
+
if (0 === tokens.length) return false;
|
|
67
|
+
insertTokensAtSelection(tokens, selection);
|
|
68
|
+
return true;
|
|
69
|
+
};
|
|
70
|
+
const CopyPastePlugin = ()=>{
|
|
71
|
+
const [editor] = useLexicalComposerContext();
|
|
72
|
+
useEffect(()=>mergeRegister(editor.registerCommand(COPY_COMMAND, (event)=>{
|
|
73
|
+
if (!event || !('clipboardData' in event) || !event.clipboardData) return false;
|
|
74
|
+
let handled = false;
|
|
75
|
+
editor.read(()=>{
|
|
76
|
+
let selection = $getSelection();
|
|
77
|
+
if (!selection || $isRangeSelection(selection) && selection.isCollapsed()) {
|
|
78
|
+
const domSelection = window.getSelection();
|
|
79
|
+
const rootElement = editor.getRootElement();
|
|
80
|
+
if (domSelection && rootElement && !domSelection.isCollapsed) selection = $createRangeSelectionFromDom(domSelection, editor);
|
|
81
|
+
}
|
|
82
|
+
if (!selection || $isRangeSelection(selection) && selection.isCollapsed()) return;
|
|
83
|
+
handled = copySelectionToClipboard(editor, event.clipboardData, selection);
|
|
84
|
+
});
|
|
85
|
+
if (handled) event.preventDefault();
|
|
86
|
+
return handled;
|
|
87
|
+
}, COMMAND_PRIORITY_CRITICAL), editor.registerCommand(CUT_COMMAND, (event)=>{
|
|
88
|
+
if (!event || !('clipboardData' in event) || !event.clipboardData) return false;
|
|
89
|
+
let handled = false;
|
|
90
|
+
editor.read(()=>{
|
|
91
|
+
let selection = $getSelection();
|
|
92
|
+
if (!selection || $isRangeSelection(selection) && selection.isCollapsed()) {
|
|
93
|
+
const domSelection = window.getSelection();
|
|
94
|
+
const rootElement = editor.getRootElement();
|
|
95
|
+
if (domSelection && rootElement && !domSelection.isCollapsed) selection = $createRangeSelectionFromDom(domSelection, editor);
|
|
96
|
+
}
|
|
97
|
+
if (!selection || $isRangeSelection(selection) && selection.isCollapsed()) return;
|
|
98
|
+
handled = copySelectionToClipboard(editor, event.clipboardData, selection);
|
|
99
|
+
});
|
|
100
|
+
if (handled) {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
editor.update(()=>{
|
|
103
|
+
const selection = $getSelection();
|
|
104
|
+
if (selection && $isRangeSelection(selection)) selection.removeText();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return handled;
|
|
108
|
+
}, COMMAND_PRIORITY_CRITICAL), editor.registerCommand(PASTE_COMMAND, (event)=>{
|
|
109
|
+
if (!event || !('clipboardData' in event) || !event.clipboardData) return false;
|
|
110
|
+
const clipboardData = event.clipboardData;
|
|
111
|
+
const hasLexicalJson = Boolean(clipboardData.getData(LEXICAL_MIME));
|
|
112
|
+
const plainText = clipboardData.getData('text/plain');
|
|
113
|
+
const hasPlainText = Boolean(plainText);
|
|
114
|
+
if (!hasLexicalJson && !hasPlainText) return false;
|
|
115
|
+
event.preventDefault();
|
|
116
|
+
editor.update(()=>{
|
|
117
|
+
const selection = $getSelection();
|
|
118
|
+
if (!selection) return;
|
|
119
|
+
if (hasLexicalJson && tryPasteLexicalContent(editor, clipboardData, selection)) return;
|
|
120
|
+
if (hasPlainText) pasteTextContent(plainText, selection);
|
|
121
|
+
}, {
|
|
122
|
+
discrete: true
|
|
123
|
+
});
|
|
124
|
+
return true;
|
|
125
|
+
}, COMMAND_PRIORITY_CRITICAL)), [
|
|
126
|
+
editor
|
|
127
|
+
]);
|
|
128
|
+
return null;
|
|
129
|
+
};
|
|
130
|
+
export { CopyPastePlugin };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
EditorRefPlugin: ()=>EditorRefPlugin
|
|
28
|
+
});
|
|
29
|
+
const external_react_namespaceObject = require("react");
|
|
30
|
+
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
31
|
+
const EditorRefPlugin = ({ onRef })=>{
|
|
32
|
+
const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
|
|
33
|
+
const onRefRef = (0, external_react_namespaceObject.useRef)(onRef);
|
|
34
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
35
|
+
onRefRef.current = onRef;
|
|
36
|
+
});
|
|
37
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
38
|
+
onRefRef.current(editor);
|
|
39
|
+
}, [
|
|
40
|
+
editor
|
|
41
|
+
]);
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
exports.EditorRefPlugin = __webpack_exports__.EditorRefPlugin;
|
|
45
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
46
|
+
"EditorRefPlugin"
|
|
47
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
48
|
+
Object.defineProperty(exports, '__esModule', {
|
|
49
|
+
value: true
|
|
50
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
+
const EditorRefPlugin = ({ onRef })=>{
|
|
4
|
+
const [editor] = useLexicalComposerContext();
|
|
5
|
+
const onRefRef = useRef(onRef);
|
|
6
|
+
useEffect(()=>{
|
|
7
|
+
onRefRef.current = onRef;
|
|
8
|
+
});
|
|
9
|
+
useEffect(()=>{
|
|
10
|
+
onRefRef.current(editor);
|
|
11
|
+
}, [
|
|
12
|
+
editor
|
|
13
|
+
]);
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
export { EditorRefPlugin };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
MultilinePlugin: ()=>MultilinePlugin
|
|
28
|
+
});
|
|
29
|
+
const external_react_namespaceObject = require("react");
|
|
30
|
+
const LexicalComposerContext_namespaceObject = require("@lexical/react/LexicalComposerContext");
|
|
31
|
+
const utils_namespaceObject = require("@lexical/utils");
|
|
32
|
+
const external_lexical_namespaceObject = require("lexical");
|
|
33
|
+
const collapseParagraphs = ()=>{
|
|
34
|
+
const root = (0, external_lexical_namespaceObject.$getRoot)();
|
|
35
|
+
const paragraphs = root.getChildren().filter(external_lexical_namespaceObject.$isParagraphNode);
|
|
36
|
+
if (paragraphs.length <= 1) return;
|
|
37
|
+
const allNodes = [];
|
|
38
|
+
for (const [i, paragraph] of paragraphs.entries()){
|
|
39
|
+
const children = paragraph.getChildren();
|
|
40
|
+
if (i > 0 && children.length > 0) allNodes.push((0, external_lexical_namespaceObject.$createTextNode)(' '));
|
|
41
|
+
for (const child of children)allNodes.push(child);
|
|
42
|
+
}
|
|
43
|
+
const newParagraph = (0, external_lexical_namespaceObject.$createParagraphNode)();
|
|
44
|
+
for (const node of allNodes)newParagraph.append(node);
|
|
45
|
+
root.clear();
|
|
46
|
+
root.append(newParagraph);
|
|
47
|
+
};
|
|
48
|
+
const stripNewlinesFromText = (text)=>text.replace(/\n+/g, ' ');
|
|
49
|
+
const MultilinePlugin = ({ multiline })=>{
|
|
50
|
+
const [editor] = (0, LexicalComposerContext_namespaceObject.useLexicalComposerContext)();
|
|
51
|
+
const prevMultilineRef = (0, external_react_namespaceObject.useRef)(null);
|
|
52
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
53
|
+
const wasMultiline = prevMultilineRef.current;
|
|
54
|
+
prevMultilineRef.current = multiline;
|
|
55
|
+
const isInitialMount = null === wasMultiline;
|
|
56
|
+
const switchedToSingleLine = true === wasMultiline && !multiline;
|
|
57
|
+
if (!multiline && (isInitialMount || switchedToSingleLine)) {
|
|
58
|
+
const timeoutId = setTimeout(()=>{
|
|
59
|
+
editor.update(()=>{
|
|
60
|
+
collapseParagraphs();
|
|
61
|
+
const root = (0, external_lexical_namespaceObject.$getRoot)();
|
|
62
|
+
const paragraphs = root.getChildren().filter(external_lexical_namespaceObject.$isParagraphNode);
|
|
63
|
+
for (const paragraph of paragraphs){
|
|
64
|
+
const children = paragraph.getChildren();
|
|
65
|
+
for (const child of children)if ((0, external_lexical_namespaceObject.$isLineBreakNode)(child)) {
|
|
66
|
+
const prev = child.getPreviousSibling();
|
|
67
|
+
const next = child.getNextSibling();
|
|
68
|
+
if (prev && next) child.replace((0, external_lexical_namespaceObject.$createTextNode)(' '));
|
|
69
|
+
else child.remove();
|
|
70
|
+
} else if (child instanceof external_lexical_namespaceObject.TextNode) {
|
|
71
|
+
const text = child.getTextContent();
|
|
72
|
+
if (text.includes('\n')) {
|
|
73
|
+
const newText = stripNewlinesFromText(text);
|
|
74
|
+
if ('' === newText.trim()) child.remove();
|
|
75
|
+
else child.setTextContent(newText);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}, 0);
|
|
81
|
+
return ()=>clearTimeout(timeoutId);
|
|
82
|
+
}
|
|
83
|
+
}, [
|
|
84
|
+
editor,
|
|
85
|
+
multiline
|
|
86
|
+
]);
|
|
87
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
88
|
+
if (multiline) return;
|
|
89
|
+
return (0, utils_namespaceObject.mergeRegister)(editor.registerCommand(external_lexical_namespaceObject.KEY_ENTER_COMMAND, (event)=>{
|
|
90
|
+
event?.preventDefault();
|
|
91
|
+
return true;
|
|
92
|
+
}, external_lexical_namespaceObject.COMMAND_PRIORITY_NORMAL), editor.registerNodeTransform(external_lexical_namespaceObject.TextNode, (node)=>{
|
|
93
|
+
const text = node.getTextContent();
|
|
94
|
+
if (text.includes('\n')) node.setTextContent(stripNewlinesFromText(text));
|
|
95
|
+
}));
|
|
96
|
+
}, [
|
|
97
|
+
editor,
|
|
98
|
+
multiline
|
|
99
|
+
]);
|
|
100
|
+
return null;
|
|
101
|
+
};
|
|
102
|
+
exports.MultilinePlugin = __webpack_exports__.MultilinePlugin;
|
|
103
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
104
|
+
"MultilinePlugin"
|
|
105
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
106
|
+
Object.defineProperty(exports, '__esModule', {
|
|
107
|
+
value: true
|
|
108
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
+
import { mergeRegister } from "@lexical/utils";
|
|
4
|
+
import { $createParagraphNode, $createTextNode, $getRoot, $isLineBreakNode, $isParagraphNode, COMMAND_PRIORITY_NORMAL, KEY_ENTER_COMMAND, TextNode } from "lexical";
|
|
5
|
+
const collapseParagraphs = ()=>{
|
|
6
|
+
const root = $getRoot();
|
|
7
|
+
const paragraphs = root.getChildren().filter($isParagraphNode);
|
|
8
|
+
if (paragraphs.length <= 1) return;
|
|
9
|
+
const allNodes = [];
|
|
10
|
+
for (const [i, paragraph] of paragraphs.entries()){
|
|
11
|
+
const children = paragraph.getChildren();
|
|
12
|
+
if (i > 0 && children.length > 0) allNodes.push($createTextNode(' '));
|
|
13
|
+
for (const child of children)allNodes.push(child);
|
|
14
|
+
}
|
|
15
|
+
const newParagraph = $createParagraphNode();
|
|
16
|
+
for (const node of allNodes)newParagraph.append(node);
|
|
17
|
+
root.clear();
|
|
18
|
+
root.append(newParagraph);
|
|
19
|
+
};
|
|
20
|
+
const stripNewlinesFromText = (text)=>text.replace(/\n+/g, ' ');
|
|
21
|
+
const MultilinePlugin = ({ multiline })=>{
|
|
22
|
+
const [editor] = useLexicalComposerContext();
|
|
23
|
+
const prevMultilineRef = useRef(null);
|
|
24
|
+
useEffect(()=>{
|
|
25
|
+
const wasMultiline = prevMultilineRef.current;
|
|
26
|
+
prevMultilineRef.current = multiline;
|
|
27
|
+
const isInitialMount = null === wasMultiline;
|
|
28
|
+
const switchedToSingleLine = true === wasMultiline && !multiline;
|
|
29
|
+
if (!multiline && (isInitialMount || switchedToSingleLine)) {
|
|
30
|
+
const timeoutId = setTimeout(()=>{
|
|
31
|
+
editor.update(()=>{
|
|
32
|
+
collapseParagraphs();
|
|
33
|
+
const root = $getRoot();
|
|
34
|
+
const paragraphs = root.getChildren().filter($isParagraphNode);
|
|
35
|
+
for (const paragraph of paragraphs){
|
|
36
|
+
const children = paragraph.getChildren();
|
|
37
|
+
for (const child of children)if ($isLineBreakNode(child)) {
|
|
38
|
+
const prev = child.getPreviousSibling();
|
|
39
|
+
const next = child.getNextSibling();
|
|
40
|
+
if (prev && next) child.replace($createTextNode(' '));
|
|
41
|
+
else child.remove();
|
|
42
|
+
} else if (child instanceof TextNode) {
|
|
43
|
+
const text = child.getTextContent();
|
|
44
|
+
if (text.includes('\n')) {
|
|
45
|
+
const newText = stripNewlinesFromText(text);
|
|
46
|
+
if ('' === newText.trim()) child.remove();
|
|
47
|
+
else child.setTextContent(newText);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}, 0);
|
|
53
|
+
return ()=>clearTimeout(timeoutId);
|
|
54
|
+
}
|
|
55
|
+
}, [
|
|
56
|
+
editor,
|
|
57
|
+
multiline
|
|
58
|
+
]);
|
|
59
|
+
useEffect(()=>{
|
|
60
|
+
if (multiline) return;
|
|
61
|
+
return mergeRegister(editor.registerCommand(KEY_ENTER_COMMAND, (event)=>{
|
|
62
|
+
event?.preventDefault();
|
|
63
|
+
return true;
|
|
64
|
+
}, COMMAND_PRIORITY_NORMAL), editor.registerNodeTransform(TextNode, (node)=>{
|
|
65
|
+
const text = node.getTextContent();
|
|
66
|
+
if (text.includes('\n')) node.setTextContent(stripNewlinesFromText(text));
|
|
67
|
+
}));
|
|
68
|
+
}, [
|
|
69
|
+
editor,
|
|
70
|
+
multiline
|
|
71
|
+
]);
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
export { MultilinePlugin };
|