@kayjs/kay 1.109.0 → 1.111.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 (199) hide show
  1. package/dist/eslint.js +488 -75
  2. package/editors/zed/extension.toml +2 -2
  3. package/llms/actions-from-islands.md +1 -1
  4. package/llms/build-and-start.md +1 -1
  5. package/llms/checks.md +1 -0
  6. package/llms/component-libraries.md +1 -1
  7. package/llms/components.md +1 -1
  8. package/llms/deprecated-lints.md +1 -1
  9. package/llms/dev-tool.md +1 -1
  10. package/llms/effects.md +1 -0
  11. package/llms/head.md +1 -1
  12. package/llms/images.md +2 -0
  13. package/llms/island-and-form-lints.md +2 -1
  14. package/llms/islands-lazy-components.md +23 -0
  15. package/llms/islands.md +4 -14
  16. package/llms/lints.md +1 -1
  17. package/llms/live-values.md +1 -1
  18. package/llms/navigation-from-code.md +1 -1
  19. package/llms/navigation.md +5 -3
  20. package/llms/performance-lints.md +1 -0
  21. package/llms/prerendering.md +1 -1
  22. package/llms/project-new-and-add.md +1 -1
  23. package/llms/project.md +1 -1
  24. package/llms/templates-elements-slots-snippets.md +4 -4
  25. package/llms/upgrading-archive.md +121 -42
  26. package/llms/upgrading.md +17 -133
  27. package/llms/whats-new-archive.md +31 -31
  28. package/llms/whats-new.md +45 -30
  29. package/llms.txt +3 -2
  30. package/package.json +11 -11
  31. package/src/build/client.ts +10 -8
  32. package/src/build/island-images.ts +277 -0
  33. package/src/build/pipeline.ts +10 -4
  34. package/src/build/static.ts +99 -24
  35. package/src/build/variants.ts +132 -18
  36. package/src/check/env-types.ts +1 -1
  37. package/src/check/project.ts +4 -0
  38. package/src/check/schema-builders.ts +230 -26
  39. package/src/check/shadow-types.ts +3 -3
  40. package/src/commands/upgrade.ts +2 -1
  41. package/src/compiler/allow-comments.ts +38 -2
  42. package/src/compiler/ast.ts +4 -4
  43. package/src/compiler/codegen.ts +4 -4
  44. package/src/compiler/deprecated-lints-1-106.ts +2 -2
  45. package/src/compiler/dom.ts +4 -3
  46. package/src/compiler/hand-parts.ts +36 -8
  47. package/src/compiler/handed-data.ts +15 -0
  48. package/src/compiler/helper-imports.ts +2 -2
  49. package/src/compiler/html.ts +3 -7
  50. package/src/compiler/index.ts +7 -4
  51. package/src/compiler/island-arguments.ts +9 -0
  52. package/src/compiler/island-lints.ts +7 -0
  53. package/src/compiler/items.ts +174 -0
  54. package/src/compiler/jsx.ts +10 -11
  55. package/src/compiler/kay-exports.ts +1 -0
  56. package/src/compiler/lints.ts +6 -7
  57. package/src/compiler/markup.ts +26 -24
  58. package/src/compiler/names.ts +1 -1
  59. package/src/compiler/removed-lints.ts +90 -0
  60. package/src/compiler/rewrite-types.ts +2 -0
  61. package/src/compiler/rewrite.ts +4 -2
  62. package/src/compiler/route-lints.ts +8 -0
  63. package/src/compiler/signal-from-prop.ts +141 -0
  64. package/src/compiler/template-reads.ts +16 -0
  65. package/src/compiler/template-walk.ts +2 -1
  66. package/src/config-shape.ts +4 -1
  67. package/src/config.ts +2 -2
  68. package/src/new.ts +16 -4
  69. package/src/project.ts +3 -3
  70. package/src/runtime/await.server.ts +4 -2
  71. package/src/runtime/checks.ts +14 -2
  72. package/src/runtime/client.ts +5 -9
  73. package/src/runtime/dev-tab-env.ts +28 -3
  74. package/src/runtime/dom-loop.ts +2 -4
  75. package/src/runtime/dom.ts +2 -2
  76. package/src/runtime/html.ts +53 -7
  77. package/src/runtime/image.ts +24 -23
  78. package/src/runtime/index.ts +2 -2
  79. package/src/runtime/island.server.ts +41 -11
  80. package/src/runtime/navigate.ts +14 -0
  81. package/src/runtime/navigation.ts +9 -1
  82. package/src/runtime/page-swap.ts +6 -3
  83. package/src/runtime/reactive.ts +72 -0
  84. package/src/runtime/row-key.ts +4 -0
  85. package/src/runtime/swap-flight.ts +10 -10
  86. package/src/runtime/swap-focus.ts +56 -9
  87. package/src/runtime/swap-kept.ts +97 -29
  88. package/src/runtime/swap-morph.ts +49 -9
  89. package/src/runtime/text-hash.ts +17 -0
  90. package/src/runtime/uid.server.ts +6 -4
  91. package/src/runtime/values.ts +12 -0
  92. package/src/server/client.ts +3 -0
  93. package/src/server/dev.ts +2 -0
  94. package/src/server/image.ts +1 -1
  95. package/src/server/kept-exports.ts +1 -0
  96. package/src/server/render-document.ts +11 -8
  97. package/src/server/render.ts +3 -3
  98. package/types/build/client.d.ts +6 -0
  99. package/types/build/client.d.ts.map +1 -1
  100. package/types/build/island-images.d.ts +45 -0
  101. package/types/build/island-images.d.ts.map +1 -0
  102. package/types/build/pipeline.d.ts.map +1 -1
  103. package/types/build/static.d.ts.map +1 -1
  104. package/types/build/variants.d.ts +9 -1
  105. package/types/build/variants.d.ts.map +1 -1
  106. package/types/check/project.d.ts.map +1 -1
  107. package/types/check/schema-builders.d.ts.map +1 -1
  108. package/types/commands/upgrade.d.ts.map +1 -1
  109. package/types/compiler/allow-comments.d.ts +2 -0
  110. package/types/compiler/allow-comments.d.ts.map +1 -1
  111. package/types/compiler/ast.d.ts +1 -1
  112. package/types/compiler/ast.d.ts.map +1 -1
  113. package/types/compiler/deprecated-lints-1-106.d.ts +2 -2
  114. package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
  115. package/types/compiler/deprecated-lints.d.ts +2 -2
  116. package/types/compiler/dom.d.ts.map +1 -1
  117. package/types/compiler/hand-parts.d.ts +6 -3
  118. package/types/compiler/hand-parts.d.ts.map +1 -1
  119. package/types/compiler/handed-data.d.ts +5 -0
  120. package/types/compiler/handed-data.d.ts.map +1 -0
  121. package/types/compiler/html.d.ts.map +1 -1
  122. package/types/compiler/index.d.ts.map +1 -1
  123. package/types/compiler/island-arguments.d.ts +5 -0
  124. package/types/compiler/island-arguments.d.ts.map +1 -1
  125. package/types/compiler/island-lints.d.ts +7 -0
  126. package/types/compiler/island-lints.d.ts.map +1 -1
  127. package/types/compiler/items.d.ts +14 -0
  128. package/types/compiler/items.d.ts.map +1 -1
  129. package/types/compiler/jsx.d.ts.map +1 -1
  130. package/types/compiler/kay-exports.d.ts.map +1 -1
  131. package/types/compiler/lints.d.ts +20 -5
  132. package/types/compiler/lints.d.ts.map +1 -1
  133. package/types/compiler/markup.d.ts +3 -1
  134. package/types/compiler/markup.d.ts.map +1 -1
  135. package/types/compiler/names.d.ts.map +1 -1
  136. package/types/compiler/removed-lints.d.ts +3 -0
  137. package/types/compiler/removed-lints.d.ts.map +1 -0
  138. package/types/compiler/rewrite-types.d.ts +1 -0
  139. package/types/compiler/rewrite-types.d.ts.map +1 -1
  140. package/types/compiler/route-lints.d.ts +8 -0
  141. package/types/compiler/route-lints.d.ts.map +1 -1
  142. package/types/compiler/signal-from-prop.d.ts +4 -0
  143. package/types/compiler/signal-from-prop.d.ts.map +1 -0
  144. package/types/compiler/template-reads.d.ts +1 -0
  145. package/types/compiler/template-reads.d.ts.map +1 -1
  146. package/types/compiler/template-walk.d.ts.map +1 -1
  147. package/types/config-shape.d.ts.map +1 -1
  148. package/types/config.d.ts +3 -1
  149. package/types/config.d.ts.map +1 -1
  150. package/types/new.d.ts.map +1 -1
  151. package/types/project.d.ts +2 -2
  152. package/types/project.d.ts.map +1 -1
  153. package/types/runtime/await.server.d.ts.map +1 -1
  154. package/types/runtime/checks.d.ts +8 -2
  155. package/types/runtime/checks.d.ts.map +1 -1
  156. package/types/runtime/client.d.ts.map +1 -1
  157. package/types/runtime/dev-tab-env.d.ts.map +1 -1
  158. package/types/runtime/dom-loop.d.ts +2 -1
  159. package/types/runtime/dom-loop.d.ts.map +1 -1
  160. package/types/runtime/dom.d.ts +2 -2
  161. package/types/runtime/dom.d.ts.map +1 -1
  162. package/types/runtime/html.d.ts +6 -3
  163. package/types/runtime/html.d.ts.map +1 -1
  164. package/types/runtime/image.d.ts.map +1 -1
  165. package/types/runtime/index.d.ts +2 -2
  166. package/types/runtime/index.d.ts.map +1 -1
  167. package/types/runtime/island.server.d.ts +1 -0
  168. package/types/runtime/island.server.d.ts.map +1 -1
  169. package/types/runtime/navigate.d.ts.map +1 -1
  170. package/types/runtime/navigation.d.ts +4 -0
  171. package/types/runtime/navigation.d.ts.map +1 -1
  172. package/types/runtime/reactive.d.ts +5 -0
  173. package/types/runtime/reactive.d.ts.map +1 -1
  174. package/types/runtime/row-key.d.ts +2 -0
  175. package/types/runtime/row-key.d.ts.map +1 -0
  176. package/types/runtime/swap-flight.d.ts +1 -1
  177. package/types/runtime/swap-flight.d.ts.map +1 -1
  178. package/types/runtime/swap-focus.d.ts +2 -0
  179. package/types/runtime/swap-focus.d.ts.map +1 -1
  180. package/types/runtime/swap-kept.d.ts.map +1 -1
  181. package/types/runtime/swap-morph.d.ts.map +1 -1
  182. package/types/runtime/text-hash.d.ts +2 -0
  183. package/types/runtime/text-hash.d.ts.map +1 -0
  184. package/types/runtime/uid.server.d.ts.map +1 -1
  185. package/types/runtime/values.d.ts +4 -0
  186. package/types/runtime/values.d.ts.map +1 -1
  187. package/types/server/app-stages.d.ts +3 -1
  188. package/types/server/app-stages.d.ts.map +1 -1
  189. package/types/server/app.d.ts +3 -1
  190. package/types/server/app.d.ts.map +1 -1
  191. package/types/server/client.d.ts +2 -0
  192. package/types/server/client.d.ts.map +1 -1
  193. package/types/server/dev.d.ts +1 -0
  194. package/types/server/dev.d.ts.map +1 -1
  195. package/types/server/kept-exports.d.ts.map +1 -1
  196. package/types/server/render-document.d.ts +1 -1
  197. package/types/server/render-document.d.ts.map +1 -1
  198. package/types/server/render.d.ts +2 -2
  199. package/types/server/render.d.ts.map +1 -1
