sygnal 6.6.0 → 7.1.0

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +258 -0
  2. package/README.md +2 -0
  3. package/dist/astro/index.cjs.js +32 -9
  4. package/dist/astro/index.cjs.js.map +1 -1
  5. package/dist/astro/index.mjs +32 -9
  6. package/dist/astro/index.mjs.map +1 -1
  7. package/dist/astro/server.cjs.js +32 -43
  8. package/dist/astro/server.cjs.js.map +1 -1
  9. package/dist/astro/server.mjs +32 -43
  10. package/dist/astro/server.mjs.map +1 -1
  11. package/dist/devtools.cjs.js.map +1 -1
  12. package/dist/devtools.esm.js.map +1 -1
  13. package/dist/diagnostics.cjs.js +154 -6
  14. package/dist/diagnostics.cjs.js.map +1 -1
  15. package/dist/diagnostics.esm.js +153 -7
  16. package/dist/diagnostics.esm.js.map +1 -1
  17. package/dist/guide/accessibility.md +3 -1
  18. package/dist/guide/ai-chat.md +6 -6
  19. package/dist/guide/behaviors.md +1 -1
  20. package/dist/guide/element-commands.md +4 -2
  21. package/dist/guide/forms-reference.md +89 -3
  22. package/dist/guide/forms.md +8 -8
  23. package/dist/guide/http.md +77 -7
  24. package/dist/guide/migrating-to-7.md +314 -0
  25. package/dist/guide/recipes/ai-summarize.md +2 -1
  26. package/dist/guide/recipes/i18n.md +1 -1
  27. package/dist/guide/resources.md +2 -0
  28. package/dist/guide/timers.md +3 -3
  29. package/dist/guide/ui/tabs.md +5 -4
  30. package/dist/guide/ui/tooltip.md +24 -0
  31. package/dist/index.cjs.js +954 -388
  32. package/dist/index.cjs.js.map +1 -1
  33. package/dist/index.d.ts +300 -46
  34. package/dist/index.esm.js +953 -389
  35. package/dist/index.esm.js.map +1 -1
  36. package/dist/sygnal.min.js +1 -1
  37. package/dist/sygnal.min.js.map +1 -1
  38. package/dist/ui.cjs.js +96 -11
  39. package/dist/ui.cjs.js.map +1 -1
  40. package/dist/ui.esm.js +96 -12
  41. package/dist/ui.esm.js.map +1 -1
  42. package/dist/vike/config/package.json +1 -1
  43. package/dist/vite/plugin.cjs.js +19 -9
  44. package/dist/vite/plugin.cjs.js.map +1 -1
  45. package/dist/vite/plugin.mjs +19 -9
  46. package/dist/vite/plugin.mjs.map +1 -1
  47. package/llms.txt +23 -22
  48. package/package.json +1 -1
  49. package/src/astro/index.d.ts +8 -0
  50. package/src/astro/index.ts +18 -0
  51. package/src/core/actions.ts +28 -21
  52. package/src/core/define.ts +2 -0
  53. package/src/core/hooks.ts +2 -2
  54. package/src/core/hosts/collection.ts +4 -3
  55. package/src/core/hosts/switchable.ts +26 -8
  56. package/src/core/instance.ts +66 -17
  57. package/src/core/runtime.ts +5 -1
  58. package/src/core/statics.ts +5 -5
  59. package/src/extra/ai/chat/behavior.ts +3 -3
  60. package/src/extra/ai/commandBar.ts +3 -3
  61. package/src/extra/ai/compose/behavior.ts +3 -3
  62. package/src/extra/ai/transports/shared.ts +10 -2
  63. package/src/extra/behaviors.ts +24 -3
  64. package/src/extra/diagnostics/checks/fetch.ts +21 -1
  65. package/src/extra/diagnostics/checks/forms.ts +4 -3
  66. package/src/extra/diagnostics/checks/index.ts +1 -0
  67. package/src/extra/diagnostics/checks/next.ts +49 -3
  68. package/src/extra/diagnostics/checks/props.ts +6 -1
  69. package/src/extra/diagnostics/checks/public.d.ts +12 -0
  70. package/src/extra/diagnostics/checks/timingAudit.ts +47 -0
  71. package/src/extra/diagnostics/codes.ts +24 -0
  72. package/src/extra/fetchDriver.ts +115 -7
  73. package/src/extra/fetchEventSource.ts +117 -0
  74. package/src/extra/form.ts +68 -26
  75. package/src/extra/formHelpers.ts +3 -1
  76. package/src/extra/lens.ts +3 -2
  77. package/src/extra/queryCache.ts +4 -3
  78. package/src/extra/socketDriver.ts +60 -9
  79. package/src/extra/ssr.ts +30 -41
  80. package/src/extra/testing.ts +100 -18
  81. package/src/extra/timers.ts +5 -2
  82. package/src/index.d.ts +299 -45
  83. package/src/index.ts +3 -0
  84. package/src/shared.ts +3 -0
  85. package/src/ui/dialog.ts +3 -2
  86. package/src/ui/tooltips.ts +92 -0
  87. package/src/ui.d.ts +35 -0
  88. package/src/ui.ts +1 -0
  89. package/src/vite/graph.ts +11 -3
  90. package/src/vite/plugin.d.ts +7 -0
  91. package/src/vite/plugin.ts +10 -5
