@ldforge/editor 0.1.9 → 1.1.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 +45 -0
- package/dist/controls.d.ts +3 -0
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +3 -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/editor-resize.d.ts +13 -0
- package/dist/editor-resize.d.ts.map +1 -0
- package/dist/editor-resize.js +121 -0
- package/dist/editor-resize.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +363 -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/analysis.d.ts +2 -0
- package/dist/sparql/analysis.d.ts.map +1 -1
- package/dist/sparql/analysis.js +54 -0
- package/dist/sparql/analysis.js.map +1 -1
- package/dist/sparql/completion.d.ts.map +1 -1
- package/dist/sparql/completion.js +7 -2
- package/dist/sparql/completion.js.map +1 -1
- package/dist/sparql/index.d.ts +1 -1
- package/dist/sparql/index.d.ts.map +1 -1
- package/dist/sparql/index.js +1 -1
- package/dist/sparql/index.js.map +1 -1
- package/dist/styles.css +541 -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 +73 -21
- package/docs/api/editor.md +190 -19
- package/docs/api/overview.md +8 -0
- package/docs/api/plugins.md +6 -2
- package/docs/api/prefixes.md +12 -11
- 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 +6 -0
- package/src/editor-height.ts +42 -0
- package/src/editor-resize.ts +150 -0
- package/src/index.ts +457 -30
- package/src/renderer-info.ts +52 -0
- package/src/renderer-wizard.ts +114 -25
- package/src/share.ts +125 -0
- package/src/sparql/analysis.ts +61 -0
- package/src/sparql/completion.ts +7 -2
- package/src/sparql/index.ts +5 -1
- package/src/styles.css +541 -82
- package/src/tab-api.ts +44 -4
- package/src/theme.ts +87 -0
package/src/tab-api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EditorState } from '@codemirror/state';
|
|
1
|
+
import { EditorState, type ChangeSpec } from '@codemirror/state';
|
|
2
2
|
import type { Locale } from '@ldforge/core';
|
|
3
3
|
import { translate } from '@ldforge/core';
|
|
4
4
|
import { prefixDeclarations } from './sparql/analysis.js';
|
|
@@ -30,6 +30,10 @@ export interface QueryTabHandle {
|
|
|
30
30
|
setQuery(query: string): void;
|
|
31
31
|
/** Lazy local formatting. Rejects on invalid syntax, deletion or newer text edits. */
|
|
32
32
|
formatQuery(options?: FormatOptions): Promise<string>;
|
|
33
|
+
/** Detached declared aliases; the last declaration wins for duplicate aliases. */
|
|
34
|
+
getPrefixes(): Record<string, string>;
|
|
35
|
+
/** Remove all declarations of an alias, leaving uses and surrounding text intact. */
|
|
36
|
+
removePrefix(prefix: string): void;
|
|
33
37
|
/** Returns the actual alias, or undefined for an unknown shorthand (with a warning). */
|
|
34
38
|
addPrefix(prefix: string, namespace?: string): string | undefined;
|
|
35
39
|
/** Trim and store a name; an empty name restores the localized default. */
|
|
@@ -56,7 +60,7 @@ export interface TabAdapter {
|
|
|
56
60
|
snapshot(): QueryWorkspace;
|
|
57
61
|
locale(): Locale;
|
|
58
62
|
assertAlive(): void;
|
|
59
|
-
setQuery(id: string, query: string): void;
|
|
63
|
+
setQuery(id: string, query: string, changes?: ChangeSpec): void;
|
|
60
64
|
rename(id: string, name: string): void;
|
|
61
65
|
activate(id: string): void;
|
|
62
66
|
delete(id: string): boolean;
|
|
@@ -69,7 +73,7 @@ export function queryWithPrefix(
|
|
|
69
73
|
query: string,
|
|
70
74
|
preferred: string,
|
|
71
75
|
namespace: string,
|
|
72
|
-
): { query: string; prefix: string } {
|
|
76
|
+
): { query: string; prefix: string; changes?: ChangeSpec } {
|
|
73
77
|
namespaceCatalog({ prefixes: { [preferred]: namespace } });
|
|
74
78
|
const state = EditorState.create({ doc: query });
|
|
75
79
|
const declared = prefixDeclarations(state);
|
|
@@ -83,6 +87,7 @@ export function queryWithPrefix(
|
|
|
83
87
|
return {
|
|
84
88
|
query: query.slice(0, edit.from) + edit.insert + query.slice(edit.from),
|
|
85
89
|
prefix,
|
|
90
|
+
changes: edit,
|
|
86
91
|
};
|
|
87
92
|
}
|
|
88
93
|
|
|
@@ -148,12 +153,47 @@ export function createTabApi(adapter: TabAdapter): {
|
|
|
148
153
|
if (formatted !== original) adapter.setQuery(id, formatted);
|
|
149
154
|
return formatted;
|
|
150
155
|
},
|
|
156
|
+
getPrefixes() {
|
|
157
|
+
return Object.fromEntries(
|
|
158
|
+
prefixDeclarations(EditorState.create({ doc: record(id).query })).map(
|
|
159
|
+
({ prefix, iri }) => [prefix, iri],
|
|
160
|
+
),
|
|
161
|
+
);
|
|
162
|
+
},
|
|
163
|
+
removePrefix(prefix: string) {
|
|
164
|
+
const original = record(id).query;
|
|
165
|
+
const declarations = prefixDeclarations(
|
|
166
|
+
EditorState.create({ doc: original }),
|
|
167
|
+
).filter((entry) => entry.prefix === prefix);
|
|
168
|
+
if (!declarations.length) return;
|
|
169
|
+
// A standalone declaration owns its line ending. Keep comments and
|
|
170
|
+
// other statements on shared lines intact.
|
|
171
|
+
let query = original;
|
|
172
|
+
const changes: { from: number; to: number }[] = [];
|
|
173
|
+
for (const declaration of declarations.reverse()) {
|
|
174
|
+
let { from, to } = declaration;
|
|
175
|
+
const lineStart = original.lastIndexOf('\n', from - 1) + 1;
|
|
176
|
+
const newline = original.indexOf('\n', to);
|
|
177
|
+
const lineEnd = newline < 0 ? original.length : newline;
|
|
178
|
+
if (
|
|
179
|
+
/^[ \t]*$/.test(original.slice(lineStart, from)) &&
|
|
180
|
+
/^[ \t\r]*$/.test(original.slice(to, lineEnd))
|
|
181
|
+
) {
|
|
182
|
+
from = lineStart;
|
|
183
|
+
to = newline < 0 ? lineEnd : newline + 1;
|
|
184
|
+
}
|
|
185
|
+
changes.push({ from, to });
|
|
186
|
+
query = query.slice(0, from) + query.slice(to);
|
|
187
|
+
}
|
|
188
|
+
adapter.setQuery(id, query, changes.reverse());
|
|
189
|
+
},
|
|
151
190
|
addPrefix(prefix: string, namespace?: string) {
|
|
152
191
|
const original = record(id).query;
|
|
153
192
|
const iri = resolve(prefix, namespace);
|
|
154
193
|
if (iri === undefined) return undefined;
|
|
155
194
|
const result = queryWithPrefix(original, prefix, iri);
|
|
156
|
-
if (result.query !== original)
|
|
195
|
+
if (result.query !== original)
|
|
196
|
+
adapter.setQuery(id, result.query, result.changes);
|
|
157
197
|
return result.prefix;
|
|
158
198
|
},
|
|
159
199
|
rename(title: string) {
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
type RGB = readonly [number, number, number];
|
|
2
|
+
|
|
3
|
+
function parseColor(value: string): RGB {
|
|
4
|
+
if (!/^#(?:[\da-f]{3}|[\da-f]{6})$/i.test(value))
|
|
5
|
+
throw new TypeError(
|
|
6
|
+
'themeMainColor must be an opaque #RGB or #RRGGBB color.',
|
|
7
|
+
);
|
|
8
|
+
const hex =
|
|
9
|
+
value.length === 4
|
|
10
|
+
? value
|
|
11
|
+
.slice(1)
|
|
12
|
+
.split('')
|
|
13
|
+
.map((digit) => digit + digit)
|
|
14
|
+
.join('')
|
|
15
|
+
: value.slice(1);
|
|
16
|
+
return [
|
|
17
|
+
Number.parseInt(hex.slice(0, 2), 16),
|
|
18
|
+
Number.parseInt(hex.slice(2, 4), 16),
|
|
19
|
+
Number.parseInt(hex.slice(4, 6), 16),
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
function mix(color: RGB, target: RGB, amount: number): RGB {
|
|
23
|
+
const channel = (index: 0 | 1 | 2) =>
|
|
24
|
+
Math.round(color[index] * (1 - amount) + target[index] * amount);
|
|
25
|
+
return [channel(0), channel(1), channel(2)];
|
|
26
|
+
}
|
|
27
|
+
function hex(color: RGB): string {
|
|
28
|
+
return (
|
|
29
|
+
'#' + color.map((value) => value.toString(16).padStart(2, '0')).join('')
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function luminance(color: RGB): number {
|
|
33
|
+
const linear = color.map((value) => {
|
|
34
|
+
const channel = value / 255;
|
|
35
|
+
return channel <= 0.04045
|
|
36
|
+
? channel / 12.92
|
|
37
|
+
: ((channel + 0.055) / 1.055) ** 2.4;
|
|
38
|
+
});
|
|
39
|
+
return (
|
|
40
|
+
(linear[0] ?? 0) * 0.2126 +
|
|
41
|
+
(linear[1] ?? 0) * 0.7152 +
|
|
42
|
+
(linear[2] ?? 0) * 0.0722
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const white: RGB = [255, 255, 255];
|
|
46
|
+
const black: RGB = [0, 0, 0];
|
|
47
|
+
|
|
48
|
+
/** Per-instance tokens. Undefined restores stylesheet defaults and host CSS overrides. */
|
|
49
|
+
export function themeTokens(value?: string): Record<string, string> {
|
|
50
|
+
if (value === undefined) return {};
|
|
51
|
+
const main = parseColor(value);
|
|
52
|
+
let ink = main;
|
|
53
|
+
// A 7:1 white contrast leaves room for the tinted selected/hover surfaces.
|
|
54
|
+
for (let step = 1; 1.05 / (luminance(ink) + 0.05) < 7 && step <= 20; step++)
|
|
55
|
+
ink = mix(main, black, step / 20);
|
|
56
|
+
const lightContrast = 1.05 / (luminance(main) + 0.05);
|
|
57
|
+
const darkContrast = (luminance(main) + 0.05) / 0.05;
|
|
58
|
+
return {
|
|
59
|
+
accent: hex(main),
|
|
60
|
+
'accent-fill': hex(main),
|
|
61
|
+
'on-accent': lightContrast >= darkContrast ? '#ffffff' : '#000000',
|
|
62
|
+
'accent-text': hex(ink),
|
|
63
|
+
text: hex(mix(main, black, 0.8)),
|
|
64
|
+
muted: hex(mix(ink, white, 0.12)),
|
|
65
|
+
surface: '#ffffff',
|
|
66
|
+
'surface-subtle': hex(mix(main, white, 0.97)),
|
|
67
|
+
'surface-tinted': hex(mix(main, white, 0.94)),
|
|
68
|
+
hover: hex(mix(main, white, 0.9)),
|
|
69
|
+
selected: hex(mix(main, white, 0.85)),
|
|
70
|
+
border: hex(mix(main, white, 0.72)),
|
|
71
|
+
'border-strong': hex(mix(main, white, 0.4)),
|
|
72
|
+
focus: hex(ink),
|
|
73
|
+
shadow: hex(mix(main, black, 0.65)) + '26',
|
|
74
|
+
backdrop: hex(mix(main, black, 0.65)) + '55',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function applyTheme(
|
|
79
|
+
root: HTMLElement,
|
|
80
|
+
previous: Record<string, string>,
|
|
81
|
+
next: Record<string, string>,
|
|
82
|
+
): void {
|
|
83
|
+
for (const name of Object.keys(previous))
|
|
84
|
+
root.style.removeProperty('--ldforge-' + name);
|
|
85
|
+
for (const [name, value] of Object.entries(next))
|
|
86
|
+
root.style.setProperty('--ldforge-' + name, value);
|
|
87
|
+
}
|