@nesso-how/plugin 0.4.0 → 0.6.0

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.
@@ -0,0 +1,70 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { Button } from '@nesso-how/ui'
3
+ import type { ActionContext } from '@nesso-how/plugin'
4
+ import './Quiz.css'
5
+
6
+ export function Quiz({ document, storage, viewId }: ActionContext) {
7
+ const [step, setStep] = useState<number | null>(null)
8
+ const [revealed, setRevealed] = useState(false)
9
+ const key = `quiz:${viewId ?? 'all'}`
10
+
11
+ useEffect(() => {
12
+ void storage.list().then((records) => {
13
+ const value = records.find(
14
+ (record) => record.key === key && record.conceptId === undefined,
15
+ )?.value
16
+ setStep(typeof value === 'number' ? value : 0)
17
+ })
18
+ }, [storage, key])
19
+
20
+ async function saveStep(next: number) {
21
+ setStep(null)
22
+ await storage.set(key, next)
23
+ setRevealed(false)
24
+ setStep(next)
25
+ }
26
+
27
+ if (step === null) return null
28
+
29
+ const { concepts, relations, relationTypes } = document.getState().viewGraph
30
+ const relation = relations[step]
31
+ const relationType = relationTypes.find(({ id }) => id === relation?.predicate)
32
+ const conceptLabel = (id: string) => concepts.find((item) => item.id === id)?.label || id
33
+ const buttonLabel = !relation ? 'Completed' : revealed ? 'Next' : 'Show concept'
34
+
35
+ return (
36
+ <section className="quiz">
37
+ <div className="quiz-card">
38
+ <h1>Concept Quiz</h1>
39
+ <p data-step>
40
+ Step {Math.min(step + 1, relations.length)} / {relations.length}
41
+ </p>
42
+ {relation ? (
43
+ <>
44
+ <p data-question>
45
+ {conceptLabel(relation.source)} — {relationType?.label || relation.predicate} → ?
46
+ </p>
47
+ <p data-answer role="status">
48
+ {revealed ? conceptLabel(relation.target) : ''}
49
+ </p>
50
+ </>
51
+ ) : (
52
+ <p data-result role="status">
53
+ {relations.length ? 'Quiz complete!' : 'This view has no relations.'}
54
+ </p>
55
+ )}
56
+ <footer>
57
+ <Button variant="outline" onClick={() => void saveStep(0)}>
58
+ Reset
59
+ </Button>
60
+ <Button
61
+ disabled={!relation}
62
+ onClick={() => (revealed ? void saveStep(step + 1) : setRevealed(true))}
63
+ >
64
+ {buttonLabel}
65
+ </Button>
66
+ </footer>
67
+ </div>
68
+ </section>
69
+ )
70
+ }
@@ -1,22 +1,31 @@
1
1
  import type { ActionContribution, NessoOperation } from '@nesso-how/plugin'
2
- import source from '../package.json' with { type: 'json' }
2
+ import { Quiz } from './Quiz.js'
3
3
 
4
4
  export const create = (): readonly ActionContribution[] => {
5
- const action: ActionContribution = {
5
+ const uppercase: ActionContribution = {
6
6
  id: 'uppercase-labels',
7
- label: source.i18n.metadata.name,
7
+ label: { en: 'Uppercase labels' },
8
8
  run: async ({ document }) => {
9
9
  const state = document.getState()
10
10
 
11
- const operations: readonly NessoOperation[] = state.viewGraph.concepts.map(({ id, label }) => ({
12
- kind: 'concept.label',
13
- id,
14
- value: label.toUpperCase(),
15
- }))
11
+ const operations: readonly NessoOperation[] = state.viewGraph.concepts.map(
12
+ ({ id, label }) => ({
13
+ kind: 'concept.label',
14
+ id,
15
+ value: label.toUpperCase(),
16
+ }),
17
+ )
16
18
 
17
19
  await document.applyOperations(operations)
18
20
  },
19
21
  }
20
22
 
21
- return [action]
23
+ const quiz: ActionContribution = {
24
+ id: 'concept-quiz',
25
+ label: { en: 'Concept Quiz' },
26
+ ui: Quiz,
27
+ icon: 'play',
28
+ }
29
+
30
+ return [uppercase, quiz]
22
31
  }
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
- "lib": ["ES2022", "WebWorker"],
5
- "module": "NodeNext",
6
- "moduleResolution": "NodeNext",
4
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "jsx": "react-jsx",
7
8
  "resolveJsonModule": true,
9
+ "allowImportingTsExtensions": true,
8
10
  "strict": true,
9
11
  "verbatimModuleSyntax": true,
10
12
  "noEmit": true,
11
- "types": []
13
+ "types": ["vite/client"]
12
14
  },
13
15
  "include": ["src"]
14
16
  }
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'vite'
2
+ import cssInjectedByJs from 'vite-plugin-css-injected-by-js'
3
+
4
+ export default defineConfig({
5
+ root: import.meta.dirname,
6
+ publicDir: false,
7
+ plugins: [cssInjectedByJs()],
8
+ define: { 'process.env.NODE_ENV': '"production"' },
9
+ build: {
10
+ target: 'es2022',
11
+ lib: { entry: 'src/index.ts', formats: ['es'], fileName: () => 'index.js' },
12
+ rolldownOptions: { external: /^react(?:-dom)?(?:\/|$)/ },
13
+ },
14
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nesso-how/plugin",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Types, validation, and asynchronous clients for isolated Nesso plugins",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,11 +8,11 @@
8
8
  "url": "git+https://github.com/nesso-how/nesso.git",
9
9
  "directory": "packages/plugin"
10
10
  },
11
- "type": "module",
12
11
  "files": [
13
12
  "dist",
14
13
  "example"
15
14
  ],
15
+ "type": "module",
16
16
  "types": "./dist/index.d.ts",
17
17
  "exports": {
18
18
  ".": {
@@ -32,19 +32,25 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
+ "@types/react": "^19.3.0",
35
36
  "semver": "^7.8.5",
36
37
  "validate-npm-package-name": "^8.0.0",
37
38
  "zod": "^4.6.5"
38
39
  },
39
40
  "devDependencies": {
41
+ "@nesso-how/core": "0.0.0",
40
42
  "@nesso-how/errors": "0.0.0",
41
43
  "@nesso-how/i18n": "0.0.0",
42
44
  "@nesso-how/schema": "0.0.0",
45
+ "@types/react-dom": "^19.3.0",
43
46
  "@types/semver": "^7.8.0",
44
47
  "@types/validate-npm-package-name": "^4.0.2",
48
+ "es-module-lexer": "^3.0.4",
49
+ "react": "^19.3.0",
50
+ "react-dom": "^19.3.0",
45
51
  "tsdown": "^0.23.1"
46
52
  },
47
53
  "scripts": {
48
- "build": "tsc -p ../../tsconfig.plugin.json && tsdown"
54
+ "build": "tsc -p ../../tsconfig.plugin.json && tsdown && tsc -p tsconfig.json"
49
55
  }
50
56
  }