ropav 0.0.11 → 0.0.13
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 +8 -3
- 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/dropdown-menu/useDropdownMenuRenderItems.d.ts +2 -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 +86 -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 +1155 -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 +29 -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 +11 -3
- package/dist/useControlState.js +4 -0
- package/dist/useFloatingPosition.js +86 -39
- package/dist/useFormControl.js +107 -0
- package/dist/useOverlayLayer.js +262 -0
- package/dist/useTeleportTarget.js +21 -10
- package/docs/public-floating-api.md +159 -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({
|
|
@@ -110,10 +111,15 @@ function useTooltip(props, emitOpenChange) {
|
|
|
110
111
|
strategy: () => props.strategy ?? "absolute",
|
|
111
112
|
offset: () => props.offset,
|
|
112
113
|
flip: () => props.flip !== false,
|
|
114
|
+
flipOptions: () => props.flipOptions,
|
|
113
115
|
shift: () => props.shift !== false,
|
|
114
116
|
collisionPadding: () => props.collisionPadding ?? 8,
|
|
115
|
-
|
|
116
|
-
restartKey: () =>
|
|
117
|
+
autoUpdateOptions: () => props.autoUpdateOptions,
|
|
118
|
+
restartKey: () => [
|
|
119
|
+
Boolean(props.teleport),
|
|
120
|
+
teleportTo.value,
|
|
121
|
+
teleportPositioningKey.value
|
|
122
|
+
]
|
|
117
123
|
});
|
|
118
124
|
const placementSide = computed(() => floating.actualPlacement.value.split("-")[0]);
|
|
119
125
|
const rootClass = computed(() => bem("rp-tooltip", {
|
|
@@ -236,11 +242,13 @@ var tooltip_default = /*#__PURE__*/ _plugin_vue_export_helper_default(/* @__PURE
|
|
|
236
242
|
type: Boolean,
|
|
237
243
|
default: true
|
|
238
244
|
},
|
|
245
|
+
flipOptions: {},
|
|
239
246
|
shift: {
|
|
240
247
|
type: Boolean,
|
|
241
248
|
default: true
|
|
242
249
|
},
|
|
243
250
|
collisionPadding: { default: 8 },
|
|
251
|
+
autoUpdateOptions: {},
|
|
244
252
|
arrow: {
|
|
245
253
|
type: Boolean,
|
|
246
254
|
default: false
|
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,59 @@ 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 getFlipFallbackStrategy() {
|
|
1217
|
+
return toValue(options.flipOptions)?.fallbackStrategy;
|
|
1218
|
+
}
|
|
1219
|
+
function getShift() {
|
|
1220
|
+
return toValue(options.shift) !== false;
|
|
1221
|
+
}
|
|
1222
|
+
function getCollisionPadding() {
|
|
1223
|
+
return toValue(options.collisionPadding) ?? DEFAULT_COLLISION_PADDING;
|
|
1224
|
+
}
|
|
1225
|
+
function getAutoUpdateAnimationFrame() {
|
|
1226
|
+
return toValue(options.autoUpdateOptions)?.animationFrame;
|
|
1227
|
+
}
|
|
1188
1228
|
function getHiddenStyle() {
|
|
1189
1229
|
return {
|
|
1190
|
-
position:
|
|
1230
|
+
position: getStrategy(),
|
|
1191
1231
|
top: "0",
|
|
1192
1232
|
left: "0",
|
|
1193
1233
|
visibility: "hidden"
|
|
1194
1234
|
};
|
|
1195
1235
|
}
|
|
1196
1236
|
function resetPosition() {
|
|
1197
|
-
actualPlacement.value =
|
|
1237
|
+
actualPlacement.value = getPlacement();
|
|
1198
1238
|
isPositioned.value = false;
|
|
1199
1239
|
floatingStyle.value = getHiddenStyle();
|
|
1200
1240
|
arrowStyle.value = void 0;
|
|
@@ -1206,28 +1246,33 @@ function useFloatingPosition(options) {
|
|
|
1206
1246
|
request += 1;
|
|
1207
1247
|
}
|
|
1208
1248
|
function getMiddleware() {
|
|
1209
|
-
const middleware = [offset(
|
|
1210
|
-
const padding =
|
|
1211
|
-
|
|
1212
|
-
if (
|
|
1213
|
-
|
|
1214
|
-
|
|
1249
|
+
const middleware = [offset(getOffset())];
|
|
1250
|
+
const padding = getCollisionPadding();
|
|
1251
|
+
const fallbackStrategy = getFlipFallbackStrategy();
|
|
1252
|
+
if (getFlip()) middleware.push(flip({
|
|
1253
|
+
padding,
|
|
1254
|
+
...fallbackStrategy == null ? {} : { fallbackStrategy }
|
|
1255
|
+
}));
|
|
1256
|
+
if (getShift()) middleware.push(shift({ padding }));
|
|
1257
|
+
const arrow$2 = getArrow();
|
|
1258
|
+
if (arrow$2) middleware.push(arrow({
|
|
1259
|
+
element: arrow$2,
|
|
1215
1260
|
padding: DEFAULT_ARROW_PADDING
|
|
1216
1261
|
}));
|
|
1217
1262
|
return middleware;
|
|
1218
1263
|
}
|
|
1219
1264
|
async function update() {
|
|
1220
|
-
const reference =
|
|
1221
|
-
const floating =
|
|
1222
|
-
if (!reference || !floating || !
|
|
1265
|
+
const reference = getReference();
|
|
1266
|
+
const floating = getFloating();
|
|
1267
|
+
if (!reference || !floating || !getOpen()) return;
|
|
1223
1268
|
const currentGeneration = generation;
|
|
1224
1269
|
const currentRequest = ++request;
|
|
1225
1270
|
const result = await computePosition(reference, floating, {
|
|
1226
|
-
placement:
|
|
1227
|
-
strategy:
|
|
1271
|
+
placement: getPlacement(),
|
|
1272
|
+
strategy: getStrategy(),
|
|
1228
1273
|
middleware: getMiddleware()
|
|
1229
1274
|
});
|
|
1230
|
-
if (currentGeneration !== generation || currentRequest !== request || !
|
|
1275
|
+
if (currentGeneration !== generation || currentRequest !== request || !getOpen()) return;
|
|
1231
1276
|
actualPlacement.value = result.placement;
|
|
1232
1277
|
floatingStyle.value = {
|
|
1233
1278
|
position: result.strategy,
|
|
@@ -1243,40 +1288,42 @@ function useFloatingPosition(options) {
|
|
|
1243
1288
|
}
|
|
1244
1289
|
function start() {
|
|
1245
1290
|
stop();
|
|
1291
|
+
if (!getOpen()) return;
|
|
1246
1292
|
resetPosition();
|
|
1247
|
-
|
|
1293
|
+
const currentGeneration = generation;
|
|
1248
1294
|
nextTick(() => {
|
|
1249
|
-
const reference =
|
|
1250
|
-
const floating =
|
|
1251
|
-
if (!reference || !floating || !
|
|
1252
|
-
|
|
1295
|
+
const reference = getReference();
|
|
1296
|
+
const floating = getFloating();
|
|
1297
|
+
if (currentGeneration !== generation || !reference || !floating || !getOpen()) return;
|
|
1298
|
+
const updatePosition = () => void update();
|
|
1299
|
+
const animationFrame = getAutoUpdateAnimationFrame();
|
|
1300
|
+
cleanup = animationFrame == null ? autoUpdate(reference, floating, updatePosition) : autoUpdate(reference, floating, updatePosition, { animationFrame });
|
|
1253
1301
|
});
|
|
1254
1302
|
}
|
|
1255
1303
|
watch([
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1304
|
+
getOpen,
|
|
1305
|
+
getReference,
|
|
1306
|
+
getFloating,
|
|
1307
|
+
getArrow,
|
|
1308
|
+
getPlacement,
|
|
1309
|
+
getStrategy,
|
|
1310
|
+
getOffset,
|
|
1311
|
+
getFlip,
|
|
1312
|
+
getFlipFallbackStrategy,
|
|
1313
|
+
getShift,
|
|
1314
|
+
getCollisionPadding,
|
|
1315
|
+
getAutoUpdateAnimationFrame,
|
|
1316
|
+
() => toValue(options.restartKey)
|
|
1268
1317
|
], start, {
|
|
1269
1318
|
flush: "post",
|
|
1270
1319
|
immediate: true
|
|
1271
1320
|
});
|
|
1272
1321
|
onBeforeUnmount(stop);
|
|
1273
1322
|
return {
|
|
1274
|
-
actualPlacement,
|
|
1275
|
-
arrowStyle,
|
|
1276
|
-
floatingStyle,
|
|
1277
|
-
isPositioned,
|
|
1278
|
-
start,
|
|
1279
|
-
stop,
|
|
1323
|
+
actualPlacement: readonly(actualPlacement),
|
|
1324
|
+
arrowStyle: readonly(arrowStyle),
|
|
1325
|
+
floatingStyle: readonly(floatingStyle),
|
|
1326
|
+
isPositioned: readonly(isPositioned),
|
|
1280
1327
|
update
|
|
1281
1328
|
};
|
|
1282
1329
|
}
|
|
@@ -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 };
|