@smilekite/lego-bricks 1.0.6 → 1.0.7

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/README.md CHANGED
@@ -1,8 +1,142 @@
1
1
  # SMILE LEGO 业务组件库
2
2
 
3
+ SMILE LEGO 是一个基于 Vue3 + TypeScript 开发的业务组件库,提供了一系列可复用的 UI 组件,帮助开发者快速构建现代化的 Web 应用。
4
+
3
5
  ## 特性
4
- * **typescript**
5
- * Vue3
6
- * 单元测试
7
- * 提交发布前验证
8
- * travis 实现自动发布
6
+ * **TypeScript 支持**:完整的类型定义,提供良好的开发体验
7
+ * ✅ **Vue3 组合式 API**:采用最新的 Vue3 特性,支持组合式 API
8
+ * ✅ **单元测试**:完善的测试用例,确保组件质量
9
+ * ✅ **提交发布前验证**:自动化的代码检查和测试流程
10
+ * **Travis CI 自动发布**:持续集成,自动发布新版本
11
+ * ✅ **轻量化**:按需引入,减少打包体积
12
+
13
+ ## 安装
14
+
15
+ 使用 npm 安装:
16
+
17
+ ```bash
18
+ npm install @smilekite/lego-bricks
19
+ ```
20
+
21
+ 使用 yarn 安装:
22
+
23
+ ```bash
24
+ yarn add @smilekite/lego-bricks
25
+ ```
26
+
27
+ ## 快速开始
28
+
29
+ ### 全局引入
30
+
31
+ ```javascript
32
+ import { createApp } from 'vue'
33
+ import LegoBricks from '@smilekite/lego-bricks'
34
+ import '@smilekite/lego-bricks/dist/bundle.css'
35
+ import App from './App.vue'
36
+
37
+ const app = createApp(App)
38
+ app.use(LegoBricks)
39
+ app.mount('#app')
40
+ ```
41
+
42
+ ### 按需引入
43
+
44
+ ```javascript
45
+ import { createApp } from 'vue'
46
+ import { LText, LImage, LShape } from '@smilekite/lego-bricks'
47
+ import '@smilekite/lego-bricks/dist/bundle.css'
48
+ import App from './App.vue'
49
+
50
+ const app = createApp(App)
51
+ app.component('LText', LText)
52
+ app.component('LImage', LImage)
53
+ app.component('LShape', LShape)
54
+ app.mount('#app')
55
+ ```
56
+
57
+ ## 组件列表
58
+
59
+ ### LText
60
+ 文本组件,用于展示和编辑文本内容。
61
+
62
+ ### LImage
63
+ 图片组件,用于展示和处理图片。
64
+
65
+ ### LShape
66
+ 形状组件,用于绘制各种几何形状。
67
+
68
+ ### FinalPage
69
+ 最终页面组件,用于展示最终的页面效果。
70
+
71
+ ## 开发指南
72
+
73
+ ### 克隆仓库
74
+
75
+ ```bash
76
+ git clone https://github.com/Kitesource/lego-bricks.git
77
+ cd lego-bricks
78
+ ```
79
+
80
+ ### 安装依赖
81
+
82
+ ```bash
83
+ npm install
84
+ ```
85
+
86
+ ### 启动开发服务器
87
+
88
+ ```bash
89
+ npm run serve
90
+ ```
91
+
92
+ ### 构建组件库
93
+
94
+ ```bash
95
+ npm run build
96
+ ```
97
+
98
+ ### 运行单元测试
99
+
100
+ ```bash
101
+ # 运行所有测试
102
+ npm run test
103
+
104
+ # 监听模式运行测试
105
+ npm run test:watch
106
+ ```
107
+
108
+ ### 代码检查
109
+
110
+ ```bash
111
+ npm run lint
112
+ ```
113
+
114
+ ### 发布
115
+ ```
116
+ npm run publish --access public
117
+ ```
118
+
119
+ ## 项目结构
120
+
121
+ ```
122
+ lego-bricks/
123
+ ├── build/ # 构建配置文件
124
+ ├── dist/ # 构建输出目录
125
+ ├── src/ # 源代码目录
126
+ │ ├── components/ # 组件目录
127
+ │ ├── hooks/ # 自定义 hooks
128
+ │ ├── App.vue # 应用入口组件
129
+ │ ├── index.ts # 组件库入口
130
+ │ └── main.ts # 开发环境入口
131
+ ├── tests/ # 测试目录
132
+ ├── package.json # 项目配置
133
+ └── README.md # 项目说明
134
+ ```
135
+
136
+ ## 贡献指南
137
+
138
+ 1. Fork 仓库
139
+ 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
140
+ 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
141
+ 4. 推送到分支 (`git push origin feature/AmazingFeature`)
142
+ 5. 开启 Pull Request
package/dist/bundle.css CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ .l-image-component[data-v-1e970aa2] {
3
+ max-width: 100%;
4
+ }
5
+
2
6
  h2.l-text-component[data-v-6bf95b7a], p.l-text-component[data-v-6bf95b7a] {
3
7
  margin-bottom: 0;
4
8
  }
