@soomo/react-text-annotator 3.0.0-staging.1
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/TextAnnotator.d.ts +13 -0
- package/dist/TextAnnotator.d.ts.map +1 -0
- package/dist/TextAnnotatorPlugin.d.ts +5 -0
- package/dist/TextAnnotatorPlugin.d.ts.map +1 -0
- package/dist/TextAnnotatorPopup.d.ts +13 -0
- package/dist/TextAnnotatorPopup.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/react-text-annotator.css +1 -0
- package/dist/react-text-annotator.es.js +13 -0
- package/dist/react-text-annotator.es.js.map +1 -0
- package/dist/react-text-annotator.es10.js +38 -0
- package/dist/react-text-annotator.es10.js.map +1 -0
- package/dist/react-text-annotator.es11.js +892 -0
- package/dist/react-text-annotator.es11.js.map +1 -0
- package/dist/react-text-annotator.es12.js +117 -0
- package/dist/react-text-annotator.es12.js.map +1 -0
- package/dist/react-text-annotator.es13.js +312 -0
- package/dist/react-text-annotator.es13.js.map +1 -0
- package/dist/react-text-annotator.es14.js +61 -0
- package/dist/react-text-annotator.es14.js.map +1 -0
- package/dist/react-text-annotator.es15.js +23 -0
- package/dist/react-text-annotator.es15.js.map +1 -0
- package/dist/react-text-annotator.es16.js +5 -0
- package/dist/react-text-annotator.es16.js.map +1 -0
- package/dist/react-text-annotator.es17.js +5 -0
- package/dist/react-text-annotator.es17.js.map +1 -0
- package/dist/react-text-annotator.es2.js +64 -0
- package/dist/react-text-annotator.es2.js.map +1 -0
- package/dist/react-text-annotator.es3.js +29 -0
- package/dist/react-text-annotator.es3.js.map +1 -0
- package/dist/react-text-annotator.es4.js +33 -0
- package/dist/react-text-annotator.es4.js.map +1 -0
- package/dist/react-text-annotator.es5.js +53 -0
- package/dist/react-text-annotator.es5.js.map +1 -0
- package/dist/react-text-annotator.es6.js +13 -0
- package/dist/react-text-annotator.es6.js.map +1 -0
- package/dist/react-text-annotator.es7.js +2 -0
- package/dist/react-text-annotator.es7.js.map +1 -0
- package/dist/react-text-annotator.es8.js +491 -0
- package/dist/react-text-annotator.es8.js.map +1 -0
- package/dist/react-text-annotator.es9.js +5 -0
- package/dist/react-text-annotator.es9.js.map +1 -0
- package/dist/tei/CETEIcean.d.ts +8 -0
- package/dist/tei/CETEIcean.d.ts.map +1 -0
- package/dist/tei/TEIAnnotator.d.ts +10 -0
- package/dist/tei/TEIAnnotator.d.ts.map +1 -0
- package/dist/tei/index.d.ts +3 -0
- package/dist/tei/index.d.ts.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function addBehaviors(bhvs) {
|
|
2
|
+
if (bhvs.namespaces) {
|
|
3
|
+
for (let prefix of Object.keys(bhvs.namespaces)) {
|
|
4
|
+
if (!this.namespaces.has(bhvs.namespaces[prefix]) && !Array.from(this.namespaces.values()).includes(prefix)) {
|
|
5
|
+
this.namespaces.set(bhvs.namespaces[prefix], prefix);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
for (let prefix of this.namespaces.values()) {
|
|
10
|
+
if (bhvs[prefix]) {
|
|
11
|
+
for (let b of Object.keys(bhvs[prefix])) {
|
|
12
|
+
this.behaviors[`${prefix}:${b}`] = bhvs[prefix][b];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (bhvs["functions"]) {
|
|
17
|
+
for (let fn of Object.keys(bhvs["functions"])) {
|
|
18
|
+
this.utilities[fn] = bhvs["functions"][fn].bind(this.utilities);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (bhvs["handlers"]) {
|
|
22
|
+
console.log("Behavior handlers are no longer used.");
|
|
23
|
+
}
|
|
24
|
+
if (bhvs["fallbacks"]) {
|
|
25
|
+
console.log("Fallback behaviors are no longer used.");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function addBehavior(ns, element, b) {
|
|
29
|
+
let p;
|
|
30
|
+
if (ns === Object(ns)) {
|
|
31
|
+
for (let prefix of Object.keys(ns)) {
|
|
32
|
+
if (!this.namespaces.has(ns[prefix])) {
|
|
33
|
+
this.namespaces.set(ns[prefix], prefix);
|
|
34
|
+
p = prefix;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
p = ns;
|
|
39
|
+
}
|
|
40
|
+
this.behaviors[`${p}:${element}`] = b;
|
|
41
|
+
}
|
|
42
|
+
function removeBehavior(ns, element) {
|
|
43
|
+
let p;
|
|
44
|
+
if (ns === Object(ns)) {
|
|
45
|
+
for (let prefix of Object.keys(ns)) {
|
|
46
|
+
if (!this.namespaces.has(ns[prefix])) {
|
|
47
|
+
this.namespaces.set(ns[prefix], prefix);
|
|
48
|
+
p = prefix;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
p = ns;
|
|
53
|
+
}
|
|
54
|
+
delete this.behaviors[`${p}:${element}`];
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
addBehavior,
|
|
58
|
+
addBehaviors,
|
|
59
|
+
removeBehavior
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=react-text-annotator.es14.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es14.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,KA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,UAAU,GAAG,CAAC,IAAI,OAAO,EAAE;AACzC;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
learnCustomElementNames,
|
|
21
|
+
learnElementNames
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=react-text-annotator.es15.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es15.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]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es16.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es17.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "./react-text-annotator.es6.js";
|
|
2
|
+
import { useRef, useEffect } from "react";
|
|
3
|
+
import CETEI from "./react-text-annotator.es8.js";
|
|
4
|
+
const PRESET_BEHAVIORS = {
|
|
5
|
+
tei: {
|
|
6
|
+
ref: (elem) => {
|
|
7
|
+
const a = document.createElement("a");
|
|
8
|
+
while (elem.firstChild) {
|
|
9
|
+
a.appendChild(elem.removeChild(elem.firstChild));
|
|
10
|
+
}
|
|
11
|
+
a.setAttribute("href", elem.getAttribute("target"));
|
|
12
|
+
elem.appendChild(a);
|
|
13
|
+
},
|
|
14
|
+
// Cf. https://github.com/TEIC/CETEIcean/issues/67
|
|
15
|
+
graphic: (elem) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const content = new Image();
|
|
18
|
+
content.src = (_a = elem.getAttribute("url")) == null ? void 0 : _a.trim();
|
|
19
|
+
if (elem.hasAttribute("width"))
|
|
20
|
+
content.setAttribute("width", elem.getAttribute("width"));
|
|
21
|
+
if (elem.hasAttribute("height"))
|
|
22
|
+
content.setAttribute("height", elem.getAttribute("height"));
|
|
23
|
+
elem.appendChild(content);
|
|
24
|
+
},
|
|
25
|
+
list: null,
|
|
26
|
+
note: null,
|
|
27
|
+
table: null,
|
|
28
|
+
teiHeader: (elem) => {
|
|
29
|
+
elem.hidden = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const CETEIcean = (props) => {
|
|
34
|
+
const el = useRef(null);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
var _a;
|
|
37
|
+
if (props.tei) {
|
|
38
|
+
const ceteicean = new CETEI();
|
|
39
|
+
ceteicean.addBehaviors({
|
|
40
|
+
...PRESET_BEHAVIORS,
|
|
41
|
+
...props.behaviors || {},
|
|
42
|
+
tei: {
|
|
43
|
+
...PRESET_BEHAVIORS.tei,
|
|
44
|
+
...((_a = props.behaviors) == null ? void 0 : _a.tei) || {}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
ceteicean.makeHTML5(props.tei, (data) => {
|
|
48
|
+
el.current.appendChild(data);
|
|
49
|
+
props.onLoad(el.current);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, [props.tei]);
|
|
53
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
54
|
+
"div",
|
|
55
|
+
{
|
|
56
|
+
ref: el,
|
|
57
|
+
className: "tei-container"
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
export {
|
|
62
|
+
CETEIcean
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=react-text-annotator.es2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es2.js","sources":["../src/tei/CETEIcean.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport CETEI from 'CETEIcean';\n\ninterface CETEIceanProps {\n\n tei?: string;\n\n onLoad?(element: Element): void;\n\n behaviors?: any;\n\n}\n\n// Override default list, note, table, and ref behaviors \n// so they don't introduce text into the DOM that interferes\n// with annotation. Apply a patch to graphics for robustness.\nconst PRESET_BEHAVIORS = {\n tei: {\n ref: (elem: Element) => {\n const a = document.createElement('a');\n\n while(elem.firstChild) {\n a.appendChild(elem.removeChild(elem.firstChild));\n }\n\n a.setAttribute('href', elem.getAttribute('target'));\n\n elem.appendChild(a);\n },\n // Cf. https://github.com/TEIC/CETEIcean/issues/67\n graphic: (elem: Element) => {\n const content = new Image();\n content.src = elem.getAttribute('url')?.trim();\n\n if (elem.hasAttribute('width'))\n content.setAttribute('width', elem.getAttribute('width'));\n\n if (elem.hasAttribute('height'))\n content.setAttribute('height', elem.getAttribute('height'));\n\n elem.appendChild(content);\n },\n list: null,\n note: null,\n table: null,\n teiHeader: (elem: HTMLElement) => {\n elem.hidden = true;\n }\n }\n}\n\nexport const CETEIcean = (props: CETEIceanProps) => {\n\n const el = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (props.tei) {\n const ceteicean = new CETEI();\n\n ceteicean.addBehaviors({\n ...PRESET_BEHAVIORS,\n ...(props.behaviors || {}),\n tei: {\n ...PRESET_BEHAVIORS.tei,\n ...(props.behaviors?.tei || {})\n }\n });\n\n ceteicean.makeHTML5(props.tei, (data: Element) => {\n el.current.appendChild(data);\n props.onLoad(el.current);\n });\n }\n }, [props.tei]);\n\n return (\n <div \n ref={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A,IACH;AAAA,EAAA,GACC,CAAC,MAAM,GAAG,CAAC;AAGZ,SAAAA,kCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,WAAU;AAAA,IAAA;AAAA,EAAA;AAGhB;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "./react-text-annotator.es6.js";
|
|
2
|
+
import { useContext, useEffect, Children, cloneElement } from "react";
|
|
3
|
+
import { AnnotoriousContext } from "@annotorious/react";
|
|
4
|
+
import { TEIPlugin } from "@recogito/text-annotator-tei";
|
|
5
|
+
import { createTextAnnotator } from "@soomo/text-annotator";
|
|
6
|
+
import "./react-text-annotator.es7.js";
|
|
7
|
+
const TEIAnnotator = (props) => {
|
|
8
|
+
const { children, ...opts } = props;
|
|
9
|
+
const { anno, setAnno } = useContext(AnnotoriousContext);
|
|
10
|
+
const onLoad = (element) => {
|
|
11
|
+
const anno2 = TEIPlugin(createTextAnnotator(element, opts));
|
|
12
|
+
setAnno(anno2);
|
|
13
|
+
};
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!anno)
|
|
16
|
+
return;
|
|
17
|
+
anno.setStyle(props.style);
|
|
18
|
+
}, [props.style]);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!anno)
|
|
21
|
+
return;
|
|
22
|
+
anno.setFilter(props.filter);
|
|
23
|
+
}, [props.filter]);
|
|
24
|
+
return props.children ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: Children.toArray(props.children).map((child) => cloneElement(child, { onLoad })) }) : null;
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
TEIAnnotator
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=react-text-annotator.es3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es3.js","sources":["../src/tei/TEIAnnotator.tsx"],"sourcesContent":["import { Children, cloneElement, ReactElement, ReactNode, useContext, useEffect } from 'react';\nimport { AnnotoriousContext, Filter } from '@annotorious/react';\nimport { TEIPlugin } from '@recogito/text-annotator-tei';\nimport type { TextAnnotatorOptions } from '@soomo/text-annotator';\nimport { createTextAnnotator } from '@soomo/text-annotator';\n\nimport '@soomo/text-annotator/dist/text-annotator.css';\n\nexport type TEIAnnotatorProps = TextAnnotatorOptions & {\n\n children?: ReactNode | JSX.Element;\n\n filter?: Filter;\n\n}\n\nexport const TEIAnnotator = (props: TEIAnnotatorProps) => {\n\n const { children, ...opts } = props;\n\n const { anno, setAnno } = useContext(AnnotoriousContext);\n\n const onLoad = (element: HTMLElement) => {\n const anno = TEIPlugin(createTextAnnotator(element, opts));\n setAnno(anno);\n }\n\n useEffect(() => {\n if (!anno)\n return;\n \n anno.setStyle(props.style);\n }, [props.style]);\n\n useEffect(() => {\n if (!anno)\n return;\n \n anno.setFilter(props.filter);\n }, [props.filter]);\n\n return props.children ? (\n <>\n {Children.toArray(props.children).map(child => \n cloneElement(child as ReactElement, { onLoad }))}\n </>\n ) : null;\n\n}\n"],"names":["anno","jsx","Fragment"],"mappings":";;;;;;AAgBa,MAAA,eAAe,CAAC,UAA6B;AAExD,QAAM,EAAE,UAAU,GAAG,KAAA,IAAS;AAE9B,QAAM,EAAE,MAAM,QAAQ,IAAI,WAAW,kBAAkB;AAEjD,QAAA,SAAS,CAAC,YAAyB;AACvC,UAAMA,QAAO,UAAU,oBAAoB,SAAS,IAAI,CAAC;AACzD,YAAQA,KAAI;AAAA,EAAA;AAGd,YAAU,MAAM;AACd,QAAI,CAAC;AACH;AAEG,SAAA,SAAS,MAAM,KAAK;AAAA,EAAA,GACxB,CAAC,MAAM,KAAK,CAAC;AAEhB,YAAU,MAAM;AACd,QAAI,CAAC;AACH;AAEG,SAAA,UAAU,MAAM,MAAM;AAAA,EAAA,GAC1B,CAAC,MAAM,MAAM,CAAC;AAEjB,SAAO,MAAM,WACXC,sCAAAC,kBAAAA,UAAA,EACG,UAAS,SAAA,QAAQ,MAAM,QAAQ,EAAE,IAAI,CAAA,UACpC,aAAa,OAAuB,EAAE,QAAQ,CAAC,GACnD,IACE;AAEN;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "./react-text-annotator.es6.js";
|
|
2
|
+
import { useRef, useContext, useEffect } from "react";
|
|
3
|
+
import { AnnotoriousContext } from "@annotorious/react";
|
|
4
|
+
import { createTextAnnotator } from "@soomo/text-annotator";
|
|
5
|
+
import "./react-text-annotator.es7.js";
|
|
6
|
+
const TextAnnotator = (props) => {
|
|
7
|
+
const el = useRef(null);
|
|
8
|
+
const { className, children, ...opts } = props;
|
|
9
|
+
const { anno, setAnno } = useContext(AnnotoriousContext);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!setAnno)
|
|
12
|
+
return;
|
|
13
|
+
const adapter = typeof opts.adapter === "function" ? opts.adapter(el.current) : opts.adapter;
|
|
14
|
+
const anno2 = createTextAnnotator(el.current, { ...opts, adapter });
|
|
15
|
+
setAnno(anno2);
|
|
16
|
+
return () => anno2.destroy();
|
|
17
|
+
}, [setAnno]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!anno)
|
|
20
|
+
return;
|
|
21
|
+
anno.setStyle(props.style);
|
|
22
|
+
}, [anno, props.style]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!anno)
|
|
25
|
+
return;
|
|
26
|
+
anno.setFilter(props.filter);
|
|
27
|
+
}, [anno, props.filter]);
|
|
28
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: el, className, children });
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
TextAnnotator
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=react-text-annotator.es4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es4.js","sources":["../src/TextAnnotator.tsx"],"sourcesContent":["import { ReactNode, useContext, useEffect, useRef } from 'react';\nimport { AnnotoriousContext, Filter, FormatAdapter } from '@annotorious/react';\nimport type { HighlightStyleExpression, TextAnnotation, TextAnnotatorOptions } from '@soomo/text-annotator';\nimport { createTextAnnotator } from '@soomo/text-annotator';\n\nimport '@soomo/text-annotator/dist/text-annotator.css';\n\nexport interface TextAnnotatorProps<E extends unknown> extends Omit<TextAnnotatorOptions<E>, 'adapter'> {\n\n children?: ReactNode | JSX.Element;\n\n adapter?: FormatAdapter<TextAnnotation, E> | ((container: HTMLElement) => FormatAdapter<TextAnnotation, E>) | null;\n\n filter?: Filter;\n\n style?: HighlightStyleExpression;\n\n className?: string;\n\n}\n\nexport const TextAnnotator = <E extends unknown>(props: TextAnnotatorProps<E>) => {\n\n const el = useRef<HTMLDivElement>(null);\n\n const { className, children, ...opts } = props;\n\n const { anno, setAnno } = useContext(AnnotoriousContext);\n\n useEffect(() => {\n if (!setAnno) return;\n\n const adapter = typeof opts.adapter === 'function' ? opts.adapter(el.current) : opts.adapter;\n\n const anno = createTextAnnotator(el.current, { ...opts, adapter });\n setAnno(anno);\n\n return () => anno.destroy();\n }, [setAnno]);\n\n useEffect(() => {\n if (!anno) return;\n\n anno.setStyle(props.style);\n }, [anno, props.style]);\n\n useEffect(() => {\n if (!anno) return;\n \n anno.setFilter(props.filter);\n }, [anno, props.filter]);\n\n return (\n <div ref={el} className={className}>\n {children}\n </div>\n )\n\n}\n"],"names":["anno","jsx"],"mappings":";;;;;AAqBa,MAAA,gBAAgB,CAAoB,UAAiC;AAE1E,QAAA,KAAK,OAAuB,IAAI;AAEtC,QAAM,EAAE,WAAW,UAAU,GAAG,SAAS;AAEzC,QAAM,EAAE,MAAM,QAAQ,IAAI,WAAW,kBAAkB;AAEvD,YAAU,MAAM;AACd,QAAI,CAAC;AAAS;AAER,UAAA,UAAU,OAAO,KAAK,YAAY,aAAa,KAAK,QAAQ,GAAG,OAAO,IAAI,KAAK;AAE/EA,UAAAA,QAAO,oBAAoB,GAAG,SAAS,EAAE,GAAG,MAAM,SAAS;AACjE,YAAQA,KAAI;AAEL,WAAA,MAAMA,MAAK;EAAQ,GACzB,CAAC,OAAO,CAAC;AAEZ,YAAU,MAAM;AACd,QAAI,CAAC;AAAM;AAEN,SAAA,SAAS,MAAM,KAAK;AAAA,EACxB,GAAA,CAAC,MAAM,MAAM,KAAK,CAAC;AAEtB,YAAU,MAAM;AACd,QAAI,CAAC;AAAM;AAEN,SAAA,UAAU,MAAM,MAAM;AAAA,EAC1B,GAAA,CAAC,MAAM,MAAM,MAAM,CAAC;AAEvB,SACGC,kCAAAA,IAAA,OAAA,EAAI,KAAK,IAAI,WACX,SACH,CAAA;AAGJ;"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "./react-text-annotator.es6.js";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import { useRef, useState, useEffect } from "react";
|
|
4
|
+
import { useAnnotator, useSelection } from "@annotorious/react";
|
|
5
|
+
const TextAnnotatorPopup = (props) => {
|
|
6
|
+
const el = useRef(null);
|
|
7
|
+
const r = useAnnotator();
|
|
8
|
+
const [open, setOpen] = useState(false);
|
|
9
|
+
const { selected, pointerEvent } = useSelection();
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (pointerEvent) {
|
|
12
|
+
if (selected.length > 0 && pointerEvent.type === "pointerup") {
|
|
13
|
+
setOpen(true);
|
|
14
|
+
} else {
|
|
15
|
+
setOpen(false);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}, [pointerEvent, selected.map((a) => a.annotation.id).join("-")]);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!(pointerEvent && open && (r == null ? void 0 : r.element)))
|
|
21
|
+
return;
|
|
22
|
+
const { left, top } = r.element.getBoundingClientRect();
|
|
23
|
+
let x = pointerEvent.clientX - left;
|
|
24
|
+
let y = pointerEvent.clientY - top;
|
|
25
|
+
const { id } = selected[0].annotation;
|
|
26
|
+
const { offsetX, offsetY } = pointerEvent;
|
|
27
|
+
const bounds = r.state.store.getAnnotationBounds(id, offsetX, offsetY);
|
|
28
|
+
if (bounds) {
|
|
29
|
+
x = Math.max(x, bounds.x - left);
|
|
30
|
+
x = Math.min(x, bounds.right - left);
|
|
31
|
+
}
|
|
32
|
+
el.current.style.left = `${x}px`;
|
|
33
|
+
el.current.style.top = `${y}px`;
|
|
34
|
+
}, [open, pointerEvent, r == null ? void 0 : r.element]);
|
|
35
|
+
const onPointerUp = (evt) => evt.stopPropagation();
|
|
36
|
+
return open && selected.length > 0 ? createPortal(
|
|
37
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
38
|
+
"div",
|
|
39
|
+
{
|
|
40
|
+
ref: el,
|
|
41
|
+
className: "a9s-popup r6o-popup not-annotatable",
|
|
42
|
+
style: { position: "absolute" },
|
|
43
|
+
onPointerUp,
|
|
44
|
+
children: props.popup({ selected })
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
r.element
|
|
48
|
+
) : null;
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
TextAnnotatorPopup
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=react-text-annotator.es5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es5.js","sources":["../src/TextAnnotatorPopup.tsx"],"sourcesContent":["import { createPortal } from 'react-dom';\nimport { ReactNode, useEffect, useRef, useState } from 'react';\nimport { TextAnnotator, TextAnnotation, TextAnnotatorState } from '@soomo/text-annotator';\nimport { useAnnotator, useSelection } from '@annotorious/react';\n\nexport interface TextAnnotatorPopupProps {\n\n selected: { annotation: TextAnnotation, editable?: boolean }[];\n\n}\n\nexport interface TextAnnotatorPopupContainerProps {\n\n popup(props: TextAnnotatorPopupProps): ReactNode | JSX.Element;\n\n}\n\nexport const TextAnnotatorPopup = (props: TextAnnotatorPopupContainerProps) => {\n\n const el = useRef<HTMLDivElement>(null);\n\n const r = useAnnotator<TextAnnotator>();\n\n const [open, setOpen] = useState(false);\n\n const { selected, pointerEvent } = useSelection<TextAnnotation>();\n\n useEffect(() => {\n // Ignore all selection changes except those\n // accompanied by a pointer event.\n if (pointerEvent) {\n if (selected.length > 0 && pointerEvent.type === 'pointerup') {\n setOpen(true);\n } else {\n setOpen(false);\n }\n }\n }, [pointerEvent, selected.map(a => a.annotation.id).join('-')]);\n\n useEffect(() => {\n if (!(pointerEvent && open && r?.element))\n return;\n\n const { left, top } = r.element.getBoundingClientRect();\n let x = pointerEvent.clientX - left;\n let y = pointerEvent.clientY - top;\n\n const { id } = selected[0].annotation;\n const { offsetX, offsetY } = pointerEvent;\n const bounds = (r.state as TextAnnotatorState).store.getAnnotationBounds(id, offsetX, offsetY);\n \n if (bounds) {\n x = Math.max(x, bounds.x - left);\n x = Math.min(x, bounds.right - left);\n }\n\n el.current.style.left = `${x}px`;\n el.current.style.top = `${y}px`;\n }, [open, pointerEvent, r?.element]);\n\n const onPointerUp = (evt: React.PointerEvent<HTMLDivElement>) =>\n evt.stopPropagation();\n \n return (open && selected.length > 0) ? createPortal(\n <div \n ref={el}\n className=\"a9s-popup r6o-popup not-annotatable\"\n style={{ position: 'absolute' }}\n onPointerUp={onPointerUp}>\n\n {props.popup({ selected })}\n \n </div>, r.element\n ) : null;\n\n}\n"],"names":["jsx"],"mappings":";;;;AAiBa,MAAA,qBAAqB,CAAC,UAA4C;AAEvE,QAAA,KAAK,OAAuB,IAAI;AAEtC,QAAM,IAAI;AAEV,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AAEtC,QAAM,EAAE,UAAU,aAAa,IAAI,aAA6B;AAEhE,YAAU,MAAM;AAGd,QAAI,cAAc;AAChB,UAAI,SAAS,SAAS,KAAK,aAAa,SAAS,aAAa;AAC5D,gBAAQ,IAAI;AAAA,MAAA,OACP;AACL,gBAAQ,KAAK;AAAA,MACf;AAAA,IACF;AAAA,EACC,GAAA,CAAC,cAAc,SAAS,IAAI,CAAA,MAAK,EAAE,WAAW,EAAE,EAAE,KAAK,GAAG,CAAC,CAAC;AAE/D,YAAU,MAAM;AACV,QAAA,EAAE,gBAAgB,SAAQ,uBAAG;AAC/B;AAEF,UAAM,EAAE,MAAM,IAAA,IAAQ,EAAE,QAAQ;AAC5B,QAAA,IAAI,aAAa,UAAU;AAC3B,QAAA,IAAI,aAAa,UAAU;AAE/B,UAAM,EAAE,GAAO,IAAA,SAAS,CAAC,EAAE;AACrB,UAAA,EAAE,SAAS,QAAY,IAAA;AAC7B,UAAM,SAAU,EAAE,MAA6B,MAAM,oBAAoB,IAAI,SAAS,OAAO;AAE7F,QAAI,QAAQ;AACV,UAAI,KAAK,IAAI,GAAG,OAAO,IAAI,IAAI;AAC/B,UAAI,KAAK,IAAI,GAAG,OAAO,QAAQ,IAAI;AAAA,IACrC;AAEA,OAAG,QAAQ,MAAM,OAAO,GAAG,CAAC;AAC5B,OAAG,QAAQ,MAAM,MAAM,GAAG,CAAC;AAAA,KAC1B,CAAC,MAAM,cAAc,uBAAG,OAAO,CAAC;AAEnC,QAAM,cAAc,CAAC,QACnB,IAAI,gBAAgB;AAEd,SAAA,QAAQ,SAAS,SAAS,IAAK;AAAA,IACrCA,kCAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAK;AAAA,QACL,WAAU;AAAA,QACV,OAAO,EAAE,UAAU,WAAW;AAAA,QAC9B;AAAA,QAEC,UAAM,MAAA,MAAM,EAAE,SAAA,CAAU;AAAA,MAAA;AAAA,IAE3B;AAAA,IAAQ,EAAE;AAAA,EACR,IAAA;AAEN;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __module as jsxRuntime } from "./react-text-annotator.es9.js";
|
|
2
|
+
import { __require as requireReactJsxRuntime_production_min } from "./react-text-annotator.es10.js";
|
|
3
|
+
import { __require as requireReactJsxRuntime_development } from "./react-text-annotator.es11.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;
|
|
10
|
+
export {
|
|
11
|
+
jsxRuntimeExports as j
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=react-text-annotator.es6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es6.js","sources":["../../../node_modules/react/jsx-runtime.js"],"sourcesContent":["'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-jsx-runtime.production.min.js');\n} else {\n module.exports = require('./cjs/react-jsx-runtime.development.js');\n}\n"],"names":["jsxRuntimeModule","require$$0","require$$1"],"mappings":";;;AAEA,IAAI,QAAQ,IAAI,aAAa,cAAc;AACzCA,aAAA,UAAiBC;AACnB,OAAO;AACLD,aAAA,UAAiBE;AACnB;;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-text-annotator.es7.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|