@soomo/react-text-annotator 3.0.0-staging.38 → 3.0.0-staging.39

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 (74) hide show
  1. package/dist/{TextAnnotatorPopup.d.ts → TextAnnotatorPopup/TextAnnotatorPopup.d.ts} +3 -2
  2. package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -0
  3. package/dist/TextAnnotatorPopup/index.d.ts +2 -0
  4. package/dist/TextAnnotatorPopup/index.d.ts.map +1 -0
  5. package/dist/hooks/index.d.ts +3 -0
  6. package/dist/hooks/index.d.ts.map +1 -0
  7. package/dist/hooks/useAnnouncePopupNavigation.d.ts +8 -0
  8. package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +1 -0
  9. package/dist/hooks/useRestoreSelectionCaret.d.ts +13 -0
  10. package/dist/hooks/useRestoreSelectionCaret.d.ts.map +1 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/react-text-annotator.css +30 -0
  14. package/dist/react-text-annotator.es.js +8 -4
  15. package/dist/react-text-annotator.es.js.map +1 -1
  16. package/dist/react-text-annotator.es11.js +445 -527
  17. package/dist/react-text-annotator.es11.js.map +1 -1
  18. package/dist/react-text-annotator.es12.js +60 -483
  19. package/dist/react-text-annotator.es12.js.map +1 -1
  20. package/dist/react-text-annotator.es13.js +38 -44
  21. package/dist/react-text-annotator.es13.js.map +1 -1
  22. package/dist/react-text-annotator.es14.js +1422 -118
  23. package/dist/react-text-annotator.es14.js.map +1 -1
  24. package/dist/react-text-annotator.es16.js +239 -29
  25. package/dist/react-text-annotator.es16.js.map +1 -1
  26. package/dist/react-text-annotator.es17.js +568 -897
  27. package/dist/react-text-annotator.es17.js.map +1 -1
  28. package/dist/react-text-annotator.es18.js +2 -2
  29. package/dist/react-text-annotator.es19.js +31 -2
  30. package/dist/react-text-annotator.es19.js.map +1 -1
  31. package/dist/react-text-annotator.es2.js +2 -2
  32. package/dist/react-text-annotator.es20.js +893 -109
  33. package/dist/react-text-annotator.es20.js.map +1 -1
  34. package/dist/react-text-annotator.es21.js +2 -309
  35. package/dist/react-text-annotator.es21.js.map +1 -1
  36. package/dist/react-text-annotator.es22.js +2 -58
  37. package/dist/react-text-annotator.es22.js.map +1 -1
  38. package/dist/react-text-annotator.es23.js +113 -19
  39. package/dist/react-text-annotator.es23.js.map +1 -1
  40. package/dist/react-text-annotator.es24.js +290 -130
  41. package/dist/react-text-annotator.es24.js.map +1 -1
  42. package/dist/react-text-annotator.es25.js +43 -545
  43. package/dist/react-text-annotator.es25.js.map +1 -1
  44. package/dist/react-text-annotator.es26.js +23 -0
  45. package/dist/react-text-annotator.es26.js.map +1 -0
  46. package/dist/react-text-annotator.es27.js +130 -0
  47. package/dist/react-text-annotator.es27.js.map +1 -0
  48. package/dist/react-text-annotator.es28.js +155 -0
  49. package/dist/react-text-annotator.es28.js.map +1 -0
  50. package/dist/react-text-annotator.es29.js +314 -0
  51. package/dist/react-text-annotator.es29.js.map +1 -0
  52. package/dist/react-text-annotator.es3.js +2 -2
  53. package/dist/react-text-annotator.es30.js +152 -0
  54. package/dist/react-text-annotator.es30.js.map +1 -0
  55. package/dist/react-text-annotator.es31.js +563 -0
  56. package/dist/react-text-annotator.es31.js.map +1 -0
  57. package/dist/react-text-annotator.es4.js +30 -23
  58. package/dist/react-text-annotator.es4.js.map +1 -1
  59. package/dist/react-text-annotator.es5.js +36 -78
  60. package/dist/react-text-annotator.es5.js.map +1 -1
  61. package/dist/react-text-annotator.es6.js +24 -178
  62. package/dist/react-text-annotator.es6.js.map +1 -1
  63. package/dist/react-text-annotator.es7.js +126 -10
  64. package/dist/react-text-annotator.es7.js.map +1 -1
  65. package/dist/react-text-annotator.es8.js +182 -0
  66. package/dist/react-text-annotator.es8.js.map +1 -0
  67. package/dist/react-text-annotator.es9.js +10 -670
  68. package/dist/react-text-annotator.es9.js.map +1 -1
  69. package/package.json +5 -3
  70. package/dist/TextAnnotatorPopup.d.ts.map +0 -1
  71. package/dist/react-text-annotator.es10.js +0 -244
  72. package/dist/react-text-annotator.es10.js.map +0 -1
  73. package/dist/react-text-annotator.es15.js +0 -5
  74. package/dist/react-text-annotator.es15.js.map +0 -1
