igniteui-webcomponents 5.3.0-RC.0 → 5.3.0-RC.1

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.
@@ -1,6 +1,10 @@
1
1
  import { getDefaultLayer } from '../../resize-container/default-ghost.js';
2
2
  import { findElementFromEventPath, getRoot, roundByDPR } from '../util.js';
3
- const additionalEvents = ['pointermove', 'lostpointercapture'];
3
+ const additionalEvents = [
4
+ 'pointermove',
5
+ 'lostpointercapture',
6
+ 'contextmenu',
7
+ ];
4
8
  class DragController {
5
9
  get _hasSnapping() {
6
10
  return Boolean(this._options.snapToCursor);
@@ -71,6 +75,7 @@ class DragController {
71
75
  switch (event.type) {
72
76
  case 'touchstart':
73
77
  case 'dragstart':
78
+ case 'contextmenu':
74
79
  event.preventDefault();
75
80
  break;
76
81
  case 'keydown':
@@ -96,7 +101,7 @@ class DragController {
96
101
  this._updatePosition(event);
97
102
  const parameters = { event, state: this._stateParameters };
98
103
  if (this._options.start?.call(this._host, parameters) === false) {
99
- this._removeGhost();
104
+ this.dispose();
100
105
  return;
101
106
  }
102
107
  this._assignPosition(this._dragItem);
@@ -1 +1 @@
1
- {"version":3,"file":"drag.js","sourceRoot":"","sources":["../../../../src/components/common/controllers/drag.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAgF3E,MAAM,gBAAgB,GAAG,CAAC,aAAa,EAAE,oBAAoB,CAAU,CAAC;AAExE,MAAM,cAAc;IAmBlB,IAAY,YAAY;QACtB,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;IAGD,IAAY,WAAW;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAC;IAC3C,CAAC;IAQD,IAAY,QAAQ;Q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Q,EAAE,KAAK,CAAC,CAC7D,CAAC;IACJ,CAAC;CACF;AAED,SAAS,sBAAsB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAW;IAC9D,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAE9C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;QAC3B,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,GAAG,EAAE,GAAG,CAAC,IAAI;QACb,KAAK,EAAE,GAAG,KAAK,IAAI;QACnB,MAAM,EAAE,GAAG,MAAM,IAAI;QACrB,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,MAAM;KACnB,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC;AAKD,MAAM,UAAU,iBAAiB,CAC/B,IAAyC,EACzC,OAAqC;IAErC,OAAO,IAAI,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import type {\n LitElement,\n ReactiveController,\n ReactiveControllerHost,\n} from 'lit';\nimport type { Ref } from 'lit/directives/ref.js';\n\nimport { getDefaultLayer } from '../../resize-container/default-ghost.js';\nimport { findElementFromEventPath, getRoot, roundByDPR } from '../util.js';\n\ntype DragCallback = (parameters: DragCallbackParameters) => unknown;\ntype DragCancelCallback = (state: DragState) => unknown;\n\nexport type DragCallbackParameters = {\n event: PointerEvent;\n state: DragState;\n};\n\ntype State = {\n initial: DOMRect;\n current: DOMRect;\n position: { x: number; y: number };\n offset: { x: number; y: number };\n};\n\ntype DragState = State & {\n ghost: HTMLElement | null;\n element: Element | null;\n};\n\ntype DragControllerConfiguration = {\n /** Whether the drag feature is enabled for the current host. */\n enabled?: boolean;\n /**\n * The mode of the drag operation.\n *\n * Deferred will create a ghost element and keep the original element\n * at its place until the operation completes successfully.\n */\n mode?: 'immediate' | 'deferred';\n /**\n * Whether starting a drag operation should snap the dragged item's top left corner\n * to the cursor position.\n */\n snapToCursor?: boolean;\n /**\n * Guard function invoked during the `start` callback.\n * Returning a truthy value will stop the current drag operation.\n */\n skip?: (event: PointerEvent) => boolean;\n\n matchTarget?: (target: Element) => boolean;\n /**\n *\n */\n trigger?: () => HTMLElement;\n /**\n * Contain drag operations to the scope of the passed DOM element.\n */\n container?: Ref<HTMLElement>;\n /**\n * The DOM element that will \"host\" the ghost drag element when the controller\n * is set to **deferred**.\n *\n * @remarks\n * In **immediate** mode, this property is ignored.\n */\n layer?: () => HTMLElement;\n\n ghost?: () => HTMLElement;\n\n /** Callback invoked at the beginning of a drag operation. */\n start?: DragCallback;\n /** Callback invoked while dragging the target element. */\n move?: DragCallback;\n\n enter?: DragCallback;\n\n leave?: DragCallback;\n\n over?: DragCallback;\n\n /** Callback invoked during a drop operation. */\n end?: DragCallback;\n /** Callback invoked when a drag is cancelled */\n cancel?: DragCancelCallback;\n};\n\nconst additionalEvents = ['pointermove', 'lostpointercapture'] as const;\n\nclass DragController implements ReactiveController {\n private _host: ReactiveControllerHost & LitElement;\n private _options: DragControllerConfiguration = {\n enabled: true,\n mode: 'deferred',\n snapToCursor: false,\n layer: getDefaultLayer,\n };\n\n private _state!: State;\n\n private _matchedElement!: Element | null;\n\n private _id = -1;\n private _hasPointerCapture = false;\n\n private _ghost: HTMLElement | null = null;\n\n /** Whether `snapToCursor` is enabled for the controller. */\n private get _hasSnapping(): boolean {\n return Boolean(this._options.snapToCursor);\n }\n\n /** Whether the current drag mode is deferred. */\n private get _isDeferred(): boolean {\n return this._options.mode === 'deferred';\n }\n\n /**\n * The source element which will capture pointer events and initiate drag mode.\n *\n * @remarks\n * By default that will be the host element itself, unless `trigger` is passed in.\n */\n private get _element(): HTMLElement {\n return this._options.trigger?.() ?? this._host;\n }\n\n /**\n * The element being dragged.\n *\n * @remarks\n * When in **deferred** mode this returns a reference to the drag ghost element,\n * otherwise it is the host element.\n */\n private get _dragItem(): HTMLElement {\n return this._isDeferred ? this._ghost! : this._host;\n }\n\n /**\n * The DOM element that will \"host\" the ghost drag element when the controller\n * is set to **deferred**.\n *\n * @remarks\n * In **immediate** mode, this property is ignored.\n */\n private get _layer(): HTMLElement {\n if (!this._isDeferred) {\n return this._host;\n }\n\n return this._options.layer?.() ?? this._host;\n }\n\n private get _stateParameters(): DragState {\n return {\n ...this._state,\n ghost: this._ghost,\n element: this._matchedElement,\n };\n }\n\n constructor(\n host: ReactiveControllerHost & LitElement,\n options?: DragControllerConfiguration\n ) {\n this._host = host;\n this._host.addController(this);\n this.set(options);\n }\n\n // #region Public API\n\n /** Whether the drag controller is enabled. */\n public get enabled(): boolean {\n return Boolean(this._options.enabled);\n }\n\n /** Updates the drag controller configuration. */\n public set(options?: DragControllerConfiguration): void {\n Object.assign(this._options, options);\n }\n\n /** Stops any drag operation and cleans up state, additional event listeners and elements. */\n public dispose(): void {\n this._matchedElement = null;\n this._removeGhost();\n this._setDragState(false);\n }\n\n /** @internal */\n public hostConnected(): void {\n this._host.addEventListener('dragstart', this);\n this._host.addEventListener('touchstart', this, { passive: false });\n this._host.addEventListener('pointerdown', this);\n }\n\n /** @internal */\n public hostDisconnected(): void {\n this._host.removeEventListener('dragstart', this);\n this._host.removeEventListener('touchstart', this);\n this._host.removeEventListener('pointerdown', this);\n this._setDragCancelListener(false);\n this._removeGhost();\n }\n\n /** @internal */\n public handleEvent(event: PointerEvent & KeyboardEvent): void {\n if (!this.enabled) {\n return;\n }\n\n switch (event.type) {\n case 'touchstart':\n case 'dragstart':\n event.preventDefault();\n break;\n case 'keydown':\n this._handleCancel(event);\n break;\n case 'pointerdown':\n this._handlePointerDown(event);\n break;\n case 'pointermove':\n this._handlePointerMove(event);\n break;\n case 'lostpointercapture':\n this._handlePointerEnd(event);\n break;\n }\n }\n\n // #endregion\n\n // #region Event handlers\n\n private _handlePointerDown(event: PointerEvent): void {\n if (this._shouldSkip(event)) {\n return;\n }\n\n this._setInitialState(event);\n this._createDragGhost();\n this._updatePosition(event);\n\n const parameters = { event, state: this._stateParameters };\n if (this._options.start?.call(this._host, parameters) === false) {\n this._removeGhost();\n return;\n }\n\n this._assignPosition(this._dragItem);\n this._setDragState();\n }\n\n private _handlePointerMove(event: PointerEvent): void {\n if (!this._hasPointerCapture) {\n return;\n }\n\n this._updatePosition(event);\n this._updateMatcher(event);\n\n const parameters = { event, state: this._stateParameters };\n this._options.move?.call(this._host, parameters);\n\n this._assignPosition(this._dragItem);\n }\n\n private _handlePointerEnd(event: PointerEvent): void {\n this._options.end?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n this.dispose();\n }\n\n private _handleCancel(event: KeyboardEvent): void {\n const key = event.key.toLowerCase();\n\n if (this._hasPointerCapture && key === 'escape') {\n // Reset state\n this._options.cancel?.call(this._host, this._stateParameters);\n }\n }\n\n // #endregion\n\n private _setDragCancelListener(enabled = true): void {\n enabled\n ? globalThis.addEventListener('keydown', this)\n : globalThis.removeEventListener('keydown', this);\n }\n\n private _setInitialState({\n pointerId,\n clientX,\n clientY,\n }: PointerEvent): void {\n const rect = this._host.getBoundingClientRect();\n const position = { x: rect.x, y: rect.y };\n const offset = { x: rect.x - clientX, y: rect.y - clientY };\n\n this._id = pointerId;\n this._state = {\n initial: rect,\n current: structuredClone(rect),\n position,\n offset,\n };\n }\n\n private _setDragState(enabled = true): void {\n this._hasPointerCapture = enabled;\n const cssValue = enabled ? 'none' : '';\n\n Object.assign(this._element.style, {\n touchAction: cssValue,\n userSelect: cssValue,\n });\n\n enabled\n ? this._element.setPointerCapture(this._id)\n : this._element.releasePointerCapture(this._id);\n\n this._setDragCancelListener(enabled);\n\n // Toggle additional events\n for (const type of additionalEvents) {\n enabled\n ? this._host.addEventListener(type, this)\n : this._host.removeEventListener(type, this);\n }\n }\n\n private _updateMatcher(event: PointerEvent) {\n if (!this._options.matchTarget) {\n return;\n }\n\n const match = getRoot(this._host)\n .elementsFromPoint(event.clientX, event.clientY)\n .find((element) => this._options.matchTarget!.call(this._host, element));\n\n if (match && !this._matchedElement) {\n this._matchedElement = match;\n this._options.enter?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n return;\n }\n\n if (!match && this._matchedElement) {\n this._options.leave?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n this._matchedElement = null;\n return;\n }\n\n if (match && match === this._matchedElement) {\n this._options.over?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n }\n }\n\n private _updatePosition({ clientX, clientY }: PointerEvent): void {\n const { x, y } = this._state.offset;\n const { x: layerX, y: layerY } = this._isDeferred\n ? this._layer.getBoundingClientRect()\n : this._state.initial;\n\n const posX = this._hasSnapping ? clientX - layerX : clientX - layerX + x;\n const posY = this._hasSnapping ? clientY - layerY : clientY - layerY + y;\n\n Object.assign(this._state.position, { x: posX, y: posY });\n }\n\n private _assignPosition(element: HTMLElement): void {\n element.style.transform = `translate3d(${roundByDPR(this._state.position.x)}px,${roundByDPR(this._state.position.y)}px,0)`;\n }\n\n private _createDragGhost(): void {\n if (!this._isDeferred) {\n return;\n }\n\n this._ghost =\n this._options.ghost?.call(this._host) ??\n createDefaultDragGhost(this._host.getBoundingClientRect());\n\n this._layer.append(this._ghost);\n }\n\n private _removeGhost(): void {\n this._ghost?.remove();\n this._ghost = null;\n }\n\n private _shouldSkip(event: PointerEvent): boolean {\n return (\n Boolean(event.button) ||\n this._options.skip?.call(this._host, event) ||\n !findElementFromEventPath((e) => e === this._element, event)\n );\n }\n}\n\nfunction createDefaultDragGhost({ x, y, width, height }: DOMRect): HTMLElement {\n const element = document.createElement('div');\n\n Object.assign(element.style, {\n position: 'absolute',\n left: `${x}px`,\n top: `${y}px`,\n width: `${width}px`,\n height: `${height}px`,\n zIndex: 1000,\n background: 'gold',\n });\n\n return element;\n}\n\n/**\n * Adds a drag and drop controller to the given host\n */\nexport function addDragController(\n host: ReactiveControllerHost & LitElement,\n options?: DragControllerConfiguration\n): DragController {\n return new DragController(host, options);\n}\n"]}
1
+ {"version":3,"file":"drag.js","sourceRoot":"","sources":["../../../../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.js';\n\nimport { getDefaultLayer } from '../../resize-container/default-ghost.js';\nimport { findElementFromEventPath, getRoot, roundByDPR } from '../util.js';\n\ntype DragCallback = (parameters: DragCallbackParameters) => unknown;\ntype DragCancelCallback = (state: DragState) => unknown;\n\nexport type DragCallbackParameters = {\n event: PointerEvent;\n state: DragState;\n};\n\ntype State = {\n initial: DOMRect;\n current: DOMRect;\n position: { x: number; y: number };\n offset: { x: number; y: number };\n};\n\ntype DragState = State & {\n ghost: HTMLElement | null;\n element: Element | null;\n};\n\ntype DragControllerConfiguration = {\n /** Whether the drag feature is enabled for the current host. */\n enabled?: boolean;\n /**\n * The mode of the drag operation.\n *\n * Deferred will create a ghost element and keep the original element\n * at its place until the operation completes successfully.\n */\n mode?: 'immediate' | 'deferred';\n /**\n * Whether starting a drag operation should snap the dragged item's top left corner\n * to the cursor position.\n */\n snapToCursor?: boolean;\n /**\n * Guard function invoked during the `start` callback.\n * Returning a truthy value will stop the current drag operation.\n */\n skip?: (event: PointerEvent) => boolean;\n\n matchTarget?: (target: Element) => boolean;\n /**\n *\n */\n trigger?: () => HTMLElement;\n /**\n * Contain drag operations to the scope of the passed DOM element.\n */\n container?: Ref<HTMLElement>;\n /**\n * The DOM element that will \"host\" the ghost drag element when the controller\n * is set to **deferred**.\n *\n * @remarks\n * In **immediate** mode, this property is ignored.\n */\n layer?: () => HTMLElement;\n\n ghost?: () => HTMLElement;\n\n /** Callback invoked at the beginning of a drag operation. */\n start?: DragCallback;\n /** Callback invoked while dragging the target element. */\n move?: DragCallback;\n\n enter?: DragCallback;\n\n leave?: DragCallback;\n\n over?: DragCallback;\n\n /** Callback invoked during a drop operation. */\n end?: DragCallback;\n /** Callback invoked when a drag is cancelled */\n cancel?: DragCancelCallback;\n};\n\nconst additionalEvents = [\n 'pointermove',\n 'lostpointercapture',\n 'contextmenu',\n] as const;\n\nclass DragController implements ReactiveController {\n private _host: ReactiveControllerHost & LitElement;\n private _options: DragControllerConfiguration = {\n enabled: true,\n mode: 'deferred',\n snapToCursor: false,\n layer: getDefaultLayer,\n };\n\n private _state!: State;\n\n private _matchedElement!: Element | null;\n\n private _id = -1;\n private _hasPointerCapture = false;\n\n private _ghost: HTMLElement | null = null;\n\n /** Whether `snapToCursor` is enabled for the controller. */\n private get _hasSnapping(): boolean {\n return Boolean(this._options.snapToCursor);\n }\n\n /** Whether the current drag mode is deferred. */\n private get _isDeferred(): boolean {\n return this._options.mode === 'deferred';\n }\n\n /**\n * The source element which will capture pointer events and initiate drag mode.\n *\n * @remarks\n * By default that will be the host element itself, unless `trigger` is passed in.\n */\n private get _element(): HTMLElement {\n return this._options.trigger?.() ?? this._host;\n }\n\n /**\n * The element being dragged.\n *\n * @remarks\n * When in **deferred** mode this returns a reference to the drag ghost element,\n * otherwise it is the host element.\n */\n private get _dragItem(): HTMLElement {\n return this._isDeferred ? this._ghost! : this._host;\n }\n\n /**\n * The DOM element that will \"host\" the ghost drag element when the controller\n * is set to **deferred**.\n *\n * @remarks\n * In **immediate** mode, this property is ignored.\n */\n private get _layer(): HTMLElement {\n if (!this._isDeferred) {\n return this._host;\n }\n\n return this._options.layer?.() ?? this._host;\n }\n\n private get _stateParameters(): DragState {\n return {\n ...this._state,\n ghost: this._ghost,\n element: this._matchedElement,\n };\n }\n\n constructor(\n host: ReactiveControllerHost & LitElement,\n options?: DragControllerConfiguration\n ) {\n this._host = host;\n this._host.addController(this);\n this.set(options);\n }\n\n // #region Public API\n\n /** Whether the drag controller is enabled. */\n public get enabled(): boolean {\n return Boolean(this._options.enabled);\n }\n\n /** Updates the drag controller configuration. */\n public set(options?: DragControllerConfiguration): void {\n Object.assign(this._options, options);\n }\n\n /** Stops any drag operation and cleans up state, additional event listeners and elements. */\n public dispose(): void {\n this._matchedElement = null;\n this._removeGhost();\n this._setDragState(false);\n }\n\n /** @internal */\n public hostConnected(): void {\n this._host.addEventListener('dragstart', this);\n this._host.addEventListener('touchstart', this, { passive: false });\n this._host.addEventListener('pointerdown', this);\n }\n\n /** @internal */\n public hostDisconnected(): void {\n this._host.removeEventListener('dragstart', this);\n this._host.removeEventListener('touchstart', this);\n this._host.removeEventListener('pointerdown', this);\n this._setDragCancelListener(false);\n this._removeGhost();\n }\n\n /** @internal */\n public handleEvent(event: PointerEvent & KeyboardEvent): void {\n if (!this.enabled) {\n return;\n }\n\n switch (event.type) {\n case 'touchstart':\n case 'dragstart':\n // Prevent contextmenu default behavior during drag\n case 'contextmenu':\n event.preventDefault();\n break;\n case 'keydown':\n this._handleCancel(event);\n break;\n case 'pointerdown':\n this._handlePointerDown(event);\n break;\n case 'pointermove':\n this._handlePointerMove(event);\n break;\n case 'lostpointercapture':\n this._handlePointerEnd(event);\n break;\n }\n }\n\n // #endregion\n\n // #region Event handlers\n\n private _handlePointerDown(event: PointerEvent): void {\n if (this._shouldSkip(event)) {\n return;\n }\n\n this._setInitialState(event);\n this._createDragGhost();\n this._updatePosition(event);\n\n const parameters = { event, state: this._stateParameters };\n if (this._options.start?.call(this._host, parameters) === false) {\n this.dispose();\n return;\n }\n\n this._assignPosition(this._dragItem);\n this._setDragState();\n }\n\n private _handlePointerMove(event: PointerEvent): void {\n if (!this._hasPointerCapture) {\n return;\n }\n\n this._updatePosition(event);\n this._updateMatcher(event);\n\n const parameters = { event, state: this._stateParameters };\n this._options.move?.call(this._host, parameters);\n\n this._assignPosition(this._dragItem);\n }\n\n private _handlePointerEnd(event: PointerEvent): void {\n this._options.end?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n this.dispose();\n }\n\n private _handleCancel(event: KeyboardEvent): void {\n const key = event.key.toLowerCase();\n\n if (this._hasPointerCapture && key === 'escape') {\n // Reset state\n this._options.cancel?.call(this._host, this._stateParameters);\n }\n }\n\n // #endregion\n\n private _setDragCancelListener(enabled = true): void {\n enabled\n ? globalThis.addEventListener('keydown', this)\n : globalThis.removeEventListener('keydown', this);\n }\n\n private _setInitialState({\n pointerId,\n clientX,\n clientY,\n }: PointerEvent): void {\n const rect = this._host.getBoundingClientRect();\n const position = { x: rect.x, y: rect.y };\n const offset = { x: rect.x - clientX, y: rect.y - clientY };\n\n this._id = pointerId;\n this._state = {\n initial: rect,\n current: structuredClone(rect),\n position,\n offset,\n };\n }\n\n private _setDragState(enabled = true): void {\n this._hasPointerCapture = enabled;\n const cssValue = enabled ? 'none' : '';\n\n Object.assign(this._element.style, {\n touchAction: cssValue,\n userSelect: cssValue,\n });\n\n enabled\n ? this._element.setPointerCapture(this._id)\n : this._element.releasePointerCapture(this._id);\n\n this._setDragCancelListener(enabled);\n\n // Toggle additional events\n for (const type of additionalEvents) {\n enabled\n ? this._host.addEventListener(type, this)\n : this._host.removeEventListener(type, this);\n }\n }\n\n private _updateMatcher(event: PointerEvent) {\n if (!this._options.matchTarget) {\n return;\n }\n\n const match = getRoot(this._host)\n .elementsFromPoint(event.clientX, event.clientY)\n .find((element) => this._options.matchTarget!.call(this._host, element));\n\n if (match && !this._matchedElement) {\n this._matchedElement = match;\n this._options.enter?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n return;\n }\n\n if (!match && this._matchedElement) {\n this._options.leave?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n this._matchedElement = null;\n return;\n }\n\n if (match && match === this._matchedElement) {\n this._options.over?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n }\n }\n\n private _updatePosition({ clientX, clientY }: PointerEvent): void {\n const { x, y } = this._state.offset;\n const { x: layerX, y: layerY } = this._isDeferred\n ? this._layer.getBoundingClientRect()\n : this._state.initial;\n\n const posX = this._hasSnapping ? clientX - layerX : clientX - layerX + x;\n const posY = this._hasSnapping ? clientY - layerY : clientY - layerY + y;\n\n Object.assign(this._state.position, { x: posX, y: posY });\n }\n\n private _assignPosition(element: HTMLElement): void {\n element.style.transform = `translate3d(${roundByDPR(this._state.position.x)}px,${roundByDPR(this._state.position.y)}px,0)`;\n }\n\n private _createDragGhost(): void {\n if (!this._isDeferred) {\n return;\n }\n\n this._ghost =\n this._options.ghost?.call(this._host) ??\n createDefaultDragGhost(this._host.getBoundingClientRect());\n\n this._layer.append(this._ghost);\n }\n\n private _removeGhost(): void {\n this._ghost?.remove();\n this._ghost = null;\n }\n\n private _shouldSkip(event: PointerEvent): boolean {\n return (\n Boolean(event.button) ||\n this._options.skip?.call(this._host, event) ||\n !findElementFromEventPath((e) => e === this._element, event)\n );\n }\n}\n\nfunction createDefaultDragGhost({ x, y, width, height }: DOMRect): HTMLElement {\n const element = document.createElement('div');\n\n Object.assign(element.style, {\n position: 'absolute',\n left: `${x}px`,\n top: `${y}px`,\n width: `${width}px`,\n height: `${height}px`,\n zIndex: 1000,\n background: 'gold',\n });\n\n return element;\n}\n\n/**\n * Adds a drag and drop controller to the given host\n */\nexport function addDragController(\n host: ReactiveControllerHost & LitElement,\n options?: DragControllerConfiguration\n): DragController {\n return new DragController(host, options);\n}\n"]}
@@ -80,7 +80,11 @@ let IgcResizeContainerComponent = IgcResizeContainerComponent_1 = class IgcResiz
80
80
  }
81
81
  _handleResizeStart(params) {
82
82
  params.event.preventDefault();
83
- this.emitEvent('igcResizeStart', { bubbles: false, detail: params });
83
+ return this.emitEvent('igcResizeStart', {
84
+ bubbles: false,
85
+ cancelable: true,
86
+ detail: params,
87
+ });
84
88
  }
85
89
  _handleResize(params) {
86
90
  this._updateResizingState(params);
@@ -1 +1 @@
1
- {"version":3,"file":"resize-container.js","sourceRoot":"","sources":["../../../src/components/resize-container/resize-container.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAY,SAAS,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAm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AC,GAAG,CAAC;GACS,2BAA2B,CAiK/C;eAjKoB,2BAA2B","sourcesContent":["import { LitElement, html, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { type Ref, createRef, ref } from 'lit/directives/ref.js';\n\nimport { themes } from '../../theming/theming-decorator.js';\nimport { registerComponent } from '../common/definitions/register.js';\nimport type { Constructor } from '../common/mixins/constructor.js';\nimport { EventEmitterMixin } from '../common/mixins/event-emitter.js';\nimport { partNameMap } from '../common/util.js';\nimport IgcIconComponent from '../icon/icon.js';\nimport { addResizeController } from './resize-controller.js';\nimport { styles } from './themes/resize-container.base.css.js';\nimport { styles as shared } from './themes/shared/resize-container.common.css.js';\nimport { all } from './themes/themes.js';\nimport type {\n ResizeCallbackParams,\n ResizeGhostFactory,\n ResizeMode,\n ResizeState,\n} from './types.js';\n\nexport interface IgcResizeContainerComponentEventMap {\n igcResizeStart: CustomEvent<ResizeCallbackParams>;\n igcResize: CustomEvent<ResizeCallbackParams>;\n igcResizeEnd: CustomEvent<ResizeCallbackParams>;\n igcResizeCancel: CustomEvent<unknown>;\n}\n\n/* blazorSuppress */\n/**\n * @element igc-resize\n *\n * @slot - renders the element(s) that should be resized\n * @slot side-adorner - renders the side resize handle.\n * @slot corner-adorner - renders the corner resize handle.\n * @slot bottom-adorner - renders the bottom resize handle.\n *\n */\n@themes(all)\nexport default class IgcResizeContainerComponent extends EventEmitterMixin<\n IgcResizeContainerComponentEventMap,\n Constructor<LitElement>\n>(LitElement) {\n public static readonly tagName = 'igc-resize';\n public static styles = [styles, shared];\n\n /* blazorSuppress */\n public static register(): void {\n registerComponent(IgcResizeContainerComponent, IgcIconComponent);\n }\n\n private _controller: ReturnType<typeof addResizeController>;\n\n private _mode: ResizeMode = 'immediate';\n private _ghostFactory?: ResizeGhostFactory;\n\n /** The DOM container doing the actual resizing */\n private _container: Ref<HTMLElement> = createRef();\n\n /** Resize component adorners */\n private _adorners: Record<'side' | 'corner' | 'bottom', Ref<HTMLElement>> = {\n side: createRef(),\n corner: createRef(),\n bottom: createRef(),\n };\n\n @state()\n private _isActive = false;\n\n /**\n * Whether to always show the resize element adorners.\n */\n @property({ type: Boolean, reflect: true })\n public active = false;\n\n @property({ attribute: false })\n public set ghostFactory(value: ResizeGhostFactory) {\n this._ghostFactory = value;\n this._controller.set({ deferredFactory: this._ghostFactory });\n }\n\n public get ghostFactory(): ResizeGhostFactory | undefined {\n return this._ghostFactory;\n }\n\n /** Get/Set the mode of the resizing operation. */\n @property()\n public set mode(value: ResizeMode) {\n this._mode = value;\n this._controller.set({ mode: this._mode });\n }\n\n public get mode(): ResizeMode {\n return this._mode;\n }\n\n constructor() {\n super();\n\n this._controller = addResizeController(this, {\n ref: [this._adorners.side, this._adorners.corner, this._adorners.bottom],\n mode: this._mode,\n deferredFactory: this._ghostFactory,\n start: this._handleResizeStart,\n resize: this._handleResize,\n end: this._handleResizeEnd,\n cancel: this._handleResizeCancel,\n resizeTarget: () => this._container.value!,\n });\n }\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const root = super.createRenderRoot();\n root.addEventListener('slotchange', () => this.requestUpdate());\n return root;\n }\n\n private _updateResizingState(params: ResizeCallbackParams): void {\n const { initial, current, trigger } = params.state;\n const { side, bottom } = this._adorners;\n\n if (trigger === side.value) {\n current.height = initial.height;\n } else if (trigger === bottom.value) {\n current.width = initial.width;\n }\n }\n\n private _handlePointerEnter(): void {\n this._isActive = true;\n }\n\n private _handlePointerLeave(): void {\n this._isActive = false;\n }\n\n private _handleResizeStart(params: ResizeCallbackParams): void {\n params.event.preventDefault();\n this.emitEvent('igcResizeStart', { bubbles: false, detail: params });\n }\n\n private _handleResize(params: ResizeCallbackParams): void {\n this._updateResizingState(params);\n this.emitEvent('igcResize', { bubbles: false, detail: params });\n }\n\n private _handleResizeEnd(params: ResizeCallbackParams): void {\n this.emitEvent('igcResizeEnd', { bubbles: false, detail: params });\n }\n\n private _handleResizeCancel({ initial }: ResizeState): void {\n this._controller.dispose();\n\n if (this.mode !== 'deferred') {\n Object.assign(this._container.value!.style, {\n width: `${initial.width}px`,\n height: `${initial.height}px`,\n });\n }\n\n this.emitEvent('igcResizeCancel', { bubbles: false, cancelable: false });\n }\n\n protected _renderAdorner(name: 'side' | 'corner' | 'bottom', part: string) {\n return html`\n <slot ${ref(this._adorners[name])} part=${part} name=\"${name}-adorner\">\n </slot>\n `;\n }\n\n protected _renderAdorners() {\n if (!this._isActive && !this.active) {\n return nothing;\n }\n\n return html`\n ${this._renderAdorner('side', 'trigger-side')}\n ${this._renderAdorner('corner', 'trigger')}\n ${this._renderAdorner('bottom', 'trigger-bottom')}\n `;\n }\n\n protected override render() {\n const parts = partNameMap({\n 'resize-base': true,\n active: this._isActive || this.active,\n });\n\n return html`\n <div\n ${ref(this._container)}\n part=${parts}\n @pointerenter=${this.active ? nothing : this._handlePointerEnter}\n @pointerleave=${this.active ? nothing : this._handlePointerLeave}\n >\n <slot></slot>\n ${this._renderAdorners()}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'igc-resize': IgcResizeContainerComponent;\n }\n}\n"]}
1
+ {"version":3,"file":"resize-container.js","sourceRoot":"","sources":["../../../src/components/resize-container/resize-container.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAY,SAAS,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,gBAAgB,MAAM,iBAAiB,CAAC;AAC/C,OAA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it';\nimport { property, state } from 'lit/decorators.js';\nimport { type Ref, createRef, ref } from 'lit/directives/ref.js';\n\nimport { themes } from '../../theming/theming-decorator.js';\nimport { registerComponent } from '../common/definitions/register.js';\nimport type { Constructor } from '../common/mixins/constructor.js';\nimport { EventEmitterMixin } from '../common/mixins/event-emitter.js';\nimport { partNameMap } from '../common/util.js';\nimport IgcIconComponent from '../icon/icon.js';\nimport { addResizeController } from './resize-controller.js';\nimport { styles } from './themes/resize-container.base.css.js';\nimport { styles as shared } from './themes/shared/resize-container.common.css.js';\nimport { all } from './themes/themes.js';\nimport type {\n ResizeCallbackParams,\n ResizeGhostFactory,\n ResizeMode,\n ResizeState,\n} from './types.js';\n\nexport interface IgcResizeContainerComponentEventMap {\n igcResizeStart: CustomEvent<ResizeCallbackParams>;\n igcResize: CustomEvent<ResizeCallbackParams>;\n igcResizeEnd: CustomEvent<ResizeCallbackParams>;\n igcResizeCancel: CustomEvent<unknown>;\n}\n\n/* blazorSuppress */\n/**\n * @element igc-resize\n *\n * @slot - renders the element(s) that should be resized\n * @slot side-adorner - renders the side resize handle.\n * @slot corner-adorner - renders the corner resize handle.\n * @slot bottom-adorner - renders the bottom resize handle.\n *\n */\n@themes(all)\nexport default class IgcResizeContainerComponent extends EventEmitterMixin<\n IgcResizeContainerComponentEventMap,\n Constructor<LitElement>\n>(LitElement) {\n public static readonly tagName = 'igc-resize';\n public static styles = [styles, shared];\n\n /* blazorSuppress */\n public static register(): void {\n registerComponent(IgcResizeContainerComponent, IgcIconComponent);\n }\n\n private _controller: ReturnType<typeof addResizeController>;\n\n private _mode: ResizeMode = 'immediate';\n private _ghostFactory?: ResizeGhostFactory;\n\n /** The DOM container doing the actual resizing */\n private _container: Ref<HTMLElement> = createRef();\n\n /** Resize component adorners */\n private _adorners: Record<'side' | 'corner' | 'bottom', Ref<HTMLElement>> = {\n side: createRef(),\n corner: createRef(),\n bottom: createRef(),\n };\n\n @state()\n private _isActive = false;\n\n /**\n * Whether to always show the resize element adorners.\n */\n @property({ type: Boolean, reflect: true })\n public active = false;\n\n @property({ attribute: false })\n public set ghostFactory(value: ResizeGhostFactory) {\n this._ghostFactory = value;\n this._controller.set({ deferredFactory: this._ghostFactory });\n }\n\n public get ghostFactory(): ResizeGhostFactory | undefined {\n return this._ghostFactory;\n }\n\n /** Get/Set the mode of the resizing operation. */\n @property()\n public set mode(value: ResizeMode) {\n this._mode = value;\n this._controller.set({ mode: this._mode });\n }\n\n public get mode(): ResizeMode {\n return this._mode;\n }\n\n constructor() {\n super();\n\n this._controller = addResizeController(this, {\n ref: [this._adorners.side, this._adorners.corner, this._adorners.bottom],\n mode: this._mode,\n deferredFactory: this._ghostFactory,\n start: this._handleResizeStart,\n resize: this._handleResize,\n end: this._handleResizeEnd,\n cancel: this._handleResizeCancel,\n resizeTarget: () => this._container.value!,\n });\n }\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const root = super.createRenderRoot();\n root.addEventListener('slotchange', () => this.requestUpdate());\n return root;\n }\n\n private _updateResizingState(params: ResizeCallbackParams): void {\n const { initial, current, trigger } = params.state;\n const { side, bottom } = this._adorners;\n\n if (trigger === side.value) {\n current.height = initial.height;\n } else if (trigger === bottom.value) {\n current.width = initial.width;\n }\n }\n\n private _handlePointerEnter(): void {\n this._isActive = true;\n }\n\n private _handlePointerLeave(): void {\n this._isActive = false;\n }\n\n private _handleResizeStart(params: ResizeCallbackParams) {\n params.event.preventDefault();\n\n return this.emitEvent('igcResizeStart', {\n bubbles: false,\n cancelable: true,\n detail: params,\n });\n }\n\n private _handleResize(params: ResizeCallbackParams): void {\n this._updateResizingState(params);\n this.emitEvent('igcResize', { bubbles: false, detail: params });\n }\n\n private _handleResizeEnd(params: ResizeCallbackParams): void {\n this.emitEvent('igcResizeEnd', { bubbles: false, detail: params });\n }\n\n private _handleResizeCancel({ initial }: ResizeState): void {\n this._controller.dispose();\n\n if (this.mode !== 'deferred') {\n Object.assign(this._container.value!.style, {\n width: `${initial.width}px`,\n height: `${initial.height}px`,\n });\n }\n\n this.emitEvent('igcResizeCancel', { bubbles: false, cancelable: false });\n }\n\n protected _renderAdorner(name: 'side' | 'corner' | 'bottom', part: string) {\n return html`\n <slot ${ref(this._adorners[name])} part=${part} name=\"${name}-adorner\">\n </slot>\n `;\n }\n\n protected _renderAdorners() {\n if (!this._isActive && !this.active) {\n return nothing;\n }\n\n return html`\n ${this._renderAdorner('side', 'trigger-side')}\n ${this._renderAdorner('corner', 'trigger')}\n ${this._renderAdorner('bottom', 'trigger-bottom')}\n `;\n }\n\n protected override render() {\n const parts = partNameMap({\n 'resize-base': true,\n active: this._isActive || this.active,\n });\n\n return html`\n <div\n ${ref(this._container)}\n part=${parts}\n @pointerenter=${this.active ? nothing : this._handlePointerEnter}\n @pointerleave=${this.active ? nothing : this._handlePointerLeave}\n >\n <slot></slot>\n ${this._renderAdorners()}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'igc-resize': IgcResizeContainerComponent;\n }\n}\n"]}
@@ -1,6 +1,10 @@
1
1
  import { findElementFromEventPath } from '../common/util.js';
2
2
  import { createDefaultGhostElement, getDefaultLayer } from './default-ghost.js';
3
- const additionalEvents = ['pointermove', 'lostpointercapture'];
3
+ const additionalEvents = [
4
+ 'pointermove',
5
+ 'lostpointercapture',
6
+ 'contextmenu',
7
+ ];
4
8
  class ResizeController {
5
9
  get _element() {
6
10
  return this._activeRef ?? this._host;
@@ -68,6 +72,7 @@ class ResizeController {
68
72
  }
69
73
  switch (event.type) {
70
74
  case 'touchstart':
75
+ case 'contextmenu':
71
76
  event.preventDefault();
72
77
  break;
73
78
  case 'keydown':
@@ -90,10 +95,11 @@ class ResizeController {
90
95
  }
91
96
  this._setInitialState(event);
92
97
  this._createGhostElement();
93
- this._options.start?.call(this._host, {
94
- event,
95
- state: this._stateParameters,
96
- });
98
+ const parameters = { event, state: this._stateParameters };
99
+ if (this._options.start?.call(this._host, parameters) === false) {
100
+ this.dispose();
101
+ return;
102
+ }
97
103
  this._setResizeState();
98
104
  }
99
105
  _handlePointerMove(event) {
@@ -110,6 +116,7 @@ class ResizeController {
110
116
  const parameters = { event, state: this._stateParameters };
111
117
  this._options.end?.call(this._host, parameters);
112
118
  this._state.current = parameters.state.current;
119
+ parameters.state.commit?.() ?? this._updatePosition(this._resizeTarget);
113
120
  this.dispose();
114
121
  }
115
122
  _handleCancel(event) {
@@ -1 +1 @@
1
- {"version":3,"file":"resize-controller.js","sourceRoot":"","sources":["../../../src/components/resize-container/resize-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGhF,MAAM,gBAAgB,GAAG,CAAC,aAAa,EAAE,oBAAoB,CAAU,CAAC;AAOxE,MAAM,gBAAgB;IAcpB,IAAY,QAAQ;QAClB,OAAO,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,KAAK,CAAC;IACvC,CAAC;IAED,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC;IACpE,CAAC;IAED,IAAY,MAAM;QAChB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC;IAC/C,CAAC;IAGD,IAAY,WAAW;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAC;IAC3C,CAAC;IAED,IAAY,gBAAgB;QAC1B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QAEzC,OAAO;YACL,OAAO;YACP,OAAO;YACP,MAAM,EAAE,OAAO,C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;IAEO,mBAAmB;QACzB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CAGF;AAED,MAAM,UAAU,mBAAmB,CACjC,IAA0C,EAC1C,OAAuC;IAEvC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\nimport { findElementFromEventPath } from '../common/util.js';\nimport { createDefaultGhostElement, getDefaultLayer } from './default-ghost.js';\nimport type { ResizeControllerConfiguration, ResizeState } from './types.js';\n\nconst additionalEvents = ['pointermove', 'lostpointercapture'] as const;\n\ntype State = {\n initial: DOMRect;\n current: DOMRect;\n};\n\nclass ResizeController implements ReactiveController {\n private _host: ReactiveControllerHost & HTMLElement;\n private _options: ResizeControllerConfiguration = {\n enabled: true,\n layer: getDefaultLayer,\n };\n\n private _id = -1;\n private _hasPointerCapture = false;\n private _state!: State;\n\n private _activeRef: HTMLElement | null = null;\n private _ghost: HTMLElement | null = null;\n\n private get _element(): HTMLElement {\n return this._activeRef ?? this._host;\n }\n\n private get _resizeTarget(): HTMLElement {\n return this._options.resizeTarget?.call(this._host) ?? this._host;\n }\n\n private get _layer(): HTMLElement {\n if (!this._isDeferred) {\n return this._host;\n }\n\n return this._options.layer?.() ?? this._host;\n }\n\n /** Whether the controller is in deferred mode. */\n private get _isDeferred(): boolean {\n return this._options.mode === 'deferred';\n }\n\n private get _stateParameters(): ResizeState {\n const { initial, current } = this._state;\n\n return {\n initial,\n current,\n deltaX: current.width - initial.width,\n deltaY: current.height - initial.height,\n ghost: this._ghost,\n trigger: this._activeRef,\n };\n }\n\n constructor(\n host: ReactiveControllerHost & HTMLElement,\n options?: ResizeControllerConfiguration\n ) {\n this._host = host;\n this._host.addController(this);\n\n this.set(options);\n }\n\n // #region Public API\n\n /** Whether the controller is enabled and will listen for events. */\n public get enabled(): boolean {\n return Boolean(this._options.enabled);\n }\n\n /** Updates the configuration of the resize controller. */\n public set(options?: ResizeControllerConfiguration): void {\n Object.assign(this._options, options);\n }\n\n /** Stops any resizing operation, cleaning up any additional elements and event listeners. */\n public dispose(): void {\n this._setResizeState(false);\n this._removeGhostElement();\n this._activeRef = null;\n }\n\n /** @internal */\n public hostConnected(): void {\n this._host.addEventListener('pointerdown', this);\n this._host.addEventListener('touchstart', this, { passive: false });\n }\n\n /** @internal */\n public hostDisconnected(): void {\n this._host.removeEventListener('pointerdown', this);\n this._host.removeEventListener('touchstart', this);\n this._setResizeCancelListener(false);\n this._removeGhostElement();\n }\n\n /** @internal */\n public handleEvent(event: PointerEvent & KeyboardEvent): void {\n if (!this.enabled) {\n return;\n }\n\n switch (event.type) {\n case 'touchstart':\n event.preventDefault();\n break;\n case 'keydown':\n this._handleCancel(event);\n break;\n case 'pointerdown':\n this._handlePointerDown(event);\n break;\n case 'pointermove':\n this._handlePointerMove(event);\n break;\n case 'lostpointercapture':\n this._handlePointerEnd(event);\n break;\n }\n }\n // #endregion\n\n // #region Event handlers\n\n private _handlePointerDown(event: PointerEvent): void {\n // Non-primary buttons are ignored\n if (event.button || this._shouldSkip(event)) {\n return;\n }\n\n this._setInitialState(event);\n this._createGhostElement();\n\n this._options.start?.call(this._host, {\n event,\n state: this._stateParameters,\n });\n this._setResizeState();\n }\n\n private _handlePointerMove(event: PointerEvent): void {\n if (!this._hasPointerCapture) {\n return;\n }\n\n this._updateState(event);\n\n const parameters = { event, state: this._stateParameters };\n this._options.resize?.call(this._host, parameters);\n this._state.current = parameters.state.current;\n this._updatePosition(this._isDeferred ? this._ghost : this._resizeTarget);\n }\n\n private _handlePointerEnd(event: PointerEvent): void {\n const parameters = { event, state: this._stateParameters };\n\n this._options.end?.call(this._host, parameters);\n this._state.current = parameters.state.current;\n // TODO:\n // this._updatePosition(this._resizeTarget);\n this.dispose();\n }\n\n private _handleCancel(event: KeyboardEvent): void {\n const key = event.key.toLowerCase();\n\n if (this._hasPointerCapture && key === 'escape') {\n this._options.cancel?.call(this._host, this._stateParameters);\n }\n }\n\n // #endregion\n\n // #region Internal API\n\n private _shouldSkip(event: PointerEvent): boolean {\n this._setActiveRef(event);\n return !this._activeRef;\n }\n\n private _setActiveRef(event: Event): void {\n const refs = this._options.ref?.map(({ value }) => value) ?? [this._host];\n\n this._activeRef =\n findElementFromEventPath<HTMLElement>(\n (e) => refs.includes(e as HTMLElement),\n event\n ) ?? null;\n }\n\n private _setResizeState(enabled = true): void {\n this._hasPointerCapture = enabled;\n\n enabled\n ? this._element.setPointerCapture(this._id)\n : this._element.releasePointerCapture(this._id);\n\n this._setResizeCancelListener(enabled);\n\n // Toggle additional event listeners\n for (const type of additionalEvents) {\n enabled\n ? this._host.addEventListener(type, this)\n : this._host.removeEventListener(type, this);\n }\n }\n\n private _setResizeCancelListener(enabled = true): void {\n enabled\n ? globalThis.addEventListener('keydown', this)\n : globalThis.removeEventListener('keydown', this);\n }\n\n private _setInitialState({ pointerId }: PointerEvent): void {\n const dimensions = this._resizeTarget.getBoundingClientRect();\n\n this._id = pointerId;\n this._state = {\n initial: dimensions,\n current: structuredClone(dimensions),\n };\n }\n\n private _updateState({ clientX, clientY }: PointerEvent): void {\n this._state.current.width = clientX - this._state.initial.x;\n this._state.current.height = clientY - this._state.initial.y;\n }\n\n private _updatePosition(element: HTMLElement | null): void {\n if (element) {\n Object.assign(element.style, {\n width: `${this._state.current.width}px`,\n height: `${this._state.current.height}px`,\n });\n }\n }\n\n private _createGhostElement(): void {\n if (!this._isDeferred) {\n return;\n }\n\n this._ghost =\n this._options.deferredFactory?.call(this._host) ??\n createDefaultGhostElement(this._resizeTarget.getBoundingClientRect());\n\n this._ghost.setAttribute('data-resize-ghost', '');\n this._layer.append(this._ghost);\n }\n\n private _removeGhostElement(): void {\n this._ghost?.remove();\n this._ghost = null;\n }\n\n // #endregion\n}\n\nexport function addResizeController(\n host: ReactiveControllerHost & HTMLElement,\n options?: ResizeControllerConfiguration\n): ResizeController {\n return new ResizeController(host, options);\n}\n"]}
1
+ {"version":3,"file":"resize-controller.js","sourceRoot":"","sources":["../../../src/components/resize-container/resize-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGhF,MAAM,gBAAgB,GAAG;IACvB,aAAa;IACb,oBAAoB;IACpB,aAAa;CACL,CAAC;AAOX,MAAM,gBAAgB;IAcpB,IAAY,QAAQ;QAClB,OAAO,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,KAAK,CAAC;IACvC,CAAC;IAED,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC;IACpE,CAAC;IAED,IAAY,MAAM;QAChB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC;IAC/C,CAAC;IAGD,IAAY,WAAW;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,UAAU,CAAC;IAC3C,CAAC;IAED,IAAY,gBAAgB;QAC1B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QAEzC,OAAO;YACL,OAAO;YACP,OAAO;YACP,MAAM,EAAE,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK;YACrC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM;YACvC,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,OAAO,EAAE,IAAI,CAAC,UAAU;SACzB,CAAC;IACJ,CAAC;IAED,YACE,IAA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,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAEO,mBAAmB;QACzB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CAGF;AAED,MAAM,UAAU,mBAAmB,CACjC,IAA0C,EAC1C,OAAuC;IAEvC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\nimport { findElementFromEventPath } from '../common/util.js';\nimport { createDefaultGhostElement, getDefaultLayer } from './default-ghost.js';\nimport type { ResizeControllerConfiguration, ResizeState } from './types.js';\n\nconst additionalEvents = [\n 'pointermove',\n 'lostpointercapture',\n 'contextmenu',\n] as const;\n\ntype State = {\n initial: DOMRect;\n current: DOMRect;\n};\n\nclass ResizeController implements ReactiveController {\n private _host: ReactiveControllerHost & HTMLElement;\n private _options: ResizeControllerConfiguration = {\n enabled: true,\n layer: getDefaultLayer,\n };\n\n private _id = -1;\n private _hasPointerCapture = false;\n private _state!: State;\n\n private _activeRef: HTMLElement | null = null;\n private _ghost: HTMLElement | null = null;\n\n private get _element(): HTMLElement {\n return this._activeRef ?? this._host;\n }\n\n private get _resizeTarget(): HTMLElement {\n return this._options.resizeTarget?.call(this._host) ?? this._host;\n }\n\n private get _layer(): HTMLElement {\n if (!this._isDeferred) {\n return this._host;\n }\n\n return this._options.layer?.() ?? this._host;\n }\n\n /** Whether the controller is in deferred mode. */\n private get _isDeferred(): boolean {\n return this._options.mode === 'deferred';\n }\n\n private get _stateParameters(): ResizeState {\n const { initial, current } = this._state;\n\n return {\n initial,\n current,\n deltaX: current.width - initial.width,\n deltaY: current.height - initial.height,\n ghost: this._ghost,\n trigger: this._activeRef,\n };\n }\n\n constructor(\n host: ReactiveControllerHost & HTMLElement,\n options?: ResizeControllerConfiguration\n ) {\n this._host = host;\n this._host.addController(this);\n\n this.set(options);\n }\n\n // #region Public API\n\n /** Whether the controller is enabled and will listen for events. */\n public get enabled(): boolean {\n return Boolean(this._options.enabled);\n }\n\n /** Updates the configuration of the resize controller. */\n public set(options?: ResizeControllerConfiguration): void {\n Object.assign(this._options, options);\n }\n\n /** Stops any resizing operation, cleaning up any additional elements and event listeners. */\n public dispose(): void {\n this._setResizeState(false);\n this._removeGhostElement();\n this._activeRef = null;\n }\n\n /** @internal */\n public hostConnected(): void {\n this._host.addEventListener('pointerdown', this);\n this._host.addEventListener('touchstart', this, { passive: false });\n }\n\n /** @internal */\n public hostDisconnected(): void {\n this._host.removeEventListener('pointerdown', this);\n this._host.removeEventListener('touchstart', this);\n this._setResizeCancelListener(false);\n this._removeGhostElement();\n }\n\n /** @internal */\n public handleEvent(event: PointerEvent & KeyboardEvent): void {\n if (!this.enabled) {\n return;\n }\n\n switch (event.type) {\n case 'touchstart':\n // Prevent contextmenu default behavior during resize\n case 'contextmenu':\n event.preventDefault();\n break;\n case 'keydown':\n this._handleCancel(event);\n break;\n case 'pointerdown':\n this._handlePointerDown(event);\n break;\n case 'pointermove':\n this._handlePointerMove(event);\n break;\n case 'lostpointercapture':\n this._handlePointerEnd(event);\n break;\n }\n }\n // #endregion\n\n // #region Event handlers\n\n private _handlePointerDown(event: PointerEvent): void {\n // Non-primary buttons are ignored\n if (event.button || this._shouldSkip(event)) {\n return;\n }\n\n this._setInitialState(event);\n this._createGhostElement();\n const parameters = { event, state: this._stateParameters };\n\n if (this._options.start?.call(this._host, parameters) === false) {\n this.dispose();\n return;\n }\n\n this._setResizeState();\n }\n\n private _handlePointerMove(event: PointerEvent): void {\n if (!this._hasPointerCapture) {\n return;\n }\n\n this._updateState(event);\n\n const parameters = { event, state: this._stateParameters };\n this._options.resize?.call(this._host, parameters);\n this._state.current = parameters.state.current;\n this._updatePosition(this._isDeferred ? this._ghost : this._resizeTarget);\n }\n\n private _handlePointerEnd(event: PointerEvent): void {\n const parameters = { event, state: this._stateParameters };\n\n this._options.end?.call(this._host, parameters);\n this._state.current = parameters.state.current;\n\n parameters.state.commit?.() ?? this._updatePosition(this._resizeTarget);\n this.dispose();\n }\n\n private _handleCancel(event: KeyboardEvent): void {\n const key = event.key.toLowerCase();\n\n if (this._hasPointerCapture && key === 'escape') {\n this._options.cancel?.call(this._host, this._stateParameters);\n }\n }\n\n // #endregion\n\n // #region Internal API\n\n private _shouldSkip(event: PointerEvent): boolean {\n this._setActiveRef(event);\n return !this._activeRef;\n }\n\n private _setActiveRef(event: Event): void {\n const refs = this._options.ref?.map(({ value }) => value) ?? [this._host];\n\n this._activeRef =\n findElementFromEventPath<HTMLElement>(\n (e) => refs.includes(e as HTMLElement),\n event\n ) ?? null;\n }\n\n private _setResizeState(enabled = true): void {\n this._hasPointerCapture = enabled;\n\n enabled\n ? this._element.setPointerCapture(this._id)\n : this._element.releasePointerCapture(this._id);\n\n this._setResizeCancelListener(enabled);\n\n // Toggle additional event listeners\n for (const type of additionalEvents) {\n enabled\n ? this._host.addEventListener(type, this)\n : this._host.removeEventListener(type, this);\n }\n }\n\n private _setResizeCancelListener(enabled = true): void {\n enabled\n ? globalThis.addEventListener('keydown', this)\n : globalThis.removeEventListener('keydown', this);\n }\n\n private _setInitialState({ pointerId }: PointerEvent): void {\n const dimensions = this._resizeTarget.getBoundingClientRect();\n\n this._id = pointerId;\n this._state = {\n initial: dimensions,\n current: structuredClone(dimensions),\n };\n }\n\n private _updateState({ clientX, clientY }: PointerEvent): void {\n this._state.current.width = clientX - this._state.initial.x;\n this._state.current.height = clientY - this._state.initial.y;\n }\n\n private _updatePosition(element: HTMLElement | null): void {\n if (element) {\n Object.assign(element.style, {\n width: `${this._state.current.width}px`,\n height: `${this._state.current.height}px`,\n });\n }\n }\n\n private _createGhostElement(): void {\n if (!this._isDeferred) {\n return;\n }\n\n this._ghost =\n this._options.deferredFactory?.call(this._host) ??\n createDefaultGhostElement(this._resizeTarget.getBoundingClientRect());\n\n this._ghost.setAttribute('data-resize-ghost', '');\n this._layer.append(this._ghost);\n }\n\n private _removeGhostElement(): void {\n this._ghost?.remove();\n this._ghost = null;\n }\n\n // #endregion\n}\n\nexport function addResizeController(\n host: ReactiveControllerHost & HTMLElement,\n options?: ResizeControllerConfiguration\n): ResizeController {\n return new ResizeController(host, options);\n}\n"]}
@@ -10,6 +10,7 @@ export type ResizeState = {
10
10
  deltaY: number;
11
11
  ghost: HTMLElement | null;
12
12
  trigger: HTMLElement | null;
13
+ commit?: () => unknown;
13
14
  };
14
15
  export type ResizeCallbackParams = {
15
16
  event: PointerEvent;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/resize-container/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Ref } from 'lit/directives/ref.js';\n\nexport type ResizeMode = 'immediate' | 'deferred';\nexport type ResizeCallback = (params: ResizeCallbackParams) => unknown;\nexport type ResizeCancelCallback = (state: ResizeState) => unknown;\nexport type ResizeGhostFactory = () => HTMLElement;\n\nexport type ResizeState = {\n initial: DOMRect;\n current: DOMRect;\n deltaX: number;\n deltaY: number;\n ghost: HTMLElement | null;\n trigger: HTMLElement | null;\n};\n\nexport type ResizeCallbackParams = {\n event: PointerEvent;\n state: ResizeState;\n};\n\nexport type ResizeControllerConfiguration = {\n enabled?: boolean;\n ref?: Ref<HTMLElement>[];\n mode?: ResizeMode;\n deferredFactory?: ResizeGhostFactory;\n layer?: () => HTMLElement;\n /** Callback invoked at the start of a resize operation. */\n start?: ResizeCallback;\n /** Callback invoked on each pointer move during a resize operation. */\n resize?: ResizeCallback;\n /** Callback invoked when a resize operation completes. */\n end?: ResizeCallback;\n /** Callback invoked when a resize operation is cancelled. */\n cancel?: ResizeCancelCallback;\n /**\n * Optional callback that returns the DOM element which will be resized/resizing depending on the\n * configured mode of the controller.\n *\n * Defaults to the controller host.\n */\n resizeTarget?: () => HTMLElement;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/resize-container/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Ref } from 'lit/directives/ref.js';\n\nexport type ResizeMode = 'immediate' | 'deferred';\nexport type ResizeCallback = (params: ResizeCallbackParams) => unknown;\nexport type ResizeCancelCallback = (state: ResizeState) => unknown;\nexport type ResizeGhostFactory = () => HTMLElement;\n\nexport type ResizeState = {\n initial: DOMRect;\n current: DOMRect;\n deltaX: number;\n deltaY: number;\n ghost: HTMLElement | null;\n trigger: HTMLElement | null;\n commit?: () => unknown;\n};\n\nexport type ResizeCallbackParams = {\n event: PointerEvent;\n state: ResizeState;\n};\n\nexport type ResizeControllerConfiguration = {\n enabled?: boolean;\n ref?: Ref<HTMLElement>[];\n mode?: ResizeMode;\n deferredFactory?: ResizeGhostFactory;\n layer?: () => HTMLElement;\n /** Callback invoked at the start of a resize operation. */\n start?: ResizeCallback;\n /** Callback invoked on each pointer move during a resize operation. */\n resize?: ResizeCallback;\n /** Callback invoked when a resize operation completes. */\n end?: ResizeCallback;\n /** Callback invoked when a resize operation is cancelled. */\n cancel?: ResizeCancelCallback;\n /**\n * Optional callback that returns the DOM element which will be resized/resizing depending on the\n * configured mode of the controller.\n *\n * Defaults to the controller host.\n */\n resizeTarget?: () => HTMLElement;\n};\n"]}
@@ -13,6 +13,10 @@ declare class TilesState {
13
13
  /** Updates the default (manual) slot of the tile manager with the current tiles. */
14
14
  assignTiles(): void;
15
15
  add(tile: IgcTileComponent): void;
16
+ /**
17
+ * Checks and adjusts tile spans based on the column count of the tile manager.
18
+ */
19
+ adjustTileGridPosition(): void;
16
20
  remove(tile: IgcTileComponent): void;
17
21
  }
18
22
  type TileDragStackEntry = {
@@ -46,6 +46,24 @@ class TilesState {
46
46
  : this._nextEmptyPosition++;
47
47
  }
48
48
  }
49
+ adjustTileGridPosition() {
50
+ const columnCount = this.manager.columnCount;
51
+ if (columnCount > 0) {
52
+ for (const tile of this.tiles) {
53
+ let colStart = tile.colStart || 0;
54
+ let colStartDelta = colStart > 0 ? 1 : 0;
55
+ const colSpan = tile.colSpan || 0;
56
+ if (colStart > columnCount) {
57
+ colStart = 0;
58
+ colStartDelta = 0;
59
+ tile.colStart = 0;
60
+ }
61
+ if (colStart + colSpan > columnCount) {
62
+ tile.colSpan = columnCount - colStart + colStartDelta;
63
+ }
64
+ }
65
+ }
66
+ }
49
67
  remove(tile) {
50
68
  for (const each of this.tiles) {
51
69
  if (each.position >= tile.position) {
@@ -1 +1 @@
1
- {"version":3,"file":"position.js","sourceRoot":"","sources":["../../../src/components/tile-manager/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAIpD,MAAM,UAAU;IAKd,IAAY,MAAM;QAChB,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAmB,mBAAmB,CAAC,CACrE,CAAC;IACJ,CAAC;IAKD,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;IAED,YAAY,OAAgC;QAjBpC,uBAAkB,GAAG,CAAC,CAAC;QAkB7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,eAAe;QACpB,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,SAAS,CACrD,IAAI,CAAC,MAAM,EACX,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,CAAC,CAC/B,CAAC;QAEF,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;QAExD,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;YAEnC,OAAO,Y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AO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,CAAmB,EAAE,CAAmB;IAChE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { last, partition } from '../common/util.js';\nimport type IgcTileManagerComponent from './tile-manager.js';\nimport type IgcTileComponent from './tile.js';\n\nclass TilesState {\n private _nextEmptyPosition = 0;\n\n public manager: IgcTileManagerComponent;\n\n private get _tiles(): IgcTileComponent[] {\n return Array.from(\n this.manager.querySelectorAll<IgcTileComponent>(':scope > igc-tile')\n );\n }\n\n /**\n * Returns the current tiles of the tile manager sorted by their position.\n */\n public get tiles(): IgcTileComponent[] {\n return this._tiles.toSorted((a, b) => a.position - b.position);\n }\n\n constructor(manager: IgcTileManagerComponent) {\n this.manager = manager;\n }\n\n public assignPositions(): void {\n let nextPosition = 0;\n const [positionedTiles, nonPositionedTiles] = partition(\n this._tiles,\n (tile) => tile.position !== -1\n );\n\n positionedTiles.sort((a, b) => a.position - b.position);\n\n for (const tile of positionedTiles) {\n // Fill any unassigned slots before the next assigned tile's position\n while (nextPosition < tile.position && nonPositionedTiles.length > 0) {\n const nonPositionedTile = nonPositionedTiles.shift()!;\n nonPositionedTile.position = nextPosition++;\n }\n\n tile.position = nextPosition;\n nextPosition = tile.position + 1;\n }\n\n for (const tile of nonPositionedTiles) {\n tile.position = nextPosition++;\n }\n }\n\n /** Updates the default (manual) slot of the tile manager with the current tiles. */\n public assignTiles(): void {\n this.manager.renderRoot.querySelector('slot')!.assign(...this._tiles);\n }\n\n public add(tile: IgcTileComponent): void {\n const tiles = this.tiles;\n\n if (tile.position > -1) {\n for (const each of tiles) {\n if (each !== tile && each.position >= tile.position) {\n each.position++;\n }\n }\n } else {\n const positionedTiles = this._tiles.filter((tile) => tile.position > -1);\n tile.position =\n positionedTiles.length > 1\n ? Math.max(...positionedTiles.map((tile) => tile.position)) + 1\n : this._nextEmptyPosition++;\n }\n }\n\n public remove(tile: IgcTileComponent): void {\n for (const each of this.tiles) {\n if (each.position >= tile.position) {\n each.position--;\n }\n }\n }\n}\n\ntype TileDragStackEntry = {\n tile: IgcTileComponent;\n position: number;\n column?: number | null;\n row?: number | null;\n};\n\nclass TileDragStack {\n private _stack: TileDragStackEntry[] = [];\n\n public peek(): IgcTileComponent {\n return last(this._stack).tile;\n }\n\n public pop(): TileDragStackEntry | undefined {\n return this._stack.pop();\n }\n\n public push(tile: IgcTileComponent): void {\n this._stack.push({\n tile,\n position: tile.position,\n column: tile.colStart,\n row: tile.rowStart,\n });\n }\n\n public restore(): void {\n for (const {\n tile,\n position,\n column: colStart,\n row: rowStart,\n } of this._stack.toReversed()) {\n Object.assign(tile, {\n position,\n colStart,\n rowStart,\n });\n }\n }\n\n public reset(): void {\n this._stack = [];\n }\n}\n\nexport function createTilesState(manager: IgcTileManagerComponent) {\n return new TilesState(manager);\n}\n\nexport function createTileDragStack(): TileDragStack {\n return new TileDragStack();\n}\n\nexport function swapTiles(a: IgcTileComponent, b: IgcTileComponent): void {\n [a.colStart, b.colStart] = [b.colStart, a.colStart];\n [a.rowStart, b.rowStart] = [b.rowStart, a.colStart];\n [a.position, b.position] = [b.position, a.position];\n}\n"]}
1
+ {"version":3,"file":"position.js","sourceRoot":"","sources":["../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I,CAAC,QAAQ;SACnB,CAAC,CAAC;IACL,CAAC;IAEM,OAAO;QACZ,KAAK,MAAM,EACT,IAAI,EACJ,QAAQ,EACR,MAAM,EAAE,QAAQ,EAChB,GAAG,EAAE,QAAQ,GACd,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC;YAC9B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;gBAClB,QAAQ;gBACR,QAAQ;gBACR,QAAQ;aACT,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAC/D,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,CAAmB,EAAE,CAAmB;IAChE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { last, partition } from '../common/util.js';\nimport type IgcTileManagerComponent from './tile-manager.js';\nimport type IgcTileComponent from './tile.js';\n\nclass TilesState {\n private _nextEmptyPosition = 0;\n\n public manager: IgcTileManagerComponent;\n\n private get _tiles(): IgcTileComponent[] {\n return Array.from(\n this.manager.querySelectorAll<IgcTileComponent>(':scope > igc-tile')\n );\n }\n\n /**\n * Returns the current tiles of the tile manager sorted by their position.\n */\n public get tiles(): IgcTileComponent[] {\n return this._tiles.toSorted((a, b) => a.position - b.position);\n }\n\n constructor(manager: IgcTileManagerComponent) {\n this.manager = manager;\n }\n\n public assignPositions(): void {\n let nextPosition = 0;\n const [positionedTiles, nonPositionedTiles] = partition(\n this._tiles,\n (tile) => tile.position !== -1\n );\n\n positionedTiles.sort((a, b) => a.position - b.position);\n\n for (const tile of positionedTiles) {\n // Fill any unassigned slots before the next assigned tile's position\n while (nextPosition < tile.position && nonPositionedTiles.length > 0) {\n const nonPositionedTile = nonPositionedTiles.shift()!;\n nonPositionedTile.position = nextPosition++;\n }\n\n tile.position = nextPosition;\n nextPosition = tile.position + 1;\n }\n\n for (const tile of nonPositionedTiles) {\n tile.position = nextPosition++;\n }\n }\n\n /** Updates the default (manual) slot of the tile manager with the current tiles. */\n public assignTiles(): void {\n this.manager.renderRoot.querySelector('slot')!.assign(...this._tiles);\n }\n\n public add(tile: IgcTileComponent): void {\n const tiles = this.tiles;\n\n if (tile.position > -1) {\n for (const each of tiles) {\n if (each !== tile && each.position >= tile.position) {\n each.position++;\n }\n }\n } else {\n const positionedTiles = this._tiles.filter((tile) => tile.position > -1);\n tile.position =\n positionedTiles.length > 1\n ? Math.max(...positionedTiles.map((tile) => tile.position)) + 1\n : this._nextEmptyPosition++;\n }\n }\n\n /**\n * Checks and adjusts tile spans based on the column count of the tile manager.\n */\n public adjustTileGridPosition(): void {\n const columnCount = this.manager.columnCount;\n\n if (columnCount > 0) {\n for (const tile of this.tiles) {\n let colStart = tile.colStart || 0;\n let colStartDelta = colStart > 0 ? 1 : 0;\n const colSpan = tile.colSpan || 0;\n\n if (colStart > columnCount) {\n colStart = 0;\n colStartDelta = 0;\n tile.colStart = 0;\n }\n\n if (colStart + colSpan > columnCount) {\n tile.colSpan = columnCount - colStart + colStartDelta;\n }\n }\n }\n }\n\n public remove(tile: IgcTileComponent): void {\n for (const each of this.tiles) {\n if (each.position >= tile.position) {\n each.position--;\n }\n }\n }\n}\n\ntype TileDragStackEntry = {\n tile: IgcTileComponent;\n position: number;\n column?: number | null;\n row?: number | null;\n};\n\nclass TileDragStack {\n private _stack: TileDragStackEntry[] = [];\n\n public peek(): IgcTileComponent {\n return last(this._stack).tile;\n }\n\n public pop(): TileDragStackEntry | undefined {\n return this._stack.pop();\n }\n\n public push(tile: IgcTileComponent): void {\n this._stack.push({\n tile,\n position: tile.position,\n column: tile.colStart,\n row: tile.rowStart,\n });\n }\n\n public restore(): void {\n for (const {\n tile,\n position,\n column: colStart,\n row: rowStart,\n } of this._stack.toReversed()) {\n Object.assign(tile, {\n position,\n colStart,\n rowStart,\n });\n }\n }\n\n public reset(): void {\n this._stack = [];\n }\n}\n\nexport function createTilesState(manager: IgcTileManagerComponent) {\n return new TilesState(manager);\n}\n\nexport function createTileDragStack(): TileDragStack {\n return new TileDragStack();\n}\n\nexport function swapTiles(a: IgcTileComponent, b: IgcTileComponent): void {\n [a.colStart, b.colStart] = [b.colStart, a.colStart];\n [a.rowStart, b.rowStart] = [b.rowStart, a.colStart];\n [a.position, b.position] = [b.position, a.position];\n}\n"]}
@@ -13,7 +13,6 @@ declare class TileResizeState {
13
13
  protected _columns: TileGridDimension;
14
14
  protected _rows: TileGridDimension;
15
15
  resizedDimensions: TileResizeDimensions;
16
- get emptyResizeDimensions(): TileResizeDimensions;
17
16
  get gap(): number;
18
17
  get position(): TileGridPosition;
19
18
  get columns(): TileGridDimension;
@@ -29,10 +28,6 @@ declare class TileResizeState {
29
28
  colSpan: number;
30
29
  rowSpan: number;
31
30
  };
32
- /**
33
- * Checks and adjusts tile spans based on the column count of the tile manager.
34
- */
35
- adjustTileGridPosition(tiles: IgcTileComponent[]): void;
36
31
  private initState;
37
32
  private calculateTileStartPosition;
38
33
  private getGridOffset;
@@ -61,9 +61,6 @@ class TileResizeState {
61
61
  height: null,
62
62
  };
63
63
  }
64
- get emptyResizeDimensions() {
65
- return { width: null, height: null };
66
- }
67
64
  get gap() {
68
65
  return this._gap;
69
66
  }
@@ -105,21 +102,6 @@ class TileResizeState {
105
102
  rowSpan: this._position.row.span,
106
103
  };
107
104
  }
108
- adjustTileGridPosition(tiles) {
109
- const columnCount = this.columns.count;
110
- for (const tile of tiles) {
111
- const colStart = tile.colStart || 0;
112
- const colSpan = tile.colSpan || 0;
113
- if (colStart > columnCount) {
114
- tile.colSpan = 1;
115
- tile.colStart = columnCount;
116
- continue;
117
- }
118
- if (colStart + colSpan - 1 > columnCount) {
119
- tile.colSpan = columnCount - colStart + 1;
120
- }
121
- }
122
- }
123
105
  initState(grid, tile) {
124
106
  const { gap, columns, rows } = parseTileParentGrid(grid);
125
107
  this._resizeUtil = new ResizeUtil(gap);
@@ -178,14 +160,14 @@ class TileResizeState {
178
160
  targetSize: rect.height,
179
161
  tilePosition: this.position.row,
180
162
  tileGridDimension: this.rows,
181
- gap: this._gap,
163
+ gap: this.gap,
182
164
  isRow,
183
165
  }
184
166
  : {
185
167
  targetSize: rect.width,
186
168
  tilePosition: this.position.column,
187
169
  tileGridDimension: this.columns,
188
- gap: this._gap,
170
+ gap: this.gap,
189
171
  isRow,
190
172
  };
191
173
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resize-state.js","sourceRoot":"","sources":["../../../src/components/tile-manager/resize-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAU9C,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,+CAA+C,CAAC,CAAC;AAE9E,SAAS,iBAAiB,CAAC,IAAsB;IAC/C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IAEzC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;Q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BACE,UAAU,EAAE,IAAI,CAAC,KAAK;gBACtB,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;gBAClC,iBAAiB,EAAE,IAAI,CAAC,OAAO;gBAC/B,GAAG,EAAE,IAAI,CAAC,IAAI;gBACd,KAAK;aACN,CAAC;IACR,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,eAAe,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["import { asNumber, first } from '../common/util.js';\nimport type { ResizeState } from '../resize-container/types.js';\nimport { ResizeUtil } from './resize-util.js';\nimport type IgcTileComponent from './tile.js';\nimport type {\n ResizeProps,\n ResizeSpanProps,\n TileGridDimension,\n TileGridPosition,\n TileResizeDimensions,\n} from './types.js';\n\nconst CssValues = new RegExp(/(?<start>\\d+)?\\s*\\/?\\s*span\\s*(?<span>\\d+)?/gi);\n\nfunction parseTileGridRect(tile: IgcTileComponent): TileGridPosition {\n const computed = getComputedStyle(tile);\n const { gridColumn, gridRow } = computed;\n\n const [column, row] = [\n first(Array.from(gridColumn.matchAll(CssValues))).groups!,\n first(Array.from(gridRow.matchAll(CssValues))).groups!,\n ];\n\n return {\n column: {\n start: asNumber(column.start, -1),\n span: asNumber(column.span, -1),\n },\n row: { start: asNumber(row.start, -1), span: asNumber(row.span, -1) },\n };\n}\n\nfunction parseTileParentGrid(gridContainer: HTMLElement) {\n const computed = getComputedStyle(gridContainer);\n const { gap, gridTemplateColumns, gridTemplateRows } = computed;\n\n const columns = gridTemplateColumns.split(' ').map(asNumber);\n const rows = gridTemplateRows.split(' ').map(asNumber);\n\n return {\n gap: asNumber(gap),\n columns: {\n count: columns.length,\n entries: columns,\n minSize: asNumber(computed.getPropertyValue('--min-col-width')),\n },\n rows: {\n count: rows.length,\n entries: rows,\n minSize: asNumber(computed.getPropertyValue('--min-row-height')),\n },\n };\n}\n\nclass TileResizeState {\n private _initialPosition!: TileGridPosition;\n private _resizeUtil!: ResizeUtil;\n\n protected _gap = 0;\n protected _prevDeltaX = 0;\n protected _prevDeltaY = 0;\n\n protected _prevSnappedWidth = 0;\n protected _prevSnappedHeight = 0;\n\n protected _position: TileGridPosition = {\n column: { start: 0, span: 0 },\n row: { start: 0, span: 0 },\n };\n\n protected _columns: TileGridDimension = {\n count: 0,\n entries: [],\n minSize: 0,\n };\n\n protected _rows: TileGridDimension = {\n count: 0,\n entries: [],\n minSize: 0,\n };\n\n public resizedDimensions: TileResizeDimensions = {\n width: null,\n height: null,\n };\n\n public get emptyResizeDimensions(): TileResizeDimensions {\n return { width: null, height: null };\n }\n\n public get gap(): number {\n return this._gap;\n }\n\n public get position(): TileGridPosition {\n return structuredClone(this._position);\n }\n\n public get columns(): TileGridDimension {\n return structuredClone(this._columns);\n }\n\n public get rows(): TileGridDimension {\n return structuredClone(this._rows);\n }\n\n public calculateSnappedWidth(state: ResizeState): number {\n const resizeProps = this.getResizeProps(state);\n const snappedDimension =\n this._resizeUtil.calculateSnappedDimension(resizeProps);\n\n this._prevDeltaX = snappedDimension.newDelta;\n this._prevSnappedWidth = snappedDimension.snappedSize;\n return snappedDimension.snappedSize;\n }\n\n public calculateSnappedHeight(state: ResizeState): number {\n const resizeProps = this.getResizeProps(state, true);\n const snappedDimension =\n this._resizeUtil.calculateSnappedDimension(resizeProps);\n\n this._prevDeltaY = snappedDimension.newDelta;\n this._prevSnappedHeight = snappedDimension.snappedSize;\n return snappedDimension.snappedSize;\n }\n\n public updateState(\n tileRect: DOMRect,\n tile: IgcTileComponent,\n grid: HTMLElement\n ): void {\n this.initState(grid, tile);\n this.calculateTileStartPosition(grid, tileRect);\n }\n\n /**\n * Calculates and returns the CSS column and row properties of a tile after resizing,\n * based on its new dimensions and starting position.\n */\n public calculateResizedGridPosition(rect: DOMRect) {\n const colProps = this.getResizeSpanProps(rect);\n const rowProps = this.getResizeSpanProps(rect, true);\n\n // REVIEW pass col minSize and allowOverflow?\n this._position.column.span =\n this._resizeUtil.calculateResizedSpan(colProps);\n this._position.row.span = this._resizeUtil.calculateResizedSpan(rowProps);\n\n return {\n colSpan: this._position.column.span,\n rowSpan: this._position.row.span,\n };\n }\n\n /**\n * Checks and adjusts tile spans based on the column count of the tile manager.\n */\n // REVIEW once we decide how to handle empty columns.\n public adjustTileGridPosition(tiles: IgcTileComponent[]): void {\n const columnCount = this.columns.count;\n\n for (const tile of tiles) {\n const colStart = tile.colStart || 0;\n const colSpan = tile.colSpan || 0;\n\n if (colStart > columnCount) {\n //Prioritize span over start?\n tile.colSpan = 1;\n tile.colStart = columnCount;\n continue;\n }\n\n if (colStart + colSpan - 1 > columnCount) {\n tile.colSpan = columnCount - colStart + 1;\n }\n }\n }\n\n private initState(grid: HTMLElement, tile: IgcTileComponent): void {\n const { gap, columns, rows } = parseTileParentGrid(grid);\n\n this._resizeUtil = new ResizeUtil(gap);\n this._initialPosition = parseTileGridRect(tile);\n this._position = structuredClone(this._initialPosition);\n\n this._gap = gap;\n this._columns = columns;\n this._rows = rows;\n this._prevDeltaX = 0;\n this._prevDeltaY = 0;\n this._prevSnappedWidth = 0;\n this._prevSnappedHeight = 0;\n }\n\n private calculateTileStartPosition(\n grid: HTMLElement,\n tileRect: DOMRect\n ): void {\n if (this._position.column.start < 0) {\n const offsetX = this.getGridOffset(grid, 'horizontal');\n\n this._position.column.start = this._resizeUtil.calculatePosition(\n tileRect.left + window.scrollX + grid.scrollLeft - offsetX,\n this._columns.entries\n );\n }\n\n if (this._position.row.start < 0) {\n const offsetY = this.getGridOffset(grid, 'vertical');\n\n this._position.row.start = this._resizeUtil.calculatePosition(\n tileRect.top + window.scrollY - offsetY,\n this._rows.entries\n );\n }\n }\n\n private getGridOffset(\n grid: HTMLElement,\n axis: 'horizontal' | 'vertical'\n ): number {\n const gridRect = grid.getBoundingClientRect();\n const computed = getComputedStyle(grid);\n\n return axis === 'horizontal'\n ? gridRect.left +\n window.scrollX +\n grid.scrollLeft +\n Number.parseFloat(computed.paddingLeft)\n : gridRect.top + window.scrollY + Number.parseFloat(computed.paddingTop);\n }\n\n private getResizeProps(state: ResizeState, isRow = false): ResizeProps {\n return isRow\n ? {\n currentDelta: state.deltaY,\n currentSize: state.current.height,\n prevDelta: this._prevDeltaY,\n gridEntries: this._rows.entries,\n startIndex: this._position.row.start,\n prevSnapped: this._prevSnappedHeight,\n }\n : {\n currentDelta: state.deltaX,\n currentSize: state.current.width,\n prevDelta: this._prevDeltaX,\n gridEntries: this._columns.entries,\n startIndex: this._position.column.start,\n prevSnapped: this._prevSnappedWidth,\n };\n }\n\n private getResizeSpanProps(rect: DOMRect, isRow = false): ResizeSpanProps {\n return isRow\n ? {\n targetSize: rect.height,\n tilePosition: this.position.row,\n tileGridDimension: this.rows,\n gap: this._gap,\n isRow,\n }\n : {\n targetSize: rect.width,\n tilePosition: this.position.column,\n tileGridDimension: this.columns,\n gap: this._gap,\n isRow,\n };\n }\n}\n\nexport function createTileResizeState(): TileResizeState {\n return new TileResizeState();\n}\n"]}
1
+ {"version":3,"file":"resize-state.js","sourceRoot":"","sources":["../../../src/components/tile-manager/resize-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAU9C,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,+CAA+C,CAAC,CAAC;AAE9E,SAAS,iBAAiB,CAAC,IAAsB;IAC/C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IAEzC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;QACpB,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAO;QACzD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC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AAK;gBACvC,WAAW,EAAE,IAAI,CAAC,iBAAiB;aACpC,CAAC;IACR,CAAC;IAEO,kBAAkB,CAAC,IAAa,EAAE,KAAK,GAAG,KAAK;QACrD,OAAO,KAAK;YACV,CAAC,CAAC;gBACE,UAAU,EAAE,IAAI,CAAC,MAAM;gBACvB,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG;gBAC/B,iBAAiB,EAAE,IAAI,CAAC,IAAI;gBAC5B,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,KAAK;aACN;YACH,CAAC,CAAC;gBACE,UAAU,EAAE,IAAI,CAAC,KAAK;gBACtB,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;gBAClC,iBAAiB,EAAE,IAAI,CAAC,OAAO;gBAC/B,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,KAAK;aACN,CAAC;IACR,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,eAAe,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["import { asNumber, first } from '../common/util.js';\nimport type { ResizeState } from '../resize-container/types.js';\nimport { ResizeUtil } from './resize-util.js';\nimport type IgcTileComponent from './tile.js';\nimport type {\n ResizeProps,\n ResizeSpanProps,\n TileGridDimension,\n TileGridPosition,\n TileResizeDimensions,\n} from './types.js';\n\nconst CssValues = new RegExp(/(?<start>\\d+)?\\s*\\/?\\s*span\\s*(?<span>\\d+)?/gi);\n\nfunction parseTileGridRect(tile: IgcTileComponent): TileGridPosition {\n const computed = getComputedStyle(tile);\n const { gridColumn, gridRow } = computed;\n\n const [column, row] = [\n first(Array.from(gridColumn.matchAll(CssValues))).groups!,\n first(Array.from(gridRow.matchAll(CssValues))).groups!,\n ];\n\n return {\n column: {\n start: asNumber(column.start, -1),\n span: asNumber(column.span, -1),\n },\n row: { start: asNumber(row.start, -1), span: asNumber(row.span, -1) },\n };\n}\n\nfunction parseTileParentGrid(gridContainer: HTMLElement) {\n const computed = getComputedStyle(gridContainer);\n const { gap, gridTemplateColumns, gridTemplateRows } = computed;\n\n const columns = gridTemplateColumns.split(' ').map(asNumber);\n const rows = gridTemplateRows.split(' ').map(asNumber);\n\n return {\n gap: asNumber(gap),\n columns: {\n count: columns.length,\n entries: columns,\n minSize: asNumber(computed.getPropertyValue('--min-col-width')),\n },\n rows: {\n count: rows.length,\n entries: rows,\n minSize: asNumber(computed.getPropertyValue('--min-row-height')),\n },\n };\n}\n\nclass TileResizeState {\n private _initialPosition!: TileGridPosition;\n private _resizeUtil!: ResizeUtil;\n\n protected _gap = 0;\n protected _prevDeltaX = 0;\n protected _prevDeltaY = 0;\n\n protected _prevSnappedWidth = 0;\n protected _prevSnappedHeight = 0;\n\n protected _position: TileGridPosition = {\n column: { start: 0, span: 0 },\n row: { start: 0, span: 0 },\n };\n\n protected _columns: TileGridDimension = {\n count: 0,\n entries: [],\n minSize: 0,\n };\n\n protected _rows: TileGridDimension = {\n count: 0,\n entries: [],\n minSize: 0,\n };\n\n public resizedDimensions: TileResizeDimensions = {\n width: null,\n height: null,\n };\n\n public get gap(): number {\n return this._gap;\n }\n\n public get position(): TileGridPosition {\n return structuredClone(this._position);\n }\n\n public get columns(): TileGridDimension {\n return structuredClone(this._columns);\n }\n\n public get rows(): TileGridDimension {\n return structuredClone(this._rows);\n }\n\n public calculateSnappedWidth(state: ResizeState): number {\n const resizeProps = this.getResizeProps(state);\n const snappedDimension =\n this._resizeUtil.calculateSnappedDimension(resizeProps);\n\n this._prevDeltaX = snappedDimension.newDelta;\n this._prevSnappedWidth = snappedDimension.snappedSize;\n return snappedDimension.snappedSize;\n }\n\n public calculateSnappedHeight(state: ResizeState): number {\n const resizeProps = this.getResizeProps(state, true);\n const snappedDimension =\n this._resizeUtil.calculateSnappedDimension(resizeProps);\n\n this._prevDeltaY = snappedDimension.newDelta;\n this._prevSnappedHeight = snappedDimension.snappedSize;\n return snappedDimension.snappedSize;\n }\n\n public updateState(\n tileRect: DOMRect,\n tile: IgcTileComponent,\n grid: HTMLElement\n ): void {\n this.initState(grid, tile);\n this.calculateTileStartPosition(grid, tileRect);\n }\n\n /**\n * Calculates and returns the CSS column and row properties of a tile after resizing,\n * based on its new dimensions and starting position.\n */\n public calculateResizedGridPosition(rect: DOMRect) {\n const colProps = this.getResizeSpanProps(rect);\n const rowProps = this.getResizeSpanProps(rect, true);\n\n // REVIEW pass col minSize and allowOverflow?\n this._position.column.span =\n this._resizeUtil.calculateResizedSpan(colProps);\n this._position.row.span = this._resizeUtil.calculateResizedSpan(rowProps);\n\n return {\n colSpan: this._position.column.span,\n rowSpan: this._position.row.span,\n };\n }\n\n private initState(grid: HTMLElement, tile: IgcTileComponent): void {\n const { gap, columns, rows } = parseTileParentGrid(grid);\n\n this._resizeUtil = new ResizeUtil(gap);\n this._initialPosition = parseTileGridRect(tile);\n this._position = structuredClone(this._initialPosition);\n\n this._gap = gap;\n this._columns = columns;\n this._rows = rows;\n this._prevDeltaX = 0;\n this._prevDeltaY = 0;\n this._prevSnappedWidth = 0;\n this._prevSnappedHeight = 0;\n }\n\n private calculateTileStartPosition(\n grid: HTMLElement,\n tileRect: DOMRect\n ): void {\n if (this._position.column.start < 0) {\n const offsetX = this.getGridOffset(grid, 'horizontal');\n\n this._position.column.start = this._resizeUtil.calculatePosition(\n tileRect.left + window.scrollX + grid.scrollLeft - offsetX,\n this._columns.entries\n );\n }\n\n if (this._position.row.start < 0) {\n const offsetY = this.getGridOffset(grid, 'vertical');\n\n this._position.row.start = this._resizeUtil.calculatePosition(\n tileRect.top + window.scrollY - offsetY,\n this._rows.entries\n );\n }\n }\n\n private getGridOffset(\n grid: HTMLElement,\n axis: 'horizontal' | 'vertical'\n ): number {\n const gridRect = grid.getBoundingClientRect();\n const computed = getComputedStyle(grid);\n\n return axis === 'horizontal'\n ? gridRect.left +\n window.scrollX +\n grid.scrollLeft +\n Number.parseFloat(computed.paddingLeft)\n : gridRect.top + window.scrollY + Number.parseFloat(computed.paddingTop);\n }\n\n private getResizeProps(state: ResizeState, isRow = false): ResizeProps {\n return isRow\n ? {\n currentDelta: state.deltaY,\n currentSize: state.current.height,\n prevDelta: this._prevDeltaY,\n gridEntries: this._rows.entries,\n startIndex: this._position.row.start,\n prevSnapped: this._prevSnappedHeight,\n }\n : {\n currentDelta: state.deltaX,\n currentSize: state.current.width,\n prevDelta: this._prevDeltaX,\n gridEntries: this._columns.entries,\n startIndex: this._position.column.start,\n prevSnapped: this._prevSnappedWidth,\n };\n }\n\n private getResizeSpanProps(rect: DOMRect, isRow = false): ResizeSpanProps {\n return isRow\n ? {\n targetSize: rect.height,\n tilePosition: this.position.row,\n tileGridDimension: this.rows,\n gap: this.gap,\n isRow,\n }\n : {\n targetSize: rect.width,\n tilePosition: this.position.column,\n tileGridDimension: this.columns,\n gap: this.gap,\n isRow,\n };\n }\n}\n\nexport function createTileResizeState(): TileResizeState {\n return new TileResizeState();\n}\n"]}
@@ -85,6 +85,7 @@ export default class IgcTileManagerComponent extends LitElement {
85
85
  */
86
86
  get tiles(): IgcTileComponent[];
87
87
  constructor();
88
+ protected updated(): void;
88
89
  protected firstUpdated(): void;
89
90
  private _observerCallback;
90
91
  saveLayout(): string;
@@ -118,6 +118,9 @@ let IgcTileManagerComponent = IgcTileManagerComponent_1 = class IgcTileManagerCo
118
118
  },
119
119
  });
120
120
  }
121
+ updated() {
122
+ this._tilesState.adjustTileGridPosition();
123
+ }
121
124
  firstUpdated() {
122
125
  this._tilesState.assignPositions();
123
126
  this._tilesState.assignTiles();