@lark-apaas/client-toolkit 1.1.19 → 1.1.20-antd-test.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.
@@ -0,0 +1,4 @@
1
+ import { Table } from 'antd';
2
+ import type { TableProps } from 'antd';
3
+ export { Table };
4
+ export type { TableProps };
@@ -0,0 +1,2 @@
1
+ import { Table } from "antd";
2
+ export { Table };
@@ -1,5 +1,6 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useEffect } from "react";
2
+ import { useEffect, useState } from "react";
3
+ import { ConfigProvider } from "antd";
3
4
  import { MiaodaInspector } from "@lark-apaas/miaoda-inspector";
4
5
  import IframeBridge from "./IframeBridge.js";
5
6
  import { defaultUIConfig } from "../theme/ui-config.js";
@@ -14,6 +15,15 @@ import safety from "./safety.js";
14
15
  registerDayjsPlugins();
15
16
  initAxiosConfig();
16
17
  const isMiaodaPreview = window.IS_MIAODA_PREVIEW;
18
+ const readCssVarColor = (varName, fallback)=>{
19
+ try {
20
+ if ('undefined' == typeof document) return fallback;
21
+ const value = getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
22
+ return value || fallback;
23
+ } catch {
24
+ return fallback;
25
+ }
26
+ };
17
27
  const App = (props)=>{
18
28
  const { themeMeta = {} } = props;
19
29
  useAppInfo();
@@ -54,17 +64,139 @@ const App = (props)=>{
54
64
  ]
55
65
  });
56
66
  };
