Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 9 additions & 35 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import process from "process";
import builtins from "builtin-modules";
import glsl from "esbuild-plugin-glsl";
import fs from 'fs';
import path from 'node:path';

const banner =
`/*
Expand Down Expand Up @@ -37,46 +36,20 @@ let manifest = {
}
}

// const workerPlugin = {
// name: 'monaco-workers',
// setup(build) {
// build.onResolve({ filter: /\.worker\.js$/ }, async (args) => {
// return {
// path: path.resolve(args.resolveDir, args.path),
// namespace: 'monaco-worker',
// };
// });
import * as dotenv from 'dotenv'

// build.onLoad({ filter: /.*/, namespace: 'monaco-worker' }, async (args) => {
// // Bundle worker code into a self-contained script
// const result = await esbuild.build({
// entryPoints: [args.path],
// bundle: true,
// format: 'iife',
// write: false,
// target: 'es6',
// });

// const code = result.outputFiles[0].text;
// return {
// contents: `export default ${JSON.stringify(code)};`,
// loader: 'js',
// };
// });
// }
// };
dotenv.config();

let autotest = {
name: 'autotest',
setup(build) {
build.onEnd(() => {
const PUT_YOUR_PATH_HERE_IF_ENABLED = '';
const ENABLED = false;
const args = process.argv.splice(2);

if (ENABLED) {
fs.copyFileSync('out/manifest.json', PUT_YOUR_PATH_HERE_IF_ENABLED);
fs.copyFileSync('out/main.js', PUT_YOUR_PATH_HERE_IF_ENABLED);
fs.copyFileSync('out/styles.css', PUT_YOUR_PATH_HERE_IF_ENABLED);
if (args.includes('--autotest')) {
fs.copyFileSync('out/manifest.json', process.env.TESTING_PATH);
fs.copyFileSync('out/main.js', process.env.TESTING_PATH);
fs.copyFileSync('out/styles.css', process.env.TESTING_PATH);
}
});
}
Expand All @@ -97,7 +70,6 @@ const context = await esbuild.context({
glsl({
minify: true,
}),
// workerPlugin,
{
name: 'worker-plugin',
setup(build) {
Expand Down Expand Up @@ -132,6 +104,8 @@ const context = await esbuild.context({
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
"./mode",
"./lib",
...builtins],
format: "cjs",
target: "es6",
Expand Down
24 changes: 9 additions & 15 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES2020",
"jsx": "react",
"strictNullChecks": true,
"strictFunctionTypes": true
},
"exclude": [
"env",
"**/env/*",
"node_modules",
"**/node_modules/*"
]
}
"compilerOptions": {
"module": "ESNext",
"target": "ES2020",
"jsx": "react",
"strictNullChecks": true,
"strictFunctionTypes": true
},
"exclude": ["env", "**/env/*", "node_modules", "**/node_modules/*"]
}
33 changes: 1 addition & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,15 @@
],
"readme": "https://github.com/Falcion/UNITADE.md#readme",
"scripts": {
"lint": "node ./script/lint.js && npm run lint:docs",
"lint:js": "node ./script/lint.js --js",
"lint:clang-format": "python3 script/pytohn/run-clang-format.py -r -c shell/ || (echo \"\\nCode not formatted correctly.\" && exit 1)",
"lint:clang-tidy": "python3 ./script/python/run-clang-tidy.py",
"lint:cpp": "node ./script/lint.js --cc",
"lint:objc": "node ./script/lint.js --objc",
"lint:py": "node ./script/lint.js --py",
"lint:gn": "node ./script/lint.js --gn",
"lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run ct-typescript-definitions && npm run lint:ts-check-js-in-markdown && npm run lint:docs-fiddles && npm run lint:docs-relative-links && npm run lint:markdown",
"lint:docs-fiddles": "standard \"docs/fiddles/**/*.js\"",
"lint:docs-relative-links": "electron-lint-markdown-links --root docs \"**/*.md\"",
"lint:markdown": "node ./script/lint.js --md",
"lint:ts-check-js-in-markdown": "electron-lint-markdown-ts-check --root docs \"**/*.md\" --ignore \"breaking-changes.md\"",
"lint:js-in-markdown": "electron-lint-markdown-standard --root docs \"**/*.md\"",
"create-api-json": "node script/js/create-api-json.js",
"ct-typescript-definitions": "npm run create-api-json && electron-typescript-definitions",
"gn-typescript-definitions": "npm run ct-typescript-definitions && shx cp environment.d.ts",
"pre-flight": "pre-flight",
"gn-check": "node ./script/js/gn-check.js",
"gn-format": "python3 script/python/run-gn-format.py",
"preversion": "npm i --force",
"precommit": "lint-staged",
"preinstall": "node -e 'process.exit(0)'",
"pretest": "npm run ct-typescript-definitions",
"prepack": "check-for-leaks",
"prepare": "husky .husky/ && cd scripts/python && python3 -m venv venv",
"update-analytics": "ts-node scripts/js/analytics-workflow.ts",
"test": "node ./script/spec-runner.js",
"start": "tsc && node out/environment.js",
"buildtsc": "tsc",
"install": "npm run start",
"pack": "python scripts/python/pack.py",
"release": "standard-version",
"release:minor": "standard-version --release-as minor",
"release:patch": "standard-version --release-as patch",
"release:major": "standard-version --release-as major",
"generate-version-json": "node scripts/js/generate-version-json.js",
"cli": ".\\gh.cli.sh",
"build": "tsc -noEmit && node esbuild.config.mjs production",
"build-nocheck": "tsc -noEmit -skipLibCheck --esModuleInterop --noCheck --downlevelIteration source/main.ts && node esbuild.config.mjs production"
"build:test": "tsc -noEmit && node esbuild.config.mjs production --autotest"
},
"repository": {
"type": "git",
Expand Down
6 changes: 6 additions & 0 deletions source/components/views/interface_view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { UnitadeViewEditor } from "@typings/components/views/editor";

export interface IUnitadeView {
editor: UnitadeViewEditor;
extension: string;
}
117 changes: 117 additions & 0 deletions source/components/views/view_code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

import UnitadePlugin from "@main";

import {
TextFileView,
WorkspaceLeaf,
TFile
} from "obsidian";

import { IUnitadeView } from "@views/interface_view";
import IUnitadeStatusBarPayload from "@typings/components/status/bar_config";

import * as monaco from 'monaco-editor';

import { genEditorSettings } from "../../utils/utils";

export class UnitadeViewCode extends TextFileView implements IUnitadeView {
editor!: monaco.editor.IStandaloneCodeEditor
extension: string = '';

constructor(leaf: WorkspaceLeaf, private plugin: UnitadePlugin) {
super(leaf);
}

async onOpen() {
await super.onOpen();
}

async onLoadFile(file: TFile) {
const context = genEditorSettings(this.plugin.settings, this.file?.extension ?? "");

this.plugin.updateStatusBarInfo(this.prepStatusBarInfo());

this.editor = monaco.editor.create(this.contentEl, context);
this.editor.onDidChangeModelContent(() => {
this.requestSave();
});
this.editor.onDidChangeCursorPosition(() => {
this.plugin.updateStatusBarInfo(this.prepStatusBarInfo());
});

this.addKeyActions();
this.addMouseActions();

await super.onLoadFile(file);
}

async onUnloadFile(file: TFile) {
this.removeKeyActions();
this.removeMouseActions();

await super.onUnloadFile(file);

this.editor.dispose();
}

async onClose() {
this.removeKeyActions();
this.removeMouseActions();

await super.onClose();
this.editor.dispose();
}

//#region Interface callbacks
onResize() {
this.editor.layout();
}

getViewType(): string {
return 'codeview';
}

getContext(file?: TFile) {
return file?.path ?? this.file?.path;
}

getViewData = (): string => {
return this.editor.getValue();
}

setViewData = (data: string, clear: boolean) => {
if (clear) {
this.editor.getModel()?.setValue(data);
} else {
this.editor.setValue(data);
}
}

clear = () => {
this.editor.setValue('');
}
//#endregion

private prepStatusBarInfo(): IUnitadeStatusBarPayload {
return {
cursor_lines:
this.editor.getPosition()?.lineNumber,
cursor_columns:
this.editor.getPosition()?.column,
display:
this.editor.getModel()?.getLanguageId(),
processor:
this.editor.getModel()?.id
}
}

private addKeyActions(): void {
}
private removeKeyActions(): void {
}

private addMouseActions(): void {
}
private removeMouseActions(): void {
}
}
37 changes: 26 additions & 11 deletions source/components/views/view_codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,60 @@ import {
import CodeMirror from '../../../lib/codemirror';

export default class UNITADE_VIEW extends TextFileView {
private _codemirror: CodeMirror.Editor;

private _editor: CodeMirror.Editor;
private _extension: string = '';

public get editor(): CodeMirror.Editor {
return this._editor;
}
public get extension(): string {
return this._extension;
}

constructor(leaf: WorkspaceLeaf, extension: string) {
super(leaf);

this._extension = extension;


this._codemirror = CodeMirror(this.contentEl, {
this._editor = CodeMirror(this.contentEl, {
theme: 'obsidian',
});

this._codemirror.on('changes', this.onChange);
this._editor.on('changes', this.onChange);
}

onResize(): void {
this._codemirror.refresh();
this._editor.refresh();
}

onChange = async () => {
this.requestSave();
}

getViewData(): string {
return this._codemirror.getValue();
return this._editor.getValue();
}

setViewData(data: string, clear: boolean): void {
if (clear)
this._codemirror.swapDoc(CodeMirror.Doc(data, `text/x-${this._extension}`));
this._editor.swapDoc(CodeMirror.Doc(data, `text/x-${this._extension}`));
else
this._codemirror.setValue(data);
this._editor.setValue(data);
}

clear(): void {
this._codemirror.setValue('');
this._codemirror.clearHistory();
this._editor.setValue('');
this._editor.clearHistory();
}

async onOpen(): Promise<void> {
super.onOpen();
}

async onClose(): Promise<void> {
super.onClose();

this.clear();
}

getDisplayText(): string {
Expand Down
Loading
Loading