@ldforge/editor 0.1.8 → 1.0.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/README.md +37 -0
- package/dist/controls.d.ts +2 -0
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +2 -0
- package/dist/controls.js.map +1 -1
- package/dist/editor-height.d.ts +8 -0
- package/dist/editor-height.d.ts.map +1 -0
- package/dist/editor-height.js +34 -0
- package/dist/editor-height.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +347 -33
- package/dist/index.js.map +1 -1
- package/dist/renderer-info.d.ts +4 -0
- package/dist/renderer-info.d.ts.map +1 -0
- package/dist/renderer-info.js +41 -0
- package/dist/renderer-info.js.map +1 -0
- package/dist/renderer-wizard.d.ts.map +1 -1
- package/dist/renderer-wizard.js +109 -25
- package/dist/renderer-wizard.js.map +1 -1
- package/dist/share.d.ts +16 -0
- package/dist/share.d.ts.map +1 -0
- package/dist/share.js +113 -0
- package/dist/share.js.map +1 -0
- package/dist/sparql/completion.d.ts.map +1 -1
- package/dist/sparql/completion.js +5 -0
- package/dist/sparql/completion.js.map +1 -1
- package/dist/styles.css +496 -82
- package/dist/tab-api.d.ts +7 -1
- package/dist/tab-api.d.ts.map +1 -1
- package/dist/tab-api.js +29 -1
- package/dist/tab-api.js.map +1 -1
- package/dist/theme.d.ts +4 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +73 -0
- package/dist/theme.js.map +1 -0
- package/docs/api/configuration.md +72 -21
- package/docs/api/editor.md +184 -19
- package/docs/api/overview.md +8 -0
- package/docs/api/plugins.md +6 -2
- package/docs/api/tab.md +37 -9
- package/docs/api/transport.md +19 -2
- package/docs/renderers.md +29 -1
- package/package.json +3 -3
- package/src/controls.ts +4 -0
- package/src/editor-height.ts +42 -0
- package/src/index.ts +440 -30
- package/src/renderer-info.ts +52 -0
- package/src/renderer-wizard.ts +114 -25
- package/src/share.ts +125 -0
- package/src/sparql/completion.ts +5 -0
- package/src/styles.css +496 -82
- package/src/tab-api.ts +44 -4
- package/src/theme.ts +87 -0
package/src/renderer-wizard.ts
CHANGED
|
@@ -46,6 +46,10 @@ const messages = {
|
|
|
46
46
|
noContract: 'This renderer does not declare a binding contract.',
|
|
47
47
|
changed: 'The active query changed. Reopen the wizard to apply a header.',
|
|
48
48
|
step: 'Step',
|
|
49
|
+
hint: 'Choose how to display your query results.',
|
|
50
|
+
bindings: 'Query variables',
|
|
51
|
+
required: 'Required',
|
|
52
|
+
optional: 'Optional',
|
|
49
53
|
},
|
|
50
54
|
nl: {
|
|
51
55
|
title: 'Plugin wizard',
|
|
@@ -65,6 +69,10 @@ const messages = {
|
|
|
65
69
|
changed:
|
|
66
70
|
'De actieve query is gewijzigd. Open de wizard opnieuw om een header toe te passen.',
|
|
67
71
|
step: 'Stap',
|
|
72
|
+
hint: 'Kies hoe je de resultaten van je query wilt weergeven.',
|
|
73
|
+
bindings: 'Queryvariabelen',
|
|
74
|
+
required: 'Verplicht',
|
|
75
|
+
optional: 'Optioneel',
|
|
68
76
|
},
|
|
69
77
|
};
|
|
70
78
|
export function createRendererWizard(host: Host) {
|
|
@@ -92,15 +100,25 @@ export function createRendererWizard(host: Host) {
|
|
|
92
100
|
dialog.id = `${heading.id}-dialog`;
|
|
93
101
|
button.setAttribute('aria-controls', dialog.id);
|
|
94
102
|
dialog.setAttribute('aria-labelledby', heading.id);
|
|
103
|
+
const progress = doc.createElement('ol');
|
|
104
|
+
progress.className = 'ldforge-wizard-progress';
|
|
95
105
|
const content = doc.createElement('div');
|
|
106
|
+
content.className = 'ldforge-wizard-content';
|
|
96
107
|
const footer = doc.createElement('div');
|
|
97
108
|
footer.className = 'ldforge-wizard-actions';
|
|
98
109
|
const error = doc.createElement('p');
|
|
99
110
|
error.setAttribute('role', 'alert');
|
|
100
|
-
dialog.append(heading, content, error, footer);
|
|
111
|
+
dialog.append(heading, progress, content, error, footer);
|
|
101
112
|
function config(): RendererHeaderConfig {
|
|
102
113
|
return { rendererId, options: values, includeBindings };
|
|
103
114
|
}
|
|
115
|
+
function focusStep() {
|
|
116
|
+
const target =
|
|
117
|
+
content.querySelector<HTMLElement>('input[type=radio]:checked') ??
|
|
118
|
+
content.querySelector<HTMLElement>('select,input,textarea,button') ??
|
|
119
|
+
footer.querySelector<HTMLElement>('button');
|
|
120
|
+
target?.focus();
|
|
121
|
+
}
|
|
104
122
|
function close() {
|
|
105
123
|
if (!opened) return;
|
|
106
124
|
opened = false;
|
|
@@ -159,7 +177,7 @@ export function createRendererWizard(host: Host) {
|
|
|
159
177
|
open() {
|
|
160
178
|
host.assertAlive();
|
|
161
179
|
if (opened) {
|
|
162
|
-
|
|
180
|
+
focusStep();
|
|
163
181
|
return;
|
|
164
182
|
}
|
|
165
183
|
host.onOpen();
|
|
@@ -194,13 +212,24 @@ export function createRendererWizard(host: Host) {
|
|
|
194
212
|
draw();
|
|
195
213
|
if (typeof dialog.showModal === 'function') dialog.showModal();
|
|
196
214
|
else dialog.setAttribute('open', '');
|
|
197
|
-
|
|
215
|
+
focusStep();
|
|
198
216
|
},
|
|
199
217
|
});
|
|
200
218
|
function draw() {
|
|
201
219
|
const locale = host.getLocale();
|
|
202
220
|
const text = messages[locale];
|
|
203
|
-
heading.textContent =
|
|
221
|
+
heading.textContent = text.title;
|
|
222
|
+
progress.setAttribute('aria-label', text.step);
|
|
223
|
+
progress.replaceChildren();
|
|
224
|
+
[text.choose, text.options, text.preview].forEach((label, index) => {
|
|
225
|
+
const item = doc.createElement('li');
|
|
226
|
+
if (index === step) item.setAttribute('aria-current', 'step');
|
|
227
|
+
item.dataset.complete = String(index < step);
|
|
228
|
+
const number = doc.createElement('span');
|
|
229
|
+
number.textContent = String(index + 1);
|
|
230
|
+
item.append(number, label);
|
|
231
|
+
progress.append(item);
|
|
232
|
+
});
|
|
204
233
|
button.title = text.title;
|
|
205
234
|
button.setAttribute('aria-label', text.title);
|
|
206
235
|
content.replaceChildren();
|
|
@@ -217,6 +246,9 @@ export function createRendererWizard(host: Host) {
|
|
|
217
246
|
control.type = 'button';
|
|
218
247
|
control.textContent = label;
|
|
219
248
|
control.addEventListener('click', run);
|
|
249
|
+
if (label === text.close) control.className = 'ldforge-wizard-close';
|
|
250
|
+
if (label === text.next || label === text.apply)
|
|
251
|
+
control.className = 'ldforge-wizard-primary';
|
|
220
252
|
footer.append(control);
|
|
221
253
|
return control;
|
|
222
254
|
}
|
|
@@ -228,23 +260,47 @@ export function createRendererWizard(host: Host) {
|
|
|
228
260
|
return;
|
|
229
261
|
}
|
|
230
262
|
if (step === 0) {
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
263
|
+
const hint = doc.createElement('p');
|
|
264
|
+
hint.className = 'ldforge-wizard-hint';
|
|
265
|
+
hint.textContent = text.hint;
|
|
266
|
+
const choices = doc.createElement('div');
|
|
267
|
+
choices.className = 'ldforge-wizard-renderers';
|
|
268
|
+
choices.setAttribute('role', 'radiogroup');
|
|
269
|
+
choices.setAttribute('aria-label', text.renderer);
|
|
270
|
+
for (const item of renderers) {
|
|
271
|
+
const card = doc.createElement('label');
|
|
272
|
+
card.className = 'ldforge-wizard-renderer';
|
|
273
|
+
const input = doc.createElement('input');
|
|
274
|
+
input.type = 'radio';
|
|
275
|
+
input.name = `${dialog.id}-renderer`;
|
|
276
|
+
input.value = item.id;
|
|
277
|
+
input.checked = rendererId === item.id;
|
|
278
|
+
input.setAttribute('aria-label', localize(item.label, locale));
|
|
279
|
+
input.addEventListener('change', () => {
|
|
280
|
+
rendererId = item.id;
|
|
281
|
+
values = {};
|
|
282
|
+
for (const option of item.wizard?.options ?? [])
|
|
283
|
+
values[option.key] =
|
|
284
|
+
option.defaultValue ?? option.choices?.[0]?.value ?? '';
|
|
285
|
+
});
|
|
286
|
+
const icon = doc.createElement('span');
|
|
287
|
+
icon.className = 'ldforge-wizard-renderer-icon';
|
|
288
|
+
icon.setAttribute('aria-hidden', 'true');
|
|
289
|
+
if (item.icon) icon.append(item.icon(doc));
|
|
290
|
+
const body = doc.createElement('span');
|
|
291
|
+
const name = doc.createElement('strong');
|
|
292
|
+
name.textContent = localize(item.label, locale);
|
|
293
|
+
body.append(name);
|
|
294
|
+
if (item.wizard?.description) {
|
|
295
|
+
const description = doc.createElement('span');
|
|
296
|
+
description.className = 'ldforge-wizard-renderer-description';
|
|
297
|
+
description.textContent = localize(item.wizard.description, locale);
|
|
298
|
+
body.append(description);
|
|
299
|
+
}
|
|
300
|
+
card.append(input, icon, body);
|
|
301
|
+
choices.append(card);
|
|
302
|
+
}
|
|
303
|
+
content.append(hint, choices);
|
|
248
304
|
}
|
|
249
305
|
if (step === 1) {
|
|
250
306
|
if (renderer.wizard?.description) {
|
|
@@ -289,6 +345,29 @@ export function createRendererWizard(host: Host) {
|
|
|
289
345
|
label.append(input);
|
|
290
346
|
content.append(label);
|
|
291
347
|
}
|
|
348
|
+
if (renderer.wizard?.bindings.length) {
|
|
349
|
+
const contract = doc.createElement('section');
|
|
350
|
+
contract.className = 'ldforge-wizard-bindings';
|
|
351
|
+
const heading = doc.createElement('h4');
|
|
352
|
+
heading.textContent = text.bindings;
|
|
353
|
+
const list = doc.createElement('dl');
|
|
354
|
+
for (const binding of renderer.wizard.bindings) {
|
|
355
|
+
const row = doc.createElement('div');
|
|
356
|
+
const name = doc.createElement('dt');
|
|
357
|
+
const code = doc.createElement('code');
|
|
358
|
+
code.textContent = `?${binding.variable}`;
|
|
359
|
+
const badge = doc.createElement('span');
|
|
360
|
+
badge.textContent = binding.required ? text.required : text.optional;
|
|
361
|
+
badge.dataset.required = String(binding.required);
|
|
362
|
+
name.append(code, badge);
|
|
363
|
+
const description = doc.createElement('dd');
|
|
364
|
+
description.textContent = localize(binding.description, locale);
|
|
365
|
+
row.append(name, description);
|
|
366
|
+
list.append(row);
|
|
367
|
+
}
|
|
368
|
+
contract.append(heading, list);
|
|
369
|
+
content.append(contract);
|
|
370
|
+
}
|
|
292
371
|
}
|
|
293
372
|
if (step === 2) {
|
|
294
373
|
const label = doc.createElement('label');
|
|
@@ -328,14 +407,16 @@ export function createRendererWizard(host: Host) {
|
|
|
328
407
|
action(text.back, () => {
|
|
329
408
|
step--;
|
|
330
409
|
draw();
|
|
331
|
-
|
|
410
|
+
focusStep();
|
|
332
411
|
});
|
|
333
412
|
if (step < 2)
|
|
334
413
|
action(text.next, () => {
|
|
335
414
|
step++;
|
|
336
415
|
draw();
|
|
337
416
|
dialog
|
|
338
|
-
.querySelector<HTMLElement>(
|
|
417
|
+
.querySelector<HTMLElement>(
|
|
418
|
+
'input:checked,select,input,textarea,button',
|
|
419
|
+
)
|
|
339
420
|
?.focus();
|
|
340
421
|
});
|
|
341
422
|
else
|
|
@@ -365,8 +446,16 @@ export function createRendererWizard(host: Host) {
|
|
|
365
446
|
}
|
|
366
447
|
if (event.key === 'Tab') {
|
|
367
448
|
const items = [
|
|
368
|
-
...dialog.querySelectorAll<HTMLElement>(
|
|
369
|
-
|
|
449
|
+
...dialog.querySelectorAll<HTMLElement>(
|
|
450
|
+
'input:checked,select,input,textarea,button',
|
|
451
|
+
),
|
|
452
|
+
].filter(
|
|
453
|
+
(item) =>
|
|
454
|
+
!item.hasAttribute('disabled') &&
|
|
455
|
+
(!(item instanceof HTMLInputElement) ||
|
|
456
|
+
item.type !== 'radio' ||
|
|
457
|
+
item.checked),
|
|
458
|
+
);
|
|
370
459
|
const first = items[0],
|
|
371
460
|
last = items.at(-1);
|
|
372
461
|
if (event.shiftKey && doc.activeElement === first) {
|
package/src/share.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createSvgIcon, parseQueryViewDirectives } from '@ldforge/core';
|
|
2
|
+
import type { Locale } from '@ldforge/core';
|
|
3
|
+
|
|
4
|
+
/** Keep existing options/comments and make the selected renderer authoritative. */
|
|
5
|
+
export function queryWithRenderer(query: string, rendererId?: string): string {
|
|
6
|
+
return queryWithDirective(query, 'view', rendererId);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function queryWithEndpoint(query: string, endpoint?: string): string {
|
|
10
|
+
if (parseQueryViewDirectives(query)['sparql-endpoint']) return query;
|
|
11
|
+
return queryWithDirective(query, 'sparql-endpoint', endpoint);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function queryWithDirective(
|
|
15
|
+
query: string,
|
|
16
|
+
key: string,
|
|
17
|
+
value?: string,
|
|
18
|
+
): string {
|
|
19
|
+
if (!value || parseQueryViewDirectives(query)[key] === value) return query;
|
|
20
|
+
const lines = query.replace(/^\uFEFF/, '').split(/\r?\n/);
|
|
21
|
+
let end = 0;
|
|
22
|
+
while (
|
|
23
|
+
end < lines.length &&
|
|
24
|
+
(!lines[end]?.trim() || lines[end]?.trimStart().startsWith('#'))
|
|
25
|
+
)
|
|
26
|
+
end++;
|
|
27
|
+
const quote = (value: string) =>
|
|
28
|
+
/^[\w.-]+$/.test(value) ? value : JSON.stringify(value);
|
|
29
|
+
let replaced = false;
|
|
30
|
+
for (let index = 0; index < end; index++) {
|
|
31
|
+
const directives = parseQueryViewDirectives(lines[index] ?? '');
|
|
32
|
+
if (directives[key] === undefined) continue;
|
|
33
|
+
lines[index] =
|
|
34
|
+
'# ' +
|
|
35
|
+
Object.entries(directives)
|
|
36
|
+
.map(
|
|
37
|
+
([name, existing]) =>
|
|
38
|
+
`${name}=${quote(name === key ? value : (existing ?? ''))}`,
|
|
39
|
+
)
|
|
40
|
+
.join('; ');
|
|
41
|
+
replaced = true;
|
|
42
|
+
}
|
|
43
|
+
if (!replaced) lines.splice(end, 0, `# ${key}=${quote(value)}`);
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createShareLink(baseUrl: string, query: string): string {
|
|
48
|
+
const url = new URL(baseUrl);
|
|
49
|
+
if (!url.hash.startsWith('#/')) url.hash = '';
|
|
50
|
+
url.searchParams.set('query', query);
|
|
51
|
+
return url.href;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createShareControl(host: {
|
|
55
|
+
tools: HTMLElement;
|
|
56
|
+
visible: boolean;
|
|
57
|
+
getLocale(): Locale;
|
|
58
|
+
copy(): Promise<string>;
|
|
59
|
+
onError(error: unknown): void;
|
|
60
|
+
}) {
|
|
61
|
+
const doc = host.tools.ownerDocument;
|
|
62
|
+
const button = doc.createElement('button');
|
|
63
|
+
button.type = 'button';
|
|
64
|
+
button.className = 'ldforge-share-toggle';
|
|
65
|
+
const live = doc.createElement('span');
|
|
66
|
+
live.className = 'ldforge-sr-only';
|
|
67
|
+
live.setAttribute('role', 'status');
|
|
68
|
+
let copied = false;
|
|
69
|
+
let pending = false;
|
|
70
|
+
let disposed = false;
|
|
71
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
72
|
+
function refreshLocale() {
|
|
73
|
+
const nl = host.getLocale() === 'nl';
|
|
74
|
+
const label = copied
|
|
75
|
+
? nl
|
|
76
|
+
? 'Link gekopieerd'
|
|
77
|
+
: 'Link copied'
|
|
78
|
+
: nl
|
|
79
|
+
? 'Deellink kopiëren'
|
|
80
|
+
: 'Copy share link';
|
|
81
|
+
button.title = label;
|
|
82
|
+
button.setAttribute('aria-label', label);
|
|
83
|
+
button.dataset.copied = String(copied);
|
|
84
|
+
const icon = createSvgIcon(
|
|
85
|
+
copied
|
|
86
|
+
? ['M5 12l4 4L19 6']
|
|
87
|
+
: [
|
|
88
|
+
'M12 16V3m-5 5 5-5 5 5',
|
|
89
|
+
'M5 13v7a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-7',
|
|
90
|
+
],
|
|
91
|
+
)(doc);
|
|
92
|
+
button.replaceChildren(icon);
|
|
93
|
+
live.textContent = copied ? label : '';
|
|
94
|
+
}
|
|
95
|
+
button.onclick = async () => {
|
|
96
|
+
if (pending) return;
|
|
97
|
+
pending = true;
|
|
98
|
+
try {
|
|
99
|
+
await host.copy();
|
|
100
|
+
if (disposed) return;
|
|
101
|
+
copied = true;
|
|
102
|
+
refreshLocale();
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
timer = setTimeout(() => {
|
|
105
|
+
copied = false;
|
|
106
|
+
refreshLocale();
|
|
107
|
+
}, 1800);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (!disposed) host.onError(error);
|
|
110
|
+
} finally {
|
|
111
|
+
pending = false;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
if (host.visible) host.tools.append(button, live);
|
|
115
|
+
refreshLocale();
|
|
116
|
+
return {
|
|
117
|
+
refreshLocale,
|
|
118
|
+
destroy() {
|
|
119
|
+
disposed = true;
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
button.remove();
|
|
122
|
+
live.remove();
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
package/src/sparql/completion.ts
CHANGED
|
@@ -37,6 +37,11 @@ export function prefixEdit(
|
|
|
37
37
|
at = Math.max(at, node.to);
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
|
+
// Insert after the declaration's line ending (and any trailing comment),
|
|
41
|
+
// rather than before it and leaving an extra blank line on every insertion.
|
|
42
|
+
const lineEnd = source.indexOf('\n', at);
|
|
43
|
+
if (lineEnd >= 0 && /^[ \t]*(?:#[^\n]*)?$/.test(source.slice(at, lineEnd)))
|
|
44
|
+
at = lineEnd + 1;
|
|
40
45
|
return {
|
|
41
46
|
from: at,
|
|
42
47
|
insert: `${at > 0 && state.sliceDoc(at - 1, at) !== '\n' ? '\n' : ''}PREFIX ${prefix}: <${iri}>\n`,
|