mnfst 0.5.239 → 0.5.241

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.239';
5
+ const MANIFEST_BUILD_VERSION = '0.5.241';
6
6
 
7
7
  /* Manifest Data Sources - Appwrite Integration */
8
8
 
@@ -205,6 +205,46 @@ function escapeForSingleQuotedJsString(s) {
205
205
  // Framework web components (not project components) — never fetched.
206
206
  const FRAMEWORK_COMPONENT_TAGS = new Set(['code', 'code-group']);
207
207
 
208
+ // The <template x-if>/<template x-for> whose tracked clone is `el`, if any.
209
+ function findOwningTemplate(el) {
210
+ if (!el._x_dataStack) return null;
211
+ for (let n = el.previousElementSibling; n; n = n.previousElementSibling) {
212
+ if (n.tagName !== 'TEMPLATE') continue;
213
+ if (n._x_currentIfEl === el) return { tpl: n, type: 'if' };
214
+ const lookup = el._x_refreshXForScope && n._x_lookup;
215
+ if (lookup) {
216
+ // Map since Alpine 3.16, plain object before
217
+ const entries = lookup instanceof Map ? lookup : Object.entries(lookup);
218
+ for (const [key, value] of entries) if (value === el) return { tpl: n, type: 'for', key };
219
+ }
220
+ }
221
+ return null;
222
+ }
223
+
224
+ // Point Alpine's clone bookkeeping at the swapped-in node.
225
+ function repointTemplateClone(owner, placeholder, node) {
226
+ const { tpl } = owner;
227
+ if (owner.type === 'if') {
228
+ const undo = tpl._x_undoIf;
229
+ tpl._x_currentIfEl = node;
230
+ tpl._x_lastRenderedEl = node;
231
+ tpl._x_undoIf = () => {
232
+ const A = window.Alpine;
233
+ const teardown = () => {
234
+ if (A && A.destroyTree) A.destroyTree(node);
235
+ node.remove();
236
+ };
237
+ A && A.mutateDom ? A.mutateDom(teardown) : teardown();
238
+ if (undo) undo();
239
+ };
240
+ } else {
241
+ if (tpl._x_lookup instanceof Map) tpl._x_lookup.set(owner.key, node);
242
+ else tpl._x_lookup[owner.key] = node;
243
+ node._x_refreshXForScope = placeholder._x_refreshXForScope;
244
+ if (tpl._x_lastRenderedEl === placeholder) tpl._x_lastRenderedEl = node;
245
+ }
246
+ }
247
+
208
248
  window.ManifestComponentsProcessor = {
209
249
  async processComponent(element, instanceId) {
210
250
  const name = element.tagName.toLowerCase().replace('x-', '');
@@ -238,7 +278,7 @@ window.ManifestComponentsProcessor = {
238
278
  }
239
279
  const container = document.createElement('div');
240
280
  container.innerHTML = content.trim();
241
- const topLevelElements = Array.from(container.children);
281
+ let topLevelElements = Array.from(container.children);
242
282
  if (topLevelElements.length === 0) {
243
283
  console.debug('[Manifest Components] skipped: empty component template', element);
244
284
  element.replaceWith(document.createComment(` Empty component: ${name} `));
@@ -263,6 +303,7 @@ window.ManifestComponentsProcessor = {
263
303
  }
264
304
  };
265
305
  topLevelElements.forEach(processScripts);
306
+ topLevelElements = Array.from(container.children);
266
307
  // Collect properties from placeholder attributes
267
308
  const props = {};
268
309
  Array.from(element.attributes).forEach(attr => {
@@ -464,7 +505,23 @@ window.ManifestComponentsProcessor = {
464
505
  const fragment = document.createDocumentFragment();
465
506
  topLevelElements.forEach(el => fragment.appendChild(el));
466
507
 
467
- parent.replaceChild(fragment, element);
508
+ // Sole child of x-if/x-for: Alpine tracks one node per clone, so a
509
+ // multi-root component keeps a host; the clone's scope carries over.
510
+ const owner = findOwningTemplate(element);
511
+ let swapped = fragment;
512
+ if (owner && topLevelElements.length) {
513
+ swapped = topLevelElements[0];
514
+ if (topLevelElements.length > 1) {
515
+ swapped = document.createElement(element.tagName.toLowerCase());
516
+ swapped.setAttribute('data-processed', '');
517
+ swapped.style.display = 'contents';
518
+ swapped.appendChild(fragment);
519
+ }
520
+ swapped._x_dataStack = element.hasAttribute('x-data') ? element._x_dataStack.slice(1) : element._x_dataStack;
521
+ repointTemplateClone(owner, element, swapped);
522
+ }
523
+
524
+ parent.replaceChild(swapped, element);
468
525
 
469
526
  // Manually init Alpine on the swapped-in elements once magic methods are
470
527
  // ready — prevents "i is not a function" errors.
@@ -2,7 +2,7 @@
2
2
 
3
3
  (function () {
4
4
 
5
- const MANIFEST_BUILD_VERSION = '0.5.239';
5
+ const MANIFEST_BUILD_VERSION = '0.5.241';
6
6
 
7
7
  /* Manifest Data Sources - Configuration */
8
8
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "manifest.appwrite.auth.js": "sha384-dsIWnH0qCAGSzAXMGrd8fvOrVl4tOIE6j5tC35JPTrQXZ56qLD36ARyvhR7vi3Id",
3
- "manifest.appwrite.data.js": "sha384-w085pnH0O67PcfKoFDex8duuZxAHkFsG0DDTE5KjXRL/XGcC1VEySE2R6JS13StI",
3
+ "manifest.appwrite.data.js": "sha384-sgQZQ0N9h/lO7AhAsfGyMKMD2Wr6IqnAmpeM901SnVVognyG7vNTHlRlQZ23k55f",
4
4
  "manifest.appwrite.presences.js": "sha384-JyVDWFT69b7Svq8J8p9tNWe2v9PZNQBY5UyhtOl1vnuHFAX0CRQ3MA9SiKq5wzNh",
5
5
  "manifest.bindings.js": "sha384-lPtMf8Ykaic9gNVZKq8Scia1881ZeMAyxer3WCIkUNwwrgzGBWto1OXADUwjvORF",
6
6
  "manifest.charts.js": "sha384-gEAv/98+29RbhvNkiNWTNyBPbLTFr2Ld15wLu29FLCL57j1cwGChRrL9Pfk7dBtT",
@@ -9,9 +9,9 @@
9
9
  "manifest.color.js": "sha384-6Rv3LxyTcZNjrhtayQfqRdCx0uSZ4BiEbgEI98I62eTvp8Aw7LBIoNJ0Je1oktwL",
10
10
  "manifest.colorpicker.js": "sha384-BhcCe8cGcd0DTJNwzXWWY+FQNRfSFFl6XqfHIFP8yHg/aXFks1NIC6lVx0Sr1VkM",
11
11
  "manifest.combobox.js": "sha384-MILTkrgsTzsYUjGo4ZuADqV85Xs4GmfB4xexfe9vbJMIoQTZ42W4zs+DTaVSPEsx",
12
- "manifest.components.js": "sha384-JalISaBBWNFl3ggx92Hb3B52EpwwG3gzgra6Q+js0OgZ8vrFKMD48CuBox2N9A5T",
12
+ "manifest.components.js": "sha384-BUFA8h+G5Plr82sV7bKzO42pPoiRZwRQcKj1lt2ROFiKjjlkayU/vmkAFqEsdBA+",
13
13
  "manifest.computed.js": "sha384-GYML/e81gQfN+iDbqhPUgny8bINCyL+SrbTofoGk4hlCnLLjv51mCv42JMqq+ku5",
14
- "manifest.data.js": "sha384-pH87i9EvgVGUlA6IelcAxxYpoIfmhd8VrnaThttDBMLzbiXir0w8/wDYkBxEzShS",
14
+ "manifest.data.js": "sha384-ouJ2qNBcbZ/TWGxbzOn3bk3pNqmEJFoiHC3z9/mIaqOmoa6v10lT0VasaxV/NdWD",
15
15
  "manifest.datepicker.js": "sha384-XnbeURni2X91ozVzatQcSjYYIS4MoW12dBRJnYAGBr0nCQ624heH5s+xtQSpLZX6",
16
16
  "manifest.defer.js": "sha384-pMRGqQKiEoJhpUcD40QeM4jEHau7sz9Xn/YCpiUamT1T4xJBZDSiYX+xnVrSWoq+",
17
17
  "manifest.device.js": "sha384-g+txmrEszYtuOvRelTp/c1wSNR2AtllVI9rx5NPPD7DzhVUnMNughonZykv2xlBW",
@@ -28,7 +28,7 @@
28
28
  "manifest.slides.js": "sha384-3uRTkyK9XPLmnxI2+igZlpi4EyPlU/7IHj5j3BZJJ2KN455vXyk99fiXV3feO/XY",
29
29
  "manifest.status.js": "sha384-MBO345ab7H6Uq1X2dZLt4Ge1Gcra+Z2qYApvlAeIV8CJhDDJrz2FPXpp+Kcp8zcM",
30
30
  "manifest.svg.js": "sha384-qr/8H9+2cIhSXNbRWRtIdrDlTOxKlNJqwEefHvCYoiBNW/kKhPTFa109Orv/EBnb",
31
- "manifest.sw.js": "sha384-y83uBPdyVvejS/1ESbzxrKpWDLtTCySZzdTe+447FkD9EIDKLBo2kD9HNDRGD2Zk",
31
+ "manifest.sw.js": "sha384-E3aYupr1VZ53KD9CbSp6EjOkAUHNydBDWsmb6KWe3SJ6Rn7W72gQ21GtPVB/ChFu",
32
32
  "manifest.tabs.js": "sha384-OIIcyaQnGS0eNYk4zgAFEDboNYect7THvUd9D0V6nqCeDOxQcoiqLrBEmmWVTTet",
33
33
  "manifest.tailwind.js": "sha384-r/Jvqb+Piz21jUts10BbVAJoKkShOdJRVFpywyi4HPIi/OfOJq5CtPyWAPbdkMgt",
34
34
  "manifest.toasts.js": "sha384-3zkWxzw693pxg3QDFsoYCA3CqYaLKmBaMArULXODD66Utolpewl0OAeTB92aWUVv",
@@ -36,5 +36,5 @@
36
36
  "manifest.url.parameters.js": "sha384-J2aSVBOPsoqsbafHndrWLHEDpKb4AKJAoQnVmKA4gZh5P/8HHjFWHO/lkusmG84l",
37
37
  "manifest.utilities.js": "sha384-L5uXMLFBIF6LUM1haRjd4eGjHSWuqsCYSpPZRPYosNfJsMC5U5TnmjBxIhrZRe2d",
38
38
  "manifest.virtual.js": "sha384-ZDNoF9QVhVcVpkjIK6NH15S6I5c6OBshiJpXSOYjNsIB+298I0a7g3aFO+jyq4Vb",
39
- "manifest.js": "sha384-m5WiqHv+23ZnBvvIt9NtUGE2Gupaw9jDpKuonIH9HZCHc+LR8wbitDImJoNPH9CI"
39
+ "manifest.js": "sha384-AvD8QPahsOp5hmdBGJtfu2jp/dYrxLgapvAzx0oc2POlfb/Gj1tvFBHG+ct76p3d"
40
40
  }
package/lib/manifest.js CHANGED
@@ -124,43 +124,139 @@
124
124
  /*
125
125
  * Reconcile baked x-for/x-if clones kept for crawlers — their <template> is still
126
126
  * live, so Alpine would render duplicates. x-if clones are adopted via
127
- * `_x_currentIfEl` (avoids re-rendering heavy content); x-for clones are removed.
127
+ * `_x_currentIfEl` (avoids re-rendering heavy content) and stay inert until
128
+ * their guard holds; x-for clones are removed.
128
129
  * Runs on alpine:init so a page without Alpine keeps its baked content.
129
130
  */
131
+ const adoptedIfs = new Set();
132
+ const adoptedTpls = new WeakSet();
133
+ let settleQueued = false;
134
+ function settleAdopted() {
135
+ for (const a of [...adoptedIfs]) a.settle();
136
+ }
137
+ function queueSettle() {
138
+ if (settleQueued) return;
139
+ settleQueued = true;
140
+ queueMicrotask(() => { settleQueued = false; settleAdopted(); });
141
+ }
142
+ function underIgnore(node) {
143
+ for (let n = node.parentNode; n; n = n.parentNode) if (n._x_ignore) return true;
144
+ return false;
145
+ }
130
146
  function adoptIfClone(tpl, el) {
131
147
  const A = window.Alpine;
132
- // Mirrors Alpine's x-if show() bookkeeping.
148
+ const expr = tpl.getAttribute('x-if');
149
+ // No Alpine root above: never walked, so the clone binds as before.
150
+ let live = !tpl.closest('[x-data],[x-init]');
151
+ let pending = false;
152
+ let stopWatch = null;
153
+ const guard = () => !!A.evaluate(tpl, expr);
154
+ const unwatch = () => {
155
+ if (stopWatch) { stopWatch(); stopWatch = null; }
156
+ };
157
+ const forget = () => {
158
+ adoptedIfs.delete(entry);
159
+ unwatch();
160
+ };
161
+ // On screen, unbound, until a settle or an outer activation.
162
+ const park = () => {
163
+ live = false;
164
+ pending = false;
165
+ unwatch();
166
+ el._x_ignore = true;
167
+ adoptedIfs.add(entry);
168
+ };
169
+ // Mirrors Alpine's x-if hide() bookkeeping.
133
170
  const undo = () => {
171
+ forget();
134
172
  A.mutateDom(() => {
135
173
  A.destroyTree(el);
136
174
  el.remove();
137
175
  });
138
176
  delete tpl._x_currentIfEl;
139
177
  delete tpl._x_lastRenderedEl;
178
+ queueSettle();
140
179
  };
141
- // Boot-time false (e.g. data still loading) keeps the clone until
142
- // manifest:ready, then removes it only if still false — no blank frame.
143
- let pending = false;
180
+ // Bound only while the guard holds; adopted clones inside follow.
181
+ const activate = () => {
182
+ if (live || tpl._x_currentIfEl !== el || !el.isConnected || underIgnore(tpl)) return;
183
+ live = true;
184
+ pending = false;
185
+ forget();
186
+ delete el._x_ignore;
187
+ A.initTree(el);
188
+ settleAdopted();
189
+ };
190
+ const watch = () => {
191
+ if (stopWatch || !pending || tpl._x_currentIfEl !== el || underIgnore(tpl)) return;
192
+ const check = A.evaluateLater(tpl, expr);
193
+ const fx = A.effect(() => check((v) => { if (v) queueMicrotask(() => { if (pending && guard()) activate(); }); }));
194
+ stopWatch = () => A.release(fx);
195
+ };
196
+ const entry = {
197
+ settle() {
198
+ if (live || pending) return;
199
+ if (tpl._x_currentIfEl !== el) return forget();
200
+ if (!el.isConnected) {
201
+ // Stashed in a template (defer) waits; removed with an ancestor is dropped.
202
+ if (!(el.getRootNode() instanceof DocumentFragment)) forget();
203
+ return;
204
+ }
205
+ if (tpl._x_marker && !underIgnore(tpl) && guard()) activate();
206
+ },
207
+ };
208
+ // Boot-time false (e.g. data still loading) keeps the clone on screen,
209
+ // unbound, until the guard holds or manifest:ready — no blank frame.
144
210
  const adoptedUndo = () => {
145
211
  if (window.__manifestReady || !window.__manifestReadyCoordinator) return undo();
146
- queueMicrotask(() => { if (tpl._x_currentIfEl === el) tpl._x_undoIf = adoptedUndo; });
212
+ queueMicrotask(() => {
213
+ if (tpl._x_currentIfEl !== el) return;
214
+ tpl._x_undoIf = adoptedUndo;
215
+ watch();
216
+ });
217
+ // Torn down with an outer clone: its guard may no longer evaluate.
218
+ if (underIgnore(tpl)) return park();
219
+ if (live) {
220
+ live = false;
221
+ el._x_ignore = true;
222
+ A.destroyTree(el);
223
+ adoptedIfs.add(entry);
224
+ }
147
225
  if (pending) return;
148
226
  pending = true;
149
227
  window.addEventListener('manifest:ready', () => {
150
- if (tpl._x_currentIfEl !== el) return;
151
- if (!tpl.isConnected || !A.evaluate(tpl, tpl.getAttribute('x-if'))) {
152
- undo();
153
- delete tpl._x_undoIf;
154
- }
228
+ if (!pending || tpl._x_currentIfEl !== el) return;
229
+ if (tpl.isConnected && underIgnore(tpl)) return park();
230
+ if (tpl.isConnected && guard()) return activate();
231
+ undo();
232
+ delete tpl._x_undoIf;
155
233
  }, { once: true });
156
234
  };
157
235
  tpl._x_currentIfEl = el;
158
236
  tpl._x_lastRenderedEl = el;
159
237
  tpl._x_undoIf = adoptedUndo;
238
+ adoptedTpls.add(tpl);
239
+ if (!live) {
240
+ el._x_ignore = true;
241
+ adoptedIfs.add(entry);
242
+ }
243
+ }
244
+ // Older renders marked placeholders inside x-if/x-for content; clones must swap.
245
+ function unmarkTemplatePlaceholders(root, inside) {
246
+ root.querySelectorAll('template').forEach((tpl) => {
247
+ const authored = inside || tpl.matches('[x-if],[x-for]');
248
+ if (authored) {
249
+ tpl.content.querySelectorAll('[data-pre-rendered]').forEach((el) => {
250
+ if (el.tagName.startsWith('X-')) el.removeAttribute('data-pre-rendered');
251
+ });
252
+ }
253
+ unmarkTemplatePlaceholders(tpl.content, authored);
254
+ });
160
255
  }
161
256
  function reconcilePrerenderClones() {
162
257
  if (typeof document === 'undefined' || !document.querySelectorAll) return;
163
- const adopted = [];
258
+ unmarkTemplatePlaceholders(document);
259
+ let adopted = 0;
164
260
  document.querySelectorAll('[data-mnfst-prerender-clone]').forEach((el) => {
165
261
  if (el.closest && el.closest('[data-hydrate]')) return;
166
262
  el.removeAttribute('data-mnfst-prerender-clone');
@@ -168,20 +264,20 @@
168
264
  if (tpl && tpl.tagName === 'TEMPLATE' && tpl.hasAttribute('x-if')) {
169
265
  // Alpine's x-if show() returns early when _x_currentIfEl is set.
170
266
  adoptIfClone(tpl, el);
171
- adopted.push([tpl, el]);
267
+ adopted++;
172
268
  } else {
173
269
  el.remove();
174
270
  }
175
271
  });
176
- if (!adopted.length) return;
177
- // Clones the start walk missed: init once (initTree skips marked nodes).
178
- document.addEventListener('alpine:initialized', () => {
179
- for (const [tpl, el] of adopted) {
180
- if (tpl._x_marker && tpl._x_currentIfEl === el && el.isConnected && !el._x_marker) {
181
- window.Alpine.initTree(el);
182
- }
183
- }
184
- }, { once: true });
272
+ if (!adopted) return;
273
+ const A = window.Alpine;
274
+ // Templates walked after start (deferred subtrees) settle once their x-if ran.
275
+ if (typeof A.interceptInit === 'function') {
276
+ A.interceptInit((node) => {
277
+ if (adoptedTpls.has(node) && adoptedIfs.size) queueSettle();
278
+ });
279
+ }
280
+ document.addEventListener('alpine:initialized', settleAdopted, { once: true });
185
281
  }
186
282
  if (typeof document !== 'undefined') {
187
283
  document.addEventListener('alpine:init', reconcilePrerenderClones, { once: true });
@@ -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.239';
19
+ const BUILD_VERSION = '0.5.241';
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.239",
3
+ "version": "0.5.241",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",