lit-rdf 0.2.1 → 0.2.2
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/CHANGELOG.md +7 -0
- package/package.json +26 -21
- package/src/components/resource-label.js +2 -1
- package/src/components/resource-value.d.ts +6 -0
- package/src/components/resource-value.js +22 -0
- package/src/context.d.ts +2 -1
- package/src/controllers/FocusNode.d.ts +1 -0
- package/src/controllers/FocusNode.js +3 -6
- package/src/converter.js +2 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/mixins/environment.js +0 -3
- package/src/mixins/graph.js +0 -3
- package/src/sort.d.ts +6 -0
- package/src/sort.js +62 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lit-rdf",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "husky",
|
|
7
|
-
"lint": "eslint . --quiet
|
|
7
|
+
"lint": "eslint . --quiet",
|
|
8
8
|
"storybook": "storybook dev -p 6006",
|
|
9
9
|
"build-storybook": "storybook build",
|
|
10
|
-
"test": "vitest --project=storybook",
|
|
10
|
+
"test:storybook": "vitest --project=storybook",
|
|
11
|
+
"test:unit": "vitest",
|
|
11
12
|
"build": "tsc",
|
|
12
13
|
"prepack": "npm run build",
|
|
13
14
|
"release": "changeset publish"
|
|
@@ -28,7 +29,8 @@
|
|
|
28
29
|
"./constructor.js": "./src/constructor.js",
|
|
29
30
|
"./mixins.js": "./src/mixins.js",
|
|
30
31
|
"./controllers.js": "./src/controllers.js",
|
|
31
|
-
"./runtime/*.js": "./src/runtime/*.js"
|
|
32
|
+
"./runtime/*.js": "./src/runtime/*.js",
|
|
33
|
+
"./sort.js": "./src/sort.js"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
36
|
"@lit/context": "^1.1.6",
|
|
@@ -41,35 +43,38 @@
|
|
|
41
43
|
"clownface-shacl-path": "^2.4.0",
|
|
42
44
|
"is-url": "^1.2.4",
|
|
43
45
|
"lit": "^3",
|
|
46
|
+
"rdf-literal": "^2.0.0",
|
|
44
47
|
"sparql-path-parser": "^0.1.1"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
|
-
"@changesets/cli": "^
|
|
48
|
-
"@chromatic-com/storybook": "^5.0
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@storybook/
|
|
53
|
-
"@
|
|
50
|
+
"@changesets/cli": "^3.0.0-next.11",
|
|
51
|
+
"@chromatic-com/storybook": "^5.3.0",
|
|
52
|
+
"@eslint/config-helpers": "^0.7.0",
|
|
53
|
+
"@eslint/js": "^10",
|
|
54
|
+
"@rolldown/plugin-node-polyfills": "^1.0.3",
|
|
55
|
+
"@storybook/addon-docs": "^10.6.0",
|
|
56
|
+
"@storybook/addon-vitest": "^10.6.0",
|
|
57
|
+
"@storybook/web-components-vite": "^10.6.0",
|
|
58
|
+
"@tpluscode/eslint-config": "^3.0.1",
|
|
54
59
|
"@types/clownface": "^2.0.10",
|
|
55
60
|
"@types/is-url": "^1.2.32",
|
|
56
61
|
"@types/rdfjs__data-model": "^2.0.9",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
58
|
-
"@typescript-eslint/parser": "^
|
|
59
|
-
"@vitest/browser-playwright": "^4.
|
|
60
|
-
"@vitest/coverage-v8": "^4.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^8.66.0",
|
|
63
|
+
"@typescript-eslint/parser": "^8.66.0",
|
|
64
|
+
"@vitest/browser-playwright": "^4.1.11",
|
|
65
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
61
66
|
"@vocabulary/rdfs": "^1.0.6",
|
|
62
|
-
"eslint
|
|
63
|
-
"eslint-
|
|
67
|
+
"eslint": "^10",
|
|
68
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
69
|
+
"eslint-plugin-storybook": "^10.5.7",
|
|
64
70
|
"husky": "^9.1.7",
|
|
65
|
-
"lint-staged": "^
|
|
71
|
+
"lint-staged": "^17.3.0",
|
|
66
72
|
"playwright": "^1.58.2",
|
|
67
|
-
"
|
|
68
|
-
"storybook": "^10.2.12",
|
|
73
|
+
"storybook": "^10.6.0",
|
|
69
74
|
"string-to-stream": "^3.0.1",
|
|
70
75
|
"typescript": "^5",
|
|
71
76
|
"util": "^0.12.5",
|
|
72
|
-
"vitest": "^4.
|
|
77
|
+
"vitest": "^4.1.11"
|
|
73
78
|
},
|
|
74
79
|
"lint-staged": {
|
|
75
80
|
"*.{js,ts}": [
|
|
@@ -20,7 +20,8 @@ let ResourceLabel = class ResourceLabel extends LitElement {
|
|
|
20
20
|
if (!this.focusNode.pointer) {
|
|
21
21
|
return html ``;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
const fallback = this.focusNode.pointer.out(this.predicate).value;
|
|
24
|
+
return html `${localizedLabel(this.focusNode.pointer, { property: this.predicate, fallback })}`;
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
27
|
__decorate([
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement } from 'lit';
|
|
8
|
+
import { FocusNode } from 'lit-rdf/controllers.js';
|
|
9
|
+
import { customElement } from 'lit/decorators.js';
|
|
10
|
+
let ResourceValue = class ResourceValue extends LitElement {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.focusNode = new FocusNode(this);
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
return this.focusNode.pointer?.value;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
ResourceValue = __decorate([
|
|
20
|
+
customElement('resource-value')
|
|
21
|
+
], ResourceValue);
|
|
22
|
+
export default ResourceValue;
|
package/src/context.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AnyPointer, GraphPointer, MultiPointer } from 'clownface';
|
|
2
2
|
import type env from '@zazuko/env/web.js';
|
|
3
|
+
import type { Term } from '@rdfjs/types';
|
|
3
4
|
export type Environment = typeof env;
|
|
4
5
|
export interface SortPredicate {
|
|
5
|
-
(node: GraphPointer): string | undefined;
|
|
6
|
+
(node: GraphPointer): Term | string | number | boolean | undefined;
|
|
6
7
|
}
|
|
7
8
|
export declare const environment: {
|
|
8
9
|
__context__: import("@zazuko/env-core").DerivedEnvironment<import("@rdfjs/environment/Environment").Environment<import("@rdfjs/data-model/Factory").default | import("@rdfjs/formats/Factory").FormatsFactory | import("@rdfjs/term-map/Factory").TermMapFactory | import("@tpluscode/rdf-ns-builders").default | import("clownface/Factory").default | import("@rdfjs/term-set/Factory").TermSetFactory | import("@rdfjs/namespace/Factory").NamespaceFactory | import("@rdfjs/traverser/Factory").TraverserFactory>, import("@rdfjs/environment/Environment").Environment<{
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ContextConsumer } from '@lit/context';
|
|
2
2
|
import { focusNode, sortPredicate, sortDirection } from '../context.js';
|
|
3
|
+
import { sort } from '../sort.js';
|
|
4
|
+
export { sort } from '../sort.js';
|
|
3
5
|
export class FocusNode {
|
|
4
6
|
constructor(host) {
|
|
5
7
|
this.focusNodeConsumer = new ContextConsumer(host, {
|
|
@@ -34,11 +36,6 @@ export class FocusNode {
|
|
|
34
36
|
if (!array || !sortPredicateFunc) {
|
|
35
37
|
return array;
|
|
36
38
|
}
|
|
37
|
-
return array.sort((
|
|
38
|
-
if (sortDirectionValue === 'desc') {
|
|
39
|
-
return sortPredicateFunc(right)?.localeCompare(sortPredicateFunc(left) || '') || 0;
|
|
40
|
-
}
|
|
41
|
-
return sortPredicateFunc(left)?.localeCompare(sortPredicateFunc(right) || '') || 0;
|
|
42
|
-
});
|
|
39
|
+
return array.sort(sort(sortPredicateFunc, sortDirectionValue));
|
|
43
40
|
}
|
|
44
41
|
}
|
package/src/converter.js
CHANGED
|
@@ -17,7 +17,7 @@ export const toNamedNode = {
|
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
19
|
export const toPropertyPath = {
|
|
20
|
-
fromAttribute(value
|
|
20
|
+
fromAttribute(value) {
|
|
21
21
|
if (typeof value === 'undefined' || value === null) {
|
|
22
22
|
throw new Error('PropertyPath converter: value is null');
|
|
23
23
|
}
|
|
@@ -28,7 +28,7 @@ export const toSortPredicate = {
|
|
|
28
28
|
fromAttribute(value) {
|
|
29
29
|
const namedNode = toNamedNode.fromAttribute(value);
|
|
30
30
|
return (node) => {
|
|
31
|
-
return node.out(namedNode).
|
|
31
|
+
return node.out(namedNode).term;
|
|
32
32
|
};
|
|
33
33
|
},
|
|
34
34
|
};
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
package/src/mixins/graph.js
CHANGED
|
@@ -9,9 +9,6 @@ import { state } from 'lit/decorators.js';
|
|
|
9
9
|
import { dataset } from '../context.js';
|
|
10
10
|
export function provideGraph(base) {
|
|
11
11
|
class WithGraphProvider extends base {
|
|
12
|
-
constructor(...args) {
|
|
13
|
-
super(...args);
|
|
14
|
-
}
|
|
15
12
|
}
|
|
16
13
|
__decorate([
|
|
17
14
|
provide({ context: dataset }),
|
package/src/sort.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GraphPointer } from 'clownface';
|
|
2
|
+
import type { Term } from '@rdfjs/types';
|
|
3
|
+
import type { SortPredicate } from './context.js';
|
|
4
|
+
export declare function toComparable(value: Term | string | number | boolean | undefined | null): unknown;
|
|
5
|
+
export declare function compareValues(left: unknown, right: unknown): number;
|
|
6
|
+
export declare function sort(getValue: SortPredicate, direction?: 'asc' | 'desc'): (left: GraphPointer, right: GraphPointer) => number;
|
package/src/sort.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { fromRdf } from 'rdf-literal';
|
|
2
|
+
export function toComparable(value) {
|
|
3
|
+
if (value === undefined || value === null) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
if (typeof value === 'object' && 'termType' in value) {
|
|
7
|
+
if (value.termType === 'Literal') {
|
|
8
|
+
return fromRdf(value);
|
|
9
|
+
}
|
|
10
|
+
return value.value;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
export function compareValues(left, right) {
|
|
15
|
+
if (left === right) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
if ((left === undefined || left === null) && (right === undefined || right === null)) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
if (left === undefined || left === null) {
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
if (right === undefined || right === null) {
|
|
25
|
+
return -1;
|
|
26
|
+
}
|
|
27
|
+
if (typeof left === 'string' && typeof right === 'string') {
|
|
28
|
+
return left.localeCompare(right);
|
|
29
|
+
}
|
|
30
|
+
if (typeof left === 'number' && typeof right === 'number') {
|
|
31
|
+
return left - right;
|
|
32
|
+
}
|
|
33
|
+
if (typeof left === 'boolean' && typeof right === 'boolean') {
|
|
34
|
+
return Number(left) - Number(right);
|
|
35
|
+
}
|
|
36
|
+
if (left instanceof Date && right instanceof Date) {
|
|
37
|
+
return left.getTime() - right.getTime();
|
|
38
|
+
}
|
|
39
|
+
if (left < right) {
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
if (left > right) {
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
export function sort(getValue, direction = 'asc') {
|
|
48
|
+
return (left, right) => {
|
|
49
|
+
const leftValue = toComparable(getValue(left));
|
|
50
|
+
const rightValue = toComparable(getValue(right));
|
|
51
|
+
const leftEmpty = leftValue === undefined || leftValue === null;
|
|
52
|
+
const rightEmpty = rightValue === undefined || rightValue === null;
|
|
53
|
+
if (leftEmpty && rightEmpty)
|
|
54
|
+
return 0;
|
|
55
|
+
if (leftEmpty)
|
|
56
|
+
return 1;
|
|
57
|
+
if (rightEmpty)
|
|
58
|
+
return -1;
|
|
59
|
+
const result = compareValues(leftValue, rightValue);
|
|
60
|
+
return direction === 'desc' ? -result : result;
|
|
61
|
+
};
|
|
62
|
+
}
|