@wireweave/language-data 1.5.3-beta.0 → 1.6.0-beta.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/README.md CHANGED
@@ -1,29 +1,29 @@
1
- <p align="center">
2
- <img src="https://docs.wireweave.org/assets/wireweave-language-data.svg" width="128" height="128" alt="Wireweave Language Data">
3
- </p>
1
+ # @wireweave/language-data
4
2
 
5
- <h1 align="center">@wireweave/language-data</h1>
3
+ Component and attribute vocabulary for the Wireweave DSL, for editor autocomplete, validation, and tooling.
6
4
 
7
- <p align="center">Shared language definitions and editor integrations for Wireweave DSL</p>
5
+ ## What it does
8
6
 
9
- ## Installation
7
+ `@wireweave/language-data` exposes the Wireweave DSL vocabulary — every component, its allowed attributes, valid children, categories, and value keywords — as plain data plus lookup helpers. It powers autocomplete, hover docs, and validation hints in editor integrations.
10
8
 
11
- ```bash
12
- npm install @wireweave/language-data
13
- # or
14
- pnpm add @wireweave/language-data
15
- ```
9
+ The vocabulary itself is **derived from `@wireweave/core/spec`**, which derives the element set from the grammar. This package declares no component or attribute of its own; it adds only editor metadata on top — an example snippet, a category label, a completion detail string. A name reaches an editor by being added to the spec, never here, so autocomplete cannot drift from what the parser accepts. The only exceptions are quarantined in `src/core-spec-gaps.ts`, which documents each one and is tested to stay disjoint from the spec.
16
10
 
17
- ## Features
11
+ Runtime output depends on the `./spec` subpath only, so no parser or renderer code reaches a bundle. The tests reach further, into core as a whole: `./spec` is a copy of what the grammar, AST types, and renderer actually do, and checking a copy against itself proves nothing. Runtime dependency and test oracle are separate axes, and the oracle is the wider of the two by design.
18
12
 
19
- - **Language Data** - Component and attribute definitions
20
- - **Monaco Integration** - Full IntelliSense for Monaco Editor
21
- - **CodeMirror Integration** - Full IntelliSense for CodeMirror 6
22
- - **Zero Dependencies** - Standalone package
13
+ Optional subpath entries provide ready-made editor integrations:
23
14
 
24
- ## Usage
15
+ - `@wireweave/language-data/monaco` — register the Wireweave language with Monaco Editor.
16
+ - `@wireweave/language-data/codemirror` — tokenizer, completion, hover, and linting sources for CodeMirror 6.
17
+
18
+ The editor adapters rely on optional peer dependencies (`monaco-editor`, `@codemirror/*`) — install only the ones for the integration you use.
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm i @wireweave/language-data
24
+ ```
25
25
 
26
- ### Basic Data
26
+ ## Usage
27
27
 
28
28
  ```typescript
29
29
  import {
@@ -33,150 +33,61 @@ import {
33
33
  getAttribute,
34
34
  getValidChildren,
35
35
  getComponentAttributes,
36
- } from '@wireweave/language-data';
36
+ isValidChild,
37
+ } from '@wireweave/language-data'
37
38
 
38
- // Get component definition
39
- const page = getComponent('page');
40
- console.log(page?.description);
39
+ // Component definition
40
+ const card = getComponent('card')
41
+ console.log(card?.description)
41
42
 
42
- // Get attribute definition
43
- const gap = getAttribute('gap');
44
- console.log(gap?.type); // "number"
43
+ // Attributes allowed on a component
44
+ const cardAttrs = getComponentAttributes('card')
45
45
 
46
- // Get valid children for a component
47
- const children = getValidChildren('page');
48
- console.log(children.map(c => c.name));
46
+ // Validity checks for the editor
47
+ isValidChild('page', 'card') // true / false
48
+ getValidChildren('grid') // valid child component names
49
49
 
50
- // Get attributes for a component
51
- const attrs = getComponentAttributes('button');
52
- console.log(attrs.map(a => a.name));
50
+ // Full vocabulary
51
+ console.log(ALL_COMPONENTS.length, ATTRIBUTES.length)
53
52
  ```
54
53
 
55
- ### Monaco Editor Integration
54
+ ### Monaco integration
56
55
 
57
56
  ```typescript
58
- import * as monaco from 'monaco-editor';
59
- import {
60
- LANGUAGE_ID,
61
- getMonarchTokensProvider,
62
- getLanguageConfiguration,
63
- createHoverProvider,
64
- createCompletionProvider,
65
- createDiagnosticsSetup,
66
- } from '@wireweave/language-data/monaco';
67
-
68
- // Register language
69
- monaco.languages.register({ id: LANGUAGE_ID });
70
- monaco.languages.setMonarchTokensProvider(LANGUAGE_ID, getMonarchTokensProvider());
71
- monaco.languages.setLanguageConfiguration(LANGUAGE_ID, getLanguageConfiguration());
72
-
73
- // Register IntelliSense
74
- monaco.languages.registerHoverProvider(LANGUAGE_ID, createHoverProvider(monaco));
75
- monaco.languages.registerCompletionItemProvider(LANGUAGE_ID, createCompletionProvider(monaco));
76
-
77
- // Setup diagnostics
78
- const editor = monaco.editor.create(container, { language: LANGUAGE_ID });
79
- const setupDiagnostics = createDiagnosticsSetup(monaco);
80
- setupDiagnostics(editor);
57
+ import * as monaco from 'monaco-editor'
58
+ import { registerWireframeLanguage } from '@wireweave/language-data/monaco'
59
+
60
+ registerWireframeLanguage(monaco)
81
61
  ```
82
62
 
83
- ### CodeMirror Integration
63
+ ### CodeMirror 6 integration
84
64
 
85
65
  ```typescript
