@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
@@ -1,57 +1,57 @@
1
- //#region src/js/focus-trap/embedded.d.ts
1
+ //#region src/js/focus-trap/focus-trap.embedded.d.ts
2
2
  declare class OuiFocusTrap {
3
3
  #private;
4
4
  /**
5
- * Is focused maintained within the _FocusTrap_ when clicking outside of it?
5
+ * Is focused maintained within the _focus trap_ when clicking outside of it?
6
6
  */
7
7
  get contain(): boolean;
8
8
  /**
9
- * Should focus be maintained within the _FocusTrap_ when clicking outside of it?
9
+ * Should focus be maintained within the _focus trap_ when clicking outside of it?
10
10
  */
11
11
  set contain(value: boolean);
12
12
  /**
13
- * Is the _FocusTrap_ disabled?
13
+ * Is the _focus trap_ disabled?
14
14
  */
15
15
  get disabled(): boolean;
16
16
  /**
17
- * Should the _FocusTrap_ be disabled?
17
+ * Should the _focus trap_ be disabled?
18
18
  */
19
19
  set disabled(value: boolean);
20
20
  /**
21
- * Is focus allowed to escape when pressing _Escape_ within the _FocusTrap_?
21
+ * Is focus allowed to escape when pressing _Escape_ within the _focus trap_?
22
22
  */
23
23
  get noescape(): boolean;
24
24
  /**
25
- * Should the _FocusTrap_ allow focus to escape when pressing _Escape_?
25
+ * Should the _focus trap_ allow focus to escape when pressing _Escape_?
26
26
  */
27
27
  set noescape(value: boolean);
28
28
  constructor(state: OuiFocusTrapState);
29
29
  /**
30
- * Destroys the _FocusTrap_
30
+ * Destroys the _focus trap_
31
31
  */
32
32
  destroy(): void;
33
33
  /**
34
- * Disables the _FocusTrap_
34
+ * Disables the _focus trap_
35
35
  */
36
36
  disable(): void;
37
37
  /**
38
- * Enables the _FocusTrap_
38
+ * Enables the _focus trap_
39
39
  */
40
40
  enable(): void;
41
41
  /**
42
- * Focuses the _FocusTrap_
42
+ * Focuses the _focus trap_
43
43
  *
44
- * @param last When `true`, focuses the last focusable element within the _FocusTrap_ instead of the first
44
+ * @param last When `true`, focuses the last focusable element within the _focus trap_ instead of the first
45
45
  */
46
46
  focus(last: boolean): void;
47
47
  }
48
48
  type OuiFocusTrapOptions = {
49
49
  /**
50
- * Should focus be maintained within the _FocusTrap_ when clicking outside of it?
50
+ * Should focus be maintained within the _focus trap_ when clicking outside of it?
51
51
  */
52
52
  contain?: boolean;
53
53
  /**
54
- * Should the _FocusTrap_ allow focus to escape when pressing _Escape_?
54
+ * Should the _focus trap_ allow focus to escape when pressing _Escape_?
55
55
  */
56
56
  noescape?: boolean;
57
57
  };
@@ -61,11 +61,11 @@ type OuiFocusTrapState = {
61
61
  options: Required<OuiFocusTrapOptions>;
62
62
  };
63
63
  /**
64
- * Creates _(or retrieves)_ a _FocusTrap_ for an element
64
+ * Creates _(or retrieves)_ a _focus trap_ for an element
65
65
  *
66
66
  * @param element Element to trap focus within
67
- * @param options _FocusTrap_ options
68
- * @returns _FocusTrap_ instance
67
+ * @param options _Focus trap_ options
68
+ * @returns _Focus trap_ instance
69
69
  */
70
70
  declare function createFocusTrap(element: HTMLElement, options?: OuiFocusTrapOptions): OuiFocusTrap;
71
71
  declare function removeFocusTrap(element: HTMLElement): void;
@@ -73,4 +73,4 @@ declare const ATTRIBUTE_FOCUSTRAP = "oui-focus-trap";
73
73
  declare const ATTRIBUTE_FOCUSTRAP_CONTAIN = "oui-focus-trap-contain";
74
74
  declare const ATTRIBUTE_FOCUSTRAP_NOESCAPE = "oui-focus-trap-noescape";
75
75
  //#endregion
