Move editor into Electron shell

This commit is contained in:
Jonatan Heyman 2023-01-12 18:55:55 +01:00
parent ce531aa854
commit fc8c4a55a0
53 changed files with 5143 additions and 1562 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +0,0 @@
{
"name": "heynote-codemirror",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c",
"watch": "rollup -c -w",
"build_grammar": "lezer-generator src/lang-heynote/heynote.grammar -o src/lang-heynote/parser.js"
},
"keywords": [],
"author": "",
"license": "",
"dependencies": {
"@codemirror/commands": "^6.1.2",
"@codemirror/lang-html": "^6.4.0",
"@codemirror/lang-java": "^6.0.1",
"@codemirror/lang-javascript": "^6.1.2",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-lezer": "^6.0.1",
"@codemirror/lang-markdown": "^6.0.5",
"@codemirror/lang-php": "^6.0.1",
"@codemirror/lang-python": "^6.1.1",
"@codemirror/lang-sql": "^6.3.3",
"@codemirror/rangeset": "^0.19.9",
"@codemirror/search": "^6.2.3",
"@lezer/generator": "^1.1.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"codemirror": "^6.0.1",
"highlight.js": "^11.7.0",
"rollup": "^3.8.1",
"rollup-plugin-typescript2": "^0.34.1",
"typescript": "^4.9.4"
}
}

View File

@ -1,31 +0,0 @@
//import typescript from 'rollup-plugin-typescript2'
import { nodeResolve } from "@rollup/plugin-node-resolve"
//import { lezer } from "@lezer/generator/rollup"
export default {
input: "./src/index.js",
output: {
file: "./src/bundle.js",
format: "iife",
//sourceMap: "inline",
//globals: {
// //
//},
},
plugins: [
// typescript({
// check: false,
// tsconfigOverride: {
// compilerOptions: {
// lib: ['es5', 'es6'],
// sourceMap: true,
// target: 'es6',
// strict: false
// }
// }
// }),
nodeResolve(),
//lezer(),
]
}

View File

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Heynote</title>
<link rel=stylesheet href="styles.css">
</head>
<body>
<div id="editor"></div>
<!--<div id="syntaxTree"></div>-->
<script src="bundle.js"></script>
</body>
</html>

View File

