@ui-sdk/vue 0.0.0-stage → 0.1.0-beta.1
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/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +561 -0
- package/dist/accordion.js +24 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +7 -0
- package/dist/alert-dialog.d.ts +231 -0
- package/dist/alert-dialog.js +33 -0
- package/dist/async-options.d.ts +18 -0
- package/dist/async-options.js +40 -0
- package/dist/autocomplete.d.ts +384 -0
- package/dist/autocomplete.js +344 -0
- package/dist/avatar.d.ts +40 -0
- package/dist/avatar.js +28 -0
- package/dist/button.d.ts +52 -0
- package/dist/button.js +43 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +7 -0
- package/dist/calendar.d.ts +311 -0
- package/dist/calendar.js +349 -0
- package/dist/carousel.d.ts +236 -0
- package/dist/carousel.js +204 -0
- package/dist/checkbox.d.ts +211 -0
- package/dist/checkbox.js +151 -0
- package/dist/children.d.ts +41 -0
- package/dist/children.js +135 -0
- package/dist/collapsible.d.ts +54 -0
- package/dist/collapsible.js +18 -0
- package/dist/color-picker.d.ts +187 -0
- package/dist/color-picker.js +158 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +21 -0
- package/dist/combobox.d.ts +517 -0
- package/dist/combobox.js +531 -0
- package/dist/command.d.ts +322 -0
- package/dist/command.js +345 -0
- package/dist/controller-target.d.ts +49 -0
- package/dist/controller-target.js +112 -0
- package/dist/create-parts.d.ts +126 -0
- package/dist/create-parts.js +206 -0
- package/dist/date-input.d.ts +133 -0
- package/dist/date-input.js +31 -0
- package/dist/date-picker.d.ts +328 -0
- package/dist/date-picker.js +354 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +59 -0
- package/dist/dialog-parts.d.ts +259 -0
- package/dist/dialog-parts.js +300 -0
- package/dist/dialog.d.ts +251 -0
- package/dist/dialog.js +25 -0
- package/dist/drawer.d.ts +304 -0
- package/dist/drawer.js +373 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +5 -0
- package/dist/field-context.d.ts +26 -0
- package/dist/field-context.js +44 -0
- package/dist/field.d.ts +154 -0
- package/dist/field.js +240 -0
- package/dist/file-input.d.ts +212 -0
- package/dist/file-input.js +255 -0
- package/dist/form-inputs.d.ts +16 -0
- package/dist/form-inputs.js +25 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +15 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +11 -0
- package/dist/hover-card.d.ts +137 -0
- package/dist/hover-card.js +153 -0
- package/dist/image-cropper.d.ts +74 -0
- package/dist/image-cropper.js +36 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +5 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +60 -0
- package/dist/input.d.ts +120 -0
- package/dist/input.js +73 -0
- package/dist/item-icon.d.ts +34 -0
- package/dist/item-icon.js +63 -0
- package/dist/label.d.ts +16 -0
- package/dist/label.js +8 -0
- package/dist/lifecycle.d.ts +11 -0
- package/dist/lifecycle.js +91 -0
- package/dist/list-items.d.ts +38 -0
- package/dist/list-items.js +59 -0
- package/dist/list-text.d.ts +7 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +273 -0
- package/dist/listbox.js +126 -0
- package/dist/menu.d.ts +678 -0
- package/dist/menu.js +607 -0
- package/dist/menubar-context.d.ts +5 -0
- package/dist/menubar-context.js +5 -0
- package/dist/menubar.d.ts +61 -0
- package/dist/menubar.js +48 -0
- package/dist/meter.d.ts +41 -0
- package/dist/meter.js +37 -0
- package/dist/navigation-menu.d.ts +228 -0
- package/dist/navigation-menu.js +195 -0
- package/dist/number-input.d.ts +176 -0
- package/dist/number-input.js +231 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +39 -0
- package/dist/nuxt/entries.json +977 -0
- package/dist/nuxt/module.d.ts +18 -0
- package/dist/nuxt/module.js +31 -0
- package/dist/nuxt/registrations.d.ts +22 -0
- package/dist/nuxt/registrations.js +22 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +7 -0
- package/dist/otp-input.d.ts +142 -0
- package/dist/otp-input.js +130 -0
- package/dist/overlays.d.ts +40 -0
- package/dist/overlays.js +118 -0
- package/dist/pagination.d.ts +201 -0
- package/dist/pagination.js +146 -0
- package/dist/password-input.d.ts +144 -0
- package/dist/password-input.js +134 -0
- package/dist/popover.d.ts +211 -0
- package/dist/popover.js +258 -0
- package/dist/popup.d.ts +60 -0
- package/dist/popup.js +89 -0
- package/dist/preferences.d.ts +44 -0
- package/dist/preferences.js +102 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +11 -0
- package/dist/progress.d.ts +41 -0
- package/dist/progress.js +37 -0
- package/dist/radio.d.ts +164 -0
- package/dist/radio.js +145 -0
- package/dist/rating.d.ts +149 -0
- package/dist/rating.js +146 -0
- package/dist/renderless.d.ts +4 -0
- package/dist/renderless.js +28 -0
- package/dist/resizable.d.ts +54 -0
- package/dist/resizable.js +22 -0
- package/dist/scroll-area.d.ts +72 -0
- package/dist/scroll-area.js +77 -0
- package/dist/segmented-control.d.ts +151 -0
- package/dist/segmented-control.js +110 -0
- package/dist/segmented-input.d.ts +76 -0
- package/dist/segmented-input.js +115 -0
- package/dist/select.d.ts +458 -0
- package/dist/select.js +468 -0
- package/dist/separator.d.ts +14 -0
- package/dist/separator.js +8 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +56 -0
- package/dist/slider.d.ts +65 -0
- package/dist/slider.js +194 -0
- package/dist/switch.d.ts +103 -0
- package/dist/switch.js +71 -0
- package/dist/tabs.d.ts +338 -0
- package/dist/tabs.js +27 -0
- package/dist/text-control.d.ts +89 -0
- package/dist/text-control.js +51 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +7 -0
- package/dist/textarea.d.ts +106 -0
- package/dist/textarea.js +68 -0
- package/dist/time-input.d.ts +131 -0
- package/dist/time-input.js +32 -0
- package/dist/timeline.d.ts +81 -0
- package/dist/timeline.js +30 -0
- package/dist/toast-parts.d.ts +203 -0
- package/dist/toast-parts.js +270 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +21 -0
- package/dist/toggle-props.d.ts +22 -0
- package/dist/toggle-props.js +14 -0
- package/dist/toggle.d.ts +199 -0
- package/dist/toggle.js +129 -0
- package/dist/token-input.d.ts +136 -0
- package/dist/token-input.js +214 -0
- package/dist/toolbar-context.d.ts +7 -0
- package/dist/toolbar-context.js +20 -0
- package/dist/toolbar.d.ts +120 -0
- package/dist/toolbar.js +77 -0
- package/dist/tooltip.d.ts +160 -0
- package/dist/tooltip.js +224 -0
- package/dist/tree.d.ts +300 -0
- package/dist/tree.js +209 -0
- package/dist/trigger-menu.d.ts +452 -0
- package/dist/trigger-menu.js +254 -0
- package/dist/use-primitive.d.ts +132 -0
- package/dist/use-primitive.js +462 -0
- package/dist/waterfall.d.ts +201 -0
- package/dist/waterfall.js +171 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1369 -0
- package/docs/components/alert-dialog.md +799 -0
- package/docs/components/autocomplete.md +1857 -0
- package/docs/components/avatar.md +272 -0
- package/docs/components/button.md +435 -0
- package/docs/components/calendar.md +1589 -0
- package/docs/components/carousel.md +1171 -0
- package/docs/components/checkbox.md +1008 -0
- package/docs/components/collapsible.md +536 -0
- package/docs/components/color-picker.md +706 -0
- package/docs/components/combobox.md +3504 -0
- package/docs/components/command.md +1481 -0
- package/docs/components/date-input.md +536 -0
- package/docs/components/date-picker.md +1244 -0
- package/docs/components/dialog.md +1397 -0
- package/docs/components/drawer.md +1166 -0
- package/docs/components/field.md +538 -0
- package/docs/components/file-input.md +611 -0
- package/docs/components/hover-card.md +505 -0
- package/docs/components/image-cropper.md +556 -0
- package/docs/components/input.md +306 -0
- package/docs/components/label.md +203 -0
- package/docs/components/listbox.md +1004 -0
- package/docs/components/menu.md +1229 -0
- package/docs/components/menubar.md +443 -0
- package/docs/components/meter.md +315 -0
- package/docs/components/navigation-menu.md +1523 -0
- package/docs/components/number-input.md +1029 -0
- package/docs/components/otp-input.md +512 -0
- package/docs/components/pagination.md +613 -0
- package/docs/components/password-input.md +649 -0
- package/docs/components/popover.md +1448 -0
- package/docs/components/preferences.md +208 -0
- package/docs/components/progress.md +423 -0
- package/docs/components/radio.md +785 -0
- package/docs/components/rating.md +416 -0
- package/docs/components/resizable.md +910 -0
- package/docs/components/scroll-area.md +915 -0
- package/docs/components/segmented-control.md +435 -0
- package/docs/components/select.md +2015 -0
- package/docs/components/separator.md +229 -0
- package/docs/components/slider.md +1084 -0
- package/docs/components/switch.md +565 -0
- package/docs/components/tabs.md +944 -0
- package/docs/components/textarea.md +299 -0
- package/docs/components/time-input.md +224 -0
- package/docs/components/timeline.md +654 -0
- package/docs/components/toast.md +1224 -0
- package/docs/components/toggle.md +500 -0
- package/docs/components/token-input.md +953 -0
- package/docs/components/toolbar.md +739 -0
- package/docs/components/tooltip.md +818 -0
- package/docs/components/tree.md +1306 -0
- package/docs/components/trigger-menu.md +1223 -0
- package/docs/components/waterfall.md +717 -0
- package/docs/controllers.md +71 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +89 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +122 -0
- package/docs/installation.md +72 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +122 -0
- package/docs/llms.txt +1502 -0
- package/docs/parts-and-composition.md +85 -0
- package/docs/popups.md +108 -0
- package/docs/rendering.md +56 -0
- package/docs/server-rendering.md +180 -0
- package/docs/state-and-events.md +100 -0
- package/docs/styling-and-animation.md +148 -0
- package/docs/utilities/async-options.md +348 -0
- package/docs/utilities/shortcuts.md +159 -0
- package/package.json +352 -3
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// src/trigger-menu.ts
|
|
2
|
+
import {
|
|
3
|
+
triggerMenu as triggerMenuPrimitive
|
|
4
|
+
} from "@ui-sdk/core/trigger-menu";
|
|
5
|
+
import {
|
|
6
|
+
defineComponent,
|
|
7
|
+
h,
|
|
8
|
+
inject,
|
|
9
|
+
provide
|
|
10
|
+
} from "vue";
|
|
11
|
+
import {
|
|
12
|
+
hasChild,
|
|
13
|
+
NotPlaced,
|
|
14
|
+
usePlaceContent,
|
|
15
|
+
usePlacedContent
|
|
16
|
+
} from "./children.js";
|
|
17
|
+
import { EditorKey } from "./editor-context.js";
|
|
18
|
+
import {
|
|
19
|
+
containerProp,
|
|
20
|
+
renderPopup,
|
|
21
|
+
useControllerEntry
|
|
22
|
+
} from "./popup.js";
|
|
23
|
+
import { ListItems } from "./list-items.js";
|
|
24
|
+
import { createParts, withElement } from "./create-parts.js";
|
|
25
|
+
import {
|
|
26
|
+
defaultSlot,
|
|
27
|
+
optionalBoolean,
|
|
28
|
+
orModel,
|
|
29
|
+
useHandle,
|
|
30
|
+
usePart,
|
|
31
|
+
usePrimitive
|
|
32
|
+
} from "./use-primitive.js";
|
|
33
|
+
import { renderless } from "./renderless.js";
|
|
34
|
+
import {
|
|
35
|
+
createTriggerMenuController,
|
|
36
|
+
textFieldAdapter
|
|
37
|
+
} from "@ui-sdk/core/trigger-menu";
|
|
38
|
+
var ContainerKey = /* @__PURE__ */ Symbol(
|
|
39
|
+
"trigger-menu-container"
|
|
40
|
+
);
|
|
41
|
+
var useTriggerMenu = () => useHandle(triggerMenuPrimitive);
|
|
42
|
+
var parts = createParts(triggerMenuPrimitive, {
|
|
43
|
+
input: "textarea",
|
|
44
|
+
item: "div",
|
|
45
|
+
"item-icon": "span",
|
|
46
|
+
group: "div",
|
|
47
|
+
"group-label": "div",
|
|
48
|
+
separator: "div"
|
|
49
|
+
});
|
|
50
|
+
var TriggerMenu = /* @__PURE__ */ renderless(
|
|
51
|
+
defineComponent({
|
|
52
|
+
name: "TriggerMenu",
|
|
53
|
+
props: {
|
|
54
|
+
triggers: {
|
|
55
|
+
type: Array,
|
|
56
|
+
required: true
|
|
57
|
+
},
|
|
58
|
+
editor: Object,
|
|
59
|
+
open: optionalBoolean,
|
|
60
|
+
modelValue: optionalBoolean,
|
|
61
|
+
status: String,
|
|
62
|
+
autoHighlight: optionalBoolean,
|
|
63
|
+
loop: optionalBoolean,
|
|
64
|
+
shortcut: String,
|
|
65
|
+
controller: Object,
|
|
66
|
+
dismissible: optionalBoolean,
|
|
67
|
+
debug: optionalBoolean,
|
|
68
|
+
container: containerProp,
|
|
69
|
+
// An action handler: a function prop beside the emit, so a returned Promise inserts a pending token.
|
|
70
|
+
onSelect: Function,
|
|
71
|
+
pendingAnnouncement: String
|
|
72
|
+
},
|
|
73
|
+
emits: {
|
|
74
|
+
"update:open": (_open) => true,
|
|
75
|
+
"update:modelValue": (_open) => true,
|
|
76
|
+
openChange: (_open, _details) => true,
|
|
77
|
+
openChangeComplete: (_open) => true,
|
|
78
|
+
dismissAttempt: (_details) => true,
|
|
79
|
+
queryChange: (_query, _details) => true
|
|
80
|
+
},
|
|
81
|
+
setup(props, { slots, emit }) {
|
|
82
|
+
const inherited = inject(EditorKey, () => void 0);
|
|
83
|
+
provide(ContainerKey, () => props.container);
|
|
84
|
+
const menu = usePrimitive(triggerMenuPrimitive, () => ({
|
|
85
|
+
...props,
|
|
86
|
+
open: orModel(props.open, props.modelValue),
|
|
87
|
+
container: void 0,
|
|
88
|
+
editor: props.editor ?? inherited(),
|
|
89
|
+
onOpenChange: (open, details) => {
|
|
90
|
+
emit("openChange", open, details);
|
|
91
|
+
if (details.canceled) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
emit("update:open", open);
|
|
95
|
+
emit("update:modelValue", open);
|
|
96
|
+
},
|
|
97
|
+
onOpenChangeComplete: (open) => emit("openChangeComplete", open),
|
|
98
|
+
onDismissAttempt: (details) => emit("dismissAttempt", details),
|
|
99
|
+
onQueryChange: (query, details) => emit("queryChange", query, details)
|
|
100
|
+
}));
|
|
101
|
+
useControllerEntry(() => props.controller, menu);
|
|
102
|
+
const placed = usePlacedContent();
|
|
103
|
+
return () => {
|
|
104
|
+
const children = slots.default?.() ?? [];
|
|
105
|
+
const own = placed() || hasChild(children, TriggerMenuContent);
|
|
106
|
+
return [children, !own && h(NotPlaced, () => h(TriggerMenuContent))];
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
var TriggerMenuInput = parts.Input;
|
|
112
|
+
var TriggerMenuContent = withElement(
|
|
113
|
+
"div",
|
|
114
|
+
defineComponent({
|
|
115
|
+
name: "TriggerMenuContent",
|
|
116
|
+
inheritAttrs: false,
|
|
117
|
+
props: {
|
|
118
|
+
side: String,
|
|
119
|
+
align: String,
|
|
120
|
+
sideOffset: Number,
|
|
121
|
+
alignOffset: Number,
|
|
122
|
+
collisionPadding: Number,
|
|
123
|
+
arrowPadding: Number,
|
|
124
|
+
anchor: [Object, String],
|
|
125
|
+
keepMounted: optionalBoolean,
|
|
126
|
+
container: containerProp
|
|
127
|
+
},
|
|
128
|
+
slots: Object,
|
|
129
|
+
setup(props, { slots }) {
|
|
130
|
+
usePlaceContent();
|
|
131
|
+
const menu = useTriggerMenu();
|
|
132
|
+
const inherited = inject(ContainerKey, () => void 0);
|
|
133
|
+
const content = () => {
|
|
134
|
+
const { container, ...content2 } = props;
|
|
135
|
+
return content2;
|
|
136
|
+
};
|
|
137
|
+
const part = usePart(menu, "content", content, void 0, {
|
|
138
|
+
tag: "div",
|
|
139
|
+
children: (state) => defaultSlot(slots, state, () => h(TriggerMenuList))
|
|
140
|
+
});
|
|
141
|
+
return () => {
|
|
142
|
+
const element = part();
|
|
143
|
+
if (!element) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return renderPopup(element, props.container ?? inherited());
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
var TriggerMenuList = withElement(
|
|
152
|
+
"div",
|
|
153
|
+
defineComponent({
|
|
154
|
+
name: "TriggerMenuList",
|
|
155
|
+
inheritAttrs: false,
|
|
156
|
+
slots: Object,
|
|
157
|
+
setup(_, { slots }) {
|
|
158
|
+
return usePart(triggerMenuPrimitive, "list", void 0, void 0, {
|
|
159
|
+
tag: "div",
|
|
160
|
+
children: (state) => defaultSlot(
|
|
161
|
+
slots,
|
|
162
|
+
state,
|
|
163
|
+
() => h(TriggerMenuItems, { items: state.items })
|
|
164
|
+
)
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
var TriggerMenuItem = parts.Item;
|
|
170
|
+
var TriggerMenuItemIcon = parts.ItemIcon;
|
|
171
|
+
var TriggerMenuGroup = parts.Group;
|
|
172
|
+
var TriggerMenuGroupLabel = parts.GroupLabel;
|
|
173
|
+
var TriggerMenuSeparator = parts.Separator;
|
|
174
|
+
var TriggerMenuEmpty = withElement(
|
|
175
|
+
"div",
|
|
176
|
+
defineComponent({
|
|
177
|
+
name: "TriggerMenuEmpty",
|
|
178
|
+
inheritAttrs: false,
|
|
179
|
+
slots: Object,
|
|
180
|
+
setup(_, { slots }) {
|
|
181
|
+
return usePart(triggerMenuPrimitive, "empty", void 0, void 0, {
|
|
182
|
+
tag: "div",
|
|
183
|
+
children: (state) => state.empty ? slots.default?.({ state }) : null
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
var TriggerMenuStatus = withElement(
|
|
189
|
+
"div",
|
|
190
|
+
defineComponent({
|
|
191
|
+
name: "TriggerMenuStatus",
|
|
192
|
+
inheritAttrs: false,
|
|
193
|
+
slots: Object,
|
|
194
|
+
setup(_, { slots }) {
|
|
195
|
+
return usePart(triggerMenuPrimitive, "status", () => ({
|
|
196
|
+
text: !slots.default
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
);
|
|
201
|
+
var TriggerMenuHint = withElement(
|
|
202
|
+
"span",
|
|
203
|
+
defineComponent({
|
|
204
|
+
name: "TriggerMenuHint",
|
|
205
|
+
inheritAttrs: false,
|
|
206
|
+
slots: Object,
|
|
207
|
+
setup(_, { slots }) {
|
|
208
|
+
return usePart(
|
|
209
|
+
triggerMenuPrimitive,
|
|
210
|
+
"hint",
|
|
211
|
+
() => ({ text: !slots.default }),
|
|
212
|
+
void 0,
|
|
213
|
+
"span"
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
);
|
|
218
|
+
var TriggerMenuItems = defineComponent({
|
|
219
|
+
name: "TriggerMenuItems",
|
|
220
|
+
props: {
|
|
221
|
+
items: { type: Array, required: true }
|
|
222
|
+
},
|
|
223
|
+
setup(props) {
|
|
224
|
+
const menu = useTriggerMenu();
|
|
225
|
+
return () => h(ListItems, {
|
|
226
|
+
items: props.items,
|
|
227
|
+
parts: listParts,
|
|
228
|
+
keyOf: menu.api.internal.keyOf
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
var listParts = {
|
|
233
|
+
Item: TriggerMenuItem,
|
|
234
|
+
Group: TriggerMenuGroup,
|
|
235
|
+
GroupLabel: TriggerMenuGroupLabel,
|
|
236
|
+
Separator: TriggerMenuSeparator
|
|
237
|
+
};
|
|
238
|
+
export {
|
|
239
|
+
TriggerMenu,
|
|
240
|
+
TriggerMenuContent,
|
|
241
|
+
TriggerMenuEmpty,
|
|
242
|
+
TriggerMenuGroup,
|
|
243
|
+
TriggerMenuGroupLabel,
|
|
244
|
+
TriggerMenuHint,
|
|
245
|
+
TriggerMenuInput,
|
|
246
|
+
TriggerMenuItem,
|
|
247
|
+
TriggerMenuItemIcon,
|
|
248
|
+
TriggerMenuItems,
|
|
249
|
+
TriggerMenuList,
|
|
250
|
+
TriggerMenuSeparator,
|
|
251
|
+
TriggerMenuStatus,
|
|
252
|
+
createTriggerMenuController,
|
|
253
|
+
textFieldAdapter
|
|
254
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { OptionsOf, Primitive, PropsOf, SlotName, StateOf, TypesOf } from "@ui-sdk/core";
|
|
2
|
+
import { type FunctionalComponent, type Slots, type SlotsType, type VNode } from "vue";
|
|
3
|
+
declare const optionalBoolean: {
|
|
4
|
+
type: BooleanConstructor;
|
|
5
|
+
default: undefined;
|
|
6
|
+
};
|
|
7
|
+
declare const orModel: <T>(value: T | undefined, model: T | undefined) => T | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* What `usePrimitive` returns, and what the parts inside its component find.
|
|
10
|
+
* @stable
|
|
11
|
+
*/
|
|
12
|
+
type PrimitiveHandle<P extends Primitive> = {
|
|
13
|
+
/** The primitive it's an instance of. */
|
|
14
|
+
primitive: P;
|
|
15
|
+
/** The core instance `usePrimitive` made, with its `get()`, `part()` and `api`. Read `state` instead of its `get()` in a render, since `get()` tracks nothing. */
|
|
16
|
+
instance: ReturnType<P>;
|
|
17
|
+
/** The methods its definition declares, like Tabs' `setValue`. */
|
|
18
|
+
api: TypesOf<P>["api"];
|
|
19
|
+
/** The instance's state. Reading it inside a render tracks it. */
|
|
20
|
+
readonly state: TypesOf<P>["state"];
|
|
21
|
+
/** Whether a slot's element should exist. Reading it inside a render tracks it. */
|
|
22
|
+
present: <S extends SlotName<P>>(name: S, props?: PropsOf<P, S>) => boolean;
|
|
23
|
+
/** Attributes, listeners and a ref for a slot's element. User listeners run first. */
|
|
24
|
+
slot: <S extends SlotName<P>>(name: S, props?: PropsOf<P, S>, user?: Record<string, any>) => Record<string, any>;
|
|
25
|
+
};
|
|
26
|
+
type Scope = {
|
|
27
|
+
handle: PrimitiveHandle<Primitive>;
|
|
28
|
+
around: Record<string, () => Record<string, unknown>>;
|
|
29
|
+
};
|
|
30
|
+
declare const pascal: (name: string) => string;
|
|
31
|
+
/** The nearest instance of a primitive and the props of the parts around, or null outside one. */
|
|
32
|
+
declare function useScope<P extends Primitive>(primitive: P): (Scope & {
|
|
33
|
+
handle: PrimitiveHandle<P>;
|
|
34
|
+
}) | null;
|
|
35
|
+
/** The nearest instance of a primitive, for a part written by hand. Throws outside one. */
|
|
36
|
+
declare function useHandle<P extends Primitive>(primitive: P): PrimitiveHandle<Primitive> & PrimitiveHandle<P>;
|
|
37
|
+
/** Shares a handle with the parts inside, like a trigger's outside its root, connected by a controller. */
|
|
38
|
+
declare function provideHandle<P extends Primitive>(handle: PrimitiveHandle<P>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Shares a part's props with the parts inside it, for the props they take
|
|
41
|
+
* from it when they're left out, like an item's `value` for its icon.
|
|
42
|
+
*/
|
|
43
|
+
declare function provideProps(primitive: Primitive, slot: string, props: () => Record<string, unknown>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Creates an instance of a primitive for this component, keeps its options
|
|
46
|
+
* current, and destroys it when the component unmounts. Pass the options as a
|
|
47
|
+
* getter, so reactive props stay in sync. Parts inside the component use it.
|
|
48
|
+
* @stable
|
|
49
|
+
*/
|
|
50
|
+
declare function usePrimitive<P extends Primitive>(primitive: P, options: () => OptionsOf<P>): PrimitiveHandle<P>;
|
|
51
|
+
/**
|
|
52
|
+
* A plain copy of a component's props that tracks each one it reads, for
|
|
53
|
+
* spreading into options. Vue's props are a proxy, and V8 copies a proxy
|
|
54
|
+
* with spread or rest through a slow generic path: in Node, a tooltip's 12
|
|
55
|
+
* props took 9 µs that way and 0.8 µs read one by one. The raw props hold every
|
|
56
|
+
* declared prop, so the copy has the same keys in the same order.
|
|
57
|
+
*/
|
|
58
|
+
declare function copyProps<T extends object>(props: T): T;
|
|
59
|
+
type StateSlotFunctions<State> = {
|
|
60
|
+
/** The part's content, which receives its state. */
|
|
61
|
+
default?: (scope: {
|
|
62
|
+
state: State;
|
|
63
|
+
}) => VNode[];
|
|
64
|
+
/**
|
|
65
|
+
* Renders your own element: bind `props` to it. `children` is the part's
|
|
66
|
+
* content, like a slider thumb's range input: render it inside with
|
|
67
|
+
* `<component :is="children" />`.
|
|
68
|
+
*/
|
|
69
|
+
render?: (scope: {
|
|
70
|
+
props: Record<string, unknown>;
|
|
71
|
+
state: State;
|
|
72
|
+
children: FunctionalComponent;
|
|
73
|
+
}) => VNode[];
|
|
74
|
+
};
|
|
75
|
+
type StateSlots<State> = SlotsType<StateSlotFunctions<State>>;
|
|
76
|
+
/**
|
|
77
|
+
* A part's slots, typed from its primitive, for a part written by hand:
|
|
78
|
+
* `slots: Object as PartSlots<typeof rating, "star">`, so a template reads
|
|
79
|
+
* its state with the types and completion of a `createParts` part.
|
|
80
|
+
* @stable
|
|
81
|
+
*/
|
|
82
|
+
type PartSlots<P extends Primitive, S extends SlotName<P>> = StateSlots<StateOf<P, S>>;
|
|
83
|
+
/** A part's default slot, rendered apart from the part, or `fallback` when it renders nothing. */
|
|
84
|
+
declare function defaultSlot(slots: Slots, state: object, fallback?: () => unknown): unknown;
|
|
85
|
+
/**
|
|
86
|
+
* How `usePart` renders a part beyond its tag: content of its own in place of
|
|
87
|
+
* the default slot, an element it always holds, and props added after the
|
|
88
|
+
* slot's attributes.
|
|
89
|
+
* @stable
|
|
90
|
+
*/
|
|
91
|
+
type PartElement<State> = {
|
|
92
|
+
/** The tag it renders unless the `render` slot replaces it. */
|
|
93
|
+
tag: string;
|
|
94
|
+
/** Its content, from its state. Without it, the default slot, which receives the state. */
|
|
95
|
+
children?: (state: State) => unknown;
|
|
96
|
+
/** An element inside the part, or next to what the `render` slot returns, like a root's hidden form input. */
|
|
97
|
+
hidden?: () => VNode;
|
|
98
|
+
/** Its props after the slot's attributes merge in, like a field's attributes on its control. */
|
|
99
|
+
extend?: (props: Record<string, any>) => Record<string, any>;
|
|
100
|
+
};
|
|
101
|
+
declare function renderElement(props: Record<string, unknown>, slots: Slots, state: object | undefined, element: PartElement<any>): VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
102
|
+
[key: string]: any;
|
|
103
|
+
}> | VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
}>[];
|
|
106
|
+
/**
|
|
107
|
+
* Renders one part of a primitive written by hand, from its component's
|
|
108
|
+
* setup: its element, with the slot's attributes and handlers merged into the
|
|
109
|
+
* component's attrs, re-rendered when what it shows changes, or nothing while
|
|
110
|
+
* the slot says it isn't present. Returns the render function, with the
|
|
111
|
+
* part's state as its `state`. `handle` is `usePrimitive`'s, or the
|
|
112
|
+
* primitive, whose nearest instance it uses. `props` replaces the element
|
|
113
|
+
* props, the component's attrs by default. The `render` slot and the default
|
|
114
|
+
* slot receive the part's state. `element` is the tag, or what to render
|
|
115
|
+
* beyond it (`PartElement`).
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* const StarIcon = defineComponent({
|
|
119
|
+
* inheritAttrs: false,
|
|
120
|
+
* props: { value: { type: String, required: true } },
|
|
121
|
+
* setup: (props) => usePart(rating, "star-icon", () => ({ value: props.value }), undefined, "span"),
|
|
122
|
+
* })
|
|
123
|
+
* @stable
|
|
124
|
+
*/
|
|
125
|
+
declare function usePart<P extends Primitive, S extends SlotName<P>>(handle: P | PrimitiveHandle<P>, slot: S, slotProps?: () => PropsOf<P, S>, props?: () => Record<string, unknown>, element?: string | PartElement<StateOf<P, S>>): (() => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
126
|
+
[key: string]: any;
|
|
127
|
+
}> | VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
}>[] | null) & {
|
|
130
|
+
state: StateOf<P, S>;
|
|
131
|
+
};
|
|
132
|
+
export { copyProps, defaultSlot, optionalBoolean, orModel, pascal, type PartElement, type PartSlots, type PrimitiveHandle, provideHandle, provideProps, renderElement, type StateSlotFunctions, type StateSlots, useHandle, usePart, usePrimitive, useScope, };
|