86
- import { StreamLanguage } from '@codemirror/language';
87
- import { autocompletion } from '@codemirror/autocomplete';
88
- import { hoverTooltip } from '@codemirror/view';
89
- import { linter } from '@codemirror/lint';
90
66
  import {
91
67
  createTokenizer,
68
+ getLanguageConfig,
92
69
  createCompletionSource,
93
70
  createHoverTooltipSource,
94
71
  createLinter,
95
- } from '@wireweave/language-data/codemirror';
96
-
97
- // Create language
98
- const wireframeLanguage = StreamLanguage.define(createTokenizer());
99
-
100
- // Setup extensions
101
- const extensions = [
102
- wireframeLanguage,
103
- autocompletion({ override: [createCompletionSource()] }),
104
- hoverTooltip(createHoverTooltipSource()),
105
- linter(createLinter()),
106
- ];
107
- ```
108
-
109
- ## Exports
110
-
111
- ### Main (`@wireweave/language-data`)
112
-
113
- | Export | Description |
114
- |--------|-------------|
115
- | `ALL_COMPONENTS` | Array of ~40 component definitions |
116
- | `ATTRIBUTES` | Array of ~60 attribute definitions |
117
- | `VALUE_KEYWORDS` | Array of valid value keywords |
118
- | `CATEGORY_LABELS` | Category name to label mapping |
119
- | `getComponent(name)` | Get component by name |
120
- | `getAttribute(name)` | Get attribute by name |
121
- | `getValidChildren(name)` | Get valid child components |
122
- | `getComponentAttributes(name)` | Get attributes for component |
123
- | `isComponent(word)` | Check if word is a component |
124
- | `isAttribute(word)` | Check if word is an attribute |
125
-
126
- ### Monaco (`@wireweave/language-data/monaco`)
127
-
128
- | Export | Description |
129
- |--------|-------------|
130
- | `LANGUAGE_ID` | Language identifier (`"wireframe"`) |
131
- | `getMonarchTokensProvider()` | Monarch tokenizer for syntax highlighting |
132
- | `getLanguageConfiguration()` | Brackets, comments, auto-closing |
133
- | `createHoverProvider(monaco)` | Hover tooltip provider |
134
- | `createCompletionProvider(monaco)` | Auto-completion provider |
135
- | `createDiagnosticsSetup(monaco)` | Diagnostics/linting setup |
136
-
137
- ### CodeMirror (`@wireweave/language-data/codemirror`)
138
-
139
- | Export | Description |
140
- |--------|-------------|
141
- | `createTokenizer()` | StreamLanguage tokenizer |
142
- | `createCompletionSource()` | Auto-completion source |
143
- | `createHoverTooltipSource()` | Hover tooltip source |
144
- | `createLinter()` | Linter for diagnostics |
145
-
146
- ## Types
147
-
148
- ```typescript
149
- interface ComponentDef {
150
- name: string;
151
- nodeType: string;
152
- category: ComponentCategory;
153
- attributes: string[];
154
- hasChildren: boolean;
155
- description: string;
156
- example: string;
157
- validChildren?: string[];
158
- validParents?: string[];
159
- }
160
-
161
- interface AttributeDef {
162
- name: string;
163
- type: 'string' | 'number' | 'boolean' | 'enum';
164
- values?: string[];
165
- description: string;
166
- example: string;
167
- }
168
-
169
- type ComponentCategory =
170
- | 'layout' | 'container' | 'grid' | 'text'
171
- | 'input' | 'display' | 'data' | 'feedback'
172
- | 'overlay' | 'navigation';
72
+ } from '@wireweave/language-data/codemirror'
173
73
  ```
174
74
 
175
- ## Used By
176
-
177
- - **[@wireweave/playground](https://github.com/wireweave/playground)** - Monaco Editor integration
178
- - **[wireweave-vscode](https://github.com/wireweave/vscode-extension)** - VS Code extension
179
- - **[dashboard](https://wireweave.org)** - CodeMirror integration
75
+ ## Main API
76
+
77
+ | Export | Description |
78
+ | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
79
+ | `ALL_COMPONENTS`, `COMPONENT_MAP`, `NODE_TYPE_MAP`, `VALID_COMPONENT_NAMES` | Component definitions and lookup maps. |
80
+ | `ATTRIBUTES`, `ATTRIBUTE_MAP`, `COMMON_ATTRIBUTES`, `VALID_ATTRIBUTE_NAMES` | Attribute definitions and lookup maps. |
81
+ | `CATEGORY_LABELS`, `VALUE_KEYWORDS`, `COMMON_NUMBERS`, `SPACING_SCALE` | Categories, value keywords, and numeric scales for completion. |
82
+ | `getComponent`, `getComponentByNodeType`, `getComponentAttributes`, `getComponentsByCategory` | Component lookups. |
83
+ | `getAttribute`, `getAttributeTypeLabel`, `formatAttributeValues` | Attribute lookups and formatting. |
84
+ | `getValidChildren`, `isValidChild` | Containment rules for validation. |
85
+ | `isComponent`, `isAttribute`, `getComponentNames`, `getAttributeNames`, `getCategories` | Membership checks and name listings. |
86
+ | `ComponentDef`, `AttributeDef`, `ComponentCategory`, `AttributeValueType` | Type definitions. |
87
+ | `registerWireframeLanguage` (`/monaco`) | Register the language with Monaco Editor. |
88
+ | `createTokenizer`, `getLanguageConfig`, `createCompletionSource`, `createHoverTooltipSource`, `createLinter`, `validateCode` (`/codemirror`) | CodeMirror 6 language sources. |
89
+
90
+ Part of the [Wireweave monorepo](https://github.com/wireweave/wireweave).
180
91
 
181
92
  ## License
182
93