@ -0,0 +1,80 @@
"use strict";
const electron = require("electron");
const node_os = require("node:os");
const node_path = require("node:path");
process.env.DIST_ELECTRON = node_path.join(__dirname, "..");
process.env.DIST = node_path.join(process.env.DIST_ELECTRON, "../dist");
process.env.PUBLIC = process.env.VITE_DEV_SERVER_URL ? node_path.join(process.env.DIST_ELECTRON, "../public") : process.env.DIST;
if (node_os.release().startsWith("6.1"))
electron.app.disableHardwareAcceleration();
if (process.platform === "win32")
electron.app.setAppUserModelId(electron.app.getName());
if (!electron.app.requestSingleInstanceLock()) {
electron.app.quit();
process.exit(0);
}
let win = null;
const preload = node_path.join(__dirname, "../preload/index.js");
const url = process.env.VITE_DEV_SERVER_URL;
const indexHtml = node_path.join(process.env.DIST, "index.html");
async function createWindow() {
win = new electron.BrowserWindow({
title: "Main window",
icon: node_path.join(process.env.PUBLIC, "favicon.ico"),
webPreferences: {
preload,
nodeIntegration: true,
contextIsolation: false
}
});
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(url);
win.webContents.openDevTools();
} else {
win.loadFile(indexHtml);
}
win.webContents.on("did-finish-load", () => {
win == null ? void 0 : win.webContents.send("main-process-message", new Date().toLocaleString());
});
win.webContents.setWindowOpenHandler(({ url: url2 }) => {
if (url2.startsWith("https:"))
electron.shell.openExternal(url2);
return { action: "deny" };
});
}
electron.app.whenReady().then(createWindow);
electron.app.on("window-all-closed", () => {
win = null;
if (process.platform !== "darwin")
electron.app.quit();
});
electron.app.on("second-instance", () => {
if (win) {
if (win.isMinimized())
win.restore();
win.focus();
}
});
electron.app.on("activate", () => {
const allWindows = electron.BrowserWindow.getAllWindows();
if (allWindows.length) {
allWindows[0].focus();
} else {
createWindow();
}
});
electron.ipcMain.handle("open-win", (_, arg) => {
const childWindow = new electron.BrowserWindow({
webPreferences: {
preload,
nodeIntegration: true,
contextIsolation: false
}
});
if (process.env.VITE_DEV_SERVER_URL) {
childWindow.loadURL(`${url}#${arg}`);
} else {
childWindow.loadFile(indexHtml, { hash: arg });
}
});
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,79 @@
"use strict";
function domReady(condition = ["complete", "interactive"]) {
return new Promise((resolve) => {
if (condition.includes(document.readyState)) {
resolve(true);
} else {
document.addEventListener("readystatechange", () => {
if (condition.includes(document.readyState)) {
resolve(true);
}
});
}
});
}
const safeDOM = {
append(parent, child) {
if (!Array.from(parent.children).find((e) => e === child)) {
return parent.appendChild(child);
}
},
remove(parent, child) {
if (Array.from(parent.children).find((e) => e === child)) {
return parent.removeChild(child);
}
}
};
function useLoading() {
const className = `loaders-css__square-spin`;
const styleContent = `
@keyframes square-spin {
25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg); }
75% { transform: perspective(100px) rotateX(0) rotateY(180deg); }
100% { transform: perspective(100px) rotateX(0) rotateY(0); }
}
.${className} > div {
animation-fill-mode: both;
width: 50px;
height: 50px;
background: #fff;
animation: square-spin 3s 0s cubic-bezier(0.09, 0.57, 0.49, 0.9) infinite;
}
.app-loading-wrap {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #282c34;
z-index: 9;
}
`;
const oStyle = document.createElement("style");
const oDiv = document.createElement("div");
oStyle.id = "app-loading-style";
oStyle.innerHTML = styleContent;
oDiv.className = "app-loading-wrap";
oDiv.innerHTML = `<div class="${className}"><div></div></div>`;
return {
appendLoading() {
safeDOM.append(document.head, oStyle);
safeDOM.append(document.body, oDiv);
},
removeLoading() {
safeDOM.remove(document.head, oStyle);
safeDOM.remove(document.body, oDiv);
}
};
}
const { appendLoading, removeLoading } = useLoading();
domReady().then(appendLoading);
window.onmessage = (ev) => {
ev.data.payload === "removeLoading" && removeLoading();
};
setTimeout(removeLoading, 4999);
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../electron/preload/index.ts"],"sourcesContent":["function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {\n return new Promise((resolve) => {\n if (condition.includes(document.readyState)) {\n resolve(true)\n } else {\n document.addEventListener('readystatechange', () => {\n if (condition.includes(document.readyState)) {\n resolve(true)\n }\n })\n }\n })\n}\n\nconst safeDOM = {\n append(parent: HTMLElement, child: HTMLElement) {\n if (!Array.from(parent.children).find(e => e === child)) {\n return parent.appendChild(child)\n }\n },\n remove(parent: HTMLElement, child: HTMLElement) {\n if (Array.from(parent.children).find(e => e === child)) {\n return parent.removeChild(child)\n }\n },\n}\n\n/**\n * https://tobiasahlin.com/spinkit\n * https://connoratherton.com/loaders\n * https://projects.lukehaas.me/css-loaders\n * https://matejkustec.github.io/SpinThatShit\n */\nfunction useLoading() {\n const className = `loaders-css__square-spin`\n const styleContent = `\n@keyframes square-spin {\n 25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }\n 50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg); }\n 75% { transform: perspective(100px) rotateX(0) rotateY(180deg); }\n 100% { transform: perspective(100px) rotateX(0) rotateY(0); }\n}\n.${className} > div {\n animation-fill-mode: both;\n width: 50px;\n height: 50px;\n background: #fff;\n animation: square-spin 3s 0s cubic-bezier(0.09, 0.57, 0.49, 0.9) infinite;\n}\n.app-loading-wrap {\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n background: #282c34;\n z-index: 9;\n}\n `\n const oStyle = document.createElement('style')\n const oDiv = document.createElement('div')\n\n oStyle.id = 'app-loading-style'\n oStyle.innerHTML = styleContent\n oDiv.className = 'app-loading-wrap'\n oDiv.innerHTML = `<div class=\"${className}\"><div></div></div>`\n\n return {\n appendLoading() {\n safeDOM.append(document.head, oStyle)\n safeDOM.append(document.body, oDiv)\n },\n removeLoading() {\n safeDOM.remove(document.head, oStyle)\n safeDOM.remove(document.body, oDiv)\n },\n }\n}\n\n// ----------------------------------------------------------------------\n\nconst { appendLoading, removeLoading } = useLoading()\ndomReady().then(appendLoading)\n\nwindow.onmessage = (ev) => {\n ev.data.payload === 'removeLoading' && removeLoading()\n}\n\nsetTimeout(removeLoading, 4999)\n"],"names":[],"mappings":";AAAA,SAAS,SAAS,YAAkC,CAAC,YAAY,aAAa,GAAG;AACxE,SAAA,IAAI,QAAQ,CAAC,YAAY;AAC9B,QAAI,UAAU,SAAS,SAAS,UAAU,GAAG;AAC3C,cAAQ,IAAI;AAAA,IAAA,OACP;AACI,eAAA,iBAAiB,oBAAoB,MAAM;AAClD,YAAI,UAAU,SAAS,SAAS,UAAU,GAAG;AAC3C,kBAAQ,IAAI;AAAA,QACd;AAAA,MAAA,CACD;AAAA,IACH;AAAA,EAAA,CACD;AACH;AAEA,MAAM,UAAU;AAAA,EACd,OAAO,QAAqB,OAAoB;AAC1C,QAAA,CAAC,MAAM,KAAK,OAAO,QAAQ,EAAE,KAAK,CAAA,MAAK,MAAM,KAAK,GAAG;AAChD,aAAA,OAAO,YAAY,KAAK;AAAA,IACjC;AAAA,EACF;AAAA,EACA,OAAO,QAAqB,OAAoB;AAC1C,QAAA,MAAM,KAAK,OAAO,QAAQ,EAAE,KAAK,CAAA,MAAK,MAAM,KAAK,GAAG;AAC/C,aAAA,OAAO,YAAY,KAAK;AAAA,IACjC;AAAA,EACF;AACF;AAQA,SAAS,aAAa;AACpB,QAAM,YAAY;AAClB,QAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAOpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBK,QAAA,SAAS,SAAS,cAAc,OAAO;AACvC,QAAA,OAAO,SAAS,cAAc,KAAK;AAEzC,SAAO,KAAK;AACZ,SAAO,YAAY;AACnB,OAAK,YAAY;AACjB,OAAK,YAAY,eAAe;AAEzB,SAAA;AAAA,IACL,gBAAgB;AACN,cAAA,OAAO,SAAS,MAAM,MAAM;AAC5B,cAAA,OAAO,SAAS,MAAM,IAAI;AAAA,IACpC;AAAA,IACA,gBAAgB;AACN,cAAA,OAAO,SAAS,MAAM,MAAM;AAC5B,cAAA,OAAO,SAAS,MAAM,IAAI;AAAA,IACpC;AAAA,EAAA;AAEJ;AAIA,MAAM,EAAE,eAAe,kBAAkB;AACzC,WAAW,KAAK,aAAa;AAE7B,OAAO,YAAY,CAAC,OAAO;AACtB,KAAA,KAAK,YAAY,mBAAmB,cAAc;AACvD;AAEA,WAAW,eAAe,IAAI;"}

