Last Sync: 2026-01-01 23:18 (Mobile)
This commit is contained in:
163
.obsidian_mobi/plugins/canvas-send-to-back/main.js
Normal file
163
.obsidian_mobi/plugins/canvas-send-to-back/main.js
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||
if you want to view the source, please visit the github repository of this plugin
|
||||
*/
|
||||
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/main.ts
|
||||
var main_exports = {};
|
||||
__export(main_exports, {
|
||||
default: () => CanvasSendToBackPlugin
|
||||
});
|
||||
module.exports = __toCommonJS(main_exports);
|
||||
var import_obsidian3 = require("obsidian");
|
||||
|
||||
// src/Notice.ts
|
||||
var import_obsidian = require("obsidian");
|
||||
var DEFAULT_NOTICE_TIMEOUT_SECONDS = 5;
|
||||
var ErrorNotice = class extends import_obsidian.Notice {
|
||||
constructor(message, timeout = DEFAULT_NOTICE_TIMEOUT_SECONDS) {
|
||||
super(`Canvas Send To Back
|
||||
${message}`, timeout * 1e3);
|
||||
console.error(`canvas-send-to-back: ${message}`);
|
||||
}
|
||||
};
|
||||
|
||||
// src/canvas.ts
|
||||
var import_obsidian2 = require("obsidian");
|
||||
function isCanvasNodeData(node) {
|
||||
return !!node && typeof node === "object" && "id" in node;
|
||||
}
|
||||
function isCanvasData(data) {
|
||||
return !!data && typeof data === "object" && "nodes" in data && Array.isArray(data.nodes) && "edges" in data && Array.isArray(data.edges);
|
||||
}
|
||||
function isCanvasState(state) {
|
||||
return !!state && typeof state === "object" && "viewState" in state && !!state.viewState && typeof state.viewState === "object" && "x" in state.viewState && typeof state.viewState.x === "number" && "y" in state.viewState && typeof state.viewState.y === "number" && "zoom" in state.viewState && typeof state.viewState.zoom === "number";
|
||||
}
|
||||
function getActiveCanvas(app) {
|
||||
const view = app.workspace.getActiveViewOfType(import_obsidian2.ItemView);
|
||||
if (!view || !view.getViewData || !view.setViewData || !view.requestSave) {
|
||||
throw new Error("No active view.");
|
||||
}
|
||||
const data = JSON.parse(view.getViewData());
|
||||
if (!isCanvasData(data)) {
|
||||
throw new Error("Active view does not contain Canvas data.");
|
||||
}
|
||||
return { view, data };
|
||||
}
|
||||
function setActiveCanvasData(view, data) {
|
||||
if (!view || !view.getViewData || !view.setViewData || !view.requestSave) {
|
||||
throw new Error("No active view.");
|
||||
}
|
||||
if (!isCanvasData(data)) {
|
||||
throw new Error("Data is not Canvas data.");
|
||||
}
|
||||
const state = view.getState();
|
||||
view.setViewData(JSON.stringify(data), true);
|
||||
view.requestSave();
|
||||
if (isCanvasState(state)) {
|
||||
view.setState(state, {});
|
||||
} else {
|
||||
throw new Error("Failed to reset zoom.");
|
||||
}
|
||||
}
|
||||
function getCanvasNodeDataByID(id, data) {
|
||||
const matchingNode = data.nodes.find((x) => x.id === id);
|
||||
if (!matchingNode) {
|
||||
throw new Error(`Could not find matching node with id "${id}".`);
|
||||
}
|
||||
return matchingNode;
|
||||
}
|
||||
|
||||
// src/register-events.ts
|
||||
function registerEvents(plugin) {
|
||||
const menuSectionName = "canvasSendToBack";
|
||||
plugin.registerEvent(
|
||||
plugin.app.workspace.on(
|
||||
"canvas:node-menu",
|
||||
(menu, node) => {
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("Send to back");
|
||||
item.setSection(menuSectionName);
|
||||
item.onClick((e) => {
|
||||
plugin.sendNodeToBack(node);
|
||||
});
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
plugin.registerEvent(
|
||||
plugin.app.workspace.on(
|
||||
"canvas:node-menu",
|
||||
(menu, node) => {
|
||||
menu.addItem((item) => {
|
||||
item.setTitle("Send to front");
|
||||
item.setSection(menuSectionName);
|
||||
item.onClick((e) => {
|
||||
plugin.sendNodeToFront(node);
|
||||
});
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// src/main.ts
|
||||
var CanvasSendToBackPlugin = class extends import_obsidian3.Plugin {
|
||||
async onload() {
|
||||
registerEvents(this);
|
||||
}
|
||||
onunload() {
|
||||
}
|
||||
sendNodeToBack(node) {
|
||||
try {
|
||||
if (!isCanvasNodeData(node)) {
|
||||
throw new Error(`Must provide a valid node.`);
|
||||
}
|
||||
const { view, data } = getActiveCanvas(this.app);
|
||||
const matchingNode = getCanvasNodeDataByID(node.id, data);
|
||||
const filteredNodes = data.nodes.filter((x) => x.id !== node.id);
|
||||
filteredNodes.unshift(matchingNode);
|
||||
data.nodes = filteredNodes;
|
||||
setActiveCanvasData(view, data);
|
||||
} catch (err) {
|
||||
new ErrorNotice(`Error sending node to back.
|
||||
${err}`);
|
||||
}
|
||||
}
|
||||
sendNodeToFront(node) {
|
||||
try {
|
||||
if (!isCanvasNodeData(node)) {
|
||||
throw new Error(`Must provide a valid node.`);
|
||||
}
|
||||
const { view, data } = getActiveCanvas(this.app);
|
||||
const matchingNode = getCanvasNodeDataByID(node.id, data);
|
||||
const filteredNodes = data.nodes.filter((x) => x.id !== node.id);
|
||||
filteredNodes.push(matchingNode);
|
||||
data.nodes = filteredNodes;
|
||||
setActiveCanvasData(view, data);
|
||||
} catch (err) {
|
||||
new ErrorNotice(`Error sending node to front.
|
||||
${err}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* nosourcemap */
|
||||
11
.obsidian_mobi/plugins/canvas-send-to-back/manifest.json
Normal file
11
.obsidian_mobi/plugins/canvas-send-to-back/manifest.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "canvas-send-to-back",
|
||||
"name": "Canvas Send to Back",
|
||||
"version": "0.0.4",
|
||||
"minAppVersion": "1.1.0",
|
||||
"description": "Send a card in Obsidian Canvas to be behind all other cards.",
|
||||
"author": "Zachatoo",
|
||||
"authorUrl": "https://zachyoung.dev",
|
||||
"fundingUrl": "https://github.com/sponsors/Zachatoo",
|
||||
"isDesktopOnly": false
|
||||
}
|
||||
8
.obsidian_mobi/plugins/canvas-send-to-back/styles.css
Normal file
8
.obsidian_mobi/plugins/canvas-send-to-back/styles.css
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
|
||||
This CSS file will be included with your plugin, and
|
||||
available in the app when your plugin is enabled.
|
||||
|
||||
If your plugin does not need CSS, delete this file.
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user