Skip to content

Commit cac6d62

Browse files
authored
Update docs for @reactodia/workspace@0.33.0 (#5)
1 parent 2d8dfc7 commit cac6d62

File tree

7 files changed

+36
-27
lines changed

7 files changed

+36
-27
lines changed

.github/workflows/ci-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
branches: [ "main" ]
1111

1212
env:
13-
reactodia_workspace_ref: 'v0.32.0'
13+
reactodia_workspace_ref: 'v0.33.0'
1414

1515
jobs:
1616
build:

.github/workflows/deploy-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
workflow_dispatch:
99

1010
env:
11-
reactodia_workspace_ref: 'v0.32.0'
11+
reactodia_workspace_ref: 'v0.33.0'
1212

1313
jobs:
1414
build:

docs/concepts/i18n.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function MultipleTranslations() {
7575

7676
The localization mechanism can be used for a custom component nested inside the [`Workspace`](/docs/components/workspace.md) by getting a [`Translation`](/docs/api/workspace/interfaces/Translation.md) instance which can be used to format localizable strings.
7777

78-
[`useTranslation()`](/docs/api/workspace/functions/useTranslation.md) hook can be used to acquire the `Translation` object; alternatively it is available as part of the [`WorkspaceContext`](/docs/concepts/workspace-context.md) via [`WorkspaceContext.translation`](/docs/api/workspace/interfaces/WorkspaceContext.md) property.
78+
[`useTranslation()`](/docs/api/workspace/functions/useTranslation.md) hook can be used to acquire the `Translation` object.
7979

8080
In the following example, additional custom translation keys are added to the workspace to provide localizable component labels:
8181
```tsx live noInline

docs/concepts/workspace-context.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ The [`WorkspaceContext`](/docs/api/workspace/interfaces/WorkspaceContext) contai
1616
| `view` | [`SharedCanvasState`](/docs/api/workspace/classes/SharedCanvasState.md) | Stores common state and settings for all [canvases](/docs/components/canvas.md) in the workspace. |
1717
| `editor` | [`EditorController`](/docs/api/workspace/classes/EditorController.md) | Stores, modifies and validates changes from the visual graph authoring.<br/>See [graph authoring](/docs/concepts/graph-authoring). |
1818
| `overlay` | [`OverlayController`](/docs/api/workspace/classes/OverlayController.md) | Controls UI overlays for the canvases, including dialogs and tasks. |
19-
| `translation` | [`Translation`](/docs/api/workspace/interfaces/Translation.md) | Provides a translation for UI text strings.<br/>See [i18n](/docs/concepts/i18n). |
2019

2120
## Getting the workspace context
2221

@@ -68,5 +67,5 @@ function Example() {
6867
```
6968

7069
:::note
71-
The library also uses separate context for [i18n](/docs/concepts/i18n) (which is accessible by [`useTranslation()`](/docs/api/workspace/functions/useTranslation.md) hook and `translation` property of the workspace context) and a nested context for the [`Canvas`](/docs/components/canvas.md).
70+
The library also uses separate context for [i18n](/docs/concepts/i18n) (accessible with [`useTranslation()`](/docs/api/workspace/functions/useTranslation.md) hook) and a nested context for the [`Canvas`](/docs/components/canvas.md) (accessible with [`useCanvas()`](/docs/api/workspace/functions/useCanvas.md) hook).
7271
:::

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reactodia/reactodia.github.io",
3-
"version": "0.31.2",
3+
"version": "0.33.0",
44
"private": true,
55
"scripts": {
66
"docusaurus": "docusaurus",
@@ -21,7 +21,7 @@
2121
"@easyops-cn/docusaurus-search-local": "^0.51.0",
2222
"@mdx-js/react": "^3.1.0",
2323
"@reactodia/hashmap": "^0.2.1",
24-
"@reactodia/workspace": "^0.32.0",
24+
"@reactodia/workspace": "^0.33.0",
2525
"clsx": "^2.1.1",
2626
"n3": "^1.17.2",
2727
"prism-react-renderer": "^2.4.1",

src/examples/ExampleMetadata.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,27 @@ export class ExampleMetadataProvider extends Reactodia.BaseMetadataProvider {
145145
await Reactodia.delay(SIMULATED_DELAY, {signal});
146146
const properties = new Map<Reactodia.PropertyTypeIri, Reactodia.MetadataPropertyShape>();
147147
if (types.some(type => this.editableTypes.has(type))) {
148-
properties.set(rdfs.comment, {
148+
properties.set(Reactodia.rdfs.label, {
149149
valueShape: {termType: 'Literal'},
150+
order: 1,
150151
});
151-
properties.set(Reactodia.rdfs.label, {
152+
properties.set(rdfs.comment, {
152153
valueShape: {termType: 'Literal'},
154+
order: 2,
153155
});
154156
properties.set(Reactodia.schema.thumbnailUrl, {
155157
valueShape: {termType: 'NamedNode'},
156158
maxCount: 1,
159+
order: 3,
157160
});
158161
properties.set(rdfs.seeAlso, {
159162
valueShape: {termType: 'NamedNode'},
163+
order: 4,
160164
});
161165
}
162166
return {properties};
163167
},
164-
getRelationShape: async (linkType, {signal}) => {
168+
getRelationShape: async (linkType, source, target, {signal}) => {
165169
await Reactodia.delay(SIMULATED_DELAY, {signal});
166170
const properties = new Map<Reactodia.PropertyTypeIri, Reactodia.MetadataPropertyShape>();
167171
if (this.editableRelations.has(linkType)) {
@@ -183,11 +187,16 @@ export class ExampleValidationProvider implements Reactodia.ValidationProvider {
183187
async validate(
184188
event: Reactodia.ValidationEvent
185189
): Promise<Reactodia.ValidationResult> {
190+
const {target, outboundLinks, graph, state, translation, language, signal} = event;
186191
const items: Array<Reactodia.ValidatedElement | Reactodia.ValidatedLink> = [];
187192

188-
if (event.target.types.includes(owl.Class)) {
189-
event.state.links.forEach(e => {
190-
if (e.type === 'relationAdd' && e.data.sourceId === event.target.id) {
193+
if (target.types.includes(owl.Class)) {
194+
for (const e of state.links.values()) {
195+
if (e.type === 'relationAdd' && e.data.sourceId === target.id) {
196+
const linkType = graph.getLinkType(e.data.linkTypeId);
197+
const linkLabel = translation.formatLabel(
198+
linkType?.data?.label, e.data.linkTypeId, language
199+
);
191200
items.push({
192201
type: 'link',
193202
target: e.data,
@@ -196,41 +205,42 @@ export class ExampleValidationProvider implements Reactodia.ValidationProvider {
196205
});
197206
items.push({
198207
type: 'element',
199-
target: event.target.id,
208+
target: target.id,
200209
severity: 'warning',
201-
message: `Cannot create <${e.data.linkTypeId}> link from a Class`,
210+
message: `Cannot create "${linkLabel}" relation from a Class`,
202211
});
203212
}
204-
});
213+
}
205214
}
206215

207216
if (
208-
event.state.elements.has(event.target.id) &&
209-
event.target.types.includes(owl.ObjectProperty)
217+
state.elements.has(target.id) &&
218+
target.types.includes(owl.ObjectProperty)
210219
) {
211-
if (!event.outboundLinks.some(link => link.linkTypeId === rdfs.subPropertyOf)) {
220+
if (!outboundLinks.some(link => link.linkTypeId === rdfs.subPropertyOf)) {
212221
items.push({
213222
type: 'element',
214-
target: event.target.id,
223+
target: target.id,
215224
severity: 'info',
216225
message: 'It might be a good idea to make the property a sub-property of another',
217226
});
218227
}
219228
}
220229

221-
for (const link of event.outboundLinks) {
230+
for (const link of outboundLinks) {
222231
const {[rdfs.comment]: comments} = link.properties;
223232
if (comments && !comments.every(comment => comment.termType === 'Literal' && comment.language)) {
224233
items.push({
225234
type: 'link',
226235
target: link,
227236
severity: 'error',
228-
message: 'rdfs:comment value should have a language',
237+
message: 'value should have a language',
238+
propertyType: rdfs.comment,
229239
});
230240
}
231241
}
232242

233-
await Reactodia.delay(SIMULATED_DELAY, {signal: event.signal});
243+
await Reactodia.delay(SIMULATED_DELAY, {signal});
234244
return {items};
235245
}
236246
}

0 commit comments

Comments
 (0)