View File

@ -0,0 +1,38 @@
/**
* @see https://www.electron.build/configuration/configuration
*/
{
"appId": "YourAppID",
"asar": true,
"icon": "public/favicon.ico",
"directories": {
"output": "release/${version}"
},
"files": [
"dist-electron",
"dist"
],
"mac": {
"artifactName": "${productName}_${version}.${ext}",
"target": [
"dmg"
]
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
],
"artifactName": "${productName}_${version}.${ext}"
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false
}
}

View File

@ -0,0 +1,11 @@
/// <reference types="vite-plugin-electron/electron-env" />
declare namespace NodeJS {
interface ProcessEnv {
VSCODE_DEBUG?: 'true'
DIST_ELECTRON: string
DIST: string
/** /dist/ or /public/ */
PUBLIC: string
}
}

View File

@ -0,0 +1,117 @@
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { release } from 'node:os'
import { join } from 'node:path'
// The built directory structure
//
// ├─┬ dist-electron
// │ ├─┬ main
// │ │ └── index.js > Electron-Main
// │ └─┬ preload
// │ └── index.js > Preload-Scripts
// ├─┬ dist
// │ └── index.html > Electron-Renderer
//
process.env.DIST_ELECTRON = join(__dirname, '..')
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist')
process.env.PUBLIC = process.env.VITE_DEV_SERVER_URL
? join(process.env.DIST_ELECTRON, '../public')
: process.env.DIST
// Disable GPU Acceleration for Windows 7
if (release().startsWith('6.1')) app.disableHardwareAcceleration()
// Set application name for Windows 10+ notifications
if (process.platform === 'win32') app.setAppUserModelId(app.getName())
if (!app.requestSingleInstanceLock()) {
app.quit()
process.exit(0)
}
// Remove electron security warnings
// This warning only shows in development mode
// Read more on https://www.electronjs.org/docs/latest/tutorial/security
// process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
let win: BrowserWindow | null = null
// Here, you can also use other preload
const preload = join(__dirname, '../preload/index.js')
const url = process.env.VITE_DEV_SERVER_URL
const indexHtml = join(process.env.DIST, 'index.html')
async function createWindow() {
win = new BrowserWindow({
title: 'Main window',
icon: join(process.env.PUBLIC, 'favicon.ico'),
//titleBarStyle: 'customButtonsOnHover',
webPreferences: {
preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
// Consider using contextBridge.exposeInMainWorld
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
nodeIntegration: true,
contextIsolation: false,
},
})
if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298
win.loadURL(url)
// Open devTool if the app is not packaged
win.webContents.openDevTools()
} else {
win.loadFile(indexHtml)
}
// Test actively push message to the Electron-Renderer
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', new Date().toLocaleString())
})
// Make all links open with the browser, not with the application
win.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith('https:')) shell.openExternal(url)
return { action: 'deny' }
})
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
win = null
if (process.platform !== 'darwin') app.quit()
})
app.on('second-instance', () => {
if (win) {
// Focus on the main window if the user tried to open another
if (win.isMinimized()) win.restore()
win.focus()
}
})
app.on('activate', () => {
const allWindows = BrowserWindow.getAllWindows()
if (allWindows.length) {
allWindows[0].focus()
} else {
createWindow()
}
})
// New window example arg: new windows url
ipcMain.handle('open-win', (_, arg) => {
const childWindow = new BrowserWindow({
webPreferences: {
preload,
nodeIntegration: true,
contextIsolation: false,
},
})
if (process.env.VITE_DEV_SERVER_URL) {
childWindow.loadURL(`${url}#${arg}`)
} else {
childWindow.loadFile(indexHtml, { hash: arg })
}
})

