Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
"block-invalid-version": "The block content format version is invalid.",
"block-invalid-language": "Only code blocks can specify a supported code language.",
"block-invalid-media": "The media block contains invalid file or display information.",
"block-invalid-view": "The view block contains invalid settings.",
"board-invalid-move": "These cards can no longer be moved to that column.",
"block-invalid-collapse": "The collapsed state is invalid.",
"block-invalid-inline": "The rich text node is invalid.",
"block-empty-text": "A text node cannot be empty.",
Expand Down Expand Up @@ -600,6 +602,19 @@
"page-fit": "Fit page"
}
},
"viewBlock": {
"table": "Table view",
"board": "Board view",
"calendar": "Calendar view",
"tableTitle": "Table",
"boardTitle": "Board",
"name": "View name",
"openTab": "Open in tab",
"cardProperties": "Card properties",
"resize": "View height",
"ungrouped": "Ungrouped",
"currentPage": "Current page"
},
"table": {
"sort": "Sort",
"group": "Group",
Expand Down Expand Up @@ -809,11 +824,15 @@
"calendar": {
"previousMonth": "Previous month",
"nextMonth": "Next month",
"previousWeek": "Previous week",
"nextWeek": "Next week",
"month": "Month",
"week": "Week",
"today": "Today",
"chooseDate": "Choose date property",
"chooseStart": "Choose start time property",
"chooseEnd": "Choose end time property",
"chooseStatus": "Choose status property",
"missingDate": "Date property not found",
"agendaWidth": "Day list width",
"remaining": "{{count}} more",
"noPages": "No pages",
Expand All @@ -834,6 +853,7 @@
"table": "Table",
"hr": "Divider",
"blocked_reference": "Linked reference",
"view": "View",
"image": "Image",
"video": "Video",
"file": "File"
Expand Down
22 changes: 21 additions & 1 deletion locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
"block-invalid-version": "块内容的格式版本无效。",
"block-invalid-language": "只有代码块可以指定语言,且必须使用支持的代码语言。",
"block-invalid-media": "多媒体块的文件或显示数据无效。",
"block-invalid-view": "视图块的设置无效。",
"board-invalid-move": "这些卡片已无法移动到该列。",
"block-invalid-collapse": "折叠状态无效。",
"block-invalid-inline": "富文本节点无效。",
"block-empty-text": "文本节点不能为空。",
Expand Down Expand Up @@ -600,6 +602,19 @@
"page-fit": "适合页面"
}
},
"viewBlock": {
"table": "表格视图",
"board": "看板视图",
"calendar": "日历视图",
"tableTitle": "表格",
"boardTitle": "看板",
"name": "视图名",
"openTab": "在标签页打开",
"cardProperties": "卡片属性",
"resize": "视图高度",
"ungrouped": "未分组",
"currentPage": "当前页面"
},
"table": {
"sort": "排序",
"group": "分组",
Expand Down Expand Up @@ -809,11 +824,15 @@
"calendar": {
"previousMonth": "上个月",
"nextMonth": "下个月",
"previousWeek": "上一周",
"nextWeek": "下一周",
"month": "月",
"week": "周",
"today": "今天",
"chooseDate": "选择日期属性",
"chooseStart": "选择开始时间属性",
"chooseEnd": "选择结束时间属性",
"chooseStatus": "选择状态属性",
"missingDate": "找不到日期属性",
"agendaWidth": "当天列表宽度",
"remaining": "还有 {{count}} 条",
"noPages": "没有页面",
Expand All @@ -834,6 +853,7 @@
"table": "表格",
"hr": "分隔线",
"blocked_reference": "链接引用",
"view": "视图",
"image": "图片",
"video": "视频",
"file": "文件"
Expand Down
3 changes: 2 additions & 1 deletion main/app/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export function registerAppIPCs(window: BrowserWindow): void {
register(contents, appChannels, {
openDevTools: route(typia.createAssert<Args<"openDevTools">>(invalid), () => contents.openDevTools({ mode: "detach" })),
setFrameColors: route(typia.createAssert<Args<"setFrameColors">>(invalid), (color, symbolColor) => {
if (process.platform !== "darwin" && !window.isDestroyed()) window.setTitleBarOverlay({ color, symbolColor });
if (process.platform === "darwin" || window.isDestroyed()) return;
window.setTitleBarOverlay(process.platform === "win32" ? { symbolColor } : { color, symbolColor });
}),
editorStarted: route(typia.createAssert<Args<"editorStarted">>(invalid), () => lifecycle.editorStarted(contents)),
beforeQuitResult: route(typia.createAssert<Args<"beforeQuitResult">>(invalid), (id, blocked) => lifecycle.saveResult(contents, id, blocked))
Expand Down
73 changes: 73 additions & 0 deletions main/knowledge/board.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { isBuiltin } from "../../shared/attrs/builtins";
import { decodeValue, emptyValue, nullable } from "../../shared/attrs/values";
import { isTimeType, resolveTimeZone, secondsToDay, secondsToMinute, timeToSeconds } from "../../shared/content/time";
import { LabloomError } from "../../shared/failure";
import type { AttributeDefinition, AttributeValue } from "../../shared/types/attributes";
import type { CommitResult } from "../../shared/types/content";
import type { BoardMove } from "../../shared/workspace/view-block";
import { canGroup, groupGranularity, type GroupGranularity, type GroupValue } from "../../shared/workspace/query";
import { dateGroup, groupDateValue } from "../../shared/workspace/query-time";
import * as workspace from "../workspace-state";
import { definitions } from "./attributes";
import { EditChanges } from "./changes";
import * as commit from "./commit";
import { statement, viewBlock } from "./records";

function movedValue(def: AttributeDefinition, before: AttributeValue, from: GroupValue, to: GroupValue,
zone: string, granularity?: GroupGranularity): AttributeValue | undefined {
if (def.type === "multiselect" || def.type === "page-links") {
const values = Array.isArray(before) ? before : [];
if (from === null ? values.length : !values.includes(from)) return undefined;
const other = values.filter(value => value !== from);
return to === null || other.includes(to) ? other : [...other, to] as AttributeValue;
}
if (isTimeType(def.type)) {
const unit = groupGranularity(def.type, granularity);
const previous = typeof before === "number" ? dateGroup(before, def.type, unit, zone) : null;
if (previous !== from) return undefined;
if (to === null) return null;
if (typeof to !== "number" || dateGroup(groupDateValue(to, def.type, unit, zone), def.type, unit, zone) !== to) throw invalidMove();
return typeof before === "number" && (def.type === "minute" || def.type === "hour")
? timeToSeconds("minute", secondsToDay(to) + " " + secondsToMinute(before, zone).slice(-5), zone)
: groupDateValue(to, def.type, unit, zone);
}
if (before !== from) return undefined;
return to === null && nullable(def.type) ? emptyValue(def.type) : to;
}

function invalidMove(): LabloomError {
return new LabloomError({ kind: "board-invalid-move" });
}

export function moveViewCards(input: BoardMove, confirmation?: string, writeId?: string): CommitResult {
const { pageId, blockId, cards, to } = input, source = { kind: "page", id: pageId } as const;
return commit.edit({ history: source, confirmation, writeId }, () => {
const view = viewBlock(pageId, blockId)?.payload.view, group = view?.query.group;
if (view?.type !== "board" || group?.field.kind !== "attribute") throw invalidMove();
const { id } = group.field, def = definitions().find(def => def.id === id);
if (!def || def.hidden || def.readonly || id === "deleted" || !canGroup(def.type)) throw invalidMove();
if (to !== null && (def.type === "page-link" || def.type === "page-links") &&
(typeof to !== "string" || !statement("SELECT 1 FROM pages WHERE id=?").get(to))) throw invalidMove();
const zone = resolveTimeZone(workspace.timeZone()), plan = new EditChanges();
const unique = new Map(cards.map(card => [card.id, card.from]));
const ids = [...unique.keys()].filter(page => unique.get(page) !== to);
const values = statement(`SELECT j.value AS id, a.value, d.value AS deleted FROM json_each(?) j
LEFT JOIN page_attrs d ON d.page_id=j.value AND d.attr_id='deleted'
LEFT JOIN page_attrs a ON a.page_id=j.value AND a.attr_id=?`).all(JSON.stringify(ids), id) as
{ id: string; value: string | number | null; deleted: number | null }[];
for (const { id: page, value: old, deleted } of values) {
const from = unique.get(page)!;
if (deleted !== 0) throw invalidMove();
const before = old === null ? null : decodeValue(def, old);
const value = movedValue(def, before, from, to, zone, group.granularity);
if (value === undefined || JSON.stringify(value) === JSON.stringify(before)) continue;
if (value === null && !nullable(def.type)) {
if (isBuiltin(id)) throw invalidMove();
plan.attributes(page, {}, [id]);
}
else plan.attributes(page, { [id]: value });
plan.touches.add(page);
}
return commit.finish(plan, pageId, 0, { action: input });
});
}
2 changes: 1 addition & 1 deletion main/knowledge/edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function deletionSubject(block: ContentBlock): string {
const names: Record<ContentBlock["type"], string> = {
title: "标题", paragraph: "段落", heading_1: "一级标题", heading_2: "二级标题", heading_3: "三级标题",
unordered_list: "无序列表项", ordered_list: "有序列表项", blockquote: "引言", callout: "提示块",
code: "代码块", table: "表格", hr: "分隔线", blocked_reference: "链接引用",
code: "代码块", table: "表格", hr: "分隔线", blocked_reference: "链接引用", view: "视图",
image: "图片", video: "视频", file: "文件"
};
const target = block.payload.target;
Expand Down
Loading
Loading