@cocoar/vue-ui 1.10.0 → 1.11.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 (39) hide show
  1. package/dist/components/checkbox/CoarCheckbox.vue.d.ts +2 -2
  2. package/dist/components/checkbox/CoarCheckbox.vue.d.ts.map +1 -1
  3. package/dist/components/date-time/plain-date-picker/CoarPlainDatePicker.vue.d.ts +1 -1
  4. package/dist/components/date-time/plain-date-picker/CoarPlainDatePicker.vue.d.ts.map +1 -1
  5. package/dist/components/date-time/plain-date-time-picker/CoarPlainDateTimePicker.vue.d.ts +1 -1
  6. package/dist/components/date-time/plain-date-time-picker/CoarPlainDateTimePicker.vue.d.ts.map +1 -1
  7. package/dist/components/date-time/zoned-date-time-picker/CoarZonedDateTimePicker.vue.d.ts +1 -1
  8. package/dist/components/date-time/zoned-date-time-picker/CoarZonedDateTimePicker.vue.d.ts.map +1 -1
  9. package/dist/components/dual-listbox/CoarDualListbox.vue.d.ts +110 -0
  10. package/dist/components/dual-listbox/CoarDualListbox.vue.d.ts.map +1 -0
  11. package/dist/components/dual-listbox/index.d.ts +3 -0
  12. package/dist/components/dual-listbox/index.d.ts.map +1 -0
  13. package/dist/components/form-field/CoarFormField.vue.d.ts +1 -1
  14. package/dist/components/form-field/CoarFormField.vue.d.ts.map +1 -1
  15. package/dist/components/listbox/CoarListbox.vue.d.ts +227 -0
  16. package/dist/components/listbox/CoarListbox.vue.d.ts.map +1 -0
  17. package/dist/components/listbox/index.d.ts +4 -0
  18. package/dist/components/listbox/index.d.ts.map +1 -0
  19. package/dist/components/listbox/types.d.ts +79 -0
  20. package/dist/components/listbox/types.d.ts.map +1 -0
  21. package/dist/components/progress-bar/CoarProgressBar.vue.d.ts +1 -1
  22. package/dist/components/progress-bar/CoarProgressBar.vue.d.ts.map +1 -1
  23. package/dist/components/radio-group/CoarRadioGroup.vue.d.ts +1 -1
  24. package/dist/components/radio-group/CoarRadioGroup.vue.d.ts.map +1 -1
  25. package/dist/components/switch/CoarSwitch.vue.d.ts +1 -1
  26. package/dist/components/switch/CoarSwitch.vue.d.ts.map +1 -1
  27. package/dist/composables/dragRegistry.d.ts +39 -0
  28. package/dist/composables/dragRegistry.d.ts.map +1 -0
  29. package/dist/composables/index.d.ts +7 -0
  30. package/dist/composables/index.d.ts.map +1 -0
  31. package/dist/composables/useDragDrop.d.ts +109 -0
  32. package/dist/composables/useDragDrop.d.ts.map +1 -0
  33. package/dist/composables/useVirtualList.d.ts +52 -0
  34. package/dist/composables/useVirtualList.d.ts.map +1 -0
  35. package/dist/index.css +1 -1
  36. package/dist/index.d.ts +6 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +3855 -2710
  39. package/package.json +2 -2
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Module-level registry that carries live item references across HTML5 drag-and-drop
3
+ * events. Used by {@link useDragDrop} to exchange payloads between independent Vue
4
+ * components — the browser's `DataTransfer` API only accepts strings, so we serialize
5
+ * a drag id there and keep the actual payload (with object identity preserved) here.
6
+ *
7
+ * Exported for advanced integrations that want to implement their own drag handlers
8
+ * while staying compatible with {@link useDragDrop}'s matching rules.
9
+ */
10
+ export declare const DRAG_MIME = "application/x-coar-dnd";
11
+ export interface DragEntry<T = unknown> {
12
+ /** Random drag-session id (stored in DataTransfer as a string). */
13
+ id: string;
14
+ /** Stable id of the source surface — used to detect self-drops. */
15
+ sourceId: string;
16
+ /** Public identifier the consumer gave the source via `dragId`, if any. */
17
+ fromId: string | null;
18
+ /** Optional drag group name. Only surfaces sharing a group accept each other's items. */
19
+ dragGroup: string | null;
20
+ /** The actual items being dragged. */
21
+ items: readonly T[];
22
+ /**
23
+ * Invoked by the drop target when it accepts the drop. The source uses this to
24
+ * emit its "items-removed" callback synchronously — avoiding the brief "duplicated
25
+ * items" window between `drop` on the target and `dragend` on the source.
26
+ */
27
+ onAcceptedBy?: (targetId: string, insertIndex: number | null) => void;
28
+ /** Flag set by a target on accept so the source's `dragend` can report `dropped: true`. */
29
+ consumed?: boolean;
30
+ }
31
+ export declare function registerDrag<T>(entry: DragEntry<T>): void;
32
+ export declare function getDrag<T>(id: string): DragEntry<T> | undefined;
33
+ /**
34
+ * Returns the drag session currently in flight — readable during `dragover`
35
+ * events, where the browser refuses to expose `DataTransfer.getData()`.
36
+ */
37
+ export declare function getActiveDrag<T>(): DragEntry<T> | undefined;
38
+ export declare function deleteDrag(id: string): void;
39
+ //# sourceMappingURL=dragRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dragRegistry.d.ts","sourceRoot":"","sources":["../../src/composables/dragRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,SAAS,2BAA2B,CAAC;AAElD,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,mEAAmE;IACnE,EAAE,EAAE,MAAM,CAAC;IACX,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,yFAAyF;IACzF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,sCAAsC;IACtC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACtE,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAKD,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAGzD;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAE/D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAE3D;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAG3C"}
@@ -0,0 +1,7 @@
1
+ export { useVirtualList } from './useVirtualList';
2
+ export type { UseVirtualListOptions, UseVirtualListReturn, VirtualRow, } from './useVirtualList';
3
+ export { useDragDrop } from './useDragDrop';
4
+ export type { UseDragDropOptions, UseDragDropReturn, DropPayload, } from './useDragDrop';
5
+ export { DRAG_MIME, registerDrag, getDrag, getActiveDrag, deleteDrag, } from './dragRegistry';
6
+ export type { DragEntry } from './dragRegistry';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,UAAU,GACX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,GACZ,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,SAAS,EACT,YAAY,EACZ,OAAO,EACP,aAAa,EACb,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { MaybeRefOrGetter, Ref } from 'vue';
2
+ /** Payload surfaced to `canDrop` checks and the `onDropAccept` callback. */
3
+ export interface DropPayload<T> {
4
+ /** The items being dropped. */
5
+ items: readonly T[];
6
+ /** Public identifier of the source surface, if it set `dragId`. */
7
+ fromId: string | null;
8
+ /** Drag group of the source surface. */
9
+ fromGroup: string | null;
10
+ /** True when the source and target are the same surface (drag within one list). */
11
+ fromSelf: boolean;
12
+ }
13
+ export interface UseDragDropOptions<T> {
14
+ /** Public identifier for this surface. Auto-generated per instance if not set. */
15
+ dragId?: MaybeRefOrGetter<string | undefined>;
16
+ /**
17
+ * Shared name linking compatible surfaces. Items can only cross between surfaces
18
+ * with the same `dragGroup`. A surface without a group still accepts self-drops.
19
+ */
20
+ dragGroup?: MaybeRefOrGetter<string | undefined>;
21
+ /**
22
+ * Whitelist of source `dragId`s this surface accepts items from. When set, drops
23
+ * are only accepted if the source's `dragId` is listed. Unset = accept from any
24
+ * surface in the same `dragGroup`.
25
+ */
26
+ dragAccept?: MaybeRefOrGetter<string[] | undefined>;
27
+ /**
28
+ * Runtime target validation. Called on `dragover` and `drop`. Return `false`
29
+ * to refuse the drop — the cursor shows "not allowed" and nothing happens.
30
+ */
31
+ canDrop?: (payload: DropPayload<T>) => boolean;
32
+ /** Fired after `startDrag` succeeds. */
33
+ onDragStart?: (items: readonly T[]) => void;
34
+ /**
35
+ * Fired on `dragend` (whether the drop was accepted or cancelled). `dropped` is
36
+ * `true` when some target consumed the payload.
37
+ */
38
+ onDragEnd?: (payload: {
39
+ items: readonly T[];
40
+ dropped: boolean;
41
+ }) => void;
42
+ /**
43
+ * Fired on this surface when it accepts a drop. Consumers update their own
44
+ * source-of-truth here (append items, insert at `insertIndex`, etc.).
45
+ */
46
+ onDropAccept?: (payload: DropPayload<T> & {
47
+ insertIndex: number | null;
48
+ }) => void;
49
+ /**
50
+ * Fired on the *source* surface when another target consumed its payload.
51
+ * Consumers update their own source-of-truth here (remove the items).
52
+ * Fires synchronously inside the target's `drop`, before the source's `dragend`.
53
+ */
54
+ onItemsRemove?: (payload: {
55
+ items: readonly T[];
56
+ toGroup: string | null;
57
+ }) => void;
58
+ }
59
+ export interface UseDragDropReturn<T> {
60
+ /** Stable instance id — use it when you need to distinguish surfaces externally. */
61
+ instanceId: string;
62
+ /** `true` while a compatible drag is hovering this surface (clears on leave/drop). */
63
+ isDragOver: Ref<boolean>;
64
+ /** `true` while this surface is the source of an in-flight drag. */
65
+ isDragging: Ref<boolean>;
66
+ /**
67
+ * Call from a `@dragstart` handler on a draggable element. Pass the payload you
68
+ * want to transfer. Returns `true` if the drag was registered, `false` if the
69
+ * event had no `dataTransfer` or items was empty.
70
+ */
71
+ startDrag(event: DragEvent, items: readonly T[]): boolean;
72
+ /** Call from a `@dragend` handler on the draggable element. Cleans up the session. */
73
+ endDrag(): void;
74
+ /** Call from the drop container's `@dragover`. */
75
+ onDragOver(event: DragEvent): void;
76
+ /** Call from the drop container's `@dragleave`. */
77
+ onDragLeave(event: DragEvent): void;
78
+ /**
79
+ * Call from the drop container's (or an inner drop target's) `@drop`. Pass an
80
+ * optional `insertIndex` to tell consumers where the drop landed (null = append).
81
+ */
82
+ onDrop(event: DragEvent, context?: {
83
+ insertIndex?: number | null;
84
+ }): void;
85
+ }
86
+ /**
87
+ * Framework-agnostic HTML5 drag-and-drop primitive used across Cocoar UI
88
+ * components. Decouples "what is being dragged" (your items) from the
89
+ * registration bookkeeping (group matching, whitelists, runtime validation,
90
+ * source-side cleanup).
91
+ *
92
+ * Usage:
93
+ * ```ts
94
+ * const dnd = useDragDrop<Row>({
95
+ * dragGroup: 'rows',
96
+ * onDropAccept: ({ items }) => { rows.value = [...rows.value, ...items] },
97
+ * onItemsRemove: ({ items }) => {
98
+ * const keep = new Set(rows.value); items.forEach(i => keep.delete(i));
99
+ * rows.value = [...keep];
100
+ * },
101
+ * })
102
+ *
103
+ * // In template:
104
+ * // <div draggable @dragstart="dnd.startDrag($event, [row])" @dragend="dnd.endDrag">
105
+ * // <div @dragover="dnd.onDragOver" @dragleave="dnd.onDragLeave" @drop="dnd.onDrop">
106
+ * ```
107
+ */
108
+ export declare function useDragDrop<T>(opts?: UseDragDropOptions<T>): UseDragDropReturn<T>;
109
+ //# sourceMappingURL=useDragDrop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDragDrop.d.ts","sourceRoot":"","sources":["../../src/composables/useDragDrop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,KAAK,GAAG,EAAE,MAAM,KAA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,CAAC;CACpF;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,oFAAoF;IACpF,UAAU,EAAE,MAAM,CAAC;IACnB,sFAAsF;IACtF,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACzB,oEAAoE;IACpE,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAGzB;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,OAAO,CAAC;IAC1D,sFAAsF;IACtF,OAAO,IAAI,IAAI,CAAC;IAGhB,kDAAkD;IAClD,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,mDAAmD;IACnD,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACpC;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CAC3E;AAOD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,GAAE,kBAAkB,CAAC,CAAC,CAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CA6HrF"}
@@ -0,0 +1,52 @@
1
+ import { MaybeRefOrGetter, Ref, ComputedRef } from 'vue';
2
+ /** Options for {@link useVirtualList}. */
3
+ export interface UseVirtualListOptions {
4
+ /** Total number of items in the virtual list. */
5
+ count: MaybeRefOrGetter<number>;
6
+ /**
7
+ * Row height in pixels — either a fixed number, or a function that returns
8
+ * the height for a given index. Reactive: if you pass a ref, changes invalidate
9
+ * the offset cache automatically.
10
+ */
11
+ itemSize: MaybeRefOrGetter<number | ((index: number) => number)>;
12
+ /** Rows rendered above/below the viewport as a scroll buffer. Default 5. */
13
+ overscan?: MaybeRefOrGetter<number>;
14
+ /** The scrollable element — typically a template ref on the scrolling container. */
15
+ scrollElement: Ref<HTMLElement | null>;
16
+ }
17
+ /** One positioned row produced by the virtualizer. */
18
+ export interface VirtualRow {
19
+ /** Position in the underlying list (0 .. count - 1). */
20
+ index: number;
21
+ /** Pixel offset from the top of the spacer. */
22
+ start: number;
23
+ /** Row height in pixels. */
24
+ size: number;
25
+ }
26
+ export interface UseVirtualListReturn {
27
+ /** Slice of rows currently inside the viewport + overscan window. */
28
+ virtualRows: ComputedRef<VirtualRow[]>;
29
+ /** Total pixel height of the full list — use this for the scroll spacer. */
30
+ totalSize: ComputedRef<number>;
31
+ /** Programmatically scroll an index into view. */
32
+ scrollToIndex(index: number, align?: 'auto' | 'start' | 'center' | 'end'): void;
33
+ /** Inspect the precomputed offset for an index (debug/tests). */
34
+ offsetFor(index: number): number;
35
+ }
36
+ /**
37
+ * Minimal fixed-viewport virtualizer. Keeps a cumulative offset table so both
38
+ * fixed and per-index heights are O(log n) per scroll event, without any
39
+ * external dependencies.
40
+ *
41
+ * Usage:
42
+ * ```ts
43
+ * const scrollEl = useTemplateRef('scroll')
44
+ * const { virtualRows, totalSize, scrollToIndex } = useVirtualList({
45
+ * count: () => items.length,
46
+ * itemSize: 32,
47
+ * scrollElement: scrollEl,
48
+ * })
49
+ * ```
50
+ */
51
+ export declare function useVirtualList(opts: UseVirtualListOptions): UseVirtualListReturn;
52
+ //# sourceMappingURL=useVirtualList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVirtualList.d.ts","sourceRoot":"","sources":["../../src/composables/useVirtualList.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,gBAAgB,EACrB,KAAK,GAAG,EACR,KAAK,WAAW,EACjB,MAAM,KAAK,CAAC;AAEb,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC;;;;OAIG;IACH,QAAQ,EAAE,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC;IACjE,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACpC,oFAAoF;IACpF,aAAa,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CACxC;AAED,sDAAsD;AACtD,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,qEAAqE;IACrE,WAAW,EAAE,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC;IACvC,4EAA4E;IAC5E,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC/B,kDAAkD;IAClD,aAAa,CACX,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAC1C,IAAI,CAAC;IACR,iEAAiE;IACjE,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC;AAQD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,oBAAoB,CA0KhF"}