@dnd-kit/vue 0.2.3

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.
package/utilities.cjs ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utilities/index.ts
21
+ var utilities_exports = {};
22
+ __export(utilities_exports, {
23
+ createContext: () => createContext,
24
+ toValueDeep: () => toValueDeep,
25
+ unrefElement: () => unrefElement
26
+ });
27
+ module.exports = __toCommonJS(utilities_exports);
28
+
29
+ // src/utilities/context.ts
30
+ var import_vue = require("vue");
31
+ function createContext(componentName) {
32
+ const injectionKey = Symbol(
33
+ `${componentName}Context`
34
+ );
35
+ return [injectContext, provideContext];
36
+ function injectContext(fallback) {
37
+ const context = (0, import_vue.inject)(injectionKey, fallback);
38
+ if (context) return context;
39
+ if (context === null) return context;
40
+ throw new Error(
41
+ `Injection \`${injectionKey.toString()}\` not found. Component must be used within \`${componentName}\``
42
+ );
43
+ }
44
+ function provideContext(contextValue) {
45
+ (0, import_vue.provide)(injectionKey, contextValue);
46
+ return contextValue;
47
+ }
48
+ }
49
+
50
+ // src/utilities/element.ts
51
+ var import_vue2 = require("vue");
52
+ function unrefElement(elRef) {
53
+ const plain = (0, import_vue2.toValue)(elRef);
54
+ return plain?.$el ?? plain ?? void 0;
55
+ }
56
+
57
+ // src/utilities/ref.ts
58
+ var import_vue3 = require("vue");
59
+ function toValueDeep(input) {
60
+ return Object.fromEntries(
61
+ Object.entries(input).map(([key, value]) => [key, (0, import_vue3.toValue)(value)])
62
+ );
63
+ }
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ createContext,
67
+ toValueDeep,
68
+ unrefElement
69
+ });
70
+ //# sourceMappingURL=utilities.cjs.map
package/utilities.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { ComponentPublicInstance, MaybeRefOrGetter } from 'vue';
2
+
3
+ declare function createContext<TContextValue>(componentName: string): readonly [<T extends TContextValue | null | undefined = TContextValue>(fallback?: T) => T extends null ? TContextValue | null : TContextValue, (contextValue: TContextValue) => TContextValue];
4
+
5
+ type MaybeRefsOrGetters<T> = {
6
+ [K in keyof T]: MaybeRefOrGetter<T[K]>;
7
+ };
8
+ type MaybeElement = HTMLElement | ComponentPublicInstance | undefined | null;
9
+
10
+ type UnRefElementReturn<T extends MaybeElement = MaybeElement> = T extends ComponentPublicInstance ? Exclude<MaybeElement, ComponentPublicInstance | null> : Exclude<T, null> | undefined;
11
+ declare function unrefElement<T extends MaybeElement>(elRef: MaybeRefOrGetter<T>): UnRefElementReturn<T>;
12
+
13
+ declare function toValueDeep<T>(input: MaybeRefsOrGetters<T>): T;
14
+
15
+ export { type UnRefElementReturn, createContext, toValueDeep, unrefElement };
package/utilities.js ADDED
@@ -0,0 +1,41 @@
1
+ // src/utilities/context.ts
2
+ import { inject, provide } from "vue";
3
+ function createContext(componentName) {
4
+ const injectionKey = Symbol(
5
+ `${componentName}Context`
6
+ );
7
+ return [injectContext, provideContext];
8
+ function injectContext(fallback) {
9
+ const context = inject(injectionKey, fallback);
10
+ if (context) return context;
11
+ if (context === null) return context;
12
+ throw new Error(
13
+ `Injection \`${injectionKey.toString()}\` not found. Component must be used within \`${componentName}\``
14
+ );
15
+ }
16
+ function provideContext(contextValue) {
17
+ provide(injectionKey, contextValue);
18
+ return contextValue;
19
+ }
20
+ }
21
+
22
+ // src/utilities/element.ts
23
+ import { toValue } from "vue";
24
+ function unrefElement(elRef) {
25
+ const plain = toValue(elRef);
26
+ return plain?.$el ?? plain ?? void 0;
27
+ }
28
+
29
+ // src/utilities/ref.ts
30
+ import { toValue as toValue2 } from "vue";
31
+ function toValueDeep(input) {
32
+ return Object.fromEntries(
33
+ Object.entries(input).map(([key, value]) => [key, toValue2(value)])
34
+ );
35
+ }
36
+ export {
37
+ createContext,
38
+ toValueDeep,
39
+ unrefElement
40
+ };
41
+ //# sourceMappingURL=utilities.js.map