@jay-framework/editor-protocol 0.6.9 → 0.7.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/dist/index.d.ts +4 -1
- package/dist/index.js +3 -2
- package/package.json +3 -3
- package/readme.md +73 -6
package/dist/index.d.ts
CHANGED
|
@@ -12,10 +12,12 @@ interface PublishMessage extends BaseMessage<PublishResponse> {
|
|
|
12
12
|
route: string;
|
|
13
13
|
jayHtml: string;
|
|
14
14
|
name: string;
|
|
15
|
+
contract?: string;
|
|
15
16
|
}[];
|
|
16
17
|
components?: {
|
|
17
18
|
jayHtml: string;
|
|
18
19
|
name: string;
|
|
20
|
+
contract?: string;
|
|
19
21
|
}[];
|
|
20
22
|
}
|
|
21
23
|
type PublishPage = PublishMessage['pages'][number];
|
|
@@ -34,6 +36,7 @@ interface PublishResponse extends BaseResponse {
|
|
|
34
36
|
status: {
|
|
35
37
|
success: boolean;
|
|
36
38
|
filePath?: string;
|
|
39
|
+
contractPath?: string;
|
|
37
40
|
error?: string;
|
|
38
41
|
}[];
|
|
39
42
|
}
|
|
@@ -87,7 +90,7 @@ interface PortDiscoveryResponse {
|
|
|
87
90
|
port: number;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
declare function createPublishMessage(pages
|
|
93
|
+
declare function createPublishMessage(pages?: PublishMessage['pages'], components?: PublishMessage['components']): PublishMessage;
|
|
91
94
|
declare function createSaveImageMessage(imageId: string, imageData: string): SaveImageMessage;
|
|
92
95
|
declare function createHasImageMessage(imageId: string): HasImageMessage;
|
|
93
96
|
declare function createPublishResponse(status: PublishResponse['status']): PublishResponse;
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/editor-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"test:watch": ":"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@jay-framework/dev-environment": "^0.
|
|
28
|
-
"@jay-framework/jay-cli": "^0.
|
|
27
|
+
"@jay-framework/dev-environment": "^0.7.0",
|
|
28
|
+
"@jay-framework/jay-cli": "^0.7.0",
|
|
29
29
|
"@types/node": "^22.15.21",
|
|
30
30
|
"rimraf": "^5.0.5",
|
|
31
31
|
"tsup": "^8.0.1",
|
package/readme.md
CHANGED
|
@@ -30,7 +30,15 @@ import {
|
|
|
30
30
|
|
|
31
31
|
// Use in editor applications
|
|
32
32
|
const editor: EditorProtocol = {
|
|
33
|
-
publish: async (params) => ({
|
|
33
|
+
publish: async (params) => ({
|
|
34
|
+
status: [
|
|
35
|
+
{
|
|
36
|
+
success: true,
|
|
37
|
+
filePath: '/test.jay-html',
|
|
38
|
+
contractPath: '/test.jay-contract', // Optional contract file path
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
}),
|
|
34
42
|
saveImage: async (params) => ({ success: true, imageUrl: '/assets/image.png' }),
|
|
35
43
|
hasImage: async (params) => ({ exists: true, imageUrl: '/assets/image.png' }),
|
|
36
44
|
};
|
|
@@ -43,10 +51,36 @@ const server: DevServerProtocol = {
|
|
|
43
51
|
};
|
|
44
52
|
|
|
45
53
|
// Create messages using constructors
|
|
46
|
-
const
|
|
54
|
+
const pages = [
|
|
47
55
|
{ route: '/home', jayHtml: '<div>Home</div>', name: 'Home' },
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
{
|
|
57
|
+
route: '/about',
|
|
58
|
+
jayHtml: '<div>{title}</div>',
|
|
59
|
+
name: 'About',
|
|
60
|
+
contract: `name: About
|
|
61
|
+
tags:
|
|
62
|
+
- tag: title
|
|
63
|
+
type: data
|
|
64
|
+
dataType: string
|
|
65
|
+
required: true`,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const components = [
|
|
70
|
+
{ jayHtml: '<button>Click me</button>', name: 'Button' },
|
|
71
|
+
{
|
|
72
|
+
jayHtml: '<div>{count}</div>',
|
|
73
|
+
name: 'Counter',
|
|
74
|
+
contract: `name: Counter
|
|
75
|
+
tags:
|
|
76
|
+
- tag: count
|
|
77
|
+
type: data
|
|
78
|
+
dataType: number
|
|
79
|
+
required: true`,
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const publishMessage = createPublishMessage(pages, components);
|
|
50
84
|
const protocolMessage = createProtocolMessage(publishMessage);
|
|
51
85
|
```
|
|
52
86
|
|
|
@@ -54,7 +88,7 @@ const protocolMessage = createProtocolMessage(publishMessage);
|
|
|
54
88
|
|
|
55
89
|
### Message Constructors
|
|
56
90
|
|
|
57
|
-
- `createPublishMessage(pages)` - Creates a publish message
|
|
91
|
+
- `createPublishMessage(pages?, components?)` - Creates a publish message with optional pages and components
|
|
58
92
|
- `createSaveImageMessage(imageId, imageData)` - Creates a save image message
|
|
59
93
|
- `createHasImageMessage(imageId)` - Creates a has image message
|
|
60
94
|
- `createProtocolMessage(payload)` - Creates a protocol message wrapper with auto-generated timestamp-based ID
|
|
@@ -70,7 +104,14 @@ const protocolMessage = createProtocolMessage(publishMessage);
|
|
|
70
104
|
|
|
71
105
|
### Publish
|
|
72
106
|
|
|
73
|
-
Publishes jay-html files to the dev server at specified routes.
|
|
107
|
+
Publishes jay-html files and optional jay-contract files to the dev server. Pages are published at specified routes, while components are published to the components directory.
|
|
108
|
+
|
|
109
|
+
**Features:**
|
|
110
|
+
|
|
111
|
+
- **Pages**: Published as `page.jay-html` and optional `page.jay-contract` files
|
|
112
|
+
- **Components**: Published as `{name}.jay-html` and optional `{name}.jay-contract` files
|
|
113
|
+
- **Contract Support**: Optional contract content for headless components
|
|
114
|
+
- **Backward Compatibility**: Contract publishing is optional and doesn't break existing workflows
|
|
74
115
|
|
|
75
116
|
### Save Image
|
|
76
117
|
|
|
@@ -79,3 +120,29 @@ Saves base64 image data to the dev server's public assets.
|
|
|
79
120
|
### Has Image
|
|
80
121
|
|
|
81
122
|
Checks if an image with the given ID already exists on the server.
|
|
123
|
+
|
|
124
|
+
## Contract Publishing
|
|
125
|
+
|
|
126
|
+
Contract files enable headless component support by defining the component's data interface and refs structure. When publishing components or pages, you can optionally include contract content:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// Publishing a headless component with contract
|
|
130
|
+
const component = {
|
|
131
|
+
jayHtml: '<div><span>{count}</span><button ref="increment">+</button></div>',
|
|
132
|
+
name: 'Counter',
|
|
133
|
+
contract: `name: Counter
|
|
134
|
+
tags:
|
|
135
|
+
- tag: count
|
|
136
|
+
type: data
|
|
137
|
+
dataType: number
|
|
138
|
+
required: true
|
|
139
|
+
- tag: increment
|
|
140
|
+
type: interactive
|
|
141
|
+
elementType: HTMLButtonElement
|
|
142
|
+
description: Button to increment the counter`,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const message = createPublishMessage(undefined, [component]);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The contract file will be saved alongside the jay-html file and can be referenced in other components using the `contract` attribute in jay-headless imports.
|