@gtkx/config 2.0.0-beta.9 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +11 -169
  2. package/dist/builtin-elements.d.ts +24 -0
  3. package/dist/builtin-elements.d.ts.map +1 -0
  4. package/dist/builtin-elements.js +376 -0
  5. package/dist/builtin-elements.js.map +1 -0
  6. package/dist/config-dependencies.d.ts +5 -3
  7. package/dist/config-dependencies.d.ts.map +1 -1
  8. package/dist/config-dependencies.js +57 -24
  9. package/dist/config-dependencies.js.map +1 -1
  10. package/dist/config-error.d.ts.map +1 -1
  11. package/dist/config-error.js.map +1 -1
  12. package/dist/config-reloader.d.ts +8 -0
  13. package/dist/config-reloader.d.ts.map +1 -0
  14. package/dist/config-reloader.js +32 -0
  15. package/dist/config-reloader.js.map +1 -0
  16. package/dist/config-source.d.ts +9 -0
  17. package/dist/config-source.d.ts.map +1 -0
  18. package/dist/config-source.js +35 -0
  19. package/dist/config-source.js.map +1 -0
  20. package/dist/config.d.ts +310 -53
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/config.js +52 -32
  23. package/dist/config.js.map +1 -1
  24. package/dist/controlled-props.d.ts +69 -0
  25. package/dist/controlled-props.d.ts.map +1 -0
  26. package/dist/controlled-props.js +57 -0
  27. package/dist/controlled-props.js.map +1 -0
  28. package/dist/deploy.d.ts +949 -20
  29. package/dist/deploy.d.ts.map +1 -1
  30. package/dist/deploy.js +17 -15
  31. package/dist/deploy.js.map +1 -1
  32. package/dist/index.d.ts +8 -3
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +6 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal.d.ts +5 -3
  37. package/dist/internal.d.ts.map +1 -1
  38. package/dist/internal.js +5 -3
  39. package/dist/internal.js.map +1 -1
  40. package/dist/loader.d.ts +23 -5
  41. package/dist/loader.d.ts.map +1 -1
  42. package/dist/loader.js +58 -42
  43. package/dist/loader.js.map +1 -1
  44. package/dist/node-version.d.ts +2 -1
  45. package/dist/node-version.d.ts.map +1 -1
  46. package/dist/node-version.js +2 -1
  47. package/dist/node-version.js.map +1 -1
  48. package/dist/resource-base-path.d.ts.map +1 -1
  49. package/dist/schema-text.d.ts.map +1 -1
  50. package/dist/user-event-signals.d.ts.map +1 -1
  51. package/dist/user-event-signals.js +2 -0
  52. package/dist/user-event-signals.js.map +1 -1
  53. package/dist/virtual.d.ts +1 -1
  54. package/dist/virtual.d.ts.map +1 -1
  55. package/dist/virtual.js +5 -4
  56. package/dist/virtual.js.map +1 -1
  57. package/dist/vite-plugin.d.ts +7 -0
  58. package/dist/vite-plugin.d.ts.map +1 -1
  59. package/dist/vite-plugin.js +13 -4
  60. package/dist/vite-plugin.js.map +1 -1
  61. package/dist/vite-root.d.ts.map +1 -1
  62. package/package.json +15 -16
  63. package/src/builtin-elements.ts +388 -0
  64. package/src/config-dependencies.ts +65 -29
  65. package/src/config-error.ts +5 -3
  66. package/src/config-reloader.ts +45 -0
  67. package/src/config-source.ts +52 -0
  68. package/src/config.ts +355 -61
  69. package/src/controlled-props.ts +116 -0
  70. package/src/deploy.ts +1029 -59
  71. package/src/index.ts +48 -3
  72. package/src/internal.ts +6 -2
  73. package/src/loader.ts +103 -54
  74. package/src/node-version.ts +2 -1
  75. package/src/user-event-signals.ts +2 -0
  76. package/src/virtual.ts +7 -6
  77. package/src/vite-plugin.ts +24 -5
