lit-rdf 0.3.0 → 0.3.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # lit-rdf
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 248eebf: No actual `custom-elements.js` module caused issues at runtime
8
+ - 7a53892: `rdf-graph` now initializes itself from 'window.graphs`
9
+ - 7a53892: Removed `data-graph.js` (technically breaking change but the script does not work in 4.0 anyway)
10
+
3
11
  ## 0.3.0
4
12
 
5
13
  ### 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
  ```
@@ -348,6 +348,16 @@
348
348
  "description": "Custom element (`<rdf-graph>`) that contributes an RDF graph dataset to an ancestor\n`DatasetProvider` (such as `<rdf-dataset>`).",
349
349
  "name": "RdfGraph",
350
350
  "members": [
351
+ {
352
+ "kind": "field",
353
+ "name": "env",
354
+ "type": {
355
+ "text": "Environment"
356
+ },
357
+ "privacy": "private",
358
+ "readonly": true,
359
+ "default": "new Environment(this)"
360
+ },
351
361
  {
352
362
  "kind": "field",
353
363
  "name": "value",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lit-rdf",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prepare": "husky && patch-package",
@@ -33,7 +33,6 @@
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": {
@@ -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 +14,7 @@ import type { DatasetCore, NamedNode } from '@rdfjs/types';
7
14
  * @element rdf-graph
8
15
  */
9
16
  export default class RdfGraph extends LitElement {
17
+ private readonly env;
10
18
  /**
11
19
  * The RDF/JS dataset containing the graph triples to contribute to the parent dataset provider.
12
20
  */
@@ -16,6 +24,7 @@ export default class RdfGraph extends LitElement {
16
24
  */
17
25
  graph: NamedNode | undefined;
18
26
  private datasetProvider;
27
+ constructor();
19
28
  protected updated(properties: Map<string, unknown>): void;
20
29
  connectedCallback(): void;
21
30
  disconnectedCallback(): void;
@@ -8,6 +8,7 @@ import { LitElement, nothing } from 'lit';
8
8
  import { customElement, property, state } from 'lit/decorators.js';
9
9
  import { consume } from '@lit/context';
10
10
  import { datasetProvider } from '../context.js';
11
+ import { Environment } from '../controllers/Environment.js';
11
12
  import { toNamedNode } from '../converter.js';
12
13
  /**
13
14
  * Custom element (`<rdf-graph>`) that contributes an RDF graph dataset to an ancestor
@@ -16,6 +17,10 @@ import { toNamedNode } from '../converter.js';
16
17
  * @element rdf-graph
17
18
  */
18
19
  let RdfGraph = class RdfGraph extends LitElement {
20
+ constructor() {
21
+ super();
22
+ this.env = new Environment(this);
23
+ }
19
24
  updated(properties) {
20
25
  if (properties.has('value')) {
21
26
  if (this.value) {
@@ -28,6 +33,9 @@ let RdfGraph = class RdfGraph extends LitElement {
28
33
  }
29
34
  connectedCallback() {
30
35
  super.connectedCallback();
36
+ if (!this.value && this.id && window.graphs?.[this.id]) {
37
+ this.value = this.env.value.dataset(window.graphs[this.id]({ factory: this.env.value }));
38
+ }
31
39
  if (this.value) {
32
40
  this.datasetProvider?.updateGraph(this, this.value, this.graph);
33
41
  }
@@ -50,6 +50,7 @@ interface HTMLRdfEnvironmentElement extends HTMLElement {
50
50
 
51
51
 
52
52
  interface HTMLRdfGraphElement extends HTMLElement {
53
+ env: Environment;
53
54
  /**
54
55
  * The RDF/JS dataset containing the graph triples to contribute to the parent dataset provider.
55
56
  */
@@ -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
- });