@ray-js/code-sandbox 0.0.3-beta-3 → 0.0.3-beta-5

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.
@@ -1,3 +1,4 @@
1
+ import { DrawerProps } from 'antd';
1
2
  import React from 'react';
2
3
  export interface CodeSandboxProps {
3
4
  code: string;
@@ -12,14 +13,32 @@ export interface CodeSandboxProps {
12
13
  }
13
14
  export declare const CodeSandbox: React.FC<CodeSandboxProps>;
14
15
  export declare const checkShowCodeSandbox: (code: string) => boolean;
16
+ export interface UseCodeSandboxDrawerOps {
17
+ getContainer?: DrawerProps['getContainer'];
18
+ title: string;
19
+ height?: string;
20
+ placement?: DrawerProps['placement'];
21
+ txpCode: string;
22
+ pageName: string;
23
+ baseUri: string;
24
+ emptyText?: string;
25
+ isZhLanguage?: boolean;
26
+ code: string;
27
+ langKey?: string;
28
+ }
29
+ export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, }: UseCodeSandboxDrawerOps) => {
30
+ modal: React.JSX.Element;
31
+ show: boolean;
32
+ setShow: React.Dispatch<React.SetStateAction<boolean>>;
33
+ };
15
34
  export declare const CodeSandboxButton: React.FC<{
16
35
  code: string;
17
36
  title: string;
18
- txpCode: string;
37
+ langKey?: string;
19
38
  tooltip?: string;
39
+ txpCode: string;
20
40
  pageName: string;
21
41
  baseUri: string;
22
- langKey?: string;
23
42
  emptyText?: string;
24
43
  isZhLanguage?: boolean;
25
44
  }>;
@@ -1,3 +1,6 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ const _excluded = ["tooltip"];
1
4
  import { Button, Drawer, Tooltip } from 'antd';
2
5
  import _ from 'lodash';
3
6
  import React, { useCallback, useEffect, useRef, useState } from 'react';
@@ -71,19 +74,62 @@ export const checkShowCodeSandbox = code => {
71
74
  }
72
75
  return false;
73
76
  };
74
- export const CodeSandboxButton = _ref2 => {
77
+ export const useCodeSandboxDrawer = _ref2 => {
75
78
  let {
76
- code,
79
+ getContainer,
77
80
  title,
78
- txpCode,
79
- tooltip = '在线编辑预览效果!',
81
+ height = '90vh',
82
+ placement = 'bottom',
83
+ isZhLanguage,
80
84
  pageName,
81
- baseUri,
85
+ txpCode,
82
86
  emptyText,
83
87
  langKey,
84
- isZhLanguage
88
+ baseUri,
89
+ code
85
90
  } = _ref2;
86
91
  const [show, setShow] = useState(false);
92
+ return {
93
+ modal: /*#__PURE__*/React.createElement(Drawer, {
94
+ getContainer: getContainer,
95
+ title: `${title}`,
96
+ height: height,
97
+ contentWrapperStyle: {
98
+ padding: 0
99
+ },
100
+ style: {
101
+ padding: 0
102
+ },
103
+ placement: placement,
104
+ destroyOnClose: true,
105
+ open: show,
106
+ onClose: () => {
107
+ setShow(false);
108
+ }
109
+ }, /*#__PURE__*/React.createElement(CodeSandbox, {
110
+ isZhLanguage: isZhLanguage,
111
+ emptyText: emptyText,
112
+ langKey: langKey,
113
+ baseUri: baseUri,
114
+ txpCode: txpCode,
115
+ pageName: pageName,
116
+ show: show,
117
+ title: title,
118
+ code: code
119
+ })),
120
+ show,
121
+ setShow
122
+ };
123
+ };
124
+ export const CodeSandboxButton = _ref3 => {
125
+ let {
126
+ tooltip
127
+ } = _ref3,
128
+ props = _objectWithoutProperties(_ref3, _excluded);
129
+ const api = useCodeSandboxDrawer(_objectSpread(_objectSpread({}, props), {}, {
130
+ height: '90vh',
131
+ getContainer: () => ref.current
132
+ }));
87
133
  const ref = useRef();
88
134
  return /*#__PURE__*/React.createElement(DrawerContain, {
89
135
  ref: ref
@@ -102,32 +148,6 @@ export const CodeSandboxButton = _ref2 => {
102
148
  alignItems: 'center',
103
149
  justifyContent: 'center'
104
150
  },
105
- onClick: () => setShow(true)
106
- })), /*#__PURE__*/React.createElement(Drawer, {
107
- getContainer: () => ref.current,
108
- title: `${title}`,
109
- height: "90vh",
110
- contentWrapperStyle: {
111
- padding: 0
112
- },
113
- style: {
114
- padding: 0
115
- },
116
- placement: "bottom",
117
- destroyOnClose: true,
118
- open: show,
119
- onClose: () => {
120
- setShow(false);
121
- }
122
- }, /*#__PURE__*/React.createElement(CodeSandbox, {
123
- isZhLanguage: isZhLanguage,
124
- emptyText: emptyText,
125
- langKey: langKey,
126
- baseUri: baseUri,
127
- txpCode: txpCode,
128
- pageName: pageName,
129
- show: show,
130
- title: title,
131
- code: code
132
- })));
151
+ onClick: () => api.setShow(true)
152
+ })), api.modal);
133
153
  };
@@ -16,7 +16,7 @@ export const Demo = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
16
16
  emptyText
17
17
  } = _ref;
18
18
  let path = `${createCompnentUri(baseUri, txpCode, `index.html`)}?t=${ts || Date.now()}`;
19
- path += `#!/pages/${comId}/index&langKey=${langKey}`;
19
+ path += `#!/pages/${comId}/index?langKey=${langKey}`;
20
20
  const ref = useRef();
21
21
  useImperativeHandle(parentRef, () => ({
22
22
  postMsg: data => {
@@ -1,3 +1,3 @@
1
- import { CodeSandboxButton, CodeSandbox } from './codesandbox';
1
+ import { CodeSandboxButton, CodeSandbox, useCodeSandboxDrawer } from './codesandbox';
2
2
  export * from './codesandbox';
3
- export { CodeSandbox, CodeSandboxButton };
3
+ export { CodeSandbox, CodeSandboxButton, useCodeSandboxDrawer };
package/lib/txp/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { CodeSandboxButton, CodeSandbox } from './codesandbox';
1
+ import { CodeSandboxButton, CodeSandbox, useCodeSandboxDrawer } from './codesandbox';
2
2
  export * from './codesandbox';
3
- export { CodeSandbox, CodeSandboxButton };
3
+ export { CodeSandbox, CodeSandboxButton, useCodeSandboxDrawer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/code-sandbox",
3
- "version": "0.0.3-beta-3",
3
+ "version": "0.0.3-beta-5",
4
4
  "description": "小程序 CodeSandbox 容器",
5
5
  "main": "lib/index",
6
6
  "files": [