@c9up/nebula 0.2.5 → 0.2.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.
- package/README.md +2 -2
- package/dist/atoms/NativeSelect.d.ts +6 -0
- package/dist/organisms/Agenda.d.ts +200 -0
- package/dist/organisms/Agenda.js +762 -0
- package/dist/organisms/index.d.ts +1 -0
- package/dist/organisms/index.js +1 -0
- package/dist/primitives/floatingSurface.js +60 -36
- package/nebula.css +1 -1
- package/package.json +1 -1
- package/registry.json +13 -0
- package/src/atoms/NativeSelect.ts +6 -0
- package/src/organisms/Agenda.ts +1061 -0
- package/src/organisms/index.ts +20 -0
- package/src/primitives/floatingSurface.ts +74 -40
package/src/organisms/index.ts
CHANGED
|
@@ -13,6 +13,26 @@
|
|
|
13
13
|
* restoration, hiding the page from assistive technology) exist once.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
export {
|
|
17
|
+
Agenda,
|
|
18
|
+
type AgendaChange,
|
|
19
|
+
type AgendaColumn,
|
|
20
|
+
type AgendaEvent,
|
|
21
|
+
type AgendaLabels,
|
|
22
|
+
type AgendaProps,
|
|
23
|
+
type AgendaRange,
|
|
24
|
+
type AgendaSlot,
|
|
25
|
+
type AgendaTone,
|
|
26
|
+
clampEnd,
|
|
27
|
+
clampMove,
|
|
28
|
+
clockOf,
|
|
29
|
+
isoDay,
|
|
30
|
+
type Lane,
|
|
31
|
+
lanesOf,
|
|
32
|
+
minutesOf,
|
|
33
|
+
snapDown,
|
|
34
|
+
snapNearest,
|
|
35
|
+
} from "./Agenda.js";
|
|
16
36
|
export {
|
|
17
37
|
AlertDialog,
|
|
18
38
|
AlertDialogAction,
|
|
@@ -87,10 +87,20 @@ interface Live {
|
|
|
87
87
|
*/
|
|
88
88
|
readonly anchor: HTMLElement;
|
|
89
89
|
readonly element: HTMLElement;
|
|
90
|
+
/**
|
|
91
|
+
* What makes it behave as an open surface: `null` from the moment it
|
|
92
|
+
* closes, through its exit animation. A surface reopened mid-exit is armed
|
|
93
|
+
* again — reusing the node without this brought it back with no dismiss
|
|
94
|
+
* layer, no repositioning and no focus trap.
|
|
95
|
+
*/
|
|
96
|
+
armed: Armed | null;
|
|
97
|
+
cancelExit: (() => void) | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface Armed {
|
|
90
101
|
readonly position: AutoPosition;
|
|
91
102
|
readonly layer: DismissableLayer;
|
|
92
103
|
readonly trap: FocusTrap | null;
|
|
93
|
-
cancelExit: (() => void) | null;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
/**
|
|
@@ -102,37 +112,11 @@ interface Live {
|
|
|
102
112
|
export function floatingSurface(options: FloatingSurfaceOptions): void {
|
|
103
113
|
let live: Live | null = null;
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (live.anchor === anchor) {
|
|
111
|
-
// The SAME anchor, already open and possibly mid-exit: cancel
|
|
112
|
-
// the teardown and reuse the node rather than stacking a second
|
|
113
|
-
// copy on top of the one fading out.
|
|
114
|
-
live.cancelExit?.();
|
|
115
|
-
live.cancelExit = null;
|
|
116
|
-
live.element.setAttribute("data-state", "open");
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
// A DIFFERENT anchor. Content is built once per open, so reusing
|
|
120
|
-
// this node would show the previous anchor's content — one surface
|
|
121
|
-
// shared by the rows of a table showed the first row's entries
|
|
122
|
-
// however many rows were clicked. Its position, dismissal listeners
|
|
123
|
-
// and focus trap all belong to the old anchor too.
|
|
124
|
-
teardown();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const mount = portal(options.content());
|
|
128
|
-
const element = mount.host.firstElementChild;
|
|
129
|
-
if (!(element instanceof HTMLElement)) {
|
|
130
|
-
mount.close();
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
element.setAttribute("data-state", "open");
|
|
135
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Position, dismissal and focus, in that order: the layer registers once
|
|
117
|
+
* the content exists, the trap focuses a surface already positioned.
|
|
118
|
+
*/
|
|
119
|
+
function arm(anchor: HTMLElement, element: HTMLElement): Armed {
|
|
136
120
|
const position = autoPosition(anchor, element, {
|
|
137
121
|
placement: options.placement,
|
|
138
122
|
offset: options.offset,
|
|
@@ -164,20 +148,72 @@ export function floatingSurface(options: FloatingSurfaceOptions): void {
|
|
|
164
148
|
} else if (options.autoFocus === true) {
|
|
165
149
|
focusSilently(options.initialFocus?.(element) ?? firstFocusable(element));
|
|
166
150
|
}
|
|
151
|
+
return { position, layer, trap };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function disarm(current: Live): void {
|
|
155
|
+
const armed = current.armed;
|
|
156
|
+
if (armed === null) return;
|
|
157
|
+
current.armed = null;
|
|
158
|
+
armed.layer.remove();
|
|
159
|
+
armed.position.stop();
|
|
160
|
+
armed.trap?.release();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function show(): void {
|
|
164
|
+
const anchor = options.anchor();
|
|
165
|
+
if (anchor === null) return;
|
|
167
166
|
|
|
168
|
-
live
|
|
167
|
+
if (live !== null) {
|
|
168
|
+
if (live.anchor === anchor) {
|
|
169
|
+
// The SAME anchor, already open and possibly mid-exit: cancel
|
|
170
|
+
// the teardown and reuse the node rather than stacking a second
|
|
171
|
+
// copy on top of the one fading out.
|
|
172
|
+
live.cancelExit?.();
|
|
173
|
+
live.cancelExit = null;
|
|
174
|
+
live.element.setAttribute("data-state", "open");
|
|
175
|
+
if (live.armed === null) {
|
|
176
|
+
live.armed = arm(anchor, live.element);
|
|
177
|
+
// `onClosed` ran when it started closing, so the component
|
|
178
|
+
// unwired its items; it is open again and rewires them.
|
|
179
|
+
options.onOpened?.(live.element);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
// A DIFFERENT anchor. Content is built once per open, so reusing
|
|
184
|
+
// this node would show the previous anchor's content — one surface
|
|
185
|
+
// shared by the rows of a table showed the first row's entries
|
|
186
|
+
// however many rows were clicked. Its position, dismissal listeners
|
|
187
|
+
// and focus trap all belong to the old anchor too.
|
|
188
|
+
teardown();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const mount = portal(options.content());
|
|
192
|
+
const element = mount.host.firstElementChild;
|
|
193
|
+
if (!(element instanceof HTMLElement)) {
|
|
194
|
+
mount.close();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
element.setAttribute("data-state", "open");
|
|
199
|
+
|
|
200
|
+
live = {
|
|
201
|
+
mount,
|
|
202
|
+
anchor,
|
|
203
|
+
element,
|
|
204
|
+
armed: arm(anchor, element),
|
|
205
|
+
cancelExit: null,
|
|
206
|
+
};
|
|
169
207
|
options.onOpened?.(element);
|
|
170
208
|
}
|
|
171
209
|
|
|
172
210
|
function hide(): void {
|
|
173
211
|
const current = live;
|
|
174
|
-
if (current === null) return;
|
|
212
|
+
if (current === null || current.armed === null) return;
|
|
175
213
|
|
|
176
214
|
// Detach behaviour first, then animate out. A surface that is fading
|
|
177
215
|
// should not still be answering Escape or repositioning itself.
|
|
178
|
-
current
|
|
179
|
-
current.position.stop();
|
|
180
|
-
current.trap?.release();
|
|
216
|
+
disarm(current);
|
|
181
217
|
returnFocusToAnchor(current.element, current.anchor);
|
|
182
218
|
current.element.setAttribute("data-state", "closed");
|
|
183
219
|
options.onClosed?.();
|
|
@@ -216,9 +252,7 @@ export function floatingSurface(options: FloatingSurfaceOptions): void {
|
|
|
216
252
|
if (current === null) return;
|
|
217
253
|
live = null;
|
|
218
254
|
current.cancelExit?.();
|
|
219
|
-
current
|
|
220
|
-
current.position.stop();
|
|
221
|
-
current.trap?.release();
|
|
255
|
+
disarm(current);
|
|
222
256
|
current.mount.close();
|
|
223
257
|
}
|
|
224
258
|
|