package/src/config.ts CHANGED
@@ -3,16 +3,24 @@ import { defu } from "defu";
3
3
  import { resolve } from "node:path";
4
4
  import { z } from "zod";
5
5
  import { configError, isRecord } from "./config-error.ts";
6
- import { deploySchema } from "./deploy.ts";
6
+ import { type DeployOptions, deploySchema } from "./deploy.ts";
7
7
  import { girLibrary, text } from "./schema-text.ts";
8
8
  import { resolveUserEventSignals } from "./user-event-signals.ts";
9
9
 
10
10
  /** Object form of the `reactCompiler` config key, forwarded to `babel-plugin-react-compiler`. */
11
11
  type ReactCompilerOptions = {
12
- /** Which functions the compiler processes. */
13
- compilationMode?: (typeof COMPILATION_MODES)[number];
14
- /** Which compiler diagnostics fail the build. */
15
- panicThreshold?: (typeof PANIC_THRESHOLDS)[number];
12
+ /**
13
+ * Which functions the React Compiler processes.
14
+ *
15
+ * @defaultValue `"infer"`, the React Compiler's own default
16
+ */
17
+ compilationMode?: "all" | "annotation" | "infer" | "syntax" | undefined;
18
+ /**
19
+ * Which React Compiler diagnostics fail the build.
20
+ *
21
+ * @defaultValue `"none"`, the React Compiler's own default
22
+ */
23
+ panicThreshold?: "all_errors" | "critical_errors" | "none" | undefined;
16
24
  };
17
25
 
18
26
  /**
@@ -25,14 +33,248 @@ type ResolvedReactCompilerOptions = ReactCompilerOptions & {
25
33
  };
26
34
 
27
35
  /**
28
- * User-facing configuration for a GTKX project, as authored in `gtkx.config.ts`: the GIR libraries
29
- * to bind and where to find them, the GApplication id, per-element configuration, the React
30
- * Compiler, codegen, and user event signal settings, and the `agents` and `mcp` blocks controlling
31
- * what coding agents are given.
36
+ * GTKX project configuration authored in `gtkx.config.ts` and validated when loaded.
37
+ *
38
+ * [Configuration and Codegen](https://gtkx.dev/v2/guide/configuration-and-codegen) shows how to set up the file
39
+ * and what codegen generates from it.
32
40
  */
