Skip to content

Commit

Permalink
feat(): Update Board feature
Browse files Browse the repository at this point in the history
Added display of page content and Linked References on board pages.
  • Loading branch information
YU000jp committed Jan 3, 2025
1 parent c465993 commit 189bb3e
Show file tree
Hide file tree
Showing 23 changed files with 537 additions and 423 deletions.
110 changes: 75 additions & 35 deletions src/batchTileView/embed/generateBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import { BlockEntity, IBatchBlock, PageEntity } from "@logseq/libs/dist/LSPlugin
import { t } from "logseq-l10n"
import { advancedQuery, queryCodeContainsTag } from "./advancedQuery"
import { keyCommonBatchBoardIncludeWord } from "../../settings"
import { hideMainContent } from "../lib"



let processingGenerateEmbed = false
export const generateEmbed = async (
type: string,
pageName: string,
blocks: { uuid: BlockEntity["uuid"] }[]
) => {

if (processingGenerateEmbed) return
processingGenerateEmbed = true
setTimeout(() => processingGenerateEmbed = false, 900)

await logseq.Editor.exitEditingMode()

logseq.showMainUI({ autoFocus: false })
Expand All @@ -33,8 +40,7 @@ export const generateEmbed = async (
) {
logseq.updateSettings({ [type]: array })// 今回分を保存

let sibling = false
const batch: IBatchBlock[] = []
const boardBatch: IBatchBlock[] = []
const typeMapping = {
"Projects": "Projects",
"Areas of Responsibility": "Areas",
Expand All @@ -43,42 +49,44 @@ export const generateEmbed = async (
}
const settingKey = typeMapping[type as keyof typeof typeMapping]
if (settingKey)
sibling = eachCategoryCreateBatchEmbed(
eachCategoryCreateBatchEmbed(
array,
logseq.settings![keyCommonBatchBoardIncludeWord + settingKey] as string,
batch
boardBatch
)

if (batch.length > 0)
await refreshPageBlocks(blocks, pageName, batch, type, sibling)
if (boardBatch.length > 0)
await refreshPageBlocks(blocks, pageName, boardBatch, type)
}
} else
// 見つからなかった場合
await removeBlocksAndNotify(blocks, pageName)
await removeBlocksAndNotify(blocks, pageName, type)


// ブロックの編集モードを終了
await logseq.Editor.exitEditingMode()

logseq.hideMainUI({ restoreEditingCursor: false })
processingGenerateEmbed = false
}



//カテゴリ分けごとにEmbedを生成 (カテゴリに含まれない場合は、その他に分類)
const eachCategoryCreateBatchEmbed = (array: string[], config: string, batch: IBatchBlock[]): boolean => {

if (config === "") {
for (const v of array)
batch.push({ content: `{{embed [[${v}]]}}` })
return false
} else {
const eachCategoryCreateBatchEmbed = (array: string[], config: string, boardBatch: IBatchBlock[]) => {

if (config === "")
boardBatch.push({
content: `# ${t("All")}`,
children: array.map((v) => ({ content: `{{embed [[${v}]]}}` }))
})
else {
const categories = config.split("\n")

for (const category of categories) {
const categoryArray = array.filter((v) => v.includes(category))
if (categoryArray.length > 0) {
batch.push({
boardBatch.push({
content: `## ${category}`, // embedを使用
children: categoryArray.map((v) => ({ content: `{{embed [[${v}]]}}` }))
})
Expand All @@ -88,11 +96,10 @@ const eachCategoryCreateBatchEmbed = (array: string[], config: string, batch: IB
}
// その他のカテゴリーに分類されなかったページを追加
if (array.length > 0)
batch.push({
boardBatch.push({
content: `## ${t("Others")}`, // 分類なし
children: array.map((v) => ({ content: `{{embed [[${v}]]}}` }))
})
return true
}
}

Expand All @@ -102,37 +109,70 @@ const refreshPageBlocks = async (
pageName: string,
batch: IBatchBlock[],
type: string,
sibling: boolean,
) => {

// 一時的にDOMエレメントを非表示にする
hideMainContent('#main-content-container div[id^="quickly-para-method-plugin/"] ')

// 全てのブロックを削除
for (const block of blocks)
await logseq.Editor.removeBlock(block.uuid)
await clearBlocks(blocks)

// 300ms待機
await new Promise((resolve) => setTimeout(resolve, 300))
// 600ms待機
await new Promise((resolve) => setTimeout(resolve, 600))

// メインページの最初のブロックを作成
const newBlockEntity = await logseq.Editor.appendBlockInPage(pageName, "") as { uuid: BlockEntity["uuid"] } | null
if (newBlockEntity) {
await logseq.Editor.insertBatchBlock(newBlockEntity.uuid, batch, { before: false, sibling })

// 先頭行
await logseq.Editor.updateBlock(newBlockEntity.uuid, `# [[${type}]]`)
// await logseq.Editor.removeBlock(newBlockEntity.uuid)
}
const newBlock = await logseq.Editor.appendBlockInPage(pageName, "") as { uuid: BlockEntity["uuid"] } | null
//下にくるブロックが先
if (newBlock)
await generateContentForMainPageContent(newBlock, type, batch)
}


// 全てのブロックを削除
const removeBlocksAndNotify = async (
blocks: { uuid: BlockEntity["uuid"] }[],
pageName: string
pageName: string,
type: string,
) => {
await refreshPageBlocks(blocks, pageName, [{ content: t("No page found") }], type)
}


const generateContentForMainPageContent = async (
newBlock: { uuid: BlockEntity["uuid"] },
type: string,
boardBatch: IBatchBlock[]
) => {

const batch: IBatchBlock[] = []
// batchの先頭に追加
batch.unshift({
content: `# ${t("Board")}`,
children: boardBatch,
})

// batchの最後尾に追加
if (logseq.settings!.showPageContent as boolean === true) {
batch.push({
content: `# ${t("Page content")}`,
children: [{ content: `{{embed [[${type}]]}}` }]
})
}
if (logseq.settings!.showLinkedReferences as boolean === true) {
batch.push({
content: `# ${t("Linked References")}`,
children: [{ content: `{{query [[${type}]]}}` }]
})
}

// バッチを挿入
await logseq.Editor.insertBatchBlock(newBlock.uuid, batch, { before: true, sibling: true })
// ブロックを削除
await logseq.Editor.removeBlock(newBlock.uuid)
}


const clearBlocks = async (blocks: { uuid: BlockEntity["uuid"] }[]) => {
for (const block of blocks)
await logseq.Editor.removeBlock(block.uuid)
//300ms待機
await new Promise((resolve) => setTimeout(resolve, 300))
// メインページの最初のブロックを作成
await logseq.Editor.appendBlockInPage(pageName, t("No page found")) as { uuid: BlockEntity["uuid"] } | null
}
14 changes: 12 additions & 2 deletions src/batchTileView/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ const addLeftMenuNavHeader = (divId: string, icon: string, title: string, baseNa

const anchor = document.createElement("a")
anchor.className = "item group flex items-center text-sm font-medium rounded-md"
anchor.addEventListener("click", () => logseq.App.pushState('page', { name: (baseName + "/" + title) }) // ページを開く
)

// ページを開く
setTimeout(() => {
anchor.addEventListener("click", () => logseq.App.pushState('page', { name: (baseName + "/" + title) }))
}, 400)

div.appendChild(anchor)

const spanIcon = document.createElement("span")
Expand All @@ -70,6 +74,12 @@ export const clearEle = (selector: string) => {
if (ele) ele.remove()
}

export const hideMainContent = (selector: string) => {
const ele = parent.document.querySelector(selector) as HTMLElement
if (ele)
ele.style.display = "none"
}

// const removeProvideStyle = (className: string) => {
// const doc = parent.document.head.querySelector(
// `style[data-injected-style^="${className}"]`
Expand Down
53 changes: 32 additions & 21 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { t } from "logseq-l10n" //https://github.com/sethyuan/logseq-l10n
export const styleList = [
"Tile",
"Gallery",
"Wide",
"Expansion",
]

Expand Down Expand Up @@ -121,35 +120,31 @@ export const settingsTemplate = (): SettingSchemaDesc[] => [
${t("To archive, open each page individually and change the page tag.")}
`,
},
{ // メインページのスタイル
key: keySettingsPageStyle,
title: t("Page style"),
type: "enum",
enumChoices: styleList,
default: "Gallery",
// Tile: コンテンツ最小限のスタイル
// Gallery: 上下左右に配置するスタイル
// Wide: 画面を横に広く使うスタイル
// Expansion: 下側に展開するスタイル
description: `
${t("The Tile style displays content in a minimalist manner.")}
${t("The Gallery style arranges the blocks up, down, left, and right.")}
${t("The Wide style uses the screen horizontally.")}
${t("The Expansion style is a style that expands on the underside.")}
`,
},
{
key: "addLeftMenu",
type: "boolean",
default: true,
// 左メニューバーにボタンを追加して、このプラグインにアクセスできるようにします。
title: t("Add a button to the left menu bar to access this plugin"),
// ツールバーからもアクセスできます。
description: t("Or from the toolbar"),
description: "",
},
{ // ページコンテンツを表示するかどうか
key: "showPageContent",
title: " > " + t("Show page content"),
type: "boolean",
default: true,
// リロードすると反映されます。
description: t("Reloading will reflect this."),
},
{
key: "showLinkedReferences",
title: " > " + t("Show linked references"),
type: "boolean",
default: true,
description: t("Reloading will reflect this."),


},
{
key: "headingBatchBoardIncludeWord",
type: "heading",
Expand Down Expand Up @@ -197,6 +192,22 @@ export const settingsTemplate = (): SettingSchemaDesc[] => [
// ページタイトルに含まれる単語で、分類し、並び替えます。改行で区切って記述します。
description: "",
},
{ // メインページのスタイル
key: keySettingsPageStyle,
title: t("Page style"),
type: "enum",
enumChoices: styleList,
default: "Gallery",
// Tile: コンテンツ最小限のスタイル
// Gallery: 上下左右に配置するスタイル
// Expansion: 下側に展開するスタイル
description: `
${t("The Tile style displays content in a minimalist manner.")}
${t("The Gallery style arranges the blocks up, down, left, and right.")}
${t("The Expansion style is a style that expands on the underside.")}
`,
},
]

export const keyCommonBatchBoardIncludeWord = "BatchBoardIncludesWord"
Loading

0 comments on commit 189bb3e

Please sign in to comment.