@@ -10,7 +14,3 @@ button.l-text-component[data-v-6bf95b7a] {
10
14
  box-sizing: border-box;
11
15
  white-space: pre-wrap;
12
16
  }
13
-
14
- .l-image-component[data-v-1e970aa2] {
15
- max-width: 100%;
16
- }
@@ -1,11 +1,26 @@
1
1
  declare const _default: import("vue").DefineComponent<{
2
- [x: string]: any;
2
+ isEditing: {
3
+ type: BooleanConstructor;
4
+ default: boolean;
5
+ };
6
+ src: {
7
+ type: StringConstructor;
8
+ default: string;
9
+ };
3
10
  }, {
4
- styleProps: import("vue").ComputedRef<Pick<any, string>>;
11
+ styleProps: any;
5
12
  handleClick: () => void;
6
13
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
7
- [x: string]: any;
14
+ isEditing: {
15
+ type: BooleanConstructor;
16
+ default: boolean;
17
+ };
18
+ src: {
19
+ type: StringConstructor;
20
+ default: string;
21
+ };
8
22
  }>>, {
9
- [x: string]: any;
23
+ isEditing: boolean;
24
+ src: string;
10
25
  }, {}>;
11
26
  export default _default;
@@ -1,11 +1,17 @@
1
1
  declare const _default: import("vue").DefineComponent<{
2
- [x: string]: any;
2
+ isEditing: {
3
+ type: BooleanConstructor;
4
+ default: boolean;
5
+ };
3
6
  }, {
4
- styleProps: import("vue").ComputedRef<Pick<any, string>>;
7
+ styleProps: any;
5
8
  handleClick: () => void;
6
9
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
7
- [x: string]: any;
10
+ isEditing: {
11
+ type: BooleanConstructor;
12
+ default: boolean;
13
+ };
8
14
  }>>, {
9
- [x: string]: any;
15
+ isEditing: boolean;
10
16
  }, {}>;
11
17
  export default _default;
@@ -1,11 +1,35 @@
1
1
  declare const _default: import("vue").DefineComponent<{
2
- [x: string]: any;
2
+ isEditing: {
3
+ type: BooleanConstructor;
4
+ default: boolean;
5
+ };
6
+ tag: {
7
+ type: StringConstructor;
8
+ default: string;
9
+ };
10
+ text: {
11
+ type: StringConstructor;
12
+ default: string;
13
+ };
3
14
  }, {
4
- styleProps: import("vue").ComputedRef<Pick<any, string>>;
15
+ styleProps: any;
5
16
  handleClick: () => void;
6
17
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
7
- [x: string]: any;
18
+ isEditing: {
19
+ type: BooleanConstructor;
20
+ default: boolean;
21
+ };
22
+ tag: {
23
+ type: StringConstructor;
24
+ default: string;
25
+ };
26
+ text: {
27
+ type: StringConstructor;
28
+ default: string;
29
+ };
8
30
  }>>, {
9
- [x: string]: any;
31
+ isEditing: boolean;
32
+ tag: string;
33
+ text: string;
10
34
  }, {}>;
11
35
  export default _default;
@@ -28,7 +28,7 @@ export interface PageData {
28
28
  author?: string;
29
29
  status?: string;
30
30
  }
