-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into last-rstudioapi-shims-i-hope
Signed-off-by: Julia Silge <julia.silge@gmail.com>
- Loading branch information
Showing
72 changed files
with
5,816 additions
and
1,172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
//@ts-check | ||
|
||
'use strict'; | ||
|
||
const withDefaults = require('../shared.webpack.config'); | ||
|
||
module.exports = withDefaults({ | ||
context: __dirname, | ||
entry: { | ||
extension: './src/extension.ts', | ||
}, | ||
externals: { | ||
'vscode': { commonjs: 'vscode' }, | ||
'express': { commonjs: 'express' } | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "positron-notebooks-helpers", | ||
"displayName": "Positron Notebooks Helpers", | ||
"description": "Positron Notebook Helpers", | ||
"version": "1.0.0", | ||
"publisher": "vscode", | ||
"engines": { | ||
"vscode": "^1.65.0" | ||
}, | ||
"categories": [ | ||
"Other" | ||
], | ||
"activationEvents": [ | ||
"onStartupFinished" | ||
], | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "positronNotebookHelpers.convertImageToBase64", | ||
"title": "Convert Image to Base64" | ||
} | ||
] | ||
}, | ||
"main": "./out/extension.js", | ||
"scripts": { | ||
"vscode:prepublish": "yarn run compile", | ||
"compile": "tsc -p ./", | ||
"watch": "tsc -watch -p ./", | ||
"lint": "eslint src --ext ts" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/glob": "^7.2.0", | ||
"@types/mocha": "^9.1.0", | ||
"@types/node": "14.x", | ||
"@typescript-eslint/eslint-plugin": "^5.12.1", | ||
"@typescript-eslint/parser": "^5.12.1", | ||
"@vscode/test-electron": "^2.1.2", | ||
"eslint": "^8.9.0", | ||
"glob": "^7.2.0", | ||
"mocha": "^9.2.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.5.5", | ||
"vsce": "^2.11.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/posit-dev/positron" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import path from 'path'; | ||
import * as vscode from 'vscode'; | ||
import { readFile } from 'fs'; | ||
|
||
// Make sure this matches the error message type defined where used | ||
// (src/vs/workbench/contrib/positronNotebook/browser/notebookCells/DeferredImage.tsx) | ||
type CoversionErrorMsg = { | ||
status: 'error'; | ||
message: string; | ||
}; | ||
|
||
/** | ||
* Activates the extension. | ||
* @param context An ExtensionContext that contains the extention context. | ||
*/ | ||
export function activate(context: vscode.ExtensionContext) { | ||
// Command that converts an image from the local file-system to a base64 string. | ||
context.subscriptions.push( | ||
vscode.commands.registerCommand( | ||
'positronNotebookHelpers.convertImageToBase64', | ||
async (imageSrc: string, baseLoc: string) => new Promise<string | CoversionErrorMsg>((resolve) => { | ||
const fullImagePath = path.join(baseLoc, imageSrc); | ||
const fileExtension = path.extname(imageSrc).slice(1); | ||
const mimeType = mimeTypeMap[fileExtension.toLowerCase()]; | ||
if (!mimeType) { | ||
resolve({ | ||
status: 'error', | ||
message: `Unsupported file type: "${fileExtension}."`, | ||
}); | ||
return; | ||
} | ||
try { | ||
readFile(fullImagePath, (err, data) => { | ||
if (err) { | ||
resolve({ | ||
status: 'error', | ||
message: err.message, | ||
}); | ||
} else if (!data) { | ||
resolve({ | ||
status: 'error', | ||
message: `No data found in file "${fullImagePath}."`, | ||
}); | ||
} else { | ||
resolve(`data:${mimeType};base64,${data.toString('base64')}`); | ||
} | ||
}); | ||
} catch (e) { | ||
return { | ||
type: 'error', | ||
message: e instanceof Error ? e.message : `Error occured while converting image ${fullImagePath} to base64.`, | ||
}; | ||
} | ||
}) | ||
) | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Map image file extension to MIME type. | ||
* | ||
* Supports all the 'image' types from [this list](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) | ||
*/ | ||
const mimeTypeMap: Record<string, string> = { | ||
png: 'image/png', | ||
apng: 'image/apng', | ||
avif: 'image/avif', | ||
ico: 'image/vnd.microsoft.icon', | ||
jpeg: 'image/jpeg', | ||
jpg: 'image/jpeg', | ||
gif: 'image/gif', | ||
bmp: 'image/bmp', | ||
webp: 'image/webp', | ||
svg: 'image/svg+xml', | ||
tiff: 'image/tiff', | ||
tif: 'image/tiff', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "ES2020", | ||
"outDir": "out", | ||
"esModuleInterop": true, | ||
"lib": ["ES2020"], | ||
"sourceMap": true, | ||
"rootDir": "src", | ||
"strict": true, | ||
"typeRoots": ["./node_modules/@types"], | ||
"paths": { | ||
"*": ["./node_modules/*"] | ||
} | ||
}, | ||
"include": ["src/**/*", "../../src/vscode-dts/vscode.d.ts"] | ||
} |
Oops, something went wrong.