lit-rdf 0.2.0 → 0.2.1
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 +6 -0
- package/package.json +2 -1
- package/src/components/target-node.d.ts +3 -2
- package/src/components/target-node.js +12 -4
- package/src/context.d.ts +12 -7
- package/src/context.js +2 -1
- package/src/controllers/FocusNode.d.ts +2 -1
- package/src/controllers/FocusNode.js +17 -6
- package/src/converter.d.ts +6 -1
- package/src/converter.js +8 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lit-rdf",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "husky",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"@typescript-eslint/parser": "^7",
|
|
59
59
|
"@vitest/browser-playwright": "^4.0.18",
|
|
60
60
|
"@vitest/coverage-v8": "^4.0.18",
|
|
61
|
+
"@vocabulary/rdfs": "^1.0.6",
|
|
61
62
|
"eslint-import-resolver-typescript": "^2",
|
|
62
63
|
"eslint-plugin-storybook": "^10.2.12",
|
|
63
64
|
"husky": "^9.1.7",
|
|
@@ -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,13 @@
|
|
|
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 { NamedNode } from '@rdfjs/types';
|
|
4
3
|
export type Environment = typeof env;
|
|
4
|
+
export interface SortPredicate {
|
|
5
|
+
(node: GraphPointer): string | undefined;
|
|
6
|
+
}
|
|
5
7
|
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
|
|
8
|
+
__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<{
|
|
9
|
+
dataset: import("@zazuko/env/lib/DatasetFactory").FactoryMethod<import("@zazuko/env/lib/Dataset").Dataset>;
|
|
10
|
+
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
11
|
}>>;
|
|
10
12
|
};
|
|
11
13
|
export declare const dataset: {
|
|
@@ -14,6 +16,9 @@ export declare const dataset: {
|
|
|
14
16
|
export declare const focusNode: {
|
|
15
17
|
__context__: MultiPointer | undefined;
|
|
16
18
|
};
|
|
17
|
-
export declare const
|
|
18
|
-
__context__:
|
|
19
|
+
export declare const sortPredicate: {
|
|
20
|
+
__context__: SortPredicate | undefined;
|
|
21
|
+
};
|
|
22
|
+
export declare const sortDirection: {
|
|
23
|
+
__context__: "asc" | "desc" | undefined;
|
|
19
24
|
};
|
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'));
|
|
@@ -2,7 +2,8 @@ import type { ReactiveControllerHost } from 'lit';
|
|
|
2
2
|
import type { GraphPointer, MultiPointer } from 'clownface';
|
|
3
3
|
export declare class FocusNode {
|
|
4
4
|
private focusNodeConsumer;
|
|
5
|
-
private
|
|
5
|
+
private sortPredicateConsumer;
|
|
6
|
+
private sortDirectionConsumer;
|
|
6
7
|
constructor(host: ReactiveControllerHost & HTMLElement);
|
|
7
8
|
get pointer(): MultiPointer | undefined;
|
|
8
9
|
get array(): GraphPointer[] | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContextConsumer } from '@lit/context';
|
|
2
|
-
import { focusNode,
|
|
2
|
+
import { focusNode, sortPredicate, sortDirection } from '../context.js';
|
|
3
3
|
export class FocusNode {
|
|
4
4
|
constructor(host) {
|
|
5
5
|
this.focusNodeConsumer = new ContextConsumer(host, {
|
|
@@ -9,8 +9,15 @@ export class FocusNode {
|
|
|
9
9
|
host.requestUpdate();
|
|
10
10
|
},
|
|
11
11
|
});
|
|
12
|
-
this.
|
|
13
|
-
context:
|
|
12
|
+
this.sortPredicateConsumer = new ContextConsumer(host, {
|
|
13
|
+
context: sortPredicate,
|
|
14
|
+
subscribe: true,
|
|
15
|
+
callback() {
|
|
16
|
+
host.requestUpdate();
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
this.sortDirectionConsumer = new ContextConsumer(host, {
|
|
20
|
+
context: sortDirection,
|
|
14
21
|
subscribe: true,
|
|
15
22
|
callback() {
|
|
16
23
|
host.requestUpdate();
|
|
@@ -22,12 +29,16 @@ export class FocusNode {
|
|
|
22
29
|
}
|
|
23
30
|
get array() {
|
|
24
31
|
const array = this.pointer?.toArray();
|
|
25
|
-
const
|
|
26
|
-
|
|
32
|
+
const sortPredicateFunc = this.sortPredicateConsumer.value;
|
|
33
|
+
const sortDirectionValue = this.sortDirectionConsumer.value;
|
|
34
|
+
if (!array || !sortPredicateFunc) {
|
|
27
35
|
return array;
|
|
28
36
|
}
|
|
29
37
|
return array.sort((left, right) => {
|
|
30
|
-
|
|
38
|
+
if (sortDirectionValue === 'desc') {
|
|
39
|
+
return sortPredicateFunc(right)?.localeCompare(sortPredicateFunc(left) || '') || 0;
|
|
40
|
+
}
|
|
41
|
+
return sortPredicateFunc(left)?.localeCompare(sortPredicateFunc(right) || '') || 0;
|
|
31
42
|
});
|
|
32
43
|
}
|
|
33
44
|
}
|
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
|
@@ -24,3 +24,11 @@ export const toPropertyPath = {
|
|
|
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).value;
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|