@yoyaflow/yoya-ui 0.3.0 → 0.3.1

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
@@ -58,6 +58,8 @@ npm run dev # basic / admin: dev server
58
58
 
59
59
  `--template admin` scaffolds a standard admin console: top navigation, collapsible sidebar and a titled RouterViews content area, with feature examples for dashboard (data boards & charts), member / role / permission management, and dictionary management (type table with an item editor dialog).
60
60
 
61
+ yoya-ui has its own unique development paradigm — declarative node DSL, page composition, and feature-module organization. The admin template is the recommended way to get familiar with it: it demonstrates the full stack of a real admin console (shell, routing, tables / forms / dialogs, dashboard boards & charts) using the library's idiomatic patterns.
62
+
61
63
  ### Install into an existing project
62
64
 
63
65
  ```bash
@@ -82,24 +84,42 @@ The page only needs a `<div id="app"></div>` loaded with a module script.
82
84
 
83
85
  ## Server-Side Rendering (SSR)
84
86
 
85
- The same page factory switches between server rendering and client rendering:
87
+ The same page factory switches between server rendering and client rendering. For a full page, use the high-level entry points — `renderPage` builds a complete HTML document (head/body in DSL) and `hydrateOrMount` bootstraps the client in one call:
86
88
 
87
89
  ```js
88
- // Server
89
- import { renderToString } from '@yoyaflow/yoya-ui/ssr';
90
- const { html, state } = renderToString(createPage, { state: { path: '/home' } });
91
-
92
- // Client
93
- import { hydrate, mount, parseState } from '@yoyaflow/yoya-ui/ssr';
94
- const data = parseState(document.getElementById('__YOYA_DATA__').textContent);
95
- const app = document.getElementById('app');
96
- if (app.firstElementChild) {
97
- hydrate(createPage, app, data); // Server HTML exists: adopt DOM, bind events
98
- } else {
99
- mount(createPage, app, data); // Empty shell: full client render
100
- }
90
+ // Server — render a complete HTML document per request
91
+ import { renderPage } from '@yoyaflow/yoya-ui/ssr';
92
+ import { HomePage, messages } from './home-page.js';
93
+
94
+ const html = renderPage(
95
+ {
96
+ page: (page, state) => {
97
+ page.head((head) => {
98
+ head.title('SSR Example'.s('title'));
99
+ head.meta({ charset: 'utf-8' });
100
+ head.link({ rel: 'stylesheet', href: '/assets/yoya.ui.css' });
101
+ });
102
+ page.body((body) => {
103
+ body.vBody((shell) => {
104
+ shell.child(HomePage(state)); // state = { lang, path, mode }
105
+ });
106
+ });
107
+ }
108
+ },
109
+ { lang, mode: 'history', path },
110
+ { messages } // per-request i18n; .s() is scoped automatically
111
+ );
112
+
113
+ // Client — reads __YOYA_DATA__; hydrates when server HTML exists, otherwise mounts
114
+ import '@yoyaflow/yoya-ui/ui.css';
115
+ import { hydrateOrMount } from '@yoyaflow/yoya-ui/ssr';
116
+ import { HomePage, messages } from './home-page.js';
117
+
118
+ hydrateOrMount(HomePage, { messages });
101
119
  ```
102
120
 
121
+ Lower-level primitives (`renderToString` / `serializeState` / `parseState` / `mount` / `hydrate`) remain available for fine-grained control, e.g. embedding an HTML fragment into your own server template.
122
+
103
123
  Key points:
104
124
 
105
125
  - `vClientOnly(loader)`: non-SSR modules (e.g. ECharts) emit a placeholder on the server and load on the client after hydration
@@ -107,7 +127,16 @@ Key points:
107
127
  - Per-request i18n instance, render-context id allocator, auto-destroy after render — the server stays stateless
108
128
  - `maxNodes` falls back to client rendering automatically when exceeded
109
129
 
110
- Full integration guide: [docs/ssr.md](docs/ssr.md) (Chinese); runnable example:
130
+ Full integration guide: [docs/ssr.md](docs/ssr.md) (Chinese); quick start with the SSR template:
131
+
132
+ ```bash
133
+ npx create-yoya-ui@latest my-app --template ssr
134
+ cd my-app
135
+ npm install
136
+ npm run build && npm start
137
+ ```
138
+
139
+ Or run the in-repo example:
111
140
 
112
141
  ```bash
113
142
  npm run build
@@ -120,7 +149,7 @@ node src/examples/ssr/server-http.mjs
120
149
  import { div, svg, createI18n } from '@yoyaflow/yoya-ui/core'; // core HTML/SVG/state
121
150
  import { vButton, vCard, vForm, vTable } from '@yoyaflow/yoya-ui/ui'; // official component library
122
151
  import { vEchart } from '@yoyaflow/yoya-ui/echart'; // ECharts component (bring your own echarts)
123
- import { renderToString, hydrate } from '@yoyaflow/yoya-ui/ssr'; // server-side rendering
152
+ import { renderPage, hydrateOrMount } from '@yoyaflow/yoya-ui/ssr'; // server-side rendering
124
153
  import '@yoyaflow/yoya-ui/ui.css'; // default styles and theme variables
125
154
  ```
126
155
 
@@ -133,7 +162,7 @@ TypeScript projects get hints and type checking with no extra configuration:
133
162
  ```ts
134
163
  import { div, vButton, vCard, vTable, toast } from '@yoyaflow/yoya-ui';
135
164
  import { createI18n } from '@yoyaflow/yoya-ui/core';
136
- import { renderToString } from '@yoyaflow/yoya-ui/ssr';
165
+ import { renderPage } from '@yoyaflow/yoya-ui/ssr';
137
166
  import '@yoyaflow/yoya-ui/ui.css';
138
167
 
