skir-codemirror-plugin 0.9.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 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
- - `Json` (type)
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 type { Json } from "./json/types";
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
@@ -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,IAAI,EAAE,MAAM,cAAc,CAAC"}
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
@@ -1,2 +1,4 @@
1
1
  export { createEditorState } from "./codemirror/create_editor_state";
2
+ export { ensureJsonState } from "./codemirror/json_state";
3
+ export { toJson } from "./json/to_json";
2
4
  //# sourceMappingURL=index.js.map
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 { Json } from \"./json/types\";\n"]}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skir-codemirror-plugin",
3
- "version": "0.9.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/gepheum/skir-codemirror-plugin#readme",
6
6
  "bugs": {
@@ -45,14 +45,10 @@
45
45
  "prepublishOnly": "npm run build"
46
46
  },
47
47
  "dependencies": {
48
- "@codemirror/buildhelper": "^1.0.2",
49
48
  "@codemirror/lang-json": "^6.0.2",
50
- "@codemirror/language": "^6.11.2",
51
49
  "@uiw/codemirror-theme-tokyo-night": "^4.25.4",
52
50
  "@uiw/codemirror-theme-tokyo-night-day": "^4.25.9",
53
51
  "codemirror": "^6.0.2",
54
- "lit": "^3.2.0",
55
- "nanoevents": "^9.1.0",
56
52
  "skir-client": "^1.0.11"
57
53
  },
58
54
  "devDependencies": {
@@ -62,7 +58,6 @@
62
58
  "@web/dev-server": "^0.4.6",
63
59
  "@web/dev-server-import-maps": "^0.2.1",
64
60
  "@web/dev-server-legacy": "^1.0.0",
65
- "@webcomponents/webcomponentsjs": "^2.8.0",
66
61
  "buckwheat": "^1.1.2",
67
62
  "concurrently": "^9.2.1",
68
63
  "eslint": "^10.0.1",
@@ -72,7 +67,6 @@
72
67
  "prettier-plugin-organize-imports": "^4.2.0",
73
68
  "rimraf": "^6.1.3",
74
69
  "ts-node": "^10.9.2",
75
- "tsx": "^4.21.0",
76
70
  "typescript": "~5.5.0",
77
71
  "typescript-eslint": "^8.56.0"
78
72
  },
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 type { Json } from "./json/types";
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";