mnfst 0.5.287 → 0.5.288

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  (function () {
4
4
 
5
- const MANIFEST_BUILD_VERSION = '0.5.287';
5
+ const MANIFEST_BUILD_VERSION = '0.5.288';
6
6
 
7
7
  /* Manifest Data Sources - Appwrite Integration */
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  (function () {
4
4
 
5
- const MANIFEST_BUILD_VERSION = '0.5.287';
5
+ const MANIFEST_BUILD_VERSION = '0.5.288';
6
6
 
7
7
  /* Manifest Data Sources - Configuration */
8
8
 
@@ -3298,14 +3298,54 @@ function sameValue(a, b) {
3298
3298
  try { return JSON.stringify(a) === JSON.stringify(b); } catch { return false; }
3299
3299
  }
3300
3300
 
3301
- // Re-insert a row at its old index (a failed delete); never duplicates one already back
3301
+ // Source order before overlapping deletes began: failed deletes return relative to it
3302
+ const deleteOrders = new Map();
3303
+
3304
+ function beginDeleteOrder(dataSourceName) {
3305
+ let entry = deleteOrders.get(dataSourceName);
3306
+ if (!entry) {
3307
+ const { arr } = findRawIndex(dataSourceName, null);
3308
+ entry = { positions: new Map((arr || []).map((row, i) => [row?.$id, i])), count: 0 };
3309
+ deleteOrders.set(dataSourceName, entry);
3310
+ }
3311
+ entry.count++;
3312
+ return entry;
3313
+ }
3314
+
3315
+ function endDeleteOrder(dataSourceName, entry) {
3316
+ if (!entry || --entry.count > 0) return;
3317
+ if (deleteOrders.get(dataSourceName) === entry) deleteOrders.delete(dataSourceName);
3318
+ }
3319
+
3320
+ // Where a returning row goes: after its nearest present predecessor in the order, else before its successor
3321
+ function restoreIndex(arr, positions, id, fallback) {
3322
+ const at = positions ? positions.get(id) : undefined;
3323
+ if (at !== undefined) {
3324
+ let before = -1, beforeAt = -1, after = -1, afterAt = Infinity;
3325
+ for (let j = 0; j < arr.length; j++) {
3326
+ const p = positions.get(arr[j]?.$id);
3327
+ if (p === undefined) continue;
3328
+ if (p < at && p > beforeAt) { beforeAt = p; before = j; }
3329
+ else if (p > at && p < afterAt) { afterAt = p; after = j; }
3330
+ }
3331
+ if (before !== -1) return before + 1;
3332
+ if (after !== -1) return after;
3333
+ }
3334
+ return fallback >= 0 && fallback <= arr.length ? fallback : arr.length;
3335
+ }
3336
+
3337
+ // Re-insert a row deleted optimistically (a failed delete); never duplicates one already back
3302
3338
  function insertEntryAt(dataSourceName, entry, index, options = {}) {
3303
3339
  if (window.ManifestDataStore?.isStaleWrite?.(dataSourceName, options)) return false;
3304
3340
  const { store, arr, index: existing } = findRawIndex(dataSourceName, entry?.$id);
3305
3341
  if (!store || !arr || existing !== -1) return false;
3306
3342
  const ds = window.ManifestDataStore;
3307
- const at = index >= 0 && index <= arr.length ? index : arr.length;
3308
- store[dataSourceName].splice(at, 0, ds.createReactiveReferences(entry, dataSourceName));
3343
+ const row = ds.createReactiveReferences(entry, dataSourceName);
3344
+ if (window.ManifestDataMain?.orderFor?.(dataSourceName) && ds.insertRow) {
3345
+ ds.insertRow(store, dataSourceName, row);
3346
+ } else {
3347
+ store[dataSourceName].splice(restoreIndex(arr, options.order, entry.$id, index), 0, row);
3348
+ }
3309
3349
  ds.touchSource(dataSourceName);
3310
3350
  clearSourceCaches(dataSourceName);
3311
3351
  return true;
@@ -3365,6 +3405,7 @@ async function executeMutation(mutationConfig) {
3365
3405
  let resolvedEntryId = entryId;
3366
3406
  let held = null; // pending-write token: re-applied over landings until settled
3367
3407
  let deletedAt = -1; // a failed delete returns the row to its place
3408
+ let deleteOrder = null;
3368
3409
  const ds0 = window.ManifestDataStore;
3369
3410
 
3370
3411
  // Get helper functions from store
@@ -3419,6 +3460,7 @@ async function executeMutation(mutationConfig) {
3419
3460
  // Snapshot for rollback
3420
3461
  const store = Alpine.store('data');
3421
3462
  if (store && store[dataSourceName] && Array.isArray(store[dataSourceName])) {
3463
+ deleteOrder = beginDeleteOrder(dataSourceName);
3422
3464
  deletedAt = findRawIndex(dataSourceName, entryId).index;
3423
3465
  const found = deletedAt !== -1 ? store[dataSourceName][deletedAt] : null;
3424
3466
  originalData = found ? { ...found } : null;
@@ -3550,7 +3592,7 @@ async function executeMutation(mutationConfig) {
3550
3592
  }
3551
3593
  if (Object.keys(restore).length) updateEntryInStore(dataSourceName, entryId, restore, writeOptions);
3552
3594
  } else if (type === 'delete' && originalData) {
3553
- insertEntryAt(dataSourceName, originalData, deletedAt, writeOptions);
3595
+ insertEntryAt(dataSourceName, originalData, deletedAt, { ...writeOptions, order: deleteOrder?.positions });
3554
3596
  }
3555
3597
  };
3556
3598
 
@@ -3569,6 +3611,8 @@ async function executeMutation(mutationConfig) {
3569
3611
  }));
3570
3612
 
3571
3613
  throw error;
3614
+ } finally {
3615
+ endDeleteOrder(dataSourceName, deleteOrder);
3572
3616
  }
3573
3617
  }
3574
3618
 
@@ -3666,6 +3710,7 @@ if (typeof window !== 'undefined') {
3666
3710
  addEntryToStore,
3667
3711
  removeEntryFromStore,
3668
3712
  rollbackMutation,
3713
+ restoreIndex,
3669
3714
  syncEntryFromServer,
3670
3715
  generateMutationId,
3671
3716
  setupEventDrivenReactivity
@@ -7590,27 +7635,50 @@ async function writeFileLink(tableName, entryId, fileId, fileIdsColumn) {
7590
7635
  }
7591
7636
  }
7592
7637
 
7593
- // Unlink a file from all table entries that reference it (used when deleting files)
7594
- // This is a best-effort cleanup - uses already-loaded table data from Alpine store
7595
- // Returns array of affected entry IDs grouped by table name: { tableName: [entryId1, entryId2, ...] }
7596
- async function unlinkFileFromAllEntries(fileId) {
7638
+ // Link columns a table holds a bucket's file ids in: storage mappings, belongsTo, else fileIds
7639
+ function fileLinkColumns(manifest, tableName, tableConfig, bucketId) {
7640
+ const config = window.ManifestDataConfig;
7641
+ const links = [];
7642
+ const storage = tableConfig?.storage;
7643
+ if (storage && typeof storage === 'object') {
7644
+ for (const [bucketName, mapping] of Object.entries(storage)) {
7645
+ if (typeof mapping === 'string') {
7646
+ const bucketSource = manifest.data[bucketName];
7647
+ links.push({ bucket: bucketSource ? config.getAppwriteBucketId(bucketSource) : null, column: mapping });
7648
+ } else if (mapping && typeof mapping === 'object') {
7649
+ links.push({ bucket: mapping.appwriteBucketId || null, column: mapping.column || 'fileIds' });
7650
+ }
7651
+ }
7652
+ }
7653
+ for (const source of Object.values(manifest.data)) {
7654
+ const link = source && typeof source === 'object' ? source.belongsTo : null;
7655
+ if (link?.table === tableName && link.fileIdsColumn) {
7656
+ links.push({ bucket: config.getAppwriteBucketId(source) || null, column: link.fileIdsColumn });
7657
+ }
7658
+ }
7659
+ const known = links.filter(link => link.bucket);
7660
+ const columns = new Set(known.filter(link => !bucketId || link.bucket === bucketId).map(link => link.column));
7661
+ if (!known.some(link => link.column === 'fileIds')) columns.add('fileIds');
7662
+ return [...columns];
7663
+ }
7664
+
7665
+ // Unlink file(s) from every loaded table entry that references them (after a delete)
7666
+ // Returns { tableName: [entryId, ...] }
7667
+ async function unlinkFileFromAllEntries(fileId, options = {}) {
7597
7668
  const manifest = await window.ManifestDataConfig.ensureManifest();
7598
7669
  if (!manifest?.data) {
7599
7670
  return {};
7600
7671
  }
7601
7672
 
7602
- const actualFileId = fileId?.$id || fileId;
7603
- if (!actualFileId) {
7673
+ const fileIds = (Array.isArray(fileId) ? fileId : [fileId]).map(id => id?.$id || id).filter(Boolean);
7674
+ if (!fileIds.length) {
7604
7675
  return {};
7605
7676
  }
7606
7677
 
7607
- // Find all table data sources that might have fileIds arrays
7608
7678
  const tables = Object.entries(manifest.data).filter(([name, config]) =>
7609
7679
  config && typeof config === 'object' && window.ManifestDataConfig.getAppwriteTableId(config)
7610
7680
  );
7611
7681
 
7612
- // Use already-loaded data from Alpine store instead of querying Appwrite
7613
- // Check if Alpine is available before accessing store
7614
7682
  if (typeof Alpine === 'undefined' || !Alpine.store) {
7615
7683
  return {};
7616
7684
  }
@@ -7619,52 +7687,46 @@ async function unlinkFileFromAllEntries(fileId) {
7619
7687
  return {};
7620
7688
  }
7621
7689
 
7622
- const affectedEntries = {}; // { tableName: [entryId1, entryId2, ...] }
7623
-
7624
- // Do all unlinks in parallel for speed
7690
+ const affectedEntries = {};
7625
7691
  const unlinkPromises = [];
7626
7692
 
7627
7693
  for (const [tableName, tableConfig] of tables) {
7628
7694
  try {
7629
- const tableId = window.ManifestDataConfig.getAppwriteTableId(tableConfig);
7630
7695
  const appwriteConfig = await window.ManifestDataConfig.getAppwriteConfig(tableConfig);
7631
-
7632
7696
  if (!appwriteConfig) continue;
7633
7697
 
7634
- // Get already-loaded entries from Alpine store
7635
7698
  const entries = store[tableName];
7636
7699
  if (!Array.isArray(entries) || entries.length === 0) {
7637
7700
  continue;
7638
7701
  }
7639
7702
 
7640
- // Find entries that have this fileId in their fileIds array
7641
- const entriesToUpdate = entries.filter(entry => {
7642
- const fileIds = entry.fileIds || [];
7643
- return Array.isArray(fileIds) && fileIds.includes(actualFileId);
7644
- });
7703
+ const columns = fileLinkColumns(manifest, tableName, tableConfig, options.bucketId);
7704
+ const affected = new Set();
7645
7705
 
7646
- if (entriesToUpdate.length > 0) {
7647
- affectedEntries[tableName] = entriesToUpdate.map(e => e.$id);
7706
+ for (const entry of entries) {
7707
+ for (const column of columns) {
7708
+ const linked = entry?.[column];
7709
+ if (!Array.isArray(linked)) continue;
7710
+ for (const id of fileIds) {
7711
+ if (!linked.includes(id)) continue;
7712
+ affected.add(entry.$id);
7713
+ unlinkPromises.push(
7714
+ unlinkFileFromEntry(tableName, entry.$id, id, column).catch(error => {
7715
+ console.warn('[Manifest Data] Could not unlink from', tableName, 'entry', entry.$id, ':', error.message);
7716
+ })
7717
+ );
7718
+ }
7719
+ }
7648
7720
  }
7649
7721
 
7650
- // Unlink file from each entry in parallel
7651
- for (const entry of entriesToUpdate) {
7652
- unlinkPromises.push(
7653
- unlinkFileFromEntry(tableName, entry.$id, actualFileId, 'fileIds')
7654
- .then(() => {
7655
- })
7656
- .catch(error => {
7657
- console.warn('[Manifest Data] Could not unlink from', tableName, 'entry', entry.$id, ':', error.message);
7658
- })
7659
- );
7722
+ if (affected.size > 0) {
7723
+ affectedEntries[tableName] = [...affected];
7660
7724
  }
7661
7725
  } catch (error) {
7662
- // Silently continue - not all tables may have fileIds
7663
7726
  console.warn('[Manifest Data] Could not process', tableName, ':', error.message);
7664
7727
  }
7665
7728
  }
7666
7729
 
7667
- // Wait for all unlinks to complete
7668
7730
  await Promise.all(unlinkPromises);
7669
7731
 
7670
7732
  return affectedEntries;
@@ -8413,6 +8475,69 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
8413
8475
 
8414
8476
  // Handle storage operations
8415
8477
  if (bucketId) {
8478
+ // $delete / $remove: delete each file, land successes locally, then unlink them
8479
+ const deleteBucketFiles = async (fileId) => {
8480
+ const ids = (Array.isArray(fileId) ? fileId : [fileId]).map(id => id?.$id || id);
8481
+ if (Array.isArray(fileId) && !ids.length) return [];
8482
+ if (ids.some(id => !id)) {
8483
+ throw new Error(`[Manifest Data] ${method} requires file ID`);
8484
+ }
8485
+ const ds = window.ManifestDataStore;
8486
+ const generation = ds?.sourceGeneration?.(dataSourceName);
8487
+ const executeMutation = window.ManifestDataMutations?.executeMutation;
8488
+ const deleteOne = id => executeMutation
8489
+ ? executeMutation({
8490
+ type: 'delete',
8491
+ dataSourceName,
8492
+ entryId: id,
8493
+ apiCall: () => window.ManifestDataAppwrite.deleteFile(bucketId, id),
8494
+ options: { scope, bucketId, appwriteConfig }
8495
+ })
8496
+ : window.ManifestDataAppwrite.deleteFile(bucketId, id);
8497
+
8498
+ const settled = await Promise.allSettled(ids.map(deleteOne));
8499
+ const deleted = ids.filter((id, i) => settled[i].status === 'fulfilled');
8500
+
8501
+ // Never a relist: an unfiltered listing would bypass the source's queries and scope
8502
+ if (deleted.length && ds?.landRemove) {
8503
+ await ds.landRemove(dataSourceName, deleted, { generation });
8504
+ }
8505
+
8506
+ // Unlink only what the server deleted
8507
+ const unlink = window.ManifestDataProxiesFiles?.unlinkFileFromAllEntries;
8508
+ const affected = await Promise.all(deleted.map(async id => {
8509
+ try {
8510
+ return unlink ? await unlink(id, { bucketId }) || {} : {};
8511
+ } catch (unlinkError) {
8512
+ console.warn('[Manifest Data] Failed to unlink deleted file from entries:', unlinkError);
8513
+ return {};
8514
+ }
8515
+ }));
8516
+
8517
+ const tables = new Set(affected.flatMap(entries => Object.keys(entries)));
8518
+ const reloadDataSourceFunc = window.ManifestDataMain?._loadDataSource;
8519
+ if (reloadDataSourceFunc) {
8520
+ for (const tableName of tables) {
8521
+ reloadDataSourceFunc(tableName).catch(err => {
8522
+ console.warn(`[Manifest Data] Failed to reload ${tableName} after file delete:`, err);
8523
+ });
8524
+ }
8525
+ }
8526
+
8527
+ deleted.forEach((id, i) => {
8528
+ const linked = Object.entries(affected[i]).filter(([, entryIds]) => Array.isArray(entryIds) && entryIds.length);
8529
+ for (const [tableName, entryIds] of linked.length ? linked : [[null, []]]) {
8530
+ window.dispatchEvent(new CustomEvent('manifest:file-deleted', { detail: { fileId: id, tableName, entryIds } }));
8531
+ }
8532
+ window.dispatchEvent(new CustomEvent('manifest:file-deleted', { detail: { fileId: id, tableName: null, entryIds: [], bucketId } }));
8533
+ });
8534
+
8535
+ const failed = settled.find(r => r.status === 'rejected');
8536
+ if (failed) throw failed.reason;
8537
+ const results = settled.map(r => r.value);
8538
+ return Array.isArray(fileId) ? results : results[0];
8539
+ };
8540
+
8416
8541
  if (method === '$create') {
8417
8542
  let [fileId, file, permissions, onProgress] = args;
8418
8543
 
@@ -8734,85 +8859,7 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
8734
8859
 
8735
8860
  return result;
8736
8861
  } else if (method === '$delete') {
8737
- const fileId = args[0];
8738
- const actualFileId = fileId?.$id || fileId;
8739
-
8740
- // Before deleting, unlink file from any table entries that reference it
8741
- // This prevents orphaned references (best-effort cleanup)
8742
- try {
8743
- const unlinkFileFromAllEntries = window.ManifestDataProxiesFiles?.unlinkFileFromAllEntries;
8744
- if (unlinkFileFromAllEntries) {
8745
- await unlinkFileFromAllEntries(actualFileId);
8746
- }
8747
- } catch (unlinkError) {
8748
- console.warn('[Manifest Data] Failed to unlink file from entries before delete:', unlinkError);
8749
- // Continue with delete even if unlink fails
8750
- }
8751
-
8752
- const executeMutation = window.ManifestDataMutations?.executeMutation;
8753
- const removeEntryFromStore = window.ManifestDataMutations?.removeEntryFromStore;
8754
-
8755
- if (Array.isArray(fileId)) {
8756
- if (executeMutation) {
8757
- // Use optimistic updates for batch delete
8758
- const results = await Promise.all(
8759
- fileId.map(id => {
8760
- const entryId = id.$id || id;
8761
- return executeMutation({
8762
- type: 'delete',
8763
- dataSourceName,
8764
- entryId,
8765
- apiCall: async () => {
8766
- return await window.ManifestDataAppwrite.deleteFile(bucketId, entryId);
8767
- },
8768
- options: {
8769
- scope,
8770
- bucketId,
8771
- appwriteConfig
8772
- }
8773
- });
8774
- })
8775
- );
8776
-
8777
- // No reload: optimistic delete + realtime sync. Reloading
8778
- // races and can resurrect deleted files from stale data.
8779
- return results;
8780
- } else {
8781
- // Fallback to old behavior
8782
- const results = await Promise.all(
8783
- fileId.map(id =>
8784
- window.ManifestDataAppwrite.deleteFile(bucketId, id.$id || id)
8785
- )
8786
- );
8787
- // Note: No reload - rely on realtime events for sync
8788
- return results;
8789
- }
8790
- } else {
8791
- if (executeMutation) {
8792
- const result = await executeMutation({
8793
- type: 'delete',
8794
- dataSourceName,
8795
- entryId: actualFileId,
8796
- apiCall: async () => {
8797
- return await window.ManifestDataAppwrite.deleteFile(bucketId, actualFileId);
8798
- },
8799
- options: {
8800
- scope,
8801
- bucketId,
8802
- appwriteConfig
8803
- }
8804
- });
8805
-
8806
- // No reload: optimistic delete + realtime sync. Reloading
8807
- // races and can resurrect deleted files from stale data.
8808
- return result;
8809
- } else {
8810
- // Fallback to old behavior
8811
- const result = await window.ManifestDataAppwrite.deleteFile(bucketId, actualFileId);
8812
- // Note: No reload - rely on realtime events for sync
8813
- return result;
8814
- }
8815
- }
8862
+ return await deleteBucketFiles(args[0]);
8816
8863
  } else if (method === '$duplicate') {
8817
8864
  const [fileId, options = {}] = args;
8818
8865
  const { newFileId, newName, ...overrides } = options;
@@ -9068,99 +9115,15 @@ function createAppwriteMethodsHandler(dataSourceName, reloadDataSource) {
9068
9115
  await unlinkFileFromEntry(tableName, entryId, fileId.$id || fileId, fileIdsColumn || 'fileIds');
9069
9116
  }
9070
9117
 
9071
- // Auto-refresh: automatically refresh and return files list for this table/entry
9072
- // This matches the pattern of $x.projects.$delete() which auto-reloads
9118
+ // Return the entry's refreshed files list
9073
9119
  const getFilesForEntry = window.ManifestDataProxiesFiles?.getFilesForEntry;
9074
9120
  if (getFilesForEntry) {
9075
9121
  return await getFilesForEntry(tableName, entryId, bucketId, fileIdsColumn || 'fileIds');
9076
9122
  }
9077
9123
  return null;
9078
9124
  } else if (method === '$remove') {
9079
- // Delete file(s), drop them from the source, unlink from table entries
9080
- // Usage: $x.assets.$remove(fileId)
9081
- const fileId = args[0];
9082
- if (!fileId) {
9083
- throw new Error('[Manifest Data] $remove requires file ID');
9084
- }
9085
-
9086
- const actualFileId = fileId.$id || fileId;
9087
-
9088
- // Before deleting, unlink file from any table entries that reference it
9089
- // This prevents orphaned references and ensures UI updates correctly
9090
- let affectedEntries = {};
9091
- try {
9092
- const unlink = window.ManifestDataProxiesFiles?.unlinkFileFromAllEntries;
9093
- if (unlink) affectedEntries = await unlink(actualFileId) || {};
9094
- } catch (unlinkError) {
9095
- console.warn('[Manifest Data] Failed to unlink file from entries before delete:', unlinkError);
9096
- // Continue with delete even if unlink fails
9097
- }
9098
-
9099
- const deletedIds = (Array.isArray(fileId) ? fileId : [fileId]).map(id => id.$id || id);
9100
- const generation = window.ManifestDataStore?.sourceGeneration?.(dataSourceName);
9101
- const result = Array.isArray(fileId)
9102
- ? await Promise.all(deletedIds.map(id => window.ManifestDataAppwrite.deleteFile(bucketId, id)))
9103
- : await window.ManifestDataAppwrite.deleteFile(bucketId, actualFileId);
9104
-
9105
- // Drop the deleted file(s) locally: a relisting would bypass the source's queries and scope
9106
- if (window.ManifestDataStore?.landRemove) {
9107
- await window.ManifestDataStore.landRemove(dataSourceName, deletedIds, { generation });
9108
- }
9109
-
9110
- // Reload affected table data sources so fileIds arrays and counters
9111
- // update in the UI (loadDataSource lands the rows itself)
9112
- const reloadDataSourceFunc = window.ManifestDataMain?._loadDataSource;
9113
- if (reloadDataSourceFunc && Object.keys(affectedEntries).length > 0) {
9114
- const reloadPromises = [];
9115
- for (const tableName of Object.keys(affectedEntries)) {
9116
- reloadPromises.push(
9117
- reloadDataSourceFunc(tableName).catch(err => {
9118
- console.warn(`[Manifest Data] Failed to reload ${tableName} after file delete:`, err);
9119
- })
9120
- );
9121
- }
9122
- // Don't await - let it happen in background
9123
- Promise.all(reloadPromises).catch(() => { });
9124
- }
9125
-
9126
- // Emit event for affected projects to auto-refresh
9127
- // Always emit the event so UI can handle it optimistically, even if we couldn't find affected entries
9128
- if (Object.keys(affectedEntries).length > 0) {
9129
- for (const [tableName, entryIds] of Object.entries(affectedEntries)) {
9130
- if (Array.isArray(entryIds) && entryIds.length > 0) {
9131
- window.dispatchEvent(new CustomEvent('manifest:file-deleted', {
9132
- detail: {
9133
- fileId: actualFileId,
9134
- tableName,
9135
- entryIds
9136
- }
9137
- }));
9138
- }
9139
- }
9140
- } else {
9141
- // If we couldn't find affected entries, still emit event with empty entryIds
9142
- // This allows UI to handle it optimistically by checking if the file is in their local list
9143
- window.dispatchEvent(new CustomEvent('manifest:file-deleted', {
9144
- detail: {
9145
- fileId: actualFileId,
9146
- tableName: null,
9147
- entryIds: []
9148
- }
9149
- }));
9150
- }
9151
-
9152
- // Also dispatch event for storage bucket reactivity (so $x.assets updates)
9153
- // The realtime handler will also update, but this ensures immediate UI update
9154
- window.dispatchEvent(new CustomEvent('manifest:file-deleted', {
9155
- detail: {
9156
- fileId: actualFileId,
9157
- tableName: null,
9158
- entryIds: [],
9159
- bucketId: bucketId // Include bucketId so storage can filter if needed
9160
- }
9161
- }));
9162
-
9163
- return result;
9125
+ // Usage: $x.assets.$remove(fileIdOrArray)
9126
+ return await deleteBucketFiles(args[0]);
9164
9127
  }
9165
9128
  }
9166
9129
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "manifest.appwrite.auth.js": "sha384-gWLSeVPqCLMiUZB8MU7GqMg3x2yULFUsp8nTTZrPp/9Dlkix42rBn9yIimvwrHqZ",
3
- "manifest.appwrite.data.js": "sha384-P9MatQi4l7pn5HH2m68X9Z0d1e6qmvry+Pfur5/Z1dzblCB90Fc078Pi0eP6LzOn",
3
+ "manifest.appwrite.data.js": "sha384-vNvLaABWVGF9HZZBBClXjUcf/398pm53bk5JukMakTJqGKAjIZ/wxkFQuh22Wavf",
4
4
  "manifest.appwrite.presences.js": "sha384-LINPhIPTCK+rA8zd+HPUzMSEgH6Sl2vQMEyItT97bnEE2FYGYKqjXX+CWdt6nl9z",
5
5
  "manifest.bindings.js": "sha384-lPtMf8Ykaic9gNVZKq8Scia1881ZeMAyxer3WCIkUNwwrgzGBWto1OXADUwjvORF",
6
6
  "manifest.charts.js": "sha384-AFbP7mQnigy7DU1s+YE30yKTeQAKfgNazhbfSNbfd9ZpLgeulZKaPi/fAq3gJHDO",
@@ -11,7 +11,7 @@
11
11
  "manifest.combobox.js": "sha384-/lJo6vaxKjgnBSRs/dzkhK1dzGk3GBw8FISoNJZB70mwAVwu1k5veZyBXjOb4keS",
12
12
  "manifest.components.js": "sha384-1el5WMdgmzu/2ocaYN21OjLi/lfjllvA8aju1J3knYuOizw+XFfJU1+rvGqYW7qk",
13
13
  "manifest.computed.js": "sha384-GYML/e81gQfN+iDbqhPUgny8bINCyL+SrbTofoGk4hlCnLLjv51mCv42JMqq+ku5",
14
- "manifest.data.js": "sha384-EaU5LQ9YSTNtyPt5MPHkuAoKF1qzVedLvCaeA22wcJn83Bhrdwj6HE0Wsa0mokQL",
14
+ "manifest.data.js": "sha384-wU3ne2fDuf03ARPLijNVuh+snST/Sy9C32TsO6XGIXx2lTd/VHYGFOWaGaeYkKlU",
15
15
  "manifest.datepicker.js": "sha384-EzlMwvIxlla/0BuyhAEqxN0M8TGcWIWgEIg840V0akKQQK1uY648wPWMkobvtq/o",
16
16
  "manifest.defer.js": "sha384-PRp7+dCZHnnl55rX2xrHutLrQnszHo7o5o9Tq28M/yjLZPuXDzcwQNxCdvbtCYSz",
17
17
  "manifest.device.js": "sha384-YeQaS56L8IILqrQNBSeAOLwIh5DuAOrE60cYLK1+46qJtUrXlAvqGe2j5mbV4Vq7",
@@ -19,17 +19,17 @@
19
19
  "manifest.edit.js": "sha384-8JqFgkt8KMtB8bkwDPe0ntKbOSKGwKz8MrDsEkxozKkEreS4OCE1YfJMWO3QBMZO",
20
20
  "manifest.export.js": "sha384-C4W5LrGQFnSILRWoWOCliajUK6rAzNW+EliogRx72vD1cUOYScSdfzHNbjSWv5XU",
21
21
  "manifest.icons.js": "sha384-kKOINpX70YzNO3FvkV6umrmO3f0KIu0DNbwB+ej55a7y/lhU7v/myQtXL0bwCTbt",
22
- "manifest.localization.js": "sha384-EImsIw8Z3l13V5eH9ZJF/yfsOfIvR1oPRNSArANkPji7V8O3IRf6zMwsNiAGj3Hk",
22
+ "manifest.localization.js": "sha384-9EDAqnI7MNCZp4Vas0RMZgceCuz9EJUi/OARm8iI+Hi4S8HF//yyVOhhhhQ+XcLq",
23
23
  "manifest.markdown.js": "sha384-icbpHC8dIijEJSaW3CODo4Ft7dBQz53pUh/2OYVBEFrLQbrFs370D+eMygJx5cW8",
24
24
  "manifest.native.js": "sha384-YeQaS56L8IILqrQNBSeAOLwIh5DuAOrE60cYLK1+46qJtUrXlAvqGe2j5mbV4Vq7",
25
25
  "manifest.payments.js": "sha384-p10n6EHBWFKVW9KhI2A+RpkwqrwD068D+wvOJ7D3Gklz1MvmIlqv1lLG1R0cUqbw",
26
26
  "manifest.rich.text.js": "sha384-ZBV9jXmu2nmprEHicddRE/m7nR4RPZtVc969Jte0+EJYBcVph7itkjcgN/61PyeC",
27
- "manifest.router.js": "sha384-wHqcrFeKBusrmrYB46677CYQQrfWKLOmzAkzsvlCNr5qGiZey+4OPrKVXSLzfK/W",
27
+ "manifest.router.js": "sha384-jDSzEKDI47BQvSbCXoLn9A9QOCWat5eawBx+/2du6+Tq6YCw9jhv+5HXuy+nJunR",
28
28
  "manifest.slides.js": "sha384-3uRTkyK9XPLmnxI2+igZlpi4EyPlU/7IHj5j3BZJJ2KN455vXyk99fiXV3feO/XY",
29
29
  "manifest.status.js": "sha384-ofu7nBnVIGZ1U1o2R9d2H3V8aEMPUCVbl5FO3gIToXqi0oa36fTviEdh5UU7Kitw",
30
30
  "manifest.submissions.js": "sha384-v9eS47ytAfTGIKAyVnbd0QWegucVS7yduvigqfsxxoqXmbaEoy0M2y+BiI4xeZBd",
31
31
  "manifest.svg.js": "sha384-qr/8H9+2cIhSXNbRWRtIdrDlTOxKlNJqwEefHvCYoiBNW/kKhPTFa109Orv/EBnb",
32
- "manifest.sw.js": "sha384-gnShzOKGydyeWISmdoOuWP7sCTT1q4wzIaezyijHQveoxQ1FpjkF/rvduQb9cXge",
32
+ "manifest.sw.js": "sha384-Eb8PhD5AKbkDmK2Fq7yckkGni5NpDEyUKNmgStNtFhaHDpfKOE7Gxe3qCyB53mpg",
33
33
  "manifest.tabs.js": "sha384-otU09H7jnawVKQdLAYpMCd3jx00tgyPVr42D2hLIBzN5dG4se505YesavdnMqEi1",
34
34
  "manifest.tailwind.js": "sha384-yuP3LEvWU+QVjxjkZ0YhErtC9RrGmhOmHjjFjhS9obqZbp5/KTIEnSR0CXDvHE0B",
35
35
  "manifest.toasts.js": "sha384-UpOz9fAdGeGUhL0NamBg5iPepEfIy73p9HYdcxfOQC5b7CVsl7Our0skdZzaLNcC",
@@ -157,9 +157,24 @@ function initializeLocalizationPlugin() {
157
157
  .filter(Boolean);
158
158
  }
159
159
 
160
+ // Base path split
161
+ function splitBasePath(pathname) {
162
+ const parts = String(pathname || '/').split('/').filter(Boolean);
163
+ const base = (typeof window.getManifestBasePath === 'function' ? window.getManifestBasePath() : '') || '';
164
+ const baseParts = base.split('/').filter(Boolean);
165
+ if (baseParts.length && baseParts.every((seg, i) => parts[i] === seg)) {
166
+ return { base: '/' + baseParts.join('/'), parts: parts.slice(baseParts.length) };
167
+ }
168
+ return { base: '', parts };
169
+ }
170
+
171
+ function joinBasePath(base, parts) {
172
+ return (base + '/' + parts.join('/')).replace(/\/{2,}/g, '/');
173
+ }
174
+
160
175
  function buildLocaleNavigationUrl(newLang, availableLocales) {
161
176
  const currentUrl = new URL(window.location.href);
162
- const pathParts = currentUrl.pathname.split('/').filter(Boolean);
177
+ const { base, parts: pathParts } = splitBasePath(currentUrl.pathname);
163
178
  const hasLanguageInUrl = pathParts[0] && availableLocales.includes(pathParts[0]);
164
179
 
165
180
  const pathWithoutLocale = hasLanguageInUrl ? pathParts.slice(1) : pathParts;
@@ -192,7 +207,7 @@ function initializeLocalizationPlugin() {
192
207
 
193
208
  if (hasLanguageInUrl) pathParts[0] = newLang;
194
209
  else pathParts.unshift(newLang);
195
- currentUrl.pathname = '/' + pathParts.join('/') + '/';
210
+ currentUrl.pathname = joinBasePath(base, pathParts) + '/';
196
211
  return currentUrl.toString();
197
212
  }
198
213
 
@@ -373,7 +388,7 @@ function initializeLocalizationPlugin() {
373
388
  function detectInitialLocale(availableLocales) {
374
389
 
375
390
  // URL path (direct links)
376
- const pathParts = window.location.pathname.split('/').filter(Boolean);
391
+ const pathParts = splitBasePath(window.location.pathname).parts;
377
392
  if (pathParts[0] && isValidLanguageCode(pathParts[0]) && availableLocales.includes(pathParts[0])) {
378
393
  return pathParts[0];
379
394
  }
@@ -472,19 +487,19 @@ function initializeLocalizationPlugin() {
472
487
  // Skipped for scoped demo changes — the prefixed URL wasn't prerendered.
473
488
  try {
474
489
  const currentUrl = new URL(window.location.href);
475
- const pathParts = currentUrl.pathname.split('/').filter(Boolean);
490
+ const { base, parts: pathParts } = splitBasePath(currentUrl.pathname);
476
491
  const hasLanguageInUrl = pathParts[0] && store.available.includes(pathParts[0]);
477
492
 
478
493
  if (!isScopedDemoChange && (updateUrl || hasLanguageInUrl)) {
479
494
  if (hasLanguageInUrl) {
480
495
  if (pathParts[0] !== newLang) {
481
496
  pathParts[0] = newLang;
482
- currentUrl.pathname = '/' + pathParts.join('/');
497
+ currentUrl.pathname = joinBasePath(base, pathParts);
483
498
  window.history.replaceState({}, '', currentUrl);
484
499
  }
485
500
  } else if (updateUrl && pathParts.length > 0) {
486
501
  pathParts.unshift(newLang);
487
- currentUrl.pathname = '/' + pathParts.join('/');
502
+ currentUrl.pathname = joinBasePath(base, pathParts);
488
503
  window.history.replaceState({}, '', currentUrl);
489
504
  }
490
505
  }
@@ -555,11 +570,11 @@ function initializeLocalizationPlugin() {
555
570
  } catch {
556
571
  return false;
557
572
  }
558
- const segs = target.pathname.split('/').filter(Boolean);
573
+ const { base: targetBase, parts: segs } = splitBasePath(target.pathname);
559
574
  if (segs.length && available.includes(segs[0])) {
560
575
  segs.shift();
561
576
  }
562
- target.pathname = '/' + segs.join('/');
577
+ target.pathname = joinBasePath(targetBase, segs);
563
578
 
564
579
  // Apply default to live store + DOM before navigating
565
580
  if (store && store.current !== defaultLocale) {
@@ -435,7 +435,20 @@ if (typeof navigator !== 'undefined' && navigator.webdriver === true) {
435
435
  }
436
436
  }
437
437
 
438
- // Resolve internal link to absolute pathname for pushState. Relative hrefs (e.g. "gadget") are resolved against the app base, not the current URL, so we never get additive paths like /src/dist/widget/gadget/widget/...
438
+ // Href parts: path, ?query, #hash
439
+ function splitHref(href) {
440
+ const hashAt = href.indexOf('#');
441
+ const hash = hashAt === -1 ? '' : href.slice(hashAt + 1);
442
+ const beforeHash = hashAt === -1 ? href : href.slice(0, hashAt);
443
+ const queryAt = beforeHash.indexOf('?');
444
+ return {
445
+ path: queryAt === -1 ? beforeHash : beforeHash.slice(0, queryAt),
446
+ search: queryAt === -1 ? '' : beforeHash.slice(queryAt),
447
+ hash
448
+ };
449
+ }
450
+
451
+ // Resolve internal link to absolute pathname against the app base
439
452
  function resolveHref(href) {
440
453
  if (!href || href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:')) return href;
441
454
  try {
@@ -570,21 +583,20 @@ function interceptLinkClicks() {
570
583
  return;
571
584
  }
572
585
 
586
+ const { path, search, hash } = splitHref(href);
587
+ const fullHref = (path ? resolveHref(path) : '') + search + (hash ? '#' + hash : '');
588
+
573
589
  // target=_blank: open the resolved URL (base path, locale) in a new tab
574
590
  if (target === '_blank') {
575
- const [path, hash] = href.split('#');
576
591
  event.preventDefault();
577
592
  event.stopPropagation();
578
593
  event.stopImmediatePropagation();
579
- window.open(resolveHref(path) + (hash ? '#' + hash : ''), '_blank', 'noopener');
594
+ window.open(fullHref, '_blank', link.relList?.contains('noreferrer') ? 'noopener,noreferrer' : 'noopener');
580
595
  return;
581
596
  }
582
597
 
583
598
  // Handle links with both route and anchor (e.g., /page#section)
584
- if (href.includes('#')) {
585
- const [path, hash] = href.split('#');
586
- const fullHref = resolveHref(path) + (hash ? '#' + hash : '');
587
-
599
+ if (hash) {
588
600
  event.preventDefault();
589
601
  event.stopPropagation();
590
602
  event.stopImmediatePropagation();
@@ -620,7 +632,6 @@ function interceptLinkClicks() {
620
632
  isInternalNavigation = true;
621
633
 
622
634
  // Update URL without page reload (use base path when app is in a subpath, e.g. /src/dist/gadget)
623
- const fullHref = resolveHref(href);
624
635
  history.pushState(null, '', fullHref);
625
636
 
626
637
  // Handle route change
@@ -16,7 +16,7 @@
16
16
 
17
17
  // Build stamps the published version here; unstamped (dev) falls back to the
18
18
  // registration URL's `v`, then 'dev'.
19
- const BUILD_VERSION = '0.5.287';
19
+ const BUILD_VERSION = '0.5.288';
20
20
  const CACHE_PREFIX = 'mnfst-sw:';
21
21
  const META_CACHE = CACHE_PREFIX + 'meta';
22
22
  // Sized to hold a full precache.json warm-up (PRECACHE_MAX_ENTRIES server-side)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst",
3
- "version": "0.5.287",
3
+ "version": "0.5.288",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",