skir-codemirror-plugin 1.0.0 → 1.0.1
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 +39 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -1
package/README.md
CHANGED
|
@@ -28,9 +28,12 @@ npm install skir-codemirror-plugin
|
|
|
28
28
|
The package root exports:
|
|
29
29
|
|
|
30
30
|
- `createEditorState`
|
|
31
|
+
- `ensureJsonState`
|
|
32
|
+
- `toJson`
|
|
31
33
|
- `CreateEditorStateParams` (type)
|
|
32
34
|
- `CustomTheme` (type)
|
|
33
|
-
- `
|
|
35
|
+
- `JsonState` (type)
|
|
36
|
+
- all types from `./json/types`
|
|
34
37
|
|
|
35
38
|
## Usage
|
|
36
39
|
|
|
@@ -60,6 +63,41 @@ new EditorView({
|
|
|
60
63
|
});
|
|
61
64
|
```
|
|
62
65
|
|
|
66
|
+
## Read Current JSON Value
|
|
67
|
+
|
|
68
|
+
Use `ensureJsonState(view, schema)` to force parse/validation against the current
|
|
69
|
+
document and retrieve the latest state. Then call `toJson(...)` on
|
|
70
|
+
`parseResult.value` when it exists.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { EditorView } from "@codemirror/view";
|
|
74
|
+
import {
|
|
75
|
+
createEditorState,
|
|
76
|
+
ensureJsonState,
|
|
77
|
+
toJson,
|
|
78
|
+
type TypeDefinition,
|
|
79
|
+
} from "skir-codemirror-plugin";
|
|
80
|
+
|
|
81
|
+
const schema: TypeDefinition = {
|
|
82
|
+
type: { kind: "primitive", value: "string" },
|
|
83
|
+
records: [],
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const view = new EditorView({
|
|
87
|
+
state: createEditorState({ schema }),
|
|
88
|
+
parent: document.getElementById("editor")!,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const jsonState = ensureJsonState(view, schema);
|
|
92
|
+
|
|
93
|
+
if (jsonState.parseResult.value) {
|
|
94
|
+
const jsonValue = toJson(jsonState.parseResult.value);
|
|
95
|
+
console.log("Current JSON value:", jsonValue);
|
|
96
|
+
} else {
|
|
97
|
+
console.log("Cannot convert to JSON:", jsonState.parseResult.errors);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
63
101
|
## createEditorState Parameters
|
|
64
102
|
|
|
65
103
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { createEditorState } from "./codemirror/create_editor_state";
|
|
2
2
|
export type { CreateEditorStateParams, CustomTheme, } from "./codemirror/create_editor_state";
|
|
3
|
-
export
|
|
3
|
+
export { ensureJsonState } from "./codemirror/json_state";
|
|
4
|
+
export type { JsonState } from "./codemirror/json_state";
|
|
5
|
+
export { toJson } from "./json/to_json";
|
|
6
|
+
export type * from "./json/types";
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,YAAY,EACV,uBAAuB,EACvB,WAAW,GACZ,MAAM,kCAAkC,CAAC;AAC1C,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,YAAY,EACV,uBAAuB,EACvB,WAAW,GACZ,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,YAAY,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,mBAAmB,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC","sourcesContent":["export { createEditorState } from \"./codemirror/create_editor_state\";\nexport type {\n CreateEditorStateParams,\n CustomTheme,\n} from \"./codemirror/create_editor_state\";\nexport type {
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAKrE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export { createEditorState } from \"./codemirror/create_editor_state\";\nexport type {\n CreateEditorStateParams,\n CustomTheme,\n} from \"./codemirror/create_editor_state\";\nexport { ensureJsonState } from \"./codemirror/json_state\";\nexport type { JsonState } from \"./codemirror/json_state\";\nexport { toJson } from \"./json/to_json\";\nexport type * from \"./json/types\";\n"]}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,4 +3,7 @@ export type {
|
|
|
3
3
|
CreateEditorStateParams,
|
|
4
4
|
CustomTheme,
|
|
5
5
|
} from "./codemirror/create_editor_state";
|
|
6
|
-
export
|
|
6
|
+
export { ensureJsonState } from "./codemirror/json_state";
|
|
7
|
+
export type { JsonState } from "./codemirror/json_state";
|
|
8
|
+
export { toJson } from "./json/to_json";
|
|
9
|
+
export type * from "./json/types";
|