@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
|
@@ -0,0 +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: 0 0 0 3px 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>
|
|
@@ -0,0 +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: 0 0 0 3px 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>
|
package/src/Input.vue
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Text field. Number fields use WpNumber (`WpNumber.vue`)
|
|
4
|
+
* and search boxes use SearchInput; this one no longer has a number mode.
|
|
5
|
+
*/
|
|
6
|
+
import { computed } from "vue";
|
|
7
|
+
import Icon from "./Icon.vue";
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
modelValue: string;
|
|
11
|
+
type?: "text" | "email" | "url" | "password" | "tel" | undefined;
|
|
12
|
+
placeholder?: string | undefined;
|
|
13
|
+
disabled?: boolean | undefined;
|
|
14
|
+
/** Shown but not editable: dimmer fill, no focus ring, a lock icon. */
|
|
15
|
+
readonly?: boolean | undefined;
|
|
16
|
+
error?: boolean | undefined;
|
|
17
|
+
/** Height on the control scale: sm 24 / md 32 / lg 40. */
|
|
18
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
19
|
+
/** Icon before the text (a search glass). Drawn inline, no box. */
|
|
20
|
+
icon?: string | undefined;
|
|
21
|
+
/** Text before the value, e.g. `$` for a variable name. */
|
|
22
|
+
prefix?: string | undefined;
|
|
23
|
+
/** Text after the value, e.g. a unit. */
|
|
24
|
+
suffix?: string | undefined;
|
|
25
|
+
id?: string | undefined;
|
|
26
|
+
ariaLabel?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
29
|
+
type: "text",
|
|
30
|
+
size: "md",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
(e: "update:modelValue", v: string): void;
|
|
35
|
+
(e: "blur", evt: FocusEvent): void;
|
|
36
|
+
(e: "focus", evt: FocusEvent): void;
|
|
37
|
+
}>();
|
|
38
|
+
|
|
39
|
+
const inputClasses = computed(() => [
|
|
40
|
+
"wp-input",
|
|
41
|
+
props.size === "sm" && "wp-input--sm",
|
|
42
|
+
props.size === "lg" && "wp-input--lg",
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
const wrapped = computed(() => Boolean(props.icon || props.prefix || props.suffix || props.readonly));
|
|
46
|
+
const groupClasses = computed(() => [
|
|
47
|
+
"wp-input-group",
|
|
48
|
+
props.size === "sm" && "wp-input-group--sm",
|
|
49
|
+
props.size === "lg" && "wp-input-group--lg",
|
|
50
|
+
props.readonly && "wp-input-group--readonly",
|
|
51
|
+
props.disabled && "wp-input-group--disabled",
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
function onInput(e: Event) {
|
|
55
|
+
emit("update:modelValue", (e.target as HTMLInputElement).value);
|
|
56
|
+
}
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<div v-if="wrapped" :class="groupClasses" :aria-invalid="error || undefined">
|
|
61
|
+
<span v-if="icon" class="wp-input-group__icon" aria-hidden="true">
|
|
62
|
+
<Icon :name="icon" />
|
|
63
|
+
</span>
|
|
64
|
+
<span v-if="prefix" class="wp-input-group__affix wp-input-group__affix--prefix" aria-hidden="true">{{ prefix }}</span>
|
|
65
|
+
<input
|
|
66
|
+
:id="id"
|
|
67
|
+
:class="inputClasses"
|
|
68
|
+
:type="type"
|
|
69
|
+
:value="modelValue"
|
|
70
|
+
:placeholder="placeholder"
|
|
71
|
+
:disabled="disabled"
|
|
72
|
+
:readonly="readonly"
|
|
73
|
+
:aria-label="ariaLabel"
|
|
74
|
+
:aria-invalid="error || undefined"
|
|
75
|
+
@input="onInput"
|
|
76
|
+
@blur="(e) => emit('blur', e)"
|
|
77
|
+
@focus="(e) => emit('focus', e)"
|
|
78
|
+
/>
|
|
79
|
+
<span v-if="suffix" class="wp-input-group__affix wp-input-group__affix--suffix" aria-hidden="true">{{ suffix }}</span>
|
|
80
|
+
<span v-if="readonly" class="wp-input-group__lock" aria-hidden="true">
|
|
81
|
+
<Icon name="pi-lock" :size="11" />
|
|
82
|
+
</span>
|
|
83
|
+
</div>
|
|
84
|
+
<input
|
|
85
|
+
v-else
|
|
86
|
+
:id="id"
|
|
87
|
+
:class="inputClasses"
|
|
88
|
+
:type="type"
|
|
89
|
+
:value="modelValue"
|
|
90
|
+
:placeholder="placeholder"
|
|
91
|
+
:disabled="disabled"
|
|
92
|
+
:readonly="readonly"
|
|
93
|
+
:aria-label="ariaLabel"
|
|
94
|
+
:aria-invalid="error || undefined"
|
|
95
|
+
@input="onInput"
|
|
96
|
+
@blur="(e) => emit('blur', e)"
|
|
97
|
+
@focus="(e) => emit('focus', e)"
|
|
98
|
+
/>
|
|
99
|
+
</template>
|
package/src/Kbd.vue
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Kbd: a keyboard shortcut drawn as keys. `Mod` reads ⌘ on a Mac and Ctrl
|
|
4
|
+
* elsewhere (from `platform-keys.ts`), so one string fits everyone. Works on
|
|
5
|
+
* the canvas and in the manager.
|
|
6
|
+
*
|
|
7
|
+
* <Kbd keys="Mod+K" />
|
|
8
|
+
* <Kbd :keys="['Shift', 'Enter']" />
|
|
9
|
+
*
|
|
10
|
+
* Screen readers hear the whole chord once ("Control plus K"); the key caps
|
|
11
|
+
* themselves are hidden from them.
|
|
12
|
+
*/
|
|
13
|
+
import { computed } from "vue";
|
|
14
|
+
import { isApplePlatform } from "./platform-keys";
|
|
15
|
+
|
|
16
|
+
const props = withDefaults(defineProps<{
|
|
17
|
+
/** "Mod+Shift+P" or ["Mod", "Shift", "P"]. */
|
|
18
|
+
keys: string | string[];
|
|
19
|
+
size?: "sm" | "md" | undefined;
|
|
20
|
+
}>(), { size: "md" });
|
|
21
|
+
|
|
22
|
+
const MAC: Record<string, string> = { Mod: "⌘", Ctrl: "⌃", Alt: "⌥", Shift: "⇧", Enter: "↵" };
|
|
23
|
+
const SPOKEN: Record<string, string> = {
|
|
24
|
+
"⌘": "Command", Ctrl: "Control", "⌃": "Control", Alt: "Alt", "⌥": "Option", Shift: "Shift", "⇧": "Shift",
|
|
25
|
+
Enter: "Enter", "↵": "Enter", Esc: "Escape", "↑": "Up", "↓": "Down", "←": "Left", "→": "Right",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const caps = computed(() => {
|
|
29
|
+
const list = Array.isArray(props.keys) ? props.keys : props.keys.split(/\+(?!$)/);
|
|
30
|
+
const mac = isApplePlatform();
|
|
31
|
+
return list.map((k) => k.trim()).filter(Boolean).map((k) => (k === "Mod" ? (mac ? "⌘" : "Ctrl") : mac ? MAC[k] ?? k : k));
|
|
32
|
+
});
|
|
33
|
+
const spoken = computed(() => caps.value.map((k) => SPOKEN[k] ?? k).join(" plus "));
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<template>
|
|
37
|
+
<kbd class="wp-kbd-keys" :data-size="size" :aria-label="spoken">
|
|
38
|
+
<template v-for="(k, i) in caps" :key="i">
|
|
39
|
+
<span v-if="i > 0" class="wp-kbd-keys__plus" aria-hidden="true">+</span>
|
|
40
|
+
<kbd class="wp-kbd-keys__cap" aria-hidden="true">{{ k }}</kbd>
|
|
41
|
+
</template>
|
|
42
|
+
</kbd>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<style scoped>
|
|
46
|
+
.wp-kbd-keys { display: inline-flex; align-items: center; gap: 2px; font: inherit; vertical-align: baseline; }
|
|
47
|
+
.wp-kbd-keys__plus { color: var(--wp-text-dim); font-size: var(--wp-text-xs); }
|
|
48
|
+
.wp-kbd-keys__cap {
|
|
49
|
+
display: inline-grid; place-items: center; box-sizing: border-box;
|
|
50
|
+
min-width: 20px; height: 20px; padding: 0 5px;
|
|
51
|
+
border: 1px solid var(--wp-border-strong); border-bottom-width: 2px; border-radius: var(--wp-radius-sm);
|
|
52
|
+
background: var(--wp-bg-2); color: var(--wp-text-muted);
|
|
53
|
+
font: 500 11px/1 var(--wp-font-mono); white-space: nowrap;
|
|
54
|
+
}
|
|
55
|
+
.wp-kbd-keys[data-size="sm"] .wp-kbd-keys__cap { min-width: 16px; height: 16px; padding: 0 3px; font-size: 10px; }
|
|
56
|
+
</style>
|
package/src/KindChip.vue
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The module-type chip: `wildcard`, `fixed_values`, `combine`, `constraint`,
|
|
4
|
+
* `derivation` or `bundle`, in the kind colour the extension uses for that
|
|
5
|
+
* type everywhere (`--wp-kind-*`; bundles are slate, `--wp-bundle-default`).
|
|
6
|
+
*
|
|
7
|
+
* <KindChip kind="module" subtype="wildcard" />
|
|
8
|
+
* <KindChip kind="bundle" />
|
|
9
|
+
*
|
|
10
|
+
* A module with no subtype reads as `fixed_values`, the oldest type.
|
|
11
|
+
*/
|
|
12
|
+
import { computed } from "vue";
|
|
13
|
+
|
|
14
|
+
export type KindChipSubtype = "fixed_values" | "combine" | "wildcard" | "constraint" | "derivation";
|
|
15
|
+
|
|
16
|
+
const props = defineProps<{
|
|
17
|
+
kind: "module" | "bundle";
|
|
18
|
+
/** A `"bundle"` subtype reads as a bundle too (some APIs report it so). */
|
|
19
|
+
subtype?: KindChipSubtype | "bundle" | null | undefined;
|
|
20
|
+
}>();
|
|
21
|
+
|
|
22
|
+
const type = computed(() => (props.kind === "bundle" ? "bundle" : (props.subtype ?? "fixed_values")));
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<span class="wp-kind-chip" :data-type="type">{{ type }}</span>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<style scoped>
|
|
30
|
+
.wp-kind-chip {
|
|
31
|
+
--kind-chip-c: var(--wp-text-muted);
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 5px;
|
|
35
|
+
padding: 3px 9px;
|
|
36
|
+
border-radius: var(--wp-radius-cap, 999px);
|
|
37
|
+
font-family: var(--wp-font-mono);
|
|
38
|
+
font-size: 11px;
|
|
39
|
+
font-weight: 500;
|
|
40
|
+
line-height: 14px;
|
|
41
|
+
letter-spacing: -0.01em;
|
|
42
|
+
white-space: nowrap;
|
|
43
|
+
color: var(--kind-chip-c);
|
|
44
|
+
background: color-mix(in oklab, var(--kind-chip-c) 14%, transparent);
|
|
45
|
+
border: 1px solid color-mix(in oklab, var(--kind-chip-c) 38%, transparent);
|
|
46
|
+
}
|
|
47
|
+
.wp-kind-chip[data-type="fixed_values"] { --kind-chip-c: var(--wp-kind-fixed); }
|
|
48
|
+
.wp-kind-chip[data-type="combine"] { --kind-chip-c: var(--wp-kind-combine); }
|
|
49
|
+
.wp-kind-chip[data-type="wildcard"] { --kind-chip-c: var(--wp-kind-wildcard); }
|
|
50
|
+
.wp-kind-chip[data-type="constraint"] { --kind-chip-c: var(--wp-kind-constraint); }
|
|
51
|
+
.wp-kind-chip[data-type="derivation"] { --kind-chip-c: var(--wp-kind-derivation); }
|
|
52
|
+
.wp-kind-chip[data-type="bundle"] { --kind-chip-c: var(--wp-bundle-default); }
|
|
53
|
+
</style>
|