@akin2unde/flowui-core 0.3.0 → 1.0.1
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/index.cjs +110 -12
- package/dist/index.d.cts +44 -2
- package/dist/index.d.ts +44 -2
- package/dist/index.js +105 -12
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -23,21 +23,26 @@ __export(index_exports, {
|
|
|
23
23
|
AsyncLabelStore: () => AsyncLabelStore,
|
|
24
24
|
clampNumber: () => clampNumber,
|
|
25
25
|
createAsyncLabelStore: () => createAsyncLabelStore,
|
|
26
|
+
createNotificationTimer: () => createNotificationTimer,
|
|
26
27
|
createTheme: () => createTheme,
|
|
27
28
|
defaultTheme: () => defaultTheme,
|
|
28
29
|
enabledSelectableDescendants: () => enabledSelectableDescendants,
|
|
30
|
+
exportTableToCsv: () => exportTableToCsv,
|
|
29
31
|
exportTableToExcel: () => exportTableToExcel,
|
|
30
32
|
exportTableToPdf: () => exportTableToPdf,
|
|
31
33
|
filterTree: () => filterTree,
|
|
32
34
|
flattenTree: () => flattenTree,
|
|
33
35
|
flowClass: () => flowClass,
|
|
34
36
|
formatLocalDateTime: () => formatLocalDateTime,
|
|
37
|
+
notificationDuration: () => notificationDuration,
|
|
35
38
|
resolveColorValue: () => resolveColorValue,
|
|
36
39
|
resolveFlowStyle: () => resolveFlowStyle,
|
|
40
|
+
resolveTooltipLocation: () => resolveTooltipLocation,
|
|
37
41
|
responsiveCSS: () => responsiveCSS,
|
|
38
42
|
sanitizeInputValue: () => sanitizeInputValue,
|
|
39
43
|
selectedTreeModels: () => selectedTreeModels,
|
|
40
44
|
setLocalDayBoundary: () => setLocalDayBoundary,
|
|
45
|
+
tableToCsv: () => tableToCsv,
|
|
41
46
|
themeToCSS: () => themeToCSS
|
|
42
47
|
});
|
|
43
48
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -497,6 +502,17 @@ function resolveFlowStyle(props, theme) {
|
|
|
497
502
|
style.WebkitBoxOrient = "vertical";
|
|
498
503
|
style.WebkitLineClamp = lines;
|
|
499
504
|
}
|
|
505
|
+
const focusStyle = props.focusStyle ?? theme.focusStyle;
|
|
506
|
+
if (focusStyle === "ring") {
|
|
507
|
+
style["--fui-field-focus-border"] = "var(--fui-color-borderStrong)";
|
|
508
|
+
style["--fui-field-focus-shadow"] = "0 0 0 2px color-mix(in srgb, var(--fui-color-focus) 22%, transparent)";
|
|
509
|
+
} else if (focusStyle === "none") {
|
|
510
|
+
style["--fui-field-focus-border"] = "var(--fui-color-border)";
|
|
511
|
+
style["--fui-field-focus-shadow"] = "none";
|
|
512
|
+
} else if (focusStyle === "border") {
|
|
513
|
+
style["--fui-field-focus-border"] = "var(--fui-color-borderStrong)";
|
|
514
|
+
style["--fui-field-focus-shadow"] = "none";
|
|
515
|
+
}
|
|
500
516
|
Object.assign(style, userStyle);
|
|
501
517
|
return { classNames, style };
|
|
502
518
|
}
|
|
@@ -549,10 +565,24 @@ function download(content, type, fileName) {
|
|
|
549
565
|
anchor.href = url;
|
|
550
566
|
anchor.download = fileName;
|
|
551
567
|
anchor.click();
|
|
552
|
-
URL.revokeObjectURL(url);
|
|
568
|
+
setTimeout(() => URL.revokeObjectURL(url), 1e3);
|
|
569
|
+
}
|
|
570
|
+
function tableToCsv(data, columns) {
|
|
571
|
+
const escape = (value) => '"' + value.replaceAll('"', '""') + '"';
|
|
572
|
+
return [
|
|
573
|
+
columns.map((column) => column.header),
|
|
574
|
+
...data.map((item) => columns.map((column) => cellText(item, column)))
|
|
575
|
+
].map((row) => row.map(escape).join(",")).join("\r\n");
|
|
576
|
+
}
|
|
577
|
+
function exportTableToCsv(data, columns, fileName = "table") {
|
|
578
|
+
download(
|
|
579
|
+
"\uFEFF" + tableToCsv(data, columns),
|
|
580
|
+
"text/csv;charset=utf-8",
|
|
581
|
+
`${fileName}.csv`
|
|
582
|
+
);
|
|
553
583
|
}
|
|
554
584
|
function xml(value) {
|
|
555
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
585
|
+
return value.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g, "").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
556
586
|
}
|
|
557
587
|
function exportTableToExcel(data, columns, fileName = "table") {
|
|
558
588
|
const row = (values) => `<Row>${values.map((value) => `<Cell><Data ss:Type="String">${xml(value)}</Data></Cell>`).join("")}</Row>`;
|
|
@@ -561,21 +591,24 @@ function exportTableToExcel(data, columns, fileName = "table") {
|
|
|
561
591
|
...data.map((item) => row(columns.map((column) => cellText(item, column))))
|
|
562
592
|
].join("");
|
|
563
593
|
const workbook = `<?xml version="1.0"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"><Worksheet ss:Name="Data"><Table>${rows}</Table></Worksheet></Workbook>`;
|
|
564
|
-
download(workbook, "application/vnd.ms-excel", `${fileName}.
|
|
594
|
+
download(workbook, "application/vnd.ms-excel", `${fileName}.xml`);
|
|
565
595
|
}
|
|
566
596
|
function pdfEscape(value) {
|
|
567
597
|
return value.replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)").replace(/[^\x20-\x7e]/g, "?");
|
|
568
598
|
}
|
|
569
599
|
function exportTableToPdf(data, columns, fileName = "table") {
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
600
|
+
const wrap = (line) => line.replace(/\r?\n/g, " ").match(/.{1,82}/gu) ?? [""];
|
|
601
|
+
const header = wrap(columns.map((column) => column.header).join(" | "));
|
|
602
|
+
const lines = data.flatMap(
|
|
603
|
+
(item) => wrap(columns.map((column) => cellText(item, column)).join(" | "))
|
|
604
|
+
);
|
|
605
|
+
const pageLength = Math.max(1, 48 - header.length);
|
|
576
606
|
const pages = Array.from(
|
|
577
|
-
{ length: Math.max(1, Math.ceil(lines.length /
|
|
578
|
-
(_, index) =>
|
|
607
|
+
{ length: Math.max(1, Math.ceil(lines.length / pageLength)) },
|
|
608
|
+
(_, index) => [
|
|
609
|
+
...header,
|
|
610
|
+
...lines.slice(index * pageLength, (index + 1) * pageLength)
|
|
611
|
+
]
|
|
579
612
|
);
|
|
580
613
|
const fontObject = 3 + pages.length * 2;
|
|
581
614
|
const pageObjects = pages.map((_, index) => 3 + index * 2);
|
|
@@ -590,7 +623,7 @@ function exportTableToPdf(data, columns, fileName = "table") {
|
|
|
590
623
|
"BT /F1 10 Tf 40 800 Td",
|
|
591
624
|
...page.flatMap((line, lineIndex) => [
|
|
592
625
|
lineIndex ? "0 -15 Td" : "",
|
|
593
|
-
`(${pdfEscape(line)
|
|
626
|
+
`(${pdfEscape(line)}) Tj`
|
|
594
627
|
]),
|
|
595
628
|
"ET"
|
|
596
629
|
].filter(Boolean).join("\n");
|
|
@@ -944,25 +977,90 @@ var AsyncLabelStore = class {
|
|
|
944
977
|
function createAsyncLabelStore(config) {
|
|
945
978
|
return new AsyncLabelStore(config);
|
|
946
979
|
}
|
|
980
|
+
|
|
981
|
+
// src/tooltip.ts
|
|
982
|
+
function resolveTooltipLocation(preferred, anchor, tooltip, viewport, gap = 6) {
|
|
983
|
+
const available = {
|
|
984
|
+
top: anchor.top,
|
|
985
|
+
right: viewport.width - anchor.right,
|
|
986
|
+
bottom: viewport.height - anchor.bottom,
|
|
987
|
+
left: anchor.left
|
|
988
|
+
};
|
|
989
|
+
const opposite = {
|
|
990
|
+
top: "bottom",
|
|
991
|
+
bottom: "top",
|
|
992
|
+
left: "right",
|
|
993
|
+
right: "left"
|
|
994
|
+
};
|
|
995
|
+
const required = preferred === "top" || preferred === "bottom" ? tooltip.height + gap : tooltip.width + gap;
|
|
996
|
+
return available[preferred] < required && available[opposite[preferred]] > available[preferred] ? opposite[preferred] : preferred;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// src/notification.ts
|
|
1000
|
+
var defaultDurations = {
|
|
1001
|
+
success: 4e3,
|
|
1002
|
+
info: 5e3,
|
|
1003
|
+
warning: 7e3,
|
|
1004
|
+
error: 8e3
|
|
1005
|
+
};
|
|
1006
|
+
function notificationDuration(type, duration, defaultDuration) {
|
|
1007
|
+
if (type === "decision") return 0;
|
|
1008
|
+
if (!(typeof duration === "number" && Number.isFinite(duration) && duration > 0))
|
|
1009
|
+
duration = defaultDuration;
|
|
1010
|
+
return typeof duration === "number" && Number.isFinite(duration) && duration > 0 ? Math.min(duration, 2147483647) : defaultDurations[type];
|
|
1011
|
+
}
|
|
1012
|
+
function createNotificationTimer(duration, onElapsed) {
|
|
1013
|
+
let remaining = duration;
|
|
1014
|
+
let started = 0;
|
|
1015
|
+
let timer;
|
|
1016
|
+
let done = false;
|
|
1017
|
+
return {
|
|
1018
|
+
resume() {
|
|
1019
|
+
if (done || timer !== void 0 || duration === 0) return;
|
|
1020
|
+
started = Date.now();
|
|
1021
|
+
timer = setTimeout(() => {
|
|
1022
|
+
timer = void 0;
|
|
1023
|
+
done = true;
|
|
1024
|
+
onElapsed();
|
|
1025
|
+
}, remaining);
|
|
1026
|
+
},
|
|
1027
|
+
pause() {
|
|
1028
|
+
if (timer === void 0) return;
|
|
1029
|
+
clearTimeout(timer);
|
|
1030
|
+
timer = void 0;
|
|
1031
|
+
remaining = Math.max(0, remaining - (Date.now() - started));
|
|
1032
|
+
},
|
|
1033
|
+
dispose() {
|
|
1034
|
+
done = true;
|
|
1035
|
+
clearTimeout(timer);
|
|
1036
|
+
timer = void 0;
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
947
1040
|
// Annotate the CommonJS export names for ESM import in node:
|
|
948
1041
|
0 && (module.exports = {
|
|
949
1042
|
AsyncLabelStore,
|
|
950
1043
|
clampNumber,
|
|
951
1044
|
createAsyncLabelStore,
|
|
1045
|
+
createNotificationTimer,
|
|
952
1046
|
createTheme,
|
|
953
1047
|
defaultTheme,
|
|
954
1048
|
enabledSelectableDescendants,
|
|
1049
|
+
exportTableToCsv,
|
|
955
1050
|
exportTableToExcel,
|
|
956
1051
|
exportTableToPdf,
|
|
957
1052
|
filterTree,
|
|
958
1053
|
flattenTree,
|
|
959
1054
|
flowClass,
|
|
960
1055
|
formatLocalDateTime,
|
|
1056
|
+
notificationDuration,
|
|
961
1057
|
resolveColorValue,
|
|
962
1058
|
resolveFlowStyle,
|
|
1059
|
+
resolveTooltipLocation,
|
|
963
1060
|
responsiveCSS,
|
|
964
1061
|
sanitizeInputValue,
|
|
965
1062
|
selectedTreeModels,
|
|
966
1063
|
setLocalDayBoundary,
|
|
1064
|
+
tableToCsv,
|
|
967
1065
|
themeToCSS
|
|
968
1066
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -109,10 +109,12 @@ interface TypographyProps {
|
|
|
109
109
|
textTransform?: ResponsiveValue<"none" | "uppercase" | "lowercase" | "capitalize">;
|
|
110
110
|
lines?: ResponsiveValue<number>;
|
|
111
111
|
}
|
|
112
|
+
type FieldFocusStyle = "border" | "ring" | "none";
|
|
112
113
|
interface BaseUIProps extends SpacingProps, LayoutProps, PositionProps, FlexItemProps, BorderProps, VisualProps {
|
|
113
114
|
id?: string;
|
|
114
115
|
hidden?: boolean;
|
|
115
116
|
testId?: string;
|
|
117
|
+
focusStyle?: FieldFocusStyle;
|
|
116
118
|
className?: string;
|
|
117
119
|
style?: Readonly<FlowUIStyle>;
|
|
118
120
|
}
|
|
@@ -151,6 +153,7 @@ interface ThemeColorScheme {
|
|
|
151
153
|
overlay: string;
|
|
152
154
|
}
|
|
153
155
|
interface FlowUITheme {
|
|
156
|
+
focusStyle?: FieldFocusStyle;
|
|
154
157
|
palette: ColorPalette;
|
|
155
158
|
schemes: {
|
|
156
159
|
light: ThemeColorScheme;
|
|
@@ -266,6 +269,7 @@ interface TreeModel extends DropdownModel {
|
|
|
266
269
|
hasChildren?: boolean;
|
|
267
270
|
}
|
|
268
271
|
interface DropdownBehaviorProps extends BaseUIProps, DisableableProps {
|
|
272
|
+
clearable?: boolean;
|
|
269
273
|
options: DropdownModel[];
|
|
270
274
|
searchable?: boolean;
|
|
271
275
|
searchPlaceholder?: string;
|
|
@@ -285,6 +289,7 @@ interface MultiSelectProps extends DropdownBehaviorProps {
|
|
|
285
289
|
chipCloseIconColor?: ColorValue;
|
|
286
290
|
}
|
|
287
291
|
interface TreeMultiSelectProps extends BaseUIProps, DisableableProps {
|
|
292
|
+
clearable?: boolean;
|
|
288
293
|
nodes: TreeModel[];
|
|
289
294
|
value?: Array<string | number>;
|
|
290
295
|
expandedValues?: Array<string | number>;
|
|
@@ -298,6 +303,7 @@ interface TreeMultiSelectProps extends BaseUIProps, DisableableProps {
|
|
|
298
303
|
chipBackgroundColor?: ColorValue;
|
|
299
304
|
chipCloseIconColor?: ColorValue;
|
|
300
305
|
}
|
|
306
|
+
type TabSelectedStyle = "underline" | "fill";
|
|
301
307
|
interface TabItem {
|
|
302
308
|
id: string;
|
|
303
309
|
label: string;
|
|
@@ -319,6 +325,13 @@ interface TableColumn<T> {
|
|
|
319
325
|
align?: "left" | "center" | "right";
|
|
320
326
|
format?: (value: unknown, row: T) => string | number;
|
|
321
327
|
}
|
|
328
|
+
interface TableLoadMoreContext {
|
|
329
|
+
loadedCount: number;
|
|
330
|
+
totalCount?: number;
|
|
331
|
+
loading: boolean;
|
|
332
|
+
hasMore: boolean;
|
|
333
|
+
loadMore: () => void;
|
|
334
|
+
}
|
|
322
335
|
type DialogPosition = "center" | "left" | "right" | "top" | "bottom";
|
|
323
336
|
type TooltipLocation = "top" | "right" | "bottom" | "left";
|
|
324
337
|
interface CardProps extends BaseUIProps {
|
|
@@ -346,6 +359,7 @@ interface TreeProps extends BaseUIProps {
|
|
|
346
359
|
defaultExpanded?: boolean;
|
|
347
360
|
}
|
|
348
361
|
interface TreeDropdownProps extends BaseUIProps, DisableableProps {
|
|
362
|
+
clearable?: boolean;
|
|
349
363
|
nodes: TreeModel[];
|
|
350
364
|
value?: string | number;
|
|
351
365
|
placeholder?: string;
|
|
@@ -424,10 +438,11 @@ interface BreadcrumbItem {
|
|
|
424
438
|
other?: any;
|
|
425
439
|
}
|
|
426
440
|
interface BreadcrumbProps extends BaseUIProps {
|
|
441
|
+
separator?: string;
|
|
427
442
|
items: BreadcrumbItem[];
|
|
428
443
|
separatorIcon?: string;
|
|
429
444
|
}
|
|
430
|
-
type NotificationType = "success" | "error" | "warning" | "info";
|
|
445
|
+
type NotificationType = "success" | "error" | "warning" | "info" | "decision";
|
|
431
446
|
type NotificationHorizontal = "left" | "center" | "right";
|
|
432
447
|
type NotificationVertical = "top" | "bottom";
|
|
433
448
|
interface NotificationProps extends BaseUIProps {
|
|
@@ -436,6 +451,7 @@ interface NotificationProps extends BaseUIProps {
|
|
|
436
451
|
horizontal?: NotificationHorizontal;
|
|
437
452
|
vertical?: NotificationVertical;
|
|
438
453
|
duration?: number;
|
|
454
|
+
defaultDuration?: number;
|
|
439
455
|
dismissible?: boolean;
|
|
440
456
|
}
|
|
441
457
|
interface KnobProps extends BaseUIProps, DisableableProps {
|
|
@@ -503,6 +519,8 @@ type FlowInputMode = NonNullable<InputProps["inputMode"]>;
|
|
|
503
519
|
declare function sanitizeInputValue(value: string, mode?: FlowInputMode): string;
|
|
504
520
|
declare function clampNumber(value: number, min: number, max: number): number;
|
|
505
521
|
|
|
522
|
+
declare function tableToCsv<T>(data: readonly T[], columns: readonly TableColumn<T>[]): string;
|
|
523
|
+
declare function exportTableToCsv<T>(data: T[], columns: TableColumn<T>[], fileName?: string): void;
|
|
506
524
|
/** Downloads an Excel-compatible SpreadsheetML workbook without a runtime dependency. */
|
|
507
525
|
declare function exportTableToExcel<T>(data: T[], columns: TableColumn<T>[], fileName?: string): void;
|
|
508
526
|
/** Downloads a compact PDF containing the currently visible table data. */
|
|
@@ -593,4 +611,28 @@ declare class AsyncLabelStore {
|
|
|
593
611
|
}
|
|
594
612
|
declare function createAsyncLabelStore(config: AsyncLabelConfig): AsyncLabelStore;
|
|
595
613
|
|
|
596
|
-
|
|
614
|
+
declare function resolveTooltipLocation(preferred: TooltipLocation, anchor: {
|
|
615
|
+
top: number;
|
|
616
|
+
right: number;
|
|
617
|
+
bottom: number;
|
|
618
|
+
left: number;
|
|
619
|
+
}, tooltip: {
|
|
620
|
+
width: number;
|
|
621
|
+
height: number;
|
|
622
|
+
}, viewport: {
|
|
623
|
+
width: number;
|
|
624
|
+
height: number;
|
|
625
|
+
}, gap?: number): TooltipLocation;
|
|
626
|
+
|
|
627
|
+
declare function notificationDuration(type: NotificationType, duration?: number, defaultDuration?: number): number;
|
|
628
|
+
declare function createNotificationTimer(duration: number, onElapsed: () => void): {
|
|
629
|
+
resume(): void;
|
|
630
|
+
pause(): void;
|
|
631
|
+
dispose(): void;
|
|
632
|
+
};
|
|
633
|
+
interface NotificationAction {
|
|
634
|
+
label: string;
|
|
635
|
+
onClick: () => void | Promise<void>;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export { type AlignValue, type AsyncLabelCode, type AsyncLabelConfig, type AsyncLabelOptions, type AsyncLabelState, AsyncLabelStore, type AutocompleteProps, type BadgeProps, type BaseUIProps, type BorderProps, type BreadcrumbItem, type BreadcrumbProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type CarouselProps, type ChartData, type ChartProps, type ChartSeries, type ChartType, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DateTimeMode, type DateTimeProps, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownBehaviorProps, type DropdownModel, type FieldFocusStyle, type FileUploadProps, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowInputMode, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type KnobProps, type LabelLookup, type LabelProps, type LabelResolverContext, type LabelResults, type LayoutProps, type ListboxProps, type LoadingProps, type MenuItem, type MultiSelectProps, type NotificationAction, type NotificationHorizontal, type NotificationProps, type NotificationType, type NotificationVertical, type OTPInputProps, type Orientation, type PaletteColor, type PasswordInputProps, type PhoneCountry, type PhoneInputProps, type PhoneNumberValue, type PopoverProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type RatingProps, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SelectionValue, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TabSelectedStyle, type TableColumn, type TableLoadMoreContext, type ThemeColorScheme, type ThemeMode, type TimelineItem, type TimelineProps, type TooltipLocation, type TooltipProps, type TreeDropdownProps, type TreeModel, type TreeMultiSelectProps, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, clampNumber, createAsyncLabelStore, createNotificationTimer, createTheme, defaultTheme, enabledSelectableDescendants, exportTableToCsv, exportTableToExcel, exportTableToPdf, filterTree, flattenTree, flowClass, formatLocalDateTime, notificationDuration, resolveColorValue, resolveFlowStyle, resolveTooltipLocation, responsiveCSS, sanitizeInputValue, selectedTreeModels, setLocalDayBoundary, tableToCsv, themeToCSS };
|
package/dist/index.d.ts
CHANGED
|
@@ -109,10 +109,12 @@ interface TypographyProps {
|
|
|
109
109
|
textTransform?: ResponsiveValue<"none" | "uppercase" | "lowercase" | "capitalize">;
|
|
110
110
|
lines?: ResponsiveValue<number>;
|
|
111
111
|
}
|
|
112
|
+
type FieldFocusStyle = "border" | "ring" | "none";
|
|
112
113
|
interface BaseUIProps extends SpacingProps, LayoutProps, PositionProps, FlexItemProps, BorderProps, VisualProps {
|
|
113
114
|
id?: string;
|
|
114
115
|
hidden?: boolean;
|
|
115
116
|
testId?: string;
|
|
117
|
+
focusStyle?: FieldFocusStyle;
|
|
116
118
|
className?: string;
|
|
117
119
|
style?: Readonly<FlowUIStyle>;
|
|
118
120
|
}
|
|
@@ -151,6 +153,7 @@ interface ThemeColorScheme {
|
|
|
151
153
|
overlay: string;
|
|
152
154
|
}
|
|
153
155
|
interface FlowUITheme {
|
|
156
|
+
focusStyle?: FieldFocusStyle;
|
|
154
157
|
palette: ColorPalette;
|
|
155
158
|
schemes: {
|
|
156
159
|
light: ThemeColorScheme;
|
|
@@ -266,6 +269,7 @@ interface TreeModel extends DropdownModel {
|
|
|
266
269
|
hasChildren?: boolean;
|
|
267
270
|
}
|
|
268
271
|
interface DropdownBehaviorProps extends BaseUIProps, DisableableProps {
|
|
272
|
+
clearable?: boolean;
|
|
269
273
|
options: DropdownModel[];
|
|
270
274
|
searchable?: boolean;
|
|
271
275
|
searchPlaceholder?: string;
|
|
@@ -285,6 +289,7 @@ interface MultiSelectProps extends DropdownBehaviorProps {
|
|
|
285
289
|
chipCloseIconColor?: ColorValue;
|
|
286
290
|
}
|
|
287
291
|
interface TreeMultiSelectProps extends BaseUIProps, DisableableProps {
|
|
292
|
+
clearable?: boolean;
|
|
288
293
|
nodes: TreeModel[];
|
|
289
294
|
value?: Array<string | number>;
|
|
290
295
|
expandedValues?: Array<string | number>;
|
|
@@ -298,6 +303,7 @@ interface TreeMultiSelectProps extends BaseUIProps, DisableableProps {
|
|
|
298
303
|
chipBackgroundColor?: ColorValue;
|
|
299
304
|
chipCloseIconColor?: ColorValue;
|
|
300
305
|
}
|
|
306
|
+
type TabSelectedStyle = "underline" | "fill";
|
|
301
307
|
interface TabItem {
|
|
302
308
|
id: string;
|
|
303
309
|
label: string;
|
|
@@ -319,6 +325,13 @@ interface TableColumn<T> {
|
|
|
319
325
|
align?: "left" | "center" | "right";
|
|
320
326
|
format?: (value: unknown, row: T) => string | number;
|
|
321
327
|
}
|
|
328
|
+
interface TableLoadMoreContext {
|
|
329
|
+
loadedCount: number;
|
|
330
|
+
totalCount?: number;
|
|
331
|
+
loading: boolean;
|
|
332
|
+
hasMore: boolean;
|
|
333
|
+
loadMore: () => void;
|
|
334
|
+
}
|
|
322
335
|
type DialogPosition = "center" | "left" | "right" | "top" | "bottom";
|
|
323
336
|
type TooltipLocation = "top" | "right" | "bottom" | "left";
|
|
324
337
|
interface CardProps extends BaseUIProps {
|
|
@@ -346,6 +359,7 @@ interface TreeProps extends BaseUIProps {
|
|
|
346
359
|
defaultExpanded?: boolean;
|
|
347
360
|
}
|
|
348
361
|
interface TreeDropdownProps extends BaseUIProps, DisableableProps {
|
|
362
|
+
clearable?: boolean;
|
|
349
363
|
nodes: TreeModel[];
|
|
350
364
|
value?: string | number;
|
|
351
365
|
placeholder?: string;
|
|
@@ -424,10 +438,11 @@ interface BreadcrumbItem {
|
|
|
424
438
|
other?: any;
|
|
425
439
|
}
|
|
426
440
|
interface BreadcrumbProps extends BaseUIProps {
|
|
441
|
+
separator?: string;
|
|
427
442
|
items: BreadcrumbItem[];
|
|
428
443
|
separatorIcon?: string;
|
|
429
444
|
}
|
|
430
|
-
type NotificationType = "success" | "error" | "warning" | "info";
|
|
445
|
+
type NotificationType = "success" | "error" | "warning" | "info" | "decision";
|
|
431
446
|
type NotificationHorizontal = "left" | "center" | "right";
|
|
432
447
|
type NotificationVertical = "top" | "bottom";
|
|
433
448
|
interface NotificationProps extends BaseUIProps {
|
|
@@ -436,6 +451,7 @@ interface NotificationProps extends BaseUIProps {
|
|
|
436
451
|
horizontal?: NotificationHorizontal;
|
|
437
452
|
vertical?: NotificationVertical;
|
|
438
453
|
duration?: number;
|
|
454
|
+
defaultDuration?: number;
|
|
439
455
|
dismissible?: boolean;
|
|
440
456
|
}
|
|
441
457
|
interface KnobProps extends BaseUIProps, DisableableProps {
|
|
@@ -503,6 +519,8 @@ type FlowInputMode = NonNullable<InputProps["inputMode"]>;
|
|
|
503
519
|
declare function sanitizeInputValue(value: string, mode?: FlowInputMode): string;
|
|
504
520
|
declare function clampNumber(value: number, min: number, max: number): number;
|
|
505
521
|
|
|
522
|
+
declare function tableToCsv<T>(data: readonly T[], columns: readonly TableColumn<T>[]): string;
|
|
523
|
+
declare function exportTableToCsv<T>(data: T[], columns: TableColumn<T>[], fileName?: string): void;
|
|
506
524
|
/** Downloads an Excel-compatible SpreadsheetML workbook without a runtime dependency. */
|
|
507
525
|
declare function exportTableToExcel<T>(data: T[], columns: TableColumn<T>[], fileName?: string): void;
|
|
508
526
|
/** Downloads a compact PDF containing the currently visible table data. */
|
|
@@ -593,4 +611,28 @@ declare class AsyncLabelStore {
|
|
|
593
611
|
}
|
|
594
612
|
declare function createAsyncLabelStore(config: AsyncLabelConfig): AsyncLabelStore;
|
|
595
613
|
|
|
596
|
-
|
|
614
|
+
declare function resolveTooltipLocation(preferred: TooltipLocation, anchor: {
|
|
615
|
+
top: number;
|
|
616
|
+
right: number;
|
|
617
|
+
bottom: number;
|
|
618
|
+
left: number;
|
|
619
|
+
}, tooltip: {
|
|
620
|
+
width: number;
|
|
621
|
+
height: number;
|
|
622
|
+
}, viewport: {
|
|
623
|
+
width: number;
|
|
624
|
+
height: number;
|
|
625
|
+
}, gap?: number): TooltipLocation;
|
|
626
|
+
|
|
627
|
+
declare function notificationDuration(type: NotificationType, duration?: number, defaultDuration?: number): number;
|
|
628
|
+
declare function createNotificationTimer(duration: number, onElapsed: () => void): {
|
|
629
|
+
resume(): void;
|
|
630
|
+
pause(): void;
|
|
631
|
+
dispose(): void;
|
|
632
|
+
};
|
|
633
|
+
interface NotificationAction {
|
|
634
|
+
label: string;
|
|
635
|
+
onClick: () => void | Promise<void>;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export { type AlignValue, type AsyncLabelCode, type AsyncLabelConfig, type AsyncLabelOptions, type AsyncLabelState, AsyncLabelStore, type AutocompleteProps, type BadgeProps, type BaseUIProps, type BorderProps, type BreadcrumbItem, type BreadcrumbProps, type BreakpointName, type ButtonGroupProps, type ButtonProps, type CSSLength, type CSSVariableStyle, type CardProps, type CarouselProps, type ChartData, type ChartProps, type ChartSeries, type ChartType, type ColorPalette, type ColorScale, type ColorShade, type ColorValue, type ComponentSize, type ComponentVariant, type DateTimeMode, type DateTimeProps, type DeepPartial, type DialogPosition, type DimensionValue, type DisableableProps, type DividerProps, type DropdownBehaviorProps, type DropdownModel, type FieldFocusStyle, type FileUploadProps, type FlexContainerProps, type FlexDirection, type FlexItemProps, type FlexWrap, type FlowInputMode, type FlowUIStyle, type FlowUITheme, type FocusableProps, type HStackProps, type IconProps, type ImageProps, type InputProps, type JustifyValue, type KnobProps, type LabelLookup, type LabelProps, type LabelResolverContext, type LabelResults, type LayoutProps, type ListboxProps, type LoadingProps, type MenuItem, type MultiSelectProps, type NotificationAction, type NotificationHorizontal, type NotificationProps, type NotificationType, type NotificationVertical, type OTPInputProps, type Orientation, type PaletteColor, type PasswordInputProps, type PhoneCountry, type PhoneInputProps, type PhoneNumberValue, type PopoverProps, type PositionProps, type PositionValue, type RadiusToken, type RadiusValue, type RatingProps, type ReadOnlyProps, type RequiredProps, type ResolvedStyle, type ResponsiveObject, type ResponsiveValue, type SchemeColor, type SelectOption, type SelectionValue, type SliderProps, type SortDirection, type SortState, type SpacingProps, type SpacingToken, type SpacingValue, type StackProps, type StyleResolution, type SwitchProps, type TabItem, type TabSelectedStyle, type TableColumn, type TableLoadMoreContext, type ThemeColorScheme, type ThemeMode, type TimelineItem, type TimelineProps, type TooltipLocation, type TooltipProps, type TreeDropdownProps, type TreeModel, type TreeMultiSelectProps, type TreeProps, type TypographyProps, type VStackProps, type VisualProps, clampNumber, createAsyncLabelStore, createNotificationTimer, createTheme, defaultTheme, enabledSelectableDescendants, exportTableToCsv, exportTableToExcel, exportTableToPdf, filterTree, flattenTree, flowClass, formatLocalDateTime, notificationDuration, resolveColorValue, resolveFlowStyle, resolveTooltipLocation, responsiveCSS, sanitizeInputValue, selectedTreeModels, setLocalDayBoundary, tableToCsv, themeToCSS };
|
package/dist/index.js
CHANGED
|
@@ -453,6 +453,17 @@ function resolveFlowStyle(props, theme) {
|
|
|
453
453
|
style.WebkitBoxOrient = "vertical";
|
|
454
454
|
style.WebkitLineClamp = lines;
|
|
455
455
|
}
|
|
456
|
+
const focusStyle = props.focusStyle ?? theme.focusStyle;
|
|
457
|
+
if (focusStyle === "ring") {
|
|
458
|
+
style["--fui-field-focus-border"] = "var(--fui-color-borderStrong)";
|
|
459
|
+
style["--fui-field-focus-shadow"] = "0 0 0 2px color-mix(in srgb, var(--fui-color-focus) 22%, transparent)";
|
|
460
|
+
} else if (focusStyle === "none") {
|
|
461
|
+
style["--fui-field-focus-border"] = "var(--fui-color-border)";
|
|
462
|
+
style["--fui-field-focus-shadow"] = "none";
|
|
463
|
+
} else if (focusStyle === "border") {
|
|
464
|
+
style["--fui-field-focus-border"] = "var(--fui-color-borderStrong)";
|
|
465
|
+
style["--fui-field-focus-shadow"] = "none";
|
|
466
|
+
}
|
|
456
467
|
Object.assign(style, userStyle);
|
|
457
468
|
return { classNames, style };
|
|
458
469
|
}
|
|
@@ -505,10 +516,24 @@ function download(content, type, fileName) {
|
|
|
505
516
|
anchor.href = url;
|
|
506
517
|
anchor.download = fileName;
|
|
507
518
|
anchor.click();
|
|
508
|
-
URL.revokeObjectURL(url);
|
|
519
|
+
setTimeout(() => URL.revokeObjectURL(url), 1e3);
|
|
520
|
+
}
|
|
521
|
+
function tableToCsv(data, columns) {
|
|
522
|
+
const escape = (value) => '"' + value.replaceAll('"', '""') + '"';
|
|
523
|
+
return [
|
|
524
|
+
columns.map((column) => column.header),
|
|
525
|
+
...data.map((item) => columns.map((column) => cellText(item, column)))
|
|
526
|
+
].map((row) => row.map(escape).join(",")).join("\r\n");
|
|
527
|
+
}
|
|
528
|
+
function exportTableToCsv(data, columns, fileName = "table") {
|
|
529
|
+
download(
|
|
530
|
+
"\uFEFF" + tableToCsv(data, columns),
|
|
531
|
+
"text/csv;charset=utf-8",
|
|
532
|
+
`${fileName}.csv`
|
|
533
|
+
);
|
|
509
534
|
}
|
|
510
535
|
function xml(value) {
|
|
511
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
536
|
+
return value.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g, "").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
512
537
|
}
|
|
513
538
|
function exportTableToExcel(data, columns, fileName = "table") {
|
|
514
539
|
const row = (values) => `<Row>${values.map((value) => `<Cell><Data ss:Type="String">${xml(value)}</Data></Cell>`).join("")}</Row>`;
|
|
@@ -517,21 +542,24 @@ function exportTableToExcel(data, columns, fileName = "table") {
|
|
|
517
542
|
...data.map((item) => row(columns.map((column) => cellText(item, column))))
|
|
518
543
|
].join("");
|
|
519
544
|
const workbook = `<?xml version="1.0"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"><Worksheet ss:Name="Data"><Table>${rows}</Table></Worksheet></Workbook>`;
|
|
520
|
-
download(workbook, "application/vnd.ms-excel", `${fileName}.
|
|
545
|
+
download(workbook, "application/vnd.ms-excel", `${fileName}.xml`);
|
|
521
546
|
}
|
|
522
547
|
function pdfEscape(value) {
|
|
523
548
|
return value.replaceAll("\\", "\\\\").replaceAll("(", "\\(").replaceAll(")", "\\)").replace(/[^\x20-\x7e]/g, "?");
|
|
524
549
|
}
|
|
525
550
|
function exportTableToPdf(data, columns, fileName = "table") {
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
551
|
+
const wrap = (line) => line.replace(/\r?\n/g, " ").match(/.{1,82}/gu) ?? [""];
|
|
552
|
+
const header = wrap(columns.map((column) => column.header).join(" | "));
|
|
553
|
+
const lines = data.flatMap(
|
|
554
|
+
(item) => wrap(columns.map((column) => cellText(item, column)).join(" | "))
|
|
555
|
+
);
|
|
556
|
+
const pageLength = Math.max(1, 48 - header.length);
|
|
532
557
|
const pages = Array.from(
|
|
533
|
-
{ length: Math.max(1, Math.ceil(lines.length /
|
|
534
|
-
(_, index) =>
|
|
558
|
+
{ length: Math.max(1, Math.ceil(lines.length / pageLength)) },
|
|
559
|
+
(_, index) => [
|
|
560
|
+
...header,
|
|
561
|
+
...lines.slice(index * pageLength, (index + 1) * pageLength)
|
|
562
|
+
]
|
|
535
563
|
);
|
|
536
564
|
const fontObject = 3 + pages.length * 2;
|
|
537
565
|
const pageObjects = pages.map((_, index) => 3 + index * 2);
|
|
@@ -546,7 +574,7 @@ function exportTableToPdf(data, columns, fileName = "table") {
|
|
|
546
574
|
"BT /F1 10 Tf 40 800 Td",
|
|
547
575
|
...page.flatMap((line, lineIndex) => [
|
|
548
576
|
lineIndex ? "0 -15 Td" : "",
|
|
549
|
-
`(${pdfEscape(line)
|
|
577
|
+
`(${pdfEscape(line)}) Tj`
|
|
550
578
|
]),
|
|
551
579
|
"ET"
|
|
552
580
|
].filter(Boolean).join("\n");
|
|
@@ -900,24 +928,89 @@ var AsyncLabelStore = class {
|
|
|
900
928
|
function createAsyncLabelStore(config) {
|
|
901
929
|
return new AsyncLabelStore(config);
|
|
902
930
|
}
|
|
931
|
+
|
|
932
|
+
// src/tooltip.ts
|
|
933
|
+
function resolveTooltipLocation(preferred, anchor, tooltip, viewport, gap = 6) {
|
|
934
|
+
const available = {
|
|
935
|
+
top: anchor.top,
|
|
936
|
+
right: viewport.width - anchor.right,
|
|
937
|
+
bottom: viewport.height - anchor.bottom,
|
|
938
|
+
left: anchor.left
|
|
939
|
+
};
|
|
940
|
+
const opposite = {
|
|
941
|
+
top: "bottom",
|
|
942
|
+
bottom: "top",
|
|
943
|
+
left: "right",
|
|
944
|
+
right: "left"
|
|
945
|
+
};
|
|
946
|
+
const required = preferred === "top" || preferred === "bottom" ? tooltip.height + gap : tooltip.width + gap;
|
|
947
|
+
return available[preferred] < required && available[opposite[preferred]] > available[preferred] ? opposite[preferred] : preferred;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/notification.ts
|
|
951
|
+
var defaultDurations = {
|
|
952
|
+
success: 4e3,
|
|
953
|
+
info: 5e3,
|
|
954
|
+
warning: 7e3,
|
|
955
|
+
error: 8e3
|
|
956
|
+
};
|
|
957
|
+
function notificationDuration(type, duration, defaultDuration) {
|
|
958
|
+
if (type === "decision") return 0;
|
|
959
|
+
if (!(typeof duration === "number" && Number.isFinite(duration) && duration > 0))
|
|
960
|
+
duration = defaultDuration;
|
|
961
|
+
return typeof duration === "number" && Number.isFinite(duration) && duration > 0 ? Math.min(duration, 2147483647) : defaultDurations[type];
|
|
962
|
+
}
|
|
963
|
+
function createNotificationTimer(duration, onElapsed) {
|
|
964
|
+
let remaining = duration;
|
|
965
|
+
let started = 0;
|
|
966
|
+
let timer;
|
|
967
|
+
let done = false;
|
|
968
|
+
return {
|
|
969
|
+
resume() {
|
|
970
|
+
if (done || timer !== void 0 || duration === 0) return;
|
|
971
|
+
started = Date.now();
|
|
972
|
+
timer = setTimeout(() => {
|
|
973
|
+
timer = void 0;
|
|
974
|
+
done = true;
|
|
975
|
+
onElapsed();
|
|
976
|
+
}, remaining);
|
|
977
|
+
},
|
|
978
|
+
pause() {
|
|
979
|
+
if (timer === void 0) return;
|
|
980
|
+
clearTimeout(timer);
|
|
981
|
+
timer = void 0;
|
|
982
|
+
remaining = Math.max(0, remaining - (Date.now() - started));
|
|
983
|
+
},
|
|
984
|
+
dispose() {
|
|
985
|
+
done = true;
|
|
986
|
+
clearTimeout(timer);
|
|
987
|
+
timer = void 0;
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
}
|
|
903
991
|
export {
|
|
904
992
|
AsyncLabelStore,
|
|
905
993
|
clampNumber,
|
|
906
994
|
createAsyncLabelStore,
|
|
995
|
+
createNotificationTimer,
|
|
907
996
|
createTheme,
|
|
908
997
|
defaultTheme,
|
|
909
998
|
enabledSelectableDescendants,
|
|
999
|
+
exportTableToCsv,
|
|
910
1000
|
exportTableToExcel,
|
|
911
1001
|
exportTableToPdf,
|
|
912
1002
|
filterTree,
|
|
913
1003
|
flattenTree,
|
|
914
1004
|
flowClass,
|
|
915
1005
|
formatLocalDateTime,
|
|
1006
|
+
notificationDuration,
|
|
916
1007
|
resolveColorValue,
|
|
917
1008
|
resolveFlowStyle,
|
|
1009
|
+
resolveTooltipLocation,
|
|
918
1010
|
responsiveCSS,
|
|
919
1011
|
sanitizeInputValue,
|
|
920
1012
|
selectedTreeModels,
|
|
921
1013
|
setLocalDayBoundary,
|
|
1014
|
+
tableToCsv,
|
|
922
1015
|
themeToCSS
|
|
923
1016
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akin2unde/flowui-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Framework-independent contracts, themes and style resolution for FlowUI.",
|
|
5
5
|
"author": "Akintunde Morakinyo",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "tsup src/index.ts --format esm,cjs --
|
|
37
|
+
"build": "tsup src/index.ts --format esm,cjs --config ../../scripts/tsup.config.mjs --clean",
|
|
38
38
|
"typecheck": "tsc --noEmit",
|
|
39
39
|
"test": "vitest run",
|
|
40
40
|
"prepack": "node ../../scripts/prepack.mjs core"
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.5.0",
|
|
47
|
-
"typescript": "
|
|
48
|
-
"vitest": "^
|
|
47
|
+
"typescript": "~6.0.3",
|
|
48
|
+
"vitest": "^4.0.8"
|
|
49
49
|
},
|
|
50
50
|
"sideEffects": false
|
|
51
51
|
}
|