@maas/vue-equipment 1.0.0-beta.13 → 1.0.0-beta.14

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 (72) hide show
  1. package/dist/nuxt/module.json +1 -1
  2. package/dist/plugins/MagicAccordion/src/components/MagicAccordionContent.vue +65 -82
  3. package/dist/plugins/MagicAccordion/src/components/MagicAccordionContent.vue.d.ts +2 -2
  4. package/dist/plugins/MagicAccordion/src/components/MagicAccordionProvider.vue +24 -30
  5. package/dist/plugins/MagicAccordion/src/components/MagicAccordionTrigger.vue +65 -61
  6. package/dist/plugins/MagicAccordion/src/components/MagicAccordionTrigger.vue.d.ts +1 -1
  7. package/dist/plugins/MagicAccordion/src/components/MagicAccordionView.vue +41 -45
  8. package/dist/plugins/MagicAccordion/src/components/MagicAccordionView.vue.d.ts +1 -1
  9. package/dist/plugins/MagicCommand/src/components/MagicCommandContent.vue +137 -150
  10. package/dist/plugins/MagicCommand/src/components/MagicCommandContent.vue.d.ts +1 -1
  11. package/dist/plugins/MagicCommand/src/components/MagicCommandDrawer.vue +45 -52
  12. package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue +80 -82
  13. package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue.d.ts +1 -1
  14. package/dist/plugins/MagicCommand/src/components/MagicCommandModal.vue +40 -47
  15. package/dist/plugins/MagicCommand/src/components/MagicCommandProvider.vue +68 -74
  16. package/dist/plugins/MagicCommand/src/components/MagicCommandRenderer.vue +22 -38
  17. package/dist/plugins/MagicCommand/src/components/MagicCommandTrigger.vue +95 -85
  18. package/dist/plugins/MagicCommand/src/components/MagicCommandTrigger.vue.d.ts +1 -1
  19. package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue +41 -47
  20. package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue.d.ts +1 -1
  21. package/dist/plugins/MagicCookie/src/components/MagicCookieItem.vue +41 -39
  22. package/dist/plugins/MagicCookie/src/components/MagicCookieItem.vue.d.ts +2 -2
  23. package/dist/plugins/MagicCookie/src/components/MagicCookieProvider.vue +23 -34
  24. package/dist/plugins/MagicCookie/src/components/MagicCookieView.vue +40 -73
  25. package/dist/plugins/MagicCookie/src/components/MagicCookieView.vue.d.ts +1 -1
  26. package/dist/plugins/MagicDraggable/src/components/MagicDraggable.vue +70 -87
  27. package/dist/plugins/MagicDraggable/src/components/MagicDraggable.vue.d.ts +7 -7
  28. package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue +262 -304
  29. package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue.d.ts +12 -12
  30. package/dist/plugins/MagicEmitter/src/composables/useMagicEmitter.d.ts +100 -100
  31. package/dist/plugins/MagicMarquee/src/components/MagicMarquee.vue +41 -69
  32. package/dist/plugins/MagicMarquee/src/composables/useMagicMarquee.d.ts +1 -1
  33. package/dist/plugins/MagicMenu/src/components/MagicMenuChannel.vue +54 -59
  34. package/dist/plugins/MagicMenu/src/components/MagicMenuChannel.vue.d.ts +2 -2
  35. package/dist/plugins/MagicMenu/src/components/MagicMenuContent.vue +188 -208
  36. package/dist/plugins/MagicMenu/src/components/MagicMenuContent.vue.d.ts +3 -3
  37. package/dist/plugins/MagicMenu/src/components/MagicMenuFloat.vue +181 -194
  38. package/dist/plugins/MagicMenu/src/components/MagicMenuItem.vue +91 -100
  39. package/dist/plugins/MagicMenu/src/components/MagicMenuItem.vue.d.ts +1 -1
  40. package/dist/plugins/MagicMenu/src/components/MagicMenuProvider.vue +83 -85
  41. package/dist/plugins/MagicMenu/src/components/MagicMenuRemote.vue +79 -75
  42. package/dist/plugins/MagicMenu/src/components/MagicMenuRemote.vue.d.ts +1 -1
  43. package/dist/plugins/MagicMenu/src/components/MagicMenuTrigger.vue +106 -105
  44. package/dist/plugins/MagicMenu/src/components/MagicMenuTrigger.vue.d.ts +1 -1
  45. package/dist/plugins/MagicMenu/src/components/MagicMenuView.vue +54 -60
  46. package/dist/plugins/MagicMenu/src/components/MagicMenuView.vue.d.ts +1 -1
  47. package/dist/plugins/MagicModal/src/components/MagicModal.vue +136 -164
  48. package/dist/plugins/MagicModal/src/components/MagicModal.vue.d.ts +1 -1
  49. package/dist/plugins/MagicNoise/src/components/MagicNoise.vue +53 -78
  50. package/dist/plugins/MagicPie/src/components/MagicPie.vue +147 -175
  51. package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudio.vue +49 -65
  52. package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudioControls.vue +87 -129
  53. package/dist/plugins/MagicPlayer/src/components/MagicPlayerDisplayTime.vue +33 -41
  54. package/dist/plugins/MagicPlayer/src/components/MagicPlayerMuxPopover.vue +99 -109
  55. package/dist/plugins/MagicPlayer/src/components/MagicPlayerOverlay.vue +47 -75
  56. package/dist/plugins/MagicPlayer/src/components/MagicPlayerPoster.vue +16 -31
  57. package/dist/plugins/MagicPlayer/src/components/MagicPlayerProvider.vue +43 -44
  58. package/dist/plugins/MagicPlayer/src/components/MagicPlayerTimeline.vue +52 -109
  59. package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideo.vue +65 -72
  60. package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideoControls.vue +154 -225
  61. package/dist/plugins/MagicPlayer/src/composables/useMagicPlayer.d.ts +1 -1
  62. package/dist/plugins/MagicScroll/src/components/MagicScrollCollision.vue +49 -59
  63. package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue +63 -70
  64. package/dist/plugins/MagicScroll/src/components/MagicScrollProvider.vue +29 -33
  65. package/dist/plugins/MagicScroll/src/components/MagicScrollScene.vue +59 -69
  66. package/dist/plugins/MagicToast/src/components/MagicToastProvider.vue +80 -95
  67. package/dist/plugins/MagicToast/src/components/MagicToastView.vue +52 -70
  68. package/dist/plugins/MagicToast/src/components/MagicToastView.vue.d.ts +2 -2
  69. package/package.json +1 -1
  70. package/dist/plugins/MagicAccordion/demo/data/footer.json +0 -117
  71. package/dist/plugins/MagicCommand/demo/data/about.json +0 -3
  72. package/dist/plugins/MagicCommand/demo/data/search.json +0 -594
