@rvx/ui 0.1.6

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.
Files changed (159) hide show
  1. package/LICENSE +21 -0
  2. package/dist/common/events.d.ts +72 -0
  3. package/dist/common/events.js +58 -0
  4. package/dist/common/events.js.map +1 -0
  5. package/dist/common/parsers.d.ts +88 -0
  6. package/dist/common/parsers.js +62 -0
  7. package/dist/common/parsers.js.map +1 -0
  8. package/dist/common/theme-test.d.ts +7 -0
  9. package/dist/common/theme-test.js +14 -0
  10. package/dist/common/theme-test.js.map +1 -0
  11. package/dist/common/theme.d.ts +144 -0
  12. package/dist/common/theme.js +2 -0
  13. package/dist/common/theme.js.map +1 -0
  14. package/dist/common/trim.d.ts +12 -0
  15. package/dist/common/trim.js +16 -0
  16. package/dist/common/trim.js.map +1 -0
  17. package/dist/common/types.d.ts +13 -0
  18. package/dist/common/types.js +10 -0
  19. package/dist/common/types.js.map +1 -0
  20. package/dist/common/writing-mode.d.ts +82 -0
  21. package/dist/common/writing-mode.js +61 -0
  22. package/dist/common/writing-mode.js.map +1 -0
  23. package/dist/components/button.d.ts +42 -0
  24. package/dist/components/button.js +26 -0
  25. package/dist/components/button.js.map +1 -0
  26. package/dist/components/checkbox.d.ts +9 -0
  27. package/dist/components/checkbox.js +32 -0
  28. package/dist/components/checkbox.js.map +1 -0
  29. package/dist/components/collapse-test.d.ts +8 -0
  30. package/dist/components/collapse-test.js +15 -0
  31. package/dist/components/collapse-test.js.map +1 -0
  32. package/dist/components/collapse.d.ts +13 -0
  33. package/dist/components/collapse.js +44 -0
  34. package/dist/components/collapse.js.map +1 -0
  35. package/dist/components/column.d.ts +12 -0
  36. package/dist/components/column.js +12 -0
  37. package/dist/components/column.js.map +1 -0
  38. package/dist/components/control-group.d.ts +7 -0
  39. package/dist/components/control-group.js +11 -0
  40. package/dist/components/control-group.js.map +1 -0
  41. package/dist/components/dialog.d.ts +33 -0
  42. package/dist/components/dialog.js +67 -0
  43. package/dist/components/dialog.js.map +1 -0
  44. package/dist/components/dropdown-input.d.ts +27 -0
  45. package/dist/components/dropdown-input.js +31 -0
  46. package/dist/components/dropdown-input.js.map +1 -0
  47. package/dist/components/dropdown.d.ts +123 -0
  48. package/dist/components/dropdown.js +176 -0
  49. package/dist/components/dropdown.js.map +1 -0
  50. package/dist/components/flex-space.d.ts +4 -0
  51. package/dist/components/flex-space.js +10 -0
  52. package/dist/components/flex-space.js.map +1 -0
  53. package/dist/components/heading.d.ts +9 -0
  54. package/dist/components/heading.js +14 -0
  55. package/dist/components/heading.js.map +1 -0
  56. package/dist/components/label.d.ts +14 -0
  57. package/dist/components/label.js +15 -0
  58. package/dist/components/label.js.map +1 -0
  59. package/dist/components/layer.d.ts +81 -0
  60. package/dist/components/layer.js +164 -0
  61. package/dist/components/layer.js.map +1 -0
  62. package/dist/components/link.d.ts +57 -0
  63. package/dist/components/link.js +26 -0
  64. package/dist/components/link.js.map +1 -0
  65. package/dist/components/page.d.ts +9 -0
  66. package/dist/components/page.js +17 -0
  67. package/dist/components/page.js.map +1 -0
  68. package/dist/components/popout.d.ts +134 -0
  69. package/dist/components/popout.js +259 -0
  70. package/dist/components/popout.js.map +1 -0
  71. package/dist/components/popover.d.ts +139 -0
  72. package/dist/components/popover.js +101 -0
  73. package/dist/components/popover.js.map +1 -0
  74. package/dist/components/radio-buttons.d.ts +17 -0
  75. package/dist/components/radio-buttons.js +26 -0
  76. package/dist/components/radio-buttons.js.map +1 -0
  77. package/dist/components/row.d.ts +10 -0
  78. package/dist/components/row.js +23 -0
  79. package/dist/components/row.js.map +1 -0
  80. package/dist/components/scroll-view.d.ts +6 -0
  81. package/dist/components/scroll-view.js +72 -0
  82. package/dist/components/scroll-view.js.map +1 -0
  83. package/dist/components/text-input.d.ts +53 -0
  84. package/dist/components/text-input.js +35 -0
  85. package/dist/components/text-input.js.map +1 -0
  86. package/dist/components/text.d.ts +7 -0
  87. package/dist/components/text.js +11 -0
  88. package/dist/components/text.js.map +1 -0
  89. package/dist/components/validation.d.ts +109 -0
  90. package/dist/components/validation.js +151 -0
  91. package/dist/components/validation.js.map +1 -0
  92. package/dist/components/value.d.ts +7 -0
  93. package/dist/components/value.js +11 -0
  94. package/dist/components/value.js.map +1 -0
  95. package/dist/index.d.ts +29 -0
  96. package/dist/index.js +30 -0
  97. package/dist/index.js.map +1 -0
  98. package/dist/test.d.ts +2 -0
  99. package/dist/test.js +3 -0
  100. package/dist/test.js.map +1 -0
  101. package/dist/theme.module.css +679 -0
  102. package/dist/theme.module.css.map +1 -0
  103. package/package.json +29 -0
  104. package/src/common/events.tsx +130 -0
  105. package/src/common/parsers.tsx +167 -0
  106. package/src/common/theme-test.tsx +20 -0
  107. package/src/common/theme.tsx +165 -0
  108. package/src/common/trim.tsx +30 -0
  109. package/src/common/types.tsx +23 -0
  110. package/src/common/writing-mode.tsx +150 -0
  111. package/src/components/button.tsx +94 -0
  112. package/src/components/checkbox.tsx +64 -0
  113. package/src/components/collapse-test.tsx +23 -0
  114. package/src/components/collapse.tsx +75 -0
  115. package/src/components/column.tsx +28 -0
  116. package/src/components/control-group.tsx +22 -0
  117. package/src/components/dialog.tsx +137 -0
  118. package/src/components/dropdown-input.tsx +82 -0
  119. package/src/components/dropdown.tsx +352 -0
  120. package/src/components/flex-space.tsx +15 -0
  121. package/src/components/heading.tsx +23 -0
  122. package/src/components/label.tsx +37 -0
  123. package/src/components/layer.tsx +299 -0
  124. package/src/components/link.tsx +118 -0
  125. package/src/components/page.tsx +36 -0
  126. package/src/components/popout.tsx +461 -0
  127. package/src/components/popover.tsx +292 -0
  128. package/src/components/radio-buttons.tsx +81 -0
  129. package/src/components/row.tsx +37 -0
  130. package/src/components/scroll-view.tsx +97 -0
  131. package/src/components/text-input.tsx +117 -0
  132. package/src/components/text.tsx +22 -0
  133. package/src/components/validation.tsx +272 -0
  134. package/src/components/value.tsx +22 -0
  135. package/src/index.tsx +29 -0
  136. package/src/test.tsx +2 -0
  137. package/src/theme/base.scss +69 -0
  138. package/src/theme/common.scss +51 -0
  139. package/src/theme/components/button.scss +116 -0
  140. package/src/theme/components/checkbox.scss +25 -0
  141. package/src/theme/components/collapse.scss +64 -0
  142. package/src/theme/components/column.scss +28 -0
  143. package/src/theme/components/control-group.scss +14 -0
  144. package/src/theme/components/dialog.scss +44 -0
  145. package/src/theme/components/dropdown.scss +50 -0
  146. package/src/theme/components/flex-space.scss +6 -0
  147. package/src/theme/components/heading.scss +39 -0
  148. package/src/theme/components/label.scss +24 -0
  149. package/src/theme/components/link.scss +25 -0
  150. package/src/theme/components/page.scss +22 -0
  151. package/src/theme/components/popover.scss +58 -0
  152. package/src/theme/components/radio-buttons.scss +31 -0
  153. package/src/theme/components/row.scss +17 -0
  154. package/src/theme/components/scroll-view.scss +51 -0
  155. package/src/theme/components/text-input.scss +45 -0
  156. package/src/theme/components/text.scss +12 -0
  157. package/src/theme/components/validation.scss +15 -0
  158. package/src/theme/components/value.scss +4 -0
  159. package/src/theme/theme.scss +22 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/components/page.tsx"],"names":[],"mappings":";AAAA,OAAO,EAA0B,OAAO,EAAc,MAAM,KAAK,CAAC;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,UAAU,IAAI,CAAC,KAOpB;IACA,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,eACN,IAAI,EAAE,KAAK,CAAC,IAAI,EAChB,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,KAAK,EAAE;YACN,KAAK,CAAC,KAAK;YACX,KAAK,EAAE,IAAI;SACX,EACD,KAAK,EAAE;YACN,KAAK,CAAC,KAAK;YACX;gBACC,oBAAoB,EAAE,KAAK,CAAC,UAAU;aACtC;SACD,aAED,cAAK,KAAK,EAAE,KAAK,EAAE,mBAAmB,GAAI,EAC1C,cAAK,KAAK,EAAE,KAAK,EAAE,gBAAgB,YAClC,KAAC,MAAM,IAAC,KAAK,EAAE,KAAK,EAAE,YAAY,YAChC,KAAK,CAAC,QAAQ,GACP,GACJ,IACD,CAAC;AACR,CAAC"}