31
- export declare const commonDefaultProps: {
31
+ export interface CommonComponentProps {
32
32
  actionType: string;
33
33
  url: string;
34
34
  height: string;
@@ -42,31 +42,14 @@ export declare const commonDefaultProps: {
42
42
  borderWidth: string;
43
43
  borderRadius: string;
44
44
  boxShadow: string;
45
- opacity: number;
46
- position: string;
47
- left: string;
48
- top: string;
49
- right: string;
50
- };
51
- export declare const textDefaultProps: {
52
- actionType: string;
53
- url: string;
54
- height: string;
55
- width: string;
56
- paddingLeft: string;
57
- paddingRight: string;
58
- paddingTop: string;
59
- paddingBottom: string;
60
- borderStyle: string;
61
- borderColor: string;
62
- borderWidth: string;
63
- borderRadius: string;
64
- boxShadow: string;
65
- opacity: number;
45
+ opacity: string;
66
46
  position: string;
67
47
  left: string;
68
48
  top: string;
69
49
  right: string;
50
+ }
51
+ export declare const commonDefaultProps: CommonComponentProps;
52
+ export interface TextComponentProps extends CommonComponentProps {
70
53
  text: string;
71
54
  fontSize: string;
72
55
  fontFamily: string;
@@ -77,140 +60,29 @@ export declare const textDefaultProps: {
77
60
  textAlign: string;
78
61
  color: string;
79
62
  backgroundColor: string;
80
- };
81
- export declare const imageDefaultProps: {
82
- actionType: string;
83
- url: string;
84
- height: string;
85
- width: string;
86
- paddingLeft: string;
87
- paddingRight: string;
88
- paddingTop: string;
89
- paddingBottom: string;
90
- borderStyle: string;
91
- borderColor: string;
92
- borderWidth: string;
93
- borderRadius: string;
94
- boxShadow: string;
95
- opacity: number;
96
- position: string;
97
- left: string;
98
- top: string;
99
- right: string;
63
+ }
64
+ export interface ImageComponentProps extends CommonComponentProps {
100
65
  src: string;
101
- };
102
- export declare const shapeDefaultProps: {
103
- actionType: string;
104
- url: string;
105
- height: string;
106
- width: string;
107
- paddingLeft: string;
108
- paddingRight: string;
109
- paddingTop: string;
110
- paddingBottom: string;
111
- borderStyle: string;
112
- borderColor: string;
113
- borderWidth: string;
114
- borderRadius: string;
115
- boxShadow: string;
116
- opacity: number;
117
- position: string;
118
- left: string;
119
- top: string;
120
- right: string;
66
+ }
67
+ export interface ShapeComponentProps extends CommonComponentProps {
121
68
  backgroundColor: string;
122
- };
123
- export declare const componentsDefaultProps: {
124
- 'l-text': {
125
- props: {
126
- actionType: string;
127
- url: string;
128
- height: string;
129
- width: string;
130
- paddingLeft: string;
131
- paddingRight: string;
132
- paddingTop: string;
133
- paddingBottom: string;
134
- borderStyle: string;
135
- borderColor: string;
136
- borderWidth: string;
137
- borderRadius: string;
138
- boxShadow: string;
139
- opacity: number;
140
- position: string;
141
- left: string;
142
- top: string;
143
- right: string;
144
- text: string;
145
- fontSize: string;
146
- fontFamily: string;
147
- fontWeight: string;
148
- fontStyle: string;
149
- textDecoration: string;
150
- lineHeight: string;
151
- textAlign: string;
152
- color: string;
153
- backgroundColor: string;
154
- };
155
- };
156
- 'l-image': {
157
- props: {
158
- actionType: string;
159
- url: string;
160
- height: string;
161
- width: string;
162
- paddingLeft: string;
163
- paddingRight: string;
164
- paddingTop: string;
165
- paddingBottom: string;
166
- borderStyle: string;
167
- borderColor: string;
168
- borderWidth: string;
169
- borderRadius: string;
170
- boxShadow: string;
171
- opacity: number;
172
- position: string;
173
- left: string;
174
- top: string;
175
- right: string;
176
- src: string;
177
- };
178
- };
179
- 'l-shape': {
180
- props: {
181
- actionType: string;
182
- url: string;
183
- height: string;
184
- width: string;
185
- paddingLeft: string;
186
- paddingRight: string;
187
- paddingTop: string;
188
- paddingBottom: string;
189
- borderStyle: string;
190
- borderColor: string;
191
- borderWidth: string;
192
- borderRadius: string;
193
- boxShadow: string;
194
- opacity: number;
195
- position: string;
196
- left: string;
197
- top: string;
198
- right: string;
199
- backgroundColor: string;
200
- };
201
- };
202
- };
69
+ }
70
+ export declare type AllComponentProps = TextComponentProps & ImageComponentProps & ShapeComponentProps;
71
+ export declare const textDefaultProps: TextComponentProps;
72
+ export declare const imageDefaultProps: ImageComponentProps;
73
+ export declare const shapeDefaultProps: ShapeComponentProps;
203
74
  export declare const isEditingProp: {
204
75
  isEditing: {
205
76
  type: BooleanConstructor;
206
77
  default: boolean;
207
78
  };
208
79
  };
209
- export declare const transformToComponentProps: (props: {
210
- [key: string]: any;
211
- }, extraProps?: {
212
- [key: string]: any;
213
- } | undefined) => {
214
- [x: string]: any;
80
+ export declare const textStylePropNames: string[];
81
+ export declare const imageStylePropsNames: string[];
82
+ export declare const shapeStylePropsNames: string[];
83
+ export declare const transformToComponentProps: <T extends {}>(props: T) => {
84
+ isEditing: {
85
+ type: BooleanConstructor;
86
+ default: boolean;
87
+ };
215
88
  };
216
- export default componentsDefaultProps;
@@ -0,0 +1,10 @@
1
+ import { CommonComponentProps } from '../defaultProps';
2
+ declare const useComponentCommon: (props: Readonly<Partial<CommonComponentProps & {
3
+ isEditing: boolean;
4
+ }>>, picks: string[]) => {
5
+ styleProps: import("vue").ComputedRef<Partial<Readonly<Partial<CommonComponentProps & {
6
+ isEditing: boolean;
7
+ }>>>>;
8
+ handleClick: () => void;
9
+ };
10
+ export default useComponentCommon;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
+ import { App } from 'vue';
2
+ export { textDefaultProps, textStylePropNames, TextComponentProps, imageDefaultProps, imageStylePropsNames, ImageComponentProps, shapeDefaultProps, shapeStylePropsNames, ShapeComponentProps, AllComponentProps } from './defaultProps';
1
3
  import LText from './components/LText';
2
4
  import LImage from './components/LImage';
3
5
  import LShape from './components/LShape';
4
6
  import FinalPage from './components/FinalPage';
5
- declare const install: (app: any) => void;
6
- export { install, LText, LImage, LShape, FinalPage };
7
+ declare const install: (app: App) => void;
8
+ export { LText, LImage, LShape, install, FinalPage };
7
9
  declare const _default: {
8
- install: (app: any) => void;
10
+ install: (app: App<any>) => void;
9
11
  };
10
12
  export default _default;
@@ -1,14 +1,13 @@
1
- import { computed, defineComponent, openBlock, createBlock, resolveDynamicComponent, withModifiers, normalizeStyle, withCtx, createTextVNode, toDisplayString, createElementBlock, Fragment, renderList, mergeProps } from 'vue';
2
- import { mapValues, pick, without } from 'lodash-es';
1
+ import { without, mapValues, pick } from 'lodash-es';
2
+ import { computed, defineComponent, openBlock, createBlock, resolveDynamicComponent, normalizeStyle, withCtx, createTextVNode, toDisplayString, createElementBlock, withModifiers, Fragment, renderList, mergeProps } from 'vue';
3
3
 
4
- // the common default props, all the components should have these props
5
4
  const commonDefaultProps = {
6
5
  // actions
7
6
  actionType: '',
8
7
  url: '',
9
8
  // size
10
9
  height: '',
11
- width: '318px',
10
+ width: '373px',
12
11
  paddingLeft: '0px',
13
12
  paddingRight: '0px',
14
13
  paddingTop: '0px',
@@ -20,7 +19,7 @@ const commonDefaultProps = {
20
19
  borderRadius: '0',
21
20
  // shadow and opacity
22
21
  boxShadow: '0 0 0 #000000',
23
- opacity: 1,
22
+ opacity: '1',
24
23
  // position and x,y
25
24
  position: 'absolute',
26
25
  left: '0',
@@ -49,73 +48,59 @@ const shapeDefaultProps = {
49
48
  backgroundColor: '',
50
49
  ...commonDefaultProps,
51
50
  };
52
- // this contains all default props for all the components
53
- // useful for inserting new component into the store
54
- const componentsDefaultProps = {
55
- 'l-text': {
56
- props: textDefaultProps,
57
- },
58
- 'l-image': {
59
- props: imageDefaultProps,
60
- },
61
- 'l-shape': {
62
- props: shapeDefaultProps,
63
- },
64
- };
65
51
  const isEditingProp = {
66
52
  isEditing: {
67
53
  type: Boolean,
68
54
  default: false,
69
55
  },
70
56
  };
71
- const transformToComponentProps = (props, extraProps) => {
72
- const mapProps = mapValues(props, item => {
57
+ const textStylePropNames = without(Object.keys(textDefaultProps), 'actionType', 'url', 'text');
58
+ const imageStylePropsNames = without(Object.keys(imageDefaultProps), 'actionType', 'url', 'src');
59
+ const shapeStylePropsNames = without(Object.keys(shapeDefaultProps), 'actionType', 'url');
60
+ const transformToComponentProps = (props) => {
61
+ const mapProps = mapValues(props, (item) => {
73
62
  return {
74
63
  type: item.constructor,
75
64
  default: item,
76
65
  };
77
66
  });
78
- if (extraProps) {
79
- return { ...mapProps, ...extraProps };
80
- }
81
- else {
82
- return mapProps;
83
- }
67
+ return { ...mapProps, ...isEditingProp };
84
68
  };
85
69
 
86
- const defaultStyles = without(Object.keys(textDefaultProps), 'actionType', 'url', 'text');
87
- const useStylePick = (props, pickStyles = defaultStyles) => {
88
- return computed(() => pick(props, pickStyles));
89
- };
90
-
91
- const useComponentClick = (props) => {
70
+ const useComponentCommon = (props, picks) => {
71
+ const styleProps = computed(() => pick(props, picks));
92
72
  const handleClick = () => {
93
- if (props.actionType && props.url && !props.isEditing) {
73
+ if (props.actionType === 'url' && props.url && !props.isEditing) {
94
74
  window.location.href = props.url;
95
75
  }
96
76
  };
97
- return handleClick;
77
+ return {
78
+ styleProps,
79
+ handleClick
80
+ };
98
81
  };
99
82
 
100
- const extraProps = {
101
- tag: {
102
- type: String,
103
- default: 'div'
104
- },
105
- ...isEditingProp
106
- };
107
- const defaultProps = transformToComponentProps(componentsDefaultProps['l-text'].props, extraProps);
83
+ const defaultProps = transformToComponentProps(textDefaultProps);
108
84
  // array that contains style props
109
85
  var script = defineComponent({
110
86
  name: 'l-text',
111
87
  props: {
88
+ tag: {
89
+ type: String,
90
+ default: 'div'
91
+ },
92
+ text: {
93
+ type: String,
94
+ default: ''
95
+ },
112
96
  ...defaultProps
113
97
  },
114
98
  setup(props) {
115
- const styleProps = useStylePick(props);
116
- const handleClick = useComponentClick(props);
99
+ // 重用并且简化
100
+ // 抽离并且获得 styleProps
101
+ const { styleProps, handleClick } = useComponentCommon(props, textStylePropNames);
117
102
  return {
118
- styleProps,
103
+ styleProps: styleProps.value,
119
104
  handleClick
120
105
  };
121
106
  }
@@ -123,15 +108,15 @@ var script = defineComponent({
123
108
 
124
109
  function render(_ctx, _cache, $props, $setup, $data, $options) {
125
110
  return (openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), {
126
- onClick: withModifiers(_ctx.handleClick, ["prevent"]),
127
111
  style: normalizeStyle(_ctx.styleProps),
128
- class: "l-text-component"
112
+ class: "l-text-component",
113
+ onClick: _ctx.handleClick
129
114
  }, {
130
115
  default: withCtx(() => [
131
116
  createTextVNode(toDisplayString(_ctx.text), 1 /* TEXT */)
132
117
  ]),
133
118
  _: 1 /* STABLE */
134
- }, 8 /* PROPS */, ["onClick", "style"]))
119
+ }, 8 /* PROPS */, ["style", "onClick"]))
135
120
  }
136
121
 
137
122
  script.render = render;
@@ -142,29 +127,36 @@ script.install = (app) => {
142
127
  app.component(script.name, script);
143
128
  };
144
129
 
130
+ const defaultProps$1 = transformToComponentProps(imageDefaultProps);
145
131
  // array that contains style props
146
132
  var script$1 = defineComponent({
147
133
  name: 'l-image',
148
- props: transformToComponentProps(componentsDefaultProps['l-image'].props, isEditingProp),
134
+ props: {
135
+ src: {
136
+ type: String,
137
+ default: ''
138
+ },
139
+ ...defaultProps$1
140
+ },
149
141
  setup(props) {
150
- const styleProps = useStylePick(props);
151
- const handleClick = useComponentClick(props);
142
+ // 重用并且简化
143
+ // 抽离并且获得 styleProps
144
+ const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames);
152
145
  return {
153
- styleProps,
146
+ styleProps: styleProps.value,
154
147
  handleClick
155
148
  };
156
- }
149
+ },
157
150
  });
158
151
 
159
152
  const _hoisted_1 = ["src"];
160
153
 
161
154
  function render$1(_ctx, _cache, $props, $setup, $data, $options) {
162
155
  return (openBlock(), createElementBlock("img", {
163
- src: _ctx.src,
164
156
  style: normalizeStyle(_ctx.styleProps),
165
- draggable: false,
166
157
  class: "l-image-component",
167
- onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
158
+ onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
159
+ src: _ctx.src
168
160
  }, null, 12 /* STYLE, PROPS */, _hoisted_1))
169
161
  }
170
162
 
@@ -176,18 +168,19 @@ script$1.install = (app) => {
176
168
  app.component(script$1.name, script$1);
177
169
  };
178
170
 
179
- const defaultProps$1 = transformToComponentProps(componentsDefaultProps['l-shape'].props, isEditingProp);
171
+ const defaultProps$2 = transformToComponentProps(shapeDefaultProps);
180
172
  // array that contains style props
181
173
  var script$2 = defineComponent({
182
174
  name: 'l-shape',
183
175
  props: {
184
- ...defaultProps$1
176
+ ...defaultProps$2
185
177
  },
186
178
  setup(props) {
187
- const styleProps = useStylePick(props);
188
- const handleClick = useComponentClick(props);
179
+ // 重用并且简化
180
+ // 抽离并且获得 styleProps
181
+ const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames);
189
182
  return {
190
- styleProps,
183
+ styleProps: styleProps.value,
191
184
  handleClick
192
185
  };
193
186
  }
@@ -195,10 +188,9 @@ var script$2 = defineComponent({
195
188
 
196
189
  function render$2(_ctx, _cache, $props, $setup, $data, $options) {
197
190
  return (openBlock(), createElementBlock("div", {
198
- onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
199
191
  style: normalizeStyle(_ctx.styleProps),
200
192
  class: "l-shape-component",
201
- draggable: false
193
+ onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
202
194
  }, null, 4 /* STYLE */))
203
195
  }
204
196
 
@@ -247,15 +239,19 @@ script$3.install = (app) => {
247
239
  app.component(script$3.name, script$3);
248
240
  };
249
241
 
250
- const components = [script, script$1, script$2, script$3];
242
+ const components = [
243
+ script,
244
+ script$1,
245
+ script$2
246
+ ];
251
247
  const install = (app) => {
252
- components.map(component => {
253
- app.use(component);
248
+ components.forEach((component) => {
249
+ app.component(component.name, component);
254
250
  });
255
251
  };
256
252
  var index = {
257
- install,
253
+ install
258
254
  };
259
255
 
260
256
  export default index;
261
- export { script$3 as FinalPage, script$1 as LImage, script$2 as LShape, script as LText, install };
257
+ export { script$3 as FinalPage, script$1 as LImage, script$2 as LShape, script as LText, imageDefaultProps, imageStylePropsNames, install, shapeDefaultProps, shapeStylePropsNames, textDefaultProps, textStylePropNames };
@@ -1,17 +1,16 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('lodash-es')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', 'lodash-es'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.LegoComponents = {}, global.Vue, global._));
5
- }(this, (function (exports, vue, lodashEs) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es'), require('vue')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'lodash-es', 'vue'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.LegoComponents = {}, global._, global.Vue));
5
+ }(this, (function (exports, lodashEs, vue) { 'use strict';
6
6
 
7
- // the common default props, all the components should have these props
8
7
  const commonDefaultProps = {
9
8
  // actions
10
9
  actionType: '',
11
10
  url: '',
12
11
  // size
13
12
  height: '',
14
- width: '318px',
13
+ width: '373px',
15
14
  paddingLeft: '0px',
16
15
  paddingRight: '0px',
17
16
  paddingTop: '0px',
@@ -23,7 +22,7 @@
23
22
  borderRadius: '0',
24
23
  // shadow and opacity
25
24
  boxShadow: '0 0 0 #000000',
26
- opacity: 1,
25
+ opacity: '1',
27
26
  // position and x,y
28
27
  position: 'absolute',
29
28
  left: '0',
@@ -52,73 +51,59 @@
52
51
  backgroundColor: '',
53
52
  ...commonDefaultProps,
54
53
  };
55
- // this contains all default props for all the components
56
- // useful for inserting new component into the store
57
- const componentsDefaultProps = {
58
- 'l-text': {
59
- props: textDefaultProps,
60
- },
61
- 'l-image': {
62
- props: imageDefaultProps,
63
- },
64
- 'l-shape': {
65
- props: shapeDefaultProps,
66
- },
67
- };
68
54
  const isEditingProp = {
69
55
  isEditing: {
70
56
  type: Boolean,
71
57
  default: false,
72
58
  },
73
59
  };
74
- const transformToComponentProps = (props, extraProps) => {
75
- const mapProps = lodashEs.mapValues(props, item => {
60
+ const textStylePropNames = lodashEs.without(Object.keys(textDefaultProps), 'actionType', 'url', 'text');
61
+ const imageStylePropsNames = lodashEs.without(Object.keys(imageDefaultProps), 'actionType', 'url', 'src');
62
+ const shapeStylePropsNames = lodashEs.without(Object.keys(shapeDefaultProps), 'actionType', 'url');
63
+ const transformToComponentProps = (props) => {
64
+ const mapProps = lodashEs.mapValues(props, (item) => {
76
65
  return {
77
66
  type: item.constructor,
78
67
  default: item,
79
68
  };
80
69
  });
81
- if (extraProps) {
82
- return { ...mapProps, ...extraProps };
83
- }
84
- else {
85
- return mapProps;
86
- }
70
+ return { ...mapProps, ...isEditingProp };
87
71
  };
88
72
 
89
- const defaultStyles = lodashEs.without(Object.keys(textDefaultProps), 'actionType', 'url', 'text');
90
- const useStylePick = (props, pickStyles = defaultStyles) => {
91
- return vue.computed(() => lodashEs.pick(props, pickStyles));
92
- };
93
-
94
- const useComponentClick = (props) => {
73
+ const useComponentCommon = (props, picks) => {
74
+ const styleProps = vue.computed(() => lodashEs.pick(props, picks));
95
75
  const handleClick = () => {
96
- if (props.actionType && props.url && !props.isEditing) {
76
+ if (props.actionType === 'url' && props.url && !props.isEditing) {
97
77
  window.location.href = props.url;
98
78
  }
99
79
  };
100
- return handleClick;
80
+ return {
81
+ styleProps,
82
+ handleClick
83
+ };
101
84
  };
102
85
 
103
- const extraProps = {
104
- tag: {
105
- type: String,
106
- default: 'div'
107
- },
108
- ...isEditingProp
109
- };
110
- const defaultProps = transformToComponentProps(componentsDefaultProps['l-text'].props, extraProps);
86
+ const defaultProps = transformToComponentProps(textDefaultProps);
111
87
  // array that contains style props
112
88
  var script = vue.defineComponent({
113
89
  name: 'l-text',
114
90
  props: {
91
+ tag: {
92
+ type: String,
93
+ default: 'div'
94
+ },
95
+ text: {
96
+ type: String,
97
+ default: ''
98
+ },
115
99
  ...defaultProps
116
100
  },
117
101
  setup(props) {
118
- const styleProps = useStylePick(props);
119
- const handleClick = useComponentClick(props);
102
+ // 重用并且简化
103
+ // 抽离并且获得 styleProps
104
+ const { styleProps, handleClick } = useComponentCommon(props, textStylePropNames);
120
105
  return {
121
- styleProps,
106
+ styleProps: styleProps.value,
122
107
  handleClick
123
108
  };
124
109
  }
@@ -126,15 +111,15 @@
126
111
 
127
112
  function render(_ctx, _cache, $props, $setup, $data, $options) {
128
113
  return (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.tag), {
129
- onClick: vue.withModifiers(_ctx.handleClick, ["prevent"]),
130
114
  style: vue.normalizeStyle(_ctx.styleProps),
131
- class: "l-text-component"
115
+ class: "l-text-component",
116
+ onClick: _ctx.handleClick
132
117
  }, {
133
118
  default: vue.withCtx(() => [
134
119
  vue.createTextVNode(vue.toDisplayString(_ctx.text), 1 /* TEXT */)
135
120
  ]),
136
121
  _: 1 /* STABLE */
137
- }, 8 /* PROPS */, ["onClick", "style"]))
122
+ }, 8 /* PROPS */, ["style", "onClick"]))
138
123
  }
139
124
 
140
125
  script.render = render;
@@ -145,29 +130,36 @@
145
130
  app.component(script.name, script);
146
131
  };
147
132
 
133
+ const defaultProps$1 = transformToComponentProps(imageDefaultProps);
148
134
  // array that contains style props
149
135
  var script$1 = vue.defineComponent({
150
136
  name: 'l-image',
151
- props: transformToComponentProps(componentsDefaultProps['l-image'].props, isEditingProp),
137
+ props: {
138
+ src: {
139
+ type: String,
140
+ default: ''
141
+ },
142
+ ...defaultProps$1
143
+ },
152
144
  setup(props) {
153
- const styleProps = useStylePick(props);
154
- const handleClick = useComponentClick(props);
145
+ // 重用并且简化
146
+ // 抽离并且获得 styleProps
147
+ const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames);
155
148
  return {
156
- styleProps,
149
+ styleProps: styleProps.value,
157
150
  handleClick
158
151
  };
159
- }
152
+ },
160
153
  });
161
154
 
162
155
  const _hoisted_1 = ["src"];
163
156
 
164
157
  function render$1(_ctx, _cache, $props, $setup, $data, $options) {
165
158
  return (vue.openBlock(), vue.createElementBlock("img", {
166
- src: _ctx.src,
167
159
  style: vue.normalizeStyle(_ctx.styleProps),
168
- draggable: false,
169
160
  class: "l-image-component",
170
- onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
161
+ onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
162
+ src: _ctx.src
171
163
  }, null, 12 /* STYLE, PROPS */, _hoisted_1))
172
164
  }
173
165
 
@@ -179,18 +171,19 @@
179
171
  app.component(script$1.name, script$1);
180
172
  };
181
173
 
182
- const defaultProps$1 = transformToComponentProps(componentsDefaultProps['l-shape'].props, isEditingProp);
174
+ const defaultProps$2 = transformToComponentProps(shapeDefaultProps);
183
175
  // array that contains style props
184
176
  var script$2 = vue.defineComponent({
185
177
  name: 'l-shape',
186
178
  props: {
187
- ...defaultProps$1
179
+ ...defaultProps$2
188
180
  },
189
181
  setup(props) {
190
- const styleProps = useStylePick(props);
191
- const handleClick = useComponentClick(props);
182
+ // 重用并且简化
183
+ // 抽离并且获得 styleProps
184
+ const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames);
192
185
  return {
193
- styleProps,
186
+ styleProps: styleProps.value,
194
187
  handleClick
195
188
  };
196
189
  }
@@ -198,10 +191,9 @@
198
191
 
199
192
  function render$2(_ctx, _cache, $props, $setup, $data, $options) {
200
193
  return (vue.openBlock(), vue.createElementBlock("div", {
201
- onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
202
194
  style: vue.normalizeStyle(_ctx.styleProps),
203
195
  class: "l-shape-component",
204
- draggable: false
196
+ onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
205
197
  }, null, 4 /* STYLE */))
206
198
  }
207
199
 
@@ -250,14 +242,18 @@
250
242
  app.component(script$3.name, script$3);
251
243
  };
252
244
 
253
- const components = [script, script$1, script$2, script$3];
245
+ const components = [
246
+ script,
247
+ script$1,
248
+ script$2
249
+ ];
254
250
  const install = (app) => {
255
- components.map(component => {
256
- app.use(component);
251
+ components.forEach((component) => {
252
+ app.component(component.name, component);
257
253
  });
258
254
  };
259
255
  var index = {
260
- install,
256
+ install
261
257
  };
262
258
 
263
259
  exports.FinalPage = script$3;
@@ -265,7 +261,13 @@
265
261
  exports.LShape = script$2;
266
262
  exports.LText = script;
267
263
  exports.default = index;
264
+ exports.imageDefaultProps = imageDefaultProps;
265
+ exports.imageStylePropsNames = imageStylePropsNames;
268
266
  exports.install = install;
267
+ exports.shapeDefaultProps = shapeDefaultProps;
268
+ exports.shapeStylePropsNames = shapeStylePropsNames;
269
+ exports.textDefaultProps = textDefaultProps;
270
+ exports.textStylePropNames = textStylePropNames;
269
271
 
270
272
  Object.defineProperty(exports, '__esModule', { value: true });
271
273
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smilekite/lego-bricks",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "author": "smiley",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -1,2 +0,0 @@
1
- declare const useComponentClick: (props: any) => () => void;
2
- export default useComponentClick;
@@ -1,3 +0,0 @@
1
- export declare const defaultStyles: string[];
2
- declare const useStylePick: (props: any, pickStyles?: string[]) => import("vue").ComputedRef<Pick<any, string>>;
3
- export default useStylePick;