@fe-free/core 2.8.13 → 2.8.15

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,19 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 2.8.15
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: data viewer
8
+ - @fe-free/tool@2.8.15
9
+
10
+ ## 2.8.14
11
+
12
+ ### Patch Changes
13
+
14
+ - fix: PageLayout
15
+ - @fe-free/tool@2.8.14
16
+
3
17
  ## 2.8.13
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "2.8.13",
3
+ "version": "2.8.15",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -41,7 +41,7 @@
41
41
  "safe-stable-stringify": "^2.5.0",
42
42
  "vanilla-jsoneditor": "^0.23.1",
43
43
  "zustand": "^4.5.4",
44
- "@fe-free/tool": "2.8.13"
44
+ "@fe-free/tool": "2.8.15"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
@@ -31,7 +31,7 @@ export const Basic: Story = {
31
31
 
32
32
  export const ForJSON: Story = {
33
33
  args: {
34
- data: JSON.stringify({ action: 'hello', data: 'world' }, null, 2),
34
+ data: JSON.stringify({ action: 'hello', data: 'world' }),
35
35
  },
36
36
  render: (props) => <BasicDemo {...props} />,
37
37
  };
@@ -1,6 +1,6 @@
1
1
  import { ArrowsAltOutlined } from '@ant-design/icons';
2
2
  import { Button, Modal, Select } from 'antd';
3
- import { useState } from 'react';
3
+ import { useMemo, useState } from 'react';
4
4
  import { Editor } from '../editor';
5
5
  import { PageLayout } from '../page_layout';
6
6
 
@@ -24,6 +24,18 @@ function DataViewer({ data, title, enableMaximize }: DataViewerProps) {
24
24
  options[0].value as DataViewerLanguage,
25
25
  );
26
26
 
27
+ const value = useMemo(() => {
28
+ try {
29
+ if (language === 'json') {
30
+ return JSON.stringify(JSON.parse(data), null, 2);
31
+ }
32
+ return data;
33
+ } catch (err) {
34
+ console.error(err);
35
+ return data;
36
+ }
37
+ }, [data, language]);
38
+
27
39
  return (
28
40
  <>
29
41
  <PageLayout
@@ -34,7 +46,7 @@ function DataViewer({ data, title, enableMaximize }: DataViewerProps) {
34
46
  <Select
35
47
  options={options}
36
48
  value={language}
37
- onChange={(value) => setLanguage(value)}
49
+ onChange={(v) => setLanguage(v)}
38
50
  className="w-[110px]"
39
51
  />
40
52
  {enableMaximize && (
@@ -45,7 +57,7 @@ function DataViewer({ data, title, enableMaximize }: DataViewerProps) {
45
57
  >
46
58
  <div className="relative h-full">
47
59
  <Editor
48
- value={data}
60
+ value={value}
49
61
  language={language === 'text' ? undefined : language}
50
62
  editable={false}
51
63
  />
@@ -55,7 +67,7 @@ function DataViewer({ data, title, enableMaximize }: DataViewerProps) {
55
67
  <Modal title="查看" open width={'80vw'} onCancel={() => setMaximize(false)} footer={null}>
56
68
  <div className="h-[80vh]">
57
69
  <Editor
58
- value={data}
70
+ value={value}
59
71
  language={language === 'text' ? undefined : language}
60
72
  editable={false}
61
73
  />
@@ -52,19 +52,17 @@ function PageLayout({
52
52
  {start}
53
53
  </div>
54
54
  )}
55
- {children && (
56
- <div
57
- className={classNames(
58
- 'flex-1 overflow-auto',
59
- {
60
- 'min-w-0 flex-shrink-0': equalParts,
61
- },
62
- childrenClassName,
63
- )}
64
- >
65
- {children}
66
- </div>
67
- )}
55
+ <div
56
+ className={classNames(
57
+ 'flex-1 overflow-auto',
58
+ {
59
+ 'min-w-0 flex-shrink-0': equalParts,
60
+ },
61
+ childrenClassName,
62
+ )}
63
+ >
64
+ {children}
65
+ </div>
68
66
  {end && (
69
67
  <div
70
68
  className={classNames(