Merge branch 'main' of https://github.com/tldraw/tldraw
This commit is contained in:
commit
3f674d7fa5
7 changed files with 1530 additions and 34 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,6 +11,7 @@ coverage
|
||||||
|
|
||||||
.vercel
|
.vercel
|
||||||
.next
|
.next
|
||||||
|
apps/www/public/workbox-*
|
||||||
apps/www/public/worker-*
|
apps/www/public/worker-*
|
||||||
apps/www/public/sw.js
|
apps/www/public/sw.js
|
||||||
apps/www/public/sw.js.map
|
apps/www/public/sw.js.map
|
||||||
|
|
|
@ -15,17 +15,17 @@ export default function App(): JSX.Element {
|
||||||
)
|
)
|
||||||
|
|
||||||
// When the editor mounts, save the state instance in a ref.
|
// When the editor mounts, save the state instance in a ref.
|
||||||
const handleMount = React.useCallback((state: TldrawApp) => {
|
const handleMount = React.useCallback((app: TldrawApp) => {
|
||||||
rTldrawApp.current = state
|
rTldrawApp.current = app
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// When the editor's document changes, post the stringified document to the vscode extension.
|
// When the editor's document changes, post the stringified document to the vscode extension.
|
||||||
const handlePersist = React.useCallback((state: TldrawApp) => {
|
const handlePersist = React.useCallback((app: TldrawApp) => {
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
type: 'editorUpdated',
|
type: 'editorUpdated',
|
||||||
text: JSON.stringify({
|
text: JSON.stringify({
|
||||||
...currentFile,
|
...currentFile,
|
||||||
document: state.document,
|
document: app.document,
|
||||||
assets: {},
|
assets: {},
|
||||||
} as TDFile),
|
} as TDFile),
|
||||||
} as MessageFromWebview)
|
} as MessageFromWebview)
|
||||||
|
@ -37,8 +37,9 @@ export default function App(): JSX.Element {
|
||||||
if (data.type === 'openedFile') {
|
if (data.type === 'openedFile') {
|
||||||
try {
|
try {
|
||||||
const { document } = JSON.parse(data.text) as TDFile
|
const { document } = JSON.parse(data.text) as TDFile
|
||||||
const state = rTldrawApp.current!
|
const app = rTldrawApp.current!
|
||||||
state.updateDocument(document)
|
app.updateDocument(document)
|
||||||
|
app.zoomToFit()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to parse file:', data.text)
|
console.warn('Failed to parse file:', data.text)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,13 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"keybindings": [
|
"keybindings": [
|
||||||
|
{
|
||||||
|
"key": "cmd+shift+d",
|
||||||
|
"title": "Zoom In",
|
||||||
|
"command": "tldraw.tldr.toggleDarkMode",
|
||||||
|
"category": "tldraw",
|
||||||
|
"enablement": "resourceExtname == .tldr"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "cmd+numpad_add",
|
"key": "cmd+numpad_add",
|
||||||
"title": "Zoom In",
|
"title": "Zoom In",
|
||||||
|
@ -119,4 +126,4 @@
|
||||||
"vsce": "^2.2.0"
|
"vsce": "^2.2.0"
|
||||||
},
|
},
|
||||||
"gitHead": "325008ff82bd27b63d625ad1b760f8871fb71af9"
|
"gitHead": "325008ff82bd27b63d625ad1b760f8871fb71af9"
|
||||||
}
|
}
|
|
@ -15,10 +15,16 @@ export class TldrawEditorProvider implements vscode.CustomTextEditorProvider {
|
||||||
private static readonly viewType = 'tldraw.tldr'
|
private static readonly viewType = 'tldraw.tldr'
|
||||||
|
|
||||||
public static register = (context: vscode.ExtensionContext): vscode.Disposable => {
|
public static register = (context: vscode.ExtensionContext): vscode.Disposable => {
|
||||||
// Register the 'Create new Tldraw file' command, which creates
|
// Several commands exist only to prevent the default keyboard shortcuts
|
||||||
// a temporary .tldr file and opens it in the editor.
|
const noopCmds = ['zoomIn', 'zoomOut', 'resetZoom', 'toggleDarkMode']
|
||||||
vscode.commands.registerCommand('tldraw.tldr.new', () => {
|
noopCmds.forEach((name) =>
|
||||||
const id = TldrawEditorProvider.newTDFileId++
|
vscode.commands.registerCommand(`${this.viewType}.${name}`, () => null)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register the 'Create New File' command, which creates a temporary
|
||||||
|
// .tldr file and opens it in the editor.
|
||||||
|
vscode.commands.registerCommand(`${this.viewType}.new`, () => {
|
||||||
|
const id = this.newTDFileId++
|
||||||
const name = id > 1 ? `New Document ${id}.tldr` : `New Document.tldr`
|
const name = id > 1 ? `New Document ${id}.tldr` : `New Document.tldr`
|
||||||
|
|
||||||
const workspaceFolders = vscode.workspace.workspaceFolders
|
const workspaceFolders = vscode.workspace.workspaceFolders
|
||||||
|
@ -27,34 +33,17 @@ export class TldrawEditorProvider implements vscode.CustomTextEditorProvider {
|
||||||
vscode.commands.executeCommand(
|
vscode.commands.executeCommand(
|
||||||
'vscode.openWith',
|
'vscode.openWith',
|
||||||
vscode.Uri.joinPath(path, name).with({ scheme: 'untitled' }),
|
vscode.Uri.joinPath(path, name).with({ scheme: 'untitled' }),
|
||||||
TldrawEditorProvider.viewType
|
this.viewType
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
vscode.commands.registerCommand('tldraw.tldr.zoomIn', () => {
|
|
||||||
// Noop
|
|
||||||
})
|
|
||||||
|
|
||||||
vscode.commands.registerCommand('tldraw.tldr.zoomOut', () => {
|
|
||||||
// Noop
|
|
||||||
})
|
|
||||||
|
|
||||||
vscode.commands.registerCommand('tldraw.tldr.resetZoom', () => {
|
|
||||||
// Noop
|
|
||||||
})
|
|
||||||
|
|
||||||
// Register our editor provider, indicating to VS Code that we can
|
// Register our editor provider, indicating to VS Code that we can
|
||||||
// handle files with the .tldr extension.
|
// handle files with the .tldr extension.
|
||||||
return vscode.window.registerCustomEditorProvider(
|
return vscode.window.registerCustomEditorProvider(
|
||||||
TldrawEditorProvider.viewType,
|
this.viewType,
|
||||||
new TldrawEditorProvider(context),
|
new TldrawEditorProvider(context),
|
||||||
{
|
{
|
||||||
webviewOptions: {
|
webviewOptions: { retainContextWhenHidden: true },
|
||||||
// See https://code.visualstudio.com/api/extension-guides/webview#retaincontextwhenhidden
|
|
||||||
retainContextWhenHidden: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
// See https://code.visualstudio.com/api/extension-guides/custom-editors#custom-editor-lifecycle
|
|
||||||
supportsMultipleEditorsPerDocument: true,
|
supportsMultipleEditorsPerDocument: true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1501
repo-map.tldr
Normal file
1501
repo-map.tldr
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue