lit-rdf 0.3.0 → 0.3.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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # lit-rdf
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ee852da: Allow both `[id]` and `[data-attribute]` to select the graph from `window.graphs`
8
+ - ee852da: `rdf-graph` should not rely on RDF environment so that populating data from `window.graphs` is as fast as possible
9
+
10
+ ## 0.3.1
11
+
12
+ ### Patch Changes
13
+
14
+ - 248eebf: No actual `custom-elements.js` module caused issues at runtime
15
+ - 7a53892: `rdf-graph` now initializes itself from 'window.graphs`
16
+ - 7a53892: Removed `data-graph.js` (technically breaking change but the script does not work in 4.0 anyway)
17
+
3
18
  ## 0.3.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -40,24 +40,25 @@ Compose them declaratively in your HTML or Lit templates:
40
40
  <rdf-dataset id="graph2">
41
41
  <!-- rdf-dataset combines the data from rdf-graph elements -->
42
42
  <rdf-graph .value="${graph}">
43
- <!-- Target person nodes and sort them by name -->
44
- <target-node target-class="schema:Person" order-by="schema:name">
45
- <!-- Filter nodes (e.g. by custom condition) -->
46
- <filter-node .filter=${person => Number(person.out(ns.schema.age).value) >= 18}>
47
- <article>
48
- <!-- Display resource label and properties -->
49
- <h2><resource-label></resource-label></h2>
50
- <p>Homepage: <resource-link property="schema:url"></resource-link></p>
51
-
52
- <!-- Traverse relations -->
53
- <h3>Friends:</h3>
54
- <traverse-graph property-path="schema:knows">
55
- <p><resource-label></resource-label></p>
56
- </traverse-graph>
57
- </article>
58
- </filter-node>
59
- </target-node>
60
43
  </rdf-graph>
44
+
45
+ <!-- Target person nodes and sort them by name -->
46
+ <target-node target-class="schema:Person" order-by="schema:name">
47
+ <!-- Filter nodes (e.g. by custom condition) -->
48
+ <filter-node .filter=${person => Number(person.out(ns.schema.age).value) >= 18}>
49
+ <article>
50
+ <!-- Display resource label and properties -->
51
+ <h2><resource-label></resource-label></h2>
52
+ <p>Homepage: <resource-link property="schema:url"></resource-link></p>
53
+
54
+ <!-- Traverse relations -->
55
+ <h3>Friends:</h3>
56
+ <traverse-graph property-path="schema:knows">
57
+ <p><resource-label></resource-label></p>
58
+ </traverse-graph>
59
+ </article>
60
+ </filter-node>
61
+ </target-node>
61
62
  </rdf-dataset>
62
63
  </rdf-environment>
63
64
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lit-rdf",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prepare": "husky && patch-package",
@@ -33,13 +33,13 @@
33
33
  "./constructor.js": "./src/constructor.js",
34
34
  "./mixins.js": "./src/mixins.js",
35
35
  "./controllers.js": "./src/controllers.js",
36
- "./runtime/*.js": "./src/runtime/*.js",
37
36
  "./sort.js": "./src/sort.js"
38
37
  },
39
38
  "dependencies": {
40
39
  "@lit/context": "^1.1.6",
41
40
  "@rdfjs-elements/lit-helpers": "^0.3.13",
42
41
  "@rdfjs/data-model": "^2.1.1",
42
+ "@rdfjs/dataset": "^2.0.3",
43
43
  "@rdfjs/types": "^2",
44
44
  "@zazuko/env": "^3.0.1",
45
45
  "@zazuko/prefixes": "^2.6.1",
@@ -57,6 +57,7 @@
57
57
  "@custom-elements-manifest/analyzer": "^0.11.0",
58
58
  "@eslint/config-helpers": "^0.7.0",
59
59
  "@eslint/js": "^10",
60
+ "@lit-labs/ssr": "^4.1.0",
60
61
  "@open-wc/testing": "^5.0.0",
61
62
  "@rollup/plugin-commonjs": "^26",
62
63
  "@rolldown/plugin-node-polyfills": "^1.0.3",
@@ -67,6 +68,7 @@
67
68
  "@types/clownface": "^2.0.10",
68
69
  "@types/is-url": "^1.2.32",
69
70
  "@types/rdfjs__data-model": "^2.0.9",
71
+ "@types/rdfjs__dataset": "^2.0.7",
70
72
  "@types/readable-stream": "^4.0.24",
71
73
  "@types/sinon": "^22.0.0",
72
74
  "@typescript-eslint/eslint-plugin": "^8.66.0",
@@ -1,5 +1,12 @@
1
1
  import { LitElement } from 'lit';
2
- import type { DatasetCore, NamedNode } from '@rdfjs/types';
2
+ import type { DataFactory, DatasetCore, NamedNode, Quad } from '@rdfjs/types';
3
+ declare global {
4
+ interface Window {
5
+ graphs?: Record<string, (options: {
6
+ factory: DataFactory;
7
+ }) => Quad[]>;
8
+ }
9
+ }
3
10
  /**
4
11
  * Custom element (`<rdf-graph>`) that contributes an RDF graph dataset to an ancestor
5
12
  * `DatasetProvider` (such as `<rdf-dataset>`).
@@ -7,6 +7,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { LitElement, nothing } from 'lit';
8
8
  import { customElement, property, state } from 'lit/decorators.js';
9
9
  import { consume } from '@lit/context';
10
+ import Dataset from '@rdfjs/dataset';
11
+ import factory from '@rdfjs/data-model';
10
12
  import { datasetProvider } from '../context.js';
11
13
  import { toNamedNode } from '../converter.js';
12
14
  /**
@@ -27,6 +29,10 @@ let RdfGraph = class RdfGraph extends LitElement {
27
29
  }
28
30
  }
29
31
  connectedCallback() {
32
+ const graphId = this.getAttribute('data-graph') || this.id;
33
+ if (!this.value && graphId && window.graphs?.[graphId]) {
34
+ this.value = Dataset.dataset(window.graphs[graphId]({ factory }));
35
+ }
30
36
  super.connectedCallback();
31
37
  if (this.value) {
32
38
  this.datasetProvider?.updateGraph(this, this.value, this.graph);
@@ -0,0 +1 @@
1
+ export {}
@@ -1,14 +0,0 @@
1
- /**
2
- * Runtime script that finds all `rdf-graph` elements in the DOM
3
- * and populates their `.value` property with an RDF/JS Dataset initialized
4
- * from graph factory functions registered on `window.graphs`.
5
- */
6
- import factory from '@zazuko/env/web.js';
7
- import type { Quad } from '@rdfjs/types';
8
- declare global {
9
- interface Window {
10
- graphs?: Record<string, (options: {
11
- factory: typeof factory;
12
- }) => Quad[]>;
13
- }
14
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Runtime script that finds all `rdf-graph` elements in the DOM
3
- * and populates their `.value` property with an RDF/JS Dataset initialized
4
- * from graph factory functions registered on `window.graphs`.
5
- */
6
- import factory from '@zazuko/env/web.js';
7
- document.querySelectorAll('rdf-graph').forEach((el) => {
8
- if (el.id && window.graphs?.[el.id]) {
9
- el.value = factory.dataset(window.graphs[el.id]({ factory }));
10
- }
11
- });