@devcabs/folio-engine 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/App.d.ts +7 -0
  2. package/dist/components/canvas/CanvasAddBar.d.ts +28 -0
  3. package/dist/components/canvas/CanvasAddModal.d.ts +38 -0
  4. package/dist/components/canvas/CanvasChart.d.ts +23 -0
  5. package/dist/components/canvas/CanvasDeleteConfirmModal.d.ts +21 -0
  6. package/dist/components/canvas/CanvasGallery.d.ts +20 -0
  7. package/dist/components/canvas/CanvasItemControls.d.ts +33 -0
  8. package/dist/components/canvas/CanvasPhoto.d.ts +28 -0
  9. package/dist/components/canvas/CanvasSection.d.ts +27 -0
  10. package/dist/components/canvas/CanvasSubsection.d.ts +23 -0
  11. package/dist/components/canvas/CanvasText.d.ts +23 -0
  12. package/dist/components/canvas/DocumentCanvas.d.ts +20 -0
  13. package/dist/components/canvas/HeroPhoto.d.ts +17 -0
  14. package/dist/components/canvas/NodeCanvas.d.ts +2 -0
  15. package/dist/components/canvas/index.d.ts +17 -0
  16. package/dist/components/chart/BarChart.d.ts +23 -0
  17. package/dist/components/chart/ChartCard.d.ts +33 -0
  18. package/dist/components/chart/ChartConfigDrawer.d.ts +16 -0
  19. package/dist/components/chart/ChartGhostWireframe.d.ts +16 -0
  20. package/dist/components/chart/ChartLegend.d.ts +14 -0
  21. package/dist/components/chart/ChartRouter.d.ts +8 -0
  22. package/dist/components/chart/ChartSortingControls.d.ts +15 -0
  23. package/dist/components/chart/ChartTableModal.d.ts +26 -0
  24. package/dist/components/chart/ChartTooltip.d.ts +12 -0
  25. package/dist/components/chart/DataPendingCard.d.ts +28 -0
  26. package/dist/components/chart/DonutChart.d.ts +16 -0
  27. package/dist/components/chart/HistogramChart.d.ts +23 -0
  28. package/dist/components/chart/LineChart.d.ts +22 -0
  29. package/dist/components/chart/RangePreviewMatrix.d.ts +19 -0
  30. package/dist/components/chart/ScatterPlot.d.ts +21 -0
  31. package/dist/components/chart/drawer/controls/BarVisualControls.d.ts +9 -0
  32. package/dist/components/chart/drawer/controls/ChartTitlesSection.d.ts +15 -0
  33. package/dist/components/chart/drawer/controls/DonutVisualControls.d.ts +7 -0
  34. package/dist/components/chart/drawer/controls/HistogramVisualControls.d.ts +13 -0
  35. package/dist/components/chart/drawer/controls/LineVisualControls.d.ts +14 -0
  36. package/dist/components/chart/drawer/controls/ScatterDataControls.d.ts +17 -0
  37. package/dist/components/chart/drawer/controls/ScatterVisualControls.d.ts +23 -0
  38. package/dist/components/chart/drawer/controls/SortingAndOrderControls.d.ts +18 -0
  39. package/dist/components/chart/drawer/controls/StandardDataControls.d.ts +31 -0
  40. package/dist/components/chart/drawer/hooks/useChartConfigForm.d.ts +156 -0
  41. package/dist/components/chart/drawer/hooks/useLiveMatrixSync.d.ts +21 -0
  42. package/dist/components/chart/drawer/hooks/useSheetVerification.d.ts +26 -0
  43. package/dist/components/chart/drawer/index.d.ts +17 -0
  44. package/dist/components/chart/drawer/panels/Step1Source.d.ts +18 -0
  45. package/dist/components/chart/drawer/panels/Step1SourceRange.d.ts +32 -0
  46. package/dist/components/chart/drawer/panels/Step2DataRange.d.ts +15 -0
  47. package/dist/components/chart/drawer/panels/Step3ChartSetup.d.ts +17 -0
  48. package/dist/components/chart/drawer/panels/Step4Review.d.ts +11 -0
  49. package/dist/components/chart/index.d.ts +22 -0
  50. package/dist/components/dev/DevActionAffordance.d.ts +4 -0
  51. package/dist/components/dev/DevExitConfirmModal.d.ts +14 -0
  52. package/dist/components/dev/DevLockBlockedModal.d.ts +3 -0
  53. package/dist/components/dev/DevModeBadge.d.ts +3 -0
  54. package/dist/components/dev/DevPinModal.d.ts +3 -0
  55. package/dist/components/dev/DevPublishModal.d.ts +9 -0
  56. package/dist/components/dev/UniversalEditModal.d.ts +40 -0
  57. package/dist/components/dev/index.d.ts +8 -0
  58. package/dist/components/feedback/EmptyState.d.ts +13 -0
  59. package/dist/components/feedback/PageNotFound.d.ts +15 -0
  60. package/dist/components/feedback/Toast.d.ts +25 -0
  61. package/dist/components/feedback/index.d.ts +2 -0
  62. package/dist/components/history/HistoryHubModal.d.ts +44 -0
  63. package/dist/components/history/index.d.ts +1 -0
  64. package/dist/components/layout/AppFooter.d.ts +10 -0
  65. package/dist/components/layout/AppHeader.d.ts +21 -0
  66. package/dist/components/layout/EditorialSection.d.ts +27 -0
  67. package/dist/components/layout/EditorialSidebar.d.ts +34 -0
  68. package/dist/components/layout/HeroSection.d.ts +2 -0
  69. package/dist/components/layout/HeroWelcome.d.ts +11 -0
  70. package/dist/components/layout/SearchField.d.ts +9 -0
  71. package/dist/components/layout/StatusPill.d.ts +2 -0
  72. package/dist/components/layout/index.d.ts +8 -0
  73. package/dist/components/roadmap/RoadmapNode.d.ts +30 -0
  74. package/dist/components/roadmap/RoadmapSection.d.ts +27 -0
  75. package/dist/components/roadmap/RoadmapTrack.d.ts +25 -0
  76. package/dist/components/roadmap/serpentine-generator.d.ts +60 -0
  77. package/dist/components/roadmap/use-roadmap-scroll.d.ts +19 -0
  78. package/dist/components/source/EditPhotoModal.d.ts +22 -0
  79. package/dist/components/source/LightboxPhotoStrip.d.ts +23 -0
  80. package/dist/components/source/LinkFolderModal.d.ts +24 -0
  81. package/dist/components/source/SourceCard.d.ts +31 -0
  82. package/dist/components/source/SourceFolderAttachment.d.ts +25 -0
  83. package/dist/components/source/SourceGallery.d.ts +26 -0
  84. package/dist/components/source/SourceImage.d.ts +26 -0
  85. package/dist/components/source/SourceLightbox.d.ts +28 -0
  86. package/dist/components/source/index.d.ts +9 -0
  87. package/dist/components/ui/AccordionSection.d.ts +21 -0
  88. package/dist/components/ui/Breadcrumb.d.ts +29 -0
  89. package/dist/components/ui/Button.d.ts +31 -0
  90. package/dist/components/ui/ColumnSelect.d.ts +17 -0
  91. package/dist/components/ui/ColumnTypeBadge.d.ts +6 -0
  92. package/dist/components/ui/DevHelpTooltip.d.ts +11 -0
  93. package/dist/components/ui/DraggableRows.d.ts +21 -0
  94. package/dist/components/ui/Drawer.d.ts +50 -0
  95. package/dist/components/ui/DrawerTier.d.ts +8 -0
  96. package/dist/components/ui/EditableText.d.ts +48 -0
  97. package/dist/components/ui/FAB.d.ts +24 -0
  98. package/dist/components/ui/Modal.d.ts +24 -0
  99. package/dist/components/ui/PageTitle.d.ts +33 -0
  100. package/dist/components/ui/ParametricShape.d.ts +57 -0
  101. package/dist/components/ui/RevolvingButton.d.ts +5 -0
  102. package/dist/components/ui/SectionTitle.d.ts +42 -0
  103. package/dist/components/ui/SeriesSelectToolbar.d.ts +10 -0
  104. package/dist/components/ui/StatusPill.d.ts +21 -0
  105. package/dist/components/ui/TieredSlider.d.ts +19 -0
  106. package/dist/components/ui/Toast.d.ts +1 -0
  107. package/dist/components/ui/ValueLabelToggle.d.ts +10 -0
  108. package/dist/components/ui/index.d.ts +21 -0
  109. package/dist/config/engine.config.d.ts +31 -0
  110. package/dist/context/DeveloperModeContext.d.ts +11 -0
  111. package/dist/context/UndoRedoContext.d.ts +20 -0
  112. package/dist/folio.js +24996 -0
  113. package/dist/folio.umd.cjs +42 -0
  114. package/dist/hooks/use-auto-toc.d.ts +31 -0
  115. package/dist/hooks/use-discrete-step-navigation.d.ts +26 -0
  116. package/dist/hooks/use-dynamic-section-numbers.d.ts +30 -0
  117. package/dist/hooks/use-hash-route.d.ts +36 -0
  118. package/dist/hooks/use-scroll.d.ts +22 -0
  119. package/dist/hooks/use-scrollspy.d.ts +19 -0
  120. package/dist/hooks/useChartTooltip.d.ts +25 -0
  121. package/dist/hooks/useContent.d.ts +36 -0
  122. package/dist/hooks/useDeveloperMode.d.ts +1 -0
  123. package/dist/hooks/useDocumentCanvas.d.ts +53 -0
  124. package/dist/hooks/useDrivePhotoSync.d.ts +15 -0
  125. package/dist/hooks/useImageLoader.d.ts +12 -0
  126. package/dist/hooks/useLightboxHistory.d.ts +14 -0
  127. package/dist/hooks/useNodeCanvas.d.ts +2 -0
  128. package/dist/hooks/useSheetChartData.d.ts +30 -0
  129. package/dist/hooks/useSourcePoint.d.ts +35 -0
  130. package/dist/hooks/useSwipeGesture.d.ts +30 -0
  131. package/dist/hooks/useUndoRedo.d.ts +9 -0
  132. package/dist/hooks/useUnsavedChangesPrompt.d.ts +18 -0
  133. package/dist/index.d.ts +52 -0
  134. package/dist/main.d.ts +1 -0
  135. package/dist/services/canvasLayoutService.d.ts +158 -0
  136. package/dist/services/chartSourceService.d.ts +128 -0
  137. package/dist/services/devLockService.d.ts +76 -0
  138. package/dist/services/draftService.d.ts +129 -0
  139. package/dist/services/drivePhotoSyncService.d.ts +60 -0
  140. package/dist/services/driveVerificationService.d.ts +41 -0
  141. package/dist/services/edgePreBakeService.d.ts +81 -0
  142. package/dist/services/historyService.d.ts +215 -0
  143. package/dist/services/historyStorage.d.ts +17 -0
  144. package/dist/services/mediaService.d.ts +25 -0
  145. package/dist/services/sheetsDataService.d.ts +59 -0
  146. package/dist/services/sheetsVerificationService.d.ts +87 -0
  147. package/dist/services/sourceService.d.ts +43 -0
  148. package/dist/services/undoRedoService.d.ts +63 -0
  149. package/dist/services/unsavedChangesService.d.ts +32 -0
  150. package/dist/style.css +1 -0
  151. package/dist/types/canvas.d.ts +115 -0
  152. package/dist/types/chart.d.ts +117 -0
  153. package/dist/types/developer.d.ts +144 -0
  154. package/dist/types/draft.d.ts +21 -0
  155. package/dist/types/edge.d.ts +232 -0
  156. package/dist/types/history.d.ts +81 -0
  157. package/dist/types/media.d.ts +16 -0
  158. package/dist/types/navigation.d.ts +19 -0
  159. package/dist/types/node.d.ts +51 -0
  160. package/dist/types/source.d.ts +88 -0
  161. package/dist/utils/canvasDefaults.d.ts +43 -0
  162. package/dist/utils/chartColors.d.ts +48 -0
  163. package/dist/utils/chartDimensions.d.ts +50 -0
  164. package/dist/utils/chartMath.d.ts +142 -0
  165. package/dist/utils/chartSanitizer.d.ts +84 -0
  166. package/dist/utils/contentDb.d.ts +86 -0
  167. package/dist/utils/devSecurity.d.ts +84 -0
  168. package/dist/utils/mediaUrl.d.ts +32 -0
  169. package/dist/utils/modalActions.d.ts +32 -0
  170. package/dist/utils/node-sections.d.ts +15 -0
  171. package/dist/utils/page-sections.d.ts +1 -0
  172. package/dist/utils/runtime-env.d.ts +21 -0
  173. package/dist/utils/scrollLock.d.ts +10 -0
  174. package/dist/utils/smooth-scroll.d.ts +24 -0
  175. package/dist/utils/source.d.ts +25 -0
  176. package/dist/utils/storage.d.ts +13 -0
  177. package/dist/utils/supabase-config.d.ts +29 -0
  178. package/dist/utils/supabase-write-guard.d.ts +15 -0
  179. package/package.json +56 -4
  180. package/README.md +0 -3
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Folio Engine - Unified History Hub Service
3
+ * Location: src/services/historyService.ts
4
+ * Specification: docs/tasks/task9_3_unified_school_history_hub.md
5
+ * Aligned with: docs/00_WORKFLOW.md, docs/03_ARCHITECTURE.md, docs/07_CODING_STANDARDS.md
6
+ *
7
+ * Implements:
8
+ * 1. Full Snapshot Bundling (all 5 nodes + Content DB overrides).
9
+ * 2. Dual-Tier Timeline (Named Milestones, Rolling Auto-Saves, Safety Backups).
10
+ * 3. 20-Checkpoint Auto-Save Rotation with Inactivity Debouncing.
11
+ * 4. Safe Pre-Restore Safety Checkpoint Guarantee.
12
+ * 5. Full JSON Backup Export & Verified Import.
13
+ */
14
+ import type { UnifiedPortalSnapshot, HistoryManifest, SnapshotType, PublishedSnapshot } from '../types/history';
15
+ import type { NodeCanvasDocument } from '../types/canvas';
16
+ import { NODE_IDS, type NodeId } from './canvasLayoutService';
17
+ import { getSupabaseConfig, isTableAvailable, markTableMissing, markTableAvailable } from '../utils/supabase-config';
18
+ export { NODE_IDS, type NodeId };
19
+ export declare function getActiveNodeIds(): string[];
20
+ export { getSupabaseConfig, isTableAvailable, markTableMissing, markTableAvailable };
21
+ import { type DraftStalenessCheck } from './draftService';
22
+ export interface EngineSyncBroadcastMessage {
23
+ type: 'MASID_PUBLISH_BROADCAST';
24
+ snapshotId: string;
25
+ timestamp: string;
26
+ canvases: Record<string, NodeCanvasDocument>;
27
+ contentOverrides: Record<string, string>;
28
+ activePublishedId: string;
29
+ }
30
+ export interface HydrationState {
31
+ isHydrating: boolean;
32
+ hasConfirmedData: boolean;
33
+ source: 'cache' | 'cloud' | 'baseline';
34
+ activePublishedId: string | null;
35
+ }
36
+ export declare const getBroadcastChannelName: (ns?: string) => string;
37
+ export declare const BROADCAST_CHANNEL_NAME: string;
38
+ export declare const getHistoryManifestKey: (ns?: string) => string;
39
+ export declare const STORAGE_KEY_HISTORY_MANIFEST: string;
40
+ export declare const getLiveActivePublishedIdKey: (ns?: string) => string;
41
+ export declare const STORAGE_KEY_LIVE_ACTIVE_PUBLISHED_ID: string;
42
+ export declare const LEGACY_STORAGE_KEY_ACTIVE_PUBLISHED_ID: string;
43
+ export declare const STORAGE_KEY_ACTIVE_PUBLISHED_ID: string;
44
+ export declare const EVENT_HISTORY_CHANGE = "engine-history-change";
45
+ export declare const HISTORY_SCHEMA_VERSION = 1;
46
+ export declare const MAX_AUTOSAVES = 20;
47
+ export declare const AUTOSAVE_DEBOUNCE_MS = 60000;
48
+ /**
49
+ * Computes scannable metrics summary across all 5 node canvas trees and Content DB.
50
+ */
51
+ export declare function computeMetricsSummary(canvases: Record<string, NodeCanvasDocument>, contentOverrides: Record<string, string>): UnifiedPortalSnapshot['summary'];
52
+ /**
53
+ * Retrieves the currently active published snapshot ID.
54
+ * Reads solely from the canonical key, running a one-time migration from legacy pointers if absent.
55
+ */
56
+ export declare function getActivePublishedId(): string;
57
+ /**
58
+ * Sets the active published snapshot ID to the canonical key exclusively.
59
+ */
60
+ export declare function setActivePublishedId(id: string): void;
61
+ /**
62
+ * Generates the canonical system factory baseline snapshot.
63
+ * Serves as the indestructible anchor for the host application.
64
+ */
65
+ export declare function getDefaultSystemBaselineSnapshot(isActive?: boolean): PublishedSnapshot;
66
+ /**
67
+ * Lightweight snapshot metadata for localStorage manifest (< 50KB).
68
+ * Excludes heavy canvas document ASTs and Content DB dictionaries.
69
+ */
70
+ export interface HistorySnapshotMetadata {
71
+ id: string;
72
+ title: string;
73
+ label?: string;
74
+ createdAt: string;
75
+ type: SnapshotType | string;
76
+ notes?: string;
77
+ authorSessionId?: string;
78
+ author?: string;
79
+ summary?: UnifiedPortalSnapshot['summary'];
80
+ metricsSummary?: unknown;
81
+ }
82
+ export interface LightweightHistoryManifest {
83
+ version: number;
84
+ lastUpdated: string;
85
+ updatedAt?: string;
86
+ snapshots: HistorySnapshotMetadata[];
87
+ }
88
+ /**
89
+ * Hydrates history manifest from persistent IndexedDB store (eliminates localStorage quota wipes).
90
+ */
91
+ export declare function hydrateHistoryFromIndexedDB(): Promise<HistoryManifest>;
92
+ /**
93
+ * Retrieves the whole-History manifest from storage.
94
+ */
95
+ export declare function getHistoryManifest(): HistoryManifest;
96
+ /**
97
+ * Persists history manifest to storage and notifies subscribers.
98
+ * Offloads heavy canvas and Content DB payloads exclusively to IndexedDB.
99
+ * localStorage receives only lightweight metadata (< 50KB for 20+ snapshots).
100
+ */
101
+ export declare function saveHistoryManifest(manifest: HistoryManifest): void;
102
+ /**
103
+ * Subscribes to real-time changes in the history manifest.
104
+ */
105
+ export declare function subscribeToHistoryChange(callback: (manifest: HistoryManifest) => void): () => void;
106
+ /**
107
+ * Aggregates a complete full snapshot bundle across all 5 nodes and Content DB.
108
+ */
109
+ export declare function captureCurrentSnapshot(title: string, notes?: string, type?: SnapshotType, sessionId?: string): UnifiedPortalSnapshot;
110
+ /**
111
+ * Creates and persists a named full milestone.
112
+ */
113
+ export declare function saveMilestone(title: string, notes?: string, sessionId?: string): UnifiedPortalSnapshot;
114
+ /**
115
+ * Prunes auto-saves in a list to keep at most MAX_AUTOSAVES (20), preserving all milestones & safety backups.
116
+ */
117
+ export declare function pruneAutoSaves(snapshots: UnifiedPortalSnapshot[]): UnifiedPortalSnapshot[];
118
+ /**
119
+ * Triggers an automated snapshot checkpoint.
120
+ * Debounced to at most once per AUTOSAVE_DEBOUNCE_MS unless forced.
121
+ */
122
+ export declare function triggerAutoSave(sessionId?: string, force?: boolean): UnifiedPortalSnapshot | null;
123
+ /**
124
+ * Restores a historical snapshot across all 5 nodes and Content DB.
125
+ * Automatically takes an immediate safety_backup before applying changes.
126
+ */
127
+ export declare function restoreUnifiedSnapshot(snapshotId: string): Promise<{
128
+ success: boolean;
129
+ safetySnapshotId?: string;
130
+ error?: string;
131
+ }>;
132
+ /**
133
+ * Removes a specific snapshot from the manifest.
134
+ */
135
+ export declare function deleteSnapshot(snapshotId: string): boolean;
136
+ /**
137
+ * Clears all history checkpoints from the manifest.
138
+ */
139
+ export declare function clearAllHistory(): void;
140
+ export interface HistoryBackupExport {
141
+ engineBackupVersion: number;
142
+ exportedAt: string;
143
+ tenant: string;
144
+ manifest: HistoryManifest;
145
+ activeState: {
146
+ canvases: Record<string, NodeCanvasDocument>;
147
+ contentOverrides: Record<string, string>;
148
+ };
149
+ }
150
+ /**
151
+ * Generates a full formatted JSON backup string for download.
152
+ */
153
+ export declare function exportHistoryBackupJson(): string;
154
+ /**
155
+ * Validates and imports a JSON history backup, merging valid snapshots.
156
+ */
157
+ export declare function importHistoryBackupJson(jsonString: string): {
158
+ success: boolean;
159
+ importedCount: number;
160
+ error?: string;
161
+ };
162
+ export { initDraftSession, discardDraftSession, } from './draftService';
163
+ /**
164
+ * Restores a historical snapshot into Developer Mode's draft storage for visual preview before publishing.
165
+ * Does NOT mutate canonical live storage.
166
+ */
167
+ export declare function restoreSnapshotToDraft(snapshot: PublishedSnapshot | UnifiedPortalSnapshot): boolean;
168
+ export declare function getLocalFallbackSnapshots(): PublishedSnapshot[];
169
+ /**
170
+ * Fetches the complete timeline of published snapshots from Supabase cloud (with offline fallback).
171
+ */
172
+ export declare function fetchPublishedHistoryFromCloud(): Promise<PublishedSnapshot[]>;
173
+ /**
174
+ * Fetches the current active published version from Supabase cloud.
175
+ */
176
+ export declare function fetchActivePublishedVersionFromCloud(): Promise<PublishedSnapshot | null>;
177
+ export interface CanPublishDraftResult {
178
+ canPublish: boolean;
179
+ reason?: 'NOT_DIRTY' | 'DRAFT_STALE';
180
+ staleness?: DraftStalenessCheck;
181
+ }
182
+ /**
183
+ * Checks whether the current draft can be safely published.
184
+ * Blocks publication if another coordinator has published since draft creation.
185
+ */
186
+ export declare function canPublishDraft(forcePublish?: boolean): CanPublishDraftResult;
187
+ /**
188
+ * Commits the current draft state, sets it as the active live version, and syncs to Supabase.
189
+ */
190
+ export declare function publishNewSnapshot(description: string, title?: string, sessionId?: string, options?: {
191
+ forcePublish?: boolean;
192
+ } | boolean): Promise<{
193
+ success: boolean;
194
+ snapshot: PublishedSnapshot;
195
+ cloudSynced: boolean;
196
+ error?: string;
197
+ }>;
198
+ export declare function getSyncBroadcastChannel(): BroadcastChannel | null;
199
+ export declare function closeSyncBroadcastChannel(): void;
200
+ export declare function broadcastLiveSync(message: EngineSyncBroadcastMessage): void;
201
+ export declare function handleIncomingSyncBroadcast(message: EngineSyncBroadcastMessage): void;
202
+ /**
203
+ * @deprecated Task 11.2.E: Artificial loading gates eliminated.
204
+ * Baseline documents render immediately on frame 1 with 0 skeleton pop-in.
205
+ */
206
+ export declare function isInitialHydrationPending(): boolean;
207
+ export declare function isCloudHydrating(): boolean;
208
+ export declare function subscribeToHydration(callback: (isHydrating: boolean) => void): () => void;
209
+ export declare function getHydrationState(): HydrationState;
210
+ export declare function resetHydrationStateForTesting(): void;
211
+ /**
212
+ * Hydrates local canonical storage from the cloud's active published version on startup.
213
+ * Memoizes in-flight promise to prevent duplicate concurrent network fetches.
214
+ */
215
+ export declare function hydrateActiveVersionFromCloud(): Promise<boolean>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Folio Engine - Persistent IndexedDB Storage for History Snapshots
3
+ * Location: src/services/historyStorage.ts
4
+ * Specification: docs/tasks/task9_7_draft_and_publish_history_system.md
5
+ *
6
+ * Provides high-capacity, persistent client-side storage for full
7
+ * snapshot bundles to eliminate the 5MB localStorage QuotaExceededError.
8
+ */
9
+ export declare const getHistoryDbName: (ns?: string) => string;
10
+ /**
11
+ * Persists an item to IndexedDB with zero quota risk.
12
+ */
13
+ export declare function saveToIndexedDB(key: string, value: unknown): Promise<boolean>;
14
+ /**
15
+ * Retrieves an item from IndexedDB.
16
+ */
17
+ export declare function loadFromIndexedDB<T>(key: string): Promise<T | null>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Folio Engine - Canonical Cloud Media Upload Service
3
+ * Location: src/services/mediaService.ts
4
+ * Specification: docs/tasks/task11_2g_db_draft_and_blob_storage_pipeline.md
5
+ * Aligned with: docs/00_WORKFLOW.md, docs/03_ARCHITECTURE.md, docs/07_CODING_STANDARDS.md
6
+ */
7
+ import type { MediaFolder, ImageDownscaleOptions } from '../types/media';
8
+ export declare const MEDIA_BUCKET_ID = "engine-media";
9
+ export declare const DEFAULT_MAX_DIMENSION = 1600;
10
+ export declare const DEFAULT_IMAGE_QUALITY = 0.82;
11
+ /**
12
+ * Sanitizes a filename, preserving lowercase extension and alphanumeric characters.
13
+ */
14
+ export declare function sanitizeFilename(filename: string): string;
15
+ /**
16
+ * Client-side downscaling using an offscreen HTML Canvas.
17
+ * Scales large camera photos (e.g. 12 MB, 4000x3000) down to max 1600px,
18
+ * producing crisp, responsive ~120 KB WebP or JPEG binaries.
19
+ */
20
+ export declare function downscaleImage(file: File | Blob, options?: ImageDownscaleOptions): Promise<Blob>;
21
+ /**
22
+ * Uploads a binary media asset directly to the Supabase engine-media bucket.
23
+ * Returns the permanent public CDN URL.
24
+ */
25
+ export declare function uploadMediaAsset(file: File | Blob, folder?: MediaFolder, originalFilename?: string): Promise<string>;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Google Sheets Tabular Ingestion & Parsing Service
3
+ * Document Reference: docs/tasks/task7_1_contracts_d3_math_sanitizer.md
4
+ *
5
+ * Slices arbitrary bounding boxes (A5:D12), preserves number purity (nulls for blanks/errors),
6
+ * automatically filters summary rows (Total/Average), detects multi-series groups,
7
+ * and pre-bakes sanitized CSV receipts.
8
+ */
9
+ import type { ChartDataset, ChartSeries, ChartType, ChartVisualConfig } from '../types/chart';
10
+ import type { NodeCode } from '../types/node';
11
+ import { BoundingBoxRange } from '../utils/chartSanitizer';
12
+ export interface ParseTabularParams {
13
+ chartId: string;
14
+ title: string;
15
+ subtitle?: string;
16
+ unit?: string;
17
+ asOfDate?: string;
18
+ chartType?: ChartType;
19
+ nodeId?: NodeCode;
20
+ visualConfig?: ChartVisualConfig;
21
+ rawMatrix?: string[][];
22
+ csvText?: string;
23
+ }
24
+ /**
25
+ * Parses raw CSV string into 2D grid preserving RFC 4180 quotes, commas, and line breaks.
26
+ */
27
+ export declare function parseCsvToMatrix(csvText: string): string[][];
28
+ /**
29
+ * Crops a 2D matrix according to bounding box range coordinates
30
+ */
31
+ export declare function cropMatrixToRange(matrix: string[][], range: BoundingBoxRange): string[][];
32
+ /**
33
+ * Transposes a 2D matrix (swaps rows and columns).
34
+ * Normalizes jagged rows to the maximum column width.
35
+ */
36
+ export declare function transposeMatrix<T = string | number | null>(matrix: T[][]): T[][];
37
+ /**
38
+ * Sorts tabular categories and series data consistently according to the specified sort rule.
39
+ */
40
+ export declare function sortTabularData(categories: string[], series: ChartSeries[], sortBy?: 'none' | 'asc' | 'desc' | 'category-asc' | 'category-desc'): {
41
+ categories: string[];
42
+ series: ChartSeries[];
43
+ };
44
+ /**
45
+ * Main ingestion function: converts raw matrix or CSV string into a validated ChartDataset.
46
+ */
47
+ export declare function parseTabularDataset(params: ParseTabularParams): ChartDataset;
48
+ export interface FetchLiveSheetMatrixParams {
49
+ sheetUrl: string;
50
+ tabName?: string;
51
+ sheetGid?: string;
52
+ range?: string;
53
+ timeoutMs?: number;
54
+ }
55
+ /**
56
+ * Fetches real-time tabular data from a public Google Sheet via GViz CSV endpoint.
57
+ * Returns a 2D string matrix of cell contents without mocking or synthetic placeholders.
58
+ */
59
+ export declare function fetchLiveSheetMatrix(params: FetchLiveSheetMatrixParams): Promise<string[][]>;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Google Sheets Access Verification & API Discovery Service
3
+ * Folio Engine
4
+ * Document Reference: docs/tasks/task7_2_access_verification_sheets_api.md
5
+ *
6
+ * Implements:
7
+ * 1. Pre-flight link access verification: Validates read access against Google endpoints
8
+ * and produces tailored sharing guidance.
9
+ * 2. Automatic Sheet Tab Discovery: Uses Google Sheets API v4 metadata to auto-discover
10
+ * tab names and sheet IDs (GIDs).
11
+ * 3. Fallbacks: Graceful degradation for unconfigured API keys, rate limits, or network errors.
12
+ */
13
+ export interface SheetMetadataTab {
14
+ title: string;
15
+ sheetId: number;
16
+ index: number;
17
+ }
18
+ export interface SheetAccessCheckResult {
19
+ accessible: boolean;
20
+ spreadsheetId: string | null;
21
+ sheetGid?: string | null;
22
+ title?: string;
23
+ error?: string;
24
+ tabs?: SheetMetadataTab[];
25
+ modifiedTime?: string;
26
+ }
27
+ /**
28
+ * Extracts Google Spreadsheet ID from diverse URL patterns:
29
+ * - https://docs.google.com/spreadsheets/d/{id}/edit#gid=0
30
+ * - https://docs.google.com/spreadsheets/d/{id}/export?format=csv
31
+ * - https://docs.google.com/spreadsheets/d/{id}/gviz/tq?tqx=out:csv
32
+ * - https://docs.google.com/spreadsheets/u/0/d/{id}/view
33
+ * - Raw spreadsheet ID (25+ alphanumeric characters with dashes/underscores)
34
+ */
35
+ export declare function extractSpreadsheetId(url: string): string | null;
36
+ /**
37
+ * Extracts sheet tab GID (numerical identifier) from URL hash or query parameters:
38
+ * - #gid=123456789
39
+ * - ?gid=123456789
40
+ */
41
+ export declare function extractSheetGid(url: string): string | null;
42
+ /**
43
+ * Retrieves configured Google API key defensively from Vite or Node runtime.
44
+ */
45
+ export declare function getGoogleApiKey(): string | null;
46
+ /**
47
+ * Pure parser for Google Sheets API v4 metadata response.
48
+ */
49
+ export declare function parseSheetsApiMetadata(data: unknown): SheetMetadataTab[];
50
+ /**
51
+ * Pure parser for tab names and sheet GIDs from public Google Sheets htmlview payload.
52
+ * Google embeds workbook sheets as:
53
+ * items.push({name: "Sheet1", pageUrl: "...", gid: "0", ...})
54
+ */
55
+ export declare function parseHtmlViewTabs(html: string): SheetMetadataTab[];
56
+ /**
57
+ * Discovers available sheet tabs using:
58
+ * 1. Google Sheets API v4 metadata endpoint (if key present & enabled).
59
+ * 2. Public htmlview scraping fallback (no API key required, CORS-enabled).
60
+ */
61
+ export declare function fetchSheetTabs(spreadsheetIdOrUrl: string, apiKey?: string, options?: {
62
+ timeoutMs?: number;
63
+ }): Promise<SheetMetadataTab[]>;
64
+ /**
65
+ * Verifies public readability of a Google Sheet link.
66
+ *
67
+ * Checks:
68
+ * 1. URL pattern validation & spreadsheet ID extraction.
69
+ * 2. Probe against Google endpoint (Sheets API v4 if API key present, or gviz probe).
70
+ * 3. Gracefully falls back to GViz probe if Sheets API is disabled or key lacks scope.
71
+ * 4. Detects restricted access (HTTP 401/403 or HTML login redirect).
72
+ * 5. Discovers sheet tabs automatically when accessible.
73
+ */
74
+ export declare function verifySheetAccess(url: string, options?: {
75
+ apiKey?: string;
76
+ timeoutMs?: number;
77
+ }): Promise<SheetAccessCheckResult>;
78
+ /**
79
+ * Formats an ISO 8601 modified timestamp into human-readable academic format (e.g. "Oct 14, 2024").
80
+ */
81
+ export declare function formatSheetModifiedTime(isoDate?: string | null): string | null;
82
+ /**
83
+ * Fetches the authentic last modification date of a Google Sheet via Google Drive API v3.
84
+ */
85
+ export declare function fetchSheetModifiedTime(spreadsheetIdOrUrl: string, apiKey?: string, options?: {
86
+ timeoutMs?: number;
87
+ }): Promise<string | null>;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * BaaS Data Access Layer & Live Evidence Persistence Service
3
+ * Folio Engine
4
+ * Subtask 5.1: Database Schema & BaaS Persistence Engine
5
+ *
6
+ * Implements a resilient client service layer with:
7
+ * 1. PostgREST / Supabase cloud persistence for live coordinator updates.
8
+ * 2. Multi-tier caching (In-Memory -> LocalStorage snapshot -> Baseline JSON fallback).
9
+ * 3. Zero-downtime offline and network disconnection resilience.
10
+ */
11
+ import type { LiveSourceSource, LiveSourceRegistry, UpsertSourcePayload } from '../types/source';
12
+ export declare const getSourceCacheStorageKey: (ns?: string) => string;
13
+ export declare const STORAGE_KEY_SOURCE_CACHE: string;
14
+ export declare const EVENT_SOURCE_SOURCE_CHANGE = "engine-evidence-source-change";
15
+ /**
16
+ * Sanitizes a LiveSourceSource ensuring any ephemeral /drive-storage/ links
17
+ * are permanently replaced with stable, non-expiring Google Drive endpoints.
18
+ */
19
+ export declare function sanitizeLiveSourceSource(source: LiveSourceSource): LiveSourceSource;
20
+ /**
21
+ * Asynchronously fetches live source sources from the database.
22
+ * Falls back transparently to localStorage snapshots or baseline JSON.
23
+ */
24
+ export declare function fetchLiveSourceSources(options?: {
25
+ forceRefresh?: boolean;
26
+ }): Promise<LiveSourceRegistry>;
27
+ /**
28
+ * Retrieves a single live source source by pointId with slug normalization.
29
+ */
30
+ export declare function getLiveSourceSource(pointId: string): Promise<LiveSourceSource | null>;
31
+ /**
32
+ * Synchronous accessor for fast UI rendering loops without layout shift.
33
+ * Reads from memory cache, localStorage snapshot, or fallback baseline synchronously.
34
+ */
35
+ export declare function getSourceSourceSync(pointId: string): LiveSourceSource | null;
36
+ /**
37
+ * Inserts or updates an source source in the BaaS database and local caches.
38
+ */
39
+ export declare function upsertLiveSourceSource(payload: UpsertSourcePayload, token?: string): Promise<LiveSourceSource>;
40
+ /**
41
+ * Resets the in-memory cache and localStorage snapshot back to system defaults.
42
+ */
43
+ export declare function resetSourceCache(): void;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Folio Engine - Active Session Undo / Redo Service
3
+ * Location: src/services/undoRedoService.ts
4
+ * Specification: docs/tasks/task9_2_active_session_undo_redo_engine.md
5
+ * Aligned with: docs/00_WORKFLOW.md, docs/03_ARCHITECTURE.md, docs/07_CODING_STANDARDS.md
6
+ *
7
+ * Implements:
8
+ * 1. Double-stack command pattern with capped depth (MAX_STACK_DEPTH = 50).
9
+ * 2. Re-entrancy prevention guard (isExecuting) to prevent nested dispatches during undo/redo.
10
+ * 3. Forward redo clearance on new user actions.
11
+ * 4. Keyboard focus detection utility (isTextInput) for shortcut chord isolation.
12
+ */
13
+ import type { UndoAction, UndoRedoState } from '../types/history';
14
+ export declare const MAX_STACK_DEPTH = 50;
15
+ export declare class UndoRedoManager {
16
+ private undoStack;
17
+ private redoStack;
18
+ private executingLock;
19
+ /**
20
+ * Pushes a reversible action onto the undo stack.
21
+ * Clears the redo stack and enforces the 50-action depth cap.
22
+ * If an undo/redo action is currently executing, this is a no-op to prevent re-entrant loops.
23
+ */
24
+ push(action: Omit<UndoAction, 'id' | 'timestamp'>): UndoAction | null;
25
+ /**
26
+ * Pops the most recent action from the undo stack, executes action.undo(),
27
+ * and pushes it onto the redo stack.
28
+ */
29
+ popUndo(): UndoAction | null;
30
+ /**
31
+ * Pops the most recent action from the redo stack, executes action.redo(),
32
+ * and pushes it onto the undo stack.
33
+ */
34
+ popRedo(): UndoAction | null;
35
+ /**
36
+ * Clears both undo and redo stacks (e.g. on dev mode exit or restore).
37
+ */
38
+ clear(): void;
39
+ /**
40
+ * Retrieves current immutable state snapshot.
41
+ */
42
+ getState(): UndoRedoState;
43
+ /**
44
+ * Returns true if an undo/redo operation is currently executing.
45
+ */
46
+ isExecuting(): boolean;
47
+ /**
48
+ * Diagnostic inspector for testing.
49
+ */
50
+ getStacks(): {
51
+ undo: UndoAction[];
52
+ redo: UndoAction[];
53
+ };
54
+ }
55
+ /**
56
+ * Checks if the target element is an active text input or editable container.
57
+ * Used to avoid hijacking native cursor undo/redo inside text fields.
58
+ */
59
+ export declare function isTextInput(target: EventTarget | null): boolean;
60
+ /**
61
+ * Singleton instance for active session lifetime.
62
+ */
63
+ export declare const undoRedoService: UndoRedoManager;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Folio Engine - Centralized Unsaved / Unpublished Changes Registry Service
3
+ * Location: src/services/unsavedChangesService.ts
4
+ * Specification: docs/tasks/task12_0_prevent_refresh_unsaved_changes.md
5
+ * Aligned with: docs/00_WORKFLOW.md, docs/03_ARCHITECTURE.md, docs/07_CODING_STANDARDS.md
6
+ *
7
+ * Implements:
8
+ * 1. Synchronous in-memory registry of active dirty modal/drawer editors.
9
+ * 2. Unified dirty status combining active in-flight forms + draft sandbox dirty state.
10
+ * 3. Canonical beforeunload event guard complying with W3C browser prompt standards.
11
+ */
12
+ /**
13
+ * Registers or updates the dirty state of an active editor component.
14
+ */
15
+ export declare function registerDirtyEditor(editorId: string, isDirty: boolean): void;
16
+ /**
17
+ * Unregisters an editor upon component unmount or cancellation.
18
+ */
19
+ export declare function unregisterDirtyEditor(editorId: string): void;
20
+ /**
21
+ * Clears all active dirty editors (used during tests or whole-session resets).
22
+ */
23
+ export declare function clearAllDirtyEditors(): void;
24
+ /**
25
+ * Returns true if there are any active in-flight unsaved form inputs OR unpublished draft changes.
26
+ */
27
+ export declare function hasAnyUnsavedChanges(): boolean;
28
+ /**
29
+ * Canonical W3C-compliant beforeunload guard.
30
+ * Returns empty string and calls preventDefault() if dirty, otherwise does nothing.
31
+ */
32
+ export declare function handleBeforeUnloadGuard(e: BeforeUnloadEvent): string | undefined;