57
- const AppContainer = (props)=>{
67
+ const AppContainer_AppContainer = (props)=>{
58
68
  const { children, ...rest } = props;
69
+ const [cssColors, setCssColors] = useState(()=>({
70
+ background: readCssVarColor('--background'),
71
+ destructive: readCssVarColor('--destructive'),
72
+ primary: readCssVarColor('--primary'),
73
+ foreground: readCssVarColor('--foreground'),
74
+ warning: readCssVarColor('--warning'),
75
+ success: readCssVarColor('--success'),
76
+ muted: readCssVarColor('--muted'),
77
+ mutedForeground: readCssVarColor('--muted-foreground'),
78
+ border: readCssVarColor('--border'),
79
+ popover: readCssVarColor('--popover'),
80
+ accent: readCssVarColor('--accent')
81
+ }));
82
+ useEffect(()=>{
83
+ if ('production' === process.env.NODE_ENV) return ()=>{};
84
+ const observer = new MutationObserver((mutations)=>{
85
+ for (const mutation of mutations){
86
+ let linkTag = null;
87
+ if ('attributes' === mutation.type) {
88
+ if ('fullstack-nestjs-template:chunk-main' === mutation.target.dataset.webpack) linkTag = mutation.target;
89
+ } else if ('childList' === mutation.type) {
90
+ for (const node of Array.from(mutation.addedNodes))if ('LINK' === node.nodeName && 'fullstack-nestjs-template:chunk-main' === node.dataset.webpack) {
91
+ linkTag = node;
92
+ break;
93
+ }
94
+ }
95
+ if (linkTag) {
96
+ let retryCount = 0;
97
+ const maxRetries = 10;
98
+ const retryDelay = 400;
99
+ const updateColors = ()=>{
100
+ const newColors = {
101
+ background: readCssVarColor('--background'),
102
+ destructive: readCssVarColor('--destructive'),
103
+ primary: readCssVarColor('--primary'),
104
+ foreground: readCssVarColor('--foreground'),
105
+ warning: readCssVarColor('--warning'),
106
+ success: readCssVarColor('--success'),
107
+ muted: readCssVarColor('--muted'),
108
+ mutedForeground: readCssVarColor('--muted-foreground'),
109
+ border: readCssVarColor('--border'),
110
+ popover: readCssVarColor('--popover'),
111
+ accent: readCssVarColor('--accent')
112
+ };
113
+ setCssColors((currentColors)=>{
114
+ if (JSON.stringify(currentColors) !== JSON.stringify(newColors)) {
115
+ retryCount = 0;
116
+ return newColors;
117
+ }
118
+ if (retryCount < maxRetries) {
119
+ retryCount++;
120
+ setTimeout(updateColors, retryDelay);
121
+ }
122
+ return currentColors;
123
+ });
124
+ };
125
+ setTimeout(updateColors, 100);
126
+ }
127
+ }
128
+ });
129
+ observer.observe(document.head, {
130
+ childList: true,
131
+ subtree: true,
132
+ attributes: true,
133
+ attributeFilter: [
134
+ 'href'
135
+ ]
136
+ });
137
+ return ()=>{
138
+ observer.disconnect();
139
+ };
140
+ }, []);
141
+ const antdThemeToken = {
142
+ colorBgBase: cssColors.background,
143
+ colorError: cssColors.destructive,
144
+ colorInfo: cssColors.primary,
145
+ colorLink: cssColors.primary,
146
+ colorPrimary: cssColors.primary,
147
+ colorSuccess: cssColors.primary,
148
+ colorTextBase: cssColors.foreground,
149
+ colorWarning: cssColors.destructive
150
+ };
151
+ const antdTableToken = {
152
+ bodySortBg: cssColors.muted,
153
+ borderColor: cssColors.border,
154
+ expandIconBg: cssColors.background,
155
+ filterDropdownBg: cssColors.popover,
156
+ filterDropdownMenuBg: cssColors.popover,
157
+ fixedHeaderSortActiveBg: cssColors.muted,
158
+ footerBg: cssColors.muted,
159
+ footerColor: cssColors.mutedForeground,
160
+ headerBg: cssColors.muted,
161
+ headerColor: cssColors.mutedForeground,
162
+ headerFilterHoverBg: cssColors.muted,
163
+ headerSortActiveBg: cssColors.muted,
164
+ headerSortHoverBg: cssColors.muted,
165
+ headerSplitColor: cssColors.border,
166
+ rowExpandedBg: cssColors.background,
167
+ rowHoverBg: cssColors.muted,
168
+ rowSelectedBg: cssColors.accent,
169
+ rowSelectedHoverBg: cssColors.accent,
170
+ stickyScrollBarBg: cssColors.muted
171
+ };
172
+ const antdPaginationToken = {
173
+ itemActiveBg: cssColors.background,
174
+ itemActiveBgDisabled: cssColors.muted,
175
+ itemActiveColor: cssColors.primary,
176
+ itemActiveColorDisabled: cssColors.muted,
177
+ itemActiveColorHover: cssColors.muted,
178
+ itemBg: cssColors.background,
179
+ itemInputBg: cssColors.background,
180
+ itemLinkBg: cssColors.background
181
+ };
59
182
  return /*#__PURE__*/ jsxs(Fragment, {
60
183
  children: [
61
184
  /*#__PURE__*/ jsx(safety, {}),
62
- /*#__PURE__*/ jsx(App, {
63
- themeMeta: props.themeMeta,
64
- children: children
185
+ /*#__PURE__*/ jsx(ConfigProvider, {
186
+ theme: {
187
+ token: antdThemeToken,
188
+ components: {
189
+ Table: antdTableToken,
190
+ Pagination: antdPaginationToken
191
+ }
192
+ },
193
+ children: /*#__PURE__*/ jsx(App, {
194
+ themeMeta: props.themeMeta,
195
+ children: children
196
+ })
65
197
  })
66
198
  ]
67
199
  });
68
200
  };
69
- const components_AppContainer = AppContainer;
70
- export { components_AppContainer as default };
201
+ const AppContainer = AppContainer_AppContainer;
202
+ export { AppContainer as default };
@@ -152,7 +152,7 @@ const Component = ()=>{
152
152
  /*#__PURE__*/ jsx(PopoverTrigger, {
153
153
  asChild: true,
154
154
  children: /*#__PURE__*/ jsxs("div", {
155
- className: "fixed right-3 bottom-3 inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-2.5 py-1.5 bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-md text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000] cursor-pointer",
155
+ className: "fixed right-3 bottom-3 inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-2.5 py-1.5 bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-[6px] text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000] cursor-pointer",
156
156
  onMouseEnter: ()=>{
157
157
  clearTimeout(timeoutRef.current);
158
158
  setOpen(true);
@@ -173,7 +173,7 @@ const Component = ()=>{
173
173
  })
174
174
  }),
175
175
  /*#__PURE__*/ jsx(PopoverContent, {
176
- className: "overflow-hidden p-0 m-0 border-0 rounded-xl!",
176
+ className: "overflow-hidden p-0 m-0 border-0 rounded-[12px]!",
177
177
  style: {
178
178
  boxShadow: '0 6px 12px 0 #41444a0a, 0 8px 24px 0 #41444a0a'
179
179
  },
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  declare const RenderError: React.FC<{
3
3
  error: Error;
4
+ resetErrorBoundary?: () => void;
4
5
  }>;
5
6
  export default RenderError;
@@ -1,10 +1,11 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect } from "react";
3
3
  import { logger } from "../../logger/index.js";
4
+ import { createApplyHandle, getModuleHot } from "../../utils/module-hot.js";
4
5
  const RenderError = (props)=>{
5
- const { error } = props;
6
+ const { error, resetErrorBoundary } = props;
6
7
  useEffect(()=>{
7
- if (props.error) logger.log({
8
+ if (error) logger.log({
8
9
  level: 'error',
9
10
  args: [
10
11
  'Render Error',
@@ -15,7 +16,22 @@ const RenderError = (props)=>{
15
16
  }
16
17
  });
17
18
  }, [
18
- props.error
19
+ error
20
+ ]);
21
+ useEffect(()=>{
22
+ if (!resetErrorBoundary) return;
23
+ const hot = getModuleHot();
24
+ if (hot) {
25
+ const handler = createApplyHandle((success)=>{
26
+ if (success) resetErrorBoundary();
27
+ });
28
+ hot.addStatusHandler(handler);
29
+ return ()=>{
30
+ hot.removeStatusHandler(handler);
31
+ };
32
+ }
33
+ }, [
34
+ resetErrorBoundary
19
35
  ]);
20
36
  return /*#__PURE__*/ jsx("div", {
21
37
  className: "min-h-screen flex items-center justify-center bg-white",
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const badgeVariants: (props?: {
4
- variant?: "default" | "secondary" | "destructive" | "outline";
4
+ variant?: "default" | "destructive" | "secondary" | "outline";
5
5
  } & import("class-variance-authority/dist/types").ClassProp) => string;
6
6
  declare function Badge({ className, variant, asChild, ...props }: React.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & {
7
7
  asChild?: boolean;
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const buttonVariants: (props?: {
4
- variant?: "default" | "link" | "secondary" | "destructive" | "outline" | "ghost";
4
+ variant?: "default" | "link" | "destructive" | "secondary" | "outline" | "ghost";
5
5
  size?: "default" | "icon" | "sm" | "lg" | "icon-sm" | "icon-lg";
6
6
  } & import("class-variance-authority/dist/types").ClassProp) => string;
7
7
  declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
@@ -1,3 +1,4 @@
1
+ import { createApplyHandle, getModuleHot } from "../utils/module-hot.js";
1
2
  import { submitPostMessage, submitSlardarEvent } from "../utils/postMessage.js";
2
3
  import { levelSchema } from "./log-types.js";
3
4
  import { logger } from "./logger.js";
@@ -61,10 +62,17 @@ function processDevServerLog(log) {
61
62
  });
62
63
  }
63
64
  }
64
- function listenHmrApplyFailed() {
65
- const hot = import.meta.webpackHot || module.hot;
66
- if (hot) hot.addStatusHandler((status)=>{
67
- if ('fail' === status || 'abort' === status) {
65
+ function listenModuleHmr() {
66
+ const hot = getModuleHot();
67
+ if (hot) hot.addStatusHandler(createApplyHandle((success, status)=>{
68
+ if (success) submitPostMessage({
69
+ type: 'DevServerMessage',
70
+ data: {
71
+ type: 'devServer-status',
72
+ status: 'hmr-apply-success'
73
+ }
74
+ });
75
+ else {
68
76
  console.warn('hmr apply failed', status);
69
77
  submitSlardarEvent({
70
78
  name: 'sandbox-devServer',
@@ -74,7 +82,7 @@ function listenHmrApplyFailed() {
74
82
  }
75
83
  });
76
84
  }
77
- });
85
+ }));
78
86
  }
79
87
  function interceptErrors() {
80
88
  window.addEventListener('error', (event)=>{
@@ -83,7 +91,7 @@ function interceptErrors() {
83
91
  window.addEventListener('unhandledrejection', (event)=>{
84
92
  logger.error(event.reason);
85
93
  });
86
- listenHmrApplyFailed();
94
+ listenModuleHmr();
87
95
  const PROXY_CONSOLE_METHOD = [
88
96
  'log',
89
97
  'info',
@@ -41,7 +41,7 @@ export interface HmrMessage extends IframeMessage<Record<string, never>> {
41
41
  /** devServer相关消息 */
42
42
  export interface DevServerMessage extends IframeMessage<{
43
43
  type: 'devServer-status';
44
- status: 'connected' | 'disconnected';
44
+ status: 'connected' | 'disconnected' | 'hmr-apply-success';
45
45
  }> {
46
46
  type: 'DevServerMessage';
47
47
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Module Hot Replacement 状态类型定义
3
+ *
4
+ * - idle: The process is waiting for a call to check
5
+ * - check: The process is checking for updates
6
+ * - prepare: The process is getting ready for the update (e.g. downloading the updated module)
7
+ * - ready: The update is prepared and available
8
+ * - dispose: The process is calling the dispose handlers on the modules that will be replaced
9
+ * - apply: The process is calling the accept handlers and re-executing self-accepted modules
10
+ * - abort: An update was aborted, but the system is still in its previous state
11
+ * - fail: An update has thrown an exception and the system's state has been compromised
12
+ */
13
+ type ModuleHotType = 'idle' | 'check' | 'prepare' | 'ready' | 'dispose' | 'apply' | 'abort' | 'fail';
14
+ interface ModuleHotInstance {
15
+ addStatusHandler: (handler: (status: ModuleHotType) => void) => void;
16
+ removeStatusHandler: (handler: (status: ModuleHotType) => void) => void;
17
+ }
18
+ export declare function getModuleHot(): ModuleHotInstance | null;
19
+ /**
20
+ * 创建模块热更成功处理函数
21
+ * 监听模块热更状态,当状态为apply时,调用回调函数并传入true
22
+ * @param callback 热更成功回调函数,参数为是否成功
23
+ */
24
+ export declare function createApplyHandle(callback: (success: boolean, status: ModuleHotType) => void): (status: ModuleHotType) => void;
25
+ export {};
@@ -0,0 +1,22 @@
1
+ function getModuleHot() {
2
+ if ('production' === process.env.NODE_ENV) return null;
3
+ return import.meta.webpackHot || module.hot;
4
+ }
5
+ function createApplyHandle(callback) {
6
+ let hasApply = false;
7
+ return (status)=>{
8
+ if ('fail' === status || 'abort' === status) {
9
+ hasApply = false;
10
+ return callback(false, status);
11
+ }
12
+ if (hasApply) {
13
+ if ('idle' === status) {
14
+ hasApply = false;
15
+ callback(true, status);
16
+ }
17
+ return;
18
+ }
19
+ hasApply = 'apply' === status;
20
+ };
21
+ }
22
+ export { createApplyHandle, getModuleHot };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.1.19",
3
+ "version": "1.1.20-antd-test.0",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -15,6 +15,11 @@
15
15
  "require": "./lib/index.js",
16
16
  "types": "./lib/index.d.ts"
17
17
  },
18
+ "./antd-table": {
19
+ "import": "./lib/antd-table.js",
20
+ "require": "./lib/antd-table.js",
21
+ "types": "./lib/antd-table.d.ts"
22
+ },
18
23
  "./lib/index.css": "./lib/index.css",
19
24
  "./dataloom": {
20
25
  "import": "./lib/apis/dataloom.js",