@gtkx/react 1.0.0-rc.1 → 1.0.0-rc.3
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/adw/config.d.ts +2 -0
- package/dist/adw/config.d.ts.map +1 -0
- package/dist/adw/config.js +2 -0
- package/dist/adw/config.js.map +1 -0
- package/dist/{libraries/adw → adw}/dialog.d.ts +2 -2
- package/dist/adw/dialog.d.ts.map +1 -0
- package/dist/adw/dialog.js +25 -0
- package/dist/adw/dialog.js.map +1 -0
- package/dist/adw/element-behaviors.d.ts +2 -0
- package/dist/adw/element-behaviors.d.ts.map +1 -0
- package/dist/adw/element-behaviors.js +269 -0
- package/dist/adw/element-behaviors.js.map +1 -0
- package/dist/adw/element-config.d.ts +11 -0
- package/dist/adw/element-config.d.ts.map +1 -0
- package/dist/adw/element-config.js +127 -0
- package/dist/adw/element-config.js.map +1 -0
- package/dist/adw/index.d.ts +4 -0
- package/dist/adw/index.d.ts.map +1 -0
- package/dist/adw/index.js +3 -0
- package/dist/adw/index.js.map +1 -0
- package/dist/adw/prop-types.d.ts +29 -0
- package/dist/adw/prop-types.d.ts.map +1 -0
- package/dist/adw/prop-types.js +2 -0
- package/dist/adw/prop-types.js.map +1 -0
- package/dist/bootstrap.d.ts +2 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +5 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/components/application.d.ts +2 -2
- package/dist/components/application.d.ts.map +1 -1
- package/dist/components/application.js +31 -18
- package/dist/components/application.js.map +1 -1
- package/dist/components/element.d.ts +6 -0
- package/dist/components/element.d.ts.map +1 -0
- package/dist/components/element.js +29 -0
- package/dist/components/element.js.map +1 -0
- package/dist/components/window.d.ts +2 -2
- package/dist/components/window.d.ts.map +1 -1
- package/dist/components/window.js +22 -12
- package/dist/components/window.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +3 -0
- package/dist/config.js.map +1 -0
- package/dist/element-behaviors.d.ts +2 -0
- package/dist/element-behaviors.d.ts.map +1 -0
- package/dist/element-behaviors.js +348 -0
- package/dist/element-behaviors.js.map +1 -0
- package/dist/element-config.d.ts +10 -0
- package/dist/element-config.d.ts.map +1 -0
- package/dist/element-config.js +149 -0
- package/dist/element-config.js.map +1 -0
- package/dist/hooks/use-application.d.ts +4 -3
- package/dist/hooks/use-application.d.ts.map +1 -1
- package/dist/hooks/use-application.js +5 -4
- package/dist/hooks/use-application.js.map +1 -1
- package/dist/hooks/use-bind-setting.d.ts +21 -4
- package/dist/hooks/use-bind-setting.d.ts.map +1 -1
- package/dist/hooks/use-bind-setting.js +27 -16
- package/dist/hooks/use-bind-setting.js.map +1 -1
- package/dist/hooks/use-merged-refs.d.ts +8 -0
- package/dist/hooks/use-merged-refs.d.ts.map +1 -0
- package/dist/hooks/use-merged-refs.js +48 -0
- package/dist/hooks/use-merged-refs.js.map +1 -0
- package/dist/hooks/use-object-value.d.ts +3 -2
- package/dist/hooks/use-object-value.d.ts.map +1 -1
- package/dist/hooks/use-object-value.js +18 -21
- package/dist/hooks/use-object-value.js.map +1 -1
- package/dist/hooks/use-parent-window.d.ts +3 -2
- package/dist/hooks/use-parent-window.d.ts.map +1 -1
- package/dist/hooks/use-parent-window.js +3 -2
- package/dist/hooks/use-parent-window.js.map +1 -1
- package/dist/hooks/use-property.d.ts +5 -5
- package/dist/hooks/use-property.d.ts.map +1 -1
- package/dist/hooks/use-property.js +4 -3
- package/dist/hooks/use-property.js.map +1 -1
- package/dist/hooks/use-setting.d.ts +5 -16
- package/dist/hooks/use-setting.d.ts.map +1 -1
- package/dist/hooks/use-setting.js +16 -11
- package/dist/hooks/use-setting.js.map +1 -1
- package/dist/hooks/use-signal.d.ts +14 -7
- package/dist/hooks/use-signal.d.ts.map +1 -1
- package/dist/hooks/use-signal.js +33 -18
- package/dist/hooks/use-signal.js.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +7 -7
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +6 -7
- package/dist/internal.js.map +1 -1
- package/dist/prop-types.d.ts +110 -0
- package/dist/prop-types.d.ts.map +1 -0
- package/dist/prop-types.js +2 -0
- package/dist/prop-types.js.map +1 -0
- package/dist/reconciler/apply-props.d.ts +10 -7
- package/dist/reconciler/apply-props.d.ts.map +1 -1
- package/dist/reconciler/apply-props.js +186 -82
- package/dist/reconciler/apply-props.js.map +1 -1
- package/dist/reconciler/behaviors.d.ts +59 -0
- package/dist/reconciler/behaviors.d.ts.map +1 -0
- package/dist/reconciler/behaviors.js +177 -0
- package/dist/reconciler/behaviors.js.map +1 -0
- package/dist/reconciler/child-routing.d.ts +5 -0
- package/dist/reconciler/child-routing.d.ts.map +1 -0
- package/dist/reconciler/child-routing.js +156 -0
- package/dist/reconciler/child-routing.js.map +1 -0
- package/dist/reconciler/host-config.d.ts +8 -12
- package/dist/reconciler/host-config.d.ts.map +1 -1
- package/dist/reconciler/host-config.js +171 -270
- package/dist/reconciler/host-config.js.map +1 -1
- package/dist/reconciler/instance.d.ts +4 -5
- package/dist/reconciler/instance.d.ts.map +1 -1
- package/dist/reconciler/instance.js +44 -22
- package/dist/reconciler/instance.js.map +1 -1
- package/dist/reconciler/metadata.d.ts +17 -0
- package/dist/reconciler/metadata.d.ts.map +1 -0
- package/dist/reconciler/metadata.js +82 -0
- package/dist/reconciler/metadata.js.map +1 -0
- package/dist/reconciler/node.d.ts +76 -0
- package/dist/reconciler/node.d.ts.map +1 -0
- package/dist/reconciler/node.js +53 -0
- package/dist/reconciler/node.js.map +1 -0
- package/dist/reconciler/placement.d.ts +5 -0
- package/dist/reconciler/placement.d.ts.map +1 -0
- package/dist/reconciler/placement.js +191 -0
- package/dist/reconciler/placement.js.map +1 -0
- package/dist/reconciler/registry.d.ts +107 -0
- package/dist/reconciler/registry.d.ts.map +1 -0
- package/dist/reconciler/registry.js +74 -0
- package/dist/reconciler/registry.js.map +1 -0
- package/dist/reconciler/root-element.d.ts +9 -12
- package/dist/reconciler/root-element.d.ts.map +1 -1
- package/dist/reconciler/root-element.js +6 -6
- package/dist/reconciler/root-element.js.map +1 -1
- package/dist/reconciler/root.d.ts +56 -0
- package/dist/reconciler/root.d.ts.map +1 -0
- package/dist/reconciler/root.js +106 -0
- package/dist/reconciler/root.js.map +1 -0
- package/dist/reconciler/signals.d.ts +9 -0
- package/dist/reconciler/signals.d.ts.map +1 -0
- package/dist/reconciler/signals.js +58 -0
- package/dist/reconciler/signals.js.map +1 -0
- package/dist/reconciler/text.d.ts +19 -0
- package/dist/reconciler/text.d.ts.map +1 -0
- package/dist/reconciler/text.js +281 -0
- package/dist/reconciler/text.js.map +1 -0
- package/dist/utils/accessible-metadata.d.ts +11 -4
- package/dist/utils/accessible-metadata.d.ts.map +1 -1
- package/dist/utils/accessible-metadata.js +20 -17
- package/dist/utils/accessible-metadata.js.map +1 -1
- package/dist/{reconciler/accessible.d.ts → utils/accessible-props.d.ts} +7 -6
- package/dist/utils/accessible-props.d.ts.map +1 -0
- package/dist/utils/accessible-props.js +181 -0
- package/dist/utils/accessible-props.js.map +1 -0
- package/dist/utils/ref-prop.d.ts +15 -0
- package/dist/utils/ref-prop.d.ts.map +1 -0
- package/dist/utils/ref-prop.js +18 -0
- package/dist/utils/ref-prop.js.map +1 -0
- package/dist/utils/settings.d.ts +17 -0
- package/dist/utils/settings.d.ts.map +1 -0
- package/dist/utils/settings.js +37 -0
- package/dist/utils/settings.js.map +1 -0
- package/dist/utils/variant.d.ts +57 -0
- package/dist/utils/variant.d.ts.map +1 -0
- package/dist/utils/variant.js +197 -0
- package/dist/utils/variant.js.map +1 -0
- package/env.d.ts +9 -0
- package/package.json +36 -11
- package/src/adw/config.ts +1 -0
- package/src/adw/dialog.tsx +35 -0
- package/src/adw/element-behaviors.ts +349 -0
- package/src/adw/element-config.ts +131 -0
- package/src/adw/index.ts +4 -0
- package/src/adw/prop-types.ts +42 -0
- package/src/bootstrap.ts +5 -0
- package/src/components/application.tsx +42 -23
- package/src/components/element.tsx +47 -0
- package/src/components/window.tsx +26 -14
- package/src/config.ts +10 -0
- package/src/element-behaviors.ts +424 -0
- package/src/element-config.ts +151 -0
- package/src/env.d.ts +1 -0
- package/src/hooks/use-application.ts +6 -4
- package/src/hooks/use-bind-setting.ts +47 -31
- package/src/hooks/use-merged-refs.ts +64 -0
- package/src/hooks/use-object-value.ts +27 -23
- package/src/hooks/use-parent-window.ts +4 -2
- package/src/hooks/use-property.ts +11 -10
- package/src/hooks/use-setting.ts +20 -33
- package/src/hooks/use-signal.ts +41 -48
- package/src/index.ts +7 -8
- package/src/internal.ts +8 -18
- package/src/prop-types.ts +142 -0
- package/src/reconciler/apply-props.ts +239 -85
- package/src/reconciler/behaviors.ts +330 -0
- package/src/reconciler/child-routing.ts +202 -0
- package/src/reconciler/host-config.ts +235 -367
- package/src/reconciler/instance.ts +76 -24
- package/src/reconciler/metadata.ts +119 -0
- package/src/reconciler/node.ts +161 -0
- package/src/reconciler/placement.ts +275 -0
- package/src/reconciler/registry.ts +175 -0
- package/src/reconciler/root-element.ts +9 -11
- package/src/reconciler/root.ts +172 -0
- package/src/reconciler/signals.ts +92 -0
- package/src/reconciler/text.ts +414 -0
- package/src/utils/accessible-metadata.ts +23 -18
- package/src/utils/accessible-props.ts +279 -0
- package/src/utils/ref-prop.ts +30 -0
- package/src/utils/settings.ts +69 -0
- package/src/utils/variant.ts +368 -0
- package/dist/hooks/use-merge-refs.d.ts +0 -3
- package/dist/hooks/use-merge-refs.d.ts.map +0 -1
- package/dist/hooks/use-merge-refs.js +0 -48
- package/dist/hooks/use-merge-refs.js.map +0 -1
- package/dist/hooks/use-object-attachment.d.ts +0 -10
- package/dist/hooks/use-object-attachment.d.ts.map +0 -1
- package/dist/hooks/use-object-attachment.js +0 -24
- package/dist/hooks/use-object-attachment.js.map +0 -1
- package/dist/libraries/adw/dialog.d.ts.map +0 -1
- package/dist/libraries/adw/dialog.js +0 -25
- package/dist/libraries/adw/dialog.js.map +0 -1
- package/dist/libraries/adw/index.d.ts +0 -2
- package/dist/libraries/adw/index.d.ts.map +0 -1
- package/dist/libraries/adw/index.js +0 -2
- package/dist/libraries/adw/index.js.map +0 -1
- package/dist/reconciler/accessible.d.ts.map +0 -1
- package/dist/reconciler/accessible.js +0 -143
- package/dist/reconciler/accessible.js.map +0 -1
- package/dist/reconciler/commit-flush.d.ts +0 -3
- package/dist/reconciler/commit-flush.d.ts.map +0 -1
- package/dist/reconciler/commit-flush.js +0 -13
- package/dist/reconciler/commit-flush.js.map +0 -1
- package/dist/reconciler/container-attach.d.ts +0 -10
- package/dist/reconciler/container-attach.d.ts.map +0 -1
- package/dist/reconciler/container-attach.js +0 -216
- package/dist/reconciler/container-attach.js.map +0 -1
- package/dist/reconciler/content-rebuild.d.ts +0 -3
- package/dist/reconciler/content-rebuild.d.ts.map +0 -1
- package/dist/reconciler/content-rebuild.js +0 -15
- package/dist/reconciler/content-rebuild.js.map +0 -1
- package/dist/reconciler/dispatch.d.ts +0 -6
- package/dist/reconciler/dispatch.d.ts.map +0 -1
- package/dist/reconciler/dispatch.js +0 -61
- package/dist/reconciler/dispatch.js.map +0 -1
- package/dist/reconciler/element-prop-appliers.d.ts +0 -5
- package/dist/reconciler/element-prop-appliers.d.ts.map +0 -1
- package/dist/reconciler/element-prop-appliers.js +0 -104
- package/dist/reconciler/element-prop-appliers.js.map +0 -1
- package/dist/reconciler/element-props.d.ts +0 -25
- package/dist/reconciler/element-props.d.ts.map +0 -1
- package/dist/reconciler/element-props.js +0 -157
- package/dist/reconciler/element-props.js.map +0 -1
- package/dist/reconciler/label-text-rebuild.d.ts +0 -3
- package/dist/reconciler/label-text-rebuild.d.ts.map +0 -1
- package/dist/reconciler/label-text-rebuild.js +0 -22
- package/dist/reconciler/label-text-rebuild.js.map +0 -1
- package/dist/reconciler/portal.d.ts +0 -11
- package/dist/reconciler/portal.d.ts.map +0 -1
- package/dist/reconciler/portal.js +0 -20
- package/dist/reconciler/portal.js.map +0 -1
- package/dist/reconciler/reconciler-error-handler.d.ts +0 -7
- package/dist/reconciler/reconciler-error-handler.d.ts.map +0 -1
- package/dist/reconciler/reconciler-error-handler.js +0 -24
- package/dist/reconciler/reconciler-error-handler.js.map +0 -1
- package/dist/reconciler/reconciler-root.d.ts +0 -19
- package/dist/reconciler/reconciler-root.d.ts.map +0 -1
- package/dist/reconciler/reconciler-root.js +0 -24
- package/dist/reconciler/reconciler-root.js.map +0 -1
- package/dist/reconciler/reconciler.d.ts +0 -3
- package/dist/reconciler/reconciler.d.ts.map +0 -1
- package/dist/reconciler/reconciler.js +0 -12
- package/dist/reconciler/reconciler.js.map +0 -1
- package/dist/reconciler/render.d.ts +0 -23
- package/dist/reconciler/render.d.ts.map +0 -1
- package/dist/reconciler/render.js +0 -46
- package/dist/reconciler/render.js.map +0 -1
- package/dist/reconciler/signal-store.d.ts +0 -22
- package/dist/reconciler/signal-store.d.ts.map +0 -1
- package/dist/reconciler/signal-store.js +0 -84
- package/dist/reconciler/signal-store.js.map +0 -1
- package/dist/reconciler/state.d.ts +0 -36
- package/dist/reconciler/state.d.ts.map +0 -1
- package/dist/reconciler/state.js +0 -38
- package/dist/reconciler/state.js.map +0 -1
- package/dist/reconciler/text-buffer-controller.d.ts +0 -17
- package/dist/reconciler/text-buffer-controller.d.ts.map +0 -1
- package/dist/reconciler/text-buffer-controller.js +0 -102
- package/dist/reconciler/text-buffer-controller.js.map +0 -1
- package/dist/reconciler/text-buffer-rebuild.d.ts +0 -3
- package/dist/reconciler/text-buffer-rebuild.d.ts.map +0 -1
- package/dist/reconciler/text-buffer-rebuild.js +0 -7
- package/dist/reconciler/text-buffer-rebuild.js.map +0 -1
- package/dist/reconciler/text-node.d.ts +0 -7
- package/dist/reconciler/text-node.d.ts.map +0 -1
- package/dist/reconciler/text-node.js +0 -8
- package/dist/reconciler/text-node.js.map +0 -1
- package/dist/reconciler/types.d.ts +0 -5
- package/dist/reconciler/types.d.ts.map +0 -1
- package/dist/reconciler/types.js +0 -2
- package/dist/reconciler/types.js.map +0 -1
- package/dist/reconciler/visibility.d.ts +0 -6
- package/dist/reconciler/visibility.d.ts.map +0 -1
- package/dist/reconciler/visibility.js +0 -57
- package/dist/reconciler/visibility.js.map +0 -1
- package/dist/reconciler/wrapper-apply.d.ts +0 -6
- package/dist/reconciler/wrapper-apply.d.ts.map +0 -1
- package/dist/reconciler/wrapper-apply.js +0 -287
- package/dist/reconciler/wrapper-apply.js.map +0 -1
- package/dist/reconciler/wrapper-content.d.ts +0 -8
- package/dist/reconciler/wrapper-content.d.ts.map +0 -1
- package/dist/reconciler/wrapper-content.js +0 -19
- package/dist/reconciler/wrapper-content.js.map +0 -1
- package/dist/reconciler/wrapper-node.d.ts +0 -8
- package/dist/reconciler/wrapper-node.d.ts.map +0 -1
- package/dist/reconciler/wrapper-node.js +0 -4
- package/dist/reconciler/wrapper-node.js.map +0 -1
- package/dist/reconciler/wrapper-protocol.d.ts +0 -13
- package/dist/reconciler/wrapper-protocol.d.ts.map +0 -1
- package/dist/reconciler/wrapper-protocol.js +0 -20
- package/dist/reconciler/wrapper-protocol.js.map +0 -1
- package/dist/utils/create-element-component.d.ts +0 -4
- package/dist/utils/create-element-component.d.ts.map +0 -1
- package/dist/utils/create-element-component.js +0 -54
- package/dist/utils/create-element-component.js.map +0 -1
- package/dist/utils/gtype.d.ts +0 -16
- package/dist/utils/gtype.d.ts.map +0 -1
- package/dist/utils/gtype.js +0 -127
- package/dist/utils/gtype.js.map +0 -1
- package/dist/utils/notify-name.d.ts +0 -5
- package/dist/utils/notify-name.d.ts.map +0 -1
- package/dist/utils/notify-name.js +0 -6
- package/dist/utils/notify-name.js.map +0 -1
- package/dist/utils/object-prop.d.ts +0 -8
- package/dist/utils/object-prop.d.ts.map +0 -1
- package/dist/utils/object-prop.js +0 -9
- package/dist/utils/object-prop.js.map +0 -1
- package/dist/utils/settings-accessor.d.ts +0 -8
- package/dist/utils/settings-accessor.d.ts.map +0 -1
- package/dist/utils/settings-accessor.js +0 -69
- package/dist/utils/settings-accessor.js.map +0 -1
- package/dist/utils/wrapper-node-jsx.d.ts +0 -32
- package/dist/utils/wrapper-node-jsx.d.ts.map +0 -1
- package/dist/utils/wrapper-node-jsx.js +0 -2
- package/dist/utils/wrapper-node-jsx.js.map +0 -1
- package/src/hooks/use-merge-refs.ts +0 -53
- package/src/hooks/use-object-attachment.ts +0 -35
- package/src/libraries/adw/dialog.tsx +0 -34
- package/src/libraries/adw/index.ts +0 -1
- package/src/reconciler/accessible.ts +0 -232
- package/src/reconciler/commit-flush.ts +0 -13
- package/src/reconciler/container-attach.ts +0 -219
- package/src/reconciler/content-rebuild.ts +0 -19
- package/src/reconciler/dispatch.ts +0 -58
- package/src/reconciler/element-prop-appliers.ts +0 -110
- package/src/reconciler/element-props.ts +0 -192
- package/src/reconciler/label-text-rebuild.ts +0 -26
- package/src/reconciler/portal.ts +0 -28
- package/src/reconciler/reconciler-error-handler.ts +0 -29
- package/src/reconciler/reconciler-root.ts +0 -57
- package/src/reconciler/reconciler.ts +0 -13
- package/src/reconciler/render.ts +0 -61
- package/src/reconciler/signal-store.ts +0 -103
- package/src/reconciler/state.ts +0 -72
- package/src/reconciler/text-buffer-controller.ts +0 -107
- package/src/reconciler/text-buffer-rebuild.ts +0 -12
- package/src/reconciler/text-node.ts +0 -13
- package/src/reconciler/types.ts +0 -6
- package/src/reconciler/visibility.ts +0 -52
- package/src/reconciler/wrapper-apply.ts +0 -308
- package/src/reconciler/wrapper-content.ts +0 -24
- package/src/reconciler/wrapper-node.ts +0 -8
- package/src/reconciler/wrapper-protocol.ts +0 -32
- package/src/utils/create-element-component.ts +0 -77
- package/src/utils/gtype.ts +0 -166
- package/src/utils/notify-name.ts +0 -10
- package/src/utils/object-prop.ts +0 -13
- package/src/utils/settings-accessor.ts +0 -89
- package/src/utils/wrapper-node-jsx.ts +0 -34
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import * as Adw from "@gtkx/gi/adw";
|
|
3
|
+
import type { AlertDialogResponse } from "./prop-types.js";
|
|
4
|
+
import {
|
|
5
|
+
addRemoveSlot,
|
|
6
|
+
adoptedChildrenSlot,
|
|
7
|
+
boxSlot,
|
|
8
|
+
childSetterSlot,
|
|
9
|
+
contentSetterSlot,
|
|
10
|
+
deferred,
|
|
11
|
+
list,
|
|
12
|
+
slot,
|
|
13
|
+
} from "../reconciler/behaviors.js";
|
|
14
|
+
import { type ElementConfig, forTypes, registerElements } from "../reconciler/registry.js";
|
|
15
|
+
import { BUILTIN_ELEMENTS, CHILD_SETTER_TYPES, CONTENT_SETTER_TYPES } from "./element-config.js";
|
|
16
|
+
|
|
17
|
+
type AdwChildSetter =
|
|
18
|
+
| Adw.Bin |
|
|
19
|
+
Adw.BreakpointBin |
|
|
20
|
+
Adw.Clamp |
|
|
21
|
+
Adw.ClampScrollable |
|
|
22
|
+
Adw.Dialog |
|
|
23
|
+
Adw.NavigationPage |
|
|
24
|
+
Adw.SplitButton |
|
|
25
|
+
Adw.StatusPage |
|
|
26
|
+
Adw.TabOverview |
|
|
27
|
+
Adw.ToastOverlay |
|
|
28
|
+
Adw.Toggle;
|
|
29
|
+
|
|
30
|
+
type AdwContentSetter = Adw.ApplicationWindow | Adw.BottomSheet | Adw.Flap | Adw.OverlaySplitView | Adw.Window;
|
|
31
|
+
type BreakpointHost = Adw.ApplicationWindow | Adw.Window | Adw.Dialog;
|
|
32
|
+
type PageHost = Adw.PreferencesDialog | Adw.PreferencesWindow;
|
|
33
|
+
type PrefixSuffixRow = Adw.ActionRow | Adw.EntryRow | Adw.ExpanderRow;
|
|
34
|
+
|
|
35
|
+
const childSetter = childSetterSlot<AdwChildSetter>();
|
|
36
|
+
const contentSetter = contentSetterSlot<AdwContentSetter>();
|
|
37
|
+
|
|
38
|
+
const breakpoints = slot<BreakpointHost, Adw.Breakpoint>("breakpoints", "AdwBreakpoint", {
|
|
39
|
+
attach: (host, breakpoint) => {
|
|
40
|
+
host.addBreakpoint(breakpoint);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const prefixSuffix = [
|
|
45
|
+
slot<PrefixSuffixRow, Gtk.Widget>("prefix", "GtkWidget", {
|
|
46
|
+
attach: (row, child) => {
|
|
47
|
+
row.addPrefix(child);
|
|
48
|
+
},
|
|
49
|
+
detach: (row, child) => {
|
|
50
|
+
row.remove(child);
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
slot<PrefixSuffixRow, Gtk.Widget>("suffix", "GtkWidget", {
|
|
54
|
+
attach: (row, child) => {
|
|
55
|
+
row.addSuffix(child);
|
|
56
|
+
},
|
|
57
|
+
detach: (row, child) => {
|
|
58
|
+
row.remove(child);
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const pageHostChildren = addRemoveSlot<Adw.PreferencesPage, PageHost>(
|
|
64
|
+
"children",
|
|
65
|
+
"AdwPreferencesPage",
|
|
66
|
+
(host, page) => {
|
|
67
|
+
host.add(page);
|
|
68
|
+
},
|
|
69
|
+
(host, page) => {
|
|
70
|
+
host.remove(page);
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
/** The runtime half of the built-in element configuration: the behaviors bound to each GObject type. */
|
|
75
|
+
const BUILTIN_BEHAVIORS: Record<string, ElementConfig<never>> = {
|
|
76
|
+
...forTypes(CHILD_SETTER_TYPES, {
|
|
77
|
+
behaviors: [childSetter],
|
|
78
|
+
}),
|
|
79
|
+
...forTypes(CONTENT_SETTER_TYPES, {
|
|
80
|
+
behaviors: [contentSetter],
|
|
81
|
+
}),
|
|
82
|
+
AdwDialog: {
|
|
83
|
+
behaviors: [childSetter, breakpoints],
|
|
84
|
+
},
|
|
85
|
+
AdwApplicationWindow: {
|
|
86
|
+
behaviors: [contentSetter, breakpoints],
|
|
87
|
+
},
|
|
88
|
+
AdwWindow: {
|
|
89
|
+
behaviors: [contentSetter, breakpoints],
|
|
90
|
+
},
|
|
91
|
+
AdwBreakpointBin: {
|
|
92
|
+
behaviors: [
|
|
93
|
+
childSetter,
|
|
94
|
+
addRemoveSlot<Adw.Breakpoint, Adw.BreakpointBin>(
|
|
95
|
+
"breakpoints",
|
|
96
|
+
"AdwBreakpoint",
|
|
97
|
+
(bin, breakpoint) => {
|
|
98
|
+
bin.addBreakpoint(breakpoint);
|
|
99
|
+
},
|
|
100
|
+
(bin, breakpoint) => {
|
|
101
|
+
bin.removeBreakpoint(breakpoint);
|
|
102
|
+
},
|
|
103
|
+
),
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
AdwActionRow: {
|
|
107
|
+
behaviors: prefixSuffix,
|
|
108
|
+
},
|
|
109
|
+
AdwEntryRow: {
|
|
110
|
+
behaviors: prefixSuffix,
|
|
111
|
+
},
|
|
112
|
+
AdwExpanderRow: {
|
|
113
|
+
behaviors: [
|
|
114
|
+
...prefixSuffix,
|
|
115
|
+
addRemoveSlot<Gtk.Widget, Adw.ExpanderRow>(
|
|
116
|
+
"rows",
|
|
117
|
+
"GtkWidget",
|
|
118
|
+
(row, child) => {
|
|
119
|
+
row.addRow(child);
|
|
120
|
+
},
|
|
121
|
+
(row, child) => {
|
|
122
|
+
row.remove(child);
|
|
123
|
+
},
|
|
124
|
+
),
|
|
125
|
+
addRemoveSlot<Gtk.Widget, Adw.ExpanderRow>(
|
|
126
|
+
"actions",
|
|
127
|
+
"GtkWidget",
|
|
128
|
+
(row, child) => {
|
|
129
|
+
row.addAction(child);
|
|
130
|
+
},
|
|
131
|
+
(row, child) => {
|
|
132
|
+
row.remove(child);
|
|
133
|
+
},
|
|
134
|
+
),
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
AdwNavigationSplitView: {
|
|
138
|
+
behaviors: [contentSetterSlot<Adw.NavigationSplitView, Adw.NavigationPage>("AdwNavigationPage")],
|
|
139
|
+
},
|
|
140
|
+
AdwLeaflet: {
|
|
141
|
+
behaviors: [boxSlot<Adw.Leaflet | Adw.WrapBox>()],
|
|
142
|
+
},
|
|
143
|
+
AdwWrapBox: {
|
|
144
|
+
behaviors: [boxSlot<Adw.Leaflet | Adw.WrapBox>()],
|
|
145
|
+
},
|
|
146
|
+
AdwCarousel: {
|
|
147
|
+
behaviors: [
|
|
148
|
+
slot<Adw.Carousel, Gtk.Widget>("children", "GtkWidget", {
|
|
149
|
+
attach: (carousel, child, info) => {
|
|
150
|
+
carousel.insert(child, info.index);
|
|
151
|
+
},
|
|
152
|
+
detach: (carousel, child) => {
|
|
153
|
+
carousel.remove(child);
|
|
154
|
+
},
|
|
155
|
+
reorder: (carousel, child, info) => {
|
|
156
|
+
carousel.reorder(child, info.index);
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
AdwPreferencesPage: {
|
|
162
|
+
behaviors: [
|
|
163
|
+
slot<Adw.PreferencesPage, Adw.PreferencesGroup>("children", "AdwPreferencesGroup", {
|
|
164
|
+
attach: (page, group, info) => {
|
|
165
|
+
page.insert(group, info.index);
|
|
166
|
+
},
|
|
167
|
+
detach: (page, group) => {
|
|
168
|
+
page.remove(group);
|
|
169
|
+
},
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
AdwPreferencesDialog: {
|
|
174
|
+
behaviors: [pageHostChildren],
|
|
175
|
+
},
|
|
176
|
+
AdwPreferencesWindow: {
|
|
177
|
+
behaviors: [pageHostChildren],
|
|
178
|
+
},
|
|
179
|
+
AdwPreferencesGroup: {
|
|
180
|
+
behaviors: [
|
|
181
|
+
addRemoveSlot<Gtk.Widget, Adw.PreferencesGroup>(
|
|
182
|
+
"children",
|
|
183
|
+
"GtkWidget",
|
|
184
|
+
(group, child) => {
|
|
185
|
+
group.add(child);
|
|
186
|
+
},
|
|
187
|
+
(group, child) => {
|
|
188
|
+
group.remove(child);
|
|
189
|
+
},
|
|
190
|
+
),
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
AdwSqueezer: {
|
|
194
|
+
behaviors: [
|
|
195
|
+
addRemoveSlot<Gtk.Widget, Adw.Squeezer>(
|
|
196
|
+
"children",
|
|
197
|
+
"GtkWidget",
|
|
198
|
+
(squeezer, child) => {
|
|
199
|
+
squeezer.add(child);
|
|
200
|
+
},
|
|
201
|
+
(squeezer, child) => {
|
|
202
|
+
squeezer.remove(child);
|
|
203
|
+
},
|
|
204
|
+
),
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
AdwTabView: {
|
|
208
|
+
behaviors: [
|
|
209
|
+
slot<Adw.TabView, Gtk.Widget>("children", "GtkWidget", {
|
|
210
|
+
attach: (view, child, info) => view.insert(child, info.index),
|
|
211
|
+
reorder: (view, _child, info) => {
|
|
212
|
+
if (info.adopted instanceof Adw.TabPage) {
|
|
213
|
+
view.reorderPage(info.adopted, info.index);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
detach: (view, _child, info) => {
|
|
217
|
+
if (info.adopted instanceof Adw.TabPage) {
|
|
218
|
+
view.closePage(info.adopted);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
resolve: (view, child) => view.getPage(child),
|
|
222
|
+
}),
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
AdwNavigationView: {
|
|
226
|
+
behaviors: [
|
|
227
|
+
addRemoveSlot<Adw.NavigationPage, Adw.NavigationView>(
|
|
228
|
+
"children",
|
|
229
|
+
"AdwNavigationPage",
|
|
230
|
+
(view, page) => {
|
|
231
|
+
view.add(page);
|
|
232
|
+
},
|
|
233
|
+
(view, page) => {
|
|
234
|
+
view.remove(page);
|
|
235
|
+
},
|
|
236
|
+
),
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
AdwViewStack: {
|
|
240
|
+
behaviors: [
|
|
241
|
+
adoptedChildrenSlot<Adw.ViewStack, Gtk.Widget>(
|
|
242
|
+
"GtkWidget",
|
|
243
|
+
(stack, child) => stack.add(child),
|
|
244
|
+
(stack, child) => {
|
|
245
|
+
stack.remove(child);
|
|
246
|
+
},
|
|
247
|
+
),
|
|
248
|
+
deferred<Adw.ViewStack, string>("visibleChildName", (stack, name) => stack.getChildByName(name) !== null),
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
AdwToolbarView: {
|
|
252
|
+
behaviors: [
|
|
253
|
+
contentSetterSlot<Adw.ToolbarView>(),
|
|
254
|
+
slot<Adw.ToolbarView, Gtk.Widget>("topBar", "GtkWidget", {
|
|
255
|
+
attach: (view, child) => {
|
|
256
|
+
view.addTopBar(child);
|
|
257
|
+
},
|
|
258
|
+
detach: (view, child) => {
|
|
259
|
+
view.remove(child);
|
|
260
|
+
},
|
|
261
|
+
}),
|
|
262
|
+
slot<Adw.ToolbarView, Gtk.Widget>("bottomBar", "GtkWidget", {
|
|
263
|
+
attach: (view, child) => {
|
|
264
|
+
view.addBottomBar(child);
|
|
265
|
+
},
|
|
266
|
+
detach: (view, child) => {
|
|
267
|
+
view.remove(child);
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
],
|
|
271
|
+
},
|
|
272
|
+
AdwHeaderBar: {
|
|
273
|
+
behaviors: [
|
|
274
|
+
slot<Adw.HeaderBar, Gtk.Widget>("start", "GtkWidget", {
|
|
275
|
+
attach: (bar, child) => {
|
|
276
|
+
bar.packStart(child);
|
|
277
|
+
},
|
|
278
|
+
detach: (bar, child) => {
|
|
279
|
+
bar.remove(child);
|
|
280
|
+
},
|
|
281
|
+
}),
|
|
282
|
+
slot<Adw.HeaderBar, Gtk.Widget>("end", "GtkWidget", {
|
|
283
|
+
attach: (bar, child) => {
|
|
284
|
+
bar.packEnd(child);
|
|
285
|
+
},
|
|
286
|
+
detach: (bar, child) => {
|
|
287
|
+
bar.remove(child);
|
|
288
|
+
},
|
|
289
|
+
}),
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
AdwShortcutsDialog: {
|
|
293
|
+
behaviors: [
|
|
294
|
+
slot<Adw.ShortcutsDialog, Adw.ShortcutsSection>("children", "AdwShortcutsSection", {
|
|
295
|
+
attach: (dialog, section) => {
|
|
296
|
+
dialog.add(section);
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
],
|
|
300
|
+
},
|
|
301
|
+
AdwShortcutsSection: {
|
|
302
|
+
behaviors: [
|
|
303
|
+
slot<Adw.ShortcutsSection, Adw.ShortcutsItem>("children", "AdwShortcutsItem", {
|
|
304
|
+
attach: (section, item) => {
|
|
305
|
+
section.add(item);
|
|
306
|
+
},
|
|
307
|
+
}),
|
|
308
|
+
],
|
|
309
|
+
},
|
|
310
|
+
AdwToggleGroup: {
|
|
311
|
+
behaviors: [
|
|
312
|
+
addRemoveSlot<Adw.Toggle, Adw.ToggleGroup>(
|
|
313
|
+
"children",
|
|
314
|
+
"AdwToggle",
|
|
315
|
+
(group, toggle) => {
|
|
316
|
+
group.add(toggle);
|
|
317
|
+
},
|
|
318
|
+
(group, toggle) => {
|
|
319
|
+
group.remove(toggle);
|
|
320
|
+
},
|
|
321
|
+
),
|
|
322
|
+
deferred<Adw.ToggleGroup, string>("activeName", (group, name) => group.getToggleByName(name) !== null),
|
|
323
|
+
deferred("active"),
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
AdwAlertDialog: {
|
|
327
|
+
behaviors: [
|
|
328
|
+
list<Adw.AlertDialog, AlertDialogResponse>("responses", {
|
|
329
|
+
add: (dialog, response) => {
|
|
330
|
+
dialog.addResponse(response.id, response.label);
|
|
331
|
+
|
|
332
|
+
if (response.appearance !== undefined) {
|
|
333
|
+
dialog.setResponseAppearance(response.id, response.appearance);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (response.enabled !== undefined) {
|
|
337
|
+
dialog.setResponseEnabled(response.id, response.enabled);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
remove: (dialog, response) => {
|
|
341
|
+
dialog.removeResponse(response.id);
|
|
342
|
+
},
|
|
343
|
+
}),
|
|
344
|
+
],
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
registerElements(BUILTIN_ELEMENTS);
|
|
349
|
+
registerElements(BUILTIN_BEHAVIORS);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { type ElementConfig, forTypes, internal, type ModuleExport } from "../reconciler/registry.js";
|
|
2
|
+
|
|
3
|
+
const CHILD_SETTER_TYPES: string[] = [
|
|
4
|
+
"AdwBin",
|
|
5
|
+
"AdwClamp",
|
|
6
|
+
"AdwClampScrollable",
|
|
7
|
+
"AdwNavigationPage",
|
|
8
|
+
"AdwSplitButton",
|
|
9
|
+
"AdwStatusPage",
|
|
10
|
+
"AdwTabOverview",
|
|
11
|
+
"AdwToastOverlay",
|
|
12
|
+
"AdwToggle",
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const CONTENT_SETTER_TYPES: string[] = ["AdwBottomSheet", "AdwFlap", "AdwOverlaySplitView"];
|
|
16
|
+
const childrenProps = internal("ChildrenProps");
|
|
17
|
+
const breakpointsProps = adw("AdwBreakpointsProps");
|
|
18
|
+
const preferencesRowProps = adw("AdwPreferencesRowProps");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The static, runtime-free half of the built-in element configuration: which base props interface each
|
|
22
|
+
* generated element extends, which component wraps it, and whether its GObject is created lazily by its
|
|
23
|
+
* parent. Codegen imports this module, so it must never reach the GObject bindings.
|
|
24
|
+
*/
|
|
25
|
+
const BUILTIN_ELEMENTS: Record<string, ElementConfig> = {
|
|
26
|
+
...forTypes(CHILD_SETTER_TYPES, {
|
|
27
|
+
props: childrenProps,
|
|
28
|
+
omitProps: ["child"],
|
|
29
|
+
}),
|
|
30
|
+
...forTypes(CONTENT_SETTER_TYPES, {
|
|
31
|
+
props: childrenProps,
|
|
32
|
+
omitProps: ["content"],
|
|
33
|
+
}),
|
|
34
|
+
AdwViewStackPage: {
|
|
35
|
+
lazy: true,
|
|
36
|
+
},
|
|
37
|
+
AdwTabPage: {
|
|
38
|
+
lazy: true,
|
|
39
|
+
},
|
|
40
|
+
AdwPreferencesRow: {
|
|
41
|
+
props: preferencesRowProps,
|
|
42
|
+
},
|
|
43
|
+
AdwDialog: {
|
|
44
|
+
props: breakpointsProps,
|
|
45
|
+
component: adw("createDialogComponent"),
|
|
46
|
+
omitProps: ["child"],
|
|
47
|
+
},
|
|
48
|
+
AdwApplicationWindow: {
|
|
49
|
+
props: breakpointsProps,
|
|
50
|
+
omitProps: ["content"],
|
|
51
|
+
},
|
|
52
|
+
AdwWindow: {
|
|
53
|
+
props: breakpointsProps,
|
|
54
|
+
omitProps: ["content"],
|
|
55
|
+
},
|
|
56
|
+
AdwBreakpointBin: {
|
|
57
|
+
props: breakpointsProps,
|
|
58
|
+
omitProps: ["child"],
|
|
59
|
+
},
|
|
60
|
+
AdwActionRow: {
|
|
61
|
+
props: preferencesRowProps,
|
|
62
|
+
},
|
|
63
|
+
AdwEntryRow: {
|
|
64
|
+
props: preferencesRowProps,
|
|
65
|
+
},
|
|
66
|
+
AdwExpanderRow: {
|
|
67
|
+
props: adw("AdwExpanderRowProps"),
|
|
68
|
+
},
|
|
69
|
+
AdwNavigationSplitView: {
|
|
70
|
+
props: childrenProps,
|
|
71
|
+
omitProps: ["content"],
|
|
72
|
+
},
|
|
73
|
+
AdwLeaflet: {
|
|
74
|
+
props: childrenProps,
|
|
75
|
+
},
|
|
76
|
+
AdwWrapBox: {
|
|
77
|
+
props: childrenProps,
|
|
78
|
+
},
|
|
79
|
+
AdwCarousel: {
|
|
80
|
+
props: childrenProps,
|
|
81
|
+
},
|
|
82
|
+
AdwPreferencesPage: {
|
|
83
|
+
props: childrenProps,
|
|
84
|
+
},
|
|
85
|
+
AdwPreferencesDialog: {
|
|
86
|
+
props: childrenProps,
|
|
87
|
+
},
|
|
88
|
+
AdwPreferencesWindow: {
|
|
89
|
+
props: childrenProps,
|
|
90
|
+
},
|
|
91
|
+
AdwPreferencesGroup: {
|
|
92
|
+
props: childrenProps,
|
|
93
|
+
},
|
|
94
|
+
AdwSqueezer: {
|
|
95
|
+
props: childrenProps,
|
|
96
|
+
},
|
|
97
|
+
AdwTabView: {
|
|
98
|
+
props: childrenProps,
|
|
99
|
+
},
|
|
100
|
+
AdwNavigationView: {
|
|
101
|
+
props: childrenProps,
|
|
102
|
+
},
|
|
103
|
+
AdwViewStack: {
|
|
104
|
+
props: childrenProps,
|
|
105
|
+
},
|
|
106
|
+
AdwToolbarView: {
|
|
107
|
+
props: adw("AdwToolbarViewProps"),
|
|
108
|
+
omitProps: ["content"],
|
|
109
|
+
},
|
|
110
|
+
AdwHeaderBar: {
|
|
111
|
+
props: internal("GtkHeaderBarProps"),
|
|
112
|
+
},
|
|
113
|
+
AdwShortcutsDialog: {
|
|
114
|
+
props: childrenProps,
|
|
115
|
+
},
|
|
116
|
+
AdwShortcutsSection: {
|
|
117
|
+
props: childrenProps,
|
|
118
|
+
},
|
|
119
|
+
AdwToggleGroup: {
|
|
120
|
+
props: childrenProps,
|
|
121
|
+
},
|
|
122
|
+
AdwAlertDialog: {
|
|
123
|
+
props: adw("AdwAlertDialogProps"),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function adw(name: string): ModuleExport {
|
|
128
|
+
return { module: "@gtkx/react/adw", export: name };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { CHILD_SETTER_TYPES, CONTENT_SETTER_TYPES, BUILTIN_ELEMENTS };
|
package/src/adw/index.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type * as Adw from "@gtkx/gi/adw";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { ChildrenProps } from "../prop-types.js";
|
|
4
|
+
|
|
5
|
+
type AlertDialogResponse = {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
appearance?: Adw.ResponseAppearance;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type AdwAlertDialogProps = {
|
|
13
|
+
responses?: AlertDialogResponse[] | null | undefined;
|
|
14
|
+
} & ChildrenProps;
|
|
15
|
+
|
|
16
|
+
type AdwPreferencesRowProps = {
|
|
17
|
+
prefix?: ReactNode | null | undefined;
|
|
18
|
+
suffix?: ReactNode | null | undefined;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type AdwExpanderRowProps = {
|
|
22
|
+
rows?: ReactNode | null | undefined;
|
|
23
|
+
actions?: ReactNode | null | undefined;
|
|
24
|
+
} & AdwPreferencesRowProps;
|
|
25
|
+
|
|
26
|
+
type AdwToolbarViewProps = {
|
|
27
|
+
topBar?: ReactNode | null | undefined;
|
|
28
|
+
bottomBar?: ReactNode | null | undefined;
|
|
29
|
+
} & ChildrenProps;
|
|
30
|
+
|
|
31
|
+
type AdwBreakpointsProps = {
|
|
32
|
+
breakpoints?: ReactNode | null | undefined;
|
|
33
|
+
} & ChildrenProps;
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
type AlertDialogResponse,
|
|
37
|
+
type AdwAlertDialogProps,
|
|
38
|
+
type AdwPreferencesRowProps,
|
|
39
|
+
type AdwExpanderRowProps,
|
|
40
|
+
type AdwToolbarViewProps,
|
|
41
|
+
type AdwBreakpointsProps,
|
|
42
|
+
};
|
package/src/bootstrap.ts
ADDED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { applicationId as defaultApplicationId } from "virtual:gtkx-config";
|
|
2
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
3
2
|
import { quitApplication, runApplication } from "@gtkx/runtime";
|
|
4
|
-
import {
|
|
3
|
+
import { pickBy } from "@gtkx/utils";
|
|
4
|
+
import { type ElementType, type ReactNode, type Ref, useLayoutEffect, useState } from "react";
|
|
5
|
+
import { applicationId as defaultApplicationId } from "virtual:gtkx-config";
|
|
5
6
|
import { ApplicationContext } from "../hooks/use-application.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
const POST_ACTIVATE_PROPS = new Set(["menubar"]);
|
|
7
|
+
import { useMergedRef } from "../hooks/use-merged-refs.js";
|
|
9
8
|
|
|
10
9
|
type ApplicationComponentProps = {
|
|
11
10
|
applicationId?: string | null | undefined;
|
|
@@ -13,31 +12,51 @@ type ApplicationComponentProps = {
|
|
|
13
12
|
ref?: Ref<Gtk.Application | null> | undefined;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
Component: ElementType,
|
|
18
|
-
): ((props: ApplicationComponentProps) => ReactNode) => {
|
|
19
|
-
return ({ applicationId = defaultApplicationId, children, ref, ...rest }: ApplicationComponentProps): ReactNode => {
|
|
20
|
-
const [app, setApp] = useState<Gtk.Application | null>(null);
|
|
15
|
+
const POST_ACTIVATE_PROPS = new Set(["menubar"]);
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const useApplicationLifecycle = (
|
|
18
|
+
application: Gtk.Application | null,
|
|
19
|
+
setActivated: (isActivated: boolean) => void,
|
|
20
|
+
): void => {
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
if (!application) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
setApp(null);
|
|
29
|
-
};
|
|
30
|
-
}, []);
|
|
26
|
+
runApplication(application);
|
|
27
|
+
setActivated(true);
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
return () => {
|
|
30
|
+
quitApplication(application);
|
|
31
|
+
setActivated(false);
|
|
32
|
+
};
|
|
33
|
+
}, [application, setActivated]);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const applicationChildren = (application: Gtk.Application | null, children: ReactNode): ReactNode => {
|
|
37
|
+
if (!application) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return <ApplicationContext.Provider value={application}>{children}</ApplicationContext.Provider>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const createApplicationComponent = (
|
|
45
|
+
Component: ElementType,
|
|
46
|
+
): ((props: ApplicationComponentProps) => ReactNode) => {
|
|
47
|
+
return ({ applicationId = defaultApplicationId, children, ref, ...rest }: ApplicationComponentProps): ReactNode => {
|
|
48
|
+
const [application, setApplication] = useState<Gtk.Application | null>(null);
|
|
49
|
+
const [activated, setActivated] = useState(false);
|
|
50
|
+
useApplicationLifecycle(application, setActivated);
|
|
51
|
+
const mergedRef = useMergedRef(ref, setApplication);
|
|
52
|
+
const appliedProps = activated ? rest : pickBy(rest, (_value, key) => !POST_ACTIVATE_PROPS.has(key));
|
|
36
53
|
|
|
37
54
|
return (
|
|
38
55
|
<Component ref={mergedRef} applicationId={applicationId} {...appliedProps}>
|
|
39
|
-
{
|
|
56
|
+
{activated ? applicationChildren(application, children) : null}
|
|
40
57
|
</Component>
|
|
41
58
|
);
|
|
42
59
|
};
|
|
43
60
|
};
|
|
61
|
+
|
|
62
|
+
export { createApplicationComponent };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { isRecord } from "@gtkx/utils";
|
|
2
|
+
import { createElement, type ElementType, isValidElement, type ReactElement, type ReactNode } from "react";
|
|
3
|
+
import type { Props } from "../reconciler/registry.js";
|
|
4
|
+
|
|
5
|
+
/** The intrinsic element that carries an object-valued prop's element into its parent's named property. */
|
|
6
|
+
const Prop = "gtkx:prop";
|
|
7
|
+
|
|
8
|
+
const hasElement = (value: unknown): boolean =>
|
|
9
|
+
isValidElement(value) || (Array.isArray(value) && value.some((item: unknown) => hasElement(item)));
|
|
10
|
+
|
|
11
|
+
const routeProp = (key: string, value: unknown, hostProps: Props, propChildren: ReactNode[]): void => {
|
|
12
|
+
if (key !== "ref" && hasElement(value)) {
|
|
13
|
+
propChildren.push(
|
|
14
|
+
createElement(Prop, { propName: key, key: `${Prop}:${key}` }, value as ReactNode),
|
|
15
|
+
);
|
|
16
|
+
} else {
|
|
17
|
+
hostProps[key] = value;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const buildElement = (typeName: string, record: Props): ReactElement => {
|
|
22
|
+
const Host = typeName as ElementType;
|
|
23
|
+
const hostProps: Props = {};
|
|
24
|
+
const propChildren: ReactNode[] = [];
|
|
25
|
+
|
|
26
|
+
for (const key in record) {
|
|
27
|
+
if (key === "children") {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
routeProp(key, record[key], hostProps, propChildren);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Host {...hostProps}>
|
|
36
|
+
{propChildren}
|
|
37
|
+
{record.children as ReactNode}
|
|
38
|
+
</Host>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const createElementComponent =
|
|
43
|
+
(typeName: string): ((props: unknown) => ReactNode) =>
|
|
44
|
+
(props: unknown): ReactNode =>
|
|
45
|
+
buildElement(typeName, isRecord(props) ? props : {});
|
|
46
|
+
|
|
47
|
+
export { Prop, createElementComponent };
|