@svadmin/ui 0.121.0 → 0.125.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.
- package/dist/app.css +757 -7
- package/dist/app.theme.css +757 -7
- package/dist/components/AbacPolicyMatrix.svelte +356 -0
- package/dist/components/AbacPolicyMatrix.svelte.d.ts +30 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/ActionPalette.svelte +272 -0
- package/dist/components/ActionPalette.svelte.d.ts +23 -0
- package/dist/components/AdminCopilotWidget.svelte +316 -0
- package/dist/components/AdminCopilotWidget.svelte.d.ts +33 -0
- package/dist/components/AnnouncementBanner.svelte +325 -0
- package/dist/components/AnnouncementBanner.svelte.d.ts +49 -0
- package/dist/components/ApiPlayground.svelte +255 -0
- package/dist/components/ApiPlayground.svelte.d.ts +24 -0
- package/dist/components/ApprovalChainBuilder.svelte +262 -0
- package/dist/components/ApprovalChainBuilder.svelte.d.ts +20 -0
- package/dist/components/ApprovalTimeline.svelte +8 -1
- package/dist/components/AsyncExportModal.svelte +551 -0
- package/dist/components/AsyncExportModal.svelte.d.ts +50 -0
- package/dist/components/AudioFeedbackProvider.svelte +131 -0
- package/dist/components/AudioFeedbackProvider.svelte.d.ts +11 -0
- package/dist/components/AuditLogViewer.svelte +1 -1
- package/dist/components/AuditTrailInspector.svelte +448 -0
- package/dist/components/AuditTrailInspector.svelte.d.ts +44 -0
- package/dist/components/BatchEditModal.svelte +266 -0
- package/dist/components/BatchEditModal.svelte.d.ts +27 -0
- package/dist/components/BillingInvoiceDrawer.svelte +206 -0
- package/dist/components/BillingInvoiceDrawer.svelte.d.ts +30 -0
- package/dist/components/CanvasAnnotation.svelte +1 -1
- package/dist/components/ChartAnnotationOverlay.svelte +228 -0
- package/dist/components/ChartAnnotationOverlay.svelte.d.ts +21 -0
- package/dist/components/ClusterTopologyGraph.svelte +317 -0
- package/dist/components/ClusterTopologyGraph.svelte.d.ts +31 -0
- package/dist/components/ColumnFilterBuilder.svelte +135 -0
- package/dist/components/ColumnFilterBuilder.svelte.d.ts +20 -0
- package/dist/components/ColumnMappingTable.svelte +174 -0
- package/dist/components/ColumnMappingTable.svelte.d.ts +23 -0
- package/dist/components/ColumnSettings.svelte +1 -1
- package/dist/components/ColumnVisibilityDrawer.svelte +541 -0
- package/dist/components/ColumnVisibilityDrawer.svelte.d.ts +16 -0
- package/dist/components/ConcurrentConflictModal.svelte +7 -7
- package/dist/components/ConversionFunnel.svelte +154 -0
- package/dist/components/ConversionFunnel.svelte.d.ts +22 -0
- package/dist/components/CronExpressionBuilder.svelte +1 -1
- package/dist/components/CursorListFooter.svelte +67 -0
- package/dist/components/CursorListFooter.svelte.d.ts +17 -0
- package/dist/components/DashboardGridLayout.svelte +309 -0
- package/dist/components/DashboardGridLayout.svelte.d.ts +30 -0
- package/dist/components/DashboardLayoutStorage.svelte +278 -0
- package/dist/components/DashboardLayoutStorage.svelte.d.ts +23 -0
- package/dist/components/DataFreshnessIndicator.svelte +149 -0
- package/dist/components/DataFreshnessIndicator.svelte.d.ts +20 -0
- package/dist/components/DataImportDropzone.svelte +215 -0
- package/dist/components/DataImportDropzone.svelte.d.ts +24 -0
- package/dist/components/DataLineageGraph.svelte +203 -0
- package/dist/components/DataLineageGraph.svelte.d.ts +26 -0
- package/dist/components/DataMaskPolicyEngine.svelte +291 -0
- package/dist/components/DataMaskPolicyEngine.svelte.d.ts +25 -0
- package/dist/components/DataScopeRuleEditor.svelte +142 -0
- package/dist/components/DataScopeRuleEditor.svelte.d.ts +19 -0
- package/dist/components/DataScreenContainer.svelte +160 -0
- package/dist/components/DataScreenContainer.svelte.d.ts +15 -0
- package/dist/components/DecisionTable.svelte +1 -1
- package/dist/components/DevTools.svelte +4 -4
- package/dist/components/DraggableRowTable.svelte +1 -1
- package/dist/components/DualApprovalGate.svelte +485 -0
- package/dist/components/DualApprovalGate.svelte.d.ts +58 -0
- package/dist/components/EditableTable.svelte +1 -1
- package/dist/components/ElectronicSealStamp.svelte +102 -0
- package/dist/components/ElectronicSealStamp.svelte.d.ts +14 -0
- package/dist/components/EnvVariableEditor.svelte +284 -0
- package/dist/components/EnvVariableEditor.svelte.d.ts +17 -0
- package/dist/components/ExcelImportWizard.svelte +2 -2
- package/dist/components/FeatureAnnouncementModal.svelte +173 -0
- package/dist/components/FeatureAnnouncementModal.svelte.d.ts +21 -0
- package/dist/components/FilterTagBar.svelte +210 -0
- package/dist/components/FilterTagBar.svelte.d.ts +23 -0
- package/dist/components/FormulaField.svelte +149 -0
- package/dist/components/FormulaField.svelte.d.ts +18 -0
- package/dist/components/GeoScatterMap.svelte +225 -0
- package/dist/components/GeoScatterMap.svelte.d.ts +22 -0
- package/dist/components/GlobalShortcuts.svelte +1 -1
- package/dist/components/HmacSignatureCalculator.svelte +199 -0
- package/dist/components/HmacSignatureCalculator.svelte.d.ts +10 -0
- package/dist/components/I18nLanguagePackEditor.svelte +208 -0
- package/dist/components/I18nLanguagePackEditor.svelte.d.ts +17 -0
- package/dist/components/ImageCropper.svelte +1 -1
- package/dist/components/ImportPreviewValidator.svelte +239 -0
- package/dist/components/ImportPreviewValidator.svelte.d.ts +26 -0
- package/dist/components/ImportWizard.svelte +1 -1
- package/dist/components/IncidentWarRoomDrawer.svelte +194 -0
- package/dist/components/IncidentWarRoomDrawer.svelte.d.ts +24 -0
- package/dist/components/JsonSchemaForm.svelte +5 -5
- package/dist/components/JsonViewer.svelte +11 -11
- package/dist/components/KeyboardShortcutsModal.svelte +362 -0
- package/dist/components/KeyboardShortcutsModal.svelte.d.ts +22 -0
- package/dist/components/KpiCard.svelte +5 -5
- package/dist/components/ListPagination.svelte +39 -3
- package/dist/components/LiveStreamLogViewer.svelte +185 -0
- package/dist/components/LiveStreamLogViewer.svelte.d.ts +21 -0
- package/dist/components/MasterDetailView.svelte +1 -1
- package/dist/components/MasterSubTableDrawer.svelte +223 -0
- package/dist/components/MasterSubTableDrawer.svelte.d.ts +25 -0
- package/dist/components/MetricGrid.svelte +2 -2
- package/dist/components/MicroAppBridge.svelte +59 -0
- package/dist/components/MicroAppBridge.svelte.d.ts +11 -0
- package/dist/components/MockDataInterceptor.svelte +292 -0
- package/dist/components/MockDataInterceptor.svelte.d.ts +27 -0
- package/dist/components/OfflineSyncBanner.svelte +1 -1
- package/dist/components/OmnibarCommandPalette.svelte +320 -0
- package/dist/components/OmnibarCommandPalette.svelte.d.ts +27 -0
- package/dist/components/OrgChart.svelte +1 -1
- package/dist/components/OrgTreePicker.svelte +1 -1
- package/dist/components/OtpInput.svelte +5 -5
- package/dist/components/PageSkeleton.svelte +19 -5
- package/dist/components/PageSkeleton.svelte.d.ts +5 -3
- package/dist/components/PdfDocumentViewer.svelte +2 -2
- package/dist/components/PeriodComparisonCard.svelte +142 -0
- package/dist/components/PeriodComparisonCard.svelte.d.ts +16 -0
- package/dist/components/PermissionSimulator.svelte +319 -0
- package/dist/components/PermissionSimulator.svelte.d.ts +34 -0
- package/dist/components/PivotDrilldownModal.svelte +6 -6
- package/dist/components/PivotMatrix.svelte +271 -0
- package/dist/components/PivotMatrix.svelte.d.ts +32 -0
- package/dist/components/PivotTable.svelte +1 -1
- package/dist/components/PlanUsageQuotaBar.svelte +154 -0
- package/dist/components/PlanUsageQuotaBar.svelte.d.ts +26 -0
- package/dist/components/Popconfirm.svelte +20 -8
- package/dist/components/Popconfirm.svelte.d.ts +3 -1
- package/dist/components/PricingCard.svelte +1 -1
- package/dist/components/PricingTable.svelte +1 -1
- package/dist/components/PrintableBill.svelte +2 -2
- package/dist/components/PrintableReportLayout.svelte +259 -0
- package/dist/components/PrintableReportLayout.svelte.d.ts +32 -0
- package/dist/components/ProSkeleton.svelte +10 -6
- package/dist/components/ProSkeleton.svelte.d.ts +2 -0
- package/dist/components/QueryAiExplainer.svelte +148 -0
- package/dist/components/QueryAiExplainer.svelte.d.ts +16 -0
- package/dist/components/QueryBuilder.svelte +456 -0
- package/dist/components/QueryBuilder.svelte.d.ts +33 -0
- package/dist/components/ResultPage.svelte +2 -2
- package/dist/components/RolePermissionComparator.svelte +273 -0
- package/dist/components/RolePermissionComparator.svelte.d.ts +28 -0
- package/dist/components/RuleExpressionBuilder.svelte +380 -0
- package/dist/components/RuleExpressionBuilder.svelte.d.ts +31 -0
- package/dist/components/SafeDeleteConfirm.svelte +5 -5
- package/dist/components/SankeyChart.svelte +111 -0
- package/dist/components/SankeyChart.svelte.d.ts +22 -0
- package/dist/components/ScheduledJobManager.svelte +225 -0
- package/dist/components/ScheduledJobManager.svelte.d.ts +23 -0
- package/dist/components/SchemaVisualModeler.svelte +336 -0
- package/dist/components/SchemaVisualModeler.svelte.d.ts +17 -0
- package/dist/components/ScreenAntiLeakGuard.svelte +88 -0
- package/dist/components/ScreenAntiLeakGuard.svelte.d.ts +12 -0
- package/dist/components/SecureDataExporter.svelte +296 -0
- package/dist/components/SecureDataExporter.svelte.d.ts +29 -0
- package/dist/components/SensitiveDataMask.svelte +81 -22
- package/dist/components/SensitiveDataMask.svelte.d.ts +15 -10
- package/dist/components/ServerStatusGrid.svelte +179 -0
- package/dist/components/ServerStatusGrid.svelte.d.ts +21 -0
- package/dist/components/SessionTimeoutGuard.svelte +154 -0
- package/dist/components/SessionTimeoutGuard.svelte.d.ts +25 -0
- package/dist/components/SignaturePad.svelte +1 -1
- package/dist/components/SliderCaptcha.svelte +1 -1
- package/dist/components/SnapshotTimelineReplay.svelte +219 -0
- package/dist/components/SnapshotTimelineReplay.svelte.d.ts +19 -0
- package/dist/components/SplitPaneLayout.svelte +1 -1
- package/dist/components/SpreadsheetView.svelte +1 -1
- package/dist/components/SqlConsole.svelte +247 -0
- package/dist/components/SqlConsole.svelte.d.ts +20 -0
- package/dist/components/StepForm.svelte +1 -1
- package/dist/components/StepWizard.svelte +513 -0
- package/dist/components/StepWizard.svelte.d.ts +49 -0
- package/dist/components/SystemCapacityForecastCard.svelte +132 -0
- package/dist/components/SystemCapacityForecastCard.svelte.d.ts +19 -0
- package/dist/components/SystemHealthCheckDashboard.svelte +306 -0
- package/dist/components/SystemHealthCheckDashboard.svelte.d.ts +24 -0
- package/dist/components/TableAggregationFooter.svelte +173 -0
- package/dist/components/TableAggregationFooter.svelte.d.ts +22 -0
- package/dist/components/TableClipboardManager.svelte +307 -0
- package/dist/components/TableClipboardManager.svelte.d.ts +13 -0
- package/dist/components/TaskCenter.svelte +46 -38
- package/dist/components/TenantContextSwitcher.svelte +314 -0
- package/dist/components/TenantContextSwitcher.svelte.d.ts +35 -0
- package/dist/components/TenantQuotasMatrix.svelte +229 -0
- package/dist/components/TenantQuotasMatrix.svelte.d.ts +22 -0
- package/dist/components/TextDiffViewer.svelte +613 -0
- package/dist/components/TextDiffViewer.svelte.d.ts +39 -0
- package/dist/components/ThreadedCommentDrawer.svelte +246 -0
- package/dist/components/ThreadedCommentDrawer.svelte.d.ts +26 -0
- package/dist/components/TierFeatureComparison.svelte +147 -0
- package/dist/components/TierFeatureComparison.svelte.d.ts +28 -0
- package/dist/components/TreeTransfer.svelte +1 -1
- package/dist/components/TreeTransferSelect.svelte +333 -0
- package/dist/components/TreeTransferSelect.svelte.d.ts +18 -0
- package/dist/components/UnsavedChangesGuard.svelte +5 -5
- package/dist/components/UsageCard.svelte +1 -1
- package/dist/components/VersionDiffViewer.svelte +1 -1
- package/dist/components/VirtualCardGrid.svelte +180 -0
- package/dist/components/VirtualCardGrid.svelte.d.ts +65 -0
- package/dist/components/VirtualTable.svelte +1 -1
- package/dist/components/VirtualTreeSelect.svelte +1 -1
- package/dist/components/WebhookSimulator.svelte +263 -0
- package/dist/components/WebhookSimulator.svelte.d.ts +26 -0
- package/dist/components/WidgetContainer.svelte +204 -0
- package/dist/components/WidgetContainer.svelte.d.ts +31 -0
- package/dist/components/WorkflowDesigner.svelte +3 -3
- package/dist/components/WorkflowExecutionTracker.svelte +131 -0
- package/dist/components/WorkflowExecutionTracker.svelte.d.ts +19 -0
- package/dist/components/WorkflowGraphDesigner.svelte +202 -0
- package/dist/components/WorkflowGraphDesigner.svelte.d.ts +24 -0
- package/dist/components/WorkflowNodeInspector.svelte +217 -0
- package/dist/components/WorkflowNodeInspector.svelte.d.ts +24 -0
- package/dist/components/WorkflowProcessCard.svelte +1 -1
- package/dist/components/WorkflowStepper.svelte +250 -0
- package/dist/components/WorkflowStepper.svelte.d.ts +27 -0
- package/dist/components/charts/GaugeChart.svelte +1 -1
- package/dist/components/list-i18n.d.ts +7 -0
- package/dist/components/list-i18n.js +14 -0
- package/dist/components/ui/button/button.svelte +3 -1
- package/dist/components/ui/button/button.svelte.d.ts +1 -0
- package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
- package/dist/components/useAudioAlert.d.svelte.ts +1 -0
- package/dist/components/useAudioAlert.svelte.d.ts +13 -0
- package/dist/components/useAudioAlert.svelte.js +90 -0
- package/dist/components/useDynamicLocale.d.svelte.ts +1 -0
- package/dist/components/useDynamicLocale.svelte.d.ts +10 -0
- package/dist/components/useDynamicLocale.svelte.js +40 -0
- package/dist/components/useFormulaEngine.d.svelte.ts +1 -0
- package/dist/components/useFormulaEngine.svelte.d.ts +9 -0
- package/dist/components/useFormulaEngine.svelte.js +209 -0
- package/dist/components/useHotkeys.d.svelte.ts +1 -0
- package/dist/components/useHotkeys.svelte.d.ts +44 -0
- package/dist/components/useHotkeys.svelte.js +190 -0
- package/dist/components/useMicroAppEvent.d.svelte.ts +1 -0
- package/dist/components/useMicroAppEvent.svelte.d.ts +16 -0
- package/dist/components/useMicroAppEvent.svelte.js +61 -0
- package/dist/components/usePrintExport.d.svelte.ts +1 -0
- package/dist/components/usePrintExport.svelte.d.ts +11 -0
- package/dist/components/usePrintExport.svelte.js +45 -0
- package/dist/components/useSessionTimeout.d.svelte.ts +1 -0
- package/dist/components/useSessionTimeout.svelte.d.ts +28 -0
- package/dist/components/useSessionTimeout.svelte.js +182 -0
- package/dist/components/useStorageCache.d.svelte.ts +1 -0
- package/dist/components/useStorageCache.svelte.d.ts +49 -0
- package/dist/components/useStorageCache.svelte.js +229 -0
- package/dist/components/useTableClipboard.d.svelte.ts +1 -0
- package/dist/components/useTableClipboard.svelte.d.ts +28 -0
- package/dist/components/useTableClipboard.svelte.js +116 -0
- package/dist/components.css +1 -1
- package/dist/index.d.ts +96 -11
- package/dist/index.js +146 -1
- package/package.json +4 -4
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { onDestroy } from 'svelte';
|
|
2
|
+
export function useSessionTimeout(options = {}) {
|
|
3
|
+
const { timeoutMinutes = 15, warningSeconds = 60, enabled = true, channelName = 'svadmin_session_sync', storageKey = 'svadmin_session_activity', onWarning, onTimeout, onExtend, } = options;
|
|
4
|
+
const resolvedTimeoutMinutes = typeof timeoutMinutes === 'function' ? timeoutMinutes() : timeoutMinutes;
|
|
5
|
+
const resolvedWarningSeconds = typeof warningSeconds === 'function' ? warningSeconds() : warningSeconds;
|
|
6
|
+
const timeoutMs = resolvedTimeoutMinutes * 60 * 1000;
|
|
7
|
+
const warningMs = resolvedWarningSeconds * 1000;
|
|
8
|
+
let lastActiveTimestamp = $state(Date.now());
|
|
9
|
+
let remainingMs = $state(timeoutMs);
|
|
10
|
+
let isWarning = $state(false);
|
|
11
|
+
let isTimedOut = $state(false);
|
|
12
|
+
let broadcastChannel = null;
|
|
13
|
+
let timerId = null;
|
|
14
|
+
let lastThrottle = 0;
|
|
15
|
+
const isEnabled = $derived(typeof enabled === 'function' ? enabled() : enabled);
|
|
16
|
+
const remainingSeconds = $derived(Math.max(0, Math.ceil(remainingMs / 1000)));
|
|
17
|
+
function syncActivityToStorage(timestamp) {
|
|
18
|
+
if (typeof window === 'undefined')
|
|
19
|
+
return;
|
|
20
|
+
try {
|
|
21
|
+
localStorage.setItem(storageKey, String(timestamp));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Storage unavailable
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function broadcastMessage(type, timestamp = Date.now()) {
|
|
28
|
+
if (broadcastChannel) {
|
|
29
|
+
try {
|
|
30
|
+
broadcastChannel.postMessage({ type, timestamp });
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Channel post failed
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
syncActivityToStorage(timestamp);
|
|
37
|
+
}
|
|
38
|
+
function recordUserActivity(broadcast = true) {
|
|
39
|
+
if (!isEnabled || isTimedOut)
|
|
40
|
+
return;
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
// Throttle activity recording to at most once per second
|
|
43
|
+
if (now - lastThrottle < 1000)
|
|
44
|
+
return;
|
|
45
|
+
lastThrottle = now;
|
|
46
|
+
lastActiveTimestamp = now;
|
|
47
|
+
remainingMs = timeoutMs;
|
|
48
|
+
if (isWarning) {
|
|
49
|
+
isWarning = false;
|
|
50
|
+
}
|
|
51
|
+
if (broadcast) {
|
|
52
|
+
broadcastMessage('ACTIVE', now);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function extend() {
|
|
56
|
+
isWarning = false;
|
|
57
|
+
isTimedOut = false;
|
|
58
|
+
lastActiveTimestamp = Date.now();
|
|
59
|
+
remainingMs = timeoutMs;
|
|
60
|
+
broadcastMessage('EXTEND', lastActiveTimestamp);
|
|
61
|
+
onExtend?.();
|
|
62
|
+
}
|
|
63
|
+
function lockNow() {
|
|
64
|
+
isWarning = false;
|
|
65
|
+
isTimedOut = true;
|
|
66
|
+
remainingMs = 0;
|
|
67
|
+
broadcastMessage('LOCK', Date.now());
|
|
68
|
+
onTimeout?.();
|
|
69
|
+
}
|
|
70
|
+
function tick() {
|
|
71
|
+
if (!isEnabled || isTimedOut)
|
|
72
|
+
return;
|
|
73
|
+
const now = Date.now();
|
|
74
|
+
const elapsed = now - lastActiveTimestamp;
|
|
75
|
+
const currentRemaining = Math.max(0, timeoutMs - elapsed);
|
|
76
|
+
remainingMs = currentRemaining;
|
|
77
|
+
if (currentRemaining <= 0) {
|
|
78
|
+
isWarning = false;
|
|
79
|
+
isTimedOut = true;
|
|
80
|
+
onTimeout?.();
|
|
81
|
+
}
|
|
82
|
+
else if (currentRemaining <= warningMs) {
|
|
83
|
+
if (!isWarning) {
|
|
84
|
+
isWarning = true;
|
|
85
|
+
}
|
|
86
|
+
onWarning?.(Math.ceil(currentRemaining / 1000));
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (isWarning) {
|
|
90
|
+
isWarning = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function handleStorageEvent(e) {
|
|
95
|
+
if (e.key === storageKey && e.newValue) {
|
|
96
|
+
const remoteTime = Number(e.newValue);
|
|
97
|
+
if (Number.isFinite(remoteTime) && remoteTime > lastActiveTimestamp) {
|
|
98
|
+
lastActiveTimestamp = remoteTime;
|
|
99
|
+
remainingMs = Math.max(0, timeoutMs - (Date.now() - remoteTime));
|
|
100
|
+
if (isWarning)
|
|
101
|
+
isWarning = false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const activityEvents = ['mousemove', 'mousedown', 'keydown', 'scroll', 'touchstart', 'pointerdown'];
|
|
106
|
+
function handleDOMActivity() {
|
|
107
|
+
recordUserActivity(true);
|
|
108
|
+
}
|
|
109
|
+
if (typeof window !== 'undefined') {
|
|
110
|
+
// Setup BroadcastChannel for cross-tab sync
|
|
111
|
+
if (typeof BroadcastChannel !== 'undefined') {
|
|
112
|
+
try {
|
|
113
|
+
broadcastChannel = new BroadcastChannel(channelName);
|
|
114
|
+
broadcastChannel.onmessage = (event) => {
|
|
115
|
+
const data = event.data;
|
|
116
|
+
if (data.type === 'ACTIVE' || data.type === 'EXTEND') {
|
|
117
|
+
const time = data.timestamp ?? Date.now();
|
|
118
|
+
lastActiveTimestamp = time;
|
|
119
|
+
remainingMs = timeoutMs;
|
|
120
|
+
if (isWarning)
|
|
121
|
+
isWarning = false;
|
|
122
|
+
}
|
|
123
|
+
else if (data.type === 'LOCK') {
|
|
124
|
+
isWarning = false;
|
|
125
|
+
isTimedOut = true;
|
|
126
|
+
remainingMs = 0;
|
|
127
|
+
onTimeout?.();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Fallback to storage event
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Storage event fallback
|
|
136
|
+
window.addEventListener('storage', handleStorageEvent);
|
|
137
|
+
// Attach activity listeners
|
|
138
|
+
activityEvents.forEach((ev) => {
|
|
139
|
+
window.addEventListener(ev, handleDOMActivity, { passive: true });
|
|
140
|
+
});
|
|
141
|
+
// Start timer tick every 1000ms
|
|
142
|
+
timerId = setInterval(tick, 1000);
|
|
143
|
+
}
|
|
144
|
+
function destroy() {
|
|
145
|
+
if (typeof window !== 'undefined') {
|
|
146
|
+
if (timerId)
|
|
147
|
+
clearInterval(timerId);
|
|
148
|
+
window.removeEventListener('storage', handleStorageEvent);
|
|
149
|
+
activityEvents.forEach((ev) => {
|
|
150
|
+
window.removeEventListener(ev, handleDOMActivity);
|
|
151
|
+
});
|
|
152
|
+
if (broadcastChannel) {
|
|
153
|
+
broadcastChannel.close();
|
|
154
|
+
broadcastChannel = null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
onDestroy(destroy);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Standalone utility or test execution
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
get isWarning() {
|
|
166
|
+
return isWarning;
|
|
167
|
+
},
|
|
168
|
+
get isTimedOut() {
|
|
169
|
+
return isTimedOut;
|
|
170
|
+
},
|
|
171
|
+
get remainingSeconds() {
|
|
172
|
+
return remainingSeconds;
|
|
173
|
+
},
|
|
174
|
+
get lastActiveTimestamp() {
|
|
175
|
+
return lastActiveTimestamp;
|
|
176
|
+
},
|
|
177
|
+
extend,
|
|
178
|
+
lockNow,
|
|
179
|
+
recordActivity: () => recordUserActivity(false),
|
|
180
|
+
destroy,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useStorageCache.svelte.js';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface StorageAdapter {
|
|
2
|
+
get<T = unknown>(key: string): Promise<T | null> | T | null;
|
|
3
|
+
set<T = unknown>(key: string, value: T, ttlSeconds?: number): Promise<void> | void;
|
|
4
|
+
delete(key: string): Promise<void> | void;
|
|
5
|
+
clear(): Promise<void> | void;
|
|
6
|
+
has(key: string): Promise<boolean> | boolean;
|
|
7
|
+
keys(): Promise<string[]> | string[];
|
|
8
|
+
}
|
|
9
|
+
export declare class MemoryStorageAdapter implements StorageAdapter {
|
|
10
|
+
private store;
|
|
11
|
+
get<T = unknown>(key: string): T | null;
|
|
12
|
+
set<T = unknown>(key: string, value: T, ttlSeconds?: number): void;
|
|
13
|
+
delete(key: string): void;
|
|
14
|
+
clear(): void;
|
|
15
|
+
has(key: string): boolean;
|
|
16
|
+
keys(): string[];
|
|
17
|
+
}
|
|
18
|
+
export declare class LocalStorageAdapter implements StorageAdapter {
|
|
19
|
+
private prefix;
|
|
20
|
+
constructor(namespace?: string);
|
|
21
|
+
private fullKey;
|
|
22
|
+
get<T = unknown>(key: string): T | null;
|
|
23
|
+
set<T = unknown>(key: string, value: T, ttlSeconds?: number): void;
|
|
24
|
+
delete(key: string): void;
|
|
25
|
+
clear(): void;
|
|
26
|
+
has(key: string): boolean;
|
|
27
|
+
keys(): string[];
|
|
28
|
+
}
|
|
29
|
+
export declare class RemoteKVAdapter implements StorageAdapter {
|
|
30
|
+
private endpointUrl;
|
|
31
|
+
private headers;
|
|
32
|
+
constructor(endpointUrl: string, headers?: () => Record<string, string>);
|
|
33
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
34
|
+
set<T = unknown>(key: string, value: T, ttlSeconds?: number): Promise<void>;
|
|
35
|
+
delete(key: string): Promise<void>;
|
|
36
|
+
clear(): Promise<void>;
|
|
37
|
+
has(key: string): Promise<boolean>;
|
|
38
|
+
keys(): Promise<string[]>;
|
|
39
|
+
}
|
|
40
|
+
export declare const defaultMemoryStorage: MemoryStorageAdapter;
|
|
41
|
+
export interface UseStorageCacheOptions {
|
|
42
|
+
adapter?: StorageAdapter | undefined;
|
|
43
|
+
ttlSeconds?: number | undefined;
|
|
44
|
+
}
|
|
45
|
+
export declare function useStorageCache<T = unknown>(key: string, initialValue: T, options?: UseStorageCacheOptions): {
|
|
46
|
+
readonly value: T;
|
|
47
|
+
set: (newVal: T) => void;
|
|
48
|
+
remove: () => void;
|
|
49
|
+
};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// 1. Memory Storage Adapter (SSR & Testing friendly)
|
|
2
|
+
export class MemoryStorageAdapter {
|
|
3
|
+
store = new Map();
|
|
4
|
+
get(key) {
|
|
5
|
+
const item = this.store.get(key);
|
|
6
|
+
if (!item)
|
|
7
|
+
return null;
|
|
8
|
+
if (item.expiresAt !== null && Date.now() > item.expiresAt) {
|
|
9
|
+
this.store.delete(key);
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return item.value;
|
|
13
|
+
}
|
|
14
|
+
set(key, value, ttlSeconds) {
|
|
15
|
+
const expiresAt = ttlSeconds !== undefined ? Date.now() + ttlSeconds * 1000 : null;
|
|
16
|
+
this.store.set(key, { value, expiresAt });
|
|
17
|
+
}
|
|
18
|
+
delete(key) {
|
|
19
|
+
this.store.delete(key);
|
|
20
|
+
}
|
|
21
|
+
clear() {
|
|
22
|
+
this.store.clear();
|
|
23
|
+
}
|
|
24
|
+
has(key) {
|
|
25
|
+
return this.get(key) !== null;
|
|
26
|
+
}
|
|
27
|
+
keys() {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
const validKeys = [];
|
|
30
|
+
this.store.forEach((item, k) => {
|
|
31
|
+
if (item.expiresAt === null || item.expiresAt > now) {
|
|
32
|
+
validKeys.push(k);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return validKeys;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// 2. LocalStorage Adapter (Browser persistent with TTL & namespace)
|
|
39
|
+
export class LocalStorageAdapter {
|
|
40
|
+
prefix;
|
|
41
|
+
constructor(namespace = 'svadmin') {
|
|
42
|
+
this.prefix = `${namespace}:`;
|
|
43
|
+
}
|
|
44
|
+
fullKey(key) {
|
|
45
|
+
return `${this.prefix}${key}`;
|
|
46
|
+
}
|
|
47
|
+
get(key) {
|
|
48
|
+
if (typeof window === 'undefined')
|
|
49
|
+
return null;
|
|
50
|
+
try {
|
|
51
|
+
const raw = localStorage.getItem(this.fullKey(key));
|
|
52
|
+
if (!raw)
|
|
53
|
+
return null;
|
|
54
|
+
const parsed = JSON.parse(raw);
|
|
55
|
+
if (!parsed || typeof parsed !== 'object')
|
|
56
|
+
return null;
|
|
57
|
+
const envelope = parsed;
|
|
58
|
+
if (envelope.expiresAt !== null && Date.now() > envelope.expiresAt) {
|
|
59
|
+
localStorage.removeItem(this.fullKey(key));
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return envelope.value;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
set(key, value, ttlSeconds) {
|
|
69
|
+
if (typeof window === 'undefined')
|
|
70
|
+
return;
|
|
71
|
+
try {
|
|
72
|
+
const expiresAt = ttlSeconds !== undefined ? Date.now() + ttlSeconds * 1000 : null;
|
|
73
|
+
const envelope = { value, expiresAt };
|
|
74
|
+
localStorage.setItem(this.fullKey(key), JSON.stringify(envelope));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Quota exceeded
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
delete(key) {
|
|
81
|
+
if (typeof window === 'undefined')
|
|
82
|
+
return;
|
|
83
|
+
try {
|
|
84
|
+
localStorage.removeItem(this.fullKey(key));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Ignore
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
clear() {
|
|
91
|
+
if (typeof window === 'undefined')
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
const toRemove = [];
|
|
95
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
96
|
+
const k = localStorage.key(i);
|
|
97
|
+
if (k && k.startsWith(this.prefix)) {
|
|
98
|
+
toRemove.push(k);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
toRemove.forEach((k) => localStorage.removeItem(k));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Ignore
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
has(key) {
|
|
108
|
+
return this.get(key) !== null;
|
|
109
|
+
}
|
|
110
|
+
keys() {
|
|
111
|
+
if (typeof window === 'undefined')
|
|
112
|
+
return [];
|
|
113
|
+
const result = [];
|
|
114
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
115
|
+
const k = localStorage.key(i);
|
|
116
|
+
if (k && k.startsWith(this.prefix)) {
|
|
117
|
+
result.push(k.slice(this.prefix.length));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// 3. Remote REST KV Adapter (Connect to any generic backend KV API)
|
|
124
|
+
export class RemoteKVAdapter {
|
|
125
|
+
endpointUrl;
|
|
126
|
+
headers;
|
|
127
|
+
constructor(endpointUrl, headers = () => ({})) {
|
|
128
|
+
this.endpointUrl = endpointUrl.replace(/\/+$/, '');
|
|
129
|
+
this.headers = headers;
|
|
130
|
+
}
|
|
131
|
+
async get(key) {
|
|
132
|
+
try {
|
|
133
|
+
const res = await fetch(`${this.endpointUrl}/${encodeURIComponent(key)}`, {
|
|
134
|
+
headers: this.headers(),
|
|
135
|
+
});
|
|
136
|
+
if (!res.ok)
|
|
137
|
+
return null;
|
|
138
|
+
const data = await res.json();
|
|
139
|
+
return data;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async set(key, value, ttlSeconds) {
|
|
146
|
+
try {
|
|
147
|
+
await fetch(`${this.endpointUrl}/${encodeURIComponent(key)}`, {
|
|
148
|
+
method: 'POST',
|
|
149
|
+
headers: { 'Content-Type': 'application/json', ...this.headers() },
|
|
150
|
+
body: JSON.stringify({ value, ttlSeconds }),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Network failure
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async delete(key) {
|
|
158
|
+
try {
|
|
159
|
+
await fetch(`${this.endpointUrl}/${encodeURIComponent(key)}`, {
|
|
160
|
+
method: 'DELETE',
|
|
161
|
+
headers: this.headers(),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// Network failure
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async clear() {
|
|
169
|
+
try {
|
|
170
|
+
await fetch(`${this.endpointUrl}`, {
|
|
171
|
+
method: 'DELETE',
|
|
172
|
+
headers: this.headers(),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// Network failure
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async has(key) {
|
|
180
|
+
return (await this.get(key)) !== null;
|
|
181
|
+
}
|
|
182
|
+
async keys() {
|
|
183
|
+
try {
|
|
184
|
+
const res = await fetch(`${this.endpointUrl}`, { headers: this.headers() });
|
|
185
|
+
if (!res.ok)
|
|
186
|
+
return [];
|
|
187
|
+
const data = await res.json();
|
|
188
|
+
return Array.isArray(data) ? data : [];
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export const defaultMemoryStorage = new MemoryStorageAdapter();
|
|
196
|
+
export function useStorageCache(key, initialValue, options = {}) {
|
|
197
|
+
const adapter = options.adapter ?? (typeof window !== 'undefined' ? new LocalStorageAdapter() : defaultMemoryStorage);
|
|
198
|
+
const ttlSeconds = options.ttlSeconds;
|
|
199
|
+
let stateVal = $state(initialValue);
|
|
200
|
+
// Sync initial from adapter on mount
|
|
201
|
+
if (typeof window !== 'undefined') {
|
|
202
|
+
const existing = adapter.get(key);
|
|
203
|
+
if (existing instanceof Promise) {
|
|
204
|
+
existing.then((val) => {
|
|
205
|
+
if (val !== null && val !== undefined) {
|
|
206
|
+
stateVal = val;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
else if (existing !== null && existing !== undefined) {
|
|
211
|
+
stateVal = existing;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function set(newVal) {
|
|
215
|
+
stateVal = newVal;
|
|
216
|
+
void adapter.set(key, newVal, ttlSeconds);
|
|
217
|
+
}
|
|
218
|
+
function remove() {
|
|
219
|
+
stateVal = initialValue;
|
|
220
|
+
void adapter.delete(key);
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
get value() {
|
|
224
|
+
return stateVal;
|
|
225
|
+
},
|
|
226
|
+
set,
|
|
227
|
+
remove,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTableClipboard.svelte.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface ColumnDef {
|
|
2
|
+
key: string;
|
|
3
|
+
label: string;
|
|
4
|
+
required?: boolean | undefined;
|
|
5
|
+
type?: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface ColumnMapping {
|
|
8
|
+
clipboardHeader: string;
|
|
9
|
+
clipboardIndex: number;
|
|
10
|
+
matchedColumnKey?: string | undefined;
|
|
11
|
+
matchedColumnLabel?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface ParsedClipboardTable {
|
|
14
|
+
headers: string[];
|
|
15
|
+
rows: Record<string, string>[];
|
|
16
|
+
rawGrid: string[][];
|
|
17
|
+
rowCount: number;
|
|
18
|
+
colCount: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function parseDelimitedText(text: string): string[][];
|
|
21
|
+
export declare function parseClipboardText(text: string, knownColumns?: ColumnDef[]): ParsedClipboardTable;
|
|
22
|
+
export declare function matchColumnsToDefinitions(headers: string[], columns: ColumnDef[]): ColumnMapping[];
|
|
23
|
+
export declare function copyRowsToClipboard(rows: Record<string, unknown>[], columns: ColumnDef[]): Promise<boolean>;
|
|
24
|
+
export declare function useTableClipboard(): {
|
|
25
|
+
parse: typeof parseClipboardText;
|
|
26
|
+
matchColumns: typeof matchColumnsToDefinitions;
|
|
27
|
+
copyRows: typeof copyRowsToClipboard;
|
|
28
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export function parseDelimitedText(text) {
|
|
2
|
+
const normalized = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
3
|
+
const lines = normalized.split('\n').filter((line) => line.trim().length > 0);
|
|
4
|
+
if (lines.length === 0)
|
|
5
|
+
return [];
|
|
6
|
+
// Detect delimiter: TSV vs CSV
|
|
7
|
+
const firstLine = lines[0] ?? '';
|
|
8
|
+
const tabCount = (firstLine.match(/\t/g) || []).length;
|
|
9
|
+
const commaCount = (firstLine.match(/,/g) || []).length;
|
|
10
|
+
const delimiter = tabCount >= commaCount && tabCount > 0 ? '\t' : ',';
|
|
11
|
+
return lines.map((line) => {
|
|
12
|
+
const result = [];
|
|
13
|
+
let cur = '';
|
|
14
|
+
let inQuotes = false;
|
|
15
|
+
for (let i = 0; i < line.length; i++) {
|
|
16
|
+
const char = line[i];
|
|
17
|
+
if (char === '"') {
|
|
18
|
+
if (inQuotes && line[i + 1] === '"') {
|
|
19
|
+
cur += '"';
|
|
20
|
+
i++;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
inQuotes = !inQuotes;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (char === delimiter && !inQuotes) {
|
|
27
|
+
result.push(cur.trim());
|
|
28
|
+
cur = '';
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
cur += char;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
result.push(cur.trim());
|
|
35
|
+
return result;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function parseClipboardText(text, knownColumns = []) {
|
|
39
|
+
const grid = parseDelimitedText(text);
|
|
40
|
+
if (grid.length === 0) {
|
|
41
|
+
return { headers: [], rows: [], rawGrid: [], rowCount: 0, colCount: 0 };
|
|
42
|
+
}
|
|
43
|
+
const firstRow = grid[0] ?? [];
|
|
44
|
+
const knownKeys = new Set(knownColumns.map((c) => c.key.toLowerCase()));
|
|
45
|
+
const knownLabels = new Set(knownColumns.map((c) => c.label.toLowerCase()));
|
|
46
|
+
// Heuristic: Check if first row is header row
|
|
47
|
+
const hasHeaders = firstRow.some((cell) => knownKeys.has(cell.toLowerCase()) || knownLabels.has(cell.toLowerCase()));
|
|
48
|
+
let headers;
|
|
49
|
+
let dataGrid;
|
|
50
|
+
if (hasHeaders && grid.length > 1) {
|
|
51
|
+
headers = firstRow;
|
|
52
|
+
dataGrid = grid.slice(1);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Treat first row as data, assign generic or matched headers
|
|
56
|
+
headers = firstRow.map((_, idx) => knownColumns[idx]?.label ?? `Column ${idx + 1}`);
|
|
57
|
+
dataGrid = grid;
|
|
58
|
+
}
|
|
59
|
+
const rows = dataGrid.map((row) => {
|
|
60
|
+
const record = {};
|
|
61
|
+
headers.forEach((header, idx) => {
|
|
62
|
+
record[header] = row[idx] ?? '';
|
|
63
|
+
});
|
|
64
|
+
return record;
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
headers,
|
|
68
|
+
rows,
|
|
69
|
+
rawGrid: dataGrid,
|
|
70
|
+
rowCount: dataGrid.length,
|
|
71
|
+
colCount: headers.length,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function matchColumnsToDefinitions(headers, columns) {
|
|
75
|
+
return headers.map((header, idx) => {
|
|
76
|
+
const clean = header.trim().toLowerCase();
|
|
77
|
+
const matched = columns.find((c) => c.key.toLowerCase() === clean || c.label.toLowerCase() === clean);
|
|
78
|
+
return {
|
|
79
|
+
clipboardHeader: header,
|
|
80
|
+
clipboardIndex: idx,
|
|
81
|
+
matchedColumnKey: matched?.key,
|
|
82
|
+
matchedColumnLabel: matched?.label,
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export async function copyRowsToClipboard(rows, columns) {
|
|
87
|
+
if (typeof navigator === 'undefined' || !navigator.clipboard) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const headerLine = columns.map((c) => c.label).join('\t');
|
|
91
|
+
const dataLines = rows.map((row) => columns
|
|
92
|
+
.map((col) => {
|
|
93
|
+
const val = row[col.key];
|
|
94
|
+
const str = val === null || val === undefined ? '' : String(val);
|
|
95
|
+
if (str.includes('\t') || str.includes('\n') || str.includes('"')) {
|
|
96
|
+
return `"${str.replace(/"/g, '""')}"`;
|
|
97
|
+
}
|
|
98
|
+
return str;
|
|
99
|
+
})
|
|
100
|
+
.join('\t'));
|
|
101
|
+
const tsv = [headerLine, ...dataLines].join('\n');
|
|
102
|
+
try {
|
|
103
|
+
await navigator.clipboard.writeText(tsv);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export function useTableClipboard() {
|
|
111
|
+
return {
|
|
112
|
+
parse: parseClipboardText,
|
|
113
|
+
matchColumns: matchColumnsToDefinitions,
|
|
114
|
+
copyRows: copyRowsToClipboard,
|
|
115
|
+
};
|
|
116
|
+
}
|
package/dist/components.css
CHANGED