@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,414 @@
|
|
|
1
|
+
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
|
+
import * as Gdk from "@gtkx/gi/gdk";
|
|
3
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
4
|
+
import { drain, indexBeforeOrEnd } from "@gtkx/utils";
|
|
5
|
+
import type { ContentChild, ContentKind, ElementNode, ParentNode, TextNode } from "./node.js";
|
|
6
|
+
import type { Props } from "./registry.js";
|
|
7
|
+
import { ELEMENT_KIND, TEXT_KIND } from "./node.js";
|
|
8
|
+
import { applyWrite } from "./signals.js";
|
|
9
|
+
|
|
10
|
+
type OffsetResult = { found: boolean; offset: number };
|
|
11
|
+
|
|
12
|
+
type BufferBuild = {
|
|
13
|
+
buffer: Gtk.TextBuffer;
|
|
14
|
+
view: Gtk.TextView | null;
|
|
15
|
+
marks: { node: ElementNode; offset: number }[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const dirtyHosts: Set<ElementNode> = new Set();
|
|
19
|
+
const tagTables: WeakMap<object, Gtk.TextTagTable> = new WeakMap();
|
|
20
|
+
const TEXT_CONTENT_KINDS: Set<string> = new Set(["label", "buffer", "tag"]);
|
|
21
|
+
const PAINTABLE_PROP = "paintable";
|
|
22
|
+
const TEXT_PROP = "text";
|
|
23
|
+
|
|
24
|
+
const CONTENT_MIX_RULES: { kind: ContentKind; prop: string; message: string }[] = [
|
|
25
|
+
{
|
|
26
|
+
kind: "label",
|
|
27
|
+
prop: "label",
|
|
28
|
+
message: "<GtkLabel> cannot mix a `label` prop with text children; use one or the other",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
kind: "buffer",
|
|
32
|
+
prop: "text",
|
|
33
|
+
message: "<GtkTextBuffer> cannot mix a `text` prop with content children; use one or the other",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
kind: "anchor",
|
|
37
|
+
prop: PAINTABLE_PROP,
|
|
38
|
+
message: "<GtkTextChildAnchor> cannot mix a `paintable` prop with a child widget; use one or the other",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const charLength = (text: string): number => text[Symbol.iterator]().toArray().length;
|
|
43
|
+
|
|
44
|
+
const bufferText = (buffer: Gtk.TextBuffer): string =>
|
|
45
|
+
buffer.getText(buffer.getStartIter(), buffer.getEndIter(), false);
|
|
46
|
+
|
|
47
|
+
const currentText = (object: GObject.Object): string | null => {
|
|
48
|
+
if (object instanceof Gtk.TextBuffer) {
|
|
49
|
+
return bufferText(object);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (object instanceof Gtk.Editable || object instanceof Gtk.EntryBuffer) {
|
|
53
|
+
return object.getText();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return null;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const hasSameText = (object: GObject.Object, prop: string, value: unknown): boolean =>
|
|
60
|
+
prop === TEXT_PROP && typeof value === "string" && currentText(object) === value;
|
|
61
|
+
|
|
62
|
+
const contentTextLength = (node: ContentChild): number => {
|
|
63
|
+
if (node.kind === TEXT_KIND) {
|
|
64
|
+
return charLength(node.text);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (node.contentKind === "tag") {
|
|
68
|
+
return node.content.reduce((sum, child) => sum + contentTextLength(child), 0);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return node.contentKind === "anchor" ? 1 : 0;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const isTagElement = (node: ContentChild): node is ElementNode =>
|
|
75
|
+
node.kind === ELEMENT_KIND && node.contentKind === "tag";
|
|
76
|
+
|
|
77
|
+
const stepOffset = (node: ContentChild, target: TextNode, offset: number): OffsetResult => {
|
|
78
|
+
if (node === target) {
|
|
79
|
+
return { found: true, offset };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (isTagElement(node)) {
|
|
83
|
+
return getOffset(node.content, target, offset);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return { found: false, offset: offset + contentTextLength(node) };
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const getOffset = (nodes: ContentChild[], target: TextNode, start: number): OffsetResult => {
|
|
90
|
+
let offset = start;
|
|
91
|
+
|
|
92
|
+
for (const node of nodes) {
|
|
93
|
+
const step = stepOffset(node, target, offset);
|
|
94
|
+
|
|
95
|
+
if (step.found) {
|
|
96
|
+
return step;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
offset = step.offset;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return { found: false, offset };
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const enclosingTagNodes = (node: TextNode): ElementNode[] => {
|
|
106
|
+
const nodes: ElementNode[] = [];
|
|
107
|
+
let current: ParentNode | null = node.parent;
|
|
108
|
+
|
|
109
|
+
while (current !== null && current.kind === ELEMENT_KIND) {
|
|
110
|
+
if (current.contentKind === "tag") {
|
|
111
|
+
nodes.push(current);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
current = current.parent;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return nodes;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const textRestrictionError = (text: string): Error =>
|
|
121
|
+
new Error(
|
|
122
|
+
"Text strings must be rendered within a <GtkLabel> or <GtkTextBuffer> element; " +
|
|
123
|
+
`received ${JSON.stringify(text)}`,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const canAcceptText = (host: ElementNode): boolean =>
|
|
127
|
+
host.contentKind !== null && TEXT_CONTENT_KINDS.has(host.contentKind);
|
|
128
|
+
|
|
129
|
+
const isRootHost = (node: ElementNode): boolean => node.contentKind === "label" || node.contentKind === "buffer";
|
|
130
|
+
|
|
131
|
+
const mapElementParent = <T>(parent: ParentNode | null, map: (element: ElementNode) => T): T | null =>
|
|
132
|
+
parent !== null && parent.kind === ELEMENT_KIND ? map(parent) : null;
|
|
133
|
+
|
|
134
|
+
const parentElement = (node: ElementNode): ElementNode | null => mapElementParent(node.parent, (parent) => parent);
|
|
135
|
+
|
|
136
|
+
const getRootHost = (node: ElementNode): ElementNode | null => {
|
|
137
|
+
let current: ElementNode | null = node;
|
|
138
|
+
|
|
139
|
+
while (current !== null) {
|
|
140
|
+
if (isRootHost(current)) {
|
|
141
|
+
return current;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
current = parentElement(current);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return null;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const markTextDirty = (host: ElementNode): void => {
|
|
151
|
+
const root = getRootHost(host);
|
|
152
|
+
|
|
153
|
+
if (root !== null) {
|
|
154
|
+
dirtyHosts.add(root);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const enclosingHost = (node: TextNode): ElementNode | null => mapElementParent(node.parent, getRootHost);
|
|
159
|
+
|
|
160
|
+
const addContent = (host: ElementNode, child: ContentChild, before: ContentChild | null): void => {
|
|
161
|
+
const content = host.content;
|
|
162
|
+
const existing = content.indexOf(child);
|
|
163
|
+
|
|
164
|
+
if (existing !== -1) {
|
|
165
|
+
content.splice(existing, 1);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
content.splice(
|
|
169
|
+
indexBeforeOrEnd(content, before, (item, target) => item === target),
|
|
170
|
+
0,
|
|
171
|
+
child,
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
child.parent = host;
|
|
175
|
+
markTextDirty(host);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const removeContent = (host: ElementNode, child: ContentChild): void => {
|
|
179
|
+
const index = host.content.indexOf(child);
|
|
180
|
+
|
|
181
|
+
if (index !== -1) {
|
|
182
|
+
host.content.splice(index, 1);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
markTextDirty(host);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const validateContentMix = (node: ElementNode, props: Props): void => {
|
|
189
|
+
if (node.content.length === 0) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const violated = CONTENT_MIX_RULES.find(
|
|
194
|
+
(rule) => rule.kind === node.contentKind && props[rule.prop] !== undefined,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
if (violated !== undefined) {
|
|
198
|
+
throw new Error(violated.message);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const detachTag = (tag: Gtk.TextTag, table: Gtk.TextTagTable, name: string | null): void => {
|
|
203
|
+
const previous = tagTables.get(tag);
|
|
204
|
+
|
|
205
|
+
if (previous !== undefined && previous !== table) {
|
|
206
|
+
previous.remove(tag);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (name === null) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const existing = table.lookup(name);
|
|
214
|
+
|
|
215
|
+
if (existing !== null && existing !== tag) {
|
|
216
|
+
table.remove(existing);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const ensureTag = (table: Gtk.TextTagTable, node: ElementNode): void => {
|
|
221
|
+
const tag = node.object;
|
|
222
|
+
|
|
223
|
+
if (!(tag instanceof Gtk.TextTag) || tagTables.get(tag) === table) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const name = typeof node.props.name === "string" ? node.props.name : null;
|
|
228
|
+
detachTag(tag, table, name);
|
|
229
|
+
|
|
230
|
+
if (name === null || table.lookup(name) !== tag) {
|
|
231
|
+
table.add(tag);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
tagTables.set(tag, table);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const insertTag = (build: BufferBuild, node: ElementNode): void => {
|
|
238
|
+
const start = build.buffer.getCharCount();
|
|
239
|
+
insertContent(build, node.content);
|
|
240
|
+
const tag = node.object;
|
|
241
|
+
|
|
242
|
+
if (tag instanceof Gtk.TextTag) {
|
|
243
|
+
ensureTag(build.buffer.getTagTable(), node);
|
|
244
|
+
build.buffer.applyTag(tag, build.buffer.getIterAtOffset(start), build.buffer.getEndIter());
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const contentPaintable = (node: ElementNode): Gdk.Paintable | null => {
|
|
249
|
+
const value = node.props[PAINTABLE_PROP];
|
|
250
|
+
|
|
251
|
+
return value instanceof Gdk.Paintable ? value : null;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const isContentPaintableProp = (node: ElementNode, name: string): boolean =>
|
|
255
|
+
name === PAINTABLE_PROP && node.contentKind === "anchor";
|
|
256
|
+
|
|
257
|
+
const insertAnchor = (build: BufferBuild, node: ElementNode): void => {
|
|
258
|
+
const paintable = contentPaintable(node);
|
|
259
|
+
|
|
260
|
+
if (paintable !== null) {
|
|
261
|
+
build.buffer.insertPaintable(build.buffer.getEndIter(), paintable);
|
|
262
|
+
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const anchor = node.object;
|
|
267
|
+
|
|
268
|
+
if (!(anchor instanceof Gtk.TextChildAnchor)) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
build.buffer.insertChildAnchor(build.buffer.getEndIter(), anchor);
|
|
273
|
+
const child = node.content[0];
|
|
274
|
+
|
|
275
|
+
if (build.view !== null && child?.kind === ELEMENT_KIND && child.object instanceof Gtk.Widget) {
|
|
276
|
+
build.view.addChildAtAnchor(child.object, anchor);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const insertElement = (build: BufferBuild, node: ElementNode): void => {
|
|
281
|
+
if (node.contentKind === "tag") {
|
|
282
|
+
insertTag(build, node);
|
|
283
|
+
} else if (node.contentKind === "anchor") {
|
|
284
|
+
insertAnchor(build, node);
|
|
285
|
+
} else {
|
|
286
|
+
build.marks.push({ node, offset: build.buffer.getCharCount() });
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const insertContent = (build: BufferBuild, nodes: ContentChild[]): void => {
|
|
291
|
+
for (const child of nodes) {
|
|
292
|
+
if (child.kind === TEXT_KIND) {
|
|
293
|
+
build.buffer.insert(build.buffer.getEndIter(), child.text, -1);
|
|
294
|
+
} else {
|
|
295
|
+
insertElement(build, child);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const placeMark = (buffer: Gtk.TextBuffer, node: ElementNode, offset: number): void => {
|
|
301
|
+
const mark = node.object;
|
|
302
|
+
|
|
303
|
+
if (!(mark instanceof Gtk.TextMark)) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const iter = buffer.getIterAtOffset(offset);
|
|
308
|
+
|
|
309
|
+
if (mark.getBuffer() === null) {
|
|
310
|
+
buffer.addMark(mark, iter);
|
|
311
|
+
} else {
|
|
312
|
+
buffer.moveMark(mark, iter);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const rebuildBuffer = (node: ElementNode): void => {
|
|
317
|
+
const buffer = node.object;
|
|
318
|
+
|
|
319
|
+
if (node.props.text !== undefined || !(buffer instanceof Gtk.TextBuffer)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
applyWrite(() => {
|
|
324
|
+
buffer.setText("", -1);
|
|
325
|
+
const build: BufferBuild = { buffer, view: node.bufferView, marks: [] };
|
|
326
|
+
insertContent(build, node.content);
|
|
327
|
+
|
|
328
|
+
for (const mark of build.marks) {
|
|
329
|
+
placeMark(buffer, mark.node, mark.offset);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
const rebuildLabel = (node: ElementNode): void => {
|
|
335
|
+
if (node.props.label !== undefined) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const label = node.object;
|
|
340
|
+
|
|
341
|
+
if (!(label instanceof Gtk.Label)) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
label.setLabel(node.content.map((child) => (child.kind === TEXT_KIND ? child.text : "")).join(""));
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const flushTextHosts = (): void => {
|
|
349
|
+
drain(dirtyHosts, (host) => {
|
|
350
|
+
if (host.contentKind === "label") {
|
|
351
|
+
rebuildLabel(host);
|
|
352
|
+
} else if (host.contentKind === "buffer") {
|
|
353
|
+
rebuildBuffer(host);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const applyEnclosingTags = (
|
|
359
|
+
buffer: Gtk.TextBuffer,
|
|
360
|
+
node: TextNode,
|
|
361
|
+
startIter: Gtk.TextIter,
|
|
362
|
+
endIter: Gtk.TextIter,
|
|
363
|
+
): void => {
|
|
364
|
+
for (const tagNode of enclosingTagNodes(node)) {
|
|
365
|
+
ensureTag(buffer.getTagTable(), tagNode);
|
|
366
|
+
|
|
367
|
+
if (tagNode.object instanceof Gtk.TextTag) {
|
|
368
|
+
buffer.applyTag(tagNode.object, startIter, endIter);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const didUpdateTextSurgically = (host: ElementNode, node: TextNode, oldText: string, newText: string): boolean => {
|
|
374
|
+
const buffer = host.object;
|
|
375
|
+
|
|
376
|
+
if (host.contentKind !== "buffer" || !(buffer instanceof Gtk.TextBuffer)) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const located = getOffset(host.content, node, 0);
|
|
381
|
+
|
|
382
|
+
if (!located.found) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const start = located.offset;
|
|
387
|
+
|
|
388
|
+
applyWrite(() => {
|
|
389
|
+
buffer.delete(buffer.getIterAtOffset(start), buffer.getIterAtOffset(start + charLength(oldText)));
|
|
390
|
+
buffer.insert(buffer.getIterAtOffset(start), newText, -1);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
const startIter = buffer.getIterAtOffset(start);
|
|
394
|
+
const endIter = buffer.getIterAtOffset(start + charLength(newText));
|
|
395
|
+
applyEnclosingTags(buffer, node, startIter, endIter);
|
|
396
|
+
|
|
397
|
+
return true;
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
export {
|
|
401
|
+
TEXT_PROP,
|
|
402
|
+
textRestrictionError,
|
|
403
|
+
bufferText,
|
|
404
|
+
hasSameText,
|
|
405
|
+
canAcceptText,
|
|
406
|
+
isContentPaintableProp,
|
|
407
|
+
markTextDirty,
|
|
408
|
+
enclosingHost,
|
|
409
|
+
addContent,
|
|
410
|
+
removeContent,
|
|
411
|
+
validateContentMix,
|
|
412
|
+
flushTextHosts,
|
|
413
|
+
didUpdateTextSurgically,
|
|
414
|
+
};
|
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
const metadataStore: WeakMap<object, Map<string, unknown>> = new WeakMap();
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const setAccessibleMetadata = (widget: object, name: string, value: unknown): void => {
|
|
4
|
+
let entries = metadataStore.get(widget);
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let entry = accessibleMetadata.get(accessible);
|
|
9
|
-
if (!entry) {
|
|
10
|
-
entry = new Map();
|
|
11
|
-
accessibleMetadata.set(accessible, entry);
|
|
6
|
+
if (entries === undefined) {
|
|
7
|
+
entries = new Map();
|
|
8
|
+
metadataStore.set(widget, entries);
|
|
12
9
|
}
|
|
13
|
-
|
|
10
|
+
|
|
11
|
+
entries.set(name, value);
|
|
14
12
|
};
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (entry) entry.delete(propName);
|
|
14
|
+
const deleteAccessibleMetadata = (widget: object, name: string): void => {
|
|
15
|
+
metadataStore.get(widget)?.delete(name);
|
|
19
16
|
};
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Returns the last value applied for an accessible prop on a widget, or null when none was applied.
|
|
20
|
+
*
|
|
21
|
+
* @param widget The widget to read from.
|
|
22
|
+
* @param name The accessible prop name.
|
|
23
|
+
* @returns The last applied value, or null.
|
|
24
|
+
*/
|
|
25
|
+
const getAccessibleMetadata = (widget: object, name: string): unknown => {
|
|
26
|
+
const value = metadataStore.get(widget)?.get(name);
|
|
27
|
+
|
|
28
|
+
return value === undefined ? null : value;
|
|
26
29
|
};
|
|
30
|
+
|
|
31
|
+
export { setAccessibleMetadata, deleteAccessibleMetadata, getAccessibleMetadata };
|