A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 67 lines 2.7 kB view raw
1import {hasClosestBlock} from "../../../protyle/util/hasClosest"; 2import {getTopAloneElement} from "../../../protyle/wysiwyg/getBlock"; 3import {enterBack, zoomOut} from "../../../menus/protyle"; 4/// #if !MOBILE 5import {openFileById} from "../../../editor/util"; 6/// #endif 7import {checkFold} from "../../../util/noRelyPCFunction"; 8import {updateReadonly} from "../../../protyle/breadcrumb/action"; 9import {Constants} from "../../../constants"; 10import {fetchPost} from "../../../util/fetch"; 11 12export const onlyProtyleCommand = (options: { 13 command: string, 14 previousRange: Range, 15 protyle: IProtyle, 16}) => { 17 if (options.command === "switchReadonly") { 18 updateReadonly(options.protyle.breadcrumb.element.parentElement.querySelector('.block__icon[data-type="readonly"]'), options.protyle); 19 return true; 20 } 21 if (options.command === "switchAdjust") { 22 let fullWidth; 23 const adjustWidth = options.protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_FULLWIDTH); 24 if (!adjustWidth) { 25 fullWidth = window.siyuan.config.editor.fullWidth ? "false" : "true"; 26 } else { 27 fullWidth = adjustWidth === "true" ? "false" : "true"; 28 } 29 fetchPost("/api/attr/setBlockAttrs", { 30 id: options.protyle.block.rootID, 31 attrs: {[Constants.CUSTOM_SY_FULLWIDTH]: fullWidth} 32 }); 33 return true; 34 } 35 const nodeElement = hasClosestBlock(options.previousRange.startContainer); 36 if (!nodeElement) { 37 return false; 38 } 39 if (options.command === "enter") { 40 let topNodeElement = getTopAloneElement(nodeElement); 41 if (topNodeElement.parentElement.classList.contains("li") && topNodeElement.parentElement.parentElement.classList.contains("list") && 42 topNodeElement.nextElementSibling?.classList.contains("list") && topNodeElement.previousElementSibling.classList.contains("protyle-action")) { 43 topNodeElement = topNodeElement.parentElement; 44 } 45 const id = topNodeElement.getAttribute("data-node-id"); 46 if (options.protyle.options.backlinkData) { 47 /// #if !MOBILE 48 checkFold(id, (zoomIn, action) => { 49 openFileById({ 50 app: options.protyle.app, 51 id, 52 action, 53 zoomIn 54 }); 55 }); 56 /// #endif 57 } else { 58 zoomOut({protyle: options.protyle, id}); 59 } 60 return true; 61 } 62 if (options.command === "enterBack") { 63 enterBack(options.protyle, nodeElement.getAttribute("data-node-id")); 64 return true; 65 } 66 return false; 67};