From 5f68ed18bc596f2cedb37d05deccc8de124aac86 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Mon, 14 Sep 2026 20:38:25 +0200 Subject: [PATCH] 2.28.0-beta.0 --- docs/API/ExcalidrawAutomate.d.ts | 24 +++++++++++ manifest-beta.json | 2 +- src/constants/constants.ts | 3 ++ src/shared/Dialogs/Messages.ts | 10 +++++ src/shared/Dialogs/SuggesterInfo.ts | 6 +++ src/shared/ExcalidrawAutomate.ts | 65 +++++++++++++++++++++++++++++ src/types/excalidrawLib.d.ts | 1 + 7 files changed, 110 insertions(+), 1 deletion(-) diff --git a/docs/API/ExcalidrawAutomate.d.ts b/docs/API/ExcalidrawAutomate.d.ts index fedd2a93..15c734b8 100644 --- a/docs/API/ExcalidrawAutomate.d.ts +++ b/docs/API/ExcalidrawAutomate.d.ts @@ -476,6 +476,30 @@ export declare class ExcalidrawAutomate { * @returns {string} The ID of the added rectangle element. */ addRect(topX: number, topY: number, width: number, height: number, id?: string): string; + /** + * Adds a sticky note and its optional fitted label to the ExcalidrawAutomate + * instance. Width and height default to Excalidraw's sticky-note size. + * @param {number} topX - The x-coordinate of the top-left corner. + * @param {number} topY - The y-coordinate of the top-left corner. + * @param {string} text - The sticky-note text. An empty string creates an unlabeled note. + * @param {Object} [formatting] - Sticky-note size and label formatting. + * @param {number} [formatting.width] - The initial width of the note. + * @param {number} [formatting.height] - The initial height of the note. + * @param {number} [formatting.fontSize] - The label's maximum font size. + * @param {number} [formatting.fontFamily] - The label font family. + * @param {"left" | "center" | "right"} [formatting.textAlign] - The label's horizontal alignment. + * @param {"top" | "middle" | "bottom"} [formatting.textVerticalAlign] - The label's vertical alignment. + * @param {string} [id] - The ID of the sticky-note element. + * @returns {string} The ID of the added sticky note. + */ + addStickyNote(topX: number, topY: number, text: string, formatting?: { + width?: number; + height?: number; + fontSize?: number; + fontFamily?: number; + textAlign?: "left" | "center" | "right"; + textVerticalAlign?: "top" | "middle" | "bottom"; + }, id?: string): string; /** * Adds a diamond element to the ExcalidrawAutomate instance. * @param {number} topX - The x-coordinate of the top-left corner. diff --git a/manifest-beta.json b/manifest-beta.json index bd47a067..f38fa620 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "2.27.3", + "version": "2.28.0-beta.0", "minAppVersion": "1.8.7", "description": "Sketch Your Mind. Edit and view Excalidraw drawings. Enter the world of 4D Visual PKM.", "author": "Zsolt Viczian", diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 0f757dec..76ea2a1f 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -119,6 +119,7 @@ export let { loadMermaid, syncInvalidIndices, getDefaultColorPalette, + convertToExcalidrawElements, } = excalidrawLib; export function updateExcalidrawLib() { @@ -138,6 +139,7 @@ export function updateExcalidrawLib() { "getLineHeight", "restoreElements", "restoreLibraryItems", + "convertToExcalidrawElements", ]; for (const fnName of requiredFunctions) { @@ -178,6 +180,7 @@ export function updateExcalidrawLib() { loadMermaid, syncInvalidIndices, getDefaultColorPalette, + convertToExcalidrawElements, } = excalidrawLib); } catch (error) { if (error instanceof Error || typeof error === "string") { diff --git a/src/shared/Dialogs/Messages.ts b/src/shared/Dialogs/Messages.ts index 8f52ffc7..69fc77d0 100644 --- a/src/shared/Dialogs/Messages.ts +++ b/src/shared/Dialogs/Messages.ts @@ -21,7 +21,17 @@ I build this plugin as a labor of love. Curious about the philosophy behind it? ## New - Copied Markdown image SVGs now replace embedded base64 images and fonts with short placeholders, making them smaller and easier to share with AI agents when developing custom CSS. +## New from Excalidraw.com +- Create sticky notes with the new **Sticky note** tool or the **N** shortcut. Labels automatically fit and grow with their note, with dedicated colors and a creation-date footer. [#12064](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/12064) + +## New in Excalidraw Automate +- Scripts can create native sticky notes, including automatically fitted labels: +\`\`\`ts +addStickyNote(topX: number, topY: number, text: string, formatting?: {width?: number; height?: number; fontSize?: number; fontFamily?: number; textAlign?: "left" | "center" | "right"; textVerticalAlign?: "top" | "middle" | "bottom";}, id?: string): string; +\`\`\` + ## Fixed +- Drawing persistence is now more reliable during rapid edits across multiple tabs, popout moves, and immediate closing. Backups and automatic exports now track the exact successfully saved revision. - Rapidly changing Markdown image appearance, selection, or image/embeddable conversion no longer leaves a rejected image-render promise in the console or lets a superseded render overwrite the newer element state. `, "2.27.3": ` diff --git a/src/shared/Dialogs/SuggesterInfo.ts b/src/shared/Dialogs/SuggesterInfo.ts index e672b77e..97d1d0f1 100644 --- a/src/shared/Dialogs/SuggesterInfo.ts +++ b/src/shared/Dialogs/SuggesterInfo.ts @@ -389,6 +389,12 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [ desc: null, after: "", }, + { + field: "addStickyNote", + code: 'addStickyNote(topX: number, topY: number, text: string, formatting?: {width?: number; height?: number; fontSize?: number; fontFamily?: number; textAlign?: "left" | "center" | "right"; textVerticalAlign?: "top" | "middle" | "bottom";}, id?: string): string;', + desc: "Adds a sticky note using the current EA colors and styles. The optional label is fitted automatically, and the function returns the note container ID.", + after: "", + }, { field: "addDiamond", code: "addDiamond(topX: number, topY: number, width: number, height: number, id?:string): string;", diff --git a/src/shared/ExcalidrawAutomate.ts b/src/shared/ExcalidrawAutomate.ts index feadf6bd..f7b33cc2 100644 --- a/src/shared/ExcalidrawAutomate.ts +++ b/src/shared/ExcalidrawAutomate.ts @@ -49,6 +49,7 @@ import { mermaidToExcalidraw, refreshTextDimensions, getFontFamilyString, + convertToExcalidrawElements, } from "src/constants/constants"; import { blobToBase64, @@ -2333,6 +2334,70 @@ export class ExcalidrawAutomate { return id; } + /** + * Adds a sticky note and its optional fitted label to the ExcalidrawAutomate + * instance. Width and height default to Excalidraw's sticky-note size. + * @param {number} topX - The x-coordinate of the top-left corner. + * @param {number} topY - The y-coordinate of the top-left corner. + * @param {string} text - The sticky-note text. An empty string creates an unlabeled note. + * @param {Object} [formatting] - Sticky-note size and label formatting. + * @param {number} [formatting.width] - The initial width of the note. + * @param {number} [formatting.height] - The initial height of the note. + * @param {number} [formatting.fontSize] - The label's maximum font size. + * @param {number} [formatting.fontFamily] - The label font family. + * @param {"left" | "center" | "right"} [formatting.textAlign] - The label's horizontal alignment. + * @param {"top" | "middle" | "bottom"} [formatting.textVerticalAlign] - The label's vertical alignment. + * @param {string} [id] - The ID of the sticky-note element. + * @returns {string} The ID of the added sticky note. + */ + addStickyNote( + topX: number, + topY: number, + text: string, + formatting?: { + width?: number; + height?: number; + fontSize?: number; + fontFamily?: number; + textAlign?: "left" | "center" | "right"; + textVerticalAlign?: "top" | "middle" | "bottom"; + }, + id?: string, + ): string { + id = id ?? nanoid(); + const elements = convertToExcalidrawElements( + [ + { + ...this.boxedElement( + id, + "stickynote", + topX, + topY, + formatting?.width ?? 0, + formatting?.height ?? 0, + ), + type: "stickynote" as const, + label: text + ? { + text, + fontSize: formatting?.fontSize ?? this.style.fontSize, + fontFamily: formatting?.fontFamily ?? this.style.fontFamily, + textAlign: + formatting?.textAlign ?? this.style.textAlign, + verticalAlign: + formatting?.textVerticalAlign ?? this.style.verticalAlign, + } + : undefined, + }, + ], + { regenerateIds: false }, + ); + for (const element of elements) { + this.elementsDict[element.id] = element; + } + return id; + } + /** * Adds a diamond element to the ExcalidrawAutomate instance. * @param {number} topX - The x-coordinate of the top-left corner. diff --git a/src/types/excalidrawLib.d.ts b/src/types/excalidrawLib.d.ts index 85157231..af68ca24 100644 --- a/src/types/excalidrawLib.d.ts +++ b/src/types/excalidrawLib.d.ts @@ -303,6 +303,7 @@ declare namespace ExcalidrawLib { } | undefined>;*/ let hashElementsVersion: typeof import("@zsviczian/excalidraw/types/excalidraw").hashElementsVersion; + let convertToExcalidrawElements: typeof import("@zsviczian/excalidraw").convertToExcalidrawElements; let Excalidraw: typeof import("@zsviczian/excalidraw").Excalidraw; let MainMenu: typeof import("@zsviczian/excalidraw").MainMenu; let WelcomeScreen: typeof import("@zsviczian/excalidraw").WelcomeScreen;