panelui-native 0.77.0 → 0.79.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.
Files changed (142) hide show
  1. package/lib/module/components/area-chart/index.js +32 -25
  2. package/lib/module/components/area-chart/index.js.map +1 -1
  3. package/lib/module/components/bottom-sheet/index.js +97 -15
  4. package/lib/module/components/bottom-sheet/index.js.map +1 -1
  5. package/lib/module/components/funnel-chart/index.js +15 -2
  6. package/lib/module/components/funnel-chart/index.js.map +1 -1
  7. package/lib/module/components/heatmap-chart/index.js +19 -27
  8. package/lib/module/components/heatmap-chart/index.js.map +1 -1
  9. package/lib/module/components/hex-chart/index.js +2 -0
  10. package/lib/module/components/hex-chart/index.js.map +1 -1
  11. package/lib/module/components/line-chart/index.js +38 -31
  12. package/lib/module/components/line-chart/index.js.map +1 -1
  13. package/lib/module/components/map/index.js +63 -39
  14. package/lib/module/components/map/index.js.map +1 -1
  15. package/lib/module/components/map/map-children.js +54 -0
  16. package/lib/module/components/map/map-children.js.map +1 -0
  17. package/lib/module/components/map/maplibre.js +31 -3
  18. package/lib/module/components/map/maplibre.js.map +1 -1
  19. package/lib/module/components/markdown-editor/index.js +288 -34
  20. package/lib/module/components/markdown-editor/index.js.map +1 -1
  21. package/lib/module/components/markdown-editor/markdown-transforms.js +272 -9
  22. package/lib/module/components/markdown-editor/markdown-transforms.js.map +1 -1
  23. package/lib/module/components/marquee/index.js +205 -46
  24. package/lib/module/components/marquee/index.js.map +1 -1
  25. package/lib/module/components/panelside/index.js +162 -34
  26. package/lib/module/components/panelside/index.js.map +1 -1
  27. package/lib/module/components/pie-chart/index.js +15 -2
  28. package/lib/module/components/pie-chart/index.js.map +1 -1
  29. package/lib/module/components/plot/index.js +42 -44
  30. package/lib/module/components/plot/index.js.map +1 -1
  31. package/lib/module/components/progress-button/index.js +617 -0
  32. package/lib/module/components/progress-button/index.js.map +1 -0
  33. package/lib/module/components/progress-button/progress-button-hold.js +91 -0
  34. package/lib/module/components/progress-button/progress-button-hold.js.map +1 -0
  35. package/lib/module/components/scatter-chart/index.js +6 -25
  36. package/lib/module/components/scatter-chart/index.js.map +1 -1
  37. package/lib/module/components/section-rail/index.js +40 -17
  38. package/lib/module/components/section-rail/index.js.map +1 -1
  39. package/lib/module/components/split-view/index.js +54 -10
  40. package/lib/module/components/split-view/index.js.map +1 -1
  41. package/lib/module/components/theme-selector/index.js +239 -0
  42. package/lib/module/components/theme-selector/index.js.map +1 -0
  43. package/lib/module/components/theme-selector/theme-preview.js +320 -0
  44. package/lib/module/components/theme-selector/theme-preview.js.map +1 -0
  45. package/lib/module/components/timeline/index.js +145 -14
  46. package/lib/module/components/timeline/index.js.map +1 -1
  47. package/lib/module/components/toast/index.js +45 -11
  48. package/lib/module/components/toast/index.js.map +1 -1
  49. package/lib/module/components/treemap-chart/index.js +63 -6
  50. package/lib/module/components/treemap-chart/index.js.map +1 -1
  51. package/lib/module/components/waterfall-chart/index.js +20 -4
  52. package/lib/module/components/waterfall-chart/index.js.map +1 -1
  53. package/lib/module/hooks/index.js +1 -0
  54. package/lib/module/hooks/index.js.map +1 -1
  55. package/lib/module/hooks/use-scroll-sections.js +44 -2
  56. package/lib/module/hooks/use-scroll-sections.js.map +1 -1
  57. package/lib/module/hooks/use-skeleton-handoff.js +58 -0
  58. package/lib/module/hooks/use-skeleton-handoff.js.map +1 -0
  59. package/lib/module/index.js +2 -0
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/typescript/src/components/area-chart/index.d.ts +1 -1
  62. package/lib/typescript/src/components/area-chart/index.d.ts.map +1 -1
  63. package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
  64. package/lib/typescript/src/components/funnel-chart/index.d.ts.map +1 -1
  65. package/lib/typescript/src/components/heatmap-chart/index.d.ts.map +1 -1
  66. package/lib/typescript/src/components/hex-chart/index.d.ts.map +1 -1
  67. package/lib/typescript/src/components/line-chart/index.d.ts +1 -1
  68. package/lib/typescript/src/components/line-chart/index.d.ts.map +1 -1
  69. package/lib/typescript/src/components/map/index.d.ts +8 -4
  70. package/lib/typescript/src/components/map/index.d.ts.map +1 -1
  71. package/lib/typescript/src/components/map/map-children.d.ts +41 -0
  72. package/lib/typescript/src/components/map/map-children.d.ts.map +1 -0
  73. package/lib/typescript/src/components/map/maplibre.d.ts +8 -4
  74. package/lib/typescript/src/components/map/maplibre.d.ts.map +1 -1
  75. package/lib/typescript/src/components/markdown-editor/index.d.ts +64 -5
  76. package/lib/typescript/src/components/markdown-editor/index.d.ts.map +1 -1
  77. package/lib/typescript/src/components/markdown-editor/markdown-transforms.d.ts +33 -5
  78. package/lib/typescript/src/components/markdown-editor/markdown-transforms.d.ts.map +1 -1
  79. package/lib/typescript/src/components/marquee/index.d.ts +55 -2
  80. package/lib/typescript/src/components/marquee/index.d.ts.map +1 -1
  81. package/lib/typescript/src/components/panelside/index.d.ts +79 -4
  82. package/lib/typescript/src/components/panelside/index.d.ts.map +1 -1
  83. package/lib/typescript/src/components/pie-chart/index.d.ts.map +1 -1
  84. package/lib/typescript/src/components/plot/index.d.ts +1 -3
  85. package/lib/typescript/src/components/plot/index.d.ts.map +1 -1
  86. package/lib/typescript/src/components/progress-button/index.d.ts +311 -0
  87. package/lib/typescript/src/components/progress-button/index.d.ts.map +1 -0
  88. package/lib/typescript/src/components/progress-button/progress-button-hold.d.ts +60 -0
  89. package/lib/typescript/src/components/progress-button/progress-button-hold.d.ts.map +1 -0
  90. package/lib/typescript/src/components/scatter-chart/index.d.ts +1 -1
  91. package/lib/typescript/src/components/scatter-chart/index.d.ts.map +1 -1
  92. package/lib/typescript/src/components/section-rail/index.d.ts.map +1 -1
  93. package/lib/typescript/src/components/split-view/index.d.ts +10 -1
  94. package/lib/typescript/src/components/split-view/index.d.ts.map +1 -1
  95. package/lib/typescript/src/components/theme-selector/index.d.ts +107 -0
  96. package/lib/typescript/src/components/theme-selector/index.d.ts.map +1 -0
  97. package/lib/typescript/src/components/theme-selector/theme-preview.d.ts +32 -0
  98. package/lib/typescript/src/components/theme-selector/theme-preview.d.ts.map +1 -0
  99. package/lib/typescript/src/components/timeline/index.d.ts +7 -0
  100. package/lib/typescript/src/components/timeline/index.d.ts.map +1 -1
  101. package/lib/typescript/src/components/toast/index.d.ts.map +1 -1
  102. package/lib/typescript/src/components/treemap-chart/index.d.ts.map +1 -1
  103. package/lib/typescript/src/components/waterfall-chart/index.d.ts.map +1 -1
  104. package/lib/typescript/src/hooks/index.d.ts +1 -0
  105. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  106. package/lib/typescript/src/hooks/use-scroll-sections.d.ts +1 -0
  107. package/lib/typescript/src/hooks/use-scroll-sections.d.ts.map +1 -1
  108. package/lib/typescript/src/hooks/use-skeleton-handoff.d.ts +11 -0
  109. package/lib/typescript/src/hooks/use-skeleton-handoff.d.ts.map +1 -0
  110. package/lib/typescript/src/index.d.ts +6 -4
  111. package/lib/typescript/src/index.d.ts.map +1 -1
  112. package/package.json +1 -1
  113. package/src/components/area-chart/index.tsx +49 -37
  114. package/src/components/bottom-sheet/index.tsx +109 -11
  115. package/src/components/funnel-chart/index.tsx +10 -2
  116. package/src/components/heatmap-chart/index.tsx +27 -22
  117. package/src/components/hex-chart/index.tsx +22 -6
  118. package/src/components/line-chart/index.tsx +57 -43
  119. package/src/components/map/index.tsx +63 -36
  120. package/src/components/map/map-children.ts +66 -0
  121. package/src/components/map/maplibre.ts +32 -4
  122. package/src/components/markdown-editor/index.tsx +413 -35
  123. package/src/components/markdown-editor/markdown-transforms.ts +274 -10
  124. package/src/components/marquee/index.tsx +254 -58
  125. package/src/components/panelside/index.tsx +179 -40
  126. package/src/components/pie-chart/index.tsx +10 -2
  127. package/src/components/plot/index.tsx +66 -50
  128. package/src/components/progress-button/index.tsx +684 -0
  129. package/src/components/progress-button/progress-button-hold.ts +88 -0
  130. package/src/components/scatter-chart/index.tsx +4 -25
  131. package/src/components/section-rail/index.tsx +39 -19
  132. package/src/components/split-view/index.tsx +53 -8
  133. package/src/components/theme-selector/index.tsx +281 -0
  134. package/src/components/theme-selector/theme-preview.tsx +205 -0
  135. package/src/components/timeline/index.tsx +143 -17
  136. package/src/components/toast/index.tsx +60 -11
  137. package/src/components/treemap-chart/index.tsx +65 -8
  138. package/src/components/waterfall-chart/index.tsx +14 -4
  139. package/src/hooks/index.ts +5 -0
  140. package/src/hooks/use-scroll-sections.ts +52 -3
  141. package/src/hooks/use-skeleton-handoff.ts +69 -0
  142. package/src/index.ts +25 -0
