mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-27 02:36:10 +01:00
This commit is contained in:
parent
0f0cab91ca
commit
a681dcaf17
5 changed files with 115 additions and 213 deletions
|
|
@ -10,12 +10,9 @@ import {Search} from "../../search";
|
|||
/// #if !MOBILE
|
||||
import {Custom} from "../../layout/dock/Custom";
|
||||
import {getAllModels} from "../../layout/getAll";
|
||||
import {openSearchAV} from "../../protyle/render/av/relation";
|
||||
import {transaction} from "../../protyle/wysiwyg/transaction";
|
||||
import {focusByRange} from "../../protyle/util/selection";
|
||||
import {hasClosestBlock, hasClosestByClassName} from "../../protyle/util/hasClosest";
|
||||
import * as dayjs from "dayjs";
|
||||
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
|
||||
import {Files} from "../../layout/dock/Files";
|
||||
import {addEditorToDatabase, addFilesToDatabase} from "../../protyle/render/av/addToDatabase";
|
||||
/// #endif
|
||||
|
||||
export const commandPanel = (app: App) => {
|
||||
|
|
@ -256,99 +253,9 @@ export const execByCommand = (options: {
|
|||
switch (options.command) {
|
||||
case "addToDatabase":
|
||||
if (!isFileFocus) {
|
||||
if (protyle.title?.editElement.contains(range.startContainer)) {
|
||||
openSearchAV("", protyle.breadcrumb.element, (listItemElement) => {
|
||||
const avID = listItemElement.dataset.avId;
|
||||
transaction(protyle, [{
|
||||
action: "insertAttrViewBlock",
|
||||
avID,
|
||||
ignoreFillFilter: true,
|
||||
srcs: [{
|
||||
id: protyle.block.rootID,
|
||||
isDetached: false
|
||||
}],
|
||||
blockID: listItemElement.dataset.blockId
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: listItemElement.dataset.blockId,
|
||||
data: dayjs().format("YYYYMMDDHHmmss"),
|
||||
}], [{
|
||||
action: "removeAttrViewBlock",
|
||||
srcIDs: [protyle.block.rootID],
|
||||
avID,
|
||||
}]);
|
||||
focusByRange(range);
|
||||
});
|
||||
} else {
|
||||
const selectElement: Element[] = [];
|
||||
protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
|
||||
selectElement.push(item);
|
||||
});
|
||||
if (selectElement.length === 0) {
|
||||
const nodeElement = hasClosestBlock(range.startContainer);
|
||||
if (nodeElement) {
|
||||
selectElement.push(nodeElement);
|
||||
}
|
||||
}
|
||||
if (selectElement.length === 0) {
|
||||
return;
|
||||
}
|
||||
openSearchAV("", selectElement[0] as HTMLElement, (listItemElement) => {
|
||||
const srcIDs: string[] = [];
|
||||
const srcs: IOperationSrcs[] = [];
|
||||
selectElement.forEach(item => {
|
||||
srcIDs.push(item.getAttribute("data-node-id"));
|
||||
srcs.push({
|
||||
id: item.getAttribute("data-node-id"),
|
||||
isDetached: false
|
||||
});
|
||||
});
|
||||
const avID = listItemElement.dataset.avId;
|
||||
transaction(protyle, [{
|
||||
action: "insertAttrViewBlock",
|
||||
avID,
|
||||
ignoreFillFilter: true,
|
||||
srcs,
|
||||
blockID: listItemElement.dataset.blockId
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: listItemElement.dataset.blockId,
|
||||
data: dayjs().format("YYYYMMDDHHmmss"),
|
||||
}], [{
|
||||
action: "removeAttrViewBlock",
|
||||
srcIDs,
|
||||
avID,
|
||||
}]);
|
||||
focusByRange(range);
|
||||
});
|
||||
}
|
||||
addEditorToDatabase(protyle, range);
|
||||
} else {
|
||||
const srcs: IOperationSrcs[] = [];
|
||||
fileLiElements.forEach(item => {
|
||||
const id = item.getAttribute("data-node-id");
|
||||
if (id) {
|
||||
srcs.push({
|
||||
id,
|
||||
isDetached: false
|
||||
});
|
||||
}
|
||||
});
|
||||
if (srcs.length > 0) {
|
||||
openSearchAV("", fileLiElements[0] as HTMLElement, (listItemElement) => {
|
||||
const avID = listItemElement.dataset.avId;
|
||||
transaction(undefined, [{
|
||||
action: "insertAttrViewBlock",
|
||||
avID,
|
||||
ignoreFillFilter: true,
|
||||
srcs,
|
||||
blockID: listItemElement.dataset.blockId
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: listItemElement.dataset.blockId,
|
||||
data: dayjs().format("YYYYMMDDHHmmss"),
|
||||
}]);
|
||||
});
|
||||
}
|
||||
addFilesToDatabase(fileLiElements);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue