Skip to content

Commit 8cf9562

Browse files
committed
added app-wide and per-document function extensions
1 parent 3517425 commit 8cf9562

8 files changed

Lines changed: 437 additions & 305 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"build-web": "echo 'export * from \"./web\"' > src/backend/index.ts && bun run build && echo 'export * from \"./tauri\"' > src/backend/index.ts",
1414
"deploy": "bun run build-web && netlify deploy -d dist --prod --site tyx-editor",
1515
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
16-
"schema": "typescript-json-schema tsconfig.json TyXSettings > schemas/tyx-settings.schema.json && typescript-json-schema tsconfig.json TyXDocument > schemas/tyx-document.schema.json"
16+
"schema": "bun scripts/create-json-schemas.ts"
1717
},
1818
"dependencies": {
1919
"@lexical/react": "^0.33.0",
@@ -54,7 +54,6 @@
5454
"prettier": "^3.5.3",
5555
"typescript": "^5.8.3",
5656
"typescript-eslint": "^8.36.0",
57-
"typescript-json-schema": "^0.65.1",
5857
"vite": "^5.4.19",
5958
"vite-plugin-static-copy": "^3.0.0"
6059
},

schemas/tyx-document.schema.json

Lines changed: 140 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,151 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"definitions": {
4-
"ElementFormatType": {
5-
"enum": ["", "center", "end", "justify", "left", "right", "start"],
6-
"type": "string"
7-
},
8-
"Omit<SerializedLexicalNode,\"format\"|\"children\"|\"direction\"|\"indent\"|\"textFormat\"|\"textStyle\">": {
9-
"properties": {
10-
"$": {
11-
"$ref": "#/definitions/Record<string,unknown>",
12-
"description": "Any state persisted with the NodeState API that is not\nconfigured for flat storage"
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"properties": {
5+
"version": {
6+
"description": "The version of TyX in which the document was created.",
7+
"type": "string"
138
},
14-
"type": {
15-
"description": "The type string used by the Node class",
16-
"type": "string"
9+
"preamble": {
10+
"description": "Raw Typst code to insert before the content.",
11+
"type": "string"
1712
},
18-
"version": {
19-
"description": "A numeric version for this schema, defaulting to 1, but not generally recommended for use",
20-
"type": "number"
21-
}
22-
},
23-
"type": "object"
24-
},
25-
"Record<string,unknown>": {
26-
"type": "object"
27-
},
28-
"SerializedEditorState<SerializedLexicalNode>": {
29-
"properties": {
30-
"root": {
31-
"$ref": "#/definitions/SerializedRootNode<SerializedLexicalNode>"
32-
}
33-
},
34-
"type": "object"
35-
},
36-
"SerializedRootNode<SerializedLexicalNode>": {
37-
"allOf": [
38-
{
39-
"$ref": "#/definitions/Omit<SerializedLexicalNode,\"format\"|\"children\"|\"direction\"|\"indent\"|\"textFormat\"|\"textStyle\">"
13+
"filename": {
14+
"description": "The filename of the document, unused.",
15+
"type": "string"
4016
},
41-
{
42-
"properties": {
43-
"children": {
44-
"items": {
45-
"description": "The base type for all serialized nodes",
46-
"properties": {
47-
"$": {
48-
"$ref": "#/definitions/Record<string,unknown>",
49-
"description": "Any state persisted with the NodeState API that is not\nconfigured for flat storage"
50-
},
51-
"type": {
52-
"description": "The type string used by the Node class",
17+
"content": {
18+
"description": "The serialized content of the editor."
19+
},
20+
"dirty": {
21+
"description": "Whether the document has been modified since loading, unused.",
22+
"type": "boolean"
23+
},
24+
"settings": {
25+
"description": "The document's settings.",
26+
"type": "object",
27+
"properties": {
28+
"root": {
5329
"type": "string"
54-
},
55-
"version": {
56-
"description": "A numeric version for this schema, defaulting to 1, but not generally recommended for use",
57-
"type": "number"
58-
}
5930
},
60-
"type": "object"
61-
},
62-
"type": "array"
63-
},
64-
"direction": {
65-
"anyOf": [
66-
{
67-
"enum": ["ltr", "rtl"],
68-
"type": "string"
31+
"fontPaths": {
32+
"type": "array",
33+
"items": {
34+
"type": "string"
35+
}
36+
},
37+
"language": {
38+
"description": "The language of the document.",
39+
"type": "string"
40+
},
41+
"paper": {
42+
"description": "The paper size of the document.",
43+
"type": "string"
44+
},
45+
"flipped": {
46+
"description": "Whether the document's page is flipped.",
47+
"type": "boolean"
48+
},
49+
"justified": {
50+
"description": "Whether the document's text is justified.",
51+
"type": "boolean"
52+
},
53+
"indentation": {
54+
"description": "Optional indentation for paragraphs in the document.",
55+
"type": "object",
56+
"properties": {
57+
"unit": {
58+
"type": "string"
59+
},
60+
"value": {
61+
"type": "string"
62+
}
63+
},
64+
"additionalProperties": false
6965
},
70-
{
71-
"type": "null"
66+
"columns": {
67+
"description": "The amount of columns in the document.",
68+
"type": "number"
69+
},
70+
"functions": {
71+
"description": "Additional TyX function definitions.",
72+
"type": "object",
73+
"propertyNames": {
74+
"type": "string"
75+
},
76+
"additionalProperties": {
77+
"type": "object",
78+
"properties": {
79+
"positional": {
80+
"type": "array",
81+
"items": {
82+
"type": "object",
83+
"properties": {
84+
"type": {
85+
"description": "The TyX type of this parameter.",
86+
"type": "string"
87+
},
88+
"required": {
89+
"description": "Whether this parameter is required.",
90+
"type": "boolean"
91+
},
92+
"label": {
93+
"description": "Optional label (usually name) of this parameter.",
94+
"type": "string"
95+
},
96+
"documentation": {
97+
"description": "Optional documentation for this parameter to show on hover.",
98+
"type": "string"
99+
}
100+
},
101+
"required": [
102+
"type"
103+
],
104+
"additionalProperties": false
105+
}
106+
},
107+
"named": {
108+
"type": "array",
109+
"items": {
110+
"type": "object",
111+
"properties": {
112+
"type": {
113+
"description": "The TyX type of this parameter.",
114+
"type": "string"
115+
},
116+
"required": {
117+
"description": "Whether this parameter is required.",
118+
"type": "boolean"
119+
},
120+
"label": {
121+
"description": "Optional label (usually name) of this parameter.",
122+
"type": "string"
123+
},
124+
"documentation": {
125+
"description": "Optional documentation for this parameter to show on hover.",
126+
"type": "string"
127+
},
128+
"name": {
129+
"type": "string"
130+
}
131+
},
132+
"required": [
133+
"type",
134+
"name"
135+
],
136+
"additionalProperties": false
137+
}
138+
}
139+
},
140+
"additionalProperties": false
141+
}
72142
}
73-
]
74-
},
75-
"format": {
76-
"$ref": "#/definitions/ElementFormatType"
77143
},
78-
"indent": {
79-
"type": "number"
80-
},
81-
"textFormat": {
82-
"type": "number"
83-
},
84-
"textStyle": {
85-
"type": "string"
86-
}
87-
},
88-
"type": "object"
89-
}
90-
]
91-
},
92-
"TyXDocumentSettings": {
93-
"description": "An object wrapping some common Typst document configuration options.",
94-
"properties": {
95-
"columns": {
96-
"description": "The amount of columns in the document.",
97-
"type": "number"
98-
},
99-
"flipped": {
100-
"description": "Whether the document's page is flipped.",
101-
"type": "boolean"
102-
},
103-
"fontPaths": {
104-
"items": {
105-
"type": "string"
106-
},
107-
"type": "array"
108-
},
109-
"indentation": {
110-
"$ref": "#/definitions/TyXLength",
111-
"description": "Optional indentation for paragraphs in the document."
112-
},
113-
"justified": {
114-
"description": "Whether the document's text is justified.",
115-
"type": "boolean"
116-
},
117-
"language": {
118-
"description": "The language of the document.",
119-
"type": "string"
120-
},
121-
"paper": {
122-
"description": "The paper size of the document.",
123-
"type": "string"
124-
},
125-
"root": {
126-
"type": "string"
144+
"additionalProperties": false
127145
}
128-
},
129-
"type": "object"
130-
},
131-
"TyXLength": {
132-
"description": "An object representing Typst `relative` or `fraction` types.",
133-
"properties": {
134-
"unit": {
135-
"type": "string"
136-
},
137-
"value": {
138-
"type": "string"
139-
}
140-
},
141-
"type": "object"
142-
}
143-
},
144-
"description": "An object representing an entire TyX document. Saved in `.tyx` files.",
145-
"properties": {
146-
"content": {
147-
"$ref": "#/definitions/SerializedEditorState<SerializedLexicalNode>",
148-
"description": "The serialized content of the editor."
149-
},
150-
"dirty": {
151-
"description": "Whether the document has been modified since loading, unused.",
152-
"type": "boolean"
153-
},
154-
"filename": {
155-
"description": "The filename of the document, unused.",
156-
"type": "string"
157-
},
158-
"preamble": {
159-
"description": "Raw Typst code to insert before the content.",
160-
"type": "string"
161-
},
162-
"settings": {
163-
"$ref": "#/definitions/TyXDocumentSettings",
164-
"description": "The document's settings."
165146
},
166-
"version": {
167-
"description": "The version of TyX in which the document was created.",
168-
"type": "string"
169-
}
170-
},
171-
"type": "object"
172-
}
147+
"required": [
148+
"version"
149+
],
150+
"additionalProperties": false
151+
}

0 commit comments

Comments
 (0)