grapes-vue-lite 0.1.0 → 0.1.2

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
@@ -50,7 +50,22 @@ import { GrapesVueEditor, type EditorContext, type EditorOptions } from "grapes-
50
50
  import "grapes-vue-lite/style.css";
51
51
 
52
52
  const options: EditorOptions = {
53
+ locale: "en",
54
+ theme: {
55
+ name: "light",
56
+ themes: {
57
+ brand: {
58
+ colorPrimary: "#0f766e",
59
+ colorSurface: "#ffffff",
60
+ },
61
+ },
62
+ },
53
63
  selectors: [{ name: "primary-button", label: "Primary button" }],
64
+ messages: {
65
+ "zh-CN": {
66
+ "app.title": "页面编辑器",
67
+ },
68
+ },
54
69
  storage: {
55
70
  localKey: "host-app-builder",
56
71
  },
@@ -87,14 +102,36 @@ function handleChange(projectJson: string) {
87
102
 
88
103
  The package treats `vue` as a peer dependency, so the host application owns the Vue runtime version.
89
104
 
105
+ The editor fills its parent container by default. When embedding it in a dialog, drawer, tab pane, or any constrained area, set the host container height explicitly:
106
+
107
+ ```vue
108
+ <template>
109
+ <div class="builder-host">
110
+ <GrapesVueEditor :options="options" />
111
+ </div>
112
+ </template>
113
+
114
+ <style scoped>
115
+ .builder-host {
116
+ height: 520px;
117
+ min-height: 0;
118
+ }
119
+ </style>
120
+ ```
121
+
122
+ For full-screen usage, set the host container to `100dvh`. The library stylesheet avoids forcing `body`, `html`, or `#app` height so it does not override the host application's page layout.
123
+
90
124
  ## Current Editor Modules
91
125
 
92
126
  - `Blocks`: block registry and categories.
93
- - `Components`: component type registry, node creation, and style constraints.
127
+ - `Components`: component type registry, node creation, style constraints, and programmatic component tree insertion through the editor context.
94
128
  - `Traits`: common and component-specific attributes.
95
129
  - `Styles`: style sectors and style properties.
96
130
  - `Selectors`: project-level class registry and class assignment.
97
131
  - `CssRules`: class selector style rules with state, component-first scope, and device overrides.
132
+ - `Parser`: HTML fragment import that maps supported tags into editable component nodes.
133
+ - `I18n`: English and Simplified Chinese UI messages with English as the default locale.
134
+ - `Theme`: light/dark editor UI themes and host-provided design tokens.
98
135
  - `Assets`: image asset registry and image assignment.
99
136
  - `Storage`: local and custom storage adapters.
100
137
  - `Commands`: command registry and shortcuts.
@@ -114,6 +151,7 @@ The editor supports both node-level styles and class selector rules.
114
151
 
115
152
  Toolbar export options:
116
153
 
154
+ - `Import HTML`: paste supported HTML and replace the current page contents with editable nodes.
117
155
  - `View HTML`: single HTML document with CSS embedded in `<style>`.
118
156
  - `View Linked HTML`: HTML document that references `grapes-vue-lite-styles.css`.
119
157
  - `View CSS`: current page CSS.
@@ -134,6 +172,32 @@ Toolbar export options:
134
172
 
135
173
  Deleting a project class removes it from the registry, all page nodes, and its CSS rule.
136
174
 
175
+ ## Programmatic Component Workflow
176
+
177
+ Plugins and host applications can create component nodes directly and insert them without wrapping every operation as a block:
178
+
179
+ ```ts
180
+ const hero = editor.Components.createNode("section", {
181
+ name: "API Hero",
182
+ droppable: true,
183
+ style: { padding: "64px", background: "#ffffff" },
184
+ });
185
+
186
+ const title = editor.Components.createNode("heading", {
187
+ text: "Created by a plugin",
188
+ });
189
+
190
+ editor.addNodeToRoot(hero);
191
+ editor.addNodeToNode(title, hero.id);
192
+ ```
193
+
194
+ Available component tree helpers:
195
+
196
+ - `addNodeToRoot(node)`: append a component to the active page root.
197
+ - `addNodeToNode(node, targetNodeId)`: append a component to a droppable target.
198
+ - `insertNodeNearNode(node, targetNodeId, "before" | "after")`: insert a component as a sibling.
199
+ - `deleteNode(id)`: remove a component and return whether deletion happened.
200
+
137
201
  ## Tests
138
202
 
139
203
  `test/exporter-smoke-test.ts` directly imports the exporter module and verifies: