1 Commits

Author SHA1 Message Date
5454183d86 With auth 2023-09-26 20:47:53 -07:00
49 changed files with 3409 additions and 4982 deletions

39
.gitignore vendored
View File

@ -264,42 +264,3 @@ __pycache__/
type-script-helper-1.1.6.vsix type-script-helper-1.1.6.vsix
type-script-helper-1.1.7.vsix type-script-helper-1.1.7.vsix
type-script-helper-1.1.8.vsix type-script-helper-1.1.8.vsix
.kanbn
*.exe
*.pdb
.vscode/helper/**
type-script-helper/src/Card.js
type-script-helper/src/Card.js.map
type-script-helper/src/ColumnsToCardsWebviewViewProvider.js
type-script-helper/src/ColumnsToCardsWebviewViewProvider.js.map
type-script-helper/src/constants.js
type-script-helper/src/constants.js.map
type-script-helper/src/extension.js
type-script-helper/src/extension.js.map
type-script-helper/src/getNonce.js
type-script-helper/src/getNonce.js.map
type-script-helper/src/H2HexColor.js
type-script-helper/src/H2HexColor.js.map
type-script-helper/src/H2NoCheckboxes.js
type-script-helper/src/H2NoCheckboxes.js.map
type-script-helper/src/H2WithCheckboxes.js
type-script-helper/src/H2WithCheckboxes.js.map
type-script-helper/src/kanbanHelper.js
type-script-helper/src/kanbanHelper.js.map
type-script-helper/src/LineNumber.js
type-script-helper/src/LineNumber.js.map
type-script-helper/src/markdownHelper.js
type-script-helper/src/markdownHelper.js.map
type-script-helper/src/PostMessage.js
type-script-helper/src/PostMessage.js.map
type-script-helper/src/promiseLinesHelper.js
type-script-helper/src/promiseLinesHelper.js.map
type-script-helper/src/readOnlyLinesHelper.js
type-script-helper/src/readOnlyLinesHelper.js.map
type-script-helper/src/replaceLinesHelper.js
type-script-helper/src/replaceLinesHelper.js.map
type-script-helper/src/WebViewPanel.js
type-script-helper/src/WebViewPanel.js.map

20
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,20 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/type-script-helper"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
]
}

25
.vscode/settings.json vendored
View File

@ -1,23 +1,6 @@
{ {
"[markdown]": { "cSpell.words": [
"editor.wordWrap": "off" "Kanban",
}, "VSIX"
"cSpell.words": [ ]
"initialise",
"Kanban",
"VSIX"
],
"files.eol": "\n",
"files.exclude": {
"**/dist": false,
"**/node_modules": true,
"**/out": false
},
"files.watcherExclude": {
"**/node_modules": true
},
"search.exclude": {
"**/dist": true,
"**/out": true
}
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,5 @@
.vscode-test/ out
.vscode/helper/**
*.vsix
dist dist
node_modules node_modules
out .vscode-test/
*.vsix

View File

@ -14,16 +14,22 @@
], ],
"outFiles": [ "outFiles": [
"${workspaceFolder}/dist/**/*.js" "${workspaceFolder}/dist/**/*.js"
] ],
"preLaunchTask": "${defaultBuildTask}"
}, },
{ {
"type": "node", "name": "Extension Tests",
"type": "extensionHost",
"request": "launch", "request": "launch",
"name": "Launch Program", "args": [
"program": "${workspaceFolder}/src/extension.ts", "--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [ "outFiles": [
"${workspaceFolder}/out/**/*.js" "${workspaceFolder}/out/**/*.js",
] "${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "tasks: watch-tests"
} }
] ]
} }

View File

@ -1,11 +0,0 @@
---
type: "note"
created: "2023-10-20T03:53:13.742Z"
updated: "2023-10-20T04:00:37.259Z"
---
# mklink
```bash
mklink /J "L:\Git\YO-VSCode\type-script-helper\net8.0\win-x64\publish" "L:\DevOps\Mesa_FI\File-Folder-Helper\bin\Release\net8.0\win-x64\publish"
```

View File

@ -1,23 +1,13 @@
// Place your settings in this file to overwrite default and user settings.
{ {
"[markdown]": { "files.exclude": {
"editor.wordWrap": "off" "out": false, // set this to true to hide the "out" folder with the compiled JS files
}, "dist": false // set this to true to hide the "dist" folder with the compiled JS files
"cSpell.words": [ },
"initialise", "search.exclude": {
"Kanban", "out": true, // set this to false to include "out" folder in search results
"VSIX" "dist": true // set this to false to include "dist" folder in search results
], },
"files.eol": "\n", // Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"files.exclude": { "typescript.tsc.autoDetect": "off"
"**/dist": false,
"**/node_modules": true,
"**/out": false
},
"files.watcherExclude": {
"**/node_modules": true
},
"search.exclude": {
"**/dist": true,
"**/out": true
}
} }

40
type-script-helper/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,40 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$ts-webpack-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "watch-tests",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": "build"
},
{
"label": "tasks: watch-tests",
"dependsOn": [
"npm: watch",
"npm: watch-tests"
],
"problemMatcher": []
}
]
}

View File

