mnfst 0.5.35 → 0.5.37

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.
@@ -1310,15 +1310,31 @@ function setNestedValue(obj, path, value) {
1310
1310
  for (let i = 0; i < keys.length - 1; i++) {
1311
1311
  const key = keys[i];
1312
1312
  const nextKey = keys[i + 1];
1313
+ const nextIsIndex = /^\d+$/.test(nextKey);
1314
+
1313
1315
  if (!(key in current)) {
1314
- current[key] = /^\d+$/.test(nextKey) ? [] : {};
1316
+ current[key] = nextIsIndex ? [] : {};
1317
+ } else if (nextIsIndex && !Array.isArray(current[key]) && current[key] && typeof current[key] === 'object') {
1318
+ // If we later discover this container should be an array, coerce numeric-key objects.
1319
+ const existing = current[key];
1320
+ const existingKeys = Object.keys(existing);
1321
+ const numericOnly = existingKeys.every(k => /^\d+$/.test(k));
1322
+ if (numericOnly) {
1323
+ const arr = [];
1324
+ existingKeys.forEach(k => {
1325
+ arr[parseInt(k, 10)] = existing[k];
1326
+ });
1327
+ current[key] = arr;
1328
+ }
1315
1329
  }
1330
+
1316
1331
  if (Array.isArray(current) && /^\d+$/.test(key)) {
1317
1332
  const idx = parseInt(key, 10);
1318
1333
  if (current[idx] == null || typeof current[idx] !== 'object') {
1319
- current[idx] = {};
1334
+ current[idx] = nextIsIndex ? [] : {};
1320
1335
  }
1321
1336
  }
1337
+
1322
1338
  current = current[key];
1323
1339
  }
1324
1340
 
@@ -89,6 +89,20 @@ function initializeLocalizationPlugin() {
89
89
  return rtlLanguages.has(lang);
90
90
  }
91
91
 
92
+ function isPrerenderedStaticBuild() {
93
+ return document.head?.querySelector('meta[name="manifest:prerendered"][content="1"]') !== null;
94
+ }
95
+
96
+ function buildLocaleNavigationUrl(newLang, availableLocales) {
97
+ const currentUrl = new URL(window.location.href);
98
+ const pathParts = currentUrl.pathname.split('/').filter(Boolean);
99
+ const hasLanguageInUrl = pathParts[0] && availableLocales.includes(pathParts[0]);
100
+ if (hasLanguageInUrl) pathParts[0] = newLang;
101
+ else pathParts.unshift(newLang);
102
+ currentUrl.pathname = '/' + pathParts.join('/');
103
+ return currentUrl.toString();
104
+ }
105
+
92
106
  // Input validation for language codes
93
107
  function isValidLanguageCode(lang) {
94
108
  if (typeof lang !== 'string' || lang.length === 0) return false;
@@ -313,6 +327,16 @@ function initializeLocalizationPlugin() {
313
327
 
314
328
 
315
329
  try {
330
+ // In prerendered static output, locale switching must navigate to a locale URL.
331
+ // Mutating Alpine store alone won't re-render baked static content.
332
+ if (isPrerenderedStaticBuild()) {
333
+ const targetUrl = buildLocaleNavigationUrl(newLang, store.available || []);
334
+ if (targetUrl !== window.location.href) {
335
+ window.location.assign(targetUrl);
336
+ }
337
+ return true;
338
+ }
339
+
316
340
  // Update store
317
341
  store.current = newLang;
318
342
  store.direction = isRTL(newLang) ? 'rtl' : 'ltr';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst",
3
- "version": "0.5.35",
3
+ "version": "0.5.37",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",