@sdxc/ui 2026.11.18 → 2026.11.26
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 +133 -1
- package/dist/app/index.d.ts +1 -0
- package/dist/app/index.js +1 -0
- package/dist/app/mixins/command-palette.js +10 -2
- package/dist/app/mixins/log-viewer.js +17 -14
- package/dist/app/mixins/route-dialog.d.ts +17 -0
- package/dist/app/mixins/route-dialog.js +53 -0
- package/dist/app/optimistic-toggle.js +6 -0
- package/dist/app/route-dialog.d.ts +38 -0
- package/dist/app/route-dialog.js +49 -0
- package/dist/audio/equalizer.d.ts +24 -0
- package/dist/audio/equalizer.js +57 -0
- package/dist/audio/index.d.ts +16 -0
- package/dist/audio/index.js +16 -0
- package/dist/audio/media-tile.d.ts +38 -0
- package/dist/audio/media-tile.js +98 -0
- package/dist/audio/player-bar.d.ts +108 -0
- package/dist/audio/player-bar.js +338 -0
- package/dist/audio/queue-list.d.ts +56 -0
- package/dist/audio/queue-list.js +102 -0
- package/dist/audio/track-list.d.ts +91 -0
- package/dist/audio/track-list.js +226 -0
- package/dist/audio/utils/media-session.d.ts +44 -0
- package/dist/audio/utils/media-session.js +87 -0
- package/dist/audio/utils/play-queue.d.ts +98 -0
- package/dist/audio/utils/play-queue.js +149 -0
- package/dist/audio/utils/track-time.d.ts +28 -0
- package/dist/audio/utils/track-time.js +36 -0
- package/dist/chat/composer-format.d.ts +35 -0
- package/dist/chat/composer-format.js +84 -0
- package/dist/chat/index.d.ts +6 -0
- package/dist/chat/index.js +6 -0
- package/dist/chat/mention-menu.d.ts +43 -0
- package/dist/chat/mention-menu.js +70 -0
- package/dist/chat/message-group.d.ts +92 -0
- package/dist/chat/message-group.js +222 -0
- package/dist/chat/mixins/composer-format.d.ts +28 -0
- package/dist/chat/mixins/composer-format.js +80 -0
- package/dist/chat/mixins/composer-send.d.ts +2 -2
- package/dist/chat/mixins/composer-send.js +4 -2
- package/dist/chat/mixins/mention-menu.d.ts +41 -0
- package/dist/chat/mixins/mention-menu.js +213 -0
- package/dist/chat/mixins/reaction-sync.d.ts +47 -0
- package/dist/chat/mixins/reaction-sync.js +172 -0
- package/dist/chat/reaction-bar.d.ts +70 -0
- package/dist/chat/reaction-bar.js +108 -0
- package/dist/chat/typing-indicator.d.ts +42 -0
- package/dist/chat/typing-indicator.js +68 -0
- package/dist/chat/utils/composer-text.d.ts +38 -0
- package/dist/chat/utils/composer-text.js +86 -0
- package/dist/chat/utils/markdown-format.d.ts +30 -0
- package/dist/chat/utils/markdown-format.js +158 -0
- package/dist/chat/utils/mention-query.d.ts +55 -0
- package/dist/chat/utils/mention-query.js +60 -0
- package/dist/commerce/cart-drawer.d.ts +69 -0
- package/dist/commerce/cart-drawer.js +163 -0
- package/dist/commerce/cart-line.d.ts +32 -0
- package/dist/commerce/cart-line.js +43 -0
- package/dist/commerce/checkout-layout.d.ts +32 -0
- package/dist/commerce/checkout-layout.js +51 -0
- package/dist/commerce/facet-filters.d.ts +121 -0
- package/dist/commerce/facet-filters.js +318 -0
- package/dist/commerce/fulfilment-note.d.ts +28 -0
- package/dist/commerce/fulfilment-note.js +26 -0
- package/dist/commerce/index.d.ts +27 -0
- package/dist/commerce/index.js +27 -0
- package/dist/commerce/item-options-dialog.d.ts +67 -0
- package/dist/commerce/item-options-dialog.js +150 -0
- package/dist/commerce/menu-item-card.d.ts +37 -0
- package/dist/commerce/menu-item-card.js +96 -0
- package/dist/commerce/option-group.d.ts +62 -0
- package/dist/commerce/option-group.js +121 -0
- package/dist/commerce/order-summary.d.ts +42 -0
- package/dist/commerce/order-summary.js +76 -0
- package/dist/commerce/order-tracker.d.ts +80 -0
- package/dist/commerce/order-tracker.js +178 -0
- package/dist/commerce/price.d.ts +52 -0
- package/dist/commerce/price.js +108 -0
- package/dist/commerce/product-card.d.ts +53 -0
- package/dist/commerce/product-card.js +127 -0
- package/dist/commerce/product-gallery.d.ts +70 -0
- package/dist/commerce/product-gallery.js +186 -0
- package/dist/commerce/promo-code.d.ts +56 -0
- package/dist/commerce/promo-code.js +101 -0
- package/dist/commerce/quantity-stepper.d.ts +42 -0
- package/dist/commerce/quantity-stepper.js +53 -0
- package/dist/commerce/question-list.d.ts +53 -0
- package/dist/commerce/question-list.js +92 -0
- package/dist/commerce/shipping-estimate.d.ts +53 -0
- package/dist/commerce/shipping-estimate.js +39 -0
- package/dist/commerce/sort-select.d.ts +38 -0
- package/dist/commerce/sort-select.js +38 -0
- package/dist/commerce/variant-picker.d.ts +75 -0
- package/dist/commerce/variant-picker.js +135 -0
- package/dist/components/amount.d.ts +46 -0
- package/dist/components/amount.js +34 -0
- package/dist/components/autocomplete.d.ts +82 -0
- package/dist/components/autocomplete.js +114 -0
- package/dist/components/carousel.d.ts +31 -1
- package/dist/components/carousel.js +66 -3
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.js +11 -0
- package/dist/components/letterbox.d.ts +47 -0
- package/dist/components/letterbox.js +56 -0
- package/dist/components/lightbox.d.ts +88 -0
- package/dist/components/lightbox.js +224 -0
- package/dist/components/media-grid.d.ts +53 -0
- package/dist/components/media-grid.js +89 -0
- package/dist/components/range-months.d.ts +100 -0
- package/dist/components/range-months.js +274 -0
- package/dist/components/rating-input.d.ts +33 -0
- package/dist/components/rating-input.js +63 -0
- package/dist/components/rating.d.ts +38 -0
- package/dist/components/rating.js +66 -0
- package/dist/components/review-card.d.ts +39 -0
- package/dist/components/review-card.js +59 -0
- package/dist/components/section-bar.d.ts +57 -0
- package/dist/components/section-bar.js +140 -0
- package/dist/components/slider.js +7 -0
- package/dist/components/step-indicator.d.ts +46 -0
- package/dist/components/step-indicator.js +96 -0
- package/dist/finance/index.d.ts +10 -0
- package/dist/finance/index.js +10 -0
- package/dist/finance/ledger.d.ts +60 -0
- package/dist/finance/ledger.js +93 -0
- package/dist/finance/payment-card.d.ts +49 -0
- package/dist/finance/payment-card.js +115 -0
- package/dist/map/engine.d.ts +49 -0
- package/dist/map/engine.js +591 -0
- package/dist/map/index.d.ts +12 -0
- package/dist/map/index.js +12 -0
- package/dist/map/map-canvas.d.ts +101 -0
- package/dist/map/map-canvas.js +275 -0
- package/dist/map/map.d.ts +217 -0
- package/dist/map/map.js +598 -0
- package/dist/map/mixins/map-link.d.ts +30 -0
- package/dist/map/mixins/map-link.js +116 -0
- package/dist/map/utils/basemap.d.ts +88 -0
- package/dist/map/utils/basemap.js +84 -0
- package/dist/map/utils/cluster.d.ts +43 -0
- package/dist/map/utils/cluster.js +80 -0
- package/dist/map/utils/mercator.d.ts +66 -0
- package/dist/map/utils/mercator.js +92 -0
- package/dist/map/utils/stage.d.ts +24 -0
- package/dist/map/utils/stage.js +49 -0
- package/dist/mixins/autocomplete.d.ts +28 -0
- package/dist/mixins/autocomplete.js +283 -0
- package/dist/mixins/carousel-controls.d.ts +14 -3
- package/dist/mixins/carousel-controls.js +89 -30
- package/dist/mixins/index.d.ts +2 -0
- package/dist/mixins/index.js +2 -0
- package/dist/mixins/lightbox-controls.d.ts +34 -0
- package/dist/mixins/lightbox-controls.js +176 -0
- package/dist/schedule/agenda.d.ts +63 -0
- package/dist/schedule/agenda.js +221 -0
- package/dist/schedule/day-strip.d.ts +50 -0
- package/dist/schedule/day-strip.js +136 -0
- package/dist/schedule/free-busy.d.ts +96 -0
- package/dist/schedule/free-busy.js +285 -0
- package/dist/schedule/index.d.ts +15 -0
- package/dist/schedule/index.js +15 -0
- package/dist/schedule/mixins/day-strip-scroll.d.ts +16 -0
- package/dist/schedule/mixins/day-strip-scroll.js +40 -0
- package/dist/schedule/mixins/time-grid-drag.d.ts +24 -0
- package/dist/schedule/mixins/time-grid-drag.js +532 -0
- package/dist/schedule/month-view.d.ts +68 -0
- package/dist/schedule/month-view.js +301 -0
- package/dist/schedule/time-grid.d.ts +168 -0
- package/dist/schedule/time-grid.js +417 -0
- package/dist/schedule/utils/time-grid-layout.d.ts +50 -0
- package/dist/schedule/utils/time-grid-layout.js +93 -0
- package/dist/schedule/year-view.d.ts +46 -0
- package/dist/schedule/year-view.js +142 -0
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +1 -0
- package/dist/styles/typewriter-text.d.ts +20 -0
- package/dist/styles/typewriter-text.js +23 -0
- package/dist/test/map.d.ts +18 -0
- package/dist/test/map.js +96 -0
- package/dist/test/reels.d.ts +30 -0
- package/dist/test/reels.js +41 -0
- package/dist/test/stories.d.ts +31 -0
- package/dist/test/stories.js +66 -0
- package/dist/travel/boarding-pass.d.ts +107 -0
- package/dist/travel/boarding-pass.js +293 -0
- package/dist/travel/car-offer.d.ts +70 -0
- package/dist/travel/car-offer.js +127 -0
- package/dist/travel/fare-calendar.d.ts +85 -0
- package/dist/travel/fare-calendar.js +233 -0
- package/dist/travel/fare-options.d.ts +84 -0
- package/dist/travel/fare-options.js +142 -0
- package/dist/travel/flight-itinerary.d.ts +84 -0
- package/dist/travel/flight-itinerary.js +112 -0
- package/dist/travel/flight-option.d.ts +58 -0
- package/dist/travel/flight-option.js +111 -0
- package/dist/travel/flight-segment.d.ts +105 -0
- package/dist/travel/flight-segment.js +174 -0
- package/dist/travel/index.d.ts +20 -0
- package/dist/travel/index.js +20 -0
- package/dist/travel/package-savings.d.ts +74 -0
- package/dist/travel/package-savings.js +128 -0
- package/dist/travel/price-breakdown.d.ts +66 -0
- package/dist/travel/price-breakdown.js +102 -0
- package/dist/travel/rating-breakdown.d.ts +81 -0
- package/dist/travel/rating-breakdown.js +132 -0
- package/dist/travel/seat-map.d.ts +108 -0
- package/dist/travel/seat-map.js +371 -0
- package/dist/travel/trip-timeline.d.ts +84 -0
- package/dist/travel/trip-timeline.js +212 -0
- package/dist/utils/gamepad-presses.d.ts +21 -0
- package/dist/utils/gamepad-presses.js +28 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/move-focus.d.ts +20 -0
- package/dist/utils/move-focus.js +28 -0
- package/dist/utils/range-months.d.ts +54 -0
- package/dist/utils/range-months.js +98 -0
- package/dist/utils/swipe-direction.d.ts +23 -0
- package/dist/utils/swipe-direction.js +27 -0
- package/dist/utils/typewriter.d.ts +49 -0
- package/dist/utils/typewriter.js +171 -0
- package/dist/video/index.d.ts +6 -2
- package/dist/video/index.js +6 -2
- package/dist/video/mixins/reel-feed-sync.d.ts +41 -0
- package/dist/video/mixins/reel-feed-sync.js +430 -0
- package/dist/video/mixins/story-viewer-sync.d.ts +31 -0
- package/dist/video/mixins/story-viewer-sync.js +391 -0
- package/dist/video/reel-feed.d.ts +95 -0
- package/dist/video/reel-feed.js +124 -0
- package/dist/video/story-ring.d.ts +32 -0
- package/dist/video/story-ring.js +42 -0
- package/dist/video/story-viewer.d.ts +85 -0
- package/dist/video/story-viewer.js +250 -0
- package/package.json +21 -2
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes every `ReactionBar` on the page answer at once: pressing a chip flips it and its count
|
|
3
|
+
* before the form posts in the background, a `ui:reaction-add` event adds or presses a chip,
|
|
4
|
+
* and a post the server refuses puts the row back. Without it each chip is a plain form.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { createElement, createMixin } from "remix/component";
|
|
10
|
+
/** DOM event type that asks a `ReactionBar` to add, or press, a reaction. */
|
|
11
|
+
export const REACTION_ADD_EVENT = "ui:reaction-add";
|
|
12
|
+
/**
|
|
13
|
+
* Dispatched on a `ReactionBar` (or any element inside the message holding one) to add the
|
|
14
|
+
* reader's reaction: an existing chip is pressed, a missing one is cloned from the row's
|
|
15
|
+
* `ReactionBar.Template`, and either posts through its form.
|
|
16
|
+
*/
|
|
17
|
+
export class ReactionAddEvent extends Event {
|
|
18
|
+
detail;
|
|
19
|
+
/** @param detail The reaction to add. */
|
|
20
|
+
constructor(detail) {
|
|
21
|
+
super(REACTION_ADD_EVENT, { bubbles: true, cancelable: true });
|
|
22
|
+
this.detail = detail;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** The chip a form submits with, when the form is one of a `ReactionBar`'s. */
|
|
26
|
+
function chipOf(form, submitter) {
|
|
27
|
+
if (!form.closest("[data-slot=reaction-bar]"))
|
|
28
|
+
return null;
|
|
29
|
+
let chip = submitter ?? form.querySelector("[data-slot=reaction]");
|
|
30
|
+
return chip instanceof HTMLButtonElement && chip.matches("[data-slot=reaction]") ? chip : null;
|
|
31
|
+
}
|
|
32
|
+
/** Reads a chip's count. */
|
|
33
|
+
function countOf(chip) {
|
|
34
|
+
return Number(chip.querySelector("[data-reaction-count]")?.textContent ?? "0") || 0;
|
|
35
|
+
}
|
|
36
|
+
/** Draws a chip as pressed or not with `count`, and points its value at the next flip. */
|
|
37
|
+
function paint(chip, pressed, count) {
|
|
38
|
+
chip.setAttribute("aria-pressed", pressed ? "true" : "false");
|
|
39
|
+
chip.value = (pressed ? chip.dataset.toggleOff : chip.dataset.toggleOn) ?? chip.value;
|
|
40
|
+
let counter = chip.querySelector("[data-reaction-count]");
|
|
41
|
+
if (counter)
|
|
42
|
+
counter.textContent = String(count);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Flips a chip at once and posts its form in the background; a refused or failed post restores
|
|
46
|
+
* the chip, and a chip whose count reaches zero leaves the row until then.
|
|
47
|
+
*/
|
|
48
|
+
function flip(form, chip, signal) {
|
|
49
|
+
let body = new URLSearchParams();
|
|
50
|
+
for (let [name, value] of new FormData(form, chip)) {
|
|
51
|
+
if (typeof value === "string")
|
|
52
|
+
body.append(name, value);
|
|
53
|
+
}
|
|
54
|
+
let pressed = chip.getAttribute("aria-pressed") === "true";
|
|
55
|
+
let count = countOf(chip);
|
|
56
|
+
let next = Math.max(0, count + (pressed ? -1 : 1));
|
|
57
|
+
let parent = form.parentNode;
|
|
58
|
+
let sibling = form.nextSibling;
|
|
59
|
+
paint(chip, !pressed, next);
|
|
60
|
+
if (next === 0)
|
|
61
|
+
form.remove();
|
|
62
|
+
let restore = () => {
|
|
63
|
+
paint(chip, pressed, count);
|
|
64
|
+
if (!form.isConnected && parent)
|
|
65
|
+
parent.insertBefore(form, sibling);
|
|
66
|
+
};
|
|
67
|
+
void fetch(form.action, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
body,
|
|
70
|
+
redirect: "manual",
|
|
71
|
+
credentials: "same-origin",
|
|
72
|
+
signal,
|
|
73
|
+
})
|
|
74
|
+
.then((response) => {
|
|
75
|
+
if (response.type !== "opaqueredirect" && !response.ok)
|
|
76
|
+
restore();
|
|
77
|
+
})
|
|
78
|
+
.catch(() => {
|
|
79
|
+
if (!signal.aborted)
|
|
80
|
+
restore();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Fills a chip cloned from the template with the reaction a {@link ReactionAddEvent} names. */
|
|
84
|
+
function fill(form, detail) {
|
|
85
|
+
let chip = form.querySelector("[data-slot=reaction]");
|
|
86
|
+
if (chip === null)
|
|
87
|
+
return null;
|
|
88
|
+
for (let input of form.querySelectorAll("[data-reaction-emoji]")) {
|
|
89
|
+
input.value = detail.emoji;
|
|
90
|
+
}
|
|
91
|
+
chip.dataset.emoji = detail.emoji;
|
|
92
|
+
let glyph = chip.querySelector("[data-reaction-emoji-glyph]");
|
|
93
|
+
if (glyph) {
|
|
94
|
+
if (detail.image === undefined)
|
|
95
|
+
glyph.textContent = detail.emoji;
|
|
96
|
+
else {
|
|
97
|
+
let image = document.createElement("img");
|
|
98
|
+
image.src = detail.image;
|
|
99
|
+
image.alt = "";
|
|
100
|
+
glyph.replaceChildren(image);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let label = chip.querySelector("[data-reaction-label]");
|
|
104
|
+
if (label)
|
|
105
|
+
label.textContent = detail.label;
|
|
106
|
+
paint(chip, false, 0);
|
|
107
|
+
return chip;
|
|
108
|
+
}
|
|
109
|
+
/** Adds or presses the reaction a {@link ReactionAddEvent} names in the bar it reached. */
|
|
110
|
+
function add(bar, detail, signal) {
|
|
111
|
+
let existing = [...bar.querySelectorAll("[data-slot=reaction]")].find((chip) => chip.dataset.emoji === detail.emoji && !chip.closest("template"));
|
|
112
|
+
if (existing) {
|
|
113
|
+
let form = existing.form;
|
|
114
|
+
let pressed = existing.getAttribute("aria-pressed") === "true";
|
|
115
|
+
if (form && (!pressed || detail.toggle))
|
|
116
|
+
flip(form, existing, signal);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
let template = bar.querySelector("template[data-reaction-template]");
|
|
120
|
+
let source = template?.content.firstElementChild ?? template?.firstElementChild;
|
|
121
|
+
let form = source?.cloneNode(true);
|
|
122
|
+
if (!(form instanceof HTMLFormElement))
|
|
123
|
+
return;
|
|
124
|
+
let chip = fill(form, detail);
|
|
125
|
+
if (chip === null)
|
|
126
|
+
return;
|
|
127
|
+
let slot = bar.querySelector("[data-slot=reaction-add], template[data-reaction-template]");
|
|
128
|
+
bar.insertBefore(form, slot);
|
|
129
|
+
flip(form, chip, signal);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Put on one element that stays on the page, such as an island's host: from then on every
|
|
133
|
+
* reaction chip under `document` flips at once and posts in the background, and
|
|
134
|
+
* `ui:reaction-add` events add reactions in place. Submits are claimed in the capture phase,
|
|
135
|
+
* before any navigation handler sees them.
|
|
136
|
+
*
|
|
137
|
+
* @returns A mixin with no visible effect on its host.
|
|
138
|
+
* @example <span hidden mix={[reactionSync()]} />
|
|
139
|
+
*/
|
|
140
|
+
export const reactionSync = createMixin((handle) => {
|
|
141
|
+
let controller;
|
|
142
|
+
handle.addEventListener("insert", () => {
|
|
143
|
+
controller?.abort();
|
|
144
|
+
controller = new AbortController();
|
|
145
|
+
let { signal } = controller;
|
|
146
|
+
document.addEventListener("submit", (event) => {
|
|
147
|
+
let form = event.target;
|
|
148
|
+
if (!(form instanceof HTMLFormElement) || event.defaultPrevented)
|
|
149
|
+
return;
|
|
150
|
+
let chip = chipOf(form, event.submitter);
|
|
151
|
+
if (chip === null)
|
|
152
|
+
return;
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
event.stopImmediatePropagation();
|
|
155
|
+
flip(form, chip, signal);
|
|
156
|
+
}, { capture: true, signal });
|
|
157
|
+
document.addEventListener(REACTION_ADD_EVENT, (event) => {
|
|
158
|
+
let target = event.target;
|
|
159
|
+
if (!(event instanceof ReactionAddEvent) || !(target instanceof Element))
|
|
160
|
+
return;
|
|
161
|
+
let bar = target.matches("[data-slot=reaction-bar]")
|
|
162
|
+
? target
|
|
163
|
+
: target.querySelector("[data-slot=reaction-bar]");
|
|
164
|
+
if (!(bar instanceof HTMLElement))
|
|
165
|
+
return;
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
add(bar, event.detail, signal);
|
|
168
|
+
}, { signal });
|
|
169
|
+
});
|
|
170
|
+
handle.addEventListener("remove", () => controller?.abort());
|
|
171
|
+
return (props = {}) => createElement(handle.element, props);
|
|
172
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The row of emoji reactions under a message: each a chip with its emoji and count, pressed
|
|
3
|
+
* when the reader is among those who reacted, a slot for adding one, and a template for chips
|
|
4
|
+
* added in place. Chips are submit buttons, so a reaction posts before any script loads.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Handle, Props as TagProps, RemixNode } from "remix/component";
|
|
10
|
+
/** Prop types for {@link ReactionBar} and its compound parts. */
|
|
11
|
+
export declare namespace ReactionBar {
|
|
12
|
+
/** Props accepted by {@link ReactionBar}. */
|
|
13
|
+
interface Props extends Omit<TagProps<"div">, "aria-label"> {
|
|
14
|
+
/** Names the row for assistive technology, such as "Reactions". */
|
|
15
|
+
"aria-label": string;
|
|
16
|
+
/**
|
|
17
|
+
* One form per {@link ReactionBar.Reaction}, then an optional {@link ReactionBar.Add}
|
|
18
|
+
* and {@link ReactionBar.Template}. The row hides while it holds no reaction.
|
|
19
|
+
*/
|
|
20
|
+
children: RemixNode;
|
|
21
|
+
}
|
|
22
|
+
/** The field a chip submits: its name, and the value that adds or removes the reaction. */
|
|
23
|
+
interface Toggle {
|
|
24
|
+
name: string;
|
|
25
|
+
on: string;
|
|
26
|
+
off: string;
|
|
27
|
+
}
|
|
28
|
+
/** Props accepted by {@link ReactionBar.Reaction}. */
|
|
29
|
+
interface ReactionProps extends Omit<TagProps<"button">, "children" | "aria-label" | "name" | "value"> {
|
|
30
|
+
/** The emoji, or the shortcode of a custom one drawn from `image`. */
|
|
31
|
+
emoji: string;
|
|
32
|
+
/** A custom emoji's image, drawn in place of the emoji's text. */
|
|
33
|
+
image?: string;
|
|
34
|
+
/** What the emoji is called, such as "Party popper"; a screen reader hears it before the count. */
|
|
35
|
+
label: string;
|
|
36
|
+
count: number;
|
|
37
|
+
/** Whether the reader reacted with this emoji; the chip draws pressed. */
|
|
38
|
+
pressed?: boolean;
|
|
39
|
+
/** @default { name: "on", on: "1", off: "0" } */
|
|
40
|
+
toggle?: Toggle;
|
|
41
|
+
}
|
|
42
|
+
/** Props accepted by {@link ReactionBar.Add}. */
|
|
43
|
+
interface AddProps extends TagProps<"span"> {
|
|
44
|
+
/** The add-reaction control, such as a button opening an emoji picker. */
|
|
45
|
+
children: RemixNode;
|
|
46
|
+
}
|
|
47
|
+
/** Props accepted by {@link ReactionBar.Template}. */
|
|
48
|
+
interface TemplateProps {
|
|
49
|
+
/**
|
|
50
|
+
* The form a new reaction posts with, holding an `<input data-reaction-emoji>` for its
|
|
51
|
+
* emoji and one {@link ReactionBar.Reaction}; `reactionSync()` clones and fills it.
|
|
52
|
+
*/
|
|
53
|
+
children: RemixNode;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Renders the row as a `role="group"` that wraps onto a second line when a message collects
|
|
58
|
+
* many reactions, and hides itself while it holds no chip.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* <ReactionBar aria-label="Reactions">
|
|
62
|
+
* <form method="post" action="/messages/42/react"><input type="hidden" name="emoji" value="🎉" /><ReactionBar.Reaction emoji="🎉" label="Party popper" count={3} pressed /></form>
|
|
63
|
+
* </ReactionBar>
|
|
64
|
+
*/
|
|
65
|
+
export declare function ReactionBar(handle: Handle<ReactionBar.Props>): () => import("remix/component").RemixElement;
|
|
66
|
+
export declare namespace ReactionBar {
|
|
67
|
+
var Reaction: (handle: Handle<ReactionBar.ReactionProps>) => () => import("remix/component").RemixElement;
|
|
68
|
+
var Add: (handle: Handle<ReactionBar.AddProps>) => () => import("remix/component").RemixElement;
|
|
69
|
+
var Template: (handle: Handle<ReactionBar.TemplateProps>) => () => import("remix/component").RemixElement;
|
|
70
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "remix/component/jsx-runtime";
|
|
2
|
+
import { visuallyHidden } from "@sdxc/u/a11y";
|
|
3
|
+
import { rounded } from "@sdxc/u/effects";
|
|
4
|
+
import { mergeMix, raw } from "@sdxc/u/general";
|
|
5
|
+
import { hstack, inlineFlex } from "@sdxc/u/layout";
|
|
6
|
+
import { motionReduce } from "@sdxc/u/responsive";
|
|
7
|
+
import { when } from "@sdxc/u/state";
|
|
8
|
+
import { tabularNums } from "@sdxc/u/typography";
|
|
9
|
+
import { attrs } from "remix/component";
|
|
10
|
+
/** The field a chip submits when the caller names none. */
|
|
11
|
+
const DEFAULT_TOGGLE = { name: "on", on: "1", off: "0" };
|
|
12
|
+
/**
|
|
13
|
+
* Renders the row as a `role="group"` that wraps onto a second line when a message collects
|
|
14
|
+
* many reactions, and hides itself while it holds no chip.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* <ReactionBar aria-label="Reactions">
|
|
18
|
+
* <form method="post" action="/messages/42/react"><input type="hidden" name="emoji" value="🎉" /><ReactionBar.Reaction emoji="🎉" label="Party popper" count={3} pressed /></form>
|
|
19
|
+
* </ReactionBar>
|
|
20
|
+
*/
|
|
21
|
+
export function ReactionBar(handle) {
|
|
22
|
+
return () => {
|
|
23
|
+
let { children, mix, ...rest } = handle.props;
|
|
24
|
+
return (_jsx("div", { ...rest, "data-slot": "reaction-bar", mix: mergeMix([
|
|
25
|
+
attrs({ role: "group" }),
|
|
26
|
+
hstack({ gap: 1, align: "center" }),
|
|
27
|
+
raw({ flexWrap: "wrap", "& > form": { display: "contents" } }),
|
|
28
|
+
when("&:not(:has([data-slot=reaction]:not(template *)))", raw({ display: "none" })),
|
|
29
|
+
], mix), children: children }));
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Renders one reaction chip: a submit button sending the toggle that flips the reader's
|
|
34
|
+
* reaction, `aria-pressed` while they are among its reactors, and its count in tabular figures
|
|
35
|
+
* so the row never shifts. Its accessible name is the emoji's label and the count.
|
|
36
|
+
*/
|
|
37
|
+
ReactionBar.Reaction = function ReactionBarReaction(handle) {
|
|
38
|
+
return () => {
|
|
39
|
+
let { emoji, image, label, count, pressed = false, toggle = DEFAULT_TOGGLE, mix, type = "submit", ...rest } = handle.props;
|
|
40
|
+
return (_jsxs("button", { ...rest, type: type, name: toggle.name, value: pressed ? toggle.off : toggle.on, "aria-pressed": pressed ? "true" : "false", "data-slot": "reaction", "data-emoji": emoji, "data-toggle-on": toggle.on, "data-toggle-off": toggle.off, mix: mergeMix([
|
|
41
|
+
inlineFlex(),
|
|
42
|
+
rounded("full"),
|
|
43
|
+
raw({
|
|
44
|
+
alignItems: "center",
|
|
45
|
+
gap: "0.3125rem",
|
|
46
|
+
blockSize: "1.625rem",
|
|
47
|
+
paddingInline: "0.5rem",
|
|
48
|
+
border: "1px solid var(--ui-neutral-border)",
|
|
49
|
+
backgroundColor: "var(--ui-neutral-bg-tint)",
|
|
50
|
+
color: "var(--ui-neutral-fg)",
|
|
51
|
+
font: "inherit",
|
|
52
|
+
fontSize: "0.75rem",
|
|
53
|
+
fontWeight: "600",
|
|
54
|
+
lineHeight: "1",
|
|
55
|
+
cursor: "pointer",
|
|
56
|
+
transition: "background-color 120ms, border-color 120ms",
|
|
57
|
+
"& > [data-reaction-emoji-glyph]": {
|
|
58
|
+
display: "inline-grid",
|
|
59
|
+
placeItems: "center",
|
|
60
|
+
fontSize: "0.9375rem",
|
|
61
|
+
},
|
|
62
|
+
"& > [data-reaction-emoji-glyph] > img": {
|
|
63
|
+
inlineSize: "1.0625rem",
|
|
64
|
+
blockSize: "1.0625rem",
|
|
65
|
+
objectFit: "contain",
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
tabularNums(),
|
|
69
|
+
when("&:hover", raw({
|
|
70
|
+
borderColor: "var(--ui-neutral-border-strong)",
|
|
71
|
+
backgroundColor: "var(--ui-neutral-bg-tint-hover)",
|
|
72
|
+
})),
|
|
73
|
+
when("&[aria-pressed='true']", raw({
|
|
74
|
+
borderColor: "var(--ui-brand-border-strong)",
|
|
75
|
+
backgroundColor: "var(--ui-brand-bg-tint)",
|
|
76
|
+
color: "var(--ui-brand-fg-emphasis)",
|
|
77
|
+
})),
|
|
78
|
+
when("&:focus-visible", raw({ outline: "2px solid var(--ui-brand-ring)", outlineOffset: "1px" })),
|
|
79
|
+
motionReduce(raw({ transition: "none" })),
|
|
80
|
+
], mix), children: [_jsx("span", { "data-reaction-emoji-glyph": "", "aria-hidden": "true", children: image === undefined ? emoji : _jsx("img", { src: image, alt: "", draggable: "false" }) }), _jsx("span", { "data-reaction-label": "", mix: [visuallyHidden()], children: label }), _jsx("span", { "data-reaction-count": "", children: count })] }));
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Renders the trailing slot for adding a reaction, where an emoji picker's trigger sits. Its
|
|
85
|
+
* controls are pill-sized to match the chips beside them.
|
|
86
|
+
*/
|
|
87
|
+
ReactionBar.Add = function ReactionBarAdd(handle) {
|
|
88
|
+
return () => {
|
|
89
|
+
let { children, mix, ...rest } = handle.props;
|
|
90
|
+
return (_jsx("span", { ...rest, "data-slot": "reaction-add", mix: mergeMix([
|
|
91
|
+
inlineFlex(),
|
|
92
|
+
raw({
|
|
93
|
+
"& :is(button, a)": {
|
|
94
|
+
blockSize: "1.625rem",
|
|
95
|
+
minInlineSize: "1.625rem",
|
|
96
|
+
borderRadius: "999px",
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
], mix), children: children }));
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Renders the inert `<template>` a new chip is cloned from, so a reaction picked from an emoji
|
|
104
|
+
* picker appears in the row at once, posting through the same form a server-drawn chip uses.
|
|
105
|
+
*/
|
|
106
|
+
ReactionBar.Template = function ReactionBarTemplate(handle) {
|
|
107
|
+
return () => _jsx("template", { "data-reaction-template": "", children: handle.props.children });
|
|
108
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The line under a conversation saying who is writing right now: three pulsing dots and
|
|
3
|
+
* "Mira is typing…". It is a polite live region that keeps its height while empty, so the log
|
|
4
|
+
* above never jumps as people start and stop typing.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Handle, Props as TagProps, RemixNode } from "remix/component";
|
|
10
|
+
/** Prop types for {@link TypingIndicator}, and the sentences {@link typingLabel} picks from. */
|
|
11
|
+
export declare namespace TypingIndicator {
|
|
12
|
+
/** Props accepted by {@link TypingIndicator}. */
|
|
13
|
+
interface Props extends TagProps<"div"> {
|
|
14
|
+
/**
|
|
15
|
+
* What is said, such as `typingLabel(names, labels)`; empty while nobody types, which
|
|
16
|
+
* hides the dots and keeps the line's height.
|
|
17
|
+
*/
|
|
18
|
+
children?: RemixNode;
|
|
19
|
+
}
|
|
20
|
+
/** The sentences {@link typingLabel} picks from, so each locale words its own. */
|
|
21
|
+
interface Labels {
|
|
22
|
+
one: (name: string) => string;
|
|
23
|
+
two: (first: string, second: string) => string;
|
|
24
|
+
many: (count: number) => string;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Renders the status line. While it has text the dots pulse in turn; under reduced motion
|
|
29
|
+
* they hold still. Its `role="status"` announces each change once.
|
|
30
|
+
*
|
|
31
|
+
* @example <TypingIndicator>{typingLabel(["Mira"], labels)}</TypingIndicator>
|
|
32
|
+
*/
|
|
33
|
+
export declare function TypingIndicator(handle: Handle<TypingIndicator.Props>): () => import("remix/component").RemixElement;
|
|
34
|
+
/**
|
|
35
|
+
* Words who is typing: one name, two names, or a count once three or more type at once.
|
|
36
|
+
*
|
|
37
|
+
* @param names Who is typing, in the order they started.
|
|
38
|
+
* @param labels The sentences for each case.
|
|
39
|
+
* @returns The sentence, or `""` when nobody is typing.
|
|
40
|
+
* @example typingLabel(["Mira"], labels) // "Mira is typing…"
|
|
41
|
+
*/
|
|
42
|
+
export declare function typingLabel(names: readonly string[], labels: TypingIndicator.Labels): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "remix/component/jsx-runtime";
|
|
2
|
+
import { keyframes } from "@sdxc/u/animation";
|
|
3
|
+
import { fg } from "@sdxc/u/color";
|
|
4
|
+
import { mergeMix, raw } from "@sdxc/u/general";
|
|
5
|
+
import { hstack, inlineFlex } from "@sdxc/u/layout";
|
|
6
|
+
import { motionReduce } from "@sdxc/u/responsive";
|
|
7
|
+
import { when } from "@sdxc/u/state";
|
|
8
|
+
import { fontSize, truncate } from "@sdxc/u/typography";
|
|
9
|
+
import { attrs } from "remix/component";
|
|
10
|
+
/** The keyframes each dot rises and fades through, offset per dot. */
|
|
11
|
+
const DOT_KEYFRAMES = "ui-typing-indicator-dot";
|
|
12
|
+
/**
|
|
13
|
+
* Renders the status line. While it has text the dots pulse in turn; under reduced motion
|
|
14
|
+
* they hold still. Its `role="status"` announces each change once.
|
|
15
|
+
*
|
|
16
|
+
* @example <TypingIndicator>{typingLabel(["Mira"], labels)}</TypingIndicator>
|
|
17
|
+
*/
|
|
18
|
+
export function TypingIndicator(handle) {
|
|
19
|
+
return () => {
|
|
20
|
+
let { children, mix, ...rest } = handle.props;
|
|
21
|
+
let empty = children === undefined || children === null || children === "";
|
|
22
|
+
return (_jsxs("div", { ...rest, "data-slot": "typing-indicator", "data-empty": empty ? "" : undefined, mix: mergeMix([
|
|
23
|
+
attrs({ role: "status", "aria-live": "polite" }),
|
|
24
|
+
hstack({ gap: 2, align: "center" }),
|
|
25
|
+
fontSize("xs"),
|
|
26
|
+
fg("neutral.muted"),
|
|
27
|
+
raw({ minBlockSize: "1.25rem", minInlineSize: "0" }),
|
|
28
|
+
when('&[data-empty] > [data-slot="typing-dots"]', raw({ visibility: "hidden" })),
|
|
29
|
+
], mix), children: [_jsxs("span", { "data-slot": "typing-dots", "aria-hidden": "true", mix: [
|
|
30
|
+
keyframes(DOT_KEYFRAMES, {
|
|
31
|
+
"0%, 60%, 100%": { transform: "translateY(0)", opacity: "0.45" },
|
|
32
|
+
"30%": { transform: "translateY(-0.1875rem)", opacity: "1" },
|
|
33
|
+
}),
|
|
34
|
+
inlineFlex(),
|
|
35
|
+
raw({
|
|
36
|
+
gap: "0.1875rem",
|
|
37
|
+
"& > span": {
|
|
38
|
+
inlineSize: "0.3125rem",
|
|
39
|
+
blockSize: "0.3125rem",
|
|
40
|
+
borderRadius: "999px",
|
|
41
|
+
backgroundColor: "currentColor",
|
|
42
|
+
animation: `${DOT_KEYFRAMES} 1.2s ease-in-out infinite`,
|
|
43
|
+
},
|
|
44
|
+
"& > span:nth-child(2)": { animationDelay: "0.15s" },
|
|
45
|
+
"& > span:nth-child(3)": { animationDelay: "0.3s" },
|
|
46
|
+
}),
|
|
47
|
+
motionReduce(raw({ "& > span": { animation: "none", opacity: "0.7" } })),
|
|
48
|
+
], children: [_jsx("span", {}), _jsx("span", {}), _jsx("span", {})] }), _jsx("span", { "data-slot": "typing-text", mix: [truncate()], children: children })] }));
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Words who is typing: one name, two names, or a count once three or more type at once.
|
|
53
|
+
*
|
|
54
|
+
* @param names Who is typing, in the order they started.
|
|
55
|
+
* @param labels The sentences for each case.
|
|
56
|
+
* @returns The sentence, or `""` when nobody is typing.
|
|
57
|
+
* @example typingLabel(["Mira"], labels) // "Mira is typing…"
|
|
58
|
+
*/
|
|
59
|
+
export function typingLabel(names, labels) {
|
|
60
|
+
let [first, second] = names;
|
|
61
|
+
if (first === undefined)
|
|
62
|
+
return "";
|
|
63
|
+
if (second === undefined)
|
|
64
|
+
return labels.one(first);
|
|
65
|
+
if (names.length === 2)
|
|
66
|
+
return labels.two(first, second);
|
|
67
|
+
return labels.many(names.length);
|
|
68
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edits a composer's text field the way typing would: the composer islands find the field
|
|
3
|
+
* they act on and replace a range of its text through the browser's editing commands, so
|
|
4
|
+
* each change lands on the native undo stack and fires the field's `input` event.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The text field an island acts on: the one whose `id` is `target`, or else the
|
|
11
|
+
* `Composer.Input` of the form the island sits in.
|
|
12
|
+
*
|
|
13
|
+
* @param from An element of the island, which locates its form.
|
|
14
|
+
* @param target The `id` of a `<textarea>` elsewhere on the page.
|
|
15
|
+
* @returns The field, or `null` when neither names a `<textarea>`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function findComposerInput(from: Element, target?: string): HTMLTextAreaElement | null;
|
|
18
|
+
/**
|
|
19
|
+
* Replaces `start`–`end` of the field's text with `text` and leaves the caret after it. The
|
|
20
|
+
* edit goes through `execCommand`, which Undo reverts; where the browser refuses it, the text
|
|
21
|
+
* is set directly and an `input` event is dispatched so listeners hear the change either way.
|
|
22
|
+
*
|
|
23
|
+
* @param input The field to edit, which takes focus.
|
|
24
|
+
* @param start Where the replaced range starts.
|
|
25
|
+
* @param end Where it ends; equal to `start` for an insertion.
|
|
26
|
+
* @param text What goes in its place.
|
|
27
|
+
*/
|
|
28
|
+
export declare function replaceText(input: HTMLTextAreaElement, start: number, end: number, text: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Turns the field's text into `next` with the smallest replacement that does it, then selects
|
|
31
|
+
* `start`–`end` of the new text, so a formatting change undoes as one step.
|
|
32
|
+
*
|
|
33
|
+
* @param input The field to edit.
|
|
34
|
+
* @param next The whole text it should hold.
|
|
35
|
+
* @param start The selection's start in `next`.
|
|
36
|
+
* @param end The selection's end in `next`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function rewriteText(input: HTMLTextAreaElement, next: string, start: number, end: number): void;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edits a composer's text field the way typing would: the composer islands find the field
|
|
3
|
+
* they act on and replace a range of its text through the browser's editing commands, so
|
|
4
|
+
* each change lands on the native undo stack and fires the field's `input` event.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { COMPOSER_INPUT_SLOT } from "../composer.js";
|
|
10
|
+
/**
|
|
11
|
+
* The text field an island acts on: the one whose `id` is `target`, or else the
|
|
12
|
+
* `Composer.Input` of the form the island sits in.
|
|
13
|
+
*
|
|
14
|
+
* @param from An element of the island, which locates its form.
|
|
15
|
+
* @param target The `id` of a `<textarea>` elsewhere on the page.
|
|
16
|
+
* @returns The field, or `null` when neither names a `<textarea>`.
|
|
17
|
+
*/
|
|
18
|
+
export function findComposerInput(from, target) {
|
|
19
|
+
if (target !== undefined) {
|
|
20
|
+
let named = from.ownerDocument.getElementById(target);
|
|
21
|
+
return named instanceof HTMLTextAreaElement ? named : null;
|
|
22
|
+
}
|
|
23
|
+
return (from
|
|
24
|
+
.closest("form")
|
|
25
|
+
?.querySelector(`[data-slot="${COMPOSER_INPUT_SLOT}"]`) ?? null);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Replaces `start`–`end` of the field's text with `text` and leaves the caret after it. The
|
|
29
|
+
* edit goes through `execCommand`, which Undo reverts; where the browser refuses it, the text
|
|
30
|
+
* is set directly and an `input` event is dispatched so listeners hear the change either way.
|
|
31
|
+
*
|
|
32
|
+
* @param input The field to edit, which takes focus.
|
|
33
|
+
* @param start Where the replaced range starts.
|
|
34
|
+
* @param end Where it ends; equal to `start` for an insertion.
|
|
35
|
+
* @param text What goes in its place.
|
|
36
|
+
*/
|
|
37
|
+
export function replaceText(input, start, end, text) {
|
|
38
|
+
let expected = input.value.slice(0, start) + text + input.value.slice(end);
|
|
39
|
+
input.focus();
|
|
40
|
+
input.setSelectionRange(start, end);
|
|
41
|
+
let command = text === "" ? "delete" : "insertText";
|
|
42
|
+
let applied = start === end && text === "" ? true : execute(input, command, text);
|
|
43
|
+
if (applied && input.value === expected)
|
|
44
|
+
return;
|
|
45
|
+
input.value = expected;
|
|
46
|
+
input.setSelectionRange(start + text.length, start + text.length);
|
|
47
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Turns the field's text into `next` with the smallest replacement that does it, then selects
|
|
51
|
+
* `start`–`end` of the new text, so a formatting change undoes as one step.
|
|
52
|
+
*
|
|
53
|
+
* @param input The field to edit.
|
|
54
|
+
* @param next The whole text it should hold.
|
|
55
|
+
* @param start The selection's start in `next`.
|
|
56
|
+
* @param end The selection's end in `next`.
|
|
57
|
+
*/
|
|
58
|
+
export function rewriteText(input, next, start, end) {
|
|
59
|
+
let current = input.value;
|
|
60
|
+
let prefix = 0;
|
|
61
|
+
let limit = Math.min(current.length, next.length);
|
|
62
|
+
while (prefix < limit && current[prefix] === next[prefix])
|
|
63
|
+
prefix += 1;
|
|
64
|
+
let suffix = 0;
|
|
65
|
+
while (suffix < limit - prefix &&
|
|
66
|
+
current[current.length - 1 - suffix] === next[next.length - 1 - suffix]) {
|
|
67
|
+
suffix += 1;
|
|
68
|
+
}
|
|
69
|
+
if (current !== next) {
|
|
70
|
+
replaceText(input, prefix, current.length - suffix, next.slice(prefix, next.length - suffix));
|
|
71
|
+
}
|
|
72
|
+
input.focus();
|
|
73
|
+
input.setSelectionRange(start, end);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Runs an editing command on the focused field. `execCommand` is deprecated but remains the
|
|
77
|
+
* one way to edit a text field that the browser's undo history records.
|
|
78
|
+
*
|
|
79
|
+
* @returns Whether the browser carried the command out.
|
|
80
|
+
*/
|
|
81
|
+
function execute(input, command, text) {
|
|
82
|
+
let document = input.ownerDocument;
|
|
83
|
+
if (document.activeElement !== input || typeof document.execCommand !== "function")
|
|
84
|
+
return false;
|
|
85
|
+
return document.execCommand(command, false, text);
|
|
86
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Markdown edits a chat composer's formatting controls make: wrapping a selection in
|
|
3
|
+
* inline markers, a code fence or a link, and prefixing lines as a quote or a list. Pure
|
|
4
|
+
* text in, text and selection out, so every edit is testable without a field.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** A Markdown edit a composer's formatting controls offer and {@link applyFormat} performs. */
|
|
10
|
+
export type FormatAction = "bold" | "italic" | "strike" | "code" | "link" | "quote" | "list";
|
|
11
|
+
/** A field's text after a format, with the range to select in it. */
|
|
12
|
+
export interface FormattedText {
|
|
13
|
+
value: string;
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Applies a Markdown format to `start`–`end` of `value`. Applying an action to text it already
|
|
19
|
+
* formats removes the format, so each button toggles; an empty selection writes the markers
|
|
20
|
+
* with the caret between them.
|
|
21
|
+
*
|
|
22
|
+
* @param value The field's text.
|
|
23
|
+
* @param start The selection's start.
|
|
24
|
+
* @param end The selection's end.
|
|
25
|
+
* @param action The format to apply.
|
|
26
|
+
* @returns The new text and the range to select in it.
|
|
27
|
+
* @example applyFormat("hi there", 3, 8, "bold") // { value: "hi **there**", start: 5, end: 10 }
|
|
28
|
+
* @example applyFormat("a\nb", 0, 3, "list") // { value: "- a\n- b", start: 0, end: 7 }
|
|
29
|
+
*/
|
|
30
|
+
export declare function applyFormat(value: string, start: number, end: number, action: FormatAction): FormattedText;
|