fix up editor things

This commit is contained in:
Chad Freeman 2024-08-15 21:13:00 -04:00
parent 7afb5d8097
commit ea65bf0ecd
6 changed files with 18 additions and 66 deletions

View file

@ -1,6 +1,5 @@
# Sprigsy editor
# planned for v1
- [ ] ability to play project
- [ ] monaco code editor

View file

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">

View file

@ -32,7 +32,6 @@
}
};
// Function to add global types
async function addGlobalTypes() {
const sprigTypeDef = (await import('./editorcontext/sprig.d.ts?raw')).default;
monaco.languages.typescript.typescriptDefaults.addExtraLib(
@ -42,7 +41,7 @@
const globalTypeDef = (await import('./editorcontext/global.d.ts?raw')).default;
monaco.languages.typescript.typescriptDefaults.addExtraLib(
globalTypeDef,
'context/global.d.ts'
'global.d.ts'
);
// IMPLEMENT ONCE v2 IS DONE!
@ -94,10 +93,10 @@
});
});
// Function to set up the editor
function setupEditor() {
editor = monaco.editor.create(editorContainer, {
value: `function game(api: sprig.FullSprigAPI): void {
value:
`function game(api: sprig.FullSprigAPI): void {
${code}
}`,
language: 'typescript',
@ -107,57 +106,6 @@
});
const model = editor.getModel()!;
// Mark function declaration and closing brace as read-only
// editor.createDecorationsCollection(
// [
// {
// range: new monaco.Range(1, 1, 1, 28),
// options: {
// className: 'read-only',
// isWholeLine: true
// }
// },
// {
// range: new monaco.Range(
// model.getLineCount(),
// 1,
// model.getLineCount(),
// model.getLineMaxColumn(model.getLineCount())
// ),
// options: {
// className: 'read-only',
// isWholeLine: true
// }
// }
// ]
// );
// Disable editing in read-only regions
// editor.onDidChangeModelContent((event) => {
// event.changes.forEach((change) => {
// const { range } = change;
// if (
// (range.startLineNumber === 1 && range.endLineNumber === 1) ||
// (range.startLineNumber === model.getLineCount() &&
// range.endLineNumber === model.getLineCount())
// ) {
// editor.executeEdits('revert-read-only', [
// {
// range: new monaco.Range(
// range.startLineNumber,
// range.startColumn,
// range.endLineNumber,
// range.endColumn
// ),
// text: '',
// forceMoveMarkers: true
// }
// ]);
// }
// });
// });
const constrainedInstance = constrainedEditor(monaco);
constrainedInstance.initializeIn(editor);
constrainedInstance.addRestrictionsTo(model, [

View file

@ -1,10 +1,11 @@
import "./sprig"
// for some reason this doesn't work, I can't figure out why
declare global {
var setTimeout: sprig.FullSprigAPI['setTimeout'];
var setInterval: sprig.FullSprigAPI['setInterval'];
var clearTimeout: sprig.FullSprigAPI['clearTimeout'];
var clearInterval: sprig.FullSprigAPI['clearInterval'];
var tones: typeof sprig['tones']
declare function tune(template: TemplateStringsArray, ...params: string[]): string
interface Window {
setTimeout: import('./sprig').sprig.FullSprigAPI['setTimeout'];
setInterval: sprig.FullSprigAPI['setInterval'];
clearTimeout: sprig.FullSprigAPI['clearTimeout'];
clearInterval: sprig.FullSprigAPI['clearInterval'];
}
}

View file

@ -1,3 +1,7 @@
/**
* normal sprig api
* this is provided because your project type is
*/
declare namespace sprig {
export declare const VALID_INPUTS: readonly ["w", "s", "a", "d", "i", "j", "k", "l"];
export type InputKey = typeof VALID_INPUTS[number];

View file

@ -1,8 +1,8 @@
<script>
import Editor from "$lib/Editor.svelte";
import CodeEditor from "$lib/CodeEditor.svelte";
</script>
<div class="">
<Editor />
<CodeEditor />
</div>