@sdxc/ui 2026.11.10 → 2026.11.14
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 +92 -45
- package/dist/app/app-shell-toggle.d.ts +2 -0
- package/dist/app/app-shell-toggle.js +5 -2
- package/dist/app/app-shell.d.ts +25 -1
- package/dist/app/app-shell.js +73 -38
- package/dist/app/auto-refresh.d.ts +2 -0
- package/dist/app/auto-refresh.js +3 -3
- package/dist/app/behaviors/refresh-schedule.d.ts +8 -3
- package/dist/app/behaviors/refresh-schedule.js +4 -3
- package/dist/app/board.d.ts +123 -0
- package/dist/app/board.js +224 -0
- package/dist/app/chart.d.ts +2 -2
- package/dist/app/chart.js +7 -3
- package/dist/app/check-runs.d.ts +116 -0
- package/dist/app/check-runs.js +201 -0
- package/dist/app/code-view.d.ts +172 -0
- package/dist/app/code-view.js +414 -0
- package/dist/app/command-palette.d.ts +38 -3
- package/dist/app/command-palette.js +53 -5
- package/dist/app/contribution-graph.d.ts +106 -0
- package/dist/app/contribution-graph.js +289 -0
- package/dist/app/detail-sheet.d.ts +7 -0
- package/dist/app/detail-sheet.js +7 -7
- package/dist/app/diff.d.ts +200 -0
- package/dist/app/diff.js +702 -0
- package/dist/app/filter-bar.d.ts +20 -0
- package/dist/app/filter-bar.js +35 -15
- package/dist/app/filter-menu.d.ts +144 -0
- package/dist/app/filter-menu.js +480 -0
- package/dist/app/gantt.d.ts +108 -0
- package/dist/app/gantt.js +420 -0
- package/dist/app/index.d.ts +19 -0
- package/dist/app/index.js +19 -0
- package/dist/app/log-viewer.d.ts +120 -0
- package/dist/app/log-viewer.js +384 -0
- package/dist/app/merge-box.d.ts +97 -0
- package/dist/app/merge-box.js +227 -0
- package/dist/app/mixins/app-shell-controls.d.ts +4 -1
- package/dist/app/mixins/app-shell-controls.js +64 -4
- package/dist/app/mixins/auto-refresh.d.ts +5 -2
- package/dist/app/mixins/auto-refresh.js +9 -3
- package/dist/app/mixins/close-popover-on-submit.d.ts +16 -0
- package/dist/app/mixins/close-popover-on-submit.js +32 -0
- package/dist/app/mixins/code-view-selection.d.ts +60 -0
- package/dist/app/mixins/code-view-selection.js +276 -0
- package/dist/app/mixins/command-palette.d.ts +15 -4
- package/dist/app/mixins/command-palette.js +94 -6
- package/dist/app/mixins/contribution-graph-keys.d.ts +19 -0
- package/dist/app/mixins/contribution-graph-keys.js +155 -0
- package/dist/app/mixins/diff-interactions.d.ts +72 -0
- package/dist/app/mixins/diff-interactions.js +269 -0
- package/dist/app/mixins/filter-menu-keys.d.ts +41 -0
- package/dist/app/mixins/filter-menu-keys.js +91 -0
- package/dist/app/mixins/gantt-today.d.ts +17 -0
- package/dist/app/mixins/gantt-today.js +50 -0
- package/dist/app/mixins/log-viewer.d.ts +29 -0
- package/dist/app/mixins/log-viewer.js +333 -0
- package/dist/app/mixins/optimistic-toggle-sync.d.ts +5 -0
- package/dist/app/mixins/optimistic-toggle-sync.js +25 -1
- package/dist/app/mixins/save-bar-sync.d.ts +7 -1
- package/dist/app/mixins/save-bar-sync.js +23 -4
- package/dist/app/mixins/save-status-sync.js +23 -1
- package/dist/app/mixins/split-view.js +1 -1
- package/dist/app/mixins/submit-on-close.d.ts +17 -0
- package/dist/app/mixins/submit-on-close.js +52 -0
- package/dist/app/mixins/tree-filter.d.ts +44 -0
- package/dist/app/mixins/tree-filter.js +111 -0
- package/dist/app/mixins/tree-navigation.d.ts +50 -0
- package/dist/app/mixins/tree-navigation.js +216 -0
- package/dist/app/optimistic-toggle.d.ts +8 -0
- package/dist/app/optimistic-toggle.js +3 -2
- package/dist/app/page-header.d.ts +18 -3
- package/dist/app/page-header.js +105 -50
- package/dist/app/review-thread.d.ts +115 -0
- package/dist/app/review-thread.js +116 -0
- package/dist/app/save-bar.d.ts +5 -0
- package/dist/app/save-bar.js +1 -1
- package/dist/app/settings-layout.d.ts +5 -0
- package/dist/app/settings-layout.js +5 -5
- package/dist/app/skeleton.d.ts +9 -0
- package/dist/app/skeleton.js +28 -0
- package/dist/app/split-view.d.ts +4 -0
- package/dist/app/split-view.js +3 -3
- package/dist/app/styles/code-tokens.d.ts +24 -0
- package/dist/app/styles/code-tokens.js +47 -0
- package/dist/app/tab-bar.d.ts +59 -0
- package/dist/app/tab-bar.js +111 -0
- package/dist/app/tree.d.ts +111 -14
- package/dist/app/tree.js +202 -15
- package/dist/app/utils/ansi.d.ts +55 -0
- package/dist/app/utils/ansi.js +157 -0
- package/dist/app/utils/diff-rows.d.ts +82 -0
- package/dist/app/utils/diff-rows.js +209 -0
- package/dist/app/utils/fuzzy-path.d.ts +58 -0
- package/dist/app/utils/fuzzy-path.js +202 -0
- package/dist/app/utils/line-range.d.ts +48 -0
- package/dist/app/utils/line-range.js +61 -0
- package/dist/app/utils/log-lines.d.ts +107 -0
- package/dist/app/utils/log-lines.js +170 -0
- package/dist/app/utils/tree-filter.d.ts +19 -0
- package/dist/app/utils/tree-filter.js +26 -0
- package/dist/app/view-options.d.ts +2 -0
- package/dist/app/view-options.js +2 -2
- package/dist/chat/activity.d.ts +72 -0
- package/dist/chat/activity.js +184 -0
- package/dist/chat/composer-submit.d.ts +38 -0
- package/dist/chat/composer-submit.js +44 -0
- package/dist/chat/composer.d.ts +47 -0
- package/dist/chat/composer.js +100 -0
- package/dist/chat/index.d.ts +6 -0
- package/dist/chat/index.js +6 -0
- package/dist/chat/mixins/composer-send.d.ts +32 -0
- package/dist/chat/mixins/composer-send.js +121 -0
- package/dist/chat/mixins/reveal-stream.d.ts +68 -0
- package/dist/chat/mixins/reveal-stream.js +184 -0
- package/dist/chat/mixins/stream-target.d.ts +18 -0
- package/dist/chat/mixins/stream-target.js +38 -0
- package/dist/components/button.js +7 -1
- package/dist/components/character-count.d.ts +44 -0
- package/dist/components/character-count.js +68 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/label-chip.d.ts +42 -0
- package/dist/components/label-chip.js +86 -0
- package/dist/components/property-list.d.ts +9 -2
- package/dist/components/property-list.js +11 -6
- package/dist/components/textarea.js +6 -1
- package/dist/components/timeline.d.ts +62 -5
- package/dist/components/timeline.js +124 -5
- package/dist/docs/code-block.js +8 -31
- package/dist/docs/file-tree.js +3 -48
- package/dist/landing/case-study.d.ts +79 -0
- package/dist/landing/case-study.js +162 -0
- package/dist/landing/contributor-wall.d.ts +72 -0
- package/dist/landing/contributor-wall.js +129 -0
- package/dist/landing/countdown.d.ts +88 -0
- package/dist/landing/countdown.js +91 -0
- package/dist/landing/episode-player.d.ts +87 -0
- package/dist/landing/episode-player.js +113 -0
- package/dist/landing/faq-band.d.ts +3 -2
- package/dist/landing/faq-band.js +4 -3
- package/dist/landing/feature-band.d.ts +8 -0
- package/dist/landing/feature-band.js +9 -3
- package/dist/landing/index.d.ts +9 -0
- package/dist/landing/index.js +9 -0
- package/dist/landing/landing-header.js +15 -4
- package/dist/landing/mixins/countdown-tick.d.ts +29 -0
- package/dist/landing/mixins/countdown-tick.js +65 -0
- package/dist/landing/mixins/usage-estimate-live.d.ts +32 -0
- package/dist/landing/mixins/usage-estimate-live.js +120 -0
- package/dist/landing/phone-fan.d.ts +38 -0
- package/dist/landing/phone-fan.js +89 -0
- package/dist/landing/phone-frame.d.ts +48 -0
- package/dist/landing/phone-frame.js +41 -0
- package/dist/landing/price-list.d.ts +68 -0
- package/dist/landing/price-list.js +125 -0
- package/dist/landing/scroll-scene.d.ts +59 -0
- package/dist/landing/scroll-scene.js +70 -0
- package/dist/landing/sponsor-wall.d.ts +30 -6
- package/dist/landing/sponsor-wall.js +70 -14
- package/dist/landing/typed-terminal.d.ts +24 -6
- package/dist/landing/typed-terminal.js +22 -14
- package/dist/landing/usage-estimate.d.ts +127 -0
- package/dist/landing/usage-estimate.js +164 -0
- package/dist/landing/utils/countdown.d.ts +33 -0
- package/dist/landing/utils/countdown.js +42 -0
- package/dist/landing/utils/pause-toggle.d.ts +2 -1
- package/dist/mixins/character-count.d.ts +62 -0
- package/dist/mixins/character-count.js +139 -0
- package/dist/mixins/index.d.ts +6 -2
- package/dist/mixins/index.js +6 -2
- package/dist/mixins/invoker-fields.d.ts +18 -0
- package/dist/mixins/invoker-fields.js +60 -0
- package/dist/mixins/media-sync.d.ts +58 -0
- package/dist/mixins/media-sync.js +102 -0
- package/dist/mixins/menu-keys.d.ts +11 -0
- package/dist/mixins/menu-keys.js +79 -70
- package/dist/mixins/sortable.d.ts +96 -0
- package/dist/mixins/sortable.js +433 -0
- package/dist/utils/code-lines.d.ts +26 -0
- package/dist/utils/code-lines.js +29 -0
- package/dist/utils/file-icon.d.ts +31 -0
- package/dist/utils/file-icon.js +60 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/write-cookie.d.ts +15 -15
- package/dist/utils/write-cookie.js +10 -16
- package/dist/video/index.d.ts +11 -0
- package/dist/video/index.js +11 -0
- package/dist/video/mixins/video-player-sync.d.ts +27 -0
- package/dist/video/mixins/video-player-sync.js +413 -0
- package/dist/video/utils/timeline.d.ts +55 -0
- package/dist/video/utils/timeline.js +90 -0
- package/dist/video/video-player.d.ts +261 -0
- package/dist/video/video-player.js +927 -0
- package/package.json +6 -3
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: dragging an item between or within lists, and moving one from the keyboard, need pointer
|
|
3
|
+
* and key listeners. No-JS baseline: each item's own move form, or a menu inside it, still moves it
|
|
4
|
+
* with a plain post, and the lists stay readable markup.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { createMixin } from "remix/component";
|
|
10
|
+
import { prefersReducedMotion } from "../utils/prefers-reduced-motion.js";
|
|
11
|
+
/** Attribute on the element holding every list the mixin moves items between. */
|
|
12
|
+
export const SORTABLE_ATTRIBUTE = "data-sortable";
|
|
13
|
+
/** Attribute a list carries its value on, which a move sends in the item's form. */
|
|
14
|
+
export const SORTABLE_LIST_ATTRIBUTE = "data-sortable-list";
|
|
15
|
+
/** Attribute on the element inside a list that holds its items; the list itself without one. */
|
|
16
|
+
export const SORTABLE_ITEMS_ATTRIBUTE = "data-sortable-items";
|
|
17
|
+
/** Attribute an item carries its value on, unique across the lists. */
|
|
18
|
+
export const SORTABLE_ITEM_ATTRIBUTE = "data-sortable-item";
|
|
19
|
+
/** Attribute an item's move form names its item with, so a move finds the form to post. */
|
|
20
|
+
export const SORTABLE_FORM_ATTRIBUTE = "data-sortable-form";
|
|
21
|
+
/**
|
|
22
|
+
* Attribute a move form names its list field with. A move appends that field after the form's
|
|
23
|
+
* own, with the list's value, and the next render of the form drops it again.
|
|
24
|
+
*/
|
|
25
|
+
export const SORTABLE_FIELD_ATTRIBUTE = "data-sortable-field";
|
|
26
|
+
/**
|
|
27
|
+
* Attribute a move form names its position field with. A move sends the value of the item it
|
|
28
|
+
* lands before in that field, or an empty value when it lands last. A form without one moves
|
|
29
|
+
* its item only between lists, to the top.
|
|
30
|
+
*/
|
|
31
|
+
export const SORTABLE_POSITION_ATTRIBUTE = "data-sortable-position";
|
|
32
|
+
/** Attribute on a list's count, which a move between lists keeps current until the page answers. */
|
|
33
|
+
export const SORTABLE_COUNT_ATTRIBUTE = "data-sortable-count";
|
|
34
|
+
/** Attribute on a list's title, which a keyboard move announces. */
|
|
35
|
+
export const SORTABLE_TITLE_ATTRIBUTE = "data-sortable-title";
|
|
36
|
+
/** Attribute on the live region a keyboard move is announced through. */
|
|
37
|
+
export const SORTABLE_STATUS_ATTRIBUTE = "data-sortable-status";
|
|
38
|
+
/** Attribute on the element that scrolls while the pointer rests near its edge mid-drag. */
|
|
39
|
+
export const SORTABLE_SCROLLER_ATTRIBUTE = "data-sortable-scroller";
|
|
40
|
+
/** Attribute set on the root for as long as a drag lasts. */
|
|
41
|
+
export const SORTABLE_ACTIVE_ATTRIBUTE = "data-sortable-active";
|
|
42
|
+
/** Attribute set on the item being dragged, for as long as the drag lasts. */
|
|
43
|
+
export const SORTABLE_DRAGGING_ATTRIBUTE = "data-sortable-dragging";
|
|
44
|
+
/** Attribute set on another list while the dragged item would land in it. */
|
|
45
|
+
export const SORTABLE_TARGET_ATTRIBUTE = "data-sortable-target";
|
|
46
|
+
/** Attribute on the copy of the item that follows the pointer. */
|
|
47
|
+
export const SORTABLE_GHOST_ATTRIBUTE = "data-sortable-ghost";
|
|
48
|
+
/** How far a press travels before it becomes a drag, so a plain click still opens the item. */
|
|
49
|
+
const DRAG_THRESHOLD_PX = 5;
|
|
50
|
+
/** How close to the scroller's edge the pointer comes before it scrolls toward it. */
|
|
51
|
+
const EDGE_PX = 48;
|
|
52
|
+
/** Elements a press on starts nothing from, so an item's own controls keep working. */
|
|
53
|
+
const INTERACTIVE = "button, input, select, textarea, summary, label, [popover], [contenteditable]";
|
|
54
|
+
/** DOM event type {@link SortableMoveEvent} is dispatched under. */
|
|
55
|
+
const MOVE_EVENT = "ui:sortable-move";
|
|
56
|
+
/**
|
|
57
|
+
* Dispatched on an item once it is dropped or moved by key, before its move form posts;
|
|
58
|
+
* `preventDefault()` keeps the item in place and the form from posting, for a consumer that
|
|
59
|
+
* saves the move itself.
|
|
60
|
+
*/
|
|
61
|
+
export class SortableMoveEvent extends Event {
|
|
62
|
+
/** The moved item's value. */
|
|
63
|
+
item;
|
|
64
|
+
/** The list it left. */
|
|
65
|
+
from;
|
|
66
|
+
/** The list it landed in, the same as `from` for a move within a list. */
|
|
67
|
+
to;
|
|
68
|
+
/** The item it landed before, `null` when it landed last or its form takes no position. */
|
|
69
|
+
before;
|
|
70
|
+
/**
|
|
71
|
+
* @param init The item, the two lists, and the item it landed before.
|
|
72
|
+
*/
|
|
73
|
+
constructor(init) {
|
|
74
|
+
super(MOVE_EVENT, { bubbles: true, cancelable: true });
|
|
75
|
+
this.item = init.item;
|
|
76
|
+
this.from = init.from;
|
|
77
|
+
this.to = init.to;
|
|
78
|
+
this.before = init.before ?? null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Moves items within and between the lists inside the nearest {@link SORTABLE_ATTRIBUTE} root.
|
|
83
|
+
* A mouse or pen press on an item that travels past a few pixels lifts it under a ghost, places
|
|
84
|
+
* it between the items under the pointer, and posts its move form on release; Escape puts it
|
|
85
|
+
* back. Shift+ArrowUp/Down move the focused item past its neighbour, and Shift+ArrowLeft/Right to
|
|
86
|
+
* the top of the list on either side. A touch press scrolls as usual.
|
|
87
|
+
*
|
|
88
|
+
* @example <span hidden mix={[sortable({ moved: "Moved to {list}" })]} />
|
|
89
|
+
*/
|
|
90
|
+
export const sortable = createMixin((handle) => {
|
|
91
|
+
let controller;
|
|
92
|
+
let options = {};
|
|
93
|
+
/** Starts listening once the marker is in the page, replacing any earlier listeners. */
|
|
94
|
+
function attach(event) {
|
|
95
|
+
controller?.abort();
|
|
96
|
+
controller = new AbortController();
|
|
97
|
+
let marker = event.node;
|
|
98
|
+
connect(findRoot, readOptions, controller.signal);
|
|
99
|
+
/** The root around the marker, or `null` while the marker is detached. */
|
|
100
|
+
function findRoot() {
|
|
101
|
+
return marker.closest(`[${SORTABLE_ATTRIBUTE}]`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Stops listening, ending a drag in progress. */
|
|
105
|
+
function detach() {
|
|
106
|
+
controller?.abort();
|
|
107
|
+
controller = undefined;
|
|
108
|
+
}
|
|
109
|
+
/** The latest options, read at each keyboard move. */
|
|
110
|
+
function readOptions() {
|
|
111
|
+
return options;
|
|
112
|
+
}
|
|
113
|
+
handle.addEventListener("insert", attach);
|
|
114
|
+
handle.addEventListener("remove", detach);
|
|
115
|
+
return (next) => {
|
|
116
|
+
options = next ?? {};
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* Listens for presses and keys on one root until `signal` aborts. The root is looked up from the
|
|
121
|
+
* marker on each event, so a marker inserted before its root is attached still finds it.
|
|
122
|
+
*
|
|
123
|
+
* @param findRoot Returns the root, or `null` while the marker is detached.
|
|
124
|
+
* @param readOptions Returns the mixin's latest options.
|
|
125
|
+
* @param signal Ends every listener, a drag in progress included.
|
|
126
|
+
*/
|
|
127
|
+
function connect(findRoot, readOptions, signal) {
|
|
128
|
+
let press;
|
|
129
|
+
/**
|
|
130
|
+
* Ends the press: clears every drag mark and puts a placed item back where it started, then
|
|
131
|
+
* moves it to where it was dropped, so a listener that prevents the move leaves it in place.
|
|
132
|
+
*/
|
|
133
|
+
function end(drop) {
|
|
134
|
+
if (!press)
|
|
135
|
+
return;
|
|
136
|
+
let { root, item, from, ghost, target, origin, positioned } = press;
|
|
137
|
+
press = undefined;
|
|
138
|
+
ghost?.remove();
|
|
139
|
+
item.removeAttribute(SORTABLE_DRAGGING_ATTRIBUTE);
|
|
140
|
+
root.removeAttribute(SORTABLE_ACTIVE_ATTRIBUTE);
|
|
141
|
+
for (let list of root.querySelectorAll(`[${SORTABLE_TARGET_ATTRIBUTE}]`)) {
|
|
142
|
+
list.removeAttribute(SORTABLE_TARGET_ATTRIBUTE);
|
|
143
|
+
}
|
|
144
|
+
if (!ghost)
|
|
145
|
+
return;
|
|
146
|
+
suppressNextClick(item);
|
|
147
|
+
if (!positioned) {
|
|
148
|
+
if (drop && target && target !== from)
|
|
149
|
+
move(item, from, target, firstItem(target, item));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
let to = item.closest(`[${SORTABLE_LIST_ATTRIBUTE}]`);
|
|
153
|
+
let moved = item.parentNode !== origin.parent || item.nextSibling !== origin.next;
|
|
154
|
+
let before = nextItem(item);
|
|
155
|
+
origin.parent?.insertBefore(item, origin.next);
|
|
156
|
+
if (drop && to && moved)
|
|
157
|
+
move(item, from, to, before);
|
|
158
|
+
}
|
|
159
|
+
/** Records a mouse or pen press on an item, outside the item's own controls. */
|
|
160
|
+
function onPointerDown(event) {
|
|
161
|
+
if (event.button !== 0 || event.pointerType === "touch")
|
|
162
|
+
return;
|
|
163
|
+
let root = findRoot();
|
|
164
|
+
if (!root)
|
|
165
|
+
return;
|
|
166
|
+
let origin = event.target instanceof Element ? event.target : null;
|
|
167
|
+
if (!origin || origin.closest(INTERACTIVE))
|
|
168
|
+
return;
|
|
169
|
+
let item = origin.closest(`[${SORTABLE_ITEM_ATTRIBUTE}]`);
|
|
170
|
+
let from = item?.closest(`[${SORTABLE_LIST_ATTRIBUTE}]`);
|
|
171
|
+
if (!item || !from || !root.contains(item))
|
|
172
|
+
return;
|
|
173
|
+
let rect = item.getBoundingClientRect();
|
|
174
|
+
press = {
|
|
175
|
+
root,
|
|
176
|
+
item,
|
|
177
|
+
from,
|
|
178
|
+
origin: { parent: item.parentNode, next: item.nextSibling },
|
|
179
|
+
positioned: takesPosition(item),
|
|
180
|
+
pointerId: event.pointerId,
|
|
181
|
+
x: event.clientX,
|
|
182
|
+
y: event.clientY,
|
|
183
|
+
offsetX: event.clientX - rect.left,
|
|
184
|
+
offsetY: event.clientY - rect.top,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** Lifts the item past the threshold, then carries the ghost and places the item under it. */
|
|
188
|
+
function onPointerMove(event) {
|
|
189
|
+
if (!press || event.pointerId !== press.pointerId)
|
|
190
|
+
return;
|
|
191
|
+
if (!press.ghost) {
|
|
192
|
+
let distance = Math.hypot(event.clientX - press.x, event.clientY - press.y);
|
|
193
|
+
if (distance < DRAG_THRESHOLD_PX)
|
|
194
|
+
return;
|
|
195
|
+
press.ghost = lift(press.item);
|
|
196
|
+
press.item.setAttribute(SORTABLE_DRAGGING_ATTRIBUTE, "");
|
|
197
|
+
press.root.setAttribute(SORTABLE_ACTIVE_ATTRIBUTE, "");
|
|
198
|
+
}
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
let tilt = prefersReducedMotion() ? "" : " rotate(1.5deg)";
|
|
201
|
+
press.ghost.style.transform = `translate(${event.clientX - press.offsetX}px, ${event.clientY - press.offsetY}px)${tilt}`;
|
|
202
|
+
let under = document.elementFromPoint(event.clientX, event.clientY);
|
|
203
|
+
let target = under?.closest(`[${SORTABLE_LIST_ATTRIBUTE}]`) ?? null;
|
|
204
|
+
if (target && !press.root.contains(target))
|
|
205
|
+
target = null;
|
|
206
|
+
if (target !== press.target) {
|
|
207
|
+
press.target?.removeAttribute(SORTABLE_TARGET_ATTRIBUTE);
|
|
208
|
+
if (target && target !== press.from)
|
|
209
|
+
target.setAttribute(SORTABLE_TARGET_ATTRIBUTE, "");
|
|
210
|
+
press.target = target;
|
|
211
|
+
}
|
|
212
|
+
if (press.positioned && target)
|
|
213
|
+
place(press.item, target, event.clientY);
|
|
214
|
+
scrollNearEdge(press.root, event.clientX, event.clientY);
|
|
215
|
+
}
|
|
216
|
+
/** Drops the item where the pointer let go. */
|
|
217
|
+
function onPointerUp() {
|
|
218
|
+
end(true);
|
|
219
|
+
}
|
|
220
|
+
/** Puts everything back when the pointer is taken away or the listeners end. */
|
|
221
|
+
function cancel() {
|
|
222
|
+
end(false);
|
|
223
|
+
}
|
|
224
|
+
/** Cancels a drag on Escape, before anything else on the page reads the key. */
|
|
225
|
+
function onKeyDown(event) {
|
|
226
|
+
if (event.key !== "Escape" || !press?.ghost)
|
|
227
|
+
return;
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
event.stopPropagation();
|
|
230
|
+
end(false);
|
|
231
|
+
}
|
|
232
|
+
/** Moves the focused item on Shift+Arrow, keeping its focus, and announces where it went. */
|
|
233
|
+
function onMoveKey(event) {
|
|
234
|
+
if (!event.shiftKey || event.altKey || event.metaKey || event.ctrlKey)
|
|
235
|
+
return;
|
|
236
|
+
if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key))
|
|
237
|
+
return;
|
|
238
|
+
let root = findRoot();
|
|
239
|
+
let focused = document.activeElement;
|
|
240
|
+
let item = focused?.closest(`[${SORTABLE_ITEM_ATTRIBUTE}]`);
|
|
241
|
+
let from = item?.closest(`[${SORTABLE_LIST_ATTRIBUTE}]`);
|
|
242
|
+
if (!root || !item || !from || !root.contains(item))
|
|
243
|
+
return;
|
|
244
|
+
if (focused?.matches("input, textarea, select, [contenteditable]"))
|
|
245
|
+
return;
|
|
246
|
+
let target = keyTarget(root, item, from, event.key);
|
|
247
|
+
if (!target)
|
|
248
|
+
return;
|
|
249
|
+
event.preventDefault();
|
|
250
|
+
move(item, from, target.list, target.before);
|
|
251
|
+
if (focused instanceof HTMLElement)
|
|
252
|
+
focused.focus({ preventScroll: false });
|
|
253
|
+
announce(root, target.list, readOptions().moved);
|
|
254
|
+
}
|
|
255
|
+
document.addEventListener("pointerdown", onPointerDown, { signal });
|
|
256
|
+
document.addEventListener("pointermove", onPointerMove, { signal });
|
|
257
|
+
document.addEventListener("pointerup", onPointerUp, { signal });
|
|
258
|
+
document.addEventListener("pointercancel", cancel, { signal });
|
|
259
|
+
document.addEventListener("keydown", onKeyDown, { signal, capture: true });
|
|
260
|
+
document.addEventListener("keydown", onMoveKey, { signal });
|
|
261
|
+
signal.addEventListener("abort", cancel);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Draws the ghost: a copy of the item fixed to the viewport at the item's size, which the
|
|
265
|
+
* pointer carries, with ids dropped so the page keeps one element per id.
|
|
266
|
+
*/
|
|
267
|
+
function lift(item) {
|
|
268
|
+
let rect = item.getBoundingClientRect();
|
|
269
|
+
let ghost = item.cloneNode(true);
|
|
270
|
+
ghost.removeAttribute(SORTABLE_ITEM_ATTRIBUTE);
|
|
271
|
+
for (let node of [ghost, ...ghost.querySelectorAll("[id]")])
|
|
272
|
+
node.removeAttribute("id");
|
|
273
|
+
ghost.setAttribute("aria-hidden", "true");
|
|
274
|
+
ghost.setAttribute(SORTABLE_GHOST_ATTRIBUTE, "");
|
|
275
|
+
Object.assign(ghost.style, {
|
|
276
|
+
position: "fixed",
|
|
277
|
+
insetBlockStart: "0",
|
|
278
|
+
insetInlineStart: "0",
|
|
279
|
+
inlineSize: `${rect.width}px`,
|
|
280
|
+
margin: "0",
|
|
281
|
+
pointerEvents: "none",
|
|
282
|
+
zIndex: "1000",
|
|
283
|
+
listStyle: "none",
|
|
284
|
+
boxShadow: "var(--ui-shadow-xl, 0 12px 28px rgb(0 0 0 / 0.18))",
|
|
285
|
+
});
|
|
286
|
+
document.body.appendChild(ghost);
|
|
287
|
+
return ghost;
|
|
288
|
+
}
|
|
289
|
+
/** Scrolls the root's scroller toward whichever of its edges the pointer rests near. */
|
|
290
|
+
function scrollNearEdge(root, x, y) {
|
|
291
|
+
let scroller = root.querySelector(`[${SORTABLE_SCROLLER_ATTRIBUTE}]`) ?? root;
|
|
292
|
+
let rect = scroller.getBoundingClientRect();
|
|
293
|
+
if (x < rect.left + EDGE_PX)
|
|
294
|
+
scroller.scrollLeft -= 12;
|
|
295
|
+
else if (x > rect.right - EDGE_PX)
|
|
296
|
+
scroller.scrollLeft += 12;
|
|
297
|
+
if (y < rect.top + EDGE_PX)
|
|
298
|
+
scroller.scrollTop -= 12;
|
|
299
|
+
else if (y > rect.bottom - EDGE_PX)
|
|
300
|
+
scroller.scrollTop += 12;
|
|
301
|
+
}
|
|
302
|
+
/** Swallows the click a drag's release fires on an item that is a link. */
|
|
303
|
+
function suppressNextClick(item) {
|
|
304
|
+
item.addEventListener("click", swallow, { capture: true, once: true });
|
|
305
|
+
setTimeout(release, 0);
|
|
306
|
+
/** Keeps the click from following the item's link. */
|
|
307
|
+
function swallow(event) {
|
|
308
|
+
event.preventDefault();
|
|
309
|
+
event.stopPropagation();
|
|
310
|
+
}
|
|
311
|
+
/** Lets later clicks through once the release's own click has passed. */
|
|
312
|
+
function release() {
|
|
313
|
+
item.removeEventListener("click", swallow, { capture: true });
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Puts the item in the target list before `before` (last when `null`) at once, bumps both counts
|
|
318
|
+
* when it changed list, then posts the item's move form with the list's value and, when the form
|
|
319
|
+
* takes one, the position, unless a listener prevented the move event.
|
|
320
|
+
*/
|
|
321
|
+
function move(item, from, to, before) {
|
|
322
|
+
let form = moveForm(item);
|
|
323
|
+
let event = new SortableMoveEvent({
|
|
324
|
+
item: item.getAttribute(SORTABLE_ITEM_ATTRIBUTE) ?? "",
|
|
325
|
+
from: from.getAttribute(SORTABLE_LIST_ATTRIBUTE) ?? "",
|
|
326
|
+
to: to.getAttribute(SORTABLE_LIST_ATTRIBUTE) ?? "",
|
|
327
|
+
before: takesPosition(item) ? (before?.getAttribute(SORTABLE_ITEM_ATTRIBUTE) ?? null) : null,
|
|
328
|
+
});
|
|
329
|
+
if (!item.dispatchEvent(event))
|
|
330
|
+
return;
|
|
331
|
+
itemsOf(to).insertBefore(item, before);
|
|
332
|
+
if (from !== to) {
|
|
333
|
+
bumpCount(from, -1);
|
|
334
|
+
bumpCount(to, 1);
|
|
335
|
+
}
|
|
336
|
+
if (!prefersReducedMotion()) {
|
|
337
|
+
item.animate?.([{ opacity: 0.4 }, { opacity: 1 }], { duration: 180, easing: "ease-out" });
|
|
338
|
+
}
|
|
339
|
+
let name = form?.getAttribute(SORTABLE_FIELD_ATTRIBUTE);
|
|
340
|
+
if (!form || !name)
|
|
341
|
+
return;
|
|
342
|
+
form.appendChild(hiddenInput(name, event.to));
|
|
343
|
+
let position = form.getAttribute(SORTABLE_POSITION_ATTRIBUTE);
|
|
344
|
+
if (position)
|
|
345
|
+
form.appendChild(hiddenInput(position, event.before ?? ""));
|
|
346
|
+
form.requestSubmit();
|
|
347
|
+
}
|
|
348
|
+
/** A hidden field, appended after the form's own so a reader of the post takes its value last. */
|
|
349
|
+
function hiddenInput(name, value) {
|
|
350
|
+
let input = document.createElement("input");
|
|
351
|
+
input.type = "hidden";
|
|
352
|
+
input.name = name;
|
|
353
|
+
input.value = value;
|
|
354
|
+
return input;
|
|
355
|
+
}
|
|
356
|
+
/** The item's own move form, when it has one. */
|
|
357
|
+
function moveForm(item) {
|
|
358
|
+
let value = item.getAttribute(SORTABLE_ITEM_ATTRIBUTE) ?? "";
|
|
359
|
+
return document.querySelector(`form[${SORTABLE_FORM_ATTRIBUTE}="${CSS.escape(value)}"]`);
|
|
360
|
+
}
|
|
361
|
+
/** Whether the item can land anywhere: it has no move form, or its form takes a position. */
|
|
362
|
+
function takesPosition(item) {
|
|
363
|
+
let form = moveForm(item);
|
|
364
|
+
return !form || form.hasAttribute(SORTABLE_POSITION_ATTRIBUTE);
|
|
365
|
+
}
|
|
366
|
+
/** The element a list's items live in. */
|
|
367
|
+
function itemsOf(list) {
|
|
368
|
+
return list.querySelector(`[${SORTABLE_ITEMS_ATTRIBUTE}]`) ?? list;
|
|
369
|
+
}
|
|
370
|
+
/** The items of a list, in order, leaving `except` out. */
|
|
371
|
+
function itemsIn(list, except) {
|
|
372
|
+
return [...itemsOf(list).children].filter((child) => child instanceof HTMLElement &&
|
|
373
|
+
child.hasAttribute(SORTABLE_ITEM_ATTRIBUTE) &&
|
|
374
|
+
child !== except);
|
|
375
|
+
}
|
|
376
|
+
/** The list's first item other than `except`, before which an item lands at the top. */
|
|
377
|
+
function firstItem(list, except) {
|
|
378
|
+
return itemsIn(list, except)[0] ?? null;
|
|
379
|
+
}
|
|
380
|
+
/** The item right after `item` in its list, or `null` when it is last. */
|
|
381
|
+
function nextItem(item) {
|
|
382
|
+
let next = item.nextElementSibling;
|
|
383
|
+
while (next && !next.hasAttribute(SORTABLE_ITEM_ATTRIBUTE))
|
|
384
|
+
next = next.nextElementSibling;
|
|
385
|
+
return next instanceof HTMLElement ? next : null;
|
|
386
|
+
}
|
|
387
|
+
/** Moves the dragged item into `list` before the first item whose middle is below `y`. */
|
|
388
|
+
function place(item, list, y) {
|
|
389
|
+
let container = itemsOf(list);
|
|
390
|
+
let before = itemsIn(list, item).find((other) => {
|
|
391
|
+
let rect = other.getBoundingClientRect();
|
|
392
|
+
return y < rect.top + rect.height / 2;
|
|
393
|
+
}) ?? null;
|
|
394
|
+
if (item.parentNode === container && nextItem(item) === before)
|
|
395
|
+
return;
|
|
396
|
+
container.insertBefore(item, before);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Where a Shift+Arrow key sends an item: the top of the list to either side, or past its
|
|
400
|
+
* neighbour above or below when it can land anywhere.
|
|
401
|
+
*/
|
|
402
|
+
function keyTarget(root, item, from, key) {
|
|
403
|
+
if (key === "ArrowLeft" || key === "ArrowRight") {
|
|
404
|
+
let lists = [...root.querySelectorAll(`[${SORTABLE_LIST_ATTRIBUTE}]`)];
|
|
405
|
+
let list = lists[lists.indexOf(from) + (key === "ArrowLeft" ? -1 : 1)];
|
|
406
|
+
return list ? { list, before: firstItem(list, item) } : null;
|
|
407
|
+
}
|
|
408
|
+
if (!takesPosition(item))
|
|
409
|
+
return null;
|
|
410
|
+
let items = itemsIn(from);
|
|
411
|
+
let index = items.indexOf(item);
|
|
412
|
+
if (key === "ArrowUp") {
|
|
413
|
+
return index > 0 ? { list: from, before: items[index - 1] } : null;
|
|
414
|
+
}
|
|
415
|
+
if (index === items.length - 1)
|
|
416
|
+
return null;
|
|
417
|
+
return { list: from, before: items[index + 2] ?? null };
|
|
418
|
+
}
|
|
419
|
+
/** Says where a keyboard move put the item, through the root's own live region. */
|
|
420
|
+
function announce(root, list, template) {
|
|
421
|
+
let region = root.querySelector(`[${SORTABLE_STATUS_ATTRIBUTE}]`);
|
|
422
|
+
if (!region || template === undefined)
|
|
423
|
+
return;
|
|
424
|
+
let title = list.querySelector(`[${SORTABLE_TITLE_ATTRIBUTE}]`)?.textContent ?? "";
|
|
425
|
+
region.textContent = template.replace("{list}", title);
|
|
426
|
+
}
|
|
427
|
+
/** Adds `delta` to a list's count, when the list shows one. */
|
|
428
|
+
function bumpCount(list, delta) {
|
|
429
|
+
let count = list.querySelector(`[${SORTABLE_COUNT_ATTRIBUTE}]`);
|
|
430
|
+
let value = Number(count?.textContent);
|
|
431
|
+
if (count && Number.isFinite(value))
|
|
432
|
+
count.textContent = String(Math.max(0, value + delta));
|
|
433
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits highlighted runs into one list of runs per source line, so every component that
|
|
3
|
+
* draws code a line at a time (a docs card, a code viewer, a diff, a log) numbers, marks
|
|
4
|
+
* and anchors lines from the same split, multi-line tokens included.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* One painted run of source. Structural, so any highlighter's `{ type, value }` runs pass
|
|
11
|
+
* straight through.
|
|
12
|
+
*/
|
|
13
|
+
export interface CodeToken {
|
|
14
|
+
type: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Splits runs at newlines (`\n` or `\r\n`) so each line owns its runs. A run spanning
|
|
19
|
+
* lines (a block comment, a template literal) becomes one run per line with the same type,
|
|
20
|
+
* and an empty line is an empty list, so the result always has one entry per source line.
|
|
21
|
+
*
|
|
22
|
+
* @param runs Runs covering the source in order, as a highlighter returns them.
|
|
23
|
+
* @returns One array of runs per line; empty pieces are dropped.
|
|
24
|
+
* @example codeLines(tokenize(source, "ts")).map((line, index) => <Line number={index + 1} runs={line} />)
|
|
25
|
+
*/
|
|
26
|
+
export declare function codeLines(runs: readonly CodeToken[]): CodeToken[][];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits highlighted runs into one list of runs per source line, so every component that
|
|
3
|
+
* draws code a line at a time (a docs card, a code viewer, a diff, a log) numbers, marks
|
|
4
|
+
* and anchors lines from the same split, multi-line tokens included.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Splits runs at newlines (`\n` or `\r\n`) so each line owns its runs. A run spanning
|
|
11
|
+
* lines (a block comment, a template literal) becomes one run per line with the same type,
|
|
12
|
+
* and an empty line is an empty list, so the result always has one entry per source line.
|
|
13
|
+
*
|
|
14
|
+
* @param runs Runs covering the source in order, as a highlighter returns them.
|
|
15
|
+
* @returns One array of runs per line; empty pieces are dropped.
|
|
16
|
+
* @example codeLines(tokenize(source, "ts")).map((line, index) => <Line number={index + 1} runs={line} />)
|
|
17
|
+
*/
|
|
18
|
+
export function codeLines(runs) {
|
|
19
|
+
let lines = [[]];
|
|
20
|
+
for (let run of runs) {
|
|
21
|
+
for (let [index, piece] of run.value.split(/\r?\n/).entries()) {
|
|
22
|
+
if (index > 0)
|
|
23
|
+
lines.push([]);
|
|
24
|
+
if (piece.length > 0)
|
|
25
|
+
lines[lines.length - 1]?.push({ type: run.type, value: piece });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return lines;
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picks the `@sdxc/icons` glyph for a file from its name, so every place that draws a file
|
|
3
|
+
* (a docs tree, a code card's header, a repository browser) shows the same kind of file
|
|
4
|
+
* with the same icon.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { FileIcon } from "@sdxc/icons";
|
|
10
|
+
/** An icon component from `@sdxc/icons`, drawn as `<Glyph size={16} aria-hidden="true" />`. */
|
|
11
|
+
export type FileIconComponent = typeof FileIcon;
|
|
12
|
+
/** Options for {@link fileIcon}. */
|
|
13
|
+
export interface FileIconOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The icon for an extension outside the built-in map, such as `FileCodeIcon` where every
|
|
16
|
+
* titled file is source code.
|
|
17
|
+
*
|
|
18
|
+
* @default FileIcon
|
|
19
|
+
*/
|
|
20
|
+
fallback?: FileIconComponent;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Picks a file's icon from its extension, treating a dotfile's name as its extension
|
|
24
|
+
* (`.env`). A name without an extension draws a plain file.
|
|
25
|
+
*
|
|
26
|
+
* @param name File name or path, such as `app/routes.ts`.
|
|
27
|
+
* @param options The icon for an unrecognised extension.
|
|
28
|
+
* @returns The icon component to render.
|
|
29
|
+
* @example let Glyph = fileIcon("package.json"); <Glyph size={16} aria-hidden="true" />
|
|
30
|
+
*/
|
|
31
|
+
export declare function fileIcon(name: string, options?: FileIconOptions): FileIconComponent;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picks the `@sdxc/icons` glyph for a file from its name, so every place that draws a file
|
|
3
|
+
* (a docs tree, a code card's header, a repository browser) shows the same kind of file
|
|
4
|
+
* with the same icon.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { FileBracesIcon, FileCodeIcon, FileCogIcon, FileIcon, FileImageIcon, FileLockIcon, FileTerminalIcon, FileTextIcon, FileTypeIcon, } from "@sdxc/icons";
|
|
10
|
+
/** Icons for file extensions whose type a reader recognises at a glance. */
|
|
11
|
+
const ICON_BY_EXTENSION = {
|
|
12
|
+
ts: FileCodeIcon,
|
|
13
|
+
tsx: FileCodeIcon,
|
|
14
|
+
js: FileCodeIcon,
|
|
15
|
+
jsx: FileCodeIcon,
|
|
16
|
+
mjs: FileCodeIcon,
|
|
17
|
+
cjs: FileCodeIcon,
|
|
18
|
+
mts: FileCodeIcon,
|
|
19
|
+
cts: FileCodeIcon,
|
|
20
|
+
html: FileCodeIcon,
|
|
21
|
+
sql: FileCodeIcon,
|
|
22
|
+
json: FileBracesIcon,
|
|
23
|
+
jsonc: FileBracesIcon,
|
|
24
|
+
md: FileTextIcon,
|
|
25
|
+
mdx: FileTextIcon,
|
|
26
|
+
txt: FileTextIcon,
|
|
27
|
+
css: FileTypeIcon,
|
|
28
|
+
png: FileImageIcon,
|
|
29
|
+
jpg: FileImageIcon,
|
|
30
|
+
jpeg: FileImageIcon,
|
|
31
|
+
gif: FileImageIcon,
|
|
32
|
+
svg: FileImageIcon,
|
|
33
|
+
webp: FileImageIcon,
|
|
34
|
+
avif: FileImageIcon,
|
|
35
|
+
ico: FileImageIcon,
|
|
36
|
+
sh: FileTerminalIcon,
|
|
37
|
+
toml: FileCogIcon,
|
|
38
|
+
yaml: FileCogIcon,
|
|
39
|
+
yml: FileCogIcon,
|
|
40
|
+
env: FileCogIcon,
|
|
41
|
+
ini: FileCogIcon,
|
|
42
|
+
lock: FileLockIcon,
|
|
43
|
+
lockb: FileLockIcon,
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Picks a file's icon from its extension, treating a dotfile's name as its extension
|
|
47
|
+
* (`.env`). A name without an extension draws a plain file.
|
|
48
|
+
*
|
|
49
|
+
* @param name File name or path, such as `app/routes.ts`.
|
|
50
|
+
* @param options The icon for an unrecognised extension.
|
|
51
|
+
* @returns The icon component to render.
|
|
52
|
+
* @example let Glyph = fileIcon("package.json"); <Glyph size={16} aria-hidden="true" />
|
|
53
|
+
*/
|
|
54
|
+
export function fileIcon(name, options = {}) {
|
|
55
|
+
let base = name.slice(name.lastIndexOf("/") + 1);
|
|
56
|
+
let dot = base.lastIndexOf(".");
|
|
57
|
+
if (dot === -1)
|
|
58
|
+
return FileIcon;
|
|
59
|
+
return ICON_BY_EXTENSION[base.slice(dot + 1).toLowerCase()] ?? options.fallback ?? FileIcon;
|
|
60
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
|
+
export * from "./code-lines.js";
|
|
9
10
|
export * from "./color-math.js";
|
|
10
11
|
export * from "./command-event.js";
|
|
11
12
|
export * from "./css-styles.js";
|
|
@@ -14,6 +15,7 @@ export * from "./disabled-selector.js";
|
|
|
14
15
|
export * from "./dispatch-change.js";
|
|
15
16
|
export * from "./eyebrow.js";
|
|
16
17
|
export * from "./field-parts.js";
|
|
18
|
+
export * from "./file-icon.js";
|
|
17
19
|
export * from "./full-turn-radians.js";
|
|
18
20
|
export * from "./geometry.js";
|
|
19
21
|
export * from "./glyph-edges.js";
|
package/dist/utils/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
|
+
export * from "./code-lines.js";
|
|
9
10
|
export * from "./color-math.js";
|
|
10
11
|
export * from "./command-event.js";
|
|
11
12
|
export * from "./css-styles.js";
|
|
@@ -14,6 +15,7 @@ export * from "./disabled-selector.js";
|
|
|
14
15
|
export * from "./dispatch-change.js";
|
|
15
16
|
export * from "./eyebrow.js";
|
|
16
17
|
export * from "./field-parts.js";
|
|
18
|
+
export * from "./file-icon.js";
|
|
17
19
|
export * from "./full-turn-radians.js";
|
|
18
20
|
export * from "./geometry.js";
|
|
19
21
|
export * from "./glyph-edges.js";
|
|
@@ -14,22 +14,22 @@
|
|
|
14
14
|
* persisted state outlives typical browsing gaps.
|
|
15
15
|
*/
|
|
16
16
|
export declare const ONE_YEAR_SECONDS: number;
|
|
17
|
+
/** Options for {@link writeCookie}. */
|
|
18
|
+
export interface WriteCookieOptions {
|
|
19
|
+
/** Seconds the cookie stays valid. @default ONE_YEAR_SECONDS */
|
|
20
|
+
maxAgeSeconds?: number;
|
|
21
|
+
/** The path the browser sends the cookie under, such as one app's own prefix. @default "/" */
|
|
22
|
+
path?: string;
|
|
23
|
+
}
|
|
17
24
|
/**
|
|
18
|
-
* Writes `value` under `name` into a `
|
|
19
|
-
*
|
|
20
|
-
* the same state, ahead of hydration ever running.
|
|
25
|
+
* Writes `value` under `name` into a `samesite=lax` cookie, so the next full navigation's server
|
|
26
|
+
* render can read it back and start already in the same state, ahead of hydration ever running.
|
|
21
27
|
*
|
|
22
28
|
* @param name Cookie name to write the value under.
|
|
23
|
-
* @param value Value to persist
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* writeCookie("app-sidebar:collapsed", true);
|
|
30
|
-
* @example
|
|
31
|
-
* writeCookie("ui:theme", "dark");
|
|
32
|
-
* @example
|
|
33
|
-
* writeCookie("ui:announcement-dismissed", true, 60 * 60 * 24 * 7);
|
|
29
|
+
* @param value Value to persist, interpolated as is, so a boolean persists as `"true"`/`"false"`.
|
|
30
|
+
* @param options How long the cookie lasts and which path it is sent under.
|
|
31
|
+
* @example writeCookie("app-sidebar:collapsed", true);
|
|
32
|
+
* @example writeCookie("ui:announcement-dismissed", true, { maxAgeSeconds: 60 * 60 * 24 * 7 });
|
|
33
|
+
* @example writeCookie("crm-sidebar", false, { path: "/crm" });
|
|
34
34
|
*/
|
|
35
|
-
export declare function writeCookie(name: string, value: string | boolean,
|
|
35
|
+
export declare function writeCookie(name: string, value: string | boolean, options?: WriteCookieOptions): void;
|