@fusion.dev/helix-headless 0.240.5 → 0.241.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,6 +45,14 @@ declare const HelixHeadlessChat_base: (new (...args: any[]) => import("@fusion.d
45
45
  * set or older turns load, the log carries `aria-busy`, as the APG asks of a
46
46
  * feed.
47
47
  *
48
+ * **A conversation opening with nothing in it yet draws turns in outline.**
49
+ * While `loading` is set and there are no turns, the log holds two placeholder
50
+ * turns, one from `me` and a reply, drawn in a skeleton's fill where a
51
+ * message's bubble would be, so the transcript has the shape a conversation
52
+ * takes rather than a line of text that the first turns push away. They are
53
+ * hidden from screen readers, which hear `loading-text`. A server, which
54
+ * cannot know whether children will arrive, draws the line alone.
55
+ *
48
56
  * The log is `aria-live="off"`. A separate status region announces each new
49
57
  * turn once, when it has finished arriving. It skips the user's own turns
50
58
  * unless they failed to send, turns loaded as history, and the turns already
@@ -172,6 +180,9 @@ declare const HelixHeadlessChat_base: (new (...args: any[]) => import("@fusion.d
172
180
  * @csspart message-state - The state text of a turn from `turns`, when there is one to show.
173
181
  * @csspart message-time - The time of a turn from `turns`.
174
182
  * @csspart message-work - The box around a turn's `work`, for a turn from `turns`, which has none.
183
+ * @csspart placeholder - The turns drawn in outline while `loading` is set and there are none. Hidden from screen readers.
184
+ * @csspart placeholder-line - One line of text in a placeholder turn.
185
+ * @csspart placeholder-turn - One placeholder turn. The one from `me` carries `data-author="me"`.
175
186
  * @csspart resume - The control shown while the user is scrolled away from the bottom.
176
187
  * @csspart resume-button - The button the `resume` region shows when nothing is slotted into it.
177
188
  * @csspart resume-mark - The arrow on the default `resume-button`.
@@ -687,6 +698,18 @@ export declare class HelixHeadlessChat extends HelixHeadlessChat_base {
687
698
  * and is followed. Leaving is moving up from there.
688
699
  */
689
700
  private readonly handleScroll;
701
+ /**
702
+ * Two turns in outline, while the conversation loads with none: one from `me`
703
+ * and a reply of three lines, as a conversation opens.
704
+ *
705
+ * Boxes of this element's own rather than messages and skeletons, which
706
+ * would each publish their parts through this one for a picture nobody
707
+ * reads. The styled tier draws them as a message's bubble and a skeleton's
708
+ * fill; here they are empty and draw nothing. Hidden from screen readers,
709
+ * which hear the loading words instead. A method, so a tier above can draw a
710
+ * different outline.
711
+ */
712
+ protected renderPlaceholder(): TemplateResult;
690
713
  /** The turns fed as data, a window of them, between the room the rest would take. */
691
714
  private renderTurns;
692
715
  /**
@@ -702,6 +702,14 @@ let HelixHeadlessChat = class HelixHeadlessChat extends MixinCollection(HelixEle
702
702
  }
703
703
  return undefined;
704
704
  }
705
+ renderPlaceholder() {
706
+ return html `<div part="placeholder" aria-hidden="true">
707
+ <div part="placeholder-turn" data-author="me"><span part="placeholder-line"></span></div>
708
+ <div part="placeholder-turn">
709
+ <span part="placeholder-line"></span><span part="placeholder-line"></span><span part="placeholder-line"></span>
710
+ </div>
711
+ </div>`;
712
+ }
705
713
  renderTurns() {
706
714
  const { after, before, first, last } = this.virtualize.window;
707
715
  const message = this.tag('chat-message');
@@ -741,6 +749,7 @@ let HelixHeadlessChat = class HelixHeadlessChat extends MixinCollection(HelixEle
741
749
  const fed = this.fed;
742
750
  const titled = this.has('header') || this.has('actions');
743
751
  const busy = this.loading || this.history === 'loading';
752
+ const turned = fed || this.messages.length > 0 || !this.childrenKnown;
744
753
  return html `<div part="header" ?hidden=${!titled}>
745
754
  <slot name="header"></slot>
746
755
  <span part="actions" ?hidden=${!this.has('actions')}>
@@ -760,7 +769,7 @@ let HelixHeadlessChat = class HelixHeadlessChat extends MixinCollection(HelixEle
760
769
  ${this.history === 'loading' ? html `<p part="history">${this.historyText}</p>` : nothing}
761
770
  ${fed ? this.renderTurns() : nothing}
762
771
  <slot name="messages" @slotchange=${this.handleSlotChange}></slot>
763
- ${this.renderStatus(fed || this.messages.length > 0 || !this.childrenKnown)}
772
+ ${this.renderStatus(turned)}${this.loading && !turned ? this.renderPlaceholder() : nothing}
764
773
  </div>
765
774
  <span part="live" role="status">${keyed(this.said, this.announcement)}</span>
766
775
  <div part="resume" ?hidden=${!away} @click=${this.handleResume}>
@@ -34,6 +34,11 @@ import { type PropertyValues, type TemplateResult } from 'lit';
34
34
  * `min` is the least the start pane keeps and `end-min` the least the end pane
35
35
  * keeps, each a percentage or a CSS length such as `16rem`.
36
36
  *
37
+ * `position` and `default-position` take a length as well as a percentage,
38
+ * such as `280px`, which is the start pane's size. The stylesheet places it
39
+ * with nothing measured, so the divider is where it belongs from the first
40
+ * paint, and the start pane keeps that size as the splitter's own size changes.
41
+ *
37
42
  * Set `primary` to the pane that keeps its size when the splitter's own size
38
43
  * changes, such as a sidebar beside a window being resized. The other pane
39
44
  * takes all of the change, as Web Awesome's split panel does. Without it,
@@ -78,7 +83,7 @@ import { type PropertyValues, type TemplateResult } from 'lit';
78
83
  * @csspart start - The box that holds the first pane.
79
84
  *
80
85
  * @cssproperty --splitter-corner-at - Where a nested splitter crosses this one, as a percentage.
81
- * @cssproperty --splitter-position - Where the divider sits, as a percentage of the box.
86
+ * @cssproperty --splitter-position - Where the divider sits: a percentage of the box, or, for a position written as a length, that length held between `min` and `max`.
82
87
  *
83
88
  * @cssstate collapsed - While a pane is shut. `data-collapsed` on the host says which.
84
89
  * @cssstate dragging - While the pointer or a corner holds the divider.
@@ -151,9 +156,10 @@ export declare class HelixHeadlessSplitter extends HelixElement {
151
156
  */
152
157
  defaultCollapsed?: 'end' | 'start';
153
158
  /**
154
- * Where the divider starts, when `position` is not set.
159
+ * Where the divider starts, when `position` is not set: a percentage, or a
160
+ * length such as `280px`, as `position` takes.
155
161
  */
156
- defaultPosition: number;
162
+ defaultPosition: number | string;
157
163
  /**
158
164
  * The least the end pane keeps, in the units `min` takes: a percentage, or
159
165
  * a CSS length such as `16rem` resolved against the splitter's box. The
@@ -244,9 +250,22 @@ export declare class HelixHeadlessSplitter extends HelixElement {
244
250
  * Reading gives where it is; writing declares it the consumer's, and
245
251
  * `default-position` seeds one this element owns. The same accessor pair
246
252
  * `Pagination.page` and the calendar's `month` carry.
253
+ *
254
+ * **Written as a length, such as `280px` or `16rem`, it is the start pane's
255
+ * size**, which the stylesheet lays out as written, between `min` and `max`.
256
+ * Nothing is measured to place it, so it is where it belongs on the first
257
+ * paint and in the server's markup, and it keeps its size as the splitter's
258
+ * own size changes. A percentage is drawn only once the splitter knows its
259
+ * box, so a sidebar of a fixed width written as one is drawn at some other
260
+ * width first and corrected, which a browser counts as a layout shift.
261
+ *
262
+ * Reading always gives a percentage, measured against the box, and 50 where
263
+ * there is no box yet. A drag, a key or a double click settles on a
264
+ * percentage, and `helix-resized` carries one: a consumer keeping a length
265
+ * converts it and writes the length back.
247
266
  */
248
267
  get position(): number;
249
- set position(next: number);
268
+ set position(next: number | string);
250
269
  /**
251
270
  * The pane that keeps its size when the splitter's own size changes. The
252
271
  * other pane takes all of the change. Unset, both keep their share.
@@ -272,8 +291,16 @@ export declare class HelixHeadlessSplitter extends HelixElement {
272
291
  /** The length along the axis last seen, in pixels. */
273
292
  private length;
274
293
  /**
275
- * Starts or stops watching the length, according to `primary`, and holds
276
- * the primary pane's size in pixels as the length changes.
294
+ * Whether the position or a bound is written as a length, which reads as a
295
+ * different percentage at every length of the splitter.
296
+ */
297
+ private get inLengths();
298
+ /**
299
+ * Starts or stops watching the length, according to `primary` and to
300
+ * whether anything is written as a length. It holds the primary pane's
301
+ * size in pixels as the length changes, and, where something is written as
302
+ * a length, draws the divider again, so the percentage it announces is the
303
+ * one it is drawn at.
277
304
  */
278
305
  private watchLength;
279
306
  /**
@@ -305,6 +332,17 @@ export declare class HelixHeadlessSplitter extends HelixElement {
305
332
  step: number;
306
333
  /** The position, whoever set it, and `undefined` until somebody has. */
307
334
  private positionState;
335
+ /** The position as it was written, by whoever wrote it last. */
336
+ private get declared();
337
+ /**
338
+ * The position as the stylesheet takes it, in `--splitter-position`.
339
+ *
340
+ * A length stays a length, held between `min` and `max` by CSS rather than by
341
+ * a measurement, so the browser places the divider with nothing to correct.
342
+ * Everything else is the percentage `showing` gives: a drag in progress, a
343
+ * shut pane, and a position written as a percentage.
344
+ */
345
+ private get drawn();
308
346
  /** The collapse, whoever set it, and `undefined` until somebody has. */
309
347
  private collapsedState;
310
348
  /**
@@ -6,6 +6,21 @@ import { property, state } from 'lit/decorators.js';
6
6
  import { HelixBeforeCollapseEvent, HelixCollapseEvent } from '../events/index.js';
7
7
  import { snapTo } from '../snap.js';
8
8
  const STACK_BELOW = 512;
9
+ const LENGTH = /^(-?[\d.]+)(em|px|rem)$/;
10
+ const isLength = (value) => typeof value === 'string' && LENGTH.test(value.trim());
11
+ const asCss = (value, fallback) => {
12
+ if (isLength(value)) {
13
+ return String(value).trim();
14
+ }
15
+ const percent = typeof value === 'number' ? value : value.trim() === '' ? Number.NaN : Number(value);
16
+ return Number.isFinite(percent) ? `${percent}%` : fallback;
17
+ };
18
+ const positionConverter = (attribute, fallback) => {
19
+ const numbers = numberConverter(attribute, fallback);
20
+ return {
21
+ fromAttribute: (value) => value !== null && isLength(value) ? value.trim() : numbers.fromAttribute?.(value),
22
+ };
23
+ };
9
24
  const channel = new WeakMap();
10
25
  const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
11
26
  let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
@@ -36,7 +51,7 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
36
51
  if (Number.isFinite(bare)) {
37
52
  return bare;
38
53
  }
39
- const length = /^(-?[\d.]+)(em|px|rem)$/.exec(text);
54
+ const length = LENGTH.exec(text);
40
55
  if (!length || typeof window === 'undefined') {
41
56
  return fallback;
42
57
  }
@@ -59,11 +74,15 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
59
74
  if (shut) {
60
75
  return shut === 'start' ? this.sliver : 100 - this.sliver;
61
76
  }
62
- return this.clamp(this.positionState ?? this.defaultPosition);
77
+ return this.clamp(this.toPercent(this.declared, 50));
63
78
  }
64
79
  set position(next) {
65
80
  const previous = this.position;
81
+ const written = this.declared;
66
82
  this.positionState = next;
83
+ if (next !== written) {
84
+ this.requestUpdate();
85
+ }
67
86
  this.reached = undefined;
68
87
  this.requestUpdate('position', previous);
69
88
  }
@@ -74,8 +93,11 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
74
93
  const box = this.chain?.by.getBoundingClientRect();
75
94
  return box ? (this.vertical ? box.height : box.width) : 0;
76
95
  }
96
+ get inLengths() {
97
+ return [this.declared, this.min, this.max, this.endMin].some(isLength);
98
+ }
77
99
  watchLength() {
78
- if (!this.held || typeof ResizeObserver === 'undefined') {
100
+ if ((!this.held && !this.inLengths) || typeof ResizeObserver === 'undefined') {
79
101
  this.lengths?.disconnect();
80
102
  this.lengths = undefined;
81
103
  this.length = 0;
@@ -89,7 +111,11 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
89
111
  const length = (this.vertical
90
112
  ? (box?.blockSize ?? entry?.contentRect.height)
91
113
  : (box?.inlineSize ?? entry?.contentRect.width)) ?? 0;
114
+ const before = this.length;
92
115
  this.holdPrimary(length);
116
+ if (this.inLengths && length !== before) {
117
+ this.requestUpdate();
118
+ }
93
119
  });
94
120
  this.lengths.observe(this);
95
121
  }
@@ -111,6 +137,9 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
111
137
  if (this.collapsed || this.dragging) {
112
138
  return;
113
139
  }
140
+ if (held === 'start' && isLength(this.declared)) {
141
+ return;
142
+ }
114
143
  const position = this.position;
115
144
  const kept = ((held === 'start' ? position : 100 - position) / 100) * before;
116
145
  const share = (kept / length) * 100;
@@ -118,6 +147,18 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
118
147
  this.positionState = this.clamp(held === 'start' ? share : 100 - share);
119
148
  this.requestUpdate('position', previous);
120
149
  }
150
+ get declared() {
151
+ return this.positionState ?? this.defaultPosition;
152
+ }
153
+ get drawn() {
154
+ const declared = this.declared;
155
+ if (this.reached !== undefined || this.collapsed || !isLength(declared)) {
156
+ return `${this.showing}%`;
157
+ }
158
+ const least = `max(0%, ${asCss(this.min, '0%')})`;
159
+ const most = `min(100%, ${asCss(this.max, '100%')}, calc(100% - ${asCss(this.endMin, '0%')}))`;
160
+ return `clamp(${least}, ${String(declared).trim()}, ${most})`;
161
+ }
121
162
  get showing() {
122
163
  return this.reached === undefined ? this.position : this.clamp(this.reached);
123
164
  }
@@ -262,7 +303,7 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
262
303
  if (opened !== undefined) {
263
304
  this.positionState = opened;
264
305
  }
265
- else if (this.shutAt(this.clamp(this.positionState ?? this.defaultPosition))) {
306
+ else if (this.shutAt(this.clamp(this.toPercent(this.declared, 50)))) {
266
307
  this.positionState = this.defaultPosition;
267
308
  }
268
309
  this.collapsedState = value === '' ? 'none' : value;
@@ -275,8 +316,11 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
275
316
  });
276
317
  }
277
318
  reset() {
278
- const home = this.clamp(this.defaultPosition);
319
+ const home = this.clamp(this.toPercent(this.defaultPosition, 50));
279
320
  this.settle(home);
321
+ if (this.positionState === home && isLength(this.defaultPosition)) {
322
+ this.positionState = this.defaultPosition;
323
+ }
280
324
  }
281
325
  constructor() {
282
326
  super();
@@ -576,7 +620,7 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
576
620
  if (changed.has('orientation')) {
577
621
  this.watchWidth();
578
622
  }
579
- if (changed.has('primary')) {
623
+ if (['primary', 'position', 'defaultPosition', 'min', 'max', 'endMin'].some((key) => changed.has(key))) {
580
624
  this.watchLength();
581
625
  }
582
626
  if (this.collapsed) {
@@ -610,7 +654,7 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
610
654
  id="start"
611
655
  ?data-dragging=${this.dragging}
612
656
  ?inert=${shut === 'start'}
613
- style="--splitter-position: ${position}%"
657
+ style="--splitter-position: ${this.drawn}"
614
658
  >
615
659
  <slot name="start"></slot>
616
660
  </div>
@@ -654,7 +698,7 @@ let HelixHeadlessSplitter = class HelixHeadlessSplitter extends HelixElement {
654
698
  aria-valuenow=${Math.round(crossing.at)}
655
699
  aria-valuetext=${this.cornerWords(position, crossing.at)}
656
700
  data-cross=${index}
657
- style="--splitter-corner-at: ${crossing.at}%; --splitter-position: ${position}%"
701
+ style="--splitter-corner-at: ${crossing.at}%; --splitter-position: ${this.drawn}"
658
702
  @dblclick=${this.handleCornerDoubleClick}
659
703
  @keydown=${this.handleCornerKeydown}
660
704
  @pointercancel=${this.handleCornerUp}
@@ -689,7 +733,7 @@ __decorate([
689
733
  property({ attribute: 'default-collapsed' })
690
734
  ], HelixHeadlessSplitter.prototype, "defaultCollapsed", void 0);
691
735
  __decorate([
692
- property({ attribute: 'default-position', converter: numberConverter('default-position', 50) })
736
+ property({ attribute: 'default-position', converter: positionConverter('default-position', 50) })
693
737
  ], HelixHeadlessSplitter.prototype, "defaultPosition", void 0);
694
738
  __decorate([
695
739
  property({ attribute: 'end-min' })
@@ -711,7 +755,7 @@ __decorate([
711
755
  property({ reflect: true })
712
756
  ], HelixHeadlessSplitter.prototype, "orientation", void 0);
713
757
  __decorate([
714
- property({ converter: numberConverter('position', undefined) })
758
+ property({ converter: positionConverter('position', undefined) })
715
759
  ], HelixHeadlessSplitter.prototype, "position", null);
716
760
  __decorate([
717
761
  property()