@wanlianyida/portal-kit 0.1.4 → 0.1.6-beta.0

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
@@ -26,11 +26,11 @@ pnpm add @wanlianyida/portal-kit
26
26
 
27
27
  ```vue
28
28
  <script setup lang="ts">
29
- import { FeedbackWidget } from '@wanlianyida/portal-kit';
30
- import { useRoute } from 'vue-router';
29
+ import { FeedbackWidget } from "@wanlianyida/portal-kit";
30
+ import { useRoute } from "vue-router";
31
31
 
32
32
  const route = useRoute();
33
- const webhookUrl = import.meta.env.VITE_FEEDBACK_WEBHOOK_URL?.trim() ?? '';
33
+ const webhookUrl = import.meta.env.VITE_FEEDBACK_WEBHOOK_URL?.trim() ?? "";
34
34
  </script>
35
35
 
36
36
  <template>
@@ -50,7 +50,7 @@ const webhookUrl = import.meta.env.VITE_FEEDBACK_WEBHOOK_URL?.trim() ?? '';
50
50
 
51
51
  ```vue
52
52
  <script setup lang="ts">
53
- import { SelectionComment } from '@wanlianyida/portal-kit';
53
+ import { SelectionComment } from "@wanlianyida/portal-kit";
54
54
  </script>
55
55
 
56
56
  <template>
@@ -73,25 +73,25 @@ admin 的预览和 docs 的文章正文都将 Markdown 直接传给 `MarkdownPre
73
73
 
74
74
  ```vue
75
75
  <script setup lang="ts">
76
- import { ref } from 'vue';
77
- import { MarkdownPreview, type HeadingSection } from '@wanlianyida/portal-kit';
76
+ import { ref } from "vue";
77
+ import { MarkdownPreview, type HeadingSection } from "@wanlianyida/portal-kit";
78
78
 
79
79
  defineProps<{ markdown: string }>();
80
80
  const sections = ref<HeadingSection[]>([]);
81
81
 
82
82
  // 下面的基址来自宿主,公共包不读取宿主的环境变量。
83
83
  const assetBase = import.meta.env.VITE_DOC_BASE || import.meta.env.BASE_URL;
84
- const routeBase = import.meta.env.BASE_URL.replace(/\/+$/, '');
84
+ const routeBase = import.meta.env.BASE_URL.replace(/\/+$/, "");
85
85
 
86
86
  function resolveAssetUrl(src: string): string {
87
87
  if (/^(https?:\/\/|\/\/|data:|blob:)/i.test(src)) return src;
88
- return `${assetBase.replace(/\/+$/, '')}/${src.replace(/^\/+/, '')}`;
88
+ return `${assetBase.replace(/\/+$/, "")}/${src.replace(/^\/+/, "")}`;
89
89
  }
90
90
 
