lit-rdf 0.2.0 → 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 +13 -0
- package/package.json +27 -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/components/target-node.d.ts +3 -2
- package/src/components/target-node.js +12 -4
- package/src/context.d.ts +13 -7
- package/src/context.js +2 -1
- package/src/controllers/FocusNode.d.ts +3 -1
- package/src/controllers/FocusNode.js +16 -8
- package/src/converter.d.ts +6 -1
- package/src/converter.js +9 -1
- 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
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# lit-rdf
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- af27103: Sorting numeric literals is now correctly based on value and not plain literal form
|
|
8
|
+
- af27103: Added `<resource-value>` component
|
|
9
|
+
|
|
10
|
+
## 0.2.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 02c819c: Added `order-dir` and function-based `orderBy` to `<target-node>`
|
|
15
|
+
|
|
3
16
|
## 0.2.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
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,34 +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.
|
|
61
|
-
"
|
|
62
|
-
"eslint
|
|
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",
|
|
66
|
+
"@vocabulary/rdfs": "^1.0.6",
|
|
67
|
+
"eslint": "^10",
|
|
68
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
69
|
+
"eslint-plugin-storybook": "^10.5.7",
|
|
63
70
|
"husky": "^9.1.7",
|
|
64
|
-
"lint-staged": "^
|
|
71
|
+
"lint-staged": "^17.3.0",
|
|
65
72
|
"playwright": "^1.58.2",
|
|
66
|
-
"
|
|
67
|
-
"storybook": "^10.2.12",
|
|
73
|
+
"storybook": "^10.6.0",
|
|
68
74
|
"string-to-stream": "^3.0.1",
|
|
69
75
|
"typescript": "^5",
|
|
70
76
|
"util": "^0.12.5",
|
|
71
|
-
"vitest": "^4.
|
|
77
|
+
"vitest": "^4.1.11"
|
|
72
78
|
},
|
|
73
79
|
"lint-staged": {
|
|
74
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;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SortPredicate } from '../context.js';
|
|
3
3
|
declare const default_base: typeof LitElement & import("../constructor.js").LitElementConstructor<import("../constructor.js").WithFocusNode & import("../mixins/targetNode.js").WithTargets>;
|
|
4
4
|
export default class extends default_base {
|
|
5
5
|
static styles: import("lit").CSSResult;
|
|
6
|
-
orderBy:
|
|
6
|
+
orderBy: SortPredicate | undefined;
|
|
7
|
+
orderDir: 'asc' | 'desc';
|
|
7
8
|
render(): import("lit-html").TemplateResult<1>;
|
|
8
9
|
}
|
|
9
10
|
export {};
|
|
@@ -8,9 +8,13 @@ import { css, html, LitElement } from 'lit';
|
|
|
8
8
|
import { customElement, property } from 'lit/decorators.js';
|
|
9
9
|
import { provide } from '@lit/context';
|
|
10
10
|
import { provideTargetNode } from '../mixins/targetNode.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { toSortPredicate } from '../converter.js';
|
|
12
|
+
import { sortDirection, sortPredicate } from '../context.js';
|
|
13
13
|
let default_1 = class extends provideTargetNode(LitElement) {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.orderDir = 'asc';
|
|
17
|
+
}
|
|
14
18
|
static { this.styles = css `
|
|
15
19
|
:host {
|
|
16
20
|
display: contents !important;
|
|
@@ -21,9 +25,13 @@ let default_1 = class extends provideTargetNode(LitElement) {
|
|
|
21
25
|
}
|
|
22
26
|
};
|
|
23
27
|
__decorate([
|
|
24
|
-
property({ type: Object, attribute: 'order-by', converter:
|
|
25
|
-
provide({ context:
|
|
28
|
+
property({ type: Object, attribute: 'order-by', converter: toSortPredicate }),
|
|
29
|
+
provide({ context: sortPredicate })
|
|
26
30
|
], default_1.prototype, "orderBy", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
property({ type: String, attribute: 'order-dir', reflect: true }),
|
|
33
|
+
provide({ context: sortDirection })
|
|
34
|
+
], default_1.prototype, "orderDir", void 0);
|
|
27
35
|
default_1 = __decorate([
|
|
28
36
|
customElement('target-node')
|
|
29
37
|
], default_1);
|
package/src/context.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { AnyPointer, MultiPointer } from 'clownface';
|
|
1
|
+
import type { AnyPointer, GraphPointer, MultiPointer } from 'clownface';
|
|
2
2
|
import type env from '@zazuko/env/web.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Term } from '@rdfjs/types';
|
|
4
4
|
export type Environment = typeof env;
|
|
5
|
+
export interface SortPredicate {
|
|
6
|
+
(node: GraphPointer): Term | string | number | boolean | undefined;
|
|
7
|
+
}
|
|
5
8
|
export declare const environment: {
|
|
6
|
-
__context__: import("@zazuko/env-core").DerivedEnvironment<import("@rdfjs/environment/Environment
|
|
7
|
-
dataset: import("@zazuko/env/lib/DatasetFactory
|
|
8
|
-
init(this: import("@rdfjs/environment/Environment
|
|
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<{
|
|
10
|
+
dataset: import("@zazuko/env/lib/DatasetFactory").FactoryMethod<import("@zazuko/env/lib/Dataset").Dataset>;
|
|
11
|
+
init(this: import("@rdfjs/environment/Environment").Environment<import("@rdfjs/data-model/Factory").default | import("@rdfjs/formats/Factory").FormatsFactory | import("@rdfjs/term-map/Factory").TermMapFactory | import("@zazuko/env/lib/DatasetFactory").DatasetFactory<import("@zazuko/env/lib/Dataset").Dataset>>): void;
|
|
9
12
|
}>>;
|
|
10
13
|
};
|
|
11
14
|
export declare const dataset: {
|
|
@@ -14,6 +17,9 @@ export declare const dataset: {
|
|
|
14
17
|
export declare const focusNode: {
|
|
15
18
|
__context__: MultiPointer | undefined;
|
|
16
19
|
};
|
|
17
|
-
export declare const
|
|
18
|
-
__context__:
|
|
20
|
+
export declare const sortPredicate: {
|
|
21
|
+
__context__: SortPredicate | undefined;
|
|
22
|
+
};
|
|
23
|
+
export declare const sortDirection: {
|
|
24
|
+
__context__: "asc" | "desc" | undefined;
|
|
19
25
|
};
|
package/src/context.js
CHANGED
|
@@ -2,4 +2,5 @@ import { createContext } from '@lit/context';
|
|
|
2
2
|
export const environment = createContext(Symbol('environment'));
|
|
3
3
|
export const dataset = createContext(Symbol('dataset'));
|
|
4
4
|
export const focusNode = createContext(Symbol('focus-node'));
|
|
5
|
-
export const
|
|
5
|
+
export const sortPredicate = createContext(Symbol('focus-node-sort'));
|
|
6
|
+
export const sortDirection = createContext(Symbol('focus-node-sort-dir'));
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ReactiveControllerHost } from 'lit';
|
|
2
2
|
import type { GraphPointer, MultiPointer } from 'clownface';
|
|
3
|
+
export { sort } from '../sort.js';
|
|
3
4
|
export declare class FocusNode {
|
|
4
5
|
private focusNodeConsumer;
|
|
5
|
-
private
|
|
6
|
+
private sortPredicateConsumer;
|
|
7
|
+
private sortDirectionConsumer;
|
|
6
8
|
constructor(host: ReactiveControllerHost & HTMLElement);
|
|
7
9
|
get pointer(): MultiPointer | undefined;
|
|
8
10
|
get array(): GraphPointer[] | undefined;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ContextConsumer } from '@lit/context';
|
|
2
|
-
import { focusNode,
|
|
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, {
|
|
@@ -9,8 +11,15 @@ export class FocusNode {
|
|
|
9
11
|
host.requestUpdate();
|
|
10
12
|
},
|
|
11
13
|
});
|
|
12
|
-
this.
|
|
13
|
-
context:
|
|
14
|
+
this.sortPredicateConsumer = new ContextConsumer(host, {
|
|
15
|
+
context: sortPredicate,
|
|
16
|
+
subscribe: true,
|
|
17
|
+
callback() {
|
|
18
|
+
host.requestUpdate();
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
this.sortDirectionConsumer = new ContextConsumer(host, {
|
|
22
|
+
context: sortDirection,
|
|
14
23
|
subscribe: true,
|
|
15
24
|
callback() {
|
|
16
25
|
host.requestUpdate();
|
|
@@ -22,12 +31,11 @@ export class FocusNode {
|
|
|
22
31
|
}
|
|
23
32
|
get array() {
|
|
24
33
|
const array = this.pointer?.toArray();
|
|
25
|
-
const
|
|
26
|
-
|
|
34
|
+
const sortPredicateFunc = this.sortPredicateConsumer.value;
|
|
35
|
+
const sortDirectionValue = this.sortDirectionConsumer.value;
|
|
36
|
+
if (!array || !sortPredicateFunc) {
|
|
27
37
|
return array;
|
|
28
38
|
}
|
|
29
|
-
return array.sort((
|
|
30
|
-
return left.out(sortPredicate).value?.localeCompare(right.out(sortPredicate).value || '') || 0;
|
|
31
|
-
});
|
|
39
|
+
return array.sort(sort(sortPredicateFunc, sortDirectionValue));
|
|
32
40
|
}
|
|
33
41
|
}
|
package/src/converter.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { ComplexAttributeConverter } from 'lit';
|
|
2
|
-
|
|
2
|
+
import type { NamedNode } from '@rdfjs/types';
|
|
3
|
+
export declare const toNamedNode: {
|
|
4
|
+
fromAttribute(value: string | null): NamedNode;
|
|
5
|
+
toAttribute({ value }: NamedNode): string;
|
|
6
|
+
};
|
|
3
7
|
export declare const toPropertyPath: ComplexAttributeConverter;
|
|
8
|
+
export declare const toSortPredicate: ComplexAttributeConverter;
|
package/src/converter.js
CHANGED
|
@@ -17,10 +17,18 @@ 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
|
}
|
|
24
24
|
return parse(value);
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
|
+
export const toSortPredicate = {
|
|
28
|
+
fromAttribute(value) {
|
|
29
|
+
const namedNode = toNamedNode.fromAttribute(value);
|
|
30
|
+
return (node) => {
|
|
31
|
+
return node.out(namedNode).term;
|
|
32
|
+
};
|
|
33
|
+
},
|
|
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
|
+
}
|