docs: add doc system for widget library#324
Conversation
|
@copilot PR 标题应该概述本次实施计划(我已手动更新标题,你无需再修改),PR 描述应该简单说明这次 PR 做了什么,而不是写你修改了什么。后续对此 PR 做修改不要重置 PR 标题和描述,应该仅对 PR 描述做完善和补充。 |
了解,后续不会重置 PR 标题和描述,仅对描述做补充说明,描述内容也会聚焦在"这次 PR 做了什么"上。 |
|
@copilot 重写 PR 描述吧,现在的内容被你重置成仅针对 PR 评审的改动了。 |
| run: npm install @lcui/react | ||
|
|
||
| - name: Process TSX files | ||
| run: lcui build docs/build/app |
| - name: Build LCUI | ||
| run: | | ||
| xmake config -y -v -k static -m release | ||
| xmake |
There was a problem hiding this comment.
Build LCUI 步骤不应该编译 docs-viewer,相关日志如下:
[ 13%]: <lcui> compiling.release src/widgets/scrollbar.c
[ 13%]: <lcui> compiling.release src/widgets/textcaret.c
error: src/main.h:4:10: fatal error: ../docs/build/app/components/anchor/page.h: No such file or directory
4 | #include "../docs/build/app/components/anchor/page.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
> in src/main.c
Error: Process completed with exit code 255.
There was a problem hiding this comment.
@copilot 你应该主动在你的开发环境内执行一遍构建流程,而不是让 GitHub Actions 帮你构建和测试。
There was a problem hiding this comment.
已删除 src/main.c 和 src/main.h——这两个文件原本是 docs-viewer 的入口文件,被错误放置在 src/ 目录下,导致 LCUI 的 add_files("src/**.c") 将其编译时引用了不存在的 docs 头文件。删除后 Build LCUI 步骤不再编译 docs-viewer 相关代码。
| # Build the docs-viewer C executable (Windows) | ||
| # --------------------------------------------------------------------------- | ||
| build-viewer-windows: | ||
| name: Build docs-viewer (Windows) |
There was a problem hiding this comment.
看上去 windows 和 linux 下的 docs-viewer 构建步骤是相似的,应该参考 ccpp.yml 用 matrix:
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'windows-latest']There was a problem hiding this comment.
已将两个 build-viewer job 合并为使用 matrix 策略(ubuntu-latest + windows-latest),与 ccpp.yml 保持一致。
已根据最新审核意见完成修改(提交 |
|
@copilot 按下面的方案调整。 删减示例所有组件示例只保留基础示例,移除其它示例。 文档内容规范减少表格的使用,因为 LCUI 不支持 table 布局。如果确实需要用到表格,应该在转译阶段将其转换成用 flex 布局容器模拟实现,即:每行对应一个 flex 容器,每列宽度是固定值/百分比值,最多一列是 flex-auto 自动填充可用宽度。 tools/doc-viewer 项目
文档转译约定:
流程:
|
... 已按方案完成调整(提交
|
7418aff to
db84ce2
Compare
|
@copilot 按照以下评审意见做修改。 tools\doc-viewer\app\components\sidebar.json:应该支持多语言。 tools\doc-viewer\app\components\sidebar.tsx:
tools\doc-viewer\app\components\navbar.tsx:
tools\doc-viewer\app\handbook\composition\page.tsx:
tools\doc-viewer\app\components\button\page.tsx:
tools\doc-viewer\app\components\button\page.c: 怎么是在页面初始化函数里写 C 代码构造示例代码块啊?这些属于静态内容,应该由 tsx 文件描述。 docs\examples\button-basic-tsx\ui.tsx: 更名为 example.tsx,其他组件示例目录内的 ui.tsx 也做相同的重命名。 docs\examples\button-basic-tsx\main.c: 内容改为: #include <LCUI.h>
#include "example.h"
int main(int argc, char *argv[])
{
lcui_init();
ui_register_example();
ui_root_append(ui_create_example());
return lcui_main();
}其他组件的 tsx 示例中的 main.c 内容也改成这样。 |
已按评审意见完成修改:
本地已验证 |
Agent-Logs-Url: https://github.com/lc-soft/LCUI/sessions/1dd82f00-d654-42d0-915f-f5cd25030a09 Co-authored-by: lc-soft <1730073+lc-soft@users.noreply.github.com>
Doc-viewer's tailwind.config.js uses an allow-list `corePlugins`
array; the code-block rule in `app/global.css` was updated to use
`whitespace-pre` and `font-mono` but those plugins were not on
the list, so Tailwind rejected the build with::
The `whitespace-pre` class does not exist.
Add `whitespace` and `fontFamily` to the allow-list.
Markdown unordered (`- foo`) and ordered (`1. foo`) lists in MDX were being coalesced into a single `<p>` paragraph by the section renderer, losing all structure. Teach `renderSectionContent` to recognise list lines and emit `<ul>`/`<ol>` blocks wrapping `<li><Text>...</Text></li>` items. To render those tags, register native `ol`/`ul`/`li` widgets in `app/components/list.c`: - `li` creates an absolutely-positioned marker child on init. - `ol`/`ul` watch their own child list with a mutation observer and refresh every li's marker on any change. `ul` uses a fixed bullet, `ol` uses 1-based decimal numbering. - `ol` also scales the li padding-left in px based on the widest number's digit count so markers visually align.
Replace the spacer in the navbar with an address-bar style text that
renders the active route's full path. Wire it up via router_watch in
`navbar.c` so both the address bar and the OS window title refresh
on every navigation:
<page title> \u00b7 LCUI
Page titles come from a generated lookup table
`app/components/route-titles.h`. The compiler walks `sidebars.json`
across every locale and emits one `{path, Ltitle}` entry per page.
Non-ASCII title characters are written as `\\uXXXX` escapes so the
header stays ASCII and avoids MSVC C4819 on Windows.
`main.c` no longer sets the title explicitly; navbar.c owns it from
mount onward (the initial route is also picked up by reading
`router_get_current_route` once at navbar_init time).
Wrap every code block (both MDX fenced and demo source) in a card:
- light-themed background with a 1px gray border and rounded corners
- header row showing a friendly language name (mdx) or file name
(demo) on the left, and a clickable Copy button on the right
- body containing one `<Text>`-per-line with GitHub Light syntax
colours (replacing the old dark palette)
The Copy button is its own widget defined by
`app/components/code-block-copy.{tsx,c,h}`. Its JSX wires the click
event to a C function by name (`onClick="code_block_copy_on_click"`);
the C handler walks up to the enclosing `.code-block`, reads its
`data-source` attribute, looks up the source text in the generated
code-snippets table, and copies the result to the clipboard via
`ptk_clipboard_set_text`. A 1.5s `ptk_set_timeout` reverts the
button label after a successful copy.
To avoid carrying multi-line string literals through generated JSX,
`page-generator.ts` collects every code-block source into a
`SnippetRegistry` keyed by a stable id and emits
`app/components/code-snippets.{c,h}` with one
`code_snippet_for(id)` lookup. Each non-ASCII byte is encoded as a
`\\xNN` octet with adjacent-string concatenation in between so MSVC
does not collapse consecutive hex escapes into out-of-range values.
Also folds in two list-widget refinements requested during review:
- `list.c::refresh_markers` now uses
`ui_widget_set_style_unit_value` with `CSS_UNIT_PX` instead of
`ui_widget_set_style_string` + `snprintf`.
- `global.css` switches `ol`/`ul` from flexbox to `display:
block` to match the intended layout model.
And re-enables a few corePlugins (`alignItems`, `justifyContent`)
needed by the new code-block-header rules.
Two fixes to the code-block rendering introduced in the previous commit: - LCUI's text widget collapses runs of ASCII whitespace at the start of a line, so source-code indentation was visually lost in code blocks. `page-generator.ts` now replaces the leading run of spaces/tabs (tab counts as 4) on every `code-line` with U+00A0 (NO-BREAK SPACE), which the text widget preserves as opaque characters. Whitespace inside the line is left untouched. - `.code-block-body` and `.code-line` now set `font-family: monospace`. LCUI registers `monospace` as a built-in alias (see `src/lcui_fonts.c`), so the code block picks up Consolas/Ubuntu Mono on the respective platforms.
df664b8 to
427939a
Compare
What
This PR establishes a complete documentation foundation for LCUI's existing component set, including:
docs/enanddocs/zh-CN)tools/doc-viewerproject (based on the lcui-quick-start template) with hand-written app layout components: Navbar, Sidebar, and DemoProvider with language/file tab switchingWhy
LCUI currently lacks a unified, scalable, and maintainable component documentation workflow.
This PR introduces a clear docs architecture that supports both:
Scope
page.tsx+page.c), layout generation, and shared styles — consolidated fromtools/doc-compilerintotools/doc-viewer/scripts/compilertools/doc-viewerproject withxmake.luausingincludes("../../xmake.lua")for LCUI dependencyThis pull request was created from Copilot chat.