mirror of
https://codeberg.org/uzu/strudel
synced 2026-11-30 11:16:48 -05:00
Compare commits
9 Commits
remove-log
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 98b71bcb4d | |||
| cf7dae5d7f | |||
| b3d9eab3b6 | |||
| c799a686c0 | |||
| b8b59d911f | |||
| a5079db6f7 | |||
| 36647afbbf | |||
| 7a343930aa | |||
| 266e5da109 |
@@ -19,7 +19,7 @@ import { isAutoCompletionEnabled } from './autocomplete.mjs';
|
||||
import { basicSetup } from './basicSetup.mjs';
|
||||
import { flash, isFlashEnabled } from './flash.mjs';
|
||||
import { highlightMiniLocations, isPatternHighlightingEnabled, updateMiniLocations } from './highlight.mjs';
|
||||
import { keybindings } from './keybindings.mjs';
|
||||
import { editorActions, keybindings } from './keybindings.mjs';
|
||||
import { sliderPlugin, updateSliderWidgets } from './slider.mjs';
|
||||
import { activateTheme, initTheme, theme } from './themes.mjs';
|
||||
import { isTooltipEnabled } from './tooltip.mjs';
|
||||
@@ -101,6 +101,7 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
|
||||
syntaxHighlighting(defaultHighlightStyle),
|
||||
EditorView.updateListener.of((v) => onChange(v)),
|
||||
drawSelection({ cursorBlinkRate: 0 }),
|
||||
editorActions.of({ onEvaluate, onStop }),
|
||||
Prec.highest(
|
||||
keymap.of([
|
||||
{
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { defaultKeymap } from '@codemirror/commands';
|
||||
import { Prec, EditorState } from '@codemirror/state';
|
||||
import { defaultKeymap, toggleLineComment } from '@codemirror/commands';
|
||||
import { Facet, Prec, EditorState } from '@codemirror/state';
|
||||
import { keymap, ViewPlugin } from '@codemirror/view';
|
||||
// import { searchKeymap } from '@codemirror/search';
|
||||
import { emacs } from '@replit/codemirror-emacs';
|
||||
import { vim } from '@replit/codemirror-vim';
|
||||
import { vim, Vim } from '@replit/codemirror-vim';
|
||||
// import { vim } from './vim_test.mjs';
|
||||
import { vscodeKeymap } from '@replit/codemirror-vscode-keymap';
|
||||
|
||||
// Per-editor way to plumb down { onEvaluate, onStop }, provided by initEditor.
|
||||
export const editorActions = Facet.define({ combine: (values) => values[0] ?? {} });
|
||||
|
||||
const vscodePlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
constructor() {}
|
||||
@@ -26,7 +29,18 @@ const keymaps = {
|
||||
vscode: vscodeExtension,
|
||||
};
|
||||
|
||||
export { Vim } from '@replit/codemirror-vim';
|
||||
export { Vim }; // export for patterns/prebake to define custom actions
|
||||
|
||||
Vim.defineEx('write', 'w', (cm) => cm.cm6.state.facet(editorActions).onEvaluate?.());
|
||||
Vim.defineEx('quit', 'q', (cm) => cm.cm6.state.facet(editorActions).onStop?.());
|
||||
|
||||
Vim.defineOperator('toggleComment', (cm, _args, _ranges, oldAnchor) => {
|
||||
// By the time an operator runs, vim has selected the motion's range in the
|
||||
// real editor so we can just call the normal codemirror command
|
||||
toggleLineComment(cm.cm6);
|
||||
return oldAnchor;
|
||||
});
|
||||
Vim.mapCommand('gc', 'operator', 'toggleComment', {}, { isEdit: true });
|
||||
|
||||
export function keybindings(name) {
|
||||
const active = keymaps[name];
|
||||
|
||||
+17
-61
@@ -2,23 +2,20 @@ import jsdoc from '../../../doc.json'; // doc.json is built with `npm run jsdoc-
|
||||
const docs = jsdoc.docs.reduce((acc, obj) => Object.assign(acc, { [obj.longname]: obj }), {});
|
||||
import { MiniRepl } from './MiniRepl';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Object} arguments
|
||||
* @param {number} [arguments.h] Adds a heading (like 3 for h3). Deprecated, add the heading in MDX instead.
|
||||
* @returns
|
||||
*/
|
||||
export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasHeight, hideMiniRepl }) {
|
||||
export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight }) {
|
||||
const item = docs[name];
|
||||
if (!item) {
|
||||
console.warn(`JsDoc for ${name} not found`);
|
||||
return <div>Could not load docs for ${name}</div>;
|
||||
console.warn('Not found: ' + name);
|
||||
return <div />;
|
||||
}
|
||||
const CustomHeading = h ? `h${h}` : undefined;
|
||||
const description = parseAndReplaceLink(item.description ?? '');
|
||||
const CustomHeading = `h${h}`;
|
||||
const description =
|
||||
item.description?.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => {
|
||||
return `<a href="#${a.replaceAll('.', '').toLowerCase()}${b ? `-${b}` : ''}">${a}${b ? `#${b}` : ''}</a>`;
|
||||
}) || '';
|
||||
return (
|
||||
<>
|
||||
{!!h && <CustomHeading id={name}>{item.longname}</CustomHeading>}
|
||||
{!!h && <CustomHeading>{item.longname}</CustomHeading>}
|
||||
{!hideDescription && (
|
||||
<>
|
||||
{!!item.synonyms_text && (
|
||||
@@ -29,43 +26,19 @@ export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasH
|
||||
<div dangerouslySetInnerHTML={{ __html: description }} />
|
||||
</>
|
||||
)}
|
||||
{item.params && item.params.length > 0 && <p className="font-bold">Arguments</p>}
|
||||
<ul>
|
||||
{item.params?.map(({ name, type, description }, i) => {
|
||||
// Check if the param is actually the parameter of an object
|
||||
const objParamSeperator = name.indexOf('.');
|
||||
const isObjectParam = objParamSeperator !== -1;
|
||||
|
||||
return (
|
||||
<li key={i} className={isObjectParam ? 'list-none' : ''}>
|
||||
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
|
||||
{description ? <> - {removeHtmlTags(description)}</> : ''}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
{item.params?.map((param, i) => (
|
||||
<li key={i}>
|
||||
{param.name} ({param.type?.names?.join('|')}): {param.description?.replace(/(<([^>]+)>)/gi, '')}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{item.returns && (
|
||||
<p>
|
||||
<span className="font-bold">Returns</span>{' '}
|
||||
{item.returns
|
||||
.map((returnValue) => {
|
||||
const description = returnValue.description ? `- ${removeHtmlTags(returnValue.description)}` : '';
|
||||
return `${returnValue.type?.names?.join(' | ')} ${description}`;
|
||||
})
|
||||
.join(' or ')}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{item.examples?.length ? (
|
||||
<div className="space-y-2">
|
||||
{item.examples?.map((example, k) => {
|
||||
const key = `${item.longname}_example_${k}`;
|
||||
return hideMiniRepl ? (
|
||||
<pre key={key}>{example}</pre>
|
||||
) : (
|
||||
<MiniRepl tune={example} key={key} {...{ punchcard, canvasHeight }} />
|
||||
);
|
||||
})}
|
||||
{item.examples?.map((example, k) => (
|
||||
<MiniRepl tune={example} key={k} {...{ punchcard, canvasHeight }} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
@@ -73,20 +46,3 @@ export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasH
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the jsDocs link with something else.
|
||||
* @param {string} string
|
||||
* @param {(name:string,longname: string) => string} [replaceWith]
|
||||
*/
|
||||
export const parseAndReplaceLink = (string, replaceWith) => {
|
||||
const jsDocsLinkRegex = /\{@link ([a-zA-Z\.#]+)\}/g;
|
||||
const fun = replaceWith ?? ((name, longname) => `<a target="_blank" href="/reference#${longname}">${name}</a>`);
|
||||
|
||||
return string.replaceAll(jsDocsLinkRegex, (_, longname) => {
|
||||
const name = [...longname.matchAll(/[a-zA-Z]*[\.#]?([a-zA-Z]+)/g)].at(0)?.at(1); //take the string after . or #
|
||||
return fun(name ?? longname, longname);
|
||||
});
|
||||
};
|
||||
|
||||
const removeHtmlTags = (string) => string.replace(/(<([^>]+)>)/gi, '');
|
||||
|
||||
@@ -3,7 +3,6 @@ import { memo, useEffect, useMemo, useState, Fragment } from 'react';
|
||||
import jsdocJson from '../../../../../doc.json';
|
||||
import { Textbox } from '@src/repl/components/panel/SettingsTab';
|
||||
import { settingsMap, useSettings } from '@src/settings.mjs';
|
||||
import { JsDoc } from '@src/docs/JsDoc';
|
||||
import { computeAvailableFunctions } from '@src/jsDocsUtils.mjs';
|
||||
|
||||
const availableFunctions = computeAvailableFunctions(jsdocJson);
|
||||
@@ -179,7 +178,48 @@ export const Reference = memo(function Reference() {
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<JsDoc name={entry.longname} hideMiniRepl></JsDoc>
|
||||
{!!entry.synonyms_text && (
|
||||
<p>
|
||||
Synonyms: <code>{entry.synonyms_text}</code>
|
||||
</p>
|
||||
)}
|
||||
|
||||
<p
|
||||
dangerouslySetInnerHTML={{
|
||||
// If we have an external url make sure it opens in another tab to not interrupt the player
|
||||
__html: entry.description.replaceAll(/<a href="https:\/\//g, `<a target="_blank" href="https://`),
|
||||
}}
|
||||
></p>
|
||||
{entry.params && entry.params.length > 0 && <p className="font-bold">Arguments</p>}
|
||||
<ul>
|
||||
{entry.params?.map(({ name, type, description }, i) => {
|
||||
// Check if the param is actually the parameter of an object
|
||||
const objParamSeperator = name.indexOf('.');
|
||||
const isObjectParam = objParamSeperator !== -1;
|
||||
|
||||
return (
|
||||
<li key={i} className={isObjectParam ? 'list-none' : ''}>
|
||||
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
|
||||
{description ? <> - {getInnerText(description)}</> : ''}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
{entry.returns && (
|
||||
<p>
|
||||
<span className="font-bold">Returns</span>{' '}
|
||||
{entry.returns.map(({ type, description }) => (
|
||||
<>
|
||||
{type?.names?.join(' | ')} {description ? <> - {getInnerText(description)}</> : ''}
|
||||
</>
|
||||
))}
|
||||
</p>
|
||||
)}
|
||||
{entry.examples?.map((example, j) => (
|
||||
<pre className="bg-background border border-muted" key={j}>
|
||||
{example}
|
||||
</pre>
|
||||
))}
|
||||
</section>
|
||||
)) || <p className="font-sans">Search or select a tag to get started.</p>}
|
||||
{detailVisibleFunctions.length > 0 && <div className="h-screen" />}
|
||||
|
||||
@@ -37,8 +37,11 @@ export function WelcomeTab({ context }) {
|
||||
tidalcycles
|
||||
</a>
|
||||
, which is a popular live coding language for music, written in Haskell. Strudel is free/open source software,
|
||||
with copyright owned by its [contributors](https://codeberg.org/uzu/strudel/activity/contributors). You can
|
||||
redistribute and/or modify it under the terms of the{' '}
|
||||
with copyright owned by its{' '}
|
||||
<a href="https://codeberg.org/uzu/strudel/activity/contributors" target="_blank">
|
||||
contributors
|
||||
</a>
|
||||
. You can redistribute and/or modify it under the terms of the{' '}
|
||||
<a href="https://codeberg.org/uzu/strudel/src/branch/main/LICENSE" target="_blank">
|
||||
GNU Affero General Public License
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user