@@ -81,6 +81,23 @@ export function toggleWrap(
81
81
  };
82
82
  }
83
83
 
84
+ /*
85
+ * A selection that crosses a line break is wrapped line by line.
86
+ *
87
+ * `**one\ntwo**` is not bold in any reader — an inline marker cannot span a
88
+ * paragraph break — so wrapping the whole span produces asterisks the writer
89
+ * can see and no emphasis they asked for. Each line gets its own pair, and
90
+ * blank lines are left alone rather than given an empty pair of markers.
91
+ */
92
+ if (selected.includes('\n')) {
93
+ const wrapped = selected
94
+ .split('\n')
95
+ .map((line) => (line.trim() === '' ? line : marker + line + marker))
96
+ .join('\n');
97
+ const next = text.slice(0, start) + wrapped + text.slice(end);
98
+ return { text: next, selection: { start, end: start + wrapped.length } };
99
+ }
100
+
84
101
  const next = text.slice(0, start) + marker + selected + marker + text.slice(end);
85
102
 
86
103
  // Nothing selected: the caret goes between the markers, which is where the
@@ -121,6 +138,60 @@ function replaceBlock(
121
138
  };
122
139
  }
123
140
 
141
+ /**
142
+ * The same replacement, with the caret left where the writer's was.
143
+ *
144
+ * A line-level action applies to whole lines, but the writer's caret was in the
145
+ * middle of one of them, and handing back the whole block selected means the
146
+ * next thing they type replaces the list they just made. So the caret is put
147
+ * back at the same distance from the start of the block, shifted by however
148
+ * much the text before it grew.
149
+ */
150
+ function replaceBlockKeepingCaret(
151
+ text: string,
152
+ range: EditorSelection,
153
+ replacement: string,
154
+ selection: EditorSelection
155
+ ): EditResult {
156
+ const next = text.slice(0, range.start) + replacement + text.slice(range.end);
157
+ const { start, end } = normalise(text, selection);
158
+
159
+ // A real selection is kept as a selection over the same lines; only a caret
160
+ // is followed precisely.
161
+ if (start !== end) {
162
+ return { text: next, selection: { start: range.start, end: range.start + replacement.length } };
163
+ }
164
+
165
+ const before = text.slice(range.start, start);
166
+ const line = before.split('\n').length - 1;
167
+ const column = before.length - (before.lastIndexOf('\n') + 1);
168
+
169
+ const oldLines = text.slice(range.start, range.end).split('\n');
170
+ const newLines = replacement.split('\n');
171
+ const index = Math.min(line, newLines.length - 1);
172
+ const oldLine = oldLines[Math.min(line, oldLines.length - 1)] ?? '';
173
+ const newLine = newLines[index] ?? '';
174
+
175
+ /*
176
+ * The caret keeps its distance from the *end* of its line, not from the
177
+ * start of it.
178
+ *
179
+ * These actions change what is in front of the text: a caret held at the
180
+ * same column ends up inside the bullet it just gained, and after removing
181
+ * one it ends up two characters into the word. The distance to the end of
182
+ * the line is the thing a prefix cannot move.
183
+ */
184
+ const fromEnd = Math.max(0, oldLine.length - column);
185
+ const nextColumn = Math.max(0, newLine.length - fromEnd);
186
+
187
+ const offsetToLine = newLines
188
+ .slice(0, index)
189
+ .reduce((total, each) => total + each.length + 1, 0);
190
+
191
+ const at = range.start + offsetToLine + Math.min(nextColumn, newLine.length);
192
+ return { text: next, selection: { start: at, end: at } };
193
+ }
194
+
124
195
  /**
125
196
  * Puts `prefix` on the front of every line the selection touches, or takes it
126
197
  * off if every one of them already has it.
@@ -140,7 +211,7 @@ export function toggleLinePrefix(
140
211
  ? lines.map((line) => line.slice(prefix.length))
141
212
  : lines.map((line) => (has(line) ? line : prefix + line));
142
213
 
143
- return replaceBlock(text, range, next.join('\n'));
214
+ return replaceBlockKeepingCaret(text, range, next.join('\n'), selection);
144
215
  }
145
216
 
146
217
  /** How an ordered-list line starts, so it can be recognised and removed. */
