@matdata/yasr 5.2.0 → 5.4.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@matdata/yasr",
3
3
  "description": "Yet Another SPARQL Resultset GUI",
4
- "version": "5.2.0",
4
+ "version": "5.4.0",
5
5
  "main": "build/yasr.min.js",
6
6
  "types": "build/ts/src/index.d.ts",
7
7
  "license": "MIT",
@@ -227,10 +227,9 @@ const getHtml = (plugin) => `
227
227
  <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.0.0/polyfill.js"></script>
228
228
  <style>
229
229
  body {
230
- font-family: 'Roboto', sans-serif;
230
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
231
231
  }
232
232
  </style>
233
- <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" />
234
233
  <link rel="stylesheet" href="build/yasr.min.css" />
235
234
  <link rel="stylesheet" href="build/pro-gallery.min.css">
236
235
  <link rel="stylesheet" href="build/pro-geo.min.css">
@@ -302,7 +301,7 @@ const getScreenWidth = (plugin) => {
302
301
  };
303
302
 
304
303
  let staticFileServer = new static.Server("./");
305
- function setupServer () {
304
+ function setupServer() {
306
305
  return new Promise((resolve, reject) => {
307
306
  var server = http
308
307
  .createServer(function (request, response) {
@@ -319,10 +318,10 @@ function setupServer () {
319
318
  .on("error", (e) => reject(e));
320
319
  });
321
320
  }
322
- function wait (time) {
321
+ function wait(time) {
323
322
  return new Promise((resolve) => setTimeout(resolve, time));
324
323
  }
325
- function waitForImagesToLoad (page) {
324
+ function waitForImagesToLoad(page) {
326
325
  return page.evaluate(() => {
327
326
  const selectors = Array.from(document.querySelectorAll("img"));
328
327
  return Promise.all(
@@ -332,7 +331,7 @@ function waitForImagesToLoad (page) {
332
331
  img.addEventListener("load", resolve);
333
332
  img.addEventListener("error", reject);
334
333
  });
335
- })
334
+ }),
336
335
  );
337
336
  });
338
337
  }
@@ -13,6 +13,6 @@ export default function (result: Parser.SparqlResults) {
13
13
  ? querySolutions.map((s) => {
14
14
  return mapValues(s, (binding) => binding.value);
15
15
  })
16
- : []
16
+ : [],
17
17
  );
18
18
  }
@@ -57,7 +57,7 @@ function parseBoolean(node: Element) {
57
57
  }
58
58
  export default function (
59
59
  xmlString: string,
60
- postProcessBinding: Parser.PostProcessBinding
60
+ postProcessBinding: Parser.PostProcessBinding,
61
61
  ): Parser.SparqlResults | undefined {
62
62
  if (typeof xmlString !== "string") return;
63
63
  const domParser = new DOMParser();
@@ -0,0 +1,246 @@
1
+ import { describe, it } from "mocha";
2
+ import { expect } from "chai";
3
+ import Yasr from "../../../index";
4
+ import Parser from "../../../parsers";
5
+
6
+ describe("Table Plugin", () => {
7
+ describe("Markdown Generation", () => {
8
+ it("should generate markdown table from simple results", () => {
9
+ const container = document.createElement("div");
10
+ const yasr = new Yasr(container);
11
+
12
+ // Mock SPARQL results
13
+ const mockResults = {
14
+ head: {
15
+ vars: ["subject", "predicate", "object"],
16
+ },
17
+ results: {
18
+ bindings: [
19
+ {
20
+ subject: { type: "uri", value: "http://example.org/resource/1" } as Parser.BindingValue,
21
+ predicate: { type: "uri", value: "http://example.org/name" } as Parser.BindingValue,
22
+ object: { type: "literal", value: "Test Name" } as Parser.BindingValue,
23
+ },
24
+ {
25
+ subject: { type: "uri", value: "http://example.org/resource/2" } as Parser.BindingValue,
26
+ predicate: { type: "uri", value: "http://example.org/name" } as Parser.BindingValue,
27
+ object: { type: "literal", value: "Another Name" } as Parser.BindingValue,
28
+ },
29
+ ],
30
+ },
31
+ };
32
+
33
+ yasr.setResponse(
34
+ {
35
+ response: JSON.stringify(mockResults),
36
+ status: 200,
37
+ contentType: "application/sparql-results+json",
38
+ },
39
+ 0,
40
+ );
41
+
42
+ const tablePlugin = yasr.plugins["table"];
43
+ // @ts-ignore - accessing private method for testing
44
+ const markdown = tablePlugin.getMarkdownTable();
45
+
46
+ expect(markdown).to.be.a("string");
47
+ expect(markdown).to.include("| subject | predicate | object |");
48
+ expect(markdown).to.include("| --- | --- | --- |");
49
+ expect(markdown).to.include("http://example.org/resource/1");
50
+ expect(markdown).to.include("Test Name");
51
+ });
52
+
53
+ it("should escape pipe characters in markdown values", () => {
54
+ const container = document.createElement("div");
55
+ const yasr = new Yasr(container);
56
+
57
+ // Mock SPARQL results with pipe character
58
+ const mockResults = {
59
+ head: {
60
+ vars: ["value"],
61
+ },
62
+ results: {
63
+ bindings: [
64
+ {
65
+ value: { type: "literal", value: "text|with|pipes" } as Parser.BindingValue,
66
+ },
67
+ ],
68
+ },
69
+ };
70
+
71
+ yasr.setResponse(
72
+ {
73
+ response: JSON.stringify(mockResults),
74
+ status: 200,
75
+ contentType: "application/sparql-results+json",
76
+ },
77
+ 0,
78
+ );
79
+
80
+ const tablePlugin = yasr.plugins["table"];
81
+ // @ts-ignore - accessing private method for testing
82
+ const markdown = tablePlugin.getMarkdownTable();
83
+
84
+ expect(markdown).to.include("text\\|with\\|pipes");
85
+ });
86
+ });
87
+
88
+ describe("URI Prefixing", () => {
89
+ it("should show URI prefixes when enabled", () => {
90
+ const container = document.createElement("div");
91
+ const yasr = new Yasr(container, {
92
+ prefixes: {
93
+ ex: "http://example.org/",
94
+ },
95
+ });
96
+
97
+ const mockResults = {
98
+ head: {
99
+ vars: ["resource"],
100
+ },
101
+ results: {
102
+ bindings: [
103
+ {
104
+ resource: { type: "uri", value: "http://example.org/test" } as Parser.BindingValue,
105
+ },
106
+ ],
107
+ },
108
+ };
109
+
110
+ yasr.setResponse(
111
+ {
112
+ response: JSON.stringify(mockResults),
113
+ status: 200,
114
+ contentType: "application/sparql-results+json",
115
+ },
116
+ 0,
117
+ );
118
+
119
+ const tablePlugin = yasr.plugins["table"];
120
+ // Draw with prefixes enabled (default)
121
+ tablePlugin.draw({ showUriPrefixes: true });
122
+
123
+ const tableHtml = container.innerHTML;
124
+ expect(tableHtml).to.include("ex:test");
125
+ });
126
+
127
+ it("should show full URIs when prefixing disabled", () => {
128
+ const container = document.createElement("div");
129
+ const yasr = new Yasr(container, {
130
+ prefixes: {
131
+ ex: "http://example.org/",
132
+ },
133
+ });
134
+
135
+ const mockResults = {
136
+ head: {
137
+ vars: ["resource"],
138
+ },
139
+ results: {
140
+ bindings: [
141
+ {
142
+ resource: { type: "uri", value: "http://example.org/test" } as Parser.BindingValue,
143
+ },
144
+ ],
145
+ },
146
+ };
147
+
148
+ yasr.setResponse(
149
+ {
150
+ response: JSON.stringify(mockResults),
151
+ status: 200,
152
+ contentType: "application/sparql-results+json",
153
+ },
154
+ 0,
155
+ );
156
+
157
+ const tablePlugin = yasr.plugins["table"];
158
+ // Draw with prefixes disabled
159
+ tablePlugin.draw({ showUriPrefixes: false });
160
+
161
+ const tableHtml = container.innerHTML;
162
+ expect(tableHtml).to.include("http://example.org/test");
163
+ expect(tableHtml).to.not.include("ex:test");
164
+ });
165
+ });
166
+
167
+ describe("Datatype Display", () => {
168
+ it("should show datatypes when enabled", () => {
169
+ const container = document.createElement("div");
170
+ const yasr = new Yasr(container);
171
+
172
+ const mockResults = {
173
+ head: {
174
+ vars: ["number"],
175
+ },
176
+ results: {
177
+ bindings: [
178
+ {
179
+ number: {
180
+ type: "literal",
181
+ value: "42",
182
+ datatype: "http://www.w3.org/2001/XMLSchema#integer",
183
+ } as Parser.BindingValue,
184
+ },
185
+ ],
186
+ },
187
+ };
188
+
189
+ yasr.setResponse(
190
+ {
191
+ response: JSON.stringify(mockResults),
192
+ status: 200,
193
+ contentType: "application/sparql-results+json",
194
+ },
195
+ 0,
196
+ );
197
+
198
+ const tablePlugin = yasr.plugins["table"];
199
+ // Draw with datatypes enabled (default)
200
+ tablePlugin.draw({ showDatatypes: true });
201
+
202
+ const tableHtml = container.innerHTML;
203
+ expect(tableHtml).to.include("^^");
204
+ expect(tableHtml).to.include("XMLSchema#integer");
205
+ });
206
+
207
+ it("should hide datatypes when disabled", () => {
208
+ const container = document.createElement("div");
209
+ const yasr = new Yasr(container);
210
+
211
+ const mockResults = {
212
+ head: {
213
+ vars: ["number"],
214
+ },
215
+ results: {
216
+ bindings: [
217
+ {
218
+ number: {
219
+ type: "literal",
220
+ value: "42",
221
+ datatype: "http://www.w3.org/2001/XMLSchema#integer",
222
+ } as Parser.BindingValue,
223
+ },
224
+ ],
225
+ },
226
+ };
227
+
228
+ yasr.setResponse(
229
+ {
230
+ response: JSON.stringify(mockResults),
231
+ status: 200,
232
+ contentType: "application/sparql-results+json",
233
+ },
234
+ 0,
235
+ );
236
+
237
+ const tablePlugin = yasr.plugins["table"];
238
+ // Draw with datatypes disabled
239
+ tablePlugin.draw({ showDatatypes: false });
240
+
241
+ const tableHtml = container.innerHTML;
242
+ expect(tableHtml).to.not.include("^^");
243
+ expect(tableHtml).to.not.include("XMLSchema#integer");
244
+ });
245
+ });
246
+ });
@@ -0,0 +1,29 @@
1
+ declare module "column-resizer" {
2
+ interface ColumnResizerOptions {
3
+ liveDrag?: boolean;
4
+ draggingClass?: string;
5
+ gripInnerHtml?: string;
6
+ minWidth?: number;
7
+ headerOnly?: boolean;
8
+ hoverCursor?: string;
9
+ dragCursor?: string;
10
+ resizeMode?: "fit" | "overflow" | "flex";
11
+ widths?: number[];
12
+ partialRefresh?: boolean;
13
+ onResize?: (() => void) | boolean;
14
+ [key: string]: any;
15
+ }
16
+
17
+ interface ColumnResizerInstance {
18
+ reset(options: { disable: boolean; onResize?: () => void; partialRefresh?: boolean; headerOnly?: boolean }): void;
19
+ onResize: () => void;
20
+ }
21
+
22
+ class ColumnResizer implements ColumnResizerInstance {
23
+ constructor(table: HTMLElement, options?: ColumnResizerOptions);
24
+ reset(options: { disable: boolean; onResize?: () => void; partialRefresh?: boolean; headerOnly?: boolean }): void;
25
+ onResize: () => void;
26
+ }
27
+
28
+ export default ColumnResizer;
29
+ }
@@ -28,15 +28,34 @@ Delimiters used by datatables
28
28
  align-items: center;
29
29
  margin-right: 10px;
30
30
  }
31
+ .copyMarkdownBtn {
32
+ margin-right: 10px;
33
+ padding: 4px 8px;
34
+ cursor: pointer;
35
+ border: 1px solid var(--yasgui-border-color, #ddd);
36
+ background-color: var(--yasgui-bg-secondary, #f7f7f7);
37
+ color: var(--yasgui-text-primary, #000);
38
+ border-radius: 3px;
39
+ font-size: 0.9em;
40
+ white-space: nowrap;
41
+
42
+ &:hover {
43
+ background-color: var(--yasgui-bg-tertiary, #eee);
44
+ }
45
+
46
+ &:active {
47
+ background-color: var(--yasgui-bg-primary, #fff);
48
+ }
49
+ }
31
50
  }
32
- .dataTable.ellipseTable {
51
+ .dataTable.compactTable {
33
52
  white-space: nowrap;
34
53
  div:not(.expanded) {
35
54
  overflow: hidden;
36
55
  text-overflow: ellipsis;
37
56
  }
38
57
  }
39
- .dataTable:not(.ellipseTable) {
58
+ .dataTable:not(.compactTable) {
40
59
  div:not(.expanded) {
41
60
  word-break: break-all;
42
61
  }
@@ -52,7 +71,7 @@ Delimiters used by datatables
52
71
  }
53
72
  }
54
73
 
55
- .dataTables_wrapper {
74
+ .dt-container {
56
75
  font-size: 0.9em;
57
76
  min-width: 100%;
58
77
  .grip-container {
@@ -72,7 +91,7 @@ Delimiters used by datatables
72
91
  }
73
92
 
74
93
  tbody tr:hover {
75
- background-color: #f9f9f9;
94
+ background-color: var(--yasgui-bg-tertiary, #f9f9f9);
76
95
  }
77
96
 
78
97
  thead tr th {
@@ -92,7 +111,7 @@ Delimiters used by datatables
92
111
  padding-right: 18px; //space for sort icon
93
112
  }
94
113
  &:hover {
95
- background-color: #f9f9f9;
114
+ background-color: var(--yasgui-tab-bg, #f9f9f9);
96
115
  }
97
116
  }
98
117
 
@@ -119,35 +138,29 @@ Delimiters used by datatables
119
138
  /**
120
139
  Selector for pagination element
121
140
  */
122
- div.dataTables_paginate.paging_simple_numbers {
123
- a.paginate_button {
141
+ div.dt-paging {
142
+ button.dt-paging-button {
124
143
  border: none;
125
144
  background: transparent;
145
+ color: var(--yasgui-text-secondary, #505050);
126
146
 
127
147
  // When the buttons are disabled show the default YASR disabled color
128
- .disabled {
129
- color: #505050;
148
+ &.disabled {
149
+ color: var(--yasgui-text-muted, #999) !important;
130
150
  }
131
151
 
132
152
  &.current {
133
- border: none;
134
- background: transparent;
135
153
  text-decoration: underline !important; // dataTables made the text-decoration important
154
+ color: var(--yasgui-accent-color, #337ab7);
136
155
  }
137
156
 
138
157
  &:hover {
139
- border: none;
140
- background: transparent;
141
-
142
158
  // Don't override the disabled grayed out style
143
159
  &:not(.disabled) {
144
- color: black !important; // dataTables made the color important
160
+ font-weight: bold;
161
+ color: var(--yasgui-text-secondary, #505050) !important;
145
162
  }
146
163
  }
147
-
148
- &:active {
149
- box-shadow: none;
150
- }
151
164
  }
152
165
  }
153
166
  }