@canlooks/can-ui 0.0.99 → 0.0.100

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.
@@ -6,9 +6,6 @@ const react_1 = require("react");
6
6
  const flex_style_1 = require("./flex.style");
7
7
  const utils_1 = require("../../utils");
8
8
  const transportStyle_1 = require("../transportStyle");
9
- const shouldAddUnits = new Set([
10
- 'gap', 'columnGap', 'rowGap'
11
- ]);
12
9
  exports.Flex = (({ inline, direction = 'row', wrap, gap = 0, columnGap, rowGap, compact, ...props }) => {
13
10
  const renderChildren = () => {
14
11
  if (!compact) {
@@ -26,12 +23,10 @@ exports.Flex = (({ inline, direction = 'row', wrap, gap = 0, columnGap, rowGap,
26
23
  });
27
24
  });
28
25
  };
29
- return ((0, jsx_runtime_1.jsx)(transportStyle_1.TransportStyle, { ...props, css: flex_style_1.style, className: (0, utils_1.clsx)(flex_style_1.classes.root, props.className), style: {
30
- ...(0, transportStyle_1.transportCSSVariables)({
31
- display: inline ? 'inline-flex' : 'flex',
32
- flexDirection: direction,
33
- flexWrap: wrap, columnGap, rowGap, gap
34
- }, shouldAddUnits),
26
+ return ((0, jsx_runtime_1.jsx)(transportStyle_1.TransportStyle, { ...props, className: (0, utils_1.clsx)(flex_style_1.classes.root, props.className), style: (0, utils_1.filterProperties)({
27
+ display: inline ? 'inline-flex' : 'flex',
28
+ flexDirection: direction,
29
+ flexWrap: wrap, columnGap, rowGap, gap,
35
30
  ...props.style
36
- }, children: renderChildren() }));
31
+ }), children: renderChildren() }));
37
32
  });
@@ -1,4 +1,3 @@
1
1
  export declare const classes: {
2
2
  root: string;
3
3
  };
4
- export declare const style: import("@emotion/react").SerializedStyles;
@@ -1,21 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.style = exports.classes = void 0;
3
+ exports.classes = void 0;
4
4
  const utils_1 = require("../../utils");
5
- const react_1 = require("@emotion/react");
6
5
  exports.classes = (0, utils_1.defineInnerClasses)('flex');
7
- exports.style = (0, react_1.css) `
8
- --display: unset;
9
- --flex-direction: unset;
10
- --flex-wrap: unset;
11
- --column-gap: unset;
12
- --row-gap: unset;
13
- --gap: unset;
14
-
15
- display: var(--display);
16
- flex-direction: var(--flex-direction);
17
- flex-wrap: var(--flex-wrap);
18
- column-gap: var(--column-gap);
19
- row-gap: var(--row-gap);
20
- gap: var(--gap);
21
- `;
@@ -32,4 +32,3 @@ export type TransportStyleOwnProps = {
32
32
  };
33
33
  export type TransportStyleProps<C extends ElementType = 'div'> = OverridableProps<TransportStyleOwnProps, C>;
34
34
  export declare const TransportStyle: OverridableComponent<TransportStyleOwnProps>;
35
- export declare function transportCSSVariables(props: any, shouldAddUnitSet?: Set<string>): any;
@@ -1,41 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransportStyle = void 0;
4
- exports.transportCSSVariables = transportCSSVariables;
5
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
6
5
  const utils_1 = require("../../utils");
7
- const transportStyle_style_1 = require("./transportStyle.style");
8
6
  exports.TransportStyle = (({ component: Component = 'div', alignItems, justifyContent, alignSelf, justifySelf, flex, width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight, paddingTop, paddingRight, paddingBottom, paddingLeft, padding, marginTop, marginRight, marginBottom, marginLeft, margin, overflowX, overflowY, overflow, ...props }) => {
9
- return ((0, jsx_runtime_1.jsx)(Component, { ...props, css: transportStyle_style_1.style, style: {
10
- ...transportCSSVariables({
11
- alignItems, justifyContent, alignSelf, justifySelf, flex,
12
- width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight,
13
- padding, paddingTop, paddingRight, paddingBottom, paddingLeft,
14
- margin, marginTop, marginRight, marginBottom, marginLeft,
15
- overflow, overflowX, overflowY
16
- }),
7
+ return ((0, jsx_runtime_1.jsx)(Component, { ...props, style: (0, utils_1.filterProperties)({
8
+ alignItems, justifyContent, alignSelf, justifySelf, flex,
9
+ width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight,
10
+ padding, paddingTop, paddingRight, paddingBottom, paddingLeft,
11
+ margin, marginTop, marginRight, marginBottom, marginLeft,
12
+ overflow, overflowX, overflowY,
17
13
  ...props.style
18
- } }));
14
+ }) }));
19
15
  });
