@witchcraft/ui 0.3.18 → 0.3.19
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/dist/module.json +1 -1
- package/dist/runtime/components/LibTable/LibTable.d.vue.ts +1 -0
- package/dist/runtime/components/LibTable/LibTable.vue +2 -2
- package/dist/runtime/components/LibTable/LibTable.vue.d.ts +1 -0
- package/dist/runtime/directives/vResizableCols.js +20 -25
- package/dist/runtime/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/runtime/components/LibTable/LibTable.stories.ts +5 -4
- package/src/runtime/components/LibTable/LibTable.vue +3 -2
- package/src/runtime/directives/vResizableCols.ts +20 -28
- package/src/runtime/types/index.ts +1 -1
package/dist/module.json
CHANGED
|
@@ -11,6 +11,7 @@ type RealProps = {
|
|
|
11
11
|
rounded?: boolean;
|
|
12
12
|
border?: boolean;
|
|
13
13
|
cellBorder?: boolean;
|
|
14
|
+
/** Disables the header. This also sets the selector to `tr:first-child > td` instead to avoid issues with the vResizableCols directive. */
|
|
14
15
|
header?: boolean;
|
|
15
16
|
colConfig?: TableColConfig<T>;
|
|
16
17
|
/**
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
mergedVirtualizerOpts.enabled && mergedVirtualizerOpts.method === 'dynamic' && `
|
|
52
52
|
relative
|
|
53
53
|
`,
|
|
54
|
-
$attrs
|
|
54
|
+
$attrs['wrapper-class']
|
|
55
55
|
)"
|
|
56
56
|
ref="parentRef"
|
|
57
57
|
>
|
|
@@ -240,7 +240,7 @@ const isPostSetup = ref(false);
|
|
|
240
240
|
const resizableOptions = computed(() => ({
|
|
241
241
|
colCount: props.cols.length,
|
|
242
242
|
widths,
|
|
243
|
-
selector:
|
|
243
|
+
selector: props.header ? void 0 : `tr:first-child > td`,
|
|
244
244
|
...props.resizable,
|
|
245
245
|
onSetup: (el) => {
|
|
246
246
|
isPostSetup.value = true;
|
|
@@ -11,6 +11,7 @@ type RealProps = {
|
|
|
11
11
|
rounded?: boolean;
|
|
12
12
|
border?: boolean;
|
|
13
13
|
cellBorder?: boolean;
|
|
14
|
+
/** Disables the header. This also sets the selector to `tr:first-child > td` instead to avoid issues with the vResizableCols directive. */
|
|
14
15
|
header?: boolean;
|
|
15
16
|
colConfig?: TableColConfig<T>;
|
|
16
17
|
/**
|
|
@@ -10,14 +10,8 @@ const defaultOpts = {
|
|
|
10
10
|
enabled: true
|
|
11
11
|
};
|
|
12
12
|
const callback = (_rect, el) => {
|
|
13
|
-
const $el = getElInfo(el);
|
|
14
|
-
if ($el.justResized) return;
|
|
15
13
|
setColWidths(el);
|
|
16
|
-
|
|
17
|
-
setTimeout(() => {
|
|
18
|
-
positionGrips(el);
|
|
19
|
-
$el.justResized = false;
|
|
20
|
-
}, 0);
|
|
14
|
+
positionGrips(el);
|
|
21
15
|
};
|
|
22
16
|
export const vResizableCols = {
|
|
23
17
|
mounted(el, { value: opts = {} }) {
|
|
@@ -29,7 +23,7 @@ export const vResizableCols = {
|
|
|
29
23
|
},
|
|
30
24
|
updated(el, { value: opts = {} }) {
|
|
31
25
|
const options = override({ ...defaultOpts }, opts);
|
|
32
|
-
const info = el && options.enabled && getElInfo(el);
|
|
26
|
+
const info = el && options.enabled && getElInfo(el, { throwIfMissing: false });
|
|
33
27
|
const hasGrips = el && options.enabled && elMap.get(el)?.grips;
|
|
34
28
|
const colsNotEqual = info && info.colCount !== options.colCount;
|
|
35
29
|
if (!options.enabled || colsNotEqual) {
|
|
@@ -54,7 +48,11 @@ function setWidth(col, amountInPx, el) {
|
|
|
54
48
|
const width = Math.max($el.margin, amountInPx);
|
|
55
49
|
const index = getColEls(el).findIndex((_) => col === _);
|
|
56
50
|
if ($el.fitWidth) {
|
|
57
|
-
|
|
51
|
+
if (amountInPx <= $el.margin) {
|
|
52
|
+
$el.widths.value[index] = `${$el.margin}px`;
|
|
53
|
+
} else {
|
|
54
|
+
$el.widths.value[index] = `${width / getBox(el).width * 100}%`;
|
|
55
|
+
}
|
|
58
56
|
} else {
|
|
59
57
|
$el.widths.value[index] = `${width}px`;
|
|
60
58
|
}
|
|
@@ -86,6 +84,7 @@ function createPointerDownHandler(el) {
|
|
|
86
84
|
castType(e.target);
|
|
87
85
|
$el.target = e.target;
|
|
88
86
|
$el.isDragging = true;
|
|
87
|
+
el.classList.add("dragging");
|
|
89
88
|
e.preventDefault();
|
|
90
89
|
document.addEventListener("pointerup", $el.pointerUpHandler);
|
|
91
90
|
const { col, colNext } = getCols(el);
|
|
@@ -133,11 +132,7 @@ function createPointerMoveHandler(el) {
|
|
|
133
132
|
setWidth(col, newWidth, el);
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
|
-
|
|
137
|
-
setTimeout(() => {
|
|
138
|
-
positionGrips(el);
|
|
139
|
-
$el.justResized = false;
|
|
140
|
-
}, 0);
|
|
135
|
+
positionGrips(el);
|
|
141
136
|
}
|
|
142
137
|
}
|
|
143
138
|
};
|
|
@@ -145,9 +140,11 @@ function createPointerMoveHandler(el) {
|
|
|
145
140
|
function createPointerUpHandler(el) {
|
|
146
141
|
return (e) => {
|
|
147
142
|
const $el = getElInfo(el);
|
|
143
|
+
$el.pointerMoveHandler(e);
|
|
148
144
|
if ($el.isDragging) {
|
|
149
145
|
e.preventDefault();
|
|
150
146
|
$el.isDragging = false;
|
|
147
|
+
el.classList.remove("dragging");
|
|
151
148
|
el.classList.remove("resizable-cols-error");
|
|
152
149
|
$el.offset = 0;
|
|
153
150
|
delete $el.target;
|
|
@@ -187,7 +184,7 @@ function getElInfo(el, { throwIfMissing = true } = {}) {
|
|
|
187
184
|
function getColEls(el) {
|
|
188
185
|
const $el = elMap.get(el);
|
|
189
186
|
if (!$el) unreachable("El went missing.");
|
|
190
|
-
return [...el.querySelectorAll(`:scope ${$el.selector
|
|
187
|
+
return [...el.querySelectorAll(`:scope ${$el.selector ?? "tr > th"}`)];
|
|
191
188
|
}
|
|
192
189
|
function setupColumns(el, opts) {
|
|
193
190
|
const gripWidth = getTestGripSize(el);
|
|
@@ -206,8 +203,10 @@ function setupColumns(el, opts) {
|
|
|
206
203
|
onTeardown: opts.onTeardown
|
|
207
204
|
};
|
|
208
205
|
elMap.set(el, $el);
|
|
209
|
-
const
|
|
210
|
-
|
|
206
|
+
const headers = getColEls(el);
|
|
207
|
+
if (headers.length !== opts.colCount) {
|
|
208
|
+
throw new Error(`Number of headers matched using selector ${opts.selector ?? "tr > th"} does not match number of columns.`);
|
|
209
|
+
}
|
|
211
210
|
setColWidths(el, headers);
|
|
212
211
|
el.style.width = $el.fitWidth ? "" : "min-content";
|
|
213
212
|
const len = opts.colCount;
|
|
@@ -218,13 +217,9 @@ function setupColumns(el, opts) {
|
|
|
218
217
|
el.appendChild(grip);
|
|
219
218
|
$el.grips.set(grip, i);
|
|
220
219
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
$el.justResized = false;
|
|
225
|
-
el.classList.add("resizable-cols-setup");
|
|
226
|
-
opts.onSetup?.(el);
|
|
227
|
-
}, 0);
|
|
220
|
+
positionGrips(el);
|
|
221
|
+
el.classList.add("resizable-cols-setup");
|
|
222
|
+
opts.onSetup?.(el);
|
|
228
223
|
}
|
|
229
224
|
function positionGrips(el) {
|
|
230
225
|
let xPos = 0;
|
|
@@ -291,7 +286,7 @@ function setColWidths(el, children) {
|
|
|
291
286
|
castType(col);
|
|
292
287
|
const colBox = getBox(col);
|
|
293
288
|
if ($el.fixedWidths[i] !== void 0) {
|
|
294
|
-
|
|
289
|
+
$el.widths.value[i] = `${$el.fixedWidths[i]}px`;
|
|
295
290
|
width += $el.fixedWidths[i];
|
|
296
291
|
} else {
|
|
297
292
|
if ($el.fitWidth) {
|
|
@@ -40,7 +40,7 @@ export type ResizableOptions = {
|
|
|
40
40
|
* It can then be used as needed by the component.
|
|
41
41
|
*/
|
|
42
42
|
widths: Ref<string[]>;
|
|
43
|
-
/** The selector to use for the cells. "tr >
|
|
43
|
+
/** The selector to use for the header cells. "tr > th" by default. */
|
|
44
44
|
selector: string;
|
|
45
45
|
/** Is called just after the `resizable-cols-setup` class is added. Can be useful for controlling the styling of wrappers or doing additional things post-setup. The default table element uses it to set the class on the wrapper also. */
|
|
46
46
|
onSetup?: (el: Element) => void;
|
package/package.json
CHANGED
|
@@ -19,8 +19,9 @@ const meta: Meta<typeof LibTable> = {
|
|
|
19
19
|
export default meta
|
|
20
20
|
type Story = StoryObj<typeof LibTable> & { args: {
|
|
21
21
|
slots?: string
|
|
22
|
-
|
|
22
|
+
["wrapper-class"]?: string
|
|
23
23
|
} }
|
|
24
|
+
|
|
24
25
|
export const Primary: Story = {
|
|
25
26
|
render: args => ({
|
|
26
27
|
components,
|
|
@@ -182,7 +183,7 @@ export const StickyHeader: Story = {
|
|
|
182
183
|
// moving the border to the wrapper is to hide the little bits of border sticking out
|
|
183
184
|
// added back the right straight border otherwise the scrollbar looks ass
|
|
184
185
|
// this is ever so slightly visible if there is no scrollbar
|
|
185
|
-
|
|
186
|
+
["wrapper-class"]: `
|
|
186
187
|
max-h-[50dvh]
|
|
187
188
|
`,
|
|
188
189
|
values: Array.from({ length: 200 }).fill(0).map((_, i) => ({
|
|
@@ -205,7 +206,7 @@ export const VirtualizedFixedHeight: Story = {
|
|
|
205
206
|
enabled: true
|
|
206
207
|
},
|
|
207
208
|
stickyHeader: true,
|
|
208
|
-
|
|
209
|
+
["wrapper-class"]: `
|
|
209
210
|
max-h-[50dvh]
|
|
210
211
|
`,
|
|
211
212
|
values: Array.from({ length: 10000 }).fill(0).map((_, i) => ({
|
|
@@ -258,7 +259,7 @@ export const VirtualizedFitWidthFalse: Story = {
|
|
|
258
259
|
[&:not(.resizable-cols-setup)]:w-max
|
|
259
260
|
[&:not(.resizable-cols-setup)_th]:w-max
|
|
260
261
|
`,
|
|
261
|
-
|
|
262
|
+
["wrapper-class"]: `
|
|
262
263
|
max-h-[50dvh]
|
|
263
264
|
`,
|
|
264
265
|
values: Array.from({ length: 10000 }).fill(0).map((_, i) => ({
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
mergedVirtualizerOpts.enabled && mergedVirtualizerOpts.method === 'dynamic' && `
|
|
51
51
|
relative
|
|
52
52
|
`,
|
|
53
|
-
($attrs as any)
|
|
53
|
+
($attrs as any)['wrapper-class'])"
|
|
54
54
|
ref="parentRef"
|
|
55
55
|
>
|
|
56
56
|
<div
|
|
@@ -256,7 +256,7 @@ const isPostSetup = ref(false)
|
|
|
256
256
|
const resizableOptions = computed<MakeRequired<Partial<ResizableOptions>, "colCount" | "widths">>(() => ({
|
|
257
257
|
colCount: props.cols.length,
|
|
258
258
|
widths,
|
|
259
|
-
selector:
|
|
259
|
+
selector: props.header ? undefined : `tr:first-child > td`,
|
|
260
260
|
...props.resizable,
|
|
261
261
|
onSetup: el => {
|
|
262
262
|
isPostSetup.value = true
|
|
@@ -414,6 +414,7 @@ type RealProps = {
|
|
|
414
414
|
rounded?: boolean
|
|
415
415
|
border?: boolean
|
|
416
416
|
cellBorder?: boolean
|
|
417
|
+
/** Disables the header. This also sets the selector to `tr:first-child > td` instead to avoid issues with the vResizableCols directive. */
|
|
417
418
|
header?: boolean
|
|
418
419
|
colConfig?: TableColConfig<T>
|
|
419
420
|
/**
|
|
@@ -24,7 +24,6 @@ type Data = {
|
|
|
24
24
|
onTeardown?: (el: Element) => void
|
|
25
25
|
fixedWidths?: Record<number, number>
|
|
26
26
|
fluidWidthsAsPercentOfFluidWidth?: Record<number, number>
|
|
27
|
-
justResized?: boolean
|
|
28
27
|
}
|
|
29
28
|
const elMap = new WeakMap<HTMLElement, Data>()
|
|
30
29
|
type RawOpts = { value: Partial<ResizableOptions> }
|
|
@@ -40,14 +39,8 @@ const defaultOpts: Omit<ResizableOptions, "colCount" | "widths" | "selector"> =
|
|
|
40
39
|
// note that while it would be nice to throttle this it seems to loose the reference to the original element
|
|
41
40
|
// haven't found where the issue is yet #future
|
|
42
41
|
const callback: ResizeCallback = (_rect: DOMRectReadOnly, el: Element): void => {
|
|
43
|
-
const $el = getElInfo(el as ResizableElement)
|
|
44
|
-
if ($el.justResized) return
|
|
45
42
|
setColWidths(el as ResizableElement)
|
|
46
|
-
|
|
47
|
-
setTimeout(() => {
|
|
48
|
-
positionGrips(el as ResizableElement)
|
|
49
|
-
$el.justResized = false
|
|
50
|
-
}, 0)
|
|
43
|
+
positionGrips(el as ResizableElement)
|
|
51
44
|
}
|
|
52
45
|
|
|
53
46
|
/**
|
|
@@ -119,7 +112,7 @@ export const vResizableCols: Directive = {
|
|
|
119
112
|
},
|
|
120
113
|
updated(el: ResizableElement, { value: opts = {} }: RawOpts) {
|
|
121
114
|
const options = override({ ...defaultOpts }, opts) as ResizableOptions
|
|
122
|
-
const info = el && options.enabled && getElInfo(el)
|
|
115
|
+
const info = el && options.enabled && getElInfo(el, { throwIfMissing: false })
|
|
123
116
|
const hasGrips = el && options.enabled && elMap.get(el)?.grips
|
|
124
117
|
// todo, we should probably check by name
|
|
125
118
|
const colsNotEqual = (info && info.colCount !== options.colCount)
|
|
@@ -148,7 +141,11 @@ function setWidth(col: HTMLElement, amountInPx: number, el: ResizableElement): v
|
|
|
148
141
|
|
|
149
142
|
const index = getColEls(el).findIndex(_ => col === _)
|
|
150
143
|
if ($el.fitWidth) {
|
|
151
|
-
|
|
144
|
+
if (amountInPx <= $el.margin) {
|
|
145
|
+
$el.widths.value[index] = `${$el.margin}px`
|
|
146
|
+
} else {
|
|
147
|
+
$el.widths.value[index] = `${width / getBox(el).width * 100}%`
|
|
148
|
+
}
|
|
152
149
|
} else {
|
|
153
150
|
$el.widths.value[index] = `${width}px`
|
|
154
151
|
}
|
|
@@ -186,6 +183,7 @@ function createPointerDownHandler(el: ResizableElement) {
|
|
|
186
183
|
castType<HTMLElement>(e.target)
|
|
187
184
|
$el.target = e.target
|
|
188
185
|
$el.isDragging = true
|
|
186
|
+
el.classList.add("dragging")
|
|
189
187
|
e.preventDefault()
|
|
190
188
|
|
|
191
189
|
// in case any errors happen, we want the pointer up to still be called
|
|
@@ -245,11 +243,7 @@ function createPointerMoveHandler(el: ResizableElement) {
|
|
|
245
243
|
}
|
|
246
244
|
}
|
|
247
245
|
|
|
248
|
-
|
|
249
|
-
setTimeout(() => {
|
|
250
|
-
positionGrips(el)
|
|
251
|
-
$el.justResized = false
|
|
252
|
-
}, 0)
|
|
246
|
+
positionGrips(el)
|
|
253
247
|
}
|
|
254
248
|
}
|
|
255
249
|
}
|
|
@@ -258,9 +252,11 @@ function createPointerMoveHandler(el: ResizableElement) {
|
|
|
258
252
|
function createPointerUpHandler(el: ResizableElement) {
|
|
259
253
|
return (e: PointerEvent) => {
|
|
260
254
|
const $el = getElInfo(el)
|
|
255
|
+
$el.pointerMoveHandler(e)
|
|
261
256
|
if ($el.isDragging) {
|
|
262
257
|
e.preventDefault()
|
|
263
258
|
$el.isDragging = false
|
|
259
|
+
el.classList.remove("dragging")
|
|
264
260
|
el.classList.remove("resizable-cols-error")
|
|
265
261
|
$el.offset = 0
|
|
266
262
|
delete $el.target
|
|
@@ -303,7 +299,7 @@ function getElInfo<T extends boolean = true>(el: ResizableElement, { throwIfMiss
|
|
|
303
299
|
function getColEls(el: ResizableElement): HTMLElement[] {
|
|
304
300
|
const $el = elMap.get(el)
|
|
305
301
|
if (!$el) unreachable("El went missing.")
|
|
306
|
-
return [...el.querySelectorAll(`:scope ${$el.selector
|
|
302
|
+
return [...el.querySelectorAll(`:scope ${$el.selector ?? "tr > th"}`)] as any
|
|
307
303
|
}
|
|
308
304
|
|
|
309
305
|
function setupColumns(el: ResizableElement, opts: ResizableOptions): void {
|
|
@@ -323,9 +319,10 @@ function setupColumns(el: ResizableElement, opts: ResizableOptions): void {
|
|
|
323
319
|
onTeardown: opts.onTeardown
|
|
324
320
|
}
|
|
325
321
|
elMap.set(el, $el)
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
322
|
+
const headers = getColEls(el)
|
|
323
|
+
if (headers.length !== opts.colCount) {
|
|
324
|
+
throw new Error(`Number of headers matched using selector ${opts.selector ?? "tr > th"} does not match number of columns.`)
|
|
325
|
+
}
|
|
329
326
|
|
|
330
327
|
setColWidths(el, headers)
|
|
331
328
|
el.style.width = $el.fitWidth ? "" : "min-content"
|
|
@@ -338,13 +335,9 @@ function setupColumns(el: ResizableElement, opts: ResizableOptions): void {
|
|
|
338
335
|
el.appendChild(grip)
|
|
339
336
|
$el.grips.set(grip, i)
|
|
340
337
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
$el.justResized = false
|
|
345
|
-
el.classList.add("resizable-cols-setup")
|
|
346
|
-
opts.onSetup?.(el)
|
|
347
|
-
}, 0)
|
|
338
|
+
positionGrips(el)
|
|
339
|
+
el.classList.add("resizable-cols-setup")
|
|
340
|
+
opts.onSetup?.(el)
|
|
348
341
|
}
|
|
349
342
|
|
|
350
343
|
function positionGrips(el: ResizableElement): void {
|
|
@@ -412,7 +405,6 @@ function setColWidths(el: ResizableElement, children?: Element[]): void {
|
|
|
412
405
|
const minFlexWidth = (totalFluidCount * $el.margin)
|
|
413
406
|
const minTotalWidth = minFlexWidth + fixedTotalPx
|
|
414
407
|
|
|
415
|
-
|
|
416
408
|
let leftOverFluidWidth = elWidth - fixedTotalPx
|
|
417
409
|
if (leftOverFluidWidth < minFlexWidth) {
|
|
418
410
|
leftOverFluidWidth = minFlexWidth
|
|
@@ -428,7 +420,7 @@ function setColWidths(el: ResizableElement, children?: Element[]): void {
|
|
|
428
420
|
*/
|
|
429
421
|
const colBox = getBox(col)
|
|
430
422
|
if ($el.fixedWidths![i] !== undefined) {
|
|
431
|
-
|
|
423
|
+
$el.widths.value[i] = `${$el.fixedWidths![i]!}px`
|
|
432
424
|
width += $el.fixedWidths![i]!
|
|
433
425
|
} else {
|
|
434
426
|
if ($el.fitWidth) {
|
|
@@ -41,7 +41,7 @@ export type ResizableOptions = {
|
|
|
41
41
|
* It can then be used as needed by the component.
|
|
42
42
|
*/
|
|
43
43
|
widths: Ref<string[]>
|
|
44
|
-
/** The selector to use for the cells. "tr >
|
|
44
|
+
/** The selector to use for the header cells. "tr > th" by default. */
|
|
45
45
|
selector: string
|
|
46
46
|
/** Is called just after the `resizable-cols-setup` class is added. Can be useful for controlling the styling of wrappers or doing additional things post-setup. The default table element uses it to set the class on the wrapper also. */
|
|
47
47
|
onSetup?: (el: Element) => void
|