@ -1,14 +1,13 @@
.gitignore
.vscode-test/**
.vscode/** .vscode/**
.vscode-test/**
out/**
node_modules/**
src/**
.gitignore
.yarnrc .yarnrc
webpack.config.js
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json **/.eslintrc.json
**/*.map **/*.map
**/*.ts **/*.ts
**/tsconfig.json
build/**
node_modules/**
src/**
webviews/**
vsc-extension-quickstart.md
webpack.config.js

View File

@ -0,0 +1,9 @@
# Change Log
All notable changes to the "type-script-helper" extension will be documented in this file.
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## [Unreleased]
- Initial release

View File

@ -1,11 +1,3 @@
---
type: "note"
created: "2022-03-10T21:18:17.054Z"
updated: "2022-03-10T21:18:17.054Z"
---
# LICENSE
Copyright (c) Twitter Inc Copyright (c) Twitter Inc
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@ -24,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.

View File

@ -1,9 +1,3 @@
---
type: "read-me"
created: "2023-09-30T01:47:18.241Z"
updated: "2023-09-30T01:47:18.242Z"
---
# type-script-helper README # type-script-helper README
## Features ## Features
@ -22,7 +16,7 @@ yo code
# ? What's the name of your extension? HelloWorld # ? What's the name of your extension? HelloWorld
### Press <Enter> to choose default for all options below ### ### Press <Enter> to choose default for all options below ###
# ? What's the identifier of your extension? hello-world # ? What's the identifier of your extension? helloworld
# ? What's the description of your extension? LEAVE BLANK # ? What's the description of your extension? LEAVE BLANK
# ? Initialize a git repository? Yes # ? Initialize a git repository? Yes
# ? Bundle the source code with webpack? No (should be yes?) # ? Bundle the source code with webpack? No (should be yes?)
@ -114,39 +108,4 @@ None
## 1.5.1 ## 1.5.1
----------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------
- columns-to-cards-webview-view-provider - Webview
- file-folder-helper-exe
- clickable list
## 1.5.2
-----------------------------------------------------------------------------------------------------------
- file-folder-helper-exe net8.0
## 1.5.3
-----------------------------------------------------------------------------------------------------------
- Updated File-Folder-Helper ccea8de8cf49343dd4190a77ac755d233bb4e528
## 1.6.0
-----------------------------------------------------------------------------------------------------------
- Updated File-Folder-Helper 4e3f06bb44b7e85ba40a5e589e6ca871cbdbfb3e
## 1.6.1
-----------------------------------------------------------------------------------------------------------
- Updated File-Folder-Helper 299aa19d538bcfd5e06e4743a5a05f6d62960a80
- code --install-extension D:\Tmp\phares\type-script-helper-1.6.1.vsix
- code-insiders --install-extension D:\Tmp\phares\type-script-helper-1.6.1.vsix
## 1.6.2
-----------------------------------------------------------------------------------------------------------
- Updated File-Folder-Helper 47e6b85c218f994216fb35d44906850a790c36d0
- Open with Text Editor Kanban
## 1.6.4 Fri Aug 02 2024 13:07:24 GMT-0700 (Mountain Standard Time)
-----------------------------------------------------------------------------------------------------------
- Wrap directory in quotes

File diff suppressed because it is too large Load Diff

View File

@ -4,28 +4,6 @@
"Other" "Other"
], ],
"contributes": { "contributes": {
"configuration": {
"type": "object",
"title": "Type Script Helper Configuration",
"properties": {
"fileTemplates.author": {
"type": [
"string",
"null"
],
"default": null,
"description": "Value to use to replace #{author} variable."
},
"fileTemplates.company": {
"type": [
"string",
"null"
],
"default": null,
"description": "Value to use to replace #{company} variable."
}
}
},
"commands": [ "commands": [
{ {
"category": "Helper", "category": "Helper",
@ -59,34 +37,24 @@
}, },
{ {
"category": "Kanban", "category": "Kanban",
"command": "kanban.refreshBoth", "command": "kanban.apiAuthenticate",
"title": "Refresh Kanban Both" "title": "API Authenticate Kanban"
}, },
{ {
"category": "Kanban", "category": "Kanban",
"command": "kanban.refreshSidebar", "command": "kanban.newEntry",
"title": "Refresh Kanban Sidebar" "title": "New Kanban Entry"
}, },
{ {
"category": "Kanban", "category": "Kanban",
"command": "kanban.refreshWebView", "command": "kanban.refresh",
"title": "Refresh Kanban WebView" "title": "Refresh Kanban"
}, },
{ {
"category": "Kanban", "category": "Kanban",
"command": "kanban.debugReload", "command": "kanban.debugReload",
"title": "Debug Reload Kanban" "title": "Debug Reload Kanban"
}, },
{
"category": "Kanban",
"command": "kanban.openWithTextEditor",
"title": "Open with Text Editor Kanban"
},
{
"category": "Markdown",
"command": "markdown.newMarkdownFile",
"title": "New Markdown File"
},
{ {
"category": "Quick Fix", "category": "Quick Fix",
"command": "replaceLinesHelper.quickFixCamelCaseProperties", "command": "replaceLinesHelper.quickFixCamelCaseProperties",
@ -199,11 +167,11 @@
} }
], ],
"views": { "views": {
"columns-to-cards-webview-view-provider-view": [ "kanban-sidebar-view": [
{ {
"contextualTitle": "Kanban", "contextualTitle": "Kanban",
"icon": "media/checklist.svg", "icon": "media/checklist.svg",
"id": "columns-to-cards-webview-view-provider", "id": "kanban-sidebar",
"name": "Kanban", "name": "Kanban",
"type": "webview" "type": "webview"
} }
@ -213,7 +181,7 @@
"activitybar": [ "activitybar": [
{ {
"icon": "media/checklist.svg", "icon": "media/checklist.svg",
"id": "columns-to-cards-webview-view-provider-view", "id": "kanban-sidebar-view",
"title": "Kanban" "title": "Kanban"
} }
] ]
@ -225,25 +193,32 @@
}, },
"description": "Helper for VS Code in TypeScript", "description": "Helper for VS Code in TypeScript",
"devDependencies": { "devDependencies": {
"@nodelib/fs.stat": "^3.0.0", "@rollup/plugin-commonjs": "^25.0.4",
"@types/mocha": "^10.0.6", "@rollup/plugin-node-resolve": "^15.2.1",
"@types/node": "^18.11.0", "@rollup/plugin-typescript": "^11.1.4",
"@types/vscode": "^1.63.0", "@tsconfig/svelte": "^1.0.10",
"@typescript-eslint/eslint-plugin": "^5.40.0", "@types/glob": "^8.1.0",
"@typescript-eslint/parser": "^5.40.0", "@types/mocha": "^10.0.1",
"@vscode/test-electron": "^2.4.0", "@types/node": "20.2.5",
"@vscode/test-web": "*", "@types/polka": "^0.5.1",
"concurrently": "^8.2.2", "@types/vscode": "^1.79.0",
"eslint": "^8.25.0", "@typescript-eslint/eslint-plugin": "^5.59.8",
"eslint-config-prettier": "^8.5.0", "@typescript-eslint/parser": "^5.59.8",
"eslint-plugin-prettier": "^4.2.1", "@vscode/test-electron": "^2.3.2",
"glob": "^10.4.1", "concurrently": "^8.2.1",
"mocha": "^10.4.0", "eslint": "^8.41.0",
"prettier": "^2.7.1", "glob": "^8.1.0",
"ts-loader": "^9.4.1", "mocha": "^10.2.0",
"typescript": "^4.8.4", "rollup": "^2.3.4",
"webpack": "^5.74.0", "rollup-plugin-svelte": "^6.1.1",
"webpack-cli": "^4.10.0" "rollup-plugin-terser": "^7.0.2",
"svelte": "^3.31.0",
"svelte-check": "^1.1.23",
"svelte-preprocess": "^5.0.4",
"ts-loader": "^9.4.3",
"typescript": "^5.1.3",
"webpack": "^5.85.0",
"webpack-cli": "^5.1.1"
}, },
"displayName": "Type Script Helper", "displayName": "Type Script Helper",
"engines": { "engines": {
@ -254,10 +229,16 @@
"publisher": "IFX", "publisher": "IFX",
"repository": "https://github.com/mikepharesjr/YO-VSCode/tree/master/type-script-helper", "repository": "https://github.com/mikepharesjr/YO-VSCode/tree/master/type-script-helper",
"scripts": { "scripts": {
"tsc-build": "tsc", "compile": "webpack --config ./build/node-extension.webpack.config.js",
"vscode:publish": "node node_modules/@vscode/vsce/vsce package", "lint": "eslint src --ext ts",
"webpack": "webpack --config ./build/node-extension.webpack.config.js", "package": "webpack --mode production --devtool hidden-source-map --config ./build/node-extension.webpack.config.js",
"pretest": "npm run test-compile && npm run lint",
"rollup:compile": "rollup -c && webpack --mode production",
"test": "node ./out/test/runTest.js",
"test-compile": "tsc -p ./",
"test-watch": "tsc -watch -p ./",
"vscode:prepublish": "npm run package",
"watch": "concurrently \"rollup -c -w\" \"webpack --watch --config ./build/node-extension.webpack.config.js\"" "watch": "concurrently \"rollup -c -w\" \"webpack --watch --config ./build/node-extension.webpack.config.js\""
}, },
"version": "1.6.4" "version": "1.5.1"
} }

View File

@ -1,22 +0,0 @@
import { H2HexColor } from "./H2HexColor";
import { LineNumber } from "./LineNumber";
import { H2NoCheckboxes } from "./H2NoCheckboxes";
import { H2WithCheckboxes } from "./H2WithCheckboxes";
export type Card = {
Assignees: Array<string>;
CreationDateTime: Date;
Directory: string;
Extension: string;
File: string;
FileName: string;
FileNameWithoutExtension: string;
H1: string;
H2HexColorCollection: Array<H2HexColor>;
H2NoCheckboxesCollection: Array<H2NoCheckboxes>;
H2WithCheckboxesCollection: Array<H2WithCheckboxes>;
LastWriteDateTime: Date;
LineNumber: LineNumber;
RequestedDateTime: string;
Type: string;
};

View File

@ -1,188 +0,0 @@
import { Card } from "./Card";
import { readFile } from "fs";
import * as vscode from "vscode";
import { getNonce } from "./getNonce";
import { PostMessage } from "./PostMessage";
import { apiBaseUrl, key } from "./constants";
import { ExecException, exec } from 'child_process';
export function refreshSidebarLogic(): any {
vscode.commands.executeCommand("workbench.action.closeSidebar").then(_ => {
vscode.commands.executeCommand("workbench.view.extension.columns-to-cards-sidebar-view");
});
}
function columnsToCardsRead(webviewView: vscode.WebviewView, columnsToCardsUri: vscode.Uri, err: NodeJS.ErrnoException | null, data: string | Buffer) {
if (err)
vscode.window.showInformationMessage(`<${columnsToCardsUri.fsPath}> doesn't exist! ${err.message}`);
const columnsToCards: Record<string, Array<Card>> = {};
const jsonObject: any = JSON.parse(data.toString('utf8'));
for (const property in jsonObject) {
columnsToCards[property] = jsonObject[property];
}
const postMessage: PostMessage = { type: "columns-to-cards", value: columnsToCards };
webviewView.webview.postMessage(postMessage);
}
function execCallback(webviewView: vscode.WebviewView, destination: vscode.Uri, error: ExecException | null, stdout: string, stderr: string) {
if (error) {
vscode.window.showInformationMessage(error.message);
return;
}
if (stderr) {
vscode.window.showInformationMessage(stderr);
return;
}
console.log(`stdout: ${stdout}`);
const columnsToCards = vscode.Uri.joinPath(destination, "columnsToCards.json");
readFile(columnsToCards.fsPath, (err, data) =>
columnsToCardsRead(webviewView, columnsToCards, err, data));
};
async function postColumnsToCards(extensionUri: vscode.Uri, webviewView: vscode.WebviewView) {
if (vscode.workspace.workspaceFolders === undefined)
vscode.window.showInformationMessage("Open workspace first!");
else {
const workspaceFoldersZero = vscode.workspace.workspaceFolders[0].uri;
const destination: vscode.Uri = vscode.Uri.joinPath(workspaceFoldersZero, ".vscode", "helper");
const fileFolderHelper: vscode.Uri = vscode.Uri.joinPath(extensionUri, "net8.0", "win-x64", "publish", "File-Folder-Helper.exe");
const command: string = `${fileFolderHelper.fsPath} s M "${workspaceFoldersZero.fsPath}" -d "${destination.fsPath}"`;
exec(command, (error, stdout, stderr) =>
execCallback(webviewView, destination, error, stdout, stderr));
}
}
function getToken(workspaceState: vscode.Memento, webviewView: vscode.WebviewView) {
webviewView.webview.postMessage({
type: "token",
value: workspaceState.get(key),
});
}
function authenticate(workspaceState: vscode.Memento, webviewView: vscode.WebviewView) {
webviewView.webview.postMessage({
type: "token",
value: workspaceState.get(key),
});
}
function logout(workspaceState: vscode.Memento) {
workspaceState.update(key, "");
}
async function openCard(value: any) {
if (vscode.workspace.workspaceFolders === undefined)
vscode.window.showInformationMessage("Open workspace first!");
else {
if (!value.File)
vscode.window.showInformationMessage("File wasn't passed!");
else {
const textDocument: vscode.TextDocument = await vscode.workspace.openTextDocument(value.File);
vscode.window.showTextDocument(textDocument);
}
}
}
export class ColumnsToCardsWebviewViewProvider implements vscode.WebviewViewProvider {
_view?: vscode.WebviewView;
constructor(private readonly _extensionContext: vscode.ExtensionContext) {
}
public revive(panel: vscode.WebviewView) {
this._view = panel;
}
public resolveWebviewView(webviewView: vscode.WebviewView) {
this._view = webviewView;
webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,
localResourceRoots: [this._extensionContext.extensionUri],
};
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
webviewView.webview.onDidReceiveMessage(async (postMessage: PostMessage) => {
switch (postMessage.type) {
case "logout":
logout(this._extensionContext.workspaceState);
break;
case "authenticate":
authenticate(this._extensionContext.workspaceState, webviewView);
break;
case "get-token":
getToken(this._extensionContext.workspaceState, webviewView);
break;
case "get-columns-to-cards":
postColumnsToCards(this._extensionContext.extensionUri, webviewView);
break;
case "open-card":
openCard(postMessage.value);
break;
case "on-info":
if (!postMessage.value)
return;
vscode.window.showInformationMessage(postMessage.value);
break;
case "on-error":
if (!postMessage.value)
return;
vscode.window.showErrorMessage(postMessage.value);
break;
default:
vscode.window.showErrorMessage(postMessage.type);
break;
}
});
}
private _getHtmlForWebview(webview: vscode.Webview) {
const styleResetUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "media", "reset.css")
);
const styleVSCodeUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "media", "vscode.css")
);
const scriptUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "out", "compiled/ColumnsToCards.js")
);
const styleMainUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "out", "compiled/ColumnsToCards.css")
);
// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--
Use a content security policy to only allow loading images from https or from our extension directory,
and only allow scripts that have a specific nonce.
-->
<meta http-equiv="Content-Security-Policy"
content="img-src https: data:;
style-src 'unsafe-inline' ${webview.cspSource};
script-src 'nonce-${nonce}';">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="${styleResetUri}" rel="stylesheet">
<link href="${styleVSCodeUri}" rel="stylesheet">
<link href="${styleMainUri}" rel="stylesheet">
<script nonce="${nonce}">
const acquiredVsCodeApi = acquireVsCodeApi();
const apiBaseUrl = ${JSON.stringify(apiBaseUrl)}
</script>
</head>
<body>
<script nonce="${nonce}" src="${scriptUri}"></script>
</body>
</html>`;
}
}
export const refreshSidebar = () => refreshSidebarLogic();

View File

@ -1,4 +0,0 @@
export type H2HexColor = {
H2: string;
HexColor: string;
};

View File

@ -1,5 +0,0 @@
export type H2NoCheckboxes = {
H2: string;
Lines: Array<string>;
};

View File

@ -1,7 +0,0 @@
export type H2WithCheckboxes = {
Completed: number;
H2: string;
NotCompleted: number;
Total: number;
};

View File

@ -1,9 +0,0 @@
export type LineNumber = {
Created: number;
H1: number;
FrontMatterYamlEnd: number;
Status: number;
Type: number;
Updated: number;
};

View File

@ -1,5 +0,0 @@
export type PostMessage = {
type: string;
value: any;
};

View File

@ -0,0 +1,115 @@
import * as vscode from "vscode";
// import { authenticate } from "./authenticate";
import { apiBaseUrl } from "./constants";
import { key } from "./constants";
import { getNonce } from "./getNonce";
export class SidebarProvider implements vscode.WebviewViewProvider {
_view?: vscode.WebviewView;
_doc?: vscode.TextDocument;
constructor(private readonly _extensionContext: vscode.ExtensionContext) { }
public resolveWebviewView(webviewView: vscode.WebviewView) {
this._view = webviewView;
webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,
localResourceRoots: [this._extensionContext.extensionUri],
};
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
webviewView.webview.onDidReceiveMessage(async (data) => {
switch (data.type) {
case "logout": {
this._extensionContext.workspaceState.update(key, "");
break;
}
case "authenticate": {
// authenticate(this._extensionContext, () => {
// webviewView.webview.postMessage({
// type: "token",
// value: this._extensionContext.workspaceState.get(key),
// });
// });
webviewView.webview.postMessage({
type: "token",
value: this._extensionContext.workspaceState.get(key),
});
break;
}
case "get-token": {
webviewView.webview.postMessage({
type: "token",
value: this._extensionContext.workspaceState.get(key),
});
break;
}
case "onInfo": {
if (!data.value) {
return;
}
vscode.window.showInformationMessage(data.value);
break;
}
case "onError": {
if (!data.value) {
return;
}
vscode.window.showErrorMessage(data.value);
break;
}
}
});
}
public revive(panel: vscode.WebviewView) {
this._view = panel;
}
private _getHtmlForWebview(webview: vscode.Webview) {
const styleResetUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "media", "reset.css")
);
const styleVSCodeUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "media", "vscode.css")
);
const scriptUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "out", "compiled/sidebar.js")
);
const styleMainUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "out", "compiled/sidebar.css")
);
// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--
Use a content security policy to only allow loading images from https or from our extension directory,
and only allow scripts that have a specific nonce.
-->
<meta http-equiv="Content-Security-Policy" content="img-src https: data:; style-src 'unsafe-inline' ${webview.cspSource
}; script-src 'nonce-${nonce}';">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="${styleResetUri}" rel="stylesheet">
<link href="${styleVSCodeUri}" rel="stylesheet">
<link href="${styleMainUri}" rel="stylesheet">
<script nonce="${nonce}">
const acquiredVsCodeApi = acquireVsCodeApi();
const apiBaseUrl = ${JSON.stringify(apiBaseUrl)}
</script>
</head>
<body>
<script nonce="${nonce}" src="${scriptUri}"></script>
</body>
</html>`;
}
}

View File

@ -1,12 +1,5 @@
import * as vscode from "vscode"; import * as vscode from "vscode";
import { getNonce } from "./getNonce"; import { getNonce } from "./getNonce";
import { apiBaseUrl } from "./constants";
import { PostMessage } from "./PostMessage";
export function refreshWebView(extensionContext: vscode.ExtensionContext): any {
WebViewPanel.kill();
WebViewPanel.createOrShow(extensionContext);
}
export class WebViewPanel { export class WebViewPanel {
/** /**
@ -16,9 +9,11 @@ export class WebViewPanel {
public static readonly viewType = "web-view-panel"; public static readonly viewType = "web-view-panel";
private readonly _panel: vscode.WebviewPanel;
private readonly _extensionUri: vscode.Uri;
private _disposables: vscode.Disposable[] = []; private _disposables: vscode.Disposable[] = [];
public static createOrShow(extensionContext: vscode.ExtensionContext) { public static createOrShow(extensionUri: vscode.Uri) {
const column = vscode.window.activeTextEditor const column = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn ? vscode.window.activeTextEditor.viewColumn
: undefined; : undefined;
@ -41,13 +36,13 @@ export class WebViewPanel {
// And restrict the webview to only loading content from our extension's `media` directory. // And restrict the webview to only loading content from our extension's `media` directory.
localResourceRoots: [ localResourceRoots: [
vscode.Uri.joinPath(extensionContext.extensionUri, "media"), vscode.Uri.joinPath(extensionUri, "media"),
vscode.Uri.joinPath(extensionContext.extensionUri, "out/compiled"), vscode.Uri.joinPath(extensionUri, "out/compiled"),
], ],
} }
); );
WebViewPanel.currentPanel = new WebViewPanel(panel, extensionContext); WebViewPanel.currentPanel = new WebViewPanel(panel, extensionUri);
} }
public static kill() { public static kill() {
@ -55,11 +50,13 @@ export class WebViewPanel {
WebViewPanel.currentPanel = undefined; WebViewPanel.currentPanel = undefined;
} }
public static revive(panel: vscode.WebviewPanel, extensionContext: vscode.ExtensionContext) { public static revive(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
WebViewPanel.currentPanel = new WebViewPanel(panel, extensionContext); WebViewPanel.currentPanel = new WebViewPanel(panel, extensionUri);
} }
private constructor(private readonly _panel: vscode.WebviewPanel, private readonly _extensionContext: vscode.ExtensionContext) { private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
this._panel = panel;
this._extensionUri = extensionUri;
// Set the webview's initial html content // Set the webview's initial html content
this._update(); this._update();
@ -100,41 +97,49 @@ export class WebViewPanel {
const webview = this._panel.webview; const webview = this._panel.webview;
this._panel.webview.html = this._getHtmlForWebview(webview); this._panel.webview.html = this._getHtmlForWebview(webview);
webview.onDidReceiveMessage(async (postMessage: PostMessage) => { webview.onDidReceiveMessage(async (data) => {
switch (postMessage.type) { switch (data.type) {
case "on-info": case "onInfo": {
if (!postMessage.value) if (!data.value) {
return; return;
vscode.window.showInformationMessage(postMessage.value); }
vscode.window.showInformationMessage(data.value);
break; break;
case "on-error": }
if (!postMessage.value) case "onError": {
if (!data.value) {
return; return;
vscode.window.showErrorMessage(postMessage.value); }
break; vscode.window.showErrorMessage(data.value);
default:
vscode.window.showErrorMessage(postMessage.type);
break; break;
}
// case "tokens": {
// await Util.globalState.update(accessTokenKey, data.accessToken);
// await Util.globalState.update(refreshTokenKey, data.refreshToken);
// break;
// }
} }
}); });
} }
private _getHtmlForWebview(webview: vscode.Webview) { private _getHtmlForWebview(webview: vscode.Webview) {
const styleResetUri = webview.asWebviewUri( // // And the uri we use to load this script in the webview
vscode.Uri.joinPath(this._extensionContext.extensionUri, "media", "reset.css")
);
const styleVSCodeUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "media", "vscode.css")
);
const scriptUri = webview.asWebviewUri( const scriptUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "out", "compiled/DisplayDate.js") vscode.Uri.joinPath(this._extensionUri, "out/compiled", "WebView.js")
);
const styleMainUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionContext.extensionUri, "out", "compiled/DisplayDate.css")
); );
// Use a nonce to only allow a specific script to be run. // Uri to load styles into webview
const stylesResetUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "media", "reset.css")
);
const stylesMainUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "media", "vscode.css")
);
// const cssUri = webview.asWebviewUri(
// vscode.Uri.joinPath(this._extensionUri, "out", "compiled/swiper.css")
// );
// // Use a nonce to only allow specific scripts to be run
const nonce = getNonce(); const nonce = getNonce();
return `<!DOCTYPE html> return `<!DOCTYPE html>
@ -145,22 +150,16 @@ export class WebViewPanel {
Use a content security policy to only allow loading images from https or from our extension directory, Use a content security policy to only allow loading images from https or from our extension directory,
and only allow scripts that have a specific nonce. and only allow scripts that have a specific nonce.
--> -->
<meta http-equiv="Content-Security-Policy" <meta http-equiv="Content-Security-Policy" content="img-src https: data:; style-src 'unsafe-inline' ${webview.cspSource}; script-src 'nonce-${nonce}';">
content="img-src https: data:;
style-src 'unsafe-inline' ${webview.cspSource};
script-src 'nonce-${nonce}';">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="${styleResetUri}" rel="stylesheet"> <link href="${stylesResetUri}" rel="stylesheet">
<link href="${styleVSCodeUri}" rel="stylesheet"> <link href="${stylesMainUri}" rel="stylesheet">
<link href="${styleMainUri}" rel="stylesheet">
<script nonce="${nonce}"> <script nonce="${nonce}">
const acquiredVsCodeApi = acquireVsCodeApi();
const apiBaseUrl = ${JSON.stringify(apiBaseUrl)}
</script> </script>
</head> </head>
<body> <body>
<script nonce="${nonce}" src="${scriptUri}"></script>
</body> </body>
<script src="${scriptUri}" nonce="${nonce}">
</html>`; </html>`;
} }
} }

View File

@ -0,0 +1,34 @@
// import * as vscode from "vscode";
// import { apiBaseUrl } from "./constants";
// import { key } from "./constants";
// import * as polka from "polka";
// export const authenticate = (extensionContext: vscode.ExtensionContext, fn: () => void) => {
// const app = polka();
// app.get(`/auth/:token`, async (req, res) => {
// const { token } = req.params;
// if (!token) {
// res.end(`<h1>something went wrong</h1>`);
// return;
// }
// await extensionContext.workspaceState.update(key, token);
// fn();
// res.end(`<h1>auth was successful, you can close this now</h1>`);
// (app as any).server.close();
// });
// app.listen(54321, (err: Error) => {
// if (err) {
// vscode.window.showErrorMessage(err.message);
// } else {
// vscode.commands.executeCommand(
// "vscode.open",
// vscode.Uri.parse(`${apiBaseUrl}/auth/github`)
// );
// }
// });
// };

View File

@ -1,2 +1,2 @@
export const apiBaseUrl: string = "http://localhost:3002"; export const key = "type-script-helper";
export const key: string = "type-script-helper"; export const apiBaseUrl = "http://localhost:3002";

View File

@ -2,28 +2,28 @@
// Import the module and reference it with the alias vscode in your code below // Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as kanbanHelper from './kanbanHelper'; import * as kanbanHelper from './kanbanHelper';
import * as markdownHelper from './markdownHelper';
import * as promiseLinesHelper from './promiseLinesHelper';
import * as replaceLinesHelper from './replaceLinesHelper'; import * as replaceLinesHelper from './replaceLinesHelper';
import * as readOnlyLinesHelper from './readOnlyLinesHelper'; import * as readOnlyLinesHelper from './readOnlyLinesHelper';
import { WebViewPanel, refreshWebView } from "./WebViewPanel"; import * as promiseLinesHelper from './promiseLinesHelper';
import { ColumnsToCardsWebviewViewProvider, refreshSidebar } from "./ColumnsToCardsWebviewViewProvider"; import { SidebarProvider } from "./SidebarProvider";
import { WebViewPanel } from "./WebViewPanel";
// This method is called when your extension is activated // This method is called when your extension is activated
// Your extension is activated the very first time the command is executed // Your extension is activated the very first time the command is executed
export async function activate(extensionContext: vscode.ExtensionContext) { export async function activate(extensionContext: vscode.ExtensionContext) {
const columnsToCardsWebviewViewProvider = new ColumnsToCardsWebviewViewProvider(extensionContext); const sidebarProvider = new SidebarProvider(extensionContext);
const item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right); const item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
item.text = "$(beaker) Show Kanban"; item.text = "$(beaker) Show Kanban";
// item.command = "kanban.show"; // item.command = "kanban.show";
item.show(); item.show();
extensionContext.subscriptions.push(vscode.window.registerWebviewViewProvider("columns-to-cards-webview-view-provider", columnsToCardsWebviewViewProvider));
extensionContext.subscriptions.push(vscode.window.registerWebviewViewProvider("kanban-sidebar", sidebarProvider));
// Use the console to output diagnostic information (console.log) and errors (console.error) // Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated // This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "type-script-helper":1.6.2 is now active!'); console.log('Congratulations, your extension "type-script-helper" is now active!');
// // The command has been defined in the package.json file // // The command has been defined in the package.json file
// // Now provide the implementation of the command with registerCommand // // Now provide the implementation of the command with registerCommand
@ -37,11 +37,10 @@ export async function activate(extensionContext: vscode.ExtensionContext) {
// context.subscriptions.push(disposable); // context.subscriptions.push(disposable);
const commands = [ const commands = [
vscode.commands.registerCommand("kanban.refreshBoth", () => { kanbanHelper.refreshBoth(extensionContext); }), // vscode.commands.registerCommand("kanban.apiAuthenticate", kanbanHelper.apiAuthenticate(extensionContext)),
vscode.commands.registerCommand("kanban.refreshSidebar", refreshSidebar), vscode.commands.registerCommand("kanban.newEntry", kanbanHelper.newEntry(sidebarProvider)),
vscode.commands.registerCommand("kanban.refreshWebView", () => { refreshWebView(extensionContext); }), vscode.commands.registerCommand("kanban.refresh", await kanbanHelper.refresh()),
vscode.commands.registerCommand("kanban.openWithTextEditor", kanbanHelper.openWithTextEditor), // vscode.commands.registerCommand("kanban.debugReload", await kanbanHelper.debugReload(extensionContext)),
vscode.commands.registerCommand("markdown.newMarkdownFile", markdownHelper.newMarkdownFile),
vscode.commands.registerCommand('promiseLinesHelper.codeGeneratorQuickPick', promiseLinesHelper.codeGeneratorQuickPick), vscode.commands.registerCommand('promiseLinesHelper.codeGeneratorQuickPick', promiseLinesHelper.codeGeneratorQuickPick),
vscode.commands.registerCommand('promiseLinesHelper.insertDateTime', promiseLinesHelper.insertDateTime), vscode.commands.registerCommand('promiseLinesHelper.insertDateTime', promiseLinesHelper.insertDateTime),
vscode.commands.registerCommand('promiseLinesHelper.transformToPopperCase', promiseLinesHelper.transformToPopperCase), vscode.commands.registerCommand('promiseLinesHelper.transformToPopperCase', promiseLinesHelper.transformToPopperCase),
@ -68,7 +67,7 @@ export async function activate(extensionContext: vscode.ExtensionContext) {
vscode.commands.registerCommand('replaceLinesHelper.unwrapSql', replaceLinesHelper.unwrapSql), vscode.commands.registerCommand('replaceLinesHelper.unwrapSql', replaceLinesHelper.unwrapSql),
vscode.commands.registerCommand('replaceLinesHelper.wrapSqlCSharp', replaceLinesHelper.wrapSqlCSharp), vscode.commands.registerCommand('replaceLinesHelper.wrapSqlCSharp', replaceLinesHelper.wrapSqlCSharp),
vscode.commands.registerCommand('replaceLinesHelper.wrapSqlVB', replaceLinesHelper.wrapSqlVB), vscode.commands.registerCommand('replaceLinesHelper.wrapSqlVB', replaceLinesHelper.wrapSqlVB),
vscode.commands.registerCommand("webView.webView", () => { WebViewPanel.createOrShow(extensionContext); }) vscode.commands.registerCommand("webView.webView", () => { WebViewPanel.createOrShow(extensionContext.extensionUri); })
]; ];
commands.forEach(command => extensionContext.subscriptions.push(command)); commands.forEach(command => extensionContext.subscriptions.push(command));

View File

@ -1,35 +1,40 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { refreshWebView } from './WebViewPanel'; // import { authenticate } from "./authenticate";
import { paramCase } from './promiseLinesHelper'; import { SidebarProvider } from './SidebarProvider';
import { refreshSidebar } from './ColumnsToCardsWebviewViewProvider'; // import { WebViewPanel } from "./WebViewPanel";
export function refreshBoth(extensionContext: vscode.ExtensionContext): any { export function newEntry(sidebarProvider: SidebarProvider): any {
refreshSidebar(); const { activeTextEditor } = vscode.window;
refreshWebView(extensionContext); if (!activeTextEditor) {
setTimeout(() => { vscode.commands.executeCommand("workbench.action.webview.openDeveloperTools"); }, 500); vscode.window.showInformationMessage("No active text editor");
return;
}
const text = activeTextEditor.document.getText(
activeTextEditor.selection
);
sidebarProvider._view?.webview.postMessage({
type: "new-entry",
value: text,
});
} }
async function openWithTextEditorLogic(): Promise<any> { // export function apiAuthenticate(extensionContext: vscode.ExtensionContext): any {
if (vscode.workspace.workspaceFolders === undefined) { // try {
vscode.window.showInformationMessage("Open workspace first!"); // authenticate(extensionContext, () => { });
return; // } catch (err) {
} // console.log(err);
if (vscode.window.tabGroups.activeTabGroup.activeTab === undefined) { // }
vscode.window.showInformationMessage("Open a tab first!"); // }
return;
} export async function refresh(): Promise<any> {
const activeTabLabel = vscode.window.tabGroups.activeTabGroup.activeTab.label; await vscode.commands.executeCommand("workbench.action.closeSidebar");
const paramCaseActiveTabLabel: string = paramCase(activeTabLabel); await vscode.commands.executeCommand("workbench.view.extension.kanban-sidebar-view");
vscode.window.showInformationMessage(`Searching for <${paramCaseActiveTabLabel}>`);
const fileUris: vscode.Uri[] = await vscode.workspace.findFiles(`**/${paramCaseActiveTabLabel}*`);
if (fileUris.length === 0) {
vscode.window.showInformationMessage(`Didn't find a file matching <${paramCaseActiveTabLabel}>!`);
return;
}
for (let i = 0; i < fileUris.length; ++i) {
const textDocument: vscode.TextDocument = await vscode.workspace.openTextDocument(fileUris[i]);
await vscode.window.showTextDocument(textDocument);
}
} }
export const openWithTextEditor = () => openWithTextEditorLogic(); // export async function debugReload(extensionContext: vscode.ExtensionContext): Promise<any> {
// WebViewPanel.kill();
// WebViewPanel.createOrShow(extensionContext.extensionUri);
// await vscode.commands.executeCommand("workbench.action.closeSidebar");
// await vscode.commands.executeCommand("workbench.view.extension.kanban-sidebar-view");
// setTimeout(() => { vscode.commands.executeCommand("workbench.action.webview.openDeveloperTools"); }, 500);
// }