View File

@ -0,0 +1,92 @@
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
return new Promise((resolve) => {
if (condition.includes(document.readyState)) {
resolve(true)
} else {
document.addEventListener('readystatechange', () => {
if (condition.includes(document.readyState)) {
resolve(true)
}
})
}
})
}
const safeDOM = {
append(parent: HTMLElement, child: HTMLElement) {
if (!Array.from(parent.children).find(e => e === child)) {
return parent.appendChild(child)
}
},
remove(parent: HTMLElement, child: HTMLElement) {
if (Array.from(parent.children).find(e => e === child)) {
return parent.removeChild(child)
}
},
}
/**
* https://tobiasahlin.com/spinkit
* https://connoratherton.com/loaders
* https://projects.lukehaas.me/css-loaders
* https://matejkustec.github.io/SpinThatShit
*/
function useLoading() {
const className = `loaders-css__square-spin`
const styleContent = `
@keyframes square-spin {
25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg); }
75% { transform: perspective(100px) rotateX(0) rotateY(180deg); }
100% { transform: perspective(100px) rotateX(0) rotateY(0); }
}
.${className} > div {
animation-fill-mode: both;
width: 50px;
height: 50px;
background: #fff;
animation: square-spin 3s 0s cubic-bezier(0.09, 0.57, 0.49, 0.9) infinite;
}
.app-loading-wrap {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #282c34;
z-index: 9;
}
`
const oStyle = document.createElement('style')
const oDiv = document.createElement('div')
oStyle.id = 'app-loading-style'
oStyle.innerHTML = styleContent
oDiv.className = 'app-loading-wrap'
oDiv.innerHTML = `<div class="${className}"><div></div></div>`
return {
appendLoading() {
safeDOM.append(document.head, oStyle)
safeDOM.append(document.body, oDiv)
},
removeLoading() {
safeDOM.remove(document.head, oStyle)
safeDOM.remove(document.body, oDiv)
},
}
}
// ----------------------------------------------------------------------
const { appendLoading, removeLoading } = useLoading()
domReady().then(appendLoading)
window.onmessage = (ev) => {
ev.data.payload === 'removeLoading' && removeLoading()
}
setTimeout(removeLoading, 4999)

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<title>heynote</title>
<link rel="stylesheet" href="/src/editor/styles.css" />
</head>
<body>
<div id="editor" style="width:100%; height:100%;"></div>
<!--<div id="app"></div>-->
<!--<script type="module" src="/src/main.ts"></script>-->
<script type="module" src="/src/editor/index.js"></script>
</body>
</html>

