@gtkx/react 1.0.0-rc.4 → 1.0.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 +5 -5
- package/dist/adw/dialog.d.ts +3 -4
- package/dist/adw/dialog.d.ts.map +1 -1
- package/dist/adw/dialog.js +15 -21
- package/dist/adw/dialog.js.map +1 -1
- package/dist/adw/element-behaviors.js +102 -54
- package/dist/adw/element-behaviors.js.map +1 -1
- package/dist/adw/element-config.d.ts +0 -6
- package/dist/adw/element-config.d.ts.map +1 -1
- package/dist/adw/element-config.js +15 -17
- package/dist/adw/element-config.js.map +1 -1
- package/dist/adw/prop-types.d.ts +34 -3
- package/dist/adw/prop-types.d.ts.map +1 -1
- package/dist/adw/prop-types.js.map +1 -1
- package/dist/components/application-window.d.ts +5 -0
- package/dist/components/application-window.d.ts.map +1 -0
- package/dist/components/application-window.js +7 -0
- package/dist/components/application-window.js.map +1 -0
- package/dist/components/application.d.ts +2 -8
- package/dist/components/application.d.ts.map +1 -1
- package/dist/components/application.js +21 -6
- package/dist/components/application.js.map +1 -1
- package/dist/components/element.d.ts +13 -1
- package/dist/components/element.d.ts.map +1 -1
- package/dist/components/element.js +39 -14
- package/dist/components/element.js.map +1 -1
- package/dist/components/portaled.d.ts +5 -0
- package/dist/components/portaled.d.ts.map +1 -0
- package/dist/components/portaled.js +8 -0
- package/dist/components/portaled.js.map +1 -0
- package/dist/components/window.d.ts +5 -5
- package/dist/components/window.d.ts.map +1 -1
- package/dist/components/window.js +16 -16
- package/dist/components/window.js.map +1 -1
- package/dist/config.d.ts +3 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/element-behaviors.js +11 -1
- package/dist/element-behaviors.js.map +1 -1
- package/dist/element-config.d.ts.map +1 -1
- package/dist/element-config.js +7 -4
- package/dist/element-config.js.map +1 -1
- package/dist/hooks/use-merged-refs.d.ts +1 -4
- package/dist/hooks/use-merged-refs.d.ts.map +1 -1
- package/dist/hooks/use-merged-refs.js +1 -1
- package/dist/hooks/use-merged-refs.js.map +1 -1
- package/dist/hooks/use-presented-instance.d.ts +12 -0
- package/dist/hooks/use-presented-instance.d.ts.map +1 -0
- package/dist/hooks/use-presented-instance.js +27 -0
- package/dist/hooks/use-presented-instance.js.map +1 -0
- package/dist/hooks/use-property.d.ts +2 -1
- package/dist/hooks/use-property.d.ts.map +1 -1
- package/dist/hooks/use-property.js.map +1 -1
- package/dist/hooks/use-signal.d.ts +2 -1
- package/dist/hooks/use-signal.d.ts.map +1 -1
- package/dist/hooks/use-signal.js.map +1 -1
- package/dist/internal.d.ts +5 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +5 -2
- package/dist/internal.js.map +1 -1
- package/dist/prop-types.d.ts +29 -5
- package/dist/prop-types.d.ts.map +1 -1
- package/dist/prop-types.js.map +1 -1
- package/dist/reconciler/apply-props.d.ts +4 -4
- package/dist/reconciler/apply-props.d.ts.map +1 -1
- package/dist/reconciler/apply-props.js +62 -20
- package/dist/reconciler/apply-props.js.map +1 -1
- package/dist/reconciler/behaviors.d.ts +9 -5
- package/dist/reconciler/behaviors.d.ts.map +1 -1
- package/dist/reconciler/behaviors.js +40 -22
- package/dist/reconciler/behaviors.js.map +1 -1
- package/dist/reconciler/devtools.d.ts +6 -0
- package/dist/reconciler/devtools.d.ts.map +1 -0
- package/dist/reconciler/devtools.js +11 -0
- package/dist/reconciler/devtools.js.map +1 -0
- package/dist/reconciler/host-config.d.ts.map +1 -1
- package/dist/reconciler/host-config.js +17 -26
- package/dist/reconciler/host-config.js.map +1 -1
- package/dist/reconciler/instance.d.ts.map +1 -1
- package/dist/reconciler/instance.js +5 -3
- package/dist/reconciler/instance.js.map +1 -1
- package/dist/reconciler/metadata.d.ts +1 -1
- package/dist/reconciler/metadata.d.ts.map +1 -1
- package/dist/reconciler/metadata.js +2 -4
- package/dist/reconciler/metadata.js.map +1 -1
- package/dist/reconciler/node.d.ts +3 -2
- package/dist/reconciler/node.d.ts.map +1 -1
- package/dist/reconciler/node.js +7 -6
- package/dist/reconciler/node.js.map +1 -1
- package/dist/reconciler/placement.js +20 -20
- package/dist/reconciler/placement.js.map +1 -1
- package/dist/reconciler/registry.d.ts +9 -7
- package/dist/reconciler/registry.d.ts.map +1 -1
- package/dist/reconciler/registry.js.map +1 -1
- package/dist/reconciler/root-element.d.ts +1 -0
- package/dist/reconciler/root-element.d.ts.map +1 -1
- package/dist/reconciler/root-element.js.map +1 -1
- package/dist/reconciler/root.d.ts +3 -0
- package/dist/reconciler/root.d.ts.map +1 -1
- package/dist/reconciler/root.js +2 -0
- package/dist/reconciler/root.js.map +1 -1
- package/dist/reconciler/signals.d.ts +1 -2
- package/dist/reconciler/signals.d.ts.map +1 -1
- package/dist/reconciler/signals.js +1 -1
- package/dist/reconciler/signals.js.map +1 -1
- package/dist/utils/accessible-props.d.ts +8 -8
- package/dist/utils/accessible-props.d.ts.map +1 -1
- package/dist/utils/accessible-props.js +11 -13
- package/dist/utils/accessible-props.js.map +1 -1
- package/dist/utils/settings.d.ts +2 -1
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/settings.js.map +1 -1
- package/dist/utils/variant.d.ts +33 -1
- package/dist/utils/variant.d.ts.map +1 -1
- package/dist/utils/variant.js.map +1 -1
- package/package.json +4 -4
- package/src/adw/dialog.tsx +22 -25
- package/src/adw/element-behaviors.ts +129 -57
- package/src/adw/element-config.ts +15 -17
- package/src/adw/prop-types.ts +35 -2
- package/src/components/application-window.tsx +10 -0
- package/src/components/application.tsx +31 -5
- package/src/components/element.tsx +52 -16
- package/src/components/portaled.tsx +14 -0
- package/src/components/window.tsx +24 -23
- package/src/config.ts +10 -1
- package/src/element-behaviors.ts +20 -0
- package/src/element-config.ts +7 -4
- package/src/hooks/use-merged-refs.ts +1 -1
- package/src/hooks/use-presented-instance.tsx +50 -0
- package/src/hooks/use-property.ts +2 -1
- package/src/hooks/use-signal.ts +2 -1
- package/src/internal.ts +5 -3
- package/src/prop-types.ts +34 -7
- package/src/reconciler/apply-props.ts +77 -24
- package/src/reconciler/behaviors.ts +72 -30
- package/src/reconciler/devtools.ts +18 -0
- package/src/reconciler/host-config.ts +19 -31
- package/src/reconciler/instance.ts +6 -3
- package/src/reconciler/metadata.ts +3 -6
- package/src/reconciler/node.ts +10 -7
- package/src/reconciler/placement.ts +25 -25
- package/src/reconciler/registry.ts +9 -7
- package/src/reconciler/root-element.ts +4 -1
- package/src/reconciler/root.ts +6 -0
- package/src/reconciler/signals.ts +0 -1
- package/src/utils/accessible-props.ts +21 -24
- package/src/utils/settings.ts +2 -1
- package/src/utils/variant.ts +33 -1
- package/dist/utils/accessible-metadata.d.ts +0 -5
- package/dist/utils/accessible-metadata.d.ts.map +0 -1
- package/dist/utils/accessible-metadata.js +0 -18
- package/dist/utils/accessible-metadata.js.map +0 -1
- package/src/utils/accessible-metadata.ts +0 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prop-types.d.ts","sourceRoot":"","sources":["../../src/adw/prop-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,KAAK,mBAAmB,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,GAAG,CAAC,kBAAkB,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACvB,SAAS,CAAC,EAAE,mBAAmB,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"prop-types.d.ts","sourceRoot":"","sources":["../../src/adw/prop-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GA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,GAAG,IAAI,GAAG,SAAS,CAAC;CAC9C,GAAG,aAAa,CAAC;AAElB,iDAAiD;AACjD,KAAK,uBAAuB,GAAG;IAC3B,qFAAqF;IACrF,OAAO,CAAC,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;IACvC;;;OAGG;IACH,CAAC,IAAI,EAAE,GAAG,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;CACzD,CAAC;AAEF,OAAO,EACH,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,GAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prop-types.js","sourceRoot":"","sources":["../../src/adw/prop-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prop-types.js","sourceRoot":"","sources":["../../src/adw/prop-types.ts"],"names":[],"mappings":"AAkEA,OAAO,EAQN,CAAC","sourcesContent":["import type * as Adw from \"@gtkx/gi/adw\";\nimport type { ReactNode } from \"react\";\nimport type { ChildrenProps } from \"../prop-types.js\";\n\n/** One button in an `Adw.AlertDialog`'s `responses` prop. */\ntype AlertDialogResponse = {\n /** Name the dialog reports on `onResponse` when this button is chosen. */\n id: string;\n /** Text shown on the button. */\n label: string;\n /** Styling the button is given, such as suggested or destructive; defaults to the plain appearance. */\n appearance?: Adw.ResponseAppearance;\n /** Whether the button can be activated; defaults to true. */\n isEnabled?: boolean;\n};\n\n/** Props of an `Adw.AlertDialog` element. */\ntype AdwAlertDialogProps = {\n /** Buttons the dialog offers, added and removed as the list changes. */\n responses?: AlertDialogResponse[] | null | undefined;\n /**\n * Widget set as the dialog's extra child, shown below the `heading` and `body` and above the\n * response buttons, leaving the dialog's own chrome in place.\n */\n children?: ReactNode;\n};\n\n/** Props of an `Adw.PreferencesRow` element. */\ntype AdwPreferencesRowProps = {\n /** Widgets added at the start of the row, before its title. */\n prefix?: ReactNode | null | undefined;\n /** Widgets added at the end of the row. */\n suffix?: ReactNode | null | undefined;\n};\n\n/** Props of an `Adw.ExpanderRow` element. */\ntype AdwExpanderRowProps = {\n /** Widgets added to the area the row reveals when it expands. */\n rows?: ReactNode | null | undefined;\n} & AdwPreferencesRowProps;\n\n/** Props of an `Adw.ToolbarView` element, whose `children` is the content the bars surround. */\ntype AdwToolbarViewProps = {\n /** Widgets stacked above the content. */\n topBar?: ReactNode | null | undefined;\n /** Widgets stacked below the content. */\n bottomBar?: ReactNode | null | undefined;\n} & ChildrenProps;\n\n/** Props of an element that hosts breakpoints, such as `Adw.Window` or `Adw.BreakpointBin`. */\ntype AdwBreakpointsProps = {\n /** `Adw.Breakpoint` elements added to the element, each applying while its condition holds. */\n breakpoints?: ReactNode | null | undefined;\n} & ChildrenProps;\n\n/** Props of an `Adw.MultiLayoutView` element. */\ntype AdwMultiLayoutViewProps = {\n /** `Adw.Layout` elements added to the view, each holding the content it lays out. */\n layouts?: ReactNode | null | undefined;\n /**\n * Widget the view places in the `Adw.LayoutSlot` whose `id` is the prop name without its `Slot`\n * suffix, so `sidebarSlot` fills the slot with id `sidebar` in whichever layout is current.\n */\n [slot: `${string}Slot`]: ReactNode | null | undefined;\n};\n\nexport {\n type AlertDialogResponse,\n type AdwAlertDialogProps,\n type AdwPreferencesRowProps,\n type AdwExpanderRowProps,\n type AdwToolbarViewProps,\n type AdwBreakpointsProps,\n type AdwMultiLayoutViewProps,\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ElementType, ReactNode } from "react";
|
|
2
|
+
declare const createApplicationWindowComponent: (Component: ElementType) => ((props: unknown) => ReactNode);
|
|
3
|
+
/** @internal */
|
|
4
|
+
export { createApplicationWindowComponent };
|
|
5
|
+
//# sourceMappingURL=application-window.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-window.d.ts","sourceRoot":"","sources":["../../src/components/application-window.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKpD,QAAA,MAAM,gCAAgC,GAAI,WAAW,WAAW,KAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,CACX,CAAC;AAEvF,gBAAgB;AAChB,OAAO,EAAE,gCAAgC,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useApplication } from "../hooks/use-application.js";
|
|
2
|
+
import { createPortaledComponent } from "./portaled.js";
|
|
3
|
+
import { createPresentedWindowComponent } from "./window.js";
|
|
4
|
+
const createApplicationWindowComponent = (Component) => createPortaledComponent(createPresentedWindowComponent(Component), useApplication);
|
|
5
|
+
/** @internal */
|
|
6
|
+
export { createApplicationWindowComponent };
|
|
7
|
+
//# sourceMappingURL=application-window.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-window.js","sourceRoot":"","sources":["../../src/components/application-window.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,gCAAgC,GAAG,CAAC,SAAsB,EAAmC,EAAE,CACjG,uBAAuB,CAAC,8BAA8B,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,CAAC;AAEvF,gBAAgB;AAChB,OAAO,EAAE,gCAAgC,EAAE,CAAC","sourcesContent":["import type { ElementType, ReactNode } from \"react\";\nimport { useApplication } from \"../hooks/use-application.js\";\nimport { createPortaledComponent } from \"./portaled.js\";\nimport { createPresentedWindowComponent } from \"./window.js\";\n\nconst createApplicationWindowComponent = (Component: ElementType): ((props: unknown) => ReactNode) =>\n createPortaledComponent(createPresentedWindowComponent(Component), useApplication);\n\n/** @internal */\nexport { createApplicationWindowComponent };\n"]}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
type ApplicationComponentProps = {
|
|
4
|
-
applicationId?: string | null | undefined;
|
|
5
|
-
children?: ReactNode | undefined;
|
|
6
|
-
ref?: Ref<Gtk.Application | null> | undefined;
|
|
7
|
-
};
|
|
8
|
-
declare const createApplicationComponent: (Component: ElementType) => ((props: ApplicationComponentProps) => ReactNode);
|
|
1
|
+
import { type ElementType, type ReactNode } from "react";
|
|
2
|
+
declare const createApplicationComponent: (Component: ElementType) => ((props: unknown) => ReactNode);
|
|
9
3
|
/** @internal */
|
|
10
4
|
export { createApplicationComponent };
|
|
11
5
|
//# sourceMappingURL=application.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../src/components/application.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../src/components/application.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAuC,MAAM,OAAO,CAAC;AAgF9F,QAAA,MAAM,0BAA0B,GAAI,WAAW,WAAW,KAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,CAC3B,CAAC;AAEjE,gBAAgB;AAChB,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -1,23 +1,37 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { quitApplication, runApplication } from "@gtkx/runtime";
|
|
3
3
|
import { pickBy } from "@gtkx/utils";
|
|
4
|
+
import process from "node:process";
|
|
4
5
|
import { useLayoutEffect, useState } from "react";
|
|
5
6
|
import { applicationId as defaultApplicationId } from "virtual:gtkx-config";
|
|
6
7
|
import { ApplicationContext } from "../hooks/use-application.js";
|
|
7
8
|
import { useMergedRef } from "../hooks/use-merged-refs.js";
|
|
9
|
+
import { createPortaledComponent } from "./portaled.js";
|
|
8
10
|
const POST_ACTIVATE_PROPS = new Set(["menubar"]);
|
|
9
|
-
const
|
|
11
|
+
const commandLine = (applicationId) => [
|
|
12
|
+
applicationId?.split(".").at(-1) ?? "gtkx",
|
|
13
|
+
...process.argv.slice(2),
|
|
14
|
+
];
|
|
15
|
+
const startApplication = (application, setActivated, applicationId) => {
|
|
16
|
+
application.on("activate", () => {
|
|
17
|
+
setActivated(true);
|
|
18
|
+
});
|
|
19
|
+
const { exitStatus } = runApplication(application, commandLine(applicationId));
|
|
20
|
+
if (exitStatus !== 0) {
|
|
21
|
+
process.exitCode = exitStatus;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const useApplicationLifecycle = (application, setActivated, applicationId) => {
|
|
10
25
|
useLayoutEffect(() => {
|
|
11
26
|
if (!application) {
|
|
12
27
|
return;
|
|
13
28
|
}
|
|
14
|
-
|
|
15
|
-
setActivated(true);
|
|
29
|
+
startApplication(application, setActivated, applicationId);
|
|
16
30
|
return () => {
|
|
17
31
|
quitApplication(application);
|
|
18
32
|
setActivated(false);
|
|
19
33
|
};
|
|
20
|
-
}, [application, setActivated]);
|
|
34
|
+
}, [application, setActivated, applicationId]);
|
|
21
35
|
};
|
|
22
36
|
const applicationChildren = (application, children) => {
|
|
23
37
|
if (!application) {
|
|
@@ -25,16 +39,17 @@ const applicationChildren = (application, children) => {
|
|
|
25
39
|
}
|
|
26
40
|
return _jsx(ApplicationContext.Provider, { value: application, children: children });
|
|
27
41
|
};
|
|
28
|
-
const
|
|
42
|
+
const createApplicationElement = (Component) => {
|
|
29
43
|
return ({ applicationId = defaultApplicationId, children, ref, ...rest }) => {
|
|
30
44
|
const [application, setApplication] = useState(null);
|
|
31
45
|
const [activated, setActivated] = useState(false);
|
|
32
|
-
useApplicationLifecycle(application, setActivated);
|
|
46
|
+
useApplicationLifecycle(application, setActivated, applicationId);
|
|
33
47
|
const mergedRef = useMergedRef(ref, setApplication);
|
|
34
48
|
const appliedProps = activated ? rest : pickBy(rest, (_value, key) => !POST_ACTIVATE_PROPS.has(key));
|
|
35
49
|
return (_jsx(Component, { ref: mergedRef, applicationId: applicationId, ...appliedProps, children: activated ? applicationChildren(application, children) : null }));
|
|
36
50
|
};
|
|
37
51
|
};
|
|
52
|
+
const createApplicationComponent = (Component) => createPortaledComponent(createApplicationElement(Component));
|
|
38
53
|
/** @internal */
|
|
39
54
|
export { createApplicationComponent };
|
|
40
55
|
//# sourceMappingURL=application.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.js","sourceRoot":"","sources":["../../src/components/application.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAA8C,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9F,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../../src/components/application.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAA8C,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9F,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe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x/gi/gtk\";\nimport { quitApplication, runApplication } from \"@gtkx/runtime\";\nimport { pickBy } from \"@gtkx/utils\";\nimport process from \"node:process\";\nimport { type ElementType, type ReactNode, type Ref, useLayoutEffect, useState } from \"react\";\nimport { applicationId as defaultApplicationId } from \"virtual:gtkx-config\";\nimport { ApplicationContext } from \"../hooks/use-application.js\";\nimport { useMergedRef } from \"../hooks/use-merged-refs.js\";\nimport { createPortaledComponent } from \"./portaled.js\";\n\ntype ApplicationComponentProps = {\n applicationId?: string | null | undefined;\n children?: ReactNode | undefined;\n ref?: Ref<Gtk.Application | null> | undefined;\n};\n\nconst POST_ACTIVATE_PROPS = new Set([\"menubar\"]);\n\nconst commandLine = (applicationId: string | null): string[] => [\n applicationId?.split(\".\").at(-1) ?? \"gtkx\",\n ...process.argv.slice(2),\n];\n\nconst startApplication = (\n application: Gtk.Application,\n setActivated: (isActivated: boolean) => void,\n applicationId: string | null,\n): void => {\n application.on(\"activate\", () => {\n setActivated(true);\n });\n\n const { exitStatus } = runApplication(application, commandLine(applicationId));\n\n if (exitStatus !== 0) {\n process.exitCode = exitStatus;\n }\n};\n\nconst useApplicationLifecycle = (\n application: Gtk.Application | null,\n setActivated: (isActivated: boolean) => void,\n applicationId: string | null,\n): void => {\n useLayoutEffect(() => {\n if (!application) {\n return;\n }\n\n startApplication(application, setActivated, applicationId);\n\n return () => {\n quitApplication(application);\n setActivated(false);\n };\n }, [application, setActivated, applicationId]);\n};\n\nconst applicationChildren = (application: Gtk.Application | null, children: ReactNode): ReactNode => {\n if (!application) {\n return null;\n }\n\n return <ApplicationContext.Provider value={application}>{children}</ApplicationContext.Provider>;\n};\n\nconst createApplicationElement = (\n Component: ElementType,\n): ((props: ApplicationComponentProps) => ReactNode) => {\n return ({ applicationId = defaultApplicationId, children, ref, ...rest }: ApplicationComponentProps): ReactNode => {\n const [application, setApplication] = useState<Gtk.Application | null>(null);\n const [activated, setActivated] = useState(false);\n useApplicationLifecycle(application, setActivated, applicationId);\n const mergedRef = useMergedRef(ref, setApplication);\n const appliedProps = activated ? rest : pickBy(rest, (_value, key) => !POST_ACTIVATE_PROPS.has(key));\n\n return (\n <Component ref={mergedRef} applicationId={applicationId} {...appliedProps}>\n {activated ? applicationChildren(application, children) : null}\n </Component>\n );\n };\n};\n\nconst createApplicationComponent = (Component: ElementType): ((props: unknown) => ReactNode) =>\n createPortaledComponent(createApplicationElement(Component));\n\n/** @internal */\nexport { createApplicationComponent };\n"]}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
declare const Prop = "gtkx:prop";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Builds the component that renders the element of a GLib type, which is how the generated `@gtkx/jsx`
|
|
5
|
+
* store exposes every widget. Reach for it to render a type codegen does not cover, such as one
|
|
6
|
+
* `registerClass` created: the element name is the GType name, and the component routes each prop whose
|
|
7
|
+
* value is an element into that prop's slot, which a bare intrinsic element cannot do.
|
|
8
|
+
*
|
|
9
|
+
* Name the props the element takes as the type argument, since the GType name says nothing about them.
|
|
10
|
+
* Left out, the component takes `unknown`, which accepts no attributes at all.
|
|
11
|
+
*
|
|
12
|
+
* @param typeName GType name to render, such as `GtkButton` or the `typeName` given to `registerClass`.
|
|
13
|
+
* @returns A component taking that type's props.
|
|
14
|
+
*/
|
|
15
|
+
declare function createElementComponent<P = unknown>(typeName: string): (props: P) => ReactNode;
|
|
4
16
|
export { Prop, createElementComponent };
|
|
5
17
|
//# sourceMappingURL=element.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/components/element.tsx"],"names":[],"mappings":"AACA,OAAO,EAAsE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG3G,QAAA,MAAM,IAAI,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/components/element.tsx"],"names":[],"mappings":"AACA,OAAO,EAAsE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG3G,QAAA,MAAM,IAAI,cAAc,CAAC;AA4DzB;;;;;;;;;;;GAWG;AAEH,iBAAS,sBAAsB,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,SAAS,CAEtF;AAED,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -2,27 +2,52 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { isRecord } from "@gtkx/utils";
|
|
3
3
|
import { createElement, isValidElement } from "react";
|
|
4
4
|
const Prop = "gtkx:prop";
|
|
5
|
+
const NO_PROP_CHILDREN = [];
|
|
5
6
|
const hasElement = (value) => isValidElement(value) || (Array.isArray(value) && value.some((item) => hasElement(item)));
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const isRoutedProp = (key, value) => key !== "children" && key !== "ref" && hasElement(value);
|
|
8
|
+
const collectPropChildren = (record) => {
|
|
9
|
+
let propChildren = null;
|
|
10
|
+
for (const key in record) {
|
|
11
|
+
if (!isRoutedProp(key, record[key])) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
propChildren ??= [];
|
|
15
|
+
propChildren.push(createElement(Prop, { propName: key, key: `${Prop}:${key}` }, record[key]));
|
|
12
16
|
}
|
|
17
|
+
return propChildren;
|
|
13
18
|
};
|
|
14
|
-
const
|
|
15
|
-
const Host = typeName;
|
|
19
|
+
const hostPropsWithout = (record) => {
|
|
16
20
|
const hostProps = {};
|
|
17
|
-
const propChildren = [];
|
|
18
21
|
for (const key in record) {
|
|
19
|
-
if (key
|
|
20
|
-
|
|
22
|
+
if (key !== "children" && !isRoutedProp(key, record[key])) {
|
|
23
|
+
hostProps[key] = record[key];
|
|
21
24
|
}
|
|
22
|
-
routeProp(key, record[key], hostProps, propChildren);
|
|
23
25
|
}
|
|
24
|
-
return
|
|
26
|
+
return hostProps;
|
|
27
|
+
};
|
|
28
|
+
const buildElement = (typeName, record) => {
|
|
29
|
+
const Host = typeName;
|
|
30
|
+
const propChildren = collectPropChildren(record);
|
|
31
|
+
if (propChildren === null) {
|
|
32
|
+
return (_jsxs(Host, { ...record, children: [NO_PROP_CHILDREN, record.children] }));
|
|
33
|
+
}
|
|
34
|
+
return (_jsxs(Host, { ...hostPropsWithout(record), children: [propChildren, record.children] }));
|
|
25
35
|
};
|
|
26
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Builds the component that renders the element of a GLib type, which is how the generated `@gtkx/jsx`
|
|
38
|
+
* store exposes every widget. Reach for it to render a type codegen does not cover, such as one
|
|
39
|
+
* `registerClass` created: the element name is the GType name, and the component routes each prop whose
|
|
40
|
+
* value is an element into that prop's slot, which a bare intrinsic element cannot do.
|
|
41
|
+
*
|
|
42
|
+
* Name the props the element takes as the type argument, since the GType name says nothing about them.
|
|
43
|
+
* Left out, the component takes `unknown`, which accepts no attributes at all.
|
|
44
|
+
*
|
|
45
|
+
* @param typeName GType name to render, such as `GtkButton` or the `typeName` given to `registerClass`.
|
|
46
|
+
* @returns A component taking that type's props.
|
|
47
|
+
*/
|
|
48
|
+
/* eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- callers name the props */
|
|
49
|
+
function createElementComponent(typeName) {
|
|
50
|
+
return (props) => buildElement(typeName, isRecord(props) ? props : {});
|
|
51
|
+
}
|
|
27
52
|
export { Prop, createElementComponent };
|
|
28
53
|
//# sourceMappingURL=element.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/components/element.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAoB,cAAc,EAAqC,MAAM,OAAO,CAAC;AAG3G,MAAM,IAAI,GAAG,WAAW,CAAC;
|
|
1
|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AE5B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,GAAG,KAAK,UAAU,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACxD,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,QAAgB,EAAE,MAAa,EAAgB,EAAE;IACnE,MAAM,IAAI,GAAG,QAAuB,CAAC;IACrC,MAAM,YAAY,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QACxB,OAAO,CACH,MAAC,IAAI,OAAK,MAAM,aACX,gBAAgB,EAChB,MAAM,CAAC,QAAqB,IAC1B,CACV,CAAC;IACN,CAAC;IAED,OAAO,CACH,MAAC,IAAI,OAAK,gBAAgB,CAAC,MAAM,CAAC,aAC7B,YAAY,EACZ,MAAM,CAAC,QAAqB,IAC1B,CACV,CAAC;AACN,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,0GAA0G;AAC1G,SAAS,sBAAsB,CAAc,QAAgB;IACzD,OAAO,CAAC,KAAQ,EAAa,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACzF,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["import { isRecord } from \"@gtkx/utils\";\nimport { createElement, type ElementType, isValidElement, type ReactElement, type ReactNode } from \"react\";\nimport type { Props } from \"../reconciler/registry.js\";\n\nconst Prop = \"gtkx:prop\";\nconst NO_PROP_CHILDREN: ReactNode[] = [];\n\nconst hasElement = (value: unknown): boolean =>\n isValidElement(value) || (Array.isArray(value) && value.some((item: unknown) => hasElement(item)));\n\nconst isRoutedProp = (key: string, value: unknown): boolean =>\n key !== \"children\" && key !== \"ref\" && hasElement(value);\n\nconst collectPropChildren = (record: Props): ReactNode[] | null => {\n let propChildren: ReactNode[] | null = null;\n\n for (const key in record) {\n if (!isRoutedProp(key, record[key])) {\n continue;\n }\n\n propChildren ??= [];\n\n propChildren.push(\n createElement(Prop, { propName: key, key: `${Prop}:${key}` }, record[key] as ReactNode),\n );\n }\n\n return propChildren;\n};\n\nconst hostPropsWithout = (record: Props): Props => {\n const hostProps: Props = {};\n\n for (const key in record) {\n if (key !== \"children\" && !isRoutedProp(key, record[key])) {\n hostProps[key] = record[key];\n }\n }\n\n return hostProps;\n};\n\nconst buildElement = (typeName: string, record: Props): ReactElement => {\n const Host = typeName as ElementType;\n const propChildren = collectPropChildren(record);\n\n if (propChildren === null) {\n return (\n <Host {...record}>\n {NO_PROP_CHILDREN}\n {record.children as ReactNode}\n </Host>\n );\n }\n\n return (\n <Host {...hostPropsWithout(record)}>\n {propChildren}\n {record.children as ReactNode}\n </Host>\n );\n};\n\n/**\n * Builds the component that renders the element of a GLib type, which is how the generated `@gtkx/jsx`\n * store exposes every widget. Reach for it to render a type codegen does not cover, such as one\n * `registerClass` created: the element name is the GType name, and the component routes each prop whose\n * value is an element into that prop's slot, which a bare intrinsic element cannot do.\n *\n * Name the props the element takes as the type argument, since the GType name says nothing about them.\n * Left out, the component takes `unknown`, which accepts no attributes at all.\n *\n * @param typeName GType name to render, such as `GtkButton` or the `typeName` given to `registerClass`.\n * @returns A component taking that type's props.\n */\n/* eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- callers name the props */\nfunction createElementComponent<P = unknown>(typeName: string): (props: P) => ReactNode {\n return (props: P): ReactNode => buildElement(typeName, isRecord(props) ? props : {});\n}\n\nexport { Prop, createElementComponent };\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ElementType, ReactNode } from "react";
|
|
2
|
+
import type { Container } from "../reconciler/host-config.js";
|
|
3
|
+
declare const createPortaledComponent: (Component: ElementType, useContainer?: () => Container) => ((props: unknown) => ReactNode);
|
|
4
|
+
export { createPortaledComponent };
|
|
5
|
+
//# sourceMappingURL=portaled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portaled.d.ts","sourceRoot":"","sources":["../../src/components/portaled.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAM9D,QAAA,MAAM,uBAAuB,GACxB,WAAW,WAAW,EAAE,eAAc,MAAM,SAA4B,KAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,CAEnB,CAAC;AAE5F,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isRecord } from "@gtkx/utils";
|
|
3
|
+
import { rootElement } from "../reconciler/root-element.js";
|
|
4
|
+
import { createPortal } from "../reconciler/root.js";
|
|
5
|
+
const useRootContainer = () => rootElement;
|
|
6
|
+
const createPortaledComponent = (Component, useContainer = useRootContainer) => (props) => createPortal(_jsx(Component, { ...(isRecord(props) ? props : {}) }), useContainer());
|
|
7
|
+
export { createPortaledComponent };
|
|
8
|
+
//# sourceMappingURL=portaled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portaled.js","sourceRoot":"","sources":["../../src/components/portaled.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,gBAAgB,GAAG,GAAc,EAAE,CAAC,WAAW,CAAC;AAEtD,MAAM,uBAAuB,GACzB,CAAC,SAAsB,EAAE,eAAgC,gBAAgB,EAAmC,EAAE,CAC1G,CAAC,KAAc,EAAa,EAAE,CAC1B,YAAY,CAAC,KAAC,SAAS,OAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,GAAI,EAAE,YAAY,EAAE,CAAC,CAAC;AAE5F,OAAO,EAAE,uBAAuB,EAAE,CAAC","sourcesContent":["import type { ElementType, ReactNode } from \"react\";\nimport { isRecord } from \"@gtkx/utils\";\nimport type { Container } from \"../reconciler/host-config.js\";\nimport { rootElement } from \"../reconciler/root-element.js\";\nimport { createPortal } from \"../reconciler/root.js\";\n\nconst useRootContainer = (): Container => rootElement;\n\nconst createPortaledComponent =\n (Component: ElementType, useContainer: () => Container = useRootContainer): ((props: unknown) => ReactNode) =>\n (props: unknown): ReactNode =>\n createPortal(<Component {...(isRecord(props) ? props : {})} />, useContainer());\n\nexport { createPortaledComponent };\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import { type ElementType, type ReactNode
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { type ElementType, type ReactNode } from "react";
|
|
3
|
+
import { type PresentedProps } from "../hooks/use-presented-instance.js";
|
|
4
|
+
declare const createPresentedWindowComponent: (Component: ElementType) => ((props: PresentedProps<Gtk.Window>) => ReactNode);
|
|
5
|
+
declare const createWindowComponent: (Component: ElementType) => ((props: unknown) => ReactNode);
|
|
6
|
+
export { createPresentedWindowComponent };
|
|
7
7
|
/** @internal */
|
|
8
8
|
export { createWindowComponent };
|
|
9
9
|
//# sourceMappingURL=window.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../src/components/window.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../src/components/window.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,KAAK,WAAW,EAAqB,KAAK,SAAS,EAAO,MAAM,OAAO,CAAC;AAEjF,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAuBnG,QAAA,MAAM,8BAA8B,GAAI,WAAW,WAAW,KAAG,CAAC,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,SAAS,CAO5G,CAAC;AAWP,QAAA,MAAM,qBAAqB,GAAI,WAAW,WAAW,KAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,CACS,CAAC;AAEhG,OAAO,EAAE,8BAA8B,EAAE,CAAC;AAC1C,gBAAgB;AAChB,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useMergedRef } from "../hooks/use-merged-refs.js";
|
|
2
|
+
import { use } from "react";
|
|
4
3
|
import { ParentWindowContext } from "../hooks/use-parent-window.js";
|
|
4
|
+
import { createPresentedComponent } from "../hooks/use-presented-instance.js";
|
|
5
5
|
import { applyWrite } from "../reconciler/signals.js";
|
|
6
|
+
import { createPortaledComponent } from "./portaled.js";
|
|
6
7
|
const presentWindow = (window) => {
|
|
7
8
|
applyWrite(() => {
|
|
8
9
|
window.present();
|
|
@@ -13,22 +14,21 @@ const destroyWindow = (window) => {
|
|
|
13
14
|
window.destroy();
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
}, [window]);
|
|
29
|
-
return (_jsx(ParentWindowContext.Provider, { value: window, children: _jsx(Component, { ref: mergedRef, ...rest }) }));
|
|
17
|
+
const usePresentWindow = () => presentWindow;
|
|
18
|
+
const createPresentedWindowComponent = (Component) => createPresentedComponent(Component, {
|
|
19
|
+
usePresent: usePresentWindow,
|
|
20
|
+
dismiss: destroyWindow,
|
|
21
|
+
wrap: (element, window) => (_jsx(ParentWindowContext.Provider, { value: window, children: element })),
|
|
22
|
+
});
|
|
23
|
+
const withDefaultTransientFor = (Component) => {
|
|
24
|
+
return (props) => {
|
|
25
|
+
const parent = use(ParentWindowContext);
|
|
26
|
+
const isDefaulted = props.transientFor === undefined && parent !== null;
|
|
27
|
+
return _jsx(Component, { ...(isDefaulted ? { ...props, transientFor: parent } : props) });
|
|
30
28
|
};
|
|
31
29
|
};
|
|
30
|
+
const createWindowComponent = (Component) => createPortaledComponent(withDefaultTransientFor(createPresentedWindowComponent(Component)));
|
|
31
|
+
export { createPresentedWindowComponent };
|
|
32
32
|
/** @internal */
|
|
33
33
|
export { createWindowComponent };
|
|
34
34
|
//# sourceMappingURL=window.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window.js","sourceRoot":"","sources":["../../src/components/window.tsx"],"names":[],"mappings":";AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"window.js","sourceRoot":"","sources":["../../src/components/window.tsx"],"names":[],"mappings":";AACA,OAAO,EAAuD,GAAG,EAAE,MAAM,OAAO,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAuB,MAAM,oCAAoC,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAOxD,MAAM,a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8BAA8B,EAAE,CAAC;AAC1C,gBAAgB;AAChB,OAAO,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport { type ElementType, type ReactElement, type ReactNode, use } from \"react\";\nimport { ParentWindowContext } from \"../hooks/use-parent-window.js\";\nimport { createPresentedComponent, type PresentedProps } from \"../hooks/use-presented-instance.js\";\nimport { applyWrite } from \"../reconciler/signals.js\";\nimport { createPortaledComponent } from \"./portaled.js\";\n\ntype WindowComponentProps = PresentedProps<Gtk.Window> & {\n // eslint-disable-next-line gtkx/accessor-naming\n transientFor?: Gtk.Window | ReactElement | null | undefined;\n};\n\nconst presentWindow = (window: Gtk.Window): void => {\n applyWrite(() => {\n window.present();\n });\n};\n\nconst destroyWindow = (window: Gtk.Window): void => {\n applyWrite(() => {\n window.destroy();\n });\n};\n\nconst usePresentWindow = (): ((window: Gtk.Window) => void) => presentWindow;\n\nconst createPresentedWindowComponent = (Component: ElementType): ((props: PresentedProps<Gtk.Window>) => ReactNode) =>\n createPresentedComponent<Gtk.Window>(Component, {\n usePresent: usePresentWindow,\n dismiss: destroyWindow,\n wrap: (element, window) => (\n <ParentWindowContext.Provider value={window}>{element}</ParentWindowContext.Provider>\n ),\n });\n\nconst withDefaultTransientFor = (Component: ElementType): ((props: WindowComponentProps) => ReactNode) => {\n return (props: WindowComponentProps): ReactNode => {\n const parent = use(ParentWindowContext);\n const isDefaulted = props.transientFor === undefined && parent !== null;\n\n return <Component {...(isDefaulted ? { ...props, transientFor: parent } : props)} />;\n };\n};\n\nconst createWindowComponent = (Component: ElementType): ((props: unknown) => ReactNode) =>\n createPortaledComponent(withDefaultTransientFor(createPresentedWindowComponent(Component)));\n\nexport { createPresentedWindowComponent };\n/** @internal */\nexport { createWindowComponent };\n"]}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** @public */
|
|
2
|
+
export { createElementComponent } from "./components/element.js";
|
|
3
|
+
/** @public */
|
|
2
4
|
export { BUILTIN_ELEMENTS } from "./element-config.js";
|
|
3
5
|
/** @public */
|
|
4
|
-
export type { DetachInfo, ElementBehavior, ElementConfig, PlaceInfo, Props } from "./reconciler/registry.js";
|
|
6
|
+
export type { DetachInfo, ElementBehavior, ElementConfig, ModuleExport, PlaceInfo, Props, } from "./reconciler/registry.js";
|
|
5
7
|
/** @public */
|
|
6
8
|
export { defineBehavior, defineElements, ELEMENTS, mergeElementConfigs } from "./reconciler/registry.js";
|
|
7
9
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc;AACd,YAAY,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc;AACd,YAAY,EACR,UAAU,EACV,eAAe,EACf,aAAa,EACb,YAAY,EACZ,SAAS,EACT,KAAK,GACR,MAAM,0BAA0B,CAAC;AAClC,cAAc;AACd,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** @public */
|
|
2
|
+
export { createElementComponent } from "./components/element.js";
|
|
3
|
+
/** @public */
|
|
2
4
|
export { BUILTIN_ELEMENTS } from "./element-config.js";
|
|
3
5
|
/** @public */
|
|
4
6
|
export { defineBehavior, defineElements, ELEMENTS, mergeElementConfigs } from "./reconciler/registry.js";
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAUvD,cAAc;AACd,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["/** @public */\nexport { createElementComponent } from \"./components/element.js\";\n/** @public */\nexport { BUILTIN_ELEMENTS } from \"./element-config.js\";\n/** @public */\nexport type {\n DetachInfo,\n ElementBehavior,\n ElementConfig,\n ModuleExport,\n PlaceInfo,\n Props,\n} from \"./reconciler/registry.js\";\n/** @public */\nexport { defineBehavior, defineElements, ELEMENTS, mergeElementConfigs } from \"./reconciler/registry.js\";\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as Gio from "@gtkx/gi/gio";
|
|
2
|
+
import * as GLib from "@gtkx/gi/glib";
|
|
2
3
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
4
|
import { BUILTIN_ELEMENTS, SINGLE_CHILD_TYPES } from "./element-config.js";
|
|
4
|
-
import { addRemoveSlot, adoptedChildrenSlot, boxSlot, childSetterSlot, controlledText, deferred, list, slot, value, wrappingIndexedSlot, } from "./reconciler/behaviors.js";
|
|
5
|
+
import { addRemoveSlot, adoptedChildrenSlot, applicationCreator, boxSlot, childSetterSlot, controlledText, deferred, list, slot, value, wrappingIndexedSlot, } from "./reconciler/behaviors.js";
|
|
5
6
|
import { forTypes, registerElements } from "./reconciler/registry.js";
|
|
6
7
|
const BUILTIN_BEHAVIORS = {
|
|
7
8
|
...forTypes(SINGLE_CHILD_TYPES, {
|
|
@@ -234,6 +235,7 @@ const BUILTIN_BEHAVIORS = {
|
|
|
234
235
|
},
|
|
235
236
|
GtkApplication: {
|
|
236
237
|
behaviors: [
|
|
238
|
+
applicationCreator(Gtk.Application),
|
|
237
239
|
addRemoveSlot("children", "GtkWindow", (application, window) => {
|
|
238
240
|
application.addWindow(window);
|
|
239
241
|
}, (application, window) => {
|
|
@@ -247,6 +249,11 @@ const BUILTIN_BEHAVIORS = {
|
|
|
247
249
|
application.setAccelsForAction(item.detailedActionName, []);
|
|
248
250
|
},
|
|
249
251
|
}),
|
|
252
|
+
list("mainOptions", {
|
|
253
|
+
add: (application, option) => {
|
|
254
|
+
addMainOption(application, option);
|
|
255
|
+
},
|
|
256
|
+
}),
|
|
250
257
|
],
|
|
251
258
|
},
|
|
252
259
|
GtkAboutDialog: {
|
|
@@ -323,6 +330,9 @@ const BUILTIN_BEHAVIORS = {
|
|
|
323
330
|
function layoutChild(parent, child) {
|
|
324
331
|
return parent.getLayoutManager()?.getLayoutChild(child) ?? null;
|
|
325
332
|
}
|
|
333
|
+
const addMainOption = (application, option) => {
|
|
334
|
+
application.addMainOption(option.longName, option.shortName?.codePointAt(0) ?? 0, option.flags ?? GLib.OptionFlags.NONE, option.arg ?? GLib.OptionArg.NONE, option.description, option.argDescription ?? null);
|
|
335
|
+
};
|
|
326
336
|
const buildMenu = (items) => {
|
|
327
337
|
const menu = Gio.Menu.new();
|
|
328
338
|
for (const item of items) {
|