View File

@ -1,22 +0,0 @@
import * as vscode from 'vscode';
import { paramCase } from './promiseLinesHelper';
async function newMarkdownFileLogic(): Promise<any> {
console.log(vscode.window.tabGroups.activeTabGroup.activeTab?.label);
if (vscode.workspace.workspaceFolders === undefined) {
vscode.window.showInformationMessage("Open workspace first!");
return;
}
const workspaceFoldersZero = vscode.workspace.workspaceFolders[0].uri;
const cardTitle = await vscode.window.showInputBox({ prompt: 'Provide title for card.' });
if (cardTitle === undefined)
return;
const paramCaseCardTitle: string = paramCase(cardTitle);
const fileUri: vscode.Uri = vscode.Uri.joinPath(workspaceFoldersZero, `${paramCaseCardTitle}.md`);
const buffer: Buffer = Buffer.from(`# ${cardTitle}`, 'utf8');
await vscode.workspace.fs.writeFile(fileUri, buffer);
const textDocument: vscode.TextDocument = await vscode.workspace.openTextDocument(fileUri);
vscode.window.showTextDocument(textDocument);
}
export const newMarkdownFile = () => newMarkdownFileLogic();

View File

@ -177,7 +177,7 @@ function transformToPopperCaseLogic(): undefined {
return undefined; return undefined;
} }
export function paramCase(str: string) { function paramCase(str: string) {
return str return str
.replace( .replace(
/([A-Z]+(.))/g, /([A-Z]+(.))/g,

View File

@ -0,0 +1,23 @@
import * as path from 'path';
import { runTests } from '@vscode/test-electron';
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests', err);
process.exit(1);
}
}
main();

View File

@ -0,0 +1,15 @@
import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';
suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});