91
91
  function resolveLink(href: string): string | null {
92
92
  // docs 的发布产物已将内部引用重写为 /s/...;残留 doc:// 显示为失效引用。
93
93
  if (/^doc:\/\//i.test(href)) return null;
94
- return href.startsWith('/s/') ? `${routeBase}${href}` : href;
94
+ return href.startsWith("/s/") ? `${routeBase}${href}` : href;
95
95
  }
96
96
  </script>
97
97
 
@@ -129,7 +129,7 @@ H1/H2 进入目录,H3–H6 也有锚点。**docs 迁移时传 `id-prefix=""`
129
129
  - 有序/无序列表、嵌套列表、只读任务列表及段首全角空格缩进。
130
130
  - 普通引用及 `[!NOTE]`、`[!WARNING]`、`[!CAUTION]` 提示块,对应信息、提醒、警告;自定义提示标题保留。
131
131
  - 任意列数的表格,保留列对齐,滚动容器可通过键盘聚焦。
132
- - 代码卡片、JSON 高亮和原文复制;未注册的语言回退纯文本,保留缩进与内部换行。普通换行按 Markdown 段落规则处理,强制换行使用行末两个空格或 `<br>`。
132
+ - 代码卡片、常见请求代码语言高亮和原文复制;语言为空或未注册时自动探测,无法高亮时安全回退原文,保留缩进与内部换行。普通换行按 Markdown 段落规则处理,强制换行使用行末两个空格或 `<br>`。
133
133
 
134
134
  ### 两端接入
135
135
 
@@ -190,10 +190,57 @@ pnpm build
190
190
  npm pack --dry-run
191
191
  ```
192
192
 
193
- 开发栈沿用 Vue 3 Composition API、TypeScript strict、Vite 库模式及类型声明生成。`vue` 和 `element-plus` 由宿主提供;marked、DOMPurify 和 highlight.js 随库构建,JSON 按需注册,无需额外加载 CDN。
193
+ 开发栈沿用 Vue 3 Composition API、TypeScript strict、Vite 库模式及类型声明生成。`vue` 和 `element-plus` 由宿主提供;marked、DOMPurify 和 highlight.js 随库构建,代码块按需注册 bash、go、http、java、javascript、json、plaintext、python、sql、typescript、xml、yaml,无需额外加载 CDN。
194
194
 
195
195
  `pnpm dev` 后进入「正文预览」,可编辑 Markdown、切换窄屏和交互语言,检查代码复制、表格、提示块及划线评论组合。该示例未配置 webhook,评论只用于本地体验,不会发往反馈通道。
196
196
 
197
197
  消毒与正文 DOM 测试使用 jsdom:happy-dom 对当前 DOMPurify 的 DOM 遍历模拟不完整,不适合验证消毒结果。其它既有组件测试继续使用 happy-dom。
198
198
 
199
199
  发布前使用 `pnpm pack` 生成 tarball,在宿主项目安装该产物并检查类型、样式及运行效果;正式发布沿用 `prepublishOnly` 的测试与构建检查。
200
+
201
+ ## 公共导航与共享会话(0.1.6-beta.0)
202
+
203
+ 导航独立入口不引入 Element Plus 或正文组件的全局 CSS;首页只依赖 Vue 即可接入。
204
+
205
+ ```vue
206
+ <script setup lang="ts">
207
+ import { PortalNavigation } from "@wanlianyida/portal-kit/navigation";
208
+ import { createSharedSession } from "@wanlianyida/portal-kit/session";
209
+
210
+ const session = createSharedSession({
211
+ mode: import.meta.env.MODE,
212
+ loginUrl: import.meta.env.VITE_SSO_LOGIN_URL,
213
+ sysType: import.meta.env.VITE_SSO_SYS_TYPE,
214
+ });
215
+ // 初始化可先于导航挂载。session.watch 返回清理函数;订阅本身不会发请求或切换企业。
216
+ // 登录信息校验、路由守卫和企业切换继续由宿主业务适配器处理。
217
+ </script>
218
+
219
+ <template>
220
+ <PortalNavigation
221
+ home-url="/"
222
+ docs-url="/docs/"
223
+ console-url="/developer"
224
+ login-url="/developer"
225
+ theme="light"
226
+ locale="zh-CN"
227
+ :show-console-button="true"
228
+ :show-theme-switch="false"
229
+ :account="{ status: 'anonymous' }"
230
+ />
231
+ </template>
232
+ ```
233
+
234
+ - `theme`:`light` / `dark`,只设置导航主题;`update:theme` 交给宿主原有主题流程。
235
+ - `locale`:`zh-CN` / `en-US`,控制公共文案。`showLanguageSwitch` 默认 `false`,开启后通过 `language` 插槽接入宿主原有语言控件;翻译加载、偏好保存及失败处理均由宿主负责。
236
+ - `showConsoleButton`:默认 `true`;设为 `false` 同时隐藏桌面和移动菜单的控制台入口。
237
+ - `showThemeSwitch`:默认 `false`;`theme` 插槽保留原项目的主题按钮。
238
+ - `fixed` / `scrolled`:首页保留吸顶和滚动态;其他项目可按原布局接入。
239
+ - `account.status`:`anonymous` / `checking` / `authenticated` / `unavailable`,须根据登录信息接口确认;不能通过企业列表为空推断未登录。
240
+ - `account.enterpriseStatus`:`unknown` / `loading` / `available` / `empty` / `unavailable`。`empty` 保持已登录并显示账号名,不额外提示;`unavailable` 提供企业信息重试。企业名优先于账号名展示。
241
+ - `console` 插槽保留原有控制台按钮样式;`account-extension` 插槽接入 `NavigationEnterprises`,它只在用户选择时发出 `select(loginId)`,不会自行初始化或切换企业。
242
+ - `logout` / `retry` / `retry-enterprises` 由宿主处理;`docs-click(MouseEvent)` 可保留文档站内 SPA 跳转。
243
+
244
+ `createSharedSession` 统一根路径 Cookie、旧 Cookie 迁移、会话变化通知和 SSO 回跳地址。Token 只保存在 Cookie;localStorage 通知仅保存随机标记。所有应用必须使用同域名与相同 MODE,Cookie 为 Path=/、SameSite=Lax,HTTPS 使用 Secure,不扩大 Domain。
245
+
246
+ 控制台使用 `session.watch(callback, { focusedOnly: true })`,只在前台感知外部 Token 改变后重新进入既有认证流程;本页写入不会造成自身重复刷新。公开页面可使用 `revalidateOnFocus: true` 重新校验会话,保持匿名阅读。
package/dist/index.d.ts CHANGED
@@ -78,6 +78,23 @@ declare type __VLS_WithTemplateSlots_2<T, S> = T & {
78
78
 
79
79
  export declare function buildFeedbackPayload(input: FeedbackInput, now?: Date): FeedbackPayload;
80
80
 
81
+ /** 公共代码主题使用的 token 分组,供可编辑文本范围与预览 HTML 共用。 */
82
+ export declare const CODE_HIGHLIGHT_CLASSES: {
83
+ readonly comment: readonly ["hljs-comment", "hljs-quote"];
84
+ readonly keyword: readonly ["hljs-keyword", "hljs-doctag", "hljs-selector-tag"];
85
+ readonly attr: readonly ["hljs-attr", "hljs-attribute"];
86
+ readonly string: readonly ["hljs-string", "hljs-regexp", "hljs-template-tag"];
87
+ readonly number: readonly ["hljs-number"];
88
+ readonly literal: readonly ["hljs-literal", "hljs-symbol", "hljs-bullet"];
89
+ readonly title: readonly ["hljs-title", "hljs-section", "hljs-selector-id", "hljs-selector-class"];
90
+ readonly punctuation: readonly ["hljs-punctuation"];
91
+ readonly variable: readonly ["hljs-variable", "hljs-template-variable"];
92
+ readonly builtin: readonly ["hljs-built_in", "hljs-type"];
93
+ readonly tag: readonly ["hljs-name", "hljs-tag"];
94
+ readonly meta: readonly ["hljs-meta"];
95
+ readonly plain: readonly ["hljs-subst"];
96
+ };
97
+
81
98
  export declare const CodePreview: DefineComponent<CodePreviewProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<CodePreviewProps> & Readonly<{}>, {
82
99
  title: string;
83
100
  locale: string;
@@ -87,7 +104,7 @@ language: string;
87
104
  export declare interface CodePreviewProps {
88
105
  code: string;
89
106
  title?: string;
90
- /** 首期注册 JSON 高亮;其它语言保留原文展示。 */
107
+ /** 支持常见请求代码语言;为空或未注册时自动探测。 */
91
108
  language?: string;
92
109
  locale?: string;
93
110
  }
@@ -189,6 +206,12 @@ export declare interface HeadingSection {
189
206
  level: number;
190
207
  }
191
208
 
209
+ /**
210
+ * 对代码进行安全高亮。语言为空或未注册时使用 highlightAuto,失败则返回空串,
211
+ * 由组件用 Vue 插值安全展示原文。
212
+ */
213
+ export declare function highlightCode(code: string, language?: string): string;
214
+
192
215
  /** 只接受飞书 / Lark 的 https 地址,避免把企业名和页面路径发到任意域名。 */
193
216
  export declare function isFeishuWebhook(url: string): boolean;
194
217