@placeholderco/placeholder-ui 3.3.2 → 3.3.3
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 +3 -0
- package/dist/editors/CodeMirror.svelte +223 -58
- package/dist/editors/CodeMirror.svelte.d.ts +27 -4
- package/dist/editors/codemirror/languages.d.ts +17 -0
- package/dist/editors/codemirror/languages.js +196 -0
- package/dist/editors/codemirror/log.d.ts +6 -0
- package/dist/editors/codemirror/log.js +122 -0
- package/dist/editors/codemirror/theme.d.ts +3 -0
- package/dist/editors/codemirror/theme.js +64 -0
- package/dist/editors/tiptap/extensions/codeBlockLanguages.d.ts +2 -17
- package/dist/editors/tiptap/extensions/codeBlockLanguages.js +2 -124
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/ui/Table.svelte +174 -5
- package/dist/ui/Table.svelte.d.ts +14 -1
- package/package.json +1 -1
package/dist/ui/Table.svelte
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { type Snippet } from 'svelte';
|
|
2
|
+
import { flushSync, type Snippet } from 'svelte';
|
|
3
3
|
import Textbox from '../form/Textbox.svelte';
|
|
4
4
|
import Checkbox from '../form/Checkbox.svelte';
|
|
5
5
|
import Icon from '../icon/Icon.svelte';
|
|
6
6
|
import Pagination from './Pagination.svelte';
|
|
7
|
+
import ResizeHandle from '../layout/ResizeHandle.svelte';
|
|
7
8
|
import {
|
|
8
9
|
iconArrowsSort,
|
|
9
10
|
iconChevronDown,
|
|
@@ -24,6 +25,10 @@
|
|
|
24
25
|
/** @deprecated Returns raw HTML injected via {@html} — unsafe for untrusted
|
|
25
26
|
* data and cannot render components. Use `cell` instead. */
|
|
26
27
|
render?: (value: any, row: T) => any;
|
|
28
|
+
/** With the table's `resizable`, whether this column gets a resize handle (default true) */
|
|
29
|
+
resizable?: boolean;
|
|
30
|
+
/** Narrowest a resize can make the column, in px (default 48) */
|
|
31
|
+
minWidth?: number;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
export interface TableProps<T = any> {
|
|
@@ -94,6 +99,15 @@
|
|
|
94
99
|
/** Skip the built-in client-side sort and render `rows` in the order given.
|
|
95
100
|
* Use with `onsort` when the server returns pre-sorted rows. */
|
|
96
101
|
manualSort?: boolean;
|
|
102
|
+
/** Let the user resize columns by dragging a header cell's end edge (or with the arrow
|
|
103
|
+
* keys on its handle). The last column, or the actions column, takes the room left. */
|
|
104
|
+
resizable?: boolean;
|
|
105
|
+
/** Column widths in px by column key (bindable). Empty until the first resize, which fixes
|
|
106
|
+
* every column at the width it was drawn at, so a drag never moves the columns before it.
|
|
107
|
+
* Double-click a handle to restore its column; save and pass it back to keep a layout. */
|
|
108
|
+
columnWidths?: Record<string, number>;
|
|
109
|
+
/** Callback once a drag, key press or reset settles a column's width */
|
|
110
|
+
oncolumnresize?: (key: string, width: number | null, widths: Record<string, number>) => void;
|
|
97
111
|
}
|
|
98
112
|
|
|
99
113
|
let {
|
|
@@ -125,9 +139,95 @@
|
|
|
125
139
|
sortKey = $bindable(null),
|
|
126
140
|
sortDirection = $bindable('asc'),
|
|
127
141
|
onsort = undefined,
|
|
128
|
-
manualSort = false
|
|
142
|
+
manualSort = false,
|
|
143
|
+
resizable = false,
|
|
144
|
+
columnWidths = $bindable({}),
|
|
145
|
+
oncolumnresize = undefined
|
|
129
146
|
}: TableProps = $props();
|
|
130
147
|
|
|
148
|
+
const DEFAULT_MIN_WIDTH = 48;
|
|
149
|
+
|
|
150
|
+
let headerCells: HTMLElement[] = $state([]);
|
|
151
|
+
/** Widths the columns were drawn at before the first resize, which a reset restores. */
|
|
152
|
+
let initialWidths = $state<Record<string, number>>({});
|
|
153
|
+
/** True while the natural layout is drawn to be measured; it is never painted. */
|
|
154
|
+
let measuring = $state(false);
|
|
155
|
+
|
|
156
|
+
const resized = $derived(resizable && !measuring && Object.keys(columnWidths).length > 0);
|
|
157
|
+
// The column that takes the room the others leave; the actions column when there is one.
|
|
158
|
+
const fillerKey = $derived(buttons ? null : (columns[columns.length - 1]?.key ?? null));
|
|
159
|
+
|
|
160
|
+
function canResize(column: Column): boolean {
|
|
161
|
+
return resizable && column.resizable !== false && column.key !== fillerKey;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function drawnWidths(): Record<string, number> {
|
|
165
|
+
const widths: Record<string, number> = {};
|
|
166
|
+
columns.forEach((column, index) => {
|
|
167
|
+
const cell = headerCells[index];
|
|
168
|
+
if (column.key !== fillerKey && cell) {
|
|
169
|
+
widths[column.key] = Math.round(cell.getBoundingClientRect().width);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return widths;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** The widths the columns take in the table's natural layout, drawn for a moment to measure. */
|
|
176
|
+
function naturalWidths(): Record<string, number> {
|
|
177
|
+
measuring = true;
|
|
178
|
+
flushSync();
|
|
179
|
+
const widths = drawnWidths();
|
|
180
|
+
measuring = false;
|
|
181
|
+
return widths;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function resizeColumn(key: string, width: number | null) {
|
|
185
|
+
if (width === null) {
|
|
186
|
+
// Widths restored from a save come without the natural ones a reset goes back to.
|
|
187
|
+
if (resized && initialWidths[key] === undefined) initialWidths = naturalWidths();
|
|
188
|
+
width = initialWidths[key] ?? null;
|
|
189
|
+
}
|
|
190
|
+
if (width === null) {
|
|
191
|
+
columnWidths = {};
|
|
192
|
+
initialWidths = {};
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Every other column keeps the width it's drawn at; one left to the layout would give way
|
|
197
|
+
// to the drag and move the dragged edge away from the pointer.
|
|
198
|
+
if (columns.some((c) => c.key !== fillerKey && columnWidths[c.key] === undefined)) {
|
|
199
|
+
const drawn = drawnWidths();
|
|
200
|
+
if (Object.keys(columnWidths).length === 0) initialWidths = drawn;
|
|
201
|
+
columnWidths = { ...drawn, ...columnWidths };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const next = { ...columnWidths, [key]: width };
|
|
205
|
+
const restored = Object.entries(next).every(([k, px]) => initialWidths[k] === px);
|
|
206
|
+
columnWidths = restored ? {} : next;
|
|
207
|
+
if (restored) initialWidths = {};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function headerWidth(column: Column): string {
|
|
211
|
+
if (resized && column.key === fillerKey) return '';
|
|
212
|
+
const px = resized ? columnWidths[column.key] : undefined;
|
|
213
|
+
if (px) return `width: ${px}px`;
|
|
214
|
+
return column.width ? `width: ${column.width}` : '';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const tableMinWidth = $derived.by(() => {
|
|
218
|
+
if (!resized) return undefined;
|
|
219
|
+
const px = columns.reduce(
|
|
220
|
+
(sum, column) =>
|
|
221
|
+
sum +
|
|
222
|
+
(column.key === fillerKey
|
|
223
|
+
? (column.minWidth ?? DEFAULT_MIN_WIDTH)
|
|
224
|
+
: (columnWidths[column.key] ?? 0)),
|
|
225
|
+
buttons ? DEFAULT_MIN_WIDTH : 0
|
|
226
|
+
);
|
|
227
|
+
const rem = (expandable ? 2.5 : 0) + (selectable && rowKey ? 2.5 : 0);
|
|
228
|
+
return rem ? `calc(${px}px + ${rem}rem)` : `${px}px`;
|
|
229
|
+
});
|
|
230
|
+
|
|
131
231
|
let searchQuery = $state('');
|
|
132
232
|
|
|
133
233
|
let _selectionWarned = false;
|
|
@@ -401,7 +501,7 @@
|
|
|
401
501
|
{/if}
|
|
402
502
|
|
|
403
503
|
<div class="table-wrapper {notRounded ? '' : 'rounded'}">
|
|
404
|
-
<table class={tableClasses}>
|
|
504
|
+
<table class={tableClasses} class:resized style:min-width={tableMinWidth}>
|
|
405
505
|
<thead>
|
|
406
506
|
<tr>
|
|
407
507
|
{#if expandable}
|
|
@@ -418,10 +518,12 @@
|
|
|
418
518
|
/>
|
|
419
519
|
</th>
|
|
420
520
|
{/if}
|
|
421
|
-
{#each columns as column}
|
|
521
|
+
{#each columns as column, index}
|
|
422
522
|
<th
|
|
523
|
+
bind:this={headerCells[index]}
|
|
423
524
|
class="table-header {column.sortable ? 'sortable' : ''} {column.align || 'left'}"
|
|
424
|
-
|
|
525
|
+
class:resizable={canResize(column)}
|
|
526
|
+
style={headerWidth(column)}
|
|
425
527
|
onclick={() => handleSort(column)}
|
|
426
528
|
>
|
|
427
529
|
<div class="header-content">
|
|
@@ -432,6 +534,28 @@
|
|
|
432
534
|
</div>
|
|
433
535
|
{/if}
|
|
434
536
|
</div>
|
|
537
|
+
{#if canResize(column)}
|
|
538
|
+
<!-- The click that ends a drag would otherwise sort the column. -->
|
|
539
|
+
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
540
|
+
<span class="column-resize" onclick={(event) => event.stopPropagation()}>
|
|
541
|
+
<ResizeHandle
|
|
542
|
+
panel={headerCells[index]}
|
|
543
|
+
size={columnWidths[column.key] ?? null}
|
|
544
|
+
min={column.minWidth ?? DEFAULT_MIN_WIDTH}
|
|
545
|
+
defaultSize={initialWidths[column.key] ?? null}
|
|
546
|
+
thickness="0.5rem"
|
|
547
|
+
ariaLabel={`${column.label} column width`}
|
|
548
|
+
title="Drag to resize; double-click to reset"
|
|
549
|
+
onresize={(width) => resizeColumn(column.key, width)}
|
|
550
|
+
onresizeend={(width) =>
|
|
551
|
+
oncolumnresize?.(
|
|
552
|
+
column.key,
|
|
553
|
+
width ?? columnWidths[column.key] ?? null,
|
|
554
|
+
columnWidths
|
|
555
|
+
)}
|
|
556
|
+
/>
|
|
557
|
+
</span>
|
|
558
|
+
{/if}
|
|
435
559
|
</th>
|
|
436
560
|
{/each}
|
|
437
561
|
{#if buttons}
|
|
@@ -613,6 +737,51 @@
|
|
|
613
737
|
text-align: right;
|
|
614
738
|
}
|
|
615
739
|
|
|
740
|
+
/* Resized columns hold their widths, so long content wraps or clips rather than widening them. */
|
|
741
|
+
.pui-table.resized {
|
|
742
|
+
table-layout: fixed;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
.pui-table.resized .table-header {
|
|
746
|
+
overflow: hidden;
|
|
747
|
+
text-overflow: ellipsis;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
.pui-table.resized .table-cell {
|
|
751
|
+
overflow-wrap: anywhere;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
.table-header.resizable {
|
|
755
|
+
position: relative;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/* Over the cell's end padding, so it never covers the label or sort icon. */
|
|
759
|
+
.column-resize {
|
|
760
|
+
position: absolute;
|
|
761
|
+
top: 0;
|
|
762
|
+
right: 0;
|
|
763
|
+
bottom: 0;
|
|
764
|
+
display: flex;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/* A header row is shorter than the panels ResizeHandle is made for: the grip is a hairline,
|
|
768
|
+
hidden until the header is hovered; the handle's own hover, focus and drag colour it. */
|
|
769
|
+
.column-resize :global(.grip) {
|
|
770
|
+
position: static;
|
|
771
|
+
width: 2px;
|
|
772
|
+
height: 1rem;
|
|
773
|
+
opacity: 0;
|
|
774
|
+
transition:
|
|
775
|
+
opacity 0.15s ease,
|
|
776
|
+
background-color 0.15s ease;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
thead:hover .column-resize :global(.grip),
|
|
780
|
+
.column-resize :global(.pui-resize-handle:focus-visible .grip),
|
|
781
|
+
.column-resize :global(.pui-resize-handle.dragging .grip) {
|
|
782
|
+
opacity: 1;
|
|
783
|
+
}
|
|
784
|
+
|
|
616
785
|
.header-content {
|
|
617
786
|
display: flex;
|
|
618
787
|
align-items: center;
|
|
@@ -14,6 +14,10 @@ export interface Column<T = any> {
|
|
|
14
14
|
/** @deprecated Returns raw HTML injected via {@html} — unsafe for untrusted
|
|
15
15
|
* data and cannot render components. Use `cell` instead. */
|
|
16
16
|
render?: (value: any, row: T) => any;
|
|
17
|
+
/** With the table's `resizable`, whether this column gets a resize handle (default true) */
|
|
18
|
+
resizable?: boolean;
|
|
19
|
+
/** Narrowest a resize can make the column, in px (default 48) */
|
|
20
|
+
minWidth?: number;
|
|
17
21
|
}
|
|
18
22
|
export interface TableProps<T = any> {
|
|
19
23
|
/** Column definitions for the table */
|
|
@@ -83,7 +87,16 @@ export interface TableProps<T = any> {
|
|
|
83
87
|
/** Skip the built-in client-side sort and render `rows` in the order given.
|
|
84
88
|
* Use with `onsort` when the server returns pre-sorted rows. */
|
|
85
89
|
manualSort?: boolean;
|
|
90
|
+
/** Let the user resize columns by dragging a header cell's end edge (or with the arrow
|
|
91
|
+
* keys on its handle). The last column, or the actions column, takes the room left. */
|
|
92
|
+
resizable?: boolean;
|
|
93
|
+
/** Column widths in px by column key (bindable). Empty until the first resize, which fixes
|
|
94
|
+
* every column at the width it was drawn at, so a drag never moves the columns before it.
|
|
95
|
+
* Double-click a handle to restore its column; save and pass it back to keep a layout. */
|
|
96
|
+
columnWidths?: Record<string, number>;
|
|
97
|
+
/** Callback once a drag, key press or reset settles a column's width */
|
|
98
|
+
oncolumnresize?: (key: string, width: number | null, widths: Record<string, number>) => void;
|
|
86
99
|
}
|
|
87
|
-
declare const Table: import("svelte").Component<TableProps<any>, {}, "selectedRows" | "expandedKeys" | "page" | "sortKey" | "sortDirection">;
|
|
100
|
+
declare const Table: import("svelte").Component<TableProps<any>, {}, "selectedRows" | "expandedKeys" | "page" | "sortKey" | "sortDirection" | "columnWidths">;
|
|
88
101
|
type Table = ReturnType<typeof Table>;
|
|
89
102
|
export default Table;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@placeholderco/placeholder-ui",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"description": "A modern, customizable Svelte 5 UI component library with comprehensive theming support. Re-brand it with a single config object.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Placeholderco",
|