@gtkx/config 2.0.0 → 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.
package/src/config.ts CHANGED
@@ -123,6 +123,12 @@ type Config = {
123
123
  * @defaultValue `{}`: every deprecation warning is shown
124
124
  */
125
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;
126
132
  };
127
133
  /** A {@link Config} whose `applicationId` is known, as loaded for an application. */
128
134
  type ApplicationConfig = Config & { applicationId: string };
@@ -258,6 +264,18 @@ type DeprecationsOptions = {
258
264
  silence?: never[] | undefined;
259
265
  };
260
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
+ };
278
+
261
279
  type McpSettings = {
262
280
  tools: string[];
263
281
  isReadOnly: boolean;
@@ -276,6 +294,8 @@ type ResolvedConfig = {
276
294
  * `notify` stays suppressed only for the property being written.
277
295
  */
278
296
  userEventSignals: Record<string, string[]>;
297
+ /** The `future` flags, each resolved to whether it is on. */
298
+ future: { v3ControlledRestore: boolean };
279
299
  /** Path of the module exporting per-element configs, or `null` when none is configured. */
280
300
  elements: string | null;
281
301
  /** GLib type names of the elements marked `isLazy`, whose GObject their parent container creates. */
@@ -380,17 +400,19 @@ const mcpSchema = z.strictObject({
380
400
  readOnly: z.boolean({ error: "must be a boolean" }).optional(),
381
401
  }) satisfies z.ZodType<McpOptions>;
382
402
 
383
- const graduatedFutureSchema = z
384
- .object({
385
- v2ByteArrays: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
386
- v2ValueReturns: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
387
- v2FinishResults: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
388
- v2InoutReturns: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
389
- v2ResourceImports: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
390
- v2DefaultLibraries: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
391
- v2TreeShaking: z.literal(true, { error: "can only be true; remove the flag" }).optional(),
392
- })
393
- .strict();
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(),
415
+ });
394
416
 
