Skip to content

Commit 64c6bd8

Browse files
committed
Merge branch 'dev' of https://github.com/ci-win/siyuan into dev
# Conflicts: # app/src/mobile/util/keyboardToolbar.ts # kernel/go.mod # kernel/go.sum
2 parents c6e12cb + 5cd2c14 commit 64c6bd8

File tree

36 files changed

+574
-475
lines changed

36 files changed

+574
-475
lines changed

app/src/assets/scss/business/_color.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
flex-direction: column;
1111
justify-content: center;
1212
background-color: var(--b3-theme-background);
13+
padding: 0;
1314

1415
&:last-child {
1516
margin-right: 0;

app/src/assets/scss/component/_typography.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
line-height: 1.625;
3030
padding: 4px;
3131
margin: 4px 0;
32+
border-radius: 4px;
3233
}
3334

3435
ins > iframe {
@@ -304,7 +305,7 @@
304305
}
305306

306307
.hljs {
307-
border-radius: 0 4px 4px 0;
308+
border-radius: 4px;
308309
padding: 22px 4px;
309310
font-size: 85%;
310311
overflow: auto;

app/src/assets/scss/mobile.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,27 @@
436436
display: block;
437437
}
438438

439+
.protyle{
440+
&-util {
441+
.color__square {
442+
height: 24px;
443+
width: 24px;
444+
}
445+
}
446+
447+
&-font {
448+
font-size: 14px;
449+
}
450+
}
451+
439452
@media (max-width: 620px) {
440453
.protyle-wysiwyg [data-node-id].sb[data-sb-layout="col"] {
441454
flex-direction: column;
442455
flex-wrap: initial;
456+
457+
& > div {
458+
margin-right: 0;
459+
}
443460
}
444461
}
445462

app/src/assets/scss/protyle/_toolbar.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
padding: 8px;
6969
max-height: 80vh;
7070
z-index: 4;
71+
box-sizing: border-box;
72+
73+
&--mobile {
74+
top: 0;
75+
left: 0;
76+
width: 100vw;
77+
}
7178
}
7279

