From 1beadb5e34b4cbb2a780777d3407b3458120a80e Mon Sep 17 00:00:00 2001 From: Francois Laberge Date: Fri, 23 Jul 2021 08:25:05 -0400 Subject: [PATCH] Missed some files --- .../vscode-simple/out/editor-provider.js | 305 ++++++++++-------- integrations/vscode-simple/out/extension.js | 18 +- integrations/vscode-simple/out/nonce.js | 23 +- 3 files changed, 186 insertions(+), 160 deletions(-) diff --git a/integrations/vscode-simple/out/editor-provider.js b/integrations/vscode-simple/out/editor-provider.js index 394baf65a..83bda10ee 100644 --- a/integrations/vscode-simple/out/editor-provider.js +++ b/integrations/vscode-simple/out/editor-provider.js @@ -1,8 +1,8 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.TldrawEditorProvider = void 0; -const vscode = require("vscode"); -const nonce_1 = require("./nonce"); +'use strict' +Object.defineProperty(exports, '__esModule', { value: true }) +exports.TldrawEditorProvider = void 0 +const vscode = require('vscode') +const nonce_1 = require('./nonce') /** * Provider for .tldr editor. * @@ -16,116 +16,134 @@ const nonce_1 = require("./nonce"); * - Synchronizing changes between a text document and the tldraw custom editor. */ class TldrawEditorProvider { - constructor(context) { - this.context = context; + constructor(context) { + this.context = context + } + static register(context) { + vscode.commands.registerCommand('tldraw.tldr.new', () => { + vscode.window.showInformationMessage('Created a new .tldr file') + const workspaceFolders = vscode.workspace.workspaceFolders + if (!workspaceFolders) { + vscode.window.showErrorMessage( + 'Creating new Tldraw Editor files currently requires opening a workspace' + ) + return + } + const uri = vscode.Uri.joinPath( + workspaceFolders[0].uri, + `new-${TldrawEditorProvider.newTldrawFileId++}.tldr` + ).with({ scheme: 'untitled' }) + vscode.commands.executeCommand( + 'vscode.openWith', + uri, + TldrawEditorProvider.viewType + ) + }) + const provider = new TldrawEditorProvider(context) + const providerRegistration = vscode.window.registerCustomEditorProvider( + TldrawEditorProvider.viewType, + provider, + { + // For this demo extension, we enable `retainContextWhenHidden` which keeps the + // webview alive even when it is not visible. You should avoid using this setting + // unless is absolutely required as it does have memory overhead. + webviewOptions: { + retainContextWhenHidden: true, + }, + supportsMultipleEditorsPerDocument: false, + } + ) + return providerRegistration + } + /** + * Called when our custom editor is opened. + * + * + */ + async resolveCustomTextEditor(document, webviewPanel, _token) { + this.document = document + // Setup initial content for the webview + webviewPanel.webview.options = { + enableScripts: true, + retainContextWhenHidden: true, } - static register(context) { - vscode.commands.registerCommand('tldraw.tldr.new', () => { - vscode.window.showInformationMessage('Created a new .tldr file'); - const workspaceFolders = vscode.workspace.workspaceFolders; - if (!workspaceFolders) { - vscode.window.showErrorMessage('Creating new Tldraw Editor files currently requires opening a workspace'); - return; - } - const uri = vscode.Uri.joinPath(workspaceFolders[0].uri, `new-${TldrawEditorProvider.newTldrawFileId++}.tldr`).with({ scheme: 'untitled' }); - vscode.commands.executeCommand('vscode.openWith', uri, TldrawEditorProvider.viewType); - }); - const provider = new TldrawEditorProvider(context); - const providerRegistration = vscode.window.registerCustomEditorProvider(TldrawEditorProvider.viewType, provider, { - // For this demo extension, we enable `retainContextWhenHidden` which keeps the - // webview alive even when it is not visible. You should avoid using this setting - // unless is absolutely required as it does have memory overhead. - webviewOptions: { - retainContextWhenHidden: true, - }, - supportsMultipleEditorsPerDocument: false, - }); - return providerRegistration; + webviewPanel.webview.html = this.getHtmlForWebview(webviewPanel.webview) + function updateWebview() { + webviewPanel.webview.postMessage({ + type: 'load', + text: document.getText(), + }) } - /** - * Called when our custom editor is opened. - * - * - */ - async resolveCustomTextEditor(document, webviewPanel, _token) { - this.document = document; - // Setup initial content for the webview - webviewPanel.webview.options = { - enableScripts: true, - retainContextWhenHidden: true, - }; - webviewPanel.webview.html = this.getHtmlForWebview(webviewPanel.webview); - function updateWebview() { - webviewPanel.webview.postMessage({ - type: 'load', - text: document.getText(), - }); + // Hook up event handlers so that we can synchronize the webview with the text document. + // + // The text document acts as our model, so we have to sync change in the document to our + // editor and sync changes in the editor back to the document. + // + // Remember that a single text document can also be shared between multiple custom + // editors (this happens for example when you split a custom editor) + let firstLoad = true + const changeDocumentSubscription = vscode.workspace.onDidChangeTextDocument( + (e) => { + if (e.document.uri.toString() === document.uri.toString()) { + if (firstLoad) { + console.log(`First load:${firstLoad}`) + updateWebview() + firstLoad = false + } else { + console.log("don't load") + } } - // Hook up event handlers so that we can synchronize the webview with the text document. - // - // The text document acts as our model, so we have to sync change in the document to our - // editor and sync changes in the editor back to the document. - // - // Remember that a single text document can also be shared between multiple custom - // editors (this happens for example when you split a custom editor) - let firstLoad = true; - const changeDocumentSubscription = vscode.workspace.onDidChangeTextDocument((e) => { - if (e.document.uri.toString() === document.uri.toString()) { - if (firstLoad) { - console.log(`First load:${firstLoad}`); - updateWebview(); - firstLoad = false; - } - else { - console.log("don't load"); - } - } - }); - // Make sure we get rid of the listener when our editor is closed. - webviewPanel.onDidDispose(() => { - changeDocumentSubscription.dispose(); - }); - // Receive message from the webview. - webviewPanel.webview.onDidReceiveMessage((e) => { - switch (e.type) { - case 'update': - console.log(`"update" extension <-`); - //console.log(`Is it different? ${}`) - //vscode.window.showInformationMessage('Upated .tdlr file') - this.updateTextDocument(document, JSON.parse(e.text)); - break; - case 'save': - console.log(`"save" extension <-`); - if (this.document !== undefined) { - this.document.save(); - // const writeData = Buffer.from(e.text, 'utf8') - // // I believe saving will automatically synchronize the in memory document - // // so we don't need to call updateTextDocument here. - // vscode.workspace.fs.writeFile(this.document?.uri, writeData) - //vscode.window.showInformationMessage('Saved .tdlr file') - } - break; - } - }); - updateWebview(); - } - /** - * Get the static html used for the editor webviews. - */ - getHtmlForWebview(webview) { - // Local path to script and css for the webview - const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this.context.extensionUri, 'webview', 'editor.js')); - // const styleResetUri = webview.asWebviewUri( - // vscode.Uri.joinPath(this.context.extensionUri, 'media', 'reset.css') - // ) - // const styleVSCodeUri = webview.asWebviewUri( - // vscode.Uri.joinPath(this.context.extensionUri, 'media', 'vscode.css') - // ) - const styleMainUri = webview.asWebviewUri(vscode.Uri.joinPath(this.context.extensionUri, 'webview', 'main.css')); - console.log('getHtmlForWebview'); - // Use a nonce to whitelist which scripts can be run - const nonce = nonce_1.getNonce(); - return /* html */ ` + } + ) + // Make sure we get rid of the listener when our editor is closed. + webviewPanel.onDidDispose(() => { + changeDocumentSubscription.dispose() + }) + // Receive message from the webview. + webviewPanel.webview.onDidReceiveMessage((e) => { + switch (e.type) { + case 'update': + console.log(`"update" extension <-`) + //console.log(`Is it different? ${}`) + //vscode.window.showInformationMessage('Upated .tdlr file') + this.updateTextDocument(document, JSON.parse(e.text)) + break + case 'save': + console.log(`"save" extension <-`) + if (this.document !== undefined) { + this.document.save() + // const writeData = Buffer.from(e.text, 'utf8') + // // I believe saving will automatically synchronize the in memory document + // // so we don't need to call updateTextDocument here. + // vscode.workspace.fs.writeFile(this.document?.uri, writeData) + //vscode.window.showInformationMessage('Saved .tdlr file') + } + break + } + }) + updateWebview() + } + /** + * Get the static html used for the editor webviews. + */ + getHtmlForWebview(webview) { + // Local path to script and css for the webview + const scriptUri = webview.asWebviewUri( + vscode.Uri.joinPath(this.context.extensionUri, 'webview', 'editor.js') + ) + // const styleResetUri = webview.asWebviewUri( + // vscode.Uri.joinPath(this.context.extensionUri, 'media', 'reset.css') + // ) + // const styleVSCodeUri = webview.asWebviewUri( + // vscode.Uri.joinPath(this.context.extensionUri, 'media', 'vscode.css') + // ) + const styleMainUri = webview.asWebviewUri( + vscode.Uri.joinPath(this.context.extensionUri, 'webview', 'main.css') + ) + console.log('getHtmlForWebview') + // Use a nonce to whitelist which scripts can be run + const nonce = nonce_1.getNonce() + return /* html */ ` @@ -147,35 +165,40 @@ class TldrawEditorProvider {
- `; + ` + } + /** + * Try to get a current document as json text. + */ + getDocumentAsJson(document) { + const text = document.getText() + if (text.trim().length === 0) { + return {} } - /** - * Try to get a current document as json text. - */ - getDocumentAsJson(document) { - const text = document.getText(); - if (text.trim().length === 0) { - return {}; - } - try { - return JSON.parse(text); - } - catch { - throw new Error('Could not get document as json. Content is not valid json!!!'); - } - } - /** - * Write out the json to a given document. - */ - updateTextDocument(document, json) { - const edit = new vscode.WorkspaceEdit(); - // Just replace the entire document every time for this example extension. - // A more complete extension should compute minimal edits instead. - edit.replace(document.uri, new vscode.Range(0, 0, document.lineCount, 0), JSON.stringify(json, null, 2)); - return vscode.workspace.applyEdit(edit); + try { + return JSON.parse(text) + } catch { + throw new Error( + 'Could not get document as json. Content is not valid json!!!' + ) } + } + /** + * Write out the json to a given document. + */ + updateTextDocument(document, json) { + const edit = new vscode.WorkspaceEdit() + // Just replace the entire document every time for this example extension. + // A more complete extension should compute minimal edits instead. + edit.replace( + document.uri, + new vscode.Range(0, 0, document.lineCount, 0), + JSON.stringify(json, null, 2) + ) + return vscode.workspace.applyEdit(edit) + } } -exports.TldrawEditorProvider = TldrawEditorProvider; -TldrawEditorProvider.newTldrawFileId = 1; -TldrawEditorProvider.viewType = 'tldraw.tldr'; -//# sourceMappingURL=editor-provider.js.map \ No newline at end of file +exports.TldrawEditorProvider = TldrawEditorProvider +TldrawEditorProvider.newTldrawFileId = 1 +TldrawEditorProvider.viewType = 'tldraw.tldr' +//# sourceMappingURL=editor-provider.js.map diff --git a/integrations/vscode-simple/out/extension.js b/integrations/vscode-simple/out/extension.js index 49a978b2f..5ee967003 100644 --- a/integrations/vscode-simple/out/extension.js +++ b/integrations/vscode-simple/out/extension.js @@ -1,10 +1,12 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.activate = void 0; -const editor_provider_1 = require("./editor-provider"); +'use strict' +Object.defineProperty(exports, '__esModule', { value: true }) +exports.activate = void 0 +const editor_provider_1 = require('./editor-provider') function activate(context) { - // Register our custom editor provider - context.subscriptions.push(editor_provider_1.TldrawEditorProvider.register(context)); + // Register our custom editor provider + context.subscriptions.push( + editor_provider_1.TldrawEditorProvider.register(context) + ) } -exports.activate = activate; -//# sourceMappingURL=extension.js.map \ No newline at end of file +exports.activate = activate +//# sourceMappingURL=extension.js.map diff --git a/integrations/vscode-simple/out/nonce.js b/integrations/vscode-simple/out/nonce.js index def2ff498..e7514a949 100644 --- a/integrations/vscode-simple/out/nonce.js +++ b/integrations/vscode-simple/out/nonce.js @@ -1,13 +1,14 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getNonce = void 0; +'use strict' +Object.defineProperty(exports, '__esModule', { value: true }) +exports.getNonce = void 0 function getNonce() { - let text = ''; - const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - for (let i = 0; i < 32; i++) { - text += possible.charAt(Math.floor(Math.random() * possible.length)); - } - return text; + let text = '' + const possible = + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' + for (let i = 0; i < 32; i++) { + text += possible.charAt(Math.floor(Math.random() * possible.length)) + } + return text } -exports.getNonce = getNonce; -//# sourceMappingURL=nonce.js.map \ No newline at end of file +exports.getNonce = getNonce +//# sourceMappingURL=nonce.js.map