Skip to content

Commit

Permalink
feat(custom-block): 新增列表脑图视图 | Add list mind-map view.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuoqiu-Yingyi committed Jul 7, 2023
1 parent a1d5880 commit e997c55
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2023-07-07

- 新增列表表格视图 | Add list table view.
- 新增列表脑图视图 | Add list mind-map view.

## 2023-07-06

Expand Down
3 changes: 3 additions & 0 deletions workspace/plugins/custom-block/public/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"custom-block-list-view-default": {
"label": "List - Default View"
},
"custom-block-list-view-map": {
"label": "List - Mind-Map View"
},
"custom-block-list-view-table": {
"label": "List - Table View"
},
Expand Down
3 changes: 3 additions & 0 deletions workspace/plugins/custom-block/public/i18n/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"custom-block-list-view-default": {
"label": "列表-默認視圖"
},
"custom-block-list-view-map": {
"label": "列表-腦圖視圖"
},
"custom-block-list-view-table": {
"label": "列表-表格視圖"
},
Expand Down
3 changes: 3 additions & 0 deletions workspace/plugins/custom-block/public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"custom-block-list-view-default": {
"label": "列表-默认视图"
},
"custom-block-list-view-map": {
"label": "列表-脑图视图"
},
"custom-block-list-view-table": {
"label": "列表-表格视图"
},
Expand Down
23 changes: 23 additions & 0 deletions workspace/plugins/custom-block/src/configs/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,29 @@ export const DEFAULT_CONFIG: IConfig = {
},
],
},
{ // 列表-脑图视图
id: "custom-block-list-view-map",
enable: true,
mode: MenuItemMode.button,
multi: true,
icon: "iconGraph",
accelerator: "list-view: map",
token: "list-view-map",
type: {
default: { enable: false },
[sdk.siyuan.NodeType.NodeDocument]: { enable: true },
[sdk.siyuan.NodeType.NodeList]: { enable: true },
},
tasks: [
{
type: TaskType.update,
params: {
name: "custom-block-list-view",
value: "map",
},
},
],
},
{ // 列表-表格视图
id: "custom-block-list-view-table",
enable: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
// Copyright (C) 2023 Zuoqiu Yingyi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

// 高度
@height: calc(50% - var(--custom-block-list-guides-line-width) / 2);

// 辅助线
.guides() {
content: "";
// height: calc(50% - var(--custom-block-list-guides-line-width) / 2);
height: @height;
width: calc(2em - var(--custom-block-list-guides-line-width));

// 覆盖默认视图的列表辅助线样式
position: absolute !important;
border-left: var(--custom-block-list-guides-line-width) solid var(--b3-theme-on-surface) !important;
}

:root {
&[plugin-custom-block~=list-view-map] {

.b3-dialog__content,
.protyle-content {

[custom-block-list-view=map] {
&[data-node-id].list {
/* 导图块样式 */
overflow-x: auto;
padding-top: 1em;
padding-bottom: 1em;

&,
&>[data-node-id].li {
>.protyle-attr {
/* 列表块属性标签 */
top: 0;

>.protyle-attr--refcount {
/* 引用数按钮 */
right: 2px;
}
}
}
}

[data-node-id] {
&.li {
/* 列表项文字设置居中 */
display: flex;
align-items: center;

&:first-of-type::after,
&:nth-last-of-type(2)::before {
/* 取消多余线条 */
border: none !important;
}

&:first-of-type::before {
/* 上框线 */
border-top-left-radius: var(--custom-block-border-radius);
}

&:nth-last-of-type(2)::after {
/* 下框线 */
// height: calc(50% - var(--custom-block-list-guides-line-width) / 2);
border-bottom: var(--custom-block-list-guides-line-width) solid var(--b3-theme-on-surface) !important;
border-bottom-left-radius: var(--custom-block-border-radius) !important;
}

&:first-of-type:nth-last-of-type(2) {
// 单子项居中
// top: 50%;
// transform: translate(0, -50%);

&::after {
/* 单个子项直线 */
border-radius: 0 !important;
// height: calc(50% - var(--custom-block-list-guides-line-width) / 2);
}
}

&::before {
/* 上导航线 */
.guides();
top: @height;
left: 0;
border-top: var(--custom-block-list-guides-line-width) solid var(--b3-theme-on-surface);
}

&::after {
/* 下导航线 */
.guides();
// 覆盖默认视图的列表辅助线样式
// top: 0 !important;
bottom: @height !important;
// left: 0 !important;
border-bottom: var(--custom-block-list-guides-line-width) solid var(--b3-theme-on-surface) !important;
}

&[data-subtype="u"] {
>div.protyle-action {
/* 无序列表标志 */
top: calc(50%);
left: calc(2em - 20px);
}
}

>div:nth-child(2) {
/* 修复单子项导航线错位问题 */
margin-top: 4px !important;
}

>div.protyle-action {
/* 表格项标志 */
top: calc(50% - 12px);
position: absolute;
transform: translate(0, -50%);
// left: 0.5em;
z-index: 2;
}

>[data-node-id] {

&::before {
/* 去除竖线 */
display: none;
}

// &.list {
// display: flex;
// flex-flow: column wrap;
// align-content: center;
// }

&[data-type="NodeHeading"] {
/* 移除脑图内部标题块的左侧边线 */
border-left: 0 solid transparent;
padding-left: 0;
}

&:not(.li, .list) {
/* 叶子节点 */
align-items: center;
display: flex;

/* 块内边距 */
padding: 4px;

/* 叶子节点的轮廓 */
outline: 1px solid var(--b3-theme-on-surface);
border-radius: var(--custom-block-border-radius);

// 文字框
&:is(.p, .h1, .h2, .h3, .h4, .h5, .h6) {
/* 段落块/标题块内边距为 0 */
padding: 0;

>[contenteditable][spellcheck] {
white-space: pre; // 保留换行
padding: 0 0.5em;
}
}

// 公式块
&:is(.render-node[data-type="NodeMathBlock"]) {
min-height: 0 !important;

.katex-display {
margin: 0;
padding: 0.25em;
}
}
}

&[data-type="NodeBlockQueryEmbed"],
&.sb,
&.bq {
/* 列表项内的容器块与嵌入块恢复上下排列 */
display: block;
}
}

}

&.list {
/* 整个导图列表取消缩进 */
margin: 0;
padding: 0 0 0 1em;
// transition: all 500ms;

&::after {
/* 后继承线 */
content: "";
position: absolute;
left: -1em;
top: @height;
border-bottom: var(--custom-block-list-guides-line-width) solid var(--b3-theme-on-surface);
width: 2em;
height: 0;
}
}
}

&.list>[data-node-id].li:first-of-type:nth-last-of-type(2),
&>[data-node-id].list>[data-node-id].li:first-of-type:nth-last-of-type(2),
[data-node-id]:not(.li)>[data-node-id].list>[data-node-id].li:first-of-type:nth-last-of-type(2) {
/* 修复顶层列表项错位问题 */
top: 0;
transform: none;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

:root {
&[plugin-custom-block~=list-view-table] {
.b3-dialog__content,
.protyle-content {

[custom-block-list-view=table] {
Expand Down
6 changes: 6 additions & 0 deletions workspace/plugins/custom-block/src/styles/define.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

/* 表格单元格宽度 */
--custom-block-table-cell-equal-width: 16em;

/* 列表辅助线宽度 */
--custom-block-list-guides-line-width: 2px;

/* 圆角直径 */
--custom-block-border-radius: 8px;
}

/* 弹幕滚动动画 */
Expand Down
1 change: 1 addition & 0 deletions workspace/plugins/custom-block/src/styles/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@import (once) url(./define.less);

@import (once) url(./custom-block-list-view-map.less);
@import (once) url(./custom-block-list-view-table.less);
@import (once) url(./custom-block-render-content.less);
@import (once) url(./custom-block-render-danmaku.less);
Expand Down

0 comments on commit e997c55

Please sign in to comment.