76
- export { createFocusTrap as a, OuiFocusTrap as i, ATTRIBUTE_FOCUSTRAP_CONTAIN as n, removeFocusTrap as o, ATTRIBUTE_FOCUSTRAP_NOESCAPE as r, ATTRIBUTE_FOCUSTRAP as t };
76
+ export { OuiFocusTrapOptions as a, OuiFocusTrap as i, ATTRIBUTE_FOCUSTRAP_CONTAIN as n, createFocusTrap as o, ATTRIBUTE_FOCUSTRAP_NOESCAPE as r, removeFocusTrap as s, ATTRIBUTE_FOCUSTRAP as t };
@@ -1,7 +1,8 @@
1
+ import { g as createMovable, h as OuiMovable, t as CreateOuiDraggableOptions } from "./draggable-zszaW1qS.mjs";
1
2
  import { OuiDialog, getDialog } from "./dialog.mjs";
2
- import { i as OuiFloatablePosition, n as OuiFloatable, o as createFloatable } from "./embedded-ai6cqURc.mjs";
3
- import { a as createFocusTrap, i as OuiFocusTrap } from "./embedded-CHK82Uh5.mjs";
3
+ import { c as createFloatable, i as OuiFloatable, n as CreateOuiFloatableOptions, o as OuiFloatablePosition } from "./floatable.embedded-YxGwzgbE.mjs";
4
+ import { a as OuiFocusTrapOptions, i as OuiFocusTrap, o as createFocusTrap } from "./focus-trap.embedded-DR8NpZfr.mjs";
4
5
  import { OuiPopover, getPopover } from "./popover.mjs";
5
6
  import { OuiSplitterElement } from "./splitter.mjs";
6
7
  import { OuiTooltip, getTooltip, setTooltipDelay } from "./tooltip.mjs";
7
- export { type OuiDialog, type OuiFloatable, type OuiFloatablePosition, type OuiFocusTrap, type OuiPopover, OuiSplitterElement, type OuiTooltip, createFloatable, createFocusTrap, getDialog, getPopover, getTooltip, setTooltipDelay };
8
+ export { type CreateOuiFloatableOptions, type CreateOuiDraggableOptions as CreateOuiMovableOptions, type OuiDialog, type OuiFloatable, type OuiFloatablePosition, type OuiFocusTrap, type OuiFocusTrapOptions, type OuiMovable, type OuiPopover, OuiSplitterElement, type OuiTooltip, createFloatable, createFocusTrap, createMovable, getDialog, getPopover, getTooltip, setTooltipDelay };
package/dist/js/index.mjs CHANGED
@@ -1,12 +1,13 @@
1
- import { createFloatable } from "./floatable/embedded.mjs";
1
+ import { createFloatable } from "./floatable/floatable.embedded.mjs";
2
+ import { createMovable } from "./movable/movable.embedded.mjs";
3
+ import "./movable/movable.standalone.mjs";
2
4
  import { getDialog } from "./dialog.mjs";
3
- import "./movable.mjs";
4
- import "./sortable.mjs";
5
+ import "./sortable/sortable.embedded.mjs";
5
6
  import "./toolbar.mjs";
6
- import "./floatable/standalone.mjs";
7
- import { createFocusTrap } from "./focus-trap/embedded.mjs";
8
- import "./focus-trap/standalone.mjs";
7
+ import "./floatable/floatable.standalone.mjs";
8
+ import { createFocusTrap } from "./focus-trap/focus-trap.embedded.mjs";
9
+ import "./focus-trap/focus-trap.standalone.mjs";
9
10
  import { getPopover } from "./popover.mjs";
10
11
  import { OuiSplitterElement } from "./splitter.mjs";
11
12
  import { getTooltip, setTooltipDelay } from "./tooltip.mjs";
12
- export { OuiSplitterElement, createFloatable, createFocusTrap, getDialog, getPopover, getTooltip, setTooltipDelay };
13
+ export { OuiSplitterElement, createFloatable, createFocusTrap, createMovable, getDialog, getPopover, getTooltip, setTooltipDelay };
@@ -1,2 +1,2 @@
1
- import { a as OuiDraggable, i as DraggableState, n as DragMovePosition, o as addDraggable, r as DraggableBound, s as removeDraggable } from "../movable-dNqBctx3.mjs";
2
- export { DragMovePosition, DraggableBound, DraggableState, OuiDraggable, addDraggable, removeDraggable };
1
+ import { a as OuiDraggableGlobals, c as addDraggable, i as OuiDraggableBound, l as getDraggableStates, n as OuiDragMovePosition, o as OuiDraggableItem, r as OuiDraggable, s as OuiDraggableState, t as CreateOuiDraggableOptions, u as removeDraggable } from "../draggable-zszaW1qS.mjs";
2
+ export { CreateOuiDraggableOptions, OuiDragMovePosition, OuiDraggable, OuiDraggableBound, OuiDraggableGlobals, OuiDraggableItem, OuiDraggableState, addDraggable, getDraggableStates, removeDraggable };
@@ -1,52 +1,84 @@
1
1
  import { getPosition, on } from "@oscarpalmer/toretto/event";
