@brushes/component-core 1.1.1 → 1.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brushes/component-core",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -56,6 +56,10 @@ export const IsShowContainer = ({
56
56
  connectors: { connect, drag }
57
57
  } = useNode();
58
58
 
59
+ const { custom } = useNode((node) => ({
60
+ custom: node.data.custom
61
+ }));
62
+
59
63
  let [searchParams] = useSearchParams();
60
64
 
61
65
  const nValue = useMemo(() => {
@@ -105,7 +109,8 @@ export const IsShowContainer = ({
105
109
  <div
106
110
  style={{
107
111
  ...margin,
108
- ...padding
112
+ ...padding,
113
+ ...custom
109
114
  }}
110
115
  ref={(ref: HTMLDivElement) => connect(drag(ref))}
111
116
  >
@@ -115,7 +120,7 @@ export const IsShowContainer = ({
115
120
  }
116
121
  };
117
122
 
118
- export const Container = ({ width, text, children, background, margin = {}, positionValue = {}, padding = {}, backgroundImage, position, $$_actions, $_actions, borderColor, ...props }: any) => {
123
+ export const Container = ({ width, text, children, className, background, margin = {}, positionValue = {}, padding = {}, backgroundImage, position, $$_actions, $_actions, borderColor, ...props }: any) => {
119
124
  // @ts-ignore
120
125
  const { styles } = useStyles();
121
126
  const { enabled } = useEditor((state) => ({
@@ -141,9 +146,13 @@ export const Container = ({ width, text, children, background, margin = {}, posi
141
146
  connectors: { connect, drag }
142
147
  } = useNode();
143
148
 
149
+ const { custom } = useNode((node) => ({
150
+ custom: node.data.custom
151
+ }));
152
+
144
153
  return (
145
154
  <div
146
- className={enabled ? styles.category : ''}
155
+ className={`${enabled ? styles.category : ''} ${className || ''}`}
147
156
  ref={(ref: HTMLDivElement) => connect(drag(ref))}
148
157
  style={{
149
158
  ...margin,
@@ -155,7 +164,8 @@ export const Container = ({ width, text, children, background, margin = {}, posi
155
164
  ...props,
156
165
  ...positionNewValue,
157
166
  background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
158
- width: ((width + '').includes('%') || (width + '').includes('px')) ? width : `${width}px`
167
+ width: ((width + '').includes('%') || (width + '').includes('px')) ? width : `${width}px`,
168
+ ...custom
159
169
  }}
160
170
  >
161
171
  <Inner text={text} enabled={enabled}>
@@ -174,6 +184,10 @@ export const OutContainerComponent = ({ width, api, params, children, background
174
184
  connectors: { connect, drag }
175
185
  } = useNode();
176
186
 
187
+ const { custom } = useNode((node) => ({
188
+ custom: node.data.custom
189
+ }));
190
+
177
191
  const { styles } = useStyles();
178
192
  return (
179
193
  <div
@@ -186,7 +200,8 @@ export const OutContainerComponent = ({ width, api, params, children, background
186
200
  ...padding,
187
201
  ...props,
188
202
  background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
189
- width: ((width + '').includes('%') || (width + '').includes('px')) ? width : `${width}px`
203
+ width: (width + '').includes('%') ? width : `${width}px`,
204
+ ...custom
190
205
  }}
191
206
  >
192
207
  <Inner enabled={enabled}>{children}</Inner>
@@ -206,6 +221,10 @@ export const ContainerWrap = ({ width, background, children, backgroundImage, he
206
221
  connectors: { connect, drag }
207
222
  } = useNode();
208
223
 
224
+ const { custom } = useNode((node) => ({
225
+ custom: node.data.custom
226
+ }));
227
+
209
228
  const { enabled } = useEditor((state) => ({
210
229
  enabled: state.options.enabled
211
230
  }));
@@ -214,10 +233,11 @@ export const ContainerWrap = ({ width, background, children, backgroundImage, he
214
233
  {...props}
215
234
  ref={(ref: HTMLDivElement) => connect(drag(ref))}
216
235
  style={{
217
- width: ((width + '').includes('%') || (width + '').includes('px')) ? width : `${width}px`,
236
+ width,
218
237
  paddingBottom: 5,
219
238
  background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
220
- minHeight: `calc(${height}vh - 110px)`
239
+ minHeight: `calc(${height}vh - 110px)`,
240
+ ...custom
221
241
  }}
222
242
  >
223
243
  <Inner root={true} enabled={enabled}>
@@ -1,6 +1,7 @@
1
1
  import { QjIcon } from '@brushes/share-resource';
2
2
  import { Watermark } from 'antd';
3
3
  import { createStyles } from 'antd-style';
4
+ import { useNode } from '@craftjs/core';
4
5
 
5
6
  const useStyle = createStyles(({ token, css }) => {
6
7
  return {
@@ -24,6 +25,9 @@ const useStyle = createStyles(({ token, css }) => {
24
25
  });
25
26
 
26
27
  export const DefaultJsx = ({ text = '内容放置区域', root }: { text?: string; root?: boolean }) => {
28
+ const { custom } = useNode((node) => ({
29
+ custom: node.data.custom
30
+ }));
27
31
  const { styles } = useStyle();
28
32
  return (
29
33
  <div
@@ -37,7 +41,8 @@ export const DefaultJsx = ({ text = '内容放置区域', root }: { text?: strin
37
41
  fontSize: 50,
38
42
  fontWeight: 500,
39
43
  display: 'block',
40
- color: '#bbb'
44
+ color: '#bbb',
45
+ ...custom,
41
46
  }}
42
47
  name={'icon-computer'}
43
48
  ></QjIcon>
@@ -1,9 +1,13 @@
1
1
  import { Typography } from 'antd';
2
+ import { useNode } from '@craftjs/core';
2
3
 
3
4
  export const SlotEmpty: React.FC<{
4
5
  children?: React.ReactNode;
5
6
  borderColor?: string;
6
7
  }> = ({ children = '当前为插槽容器,可以自定义组件代码。', borderColor = 'rgba(0, 0, 0, 0.1)' }) => {
8
+ const { custom } = useNode((node) => ({
9
+ custom: node.data.custom
10
+ }));
7
11
  return (
8
12
  <div
9
13
  style={{
@@ -15,7 +19,8 @@ export const SlotEmpty: React.FC<{
15
19
  fontSize: 12,
16
20
  textAlign: 'center',
17
21
  fontWeight: 'normal',
18
- background: 'rgba(255,255,255, 0.2)'
22
+ background: 'rgba(255,255,255, 0.2)',
23
+ ...custom
19
24
  }}
20
25
  >
21
26
  <Typography.Text type="secondary">{children}</Typography.Text>
@@ -1,4 +1,3 @@
1
1
  export * from './container';
2
2
  export * from './default';
3
3
  export * from './empty';
4
- // export * from './resizer';
@@ -2,8 +2,12 @@ import { useEffect, useMemo, useState } from 'react';
2
2
  import { Button, Form } from 'antd';
3
3
  import { useMountedRef } from '@brushes/form';
4
4
  import { get } from '@brushes/request';
5
+ import { useNode } from '@craftjs/core';
5
6
 
6
7
  export const CodeComponent = ({ api = '/web/ml/muser/sendPhone.json', codeKey, height = 36 }: { codeKey?: string; api?: string; height?: number }) => {
8
+ const { custom } = useNode((node) => ({
9
+ custom: node.data.custom
10
+ }));
7
11
  const form = Form.useFormInstance();
8
12
  const verCode = form.getFieldValue('verCode');
9
13
  const [dataTime, setDataTime] = useState(0);
@@ -53,7 +57,7 @@ export const CodeComponent = ({ api = '/web/ml/muser/sendPhone.json', codeKey, h
53
57
  };
54
58
 
55
59
  return (
56
- <Button loading={loading} size={'small'} type={'link'} disabled={isfetch} style={{ cursor: 'pointer', height, width: 90 }} onClick={fetchCode}>
60
+ <Button loading={loading} size={'small'} type={'link'} disabled={isfetch} style={{ cursor: 'pointer', height, width: 90, ...custom }} onClick={fetchCode}>
57
61
  {dataTime === 0 ? '获取验证码' : `倒计时${dataTime}秒`}
58
62
  </Button>
59
63
  );
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
2
2
  import { Form, Spin } from 'antd';
3
3
  import { dynamicFormFields } from '@brushes/form';
4
4
  import { createStyles } from 'antd-style';
5
+ import { useNode } from '@craftjs/core';
5
6
 
6
7
  const useStyle = createStyles(({ token, css }, { height }: { height: number }) => {
7
8
  return {
@@ -13,6 +14,9 @@ const useStyle = createStyles(({ token, css }, { height }: { height: number }) =
13
14
  };
14
15
  });
15
16
  export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', codeKey, height = 40 }: { api?: string; codeKey?: string; height?: number }) => {
17
+ const { custom } = useNode((node) => ({
18
+ custom: node.data.custom
19
+ }));
16
20
  const { styles } = useStyle({ height });
17
21
  const form = Form.useFormInstance();
18
22
  const isDisabled = form.getFieldValue('isDisabled');
@@ -66,7 +70,7 @@ export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', code
66
70
  <Spin spinning={loading}>{verImg ? <img src={verImg} onClick={fetchCode} style={{ width: 90, height: height - 2 }} /> : <div style={{ width: 90, height: height - 2 }}></div>}</Spin>
67
71
  ),
68
72
  style: {
69
- height
73
+ height, ...custom
70
74
  }
71
75
  }
72
76
  }
@@ -1,6 +1,10 @@
1
1
  import { Divider } from 'antd';
2
+ import { useNode } from '@craftjs/core';
2
3
 
3
4
  const Title = ({ title }: { title: string }) => {
5
+ const { custom } = useNode((node) => ({
6
+ custom: node.data.custom
7
+ }));
4
8
  return (
5
9
  <>
6
10
  <Divider style={{ fontSize: 13, margin: '2px 0' }} orientation="left">
@@ -1,270 +0,0 @@
1
- // import { useNode, useEditor } from '@craftjs/core';
2
- // import cx from 'classnames';
3
- // import { debounce } from 'debounce';
4
- // import { Resizable } from 're-resizable';
5
- // import { useRef, useEffect, useState, useCallback } from 'react';
6
- // import { styled } from 'styled-components';
7
- //
8
- // import {
9
- // isPercentage,
10
- // pxToPercent,
11
- // percentToPx,
12
- // getElementDimensions,
13
- // } from './numToMeasurement';
14
- //
15
- // const Indicators = styled.div<{ $bound?: 'row' | 'column' }>`
16
- // position: absolute;
17
- // top: 0;
18
- // left: 0;
19
- // width: 100%;
20
- // height: 100%;
21
- // pointer-events: none;
22
- // span {
23
- // position: absolute;
24
- // width: 8px;
25
- // height: 8px;
26
- // background: #fff;
27
- // border-radius: 100%;
28
- // display: block;
29
- // box-shadow: 0px 0px 12px -1px rgba(0, 0, 0, 0.25);
30
- // z-index: 99999;
31
- // pointer-events: none;
32
- // border: 2px solid #36a9e0;
33
- // &:nth-child(1) {
34
- // ${(props) =>
35
- // props.$bound
36
- // ? props.$bound === 'row'
37
- // ? `
38
- // left: 50%;
39
- // top: -5px;
40
- // transform:translateX(-50%);
41
- // `
42
- // : `
43
- // top: 50%;
44
- // left: -5px;
45
- // transform:translateY(-50%);
46
- // `
47
- // : `
48
- // left: -5px;
49
- // top:-5px;
50
- // `}
51
- // }
52
- // &:nth-child(2) {
53
- // right: -5px;
54
- // top: -5px;
55
- // display: ${(props) => (props.$bound ? 'none' : 'block')};
56
- // }
57
- // &:nth-child(3) {
58
- // ${(props) =>
59
- // props.$bound
60
- // ? props.$bound === 'row'
61
- // ? `
62
- // left: 50%;
63
- // bottom: -3px;
64
- // transform:translateX(-50%);
65
- // `
66
- // : `
67
- // bottom: 50%;
68
- // left: -5px;
69
- // transform:translateY(-50%);
70
- // `
71
- // : `
72
- // left: -5px;
73
- // bottom:-3px;
74
- // `}
75
- // }
76
- // &:nth-child(4) {
77
- // bottom: -3px;
78
- // right: -5px;
79
- // display: ${(props) => (props.$bound ? 'none' : 'block')};
80
- // }
81
- // }
82
- // `;
83
- //
84
- // export const Resizer = ({ propKey = { width: 'width', height: 'height' }, children, ...props }: any) => {
85
- // const {
86
- // id,
87
- // actions: { setProp },
88
- // connectors: { connect },
89
- // fillSpace,
90
- // nodeWidth,
91
- // nodeHeight,
92
- // parent,
93
- // active,
94
- // inNodeContext,
95
- // } = useNode((node) => {
96
- // return {
97
- // parent: node.data.parent,
98
- // active: node.events.selected,
99
- // nodeWidth: node.data.props[propKey.width],
100
- // nodeHeight: node.data.props[propKey.height],
101
- // fillSpace: node.data.props.fillSpace,
102
- // }
103
- // });
104
- // const { isRootNode, parentDirection } = useEditor((state, query) => {
105
- // return {
106
- // parentDirection:
107
- // parent &&
108
- // state.nodes[parent] &&
109
- // state.nodes[parent].data.props.flexDirection,
110
- // isRootNode: query.node(id).isRoot(),
111
- // };
112
- // });
113
- //
114
- // const resizable = useRef<Resizable>(null);
115
- // const isResizing = useRef<Boolean>(false);
116
- // const editingDimensions = useRef<any>(null);
117
- // const nodeDimensions = useRef(null);
118
- // nodeDimensions.current = { width: nodeWidth, height: nodeHeight };
119
- //
120
- // /**
121
- // * Using an internal value to ensure the width/height set in the node is converted to px
122
- // * because for some reason the <re-resizable /> library does not work well with percentages.
123
- // */
124
- // const [internalDimensions, setInternalDimensions] = useState({
125
- // width: nodeWidth,
126
- // height: nodeHeight,
127
- // });
128
- //
129
- // const updateInternalDimensionsInPx = useCallback(() => {
130
- // const { width: nodeWidth, height: nodeHeight } = nodeDimensions.current;
131
- // const width = percentToPx(
132
- // nodeWidth,
133
- // resizable.current &&
134
- // getElementDimensions(resizable.current.resizable.parentElement).width
135
- // );
136
- // const height = percentToPx(
137
- // nodeHeight,
138
- // resizable.current &&
139
- // getElementDimensions(resizable.current.resizable.parentElement).height
140
- // );
141
- //
142
- // setInternalDimensions({
143
- // width,
144
- // height,
145
- // });
146
- // }, []);
147
- //
148
- // const updateInternalDimensionsWithOriginal = useCallback(() => {
149
- // const { width: nodeWidth, height: nodeHeight } = nodeDimensions.current;
150
- // setInternalDimensions({
151
- // width: nodeWidth,
152
- // height: nodeHeight,
153
- // });
154
- // }, []);
155
- //
156
- // const getUpdatedDimensions = (width, height) => {
157
- // const dom = resizable.current.resizable;
158
- // if (!dom) return;
159
- //
160
- // const currentWidth = parseInt(editingDimensions.current.width),
161
- // currentHeight = parseInt(editingDimensions.current.height);
162
- //
163
- // return {
164
- // width: currentWidth + parseInt(width),
165
- // height: currentHeight + parseInt(height),
166
- // };
167
- // };
168
- //
169
- // useEffect(() => {
170
- // if (!isResizing.current) updateInternalDimensionsWithOriginal();
171
- // }, [nodeWidth, nodeHeight, updateInternalDimensionsWithOriginal]);
172
- //
173
- // useEffect(() => {
174
- // const listener = debounce(updateInternalDimensionsWithOriginal, 1);
175
- // window.addEventListener('resize', listener);
176
- //
177
- // return () => {
178
- // window.removeEventListener('resize', listener);
179
- // };
180
- // }, [updateInternalDimensionsWithOriginal]);
181
- //
182
- // return (
183
- // <Resizable
184
- // enable={[
185
- // 'top',
186
- // 'left',
187
- // 'bottom',
188
- // 'right',
189
- // 'topLeft',
190
- // 'topRight',
191
- // 'bottomLeft',
192
- // 'bottomRight',
193
- // ].reduce((acc: any, key) => {
194
- // acc[key] = active && inNodeContext;
195
- // return acc;
196
- // }, {})}
197
- // style={{margin: '0 auto'}}
198
- // className={cx([
199
- // {
200
- // 'm-auto': isRootNode,
201
- // flex: true,
202
- // },
203
- // ])}
204
- // ref={(ref) => {
205
- // if (ref) {
206
- // resizable.current = ref;
207
- // connect(resizable.current.resizable);
208
- // }
209
- // }}
210
- // size={internalDimensions}
211
- // onResizeStart={(e) => {
212
- // updateInternalDimensionsInPx();
213
- // e.preventDefault();
214
- // e.stopPropagation();
215
- // const dom = resizable.current.resizable;
216
- // if (!dom) return;
217
- // editingDimensions.current = {
218
- // width: dom.getBoundingClientRect().width,
219
- // height: dom.getBoundingClientRect().height,
220
- // };
221
- // isResizing.current = true;
222
- // }}
223
- // onResize={(_, __, ___, d) => {
224
- // const dom = resizable.current.resizable;
225
- // let { width, height }: any = getUpdatedDimensions(d.width, d.height);
226
- // if (isPercentage(nodeWidth))
227
- // width =
228
- // pxToPercent(width, getElementDimensions(dom.parentElement).width) +
229
- // '%';
230
- // else width = `${width}px`;
231
- //
232
- // if (isPercentage(nodeHeight))
233
- // height =
234
- // pxToPercent(
235
- // height,
236
- // getElementDimensions(dom.parentElement).height
237
- // ) + '%';
238
- // else height = `${height}px`;
239
- //
240
- // if (isPercentage(width) && dom.parentElement.style.width === 'auto') {
241
- // width = editingDimensions.current.width + d.width + 'px';
242
- // }
243
- //
244
- // if (isPercentage(height) && dom.parentElement.style.height === 'auto') {
245
- // height = editingDimensions.current.height + d.height + 'px';
246
- // }
247
- //
248
- // setProp((prop: any) => {
249
- // prop[propKey.width] = width;
250
- // prop[propKey.height] = height;
251
- // }, 500);
252
- // }}
253
- // onResizeStop={() => {
254
- // isResizing.current = false;
255
- // updateInternalDimensionsWithOriginal();
256
- // }}
257
- // {...props}
258
- // >
259
- // {children}
260
- // {active && (
261
- // <Indicators $bound={fillSpace === 'yes' ? parentDirection : false}>
262
- // <span></span>
263
- // <span></span>
264
- // <span></span>
265
- // <span></span>
266
- // </Indicators>
267
- // )}
268
- // </Resizable>
269
- // );
270
- // };
@@ -1,26 +0,0 @@
1
- export const isPercentage = (val: string) => typeof val === 'string' && val.indexOf('%') > -1;
2
-
3
- export const percentToPx = (value: any, comparativeValue: number) => {
4
- if (value.indexOf('px') > -1 || value === 'auto' || !comparativeValue) return value;
5
- const percent = parseInt(value);
6
- return (percent / 100) * comparativeValue + 'px';
7
- };
8
- export const pxToPercent = (value: any, comparativeValue: number) => {
9
- const val = (Math.abs(value) / comparativeValue) * 100;
10
- if (value < 0) return -1 * val;
11
- else return Math.round(val);
12
- };
13
- export const getElementDimensions = (element: HTMLElement) => {
14
- const computedStyle = getComputedStyle(element);
15
-
16
- let height = element.clientHeight,
17
- width = element.clientWidth; // width with padding
18
-
19
- height -= parseFloat(computedStyle.paddingTop) + parseFloat(computedStyle.paddingBottom);
20
- width -= parseFloat(computedStyle.paddingLeft) + parseFloat(computedStyle.paddingRight);
21
-
22
- return {
23
- width,
24
- height
25
- };
26
- };