@oscarpalmer/oui 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) 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 +6 -0
  5. package/dist/js/dialog.mjs +23 -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} +22 -17
  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-ai6cqURc.d.mts → floatable.embedded-YxGwzgbE.d.mts} +13 -10
  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 +3 -2
  26. package/dist/js/popover.mjs +8 -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.d.mts +24 -0
  32. package/dist/js/splitter.mjs +33 -9
  33. package/dist/js/toolbar.mjs +6 -6
  34. package/dist/js/tooltip.d.mts +12 -2
  35. package/dist/js/tooltip.mjs +49 -33
  36. package/package.json +11 -11
  37. package/src/css/floatable.scss +0 -2
  38. package/src/css/message.scss +1 -0
  39. package/src/css/reset.scss +1 -0
  40. package/src/js/dialog.ts +42 -1
  41. package/src/js/floatable/{embedded.ts → floatable.embedded.ts} +26 -18
  42. package/src/js/floatable/floatable.standalone.ts +6 -0
  43. package/src/js/focus-trap/{embedded.ts → focus-trap.embedded.ts} +20 -17
  44. package/src/js/focus-trap/focus-trap.standalone.ts +1 -0
  45. package/src/js/index.ts +4 -4
  46. package/src/js/internal/draggable.ts +309 -168
  47. package/src/js/movable/movable.embedded.ts +328 -0
  48. package/src/js/movable/movable.standalone.ts +2 -0
  49. package/src/js/popover.ts +11 -2
  50. package/src/js/{sortable.ts → sortable/sortable.embedded.ts} +170 -103
  51. package/src/js/sortable/sortable.standalone.ts +2 -0
  52. package/src/js/splitter.ts +28 -4
  53. package/src/js/tooltip.ts +66 -43
  54. package/dist/js/floatable/embedded.d.mts +0 -2
  55. package/dist/js/floatable/standalone.d.mts +0 -2
  56. package/dist/js/floatable/standalone.mjs +0 -2
  57. package/dist/js/focus-trap/embedded.d.mts +0 -2
  58. package/dist/js/focus-trap/standalone.d.mts +0 -2
  59. package/dist/js/focus-trap/standalone.mjs +0 -6
  60. package/dist/js/movable-dNqBctx3.d.mts +0 -101
  61. package/dist/js/movable.d.mts +0 -2
  62. package/dist/js/movable.mjs +0 -152
  63. package/dist/js/sortable.d.mts +0 -2
  64. package/src/js/floatable/standalone.ts +0 -1
  65. package/src/js/focus-trap/standalone.ts +0 -6
  66. 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,18 @@ 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();
24
+ }
25
+
26
+ /**
27
+ * Open or close the tooltip
28
+ */
29
+ set open(value: boolean) {
30
+ if (value === true) {
31
+ this.show();
32
+ } else if (value === false) {
33
+ this.hide();
34
+ }
23
35
  }
24
36
 
