@widgetic/design-system 0.5.40 → 0.5.42
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.md +73 -0
- package/dist/components/ContentRefreshOverlay.svelte +103 -0
- package/dist/components/ContentRefreshOverlay.svelte.d.ts +18 -0
- package/dist/components/EmptyState.svelte +6 -2
- package/dist/components/chat/Composer.svelte +380 -19
- package/dist/components/chat/Composer.svelte.d.ts +88 -1
- package/dist/components/chat/PlanCard.svelte +218 -88
- package/dist/components/chat/PlanCard.svelte.d.ts +11 -0
- package/dist/components/chat/QuestionCard.svelte +180 -70
- package/dist/components/chat/QuestionCard.svelte.d.ts +28 -2
- package/dist/components/chat/QuestionCardSummary.svelte +96 -0
- package/dist/components/chat/QuestionCardSummary.svelte.d.ts +20 -0
- package/dist/components/chat/QueueCard.svelte +185 -0
- package/dist/components/chat/QueueCard.svelte.d.ts +40 -0
- package/dist/components/chat/composerLogic.d.ts +31 -0
- package/dist/components/chat/composerLogic.js +37 -0
- package/dist/components/chat/composerReferences.d.ts +28 -0
- package/dist/components/chat/composerReferences.js +23 -0
- package/dist/components/chat/index.d.ts +8 -3
- package/dist/components/chat/index.js +10 -2
- package/dist/components/chat/questionCardLogic.d.ts +40 -3
- package/dist/components/chat/questionCardLogic.js +54 -3
- package/dist/components/chat/queueCardLogic.d.ts +7 -0
- package/dist/components/chat/queueCardLogic.js +5 -0
- package/dist/components/creator/CreatorBar.svelte +54 -1
- package/dist/components/creator/CreatorBar.svelte.d.ts +5 -0
- package/dist/components/creator/index.d.ts +1 -2
- package/dist/components/creator/index.js +2 -0
- package/dist/components/index.d.ts +8 -7
- package/dist/components/index.js +8 -6
- package/dist/components/modals/BaseModal.svelte +23 -4
- package/dist/components/modals/BaseModal.svelte.d.ts +5 -0
- package/dist/components/navigation/breadcrumbSlideIn.d.ts +6 -2
- package/dist/components/navigation/breadcrumbSlideIn.js +6 -6
- package/dist/components/search-input/SearchInput.svelte +317 -14
- package/dist/components/search-input/SearchInput.svelte.d.ts +3 -0
- package/dist/components/search-input/index.d.ts +1 -0
- package/dist/components/search-input/index.js +1 -0
- package/dist/components/search-input/index2.d.ts +4 -0
- package/dist/components/search-input/recentSearches.d.ts +16 -0
- package/dist/components/search-input/recentSearches.js +141 -0
- package/dist/components/shell/NavRow.svelte +53 -10
- package/dist/components/shell/NavRow.svelte.d.ts +23 -2
- package/dist/components/shell/NotificationRow.svelte +3 -2
- package/dist/components/shell/ProfileRow.svelte +6 -4
- package/dist/components/shell/ProfileRow.svelte.d.ts +2 -2
- package/dist/components/shell/SettingsDialog.svelte +23 -1
- package/dist/components/shell/WidgetRow.svelte +4 -3
- package/dist/components/shell/WidgetRow.svelte.d.ts +2 -2
- package/dist/components/toast/ToasterModal.svelte +8 -3
- package/dist/components/toast/ToasterModal.svelte.d.ts +2 -0
- package/dist/components/ui/accordion/accordion-trigger.svelte +19 -0
- package/dist/components/ui/button/button.svelte +4 -2
- package/dist/components/ui/chip/chip.svelte +39 -1
- package/dist/components/ui/chip/chip.svelte.d.ts +8 -0
- package/dist/components/ui/chip/chipProgress.d.ts +14 -0
- package/dist/components/ui/chip/chipProgress.js +21 -0
- package/dist/components/ui/dialog/dialog-content.svelte +24 -2
- package/dist/components/ui/dropdown-menu/dropdown-menu-content.svelte +2 -1
- package/dist/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +2 -1
- package/dist/components/ui/hover-card/hover-card-content.svelte +2 -1
- package/dist/components/ui/icon-button/icon-button.svelte +2 -0
- package/dist/components/ui/icon-button/icon-button.svelte.d.ts +5 -0
- package/dist/components/ui/number-controls/index.d.ts +2 -0
- package/dist/components/ui/number-controls/index.js +2 -0
- package/dist/components/ui/number-controls/number-controls.svelte +530 -0
- package/dist/components/ui/number-controls/number-controls.svelte.d.ts +46 -0
- package/dist/components/ui/number-controls/numberControlsSteps.d.ts +17 -0
- package/dist/components/ui/number-controls/numberControlsSteps.js +23 -0
- package/dist/components/ui/number-controls/numberControlsValueArea.d.ts +29 -0
- package/dist/components/ui/number-controls/numberControlsValueArea.js +51 -0
- package/dist/components/ui/popover/popover-content.svelte +2 -1
- package/dist/components/ui/select/select-content.svelte +2 -1
- package/dist/components/ui/text-flip/index.d.ts +1 -0
- package/dist/components/ui/text-flip/index.js +1 -0
- package/dist/components/ui/text-flip/text-flip.svelte +103 -0
- package/dist/components/ui/text-flip/text-flip.svelte.d.ts +15 -0
- package/dist/components/ui/text-flip/textFlipLogic.d.ts +49 -0
- package/dist/components/ui/text-flip/textFlipLogic.js +151 -0
- package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
- package/dist/inline-completion/completionAnswer.d.ts +11 -0
- package/dist/inline-completion/completionAnswer.js +49 -0
- package/dist/inline-completion/completionCache.d.ts +24 -0
- package/dist/inline-completion/completionCache.js +47 -0
- package/dist/inline-completion/completionController.d.ts +61 -0
- package/dist/inline-completion/completionController.js +280 -0
- package/dist/inline-completion/completionKeys.d.ts +21 -0
- package/dist/inline-completion/completionKeys.js +19 -0
- package/dist/inline-completion/completionText.d.ts +53 -0
- package/dist/inline-completion/completionText.js +79 -0
- package/dist/inline-completion/completionTypes.d.ts +71 -0
- package/dist/inline-completion/completionTypes.js +5 -0
- package/dist/inline-completion/gatewayCompletion.d.ts +37 -0
- package/dist/inline-completion/gatewayCompletion.js +77 -0
- package/dist/inline-completion/ghostTap.d.ts +19 -0
- package/dist/inline-completion/ghostTap.js +20 -0
- package/dist/inline-completion/hintMemory.d.ts +43 -0
- package/dist/inline-completion/hintMemory.js +90 -0
- package/dist/inline-completion/httpSource.d.ts +40 -0
- package/dist/inline-completion/httpSource.js +149 -0
- package/dist/inline-completion/index.d.ts +30 -0
- package/dist/inline-completion/index.js +20 -0
- package/dist/inline-completion/inlineCompletionAction.d.ts +54 -0
- package/dist/inline-completion/inlineCompletionAction.js +310 -0
- package/dist/inline-completion/outcomeReporter.d.ts +49 -0
- package/dist/inline-completion/outcomeReporter.js +139 -0
- package/dist/inline-completion/promiseLike.d.ts +9 -0
- package/dist/inline-completion/promiseLike.js +9 -0
- package/dist/prompt-references/ReferenceMenu.svelte +344 -0
- package/dist/prompt-references/ReferenceMenu.svelte.d.ts +26 -0
- package/dist/prompt-references/index.d.ts +27 -0
- package/dist/prompt-references/index.js +20 -0
- package/dist/prompt-references/neutralizingSource.d.ts +21 -0
- package/dist/prompt-references/neutralizingSource.js +29 -0
- package/dist/prompt-references/promptReferences.d.ts +28 -0
- package/dist/prompt-references/promptReferences.js +766 -0
- package/dist/prompt-references/referenceBadge.d.ts +61 -0
- package/dist/prompt-references/referenceBadge.js +82 -0
- package/dist/prompt-references/referenceBadgePainter.d.ts +31 -0
- package/dist/prompt-references/referenceBadgePainter.js +106 -0
- package/dist/prompt-references/referenceEditing.d.ts +60 -0
- package/dist/prompt-references/referenceEditing.js +135 -0
- package/dist/prompt-references/referenceLabels.d.ts +56 -0
- package/dist/prompt-references/referenceLabels.js +215 -0
- package/dist/prompt-references/referenceMeasure.d.ts +12 -0
- package/dist/prompt-references/referenceMeasure.js +63 -0
- package/dist/prompt-references/referenceMenuHost.svelte.d.ts +29 -0
- package/dist/prompt-references/referenceMenuHost.svelte.js +43 -0
- package/dist/prompt-references/referenceMenuKeys.d.ts +26 -0
- package/dist/prompt-references/referenceMenuKeys.js +49 -0
- package/dist/prompt-references/referenceMenuPlacement.d.ts +63 -0
- package/dist/prompt-references/referenceMenuPlacement.js +66 -0
- package/dist/prompt-references/referenceTokens.d.ts +175 -0
- package/dist/prompt-references/referenceTokens.js +332 -0
- package/dist/prompt-references/referenceTrigger.d.ts +52 -0
- package/dist/prompt-references/referenceTrigger.js +100 -0
- package/dist/prompt-references/referenceTypes.d.ts +38 -0
- package/dist/prompt-references/referenceTypes.js +4 -0
- package/dist/prompt-references/sentReferences.d.ts +50 -0
- package/dist/prompt-references/sentReferences.js +122 -0
- package/dist/styles/tokens.css +126 -1
- package/dist/textarea-overlay/index.d.ts +9 -0
- package/dist/textarea-overlay/index.js +7 -0
- package/dist/textarea-overlay/mirrorSegments.d.ts +31 -0
- package/dist/textarea-overlay/mirrorSegments.js +47 -0
- package/dist/textarea-overlay/mirrorSizing.d.ts +39 -0
- package/dist/textarea-overlay/mirrorSizing.js +40 -0
- package/dist/textarea-overlay/textareaOverlay.d.ts +25 -0
- package/dist/textarea-overlay/textareaOverlay.js +277 -0
- package/dist/utils/modalEnterKey.d.ts +139 -0
- package/dist/utils/modalEnterKey.js +276 -0
- package/dist/utils/modalFocusTrap.d.ts +7 -0
- package/dist/utils/modalFocusTrap.js +22 -0
- package/dist/utils/overlayMotion.d.ts +10 -0
- package/dist/utils/overlayMotion.js +12 -3
- package/dist/utils/reducedMotion.d.ts +9 -0
- package/dist/utils/reducedMotion.js +13 -0
- package/dist/utils/revealOpeningSection.d.ts +51 -0
- package/dist/utils/revealOpeningSection.js +109 -0
- package/package.json +16 -1
- package/dist/components/ui/number-stepper/index.d.ts +0 -3
- package/dist/components/ui/number-stepper/index.js +0 -3
- package/dist/components/ui/number-stepper/number-stepper.svelte +0 -212
- package/dist/components/ui/number-stepper/number-stepper.svelte.d.ts +0 -24
- package/dist/components/ui/number-stepper/numberStepperSteps.d.ts +0 -26
- package/dist/components/ui/number-stepper/numberStepperSteps.js +0 -45
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mirror layer: a transparent copy of a text field's text, laid exactly over it, on which owners paint what the field itself cannot
|
|
3
|
+
* show: the ghost text after the caret (`inline-completion`) and the file badges that stand in for reserved characters
|
|
4
|
+
* (`prompt-references`). Both paint on ONE mirror per field, each under its own owner name, so one never touches the other's nodes.
|
|
5
|
+
*
|
|
6
|
+
* How the mirror matches the field: it is a sibling after the field, absolutely placed over the field's own box, with the typography,
|
|
7
|
+
* padding and borders copied from the field's computed style (borders transparent), so text wraps at the same places; the field's
|
|
8
|
+
* scroll offset is mirrored on its content; its text is transparent, so only what an owner paints is seen. It never takes a pointer
|
|
9
|
+
* event and is hidden from assistive technology (the owners announce what matters themselves).
|
|
10
|
+
*
|
|
11
|
+
* Nothing here knows what is painted: an owner hands in ranges and a function that builds a node for each.
|
|
12
|
+
*/
|
|
13
|
+
import { buildMirrorSegments } from "./mirrorSegments.js";
|
|
14
|
+
import { borderBoxWidthOf, scrollbarWidthOf } from "./mirrorSizing.js";
|
|
15
|
+
/**
|
|
16
|
+
* What is copied from the field's computed style, so the mirror wraps text where the field does. The sides of the line are copied by
|
|
17
|
+
* their logical names (start and end): the mirror takes the field's direction too, so each lands on the side the field has it on.
|
|
18
|
+
*/
|
|
19
|
+
const MIRRORED_PROPERTIES = [
|
|
20
|
+
'box-sizing',
|
|
21
|
+
'border-top-width',
|
|
22
|
+
'border-inline-end-width',
|
|
23
|
+
'border-bottom-width',
|
|
24
|
+
'border-inline-start-width',
|
|
25
|
+
'padding-top',
|
|
26
|
+
'padding-inline-end',
|
|
27
|
+
'padding-bottom',
|
|
28
|
+
'padding-inline-start',
|
|
29
|
+
'font-family',
|
|
30
|
+
'font-size',
|
|
31
|
+
'font-style',
|
|
32
|
+
'font-weight',
|
|
33
|
+
'font-variant',
|
|
34
|
+
'font-stretch',
|
|
35
|
+
'font-kerning',
|
|
36
|
+
'font-feature-settings',
|
|
37
|
+
'font-variation-settings',
|
|
38
|
+
'letter-spacing',
|
|
39
|
+
'word-spacing',
|
|
40
|
+
'line-height',
|
|
41
|
+
'text-transform',
|
|
42
|
+
'text-indent',
|
|
43
|
+
'text-align',
|
|
44
|
+
'text-rendering',
|
|
45
|
+
'text-wrap',
|
|
46
|
+
'tab-size',
|
|
47
|
+
'direction',
|
|
48
|
+
'unicode-bidi',
|
|
49
|
+
'writing-mode',
|
|
50
|
+
'overflow-wrap',
|
|
51
|
+
'word-break',
|
|
52
|
+
'line-break',
|
|
53
|
+
'hyphens'
|
|
54
|
+
];
|
|
55
|
+
/** A problem is logged once per kind, not once per paint. */
|
|
56
|
+
const reportedProblems = new Set();
|
|
57
|
+
function reportProblemOnce(kind, error) {
|
|
58
|
+
if (reportedProblems.has(kind))
|
|
59
|
+
return;
|
|
60
|
+
reportedProblems.add(kind);
|
|
61
|
+
console.debug(`[textarea-overlay] ${kind}`, error instanceof Error ? error.message : (error ?? ''));
|
|
62
|
+
}
|
|
63
|
+
function createOverlayCore(field) {
|
|
64
|
+
const doc = field.ownerDocument;
|
|
65
|
+
const fieldWindow = doc.defaultView;
|
|
66
|
+
if (!fieldWindow || !field.parentElement)
|
|
67
|
+
return null;
|
|
68
|
+
// Declared with its own type, so the functions below see a window and not "a window or nothing".
|
|
69
|
+
const win = fieldWindow;
|
|
70
|
+
const isInput = field.tagName === 'INPUT';
|
|
71
|
+
const shownDisplay = isInput ? 'flex' : 'block';
|
|
72
|
+
const mirror = doc.createElement('div');
|
|
73
|
+
mirror.setAttribute('aria-hidden', 'true');
|
|
74
|
+
mirror.setAttribute('data-textarea-overlay', '');
|
|
75
|
+
// What must hold whatever the page's styles say. Typography and box measures are copied from the field in `measureField`.
|
|
76
|
+
mirror.style.cssText =
|
|
77
|
+
'position:absolute;pointer-events:none;overflow:hidden;margin:0;border-style:solid;border-color:transparent;background:transparent;color:transparent;display:none;';
|
|
78
|
+
if (isInput)
|
|
79
|
+
mirror.style.alignItems = 'center';
|
|
80
|
+
const content = doc.createElement('div');
|
|
81
|
+
// A textarea wraps its text and keeps its blanks; an input keeps one line.
|
|
82
|
+
content.style.cssText = `position:relative;${isInput ? 'white-space:pre;' : 'white-space:pre-wrap;min-height:100%;'}`;
|
|
83
|
+
mirror.appendChild(content);
|
|
84
|
+
field.insertAdjacentElement('afterend', mirror);
|
|
85
|
+
const decorationsByOwner = new Map();
|
|
86
|
+
let paintQueued = false;
|
|
87
|
+
let destroyed = false;
|
|
88
|
+
/** Puts the mirror over the field: its place, its size, the room a scrollbar takes, and its place in the stack. */
|
|
89
|
+
function measureBox(computed) {
|
|
90
|
+
mirror.style.top = `${field.offsetTop}px`;
|
|
91
|
+
// rtl-ok: measured from the left edge of the offset parent, like the field's own `offsetLeft` is, in either direction
|
|
92
|
+
mirror.style.left = `${field.offsetLeft}px`;
|
|
93
|
+
// Sized from the border edge whatever box-sizing the field has: the padding and borders copied onto the mirror sit inside it.
|
|
94
|
+
// The fraction of the width stays (see `borderBoxWidthOf`): the rounded `offsetWidth` would move a line break.
|
|
95
|
+
mirror.style.boxSizing = 'border-box';
|
|
96
|
+
mirror.style.width = `${borderBoxWidthOf(computed, field.offsetWidth)}px`;
|
|
97
|
+
mirror.style.height = `${field.offsetHeight}px`;
|
|
98
|
+
// A scrollbar takes room from the field's text and none from its box: the mirror keeps the same room by padding.
|
|
99
|
+
const scrollbarWidth = scrollbarWidthOf({
|
|
100
|
+
offsetWidth: field.offsetWidth,
|
|
101
|
+
clientWidth: field.clientWidth,
|
|
102
|
+
borderWidth: (Number.parseFloat(computed.borderLeftWidth) || 0) +
|
|
103
|
+
(Number.parseFloat(computed.borderRightWidth) || 0)
|
|
104
|
+
});
|
|
105
|
+
// The scrollbar sits at the end of the line: on the right in a left-to-right field, on the left in a right-to-left one.
|
|
106
|
+
const side = 'padding-inline-end';
|
|
107
|
+
mirror.style.setProperty(side, `${(Number.parseFloat(computed.getPropertyValue(side)) || 0) + scrollbarWidth}px`);
|
|
108
|
+
// Over the field even when the field is stacked: one step above its z-index when it has one.
|
|
109
|
+
const stack = Number.parseInt(computed.zIndex, 10);
|
|
110
|
+
mirror.style.zIndex = Number.isFinite(stack) ? String(stack + 1) : '';
|
|
111
|
+
}
|
|
112
|
+
/** Copies the field's typography and box measures onto the mirror, so its text wraps where the field's does. */
|
|
113
|
+
function measureField() {
|
|
114
|
+
const computed = win.getComputedStyle(field);
|
|
115
|
+
for (const name of MIRRORED_PROPERTIES)
|
|
116
|
+
mirror.style.setProperty(name, computed.getPropertyValue(name));
|
|
117
|
+
measureBox(computed);
|
|
118
|
+
}
|
|
119
|
+
/** The field's scroll offset, on the content: what is painted moves with the text. */
|
|
120
|
+
function syncScroll() {
|
|
121
|
+
content.style.transform = isInput
|
|
122
|
+
? `translateX(${-field.scrollLeft}px)`
|
|
123
|
+
: `translateY(${-field.scrollTop}px)`;
|
|
124
|
+
}
|
|
125
|
+
/** Paints what the owners hold. */
|
|
126
|
+
function paint() {
|
|
127
|
+
paintQueued = false;
|
|
128
|
+
if (destroyed)
|
|
129
|
+
return;
|
|
130
|
+
const decorations = [];
|
|
131
|
+
for (const [owner, list] of decorationsByOwner) {
|
|
132
|
+
for (const decoration of list)
|
|
133
|
+
decorations.push({
|
|
134
|
+
owner,
|
|
135
|
+
start: decoration.start,
|
|
136
|
+
end: decoration.end,
|
|
137
|
+
payload: decoration
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (decorations.length === 0 || field.offsetWidth === 0) {
|
|
141
|
+
content.replaceChildren();
|
|
142
|
+
mirror.style.display = 'none';
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// The field may have moved, shown a scrollbar, changed its direction or its type size since the last paint without raising an
|
|
146
|
+
// event (a ghost that comes straight from the cache replaces the one before it with no pause between): it is read every time.
|
|
147
|
+
measureField();
|
|
148
|
+
const nodes = [];
|
|
149
|
+
for (const segment of buildMirrorSegments(field.value, decorations)) {
|
|
150
|
+
if (segment.kind === 'text') {
|
|
151
|
+
nodes.push(doc.createTextNode(segment.text));
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
nodes.push(segment.decoration.payload.render(segment.covered));
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
// A painter that fails leaves its place empty; the text around it still lines up.
|
|
159
|
+
reportProblemOnce('a decoration failed to render', error);
|
|
160
|
+
nodes.push(doc.createTextNode(segment.covered));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// A text that ends with a new line has one more (empty) line in the field; a block of `pre-wrap` text drops it unless something
|
|
164
|
+
// stands on it. A zero-width filler does, so the two have the same height (the badges' wrap check compares them).
|
|
165
|
+
if (!isInput && field.value.endsWith('\n'))
|
|
166
|
+
nodes.push(doc.createTextNode('\u200b'));
|
|
167
|
+
content.replaceChildren(...nodes);
|
|
168
|
+
mirror.style.display = shownDisplay;
|
|
169
|
+
syncScroll();
|
|
170
|
+
}
|
|
171
|
+
function queuePaint() {
|
|
172
|
+
if (paintQueued || destroyed)
|
|
173
|
+
return;
|
|
174
|
+
paintQueued = true;
|
|
175
|
+
queueMicrotask(() => {
|
|
176
|
+
try {
|
|
177
|
+
paint();
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
reportProblemOnce('could not paint', error);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function refresh() {
|
|
185
|
+
if (destroyed)
|
|
186
|
+
return;
|
|
187
|
+
try {
|
|
188
|
+
paint();
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
reportProblemOnce('could not measure the field', error);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// The field may grow (a composer that follows its text), be resized, or have its fonts arrive late: the mirror follows.
|
|
195
|
+
let refreshFrame = 0;
|
|
196
|
+
const onFieldResized = () => {
|
|
197
|
+
if (refreshFrame !== 0 || destroyed)
|
|
198
|
+
return;
|
|
199
|
+
refreshFrame = win.requestAnimationFrame(() => {
|
|
200
|
+
refreshFrame = 0;
|
|
201
|
+
refresh();
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
const observer = typeof win.ResizeObserver === 'function' ? new win.ResizeObserver(onFieldResized) : null;
|
|
205
|
+
observer?.observe(field);
|
|
206
|
+
field.addEventListener('scroll', syncScroll, { passive: true });
|
|
207
|
+
doc.fonts?.ready.then(onFieldResized, () => { });
|
|
208
|
+
return {
|
|
209
|
+
element: mirror,
|
|
210
|
+
setOwnerDecorations(owner, decorations) {
|
|
211
|
+
if (decorations.length === 0)
|
|
212
|
+
decorationsByOwner.delete(owner);
|
|
213
|
+
else
|
|
214
|
+
decorationsByOwner.set(owner, decorations);
|
|
215
|
+
queuePaint();
|
|
216
|
+
},
|
|
217
|
+
refresh,
|
|
218
|
+
destroy() {
|
|
219
|
+
if (destroyed)
|
|
220
|
+
return;
|
|
221
|
+
destroyed = true;
|
|
222
|
+
observer?.disconnect();
|
|
223
|
+
if (refreshFrame !== 0)
|
|
224
|
+
win.cancelAnimationFrame(refreshFrame);
|
|
225
|
+
field.removeEventListener('scroll', syncScroll);
|
|
226
|
+
mirror.remove();
|
|
227
|
+
decorationsByOwner.clear();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/** The mirror of each field, with how many owners hold it: one mirror per field, however many owners paint on it. */
|
|
232
|
+
const overlays = new WeakMap();
|
|
233
|
+
/**
|
|
234
|
+
* Takes a handle on the mirror of `field` for `owner`, making the mirror if the field has none yet. Returns null when there is nowhere
|
|
235
|
+
* to put one (the field is not in a document). Owners must be distinct per kind of decoration (`ghost`, `references`).
|
|
236
|
+
*/
|
|
237
|
+
export function acquireTextareaOverlay(field, owner) {
|
|
238
|
+
let entry = overlays.get(field);
|
|
239
|
+
if (!entry) {
|
|
240
|
+
try {
|
|
241
|
+
const core = createOverlayCore(field);
|
|
242
|
+
if (!core)
|
|
243
|
+
return null;
|
|
244
|
+
entry = { core, holders: 0 };
|
|
245
|
+
overlays.set(field, entry);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
reportProblemOnce('could not make the mirror', error);
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
entry.holders += 1;
|
|
253
|
+
const held = entry;
|
|
254
|
+
let released = false;
|
|
255
|
+
return {
|
|
256
|
+
element: held.core.element,
|
|
257
|
+
setDecorations(decorations) {
|
|
258
|
+
if (!released)
|
|
259
|
+
held.core.setOwnerDecorations(owner, decorations);
|
|
260
|
+
},
|
|
261
|
+
refresh() {
|
|
262
|
+
if (!released)
|
|
263
|
+
held.core.refresh();
|
|
264
|
+
},
|
|
265
|
+
release() {
|
|
266
|
+
if (released)
|
|
267
|
+
return;
|
|
268
|
+
released = true;
|
|
269
|
+
held.core.setOwnerDecorations(owner, []);
|
|
270
|
+
held.holders -= 1;
|
|
271
|
+
if (held.holders <= 0) {
|
|
272
|
+
held.core.destroy();
|
|
273
|
+
overlays.delete(field);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enter in an open modal presses the modal's main button (owner, 18 Nov 2026: "when I have a modal open, if I click Enter,
|
|
3
|
+
* take it as the main CTA").
|
|
4
|
+
*
|
|
5
|
+
* Both modal shells of the design system (`BaseModal` and the bits-ui `Dialog.Content`) put the `modalEnterKey` action on
|
|
6
|
+
* their card, so every dialog built on them gets it without writing anything. A key press is for a card when it was pressed
|
|
7
|
+
* inside that card and no other card is closer to the focus: a modal that is open over another one never presses the buttons
|
|
8
|
+
* of the one under it.
|
|
9
|
+
*
|
|
10
|
+
* Which button: the one the person sees as the main one.
|
|
11
|
+
* 1. a button marked `data-modal-primary` (the last one, when several are), else
|
|
12
|
+
* 2. the last filled button of the card (design system `Button` with `variant` default, accent or destructive; the Button
|
|
13
|
+
* writes it as `data-variant`). The footer comes last in every dialog, so a filled button inside the body does not win.
|
|
14
|
+
* The last filled button is the one that counts even while it is disabled ("Create" waiting for a name): Enter then does
|
|
15
|
+
* nothing, it does not fall back on another button.
|
|
16
|
+
*
|
|
17
|
+
* When Enter belongs to the control it is pressed on, it is left alone: a focused button or link does its own thing (Enter on
|
|
18
|
+
* "Cancel" cancels), a textarea gets a new line (Cmd or Ctrl + Enter submits), a combobox, a list option that is not chosen
|
|
19
|
+
* yet, a select and a rich text field keep their Enter, and so does everything that has already handled the key
|
|
20
|
+
* (`defaultPrevented`, or a handler that stopped it from travelling on), which is how a dialog that has its own Enter in a
|
|
21
|
+
* field (the rename dialog) keeps working unchanged. A control can say it itself: `data-modal-enter="own"` on it or on something
|
|
22
|
+
* around it keeps Enter for the control, and `data-modal-enter="primary"` on a button hands its Enter to the main button
|
|
23
|
+
* instead (a choice that is only a step towards the main action).
|
|
24
|
+
*
|
|
25
|
+
* The listener is on the window, in the bubble phase, on purpose: Svelte 5 handles `onkeydown="…"` of an element once, at the
|
|
26
|
+
* root of the app, after the key has passed the card. A listener on the card would see the key before the field's own handler
|
|
27
|
+
* and take it from it; on the window it comes last, and sees what the field did with it.
|
|
28
|
+
*/
|
|
29
|
+
/** Marks the button that Enter presses. Put it on a button that is not the last filled button of the card. */
|
|
30
|
+
export declare const modalPrimaryAttribute = "data-modal-primary";
|
|
31
|
+
/** `own` on a control (or around it) keeps Enter for the control, `primary` on a button hands its Enter to the main button. */
|
|
32
|
+
export declare const modalEnterAttribute = "data-modal-enter";
|
|
33
|
+
/** Written by the action on the card of every modal, so that a key press can tell which card is the closest to the focus. */
|
|
34
|
+
export declare const modalCardAttribute = "data-modal-card";
|
|
35
|
+
/** What the decision needs to know about the element that has the focus (every DOM `Element` has all of it). */
|
|
36
|
+
export interface EnterTargetLike {
|
|
37
|
+
tagName?: string;
|
|
38
|
+
type?: string;
|
|
39
|
+
isContentEditable?: boolean;
|
|
40
|
+
getAttribute(name: string): string | null;
|
|
41
|
+
closest(selector: string): EnterTargetLike | null;
|
|
42
|
+
}
|
|
43
|
+
/** What the decision needs to know about the key press (a `KeyboardEvent` has all of it). */
|
|
44
|
+
export interface EnterKeyFacts {
|
|
45
|
+
key: string;
|
|
46
|
+
defaultPrevented: boolean;
|
|
47
|
+
isComposing: boolean;
|
|
48
|
+
repeat: boolean;
|
|
49
|
+
shiftKey: boolean;
|
|
50
|
+
altKey: boolean;
|
|
51
|
+
metaKey: boolean;
|
|
52
|
+
ctrlKey: boolean;
|
|
53
|
+
keyCode?: number;
|
|
54
|
+
target: EnterTargetLike | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Whether Enter, pressed with the focus on `target`, belongs to `target` (it does something there) and so is not for the
|
|
58
|
+
* main button. `submitShortcut` is Cmd or Ctrl + Enter, which a textarea gives to the dialog.
|
|
59
|
+
*/
|
|
60
|
+
export declare function targetKeepsEnter(target: EnterTargetLike | null, submitShortcut?: boolean): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Whether this key press is an Enter that the modal takes as "the main button": Enter, not handled by anything yet, not part of
|
|
63
|
+
* typing in another script (an IME choosing a character), not a held key (the main button is pressed once), not a line break
|
|
64
|
+
* (Shift or Alt + Enter), and not an Enter that the control it is on keeps for itself.
|
|
65
|
+
*/
|
|
66
|
+
export declare function shouldTakeEnterAsPrimary(facts: EnterKeyFacts): boolean;
|
|
67
|
+
/** What the search for the main button needs from a button. */
|
|
68
|
+
export interface PrimaryActionElement extends EnterTargetLike {
|
|
69
|
+
hasAttribute?(name: string): boolean;
|
|
70
|
+
disabled?: boolean;
|
|
71
|
+
hidden?: boolean;
|
|
72
|
+
click(): void;
|
|
73
|
+
textContent?: string | null;
|
|
74
|
+
}
|
|
75
|
+
/** What the search for the main button needs from the card of the modal. */
|
|
76
|
+
export interface PrimaryActionContainer {
|
|
77
|
+
querySelectorAll(selector: string): ArrayLike<PrimaryActionElement>;
|
|
78
|
+
}
|
|
79
|
+
/** True when the button can be pressed right now: not `disabled`, not `aria-disabled`. */
|
|
80
|
+
export declare function isActionEnabled(element: PrimaryActionElement): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The main button of a modal card (see the rules at the top of this file), whether it can be pressed or not, and `null` when
|
|
83
|
+
* the card has none. The caller checks `isActionEnabled`.
|
|
84
|
+
*
|
|
85
|
+
* @param isVisible - Whether an element is drawn (a button inside a closed section is not). The page default reads the layout.
|
|
86
|
+
*/
|
|
87
|
+
export declare function findModalPrimaryAction(card: PrimaryActionContainer, isVisible?: (element: PrimaryActionElement) => boolean): PrimaryActionElement | null;
|
|
88
|
+
/** What `activateModalPrimaryOnEnter` reads of the key press, and what it does to it (a `KeyboardEvent` has all of it). */
|
|
89
|
+
export interface EnterKeyEventLike {
|
|
90
|
+
key: string;
|
|
91
|
+
defaultPrevented: boolean;
|
|
92
|
+
isComposing: boolean;
|
|
93
|
+
repeat: boolean;
|
|
94
|
+
shiftKey: boolean;
|
|
95
|
+
altKey: boolean;
|
|
96
|
+
metaKey: boolean;
|
|
97
|
+
ctrlKey: boolean;
|
|
98
|
+
keyCode?: number;
|
|
99
|
+
target: unknown;
|
|
100
|
+
composedPath?(): ArrayLike<unknown>;
|
|
101
|
+
preventDefault(): void;
|
|
102
|
+
stopPropagation(): void;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* What the decision reads of a key press. The properties are read one by one on purpose: a `KeyboardEvent` keeps them on its
|
|
106
|
+
* prototype, so spreading it into an object copies none of them.
|
|
107
|
+
*/
|
|
108
|
+
export declare function enterKeyFactsOf(event: EnterKeyEventLike): EnterKeyFacts;
|
|
109
|
+
/** How long after the main button was pressed a second Enter is not taken for another press (a double tap, a closing dialog). */
|
|
110
|
+
export declare const primaryPressCooldownMs = 400;
|
|
111
|
+
/** Whether a press at `lastPressAtMs` still counts as "just now" at `nowMs`. */
|
|
112
|
+
export declare function isWithinPressCooldown(lastPressAtMs: number, nowMs: number, cooldownMs?: number): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Presses the main button of `card` for an Enter key press, when the key press is one that the modal takes (see
|
|
115
|
+
* `shouldTakeEnterAsPrimary`) and the card has a main button that can be pressed.
|
|
116
|
+
*
|
|
117
|
+
* The key is then kept from everything else: `preventDefault` stops the browser from also submitting a form the focused field
|
|
118
|
+
* is in (the button's own press does that, once), `stopPropagation` stops the key from travelling on.
|
|
119
|
+
*
|
|
120
|
+
* @returns whether the main button was pressed
|
|
121
|
+
*/
|
|
122
|
+
export declare function activateModalPrimaryOnEnter(event: EnterKeyEventLike, card: PrimaryActionContainer, isVisible?: (element: PrimaryActionElement) => boolean): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Whether the key press belongs to `card`: it was pressed inside it, and no other modal card is closer to the focus (a modal
|
|
125
|
+
* drawn inside another one's markup is the closest one).
|
|
126
|
+
*/
|
|
127
|
+
export declare function keyPressBelongsToCard(path: ArrayLike<unknown>, card: unknown): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Svelte action for the card of a modal: Enter pressed inside the card presses its main button (see the top of this file).
|
|
130
|
+
* `enabled: false` switches it off for a modal that wants Enter for itself.
|
|
131
|
+
*/
|
|
132
|
+
export declare function modalEnterKey(card: HTMLElement, options?: {
|
|
133
|
+
enabled?: boolean;
|
|
134
|
+
}): {
|
|
135
|
+
update(nextOptions?: {
|
|
136
|
+
enabled?: boolean;
|
|
137
|
+
}): void;
|
|
138
|
+
destroy(): void;
|
|
139
|
+
};
|