@yoyaflow/yoya-ui 0.2.1 → 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
@@ -44,6 +44,24 @@ function HelloWorldExampleI18n() {
44
44
 
45
45
  ## Installation
46
46
 
47
+ ### Scaffold a new project
48
+
49
+ ```bash
50
+ npx create-yoya-ui@latest my-app # basic template (SPA)
51
+ npx create-yoya-ui@latest my-app --template ssr # SSR template (renderPage + hydrateOrMount)
52
+ npx create-yoya-ui@latest my-app --template admin # admin console template (top nav + collapsible sidebar + RouterViews)
53
+ cd my-app
54
+ npm install
55
+ npm run dev # basic / admin: dev server
56
+ # SSR: npm run build && npm start
57
+ ```
58
+
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
+
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
+
63
+ ### Install into an existing project
64
+
47
65
  ```bash
48
66
  npm install @yoyaflow/yoya-ui
49
67
  ```
@@ -66,24 +84,42 @@ The page only needs a `<div id="app"></div>` loaded with a module script.
66
84
 
67
85
  ## Server-Side Rendering (SSR)
68
86
 
69
- 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:
70
88
 
71
89
  ```js
72
- // Server
73
- import { renderToString } from '@yoyaflow/yoya-ui/ssr';
74
- const { html, state } = renderToString(createPage, { state: { path: '/home' } });
75
-
76
- // Client
77
- import { hydrate, mount, parseState } from '@yoyaflow/yoya-ui/ssr';
78
- const data = parseState(document.getElementById('__YOYA_DATA__').textContent);
79
- const app = document.getElementById('app');
80
- if (app.firstElementChild) {
81
- hydrate(createPage, app, data); // Server HTML exists: adopt DOM, bind events
82
- } else {
83
- mount(createPage, app, data); // Empty shell: full client render
84
- }
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 });
85
119
  ```
86
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
+
87
123
  Key points:
88
124
 
89
125
  - `vClientOnly(loader)`: non-SSR modules (e.g. ECharts) emit a placeholder on the server and load on the client after hydration
@@ -91,7 +127,16 @@ Key points:
91
127
  - Per-request i18n instance, render-context id allocator, auto-destroy after render — the server stays stateless
92
128
  - `maxNodes` falls back to client rendering automatically when exceeded
93
129
 
94
- 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:
95
140
 
96
141
  ```bash
97
142
  npm run build
@@ -104,7 +149,7 @@ node src/examples/ssr/server-http.mjs
104
149
  import { div, svg, createI18n } from '@yoyaflow/yoya-ui/core'; // core HTML/SVG/state
105
150
  import { vButton, vCard, vForm, vTable } from '@yoyaflow/yoya-ui/ui'; // official component library
106
151
  import { vEchart } from '@yoyaflow/yoya-ui/echart'; // ECharts component (bring your own echarts)
107
- import { renderToString, hydrate } from '@yoyaflow/yoya-ui/ssr'; // server-side rendering
152
+ import { renderPage, hydrateOrMount } from '@yoyaflow/yoya-ui/ssr'; // server-side rendering
108
153
  import '@yoyaflow/yoya-ui/ui.css'; // default styles and theme variables
109
154
  ```
110
155
 
@@ -117,7 +162,7 @@ TypeScript projects get hints and type checking with no extra configuration:
117
162
  ```ts
118
163
  import { div, vButton, vCard, vTable, toast } from '@yoyaflow/yoya-ui';
119
164
  import { createI18n } from '@yoyaflow/yoya-ui/core';
120
- import { renderToString } from '@yoyaflow/yoya-ui/ssr';
165
+ import { renderPage } from '@yoyaflow/yoya-ui/ssr';
121
166
  import '@yoyaflow/yoya-ui/ui.css';
122
167
 
123
168
  div((page) => {
@@ -173,7 +218,7 @@ npm run build
173
218
 
174
219
  - `yoya.core.js` / `yoya.ui.js` — core and component library ESM entries
175
220
  - `yoya.echart.js` — ECharts component entry (does not bundle echarts itself)
176
- - `yoya.ssr.js` — server rendering entry (`renderToString` / `hydrate` / `mount`)
221
+ - `yoya.ssr.js` — server rendering entry (`renderPage` / `hydrateOrMount` / `renderToString` / `hydrate` / `mount`)
177
222
  - `echarts.min.js` — ECharts core (load globally via `<script>`)
178
223
  - `yoya.ui.css` — default styles and theme variables
179
224
  - `yoya-ui.umd.js` — UMD build (`window.YoyaUI`)
package/README.zh-CN.md CHANGED
@@ -45,6 +45,24 @@ function HelloWorldExampleI18n() {
45
45
 
46
46
  ## 安装
47
47
 
48
+ ### 脚手架快速搭建
49
+
50
+ ```bash
51
+ npx create-yoya-ui@latest my-app # basic 模板(SPA)
52
+ npx create-yoya-ui@latest my-app --template ssr # SSR 模板(renderPage + hydrateOrMount)
53
+ npx create-yoya-ui@latest my-app --template admin # admin 后台管理模板(顶部导航 + 可折叠侧栏 + RouterViews)
54
+ cd my-app
55
+ npm install
56
+ npm run dev # basic / admin:开发服务器
57
+ # SSR:npm run build && npm start
58
+ ```
59
+
60
+ `--template admin` 生成标准后台管理模板:顶部导航 + 可折叠侧栏 + 带标题的 RouterViews 内容区,内置数据概览看板与图表,以及成员 / 角色 / 权限 / 字典管理等业务域示例。
61
+
62
+ yoya-ui 拥有自己独特的开发范式:声明式节点 DSL、页面编排与 feature 模块组织。推荐使用 admin 模板创建项目来了解这些范式——它用库的原生写法完整展示了一个真实后台(页面壳、路由、表格/表单/弹窗、数据看板与图表)。
63
+
64
+ ### 已有项目引入
65
+
48
66
  ```bash
49
67
  npm install @yoyaflow/yoya-ui
50
68
  ```
@@ -67,24 +85,42 @@ div((page) => {
67
85
 
68
86
  ## 服务端渲染(SSR)
69
87
 
70
- 同一份页面工厂代码,服务端渲染与客户端渲染可切换:
88
+ 同一份页面工厂代码,服务端渲染与客户端渲染可切换。整页场景直接使用高层入口:`renderPage` 输出完整 HTML 文档(head/body 用 DSL 定义),`hydrateOrMount` 一行完成客户端接入:
71
89
 
72
90
  ```js
73
- // 服务端
74
- import { renderToString } from '@yoyaflow/yoya-ui/ssr';
75
- const { html, state } = renderToString(createPage, { state: { path: '/home' } });
76
-
77
- // 客户端
78
- import { hydrate, mount, parseState } from '@yoyaflow/yoya-ui/ssr';
79
- const data = parseState(document.getElementById('__YOYA_DATA__').textContent);
80
- const app = document.getElementById('app');
81
- if (app.firstElementChild) {
82
- hydrate(createPage, app, data); // 有服务端 HTML:收养 DOM、绑定事件
83
- } else {
84
- mount(createPage, app, data); // 空壳:全量客户端渲染
85
- }
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 });
86
120
  ```
87
121
 
122
+ 底层原语(`renderToString` / `serializeState` / `parseState` / `mount` / `hydrate`)仍然可用,适合需要细粒度控制的场景,例如把 HTML 片段嵌入自有服务端模板。
123
+
88
124
  要点:
89
125
 
90
126
  - `vClientOnly(loader)`:非 SSR 模块(如 ECharts)服务端只出占位,hydration 后客户端加载
@@ -92,7 +128,16 @@ if (app.firstElementChild) {
92
128
  - 每请求 i18n 实例、渲染上下文 id 分配器、渲染后自动销毁——服务端保持无状态
93
129
  - `maxNodes` 超限自动回退客户端渲染
94
130
 
95
- 完整集成指南见 [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
+ 或运行仓库内示例:
96
141
 
97
142
  ```bash
98
143
  npm run build
@@ -105,7 +150,7 @@ node src/examples/ssr/server-http.mjs
105
150
  import { div, svg, createI18n } from '@yoyaflow/yoya-ui/core'; // 核心 HTML/SVG/状态
106
151
  import { vButton, vCard, vForm, vTable } from '@yoyaflow/yoya-ui/ui'; // 官方组件库
107
152
  import { vEchart } from '@yoyaflow/yoya-ui/echart'; // ECharts 组件(需自行引入 echarts)
108
- import { renderToString, hydrate } from '@yoyaflow/yoya-ui/ssr'; // 服务端渲染
153
+ import { renderPage, hydrateOrMount } from '@yoyaflow/yoya-ui/ssr'; // 服务端渲染
109
154
  import '@yoyaflow/yoya-ui/ui.css'; // 默认样式与主题变量
110
155
  ```
111
156
 
@@ -118,7 +163,7 @@ TypeScript 项目无需额外配置即可获得提示与类型检查:
118
163
  ```ts
119
164
  import { div, vButton, vCard, vTable, toast } from '@yoyaflow/yoya-ui';
120
165
  import { createI18n } from '@yoyaflow/yoya-ui/core';
121
- import { renderToString } from '@yoyaflow/yoya-ui/ssr';
166
+ import { renderPage } from '@yoyaflow/yoya-ui/ssr';
122
167
  import '@yoyaflow/yoya-ui/ui.css';
123
168
 
124
169
  div((page) => {
@@ -174,7 +219,7 @@ npm run build
174
219
 
175
220
  - `yoya.core.js` / `yoya.ui.js` — 核心与组件库 ESM 入口
176
221
  - `yoya.echart.js` — ECharts 组件入口(不包含 echarts 本体)
177
- - `yoya.ssr.js` — 服务端渲染入口(`renderToString` / `hydrate` / `mount`)
222
+ - `yoya.ssr.js` — 服务端渲染入口(`renderPage` / `hydrateOrMount` / `renderToString` / `hydrate` / `mount`)
178
223
  - `echarts.min.js` — ECharts 本体(用 `<script>` 标签全局引入)
179
224
  - `yoya.ui.css` — 默认样式与主题变量
180
225
  - `yoya-ui.umd.js` — UMD 版(`window.YoyaUI`)