33
- type Config = z.infer<typeof configSchema>;
34
- type ModuleExport = z.infer<typeof moduleExportSchema>;
35
- type ElementConfigEntry = z.infer<typeof elementConfigSchema>;
41
+ type Config = {
42
+ /**
43
+ * Additional GIR libraries to bind, such as `WebKit-6.0`.
44
+ * Adwaita and GTK are included implicitly and must not be listed.
45
+ *
46
+ * @defaultValue None: GTKX binds `Adw-1`, `Gtk-4.0` and the libraries they depend on
47
+ */
48
+ libraries?: string[] | undefined;
49
+ /**
50
+ * Additional GIR search directories, searched before the system ones. Relative paths are resolved from the
51
+ * project root.
52
+ *
53
+ * @defaultValue None: GTKX searches `/usr/share/gir-1.0` and the GIR directories pkg-config reports for
54
+ * `gobject-introspection-1.0`
55
+ */
56
+ girPath?: string[] | undefined;
57
+ /**
58
+ * GApplication identifier, such as `com.example.Tasks`. Required to run, build or deploy the project as an
59
+ * application; a package that is not an application, such as a component library, leaves it out.
60
+ *
61
+ * @defaultValue None: the project loads as a package, with `isApplication` set to `false`
62
+ */
63
+ applicationId?: string | undefined;
64
+ /**
65
+ * Whether to enable the React Compiler, or options passed to it. `false` disables it.
66
+ *
67
+ * @defaultValue `true`
68
+ * @example
69
+ * ```ts
70
+ * reactCompiler: { compilationMode: "annotation" },
71
+ * ```
72
+ */
73
+ reactCompiler?: boolean | ReactCompilerOptions | undefined;
74
+ /**
75
+ * Whether GTKX generates project bindings. Set to `false` to reuse an installed binding store.
76
+ *
77
+ * @defaultValue `true`
78
+ */
79
+ codegen?: boolean | undefined;
80
+ /**
81
+ * Additional signals to suppress during React property updates, keyed by GLib type name.
82
+ * Entries extend the built-in signal lists.
83
+ *
84
+ * @defaultValue `{}`: only the built-in lists
85
+ */
86
+ userEventSignals?: Record<string, string[]> | undefined;
87
+ /**
88
+ * Custom element behaviors and overrides for generated components, props, and documentation.
89
+ *
90
+ * @defaultValue `{}`: no custom behaviors or overrides
91
+ */
92
+ elements?: ElementsOptions | undefined;
93
+ /**
94
+ * Path to an icon theme directory or a single SVG, PNG or XPM application icon file, relative to the project
95
+ * root. Deployment requires an icon.
96
+ *
97
+ * @defaultValue The one `<applicationId>.svg`, `.png` or `.xpm` file in the project root, if exactly one
98
+ * exists
99
+ */
100
+ applicationIcon?: string | undefined;
101
+ /**
102
+ * Application metadata, bundled runtime settings, and packaging options used by `gtkx deploy`.
103
+ *
104
+ * @defaultValue `{}`: metadata comes from `package.json` and packaging builds a Flatpak
105
+ */
106
+ deploy?: DeployOptions | undefined;
107
+ /**
108
+ * Controls the project instructions and reference files generated for coding agents.
109
+ *
110
+ * @defaultValue `{}`: an application gets both, a package neither
111
+ */
112
+ agents?: AgentsOptions | undefined;
113
+ /**
114
+ * Default tool selection and access mode for the project's MCP server. The `gtkx mcp` flags `--tools` and
115
+ * `--read-only` take precedence.
116
+ *
117
+ * @defaultValue `{}`: every tool, app interactions included
118
+ */
119
+ mcp?: McpOptions | undefined;
120
+ /**
121
+ * Controls warnings for deprecated configuration and behavior.
122
+ *
123
+ * @defaultValue `{}`: every deprecation warning is shown
124
+ */
125
+ deprecations?: DeprecationsOptions | undefined;
126
+ /**
127
+ * Opts into behavior that becomes the default in the next major version.
128
+ *
129
+ * @defaultValue `{}`: every flag is off
130
+ */
131
+ future?: FutureOptions | undefined;
132
+ };
133
+ /** A {@link Config} whose `applicationId` is known, as loaded for an application. */
134
+ type ApplicationConfig = Config & { applicationId: string };
135
+
136
+ /** A named export of a module, which `elements.config` entries reference for components and props. */
137
+ type ModuleExport = {
138
+ /** Module specifier containing the named export; relative paths start at the project root. */
139
+ module: string;
140
+ /** Name of the export to import from the module. */
141
+ export: string;
142
+ };
143
+
144
+ /** The props type an `elements.config` entry adds to a generated element, and how it combines with them. */
145
+ type ElementPropsExport = {
146
+ /** Module specifier containing the named export; relative paths start at the project root. */
147
+ module: string;
148
+ /** Name of the props type to import from the module. */
149
+ export: string;
150
+ /**
151
+ * How the exported props are combined: `intersection` is inherited; `factory` applies only to this type.
152
+ *
153
+ * @defaultValue `"intersection"`
154
+ */
155
+ composition?: "factory" | "intersection" | undefined;
156
+ /**
157
+ * Props that can only be set when the element is created; changing them afterward throws.
158
+ *
159
+ * @defaultValue `[]`
160
+ */
161
+ constructOnly?: string[] | undefined;
162
+ };
163
+
164
+ /** Overrides for one GLib type in `elements.config`, keyed by its registered type name. */
165
+ type ElementConfigOptions = {
166
+ /**
167
+ * Component export that wraps the generated element.
168
+ *
169
+ * @defaultValue None: no wrapper `component`
170
+ */
171
+ component?: ModuleExport | undefined;
172
+ /**
173
+ * Additional props type to combine with the generated element props.
174
+ *
175
+ * @defaultValue None: no extra `props` type
176
+ */
177
+ props?: ElementPropsExport | undefined;
178
+ /**
179
+ * Whether the parent container creates this element's GObject instead of the element constructing its own.
180
+ * Subtypes inherit the setting.
181
+ *
182
+ * @defaultValue `false`
183
+ */
184
+ isLazy?: boolean | undefined;
185
+ /**
186
+ * Accepted child GLib type names to show in the generated element documentation.
187
+ *
188
+ * @defaultValue `[]`
189
+ */
190
+ acceptedChildTypes?: string[] | undefined;
191
+ /**
192
+ * GObject properties to leave out of generated props, such as properties managed by an element behavior.
193
+ *
194
+ * @defaultValue `[]`: every GObject property becomes a prop
195
+ */
196
+ omittedProps?: string[] | undefined;
197
+ };
198
+
199
+ /** The `elements` options: custom element behaviors and per-type overrides for generated elements. */
200
+ type ElementsOptions = {
201
+ /**
202
+ * Path, relative to the project root, of the module exporting the element behavior map.
203
+ *
204
+ * @defaultValue None: only the behaviors built into `@gtkx/react` apply
205
+ */
206
+ behaviors?: string | undefined;
207
+ /**
208
+ * Element configuration overrides keyed by GLib type name, such as `GtkWidget`.
209
+ *
210
+ * @defaultValue `{}`
211
+ */
212
+ config?: Record<string, ElementConfigOptions> | undefined;
213
+ };
214
+
215
+ /** The `agents` options: which files codegen maintains for coding agents. */
216
+ type AgentsOptions = {
217
+ /**
218
+ * Whether codegen maintains the GTKX rules in `AGENTS.md` and creates a missing `CLAUDE.md` import.
219
+ * `false` removes rules written earlier, deleting `AGENTS.md` and the `CLAUDE.md` import when nothing else
220
+ * remains.
221
+ *
222
+ * @defaultValue `true` for an application, `false` for a package without an `applicationId`
223
+ */
224
+ rules?: boolean | undefined;
225
+ /**
226
+ * Whether codegen writes the generated element reference to `.gtkx/reference` and points the rules at it.
227
+ * `false` removes a reference generated earlier.
228
+ *
229
+ * @defaultValue `true` for an application, `false` for a package without an `applicationId`
230
+ */
231
+ reference?: boolean | undefined;
232
+ };
233
+
234
+ /** The `mcp` options: the tools `gtkx mcp` offers by default and whether it may interact with the app. */
235
+ type McpOptions = {
236
+ /**
237
+ * Tool name patterns applied in order: `*` matches any text and a leading `!` excludes matches.
238
+ * Omitted, empty, or exclusion-only lists start with all tools; other lists start with none.
239
+ * `gtkx mcp --tools` overrides it.
240
+ *
241
+ * @defaultValue `[]`: every tool
242
+ * @example
243
+ * ```ts
244
+ * tools: ["gtkx_*", "!gtkx_take_screenshot"],
245
+ * ```
246
+ */
247
+ tools?: string[] | undefined;
248
+ /**
249
+ * Whether the MCP server exposes only inspection and reference tools, excluding app interactions.
250
+ * `gtkx mcp --read-only` overrides it.
251
+ *
252
+ * @defaultValue `false`
253
+ */
254
+ readOnly?: boolean | undefined;
255
+ };
256
+
257
+ /** The `deprecations` options: which deprecation warnings stay silent. */
258
+ type DeprecationsOptions = {
259
+ /**
260
+ * Deprecation identifiers whose warnings are suppressed. There are currently no accepted identifiers.
261
+ *
262
+ * @defaultValue `[]`
263
+ */
264
+ silence?: never[] | undefined;
265
+ };
266
+
267
+ /** The `future` options: behavior that becomes the default in GTKX 3.0. */
268
+ type FutureOptions = {
269
+ /**
270
+ * Whether props that hold state the user edits, such as `text` on an entry or `active` on a check button, return
271
+ * to their rendered value after every change the user makes, unless a handler renders the new value. Leaving such
272
+ * a prop out, or passing `undefined`, leaves the value to the widget.
273
+ *
274
+ * @defaultValue `false`: these props are written only when their rendered value changes
275
+ */
276
+ v3ControlledRestore?: boolean | undefined;
277
+ };
36
278
 
