@salmonui/dropdowns 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/combobox/Combobox.d.ts +54 -0
- package/dist/combobox/Combobox.d.ts.map +1 -0
- package/dist/combobox/Combobox.js +484 -0
- package/dist/combobox/Combobox.js.map +1 -0
- package/dist/combobox/ComboboxField.d.ts +9 -0
- package/dist/combobox/ComboboxField.d.ts.map +1 -0
- package/dist/combobox/ComboboxField.js +13 -0
- package/dist/combobox/ComboboxField.js.map +1 -0
- package/dist/combobox/columns-grid.d.ts +20 -0
- package/dist/combobox/columns-grid.d.ts.map +1 -0
- package/dist/combobox/columns-grid.js +106 -0
- package/dist/combobox/columns-grid.js.map +1 -0
- package/dist/combobox/columns.d.ts +45 -0
- package/dist/combobox/columns.d.ts.map +1 -0
- package/dist/combobox/columns.js +42 -0
- package/dist/combobox/columns.js.map +1 -0
- package/dist/combobox.css +706 -0
- package/dist/combobox.d.ts +6 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +10 -0
- package/dist/combobox.js.map +1 -0
- package/dist/dropdown/core.d.ts +178 -0
- package/dist/dropdown/core.d.ts.map +1 -0
- package/dist/dropdown/core.js +582 -0
- package/dist/dropdown/core.js.map +1 -0
- package/dist/dropdown/field.d.ts +17 -0
- package/dist/dropdown/field.d.ts.map +1 -0
- package/dist/dropdown/field.js +24 -0
- package/dist/dropdown/field.js.map +1 -0
- package/dist/dropdown/locale.d.ts +3 -0
- package/dist/dropdown/locale.d.ts.map +1 -0
- package/dist/dropdown/locale.js +23 -0
- package/dist/dropdown/locale.js.map +1 -0
- package/dist/dropdown/overlay.d.ts +14 -0
- package/dist/dropdown/overlay.d.ts.map +1 -0
- package/dist/dropdown/overlay.js +46 -0
- package/dist/dropdown/overlay.js.map +1 -0
- package/dist/dropdown/popup.d.ts +44 -0
- package/dist/dropdown/popup.d.ts.map +1 -0
- package/dist/dropdown/popup.js +183 -0
- package/dist/dropdown/popup.js.map +1 -0
- package/dist/dropdown/types.d.ts +180 -0
- package/dist/dropdown/types.d.ts.map +1 -0
- package/dist/dropdown/types.js +4 -0
- package/dist/dropdown/types.js.map +1 -0
- package/dist/internal/caret.d.ts +18 -0
- package/dist/internal/caret.d.ts.map +1 -0
- package/dist/internal/caret.js +73 -0
- package/dist/internal/caret.js.map +1 -0
- package/dist/internal/collection/collection.d.ts +53 -0
- package/dist/internal/collection/collection.d.ts.map +1 -0
- package/dist/internal/collection/collection.js +161 -0
- package/dist/internal/collection/collection.js.map +1 -0
- package/dist/internal/collection/fold.d.ts +15 -0
- package/dist/internal/collection/fold.d.ts.map +1 -0
- package/dist/internal/collection/fold.js +33 -0
- package/dist/internal/collection/fold.js.map +1 -0
- package/dist/internal/collection/remote.d.ts +76 -0
- package/dist/internal/collection/remote.d.ts.map +1 -0
- package/dist/internal/collection/remote.js +261 -0
- package/dist/internal/collection/remote.js.map +1 -0
- package/dist/internal/collection/search.d.ts +28 -0
- package/dist/internal/collection/search.d.ts.map +1 -0
- package/dist/internal/collection/search.js +119 -0
- package/dist/internal/collection/search.js.map +1 -0
- package/dist/internal/collection/selection.d.ts +33 -0
- package/dist/internal/collection/selection.d.ts.map +1 -0
- package/dist/internal/collection/selection.js +82 -0
- package/dist/internal/collection/selection.js.map +1 -0
- package/dist/internal/collection/view.d.ts +22 -0
- package/dist/internal/collection/view.d.ts.map +1 -0
- package/dist/internal/collection/view.js +83 -0
- package/dist/internal/collection/view.js.map +1 -0
- package/dist/internal/select.d.ts +2 -0
- package/dist/internal/select.d.ts.map +1 -0
- package/dist/internal/select.js +7 -0
- package/dist/internal/select.js.map +1 -0
- package/dist/listbox/Listbox.d.ts +8 -0
- package/dist/listbox/Listbox.d.ts.map +1 -0
- package/dist/listbox/Listbox.js +886 -0
- package/dist/listbox/Listbox.js.map +1 -0
- package/dist/listbox/drag-types.d.ts +50 -0
- package/dist/listbox/drag-types.d.ts.map +1 -0
- package/dist/listbox/drag-types.js +6 -0
- package/dist/listbox/drag-types.js.map +1 -0
- package/dist/listbox/drag.d.ts +33 -0
- package/dist/listbox/drag.d.ts.map +1 -0
- package/dist/listbox/drag.js +201 -0
- package/dist/listbox/drag.js.map +1 -0
- package/dist/listbox/grid.d.ts +28 -0
- package/dist/listbox/grid.d.ts.map +1 -0
- package/dist/listbox/grid.js +165 -0
- package/dist/listbox/grid.js.map +1 -0
- package/dist/listbox/locale.d.ts +24 -0
- package/dist/listbox/locale.d.ts.map +1 -0
- package/dist/listbox/locale.js +25 -0
- package/dist/listbox/locale.js.map +1 -0
- package/dist/listbox/move.d.ts +16 -0
- package/dist/listbox/move.d.ts.map +1 -0
- package/dist/listbox/move.js +70 -0
- package/dist/listbox/move.js.map +1 -0
- package/dist/listbox/types.d.ts +210 -0
- package/dist/listbox/types.d.ts.map +1 -0
- package/dist/listbox/types.js +2 -0
- package/dist/listbox/types.js.map +1 -0
- package/dist/listbox.css +330 -0
- package/dist/listbox.d.ts +6 -0
- package/dist/listbox.d.ts.map +1 -0
- package/dist/listbox.js +7 -0
- package/dist/listbox.js.map +1 -0
- package/dist/mention/Mention.d.ts +5 -0
- package/dist/mention/Mention.d.ts.map +1 -0
- package/dist/mention/Mention.js +530 -0
- package/dist/mention/Mention.js.map +1 -0
- package/dist/mention/query.d.ts +27 -0
- package/dist/mention/query.d.ts.map +1 -0
- package/dist/mention/query.js +53 -0
- package/dist/mention/query.js.map +1 -0
- package/dist/mention/store.d.ts +22 -0
- package/dist/mention/store.d.ts.map +1 -0
- package/dist/mention/store.js +25 -0
- package/dist/mention/store.js.map +1 -0
- package/dist/mention/types.d.ts +177 -0
- package/dist/mention/types.d.ts.map +1 -0
- package/dist/mention/types.js +2 -0
- package/dist/mention/types.js.map +1 -0
- package/dist/mention.css +116 -0
- package/dist/mention.d.ts +3 -0
- package/dist/mention.d.ts.map +1 -0
- package/dist/mention.js +7 -0
- package/dist/mention.js.map +1 -0
- package/dist/select/Select.d.ts +31 -0
- package/dist/select/Select.d.ts.map +1 -0
- package/dist/select/Select.js +362 -0
- package/dist/select/Select.js.map +1 -0
- package/dist/select/SelectField.d.ts +9 -0
- package/dist/select/SelectField.d.ts.map +1 -0
- package/dist/select/SelectField.js +13 -0
- package/dist/select/SelectField.js.map +1 -0
- package/dist/select.css +536 -0
- package/dist/select.d.ts +5 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +9 -0
- package/dist/select.js.map +1 -0
- package/dist/styles.css +1590 -0
- package/dist/tree-select/TreeSelect.d.ts +69 -0
- package/dist/tree-select/TreeSelect.d.ts.map +1 -0
- package/dist/tree-select/TreeSelect.js +597 -0
- package/dist/tree-select/TreeSelect.js.map +1 -0
- package/dist/tree-select/filter.d.ts +24 -0
- package/dist/tree-select/filter.d.ts.map +1 -0
- package/dist/tree-select/filter.js +74 -0
- package/dist/tree-select/filter.js.map +1 -0
- package/dist/tree-select/locale.d.ts +3 -0
- package/dist/tree-select/locale.d.ts.map +1 -0
- package/dist/tree-select/locale.js +8 -0
- package/dist/tree-select/locale.js.map +1 -0
- package/dist/tree-select/popup.d.ts +19 -0
- package/dist/tree-select/popup.d.ts.map +1 -0
- package/dist/tree-select/popup.js +418 -0
- package/dist/tree-select/popup.js.map +1 -0
- package/dist/tree-select/types.d.ts +147 -0
- package/dist/tree-select/types.d.ts.map +1 -0
- package/dist/tree-select/types.js +4 -0
- package/dist/tree-select/types.js.map +1 -0
- package/dist/tree-select.css +601 -0
- package/dist/tree-select.d.ts +5 -0
- package/dist/tree-select.d.ts.map +1 -0
- package/dist/tree-select.js +10 -0
- package/dist/tree-select.js.map +1 -0
- package/package.json +65 -4
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Pure mention logic: trigger detection at the caret and the text of an
|
|
2
|
+
// insertion. No React, no DOM globals, unit tested in Node. Filtering,
|
|
3
|
+
// folding and match ranges come from internal/collection/.
|
|
4
|
+
const isSpace = (ch) => ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r' || ch === ' ' || ch === ' ';
|
|
5
|
+
const isBreak = (ch) => ch === '\n' || ch === '\r';
|
|
6
|
+
/** Longest search text the detector scans back over (a guard for very long lines). */
|
|
7
|
+
const MAX_SCAN = 200;
|
|
8
|
+
/**
|
|
9
|
+
* Finds the mention that ends at `caret`, or null. Scans back from the caret
|
|
10
|
+
* to the nearest trigger character; without `multiWord` whitespace ends the
|
|
11
|
+
* scan, with it only a line break does. The search text never starts with
|
|
12
|
+
* whitespace. Among triggers that share a prefix the longest wins.
|
|
13
|
+
*/
|
|
14
|
+
export function findMention(value, caret, triggers, options) {
|
|
15
|
+
if (caret < 0 || caret > value.length || triggers.length === 0)
|
|
16
|
+
return null;
|
|
17
|
+
const floor = Math.max(0, caret - MAX_SCAN);
|
|
18
|
+
for (let i = caret - 1; i >= floor; i--) {
|
|
19
|
+
const ch = value[i];
|
|
20
|
+
if (isBreak(ch) || (!options.multiWord && isSpace(ch)))
|
|
21
|
+
return null;
|
|
22
|
+
let best = -1;
|
|
23
|
+
let bestLength = 0;
|
|
24
|
+
for (let t = 0; t < triggers.length; t++) {
|
|
25
|
+
const char = triggers[t].char;
|
|
26
|
+
if (char.length === 0 || char.length <= bestLength)
|
|
27
|
+
continue;
|
|
28
|
+
const start = i - char.length + 1;
|
|
29
|
+
if (start < 0 || value.slice(start, i + 1) !== char)
|
|
30
|
+
continue;
|
|
31
|
+
best = t;
|
|
32
|
+
bestLength = char.length;
|
|
33
|
+
}
|
|
34
|
+
if (best < 0)
|
|
35
|
+
continue;
|
|
36
|
+
const start = i - bestLength + 1;
|
|
37
|
+
const before = start > 0 ? value[start - 1] : '';
|
|
38
|
+
if (options.requireLeadingSpace && before !== '' && !isSpace(before)) {
|
|
39
|
+
// `name@host`: not a mention. A trigger char inside a word still ends the scan.
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const text = value.slice(i + 1, caret);
|
|
43
|
+
if (text.length > 0 && isSpace(text[0]))
|
|
44
|
+
return null;
|
|
45
|
+
return { trigger: best, start, end: caret, text };
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
/** The text that replaces the trigger and search text: optional trigger char, the item text, the suffix. */
|
|
50
|
+
export function insertionText(char, keepChar, text, suffix) {
|
|
51
|
+
return `${keepChar ? char : ''}${text}${suffix}`;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/mention/query.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,uEAAuE;AACvE,2DAA2D;AAsB3D,MAAM,OAAO,GAAG,CAAC,EAAU,EAAW,EAAE,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,CAAC;AAC7H,MAAM,OAAO,GAAG,CAAC,EAAU,EAAW,EAAE,CAAC,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,CAAC;AAEpE,sFAAsF;AACtF,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,KAAa,EAAE,QAAuC,EAAE,OAA6B;IAC9H,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,C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C;QACvC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC;YAAE,OAAO,IAAI,CAAC;QACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACpD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAAiB,EAAE,IAAY,EAAE,MAAc;IACzF,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MentionDataSource } from './types.js';
|
|
2
|
+
export interface MentionSnapshot<T> {
|
|
3
|
+
readonly open: boolean;
|
|
4
|
+
readonly items: readonly T[];
|
|
5
|
+
readonly active: number;
|
|
6
|
+
readonly status: 'idle' | 'loading' | 'error';
|
|
7
|
+
readonly error: unknown;
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly trigger: number;
|
|
10
|
+
/** Portal container while open (an Element; typed opaquely so this module stays DOM-free). */
|
|
11
|
+
readonly container: object | null;
|
|
12
|
+
/** Direction of the field, read when the list opens. */
|
|
13
|
+
readonly dir: 'ltr' | 'rtl';
|
|
14
|
+
}
|
|
15
|
+
export interface MentionStore<T> {
|
|
16
|
+
get(): MentionSnapshot<T>;
|
|
17
|
+
set(patch: Partial<MentionSnapshot<T>>): void;
|
|
18
|
+
subscribe(listener: () => void): () => void;
|
|
19
|
+
}
|
|
20
|
+
export declare function createMentionStore<T>(): MentionStore<T>;
|
|
21
|
+
export declare const isRemote: <T>(data: unknown) => data is MentionDataSource<T>;
|
|
22
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/mention/store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;IAC9C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,wDAAwD;IACxD,QAAQ,CAAC,GAAG,EAAE,KAAK,GAAG,KAAK,CAAC;CAC7B;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,GAAG,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;IAC1B,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC9C,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CAC7C;AAED,wBAAgB,kBAAkB,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAmBvD;AAED,eAAO,MAAM,QAAQ,GAAI,CAAC,QAAQ,OAAO,KAAG,IAAI,IAAI,iBAAiB,CAAC,CAAC,CAAoG,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function createMentionStore() {
|
|
2
|
+
let state = { open: false, items: [], active: -1, status: 'idle', error: null, text: '', trigger: -1, container: null, dir: 'ltr' };
|
|
3
|
+
const listeners = new Set();
|
|
4
|
+
return {
|
|
5
|
+
get: () => state,
|
|
6
|
+
set(patch) {
|
|
7
|
+
let changed = false;
|
|
8
|
+
for (const key in patch) {
|
|
9
|
+
if (!Object.is(patch[key], state[key]))
|
|
10
|
+
changed = true;
|
|
11
|
+
}
|
|
12
|
+
if (!changed)
|
|
13
|
+
return;
|
|
14
|
+
state = { ...state, ...patch };
|
|
15
|
+
for (const l of listeners)
|
|
16
|
+
l();
|
|
17
|
+
},
|
|
18
|
+
subscribe(listener) {
|
|
19
|
+
listeners.add(listener);
|
|
20
|
+
return () => listeners.delete(listener);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export const isRemote = (data) => data != null && !Array.isArray(data) && typeof data.read === 'function';
|
|
25
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/mention/store.ts"],"names":[],"mappings":"AA0BA,MAAM,UAAU,kBAAkB;IAChC,IAAI,KAAK,GAAuB,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IACxJ,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IACxC,OAAO;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK;QAChB,GAAG,CAAC,KAAK;YACP,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;gBACxB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,GAA+B,CAAC,EAAE,KAAK,CAAC,GAA+B,CAAC,CAAC;oBAAE,OAAO,GAAG,IAAI,CAAC;YACjH,CAAC;YACD,IAAI,CAAC,OAAO;gBAAE,OAAO;YACrB,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC;YAC/B,KAAK,MAAM,CAAC,IAAI,SAAS;gBAAE,CAAC,EAAE,CAAC;QACjC,CAAC;QACD,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAI,IAAa,EAAgC,EAAE,CAAC,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,OAAQ,IAA2B,CAAC,IAAI,KAAK,UAAU,CAAC"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode, Ref, RefObject } from 'react';
|
|
2
|
+
import type { DataSource } from '@salmonui/core/data';
|
|
3
|
+
import type { SearchOperator } from '../internal/collection/search.js';
|
|
4
|
+
/** `'startsWith' | 'contains' | 'endsWith'` or a predicate; Mention defaults to `'contains'`. */
|
|
5
|
+
export type MentionSearchOperator<T> = SearchOperator<T>;
|
|
6
|
+
/** Default item shape: `{ value, label, disabled }`; a string or number is its own value and label. */
|
|
7
|
+
export interface MentionItem {
|
|
8
|
+
readonly value: string | number;
|
|
9
|
+
readonly label?: string;
|
|
10
|
+
readonly disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Remote suggestions: any `@salmonui/data` source (or another object with the
|
|
14
|
+
* structural `read()` of the Data Grid data source contract). The search
|
|
15
|
+
* text is sent as `query.search`, the result window as `range`.
|
|
16
|
+
*/
|
|
17
|
+
export type MentionDataSource<T> = Pick<DataSource<T>, 'read'>;
|
|
18
|
+
/** Local items or a remote source. */
|
|
19
|
+
export type MentionData<T> = readonly T[] | MentionDataSource<T>;
|
|
20
|
+
export interface MentionTrigger<T = MentionItem> {
|
|
21
|
+
/** The trigger character (or string), for example `'@'` or `'#'`. */
|
|
22
|
+
readonly char: string;
|
|
23
|
+
/** Suggestions for this trigger; defaults to the `Mention` `data`. */
|
|
24
|
+
readonly data?: MentionData<T>;
|
|
25
|
+
/** Keep the trigger character in the inserted text. */
|
|
26
|
+
readonly keepChar?: boolean;
|
|
27
|
+
/** Text appended after the insertion, such as `' '` or `'\n'`. */
|
|
28
|
+
readonly suffix?: string;
|
|
29
|
+
}
|
|
30
|
+
/** What the change and insert callbacks report as the cause. */
|
|
31
|
+
export type MentionEventSource = 'pointer' | 'keyboard' | 'touch' | 'api';
|
|
32
|
+
export interface MentionInsertEvent<T = MentionItem> {
|
|
33
|
+
readonly item: T;
|
|
34
|
+
/** The text that replaces the trigger and the search text. */
|
|
35
|
+
readonly text: string;
|
|
36
|
+
/** The trigger character that started this mention. */
|
|
37
|
+
readonly trigger: string;
|
|
38
|
+
readonly source: MentionEventSource;
|
|
39
|
+
}
|
|
40
|
+
export interface MentionBeforeInsertEvent<T = MentionItem> extends MentionInsertEvent<T> {
|
|
41
|
+
/** Cancels the insertion; the list stays open. */
|
|
42
|
+
preventDefault(): void;
|
|
43
|
+
readonly defaultPrevented: boolean;
|
|
44
|
+
}
|
|
45
|
+
export type MentionOpenChangeReason = 'trigger' | 'insert' | 'escape' | 'outside' | 'blur' | 'caret' | 'tab';
|
|
46
|
+
export interface MentionOpenChangeEvent {
|
|
47
|
+
readonly source: MentionEventSource;
|
|
48
|
+
readonly reason: MentionOpenChangeReason;
|
|
49
|
+
}
|
|
50
|
+
export interface MentionSearchChangeEvent {
|
|
51
|
+
readonly text: string;
|
|
52
|
+
readonly trigger: string;
|
|
53
|
+
}
|
|
54
|
+
export interface MentionRenderItemContext<T = MentionItem> {
|
|
55
|
+
readonly item: T;
|
|
56
|
+
readonly label: string;
|
|
57
|
+
readonly active: boolean;
|
|
58
|
+
readonly disabled: boolean;
|
|
59
|
+
/** Matched range of `label` when `highlightMatches` is on, else null. */
|
|
60
|
+
readonly matches: readonly [number, number] | null;
|
|
61
|
+
readonly trigger: string;
|
|
62
|
+
}
|
|
63
|
+
export interface MentionLocaleText {
|
|
64
|
+
/** Accessible name of the suggestion list. */
|
|
65
|
+
readonly listLabel: string;
|
|
66
|
+
/** Shown when nothing matches. */
|
|
67
|
+
readonly noResults: string;
|
|
68
|
+
/** Shown while a remote read is pending. */
|
|
69
|
+
readonly loading: string;
|
|
70
|
+
/** Shown when a remote read fails. */
|
|
71
|
+
readonly loadError: string;
|
|
72
|
+
}
|
|
73
|
+
export type MentionPart = 'root' | 'popup' | 'list' | 'option';
|
|
74
|
+
/** What `Mention` asks an editor target to insert. */
|
|
75
|
+
export interface MentionEditorInsertion {
|
|
76
|
+
/** Offset of the trigger in the text block (the text `getTextBeforeCaret()` returns). */
|
|
77
|
+
readonly start: number;
|
|
78
|
+
/** Offset of the caret: `[start, end)` is the trigger and the search text to replace. */
|
|
79
|
+
readonly end: number;
|
|
80
|
+
/** The text the textarea path would insert: trigger (with `keepChar`), the insert text, then `suffix`. */
|
|
81
|
+
readonly text: string;
|
|
82
|
+
/** The trigger suffix included at the end of `text` (`''` by default). */
|
|
83
|
+
readonly suffix: string;
|
|
84
|
+
readonly trigger: string;
|
|
85
|
+
readonly value: string | number;
|
|
86
|
+
readonly label: string;
|
|
87
|
+
readonly item: unknown;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A rich text surface `Mention` attaches to instead of a `<textarea>` or
|
|
91
|
+
* `<input>`: a plain `contenteditable` element through
|
|
92
|
+
* `createContentEditableMentionTarget`, or the `@salmonui/rich-text` engine.
|
|
93
|
+
* Offsets count the characters of the current text block, an inline atom
|
|
94
|
+
* (an inserted mention) as one U+FFFC character.
|
|
95
|
+
*/
|
|
96
|
+
export interface MentionEditorTarget {
|
|
97
|
+
/**
|
|
98
|
+
* The editable element (the host gives it `role="textbox"`). `Mention` adds the
|
|
99
|
+
* combobox ARIA attributes to it while the list is open, listens for `keydown` in
|
|
100
|
+
* the capture phase (keys it handles while open call `preventDefault()` and
|
|
101
|
+
* `stopImmediatePropagation()`), for composition and for `focusout`.
|
|
102
|
+
*/
|
|
103
|
+
readonly element: HTMLElement;
|
|
104
|
+
/** Text of the current text block from its start to the caret; `null` when the selection is not collapsed or not editable. */
|
|
105
|
+
getTextBeforeCaret(): string | null;
|
|
106
|
+
/** Viewport rectangle of the character at `offset` of that text, `null` when unknown. */
|
|
107
|
+
getCaretRect(offset: number): {
|
|
108
|
+
readonly left: number;
|
|
109
|
+
readonly top: number;
|
|
110
|
+
readonly bottom: number;
|
|
111
|
+
} | null;
|
|
112
|
+
/** Replaces `[start, end)` of the text block with the mention (and its suffix) and puts the caret after it. */
|
|
113
|
+
insertMention(insertion: MentionEditorInsertion): void;
|
|
114
|
+
/** Calls `listener` after the editor applied a text or selection change; returns the unsubscribe function. */
|
|
115
|
+
subscribe(listener: () => void): () => void;
|
|
116
|
+
}
|
|
117
|
+
export interface MentionProps<T = MentionItem> {
|
|
118
|
+
/** One `<textarea>` or `<input>` (possibly nested in other markup). Omit it and pass `target` instead. */
|
|
119
|
+
readonly children?: ReactNode;
|
|
120
|
+
/** The field to attach to when it is not a child. */
|
|
121
|
+
readonly target?: RefObject<HTMLTextAreaElement | HTMLInputElement | null>;
|
|
122
|
+
/**
|
|
123
|
+
* A `contenteditable` surface to attach to instead of a field: the
|
|
124
|
+
* result of `createContentEditableMentionTarget(element)` or the target a
|
|
125
|
+
* rich text editor provides. Keep it stable across renders; it wins over
|
|
126
|
+
* `target` and children fields.
|
|
127
|
+
*/
|
|
128
|
+
readonly editor?: MentionEditorTarget | null;
|
|
129
|
+
/** Suggestions for triggers without their own `data`. */
|
|
130
|
+
readonly data?: MentionData<T>;
|
|
131
|
+
/** Trigger characters, each with optional own data (default `[{ char: '@' }]`). */
|
|
132
|
+
readonly triggers?: readonly MentionTrigger<T>[];
|
|
133
|
+
/** A trigger only counts at the start or after whitespace (default `true`). */
|
|
134
|
+
readonly requireLeadingSpace?: boolean;
|
|
135
|
+
/** The search text may contain spaces. */
|
|
136
|
+
readonly multiWord?: boolean;
|
|
137
|
+
/** Characters typed after the trigger before the list opens. */
|
|
138
|
+
readonly minSearchLength?: number;
|
|
139
|
+
/** Suggestions shown at most. */
|
|
140
|
+
readonly maxResults?: number;
|
|
141
|
+
/** Default `'contains'`. */
|
|
142
|
+
readonly searchOperator?: MentionSearchOperator<T>;
|
|
143
|
+
readonly matchCase?: boolean;
|
|
144
|
+
readonly ignoreAccents?: boolean;
|
|
145
|
+
/** Fields a remote source searches (default `['label']`). */
|
|
146
|
+
readonly searchFields?: readonly string[];
|
|
147
|
+
/** Delay in ms before a remote read (default 300); local data filters on every keystroke. */
|
|
148
|
+
readonly debounce?: number;
|
|
149
|
+
/** Mark the matched text in each suggestion (`<mark>`). */
|
|
150
|
+
readonly highlightMatches?: boolean;
|
|
151
|
+
readonly getItemValue?: (item: T) => string | number;
|
|
152
|
+
readonly getItemLabel?: (item: T) => string;
|
|
153
|
+
readonly isItemDisabled?: (item: T) => boolean;
|
|
154
|
+
/** Text inserted for an item (default its label). */
|
|
155
|
+
readonly getInsertText?: (item: T, trigger: MentionTrigger<T>) => string;
|
|
156
|
+
readonly onBeforeInsert?: (event: MentionBeforeInsertEvent<T>) => void;
|
|
157
|
+
readonly onInsert?: (event: MentionInsertEvent<T>) => void;
|
|
158
|
+
readonly onOpenChange?: (open: boolean, event: MentionOpenChangeEvent) => void;
|
|
159
|
+
readonly onSearchChange?: (event: MentionSearchChangeEvent) => void;
|
|
160
|
+
readonly onLoadError?: (error: unknown) => void;
|
|
161
|
+
readonly renderItem?: (context: MentionRenderItemContext<T>) => ReactNode;
|
|
162
|
+
readonly renderEmpty?: () => ReactNode;
|
|
163
|
+
readonly renderLoading?: () => ReactNode;
|
|
164
|
+
readonly renderError?: (context: {
|
|
165
|
+
readonly error: unknown;
|
|
166
|
+
}) => ReactNode;
|
|
167
|
+
readonly localeText?: Partial<MentionLocaleText>;
|
|
168
|
+
/** Portal container of the popup (default the field's closest theme scope, else `document.body`). */
|
|
169
|
+
readonly container?: Element | null;
|
|
170
|
+
readonly className?: string;
|
|
171
|
+
readonly style?: CSSProperties;
|
|
172
|
+
readonly classNames?: Partial<Record<MentionPart, string>>;
|
|
173
|
+
readonly styles?: Partial<Record<MentionPart, CSSProperties>>;
|
|
174
|
+
/** The root `<div>` that wraps `children`. */
|
|
175
|
+
readonly ref?: Ref<HTMLDivElement>;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mention/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEvE,iGAAiG;AACjG,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAEzD,uGAAuG;AACvG,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAE/D,sCAAsC;AACtC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,EAAE,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAEjE,MAAM,WAAW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,KAAK,IAAI,CAAC;IAChD,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;IAC1E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,SAAS,CAAC;IACvC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,SAAS,CAAC;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,SAAS,CAAC;IAC3E,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACjD,qGAAqG;IACrG,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC;IAC9D,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mention/types.ts"],"names":[],"mappings":""}
|
package/dist/mention.css
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
@layer salmon.a;
|
|
2
|
+
@layer salmon.a {
|
|
3
|
+
/* @salmonui/react/mention: the suggestion popup.
|
|
4
|
+
The root only wraps the user's field; colors come from the theme variables. */
|
|
5
|
+
.salmon-mention {
|
|
6
|
+
display: block;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.salmon-mention-popup {
|
|
10
|
+
position: fixed;
|
|
11
|
+
z-index: 1000;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
min-inline-size: 180px;
|
|
14
|
+
max-inline-size: min(360px, calc(100vw - 16px));
|
|
15
|
+
max-block-size: min(calc(8 * 32px + 2 * var(--salmon-space-2) + 2px), calc(100vh - 16px));
|
|
16
|
+
overflow: auto;
|
|
17
|
+
padding: var(--salmon-space-2);
|
|
18
|
+
font-family: var(--salmon-font-sans, system-ui, sans-serif);
|
|
19
|
+
font-size: var(--salmon-font-size-md, 14px);
|
|
20
|
+
line-height: var(--salmon-line-height-tight, 1.25);
|
|
21
|
+
color: var(--salmon-text-primary, CanvasText);
|
|
22
|
+
background: var(--salmon-surface-overlay, Canvas);
|
|
23
|
+
border: 1px solid var(--salmon-border-default, GrayText);
|
|
24
|
+
border-radius: var(--salmon-radius-lg);
|
|
25
|
+
box-shadow: var(--salmon-shadow-md, none);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Fixed at the viewport origin (inline style) and moved by `transform` in a layout effect; hidden until placed. */
|
|
29
|
+
.salmon-mention-popup:not([data-placed]) {
|
|
30
|
+
visibility: hidden;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.salmon-mention-list {
|
|
34
|
+
margin: 0;
|
|
35
|
+
padding: 0;
|
|
36
|
+
list-style: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.salmon-mention-option {
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
gap: var(--salmon-space-3);
|
|
43
|
+
min-block-size: 32px;
|
|
44
|
+
padding-inline: var(--salmon-space-4);
|
|
45
|
+
border-radius: var(--salmon-radius-sm, 4px);
|
|
46
|
+
white-space: nowrap;
|
|
47
|
+
overflow: hidden;
|
|
48
|
+
text-overflow: ellipsis;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* The default item text: one flex item, so a highlighted match sits flush with its text and long labels truncate. */
|
|
53
|
+
.salmon-mention-label {
|
|
54
|
+
min-inline-size: 0;
|
|
55
|
+
overflow: hidden;
|
|
56
|
+
text-overflow: ellipsis;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.salmon-mention-option[data-active] {
|
|
60
|
+
color: var(--salmon-text-primary, CanvasText);
|
|
61
|
+
background: var(--salmon-surface-selected, Highlight);
|
|
62
|
+
outline: var(--salmon-state-focus-ring-width, 2px) solid var(--salmon-state-focus-ring, Highlight);
|
|
63
|
+
outline-offset: calc(-1 * var(--salmon-state-focus-ring-width, 2px));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.salmon-mention-option[data-disabled] {
|
|
67
|
+
color: var(--salmon-text-disabled, GrayText);
|
|
68
|
+
cursor: default;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.salmon-mention-mark {
|
|
72
|
+
color: inherit;
|
|
73
|
+
background: none;
|
|
74
|
+
font-weight: var(--salmon-font-weight-semibold, 600);
|
|
75
|
+
text-decoration: underline;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.salmon-mention-status {
|
|
79
|
+
padding: var(--salmon-space-3) var(--salmon-space-4);
|
|
80
|
+
color: var(--salmon-text-secondary, GrayText);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.salmon-mention-status[data-error] {
|
|
84
|
+
color: var(--salmon-color-danger-text, CanvasText);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* a mention inserted into a contenteditable target (createContentEditableMentionTarget). */
|
|
88
|
+
.salmon-mention-chip {
|
|
89
|
+
padding-inline: var(--salmon-space-2);
|
|
90
|
+
border-radius: var(--salmon-radius-sm, 4px);
|
|
91
|
+
color: var(--salmon-text-primary, CanvasText);
|
|
92
|
+
background: var(--salmon-surface-selected, Highlight);
|
|
93
|
+
white-space: nowrap;
|
|
94
|
+
user-select: all;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@media (forced-colors: active) {
|
|
98
|
+
.salmon-mention-chip {
|
|
99
|
+
border: 1px solid CanvasText;
|
|
100
|
+
}
|
|
101
|
+
.salmon-mention-popup {
|
|
102
|
+
color: CanvasText;
|
|
103
|
+
background: Canvas;
|
|
104
|
+
border-color: CanvasText;
|
|
105
|
+
}
|
|
106
|
+
.salmon-mention-option[data-active] {
|
|
107
|
+
color: HighlightText;
|
|
108
|
+
background: Highlight;
|
|
109
|
+
forced-color-adjust: none;
|
|
110
|
+
}
|
|
111
|
+
.salmon-mention-option[data-disabled] {
|
|
112
|
+
color: GrayText;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Mention, MENTION_DEFAULT_LOCALE_TEXT } from './mention/Mention.js';
|
|
2
|
+
export type { MentionBeforeInsertEvent, MentionData, MentionDataSource, MentionEditorInsertion, MentionEditorTarget, MentionEventSource, MentionInsertEvent, MentionItem, MentionLocaleText, MentionOpenChangeEvent, MentionOpenChangeReason, MentionPart, MentionProps, MentionRenderItemContext, MentionSearchChangeEvent, MentionSearchOperator, MentionTrigger, } from './mention/types.js';
|
|
3
|
+
//# sourceMappingURL=mention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mention.d.ts","sourceRoot":"","sources":["../src/mention.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAC5E,YAAY,EACV,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,WAAW,EACX,YAAY,EACZ,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,GACf,MAAM,oBAAoB,CAAC"}
|
package/dist/mention.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { expectStylesheet } from '@salmonui/core/internal/dev';
|
|
2
|
+
// `@salmonui/dropdowns/mention`: Mention over a <textarea>, an <input> or a contenteditable target.
|
|
3
|
+
// Styles: `@salmonui/dropdowns/mention/styles.css`.
|
|
4
|
+
export { Mention, MENTION_DEFAULT_LOCALE_TEXT } from './mention/Mention.js';
|
|
5
|
+
if (process.env.NODE_ENV !== 'production')
|
|
6
|
+
expectStylesheet('@salmonui/dropdowns/mention', 'salmon-mention');
|
|
7
|
+
//# sourceMappingURL=mention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mention.js","sourceRoot":"","sources":["../src/mention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,oGAAoG;AACpG,oDAAoD;AACpD,OAAO,EAAE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAwB5E,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAAE,gBAAgB,CAAC,6BAA6B,EAAE,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type CSSProperties, type Ref } from 'react';
|
|
2
|
+
import type { DropdownValue } from '../dropdown/types.js';
|
|
3
|
+
import type { DropdownCommonProps, DropdownDomProps, DropdownFieldProps, DropdownLocaleText, DropdownSearchChangeEvent, DropdownValueChangeEvent } from '../dropdown/types.js';
|
|
4
|
+
export declare const SELECT_DEFAULT_LOCALE_TEXT: DropdownLocaleText;
|
|
5
|
+
interface SelectOwnProps<Item> extends DropdownCommonProps<Item>, DropdownFieldProps, DropdownDomProps {
|
|
6
|
+
/** A search input inside the popup filters the options. */
|
|
7
|
+
readonly searchable?: boolean;
|
|
8
|
+
readonly searchPlaceholder?: string;
|
|
9
|
+
readonly onSearchChange?: (text: string, event: DropdownSearchChangeEvent) => void;
|
|
10
|
+
/** How the selected values of `multiple` show in the trigger: joined labels (default) or a count. Chips are a `Combobox multiple` display. */
|
|
11
|
+
readonly valueDisplay?: 'text' | 'count';
|
|
12
|
+
/** The trigger `<button role="combobox">`. */
|
|
13
|
+
readonly ref?: Ref<HTMLButtonElement>;
|
|
14
|
+
}
|
|
15
|
+
export interface SelectSingleProps<Item> extends SelectOwnProps<Item> {
|
|
16
|
+
readonly multiple?: false;
|
|
17
|
+
/** Selected value; `null` is a controlled empty selection. */
|
|
18
|
+
readonly value?: DropdownValue | null;
|
|
19
|
+
readonly defaultValue?: DropdownValue | null;
|
|
20
|
+
readonly onValueChange?: (value: DropdownValue | null, event: DropdownValueChangeEvent<Item>) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface SelectMultipleProps<Item> extends SelectOwnProps<Item> {
|
|
23
|
+
readonly multiple: true;
|
|
24
|
+
readonly value?: readonly DropdownValue[];
|
|
25
|
+
readonly defaultValue?: readonly DropdownValue[];
|
|
26
|
+
readonly onValueChange?: (value: readonly DropdownValue[], event: DropdownValueChangeEvent<Item>) => void;
|
|
27
|
+
}
|
|
28
|
+
export type SelectProps<Item = unknown> = SelectSingleProps<Item> | SelectMultipleProps<Item>;
|
|
29
|
+
export declare function Select<Item = unknown>(props: SelectProps<Item>): import("react").JSX.Element;
|
|
30
|
+
export type { CSSProperties };
|
|
31
|
+
//# sourceMappingURL=Select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../src/select/Select.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAoE,KAAK,aAAa,EAAgG,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AACrN,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAQ1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAuB,kBAAkB,EAAE,kBAAkB,EAAqD,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAEvP,eAAO,MAAM,0BAA0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