@oscarpalmer/oui 0.26.1 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/css/floatable.css +0 -2
  2. package/dist/css/message.css +1 -0
  3. package/dist/css/reset.css +1 -0
  4. package/dist/js/dialog.d.mts +2 -0
  5. package/dist/js/dialog.mjs +16 -1
  6. package/dist/js/draggable-zszaW1qS.d.mts +155 -0
  7. package/dist/js/floatable/floatable.embedded.d.mts +2 -0
  8. package/dist/js/floatable/{embedded.mjs → floatable.embedded.mjs} +16 -11
  9. package/dist/js/floatable/floatable.standalone.d.mts +2 -0
  10. package/dist/js/floatable/floatable.standalone.mjs +2 -0
  11. package/dist/js/{embedded-CSOh5njI.d.mts → floatable.embedded-YxGwzgbE.d.mts} +5 -2
  12. package/dist/js/focus-trap/focus-trap.embedded.d.mts +2 -0
  13. package/dist/js/focus-trap/{embedded.mjs → focus-trap.embedded.mjs} +17 -15
  14. package/dist/js/focus-trap/focus-trap.standalone.d.mts +2 -0
  15. package/dist/js/focus-trap/focus-trap.standalone.mjs +2 -0
  16. package/dist/js/{embedded-CHK82Uh5.d.mts → focus-trap.embedded-DR8NpZfr.d.mts} +18 -18
  17. package/dist/js/index.d.mts +4 -3
  18. package/dist/js/index.mjs +8 -7
  19. package/dist/js/internal/draggable.d.mts +2 -2
  20. package/dist/js/internal/draggable.mjs +146 -94
  21. package/dist/js/movable/movable.embedded.d.mts +2 -0
  22. package/dist/js/movable/movable.embedded.mjs +184 -0
  23. package/dist/js/movable/movable.standalone.d.mts +2 -0
  24. package/dist/js/movable/movable.standalone.mjs +2 -0
  25. package/dist/js/popover.d.mts +2 -2
  26. package/dist/js/popover.mjs +4 -3
  27. package/dist/js/sortable/sortable.embedded.d.mts +2 -0
  28. package/dist/js/{sortable.mjs → sortable/sortable.embedded.mjs} +88 -63
  29. package/dist/js/sortable/sortable.standalone.d.mts +2 -0
  30. package/dist/js/sortable/sortable.standalone.mjs +2 -0
  31. package/dist/js/splitter.mjs +5 -5
  32. package/dist/js/toolbar.mjs +6 -6
  33. package/dist/js/tooltip.d.mts +2 -2
  34. package/dist/js/tooltip.mjs +36 -33
  35. package/package.json +11 -11
  36. package/src/css/floatable.scss +0 -2
  37. package/src/css/message.scss +1 -0
  38. package/src/css/reset.scss +1 -0
  39. package/src/js/dialog.ts +31 -1
  40. package/src/js/floatable/{embedded.ts → floatable.embedded.ts} +18 -10
  41. package/src/js/floatable/floatable.standalone.ts +6 -0
  42. package/src/js/focus-trap/{embedded.ts → focus-trap.embedded.ts} +20 -17
  43. package/src/js/focus-trap/focus-trap.standalone.ts +1 -0
  44. package/src/js/index.ts +4 -4
  45. package/src/js/internal/draggable.ts +309 -168
  46. package/src/js/movable/movable.embedded.ts +328 -0
  47. package/src/js/movable/movable.standalone.ts +2 -0
  48. package/src/js/popover.ts +3 -2
  49. package/src/js/{sortable.ts → sortable/sortable.embedded.ts} +170 -103
  50. package/src/js/sortable/sortable.standalone.ts +2 -0
  51. package/src/js/tooltip.ts +49 -43
  52. package/dist/js/floatable/embedded.d.mts +0 -2
  53. package/dist/js/floatable/standalone.d.mts +0 -2
  54. package/dist/js/floatable/standalone.mjs +0 -2
  55. package/dist/js/focus-trap/embedded.d.mts +0 -2
  56. package/dist/js/focus-trap/standalone.d.mts +0 -2
  57. package/dist/js/focus-trap/standalone.mjs +0 -6
  58. package/dist/js/movable-dNqBctx3.d.mts +0 -101
  59. package/dist/js/movable.d.mts +0 -2
  60. package/dist/js/movable.mjs +0 -152
  61. package/dist/js/sortable.d.mts +0 -2
  62. package/src/js/floatable/standalone.ts +0 -1
  63. package/src/js/focus-trap/standalone.ts +0 -6
  64. package/src/js/movable.ts +0 -260
