@nesso-how/plugin-example 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.
- package/README.md +11 -8
- package/dist/index.js +10225 -63
- package/package.json +46 -20
- package/src/Quiz.css +50 -0
- package/src/Quiz.tsx +70 -0
- package/src/index.ts +18 -9
- package/tsconfig.json +6 -4
- package/vite.config.ts +14 -0
package/package.json
CHANGED
|
@@ -1,42 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nesso-how/plugin-example",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Official example showing how to build Nesso plugins with the SDK and plugin APIs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nesso-plugin"
|
|
7
|
+
],
|
|
5
8
|
"license": "MIT",
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "git+https://github.com/nesso-how/nesso.git",
|
|
9
12
|
"directory": "packages/plugin/example"
|
|
10
13
|
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"tsconfig.json",
|
|
18
|
+
"vite.config.ts"
|
|
19
|
+
],
|
|
11
20
|
"type": "module",
|
|
12
|
-
"
|
|
13
|
-
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
14
25
|
"scripts": {
|
|
15
26
|
"check": "tsc",
|
|
16
|
-
"build": "npm run check &&
|
|
27
|
+
"build": "npm run check && vite build",
|
|
17
28
|
"prepack": "npm run build"
|
|
18
29
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@nesso-how/ui": "1.0.0-beta.1",
|
|
32
|
+
"react": "^19.2.8",
|
|
33
|
+
"react-dom": "^19.2.8"
|
|
22
34
|
},
|
|
23
35
|
"devDependencies": {
|
|
24
|
-
"@nesso-how/plugin": "0.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
36
|
+
"@nesso-how/plugin": "0.6.0",
|
|
37
|
+
"@types/react": "^19.2.18",
|
|
38
|
+
"@types/react-dom": "^19.2.7",
|
|
39
|
+
"typescript": "~7.0.2",
|
|
40
|
+
"vite": "^8.3.0",
|
|
41
|
+
"vite-plugin-css-injected-by-js": "^5.0.3"
|
|
42
|
+
},
|
|
43
|
+
"i18n": {
|
|
44
|
+
"metadata": {
|
|
45
|
+
"name": {
|
|
46
|
+
"en": "Plugin Example"
|
|
47
|
+
},
|
|
48
|
+
"description": {
|
|
49
|
+
"en": "Learn how to build Nesso plugins with the SDK and plugin APIs."
|
|
50
|
+
},
|
|
51
|
+
"documentation": {
|
|
52
|
+
"en": "A reference plugin for developers, with practical examples of using Nesso's SDK and plugin APIs to define actions, interact with graph data, and build custom interfaces."
|
|
53
|
+
}
|
|
54
|
+
}
|
|
27
55
|
},
|
|
28
56
|
"nesso": {
|
|
29
57
|
"apiVersion": 1,
|
|
30
58
|
"kind": "actions",
|
|
31
59
|
"entry": "dist/index.js",
|
|
32
|
-
"writes": [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"documentation": { "en": "Changes the labels of concepts in the invoked view in one undoable transaction. Concepts shared with other views change there too." }
|
|
40
|
-
}
|
|
60
|
+
"writes": [
|
|
61
|
+
"concept.label"
|
|
62
|
+
],
|
|
63
|
+
"capabilities": [
|
|
64
|
+
"ui",
|
|
65
|
+
"storage"
|
|
66
|
+
]
|
|
41
67
|
}
|
|
42
68
|
}
|
package/src/Quiz.css
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
.quiz {
|
|
2
|
+
display: grid;
|
|
3
|
+
min-height: 100dvh;
|
|
4
|
+
place-items: center;
|
|
5
|
+
padding: 24px;
|
|
6
|
+
color: var(--foreground);
|
|
7
|
+
font:
|
|
8
|
+
13px/1.5 var(--font-sans),
|
|
9
|
+
system-ui,
|
|
10
|
+
sans-serif;
|
|
11
|
+
}
|
|
12
|
+
.quiz-card {
|
|
13
|
+
width: 100%;
|
|
14
|
+
max-width: 560px;
|
|
15
|
+
overflow-wrap: anywhere;
|
|
16
|
+
text-align: center;
|
|
17
|
+
}
|
|
18
|
+
.quiz h1 {
|
|
19
|
+
margin: 0 0 4px;
|
|
20
|
+
font-size: 20px;
|
|
21
|
+
font-weight: 500;
|
|
22
|
+
}
|
|
23
|
+
.quiz [data-step] {
|
|
24
|
+
margin: 0 0 16px;
|
|
25
|
+
color: var(--muted-foreground);
|
|
26
|
+
}
|
|
27
|
+
.quiz [data-question] {
|
|
28
|
+
margin: 0;
|
|
29
|
+
color: var(--muted-foreground);
|
|
30
|
+
}
|
|
31
|
+
.quiz [data-answer] {
|
|
32
|
+
min-height: 1.5em;
|
|
33
|
+
margin: 16px 0;
|
|
34
|
+
font-size: 18px;
|
|
35
|
+
}
|
|
36
|
+
.quiz [data-result] {
|
|
37
|
+
width: fit-content;
|
|
38
|
+
margin: 8px auto 24px;
|
|
39
|
+
padding: 16px 24px;
|
|
40
|
+
border: 1px solid var(--border);
|
|
41
|
+
border-radius: 12px;
|
|
42
|
+
background: var(--muted);
|
|
43
|
+
font-size: 18px;
|
|
44
|
+
font-weight: 500;
|
|
45
|
+
}
|
|
46
|
+
.quiz footer {
|
|
47
|
+
display: flex;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
gap: 8px;
|
|
50
|
+
}
|
package/src/Quiz.tsx
ADDED
|
@@ -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
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import type { ActionContribution, NessoOperation } from '@nesso-how/plugin'
|
|
2
|
-
import
|
|
2
|
+
import { Quiz } from './Quiz.js'
|
|
3
3
|
|
|
4
4
|
export const create = (): readonly ActionContribution[] => {
|
|
5
|
-
const
|
|
5
|
+
const uppercase: ActionContribution = {
|
|
6
6
|
id: 'uppercase-labels',
|
|
7
|
-
label:
|
|
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(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2022",
|
|
4
|
-
"lib": ["ES2022", "
|
|
5
|
-
"module": "
|
|
6
|
-
"moduleResolution": "
|
|
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
|
}
|
package/vite.config.ts
ADDED
|
@@ -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
|
+
})
|