@matdata/yasr 4.7.5 → 4.8.0
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/build/ts/src/bindingsToCsv.js +14 -0
- package/build/ts/src/bindingsToCsv.js.map +1 -0
- package/build/ts/src/defaults.js +28 -0
- package/build/ts/src/defaults.js.map +1 -0
- package/build/ts/src/helpers/addCSS.js +8 -0
- package/build/ts/src/helpers/addCSS.js.map +1 -0
- package/build/ts/src/helpers/addScript.js +13 -0
- package/build/ts/src/helpers/addScript.js.map +1 -0
- package/build/ts/src/helpers/index.js +4 -0
- package/build/ts/src/helpers/index.js.map +1 -0
- package/build/ts/src/helpers/sanitize.js +9 -0
- package/build/ts/src/helpers/sanitize.js.map +1 -0
- package/build/ts/src/imgs.js +5 -0
- package/build/ts/src/imgs.js.map +1 -0
- package/build/ts/src/index.d.ts +3 -2
- package/build/ts/src/index.js +581 -0
- package/build/ts/src/index.js.map +1 -0
- package/build/ts/src/parsers/csv.js +26 -0
- package/build/ts/src/parsers/csv.js.map +1 -0
- package/build/ts/src/parsers/index.js +267 -0
- package/build/ts/src/parsers/index.js.map +1 -0
- package/build/ts/src/parsers/json.js +21 -0
- package/build/ts/src/parsers/json.js.map +1 -0
- package/build/ts/src/parsers/tsv.js +40 -0
- package/build/ts/src/parsers/tsv.js.map +1 -0
- package/build/ts/src/parsers/turtleFamily.js +58 -0
- package/build/ts/src/parsers/turtleFamily.js.map +1 -0
- package/build/ts/src/parsers/xml.js +77 -0
- package/build/ts/src/parsers/xml.js.map +1 -0
- package/build/ts/src/plugins/boolean/index.d.ts +1 -0
- package/build/ts/src/plugins/boolean/index.js +31 -0
- package/build/ts/src/plugins/boolean/index.js.map +1 -0
- package/build/ts/src/plugins/error/index.d.ts +1 -0
- package/build/ts/src/plugins/error/index.js +123 -0
- package/build/ts/src/plugins/error/index.js.map +1 -0
- package/build/ts/src/plugins/index.js +2 -0
- package/build/ts/src/plugins/index.js.map +1 -0
- package/build/ts/src/plugins/response/index.d.ts +9 -0
- package/build/ts/src/plugins/response/index.js +139 -0
- package/build/ts/src/plugins/response/index.js.map +1 -0
- package/build/ts/src/plugins/table/index.d.ts +3 -0
- package/build/ts/src/plugins/table/index.js +350 -0
- package/build/ts/src/plugins/table/index.js.map +1 -0
- package/build/yasr.min.css +2 -2
- package/build/yasr.min.css.map +7 -1
- package/build/yasr.min.js +103 -3
- package/build/yasr.min.js.map +7 -1
- package/package.json +1 -1
- package/src/index.ts +3 -3
- package/src/jquery/extendJquery.js +1 -1
- package/src/jquery/tableToCsv.js +2 -2
- package/src/plugins/boolean/index.ts +1 -1
- package/src/plugins/error/index.ts +1 -1
- package/src/plugins/response/index.ts +10 -10
- package/src/plugins/table/index.ts +4 -4
- package/build/yasr.html +0 -32
- package/build/yasr.min.js.LICENSE.txt +0 -34
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { addClass } from "@matdata/yasgui-utils";
|
|
11
|
+
import "./index.scss";
|
|
12
|
+
export default class Error {
|
|
13
|
+
constructor(yasr) {
|
|
14
|
+
this.priority = 20;
|
|
15
|
+
this.hideFromSelection = true;
|
|
16
|
+
this.yasr = yasr;
|
|
17
|
+
}
|
|
18
|
+
canHandleResults() {
|
|
19
|
+
return !!this.yasr.results && !!this.yasr.results.getError();
|
|
20
|
+
}
|
|
21
|
+
getTryBtn(link) {
|
|
22
|
+
const tryBtn = document.createElement("a");
|
|
23
|
+
tryBtn.href = link;
|
|
24
|
+
tryBtn.rel = "noopener noreferrer";
|
|
25
|
+
tryBtn.target = "_blank";
|
|
26
|
+
tryBtn.className = "yasr_tryQuery";
|
|
27
|
+
tryBtn.textContent = "Try query in a new browser window";
|
|
28
|
+
return tryBtn;
|
|
29
|
+
}
|
|
30
|
+
getCorsMessage() {
|
|
31
|
+
const corsEl = document.createElement("div");
|
|
32
|
+
corsEl.className = "redOutline";
|
|
33
|
+
const mainMsg = document.createElement("p");
|
|
34
|
+
mainMsg.textContent = "Unable to get response from endpoint. Possible reasons:";
|
|
35
|
+
corsEl.appendChild(mainMsg);
|
|
36
|
+
const list = document.createElement("ul");
|
|
37
|
+
const incorrectEndpoint = document.createElement("li");
|
|
38
|
+
incorrectEndpoint.textContent = "Incorrect endpoint URL";
|
|
39
|
+
list.appendChild(incorrectEndpoint);
|
|
40
|
+
const endpointDown = document.createElement("li");
|
|
41
|
+
endpointDown.textContent = "Endpoint is down";
|
|
42
|
+
list.appendChild(endpointDown);
|
|
43
|
+
const cors = document.createElement("li");
|
|
44
|
+
const firstPart = document.createElement("span");
|
|
45
|
+
firstPart.textContent = "Endpoint is not accessible from the YASGUI server and website, and the endpoint is not ";
|
|
46
|
+
cors.appendChild(firstPart);
|
|
47
|
+
const secondPart = document.createElement("a");
|
|
48
|
+
secondPart.textContent = "CORS-enabled";
|
|
49
|
+
secondPart.href = "http://enable-cors.org/";
|
|
50
|
+
secondPart.target = "_blank";
|
|
51
|
+
secondPart.rel = "noopener noreferrer";
|
|
52
|
+
cors.appendChild(secondPart);
|
|
53
|
+
list.appendChild(cors);
|
|
54
|
+
corsEl.appendChild(list);
|
|
55
|
+
return corsEl;
|
|
56
|
+
}
|
|
57
|
+
draw() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
var _a;
|
|
60
|
+
const el = document.createElement("div");
|
|
61
|
+
el.className = "errorResult";
|
|
62
|
+
this.yasr.resultsEl.appendChild(el);
|
|
63
|
+
const error = (_a = this.yasr.results) === null || _a === void 0 ? void 0 : _a.getError();
|
|
64
|
+
if (!error)
|
|
65
|
+
return;
|
|
66
|
+
const header = document.createElement("div");
|
|
67
|
+
header.className = "errorHeader";
|
|
68
|
+
el.appendChild(header);
|
|
69
|
+
const newMessage = yield this.yasr.renderError(error);
|
|
70
|
+
if (newMessage) {
|
|
71
|
+
const customMessage = document.createElement("div");
|
|
72
|
+
customMessage.className = "redOutline";
|
|
73
|
+
customMessage.appendChild(newMessage);
|
|
74
|
+
el.appendChild(customMessage);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (error.status) {
|
|
78
|
+
var statusText = "Error";
|
|
79
|
+
if (error.statusText && error.statusText.length < 100) {
|
|
80
|
+
statusText = error.statusText;
|
|
81
|
+
}
|
|
82
|
+
statusText += ` (#${error.status})`;
|
|
83
|
+
const statusTextEl = document.createElement("span");
|
|
84
|
+
statusTextEl.className = "status";
|
|
85
|
+
statusTextEl.textContent = statusText;
|
|
86
|
+
header.appendChild(statusTextEl);
|
|
87
|
+
if (this.yasr.config.getPlainQueryLinkToEndpoint) {
|
|
88
|
+
const link = this.yasr.config.getPlainQueryLinkToEndpoint();
|
|
89
|
+
if (link)
|
|
90
|
+
header.appendChild(this.getTryBtn(link));
|
|
91
|
+
}
|
|
92
|
+
if (error.text) {
|
|
93
|
+
const textContainer = document.createElement("div");
|
|
94
|
+
addClass(textContainer, "errorMessageContainer");
|
|
95
|
+
el.appendChild(textContainer);
|
|
96
|
+
const errTextEl = document.createElement("pre");
|
|
97
|
+
addClass(errTextEl, "errorMessage");
|
|
98
|
+
errTextEl.textContent = error.text;
|
|
99
|
+
textContainer.appendChild(errTextEl);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
if (this.yasr.config.getPlainQueryLinkToEndpoint) {
|
|
104
|
+
const link = this.yasr.config.getPlainQueryLinkToEndpoint();
|
|
105
|
+
if (link)
|
|
106
|
+
header.appendChild(this.getTryBtn(link));
|
|
107
|
+
}
|
|
108
|
+
if (!error.text || error.text.indexOf("Request has been terminated") >= 0) {
|
|
109
|
+
el.appendChild(this.getCorsMessage());
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const errTextEl = document.createElement("pre");
|
|
113
|
+
errTextEl.textContent = error.text;
|
|
114
|
+
el.appendChild(errTextEl);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
getIcon() {
|
|
120
|
+
return document.createElement("");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/yasr/src/plugins/error/index.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,cAAc,CAAC;AAEtB,MAAM,CAAC,OAAO,OAAO,KAAK;IAExB,YAAY,IAAU;QA+GtB,aAAQ,GAAG,EAAE,CAAC;QACd,sBAAiB,GAAG,IAAI,CAAC;QA/GvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,gBAAgB;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC/D,CAAC;IACO,SAAS,CAAC,IAAY;QAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,MAAM,CAAC,GAAG,GAAG,qBAAqB,CAAC;QACnC,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC;QACzB,MAAM,CAAC,SAAS,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AAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;gBACrD,CAAC;gBACD,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,6BAA6B,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC1E,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;gBACxC,CAAC;qBAAM,CAAC;oBACN,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;oBAChD,SAAS,CAAC,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC;oBACnC,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IACD,OAAO;QACL,OAAO,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;CAGF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/yasr/src/plugins/index.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Plugin } from "../";
|
|
2
2
|
import Yasr from "../../";
|
|
3
|
+
import "./index.scss";
|
|
4
|
+
import "codemirror/addon/fold/foldcode.js";
|
|
5
|
+
import "codemirror/addon/fold/foldgutter.js";
|
|
6
|
+
import "codemirror/addon/fold/xml-fold.js";
|
|
7
|
+
import "codemirror/addon/fold/brace-fold.js";
|
|
8
|
+
import "codemirror/addon/edit/matchbrackets.js";
|
|
9
|
+
import "codemirror/mode/xml/xml.js";
|
|
10
|
+
import "codemirror/mode/javascript/javascript.js";
|
|
11
|
+
import "codemirror/lib/codemirror.css";
|
|
3
12
|
export interface PluginConfig {
|
|
4
13
|
maxLines: number;
|
|
5
14
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import "./index.scss";
|
|
2
|
+
import CodeMirror from "codemirror";
|
|
3
|
+
import "codemirror/addon/fold/foldcode.js";
|
|
4
|
+
import "codemirror/addon/fold/foldgutter.js";
|
|
5
|
+
import "codemirror/addon/fold/xml-fold.js";
|
|
6
|
+
import "codemirror/addon/fold/brace-fold.js";
|
|
7
|
+
import "codemirror/addon/edit/matchbrackets.js";
|
|
8
|
+
import "codemirror/mode/xml/xml.js";
|
|
9
|
+
import "codemirror/mode/javascript/javascript.js";
|
|
10
|
+
import "codemirror/lib/codemirror.css";
|
|
11
|
+
import { drawSvgStringAsElement, addClass, removeClass, drawFontAwesomeIconAsSvg } from "@matdata/yasgui-utils";
|
|
12
|
+
import * as faAlignIcon from "@fortawesome/free-solid-svg-icons/faAlignLeft";
|
|
13
|
+
import * as imgs from "../../imgs";
|
|
14
|
+
class Response {
|
|
15
|
+
constructor(yasr) {
|
|
16
|
+
this.label = "Response";
|
|
17
|
+
this.priority = 2;
|
|
18
|
+
this.helpReference = "https://docs.triply.cc/yasgui/#response";
|
|
19
|
+
this.yasr = yasr;
|
|
20
|
+
this.config = Response.defaults;
|
|
21
|
+
if (yasr.config.plugins["response"] && yasr.config.plugins["response"].dynamicConfig) {
|
|
22
|
+
this.config = Object.assign(Object.assign({}, this.config), yasr.config.plugins["response"].dynamicConfig);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
canHandleResults() {
|
|
26
|
+
if (!this.yasr.results)
|
|
27
|
+
return false;
|
|
28
|
+
if (!this.yasr.results.getOriginalResponseAsString)
|
|
29
|
+
return false;
|
|
30
|
+
var response = this.yasr.results.getOriginalResponseAsString();
|
|
31
|
+
if ((!response || response.length == 0) && this.yasr.results.getError())
|
|
32
|
+
return false;
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
getIcon() {
|
|
36
|
+
return drawSvgStringAsElement(drawFontAwesomeIconAsSvg(faAlignIcon));
|
|
37
|
+
}
|
|
38
|
+
download(filename) {
|
|
39
|
+
if (!this.yasr.results)
|
|
40
|
+
return;
|
|
41
|
+
const contentType = this.yasr.results.getContentType();
|
|
42
|
+
const type = this.yasr.results.getType();
|
|
43
|
+
const extension = type === "xml" ? "rdf" : type;
|
|
44
|
+
return {
|
|
45
|
+
getData: () => {
|
|
46
|
+
var _a;
|
|
47
|
+
return ((_a = this.yasr.results) === null || _a === void 0 ? void 0 : _a.getOriginalResponseAsString()) || "";
|
|
48
|
+
},
|
|
49
|
+
filename: `${filename || "queryResults"}${extension ? "." + extension : ""}`,
|
|
50
|
+
contentType: contentType ? contentType : "text/plain",
|
|
51
|
+
title: "Download result",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
draw(persistentConfig) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const config = Object.assign(Object.assign({}, this.config), persistentConfig);
|
|
57
|
+
let value = ((_a = this.yasr.results) === null || _a === void 0 ? void 0 : _a.getOriginalResponseAsString()) || "";
|
|
58
|
+
const lines = value.split("\n");
|
|
59
|
+
if (lines.length > config.maxLines) {
|
|
60
|
+
value = lines.slice(0, config.maxLines).join("\n");
|
|
61
|
+
}
|
|
62
|
+
const codemirrorOpts = {
|
|
63
|
+
readOnly: true,
|
|
64
|
+
lineNumbers: true,
|
|
65
|
+
lineWrapping: true,
|
|
66
|
+
foldGutter: true,
|
|
67
|
+
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
|
68
|
+
value: value,
|
|
69
|
+
extraKeys: { Tab: false },
|
|
70
|
+
};
|
|
71
|
+
const mode = (_b = this.yasr.results) === null || _b === void 0 ? void 0 : _b.getType();
|
|
72
|
+
if (mode === "json") {
|
|
73
|
+
codemirrorOpts.mode = { name: "javascript", json: true };
|
|
74
|
+
}
|
|
75
|
+
this.cm = CodeMirror(this.yasr.resultsEl, codemirrorOpts);
|
|
76
|
+
if (lines.length > config.maxLines)
|
|
77
|
+
this.showLess(false);
|
|
78
|
+
}
|
|
79
|
+
limitData(value) {
|
|
80
|
+
const lines = value.split("\n");
|
|
81
|
+
if (lines.length > this.config.maxLines) {
|
|
82
|
+
value = lines.slice(0, this.config.maxLines).join("\n");
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
showLess(setValue = true) {
|
|
87
|
+
var _a;
|
|
88
|
+
if (!this.cm)
|
|
89
|
+
return;
|
|
90
|
+
addClass(this.cm.getWrapperElement(), "overflow");
|
|
91
|
+
if (this.overLay) {
|
|
92
|
+
this.overLay.remove();
|
|
93
|
+
this.overLay = undefined;
|
|
94
|
+
}
|
|
95
|
+
this.overLay = document.createElement("div");
|
|
96
|
+
addClass(this.overLay, "overlay");
|
|
97
|
+
const overlayContent = document.createElement("div");
|
|
98
|
+
addClass(overlayContent, "overlay_content");
|
|
99
|
+
const showMoreButton = document.createElement("button");
|
|
100
|
+
showMoreButton.title = "Show all";
|
|
101
|
+
addClass(showMoreButton, "yasr_btn", "overlay_btn");
|
|
102
|
+
showMoreButton.textContent = "Show all";
|
|
103
|
+
showMoreButton.addEventListener("click", () => this.showMore());
|
|
104
|
+
overlayContent.append(showMoreButton);
|
|
105
|
+
const downloadButton = document.createElement("button");
|
|
106
|
+
downloadButton.title = "Download result";
|
|
107
|
+
addClass(downloadButton, "yasr_btn", "overlay_btn");
|
|
108
|
+
const text = document.createElement("span");
|
|
109
|
+
text.innerText = "Download result";
|
|
110
|
+
downloadButton.appendChild(text);
|
|
111
|
+
downloadButton.appendChild(drawSvgStringAsElement(imgs.download));
|
|
112
|
+
downloadButton.addEventListener("click", () => this.yasr.download());
|
|
113
|
+
downloadButton.addEventListener("keydown", (event) => {
|
|
114
|
+
if (event.code === "Space" || event.code === "Enter")
|
|
115
|
+
this.yasr.download();
|
|
116
|
+
});
|
|
117
|
+
overlayContent.appendChild(downloadButton);
|
|
118
|
+
this.overLay.appendChild(overlayContent);
|
|
119
|
+
this.cm.getWrapperElement().appendChild(this.overLay);
|
|
120
|
+
if (setValue) {
|
|
121
|
+
this.cm.setValue(this.limitData(((_a = this.yasr.results) === null || _a === void 0 ? void 0 : _a.getOriginalResponseAsString()) || ""));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
showMore() {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
if (!this.cm)
|
|
127
|
+
return;
|
|
128
|
+
removeClass(this.cm.getWrapperElement(), "overflow");
|
|
129
|
+
(_a = this.overLay) === null || _a === void 0 ? void 0 : _a.remove();
|
|
130
|
+
this.overLay = undefined;
|
|
131
|
+
this.cm.setValue(((_b = this.yasr.results) === null || _b === void 0 ? void 0 : _b.getOriginalResponseAsString()) || "");
|
|
132
|
+
this.cm.refresh();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
Response.defaults = {
|
|
136
|
+
maxLines: 30,
|
|
137
|
+
};
|
|
138
|
+
export default Response;
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/yasr/src/plugins/response/index.ts"],"names":[],"mappings":"AAKA,OAAO,cAAc,CAAC;AACtB,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC;AAE7C,OAAO,wCAAwC,CAAC;AAChD,OAAO,4BAA4B,CAAC;AAEpC,OAAO,0CAA0C,CAAC;AAClD,OAAO,+BAA+B,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAChH,OAAO,KAAK,WAAW,MAAM,+CAA+C,CAAC;AAE7E,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAKnC,MAAqB,QAAQ;IAQ3B,YAAY,IAAU;QANtB,UAAK,GAAG,UAAU,CAAC;QACnB,aAAQ,GAAG,CAAC,CAAC;QACb,kBAAa,GAAG,yCAAyC,CAAC;QAKxD,IAAI,CAAC,IAAI,GAAG,IA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QACzC,IAAI,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA,MAAA,IAAI,CAAC,IAAI,CAAC,OAAO,0CAAE,2BAA2B,EAAE,KAAI,EAAE,CAAC,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;IAID,QAAQ;;QACN,IAAI,CAAC,IAAI,CAAC,EAAE;YAAE,OAAO;QACrB,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,iBAAiB,EAAE,EAAE,UAAU,CAAC,CAAC;QACrD,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA,MAAA,IAAI,CAAC,IAAI,CAAC,OAAO,0CAAE,2BAA2B,EAAE,KAAI,EAAE,CAAC,CAAC;QACzE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;;AACa,iBAAQ,GAAiB;IACrC,QAAQ,EAAE,EAAE;CACb,AAFqB,CAEpB;eA/IiB,QAAQ"}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import "./index.scss";
|
|
2
|
+
import "datatables.net-dt/css/dataTables.dataTables.min.css";
|
|
3
|
+
import "datatables.net";
|
|
4
|
+
import $ from "jquery";
|
|
5
|
+
import { escape } from "lodash-es";
|
|
6
|
+
import { drawSvgStringAsElement, drawFontAwesomeIconAsSvg, addClass, removeClass } from "@matdata/yasgui-utils";
|
|
7
|
+
import * as faTableIcon from "@fortawesome/free-solid-svg-icons/faTable";
|
|
8
|
+
import { cloneDeep } from "lodash-es";
|
|
9
|
+
import sanitize from "../../helpers/sanitize";
|
|
10
|
+
import ColumnResizer from "column-resizer";
|
|
11
|
+
const DEFAULT_PAGE_SIZE = 50;
|
|
12
|
+
function expand(event) {
|
|
13
|
+
addClass(this, "expanded");
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
}
|
|
16
|
+
class Table {
|
|
17
|
+
getIcon() {
|
|
18
|
+
return drawSvgStringAsElement(drawFontAwesomeIconAsSvg(faTableIcon));
|
|
19
|
+
}
|
|
20
|
+
constructor(yasr) {
|
|
21
|
+
this.persistentConfig = {};
|
|
22
|
+
this.helpReference = "https://docs.triply.cc/yasgui/#table";
|
|
23
|
+
this.label = "Table";
|
|
24
|
+
this.priority = 10;
|
|
25
|
+
this.setEllipsisHandlers = () => {
|
|
26
|
+
var _a;
|
|
27
|
+
(_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.cells({ page: "current" }).every((rowIdx, colIdx) => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const cell = (_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.cell(rowIdx, colIdx);
|
|
30
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.data()) === "")
|
|
31
|
+
return;
|
|
32
|
+
const cellNode = cell === null || cell === void 0 ? void 0 : cell.node();
|
|
33
|
+
if (cellNode) {
|
|
34
|
+
const content = cellNode.firstChild;
|
|
35
|
+
if ((((_b = content.firstElementChild) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect().width) || 0) > content.getBoundingClientRect().width) {
|
|
36
|
+
if (!content.classList.contains("expandable")) {
|
|
37
|
+
addClass(content, "expandable");
|
|
38
|
+
content.addEventListener("click", expand, { once: true });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
if (content.classList.contains("expandable")) {
|
|
43
|
+
removeClass(content, "expandable");
|
|
44
|
+
content.removeEventListener("click", expand);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
this.handleTableSearch = (event) => {
|
|
51
|
+
var _a;
|
|
52
|
+
(_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.search(event.target.value).draw("page");
|
|
53
|
+
};
|
|
54
|
+
this.handleTableSizeSelect = (event) => {
|
|
55
|
+
var _a;
|
|
56
|
+
const pageLength = parseInt(event.target.value);
|
|
57
|
+
(_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.page.len(pageLength).draw("page");
|
|
58
|
+
this.persistentConfig.pageSize = pageLength;
|
|
59
|
+
this.yasr.storePluginConfig("table", this.persistentConfig);
|
|
60
|
+
};
|
|
61
|
+
this.handleSetCompactToggle = (event) => {
|
|
62
|
+
this.persistentConfig.compact = event.target.checked;
|
|
63
|
+
this.draw(this.persistentConfig);
|
|
64
|
+
this.yasr.storePluginConfig("table", this.persistentConfig);
|
|
65
|
+
};
|
|
66
|
+
this.handleSetEllipsisToggle = (event) => {
|
|
67
|
+
this.persistentConfig.isEllipsed = event.target.checked;
|
|
68
|
+
this.draw(this.persistentConfig);
|
|
69
|
+
this.yasr.storePluginConfig("table", this.persistentConfig);
|
|
70
|
+
};
|
|
71
|
+
this.yasr = yasr;
|
|
72
|
+
this.config = Table.defaults;
|
|
73
|
+
}
|
|
74
|
+
getRows() {
|
|
75
|
+
if (!this.yasr.results)
|
|
76
|
+
return [];
|
|
77
|
+
const bindings = this.yasr.results.getBindings();
|
|
78
|
+
if (!bindings)
|
|
79
|
+
return [];
|
|
80
|
+
const vars = this.yasr.results.getVariables();
|
|
81
|
+
return bindings.map((binding, rowId) => [rowId + 1, ...vars.map((variable) => { var _a; return (_a = binding[variable]) !== null && _a !== void 0 ? _a : ""; })]);
|
|
82
|
+
}
|
|
83
|
+
getUriLinkFromBinding(binding, prefixes) {
|
|
84
|
+
const href = sanitize(binding.value);
|
|
85
|
+
let visibleString = href;
|
|
86
|
+
let prefixed = false;
|
|
87
|
+
if (prefixes) {
|
|
88
|
+
for (const prefixLabel in prefixes) {
|
|
89
|
+
if (visibleString.indexOf(prefixes[prefixLabel]) == 0) {
|
|
90
|
+
visibleString = prefixLabel + ":" + href.substring(prefixes[prefixLabel].length);
|
|
91
|
+
prefixed = true;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const hideBrackets = prefixed || this.persistentConfig.compact;
|
|
97
|
+
const uri = `${hideBrackets ? "" : "<"}<a class='iri' target='${this.config.openIriInNewWindow ? "_blank" : "_self"}'${this.config.openIriInNewWindow ? " ref='noopener noreferrer'" : ""} href='${href}'>${sanitize(visibleString)}</a>${hideBrackets ? "" : ">"}`;
|
|
98
|
+
return sanitize(uri);
|
|
99
|
+
}
|
|
100
|
+
getCellContent(binding, prefixes) {
|
|
101
|
+
let content;
|
|
102
|
+
if (binding.type == "uri") {
|
|
103
|
+
content = `<span>${this.getUriLinkFromBinding(binding, prefixes)}</span>`;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
content = `<span class='nonIri'>${this.formatLiteral(binding, prefixes)}</span>`;
|
|
107
|
+
}
|
|
108
|
+
return `<div>${content}</div>`;
|
|
109
|
+
}
|
|
110
|
+
formatLiteral(literalBinding, prefixes) {
|
|
111
|
+
let stringRepresentation = sanitize(escape(literalBinding.value));
|
|
112
|
+
if (this.persistentConfig.compact)
|
|
113
|
+
return stringRepresentation;
|
|
114
|
+
if (literalBinding["xml:lang"]) {
|
|
115
|
+
stringRepresentation = `"${stringRepresentation}"<sup>@${literalBinding["xml:lang"]}</sup>`;
|
|
116
|
+
}
|
|
117
|
+
else if (literalBinding.datatype) {
|
|
118
|
+
const dataType = this.getUriLinkFromBinding({ type: "uri", value: literalBinding.datatype }, prefixes);
|
|
119
|
+
stringRepresentation = `"${stringRepresentation}"<sup>^^${dataType}</sup>`;
|
|
120
|
+
}
|
|
121
|
+
return stringRepresentation;
|
|
122
|
+
}
|
|
123
|
+
getColumns() {
|
|
124
|
+
var _a;
|
|
125
|
+
if (!this.yasr.results)
|
|
126
|
+
return [];
|
|
127
|
+
const prefixes = this.yasr.getPrefixes();
|
|
128
|
+
return [
|
|
129
|
+
{
|
|
130
|
+
name: "",
|
|
131
|
+
searchable: false,
|
|
132
|
+
width: `${this.getSizeFirstColumn()}px`,
|
|
133
|
+
type: "num",
|
|
134
|
+
orderable: false,
|
|
135
|
+
visible: this.persistentConfig.compact !== true,
|
|
136
|
+
render: (data, type) => type === "filter" || type === "sort" || !type ? data : `<div class="rowNumber">${data}</div>`,
|
|
137
|
+
},
|
|
138
|
+
...(_a = this.yasr.results) === null || _a === void 0 ? void 0 : _a.getVariables().map((name) => {
|
|
139
|
+
return {
|
|
140
|
+
name,
|
|
141
|
+
title: sanitize(name),
|
|
142
|
+
render: (data, type, _row, _meta) => {
|
|
143
|
+
if (data === "")
|
|
144
|
+
return data;
|
|
145
|
+
if (type === "filter" || type === "sort" || !type)
|
|
146
|
+
return sanitize(data.value);
|
|
147
|
+
return this.getCellContent(data, prefixes);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}),
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
getSizeFirstColumn() {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
const numResults = ((_b = (_a = this.yasr.results) === null || _a === void 0 ? void 0 : _a.getBindings()) === null || _b === void 0 ? void 0 : _b.length) || 0;
|
|
156
|
+
return numResults.toString().length * 8;
|
|
157
|
+
}
|
|
158
|
+
draw(persistentConfig) {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
this.persistentConfig = Object.assign(Object.assign({}, this.persistentConfig), persistentConfig);
|
|
161
|
+
this.tableEl = document.createElement("table");
|
|
162
|
+
const rows = this.getRows();
|
|
163
|
+
const columns = this.getColumns();
|
|
164
|
+
if (rows.length <= ((persistentConfig === null || persistentConfig === void 0 ? void 0 : persistentConfig.pageSize) || DEFAULT_PAGE_SIZE)) {
|
|
165
|
+
this.yasr.pluginControls;
|
|
166
|
+
addClass(this.yasr.rootEl, "isSinglePage");
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
removeClass(this.yasr.rootEl, "isSinglePage");
|
|
170
|
+
}
|
|
171
|
+
if (this.dataTable) {
|
|
172
|
+
this.destroyResizer();
|
|
173
|
+
this.dataTable.destroy(true);
|
|
174
|
+
this.dataTable = undefined;
|
|
175
|
+
}
|
|
176
|
+
this.yasr.resultsEl.appendChild(this.tableEl);
|
|
177
|
+
const dtConfig = Object.assign(Object.assign({}, cloneDeep(this.config.tableConfig)), { pageLength: (persistentConfig === null || persistentConfig === void 0 ? void 0 : persistentConfig.pageSize) ? persistentConfig.pageSize : DEFAULT_PAGE_SIZE, data: rows, columns: columns });
|
|
178
|
+
this.dataTable = $(this.tableEl).DataTable(dtConfig);
|
|
179
|
+
this.tableEl.style.removeProperty("width");
|
|
180
|
+
this.tableEl.style.width = this.tableEl.clientWidth + "px";
|
|
181
|
+
const widths = Array.from(this.tableEl.querySelectorAll("th")).map((h) => h.offsetWidth - 26);
|
|
182
|
+
this.tableResizer = new ColumnResizer.default(this.tableEl, {
|
|
183
|
+
widths: this.persistentConfig.compact === true ? widths : [this.getSizeFirstColumn(), ...widths.slice(1)],
|
|
184
|
+
partialRefresh: true,
|
|
185
|
+
onResize: this.persistentConfig.isEllipsed !== false && this.setEllipsisHandlers,
|
|
186
|
+
headerOnly: true,
|
|
187
|
+
});
|
|
188
|
+
if (this.persistentConfig.isEllipsed !== false) {
|
|
189
|
+
(_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.on("preDraw", () => {
|
|
190
|
+
var _a, _b, _c;
|
|
191
|
+
(_a = this.tableResizer) === null || _a === void 0 ? void 0 : _a.reset({ disable: true });
|
|
192
|
+
removeClass(this.tableEl, "ellipseTable");
|
|
193
|
+
(_b = this.tableEl) === null || _b === void 0 ? void 0 : _b.style.removeProperty("width");
|
|
194
|
+
(_c = this.tableEl) === null || _c === void 0 ? void 0 : _c.style.setProperty("width", this.tableEl.clientWidth + "px");
|
|
195
|
+
return true;
|
|
196
|
+
});
|
|
197
|
+
(_b = this.dataTable) === null || _b === void 0 ? void 0 : _b.on("draw", () => {
|
|
198
|
+
var _a, _b;
|
|
199
|
+
if (!this.tableEl)
|
|
200
|
+
return;
|
|
201
|
+
let targetSize = this.tableEl.clientWidth;
|
|
202
|
+
this.tableEl.style.removeProperty("width");
|
|
203
|
+
if (targetSize > this.tableEl.clientWidth)
|
|
204
|
+
targetSize = this.tableEl.clientWidth;
|
|
205
|
+
(_a = this.tableEl) === null || _a === void 0 ? void 0 : _a.style.setProperty("width", `${targetSize}px`);
|
|
206
|
+
(_b = this.tableResizer) === null || _b === void 0 ? void 0 : _b.reset({
|
|
207
|
+
disable: false,
|
|
208
|
+
partialRefresh: true,
|
|
209
|
+
onResize: this.setEllipsisHandlers,
|
|
210
|
+
headerOnly: true,
|
|
211
|
+
});
|
|
212
|
+
addClass(this.tableEl, "ellipseTable");
|
|
213
|
+
this.setEllipsisHandlers();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
this.drawControls();
|
|
217
|
+
if (this.persistentConfig.isEllipsed !== false) {
|
|
218
|
+
addClass(this.tableEl, "ellipseTable");
|
|
219
|
+
this.setEllipsisHandlers();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
drawControls() {
|
|
223
|
+
var _a;
|
|
224
|
+
this.removeControls();
|
|
225
|
+
this.tableControls = document.createElement("div");
|
|
226
|
+
this.tableControls.className = "tableControls";
|
|
227
|
+
const toggleWrapper = document.createElement("div");
|
|
228
|
+
const switchComponent = document.createElement("label");
|
|
229
|
+
const textComponent = document.createElement("span");
|
|
230
|
+
textComponent.innerText = "Simple view";
|
|
231
|
+
addClass(textComponent, "label");
|
|
232
|
+
switchComponent.appendChild(textComponent);
|
|
233
|
+
addClass(switchComponent, "switch");
|
|
234
|
+
toggleWrapper.appendChild(switchComponent);
|
|
235
|
+
this.tableCompactSwitch = document.createElement("input");
|
|
236
|
+
switchComponent.addEventListener("change", this.handleSetCompactToggle);
|
|
237
|
+
this.tableCompactSwitch.type = "checkbox";
|
|
238
|
+
switchComponent.appendChild(this.tableCompactSwitch);
|
|
239
|
+
this.tableCompactSwitch.defaultChecked = !!this.persistentConfig.compact;
|
|
240
|
+
this.tableControls.appendChild(toggleWrapper);
|
|
241
|
+
const ellipseToggleWrapper = document.createElement("div");
|
|
242
|
+
const ellipseSwitchComponent = document.createElement("label");
|
|
243
|
+
const ellipseTextComponent = document.createElement("span");
|
|
244
|
+
ellipseTextComponent.innerText = "Ellipse";
|
|
245
|
+
addClass(ellipseTextComponent, "label");
|
|
246
|
+
ellipseSwitchComponent.appendChild(ellipseTextComponent);
|
|
247
|
+
addClass(ellipseSwitchComponent, "switch");
|
|
248
|
+
ellipseToggleWrapper.appendChild(ellipseSwitchComponent);
|
|
249
|
+
this.tableEllipseSwitch = document.createElement("input");
|
|
250
|
+
ellipseSwitchComponent.addEventListener("change", this.handleSetEllipsisToggle);
|
|
251
|
+
this.tableEllipseSwitch.type = "checkbox";
|
|
252
|
+
ellipseSwitchComponent.appendChild(this.tableEllipseSwitch);
|
|
253
|
+
this.tableEllipseSwitch.defaultChecked = this.persistentConfig.isEllipsed !== false;
|
|
254
|
+
this.tableControls.appendChild(ellipseToggleWrapper);
|
|
255
|
+
this.tableFilterField = document.createElement("input");
|
|
256
|
+
this.tableFilterField.className = "tableFilter";
|
|
257
|
+
this.tableFilterField.placeholder = "Filter query results";
|
|
258
|
+
this.tableFilterField.setAttribute("aria-label", "Filter query results");
|
|
259
|
+
this.tableControls.appendChild(this.tableFilterField);
|
|
260
|
+
this.tableFilterField.addEventListener("keyup", this.handleTableSearch);
|
|
261
|
+
const pageSizerWrapper = document.createElement("div");
|
|
262
|
+
pageSizerWrapper.className = "pageSizeWrapper";
|
|
263
|
+
const pageSizerLabel = document.createElement("span");
|
|
264
|
+
pageSizerLabel.textContent = "Page size: ";
|
|
265
|
+
pageSizerLabel.className = "pageSizerLabel";
|
|
266
|
+
pageSizerWrapper.appendChild(pageSizerLabel);
|
|
267
|
+
this.tableSizeField = document.createElement("select");
|
|
268
|
+
this.tableSizeField.className = "tableSizer";
|
|
269
|
+
const options = [10, 50, 100, 1000, -1];
|
|
270
|
+
for (const option of options) {
|
|
271
|
+
const element = document.createElement("option");
|
|
272
|
+
element.value = option + "";
|
|
273
|
+
element.innerText = option > 0 ? option + "" : "All";
|
|
274
|
+
if (((_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.page.len()) === option)
|
|
275
|
+
element.selected = true;
|
|
276
|
+
this.tableSizeField.appendChild(element);
|
|
277
|
+
}
|
|
278
|
+
pageSizerWrapper.appendChild(this.tableSizeField);
|
|
279
|
+
this.tableSizeField.addEventListener("change", this.handleTableSizeSelect);
|
|
280
|
+
this.tableControls.appendChild(pageSizerWrapper);
|
|
281
|
+
this.yasr.pluginControls.appendChild(this.tableControls);
|
|
282
|
+
}
|
|
283
|
+
download(filename) {
|
|
284
|
+
return {
|
|
285
|
+
getData: () => { var _a; return ((_a = this.yasr.results) === null || _a === void 0 ? void 0 : _a.asCsv()) || ""; },
|
|
286
|
+
contentType: "text/csv",
|
|
287
|
+
title: "Download result",
|
|
288
|
+
filename: `${filename || "queryResults"}.csv`,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
canHandleResults() {
|
|
292
|
+
return !!this.yasr.results && this.yasr.results.getVariables() && this.yasr.results.getVariables().length > 0;
|
|
293
|
+
}
|
|
294
|
+
removeControls() {
|
|
295
|
+
var _a, _b, _c, _d, _e, _f;
|
|
296
|
+
(_a = this.tableFilterField) === null || _a === void 0 ? void 0 : _a.removeEventListener("keyup", this.handleTableSearch);
|
|
297
|
+
this.tableFilterField = undefined;
|
|
298
|
+
(_b = this.tableSizeField) === null || _b === void 0 ? void 0 : _b.removeEventListener("change", this.handleTableSizeSelect);
|
|
299
|
+
this.tableSizeField = undefined;
|
|
300
|
+
(_c = this.tableCompactSwitch) === null || _c === void 0 ? void 0 : _c.removeEventListener("change", this.handleSetCompactToggle);
|
|
301
|
+
this.tableCompactSwitch = undefined;
|
|
302
|
+
(_d = this.tableEllipseSwitch) === null || _d === void 0 ? void 0 : _d.removeEventListener("change", this.handleSetEllipsisToggle);
|
|
303
|
+
this.tableEllipseSwitch = undefined;
|
|
304
|
+
while ((_e = this.tableControls) === null || _e === void 0 ? void 0 : _e.firstChild)
|
|
305
|
+
this.tableControls.firstChild.remove();
|
|
306
|
+
(_f = this.tableControls) === null || _f === void 0 ? void 0 : _f.remove();
|
|
307
|
+
}
|
|
308
|
+
destroyResizer() {
|
|
309
|
+
if (this.tableResizer) {
|
|
310
|
+
this.tableResizer.reset({ disable: true });
|
|
311
|
+
window.removeEventListener("resize", this.tableResizer.onResize);
|
|
312
|
+
this.tableResizer = undefined;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
destroy() {
|
|
316
|
+
var _a;
|
|
317
|
+
this.removeControls();
|
|
318
|
+
this.destroyResizer();
|
|
319
|
+
(_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.destroy(true);
|
|
320
|
+
this.dataTable = undefined;
|
|
321
|
+
removeClass(this.yasr.rootEl, "isSinglePage");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
Table.defaults = {
|
|
325
|
+
openIriInNewWindow: true,
|
|
326
|
+
tableConfig: {
|
|
327
|
+
layout: {
|
|
328
|
+
top: null,
|
|
329
|
+
topStart: null,
|
|
330
|
+
topEnd: null,
|
|
331
|
+
},
|
|
332
|
+
pageLength: DEFAULT_PAGE_SIZE,
|
|
333
|
+
lengthChange: true,
|
|
334
|
+
data: [],
|
|
335
|
+
columns: [],
|
|
336
|
+
order: [],
|
|
337
|
+
deferRender: true,
|
|
338
|
+
orderClasses: false,
|
|
339
|
+
language: {
|
|
340
|
+
paginate: {
|
|
341
|
+
first: "<<",
|
|
342
|
+
last: ">>",
|
|
343
|
+
next: ">",
|
|
344
|
+
previous: "<",
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
export default Table;
|
|
350
|
+
//# sourceMappingURL=index.js.map
|