Skip to content

Commit f75a3d4

Browse files
committed
added injectionKey
1 parent f0ee2d8 commit f75a3d4

File tree

4 files changed

+90
-6
lines changed

4 files changed

+90
-6
lines changed

docs/v2/guide/changelog.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ const { isDragging } = makeDraggable(el, { id: props.item.id }, () => [
2929

3030
---
3131

32+
### New export — `injectionKey`
33+
34+
`injectionKey` is now part of the public API:
35+
36+
```ts
37+
import { injectionKey } from '@vue-dnd-kit/core';
38+
```
39+
40+
This is the Vue injection key under which `DnDProvider` stores its internal context. It is intended for **advanced or non-standard use cases** — for example:
41+
42+
- Bridging a separately mounted Vue app (e.g. a shadow root) into the same DnD context
43+
- Building custom integrations that need direct access to the internal provider
44+
- Exploring or debugging what the library holds internally
45+
46+
For everything standard — reading drag state, pointer position, preview, entities — use `useDnDProvider`. It returns a stable, typed public API and is all you need in 99% of cases.
47+
48+
**`injectionKey` gives you the raw internal provider.** Its shape is not part of the public API contract and may change between minor versions.
49+
50+
[injectionKey — advanced use](/v2/guide/core/use-dnd-provider#injectionkey-advanced-use-only)
51+
52+
---
53+
3254
### Bug fix — drop fails after scrolling away while dragging
3355

3456
**Symptom.** Start dragging an item in a virtual list → scroll so the item unmounts → scroll back so it remounts → try to drop — nothing fires.
@@ -49,9 +71,9 @@ const { isDragging } = makeDraggable(el, { id: props.item.id }, () => [
4971

5072
---
5173

52-
### Bug fix — drag did not start inside a Shadow DOM
74+
### Bug fix — full Shadow DOM support
5375

54-
**Two separate bugs were fixed. Together they make full Shadow DOM support work — including cross-boundary drag between a shadow list and a regular list.**
76+
**Two separate bugs were fixed. Together they enable full Shadow DOM support — including cross-boundary drag between a shadow list and a regular list.**
5577

5678
#### Part 1 — drag never started inside a shadow root
5779

@@ -73,18 +95,21 @@ const target = (event.composedPath?.()[0] ?? event.target) as HTMLElement;
7395

7496
**The old approach** wrapped the shadow app in its own `DnDProvider`. This created two completely isolated DnD contexts — drag sessions in the shadow root were invisible to the outer provider and vice versa. Sorting between the two lists was impossible.
7597

76-
**The fix** is to share the outer provider with the inner Vue app via `app.provide`. Since pointer events from inside the shadow root already reach `document` (where the outer provider listens), and `composedPath()[0]` resolves the real element, all that was missing was the elements being registered in the same maps.
98+
**The fix** is to share the outer provider with the inner Vue app via `app.provide` using the newly exported `injectionKey`. Since pointer events from inside the shadow root already reach `document` (where the outer provider listens), and `composedPath()[0]` resolves the real element, all that was missing was the elements being registered in the same maps.
7799

78100
```ts
79-
// Get the outer provider inside the component that mounts the shadow app
101+
import { inject } from 'vue';
102+
import { injectionKey } from '@vue-dnd-kit/core';
103+
104+
// Inside a component that is a descendant of the outer DnDProvider:
80105
const outerProvider = inject(injectionKey);
81106

82107
onMounted(() => {
83108
const shadow = host.attachShadow({ mode: 'open' });
84109
const container = document.createElement('div');
85110
shadow.appendChild(container);
86111

87-
// No DnDProvider wrapper — just share the outer provider directly
112+
// No DnDProvider wrapper — share the outer provider directly
88113
createApp({ render: () => h(YourShadowList) })
89114
.provide(injectionKey, outerProvider)
90115
.mount(container);
@@ -94,3 +119,22 @@ onMounted(() => {
94119
Result: shadow DOM elements and regular DOM elements participate in the same drag session. You can sort within each list and drag items across the boundary between them.
95120

96121
---
122+
123+
## v2.2.0
124+
125+
- Added grid layout example
126+
- Various stability improvements
127+
128+
## v2.1.0
129+
130+
- `makeSelectionArea` — box-select with multi-drag support
131+
- `makeAutoScroll` — automatic container scroll during drag
132+
- Keyboard navigation (Enter / Space / Arrows / Escape)
133+
134+
## v2.0.0
135+
136+
- Full rewrite. Composable-first API: `makeDraggable`, `makeDroppable`, `makeConstraintArea`, `makeSelectionArea`
137+
- `DnDProvider` as the scope boundary (multiple independent providers on one page)
138+
- `suggestSort`, `suggestSwap`, `suggestCopy`, `suggestRemove` helpers on `event.helpers`
139+
- Touch support
140+
- Zero external dependencies

docs/v2/guide/core/use-dnd-provider.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,45 @@ Reading preview position in a custom preview:
109109

110110
---
111111

112+
---
113+
114+
## `injectionKey` — advanced use only
115+
116+
`injectionKey` is the Vue injection key under which `DnDProvider` stores its context. It is exported from the public API but **should not be used in normal application code**`useDnDProvider` covers all typical needs.
117+
118+
Typical use cases:
119+
120+
- Bridging a separately mounted Vue app (e.g. inside a shadow root) into the same DnD context
121+
- Building custom integrations that need direct access to the internal provider
122+
- Exploring or debugging what the library holds at runtime
123+
124+
Example — sharing context with a shadow root app:
125+
126+
```ts
127+
import { inject, createApp, h } from 'vue';
128+
import { injectionKey } from '@vue-dnd-kit/core';
129+
130+
// Inside a component that is a descendant of DnDProvider:
131+
const outerProvider = inject(injectionKey);
132+
133+
onMounted(() => {
134+
const shadow = host.attachShadow({ mode: 'open' });
135+
const container = document.createElement('div');
136+
shadow.appendChild(container);
137+
138+
// Share the outer provider with the inner app — no DnDProvider wrapper needed
139+
createApp({ render: () => h(YourComponent) })
140+
.provide(injectionKey, outerProvider)
141+
.mount(container);
142+
});
143+
```
144+
145+
Elements inside the shadow root will register into the same `draggableMap` / `droppableMap` as the outer app and participate in the same drag sessions.
146+
147+
> **Do not** use `injectionKey` + `inject` as a replacement for `useDnDProvider`. The value behind the key is an internal type — its shape is not part of the public API contract and may change between minor versions.
148+
149+
---
150+
112151
## See also
113152

114153
- [DnDProvider](/v2/guide/core/dnd-provider) — setup and preview slot.

packages/core/src/external/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export { makeSelectionArea } from './composables/makeSelectionArea';
1212
export { makeConstraintArea } from './composables/makeConstraintArea';
1313
export { makeDroppable } from './composables/makeDroppable';
1414
export { useDnDProvider } from './composables/useDnDProvider';
15+
export { injectionKey } from '../internal/utils/namespaces';
1516
export {
1617
makeAutoScroll,
1718
type IAutoScrollOptions,

playground/src/sections/ShadowDomSection.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
import {
5252
makeDraggable,
5353
makeDroppable,
54+
injectionKey,
5455
} from '../../../packages/core/src/external/index';
55-
import { injectionKey } from '../../../packages/core/src/internal/utils/namespaces';
5656
import type { IDragEvent } from '../../../packages/core/src/external/types';
5757
5858
interface Item {

0 commit comments

Comments
 (0)