@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/diff.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A small word or line diff for DiffView: the longest common subsequence of
|
|
3
|
-
* the two token lists, then the runs that are the same, added or removed.
|
|
4
|
-
* Inputs past `limit` tokens on either side fall back to "all removed, all
|
|
5
|
-
* added", which keeps the table (n × m) small.
|
|
6
|
-
*/
|
|
7
|
-
export type DiffPart = { kind: "same" | "add" | "del"; text: string };
|
|
8
|
-
|
|
9
|
-
/** Words with the spaces after them, so joining the parts gives the text back. */
|
|
10
|
-
export function tokenize(text: string, by: "words" | "lines"): string[] {
|
|
11
|
-
if (!text) return [];
|
|
12
|
-
return by === "lines" ? text.split(/(?<=\n)/) : text.match(/\s+|[^\s]+/g) ?? [];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function diffTokens(a: string[], b: string[], limit = 2000): DiffPart[] {
|
|
16
|
-
if (a.length > limit || b.length > limit) {
|
|
17
|
-
return merge([...a.map((t) => ({ kind: "del" as const, text: t })), ...b.map((t) => ({ kind: "add" as const, text: t }))]);
|
|
18
|
-
}
|
|
19
|
-
const n = a.length; const m = b.length;
|
|
20
|
-
const lcs: number[][] = Array.from({ length: n + 1 }, () => new Array<number>(m + 1).fill(0));
|
|
21
|
-
for (let i = n - 1; i >= 0; i--) {
|
|
22
|
-
for (let j = m - 1; j >= 0; j--) {
|
|
23
|
-
lcs[i][j] = a[i] === b[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const out: DiffPart[] = [];
|
|
27
|
-
let i = 0; let j = 0;
|
|
28
|
-
while (i < n && j < m) {
|
|
29
|
-
if (a[i] === b[j]) { out.push({ kind: "same", text: a[i] }); i++; j++; }
|
|
30
|
-
else if (lcs[i + 1][j] >= lcs[i][j + 1]) { out.push({ kind: "del", text: a[i] }); i++; }
|
|
31
|
-
else { out.push({ kind: "add", text: b[j] }); j++; }
|
|
32
|
-
}
|
|
33
|
-
while (i < n) out.push({ kind: "del", text: a[i++] });
|
|
34
|
-
while (j < m) out.push({ kind: "add", text: b[j++] });
|
|
35
|
-
return merge(out);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Join neighbours of one kind into one part. */
|
|
39
|
-
function merge(parts: DiffPart[]): DiffPart[] {
|
|
40
|
-
const out: DiffPart[] = [];
|
|
41
|
-
for (const p of parts) {
|
|
42
|
-
const last = out[out.length - 1];
|
|
43
|
-
if (last && last.kind === p.kind) last.text += p.text;
|
|
44
|
-
else out.push({ ...p });
|
|
45
|
-
}
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function diffText(before: string, after: string, by: "words" | "lines" = "words"): DiffPart[] {
|
|
50
|
-
return diffTokens(tokenize(before, by), tokenize(after, by));
|
|
51
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* A small word or line diff for DiffView: the longest common subsequence of
|
|
3
|
+
* the two token lists, then the runs that are the same, added or removed.
|
|
4
|
+
* Inputs past `limit` tokens on either side fall back to "all removed, all
|
|
5
|
+
* added", which keeps the table (n × m) small.
|
|
6
|
+
*/
|
|
7
|
+
export type DiffPart = { kind: "same" | "add" | "del"; text: string };
|
|
8
|
+
|
|
9
|
+
/** Words with the spaces after them, so joining the parts gives the text back. */
|
|
10
|
+
export function tokenize(text: string, by: "words" | "lines"): string[] {
|
|
11
|
+
if (!text) return [];
|
|
12
|
+
return by === "lines" ? text.split(/(?<=\n)/) : text.match(/\s+|[^\s]+/g) ?? [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function diffTokens(a: string[], b: string[], limit = 2000): DiffPart[] {
|
|
16
|
+
if (a.length > limit || b.length > limit) {
|
|
17
|
+
return merge([...a.map((t) => ({ kind: "del" as const, text: t })), ...b.map((t) => ({ kind: "add" as const, text: t }))]);
|
|
18
|
+
}
|
|
19
|
+
const n = a.length; const m = b.length;
|
|
20
|
+
const lcs: number[][] = Array.from({ length: n + 1 }, () => new Array<number>(m + 1).fill(0));
|
|
21
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
22
|
+
for (let j = m - 1; j >= 0; j--) {
|
|
23
|
+
lcs[i][j] = a[i] === b[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const out: DiffPart[] = [];
|
|
27
|
+
let i = 0; let j = 0;
|
|
28
|
+
while (i < n && j < m) {
|
|
29
|
+
if (a[i] === b[j]) { out.push({ kind: "same", text: a[i] }); i++; j++; }
|
|
30
|
+
else if (lcs[i + 1][j] >= lcs[i][j + 1]) { out.push({ kind: "del", text: a[i] }); i++; }
|
|
31
|
+
else { out.push({ kind: "add", text: b[j] }); j++; }
|
|
32
|
+
}
|
|
33
|
+
while (i < n) out.push({ kind: "del", text: a[i++] });
|
|
34
|
+
while (j < m) out.push({ kind: "add", text: b[j++] });
|
|
35
|
+
return merge(out);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Join neighbours of one kind into one part. */
|
|
39
|
+
function merge(parts: DiffPart[]): DiffPart[] {
|
|
40
|
+
const out: DiffPart[] = [];
|
|
41
|
+
for (const p of parts) {
|
|
42
|
+
const last = out[out.length - 1];
|
|
43
|
+
if (last && last.kind === p.kind) last.text += p.text;
|
|
44
|
+
else out.push({ ...p });
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function diffText(before: string, after: string, by: "words" | "lines" = "words"): DiffPart[] {
|
|
50
|
+
return diffTokens(tokenize(before, by), tokenize(after, by));
|
|
51
|
+
}
|
package/src/drop-zone.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File checks for DropZone: does a file (or a dragged item, whose name is
|
|
3
|
-
* not known until the drop) match an `accept` list like the file input's
|
|
4
|
-
* ("image/*,.txt,application/json")?
|
|
5
|
-
*/
|
|
6
|
-
export function acceptList(accept: string | undefined): string[] {
|
|
7
|
-
return (accept ?? "").split(",").map((a) => a.trim().toLowerCase()).filter(Boolean);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function typeMatches(type: string, rule: string): boolean {
|
|
11
|
-
if (!type) return false;
|
|
12
|
-
const t = type.toLowerCase();
|
|
13
|
-
return rule.endsWith("/*") ? t.startsWith(rule.slice(0, -1)) : t === rule;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** A dropped file: by its extension or its type. An empty list takes all. */
|
|
17
|
-
export function fileAccepted(file: { name: string; type: string }, accept: string | undefined): boolean {
|
|
18
|
-
const rules = acceptList(accept);
|
|
19
|
-
if (!rules.length) return true;
|
|
20
|
-
const name = file.name.toLowerCase();
|
|
21
|
-
return rules.some((r) => (r.startsWith(".") ? name.endsWith(r) : typeMatches(file.type, r)));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A dragged item, before the drop: only its type is known. Returns false
|
|
26
|
-
* only when it surely won't be taken; an item with no type, or a list that
|
|
27
|
-
* names extensions (which we can't see yet), gets the benefit of the doubt.
|
|
28
|
-
*/
|
|
29
|
-
export function dragItemMaybeAccepted(type: string, accept: string | undefined): boolean {
|
|
30
|
-
const rules = acceptList(accept);
|
|
31
|
-
if (!rules.length || !type) return true;
|
|
32
|
-
if (rules.some((r) => r.startsWith("."))) return true;
|
|
33
|
-
return rules.some((r) => typeMatches(type, r));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** "2.4 MB", "820 KB". */
|
|
37
|
-
export function formatBytes(n: number): string {
|
|
38
|
-
if (n >= 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(n >= 10 * 1024 * 1024 ? 0 : 1)} MB`;
|
|
39
|
-
if (n >= 1024) return `${Math.round(n / 1024)} KB`;
|
|
40
|
-
return `${n} B`;
|
|
41
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* File checks for DropZone: does a file (or a dragged item, whose name is
|
|
3
|
+
* not known until the drop) match an `accept` list like the file input's
|
|
4
|
+
* ("image/*,.txt,application/json")?
|
|
5
|
+
*/
|
|
6
|
+
export function acceptList(accept: string | undefined): string[] {
|
|
7
|
+
return (accept ?? "").split(",").map((a) => a.trim().toLowerCase()).filter(Boolean);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function typeMatches(type: string, rule: string): boolean {
|
|
11
|
+
if (!type) return false;
|
|
12
|
+
const t = type.toLowerCase();
|
|
13
|
+
return rule.endsWith("/*") ? t.startsWith(rule.slice(0, -1)) : t === rule;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A dropped file: by its extension or its type. An empty list takes all. */
|
|
17
|
+
export function fileAccepted(file: { name: string; type: string }, accept: string | undefined): boolean {
|
|
18
|
+
const rules = acceptList(accept);
|
|
19
|
+
if (!rules.length) return true;
|
|
20
|
+
const name = file.name.toLowerCase();
|
|
21
|
+
return rules.some((r) => (r.startsWith(".") ? name.endsWith(r) : typeMatches(file.type, r)));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A dragged item, before the drop: only its type is known. Returns false
|
|
26
|
+
* only when it surely won't be taken; an item with no type, or a list that
|
|
27
|
+
* names extensions (which we can't see yet), gets the benefit of the doubt.
|
|
28
|
+
*/
|
|
29
|
+
export function dragItemMaybeAccepted(type: string, accept: string | undefined): boolean {
|
|
30
|
+
const rules = acceptList(accept);
|
|
31
|
+
if (!rules.length || !type) return true;
|
|
32
|
+
if (rules.some((r) => r.startsWith("."))) return true;
|
|
33
|
+
return rules.some((r) => typeMatches(type, r));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** "2.4 MB", "820 KB". */
|
|
37
|
+
export function formatBytes(n: number): string {
|
|
38
|
+
if (n >= 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(n >= 10 * 1024 * 1024 ? 0 : 1)} MB`;
|
|
39
|
+
if (n >= 1024) return `${Math.round(n / 1024)} KB`;
|
|
40
|
+
return `${n} B`;
|
|
41
|
+
}
|
package/src/field.css
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* Field box: the one look of every text-like field in the kit (Input,
|
|
2
|
+
* Textarea and Select draw the same box from theme/tokens.css' `.wp-input`;
|
|
3
|
+
* SearchInput, WpNumber, Combobox, TagInput, ColorField and WpSelect pull this
|
|
4
|
+
* sheet in scoped). It reads only the SHARED_TOKENS names, so a field wears
|
|
5
|
+
* the manager colours on a page and the canvas colours in a node.
|
|
6
|
+
*
|
|
7
|
+
* <div class="wp-field-box wp-field-box--sm" …>
|
|
8
|
+
*
|
|
9
|
+
* Heights follow the control scale (sm 24 / md 32 / lg 40) as a min-height,
|
|
10
|
+
* so a field that wraps (Combobox, TagInput chips) can grow; a single-line
|
|
11
|
+
* field sets `height: var(--wp-field-h)` itself. A piece keeps its own
|
|
12
|
+
* layout (display, padding, gap) and font family (WpNumber and ColorField
|
|
13
|
+
* are mono); the box sets everything you see around it.
|
|
14
|
+
*
|
|
15
|
+
* States: hover (stronger border), focus-within (accent border + focus
|
|
16
|
+
* ring), invalid (`.is-invalid`, `[data-invalid]` or `aria-invalid`),
|
|
17
|
+
* disabled (`.is-disabled`, `[data-disabled]` or `:disabled`: 45%).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
.wp-field-box {
|
|
21
|
+
--wp-field-h: var(--wp-control-h-md);
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
min-height: var(--wp-field-h);
|
|
24
|
+
background: var(--wp-bg-2);
|
|
25
|
+
color: var(--wp-text);
|
|
26
|
+
border: 1px solid var(--wp-border);
|
|
27
|
+
border-radius: var(--wp-radius-sm);
|
|
28
|
+
font-size: 12.5px;
|
|
29
|
+
transition: border-color var(--wp-motion-quick), box-shadow var(--wp-motion-quick), background var(--wp-motion-quick);
|
|
30
|
+
}
|
|
31
|
+
.wp-field-box--sm { --wp-field-h: var(--wp-control-h-sm); font-size: 12px; }
|
|
32
|
+
.wp-field-box--lg { --wp-field-h: var(--wp-control-h-lg); font-size: 13.5px; }
|
|
33
|
+
|
|
34
|
+
.wp-field-box:hover { border-color: var(--wp-border-strong); }
|
|
35
|
+
.wp-field-box:focus-within,
|
|
36
|
+
.wp-field-box:focus-visible {
|
|
37
|
+
outline: none;
|
|
38
|
+
border-color: var(--wp-accent-500);
|
|
39
|
+
box-shadow: var(--wp-focus-ring);
|
|
40
|
+
background: var(--wp-bg-1);
|
|
41
|
+
}
|
|
42
|
+
.wp-field-box.is-invalid,
|
|
43
|
+
.wp-field-box[data-invalid],
|
|
44
|
+
.wp-field-box[aria-invalid="true"] { border-color: var(--wp-error-border); }
|
|
45
|
+
.wp-field-box.is-disabled,
|
|
46
|
+
.wp-field-box[data-disabled],
|
|
47
|
+
.wp-field-box:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
48
|
+
.wp-field-box.is-disabled:hover,
|
|
49
|
+
.wp-field-box[data-disabled]:hover,
|
|
50
|
+
.wp-field-box:disabled:hover { border-color: var(--wp-border); }
|