bi-sdk-react 0.0.8 → 0.0.10

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 (30) hide show
  1. package/dist/es/js/bi-sdk.es.js +14 -10
  2. package/dist/types/components/context/PageContext.d.ts +18 -0
  3. package/dist/types/components/index.d.ts +2 -2
  4. package/dist/types/components/plugins/@antd/item-props/HtmlProps.d.ts +1 -0
  5. package/dist/types/components/plugins/@antd/items/HtmlRender.d.ts +1 -0
  6. package/dist/types/components/utils.d.ts +1 -0
  7. package/dist/umd/js/bi-sdk.umd.min.js +13 -9
  8. package/package.json +1 -1
  9. package/src/components/PageDesigner.tsx +4 -4
  10. package/src/components/context/{DesignerContext.tsx → PageContext.tsx} +8 -8
  11. package/src/components/dnd/DropContainer.tsx +2 -2
  12. package/src/components/index.ts +3 -2
  13. package/src/components/layout/PageCanvas.tsx +2 -2
  14. package/src/components/layout/PageItem.tsx +2 -2
  15. package/src/components/panel/AiPanel.tsx +30 -22
  16. package/src/components/panel/CascadePanel.tsx +2 -2
  17. package/src/components/panel/CodePanel.tsx +2 -2
  18. package/src/components/panel/ComponentPanel.tsx +2 -2
  19. package/src/components/panel/DatasourcePanel.tsx +2 -2
  20. package/src/components/panel/LayerPanel.tsx +2 -2
  21. package/src/components/panel/PropertiesPanel.tsx +2 -2
  22. package/src/components/panel/ScriptPanel.tsx +2 -2
  23. package/src/components/panel/VariablesPanel.tsx +2 -2
  24. package/src/components/plugins/@antd/item-props/HtmlProps.tsx +13 -5
  25. package/src/components/plugins/@antd/items/CardRender.tsx +1 -1
  26. package/src/components/plugins/@antd/items/ColRender.tsx +2 -2
  27. package/src/components/plugins/@antd/items/HtmlRender.tsx +3 -1
  28. package/src/components/plugins/@antd/items/RowRender.tsx +2 -2
  29. package/src/components/plugins/@antd/items/SpaceRender.tsx +2 -2
  30. package/src/components/utils.ts +19 -3
@@ -18,7 +18,7 @@ import {
18
18
  } from "antd";
19
19
  import React, { useContext, useMemo, useState } from "react";
20
20
  import styled from "styled-components";
21
- import { DesignerContext } from "../context/DesignerContext";
21
+ import { PageContext } from "../context/PageContext";
22
22
  import { IconFont } from "../icon/IconFont";
23
23
  import { PaneHeader } from "./PaneHeader";
24
24
  import { uuid } from "../utils";
@@ -64,7 +64,7 @@ const Root = styled.div`
64
64
  `;
65
65
 
66
66
  export const DatasourcePanel: React.FC = () => {
67
- const { schema, setSchema } = useContext(DesignerContext);
67
+ const { schema, setSchema } = useContext(PageContext);
68
68
 
69
69
  const [apiVisible, setApiVisible] = useState(false);
70
70
  const [sqlVisible, setSqlVisible] = useState(false);
@@ -2,7 +2,7 @@ import { MinusSquareOutlined, PlusSquareOutlined } from "@ant-design/icons";
2
2
  import { Space, Tooltip, Tree } from "antd";
3
3
  import React, { useContext, useMemo, useState } from "react";
4
4
  import styled from "styled-components";
5
- import { DesignerContext } from "../context/DesignerContext";
5
+ import { PageContext } from "../context/PageContext";
6
6
  import { uuid } from "../utils";
7
7
  import { PaneHeader } from "./PaneHeader";
8
8
 
@@ -39,7 +39,7 @@ export const LayerPanel: React.FC = () => {
39
39
  selectedItem,
40
40
  setSelectedItem: onSelect,
41
41
  plugins,
42
- } = useContext(DesignerContext);
42
+ } = useContext(PageContext);
43
43
  const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
44
44
  const selectedKeys = useMemo(
45
45
  () => (selectedItem ? [selectedItem.id!] : []),
@@ -19,7 +19,7 @@ import {
19
19
  } from "antd";
20
20
  import React, { useContext, useMemo, useRef, useState } from "react";
21
21
  import styled from "styled-components";
22
- import { DesignerContext } from "../context/DesignerContext";
22
+ import { PageContext } from "../context/PageContext";
23
23
  import { IconFont } from "../icon/IconFont";
24
24
  import { PaneHeader } from "./PaneHeader";
25
25
  import { DataSetOutput, SchemaItemType, FieldType } from "../typing";
@@ -82,7 +82,7 @@ export const PropertiesPanel: React.FC<{
82
82
  schema,
83
83
  setSchema,
84
84
  datasetSelector,
85
- } = useContext(DesignerContext);
85
+ } = useContext(PageContext);
86
86
  const refCustomDatasource = useRef<any>(null);