4319
heynote-electron/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
{
"name": "electron-vue-vite",
"version": "2.0.0",
"main": "dist-electron/main/index.js",
"description": "Really simple Electron + Vue + Vite boilerplate.",
"author": "草鞋没号 <308487730@qq.com>",
"license": "MIT",
"private": true,
"keywords": [
"electron",
"rollup",
"vite",
"vue3",
"vue"
],
"debug": {
"env": {
"VITE_DEV_SERVER_URL": "http://127.0.0.1:3344/"
}
},
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build && electron-builder",
"preview": "vite preview"
},
"devDependencies": {
"@codemirror/commands": "^6.1.2",
"@codemirror/lang-html": "^6.4.0",
"@codemirror/lang-java": "^6.0.1",
"@codemirror/lang-javascript": "^6.1.2",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-lezer": "^6.0.1",
"@codemirror/lang-markdown": "^6.0.5",
"@codemirror/lang-php": "^6.0.1",
"@codemirror/lang-python": "^6.1.1",
"@codemirror/lang-sql": "^6.3.3",
"@codemirror/rangeset": "^0.19.9",
"@codemirror/search": "^6.2.3",
"@lezer/generator": "^1.1.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@vitejs/plugin-vue": "^4.0.0",
"codemirror": "^6.0.1",
"electron": "^22.0.0",
"electron-builder": "^22.10.3",
"typescript": "^4.9.4",
"vite": "^4.0.3",
"vite-plugin-electron": "^0.11.1",
"vite-plugin-electron-renderer": "^0.11.3",
"vue": "^3.2.45",
"vue-tsc": "^1.0.16"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="216" height="216" viewBox="0 0 216 216"><path fill="#80bd01" d="M104.6 180.7c-2 0-3.9-.5-5.7-1.5l-18.1-10.7c-2.7-1.5-1.4-2-.5-2.4 3.6-1.2 4.3-1.5 8.2-3.7.4-.2.9-.1 1.3.1l13.9 8.2c.5.3 1.2.3 1.7 0l54.1-31.2c.5-.3.8-.9.8-1.5V75.7c0-.6-.3-1.2-.8-1.5l-54-31.2c-.5-.3-1.2-.3-1.7 0l-54 31.2c-.5.3-.9.9-.9 1.5v62.4c0 .6.3 1.2.9 1.4l14.8 8.6c8 4 13-.7 13-5.5V81c0-.9.7-1.6 1.6-1.6h6.9c.9 0 1.6.7 1.6 1.6v61.6c0 10.7-5.8 16.9-16 16.9-3.1 0-5.6 0-12.5-3.4L44.8 148c-3.5-2-5.7-5.8-5.7-9.9V75.7c0-4.1 2.2-7.8 5.7-9.9l54.1-31.2c3.4-1.9 8-1.9 11.4 0l54.1 31.2c3.5 2 5.7 5.8 5.7 9.9v62.4c0 4.1-2.2 7.8-5.7 9.9l-54.1 31.2c-1.8 1-3.7 1.5-5.7 1.5zm43.6-61.5c0-11.7-7.9-14.8-24.5-17-16.8-2.2-18.5-3.4-18.5-7.3 0-3.2 1.4-7.6 13.9-7.6 11.1 0 15.2 2.4 16.9 9.9.1.7.8 1.2 1.5 1.2h7c.4 0 .8-.2 1.1-.5.3-.3.5-.8.4-1.2-1.1-12.9-9.7-18.9-27-18.9-15.4 0-24.6 6.5-24.6 17.4 0 11.8 9.1 15.1 23.9 16.6 17.7 1.7 19.1 4.3 19.1 7.8 0 6-4.8 8.6-16.2 8.6-14.3 0-17.5-3.6-18.5-10.7-.1-.8-.8-1.3-1.6-1.3h-7c-.9 0-1.6.7-1.6 1.6 0 9.1 5 20 28.6 20 17.3-.1 27.1-6.8 27.1-18.6zM172 55.9V57h3v8h1.2v-8h3.1v-1.1H172zm8.4 9.1h1.2v-7.6l2.6 7.6h1.2l2.6-7.6V65h1.2v-9h-1.7l-2.6 7.6-2.6-7.6h-1.8v9z"/></svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,51 @@
<script setup lang="ts">
import HelloWorld from './components/HelloWorld.vue'
console.log("[App.vue]", `Hello world from Electron ${process.versions.electron}!`)
</script>
<template>
<div>
<a href="https://www.electronjs.org/" target="_blank">
<img src="./assets/electron.svg" class="logo electron" alt="Electron logo" />
</a>
<a href="https://vitejs.dev/" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
</a>
<a href="https://vuejs.org/" target="_blank">
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
</a>
</div>
<HelloWorld msg="Electron + Vite + Vue" />
<div class="flex-center">
Place static files into the <code>/public</code> folder
<img style="width:5em;" src="/node.svg" alt="Node logo">
</div>
</template>
<style>
.flex-center {
display: flex;
align-items: center;
justify-content: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo.electron:hover {
filter: drop-shadow(0 0 2em #9FEAF9);
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
filter: drop-shadow(0 0 2em #42b883aa);
}
</style>

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256"><g fill="none" fill-rule="evenodd"><circle fill="#2B2E3A" cx="128" cy="128" r="128"/><g fill="#9FEAF9" fill-rule="nonzero"><path d="M100.502 71.69c-26.005-4.736-46.567.221-54.762 14.415-6.115 10.592-4.367 24.635 4.24 39.646a2.667 2.667 0 1 0 4.626-2.653c-7.752-13.522-9.261-25.641-4.247-34.326 6.808-11.791 25.148-16.213 49.187-11.835a2.667 2.667 0 0 0 .956-5.247zm-36.999 72.307c10.515 11.555 24.176 22.394 39.756 31.388 37.723 21.78 77.883 27.601 97.675 14.106a2.667 2.667 0 1 0-3.005-4.406c-17.714 12.078-55.862 6.548-92.003-14.318-15.114-8.726-28.343-19.222-38.478-30.36a2.667 2.667 0 1 0-3.945 3.59z"/><path d="M194.62 140.753c17.028-20.116 22.973-40.348 14.795-54.512-6.017-10.423-18.738-15.926-35.645-16.146a2.667 2.667 0 0 0-.069 5.333c15.205.198 26.165 4.939 31.096 13.48 6.792 11.765 1.49 29.807-14.248 48.399a2.667 2.667 0 1 0 4.071 3.446zm-43.761-68.175c-15.396 3.299-31.784 9.749-47.522 18.835-38.942 22.483-64.345 55.636-60.817 79.675a2.667 2.667 0 1 0 5.277-.775c-3.133-21.344 20.947-52.769 58.207-74.281 15.267-8.815 31.135-15.06 45.972-18.239a2.667 2.667 0 1 0-1.117-5.215z"/><path d="M87.77 187.753c8.904 24.86 23.469 40.167 39.847 40.167 11.945 0 22.996-8.143 31.614-22.478a2.667 2.667 0 1 0-4.571-2.748c-7.745 12.883-17.258 19.892-27.043 19.892-13.605 0-26.596-13.652-34.825-36.63a2.667 2.667 0 1 0-5.021 1.797zm81.322-4.863c4.61-14.728 7.085-31.718 7.085-49.423 0-44.179-15.463-82.263-37.487-92.042a2.667 2.667 0 0 0-2.164 4.874c19.643 8.723 34.317 44.866 34.317 87.168 0 17.177-2.397 33.63-6.84 47.83a2.667 2.667 0 1 0 5.09 1.593zm50.224-2.612c0-7.049-5.714-12.763-12.763-12.763-7.049 0-12.763 5.714-12.763 12.763 0 7.049 5.714 12.763 12.763 12.763 7.049 0 12.763-5.714 12.763-12.763zm-5.333 0a7.43 7.43 0 1 1-14.86 0 7.43 7.43 0 0 1 14.86 0zM48.497 193.041c7.05 0 12.764-5.714 12.764-12.763 0-7.049-5.715-12.763-12.764-12.763-7.048 0-12.763 5.714-12.763 12.763 0 7.049 5.715 12.763 12.763 12.763zm0-5.333a7.43 7.43 0 1 1 0-14.86 7.43 7.43 0 0 1 0 14.86z"/><path d="M127.617 54.444c7.049 0 12.763-5.714 12.763-12.763 0-7.049-5.714-12.763-12.763-12.763-7.049 0-12.763 5.714-12.763 12.763 0 7.049 5.714 12.763 12.763 12.763zm0-5.333a7.43 7.43 0 1 1 0-14.86 7.43 7.43 0 0 1 0 14.86zm1.949 93.382c-4.985 1.077-9.896-2.091-10.975-7.076a9.236 9.236 0 0 1 7.076-10.976c4.985-1.077 9.896 2.091 10.976 7.076 1.077 4.985-2.091 9.897-7.077 10.976z"/></g></g></svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

View File

@ -0,0 +1,38 @@
<script setup lang="ts">
import { ref } from 'vue'
defineProps<{ msg: string }>()
const count = ref(0)
</script>
<template>
<h1>{{ msg }}</h1>
<div class="card">
<button type="button" @click="count++">count is {{ count }}</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test HMR
</p>
</div>
<p>
Check out
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
>create-vue</a
>, the official Vue + Vite starter
</p>
<p>
Install
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
in your IDE for a better DX
</p>
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
</template>
<style scoped>
.read-the-docs {
color: #888;
}
</style>

View File

@ -241,6 +241,20 @@ const preventSelectionBeforeFirstBlock = EditorState.transactionFilter.of((tr) =
})
const blockLineNumbers = lineNumbers({
formatNumber(lineNo, state) {
if (state.doc.lines >= lineNo) {
const lineOffset = state.doc.line(lineNo).from
const block = state.facet(blockState).find(block => block.content.from <= lineOffset && block.content.to >= lineOffset)
if (block) {
const firstBlockLine = state.doc.lineAt(block.content.from).number
return lineNo - firstBlockLine + 1
}
}
return ""
}
})
export const noteBlockExtension = () => {
return [
blockState,
@ -249,18 +263,6 @@ export const noteBlockExtension = () => {
blockLayer,
preventFirstBlockFromBeingDeleted,
preventSelectionBeforeFirstBlock,
lineNumbers({
formatNumber(lineNo, state) {
if (state.doc.lines >= lineNo) {
const lineOffset = state.doc.line(lineNo).from
const block = state.facet(blockState).find(block => block.content.from <= lineOffset && block.content.to >= lineOffset)
if (block) {
const firstBlockLine = state.doc.lineAt(block.content.from).number
return lineNo - firstBlockLine + 1
}
}
return ""
}
}),
blockLineNumbers,
]
}

View File

@ -11,7 +11,7 @@ export function languageDetection(getView) {
const previousBlockContent = []
let idleCallbackId = null
const detectionWorker = new Worker('language-detection/worker.js');
const detectionWorker = new Worker('/src/editor/language-detection/worker.js');
detectionWorker.onmessage = (event) => {
//console.log("event:", event.data)
if (!event.data.highlightjs.language) {

View File

@ -1,8 +1,11 @@
importScripts("/public/highlight.min.js")
const HIGHLIGHTJS_LANGUAGES = ["json", "python", "javascript", "html", "sql", "java", "plaintext"]
onmessage = (event) => {
//console.log("worker received message:", event.data)
importScripts("../../lib/highlight.min.js")
//importScripts("../../lib/highlight.min.js")
const result = self.hljs.highlightAuto(event.data.content, HIGHLIGHTJS_LANGUAGES);
postMessage({
highlightjs: {

View File

@ -0,0 +1,10 @@
import { createApp } from 'vue'
import "./style.css"
import App from './App.vue'
import './samples/node-api'
createApp(App)
.mount('#app')
.$nextTick(() => {
postMessage({ payload: 'removeLoading' }, '*')
})

View File

@ -0,0 +1,13 @@
import { lstat } from 'node:fs/promises'
import { cwd } from 'node:process'
import { ipcRenderer } from 'electron'
ipcRenderer.on('main-process-message', (_event, ...args) => {
console.log('[Receive Main-process message]:', ...args)
})
lstat(cwd()).then(stats => {
console.log('[fs.lstat]', stats)
}).catch(err => {
console.error(err)
})

View File

@ -0,0 +1,91 @@
:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
code {
background-color: #1a1a1a;
padding: 2px 4px;
margin: 0 4px;
border-radius: 4px;
}
.card {
padding: 2em;
}
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
code {
background-color: #f9f9f9;
}
}

7
heynote-electron/src/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}

View File

@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"moduleResolution": "Node",
"strict": true,
"jsx": "preserve",
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"noEmit": true
},
"include": ["src"],
"references": [
{ "path": "./tsconfig.node.json" }
]
}

View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts", "package.json", "electron"]
}

View File

@ -0,0 +1,71 @@
import { rmSync } from 'node:fs'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'
import pkg from './package.json'
rmSync('dist-electron', { recursive: true, force: true })
const isDevelopment = process.env.NODE_ENV === "development" || !!process.env.VSCODE_DEBUG
const isProduction = process.env.NODE_ENV === "production"
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
electron([
{
// Main-Process entry file of the Electron App.
entry: 'electron/main/index.ts',
onstart(options) {
if (process.env.VSCODE_DEBUG) {
console.log(/* For `.vscode/.debug.script.mjs` */'[startup] Electron App')
} else {
options.startup()
}
},
vite: {
build: {
sourcemap: isDevelopment,
minify: isProduction,
outDir: 'dist-electron/main',
rollupOptions: {
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {}),
},
},
},
},
{
entry: 'electron/preload/index.ts',
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
options.reload()
},
vite: {
build: {
sourcemap: isDevelopment,
minify: isProduction,
outDir: 'dist-electron/preload',
rollupOptions: {
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {}),
},
},
},
}
]),
// Use Node.js API in the Renderer-process
renderer({
nodeIntegration: true,
}),
],
server: !!process.env.VSCODE_DEBUG ? (() => {
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL)
return {
host: url.hostname,
port: +url.port,
}
})() : undefined,
clearScreen: false,
})