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;
|
||||
}
|
||||
|
|
|
@ -29,8 +29,7 @@ import {makeCard} from "../card/makeCard";
|
|||
import {transaction} from "../protyle/wysiwyg/transaction";
|
||||
import {emitOpenMenu} from "../plugin/EventBus";
|
||||
import {openByMobile} from "../protyle/util/compatibility";
|
||||
import {openSearchAV} from "../protyle/render/av/relation";
|
||||
import * as dayjs from "dayjs";
|
||||
import {addFilesToDatabase} from "../protyle/render/av/addToDatabase";
|
||||
|
||||
const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
|
||||
const fileItemElement = Array.from(selectItemElements).find(item => {
|
||||
|
@ -57,27 +56,7 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
|
|||
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
|
||||
icon: "iconDatabase",
|
||||
click: () => {
|
||||
openSearchAV("", selectItemElements[0] as HTMLElement, (listItemElement) => {
|
||||
const avID = listItemElement.dataset.avId;
|
||||
const srcs: IOperationSrcs[] = [];
|
||||
blockIDs.forEach(id => {
|
||||
srcs.push({
|
||||
id,
|
||||
isDetached: false
|
||||
});
|
||||
});
|
||||
transaction(undefined, [{
|
||||
action: "insertAttrViewBlock",
|
||||
avID,
|
||||
ignoreFillFilter: true,
|
||||
srcs,
|
||||
blockID: listItemElement.dataset.blockId
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: listItemElement.dataset.blockId,
|
||||
data: dayjs().format("YYYYMMDDHHmmss"),
|
||||
}]);
|
||||
});
|
||||
addFilesToDatabase(Array.from(selectItemElements));
|
||||
}
|
||||
}).element);
|
||||
}
|
||||
|
@ -478,23 +457,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
|
|||
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
|
||||
icon: "iconDatabase",
|
||||
click: () => {
|
||||
openSearchAV("", liElement as HTMLElement, (listItemElement) => {
|
||||
const avID = listItemElement.dataset.avId;
|
||||
transaction(undefined, [{
|
||||
action: "insertAttrViewBlock",
|
||||
avID,
|
||||
ignoreFillFilter: true,
|
||||
srcs: [{
|
||||
id,
|
||||
isDetached: false
|
||||
}],
|
||||
blockID: listItemElement.dataset.blockId
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: listItemElement.dataset.blockId,
|
||||
data: dayjs().format("YYYYMMDDHHmmss"),
|
||||
}]);
|
||||
});
|
||||
addFilesToDatabase([liElement]);
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
|
|
@ -47,9 +47,9 @@ import {avRender} from "../render/av/render";
|
|||
import {emitOpenMenu} from "../../plugin/EventBus";
|
||||
import {insertAttrViewBlockAnimation} from "../render/av/row";
|
||||
import {avContextmenu} from "../render/av/action";
|
||||
import {openSearchAV} from "../render/av/relation";
|
||||
import {getPlainText} from "../util/paste";
|
||||
import {Menu} from "../../plugin/Menu";
|
||||
import {addEditorToDatabase} from "../render/av/addToDatabase";
|
||||
|
||||
export class Gutter {
|
||||
public element: HTMLElement;
|
||||
|
@ -817,34 +817,7 @@ export class Gutter {
|
|||
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
|
||||
icon: "iconDatabase",
|
||||
click: () => {
|
||||
openSearchAV("", selectsElement[0] as HTMLElement, (listItemElement) => {
|
||||
const srcIDs: string[] = [];
|
||||
const srcs: IOperationSrcs[] = [];
|
||||
selectsElement.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,
|
||||
srcs,
|
||||
ignoreFillFilter: true,
|
||||
blockID: listItemElement.dataset.blockId
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: listItemElement.dataset.blockId,
|
||||
data: dayjs().format("YYYYMMDDHHmmss"),
|
||||
}], [{
|
||||
action: "removeAttrViewBlock",
|
||||
srcIDs,
|
||||
avID,
|
||||
}]);
|
||||
focusByRange(range);
|
||||
});
|
||||
addEditorToDatabase(protyle, range);
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
@ -1289,28 +1262,7 @@ export class Gutter {
|
|||
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
|
||||
icon: "iconDatabase",
|
||||
click: () => {
|
||||
openSearchAV("", nodeElement as HTMLElement, (listItemElement) => {
|
||||
const avID = listItemElement.dataset.avId;
|
||||
transaction(protyle, [{
|
||||
action: "insertAttrViewBlock",
|
||||
avID,
|
||||
srcs: [{
|
||||
id,
|
||||
isDetached: false
|
||||
}],
|
||||
ignoreFillFilter: true,
|
||||
blockID: listItemElement.dataset.blockId
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: listItemElement.dataset.blockId,
|
||||
data: dayjs().format("YYYYMMDDHHmmss"),
|
||||
}], [{
|
||||
action: "removeAttrViewBlock",
|
||||
srcIDs: [id],
|
||||
avID,
|
||||
}]);
|
||||
focusByRange(range);
|
||||
});
|
||||
addEditorToDatabase(protyle, range);
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
|
|
@ -21,9 +21,7 @@ import {openDocHistory} from "../../history/doc";
|
|||
import {openNewWindowById} from "../../window/openNewWindow";
|
||||
import {genImportMenu} from "../../menus/navigation";
|
||||
import {transferBlockRef} from "../../menus/block";
|
||||
import {openSearchAV} from "../render/av/relation";
|
||||
import {transaction} from "../wysiwyg/transaction";
|
||||
import {focusByRange} from "../util/selection";
|
||||
import {addEditorToDatabase} from "../render/av/addToDatabase";
|
||||
|
||||
export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
|
||||
hideTooltip();
|
||||
|
@ -51,28 +49,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
|
|||
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
|
||||
icon: "iconDatabase",
|
||||
click: () => {
|
||||
openSearchAV("", protyle.breadcrumb.element, (listItemElement) => {
|
||||
const avID = listItemElement.dataset.avId;
|
||||
transaction(protyle, [{
|
||||
action: "insertAttrViewBlock",
|
||||
avID,
|
||||
ignoreFillFilter: true,
|
||||
srcs: [{
|
||||
id: response.data.rootID,
|
||||
isDetached: false
|
||||
}],
|
||||
blockID: listItemElement.dataset.blockId
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: listItemElement.dataset.blockId,
|
||||
data: dayjs().format("YYYYMMDDHHmmss"),
|
||||
}], [{
|
||||
action: "removeAttrViewBlock",
|
||||
srcIDs: [response.data.rootID],
|
||||
avID,
|
||||
}]);
|
||||
focusByRange(range);
|
||||
});
|
||||
addEditorToDatabase(protyle, range, "title");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
|
103
app/src/protyle/render/av/addToDatabase.ts
Normal file
103
app/src/protyle/render/av/addToDatabase.ts
Normal file
|
@ -0,0 +1,103 @@
|
|||
import {openSearchAV} from "./relation";
|
||||
import {transaction} from "../../wysiwyg/transaction";
|
||||
import {focusByRange} from "../../util/selection";
|
||||
import {hasClosestBlock} from "../../util/hasClosest";
|
||||
import * as dayjs from "dayjs";
|
||||
|
||||
export const addFilesToDatabase = (fileLiElements: Element[]) => {
|
||||
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"),
|
||||
}]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const addEditorToDatabase = (protyle: IProtyle, range: Range, type?: string) => {
|
||||
if (protyle.title?.editElement.contains(range.startContainer) || type === "title") {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue