testomatio-editor-blocks 0.1.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 ADDED
@@ -0,0 +1,121 @@
1
+ # Testomatio Editor Blocks
2
+
3
+ Custom BlockNote blocks, schema, and Markdown conversion helpers for Testomatio-style test cases and steps. The repository bundles two things:
4
+
5
+ - A Vite playground (`npm run dev`) for trying the blocks in isolation.
6
+ - A publishable package (`npm run build:package`) that writes the distributable files to `package/`.
7
+
8
+ ## Prerequisites
9
+
10
+ - Node.js 20+
11
+ - npm 9+
12
+
13
+ Install once after cloning:
14
+
15
+ ```bash
16
+ npm install
17
+ ```
18
+
19
+ ## Running The UI
20
+
21
+ Start the Vite dev server:
22
+
23
+ ```bash
24
+ npm run dev
25
+ ```
26
+
27
+ The app defaults to `http://localhost:5173`. Paste Markdown (including tables or step blocks) directly into the editor to see it converted into structured blocks, while the right-hand panels display the Markdown and block JSON previews.
28
+
29
+ ## Building the Package
30
+
31
+ Create the publishable bundle (JavaScript, type declarations, and stylesheet) by running:
32
+
33
+ ```bash
34
+ npm run build:package
35
+ ```
36
+
37
+ The compiled files land in `package/`:
38
+
39
+ - `package/index.js` and `package/index.d.ts` export the schema plus converters.
40
+ - `package/editor/...` contains the underlying source hierarchy for easier debugging.
41
+ - `package/styles.css` ships all required styles for the blocks.
42
+
43
+ Running `npm run build` will also invoke Vite and place the playground site in `dist/`, which you can upload to Cloudflare Pages if you want a hosted demo.
44
+
45
+ ## Using Inside Any BlockNote Editor
46
+
47
+ 1. **Install**
48
+
49
+ Add `testomatio-editor-blocks` alongside the BlockNote packages you already use:
50
+
51
+ ```bash
52
+ npm install testomatio-editor-blocks @blocknote/react @blocknote/core
53
+ ```
54
+
55
+ (If you are working locally before publishing, use `npm install ../path/to/testomatio-editor-blocks --save`.)
56
+
57
+ 2. **Load the schema and helpers**
58
+
59
+ ```jsx
60
+ import { BlockNoteView } from "@blocknote/mantine";
61
+ import { useCreateBlockNote, useEditorChange } from "@blocknote/react";
62
+ import {
63
+ customSchema,
64
+ markdownToBlocks,
65
+ blocksToMarkdown,
66
+ testomatioEditorClassName,
67
+ } from "testomatio-editor-blocks";
68
+ import "testomatio-editor-blocks/styles.css";
69
+
70
+ const editor = useCreateBlockNote({
71
+ schema: customSchema,
72
+ pasteHandler: ({ event, editor, defaultPasteHandler }) => {
73
+ const text = event.clipboardData?.getData("text/plain") ?? "";
74
+ if (!text.trim()) {
75
+ return defaultPasteHandler();
76
+ }
77
+ try {
78
+ const blocks = markdownToBlocks(text);
79
+ editor.insertBlocks(blocks);
80
+ return true;
81
+ } catch {
82
+ return defaultPasteHandler();
83
+ }
84
+ },
85
+ });
86
+
87
+ useEditorChange((instance) => {
88
+ const markdown = blocksToMarkdown(instance.document);
89
+ // Persist markdown to your backend or trigger app logic.
90
+ console.log(markdown);
91
+ }, editor);
92
+
93
+ return (
94
+ <BlockNoteView
95
+ editor={editor}
96
+ className={testomatioEditorClassName}
97
+ slashMenu={false}
98
+ />
99
+ );
100
+ ```
101
+
102
+ 3. **Work with Markdown**
103
+
104
+ - `markdownToBlocks(markdown: string)` converts Testomatio Markdown into BlockNote block definitions ready for insertion.
105
+ - `blocksToMarkdown(blocks)` serialises editor content back into Markdown for storing or syncing.
106
+ - `testomatioEditorClassName` gives you the `markdown` wrapper class so the editor inherits the same Tailwind typography styles as your read-only view.
107
+
108
+ 4. **Blocks Available**
109
+
110
+ - `testCase`: rich-text wrapper with status and reference metadata.
111
+ - `testStep`: inline WYSIWYG inputs for Step Title, Data, and Expected Result with bold/italic/underline formatting.
112
+
113
+ ## Running Tests
114
+
115
+ Vitest covers the Markdown/block converter. Run the suite with:
116
+
117
+ ```bash
118
+ npm run test:run
119
+ ```
120
+
121
+ Use `npm run test` if you prefer the interactive watcher.
@@ -0,0 +1,8 @@
1
+ import type { Block, PartialBlock } from "@blocknote/core";
2
+ import type { customSchema } from "./customSchema";
3
+ type Schema = typeof customSchema;
4
+ export type CustomEditorBlock = Block<Schema["blockSchema"], Schema["inlineContentSchema"], Schema["styleSchema"]>;
5
+ export type CustomPartialBlock = PartialBlock<Schema["blockSchema"], Schema["inlineContentSchema"], Schema["styleSchema"]>;
6
+ export declare function blocksToMarkdown(blocks: CustomEditorBlock[]): string;
7
+ export declare function markdownToBlocks(markdown: string): CustomPartialBlock[];
8
+ export {};