20
- const shouldAddUnits = new Set([
21
- 'width', 'minWidth', 'maxWidth',
22
- 'height', 'minHeight', 'maxHeight',
23
- 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft',
24
- 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft',
25
- 'gap', 'columnGap', 'rowGap'
26
- ]);
27
- function transportCSSVariables(props, shouldAddUnitSet) {
28
- const vars = {};
29
- for (const p in props) {
30
- let value = props[p];
31
- if (typeof value === 'undefined') {
32
- continue;
33
- }
34
- const set = new Set([...shouldAddUnits, ...shouldAddUnitSet || []]);
35
- if (typeof value === 'number' && set.has(p)) {
36
- value += 'px';
37
- }
38
- vars['--' + (0, utils_1.humpToSegmented)(p)] = value;
39
- }
40
- return vars;
41
- }
@@ -135,6 +135,12 @@ export declare function range(value: number, min?: number, max?: number): number
135
135
  */
136
136
  export declare function queryDeep<T = any>(obj: any, keyPath: PropertyKey | PropertyKey[], setValue?: (oldValue: any) => T, separator?: string): T;
137
137
  export declare function queryDeep<T = any>(obj: any, keyPath: PropertyKey | PropertyKey[], separator?: string, setValue?: (oldValue: any) => T): T;
138
+ /**
139
+ * 过滤对象中值为undefined属性
140
+ * @param obj
141
+ * @param undefinedValue 可传入该值,用于替换undefined以删除其他属性
142
+ */
143
+ export declare function filterProperties<T extends Record<string, any>>(obj: T, undefinedValue?: any): T;
138
144
  /**
139
145
  * 合并属性
140
146
  */
@@ -22,6 +22,7 @@ exports.findPredecessor = findPredecessor;
22
22
  exports.listenAllPredecessorsScroll = listenAllPredecessorsScroll;
23
23
  exports.range = range;
24
24
  exports.queryDeep = queryDeep;
25
+ exports.filterProperties = filterProperties;
25
26
  exports.mergeComponentProps = mergeComponentProps;
