Update project configuration and dependencies for version 0.0.6

- Add .prettierrc for code formatting
- Update package and jsr.json version to 0.0.6
- Upgrade @kksh/api dependency to version 0.1.1
- Refactor imports in source files to align with new structure
This commit is contained in:
Huakun Shen 2025-02-06 22:22:09 -05:00
parent 00ba6e0255
commit 2e7e6361e3
No known key found for this signature in database
8 changed files with 139 additions and 132 deletions

4
.prettierrc Normal file
View File

@ -0,0 +1,4 @@
{
"semi": false,
"trailingComma": "none"
}

View File

@ -1,6 +1,6 @@
import { watch } from "fs" import { watch } from "fs"
import { join } from "path" import { join } from "path"
import { refreshTemplateWorkerExtension } from "@kksh/api/dev" import { refreshTemplateWorkerCommand } from "@kksh/api/dev"
import { $ } from "bun" import { $ } from "bun"
const entrypoints = ["./src/index.ts"] const entrypoints = ["./src/index.ts"]
@ -11,7 +11,7 @@ async function build() {
await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}` await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}`
} }
if (Bun.argv.includes("dev")) { if (Bun.argv.includes("dev")) {
await refreshTemplateWorkerExtension() await refreshTemplateWorkerCommand()
} }
} catch (error) { } catch (error) {
console.error(error) console.error(error)

BIN
bun.lockb

Binary file not shown.

View File

@ -1,6 +1,6 @@
{ {
"name": "@kunkun/kunkun-ext-browser-bookmark", "name": "@kunkun/kunkun-ext-browser-bookmark",
"version": "0.0.5", "version": "0.0.6",
"license": "MIT", "license": "MIT",
"exports": "./mod.ts", "exports": "./mod.ts",
"publish": { "publish": {

View File

@ -6,7 +6,7 @@
"name": "Huakun", "name": "Huakun",
"url": "https://huakunshen.com" "url": "https://huakunshen.com"
}, },
"version": "0.0.5", "version": "0.0.6",
"repository": "https://github.com/kunkunsh/kunkun-ext-browser-bookmark", "repository": "https://github.com/kunkunsh/kunkun-ext-browser-bookmark",
"type": "module", "type": "module",
"kunkun": { "kunkun": {
@ -98,7 +98,7 @@
"build": "bun build.ts" "build": "bun build.ts"
}, },
"dependencies": { "dependencies": {
"@kksh/api": "^0.0.48", "@kksh/api": "^0.1.1",
"i18next": "^23.15.1", "i18next": "^23.15.1",
"valibot": "^0.40.0" "valibot": "^0.40.0"
}, },

View File

@ -1,4 +1,4 @@
import { fs, os, path, shell, toast } from "@kksh/api/ui/worker" import { fs, os, path, shell, toast } from "@kksh/api/ui/template"
import * as v from "valibot" import * as v from "valibot"
import { ChromeBookmarksFile } from "./types" import { ChromeBookmarksFile } from "./types"
import type { Browser, ChromeBookmark, Platform } from "./types" import type { Browser, ChromeBookmark, Platform } from "./types"

View File

@ -1,140 +1,143 @@
import { import {
Action, expose,
app, Icon,
expose, IconEnum,
Form, List,
fs, open,
Icon, toast,
IconEnum, ui,
List, TemplateUiCommand
NodeNameEnum, } from "@kksh/api/ui/template"
open, import { createBookmarkLoader, type Bookmark } from "./bookmark"
os,
path,
shell,
toast,
ui,
WorkerExtension
} from "@kksh/api/ui/worker"
import { ChromeBookmarks, createBookmarkLoader, type Bookmark } from "./bookmark"
import { setupI18n, t } from "./i18n"
import type { Platform } from "./types"
function bookmarkToItem(bookmark: Bookmark, options: { browserIcon: Icon }): List.Item { function bookmarkToItem(
return new List.Item({ bookmark: Bookmark,
title: bookmark.name, options: { browserIcon: Icon }
subTitle: bookmark.subtitle, ): List.Item {
value: bookmark.url, return new List.Item({
icon: bookmark.favicon title: bookmark.name,
? new Icon({ subTitle: bookmark.subtitle,
type: IconEnum.RemoteUrl, value: bookmark.url,
value: bookmark.favicon icon: bookmark.favicon
}) ? new Icon({
: new Icon({ type: IconEnum.RemoteUrl,
type: IconEnum.Iconify, value: bookmark.favicon
value: options.browserIcon.value })
}), : new Icon({
accessories: [ type: IconEnum.Iconify,
new List.ItemAccessory({ value: options.browserIcon.value
icon: new Icon({ }),
type: IconEnum.Iconify, accessories: [
value: options.browserIcon.value new List.ItemAccessory({
}) icon: new Icon({
}) type: IconEnum.Iconify,
] value: options.browserIcon.value
}) })
})
]
})
} }
class BrowserBookmark extends WorkerExtension { class BrowserBookmark extends TemplateUiCommand {
async onFormSubmit(value: Record<string, any>): Promise<void> { async onFormSubmit(value: Record<string, any>): Promise<void> {
console.log("Form submitted", value) console.log("Form submitted", value)
toast.success(`Form submitted: ${JSON.stringify(value)}`) toast.success(`Form submitted: ${JSON.stringify(value)}`)
} }
async load() { async load() {
ui.showLoadingBar(true) ui.showLoadingBar(true)
ui.setSearchBarPlaceholder("Search for bookmarks") ui.setSearchBarPlaceholder("Search for bookmarks")
ui.render(new List.List({})) ui.render(new List.List({}))
// const platform: Platform = await os.platform() // const platform: Platform = await os.platform()
const [chromeBookmarks, edgeBookmarks, firefoxBookmarks] = await Promise.all([ const [chromeBookmarks, edgeBookmarks, firefoxBookmarks] =
createBookmarkLoader("chrome").then((loader) => loader?.load() ?? []), await Promise.all([
createBookmarkLoader("edge").then((loader) => loader?.load() ?? []), createBookmarkLoader("chrome").then((loader) => loader?.load() ?? []),
createBookmarkLoader("firefox").then((loader) => loader?.load() ?? []) createBookmarkLoader("edge").then((loader) => loader?.load() ?? []),
]) createBookmarkLoader("firefox").then((loader) => loader?.load() ?? [])
])
const sections: List.Section[] = [] const sections: List.Section[] = []
if (firefoxBookmarks.length > 0) { if (firefoxBookmarks.length > 0) {
sections.push( sections.push(
new List.Section({ new List.Section({
title: "Firefox", title: "Firefox",
subtitle: "Firefox", subtitle: "Firefox",
items: firefoxBookmarks.map((bookmark) => items: firefoxBookmarks.map((bookmark) =>
bookmarkToItem(bookmark, { bookmarkToItem(bookmark, {
browserIcon: new Icon({ type: IconEnum.Iconify, value: "logos:firefox" }) browserIcon: new Icon({
}) type: IconEnum.Iconify,
) value: "logos:firefox"
}) })
) })
} )
})
)
}
if (chromeBookmarks.length > 0) { if (chromeBookmarks.length > 0) {
sections.push( sections.push(
new List.Section({ new List.Section({
title: "Chrome", title: "Chrome",
subtitle: "Chrome", subtitle: "Chrome",
items: chromeBookmarks.map((bookmark) => items: chromeBookmarks.map((bookmark) =>
bookmarkToItem(bookmark, { bookmarkToItem(bookmark, {
browserIcon: new Icon({ type: IconEnum.Iconify, value: "logos:chrome" }) browserIcon: new Icon({
}) type: IconEnum.Iconify,
) value: "logos:chrome"
}) })
) })
} )
if (edgeBookmarks.length > 0) { })
sections.push( )
new List.Section({ }
title: "Edge", if (edgeBookmarks.length > 0) {
subtitle: "Edge", sections.push(
items: edgeBookmarks.map((bookmark) => new List.Section({
bookmarkToItem(bookmark, { title: "Edge",
browserIcon: new Icon({ type: IconEnum.Iconify, value: "logos:microsoft-edge" }) subtitle: "Edge",
}) items: edgeBookmarks.map((bookmark) =>
) bookmarkToItem(bookmark, {
}) browserIcon: new Icon({
) type: IconEnum.Iconify,
} value: "logos:microsoft-edge"
})
})
)
})
)
}
return ui return ui
.setSearchBarPlaceholder("Enter a search term, and press enter to search") .setSearchBarPlaceholder("Enter a search term, and press enter to search")
.then(async () => { .then(async () => {
return ui.render(new List.List({ sections })) return ui.render(new List.List({ sections }))
}) })
.finally(() => { .finally(() => {
ui.showLoadingBar(false) ui.showLoadingBar(false)
}) })
} }
async onActionSelected(actionValue: string): Promise<void> { async onActionSelected(actionValue: string): Promise<void> {
switch (actionValue) { switch (actionValue) {
case "open": case "open":
break break
default: default:
break break
} }
} }
onSearchTermChange(term: string): Promise<void> { onSearchTermChange(term: string): Promise<void> {
return Promise.resolve() return Promise.resolve()
} }
onListItemSelected(value: string): Promise<void> { onListItemSelected(value: string): Promise<void> {
console.log("Item selected:", value) console.log("Item selected:", value)
if (value.startsWith("http")) { if (value.startsWith("http")) {
open.url(value) open.url(value)
} }
return Promise.resolve() return Promise.resolve()
} }
} }
expose(new BrowserBookmark()) expose(new BrowserBookmark())

View File

@ -1,4 +1,4 @@
import { os } from "@kksh/api/ui/worker" import { os } from "@kksh/api/ui/template"
import * as v from "valibot" import * as v from "valibot"
export type Platform = Awaited<ReturnType<typeof os.platform>> export type Platform = Awaited<ReturnType<typeof os.platform>>