"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/nodes/index.ts var index_exports = {}; __export(index_exports, { NoteNode: () => NoteNode }); module.exports = __toCommonJS(index_exports); // src/nodes/NoteNode/NoteNode.tsx var import_react = __toESM(require("react")); var import_react2 = require("@blocknote/react"); var import_shadcn = require("@blocknote/shadcn"); var import_locales = require("@blocknote/core/locales"); // src/utils/debug.ts var import_debug = __toESM(require("debug")); var NAMESPACE = "canvas"; function createDebug(module2) { const base = (0, import_debug.default)(`${NAMESPACE}:${module2}`); const warn = (0, import_debug.default)(`${NAMESPACE}:${module2}:warn`); const error = (0, import_debug.default)(`${NAMESPACE}:${module2}:error`); warn.enabled = true; error.enabled = true; warn.log = console.warn.bind(console); error.log = console.error.bind(console); const debugFn = Object.assign(base, { warn, error }); return debugFn; } var debug = { graph: { node: createDebug("graph:node"), edge: createDebug("graph:edge"), sync: createDebug("graph:sync") }, ui: { selection: createDebug("ui:selection"), drag: createDebug("ui:drag"), resize: createDebug("ui:resize") }, sync: { status: createDebug("sync:status"), mutations: createDebug("sync:mutations"), queue: createDebug("sync:queue") }, viewport: createDebug("viewport") }; // src/nodes/NoteNode/NoteNode.tsx var import_inter = require("@blocknote/core/fonts/inter.css"); var import_style = require("@blocknote/shadcn/style.css"); var import_jsx_runtime = require("react/jsx-runtime"); var debug2 = createDebug("note-node"); function NoteNode({ nodeData, storage, theme = "light", placeholder = "Start typing...", isResizing }) { const isSyncingFromStorage = (0, import_react.useRef)(false); const isSyncingToStorage = (0, import_react.useRef)(false); const lastStorageContent = (0, import_react.useRef)(""); const editor = (0, import_react2.useCreateBlockNote)({ initialContent: [{ id: crypto.randomUUID(), type: "paragraph", content: "" }], dictionary: { ...import_locales.en, placeholders: { ...import_locales.en.placeholders, emptyDocument: placeholder, default: placeholder, heading: "Enter a heading" } } }, []); (0, import_react2.useEditorChange)(() => { if (isSyncingFromStorage.current) { return; } try { isSyncingToStorage.current = true; const html = editor.blocksToFullHTML(editor.document); if (html !== lastStorageContent.current) { lastStorageContent.current = html; storage.onChange(html); } } catch (err) { debug2.error("Failed to sync to storage: %O", err); } finally { isSyncingToStorage.current = false; } }, editor); (0, import_react.useEffect)(() => { if (!editor) return; const handleStorageChange = (newContent) => { if (isSyncingToStorage.current) { return; } queueMicrotask(() => { if (newContent === lastStorageContent.current) return; lastStorageContent.current = newContent; if (newContent && newContent.trim()) { try { isSyncingFromStorage.current = true; const blocks = editor.tryParseHTMLToBlocks(newContent); editor.replaceBlocks(editor.document, blocks); } catch (err_0) { debug2.error("Failed to parse HTML from storage: %O", err_0); } finally { isSyncingFromStorage.current = false; } } }); }; const unsubscribe = storage.subscribe?.(handleStorageChange); if (storage.content && storage.content !== lastStorageContent.current) { handleStorageChange(storage.content); } return () => { unsubscribe?.(); }; }, [editor, storage]); if (storage.isLoading) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "note-node note-node--loading", style: styles.loading, children: "Loading..." }); } return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "note-node", style: styles.container, "data-no-drag": "true", onClick: (e) => { e.stopPropagation(); }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_shadcn.BlockNoteView, { editor, theme }) }); } var styles = { container: { height: "100%", width: "100%", overflow: "auto", touchAction: "auto" }, loading: { display: "flex", alignItems: "center", justifyContent: "center", height: "100%", color: "#666" } }; //# sourceMappingURL=index.js.map