37
279
  type McpSettings = {
38
280
  tools: string[];
@@ -43,6 +285,8 @@ type McpSettings = {
43
285
  type ResolvedConfig = {
44
286
  /** The GApplication identifier the app registers under. */
45
287
  applicationId: string;
288
+ /** The gettext domain, which is the `applicationId` production builds use. */
289
+ translationDomain: string;
46
290
  /** React Compiler options for the build, or `null` when the compiler is disabled. */
47
291
  reactCompiler: ResolvedReactCompilerOptions | null;
48
292
  /**
@@ -50,6 +294,8 @@ type ResolvedConfig = {
50
294
  * `notify` stays suppressed only for the property being written.
51
295
  */
52
296
  userEventSignals: Record<string, string[]>;
297
+ /** The `future` flags, each resolved to whether it is on. */
298
+ future: { v3ControlledRestore: boolean };
53
299
  /** Path of the module exporting per-element configs, or `null` when none is configured. */
54
300
  elements: string | null;
55
301
  /** GLib type names of the elements marked `isLazy`, whose GObject their parent container creates. */
@@ -58,6 +304,7 @@ type ResolvedConfig = {
58
304
 
59
305
  const APPLICATION_ID_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)+$/;
60
306
  const APPLICATION_ID_MAX_LENGTH = 255;
307
+ const LIBRARY_APPLICATION_ID = "org.gtkx.Library";
61
308
  const IMPLICIT_LIBRARIES: Set<string> = new Set(["Adw-1", "Gtk-4.0"]);
62
309
  /** Compilation modes `babel-plugin-react-compiler` accepts. */
63
310
  const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"] as const;
@@ -65,26 +312,32 @@ const COMPILATION_MODES = ["infer", "syntax", "annotation", "all"] as const;
65
312
  const PANIC_THRESHOLDS = ["none", "critical_errors", "all_errors"] as const;
66
313
  const REACT_COMPILER_TARGET = "19";
67
314
 
68
- const librarySchema = girLibrary('must be of the form "Name-Version", such as "Adw-1"')
69
- .refine((library) => !IMPLICIT_LIBRARIES.has(library), { error: "is bound implicitly; remove it" });
315
+ const librarySchema = girLibrary('must be of the form "Name-Version", such as "Adw-1"').refine(
316
+ (library) => !IMPLICIT_LIBRARIES.has(library),
317
+ { error: "is bound implicitly; remove it" },
318
+ );
70
319
 
71
320
  const librariesSchema = z
72
321
  .array(librarySchema, { error: "must be a non-empty string array or omitted" })
73
322
  .min(1, { error: "must be a non-empty string array or omitted" });
74
323
 
75
324
  const applicationIdSchema = z
76
- .string({ error: "must satisfy g_application_id_is_valid" })
325
+ .string({
326
+ error: (issue) =>
327
+ issue.input === undefined
328
+ ? 'is required to run, build or deploy an application, such as "org.example.MyApp"'
329
+ : "must satisfy g_application_id_is_valid",
330
+ })
77
331
  .refine((value) => isValidApplicationId(value), {
78
332
  error: 'must satisfy g_application_id_is_valid, such as "org.example.MyApp"',
79
333
  });
80
334
 
81
- const reactCompilerSchema = z.union([
82
- z.boolean(),
83
- z.object({
84
- compilationMode: z.enum(COMPILATION_MODES).optional(),
85
- panicThreshold: z.enum(PANIC_THRESHOLDS).optional(),
86
- }),
87
- ]);
335
+ const reactCompilerOptionsSchema = z.strictObject({
336
+ compilationMode: z.enum(COMPILATION_MODES).optional(),
337
+ panicThreshold: z.enum(PANIC_THRESHOLDS).optional(),
338
+ }) satisfies z.ZodType<ReactCompilerOptions>;
339
+
340
+ const reactCompilerSchema = z.union([z.boolean(), reactCompilerOptionsSchema]);
88
341
 
89
342
  const userEventSignalsSchema = z.record(
90
343
  z.string(),
@@ -97,18 +350,24 @@ const userEventSignalsSchema = z.record(
97
350
  { error: "must be a record of GLib type names to signal name arrays" },
98
351
  );
99
352
 
100
- const moduleExportSchema = z.object(
353
+ const moduleExportSchema = z.strictObject(
101
354
  {
102
355
  module: z.string({ error: "must be a module specifier" }).min(1, { error: "must be a module specifier" }),
103
356
  export: z.string({ error: "must be an export name" }).min(1, { error: "must be an export name" }),
104
357
  },
105
358
  { error: "must be a { module, export } object" },
106
- );
359
+ ) satisfies z.ZodType<ModuleExport>;
360
+
361
+ const elementPropsSchema = moduleExportSchema.extend({
362
+ composition: z.enum(["factory", "intersection"]).optional(),
363
+ constructOnly: z.array(z.string()).optional(),
364
+ }) satisfies z.ZodType<ElementPropsExport>;
107
365
 
108
- const elementConfigSchema = z.object({
366
+ const elementConfigSchema = z.strictObject({
109
367
  component: moduleExportSchema.optional(),
110
- props: moduleExportSchema.optional(),
368
+ props: elementPropsSchema.optional(),
111
369
  isLazy: z.boolean({ error: "must be a boolean" }).optional(),
370
+ acceptedChildTypes: z.array(z.string()).optional(),
112
371
  omittedProps: z
113
372
  .array(
114
373
  z.string({ error: "must be a non-empty property name" }).min(1, {
@@ -117,55 +376,57 @@ const elementConfigSchema = z.object({
117
376
  { error: "must be an array of property names" },
118
377
  )
119
378
  .optional(),
120
- });
379
+ }) satisfies z.ZodType<ElementConfigOptions>;
121
380
 
122
- const elementsSchema = z.object({
381
+ const elementsSchema = z.strictObject({
123
382
  behaviors: z
124
383
  .string({ error: "must be a path to a module exporting element behaviors" })
125
384
  .min(1, { error: "must be a path to a module exporting element behaviors" })
126
385
  .optional(),
127
386
  config: z.record(z.string(), elementConfigSchema).optional(),
128
- });
387
+ }) satisfies z.ZodType<ElementsOptions>;
129
388
 
130
- const agentsSchema = z.object({
389
+ const agentsSchema = z.strictObject({
131
390
  rules: z.boolean({ error: "must be a boolean" }).optional(),
132
391
  reference: z.boolean({ error: "must be a boolean" }).optional(),
133
- });
392
+ }) satisfies z.ZodType<AgentsOptions>;
134
393
 
135
- const mcpSchema = z.object({
394
+ const mcpSchema = z.strictObject({
136
395
  tools: z
137
396
  .array(z.string({ error: "must be a tool name pattern" }).min(1, { error: "must be a tool name pattern" }), {
138
397
  error: "must be an array of tool name patterns",
139
398
  })
140
399
  .optional(),
141
400
  readOnly: z.boolean({ error: "must be a boolean" }).optional(),
401
+ }) satisfies z.ZodType<McpOptions>;
402
+
403
+ const futureSchema = z.strictObject({
404
+ v3ControlledRestore: z.boolean({ error: "must be a boolean" }).optional(),
405
+ }) satisfies z.ZodType<FutureOptions>;
406
+
407
+ const graduatedFutureSchema = futureSchema.extend({
408
+ v2ByteArrays: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
409
+ v2ValueReturns: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
410
+ v2FinishResults: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
411
+ v2InoutReturns: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
412
+ v2ResourceImports: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
413
+ v2DefaultLibraries: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
414
+ v2TreeShaking: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
142
415
  });
143
416
 
144
- const graduatedFutureSchema = z
145
- .object({
146
- v2ByteArrays: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
147
- v2ValueReturns: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
148
- v2FinishResults: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
149
- v2InoutReturns: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
150
- v2ResourceImports: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
151
- v2DefaultLibraries: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
152
- v2TreeShaking: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
153
- })
154
- .strict();
155
-
156
- const deprecationsSchema = z.object({
417
+ const deprecationsSchema = z.strictObject({
157
418
  silence: z
158
419
  .array(z.never({ error: "does not name a current deprecation" }), {
159
420
  error: "must be an array of current deprecation ids",
160
421
  })
161
422
  .optional(),
162
- });
423
+ }) satisfies z.ZodType<DeprecationsOptions>;
163
424
 
164
- /** Schema every `gtkx.config.ts` is validated against, and the source of the {@link Config} type. */
165
- const configSchema = z.object({
425
+ /** Schema every `gtkx.config.ts` is validated against. */
426
+ const configSchema = z.strictObject({
166
427
  libraries: librariesSchema.optional(),
167
428
  girPath: z.array(z.string(), { error: "must be an array of strings if provided" }).optional(),
168
- applicationId: applicationIdSchema,
429
+ applicationId: applicationIdSchema.optional(),
169
430
  reactCompiler: reactCompilerSchema.optional(),
170
431
  codegen: z.boolean({ error: "must be a boolean" }).optional(),
171
432
  userEventSignals: userEventSignalsSchema.optional(),
@@ -175,14 +436,18 @@ const configSchema = z.object({
175
436
  agents: agentsSchema.optional(),
176
437
  mcp: mcpSchema.optional(),
177
438
  deprecations: deprecationsSchema.optional(),
178
- });
439
+ future: futureSchema.optional(),
440
+ }) satisfies z.ZodType<Config>;
179
441
 
180
442
  /**
181
443
  * Returns the given configuration unchanged, typed as {@link Config}, so `gtkx.config.ts` gets
182
444
  * autocompletion and type checking.
183
445
  */
184
446
  const defineConfig: DefineConfig<Config> = createDefineConfig<Config>();
185
- const validationSchema = configSchema.extend({ future: graduatedFutureSchema.optional() });
447
+ const validationSchema = configSchema.extend({
448
+ applicationId: applicationIdSchema,
449
+ future: graduatedFutureSchema.optional(),
450
+ });
186
451
 
187
452
  const isValidApplicationId = (applicationId: string): boolean =>
188
453
  applicationId.length <= APPLICATION_ID_MAX_LENGTH && APPLICATION_ID_PATTERN.test(applicationId);
@@ -201,7 +466,10 @@ const resolveReactCompilerOptions = (setting: Config["reactCompiler"]): Resolved
201
466
  };
202
467
  };
203
468
 
204
- const validateConfig = (config: unknown, configFile?: string): void => {
469
+ const validateConfig: (config: unknown, configFile?: string) => asserts config is ApplicationConfig = (
470
+ config,
471
+ configFile,
472
+ ) => {
205
473
  const result = validationSchema.safeParse(config);
206
474
 
207
475
  if (!result.success) {
@@ -214,7 +482,9 @@ const graduatedFutureKeys = (config: unknown): string[] => {
214
482
  return [];
215
483
  }
216
484
 
217
- return Object.keys(config.future).toSorted((first, second) => first.localeCompare(second));
485
+ return Object.keys(config.future)
486
+ .filter((key) => !Object.hasOwn(futureSchema.shape, key))
487
+ .toSorted((first, second) => first.localeCompare(second));
218
488
  };
219
489
 
220
490
  /**
@@ -238,7 +508,7 @@ const resolveLazyElements = (elements: Config["elements"]): string[] =>
238
508
 
239
509
  const elementEntryValues = <T>(
240
510
  elements: Config["elements"],
241
- pick: (entry: ElementConfigEntry) => T | undefined,
511
+ pick: (entry: ElementConfigOptions) => T | undefined,
242
512
  ): Record<string, T> =>
243
513
  Object.fromEntries(
244
514
  Object.entries(elements?.config ?? {}).flatMap(([type, entry]) => {
@@ -248,33 +518,46 @@ const elementEntryValues = <T>(
248
518
  }),
249
519
  );
250
520
 
251
- const resolveElementComponents = (elements: Config["elements"]): Record<string, ModuleExport> =>
252
- elementEntryValues(elements, (entry) => entry.component);
521
+ const resolveModuleSpecifier = <T extends { module: string }>(reference: T, root: string): T =>
522
+ reference.module.startsWith("./") || reference.module.startsWith("../")
523
+ ? { ...reference, module: resolve(root, reference.module) }
524
+ : reference;
525
+
526
+ const resolveElementComponents = (elements: Config["elements"], root: string): Record<string, ModuleExport> =>
527
+ elementEntryValues(elements, (entry) => entry.component && resolveModuleSpecifier(entry.component, root));
528
+
529
+ const resolveElementProps = (elements: Config["elements"], root: string): Record<string, ElementPropsExport> =>
530
+ elementEntryValues(elements, (entry) => entry.props && resolveModuleSpecifier(entry.props, root));
253
531
 
254
- const resolveElementProps = (elements: Config["elements"]): Record<string, ModuleExport> =>
255
- elementEntryValues(elements, (entry) => entry.props);
532
+ const resolveAcceptedChildTypes = (elements: Config["elements"]): Record<string, string[]> =>
533
+ elementEntryValues(elements, (entry) => entry.acceptedChildTypes);
256
534
 
257
535
  const resolveOmittedProps = (elements: Config["elements"]): Record<string, string[]> =>
258
536
  elementEntryValues(elements, (entry) => entry.omittedProps);
259
537
 
260
- const isAgentRulesEnabled = (config: Config): boolean => config.agents?.rules !== false;
261
- const isAgentReferenceEnabled = (config: Config): boolean => config.agents?.reference !== false;
538
+ const isAgentRulesEnabled = (config: Config, isApplication: boolean): boolean => config.agents?.rules ?? isApplication;
539
+ const isAgentReferenceEnabled = (config: Config, isApplication: boolean): boolean =>
540
+ config.agents?.reference ?? isApplication;
262
541
 
263
542
  const resolveMcpSettings = (config: Config): McpSettings => ({
264
543
  tools: config.mcp?.tools ?? [],
265
544
  isReadOnly: config.mcp?.readOnly === true,
266
545
  });
267
546
 
268
- const resolveConfig = (config: Config, root?: string): ResolvedConfig => ({
547
+ const resolveConfig = (config: ApplicationConfig, translationDomain: string, root?: string): ResolvedConfig => ({
269
548
  applicationId: config.applicationId,
549
+ translationDomain,
270
550
  reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
271
551
  userEventSignals: resolveUserEventSignals(config.userEventSignals),
552
+ future: { v3ControlledRestore: config.future?.v3ControlledRestore === true },
272
553
  elements: resolveElementsModule(config.elements?.behaviors, root),
273
554
  lazyElements: resolveLazyElements(config.elements),
274
555
  });
275
556
 
276
557
  export {
558
+ configSchema,
277
559
  APPLICATION_ID_MAX_LENGTH,
560
+ LIBRARY_APPLICATION_ID,
278
561
  defineConfig,
279
562
  isAgentReferenceEnabled,
280
563
  isAgentRulesEnabled,
@@ -285,11 +568,22 @@ export {
285
568
  resolveLazyElements,
286
569
  resolveElementComponents,
287
570
  resolveElementProps,
571
+ resolveAcceptedChildTypes,
288
572
  resolveMcpSettings,
289
573
  resolveOmittedProps,
290
574
  resolveConfig,
575
+ type AgentsOptions,
576
+ type DeprecationsOptions,
577
+ type ElementsOptions,
578
+ type FutureOptions,
579
+ type McpOptions,
291
580
  type McpSettings,
581
+ type ReactCompilerOptions,
292
582
  type ResolvedReactCompilerOptions,
583
+ type ApplicationConfig,
293
584
  type Config,
585
+ type ElementConfigOptions,
586
+ type ElementPropsExport,
587
+ type ModuleExport,
294
588
  type ResolvedConfig,
295
589
  };