mirror of
https://codeberg.org/uzu/strudel
synced 2026-09-04 22:52:55 -04:00
themable codemirror + repl
This commit is contained in:
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
+8
-3
@@ -174,7 +174,7 @@ const highlightField = StateField.define({
|
||||
},
|
||||
provide: (f) => EditorView.decorations.from(f)
|
||||
});
|
||||
function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorDidMount }) {
|
||||
function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorDidMount, theme }) {
|
||||
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CodeMirror$1, {
|
||||
onViewChange: onViewChanged,
|
||||
style: {
|
||||
@@ -186,7 +186,7 @@ function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorD
|
||||
onChange,
|
||||
extensions: [
|
||||
javascript(),
|
||||
materialPalenight,
|
||||
theme || materialPalenight,
|
||||
highlightField
|
||||
]
|
||||
}));
|
||||
@@ -423,6 +423,10 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawP
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => cycle.stop();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
pending,
|
||||
code,
|
||||
@@ -538,7 +542,7 @@ function Icon({ type }) {
|
||||
}[type]);
|
||||
}
|
||||
|
||||
function MiniRepl({ tune, defaultSynth, hideOutsideView = false }) {
|
||||
function MiniRepl({ tune, defaultSynth, hideOutsideView = false, theme }) {
|
||||
const { code, setCode, pattern, activateCode, error, cycle, dirty, togglePlay } = useRepl({
|
||||
tune,
|
||||
defaultSynth,
|
||||
@@ -578,6 +582,7 @@ function MiniRepl({ tune, defaultSynth, hideOutsideView = false }) {
|
||||
}, error.message)), /* @__PURE__ */ React.createElement("div", {
|
||||
className: styles.body
|
||||
}, show && /* @__PURE__ */ React.createElement(CodeMirror, {
|
||||
theme,
|
||||
value: code,
|
||||
onChange: setCode,
|
||||
onViewChanged: setView
|
||||
|
||||
@@ -45,7 +45,7 @@ const highlightField = StateField.define({
|
||||
provide: (f) => EditorView.decorations.from(f),
|
||||
});
|
||||
|
||||
export default function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorDidMount }) {
|
||||
export default function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorDidMount, theme }) {
|
||||
return (
|
||||
<>
|
||||
<_CodeMirror
|
||||
@@ -59,7 +59,7 @@ export default function CodeMirror({ value, onChange, onViewChanged, onCursor, o
|
||||
onChange={onChange}
|
||||
extensions={[
|
||||
javascript(),
|
||||
materialPalenight,
|
||||
theme || materialPalenight,
|
||||
highlightField,
|
||||
// theme, language, ...
|
||||
]}
|
||||
|
||||
@@ -9,7 +9,7 @@ import './style.css';
|
||||
import styles from './MiniRepl.module.css';
|
||||
import { Icon } from './Icon';
|
||||
|
||||
export function MiniRepl({ tune, defaultSynth, hideOutsideView = false }) {
|
||||
export function MiniRepl({ tune, defaultSynth, hideOutsideView = false, theme }) {
|
||||
const { code, setCode, pattern, activateCode, error, cycle, dirty, togglePlay } = useRepl({
|
||||
tune,
|
||||
defaultSynth,
|
||||
@@ -40,8 +40,8 @@ export function MiniRepl({ tune, defaultSynth, hideOutsideView = false }) {
|
||||
</div>
|
||||
{error && <div className={styles.error}>{error.message}</div>}
|
||||
</div>
|
||||
<div className={styles.body} >
|
||||
{show && <CodeMirror6 value={code} onChange={setCode} onViewChanged={setView} />}
|
||||
<div className={styles.body}>
|
||||
{show && <CodeMirror6 theme={theme} value={code} onChange={setCode} onViewChanged={setView} />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { useCallback, useState, useMemo } from 'react';
|
||||
import { useCallback, useState, useMemo, useEffect } from 'react';
|
||||
import { evaluate } from '@strudel.cycles/eval';
|
||||
import { getPlayableNoteValue } from '@strudel.cycles/core/util.mjs';
|
||||
import useCycle from './useCycle.mjs';
|
||||
@@ -142,6 +142,10 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawP
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => cycle.stop();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
pending,
|
||||
code,
|
||||
|
||||
Reference in New Issue
Block a user