@deepseek-ai/dsh-client-ui-primitives 0.2.2-rc.5 → 0.2.3-alpha.2
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/README.i18n.yaml +12 -12
- package/README.md +21 -10
- package/README.zh.md +21 -10
- package/lib/index.js +2961 -868
- package/lib/index.js.map +1 -1
- package/lib/types/Checkbox.d.ts.map +1 -1
- package/lib/types/Checkbox.js.map +1 -1
- package/lib/types/HoverCard.d.ts +5 -3
- package/lib/types/HoverCard.d.ts.map +1 -1
- package/lib/types/HoverCard.js.map +1 -1
- package/lib/types/ImageLightbox.d.ts.map +1 -1
- package/lib/types/ImageLightbox.js.map +1 -1
- package/lib/types/LinkIcon.js.map +1 -1
- package/lib/types/Marquee.d.ts +35 -0
- package/lib/types/Marquee.d.ts.map +1 -0
- package/lib/types/Marquee.js.map +1 -0
- package/lib/types/Menu.d.ts +24 -5
- package/lib/types/Menu.d.ts.map +1 -1
- package/lib/types/Menu.js.map +1 -1
- package/lib/types/PermissionIcon.d.ts.map +1 -1
- package/lib/types/PermissionIcon.js.map +1 -1
- package/lib/types/SearchField.d.ts +18 -0
- package/lib/types/SearchField.d.ts.map +1 -0
- package/lib/types/SearchField.js.map +1 -0
- package/lib/types/Switch.d.ts +5 -1
- package/lib/types/Switch.d.ts.map +1 -1
- package/lib/types/Switch.js.map +1 -1
- package/lib/types/TerminalBlock.js.map +1 -1
- package/lib/types/clipboard.d.ts +4 -2
- package/lib/types/clipboard.d.ts.map +1 -1
- package/lib/types/clipboard.js.map +1 -1
- package/lib/types/icons/artwork.d.ts +16 -0
- package/lib/types/icons/artwork.d.ts.map +1 -1
- package/lib/types/icons/artwork.js.map +1 -1
- package/lib/types/icons/index.d.ts +21 -5
- package/lib/types/icons/index.d.ts.map +1 -1
- package/lib/types/icons/index.js.map +1 -1
- package/lib/types/icons/props.d.ts +1 -1
- package/lib/types/icons/props.d.ts.map +1 -1
- package/lib/types/icons/shared-artwork.js.map +1 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/input-modality.d.ts +5 -0
- package/lib/types/input-modality.d.ts.map +1 -1
- package/lib/types/input-modality.js.map +1 -1
- package/lib/types/markdown/cjkFriendlyStrong.d.ts +4 -1
- package/lib/types/markdown/cjkFriendlyStrong.d.ts.map +1 -1
- package/lib/types/markdown/cjkFriendlyStrong.js.map +1 -1
- package/lib/types/useMenuSubmenu.d.ts +1 -0
- package/lib/types/useMenuSubmenu.d.ts.map +1 -1
- package/lib/types/useMenuSubmenu.js.map +1 -1
- package/lib/types/useModalLayer.d.ts +3 -1
- package/lib/types/useModalLayer.d.ts.map +1 -1
- package/lib/types/useModalLayer.js.map +1 -1
- package/package.json +8 -8
- package/src/Checkbox.module.css +43 -2
- package/src/Checkbox.tsx +7 -3
- package/src/HoverCard.module.css +42 -0
- package/src/HoverCard.tsx +53 -49
- package/src/ImageLightbox.tsx +2 -1
- package/src/Input.module.css +7 -1
- package/src/LinkIcon.tsx +9 -9
- package/src/Marquee.module.css +47 -0
- package/src/Marquee.tsx +109 -0
- package/src/Menu.module.css +34 -4
- package/src/Menu.tsx +138 -35
- package/src/Modal.module.css +8 -4
- package/src/PermissionIcon.tsx +10 -12
- package/src/Pill.module.css +11 -1
- package/src/RiskConfirmation.module.css +6 -1
- package/src/SearchField.module.css +74 -0
- package/src/SearchField.tsx +37 -0
- package/src/SegmentedTabs.module.css +4 -10
- package/src/Switch.tsx +7 -1
- package/src/TerminalBlock.tsx +4 -4
- package/src/clipboard.ts +29 -15
- package/src/icons/artwork.ts +89 -85
- package/src/icons/index.tsx +29 -5
- package/src/icons/props.ts +1 -1
- package/src/icons/shared-artwork.tsx +14 -14
- package/src/index.ts +2 -1
- package/src/input-modality.ts +13 -5
- package/src/markdown/MarkdownText.module.css +21 -10
- package/src/markdown/cjkFriendlyStrong.ts +9 -2
- package/src/useMenuSubmenu.ts +6 -3
- package/src/useModalLayer.ts +5 -2
- package/lib/AnimatedRows.module.css +0 -7
- package/lib/Button.module.css +0 -84
- package/lib/Checkbox.module.css +0 -28
- package/lib/CodeCard.module.css +0 -85
- package/lib/CommandText.module.css +0 -12
- package/lib/ConnectionIndicator.module.css +0 -120
- package/lib/DetailDocument.module.css +0 -67
- package/lib/DiffBlock.module.css +0 -82
- package/lib/DisclosureRow.module.css +0 -115
- package/lib/FileTypeIcon.module.css +0 -50
- package/lib/HoverCard.module.css +0 -108
- package/lib/ImageLightbox.module.css +0 -54
- package/lib/ImagePreview.module.css +0 -24
- package/lib/InlineEditor.module.css +0 -23
- package/lib/Input.module.css +0 -38
- package/lib/JsonTree.module.css +0 -371
- package/lib/Menu.module.css +0 -443
- package/lib/MenuGroup.module.css +0 -37
- package/lib/MenuSurface.module.css +0 -65
- package/lib/Modal.module.css +0 -147
- package/lib/PathLabel.module.css +0 -28
- package/lib/Pill.module.css +0 -30
- package/lib/QuotePreview.module.css +0 -138
- package/lib/ReadBlock.module.css +0 -45
- package/lib/RiskConfirmation.module.css +0 -47
- package/lib/RowDragPreview.module.css +0 -12
- package/lib/SearchBlock.module.css +0 -114
- package/lib/SegmentedControl.module.css +0 -81
- package/lib/SegmentedTabs.module.css +0 -77
- package/lib/ShortcutKeys.module.css +0 -33
- package/lib/StateDot.module.css +0 -100
- package/lib/Switch.module.css +0 -49
- package/lib/Tag.module.css +0 -57
- package/lib/TerminalBlock.module.css +0 -207
- package/lib/TextShimmer.module.css +0 -88
- package/lib/Toast.module.css +0 -102
- package/lib/Tooltip.module.css +0 -68
- package/lib/UserMessageBubble.module.css +0 -11
- package/lib/WebBlock.module.css +0 -153
- package/lib/ZoomControls.module.css +0 -54
- package/lib/markdown/CodeBlock.module.css +0 -209
- package/lib/markdown/JsonBlock.module.css +0 -34
- package/lib/markdown/MarkdownText.module.css +0 -511
- package/lib/settings-form/SettingsForm.module.css +0 -53
- package/lib/settings-form/fields.module.css +0 -153
- package/lib/types/rank-by-name.d.ts +0 -22
- package/lib/types/rank-by-name.d.ts.map +0 -1
- package/lib/types/rank-by-name.js.map +0 -1
- package/lib/user-text.module.css +0 -46
- package/src/rank-by-name.ts +0 -93
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared ranking for `/` menu candidates: the query must be a
|
|
3
|
-
* case-insensitive ordered subsequence of the candidate name or, when the
|
|
4
|
-
* candidate carries one, of its display label (a localized title). Prefix
|
|
5
|
-
* hits rank first, then the strongest alignment score over either key, then
|
|
6
|
-
* the source order of the input. Decision record:
|
|
7
|
-
* .agents/notes/archived/feature/2026-08-04-web-slash-command-fuzzy-discovery.md
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Rank named items by a menu query.
|
|
11
|
-
* @param items - candidates in source order (a host catalog, then client
|
|
12
|
-
* contributions); an item's optional `label` is a second search key beside
|
|
13
|
-
* its name.
|
|
14
|
-
* @param rawQuery - the text typed after the trigger, matched case-insensitively.
|
|
15
|
-
* @returns the matching items: prefix hits first, then by alignment score,
|
|
16
|
-
* then in source order. The input list itself for an empty query.
|
|
17
|
-
*/
|
|
18
|
-
export declare function rankByName<T extends {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly label?: string;
|
|
21
|
-
}>(items: readonly T[], rawQuery: string): readonly T[];
|
|
22
|
-
//# sourceMappingURL=rank-by-name.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rank-by-name.d.ts","sourceRoot":"","sources":["../../src/rank-by-name.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAqDH;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EACrF,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,QAAQ,EAAE,MAAM,GACf,SAAS,CAAC,EAAE,CAo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,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;IACrG,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AACxC,CAAC"}
|
package/lib/user-text.module.css
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/* Inline projection of sent user text: plain runs and reference chips flow in
|
|
2
|
-
the consumer's own line box (bubble or queue row); nothing here is block.
|
|
3
|
-
White-space policy stays with the consumer: the bubble wraps with pre-wrap,
|
|
4
|
-
the queue preview keeps its single nowrap/ellipsis line. */
|
|
5
|
-
|
|
6
|
-
.plainRun {
|
|
7
|
-
font-size: inherit;
|
|
8
|
-
line-height: inherit;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.refChip {
|
|
12
|
-
/* Plain inline, NOT inline-flex: a flex container takes its baseline from
|
|
13
|
-
its first flex item — the icon svg, which has no text baseline — so the
|
|
14
|
-
chip's label rode ~3px above the surrounding text in both surfaces. An
|
|
15
|
-
inline chip shares the consumer's baseline by construction. */
|
|
16
|
-
display: inline;
|
|
17
|
-
max-width: 100%;
|
|
18
|
-
margin: 0 2px;
|
|
19
|
-
color: var(--dsw-alias-state-business-primary);
|
|
20
|
-
font-weight: 500;
|
|
21
|
-
white-space: inherit;
|
|
22
|
-
overflow-wrap: anywhere;
|
|
23
|
-
text-align: inherit;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/* Skill and command tokens read as code: the theme's code family at the
|
|
27
|
-
consumer's own size and line height, so the chip sits on the bubble line
|
|
28
|
-
like the plain runs around it. `@` chips keep the body face — a file or
|
|
29
|
-
session name is a label, not code. */
|
|
30
|
-
.slashChip {
|
|
31
|
-
font-family: var(--dsw-font-markdown-code-font-family);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/* Inline reference glyphs (always ReferenceIcon svgs) ride the consumer's own
|
|
35
|
-
font: 1em keeps the glyph at the text's size in the bubble (14px + user
|
|
36
|
-
setting), the queue preview's fixed 13px line, and any future consumer — a
|
|
37
|
-
px+delta size followed only the bubble axis and left the glyph oversized in
|
|
38
|
-
the queue row. */
|
|
39
|
-
.refIcon {
|
|
40
|
-
width: 1em;
|
|
41
|
-
height: 1em;
|
|
42
|
-
margin-right: 4px;
|
|
43
|
-
/* Optical centering against the text: drops the glyph below the baseline by
|
|
44
|
-
a font-relative amount, so it holds across the font axis. */
|
|
45
|
-
vertical-align: -0.125em;
|
|
46
|
-
}
|
package/src/rank-by-name.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared ranking for `/` menu candidates: the query must be a
|
|
3
|
-
* case-insensitive ordered subsequence of the candidate name or, when the
|
|
4
|
-
* candidate carries one, of its display label (a localized title). Prefix
|
|
5
|
-
* hits rank first, then the strongest alignment score over either key, then
|
|
6
|
-
* the source order of the input. Decision record:
|
|
7
|
-
* .agents/notes/archived/feature/2026-08-04-web-slash-command-fuzzy-discovery.md
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/** One match with its stable source position. */
|
|
11
|
-
interface Ranked<T> {
|
|
12
|
-
readonly item: T
|
|
13
|
-
readonly index: number
|
|
14
|
-
readonly prefix: boolean
|
|
15
|
-
readonly score: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Extra weight for name starts and separator boundaries. */
|
|
19
|
-
function boundaryBonus(name: string, index: number): number {
|
|
20
|
-
return index === 0 || name.charAt(index - 1) === '-' || name.charAt(index - 1) === '_' ? 8 : 0
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Score the strongest ordered-subsequence alignment in O(name × query).
|
|
25
|
-
* Boundary and adjacent matches earn weight; skipped and leading characters
|
|
26
|
-
* cost weight. Undefined when the query is not a subsequence of the name.
|
|
27
|
-
*/
|
|
28
|
-
function alignmentScore(name: string, query: string): number | undefined {
|
|
29
|
-
if (query.length > name.length) return undefined
|
|
30
|
-
const noMatch = Number.NEGATIVE_INFINITY
|
|
31
|
-
let previous = Array<number>(name.length).fill(noMatch)
|
|
32
|
-
for (let index = 0; index < name.length; index++) {
|
|
33
|
-
if (name.charAt(index) === query.charAt(0)) previous[index] = 1 + boundaryBonus(name, index) - index
|
|
34
|
-
}
|
|
35
|
-
for (let queryIndex = 1; queryIndex < query.length; queryIndex++) {
|
|
36
|
-
const current = Array<number>(name.length).fill(noMatch)
|
|
37
|
-
// Sweep the previous row once: `left` is its score one character back
|
|
38
|
-
// (the adjacent continuation), `leftLeft` two back (the earliest gapped one).
|
|
39
|
-
let left = noMatch
|
|
40
|
-
let leftLeft = noMatch
|
|
41
|
-
let bestGapped = noMatch
|
|
42
|
-
for (const [index, prior] of previous.entries()) {
|
|
43
|
-
if (leftLeft !== noMatch) bestGapped = Math.max(bestGapped, leftLeft + index - 2)
|
|
44
|
-
if (name.charAt(index) === query.charAt(queryIndex)) {
|
|
45
|
-
const bonus = 1 + boundaryBonus(name, index)
|
|
46
|
-
let score = noMatch
|
|
47
|
-
if (left !== noMatch) score = left + bonus + 4
|
|
48
|
-
if (bestGapped !== noMatch) score = Math.max(score, bestGapped + bonus + 1 - index)
|
|
49
|
-
current[index] = score
|
|
50
|
-
}
|
|
51
|
-
leftLeft = left
|
|
52
|
-
left = prior
|
|
53
|
-
}
|
|
54
|
-
previous = current
|
|
55
|
-
}
|
|
56
|
-
let best = noMatch
|
|
57
|
-
for (const score of previous) best = Math.max(best, score)
|
|
58
|
-
return best === noMatch ? undefined : best
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Rank named items by a menu query.
|
|
63
|
-
* @param items - candidates in source order (a host catalog, then client
|
|
64
|
-
* contributions); an item's optional `label` is a second search key beside
|
|
65
|
-
* its name.
|
|
66
|
-
* @param rawQuery - the text typed after the trigger, matched case-insensitively.
|
|
67
|
-
* @returns the matching items: prefix hits first, then by alignment score,
|
|
68
|
-
* then in source order. The input list itself for an empty query.
|
|
69
|
-
*/
|
|
70
|
-
export function rankByName<T extends { readonly name: string; readonly label?: string }>(
|
|
71
|
-
items: readonly T[],
|
|
72
|
-
rawQuery: string,
|
|
73
|
-
): readonly T[] {
|
|
74
|
-
const query = rawQuery.toLowerCase()
|
|
75
|
-
if (query === '') return items
|
|
76
|
-
const ranked: Ranked<T>[] = []
|
|
77
|
-
items.forEach((item, index) => {
|
|
78
|
-
const keys = item.label === undefined ? [item.name] : [item.name, item.label]
|
|
79
|
-
let prefix = false
|
|
80
|
-
let score: number | undefined
|
|
81
|
-
for (const key of keys) {
|
|
82
|
-
const lower = key.toLowerCase()
|
|
83
|
-
const keyScore = alignmentScore(lower, query)
|
|
84
|
-
if (keyScore === undefined) continue
|
|
85
|
-
prefix ||= lower.startsWith(query)
|
|
86
|
-
score = score === undefined ? keyScore : Math.max(score, keyScore)
|
|
87
|
-
}
|
|
88
|
-
if (score !== undefined) ranked.push({ item, index, prefix, score })
|
|
89
|
-
})
|
|
90
|
-
ranked.sort((left, right) =>
|
|
91
|
-
Number(right.prefix) - Number(left.prefix) || right.score - left.score || left.index - right.index)
|
|
92
|
-
return ranked.map(match => match.item)
|
|
93
|
-
}
|