UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

1 lines 2.92 kB
{"version":3,"file":"ActiveSelectionLayoutManager.mjs","names":[],"sources":["../../../src/LayoutManager/ActiveSelectionLayoutManager.ts"],"sourcesContent":["import { LayoutManager } from './LayoutManager';\nimport type { RegistrationContext, StrictLayoutContext } from './types';\nimport type { Group } from '../shapes/Group';\n\n/**\n * Today the LayoutManager class also takes care of subscribing event handlers\n * to update the group layout when the group is interactive and a transform is applied\n * to a child object.\n * The ActiveSelection is never interactive, but it could contain objects from\n * groups that are.\n * The standard LayoutManager would subscribe the children of the activeSelection to\n * perform layout changes to the active selection itself, what we need instead is that\n * the transformation applied to the active selection will trigger changes to the\n * original group of the children ( the one referenced under the parent property )\n * This subclass of the LayoutManager has a single duty to fill the gap of this difference.`\n */\nexport class ActiveSelectionLayoutManager extends LayoutManager {\n subscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>,\n ): void {\n const activeSelection = context.target;\n const parents = context.targets.reduce((parents, target) => {\n target.parent && parents.add(target.parent);\n return parents;\n }, new Set<Group>());\n parents.forEach((parent) => {\n parent.layoutManager.subscribeTargets({\n target: parent,\n targets: [activeSelection],\n });\n });\n }\n\n /**\n * unsubscribe from parent only if all its children were deselected\n */\n unsubscribeTargets(\n context: RegistrationContext & Partial<StrictLayoutContext>,\n ): void {\n const activeSelection = context.target;\n const selectedObjects = activeSelection.getObjects();\n const parents = context.targets.reduce((parents, target) => {\n target.parent && parents.add(target.parent);\n return parents;\n }, new Set<Group>());\n parents.forEach((parent) => {\n !selectedObjects.some((object) => object.parent === parent) &&\n parent.layoutManager.unsubscribeTargets({\n target: parent,\n targets: [activeSelection],\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,IAAa,+BAAb,cAAkD,cAAc;CAC9D,iBACE,SACM;EACN,MAAM,kBAAkB,QAAQ;AAChB,UAAQ,QAAQ,QAAQ,SAAS,WAAW;AAC1D,UAAO,UAAU,QAAQ,IAAI,OAAO,OAAO;AAC3C,UAAO;qBACN,IAAI,KAAY,CAAC,CACZ,SAAS,WAAW;AAC1B,UAAO,cAAc,iBAAiB;IACpC,QAAQ;IACR,SAAS,CAAC,gBAAgB;IAC3B,CAAC;IACF;;;;;CAMJ,mBACE,SACM;EACN,MAAM,kBAAkB,QAAQ;EAChC,MAAM,kBAAkB,gBAAgB,YAAY;AACpC,UAAQ,QAAQ,QAAQ,SAAS,WAAW;AAC1D,UAAO,UAAU,QAAQ,IAAI,OAAO,OAAO;AAC3C,UAAO;qBACN,IAAI,KAAY,CAAC,CACZ,SAAS,WAAW;AAC1B,IAAC,gBAAgB,MAAM,WAAW,OAAO,WAAW,OAAO,IACzD,OAAO,cAAc,mBAAmB;IACtC,QAAQ;IACR,SAAS,CAAC,gBAAgB;IAC3B,CAAC;IACJ"}