@pairdraw/core 0.19.0 → 0.19.2
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/dist/canvas/overlays/index.d.ts +2 -2
- package/dist/canvas/overlays/index.js +2 -2
- package/dist/canvas/overlays/selection.d.ts +1 -2
- package/dist/canvas/overlays/selection.d.ts.map +1 -1
- package/dist/canvas/overlays/selection.js +2 -9
- package/dist/canvas/overlays/selection.js.map +1 -1
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +2 -0
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +0 -1
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -4
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
- package/dist/canvas/renderer/overlay-pass.js +0 -1
- package/dist/canvas/renderer/overlay-pass.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +0 -1
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +0 -1
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +0 -1
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/design-jsx/index.d.ts +2 -2
- package/dist/design-jsx/index.js +2 -2
- package/dist/design-jsx/renderer.d.ts +3 -2
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/design-jsx/renderer.js +2 -2
- package/dist/design-jsx/renderer.js.map +1 -1
- package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
- package/dist/editor/clipboard/snapshot.js +12 -4
- package/dist/editor/clipboard/snapshot.js.map +1 -1
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +2 -7
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/color-space.d.ts.map +1 -1
- package/dist/editor/color-space.js +33 -38
- package/dist/editor/color-space.js.map +1 -1
- package/dist/editor/create.d.ts +9 -5
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +10 -1
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +2 -1
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/nudge.js +1 -1
- package/dist/editor/nudge.js.map +1 -1
- package/dist/editor/read-only/actions.js +2 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/container.d.ts +2 -0
- package/dist/editor/selection/container.d.ts.map +1 -1
- package/dist/editor/selection/container.js +17 -1
- package/dist/editor/selection/container.js.map +1 -1
- package/dist/editor/selection/navigation.js +7 -4
- package/dist/editor/selection/navigation.js.map +1 -1
- package/dist/editor/selection/read.d.ts +2 -2
- package/dist/editor/selection.d.ts +4 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/shapes/with-text.d.ts.map +1 -1
- package/dist/editor/shapes/with-text.js +2 -5
- package/dist/editor/shapes/with-text.js.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.js +1 -1
- package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
- package/dist/editor/structure/boolean.d.ts +2 -3
- package/dist/editor/structure/boolean.d.ts.map +1 -1
- package/dist/editor/structure/boolean.js.map +1 -1
- package/dist/editor/structure/group/bounds.d.ts.map +1 -1
- package/dist/editor/structure/group/bounds.js +1 -3
- package/dist/editor/structure/group/bounds.js.map +1 -1
- package/dist/editor/structure/outline-stroke.js +3 -3
- package/dist/editor/structure/outline-stroke.js.map +1 -1
- package/dist/editor/structure/reorder.d.ts.map +1 -1
- package/dist/editor/structure/reorder.js +7 -14
- package/dist/editor/structure/reorder.js.map +1 -1
- package/dist/editor/structure/state.js +1 -1
- package/dist/editor/structure/state.js.map +1 -1
- package/dist/editor/structure.d.ts +1 -2
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/structure.js +3 -3
- package/dist/editor/structure.js.map +1 -1
- package/dist/editor/types.d.ts +4 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variables.d.ts.map +1 -1
- package/dist/editor/variables.js +57 -1
- package/dist/editor/variables.js.map +1 -1
- package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
- package/dist/figma-api/accessors/text/index.js +4 -1
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/fonts/loaded.d.ts +3 -1
- package/dist/figma-api/fonts/loaded.d.ts.map +1 -1
- package/dist/figma-api/fonts/loaded.js +8 -1
- package/dist/figma-api/fonts/loaded.js.map +1 -1
- package/dist/figma-api/index.d.ts +13 -0
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +13 -0
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/serialization.d.ts.map +1 -1
- package/dist/figma-api/serialization.js +2 -1
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/figma-api/shape-details.d.ts +26 -0
- package/dist/figma-api/shape-details.d.ts.map +1 -0
- package/dist/figma-api/shape-details.js +28 -0
- package/dist/figma-api/shape-details.js.map +1 -0
- package/dist/figma-api/shape-with-text.js +2 -5
- package/dist/figma-api/shape-with-text.js.map +1 -1
- package/dist/figma-api/surface.d.ts +1 -1
- package/dist/figma-api/surface.d.ts.map +1 -1
- package/dist/figma-api/surface.js +1 -0
- package/dist/figma-api/surface.js.map +1 -1
- package/dist/icons/svg.js +1 -1
- package/dist/icons/svg.js.map +1 -1
- package/dist/io/formats/design-tokens/apply.d.ts +1 -1
- package/dist/io/formats/drawio/index.d.ts.map +1 -1
- package/dist/io/formats/drawio/index.js +1 -1
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +7 -4
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +4 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/pdf/dom.d.ts +6 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +9 -22
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/export.js +1 -1
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +3 -1
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +52 -16
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +50 -12
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/derived.d.ts +7 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +11 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/grid.d.ts +7 -2
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +27 -9
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout/mutations.d.ts +1 -0
- package/dist/layout/mutations.d.ts.map +1 -1
- package/dist/layout/mutations.js +10 -0
- package/dist/layout/mutations.js.map +1 -1
- package/dist/layout/strokes.d.ts +9 -1
- package/dist/layout/strokes.d.ts.map +1 -1
- package/dist/layout/strokes.js +12 -1
- package/dist/layout/strokes.js.map +1 -1
- package/dist/layout/yoga-helpers.d.ts +3 -1
- package/dist/layout/yoga-helpers.d.ts.map +1 -1
- package/dist/layout/yoga-helpers.js +16 -2
- package/dist/layout/yoga-helpers.js.map +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +71 -38
- package/dist/layout.js.map +1 -1
- package/dist/lint/linter.d.ts +1 -0
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +13 -1
- package/dist/lint/linter.js.map +1 -1
- package/dist/lint/rules/effect-style-required.js +1 -0
- package/dist/lint/rules/effect-style-required.js.map +1 -1
- package/dist/lint/rules/text-style-required.js +1 -0
- package/dist/lint/rules/text-style-required.js.map +1 -1
- package/dist/lint/types.d.ts +7 -0
- package/dist/lint/types.d.ts.map +1 -1
- package/dist/rpc/commands.d.ts +2 -2
- package/dist/rpc/index.d.ts +2 -2
- package/dist/rpc/read-commands.d.ts +18 -8
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +18 -9
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/font/faces.d.ts +12 -1
- package/dist/text/font/faces.d.ts.map +1 -1
- package/dist/text/font/faces.js +15 -1
- package/dist/text/font/faces.js.map +1 -1
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +6 -11
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +2 -2
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +1 -0
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +14 -0
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/vector/path.d.ts.map +1 -1
- package/dist/tools/vector/path.js +39 -7
- package/dist/tools/vector/path.js.map +1 -1
- package/dist/xpath.d.ts +3 -0
- package/dist/xpath.d.ts.map +1 -1
- package/dist/xpath.js +3 -1
- package/dist/xpath.js.map +1 -1
- package/package.json +9 -9
- package/src/canvas/overlays/index.ts +0 -1
- package/src/canvas/overlays/selection.ts +1 -12
- package/src/canvas/renderer/fonts.ts +2 -0
- package/src/canvas/renderer/methods.ts +0 -9
- package/src/canvas/renderer/overlay-pass.ts +0 -1
- package/src/canvas/renderer/pipeline.ts +0 -1
- package/src/canvas/renderer/types.ts +0 -1
- package/src/canvas/renderer.ts +0 -1
- package/src/design-jsx/index.ts +1 -1
- package/src/design-jsx/renderer.ts +1 -1
- package/src/editor/clipboard/snapshot.ts +21 -4
- package/src/editor/clipboard.ts +4 -14
- package/src/editor/color-space.ts +47 -38
- package/src/editor/create.ts +14 -2
- package/src/editor/history/edit.ts +5 -1
- package/src/editor/nudge.ts +1 -1
- package/src/editor/read-only/actions.ts +2 -0
- package/src/editor/selection/container.ts +24 -1
- package/src/editor/selection/navigation.ts +8 -6
- package/src/editor/shapes/with-text.ts +2 -5
- package/src/editor/structure/auto-layout-wrap.ts +1 -1
- package/src/editor/structure/boolean.ts +1 -3
- package/src/editor/structure/group/bounds.ts +1 -5
- package/src/editor/structure/outline-stroke.ts +3 -3
- package/src/editor/structure/reorder.ts +8 -14
- package/src/editor/structure/state.ts +1 -1
- package/src/editor/structure.ts +5 -8
- package/src/editor/types.ts +4 -1
- package/src/editor/variables.ts +74 -2
- package/src/figma-api/accessors/text/index.ts +10 -1
- package/src/figma-api/fonts/loaded.ts +9 -0
- package/src/figma-api/index.ts +25 -0
- package/src/figma-api/serialization.ts +2 -1
- package/src/figma-api/shape-details.ts +50 -0
- package/src/figma-api/shape-with-text.ts +2 -5
- package/src/figma-api/surface.ts +1 -0
- package/src/global.d.ts +5 -0
- package/src/icons/svg.ts +3 -1
- package/src/io/formats/drawio/index.ts +3 -1
- package/src/io/formats/html/layers.ts +11 -2
- package/src/io/formats/pdf/dom.ts +10 -18
- package/src/io/formats/pdf/export.ts +1 -1
- package/src/io/formats/svg/defs.ts +10 -1
- package/src/io/formats/svg/export.ts +94 -19
- package/src/layout/apply.ts +87 -21
- package/src/layout/derived.ts +14 -0
- package/src/layout/grid.ts +33 -9
- package/src/layout/mutations.ts +13 -1
- package/src/layout/strokes.ts +12 -0
- package/src/layout/yoga-helpers.ts +18 -1
- package/src/layout.ts +94 -49
- package/src/lint/linter.ts +17 -2
- package/src/lint/rules/effect-style-required.ts +2 -0
- package/src/lint/rules/text-style-required.ts +2 -0
- package/src/lint/types.ts +8 -0
- package/src/rpc/index.ts +1 -0
- package/src/rpc/read-commands.ts +40 -23
- package/src/text/font/faces.ts +22 -0
- package/src/text/font/manager.ts +9 -11
- package/src/tools/modify/layout.ts +5 -0
- package/src/tools/read/nodes.ts +0 -1
- package/src/tools/structure/batch.ts +22 -0
- package/src/tools/vector/path.ts +30 -6
- package/src/xpath.ts +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","names":[],"sources":["../../../src/editor/history/edit.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\nimport type { UndoEntry, UndoManager } from '@pairdraw/scene-graph/undo'\n\nimport {\n applyDocumentChange,\n isEmptyDocumentChange,\n recordDocumentChange,\n restoreDocumentChange,\n type DocumentChange,\n type DocumentChangeRecorder\n} from '#core/editor/history/document-change'\nimport type { EditorContext } from '#core/editor/types'\n\nexport interface RecordEditOptions {\n /** The undo step's label. */\n label: string\n /** The page the edit is made from; it is recorded wherever in the document it lands. */\n pageId?: string\n /** False for an edit that records its own steps, such as an atomic tool's. */\n push?: boolean\n /**\n * Records the step on its own, settling any batch first, rather than as part of an open batch.\n * An edit that finishes after an await needs this: a batch open by then belongs to another\n * edit, such as a picker drag. `recordEditAsync` always does.\n */\n ownStep?: boolean\n /**\n * Puts back everything the edit changed when it throws, so a failed agent call or script leaves\n * the document as it found it and records no step. Undoing it costs what the edit touched, not\n * a copy of the document. Without it, or when something else wrote to the document while the\n * edit ran, what the edit did before it threw stays as one step.\n */\n rollbackOnThrow?: boolean\n /**\n * Whether nothing outside the editor's history wrote to the document since the edit began, such\n * as a collaborator. Asked once the edit has thrown; false records the edit's step instead of a\n * rollback that would revert those writes too. Writes the history sees are checked anyway.\n */\n canRollBack?: () => boolean\n /**\n * Receives what the edit changed, also when it fails, before its step closes. An edit rolled\n * back after it threw changed nothing.\n */\n onRecorded?: (change: DocumentChange) => void\n}\n\nfunction unchanged(pageId: string): DocumentChange {\n return {\n pageId,\n pageIds: [],\n created: [],\n deleted: [],\n updated: [],\n children: { before: [], after: [] },\n variables: [],\n collections: []\n }\n}\n\n/**\n * The undo step of a recorded change. Built outside the edit's own scope, so the step keeps only\n * the change: not the edit's recording state, nor its options, whose `onRecorded` can hold the\n * step before it and so every step back to the first, past the history limit.\n */\nfunction changeStep(ctx: EditorContext, label: string, change: DocumentChange): UndoEntry {\n return {\n label,\n forward: () => restoreDocumentChange(ctx, change, 'after'),\n inverse: () => restoreDocumentChange(ctx, change, 'before')\n }\n}\n\n/** How many edits that await are running in each history. */\nconst runningEdits = new WeakMap<UndoManager, number>()\n\n/** The recorders of edits still open in each editor, which anyone else's edit waits outside. */\nconst openRecorders = new WeakMap<EditorContext, Set<DocumentChangeRecorder>>()\n\nfunction keepOpenRecorder(ctx: EditorContext, recorder: DocumentChangeRecorder): void {\n let recorders = openRecorders.get(ctx)\n if (!recorders) {\n recorders = new Set()\n openRecorders.set(ctx, recorders)\n }\n recorders.add(recorder)\n}\n\nfunction releaseOpenRecorder(ctx: EditorContext, recorder: DocumentChangeRecorder): void {\n const recorders = openRecorders.get(ctx)\n if (!recorders) return\n recorders.delete(recorder)\n if (recorders.size === 0) openRecorders.delete(ctx)\n}\n\n/**\n * Runs a separate edit, or an undo or redo, while the edits that are still open treat what it\n * changes as someone else's: their steps leave it alone. The edit is synchronous, so nothing it\n * runs interleaves with their awaits.\n */\nfunction withOpenEditsPaused<T>(ctx: EditorContext, run: () => T, own?: DocumentChangeRecorder): T {\n const recorders = [...(openRecorders.get(ctx) ?? [])].filter((recorder) => recorder !== own)\n for (const recorder of recorders) recorder.pause()\n try {\n return run()\n } finally {\n for (const recorder of recorders) recorder.resume()\n }\n}\n\n/**\n * Watches, while an edit awaits, for writes it does not own: a step recorded, undone, or redone,\n * another edit or a batch open, or text being edited. They land in the edit's change, so rolling\n * it back would revert them too. Returns the function that stops watching and tells.\n */\nfunction watchOtherWrites(ctx: EditorContext): () => boolean {\n const { undo } = ctx\n const running = runningEdits.get(undo) ?? 0\n let others = running > 0 || undo.isRecording || ctx.state.editingTextId !== null\n runningEdits.set(undo, running + 1)\n const stop = ctx.onEditorEvent('history:changed', () => {\n others = true\n })\n return () => {\n stop()\n const left = (runningEdits.get(undo) ?? 1) - 1\n runningEdits.set(undo, left)\n return others || left > 0 || undo.isBatching || ctx.state.editingTextId !== null\n }\n}\n\n/**\n * Puts the document back as it was before a failed edit, keeping the selection the edit left\n * alone; false when that failed too, and the edit's step is then recorded instead, so what it did\n * stays undoable.\n */\nfunction rollBack(ctx: EditorContext, graph: SceneGraph, change: DocumentChange): boolean {\n try {\n if (ctx.graph !== graph) {\n // The document the edit ran in is no longer shown, so only its graph goes back.\n applyDocumentChange(graph, change, 'before')\n return true\n }\n restoreDocumentChange(ctx, change, 'before', { keepSelection: true })\n } catch {\n return false\n }\n // The document is back where its history left it, so what follows the history, such as its\n // unsaved state, settles as after an undo.\n ctx.emitEditorEvent('history:changed')\n return true\n}\n\nfunction begin(ctx: EditorContext, options: RecordEditOptions, awaits = false) {\n const graph = ctx.graph\n const pageId = options.pageId ?? ctx.state.currentPageId\n const recorder = recordDocumentChange(graph, pageId)\n if (awaits) keepOpenRecorder(ctx, recorder)\n // A synchronous edit runs alone; one that awaits shares the document while it waits.\n const othersWrote = awaits ? watchOtherWrites(ctx) : () => false\n const finish = (failed: boolean) => {\n if (awaits) releaseOpenRecorder(ctx, recorder)\n const others = othersWrote()\n const change = recorder.finish()\n const empty = isEmptyDocumentChange(change)\n if (\n failed &&\n options.rollbackOnThrow &&\n !empty &&\n !others &&\n options.canRollBack?.() !== false &&\n rollBack(ctx, graph, change)\n ) {\n options.onRecorded?.(unchanged(pageId))\n return\n }\n // An edit that changed nothing, such as a read-only script, leaves no empty step behind.\n if (options.push !== false && !empty) {\n const entry = changeStep(ctx, options.label, change)\n if (options.ownStep) ctx.undo.pushStep(entry)\n else ctx.undo.push(entry)\n }\n options.onRecorded?.(change)\n }\n return { finish, recorder }\n}\n\n/**\n * Runs a synchronous edit as one undo step of everything it changed in the document, also when\n * it throws part way, so what it did stays undoable, unless `rollbackOnThrow` puts it back. Its\n * step is recorded in the same task as its changes, as the document's unsaved state expects of an\n * edit, and joins a batch open around it.\n */\nexport function recordEdit<T>(ctx: EditorContext, options: RecordEditOptions, run: () => T): T {\n const { finish, recorder } = begin(ctx, options)\n let failed = true\n try {\n // An edit that awaits meanwhile keeps what this one changes out of its step.\n const result = withOpenEditsPaused(ctx, run, recorder)\n failed = false\n return result\n } finally {\n finish(failed)\n }\n}\n\n/**\n * Runs an edit that awaits before it finishes, such as an agent's tool call that loads fonts or\n * runs a layout, as one undo step. The edit stays open until its step is recorded, so the changes\n * it makes meanwhile count as its own rather than as edits outside the history. An edit made\n * elsewhere while it runs, such as the user's, lands in the same step: nothing tells whose write\n * is whose across an await. So `rollbackOnThrow` rolls back only an edit nothing else wrote\n * beside, as far as the history and `canRollBack` can tell, and otherwise records its step. An\n * edit that can compute first and apply in one go records only the apply with `recordEdit`\n * instead.\n */\nexport async function recordEditAsync<T>(\n ctx: EditorContext,\n options: RecordEditOptions,\n run: () => Promise<T>\n): Promise<T> {\n // Capturing can throw; the edit opens only once it has, so a failure never leaves it open.\n const { finish } = begin(ctx, { ...options, ownStep: true }, true)\n const close = ctx.undo.openEdit()\n let failed = true\n try {\n const result = await run()\n failed = false\n return result\n } finally {\n try {\n finish(failed)\n } finally {\n close()\n }\n }\n}\n"],"mappings":";;AA8CA,SAAS,UAAU,QAAgC;CACjD,OAAO;EACL;EACA,SAAS,CAAC;EACV,SAAS,CAAC;EACV,SAAS,CAAC;EACV,SAAS,CAAC;EACV,UAAU;GAAE,QAAQ,CAAC;GAAG,OAAO,CAAC;EAAE;EAClC,WAAW,CAAC;EACZ,aAAa,CAAC;CAChB;AACF;;;;;;AAOA,SAAS,WAAW,KAAoB,OAAe,QAAmC;CACxF,OAAO;EACL;EACA,eAAe,sBAAsB,KAAK,QAAQ,OAAO;EACzD,eAAe,sBAAsB,KAAK,QAAQ,QAAQ;CAC5D;AACF;;AAGA,MAAM,+BAA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YA,eAAsB,gBACpB,KACA,SACA,KACY;CAEZ,MAAM,EAAE,WAAW,MAAM,KAAK;EAAE,GAAG;EAAS,SAAS;CAAK,GAAG,IAAI;CACjE,MAAM,QAAQ,IAAI,KAAK,SAAS;CAChC,IAAI,SAAS;CACb,IAAI;EACF,MAAM,SAAS,MAAM,IAAI;EACzB,SAAS;EACT,OAAO;CACT,UAAU;EACR,IAAI;GACF,OAAO,MAAM;EACf,UAAU;GACR,MAAM;EACR;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"edit.js","names":[],"sources":["../../../src/editor/history/edit.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\nimport type { UndoEntry, UndoManager } from '@pairdraw/scene-graph/undo'\n\nimport {\n applyDocumentChange,\n isEmptyDocumentChange,\n recordDocumentChange,\n restoreDocumentChange,\n type DocumentChange,\n type DocumentChangeRecorder\n} from '#core/editor/history/document-change'\nimport type { EditorContext } from '#core/editor/types'\n\nexport interface RecordEditOptions {\n /** The undo step's label. */\n label: string\n /** The page the edit is made from; it is recorded wherever in the document it lands. */\n pageId?: string\n /** False for an edit that records its own steps, such as an atomic tool's. */\n push?: boolean\n /**\n * Records the step on its own, settling any batch first, rather than as part of an open batch.\n * An edit that finishes after an await needs this: a batch open by then belongs to another\n * edit, such as a picker drag. `recordEditAsync` always does.\n */\n ownStep?: boolean\n /**\n * Puts back everything the edit changed when it throws, so a failed agent call or script leaves\n * the document as it found it and records no step. Undoing it costs what the edit touched, not\n * a copy of the document. Without it, or when something else wrote to the document while the\n * edit ran, what the edit did before it threw stays as one step.\n */\n rollbackOnThrow?: boolean\n /**\n * Whether nothing outside the editor's history wrote to the document since the edit began, such\n * as a collaborator. Asked once the edit has thrown; false records the edit's step instead of a\n * rollback that would revert those writes too. Writes the history sees are checked anyway.\n */\n canRollBack?: () => boolean\n /**\n * Receives what the edit changed, also when it fails, before its step closes. An edit rolled\n * back after it threw changed nothing.\n */\n onRecorded?: (change: DocumentChange) => void\n}\n\nfunction unchanged(pageId: string): DocumentChange {\n return {\n pageId,\n pageIds: [],\n created: [],\n deleted: [],\n updated: [],\n children: { before: [], after: [] },\n variables: [],\n collections: []\n }\n}\n\n/**\n * The undo step of a recorded change. Built outside the edit's own scope, so the step keeps only\n * the change: not the edit's recording state, nor its options, whose `onRecorded` can hold the\n * step before it and so every step back to the first, past the history limit.\n */\nfunction changeStep(ctx: EditorContext, label: string, change: DocumentChange): UndoEntry {\n return {\n label,\n forward: () => restoreDocumentChange(ctx, change, 'after'),\n inverse: () => restoreDocumentChange(ctx, change, 'before')\n }\n}\n\n/** How many edits that await are running in each history. */\nconst runningEdits = new WeakMap<UndoManager, number>()\n\n/** The recorders of edits still open in each editor, which anyone else's edit waits outside. */\nconst openRecorders = new WeakMap<EditorContext, Set<DocumentChangeRecorder>>()\n\nfunction keepOpenRecorder(ctx: EditorContext, recorder: DocumentChangeRecorder): void {\n let recorders = openRecorders.get(ctx)\n if (!recorders) {\n recorders = new Set()\n openRecorders.set(ctx, recorders)\n }\n recorders.add(recorder)\n}\n\nfunction releaseOpenRecorder(ctx: EditorContext, recorder: DocumentChangeRecorder): void {\n const recorders = openRecorders.get(ctx)\n if (!recorders) return\n recorders.delete(recorder)\n if (recorders.size === 0) openRecorders.delete(ctx)\n}\n\n/**\n * Runs a separate edit, or an undo or redo, while the edits that are still open treat what it\n * changes as someone else's: their steps leave it alone. The edit is synchronous, so nothing it\n * runs interleaves with their awaits.\n */\nfunction withOpenEditsPaused<T>(ctx: EditorContext, run: () => T, own?: DocumentChangeRecorder): T {\n const recorders = [...(openRecorders.get(ctx) ?? [])].filter((recorder) => recorder !== own)\n for (const recorder of recorders) recorder.pause()\n try {\n return run()\n } finally {\n for (const recorder of recorders) recorder.resume()\n }\n}\n\n/**\n * Watches, while an edit awaits, for writes it does not own: a step recorded, undone, or redone,\n * another edit or a batch open, or text being edited. They land in the edit's change, so rolling\n * it back would revert them too. Returns the function that stops watching and tells.\n */\nfunction watchOtherWrites(ctx: EditorContext): () => boolean {\n const { undo } = ctx\n const running = runningEdits.get(undo) ?? 0\n let others = running > 0 || undo.isRecording || ctx.state.editingTextId !== null\n runningEdits.set(undo, running + 1)\n const stop = ctx.onEditorEvent('history:changed', () => {\n others = true\n })\n return () => {\n stop()\n const left = (runningEdits.get(undo) ?? 1) - 1\n runningEdits.set(undo, left)\n return others || left > 0 || undo.isBatching || ctx.state.editingTextId !== null\n }\n}\n\n/**\n * Puts the document back as it was before a failed edit, keeping the selection the edit left\n * alone; false when that failed too, and the edit's step is then recorded instead, so what it did\n * stays undoable.\n */\nfunction rollBack(ctx: EditorContext, graph: SceneGraph, change: DocumentChange): boolean {\n try {\n if (ctx.graph !== graph) {\n // The document the edit ran in is no longer shown, so only its graph goes back.\n applyDocumentChange(graph, change, 'before')\n return true\n }\n restoreDocumentChange(ctx, change, 'before', { keepSelection: true })\n } catch {\n return false\n }\n // The document is back where its history left it, so what follows the history, such as its\n // unsaved state, settles as after an undo.\n ctx.emitEditorEvent('history:changed')\n return true\n}\n\nfunction begin(ctx: EditorContext, options: RecordEditOptions, awaits = false) {\n const graph = ctx.graph\n const pageId = options.pageId ?? ctx.state.currentPageId\n const recorder = recordDocumentChange(graph, pageId)\n if (awaits) keepOpenRecorder(ctx, recorder)\n // A synchronous edit runs alone; one that awaits shares the document while it waits.\n const othersWrote = awaits ? watchOtherWrites(ctx) : () => false\n const finish = (failed: boolean) => {\n if (awaits) releaseOpenRecorder(ctx, recorder)\n const others = othersWrote()\n const change = recorder.finish()\n const empty = isEmptyDocumentChange(change)\n if (\n failed &&\n options.rollbackOnThrow &&\n !empty &&\n !others &&\n options.canRollBack?.() !== false &&\n rollBack(ctx, graph, change)\n ) {\n options.onRecorded?.(unchanged(pageId))\n return\n }\n // An edit that changed nothing, such as a read-only script, leaves no empty step behind.\n if (options.push !== false && !empty) {\n const entry = changeStep(ctx, options.label, change)\n if (ctx.graph !== graph) {\n // The document the edit began on was swapped away while it awaited: its step stays with\n // that document, and the one now open never carries an edit it did not see.\n ctx.parkStep(graph, entry)\n } else if (options.ownStep) ctx.undo.pushStep(entry)\n else ctx.undo.push(entry)\n }\n options.onRecorded?.(change)\n }\n return { finish, recorder }\n}\n\n/**\n * Runs a synchronous edit as one undo step of everything it changed in the document, also when\n * it throws part way, so what it did stays undoable, unless `rollbackOnThrow` puts it back. Its\n * step is recorded in the same task as its changes, as the document's unsaved state expects of an\n * edit, and joins a batch open around it.\n */\nexport function recordEdit<T>(ctx: EditorContext, options: RecordEditOptions, run: () => T): T {\n const { finish, recorder } = begin(ctx, options)\n let failed = true\n try {\n // An edit that awaits meanwhile keeps what this one changes out of its step.\n const result = withOpenEditsPaused(ctx, run, recorder)\n failed = false\n return result\n } finally {\n finish(failed)\n }\n}\n\n/**\n * Runs an edit that awaits before it finishes, such as an agent's tool call that loads fonts or\n * runs a layout, as one undo step. The edit stays open until its step is recorded, so the changes\n * it makes meanwhile count as its own rather than as edits outside the history. An edit made\n * elsewhere while it runs, such as the user's, lands in the same step: nothing tells whose write\n * is whose across an await. So `rollbackOnThrow` rolls back only an edit nothing else wrote\n * beside, as far as the history and `canRollBack` can tell, and otherwise records its step. An\n * edit that can compute first and apply in one go records only the apply with `recordEdit`\n * instead.\n */\nexport async function recordEditAsync<T>(\n ctx: EditorContext,\n options: RecordEditOptions,\n run: () => Promise<T>\n): Promise<T> {\n // Capturing can throw; the edit opens only once it has, so a failure never leaves it open.\n const { finish } = begin(ctx, { ...options, ownStep: true }, true)\n const close = ctx.undo.openEdit()\n let failed = true\n try {\n const result = await run()\n failed = false\n return result\n } finally {\n try {\n finish(failed)\n } finally {\n close()\n }\n }\n}\n"],"mappings":";;AA8CA,SAAS,UAAU,QAAgC;CACjD,OAAO;EACL;EACA,SAAS,CAAC;EACV,SAAS,CAAC;EACV,SAAS,CAAC;EACV,SAAS,CAAC;EACV,UAAU;GAAE,QAAQ,CAAC;GAAG,OAAO,CAAC;EAAE;EAClC,WAAW,CAAC;EACZ,aAAa,CAAC;CAChB;AAC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,WAAc,KAAoB,SAA4B,KAAiB;CAC7F,MAAM,EAAE,QAAQ,aAAa,MAAM,KAAK,OAAO;CAC/C,IAAI,SAAS;CACb,IAAI;EAEF,MAAM,SAAS,oBAAoB,KAAK,KAAK,QAAQ;EACrD,SAAS;EACT,OAAO;CACT,UAAU;EACR,OAAO,MAAM;CACf;AACF;;;;;;;;;;;AAYA,eAAsB,gBACpB,KACA,SACA,KACY;CAEZ,MAAM,EAAE,WAAW,MAAM,KAAK;EAAE,GAAG;EAAS,SAAS;CAAK,GAAG,IAAI;CACjE,MAAM,QAAQ,IAAI,KAAK,SAAS;CAChC,IAAI,SAAS;CACb,IAAI;EACF,MAAM,SAAS,MAAM,IAAI;EACzB,SAAS;EACT,OAAO;CACT,UAAU;EACR,IAAI;GACF,OAAO,MAAM;EACf,UAAU;GACR,MAAM;EACR;CACF;AACF"}
|
package/dist/editor/nudge.js
CHANGED
|
@@ -42,7 +42,7 @@ function createNudgeActions(ctx) {
|
|
|
42
42
|
let closeNudgeEdit = null;
|
|
43
43
|
function applyOrder(parentId, order) {
|
|
44
44
|
order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index));
|
|
45
|
-
ctx.
|
|
45
|
+
ctx.runLayoutForParents([parentId]);
|
|
46
46
|
}
|
|
47
47
|
function commitReorder() {
|
|
48
48
|
if (!reorderOriginals) return;
|
package/dist/editor/nudge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nudge.js","names":[],"sources":["../../src/editor/nudge.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { collectNodePositions, pushPositionUndo } from './history/position'\nimport { fitEnclosingGroupsWithUndo } from './structure/group/bounds'\nimport type { EditorContext } from './types'\n\nconst NUDGE_COMMIT_DELAY = 300\n\n/** The flow an arrow key moves a layer along: its row or column, or none. */\nfunction flowParent(ctx: EditorContext, node: SceneNode): SceneNode | null {\n if (node.layoutPositioning === 'ABSOLUTE' || !node.parentId) return null\n const parent = ctx.graph.getNode(node.parentId)\n return parent?.layoutMode === 'HORIZONTAL' || parent?.layoutMode === 'VERTICAL' ? parent : null\n}\n\n/**\n * One slot along the flow for an arrow key, as Figma reorders auto layout children: Right and\n * Left in a row (mirrored when it runs right to left), Down and Up in a column, and nothing for\n * the arrows across it. Shift moves one slot too.\n */\nfunction flowStep(parent: SceneNode, dx: number, dy: number): -1 | 0 | 1 {\n const along = parent.layoutMode === 'HORIZONTAL' ? dx : dy\n const visual =\n parent.layoutMode === 'HORIZONTAL' && parent.layoutDirection === 'RTL' ? -along : along\n if (visual === 0) return 0\n return visual > 0 ? 1 : -1\n}\n\n/**\n * The flow with each selected layer moved one slot by `step`; one already at the end of the\n * flow, or behind another selected layer that is, stays put.\n */\nfunction steppedFlow(\n flow: readonly string[],\n selected: ReadonlySet<string>,\n step: 1 | -1\n): string[] {\n const order = [...flow]\n const indices = step > 0 ? order.map((_, i) => order.length - 1 - i) : order.map((_, i) => i)\n for (const i of indices) {\n const j = i + step\n if (!selected.has(order[i]) || j < 0 || j >= order.length || selected.has(order[j])) continue\n ;[order[i], order[j]] = [order[j], order[i]]\n }\n return order\n}\n\nexport function createNudgeActions(ctx: EditorContext) {\n let nudgeOriginals: Map<string, Vector> | null = null\n let reorderOriginals: Map<string, string[]> | null = null\n let nudgeCommitTimer: ReturnType<typeof setTimeout> | null = null\n /** Open from the first key press until the nudge records its step, which waits for a pause. */\n let closeNudgeEdit: (() => void) | null = null\n\n function applyOrder(parentId: string, order: readonly string[]) {\n order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index))\n ctx.runLayoutForNode(parentId)\n }\n\n function commitReorder() {\n if (!reorderOriginals) return\n const originals = reorderOriginals\n reorderOriginals = null\n const finals = new Map(\n [...originals.keys()].map((id) => [id, [...(ctx.graph.getNode(id)?.childIds ?? [])]])\n )\n if ([...originals].every(([id, order]) => isEqual(order, finals.get(id)))) return\n ctx.undo.push({\n label: 'Reorder',\n forward: () => {\n for (const [id, order] of finals) applyOrder(id, order)\n },\n inverse: () => {\n for (const [id, order] of originals) applyOrder(id, order)\n }\n })\n }\n\n function commitNudge() {\n nudgeCommitTimer = null\n try {\n commitReorder()\n commitMove()\n } finally {\n closeNudgeEdit?.()\n closeNudgeEdit = null\n }\n }\n\n function commitMove() {\n if (!nudgeOriginals) return\n const originals = nudgeOriginals\n nudgeOriginals = null\n\n const finals = collectNodePositions(ctx, originals.keys())\n const parentIds = [...originals.keys()].flatMap((id) => ctx.graph.getNode(id)?.parentId ?? [])\n // Groups and booleans fit their nudged children, in the same undo step.\n ctx.undo.runBatch('Nudge', () => {\n pushPositionUndo(ctx, 'Nudge', originals, finals)\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n ctx.requestRender()\n }\n\n /** Moves the selected layers in auto layout flows one slot; returns the layers it handled. */\n function reorderInFlows(movable: readonly string[], dx: number, dy: number): Set<string> {\n const byParent = new Map<string, Set<string>>()\n for (const id of movable) {\n const node = ctx.graph.getNode(id)\n const parent = node && flowParent(ctx, node)\n if (!parent) continue\n const selected = byParent.get(parent.id) ?? new Set<string>()\n selected.add(id)\n byParent.set(parent.id, selected)\n }\n const handled = new Set<string>()\n for (const [parentId, selected] of byParent) {\n for (const id of selected) handled.add(id)\n const parent = ctx.graph.getNode(parentId)\n const step = parent ? flowStep(parent, dx, dy) : 0\n if (!parent || step === 0) continue\n const children = ctx.graph.getChildren(parentId)\n const flowIds = children\n .filter((child) => child.layoutPositioning !== 'ABSOLUTE')\n .map((c) => c.id)\n const moved = steppedFlow(flowIds, selected, step)\n if (isEqual(moved, flowIds)) continue\n reorderOriginals ??= new Map()\n if (!reorderOriginals.has(parentId)) reorderOriginals.set(parentId, [...parent.childIds])\n // Layers that ignore the layout keep their places in the stack.\n let next = 0\n const order = children.map((child) =>\n child.layoutPositioning === 'ABSOLUTE' ? child.id : moved[next++]\n )\n applyOrder(parentId, order)\n }\n return handled\n }\n\n function nudgeSelected(dx: number, dy: number) {\n const ids = [...ctx.state.selectedIds]\n if (ids.length === 0) return\n\n const movable: string[] = []\n for (const id of ids) {\n const node = ctx.graph.getNode(id)\n if (node && !node.locked) movable.push(id)\n }\n if (movable.length === 0) return\n\n // The step waits for the keys to pause: hold the edit open until then, so the unsaved-changes\n // tracker takes the moves for that step's own.\n closeNudgeEdit ??= ctx.undo.openEdit()\n\n const reordered = reorderInFlows(movable, dx, dy)\n const nudged = movable.filter((id) => !reordered.has(id))\n\n // A run can span selection changes; each layer's start is recorded the first time it moves.\n if (nudged.length > 0) {\n nudgeOriginals ??= new Map()\n for (const id of nudged) {\n if (nudgeOriginals.has(id)) continue\n const node = ctx.graph.getNode(id)\n if (node) nudgeOriginals.set(id, { x: node.x, y: node.y })\n }\n }\n\n for (const id of nudged) {\n const node = ctx.graph.getNode(id)\n if (!node) continue\n ctx.graph.updateNode(id, { x: node.x + dx, y: node.y + dy })\n }\n\n if (nudgeCommitTimer) clearTimeout(nudgeCommitTimer)\n nudgeCommitTimer = setTimeout(commitNudge, NUDGE_COMMIT_DELAY)\n\n ctx.requestRender()\n }\n\n function flushNudge() {\n if (nudgeCommitTimer) {\n clearTimeout(nudgeCommitTimer)\n commitNudge()\n }\n }\n\n return { nudgeSelected, flushNudge }\n}\n"],"mappings":";;;;AASA,MAAM,qBAAqB;;AAG3B,SAAS,WAAW,KAAoB,MAAmC;CACzE,IAAI,KAAK,sBAAsB,cAAc,CAAC,KAAK,UAAU,OAAO;CACpE,MAAM,SAAS,IAAI,MAAM,QAAQ,KAAK,QAAQ;CAC9C,OAAO,QAAQ,eAAe,gBAAgB,QAAQ,eAAe,aAAa,SAAS;AAC7F;;;;;;AAOA,SAAS,SAAS,QAAmB,IAAY,IAAwB;CACvE,MAAM,QAAQ,OAAO,eAAe,eAAe,KAAK;CACxD,MAAM,SACJ,OAAO,eAAe,gBAAgB,OAAO,oBAAoB,QAAQ,CAAC,QAAQ;CACpF,IAAI,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Q,EAAE;GACjC,IAAI,CAAC,MAAM;GACX,IAAI,MAAM,WAAW,IAAI;IAAE,GAAG,KAAK,IAAI;IAAI,GAAG,KAAK,IAAI;GAAG,CAAC;EAC7D;EAEA,IAAI,kBAAkB,aAAa,gBAAgB;EACnD,mBAAmB,WAAW,aAAa,kBAAkB;EAE7D,IAAI,cAAc;CACpB;CAEA,SAAS,aAAa;EACpB,IAAI,kBAAkB;GACpB,aAAa,gBAAgB;GAC7B,YAAY;EACd;CACF;CAEA,OAAO;EAAE;EAAe;CAAW;AACrC"}
|
|
1
|
+
{"version":3,"file":"nudge.js","names":[],"sources":["../../src/editor/nudge.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { collectNodePositions, pushPositionUndo } from './history/position'\nimport { fitEnclosingGroupsWithUndo } from './structure/group/bounds'\nimport type { EditorContext } from './types'\n\nconst NUDGE_COMMIT_DELAY = 300\n\n/** The flow an arrow key moves a layer along: its row or column, or none. */\nfunction flowParent(ctx: EditorContext, node: SceneNode): SceneNode | null {\n if (node.layoutPositioning === 'ABSOLUTE' || !node.parentId) return null\n const parent = ctx.graph.getNode(node.parentId)\n return parent?.layoutMode === 'HORIZONTAL' || parent?.layoutMode === 'VERTICAL' ? parent : null\n}\n\n/**\n * One slot along the flow for an arrow key, as Figma reorders auto layout children: Right and\n * Left in a row (mirrored when it runs right to left), Down and Up in a column, and nothing for\n * the arrows across it. Shift moves one slot too.\n */\nfunction flowStep(parent: SceneNode, dx: number, dy: number): -1 | 0 | 1 {\n const along = parent.layoutMode === 'HORIZONTAL' ? dx : dy\n const visual =\n parent.layoutMode === 'HORIZONTAL' && parent.layoutDirection === 'RTL' ? -along : along\n if (visual === 0) return 0\n return visual > 0 ? 1 : -1\n}\n\n/**\n * The flow with each selected layer moved one slot by `step`; one already at the end of the\n * flow, or behind another selected layer that is, stays put.\n */\nfunction steppedFlow(\n flow: readonly string[],\n selected: ReadonlySet<string>,\n step: 1 | -1\n): string[] {\n const order = [...flow]\n const indices = step > 0 ? order.map((_, i) => order.length - 1 - i) : order.map((_, i) => i)\n for (const i of indices) {\n const j = i + step\n if (!selected.has(order[i]) || j < 0 || j >= order.length || selected.has(order[j])) continue\n ;[order[i], order[j]] = [order[j], order[i]]\n }\n return order\n}\n\nexport function createNudgeActions(ctx: EditorContext) {\n let nudgeOriginals: Map<string, Vector> | null = null\n let reorderOriginals: Map<string, string[]> | null = null\n let nudgeCommitTimer: ReturnType<typeof setTimeout> | null = null\n /** Open from the first key press until the nudge records its step, which waits for a pause. */\n let closeNudgeEdit: (() => void) | null = null\n\n function applyOrder(parentId: string, order: readonly string[]) {\n order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index))\n ctx.runLayoutForParents([parentId])\n }\n\n function commitReorder() {\n if (!reorderOriginals) return\n const originals = reorderOriginals\n reorderOriginals = null\n const finals = new Map(\n [...originals.keys()].map((id) => [id, [...(ctx.graph.getNode(id)?.childIds ?? [])]])\n )\n if ([...originals].every(([id, order]) => isEqual(order, finals.get(id)))) return\n ctx.undo.push({\n label: 'Reorder',\n forward: () => {\n for (const [id, order] of finals) applyOrder(id, order)\n },\n inverse: () => {\n for (const [id, order] of originals) applyOrder(id, order)\n }\n })\n }\n\n function commitNudge() {\n nudgeCommitTimer = null\n try {\n commitReorder()\n commitMove()\n } finally {\n closeNudgeEdit?.()\n closeNudgeEdit = null\n }\n }\n\n function commitMove() {\n if (!nudgeOriginals) return\n const originals = nudgeOriginals\n nudgeOriginals = null\n\n const finals = collectNodePositions(ctx, originals.keys())\n const parentIds = [...originals.keys()].flatMap((id) => ctx.graph.getNode(id)?.parentId ?? [])\n // Groups and booleans fit their nudged children, in the same undo step.\n ctx.undo.runBatch('Nudge', () => {\n pushPositionUndo(ctx, 'Nudge', originals, finals)\n fitEnclosingGroupsWithUndo(ctx, parentIds)\n })\n ctx.requestRender()\n }\n\n /** Moves the selected layers in auto layout flows one slot; returns the layers it handled. */\n function reorderInFlows(movable: readonly string[], dx: number, dy: number): Set<string> {\n const byParent = new Map<string, Set<string>>()\n for (const id of movable) {\n const node = ctx.graph.getNode(id)\n const parent = node && flowParent(ctx, node)\n if (!parent) continue\n const selected = byParent.get(parent.id) ?? new Set<string>()\n selected.add(id)\n byParent.set(parent.id, selected)\n }\n const handled = new Set<string>()\n for (const [parentId, selected] of byParent) {\n for (const id of selected) handled.add(id)\n const parent = ctx.graph.getNode(parentId)\n const step = parent ? flowStep(parent, dx, dy) : 0\n if (!parent || step === 0) continue\n const children = ctx.graph.getChildren(parentId)\n const flowIds = children\n .filter((child) => child.layoutPositioning !== 'ABSOLUTE')\n .map((c) => c.id)\n const moved = steppedFlow(flowIds, selected, step)\n if (isEqual(moved, flowIds)) continue\n reorderOriginals ??= new Map()\n if (!reorderOriginals.has(parentId)) reorderOriginals.set(parentId, [...parent.childIds])\n // Layers that ignore the layout keep their places in the stack.\n let next = 0\n const order = children.map((child) =>\n child.layoutPositioning === 'ABSOLUTE' ? child.id : moved[next++]\n )\n applyOrder(parentId, order)\n }\n return handled\n }\n\n function nudgeSelected(dx: number, dy: number) {\n const ids = [...ctx.state.selectedIds]\n if (ids.length === 0) return\n\n const movable: string[] = []\n for (const id of ids) {\n const node = ctx.graph.getNode(id)\n if (node && !node.locked) movable.push(id)\n }\n if (movable.length === 0) return\n\n // The step waits for the keys to pause: hold the edit open until then, so the unsaved-changes\n // tracker takes the moves for that step's own.\n closeNudgeEdit ??= ctx.undo.openEdit()\n\n const reordered = reorderInFlows(movable, dx, dy)\n const nudged = movable.filter((id) => !reordered.has(id))\n\n // A run can span selection changes; each layer's start is recorded the first time it moves.\n if (nudged.length > 0) {\n nudgeOriginals ??= new Map()\n for (const id of nudged) {\n if (nudgeOriginals.has(id)) continue\n const node = ctx.graph.getNode(id)\n if (node) nudgeOriginals.set(id, { x: node.x, y: node.y })\n }\n }\n\n for (const id of nudged) {\n const node = ctx.graph.getNode(id)\n if (!node) continue\n ctx.graph.updateNode(id, { x: node.x + dx, y: node.y + dy })\n }\n\n if (nudgeCommitTimer) clearTimeout(nudgeCommitTimer)\n nudgeCommitTimer = setTimeout(commitNudge, NUDGE_COMMIT_DELAY)\n\n ctx.requestRender()\n }\n\n function flushNudge() {\n if (nudgeCommitTimer) {\n clearTimeout(nudgeCommitTimer)\n commitNudge()\n }\n }\n\n return { nudgeSelected, flushNudge }\n}\n"],"mappings":";;;;AASA,MAAM,qBAAqB;;AAG3B,SAAS,WAAW,KAAoB,MAAmC;CACzE,IAAI,KAAK,sBAAsB,cAAc,CAAC,KAAK,UAAU,OAAO;CACpE,MAAM,SAAS,IAAI,MAAM,QAAQ,KAAK,QAAQ;CAC9C,OAAO,QAAQ,eAAe,gBAAgB,QAAQ,eAAe,aAAa,SAAS;AAC7F;;;;;;AAOA,SAAS,SAAS,QAAmB,IAAY,IAAwB;CACvE,MAAM,QAAQ,OAAO,eAAe,eAAe,KAAK;CACxD,MAAM,SACJ,OAAO,eAAe,gBAAgB,OAAO,oBAAoB,QAAQ,CAAC,QAAQ;CACpF,IAAI,WAAW,GAAG,OAAO;CACzB,OAAO,SAAS,IAAI,IAAI;AAC1B;;;;;AAMA,SAAS,YACP,MACA,UACA,MACU;CACV,MAAM,QAAQ,CAAC,GAAG,IAAI;CACtB,MAAM,UAAU,OAAO,IAAI,MAAM,KAAK,GAAG,MAAM,MAAM,SAAS,IAAI,CAAC,IAAI,MAAM,KAAK,GAAG,MAAM,CAAC;CAC5F,KAAK,MAAM,KAAK,SAAS;EACvB,MAAM,IAAI,IAAI;EACd,IAAI,CAAC,SAAS,IAAI,MAAM,EAAE,KAAK,IAAI,KAAK,KAAK,MAAM,UAAU,SAAS,IAAI,MAAM,EAAE,GAAG;EACpF,CAAC,MAAM,IAAI,MAAM,MAAM,CAAC,MAAM,IAAI,MAAM,EAAE;CAC7C;CACA,OAAO;AACT;AAEA,SAAgB,mBAAmB,KAAoB;CACrD,IAAI,iBAA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;EACrC,IAAI,IAAI,WAAW,GAAG;EAEtB,MAAM,UAAoB,CAAC;EAC3B,KAAK,MAAM,MAAM,KAAK;GACpB,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;GACjC,IAAI,QAAQ,CAAC,KAAK,QAAQ,QAAQ,KAAK,EAAE;EAC3C;EACA,IAAI,QAAQ,WAAW,GAAG;EAI1B,mBAAmB,IAAI,KAAK,SAAS;EAErC,MAAM,YAAY,eAAe,SAAS,IAAI,EAAE;EAChD,MAAM,SAAS,QAAQ,QAAQ,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;EAGxD,IAAI,OAAO,SAAS,GAAG;GACrB,mCAAmB,IAAI,IAAI;GAC3B,KAAK,MAAM,MAAM,QAAQ;IACvB,IAAI,eAAe,IAAI,EAAE,GAAG;IAC5B,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;IACjC,IAAI,MAAM,eAAe,IAAI,IAAI;KAAE,GAAG,KAAK;KAAG,GAAG,KAAK;IAAE,CAAC;GAC3D;EACF;EAEA,KAAK,MAAM,MAAM,QAAQ;GACvB,MAAM,OAAO,IAAI,MAAM,QAAQ,EAAE;GACjC,IAAI,CAAC,MAAM;GACX,IAAI,MAAM,WAAW,IAAI;IAAE,GAAG,KAAK,IAAI;IAAI,GAAG,KAAK,IAAI;GAAG,CAAC;EAC7D;EAEA,IAAI,kBAAkB,aAAa,gBAAgB;EACnD,mBAAmB,WAAW,aAAa,kBAAkB;EAE7D,IAAI,cAAc;CACpB;CAEA,SAAS,aAAa;EACpB,IAAI,kBAAkB;GACpB,aAAa,gBAAgB;GAC7B,YAAY;EACd;CACF;CAEA,OAAO;EAAE;EAAe;CAAW;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","names":[],"sources":["../../../src/editor/read-only/actions.ts"],"sourcesContent":["/**\n * Editor actions a read-only document still offers: reading it, selecting, moving around and\n * between pages, previewing, copying, and the canvas's own lifecycle, as Figma keeps while a\n * version is viewed. Every other action changes the document and is refused, so an action added\n * later is refused until it is listed here (`packages/core/tests/editor/read-only.test.ts`).\n */\nexport const READ_ONLY_ACTIONS: ReadonlySet<string> = new Set([\n // Reads\n 'isSyncingComponents',\n 'acceptingParent',\n 'acceptsChildren',\n 'canArrangeNodes',\n 'canAutoArrangeNodes',\n 'canConvertToFrame',\n 'canDistributeNodes',\n 'canEditImage',\n 'collectVariantOptions',\n 'componentInstanceCount',\n 'figCompression',\n 'findVariantByValues',\n // Applies component edits already made to their instances; it makes none of its own.\n 'flushComponentSync',\n 'getChildren',\n 'getCollection',\n 'getCollectionCount',\n 'getCollections',\n 'getComponentPropertyAuthoring',\n 'getComponentPropertyBindings',\n 'getComponentSetPropertyDefs',\n 'getComponentSetVariantConflicts',\n 'getDefaultVariantForComponentSet',\n 'getExposableInstances',\n 'getImage',\n 'getInstanceComponentPropertyDefinitions',\n 'getInstanceComponentPropertyValue',\n 'getLayerTree',\n 'getNode',\n 'getPages',\n 'getSelectedNode',\n 'getSelectedNodes',\n 'getShownStatus',\n 'getTextHyperlink',\n 'getTextSelectionStyle',\n 'getVariable',\n 'getVariableCount',\n 'getVariablesByType',\n 'getVariablesForCollection',\n 'getVariantOptionAvailability',\n 'getVariantOptions',\n 'hitTestAtPoint',\n 'hyperlinkAtPoint',\n 'isInteractiveEditing',\n 'isTopLevel',\n 'pageSwitchCount',\n 'previewRenameSelected',\n 'scaleSelectionBounds',\n // Recording only: what the edit runs is refused or allowed on its own.\n 'recordEdit',\n 'recordEditAsync',\n 'resolveColorVariable',\n 'resolveNumberVariable',\n 'replaceableInstanceLayers',\n 'screenToCanvas',\n 'selectionSpacing',\n 'snapshotPage',\n 'statusWorkflow',\n 'validateComponentSet',\n\n // Selection and hover\n 'clearSelection',\n 'enterContainer',\n 'exitContainer',\n 'select',\n 'selectAll',\n 'selectAtPoint',\n 'selectChildren',\n 'selectInverse',\n 'selectNextSibling',\n 'selectParent',\n 'selectPreviousSibling',\n 'setCodeFocusNode',\n 'setHoveredNode',\n 'setMarquee',\n 'setMeasurementMode',\n 'setTool',\n 'validateEnteredContainer',\n\n // Canvas overlays that show without changing anything\n 'endImageEdit',\n 'setAutoLayoutHover',\n 'setDesignIssueHighlight',\n 'setDropTarget',\n 'setGuidePreview',\n 'setGuideRedline',\n 'setHoveredGuide',\n 'setLayoutInsertIndicator',\n 'setRenamingLabel',\n 'setRotationPreview',\n 'setSelectedGuide',\n 'setShapeHandleHover',\n 'setSnapGuides',\n 'setTransforming',\n\n // Viewport and pages\n 'applyZoom',\n 'centerOn',\n 'clearPageViewports',\n 'commitPageSwitch',\n 'focusComponent',\n 'followHyperlink',\n 'goToMainComponent',\n 'pan',\n 'preparePage',\n 'preparePageNodes',\n 'loadPageNodes',\n 'pageHoldingNode',\n 'revealNodes',\n 'setZoomAroundPoint',\n 'switchPage',\n 'switchToNextPage',\n 'switchToPreviousPage',\n 'zoomTo100',\n 'zoomToArea',\n 'zoomToBounds',\n 'zoomToFit',\n 'zoomToLevel',\n 'zoomToNextFrame',\n 'zoomToPreviousFrame',\n 'zoomToSelection',\n\n // Preview\n 'leaveCanvasView',\n 'resetPlay',\n 'startPlay',\n 'stopPlay',\n 'togglePlay',\n\n // Presenting the page's slides\n 'fitPresentation',\n 'getPresentation',\n 'getSlides',\n 'presentNextSlide',\n 'presentPreviousSlide',\n 'presentSlide',\n 'scrollPresentation',\n 'setPresentationScale',\n 'startPresentation',\n 'stopPresentation',\n 'togglePresentation',\n\n // Shader Mode: looking at one shader; tuning it is an edit, refused like any other\n 'canStartShaderMode',\n 'getShaderMode',\n 'startShaderMode',\n 'stopShaderMode',\n 'toggleShaderMode',\n\n // Copying out\n 'copySelectionAsHTML',\n 'copySelectionAsJSX',\n 'copySelectionAsSVG',\n 'copySelectionAsText',\n 'prepareCopy',\n\n // Ending what was in progress\n 'cancelNodePreviews',\n 'flushNudge',\n 'penCancel',\n 'pencilCancel',\n\n // Canvas, layout, and document lifecycle\n 'beginInteractiveEdit',\n 'dispose',\n 'drawPageShaderFrames',\n 'hasShaderRasterizer',\n 'loadFontsForNodes',\n 'onEditorEvent',\n 'refreshDocumentSettings',\n 'refreshVariables',\n 'releaseGraphResources',\n 'removeCanvasRenderer',\n 'replaceGraph',\n 'requestRefresh',\n 'requestRender',\n 'requestRepaint',\n 'runLayoutForNode',\n 'setCanvasKit',\n 'setNavigationPhase',\n 'setReadOnly',\n 'setShaderRasterizer',\n 'settleShaderFrames',\n 'subscribeToGraph',\n 'textSelectionChanged'\n])\n"],"mappings":";;;;;;;AAMA,MAAa,oCAAyC,IAAI,IAAI;CAE5D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../../../src/editor/read-only/actions.ts"],"sourcesContent":["/**\n * Editor actions a read-only document still offers: reading it, selecting, moving around and\n * between pages, previewing, copying, and the canvas's own lifecycle, as Figma keeps while a\n * version is viewed. Every other action changes the document and is refused, so an action added\n * later is refused until it is listed here (`packages/core/tests/editor/read-only.test.ts`).\n */\nexport const READ_ONLY_ACTIONS: ReadonlySet<string> = new Set([\n // Reads\n 'isSyncingComponents',\n 'acceptingParent',\n 'acceptsChildren',\n 'canArrangeNodes',\n 'canAutoArrangeNodes',\n 'canConvertToFrame',\n 'canDistributeNodes',\n 'canEditImage',\n 'collectVariantOptions',\n 'componentInstanceCount',\n 'figCompression',\n 'findVariantByValues',\n // Applies component edits already made to their instances; it makes none of its own.\n 'flushComponentSync',\n 'getChildren',\n 'getCollection',\n 'getCollectionCount',\n 'getCollections',\n 'getComponentPropertyAuthoring',\n 'getComponentPropertyBindings',\n 'getComponentSetPropertyDefs',\n 'getComponentSetVariantConflicts',\n 'getDefaultVariantForComponentSet',\n 'getExposableInstances',\n 'getImage',\n 'getInstanceComponentPropertyDefinitions',\n 'getInstanceComponentPropertyValue',\n 'getLayerTree',\n 'getNode',\n 'getPages',\n 'getSelectedNode',\n 'getSelectedNodes',\n 'getShownStatus',\n 'getTextHyperlink',\n 'getTextSelectionStyle',\n 'getVariable',\n 'getVariableCount',\n 'getVariablesByType',\n 'getVariablesForCollection',\n 'getVariantOptionAvailability',\n 'getVariantOptions',\n 'hitTestAtPoint',\n 'hyperlinkAtPoint',\n 'isInteractiveEditing',\n 'isTopLevel',\n 'pageSwitchCount',\n 'previewRenameSelected',\n 'scaleSelectionBounds',\n // Recording only: what the edit runs is refused or allowed on its own.\n 'recordEdit',\n 'recordEditAsync',\n 'resolveColorVariable',\n 'resolveNumberVariable',\n 'replaceableInstanceLayers',\n 'screenToCanvas',\n 'selectionSpacing',\n 'snapshotPage',\n 'statusWorkflow',\n 'validateComponentSet',\n\n // Selection and hover\n 'clearSelection',\n 'enterContainer',\n 'enterContainerOf',\n 'exitContainer',\n 'exitContainers',\n 'select',\n 'selectAll',\n 'selectAtPoint',\n 'selectChildren',\n 'selectInverse',\n 'selectNextSibling',\n 'selectParent',\n 'selectPreviousSibling',\n 'setCodeFocusNode',\n 'setHoveredNode',\n 'setMarquee',\n 'setMeasurementMode',\n 'setTool',\n 'validateEnteredContainer',\n\n // Canvas overlays that show without changing anything\n 'endImageEdit',\n 'setAutoLayoutHover',\n 'setDesignIssueHighlight',\n 'setDropTarget',\n 'setGuidePreview',\n 'setGuideRedline',\n 'setHoveredGuide',\n 'setLayoutInsertIndicator',\n 'setRenamingLabel',\n 'setRotationPreview',\n 'setSelectedGuide',\n 'setShapeHandleHover',\n 'setSnapGuides',\n 'setTransforming',\n\n // Viewport and pages\n 'applyZoom',\n 'centerOn',\n 'clearPageViewports',\n 'commitPageSwitch',\n 'focusComponent',\n 'followHyperlink',\n 'goToMainComponent',\n 'pan',\n 'preparePage',\n 'preparePageNodes',\n 'loadPageNodes',\n 'pageHoldingNode',\n 'revealNodes',\n 'setZoomAroundPoint',\n 'switchPage',\n 'switchToNextPage',\n 'switchToPreviousPage',\n 'zoomTo100',\n 'zoomToArea',\n 'zoomToBounds',\n 'zoomToFit',\n 'zoomToLevel',\n 'zoomToNextFrame',\n 'zoomToPreviousFrame',\n 'zoomToSelection',\n\n // Preview\n 'leaveCanvasView',\n 'resetPlay',\n 'startPlay',\n 'stopPlay',\n 'togglePlay',\n\n // Presenting the page's slides\n 'fitPresentation',\n 'getPresentation',\n 'getSlides',\n 'presentNextSlide',\n 'presentPreviousSlide',\n 'presentSlide',\n 'scrollPresentation',\n 'setPresentationScale',\n 'startPresentation',\n 'stopPresentation',\n 'togglePresentation',\n\n // Shader Mode: looking at one shader; tuning it is an edit, refused like any other\n 'canStartShaderMode',\n 'getShaderMode',\n 'startShaderMode',\n 'stopShaderMode',\n 'toggleShaderMode',\n\n // Copying out\n 'copySelectionAsHTML',\n 'copySelectionAsJSX',\n 'copySelectionAsSVG',\n 'copySelectionAsText',\n 'prepareCopy',\n\n // Ending what was in progress\n 'cancelNodePreviews',\n 'flushNudge',\n 'penCancel',\n 'pencilCancel',\n\n // Canvas, layout, and document lifecycle\n 'beginInteractiveEdit',\n 'dispose',\n 'drawPageShaderFrames',\n 'hasShaderRasterizer',\n 'loadFontsForNodes',\n 'onEditorEvent',\n 'refreshDocumentSettings',\n 'refreshVariables',\n 'releaseGraphResources',\n 'removeCanvasRenderer',\n 'replaceGraph',\n 'requestRefresh',\n 'requestRender',\n 'requestRepaint',\n 'runLayoutForNode',\n 'setCanvasKit',\n 'setNavigationPhase',\n 'setReadOnly',\n 'setShaderRasterizer',\n 'settleShaderFrames',\n 'subscribeToGraph',\n 'textSelectionChanged'\n])\n"],"mappings":";;;;;;;AAMA,MAAa,oCAAyC,IAAI,IAAI;CAE5D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -3,7 +3,9 @@ import { EditorContext } from "../types.js";
|
|
|
3
3
|
declare function createSelectionContainerActions(ctx: EditorContext): {
|
|
4
4
|
validateEnteredContainer: () => void;
|
|
5
5
|
enterContainer: (id: string) => void;
|
|
6
|
+
enterContainerOf: (nodeId: string) => void;
|
|
6
7
|
exitContainer: () => void;
|
|
8
|
+
exitContainers: () => void;
|
|
7
9
|
};
|
|
8
10
|
//#endregion
|
|
9
11
|
export { createSelectionContainerActions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","names":[],"sources":["../../../src/editor/selection/container.ts"],"mappings":";;iBAEgB,gCAAgC,KAAK;;EAOvB,iBAAA"}
|
|
1
|
+
{"version":3,"file":"container.d.ts","names":[],"sources":["../../../src/editor/selection/container.ts"],"mappings":";;iBAEgB,gCAAgC,KAAK;;EAOvB,iBAAA;EASM,mBAAA"}
|
|
@@ -6,6 +6,16 @@ function createSelectionContainerActions(ctx) {
|
|
|
6
6
|
function enterContainer(id) {
|
|
7
7
|
ctx.state.enteredContainerId = id;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Enters the container a click reached the layer through, as a double-click would have: its
|
|
11
|
+
* direct parent, unless that is the page or a container a click looks into by itself (a top-level
|
|
12
|
+
* frame, a section, a component set), which is never entered.
|
|
13
|
+
*/
|
|
14
|
+
function enterContainerOf(nodeId) {
|
|
15
|
+
const parentId = ctx.graph.getNode(nodeId)?.parentId ?? null;
|
|
16
|
+
const entered = parentId && parentId !== ctx.state.currentPageId && !ctx.graph.isOpenContainer(parentId);
|
|
17
|
+
ctx.state.enteredContainerId = entered ? parentId : null;
|
|
18
|
+
}
|
|
9
19
|
function exitContainer() {
|
|
10
20
|
const entered = ctx.state.enteredContainerId;
|
|
11
21
|
if (!entered) return;
|
|
@@ -14,10 +24,16 @@ function createSelectionContainerActions(ctx) {
|
|
|
14
24
|
else ctx.state.enteredContainerId = null;
|
|
15
25
|
ctx.setSelectedIds(new Set(entered ? [entered] : []));
|
|
16
26
|
}
|
|
27
|
+
/** Leaves every entered container; Escape then lands on the page and clears the selection. */
|
|
28
|
+
function exitContainers() {
|
|
29
|
+
ctx.state.enteredContainerId = null;
|
|
30
|
+
}
|
|
17
31
|
return {
|
|
18
32
|
validateEnteredContainer,
|
|
19
33
|
enterContainer,
|
|
20
|
-
|
|
34
|
+
enterContainerOf,
|
|
35
|
+
exitContainer,
|
|
36
|
+
exitContainers
|
|
21
37
|
};
|
|
22
38
|
}
|
|
23
39
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","names":[],"sources":["../../../src/editor/selection/container.ts"],"sourcesContent":["import type { EditorContext } from '#core/editor/types'\n\nexport function createSelectionContainerActions(ctx: EditorContext) {\n function validateEnteredContainer() {\n if (ctx.state.enteredContainerId && !ctx.graph.getNode(ctx.state.enteredContainerId)) {\n ctx.state.enteredContainerId = null\n }\n }\n\n function enterContainer(id: string) {\n ctx.state.enteredContainerId = id\n }\n\n function exitContainer() {\n const entered = ctx.state.enteredContainerId\n if (!entered) return\n const node = ctx.graph.getNode(entered)\n const parentId = node?.parentId\n if (parentId && parentId !== ctx.state.currentPageId) {\n ctx.state.enteredContainerId = parentId\n } else {\n ctx.state.enteredContainerId = null\n }\n ctx.setSelectedIds(new Set(entered ? [entered] : []))\n }\n\n return {
|
|
1
|
+
{"version":3,"file":"container.js","names":[],"sources":["../../../src/editor/selection/container.ts"],"sourcesContent":["import type { EditorContext } from '#core/editor/types'\n\nexport function createSelectionContainerActions(ctx: EditorContext) {\n function validateEnteredContainer() {\n if (ctx.state.enteredContainerId && !ctx.graph.getNode(ctx.state.enteredContainerId)) {\n ctx.state.enteredContainerId = null\n }\n }\n\n function enterContainer(id: string) {\n ctx.state.enteredContainerId = id\n }\n\n /**\n * Enters the container a click reached the layer through, as a double-click would have: its\n * direct parent, unless that is the page or a container a click looks into by itself (a top-level\n * frame, a section, a component set), which is never entered.\n */\n function enterContainerOf(nodeId: string) {\n const parentId = ctx.graph.getNode(nodeId)?.parentId ?? null\n const entered =\n parentId && parentId !== ctx.state.currentPageId && !ctx.graph.isOpenContainer(parentId)\n ctx.state.enteredContainerId = entered ? parentId : null\n }\n\n function exitContainer() {\n const entered = ctx.state.enteredContainerId\n if (!entered) return\n const node = ctx.graph.getNode(entered)\n const parentId = node?.parentId\n if (parentId && parentId !== ctx.state.currentPageId) {\n ctx.state.enteredContainerId = parentId\n } else {\n ctx.state.enteredContainerId = null\n }\n ctx.setSelectedIds(new Set(entered ? [entered] : []))\n }\n\n /** Leaves every entered container; Escape then lands on the page and clears the selection. */\n function exitContainers() {\n ctx.state.enteredContainerId = null\n }\n\n return {\n validateEnteredContainer,\n enterContainer,\n enterContainerOf,\n exitContainer,\n exitContainers\n }\n}\n"],"mappings":";AAEA,SAAgB,gCAAgC,KAAoB;CAClE,SAAS,2BAA2B;EAClC,IAAI,IAAI,MAAM,sBAAsB,CAAC,IAAI,MAAM,QAAQ,IAAI,MAAM,kBAAkB,GACjF,IAAI,MAAM,qBAAqB;CAEnC;CAEA,SAAS,eAAe,IAAY;EAClC,IAAI,MAAM,qBAAqB;CACjC;;;;;;CAOA,SAAS,iBAAiB,QAAgB;EACxC,MAAM,WAAW,IAAI,MAAM,QAAQ,MAAM,CAAC,EAAE,YAAY;EACxD,MAAM,UACJ,YAAY,aAAa,IAAI,MAAM,iBAAiB,CAAC,IAAI,MAAM,gBAAgB,QAAQ;EACzF,IAAI,MAAM,qBAAqB,UAAU,WAAW;CACtD;CAEA,SAAS,gBAAgB;EACvB,MAAM,UAAU,IAAI,MAAM;EAC1B,IAAI,CAAC,SAAS;EAEd,MAAM,WADO,IAAI,MAAM,QAAQ,OACX,CAAC,EAAE;EACvB,IAAI,YAAY,aAAa,IAAI,MAAM,eACrC,IAAI,MAAM,qBAAqB;OAE/B,IAAI,MAAM,qBAAqB;EAEjC,IAAI,eAAe,IAAI,IAAI,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;CACtD;;CAGA,SAAS,iBAAiB;EACxB,IAAI,MAAM,qBAAqB;CACjC;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -9,12 +9,15 @@ function createSelectionNavigationActions(ctx, select) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Replaces each selected layer that has children with its children, as Figma's Enter does, and
|
|
13
|
+
* keeps the others selected; a selection where none has children stays. A generated frame, such
|
|
14
|
+
* as a sticky note, has none to offer: its template owns its layers.
|
|
14
15
|
*/
|
|
15
16
|
function selectChildren() {
|
|
16
|
-
const
|
|
17
|
-
|
|
17
|
+
const nodes = selectedNodes();
|
|
18
|
+
const opens = (node) => !isGeneratedFrame(node) && node.childIds.length > 0;
|
|
19
|
+
if (!nodes.some(opens)) return;
|
|
20
|
+
select(nodes.flatMap((node) => opens(node) ? node.childIds : [node.id]));
|
|
18
21
|
}
|
|
19
22
|
/** Selects the parents of the selected layers; layers directly on the page stay selected. */
|
|
20
23
|
function selectParent() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.js","names":[],"sources":["../../../src/editor/selection/navigation.ts"],"sourcesContent":["import { generatedFrameOwner, isGeneratedFrame } from '@pairdraw/scene-graph/generated'\n\nimport type { EditorContext } from '#core/editor/types'\n\ntype Select = (ids: string[]) => void\n\n/** Figma's keyboard moves through the layer tree: Enter, Shift+Enter, Tab, and Shift+Tab. */\nexport function createSelectionNavigationActions(ctx: EditorContext, select: Select) {\n function selectedNodes() {\n return [...ctx.state.selectedIds].flatMap((id) => {\n const node = ctx.graph.getNode(id)\n return node ? [node] : []\n })\n }\n\n /**\n *
|
|
1
|
+
{"version":3,"file":"navigation.js","names":[],"sources":["../../../src/editor/selection/navigation.ts"],"sourcesContent":["import { generatedFrameOwner, isGeneratedFrame } from '@pairdraw/scene-graph/generated'\n\nimport type { EditorContext } from '#core/editor/types'\n\ntype Select = (ids: string[]) => void\n\n/** Figma's keyboard moves through the layer tree: Enter, Shift+Enter, Tab, and Shift+Tab. */\nexport function createSelectionNavigationActions(ctx: EditorContext, select: Select) {\n function selectedNodes() {\n return [...ctx.state.selectedIds].flatMap((id) => {\n const node = ctx.graph.getNode(id)\n return node ? [node] : []\n })\n }\n\n /**\n * Replaces each selected layer that has children with its children, as Figma's Enter does, and\n * keeps the others selected; a selection where none has children stays. A generated frame, such\n * as a sticky note, has none to offer: its template owns its layers.\n */\n function selectChildren() {\n const nodes = selectedNodes()\n const opens = (node: (typeof nodes)[number]) =>\n !isGeneratedFrame(node) && node.childIds.length > 0\n if (!nodes.some(opens)) return\n select(nodes.flatMap((node) => (opens(node) ? node.childIds : [node.id])))\n }\n\n /** Selects the parents of the selected layers; layers directly on the page stay selected. */\n function selectParent() {\n const nodes = selectedNodes()\n const parents = nodes.map((node) => {\n const parent = node.parentId ? ctx.graph.getNode(node.parentId) : undefined\n return parent && parent.type !== 'CANVAS' ? parent.id : node.id\n })\n if (parents.some((id, index) => id !== nodes[index].id)) select(parents)\n }\n\n /**\n * Moves each selected layer to its sibling, wrapping at the ends. Next goes down the layers\n * panel, which lists the topmost layer first, so it steps back through the children.\n */\n function selectSibling(step: 1 | -1) {\n const nodes = selectedNodes()\n if (nodes.length === 0) return\n select(\n nodes.map((node) => {\n if (generatedFrameOwner(ctx.graph, node)) return node.id\n const siblings = node.parentId ? (ctx.graph.getNode(node.parentId)?.childIds ?? []) : []\n const index = siblings.indexOf(node.id)\n if (index === -1) return node.id\n return siblings[(index - step + siblings.length) % siblings.length]\n })\n )\n }\n\n return {\n selectChildren,\n selectParent,\n selectNextSibling: () => selectSibling(1),\n selectPreviousSibling: () => selectSibling(-1)\n }\n}\n"],"mappings":";;;AAOA,SAAgB,iCAAiC,KAAoB,QAAgB;CACn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ACxC,6BAA6B,cAAc,EAAE;CAC/C;AACF"}
|
|
@@ -88,7 +88,7 @@ declare function createSelectionReadActions(ctx: EditorContext): {
|
|
|
88
88
|
layoutAlignSelf: import("@pairdraw/scene-graph").LayoutAlignSelf;
|
|
89
89
|
vectorNetwork: import("@pairdraw/scene-graph").VectorNetwork | null;
|
|
90
90
|
handleMirroring: import("@pairdraw/scene-graph").HandleMirroring;
|
|
91
|
-
booleanOperation: "
|
|
91
|
+
booleanOperation: import("@pairdraw/scene-graph").BooleanOperation | undefined;
|
|
92
92
|
fillGeometry: import("@pairdraw/scene-graph").GeometryPath[];
|
|
93
93
|
strokeGeometry: import("@pairdraw/scene-graph").GeometryPath[];
|
|
94
94
|
arcData: import("@pairdraw/scene-graph").ArcData | null;
|
|
@@ -260,7 +260,7 @@ declare function createSelectionReadActions(ctx: EditorContext): {
|
|
|
260
260
|
layoutAlignSelf: import("@pairdraw/scene-graph").LayoutAlignSelf;
|
|
261
261
|
vectorNetwork: import("@pairdraw/scene-graph").VectorNetwork | null;
|
|
262
262
|
handleMirroring: import("@pairdraw/scene-graph").HandleMirroring;
|
|
263
|
-
booleanOperation: "
|
|
263
|
+
booleanOperation: import("@pairdraw/scene-graph").BooleanOperation | undefined;
|
|
264
264
|
fillGeometry: import("@pairdraw/scene-graph").GeometryPath[];
|
|
265
265
|
strokeGeometry: import("@pairdraw/scene-graph").GeometryPath[];
|
|
266
266
|
arcData: import("@pairdraw/scene-graph").ArcData | null;
|
|
@@ -97,7 +97,7 @@ declare function createSelectionActions(ctx: EditorContext): {
|
|
|
97
97
|
layoutAlignSelf: import("@pairdraw/scene-graph").LayoutAlignSelf;
|
|
98
98
|
vectorNetwork: import("@pairdraw/scene-graph").VectorNetwork | null;
|
|
99
99
|
handleMirroring: import("@pairdraw/scene-graph").HandleMirroring;
|
|
100
|
-
booleanOperation: "
|
|
100
|
+
booleanOperation: import("@pairdraw/scene-graph").BooleanOperation | undefined;
|
|
101
101
|
fillGeometry: import("@pairdraw/scene-graph").GeometryPath[];
|
|
102
102
|
strokeGeometry: import("@pairdraw/scene-graph").GeometryPath[];
|
|
103
103
|
arcData: import("@pairdraw/scene-graph").ArcData | null;
|
|
@@ -269,7 +269,7 @@ declare function createSelectionActions(ctx: EditorContext): {
|
|
|
269
269
|
layoutAlignSelf: import("@pairdraw/scene-graph").LayoutAlignSelf;
|
|
270
270
|
vectorNetwork: import("@pairdraw/scene-graph").VectorNetwork | null;
|
|
271
271
|
handleMirroring: import("@pairdraw/scene-graph").HandleMirroring;
|
|
272
|
-
booleanOperation: "
|
|
272
|
+
booleanOperation: import("@pairdraw/scene-graph").BooleanOperation | undefined;
|
|
273
273
|
fillGeometry: import("@pairdraw/scene-graph").GeometryPath[];
|
|
274
274
|
strokeGeometry: import("@pairdraw/scene-graph").GeometryPath[];
|
|
275
275
|
arcData: import("@pairdraw/scene-graph").ArcData | null;
|
|
@@ -360,7 +360,9 @@ declare function createSelectionActions(ctx: EditorContext): {
|
|
|
360
360
|
}[];
|
|
361
361
|
validateEnteredContainer: () => void;
|
|
362
362
|
enterContainer: (id: string) => void;
|
|
363
|
+
enterContainerOf: (nodeId: string) => void;
|
|
363
364
|
exitContainer: () => void;
|
|
365
|
+
exitContainers: () => void;
|
|
364
366
|
setConnectorTarget: (target: ConnectorTarget | null) => void;
|
|
365
367
|
setMarquee: (rect: import("@pairdraw/scene-graph/primitives").Rect | null) => void;
|
|
366
368
|
setSnapGuides: (guides: import("@pairdraw/scene-graph/snap").SnapGuide[]) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.d.ts","names":[],"sources":["../../src/editor/selection.ts"],"mappings":";;;;;;;;;iBASgB,uBAAuB,KAAK;;qDAAA
|
|
1
|
+
{"version":3,"file":"selection.d.ts","names":[],"sources":["../../src/editor/selection.ts"],"mappings":";;;;;;;;;iBASgB,uBAAuB,KAAK;;qDAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0Bf,SAAA,qBAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-text.d.ts","names":[],"sources":["../../../src/editor/shapes/with-text.ts"],"mappings":";;;;;;;;;;iBA4BgB,2BAA2B,KAAK,eAAe,OAAO;EAoBhC,uBAAA,MAAA;EAQG,2BAAA,KAAA,kBAAgB,MAAQ;
|
|
1
|
+
{"version":3,"file":"with-text.d.ts","names":[],"sources":["../../../src/editor/shapes/with-text.ts"],"mappings":";;;;;;;;;;iBA4BgB,2BAA2B,KAAK,eAAe,OAAO;EAoBhC,uBAAA,MAAA;EAQG,2BAAA,KAAA,kBAAgB,MAAQ;EAsB1B,yBAAA,KAAA,kBAAgB,MAAQ;EAQrB,4BAAA,KAAA,kBAAgB,MAAQ;EAcvB,6BAAA,KAAA,kBAAgB,OAAS;EAOzB,6BAAA,KAAA,kBAAgB,MAAQ;EAOzB,4BAAA,KAAA,kBAAgB,MAAQ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { recordSubtreeEdit } from "../components/slots/history.js";
|
|
2
|
-
import {
|
|
2
|
+
import { shapeWithTextKindFields, shapeWithTextLabel } from "@pairdraw/scene-graph/generated";
|
|
3
3
|
import { figJamColorName, figJamFillMode, figJamLineColorFields, figJamLineStyleFields, figJamShapePaint, figJamTextSizeFields, figJamTypeface } from "@pairdraw/scene-graph/figjam";
|
|
4
4
|
//#region src/editor/shapes/with-text.ts
|
|
5
5
|
const FILL_OPACITY = {
|
|
@@ -34,10 +34,7 @@ function createShapeWithTextActions(ctx, nodes) {
|
|
|
34
34
|
*/
|
|
35
35
|
function changeShapesWithTextKind(ids, kind) {
|
|
36
36
|
editShapes("Change shape", shapesAmong(ids).filter((shape) => shape.shapeWithTextType !== kind).map((shape) => shape.id), (shape) => {
|
|
37
|
-
nodes.updateNode(shape.id,
|
|
38
|
-
shapeWithTextType: kind,
|
|
39
|
-
...shapeWithTextFrameFields(kind, shape.width, shape.height)
|
|
40
|
-
});
|
|
37
|
+
nodes.updateNode(shape.id, shapeWithTextKindFields(shape, kind));
|
|
41
38
|
});
|
|
42
39
|
}
|
|
43
40
|
function paint(shape, name, mode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-text.js","names":[],"sources":["../../../src/editor/shapes/with-text.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\nimport {\n figJamColorName,\n figJamFillMode,\n figJamLineColorFields,\n figJamLineStyleFields,\n figJamShapePaint,\n figJamTextSizeFields,\n figJamTypeface,\n type FigJamColorName,\n type FigJamFillMode,\n type FigJamLineStyle,\n type FigJamTextSize\n} from '@pairdraw/scene-graph/figjam'\nimport {
|
|
1
|
+
{"version":3,"file":"with-text.js","names":[],"sources":["../../../src/editor/shapes/with-text.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\nimport {\n figJamColorName,\n figJamFillMode,\n figJamLineColorFields,\n figJamLineStyleFields,\n figJamShapePaint,\n figJamTextSizeFields,\n figJamTypeface,\n type FigJamColorName,\n type FigJamFillMode,\n type FigJamLineStyle,\n type FigJamTextSize\n} from '@pairdraw/scene-graph/figjam'\nimport { shapeWithTextKindFields, shapeWithTextLabel } from '@pairdraw/scene-graph/generated'\nimport type { ShapeWithTextType } from '@pairdraw/scene-graph/shape-with-text'\n\nimport { recordSubtreeEdit } from '#core/editor/components/slots/history'\nimport type { NodeActions } from '#core/editor/nodes'\nimport type { EditorContext } from '#core/editor/types'\n\nconst FILL_OPACITY: Record<FigJamFillMode, number> = { fill: 1, transparent: 0.5, none: 0 }\n\n/**\n * Shape-with-text commands: the kind the tool places, and the kind, colours, outline and text of\n * shapes already placed, as FigJam's selection toolbar sets them. Each change records the\n * shapes' whole subtrees as one step, since the label changes with the shape.\n */\nexport function createShapeWithTextActions(ctx: EditorContext, nodes: NodeActions) {\n function shapesAmong(ids: Iterable<string>): SceneNode[] {\n return [...ids].flatMap((id) => {\n const node = ctx.graph.getNode(id)\n return node?.type === 'SHAPE_WITH_TEXT' ? [node] : []\n })\n }\n\n function editShapes(label: string, ids: Iterable<string>, change: (shape: SceneNode) => void) {\n const shapes = shapesAmong(ids)\n if (shapes.length === 0) return\n recordSubtreeEdit(\n ctx,\n label,\n shapes.map((shape) => shape.id),\n () => shapes.forEach(change)\n )\n }\n\n /** Makes `kind` the one the shape tool places, as picking it in FigJam's Shapes panel does. */\n function setShapeWithTextKind(kind: ShapeWithTextType) {\n ctx.state.shapeWithTextKind = kind\n }\n\n /**\n * Turns the shapes with text among `ids` into `kind`, keeping their size, as FigJam's shape\n * switcher does; each lays its label out in the new kind's label area.\n */\n function changeShapesWithTextKind(ids: Iterable<string>, kind: ShapeWithTextType) {\n const changing = shapesAmong(ids).filter((shape) => shape.shapeWithTextType !== kind)\n editShapes(\n 'Change shape',\n changing.map((shape) => shape.id),\n (shape) => {\n nodes.updateNode(shape.id, shapeWithTextKindFields(shape, kind))\n }\n )\n }\n\n function paint(shape: SceneNode, name: FigJamColorName, mode: FigJamFillMode) {\n const label = shapeWithTextLabel(ctx.graph, shape)\n const painted = figJamShapePaint(shape, label, name, mode)\n nodes.updateNode(shape.id, painted.shape)\n if (label) nodes.updateNode(label.id, painted.label)\n }\n\n /**\n * Paints the shapes in palette colour `name`. A see-through fill stays see-through, and a shape\n * without fill is filled again.\n */\n function setShapesWithTextColor(ids: Iterable<string>, name: FigJamColorName) {\n editShapes('Change shape color', ids, (shape) => {\n const mode = figJamFillMode(shape.fills.at(0))\n paint(shape, name, mode === 'none' ? 'fill' : mode)\n })\n }\n\n /** Fills the shapes solid, see-through, or not at all, keeping their colour. */\n function setShapesWithTextFillMode(ids: Iterable<string>, mode: FigJamFillMode) {\n editShapes('Change shape fill', ids, (shape) => {\n const fill = shape.fills.at(0)\n const name = figJamColorName(fill?.color)\n if (name) paint(shape, name, mode)\n else if (fill) {\n nodes.updateNode(shape.id, {\n fills: [{ ...fill, opacity: FILL_OPACITY[mode] }, ...shape.fills.slice(1)]\n })\n }\n })\n }\n\n /** Draws the shapes' outlines solid, dashed, or not at all. */\n function setShapesWithTextLineStyle(ids: Iterable<string>, style: FigJamLineStyle) {\n editShapes('Change shape line', ids, (shape) =>\n nodes.updateNode(shape.id, figJamLineStyleFields(shape, style))\n )\n }\n\n /** Colours the shapes' outlines in palette colour `name`, which later fills leave alone. */\n function setShapesWithTextLineColor(ids: Iterable<string>, name: FigJamColorName) {\n editShapes('Change shape line color', ids, (shape) =>\n nodes.updateNode(shape.id, figJamLineColorFields(shape, name))\n )\n }\n\n /** Sets the shapes' label text to one of FigJam's sizes; each grows or shrinks to fit it. */\n function setShapesWithTextTextSize(ids: Iterable<string>, size: FigJamTextSize) {\n editShapes('Change shape text size', ids, (shape) => {\n const label = shapeWithTextLabel(ctx.graph, shape)\n if (label) {\n nodes.updateNode(label.id, figJamTextSizeFields(size, figJamTypeface(label) ?? 'simple'))\n }\n })\n }\n\n return {\n setShapeWithTextKind,\n changeShapesWithTextKind,\n setShapesWithTextColor,\n setShapesWithTextFillMode,\n setShapesWithTextLineStyle,\n setShapesWithTextLineColor,\n setShapesWithTextTextSize\n }\n}\n"],"mappings":";;;;AAqBA,MAAM,eAA+C;CAAE,MAAM;CAAG,aAAa;CAAK,MAAM;AAAE;;;;;;AAO1F,SAAgB,2BAA2B,KAAoB,OAAoB;CACjF,SAAS,YAAY,KAA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O,gBAAgB,MAAM,KAAK;GACxC,IAAI,MAAM,MAAM,OAAO,MAAM,IAAI;QAC5B,IAAI,MACP,MAAM,WAAW,MAAM,IAAI,EACzB,OAAO,CAAC;IAAE,GAAG;IAAM,SAAS,aAAa;GAAM,GAAG,GAAG,MAAM,MAAM,MAAM,CAAC,CAAC,EAC3E,CAAC;EAEL,CAAC;CACH;;CAGA,SAAS,2BAA2B,KAAuB,OAAwB;EACjF,WAAW,qBAAqB,MAAM,UACpC,MAAM,WAAW,MAAM,IAAI,sBAAsB,OAAO,KAAK,CAAC,CAChE;CACF;;CAGA,SAAS,2BAA2B,KAAuB,MAAuB;EAChF,WAAW,2BAA2B,MAAM,UAC1C,MAAM,WAAW,MAAM,IAAI,sBAAsB,OAAO,IAAI,CAAC,CAC/D;CACF;;CAGA,SAAS,0BAA0B,KAAuB,MAAsB;EAC9E,WAAW,0BAA0B,MAAM,UAAU;GACnD,MAAM,QAAQ,mBAAmB,IAAI,OAAO,KAAK;GACjD,IAAI,OACF,MAAM,WAAW,MAAM,IAAI,qBAAqB,MAAM,eAAe,KAAK,KAAK,QAAQ,CAAC;EAE5F,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -85,7 +85,7 @@ function wrapInAutoLayout(ctx, selectedNodes) {
|
|
|
85
85
|
ctx.graph.deleteNode(frameId);
|
|
86
86
|
order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index));
|
|
87
87
|
for (const [id, rect] of geometry) ctx.graph.updateNode(id, rect);
|
|
88
|
-
ctx.
|
|
88
|
+
ctx.runLayoutForParents([parentId]);
|
|
89
89
|
ctx.setSelectedIds(prevSelection);
|
|
90
90
|
}
|
|
91
91
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-layout-wrap.js","names":[],"sources":["../../../src/editor/structure/auto-layout-wrap.ts"],"sourcesContent":["import { median } from 'es-toolkit'\n\nimport type { LayoutMode, SceneNode } from '@pairdraw/scene-graph'\nimport { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'\nimport type { Rect } from '@pairdraw/scene-graph/primitives'\n\nimport { wrapParentId } from '#core/editor/structure/container-wrap'\nimport type { EditorContext } from '#core/editor/types'\nimport { computeLayout } from '#core/layout'\n\n/** The place and size of each layer and everything inside it, which the new layout can change. */\nfunction captureGeometry(ctx: EditorContext, nodes: SceneNode[]): Map<string, Rect> {\n const geometry = new Map<string, Rect>()\n const visit = (node: SceneNode) => {\n geometry.set(node.id, { x: node.x, y: node.y, width: node.width, height: node.height })\n for (const child of ctx.graph.getChildren(node.id)) visit(child)\n }\n for (const node of nodes) visit(node)\n return geometry\n}\n\n/** The spacing the layers already have along `direction`, rounded, as Figma infers it. */\nfunction inferGap(ctx: EditorContext, nodes: SceneNode[], direction: LayoutMode): number {\n const horizontal = direction === 'HORIZONTAL'\n const placed = nodes\n .map((node) => ({\n position: ctx.graph.getAbsolutePosition(node.id),\n size: horizontal ? node.width : node.height\n }))\n .sort((a, b) =>\n horizontal\n ? a.position.x - b.position.x || a.position.y - b.position.y\n : a.position.y - b.position.y || a.position.x - b.position.x\n )\n const gaps = placed\n .slice(1)\n .map((item, index) =>\n horizontal\n ? item.position.x - (placed[index].position.x + placed[index].size)\n : item.position.y - (placed[index].position.y + placed[index].size)\n )\n return gaps.length > 0 ? Math.round(median(gaps)) : 0\n}\n\n/**\n * Wrap sibling layers in a new auto layout frame; returns the frame, or null if they are not\n * siblings. The frame takes the slot of the topmost selected layer, as Figma places a new group,\n * and undo puts every layer back in its old slot, place, and size.\n */\nexport function wrapInAutoLayout(ctx: EditorContext, selectedNodes: SceneNode[]): string | null {\n const wrapParent = wrapParentId(ctx, selectedNodes)\n const parent = wrapParent ? ctx.graph.getNode(wrapParent) : undefined\n if (!parent) return null\n const parentId = parent.id\n\n const prevSelection = new Set(ctx.state.selectedIds)\n const order = [...parent.childIds]\n const geometry = captureGeometry(ctx, selectedNodes)\n const bounds = getAxisAlignedBoundsInParent(selectedNodes, parentId, ctx.graph)\n const direction: LayoutMode =\n selectedNodes.length <= 1 || bounds.height > bounds.width ? 'VERTICAL' : 'HORIZONTAL'\n const frameFields: Partial<SceneNode> = {\n name: 'Frame',\n x: bounds.x,\n y: bounds.y,\n width: bounds.width,\n height: bounds.height,\n layoutMode: direction,\n primaryAxisSizing: 'HUG',\n counterAxisSizing: 'HUG',\n itemSpacing: inferGap(ctx, selectedNodes, direction),\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n fills: []\n }\n // In reading order inside the new frame.\n const sortedIds = selectedNodes\n .map((n) => ({ id: n.id, pos: ctx.graph.getAbsolutePosition(n.id) }))\n .sort((a, b) => a.pos.y - b.pos.y || a.pos.x - b.pos.x)\n .map((n) => n.id)\n // Just above the topmost selected layer, before the selected layers move into the frame.\n const slot = Math.max(...selectedNodes.map((n) => order.indexOf(n.id))) + 1\n\n function wrap(frameId?: string): string {\n const frame = ctx.graph.createNode('FRAME', parentId, {\n ...frameFields,\n ...(frameId ? { id: frameId } : {})\n })\n ctx.graph.insertChildAt(frame.id, parentId, slot)\n for (const id of sortedIds) ctx.graph.reparentNode(id, frame.id)\n computeLayout(ctx.graph, frame.id)\n ctx.runLayoutForNode(frame.id)\n ctx.setSelectedIds(new Set([frame.id]))\n return frame.id\n }\n\n const frameId = wrap()\n ctx.undo.push({\n label: 'Wrap in auto layout',\n forward: () => {\n wrap(frameId)\n },\n inverse: () => {\n for (const id of sortedIds) ctx.graph.reparentNode(id, parentId)\n ctx.graph.deleteNode(frameId)\n order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index))\n for (const [id, rect] of geometry) ctx.graph.updateNode(id, rect)\n ctx.
|
|
1
|
+
{"version":3,"file":"auto-layout-wrap.js","names":[],"sources":["../../../src/editor/structure/auto-layout-wrap.ts"],"sourcesContent":["import { median } from 'es-toolkit'\n\nimport type { LayoutMode, SceneNode } from '@pairdraw/scene-graph'\nimport { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'\nimport type { Rect } from '@pairdraw/scene-graph/primitives'\n\nimport { wrapParentId } from '#core/editor/structure/container-wrap'\nimport type { EditorContext } from '#core/editor/types'\nimport { computeLayout } from '#core/layout'\n\n/** The place and size of each layer and everything inside it, which the new layout can change. */\nfunction captureGeometry(ctx: EditorContext, nodes: SceneNode[]): Map<string, Rect> {\n const geometry = new Map<string, Rect>()\n const visit = (node: SceneNode) => {\n geometry.set(node.id, { x: node.x, y: node.y, width: node.width, height: node.height })\n for (const child of ctx.graph.getChildren(node.id)) visit(child)\n }\n for (const node of nodes) visit(node)\n return geometry\n}\n\n/** The spacing the layers already have along `direction`, rounded, as Figma infers it. */\nfunction inferGap(ctx: EditorContext, nodes: SceneNode[], direction: LayoutMode): number {\n const horizontal = direction === 'HORIZONTAL'\n const placed = nodes\n .map((node) => ({\n position: ctx.graph.getAbsolutePosition(node.id),\n size: horizontal ? node.width : node.height\n }))\n .sort((a, b) =>\n horizontal\n ? a.position.x - b.position.x || a.position.y - b.position.y\n : a.position.y - b.position.y || a.position.x - b.position.x\n )\n const gaps = placed\n .slice(1)\n .map((item, index) =>\n horizontal\n ? item.position.x - (placed[index].position.x + placed[index].size)\n : item.position.y - (placed[index].position.y + placed[index].size)\n )\n return gaps.length > 0 ? Math.round(median(gaps)) : 0\n}\n\n/**\n * Wrap sibling layers in a new auto layout frame; returns the frame, or null if they are not\n * siblings. The frame takes the slot of the topmost selected layer, as Figma places a new group,\n * and undo puts every layer back in its old slot, place, and size.\n */\nexport function wrapInAutoLayout(ctx: EditorContext, selectedNodes: SceneNode[]): string | null {\n const wrapParent = wrapParentId(ctx, selectedNodes)\n const parent = wrapParent ? ctx.graph.getNode(wrapParent) : undefined\n if (!parent) return null\n const parentId = parent.id\n\n const prevSelection = new Set(ctx.state.selectedIds)\n const order = [...parent.childIds]\n const geometry = captureGeometry(ctx, selectedNodes)\n const bounds = getAxisAlignedBoundsInParent(selectedNodes, parentId, ctx.graph)\n const direction: LayoutMode =\n selectedNodes.length <= 1 || bounds.height > bounds.width ? 'VERTICAL' : 'HORIZONTAL'\n const frameFields: Partial<SceneNode> = {\n name: 'Frame',\n x: bounds.x,\n y: bounds.y,\n width: bounds.width,\n height: bounds.height,\n layoutMode: direction,\n primaryAxisSizing: 'HUG',\n counterAxisSizing: 'HUG',\n itemSpacing: inferGap(ctx, selectedNodes, direction),\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n fills: []\n }\n // In reading order inside the new frame.\n const sortedIds = selectedNodes\n .map((n) => ({ id: n.id, pos: ctx.graph.getAbsolutePosition(n.id) }))\n .sort((a, b) => a.pos.y - b.pos.y || a.pos.x - b.pos.x)\n .map((n) => n.id)\n // Just above the topmost selected layer, before the selected layers move into the frame.\n const slot = Math.max(...selectedNodes.map((n) => order.indexOf(n.id))) + 1\n\n function wrap(frameId?: string): string {\n const frame = ctx.graph.createNode('FRAME', parentId, {\n ...frameFields,\n ...(frameId ? { id: frameId } : {})\n })\n ctx.graph.insertChildAt(frame.id, parentId, slot)\n for (const id of sortedIds) ctx.graph.reparentNode(id, frame.id)\n computeLayout(ctx.graph, frame.id)\n ctx.runLayoutForNode(frame.id)\n ctx.setSelectedIds(new Set([frame.id]))\n return frame.id\n }\n\n const frameId = wrap()\n ctx.undo.push({\n label: 'Wrap in auto layout',\n forward: () => {\n wrap(frameId)\n },\n inverse: () => {\n for (const id of sortedIds) ctx.graph.reparentNode(id, parentId)\n ctx.graph.deleteNode(frameId)\n order.forEach((id, index) => ctx.graph.insertChildAt(id, parentId, index))\n for (const [id, rect] of geometry) ctx.graph.updateNode(id, rect)\n ctx.runLayoutForParents([parentId])\n ctx.setSelectedIds(prevSelection)\n }\n })\n return frameId\n}\n"],"mappings":";;;;;;AAWA,SAAS,gBAAgB,KAAoB,OAAuC;CAClF,MAAM,2BAAW,IAAI,IAAkB;CACvC,MAAM,SAAS,SAAoB;EACjC,SAAS,IAAI,KAAK,IAAI;GAAE,GAAG,KAA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;GAC/D,IAAI,MAAM,WAAW,OAAO;GAC5B,MAAM,SAAS,IAAI,UAAU,IAAI,MAAM,cAAc,IAAI,UAAU,KAAK,CAAC;GACzE,KAAK,MAAM,CAAC,IAAI,SAAS,UAAU,IAAI,MAAM,WAAW,IAAI,IAAI;GAChE,IAAI,oBAAoB,CAAC,QAAQ,CAAC;GAClC,IAAI,eAAe,aAAa;EAClC;CACF,CAAC;CACD,OAAO;AACT"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { EditorContext } from "../types.js";
|
|
2
|
-
import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
2
|
+
import { BooleanOperation, SceneGraph, SceneNode } from "@pairdraw/scene-graph";
|
|
3
3
|
import { GroupFit, GroupFitOptions } from "@pairdraw/scene-graph/group-bounds";
|
|
4
4
|
//#region src/editor/structure/boolean.d.ts
|
|
5
|
-
type BooleanOperation = 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE';
|
|
6
5
|
/**
|
|
7
6
|
* Wraps sibling layers in a boolean operation named after it, as Figma names one from the canvas
|
|
8
7
|
* and from the plugin API. Shared by the editor command and the plugin API; `props` gives the look.
|
|
@@ -20,5 +19,5 @@ declare function createBooleanOperation(graph: SceneGraph, nodes: readonly Scene
|
|
|
20
19
|
declare function booleanOperationPaints(operation: BooleanOperation, nodes: readonly SceneNode[], style: 'canvas' | 'script'): Partial<SceneNode>;
|
|
21
20
|
declare function booleanOperationSelected(ctx: EditorContext, selectedNodes: SceneNode[], operation: BooleanOperation): string | null;
|
|
22
21
|
//#endregion
|
|
23
|
-
export {
|
|
22
|
+
export { booleanOperationPaints, booleanOperationSelected, createBooleanOperation };
|
|
24
23
|
//# sourceMappingURL=boolean.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boolean.d.ts","names":[],"sources":["../../../src/editor/structure/boolean.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"boolean.d.ts","names":[],"sources":["../../../src/editor/structure/boolean.ts"],"mappings":";;;;;;;;;iBAsBgB,uBACd,OAAO,YACP,gBAAgB,aAChB,kBACA,WAAW,kBACX,2BACA,QAAO,QAAQ,YACf,aAAY;EACT,MAAM;EAAW,KAAK;;;;;;;iBAgBX,uBACd,WAAW,kBACX,gBAAgB,aAChB,6BACC,QAAQ;iBAMK,yBACd,KAAK,eACL,eAAe,aACf,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boolean.js","names":["exhaustive"],"sources":["../../../src/editor/structure/boolean.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { copyFills } from '@pairdraw/scene-graph/copy'\nimport {\n fitEnclosingGroups,\n undoGroupFit,\n type GroupFit,\n type GroupFitOptions\n} from '@pairdraw/scene-graph/group-bounds'\n\nimport { canMakeBooleanSourceNode, groupFitOptions } from '#core/canvas/boolean'\nimport { restoreSubtree, snapshotSubtree } from '#core/editor/history/subtree'\nimport { newLayerDefaults } from '#core/editor/shapes/defaults'\nimport type { EditorContext } from '#core/editor/types'\n\nimport { canvasWrapIndex, inStackOrder, wrapNodes } from './container-wrap'\nimport { selectedNodesInSharedParent } from './selection'\n\
|
|
1
|
+
{"version":3,"file":"boolean.js","names":["exhaustive"],"sources":["../../../src/editor/structure/boolean.ts"],"sourcesContent":["import type { BooleanOperation, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { copyFills } from '@pairdraw/scene-graph/copy'\nimport {\n fitEnclosingGroups,\n undoGroupFit,\n type GroupFit,\n type GroupFitOptions\n} from '@pairdraw/scene-graph/group-bounds'\n\nimport { canMakeBooleanSourceNode, groupFitOptions } from '#core/canvas/boolean'\nimport { restoreSubtree, snapshotSubtree } from '#core/editor/history/subtree'\nimport { newLayerDefaults } from '#core/editor/shapes/defaults'\nimport type { EditorContext } from '#core/editor/types'\n\nimport { canvasWrapIndex, inStackOrder, wrapNodes } from './container-wrap'\nimport { selectedNodesInSharedParent } from './selection'\n\n/**\n * Wraps sibling layers in a boolean operation named after it, as Figma names one from the canvas\n * and from the plugin API. Shared by the editor command and the plugin API; `props` gives the look.\n * Returns the refit of the boolean and the groups around it too, so undo can reverse it.\n */\nexport function createBooleanOperation(\n graph: SceneGraph,\n nodes: readonly SceneNode[],\n parentId: string,\n operation: BooleanOperation,\n index: number | undefined,\n props: Partial<SceneNode> = {},\n fitOptions: GroupFitOptions = {}\n): { node: SceneNode; fit: GroupFit | null } {\n const node = wrapNodes(graph, 'BOOLEAN_OPERATION', nodes, parentId, index, {\n name: operationLabel(operation),\n booleanOperation: operation,\n ...props\n })\n // Figma sizes a boolean to its result, and the groups around it follow.\n const fit = fitEnclosingGroups(graph, [node.id], fitOptions)\n return { node, fit }\n}\n\n/**\n * Paints of a new boolean operation, listed bottom to top. From the canvas Figma fills it like its\n * topmost operand, or like the base for Subtract, without strokes; from the plugin API it gets the\n * default shape grey.\n */\nexport function booleanOperationPaints(\n operation: BooleanOperation,\n nodes: readonly SceneNode[],\n style: 'canvas' | 'script'\n): Partial<SceneNode> {\n if (style === 'script') return { fills: newLayerDefaults('RECTANGLE').fills, strokes: [] }\n const source = operation === 'SUBTRACT' ? nodes.at(0) : nodes.at(-1)\n return { fills: copyFills(source?.fills ?? []), strokes: [] }\n}\n\nexport function booleanOperationSelected(\n ctx: EditorContext,\n selectedNodes: SceneNode[],\n operation: BooleanOperation\n) {\n const selection = selectedNodesInSharedParent(ctx, selectedNodes)\n if (!selection || selection.topLevel.length < 2) return null\n const { parentId, parent } = selection\n if (selection.topLevel.some((node) => !canMakeBooleanSourceNode(node, ctx.graph))) return null\n\n const operands = inStackOrder(ctx.graph, selection.topLevel, parentId)\n const prevSelection = new Set(ctx.state.selectedIds)\n const childSnapshots = operands.map((node) => ({\n id: node.id,\n subtree: snapshotSubtree(ctx.graph, node.id)\n }))\n const origPositions = operands.map((node) => ({\n id: node.id,\n x: node.x,\n y: node.y,\n index: parent.childIds.indexOf(node.id)\n }))\n const index = canvasWrapIndex(parent, operands)\n const { node: booleanNode, fit: createdFit } = createBooleanOperation(\n ctx.graph,\n operands,\n parentId,\n operation,\n index,\n booleanOperationPaints(operation, operands, 'canvas'),\n groupFitOptions(ctx.getRenderer(), ctx.graph)\n )\n const booleanId = booleanNode.id\n let fit = createdFit\n ctx.setSelectedIds(new Set([booleanId]))\n\n ctx.undo.push({\n label: operationLabel(operation),\n forward: () => {\n const nodes = origPositions.flatMap((pos) => ctx.graph.getNode(pos.id) ?? [])\n fit = createBooleanOperation(\n ctx.graph,\n nodes,\n parentId,\n operation,\n index,\n { ...booleanNode, childIds: [], id: booleanId },\n groupFitOptions(ctx.getRenderer(), ctx.graph)\n ).fit\n ctx.setSelectedIds(new Set([booleanId]))\n },\n inverse: () => {\n // The groups around the boolean go back first, so the operands' places mean what they did.\n if (fit) undoGroupFit(ctx.graph, fit)\n for (const { id, subtree } of childSnapshots) {\n const root = subtree.get(id)\n if (!root) continue\n if (!ctx.graph.getNode(id)) restoreSubtree(ctx.graph, root, parentId, subtree)\n else ctx.graph.reparentNode(id, parentId)\n }\n ctx.graph.deleteNode(booleanId)\n // Back to their own places in the stack, lowest first so each index is still free.\n for (const pos of origPositions) {\n ctx.graph.insertChildAt(pos.id, parentId, pos.index)\n ctx.graph.updateNode(pos.id, { x: pos.x, y: pos.y })\n }\n ctx.setSelectedIds(prevSelection)\n }\n })\n\n return booleanId\n}\n\nfunction operationLabel(operation: BooleanOperation) {\n switch (operation) {\n case 'UNION':\n return 'Union'\n case 'SUBTRACT':\n return 'Subtract'\n case 'INTERSECT':\n return 'Intersect'\n case 'EXCLUDE':\n return 'Exclude'\n default: {\n const exhaustive: never = operation\n return exhaustive\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,SAAgB,uBACd,OACA,OACA,UACA,WACA,OACA,QAA4B,CAAC,GAC7B,aAA8B,CAAC,GACY;CAC3C,MAAM,OAAO,UAAU,OAAO,qBAAqB,OAAO,UAAU,OAAO;EACzE,MAAM,eAAe,S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ounds.d.ts","names":[],"sources":["../../../../src/editor/structure/group/bounds.ts"],"mappings":";;;;;;;;iBAagB,2BAA2B,KAAK,eAAe,WAAW;;;;;;
|
|
1
|
+
{"version":3,"file":"bounds.d.ts","names":[],"sources":["../../../../src/editor/structure/group/bounds.ts"],"mappings":";;;;;;;;iBAagB,2BAA2B,KAAK,eAAe,WAAW;;;;;;iBA+B1D,wBAAwB,KAAK,eAAe,UAAU"}
|
|
@@ -12,9 +12,7 @@ function fitEnclosingGroupsWithUndo(ctx, parentIds) {
|
|
|
12
12
|
const fit = fitEnclosingGroups(ctx.graph, parentIds, groupFitOptions(ctx.getRenderer(), ctx.graph));
|
|
13
13
|
if (!fit) return;
|
|
14
14
|
const fittedParents = compact([...[...fit.before.keys()].map((id) => ctx.graph.getNode(id)?.parentId), ...fit.removed.map(({ node }) => node.parentId)]);
|
|
15
|
-
const layoutAround = () =>
|
|
16
|
-
for (const parentId of new Set(fittedParents)) if (parentId) ctx.runLayoutForNode(parentId);
|
|
17
|
-
};
|
|
15
|
+
const layoutAround = () => ctx.runLayoutForParents(fittedParents);
|
|
18
16
|
layoutAround();
|
|
19
17
|
ctx.undo.push({
|
|
20
18
|
label: "Fit groups",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounds.js","names":[],"sources":["../../../../src/editor/structure/group/bounds.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\n\nimport { fitEnclosingGroups, redoGroupFit, undoGroupFit } from '@pairdraw/scene-graph/group-bounds'\n\nimport { groupFitOptions } from '#core/canvas/boolean'\nimport type { EditorContext } from '#core/editor/types'\n\n/**\n * Refits the groups and booleans around these parents after their layers moved, came, or went, as\n * one undo step; a group left empty goes away. An auto layout around a group that changed lays out\n * again, so the layers beside it make room. The fit itself is shared with the plugin API; see\n * `fitEnclosingGroups` in Scene Graph.\n */\nexport function fitEnclosingGroupsWithUndo(ctx: EditorContext, parentIds: Iterable<string>) {\n const fit = fitEnclosingGroups(\n ctx.graph,\n parentIds,\n groupFitOptions(ctx.getRenderer(), ctx.graph)\n )\n if (!fit) return\n const fittedParents = compact([\n ...[...fit.before.keys()].map((id) => ctx.graph.getNode(id)?.parentId),\n ...fit.removed.map(({ node }) => node.parentId)\n ])\n const layoutAround = () =>
|
|
1
|
+
{"version":3,"file":"bounds.js","names":[],"sources":["../../../../src/editor/structure/group/bounds.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\n\nimport { fitEnclosingGroups, redoGroupFit, undoGroupFit } from '@pairdraw/scene-graph/group-bounds'\n\nimport { groupFitOptions } from '#core/canvas/boolean'\nimport type { EditorContext } from '#core/editor/types'\n\n/**\n * Refits the groups and booleans around these parents after their layers moved, came, or went, as\n * one undo step; a group left empty goes away. An auto layout around a group that changed lays out\n * again, so the layers beside it make room. The fit itself is shared with the plugin API; see\n * `fitEnclosingGroups` in Scene Graph.\n */\nexport function fitEnclosingGroupsWithUndo(ctx: EditorContext, parentIds: Iterable<string>) {\n const fit = fitEnclosingGroups(\n ctx.graph,\n parentIds,\n groupFitOptions(ctx.getRenderer(), ctx.graph)\n )\n if (!fit) return\n const fittedParents = compact([\n ...[...fit.before.keys()].map((id) => ctx.graph.getNode(id)?.parentId),\n ...fit.removed.map(({ node }) => node.parentId)\n ])\n const layoutAround = () => ctx.runLayoutForParents(fittedParents)\n layoutAround()\n ctx.undo.push({\n label: 'Fit groups',\n forward: () => {\n redoGroupFit(ctx.graph, fit)\n layoutAround()\n },\n inverse: () => {\n undoGroupFit(ctx.graph, fit)\n layoutAround()\n }\n })\n}\n\n/**\n * Refits the groups around layers that were shown or hidden, since a group spans only the layers\n * it shows. The fit follows from what the layers show, so an edit that replays on undo and redo\n * refits again and needs no undo step of its own.\n */\nexport function refitGroupsAroundLayers(ctx: EditorContext, layerIds: Iterable<string>) {\n const parentIds = compact([...layerIds].map((id) => ctx.graph.getNode(id)?.parentId))\n fitEnclosingGroups(ctx.graph, parentIds, groupFitOptions(ctx.getRenderer(), ctx.graph))\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,2BAA2B,KAAoB,WAA6B;CAC1F,MAAM,MAAM,mBACV,IAAI,OACJ,WACA,gBAAgB,IAAI,YAAY,GAAG,IAAI,KAAK,CAC9C;CACA,IAAI,CAAC,KAAK;CACV,MAAM,gBAAgB,QAAQ,CAC5B,GAAG,CAAC,GAAG,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,IAAI,MAAM,QAAQ,EAAE,CAAC,EAAE,QAAQ,GACrE,GAAG,IAAI,QAAQ,KAAK,EAAE,WAAW,KAAK,QAAQ,CAChD,CAAC;CACD,MAAM,qBAAqB,IAAI,oBAAoB,aAAa;CAChE,aAAa;CACb,IAAI,KAAK,KAAK;EACZ,OAAO;EACP,eAAe;GACb,aAAa,IAAI,OAAO,GAAG;GAC3B,aAAa;EACf;EACA,eAAe;GACb,aAAa,IAAI,OAAO,GAAG;GAC3B,aAAa;EACf;CACF,CAAC;AACH;;;;;;AAOA,SAAgB,wBAAwB,KAAoB,UAA4B;CACtF,MAAM,YAAY,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,OAAO,IAAI,MAAM,QAAQ,EAAE,CAAC,EAAE,QAAQ,CAAC;CACpF,mBAAmB,IAAI,OAAO,WAAW,gBAAgB,IAAI,YAAY,GAAG,IAAI,KAAK,CAAC;AACxF"}
|
|
@@ -60,7 +60,7 @@ function outlineStrokeSelected(ctx, selectedNodes) {
|
|
|
60
60
|
});
|
|
61
61
|
const parentIds = new Set(plan.map((entry) => entry.parentId));
|
|
62
62
|
const prevSelection = new Set(ctx.state.selectedIds);
|
|
63
|
-
|
|
63
|
+
ctx.runLayoutForParents(parentIds);
|
|
64
64
|
ctx.setSelectedIds(new Set(madeIds));
|
|
65
65
|
ctx.undo.runBatch("Outline stroke", () => {
|
|
66
66
|
pushOutlineUndo(ctx, {
|
|
@@ -81,7 +81,7 @@ function pushOutlineUndo(ctx, { plan, made, madeIds, parentIds, prevSelection })
|
|
|
81
81
|
forward: () => {
|
|
82
82
|
for (const { node } of plan) ctx.graph.deleteNode(node.id);
|
|
83
83
|
restoreAt(ctx, made);
|
|
84
|
-
|
|
84
|
+
ctx.runLayoutForParents(parentIds);
|
|
85
85
|
ctx.setSelectedIds(new Set(madeIds));
|
|
86
86
|
},
|
|
87
87
|
inverse: () => {
|
|
@@ -92,7 +92,7 @@ function pushOutlineUndo(ctx, { plan, made, madeIds, parentIds, prevSelection })
|
|
|
92
92
|
index,
|
|
93
93
|
snapshot
|
|
94
94
|
})));
|
|
95
|
-
|
|
95
|
+
ctx.runLayoutForParents(parentIds);
|
|
96
96
|
ctx.setSelectedIds(new Set(prevSelection));
|
|
97
97
|
}
|
|
98
98
|
});
|