package/src/js/tooltip.ts CHANGED
@@ -5,9 +5,10 @@ import {findAncestor} from '@oscarpalmer/toretto/find';
5
5
  import {isHTMLOrSVGElement} from '@oscarpalmer/toretto/is';
6
6
  import {
7
7
  createEmbeddedFloatable,
8
+ FLOATABLE_STATE_OPEN,
8
9
  type OuiFloatable,
9
10
  type OuiFloatableOptions,
10
- } from './floatable/embedded';
11
+ } from './floatable/floatable.embedded';
11
12
  import {attributable} from './internal/attributable';
12
13
 
13
14
  // #region Types
@@ -19,7 +20,7 @@ class OuiTooltip {
19
20
  * Is the tooltip open?
20
21
  */
21
22
  get open(): boolean {
22
- return this.#state.content.checkVisibility();
23
+ return this === activeTooltip && content.checkVisibility();
23
24
  }
24
25
 
25
26
  /**
@@ -56,7 +57,7 @@ class OuiTooltip {
56
57
 
57
58
  type OuiTooltipState = {
58
59
  anchor: HTMLElement;
59
- content: HTMLElement;
60
+ elements: HTMLElement[];
60
61
  floatable: OuiFloatable;
61
62
  timer?: number;
62
63
  tooltip: OuiTooltip;
@@ -67,12 +68,12 @@ type OuiTooltipState = {
67
68
  // #region Functions
68
69
 
69
70
  function activate(event: Event, focus: boolean): void {
70
- const anchor = findAncestor(event, SELECTOR) as HTMLElement | null;
71
- const content = findAncestor(event, SELECTOR_CONTENT) as HTMLElement | null;
71
+ const targetAnchor = findAncestor(event, SELECTOR) as HTMLElement | null;
72
+ const targetContent = findAncestor(event, SELECTOR_CONTENT) as HTMLElement | null;
72
73
 
73
- if (anchor == null && content == null) {
74
+ if (targetAnchor == null && targetContent == null) {
74
75
  if (!focused) {
75
- closeTooltip(activeState);
76
+ closeTooltip(true, activeState);
76
77
 
77
78
  activeState = undefined;
78
79
  activeTooltip = undefined;
@@ -81,7 +82,7 @@ function activate(event: Event, focus: boolean): void {
81
82
  return;
82
83
  }
83
84
 
84
- const state = states.get((anchor ?? content)!);
85
+ const state = states.get((targetAnchor ?? targetContent)!);
85
86
 
86
87
  if (state == null || state.tooltip === activeTooltip) {
87
88
  return;
@@ -89,7 +90,7 @@ function activate(event: Event, focus: boolean): void {
89
90
 
90
91
  const shouldDelay = activeTooltip == null;
91
92
 
92
- closeTooltip(activeState);
93
+ closeTooltip(false, activeState);
93
94
 
94
95
  activeState = state;
95
96
  activeTooltip = state.tooltip;
@@ -98,14 +99,14 @@ function activate(event: Event, focus: boolean): void {
98
99
 
99
100
  state.timer = setTimeout(
100
101
  () => {
101
- state.content.showPopover({
102
- source: state.anchor as HTMLElement,
103
- });
102
+ content.innerHTML = '';
103
+
104
+ content.append(...state.elements);
105
+
106
+ state.floatable.show();
104
107
 
105
108
  setTimeout(() => {
106
109
  state.floatable.update();
107
-
108
- state.content.setAttribute(ATTRIBUTE_CONTENT_OPEN, '');
109
110
  });
110
111
  },
111
112
  shouldDelay ? delay : 0,
@@ -118,7 +119,7 @@ function addTooltip(element: HTMLElement): void {
118
119
  }
119
120
  }
120
121
 
121
- function closeTooltip(state?: OuiTooltipState): void {
122
+ function closeTooltip(clear: boolean, state?: OuiTooltipState): void {
122
123
  if (state == null) {
123
124
  return;
124
125
  }
@@ -127,30 +128,28 @@ function closeTooltip(state?: OuiTooltipState): void {
127
128
  clearTimeout(state.timer);
128
129
  }
129
130
 
130
- state.content?.hidePopover();
131
- state.content?.removeAttribute(ATTRIBUTE_CONTENT_OPEN);
131
+ if (clear) {
132
+ content?.hidePopover();
133
+ }
132
134
  }
133
135
 
134
136
  function createTooltip(anchor: HTMLElement): void {
135
- const content = getContent(anchor);
137
+ const elements = getElements(anchor);
136
138
 
137
- if (content == null) {
139
+ if (elements == null) {
138
140
  return;
139
141
  }
140
142
 
141
- anchor.insertAdjacentElement('afterend', content);
142
-
143
- states.set(anchor, getState(anchor, content));
143
+ states.set(anchor, getState(anchor, elements));
144
144
  }
145
145
 
146
146
  function destroyTooltip(state: OuiTooltipState): void {
147
147
  clearTimeout(state.timer);
148
148
 
149
- state.content.remove();
150
149
  state.floatable.destroy();
151
150
 
152
151
  state.anchor = undefined as never;
153
- state.content = undefined as never;
152
+ state.elements = undefined as never;
154
153
  state.floatable = undefined as never;
155
154
  state.tooltip = undefined as never;
156
155
  }
@@ -178,13 +177,7 @@ function findElements(attribute: string | null): HTMLElement[] {
178
177
  return elements;
179
178
  }
180
179
 
181
- function getContent(anchor: HTMLElement): HTMLElement | undefined {
182
- const elements = getElements(anchor);
183
-
184
- if (elements == null) {
185
- return;
186
- }
187
-
180
+ function getContent(): HTMLElement {
188
181
  const content = createElement(CONTENT_TAGNAME, {
189
182
  popover: 'hint',
190
183
  role: 'tooltip',
@@ -193,8 +186,6 @@ function getContent(anchor: HTMLElement): HTMLElement | undefined {
193
186
 
194
187
  content.setAttribute(ATTRIBUTE_CONTENT, '');
195
188
 
196
- content.append(...elements);
197
-
198
189
  return content;
199
190
  }
200
191
 
@@ -202,36 +193,36 @@ function getElements(anchor: HTMLElement): HTMLElement[] | undefined {
202
193
  let elements = findElements(anchor.getAttribute(ARIA_LABELLEDBY));
203
194
 
204
195
  if (elements.length > 0) {
205
- return elements.map(element => element.cloneNode(true)) as HTMLElement[];
196
+ return elements;
206
197
  }
207
198
 
208
199
  elements = findElements(anchor.getAttribute(ARIA_DESCRIBEDBY));
209
200
 
210
201
  if (elements.length > 0) {
211
- return elements.map(element => element.cloneNode(true)) as HTMLElement[];
202
+ return elements;
212
203
  }
213
204
 
214
- let content = anchor.getAttribute(ARIA_LABEL);
205
+ let text = anchor.getAttribute(ARIA_LABEL);
215
206
 
216
- if (isNullableOrWhitespace(content)) {
217
- content = anchor.getAttribute(ARIA_DESCRIPTION);
207
+ if (isNullableOrWhitespace(text)) {
208
+ text = anchor.getAttribute(ARIA_DESCRIPTION);
218
209
  }
219
210
 
220
- if (isNullableOrWhitespace(content)) {
211
+ if (isNullableOrWhitespace(text)) {
221
212
  return;
222
213
  }
223
214
 
224
215
  const paragraph = document.createElement('p');
225
216
 
226
- paragraph.textContent = content;
217
+ paragraph.textContent = text;
227
218
 
228
219
  return [paragraph];
229
220
  }
230
221
 
231
- function getState(anchor: HTMLElement, content: HTMLElement): OuiTooltipState {
222
+ function getState(anchor: HTMLElement, elements: HTMLElement[]): OuiTooltipState {
232
223
  const state: OuiTooltipState = {
233
224
  anchor,
234
- content,
225
+ elements,
235
226
  floatable: createEmbeddedFloatable(anchor, content, options),
236
227
  tooltip: null as never,
237
228
  };
@@ -273,7 +264,7 @@ function onFocusout(): void {
273
264
  return;
274
265
  }
275
266
 
276
- closeTooltip(activeState);
267
+ closeTooltip(true, activeState);
277
268
 
278
269
  activeState = undefined;
279
270
  activeTooltip = undefined;
@@ -284,6 +275,14 @@ function onPointermove(event: Event): void {
284
275
  activate(event, false);
285
276
  }
286
277
 
278
+ function onToggle(event: ToggleEvent): void {
279
+ if (event.newState === FLOATABLE_STATE_OPEN) {
280
+ content.setAttribute(ATTRIBUTE_CONTENT_OPEN, '');
281
+ } else {
282
+ content.removeAttribute(ATTRIBUTE_CONTENT_OPEN);
283
+ }
284
+ }
285
+
287
286
  function removeTooltip(element: HTMLElement): void {
288
287
  const state = states.get(element);
289
288
 
@@ -334,11 +333,14 @@ const SELECTOR = `[${ATTRIBUTE}]`;
334
333
 
335
334
  const SELECTOR_CONTENT = `[${ATTRIBUTE_CONTENT}]`;
336
335
 
336
+ const content = getContent();
337
+
337
338
  const states = new WeakMap<HTMLElement, OuiTooltipState>();
338
339
 
339
340
  const options: OuiFloatableOptions = {
340
341
  attribute: `${ATTRIBUTE}-position`,
341
342
  position: 'above',
343
+ reusable: true,
342
344
  };
343
345
 
344
346
  let delay = 500;
@@ -355,6 +357,10 @@ let focusTimer: number | undefined;
355
357
 
356
358
  // #region Initialization
357
359
 
360
+ document.body.append(content);
361
+
362
+ on(content, 'toggle', onToggle);
363
+
358
364
  on(document, 'focusin', onFocusin);
359
365
  on(document, 'focusout', onFocusout);
360
366
  on(document, 'pointermove', onPointermove);
@@ -1,2 +0,0 @@
1
- import { a as createEmbeddedFloatable, c as removeFloatable, i as OuiFloatablePosition, n as OuiFloatable, o as createFloatable, r as OuiFloatableOptions, s as getOnBeforeToggleListener, t as ATTRIBUTE_FLOATABLE } from "../embedded-CSOh5njI.mjs";
2
- export { ATTRIBUTE_FLOATABLE, OuiFloatable, OuiFloatableOptions, OuiFloatablePosition, createEmbeddedFloatable, createFloatable, getOnBeforeToggleListener, removeFloatable };
@@ -1,2 +0,0 @@
1
- import { i as OuiFloatablePosition, n as OuiFloatable, o as createFloatable } from "../embedded-CSOh5njI.mjs";
2
- export { type OuiFloatable, type OuiFloatablePosition, createFloatable };
@@ -1,2 +0,0 @@
1
- import { createFloatable } from "./embedded.mjs";
2
- export { createFloatable };
@@ -1,2 +0,0 @@
1
- import { a as createFocusTrap, i as OuiFocusTrap, n as ATTRIBUTE_FOCUSTRAP_CONTAIN, o as removeFocusTrap, r as ATTRIBUTE_FOCUSTRAP_NOESCAPE, t as ATTRIBUTE_FOCUSTRAP } from "../embedded-CHK82Uh5.mjs";
2
- export { ATTRIBUTE_FOCUSTRAP, ATTRIBUTE_FOCUSTRAP_CONTAIN, ATTRIBUTE_FOCUSTRAP_NOESCAPE, OuiFocusTrap, createFocusTrap, removeFocusTrap };
@@ -1,2 +0,0 @@
1
- import { a as createFocusTrap, i as OuiFocusTrap } from "../embedded-CHK82Uh5.mjs";
2
- export { type OuiFocusTrap, createFocusTrap };
@@ -1,6 +0,0 @@
1
- import { attributable } from "../internal/attributable.mjs";
2
- import { ATTRIBUTE_FOCUSTRAP, createFocusTrap, removeFocusTrap } from "./embedded.mjs";
3
- //#region src/js/focus-trap/standalone.ts
4
- attributable(ATTRIBUTE_FOCUSTRAP, createFocusTrap, removeFocusTrap);
5
- //#endregion
6
- export { createFocusTrap };
@@ -1,101 +0,0 @@
1
- import { EventPosition, PlainObject } from "@oscarpalmer/atoms/models";
2
-
3
- //#region src/js/sortable.d.ts
4
- declare class OuiSortable extends OuiDraggable {
5
- connections: string | null;
6
- origin: HTMLElement | undefined;
7
- get dragged(): HTMLElement;
8
- constructor(element: HTMLElement);
9
- }
10
- //#endregion
11
- //#region src/js/internal/draggable.d.ts
12
- declare abstract class OuiDraggable {
13
- prefix: string;
14
- element: HTMLElement;
15
- options: DraggableOptions;
16
- container: HTMLElement | undefined;
17
- hasHandles: boolean | undefined;
18
- horizontal: boolean;
19
- vertical: boolean;
20
- abstract readonly dragged: HTMLElement;
21
- abstract origin: HTMLElement | undefined;
22
- constructor(prefix: string, element: HTMLElement, options: DraggableOptions);
23
- destroy(): void;
24
- }
25
- type DragBegin = (event: MouseEvent | TouchEvent, state: DraggableState, draggable: OuiDraggable, element: HTMLElement, handle: HTMLElement, position: EventPosition) => void;
26
- type DragCancel = (state: DraggableState, draggable: OuiDraggable) => void;
27
- type DragEnd = (event: MouseEvent | TouchEvent, state: DraggableState, draggable: OuiDraggable, reset: () => void) => void;
28
- type DragMove = (event: MouseEvent | TouchEvent, state: DraggableState, draggable: OuiDraggable, position: DragMovePosition) => PlainObject | undefined;
29
- type DragMovePosition = {
30
- calculated: EventPosition;
31
- original: EventPosition;
32
- };
33
- type DraggableBound<Property extends keyof DraggableInstances = keyof DraggableInstances, Instance extends DraggableInstances[Property] = DraggableInstances[Property]> = {
34
- constructor: new (element: HTMLElement) => Instance;
35
- property: Property;
36
- };
37
- type DraggableInstances = {
38
- movable?: OuiMovable;
39
- sortable?: OuiSortable;
40
- };
41
- type DraggableOptions = {
42
- container: DraggableOptionsContainer;
43
- direction: DraggableOptionsDirection;
44
- drag: DraggableOptionsDrag;
45
- position: DraggableOptionsPosition;
46
- };
47
- type DraggableOptionsContainer = {
48
- attribute: string;
49
- map: Map<HTMLElement, Set<OuiDraggable>>;
50
- onDestroy?: DraggableOptionsContainerOnDestroy;
51
- onInitialize?: DraggableOptionsContainerOnInitialize;
52
- };
53
- type DraggableOptionsContainerOnDestroy = (draggable: OuiDraggable, container: HTMLElement, empty: boolean) => void;
54
- type DraggableOptionsContainerOnInitialize = (draggable: OuiDraggable) => void;
55
- type DraggableOptionsDirection = {
56
- attribute: string;
57
- onAfter?: DraggableOptionsDirectionOnAfter;
58
- };
59
- type DraggableOptionsDirectionOnAfter = (draggable: OuiDraggable) => void;
60
- type DraggableOptionsDrag = {
61
- onBegin: DragBegin;
62
- onCancel: DragCancel;
63
- onEnd: DragEnd;
64
- onMove: DragMove;
65
- };
66
- type DraggableOptionsPosition = {
67
- getOffset: DraggableOptionsPositionGetOffset;
68
- getOriginal: DraggableOptionsPositionGetOriginal;
69
- };
70
- type DraggableOptionsPositionGetOffset = (state: DraggableState, draggable: OuiDraggable, element: HTMLElement, position: EventPosition) => EventPosition;
71
- type DraggableOptionsPositionGetOriginal = (state: DraggableState, draggable: OuiDraggable, position: EventPosition) => EventPosition;
72
- type DraggableState = {
73
- container: DOMRect | undefined;
74
- element: DraggableStateElement | undefined;
75
- instances: WeakMap<HTMLElement, DraggableInstances>;
76
- offset: EventPosition | undefined;
77
- original: EventPosition | undefined;
78
- };
79
- type DraggableStateElement = {
80
- node: HTMLElement;
81
- rectangle: DOMRect;
82
- };
83
- declare function addDraggable<Property extends keyof DraggableInstances, Instance extends DraggableInstances[Property]>(this: DraggableBound<Property, Instance>, element: HTMLElement): void;
84
- declare function removeDraggable<Property extends keyof DraggableInstances, Instance extends DraggableInstances[Property]>(this: {
85
- constructor: new (element: HTMLElement) => Instance;
86
- property: Property;
87
- }, element: HTMLElement): void;
88
- //#endregion
89
- //#region src/js/movable.d.ts
90
- declare class OuiMovable extends OuiDraggable {
91
- inset: string;
92
- moved: boolean;
93
- offset: Partial<EventPosition> | undefined;
94
- position: string;
95
- get dragged(): HTMLElement;
96
- get origin(): HTMLElement | undefined;
97
- constructor(element: HTMLElement);
98
- destroy(): void;
99
- }
100
- //#endregion
101
- export { OuiDraggable as a, OuiSortable as c, DraggableState as i, DragMovePosition as n, addDraggable as o, DraggableBound as r, removeDraggable as s, OuiMovable as t };
@@ -1,2 +0,0 @@
1
- import { t as OuiMovable } from "./movable-dNqBctx3.mjs";
2
- export { OuiMovable };
@@ -1,152 +0,0 @@
1
- import { attributable } from "./internal/attributable.mjs";
2
- import { OuiDraggable, addDraggable, removeDraggable } from "./internal/draggable.mjs";
3
- import { getPosition, on } from "@oscarpalmer/toretto/event";
4
- //#region src/js/movable.ts
5
- var OuiMovable = class extends OuiDraggable {
6
- inset;
7
- moved = false;
8
- offset;
9
- position;
10
- get dragged() {
11
- return this.element;
12
- }
13
- get origin() {
14
- return this.element;
15
- }
16
- constructor(element) {
17
- super("move", element, {
18
- container: {
19
- attribute: ATTRIBUTE_CONTAINER,
20
- map: CONTAINERS,
21
- onDestroy: destroyContainer,
22
- onInitialize: initializeContainer
23
- },
24
- direction: {
25
- attribute: ATTRIBUTE_DIRECTION,
26
- onAfter: afterDirection
27
- },
28
- drag: {
29
- onBegin,
30
- onCancel,
31
- onEnd,
32
- onMove
33
- },
34
- position: {
35
- getOffset: getOffsetPosition,
36
- getOriginal: getOriginalPosition
37
- }
38
- });
39
- this.hasHandles = element.querySelector(SELECTOR_HANDLE) != null;
40
- this.inset = element.style.inset;
41
- this.position = element.style.position;
42
- }
43
- destroy() {
44
- super.destroy();
45
- MOVED.delete(this);
46
- this.element.style.inset = this.inset;
47
- this.element.style.position = this.position;
48
- }
49
- };
50
- function afterDirection(draggable) {
51
- const container = draggable.container?.getBoundingClientRect();
52
- if (container != null) setOffset(draggable, container);
53
- }
54
- function destroyContainer(_, container, empty) {
55
- if (empty) resizer.unobserve(container);
56
- }
57
- function getOffsetPosition(state, _, __, position) {
58
- return {
59
- x: position.x - (state.element?.rectangle.left ?? 0),
60
- y: position.y - (state.element?.rectangle.top ?? 0)
61
- };
62
- }
63
- function getOriginalPosition(state) {
64
- return {
65
- x: state.element?.rectangle.left ?? 0,
66
- y: state.element?.rectangle.top ?? 0
67
- };
68
- }
69
- function initializeContainer(draggable) {
70
- resizer.observe(draggable.container);
71
- }
72
- function onBegin() {}
73
- function onCancel(state, draggable) {
74
- const { element, inset, moved, position } = draggable;
75
- const { x, y } = state.original ?? {
76
- x: 0,
77
- y: 0
78
- };
79
- if (moved) element.style.inset = `${y}px auto auto ${x}px`;
80
- else {
81
- element.style.position = position;
82
- element.style.inset = inset;
83
- }
84
- }
85
- function onEnd(event, state, draggable, reset) {
86
- const movable = draggable;
87
- if (!movable.moved) {
88
- movable.moved = true;
89
- if (movable.container != null) MOVED.add(movable);
90
- }
91
- const container = movable.container?.getBoundingClientRect();
92
- if (container != null) setOffset(movable, container);
93
- const end = new CustomEvent(EVENT_END, {
94
- detail: {
95
- from: { ...state.original },
96
- to: getPosition(event)
97
- },
98
- cancelable: true
99
- });
100
- movable.element.dispatchEvent(end);
101
- setTimeout(() => {
102
- if (end.defaultPrevented) onCancel(state, draggable);
103
- reset();
104
- });
105
- }
106
- function onMove(_, state, __, position) {
107
- return {
108
- from: { ...state.original },
109
- to: { ...position.calculated }
110
- };
111
- }
112
- function onResize(entries) {
113
- const { length } = entries;
114
- for (let index = 0; index < length; index += 1) {
115
- const entry = entries[index];
116
- const set = CONTAINERS.get(entry.target);
117
- if (set == null) continue;
118
- for (const movable of set) reposition(movable);
119
- }
120
- }
121
- function onScroll() {
122
- for (const moved of MOVED) reposition(moved);
123
- }
124
- function reposition(movable) {
125
- if (!movable.moved || movable.container == null) return;
126
- const container = movable.container.getBoundingClientRect();
127
- const x = container.left + (movable.offset?.x ?? 0);
128
- const y = container.top + (movable.offset?.y ?? 0);
129
- movable.element.style.inset = `${y}px auto auto ${x}px`;
130
- }
131
- function setOffset(movable, container) {
132
- movable.offset = {};
133
- const element = movable.element.getBoundingClientRect();
134
- movable.offset.y = element.top - container.top;
135
- movable.offset.x = element.left - container.left;
136
- }
137
- const ATTRIBUTE = "oui-movable";
138
- const ATTRIBUTE_CONTAINER = `${ATTRIBUTE}-container`;
139
- const ATTRIBUTE_DIRECTION = `${ATTRIBUTE}-direction`;
140
- const CONTAINERS = /* @__PURE__ */ new Map();
141
- const EVENT_END = "move:end";
142
- const MOVED = /* @__PURE__ */ new Set();
143
- const SELECTOR_HANDLE = `[${ATTRIBUTE}-handle]`;
144
- const bound = {
145
- constructor: OuiMovable,
146
- property: "movable"
147
- };
148
- const resizer = new ResizeObserver(onResize);
149
- attributable(ATTRIBUTE, addDraggable.bind(bound), removeDraggable.bind(bound));
150
- on(document, "scroll", onScroll);
151
- //#endregion
152
- export { OuiMovable };
@@ -1,2 +0,0 @@
1
- import { c as OuiSortable } from "./movable-dNqBctx3.mjs";
2
- export { OuiSortable };
@@ -1 +0,0 @@
1
- export {createFloatable, type OuiFloatable, type OuiFloatablePosition} from './embedded';
@@ -1,6 +0,0 @@
1
- import {attributable} from '../internal/attributable';
2
- import {ATTRIBUTE_FOCUSTRAP, createFocusTrap, removeFocusTrap, type OuiFocusTrap} from './embedded';
3
-
4
- attributable(ATTRIBUTE_FOCUSTRAP, createFocusTrap, removeFocusTrap);
5
-
6
- export {createFocusTrap, type OuiFocusTrap};