25
37
  constructor(state: OuiTooltipState) {
@@ -45,7 +57,7 @@ class OuiTooltip {
45
57
 
46
58
  type OuiTooltipState = {
47
59
  anchor: HTMLElement;
48
- content: HTMLElement;
60
+ elements: HTMLElement[];
49
61
  floatable: OuiFloatable;
50
62
  timer?: number;
51
63
  tooltip: OuiTooltip;
@@ -56,12 +68,12 @@ type OuiTooltipState = {
56
68
  // #region Functions
57
69
 
58
70
  function activate(event: Event, focus: boolean): void {
59
- const anchor = findAncestor(event, SELECTOR) as HTMLElement | null;
60
- 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;
61
73
 
62
- if (anchor == null && content == null) {
74
+ if (targetAnchor == null && targetContent == null) {
63
75
  if (!focused) {
64
- closeTooltip(activeState);
76
+ closeTooltip(true, activeState);
65
77
 
66
78
  activeState = undefined;
67
79
  activeTooltip = undefined;
@@ -70,7 +82,7 @@ function activate(event: Event, focus: boolean): void {
70
82
  return;
71
83
  }
72
84
 
73
- const state = states.get((anchor ?? content)!);
85
+ const state = states.get((targetAnchor ?? targetContent)!);
74
86
 
75
87
  if (state == null || state.tooltip === activeTooltip) {
76
88
  return;
@@ -78,7 +90,7 @@ function activate(event: Event, focus: boolean): void {
78
90
 
79
91
  const shouldDelay = activeTooltip == null;
80
92
 
81
- closeTooltip(activeState);
93
+ closeTooltip(false, activeState);
82
94
 
83
95
  activeState = state;
84
96
  activeTooltip = state.tooltip;
@@ -87,14 +99,14 @@ function activate(event: Event, focus: boolean): void {
87
99
 
88
100
  state.timer = setTimeout(
89
101
  () => {
90
- state.content.showPopover({
91
- source: state.anchor as HTMLElement,
92
- });
102
+ content.innerHTML = '';
103
+
104
+ content.append(...state.elements);
105
+
106
+ state.floatable.show();
93
107
 
94
108
  setTimeout(() => {
95
109
  state.floatable.update();
96
-
97
- state.content.setAttribute(ATTRIBUTE_CONTENT_OPEN, '');
98
110
  });
99
111
  },
100
112
  shouldDelay ? delay : 0,
@@ -107,7 +119,7 @@ function addTooltip(element: HTMLElement): void {
107
119
  }
108
120
  }
109
121
 
110
- function closeTooltip(state?: OuiTooltipState): void {
122
+ function closeTooltip(clear: boolean, state?: OuiTooltipState): void {
111
123
  if (state == null) {
112
124
  return;
113
125
  }
@@ -116,30 +128,28 @@ function closeTooltip(state?: OuiTooltipState): void {
116
128
  clearTimeout(state.timer);
117
129
  }
118
130
 
119
- state.content?.hidePopover();
120
- state.content?.removeAttribute(ATTRIBUTE_CONTENT_OPEN);
131
+ if (clear) {
132
+ content?.hidePopover();
133
+ }
121
134
  }
122
135
 
123
136
  function createTooltip(anchor: HTMLElement): void {
124
- const content = getContent(anchor);
137
+ const elements = getElements(anchor);
125
138
 
126
- if (content == null) {
139
+ if (elements == null) {
127
140
  return;
128
141
  }
129
142
 
130
- anchor.insertAdjacentElement('afterend', content);
131
-
132
- states.set(anchor, getState(anchor, content));
143
+ states.set(anchor, getState(anchor, elements));
133
144
  }
134
145
 
135
146
  function destroyTooltip(state: OuiTooltipState): void {
136
147
  clearTimeout(state.timer);
137
148
 
138
- state.content.remove();
139
149
  state.floatable.destroy();
140
150
 
141
151
  state.anchor = undefined as never;
142
- state.content = undefined as never;
152
+ state.elements = undefined as never;
143
153
  state.floatable = undefined as never;
144
154
  state.tooltip = undefined as never;
145
155
  }
@@ -167,13 +177,7 @@ function findElements(attribute: string | null): HTMLElement[] {
167
177
  return elements;
168
178
  }
169
179
 
170
- function getContent(anchor: HTMLElement): HTMLElement | undefined {
171
- const elements = getElements(anchor);
172
-
173
- if (elements == null) {
174
- return;
175
- }
176
-
180
+ function getContent(): HTMLElement {
177
181
  const content = createElement(CONTENT_TAGNAME, {
178
182
  popover: 'hint',
179
183
  role: 'tooltip',
@@ -182,8 +186,6 @@ function getContent(anchor: HTMLElement): HTMLElement | undefined {
182
186
 
183
187
  content.setAttribute(ATTRIBUTE_CONTENT, '');
184
188
 
185
- content.append(...elements);
186
-
187
189
  return content;
188
190
  }
189
191
 
@@ -191,36 +193,36 @@ function getElements(anchor: HTMLElement): HTMLElement[] | undefined {
191
193
  let elements = findElements(anchor.getAttribute(ARIA_LABELLEDBY));
192
194
 
193
195
  if (elements.length > 0) {
194
- return elements.map(element => element.cloneNode(true)) as HTMLElement[];
196
+ return elements;
195
197
  }
196
198
 
197
199
  elements = findElements(anchor.getAttribute(ARIA_DESCRIBEDBY));
198
200
 
199
201
  if (elements.length > 0) {
200
- return elements.map(element => element.cloneNode(true)) as HTMLElement[];
202
+ return elements;
201
203
  }
202
204
 
203
- let content = anchor.getAttribute(ARIA_LABEL);
205
+ let text = anchor.getAttribute(ARIA_LABEL);
204
206
 
205
- if (isNullableOrWhitespace(content)) {
206
- content = anchor.getAttribute(ARIA_DESCRIPTION);
207
+ if (isNullableOrWhitespace(text)) {
208
+ text = anchor.getAttribute(ARIA_DESCRIPTION);
207
209
  }
208
210
 
209
- if (isNullableOrWhitespace(content)) {
211
+ if (isNullableOrWhitespace(text)) {
210
212
  return;
211
213
  }
212
214
 
213
215
  const paragraph = document.createElement('p');
214
216
 
215
- paragraph.textContent = content;
217
+ paragraph.textContent = text;
216
218
 
217
219
  return [paragraph];
218
220
  }
219
221
 
220
- function getState(anchor: HTMLElement, content: HTMLElement): OuiTooltipState {
222
+ function getState(anchor: HTMLElement, elements: HTMLElement[]): OuiTooltipState {
221
223
  const state: OuiTooltipState = {
222
224
  anchor,
223
- content,
225
+ elements,
224
226
  floatable: createEmbeddedFloatable(anchor, content, options),
225
227
  tooltip: null as never,
226
228
  };
@@ -230,6 +232,12 @@ function getState(anchor: HTMLElement, content: HTMLElement): OuiTooltipState {
230
232
  return state;
231
233
  }
232
234
 
235
+ /**
236
+ * Get the _OuiTooltip_ for an element
237
+ *
238
+ * @param element Element to get _OuiTooltip_ for
239
+ * @returns _OuiTooltip_ instance
240
+ */
233
241
  function getTooltip(element: HTMLElement): OuiTooltip | undefined {
234
242
  return states.get(element)?.tooltip;
235
243
  }
@@ -256,7 +264,7 @@ function onFocusout(): void {
256
264
  return;
257
265
  }
258
266
 
259
- closeTooltip(activeState);
267
+ closeTooltip(true, activeState);
260
268
 
261
269
  activeState = undefined;
262
270
  activeTooltip = undefined;
@@ -267,6 +275,14 @@ function onPointermove(event: Event): void {
267
275
  activate(event, false);
268
276
  }
269
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
+
270
286
  function removeTooltip(element: HTMLElement): void {
271
287
  const state = states.get(element);
272
288
 
@@ -317,11 +333,14 @@ const SELECTOR = `[${ATTRIBUTE}]`;
317
333
 
318
334
  const SELECTOR_CONTENT = `[${ATTRIBUTE_CONTENT}]`;
319
335
 
336
+ const content = getContent();
337
+
320
338
  const states = new WeakMap<HTMLElement, OuiTooltipState>();
321
339
 
322
340
  const options: OuiFloatableOptions = {
323
341
  attribute: `${ATTRIBUTE}-position`,
324
342
  position: 'above',
343
+ reusable: true,
325
344
  };
326
345
 
327
346
  let delay = 500;
@@ -338,6 +357,10 @@ let focusTimer: number | undefined;
338
357
 
339
358
  // #region Initialization
340
359
 
360
+ document.body.append(content);
361
+
362
+ on(content, 'toggle', onToggle);
363
+
341
364
  on(document, 'focusin', onFocusin);
342
365
  on(document, 'focusout', onFocusout);
343
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-ai6cqURc.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-ai6cqURc.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};