Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added YAML support #85

Merged
merged 6 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-oranges-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"codemirror-json-schema": minor
---

Added YAML support, switched back to markdown for messages, provide markdown rendering, and fix some autocompletion issues
10 changes: 10 additions & 0 deletions dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<style>
:root {
--bg-color: #282c34;
--fbc-light-gray: #f0f0f4;
}
h1,
h2,
Expand Down Expand Up @@ -66,10 +67,15 @@
}
.cm6-json-schema-hover,
.cm-editor .cm-diagnostic-error {
font-size: 12px;
padding: 0.5rem;
}
.cm6-json-schema-hover--description {
margin-bottom: 0.5rem;
max-width: 600px;
}
.cm6-json-schema-hover--code-wrapper {
border-top: 1px solid #888;
}
.grid-row {
display: grid;
Expand Down Expand Up @@ -110,6 +116,10 @@ <h2><code>package.json</code> demo</h2>
<h2><code>package.json5</code> demo</h2>
<div id="editor-json5"></div>
</div>
<div>
<h2><code>package.yaml</code> demo</h2>
<div id="editor-yaml"></div>
</div>
</div>
<script type="module" src="./index.ts"></script>
</body>
Expand Down
17 changes: 16 additions & 1 deletion dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { JSONSchema7 } from "json-schema";

// sample data
import { jsonText, json5Text } from "./sample-text";
import { jsonText, json5Text, yamlText } from "./sample-text";
import packageJsonSchema from "./package.schema.json";

// json4
Expand All @@ -38,6 +38,8 @@ import { jsonSchema, updateSchema } from "../src/index";
// json5
import { json5Schema } from "../src/json5";

import { yamlSchema } from "../src/yaml";

const schema = packageJsonSchema as JSONSchema7;

/**
Expand Down Expand Up @@ -99,6 +101,19 @@ const editor2 = new EditorView({
parent: document.querySelector("#editor-json5")!,
});

/**
* yaml!
*/
const yamlState = EditorState.create({
doc: yamlText,
extensions: [commonExtensions, yamlSchema(schema)],
});

const editor3 = new EditorView({
state: yamlState,
parent: document.querySelector("#editor-yaml")!,
});

const handleSchemaChange = (newSchema: JSONSchema7) => {
updateSchema(editor1, newSchema);
updateSchema(editor2, newSchema);
acao marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
9 changes: 9 additions & 0 deletions dev/sample-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ export const json5Text = `{
}],
'type': '',
}`;

export const yamlText = `name: lexunicon
version: 0.0.0
description: A lexicon for the unicon programming language
contributors:
- email: email
url: h
type: ''
`;
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,30 @@
"default": "./cjs/index.js"
},
"./json5": {
"import": "./dist/json5.js",
"types": "./dist/json5.d.ts",
"require": "./cjs/json5.js",
"default": "./cjs/json5.js"
"import": "./dist/json5/index.js",
"types": "./dist/json5/index.d.ts",
"require": "./cjs/json5/index.js",
"default": "./cjs/json5/index.js"
},
"./yaml": {
"import": "./dist/yaml/index.js",
"types": "./dist/yaml/index.d.ts",
"require": "./cjs/yaml/index.js",
"default": "./cjs/yaml/index.js"
}
},
"repository": "github:acao/codemirror-json-schema",
"homepage": "https://codemirror-json-schema.netlify.app/",
"dependencies": {
"@changesets/changelog-github": "^0.4.8",
"@codemirror/lang-yaml": "^6.0.0",
"@sagold/json-pointer": "^5.1.1",
"@types/json-schema": "^7.0.12",
"@types/node": "^20.4.2",
"json-schema": "^0.4.0",
"json-schema-library": "^9.1.2"
"json-schema-library": "^9.1.2",
"markdown-it": "^14.0.0",
"yaml": "^2.3.4"
},
"optionalDependencies": {
"@codemirror/lang-json": "^6.0.1",
Expand All @@ -82,6 +91,7 @@
"@codemirror/view": "^6.14.1",
"@evilmartians/lefthook": "^1.4.6",
"@lezer/common": "^1.0.3",
"@types/markdown-it": "^13.0.7",
"@vitest/coverage-v8": "^0.34.6",
"codemirror": "^6.0.1",
"codemirror-json5": "^1.0.3",
Expand Down
112 changes: 111 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading