@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
@@ -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 };