@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,292 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T extends object">
|
|
2
|
+
/**
|
|
3
|
+
* DataTable: rows and columns with a sticky header, sortable columns, row
|
|
4
|
+
* selection, a loading state and an empty state. Built on the `.wp-table`
|
|
5
|
+
* classes so it matches the list pages.
|
|
6
|
+
*
|
|
7
|
+
* <DataTable
|
|
8
|
+
* v-model:sort="sort" v-model:selected="picked"
|
|
9
|
+
* :columns="[{ key: 'name', label: 'Name', sortable: true }, { key: 'uses', label: 'Uses', align: 'right', sortable: true }]"
|
|
10
|
+
* :rows="rows" row-key="id" selectable aria-label="Tags"
|
|
11
|
+
* >
|
|
12
|
+
* <template #cell-name="{ row }"><Chip>{{ row.name }}</Chip></template>
|
|
13
|
+
* <template #empty><EmptyState … /></template>
|
|
14
|
+
* </DataTable>
|
|
15
|
+
*
|
|
16
|
+
* Sorting (APG sortable table): each sortable header holds a button, and only
|
|
17
|
+
* the sorted column carries `aria-sort`. The table sorts its rows itself
|
|
18
|
+
* (by `sortValue`, else the cell value); with `manual-sort` it only reports
|
|
19
|
+
* the sort and the parent passes rows in order.
|
|
20
|
+
*
|
|
21
|
+
* `row-clickable` makes each row open something (a trace, a detail panel):
|
|
22
|
+
* rows take focus, and a click or Enter emits `row-click`. `active-key`
|
|
23
|
+
* marks the row that is open.
|
|
24
|
+
*/
|
|
25
|
+
import { computed } from "vue";
|
|
26
|
+
import Checkbox from "./Checkbox.vue";
|
|
27
|
+
|
|
28
|
+
export interface DataColumn<R> {
|
|
29
|
+
key: string;
|
|
30
|
+
label: string;
|
|
31
|
+
sortable?: boolean | undefined;
|
|
32
|
+
align?: "left" | "right" | "center" | undefined;
|
|
33
|
+
/** A CSS width for the column, e.g. `120px` or `30%`. */
|
|
34
|
+
width?: string | undefined;
|
|
35
|
+
/** Show the value in the mono font (counts, ids, seeds). */
|
|
36
|
+
mono?: boolean | undefined;
|
|
37
|
+
/** The value to sort by, when it isn't `row[key]`. */
|
|
38
|
+
sortValue?: (row: R) => string | number | null | undefined;
|
|
39
|
+
/** The direction a first click sorts in. */
|
|
40
|
+
firstDir?: "asc" | "desc" | undefined;
|
|
41
|
+
/** Hide the header text (an actions column); it still names the cells. */
|
|
42
|
+
hideLabel?: boolean | undefined;
|
|
43
|
+
/** A class on the column's header and cells. */
|
|
44
|
+
class?: string | undefined;
|
|
45
|
+
/** Extra attributes on the header cell (e.g. `data-ai-anchor`). */
|
|
46
|
+
headAttrs?: Record<string, string> | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface DataSort { key: string; dir: "asc" | "desc" }
|
|
50
|
+
|
|
51
|
+
const props = withDefaults(defineProps<{
|
|
52
|
+
columns: DataColumn<T>[];
|
|
53
|
+
rows: T[];
|
|
54
|
+
/** A field name, or a function, giving each row a stable key. */
|
|
55
|
+
rowKey: string | ((row: T) => string);
|
|
56
|
+
sort?: DataSort | null | undefined;
|
|
57
|
+
/** The parent sorts the rows; the table only reports clicks. */
|
|
58
|
+
manualSort?: boolean | undefined;
|
|
59
|
+
selectable?: boolean | undefined;
|
|
60
|
+
selected?: string[] | undefined;
|
|
61
|
+
loading?: boolean | undefined;
|
|
62
|
+
/** How many placeholder rows to draw while loading. */
|
|
63
|
+
loadingRows?: number | undefined;
|
|
64
|
+
stickyHead?: boolean | undefined;
|
|
65
|
+
/** Shown when there are no rows and no `#empty` slot. */
|
|
66
|
+
emptyText?: string | undefined;
|
|
67
|
+
ariaLabel?: string | undefined;
|
|
68
|
+
/** Extra attributes per row, e.g. `data-test`. */
|
|
69
|
+
rowAttrs?: ((row: T) => Record<string, string | undefined>) | undefined;
|
|
70
|
+
size?: "sm" | "md" | undefined;
|
|
71
|
+
/** Rows are focusable and emit `row-click` on click or Enter. */
|
|
72
|
+
rowClickable?: boolean | undefined;
|
|
73
|
+
/** The key of the row that is open, drawn highlighted. */
|
|
74
|
+
activeKey?: string | null | undefined;
|
|
75
|
+
}>(), {
|
|
76
|
+
sort: null,
|
|
77
|
+
selected: () => [],
|
|
78
|
+
loadingRows: 3,
|
|
79
|
+
stickyHead: true,
|
|
80
|
+
emptyText: "Nothing here yet.",
|
|
81
|
+
rowAttrs: undefined,
|
|
82
|
+
size: "md",
|
|
83
|
+
activeKey: null,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const emit = defineEmits<{
|
|
87
|
+
(e: "update:sort", s: DataSort | null): void;
|
|
88
|
+
(e: "update:selected", keys: string[]): void;
|
|
89
|
+
(e: "row-click", row: T): void;
|
|
90
|
+
}>();
|
|
91
|
+
|
|
92
|
+
const keyOf = (row: T): string =>
|
|
93
|
+
typeof props.rowKey === "function" ? props.rowKey(row) : String((row as Record<string, unknown>)[props.rowKey]);
|
|
94
|
+
|
|
95
|
+
const cell = (row: T, key: string): unknown => (row as Record<string, unknown>)[key];
|
|
96
|
+
|
|
97
|
+
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
|
98
|
+
|
|
99
|
+
const shown = computed<T[]>(() => {
|
|
100
|
+
const s = props.sort;
|
|
101
|
+
if (!s || props.manualSort) return props.rows;
|
|
102
|
+
const col = props.columns.find((c) => c.key === s.key);
|
|
103
|
+
if (!col) return props.rows;
|
|
104
|
+
const val = (r: T): unknown => (col.sortValue ? col.sortValue(r) : cell(r, col.key));
|
|
105
|
+
const sign = s.dir === "asc" ? 1 : -1;
|
|
106
|
+
return [...props.rows].sort((a, b) => {
|
|
107
|
+
const x = val(a);
|
|
108
|
+
const y = val(b);
|
|
109
|
+
// Blanks sort last whichever way the column goes.
|
|
110
|
+
const xb = x === null || x === undefined || x === "";
|
|
111
|
+
const yb = y === null || y === undefined || y === "";
|
|
112
|
+
if (xb || yb) return xb === yb ? 0 : xb ? 1 : -1;
|
|
113
|
+
if (typeof x === "number" && typeof y === "number") return (x - y) * sign;
|
|
114
|
+
return collator.compare(String(x), String(y)) * sign;
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
function ariaSort(c: DataColumn<T>): "ascending" | "descending" | undefined {
|
|
119
|
+
if (!c.sortable || props.sort?.key !== c.key) return undefined;
|
|
120
|
+
return props.sort.dir === "asc" ? "ascending" : "descending";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function sortBy(c: DataColumn<T>): void {
|
|
124
|
+
const now = props.sort;
|
|
125
|
+
const dir = now?.key === c.key ? (now.dir === "asc" ? "desc" : "asc") : (c.firstDir ?? "asc");
|
|
126
|
+
emit("update:sort", { key: c.key, dir });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const picked = computed(() => new Set(props.selected));
|
|
130
|
+
const allKeys = computed(() => shown.value.map(keyOf));
|
|
131
|
+
const allPicked = computed(() => allKeys.value.length > 0 && allKeys.value.every((k) => picked.value.has(k)));
|
|
132
|
+
const somePicked = computed(() => !allPicked.value && allKeys.value.some((k) => picked.value.has(k)));
|
|
133
|
+
|
|
134
|
+
function toggleAll(on: boolean): void {
|
|
135
|
+
const keys = new Set(props.selected);
|
|
136
|
+
for (const k of allKeys.value) {
|
|
137
|
+
if (on) keys.add(k);
|
|
138
|
+
else keys.delete(k);
|
|
139
|
+
}
|
|
140
|
+
emit("update:selected", [...keys]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function toggleRow(row: T, on: boolean): void {
|
|
144
|
+
const k = keyOf(row);
|
|
145
|
+
emit("update:selected", on ? [...props.selected.filter((x) => x !== k), k] : props.selected.filter((x) => x !== k));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const span = computed(() => props.columns.length + (props.selectable ? 1 : 0));
|
|
149
|
+
</script>
|
|
150
|
+
|
|
151
|
+
<template>
|
|
152
|
+
<div class="wp-table-wrap wp-data-table" :data-size="size">
|
|
153
|
+
<table
|
|
154
|
+
class="wp-table"
|
|
155
|
+
:class="{ 'wp-table--sticky-head': stickyHead }"
|
|
156
|
+
:aria-label="ariaLabel"
|
|
157
|
+
:aria-busy="loading || undefined"
|
|
158
|
+
>
|
|
159
|
+
<colgroup>
|
|
160
|
+
<col v-if="selectable" class="wp-data-table__check-col">
|
|
161
|
+
<col v-for="c in columns" :key="c.key" :style="c.width ? { width: c.width } : undefined">
|
|
162
|
+
</colgroup>
|
|
163
|
+
<thead>
|
|
164
|
+
<tr>
|
|
165
|
+
<th v-if="selectable" class="wp-data-table__check" scope="col">
|
|
166
|
+
<Checkbox
|
|
167
|
+
class="wp-checkbox--inline"
|
|
168
|
+
:model-value="allPicked"
|
|
169
|
+
:indeterminate="somePicked"
|
|
170
|
+
:disabled="loading || allKeys.length === 0"
|
|
171
|
+
aria-label="Select all rows"
|
|
172
|
+
@update:model-value="toggleAll"
|
|
173
|
+
/>
|
|
174
|
+
</th>
|
|
175
|
+
<th
|
|
176
|
+
v-for="c in columns"
|
|
177
|
+
:key="c.key"
|
|
178
|
+
scope="col"
|
|
179
|
+
v-bind="c.headAttrs ?? {}"
|
|
180
|
+
:class="c.class"
|
|
181
|
+
:aria-sort="ariaSort(c)"
|
|
182
|
+
:data-align="c.align"
|
|
183
|
+
>
|
|
184
|
+
<button
|
|
185
|
+
v-if="c.sortable"
|
|
186
|
+
type="button"
|
|
187
|
+
class="wp-data-table__sort"
|
|
188
|
+
:data-sorted="sort?.key === c.key ? sort.dir : undefined"
|
|
189
|
+
@click="sortBy(c)"
|
|
190
|
+
>
|
|
191
|
+
<slot :name="`head-${c.key}`" :column="c">{{ c.label }}</slot>
|
|
192
|
+
<i
|
|
193
|
+
class="pi wp-data-table__sort-icon"
|
|
194
|
+
:class="sort?.key === c.key ? (sort.dir === 'asc' ? 'pi-sort-up-fill' : 'pi-sort-down-fill') : 'pi-sort'"
|
|
195
|
+
aria-hidden="true"
|
|
196
|
+
/>
|
|
197
|
+
</button>
|
|
198
|
+
<span v-else-if="c.hideLabel" class="wp-data-table__sr">{{ c.label }}</span>
|
|
199
|
+
<slot v-else :name="`head-${c.key}`" :column="c">{{ c.label }}</slot>
|
|
200
|
+
</th>
|
|
201
|
+
</tr>
|
|
202
|
+
</thead>
|
|
203
|
+
<tbody>
|
|
204
|
+
<template v-if="loading && rows.length === 0">
|
|
205
|
+
<tr v-for="n in loadingRows" :key="`skel-${n}`" class="wp-row-skel" aria-hidden="true">
|
|
206
|
+
<td v-for="i in span" :key="i"><span class="wp-skel-bar" :style="{ width: `${40 + ((n * 17 + i * 23) % 50)}%` }" /></td>
|
|
207
|
+
</tr>
|
|
208
|
+
</template>
|
|
209
|
+
<tr v-else-if="shown.length === 0" class="wp-data-table__empty">
|
|
210
|
+
<td :colspan="span">
|
|
211
|
+
<slot name="empty"><span class="wp-dim">{{ emptyText }}</span></slot>
|
|
212
|
+
</td>
|
|
213
|
+
</tr>
|
|
214
|
+
<template v-else>
|
|
215
|
+
<tr
|
|
216
|
+
v-for="(row, index) in shown"
|
|
217
|
+
:key="keyOf(row)"
|
|
218
|
+
v-bind="rowAttrs ? rowAttrs(row) : {}"
|
|
219
|
+
:aria-selected="selectable ? picked.has(keyOf(row)) : undefined"
|
|
220
|
+
:data-selected="selectable && picked.has(keyOf(row)) ? 'true' : undefined"
|
|
221
|
+
:data-active="activeKey !== null && keyOf(row) === activeKey ? 'true' : undefined"
|
|
222
|
+
:data-clickable="rowClickable || undefined"
|
|
223
|
+
:tabindex="rowClickable ? 0 : undefined"
|
|
224
|
+
@click="rowClickable && emit('row-click', row)"
|
|
225
|
+
@keydown.enter="rowClickable && emit('row-click', row)"
|
|
226
|
+
>
|
|
227
|
+
<td v-if="selectable" class="wp-data-table__check" @click.stop>
|
|
228
|
+
<Checkbox
|
|
229
|
+
class="wp-checkbox--inline"
|
|
230
|
+
:model-value="picked.has(keyOf(row))"
|
|
231
|
+
aria-label="Select row"
|
|
232
|
+
@update:model-value="(on: boolean) => toggleRow(row, on)"
|
|
233
|
+
/>
|
|
234
|
+
</td>
|
|
235
|
+
<td
|
|
236
|
+
v-for="c in columns"
|
|
237
|
+
:key="c.key"
|
|
238
|
+
:data-align="c.align"
|
|
239
|
+
:class="[c.class, { 'wp-mono': c.mono }]"
|
|
240
|
+
>
|
|
241
|
+
<slot :name="`cell-${c.key}`" :row="row" :value="cell(row, c.key)" :index="index">{{ cell(row, c.key) ?? "" }}</slot>
|
|
242
|
+
</td>
|
|
243
|
+
</tr>
|
|
244
|
+
</template>
|
|
245
|
+
</tbody>
|
|
246
|
+
</table>
|
|
247
|
+
</div>
|
|
248
|
+
</template>
|
|
249
|
+
|
|
250
|
+
<style scoped>
|
|
251
|
+
.wp-data-table { overflow: auto; }
|
|
252
|
+
.wp-data-table th[data-align="right"], .wp-data-table td[data-align="right"] { text-align: right; }
|
|
253
|
+
.wp-data-table th[data-align="center"], .wp-data-table td[data-align="center"] { text-align: center; }
|
|
254
|
+
.wp-data-table th[data-align="right"] .wp-data-table__sort { flex-direction: row-reverse; }
|
|
255
|
+
.wp-data-table[data-size="sm"] :deep(thead th) { padding: 6px 10px; }
|
|
256
|
+
.wp-data-table[data-size="sm"] :deep(tbody td) { padding: 6px 10px; }
|
|
257
|
+
.wp-data-table__check-col { width: 40px; }
|
|
258
|
+
.wp-data-table__check { width: 40px; text-align: center; }
|
|
259
|
+
.wp-data-table__sort {
|
|
260
|
+
display: inline-flex;
|
|
261
|
+
align-items: center;
|
|
262
|
+
gap: 6px;
|
|
263
|
+
margin: -4px -6px;
|
|
264
|
+
padding: 4px 6px;
|
|
265
|
+
border: 0;
|
|
266
|
+
border-radius: var(--wp-radius-sm);
|
|
267
|
+
background: none;
|
|
268
|
+
color: inherit;
|
|
269
|
+
font: inherit;
|
|
270
|
+
letter-spacing: inherit;
|
|
271
|
+
text-transform: inherit;
|
|
272
|
+
cursor: pointer;
|
|
273
|
+
}
|
|
274
|
+
.wp-data-table__sort:hover { color: var(--wp-text); background: var(--wp-bg-3); }
|
|
275
|
+
.wp-data-table__sort:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
|
|
276
|
+
.wp-data-table__sort[data-sorted] { color: var(--wp-text); }
|
|
277
|
+
.wp-data-table__sort-icon { font-size: 10px; opacity: 0.5; }
|
|
278
|
+
.wp-data-table__sort[data-sorted] .wp-data-table__sort-icon { opacity: 1; color: var(--wp-accent-text); }
|
|
279
|
+
.wp-data-table tbody tr[data-selected="true"] td { background: var(--wp-row-active, var(--wp-row-hover)); }
|
|
280
|
+
.wp-data-table tbody tr[data-clickable] { cursor: pointer; }
|
|
281
|
+
.wp-data-table tbody tr[data-clickable]:focus-visible { outline: 2px solid var(--wp-border-focus); outline-offset: -2px; }
|
|
282
|
+
.wp-data-table tbody tr[data-active="true"] td { background: color-mix(in oklab, var(--wp-accent-500) 16%, transparent); }
|
|
283
|
+
.wp-data-table__empty td { padding: 20px 12px; text-align: center; }
|
|
284
|
+
.wp-data-table__sr {
|
|
285
|
+
position: absolute;
|
|
286
|
+
width: 1px;
|
|
287
|
+
height: 1px;
|
|
288
|
+
overflow: hidden;
|
|
289
|
+
clip-path: inset(50%);
|
|
290
|
+
white-space: nowrap;
|
|
291
|
+
}
|
|
292
|
+
</style>
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A date field: the button shows the picked day; it opens a month grid in
|
|
4
|
+
* a kit Popover. The value is a "YYYY-MM-DD" string (a calendar day, no
|
|
5
|
+
* time zone) or null.
|
|
6
|
+
*
|
|
7
|
+
* <DatePicker v-model="since" aria-label="Changed since" clearable />
|
|
8
|
+
* <DatePicker v-model="day" :min="firstRun" :max="today" />
|
|
9
|
+
*
|
|
10
|
+
* APG date picker dialog: the grid is one Tab stop; arrows move a day or a
|
|
11
|
+
* week, PageUp / PageDown a month (Shift: a year), Home / End to the start
|
|
12
|
+
* or end of the week, Enter or Space picks, Escape closes and gives focus
|
|
13
|
+
* back to the button. Days outside `min` / `max` can't be picked.
|
|
14
|
+
*/
|
|
15
|
+
import { computed, nextTick, ref, useId, watch } from "vue";
|
|
16
|
+
import Popover from "./Popover.vue";
|
|
17
|
+
import {
|
|
18
|
+
addDays, addMonths, compareYmd, fromDate, monthGrid, parseYmd, toYmd, weekdayNames, type Ymd,
|
|
19
|
+
} from "./calendar";
|
|
20
|
+
|
|
21
|
+
const props = withDefaults(defineProps<{
|
|
22
|
+
modelValue: string | null;
|
|
23
|
+
min?: string | undefined;
|
|
24
|
+
max?: string | undefined;
|
|
25
|
+
placeholder?: string | undefined;
|
|
26
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
27
|
+
disabled?: boolean | undefined;
|
|
28
|
+
invalid?: boolean | undefined;
|
|
29
|
+
ariaLabel?: string | undefined;
|
|
30
|
+
clearable?: boolean | undefined;
|
|
31
|
+
/** 0 = Sunday, 1 = Monday. */
|
|
32
|
+
weekStart?: 0 | 1 | undefined;
|
|
33
|
+
/** Language for month and day names; the browser's by default. */
|
|
34
|
+
locale?: string | undefined;
|
|
35
|
+
}>(), {
|
|
36
|
+
min: undefined, max: undefined, placeholder: "Pick a date", size: "md",
|
|
37
|
+
ariaLabel: "Date", weekStart: 1, locale: undefined,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const emit = defineEmits<{ (e: "update:modelValue", v: string | null): void }>();
|
|
41
|
+
|
|
42
|
+
const uid = useId();
|
|
43
|
+
const gridId = `wp-date-grid-${uid}`;
|
|
44
|
+
const titleId = `wp-date-title-${uid}`;
|
|
45
|
+
const open = ref(false);
|
|
46
|
+
const gridEl = ref<HTMLElement | null>(null);
|
|
47
|
+
|
|
48
|
+
const value = computed(() => parseYmd(props.modelValue));
|
|
49
|
+
const lo = computed(() => parseYmd(props.min));
|
|
50
|
+
const hi = computed(() => parseYmd(props.max));
|
|
51
|
+
const today = fromDate(new Date());
|
|
52
|
+
|
|
53
|
+
/** The day with the keyboard focus; the shown month follows it. */
|
|
54
|
+
const focus = ref<Ymd>(value.value ?? today);
|
|
55
|
+
const days = computed(() => monthGrid(focus.value.y, focus.value.m, props.weekStart));
|
|
56
|
+
const weeks = computed(() => Array.from({ length: 6 }, (_, w) => days.value.slice(w * 7, w * 7 + 7)));
|
|
57
|
+
const names = computed(() => weekdayNames(props.weekStart, props.locale));
|
|
58
|
+
const title = computed(() => new Date(focus.value.y, focus.value.m, 1)
|
|
59
|
+
.toLocaleDateString(props.locale, { month: "long", year: "numeric" }));
|
|
60
|
+
|
|
61
|
+
const shown = computed(() => (value.value
|
|
62
|
+
? new Date(value.value.y, value.value.m, value.value.d).toLocaleDateString(props.locale, { day: "numeric", month: "short", year: "numeric" })
|
|
63
|
+
: ""));
|
|
64
|
+
|
|
65
|
+
const same = (a: Ymd | null, b: Ymd): boolean => !!a && compareYmd(a, b) === 0;
|
|
66
|
+
const outOfRange = (v: Ymd): boolean => (!!lo.value && compareYmd(v, lo.value) < 0) || (!!hi.value && compareYmd(v, hi.value) > 0);
|
|
67
|
+
const clamp = (v: Ymd): Ymd => (lo.value && compareYmd(v, lo.value) < 0 ? lo.value : hi.value && compareYmd(v, hi.value) > 0 ? hi.value : v);
|
|
68
|
+
const long = (v: Ymd): string => new Date(v.y, v.m, v.d).toLocaleDateString(props.locale, { weekday: "long", day: "numeric", month: "long", year: "numeric" });
|
|
69
|
+
|
|
70
|
+
function focusDay(): void {
|
|
71
|
+
void nextTick(() => gridEl.value?.querySelector<HTMLElement>('[tabindex="0"]')?.focus());
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
watch(open, (v) => {
|
|
75
|
+
if (!v) return;
|
|
76
|
+
focus.value = clamp(value.value ?? today);
|
|
77
|
+
focusDay();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
function pick(v: Ymd): void {
|
|
81
|
+
if (outOfRange(v)) return;
|
|
82
|
+
emit("update:modelValue", toYmd(v));
|
|
83
|
+
open.value = false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function move(v: Ymd): void {
|
|
87
|
+
focus.value = clamp(v);
|
|
88
|
+
focusDay();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function shiftMonth(n: number): void {
|
|
92
|
+
move(addMonths(focus.value, n));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function onGridKey(ev: KeyboardEvent): void {
|
|
96
|
+
const f = focus.value;
|
|
97
|
+
const dow = (new Date(f.y, f.m, f.d).getDay() - props.weekStart + 7) % 7;
|
|
98
|
+
const to: Record<string, () => Ymd> = {
|
|
99
|
+
ArrowLeft: () => addDays(f, -1),
|
|
100
|
+
ArrowRight: () => addDays(f, 1),
|
|
101
|
+
ArrowUp: () => addDays(f, -7),
|
|
102
|
+
ArrowDown: () => addDays(f, 7),
|
|
103
|
+
Home: () => addDays(f, -dow),
|
|
104
|
+
End: () => addDays(f, 6 - dow),
|
|
105
|
+
PageUp: () => addMonths(f, ev.shiftKey ? -12 : -1),
|
|
106
|
+
PageDown: () => addMonths(f, ev.shiftKey ? 12 : 1),
|
|
107
|
+
};
|
|
108
|
+
if (to[ev.key]) {
|
|
109
|
+
ev.preventDefault();
|
|
110
|
+
move(to[ev.key]());
|
|
111
|
+
} else if (ev.key === "Enter" || ev.key === " ") {
|
|
112
|
+
ev.preventDefault();
|
|
113
|
+
pick(f);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function clear(): void {
|
|
118
|
+
emit("update:modelValue", null);
|
|
119
|
+
}
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<!-- Popover's autofocus prop is off: focus goes to the picked day, not the first button. -->
|
|
123
|
+
<!-- eslint-disable vuejs-accessibility/no-autofocus -->
|
|
124
|
+
<template>
|
|
125
|
+
<span class="wp-date" :data-size="size">
|
|
126
|
+
<Popover v-model:open="open" :autofocus="false" :label="ariaLabel">
|
|
127
|
+
<template #trigger="{ props: tp }">
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
class="wp-date__field"
|
|
131
|
+
:data-invalid="invalid || undefined"
|
|
132
|
+
:disabled="disabled"
|
|
133
|
+
:aria-label="shown ? `${ariaLabel}: ${shown}` : ariaLabel"
|
|
134
|
+
v-bind="tp"
|
|
135
|
+
>
|
|
136
|
+
<i class="pi pi-calendar wp-date__icon" aria-hidden="true" />
|
|
137
|
+
<span :class="shown ? 'wp-date__text' : 'wp-date__placeholder'">{{ shown || placeholder }}</span>
|
|
138
|
+
</button>
|
|
139
|
+
</template>
|
|
140
|
+
<div class="wp-date__panel">
|
|
141
|
+
<div class="wp-date__head">
|
|
142
|
+
<button type="button" class="wp-date__nav" aria-label="Previous month" @click="shiftMonth(-1)">
|
|
143
|
+
<i class="pi pi-chevron-left" aria-hidden="true" />
|
|
144
|
+
</button>
|
|
145
|
+
<span :id="titleId" class="wp-date__title" aria-live="polite">{{ title }}</span>
|
|
146
|
+
<button type="button" class="wp-date__nav" aria-label="Next month" @click="shiftMonth(1)">
|
|
147
|
+
<i class="pi pi-chevron-right" aria-hidden="true" />
|
|
148
|
+
</button>
|
|
149
|
+
</div>
|
|
150
|
+
<!-- The grid is reached through its days (roving tabindex); it only listens for their keys. -->
|
|
151
|
+
<!-- eslint-disable-next-line vuejs-accessibility/no-static-element-interactions, vuejs-accessibility/interactive-supports-focus -->
|
|
152
|
+
<table :id="gridId" ref="gridEl" class="wp-date__grid" role="grid" :aria-labelledby="titleId" @keydown="onGridKey">
|
|
153
|
+
<thead>
|
|
154
|
+
<tr>
|
|
155
|
+
<th v-for="n in names" :key="n.long" scope="col" :abbr="n.long">{{ n.short }}</th>
|
|
156
|
+
</tr>
|
|
157
|
+
</thead>
|
|
158
|
+
<tbody>
|
|
159
|
+
<tr v-for="(week, w) in weeks" :key="w">
|
|
160
|
+
<td
|
|
161
|
+
v-for="d in week"
|
|
162
|
+
:key="toYmd(d)"
|
|
163
|
+
class="wp-date__day"
|
|
164
|
+
:tabindex="same(focus, d) ? 0 : -1"
|
|
165
|
+
:aria-selected="same(value, d)"
|
|
166
|
+
:aria-disabled="outOfRange(d) || undefined"
|
|
167
|
+
:aria-label="long(d)"
|
|
168
|
+
:aria-current="same(today, d) ? 'date' : undefined"
|
|
169
|
+
:data-other="d.m !== focus.m || undefined"
|
|
170
|
+
:data-today="same(today, d) || undefined"
|
|
171
|
+
@click="pick(d)"
|
|
172
|
+
>{{ d.d }}</td>
|
|
173
|
+
</tr>
|
|
174
|
+
</tbody>
|
|
175
|
+
</table>
|
|
176
|
+
<div class="wp-date__foot">
|
|
177
|
+
<button type="button" class="wp-date__link" :disabled="outOfRange(today)" @click="pick(today)">Today</button>
|
|
178
|
+
<button v-if="clearable && modelValue" type="button" class="wp-date__link" @click="clear(); open = false">Clear</button>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
</Popover>
|
|
182
|
+
</span>
|
|
183
|
+
</template>
|
|
184
|
+
|
|
185
|
+
<style scoped>
|
|
186
|
+
.wp-date { display: inline-flex; --_h: var(--wp-control-h-md); }
|
|
187
|
+
.wp-date[data-size="sm"] { --_h: var(--wp-control-h-sm); }
|
|
188
|
+
.wp-date[data-size="lg"] { --_h: var(--wp-control-h-lg); }
|
|
189
|
+
.wp-date__field {
|
|
190
|
+
display: inline-flex; align-items: center; gap: var(--wp-space-2); box-sizing: border-box;
|
|
191
|
+
min-width: 150px; height: var(--_h); padding: 0 var(--wp-space-3);
|
|
192
|
+
border: 1px solid var(--wp-border); border-radius: var(--wp-radius);
|
|
193
|
+
background: var(--wp-bg-1); color: var(--wp-text); cursor: pointer;
|
|
194
|
+
font: 400 var(--wp-text-sm)/1 var(--wp-font-sans); text-align: left;
|
|
195
|
+
transition: border-color var(--wp-motion-hover), box-shadow var(--wp-motion-hover);
|
|
196
|
+
}
|
|
197
|
+
.wp-date[data-size="sm"] .wp-date__field { min-width: 120px; padding: 0 var(--wp-space-2); border-radius: var(--wp-radius-sm); font-size: var(--wp-text-xs); }
|
|
198
|
+
.wp-date__field:hover:not(:disabled) { border-color: var(--wp-border-strong); }
|
|
199
|
+
.wp-date__field:focus-visible { outline: none; border-color: var(--wp-border-focus); box-shadow: 0 0 0 3px var(--wp-focus-ring); }
|
|
200
|
+
.wp-date__field[data-invalid] { border-color: var(--wp-error-border); }
|
|
201
|
+
.wp-date__field:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
202
|
+
.wp-date__icon { color: var(--wp-text-muted); font-size: 12px; }
|
|
203
|
+
.wp-date__placeholder { color: var(--wp-text-dim); }
|
|
204
|
+
.wp-date__panel { display: flex; flex-direction: column; gap: var(--wp-space-2); }
|
|
205
|
+
.wp-date__head { display: flex; align-items: center; justify-content: space-between; gap: var(--wp-space-2); }
|
|
206
|
+
.wp-date__title { font-weight: 600; color: var(--wp-text); }
|
|
207
|
+
.wp-date__nav, .wp-date__link {
|
|
208
|
+
display: inline-grid; place-items: center; height: var(--wp-control-h-sm); min-width: var(--wp-control-h-sm);
|
|
209
|
+
padding: 0 var(--wp-space-2); border: 0; border-radius: var(--wp-radius-sm);
|
|
210
|
+
background: transparent; color: var(--wp-text-muted); cursor: pointer; font: inherit;
|
|
211
|
+
}
|
|
212
|
+
.wp-date__nav .pi { font-size: 11px; }
|
|
213
|
+
.wp-date__nav:hover, .wp-date__link:hover:not(:disabled) { background: var(--wp-row-hover); color: var(--wp-text); }
|
|
214
|
+
.wp-date__nav:focus-visible, .wp-date__link:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
|
|
215
|
+
.wp-date__link:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
216
|
+
.wp-date__grid { border-collapse: collapse; }
|
|
217
|
+
.wp-date__grid th {
|
|
218
|
+
width: 32px; height: 24px; color: var(--wp-text-muted); font-size: var(--wp-text-xs); font-weight: 500;
|
|
219
|
+
}
|
|
220
|
+
.wp-date__day {
|
|
221
|
+
width: 32px; height: 30px; padding: 0; text-align: center; border-radius: var(--wp-radius-sm);
|
|
222
|
+
color: var(--wp-text); font-variant-numeric: tabular-nums; cursor: pointer;
|
|
223
|
+
}
|
|
224
|
+
.wp-date__day[data-other] { color: var(--wp-text-dim); }
|
|
225
|
+
.wp-date__day[data-today] { box-shadow: inset 0 0 0 1px var(--wp-border-strong); }
|
|
226
|
+
.wp-date__day:hover { background: var(--wp-row-hover); }
|
|
227
|
+
.wp-date__day[aria-selected="true"] { background: var(--wp-accent); color: var(--wp-bg); }
|
|
228
|
+
.wp-date__day[aria-disabled="true"] { opacity: 0.35; cursor: not-allowed; background: transparent; text-decoration: line-through; }
|
|
229
|
+
.wp-date__day:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
|
|
230
|
+
.wp-date__foot { display: flex; justify-content: space-between; }
|
|
231
|
+
@media (prefers-reduced-motion: reduce) {
|
|
232
|
+
.wp-date__field { transition: none; }
|
|
233
|
+
}
|
|
234
|
+
</style>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Description list: label and value rows (an item's details, a step of the
|
|
4
|
+
* trace, model info). Labels line up in one column and values in the next;
|
|
5
|
+
* `stacked` puts each label above its value for a narrow panel. Works on the
|
|
6
|
+
* canvas and in the manager.
|
|
7
|
+
*
|
|
8
|
+
* <DescriptionList :items="[{ label: 'Family', value: 'SDXL' }, { label: 'ID', value: id, mono: true, copy: true }]" />
|
|
9
|
+
* <DescriptionList :items="rows"><template #value-status="{ item }"><Badge dot tone="success" text="Live" /></template></DescriptionList>
|
|
10
|
+
*
|
|
11
|
+
* A value that is empty draws a dim dash. A row with `key` can fill its value
|
|
12
|
+
* from the `value-<key>` slot.
|
|
13
|
+
*/
|
|
14
|
+
import CopyButton from "./CopyButton.vue";
|
|
15
|
+
|
|
16
|
+
export interface DescriptionItem {
|
|
17
|
+
label: string;
|
|
18
|
+
value?: string | number | null | undefined;
|
|
19
|
+
/** Names the `value-<key>` slot for this row. */
|
|
20
|
+
key?: string | undefined;
|
|
21
|
+
/** Draw the value in the mono font (ids, seeds, paths). */
|
|
22
|
+
mono?: boolean | undefined;
|
|
23
|
+
/** Add a copy button after the value. */
|
|
24
|
+
copy?: boolean | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
withDefaults(defineProps<{
|
|
28
|
+
items: DescriptionItem[];
|
|
29
|
+
layout?: "columns" | "stacked" | undefined;
|
|
30
|
+
size?: "sm" | "md" | undefined;
|
|
31
|
+
/** Lines between rows. */
|
|
32
|
+
divided?: boolean | undefined;
|
|
33
|
+
}>(), { layout: "columns", size: "md" });
|
|
34
|
+
|
|
35
|
+
const empty = (v: DescriptionItem["value"]): boolean => v === undefined || v === null || v === "";
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<template>
|
|
39
|
+
<dl class="wp-dl" :data-layout="layout" :data-size="size" :data-divided="divided || undefined">
|
|
40
|
+
<div v-for="(it, i) in items" :key="it.key ?? `${i}-${it.label}`" class="wp-dl__row">
|
|
41
|
+
<dt class="wp-dl__label">{{ it.label }}</dt>
|
|
42
|
+
<dd class="wp-dl__value" :data-mono="it.mono || undefined">
|
|
43
|
+
<slot v-if="it.key && $slots[`value-${it.key}`]" :name="`value-${it.key}`" :item="it" />
|
|
44
|
+
<template v-else-if="empty(it.value)"><span class="wp-dl__empty" aria-label="None">—</span></template>
|
|
45
|
+
<template v-else>
|
|
46
|
+
<span class="wp-dl__text">{{ it.value }}</span>
|
|
47
|
+
<CopyButton v-if="it.copy" :text="String(it.value)" :label="`Copy ${it.label}`" size="sm" class="wp-dl__copy" />
|
|
48
|
+
</template>
|
|
49
|
+
</dd>
|
|
50
|
+
</div>
|
|
51
|
+
</dl>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<style scoped>
|
|
55
|
+
.wp-dl {
|
|
56
|
+
display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: var(--wp-space-6); row-gap: var(--wp-space-3);
|
|
57
|
+
margin: 0; min-width: 0; font: 400 var(--wp-text-sm)/1.45 var(--wp-font-sans);
|
|
58
|
+
}
|
|
59
|
+
.wp-dl[data-size="sm"] { column-gap: var(--wp-space-5); row-gap: var(--wp-space-2); font-size: var(--wp-text-xs); }
|
|
60
|
+
.wp-dl__row { display: contents; }
|
|
61
|
+
.wp-dl__label { margin: 0; color: var(--wp-text-muted); }
|
|
62
|
+
.wp-dl__value { display: flex; align-items: center; gap: var(--wp-space-2); min-width: 0; margin: 0; color: var(--wp-text); }
|
|
63
|
+
.wp-dl__text { min-width: 0; overflow-wrap: anywhere; }
|
|
64
|
+
.wp-dl__value[data-mono] .wp-dl__text { font-family: var(--wp-font-mono); font-size: 0.95em; }
|
|
65
|
+
.wp-dl__empty { color: var(--wp-text-dim); }
|
|
66
|
+
.wp-dl__copy { margin: -4px 0; }
|
|
67
|
+
.wp-dl[data-divided] { row-gap: 0; }
|
|
68
|
+
.wp-dl[data-divided] .wp-dl__label, .wp-dl[data-divided] .wp-dl__value { padding: var(--wp-space-3) 0; border-top: 1px solid var(--wp-border-soft); }
|
|
69
|
+
.wp-dl[data-divided] .wp-dl__row:first-child > * { border-top: 0; }
|
|
70
|
+
.wp-dl[data-layout="stacked"] { grid-template-columns: minmax(0, 1fr); row-gap: var(--wp-space-4); }
|
|
71
|
+
.wp-dl[data-layout="stacked"] .wp-dl__row { display: flex; flex-direction: column; gap: 2px; }
|
|
72
|
+
.wp-dl[data-layout="stacked"] .wp-dl__label { font-size: var(--wp-text-xs); font-weight: 600; }
|
|
73
|
+
</style>
|
package/src/DiffView.vue
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Diff view: what changed between two texts, word by word (an option, a
|
|
4
|
+
* template) or line by line (a pack, a log). Removed text is struck through
|
|
5
|
+
* on red, added text is on green, and each change also says "removed" /
|
|
6
|
+
* "added" to screen readers, so colour is never the only sign. Works on the
|
|
7
|
+
* canvas and in the manager.
|
|
8
|
+
*
|
|
9
|
+
* <DiffView before="auburn hair, rim light" after="silver hair, rim light" />
|
|
10
|
+
* <DiffView :before="oldJson" :after="newJson" by="lines" layout="split" />
|
|
11
|
+
*
|
|
12
|
+
* `layout="split"` shows Before and After side by side. Very long texts fall
|
|
13
|
+
* back to "all removed, all added" rather than freeze the page.
|
|
14
|
+
*/
|
|
15
|
+
import { computed } from "vue";
|
|
16
|
+
import { diffText } from "./diff";
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(defineProps<{
|
|
19
|
+
before: string;
|
|
20
|
+
after: string;
|
|
21
|
+
by?: "words" | "lines" | undefined;
|
|
22
|
+
layout?: "inline" | "split" | undefined;
|
|
23
|
+
size?: "sm" | "md" | undefined;
|
|
24
|
+
/** Mono font, for code and JSON. */
|
|
25
|
+
mono?: boolean | undefined;
|
|
26
|
+
}>(), { by: "words", layout: "inline", size: "md" });
|
|
27
|
+
|
|
28
|
+
const parts = computed(() => diffText(props.before, props.after, props.by));
|
|
29
|
+
const counts = computed(() => ({
|
|
30
|
+
add: parts.value.filter((p) => p.kind === "add").length,
|
|
31
|
+
del: parts.value.filter((p) => p.kind === "del").length,
|
|
32
|
+
}));
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<template>
|
|
36
|
+
<div class="wp-diff" :data-size="size" :data-layout="layout" :data-by="by" :data-mono="mono || by === 'lines' || undefined">
|
|
37
|
+
<p v-if="!counts.add && !counts.del" class="wp-diff__same">No changes</p>
|
|
38
|
+
<template v-else-if="layout === 'inline'">
|
|
39
|
+
<div class="wp-diff__text"><template v-for="(p, i) in parts" :key="i"><span v-if="p.kind === 'same'">{{ p.text }}</span><del v-else-if="p.kind === 'del'" class="wp-diff__del"><span class="wp-diff__sr">removed: </span>{{ p.text }}</del><ins v-else class="wp-diff__add"><span class="wp-diff__sr">added: </span>{{ p.text }}</ins></template></div>
|
|
40
|
+
</template>
|
|
41
|
+
<div v-else class="wp-diff__split">
|
|
42
|
+
<section class="wp-diff__side" aria-label="Before">
|
|
43
|
+
<span class="wp-diff__side-label" aria-hidden="true">Before</span>
|
|
44
|
+
<div class="wp-diff__text"><template v-for="(p, i) in parts" :key="i"><span v-if="p.kind === 'same'">{{ p.text }}</span><del v-else-if="p.kind === 'del'" class="wp-diff__del"><span class="wp-diff__sr">removed: </span>{{ p.text }}</del></template></div>
|
|
45
|
+
</section>
|
|
46
|
+
<section class="wp-diff__side" aria-label="After">
|
|
47
|
+
<span class="wp-diff__side-label" aria-hidden="true">After</span>
|
|
48
|
+
<div class="wp-diff__text"><template v-for="(p, i) in parts" :key="i"><span v-if="p.kind === 'same'">{{ p.text }}</span><ins v-else-if="p.kind === 'add'" class="wp-diff__add"><span class="wp-diff__sr">added: </span>{{ p.text }}</ins></template></div>
|
|
49
|
+
</section>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<style scoped>
|
|
55
|
+
.wp-diff { min-width: 0; color: var(--wp-text); font: 400 var(--wp-text-sm)/1.6 var(--wp-font-sans); }
|
|
56
|
+
.wp-diff[data-size="sm"] { font-size: var(--wp-text-xs); }
|
|
57
|
+
.wp-diff[data-mono] { font-family: var(--wp-font-mono); }
|
|
58
|
+
.wp-diff__text { white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
59
|
+
.wp-diff__del, .wp-diff__add { border-radius: min(3px, var(--wp-radius-cap, 999px)); padding: 0 1px; text-decoration-thickness: 1px; }
|
|
60
|
+
.wp-diff__del { background: color-mix(in srgb, var(--wp-danger) 16%, transparent); color: var(--wp-danger-text); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--wp-danger) 70%, transparent); }
|
|
61
|
+
.wp-diff__add { background: color-mix(in srgb, var(--wp-success) 18%, transparent); color: var(--wp-text); text-decoration: none; box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--wp-success) 60%, transparent); }
|
|
62
|
+
.wp-diff[data-by="lines"] .wp-diff__del, .wp-diff[data-by="lines"] .wp-diff__add { display: block; padding: 0 var(--wp-space-2); border-radius: 0; }
|
|
63
|
+
.wp-diff__split { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--wp-space-4); }
|
|
64
|
+
.wp-diff__side { min-width: 0; padding: var(--wp-space-3) var(--wp-space-4); border: 1px solid var(--wp-border); border-radius: var(--wp-radius); background: var(--wp-bg-1); }
|
|
65
|
+
.wp-diff__side-label { display: block; margin-bottom: var(--wp-space-2); color: var(--wp-text-dim); font: 600 var(--wp-text-xs)/1 var(--wp-font-sans); letter-spacing: 0.06em; text-transform: uppercase; }
|
|
66
|
+
.wp-diff__same { margin: 0; color: var(--wp-text-dim); font-style: italic; }
|
|
67
|
+
.wp-diff__sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
|
|
68
|
+
</style>
|