labull-framework 0.1.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.
Files changed (43) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +82 -0
  3. package/dist/auth.d.ts +1 -0
  4. package/dist/auth.js +17 -0
  5. package/dist/chunk-_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  6. package/dist/chunk-index-BWpDbB19.js +129 -0
  7. package/dist/chunk-index-_jasBCim.js +526 -0
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.js +30 -0
  10. package/dist/magic-block.d.ts +1 -0
  11. package/dist/magic-block.js +1580 -0
  12. package/dist/style.css +1 -0
  13. package/dist/theme.d.ts +1 -0
  14. package/dist/theme.js +4 -0
  15. package/dist/types/auth-real.d.ts +60 -0
  16. package/dist/types/auth.d.ts +1 -0
  17. package/dist/types/index.d.ts +2 -0
  18. package/dist/types/magic-block-MagicBlockConsole.vue.d.ts +2 -0
  19. package/dist/types/magic-block-MagicBlockHost.vue.d.ts +21 -0
  20. package/dist/types/magic-block-bridge.d.ts +22 -0
  21. package/dist/types/magic-block-devkit.d.ts +15 -0
  22. package/dist/types/magic-block-instances.d.ts +34 -0
  23. package/dist/types/magic-block-localfs.d.ts +126 -0
  24. package/dist/types/magic-block-manifest.d.ts +64 -0
  25. package/dist/types/magic-block-preview.d.ts +11 -0
  26. package/dist/types/magic-block-real.d.ts +7 -0
  27. package/dist/types/magic-block-render.d.ts +12 -0
  28. package/dist/types/magic-block-theme.d.ts +33 -0
  29. package/dist/types/magic-block.d.ts +1 -0
  30. package/dist/types/theme.d.ts +3 -0
  31. package/dist/types/ui-AppSearch.vue.d.ts +2 -0
  32. package/dist/types/ui-ProductShell.vue.d.ts +31 -0
  33. package/dist/types/ui-ProductSide.vue.d.ts +14 -0
  34. package/dist/types/ui-ProductTabs.vue.d.ts +2 -0
  35. package/dist/types/ui-UserMenu.vue.d.ts +2 -0
  36. package/dist/types/ui-gate.d.ts +9 -0
  37. package/dist/types/ui-real.d.ts +16 -0
  38. package/dist/types/ui-tabs.d.ts +31 -0
  39. package/dist/types/ui-types.d.ts +20 -0
  40. package/dist/types/ui.d.ts +1 -0
  41. package/dist/ui.d.ts +1 -0
  42. package/dist/ui.js +15 -0
  43. package/package.json +67 -0
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Labull
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ 第三方组件(随本包分发的成品 CSS / 字形)各自的许可归其作者所有:
26
+
27
+ - PrimeVue 主题层(`Mira`)与 PrimeIcons 字形:搬入的成品 CSS,均为 MIT。
28
+ - 其余依赖(Django、PyJWT 等)按各自许可(BSD-3-Clause / MIT)分发,未做修改。
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # labull-framework
2
+
3
+ Labull 前端 SDK:把原来四个工作区包(`@labull/theme` / `@labull/auth` / `@labull/ui` /
4
+ `@labull/magic-block`)**打成一个包**发布。装一次就有四块,subpath 一个不少。
5
+
6
+ **产物是编译好的**(`dist/*.js` + `dist/*.d.ts` + `dist/style.css`),不需要你自己编译 `.vue`。
7
+
8
+ ## 装
9
+
10
+ ```bash
11
+ npm i labull-framework vue vue-router
12
+ ```
13
+
14
+ | peerDependency | 什么时候要 |
15
+ |---|---|
16
+ | `vue@^3.4` | **必装**(四块都依赖它) |
17
+ | `vue-router@^4.3` | 只有用 `labull-framework/ui` 或 `labull-framework/magic-block` 才要 |
18
+
19
+ 没有别的运行时依赖:PrimeVue 那套 `.p-*` 样式是**成品 CSS**(`dist/style.css` 里),
20
+ primeicons 的字库已内联成 `data:` URL —— 不用装 `primevue`、`primeicons` 或任何字体包。
21
+
22
+ ## 五分钟上手
23
+
24
+ ```ts
25
+ // main.ts
26
+ import { createApp } from 'vue'
27
+ import { createRouter, createWebHistory } from 'vue-router'
28
+ import { labull } from 'labull-framework' // 登录态 + 外壳
29
+ import 'labull-framework/style.css' // 主题 + 组件样式(一份就够)
30
+
31
+ const app = createApp(App)
32
+ app.use(createRouter({ history: createWebHistory(), routes })) // 🔴 必须排在 labull 之前
33
+ app.use(labull) // 注册全局组件 + 路由守卫
34
+ app.mount('#app')
35
+ ```
36
+
37
+ ```vue
38
+ <script setup lang="ts">
39
+ import { useAuth } from 'labull-framework/auth'
40
+ import { MagicBlockHost } from 'labull-framework/magic-block'
41
+
42
+ const { user, isStaff, logout } = useAuth()
43
+ </script>
44
+
45
+ <template>
46
+ <ProductShell>
47
+ <template #appbar><b>订单系统</b></template>
48
+ <MagicBlockHost uuid="6f1c…" />
49
+ </ProductShell>
50
+ </template>
51
+ ```
52
+
53
+ 后端地址走 `VITE_API_BASE`(默认 `http://localhost:3000`)。
54
+
55
+ ## subpath 对照表(原包 → 现在怎么 import)
56
+
57
+ | 原来 | 现在 | 内容 |
58
+ |---|---|---|
59
+ | `@labull/theme` | `labull-framework/style.css`(或 `labull-framework/theme`) | `--sp-*` token + 完整主题层 + 结构类 + primeicons |
60
+ | `@labull/auth` | `labull-framework/auth` | `useAuth()` / `apiFetch()` / `ensureAuthenticated()` / `createAuthGate()` / `API_BASE` |
61
+ | `@labull/ui` | `labull-framework/ui` | `ProductShell` / `ProductSide` / `ProductTabs` / `AppSearch` / `UserMenu` / `labull` 插件 |
62
+ | `@labull/magic-block` | `labull-framework/magic-block` | `MagicBlockHost` / `MagicBlockConsole` / 清单校验 / bridge |
63
+
64
+ 根入口 `labull-framework` = `auth` + `ui`(最常用的两层)。
65
+
66
+ 🔴 **它故意不 re-export `magic-block`**:`magic-block` 与 `auth` 都导出 `API_BASE`,
67
+ 两路 `export *` 撞同一个名字是打包器层面的歧义。要块就从 `labull-framework/magic-block` 拿。
68
+
69
+ ## 两份东西要知道
70
+
71
+ - 🔴 **前端不做授权**:`isStaff` / `groups` / `permissions` 只是界面显隐,判据全在后端。
72
+ - 🔴 **单例只有一份**:`auth` 的状态是模块级单例,`ui` 与 `magic-block` 共用同一份
73
+ (产物里共享代码在 `dist/chunk-*.js`,不是各拷贝一份)—— 所以"用户菜单说登录了、
74
+ 宿主说没登录"这种事不会发生。
75
+
76
+ ## 样式说明
77
+
78
+ `dist/style.css` 是**完整层**(≈478 KB,gzip ≈91 KB):token + PrimeVue 主题层 + `.labull-*`
79
+ 结构类 + shell + 组件样式 + 内联 primeicons。
80
+
81
+ 单包方案里**没有**"只要 token、不要那 450 KB 主题层"的入口(原来 `@labull/theme` 分两层,
82
+ 现在只有一份)。真要精简,就在应用里覆盖 `--sp-*` 变量、不引 `style.css` 而自己写需要的部分。
package/dist/auth.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/auth'
package/dist/auth.js ADDED
@@ -0,0 +1,17 @@
1
+ import { A as s, a as t, C as r, b as u, c as A, d as c, e as h, f as i, g as n, h as E, l as o, i as S, j as _, u as l } from "./chunk-index-BWpDbB19.js";
2
+ export {
3
+ s as API_BASE,
4
+ t as AUTH_DEADLINE_MS,
5
+ r as CLEAR_SESSION_DEADLINE_MS,
6
+ u as apiFetch,
7
+ A as authHeaders,
8
+ c as createAuthGate,
9
+ h as currentPath,
10
+ i as currentUser,
11
+ n as currentUserInTime,
12
+ E as ensureAuthenticated,
13
+ o as loginUrl,
14
+ S as loginWithRedirect,
15
+ _ as logout,
16
+ l as useAuth
17
+ };
@@ -0,0 +1,9 @@
1
+ const s = (t, r) => {
2
+ const o = t.__vccOpts || t;
3
+ for (const [c, e] of r)
4
+ o[c] = e;
5
+ return o;
6
+ };
7
+ export {
8
+ s as _
9
+ };
@@ -0,0 +1,129 @@
1
+ import { ref as c, computed as T } from "vue";
2
+ const l = "http://localhost:3000", h = 8e3, C = 1500, y = "labull.csrf", P = "x-labull-csrf", $ = ["GET", "HEAD", "OPTIONS"], u = c(null);
3
+ function v(t) {
4
+ for (const e of (typeof document > "u" ? "" : document.cookie).split(";")) {
5
+ const [n, ...s] = e.trim().split("=");
6
+ if (n === t) return s.join("=");
7
+ }
8
+ return "";
9
+ }
10
+ function m(t = "GET", e = !1) {
11
+ const n = e ? { "Content-Type": "application/json" } : {}, s = v(y);
12
+ return s && !$.includes(t.toUpperCase()) && (n[P] = s), n;
13
+ }
14
+ async function E(t, e = {}) {
15
+ const n = String(e.method ?? "GET").toUpperCase(), s = await fetch(`${l}${t}`, {
16
+ ...e,
17
+ method: n,
18
+ credentials: "include",
19
+ headers: { ...m(n, e.body !== void 0), ...e.headers ?? {} }
20
+ });
21
+ if (!s.ok) {
22
+ const o = await s.json().catch(() => null), a = typeof o?.message == "string" ? o.message : "";
23
+ throw Object.assign(new Error(a || `请求失败:${s.status} ${t}`), { status: s.status });
24
+ }
25
+ return s.status === 204 ? void 0 : await s.json();
26
+ }
27
+ function f() {
28
+ if (typeof window > "u") return "/";
29
+ const t = window.location, e = `${t.pathname}${t.search}`;
30
+ return e.startsWith("/") && !e.startsWith("//") ? e : "/";
31
+ }
32
+ function O(t = f()) {
33
+ const e = t.startsWith("/") && !t.startsWith("//") ? t : "/";
34
+ return `${l}/auth/login?redirect=${encodeURIComponent(e)}`;
35
+ }
36
+ function w(t = f()) {
37
+ window.location.assign(O(t));
38
+ }
39
+ function _() {
40
+ u.value = null, window.location.assign(`${l}/auth/logout`);
41
+ }
42
+ async function b() {
43
+ try {
44
+ const t = await E("/auth/me");
45
+ return u.value = t, t;
46
+ } catch (t) {
47
+ const e = t?.status;
48
+ return (e === 401 || e === 403) && await Promise.race([
49
+ fetch(`${l}/auth/logout`, { method: "POST", credentials: "include", headers: m("POST", !0) }).catch(() => {
50
+ }),
51
+ new Promise((n) => setTimeout(n, C))
52
+ ]), u.value = null, null;
53
+ }
54
+ }
55
+ async function p(t = h) {
56
+ let e;
57
+ const n = new Promise((s) => {
58
+ e = setTimeout(() => s("timeout"), t);
59
+ });
60
+ try {
61
+ return await Promise.race([b(), n]);
62
+ } finally {
63
+ e !== void 0 && clearTimeout(e);
64
+ }
65
+ }
66
+ async function U(t = f(), e = h) {
67
+ const n = await p(e);
68
+ return n !== "timeout" && n ? n : (n !== "timeout" && w(t), null);
69
+ }
70
+ function D(t = {}) {
71
+ const e = t.deadlineMs ?? h, n = c(!1), s = c(!1), o = c(!1);
72
+ let a = null, d = !1;
73
+ async function S(r) {
74
+ const i = await p(e);
75
+ if (i !== "timeout" && i) {
76
+ d = !0, s.value = !1, o.value = !1, n.value = !0;
77
+ return;
78
+ }
79
+ if (n.value = !1, s.value = !0, o.value = i === "timeout", i !== "timeout")
80
+ try {
81
+ w(r);
82
+ } catch {
83
+ console.warn("[labull] 整页跳登录没成功;界面上的手动登录链接还在。");
84
+ }
85
+ }
86
+ function g(r) {
87
+ return d ? Promise.resolve() : a || (a = S(r).finally(() => {
88
+ a = null;
89
+ }), a);
90
+ }
91
+ function A(r) {
92
+ d = !1, n.value = !1, g(r);
93
+ }
94
+ return { open: n, denied: s, unreachable: o, pass: g, recheck: A };
95
+ }
96
+ function R() {
97
+ async function t() {
98
+ const e = await p();
99
+ return e === "timeout" ? null : e;
100
+ }
101
+ return {
102
+ user: u,
103
+ isStaff: T(() => u.value?.isStaff === !0),
104
+ /** 🔴 只是界面提示位(本地读得到 CSRF cookie 就算),**不是授权判据**:要挡就在后端挡。 */
105
+ isAuthenticated: () => v(y) !== "",
106
+ refresh: t,
107
+ apiFetch: E,
108
+ authHeaders: m,
109
+ currentPath: f,
110
+ login: w,
111
+ logout: _
112
+ };
113
+ }
114
+ export {
115
+ l as A,
116
+ C,
117
+ h as a,
118
+ E as b,
119
+ m as c,
120
+ D as d,
121
+ f as e,
122
+ b as f,
123
+ p as g,
124
+ U as h,
125
+ w as i,
126
+ _ as j,
127
+ O as l,
128
+ R as u
129
+ };