@gtkx/react 1.0.0-rc.1 → 1.0.0-rc.2
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 +299 -0
- package/dist/adw/element-behaviors.js.map +1 -0
- package/dist/adw/element-config.d.ts +9 -0
- package/dist/adw/element-config.d.ts.map +1 -0
- package/dist/adw/element-config.js +137 -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 +10 -11
- 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 +146 -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 +10 -7
- package/dist/hooks/use-signal.d.ts.map +1 -1
- package/dist/hooks/use-signal.js +29 -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 +6 -7
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +5 -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 +182 -84
- 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 +172 -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 +175 -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 +175 -0
- package/dist/reconciler/placement.js.map +1 -0
- package/dist/reconciler/registry.d.ts +92 -0
- package/dist/reconciler/registry.d.ts.map +1 -0
- package/dist/reconciler/registry.js +64 -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 +109 -0
- package/dist/reconciler/root.js.map +1 -0
- package/dist/reconciler/signals.d.ts +10 -0
- package/dist/reconciler/signals.d.ts.map +1 -0
- package/dist/reconciler/signals.js +70 -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 +276 -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 +379 -0
- package/src/adw/element-config.ts +140 -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 +12 -13
- package/src/config.ts +3 -0
- package/src/element-behaviors.ts +424 -0
- package/src/element-config.ts +148 -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 +37 -48
- package/src/index.ts +7 -8
- package/src/internal.ts +7 -18
- package/src/prop-types.ts +142 -0
- package/src/reconciler/apply-props.ts +233 -85
- package/src/reconciler/behaviors.ts +324 -0
- package/src/reconciler/child-routing.ts +202 -0
- package/src/reconciler/host-config.ts +239 -366
- 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 +255 -0
- package/src/reconciler/registry.ts +161 -0
- package/src/reconciler/root-element.ts +9 -11
- package/src/reconciler/root.ts +175 -0
- package/src/reconciler/signals.ts +113 -0
- package/src/reconciler/text.ts +407 -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
|
@@ -1,30 +1,82 @@
|
|
|
1
|
-
import * as GObject from "@gtkx/gi/gobject";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import type
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
|
+
import { getWrapperClass, TYPE_INVALID, typeFromName, typeIsA } from "@gtkx/runtime";
|
|
3
|
+
import { pickBy } from "@gtkx/utils";
|
|
4
|
+
import type { Props } from "./registry.js";
|
|
5
|
+
import { type TypeInfo, typeInfoFor } from "./metadata.js";
|
|
6
|
+
import {
|
|
7
|
+
type ContentKind,
|
|
8
|
+
createElementNode,
|
|
9
|
+
createLazyNode,
|
|
10
|
+
type Dispatch,
|
|
11
|
+
type ElementNode,
|
|
12
|
+
type LazyNode,
|
|
13
|
+
} from "./node.js";
|
|
14
|
+
import { ELEMENTS } from "./registry.js";
|
|
15
|
+
|
|
16
|
+
type WidgetConstructor = new (props: Props) => GObject.Object;
|
|
17
|
+
type ContentType = { kind: ContentKind; type: bigint };
|
|
18
|
+
|
|
19
|
+
const CONTENT_TYPE_NAMES: { kind: ContentKind; name: string }[] = [
|
|
20
|
+
{ kind: "label", name: "GtkLabel" },
|
|
21
|
+
{ kind: "buffer", name: "GtkTextBuffer" },
|
|
22
|
+
{ kind: "tag", name: "GtkTextTag" },
|
|
23
|
+
{ kind: "anchor", name: "GtkTextChildAnchor" },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const getContentTypes = createContentTypeCache();
|
|
27
|
+
|
|
28
|
+
function createContentTypeCache(): () => ContentType[] {
|
|
29
|
+
let cached: ContentType[] | null = null;
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
cached ??= CONTENT_TYPE_NAMES.map((entry) => ({ kind: entry.kind, type: typeFromName(entry.name) }));
|
|
33
|
+
|
|
34
|
+
return cached;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const resolveContentKind = (type: bigint): ContentKind | null => {
|
|
39
|
+
for (const entry of getContentTypes()) {
|
|
40
|
+
if (entry.type !== TYPE_INVALID && typeIsA(type, entry.type)) {
|
|
41
|
+
return entry.kind;
|
|
42
|
+
}
|
|
15
43
|
}
|
|
16
|
-
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const constructInput = (info: TypeInfo, props: Props): Props =>
|
|
49
|
+
pickBy(
|
|
50
|
+
props,
|
|
51
|
+
(value, name) =>
|
|
52
|
+
value !== undefined &&
|
|
53
|
+
!info.deferred.has(name) &&
|
|
54
|
+
(info.constructOnly.has(name) || info.construct.has(name)),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const instantiate = (type: bigint, input: Props): GObject.Object => {
|
|
58
|
+
const cls = getWrapperClass(type) as WidgetConstructor;
|
|
59
|
+
|
|
60
|
+
return new cls(input);
|
|
17
61
|
};
|
|
18
62
|
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return node;
|
|
63
|
+
const createObject = (typeName: string, type: bigint, input: Props): GObject.Object => {
|
|
64
|
+
const create = ELEMENTS[typeName]?.behaviors?.find((behavior) => behavior.create !== undefined)?.create;
|
|
65
|
+
|
|
66
|
+
return create === undefined ? instantiate(type, input) : create(input);
|
|
24
67
|
};
|
|
25
68
|
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
69
|
+
const resolveElementNode = (typeName: string, props: Props, dispatch: Dispatch): ElementNode | LazyNode => {
|
|
70
|
+
const info = typeInfoFor(typeName);
|
|
71
|
+
|
|
72
|
+
if (info.lazy) {
|
|
73
|
+
return createLazyNode(typeName, props, dispatch);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const type = typeFromName(typeName);
|
|
77
|
+
const object = createObject(typeName, type, constructInput(info, props));
|
|
78
|
+
|
|
79
|
+
return createElementNode(typeName, object, dispatch, resolveContentKind(type));
|
|
30
80
|
};
|
|
81
|
+
|
|
82
|
+
export { resolveElementNode };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { TYPE_INVALID, typeFromName, typeInterfaces, typeName, typeParent } from "@gtkx/runtime";
|
|
2
|
+
import { getOrInsert } from "@gtkx/utils";
|
|
3
|
+
import { CONSTRUCT_ONLY_PROPS, CONSTRUCT_PROPS, DEFAULT_PROPS, SIGNALS, userEventSignals } from "virtual:gtkx-config";
|
|
4
|
+
import { deferredProps, type ElementBehavior, ELEMENTS } from "./registry.js";
|
|
5
|
+
|
|
6
|
+
type TypeInfo = {
|
|
7
|
+
typeName: string;
|
|
8
|
+
signals: Record<string, string>;
|
|
9
|
+
userEventSignals: Set<string>;
|
|
10
|
+
behaviors: ElementBehavior[];
|
|
11
|
+
deferred: Set<string>;
|
|
12
|
+
lazy: boolean;
|
|
13
|
+
hasFlush: boolean;
|
|
14
|
+
hasMount: boolean;
|
|
15
|
+
constructOnly: Set<string>;
|
|
16
|
+
construct: Set<string>;
|
|
17
|
+
defaults: Record<string, unknown>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const ancestryCache: Map<string, string[]> = new Map();
|
|
21
|
+
const typeInfoCache: Map<string, TypeInfo> = new Map();
|
|
22
|
+
|
|
23
|
+
const addAncestor = (names: string[], seen: Set<string>, name: string | null): void => {
|
|
24
|
+
if (name === null || seen.has(name)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
seen.add(name);
|
|
29
|
+
names.push(name);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const buildAncestry = (name: string): string[] => {
|
|
33
|
+
const names: string[] = [];
|
|
34
|
+
const seen: Set<string> = new Set();
|
|
35
|
+
let type = typeFromName(name);
|
|
36
|
+
|
|
37
|
+
while (type !== TYPE_INVALID) {
|
|
38
|
+
addAncestor(names, seen, typeName(type));
|
|
39
|
+
|
|
40
|
+
for (const iface of typeInterfaces(type)) {
|
|
41
|
+
addAncestor(names, seen, typeName(iface));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type = typeParent(type);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return names;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const ancestryFor = (name: string): string[] => getOrInsert(ancestryCache, name, buildAncestry);
|
|
51
|
+
|
|
52
|
+
const addAll = <T>(target: Set<T>, source: Iterable<T> | undefined): void => {
|
|
53
|
+
const items = source ?? [];
|
|
54
|
+
|
|
55
|
+
for (const item of items) {
|
|
56
|
+
target.add(item);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const accumulateAncestor = (info: TypeInfo, ancestor: string): void => {
|
|
61
|
+
Object.assign(info.signals, SIGNALS[ancestor] ?? {});
|
|
62
|
+
addAll(info.userEventSignals, userEventSignals[ancestor]);
|
|
63
|
+
addAll(info.constructOnly, CONSTRUCT_ONLY_PROPS[ancestor]);
|
|
64
|
+
addAll(info.construct, CONSTRUCT_PROPS[ancestor]);
|
|
65
|
+
info.behaviors.push(...(ELEMENTS[ancestor]?.behaviors ?? []));
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const applyBehaviorFlags = (info: TypeInfo, behavior: ElementBehavior): void => {
|
|
69
|
+
if (behavior.flush !== undefined) {
|
|
70
|
+
info.hasFlush = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (behavior.mount !== undefined) {
|
|
74
|
+
info.hasMount = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
addAll(info.deferred, deferredProps(behavior));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const resolveBehaviorFlags = (info: TypeInfo): void => {
|
|
81
|
+
for (const behavior of info.behaviors) {
|
|
82
|
+
applyBehaviorFlags(info, behavior);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const buildTypeInfo = (name: string): TypeInfo => {
|
|
87
|
+
const chain = ancestryFor(name);
|
|
88
|
+
|
|
89
|
+
const info: TypeInfo = {
|
|
90
|
+
typeName: name,
|
|
91
|
+
signals: {},
|
|
92
|
+
userEventSignals: new Set(),
|
|
93
|
+
behaviors: [],
|
|
94
|
+
deferred: new Set(),
|
|
95
|
+
lazy: false,
|
|
96
|
+
hasFlush: false,
|
|
97
|
+
hasMount: false,
|
|
98
|
+
constructOnly: new Set(),
|
|
99
|
+
construct: new Set(),
|
|
100
|
+
defaults: {},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
for (const ancestor of chain) {
|
|
104
|
+
accumulateAncestor(info, ancestor);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
resolveBehaviorFlags(info);
|
|
108
|
+
info.lazy = chain.some((ancestor) => ELEMENTS[ancestor]?.lazy === true);
|
|
109
|
+
|
|
110
|
+
for (const ancestor of chain.toReversed()) {
|
|
111
|
+
Object.assign(info.defaults, DEFAULT_PROPS[ancestor] ?? {});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return info;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const typeInfoFor = (name: string): TypeInfo => getOrInsert(typeInfoCache, name, buildTypeInfo);
|
|
118
|
+
|
|
119
|
+
export { typeInfoFor, type TypeInfo };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
|
+
import type * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
+
import type { SignalHandler } from "@gtkx/runtime";
|
|
4
|
+
import { getOrInsert } from "@gtkx/utils";
|
|
5
|
+
import type { ElementBehavior, Props } from "./registry.js";
|
|
6
|
+
|
|
7
|
+
type ContentKind = "label" | "buffer" | "tag" | "anchor";
|
|
8
|
+
type HandlerRecord = { signal: string; handler: SignalHandler; wrapped: SignalHandler; blockable: boolean };
|
|
9
|
+
type Dispatch = (fn: () => unknown) => unknown;
|
|
10
|
+
|
|
11
|
+
type SignalTarget = {
|
|
12
|
+
object: GObject.Object;
|
|
13
|
+
handlers: Map<string, HandlerRecord>;
|
|
14
|
+
typeName: string;
|
|
15
|
+
dispatch: Dispatch;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type PlacedChild = {
|
|
19
|
+
node: PlaceableNode;
|
|
20
|
+
object: GObject.Object;
|
|
21
|
+
adopted: GObject.Object | null;
|
|
22
|
+
slot: string;
|
|
23
|
+
behavior: ElementBehavior | null;
|
|
24
|
+
attached: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type ElementNode = SignalTarget & {
|
|
28
|
+
kind: typeof ELEMENT_KIND;
|
|
29
|
+
props: Props;
|
|
30
|
+
placements: Map<string, PlacedChild[]>;
|
|
31
|
+
contexts: Map<ElementBehavior, unknown>;
|
|
32
|
+
parent: ParentNode | null;
|
|
33
|
+
content: ContentChild[];
|
|
34
|
+
contentKind: ContentKind | null;
|
|
35
|
+
bufferView: Gtk.TextView | null;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type PropNode = {
|
|
39
|
+
kind: typeof PROP_KIND;
|
|
40
|
+
slot: string;
|
|
41
|
+
children: PlaceableNode[];
|
|
42
|
+
parent: ElementNode | null;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type LazyNode = {
|
|
46
|
+
kind: typeof LAZY_KIND;
|
|
47
|
+
typeName: string;
|
|
48
|
+
props: Props;
|
|
49
|
+
children: PlaceableNode[];
|
|
50
|
+
parent: ElementNode | null;
|
|
51
|
+
adopted: GObject.Object | null;
|
|
52
|
+
handlers: Map<string, HandlerRecord>;
|
|
53
|
+
dispatch: Dispatch;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type TextNode = {
|
|
57
|
+
kind: typeof TEXT_KIND;
|
|
58
|
+
text: string;
|
|
59
|
+
parent: ParentNode | null;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type PlaceableNode = ElementNode | LazyNode;
|
|
63
|
+
type ParentNode = ElementNode | PropNode | LazyNode;
|
|
64
|
+
type ContentChild = TextNode | ElementNode;
|
|
65
|
+
type Instance = ElementNode | PropNode | LazyNode;
|
|
66
|
+
type AnyNode = Instance | TextNode;
|
|
67
|
+
|
|
68
|
+
const ELEMENT_KIND = "element";
|
|
69
|
+
const PROP_KIND = "prop";
|
|
70
|
+
const TEXT_KIND = "text";
|
|
71
|
+
const LAZY_KIND = "lazy";
|
|
72
|
+
const DEFAULT_SLOT = "children";
|
|
73
|
+
|
|
74
|
+
const createPropNode = (slot: string): PropNode => ({
|
|
75
|
+
kind: PROP_KIND,
|
|
76
|
+
slot,
|
|
77
|
+
children: [],
|
|
78
|
+
parent: null,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const createLazyNode = (typeName: string, props: Props, dispatch: Dispatch): LazyNode => ({
|
|
82
|
+
kind: LAZY_KIND,
|
|
83
|
+
typeName,
|
|
84
|
+
props,
|
|
85
|
+
children: [],
|
|
86
|
+
parent: null,
|
|
87
|
+
adopted: null,
|
|
88
|
+
handlers: new Map(),
|
|
89
|
+
dispatch,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const createElementNode = (
|
|
93
|
+
typeName: string,
|
|
94
|
+
object: GObject.Object,
|
|
95
|
+
dispatch: Dispatch,
|
|
96
|
+
contentKind: ContentKind | null,
|
|
97
|
+
): ElementNode => ({
|
|
98
|
+
kind: ELEMENT_KIND,
|
|
99
|
+
typeName,
|
|
100
|
+
object,
|
|
101
|
+
props: {},
|
|
102
|
+
handlers: new Map(),
|
|
103
|
+
placements: new Map(),
|
|
104
|
+
contexts: new Map(),
|
|
105
|
+
parent: null,
|
|
106
|
+
content: [],
|
|
107
|
+
contentKind,
|
|
108
|
+
bufferView: null,
|
|
109
|
+
dispatch,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const createTextNode = (text: string): TextNode => ({ kind: TEXT_KIND, text, parent: null });
|
|
113
|
+
|
|
114
|
+
const nodeObject = (node: PlaceableNode): GObject.Object | null => {
|
|
115
|
+
if (node.kind === LAZY_KIND) {
|
|
116
|
+
const [child] = node.children;
|
|
117
|
+
|
|
118
|
+
return child === undefined ? null : nodeObject(child);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return node.object;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const lazyTarget = (node: LazyNode, adopted: GObject.Object): SignalTarget => ({
|
|
125
|
+
object: adopted,
|
|
126
|
+
handlers: node.handlers,
|
|
127
|
+
typeName: node.typeName,
|
|
128
|
+
dispatch: node.dispatch,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const getOrCreateContext = (node: ElementNode, behavior: ElementBehavior): unknown =>
|
|
132
|
+
getOrInsert(node.contexts, behavior, () => behavior.createContext?.(node.object));
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
ELEMENT_KIND,
|
|
136
|
+
PROP_KIND,
|
|
137
|
+
TEXT_KIND,
|
|
138
|
+
LAZY_KIND,
|
|
139
|
+
DEFAULT_SLOT,
|
|
140
|
+
createPropNode,
|
|
141
|
+
createLazyNode,
|
|
142
|
+
createElementNode,
|
|
143
|
+
createTextNode,
|
|
144
|
+
nodeObject,
|
|
145
|
+
lazyTarget,
|
|
146
|
+
getOrCreateContext,
|
|
147
|
+
type ContentKind,
|
|
148
|
+
type HandlerRecord,
|
|
149
|
+
type Dispatch,
|
|
150
|
+
type SignalTarget,
|
|
151
|
+
type PlacedChild,
|
|
152
|
+
type ElementNode,
|
|
153
|
+
type PropNode,
|
|
154
|
+
type LazyNode,
|
|
155
|
+
type TextNode,
|
|
156
|
+
type PlaceableNode,
|
|
157
|
+
type ParentNode,
|
|
158
|
+
type ContentChild,
|
|
159
|
+
type Instance,
|
|
160
|
+
type AnyNode,
|
|
161
|
+
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import * as GObject from "@gtkx/gi/gobject";
|
|
2
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
+
import { getOrInsert, indexBeforeOrEnd, remove } from "@gtkx/utils";
|
|
4
|
+
import type { DetachInfo, ElementBehavior, PlaceInfo } from "./registry.js";
|
|
5
|
+
import { applyAdoptedProps, markFlush } from "./apply-props.js";
|
|
6
|
+
import { typeInfoFor } from "./metadata.js";
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_SLOT,
|
|
9
|
+
ELEMENT_KIND,
|
|
10
|
+
type ElementNode,
|
|
11
|
+
getOrCreateContext,
|
|
12
|
+
LAZY_KIND,
|
|
13
|
+
lazyTarget,
|
|
14
|
+
nodeObject,
|
|
15
|
+
type PlaceableNode,
|
|
16
|
+
type PlacedChild,
|
|
17
|
+
} from "./node.js";
|
|
18
|
+
import { markTextDirty } from "./text.js";
|
|
19
|
+
|
|
20
|
+
type AttachContext = { parent: ElementNode; entry: PlacedChild; index: number; sibling: GObject.Object | null };
|
|
21
|
+
|
|
22
|
+
const createEntry = (slot: string, node: PlaceableNode): PlacedChild | null => {
|
|
23
|
+
const object = nodeObject(node);
|
|
24
|
+
|
|
25
|
+
if (object === null) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return { node, object, adopted: null, slot, behavior: null, attached: false };
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const siblingAt = (entries: PlacedChild[], index: number): GObject.Object | null =>
|
|
33
|
+
index > 0 ? (entries[index - 1]?.object ?? null) : null;
|
|
34
|
+
|
|
35
|
+
const placeInfo = (entry: PlacedChild, index: number, sibling: GObject.Object | null, context: unknown): PlaceInfo => ({
|
|
36
|
+
slot: entry.slot,
|
|
37
|
+
index,
|
|
38
|
+
sibling,
|
|
39
|
+
adopted: entry.adopted,
|
|
40
|
+
props: entry.node.props,
|
|
41
|
+
context,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const adoptedFrom = (parent: ElementNode, entry: PlacedChild, behavior: ElementBehavior, claim: unknown): void => {
|
|
45
|
+
if (behavior.resolve !== undefined) {
|
|
46
|
+
entry.adopted = behavior.resolve(parent.object, entry.object);
|
|
47
|
+
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
entry.adopted = claim instanceof GObject.Object ? claim : null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const applyLazyProps = (entry: PlacedChild): void => {
|
|
55
|
+
if (entry.node.kind !== LAZY_KIND || entry.adopted === null) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
applyAdoptedProps(lazyTarget(entry.node, entry.adopted), {}, entry.node.props);
|
|
60
|
+
entry.node.adopted = entry.adopted;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const wireBufferView = (node: PlaceableNode, parent: ElementNode): void => {
|
|
64
|
+
if (!(node.kind === ELEMENT_KIND && node.contentKind === "buffer" && parent.object instanceof Gtk.TextView)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
node.bufferView = parent.object;
|
|
69
|
+
markTextDirty(node);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const setObjectSlot = (parent: ElementNode, entry: PlacedChild): void => {
|
|
73
|
+
Reflect.set(parent.object, entry.slot, entry.object);
|
|
74
|
+
wireBufferView(entry.node, parent);
|
|
75
|
+
entry.behavior = null;
|
|
76
|
+
entry.attached = true;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const didAttach = (ctx: AttachContext, behavior: ElementBehavior): boolean => {
|
|
80
|
+
const attach = behavior.attach;
|
|
81
|
+
|
|
82
|
+
if (attach === undefined) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const context = getOrCreateContext(ctx.parent, behavior);
|
|
87
|
+
const claim = attach(ctx.parent.object, ctx.entry.object, placeInfo(ctx.entry, ctx.index, ctx.sibling, context));
|
|
88
|
+
|
|
89
|
+
if (claim === undefined) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
ctx.entry.behavior = behavior;
|
|
94
|
+
adoptedFrom(ctx.parent, ctx.entry, behavior, claim);
|
|
95
|
+
ctx.entry.attached = true;
|
|
96
|
+
applyLazyProps(ctx.entry);
|
|
97
|
+
|
|
98
|
+
return true;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const attachEntry = (parent: ElementNode, entry: PlacedChild, index: number, sibling: GObject.Object | null): void => {
|
|
102
|
+
const ctx: AttachContext = { parent, entry, index, sibling };
|
|
103
|
+
|
|
104
|
+
for (const behavior of typeInfoFor(parent.typeName).behaviors) {
|
|
105
|
+
if (didAttach(ctx, behavior)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (entry.slot !== DEFAULT_SLOT) {
|
|
111
|
+
setObjectSlot(parent, entry);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const detachInfo = (entry: PlacedChild, context: unknown): DetachInfo => ({
|
|
116
|
+
slot: entry.slot,
|
|
117
|
+
adopted: entry.adopted,
|
|
118
|
+
props: entry.node.props,
|
|
119
|
+
context,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const detachEntry = (parent: ElementNode, entry: PlacedChild): void => {
|
|
123
|
+
if (!entry.attached) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
entry.attached = false;
|
|
128
|
+
const behavior = entry.behavior;
|
|
129
|
+
|
|
130
|
+
if (behavior === null) {
|
|
131
|
+
if (entry.slot !== DEFAULT_SLOT) {
|
|
132
|
+
Reflect.set(parent.object, entry.slot, null);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
behavior.detach?.(parent.object, entry.object, detachInfo(entry, getOrCreateContext(parent, behavior)));
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const rebuild = (parent: ElementNode, entries: PlacedChild[]): void => {
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
detachEntry(parent, entry);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
for (const [index, entry] of entries.entries()) {
|
|
147
|
+
entry.behavior = null;
|
|
148
|
+
attachEntry(parent, entry, index, siblingAt(entries, index));
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const getPosition = (entries: PlacedChild[], before: PlaceableNode | null): number =>
|
|
153
|
+
indexBeforeOrEnd(entries, before, (entry, target) => entry.node === target);
|
|
154
|
+
|
|
155
|
+
const placeNew = (parent: ElementNode, entry: PlacedChild, entries: PlacedChild[], index: number): void => {
|
|
156
|
+
attachEntry(parent, entry, index, siblingAt(entries, index));
|
|
157
|
+
|
|
158
|
+
if (!entry.attached) {
|
|
159
|
+
remove(entries, entry);
|
|
160
|
+
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const isInsertedBeforeEnd = index < entries.length - 1;
|
|
165
|
+
const isCannotReorderInPlace = entry.behavior !== null && entry.behavior.reorder === undefined;
|
|
166
|
+
|
|
167
|
+
if (isInsertedBeforeEnd && isCannotReorderInPlace) {
|
|
168
|
+
rebuild(parent, entries);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const moveEntry = (parent: ElementNode, entry: PlacedChild, entries: PlacedChild[], index: number): void => {
|
|
173
|
+
const behavior = entry.behavior;
|
|
174
|
+
const reorder = behavior?.reorder;
|
|
175
|
+
|
|
176
|
+
if (behavior === null || reorder === undefined) {
|
|
177
|
+
rebuild(parent, entries);
|
|
178
|
+
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const context = getOrCreateContext(parent, behavior);
|
|
183
|
+
const claim = reorder(parent.object, entry.object, placeInfo(entry, index, siblingAt(entries, index), context));
|
|
184
|
+
adoptedFrom(parent, entry, behavior, claim);
|
|
185
|
+
applyLazyProps(entry);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const resolveEntry = (
|
|
189
|
+
entries: PlacedChild[],
|
|
190
|
+
existing: number,
|
|
191
|
+
slot: string,
|
|
192
|
+
node: PlaceableNode,
|
|
193
|
+
): PlacedChild | null => {
|
|
194
|
+
if (existing >= 0) {
|
|
195
|
+
return entries[existing] ?? null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return createEntry(slot, node);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const placeChild = (
|
|
202
|
+
parent: ElementNode,
|
|
203
|
+
slot: string,
|
|
204
|
+
node: PlaceableNode,
|
|
205
|
+
before: PlaceableNode | null,
|
|
206
|
+
): void => {
|
|
207
|
+
const entries = getOrInsert(parent.placements, slot, () => []);
|
|
208
|
+
const existing = entries.findIndex((entry) => entry.node === node);
|
|
209
|
+
const entry = resolveEntry(entries, existing, slot, node);
|
|
210
|
+
|
|
211
|
+
if (entry === null) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const isMove = existing !== -1;
|
|
216
|
+
|
|
217
|
+
if (isMove) {
|
|
218
|
+
entries.splice(existing, 1);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const index = getPosition(entries, before);
|
|
222
|
+
entries.splice(index, 0, entry);
|
|
223
|
+
|
|
224
|
+
if (isMove) {
|
|
225
|
+
moveEntry(parent, entry, entries, index);
|
|
226
|
+
} else {
|
|
227
|
+
placeNew(parent, entry, entries, index);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
markFlush(parent);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const unplaceChild = (parent: ElementNode, slot: string, node: PlaceableNode): void => {
|
|
234
|
+
const entries = parent.placements.get(slot);
|
|
235
|
+
|
|
236
|
+
if (entries === undefined) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const index = entries.findIndex((entry) => entry.node === node);
|
|
241
|
+
|
|
242
|
+
if (index === -1) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const [entry] = entries.splice(index, 1);
|
|
247
|
+
|
|
248
|
+
if (entry !== undefined) {
|
|
249
|
+
detachEntry(parent, entry);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
markFlush(parent);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
export { placeChild, unplaceChild };
|