@@ -0,0 +1,90 @@
1
+ // The lints kay has removed, each with the form it reported gone: a `lints` entry naming one still loads, `kay check` says to remove it, and it changes nothing.
2
+ export const REMOVED_LINTS = [
3
+ 'deprecated-action-readers',
4
+ 'deprecated-action-type',
5
+ 'deprecated-ai-labels',
6
+ 'deprecated-ai-language',
7
+ 'deprecated-ai-links',
8
+ 'deprecated-ai-options',
9
+ 'deprecated-ai-props',
10
+ 'deprecated-analytics-options',
11
+ 'deprecated-app-hooks',
12
+ 'deprecated-auth-methods',
13
+ 'deprecated-auth-rate-limits',
14
+ 'deprecated-auth-signed',
15
+ 'deprecated-await-consent',
16
+ 'deprecated-call-result',
17
+ 'deprecated-callback-handler',
18
+ 'deprecated-children-prop',
19
+ 'deprecated-client-keys',
20
+ 'deprecated-cms-options',
21
+ 'deprecated-cms-test-helpers',
22
+ 'deprecated-config-groups',
23
+ 'deprecated-config-keys',
24
+ 'deprecated-config-switch',
25
+ 'deprecated-context-import',
26
+ 'deprecated-ctx-fail',
27
+ 'deprecated-deny-call',
28
+ 'deprecated-disk-files',
29
+ 'deprecated-env-files',
30
+ 'deprecated-event-names',
31
+ 'deprecated-filter-options',
32
+ 'deprecated-format-duration',
33
+ 'deprecated-guard-option',
34
+ 'deprecated-hook-context',
35
+ 'deprecated-hook-names',
36
+ 'deprecated-i18n-keys',
37
+ 'deprecated-if-alias',
38
+ 'deprecated-image-options',
39
+ 'deprecated-images-keys',
40
+ 'deprecated-import-path',
41
+ 'deprecated-infinite-list-options',
42
+ 'deprecated-island-attributes',
43
+ 'deprecated-island-events',
44
+ 'deprecated-island-fence',
45
+ 'deprecated-job-handler',
46
+ 'deprecated-job-options',
47
+ 'deprecated-link-flags',
48
+ 'deprecated-listen-target',
49
+ 'deprecated-live-api',
50
+ 'deprecated-local-state',
51
+ 'deprecated-mail-form',
52
+ 'deprecated-mail-send',
53
+ 'deprecated-navigate-query',
54
+ 'deprecated-navigation-hooks',
55
+ 'deprecated-package-names',
56
+ 'deprecated-page-cache',
57
+ 'deprecated-page-island',
58
+ 'deprecated-page-seo',
59
+ 'deprecated-pages-options',
60
+ 'deprecated-parts-class',
61
+ 'deprecated-persisted-call',
62
+ 'deprecated-persisted-query',
63
+ 'deprecated-persisted-storage',
64
+ 'deprecated-rate-enforce',
65
+ 'deprecated-redirect-permanent',
66
+ 'deprecated-refuse-call',
67
+ 'deprecated-route-keys',
68
+ 'deprecated-schedule-call',
69
+ 'deprecated-schedule-tz',
70
+ 'deprecated-schema-type',
71
+ 'deprecated-script-fence',
72
+ 'deprecated-secret-keys',
73
+ 'deprecated-socket-frames',
74
+ 'deprecated-source-readers',
75
+ 'deprecated-store-ms',
76
+ 'deprecated-store-names',
77
+ 'deprecated-test-helpers',
78
+ 'deprecated-ttl-names',
79
+ 'deprecated-ui-callbacks',
80
+ 'deprecated-ui-hotkey',
81
+ 'deprecated-ui-input',
82
+ 'deprecated-ui-item-keys',
83
+ 'deprecated-ui-items',
84
+ 'deprecated-uncaught-await',
85
+ 'deprecated-workflow-start-id',
86
+ 'uncaught-await',
87
+ 'unreturned-fail',
88
+ ] as const
89
+
90
+ export type RemovedLintName = typeof REMOVED_LINTS[number]
@@ -10,6 +10,8 @@ export type Rewrites = Map<number, Rewrite & { end: number }>
10
10
  export interface Sites {
11
11
  // Arrow parameters, and the index a loop declares in its block, that code which runs reads through a call: a loop's row and index, an `if`'s alias.
12
12
  rows: Set<number>
13
+ // The start of the parameters of a slot block whose plain names are read through accessors, as a loop's row is.
14
+ blocks: Set<number>
13
15
  // A template `const`'s pattern, true when code that runs reads its names as memos.
14
16
  consts: Map<number, boolean>
15
17
  // The `consts` among them that destructure a loop's item, which behave as the item of a plain loop does.
@@ -539,9 +539,11 @@ class RewriteFinder {
539
539
 
540
540
  // A loop's row and index and an `if`'s alias track the current value, so code that runs reads them through a call.
541
541
  private rows(path: Path<ArrowFunctionExpression>) {
542
+ const block = this.input.sites.blocks.has(path.node.params[0]?.start ?? -1)
543
+
542
544
  for (const [index, param] of path.node.params.entries()) {
543
- if (param.type === 'Identifier' && this.input.sites.rows.has(param.start))
544
- this.rowBinding(path.scope, param.name, index === 0 ? loopKey(path, param.name) : undefined)
545
+ if (param.type === 'Identifier' && (block || this.input.sites.rows.has(param.start)))
546
+ this.rowBinding(path.scope, param.name, index === 0 && !block ? loopKey(path, param.name) : undefined)
545
547
  }
546
548
  }
547
549
 
@@ -10,6 +10,14 @@ export const ROUTE_LINTS = {
10
10
  ...LOOP_LINTS,
11
11
  ...LINK_LINTS,
12
12
  ...SCHEMA_LINTS,
13
+ 'static-remote-image': {
14
+ level: 'warn',
15
+ group: 'performance',
16
+ site: true,
17
+ summary: 'On a `kay build --static` export, an island image the build cannot write files for: an `image(source, { width, height })` whose source is neither an imported image nor a literal URL, a literal URL on a host `assets.images.remote` does not list, a width or height that is no number literal, or an `aspect`, `quality` or `sizes` that is no literal. The export has no image route, so the browser links the original image, or asks for a file that does not exist. Give `image()` the URL as a literal on a listed host, with its size and options as literals, and the build fetches and resizes it. A best-effort read of the island\'s source. Reported by `kay build --static`.',
18
+ wrong: 'img({...image(post.cover, { width: 1200, height: 800 })} alt="")',
19
+ right: 'img({...image(\'https://cms.example.com/cover.jpg\', { width: 1200, height: 800 })} alt="")',
20
+ },
13
21
  'text-size-colour': {
14
22
  level: 'warn',
15
23
  group: 'code',
@@ -0,0 +1,141 @@
1
+ import type { Diagnostic, Fix } from './ast'
2
+ import type { Node, NodeOfType } from './estree'
3
+ import type { ParsedFence, PropsDeclaration } from './script'
4
+ import { eachNode } from './each-node'
5
+ import { INITIAL_PROP } from './live-reads'
6
+ import { patternNames } from './pattern-names'
7
+
8
+ type ImportSpecifier = NodeOfType<'ImportSpecifier'>
9
+
10
+ const KAY = 'kay'
11
+
12
+ // The name a prop is read by, through a chain of plain properties (`todo.title`), or undefined for any other expression.
13
+ function propRoot(node: Node): string | undefined {
14
+ if (node.type === 'Identifier')
15
+ return node.name
16
+
17
+ return node.type === 'MemberExpression' && !node.computed && node.property.type === 'Identifier' ? propRoot(node.object) : undefined
18
+ }
19
+
20
+ function importedAs(node: Node, name: string): node is ImportSpecifier {
21
+ return node.type === 'ImportSpecifier' && node.importKind !== 'type' && node.local.name === name && (node.imported.type === 'Identifier' ? node.imported.name : node.imported.value) === name
22
+ }
23
+
24
+ // The names an `effect` writes, `effect(() => shown = open)` or `shown.set(open)`: a signal it follows needs no `linked`.
25
+ function followedByEffects(ast: Node): Set<string> {
26
+ const names = new Set<string>()
27
+
28
+ eachNode(ast, (node) => {
29
+ if (node.type !== 'CallExpression' || node.callee.type !== 'Identifier' || node.callee.name !== 'effect')
30
+ return
31
+
32
+ eachNode(node, (inner) => {
33
+ if (inner.type === 'AssignmentExpression' && inner.left.type === 'Identifier')
34
+ names.add(inner.left.name)
35
+
36
+ if (inner.type === 'CallExpression' && inner.callee.type === 'MemberExpression' && inner.callee.property.type === 'Identifier' && inner.callee.property.name === 'set' && inner.callee.object.type === 'Identifier')
37
+ names.add(inner.callee.object.name)
38
+ })
39
+
40
+ return false
41
+ })
42
+
43
+ return names
44
+ }
45
+
46
+ // The names the script writes outside an `effect`: `name = value`, `name += 1` or `name.set(...)`, `.update(...)`.
47
+ function writtenNames(ast: Node): Set<string> {
48
+ const names = new Set<string>()
49
+
50
+ eachNode(ast, (node) => {
51
+ if (node.type === 'AssignmentExpression' && node.left.type === 'Identifier')
52
+ names.add(node.left.name)
53
+
54
+ if (node.type === 'UpdateExpression' && node.argument.type === 'Identifier')
55
+ names.add(node.argument.name)
56
+
57
+ if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && node.callee.property.type === 'Identifier' && (node.callee.property.name === 'set' || node.callee.property.name === 'update'))
58
+ names.add(node.callee.object.name)
59
+ })
60
+
61
+ return names
62
+ }
63
+
64
+ // A `signal(prop)` at the top of an island's script that the island never writes: the signal takes the prop's value when the component is created, so it keeps the first one when the page gives the island another, as a refresh does while the island stays. `linked(() => prop)` is the signal that follows its source. A signal the island writes (a counter starting from a prop) is its own state and is left alone.
65
+ // A prop named as a seed (`initial...`, `default...`) is meant to be read once, and a name declared again in the script is left alone.
66
+ export function signalFromProps(fence: ParsedFence, props: PropsDeclaration | undefined, writtenInTemplate: ReadonlySet<string>): Diagnostic[] {
67
+ if (!props || !fence.code.includes('signal'))
68
+ return []
69
+
70
+ const watched = new Set(props.bindings.filter(binding => !INITIAL_PROP.test(binding.key)).map(binding => fence.code.slice(binding.local.start - fence.offset, binding.local.end - fence.offset)))
71
+ const declaration = fence.ast.body.find(node => node.type === 'ImportDeclaration' && node.source.value === KAY && node.importKind !== 'type')
72
+ const specifier = declaration?.type === 'ImportDeclaration' ? declaration.specifiers.find(node => importedAs(node, 'signal')) : undefined
73
+
74
+ if (watched.size === 0 || specifier?.type !== 'ImportSpecifier')
75
+ return []
76
+
77
+ const linked = declaration?.type === 'ImportDeclaration' && declaration.specifiers.some(node => importedAs(node, 'linked'))
78
+ let others = 0
79
+ let taken = false
80
+ const seeds: { call: NodeOfType<'CallExpression'>, name: string | undefined }[] = []
81
+
82
+ eachNode(fence.ast, (node) => {
83
+ if (node.type === 'ImportDeclaration' || (node.type === 'VariableDeclaration' && fence.shift(node).start === props.statement.start))
84
+ return false
85
+
86
+ // A parameter of a function in the script is its own value, not the prop.
87
+ if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
88
+ for (const param of node.params) {
89
+ for (const name of patternNames(param))
90
+ watched.delete(name)
91
+ }
92
+ }
93
+
94
+ if (node.type === 'VariableDeclarator') {
95
+ for (const name of patternNames(node.id)) {
96
+ watched.delete(name)
97
+ taken ||= name === 'linked'
98
+ }
99
+
100
+ const { init } = node
101
+
102
+ if (init?.type === 'CallExpression' && init.callee.type === 'Identifier' && init.callee.name === 'signal' && init.arguments.length === 1 && init.arguments[0]!.type !== 'SpreadElement')
103
+ seeds.push({ call: init, name: node.id.type === 'Identifier' ? node.id.name : undefined })
104
+ }
105
+
106
+ if (node.type === 'Identifier' && node.name === 'signal')
107
+ others++
108
+
109
+ return true
110
+ })
111
+
112
+ const diagnostics: Diagnostic[] = []
113
+ const followed = followedByEffects(fence.ast)
114
+ const written = writtenNames(fence.ast)
115
+ const found = seeds.filter(({ call, name }) => {
116
+ // A seed the island writes is its own state, which starts from the prop by intent, as a counter does.
117
+ const root = call.typeArguments || (name !== undefined && (followed.has(name) || written.has(name) || writtenInTemplate.has(name))) ? undefined : propRoot(call.arguments[0]!)
118
+
119
+ return root !== undefined && watched.has(root)
120
+ })
121
+
122
+ for (const { call } of found) {
123
+ const seed = call.arguments[0]!
124
+ const root = propRoot(seed)!
125
+ const text = fence.code.slice(seed.start, seed.end)
126
+ const imports: Fix['edits'] = linked || taken ? [] : [{ ...fence.shift(specifier), text: others > found.length ? 'linked, signal' : 'linked' }]
127
+ const fix: Fix = { title: `Write \`linked(() => ${text})\``, safe: !taken, edits: [{ ...fence.shift(call), text: `linked(() => ${text})` }, ...imports] }
128
+
129
+ diagnostics.push({
130
+ ...fence.shift(call),
131
+ code: 'signal-from-prop',
132
+ message: `\`signal(${text})\` keeps the first value of \`${root}\`, as a signal made from a prop does not follow it`,
133
+ note: 'the island stays when the page gives it new props, as after an action or a refresh, so a seed read once shows the old value',
134
+ help: `write \`linked(() => ${text})\`, which follows the prop and can still be written, or \`// kay-allow signal-from-prop\` when the first value is meant`,
135
+ checkOnly: true,
136
+ fixes: taken ? [] : [fix],
137
+ })
138
+ }
139
+
140
+ return diagnostics
141
+ }
@@ -173,6 +173,22 @@ export function templateWords(file: KayFile): string[] {
173
173
  return [...words]
174
174
  }
175
175
 
176
+ // The names the template's expressions write, `count = 1`, `count += 1`, `count++` or `count.set(...)`; it over-approximates, a word before `=` in any expression counts.
177
+ const WRITE = /([\w$]+)\s*(?:\.(?:set|update)\s*\(|(?:\*\*|<<|>>>?|&&|\|\||\?\?|[-+*/%&|^])?=(?![=>])|\+\+|--)|(?:\+\+|--)\s*([\w$]+)/g
178
+
179
+ export function templateWrites(file: KayFile): Set<string> {
180
+ const names = new Set<string>()
181
+
182
+ visitNodes(file.template, (node) => {
183
+ for (const span of nodeExpressions(node)) {
184
+ for (const [, after, before] of file.source.slice(span.start, span.end).matchAll(WRITE))
185
+ names.add((after ?? before)!)
186
+ }
187
+ })
188
+
189
+ return names
190
+ }
191
+
176
192
  // The child blocks of a node with the spans naming what each sees besides its parent's names: a loop's item and index, a snippet's or slot's parameters, a branch's alias.
177
193
  export function scopedBlocks(node: Node): [Node[], Span[]][] {
178
194
  switch (node.kind) {
@@ -68,5 +68,6 @@ export function nameDestructuredRows(file: KayFile): KayFile {
68
68
  node.children.unshift({ kind: 'const', ...node.item, pattern: node.item, value: at, row })
69
69
  })
70
70
 
71
- return { ...file, template }
71
+ // The facts cached on the file name its old nodes, so the clone gets its own.
72
+ return { ...file, template, facts: undefined }
72
73
  }
@@ -76,7 +76,10 @@ const CONFIG: Record<keyof ConfigInput, Rule> = {
76
76
  seo: bag(SEO),
77
77
  robots: either(bool, bag(ROBOTS)),
78
78
  sitemap: either(bool, bag(SITEMAP)),
79
- head: list(obj),
79
+ head: list(bag({ tag: str, props: obj }, (entry, path, out) => {
80
+ if ('children' in entry)
81
+ out.push(`\`${path}.children\` is ignored: a tag's text goes in \`props.children\``)
82
+ })),
80
83
  budget: bag(BUDGET),
81
84
  entry: str,
82
85
  security: either(bool, bag(SECURITY_KEYS)),
package/src/config.ts CHANGED
@@ -57,8 +57,8 @@ export interface KayConfig extends AppHooks {
57
57
  robots?: RobotsConfig | boolean | undefined
58
58
  // How `/sitemap.xml` is kept, or `false` to serve none (and name none in `/robots.txt`).
59
59
  sitemap?: SitemapConfig | boolean | undefined
60
- // Tags every page's head carries, written as a `head` block compiles them: `[{ tag: 'script', props: { src: '/stats.js', defer: true } }]`, a tag's text as `children`. A layout or the page setting a tag of the same identity wins, and the content security policy lets their inline scripts and styles through.
61
- head?: HeadTag[] | undefined
60
+ // Tags every page's head carries, written as a `head` block compiles them: `[{ tag: 'script', props: { src: '/stats.js', defer: true } }]`, a tag's text as `props.children`. A layout or the page setting a tag of the same identity wins, and the content security policy lets their inline scripts and styles through.
61
+ head?: (HeadTag & { children?: never })[] | undefined
62
62
  // The most a page may load, compressed: `{ js: '20kb', css: '10kb' }` for its scripts and stylesheets, `weight: '500kb'` for the whole page and `grade: 'C'` for the worst EcoIndex grade it may have. `kay build` reports each page over it with `over-budget`, naming the modules weighing most for `js` and `css`; a key left out sets no limit, and with none nothing is checked.
63
63
  budget?: BudgetConfig | undefined
64
64
  // The server entry, relative to the root, `src/server.ts` by default: what `kay dev`, `start`, `render`, `check` and `build` run and type against, unless `--entry` names another. With no file there, kay's own server of the pages.
package/src/new.ts CHANGED
@@ -130,15 +130,27 @@ export async function originHost(dir: string): Promise<Host | undefined> {
130
130
  }
131
131
  }
132
132
 
133
- // Refuses a target `kay new` would write over: a file, or a directory that already holds files.
133
+ // What a fresh clone of a new forge repo holds besides `.git`: a folder with only these is scaffolded in place. A file the template writes too (`.gitignore`) is replaced, one it does not (`README.md`, the licence) is kept.
134
+ const FRESH_REPO_ENTRY = /^(?:\.git|README(?:\.\w+)?|LICENSE(?:[-.].+)?|\.gitignore|\.gitattributes)$/i
135
+
136
+ // Refuses a target `kay new` would write over: a file, or a directory that holds anything but what a fresh clone does.
134
137
  export async function refuseTarget(target: string): Promise<void> {
135
138
  const dir = resolve(target)
136
139
 
137
- if (existsSync(dir) && !statSync(dir).isDirectory())
140
+ if (!existsSync(dir))
141
+ return
142
+
143
+ if (!statSync(dir).isDirectory())
138
144
  throw new Error(`kay: ${target} is not a directory`)
139
145
 
140
- if (existsSync(dir) && (await readdir(dir)).length > 0)
141
- throw new Error(`kay: ${target} is not empty`)
146
+ const inTheWay = (await readdir(dir)).filter(entry => !FRESH_REPO_ENTRY.test(entry)).sort()
147
+
148
+ if (inTheWay.length === 0)
149
+ return
150
+
151
+ const shown = inTheWay.slice(0, 5).join(', ')
152
+
153
+ throw new Error(`kay: ${target} is not empty: ${shown}${inTheWay.length > 5 ? `, and ${inTheWay.length - 5} more` : ''} in the way`)
142
154
  }
143
155
 
144
156
  // Whether `kay new` adds the feature through `kay add` after scaffolding: a library's, but for a templated one whose files the templates write.
package/src/project.ts CHANGED
@@ -185,8 +185,8 @@ function customWidths(widths: number[] | undefined): number[] | undefined {
185
185
  }
186
186
 
187
187
  // How every page renders, served or prerendered alike.
188
- export function renderOptionsOf(config: KayConfig, mode: Pick<Mode, 'dev' | 'devRoutes'>, built: { head: SeoHead | undefined, maxDensity: number, editor?: string | undefined, contexts?: string[] | undefined, fontCss?: string | undefined, islandPreloads?: RenderOptions['islandPreloads'] }): RenderOptions {
189
- return { ...pickConfig(config, RENDER_CONFIG), dev: mode.dev, devTools: mode.devRoutes, serverTiming: config.ops?.observe?.serverTiming ?? mode.dev, sameTabLinks: sameTabOn(config), linkSchemes: linkSchemes(config), fontCss: config.client?.saveData === false ? undefined : built.fontCss, islandPreloads: config.client?.saveData === false ? undefined : built.islandPreloads, head: built.head, base: basePath(config.base), maxDensity: built.maxDensity, imageWidths: customWidths(config.assets?.images?.widths), resolvedImages: config.assets?.images?.resolve !== undefined, offline: registersWorker(config, mode), installOffer: pushListed(config), editor: built.editor, contexts: built.contexts }
188
+ export function renderOptionsOf(config: LoadedConfig, mode: Pick<Mode, 'dev' | 'devRoutes'>, built: { head: SeoHead | undefined, maxDensity: number, editor?: string | undefined, contexts?: string[] | undefined, fontCss?: string | undefined, islandPreloads?: RenderOptions['islandPreloads'] }): RenderOptions {
189
+ return { ...pickConfig(config, RENDER_CONFIG), publicEnv: config.publicEnv === true, dev: mode.dev, devTools: mode.devRoutes, serverTiming: config.ops?.observe?.serverTiming ?? mode.dev, sameTabLinks: sameTabOn(config), linkSchemes: linkSchemes(config), fontCss: config.client?.saveData === false ? undefined : built.fontCss, islandPreloads: config.client?.saveData === false ? undefined : built.islandPreloads, head: built.head, base: basePath(config.base), maxDensity: built.maxDensity, imageWidths: customWidths(config.assets?.images?.widths), resolvedImages: config.assets?.images?.resolve !== undefined, offline: registersWorker(config, mode), installOffer: pushListed(config), editor: built.editor, contexts: built.contexts }
190
190
  }
191
191
 
192
192
  // A project as every entry point takes it: where it is, its config, where it keeps each part and how it runs.
@@ -207,7 +207,7 @@ export function writesFrench(config: Pick<KayConfig, 'lang' | 'i18n' | 'client'>
207
207
  }
208
208
 
209
209
  // The browser build a config asks for. `kay build`'s (`build` given) minifies unless the config says not to; one a server or a test makes on demand does only when the config says so.
210
- export function clientOptionsOf(config: LoadedConfig, mode: Pick<Mode, 'dev' | 'underKayDev'>, build?: Pick<ClientOptions, 'exported' | 'report'>): ClientOptions {
210
+ export function clientOptionsOf(config: LoadedConfig, mode: Pick<Mode, 'dev' | 'underKayDev'>, build?: Pick<ClientOptions, 'exported' | 'staticImages' | 'report'>): ClientOptions {
211
211
  return {
212
212
  ...pickConfig(config, CLIENT_BUILD_KEYS),
213
213
  minify: config.minify ?? build !== undefined,
@@ -4,7 +4,7 @@ import type { JSX } from './jsx'
4
4
  import type { Html } from './rendered'
5
5
  import { AWAIT_FAILED, AWAIT_FAILED_KEY } from './await-failed'
6
6
  import { escape } from './escape'
7
- import { awaitNotes, child } from './html'
7
+ import { awaitNotes, child, keepLoopKeys } from './html'
8
8
  import { insideIsland } from './island.server'
9
9
  import { getOwner, runWithOwner } from './reactive'
10
10
  import { html } from './rendered'
@@ -195,10 +195,12 @@ export function Await<T>(props: AwaitChannel<T>): JSX.Element {
195
195
  // Rendered once the value settles, under the component that declared it, for what it provided.
196
196
  const parent = getOwner()
197
197
  const failed = props.failed
198
+ const inLoop = keepLoopKeys()
199
+ const resume = <R>(render: () => R) => inLoop(() => following(notes, render))
198
200
 
199
201
  const fallback = props.fallback
200
202
 
201
- collecting.blocks.push({ id, value, ready: (settled: never) => runWithOwner(parent, () => following(notes, () => props.ready(settled))), failed: failed && (error => runWithOwner(parent, () => following(notes, () => failed(error)))), fallback: fallback && (error => runWithOwner(parent, () => following(notes, () => fallback(error)))), alert: props.alert ? error => runWithOwner(parent, () => following(notes, () => props.alert!(error))) : awaitFailed, site: failed ? undefined : new Error('await') })
203
+ collecting.blocks.push({ id, value, ready: (settled: never) => runWithOwner(parent, () => resume(() => props.ready(settled))), failed: failed && (error => runWithOwner(parent, () => resume(() => failed(error)))), fallback: fallback && (error => runWithOwner(parent, () => resume(() => fallback(error)))), alert: props.alert ? error => runWithOwner(parent, () => resume(() => props.alert!(error))) : awaitFailed, site: failed ? undefined : new Error('await') })
202
204
  // The streamed block replaces this one whole, so an `await` inside it renders its own pending block and streams nothing.
203
205
  deferred = undefined
204
206
 
@@ -43,6 +43,17 @@ export type BoundValue<Tag, Key> = Key extends keyof PropsOfComponent<Tag> ? Mar
43
43
  // Lets the checker tell islands from plain components.
44
44
  export interface IslandBrand { readonly [ISLAND]: true }
45
45
 
46
+ declare const ASKED: unique symbol
47
+
48
+ // What an island lists in `island({ interactive })`, kept in its type so a use that turns none of those props on is known to render as plain markup, which takes a function.
49
+ export interface IslandAsked<Interactive extends Readonly<Record<string, boolean>>> { readonly [ASKED]: Interactive }
50
+
51
+ // The props that make a use an island whatever the component lists.
52
+ type IslandOptionKeys = 'hydrate' | 'persist' | 'render' | 'fallback'
53
+
54
+ // Whether a use naming these props turns none of the component's interactive ones on: a prop it may leave out is on by default, and a spread, which names nothing, may carry any.
55
+ type StaysPlain<Component, Used> = Component extends IslandAsked<infer Interactive> ? true extends Interactive[keyof Interactive] ? false : [Used & (keyof Interactive | IslandOptionKeys)] extends [never] ? true : false : false
56
+
46
57
  // What an interactive component's default export is; only islands take `hydrate`.
47
58
  // What a static parent passes an island besides its props: when it hydrates, and whether it lives on across navigations, `persist` keeping it by its component, `persist="key"` by a key of its own.
48
59
  // `fallback` is the markup a client-only use shows on the server until the browser renders the island, written as an `@fallback` block: it reaches the island under a key of kay's own, so a component's `fallback` prop of another kind is its own.
@@ -328,7 +339,8 @@ export type PlainIslandProp<Component, Value> = Component extends IslandBrand ?
328
339
  export type SlotCall = (...args: any[]) => JSX.Element
329
340
 
330
341
  // A function written in the attribute is checked apart from its value, which a wrapping call would stop a generic component from typing: `0` stands for the attribute.
331
- export type FunctionProp<Component> = Component extends IslandBrand ? { kayLint: 'island-prop', kayAlways: true, kayError: Unsendable } : 0
342
+ // `Names` is the props the use writes, as an object type: a use turning no interactive prop of an island on is plain markup, which takes a function.
343
+ export type FunctionProp<Component, Names extends object = Record<string, unknown>> = Component extends IslandBrand ? true extends StaysPlain<Component, keyof Names> ? 0 : { kayLint: 'island-prop', kayAlways: true, kayError: Unsendable } : 0
332
344
 
333
345
  // What `defer()` returns, a plain promise: an `await` block takes any promise, so nothing marks one.
334
346
  export type Deferred<T> = Promise<T>
@@ -375,7 +387,7 @@ export interface TemplateHelpers {
375
387
  componentClass: <const List extends readonly unknown[]>(list: List) => ComponentClass<List>
376
388
  partClass: (props: unknown, part: string) => unknown
377
389
  partHanded: (part: string, list: readonly unknown[]) => unknown
378
- partsClass: (list: readonly unknown[]) => unknown
390
+ partProps: (read: () => readonly [list: readonly unknown[], written?: unknown]) => unknown
379
391
  handParts: (list: readonly unknown[], written?: unknown) => unknown
380
392
  omit: <Props extends object, Key extends keyof Props>(props: Props, ...keys: Key[]) => Omit<Props, Key>
381
393
  head: (tags: { tag: string, props: Record<string, unknown> }[]) => void
@@ -3,6 +3,7 @@ import { reviveActionsIn } from './action-revive'
3
3
  import { withBase } from './base'
4
4
  import { skew } from './build'
5
5
  import { dispatch, hydrate, render } from './dom'
6
+ import { liveProps } from './live-props'
6
7
  import { HYDRATED, ISLAND } from './markers'
7
8
  import { flush, recordSignals, reportError, root, setErrorReporter } from './reactive'
8
9
  import { savesDataInBrowser } from './save-data'
@@ -225,10 +226,10 @@ async function hydrateIsland(registry: IslandRegistry, element: HTMLElement): Pr
225
226
  return
226
227
  }
227
228
 
228
- let loaded: [Awaited<ReturnType<IslandRegistry[string]>>, Awaited<ReturnType<typeof staticSlots>>, Awaited<ReturnType<typeof livePropsOf>>, void | undefined]
229
+ let loaded: [Awaited<ReturnType<IslandRegistry[string]>>, Awaited<ReturnType<typeof staticSlots>>, void | undefined]
229
230
 
230
231
  try {
231
- loaded = await Promise.all([load(), staticSlots(registry, element), livePropsOf(element), reviveActionsIn(element.dataset.props)])
232
+ loaded = await Promise.all([load(), staticSlots(registry, element), reviveActionsIn(element.dataset.props)])
232
233
 
233
234
  // What the server drew of its lazy components loads first, so the markup is claimed as it stands.
234
235
  const drawn = (globalThis as { $kayLoadDrawn?: (island: HTMLElement) => Promise<void> }).$kayLoadDrawn
@@ -246,7 +247,7 @@ async function hydrateIsland(registry: IslandRegistry, element: HTMLElement): Pr
246
247
  throw error
247
248
  }
248
249
 
249
- const [{ default: component }, slots, live] = loaded
250
+ const [{ default: component }, slots] = loaded
250
251
 
251
252
  // A page swap took it away while its chunk loaded: hydrated now, its effects would outlive it. One in a static slot its island hid hydrates as it shows it again.
252
253
  if (!element.isConnected) {
@@ -256,7 +257,7 @@ async function hydrateIsland(registry: IslandRegistry, element: HTMLElement): Pr
256
257
  }
257
258
 
258
259
  const given = element.dataset.props === undefined ? {} : decodeServerValue(element.dataset.props) as Record<string, unknown>
259
- const [props, update] = live ? live(given) : [given, undefined]
260
+ const [props, update] = liveProps(given)
260
261
 
261
262
  for (const [key, slot] of Object.entries(slots))
262
263
  Object.defineProperty(props, key, { value: slot, enumerable: true, configurable: true })
@@ -316,11 +317,6 @@ async function hydrateIsland(registry: IslandRegistry, element: HTMLElement): Pr
316
317
  element.dispatchEvent(new Event(HYDRATED))
317
318
  }
318
319
 
319
- // Its own chunk, which only a page holding a persistent island loads: the one kind of island the next page gives other props to.
320
- async function livePropsOf(element: HTMLElement): Promise<typeof import('./live-props').liveProps | undefined> {
321
- return element.dataset.persist === undefined ? undefined : (await import('./live-props')).liveProps
322
- }
323
-
324
320
  // The static slots a static parent gave the island, whose code only a page holding such an island loads.
325
321
  async function staticSlots(registry: IslandRegistry, element: HTMLElement): Promise<Record<string, () => Node[]>> {
326
322
  return element.dataset.slots === undefined ? {} : (await import('./static-slots')).islandSlots(element, root => void hydrateIslands(registry, root))
@@ -1,7 +1,10 @@
1
+ import type { DevRequest } from '../server/dev'
1
2
  import type { DevTab, DevTool } from './dev-tool'
2
3
 
3
4
  // The Env tab's code, fetched at once as its badge counts the variables that look like secrets, with the tool's shared helpers from `tool.kit`.
4
5
  const ENV_URL = '/_kay/env.js'
6
+ // Copied from dev-tool-constants.ts, as a tab module imports nothing.
7
+ const REQUEST = 'kay-dev-request'
5
8
  const MODULE_START = 'export default '
6
9
  const BUILT_EVENT = 'kay:dev-built'
7
10
 
@@ -54,6 +57,16 @@ export default function envTab(tool: DevTool, tab: DevTab): () => void {
54
57
  const { copyButton, entry, filterable, ownFetch, signal, toolbar } = tool.kit
55
58
  const win = tool.root.ownerDocument.defaultView!
56
59
  let reread: () => void = () => undefined
60
+ // False only when the page's request block says so; a page with none, or an unreadable one, is asked.
61
+ const served = (): boolean => {
62
+ try {
63
+ return (JSON.parse(win.document.getElementById(REQUEST)?.textContent ?? 'null') as DevRequest | null)?.publicEnv !== false
64
+ }
65
+ catch {
66
+ return true
67
+ }
68
+ }
69
+ let knew = served()
57
70
  const content = tool.make('div', 'stack')
58
71
  const bar = toolbar('Filter by name or value', () => bar.apply(content))
59
72
  let asked = 0
@@ -63,10 +76,13 @@ export default function envTab(tool: DevTool, tab: DevTab): () => void {
63
76
  let failure: string | undefined
64
77
 
65
78
  try {
66
- const response = await ownFetch(win, ENV_URL, { cache: 'no-store' })
79
+ // The route is there only when a field is `s.Public`, which the page's request block says: asking an app without one logs a 404.
80
+ knew = served()
67
81
 
68
- // The route is there only when a field is `s.Public`; any other answer is a failure to read it.
69
- if (response.status !== 404) {
82
+ const response = knew ? await ownFetch(win, ENV_URL, { cache: 'no-store' }) : undefined
83
+
84
+ // Any answer but a 404 is a failure to read it.
85
+ if (response && response.status !== 404) {
70
86
  if (!response.ok)
71
87
  throw new Error(`the server answered ${response.status}`)
72
88
 
@@ -129,6 +145,15 @@ export default function envTab(tool: DevTool, tab: DevTab): () => void {
129
145
  reread = () => void read()
130
146
  tab.panel.append(bar.element, content)
131
147
  win.document.addEventListener(BUILT_EVENT, reread, { signal })
148
+
149
+ // A restart that adds or drops the first or last public field brings the page a new block once it is patched in, after the built event.
150
+ const blocks = new MutationObserver(() => {
151
+ if (served() !== knew)
152
+ reread()
153
+ })
154
+
155
+ blocks.observe(win.document.head, { childList: true })
156
+ signal.addEventListener('abort', () => blocks.disconnect())
132
157
  reread()
133
158
 
134
159
  return () => reread()
@@ -1,6 +1,7 @@
1
1
  import type { Unit } from './dom'
2
2
  import { animated, blockIn, claiming, entered, firstOf, insertUnit, lastOf, Region, release, removeUnit, rowUnit, swap, units, within } from './dom'
3
3
  import { createSignal, onCleanup, renderEffect, root, unrecorded, untrack } from './reactive'
4
+ import { rowKey } from './row-key'
4
5
 
5
6
  declare const KAY_FRENCH: true | undefined
6
7
 
@@ -14,10 +15,7 @@ interface Row {
14
15
  dispose: () => void
15
16
  }
16
17
 
17
- // The key of a row whose `for` names none: the item's `id` when it has one, else the item itself, so a copy of an item is a new row.
18
- export function rowKey(item: unknown): unknown {
19
- return typeof item === 'object' && item !== null && 'id' in item ? item.id : item
20
- }
18
+ export { rowKey }
21
19
 
22
20
  const entryKey = (entry: unknown) => (entry as [unknown, unknown])[0]
23
21
 
@@ -19,9 +19,9 @@ declare const KAY_BROWSER: true | undefined
19
19
  declare const KAY_FRENCH: true | undefined
20
20
 
21
21
  export { holdSubmits, listenSubmit, listenSubmitWith, listenWith } from './form-hold'
22
- export { renderEffect as effect, memo, untrack } from './reactive'
22
+ export { renderEffect as effect, memo, param, slotCall, untrack } from './reactive'
23
23
  export { transition } from './transition'
24
- export { checkedMarkup, componentClass, handParts, merge, omit, partClass, partHanded, partsClass, spreadAttributes, spreadWith } from './values'
24
+ export { checkedMarkup, componentClass, handParts, merge, omit, partClass, partHanded, partProps, spreadAttributes, spreadWith } from './values'
25
25
 
26
26
  // Several sibling nodes rendered as one: a block or a component returning more than one node. Its first and last nodes stay in place while what sits between changes.
27
27
  export class Range {