akar 2.1.0 → 2.2.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.
- package/dist/Editable/EditableCancelTrigger.cjs +4 -3
- package/dist/Editable/EditableCancelTrigger.cjs.map +1 -1
- package/dist/Editable/EditableCancelTrigger.js +5 -4
- package/dist/Editable/EditableCancelTrigger.js.map +1 -1
- package/dist/Editable/EditableInput.cjs +6 -2
- package/dist/Editable/EditableInput.cjs.map +1 -1
- package/dist/Editable/EditableInput.js +6 -2
- package/dist/Editable/EditableInput.js.map +1 -1
- package/dist/Editable/EditableRoot.cjs +46 -5
- package/dist/Editable/EditableRoot.cjs.map +1 -1
- package/dist/Editable/EditableRoot.js +47 -6
- package/dist/Editable/EditableRoot.js.map +1 -1
- package/dist/Editable/EditableSubmitTrigger.cjs +4 -3
- package/dist/Editable/EditableSubmitTrigger.cjs.map +1 -1
- package/dist/Editable/EditableSubmitTrigger.js +5 -4
- package/dist/Editable/EditableSubmitTrigger.js.map +1 -1
- package/dist/constant.d.cts.map +1 -1
- package/dist/index2.d.cts +13 -13
- package/dist/index2.d.ts.map +1 -1
- package/dist/index3.d.cts +713 -699
- package/dist/index3.d.cts.map +1 -1
- package/dist/index3.d.ts +729 -715
- package/dist/index3.d.ts.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/shared/createContext.cjs +1 -1
- package/dist/shared/createContext.js +1 -1
- package/package.json +1 -1
- package/src/Editable/EditableCancelTrigger.vue +6 -3
- package/src/Editable/EditableInput.vue +11 -2
- package/src/Editable/EditableRoot.vue +65 -7
- package/src/Editable/EditableSubmitTrigger.vue +6 -3
package/dist/internal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./index2.js";
|
|
2
2
|
import { MenuArrowProps, MenuCheckboxItemEmits, MenuCheckboxItemProps, MenuContentEmits, MenuContentProps, MenuEmits, MenuGroupProps, MenuItemEmits, MenuItemIndicatorProps, MenuItemProps, MenuLabelProps, MenuPortalProps, MenuProps, MenuRadioGroupEmits, MenuRadioGroupProps, MenuRadioItemEmits, MenuRadioItemProps, MenuSeparatorProps, MenuSubContentEmits, MenuSubContentProps, MenuSubEmits, MenuSubProps, MenuSubTriggerProps, PopperAnchorProps, _default$313 as _default$13, _default$314 as _default$8, _default$315 as _default, _default$316 as _default$6, _default$317 as _default$10, _default$318 as _default$3, _default$319 as _default$14, _default$320 as _default$12, _default$321 as _default$2, _default$322 as _default$1, _default$323 as _default$11, _default$324 as _default$7, _default$326 as _default$9, _default$327 as _default$4, _default$328 as _default$5, injectMenuContext, injectMenuRootContext } from "./index3.js";
|
|
3
|
-
import * as
|
|
3
|
+
import * as vue56 from "vue";
|
|
4
4
|
|
|
5
5
|
//#region src/Menu/MenuAnchor.vue.d.ts
|
|
6
6
|
interface MenuAnchorProps extends PopperAnchorProps {}
|
|
@@ -10,7 +10,7 @@ declare const __VLS_template: () => {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
13
|
-
declare const __VLS_base:
|
|
13
|
+
declare const __VLS_base: vue56.DefineComponent<MenuAnchorProps, {}, {}, {}, {}, vue56.ComponentOptionsMixin, vue56.ComponentOptionsMixin, {}, string, vue56.PublicProps, Readonly<MenuAnchorProps> & Readonly<{}>, {}, {}, {}, {}, string, vue56.ComponentProvideOptions, false, {}, any>;
|
|
14
14
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
15
15
|
declare const _default$15: typeof __VLS_export;
|
|
16
16
|
type __VLS_WithSlots<T, S> = T & {
|
|
@@ -6,7 +6,7 @@ const vue = require_rolldown_runtime.__toESM(require("vue"));
|
|
|
6
6
|
* The exact akar version, replaced at build time (see `tsdown.config.ts`).
|
|
7
7
|
* Falls back to `'dev'` when the source is compiled without the define.
|
|
8
8
|
*/
|
|
9
|
-
const VERSION = "2.
|
|
9
|
+
const VERSION = "2.2.0";
|
|
10
10
|
function getSymbolDescription(providerComponentName, contextName) {
|
|
11
11
|
return contextName ?? (typeof providerComponentName === "string" ? `${providerComponentName}Context` : providerComponentName.join("/"));
|
|
12
12
|
}
|
|
@@ -5,7 +5,7 @@ import { inject, provide } from "vue";
|
|
|
5
5
|
* The exact akar version, replaced at build time (see `tsdown.config.ts`).
|
|
6
6
|
* Falls back to `'dev'` when the source is compiled without the define.
|
|
7
7
|
*/
|
|
8
|
-
const VERSION = "2.
|
|
8
|
+
const VERSION = "2.2.0";
|
|
9
9
|
function getSymbolDescription(providerComponentName, contextName) {
|
|
10
10
|
return contextName ?? (typeof providerComponentName === "string" ? `${providerComponentName}Context` : providerComponentName.join("/"));
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ export interface EditableCancelTriggerProps extends PrimitiveProps {}
|
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
+
import { computed } from 'vue';
|
|
8
9
|
import { Primitive } from '@/Primitive';
|
|
9
10
|
import { disabledAttr } from '@/shared';
|
|
10
11
|
import { injectEditableRootContext } from './EditableRoot.vue';
|
|
@@ -12,15 +13,17 @@ import { injectEditableRootContext } from './EditableRoot.vue';
|
|
|
12
13
|
const props = withDefaults(defineProps<EditableCancelTriggerProps>(), { as: 'button' });
|
|
13
14
|
|
|
14
15
|
const context = injectEditableRootContext();
|
|
16
|
+
|
|
17
|
+
const disabled = computed(() => context.disabled.value || context.isSubmitting.value);
|
|
15
18
|
</script>
|
|
16
19
|
|
|
17
20
|
<template>
|
|
18
21
|
<Primitive
|
|
19
22
|
v-bind="props"
|
|
20
23
|
aria-label="cancel"
|
|
21
|
-
:aria-disabled="
|
|
22
|
-
:data-disabled="
|
|
23
|
-
:disabled="disabledAttr(
|
|
24
|
+
:aria-disabled="disabled ? '' : undefined"
|
|
25
|
+
:data-disabled="disabled ? '' : undefined"
|
|
26
|
+
:disabled="disabledAttr(disabled, props.as, props.asChild)"
|
|
24
27
|
:type="as === 'button' ? 'button' : undefined"
|
|
25
28
|
:hidden="context.isEditing.value ? undefined : ''"
|
|
26
29
|
@click="context.cancel"
|
|
@@ -18,7 +18,7 @@ const props = withDefaults(defineProps<EditableInputProps>(), {
|
|
|
18
18
|
|
|
19
19
|
const context = injectEditableRootContext();
|
|
20
20
|
|
|
21
|
-
const disabled = computed(() => context.disabled.value);
|
|
21
|
+
const disabled = computed(() => context.disabled.value || context.isSubmitting.value);
|
|
22
22
|
|
|
23
23
|
const placeholder = computed(() => context.placeholder.value?.edit);
|
|
24
24
|
|
|
@@ -46,7 +46,16 @@ watch(context.isEditing, (value) => {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
function handleSubmitKeyDown(event: KeyboardEvent) {
|
|
49
|
-
|
|
49
|
+
const submitsOnEnter = context.submitMode.value === 'enter' || context.submitMode.value === 'both';
|
|
50
|
+
if (!submitsOnEnter || event.key !== KEY_CODES.ENTER || event.isComposing) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (context.multiline.value) {
|
|
55
|
+
if (event.ctrlKey || event.metaKey) {
|
|
56
|
+
context.submit();
|
|
57
|
+
}
|
|
58
|
+
} else if (!event.shiftKey && !event.metaKey) {
|
|
50
59
|
context.submit();
|
|
51
60
|
}
|
|
52
61
|
}
|
|
@@ -21,7 +21,9 @@ type EditableRootContext = {
|
|
|
21
21
|
selectOnFocus: Ref<boolean>;
|
|
22
22
|
edit: () => void;
|
|
23
23
|
cancel: () => void;
|
|
24
|
-
submit: () => void
|
|
24
|
+
submit: () => Promise<void>;
|
|
25
|
+
isSubmitting: Ref<boolean>;
|
|
26
|
+
multiline: Ref<boolean>;
|
|
25
27
|
inputRef: Ref<HTMLInputElement | undefined>;
|
|
26
28
|
startWithEditMode: Ref<boolean>;
|
|
27
29
|
isEmpty: Ref<boolean>;
|
|
@@ -56,6 +58,14 @@ export interface EditableRootProps extends PrimitiveProps, FormFieldProps {
|
|
|
56
58
|
autoResize?: boolean;
|
|
57
59
|
/** The id of the field */
|
|
58
60
|
id?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Runs before a submit is accepted. It may return a promise. While it is pending the editor
|
|
63
|
+
* stays open and is busy. If it resolves `false` or rejects, the editor stays open and the typed
|
|
64
|
+
* value is kept. Rejections are caught: report your own errors from inside this function.
|
|
65
|
+
*/
|
|
66
|
+
beforeSubmit?: (value: string | null | undefined) => boolean | void | Promise<boolean | void>;
|
|
67
|
+
/** Whether the field is multi-line. Enter adds a line break. Ctrl+Enter or Cmd+Enter submits. */
|
|
68
|
+
multiline?: boolean;
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
export type EditableRootEmits = {
|
|
@@ -75,7 +85,7 @@ export const [injectEditableRootContext, provideEditableRootContext]
|
|
|
75
85
|
import type { Ref } from 'vue';
|
|
76
86
|
import { isString } from '@vinicunca/perkakas';
|
|
77
87
|
import { useVModel } from '@vueuse/core';
|
|
78
|
-
import { computed, ref, toRefs, watch } from 'vue';
|
|
88
|
+
import { computed, nextTick, ref, toRefs, watch } from 'vue';
|
|
79
89
|
import { Primitive, usePrimitiveElement } from '@/Primitive';
|
|
80
90
|
import { VisuallyHiddenInput } from '@/VisuallyHidden';
|
|
81
91
|
|
|
@@ -92,6 +102,8 @@ const props = withDefaults(defineProps<EditableRootProps>(), {
|
|
|
92
102
|
placeholder: 'Enter text...',
|
|
93
103
|
autoResize: false,
|
|
94
104
|
required: false,
|
|
105
|
+
multiline: false,
|
|
106
|
+
beforeSubmit: undefined,
|
|
95
107
|
});
|
|
96
108
|
|
|
97
109
|
const emits = defineEmits<EditableRootEmits>();
|
|
@@ -104,7 +116,11 @@ defineSlots<{
|
|
|
104
116
|
/** Whether the editable field is empty */
|
|
105
117
|
isEmpty: boolean;
|
|
106
118
|
/** Function to submit the value of the editable */
|
|
107
|
-
submit: () => void
|
|
119
|
+
submit: () => Promise<void>;
|
|
120
|
+
/** Whether a submit is pending (`beforeSubmit` has not settled yet) */
|
|
121
|
+
isSubmitting: boolean;
|
|
122
|
+
/** The current value of the input, before it is submitted */
|
|
123
|
+
inputValue: typeof inputValue.value;
|
|
108
124
|
/** Function to cancel the value of the editable */
|
|
109
125
|
cancel: () => void;
|
|
110
126
|
/** Function to set the editable in edit mode */
|
|
@@ -127,11 +143,13 @@ const {
|
|
|
127
143
|
readonly,
|
|
128
144
|
autoResize,
|
|
129
145
|
required,
|
|
146
|
+
multiline,
|
|
130
147
|
} = toRefs(props);
|
|
131
148
|
|
|
132
149
|
const inputRef = ref<HTMLInputElement | undefined>();
|
|
133
150
|
const dir = useDirection(propDir);
|
|
134
151
|
const isEditing = ref(startWithEditMode.value ?? false);
|
|
152
|
+
const isSubmitting = ref(false);
|
|
135
153
|
|
|
136
154
|
const modelValue = useVModel(props, 'modelValue', emits, {
|
|
137
155
|
defaultValue: defaultValue.value ?? '',
|
|
@@ -155,6 +173,9 @@ watch(() => modelValue.value, () => {
|
|
|
155
173
|
}, { immediate: true, deep: true });
|
|
156
174
|
|
|
157
175
|
function cancel() {
|
|
176
|
+
if (isSubmitting.value) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
158
179
|
isEditing.value = false;
|
|
159
180
|
emits('update:state', 'cancel');
|
|
160
181
|
}
|
|
@@ -166,16 +187,48 @@ function edit() {
|
|
|
166
187
|
emits('update:state', 'edit');
|
|
167
188
|
}
|
|
168
189
|
|
|
169
|
-
function
|
|
170
|
-
modelValue.value =
|
|
190
|
+
function commit(value: string | null | undefined) {
|
|
191
|
+
modelValue.value = value;
|
|
171
192
|
isEditing.value = false;
|
|
172
193
|
|
|
173
194
|
emits('update:state', 'submit');
|
|
174
|
-
emits('submit',
|
|
195
|
+
emits('submit', value);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function submit(): Promise<void> {
|
|
199
|
+
if (isSubmitting.value) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const guard = props.beforeSubmit;
|
|
204
|
+
if (!guard) {
|
|
205
|
+
commit(inputValue.value);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Commit the value the guard saw, even if modelValue changes while it is pending.
|
|
210
|
+
const value = inputValue.value;
|
|
211
|
+
isSubmitting.value = true;
|
|
212
|
+
let accepted = false;
|
|
213
|
+
try {
|
|
214
|
+
accepted = (await guard(value)) !== false;
|
|
215
|
+
} catch {
|
|
216
|
+
accepted = false;
|
|
217
|
+
} finally {
|
|
218
|
+
isSubmitting.value = false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (accepted) {
|
|
222
|
+
commit(value);
|
|
223
|
+
} else {
|
|
224
|
+
// The input was disabled while saving, which drops focus. Give it back.
|
|
225
|
+
await nextTick();
|
|
226
|
+
inputRef.value?.focus({ preventScroll: true });
|
|
227
|
+
}
|
|
175
228
|
}
|
|
176
229
|
|
|
177
230
|
function handleDismiss() {
|
|
178
|
-
if (isEditing.value) {
|
|
231
|
+
if (isEditing.value && !isSubmitting.value) {
|
|
179
232
|
if (submitMode.value === 'blur' || submitMode.value === 'both') {
|
|
180
233
|
submit();
|
|
181
234
|
} else {
|
|
@@ -210,6 +263,8 @@ provideEditableRootContext({
|
|
|
210
263
|
edit,
|
|
211
264
|
cancel,
|
|
212
265
|
submit,
|
|
266
|
+
isSubmitting,
|
|
267
|
+
multiline,
|
|
213
268
|
activationMode,
|
|
214
269
|
submitMode,
|
|
215
270
|
selectOnFocus,
|
|
@@ -230,6 +285,7 @@ provideEditableRootContext({
|
|
|
230
285
|
:dir="dir"
|
|
231
286
|
data-dismissable-layer
|
|
232
287
|
data-editable-root
|
|
288
|
+
:data-submitting="isSubmitting ? '' : undefined"
|
|
233
289
|
@focus.capture="focusOutside.onFocusCapture"
|
|
234
290
|
@blur.capture="focusOutside.onBlurCapture"
|
|
235
291
|
@pointerdown.capture="pointerDownOutside.onPointerDownCapture"
|
|
@@ -239,6 +295,8 @@ provideEditableRootContext({
|
|
|
239
295
|
:is-editing="isEditing"
|
|
240
296
|
:is-empty="isEmpty"
|
|
241
297
|
:submit="submit"
|
|
298
|
+
:is-submitting="isSubmitting"
|
|
299
|
+
:input-value="inputValue"
|
|
242
300
|
:cancel="cancel"
|
|
243
301
|
:edit="edit"
|
|
244
302
|
/>
|
|
@@ -5,6 +5,7 @@ export interface EditableSubmitTriggerProps extends PrimitiveProps {}
|
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
+
import { computed } from 'vue';
|
|
8
9
|
import { Primitive } from '@/Primitive';
|
|
9
10
|
import { disabledAttr } from '@/shared';
|
|
10
11
|
import { injectEditableRootContext } from './EditableRoot.vue';
|
|
@@ -12,15 +13,17 @@ import { injectEditableRootContext } from './EditableRoot.vue';
|
|
|
12
13
|
const props = withDefaults(defineProps<EditableSubmitTriggerProps>(), { as: 'button' });
|
|
13
14
|
|
|
14
15
|
const context = injectEditableRootContext();
|
|
16
|
+
|
|
17
|
+
const disabled = computed(() => context.disabled.value || context.isSubmitting.value);
|
|
15
18
|
</script>
|
|
16
19
|
|
|
17
20
|
<template>
|
|
18
21
|
<Primitive
|
|
19
22
|
v-bind="props"
|
|
20
23
|
aria-label="submit"
|
|
21
|
-
:aria-disabled="
|
|
22
|
-
:data-disabled="
|
|
23
|
-
:disabled="disabledAttr(
|
|
24
|
+
:aria-disabled="disabled ? '' : undefined"
|
|
25
|
+
:data-disabled="disabled ? '' : undefined"
|
|
26
|
+
:disabled="disabledAttr(disabled, props.as, props.asChild)"
|
|
24
27
|
:type="as === 'button' ? 'button' : undefined"
|
|
25
28
|
:hidden="context.isEditing.value ? undefined : ''"
|
|
26
29
|
@click="context.submit"
|