@farm.js/react 0.1.0-beta.3 → 0.1.0-beta.31

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.
package/dist/index.cjs CHANGED
@@ -1,5 +1,28 @@
1
1
  'use strict';
2
2
 
3
+ // src/compiler-options.ts
4
+ var warnedExperimentalCompiler = false;
5
+ function resolveCompilerOption(options = {}, warnDeprecated = false) {
6
+ const experimental = options.experimental;
7
+ const legacy = experimental && typeof experimental === "object" ? experimental.compiler : void 0;
8
+ if (legacy !== void 0 && options.compiler !== void 0) {
9
+ throw new TypeError(
10
+ "Configure the React compiler with `compiler` only; remove `experimental.compiler`."
11
+ );
12
+ }
13
+ const compiler = legacy === void 0 ? options.compiler : legacy;
14
+ if (compiler !== void 0 && typeof compiler !== "boolean" && (compiler === null || typeof compiler !== "object" || Array.isArray(compiler))) {
15
+ throw new TypeError("React compiler must be a boolean or compiler options object.");
16
+ }
17
+ if (legacy !== void 0 && warnDeprecated && !warnedExperimentalCompiler) {
18
+ warnedExperimentalCompiler = true;
19
+ console.warn(
20
+ "[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`."
21
+ );
22
+ }
23
+ return compiler;
24
+ }
25
+
3
26
  // src/index.ts
4
27
  var DEFAULT_COMPILER_DIRECTIVE = "use compiler";
5
28
  var DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
@@ -28,6 +51,10 @@ function normalizeReactCompilerOptions(value) {
28
51
  if (!["fallback", "warn", "error"].includes(onUnsupported)) {
29
52
  throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);
30
53
  }
54
+ const reactivity = options.reactivity || "hybrid";
55
+ if (reactivity !== "static" && reactivity !== "hybrid") {
56
+ throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);
57
+ }
31
58
  if (options.report !== void 0 && typeof options.report !== "boolean") {
32
59
  throw new TypeError("The React compiler report option must be a boolean.");
33
60
  }
@@ -38,7 +65,7 @@ function normalizeReactCompilerOptions(value) {
38
65
  }
39
66
  const reportFile = normalizeCompilerReportFile(options.reportFile);
40
67
  const report = options.report === true || options.reportFile !== void 0;
41
- return { mode, directive, onUnsupported, report, reportFile };
68
+ return { mode, directive, onUnsupported, reactivity, report, reportFile };
42
69
  }
