dalila 1.5.6 → 1.5.8

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.
@@ -177,18 +177,22 @@ function bindEvents(root, ctx, events, cleanups) {
177
177
  * Bind all [d-when] directives within root
178
178
  */
179
179
  function bindWhen(root, ctx, cleanups) {
180
- const elements = qsaIncludingRoot(root, '[d-when]');
180
+ const elements = qsaIncludingRoot(root, '[when], [d-when]');
181
181
  for (const el of elements) {
182
- const bindingName = normalizeBinding(el.getAttribute('d-when'));
182
+ const attrName = el.hasAttribute('when') ? 'when' : 'd-when';
183
+ const bindingName = normalizeBinding(el.getAttribute(attrName));
183
184
  if (!bindingName)
184
185
  continue;
185
186
  const binding = ctx[bindingName];
186
187
  if (binding === undefined) {
187
- warn(`d-when: "${bindingName}" not found in context`);
188
+ warn(`when: "${bindingName}" not found in context`);
188
189
  continue;
189
190
  }
190
191
  const htmlEl = el;
191
- // Effect is owned by templateScope no need to track stop manually
192
+ // Apply initial state synchronously to avoid FOUC (flash of unstyled content)
193
+ const initialValue = !!resolve(binding);
194
+ htmlEl.style.display = initialValue ? '' : 'none';
195
+ // Then create reactive effect to keep it updated
192
196
  effect(() => {
193
197
  const value = !!resolve(binding);
194
198
  htmlEl.style.display = value ? '' : 'none';
@@ -212,9 +216,8 @@ function bindMatch(root, ctx, cleanups) {
212
216
  warn(`d-match: "${bindingName}" not found in context`);
213
217
  continue;
214
218
  }
215
- effect(() => {
216
- // Re-query cases on every run so dynamically added/removed [case]
217
- // children (e.g. via d-if) are always up to date.
219
+ // Apply initial state synchronously to avoid FOUC
220
+ const applyMatch = () => {
218
221
  const cases = Array.from(el.querySelectorAll('[case]'));
219
222
  const v = resolve(binding);
220
223
  const value = v == null ? '' : String(v);
@@ -238,6 +241,12 @@ function bindMatch(root, ctx, cleanups) {
238
241
  else if (defaultEl) {
239
242
  defaultEl.style.display = '';
240
243
  }
244
+ };
245
+ // Apply initial state
246
+ applyMatch();
247
+ // Then create reactive effect to keep it updated
248
+ effect(() => {
249
+ applyMatch();
241
250
  });
242
251
  }
243
252
  }
@@ -350,6 +359,12 @@ function bindIf(root, ctx, cleanups) {
350
359
  el.parentNode?.replaceChild(comment, el);
351
360
  el.removeAttribute('d-if');
352
361
  const htmlEl = el;
362
+ // Apply initial state synchronously to avoid FOUC
363
+ const initialValue = !!resolve(binding);
364
+ if (initialValue) {
365
+ comment.parentNode?.insertBefore(htmlEl, comment);
366
+ }
367
+ // Then create reactive effect to keep it updated
353
368
  effect(() => {
354
369
  const value = !!resolve(binding);
355
370
  if (value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dalila",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "DOM-first reactive framework based on signals",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",