tiptap-model-language 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wexio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # tiptap-model-language
2
+
3
+ > Type-safe template authoring inside your Tiptap editor. Variables, conditions,
4
+ > loops and filters with live validation, quick-fixes and staged autocomplete.
5
+
6
+ [![npm](https://img.shields.io/npm/v/tiptap-model-language?label=npm&color=cb3837&logo=npm)](https://www.npmjs.com/package/tiptap-model-language)
7
+ [![CI](https://github.com/wexiohub/tiptap-model-language/actions/workflows/ci.yml/badge.svg)](https://github.com/wexiohub/tiptap-model-language/actions/workflows/ci.yml)
8
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/tiptap-model-language?label=bundle%20size)](https://bundlephobia.com/package/tiptap-model-language)
9
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
10
+ [![powered by wexio.io](https://img.shields.io/badge/powered%20by-wexio.io-0b0b0b)](https://wexio.io)
11
+
12
+ A [Tiptap](https://tiptap.dev) / [ProseMirror](https://prosemirror.net) extension
13
+ for the [`model-language`](https://www.npmjs.com/package/model-language) template
14
+ syntax. Writers get VS Code-style feedback while they type: `{{…}}` syntax
15
+ highlighting, staged type-aware autocomplete (variables, filters, control
16
+ blocks), hover diagnostics with one-click quick-fixes, and live validation that
17
+ runs fully in-process, with no server round-trip.
18
+
19
+ **Live demo and docs:** [ml.wexio.io](https://ml.wexio.io)
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install tiptap-model-language @tiptap/react @tiptap/starter-kit
25
+ ```
26
+
27
+ The `model-language` engine ships inside the package, so there is nothing else to
28
+ add. `react`, `react-dom` and the `@tiptap/*` packages are peer dependencies you
29
+ already have in a Tiptap app.
30
+
31
+ ## Quick start
32
+
33
+ Add `ModelSyntax` to any Tiptap editor and hand it a set of namespaces (for
34
+ autocomplete) and a field schema (for validation).
35
+
36
+ ```tsx
37
+ import { EditorContent, useEditor } from "@tiptap/react";
38
+ import StarterKit from "@tiptap/starter-kit";
39
+ import { ModelSyntax } from "tiptap-model-language";
40
+
41
+ const namespaces = [
42
+ { key: "contact", label: "Contact", fields: [
43
+ { key: "first_name", type: "string", label: "First name" },
44
+ { key: "priority", type: "enum", label: "Priority",
45
+ values: ["high", "low"] },
46
+ ]},
47
+ ];
48
+
49
+ const schema = [
50
+ { path: "contact.first_name", type: "string", nullable: true },
51
+ { path: "contact.priority", type: "enum", values: ["high", "low"] },
52
+ ];
53
+
54
+ export function TemplateEditor() {
55
+ const editor = useEditor({
56
+ extensions: [
57
+ StarterKit,
58
+ ModelSyntax.configure({
59
+ namespaces,
60
+ schema,
61
+ onResult: (r) => console.log(r.diagnostics, r.maxTokenEstimate),
62
+ }),
63
+ ],
64
+ });
65
+
66
+ return <EditorContent editor={editor} />;
67
+ }
68
+ ```
69
+
70
+ When the schema loads asynchronously or changes at runtime, push it in with the
71
+ `setModelData` command instead of the static options; it re-validates the
72
+ document right away.
73
+
74
+ ```ts
75
+ editor.commands.setModelData({ namespaces, schema });
76
+ ```
77
+
78
+ ## What you get
79
+
80
+ - **Syntax highlighting** for raw-text `{{…}}` tokens: braces, keywords,
81
+ variables, operators, strings, numbers and filter pipelines, each in its own
82
+ colour, even when a tag wraps across a line break.
83
+ - **Staged autocomplete** triggered by `{{`: field, then operator, then value.
84
+ Enums list their options, array operators build a `["a", "b"]` list, dates
85
+ offer format presets with a live preview, timezones come from a dropdown.
86
+ - **Local validation** on every keystroke via the `model-language` `validate()`
87
+ engine: unknown fields, missing defaults, unbalanced blocks, mistyped
88
+ operators. Zero round-trips.
89
+ - **Hover diagnostics + quick-fixes**: hover a squiggle for the message and a
90
+ one-click fix (add a type-aware default, insert the missing `{{/if}}` in the
91
+ right scope, correct a mistyped operator).
92
+ - **Localizable**: every user-facing string is overridable, and engine
93
+ diagnostics translate by their stable code.
94
+
95
+ ## Options
96
+
97
+ Pass any of these to `ModelSyntax.configure({…})`. Only `namespaces` and `schema`
98
+ are usually needed.
99
+
100
+ | Option | Type | Default | Description |
101
+ |---|---|---|---|
102
+ | `namespaces` | `MlNamespace[]` | `[]` | Autocomplete + highlighting groups. Static case; push via `setModelData` for async data. |
103
+ | `schema` | `FieldSchema` | `[]` | Flattened field schema for local validation. Static case. |
104
+ | `skipValidation` | `boolean` | `false` | Turn off the `validate()` pass. Structural squiggles still render. |
105
+ | `debounceMs` | `number` | `300` | Debounce for the validation pass. |
106
+ | `severities` | `DiagnosticSeverity[]` | all | Which severities render inline. |
107
+ | `labels` | `Partial<ModelLanguageLabels>` | `{}` | Override any user-facing string. |
108
+ | `translateDiagnostic` | `(d) => string \| undefined` | `undefined` | Localize an engine diagnostic by its stable code. |
109
+ | `onResult` | `(result) => void` | `undefined` | Full result hook (diagnostics + token estimate). |
110
+
111
+ Full reference: [ml.wexio.io/docs](https://ml.wexio.io/docs).
112
+
113
+ ## The engine, re-exported
114
+
115
+ The `model-language` engine is re-exported from this package, so you can validate
116
+ and render templates with the exact engine the editor uses, no extra install.
117
+
118
+ ```ts
119
+ import { parse, render, validate } from "tiptap-model-language";
120
+
121
+ const { diagnostics, maxTokenEstimate } = validate(template, schema);
122
+
123
+ const { ast } = parse(template);
124
+ const { text } = render(ast, snapshot, schema, { now: new Date() });
125
+ ```
126
+
127
+ ## Development
128
+
129
+ ```bash
130
+ pnpm install
131
+ pnpm test # vitest (unit)
132
+ pnpm test:cov # vitest + coverage
133
+ pnpm lint # Biome
134
+ pnpm typecheck # tsc --noEmit
135
+ pnpm build # tsup -> dist (ESM + CJS + .d.ts)
136
+ ```
137
+
138
+ The landing page and end-to-end (Playwright) suite live in the separate
139
+ [demo repository](https://ml.wexio.io).
140
+
141
+ ## License
142
+
143
+ MIT (c) [Wexio](https://wexio.io)
144
+
145
+ ---
146
+
147
+ <p align="center">Built and maintained by <a href="https://wexio.io"><b>Wexio</b></a>, wexio.io</p>