@@ -164,7 +235,7 @@ export function toggleOrderedList(
164
235
  ? lines.map((line) => line.replace(ORDERED, ''))
165
236
  : lines.map((line, i) => `${i + 1}. ${line.replace(ORDERED, '')}`);
166
237
 
167
- return replaceBlock(text, range, next.join('\n'));
238
+ return replaceBlockKeepingCaret(text, range, next.join('\n'), selection);
168
239
  }
169
240
 
170
241
  /* -------------------------------------------------------------------------- *
@@ -208,21 +279,214 @@ export function insertLink(text: string, selection: EditorSelection): EditResult
208
279
  * makes room for itself: a blank line before it when it is not already at the
209
280
  * start of a paragraph, and one after it at the end.
210
281
  */
282
+ /**
283
+ * The whole fenced block the selection is inside, or `null`.
284
+ *
285
+ * Scanned from the top of the document rather than read off the lines the
286
+ * selection touches, because a caret sitting on a line of code touches one
287
+ * line and that line says nothing about the fence around it. Without this,
288
+ * pressing the code button inside a fence wrapped it in a second one.
289
+ */
290
+ function enclosingFence(
291
+ text: string,
292
+ selection: EditorSelection
293
+ ): EditorSelection | null {
294
+ const { start, end } = normalise(text, selection);
295
+ let offset = 0;
296
+ let openedAt: number | null = null;
297
+
298
+ for (const line of text.split('\n')) {
299
+ const lineStart = offset;
300
+ const lineEnd = offset + line.length;
301
+
302
+ if (line.startsWith('```')) {
303
+ if (openedAt === null) openedAt = lineStart;
304
+ else {
305
+ if (start >= openedAt && end <= lineEnd) return { start: openedAt, end: lineEnd };
306
+ openedAt = null;
307
+ }
308
+ }
309
+
310
+ offset = lineEnd + 1;
311
+ }
312
+
313
+ return null;
314
+ }
315
+
211
316
  export function toggleFence(text: string, selection: EditorSelection): EditResult {
317
+ const enclosing = enclosingFence(text, selection);
318
+ if (enclosing) {
319
+ const inner = text
320
+ .slice(enclosing.start, enclosing.end)
321
+ .split('\n')
322
+ .slice(1, -1)
323
+ .join('\n');
324
+ return replaceBlock(text, enclosing, inner);
325
+ }
326
+
212
327
  const range = lineRange(text, selection);
213
328
  const block = text.slice(range.start, range.end);
214
- const lines = block.split('\n');
215
-
216
- if (lines.length >= 2 && lines[0]?.startsWith('```') && lines.at(-1) === '```') {
217
- return replaceBlock(text, range, lines.slice(1, -1).join('\n'));
218
- }
219
329
 
220
330
  const leadIn = range.start > 0 && text[range.start - 1] !== '\n' ? '\n' : '';
221
- const fenced = `${leadIn}\`\`\`\n${block}\n\`\`\``;
331
+ // And a blank line after it, unless the fence already ends the document or
332
+ // the line below it is blank. A paragraph butted up against a closing fence
333
+ // is a paragraph some readers swallow into the code block.
334
+ const rest = text.slice(range.end);
335
+ const leadOut = rest === '' || rest.startsWith('\n\n') ? '' : '\n';
336
+
337
+ const opener = `${leadIn}\`\`\`\n`;
338
+ const fenced = `${opener}${block}\n\`\`\`${leadOut}`;
222
339
  const result = replaceBlock(text, range, fenced);
223
340
 
224
341
  // Inside the fence, on the line the code goes on — not around the whole
225
- // block, which would be selecting the markers along with the content.
226
- const inner = range.start + leadIn.length + 4;
342
+ // block, which would be selecting the markers along with the content. The
343
+ // offset is the opener's own length rather than a written-down number, so it
344
+ // cannot drift from the string above it.
345
+ const inner = range.start + opener.length;
227
346
  return { text: result.text, selection: { start: inner, end: inner + block.length } };
228
347
  }
