@unvired/turboforms-embed-sdk 1.0.14 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -309,6 +309,41 @@ When a user crops or annotates an existing server image or local image, the SDK
309
309
 
310
310
  This process simplifies the architecture: edits simply generate brand new files, offloading any complex diffing logic to the main application server layer.
311
311
 
312
+ ## ⚡ Performance Optimization
313
+
314
+ ### Pre-initializing SmartStorage (IndexedDB)
315
+
316
+ Opening an IndexedDB connection can sometimes introduce a slight delay (lag) during the first file upload or image capture. To eliminate this, the SDK dispatches a `smartStorageReady` event as soon as the storage provider is registered.
317
+
318
+ You can listen for this event in your host application and call `preInitialize()` to "warm up" the database connection immediately during page load, ensuring the first upload is instantaneous.
319
+
320
+ #### Implementation Example
321
+
322
+ ```javascript
323
+ // Proper event-driven initialization in your host application
324
+ (function() {
325
+ const initDb = (SmartStorage) => {
326
+ if (SmartStorage && typeof SmartStorage.preInitialize === 'function') {
327
+ console.log("⚡ Pre-initializing SmartStorage IndexedDB...");
328
+ SmartStorage.preInitialize();
329
+ }
330
+ };
331
+
332
+ // 1. Check if already loaded in Formio provider registry
333
+ const existing = window.Formio?.providers?.storage?.SmartStorage ||
334
+ window.Formio?.Providers?.providers?.storage?.SmartStorage;
335
+
336
+ if (existing) {
337
+ initDb(existing);
338
+ } else {
339
+ // 2. Otherwise listen for the SDK's "ready" event dispatched on document
340
+ document.addEventListener('smartStorageReady', (e) => {
341
+ initDb(e.detail.SmartStorage);
342
+ }, { once: true });
343
+ }
344
+ })();
345
+ ```
346
+
312
347
  ## 🔧 Form Instance Methods
313
348
 
314
349
  The `loadUnviredForms` function returns a FormInstance object with the following methods: