@24city/web-console 0.1.1 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.3
4
+
5
+ - 新增 `@24city/web-console/vite` 的 `semiCssLayer()`:把 Semi 自带的样式放进 CSS 级联层 `semi`,本包主题也写进这一层。
6
+ 产品与本包组件的 CSS Modules 不在任何层里,一律排在 Semi 与主题之上,照着写的覆盖不再被 Semi 三个类的选择器静默压掉
7
+ (AdFlow Staging 上审计出 31 条:形象页 20px 大号页签变成 14px、新建产品的加号从 28px 变成 14px、积分数字变灰等)。
8
+ **产品的 `vite.config.ts` 必须加上它**;守卫新增 `checkSemiCssLayer` 检查,消费方验证也检查构建产物里 Semi 在 `semi` 层中。
9
+ - 主题让 `.semi-button-content` 继承按钮上的 `gap`、`flex-direction`、`align-items`:Logo 与产品名、积分金币与数字、个人中心链接与外链图标、
10
+ 空间切换等不再粘在一起,产品里写在按钮上的竖排(如 AdFlow 工作台的步骤条“标题 + 状态”)不再挤成一行。
11
+ - 页面底色 `--app-page-bg` 改为不透明的灰(与 Arco 时代的 #F5F5F5 相同);原来是 9% 的半透明填充,叠在灰色页面底上成了 #E4E4E4。
12
+ - 侧栏:菜单项图标与文字垂直居中(原来图标贴在顶上);去掉 Semi 竖向导航列表自带的 12px 顶部内边距;没有标题的分组与下一组的标题只隔 4px,
13
+ 与 Arco 时代的位置一致。
14
+ - 头像里的字母按头像大小显示(顶栏 15px、账号菜单 22px),Semi 在头像文字上写死的 12px 不再生效。
15
+ - 新增组件总览页 `js/examples/console-gallery`(`pnpm run gallery:build`),全部组件平铺在一个自包含的 HTML 里,见 README「组件总览」。
16
+
17
+ ## 0.1.2
18
+
19
+ - 个人中心页面标题同样补足优先级(0.1.1 只改了 `ProductPage` 的标题),Staging 上仍是 Semi 默认的 32px,现在回到 24px。
20
+ - README 补一条:Semi 的竖向 `Space` 默认把子项居中收缩(`align="center"`),Arco 是拉伸;表单类竖排要么给 `align="start"`,要么在自己的类上写 `align-items: stretch`。
21
+
3
22
  ## 0.1.1
4
23
 
5
24
  - 修正 Semi 覆盖样式在打包后失效的问题(AdFlow Staging 上发现:整站回到 Semi 默认的蓝灰中性色、3px 圆角、32px 页面标题)。
package/README.md CHANGED
@@ -23,6 +23,17 @@ Semi 的三个包必须精确声明为本包 `peerDependencies` 里的版本:
23
23
  @import "@24city/web-console/styles.css";
24
24
  ```
25
25
 
26
+ 产品的 `vite.config.ts` 必须加上 `semiCssLayer()`(守卫 `checkSemiCssLayer` 会检查):
27
+
28
+ ```ts
29
+ import { semiCssLayer } from '@24city/web-console/vite'
30
+
31
+ export default defineConfig({ plugins: [react(), semiCssLayer()] })
32
+ ```
33
+
34
+ 它把 Semi 自带的样式放进 CSS 级联层 `semi`,本包主题也写在这一层里;产品与本包组件的 CSS Modules 不在任何层里,**一律排在 Semi 与主题之上**,
35
+ 不用再比 Semi 的选择器“多一个类”(Semi 常用三个类的选择器,照着 Arco 习惯写的覆盖会被静默压掉)。不加这个插件时,本包主题会被 Semi 整体盖住。
36
+
26
37
  颜色分五层,只有品牌主色是产品的:
27
38
 
28
39
  | 层 | 变量 | 谁定 |
@@ -61,7 +72,8 @@ Semi 的三个包必须精确声明为本包 `peerDependencies` 里的版本:
61
72
  | `/account` | `createAccountApi`、`AuthProvider`、`RouteGuard`、`LoginPage`、`useAuthState`、`useLogout`、`useSpaceSwitch`、`useMembership`、`AccountMenu`、`WalletBadge`、`UpgradeEntry`、`UpgradeModal`、`QuotaPill`、`AccountCenterPage`、`plansUrl`、`ConsoleCustomization` |
62
73
  | `/layout` | `ConsoleLayout`、`BrandMark`、导航类型 |
63
74
  | `/page` | `ProductPage`、`FullPage`、`LoadingCard`、`ErrorCard`、`EmptyCard`、`StatusResult`、`LinkButton`、`TextLink`、`SessionUnavailable`、`ErrorBoundary`、`RouteErrorPage`、`StartupError`、`NotFoundPage` |
64
- | `/testing/guard` | `checkUiLibraryUsage`、`checkSemiVersion`(Node,用于 vitest) |
75
+ | `/vite` | `semiCssLayer`(构建插件:Semi 的样式放进 `semi` 层,产品 `vite.config.ts` 必加;Node) |
76
+ | `/testing/guard` | `checkUiLibraryUsage`、`checkSemiVersion`、`checkSemiCssLayer`(Node,用于 vitest) |
65
77
  | `/testing/jsdom` | jsdom 测试环境的浏览器 API 垫片(matchMedia、ResizeObserver、canvas、Range),在 setup 里排在引入 Semi 之前 |
66
78
  | `/testing/fixtures` | `createFixtureRuntime`、`createFixtureAccountApi` 等替身(UI-only 模式与测试) |
67
79
  | `/styles.css` | 主题 + 本包组件样式(Semi 组件样式随组件引入) |
@@ -134,16 +146,29 @@ const customization: ConsoleCustomization = {
134
146
  </script>
135
147
  ```
136
148
 
149
+ ## 组件总览
150
+
151
+ `js/examples/console-gallery` 把本包的全部组件和经本包主题后的 Semi 基础组件平铺在一个页面里:整页预览(外壳、账号菜单、个人中心三页、升级弹窗、
152
+ 404、启动失败、会话与账号服务不可用、公开首页)、设计变量(品牌色板、中性灰、文字层级、填充与边框、圆角、投影)、本包组件、Semi 基础组件和图标。
153
+ 账号接口是替身,不连任何服务;顶部可切品牌主色、会员状态(免费版 / 专业版 / 团队空间)和次要文字深浅,开关写在地址 # 后面,链接发给别人就是同一个状态。
154
+
155
+ ```sh
156
+ pnpm run gallery:build # 在 js/ 下运行,产出 examples/console-gallery/dist/web-console-gallery.html
157
+ ```
158
+
159
+ 产出是单个 HTML(图片、JS、CSS 全部内联),本地双击打开即可,也可以直接发给同事或投屏讨论。改了本包的样式或组件后重新构建一次,对照着看。
160
+
137
161
  ## 守卫测试
138
162
 
139
163
  产品加一个测试文件,界面就只能来自 Semi 和本包:
140
164
 
141
165
  ```ts
142
- import { checkSemiVersion, checkUiLibraryUsage } from '@24city/web-console/testing/guard'
166
+ import { checkSemiCssLayer, checkSemiVersion, checkUiLibraryUsage } from '@24city/web-console/testing/guard'
143
167
 
144
168
  it('界面只使用 Semi Design 与 @24city/web-console', () => {
145
169
  expect(checkUiLibraryUsage({ sourceRoot: resolve(process.cwd(), 'src') })).toEqual([])
146
170
  expect(checkSemiVersion(resolve(process.cwd(), 'package.json'))).toEqual([])
171
+ expect(checkSemiCssLayer(resolve(process.cwd(), 'vite.config.ts'))).toEqual([])
147
172
  })
148
173
  ```
149
174
 
@@ -157,9 +182,13 @@ Lottie 在模块加载时会用到 canvas,没有垫片时整个包都引不进
157
182
 
158
183
  ### 用 Semi 时的几个坑
159
184
 
160
- - Semi 把设计变量定义在 `body` 上,而打包后 `@douyinfe/semi-ui` 的 `_base/base.css` 往往排在本包样式之后:覆盖 Semi 的规则不能只靠同级选择器与引入顺序。
161
- 本包的变量写在 `html body` 上,组件覆盖在 Semi 的选择器之上再加一级;产品自己的模块样式若要盖住 Semi 的某条规则,同样要比它多一个类。
185
+ - 覆盖 Semi 的样式靠分层而不是选择器优先级:`semiCssLayer()` 把 Semi 放进 `semi` 层,产品与本包组件的模块样式写普通选择器就排在它之上。
186
+ 本包主题与 Semi 同层,仍按选择器优先级细调 Semi(变量写在 `html body` 上,组件规则比 Semi 高一级),所以产品样式也排在主题之上。
187
+ - Semi 把按钮的子元素包进 `.semi-button-content`。本包主题让它继承按钮上的 `gap`、`flex-direction`、`align-items`,
188
+ 在按钮自己的类上写这几项就生效;用 `icon` 属性时 Semi 另有 8px 图标间距。
162
189
  - Semi 的 `Input` 把 `className` 放在 `.semi-input-wrapper` 自己身上(Arco 在外面还有一层),模块样式要写成 `.mine:global(.semi-input-wrapper)` 而不是后代选择器。
190
+ - Semi 的竖向 `Space`(`vertical`)默认 `align="center"`,子项居中并收缩到内容宽;Arco 的竖向 Space 是拉伸的。表单字段一类的竖排给 `align="start"`,
191
+ 要占满一行的在自己的类上写 `align-items: stretch`。
163
192
  - Arco 的 `type="text"` 按钮是主色文字,Semi 对应的是 `theme="borderless" type="primary"`;`type="tertiary"` 是灰色。
164
193
  - Semi 的图标渲染为 `role="img"` 并带英文 `aria-label`,放在按钮文字旁会污染按钮的读屏名称:装饰性图标一律加 `aria-hidden="true"`。
165
194
  - 弹窗默认脚部按钮带英文 `aria-label`(confirm / cancel):本包在 `/semi` 里清掉了默认值;自己传 `okButtonProps` 时用 `modalButtonProps({...})` 合并。
@@ -1,6 +1,6 @@
1
1
  import { A as e, a as t, c as o, b as n, i as r, d as i, l as u, n as c, r as l, e as g, f as p, u as A, g as S, w as P } from "../chunks/logout-signal-CiD_zY5M.js";
2
- import { A as C, C as d, L as f, P as h, a as m, b as y, Q as N, R as T, S as E, c as O, T as b, U, d as F, p as _, e as x, f as v, g as w, y as B } from "../chunks/upgrade-modal-DzdKuEkJ.js";
3
- import { A as I, a as q, b as D, E as K, F as M, P as Q, c as G, d as H, U as k, e as W, W as Y, f as j, g as z, h as J, i as V, j as X, k as Z, l as $, m as aa, n as sa, o as ea, p as ta, q as oa, r as na, s as ra, t as ia, u as ua, v as ca, w as la, x as ga, y as pa, z as Aa, B as Sa, C as Pa, D as La, G as Ca, H as da, I as fa, J as ha, K as ma, L as ya, M as Na, N as Ta, O as Ea, Q as Oa } from "../chunks/wallet-badge-CnyMLpUO.js";
2
+ import { A as C, C as d, L as f, P as h, a as m, b as y, Q as N, R as T, S as E, c as O, T as b, U, d as F, p as _, e as x, f as v, g as w, y as B } from "../chunks/upgrade-modal-J0X79nT2.js";
3
+ import { A as I, a as q, b as D, E as K, F as M, P as Q, c as G, d as H, U as k, e as W, W as Y, f as j, g as z, h as J, i as V, j as X, k as Z, l as $, m as aa, n as sa, o as ea, p as ta, q as oa, r as na, s as ra, t as ia, u as ua, v as ca, w as la, x as ga, y as pa, z as Aa, B as Sa, C as Pa, D as La, G as Ca, H as da, I as fa, J as ha, K as ma, L as ya, M as Na, N as Ta, O as Ea, Q as Oa } from "../chunks/wallet-badge-BXu-WxJa.js";
4
4
  import { A as Ua } from "../chunks/auth-provider-CqiyTeOt.js";
5
5
  import { notifyCustomerSessionChanged as _a, subscribeCustomerSessionChanges as xa } from "@24city/web-runtime/session-sync";
6
6
  export {
@@ -0,0 +1,208 @@
1
+ import { jsx as n, jsxs as c, Fragment as O } from "react/jsx-runtime";
2
+ import { useState as b, useEffect as S } from "react";
3
+ import { Layout as k, Button as f, Typography as F, Space as Q, Nav as $ } from "@douyinfe/semi-ui";
4
+ import { IconSidebar as P } from "@douyinfe/semi-icons";
5
+ import { useLocation as Y, useNavigate as q, Outlet as D } from "react-router";
6
+ import { h as J, B as V, o as X, e as Z, W as z, b as ee } from "./wallet-badge-BXu-WxJa.js";
7
+ import { u as R, b as ne, a as te } from "./context-CaVim6ZO.js";
8
+ import { u as ae } from "./use-media-query-DvyinWNg.js";
9
+ const oe = "_layout_1pk01_6", se = "_header_1pk01_13", le = "_headerLeft_1pk01_34", re = "_logo_1pk01_42", ce = "_logoMark_1pk01_57", ie = "_logoText_1pk01_64", de = "_modules_1pk01_73", ue = "_module_1pk01_73", pe = "_moduleText_1pk01_110", me = "_moduleIcon_1pk01_130", _e = "_moduleInk_1pk01_134", he = "_headerRight_1pk01_154", ke = "_body_1pk01_163", fe = "_sider_1pk01_169", ye = "_siderInner_1pk01_183", ge = "_panel_1pk01_190", Ne = "_expandButton_1pk01_227", ve = "_menu_1pk01_243", be = "_menuGroup_1pk01_254", Ie = "_menuGroupPlain_1pk01_263", xe = "_menuGroupTitle_1pk01_268", Ce = "_menuList_1pk01_279", Me = "_collapseButton_1pk01_402", Be = "_mask_1pk01_423", we = "_content_1pk01_432", Le = "_contentCentered_1pk01_438", Ge = "_contentInner_1pk01_450", Te = "_letterMark_1pk01_503", e = {
10
+ layout: oe,
11
+ header: se,
12
+ headerLeft: le,
13
+ logo: re,
14
+ logoMark: ce,
15
+ logoText: ie,
16
+ modules: de,
17
+ module: ue,
18
+ moduleText: pe,
19
+ moduleIcon: me,
20
+ moduleInk: _e,
21
+ headerRight: he,
22
+ body: ke,
23
+ sider: fe,
24
+ siderInner: ye,
25
+ panel: ge,
26
+ expandButton: Ne,
27
+ menu: ve,
28
+ menuGroup: be,
29
+ menuGroupPlain: Ie,
30
+ menuGroupTitle: xe,
31
+ menuList: Ce,
32
+ collapseButton: Me,
33
+ mask: Be,
34
+ content: we,
35
+ contentCentered: Le,
36
+ contentInner: Ge,
37
+ letterMark: Te
38
+ }, $e = (a, l) => a === l || a.startsWith(`${l}/`), Pe = (a, l) => a.flatMap((o) => o.items).find((o) => new URL(o.to, "http://console.local").pathname === l), Se = (a, l) => {
39
+ var o;
40
+ return (o = [...a].map((r) => ({ module: r, path: new URL(r.to, "http://console.local").pathname })).filter(({ path: r }) => $e(l, r)).sort((r, u) => u.path.length - r.path.length)[0]) == null ? void 0 : o.module;
41
+ }, Re = () => {
42
+ const [a, l] = b(!1);
43
+ return S(() => {
44
+ const o = () => l(window.scrollY > 0);
45
+ return o(), window.addEventListener("scroll", o, { passive: !0 }), () => window.removeEventListener("scroll", o);
46
+ }, []), a;
47
+ }, Ae = ({ size: a = 30, className: l }) => {
48
+ const o = R(), r = (u) => l ? `${u} ${l}` : u;
49
+ return o.markUrl ? /* @__PURE__ */ n(
50
+ "span",
51
+ {
52
+ className: r(e.logoMark),
53
+ style: { width: a, height: a, backgroundImage: `url("${o.markUrl}")` },
54
+ "aria-hidden": "true"
55
+ }
56
+ ) : /* @__PURE__ */ n("span", { className: r(e.letterMark), style: { width: a, height: a }, "aria-hidden": "true", children: Array.from(o.mark).slice(0, 2).join("") });
57
+ }, Qe = ({
58
+ modules: a = [],
59
+ activeModuleKey: l,
60
+ moduleTarget: o,
61
+ sidebar: r = [],
62
+ selectedKey: u,
63
+ renderItemLabel: I,
64
+ headerRight: A,
65
+ menuLabel: U = "工作台菜单",
66
+ children: E,
67
+ extra: K
68
+ }) => {
69
+ var T;
70
+ const { config: x } = ne(), C = R(), y = Y(), g = q(), M = x.routes.app, _ = J(M, V(te())), B = X(M, y.pathname), h = B ? [] : r ?? [], w = h.length > 0, W = l ?? ((T = Se(a, y.pathname)) == null ? void 0 : T.key), p = Pe([...h, _], y.pathname), L = u ?? (p == null ? void 0 : p.key), i = ae("(min-width: 992px)"), j = Re(), [m, N] = b(!i), [v, d] = b(!1), H = new Map([...h, _].flatMap((t) => t.items.map((s) => [s.key, s])));
71
+ S(() => {
72
+ N(!i), d(!1);
73
+ }, [i]);
74
+ const G = (t) => {
75
+ const s = H.get(t);
76
+ s && g(s.to), d(!1);
77
+ };
78
+ return /* @__PURE__ */ c(k, { className: e.layout, children: [
79
+ /* @__PURE__ */ c(k.Header, { className: e.header, "data-scrolled": j ? "true" : "false", children: [
80
+ /* @__PURE__ */ c("div", { className: e.headerLeft, children: [
81
+ /* @__PURE__ */ c(
82
+ f,
83
+ {
84
+ theme: "borderless",
85
+ type: "tertiary",
86
+ className: e.logo,
87
+ "aria-label": `${C.shortName} 首页`,
88
+ onClick: () => g(x.routes.publicHome),
89
+ children: [
90
+ /* @__PURE__ */ n(Ae, {}),
91
+ /* @__PURE__ */ n(F.Text, { className: e.logoText, children: C.shortName })
92
+ ]
93
+ }
94
+ ),
95
+ a.length ? /* @__PURE__ */ n("div", { className: e.modules, role: "navigation", "aria-label": "产品模块", children: a.map((t) => /* @__PURE__ */ c(
96
+ f,
97
+ {
98
+ theme: "borderless",
99
+ type: "tertiary",
100
+ className: e.module,
101
+ "aria-current": W === t.key ? "page" : void 0,
102
+ onClick: () => g(o ? o(t) : t.to),
103
+ children: [
104
+ /* @__PURE__ */ c("span", { className: e.moduleText, children: [
105
+ t.icon ? /* @__PURE__ */ n("span", { className: e.moduleIcon, children: /* @__PURE__ */ n(t.icon, {}) }) : null,
106
+ t.label
107
+ ] }),
108
+ /* @__PURE__ */ n("span", { className: e.moduleInk, "aria-hidden": "true" })
109
+ ]
110
+ },
111
+ t.key
112
+ )) }) : null
113
+ ] }),
114
+ /* @__PURE__ */ n(Q, { spacing: 10, className: e.headerRight, children: A ?? /* @__PURE__ */ c(O, { children: [
115
+ /* @__PURE__ */ n(Z, {}),
116
+ /* @__PURE__ */ n(z, {}),
117
+ /* @__PURE__ */ n(ee, { personal: _, selectedKey: p && _.items.includes(p) ? p.key : void 0, onOpen: G })
118
+ ] }) })
119
+ ] }),
120
+ /* @__PURE__ */ c(k, { className: e.body, children: [
121
+ w ? /* @__PURE__ */ n("aside", { className: e.sider, "data-collapsed": m ? "true" : "false", children: /* @__PURE__ */ c(
122
+ "div",
123
+ {
124
+ className: e.siderInner,
125
+ "data-collapsed": m ? "true" : "false",
126
+ "data-peek": v ? "true" : "false",
127
+ onMouseEnter: () => {
128
+ m && i && d(!0);
129
+ },
130
+ onMouseLeave: () => {
131
+ i && d(!1);
132
+ },
133
+ children: [
134
+ m ? /* @__PURE__ */ n(
135
+ f,
136
+ {
137
+ theme: "light",
138
+ type: "tertiary",
139
+ className: e.expandButton,
140
+ icon: /* @__PURE__ */ n(P, { "aria-hidden": "true" }),
141
+ "aria-label": "展开侧边栏",
142
+ "aria-expanded": v,
143
+ onClick: () => {
144
+ i ? (N(!1), d(!1)) : d((t) => !t);
145
+ }
146
+ }
147
+ ) : null,
148
+ /* @__PURE__ */ c("div", { className: e.panel, children: [
149
+ /* @__PURE__ */ n("nav", { className: e.menu, "aria-label": U, children: h.map((t) => /* @__PURE__ */ c(
150
+ "div",
151
+ {
152
+ className: t.label ? e.menuGroup : `${e.menuGroup} ${e.menuGroupPlain}`,
153
+ role: "group",
154
+ "aria-label": t.label || void 0,
155
+ children: [
156
+ t.label ? /* @__PURE__ */ n("div", { className: e.menuGroupTitle, children: t.label }) : null,
157
+ /* @__PURE__ */ n(
158
+ $,
159
+ {
160
+ mode: "vertical",
161
+ className: e.menuList,
162
+ selectedKeys: L ? [L] : [],
163
+ onSelect: ({ itemKey: s }) => G(String(s)),
164
+ children: t.items.map((s) => /* @__PURE__ */ n(
165
+ $.Item,
166
+ {
167
+ itemKey: s.key,
168
+ icon: s.icon ? /* @__PURE__ */ n(s.icon, {}) : void 0,
169
+ text: I ? I(s) : s.label
170
+ },
171
+ s.key
172
+ ))
173
+ }
174
+ )
175
+ ]
176
+ },
177
+ t.key
178
+ )) }),
179
+ i ? /* @__PURE__ */ n(
180
+ f,
181
+ {
182
+ theme: "borderless",
183
+ type: "tertiary",
184
+ className: e.collapseButton,
185
+ icon: /* @__PURE__ */ n(P, { "aria-hidden": "true" }),
186
+ onClick: () => {
187
+ N((t) => !t), d(!1);
188
+ },
189
+ children: m ? "固定侧边栏" : "收起侧边栏"
190
+ }
191
+ ) : null
192
+ ] })
193
+ ]
194
+ }
195
+ ) }) : null,
196
+ v && !i && w ? /* @__PURE__ */ n("div", { className: e.mask, "aria-hidden": "true", onClick: () => d(!1) }) : null,
197
+ /* @__PURE__ */ n(k.Content, { className: B ? `${e.content} ${e.contentCentered}` : e.content, children: /* @__PURE__ */ n("div", { className: e.contentInner, children: E ?? /* @__PURE__ */ n(D, {}) }) })
198
+ ] }),
199
+ K
200
+ ] });
201
+ };
202
+ export {
203
+ Ae as B,
204
+ Qe as C,
205
+ Pe as a,
206
+ Se as f,
207
+ $e as i
208
+ };