7380
&-font {

app/src/assets/scss/protyle/_wysiwyg.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,17 @@
155155
& > div {
156156
flex: 1;
157157
box-sizing: border-box;
158+
margin-right: 24px;
159+
160+
&:nth-last-child(2),
161+
&:last-child {
162+
margin-right: 0;
163+
}
158164
}
159165

160166
.sb {
161-
margin: 0;
167+
margin-top: 0;
168+
margin-bottom: 0;
162169
}
163170

164171
& > div .protyle-attr--refcount {

app/src/card/makeCard.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {hideElements} from "../protyle/ui/hideElements";
77
import {viewCards} from "./viewCards";
88
import {Constants} from "../constants";
99
import {escapeAttr, escapeHtml} from "../util/escape";
10+
import {transaction} from "../protyle/wysiwyg/transaction";
1011

1112
export const genCardItem = (item: ICardPackage) => {
1213
return `<li data-id="${item.id}" data-name="${escapeAttr(item.name)}" class="b3-list-item b3-list-item--narrow${isMobile() ? "" : " b3-list-item--hide-action"}">
@@ -176,7 +177,7 @@ export const makeCard = (ids: string[]) => {
176177
});
177178
};
178179

179-
export const quickMakeCard = (nodeElement: Element[]) => {
180+
export const quickMakeCard = (protyle: IProtyle, nodeElement: Element[]) => {
180181
let isRemove = true;
181182
const ids: string[] = [];
182183
nodeElement.forEach(item => {
@@ -190,15 +191,25 @@ export const quickMakeCard = (nodeElement: Element[]) => {
190191
}
191192
});
192193
if (isRemove) {
193-
fetchPost("/api/riff/removeRiffCards", {
194+
transaction(protyle, [{
195+
action: "removeFlashcards",
194196
deckID: Constants.QUICK_DECK_ID,
195197
blockIDs: ids
196-
});
198+
}], [{
199+
action: "addFlashcards",
200+
deckID: Constants.QUICK_DECK_ID,
201+
blockIDs: ids
202+
}]);
197203
} else {
198-
fetchPost("/api/riff/addRiffCards", {
204+
transaction(protyle, [{
205+
action: "addFlashcards",
199206
deckID: Constants.QUICK_DECK_ID,
200207
blockIDs: ids
201-
});
208+
}], [{
209+
action: "removeFlashcards",
210+
deckID: Constants.QUICK_DECK_ID,
211+
blockIDs: ids
212+
}]);
202213
}
203214
};
204215

app/src/layout/Wnd.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {Tab} from "./Tab";
1212
import {Model} from "./Model";
1313
import {Editor} from "../editor";
1414
import {Graph} from "./dock/Graph";
15-
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
15+
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
1616
import {Constants} from "../constants";
1717
/// #if !BROWSER
1818
import {webFrame, ipcRenderer} from "electron";
@@ -32,6 +32,7 @@ import {MenuItem} from "../menus/Menu";
3232
import {escapeHtml} from "../util/escape";
3333
import {isWindow} from "../util/functions";
3434
import {hideAllElements} from "../protyle/ui/hideElements";
35+
import {focusByOffset, getSelectionOffset} from "../protyle/util/selection";
3536

3637
export class Wnd {
3738
public id: string;
@@ -369,6 +370,7 @@ export class Wnd {
369370
switchWnd(newWnd, targetWnd);
370371
}
371372
}
373+
resizeTabs();
372374
/// #if !BROWSER
373375
setTabPosition();
374376
/// #endif
@@ -754,10 +756,29 @@ export class Wnd {
754756
}
755757

756758
public moveTab(tab: Tab, nextId?: string) {
759+
let rangeData: {
760+
id: string,
761+
start: number,
762+
end: number
763+
};
764+
if (tab.model instanceof Editor && tab.model.editor.protyle.toolbar.range) {
765+
const blockElement = hasClosestBlock(tab.model.editor.protyle.toolbar.range.startContainer);
766+
if (blockElement) {
767+
const startEnd = getSelectionOffset(blockElement, undefined, tab.model.editor.protyle.toolbar.range);
768+
rangeData = {
769+
id: blockElement.getAttribute("data-node-id"),
770+
start: startEnd.start,
771+
end: startEnd.end
772+
};
773+
}
774+
}
757775
this.element.querySelector(".layout-tab-container").append(tab.panelElement);
758-
if (tab.model instanceof Editor) {
759-
// DOM 移动后 range 会变化,因此置空
760-
tab.model.editor.protyle.toolbar.range = null;
776+
if (rangeData && tab.model instanceof Editor) {
777+
// DOM 移动后 range 会变化
778+
const range = focusByOffset(tab.model.editor.protyle.wysiwyg.element.querySelector(`[data-node-id="${rangeData.id}"]`), rangeData.start, rangeData.end);
779+
if (range) {
780+
tab.model.editor.protyle.toolbar.range = range;
781+
}
761782
}
762783
if (nextId) {
763784
// 只能用 find https://github.com/siyuan-note/siyuan/issues/3455
@@ -802,7 +823,6 @@ export class Wnd {
802823
}
803824
}
804825
tab.parent = this;
805-
resizeTabs();
806826
hideAllElements(["toolbar"]);
807827
}
808828

app/src/layout/util.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {getAllModels, getAllTabs} from "./getAll";
1616
import {Asset} from "../asset";
1717
import {Search} from "../search";
1818
import {Dock} from "./dock";
19-
import {focusByRange} from "../protyle/util/selection";
19+
import {focusByOffset, focusByRange, getSelectionOffset} from "../protyle/util/selection";
2020
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
2121
import {fetchPost} from "../util/fetch";
2222
import {hasClosestBlock, hasClosestByClassName} from "../protyle/util/hasClosest";
@@ -79,7 +79,35 @@ export const getDockByType = (type: TDockType) => {
7979
};
8080

8181
export const switchWnd = (newWnd: Wnd, targetWnd: Wnd) => {
82+
// DOM 移动后 range 会变化
83+
const rangeDatas: {
84+
id: string,
85+
start: number,
86+
end: number
87+
}[] = [];
88+
targetWnd.children.forEach((item) => {
89+
if (item.model instanceof Editor && item.model.editor.protyle.toolbar.range) {
90+
const blockElement = hasClosestBlock(item.model.editor.protyle.toolbar.range.startContainer);
91+
if (blockElement) {
92+
const startEnd = getSelectionOffset(blockElement, undefined, item.model.editor.protyle.toolbar.range);
93+
rangeDatas.push({
94+
id: blockElement.getAttribute("data-node-id"),
95+
start: startEnd.start,
96+
end: startEnd.end
97+
});
98+
}
99+
}
100+
});
82101
newWnd.element.after(targetWnd.element);
102+
targetWnd.children.forEach((item) => {
103+
if (item.model instanceof Editor) {
104+
const rangeData = rangeDatas.splice(0, 1)[0];
105+
const range = focusByOffset(item.model.editor.protyle.wysiwyg.element.querySelector(`[data-node-id="${rangeData.id}"]`), rangeData.start, rangeData.end);
106+
if (range) {
107+
item.model.editor.protyle.toolbar.range = range;
108+
}
109+
}
110+
});
83111
// 分割线
84112
newWnd.element.after(newWnd.element.previousElementSibling);
85113
newWnd.parent.children.find((item, index) => {
@@ -160,7 +188,7 @@ export const exportLayout = (reload: boolean, cb?: () => void, onlyData = false,
160188
} else if (cb) {
161189
cb();
162190
}
163-
return ;
191+
return;
164192
}
165193
const useElement = document.querySelector("#barDock use");
166194
if (!useElement) {

app/src/menus/Menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class Menu {
135135
} else {
136136
this.element.style.transform = "translateY(-100vh)";
137137
}
138-
})
138+
});
139139
this.element.lastElementChild.scrollTop = 0;
140140
}
141141
}

app/src/menus/onGetnotebookconf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const onGetnotebookconf = (data: INotebookConf) => {
5656
bindEvent() {
5757
bindSettingEvent(document.querySelector("#model"), data);
5858
}
59-
})
59+
});
6060
} else {
6161
const dialog = new Dialog({
6262
width: "80vw",
@@ -94,4 +94,4 @@ const bindSettingEvent = (contentElement: Element, data: INotebookConf) => {
9494
});
9595
});
9696
});
97-
}
97+
};

0 commit comments

Comments
 (0)