@@ -3063,7 +3063,7 @@ function withUses(def, state) {
3063
3063
  * state reads from the cache ('success' with the cached data), else 'loading' ('idle' for a
3064
3064
  * falsy request), as the client's first paint does with the same (hydrated) cache
3065
3065
  */
3066
- function withResources(def, state) {
3066
+ function withResources(def, state, ctx) {
3067
3067
  state = withUses(def, state);
3068
3068
  const res = def && def.resources;
3069
3069
  if (!res || !state || typeof state !== 'object' || Array.isArray(state))
@@ -3074,7 +3074,7 @@ function withResources(def, state) {
3074
3074
  continue;
3075
3075
  let q;
3076
3076
  try {
3077
- q = typeof res[n] === 'function' ? res[n](state) : res[n];
3077
+ q = typeof res[n] === 'function' ? res[n](state, ctx) : res[n];
3078
3078
  }
3079
3079
  catch (_) { }
3080
3080
  const E = q && ssrCache ? ssrCache.get(ssrCache.key(q, 1)) : undefined;
@@ -3121,15 +3121,33 @@ function viewFailed(def, err, name) {
3121
3121
  }
3122
3122
  return vnode;
3123
3123
  }
3124
- function collectHead(def, state) {
3124
+ function collectHead(def, state, ctx) {
3125
3125
  const h = def && def.head;
3126
3126
  if (!heads || !h)
3127
3127
  return;
3128
3128
  try {
3129
- heads.push(typeof h === 'function' ? h(state) : h);
3129
+ heads.push(typeof h === 'function' ? h(state, ctx) : h);
3130
3130
  }
3131
3131
  catch (_) { }
3132
3132
  }
3133
+ /**
3134
+ * PLAN-13 F-1: the context a component sees (its parent's, plus its own entries computed on
3135
+ * `state`). The statics get it as on the client; for `resources` it is computed on the state
3136
+ * before the resources are filled in (a context entry can't read the component's own resource)
3137
+ */
3138
+ function contextOf(def, state, parent) {
3139
+ const own = def.context || {}, out = { ...parent };
3140
+ for (const key of Object.keys(own)) {
3141
+ const f = own[key];
3142
+ if (typeof f === 'function' && state != null) {
3143
+ try {
3144
+ out[key] = f(state);
3145
+ }
3146
+ catch (_) { }
3147
+ }
3148
+ }
3149
+ return out;
3150
+ }
3133
3151
  /**
3134
3152
  * Render a Sygnal component to an HTML string.
3135
3153
  *
@@ -3170,20 +3188,10 @@ function renderRoot(componentDef, options) {
3170
3188
  const uid = (options.uid || 'u').replace(/[^\w-]+/g, '_');
3171
3189
  const ownState = state !== undefined ? state : componentDef.initialState;
3172
3190
  // 5-5: the view sees its resources; the hydration script keeps the state as it was given
3173
- const resolvedState = withResources(componentDef, ownState);
3174
- collectHead(componentDef, resolvedState);
3191
+ const resolvedState = withResources(componentDef, ownState, contextOf(componentDef, ownState, context));
3175
3192
  // Build context: merge parent context with component's own context definitions
3176
- const componentContext = componentDef.context || {};
3177
- const mergedContext = { ...context };
3178
- for (const key of Object.keys(componentContext)) {
3179
- const contextFn = componentContext[key];
3180
- if (typeof contextFn === 'function' && resolvedState != null) {
3181
- try {
3182
- mergedContext[key] = contextFn(resolvedState);
3183
- }
3184
- catch (_) { }
3185
- }
3186
- }
3193
+ const mergedContext = contextOf(componentDef, resolvedState, context);
3194
+ collectHead(componentDef, resolvedState, mergedContext);
3187
3195
  // Call the view function
3188
3196
  let vnode;
3189
3197
  try {
@@ -3394,19 +3402,9 @@ function renderSubComponent(vnode, context, parentState, uid) {
3394
3402
  // State passed directly
3395
3403
  childState = stateProp;
3396
3404
  }
3397
- childState = withResources(componentDef, childState);
3405
+ childState = withResources(componentDef, childState, contextOf(componentDef, childState, context));
3398
3406
  // Build child context
3399
- const childContext = { ...context };
3400
- const componentContext = componentDef.context || {};
3401
- for (const key of Object.keys(componentContext)) {
3402
- const contextFn = componentContext[key];
3403
- if (typeof contextFn === 'function' && childState != null) {
3404
- try {
3405
- childContext[key] = contextFn(childState);
3406
- }
3407
- catch (_) { }
3408
- }
3409
- }
3407
+ const childContext = contextOf(componentDef, childState, context);
3410
3408
  // Extract slots from children
3411
3409
  const slots = {};
3412
3410
  const defaultSlotChildren = [];
@@ -3428,7 +3426,7 @@ function renderSubComponent(vnode, context, parentState, uid) {
3428
3426
  slots.default = [];
3429
3427
  slots.default.push(...defaultSlotChildren);
3430
3428
  }
3431
- collectHead(componentDef, childState);
3429
+ collectHead(componentDef, childState, childContext);
3432
3430
  // Call the view function
3433
3431
  let result;
3434
3432
  try {
@@ -3645,19 +3643,10 @@ function renderSwitchable(vnode, context, parentState, uid) {
3645
3643
  * Internal helper: render a component def to a VNode (not HTML string).
3646
3644
  */
3647
3645
  function renderToStringInternal(componentDef, state, context, uid) {
3648
- const resolvedState = withResources(componentDef, state !== undefined ? state : componentDef.initialState);
3649
- const componentContext = componentDef.context || {};
3650
- const mergedContext = { ...context };
3651
- for (const key of Object.keys(componentContext)) {
3652
- const contextFn = componentContext[key];
3653
- if (typeof contextFn === 'function' && resolvedState != null) {
3654
- try {
3655
- mergedContext[key] = contextFn(resolvedState);
3656
- }
3657
- catch (_) { }
3658
- }
3659
- }
3660
- collectHead(componentDef, resolvedState);
3646
+ const own = state !== undefined ? state : componentDef.initialState;
3647
+ const resolvedState = withResources(componentDef, own, contextOf(componentDef, own, context));
3648
+ const mergedContext = contextOf(componentDef, resolvedState, context);
3649
+ collectHead(componentDef, resolvedState, mergedContext);
3661
3650
  let vnode;
3662
3651
  try {
3663
3652
  vnode = componentDef({