87
87
  const [selectedTab, setSelectedTab] = useState<"1" | "2">("1");
88
88
  const items = useMemo(() => computeItems(schema?.items || []), [schema]);
@@ -5,7 +5,7 @@ import { PaneHeader } from "./PaneHeader";
5
5
  import styled from "styled-components";
6
6
  import { IconFont } from "../icon/IconFont";
7
7
  import { DeleteOutlined, EditOutlined } from "@ant-design/icons";
8
- import { DesignerContext } from "../context/DesignerContext";
8
+ import { PageContext } from "../context/PageContext";
9
9
  import { ScriptItem } from "../typing";
10
10
 
11
11
 
@@ -51,7 +51,7 @@ const Root = styled.div`
51
51
  `;
52
52
 
53
53
  export const ScriptPanel: React.FC = () => {
54
- const {schema, setSchema} = useContext(DesignerContext);
54
+ const {schema, setSchema} = useContext(PageContext);
55
55
  const [visible, setVisible] = React.useState(false);
56
56
  const [editIndex, setEditIndex] = React.useState(-1);
57
57
  const [form] = Form.useForm<ScriptItem>();
@@ -4,7 +4,7 @@ import { Table, Button, Space, Popconfirm, Modal, Form, Input } from "antd";
4
4
  import { PaneHeader } from "./PaneHeader";
5
5
  import { DeleteOutlined, EditOutlined } from "@ant-design/icons";
6
6
  import { IconFont } from "../icon/IconFont";
7
- import { DesignerContext } from "../context/DesignerContext";
7
+ import { PageContext } from "../context/PageContext";
8
8
  import { VariableItem } from "../typing";
9
9
 
10
10
 
@@ -22,7 +22,7 @@ const Root = styled.div`
22
22
  `;
23
23
 
24
24
  export const VariablesPanel: React.FC = () => {
25
- const {schema, setSchema} = useContext(DesignerContext);
25
+ const {schema, setSchema} = useContext(PageContext);
26
26
  const [visible, setVisible] = React.useState(false);
27
27
  const [editIndex, setEditIndex] = React.useState(-1);
28
28
  const [form] = Form.useForm<VariableItem>();
@@ -1,18 +1,18 @@
1
1
  import React, { useRef } from "react";
2
- import { Form } from "antd";
2
+ import { Form, Select } from "antd";
3
3
  import Editor from "@monaco-editor/react";
4
4
  import type { PropEditorProps } from "./types";
5
5
  import { IconFont } from "../../../icon/IconFont";
6
6
 
7
- export type HtmlModel = { template: string };
7
+ export type HtmlModel = { template: string; classNames?: string[] };
8
8
 
9
9
  export const HtmlProps: React.FC<PropEditorProps<HtmlModel>> = ({
10
10
  model,
11
11
  onChange,
12
12
  }) => {
13
13
  const ref = useRef<any>(null);
14
- const setTemplate = (v?: string) =>
15
- onChange && onChange({ ...model, template: v || "" });
14
+ const triggerModel = (key: keyof HtmlModel, value: any) =>
15
+ onChange && onChange({ ...model, [key]: value });
16
16
  const format = () => {
17
17
  const editor = (ref.current as any)?.editor;
18
18
  editor?.getAction("editor.action.formatDocument")?.run();
@@ -20,6 +20,14 @@ export const HtmlProps: React.FC<PropEditorProps<HtmlModel>> = ({
20
20
  return (
21
21
  <div>
22
22
  <Form layout="vertical">
23
+ <Form.Item label="类名">
24
+ <Select
25
+ size="small"
26
+ value={model.classNames}
27
+ mode="tags"
28
+ onChange={(value) => triggerModel("classNames", value)}
29
+ />
30
+ </Form.Item>
23
31
  <Form.Item
24
32
  label={
25
33
  <>
@@ -45,7 +53,7 @@ export const HtmlProps: React.FC<PropEditorProps<HtmlModel>> = ({
45
53
  height="300px"
46
54
  defaultLanguage="html"
47
55
  value={model.template}
48
- onChange={(v) => setTemplate(v || "")}
56
+ onChange={(v) => triggerModel("template", v || "")}
49
57
  options={{
50
58
  minimap: { enabled: false },
51
59
  scrollBeyondLastLine: false,
@@ -2,7 +2,7 @@ import { Card, CardProps } from "antd";
2
2
  import React, { useContext, useMemo, useState } from "react";
3
3
  import { DropContainer } from "../../../dnd/DropContainer";
4
4
  import { HtmlBaseProps } from "../../../typing";
5
- import { DesignerContext } from "../../../context/DesignerContext";
5
+ import { PageContext } from "../../../context/PageContext";
6
6
 
7
7
  export type CardRenderProps = {
8
8
  bordered?: boolean;
@@ -3,7 +3,7 @@ import React, { useContext, useMemo, useState } from "react";
3
3
  import { PageItem } from "../../../layout/PageItem";
4
4
  import { DropContainer } from "../../../dnd/DropContainer";
5
5
  import { HtmlBaseProps } from "../../../typing";
6
- import { DesignerContext } from "../../../context/DesignerContext";
6
+ import { PageContext } from "../../../context/PageContext";
7
7
  import { EnvContext } from "../../../context/EnvContext";
8
8
 
9
9
  export type ColRenderProps = {
@@ -30,7 +30,7 @@ export const ColRender: React.FC<ColRenderProps> = ({
30
30
  style = {},
31
31
  className,
32
32
  }) => {
33
- const { designable } = useContext(DesignerContext);
33
+ const { designable } = useContext(PageContext);
34
34
  const { deviceWidth } = useContext(EnvContext);
35
35
  const [localChildren, setLocalChildren] = useState(item.children || []);
36
36
 
@@ -9,6 +9,7 @@ export type HtmlRenderProps = {
9
9
  template?: string;
10
10
  style?: React.CSSProperties;
11
11
  item: any;
12
+ classNames?: string[];
12
13
  } & HtmlBaseProps;
13
14
 
14
15
  /**
@@ -28,6 +29,7 @@ export const HtmlRender: React.FC<HtmlRenderProps> = ({
28
29
  item,
29
30
  style,
30
31
  className,
32
+ classNames = [],
31
33
  }) => {
32
34
  const { env, initCallback } = useContext(EnvContext);
33
35
  const datasource = useDatasource(id, item.datasource);
@@ -79,7 +81,7 @@ export const HtmlRender: React.FC<HtmlRenderProps> = ({
79
81
  <div
80
82
  id={id}
81
83
  style={style}
82
- className={className}
84
+ className={(classNames || []).join(" ") + (" " + className || "")}
83
85
  dangerouslySetInnerHTML={{ __html: html }}
84
86
  />
85
87
  );
@@ -2,7 +2,7 @@ import { Row } from "antd";
2
2
  import React, { useContext, useState } from "react";
3
3
  import { DropContainer } from "../../../dnd/DropContainer";
4
4
  import { HtmlBaseProps } from "../../../typing";
5
- import { DesignerContext } from "../../../context/DesignerContext";
5
+ import { PageContext } from "../../../context/PageContext";
6
6
 
7
7
  export type RowRenderProps = {
8
8
  gutter?: number | [number, number];
@@ -22,7 +22,7 @@ export const RowRender: React.FC<RowRenderProps> = ({
22
22
  style,
23
23
  className,
24
24
  }) => {
25
- const { designable } = useContext(DesignerContext);
25
+ const { designable } = useContext(PageContext);
26
26
  const [localChildren, setLocalChildren] = useState(item.children || []);
27
27
 
28
28
  const onLocalChildrenChange = (list: any[]) => {
@@ -2,7 +2,7 @@ import { Space } from "antd";
2
2
  import React, { useContext, useMemo, useState } from "react";
3
3
  import { DropContainer } from "../../../dnd/DropContainer";
4
4
  import { HtmlBaseProps } from "../../../typing";
5
- import { DesignerContext } from "../../../context/DesignerContext";
5
+ import { PageContext } from "../../../context/PageContext";
6
6
  import { type SizeType } from "antd/es/config-provider/SizeContext";
7
7
 
8
8
  export type SpaceRenderProps = {
@@ -21,7 +21,7 @@ export const SpaceRender: React.FC<SpaceRenderProps> = ({
21
21
  style = {},
22
22
  className,
23
23
  }) => {
24
- const { designable } = useContext(DesignerContext);
24
+ const { designable } = useContext(PageContext);
25
25
  const [localChildren, setLocalChildren] = useState(item.children || []);
26
26
 
27
27
  const onLocalChildrenChange = (list: any[]) => {
@@ -36,8 +36,6 @@ export const handleCallback = (
36
36
 
37
37
  export const uuid = () => v4();
38
38
 
39
-
40
-
41
39
  export const formatTime = (dateStr: string) => {
42
40
  if (!dateStr) return "";
43
41
  const date = new Date(dateStr);
@@ -74,4 +72,22 @@ export const formatTime = (dateStr: string) => {
74
72
 
75
73
  const YYYY = date.getFullYear();
76
74
  return `${YYYY}-${MM}-${DD} ${HH}:${mm}`;
77
- };
75
+ };
76
+
77
+ export const isMobile = () => {
78
+ const userAgent = navigator.userAgent;
79
+ const mobileKeywords = [
80
+ "Android",
81
+ "iPhone",
82
+ "iPad",
83
+ "Windows Phone",
84
+ "BlackBerry",
85
+ "Opera Mini",
86
+ "Symbian",
87
+ "Kindle",
88
+ "Mobile",
89
+ ];
90
+
91
+ const regex = new RegExp(mobileKeywords.join("|"), "i");
92
+ return regex.test(userAgent);
93
+ };