diff --git a/extension/package.json b/extension/package.json index bc00ac7..55458e2 100644 --- a/extension/package.json +++ b/extension/package.json @@ -1,381 +1,387 @@ { - "name": "excalidraw-editor", - "icon": "assets/images/logo.png", - "displayName": "Excalidraw", - "description": "Draw schemas in VS Code using Excalidraw", - "version": "3.7.4", - "publisher": "pomdtr", - "engines": { - "vscode": "^1.63.0" - }, - "categories": [ - "Visualization" - ], - "keywords": [ - "draw", - "schemas", - "graphics", - "paint", - "excalidraw" - ], - "author": { - "name": "pomdtr", - "email": "achille.lacoin@gmail.com", - "url": "https://github.com/pomdtr" - }, - "activationEvents": [ - "workspaceContains:**/*.{excalidraw,excalidraw.svg,excalidraw.png}", - "onCustomEditor:editor.excalidraw" + "name": "excalidraw-editor", + "icon": "assets/images/logo.png", + "displayName": "Excalidraw", + "description": "Draw schemas in VS Code using Excalidraw", + "version": "3.7.4", + "publisher": "pomdtr", + "engines": { + "vscode": "^1.63.0" + }, + "categories": [ + "Visualization" + ], + "keywords": [ + "draw", + "schemas", + "graphics", + "paint", + "excalidraw" + ], + "author": { + "name": "pomdtr", + "email": "achille.lacoin@gmail.com", + "url": "https://github.com/pomdtr" + }, + "activationEvents": [ + "workspaceContains:**/*.{excalidraw,excalidraw.svg,excalidraw.png}", + "onCustomEditor:editor.excalidraw", + "onCommand:editor.excalidraw.newDiagram" + ], + "repository": { + "type": "git", + "url": "https://github.com/excalidraw/excalidraw-vscode/tree/master/extension" + }, + "browser": "./dist/extension.js", + "contributes": { + "commands": [ + { + "command": "excalidraw.updateTheme", + "category": "Excalidraw", + "title": "Color Theme", + "icon": "$(color-mode)" + }, + { + "command": "excalidraw.preventDefault", + "category": "Excalidraw", + "title": "Prevent Default" + }, + { + "command": "excalidraw.showSource", + "category": "Excalidraw", + "title": "Open Source", + "icon": "$(go-to-file)" + }, + { + "command": "excalidraw.showEditor", + "category": "Excalidraw", + "title": "Open Excalidraw", + "icon": { + "dark": "./assets/images/menu-icon-dark.png", + "light": "./assets/images/menu-icon-light.png" + } + }, + { + "command": "excalidraw.showImage", + "category": "Excalidraw", + "title": "Open Image", + "icon": "$(go-to-file)" + }, + { + "command": "excalidraw.showSourceToSide", + "category": "Excalidraw", + "title": "Open Source to the Side", + "icon": "$(go-to-file)" + }, + { + "command": "excalidraw.showEditorToSide", + "category": "Excalidraw", + "title": "Open Excalidraw to the Side", + "icon": { + "dark": "./assets/menu-icon-dark.png", + "light": "./assets/menu-icon-light.png" + } + }, + { + "command": "excalidraw.showImageToSide", + "category": "Excalidraw", + "title": "Open Image to the Side", + "icon": "$(go-to-file)" + }, + { + "command": "excalidraw.newDiagram", + "title": "New Excalidraw Diagram", + "category": "Excalidraw" + } ], - "repository": { - "type": "git", - "url": "https://github.com/excalidraw/excalidraw-vscode/tree/master/extension" - }, - "browser": "./dist/extension.js", - "contributes": { - "commands": [ - { - "command": "excalidraw.updateTheme", - "category": "Excalidraw", - "title": "Color Theme", - "icon": "$(color-mode)" - }, - { - "command": "excalidraw.preventDefault", - "category": "Excalidraw", - "title": "Prevent Default" - }, - { - "command": "excalidraw.showSource", - "category": "Excalidraw", - "title": "Open Source", - "icon": "$(go-to-file)" - }, - { - "command": "excalidraw.showEditor", - "category": "Excalidraw", - "title": "Open Excalidraw", - "icon": { - "dark": "./assets/images/menu-icon-dark.png", - "light": "./assets/images/menu-icon-light.png" - } - }, - { - "command": "excalidraw.showImage", - "category": "Excalidraw", - "title": "Open Image", - "icon": "$(go-to-file)" - }, - { - "command": "excalidraw.showSourceToSide", - "category": "Excalidraw", - "title": "Open Source to the Side", - "icon": "$(go-to-file)" - }, - { - "command": "excalidraw.showEditorToSide", - "category": "Excalidraw", - "title": "Open Excalidraw to the Side", - "icon": { - "dark": "./assets/menu-icon-dark.png", - "light": "./assets/menu-icon-light.png" - } - }, - { - "command": "excalidraw.showImageToSide", - "category": "Excalidraw", - "title": "Open Image to the Side", - "icon": "$(go-to-file)" - } - ], - "configuration": [ - { - "title": "Excalidraw", - "properties": { - "excalidraw.theme": { - "description": "Excalidraw theme. Use auto to sync theme with VSCode color theme.", - "type": "string", - "default": "light", - "enum": [ - "auto", - "light", - "dark" - ] - }, - "excalidraw.language": { - "type": "string", - "description": "Language of the Excalidraw Editor. Defauts to the VS Code display language.", - "enum": [ - "en", - "ar-SA", - "bg-BG", - "ca-ES", - "cs-CZ", - "de-DE", - "el-GR", - "es-ES", - "eu-ES", - "fa-IR", - "fi-FI", - "fr-FR", - "he-IL", - "hi-IN", - "hu-HU", - "id-ID", - "it-IT", - "ja-JP", - "kab-KAB", - "kk-KZ", - "ko-KR", - "lt-LT", - "lv-LV", - "my-MM", - "nb-NO", - "nl-NL", - "nn-NO", - "oc-FR", - "pa-IN", - "pl-PL", - "pt-BR", - "pt-PT", - "ro-RO", - "ru-RU", - "sk-SK", - "sv-SE", - "sl-SI", - "tr-TR", - "uk-UA", - "zh-CN", - "zh-TW", - "vi-VN", - "mr-IN" - ], - "enumDescriptions": [ - "English", - "मराठी", - "Tiếng Việt", - "繁體中文", - "简体中文", - "Українська", - "Türkçe", - "Slovenščina", - "Svenska", - "Slovenčina", - "Русский", - "Română", - "Português", - "Português Brasileiro", - "Polski", - "ਪੰਜਾਬੀ", - "Occitan", - "Norsk nynorsk", - "Nederlands", - "Norsk bokmål", - "Burmese", - "Latviešu", - "Lietuvių", - "한국어", - "Қазақ тілі", - "Taqbaylit", - "日本語", - "Italiano", - "Bahasa Indonesia", - "Magyar", - "हिन्दी", - "עברית", - "Français", - "Suomi", - "فارسی", - "Euskara", - "Español", - "Ελληνικά", - "Deutsch", - "Česky", - "Català", - "Български", - "العربية" - ] - }, - "excalidraw.workspaceLibraryPath": { - "scope": "window", - "description": "Path to the file used to store the excalidraw library (relative to workspace root). If not set, the library will be persisted in the user storage.", - "type": "string" - }, - "excalidraw.image": { - "description": "Settings specifics to image with embed scene.", - "type": "object", - "properties": { - "exportScale": { - "description": "Scale of the exported drawings. Higher values will result in higher quality images.", - "type": "number", - "default": 1, - "enum": [ - 1, - 2, - 3 - ] - }, - "exportWithBackground": { - "description": "Indicates whether background should be exported", - "type": "boolean", - "default": true - }, - "exportWithDarkMode": { - "description": "Indicates whether to export with dark mode", - "type": "boolean", - "default": false - } - }, - "default": { - "exportScale": 1, - "exportWithBackground": true, - "exportWithDarkMode": false - } - } - } - } - ], - "languages": [ - { - "id": "json", - "extensions": [ - ".excalidraw", - ".excalidrawlib" - ] - } - ], - "menus": { - "commandPalette": [ - { - "command": "excalidraw.updateTheme", - "when": "activeCustomEditorId == 'editor.excalidraw'" - }, - { - "command": "excalidraw.preventDefault", - "when": "false" - }, - { - "command": "excalidraw.showSource", - "when": "false" - }, - { - "command": "excalidraw.showEditor", - "when": "false" - }, - { - "command": "excalidraw.showImage", - "when": "false" - }, - { - "command": "excalidraw.showSourceToSide", - "when": "false" - }, - { - "command": "excalidraw.showEditorToSide", - "when": "false" - }, - { - "command": "excalidraw.showImageToSide", - "when": "false" - } + "configuration": [ + { + "title": "Excalidraw", + "properties": { + "excalidraw.theme": { + "description": "Excalidraw theme. Use auto to sync theme with VSCode color theme.", + "type": "string", + "default": "light", + "enum": [ + "auto", + "light", + "dark" + ] + }, + "excalidraw.language": { + "type": "string", + "description": "Language of the Excalidraw Editor. Defauts to the VS Code display language.", + "enum": [ + "en", + "ar-SA", + "bg-BG", + "ca-ES", + "cs-CZ", + "de-DE", + "el-GR", + "es-ES", + "eu-ES", + "fa-IR", + "fi-FI", + "fr-FR", + "he-IL", + "hi-IN", + "hu-HU", + "id-ID", + "it-IT", + "ja-JP", + "kab-KAB", + "kk-KZ", + "ko-KR", + "lt-LT", + "lv-LV", + "my-MM", + "nb-NO", + "nl-NL", + "nn-NO", + "oc-FR", + "pa-IN", + "pl-PL", + "pt-BR", + "pt-PT", + "ro-RO", + "ru-RU", + "sk-SK", + "sv-SE", + "sl-SI", + "tr-TR", + "uk-UA", + "zh-CN", + "zh-TW", + "vi-VN", + "mr-IN" ], - "editor/title": [ - { - "command": "excalidraw.showEditor", - "alt": "excalidraw.showEditorToSide", - "when": "activeCustomEditorId != 'editor.excalidraw' && resourceFilename =~ /^.+\\.excalidraw(.png|.svg)?$/", - "group": "navigation" - }, - { - "command": "excalidraw.showSource", - "alt": "excalidraw.showSourceToSide", - "group": "navigation", - "when": "activeCustomEditorId == 'editor.excalidraw' && resourceFilename =~ /^.+\\.excalidraw(.svg)?$/" - }, - { - "command": "excalidraw.showImage", - "alt": "excalidraw.showImageToSide", - "when": "activeCustomEditorId == 'editor.excalidraw' && resourceFilename =~ /^.+\\.excalidraw.png$/", - "group": "navigation" - }, - { - "command": "excalidraw.updateTheme", - "when": "activeCustomEditorId == 'editor.excalidraw'", - "group": "navigation" - } + "enumDescriptions": [ + "English", + "मराठी", + "Tiếng Việt", + "繁體中文", + "简体中文", + "Українська", + "Türkçe", + "Slovenščina", + "Svenska", + "Slovenčina", + "Русский", + "Română", + "Português", + "Português Brasileiro", + "Polski", + "ਪੰਜਾਬੀ", + "Occitan", + "Norsk nynorsk", + "Nederlands", + "Norsk bokmål", + "Burmese", + "Latviešu", + "Lietuvių", + "한국어", + "Қазақ тілі", + "Taqbaylit", + "日本語", + "Italiano", + "Bahasa Indonesia", + "Magyar", + "हिन्दी", + "עברית", + "Français", + "Suomi", + "فارسی", + "Euskara", + "Español", + "Ελληνικά", + "Deutsch", + "Česky", + "Català", + "Български", + "العربية" ] - }, - "customEditors": [ - { - "viewType": "editor.excalidraw", - "displayName": "Excalidraw", - "priority": "default", - "selector": [ - { - "filenamePattern": "*.excalidraw" - }, - { - "filenamePattern": "*.excalidraw.json" - }, - { - "filenamePattern": "*.excalidraw.svg" - }, - { - "filenamePattern": "*.excalidraw.png" - } + }, + "excalidraw.workspaceLibraryPath": { + "scope": "window", + "description": "Path to the file used to store the excalidraw library (relative to workspace root). If not set, the library will be persisted in the user storage.", + "type": "string" + }, + "excalidraw.image": { + "description": "Settings specifics to image with embed scene.", + "type": "object", + "properties": { + "exportScale": { + "description": "Scale of the exported drawings. Higher values will result in higher quality images.", + "type": "number", + "default": 1, + "enum": [ + 1, + 2, + 3 ] - } - ], - "keybindings": [ - { - "command": "excalidraw.preventDefault", - "key": "ctrl+z", - "mac": "cmd+z", - "when": "activeCustomEditorId == 'editor.excalidraw'" + }, + "exportWithBackground": { + "description": "Indicates whether background should be exported", + "type": "boolean", + "default": true + }, + "exportWithDarkMode": { + "description": "Indicates whether to export with dark mode", + "type": "boolean", + "default": false + } }, - { - "command": "excalidraw.preventDefault", - "key": "ctrl+y", - "mac": "cmd+shift+z", - "when": "activeCustomEditorId == 'editor.excalidraw'" + "default": { + "exportScale": 1, + "exportWithBackground": true, + "exportWithDarkMode": false } + } + } + } + ], + "languages": [ + { + "id": "json", + "extensions": [ + ".excalidraw", + ".excalidrawlib" ] - }, - "scripts": { - "install": "cd ../webview && npm install", - "vscode:prepublish": "npm run package", - "package": "npm run build-webview && npm run copy-webview && webpack --mode production --devtool hidden-source-map", - "build": "npm run build-webview && npm run copy-webview && webpack --mode development", - "copy-webview": "shx rm -rf public && shx cp -r ../webview/build public", - "lint": "eslint --ext .ts src", - "build-webview": "cd ../webview && npm run build", - "start-webview": "cd ../webview && npm run start", - "open-in-browser": "vscode-test-web --extensionDevelopmentPath=. ../examples" - }, - "capabilities": { - "untrustedWorkspaces": { - "supported": true + } + ], + "menus": { + "commandPalette": [ + { + "command": "excalidraw.updateTheme", + "when": "activeCustomEditorId == 'editor.excalidraw'" + }, + { + "command": "excalidraw.preventDefault", + "when": "false" + }, + { + "command": "excalidraw.showSource", + "when": "false" + }, + { + "command": "excalidraw.showEditor", + "when": "false" + }, + { + "command": "excalidraw.showImage", + "when": "false" + }, + { + "command": "excalidraw.showSourceToSide", + "when": "false" + }, + { + "command": "excalidraw.showEditorToSide", + "when": "false" + }, + { + "command": "excalidraw.showImageToSide", + "when": "false" } + ], + "editor/title": [ + { + "command": "excalidraw.showEditor", + "alt": "excalidraw.showEditorToSide", + "when": "activeCustomEditorId != 'editor.excalidraw' && resourceFilename =~ /^.+\\.excalidraw(.png|.svg)?$/", + "group": "navigation" + }, + { + "command": "excalidraw.showSource", + "alt": "excalidraw.showSourceToSide", + "group": "navigation", + "when": "activeCustomEditorId == 'editor.excalidraw' && resourceFilename =~ /^.+\\.excalidraw(.svg)?$/" + }, + { + "command": "excalidraw.showImage", + "alt": "excalidraw.showImageToSide", + "when": "activeCustomEditorId == 'editor.excalidraw' && resourceFilename =~ /^.+\\.excalidraw.png$/", + "group": "navigation" + }, + { + "command": "excalidraw.updateTheme", + "when": "activeCustomEditorId == 'editor.excalidraw'", + "group": "navigation" + } + ] }, - "devDependencies": { - "@excalidraw/eslint-config": "^1.0.3", - "@types/node": "^18.11.0", - "@types/vscode": "^1.63.0", - "@typescript-eslint/eslint-plugin": "^5.40.0", - "@typescript-eslint/parser": "^5.40.0", - "@vscode/test-web": "*", - "eslint": "^8.25.0", - "eslint-config-prettier": "^8.5.0", - "eslint-plugin-prettier": "^4.2.1", - "prettier": "^2.7.1", - "shx": "^0.3.4", - "ts-loader": "^9.4.1", - "typescript": "^4.8.4", - "webpack": "^5.74.0", - "webpack-cli": "^4.10.0" - }, - "dependencies": { - "js-base64": "^3.7.2", - "path-browserify": "^1.0.1" + "customEditors": [ + { + "viewType": "editor.excalidraw", + "displayName": "Excalidraw", + "priority": "default", + "selector": [ + { + "filenamePattern": "*.excalidraw" + }, + { + "filenamePattern": "*.excalidraw.json" + }, + { + "filenamePattern": "*.excalidraw.svg" + }, + { + "filenamePattern": "*.excalidraw.png" + } + ] + } + ], + "keybindings": [ + { + "command": "excalidraw.preventDefault", + "key": "ctrl+z", + "mac": "cmd+z", + "when": "activeCustomEditorId == 'editor.excalidraw'" + }, + { + "command": "excalidraw.preventDefault", + "key": "ctrl+y", + "mac": "cmd+shift+z", + "when": "activeCustomEditorId == 'editor.excalidraw'" + } + ] + }, + "scripts": { + "install": "cd ../webview && npm install", + "vscode:prepublish": "npm run package", + "package": "npm run build-webview && npm run copy-webview && webpack --mode production --devtool hidden-source-map", + "build": "npm run build-webview && npm run copy-webview && webpack --mode development", + "copy-webview": "shx rm -rf public && shx cp -r ../webview/build public", + "lint": "eslint --ext .ts src", + "build-webview": "cd ../webview && npm run build", + "start-webview": "cd ../webview && npm run start", + "open-in-browser": "vscode-test-web --extensionDevelopmentPath=. ../examples" + }, + "capabilities": { + "untrustedWorkspaces": { + "supported": true } + }, + "devDependencies": { + "@excalidraw/eslint-config": "^1.0.3", + "@types/node": "^18.11.0", + "@types/vscode": "^1.63.0", + "@typescript-eslint/eslint-plugin": "^5.40.0", + "@typescript-eslint/parser": "^5.40.0", + "@vscode/test-web": "*", + "eslint": "^8.25.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-prettier": "^4.2.1", + "prettier": "^2.7.1", + "shx": "^0.3.4", + "ts-loader": "^9.4.1", + "typescript": "^4.8.4", + "webpack": "^5.74.0", + "webpack-cli": "^4.10.0" + }, + "dependencies": { + "js-base64": "^3.7.2", + "path-browserify": "^1.0.1" + } } diff --git a/extension/src/commands.ts b/extension/src/commands.ts index fe69c4f..16928f2 100644 --- a/extension/src/commands.ts +++ b/extension/src/commands.ts @@ -1,4 +1,5 @@ import * as vscode from "vscode"; +import { ExcalidrawDocument } from './document' function getConfigurationScope( config: vscode.WorkspaceConfiguration, @@ -89,6 +90,26 @@ function showImage(uri: vscode.Uri, viewColumn?: vscode.ViewColumn) { ); } +async function showSaveDialog() { + const targetUri = await vscode.window.showSaveDialog({ + saveLabel: 'Create', + filters: { + Diagrams: ['excalidraw'] + } + }) + if (!targetUri) { + return + } + try { + const doc = new ExcalidrawDocument(targetUri, new Uint8Array()) + await doc.saveAs(targetUri); + showEditor(targetUri, vscode.ViewColumn.Active); + } catch (e) { + console.error('Cannot create or open file', e); + await vscode.window.showErrorMessage(`Cannot create or open file "${targetUri.toString()}"!`); + } +} + export function registerCommands(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand("excalidraw.updateTheme", updateTheme) @@ -120,4 +141,7 @@ export function registerCommands(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand("excalidraw.preventDefault", () => {}) ); + context.subscriptions.push( + vscode.commands.registerCommand('excalidraw.newDiagram', () => showSaveDialog()) + ); } diff --git a/webview/package-lock.json b/webview/package-lock.json index af7c658..c8a6f85 100644 --- a/webview/package-lock.json +++ b/webview/package-lock.json @@ -8,7 +8,7 @@ "name": "excalidraw", "version": "1.0.0", "dependencies": { - "@excalidraw/excalidraw": "^0.17.2", + "@excalidraw/excalidraw": "^0.17.6", "js-base64": "^3.7.2", "lodash-es": "^4.17.21", "react": "^17.0.2", @@ -2402,9 +2402,9 @@ } }, "node_modules/@excalidraw/excalidraw": { - "version": "0.17.2", - "resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.17.2.tgz", - "integrity": "sha512-7pqUWD8+mPjDhF4XxG3gw4rvE2JGaLW3Vss5UZfTbITPxAtFaGEc1K081bncitnaYhUwN9ENJE0i87QB3poDwQ==", + "version": "0.17.6", + "resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.17.6.tgz", + "integrity": "sha512-fyCl+zG/Z5yhHDh5Fq2ZGmphcrALmuOdtITm8gN4d8w4ntnaopTXcTfnAAaU3VleDC6LhTkoLOTG6P5kgREiIg==", "peerDependencies": { "react": "^17.0.2 || ^18.2.0", "react-dom": "^17.0.2 || ^18.2.0"