26
27
  /**
27
28
  * 生成最简易的随机ID
@@ -353,6 +354,19 @@ function queryDeep(obj, keyPath, a, b) {
353
354
  }
354
355
  return obj[keyPath];
355
356
  }
357
+ /**
358
+ * 过滤对象中值为undefined属性
359
+ * @param obj
360
+ * @param undefinedValue 可传入该值,用于替换undefined以删除其他属性
361
+ */
362
+ function filterProperties(obj, undefinedValue) {
363
+ for (const k in obj) {
364
+ if (obj[k] === undefinedValue) {
365
+ delete obj[k];
366
+ }
367
+ }
368
+ return obj;
369
+ }
356
370
  function mergeComponentProps(...props) {
357
371
  const { length } = props;
358
372
  if (length <= 1) {
@@ -1,11 +1,8 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
2
  import { Children, cloneElement, isValidElement } from 'react';
3
- import { classes, style } from './flex.style';
4
- import { clsx } from '../../utils';
5
- import { transportCSSVariables, TransportStyle } from '../transportStyle';
6
- const shouldAddUnits = new Set([
7
- 'gap', 'columnGap', 'rowGap'
8
- ]);
3
+ import { classes } from './flex.style';
4
+ import { clsx, filterProperties } from '../../utils';
5
+ import { TransportStyle } from '../transportStyle';
9
6
  export const Flex = (({ inline, direction = 'row', wrap, gap = 0, columnGap, rowGap, compact, ...props }) => {
10
7
  const renderChildren = () => {
11
8
  if (!compact) {
@@ -23,12 +20,10 @@ export const Flex = (({ inline, direction = 'row', wrap, gap = 0, columnGap, row
23
20
  });
24
21
  });
25
22
  };
26
- return (_jsx(TransportStyle, { ...props, css: style, className: clsx(classes.root, props.className), style: {
27
- ...transportCSSVariables({
28
- display: inline ? 'inline-flex' : 'flex',
29
- flexDirection: direction,
30
- flexWrap: wrap, columnGap, rowGap, gap
31
- }, shouldAddUnits),
23
+ return (_jsx(TransportStyle, { ...props, className: clsx(classes.root, props.className), style: filterProperties({
24
+ display: inline ? 'inline-flex' : 'flex',
25
+ flexDirection: direction,
26
+ flexWrap: wrap, columnGap, rowGap, gap,
32
27
  ...props.style
33
- }, children: renderChildren() }));
28
+ }), children: renderChildren() }));
34
29
  });
@@ -1,4 +1,3 @@
1
1
  export declare const classes: {
2
2
  root: string;
3
3
  };
4
- export declare const style: import("@emotion/react").SerializedStyles;
@@ -1,18 +1,2 @@
1
1
  import { defineInnerClasses } from '../../utils';
2
- import { css } from '@emotion/react';
3
2
  export const classes = defineInnerClasses('flex');
4
- export const style = css `
5
- --display: unset;
6
- --flex-direction: unset;
7
- --flex-wrap: unset;
8
- --column-gap: unset;
9
- --row-gap: unset;
10
- --gap: unset;
11
-
12
- display: var(--display);
13
- flex-direction: var(--flex-direction);
14
- flex-wrap: var(--flex-wrap);
15
- column-gap: var(--column-gap);
16
- row-gap: var(--row-gap);
17
- gap: var(--gap);
18
- `;
@@ -32,4 +32,3 @@ export type TransportStyleOwnProps = {
32
32
  };
33
33
  export type TransportStyleProps<C extends ElementType = 'div'> = OverridableProps<TransportStyleOwnProps, C>;
34
34
  export declare const TransportStyle: OverridableComponent<TransportStyleOwnProps>;
35
- export declare function transportCSSVariables(props: any, shouldAddUnitSet?: Set<string>): any;
@@ -1,37 +1,12 @@
1
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
- import { humpToSegmented } from '../../utils';
3
- import { style } from './transportStyle.style';
2
+ import { filterProperties } from '../../utils';
4
3
  export const TransportStyle = (({ component: Component = 'div', alignItems, justifyContent, alignSelf, justifySelf, flex, width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight, paddingTop, paddingRight, paddingBottom, paddingLeft, padding, marginTop, marginRight, marginBottom, marginLeft, margin, overflowX, overflowY, overflow, ...props }) => {
5
- return (_jsx(Component, { ...props, css: style, style: {
6
- ...transportCSSVariables({
7
- alignItems, justifyContent, alignSelf, justifySelf, flex,
8
- width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight,
9
- padding, paddingTop, paddingRight, paddingBottom, paddingLeft,
10
- margin, marginTop, marginRight, marginBottom, marginLeft,
11
- overflow, overflowX, overflowY
12
- }),
4
+ return (_jsx(Component, { ...props, style: filterProperties({
5
+ alignItems, justifyContent, alignSelf, justifySelf, flex,
6
+ width, minWidth, maxWidth, height, minHeight, maxHeight, lineHeight,
7
+ padding, paddingTop, paddingRight, paddingBottom, paddingLeft,
8
+ margin, marginTop, marginRight, marginBottom, marginLeft,
9
+ overflow, overflowX, overflowY,
13
10
  ...props.style
14
- } }));
11
+ }) }));
15
12
  });
16
- const shouldAddUnits = new Set([
17
- 'width', 'minWidth', 'maxWidth',
18
- 'height', 'minHeight', 'maxHeight',
19
- 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft',
20
- 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft',
21
- 'gap', 'columnGap', 'rowGap'
22
- ]);
23
- export function transportCSSVariables(props, shouldAddUnitSet) {
24
- const vars = {};
25
- for (const p in props) {
26
- let value = props[p];
27
- if (typeof value === 'undefined') {
28
- continue;
29
- }
30
- const set = new Set([...shouldAddUnits, ...shouldAddUnitSet || []]);
31
- if (typeof value === 'number' && set.has(p)) {
32
- value += 'px';
33
- }
34
- vars['--' + humpToSegmented(p)] = value;
35
- }
36
- return vars;
37
- }
@@ -135,6 +135,12 @@ export declare function range(value: number, min?: number, max?: number): number
135
135
  */
136
136
  export declare function queryDeep<T = any>(obj: any, keyPath: PropertyKey | PropertyKey[], setValue?: (oldValue: any) => T, separator?: string): T;
137
137
  export declare function queryDeep<T = any>(obj: any, keyPath: PropertyKey | PropertyKey[], separator?: string, setValue?: (oldValue: any) => T): T;
138
+ /**
139
+ * 过滤对象中值为undefined属性
140
+ * @param obj
141
+ * @param undefinedValue 可传入该值,用于替换undefined以删除其他属性
142
+ */
143
+ export declare function filterProperties<T extends Record<string, any>>(obj: T, undefinedValue?: any): T;
138
144
  /**
139
145
  * 合并属性
140
146
  */
@@ -328,6 +328,19 @@ export function queryDeep(obj, keyPath, a, b) {
328
328
  }
329
329
  return obj[keyPath];
330
330
  }
331
+ /**
332
+ * 过滤对象中值为undefined属性
333
+ * @param obj
334
+ * @param undefinedValue 可传入该值,用于替换undefined以删除其他属性
335
+ */
336
+ export function filterProperties(obj, undefinedValue) {
337
+ for (const k in obj) {
338
+ if (obj[k] === undefinedValue) {
339
+ delete obj[k];
340
+ }
341
+ }
342
+ return obj;
343
+ }
331
344
  export function mergeComponentProps(...props) {
332
345
  const { length } = props;
333
346
  if (length <= 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.99",
3
+ "version": "0.0.100",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",