lit-rdf 0.2.1 → 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 CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## 0.2.1
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "lit-rdf",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prepare": "husky",
7
- "lint": "eslint . --quiet --ignore-path .gitignore --ignore-path .eslintignore",
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,35 +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": "^2.29.0",
48
- "@chromatic-com/storybook": "^5.0.1",
49
- "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
50
- "@storybook/addon-docs": "^10.2.12",
51
- "@storybook/addon-vitest": "^10.2.12",
52
- "@storybook/web-components-vite": "^10.2.12",
53
- "@tpluscode/eslint-config": "^0.6.4",
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": "^7",
58
- "@typescript-eslint/parser": "^7",
59
- "@vitest/browser-playwright": "^4.0.18",
60
- "@vitest/coverage-v8": "^4.0.18",
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",
61
66
  "@vocabulary/rdfs": "^1.0.6",
62
- "eslint-import-resolver-typescript": "^2",
63
- "eslint-plugin-storybook": "^10.2.12",
67
+ "eslint": "^10",
68
+ "eslint-import-resolver-typescript": "^4.4.5",
69
+ "eslint-plugin-storybook": "^10.5.7",
64
70
  "husky": "^9.1.7",
65
- "lint-staged": "^16.2.7",
71
+ "lint-staged": "^17.3.0",
66
72
  "playwright": "^1.58.2",
67
- "rollup-plugin-polyfill-node": "^0.13.0",
68
- "storybook": "^10.2.12",
73
+ "storybook": "^10.6.0",
69
74
  "string-to-stream": "^3.0.1",
70
75
  "typescript": "^5",
71
76
  "util": "^0.12.5",
72
- "vitest": "^4.0.18"
77
+ "vitest": "^4.1.11"
73
78
  },
74
79
  "lint-staged": {
75
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
- return html `${localizedLabel(this.focusNode.pointer, { property: this.predicate })}`;
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,6 @@
1
+ import { LitElement } from 'lit';
2
+ export default class ResourceValue extends LitElement {
3
+ private readonly focusNode;
4
+ constructor();
5
+ render(): string | undefined;
6
+ }
@@ -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;
package/src/context.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { AnyPointer, GraphPointer, MultiPointer } from 'clownface';
2
2
  import type env from '@zazuko/env/web.js';
3
+ import type { Term } from '@rdfjs/types';
3
4
  export type Environment = typeof env;
4
5
  export interface SortPredicate {
5
- (node: GraphPointer): string | undefined;
6
+ (node: GraphPointer): Term | string | number | boolean | undefined;
6
7
  }
7
8
  export declare const environment: {
8
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<{
@@ -1,5 +1,6 @@
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
6
  private sortPredicateConsumer;
@@ -1,5 +1,7 @@
1
1
  import { ContextConsumer } from '@lit/context';
2
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, {
@@ -34,11 +36,6 @@ export class FocusNode {
34
36
  if (!array || !sortPredicateFunc) {
35
37
  return array;
36
38
  }
37
- return array.sort((left, right) => {
38
- if (sortDirectionValue === 'desc') {
39
- return sortPredicateFunc(right)?.localeCompare(sortPredicateFunc(left) || '') || 0;
40
- }
41
- return sortPredicateFunc(left)?.localeCompare(sortPredicateFunc(right) || '') || 0;
42
- });
39
+ return array.sort(sort(sortPredicateFunc, sortDirectionValue));
43
40
  }
44
41
  }
package/src/converter.js CHANGED
@@ -17,7 +17,7 @@ export const toNamedNode = {
17
17
  },
18
18
  };
19
19
  export const toPropertyPath = {
20
- fromAttribute(value, type) {
20
+ fromAttribute(value) {
21
21
  if (typeof value === 'undefined' || value === null) {
22
22
  throw new Error('PropertyPath converter: value is null');
23
23
  }
@@ -28,7 +28,7 @@ export const toSortPredicate = {
28
28
  fromAttribute(value) {
29
29
  const namedNode = toNamedNode.fromAttribute(value);
30
30
  return (node) => {
31
- return node.out(namedNode).value;
31
+ return node.out(namedNode).term;
32
32
  };
33
33
  },
34
34
  };
package/src/index.d.ts CHANGED
@@ -4,3 +4,4 @@ import './components/focus-node.js';
4
4
  import './components/target-node.js';
5
5
  import './components/resource-label.js';
6
6
  import './components/resource-link.js';
7
+ import './components/resource-value.js';
package/src/index.js CHANGED
@@ -4,3 +4,4 @@ import './components/focus-node.js';
4
4
  import './components/target-node.js';
5
5
  import './components/resource-label.js';
6
6
  import './components/resource-link.js';
7
+ import './components/resource-value.js';
@@ -9,9 +9,6 @@ import { state } from 'lit/decorators.js';
9
9
  import { environment as context } from '../context.js';
10
10
  export function provideEnvironment(base) {
11
11
  class Impl extends base {
12
- constructor(...args) {
13
- super(...args);
14
- }
15
12
  }
16
13
  __decorate([
17
14
  state(),
@@ -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
+ }