Skip to content

Commit fecaf2c

Browse files
committed
暂时移除 Million,并独立化文本导入编辑器
1 parent 4cae72f commit fecaf2c

2 files changed

Lines changed: 33 additions & 110 deletions

File tree

src/components/Dialogs/import-from-text.tsx

Lines changed: 31 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import {
1717
Select,
1818
Switch,
1919
Text,
20+
TextArea,
2021
TextField,
2122
} from "@radix-ui/themes";
22-
import { useAtom, useAtomValue, useStore } from "jotai";
23+
import { atom, useAtom, useAtomValue, useStore } from "jotai";
2324
import { atomWithStorage } from "jotai/utils";
2425
import type * as monaco from "monaco-editor";
2526
import {
@@ -88,15 +89,27 @@ const emptyBeatSymbolAtom = atomWithStorage(
8889
"importFromText.emptyBeatSymbol",
8990
"^",
9091
);
92+
const textValueAtom = atom("");
93+
94+
const ImportFromTextEditor = memo(() => {
95+
const [value, setValue] = useAtom(textValueAtom);
96+
return (
97+
<TextArea
98+
style={{
99+
height: "calc(80vh - 5em)",
100+
flex: "1 1 auto",
101+
fontFamily: "var(--code-font-family)"
102+
}}
103+
value={value}
104+
onChange={(evt) => setValue(evt.currentTarget.value)}
105+
/>
106+
);
107+
});
91108

92109
export const ImportFromText = () => {
93-
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>(null);
94-
const monacoRef = useRef<Monaco>(null);
95-
const [value, setValue] = useState("");
96110
const [importFromTextDialog, setImportFromTextDialog] = useAtom(
97111
importFromTextDialogAtom,
98112
);
99-
const isDarkTheme = useAtomValue(isDarkThemeAtom);
100113

101114
const [importMode, setImportMode] = useAtom(importModeAtom);
102115
const [lineSeparatorMode, setLineSeparatorMode] = useAtom(
@@ -269,96 +282,6 @@ export const ImportFromText = () => {
269282
[store],
270283
);
271284

272-
function handleEditorWillMount(monaco: Monaco) {
273-
console.log(
274-
"monaco.languages.getLanguages()",
275-
monaco.languages.getLanguages(),
276-
);
277-
}
278-
279-
function handleEditorDidMount(
280-
editor: monaco.editor.IStandaloneCodeEditor,
281-
monaco: Monaco,
282-
) {
283-
editorRef.current = editor;
284-
monacoRef.current = monaco;
285-
286-
editor.updateOptions({
287-
smoothScrolling: true,
288-
});
289-
290-
// let decoCol: IEditorDecorationsCollection | null = null;
291-
292-
// editor.onDidChangeModelContent(() => {
293-
// try {
294-
// decoCol?.clear();
295-
// } catch {
296-
// /* empty */
297-
// }
298-
// const model = editor.getModel();
299-
// if (!model) return;
300-
301-
// const deco: IModelDeltaDecoration[] = [];
302-
303-
// deco.push(
304-
// ...model
305-
// .findMatches(wordSeparator, true, false, true, null, false)
306-
// .map((match) => ({
307-
// range: match.range,
308-
// options: {
309-
// inlineClassName: styles.wordSeparator,
310-
// },
311-
// })),
312-
// );
313-
314-
// deco.push(
315-
// ...model
316-
// .findMatches(lineSeparator, true, false, true, null, false)
317-
// .map((match) => ({
318-
// range: match.range,
319-
// options: {
320-
// inlineClassName: styles.lineSeparator,
321-
// },
322-
// })),
323-
// );
324-
325-
// deco.push(
326-
// ...model
327-
// .findMatches(bgLyricPrefix, true, false, true, null, false)
328-
// .map((match) => ({
329-
// range: match.range,
330-
// options: {
331-
// inlineClassName: styles.bgLinePrefix,
332-
// },
333-
// })),
334-
// );
335-
336-
// deco.push(
337-
// ...model
338-
// .findMatches(duetLyricPrefix, true, false, true, null, false)
339-
// .map((match) => ({
340-
// range: match.range,
341-
// options: {
342-
// inlineClassName: styles.duetLinePrefix,
343-
// },
344-
// })),
345-
// );
346-
347-
// deco.push(
348-
// ...model
349-
// .findMatches(emptyBeatSymbol, true, false, true, null, false)
350-
// .map((match) => ({
351-
// range: match.range,
352-
// options: {
353-
// inlineClassName: styles.emptyBeatSymbol,
354-
// },
355-
// })),
356-
// );
357-
358-
// decoCol = editor.createDecorationsCollection(deco);
359-
// });
360-
}
361-
362285
return (
363286
<Dialog.Root
364287
open={importFromTextDialog}
@@ -377,7 +300,7 @@ export const ImportFromText = () => {
377300
<Button
378301
onClick={() => {
379302
try {
380-
onImport(value);
303+
onImport(store.get(textValueAtom));
381304
setImportFromTextDialog(false);
382305
} catch (e) {
383306
error(
@@ -397,20 +320,20 @@ export const ImportFromText = () => {
397320
sm: "row",
398321
}}
399322
>
400-
<Card style={{ flex: "1 1 auto" }}>
323+
{/* <Card style={{ flex: "1 1 auto" }}>
401324
<Inset>
402-
<SuspensePlaceHolder>
403-
<MonacoEditor
404-
height="calc(80vh - 5em)"
405-
theme={isDarkTheme ? "vs-dark" : "light"}
406-
beforeMount={handleEditorWillMount}
407-
onMount={handleEditorDidMount}
408-
value={value}
409-
onChange={(v) => setValue(v ?? "")}
410-
/>
411-
</SuspensePlaceHolder>
325+
<TextArea
326+
style={{
327+
height: "calc(80vh - 5em)",
328+
flex: "1 1 auto"
329+
}}
330+
value={value}
331+
onChange={(evt) => setValue(evt.currentTarget.value)}
332+
/>
412333
</Inset>
413-
</Card>
334+
</Card> */}
335+
336+
<ImportFromTextEditor />
414337
<Grid
415338
columns="2"
416339
gapY="2"

vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MillionLint from "@million/lint";
1+
// import MillionLint from "@million/lint";
22
import react from "@vitejs/plugin-react";
33
import jotaiDebugLabel from "jotai/babel/plugin-debug-label";
44
import jotaiReactRefresh from "jotai/babel/plugin-react-refresh";
@@ -26,7 +26,7 @@ process.env.AMLL_LOCAL_EXISTS = AMLL_LOCAL_EXISTS ? "true" : "false";
2626
const plugins: Plugin[] = [
2727
ConditionalCompile(),
2828
topLevelAwait(),
29-
MillionLint.vite(),
29+
// MillionLint.vite(),
3030
react({
3131
babel: {
3232
presets: ["jotai/babel/preset"],

0 commit comments

Comments
 (0)