@gtkx/react 1.4.0 → 1.5.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/README.md CHANGED
@@ -98,7 +98,7 @@ GTK4 is mature, and GtkBuilder XML can lay out a static interface, but nothing r
98
98
  - a React reconciler that exposes every GObject as a JSX element,
99
99
  - a CLI for scaffolding, development, and production builds,
100
100
  - a dev server with Fast Refresh that patches your running UI in place,
101
- - CSS-in-JS styling, React Spring animations, React Navigation stack, tab, drawer, and split view navigators, and high-level list, grid, and dialog components,
101
+ - CSS-in-JS styling, React Hook Form-powered Adwaita controls, gettext-backed react-i18next localization, React Spring animations, React Navigation stack, tab, drawer, and split view navigators, and high-level list, grid, and dialog components,
102
102
  - a Testing Library-style API for querying and driving your widgets in tests,
103
103
  - and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
104
104
 
@@ -1,40 +1,17 @@
1
1
  import * as Adw from "@gtkx/gi/adw";
2
- import { addRemoveSlot, adoptedChildrenSlot, applicationCreator, boxSlot, childMatcher, childSetterSlot, contentSetterSlot, deferred, indexedSlot, list, slot, } from "../reconciler/behaviors.js";
2
+ import { applicationCreator, boxSlot, childMatcher, childSetterSlot, contentSetterSlot, deferred, indexedSlot, list, methodSlot, setterSlot, slot, } from "../reconciler/behaviors.js";
3
3
  import { forTypes, registerElements } from "../reconciler/registry.js";
4
4
  import { BUILTIN_ELEMENTS, CHILD_SETTER_TYPES, CONTENT_SETTER_TYPES } from "./element-config.js";
5
5
  const SLOT_SUFFIX = "Slot";
6
6
  const childSetter = childSetterSlot();
7
7
  const contentSetter = contentSetterSlot();
8
- const breakpoints = slot("breakpoints", "AdwBreakpoint", {
9
- attach: (host, breakpoint) => {
10
- host.addBreakpoint(breakpoint);
11
- },
12
- });
8
+ const breakpoints = methodSlot("breakpoints", "AdwBreakpoint", "addBreakpoint");
13
9
  const prefixSuffix = [
14
- addRemoveSlot("prefix", "GtkWidget", (row, child) => {
15
- row.addPrefix(child);
16
- }, (row, child) => {
17
- row.remove(child);
18
- }),
19
- addRemoveSlot("suffix", "GtkWidget", (row, child) => {
20
- row.addSuffix(child);
21
- }, (row, child) => {
22
- row.remove(child);
23
- }),
10
+ methodSlot("prefix", "GtkWidget", "addPrefix", "remove"),
11
+ methodSlot("suffix", "GtkWidget", "addSuffix", "remove"),
24
12
  ];
25
- const preferencesDialogChildren = addRemoveSlot("children", "AdwPreferencesPage", (dialog, page) => {
26
- dialog.add(page);
27
- }, (dialog, page) => {
28
- dialog.remove(page);
29
- });
30
- const alertDialogExtraChild = slot("children", "GtkWidget", {
31
- attach: (dialog, child) => {
32
- dialog.setExtraChild(child);
33
- },
34
- detach: (dialog) => {
35
- dialog.setExtraChild(null);
36
- },
37
- });
13
+ const preferencesDialogChildren = methodSlot("children", "AdwPreferencesPage", "add", "remove");
14
+ const alertDialogExtraChild = setterSlot("children", "GtkWidget", "setExtraChild");
38
15
  const sidebarSections = indexedSlot("children", "AdwSidebarSection");
39
16
  const sidebarItems = indexedSlot("children", "AdwSidebarItem");
40
17
  const isWidget = childMatcher("GtkWidget");
@@ -90,14 +67,7 @@ const BUILTIN_BEHAVIORS = {
90
67
  },
91
68
  AdwClampScrollable: {
92
69
  behaviors: [
93
- slot("children", "GtkScrollable", {
94
- attach: (clamp, child) => {
95
- clamp.setChild(child);
96
- },
97
- detach: (clamp) => {
98
- clamp.setChild(null);
99
- },
100
- }),
70
+ setterSlot("children", "GtkScrollable", "setChild"),
101
71
  ],
102
72
  },
