@webx-ui/core 0.38.0 → 0.40.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.
@@ -0,0 +1,94 @@
1
+ /**
2
+ * One placeholder a text field offers: `[name]` in the text, which whoever prints the text swaps
3
+ * for something else — a phone number kept in settings, the year, a company name.
4
+ *
5
+ * The field never swaps anything itself. It stores the brackets as typed and only helps to type
6
+ * them: a list that opens on `[`, a button with every placeholder there is, and the known ones
7
+ * drawn as chips so they read as one thing rather than as punctuation.
8
+ */
9
+ export interface TokenOption {
10
+ /** What goes between the brackets: `/^[a-z][a-z0-9_-]{0,63}$/`. */
11
+ name: string;
12
+ /** What it stands for right now, shown beside the name as a hint. */
13
+ value?: string;
14
+ /** One line about what it is, for a name that does not say. */
15
+ description?: string;
16
+ }
17
+ /** The props every field that offers placeholders shares. */
18
+ export interface TokenFieldProps {
19
+ /** Placeholders to suggest on `[` and to draw as chips. Nothing changes without them. */
20
+ tokens?: TokenOption[];
21
+ /** Heading of the list the help button opens. */
22
+ tokensTitle?: string;
23
+ /** Accessible name and tooltip of the help button. */
24
+ tokensLabel?: string;
25
+ }
26
+ export declare const TOKEN_NAME: RegExp;
27
+ export interface TokenSpan {
28
+ from: number;
29
+ to: number;
30
+ name: string;
31
+ }
32
+ /** Where the known placeholders of a text are. Unknown names and `[[escaped]]` ones are text. */
33
+ export declare function tokenSpans(text: string, known: ReadonlySet<string>): TokenSpan[];
34
+ export interface TokenSegment {
35
+ text: string;
36
+ token: string | null;
37
+ }
38
+ /** The text cut at its placeholders — what a mirror behind a plain field draws. */
39
+ export declare function tokenSegments(text: string, known: ReadonlySet<string>): TokenSegment[];
40
+ /**
41
+ * The placeholder being typed right before the caret: `[` and the start of a name. A `[` after
42
+ * another `[` is the start of an escaped one, and nobody wants a list for that.
43
+ */
44
+ export declare function tokenQuery(before: string): {
45
+ from: number;
46
+ query: string;
47
+ } | null;
48
+ /** The text a chosen placeholder is written as. */
49
+ export declare function tokenText(token: TokenOption): string;
50
+ /** Where the list hangs from: a rectangle in the viewport, and the element it scrolls with. */
51
+ export interface TokenAnchor {
52
+ getBoundingClientRect: () => DOMRect;
53
+ contextElement?: Element;
54
+ }
55
+ export declare function tokenAnchor(rect: DOMRect, owner: Element | null): TokenAnchor;
56
+ /** A rectangle by hand: `new DOMRect` is not everywhere these fields are rendered. */
57
+ export declare function rectOf(x: number, y: number, width: number, height: number): DOMRect;
58
+ /**
59
+ * Under the field, at the caret's column: the list of a one-line field hangs from the field's
60
+ * bottom edge rather than from the caret, so it never covers the line being typed.
61
+ */
62
+ export declare function fieldAnchor(owner: HTMLElement | null, caret: DOMRect | null): TokenAnchor | undefined;
63
+ /**
64
+ * The rectangle of one character of an element's text, by its offset — the caret's place in a
65
+ * mirror that draws the same text as the field in the same box. Null where layout is not
66
+ * measured (a test), and the caller falls back to the field.
67
+ */
68
+ export declare function textRect(root: HTMLElement, offset: number): DOMRect | null;
69
+ export interface TokenRange {
70
+ from: number;
71
+ to: number;
72
+ }
73
+ /**
74
+ * The list of placeholders and what the keyboard does to it, for any field — where the text is
75
+ * and how a choice is written back is the field's business.
76
+ *
77
+ * Two ways in: typing (`[ph` before the caret, the list filtered by it, the choice replacing it)
78
+ * and browsing (the help button, every placeholder, the choice going where the caret is).
79
+ */
80
+ export declare function useTokenMenu(tokens: () => TokenOption[] | undefined): {
81
+ open: import('vue').Ref<boolean, boolean>;
82
+ browsing: import('vue').Ref<boolean, boolean>;
83
+ items: import('vue').ComputedRef<TokenOption[]>;
84
+ active: import('vue').Ref<number, number>;
85
+ anchor: import('vue').ShallowRef<TokenAnchor | undefined, TokenAnchor | undefined>;
86
+ all: import('vue').ComputedRef<TokenOption[]>;
87
+ known: import('vue').ComputedRef<ReadonlySet<string>>;
88
+ close: () => void;
89
+ suggest: (before: string, caret: number, at: () => TokenAnchor | undefined) => void;
90
+ browse: (at: TokenRange, where: TokenAnchor | undefined) => void;
91
+ choose: (token: TokenOption, insert: (token: TokenOption, at: TokenRange) => void) => void;
92
+ keydown: (event: KeyboardEvent, insert: (token: TokenOption, at: TokenRange) => void) => boolean;
93
+ };
94
+ export type TokenMenu = ReturnType<typeof useTokenMenu>;
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { WebxUI, type WebxUiOptions } from './plugin';
3
3
  export type { ControlSize, ControlStatus, ValidationErrors } from './composables/useFormField';
4
4
  export { useControlAttrs, type ControlAttrs } from './composables/useControlAttrs';
5
5
  export { provideLocales, useLocales, useLocalized, localeLabel, localizedValue, localesKey, type LocaleOption, type LocalesContext, type LocalizedValue, type LocalizedFieldProps, } from './composables/useLocalized';
6
+ export { tokenSpans, tokenQuery, type TokenFieldProps, type TokenOption, type TokenSpan, } from './composables/useTokens';
6
7
  export { provideDateLocale, useDateLocale, dateLocaleKey, type DateLocaleSource, } from './composables/useDateLocale';
7
8
  export { provideDateTimezone, useDateTimezone, dateTimezoneKey, type DateTimezoneSource, } from './composables/useDateTimezone';
8
9
  export type { DateFnsLocale } from './internal/dateLocale';