139
168
  div((page) => {
@@ -189,7 +218,7 @@ npm run build
189
218
 
190
219
  - `yoya.core.js` / `yoya.ui.js` — core and component library ESM entries
191
220
  - `yoya.echart.js` — ECharts component entry (does not bundle echarts itself)
192
- - `yoya.ssr.js` — server rendering entry (`renderToString` / `hydrate` / `mount`)
221
+ - `yoya.ssr.js` — server rendering entry (`renderPage` / `hydrateOrMount` / `renderToString` / `hydrate` / `mount`)
193
222
  - `echarts.min.js` — ECharts core (load globally via `<script>`)
194
223
  - `yoya.ui.css` — default styles and theme variables
195
224
  - `yoya-ui.umd.js` — UMD build (`window.YoyaUI`)
package/README.zh-CN.md CHANGED
@@ -59,6 +59,8 @@ npm run dev # basic / admin:开发服务器
59
59
 
60
60
  `--template admin` 生成标准后台管理模板:顶部导航 + 可折叠侧栏 + 带标题的 RouterViews 内容区,内置数据概览看板与图表,以及成员 / 角色 / 权限 / 字典管理等业务域示例。
61
61
 
62
+ yoya-ui 拥有自己独特的开发范式:声明式节点 DSL、页面编排与 feature 模块组织。推荐使用 admin 模板创建项目来了解这些范式——它用库的原生写法完整展示了一个真实后台(页面壳、路由、表格/表单/弹窗、数据看板与图表)。
63
+
62
64
  ### 已有项目引入
63
65
 
64
66
  ```bash
@@ -83,24 +85,42 @@ div((page) => {
83
85
 
84
86
  ## 服务端渲染(SSR)
85
87
 
86
- 同一份页面工厂代码,服务端渲染与客户端渲染可切换:
88
+ 同一份页面工厂代码,服务端渲染与客户端渲染可切换。整页场景直接使用高层入口:`renderPage` 输出完整 HTML 文档(head/body 用 DSL 定义),`hydrateOrMount` 一行完成客户端接入:
87
89
 
88
90
  ```js
89
- // 服务端
90
- import { renderToString } from '@yoyaflow/yoya-ui/ssr';
91
- const { html, state } = renderToString(createPage, { state: { path: '/home' } });
92
-
93
- // 客户端
94
- import { hydrate, mount, parseState } from '@yoyaflow/yoya-ui/ssr';
95
- const data = parseState(document.getElementById('__YOYA_DATA__').textContent);
96
- const app = document.getElementById('app');
97
- if (app.firstElementChild) {
98
- hydrate(createPage, app, data); // 有服务端 HTML:收养 DOM、绑定事件
99
- } else {
100
- mount(createPage, app, data); // 空壳:全量客户端渲染
101
- }
91
+ // 服务端:按请求渲染完整 HTML 文档
92
+ import { renderPage } from '@yoyaflow/yoya-ui/ssr';
93
+ import { HomePage, messages } from './home-page.js';
94
+
95
+ const html = renderPage(
96
+ {
97
+ page: (page, state) => {
98
+ page.head((head) => {
99
+ head.title('SSR 示例'.s('title'));
100
+ head.meta({ charset: 'utf-8' });
101
+ head.link({ rel: 'stylesheet', href: '/assets/yoya.ui.css' });
102
+ });
103
+ page.body((body) => {
104
+ body.vBody((shell) => {
105
+ shell.child(HomePage(state)); // state = { lang, path, mode }
106
+ });
107
+ });
108
+ }
109
+ },
110
+ { lang, mode: 'history', path },
111
+ { messages } // 每请求 i18n,.s() 自动作用域
112
+ );
113
+
114
+ // 客户端:自动读取 __YOYA_DATA__,有服务端 HTML 走 hydrate,否则 mount
115
+ import '@yoyaflow/yoya-ui/ui.css';
116
+ import { hydrateOrMount } from '@yoyaflow/yoya-ui/ssr';
117
+ import { HomePage, messages } from './home-page.js';
118
+
119
+ hydrateOrMount(HomePage, { messages });
102
120
  ```
103
121
 
122
+ 底层原语(`renderToString` / `serializeState` / `parseState` / `mount` / `hydrate`)仍然可用,适合需要细粒度控制的场景,例如把 HTML 片段嵌入自有服务端模板。
123
+
104
124
  要点:
105
125
 
106
126
  - `vClientOnly(loader)`:非 SSR 模块(如 ECharts)服务端只出占位,hydration 后客户端加载
@@ -108,7 +128,16 @@ if (app.firstElementChild) {
108
128
  - 每请求 i18n 实例、渲染上下文 id 分配器、渲染后自动销毁——服务端保持无状态
109
129
  - `maxNodes` 超限自动回退客户端渲染
110
130
 
111
- 完整集成指南见 [docs/ssr.md](docs/ssr.md);可运行示例:
131
+ 完整集成指南见 [docs/ssr.md](docs/ssr.md);用 SSR 模板快速开始:
132
+
133
+ ```bash
134
+ npx create-yoya-ui@latest my-app --template ssr
135
+ cd my-app
136
+ npm install
137
+ npm run build && npm start
138
+ ```
139
+
140
+ 或运行仓库内示例:
112
141
 
113
142
  ```bash
114
143
  npm run build
@@ -121,7 +150,7 @@ node src/examples/ssr/server-http.mjs
121
150
  import { div, svg, createI18n } from '@yoyaflow/yoya-ui/core'; // 核心 HTML/SVG/状态
122
151
  import { vButton, vCard, vForm, vTable } from '@yoyaflow/yoya-ui/ui'; // 官方组件库
123
152
  import { vEchart } from '@yoyaflow/yoya-ui/echart'; // ECharts 组件(需自行引入 echarts)
124
- import { renderToString, hydrate } from '@yoyaflow/yoya-ui/ssr'; // 服务端渲染
153
+ import { renderPage, hydrateOrMount } from '@yoyaflow/yoya-ui/ssr'; // 服务端渲染
125
154
  import '@yoyaflow/yoya-ui/ui.css'; // 默认样式与主题变量
126
155
  ```
127
156
 
@@ -134,7 +163,7 @@ TypeScript 项目无需额外配置即可获得提示与类型检查:
134
163
  ```ts
135
164
  import { div, vButton, vCard, vTable, toast } from '@yoyaflow/yoya-ui';
136
165
  import { createI18n } from '@yoyaflow/yoya-ui/core';
137
- import { renderToString } from '@yoyaflow/yoya-ui/ssr';
166
+ import { renderPage } from '@yoyaflow/yoya-ui/ssr';
138
167
  import '@yoyaflow/yoya-ui/ui.css';
139
168
 
140
169
  div((page) => {
@@ -190,7 +219,7 @@ npm run build
190
219
 
191
220
  - `yoya.core.js` / `yoya.ui.js` — 核心与组件库 ESM 入口
192
221
  - `yoya.echart.js` — ECharts 组件入口(不包含 echarts 本体)
193
- - `yoya.ssr.js` — 服务端渲染入口(`renderToString` / `hydrate` / `mount`)
222
+ - `yoya.ssr.js` — 服务端渲染入口(`renderPage` / `hydrateOrMount` / `renderToString` / `hydrate` / `mount`)
194
223
  - `echarts.min.js` — ECharts 本体(用 `<script>` 标签全局引入)
195
224
  - `yoya.ui.css` — 默认样式与主题变量
196
225
  - `yoya-ui.umd.js` — UMD 版(`window.YoyaUI`)