Skip to content

Commit

Permalink
Merge pull request #301 from hypermedia-app/shaperone-env
Browse files Browse the repository at this point in the history
refactor: introduce `ShaperoneEnvironment`
  • Loading branch information
tpluscode authored Mar 26, 2024
2 parents b142947 + 39808ae commit 0c1f88b
Show file tree
Hide file tree
Showing 324 changed files with 21,137 additions and 16,142 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-experts-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hydrofoil/shaperone-rdf-validate-shacl": minor
---

Deprecated `validate.with`
15 changes: 15 additions & 0 deletions .changeset/curvy-mugs-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@hydrofoil/shaperone-playground-examples": patch
"@hydrofoil/shaperone-playground": patch
"@hydrofoil/shaperone-core": patch
"@hydrofoil/shaperone-core-tests": patch
"@hydrofoil/shaperone-hydra": patch
"@hydrofoil/shaperone-rdf-validate-shacl": patch
"@shaperone/testing": patch
"@hydrofoil/shaperone-wc": patch
"@hydrofoil/shaperone-wc-material": patch
"@hydrofoil/shaperone-wc-shoelace": patch
"@hydrofoil/shaperone-wc-vaadin": patch
---

Update RDF/JS-related dependencies (closes #300)
5 changes: 5 additions & 0 deletions .changeset/gorgeous-tips-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hydrofoil/shaperone-core": patch
---

Use a centralised RDF/JS Environment. Component implementors are encouraged to use the `env` parameter passed to the render function.
5 changes: 5 additions & 0 deletions .changeset/hot-students-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hydrofoil/shaperone-wc-shoelace": minor
---

Updated shoelace to v2.15
5 changes: 5 additions & 0 deletions .changeset/quick-weeks-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hydrofoil/shaperone-wc": minor
---

Configuration objects must be retrieved by calling `configure` first
14 changes: 14 additions & 0 deletions .changeset/rude-queens-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@hydrofoil/shaperone-playground-examples": minor
"@hydrofoil/shaperone-playground": minor
"@hydrofoil/shaperone-core-tests": minor
"@hydrofoil/shaperone-hydra": minor
"@hydrofoil/shaperone-rdf-validate-shacl": minor
"@shaperone/testing": minor
"@hydrofoil/shaperone-wc": minor
"@hydrofoil/shaperone-wc-material": minor
"@hydrofoil/shaperone-wc-shoelace": minor
"@hydrofoil/shaperone-wc-vaadin": minor
---

Use a centralised RDF/JS Environment
5 changes: 5 additions & 0 deletions .changeset/spotty-icons-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hydrofoil/shaperone-wc-vaadin": minor
---

Update vaadin components to v22
7 changes: 7 additions & 0 deletions .changeset/swift-geese-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@hydrofoil/shaperone-core": minor
---

Changes to `@hydrofoil/shaperone-wc/configure`:
- It is now required to call `env.use($rdf)`
- `editors.addMetadata` now takes a function `(env: ShaperoneEnvironment) => DatasetCore | Iterable<Quad>`
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
"max-len": ["error", 200],
"wc/guard-super-call": "off",
"class-methods-use-this": "off",
"no-param-reassign": ["error", { "props": false }]
"no-param-reassign": ["error", { "props": false }],
"@typescript-eslint/no-explicit-any": "off",
"lit/no-classfield-shadowing": "warn"
},
"overrides": [{
"files": "**/test/**/*.ts",
"rules": {
"no-unused-expressions": "warn",
"babel/no-unused-expressions": "off"
"babel/no-unused-expressions": "off",
"lit-a11y/accessible-name": "off"
}
},{
"files": "packages/core-tests/**/*.ts",
Expand Down
8 changes: 8 additions & 0 deletions .github/pr-commenter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
comment:
on-update: nothing
snippets:
- id: preview-url
files:
- 'packages/**/*'
- 'demos/**/*'
body: "Netlify preview deployed to [{{ url }}]({{ url }})"
26 changes: 13 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
- run: yarn install --ci
node-version: 18
- run: npm ci
- run: yarn lint

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
- run: yarn install --ci
node-version: 18
- run: npm ci
- run: yarn tsc --noEmit
- run: yarn build
- run: yarn prerelease
- run: npx wsrun -m prepack --noEmit

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
- run: yarn install --ci
node-version: 18
- run: npm ci
- run: yarn test
- name: Codecov
uses: codecov/codecov-action@v3
Expand Down
30 changes: 17 additions & 13 deletions .github/workflows/netlify.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
name: Netlify

on: push
on:
pull_request:
push:
branches:
- master

jobs:
Deploy:
runs-on: ubuntu-latest
env:
NETLIFY_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- run: yarn install --ci
- run: npm ci

- uses: nelonoel/[email protected]

Expand All @@ -24,7 +28,7 @@ jobs:
run: npx json -I -f dist/variables.json -e "this.playground='https://$DOMAIN/playground'"

- name: Publish preview
uses: tpluscode/action-netlify-deploy@nvm
uses: jsmrcaga/action-netlify-deploy@v2.1.0
if: env.NETLIFY_TOKEN
with:
NETLIFY_AUTH_TOKEN: ${{ env.NETLIFY_TOKEN }}
Expand All @@ -33,12 +37,12 @@ jobs:
build_directory: dist
deploy_alias: ${{ env.BRANCH_NAME }}
NETLIFY_DEPLOY_TO_PROD: ${{ env.BRANCH_NAME == 'master' }}
monorepo_package: "@hydrofoil/shaperone-playground"

- name: Status check
uses: Sibz/[email protected]
if: env.NETLIFY_TOKEN
- uses: exercism/[email protected]
with:
authToken: ${{ secrets.GITHUB_TOKEN }}
context: Netlify Site
state: success
target_url: https://${{ env.BRANCH_NAME }}--shaperone.netlify.app
github-token: ${{ secrets.GITHUB_TOKEN }}
template-variables: |
{
"url": "${{ env.NETLIFY_PREVIEW_URL }}"
}
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Install Dependencies
run: yarn
run: npm ci

- name: Create Release Pull Request or Publish to npm
id: changesets
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
18
16 changes: 0 additions & 16 deletions babel.config.json

This file was deleted.

12 changes: 6 additions & 6 deletions demos/examples/ErrorSummary/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { decorate, FocusNodeTemplate } from '@hydrofoil/shaperone-wc/templates'
import { decorate, FocusNodeTemplate } from '@hydrofoil/shaperone-wc/templates.js'
import { html } from '@hydrofoil/shaperone-wc'
import type { ValidationResult } from '@rdfine/shacl'
import { shrink } from '@zazuko/rdf-vocabularies/shrink'
import TermMap from '@rdf-esm/term-map'
import { Term } from 'rdf-js'
import { shrink } from '@zazuko/prefixes/shrink'
import rdf from '@zazuko/env/web.js'
import type { Term } from '@rdfjs/types'

function createMessage(result: ValidationResult) {
if (result.resultMessage) {
Expand Down Expand Up @@ -46,7 +46,7 @@ export const errorSummary = decorate((focusNode: FocusNodeTemplate) => (context,
const summary = context.focusNode.validationResults
.reduce(({ focusNodes, errors }, { result }) => {
if (result.focusNode) {
const focusNodeErrors = focusNodes.get(result.focusNode) || { properties: new TermMap(), errors: [] }
const focusNodeErrors = focusNodes.get(result.focusNode) || { properties: rdf.termMap(), errors: [] }
if (result.resultPath) {
const pathErrors = focusNodeErrors.properties.get(result.resultPath.id)
if (pathErrors) {
Expand All @@ -64,7 +64,7 @@ export const errorSummary = decorate((focusNode: FocusNodeTemplate) => (context,
}

return { focusNodes, errors }
}, { focusNodes: new TermMap(), errors: [] } as Errors)
}, { focusNodes: rdf.termMap(), errors: [] } as Errors)

if (summary.errors.length || summary.focusNodes.size) {
return html`${renderSummary(summary)} ${focusNode(context, args)}`
Expand Down
21 changes: 13 additions & 8 deletions demos/examples/LanguageMultiSelect/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { MultiEditorComponent, html } from '@hydrofoil/shaperone-wc'
import { quad, namedNode, literal } from '@rdf-esm/data-model'
import $rdf from '@zazuko/env/web.js'
import { MultiEditor, Lazy } from '@hydrofoil/shaperone-core'
import { vcard, dash, rdf, rdfs } from '@tpluscode/rdf-ns-builders'
import { vcard, rdfs } from '@tpluscode/rdf-ns-builders'
import { getLocalizedLabel } from '@rdfjs-elements/lit-helpers'
import { sort } from '@hydrofoil/shaperone-core/lib/components'
import { sort } from '@hydrofoil/shaperone-core/lib/components.js'
import { ShaperoneEnvironment } from '@hydrofoil/shaperone-core/env.js'

const editor = namedNode('http://example.com/LanguageMultiSelect')
const editor = $rdf.namedNode('http://example.com/LanguageMultiSelect')

export const component: (theme: 'lumo' | 'material') => Lazy<MultiEditorComponent> = theme => ({
editor,
async lazyRender() {
await import(`multiselect-combo-box/theme/${theme}/multiselect-combo-box`)
if (theme === 'material') {
await import(/* @vite-ignore */'multiselect-combo-box/theme/material/multiselect-combo-box.js')
} else {
await import(/* @vite-ignore */'multiselect-combo-box/theme/lumo/multiselect-combo-box.js')
}

return ({ property }, { update }) => {
const languages = property.shape.in
Expand Down Expand Up @@ -58,7 +63,7 @@ export const matcher: MultiEditor = {
},
}

export function * metadata() {
yield quad(editor, rdf.type, dash.MultiEditor)
yield quad(editor, rdfs.label, literal('Language combobox'))
export function * metadata(env: ShaperoneEnvironment) {
yield env.quad(editor, env.ns.rdf.type, env.ns.dash.MultiEditor)
yield env.quad(editor, env.ns.rdfs.label, env.literal('Language combobox'))
}
2 changes: 1 addition & 1 deletion demos/examples/NestedShapesIndividually/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decorate, FormTemplate } from '@hydrofoil/shaperone-wc/templates'
import { decorate, FormTemplate } from '@hydrofoil/shaperone-wc/templates.js'
import { html, css } from '@hydrofoil/shaperone-wc'

export const topmostFocusNodeFormRenderer = decorate((form: FormTemplate): FormTemplate => {
Expand Down
21 changes: 11 additions & 10 deletions demos/examples/StarRating/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import type { IconDefinition } from '@fortawesome/fontawesome-common-types'
import type { IconName } from '@fortawesome/fontawesome-svg-core'
import { html, SingleEditor, Lazy, SingleEditorComponent } from '@hydrofoil/shaperone-wc'
import type { UpdateComponentState } from '@hydrofoil/shaperone-core/models/components'
import { literal, namedNode, quad } from '@rdf-esm/data-model'
import { rdf, rdfs, schema, xsd } from '@tpluscode/rdf-ns-builders'
import { schema, xsd } from '@tpluscode/rdf-ns-builders'
import { dash } from '@tpluscode/rdf-ns-builders/loose'
import type { PropertyShape } from '@rdfine/shacl'
import { ShaperoneEnvironment } from '@hydrofoil/shaperone-core/env.js'
import rdf from '@zazuko/env/web.js'

export interface StarRating {
icon?: IconDefinition | null
Expand All @@ -16,7 +17,7 @@ export interface StarRatingComponent extends SingleEditorComponent<StarRating> {
defaultIcon?: IconDefinition
}

const editor = namedNode('http://example.com/StarRating')
const editor = rdf.namedNode('http://example.com/StarRating')

interface LoadIcon {
defaultIcon: IconDefinition | undefined
Expand All @@ -29,7 +30,7 @@ async function loadIcon({ defaultIcon, shape, updateComponentState }: LoadIcon)
const iconName: IconName | undefined = shape.pointer.out(dash.icon).value as IconName
if (iconName) {
try {
({ definition: icon } = await import(`@fortawesome/free-solid-svg-icons/${iconName}.js`))
({ definition: icon } = await import(/* @vite-ignore */`@fortawesome/free-solid-svg-icons/${iconName}.js`))
} catch (e) {
icon = null
}
Expand Down Expand Up @@ -64,13 +65,13 @@ export const component: Lazy<StarRatingComponent> = {
return false
},
async lazyRender() {
await import('./star-rating')
await import('./star-rating.js')

return function ({ value }, { update }) {
return function ({ env, value }, { update }) {
const rating = value.object ? Number.parseFloat(value.object.value) : 0

function setRating(e: CustomEvent) {
update(literal(e.detail.value.toString(), xsd.float))
update(env.literal(e.detail.value.toString(), xsd.float))
}

return html`<ex-star-rating .value="${rating}"
Expand All @@ -87,7 +88,7 @@ export const matcher: SingleEditor = {
},
}

export function * metadata() {
yield quad(editor, rdf.type, dash.SingleEditor)
yield quad(editor, rdfs.label, literal('Star rating'))
export function * metadata(env: ShaperoneEnvironment) {
yield env.quad(editor, env.ns.rdf.type, env.ns.dash.SingleEditor)
yield env.quad(editor, env.ns.rdfs.label, env.literal('Star rating'))
}
4 changes: 2 additions & 2 deletions demos/examples/XoneRenderer/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { decorate, FocusNodeTemplate } from '@hydrofoil/shaperone-wc/templates'
import { decorate, FocusNodeTemplate } from '@hydrofoil/shaperone-wc/templates.js'
import { html } from '@hydrofoil/shaperone-wc'
import { LogicalConstraint } from '@hydrofoil/shaperone-core/models/forms'
import type { Shape } from '@rdfine/shacl'
import { Term } from 'rdf-js'
import type { Term } from '@rdfjs/types'
import { localizedLabel } from '@rdfjs-elements/lit-helpers/localizedLabel.js'

const selectedShapes = new WeakMap<Term, Shape>()
Expand Down
Loading

0 comments on commit 0c1f88b

Please sign in to comment.