395
417
  const deprecationsSchema = z.strictObject({
396
418
  silence: z
@@ -414,6 +436,7 @@ const configSchema = z.strictObject({
414
436
  agents: agentsSchema.optional(),
415
437
  mcp: mcpSchema.optional(),
416
438
  deprecations: deprecationsSchema.optional(),
439
+ future: futureSchema.optional(),
417
440
  }) satisfies z.ZodType<Config>;
418
441
 
419
442
  /**
@@ -459,7 +482,9 @@ const graduatedFutureKeys = (config: unknown): string[] => {
459
482
  return [];
460
483
  }
461
484
 
462
- 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));
463
488
  };
464
489
 
465
490
  /**
@@ -524,6 +549,7 @@ const resolveConfig = (config: ApplicationConfig, translationDomain: string, roo
524
549
  translationDomain,
525
550
  reactCompiler: resolveReactCompilerOptions(config.reactCompiler),
526
551
  userEventSignals: resolveUserEventSignals(config.userEventSignals),
552
+ future: { v3ControlledRestore: config.future?.v3ControlledRestore === true },
527
553
  elements: resolveElementsModule(config.elements?.behaviors, root),
528
554
  lazyElements: resolveLazyElements(config.elements),
529
555
  });
@@ -549,6 +575,7 @@ export {
549
575
  type AgentsOptions,
550
576
  type DeprecationsOptions,
551
577
  type ElementsOptions,
578
+ type FutureOptions,
552
579
  type McpOptions,
553
580
  type McpSettings,
554
581
  type ReactCompilerOptions,
@@ -0,0 +1,116 @@
1
+ import { upperFirst } from "@gtkx/utils";
2
+
3
+ /** How GTKX keeps one controlled prop at its rendered value. */
4
+ type ControlledProp = {
5
+ /** Signal the widget emits when the user changes the prop. */
6
+ signal: string;
7
+ /**
8
+ * Other signals the widget emits for the same change, such as a notebook's `switch-page`. In development, an
9
+ * element that passes the prop warns unless it has a handler for one of these, for `signal`, or for the prop's
10
+ * notification, which a bare `onNotify` also receives.
11
+ */
12
+ reportedBy?: string[];
13
+ /**
14
+ * Prop of the widget the user changes the value through, the element itself or the text view showing a buffer,
15
+ * that keeps the user from changing it while false, such as `editable` for text. In development, an element whose
16
+ * widget has it set to false does not warn about a missing handler.
17
+ */
18
+ enabledBy?: string;
19
+ /**
20
+ * Props holding the lowest and highest value the widget currently accepts. GTKX writes the rendered value clamped
21
+ * to them, and checks it again whenever they change, so a value out of reach settles on the nearest one the widget
22
+ * accepts and returns once it comes into reach.
23
+ */
24
+ range?: [min: string, max: string];
25
+ /**
26
+ * Whether the value is the `name` of one of the element's children, or of the page the element creates for one,
27
+ * such as the page a preferences dialog shows. GTKX then leaves it out of construction, writes it only while a
28
+ * child the element holds has that name, and writes it again when a child with that name is placed, so a page
29
+ * rendered after the element or removed and added back is shown, with or without `future.v3ControlledRestore`.
30
+ */
31
+ namesChild?: boolean;
32
+ /**
33
+ * Property of the element holding the list model of the children the value is a position among, such as a
34
+ * notebook's `pages`. GTKX then writes the value again when placing children adds the one at that position to that
35
+ * model, so a page rendered after the element or removed and added back is the one selected, with or without
36
+ * `future.v3ControlledRestore`.
37
+ */
38
+ positionIn?: string;
39
+ /**
40
+ * Signal through which the user asks for a change that could not be undone, such as closing a window, which
41
+ * destroys it. Once the app's own handlers have run, GTKX stops the signal by returning `true`, so only the app
42
+ * makes the change, by rendering it.
43
+ */
44
+ refusedSignal?: string;
45
+ /**
46
+ * Prop that lets the widget make the change the refused signal asks for itself, before GTKX can refuse it, as
47
+ * `hideOnClose` hides a window. While it is `false`, the prop never changes when the user asks, so only the refused
48
+ * signal's handler reports the request.
49
+ */
50
+ refusedUnless?: string;
51
+ /**
52
+ * Whether writing the prop shows something anchored to the widget, such as a menu button's popover, which the
53
+ * compositor only places once the widget is mapped in a window that has painted a frame. With or without
54
+ * `future.v3ControlledRestore`, GTKX leaves the prop out of construction and writes `true` only then, and an
55
+ * `Activity` boundary that hides the widget closes it and opens it again on reveal.
56
+ */
57
+ isAnchored?: boolean;
58
+ };
59
+
60
+ /**
61
+ * Props that hold state the user edits, keyed by GLib type name. Under `future.v3ControlledRestore`, GTKX restores
62
+ * each one to its rendered value after every change the user makes. Every element that has one also takes its
63
+ * `default*` prop, named by {@link defaultPropName}. Subtypes inherit the entries of their ancestors and interfaces.
64
+ */
65
+ const CONTROLLED_PROPS: Record<string, Record<string, ControlledProp>> = {
66
+ AdwComboRow: { selected: { signal: "notify::selected", reportedBy: ["notify::selected-item"] } },
67
+ AdwExpanderRow: {
68
+ enableExpansion: { signal: "notify::enable-expansion", enabledBy: "showEnableSwitch" },
69
+ expanded: { signal: "notify::expanded" },
70
+ },
71
+ AdwPreferencesDialog: {
72
+ visiblePageName: {
73
+ signal: "notify::visible-page-name",
74
+ reportedBy: ["notify::visible-page"],
75
+ namesChild: true,
76
+ },
77
+ },
78
+ AdwPreferencesWindow: {
79
+ visiblePageName: {
80
+ signal: "notify::visible-page-name",
81
+ reportedBy: ["notify::visible-page"],
82
+ namesChild: true,
83
+ },
84
+ },
85
+ AdwSidebar: {
86
+ selected: {
87
+ signal: "notify::selected",
88
+ reportedBy: ["notify::selected-item", "activated"],
89
+ positionIn: "items",
90
+ },
91
+ },
92
+ AdwSpinRow: { value: { signal: "notify::value", reportedBy: ["changed"] } },
93
+ AdwSwitchRow: { active: { signal: "notify::active" } },
94
+ GtkAdjustment: { value: { signal: "value-changed" } },
95
+ GtkCheckButton: { active: { signal: "toggled" } },
96
+ GtkDropDown: { selected: { signal: "notify::selected", reportedBy: ["notify::selected-item"] } },
97
+ GtkEditable: { text: { signal: "changed", enabledBy: "editable" } },
98
+ GtkExpander: { expanded: { signal: "notify::expanded" } },
99
+ GtkMenuButton: { active: { signal: "notify::active", isAnchored: true } },
100
+ GtkNotebook: { page: { signal: "notify::page", reportedBy: ["switch-page"], positionIn: "pages" } },
101
+ GtkPaned: { position: { signal: "notify::position", range: ["minPosition", "maxPosition"] } },
102
+ GtkPopover: { visible: { signal: "notify::visible", reportedBy: ["closed"] } },
103
+ GtkSpinButton: { value: { signal: "value-changed", reportedBy: ["changed"] } },
104
+ GtkSwitch: { active: { signal: "notify::active", reportedBy: ["state-set"] } },
105
+ GtkTextBuffer: { text: { signal: "changed", enabledBy: "editable" } },
106
+ GtkToggleButton: { active: { signal: "toggled", reportedBy: ["clicked"] } },
107
+ GtkWindow: { visible: { signal: "notify::visible", refusedSignal: "close-request", refusedUnless: "hideOnClose" } },
108
+ };
109
+
110
+ /**
111
+ * The prop that gives the controlled prop `name` its value when the element is created and then leaves it to the
112
+ * widget, such as `defaultText` for `text`.
113
+ */
114
+ const defaultPropName = (name: string): string => `default${upperFirst(name)}`;
115
+
116
+ export { CONTROLLED_PROPS, defaultPropName, type ControlledProp };
package/src/deploy.ts CHANGED
@@ -887,8 +887,8 @@ type DeployOptions = {
887
887
  */
888
888
  architectures?: ("arm64" | "x64")[] | undefined;
889
889
  /**
890
- * Deployment directory relative to the project root, with packages in its `out` directory. `gtkx deploy
891
- * --out` overrides it.
890
+ * Deployment directory relative to the project root, with packages in its `out` directory. It must be below
891
+ * the project root and outside `.gtkx`, which GTKX reserves for generated files. `gtkx deploy --out` overrides it.
892
892
  *
893
893
  * @defaultValue `"build"`
894
894
  */
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export {
12
12
  type ElementConfigOptions,
13
13
  type ElementPropsExport,
14
14
  type ElementsOptions,
15
+ type FutureOptions,
15
16
  type McpOptions,
16
17
  mergeConfig,
17
18
  type ModuleExport,
@@ -23,8 +23,10 @@ const DEFAULT_USER_EVENT_SIGNALS: Record<string, string[]> = {
23
23
  GtkSwitch: ["state-set"],
24
24
  GtkTextBuffer: [
25
25
  "apply-tag",
26
+ "begin-user-action",
26
27
  "changed",
27
28
  "delete-range",
29
+ "end-user-action",
28
30
  "insert-child-anchor",
29
31
  "insert-paintable",
30
32
  "insert-text",
package/src/virtual.ts CHANGED
@@ -22,6 +22,7 @@ const renderConfigModule = (config: ResolvedConfig, localeDir: string | null = n
22
22
  `export const localeDir = ${JSON.stringify(localeDir)};`,
23
23
  `export const resourceBasePath = ${JSON.stringify(resourceBasePath(config.applicationId))};`,
24
24
  `export const userEventSignals = ${JSON.stringify(config.userEventSignals)};`,
25
+ `export const future = ${JSON.stringify(config.future)};`,
25
26
  config.elements === null
26
27
  ? `export const elements = ${lazyJson};`
27
28
  : `export const elements = mergeElementConfigs(__elementBehaviors, ${lazyJson});`,