@soomo/react-text-annotator 3.0.0-staging.10 → 3.0.0-staging.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"react-text-annotator.es21.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"react-text-annotator.es21.js","sources":["../../../node_modules/CETEIcean/src/behaviors.js"],"sourcesContent":["\n/* \n Add a user-defined set of behaviors to CETEIcean's processing\n workflow. Added behaviors will override predefined behaviors with the\n same name.\n*/\nexport function addBehaviors(bhvs) {\n if (bhvs.namespaces) {\n for (let prefix of Object.keys(bhvs.namespaces)) {\n if (!this.namespaces.has(bhvs.namespaces[prefix]) && !Array.from(this.namespaces.values()).includes(prefix)) {\n this.namespaces.set(bhvs.namespaces[prefix], prefix);\n }\n }\n }\n for (let prefix of this.namespaces.values()) {\n if (bhvs[prefix]) {\n for (let b of Object.keys(bhvs[prefix])) {\n this.behaviors[`${prefix}:${b}`] = bhvs[prefix][b];\n }\n }\n }\n if (bhvs[\"functions\"]) {\n for (let fn of Object.keys(bhvs[\"functions\"])) {\n this.utilities[fn] = bhvs[\"functions\"][fn].bind(this.utilities);\n }\n }\n if (bhvs[\"handlers\"]) {\n console.log(\"Behavior handlers are no longer used.\")\n }\n if (bhvs[\"fallbacks\"]) {\n console.log(\"Fallback behaviors are no longer used.\")\n }\n}\n\n/* \n Adds or replaces an individual behavior. Takes a namespace prefix or namespace definition,\n the element name, and the behavior. E.g.\n addBehavior(\"tei\", \"add\", [\"`\",\"`\"]) for an already-declared namespace or\n addBehavior({\"doc\": \"http://docbook.org/ns/docbook\"}, \"note\", [\"[\",\"]\"]) for a new one\n*/\nexport function addBehavior(ns, element, b) {\n let p;\n if (ns === Object(ns)) {\n for (let prefix of Object.keys(ns)) {\n if (!this.namespaces.has(ns[prefix])) {\n this.namespaces.set(ns[prefix], prefix);\n p = prefix;\n }\n }\n } else {\n p = ns;\n }\n this.behaviors[`${p}:${element}`] = b;\n}\n\n/*\n Removes a previously-defined or default behavior. Takes a namespace prefix or namespace definition\n and the element name.\n*/\nexport function removeBehavior(ns, element) {\n let p;\n if (ns === Object(ns)) {\n for (let prefix of Object.keys(ns)) {\n if (!this.namespaces.has(ns[prefix])) {\n this.namespaces.set(ns[prefix], prefix);\n p = prefix;\n }\n }\n } else {\n p = ns;\n }\n delete this.behaviors[`${p}:${element}`];\n}\n"],"names":[],"mappings":"AAMO,SAAS,aAAa,MAAM;AACjC,MAAI,KAAK,YAAY;AACnB,aAAS,UAAU,OAAO,KAAK,KAAK,UAAU,GAAG;AAC/C,UAAI,CAAC,KAAK,WAAW,IAAI,KAAK,WAAW,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,WAAW,OAAM,CAAE,EAAE,SAAS,MAAM,GAAG;AAC3G,aAAK,WAAW,IAAI,KAAK,WAAW,MAAM,GAAG,MAAM;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AACD,WAAS,UAAU,KAAK,WAAW,OAAM,GAAI;AAC3C,QAAI,KAAK,MAAM,GAAG;AAChB,eAAS,KAAK,OAAO,KAAK,KAAK,MAAM,CAAC,GAAG;AACvC,aAAK,UAAU,GAAG,MAAM,IAAI,CAAC,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;AAAA,MAClD;AAAA,IACF;AAAA,EACF;AACD,MAAI,KAAK,WAAW,GAAG;AACrB,aAAS,MAAM,OAAO,KAAK,KAAK,WAAW,CAAC,GAAG;AAC7C,WAAK,UAAU,EAAE,IAAI,KAAK,WAAW,EAAE,EAAE,EAAE,KAAK,KAAK,SAAS;AAAA,IAC/D;AAAA,EACF;AACD,MAAI,KAAK,UAAU,GAAG;AACpB,YAAQ,IAAI,uCAAuC;AAAA,EACpD;AACD,MAAI,KAAK,WAAW,GAAG;AACrB,YAAQ,IAAI,wCAAwC;AAAA,EACrD;AACH;AAQO,SAAS,YAAY,IAAI,SAAS,GAAG;AAC1C,MAAI;AACJ,MAAI,OAAO,OAAO,EAAE,GAAG;AACrB,aAAS,UAAU,OAAO,KAAK,EAAE,GAAG;AAClC,UAAI,CAAC,KAAK,WAAW,IAAI,GAAG,MAAM,CAAC,GAAG;AACpC,aAAK,WAAW,IAAI,GAAG,MAAM,GAAG,MAAM;AACtC,YAAI;AAAA,MACL;AAAA,IACF;AAAA,EACL,OAAS;AACL,QAAI;AAAA,EACL;AACD,OAAK,UAAU,GAAG,CAAC,IAAI,OAAO,EAAE,IAAI;AACtC;AAMO,SAAS,eAAe,IAAI,SAAS;AAC1C,MAAI;AACJ,MAAI,OAAO,OAAO,EAAE,GAAG;AACrB,aAAS,UAAU,OAAO,KAAK,EAAE,GAAG;AAClC,UAAI,CAAC,KAAK,WAAW,IAAI,GAAG,MAAM,CAAC,GAAG;AACpC,aAAK,WAAW,IAAI,GAAG,MAAM,GAAG,MAAM;AACtC,YAAI;AAAA,MACL;AAAA,IACF;AAAA,EACL,OAAS;AACL,QAAI;AAAA,EACL;AACD,SAAO,KAAK,UAAU,GAAG,CAAC,IAAI,OAAO,EAAE;AACzC;","x_google_ignoreList":[0]}
@@ -1,5 +1,23 @@
1
- var reactJsxRuntime_development = {};
1
+ function learnElementNames(XML_dom, namespaces) {
2
+ const root = XML_dom.documentElement;
3
+ let i = 1;
4
+ let qname = function(e) {
5
+ if (!namespaces.has(e.namespaceURI ? e.namespaceURI : "")) {
6
+ namespaces.set(e.namespaceURI, "ns" + i++);
7
+ }
8
+ return namespaces.get(e.namespaceURI ? e.namespaceURI : "") + ":" + e.localName;
9
+ };
10
+ const els = new Set(
11
+ Array.from(root.querySelectorAll("*"), qname)
12
+ );
13
+ els.add(qname(root));
14
+ return els;
15
+ }
16
+ function learnCustomElementNames(HTML_dom) {
17
+ return new Set(Array.from(HTML_dom.querySelectorAll("*[data-origname]"), (e) => e.localName.replace(/(\w+)-.+/, "$1:") + e.getAttribute("data-origname")));
18
+ }
2
19
  export {
3
- reactJsxRuntime_development as __exports
20
+ learnCustomElementNames,
21
+ learnElementNames
4
22
  };
5
23
  //# sourceMappingURL=react-text-annotator.es22.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-text-annotator.es22.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"react-text-annotator.es22.js","sources":["../../../node_modules/CETEIcean/src/dom.js"],"sourcesContent":["export function learnElementNames(XML_dom, namespaces) {\n const root = XML_dom.documentElement;\n let i = 1;\n let qname = function(e) { \n if (!namespaces.has(e.namespaceURI ? e.namespaceURI : \"\")) {\n namespaces.set(e.namespaceURI, \"ns\" + i++);\n } \n return namespaces.get(e.namespaceURI ? e.namespaceURI : \"\") + \":\" + e.localName;\n };\n const els = new Set(\n Array.from(root.querySelectorAll(\"*\"), qname));\n \n // Add the root element to the array\n els.add(qname(root));\n return els\n}\n\nexport function learnCustomElementNames(HTML_dom) {\n return new Set(Array.from(HTML_dom.querySelectorAll(\"*[data-origname]\"), e => e.localName.replace(/(\\w+)-.+/,\"$1:\") + e.getAttribute(\"data-origname\")));\n}"],"names":[],"mappings":"AAAO,SAAS,kBAAkB,SAAS,YAAY;AACrD,QAAM,OAAO,QAAQ;AACrB,MAAI,IAAI;AACR,MAAI,QAAQ,SAAS,GAAG;AACtB,QAAI,CAAC,WAAW,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG;AACzD,iBAAW,IAAI,EAAE,cAAc,OAAO,GAAG;AAAA,IAC1C;AACD,WAAO,WAAW,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,MAAM,EAAE;AAAA,EAC1E;AACE,QAAM,MAAM,IAAI;AAAA,IACd,MAAM,KAAK,KAAK,iBAAiB,GAAG,GAAG,KAAK;AAAA,EAAC;AAG/C,MAAI,IAAI,MAAM,IAAI,CAAC;AACnB,SAAO;AACT;AAEO,SAAS,wBAAwB,UAAU;AAChD,SAAO,IAAI,IAAI,MAAM,KAAK,SAAS,iBAAiB,kBAAkB,GAAG,OAAK,EAAE,UAAU,QAAQ,YAAW,KAAK,IAAI,EAAE,aAAa,eAAe,CAAC,CAAC;AACxJ;","x_google_ignoreList":[0]}
@@ -86,25 +86,74 @@ const useFloatingParentNodeId = () => {
86
86
  return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
87
87
  };
88
88
  const useFloatingTree = () => React.useContext(FloatingTreeContext);
89
+ function useFloatingRootContext(options) {
90
+ const {
91
+ open = false,
92
+ onOpenChange: onOpenChangeProp,
93
+ elements: elementsProp
94
+ } = options;
95
+ const floatingId = useId();
96
+ const dataRef = React.useRef({});
97
+ const [events] = React.useState(() => createPubSub());
98
+ const nested = useFloatingParentNodeId() != null;
99
+ if (process.env.NODE_ENV !== "production") {
100
+ const optionDomReference = elementsProp.reference;
101
+ if (optionDomReference && !isElement(optionDomReference)) {
102
+ error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
103
+ }
104
+ }
105
+ const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
106
+ const onOpenChange = useEffectEvent((open2, event, reason) => {
107
+ dataRef.current.openEvent = open2 ? event : void 0;
108
+ events.emit("openchange", {
109
+ open: open2,
110
+ event,
111
+ reason,
112
+ nested
113
+ });
114
+ onOpenChangeProp == null || onOpenChangeProp(open2, event, reason);
115
+ });
116
+ const refs = React.useMemo(() => ({
117
+ setPositionReference
118
+ }), []);
119
+ const elements = React.useMemo(() => ({
120
+ reference: positionReference || elementsProp.reference || null,
121
+ floating: elementsProp.floating || null,
122
+ domReference: elementsProp.reference
123
+ }), [positionReference, elementsProp.reference, elementsProp.floating]);
124
+ return React.useMemo(() => ({
125
+ dataRef,
126
+ open,
127
+ onOpenChange,
128
+ elements,
129
+ events,
130
+ floatingId,
131
+ refs
132
+ }), [open, onOpenChange, elements, events, floatingId, refs]);
133
+ }
89
134
  function useFloating(options) {
90
- var _options$elements;
91
135
  if (options === void 0) {
92
136
  options = {};
93
137
  }
94
138
  const {
95
- open = false,
96
- onOpenChange: unstable_onOpenChange,
97
139
  nodeId
98
140
  } = options;
141
+ const internalRootContext = useFloatingRootContext({
142
+ ...options,
143
+ elements: {
144
+ reference: null,
145
+ floating: null,
146
+ ...options.elements
147
+ }
148
+ });
149
+ const rootContext = options.rootContext || internalRootContext;
150
+ const computedElements = rootContext.elements;
99
151
  const [_domReference, setDomReference] = React.useState(null);
100
152
  const [positionReference, _setPositionReference] = React.useState(null);
101
- const optionDomReference = (_options$elements = options.elements) == null ? void 0 : _options$elements.reference;
153
+ const optionDomReference = computedElements == null ? void 0 : computedElements.reference;
102
154
  const domReference = optionDomReference || _domReference;
103
- if (process.env.NODE_ENV !== "production") {
104
- if (optionDomReference && !isElement(optionDomReference)) {
105
- error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
106
- }
107
- }
155
+ const domReferenceRef = React.useRef(null);
156
+ const tree = useFloatingTree();
108
157
  index(() => {
109
158
  if (domReference) {
110
159
  domReferenceRef.current = domReference;
@@ -113,28 +162,12 @@ function useFloating(options) {
113
162
  const position = useFloating$1({
114
163
  ...options,
115
164
  elements: {
116
- ...options.elements,
165
+ ...computedElements,
117
166
  ...positionReference && {
118
167
  reference: positionReference
119
168
  }
120
169
  }
121
170
  });
122
- const tree = useFloatingTree();
123
- const nested = useFloatingParentNodeId() != null;
124
- const onOpenChange = useEffectEvent((open2, event, reason) => {
125
- dataRef.current.openEvent = open2 ? event : void 0;
126
- events.emit("openchange", {
127
- open: open2,
128
- event,
129
- reason,
130
- nested
131
- });
132
- unstable_onOpenChange == null || unstable_onOpenChange(open2, event, reason);
133
- });
134
- const domReferenceRef = React.useRef(null);
135
- const dataRef = React.useRef({});
136
- const events = React.useState(() => createPubSub())[0];
137
- const floatingId = useId();
138
171
  const setPositionReference = React.useCallback((node) => {
139
172
  const computedPositionReference = isElement(node) ? {
140
173
  getBoundingClientRect: () => node.getBoundingClientRect(),
@@ -167,16 +200,13 @@ function useFloating(options) {
167
200
  }), [position.elements, domReference]);
168
201
  const context = React.useMemo(() => ({
169
202
  ...position,
203
+ ...rootContext,
170
204
  refs,
171
205
  elements,
172
- dataRef,
173
- nodeId,
174
- floatingId,
175
- events,
176
- open,
177
- onOpenChange
178
- }), [position, nodeId, floatingId, events, open, onOpenChange, refs, elements]);
206
+ nodeId
207
+ }), [position, refs, elements, nodeId, rootContext]);
179
208
  index(() => {
209
+ rootContext.dataRef.current.floatingContext = context;
180
210
  const node = tree == null ? void 0 : tree.nodesRef.current.find((node2) => node2.id === nodeId);
181
211
  if (node) {
182
212
  node.context = context;
@@ -193,6 +223,7 @@ export {
193
223
  getOverflowAncestors,
194
224
  useFloating,
195
225
  useFloatingParentNodeId,
226
+ useFloatingRootContext,
196
227
  useFloatingTree,
197
228
  useId
198
229
  };