103
73
  ...forTypes(CHILD_SETTER_TYPES, {
@@ -118,11 +88,7 @@ const BUILTIN_BEHAVIORS = {
118
88
  AdwBreakpointBin: {
119
89
  behaviors: [
120
90
  childSetter,
121
- addRemoveSlot("breakpoints", "AdwBreakpoint", (bin, breakpoint) => {
122
- bin.addBreakpoint(breakpoint);
123
- }, (bin, breakpoint) => {
124
- bin.removeBreakpoint(breakpoint);
125
- }),
91
+ methodSlot("breakpoints", "AdwBreakpoint", "addBreakpoint", "removeBreakpoint"),
126
92
  ],
127
93
  },
128
94
  AdwActionRow: {
@@ -134,11 +100,7 @@ const BUILTIN_BEHAVIORS = {
134
100
  AdwExpanderRow: {
135
101
  behaviors: [
136
102
  ...prefixSuffix,
137
- addRemoveSlot("rows", "GtkWidget", (row, child) => {
138
- row.addRow(child);
139
- }, (row, child) => {
140
- row.remove(child);
141
- }),
103
+ methodSlot("rows", "GtkWidget", "addRow", "remove"),
142
104
  ],
143
105
  },
144
106
  AdwNavigationSplitView: {
@@ -178,13 +140,7 @@ const BUILTIN_BEHAVIORS = {
178
140
  behaviors: [preferencesDialogChildren],
179
141
  },
180
142
  AdwPreferencesGroup: {
181
- behaviors: [
182
- addRemoveSlot("children", "GtkWidget", (group, child) => {
183
- group.add(child);
184
- }, (group, child) => {
185
- group.remove(child);
186
- }),
187
- ],
143
+ behaviors: [methodSlot("children", "GtkWidget", "add", "remove")],
188
144
  },
189
145
  AdwTabView: {
190
146
  behaviors: [
@@ -206,81 +162,37 @@ const BUILTIN_BEHAVIORS = {
206
162
  },
207
163
  AdwNavigationView: {
208
164
  behaviors: [
209
- addRemoveSlot("children", "AdwNavigationPage", (view, page) => {
210
- view.add(page);
211
- }, (view, page) => {
212
- view.remove(page);
213
- }),
165
+ methodSlot("children", "AdwNavigationPage", "add", "remove"),
214
166
  ],
215
167
  },
216
168
  AdwViewStack: {
217
169
  behaviors: [
218
- adoptedChildrenSlot("GtkWidget", (stack, child) => stack.add(child), (stack, child) => {
219
- stack.remove(child);
220
- }),
170
+ methodSlot("children", "GtkWidget", "add", "remove"),
221
171
  deferred("visibleChildName", (stack, name) => stack.getChildByName(name) !== null),
222
172
  ],
223
173
  },
224
174
  AdwToolbarView: {
225
175
  behaviors: [
226
176
  contentSetterSlot(),
227
- addRemoveSlot("topBar", "GtkWidget", (view, child) => {
228
- view.addTopBar(child);
229
- }, (view, child) => {
230
- view.remove(child);
231
- }),
232
- addRemoveSlot("bottomBar", "GtkWidget", (view, child) => {
233
- view.addBottomBar(child);
234
- }, (view, child) => {
235
- view.remove(child);
236
- }),
177
+ methodSlot("topBar", "GtkWidget", "addTopBar", "remove"),
178
+ methodSlot("bottomBar", "GtkWidget", "addBottomBar", "remove"),
237
179
  ],
238
180
  },
239
181
  AdwHeaderBar: {
240
182
  behaviors: [
241
- slot("start", "GtkWidget", {
242
- attach: (bar, child) => {
243
- bar.packStart(child);
244
- },
245
- detach: (bar, child) => {
246
- bar.remove(child);
247
- },
248
- }),
249
- slot("end", "GtkWidget", {
250
- attach: (bar, child) => {
251
- bar.packEnd(child);
252
- },
253
- detach: (bar, child) => {
254
- bar.remove(child);
255
- },
256
- }),
183
+ methodSlot("start", "GtkWidget", "packStart", "remove"),
184
+ methodSlot("end", "GtkWidget", "packEnd", "remove"),
257
185
  ],
258
186
  },
259
187
  AdwShortcutsDialog: {
260
- behaviors: [
261
- slot("children", "AdwShortcutsSection", {
262
- attach: (dialog, section) => {
263
- dialog.add(section);
264
- },
265
- }),
266
- ],
188
+ behaviors: [methodSlot("children", "AdwShortcutsSection", "add")],
267
189
  },
268
190
  AdwShortcutsSection: {
269
- behaviors: [
270
- slot("children", "AdwShortcutsItem", {
271
- attach: (section, item) => {
272
- section.add(item);
273
- },
274
- }),
275
- ],
191
+ behaviors: [methodSlot("children", "AdwShortcutsItem", "add")],
276
192
  },
277
193
  AdwToggleGroup: {
278
194
  behaviors: [
279
- addRemoveSlot("children", "AdwToggle", (group, toggle) => {
280
- group.add(toggle);
281
- }, (group, toggle) => {
282
- group.remove(toggle);
283
- }),
195
+ methodSlot("children", "AdwToggle", "add", "remove"),
284
196
  deferred("activeName", (group, name) => group.getToggleByName(name) !== null),
285
197
  deferred("active"),
286
198
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"element-behaviors.js","sourceRoot":"","sources":["../../src/adw/element-behaviors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,OAAO,EACH,aAAa,EACb,mBAAmB,EACnB,kBA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CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC;AAED,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;AACnC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport * as Adw from \"@gtkx/gi/adw\";\nimport type { AlertDialogResponse } from \"./prop-types.js\";\nimport {\n addRemoveSlot,\n adoptedChildrenSlot,\n applicationCreator,\n boxSlot,\n childMatcher,\n childSetterSlot,\n contentSetterSlot,\n deferred,\n indexedSlot,\n list,\n slot,\n} from \"../reconciler/behaviors.js\";\nimport { type ElementBehavior, type ElementConfig, forTypes, registerElements } from \"../reconciler/registry.js\";\nimport { BUILTIN_ELEMENTS, CHILD_SETTER_TYPES, CONTENT_SETTER_TYPES } from \"./element-config.js\";\n\ntype AdwChildSetter =\n | Adw.Bin |\n Adw.BreakpointBin |\n Adw.Clamp |\n Adw.Dialog |\n Adw.NavigationPage |\n Adw.SplitButton |\n Adw.StatusPage |\n Adw.TabOverview |\n Adw.ToastOverlay |\n Adw.Toggle;\n\ntype AdwContentSetter = Adw.ApplicationWindow | Adw.BottomSheet | Adw.OverlaySplitView | Adw.Window;\ntype BreakpointHost = Adw.ApplicationWindow | Adw.Window | Adw.Dialog;\ntype PrefixSuffixRow = Adw.ActionRow | Adw.EntryRow | Adw.ExpanderRow;\n\nconst SLOT_SUFFIX = \"Slot\";\nconst childSetter = childSetterSlot<AdwChildSetter>();\nconst contentSetter = contentSetterSlot<AdwContentSetter>();\n\nconst breakpoints = slot<BreakpointHost, Adw.Breakpoint>(\"breakpoints\", \"AdwBreakpoint\", {\n attach: (host, breakpoint) => {\n host.addBreakpoint(breakpoint);\n },\n});\n\nconst prefixSuffix = [\n addRemoveSlot<Gtk.Widget, PrefixSuffixRow>(\n \"prefix\",\n \"GtkWidget\",\n (row, child) => {\n row.addPrefix(child);\n },\n (row, child) => {\n row.remove(child);\n },\n ),\n addRemoveSlot<Gtk.Widget, PrefixSuffixRow>(\n \"suffix\",\n \"GtkWidget\",\n (row, child) => {\n row.addSuffix(child);\n },\n (row, child) => {\n row.remove(child);\n },\n ),\n];\n\nconst preferencesDialogChildren = addRemoveSlot<Adw.PreferencesPage, Adw.PreferencesDialog>(\n \"children\",\n \"AdwPreferencesPage\",\n (dialog, page) => {\n dialog.add(page);\n },\n (dialog, page) => {\n dialog.remove(page);\n },\n);\n\nconst alertDialogExtraChild = slot<Adw.AlertDialog, Gtk.Widget>(\"children\", \"GtkWidget\", {\n attach: (dialog, child) => {\n dialog.setExtraChild(child);\n },\n detach: (dialog) => {\n dialog.setExtraChild(null);\n },\n});\n\nconst sidebarSections = indexedSlot<Adw.Sidebar, Adw.SidebarSection>(\"children\", \"AdwSidebarSection\");\nconst sidebarItems = indexedSlot<Adw.SidebarSection, Adw.SidebarItem>(\"children\", \"AdwSidebarItem\");\nconst isWidget = childMatcher(\"GtkWidget\");\n\nconst multiLayoutSlots: ElementBehavior<Adw.MultiLayoutView> = {\n attach: (view, child, info) => {\n const id = getSlotId(info.slot);\n\n if (id === null || !isWidget(child)) {\n return;\n }\n\n view.setChild(id, child as Gtk.Widget);\n\n return true;\n },\n detach: (view, child, info) => {\n const id = getSlotId(info.slot);\n\n if (id === null || !isWidget(child)) {\n return;\n }\n\n const widget = child as Gtk.Widget;\n\n if (view.getChild(id) === widget) {\n widget.unparent();\n }\n },\n};\n\nconst multiLayoutLayouts = slot<Adw.MultiLayoutView, Gtk.Widget>(\"layouts\", \"GtkWidget\", {\n attach: (view, content) => {\n const layout = new Adw.Layout({ content });\n view.addLayout(layout);\n\n return layout;\n },\n reorder: (_view, _content, info) => info.adopted,\n detach: (view, _content, info) => {\n if (info.adopted instanceof Adw.Layout) {\n view.removeLayout(info.adopted);\n }\n },\n});\n\nconst BUILTIN_BEHAVIORS: Record<string, ElementConfig<never>> = {\n AdwApplication: {\n behaviors: [applicationCreator(Adw.Application)],\n },\n AdwSidebar: {\n behaviors: [sidebarSections],\n },\n AdwSidebarSection: {\n behaviors: [sidebarItems],\n },\n AdwMultiLayoutView: {\n behaviors: [\n multiLayoutLayouts,\n multiLayoutSlots,\n deferred<Adw.MultiLayoutView, string>(\"layoutName\", (view, name) => view.getLayoutByName(name) !== null),\n ],\n },\n AdwClampScrollable: {\n behaviors: [\n slot<Adw.ClampScrollable, Gtk.Scrollable & Gtk.Widget>(\"children\", \"GtkScrollable\", {\n attach: (clamp, child) => {\n clamp.setChild(child);\n },\n detach: (clamp) => {\n clamp.setChild(null);\n },\n }),\n ],\n },\n ...forTypes(CHILD_SETTER_TYPES, {\n behaviors: [childSetter],\n }),\n ...forTypes(CONTENT_SETTER_TYPES, {\n behaviors: [contentSetter],\n }),\n AdwDialog: {\n behaviors: [childSetter, breakpoints],\n },\n AdwApplicationWindow: {\n behaviors: [contentSetter, breakpoints],\n },\n AdwWindow: {\n behaviors: [contentSetter, breakpoints],\n },\n AdwBreakpointBin: {\n behaviors: [\n childSetter,\n addRemoveSlot<Adw.Breakpoint, Adw.BreakpointBin>(\n \"breakpoints\",\n \"AdwBreakpoint\",\n (bin, breakpoint) => {\n bin.addBreakpoint(breakpoint);\n },\n (bin, breakpoint) => {\n bin.removeBreakpoint(breakpoint);\n },\n ),\n ],\n },\n AdwActionRow: {\n behaviors: prefixSuffix,\n },\n AdwEntryRow: {\n behaviors: prefixSuffix,\n },\n AdwExpanderRow: {\n behaviors: [\n ...prefixSuffix,\n addRemoveSlot<Gtk.Widget, Adw.ExpanderRow>(\n \"rows\",\n \"GtkWidget\",\n (row, child) => {\n row.addRow(child);\n },\n (row, child) => {\n row.remove(child);\n },\n ),\n ],\n },\n AdwNavigationSplitView: {\n behaviors: [contentSetterSlot<Adw.NavigationSplitView, Adw.NavigationPage>(\"AdwNavigationPage\")],\n },\n AdwWrapBox: {\n behaviors: [boxSlot<Adw.WrapBox>()],\n },\n AdwCarousel: {\n behaviors: [\n slot<Adw.Carousel, Gtk.Widget>(\"children\", \"GtkWidget\", {\n attach: (carousel, child, info) => {\n carousel.insert(child, info.index);\n },\n detach: (carousel, child) => {\n carousel.remove(child);\n },\n reorder: (carousel, child, info) => {\n carousel.reorder(child, info.index);\n },\n }),\n ],\n },\n AdwPreferencesPage: {\n behaviors: [\n slot<Adw.PreferencesPage, Adw.PreferencesGroup>(\"children\", \"AdwPreferencesGroup\", {\n attach: (page, group, info) => {\n page.insert(group, info.index);\n },\n detach: (page, group) => {\n page.remove(group);\n },\n }),\n ],\n },\n AdwPreferencesDialog: {\n behaviors: [preferencesDialogChildren],\n },\n AdwPreferencesGroup: {\n behaviors: [\n addRemoveSlot<Gtk.Widget, Adw.PreferencesGroup>(\n \"children\",\n \"GtkWidget\",\n (group, child) => {\n group.add(child);\n },\n (group, child) => {\n group.remove(child);\n },\n ),\n ],\n },\n AdwTabView: {\n behaviors: [\n slot<Adw.TabView, Gtk.Widget>(\"children\", \"GtkWidget\", {\n attach: (view, child, info) => view.insert(child, info.index),\n reorder: (view, _child, info) => {\n if (info.adopted instanceof Adw.TabPage) {\n view.reorderPage(info.adopted, info.index);\n }\n },\n detach: (view, _child, info) => {\n if (info.adopted instanceof Adw.TabPage) {\n view.closePage(info.adopted);\n }\n },\n resolve: (view, child) => view.getPage(child),\n }),\n ],\n },\n AdwNavigationView: {\n behaviors: [\n addRemoveSlot<Adw.NavigationPage, Adw.NavigationView>(\n \"children\",\n \"AdwNavigationPage\",\n (view, page) => {\n view.add(page);\n },\n (view, page) => {\n view.remove(page);\n },\n ),\n ],\n },\n AdwViewStack: {\n behaviors: [\n adoptedChildrenSlot<Adw.ViewStack, Gtk.Widget>(\n \"GtkWidget\",\n (stack, child) => stack.add(child),\n (stack, child) => {\n stack.remove(child);\n },\n ),\n deferred<Adw.ViewStack, string>(\"visibleChildName\", (stack, name) => stack.getChildByName(name) !== null),\n ],\n },\n AdwToolbarView: {\n behaviors: [\n contentSetterSlot<Adw.ToolbarView>(),\n addRemoveSlot<Gtk.Widget, Adw.ToolbarView>(\n \"topBar\",\n \"GtkWidget\",\n (view, child) => {\n view.addTopBar(child);\n },\n (view, child) => {\n view.remove(child);\n },\n ),\n addRemoveSlot<Gtk.Widget, Adw.ToolbarView>(\n \"bottomBar\",\n \"GtkWidget\",\n (view, child) => {\n view.addBottomBar(child);\n },\n (view, child) => {\n view.remove(child);\n },\n ),\n ],\n },\n AdwHeaderBar: {\n behaviors: [\n slot<Adw.HeaderBar, Gtk.Widget>(\"start\", \"GtkWidget\", {\n attach: (bar, child) => {\n bar.packStart(child);\n },\n detach: (bar, child) => {\n bar.remove(child);\n },\n }),\n slot<Adw.HeaderBar, Gtk.Widget>(\"end\", \"GtkWidget\", {\n attach: (bar, child) => {\n bar.packEnd(child);\n },\n detach: (bar, child) => {\n bar.remove(child);\n },\n }),\n ],\n },\n AdwShortcutsDialog: {\n behaviors: [\n slot<Adw.ShortcutsDialog, Adw.ShortcutsSection>(\"children\", \"AdwShortcutsSection\", {\n attach: (dialog, section) => {\n dialog.add(section);\n },\n }),\n ],\n },\n AdwShortcutsSection: {\n behaviors: [\n slot<Adw.ShortcutsSection, Adw.ShortcutsItem>(\"children\", \"AdwShortcutsItem\", {\n attach: (section, item) => {\n section.add(item);\n },\n }),\n ],\n },\n AdwToggleGroup: {\n behaviors: [\n addRemoveSlot<Adw.Toggle, Adw.ToggleGroup>(\n \"children\",\n \"AdwToggle\",\n (group, toggle) => {\n group.add(toggle);\n },\n (group, toggle) => {\n group.remove(toggle);\n },\n ),\n deferred<Adw.ToggleGroup, string>(\"activeName\", (group, name) => group.getToggleByName(name) !== null),\n deferred(\"active\"),\n ],\n },\n AdwAlertDialog: {\n behaviors: [\n alertDialogExtraChild,\n list<Adw.AlertDialog, AlertDialogResponse>(\"responses\", {\n add: (dialog, response) => {\n dialog.addResponse(response.id, response.label);\n\n if (response.appearance !== undefined) {\n dialog.setResponseAppearance(response.id, response.appearance);\n }\n\n if (response.isEnabled !== undefined) {\n dialog.setResponseEnabled(response.id, response.isEnabled);\n }\n },\n remove: (dialog, response) => {\n dialog.removeResponse(response.id);\n },\n }),\n ],\n },\n};\n\nfunction getSlotId(name: string): string | null {\n if (name.length <= SLOT_SUFFIX.length || !name.endsWith(SLOT_SUFFIX)) {\n return null;\n }\n\n return name.slice(0, -SLOT_SUFFIX.length);\n}\n\nregisterElements(BUILTIN_ELEMENTS);\nregisterElements(BUILTIN_BEHAVIORS);\n"]}
1
+ {"version":3,"file":"element-behaviors.js","sourceRoot":"","sources":["../../src/adw/element-behaviors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,OAAO,EACH,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,UAAU,EACV,UAAU,EACV,IAAI,GACP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAA4C,QAAQ,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAkBjG,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,MAAM,WAAW,GAAG,eAAe,EAAkB,CAAC;AACtD,MAAM,aAAa,GAAG,iBAAiB,EAAoB,CAAC;AAC5D,MAAM,WAAW,GAAG,UAAU,CAAiC,aAAa,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;AAEhH,MAAM,YAAY,GAAG;IACjB,UAAU,CAA8B,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,CAAC;IACrF,UAAU,CAA8B,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,CAAC;CACxF,CAAC;AAEF,MAAM,yBAAyB,GAAG,UAAU,CACxC,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,QAAQ,CACpD,CAAC;AAEF,MAAM,qBAAqB,GAAG,UAAU,CAA8B,UAAU,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;AAChH,MAAM,eAAe,G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ACD,cAAc,EAAE;QACZ,SAAS,EAAE;YACP,qBAAqB;YACrB,IAAI,CAAuC,WAAW,EAAE;gBACpD,GAAG,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;oBACtB,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;oBAEhD,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;wBACpC,MAAM,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;oBACnE,CAAC;oBAED,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;wBACnC,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;oBAC/D,CAAC;gBACL,CAAC;gBACD,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;oBACzB,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACvC,CAAC;aACJ,CAAC;SACL;KACJ;CACJ,CAAC;AAEF,SAAS,SAAS,CAAC,IAAY;IAC3B,IAAI,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACnE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC;AAED,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;AACnC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport * as Adw from \"@gtkx/gi/adw\";\nimport type { AlertDialogResponse } from \"./prop-types.js\";\nimport {\n applicationCreator,\n boxSlot,\n childMatcher,\n childSetterSlot,\n contentSetterSlot,\n deferred,\n indexedSlot,\n list,\n methodSlot,\n setterSlot,\n slot,\n} from \"../reconciler/behaviors.js\";\nimport { type ElementBehavior, type ElementConfig, forTypes, registerElements } from \"../reconciler/registry.js\";\nimport { BUILTIN_ELEMENTS, CHILD_SETTER_TYPES, CONTENT_SETTER_TYPES } from \"./element-config.js\";\n\ntype AdwChildSetter =\n | Adw.Bin |\n Adw.BreakpointBin |\n Adw.Clamp |\n Adw.Dialog |\n Adw.NavigationPage |\n Adw.SplitButton |\n Adw.StatusPage |\n Adw.TabOverview |\n Adw.ToastOverlay |\n Adw.Toggle;\n\ntype AdwContentSetter = Adw.ApplicationWindow | Adw.BottomSheet | Adw.OverlaySplitView | Adw.Window;\ntype BreakpointHost = Adw.ApplicationWindow | Adw.Window | Adw.Dialog;\ntype PrefixSuffixRow = Adw.ActionRow | Adw.EntryRow | Adw.ExpanderRow;\n\nconst SLOT_SUFFIX = \"Slot\";\nconst childSetter = childSetterSlot<AdwChildSetter>();\nconst contentSetter = contentSetterSlot<AdwContentSetter>();\nconst breakpoints = methodSlot<BreakpointHost, Adw.Breakpoint>(\"breakpoints\", \"AdwBreakpoint\", \"addBreakpoint\");\n\nconst prefixSuffix = [\n methodSlot<PrefixSuffixRow, Gtk.Widget>(\"prefix\", \"GtkWidget\", \"addPrefix\", \"remove\"),\n methodSlot<PrefixSuffixRow, Gtk.Widget>(\"suffix\", \"GtkWidget\", \"addSuffix\", \"remove\"),\n];\n\nconst preferencesDialogChildren = methodSlot<Adw.PreferencesDialog, Adw.PreferencesPage>(\n \"children\", \"AdwPreferencesPage\", \"add\", \"remove\",\n);\n\nconst alertDialogExtraChild = setterSlot<Adw.AlertDialog, Gtk.Widget>(\"children\", \"GtkWidget\", \"setExtraChild\");\nconst sidebarSections = indexedSlot<Adw.Sidebar, Adw.SidebarSection>(\"children\", \"AdwSidebarSection\");\nconst sidebarItems = indexedSlot<Adw.SidebarSection, Adw.SidebarItem>(\"children\", \"AdwSidebarItem\");\nconst isWidget = childMatcher(\"GtkWidget\");\n\nconst multiLayoutSlots: ElementBehavior<Adw.MultiLayoutView> = {\n attach: (view, child, info) => {\n const id = getSlotId(info.slot);\n\n if (id === null || !isWidget(child)) {\n return;\n }\n\n view.setChild(id, child as Gtk.Widget);\n\n return true;\n },\n detach: (view, child, info) => {\n const id = getSlotId(info.slot);\n\n if (id === null || !isWidget(child)) {\n return;\n }\n\n const widget = child as Gtk.Widget;\n\n if (view.getChild(id) === widget) {\n widget.unparent();\n }\n },\n};\n\nconst multiLayoutLayouts = slot<Adw.MultiLayoutView, Gtk.Widget>(\"layouts\", \"GtkWidget\", {\n attach: (view, content) => {\n const layout = new Adw.Layout({ content });\n view.addLayout(layout);\n\n return layout;\n },\n reorder: (_view, _content, info) => info.adopted,\n detach: (view, _content, info) => {\n if (info.adopted instanceof Adw.Layout) {\n view.removeLayout(info.adopted);\n }\n },\n});\n\nconst BUILTIN_BEHAVIORS: Record<string, ElementConfig<never>> = {\n AdwApplication: {\n behaviors: [applicationCreator(Adw.Application)],\n },\n AdwSidebar: {\n behaviors: [sidebarSections],\n },\n AdwSidebarSection: {\n behaviors: [sidebarItems],\n },\n AdwMultiLayoutView: {\n behaviors: [\n multiLayoutLayouts,\n multiLayoutSlots,\n deferred<Adw.MultiLayoutView, string>(\"layoutName\", (view, name) => view.getLayoutByName(name) !== null),\n ],\n },\n AdwClampScrollable: {\n behaviors: [\n setterSlot<Adw.ClampScrollable, Gtk.Scrollable & Gtk.Widget>(\"children\", \"GtkScrollable\", \"setChild\"),\n ],\n },\n ...forTypes(CHILD_SETTER_TYPES, {\n behaviors: [childSetter],\n }),\n ...forTypes(CONTENT_SETTER_TYPES, {\n behaviors: [contentSetter],\n }),\n AdwDialog: {\n behaviors: [childSetter, breakpoints],\n },\n AdwApplicationWindow: {\n behaviors: [contentSetter, breakpoints],\n },\n AdwWindow: {\n behaviors: [contentSetter, breakpoints],\n },\n AdwBreakpointBin: {\n behaviors: [\n childSetter,\n methodSlot<Adw.BreakpointBin, Adw.Breakpoint>(\n \"breakpoints\", \"AdwBreakpoint\", \"addBreakpoint\", \"removeBreakpoint\",\n ),\n ],\n },\n AdwActionRow: {\n behaviors: prefixSuffix,\n },\n AdwEntryRow: {\n behaviors: prefixSuffix,\n },\n AdwExpanderRow: {\n behaviors: [\n ...prefixSuffix,\n methodSlot<Adw.ExpanderRow, Gtk.Widget>(\"rows\", \"GtkWidget\", \"addRow\", \"remove\"),\n ],\n },\n AdwNavigationSplitView: {\n behaviors: [contentSetterSlot<Adw.NavigationSplitView, Adw.NavigationPage>(\"AdwNavigationPage\")],\n },\n AdwWrapBox: {\n behaviors: [boxSlot<Adw.WrapBox>()],\n },\n AdwCarousel: {\n behaviors: [\n slot<Adw.Carousel, Gtk.Widget>(\"children\", \"GtkWidget\", {\n attach: (carousel, child, info) => {\n carousel.insert(child, info.index);\n },\n detach: (carousel, child) => {\n carousel.remove(child);\n },\n reorder: (carousel, child, info) => {\n carousel.reorder(child, info.index);\n },\n }),\n ],\n },\n AdwPreferencesPage: {\n behaviors: [\n slot<Adw.PreferencesPage, Adw.PreferencesGroup>(\"children\", \"AdwPreferencesGroup\", {\n attach: (page, group, info) => {\n page.insert(group, info.index);\n },\n detach: (page, group) => {\n page.remove(group);\n },\n }),\n ],\n },\n AdwPreferencesDialog: {\n behaviors: [preferencesDialogChildren],\n },\n AdwPreferencesGroup: {\n behaviors: [methodSlot<Adw.PreferencesGroup, Gtk.Widget>(\"children\", \"GtkWidget\", \"add\", \"remove\")],\n },\n AdwTabView: {\n behaviors: [\n slot<Adw.TabView, Gtk.Widget>(\"children\", \"GtkWidget\", {\n attach: (view, child, info) => view.insert(child, info.index),\n reorder: (view, _child, info) => {\n if (info.adopted instanceof Adw.TabPage) {\n view.reorderPage(info.adopted, info.index);\n }\n },\n detach: (view, _child, info) => {\n if (info.adopted instanceof Adw.TabPage) {\n view.closePage(info.adopted);\n }\n },\n resolve: (view, child) => view.getPage(child),\n }),\n ],\n },\n AdwNavigationView: {\n behaviors: [\n methodSlot<Adw.NavigationView, Adw.NavigationPage>(\"children\", \"AdwNavigationPage\", \"add\", \"remove\"),\n ],\n },\n AdwViewStack: {\n behaviors: [\n methodSlot<Adw.ViewStack, Gtk.Widget>(\"children\", \"GtkWidget\", \"add\", \"remove\"),\n deferred<Adw.ViewStack, string>(\"visibleChildName\", (stack, name) => stack.getChildByName(name) !== null),\n ],\n },\n AdwToolbarView: {\n behaviors: [\n contentSetterSlot<Adw.ToolbarView>(),\n methodSlot<Adw.ToolbarView, Gtk.Widget>(\"topBar\", \"GtkWidget\", \"addTopBar\", \"remove\"),\n methodSlot<Adw.ToolbarView, Gtk.Widget>(\"bottomBar\", \"GtkWidget\", \"addBottomBar\", \"remove\"),\n ],\n },\n AdwHeaderBar: {\n behaviors: [\n methodSlot<Adw.HeaderBar, Gtk.Widget>(\"start\", \"GtkWidget\", \"packStart\", \"remove\"),\n methodSlot<Adw.HeaderBar, Gtk.Widget>(\"end\", \"GtkWidget\", \"packEnd\", \"remove\"),\n ],\n },\n AdwShortcutsDialog: {\n behaviors: [methodSlot<Adw.ShortcutsDialog, Adw.ShortcutsSection>(\"children\", \"AdwShortcutsSection\", \"add\")],\n },\n AdwShortcutsSection: {\n behaviors: [methodSlot<Adw.ShortcutsSection, Adw.ShortcutsItem>(\"children\", \"AdwShortcutsItem\", \"add\")],\n },\n AdwToggleGroup: {\n behaviors: [\n methodSlot<Adw.ToggleGroup, Adw.Toggle>(\"children\", \"AdwToggle\", \"add\", \"remove\"),\n deferred<Adw.ToggleGroup, string>(\"activeName\", (group, name) => group.getToggleByName(name) !== null),\n deferred(\"active\"),\n ],\n },\n AdwAlertDialog: {\n behaviors: [\n alertDialogExtraChild,\n list<Adw.AlertDialog, AlertDialogResponse>(\"responses\", {\n add: (dialog, response) => {\n dialog.addResponse(response.id, response.label);\n\n if (response.appearance !== undefined) {\n dialog.setResponseAppearance(response.id, response.appearance);\n }\n\n if (response.isEnabled !== undefined) {\n dialog.setResponseEnabled(response.id, response.isEnabled);\n }\n },\n remove: (dialog, response) => {\n dialog.removeResponse(response.id);\n },\n }),\n ],\n },\n};\n\nfunction getSlotId(name: string): string | null {\n if (name.length <= SLOT_SUFFIX.length || !name.endsWith(SLOT_SUFFIX)) {\n return null;\n }\n\n return name.slice(0, -SLOT_SUFFIX.length);\n}\n\nregisterElements(BUILTIN_ELEMENTS);\nregisterElements(BUILTIN_BEHAVIORS);\n"]}
@@ -2,7 +2,7 @@ import * as Gio from "@gtkx/gi/gio";
2
2
  import * as GLib from "@gtkx/gi/glib";
3
3
  import * as Gtk from "@gtkx/gi/gtk";
4
4
  import { BUILTIN_ELEMENTS, SINGLE_CHILD_TYPES } from "./element-config.js";
5
- import { addRemoveSlot, adoptedChildrenSlot, applicationCreator, boxSlot, childSetterSlot, controlledText, deferred, list, slot, value, wrappingIndexedSlot, } from "./reconciler/behaviors.js";
5
+ import { applicationCreator, boxSlot, childSetterSlot, controlledText, deferred, deferredWith, list, methodSlot, setterSlot, slot, value, wrappingIndexedSlot, } from "./reconciler/behaviors.js";
6
6
  import { forTypes, registerElements, } from "./reconciler/registry.js";
7
7
  import { applyWrite } from "./reconciler/signals.js";
8
8
  import { applyStyle, CSS_CLASSES_PROP, styleClass } from "./reconciler/style.js";
@@ -15,16 +15,8 @@ const BUILTIN_BEHAVIORS = {
15
15
  }),
16
16
  ...forTypes(["GtkHeaderBar", "GtkActionBar"], {
17
17
  behaviors: [
18
- addRemoveSlot("start", "GtkWidget", (bar, child) => {
19
- bar.packStart(child);
20
- }, (bar, child) => {
21
- bar.remove(child);
22
- }),
23
- addRemoveSlot("end", "GtkWidget", (bar, child) => {
24
- bar.packEnd(child);
25
- }, (bar, child) => {
26
- bar.remove(child);
27
- }),
18
+ methodSlot("start", "GtkWidget", "packStart", "remove"),
19
+ methodSlot("end", "GtkWidget", "packEnd", "remove"),
28
20
  ],
29
21
  }),
30
22
  GtkWindow: {
@@ -40,19 +32,8 @@ const BUILTIN_BEHAVIORS = {
40
32
  popover.unparent();
41
33
  },
42
34
  }),
43
- addRemoveSlot("controllers", "GtkEventController", (widget, controller) => {
44
- widget.addController(controller);
45
- }, (widget, controller) => {
46
- widget.removeController(controller);
47
- }),
48
- slot("layoutManager", "GtkLayoutManager", {
49
- attach: (widget, manager) => {
50
- widget.setLayoutManager(manager);
51
- },
52
- detach: (widget) => {
53
- widget.setLayoutManager(null);
54
- },
55
- }),
35
+ methodSlot("controllers", "GtkEventController", "addController", "removeController"),
36
+ setterSlot("layoutManager", "GtkLayoutManager", "setLayoutManager"),
56
37
  slot("actionGroups", "GActionGroup", {
57
38
  attach: (widget, group, info) => {
58
39
  widget.insertActionGroup(info.props.prefix ?? "", group);
@@ -98,27 +79,14 @@ const BUILTIN_BEHAVIORS = {
98
79
  },
99
80
  GtkShortcutController: {
100
81
  behaviors: [
101
- addRemoveSlot("shortcuts", "GtkShortcut", (controller, shortcut) => {
102
- controller.addShortcut(shortcut);
103
- }, (controller, shortcut) => {
104
- controller.removeShortcut(shortcut);
105
- }),
82
+ methodSlot("shortcuts", "GtkShortcut", "addShortcut", "removeShortcut"),
106
83
  ],
107
84
  },
108
85
  GtkTextChildAnchor: {
109
86
  behaviors: [{ create: () => Gtk.TextChildAnchor.new() }],
110
87
  },
111
88
  GtkTextView: {
112
- behaviors: [
113
- slot("children", "GtkTextBuffer", {
114
- attach: (view, buffer) => {
115
- view.setBuffer(buffer);
116
- },
117
- detach: (view) => {
118
- view.setBuffer(null);
119
- },
120
- }),
121
- ],
89
+ behaviors: [setterSlot("children", "GtkTextBuffer", "setBuffer")],
122
90
  },
123
91
  GActionMap: {
124
92
  behaviors: [
@@ -196,16 +164,8 @@ const BUILTIN_BEHAVIORS = {
196
164
  },
197
165
  GtkConstraintLayout: {
198
166
  behaviors: [
199
- addRemoveSlot("constraints", "GtkConstraint", (layout, constraint) => {
200
- layout.addConstraint(constraint);
201
- }, (layout, constraint) => {
202
- layout.removeConstraint(constraint);
203
- }),
204
- addRemoveSlot("guides", "GtkConstraintGuide", (layout, guide) => {
205
- layout.addGuide(guide);
206
- }, (layout, guide) => {
207
- layout.removeGuide(guide);
208
- }),
167
+ methodSlot("constraints", "GtkConstraint", "addConstraint", "removeConstraint"),
168
+ methodSlot("guides", "GtkConstraintGuide", "addGuide", "removeGuide"),
209
169
  list("vfl", {
210
170
  add: (layout, item) => [
211
171
  ...layout.addConstraintsFromDescription(item.lines, item.hspacing ?? 0, item.vspacing ?? 0, item.views ?? new Map()),
@@ -220,9 +180,7 @@ const BUILTIN_BEHAVIORS = {
220
180
  },
221
181
  GtkStack: {
222
182
  behaviors: [
223
- adoptedChildrenSlot("GtkWidget", (stack, child) => stack.addChild(child), (stack, child) => {
224
- stack.remove(child);
225
- }),
183
+ methodSlot("children", "GtkWidget", "addChild", "remove"),
226
184
  deferred("visibleChildName", (stack, name) => stack.getChildByName(name) !== null),
227
185
  ],
228
186
  },
@@ -243,11 +201,7 @@ const BUILTIN_BEHAVIORS = {
243
201
  GtkApplication: {
244
202
  behaviors: [
245
203
  applicationCreator(Gtk.Application),
246
- addRemoveSlot("children", "GtkWindow", (application, window) => {
247
- application.addWindow(window);
248
- }, (application, window) => {
249
- application.removeWindow(window);
250
- }),
204
+ methodSlot("children", "GtkWindow", "addWindow", "removeWindow"),
251
205
  list("actionAccels", {
252
206
  add: (application, item) => {
253
207
  application.setAccelsForAction(item.detailedActionName, item.accels);
@@ -392,72 +346,23 @@ function desiredIndex(value) {
392
346
  }
393
347
  return value;
394
348
  }
395
- function selectRowAt(box, row) {
396
- applyWrite(SELECTED_INDEX_PROP, () => {
397
- box.selectRow(row);
398
- });
399
- }
400
- function clearSelection(box) {
401
- applyWrite(SELECTED_INDEX_PROP, () => {
349
+ function applySelectedIndex(box, index) {
350
+ if (index < 0) {
402
351
  box.unselectAll();
403
- });
404
- }
405
- function applySelectedIndex(box, state) {
406
- const { desired } = state;
407
- if (desired === undefined || selectedRowIndex(box) === desired) {
408
- return;
409
- }
410
- if (desired < 0) {
411
- clearSelection(box);
412
352
  return;
413
353
  }
414
- const row = box.getRowAtIndex(desired);
354
+ const row = box.getRowAtIndex(index);
415
355
  if (row !== null) {
416
- selectRowAt(box, row);
417
- }
418
- }
419
- function scheduleSelectedIndex(box, state) {
420
- if (state.isScheduled) {
421
- return;
422
- }
423
- state.isScheduled = true;
424
- queueMicrotask(() => {
425
- state.isScheduled = false;
426
- if (state.disconnect !== null) {
427
- applySelectedIndex(box, state);
428
- }
429
- });
430
- }
431
- function watchSelectionDrift(box, state) {
432
- if (state.disconnect !== null) {
433
- return;
356
+ box.selectRow(row);
434
357
  }
435
- const handler = () => {
436
- scheduleSelectedIndex(box, state);
437
- };
438
- box.on(SELECTION_SIGNAL, handler);
439
- state.disconnect = () => {
440
- box.off(SELECTION_SIGNAL, handler);
441
- };
442
358
  }
443
359
  function selectedIndexBehavior() {
444
- return {
445
- deferred: [SELECTED_INDEX_PROP],
446
- initialize: () => ({ desired: undefined, isScheduled: false, disconnect: null }),
447
- update: (_box, _prev, next, context) => {
448
- context.desired = desiredIndex(next[SELECTED_INDEX_PROP]);
449
- return [SELECTED_INDEX_PROP];
450
- },
451
- flush: (box, context) => {
452
- applySelectedIndex(box, context);
453
- watchSelectionDrift(box, context);
454
- },
455
- teardown: (_box, context) => {
456
- const state = context;
457
- state.disconnect?.();
458
- state.disconnect = null;
459
- },
460
- };
360
+ return deferredWith(SELECTED_INDEX_PROP, {
361
+ parse: desiredIndex,
362
+ read: selectedRowIndex,
363
+ write: applySelectedIndex,
364
+ signal: SELECTION_SIGNAL,
365
+ });
461
366
  }
462
367
  const addMainOption = (application, option) => {
463
368
  application.addMainOption(option.longName, option.shortName?.codePointAt(0) ?? 0, option.flags ?? GLib.OptionFlags.NONE, option.arg ?? GLib.OptionArg.NONE, option.description, option.argDescription ?? null);