lit-rdf 0.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.
Files changed (41) hide show
  1. package/package.json +72 -0
  2. package/src/components/data-graph.d.ts +8 -0
  3. package/src/components/data-graph.js +26 -0
  4. package/src/components/focus-node.d.ts +7 -0
  5. package/src/components/focus-node.js +28 -0
  6. package/src/components/rdf-environment.d.ts +7 -0
  7. package/src/components/rdf-environment.js +23 -0
  8. package/src/components/resource-label.d.ts +8 -0
  9. package/src/components/resource-label.js +31 -0
  10. package/src/components/resource-link.d.ts +8 -0
  11. package/src/components/resource-link.js +36 -0
  12. package/src/components/target-node.d.ts +9 -0
  13. package/src/components/target-node.js +30 -0
  14. package/src/components/traverse-graph.d.ts +12 -0
  15. package/src/components/traverse-graph.js +38 -0
  16. package/src/constructor.d.ts +13 -0
  17. package/src/constructor.js +1 -0
  18. package/src/context.d.ts +19 -0
  19. package/src/context.js +5 -0
  20. package/src/controllers/FocusNode.d.ts +9 -0
  21. package/src/controllers/FocusNode.js +27 -0
  22. package/src/controllers.d.ts +1 -0
  23. package/src/controllers.js +1 -0
  24. package/src/converter.d.ts +3 -0
  25. package/src/converter.js +26 -0
  26. package/src/index.d.ts +6 -0
  27. package/src/index.js +6 -0
  28. package/src/mixins/environment.d.ts +3 -0
  29. package/src/mixins/environment.js +32 -0
  30. package/src/mixins/focusNode.d.ts +2 -0
  31. package/src/mixins/focusNode.js +20 -0
  32. package/src/mixins/graph.d.ts +3 -0
  33. package/src/mixins/graph.js +33 -0
  34. package/src/mixins/targetNode.d.ts +2 -0
  35. package/src/mixins/targetNode.js +69 -0
  36. package/src/mixins/traverseGraph.d.ts +5 -0
  37. package/src/mixins/traverseGraph.js +37 -0
  38. package/src/mixins.d.ts +3 -0
  39. package/src/mixins.js +3 -0
  40. package/src/runtime/data-graph.d.ts +9 -0
  41. package/src/runtime/data-graph.js +8 -0
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "lit-rdf",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "prepare": "husky",
7
+ "lint": "eslint . --quiet --ignore-path .gitignore",
8
+ "storybook": "storybook dev -p 6006",
9
+ "build-storybook": "storybook build",
10
+ "build": "tsc",
11
+ "prepack": "npm run build",
12
+ "release": "changeset publish"
13
+ },
14
+ "files": [
15
+ "src/**/*.js",
16
+ "src/**/*.d.ts"
17
+ ],
18
+ "exports": {
19
+ ".": "./src/index.js",
20
+ "./components/*.js": "./src/components/*.js",
21
+ "./converter.js": "./src/converter.js",
22
+ "./constructor.js": "./src/constructor.js",
23
+ "./mixins.js": "./src/mixins.js",
24
+ "./controllers.js": "./src/controllers.js",
25
+ "./runtime/*.js": "./src/runtime/*.js"
26
+ },
27
+ "dependencies": {
28
+ "@lit/context": "^1.1.6",
29
+ "@rdfjs-elements/lit-helpers": "^0.3.13",
30
+ "@rdfjs/data-model": "^2.1.1",
31
+ "@rdfjs/types": "^2",
32
+ "@zazuko/env": "^3.0.1",
33
+ "@zazuko/prefixes": "^2.6.1",
34
+ "clownface": "^2.0.3",
35
+ "clownface-shacl-path": "^2.4.0",
36
+ "is-url": "^1.2.4",
37
+ "lit": "^3",
38
+ "sparql-path-parser": "^0.1.1"
39
+ },
40
+ "devDependencies": {
41
+ "@changesets/cli": "^2.29.0",
42
+ "@chromatic-com/storybook": "^5.0.1",
43
+ "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
44
+ "@storybook/addon-docs": "^10.2.12",
45
+ "@storybook/addon-vitest": "^10.2.12",
46
+ "@storybook/web-components-vite": "^10.2.12",
47
+ "@tpluscode/eslint-config": "^0.6.4",
48
+ "@types/clownface": "^2.0.10",
49
+ "@types/is-url": "^1.2.32",
50
+ "@types/rdfjs__data-model": "^2.0.9",
51
+ "@typescript-eslint/eslint-plugin": "^7",
52
+ "@typescript-eslint/parser": "^7",
53
+ "@vitest/browser-playwright": "^4.0.18",
54
+ "@vitest/coverage-v8": "^4.0.18",
55
+ "eslint-import-resolver-typescript": "^2",
56
+ "eslint-plugin-storybook": "^10.2.12",
57
+ "husky": "^9.1.7",
58
+ "lint-staged": "^16.2.7",
59
+ "playwright": "^1.58.2",
60
+ "rollup-plugin-polyfill-node": "^0.13.0",
61
+ "storybook": "^10.2.12",
62
+ "string-to-stream": "^3.0.1",
63
+ "typescript": "^5",
64
+ "util": "^0.12.5",
65
+ "vitest": "^4.0.18"
66
+ },
67
+ "lint-staged": {
68
+ "*.{js,ts}": [
69
+ "eslint --fix --quiet"
70
+ ]
71
+ }
72
+ }
@@ -0,0 +1,8 @@
1
+ import { LitElement } from 'lit';
2
+ import type { AnyPointer } from 'clownface';
3
+ declare const default_base: typeof LitElement & import("../constructor.js").LitElementConstructor<import("../constructor.js").WithEnvironment> & import("../constructor.js").LitElementConstructor<import("../constructor.js").WithGraph>;
4
+ export default class extends default_base {
5
+ parent: AnyPointer | undefined;
6
+ render(): unknown;
7
+ }
8
+ export {};
@@ -0,0 +1,26 @@
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 { html, LitElement } from 'lit';
8
+ import { consume } from '@lit/context';
9
+ import { customElement, state } from 'lit/decorators.js';
10
+ import { dataset } from '../context.js';
11
+ import { consumeEnvironment } from '../mixins/environment.js';
12
+ import { provideGraph } from '../mixins/graph.js';
13
+ let default_1 = class extends provideGraph(consumeEnvironment(LitElement)) {
14
+ render() {
15
+ return html `
16
+ <slot></slot>`;
17
+ }
18
+ };
19
+ __decorate([
20
+ consume({ context: dataset, subscribe: true }),
21
+ state()
22
+ ], default_1.prototype, "parent", void 0);
23
+ default_1 = __decorate([
24
+ customElement('data-graph')
25
+ ], default_1);
26
+ export default default_1;
@@ -0,0 +1,7 @@
1
+ import { LitElement } from 'lit';
2
+ import type { MultiPointer } from 'clownface';
3
+ export default class extends LitElement {
4
+ static styles: import("lit").CSSResult;
5
+ focusNode: MultiPointer | undefined;
6
+ render(): import("lit-html").TemplateResult<1>;
7
+ }
@@ -0,0 +1,28 @@
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 { css, html, LitElement } from 'lit';
8
+ import { customElement, state } from 'lit/decorators.js';
9
+ import { provide } from '@lit/context';
10
+ import { focusNode as context } from '../context.js';
11
+ let default_1 = class extends LitElement {
12
+ static { this.styles = css `
13
+ :host {
14
+ display: contents !important;
15
+ }
16
+ `; }
17
+ render() {
18
+ return html `<slot></slot>`;
19
+ }
20
+ };
21
+ __decorate([
22
+ provide({ context }),
23
+ state()
24
+ ], default_1.prototype, "focusNode", void 0);
25
+ default_1 = __decorate([
26
+ customElement('focus-node')
27
+ ], default_1);
28
+ export default default_1;
@@ -0,0 +1,7 @@
1
+ import { LitElement } from 'lit';
2
+ declare const default_base: typeof LitElement & import("../constructor.js").LitElementConstructor<import("../constructor.js").WithEnvironment>;
3
+ export default class extends default_base {
4
+ constructor();
5
+ render(): import("lit-html").TemplateResult<1>;
6
+ }
7
+ export {};
@@ -0,0 +1,23 @@
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 { html, LitElement } from 'lit';
8
+ import env from '@zazuko/env/web.js';
9
+ import { customElement } from 'lit/decorators.js';
10
+ import { provideEnvironment } from '../mixins.js';
11
+ let default_1 = class extends provideEnvironment(LitElement) {
12
+ constructor() {
13
+ super();
14
+ this.rdf = env;
15
+ }
16
+ render() {
17
+ return html `<slot></slot>`;
18
+ }
19
+ };
20
+ default_1 = __decorate([
21
+ customElement('rdf-environment')
22
+ ], default_1);
23
+ export default default_1;
@@ -0,0 +1,8 @@
1
+ import { LitElement } from 'lit';
2
+ import type { NamedNode } from '@rdfjs/types';
3
+ declare const ResourceLabel_base: typeof LitElement & import("../constructor.js").LitElementConstructor<import("../constructor.js").WithFocusNode>;
4
+ export declare class ResourceLabel extends ResourceLabel_base {
5
+ property: NamedNode;
6
+ render(): import("lit-html").TemplateResult<1>;
7
+ }
8
+ export {};
@@ -0,0 +1,31 @@
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 { html, LitElement } from 'lit';
8
+ import { customElement, property } from 'lit/decorators.js';
9
+ import { localizedLabel } from '@rdfjs-elements/lit-helpers/localizedLabel.js';
10
+ import rdf from '@rdfjs/data-model';
11
+ import { consumeFocusNode } from '../mixins/focusNode.js';
12
+ import { toNamedNode } from '../converter.js';
13
+ let ResourceLabel = class ResourceLabel extends consumeFocusNode(LitElement) {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.property = rdf.namedNode('http://www.w3.org/2000/01/rdf-schema#label');
17
+ }
18
+ render() {
19
+ if (!this.focusNode) {
20
+ return html ``;
21
+ }
22
+ return html `${localizedLabel(this.focusNode, { property: this.property })}`;
23
+ }
24
+ };
25
+ __decorate([
26
+ property({ type: Object, converter: toNamedNode })
27
+ ], ResourceLabel.prototype, "property", void 0);
28
+ ResourceLabel = __decorate([
29
+ customElement('resource-label')
30
+ ], ResourceLabel);
31
+ export { ResourceLabel };
@@ -0,0 +1,8 @@
1
+ import { LitElement } from 'lit';
2
+ import type { NamedNode } from '@rdfjs/types';
3
+ declare const ResourceLink_base: typeof LitElement & import("../constructor.js").LitElementConstructor<import("../constructor.js").WithFocusNode>;
4
+ export declare class ResourceLink extends ResourceLink_base {
5
+ property?: NamedNode;
6
+ render(): import("lit-html").TemplateResult<1>;
7
+ }
8
+ export {};
@@ -0,0 +1,36 @@
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 { html, LitElement } from 'lit';
8
+ import { customElement, property } from 'lit/decorators.js';
9
+ import { findNodes } from 'clownface-shacl-path';
10
+ import { consumeFocusNode } from '../mixins/focusNode.js';
11
+ import { toPropertyPath } from '../converter.js';
12
+ let ResourceLink = class ResourceLink extends consumeFocusNode(LitElement) {
13
+ render() {
14
+ if (!this.focusNode) {
15
+ return html `
16
+ <slot></slot>`;
17
+ }
18
+ let href;
19
+ if (this.property) {
20
+ href = findNodes(this.focusNode, this.property).value;
21
+ }
22
+ if (!href) {
23
+ href = this.focusNode.value;
24
+ }
25
+ return html `<a href="${href}">
26
+ <slot></slot>
27
+ </a>`;
28
+ }
29
+ };
30
+ __decorate([
31
+ property({ type: Object, converter: toPropertyPath })
32
+ ], ResourceLink.prototype, "property", void 0);
33
+ ResourceLink = __decorate([
34
+ customElement('resource-link')
35
+ ], ResourceLink);
36
+ export { ResourceLink };
@@ -0,0 +1,9 @@
1
+ import { LitElement } from 'lit';
2
+ import type { NamedNode } from '@rdfjs/types';
3
+ declare const default_base: typeof LitElement & import("../constructor.js").LitElementConstructor<import("../constructor.js").WithFocusNode>;
4
+ export default class extends default_base {
5
+ static styles: import("lit").CSSResult;
6
+ orderBy: NamedNode | undefined;
7
+ render(): import("lit-html").TemplateResult<1>;
8
+ }
9
+ export {};
@@ -0,0 +1,30 @@
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 { css, html, LitElement } from 'lit';
8
+ import { customElement, property } from 'lit/decorators.js';
9
+ import { provide } from '@lit/context';
10
+ import { provideTargetNode } from '../mixins/targetNode.js';
11
+ import { toNamedNode } from '../converter.js';
12
+ import { sortCriteria } from '../context.js';
13
+ let default_1 = class extends provideTargetNode(LitElement) {
14
+ static { this.styles = css `
15
+ :host {
16
+ display: contents !important;
17
+ }
18
+ `; }
19
+ render() {
20
+ return html `<slot></slot>`;
21
+ }
22
+ };
23
+ __decorate([
24
+ property({ type: Object, attribute: 'order-by', converter: toNamedNode }),
25
+ provide({ context: sortCriteria })
26
+ ], default_1.prototype, "orderBy", void 0);
27
+ default_1 = __decorate([
28
+ customElement('target-node')
29
+ ], default_1);
30
+ export default default_1;
@@ -0,0 +1,12 @@
1
+ import { LitElement } from 'lit';
2
+ import type { GraphPointer, MultiPointer } from 'clownface';
3
+ declare const default_base: typeof LitElement & import("../constructor.js").LitElementConstructor<{
4
+ objectNode: MultiPointer | undefined;
5
+ }>;
6
+ export default class extends default_base {
7
+ static styles: import("lit").CSSResult;
8
+ renderObjectNode?: (node: GraphPointer) => unknown;
9
+ renderObjectNodes?: (nodes: MultiPointer) => unknown;
10
+ render(): unknown;
11
+ }
12
+ export {};
@@ -0,0 +1,38 @@
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 { css, html, LitElement } from 'lit';
8
+ import { customElement, property } from 'lit/decorators.js';
9
+ import { traverseGraph } from '../mixins/traverseGraph.js';
10
+ let default_1 = class extends traverseGraph(LitElement) {
11
+ static { this.styles = css `
12
+ :host {
13
+ display: contents;
14
+ }
15
+ `; }
16
+ render() {
17
+ if (!this.objectNode || this.objectNode.terms.length === 0) {
18
+ return html `<slot name="empty"></slot>`;
19
+ }
20
+ if (this.renderObjectNodes) {
21
+ return this.renderObjectNodes(this.objectNode);
22
+ }
23
+ if (this.renderObjectNode) {
24
+ return html `${this.objectNode.map(node => this.renderObjectNode(node))}`;
25
+ }
26
+ return html `<slot></slot>`;
27
+ }
28
+ };
29
+ __decorate([
30
+ property({ type: Object })
31
+ ], default_1.prototype, "renderObjectNode", void 0);
32
+ __decorate([
33
+ property({ type: Object })
34
+ ], default_1.prototype, "renderObjectNodes", void 0);
35
+ default_1 = __decorate([
36
+ customElement('traverse-graph')
37
+ ], default_1);
38
+ export default default_1;
@@ -0,0 +1,13 @@
1
+ import type { LitElement } from 'lit';
2
+ import type { AnyPointer, MultiPointer } from 'clownface';
3
+ import type { Environment } from './context.js';
4
+ export type LitElementConstructor<T = {}> = new (...args: any[]) => T & LitElement;
5
+ export type WithGraph = {
6
+ graph: AnyPointer | undefined;
7
+ };
8
+ export type WithEnvironment = {
9
+ rdf: Environment;
10
+ };
11
+ export type WithFocusNode = {
12
+ focusNode: MultiPointer | undefined;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { AnyPointer, MultiPointer } from 'clownface';
2
+ import type env from '@zazuko/env/web.js';
3
+ import type { NamedNode } from '@rdfjs/types';
4
+ export type Environment = typeof env;
5
+ export declare const environment: {
6
+ __context__: import("@zazuko/env-core").DerivedEnvironment<import("@rdfjs/environment/Environment.js").Environment<import("@rdfjs/data-model/Factory.js").default | import("@rdfjs/formats/Factory.js").FormatsFactory | import("@rdfjs/term-map/Factory.js").TermMapFactory | import("@tpluscode/rdf-ns-builders").default | import("clownface/Factory.js").default | import("@rdfjs/term-set/Factory.js").TermSetFactory | import("@rdfjs/namespace/Factory.js").NamespaceFactory | import("@rdfjs/traverser/Factory.js").TraverserFactory>, import("@rdfjs/environment/Environment.js").Environment<{
7
+ dataset: import("@zazuko/env/lib/DatasetFactory.js").FactoryMethod<import("@zazuko/env/lib/Dataset.js").Dataset>;
8
+ init(this: import("@rdfjs/environment/Environment.js").Environment<import("@rdfjs/data-model/Factory.js").default | import("@rdfjs/formats/Factory.js").FormatsFactory | import("@rdfjs/term-map/Factory.js").TermMapFactory | import("@zazuko/env/lib/DatasetFactory.js").DatasetFactory<import("@zazuko/env/lib/Dataset.js").Dataset>>): void;
9
+ }>>;
10
+ };
11
+ export declare const dataset: {
12
+ __context__: AnyPointer<import("clownface").AnyContext, import("@rdfjs/types").DatasetCore<import("@rdfjs/types").Quad, import("@rdfjs/types").Quad>> | undefined;
13
+ };
14
+ export declare const focusNode: {
15
+ __context__: MultiPointer | undefined;
16
+ };
17
+ export declare const sortCriteria: {
18
+ __context__: NamedNode<string> | undefined;
19
+ };
package/src/context.js ADDED
@@ -0,0 +1,5 @@
1
+ import { createContext } from '@lit/context';
2
+ export const environment = createContext(Symbol('environment'));
3
+ export const dataset = createContext(Symbol('dataset'));
4
+ export const focusNode = createContext(Symbol('focus-node'));
5
+ export const sortCriteria = createContext(Symbol('focus-node-sort'));
@@ -0,0 +1,9 @@
1
+ import type { ReactiveControllerHost } from 'lit';
2
+ import type { GraphPointer, MultiPointer } from 'clownface';
3
+ export declare class FocusNode {
4
+ private focusNodeConsumer;
5
+ private sortCriteriaConsumer;
6
+ constructor(host: ReactiveControllerHost & HTMLElement);
7
+ get pointer(): MultiPointer | undefined;
8
+ get array(): GraphPointer[] | undefined;
9
+ }
@@ -0,0 +1,27 @@
1
+ import { ContextConsumer } from '@lit/context';
2
+ import { focusNode, sortCriteria } from '../context.js';
3
+ export class FocusNode {
4
+ constructor(host) {
5
+ this.focusNodeConsumer = new ContextConsumer(host, {
6
+ context: focusNode,
7
+ subscribe: true,
8
+ });
9
+ this.sortCriteriaConsumer = new ContextConsumer(host, {
10
+ context: sortCriteria,
11
+ subscribe: true,
12
+ });
13
+ }
14
+ get pointer() {
15
+ return this.focusNodeConsumer.value;
16
+ }
17
+ get array() {
18
+ const array = this.pointer?.toArray();
19
+ const sortPredicate = this.sortCriteriaConsumer.value;
20
+ if (!array || !sortPredicate) {
21
+ return array;
22
+ }
23
+ return array.sort((left, right) => {
24
+ return left.out(sortPredicate).value?.localeCompare(right.out(sortPredicate).value || '') || 0;
25
+ });
26
+ }
27
+ }
@@ -0,0 +1 @@
1
+ export { FocusNode } from './controllers/FocusNode.js';
@@ -0,0 +1 @@
1
+ export { FocusNode } from './controllers/FocusNode.js';
@@ -0,0 +1,3 @@
1
+ import type { ComplexAttributeConverter } from 'lit';
2
+ export declare const toNamedNode: ComplexAttributeConverter;
3
+ export declare const toPropertyPath: ComplexAttributeConverter;
@@ -0,0 +1,26 @@
1
+ import isUrl from 'is-url';
2
+ import rdf from '@rdfjs/data-model';
3
+ import { expand, shrink } from '@zazuko/prefixes';
4
+ import { parse } from 'sparql-path-parser';
5
+ export const toNamedNode = {
6
+ fromAttribute(value) {
7
+ if (typeof value === 'undefined' || value === null) {
8
+ throw new Error('NamedNode converter: value is null');
9
+ }
10
+ if (isUrl(value)) {
11
+ return rdf.namedNode(value);
12
+ }
13
+ return rdf.namedNode(expand(value));
14
+ },
15
+ toAttribute({ value }) {
16
+ return shrink(value);
17
+ },
18
+ };
19
+ export const toPropertyPath = {
20
+ fromAttribute(value, type) {
21
+ if (typeof value === 'undefined' || value === null) {
22
+ throw new Error('PropertyPath converter: value is null');
23
+ }
24
+ return parse(value);
25
+ },
26
+ };
package/src/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import './components/data-graph.js';
2
+ import './components/traverse-graph.js';
3
+ import './components/focus-node.js';
4
+ import './components/target-node.js';
5
+ import './components/resource-label.js';
6
+ import './components/resource-link.js';
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import './components/data-graph.js';
2
+ import './components/traverse-graph.js';
3
+ import './components/focus-node.js';
4
+ import './components/target-node.js';
5
+ import './components/resource-label.js';
6
+ import './components/resource-link.js';
@@ -0,0 +1,3 @@
1
+ import type { LitElementConstructor, WithEnvironment } from '../constructor.js';
2
+ export declare function consumeEnvironment<T extends LitElementConstructor>(base: T): T & LitElementConstructor<WithEnvironment>;
3
+ export declare function provideEnvironment<T extends LitElementConstructor>(base: T): T & LitElementConstructor<WithEnvironment>;
@@ -0,0 +1,32 @@
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 { consume, provide } from '@lit/context';
8
+ import { state } from 'lit/decorators.js';
9
+ import { environment as context } from '../context.js';
10
+ export function consumeEnvironment(base) {
11
+ class Impl extends base {
12
+ constructor(...args) {
13
+ super(...args);
14
+ }
15
+ }
16
+ __decorate([
17
+ consume({ context })
18
+ ], Impl.prototype, "rdf", void 0);
19
+ return Impl;
20
+ }
21
+ export function provideEnvironment(base) {
22
+ class Impl extends base {
23
+ constructor(...args) {
24
+ super(...args);
25
+ }
26
+ }
27
+ __decorate([
28
+ state(),
29
+ provide({ context })
30
+ ], Impl.prototype, "rdf", void 0);
31
+ return Impl;
32
+ }
@@ -0,0 +1,2 @@
1
+ import type { LitElementConstructor, WithFocusNode } from '../constructor.js';
2
+ export declare function consumeFocusNode<T extends LitElementConstructor>(base: T): T & LitElementConstructor<WithFocusNode>;
@@ -0,0 +1,20 @@
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 { consume } from '@lit/context';
8
+ import { focusNode as context } from '../context.js';
9
+ import { consumeEnvironment } from './environment.js';
10
+ export function consumeFocusNode(base) {
11
+ class Impl extends consumeEnvironment(base) {
12
+ constructor(...args) {
13
+ super(...args);
14
+ }
15
+ }
16
+ __decorate([
17
+ consume({ context, subscribe: true })
18
+ ], Impl.prototype, "focusNode", void 0);
19
+ return Impl;
20
+ }
@@ -0,0 +1,3 @@
1
+ import type { LitElementConstructor, WithGraph } from '../constructor.js';
2
+ export declare function provideGraph<T extends LitElementConstructor>(base: T): T & LitElementConstructor<WithGraph>;
3
+ export declare function consumeGraph<T extends LitElementConstructor>(base: T): T & LitElementConstructor<WithGraph>;
@@ -0,0 +1,33 @@
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 { consume, provide } from '@lit/context';
8
+ import { state } from 'lit/decorators.js';
9
+ import { dataset } from '../context.js';
10
+ export function provideGraph(base) {
11
+ class WithGraphProvider extends base {
12
+ constructor(...args) {
13
+ super(...args);
14
+ }
15
+ }
16
+ __decorate([
17
+ provide({ context: dataset }),
18
+ state()
19
+ ], WithGraphProvider.prototype, "graph", void 0);
20
+ return WithGraphProvider;
21
+ }
22
+ export function consumeGraph(base) {
23
+ class WithGraphConsumer extends base {
24
+ constructor(...args) {
25
+ super(...args);
26
+ }
27
+ }
28
+ __decorate([
29
+ consume({ context: dataset, subscribe: true }),
30
+ state()
31
+ ], WithGraphConsumer.prototype, "graph", void 0);
32
+ return WithGraphConsumer;
33
+ }
@@ -0,0 +1,2 @@
1
+ import type { LitElementConstructor, WithFocusNode } from '../constructor.js';
2
+ export declare function provideTargetNode<T extends LitElementConstructor>(base: T): T & LitElementConstructor<WithFocusNode>;
@@ -0,0 +1,69 @@
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 { property, state } from 'lit/decorators.js';
8
+ import { provide } from '@lit/context';
9
+ import { focusNode } from '../context.js';
10
+ import { toNamedNode } from '../converter.js';
11
+ import { consumeEnvironment } from './environment.js';
12
+ import { consumeGraph } from './graph.js';
13
+ export function provideTargetNode(base) {
14
+ class DataBound extends consumeGraph(consumeEnvironment(base)) {
15
+ constructor(...args) {
16
+ super(...args);
17
+ }
18
+ willUpdate(_changedProperties) {
19
+ if (_changedProperties.has('graph')) {
20
+ this.setFocusNode();
21
+ }
22
+ }
23
+ updated(_changedProperties) {
24
+ if (_changedProperties.has('graph')) {
25
+ this.setFocusNode();
26
+ }
27
+ }
28
+ setFocusNode() {
29
+ if (this.graph) {
30
+ const found = this.findFocusNode();
31
+ if (found?.terms.length) {
32
+ this.focusNode = found;
33
+ }
34
+ }
35
+ }
36
+ findFocusNode() {
37
+ if (this.targetNode) {
38
+ return this.graph?.node(this.targetNode);
39
+ }
40
+ if (this.targetClass) {
41
+ return this.graph?.has(this.rdf.ns.rdf.type, this.targetClass);
42
+ }
43
+ if (this.targetSubjectsOf) {
44
+ return this.graph?.in(this.targetSubjectsOf);
45
+ }
46
+ if (this.targetObjectsOf) {
47
+ return this.graph?.out(this.targetObjectsOf);
48
+ }
49
+ return undefined;
50
+ }
51
+ }
52
+ __decorate([
53
+ property({ type: Object, converter: toNamedNode, attribute: 'target-objects-of' })
54
+ ], DataBound.prototype, "targetObjectsOf", void 0);
55
+ __decorate([
56
+ property({ type: Object, converter: toNamedNode, attribute: 'target-subjects-of' })
57
+ ], DataBound.prototype, "targetSubjectsOf", void 0);
58
+ __decorate([
59
+ property({ type: Object, converter: toNamedNode, attribute: 'target-class' })
60
+ ], DataBound.prototype, "targetClass", void 0);
61
+ __decorate([
62
+ property({ type: Object, converter: toNamedNode, attribute: 'target-node' })
63
+ ], DataBound.prototype, "targetNode", void 0);
64
+ __decorate([
65
+ provide({ context: focusNode }),
66
+ state()
67
+ ], DataBound.prototype, "focusNode", void 0);
68
+ return DataBound;
69
+ }
@@ -0,0 +1,5 @@
1
+ import type { MultiPointer } from 'clownface';
2
+ import type { LitElementConstructor } from '../constructor.js';
3
+ export declare function traverseGraph<T extends LitElementConstructor>(Base: T): T & LitElementConstructor<{
4
+ objectNode: MultiPointer | undefined;
5
+ }>;
@@ -0,0 +1,37 @@
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 { property } from 'lit/decorators.js';
8
+ import { findNodes } from 'clownface-shacl-path';
9
+ import { provide } from '@lit/context';
10
+ import { focusNode as context } from '../context.js';
11
+ import { toPropertyPath } from '../converter.js';
12
+ import { consumeFocusNode } from './focusNode.js';
13
+ export function traverseGraph(Base) {
14
+ class TraverseGraph extends consumeFocusNode(Base) {
15
+ constructor(...args) {
16
+ super(...args);
17
+ }
18
+ willUpdate(_changedProperties) {
19
+ if (_changedProperties.has('focusNode') || _changedProperties.has('propertyPath')) {
20
+ this.setObjectNode();
21
+ }
22
+ }
23
+ setObjectNode() {
24
+ if (this.propertyPath && this.focusNode) {
25
+ this.objectNode = findNodes(this.focusNode, this.propertyPath);
26
+ }
27
+ }
28
+ }
29
+ __decorate([
30
+ property({ type: Object, converter: toPropertyPath, attribute: 'property-path' })
31
+ ], TraverseGraph.prototype, "propertyPath", void 0);
32
+ __decorate([
33
+ provide({ context }),
34
+ property()
35
+ ], TraverseGraph.prototype, "objectNode", void 0);
36
+ return TraverseGraph;
37
+ }
@@ -0,0 +1,3 @@
1
+ export { consumeFocusNode } from './mixins/focusNode.js';
2
+ export { provideGraph } from './mixins/graph.js';
3
+ export { provideEnvironment, consumeEnvironment } from './mixins/environment.js';
package/src/mixins.js ADDED
@@ -0,0 +1,3 @@
1
+ export { consumeFocusNode } from './mixins/focusNode.js';
2
+ export { provideGraph } from './mixins/graph.js';
3
+ export { provideEnvironment, consumeEnvironment } from './mixins/environment.js';
@@ -0,0 +1,9 @@
1
+ import factory from '@zazuko/env/web.js';
2
+ import type { Quad } from '@rdfjs/types';
3
+ declare global {
4
+ interface Window {
5
+ graphs?: Record<string, (options: {
6
+ factory: typeof factory;
7
+ }) => Quad[]>;
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ import factory from '@zazuko/env/web.js';
2
+ document.querySelectorAll('[data-graph]').forEach((el) => {
3
+ const graphName = el.getAttribute('data-graph');
4
+ if (graphName && window.graphs?.[graphName]) {
5
+ const dataset = factory.dataset(window.graphs[graphName]({ factory }));
6
+ el.graph = factory.clownface({ dataset });
7
+ }
8
+ });