@@ -0,0 +1,134 @@
1
+ import { Event as RvxEvent, Expression, View } from "rvx";
2
+ import { Direction } from "../common/writing-mode.js";
3
+ /**
4
+ * Defines the direction in which the popout is placed in relation to it's anchor.
5
+ *
6
+ * + `"block"` coresponds to the block flow direction.
7
+ * + `"inline"` coresponds to the inline flow direction.
8
+ * + If `"-start"` or `"-end"` is present, that direction is used unless there isn't enough space for the current content and the opposite side has more available space.
9
+ */
10
+ export type PopoutPlacement = "block" | "inline" | EffectivePopoutPlacement;
11
+ export type EffectivePopoutPlacement = "block-start" | "block-end" | "inline-start" | "inline-end";
12
+ /**
13
+ * Defines which side of the anchor and content are aligned orthogonally to the placement axis.
14
+ *
15
+ * + `"center"` aligns the popout center to the anchor center.
16
+ * + `"start"` aligns the popout start to the anchor start.
17
+ * + `"end"` aligns the popout end to the anchor end.
18
+ */
19
+ export type PopoutAlignment = "center" | "start" | "end";
20
+ export interface PopoutPlacementArgs {
21
+ /**
22
+ * When set during the `onPlacement` event, this defines the gap between the anchor and the content in `px`.
23
+ *
24
+ * @default 0
25
+ */
26
+ gap: number;
27
+ }
28
+ export interface PopoutPlacementInfo {
29
+ /**
30
+ * The rect of the anchor at the time of placement.
31
+ */
32
+ anchorRect: DOMRect;
33
+ /**
34
+ * The content root element.
35
+ */
36
+ content: HTMLElement;
37
+ /**
38
+ * The effective placement.
39
+ */
40
+ placement: EffectivePopoutPlacement;
41
+ /**
42
+ * The effective placement direction.
43
+ */
44
+ placementDir: Direction;
45
+ /**
46
+ * The block start or inline start direction orthogonal to the effective placement axis.
47
+ */
48
+ alignStart: Direction;
49
+ }
50
+ export interface PopoutContent {
51
+ (props: {
52
+ /**
53
+ * The popout itself.
54
+ */
55
+ popout: Popout;
56
+ /**
57
+ * Called after the popout content is attached to the document, but before calculating the placement.
58
+ */
59
+ onPlacement: RvxEvent<[event: PopoutPlacementArgs]>;
60
+ /**
61
+ * Set the size reference element.
62
+ *
63
+ * If never called or if the last target was undefined, the popout root is used as reference.
64
+ */
65
+ setSizeReference: (target: Element | undefined) => void;
66
+ /**
67
+ * Reactively get information on the effective placement.
68
+ */
69
+ placement: () => PopoutPlacementInfo | undefined;
70
+ }): unknown;
71
+ }
72
+ export interface PopoutOptions {
73
+ /**
74
+ * Defines the direction in which the popout is placed in relation to it's anchor.
75
+ *
76
+ * See {@link PopoutPlacement}
77
+ */
78
+ placement: Expression<PopoutPlacement>;
79
+ /**
80
+ * Defines which side of the anchor and content are aligned orthogonally to the placement axis.
81
+ *
82
+ * See {@link PopoutAlignment}
83
+ */
84
+ alignment: Expression<PopoutAlignment>;
85
+ /**
86
+ * The content component to render while the popout is visible.
87
+ */
88
+ content: PopoutContent;
89
+ /**
90
+ * An array of event names that cause the popout to hide automatically when dispatched outside of the current layer stack or the latest anchor.
91
+ *
92
+ * @default ["resize", "scroll", "mousedown", "touchstart", "focusin", "rvx-ui:passive-action"]
93
+ */
94
+ foreignEvents?: string[];
95
+ }
96
+ /**
97
+ * Utility to create automatically placed floating content like popovers or dropdowns.
98
+ */
99
+ export declare class Popout {
100
+ #private;
101
+ /**
102
+ * Create a new popout.
103
+ *
104
+ * The popout hides automatically when the current context is disposed.
105
+ */
106
+ constructor(options: PopoutOptions);
107
+ /**
108
+ * Reactively check if the popout is currently visible.
109
+ */
110
+ get visible(): boolean;
111
+ /**
112
+ * Show the popout or recalculate placement if already visible.
113
+ *
114
+ * @param anchor The anchor view to use. This doesn't affect the view in any way.
115
+ * @param pointerEvent An optional event to determine which anchor rect to use if the anchor has multiple client rects like wrapping texts or just multiple distinct root nodes.
116
+ */
117
+ show(anchor: View, pointerEvent?: Event): void;
118
+ /**
119
+ * Recalculate placement using the most recent anchor and pointer event if currently visible.
120
+ *
121
+ * Placement is recalculated automatically when the content is resized.
122
+ *
123
+ * Resizing or moving anchors don't trigger recalculation as it is expected, that content behind the popout doesn't change significantly while the popout is open.
124
+ */
125
+ update(): void;
126
+ /**
127
+ * The same as {@link show}, but the popout is hidden instead if currently visible.
128
+ */
129
+ toggle(anchor: View, pointerEvent?: Event): void;
130
+ /**
131
+ * Hide the popout if currently visible.
132
+ */
133
+ hide(): void;
134
+ }
@@ -0,0 +1,259 @@
1
+ import { jsx as _jsx } from "rvx/jsx-runtime";
2
+ import { captureSelf, Emitter, extract, get, getContext, render, runInContext, sig, teardown, untrack, viewNodes } from "rvx";
3
+ import { PASSIVE_ACTION_EVENT } from "../common/events.js";
4
+ import { axisEquals, DOWN, flip, getBlockStart, getInlineStart, getSize, getWindowSize, getWindowSpaceAround, INSET, LEFT, RIGHT, UP } from "../common/writing-mode.js";
5
+ import { LAYER, Layer } from "./layer.js";
6
+ export class Popout {
7
+ #context;
8
+ #placement;
9
+ #alignment;
10
+ #content;
11
+ #foreignEvents;
12
+ #instance;
13
+ #instanceArgs;
14
+ #visible = sig(false);
15
+ #onPlacement = new Emitter();
16
+ #placementState = sig(undefined);
17
+ constructor(options) {
18
+ this.#context = getContext();
19
+ this.#placement = options.placement;
20
+ this.#alignment = options.alignment;
21
+ this.#content = options.content;
22
+ this.#foreignEvents = options.foreignEvents ?? ["resize", "scroll", "mousedown", "touchstart", "focusin", PASSIVE_ACTION_EVENT];
23
+ teardown(() => {
24
+ this.hide();
25
+ });
26
+ }
27
+ get visible() {
28
+ return this.#visible.value;
29
+ }
30
+ show(anchor, pointerEvent) {
31
+ this.#instanceArgs = undefined;
32
+ this.#placementState.value = undefined;
33
+ let pointer;
34
+ if (globalThis.MouseEvent && pointerEvent instanceof MouseEvent) {
35
+ pointer = pointerEvent;
36
+ }
37
+ else if (globalThis.TouchEvent && pointerEvent instanceof TouchEvent) {
38
+ pointer = pointerEvent.touches.item(0) ?? undefined;
39
+ }
40
+ let anchorRect;
41
+ let writingMode;
42
+ let scriptDir;
43
+ if (pointer !== undefined) {
44
+ const { clientX, clientY } = pointer;
45
+ nodes: for (const node of viewNodes(anchor)) {
46
+ if (node instanceof Element) {
47
+ for (const rect of node.getClientRects()) {
48
+ if (clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom) {
49
+ const styles = getComputedStyle(node);
50
+ writingMode ??= styles.writingMode || "horizontal-tb";
51
+ scriptDir ??= styles.direction || "ltr";
52
+ anchorRect = rect;
53
+ break nodes;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ if (anchorRect === undefined) {
60
+ for (const node of viewNodes(anchor)) {
61
+ if (node instanceof Element) {
62
+ anchorRect = node.getBoundingClientRect();
63
+ const styles = getComputedStyle(node);
64
+ writingMode ??= styles.writingMode || "horizontal-tb";
65
+ scriptDir ??= styles.direction || "ltr";
66
+ break;
67
+ }
68
+ }
69
+ if (anchorRect === undefined) {
70
+ throw new Error("anchor must contain at least one element.");
71
+ }
72
+ }
73
+ let instance = this.#instance;
74
+ if (instance === undefined) {
75
+ runInContext(this.#context, () => {
76
+ captureSelf(dispose => {
77
+ instance = this.#instance = {
78
+ dispose,
79
+ content: undefined,
80
+ view: undefined,
81
+ observer: undefined,
82
+ sizeReference: undefined,
83
+ };
84
+ instance.view = render(_jsx(Layer, { children: () => {
85
+ const layer = extract(LAYER);
86
+ const onForeignEvent = (event) => {
87
+ if (event.target instanceof Node) {
88
+ if (layer.stackContains(event.target)) {
89
+ return;
90
+ }
91
+ const args = this.#instanceArgs;
92
+ if (args !== undefined) {
93
+ for (const node of viewNodes(args.anchor)) {
94
+ if (node === event.target || node.contains(event.target)) {
95
+ return;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ this.hide();
101
+ };
102
+ this.#foreignEvents.forEach(t => window.addEventListener(t, onForeignEvent, { passive: true, capture: true }));
103
+ teardown(() => {
104
+ this.#foreignEvents.forEach(t => window.removeEventListener(t, onForeignEvent, { capture: true }));
105
+ });
106
+ instance.content = _jsx("div", { style: {
107
+ "position": "fixed",
108
+ "writing-mode": writingMode,
109
+ }, dir: scriptDir, children: this.#content({
110
+ popout: this,
111
+ onPlacement: this.#onPlacement.event,
112
+ placement: () => this.#placementState.value,
113
+ setSizeReference: target => {
114
+ instance.sizeReference = target;
115
+ },
116
+ }) });
117
+ return instance.content;
118
+ } }));
119
+ document.body.appendChild(instance.view.take());
120
+ instance.observer = new ResizeObserver(entries => {
121
+ const args = this.#instanceArgs;
122
+ const size = entries[entries.length - 1]?.borderBoxSize[0];
123
+ if (args !== undefined && size !== undefined && (size.blockSize !== args.contentBlockSize || size.inlineSize !== args.contentInlineSize)) {
124
+ this.show(args.anchor, args.pointerEvent);
125
+ }
126
+ });
127
+ instance.observer.observe(instance.content, { box: "border-box" });
128
+ });
129
+ });
130
+ }
131
+ const placementArgs = { gap: 0 };
132
+ this.#onPlacement.emit(placementArgs);
133
+ const { gap } = placementArgs;
134
+ const { content, sizeReference } = instance;
135
+ const inlineStart = getInlineStart(writingMode, scriptDir);
136
+ const blockStart = getBlockStart(writingMode);
137
+ content.style.setProperty("--popout-anchor-inline-size", `${anchorRect.width}px`);
138
+ content.style.left = "0px";
139
+ content.style.top = "0px";
140
+ content.style.right = "";
141
+ content.style.bottom = "";
142
+ const place = untrack(() => get(this.#placement));
143
+ switch (place) {
144
+ case "block":
145
+ case "block-start":
146
+ case "block-end":
147
+ content.style.maxInlineSize = `${getWindowSize(inlineStart)}px`;
148
+ content.style.maxBlockSize = `${Math.max(getWindowSpaceAround(anchorRect, blockStart), getWindowSpaceAround(anchorRect, flip(blockStart))) - gap}px`;
149
+ break;
150
+ case "inline":
151
+ case "inline-start":
152
+ case "inline-end":
153
+ content.style.maxBlockSize = `${getWindowSize(blockStart)}px`;
154
+ content.style.maxInlineSize = `${Math.max(getWindowSpaceAround(anchorRect, inlineStart), getWindowSpaceAround(anchorRect, flip(inlineStart))) - gap}px`;
155
+ break;
156
+ }
157
+ content.style.setProperty("--popout-max-block-size", content.style.maxBlockSize);
158
+ content.style.setProperty("--popout-max-inline-size", content.style.maxInlineSize);
159
+ const contentRect = (sizeReference ?? content).getBoundingClientRect();
160
+ let placement;
161
+ let placementDir;
162
+ let alignStart;
163
+ if (place === "inline" || place === "block") {
164
+ const start = place === "inline" ? inlineStart : blockStart;
165
+ const startSpace = getWindowSpaceAround(anchorRect, start);
166
+ const endSpace = getWindowSpaceAround(anchorRect, flip(start));
167
+ if (startSpace > endSpace) {
168
+ placementDir = start;
169
+ placement = place === "inline" ? "inline-start" : "block-start";
170
+ }
171
+ else {
172
+ placementDir = flip(start);
173
+ placement = place === "inline" ? "inline-end" : "block-end";
174
+ }
175
+ alignStart = place === "inline" ? blockStart : inlineStart;
176
+ }
177
+ else {
178
+ placement = place;
179
+ placementDir = place === "block-start" ? blockStart : (place === "block-end" ? flip(blockStart) : (place === "inline-start" ? inlineStart : flip(inlineStart)));
180
+ alignStart = axisEquals(placementDir, blockStart) ? inlineStart : blockStart;
181
+ const space = getWindowSpaceAround(anchorRect, placementDir);
182
+ if (getSize(contentRect, placementDir) > space) {
183
+ if (getWindowSpaceAround(anchorRect, flip(placementDir)) > space) {
184
+ placementDir = flip(placementDir);
185
+ }
186
+ }
187
+ }
188
+ content.style[INSET[flip(placementDir)]] = `${getAnchorRectInset(anchorRect, placementDir) + gap}px`;
189
+ content.style[INSET[placementDir]] = "";
190
+ const align = untrack(() => get(this.#alignment));
191
+ const alignContentSize = getSize(contentRect, alignStart);
192
+ let alignInset;
193
+ let alignEnd = false;
194
+ switch (align) {
195
+ case "center":
196
+ alignInset = getWindowSpaceAround(anchorRect, alignStart) + ((getSize(anchorRect, alignStart) - alignContentSize) / 2);
197
+ break;
198
+ case "start":
199
+ alignInset = getWindowSpaceAround(anchorRect, alignStart);
200
+ break;
201
+ case "end":
202
+ alignInset = getWindowSpaceAround(anchorRect, flip(alignStart));
203
+ alignEnd = true;
204
+ break;
205
+ }
206
+ const alignSpace = getWindowSize(alignStart);
207
+ alignInset = Math.max(0, Math.min(alignInset, alignSpace - alignContentSize));
208
+ content.style[INSET[alignStart]] = alignEnd ? "" : `${alignInset}px`;
209
+ content.style[INSET[flip(alignStart)]] = alignEnd ? `${alignInset}px` : "";
210
+ this.#instanceArgs = {
211
+ anchor,
212
+ pointerEvent,
213
+ contentBlockSize: getSize(contentRect, blockStart),
214
+ contentInlineSize: getSize(contentRect, inlineStart),
215
+ };
216
+ this.#placementState.value = {
217
+ anchorRect,
218
+ content,
219
+ placement,
220
+ placementDir,
221
+ alignStart,
222
+ };
223
+ this.#visible.value = true;
224
+ }
225
+ update() {
226
+ const args = this.#instanceArgs;
227
+ if (args !== undefined) {
228
+ this.show(args.anchor, args.pointerEvent);
229
+ }
230
+ }
231
+ toggle(anchor, pointerEvent) {
232
+ if (this.visible) {
233
+ this.hide();
234
+ }
235
+ else {
236
+ this.show(anchor, pointerEvent);
237
+ }
238
+ }
239
+ hide() {
240
+ const instance = this.#instance;
241
+ if (instance !== undefined) {
242
+ this.#instanceArgs = undefined;
243
+ this.#instance = undefined;
244
+ instance.observer.disconnect();
245
+ instance.dispose();
246
+ instance.view.detach();
247
+ this.#visible.value = false;
248
+ }
249
+ }
250
+ }
251
+ function getAnchorRectInset(rect, dir) {
252
+ switch (dir) {
253
+ case UP: return window.innerHeight - rect.top;
254
+ case RIGHT: return rect.right;
255
+ case DOWN: return rect.bottom;
256
+ case LEFT: return window.innerWidth - rect.left;
257
+ }
258
+ }
259
+ //# sourceMappingURL=popout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"popout.js","sourceRoot":"","sources":["../../src/components/popout.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAiC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAmB,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAgB,OAAO,EAAQ,SAAS,EAAE,MAAM,KAAK,CAAC;AAElM,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,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QAC3C,CAAC;IACF,CAAC;IAKD,MAAM,CAAC,MAAY,EAAE,YAAoB;QACxC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,IAAI,EAAE,CAAC;QACb,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACjC,CAAC;IACF,CAAC;IAKD,IAAI;QACH,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;YAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC3B,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC/B,QAAQ,CAAC,OAAO,EAAE,CAAC;YACnB,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACvB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,CAAC;IACF,CAAC;CACD;AAED,SAAS,kBAAkB,CAAC,IAAa,EAAE,GAAc;IACxD,QAAQ,GAAG,EAAE,CAAC;QACb,KAAK,EAAE,CAAC,CAAC,OAAO,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC;QAC9C,KAAK,KAAK,CAAC,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC;QAC9B,KAAK,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC;QAC9B,KAAK,IAAI,CAAC,CAAC,OAAO,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;IACjD,CAAC;AACF,CAAC"}
@@ -0,0 +1,139 @@
1
+ import { ClassValue, Expression, StyleValue } from "rvx";
2
+ import { Action } from "../common/events.js";
3
+ import { DialogRole } from "./dialog.js";
4
+ import { Popout, PopoutAlignment, PopoutPlacement } from "./popout.js";
5
+ export type PopoverRole = DialogRole | "menu";
6
+ export interface PopoverContent {
7
+ (props: {
8
+ popout: Popout;
9
+ }): unknown;
10
+ }
11
+ /**
12
+ * Create a popover that is initially hidden.
13
+ */
14
+ export declare function createPopover(props: {
15
+ /**
16
+ * Defines the direction in which the popover is placed in relation to the anchor.
17
+ *
18
+ * This expression is only evaluated when calculating the popover placement.
19
+ *
20
+ * See {@link PopoutPlacement}
21
+ *
22
+ * @default "block"
23
+ */
24
+ placement?: Expression<PopoutPlacement | undefined>;
25
+ /**
26
+ * Defines which side of the anchor and popover are aligned orthogonally to the placement axis.
27
+ *
28
+ * This expression is only evaluated when calculating the popover placement.
29
+ *
30
+ * See {@link PopoutAlignment}
31
+ *
32
+ * @default "center"
33
+ */
34
+ alignment?: Expression<PopoutAlignment | undefined>;
35
+ /**
36
+ * The content component.
37
+ */
38
+ content: PopoverContent;
39
+ inlineSize?: Expression<string | undefined>;
40
+ maxInlineSize?: Expression<string | undefined>;
41
+ blockSize?: Expression<string | undefined>;
42
+ maxBlockSize?: Expression<string | undefined>;
43
+ /**
44
+ * An array of event names that cause the popover to hide automatically when dispatched outside of the current layer stack or the anchor.
45
+ *
46
+ * @default ["resize", "scroll", "mousedown", "touchstart", "focusin", "rvx-ui:passive-action"]
47
+ */
48
+ foreignEvents?: string[];
49
+ /**
50
+ * The content role.
51
+ *
52
+ * @default "dialog"
53
+ */
54
+ role?: PopoverRole;
55
+ id?: string;
56
+ class?: ClassValue;
57
+ style?: StyleValue;
58
+ "aria-label"?: Expression<string | undefined>;
59
+ "aria-labelledby"?: Expression<string | undefined>;
60
+ "aria-describedby"?: Expression<string | undefined>;
61
+ }): Popout;
62
+ export interface PopoverAnchorProps {
63
+ action: Action;
64
+ id?: Expression<string | undefined>;
65
+ "aria-label"?: Expression<string | undefined>;
66
+ "aria-labelledby"?: Expression<string | undefined>;
67
+ }
68
+ export declare function Popover(props: {
69
+ /**
70
+ * A function to immediately render the anchor.
71
+ */
72
+ anchor: (props: PopoverAnchorProps) => unknown;
73
+ /**
74
+ * The anchor id.
75
+ *
76
+ * By default, a unique id is generated and linked to the attached popover.
77
+ */
78
+ id?: Expression<string | undefined>;
79
+ /** Class for the popover. */
80
+ class?: ClassValue;
81
+ /** Style for the popover. */
82
+ style?: StyleValue;
83
+ /** The popover content component. */
84
+ children: PopoverContent;
85
+ inlineSize?: Expression<string | undefined>;
86
+ maxInlineSize?: Expression<string | undefined>;
87
+ blockSize?: Expression<string | undefined>;
88
+ maxBlockSize?: Expression<string | undefined>;
89
+ /**
90
+ * Defines the direction in which the popover is placed in relation to the anchor.
91
+ *
92
+ * This expression is only evaluated when calculating the popover placement.
93
+ *
94
+ * See {@link PopoutPlacement}^
95
+ *
96
+ * @default "block"
97
+ */
98
+ placement?: Expression<PopoutPlacement | undefined>;
99
+ /**
100
+ * Defines which side of the anchor and popover are aligned orthogonally to the placement axis.
101
+ *
102
+ * This expression is only evaluated when calculating the popover placement.
103
+ *
104
+ * See {@link PopoutAlignment}
105
+ *
106
+ * @default "center"
107
+ */
108
+ alignment?: Expression<PopoutAlignment | undefined>;
109
+ /**
110
+ * An array of event names that cause the popover to hide automatically when dispatched outside of the current layer stack or the anchor.
111
+ *
112
+ * @default ["resize", "scroll", "mousedown", "touchstart", "focusin", "rvx-ui:passive-action"]
113
+ */
114
+ foreignEvents?: string[];
115
+ /**
116
+ * The popover role.
117
+ *
118
+ * @default "dialog"
119
+ */
120
+ role?: PopoverRole;
121
+ /**
122
+ * The anchor and popover label.
123
+ *
124
+ * By default, the anchor itself is used a label for the popover.
125
+ */
126
+ "aria-label"?: Expression<string | undefined>;
127
+ /**
128
+ * The anchor and popover label id.
129
+ *
130
+ * By default, the anchor itself is used a label for the popover.
131
+ */
132
+ "aria-labelledby"?: Expression<string | undefined>;
133
+ /**
134
+ * An optional popover description id.
135
+ *
136
+ * If the popover contains a description, this should be set to it's id.
137
+ */
138
+ "aria-describedby"?: Expression<string | undefined>;
139
+ }): unknown;
@@ -0,0 +1,101 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "rvx/jsx-runtime";
2
+ import { extract, get, Inject, map, render, sig, SVG, uniqueId, watch, XMLNS } from "rvx";
3
+ import { THEME } from "../common/theme.js";
4
+ import { DOWN, getSize, getXY, LEFT, RIGHT, UP } from "../common/writing-mode.js";
5
+ import { LAYER } from "./layer.js";
6
+ import { Popout } from "./popout.js";
7
+ export function createPopover(props) {
8
+ return new Popout({
9
+ placement: map(props.placement, v => v ?? "block"),
10
+ alignment: map(props.alignment, v => v ?? "center"),
11
+ content: ({ popout, onPlacement, placement, setSizeReference }) => {
12
+ const theme = extract(THEME);
13
+ const layer = extract(LAYER);
14
+ const spikeTransform = sig("");
15
+ layer.useHotkey("escape", () => {
16
+ popout.hide();
17
+ });
18
+ onPlacement(args => {
19
+ args.gap = Math.abs(spikeArea.getBoundingClientRect().x - root.getBoundingClientRect().x);
20
+ });
21
+ watch(placement, placement => {
22
+ if (placement) {
23
+ const { anchorRect, placementDir, alignStart } = placement;
24
+ const contentRect = placement.content.getBoundingClientRect();
25
+ const rawOffset = getXY(anchorRect, alignStart) + (getSize(anchorRect, alignStart) / 2) - getXY(contentRect, alignStart);
26
+ const offset = `max(var(--popover-spike-min-offset), min(${rawOffset}px, ${getSize(contentRect, alignStart)}px - var(--popover-spike-min-offset)))`;
27
+ switch (placementDir) {
28
+ case DOWN:
29
+ spikeTransform.value = `translate(${offset}, 0px)`;
30
+ break;
31
+ case UP:
32
+ spikeTransform.value = `translate(${offset}, ${contentRect.height}px) rotate(180deg)`;
33
+ break;
34
+ case RIGHT:
35
+ spikeTransform.value = `translate(0px, ${offset}) rotate(270deg)`;
36
+ break;
37
+ case LEFT:
38
+ spikeTransform.value = `translate(${contentRect.width}px, ${offset}) rotate(90deg)`;
39
+ break;
40
+ }
41
+ }
42
+ });
43
+ const spikeArea = _jsx("div", { class: theme?.popover_spike_area, children: _jsx("div", { class: theme?.popover_spike, style: { transform: spikeTransform }, children: _jsx(Inject, { value: SVG, children: () => {
44
+ return _jsx("svg", { viewBox: "0 0 16 16", preserveAspectRatio: "none", children: _jsx("path", { d: "M0,16 L8,0 L16,16 Z" }) });
45
+ } }, XMLNS) }) });
46
+ const content = _jsx("div", { class: [
47
+ theme?.column,
48
+ theme?.column_content,
49
+ theme?.popover_content,
50
+ ], children: props.content({ popout }) });
51
+ setSizeReference(content);
52
+ const root = _jsxs("div", { tabindex: "-1", role: map(props.role, v => v ?? "dialog"), id: props.id, class: [
53
+ theme?.popover,
54
+ props.class,
55
+ ], style: [
56
+ props.style,
57
+ {
58
+ "inline-size": props.inlineSize,
59
+ "max-inline-size": props.maxInlineSize,
60
+ "block-size": props.blockSize,
61
+ "max-block-size": props.maxBlockSize,
62
+ },
63
+ ], "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], "aria-describedby": props["aria-describedby"], children: [spikeArea, _jsx("div", { class: theme?.popover_scroll_area, children: content })] });
64
+ layer.useAutoFocusFallback(root);
65
+ return root;
66
+ },
67
+ foreignEvents: props.foreignEvents,
68
+ });
69
+ }
70
+ export function Popover(props) {
71
+ const defaultId = uniqueId();
72
+ const id = map(props.id, v => v ?? defaultId);
73
+ const popover = createPopover({
74
+ content: props.children,
75
+ inlineSize: props.inlineSize,
76
+ maxInlineSize: props.maxInlineSize,
77
+ blockSize: props.blockSize,
78
+ maxBlockSize: props.maxBlockSize,
79
+ placement: props.placement,
80
+ alignment: props.alignment,
81
+ foreignEvents: props.foreignEvents,
82
+ role: props.role,
83
+ class: props.class,
84
+ style: props.style,
85
+ "aria-label": props["aria-label"],
86
+ "aria-labelledby": () => (get(props["aria-label"]) === undefined
87
+ ? (get(props["aria-labelledby"]) ?? get(id))
88
+ : undefined),
89
+ "aria-describedby": props["aria-describedby"],
90
+ });
91
+ const anchor = render(props.anchor({
92
+ action: event => {
93
+ popover.toggle(anchor, event);
94
+ },
95
+ id,
96
+ "aria-label": props["aria-label"],
97
+ "aria-labelledby": props["aria-labelledby"],
98
+ }));
99
+ return anchor;
100
+ }
101
+ //# sourceMappingURL=popover.js.map
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