@@ -1,7 +1,31 @@
1
- <script>
2
- import { defineComponent as _defineComponent } from "vue";
3
- import { unref as _unref, renderSlot as _renderSlot, vShow as _vShow, mergeProps as _mergeProps, openBlock as _openBlock, createElementBlock as _createElementBlock, withDirectives as _withDirectives, createCommentVNode as _createCommentVNode, Transition as _Transition, withCtx as _withCtx, createVNode as _createVNode, Teleport as _Teleport, createBlock as _createBlock } from "vue";
4
- const _hoisted_1 = ["data-id", "data-idle"];
1
+ <template>
2
+ <teleport v-if="state.renderer && state.active" :to="state.renderer">
3
+ <transition
4
+ :name="state.options.transition?.content"
5
+ :on-before-enter="onBeforeEnter"
6
+ :on-enter="onEnter"
7
+ :on-after-enter="onAfterEnter"
8
+ :on-before-leave="onBeforeLeave"
9
+ :on-leave="onLeave"
10
+ :on-after-leave="onAfterLeave"
11
+ >
12
+ <div
13
+ v-if="isActive"
14
+ v-show="!isIdle"
15
+ ref="el"
16
+ :key="`${viewId}-content`"
17
+ class="magic-command-content"
18
+ :data-id="`${viewId}-content`"
19
+ :data-idle="isIdle"
20
+ v-bind="$attrs"
21
+ >
22
+ <slot />
23
+ </div>
24
+ </transition>
25
+ </teleport>
26
+ </template>
27
+
28
+ <script setup>
5
29
  import {
6
30
  ref,
7
31
  inject,
@@ -25,158 +49,121 @@ import { useCommandView } from "../composables/private/useCommandView";
25
49
  import { useCommandState } from "../composables/private/useCommandState";
26
50
  import "@maas/vue-equipment/utils/css/animations/fade-in.css";
27
51
  import "@maas/vue-equipment/utils/css/animations/fade-out.css";
28
- export default /* @__PURE__ */ _defineComponent({
29
- ...{
30
- inheritAttrs: false
31
- },
32
- __name: "MagicCommandContent",
33
- setup(__props) {
34
- const instanceId = inject(MagicCommandInstanceId, void 0);
35
- const viewId = inject(MagicCommandViewId, void 0);
36
- const elRef = useTemplateRef("el");
37
- if (!instanceId) {
38
- throw new Error(
39
- "MagicCommandContent must be nested inside MagicCommandProvider"
40
- );
41
- }
42
- if (!viewId) {
43
- throw new Error("MagicCommandContent must be nested inside MagicCommandView");
44
- }
45
- const { getView } = useCommandView(instanceId);
46
- const view = getView(viewId);
47
- const { initializeState } = useCommandState(instanceId);
48
- const state = initializeState();
49
- const isActive = computed(() => view?.active && state.active && state.renderer);
50
- const isIdle = computed(() => state.input.view !== viewId);
51
- const options = inject(MagicCommandProviderOptions, void 0);
52
- const { activeItem, selectNextItem, selectPrevItem } = useCommandItem({
53
- instanceId,
54
- viewId
55
- });
56
- const {
57
- onBeforeEnter,
58
- onEnter,
59
- onAfterEnter,
60
- onBeforeLeave,
61
- onLeave,
62
- onAfterLeave
63
- } = useCommandCallback({
64
- instanceId,
65
- viewId
66
- });
67
- const {
68
- findElement,
69
- findScrollableAncestor,
70
- isElementAbove,
71
- isElementBelow,
72
- scrollInFromBottom,
73
- scrollInFromTop
74
- } = useCommandScroll(elRef);
75
- const keys = useMagicKeys();
76
- const nextTimeout = ref(void 0);
77
- const prevTimeout = ref(void 0);
78
- const nextInterval = ref(void 0);
79
- const prevInterval = ref(void 0);
80
- if (options?.keyListener?.next) {
81
- for (const key of options.keyListener.next) {
82
- watch(keys[key], (value) => {
83
- if (isIdle.value) {
84
- return;
85
- }
86
- if (value) {
87
- state.input.type = "keyboard";
52
+ defineOptions({
53
+ inheritAttrs: false
54
+ });
55
+ const instanceId = inject(MagicCommandInstanceId, void 0);
56
+ const viewId = inject(MagicCommandViewId, void 0);
57
+ const elRef = useTemplateRef("el");
58
+ if (!instanceId) {
59
+ throw new Error(
60
+ "MagicCommandContent must be nested inside MagicCommandProvider"
61
+ );
62
+ }
63
+ if (!viewId) {
64
+ throw new Error("MagicCommandContent must be nested inside MagicCommandView");
65
+ }
66
+ const { getView } = useCommandView(instanceId);
67
+ const view = getView(viewId);
68
+ const { initializeState } = useCommandState(instanceId);
69
+ const state = initializeState();
70
+ const isActive = computed(() => view?.active && state.active && state.renderer);
71
+ const isIdle = computed(() => state.input.view !== viewId);
72
+ const options = inject(MagicCommandProviderOptions, void 0);
73
+ const { activeItem, selectNextItem, selectPrevItem } = useCommandItem({
74
+ instanceId,
75
+ viewId
76
+ });
77
+ const {
78
+ onBeforeEnter,
79
+ onEnter,
80
+ onAfterEnter,
81
+ onBeforeLeave,
82
+ onLeave,
83
+ onAfterLeave
84
+ } = useCommandCallback({
85
+ instanceId,
86
+ viewId
87
+ });
88
+ const {
89
+ findElement,
90
+ findScrollableAncestor,
91
+ isElementAbove,
92
+ isElementBelow,
93
+ scrollInFromBottom,
94
+ scrollInFromTop
95
+ } = useCommandScroll(elRef);
96
+ const keys = useMagicKeys();
97
+ const nextTimeout = ref(void 0);
98
+ const prevTimeout = ref(void 0);
99
+ const nextInterval = ref(void 0);
100
+ const prevInterval = ref(void 0);
101
+ if (options?.keyListener?.next) {
102
+ for (const key of options.keyListener.next) {
103
+ watch(keys[key], (value) => {
104
+ if (isIdle.value) {
105
+ return;
106
+ }
107
+ if (value) {
108
+ state.input.type = "keyboard";
109
+ selectNextItem(options.loop);
110
+ nextTimeout.value = setTimeout(() => {
111
+ nextInterval.value = setInterval(() => {
88
112
  selectNextItem(options.loop);
89
- nextTimeout.value = setTimeout(() => {
90
- nextInterval.value = setInterval(() => {
91
- selectNextItem(options.loop);
92
- }, 100);
93
- }, 500);
94
- } else {
95
- clearTimeout(nextTimeout.value);
96
- clearInterval(nextInterval.value);
97
- }
98
- });
113
+ }, 100);
114
+ }, 500);
115
+ } else {
116
+ clearTimeout(nextTimeout.value);
117
+ clearInterval(nextInterval.value);
99
118
  }
100
- }
101
- if (options?.keyListener?.prev) {
102
- for (const key of options.keyListener.prev) {
103
- watch(keys[key], (value) => {
104
- if (isIdle.value) {
105
- return;
106
- }
107
- if (value) {
108
- state.input.type = "keyboard";
119
+ });
120
+ }
121
+ }
122
+ if (options?.keyListener?.prev) {
123
+ for (const key of options.keyListener.prev) {
124
+ watch(keys[key], (value) => {
125
+ if (isIdle.value) {
126
+ return;
127
+ }
128
+ if (value) {
129
+ state.input.type = "keyboard";
130
+ selectPrevItem(options.loop);
131
+ prevTimeout.value = setTimeout(() => {
132
+ prevInterval.value = setInterval(() => {
109
133
  selectPrevItem(options.loop);
110
- prevTimeout.value = setTimeout(() => {
111
- prevInterval.value = setInterval(() => {
112
- selectPrevItem(options.loop);
113
- }, 100);
114
- }, 500);
115
- } else {
116
- clearTimeout(prevTimeout.value);
117
- clearInterval(prevInterval.value);
118
- }
119
- });
134
+ }, 100);
135
+ }, 500);
136
+ } else {
137
+ clearTimeout(prevTimeout.value);
138
+ clearInterval(prevInterval.value);
120
139
  }
140
+ });
141
+ }
142
+ }
143
+ watch(
144
+ activeItem,
145
+ async (value) => {
146
+ if (!value || isIdle.value || state.input.type !== "keyboard") {
147
+ return;
121
148
  }
122
- watch(
123
- activeItem,
124
- async (value) => {
125
- if (!value || isIdle.value || state.input.type !== "keyboard") {
126
- return;
149
+ nextTick(() => {
150
+ const element = findElement(value.id);
151
+ if (element) {
152
+ const ancestor = findScrollableAncestor(element);
153
+ switch (true) {
154
+ case isElementAbove({ element, ancestor }):
155
+ scrollInFromTop({ element, ancestor });
156
+ break;
157
+ case isElementBelow({ element, ancestor }):
158
+ scrollInFromBottom({ element, ancestor });
159
+ break;
127
160
  }
128
- nextTick(() => {
129
- const element = findElement(value.id);
130
- if (element) {
131
- const ancestor = findScrollableAncestor(element);
132
- switch (true) {
133
- case isElementAbove({ element, ancestor }):
134
- scrollInFromTop({ element, ancestor });
135
- break;
136
- case isElementBelow({ element, ancestor }):
137
- scrollInFromBottom({ element, ancestor });
138
- break;
139
- }
140
- }
141
- });
142
- },
143
- { deep: true }
144
- );
145
- provide(MagicCommandContentId, `${viewId}-content`);
146
- return (_ctx, _cache) => {
147
- return _unref(state).renderer && _unref(state).active ? (_openBlock(), _createBlock(_Teleport, {
148
- key: 0,
149
- to: _unref(state).renderer
150
- }, [
151
- _createVNode(_Transition, {
152
- name: _unref(state).options.transition?.content,
153
- "on-before-enter": _unref(onBeforeEnter),
154
- "on-enter": _unref(onEnter),
155
- "on-after-enter": _unref(onAfterEnter),
156
- "on-before-leave": _unref(onBeforeLeave),
157
- "on-leave": _unref(onLeave),
158
- "on-after-leave": _unref(onAfterLeave)
159
- }, {
160
- default: _withCtx(() => [
161
- isActive.value ? _withDirectives((_openBlock(), _createElementBlock("div", _mergeProps({
162
- ref: "el",
163
- key: `${_unref(viewId)}-content`,
164
- class: "magic-command-content",
165
- "data-id": `${_unref(viewId)}-content`,
166
- "data-idle": isIdle.value
167
- }, _ctx.$attrs), [
168
- _renderSlot(_ctx.$slots, "default")
169
- ], 16, _hoisted_1)), [
170
- [_vShow, !isIdle.value]
171
- ]) : _createCommentVNode("v-if", true)
172
- ]),
173
- _: 3
174
- /* FORWARDED */
175
- }, 8, ["name", "on-before-enter", "on-enter", "on-after-enter", "on-before-leave", "on-leave", "on-after-leave"])
176
- ], 8, ["to"])) : _createCommentVNode("v-if", true);
177
- };
178
- }
179
- });
161
+ }
162
+ });
163
+ },
164
+ { deep: true }
165
+ );
166
+ provide(MagicCommandContentId, `${viewId}-content`);
180
167
  </script>
181
168
 
182
169
  <style>
@@ -1,7 +1,7 @@
1
1
  import '@maas/vue-equipment/utils/css/animations/fade-in.css';
2
2
  import '@maas/vue-equipment/utils/css/animations/fade-out.css';
3
3
  declare const viewId: string | undefined;
4
- declare const state: import("../types").CommandState;
4
+ declare const state: import("../types/index.js").CommandState;
5
5
  declare const isActive: import("vue").ComputedRef<false | HTMLElement | null | undefined>;
6
6
  declare const isIdle: import("vue").ComputedRef<boolean>;
7
7
  declare const onBeforeEnter: () => void, onEnter: () => void, onAfterEnter: () => void, onBeforeLeave: () => void, onLeave: () => void, onAfterLeave: () => void;
@@ -1,6 +1,15 @@
1
- <script>
2
- import { defineComponent as _defineComponent } from "vue";
3
- import { unref as _unref, renderSlot as _renderSlot, resolveComponent as _resolveComponent, mergeProps as _mergeProps, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock } from "vue";
1
+ <template>
2
+ <magic-drawer
3
+ :id="instanceId"
4
+ class="magic-command-drawer"
5
+ :options="options"
6
+ v-bind="$attrs"
7
+ >
8
+ <slot />
9
+ </magic-drawer>
10
+ </template>
11
+
12
+ <script setup>
4
13
  import { inject, watch, onBeforeUnmount } from "vue";
5
14
  import {
6
15
  useMagicDrawer,
@@ -8,55 +17,39 @@ import {
8
17
  } from "@maas/vue-equipment/plugins";
9
18
  import { useMagicCommand } from "../composables/useMagicCommand";
10
19
  import { MagicCommandInstanceId } from "../symbols";
11
- export default /* @__PURE__ */ _defineComponent({
12
- ...{
13
- inheritAttrs: false
14
- },
15
- __name: "MagicCommandDrawer",
16
- props: {
17
- options: { type: null, required: false }
18
- },
19
- setup(__props) {
20
- const instanceId = inject(MagicCommandInstanceId, "");
21
- const emitter = useMagicEmitter();
22
- if (!instanceId) {
23
- throw new Error(
24
- "MagicCommandDrawer must be nested inside MagicCommandProvider"
25
- );
26
- }
27
- function afterLeaveCallback(payload) {
28
- if (typeof payload === "string" && payload === instanceId) {
29
- close();
30
- }
31
- }
32
- const { close, isActive } = useMagicCommand(instanceId);
33
- const drawerApi = useMagicDrawer(instanceId);
34
- watch(isActive, (value) => {
35
- if (value) {
36
- drawerApi.open();
37
- } else {
38
- drawerApi.close();
39
- }
40
- });
41
- emitter.on("afterLeave", afterLeaveCallback);
42
- onBeforeUnmount(() => {
43
- emitter.off("afterLeave", afterLeaveCallback);
44
- close();
45
- });
46
- return (_ctx, _cache) => {
47
- const _component_magic_drawer = _resolveComponent("magic-drawer");
48
- return _openBlock(), _createBlock(_component_magic_drawer, _mergeProps({
49
- id: _unref(instanceId),
50
- class: "magic-command-drawer",
51
- options: _ctx.options
52
- }, _ctx.$attrs), {
53
- default: _withCtx(() => [
54
- _renderSlot(_ctx.$slots, "default")
55
- ]),
56
- _: 3
57
- /* FORWARDED */
58
- }, 16, ["id", "options"]);
59
- };
20
+ defineOptions({
21
+ inheritAttrs: false
22
+ });
23
+ defineProps({
24
+ options: {
25
+ type: null,
26
+ required: false
27
+ }
28
+ });
29
+ const instanceId = inject(MagicCommandInstanceId, "");
30
+ const emitter = useMagicEmitter();
31
+ if (!instanceId) {
32
+ throw new Error(
33
+ "MagicCommandDrawer must be nested inside MagicCommandProvider"
34
+ );
35
+ }
36
+ function afterLeaveCallback(payload) {
37
+ if (typeof payload === "string" && payload === instanceId) {
38
+ close();
60
39
  }
40
+ }
41
+ const { close, isActive } = useMagicCommand(instanceId);
42
+ const drawerApi = useMagicDrawer(instanceId);
43
+ watch(isActive, (value) => {
44
+ if (value) {
45
+ drawerApi.open();
46
+ } else {
47
+ drawerApi.close();
48
+ }
49
+ });
50
+ emitter.on("afterLeave", afterLeaveCallback);
51
+ onBeforeUnmount(() => {
52
+ emitter.off("afterLeave", afterLeaveCallback);
53
+ close();
61
54
  });
62
55
  </script>
@@ -1,11 +1,21 @@
1
- <script>
2
- import { defineComponent as _defineComponent } from "vue";
3
- import { unref as _unref, renderSlot as _renderSlot, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode } from "vue";
4
- const _hoisted_1 = ["data-id", "data-disabled", "data-active", "data-pointer-disabled"];
5
- const _hoisted_2 = {
6
- key: 0,
7
- class: "magic-command-item__pointer-guard"
8
- };
1
+ <template>
2
+ <div
3
+ class="magic-command-item"
4
+ :data-id="mappedId"
5
+ :data-disabled="disabled"
6
+ :data-active="item.active"
7
+ :data-pointer-disabled="pointerDisabled"
8
+ @mouseenter="guardedSelect"
9
+ @mousemove="guardedSelect"
10
+ @touchstart.passive="guardedSelect"
11
+ @click="onClick"
12
+ >
13
+ <slot :item-active="item.active" :item-disabled="disabled" />
14
+ <div v-if="pointerDisabled" class="magic-command-item__pointer-guard" />
15
+ </div>
16
+ </template>
17
+
18
+ <script setup>
9
19
  import {
10
20
  computed,
11
21
  inject,
@@ -24,83 +34,71 @@ import {
24
34
  MagicCommandItemActive,
25
35
  MagicCommandItemDisabled
26
36
  } from "../symbols";
27
- export default /* @__PURE__ */ _defineComponent({
28
- __name: "MagicCommandItem",
29
- props: {
30
- id: { type: String, required: false },
31
- initial: { type: Boolean, required: false, default: false },
32
- disabled: { type: Boolean, required: false, default: false }
37
+ const {
38
+ id,
39
+ initial = false,
40
+ disabled = false
41
+ } = defineProps({
42
+ id: {
43
+ type: String,
44
+ required: false
45
+ },
46
+ initial: {
47
+ type: Boolean,
48
+ required: false
33
49
  },
34
- emits: ["click"],
35
- setup(__props, { emit: __emit }) {
36
- const emit = __emit;
37
- const instanceId = inject(MagicCommandInstanceId, void 0);
38
- const viewId = inject(MagicCommandViewId, void 0);
39
- const contentId = inject(MagicCommandContentId, void 0);
40
- if (!instanceId) {
41
- throw new Error("MagicCommandItem must be nested inside MagicCommandProvider");
42
- }
43
- if (!viewId) {
44
- throw new Error("MagicCommandItem must be nested inside MagicCommandView");
45
- }
46
- if (!contentId) {
47
- throw new Error("MagicCommandItem must be nested inside MagicCommandContent");
48
- }
49
- const mappedId = computed(() => __props.id ?? `magic-command-item-${useId()}`);
50
- const { initializeItem, deleteItem, selectItem } = useCommandItem({
51
- instanceId,
52
- viewId
53
- });
54
- const { initializeState } = useCommandState(instanceId);
55
- const state = initializeState();
56
- const item = initializeItem({
57
- id: mappedId.value,
58
- disabled: __props.disabled ?? false
59
- });
60
- const pointerDisabled = computed(() => state.input.type !== "pointer");
61
- const mappedDisabled = computed(() => __props.disabled ?? item?.disabled);
62
- const mappedActive = computed(() => item?.active);
63
- function guardedSelect() {
64
- if (state.input.type === "pointer" && !item.disabled && !item.active) {
65
- selectItem(mappedId.value);
66
- }
67
- }
68
- function onClick(event) {
69
- emit("click", event);
70
- guardedSelect();
71
- }
72
- provide(MagicCommandItemId, mappedId.value);
73
- provide(MagicCommandItemActive, mappedActive);
74
- provide(MagicCommandItemDisabled, mappedDisabled);
75
- onMounted(() => {
76
- if (__props.initial) {
77
- selectItem(mappedId.value);
78
- }
79
- });
80
- onBeforeUnmount(() => {
81
- deleteItem(mappedId.value);
82
- });
83
- return (_ctx, _cache) => {
84
- return _openBlock(), _createElementBlock("div", {
85
- class: "magic-command-item",
86
- "data-id": mappedId.value,
87
- "data-disabled": _ctx.disabled,
88
- "data-active": _unref(item).active,
89
- "data-pointer-disabled": pointerDisabled.value,
90
- onMouseenter: guardedSelect,
91
- onMousemove: guardedSelect,
92
- onTouchstartPassive: guardedSelect,
93
- onClick
94
- }, [
95
- _renderSlot(_ctx.$slots, "default", {
96
- itemActive: _unref(item).active,
97
- itemDisabled: _ctx.disabled
98
- }),
99
- pointerDisabled.value ? (_openBlock(), _createElementBlock("div", _hoisted_2)) : _createCommentVNode("v-if", true)
100
- ], 40, _hoisted_1);
101
- };
50
+ disabled: {
51
+ type: Boolean,
52
+ required: false
102
53
  }
103
54
  });
55
+ const emit = defineEmits(["click"]);
56
+ const instanceId = inject(MagicCommandInstanceId, void 0);
57
+ const viewId = inject(MagicCommandViewId, void 0);
58
+ const contentId = inject(MagicCommandContentId, void 0);
59
+ if (!instanceId) {
60
+ throw new Error("MagicCommandItem must be nested inside MagicCommandProvider");
61
+ }
62
+ if (!viewId) {
63
+ throw new Error("MagicCommandItem must be nested inside MagicCommandView");
64
+ }
65
+ if (!contentId) {
66
+ throw new Error("MagicCommandItem must be nested inside MagicCommandContent");
67
+ }
68
+ const mappedId = computed(() => id ?? `magic-command-item-${useId()}`);
69
+ const { initializeItem, deleteItem, selectItem } = useCommandItem({
70
+ instanceId,
71
+ viewId
72
+ });
73
+ const { initializeState } = useCommandState(instanceId);
74
+ const state = initializeState();
75
+ const item = initializeItem({
76
+ id: mappedId.value,
77
+ disabled: disabled ?? false
78
+ });
79
+ const pointerDisabled = computed(() => state.input.type !== "pointer");
80
+ const mappedDisabled = computed(() => disabled ?? item?.disabled);
81
+ const mappedActive = computed(() => item?.active);
82
+ function guardedSelect() {
83
+ if (state.input.type === "pointer" && !item.disabled && !item.active) {
84
+ selectItem(mappedId.value);
85
+ }
86
+ }
87
+ function onClick(event) {
88
+ emit("click", event);
89
+ guardedSelect();
90
+ }
91
+ provide(MagicCommandItemId, mappedId.value);
92
+ provide(MagicCommandItemActive, mappedActive);
93
+ provide(MagicCommandItemDisabled, mappedDisabled);
94
+ onMounted(() => {
95
+ if (initial) {
96
+ selectItem(mappedId.value);
97
+ }
98
+ });
99
+ onBeforeUnmount(() => {
100
+ deleteItem(mappedId.value);
101
+ });
104
102
  </script>
105
103
 
106
104
  <style>
@@ -4,7 +4,7 @@ interface MagicCommandItemProps {
4
4
  disabled?: boolean;
5
5
  }
6
6
  declare const mappedId: import("vue").ComputedRef<string>;
7
- declare const item: import("../types").CommandItem;
7
+ declare const item: import("../types/index.js").CommandItem;
8
8
  declare const pointerDisabled: import("vue").ComputedRef<boolean>;
9
9
  declare function guardedSelect(): void;
10
10
  declare function onClick(event: MouseEvent): void;