ropav 0.0.11 → 0.0.12
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/README.md +3 -0
- package/dist/checkbox.css +32 -32
- package/dist/checkbox.js +33 -14
- package/dist/color-input.css +19 -19
- package/dist/color-input.js +35 -17
- package/dist/components/checkbox/types.d.ts +5 -1
- package/dist/components/checkbox/useCheckbox.d.ts +1 -1
- package/dist/components/color-input/types.d.ts +4 -1
- package/dist/components/color-input/useColorInput.d.ts +1 -1
- package/dist/components/color-input/useColorInputValue.d.ts +1 -1
- package/dist/components/dialog/dialog-close.d.ts +21 -0
- package/dist/components/dialog/dialog-content.d.ts +32 -0
- package/dist/components/dialog/dialog-core.d.ts +27 -0
- package/dist/components/dialog/dialog-description.d.ts +21 -0
- package/dist/components/dialog/dialog-overlay.d.ts +21 -0
- package/dist/components/dialog/dialog-portal.d.ts +21 -0
- package/dist/components/dialog/dialog-root.d.ts +28 -0
- package/dist/components/dialog/dialog-title.d.ts +21 -0
- package/dist/components/dialog/dialog-trigger.d.ts +23 -0
- package/dist/components/dialog/index.d.ts +9 -0
- package/dist/components/dialog/index.js +2 -0
- package/dist/components/dialog/types.d.ts +61 -0
- package/dist/components/dropdown-menu/dropdown-menu-checkbox-item.d.ts +24 -0
- package/dist/components/dropdown-menu/dropdown-menu-content.d.ts +34 -0
- package/dist/components/dropdown-menu/dropdown-menu-context-trigger.d.ts +23 -0
- package/dist/components/dropdown-menu/dropdown-menu-item-indicator.d.ts +24 -0
- package/dist/components/dropdown-menu/dropdown-menu-item-row.d.ts +28 -0
- package/dist/components/dropdown-menu/dropdown-menu-item.d.ts +23 -0
- package/dist/components/dropdown-menu/dropdown-menu-items.d.ts +24 -22
- package/dist/components/dropdown-menu/dropdown-menu-label.d.ts +21 -0
- package/dist/components/dropdown-menu/dropdown-menu-outside.d.ts +3 -0
- package/dist/components/dropdown-menu/dropdown-menu-portal.d.ts +21 -0
- package/dist/components/dropdown-menu/dropdown-menu-primitive-core.d.ts +110 -0
- package/dist/components/dropdown-menu/dropdown-menu-primitives.d.ts +15 -724
- package/dist/components/dropdown-menu/dropdown-menu-radio-group.d.ts +25 -0
- package/dist/components/dropdown-menu/dropdown-menu-radio-item.d.ts +23 -0
- package/dist/components/dropdown-menu/dropdown-menu-root.d.ts +30 -0
- package/dist/components/dropdown-menu/dropdown-menu-separator.d.ts +19 -0
- package/dist/components/dropdown-menu/dropdown-menu-sub-content.d.ts +34 -0
- package/dist/components/dropdown-menu/dropdown-menu-sub-trigger.d.ts +28 -0
- package/dist/components/dropdown-menu/dropdown-menu-sub.d.ts +28 -0
- package/dist/components/dropdown-menu/dropdown-menu-trigger.d.ts +23 -0
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +5 -2
- package/dist/components/dropdown-menu/index.d.ts +28 -49
- package/dist/components/dropdown-menu/index.js +2 -2
- package/dist/components/dropdown-menu/types.d.ts +5 -2
- package/dist/components/dropdown-menu/useDropdownMenu.d.ts +8 -4
- package/dist/components/dropdown-menu/useDropdownMenuDisclosure.d.ts +7 -2
- package/dist/components/dropdown-menu/useDropdownMenuPortalPosition.d.ts +3 -3
- package/dist/components/dropdown-menu/useDropdownMenuPrimitiveContent.d.ts +27 -0
- package/dist/components/floating/index.d.ts +3 -1
- package/dist/components/floating/index.js +3 -0
- package/dist/components/floating/types.d.ts +75 -1
- package/dist/components/floating/useFloatingPosition.d.ts +3 -26
- package/dist/components/floating/useHoverDisclosure.d.ts +2 -0
- package/dist/components/input/input.d.ts +4 -1
- package/dist/components/input/types.d.ts +3 -1
- package/dist/components/modal/index.d.ts +1 -1
- package/dist/components/modal/modal.d.ts +3 -1
- package/dist/components/modal/types.d.ts +3 -0
- package/dist/components/modal/useModal.d.ts +7 -4
- package/dist/components/number-input/types.d.ts +3 -1
- package/dist/components/number-input/useNumberInput.d.ts +2 -1
- package/dist/components/popover/usePopover.d.ts +2 -2
- package/dist/components/radio/types.d.ts +17 -1
- package/dist/components/radio/useRadio.d.ts +3 -0
- package/dist/components/select/select.d.ts +4 -1
- package/dist/components/select/types.d.ts +6 -1
- package/dist/components/select/useSelect.d.ts +3 -2
- package/dist/components/slider/index.d.ts +1 -1
- package/dist/components/slider/range-slider.d.ts +3 -3
- package/dist/components/slider/types.d.ts +11 -3
- package/dist/components/slider/useRangeSlider.d.ts +1 -1
- package/dist/components/slider/useSlider.d.ts +1 -1
- package/dist/components/switch/types.d.ts +5 -1
- package/dist/components/switch/useSwitch.d.ts +1 -1
- package/dist/components/teleport-provider/index.d.ts +1 -0
- package/dist/components/teleport-provider/index.js +2 -1
- package/dist/components/teleport-provider/useTeleportTarget.d.ts +4 -3
- package/dist/components/textarea/types.d.ts +4 -1
- package/dist/components/textarea/useTextarea.d.ts +1 -1
- package/dist/components/toast/index.d.ts +2 -1
- package/dist/components/toast/index.js +2 -2
- package/dist/components/toast/toast-store.d.ts +2 -0
- package/dist/components/toast/types.d.ts +10 -4
- package/dist/components/toast/useToast.d.ts +2 -2
- package/dist/components/tooltip/useTooltip.d.ts +3 -3
- package/dist/composables/useOverlayLayer.d.ts +32 -0
- package/dist/dialog.js +510 -0
- package/dist/dropdown-menu.css +4 -5
- package/dist/dropdown-menu.js +1141 -886
- package/dist/floating.js +403 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -4
- package/dist/input.css +24 -24
- package/dist/input.js +21 -11
- package/dist/legacy-unlayered.css +424 -503
- package/dist/modal.css +28 -28
- package/dist/modal.js +141 -200
- package/dist/number-input.css +20 -20
- package/dist/number-input.js +44 -16
- package/dist/popover.css +4 -4
- package/dist/popover.js +25 -40
- package/dist/radio.css +18 -18
- package/dist/radio.js +96 -18
- package/dist/select.css +54 -43
- package/dist/select.js +185 -67
- package/dist/slider.css +183 -202
- package/dist/slider.js +138 -37
- package/dist/switch.css +17 -17
- package/dist/switch.js +31 -13
- package/dist/textarea.css +26 -26
- package/dist/textarea.js +19 -9
- package/dist/toast.js +110 -99
- package/dist/tooltip.css +5 -80
- package/dist/tooltip.js +7 -3
- package/dist/useControlState.js +4 -0
- package/dist/useFloatingPosition.js +71 -38
- package/dist/useFormControl.js +107 -0
- package/dist/useOverlayLayer.js +262 -0
- package/dist/useTeleportTarget.js +21 -10
- package/docs/public-floating-api.md +148 -0
- package/docs/public-styles-api.md +2 -1
- package/package.json +10 -6
- package/dist/useClickOutside.js +0 -24
package/dist/tooltip.js
CHANGED
|
@@ -4,7 +4,7 @@ import { n as useStylesApi, t as presence } from "./styles-api.js";
|
|
|
4
4
|
import { i as getComponentVariantColorRoles } from "./componentColors.js";
|
|
5
5
|
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper.js";
|
|
6
6
|
import { n as useFloatingPosition, r as useFloatingTarget, t as isElementReference } from "./useFloatingPosition.js";
|
|
7
|
-
import { n as useTeleportTarget } from "./useTeleportTarget.js";
|
|
7
|
+
import { n as useTeleportPositioningKey, r as useTeleportTarget } from "./useTeleportTarget.js";
|
|
8
8
|
import { VaporTeleport, VaporTransition, applyVShow, computed, createComponent, createIf, createSlot, createTemplateRefSetter, defineVaporComponent, extend, onBeforeUnmount, ref, renderEffect, setAttr, setDynamicProps, setInsertionState, setStaticTemplateRef, setStyle, setText, template, toDisplayString, unref, useId, useSlots, watch } from "vue";
|
|
9
9
|
//#region src/composables/useDelayedOpen.ts
|
|
10
10
|
function readOption(value, fallback) {
|
|
@@ -92,6 +92,7 @@ function useTooltip(props, emitOpenChange) {
|
|
|
92
92
|
const shouldRenderContent = computed(() => !isDisabled.value);
|
|
93
93
|
const shouldDescribeContent = computed(() => shouldRenderContent.value && !isDecorative.value);
|
|
94
94
|
const teleportTo = useTeleportTarget(() => props.teleportTo);
|
|
95
|
+
const teleportPositioningKey = useTeleportPositioningKey();
|
|
95
96
|
const { isExplicitTarget, reference, resolvedTarget } = useFloatingTarget(() => props.target, rootRef);
|
|
96
97
|
const targetElement = computed(() => isElementReference(resolvedTarget.value) ? resolvedTarget.value : null);
|
|
97
98
|
const { isOpen, open, closeImmediate } = useDelayedOpen({
|
|
@@ -112,8 +113,11 @@ function useTooltip(props, emitOpenChange) {
|
|
|
112
113
|
flip: () => props.flip !== false,
|
|
113
114
|
shift: () => props.shift !== false,
|
|
114
115
|
collisionPadding: () => props.collisionPadding ?? 8,
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
restartKey: () => [
|
|
117
|
+
Boolean(props.teleport),
|
|
118
|
+
teleportTo.value,
|
|
119
|
+
teleportPositioningKey.value
|
|
120
|
+
]
|
|
117
121
|
});
|
|
118
122
|
const placementSide = computed(() => floating.actualPlacement.value.split("-")[0]);
|
|
119
123
|
const rootClass = computed(() => bem("rp-tooltip", {
|
package/dist/useControlState.js
CHANGED
|
@@ -6,6 +6,7 @@ function mergeIds(...values) {
|
|
|
6
6
|
}
|
|
7
7
|
function useControlState(options = {}) {
|
|
8
8
|
const id = computed(() => options.id);
|
|
9
|
+
const form = computed(() => options.form);
|
|
9
10
|
const disabled = computed(() => options.disabled ?? false);
|
|
10
11
|
const required = computed(() => options.required ?? false);
|
|
11
12
|
const invalid = computed(() => options.invalid ?? false);
|
|
@@ -16,6 +17,9 @@ function useControlState(options = {}) {
|
|
|
16
17
|
get id() {
|
|
17
18
|
return id.value;
|
|
18
19
|
},
|
|
20
|
+
get form() {
|
|
21
|
+
return form.value;
|
|
22
|
+
},
|
|
19
23
|
get disabled() {
|
|
20
24
|
return disabled.value;
|
|
21
25
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, isRef, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, watch } from "vue";
|
|
1
|
+
import { computed, isRef, nextTick, onBeforeUnmount, onMounted, readonly, ref, shallowRef, toValue, watch } from "vue";
|
|
2
2
|
//#region node_modules/.pnpm/@floating-ui+utils@0.2.12/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
|
|
3
3
|
var min = Math.min;
|
|
4
4
|
var max = Math.max;
|
|
@@ -1138,6 +1138,10 @@ var computePosition = (reference, floating, options) => {
|
|
|
1138
1138
|
//#endregion
|
|
1139
1139
|
//#region src/components/floating/useFloatingPosition.ts
|
|
1140
1140
|
var DEFAULT_ARROW_PADDING = 4;
|
|
1141
|
+
var DEFAULT_COLLISION_PADDING = 8;
|
|
1142
|
+
var DEFAULT_OFFSET = 8;
|
|
1143
|
+
var DEFAULT_PLACEMENT = "bottom";
|
|
1144
|
+
var DEFAULT_STRATEGY = "absolute";
|
|
1141
1145
|
function readFloatingTarget(target) {
|
|
1142
1146
|
return isRef(target) ? target.value : target;
|
|
1143
1147
|
}
|
|
@@ -1178,23 +1182,53 @@ function useFloatingTarget(getTarget, fallback) {
|
|
|
1178
1182
|
};
|
|
1179
1183
|
}
|
|
1180
1184
|
function useFloatingPosition(options) {
|
|
1181
|
-
const actualPlacement = ref(
|
|
1185
|
+
const actualPlacement = ref(getPlacement());
|
|
1182
1186
|
const isPositioned = ref(false);
|
|
1183
1187
|
const floatingStyle = ref(getHiddenStyle());
|
|
1184
1188
|
const arrowStyle = ref();
|
|
1185
1189
|
let cleanup;
|
|
1186
1190
|
let generation = 0;
|
|
1187
1191
|
let request = 0;
|
|
1192
|
+
function getReference() {
|
|
1193
|
+
return toValue(options.reference);
|
|
1194
|
+
}
|
|
1195
|
+
function getFloating() {
|
|
1196
|
+
return toValue(options.floating);
|
|
1197
|
+
}
|
|
1198
|
+
function getArrow() {
|
|
1199
|
+
return toValue(options.arrow);
|
|
1200
|
+
}
|
|
1201
|
+
function getOpen() {
|
|
1202
|
+
return toValue(options.open) !== false;
|
|
1203
|
+
}
|
|
1204
|
+
function getPlacement() {
|
|
1205
|
+
return toValue(options.placement) ?? DEFAULT_PLACEMENT;
|
|
1206
|
+
}
|
|
1207
|
+
function getStrategy() {
|
|
1208
|
+
return toValue(options.strategy) ?? DEFAULT_STRATEGY;
|
|
1209
|
+
}
|
|
1210
|
+
function getOffset() {
|
|
1211
|
+
return toValue(options.offset) ?? DEFAULT_OFFSET;
|
|
1212
|
+
}
|
|
1213
|
+
function getFlip() {
|
|
1214
|
+
return toValue(options.flip) !== false;
|
|
1215
|
+
}
|
|
1216
|
+
function getShift() {
|
|
1217
|
+
return toValue(options.shift) !== false;
|
|
1218
|
+
}
|
|
1219
|
+
function getCollisionPadding() {
|
|
1220
|
+
return toValue(options.collisionPadding) ?? DEFAULT_COLLISION_PADDING;
|
|
1221
|
+
}
|
|
1188
1222
|
function getHiddenStyle() {
|
|
1189
1223
|
return {
|
|
1190
|
-
position:
|
|
1224
|
+
position: getStrategy(),
|
|
1191
1225
|
top: "0",
|
|
1192
1226
|
left: "0",
|
|
1193
1227
|
visibility: "hidden"
|
|
1194
1228
|
};
|
|
1195
1229
|
}
|
|
1196
1230
|
function resetPosition() {
|
|
1197
|
-
actualPlacement.value =
|
|
1231
|
+
actualPlacement.value = getPlacement();
|
|
1198
1232
|
isPositioned.value = false;
|
|
1199
1233
|
floatingStyle.value = getHiddenStyle();
|
|
1200
1234
|
arrowStyle.value = void 0;
|
|
@@ -1206,28 +1240,29 @@ function useFloatingPosition(options) {
|
|
|
1206
1240
|
request += 1;
|
|
1207
1241
|
}
|
|
1208
1242
|
function getMiddleware() {
|
|
1209
|
-
const middleware = [offset(
|
|
1210
|
-
const padding =
|
|
1211
|
-
if (
|
|
1212
|
-
if (
|
|
1213
|
-
|
|
1214
|
-
|
|
1243
|
+
const middleware = [offset(getOffset())];
|
|
1244
|
+
const padding = getCollisionPadding();
|
|
1245
|
+
if (getFlip()) middleware.push(flip({ padding }));
|
|
1246
|
+
if (getShift()) middleware.push(shift({ padding }));
|
|
1247
|
+
const arrow$2 = getArrow();
|
|
1248
|
+
if (arrow$2) middleware.push(arrow({
|
|
1249
|
+
element: arrow$2,
|
|
1215
1250
|
padding: DEFAULT_ARROW_PADDING
|
|
1216
1251
|
}));
|
|
1217
1252
|
return middleware;
|
|
1218
1253
|
}
|
|
1219
1254
|
async function update() {
|
|
1220
|
-
const reference =
|
|
1221
|
-
const floating =
|
|
1222
|
-
if (!reference || !floating || !
|
|
1255
|
+
const reference = getReference();
|
|
1256
|
+
const floating = getFloating();
|
|
1257
|
+
if (!reference || !floating || !getOpen()) return;
|
|
1223
1258
|
const currentGeneration = generation;
|
|
1224
1259
|
const currentRequest = ++request;
|
|
1225
1260
|
const result = await computePosition(reference, floating, {
|
|
1226
|
-
placement:
|
|
1227
|
-
strategy:
|
|
1261
|
+
placement: getPlacement(),
|
|
1262
|
+
strategy: getStrategy(),
|
|
1228
1263
|
middleware: getMiddleware()
|
|
1229
1264
|
});
|
|
1230
|
-
if (currentGeneration !== generation || currentRequest !== request || !
|
|
1265
|
+
if (currentGeneration !== generation || currentRequest !== request || !getOpen()) return;
|
|
1231
1266
|
actualPlacement.value = result.placement;
|
|
1232
1267
|
floatingStyle.value = {
|
|
1233
1268
|
position: result.strategy,
|
|
@@ -1243,40 +1278,38 @@ function useFloatingPosition(options) {
|
|
|
1243
1278
|
}
|
|
1244
1279
|
function start() {
|
|
1245
1280
|
stop();
|
|
1281
|
+
if (!getOpen()) return;
|
|
1246
1282
|
resetPosition();
|
|
1247
|
-
|
|
1283
|
+
const currentGeneration = generation;
|
|
1248
1284
|
nextTick(() => {
|
|
1249
|
-
const reference =
|
|
1250
|
-
const floating =
|
|
1251
|
-
if (!reference || !floating || !
|
|
1285
|
+
const reference = getReference();
|
|
1286
|
+
const floating = getFloating();
|
|
1287
|
+
if (currentGeneration !== generation || !reference || !floating || !getOpen()) return;
|
|
1252
1288
|
cleanup = autoUpdate(reference, floating, () => void update());
|
|
1253
1289
|
});
|
|
1254
1290
|
}
|
|
1255
1291
|
watch([
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
options.
|
|
1267
|
-
() => options.restartKey?.()
|
|
1292
|
+
getOpen,
|
|
1293
|
+
getReference,
|
|
1294
|
+
getFloating,
|
|
1295
|
+
getArrow,
|
|
1296
|
+
getPlacement,
|
|
1297
|
+
getStrategy,
|
|
1298
|
+
getOffset,
|
|
1299
|
+
getFlip,
|
|
1300
|
+
getShift,
|
|
1301
|
+
getCollisionPadding,
|
|
1302
|
+
() => toValue(options.restartKey)
|
|
1268
1303
|
], start, {
|
|
1269
1304
|
flush: "post",
|
|
1270
1305
|
immediate: true
|
|
1271
1306
|
});
|
|
1272
1307
|
onBeforeUnmount(stop);
|
|
1273
1308
|
return {
|
|
1274
|
-
actualPlacement,
|
|
1275
|
-
arrowStyle,
|
|
1276
|
-
floatingStyle,
|
|
1277
|
-
isPositioned,
|
|
1278
|
-
start,
|
|
1279
|
-
stop,
|
|
1309
|
+
actualPlacement: readonly(actualPlacement),
|
|
1310
|
+
arrowStyle: readonly(arrowStyle),
|
|
1311
|
+
floatingStyle: readonly(floatingStyle),
|
|
1312
|
+
isPositioned: readonly(isPositioned),
|
|
1280
1313
|
update
|
|
1281
1314
|
};
|
|
1282
1315
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { computed, inject, provide, shallowRef, watch, watchEffect } from "vue";
|
|
2
|
+
//#region src/composables/useControllableValue.ts
|
|
3
|
+
function useControllableValue(options) {
|
|
4
|
+
const initialValue = options.defaultValue();
|
|
5
|
+
const uncontrolledValue = shallowRef(initialValue);
|
|
6
|
+
const isControlled = computed(() => options.modelValue() !== void 0);
|
|
7
|
+
watch(options.modelValue, (value) => {
|
|
8
|
+
if (value !== void 0) uncontrolledValue.value = value;
|
|
9
|
+
}, { immediate: true });
|
|
10
|
+
const value = computed(() => options.modelValue() ?? uncontrolledValue.value);
|
|
11
|
+
function setValue(nextValue) {
|
|
12
|
+
if (!isControlled.value) uncontrolledValue.value = nextValue;
|
|
13
|
+
options.onChange(nextValue);
|
|
14
|
+
}
|
|
15
|
+
function resetValue(nextValue = initialValue) {
|
|
16
|
+
if (!isControlled.value) uncontrolledValue.value = nextValue;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
initialValue,
|
|
20
|
+
isControlled,
|
|
21
|
+
value,
|
|
22
|
+
setValue,
|
|
23
|
+
resetValue
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/composables/useFormControl.ts
|
|
28
|
+
var nestedFormControlOwnerKey = Symbol("nestedFormControlOwner");
|
|
29
|
+
function provideNestedFormControlOwner() {
|
|
30
|
+
let claimed = false;
|
|
31
|
+
provide(nestedFormControlOwnerKey, () => {
|
|
32
|
+
if (claimed) return false;
|
|
33
|
+
claimed = true;
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function claimNestedFormControlOwner() {
|
|
38
|
+
return inject(nestedFormControlOwnerKey, void 0)?.() ?? false;
|
|
39
|
+
}
|
|
40
|
+
function getElements(options) {
|
|
41
|
+
return options.elements().filter((element) => Boolean(element));
|
|
42
|
+
}
|
|
43
|
+
function useFormControl(options) {
|
|
44
|
+
const initialized = /* @__PURE__ */ new WeakSet();
|
|
45
|
+
watchEffect(() => {
|
|
46
|
+
const elements = getElements(options);
|
|
47
|
+
for (const [index, element] of elements.entries()) {
|
|
48
|
+
if (!initialized.has(element)) {
|
|
49
|
+
options.initializeDefault?.(element, index);
|
|
50
|
+
initialized.add(element);
|
|
51
|
+
}
|
|
52
|
+
element.setCustomValidity(options.validationMessage?.(element, index, elements) ?? "");
|
|
53
|
+
}
|
|
54
|
+
}, { flush: "post" });
|
|
55
|
+
watchEffect((onCleanup) => {
|
|
56
|
+
const documents = new Set(getElements(options).map((element) => element.ownerDocument));
|
|
57
|
+
if (documents.size === 0) return;
|
|
58
|
+
function onReset(event) {
|
|
59
|
+
const form = event.target;
|
|
60
|
+
if (!(form instanceof HTMLFormElement)) return;
|
|
61
|
+
const elements = getElements(options).filter((element) => element.form === form);
|
|
62
|
+
if (elements.length === 0) return;
|
|
63
|
+
queueMicrotask(() => {
|
|
64
|
+
if (options.isControlled()) options.syncControlledValue(elements);
|
|
65
|
+
else options.readResetValue(elements);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
for (const document of documents) document.addEventListener("reset", onReset, true);
|
|
69
|
+
onCleanup(() => {
|
|
70
|
+
for (const document of documents) document.removeEventListener("reset", onReset, true);
|
|
71
|
+
});
|
|
72
|
+
}, { flush: "post" });
|
|
73
|
+
}
|
|
74
|
+
function useTextFormControl(element, controllable, validationMessage) {
|
|
75
|
+
useFormControl({
|
|
76
|
+
elements: () => [element()],
|
|
77
|
+
isControlled: () => controllable.isControlled.value,
|
|
78
|
+
initializeDefault(control) {
|
|
79
|
+
control.defaultValue = controllable.initialValue;
|
|
80
|
+
},
|
|
81
|
+
validationMessage,
|
|
82
|
+
readResetValue([control]) {
|
|
83
|
+
controllable.resetValue(control.value);
|
|
84
|
+
},
|
|
85
|
+
syncControlledValue([control]) {
|
|
86
|
+
control.value = controllable.value.value;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function useCheckedFormControl(element, controllable, validationMessage) {
|
|
91
|
+
useFormControl({
|
|
92
|
+
elements: () => [element()],
|
|
93
|
+
isControlled: () => controllable.isControlled.value,
|
|
94
|
+
initializeDefault(control) {
|
|
95
|
+
control.defaultChecked = controllable.initialValue;
|
|
96
|
+
},
|
|
97
|
+
validationMessage,
|
|
98
|
+
readResetValue([control]) {
|
|
99
|
+
controllable.resetValue(control.checked);
|
|
100
|
+
},
|
|
101
|
+
syncControlledValue([control]) {
|
|
102
|
+
control.checked = controllable.value.value;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { useTextFormControl as a, useFormControl as i, provideNestedFormControlOwner as n, useControllableValue as o, useCheckedFormControl as r, claimNestedFormControlOwner as t };
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { computed, inject, onBeforeUnmount, provide, readonly, ref, shallowRef, toValue, watch } from "vue";
|
|
2
|
+
//#region src/composables/useOverlayLayer.ts
|
|
3
|
+
var overlayLayerKey = Symbol("overlay-layer");
|
|
4
|
+
var documentStates = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
var layerMetadata = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
function createState() {
|
|
7
|
+
return {
|
|
8
|
+
layers: [],
|
|
9
|
+
inertSnapshots: /* @__PURE__ */ new Map(),
|
|
10
|
+
originalBodyOverflow: "",
|
|
11
|
+
scrollLocked: false,
|
|
12
|
+
observer: null,
|
|
13
|
+
syncQueued: false
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function getState(document) {
|
|
17
|
+
const existing = documentStates.get(document);
|
|
18
|
+
if (existing) return existing;
|
|
19
|
+
const state = createState();
|
|
20
|
+
documentStates.set(document, state);
|
|
21
|
+
return state;
|
|
22
|
+
}
|
|
23
|
+
function isDescendantLayer(layer, ancestor) {
|
|
24
|
+
let parent = layerMetadata.get(layer)?.parent ?? null;
|
|
25
|
+
while (parent) {
|
|
26
|
+
if (parent === ancestor) return true;
|
|
27
|
+
parent = layerMetadata.get(parent)?.parent ?? null;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
function syncLayerZIndices(state) {
|
|
32
|
+
let highestZIndex = Number.NEGATIVE_INFINITY;
|
|
33
|
+
for (const layer of state.layers) {
|
|
34
|
+
const metadata = layerMetadata.get(layer);
|
|
35
|
+
if (!metadata) continue;
|
|
36
|
+
const zIndex = Math.max(metadata.baseZIndex, highestZIndex + 2);
|
|
37
|
+
metadata.setZIndex(zIndex);
|
|
38
|
+
highestZIndex = zIndex;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isEventWithinElement(event, element) {
|
|
42
|
+
const path = event.composedPath();
|
|
43
|
+
if (path.length > 0) return path.some((entry) => entry === element || typeof Node !== "undefined" && entry instanceof Node && element.contains(entry));
|
|
44
|
+
return typeof Node !== "undefined" && event.target instanceof Node && element.contains(event.target);
|
|
45
|
+
}
|
|
46
|
+
function restoreInertBackground(state) {
|
|
47
|
+
for (const [element, snapshot] of state.inertSnapshots) {
|
|
48
|
+
element.inert = snapshot.inert;
|
|
49
|
+
if (snapshot.ariaHidden == null) element.removeAttribute("aria-hidden");
|
|
50
|
+
else element.setAttribute("aria-hidden", snapshot.ariaHidden);
|
|
51
|
+
}
|
|
52
|
+
state.inertSnapshots.clear();
|
|
53
|
+
}
|
|
54
|
+
function inertElement(state, element) {
|
|
55
|
+
if (!state.inertSnapshots.has(element)) state.inertSnapshots.set(element, {
|
|
56
|
+
ariaHidden: element.getAttribute("aria-hidden"),
|
|
57
|
+
inert: Boolean(element.inert)
|
|
58
|
+
});
|
|
59
|
+
element.inert = true;
|
|
60
|
+
element.setAttribute("aria-hidden", "true");
|
|
61
|
+
}
|
|
62
|
+
function inertUnprotectedBranches(state, parent, protectedRoots) {
|
|
63
|
+
for (const child of parent.children) {
|
|
64
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
65
|
+
if (!protectedRoots.some((root) => child === root || child.contains(root))) {
|
|
66
|
+
inertElement(state, child);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!protectedRoots.includes(child)) inertUnprotectedBranches(state, child, protectedRoots);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function stopObserver(state) {
|
|
73
|
+
state.observer?.disconnect();
|
|
74
|
+
state.observer = null;
|
|
75
|
+
state.syncQueued = false;
|
|
76
|
+
}
|
|
77
|
+
function unlockScroll(document, state) {
|
|
78
|
+
if (!state.scrollLocked) return;
|
|
79
|
+
document.body.style.overflow = state.originalBodyOverflow;
|
|
80
|
+
state.scrollLocked = false;
|
|
81
|
+
}
|
|
82
|
+
function queueModalEffects(document, state) {
|
|
83
|
+
if (state.syncQueued) return;
|
|
84
|
+
state.syncQueued = true;
|
|
85
|
+
queueMicrotask(() => {
|
|
86
|
+
state.syncQueued = false;
|
|
87
|
+
syncModalEffects(document, state);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function startObserver(document, state) {
|
|
91
|
+
if (state.observer || typeof MutationObserver === "undefined") return;
|
|
92
|
+
state.observer = new MutationObserver(() => queueModalEffects(document, state));
|
|
93
|
+
state.observer.observe(document.body, {
|
|
94
|
+
childList: true,
|
|
95
|
+
subtree: true
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function syncModalEffects(document, state) {
|
|
99
|
+
restoreInertBackground(state);
|
|
100
|
+
let modalIndex = -1;
|
|
101
|
+
for (let index = state.layers.length - 1; index >= 0; index -= 1) {
|
|
102
|
+
const layer = state.layers[index];
|
|
103
|
+
if (layer?.modalEffects && layer.modal.value) {
|
|
104
|
+
modalIndex = index;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const shouldLock = state.layers.some((layer) => layer.modalEffects && layer.modal.value && layer.preventScroll.value);
|
|
109
|
+
if (shouldLock && !state.scrollLocked) {
|
|
110
|
+
state.originalBodyOverflow = document.body.style.overflow;
|
|
111
|
+
document.body.style.overflow = "hidden";
|
|
112
|
+
state.scrollLocked = true;
|
|
113
|
+
} else if (!shouldLock) unlockScroll(document, state);
|
|
114
|
+
if (modalIndex < 0) {
|
|
115
|
+
stopObserver(state);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const protectedRoots = [];
|
|
119
|
+
for (const layer of state.layers.slice(modalIndex)) {
|
|
120
|
+
const element = layer.element.value;
|
|
121
|
+
if (element?.isConnected) protectedRoots.push(element);
|
|
122
|
+
for (const branch of layer.branches.value) if (branch.isConnected) protectedRoots.push(branch);
|
|
123
|
+
}
|
|
124
|
+
if (protectedRoots.length > 0) {
|
|
125
|
+
inertUnprotectedBranches(state, document.body, protectedRoots);
|
|
126
|
+
startObserver(document, state);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function removeLayer(layer, document, state) {
|
|
130
|
+
const index = state.layers.indexOf(layer);
|
|
131
|
+
if (index >= 0) state.layers.splice(index, 1);
|
|
132
|
+
syncLayerZIndices(state);
|
|
133
|
+
syncModalEffects(document, state);
|
|
134
|
+
}
|
|
135
|
+
function useOverlayLayer(options) {
|
|
136
|
+
const parent = inject(overlayLayerKey, null);
|
|
137
|
+
const active = computed(() => Boolean(toValue(options.active)));
|
|
138
|
+
const modal = computed(() => Boolean(toValue(options.modal ?? false)));
|
|
139
|
+
const preventScroll = computed(() => Boolean(toValue(options.preventScroll ?? true)));
|
|
140
|
+
const branches = shallowRef([]);
|
|
141
|
+
const focusBranches = shallowRef([]);
|
|
142
|
+
const branchSet = /* @__PURE__ */ new Set();
|
|
143
|
+
const focusBranchSet = /* @__PURE__ */ new Set();
|
|
144
|
+
const insideBranchSet = /* @__PURE__ */ new Set();
|
|
145
|
+
const zIndex = ref(options.baseZIndex ?? 100);
|
|
146
|
+
let registeredDocument = null;
|
|
147
|
+
let registeredElement = null;
|
|
148
|
+
let parentBranchCleanup;
|
|
149
|
+
function syncBranches() {
|
|
150
|
+
branches.value = [...branchSet];
|
|
151
|
+
focusBranches.value = [...focusBranchSet];
|
|
152
|
+
if (registeredDocument) syncModalEffects(registeredDocument, getState(registeredDocument));
|
|
153
|
+
}
|
|
154
|
+
function registerBranch(element, branchOptions = {}) {
|
|
155
|
+
branchSet.add(element);
|
|
156
|
+
if (branchOptions.focus !== false) focusBranchSet.add(element);
|
|
157
|
+
if (branchOptions.inside !== false) insideBranchSet.add(element);
|
|
158
|
+
const parentCleanup = parent?.registerBranch(element, branchOptions);
|
|
159
|
+
syncBranches();
|
|
160
|
+
return () => {
|
|
161
|
+
branchSet.delete(element);
|
|
162
|
+
focusBranchSet.delete(element);
|
|
163
|
+
insideBranchSet.delete(element);
|
|
164
|
+
parentCleanup?.();
|
|
165
|
+
syncBranches();
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function replaceParentBranch(element) {
|
|
169
|
+
parentBranchCleanup?.();
|
|
170
|
+
parentBranchCleanup = element ? parent?.registerBranch(element) : void 0;
|
|
171
|
+
}
|
|
172
|
+
const context = {
|
|
173
|
+
id: Symbol("overlay-layer"),
|
|
174
|
+
element: options.element,
|
|
175
|
+
active,
|
|
176
|
+
modal,
|
|
177
|
+
modalEffects: options.modalEffects === true,
|
|
178
|
+
preventScroll,
|
|
179
|
+
branches,
|
|
180
|
+
focusBranches,
|
|
181
|
+
zIndex: readonly(zIndex),
|
|
182
|
+
isTopLayer() {
|
|
183
|
+
if (!registeredDocument) return false;
|
|
184
|
+
const layers = getState(registeredDocument).layers;
|
|
185
|
+
return layers[layers.length - 1] === context;
|
|
186
|
+
},
|
|
187
|
+
isInside(event, additional = []) {
|
|
188
|
+
return [
|
|
189
|
+
options.element.value,
|
|
190
|
+
...insideBranchSet,
|
|
191
|
+
...additional
|
|
192
|
+
].some((element) => element != null && isEventWithinElement(event, element));
|
|
193
|
+
},
|
|
194
|
+
registerBranch
|
|
195
|
+
};
|
|
196
|
+
layerMetadata.set(context, {
|
|
197
|
+
baseZIndex: options.baseZIndex ?? 100,
|
|
198
|
+
parent,
|
|
199
|
+
setZIndex(value) {
|
|
200
|
+
zIndex.value = value;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
function unregister() {
|
|
204
|
+
replaceParentBranch(null);
|
|
205
|
+
if (!registeredDocument) return;
|
|
206
|
+
const document = registeredDocument;
|
|
207
|
+
registeredDocument = null;
|
|
208
|
+
registeredElement = null;
|
|
209
|
+
removeLayer(context, document, getState(document));
|
|
210
|
+
}
|
|
211
|
+
function register(element) {
|
|
212
|
+
const document = element.ownerDocument;
|
|
213
|
+
if (registeredDocument === document) {
|
|
214
|
+
if (registeredElement !== element) {
|
|
215
|
+
replaceParentBranch(element);
|
|
216
|
+
registeredElement = element;
|
|
217
|
+
syncModalEffects(document, getState(document));
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
unregister();
|
|
222
|
+
const state = getState(document);
|
|
223
|
+
const currentIndex = state.layers.indexOf(context);
|
|
224
|
+
if (currentIndex >= 0) state.layers.splice(currentIndex, 1);
|
|
225
|
+
const descendantIndex = state.layers.findIndex((layer) => isDescendantLayer(layer, context));
|
|
226
|
+
if (descendantIndex >= 0) state.layers.splice(descendantIndex, 0, context);
|
|
227
|
+
else state.layers.push(context);
|
|
228
|
+
registeredDocument = document;
|
|
229
|
+
registeredElement = element;
|
|
230
|
+
replaceParentBranch(element);
|
|
231
|
+
syncLayerZIndices(state);
|
|
232
|
+
syncModalEffects(document, state);
|
|
233
|
+
}
|
|
234
|
+
watch([active, options.element], ([isActive, element]) => {
|
|
235
|
+
if (isActive && element?.isConnected) register(element);
|
|
236
|
+
else unregister();
|
|
237
|
+
}, {
|
|
238
|
+
flush: "post",
|
|
239
|
+
immediate: true
|
|
240
|
+
});
|
|
241
|
+
watch([modal, preventScroll], () => {
|
|
242
|
+
if (registeredDocument) syncModalEffects(registeredDocument, getState(registeredDocument));
|
|
243
|
+
});
|
|
244
|
+
onBeforeUnmount(unregister);
|
|
245
|
+
provide(overlayLayerKey, context);
|
|
246
|
+
return context;
|
|
247
|
+
}
|
|
248
|
+
function useOverlayLayerBranch(element, options = {}) {
|
|
249
|
+
const layer = inject(overlayLayerKey, null);
|
|
250
|
+
let cleanup;
|
|
251
|
+
watch(element, (nextElement) => {
|
|
252
|
+
cleanup?.();
|
|
253
|
+
cleanup = nextElement ? layer?.registerBranch(nextElement, options) : void 0;
|
|
254
|
+
}, {
|
|
255
|
+
flush: "post",
|
|
256
|
+
immediate: true
|
|
257
|
+
});
|
|
258
|
+
onBeforeUnmount(() => cleanup?.());
|
|
259
|
+
return layer;
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
export { useOverlayLayerBranch as n, useOverlayLayer as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, inject, isRef, provide } from "vue";
|
|
1
|
+
import { computed, inject, isRef, provide, toValue } from "vue";
|
|
2
2
|
//#region src/components/teleport-provider/useTeleportTarget.ts
|
|
3
3
|
var teleportTargetKey = Symbol("teleport-target");
|
|
4
4
|
function readTeleportTarget(target) {
|
|
@@ -7,23 +7,34 @@ function readTeleportTarget(target) {
|
|
|
7
7
|
function hasTarget(target) {
|
|
8
8
|
return target != null && target !== "";
|
|
9
9
|
}
|
|
10
|
-
function provideTeleportTarget(props) {
|
|
11
|
-
const
|
|
10
|
+
function provideTeleportTarget(props, positioningKey) {
|
|
11
|
+
const parentContext = inject(teleportTargetKey, void 0);
|
|
12
12
|
const target = computed(() => {
|
|
13
13
|
const ownTarget = readTeleportTarget(props.teleportTo);
|
|
14
14
|
if (hasTarget(ownTarget)) return ownTarget;
|
|
15
|
-
return
|
|
15
|
+
return parentContext?.target.value ?? "body";
|
|
16
|
+
});
|
|
17
|
+
provide(teleportTargetKey, {
|
|
18
|
+
target,
|
|
19
|
+
positioningKey: computed(() => [
|
|
20
|
+
target.value,
|
|
21
|
+
toValue(positioningKey),
|
|
22
|
+
parentContext?.positioningKey.value
|
|
23
|
+
])
|
|
16
24
|
});
|
|
17
|
-
provide(teleportTargetKey, target);
|
|
18
25
|
return target;
|
|
19
26
|
}
|
|
20
|
-
function useTeleportTarget(
|
|
21
|
-
const
|
|
27
|
+
function useTeleportTarget(target) {
|
|
28
|
+
const providedContext = inject(teleportTargetKey, void 0);
|
|
22
29
|
return computed(() => {
|
|
23
|
-
const ownTarget = readTeleportTarget(
|
|
30
|
+
const ownTarget = readTeleportTarget(toValue(target));
|
|
24
31
|
if (hasTarget(ownTarget)) return ownTarget;
|
|
25
|
-
return
|
|
32
|
+
return providedContext?.target.value ?? "body";
|
|
26
33
|
});
|
|
27
34
|
}
|
|
35
|
+
function useTeleportPositioningKey() {
|
|
36
|
+
const providedContext = inject(teleportTargetKey, void 0);
|
|
37
|
+
return computed(() => providedContext?.positioningKey.value);
|
|
38
|
+
}
|
|
28
39
|
//#endregion
|
|
29
|
-
export {
|
|
40
|
+
export { useTeleportPositioningKey as n, useTeleportTarget as r, provideTeleportTarget as t };
|