@dumiflex/wp-kit 0.0.0-stage → 0.3.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/CHANGELOG.md +51 -0
- package/LICENSE +674 -0
- package/README.md +76 -3
- package/package.json +77 -6
- package/src/Avatar.vue +83 -0
- package/src/Badge.vue +97 -0
- package/src/Banner.vue +118 -0
- package/src/BookmarkButton.vue +27 -0
- package/src/BundleMeta.vue +51 -0
- package/src/Button.vue +103 -0
- package/src/Card.vue +68 -0
- package/src/Checkbox.vue +107 -0
- package/src/Chip.vue +97 -0
- package/src/ChipToggle.vue +92 -0
- package/src/ChoiceCards.vue +133 -0
- package/src/CloseButton.vue +69 -0
- package/src/CodeBlock.vue +119 -0
- package/src/ColorField.vue +206 -0
- package/src/ColorPicker.vue +201 -0
- package/src/Combobox.vue +334 -0
- package/src/ConfirmDialog.vue +163 -0
- package/src/ConfirmModal.vue +147 -0
- package/src/ConstraintMatrixPreview.vue +708 -0
- package/src/ContextMenu.vue +379 -0
- package/src/CopyButton.vue +156 -0
- package/src/DataTable.vue +292 -0
- package/src/DatePicker.vue +234 -0
- package/src/DescriptionList.vue +73 -0
- package/src/DiffView.vue +68 -0
- package/src/Disclosure.vue +166 -0
- package/src/DragHandle.vue +49 -0
- package/src/Drawer.vue +131 -0
- package/src/DropZone.vue +196 -0
- package/src/DropdownMenu.vue +72 -0
- package/src/EmptyState.vue +111 -0
- package/src/Field.vue +28 -0
- package/src/HsvPicker.vue +208 -0
- package/src/Icon.vue +39 -0
- package/src/IconPicker.vue +209 -0
- package/src/ImageGrid.vue +125 -0
- package/src/InlineEdit.vue +183 -0
- package/src/Input.vue +99 -0
- package/src/Kbd.vue +56 -0
- package/src/KindChip.vue +53 -0
- package/src/Lightbox.vue +173 -0
- package/src/ListFilter.vue +85 -0
- package/src/ListRow.vue +204 -0
- package/src/LoadingMark.vue +161 -0
- package/src/Logo.vue +60 -0
- package/src/Modal.vue +76 -0
- package/src/ModalShell.vue +107 -0
- package/src/Pagination.vue +106 -0
- package/src/Popover.vue +171 -0
- package/src/PostCard.vue +211 -0
- package/src/ProgressBar.vue +90 -0
- package/src/RadioGroup.vue +177 -0
- package/src/RangeSlider.vue +183 -0
- package/src/RatingBadge.vue +42 -0
- package/src/RelativeDate.vue +35 -0
- package/src/ResizeHandle.vue +143 -0
- package/src/SearchInput.vue +199 -0
- package/src/Select.vue +641 -0
- package/src/Separator.vue +54 -0
- package/src/Skeleton.vue +82 -0
- package/src/Slider.vue +198 -0
- package/src/SortableList.vue +260 -0
- package/src/SplitPane.vue +68 -0
- package/src/StarButton.vue +40 -0
- package/src/Stepper.vue +141 -0
- package/src/SupportLinks.vue +93 -0
- package/src/TagInput.vue +300 -0
- package/src/Textarea.vue +57 -0
- package/src/Timeline.vue +92 -0
- package/src/ToastCard.vue +119 -0
- package/src/ToastHost.vue +40 -0
- package/src/Toggle.vue +36 -0
- package/src/TokenizedValue.vue +310 -0
- package/src/Toolbar.vue +110 -0
- package/src/VirtualList.vue +87 -0
- package/src/VisuallyHidden.vue +29 -0
- package/src/WpButton.vue +75 -0
- package/src/WpCheck.vue +102 -0
- package/src/WpIconButton.vue +107 -0
- package/src/WpImageZoom.vue +544 -0
- package/src/WpNumber.vue +183 -0
- package/src/WpSegmented.vue +175 -0
- package/src/WpSelect.vue +89 -0
- package/src/WpSwitch.vue +163 -0
- package/src/WpTabs.vue +188 -0
- package/src/_modal-motion.css +33 -0
- package/src/_skeleton.css +50 -0
- package/src/axis-color.ts +42 -0
- package/src/button.css +169 -0
- package/src/calendar.ts +59 -0
- package/src/clipboard.ts +50 -0
- package/src/colour-presets.ts +12 -0
- package/src/diff.ts +51 -0
- package/src/drop-zone.ts +41 -0
- package/src/flip.ts +237 -0
- package/src/floating.ts +99 -0
- package/src/hsv.ts +100 -0
- package/src/icon-catalog.ts +52 -0
- package/src/image-zoom.ts +93 -0
- package/src/logo-paths.ts +21 -0
- package/src/matrix-axis.ts +91 -0
- package/src/pagination.ts +27 -0
- package/src/platform-keys.ts +29 -0
- package/src/rich-tokenize.ts +357 -0
- package/src/select-types.ts +32 -0
- package/src/slider-math.ts +45 -0
- package/src/sortable.ts +22 -0
- package/src/theme/fonts/OFL-Fraunces.txt +93 -0
- package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -0
- package/src/theme/fonts/OFL-Manrope.txt +93 -0
- package/src/theme/fonts/fraunces-latin-wght-normal.woff2 +0 -0
- package/src/theme/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/src/theme/fonts/manrope-latin-wght-normal.woff2 +0 -0
- package/src/theme/looks.css +428 -0
- package/src/theme/palettes.css +254 -0
- package/src/theme/tokens.css +2894 -0
- package/src/tokens.ts +56 -0
- package/src/tooltip.css +43 -0
- package/src/tooltip.ts +146 -0
- package/src/useDialogFocus.ts +73 -0
- package/src/useGrowableField.ts +357 -0
- package/src/useModalKeyShield.ts +116 -0
- package/src/useToast.ts +48 -0
- package/src/wp-logo.svg +14 -0
package/src/Logo.vue
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** Gradient ids must be unique on the page, and two logos may wear different
|
|
3
|
+
* brands, so count across every app on it. */
|
|
4
|
+
let nextId = 0;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
/**
|
|
9
|
+
* The Wildcard Pipeline logo, drawn inline so it needs no file. It names
|
|
10
|
+
* itself to screen readers; `decorative` hides it when the name is written
|
|
11
|
+
* beside it (the top bar's brand). `brand="community"` draws it in the
|
|
12
|
+
* community site's colours.
|
|
13
|
+
*
|
|
14
|
+
* <Logo :size="22" decorative />
|
|
15
|
+
*/
|
|
16
|
+
import { computed } from "vue";
|
|
17
|
+
import { BRAND_COLOURS, type LogoBrand } from "./logo-paths";
|
|
18
|
+
|
|
19
|
+
const props = withDefaults(defineProps<{
|
|
20
|
+
size?: number | undefined;
|
|
21
|
+
decorative?: boolean | undefined;
|
|
22
|
+
brand?: LogoBrand | undefined;
|
|
23
|
+
}>(), { size: 28, brand: "extension" });
|
|
24
|
+
|
|
25
|
+
const id = `wp-logo-${nextId++}`;
|
|
26
|
+
const c = computed(() => BRAND_COLOURS[props.brand]);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<svg
|
|
31
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
32
|
+
viewBox="0 0 1024 1024"
|
|
33
|
+
:width="size"
|
|
34
|
+
:height="size"
|
|
35
|
+
:role="decorative ? undefined : 'img'"
|
|
36
|
+
:aria-label="decorative ? undefined : 'Wildcard Pipeline'"
|
|
37
|
+
:aria-hidden="decorative || undefined"
|
|
38
|
+
class="wp-logo"
|
|
39
|
+
>
|
|
40
|
+
<defs>
|
|
41
|
+
<linearGradient :id="`${id}a`" x1="312.56" y1="897.19" x2="312.56" y2="2" gradientUnits="userSpaceOnUse">
|
|
42
|
+
<stop offset="0" :stop-color="c[0]" />
|
|
43
|
+
<stop offset="1" :stop-color="c[1]" />
|
|
44
|
+
</linearGradient>
|
|
45
|
+
<linearGradient :id="`${id}b`" x1="711.44" y1="126.81" x2="711.44" y2="1022" gradientUnits="userSpaceOnUse">
|
|
46
|
+
<stop offset="0" :stop-color="c[1]" />
|
|
47
|
+
<stop offset="1" :stop-color="c[2]" />
|
|
48
|
+
</linearGradient>
|
|
49
|
+
</defs>
|
|
50
|
+
<path :fill="`url(#${id}a)`" d="m512,2c-53.6,0-98.47,38.16-108.84,88.73-75.07,19.29-143.32,58.26-198.74,113.68-55.42,55.42-94.39,123.68-113.68,198.74-50.58,10.38-88.73,55.24-88.73,108.84s38.16,98.47,88.73,108.84c13.62,53.14,37.03,102.64,69.77,147.47,37.14,50.86,85.83,93.86,140.81,124.33,5.54,3.08,11.56,4.54,17.48,4.54,12.7,0,25.02-6.72,31.61-18.61,9.68-17.44,3.38-39.42-14.07-49.09-85.32-47.32-147.22-125.71-173.38-218.21,36.3-18.29,61.27-55.92,61.27-99.28s-24.94-80.97-61.23-99.27c34.22-119.96,129.79-215.52,249.74-249.74,18.3,36.29,55.92,61.23,99.27,61.23,61.27,0,111.11-49.84,111.11-111.11S573.27,2,512,2ZM113.11,473.11c21.44,0,38.89,17.44,38.89,38.89,0,20.1-15.32,36.69-34.91,38.69h-.01c-.18.02-.36.03-.53.04-1.13.1-2.28.16-3.43.16-21.44,0-38.89-17.44-38.89-38.89s17.44-38.89,38.89-38.89Zm398.89-321.11c-21.44,0-38.89-17.44-38.89-38.89s17.44-38.89,38.89-38.89,38.89,17.44,38.89,38.89-17.44,38.89-38.89,38.89Z" />
|
|
51
|
+
<path :fill="`url(#${id}b)`" d="m933.27,403.16c-13.62-53.14-37.03-102.64-69.77-147.47-37.14-50.86-85.83-93.86-140.81-124.33-17.44-9.68-39.42-3.38-49.09,14.07-9.68,17.44-3.38,39.42,14.07,49.09,85.32,47.32,147.22,125.71,173.38,218.21-36.3,18.29-61.27,55.92-61.27,99.28s24.94,80.97,61.23,99.27c-34.22,119.96-129.79,215.52-249.74,249.74-18.3-36.29-55.92-61.23-99.27-61.23-61.27,0-111.11,49.84-111.11,111.11s49.84,111.11,111.11,111.11c53.6,0,98.47-38.16,108.84-88.73,75.07-19.29,143.32-58.26,198.74-113.68,55.42-55.42,94.39-123.68,113.68-198.74,50.58-10.38,88.73-55.24,88.73-108.84s-38.16-98.47-88.73-108.84Zm-421.27,546.62c-21.44,0-38.89-17.44-38.89-38.89s17.44-38.89,38.89-38.89,38.89,17.44,38.89,38.89-17.44,38.89-38.89,38.89Zm398.89-398.89c-21.44,0-38.89-17.44-38.89-38.89,0-20.03,15.22-36.58,34.72-38.67.38-.04.77-.08,1.16-.11h.02c.99-.08,1.99-.11,2.99-.11,21.44,0,38.89,17.44,38.89,38.89s-17.44,38.89-38.89,38.89Z" />
|
|
52
|
+
<path :fill="c[0]" d="m735.02,517.56c-153.82,30.87-186.59,63.64-217.46,217.46-1.22,6.08-9.9,6.08-11.12,0-30.87-153.82-63.64-186.59-217.46-217.46-6.08-1.22-6.08-9.9,0-11.12,153.82-30.87,186.59-63.64,217.46-217.46,1.22-6.08,9.9-6.08,11.12,0,30.87,153.82,63.64,186.59,217.46,217.46,6.08,1.22,6.08,9.9,0,11.12Z" />
|
|
53
|
+
<path :fill="c[1]" d="m434.06,665.85c-51.08,10.25-61.96,21.13-72.22,72.22-.41,2.02-3.29,2.02-3.69,0-10.25-51.08-21.13-61.96-72.22-72.22-2.02-.41-2.02-3.29,0-3.69,51.08-10.25,61.96-21.13,72.22-72.22.41-2.02,3.29-2.02,3.69,0,10.25,51.08,21.13,61.96,72.22,72.22,2.02.41,2.02,3.29,0,3.69Z" />
|
|
54
|
+
<path :fill="c[2]" d="m738.07,361.84c-51.08,10.25-61.96,21.13-72.22,72.22-.41,2.02-3.29,2.02-3.69,0-10.25-51.08-21.13-61.96-72.22-72.22-2.02-.41-2.02-3.29,0-3.69,51.08-10.25,61.96-21.13,72.22-72.22.41-2.02,3.29-2.02,3.69,0,10.25,51.08,21.13,61.96,72.22,72.22,2.02.41,2.02,3.29,0,3.69Z" />
|
|
55
|
+
</svg>
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<style scoped>
|
|
59
|
+
.wp-logo { display: block; flex-shrink: 0; }
|
|
60
|
+
</style>
|
package/src/Modal.vue
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import CloseButton from "./CloseButton.vue";
|
|
3
|
+
import { computed, ref, useId, useSlots } from "vue";
|
|
4
|
+
import { useDialogFocus } from "./useDialogFocus";
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
open: boolean;
|
|
8
|
+
title?: string | undefined;
|
|
9
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
10
|
+
closeOnBackdrop?: boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
const props = withDefaults(defineProps<Props>(), { size: "md", closeOnBackdrop: true });
|
|
13
|
+
|
|
14
|
+
const emit = defineEmits<{
|
|
15
|
+
(e: "update:open", v: boolean): void;
|
|
16
|
+
}>();
|
|
17
|
+
|
|
18
|
+
const slots = useSlots();
|
|
19
|
+
|
|
20
|
+
const modalClasses = computed(() => ["wp-modal", `wp-modal--${props.size}`]);
|
|
21
|
+
const dialog = ref<HTMLElement | null>(null);
|
|
22
|
+
const titleId = `wp-modal-title-${useId()}`;
|
|
23
|
+
|
|
24
|
+
function close() {
|
|
25
|
+
emit("update:open", false);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function onBackdrop() {
|
|
29
|
+
if (props.closeOnBackdrop) close();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
useDialogFocus(dialog, () => props.open, {
|
|
33
|
+
onEscape: close,
|
|
34
|
+
// The first control in the body, else the dialog itself (the close button
|
|
35
|
+
// would make Enter close it).
|
|
36
|
+
initial: (root, els) => {
|
|
37
|
+
const body = root.querySelector(".wp-modal__body");
|
|
38
|
+
return els.find((el) => body?.contains(el)) ?? root;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<Teleport to="body">
|
|
45
|
+
<div
|
|
46
|
+
v-if="open"
|
|
47
|
+
class="wp-modal__backdrop"
|
|
48
|
+
data-test="modal-backdrop"
|
|
49
|
+
@mousedown.self="onBackdrop"
|
|
50
|
+
>
|
|
51
|
+
<div
|
|
52
|
+
ref="dialog"
|
|
53
|
+
:class="modalClasses"
|
|
54
|
+
role="dialog"
|
|
55
|
+
aria-modal="true"
|
|
56
|
+
:aria-labelledby="title || slots.header ? titleId : undefined"
|
|
57
|
+
tabindex="-1"
|
|
58
|
+
@mousedown.stop
|
|
59
|
+
>
|
|
60
|
+
<header v-if="title || slots.header" class="wp-modal__head">
|
|
61
|
+
<h3 v-if="title" :id="titleId" class="wp-modal__title">{{ title }}</h3>
|
|
62
|
+
<!-- A custom header puts :id="titleId" on its own heading. -->
|
|
63
|
+
<slot name="header" :title-id="titleId" />
|
|
64
|
+
<span class="wp-spacer" />
|
|
65
|
+
<CloseButton kbd="Esc" @click="close" />
|
|
66
|
+
</header>
|
|
67
|
+
<div class="wp-modal__body">
|
|
68
|
+
<slot />
|
|
69
|
+
</div>
|
|
70
|
+
<footer v-if="slots.footer" class="wp-modal__foot">
|
|
71
|
+
<slot name="footer" />
|
|
72
|
+
</footer>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</Teleport>
|
|
76
|
+
</template>
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Teleport to="body">
|
|
3
|
+
<Transition name="wp-modal" appear>
|
|
4
|
+
<div v-if="visible" ref="overlayEl" class="wp-modal-overlay" @click="$emit('close')">
|
|
5
|
+
<div
|
|
6
|
+
class="wp-modal-wrapper"
|
|
7
|
+
role="dialog"
|
|
8
|
+
aria-modal="true"
|
|
9
|
+
:aria-label="label"
|
|
10
|
+
:aria-labelledby="labelledby"
|
|
11
|
+
@click.stop
|
|
12
|
+
>
|
|
13
|
+
<slot></slot>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
</Transition>
|
|
17
|
+
</Teleport>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
import { ref, watch, onBeforeUnmount } from "vue";
|
|
22
|
+
import { useModalKeyShield } from "./useModalKeyShield";
|
|
23
|
+
|
|
24
|
+
const props = defineProps<{
|
|
25
|
+
visible: boolean;
|
|
26
|
+
/** The dialog's name when it has no visible title. */
|
|
27
|
+
label?: string | undefined;
|
|
28
|
+
/** Id of the element that names the dialog (its title). */
|
|
29
|
+
labelledby?: string | undefined;
|
|
30
|
+
}>();
|
|
31
|
+
const emit = defineEmits<{
|
|
32
|
+
(e: "close"): void;
|
|
33
|
+
/** Every keydown inside the modal. Consumers MUST use this instead of a
|
|
34
|
+
* window listener: the shield stops inside-modal keys at the overlay, so a
|
|
35
|
+
* window listener would never see them. */
|
|
36
|
+
(e: "keydown", ev: KeyboardEvent): void;
|
|
37
|
+
}>();
|
|
38
|
+
|
|
39
|
+
const overlayEl = ref<HTMLElement | null>(null);
|
|
40
|
+
|
|
41
|
+
function closeOnEscape(event: KeyboardEvent): void {
|
|
42
|
+
if (!props.visible || event.key !== "Escape") return;
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
emit("close");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Keys pressed INSIDE the modal are handled here and stop at the overlay, so
|
|
48
|
+
// they never reach ComfyUI's global shortcuts (see useModalKeyShield).
|
|
49
|
+
useModalKeyShield(overlayEl, {
|
|
50
|
+
onKey: (ev) => {
|
|
51
|
+
emit("keydown", ev);
|
|
52
|
+
closeOnEscape(ev);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// The window listener still covers the case where focus is OUTSIDE the modal
|
|
57
|
+
// — clicking the canvas leaves the modal open but unfocused, and Escape should
|
|
58
|
+
// still close it. Events from inside never get here; the shield stops them.
|
|
59
|
+
function onKeydown(event: KeyboardEvent) {
|
|
60
|
+
closeOnEscape(event);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
watch(
|
|
64
|
+
() => props.visible,
|
|
65
|
+
(visible) => {
|
|
66
|
+
if (visible) window.addEventListener("keydown", onKeydown);
|
|
67
|
+
else window.removeEventListener("keydown", onKeydown);
|
|
68
|
+
},
|
|
69
|
+
{ immediate: true },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
onBeforeUnmount(() => window.removeEventListener("keydown", onKeydown));
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<style>
|
|
76
|
+
@import "./_modal-motion.css";
|
|
77
|
+
</style>
|
|
78
|
+
|
|
79
|
+
<style scoped>
|
|
80
|
+
.wp-modal-overlay,
|
|
81
|
+
.wp-modal-overlay * {
|
|
82
|
+
box-sizing: border-box;
|
|
83
|
+
}
|
|
84
|
+
.wp-modal-overlay {
|
|
85
|
+
position: fixed;
|
|
86
|
+
inset: 0;
|
|
87
|
+
z-index: 9999;
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
padding: 20px;
|
|
92
|
+
background: var(--wp-overlay-bg, rgba(0, 0, 0, 0.62));
|
|
93
|
+
font-family: var(--wp-font-sans, sans-serif);
|
|
94
|
+
cursor: default;
|
|
95
|
+
}
|
|
96
|
+
.wp-modal-wrapper {
|
|
97
|
+
display: flex;
|
|
98
|
+
justify-content: center;
|
|
99
|
+
width: 100%;
|
|
100
|
+
max-height: 100%;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* `wp-modal` open/close transition lives in
|
|
104
|
+
* src/components/shared/_modal-motion.css (imported globally via
|
|
105
|
+
* ContextWidget) so every modal — ModalShell consumers, ConfirmDialog,
|
|
106
|
+
* InjectorBindingModal — animates with the same rules. */
|
|
107
|
+
</style>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Pagination: move through a long list a page at a time, or load more at
|
|
4
|
+
* its end. Works on the canvas and in the manager.
|
|
5
|
+
*
|
|
6
|
+
* <Pagination v-model:page="page" :total="rows.length" :page-size="50" />
|
|
7
|
+
* <Pagination mode="more" :shown="shown.length" :total="230" :loading="busy" @more="loadMore" />
|
|
8
|
+
*
|
|
9
|
+
* Pages: a `nav` with Previous / Next and the page numbers (first, last, the
|
|
10
|
+
* current page with `siblings` either side, "…" between), the current one
|
|
11
|
+
* marked `aria-current="page"`. More: one "Load more" button under a
|
|
12
|
+
* "Showing 50 of 230" line. Nothing is drawn when everything fits on one page.
|
|
13
|
+
*/
|
|
14
|
+
import { computed } from "vue";
|
|
15
|
+
import { pageItems } from "./pagination";
|
|
16
|
+
import WpButton from "./WpButton.vue";
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(defineProps<{
|
|
19
|
+
/** pages: numbered pages. more: a Load more button. */
|
|
20
|
+
mode?: "pages" | "more" | undefined;
|
|
21
|
+
/** The current page, from 1. */
|
|
22
|
+
page?: number | undefined;
|
|
23
|
+
/** How many items there are in all. */
|
|
24
|
+
total: number;
|
|
25
|
+
pageSize?: number | undefined;
|
|
26
|
+
/** Pages shown either side of the current one. */
|
|
27
|
+
siblings?: number | undefined;
|
|
28
|
+
/** In "more" mode: how many items are on screen. */
|
|
29
|
+
shown?: number | undefined;
|
|
30
|
+
loading?: boolean | undefined;
|
|
31
|
+
disabled?: boolean | undefined;
|
|
32
|
+
size?: "sm" | "md" | undefined;
|
|
33
|
+
/** The item's name in "Showing 50 of 230 modules". */
|
|
34
|
+
noun?: string | undefined;
|
|
35
|
+
ariaLabel?: string | undefined;
|
|
36
|
+
}>(), { mode: "pages", page: 1, pageSize: 25, siblings: 1, shown: 0, size: "md", noun: undefined, ariaLabel: "Pages" });
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{ (e: "update:page", v: number): void; (e: "more"): void }>();
|
|
39
|
+
|
|
40
|
+
const pages = computed(() => Math.max(1, Math.ceil(props.total / Math.max(1, props.pageSize))));
|
|
41
|
+
const items = computed(() => pageItems(props.page, pages.value, props.siblings));
|
|
42
|
+
const from = computed(() => Math.min(props.total, (props.page - 1) * props.pageSize + 1));
|
|
43
|
+
const to = computed(() => Math.min(props.total, props.page * props.pageSize));
|
|
44
|
+
|
|
45
|
+
function go(p: number): void {
|
|
46
|
+
const next = Math.min(Math.max(1, p), pages.value);
|
|
47
|
+
if (next !== props.page && !props.disabled) emit("update:page", next);
|
|
48
|
+
}
|
|
49
|
+
const btnSize = computed(() => (props.size === "sm" ? "sm" : "md"));
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<nav v-if="mode === 'pages' && pages > 1" class="wp-paging" :data-size="size" :aria-label="ariaLabel">
|
|
54
|
+
<span class="wp-paging__range" aria-live="polite">{{ from }}–{{ to }} of {{ total }}</span>
|
|
55
|
+
<ul class="wp-paging__list">
|
|
56
|
+
<li>
|
|
57
|
+
<WpButton variant="ghost" :size="btnSize" icon="pi-chevron-left" aria-label="Previous page" :disabled="disabled || props.page <= 1" @click="go(props.page - 1)" />
|
|
58
|
+
</li>
|
|
59
|
+
<li v-for="it in items" :key="it">
|
|
60
|
+
<span v-if="typeof it !== 'number'" class="wp-paging__gap" aria-hidden="true">…</span>
|
|
61
|
+
<button
|
|
62
|
+
v-else
|
|
63
|
+
type="button"
|
|
64
|
+
class="wp-paging__page"
|
|
65
|
+
:data-size="size"
|
|
66
|
+
:aria-current="it === page ? 'page' : undefined"
|
|
67
|
+
:aria-label="`Page ${it}`"
|
|
68
|
+
:disabled="disabled"
|
|
69
|
+
@click="go(it)"
|
|
70
|
+
>{{ it }}</button>
|
|
71
|
+
</li>
|
|
72
|
+
<li>
|
|
73
|
+
<WpButton variant="ghost" :size="btnSize" icon="pi-chevron-right" aria-label="Next page" :disabled="disabled || props.page >= pages" @click="go(props.page + 1)" />
|
|
74
|
+
</li>
|
|
75
|
+
</ul>
|
|
76
|
+
</nav>
|
|
77
|
+
<div v-else-if="mode === 'more' && total > 0" class="wp-paging wp-paging--more" :data-size="size">
|
|
78
|
+
<span class="wp-paging__range" aria-live="polite">Showing {{ Math.min(props.shown, total) }} of {{ total }}{{ noun ? ` ${noun}` : "" }}</span>
|
|
79
|
+
<WpButton v-if="props.shown < total" variant="secondary" :size="btnSize" :loading="loading" :disabled="disabled" @click="emit('more')">Load more</WpButton>
|
|
80
|
+
</div>
|
|
81
|
+
</template>
|
|
82
|
+
|
|
83
|
+
<style scoped>
|
|
84
|
+
.wp-paging {
|
|
85
|
+
display: flex; align-items: center; justify-content: space-between; gap: var(--wp-space-4); flex-wrap: wrap;
|
|
86
|
+
min-width: 0; color: var(--wp-text-muted); font: 400 var(--wp-text-sm)/1.2 var(--wp-font-sans);
|
|
87
|
+
}
|
|
88
|
+
.wp-paging[data-size="sm"] { font-size: var(--wp-text-xs); gap: var(--wp-space-3); }
|
|
89
|
+
.wp-paging--more { flex-direction: column; justify-content: center; }
|
|
90
|
+
.wp-paging__range { font-variant-numeric: tabular-nums; }
|
|
91
|
+
.wp-paging__list { display: flex; align-items: center; gap: 2px; margin: 0; padding: 0; list-style: none; }
|
|
92
|
+
.wp-paging__gap { display: inline-grid; place-items: center; min-width: 20px; color: var(--wp-text-dim); }
|
|
93
|
+
.wp-paging__page {
|
|
94
|
+
display: inline-grid; place-items: center; box-sizing: border-box;
|
|
95
|
+
min-width: var(--wp-control-h-md); height: var(--wp-control-h-md); margin: 0; padding: 0 var(--wp-space-2);
|
|
96
|
+
border: 1px solid transparent; border-radius: var(--wp-radius);
|
|
97
|
+
background: transparent; color: var(--wp-text-muted); font: 500 var(--wp-text-sm)/1 var(--wp-font-sans);
|
|
98
|
+
font-variant-numeric: tabular-nums; cursor: pointer;
|
|
99
|
+
transition: background var(--wp-motion-hover), color var(--wp-motion-hover);
|
|
100
|
+
}
|
|
101
|
+
.wp-paging__page[data-size="sm"] { min-width: var(--wp-control-h-sm); height: var(--wp-control-h-sm); border-radius: var(--wp-radius-sm); font-size: var(--wp-text-xs); }
|
|
102
|
+
.wp-paging__page:hover:not(:disabled) { background: var(--wp-row-hover); color: var(--wp-text); }
|
|
103
|
+
.wp-paging__page[aria-current="page"] { border-color: var(--wp-border-strong); background: var(--wp-bg-3); color: var(--wp-text); font-weight: 600; }
|
|
104
|
+
.wp-paging__page:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
|
|
105
|
+
.wp-paging__page:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
106
|
+
</style>
|
package/src/Popover.vue
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A panel anchored to a trigger: opens below it (or wherever `placement`
|
|
4
|
+
* says), flips and stays on screen, follows the trigger on scroll and
|
|
5
|
+
* resize, and closes on Escape or a click outside, giving focus back to
|
|
6
|
+
* the trigger. Works on the canvas and in the manager. Anything that
|
|
7
|
+
* floats next to a control builds on this instead of its own Teleport.
|
|
8
|
+
*
|
|
9
|
+
* <Popover v-model:open="open" label="Category colour">
|
|
10
|
+
* <template #trigger="{ props }"><Button v-bind="props">Colour</Button></template>
|
|
11
|
+
* …panel content…
|
|
12
|
+
* </Popover>
|
|
13
|
+
*
|
|
14
|
+
* One panel shared by many triggers (the cells of a rule grid) passes the
|
|
15
|
+
* element it belongs to as `anchor` instead of a trigger slot; clicks on that
|
|
16
|
+
* element don't count as outside, so it can toggle the panel itself.
|
|
17
|
+
*
|
|
18
|
+
* <Popover :open="!!cell" :anchor="cell?.el" label="Cell rule" @update:open="cell = null">…</Popover>
|
|
19
|
+
*/
|
|
20
|
+
import { computed, nextTick, onBeforeUnmount, ref, useId, watch } from "vue";
|
|
21
|
+
import { placeFloating, viewportSize, type Placement, type Side } from "./floating";
|
|
22
|
+
|
|
23
|
+
const props = withDefaults(defineProps<{
|
|
24
|
+
open: boolean;
|
|
25
|
+
placement?: Placement | undefined;
|
|
26
|
+
/** The panel's name for screen readers. */
|
|
27
|
+
label?: string | undefined;
|
|
28
|
+
/** Make the panel at least as wide as the trigger (lists under a field). */
|
|
29
|
+
matchWidth?: boolean | undefined;
|
|
30
|
+
/** Move focus into the panel when it opens. Off for panels you type past. */
|
|
31
|
+
autofocus?: boolean | undefined;
|
|
32
|
+
/** "dialog" for panels with controls, "menu"/"listbox" when the content is one. */
|
|
33
|
+
role?: "dialog" | "menu" | "listbox" | "group" | undefined;
|
|
34
|
+
/** Place the panel against this element instead of the trigger slot. */
|
|
35
|
+
anchor?: HTMLElement | null | undefined;
|
|
36
|
+
}>(), { placement: "bottom-start", autofocus: true, role: "dialog", anchor: null });
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{ (e: "update:open", v: boolean): void }>();
|
|
39
|
+
|
|
40
|
+
const id = `wp-popover-${useId()}`;
|
|
41
|
+
const anchorEl = ref<HTMLElement | null>(null);
|
|
42
|
+
const panelEl = ref<HTMLElement | null>(null);
|
|
43
|
+
const pos = ref<{ x: number; y: number; side: Side; minWidth?: number | undefined }>({ x: -9999, y: -9999, side: "bottom" });
|
|
44
|
+
|
|
45
|
+
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), '
|
|
46
|
+
+ 'textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
47
|
+
|
|
48
|
+
function trigger(): HTMLElement | null {
|
|
49
|
+
if (props.anchor) return props.anchor;
|
|
50
|
+
const el = anchorEl.value;
|
|
51
|
+
return (el?.firstElementChild as HTMLElement | null) ?? el;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function setOpen(v: boolean): void {
|
|
55
|
+
if (v !== props.open) emit("update:open", v);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const triggerProps = computed(() => ({
|
|
59
|
+
"aria-haspopup": (props.role === "group" ? "true" : props.role) as "true" | "dialog" | "menu" | "listbox",
|
|
60
|
+
"aria-expanded": props.open,
|
|
61
|
+
"aria-controls": props.open ? id : undefined,
|
|
62
|
+
onClick: () => setOpen(!props.open),
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
function place(): void {
|
|
66
|
+
const t = trigger();
|
|
67
|
+
const p = panelEl.value;
|
|
68
|
+
if (!t || !p) return;
|
|
69
|
+
const r = t.getBoundingClientRect();
|
|
70
|
+
const at = placeFloating(r, { width: Math.max(p.offsetWidth, props.matchWidth ? r.width : 0), height: p.offsetHeight }, viewportSize(), {
|
|
71
|
+
placement: props.placement,
|
|
72
|
+
});
|
|
73
|
+
pos.value = { ...at, minWidth: props.matchWidth ? r.width : undefined };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function onPointerDown(ev: PointerEvent): void {
|
|
77
|
+
const path = ev.composedPath();
|
|
78
|
+
if (panelEl.value && path.includes(panelEl.value)) return;
|
|
79
|
+
if (anchorEl.value && path.includes(anchorEl.value)) return;
|
|
80
|
+
if (props.anchor && path.includes(props.anchor)) return;
|
|
81
|
+
setOpen(false);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function onKeydown(ev: KeyboardEvent): void {
|
|
85
|
+
if (ev.key !== "Escape") return;
|
|
86
|
+
ev.preventDefault();
|
|
87
|
+
ev.stopPropagation();
|
|
88
|
+
setOpen(false);
|
|
89
|
+
trigger()?.focus();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function listen(on: boolean): void {
|
|
93
|
+
const m = on ? "addEventListener" : "removeEventListener";
|
|
94
|
+
window[m]("pointerdown", onPointerDown as EventListener, true);
|
|
95
|
+
window[m]("keydown", onKeydown as EventListener, true);
|
|
96
|
+
window[m]("resize", place);
|
|
97
|
+
window[m]("scroll", place, true);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
watch(() => props.open, async (v) => {
|
|
101
|
+
if (typeof window === "undefined") return;
|
|
102
|
+
listen(v);
|
|
103
|
+
if (!v) return;
|
|
104
|
+
await nextTick();
|
|
105
|
+
place();
|
|
106
|
+
if (props.autofocus && panelEl.value && !panelEl.value.contains(document.activeElement)) {
|
|
107
|
+
(panelEl.value.querySelector<HTMLElement>(FOCUSABLE) ?? panelEl.value).focus();
|
|
108
|
+
}
|
|
109
|
+
}, { immediate: true });
|
|
110
|
+
|
|
111
|
+
// A shared panel moving to another trigger re-places without closing.
|
|
112
|
+
watch(() => props.anchor, () => { if (props.open) void nextTick(place); });
|
|
113
|
+
|
|
114
|
+
onBeforeUnmount(() => { if (typeof window !== "undefined") listen(false); });
|
|
115
|
+
|
|
116
|
+
defineExpose({ place });
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<template>
|
|
120
|
+
<span v-if="$slots.trigger" ref="anchorEl" class="wp-popover-anchor">
|
|
121
|
+
<slot name="trigger" :props="triggerProps" :open="open" />
|
|
122
|
+
</span>
|
|
123
|
+
<Teleport to="body">
|
|
124
|
+
<div
|
|
125
|
+
v-if="open"
|
|
126
|
+
:id="id"
|
|
127
|
+
ref="panelEl"
|
|
128
|
+
class="wp-popover"
|
|
129
|
+
:data-side="pos.side"
|
|
130
|
+
:role="role"
|
|
131
|
+
:aria-label="label"
|
|
132
|
+
tabindex="-1"
|
|
133
|
+
:style="{ left: `${pos.x}px`, top: `${pos.y}px`, minWidth: pos.minWidth ? `${pos.minWidth}px` : undefined }"
|
|
134
|
+
>
|
|
135
|
+
<slot :close="() => setOpen(false)" />
|
|
136
|
+
</div>
|
|
137
|
+
</Teleport>
|
|
138
|
+
</template>
|
|
139
|
+
|
|
140
|
+
<style>
|
|
141
|
+
@layer wp-extension {
|
|
142
|
+
.wp-popover-anchor { display: inline-flex; }
|
|
143
|
+
.wp-popover {
|
|
144
|
+
position: fixed;
|
|
145
|
+
z-index: 10000;
|
|
146
|
+
max-width: min(420px, calc(100vw - 16px));
|
|
147
|
+
max-height: calc(100vh - 16px);
|
|
148
|
+
overflow: auto;
|
|
149
|
+
padding: var(--wp-space-3);
|
|
150
|
+
background: var(--wp-bg-2);
|
|
151
|
+
color: var(--wp-text);
|
|
152
|
+
border: 1px solid var(--wp-border-strong);
|
|
153
|
+
border-radius: var(--wp-radius);
|
|
154
|
+
box-shadow: var(--wp-shadow-md);
|
|
155
|
+
font-family: var(--wp-font-sans);
|
|
156
|
+
font-size: var(--wp-text-sm);
|
|
157
|
+
outline: none;
|
|
158
|
+
animation: wp-popover-in 120ms ease-out;
|
|
159
|
+
}
|
|
160
|
+
@keyframes wp-popover-in {
|
|
161
|
+
from { opacity: 0; transform: translateY(-2px); }
|
|
162
|
+
}
|
|
163
|
+
.wp-popover[data-side="top"] { animation-name: wp-popover-in-up; }
|
|
164
|
+
@keyframes wp-popover-in-up {
|
|
165
|
+
from { opacity: 0; transform: translateY(2px); }
|
|
166
|
+
}
|
|
167
|
+
@media (prefers-reduced-motion: reduce) {
|
|
168
|
+
.wp-popover { animation: none; }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
</style>
|