43
70
  var REACT_RENDERER = Object.freeze({
44
71
  name: "react",
@@ -56,21 +83,34 @@ var REACT_RENDERER = Object.freeze({
56
83
  "@farm.js/react/compiler-runtime"
57
84
  ],
58
85
  capabilities: {
59
- streaming: { node: true, web: false }
86
+ reconcilesRerenders: true,
87
+ streaming: {
88
+ node: true,
89
+ web: false,
90
+ runtimes: { edge: { node: false, web: true } }
91
+ },
92
+ functionComponents: true
60
93
  }
61
94
  });
62
95
  function react(options = {}) {
63
- const compiler = options.experimental?.compiler;
96
+ const compiler = resolveCompilerOption(options, true);
64
97
  const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;
65
98
  return {
66
99
  ...REACT_RENDERER,
67
100
  dedupe: [...REACT_RENDERER.dedupe || []],
68
101
  optimizeDeps: [...REACT_RENDERER.optimizeDeps || []],
69
102
  capabilities: {
70
- streaming: { ...REACT_RENDERER.capabilities?.streaming }
103
+ reconcilesRerenders: true,
104
+ streaming: {
105
+ ...REACT_RENDERER.capabilities?.streaming,
106
+ runtimes: {
107
+ edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge }
108
+ }
109
+ },
110
+ functionComponents: true
71
111
  },
72
112
  options: {
73
- experimental: { compiler: normalizedCompiler }
113
+ compiler: normalizedCompiler
74
114
  }
75
115
  };
76
116
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAiCO,IAAM,0BAAA,GAA6B;AACnC,IAAM,4BAAA,GAA+B;AAE5C,SAAS,4BAA4B,KAAA,EAAwB;AAC3D,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,4BAAA;AAChC,EAAA,IAAI,OAAO,KAAA,KAAU,Q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,QAAA,GAAW,6BAAA,CAA8B,QAAQ,CAAA,GAAI,KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,SAAA,EAAW,EAAE,GAAG,cAAA,CAAe,cAAc,SAAA;AAAU,KACzD;AAAA,IACA,OAAA,EAAS;AAAA,MACP,YAAA,EAAc,EAAE,QAAA,EAAU,kBAAA;AAAmB;AAC/C,GACF;AACF","file":"index.cjs","sourcesContent":["import type { FarmRenderer } from \"@farm.js/core/renderer\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n experimental?: {\n /** `true` enables automatic inference; an object customizes selection. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n streaming: { node: true, web: false },\n },\n});\n\n/** Select React and optionally enable Farm's experimental AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = options.experimental?.compiler;\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n streaming: { ...REACT_RENDERER.capabilities?.streaming },\n },\n options: {\n experimental: { compiler: normalizedCompiler },\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
1
+ {"version":3,"sources":["../src/compiler-options.ts","../src/index.ts"],"names":[],"mappings":";;;AAEA,IAAI,0BAAA,GAA6B,KAAA;AAG1B,SAAS,qBAAA,CACd,OAAA,GAA0D,EAAC,EAC3D,iBAAiB,KAAA,EAC2B;AAC5C,EAAA,MAAM,eAAe,OAAA,CAAQ,YAAA;AAC7B,EAAA,MAAM,SACJ,YAAA,IAAgB,OAAO,YAAA,KAAiB,QAAA,GACnC,aAAwC,QAAA,GACzC,MAAA;AACN,EAAA,IAAI,MAAA,KAAW,MAAA,IAAa,OAAA,CAAQ,QAAA,KAAa,MAAA,EAAW;AAC1D,IAAA,MAAM,IAAI,SAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,MAAM,QAAA,GAAW,MAAA,KAAW,MAAA,GAAY,OAAA,CAAQ,QAAA,GAAW,MAAA;AAC3D,EAAA,IACE,QAAA,KAAa,MAAA,IACb,OAAO,QAAA,KAAa,SAAA,KACnB,QAAA,KAAa,IAAA,IAAQ,OAAO,QAAA,KAAa,QAAA,IAAY,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,CAAA,EAC5E;AACA,IAAA,MAAM,IAAI,UAAU,8DAA8D,CAAA;AAAA,EACpF;AACA,EAAA,IAAI,MAAA,KAAW,MAAA,IAAa,cAAA,IAAkB,CAAC,0BAAA,EAA4B;AACzE,IAAA,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A,EAAS;AAAA,MACP,QAAA,EAAU;AAAA;AACZ,GACF;AACF","file":"index.cjs","sourcesContent":["import type { ReactCompilerOptions } from \"./index\";\n\nlet warnedExperimentalCompiler = false;\n\n// Shared by react() and the Vite adapter, including descriptors from older renderers.\nexport function resolveCompilerOption(\n options: { compiler?: unknown; experimental?: unknown } = {},\n warnDeprecated = false,\n): boolean | ReactCompilerOptions | undefined {\n const experimental = options.experimental;\n const legacy =\n experimental && typeof experimental === \"object\"\n ? (experimental as { compiler?: unknown }).compiler\n : undefined;\n if (legacy !== undefined && options.compiler !== undefined) {\n throw new TypeError(\n \"Configure the React compiler with `compiler` only; remove `experimental.compiler`.\",\n );\n }\n const compiler = legacy === undefined ? options.compiler : legacy;\n if (\n compiler !== undefined &&\n typeof compiler !== \"boolean\" &&\n (compiler === null || typeof compiler !== \"object\" || Array.isArray(compiler))\n ) {\n throw new TypeError(\"React compiler must be a boolean or compiler options object.\");\n }\n if (legacy !== undefined && warnDeprecated && !warnedExperimentalCompiler) {\n warnedExperimentalCompiler = true;\n console.warn(\n \"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`.\",\n );\n }\n return compiler as boolean | ReactCompilerOptions | undefined;\n}\n","import type { FarmRenderer } from \"@farm.js/core/renderer\";\nimport { resolveCompilerOption } from \"./compiler-options\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n /**\n * Farm's AOT compiler. `true` enables automatic inference; an object\n * customizes selection. Unsupported components always stay on React.\n */\n compiler?: boolean | ReactCompilerOptions;\n experimental?: {\n /** @deprecated Use the top-level `compiler` option. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n node: true,\n web: false,\n runtimes: { edge: { node: false, web: true } },\n },\n functionComponents: true,\n },\n});\n\n/** Select React and optionally enable Farm's AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = resolveCompilerOption(options, true);\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n ...REACT_RENDERER.capabilities?.streaming,\n runtimes: {\n edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge },\n },\n },\n functionComponents: true,\n },\n options: {\n compiler: normalizedCompiler,\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import { FarmRenderer } from '@farm.js/core/renderer';
2
2
  export { FarmRenderer } from '@farm.js/core/renderer';
3
3
 
4
4
  type ReactCompilerMode = "infer" | "annotation";
5
+ type ReactCompilerReactivity = "static" | "hybrid";
5
6
  type UnsupportedCompilerBehavior = "fallback" | "warn" | "error";
6
7
  interface ReactCompilerOptions {
7
8
  /** Compile every component that the safe subset can prove eligible. */
@@ -10,14 +11,24 @@ interface ReactCompilerOptions {
10
11
  directive?: string;
11
12
  /** What to do when a selected component is outside the safe subset. */
12
13
  onUnsupported?: UnsupportedCompilerBehavior;
14
+ /**
15
+ * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven
16
+ * dependencies and narrows short-circuited reads at runtime.
17
+ */
18
+ reactivity?: ReactCompilerReactivity;
13
19
  /** Write a machine-readable compiler coverage report after a production build. */
14
20
  report?: boolean;
15
21
  /** Project-relative report location. Providing it also enables reporting. */
16
22
  reportFile?: string;
17
23
  }
18
24
  interface ReactRendererOptions {
25
+ /**
26
+ * Farm's AOT compiler. `true` enables automatic inference; an object
27
+ * customizes selection. Unsupported components always stay on React.
28
+ */
29
+ compiler?: boolean | ReactCompilerOptions;
19
30
  experimental?: {
20
- /** `true` enables automatic inference; an object customizes selection. */
31
+ /** @deprecated Use the top-level `compiler` option. */
21
32
  compiler?: boolean | ReactCompilerOptions;
22
33
  };
23
34
  }
@@ -25,6 +36,7 @@ interface NormalizedReactCompilerOptions {
25
36
  mode: ReactCompilerMode;
26
37
  directive: string;
27
38
  onUnsupported: UnsupportedCompilerBehavior;
39
+ reactivity: ReactCompilerReactivity;
28
40
  report: boolean;
29
41
  reportFile: string;
30
42
  }
@@ -32,7 +44,7 @@ declare const DEFAULT_COMPILER_DIRECTIVE = "use compiler";
32
44
  declare const DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
33
45
  declare function normalizeReactCompilerOptions(value: true | ReactCompilerOptions): NormalizedReactCompilerOptions;
34
46
  declare const REACT_RENDERER: Readonly<FarmRenderer>;
35
- /** Select React and optionally enable Farm's experimental AOT compiler. */
47
+ /** Select React and optionally enable Farm's AOT compiler. */
36
48
  declare function react(options?: ReactRendererOptions): FarmRenderer;
37
49
 
38
- export { DEFAULT_COMPILER_DIRECTIVE, DEFAULT_COMPILER_REPORT_FILE, type NormalizedReactCompilerOptions, REACT_RENDERER, type ReactCompilerMode, type ReactCompilerOptions, type ReactRendererOptions, type UnsupportedCompilerBehavior, normalizeReactCompilerOptions, react };
50
+ export { DEFAULT_COMPILER_DIRECTIVE, DEFAULT_COMPILER_REPORT_FILE, type NormalizedReactCompilerOptions, REACT_RENDERER, type ReactCompilerMode, type ReactCompilerOptions, type ReactCompilerReactivity, type ReactRendererOptions, type UnsupportedCompilerBehavior, normalizeReactCompilerOptions, react };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { FarmRenderer } from '@farm.js/core/renderer';
2
2
  export { FarmRenderer } from '@farm.js/core/renderer';
3
3
 
4
4
  type ReactCompilerMode = "infer" | "annotation";
5
+ type ReactCompilerReactivity = "static" | "hybrid";
5
6
  type UnsupportedCompilerBehavior = "fallback" | "warn" | "error";
6
7
  interface ReactCompilerOptions {
7
8
  /** Compile every component that the safe subset can prove eligible. */
@@ -10,14 +11,24 @@ interface ReactCompilerOptions {
10
11
  directive?: string;
11
12
  /** What to do when a selected component is outside the safe subset. */
12
13
  onUnsupported?: UnsupportedCompilerBehavior;
14
+ /**
15
+ * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven
16
+ * dependencies and narrows short-circuited reads at runtime.
17
+ */
18
+ reactivity?: ReactCompilerReactivity;
13
19
  /** Write a machine-readable compiler coverage report after a production build. */
14
20
  report?: boolean;
15
21
  /** Project-relative report location. Providing it also enables reporting. */
16
22
  reportFile?: string;
17
23
  }
18
24
  interface ReactRendererOptions {
25
+ /**
26
+ * Farm's AOT compiler. `true` enables automatic inference; an object
27
+ * customizes selection. Unsupported components always stay on React.
28
+ */
29
+ compiler?: boolean | ReactCompilerOptions;
19
30
  experimental?: {
20
- /** `true` enables automatic inference; an object customizes selection. */
31
+ /** @deprecated Use the top-level `compiler` option. */
21
32
  compiler?: boolean | ReactCompilerOptions;
22
33
  };
23
34
  }
@@ -25,6 +36,7 @@ interface NormalizedReactCompilerOptions {
25
36
  mode: ReactCompilerMode;
26
37
  directive: string;
27
38
  onUnsupported: UnsupportedCompilerBehavior;
39
+ reactivity: ReactCompilerReactivity;
28
40
  report: boolean;
29
41
  reportFile: string;
30
42
  }
@@ -32,7 +44,7 @@ declare const DEFAULT_COMPILER_DIRECTIVE = "use compiler";
32
44
  declare const DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
33
45
  declare function normalizeReactCompilerOptions(value: true | ReactCompilerOptions): NormalizedReactCompilerOptions;
34
46
  declare const REACT_RENDERER: Readonly<FarmRenderer>;
35
- /** Select React and optionally enable Farm's experimental AOT compiler. */
47
+ /** Select React and optionally enable Farm's AOT compiler. */
36
48
  declare function react(options?: ReactRendererOptions): FarmRenderer;
37
49
 
38
- export { DEFAULT_COMPILER_DIRECTIVE, DEFAULT_COMPILER_REPORT_FILE, type NormalizedReactCompilerOptions, REACT_RENDERER, type ReactCompilerMode, type ReactCompilerOptions, type ReactRendererOptions, type UnsupportedCompilerBehavior, normalizeReactCompilerOptions, react };
50
+ export { DEFAULT_COMPILER_DIRECTIVE, DEFAULT_COMPILER_REPORT_FILE, type NormalizedReactCompilerOptions, REACT_RENDERER, type ReactCompilerMode, type ReactCompilerOptions, type ReactCompilerReactivity, type ReactRendererOptions, type UnsupportedCompilerBehavior, normalizeReactCompilerOptions, react };
package/dist/index.mjs CHANGED
@@ -1,3 +1,26 @@
1
+ // src/compiler-options.ts
2
+ var warnedExperimentalCompiler = false;
3
+ function resolveCompilerOption(options = {}, warnDeprecated = false) {
4
+ const experimental = options.experimental;
5
+ const legacy = experimental && typeof experimental === "object" ? experimental.compiler : void 0;
6
+ if (legacy !== void 0 && options.compiler !== void 0) {
7
+ throw new TypeError(
8
+ "Configure the React compiler with `compiler` only; remove `experimental.compiler`."
9
+ );
10
+ }
11
+ const compiler = legacy === void 0 ? options.compiler : legacy;
12
+ if (compiler !== void 0 && typeof compiler !== "boolean" && (compiler === null || typeof compiler !== "object" || Array.isArray(compiler))) {
13
+ throw new TypeError("React compiler must be a boolean or compiler options object.");
14
+ }
15
+ if (legacy !== void 0 && warnDeprecated && !warnedExperimentalCompiler) {
16
+ warnedExperimentalCompiler = true;
17
+ console.warn(
18
+ "[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`."
19
+ );
20
+ }
21
+ return compiler;
22
+ }
23
+
1
24
  // src/index.ts
2
25
  var DEFAULT_COMPILER_DIRECTIVE = "use compiler";
3
26
  var DEFAULT_COMPILER_REPORT_FILE = ".farm/react-compiler.json";
@@ -26,6 +49,10 @@ function normalizeReactCompilerOptions(value) {
26
49
  if (!["fallback", "warn", "error"].includes(onUnsupported)) {
27
50
  throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);
28
51
  }
52
+ const reactivity = options.reactivity || "hybrid";
53
+ if (reactivity !== "static" && reactivity !== "hybrid") {
54
+ throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);
55
+ }
29
56
  if (options.report !== void 0 && typeof options.report !== "boolean") {
30
57
  throw new TypeError("The React compiler report option must be a boolean.");
31
58
  }
@@ -36,7 +63,7 @@ function normalizeReactCompilerOptions(value) {
36
63
  }
37
64
  const reportFile = normalizeCompilerReportFile(options.reportFile);
38
65
  const report = options.report === true || options.reportFile !== void 0;
39
- return { mode, directive, onUnsupported, report, reportFile };
66
+ return { mode, directive, onUnsupported, reactivity, report, reportFile };
40
67
  }
41
68
  var REACT_RENDERER = Object.freeze({
42
69
  name: "react",
@@ -54,21 +81,34 @@ var REACT_RENDERER = Object.freeze({
54
81
  "@farm.js/react/compiler-runtime"
55
82
  ],
56
83
  capabilities: {
57
- streaming: { node: true, web: false }
84
+ reconcilesRerenders: true,
85
+ streaming: {
86
+ node: true,
87
+ web: false,
88
+ runtimes: { edge: { node: false, web: true } }
89
+ },
90
+ functionComponents: true
58
91
  }
59
92
  });
60
93
  function react(options = {}) {
61
- const compiler = options.experimental?.compiler;
94
+ const compiler = resolveCompilerOption(options, true);
62
95
  const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;
63
96
  return {
64
97
  ...REACT_RENDERER,
65
98
  dedupe: [...REACT_RENDERER.dedupe || []],
66
99
  optimizeDeps: [...REACT_RENDERER.optimizeDeps || []],
67
100
  capabilities: {
68
- streaming: { ...REACT_RENDERER.capabilities?.streaming }
101
+ reconcilesRerenders: true,
102
+ streaming: {
103
+ ...REACT_RENDERER.capabilities?.streaming,
104
+ runtimes: {
105
+ edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge }
106
+ }
107
+ },
108
+ functionComponents: true
69
109
  },
70
110
  options: {
71
- experimental: { compiler: normalizedCompiler }
111
+ compiler: normalizedCompiler
72
112
  }
73
113
  };
74
114
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAiCO,IAAM,0BAAA,GAA6B;AACnC,IAAM,4BAAA,GAA+B;AAE5C,SAAS,4BAA4B,KAAA,EAAwB;AAC3D,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,4BAAA;AAChC,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,KAAA,CAAM,MAAK,EAAG;AAC9C,IAAA,MAAM,IAAI,UAAU,mEAAmE,CAAA;AAAA,EACzF;AACA,EAAA,MAAM,aAAa,KAAA,CAAM,IAAA,EAAK,CAAE,OAAA,CAAQ,OAAO,GAAG,CAAA;AAClD,EAAA,IACE,UAAA,CAAW,UAAA,CAAW,GAAG,CAAA,IACzB,eAAe,IAAA,CAAK,UAAU,CAAA,IAC9B,UAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,QAAA,CAAS,IAAI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AA,EAAS;AAAA,MACP,YAAA,EAAc,EAAE,QAAA,EAAU,kBAAA;AAAmB;AAC/C,GACF;AACF","file":"index.mjs","sourcesContent":["import type { FarmRenderer } from \"@farm.js/core/renderer\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n experimental?: {\n /** `true` enables automatic inference; an object customizes selection. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n streaming: { node: true, web: false },\n },\n});\n\n/** Select React and optionally enable Farm's experimental AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = options.experimental?.compiler;\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n streaming: { ...REACT_RENDERER.capabilities?.streaming },\n },\n options: {\n experimental: { compiler: normalizedCompiler },\n },\n };\n}\n\nexport { REACT_RENDERER };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IAAA;AAAA,IACrB,SAAA,EAAW;AAAA,MACT,IAAA,EAAM,IAAA;AAAA,MACN,GAAA,EAAK,KAAA;AAAA,MACL,QAAA,EAAU,EAAE,IAAA,EAAM,EAAE,MAAM,KAAA,EAAO,GAAA,EAAK,MAAK;AAAE,KAC/C;AAAA,IACA,kBAAA,EAAoB;AAAA;AAExB,CAAC;AAGM,SAAS,KAAA,CAAM,OAAA,GAAgC,EAAC,EAAiB;AACtE,EAAA,MAAM,QAAA,GAAW,qBAAA,CAAsB,OAAA,EAAS,IAAI,CAAA;AACpD,EAAA,MAAM,kBAAA,GAAqB,QAAA,GAAW,6BAAA,CAA8B,QAAQ,CAAA,GAAI,KAAA;AAEhF,EAAA,OAAO;AAAA,IACL,GAAG,cAAA;AAAA,IACH,QAAQ,CAAC,GAAI,cAAA,CAAe,MAAA,IAAU,EAAG,CAAA;AAAA,IACzC,cAAc,CAAC,GAAI,cAAA,CAAe,YAAA,IAAgB,EAAG,CAAA;AAAA,IACrD,YAAA,EAAc;AAAA,MACZ,mBAAA,EAAqB,IAAA;AAAA,MACrB,SAAA,EAAW;AAAA,QACT,GAAG,eAAe,YAAA,EAAc,SAAA;AAAA,QAChC,QAAA,EAAU;AAAA,UACR,MAAM,EAAE,GAAG,eAAe,YAAA,EAAc,SAAA,EAAW,UAAU,IAAA;AAAK;AACpE,OACF;AAAA,MACA,kBAAA,EAAoB;AAAA,KACtB;AAAA,IACA,OAAA,EAAS;AAAA,MACP,QAAA,EAAU;AAAA;AACZ,GACF;AACF","file":"index.mjs","sourcesContent":["import type { ReactCompilerOptions } from \"./index\";\n\nlet warnedExperimentalCompiler = false;\n\n// Shared by react() and the Vite adapter, including descriptors from older renderers.\nexport function resolveCompilerOption(\n options: { compiler?: unknown; experimental?: unknown } = {},\n warnDeprecated = false,\n): boolean | ReactCompilerOptions | undefined {\n const experimental = options.experimental;\n const legacy =\n experimental && typeof experimental === \"object\"\n ? (experimental as { compiler?: unknown }).compiler\n : undefined;\n if (legacy !== undefined && options.compiler !== undefined) {\n throw new TypeError(\n \"Configure the React compiler with `compiler` only; remove `experimental.compiler`.\",\n );\n }\n const compiler = legacy === undefined ? options.compiler : legacy;\n if (\n compiler !== undefined &&\n typeof compiler !== \"boolean\" &&\n (compiler === null || typeof compiler !== \"object\" || Array.isArray(compiler))\n ) {\n throw new TypeError(\"React compiler must be a boolean or compiler options object.\");\n }\n if (legacy !== undefined && warnDeprecated && !warnedExperimentalCompiler) {\n warnedExperimentalCompiler = true;\n console.warn(\n \"[farm] `react({ experimental: { compiler } })` is deprecated. Use `react({ compiler })`.\",\n );\n }\n return compiler as boolean | ReactCompilerOptions | undefined;\n}\n","import type { FarmRenderer } from \"@farm.js/core/renderer\";\nimport { resolveCompilerOption } from \"./compiler-options\";\n\nexport type ReactCompilerMode = \"infer\" | \"annotation\";\nexport type ReactCompilerReactivity = \"static\" | \"hybrid\";\nexport type UnsupportedCompilerBehavior = \"fallback\" | \"warn\" | \"error\";\n\nexport interface ReactCompilerOptions {\n /** Compile every component that the safe subset can prove eligible. */\n mode?: ReactCompilerMode;\n /** Function or module directive used only by annotation mode. */\n directive?: string;\n /** What to do when a selected component is outside the safe subset. */\n onUnsupported?: UnsupportedCompilerBehavior;\n /**\n * How compiled bindings subscribe to state. `hybrid` keeps compiler-proven\n * dependencies and narrows short-circuited reads at runtime.\n */\n reactivity?: ReactCompilerReactivity;\n /** Write a machine-readable compiler coverage report after a production build. */\n report?: boolean;\n /** Project-relative report location. Providing it also enables reporting. */\n reportFile?: string;\n}\n\nexport interface ReactRendererOptions {\n /**\n * Farm's AOT compiler. `true` enables automatic inference; an object\n * customizes selection. Unsupported components always stay on React.\n */\n compiler?: boolean | ReactCompilerOptions;\n experimental?: {\n /** @deprecated Use the top-level `compiler` option. */\n compiler?: boolean | ReactCompilerOptions;\n };\n}\n\nexport interface NormalizedReactCompilerOptions {\n mode: ReactCompilerMode;\n directive: string;\n onUnsupported: UnsupportedCompilerBehavior;\n reactivity: ReactCompilerReactivity;\n report: boolean;\n reportFile: string;\n}\n\nexport const DEFAULT_COMPILER_DIRECTIVE = \"use compiler\";\nexport const DEFAULT_COMPILER_REPORT_FILE = \".farm/react-compiler.json\";\n\nfunction normalizeCompilerReportFile(value: unknown): string {\n if (value === undefined) return DEFAULT_COMPILER_REPORT_FILE;\n if (typeof value !== \"string\" || !value.trim()) {\n throw new TypeError(\"The React compiler report file must be a non-empty relative path.\");\n }\n const normalized = value.trim().replace(/\\\\/g, \"/\");\n if (\n normalized.startsWith(\"/\") ||\n /^[A-Za-z]:\\//.test(normalized) ||\n normalized.split(\"/\").includes(\"..\")\n ) {\n throw new TypeError(\"The React compiler report file must stay inside the project root.\");\n }\n return normalized;\n}\n\nexport function normalizeReactCompilerOptions(\n value: true | ReactCompilerOptions,\n): NormalizedReactCompilerOptions {\n const options = value === true ? {} : value;\n const mode = options.mode || \"infer\";\n\n if (mode !== \"infer\" && mode !== \"annotation\") {\n throw new TypeError(`Unknown React compiler mode: ${String(mode)}`);\n }\n\n if (options.directive !== undefined && mode !== \"annotation\") {\n throw new TypeError(\"The React compiler directive can only be configured in annotation mode.\");\n }\n\n const directive = options.directive?.trim() || DEFAULT_COMPILER_DIRECTIVE;\n const onUnsupported = options.onUnsupported || \"fallback\";\n if (!([\"fallback\", \"warn\", \"error\"] as const).includes(onUnsupported)) {\n throw new TypeError(`Unknown unsupported-component behavior: ${String(onUnsupported)}`);\n }\n\n const reactivity = options.reactivity || \"hybrid\";\n if (reactivity !== \"static\" && reactivity !== \"hybrid\") {\n throw new TypeError(`Unknown React compiler reactivity mode: ${String(reactivity)}`);\n }\n\n if (options.report !== undefined && typeof options.report !== \"boolean\") {\n throw new TypeError(\"The React compiler report option must be a boolean.\");\n }\n if (options.report === false && options.reportFile !== undefined) {\n throw new TypeError(\n \"A React compiler report file cannot be configured when reporting is false.\",\n );\n }\n const reportFile = normalizeCompilerReportFile(options.reportFile);\n const report = options.report === true || options.reportFile !== undefined;\n\n return { mode, directive, onUnsupported, reactivity, report, reportFile };\n}\n\nconst REACT_RENDERER: Readonly<FarmRenderer> = Object.freeze({\n name: \"react\",\n vite: \"@farm.js/react/vite\",\n server: \"@farm.js/react/server\",\n client: \"@farm.js/react/client\",\n jsxImportSource: \"react\",\n dedupe: [\"react\", \"react-dom\", \"react/jsx-runtime\", \"react/jsx-dev-runtime\"],\n optimizeDeps: [\n \"react\",\n \"react-dom\",\n \"react-dom/client\",\n \"react/jsx-runtime\",\n \"react/jsx-dev-runtime\",\n \"@farm.js/react/compiler-runtime\",\n ],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n node: true,\n web: false,\n runtimes: { edge: { node: false, web: true } },\n },\n functionComponents: true,\n },\n});\n\n/** Select React and optionally enable Farm's AOT compiler. */\nexport function react(options: ReactRendererOptions = {}): FarmRenderer {\n const compiler = resolveCompilerOption(options, true);\n const normalizedCompiler = compiler ? normalizeReactCompilerOptions(compiler) : false;\n\n return {\n ...REACT_RENDERER,\n dedupe: [...(REACT_RENDERER.dedupe || [])],\n optimizeDeps: [...(REACT_RENDERER.optimizeDeps || [])],\n capabilities: {\n reconcilesRerenders: true,\n streaming: {\n ...REACT_RENDERER.capabilities?.streaming,\n runtimes: {\n edge: { ...REACT_RENDERER.capabilities?.streaming?.runtimes?.edge },\n },\n },\n functionComponents: true,\n },\n options: {\n compiler: normalizedCompiler,\n },\n };\n}\n\nexport { REACT_RENDERER };\nexport type { FarmRenderer } from \"@farm.js/core/renderer\";\n"]}
package/dist/list.cjs CHANGED
@@ -6,9 +6,32 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
6
 
7
7
  var React__default = /*#__PURE__*/_interopDefault(React);
8
8
 
9
+ // src/list.tsx
10
+
11
+ // src/iterable.ts
12
+ var oneShotSnapshots = /* @__PURE__ */ new WeakMap();
13
+ var arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();
14
+ function materializeIterable(source) {
15
+ if (source == null) return [];
16
+ if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
17
+ const items2 = [];
18
+ for (let index = 0; index < source.length; index += 1) items2.push(source[index]);
19
+ return items2;
20
+ }
21
+ const iterator = source[Symbol.iterator]();
22
+ const oneShot = iterator === source && (typeof source === "object" || typeof source === "function");
23
+ if (oneShot) {
24
+ const cached = oneShotSnapshots.get(source);
25
+ if (cached) return cached;
26
+ }
27
+ const items = Array.from({ [Symbol.iterator]: () => iterator });
28
+ if (oneShot) oneShotSnapshots.set(source, items);
29
+ return items;
30
+ }
31
+
9
32
  // src/list.tsx
10
33
  function List({ each, by, children }) {
11
- const rows = each ? Array.from(each) : [];
34
+ const rows = materializeIterable(each);
12
35
  return React__default.default.createElement(
13
36
  React__default.default.Fragment,
14
37
  null,
package/dist/list.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/list.tsx"],"names":["React"],"mappings":";;;;;;;;;AAkBO,SAAS,IAAA,CAAW,EAAE,IAAA,EAAM,EAAA,EAAI,UAAS,EAAwC;AACtF,EAAA,MAAM,OAAO,IAAA,GAAO,KAAA,CAAM,IAAA,CAAK,IAAI,IAAI,EAAC;AACxC,EAAA,OAAOA,sBAAA,CAAM,aAAA;AAAA,IACXA,sBAAA,CAAM,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,IAAA,CAAK,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU;AAC3B,MAAA,MAAM,GAAA,GAAM,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA;AAChC,MAAA,IAAI,CAACA,sBAAA,CAAM,cAAA,CAAe,GAAG,CAAA,EAAG;AAC9B,QAAA,MAAM,IAAI,UAAU,6DAA6D,CAAA;AAAA,MACnF;AACA,MAAA,OAAOA,sBAAA,CAAM,aAAa,GAAA,EAAK,EAAE,KAAK,EAAA,CAAG,IAAA,EAAM,KAAK,CAAA,EAAuB,CAAA;AAAA,IAC7E,CAAC;AAAA,GACH;AACF","file":"list.cjs","sourcesContent":["import React from \"react\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = each ? Array.from(each) : [];\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}
1
+ {"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["items","React"],"mappings":";;;;;;;;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;AAEjE,IAAM,gCAAiC,CAAA,MAAM,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,QAAQ,CAAA,GAAG;AAGxE,SAAS,oBAA0B,MAAA,EAAmD;AAC3F,EAAA,IAAI,MAAA,IAAU,IAAA,EAAM,OAAO,EAAC;AAE5B,EAAA,IACE,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,IACpB,OAAO,cAAA,CAAe,MAAM,CAAA,KAAM,KAAA,CAAM,SAAA,IACxC,MAAA,CAAO,MAAA,CAAO,QAAQ,MAAM,aAAA,EAC5B;AACA,IAAA,MAAMA,SAAgB,EAAC;AACvB,IAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,MAAA,CAAO,MAAA,EAAQ,KAAA,IAAS,CAAA,EAAGA,MAAAA,CAAM,IAAA,CAAK,MAAA,CAAO,KAAK,CAAC,CAAA;AAC/E,IAAA,OAAOA,MAAAA;AAAA,EACT;A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/* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();\n\n/** Materialize an iterable without consuming a one-shot iterator more than once. */\nexport function materializeIterable<Item>(source: Iterable<Item> | null | undefined): Item[] {\n if (source == null) return [];\n // A plain array iterates by index, so copy it without the iterator protocol.\n if (\n Array.isArray(source) &&\n Object.getPrototypeOf(source) === Array.prototype &&\n source[Symbol.iterator] === arrayIterator\n ) {\n const items: Item[] = [];\n for (let index = 0; index < source.length; index += 1) items.push(source[index]);\n return items;\n }\n\n const iterator = source[Symbol.iterator]();\n const oneShot =\n iterator === (source as unknown) &&\n (typeof source === \"object\" || typeof source === \"function\");\n if (oneShot) {\n const cached = oneShotSnapshots.get(source as object);\n if (cached) return cached as Item[];\n }\n\n const items = Array.from({ [Symbol.iterator]: () => iterator });\n if (oneShot) oneShotSnapshots.set(source as object, items);\n return items;\n}\n","import React from \"react\";\nimport { materializeIterable } from \"./iterable\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = materializeIterable(each);\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}
package/dist/list.mjs CHANGED
@@ -1,8 +1,31 @@
1
1
  import React from 'react';
2
2
 
3
+ // src/list.tsx
4
+
5
+ // src/iterable.ts
6
+ var oneShotSnapshots = /* @__PURE__ */ new WeakMap();
7
+ var arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();
8
+ function materializeIterable(source) {
9
+ if (source == null) return [];
10
+ if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
11
+ const items2 = [];
12
+ for (let index = 0; index < source.length; index += 1) items2.push(source[index]);
13
+ return items2;
14
+ }
15
+ const iterator = source[Symbol.iterator]();
16
+ const oneShot = iterator === source && (typeof source === "object" || typeof source === "function");
17
+ if (oneShot) {
18
+ const cached = oneShotSnapshots.get(source);
19
+ if (cached) return cached;
20
+ }
21
+ const items = Array.from({ [Symbol.iterator]: () => iterator });
22
+ if (oneShot) oneShotSnapshots.set(source, items);
23
+ return items;
24
+ }
25
+
3
26
  // src/list.tsx
4
27
  function List({ each, by, children }) {
5
- const rows = each ? Array.from(each) : [];
28
+ const rows = materializeIterable(each);
6
29
  return React.createElement(
7
30
  React.Fragment,
8
31
  null,
package/dist/list.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/list.tsx"],"names":[],"mappings":";;;AAkBO,SAAS,IAAA,CAAW,EAAE,IAAA,EAAM,EAAA,EAAI,UAAS,EAAwC;AACtF,EAAA,MAAM,OAAO,IAAA,GAAO,KAAA,CAAM,IAAA,CAAK,IAAI,IAAI,EAAC;AACxC,EAAA,OAAO,KAAA,CAAM,aAAA;AAAA,IACX,KAAA,CAAM,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,IAAA,CAAK,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU;AAC3B,MAAA,MAAM,GAAA,GAAM,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA;AAChC,MAAA,IAAI,CAAC,KAAA,CAAM,cAAA,CAAe,GAAG,CAAA,EAAG;AAC9B,QAAA,MAAM,IAAI,UAAU,6DAA6D,CAAA;AAAA,MACnF;AACA,MAAA,OAAO,KAAA,CAAM,aAAa,GAAA,EAAK,EAAE,KAAK,EAAA,CAAG,IAAA,EAAM,KAAK,CAAA,EAAuB,CAAA;AAAA,IAC7E,CAAC;AAAA,GACH;AACF","file":"list.mjs","sourcesContent":["import React from \"react\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = each ? Array.from(each) : [];\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}
1
+ {"version":3,"sources":["../src/iterable.ts","../src/list.tsx"],"names":["items"],"mappings":";;;;;AAAA,IAAM,gBAAA,uBAAuB,OAAA,EAAoC;AAEjE,IAAM,gCAAiC,CAAA,MAAM,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,QAAQ,CAAA,GAAG;AAGxE,SAAS,oBAA0B,MAAA,EAAmD;AAC3F,EAAA,IAAI,MAAA,IAAU,IAAA,EAAM,OAAO,EAAC;AAE5B,EAAA,IACE,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,IACpB,OAAO,cAAA,CAAe,MAAM,CAAA,KAAM,KAAA,CAAM,SAAA,IACxC,MAAA,CAAO,MAAA,CAAO,QAAQ,MAAM,aAAA,EAC5B;AACA,IAAA,MAAMA,SAAgB,EAAC;AACvB,IAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,MAAA,CAAO,MAAA,EAAQ,KAAA,IAAS,CAAA,EAAGA,MAAAA,CAAM,IAAA,CAAK,M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ourcesContent":["const oneShotSnapshots = new WeakMap<object, readonly unknown[]>();\n\nconst arrayIterator = /* @__PURE__ */ (() => Array.prototype[Symbol.iterator])();\n\n/** Materialize an iterable without consuming a one-shot iterator more than once. */\nexport function materializeIterable<Item>(source: Iterable<Item> | null | undefined): Item[] {\n if (source == null) return [];\n // A plain array iterates by index, so copy it without the iterator protocol.\n if (\n Array.isArray(source) &&\n Object.getPrototypeOf(source) === Array.prototype &&\n source[Symbol.iterator] === arrayIterator\n ) {\n const items: Item[] = [];\n for (let index = 0; index < source.length; index += 1) items.push(source[index]);\n return items;\n }\n\n const iterator = source[Symbol.iterator]();\n const oneShot =\n iterator === (source as unknown) &&\n (typeof source === \"object\" || typeof source === \"function\");\n if (oneShot) {\n const cached = oneShotSnapshots.get(source as object);\n if (cached) return cached as Item[];\n }\n\n const items = Array.from({ [Symbol.iterator]: () => iterator });\n if (oneShot) oneShotSnapshots.set(source as object, items);\n return items;\n}\n","import React from \"react\";\nimport { materializeIterable } from \"./iterable\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = materializeIterable(each);\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}