@pixerate/editor 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/agent/index.cjs +59 -9
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +6 -4
- package/dist/agent/index.d.ts +6 -4
- package/dist/agent/index.js +52 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/{builtins-Chj6zv_O.d.ts → builtins-haN82vjT.d.ts} +33 -3
- package/dist/{builtins-CdPcLwwF.d.cts → builtins-nMXh9sT3.d.cts} +33 -3
- package/dist/canvas/index.cjs +372 -8
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +72 -4
- package/dist/canvas/index.d.ts +72 -4
- package/dist/canvas/index.js +368 -4
- package/dist/canvas/index.js.map +1 -1
- package/dist/{chunk-UBCFIABU.js → chunk-5H2OPMXZ.js} +183 -6
- package/dist/chunk-5H2OPMXZ.js.map +1 -0
- package/dist/{chunk-NFVBT3UZ.cjs → chunk-66IMF6OD.cjs} +108 -25
- package/dist/chunk-66IMF6OD.cjs.map +1 -0
- package/dist/{chunk-Q2OHWD2A.js → chunk-6IO7WUSU.js} +19 -5
- package/dist/chunk-6IO7WUSU.js.map +1 -0
- package/dist/{chunk-YOMYSFJU.cjs → chunk-AGR7EVRW.cjs} +49 -35
- package/dist/chunk-AGR7EVRW.cjs.map +1 -0
- package/dist/{chunk-RRREAOVM.cjs → chunk-HNDSPZ5T.cjs} +4 -4
- package/dist/{chunk-RRREAOVM.cjs.map → chunk-HNDSPZ5T.cjs.map} +1 -1
- package/dist/chunk-HXDMZQTD.cjs +497 -0
- package/dist/chunk-HXDMZQTD.cjs.map +1 -0
- package/dist/chunk-IB3ZHQAX.js +497 -0
- package/dist/chunk-IB3ZHQAX.js.map +1 -0
- package/dist/{chunk-X7HXL2SB.js → chunk-JT7AXQTE.js} +336 -10
- package/dist/chunk-JT7AXQTE.js.map +1 -0
- package/dist/{chunk-HDYMLS3X.cjs → chunk-MC2LQN5S.cjs} +196 -19
- package/dist/chunk-MC2LQN5S.cjs.map +1 -0
- package/dist/{chunk-JOIREKL7.js → chunk-UKI64KUD.js} +85 -2
- package/dist/chunk-UKI64KUD.js.map +1 -0
- package/dist/{chunk-MHEPLBFB.js → chunk-WON34HKM.js} +2 -2
- package/dist/{chunk-NQF32I6Z.cjs → chunk-YK5TATOF.cjs} +461 -135
- package/dist/chunk-YK5TATOF.cjs.map +1 -0
- package/dist/commands/index.cjs +30 -410
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.cts +1 -1
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.js +17 -397
- package/dist/commands/index.js.map +1 -1
- package/dist/{controller-CxXGOEmy.d.cts → controller-w6eRTjF8.d.cts} +67 -2
- package/dist/{controller-CxXGOEmy.d.ts → controller-w6eRTjF8.d.ts} +67 -2
- package/dist/extensions/index.cjs +23 -5
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +1 -1
- package/dist/extensions/index.d.ts +1 -1
- package/dist/extensions/index.js +23 -5
- package/dist/{index-jcJwmBYt.d.cts → index-C6gaQRH0.d.cts} +53 -4
- package/dist/{index-B273Zllk.d.ts → index-DXAv_R08.d.ts} +53 -4
- package/dist/index.cjs +66 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +46 -6
- package/dist/index.js.map +1 -1
- package/dist/serializers/index.cjs +5 -3
- package/dist/serializers/index.cjs.map +1 -1
- package/dist/serializers/index.d.cts +13 -3
- package/dist/serializers/index.d.ts +13 -3
- package/dist/serializers/index.js +4 -2
- package/dist/spreadsheet/index.cjs +22 -2
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +76 -3
- package/dist/spreadsheet/index.d.ts +76 -3
- package/dist/spreadsheet/index.js +21 -1
- package/package.json +1 -1
- package/dist/chunk-HDYMLS3X.cjs.map +0 -1
- package/dist/chunk-JOIREKL7.js.map +0 -1
- package/dist/chunk-NFVBT3UZ.cjs.map +0 -1
- package/dist/chunk-NQF32I6Z.cjs.map +0 -1
- package/dist/chunk-Q2OHWD2A.js.map +0 -1
- package/dist/chunk-UBCFIABU.js.map +0 -1
- package/dist/chunk-X7HXL2SB.js.map +0 -1
- package/dist/chunk-YOMYSFJU.cjs.map +0 -1
- /package/dist/{chunk-MHEPLBFB.js.map → chunk-WON34HKM.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunk66IMF6ODcjs = require('./chunk-66IMF6OD.cjs');
|
|
5
5
|
|
|
6
6
|
// src/serializers/html.ts
|
|
7
7
|
var DROP_WITH_CONTENT_REGEX = /<(script|style|template|noscript|iframe|object|embed|head|title|svg|math|textarea|select|button)\b[^>]*>[\s\S]*?<\/\1\s*>/gi;
|
|
@@ -15,12 +15,12 @@ function sanitizeImportedHtml(html) {
|
|
|
15
15
|
const body = BODY_REGEX.exec(content);
|
|
16
16
|
if (body) content = body[1];
|
|
17
17
|
content = content.replace(DROP_WITH_CONTENT_REGEX, "").replace(UNCLOSED_RAW_TEXT_REGEX, "").replace(NAMESPACED_TAG_REGEX, "");
|
|
18
|
-
const sanitized =
|
|
18
|
+
const sanitized = _chunk66IMF6ODcjs.sanitizeHtml.call(void 0, content, { disallowedTags: "strip" }).trim();
|
|
19
19
|
return sanitized || "<p></p>";
|
|
20
20
|
}
|
|
21
21
|
function plainTextToParagraphHtml(text) {
|
|
22
22
|
if (!text) return "<p></p>";
|
|
23
|
-
return text.replace(/\r\n?/g, "\n").split("\n").map((line) => `<p>${
|
|
23
|
+
return text.replace(/\r\n?/g, "\n").split("\n").map((line) => `<p>${_chunk66IMF6ODcjs.escapeHtml.call(void 0, line)}</p>`).join("");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/serializers/rtf.ts
|
|
@@ -296,4 +296,4 @@ function readRichClipboard(event, schema, mimeType = PIXERATE_DOCUMENT_MIME) {
|
|
|
296
296
|
|
|
297
297
|
|
|
298
298
|
exports.sanitizeImportedHtml = sanitizeImportedHtml; exports.plainTextToParagraphHtml = plainTextToParagraphHtml; exports.rtfToPlainText = rtfToPlainText; exports.PIXERATE_DOCUMENT_MIME = PIXERATE_DOCUMENT_MIME; exports.getSchemaSignature = getSchemaSignature; exports.serializeRichClipboardPayload = serializeRichClipboardPayload; exports.parseRichClipboardPayload = parseRichClipboardPayload; exports.getClipboardData = getClipboardData; exports.readRichClipboard = readRichClipboard;
|
|
299
|
-
//# sourceMappingURL=chunk-
|
|
299
|
+
//# sourceMappingURL=chunk-HNDSPZ5T.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-RRREAOVM.cjs","../src/serializers/html.ts","../src/serializers/rtf.ts","../src/serializers/clipboard.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACGA,IAAM,wBAAA,EACJ,6HAAA;AAEF,IAAM,wBAAA,EAA0B,kCAAA;AAChC,IAAM,WAAA,EAAa,2CAAA;AAEnB,IAAM,qBAAA,EAAuB,oCAAA;AAetB,SAAS,oBAAA,CAAqB,IAAA,EAAsB;AACzD,EAAA,GA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A,UAAS,IAAE,CAAA,CAAA,mBAAI,IAAA,CAAK,KAAA,UAAS,IAAE,CAAA,CAAA,EAAI,MAAA,CAAO,IAAA,kBAAK,IAAA,CAAK,IAAA,CAAK,KAAA,UAAS,CAAC,GAAC,CAAA,CAAE,IAAA,CAAK,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA;AAAA,IAAA;AAChI,EAAA;AAEF,EAAA;AACE,IAAA;AAA6E,EAAA;AAE/E,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAGO;AACL,EAAA;AAAsC,IAAA;AAC3B,IAAA;AACwB,IAAA;AACb,EAAA;AAEtB,EAAA;AACF;AAQO;AACL,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAkD,EAAA;AAElD,IAAA;AAAO,EAAA;AAEX;AAaO;AACL,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAMO;AAKL,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AAA2B,EAAA;AAE3B,IAAA;AAAO,EAAA;AAET,EAAA;AACF;AHwKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-RRREAOVM.cjs","sourcesContent":[null,"import { sanitizeHtml } from \"./markdown\";\nimport { escapeHtml } from \"./plain-text\";\n\n/**\n * Elements whose content is never document text (scripts, styles, metadata,\n * embedded objects, form controls). They are removed together with their\n * content before sanitizing, so e.g. CSS rules don't show up as paragraphs.\n */\nconst DROP_WITH_CONTENT_REGEX =\n /<(script|style|template|noscript|iframe|object|embed|head|title|svg|math|textarea|select|button)\\b[^>]*>[\\s\\S]*?<\\/\\1\\s*>/gi;\n/** An unclosed `<script>` / `<style>` swallows the rest of the document. */\nconst UNCLOSED_RAW_TEXT_REGEX = /<(script|style)\\b[^>]*>[\\s\\S]*$/i;\nconst BODY_REGEX = /<body\\b[^>]*>([\\s\\S]*?)(?:<\\/body\\s*>|$)/i;\n/** Namespaced tags such as Word's `<o:p>`, which the sanitizer cannot parse. */\nconst NAMESPACED_TAG_REGEX = /<\\/?[a-zA-Z][\\w-]*:[\\w-]+\\b[^>]*>/g;\n\n/**\n * Sanitizes a full HTML document or fragment for insertion into the editor,\n * e.g. an imported `.html` file or HTML from another application.\n *\n * - Keeps only the `<body>` content when the input is a full document.\n * - Removes comments, doctype/XML declarations, CDATA, scripts, styles and\n * other non-text elements together with their content.\n * - Applies the same tag/attribute/URL allowlist as embedded HTML in markdown\n * (see `sanitizeHtml`), but strips disallowed tags instead of escaping them,\n * so wrappers such as `<section>` or `<font>` keep their text.\n *\n * It is string-based (no live DOM), so handlers such as `<img onerror>` never run.\n */\nexport function sanitizeImportedHtml(html: string): string {\n if (!html) return \"<p></p>\";\n let content = html.replace(/^/, \"\");\n content = content\n .replace(/<!--[\\s\\S]*?(?:-->|$)/g, \"\")\n .replace(/<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>|$)/g, \"\")\n .replace(/<![^>]*>/g, \"\")\n .replace(/<\\?[\\s\\S]*?(?:\\?>|$)/g, \"\");\n const body = BODY_REGEX.exec(content);\n if (body) content = body[1];\n content = content\n .replace(DROP_WITH_CONTENT_REGEX, \"\")\n .replace(UNCLOSED_RAW_TEXT_REGEX, \"\")\n .replace(NAMESPACED_TAG_REGEX, \"\");\n const sanitized = sanitizeHtml(content, { disallowedTags: \"strip\" }).trim();\n return sanitized || \"<p></p>\";\n}\n\n/**\n * Converts untrusted plain text to TipTap paragraph HTML, always escaping it.\n *\n * Unlike `plainTextToTipTapHtml`, text that already looks like `<p>…</p>` is\n * not passed through as HTML, which matters for imported files.\n */\nexport function plainTextToParagraphHtml(text: string): string {\n if (!text) return \"<p></p>\";\n return text\n .replace(/\\r\\n?/g, \"\\n\")\n .split(\"\\n\")\n .map((line) => `<p>${escapeHtml(line)}</p>`)\n .join(\"\");\n}\n","/**\n * Destinations whose content is metadata or binary data rather than document\n * text. A group starting with one of these control words (or with `\\*`) is\n * skipped entirely.\n */\nconst SKIPPED_DESTINATIONS = new Set([\n \"author\", \"bkmkend\", \"bkmkstart\", \"colortbl\", \"comment\", \"datastore\",\n \"doccomm\", \"falt\", \"fldinst\", \"filetbl\", \"fonttbl\", \"footer\", \"footerf\",\n \"footerl\", \"footerr\", \"footnote\", \"generator\", \"header\", \"headerf\",\n \"headerl\", \"headerr\", \"info\", \"keywords\", \"latentstyles\", \"listoverridetable\",\n \"listtable\", \"nonshppict\", \"object\", \"operator\", \"pict\", \"private\", \"revtbl\",\n \"rsidtbl\", \"shppict\", \"stylesheet\", \"subject\", \"themedata\", \"title\",\n \"xmlnstbl\", \"colorschememapping\",\n]);\n\n/** Control words that map to a literal character. */\nconst CONTROL_WORD_TEXT: Record<string, string> = {\n par: \"\\n\",\n sect: \"\\n\",\n page: \"\\n\",\n line: \"\\n\",\n row: \"\\n\",\n cell: \"\\t\",\n tab: \"\\t\",\n emdash: \"—\",\n endash: \"–\",\n emspace: \" \",\n enspace: \" \",\n bullet: \"•\",\n lquote: \"‘\",\n rquote: \"’\",\n ldblquote: \"“\",\n rdblquote: \"”\",\n};\n\n/** Windows-1252 code points in 0x80–0x9F that differ from Latin-1. */\nconst CP1252: Record<number, string> = {\n 0x80: \"€\", 0x82: \"‚\", 0x83: \"ƒ\", 0x84: \"„\", 0x85: \"…\",\n 0x86: \"†\", 0x87: \"‡\", 0x88: \"ˆ\", 0x89: \"‰\", 0x8a: \"Š\",\n 0x8b: \"‹\", 0x8c: \"Œ\", 0x8e: \"Ž\", 0x91: \"‘\", 0x92: \"’\",\n 0x93: \"“\", 0x94: \"”\", 0x95: \"•\", 0x96: \"–\", 0x97: \"—\",\n 0x98: \"˜\", 0x99: \"™\", 0x9a: \"š\", 0x9b: \"›\", 0x9c: \"œ\",\n 0x9e: \"ž\", 0x9f: \"Ÿ\",\n};\n\nconst CONTROL_WORD_REGEX = /\\\\([a-zA-Z]{1,32})(-?\\d{1,10})? ?/y;\n\n/**\n * Best-effort plain-text extraction from an RTF document.\n *\n * Handles paragraphs/line breaks/tabs, escaped braces and backslashes,\n * `\\'hh` hex escapes (decoded as Windows-1252), `\\uN` Unicode escapes with\n * their `\\ucN` fallback characters, common typographic control words, and\n * skips metadata destinations (font/colour tables, `\\info`, pictures, field\n * instructions, `\\*` destinations). Formatting (bold, lists, tables) is not\n * preserved. Input that does not start with `{\\rtf` is returned unchanged.\n */\nexport function rtfToPlainText(rtf: string): string {\n if (!rtf) return \"\";\n if (!/^\\s*\\{\\\\rtf/.test(rtf)) return rtf;\n\n let out = \"\";\n const stack: Array<{ skip: boolean; uc: number }> = [];\n let skip = false;\n // Number of fallback characters that follow a \\uN escape.\n let uc = 1;\n let pendingFallback = 0;\n // True right after `{`, so a destination control word can mark the group.\n let groupStart = false;\n\n const emit = (text: string) => {\n if (skip) return;\n if (pendingFallback > 0) {\n pendingFallback--;\n return;\n }\n out += text;\n };\n\n let i = 0;\n while (i < rtf.length) {\n const ch = rtf[i];\n if (ch === \"{\") {\n stack.push({ skip, uc });\n groupStart = true;\n i++;\n continue;\n }\n if (ch === \"}\") {\n const prev = stack.pop();\n if (prev) {\n skip = prev.skip;\n uc = prev.uc;\n }\n pendingFallback = 0;\n groupStart = false;\n i++;\n continue;\n }\n const atGroupStart = groupStart;\n groupStart = false;\n\n if (ch === \"\\\\\") {\n const next = rtf[i + 1];\n if (next === \"\\\\\" || next === \"{\" || next === \"}\") {\n emit(next);\n i += 2;\n continue;\n }\n if (next === \"*\") {\n // `{\\*\\dest …}`: an ignorable destination this reader doesn't know.\n skip = true;\n i += 2;\n continue;\n }\n if (next === \"'\") {\n const code = parseInt(rtf.slice(i + 2, i + 4), 16);\n if (!Number.isNaN(code)) emit(CP1252[code] ?? String.fromCharCode(code));\n i += 4;\n continue;\n }\n if (next === \"~\") {\n emit(\" \");\n i += 2;\n continue;\n }\n if (next === \"_\") {\n emit(\"‑\");\n i += 2;\n continue;\n }\n if (next === \"\\n\" || next === \"\\r\") {\n emit(\"\\n\");\n i += 2;\n continue;\n }\n CONTROL_WORD_REGEX.lastIndex = i;\n const match = CONTROL_WORD_REGEX.exec(rtf);\n if (!match) {\n // Other control symbols (`\\-`, `\\|`, `\\:`) produce no text.\n i += 2;\n continue;\n }\n i = CONTROL_WORD_REGEX.lastIndex;\n const word = match[1];\n const param = match[2] !== undefined ? parseInt(match[2], 10) : undefined;\n if (atGroupStart && SKIPPED_DESTINATIONS.has(word)) {\n skip = true;\n } else if (word === \"u\" && param !== undefined) {\n emit(String.fromCharCode(param < 0 ? param + 65536 : param));\n if (!skip) pendingFallback = uc;\n } else if (word === \"uc\" && param !== undefined) {\n uc = param;\n } else if (word === \"bin\" && param !== undefined) {\n // Raw binary data: skip it.\n i += param;\n } else if (CONTROL_WORD_TEXT[word] !== undefined) {\n emit(CONTROL_WORD_TEXT[word]);\n }\n continue;\n }\n // Raw newlines are formatting in RTF; only control words break lines.\n if (ch === \"\\n\" || ch === \"\\r\") {\n i++;\n continue;\n }\n emit(ch);\n i++;\n }\n\n return out.replace(/\\n+$/, \"\");\n}\n","import { Slice, type Schema } from \"@tiptap/pm/model\";\n\n/**\n * Custom clipboard MIME type for content copied from a @pixerate/editor\n * rich-text editor. It carries the ProseMirror slice as JSON so pasting back\n * into a compatible editor is lossless (no HTML round trip).\n */\nexport const PIXERATE_DOCUMENT_MIME = \"application/x.pixerate.document+json\";\n\n/** Payload written under {@link PIXERATE_DOCUMENT_MIME}. */\nexport interface RichClipboardPayload {\n version: 1;\n /** {@link getSchemaSignature} of the source editor's schema. */\n schema: string;\n /** `Slice.toJSON()` of the copied selection. */\n slice: { content?: unknown[]; openStart?: number; openEnd?: number } | null;\n}\n\nconst signatureCache = new WeakMap<Schema, string>();\n\n/** 32-bit FNV-1a, enough to tell schemas apart without a crypto dependency. */\nfunction fnv1a(text: string): string {\n let hash = 0x811c9dc5;\n for (let i = 0; i < text.length; i++) {\n hash ^= text.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n return (hash >>> 0).toString(16).padStart(8, \"0\");\n}\n\n/**\n * Returns a stable signature for a ProseMirror schema: node names, content\n * expressions, groups, attribute names and mark names. Two editors with the\n * same extensions produce the same signature, so a slice copied from one can\n * be deserialized in the other without losing or rejecting nodes.\n */\nexport function getSchemaSignature(schema: Schema): string {\n const cached = signatureCache.get(schema);\n if (cached) return cached;\n const parts: string[] = [];\n for (const [name, type] of Object.entries(schema.nodes)) {\n const spec = type.spec;\n parts.push(\n `n:${name}|${spec.content ?? \"\"}|${spec.group ?? \"\"}|${spec.marks ?? \"\"}|${Object.keys(type.spec.attrs ?? {}).sort().join(\",\")}`,\n );\n }\n for (const [name, type] of Object.entries(schema.marks)) {\n parts.push(`m:${name}|${Object.keys(type.spec.attrs ?? {}).sort().join(\",\")}`);\n }\n const signature = `pm1-${fnv1a(parts.join(\";\"))}`;\n signatureCache.set(schema, signature);\n return signature;\n}\n\n/** Serializes a slice into the {@link PIXERATE_DOCUMENT_MIME} payload string. */\nexport function serializeRichClipboardPayload(slice: Slice, schema: Schema): string {\n const payload: RichClipboardPayload = {\n version: 1,\n schema: getSchemaSignature(schema),\n slice: slice.toJSON(),\n };\n return JSON.stringify(payload);\n}\n\n/**\n * Parses a {@link PIXERATE_DOCUMENT_MIME} payload into a slice for `schema`.\n * Returns `null` (so callers fall back to HTML / plain text) when the payload\n * is malformed, from another payload version, or from an editor whose schema\n * signature differs.\n */\nexport function parseRichClipboardPayload(data: string | null | undefined, schema: Schema): Slice | null {\n if (!data) return null;\n try {\n const payload = JSON.parse(data) as Partial<RichClipboardPayload>;\n if (!payload || payload.version !== 1) return null;\n if (payload.schema !== getSchemaSignature(schema)) return null;\n if (!payload.slice) return null;\n return Slice.fromJSON(schema, payload.slice as any);\n } catch {\n return null;\n }\n}\n\n/** Minimal clipboard data surface (`DataTransfer`). */\nexport interface ClipboardDataLike {\n getData(format: string): string;\n setData(format: string, data: string): void;\n clearData?(format?: string): void;\n}\n\n/**\n * Returns the `clipboardData` of a native `ClipboardEvent` or of a React\n * synthetic clipboard event (which wraps the native event in `nativeEvent`).\n */\nexport function getClipboardData(event: unknown): ClipboardDataLike | null {\n if (!event || typeof event !== \"object\") return null;\n const native = \"nativeEvent\" in event ? (event as any).nativeEvent : event;\n return ((event as any).clipboardData ?? native?.clipboardData ?? null) as ClipboardDataLike | null;\n}\n\n/**\n * Reads a slice from a paste event's {@link PIXERATE_DOCUMENT_MIME} data.\n * Returns `null` when the data is missing or its schema does not match.\n */\nexport function readRichClipboard(\n event: unknown,\n schema: Schema,\n mimeType: string = PIXERATE_DOCUMENT_MIME,\n): Slice | null {\n const data = getClipboardData(event);\n if (!data) return null;\n let raw: string | undefined;\n try {\n raw = data.getData(mimeType);\n } catch {\n return null;\n }\n return parseRichClipboardPayload(raw, schema);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-HNDSPZ5T.cjs","../src/serializers/html.ts","../src/serializers/rtf.ts","../src/serializers/clipboard.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACGA,IAAM,wBAAA,EACJ,6HAAA;AAEF,IAAM,wBAAA,EAA0B,kCAAA;AAChC,IAAM,WAAA,EAAa,2CAAA;AAEnB,IAAM,qBAAA,EAAuB,oCAAA;AAetB,SAAS,oBAAA,CAAqB,IAAA,EAAsB;AACzD,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,OAAO,SAAA;AAClB,EAAA,IAAI,QAAA,EAAU,IAAA,CAAK,OAAA,CAAQ,IAAA,EAAM,EAAE,CAAA;AACnC,EAAA,QAAA,EAAU,OAAA,CACP,OAAA,CAAQ,wBAAA,EAA0B,EAAE,CAAA,CACpC,OAAA,CAAQ,iCAAA,EAAmC,EAAE,CAAA,CAC7C,OAAA,CAAQ,WAAA,EAAa,EAAE,CAAA,CACvB,OAAA,CAAQ,uBAAA,EAAyB,EAAE,CAAA;AACtC,EAAA,MAAM,KAAA,EAAO,UAAA,C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wB,IAAA;AACb,EAAA;AAEtB,EAAA;AACF;AAQO;AACL,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAkD,EAAA;AAElD,IAAA;AAAO,EAAA;AAEX;AAaO;AACL,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAMO;AAKL,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AAA2B,EAAA;AAE3B,IAAA;AAAO,EAAA;AAET,EAAA;AACF;AHwKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-HNDSPZ5T.cjs","sourcesContent":[null,"import { sanitizeHtml } from \"./markdown\";\nimport { escapeHtml } from \"./plain-text\";\n\n/**\n * Elements whose content is never document text (scripts, styles, metadata,\n * embedded objects, form controls). They are removed together with their\n * content before sanitizing, so e.g. CSS rules don't show up as paragraphs.\n */\nconst DROP_WITH_CONTENT_REGEX =\n /<(script|style|template|noscript|iframe|object|embed|head|title|svg|math|textarea|select|button)\\b[^>]*>[\\s\\S]*?<\\/\\1\\s*>/gi;\n/** An unclosed `<script>` / `<style>` swallows the rest of the document. */\nconst UNCLOSED_RAW_TEXT_REGEX = /<(script|style)\\b[^>]*>[\\s\\S]*$/i;\nconst BODY_REGEX = /<body\\b[^>]*>([\\s\\S]*?)(?:<\\/body\\s*>|$)/i;\n/** Namespaced tags such as Word's `<o:p>`, which the sanitizer cannot parse. */\nconst NAMESPACED_TAG_REGEX = /<\\/?[a-zA-Z][\\w-]*:[\\w-]+\\b[^>]*>/g;\n\n/**\n * Sanitizes a full HTML document or fragment for insertion into the editor,\n * e.g. an imported `.html` file or HTML from another application.\n *\n * - Keeps only the `<body>` content when the input is a full document.\n * - Removes comments, doctype/XML declarations, CDATA, scripts, styles and\n * other non-text elements together with their content.\n * - Applies the same tag/attribute/URL allowlist as embedded HTML in markdown\n * (see `sanitizeHtml`), but strips disallowed tags instead of escaping them,\n * so wrappers such as `<section>` or `<font>` keep their text.\n *\n * It is string-based (no live DOM), so handlers such as `<img onerror>` never run.\n */\nexport function sanitizeImportedHtml(html: string): string {\n if (!html) return \"<p></p>\";\n let content = html.replace(/^/, \"\");\n content = content\n .replace(/<!--[\\s\\S]*?(?:-->|$)/g, \"\")\n .replace(/<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>|$)/g, \"\")\n .replace(/<![^>]*>/g, \"\")\n .replace(/<\\?[\\s\\S]*?(?:\\?>|$)/g, \"\");\n const body = BODY_REGEX.exec(content);\n if (body) content = body[1];\n content = content\n .replace(DROP_WITH_CONTENT_REGEX, \"\")\n .replace(UNCLOSED_RAW_TEXT_REGEX, \"\")\n .replace(NAMESPACED_TAG_REGEX, \"\");\n const sanitized = sanitizeHtml(content, { disallowedTags: \"strip\" }).trim();\n return sanitized || \"<p></p>\";\n}\n\n/**\n * Converts untrusted plain text to TipTap paragraph HTML, always escaping it.\n *\n * Unlike `plainTextToTipTapHtml`, text that already looks like `<p>…</p>` is\n * not passed through as HTML, which matters for imported files.\n */\nexport function plainTextToParagraphHtml(text: string): string {\n if (!text) return \"<p></p>\";\n return text\n .replace(/\\r\\n?/g, \"\\n\")\n .split(\"\\n\")\n .map((line) => `<p>${escapeHtml(line)}</p>`)\n .join(\"\");\n}\n","/**\n * Destinations whose content is metadata or binary data rather than document\n * text. A group starting with one of these control words (or with `\\*`) is\n * skipped entirely.\n */\nconst SKIPPED_DESTINATIONS = new Set([\n \"author\", \"bkmkend\", \"bkmkstart\", \"colortbl\", \"comment\", \"datastore\",\n \"doccomm\", \"falt\", \"fldinst\", \"filetbl\", \"fonttbl\", \"footer\", \"footerf\",\n \"footerl\", \"footerr\", \"footnote\", \"generator\", \"header\", \"headerf\",\n \"headerl\", \"headerr\", \"info\", \"keywords\", \"latentstyles\", \"listoverridetable\",\n \"listtable\", \"nonshppict\", \"object\", \"operator\", \"pict\", \"private\", \"revtbl\",\n \"rsidtbl\", \"shppict\", \"stylesheet\", \"subject\", \"themedata\", \"title\",\n \"xmlnstbl\", \"colorschememapping\",\n]);\n\n/** Control words that map to a literal character. */\nconst CONTROL_WORD_TEXT: Record<string, string> = {\n par: \"\\n\",\n sect: \"\\n\",\n page: \"\\n\",\n line: \"\\n\",\n row: \"\\n\",\n cell: \"\\t\",\n tab: \"\\t\",\n emdash: \"—\",\n endash: \"–\",\n emspace: \" \",\n enspace: \" \",\n bullet: \"•\",\n lquote: \"‘\",\n rquote: \"’\",\n ldblquote: \"“\",\n rdblquote: \"”\",\n};\n\n/** Windows-1252 code points in 0x80–0x9F that differ from Latin-1. */\nconst CP1252: Record<number, string> = {\n 0x80: \"€\", 0x82: \"‚\", 0x83: \"ƒ\", 0x84: \"„\", 0x85: \"…\",\n 0x86: \"†\", 0x87: \"‡\", 0x88: \"ˆ\", 0x89: \"‰\", 0x8a: \"Š\",\n 0x8b: \"‹\", 0x8c: \"Œ\", 0x8e: \"Ž\", 0x91: \"‘\", 0x92: \"’\",\n 0x93: \"“\", 0x94: \"”\", 0x95: \"•\", 0x96: \"–\", 0x97: \"—\",\n 0x98: \"˜\", 0x99: \"™\", 0x9a: \"š\", 0x9b: \"›\", 0x9c: \"œ\",\n 0x9e: \"ž\", 0x9f: \"Ÿ\",\n};\n\nconst CONTROL_WORD_REGEX = /\\\\([a-zA-Z]{1,32})(-?\\d{1,10})? ?/y;\n\n/**\n * Best-effort plain-text extraction from an RTF document.\n *\n * Handles paragraphs/line breaks/tabs, escaped braces and backslashes,\n * `\\'hh` hex escapes (decoded as Windows-1252), `\\uN` Unicode escapes with\n * their `\\ucN` fallback characters, common typographic control words, and\n * skips metadata destinations (font/colour tables, `\\info`, pictures, field\n * instructions, `\\*` destinations). Formatting (bold, lists, tables) is not\n * preserved. Input that does not start with `{\\rtf` is returned unchanged.\n */\nexport function rtfToPlainText(rtf: string): string {\n if (!rtf) return \"\";\n if (!/^\\s*\\{\\\\rtf/.test(rtf)) return rtf;\n\n let out = \"\";\n const stack: Array<{ skip: boolean; uc: number }> = [];\n let skip = false;\n // Number of fallback characters that follow a \\uN escape.\n let uc = 1;\n let pendingFallback = 0;\n // True right after `{`, so a destination control word can mark the group.\n let groupStart = false;\n\n const emit = (text: string) => {\n if (skip) return;\n if (pendingFallback > 0) {\n pendingFallback--;\n return;\n }\n out += text;\n };\n\n let i = 0;\n while (i < rtf.length) {\n const ch = rtf[i];\n if (ch === \"{\") {\n stack.push({ skip, uc });\n groupStart = true;\n i++;\n continue;\n }\n if (ch === \"}\") {\n const prev = stack.pop();\n if (prev) {\n skip = prev.skip;\n uc = prev.uc;\n }\n pendingFallback = 0;\n groupStart = false;\n i++;\n continue;\n }\n const atGroupStart = groupStart;\n groupStart = false;\n\n if (ch === \"\\\\\") {\n const next = rtf[i + 1];\n if (next === \"\\\\\" || next === \"{\" || next === \"}\") {\n emit(next);\n i += 2;\n continue;\n }\n if (next === \"*\") {\n // `{\\*\\dest …}`: an ignorable destination this reader doesn't know.\n skip = true;\n i += 2;\n continue;\n }\n if (next === \"'\") {\n const code = parseInt(rtf.slice(i + 2, i + 4), 16);\n if (!Number.isNaN(code)) emit(CP1252[code] ?? String.fromCharCode(code));\n i += 4;\n continue;\n }\n if (next === \"~\") {\n emit(\" \");\n i += 2;\n continue;\n }\n if (next === \"_\") {\n emit(\"‑\");\n i += 2;\n continue;\n }\n if (next === \"\\n\" || next === \"\\r\") {\n emit(\"\\n\");\n i += 2;\n continue;\n }\n CONTROL_WORD_REGEX.lastIndex = i;\n const match = CONTROL_WORD_REGEX.exec(rtf);\n if (!match) {\n // Other control symbols (`\\-`, `\\|`, `\\:`) produce no text.\n i += 2;\n continue;\n }\n i = CONTROL_WORD_REGEX.lastIndex;\n const word = match[1];\n const param = match[2] !== undefined ? parseInt(match[2], 10) : undefined;\n if (atGroupStart && SKIPPED_DESTINATIONS.has(word)) {\n skip = true;\n } else if (word === \"u\" && param !== undefined) {\n emit(String.fromCharCode(param < 0 ? param + 65536 : param));\n if (!skip) pendingFallback = uc;\n } else if (word === \"uc\" && param !== undefined) {\n uc = param;\n } else if (word === \"bin\" && param !== undefined) {\n // Raw binary data: skip it.\n i += param;\n } else if (CONTROL_WORD_TEXT[word] !== undefined) {\n emit(CONTROL_WORD_TEXT[word]);\n }\n continue;\n }\n // Raw newlines are formatting in RTF; only control words break lines.\n if (ch === \"\\n\" || ch === \"\\r\") {\n i++;\n continue;\n }\n emit(ch);\n i++;\n }\n\n return out.replace(/\\n+$/, \"\");\n}\n","import { Slice, type Schema } from \"@tiptap/pm/model\";\n\n/**\n * Custom clipboard MIME type for content copied from a @pixerate/editor\n * rich-text editor. It carries the ProseMirror slice as JSON so pasting back\n * into a compatible editor is lossless (no HTML round trip).\n */\nexport const PIXERATE_DOCUMENT_MIME = \"application/x.pixerate.document+json\";\n\n/** Payload written under {@link PIXERATE_DOCUMENT_MIME}. */\nexport interface RichClipboardPayload {\n version: 1;\n /** {@link getSchemaSignature} of the source editor's schema. */\n schema: string;\n /** `Slice.toJSON()` of the copied selection. */\n slice: { content?: unknown[]; openStart?: number; openEnd?: number } | null;\n}\n\nconst signatureCache = new WeakMap<Schema, string>();\n\n/** 32-bit FNV-1a, enough to tell schemas apart without a crypto dependency. */\nfunction fnv1a(text: string): string {\n let hash = 0x811c9dc5;\n for (let i = 0; i < text.length; i++) {\n hash ^= text.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n return (hash >>> 0).toString(16).padStart(8, \"0\");\n}\n\n/**\n * Returns a stable signature for a ProseMirror schema: node names, content\n * expressions, groups, attribute names and mark names. Two editors with the\n * same extensions produce the same signature, so a slice copied from one can\n * be deserialized in the other without losing or rejecting nodes.\n */\nexport function getSchemaSignature(schema: Schema): string {\n const cached = signatureCache.get(schema);\n if (cached) return cached;\n const parts: string[] = [];\n for (const [name, type] of Object.entries(schema.nodes)) {\n const spec = type.spec;\n parts.push(\n `n:${name}|${spec.content ?? \"\"}|${spec.group ?? \"\"}|${spec.marks ?? \"\"}|${Object.keys(type.spec.attrs ?? {}).sort().join(\",\")}`,\n );\n }\n for (const [name, type] of Object.entries(schema.marks)) {\n parts.push(`m:${name}|${Object.keys(type.spec.attrs ?? {}).sort().join(\",\")}`);\n }\n const signature = `pm1-${fnv1a(parts.join(\";\"))}`;\n signatureCache.set(schema, signature);\n return signature;\n}\n\n/** Serializes a slice into the {@link PIXERATE_DOCUMENT_MIME} payload string. */\nexport function serializeRichClipboardPayload(slice: Slice, schema: Schema): string {\n const payload: RichClipboardPayload = {\n version: 1,\n schema: getSchemaSignature(schema),\n slice: slice.toJSON(),\n };\n return JSON.stringify(payload);\n}\n\n/**\n * Parses a {@link PIXERATE_DOCUMENT_MIME} payload into a slice for `schema`.\n * Returns `null` (so callers fall back to HTML / plain text) when the payload\n * is malformed, from another payload version, or from an editor whose schema\n * signature differs.\n */\nexport function parseRichClipboardPayload(data: string | null | undefined, schema: Schema): Slice | null {\n if (!data) return null;\n try {\n const payload = JSON.parse(data) as Partial<RichClipboardPayload>;\n if (!payload || payload.version !== 1) return null;\n if (payload.schema !== getSchemaSignature(schema)) return null;\n if (!payload.slice) return null;\n return Slice.fromJSON(schema, payload.slice as any);\n } catch {\n return null;\n }\n}\n\n/** Minimal clipboard data surface (`DataTransfer`). */\nexport interface ClipboardDataLike {\n getData(format: string): string;\n setData(format: string, data: string): void;\n clearData?(format?: string): void;\n}\n\n/**\n * Returns the `clipboardData` of a native `ClipboardEvent` or of a React\n * synthetic clipboard event (which wraps the native event in `nativeEvent`).\n */\nexport function getClipboardData(event: unknown): ClipboardDataLike | null {\n if (!event || typeof event !== \"object\") return null;\n const native = \"nativeEvent\" in event ? (event as any).nativeEvent : event;\n return ((event as any).clipboardData ?? native?.clipboardData ?? null) as ClipboardDataLike | null;\n}\n\n/**\n * Reads a slice from a paste event's {@link PIXERATE_DOCUMENT_MIME} data.\n * Returns `null` when the data is missing or its schema does not match.\n */\nexport function readRichClipboard(\n event: unknown,\n schema: Schema,\n mimeType: string = PIXERATE_DOCUMENT_MIME,\n): Slice | null {\n const data = getClipboardData(event);\n if (!data) return null;\n let raw: string | undefined;\n try {\n raw = data.getData(mimeType);\n } catch {\n return null;\n }\n return parseRichClipboardPayload(raw, schema);\n}\n"]}
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk26BVFKHUcjs = require('./chunk-26BVFKHU.cjs');
|
|
5
|
+
|
|
6
|
+
// src/commands/builtins.ts
|
|
7
|
+
var DEFAULT_HISTORY_SHORTCUTS = [
|
|
8
|
+
{ command: "undo", chord: "Mod+Z" },
|
|
9
|
+
{ command: "redo", chord: "Mod+Shift+Z" },
|
|
10
|
+
{ command: "redo", chord: "Mod+Y", platforms: ["windows", "linux"] }
|
|
11
|
+
];
|
|
12
|
+
function createHistoryCommands(history, options = {}) {
|
|
13
|
+
const prefix = _nullishCoalesce(options.prefix, () => ( "history."));
|
|
14
|
+
const group = _nullishCoalesce(options.group, () => ( "Edit"));
|
|
15
|
+
const shortcutsOf = (command) => DEFAULT_HISTORY_SHORTCUTS.filter((b) => b.command === command).map(({ command: _c, ...rest }) => rest);
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
id: `${prefix}undo`,
|
|
19
|
+
label: "Undo",
|
|
20
|
+
group,
|
|
21
|
+
keywords: ["revert", "back"],
|
|
22
|
+
description: "Reverts the last change.",
|
|
23
|
+
shortcut: shortcutsOf("undo"),
|
|
24
|
+
...options.scope ? { scope: options.scope } : {},
|
|
25
|
+
enabled: () => history.getState().canUndo ? true : "Nothing to undo.",
|
|
26
|
+
run: () => {
|
|
27
|
+
history.undo();
|
|
28
|
+
return { undone: true, state: history.getState() };
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: `${prefix}redo`,
|
|
33
|
+
label: "Redo",
|
|
34
|
+
group,
|
|
35
|
+
keywords: ["repeat", "forward"],
|
|
36
|
+
description: "Re-applies the last undone change.",
|
|
37
|
+
shortcut: shortcutsOf("redo"),
|
|
38
|
+
...options.scope ? { scope: options.scope } : {},
|
|
39
|
+
enabled: () => history.getState().canRedo ? true : "Nothing to redo.",
|
|
40
|
+
run: () => {
|
|
41
|
+
history.redo();
|
|
42
|
+
return { redone: true, state: history.getState() };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
var historyShortcutMap = null;
|
|
48
|
+
function matchHistoryShortcut(event, options = {}) {
|
|
49
|
+
historyShortcutMap ??= new (0, _chunk26BVFKHUcjs.ShortcutMap)(DEFAULT_HISTORY_SHORTCUTS);
|
|
50
|
+
return _nullishCoalesce(_optionalChain([historyShortcutMap, 'access', _2 => _2.resolve, 'call', _3 => _3(event, options), 'optionalAccess', _4 => _4.command]), () => ( null));
|
|
51
|
+
}
|
|
52
|
+
var ARRANGE_LABELS = {
|
|
53
|
+
alignLeft: "Align Left",
|
|
54
|
+
alignCenter: "Align Horizontal Centers",
|
|
55
|
+
alignRight: "Align Right",
|
|
56
|
+
alignTop: "Align Top",
|
|
57
|
+
alignMiddle: "Align Vertical Centers",
|
|
58
|
+
alignBottom: "Align Bottom",
|
|
59
|
+
distributeHorizontal: "Distribute Horizontally",
|
|
60
|
+
distributeVertical: "Distribute Vertically",
|
|
61
|
+
lock: "Lock",
|
|
62
|
+
unlock: "Unlock",
|
|
63
|
+
bringForward: "Bring Forward",
|
|
64
|
+
sendBackward: "Send Backward",
|
|
65
|
+
bringToFront: "Bring to Front",
|
|
66
|
+
sendToBack: "Send to Back",
|
|
67
|
+
nextScene: "Next Scene",
|
|
68
|
+
previousScene: "Previous Scene"
|
|
69
|
+
};
|
|
70
|
+
var IDS_PARAMS = {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
ids: {
|
|
74
|
+
type: "array",
|
|
75
|
+
items: { type: "string" },
|
|
76
|
+
description: "Node ids to act on (default: the selection)."
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function createArrangeCommands(controller, options = {}) {
|
|
81
|
+
const prefix = _nullishCoalesce(options.prefix, () => ( "canvas."));
|
|
82
|
+
const group = _nullishCoalesce(options.group, () => ( "Arrange"));
|
|
83
|
+
const scope = options.scope === null ? void 0 : _nullishCoalesce(options.scope, () => ( "canvas"));
|
|
84
|
+
const bindings = _nullishCoalesce(options.bindings, () => ( _chunk26BVFKHUcjs.DEFAULT_ARRANGE_SHORTCUTS));
|
|
85
|
+
const count = (params) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _5 => _5.ids, 'optionalAccess', _6 => _6.length]), () => ( _optionalChain([options, 'access', _7 => _7.getSelectedIds, 'optionalCall', _8 => _8(), 'access', _9 => _9.length])));
|
|
86
|
+
const needs = (min, what) => (_, params) => {
|
|
87
|
+
const n = count(params);
|
|
88
|
+
if (n === void 0 || n >= min) return true;
|
|
89
|
+
return min === 1 ? `Select a ${what} first.` : `Select at least ${min} ${what}s.`;
|
|
90
|
+
};
|
|
91
|
+
const run = {
|
|
92
|
+
alignLeft: (ids) => controller.align("left", ids),
|
|
93
|
+
alignCenter: (ids) => controller.align("center", ids),
|
|
94
|
+
alignRight: (ids) => controller.align("right", ids),
|
|
95
|
+
alignTop: (ids) => controller.align("top", ids),
|
|
96
|
+
alignMiddle: (ids) => controller.align("middle", ids),
|
|
97
|
+
alignBottom: (ids) => controller.align("bottom", ids),
|
|
98
|
+
distributeHorizontal: (ids) => controller.distribute("horizontal", "gaps", ids),
|
|
99
|
+
distributeVertical: (ids) => controller.distribute("vertical", "gaps", ids),
|
|
100
|
+
lock: (ids) => controller.lock(ids),
|
|
101
|
+
unlock: (ids) => controller.unlock(ids),
|
|
102
|
+
bringForward: (ids) => controller.reorder("bringForward", ids),
|
|
103
|
+
sendBackward: (ids) => controller.reorder("sendBackward", ids),
|
|
104
|
+
bringToFront: (ids) => controller.reorder("bringToFront", ids),
|
|
105
|
+
sendToBack: (ids) => controller.reorder("sendToBack", ids),
|
|
106
|
+
nextScene: () => _optionalChain([options, 'access', _10 => _10.scenes, 'optionalAccess', _11 => _11.next, 'call', _12 => _12()]),
|
|
107
|
+
previousScene: () => _optionalChain([options, 'access', _13 => _13.scenes, 'optionalAccess', _14 => _14.previous, 'call', _15 => _15()])
|
|
108
|
+
};
|
|
109
|
+
const actions = Object.keys(ARRANGE_LABELS);
|
|
110
|
+
return actions.filter((action) => options.scenes || action !== "nextScene" && action !== "previousScene").map((action) => {
|
|
111
|
+
const isScene = action === "nextScene" || action === "previousScene";
|
|
112
|
+
const enabled = isScene ? void 0 : action.startsWith("align") ? needs(2, "node") : action.startsWith("distribute") ? needs(3, "node") : needs(1, "node");
|
|
113
|
+
return {
|
|
114
|
+
id: `${prefix}${action}`,
|
|
115
|
+
label: ARRANGE_LABELS[action],
|
|
116
|
+
group: isScene ? "Scenes" : group,
|
|
117
|
+
keywords: isScene ? ["scene", "slide", "page"] : action.startsWith("align") ? ["align"] : ["arrange", "layer", "order"],
|
|
118
|
+
...scope ? { scope } : {},
|
|
119
|
+
shortcut: bindings.filter((b) => b.action === action).map((b) => b.label),
|
|
120
|
+
...isScene ? {} : { params: IDS_PARAMS },
|
|
121
|
+
...enabled ? { enabled } : {},
|
|
122
|
+
run: (_ctx, params) => run[action](_optionalChain([params, 'optionalAccess', _16 => _16.ids]))
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
var SHAPE_COMMANDS = [
|
|
127
|
+
{ op: "unite", label: "Unite Shapes", keywords: ["union", "merge", "boolean", "combine"] },
|
|
128
|
+
{ op: "intersect", label: "Intersect Shapes", keywords: ["intersection", "boolean", "combine"] },
|
|
129
|
+
{ op: "subtract", label: "Subtract Shapes", keywords: ["difference", "minus front", "boolean", "combine"] },
|
|
130
|
+
{ op: "exclude", label: "Exclude Shapes", keywords: ["xor", "boolean", "combine"] },
|
|
131
|
+
{ op: "divide", label: "Divide Shapes", keywords: ["split", "pathfinder", "boolean"] }
|
|
132
|
+
];
|
|
133
|
+
var JOIN_PARAM = { type: "string", enum: ["miter", "round", "bevel"], description: "Corner style (default miter)." };
|
|
134
|
+
function createShapeCommands(controller, options = {}) {
|
|
135
|
+
const prefix = _nullishCoalesce(options.prefix, () => ( "canvas."));
|
|
136
|
+
const group = _nullishCoalesce(options.group, () => ( "Shape"));
|
|
137
|
+
const scope = options.scope === null ? void 0 : _nullishCoalesce(options.scope, () => ( "canvas"));
|
|
138
|
+
const base = { group, ...scope ? { scope } : {} };
|
|
139
|
+
const combine = SHAPE_COMMANDS.map(
|
|
140
|
+
({ op, label, keywords }) => ({
|
|
141
|
+
...base,
|
|
142
|
+
id: `${prefix}${op}`,
|
|
143
|
+
label,
|
|
144
|
+
keywords: [...keywords],
|
|
145
|
+
description: `${label.split(" ")[0]}s the selected shapes into a new path (curves are kept).`,
|
|
146
|
+
params: IDS_PARAMS,
|
|
147
|
+
enabled: (_ctx, params) => controller.canCombineShapes(_optionalChain([params, 'optionalAccess', _17 => _17.ids])) ? true : "Select at least two unlocked shapes.",
|
|
148
|
+
run: (_ctx, params) => controller.combineShapes(op, _optionalChain([params, 'optionalAccess', _18 => _18.ids]))
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
return [
|
|
152
|
+
...combine,
|
|
153
|
+
{
|
|
154
|
+
...base,
|
|
155
|
+
id: `${prefix}offsetPath`,
|
|
156
|
+
label: "Offset Path\u2026",
|
|
157
|
+
keywords: ["inset", "outset", "grow", "shrink", "expand", "contract"],
|
|
158
|
+
description: "Grows (positive distance) or shrinks (negative) the selected shapes.",
|
|
159
|
+
params: {
|
|
160
|
+
type: "object",
|
|
161
|
+
properties: {
|
|
162
|
+
distance: { type: "number", description: `Offset in canvas units (default ${_nullishCoalesce(options.defaultOffset, () => ( 10))}).` },
|
|
163
|
+
join: JOIN_PARAM,
|
|
164
|
+
miterLimit: { type: "number", description: "Miter limit (default 4)." },
|
|
165
|
+
ids: IDS_PARAMS.properties.ids
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
enabled: (_ctx, params) => controller.canOffsetShapes(_optionalChain([params, 'optionalAccess', _19 => _19.ids])) ? true : "Select an unlocked shape.",
|
|
169
|
+
run: (_ctx, params) => controller.offsetShapes(_nullishCoalesce(_nullishCoalesce(_optionalChain([params, 'optionalAccess', _20 => _20.distance]), () => ( options.defaultOffset)), () => ( 10)), _optionalChain([params, 'optionalAccess', _21 => _21.ids]), {
|
|
170
|
+
..._optionalChain([params, 'optionalAccess', _22 => _22.join]) ? { join: params.join } : {},
|
|
171
|
+
..._optionalChain([params, 'optionalAccess', _23 => _23.miterLimit]) !== void 0 ? { miterLimit: params.miterLimit } : {}
|
|
172
|
+
})
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
...base,
|
|
176
|
+
id: `${prefix}outlineStroke`,
|
|
177
|
+
label: "Outline Stroke",
|
|
178
|
+
keywords: ["expand stroke", "stroke to path", "convert stroke"],
|
|
179
|
+
description: "Converts the strokes of the selected shapes to filled shapes.",
|
|
180
|
+
params: {
|
|
181
|
+
type: "object",
|
|
182
|
+
properties: {
|
|
183
|
+
join: JOIN_PARAM,
|
|
184
|
+
cap: { type: "string", enum: ["butt", "round", "square"], description: "Line cap (default butt)." },
|
|
185
|
+
miterLimit: { type: "number", description: "Miter limit (default 4)." },
|
|
186
|
+
ids: IDS_PARAMS.properties.ids
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
enabled: (_ctx, params) => controller.canOutlineStroke(_optionalChain([params, 'optionalAccess', _24 => _24.ids])) ? true : "Select an unlocked shape with a stroke.",
|
|
190
|
+
run: (_ctx, params) => controller.outlineStroke(_optionalChain([params, 'optionalAccess', _25 => _25.ids]), {
|
|
191
|
+
..._optionalChain([params, 'optionalAccess', _26 => _26.join]) ? { join: params.join } : {},
|
|
192
|
+
..._optionalChain([params, 'optionalAccess', _27 => _27.cap]) ? { cap: params.cap } : {},
|
|
193
|
+
..._optionalChain([params, 'optionalAccess', _28 => _28.miterLimit]) !== void 0 ? { miterLimit: params.miterLimit } : {}
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
function hasVariantCommands(controller) {
|
|
199
|
+
return typeof controller.addVariant === "function" && typeof controller.removeVariant === "function";
|
|
200
|
+
}
|
|
201
|
+
var SET_ID_PARAM = { type: "string", description: "Component set (or one of its variants) to act on (default: the selection\u2019s set)." };
|
|
202
|
+
var VARIANT_ID_PARAM = { type: "string", description: "Variant to act on (default: the first selected variant)." };
|
|
203
|
+
var VARIANT_VALUES_PARAM = {
|
|
204
|
+
type: "object",
|
|
205
|
+
description: 'Variant property \u2192 value, e.g. { "Size": "Medium" }. New property names are added to every variant.',
|
|
206
|
+
additionalProperties: { type: "string" }
|
|
207
|
+
};
|
|
208
|
+
function variantCommands(controller, prefix, base) {
|
|
209
|
+
return [
|
|
210
|
+
{
|
|
211
|
+
...base,
|
|
212
|
+
id: `${prefix}addVariant`,
|
|
213
|
+
label: "Add Variant",
|
|
214
|
+
keywords: ["variant", "new variant", "duplicate variant", "component set"],
|
|
215
|
+
description: "Adds a variant to a component set by duplicating one (default: the selected or default variant) with new property values.",
|
|
216
|
+
params: {
|
|
217
|
+
type: "object",
|
|
218
|
+
properties: {
|
|
219
|
+
setId: SET_ID_PARAM,
|
|
220
|
+
from: { type: "string", description: "Variant to duplicate (default: the selected variant, else the default one)." },
|
|
221
|
+
variant: VARIANT_VALUES_PARAM,
|
|
222
|
+
x: { type: "number", description: "X in the set\u2019s space (default: next to the source)." },
|
|
223
|
+
y: { type: "number", description: "Y in the set\u2019s space." }
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
enabled: (_ctx, params) => controller.canAddVariant(_optionalChain([params, 'optionalAccess', _29 => _29.setId]), {
|
|
227
|
+
..._optionalChain([params, 'optionalAccess', _30 => _30.from]) !== void 0 ? { from: params.from } : {},
|
|
228
|
+
..._optionalChain([params, 'optionalAccess', _31 => _31.variant]) ? { variant: params.variant } : {}
|
|
229
|
+
}),
|
|
230
|
+
run: (_ctx, params) => outcome(
|
|
231
|
+
controller.addVariant(_optionalChain([params, 'optionalAccess', _32 => _32.setId]), {
|
|
232
|
+
..._optionalChain([params, 'optionalAccess', _33 => _33.from]) !== void 0 ? { from: params.from } : {},
|
|
233
|
+
..._optionalChain([params, 'optionalAccess', _34 => _34.variant]) ? { variant: params.variant } : {},
|
|
234
|
+
..._optionalChain([params, 'optionalAccess', _35 => _35.x]) !== void 0 || _optionalChain([params, 'optionalAccess', _36 => _36.y]) !== void 0 ? { position: { x: _nullishCoalesce(_optionalChain([params, 'optionalAccess', _37 => _37.x]), () => ( 0)), y: _nullishCoalesce(_optionalChain([params, 'optionalAccess', _38 => _38.y]), () => ( 0)) } } : {}
|
|
235
|
+
})
|
|
236
|
+
)
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
...base,
|
|
240
|
+
id: `${prefix}removeVariant`,
|
|
241
|
+
label: "Remove Variant",
|
|
242
|
+
keywords: ["delete variant", "variant"],
|
|
243
|
+
description: "Removes a variant; its instances switch to the closest remaining variant, keeping overrides.",
|
|
244
|
+
params: { type: "object", properties: { id: VARIANT_ID_PARAM } },
|
|
245
|
+
enabled: (_ctx, params) => controller.canRemoveVariant(_optionalChain([params, 'optionalAccess', _39 => _39.id])),
|
|
246
|
+
run: (_ctx, params) => outcome(controller.removeVariant(_optionalChain([params, 'optionalAccess', _40 => _40.id])))
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
...base,
|
|
250
|
+
id: `${prefix}setVariantProperties`,
|
|
251
|
+
label: "Edit Variant Properties\u2026",
|
|
252
|
+
keywords: ["rename variant", "variant values", "variant"],
|
|
253
|
+
description: "Sets a variant\u2019s property values (refusing a combination another variant has).",
|
|
254
|
+
params: { type: "object", properties: { values: VARIANT_VALUES_PARAM, id: VARIANT_ID_PARAM }, required: ["values"] },
|
|
255
|
+
enabled: (_ctx, params) => controller.canSetVariantProperties(_optionalChain([params, 'optionalAccess', _41 => _41.values]), _optionalChain([params, 'optionalAccess', _42 => _42.id])),
|
|
256
|
+
run: (_ctx, params) => outcome(controller.setVariantProperties(params.values, _optionalChain([params, 'optionalAccess', _43 => _43.id])))
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
...base,
|
|
260
|
+
id: `${prefix}renameVariantProperty`,
|
|
261
|
+
label: "Rename Variant Property\u2026",
|
|
262
|
+
keywords: ["rename property", "variant property"],
|
|
263
|
+
description: "Renames a variant property across a component set.",
|
|
264
|
+
params: {
|
|
265
|
+
type: "object",
|
|
266
|
+
properties: { name: { type: "string" }, newName: { type: "string" }, setId: SET_ID_PARAM },
|
|
267
|
+
required: ["name", "newName"]
|
|
268
|
+
},
|
|
269
|
+
enabled: (_ctx, params) => controller.canRenameVariantProperty(_optionalChain([params, 'optionalAccess', _44 => _44.name]), _optionalChain([params, 'optionalAccess', _45 => _45.newName]), _optionalChain([params, 'optionalAccess', _46 => _46.setId])),
|
|
270
|
+
run: (_ctx, params) => outcome(controller.renameVariantProperty(params.name, params.newName, _optionalChain([params, 'optionalAccess', _47 => _47.setId])))
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
...base,
|
|
274
|
+
id: `${prefix}renameVariantValue`,
|
|
275
|
+
label: "Rename Variant Value\u2026",
|
|
276
|
+
keywords: ["rename value", "variant value"],
|
|
277
|
+
description: "Renames a value of a variant property across a component set.",
|
|
278
|
+
params: {
|
|
279
|
+
type: "object",
|
|
280
|
+
properties: { property: { type: "string" }, value: { type: "string" }, newValue: { type: "string" }, setId: SET_ID_PARAM },
|
|
281
|
+
required: ["property", "value", "newValue"]
|
|
282
|
+
},
|
|
283
|
+
enabled: (_ctx, params) => controller.canRenameVariantValue(_optionalChain([params, 'optionalAccess', _48 => _48.property]), _optionalChain([params, 'optionalAccess', _49 => _49.value]), _optionalChain([params, 'optionalAccess', _50 => _50.newValue]), _optionalChain([params, 'optionalAccess', _51 => _51.setId])),
|
|
284
|
+
run: (_ctx, params) => outcome(controller.renameVariantValue(params.property, params.value, params.newValue, _optionalChain([params, 'optionalAccess', _52 => _52.setId])))
|
|
285
|
+
}
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
var outcome = (result) => {
|
|
289
|
+
if (!result.ok) throw new Error(result.reason);
|
|
290
|
+
return { ids: result.ids };
|
|
291
|
+
};
|
|
292
|
+
var ID_PARAM = { type: "string", description: "Instance (or layer inside one) to act on (default: the first selected node)." };
|
|
293
|
+
function createComponentCommands(controller, options = {}) {
|
|
294
|
+
const prefix = _nullishCoalesce(options.prefix, () => ( "canvas."));
|
|
295
|
+
const group = _nullishCoalesce(options.group, () => ( "Components"));
|
|
296
|
+
const scope = options.scope === null ? void 0 : _nullishCoalesce(options.scope, () => ( "canvas"));
|
|
297
|
+
const base = { group, ...scope ? { scope } : {} };
|
|
298
|
+
const idParams = { type: "object", properties: { id: ID_PARAM } };
|
|
299
|
+
return [
|
|
300
|
+
{
|
|
301
|
+
...base,
|
|
302
|
+
id: `${prefix}createComponent`,
|
|
303
|
+
label: "Create Component",
|
|
304
|
+
keywords: ["component", "symbol", "main component", "reusable"],
|
|
305
|
+
description: "Turns the selected frame into a main component, or wraps the selection in one.",
|
|
306
|
+
params: IDS_PARAMS,
|
|
307
|
+
shortcut: "Mod+Alt+K",
|
|
308
|
+
enabled: (_ctx, params) => controller.canCreateComponent(_optionalChain([params, 'optionalAccess', _53 => _53.ids])),
|
|
309
|
+
run: (_ctx, params) => outcome(controller.createComponent(_optionalChain([params, 'optionalAccess', _54 => _54.ids])))
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
...base,
|
|
313
|
+
id: `${prefix}combineAsVariants`,
|
|
314
|
+
label: "Combine as Variants",
|
|
315
|
+
keywords: ["component set", "variant", "variants"],
|
|
316
|
+
description: "Wraps the selected components in a component set.",
|
|
317
|
+
params: IDS_PARAMS,
|
|
318
|
+
enabled: (_ctx, params) => controller.canCombineAsVariants(_optionalChain([params, 'optionalAccess', _55 => _55.ids])),
|
|
319
|
+
run: (_ctx, params) => outcome(controller.combineAsVariants(_optionalChain([params, 'optionalAccess', _56 => _56.ids])))
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
...base,
|
|
323
|
+
id: `${prefix}createInstance`,
|
|
324
|
+
label: "Create Instance",
|
|
325
|
+
keywords: ["instance", "insert component", "use component"],
|
|
326
|
+
description: "Places an instance of a component (or a component set\u2019s default variant).",
|
|
327
|
+
params: {
|
|
328
|
+
type: "object",
|
|
329
|
+
properties: {
|
|
330
|
+
componentId: { type: "string", description: "Component or component set id." },
|
|
331
|
+
parentId: { type: "string", description: "Frame to place it in (default: the canvas)." },
|
|
332
|
+
x: { type: "number", description: "X in the parent\u2019s space (default: next to the main)." },
|
|
333
|
+
y: { type: "number", description: "Y in the parent\u2019s space." },
|
|
334
|
+
properties: { type: "object", description: "Variant and component property values.", additionalProperties: true }
|
|
335
|
+
},
|
|
336
|
+
required: ["componentId"]
|
|
337
|
+
},
|
|
338
|
+
enabled: (_ctx, params) => _optionalChain([params, 'optionalAccess', _57 => _57.componentId]) === void 0 ? true : controller.canCreateInstance(params.componentId, params.parentId),
|
|
339
|
+
run: (_ctx, params) => outcome(
|
|
340
|
+
controller.createInstance(params.componentId, {
|
|
341
|
+
...params.parentId !== void 0 ? { parentId: params.parentId } : {},
|
|
342
|
+
...params.x !== void 0 || params.y !== void 0 ? { position: { x: _nullishCoalesce(params.x, () => ( 0)), y: _nullishCoalesce(params.y, () => ( 0)) } } : {},
|
|
343
|
+
...params.properties ? { properties: params.properties } : {}
|
|
344
|
+
})
|
|
345
|
+
)
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
...base,
|
|
349
|
+
id: `${prefix}detachInstance`,
|
|
350
|
+
label: "Detach Instance",
|
|
351
|
+
keywords: ["unlink", "break instance"],
|
|
352
|
+
description: "Turns the selected instances into plain frames that keep their look.",
|
|
353
|
+
params: IDS_PARAMS,
|
|
354
|
+
shortcut: "Mod+Alt+B",
|
|
355
|
+
enabled: (_ctx, params) => controller.canDetachInstance(_optionalChain([params, 'optionalAccess', _58 => _58.ids])),
|
|
356
|
+
run: (_ctx, params) => outcome(controller.detachInstance(_optionalChain([params, 'optionalAccess', _59 => _59.ids])))
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
...base,
|
|
360
|
+
id: `${prefix}resetOverrides`,
|
|
361
|
+
label: "Reset All Changes",
|
|
362
|
+
keywords: ["reset instance", "reset overrides", "revert"],
|
|
363
|
+
description: "Resets the overrides of an instance (or of a layer, or one override group) to its main.",
|
|
364
|
+
params: {
|
|
365
|
+
type: "object",
|
|
366
|
+
properties: {
|
|
367
|
+
id: ID_PARAM,
|
|
368
|
+
group: { type: "string", description: 'One override group to reset, e.g. "data.label" or "shape.fill" (default: all).' }
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
enabled: (_ctx, params) => controller.canResetOverrides(_optionalChain([params, 'optionalAccess', _60 => _60.id])),
|
|
372
|
+
run: (_ctx, params) => outcome(controller.resetOverrides(_optionalChain([params, 'optionalAccess', _61 => _61.id]), _optionalChain([params, 'optionalAccess', _62 => _62.group])))
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
...base,
|
|
376
|
+
id: `${prefix}pushOverrides`,
|
|
377
|
+
label: "Push Changes to Main Component",
|
|
378
|
+
keywords: ["push overrides", "update main component"],
|
|
379
|
+
description: "Copies the instance\u2019s overrides to its main component and every other instance.",
|
|
380
|
+
params: idParams,
|
|
381
|
+
enabled: (_ctx, params) => controller.canPushOverrides(_optionalChain([params, 'optionalAccess', _63 => _63.id])),
|
|
382
|
+
run: (_ctx, params) => outcome(controller.pushOverrides(_optionalChain([params, 'optionalAccess', _64 => _64.id])))
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
...base,
|
|
386
|
+
id: `${prefix}goToMainComponent`,
|
|
387
|
+
label: "Go to Main Component",
|
|
388
|
+
keywords: ["main component", "find main", "reveal"],
|
|
389
|
+
description: "Selects the main component of the selected instance.",
|
|
390
|
+
params: idParams,
|
|
391
|
+
enabled: (_ctx, params) => controller.canGoToMainComponent(_optionalChain([params, 'optionalAccess', _65 => _65.id])),
|
|
392
|
+
run: (_ctx, params) => {
|
|
393
|
+
const main = controller.goToMainComponent(_optionalChain([params, 'optionalAccess', _66 => _66.id]));
|
|
394
|
+
if (!main) throw new Error("The main component was not found.");
|
|
395
|
+
return { id: main };
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
...base,
|
|
400
|
+
id: `${prefix}swapInstance`,
|
|
401
|
+
label: "Swap Instance\u2026",
|
|
402
|
+
keywords: ["replace instance", "swap component"],
|
|
403
|
+
description: "Makes the selected instances show another component, keeping matching overrides.",
|
|
404
|
+
params: {
|
|
405
|
+
type: "object",
|
|
406
|
+
properties: {
|
|
407
|
+
componentId: { type: "string", description: "Component or component set to swap to." },
|
|
408
|
+
ids: IDS_PARAMS.properties.ids
|
|
409
|
+
},
|
|
410
|
+
required: ["componentId"]
|
|
411
|
+
},
|
|
412
|
+
enabled: (_ctx, params) => controller.canSwapInstance(_optionalChain([params, 'optionalAccess', _67 => _67.componentId]), _optionalChain([params, 'optionalAccess', _68 => _68.ids])),
|
|
413
|
+
run: (_ctx, params) => outcome(controller.swapInstance(params.componentId, _optionalChain([params, 'optionalAccess', _69 => _69.ids])))
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
...base,
|
|
417
|
+
id: `${prefix}setInstanceProperties`,
|
|
418
|
+
label: "Set Instance Properties\u2026",
|
|
419
|
+
keywords: ["variant", "switch variant", "component property", "toggle"],
|
|
420
|
+
description: "Sets variant properties (switching variants) and component property values of the selected instances.",
|
|
421
|
+
params: {
|
|
422
|
+
type: "object",
|
|
423
|
+
properties: {
|
|
424
|
+
properties: { type: "object", description: "Property name \u2192 value (variant value, boolean, text or component id).", additionalProperties: true },
|
|
425
|
+
ids: IDS_PARAMS.properties.ids
|
|
426
|
+
},
|
|
427
|
+
required: ["properties"]
|
|
428
|
+
},
|
|
429
|
+
enabled: (_ctx, params) => controller.canSetInstanceProperties(_optionalChain([params, 'optionalAccess', _70 => _70.ids])),
|
|
430
|
+
run: (_ctx, params) => outcome(controller.setInstanceProperties(params.properties, _optionalChain([params, 'optionalAccess', _71 => _71.ids])))
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
...base,
|
|
434
|
+
id: `${prefix}restoreMainComponent`,
|
|
435
|
+
label: "Restore Main Component",
|
|
436
|
+
keywords: ["missing main", "recover component"],
|
|
437
|
+
description: "Turns an instance whose main was deleted back into the main component.",
|
|
438
|
+
params: idParams,
|
|
439
|
+
enabled: (_ctx, params) => controller.canRestoreMainComponent(_optionalChain([params, 'optionalAccess', _72 => _72.id])),
|
|
440
|
+
run: (_ctx, params) => outcome(controller.restoreMainComponent(_optionalChain([params, 'optionalAccess', _73 => _73.id])))
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
...base,
|
|
444
|
+
id: `${prefix}listComponents`,
|
|
445
|
+
label: "List Components",
|
|
446
|
+
keywords: ["components", "variants", "assets"],
|
|
447
|
+
description: "Lists the components and component sets (with their variant options).",
|
|
448
|
+
readOnly: true,
|
|
449
|
+
run: () => controller.list()
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
...base,
|
|
453
|
+
id: `${prefix}inspectInstance`,
|
|
454
|
+
label: "Inspect Instance",
|
|
455
|
+
keywords: ["instance", "overrides", "properties"],
|
|
456
|
+
description: "Describes an instance: its main, variant, property values and overrides.",
|
|
457
|
+
params: idParams,
|
|
458
|
+
readOnly: true,
|
|
459
|
+
enabled: (_ctx, params) => controller.inspect(_optionalChain([params, 'optionalAccess', _74 => _74.id])) ? true : "Select an instance.",
|
|
460
|
+
run: (_ctx, params) => _nullishCoalesce(controller.inspect(_optionalChain([params, 'optionalAccess', _75 => _75.id])), () => ( null))
|
|
461
|
+
},
|
|
462
|
+
...hasVariantCommands(controller) ? variantCommands(controller, prefix, base) : []
|
|
463
|
+
];
|
|
464
|
+
}
|
|
465
|
+
function createSpreadsheetCommands(controller, options = {}) {
|
|
466
|
+
const prefix = _nullishCoalesce(options.prefix, () => ( "spreadsheet."));
|
|
467
|
+
const scope = options.scope === null ? void 0 : _nullishCoalesce(options.scope, () => ( "spreadsheet"));
|
|
468
|
+
const hasRange = () => controller.selectedRange ? true : "Select a range first.";
|
|
469
|
+
const base = { group: "Table", ...scope ? { scope } : {} };
|
|
470
|
+
return [
|
|
471
|
+
{ ...base, id: `${prefix}toggleFilters`, label: "Toggle Filters", keywords: ["filter"], run: () => controller.toggleFilters() },
|
|
472
|
+
{
|
|
473
|
+
...base,
|
|
474
|
+
id: `${prefix}clearFilters`,
|
|
475
|
+
label: "Clear Filters",
|
|
476
|
+
keywords: ["filter", "reset"],
|
|
477
|
+
enabled: () => controller.getFilterState().rules.length > 0 ? true : "No filters to clear.",
|
|
478
|
+
run: () => controller.clearFilters()
|
|
479
|
+
},
|
|
480
|
+
{ ...base, id: `${prefix}unhideAll`, label: "Unhide All Rows and Columns", keywords: ["show", "hidden"], run: () => controller.unhideAll() },
|
|
481
|
+
{ ...base, id: `${prefix}mergeCells`, label: "Merge Cells", keywords: ["combine"], enabled: hasRange, run: () => controller.mergeCells() },
|
|
482
|
+
{ ...base, id: `${prefix}unmergeCells`, label: "Unmerge Cells", keywords: ["split"], enabled: hasRange, run: () => controller.unmergeCells() },
|
|
483
|
+
{ ...base, id: `${prefix}transposeRange`, label: "Transpose Range", keywords: ["rotate", "swap rows columns"], enabled: hasRange, run: () => controller.transposeRange() }
|
|
484
|
+
];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
exports.DEFAULT_HISTORY_SHORTCUTS = DEFAULT_HISTORY_SHORTCUTS; exports.createHistoryCommands = createHistoryCommands; exports.matchHistoryShortcut = matchHistoryShortcut; exports.createArrangeCommands = createArrangeCommands; exports.createShapeCommands = createShapeCommands; exports.hasVariantCommands = hasVariantCommands; exports.createComponentCommands = createComponentCommands; exports.createSpreadsheetCommands = createSpreadsheetCommands;
|
|
497
|
+
//# sourceMappingURL=chunk-HXDMZQTD.cjs.map
|