2
+ import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
2
3
  import { clamp } from "@oscarpalmer/atoms/number";
3
4
  import { findAncestor } from "@oscarpalmer/toretto/find";
4
5
  import { toggleStyles } from "@oscarpalmer/toretto/style";
5
6
  import supportsTouch from "@oscarpalmer/toretto/touch";
6
7
  //#region src/js/internal/draggable.ts
7
8
  var OuiDraggable = class {
8
- prefix;
9
- element;
10
- options;
11
- container;
12
- hasHandles;
13
- horizontal = true;
14
- vertical = true;
15
- constructor(prefix, element, options) {
16
- this.prefix = prefix;
17
- this.element = element;
18
- this.options = options;
19
- setContainer(this, options);
20
- setDirection(this, options);
9
+ #destroyed = false;
10
+ #name;
11
+ #state;
12
+ get element() {
13
+ return this.#state.element;
14
+ }
15
+ constructor(name, event, attribute, element, options, extras) {
16
+ this.#name = name;
17
+ this.#state = {
18
+ ...extras,
19
+ attribute,
20
+ element,
21
+ event,
22
+ options,
23
+ horizontal: true,
24
+ vertical: true,
25
+ styling: toggleStyles(element, styles)
26
+ };
27
+ const item = {
28
+ instance: this,
29
+ state: this.#state
30
+ };
31
+ setContainer(item);
32
+ setDirection(item);
33
+ element.setAttribute(attribute, "");
34
+ let states = globals.states.get(element);
35
+ states ??= {};
36
+ states[this.#name] = this.#state;
37
+ globals.states.set(element, states);
21
38
  }
22
39
  destroy() {
23
- unsetContainer(this, this.options);
24
- this.container = void 0;
25
- this.element = void 0;
26
- this.options = void 0;
40
+ if (this.#destroyed) return;
41
+ this.#destroyed = true;
42
+ destroyInstance(this, this.#state);
27
43
  }
28
44
  };
29
- function addDraggable(element) {
30
- let instances = state.instances.get(element);
45
+ function addDraggable(element, options) {
46
+ let instances = globals.instances.get(element);
31
47
  if (instances == null) {
32
48
  instances = {};
33
- state.instances.set(element, instances);
49
+ globals.instances.set(element, instances);
34
50
  }
35
- instances[this.property] ??= new this.constructor(element);
51
+ instances[this.property] ??= new this.constructor(element, options);
52
+ return instances[this.property];
53
+ }
54
+ function destroyInstance(instance, state) {
55
+ unsetContainer({
56
+ instance,
57
+ state
58
+ });
59
+ state.element.removeAttribute(state.attribute);
60
+ state.styling.remove();
61
+ state.container = void 0;
62
+ state.element = void 0;
63
+ state.options = void 0;
64
+ state.styling = void 0;
65
+ }
66
+ function getDraggableStates(element) {
67
+ return globals.states.get(element);
36
68
  }
37
69
  function getHandle(event, isMovable) {
38
70
  return findAncestor(event, isMovable ? SELECTOR_MOVABLE_HANDLE : SELECTOR_SORTABLE_HANDLE);
39
71
  }
40
- function getNextPosition(draggable, position) {
41
- let x = state.original?.x ?? 0;
42
- let y = state.original?.y ?? 0;
43
- if (draggable.horizontal) {
44
- x = position.x - (state.offset?.x ?? 0);
45
- if (state.container != null && state.element != null) x = clamp(x, state.container.left, state.container.right - state.element.rectangle.width);
72
+ function getNextPosition(item, position) {
73
+ let x = globals.original?.x ?? 0;
74
+ let y = globals.original?.y ?? 0;
75
+ if (item.state.horizontal) {
76
+ x = position.x - (globals.offset?.x ?? 0);
77
+ if (globals.container != null && globals.element != null) x = clamp(x, globals.container.left, globals.container.right - globals.element.rectangle.width);
46
78
  }
47
- if (draggable.vertical) {
48
- y = position.y - (state.offset?.y ?? 0);
49
- if (state.container != null && state.element != null) y = clamp(y, state.container.top, state.container.bottom - state.element.rectangle.height);
79
+ if (item.state.vertical) {
80
+ y = position.y - (globals.offset?.y ?? 0);
81
+ if (globals.container != null && globals.element != null) y = clamp(y, globals.container.top, globals.container.bottom - globals.element.rectangle.height);
50
82
  }
51
83
  return {
52
84
  x,
@@ -55,19 +87,22 @@ function getNextPosition(draggable, position) {
55
87
  }
56
88
  function onKeydown(event) {
57
89
  if (current == null || event.key !== KEY_ESCAPE) return;
58
- const { origin } = current;
59
- current.options.drag.onCancel?.(state, current);
60
- current.element.dispatchEvent(new CustomEvent(`${current.prefix}:cancel`, { detail: { element: origin } }));
90
+ current.state.options.drag.onCancel?.(globals, current);
91
+ current.state.element.dispatchEvent(new CustomEvent(`${current.state.event}:cancel`, { detail: { element: current.state.options.getOrigin() } }));
61
92
  reset();
62
93
  }
63
94
  function onPointerdown(event) {
64
95
  if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || (supportsTouch.value ? event.type === "mousedown" : event.type === "touchstart" || event.button !== 0)) return;
65
96
  const container = findAncestor(event, SELECTOR);
66
- const instances = state.instances.get(container);
67
- if (instances == null) return;
97
+ const instances = globals.instances.get(container);
98
+ const states = globals.states.get(container);
99
+ if (instances == null || states == null) return;
68
100
  const isMovable = container.hasAttribute(ATTRIBUTE_MOVABLE);
69
- const instance = isMovable ? instances.movable : instances.sortable;
70
- if (instance == null) return;
101
+ const item = {
102
+ instance: isMovable ? instances.movable : instances.sortable,
103
+ state: isMovable ? states.movable : states.sortable
104
+ };
105
+ if (item.instance == null || item.state == null) return;
71
106
  if (supportsTouch.value) event.preventDefault();
72
107
  let element = container;
73
108
  if (!isMovable) {
@@ -75,41 +110,43 @@ function onPointerdown(event) {
75
110
  if (element == null || element.parentElement !== container) return;
76
111
  }
77
112
  let handle = element;
78
- instance.hasHandles ??= element.querySelector(SELECTOR_SORTABLE_HANDLE) != null;
79
- if (instance.hasHandles) handle = getHandle(event, isMovable);
113
+ item.state.hasHandles ??= element.querySelector(SELECTOR_SORTABLE_HANDLE) != null;
114
+ if (item.state.hasHandles) handle = getHandle(event, isMovable);
80
115
  if (handle == null) return;
81
- const { dragged } = instance;
116
+ const dragged = item.state.options.getDragged();
82
117
  const rectangle = dragged.getBoundingClientRect();
83
118
  const position = getPosition(event) ?? {
84
119
  x: 0,
85
120
  y: 0
86
121
  };
87
- current = instance;
88
- state.container = instance.container?.getBoundingClientRect();
89
- state.element = {
122
+ current = item;
123
+ globals.container = item.state.container?.getBoundingClientRect();
124
+ globals.element = {
90
125
  rectangle,
91
126
  node: dragged
92
127
  };
93
- state.offset = instance.options.position.getOffset(state, instance, element, position);
94
- state.original = instance.options.position.getOriginal(state, instance, position);
95
- const begin = new CustomEvent(`${instance.prefix}:begin`, {
128
+ globals.offset = item.state.options.position.getOffset(globals, item, element, position);
129
+ globals.original = item.state.options.position.getOriginal(globals, item, position);
130
+ const begin = new CustomEvent(`${item.state.event}:begin`, {
96
131
  detail: {
97
132
  element,
98
- position: { ...state.original }
133
+ position: { ...globals.original }
99
134
  },
100
135
  cancelable: true
101
136
  });
102
- instance.element.dispatchEvent(begin);
137
+ item.state.element.dispatchEvent(begin);
103
138
  setTimeout(() => {
104
139
  if (begin.defaultPrevented) {
105
- current?.options.drag.onCancel(state, instance);
140
+ item.state.options.drag.onCancel?.(globals, item);
106
141
  reset();
107
142
  return;
108
143
  }
109
- const next = getNextPosition(instance, position);
144
+ const next = getNextPosition(item, position);
110
145
  dragged.style.position = "fixed";
111
146
  dragged.style.inset = `${next.y}px auto auto ${next.x}px`;
112
- instance.options.drag.onBegin(event, state, instance, element, handle, next);
147
+ dragged.style.transform = "translate3d(0, 0, 0)";
148
+ item.state.options.drag.onBegin?.(event, globals, item, element, handle, next);
149
+ item.state.styling.set();
113
150
  styleToggler.set();
114
151
  });
115
152
  }
@@ -118,61 +155,74 @@ function onPointermove(event) {
118
155
  const position = getPosition(event);
119
156
  if (position == null) return;
120
157
  const next = getNextPosition(current, position);
121
- if (state.element != null) state.element.node.style.inset = `${next.y}px auto auto ${next.x}px`;
122
- const detail = current.options.drag.onMove(event, state, current, {
158
+ if (globals.element != null) globals.element.node.style.inset = `${next.y}px auto auto ${next.x}px`;
159
+ const detail = current.state.options.drag.onMove(event, globals, current, {
123
160
  calculated: next,
124
161
  original: position
125
162
  });
126
- current.element.dispatchEvent(new CustomEvent(`${current.prefix}:move`, { detail }));
163
+ current.state.element.dispatchEvent(new CustomEvent(`${current.state.event}:move`, { detail }));
127
164
  }
128
165
  function onPointerup(event) {
129
- current?.options.drag.onEnd?.(event, state, current, reset);
166
+ current?.state.options.drag.onEnd?.(event, globals, current, reset);
130
167
  }
131
168
  function removeDraggable(element) {
132
169
  const { property } = this;
133
- const instances = state.instances.get(element);
134
- if (instances == null || instances[property] == null) return;
135
- instances[property]?.destroy();
136
- instances[property] = void 0;
137
- if (instances[properties[property]] == null) state.instances.delete(element);
170
+ removeInstance(globals.instances, property, element);
171
+ removeInstance(globals.states, property, element);
172
+ }
173
+ function removeInstance(map, name, element) {
174
+ const instances = map.get(element);
175
+ if (instances == null || instances[name] == null) return;
176
+ if (typeof instances[name].destroy === "function") instances[name].destroy();
177
+ instances[name] = void 0;
178
+ if (instances[properties[name]] == null) map.delete(element);
138
179
  }
139
180
  function reset() {
140
- current = void 0;
141
- state.container = void 0;
142
- state.element = void 0;
143
- state.offset = void 0;
144
- state.original = void 0;
181
+ current?.state.styling.remove();
145
182
  styleToggler.remove();
183
+ current = void 0;
184
+ globals.container = void 0;
185
+ globals.element = void 0;
186
+ globals.offset = void 0;
187
+ globals.original = void 0;
146
188
  }
147
- function setContainer(draggable, options) {
148
- const selector = draggable.element.getAttribute(options.container.attribute);
189
+ function setContainer(item) {
190
+ const { container } = item.state.options.input ?? {};
191
+ if (isHTMLOrSVGElement(container)) {
192
+ setContainerElement(item, container);
193
+ return;
194
+ }
195
+ const selector = container ?? item.instance.element.getAttribute(item.state.options.container.attribute);
149
196
  if (typeof selector !== "string") return;
150
- draggable.container = globals.has(selector) ? draggable.element.ownerDocument.body : document.querySelector(selector) ?? void 0;
151
- if (draggable.container == null) return;
152
- const set = options.container.map.get(draggable.container);
153
- if (set == null) options.container.map.set(draggable.container, new Set([draggable]));
154
- else set.add(draggable);
155
- options.container.onInitialize?.(draggable);
156
- }
157
- function setDirection(draggable, options) {
158
- const direction = draggable.element.getAttribute(options.direction.attribute);
159
- if (horizontals.has(direction)) draggable.vertical = false;
160
- else if (verticals.has(direction)) draggable.horizontal = false;
161
- options.direction.onAfter?.(draggable);
162
- }
163
- function unsetContainer(draggable, options) {
164
- const { container } = draggable;
197
+ const element = containers.has(selector) ? item.state.element.ownerDocument.body : document.querySelector(selector) ?? void 0;
198
+ if (isHTMLOrSVGElement(element)) setContainerElement(item, element);
199
+ }
200
+ function setContainerElement(item, element) {
201
+ item.state.container = element;
202
+ const set = item.state.options.container.map.get(element);
203
+ if (set == null) item.state.options.container.map.set(element, /* @__PURE__ */ new Set([item.instance]));
204
+ else set.add(item.instance);
205
+ item.state.options.container.onInitialize?.(item);
206
+ }
207
+ function setDirection(item) {
208
+ const direction = item.state.element.getAttribute(item.state.options.direction.attribute);
209
+ if (horizontals.has(direction)) item.state.vertical = false;
210
+ else if (verticals.has(direction)) item.state.horizontal = false;
211
+ item.state.options.direction.onAfter?.(item);
212
+ }
213
+ function unsetContainer(item) {
214
+ const { container } = item.state;
165
215
  if (container == null) return;
166
- const set = options.container.map.get(container);
216
+ const set = item.state.options.container.map.get(container);
167
217
  let empty = false;
168
218
  if (set != null) {
169
- set.delete(draggable);
219
+ set.delete(item.instance);
170
220
  if (set.size === 0) {
171
221
  empty = true;
172
- options.container.map.delete(container);
222
+ item.state.options.container.map.delete(container);
173
223
  }
174
224
  }
175
- options.container.onDestroy?.(draggable, container, empty);
225
+ item.state.options.container.onDestroy?.(item, container, empty);
176
226
  }
177
227
  const ATTRIBUTE_MOVABLE = "oui-movable";
178
228
  const ATTRIBUTE_SORTABLE = "oui-sortable";
@@ -181,29 +231,31 @@ const SELECTOR = `[${ATTRIBUTE_MOVABLE}], [${ATTRIBUTE_SORTABLE}]`;
181
231
  const SELECTOR_MOVABLE_HANDLE = `[${ATTRIBUTE_MOVABLE}-handle]`;
182
232
  const SELECTOR_SORTABLE_HANDLE = `[${ATTRIBUTE_SORTABLE}-handle]`;
183
233
  const SELECTOR_SORTABLE_ITEM = `[${ATTRIBUTE_SORTABLE}] > *`;
184
- const globals = new Set([
234
+ const containers = /* @__PURE__ */ new Set([
185
235
  "body",
186
236
  "document",
187
237
  "window"
188
238
  ]);
189
- const horizontals = new Set(["horizontal", "x"]);
239
+ const horizontals = /* @__PURE__ */ new Set(["horizontal", "x"]);
190
240
  const properties = {
191
241
  movable: "sortable",
192
242
  sortable: "movable"
193
243
  };
194
- const state = {
244
+ const globals = {
195
245
  container: void 0,
196
246
  element: void 0,
197
247
  instances: /* @__PURE__ */ new WeakMap(),
198
248
  offset: void 0,
199
- original: void 0
249
+ original: void 0,
250
+ states: /* @__PURE__ */ new WeakMap()
200
251
  };
201
- const styleToggler = toggleStyles(document.body, {
252
+ const styles = {
202
253
  touchAction: "none",
203
254
  userSelect: "none",
204
255
  webkitUserSelect: "none"
205
- });
206
- const verticals = new Set(["vertical", "y"]);
256
+ };
257
+ const styleToggler = toggleStyles(document.body, styles);
258
+ const verticals = /* @__PURE__ */ new Set(["vertical", "y"]);
207
259
  let current;
208
260
  on(document, "keydown", onKeydown);
209
261
  on(document, "mousedown", onPointerdown);
@@ -212,4 +264,4 @@ on(document, "pointerup", onPointerup);
212
264
  on(document, "touchcancel", onPointerup, { passive: false });
213
265
  on(document, "touchstart", onPointerdown, { passive: false });
214
266
  //#endregion
215
- export { OuiDraggable, addDraggable, removeDraggable };
267
+ export { OuiDraggable, addDraggable, getDraggableStates, removeDraggable };
@@ -0,0 +1,2 @@
1
+ import { g as createMovable, h as OuiMovable, m as ATTRIBUTE_MOVABLE_HANDLE, p as ATTRIBUTE_MOVABLE } from "../draggable-zszaW1qS.mjs";
2
+ export { ATTRIBUTE_MOVABLE, ATTRIBUTE_MOVABLE_HANDLE, OuiMovable, createMovable };