@dumiflex/wp-kit 0.3.0 → 0.4.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 +77 -51
- package/LICENSE +674 -674
- package/README.md +73 -76
- package/package.json +78 -77
- package/src/Avatar.vue +83 -83
- package/src/Badge.vue +97 -97
- package/src/Banner.vue +118 -118
- package/src/BookmarkButton.vue +27 -27
- package/src/BundleMeta.vue +51 -51
- package/src/Button.vue +103 -103
- package/src/Card.vue +68 -68
- package/src/Checkbox.vue +109 -107
- package/src/Chip.vue +163 -97
- package/src/ChoiceCards.vue +133 -133
- package/src/CloseButton.vue +69 -69
- package/src/CodeBlock.vue +119 -119
- package/src/ColorField.vue +188 -206
- package/src/ColorPicker.vue +201 -201
- package/src/Combobox.vue +331 -334
- package/src/ConfirmDialog.vue +165 -163
- package/src/ConfirmModal.vue +147 -147
- package/src/ConstraintMatrixPreview.vue +708 -708
- package/src/ContextMenu.vue +386 -379
- package/src/CopyButton.vue +156 -156
- package/src/DataTable.vue +292 -292
- package/src/DatePicker.vue +234 -234
- package/src/DescriptionList.vue +73 -73
- package/src/DiffView.vue +68 -68
- package/src/Disclosure.vue +166 -166
- package/src/DragHandle.vue +49 -49
- package/src/Drawer.vue +131 -131
- package/src/DropZone.vue +196 -196
- package/src/DropdownMenu.vue +72 -72
- package/src/EmptyState.vue +111 -111
- package/src/Field.vue +28 -28
- package/src/HsvPicker.vue +208 -208
- package/src/Icon.vue +39 -39
- package/src/IconPicker.vue +209 -209
- package/src/ImageGrid.vue +125 -125
- package/src/InlineEdit.vue +183 -183
- package/src/Input.vue +99 -99
- package/src/Kbd.vue +56 -56
- package/src/Lightbox.vue +173 -173
- package/src/ListFilter.vue +85 -85
- package/src/ListRow.vue +204 -204
- package/src/LoadingMark.vue +175 -161
- package/src/Logo.vue +60 -60
- package/src/Modal.vue +78 -76
- package/src/ModalShell.vue +109 -107
- package/src/Pagination.vue +106 -106
- package/src/Popover.vue +180 -171
- package/src/PostCard.vue +210 -211
- package/src/ProgressBar.vue +90 -90
- package/src/RadioGroup.vue +177 -177
- package/src/RangeSlider.vue +183 -183
- package/src/RelativeDate.vue +35 -35
- package/src/ResizeHandle.vue +143 -143
- package/src/SearchInput.vue +192 -199
- package/src/Select.vue +644 -641
- package/src/Separator.vue +54 -54
- package/src/Skeleton.vue +82 -82
- package/src/Slider.vue +198 -198
- package/src/SortableList.vue +260 -260
- package/src/SplitPane.vue +68 -68
- package/src/StarButton.vue +40 -40
- package/src/Stepper.vue +141 -141
- package/src/SupportLinks.vue +93 -93
- package/src/TagInput.vue +297 -300
- package/src/Textarea.vue +57 -57
- package/src/Timeline.vue +92 -92
- package/src/ToastCard.vue +119 -119
- package/src/ToastHost.vue +40 -40
- package/src/Toggle.vue +36 -36
- package/src/TokenizedValue.vue +310 -310
- package/src/Toolbar.vue +110 -110
- package/src/VirtualList.vue +87 -87
- package/src/VisuallyHidden.vue +29 -29
- package/src/WpButton.vue +75 -75
- package/src/WpCheck.vue +104 -102
- package/src/WpIconButton.vue +107 -107
- package/src/WpImageZoom.vue +544 -544
- package/src/WpNumber.vue +178 -183
- package/src/WpSegmented.vue +175 -175
- package/src/WpSelect.vue +93 -89
- package/src/WpSwitch.vue +163 -163
- package/src/WpTabs.vue +188 -188
- package/src/_modal-motion.css +33 -33
- package/src/_skeleton.css +50 -50
- package/src/axis-color.ts +42 -42
- package/src/button.css +169 -169
- package/src/calendar.ts +59 -59
- package/src/clipboard.ts +50 -50
- package/src/colour-presets.ts +12 -12
- package/src/diff.ts +51 -51
- package/src/drop-zone.ts +41 -41
- package/src/field.css +50 -0
- package/src/flip.ts +237 -237
- package/src/floating-layer.ts +48 -0
- package/src/floating.ts +99 -99
- package/src/hsv.ts +100 -100
- package/src/icon-catalog.ts +52 -52
- package/src/image-zoom.ts +93 -93
- package/src/kind-colour.ts +28 -0
- package/src/logo-paths.ts +21 -21
- package/src/matrix-axis.ts +91 -91
- package/src/pagination.ts +27 -27
- package/src/platform-keys.ts +29 -29
- package/src/rich-tokenize.ts +357 -357
- package/src/select-types.ts +32 -32
- package/src/slider-math.ts +45 -45
- package/src/sortable.ts +22 -22
- package/src/theme/fonts/OFL-Fraunces.txt +93 -93
- package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -93
- package/src/theme/fonts/OFL-Manrope.txt +93 -93
- package/src/theme/looks.css +428 -428
- package/src/theme/palettes.css +254 -254
- package/src/theme/tokens.css +2896 -2894
- package/src/tokens.ts +56 -56
- package/src/tooltip.css +43 -43
- package/src/tooltip.ts +146 -146
- package/src/useDialogFocus.ts +73 -73
- package/src/useGrowableField.ts +357 -357
- package/src/useModalKeyShield.ts +116 -116
- package/src/useToast.ts +48 -48
- package/src/wp-logo.svg +14 -14
- package/src/ChipToggle.vue +0 -92
- package/src/KindChip.vue +0 -53
- package/src/RatingBadge.vue +0 -42
package/src/ImageGrid.vue
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* A grid of image tiles that fills its width (tiles at least `min-size`
|
|
4
|
-
* wide). A click or Enter opens the image in a Lightbox, where ← / → step
|
|
5
|
-
* through the rest. With `selectable` each tile gets a check box in its
|
|
6
|
-
* corner and `v-model:selected` holds the picked ids.
|
|
7
|
-
*
|
|
8
|
-
* <ImageGrid :images="outputs" />
|
|
9
|
-
* <ImageGrid v-model:selected="keep" :images="frames" selectable :min-size="96" />
|
|
10
|
-
*
|
|
11
|
-
* Tiles are buttons in reading order (one Tab stop each); a tile with no
|
|
12
|
-
* `src` draws a Skeleton-like block while it loads.
|
|
13
|
-
*/
|
|
14
|
-
import { computed, ref } from "vue";
|
|
15
|
-
import Lightbox from "./Lightbox.vue";
|
|
16
|
-
import WpCheck from "./WpCheck.vue";
|
|
17
|
-
|
|
18
|
-
export interface GridImage { id: string; src: string; alt: string; thumb?: string; caption?: string }
|
|
19
|
-
|
|
20
|
-
const props = withDefaults(defineProps<{
|
|
21
|
-
images: GridImage[];
|
|
22
|
-
/** Smallest tile width in px. */
|
|
23
|
-
minSize?: number | undefined;
|
|
24
|
-
/** Width / height of a tile. */
|
|
25
|
-
aspect?: number | undefined;
|
|
26
|
-
gap?: "sm" | "md" | undefined;
|
|
27
|
-
selectable?: boolean | undefined;
|
|
28
|
-
selected?: string[] | undefined;
|
|
29
|
-
/** Open the Lightbox on a click (off: emit `open` and do your own thing). */
|
|
30
|
-
lightbox?: boolean | undefined;
|
|
31
|
-
ariaLabel?: string | undefined;
|
|
32
|
-
}>(), { minSize: 120, aspect: 1, gap: "md", selectable: false, selected: () => [], lightbox: true, ariaLabel: "Images" });
|
|
33
|
-
|
|
34
|
-
const emit = defineEmits<{
|
|
35
|
-
(e: "update:selected", v: string[]): void;
|
|
36
|
-
(e: "open", index: number): void;
|
|
37
|
-
}>();
|
|
38
|
-
|
|
39
|
-
const open = ref(false);
|
|
40
|
-
const at = ref(0);
|
|
41
|
-
const shots = computed(() => props.images.map((i) => ({ src: i.src, alt: i.alt, caption: i.caption })));
|
|
42
|
-
|
|
43
|
-
function show(i: number): void {
|
|
44
|
-
emit("open", i);
|
|
45
|
-
if (!props.lightbox) return;
|
|
46
|
-
at.value = i;
|
|
47
|
-
open.value = true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function toggle(id: string, on: boolean): void {
|
|
51
|
-
emit("update:selected", on ? [...props.selected, id] : props.selected.filter((x) => x !== id));
|
|
52
|
-
}
|
|
53
|
-
</script>
|
|
54
|
-
|
|
55
|
-
<template>
|
|
56
|
-
<div class="wp-image-grid">
|
|
57
|
-
<ul
|
|
58
|
-
class="wp-image-grid__list"
|
|
59
|
-
:data-gap="gap"
|
|
60
|
-
:aria-label="ariaLabel"
|
|
61
|
-
:style="{ '--_min': `${minSize}px`, '--_aspect': String(aspect) }"
|
|
62
|
-
>
|
|
63
|
-
<li
|
|
64
|
-
v-for="(img, i) in images"
|
|
65
|
-
:key="img.id"
|
|
66
|
-
class="wp-image-grid__tile"
|
|
67
|
-
:data-selected="(selectable && props.selected.includes(img.id)) || undefined"
|
|
68
|
-
>
|
|
69
|
-
<button
|
|
70
|
-
type="button"
|
|
71
|
-
class="wp-image-grid__open"
|
|
72
|
-
:aria-label="selectable ? `Open ${img.alt}` : img.alt"
|
|
73
|
-
@click="show(i)"
|
|
74
|
-
>
|
|
75
|
-
<img v-if="img.thumb || img.src" class="wp-image-grid__img" :src="img.thumb || img.src" alt="" loading="lazy">
|
|
76
|
-
<span v-else class="wp-image-grid__empty" aria-hidden="true" />
|
|
77
|
-
</button>
|
|
78
|
-
<WpCheck
|
|
79
|
-
v-if="selectable"
|
|
80
|
-
class="wp-image-grid__check"
|
|
81
|
-
:model-value="props.selected.includes(img.id)"
|
|
82
|
-
:aria-label="`Select ${img.alt}`"
|
|
83
|
-
@update:model-value="toggle(img.id, $event)"
|
|
84
|
-
/>
|
|
85
|
-
<span v-if="img.caption" class="wp-image-grid__caption">{{ img.caption }}</span>
|
|
86
|
-
</li>
|
|
87
|
-
</ul>
|
|
88
|
-
<Lightbox v-if="lightbox" v-model:open="open" v-model:index="at" :images="shots" />
|
|
89
|
-
</div>
|
|
90
|
-
</template>
|
|
91
|
-
|
|
92
|
-
<style scoped>
|
|
93
|
-
.wp-image-grid { min-width: 0; }
|
|
94
|
-
.wp-image-grid__list {
|
|
95
|
-
display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--_min), 1fr));
|
|
96
|
-
gap: var(--wp-space-3); margin: 0; padding: 0; list-style: none;
|
|
97
|
-
}
|
|
98
|
-
.wp-image-grid__list[data-gap="sm"] { gap: var(--wp-space-1); }
|
|
99
|
-
.wp-image-grid__tile { position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
100
|
-
.wp-image-grid__open {
|
|
101
|
-
display: block; width: 100%; aspect-ratio: var(--_aspect); padding: 0; overflow: hidden;
|
|
102
|
-
border: 1px solid var(--wp-border); border-radius: var(--wp-radius);
|
|
103
|
-
background: var(--wp-bg-2); cursor: zoom-in;
|
|
104
|
-
transition: border-color var(--wp-motion-hover), box-shadow var(--wp-motion-hover);
|
|
105
|
-
}
|
|
106
|
-
.wp-image-grid__open:hover { border-color: var(--wp-border-strong); }
|
|
107
|
-
.wp-image-grid__open:focus-visible { outline: none; border-color: var(--wp-border-focus); box-shadow:
|
|
108
|
-
.wp-image-grid__tile[data-selected] .wp-image-grid__open { border-color: var(--wp-accent); box-shadow: 0 0 0 2px var(--wp-accent-glow); }
|
|
109
|
-
.wp-image-grid__img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
|
110
|
-
.wp-image-grid__empty {
|
|
111
|
-
display: block; width: 100%; height: 100%;
|
|
112
|
-
background: linear-gradient(90deg, var(--wp-bg-2) 0%, var(--wp-bg-3) 50%, var(--wp-bg-2) 100%);
|
|
113
|
-
background-size: 200% 100%; animation: wp-image-grid-shimmer var(--wp-motion-shimmer) infinite;
|
|
114
|
-
}
|
|
115
|
-
@keyframes wp-image-grid-shimmer { to { background-position: -200% 0; } }
|
|
116
|
-
.wp-image-grid__check { position: absolute; top: 6px; left: 6px; }
|
|
117
|
-
.wp-image-grid__caption {
|
|
118
|
-
overflow: hidden; color: var(--wp-text-muted); font: 400 var(--wp-text-xs)/1.3 var(--wp-font-sans);
|
|
119
|
-
text-overflow: ellipsis; white-space: nowrap;
|
|
120
|
-
}
|
|
121
|
-
@media (prefers-reduced-motion: reduce) {
|
|
122
|
-
.wp-image-grid__open { transition: none; }
|
|
123
|
-
.wp-image-grid__empty { animation: none; }
|
|
124
|
-
}
|
|
125
|
-
</style>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A grid of image tiles that fills its width (tiles at least `min-size`
|
|
4
|
+
* wide). A click or Enter opens the image in a Lightbox, where ← / → step
|
|
5
|
+
* through the rest. With `selectable` each tile gets a check box in its
|
|
6
|
+
* corner and `v-model:selected` holds the picked ids.
|
|
7
|
+
*
|
|
8
|
+
* <ImageGrid :images="outputs" />
|
|
9
|
+
* <ImageGrid v-model:selected="keep" :images="frames" selectable :min-size="96" />
|
|
10
|
+
*
|
|
11
|
+
* Tiles are buttons in reading order (one Tab stop each); a tile with no
|
|
12
|
+
* `src` draws a Skeleton-like block while it loads.
|
|
13
|
+
*/
|
|
14
|
+
import { computed, ref } from "vue";
|
|
15
|
+
import Lightbox from "./Lightbox.vue";
|
|
16
|
+
import WpCheck from "./WpCheck.vue";
|
|
17
|
+
|
|
18
|
+
export interface GridImage { id: string; src: string; alt: string; thumb?: string; caption?: string }
|
|
19
|
+
|
|
20
|
+
const props = withDefaults(defineProps<{
|
|
21
|
+
images: GridImage[];
|
|
22
|
+
/** Smallest tile width in px. */
|
|
23
|
+
minSize?: number | undefined;
|
|
24
|
+
/** Width / height of a tile. */
|
|
25
|
+
aspect?: number | undefined;
|
|
26
|
+
gap?: "sm" | "md" | undefined;
|
|
27
|
+
selectable?: boolean | undefined;
|
|
28
|
+
selected?: string[] | undefined;
|
|
29
|
+
/** Open the Lightbox on a click (off: emit `open` and do your own thing). */
|
|
30
|
+
lightbox?: boolean | undefined;
|
|
31
|
+
ariaLabel?: string | undefined;
|
|
32
|
+
}>(), { minSize: 120, aspect: 1, gap: "md", selectable: false, selected: () => [], lightbox: true, ariaLabel: "Images" });
|
|
33
|
+
|
|
34
|
+
const emit = defineEmits<{
|
|
35
|
+
(e: "update:selected", v: string[]): void;
|
|
36
|
+
(e: "open", index: number): void;
|
|
37
|
+
}>();
|
|
38
|
+
|
|
39
|
+
const open = ref(false);
|
|
40
|
+
const at = ref(0);
|
|
41
|
+
const shots = computed(() => props.images.map((i) => ({ src: i.src, alt: i.alt, caption: i.caption })));
|
|
42
|
+
|
|
43
|
+
function show(i: number): void {
|
|
44
|
+
emit("open", i);
|
|
45
|
+
if (!props.lightbox) return;
|
|
46
|
+
at.value = i;
|
|
47
|
+
open.value = true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function toggle(id: string, on: boolean): void {
|
|
51
|
+
emit("update:selected", on ? [...props.selected, id] : props.selected.filter((x) => x !== id));
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<div class="wp-image-grid">
|
|
57
|
+
<ul
|
|
58
|
+
class="wp-image-grid__list"
|
|
59
|
+
:data-gap="gap"
|
|
60
|
+
:aria-label="ariaLabel"
|
|
61
|
+
:style="{ '--_min': `${minSize}px`, '--_aspect': String(aspect) }"
|
|
62
|
+
>
|
|
63
|
+
<li
|
|
64
|
+
v-for="(img, i) in images"
|
|
65
|
+
:key="img.id"
|
|
66
|
+
class="wp-image-grid__tile"
|
|
67
|
+
:data-selected="(selectable && props.selected.includes(img.id)) || undefined"
|
|
68
|
+
>
|
|
69
|
+
<button
|
|
70
|
+
type="button"
|
|
71
|
+
class="wp-image-grid__open"
|
|
72
|
+
:aria-label="selectable ? `Open ${img.alt}` : img.alt"
|
|
73
|
+
@click="show(i)"
|
|
74
|
+
>
|
|
75
|
+
<img v-if="img.thumb || img.src" class="wp-image-grid__img" :src="img.thumb || img.src" alt="" loading="lazy">
|
|
76
|
+
<span v-else class="wp-image-grid__empty" aria-hidden="true" />
|
|
77
|
+
</button>
|
|
78
|
+
<WpCheck
|
|
79
|
+
v-if="selectable"
|
|
80
|
+
class="wp-image-grid__check"
|
|
81
|
+
:model-value="props.selected.includes(img.id)"
|
|
82
|
+
:aria-label="`Select ${img.alt}`"
|
|
83
|
+
@update:model-value="toggle(img.id, $event)"
|
|
84
|
+
/>
|
|
85
|
+
<span v-if="img.caption" class="wp-image-grid__caption">{{ img.caption }}</span>
|
|
86
|
+
</li>
|
|
87
|
+
</ul>
|
|
88
|
+
<Lightbox v-if="lightbox" v-model:open="open" v-model:index="at" :images="shots" />
|
|
89
|
+
</div>
|
|
90
|
+
</template>
|
|
91
|
+
|
|
92
|
+
<style scoped>
|
|
93
|
+
.wp-image-grid { min-width: 0; }
|
|
94
|
+
.wp-image-grid__list {
|
|
95
|
+
display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--_min), 1fr));
|
|
96
|
+
gap: var(--wp-space-3); margin: 0; padding: 0; list-style: none;
|
|
97
|
+
}
|
|
98
|
+
.wp-image-grid__list[data-gap="sm"] { gap: var(--wp-space-1); }
|
|
99
|
+
.wp-image-grid__tile { position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
100
|
+
.wp-image-grid__open {
|
|
101
|
+
display: block; width: 100%; aspect-ratio: var(--_aspect); padding: 0; overflow: hidden;
|
|
102
|
+
border: 1px solid var(--wp-border); border-radius: var(--wp-radius);
|
|
103
|
+
background: var(--wp-bg-2); cursor: zoom-in;
|
|
104
|
+
transition: border-color var(--wp-motion-hover), box-shadow var(--wp-motion-hover);
|
|
105
|
+
}
|
|
106
|
+
.wp-image-grid__open:hover { border-color: var(--wp-border-strong); }
|
|
107
|
+
.wp-image-grid__open:focus-visible { outline: none; border-color: var(--wp-border-focus); box-shadow: var(--wp-focus-ring); }
|
|
108
|
+
.wp-image-grid__tile[data-selected] .wp-image-grid__open { border-color: var(--wp-accent); box-shadow: 0 0 0 2px var(--wp-accent-glow); }
|
|
109
|
+
.wp-image-grid__img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
|
110
|
+
.wp-image-grid__empty {
|
|
111
|
+
display: block; width: 100%; height: 100%;
|
|
112
|
+
background: linear-gradient(90deg, var(--wp-bg-2) 0%, var(--wp-bg-3) 50%, var(--wp-bg-2) 100%);
|
|
113
|
+
background-size: 200% 100%; animation: wp-image-grid-shimmer var(--wp-motion-shimmer) infinite;
|
|
114
|
+
}
|
|
115
|
+
@keyframes wp-image-grid-shimmer { to { background-position: -200% 0; } }
|
|
116
|
+
.wp-image-grid__check { position: absolute; top: 6px; left: 6px; }
|
|
117
|
+
.wp-image-grid__caption {
|
|
118
|
+
overflow: hidden; color: var(--wp-text-muted); font: 400 var(--wp-text-xs)/1.3 var(--wp-font-sans);
|
|
119
|
+
text-overflow: ellipsis; white-space: nowrap;
|
|
120
|
+
}
|
|
121
|
+
@media (prefers-reduced-motion: reduce) {
|
|
122
|
+
.wp-image-grid__open { transition: none; }
|
|
123
|
+
.wp-image-grid__empty { animation: none; }
|
|
124
|
+
}
|
|
125
|
+
</style>
|
package/src/InlineEdit.vue
CHANGED
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* Inline edit: a name that turns into a text box where it stands. Click it
|
|
4
|
-
* (or focus it and press Enter or F2), type, then Enter or a click away
|
|
5
|
-
* saves and Escape puts the old text back. Works on the canvas and in the
|
|
6
|
-
* manager.
|
|
7
|
-
*
|
|
8
|
-
* <InlineEdit v-model="mod.name" label="Wildcard name" />
|
|
9
|
-
* <InlineEdit v-model="title" label="Chat title" :validate="(v) => taken(v) ? 'That name is taken' : null" />
|
|
10
|
-
*
|
|
11
|
-
* Read view is a button named "Rename <label>: <value>", with a pencil on
|
|
12
|
-
* hover and focus. An empty or invalid value keeps the box open with the
|
|
13
|
-
* message under it; `update:modelValue` only fires on a saved change.
|
|
14
|
-
*/
|
|
15
|
-
import { computed, nextTick, ref, useId } from "vue";
|
|
16
|
-
|
|
17
|
-
const props = withDefaults(defineProps<{
|
|
18
|
-
modelValue: string;
|
|
19
|
-
/** What is being renamed, e.g. "Wildcard name". */
|
|
20
|
-
label: string;
|
|
21
|
-
placeholder?: string | undefined;
|
|
22
|
-
/** Return a message to refuse the value, or null to take it. */
|
|
23
|
-
validate?: ((v: string) => string | null) | undefined;
|
|
24
|
-
/** Refuse an empty value. On by default. */
|
|
25
|
-
required?: boolean | undefined;
|
|
26
|
-
disabled?: boolean | undefined;
|
|
27
|
-
size?: "sm" | "md" | "lg" | undefined;
|
|
28
|
-
/** Trim spaces from both ends before saving. */
|
|
29
|
-
trim?: boolean | undefined;
|
|
30
|
-
maxlength?: number | undefined;
|
|
31
|
-
}>(), { placeholder: "Untitled", required: true, size: "md", trim: true, maxlength: undefined });
|
|
32
|
-
|
|
33
|
-
const emit = defineEmits<{
|
|
34
|
-
(e: "update:modelValue", v: string): void;
|
|
35
|
-
(e: "edit"): void;
|
|
36
|
-
(e: "cancel"): void;
|
|
37
|
-
}>();
|
|
38
|
-
|
|
39
|
-
const editing = ref(false);
|
|
40
|
-
const draft = ref("");
|
|
41
|
-
const error = ref<string | null>(null);
|
|
42
|
-
const inputEl = ref<HTMLInputElement | null>(null);
|
|
43
|
-
const readEl = ref<HTMLButtonElement | null>(null);
|
|
44
|
-
const errId = `wp-inline-edit-${useId()}`;
|
|
45
|
-
|
|
46
|
-
const shown = computed(() => props.modelValue || props.placeholder);
|
|
47
|
-
|
|
48
|
-
async function open(): Promise<void> {
|
|
49
|
-
if (props.disabled || editing.value) return;
|
|
50
|
-
draft.value = props.modelValue;
|
|
51
|
-
error.value = null;
|
|
52
|
-
editing.value = true;
|
|
53
|
-
emit("edit");
|
|
54
|
-
await nextTick();
|
|
55
|
-
inputEl.value?.focus();
|
|
56
|
-
inputEl.value?.select();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function check(v: string): string | null {
|
|
60
|
-
if (props.required && !v) return `${props.label} can't be empty`;
|
|
61
|
-
return props.validate?.(v) ?? null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function close(): Promise<void> {
|
|
65
|
-
editing.value = false;
|
|
66
|
-
error.value = null;
|
|
67
|
-
await nextTick();
|
|
68
|
-
readEl.value?.focus();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function save(refocus = true): void {
|
|
72
|
-
if (!editing.value) return;
|
|
73
|
-
const v = props.trim ? draft.value.trim() : draft.value;
|
|
74
|
-
const msg = check(v);
|
|
75
|
-
if (msg) {
|
|
76
|
-
error.value = msg;
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (v !== props.modelValue) emit("update:modelValue", v);
|
|
80
|
-
if (refocus) void close();
|
|
81
|
-
else { editing.value = false; error.value = null; }
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function cancel(): void {
|
|
85
|
-
if (!editing.value) return;
|
|
86
|
-
emit("cancel");
|
|
87
|
-
void close();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function onBlur(): void {
|
|
91
|
-
// A click away saves; a value that can't be saved is put back instead of
|
|
92
|
-
// leaving a box open that nobody is looking at.
|
|
93
|
-
if (!editing.value) return;
|
|
94
|
-
const v = props.trim ? draft.value.trim() : draft.value;
|
|
95
|
-
if (check(v)) { editing.value = false; error.value = null; emit("cancel"); return; }
|
|
96
|
-
save(false);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function onKeydown(ev: KeyboardEvent): void {
|
|
100
|
-
if (ev.key === "Enter") { ev.preventDefault(); save(); }
|
|
101
|
-
else if (ev.key === "Escape") { ev.preventDefault(); ev.stopPropagation(); cancel(); }
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function onReadKey(ev: KeyboardEvent): void {
|
|
105
|
-
if (ev.key === "F2") { ev.preventDefault(); void open(); }
|
|
106
|
-
}
|
|
107
|
-
</script>
|
|
108
|
-
|
|
109
|
-
<template>
|
|
110
|
-
<span class="wp-inline-edit" :data-size="size" :data-editing="editing || undefined">
|
|
111
|
-
<template v-if="editing">
|
|
112
|
-
<input
|
|
113
|
-
ref="inputEl"
|
|
114
|
-
v-model="draft"
|
|
115
|
-
class="wp-inline-edit__input"
|
|
116
|
-
type="text"
|
|
117
|
-
:aria-label="label"
|
|
118
|
-
:aria-invalid="error ? 'true' : undefined"
|
|
119
|
-
:aria-describedby="error ? errId : undefined"
|
|
120
|
-
:placeholder="placeholder"
|
|
121
|
-
:maxlength="maxlength"
|
|
122
|
-
@keydown="onKeydown"
|
|
123
|
-
@blur="onBlur"
|
|
124
|
-
>
|
|
125
|
-
<span v-if="error" :id="errId" class="wp-inline-edit__error" role="alert">{{ error }}</span>
|
|
126
|
-
</template>
|
|
127
|
-
<button
|
|
128
|
-
v-else
|
|
129
|
-
ref="readEl"
|
|
130
|
-
type="button"
|
|
131
|
-
class="wp-inline-edit__read"
|
|
132
|
-
:data-empty="!modelValue || undefined"
|
|
133
|
-
:aria-label="`Rename ${label}: ${modelValue || placeholder}`"
|
|
134
|
-
:disabled="disabled"
|
|
135
|
-
@click="open"
|
|
136
|
-
@keydown="onReadKey"
|
|
137
|
-
>
|
|
138
|
-
<span class="wp-inline-edit__text">{{ shown }}</span>
|
|
139
|
-
<i class="pi pi-pencil wp-inline-edit__pen" aria-hidden="true" />
|
|
140
|
-
</button>
|
|
141
|
-
</span>
|
|
142
|
-
</template>
|
|
143
|
-
|
|
144
|
-
<style scoped>
|
|
145
|
-
.wp-inline-edit {
|
|
146
|
-
--_h: var(--wp-control-h-md);
|
|
147
|
-
position: relative; display: inline-flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: 100%;
|
|
148
|
-
/* The padding of the hover box sits outside the text's line. */
|
|
149
|
-
margin-left: calc(var(--wp-space-3) * -1);
|
|
150
|
-
font: inherit; vertical-align: middle;
|
|
151
|
-
}
|
|
152
|
-
.wp-inline-edit[data-size="sm"] { --_h: var(--wp-control-h-sm); }
|
|
153
|
-
.wp-inline-edit[data-size="lg"] { --_h: var(--wp-control-h-lg); }
|
|
154
|
-
.wp-inline-edit__read, .wp-inline-edit__input {
|
|
155
|
-
box-sizing: border-box; height: var(--_h); margin: 0; min-width: 0;
|
|
156
|
-
padding: 0 var(--wp-space-3); border-radius: var(--wp-radius-sm);
|
|
157
|
-
font: inherit; color: var(--wp-text);
|
|
158
|
-
}
|
|
159
|
-
.wp-inline-edit__read {
|
|
160
|
-
display: inline-flex; align-items: center; gap: var(--wp-space-3); max-width: 100%;
|
|
161
|
-
border: 1px solid transparent; background: transparent; cursor: text; text-align: left;
|
|
162
|
-
transition: background var(--wp-motion-hover), border-color var(--wp-motion-hover);
|
|
163
|
-
}
|
|
164
|
-
.wp-inline-edit__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
165
|
-
.wp-inline-edit__read[data-empty] .wp-inline-edit__text { color: var(--wp-text-dim); font-style: italic; }
|
|
166
|
-
.wp-inline-edit__pen { flex: none; font-size: 0.8em; color: var(--wp-text-dim); opacity: 0; transition: opacity var(--wp-motion-hover); }
|
|
167
|
-
.wp-inline-edit__read:hover:not(:disabled) { background: var(--wp-row-hover); border-color: var(--wp-border-soft); }
|
|
168
|
-
.wp-inline-edit__read:hover .wp-inline-edit__pen, .wp-inline-edit__read:focus-visible .wp-inline-edit__pen { opacity: 1; }
|
|
169
|
-
.wp-inline-edit__read:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
|
|
170
|
-
.wp-inline-edit__read:disabled { cursor: default; }
|
|
171
|
-
.wp-inline-edit__input {
|
|
172
|
-
width: 100%; min-width: 12ch;
|
|
173
|
-
border: 1px solid var(--wp-border-focus); background: var(--wp-bg-1); outline: none;
|
|
174
|
-
box-shadow:
|
|
175
|
-
}
|
|
176
|
-
.wp-inline-edit__input[aria-invalid="true"] { border-color: var(--wp-error-border); box-shadow: 0 0 0 3px color-mix(in srgb, var(--wp-danger) 22%, transparent); }
|
|
177
|
-
.wp-inline-edit__error {
|
|
178
|
-
margin-top: 2px; color: var(--wp-error-text); font: 400 var(--wp-text-xs)/1.3 var(--wp-font-sans);
|
|
179
|
-
}
|
|
180
|
-
@media (prefers-reduced-motion: reduce) {
|
|
181
|
-
.wp-inline-edit__read, .wp-inline-edit__pen { transition: none; }
|
|
182
|
-
}
|
|
183
|
-
</style>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Inline edit: a name that turns into a text box where it stands. Click it
|
|
4
|
+
* (or focus it and press Enter or F2), type, then Enter or a click away
|
|
5
|
+
* saves and Escape puts the old text back. Works on the canvas and in the
|
|
6
|
+
* manager.
|
|
7
|
+
*
|
|
8
|
+
* <InlineEdit v-model="mod.name" label="Wildcard name" />
|
|
9
|
+
* <InlineEdit v-model="title" label="Chat title" :validate="(v) => taken(v) ? 'That name is taken' : null" />
|
|
10
|
+
*
|
|
11
|
+
* Read view is a button named "Rename <label>: <value>", with a pencil on
|
|
12
|
+
* hover and focus. An empty or invalid value keeps the box open with the
|
|
13
|
+
* message under it; `update:modelValue` only fires on a saved change.
|
|
14
|
+
*/
|
|
15
|
+
import { computed, nextTick, ref, useId } from "vue";
|
|
16
|
+
|
|
17
|
+
const props = withDefaults(defineProps<{
|
|
18
|
+
modelValue: string;
|
|
19
|
+
/** What is being renamed, e.g. "Wildcard name". */
|
|
20
|
+
label: string;
|
|
21
|
+
placeholder?: string | undefined;
|
|
22
|
+
/** Return a message to refuse the value, or null to take it. */
|
|
23
|
+
validate?: ((v: string) => string | null) | undefined;
|
|
24
|
+
/** Refuse an empty value. On by default. */
|
|
25
|
+
required?: boolean | undefined;
|
|
26
|
+
disabled?: boolean | undefined;
|
|
27
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
28
|
+
/** Trim spaces from both ends before saving. */
|
|
29
|
+
trim?: boolean | undefined;
|
|
30
|
+
maxlength?: number | undefined;
|
|
31
|
+
}>(), { placeholder: "Untitled", required: true, size: "md", trim: true, maxlength: undefined });
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
(e: "update:modelValue", v: string): void;
|
|
35
|
+
(e: "edit"): void;
|
|
36
|
+
(e: "cancel"): void;
|
|
37
|
+
}>();
|
|
38
|
+
|
|
39
|
+
const editing = ref(false);
|
|
40
|
+
const draft = ref("");
|
|
41
|
+
const error = ref<string | null>(null);
|
|
42
|
+
const inputEl = ref<HTMLInputElement | null>(null);
|
|
43
|
+
const readEl = ref<HTMLButtonElement | null>(null);
|
|
44
|
+
const errId = `wp-inline-edit-${useId()}`;
|
|
45
|
+
|
|
46
|
+
const shown = computed(() => props.modelValue || props.placeholder);
|
|
47
|
+
|
|
48
|
+
async function open(): Promise<void> {
|
|
49
|
+
if (props.disabled || editing.value) return;
|
|
50
|
+
draft.value = props.modelValue;
|
|
51
|
+
error.value = null;
|
|
52
|
+
editing.value = true;
|
|
53
|
+
emit("edit");
|
|
54
|
+
await nextTick();
|
|
55
|
+
inputEl.value?.focus();
|
|
56
|
+
inputEl.value?.select();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function check(v: string): string | null {
|
|
60
|
+
if (props.required && !v) return `${props.label} can't be empty`;
|
|
61
|
+
return props.validate?.(v) ?? null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function close(): Promise<void> {
|
|
65
|
+
editing.value = false;
|
|
66
|
+
error.value = null;
|
|
67
|
+
await nextTick();
|
|
68
|
+
readEl.value?.focus();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function save(refocus = true): void {
|
|
72
|
+
if (!editing.value) return;
|
|
73
|
+
const v = props.trim ? draft.value.trim() : draft.value;
|
|
74
|
+
const msg = check(v);
|
|
75
|
+
if (msg) {
|
|
76
|
+
error.value = msg;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (v !== props.modelValue) emit("update:modelValue", v);
|
|
80
|
+
if (refocus) void close();
|
|
81
|
+
else { editing.value = false; error.value = null; }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function cancel(): void {
|
|
85
|
+
if (!editing.value) return;
|
|
86
|
+
emit("cancel");
|
|
87
|
+
void close();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function onBlur(): void {
|
|
91
|
+
// A click away saves; a value that can't be saved is put back instead of
|
|
92
|
+
// leaving a box open that nobody is looking at.
|
|
93
|
+
if (!editing.value) return;
|
|
94
|
+
const v = props.trim ? draft.value.trim() : draft.value;
|
|
95
|
+
if (check(v)) { editing.value = false; error.value = null; emit("cancel"); return; }
|
|
96
|
+
save(false);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function onKeydown(ev: KeyboardEvent): void {
|
|
100
|
+
if (ev.key === "Enter") { ev.preventDefault(); save(); }
|
|
101
|
+
else if (ev.key === "Escape") { ev.preventDefault(); ev.stopPropagation(); cancel(); }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function onReadKey(ev: KeyboardEvent): void {
|
|
105
|
+
if (ev.key === "F2") { ev.preventDefault(); void open(); }
|
|
106
|
+
}
|
|
107
|
+
</script>
|
|
108
|
+
|
|
109
|
+
<template>
|
|
110
|
+
<span class="wp-inline-edit" :data-size="size" :data-editing="editing || undefined">
|
|
111
|
+
<template v-if="editing">
|
|
112
|
+
<input
|
|
113
|
+
ref="inputEl"
|
|
114
|
+
v-model="draft"
|
|
115
|
+
class="wp-inline-edit__input"
|
|
116
|
+
type="text"
|
|
117
|
+
:aria-label="label"
|
|
118
|
+
:aria-invalid="error ? 'true' : undefined"
|
|
119
|
+
:aria-describedby="error ? errId : undefined"
|
|
120
|
+
:placeholder="placeholder"
|
|
121
|
+
:maxlength="maxlength"
|
|
122
|
+
@keydown="onKeydown"
|
|
123
|
+
@blur="onBlur"
|
|
124
|
+
>
|
|
125
|
+
<span v-if="error" :id="errId" class="wp-inline-edit__error" role="alert">{{ error }}</span>
|
|
126
|
+
</template>
|
|
127
|
+
<button
|
|
128
|
+
v-else
|
|
129
|
+
ref="readEl"
|
|
130
|
+
type="button"
|
|
131
|
+
class="wp-inline-edit__read"
|
|
132
|
+
:data-empty="!modelValue || undefined"
|
|
133
|
+
:aria-label="`Rename ${label}: ${modelValue || placeholder}`"
|
|
134
|
+
:disabled="disabled"
|
|
135
|
+
@click="open"
|
|
136
|
+
@keydown="onReadKey"
|
|
137
|
+
>
|
|
138
|
+
<span class="wp-inline-edit__text">{{ shown }}</span>
|
|
139
|
+
<i class="pi pi-pencil wp-inline-edit__pen" aria-hidden="true" />
|
|
140
|
+
</button>
|
|
141
|
+
</span>
|
|
142
|
+
</template>
|
|
143
|
+
|
|
144
|
+
<style scoped>
|
|
145
|
+
.wp-inline-edit {
|
|
146
|
+
--_h: var(--wp-control-h-md);
|
|
147
|
+
position: relative; display: inline-flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: 100%;
|
|
148
|
+
/* The padding of the hover box sits outside the text's line. */
|
|
149
|
+
margin-left: calc(var(--wp-space-3) * -1);
|
|
150
|
+
font: inherit; vertical-align: middle;
|
|
151
|
+
}
|
|
152
|
+
.wp-inline-edit[data-size="sm"] { --_h: var(--wp-control-h-sm); }
|
|
153
|
+
.wp-inline-edit[data-size="lg"] { --_h: var(--wp-control-h-lg); }
|
|
154
|
+
.wp-inline-edit__read, .wp-inline-edit__input {
|
|
155
|
+
box-sizing: border-box; height: var(--_h); margin: 0; min-width: 0;
|
|
156
|
+
padding: 0 var(--wp-space-3); border-radius: var(--wp-radius-sm);
|
|
157
|
+
font: inherit; color: var(--wp-text);
|
|
158
|
+
}
|
|
159
|
+
.wp-inline-edit__read {
|
|
160
|
+
display: inline-flex; align-items: center; gap: var(--wp-space-3); max-width: 100%;
|
|
161
|
+
border: 1px solid transparent; background: transparent; cursor: text; text-align: left;
|
|
162
|
+
transition: background var(--wp-motion-hover), border-color var(--wp-motion-hover);
|
|
163
|
+
}
|
|
164
|
+
.wp-inline-edit__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
165
|
+
.wp-inline-edit__read[data-empty] .wp-inline-edit__text { color: var(--wp-text-dim); font-style: italic; }
|
|
166
|
+
.wp-inline-edit__pen { flex: none; font-size: 0.8em; color: var(--wp-text-dim); opacity: 0; transition: opacity var(--wp-motion-hover); }
|
|
167
|
+
.wp-inline-edit__read:hover:not(:disabled) { background: var(--wp-row-hover); border-color: var(--wp-border-soft); }
|
|
168
|
+
.wp-inline-edit__read:hover .wp-inline-edit__pen, .wp-inline-edit__read:focus-visible .wp-inline-edit__pen { opacity: 1; }
|
|
169
|
+
.wp-inline-edit__read:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
|
|
170
|
+
.wp-inline-edit__read:disabled { cursor: default; }
|
|
171
|
+
.wp-inline-edit__input {
|
|
172
|
+
width: 100%; min-width: 12ch;
|
|
173
|
+
border: 1px solid var(--wp-border-focus); background: var(--wp-bg-1); outline: none;
|
|
174
|
+
box-shadow: var(--wp-focus-ring);
|
|
175
|
+
}
|
|
176
|
+
.wp-inline-edit__input[aria-invalid="true"] { border-color: var(--wp-error-border); box-shadow: 0 0 0 3px color-mix(in srgb, var(--wp-danger) 22%, transparent); }
|
|
177
|
+
.wp-inline-edit__error {
|
|
178
|
+
margin-top: 2px; color: var(--wp-error-text); font: 400 var(--wp-text-xs)/1.3 var(--wp-font-sans);
|
|
179
|
+
}
|
|
180
|
+
@media (prefers-reduced-motion: reduce) {
|
|
181
|
+
.wp-inline-edit__read, .wp-inline-edit__pen { transition: none; }
|
|
182
|
+
}
|
|
183
|
+
</style>
|