348
+
349
+ /* -------------------------------------------------------------------------- *
350
+ * Images
351
+ * -------------------------------------------------------------------------- */
352
+
353
+ /** Placeholder left where an image's description goes. */
354
+ export const IMAGE_PLACEHOLDER = 'description';
355
+
356
+ /**
357
+ * Inserts an image, and selects the part that still needs filling in.
358
+ *
359
+ * The description first, not the URL. An image with no alt text is the failure
360
+ * that actually happens, and the writer is far more likely to have the URL on
361
+ * the clipboard than the sentence describing what is in it — so the sentence is
362
+ * what the caret is left on.
363
+ */
364
+ export function insertImage(text: string, selection: EditorSelection): EditResult {
365
+ const { start, end } = normalise(text, selection);
366
+ const label = text.slice(start, end);
367
+ const alt = label || IMAGE_PLACEHOLDER;
368
+ const inserted = `![${alt}](${LINK_PLACEHOLDER})`;
369
+ const next = text.slice(0, start) + inserted + text.slice(end);
370
+
371
+ // With a description already written, what is missing is the target.
372
+ if (label) {
373
+ const from = start + label.length + 4; // `![` + label + `](`
374
+ return { text: next, selection: { start: from, end: from + LINK_PLACEHOLDER.length } };
375
+ }
376
+
377
+ const from = start + 2; // `![`
378
+ return { text: next, selection: { start: from, end: from + alt.length } };
379
+ }
380
+
381
+ /* -------------------------------------------------------------------------- *
382
+ * Continuing a list
383
+ * -------------------------------------------------------------------------- */
384
+
385
+ /** A bullet line, and how much of it is the marker. */
386
+ const BULLET = /^(\s*)([-*+])(\s+)(.*)$/;
387
+ /** A numbered line, split the same way. */
388
+ const NUMBERED = /^(\s*)(\d+)\.(\s+)(.*)$/;
389
+
390
+ /**
391
+ * What Return should do inside a list.
392
+ *
393
+ * Returns `null` when the caret is not on a list line, which is the signal to
394
+ * let the newline happen normally. Otherwise it either starts the next item or,
395
+ * on an item with nothing in it, ends the list — because a writer pressing
396
+ * Return on an empty bullet is telling you they have run out of items, and the
397
+ * alternative is a trail of empty bullets they have to delete by hand.
398
+ */
399
+ export function continueList(
400
+ text: string,
401
+ selection: EditorSelection
402
+ ): EditResult | null {
403
+ const { start, end } = normalise(text, selection);
404
+ // Only a caret continues a list. With a range selected, Return replaces it,
405
+ // and guessing which end of it the writer meant is worse than not guessing.
406
+ if (start !== end) return null;
407
+
408
+ const lineStart = text.lastIndexOf('\n', start - 1) + 1;
409
+ const line = text.slice(lineStart, start);
410
+
411
+ const bullet = BULLET.exec(line);
412
+ const numbered = bullet ? null : NUMBERED.exec(line);
413
+ if (!bullet && !numbered) return null;
414
+
415
+ const [, indent = '', marker = '', gap = ' ', content = ''] = (bullet ?? numbered)!;
416
+
417
+ // An item with nothing in it ends the list: the line becomes empty and the
418
+ // caret stays on it, ready for an ordinary paragraph.
419
+ if (content.trim() === '') {
420
+ const next = text.slice(0, lineStart) + text.slice(start);
421
+ return { text: next, selection: { start: lineStart, end: lineStart } };
422
+ }
423
+
424
+ const opener = numbered
425
+ ? `${indent}${Number(marker) + 1}.${gap}`
426
+ : `${indent}${marker}${gap}`;
427
+ const inserted = `\n${opener}`;
428
+ const next = text.slice(0, start) + inserted + text.slice(start);
429
+ const at = start + inserted.length;
430
+ return { text: next, selection: { start: at, end: at } };
431
+ }
432
+
433
+ /* -------------------------------------------------------------------------- *
434
+ * What is already applied
435
+ * -------------------------------------------------------------------------- */
436
+
437
+ /**
438
+ * Whether an inline marker is already around the caret or the selection.
439
+ *
440
+ * Both arrangements count, for the same reason `toggleWrap` accepts both: the
441
+ * writer may have selected `**bold**` or selected `bold` inside it, and with
442
+ * nothing selected at all the caret may simply be sitting between the markers.
443
+ */
444
+ export function hasWrap(
445
+ text: string,
446
+ selection: EditorSelection,
447
+ marker: string
448
+ ): boolean {
449
+ const { start, end } = normalise(text, selection);
450
+ const selected = text.slice(start, end);
451
+ const len = marker.length;
452
+
453
+ if (
454
+ selected.length >= len * 2 &&
455
+ selected.startsWith(marker) &&
456
+ selected.endsWith(marker)
457
+ ) {
458
+ return true;
459
+ }
460
+
461
+ return (
462
+ text.slice(Math.max(0, start - len), start) === marker &&
463
+ text.slice(end, end + len) === marker
464
+ );
465
+ }
466
+
467
+ /** Whether every line the selection touches already starts with `prefix`. */
468
+ export function hasLinePrefix(
469
+ text: string,
470
+ selection: EditorSelection,
471
+ prefix: string
472
+ ): boolean {
473
+ const range = lineRange(text, selection);
474
+ return text
475
+ .slice(range.start, range.end)
476
+ .split('\n')
477
+ .every((line) => line.startsWith(prefix));
478
+ }
479
+
480
+ /** Whether every line the selection touches is already numbered. */
481
+ export function hasOrderedList(text: string, selection: EditorSelection): boolean {
482
+ const range = lineRange(text, selection);
483
+ return text
484
+ .slice(range.start, range.end)
485
+ .split('\n')
486
+ .every((line) => ORDERED.test(line));
487
+ }
488
+
489
+ /** Whether the selection is inside a fence. */
490
+ export function hasFence(text: string, selection: EditorSelection): boolean {
491
+ return enclosingFence(text, selection) !== null;
492
+ }