@@ -1,673 +1,13 @@
1
- import * as React from "react";
2
- import { useLayoutEffect, useEffect } from "react";
3
- import { getDocument, isReactEvent, getTarget, isRootElement, contains, isEventTargetWithin } from "./react-text-annotator.es13.js";
4
- import { isElement, getOverflowAncestors, isLastTraversableNode, getParentNode, isHTMLElement, getComputedStyle } from "./react-text-annotator.es14.js";
5
- import "react-dom";
6
- import { useFloating as useFloating$1 } from "./react-text-annotator.es10.js";
7
- import { flip, inline, offset, shift } from "./react-text-annotator.es10.js";
8
- const SafeReact = {
9
- ...React
10
- };
11
- const useInsertionEffect = SafeReact.useInsertionEffect;
12
- const useSafeInsertionEffect = useInsertionEffect || ((fn) => fn());
13
- function useEffectEvent(callback) {
14
- const ref = React.useRef(() => {
15
- if (process.env.NODE_ENV !== "production") {
16
- throw new Error("Cannot call an event handler while rendering.");
17
- }
18
- });
19
- useSafeInsertionEffect(() => {
20
- ref.current = callback;
21
- });
22
- return React.useCallback(function() {
23
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
24
- args[_key] = arguments[_key];
25
- }
26
- return ref.current == null ? void 0 : ref.current(...args);
27
- }, []);
28
- }
29
- var index = typeof document !== "undefined" ? useLayoutEffect : useEffect;
30
- let serverHandoffComplete = false;
31
- let count = 0;
32
- const genId = () => (
33
- // Ensure the id is unique with multiple independent versions of Floating UI
34
- // on <React 18
35
- "floating-ui-" + Math.random().toString(36).slice(2, 6) + count++
36
- );
37
- function useFloatingId() {
38
- const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : void 0);
39
- index(() => {
40
- if (id == null) {
41
- setId(genId());
42
- }
43
- }, []);
44
- React.useEffect(() => {
45
- serverHandoffComplete = true;
46
- }, []);
47
- return id;
48
- }
49
- const useReactId = SafeReact.useId;
50
- const useId = useReactId || useFloatingId;
51
- let devMessageSet;
52
- if (process.env.NODE_ENV !== "production") {
53
- devMessageSet = /* @__PURE__ */ new Set();
54
- }
55
- function error() {
56
- var _devMessageSet3;
57
- for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
58
- messages[_key2] = arguments[_key2];
59
- }
60
- const message = "Floating UI: " + messages.join(" ");
61
- if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
62
- var _devMessageSet4;
63
- (_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
64
- console.error(message);
65
- }
66
- }
67
- function createPubSub() {
68
- const map = /* @__PURE__ */ new Map();
69
- return {
70
- emit(event, data) {
71
- var _map$get;
72
- (_map$get = map.get(event)) == null || _map$get.forEach((handler) => handler(data));
73
- },
74
- on(event, listener) {
75
- map.set(event, [...map.get(event) || [], listener]);
76
- },
77
- off(event, listener) {
78
- var _map$get2;
79
- map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter((l) => l !== listener)) || []);
80
- }
81
- };
82
- }
83
- const FloatingNodeContext = /* @__PURE__ */ React.createContext(null);
84
- const FloatingTreeContext = /* @__PURE__ */ React.createContext(null);
85
- const useFloatingParentNodeId = () => {
86
- var _React$useContext;
87
- return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
88
- };
89
- const useFloatingTree = () => React.useContext(FloatingTreeContext);
90
- function createAttribute(name) {
91
- return "data-floating-ui-" + name;
92
- }
93
- function getChildren(nodes, id) {
94
- let allChildren = nodes.filter((node) => {
95
- var _node$context;
96
- return node.parentId === id && ((_node$context = node.context) == null ? void 0 : _node$context.open);
97
- });
98
- let currentChildren = allChildren;
99
- while (currentChildren.length) {
100
- currentChildren = nodes.filter((node) => {
101
- var _currentChildren;
102
- return (_currentChildren = currentChildren) == null ? void 0 : _currentChildren.some((n) => {
103
- var _node$context2;
104
- return node.parentId === n.id && ((_node$context2 = node.context) == null ? void 0 : _node$context2.open);
105
- });
106
- });
107
- allChildren = allChildren.concat(currentChildren);
108
- }
109
- return allChildren;
110
- }
111
- const bubbleHandlerKeys = {
112
- pointerdown: "onPointerDown",
113
- mousedown: "onMouseDown",
114
- click: "onClick"
115
- };
116
- const captureHandlerKeys = {
117
- pointerdown: "onPointerDownCapture",
118
- mousedown: "onMouseDownCapture",
119
- click: "onClickCapture"
120
- };
121
- const normalizeProp = (normalizable) => {
122
- var _normalizable$escapeK, _normalizable$outside;
123
- return {
124
- escapeKey: typeof normalizable === "boolean" ? normalizable : (_normalizable$escapeK = normalizable == null ? void 0 : normalizable.escapeKey) != null ? _normalizable$escapeK : false,
125
- outsidePress: typeof normalizable === "boolean" ? normalizable : (_normalizable$outside = normalizable == null ? void 0 : normalizable.outsidePress) != null ? _normalizable$outside : true
126
- };
127
- };
128
- function useDismiss(context, props) {
129
- if (props === void 0) {
130
- props = {};
131
- }
132
- const {
133
- open,
134
- onOpenChange,
135
- elements,
136
- dataRef
137
- } = context;
138
- const {
139
- enabled = true,
140
- escapeKey = true,
141
- outsidePress: unstable_outsidePress = true,
142
- outsidePressEvent = "pointerdown",
143
- referencePress = false,
144
- referencePressEvent = "pointerdown",
145
- ancestorScroll = false,
146
- bubbles,
147
- capture
148
- } = props;
149
- const tree = useFloatingTree();
150
- const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === "function" ? unstable_outsidePress : () => false);
151
- const outsidePress = typeof unstable_outsidePress === "function" ? outsidePressFn : unstable_outsidePress;
152
- const insideReactTreeRef = React.useRef(false);
153
- const endedOrStartedInsideRef = React.useRef(false);
154
- const {
155
- escapeKey: escapeKeyBubbles,
156
- outsidePress: outsidePressBubbles
157
- } = normalizeProp(bubbles);
158
- const {
159
- escapeKey: escapeKeyCapture,
160
- outsidePress: outsidePressCapture
161
- } = normalizeProp(capture);
162
- const closeOnEscapeKeyDown = useEffectEvent((event) => {
163
- var _dataRef$current$floa;
164
- if (!open || !enabled || !escapeKey || event.key !== "Escape") {
165
- return;
166
- }
167
- const nodeId = (_dataRef$current$floa = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa.nodeId;
168
- const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
169
- if (!escapeKeyBubbles) {
170
- event.stopPropagation();
171
- if (children.length > 0) {
172
- let shouldDismiss = true;
173
- children.forEach((child) => {
174
- var _child$context;
175
- if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
176
- shouldDismiss = false;
177
- return;
178
- }
179
- });
180
- if (!shouldDismiss) {
181
- return;
182
- }
183
- }
184
- }
185
- onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event, "escape-key");
186
- });
187
- const closeOnEscapeKeyDownCapture = useEffectEvent((event) => {
188
- var _getTarget2;
189
- const callback = () => {
190
- var _getTarget;
191
- closeOnEscapeKeyDown(event);
192
- (_getTarget = getTarget(event)) == null || _getTarget.removeEventListener("keydown", callback);
193
- };
194
- (_getTarget2 = getTarget(event)) == null || _getTarget2.addEventListener("keydown", callback);
195
- });
196
- const closeOnPressOutside = useEffectEvent((event) => {
197
- var _dataRef$current$floa2;
198
- const insideReactTree = insideReactTreeRef.current;
199
- insideReactTreeRef.current = false;
200
- const endedOrStartedInside = endedOrStartedInsideRef.current;
201
- endedOrStartedInsideRef.current = false;
202
- if (outsidePressEvent === "click" && endedOrStartedInside) {
203
- return;
204
- }
205
- if (insideReactTree) {
206
- return;
207
- }
208
- if (typeof outsidePress === "function" && !outsidePress(event)) {
209
- return;
210
- }
211
- const target = getTarget(event);
212
- const inertSelector = "[" + createAttribute("inert") + "]";
213
- const markers = getDocument(elements.floating).querySelectorAll(inertSelector);
214
- let targetRootAncestor = isElement(target) ? target : null;
215
- while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
216
- const nextParent = getParentNode(targetRootAncestor);
217
- if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
218
- break;
219
- }
220
- targetRootAncestor = nextParent;
221
- }
222
- if (markers.length && isElement(target) && !isRootElement(target) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
223
- !contains(target, elements.floating) && // If the target root element contains none of the markers, then the
224
- // element was injected after the floating element rendered.
225
- Array.from(markers).every((marker) => !contains(targetRootAncestor, marker))) {
226
- return;
227
- }
228
- if (isHTMLElement(target) && floating) {
229
- const canScrollX = target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
230
- const canScrollY = target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
231
- let xCond = canScrollY && event.offsetX > target.clientWidth;
232
- if (canScrollY) {
233
- const isRTL = getComputedStyle(target).direction === "rtl";
234
- if (isRTL) {
235
- xCond = event.offsetX <= target.offsetWidth - target.clientWidth;
236
- }
237
- }
238
- if (xCond || canScrollX && event.offsetY > target.clientHeight) {
239
- return;
240
- }
241
- }
242
- const nodeId = (_dataRef$current$floa2 = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa2.nodeId;
243
- const targetIsInsideChildren = tree && getChildren(tree.nodesRef.current, nodeId).some((node) => {
244
- var _node$context;
245
- return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
246
- });
247
- if (isEventTargetWithin(event, elements.floating) || isEventTargetWithin(event, elements.domReference) || targetIsInsideChildren) {
248
- return;
249
- }
250
- const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
251
- if (children.length > 0) {
252
- let shouldDismiss = true;
253
- children.forEach((child) => {
254
- var _child$context2;
255
- if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
256
- shouldDismiss = false;
257
- return;
258
- }
259
- });
260
- if (!shouldDismiss) {
261
- return;
262
- }
263
- }
264
- onOpenChange(false, event, "outside-press");
265
- });
266
- const closeOnPressOutsideCapture = useEffectEvent((event) => {
267
- var _getTarget4;
268
- const callback = () => {
269
- var _getTarget3;
270
- closeOnPressOutside(event);
271
- (_getTarget3 = getTarget(event)) == null || _getTarget3.removeEventListener(outsidePressEvent, callback);
272
- };
273
- (_getTarget4 = getTarget(event)) == null || _getTarget4.addEventListener(outsidePressEvent, callback);
274
- });
275
- React.useEffect(() => {
276
- if (!open || !enabled) {
277
- return;
278
- }
279
- dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
280
- dataRef.current.__outsidePressBubbles = outsidePressBubbles;
281
- function onScroll(event) {
282
- onOpenChange(false, event, "ancestor-scroll");
283
- }
284
- const doc = getDocument(elements.floating);
285
- escapeKey && doc.addEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
286
- outsidePress && doc.addEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
287
- let ancestors = [];
288
- if (ancestorScroll) {
289
- if (isElement(elements.domReference)) {
290
- ancestors = getOverflowAncestors(elements.domReference);
291
- }
292
- if (isElement(elements.floating)) {
293
- ancestors = ancestors.concat(getOverflowAncestors(elements.floating));
294
- }
295
- if (!isElement(elements.reference) && elements.reference && elements.reference.contextElement) {
296
- ancestors = ancestors.concat(getOverflowAncestors(elements.reference.contextElement));
297
- }
298
- }
299
- ancestors = ancestors.filter((ancestor) => {
300
- var _doc$defaultView;
301
- return ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport);
302
- });
303
- ancestors.forEach((ancestor) => {
304
- ancestor.addEventListener("scroll", onScroll, {
305
- passive: true
306
- });
307
- });
308
- return () => {
309
- escapeKey && doc.removeEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
310
- outsidePress && doc.removeEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
311
- ancestors.forEach((ancestor) => {
312
- ancestor.removeEventListener("scroll", onScroll);
313
- });
314
- };
315
- }, [dataRef, elements, escapeKey, outsidePress, outsidePressEvent, open, onOpenChange, ancestorScroll, enabled, escapeKeyBubbles, outsidePressBubbles, closeOnEscapeKeyDown, escapeKeyCapture, closeOnEscapeKeyDownCapture, closeOnPressOutside, outsidePressCapture, closeOnPressOutsideCapture]);
316
- React.useEffect(() => {
317
- insideReactTreeRef.current = false;
318
- }, [outsidePress, outsidePressEvent]);
319
- const reference = React.useMemo(() => ({
320
- onKeyDown: closeOnEscapeKeyDown,
321
- [bubbleHandlerKeys[referencePressEvent]]: (event) => {
322
- if (referencePress) {
323
- onOpenChange(false, event.nativeEvent, "reference-press");
324
- }
325
- }
326
- }), [closeOnEscapeKeyDown, onOpenChange, referencePress, referencePressEvent]);
327
- const floating = React.useMemo(() => ({
328
- onKeyDown: closeOnEscapeKeyDown,
329
- onMouseDown() {
330
- endedOrStartedInsideRef.current = true;
331
- },
332
- onMouseUp() {
333
- endedOrStartedInsideRef.current = true;
334
- },
335
- [captureHandlerKeys[outsidePressEvent]]: () => {
336
- insideReactTreeRef.current = true;
337
- }
338
- }), [closeOnEscapeKeyDown, outsidePressEvent]);
339
- return React.useMemo(() => enabled ? {
340
- reference,
341
- floating
342
- } : {}, [enabled, reference, floating]);
343
- }
344
- function useFloatingRootContext(options) {
345
- const {
346
- open = false,
347
- onOpenChange: onOpenChangeProp,
348
- elements: elementsProp
349
- } = options;
350
- const floatingId = useId();
351
- const dataRef = React.useRef({});
352
- const [events] = React.useState(() => createPubSub());
353
- const nested = useFloatingParentNodeId() != null;
354
- if (process.env.NODE_ENV !== "production") {
355
- const optionDomReference = elementsProp.reference;
356
- if (optionDomReference && !isElement(optionDomReference)) {
357
- error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
358
- }
359
- }
360
- const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
361
- const onOpenChange = useEffectEvent((open2, event, reason) => {
362
- dataRef.current.openEvent = open2 ? event : void 0;
363
- events.emit("openchange", {
364
- open: open2,
365
- event,
366
- reason,
367
- nested
368
- });
369
- onOpenChangeProp == null || onOpenChangeProp(open2, event, reason);
370
- });
371
- const refs = React.useMemo(() => ({
372
- setPositionReference
373
- }), []);
374
- const elements = React.useMemo(() => ({
375
- reference: positionReference || elementsProp.reference || null,
376
- floating: elementsProp.floating || null,
377
- domReference: elementsProp.reference
378
- }), [positionReference, elementsProp.reference, elementsProp.floating]);
379
- return React.useMemo(() => ({
380
- dataRef,
381
- open,
382
- onOpenChange,
383
- elements,
384
- events,
385
- floatingId,
386
- refs
387
- }), [open, onOpenChange, elements, events, floatingId, refs]);
388
- }
389
- function useFloating(options) {
390
- if (options === void 0) {
391
- options = {};
392
- }
393
- const {
394
- nodeId
395
- } = options;
396
- const internalRootContext = useFloatingRootContext({
397
- ...options,
398
- elements: {
399
- reference: null,
400
- floating: null,
401
- ...options.elements
402
- }
403
- });
404
- const rootContext = options.rootContext || internalRootContext;
405
- const computedElements = rootContext.elements;
406
- const [_domReference, setDomReference] = React.useState(null);
407
- const [positionReference, _setPositionReference] = React.useState(null);
408
- const optionDomReference = computedElements == null ? void 0 : computedElements.reference;
409
- const domReference = optionDomReference || _domReference;
410
- const domReferenceRef = React.useRef(null);
411
- const tree = useFloatingTree();
412
- index(() => {
413
- if (domReference) {
414
- domReferenceRef.current = domReference;
415
- }
416
- }, [domReference]);
417
- const position = useFloating$1({
418
- ...options,
419
- elements: {
420
- ...computedElements,
421
- ...positionReference && {
422
- reference: positionReference
423
- }
424
- }
425
- });
426
- const setPositionReference = React.useCallback((node) => {
427
- const computedPositionReference = isElement(node) ? {
428
- getBoundingClientRect: () => node.getBoundingClientRect(),
429
- contextElement: node
430
- } : node;
431
- _setPositionReference(computedPositionReference);
432
- position.refs.setReference(computedPositionReference);
433
- }, [position.refs]);
434
- const setReference = React.useCallback((node) => {
435
- if (isElement(node) || node === null) {
436
- domReferenceRef.current = node;
437
- setDomReference(node);
438
- }
439
- if (isElement(position.refs.reference.current) || position.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
440
- // `null` to support `positionReference` + an unstable `reference`
441
- // callback ref.
442
- node !== null && !isElement(node)) {
443
- position.refs.setReference(node);
444
- }
445
- }, [position.refs]);
446
- const refs = React.useMemo(() => ({
447
- ...position.refs,
448
- setReference,
449
- setPositionReference,
450
- domReference: domReferenceRef
451
- }), [position.refs, setReference, setPositionReference]);
452
- const elements = React.useMemo(() => ({
453
- ...position.elements,
454
- domReference
455
- }), [position.elements, domReference]);
456
- const context = React.useMemo(() => ({
457
- ...position,
458
- ...rootContext,
459
- refs,
460
- elements,
461
- nodeId
462
- }), [position, refs, elements, nodeId, rootContext]);
463
- index(() => {
464
- rootContext.dataRef.current.floatingContext = context;
465
- const node = tree == null ? void 0 : tree.nodesRef.current.find((node2) => node2.id === nodeId);
466
- if (node) {
467
- node.context = context;
468
- }
469
- });
470
- return React.useMemo(() => ({
471
- ...position,
472
- context,
473
- refs,
474
- elements
475
- }), [position, refs, elements, context]);
476
- }
477
- const ACTIVE_KEY = "active";
478
- const SELECTED_KEY = "selected";
479
- function mergeProps(userProps, propsList, elementKey) {
480
- const map = /* @__PURE__ */ new Map();
481
- const isItem = elementKey === "item";
482
- let domUserProps = userProps;
483
- if (isItem && userProps) {
484
- const {
485
- [ACTIVE_KEY]: _,
486
- [SELECTED_KEY]: __,
487
- ...validProps
488
- } = userProps;
489
- domUserProps = validProps;
490
- }
491
- return {
492
- ...elementKey === "floating" && {
493
- tabIndex: -1
494
- },
495
- ...domUserProps,
496
- ...propsList.map((value) => {
497
- const propsOrGetProps = value ? value[elementKey] : null;
498
- if (typeof propsOrGetProps === "function") {
499
- return userProps ? propsOrGetProps(userProps) : null;
500
- }
501
- return propsOrGetProps;
502
- }).concat(userProps).reduce((acc, props) => {
503
- if (!props) {
504
- return acc;
505
- }
506
- Object.entries(props).forEach((_ref) => {
507
- let [key, value] = _ref;
508
- if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
509
- return;
510
- }
511
- if (key.indexOf("on") === 0) {
512
- if (!map.has(key)) {
513
- map.set(key, []);
514
- }
515
- if (typeof value === "function") {
516
- var _map$get;
517
- (_map$get = map.get(key)) == null || _map$get.push(value);
518
- acc[key] = function() {
519
- var _map$get2;
520
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
521
- args[_key] = arguments[_key];
522
- }
523
- return (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.map((fn) => fn(...args)).find((val) => val !== void 0);
524
- };
525
- }
526
- } else {
527
- acc[key] = value;
528
- }
529
- });
530
- return acc;
531
- }, {})
532
- };
533
- }
534
- function useInteractions(propsList) {
535
- if (propsList === void 0) {
536
- propsList = [];
537
- }
538
- const referenceDeps = propsList.map((key) => key == null ? void 0 : key.reference);
539
- const floatingDeps = propsList.map((key) => key == null ? void 0 : key.floating);
540
- const itemDeps = propsList.map((key) => key == null ? void 0 : key.item);
541
- const getReferenceProps = React.useCallback(
542
- (userProps) => mergeProps(userProps, propsList, "reference"),
543
- // eslint-disable-next-line react-hooks/exhaustive-deps
544
- referenceDeps
545
- );
546
- const getFloatingProps = React.useCallback(
547
- (userProps) => mergeProps(userProps, propsList, "floating"),
548
- // eslint-disable-next-line react-hooks/exhaustive-deps
549
- floatingDeps
550
- );
551
- const getItemProps = React.useCallback(
552
- (userProps) => mergeProps(userProps, propsList, "item"),
553
- // eslint-disable-next-line react-hooks/exhaustive-deps
554
- itemDeps
555
- );
556
- return React.useMemo(() => ({
557
- getReferenceProps,
558
- getFloatingProps,
559
- getItemProps
560
- }), [getReferenceProps, getFloatingProps, getItemProps]);
561
- }
562
- const componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([["select", "listbox"], ["combobox", "listbox"], ["label", false]]);
563
- function useRole(context, props) {
564
- var _componentRoleToAriaR;
565
- if (props === void 0) {
566
- props = {};
567
- }
568
- const {
569
- open,
570
- floatingId
571
- } = context;
572
- const {
573
- enabled = true,
574
- role = "dialog"
575
- } = props;
576
- const ariaRole = (_componentRoleToAriaR = componentRoleToAriaRoleMap.get(role)) != null ? _componentRoleToAriaR : role;
577
- const referenceId = useId();
578
- const parentId = useFloatingParentNodeId();
579
- const isNested = parentId != null;
580
- const reference = React.useMemo(() => {
581
- if (ariaRole === "tooltip" || role === "label") {
582
- return {
583
- ["aria-" + (role === "label" ? "labelledby" : "describedby")]: open ? floatingId : void 0
584
- };
585
- }
586
- return {
587
- "aria-expanded": open ? "true" : "false",
588
- "aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
589
- "aria-controls": open ? floatingId : void 0,
590
- ...ariaRole === "listbox" && {
591
- role: "combobox"
592
- },
593
- ...ariaRole === "menu" && {
594
- id: referenceId
595
- },
596
- ...ariaRole === "menu" && isNested && {
597
- role: "menuitem"
598
- },
599
- ...role === "select" && {
600
- "aria-autocomplete": "none"
601
- },
602
- ...role === "combobox" && {
603
- "aria-autocomplete": "list"
604
- }
605
- };
606
- }, [ariaRole, floatingId, isNested, open, referenceId, role]);
607
- const floating = React.useMemo(() => {
608
- const floatingProps = {
609
- id: floatingId,
610
- ...ariaRole && {
611
- role: ariaRole
612
- }
613
- };
614
- if (ariaRole === "tooltip" || role === "label") {
615
- return floatingProps;
616
- }
617
- return {
618
- ...floatingProps,
619
- ...ariaRole === "menu" && {
620
- "aria-labelledby": referenceId
621
- }
622
- };
623
- }, [ariaRole, floatingId, referenceId, role]);
624
- const item = React.useCallback((_ref) => {
625
- let {
626
- active,
627
- selected
628
- } = _ref;
629
- const commonProps = {
630
- role: "option",
631
- ...active && {
632
- id: floatingId + "-option"
633
- }
634
- };
635
- switch (role) {
636
- case "select":
637
- return {
638
- ...commonProps,
639
- "aria-selected": active && selected
640
- };
641
- case "combobox": {
642
- return {
643
- ...commonProps,
644
- ...active && {
645
- "aria-selected": true
646
- }
647
- };
648
- }
649
- }
650
- return {};
651
- }, [floatingId, role]);
652
- return React.useMemo(() => enabled ? {
653
- reference,
654
- floating,
655
- item
656
- } : {}, [enabled, reference, floating, item]);
657
- }
1
+ import { __module as jsxRuntime } from "./react-text-annotator.es18.js";
2
+ import { __require as requireReactJsxRuntime_production_min } from "./react-text-annotator.es19.js";
3
+ import { __require as requireReactJsxRuntime_development } from "./react-text-annotator.es20.js";
4
+ if (process.env.NODE_ENV === "production") {
5
+ jsxRuntime.exports = requireReactJsxRuntime_production_min();
6
+ } else {
7
+ jsxRuntime.exports = requireReactJsxRuntime_development();
8
+ }
9
+ var jsxRuntimeExports = jsxRuntime.exports;
658
10
  export {
659
- flip,
660
- getOverflowAncestors,
661
- inline,
662
- offset,
663
- shift,
664
- useDismiss,
665
- useFloating,
666
- useFloatingParentNodeId,
667
- useFloatingRootContext,
668
- useFloatingTree,
669
- useId,
670
- useInteractions,
671
- useRole
11
+ jsxRuntimeExports as j
672
12
  };
673
13
  //# sourceMappingURL=react-text-annotator.es9.js.map