View File

@ -0,0 +1,38 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';
export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
color: true
});
const testsRoot = path.resolve(__dirname, '..');
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}

View File

@ -1,11 +1,3 @@
---
type: "note"
created: "2023-07-07T16:15:27.822Z"
updated: "2023-07-07T16:15:27.822Z"
---
# vsc-extension-quickstart
# Welcome to your VS Code Extension # Welcome to your VS Code Extension
## What's in the folder ## What's in the folder

View File

@ -1,25 +0,0 @@
<script lang="ts">
import type { Card } from "../../src/Card";
export let key: string;
export let card: Card;
export let index: number;
</script>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore missing-declaration -->
<li id={index.toString()}>
<!-- svelte-ignore a11y-invalid-attribute -->
<a
href="#{index.toString()}"
title="{key}"
on:click={async () => {
acquiredVsCodeApi.postMessage({
type: "open-card",
value: { File: card.File },
});
}}
>
{card.H1}
</a>
</li>

View File

@ -1,19 +0,0 @@
<script lang="ts">
import type { Card } from "../../src/Card";
import CardComponent from "./CardComponent.svelte";
export let key: string = "";
export let value: Array<Card> = [];
</script>
{#if !value}
<div>loading...</div>
{:else}
<hr>
<h1>{key}</h1>
<ul>
{#each value as card, index}
<CardComponent {key} {card} {index} />
{/each}
</ul>
{/if}

View File

@ -1,33 +0,0 @@
<script lang="ts">
import { onMount } from "svelte";
import Cards from "./Cards.svelte";
import type { Card } from "../../src/Card";
import type { PostMessage } from "../../src/PostMessage";
let columnsToCards: Record<string, Array<Card>> = {};
onMount(async () => {
window.addEventListener("message", async (event) => {
const postMessage: PostMessage = event.data;
switch (postMessage.type) {
case "columns-to-cards": {
columnsToCards = postMessage.value;
break;
}
}
});
const postMessage: PostMessage = {
type: "get-columns-to-cards",
value: undefined,
};
acquiredVsCodeApi.postMessage(postMessage);
});
</script>
{#if Object.entries(columnsToCards).length == 0}
<div>loading...</div>
{:else}
{#each Object.entries(columnsToCards) as [key, value], index (key)}
<Cards {key} {value} />
{/each}
{/if}

View File

@ -1,4 +0,0 @@
<script lang="ts">
</script>
<h1>2023-09-23-15-20</h1>

View File

@ -0,0 +1,87 @@
<script lang="ts">
import { onMount } from "svelte";
import type { User } from "../types";
import type { Entry } from "../types";
export let user: User;
export let accessToken: string;
let text = "";
let entries: Array<Entry> = [];
async function addEntry(t: string) {
const response = await fetch(`${apiBaseUrl}/entry`, {
method: "POST",
body: JSON.stringify({
text: t,
}),
headers: {
"content-type": "application/json",
authorization: `Bearer ${accessToken}`,
},
});
const { entry } = await response.json();
entries = [entry, ...entries];
}
onMount(async () => {
window.addEventListener("message", async (event) => {
const message = event.data;
switch (message.type) {
case "new-entry":
addEntry(message.value);
break;
}
});
const response = await fetch(`${apiBaseUrl}/entry`, {
headers: {
authorization: `Bearer ${accessToken}`,
},
});
const payload = await response.json();
entries = payload.entries;
});
</script>
<div>Hello: {user.name}</div>
<form
on:submit|preventDefault={async () => {
addEntry(text);
text = "";
}}
>
<input bind:value={text} />
</form>
<ul>
{#each entries as entry (entry.id)}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore missing-declaration -->
<li
class:complete={entry.completed}
on:click={async () => {
entry.completed = !entry.completed;
const response = await fetch(`${apiBaseUrl}/entry`, {
method: "PUT",
body: JSON.stringify({
id: entry.id,
}),
headers: {
"content-type": "application/json",
authorization: `Bearer ${accessToken}`,
},
});
console.log(await response.json());
}}
>
{entry.text}
</li>
{/each}
</ul>
<style>
.complete {
text-decoration: line-through;
}
</style>

View File

@ -0,0 +1,70 @@
<script lang="ts">
import { onMount } from "svelte";
import type { User } from "../types";
import Entries from "./Entries.svelte";
let accessToken = "";
let loading = true;
let user: User | null = null;
let page: "entries" | "contact" =
acquiredVsCodeApi.getState()?.page || "entries";
$: {
acquiredVsCodeApi.setState({ page });
}
onMount(async () => {
window.addEventListener("message", async (event) => {
const message = event.data;
switch (message.type) {
case "token":
accessToken = message.value;
const response = await fetch(`${apiBaseUrl}/me`, {
headers: {
authorization: `Bearer ${accessToken}`,
},
});
const data = await response.json();
user = data.user;
loading = false;
}
});
acquiredVsCodeApi.postMessage({ type: "get-token", value: undefined });
});
</script>
{#if loading}
<div>loading...</div>
{:else if user}
{#if page === "entries"}
<Entries {user} {accessToken} />
<button
on:click={() => {
page = "contact";
}}>go to contact</button
>
{:else}
<div>Contact me here: adlkfjjqioefeqio</div>
<button
on:click={() => {
page = "entries";
}}>go back</button
>
{/if}
<!-- svelte-ignore missing-declaration -->
<button
on:click={() => {
accessToken = "";
user = null;
acquiredVsCodeApi.postMessage({ type: "logout", value: undefined });
}}>logout</button
>
{:else}
<!-- svelte-ignore missing-declaration -->
<button
on:click={() => {
acquiredVsCodeApi.postMessage({ type: "authenticate", value: undefined });
}}>login with GitHub</button
>
{/if}

View File

@ -0,0 +1,4 @@
<script lang="ts">
</script>
<h1>WebView 2023-09-23-15-20</h1>

View File

@ -1,10 +1,10 @@
import * as _vscode from "vscode"; import * as _vscode from "vscode";
import type { PostMessage } from "../types";
declare global { declare global {
const acquiredVsCodeApi: { const acquiredVsCodeApi: {
postMessage: (PostMessage) => void; postMessage: ({ type: string, value: any }) => void;
getState: () => any; getState: () => any;
setState: (state: any) => void; setState: (state: any) => void;
}; };
const apiBaseUrl: string;
} }

View File

@ -1,4 +1,4 @@
import App from "../components/DisplayDate.svelte"; import App from "../components/Sidebar.svelte";
const app = new App({ const app = new App({
target: document.body, target: document.body,

View File

@ -1,4 +1,4 @@
import App from "../components/ColumnsToCards.svelte"; import App from "../components/WebView.svelte";
const app = new App({ const app = new App({
target: document.body, target: document.body,

View File

@ -0,0 +1,11 @@
export type User = {
id: string;
name: string;
githubId: string;
};
export type Entry = {
text: string;
completed: boolean;
id: number;
};