@smilekite/lego-bricks 1.0.5 → 1.0.6

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,8 @@
1
- # SMILE LEGO 业务组件库
2
-
3
- ## 特性
4
- * **typescript**
5
- * Vue3
6
- * 单元测试
7
- * 提交发布前验证
1
+ # SMILE LEGO 业务组件库
2
+
3
+ ## 特性
4
+ * **typescript**
5
+ * Vue3
6
+ * 单元测试
7
+ * 提交发布前验证
8
8
  * travis 实现自动发布
package/dist/bundle.css CHANGED
@@ -1,16 +1,16 @@
1
1
 
2
- .l-image-component[data-v-1e970aa2] {
3
- max-width: 100%;
4
- }
5
-
6
- h2.l-text-component[data-v-6bf95b7a], p.l-text-component[data-v-6bf95b7a] {
2
+ h2.l-text-component[data-v-6bf95b7a], p.l-text-component[data-v-6bf95b7a] {
7
3
  margin-bottom: 0;
8
4
  }
9
- button.l-text-component[data-v-6bf95b7a] {
10
- padding: 5px 10px;
5
+ button.l-text-component[data-v-6bf95b7a] {
6
+ padding: 5px 10px;
11
7
  cursor: pointer;
12
8
  }
13
- .l-text-component[data-v-6bf95b7a] {
14
- box-sizing: border-box;
9
+ .l-text-component[data-v-6bf95b7a] {
10
+ box-sizing: border-box;
15
11
  white-space: pre-wrap;
16
- }
12
+ }
13
+
14
+ .l-image-component[data-v-1e970aa2] {
15
+ max-width: 100%;
16
+ }
@@ -1,19 +1,11 @@
1
1
  declare const _default: import("vue").DefineComponent<{
2
- isEditing: {
3
- type: BooleanConstructor;
4
- default: boolean;
5
- };
2
+ [x: string]: any;
6
3
  }, {
7
- styleProps: import("vue").ComputedRef<Partial<Readonly<Partial<import("../../defaultProps").CommonComponentProps & {
8
- isEditing: boolean;
9
- }>>>>;
4
+ styleProps: import("vue").ComputedRef<Pick<any, string>>;
10
5
  handleClick: () => void;
11
6
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
12
- isEditing: {
13
- type: BooleanConstructor;
14
- default: boolean;
15
- };
7
+ [x: string]: any;
16
8
  }>>, {
17
- isEditing: boolean;
9
+ [x: string]: any;
18
10
  }, {}>;
19
11
  export default _default;
@@ -1,19 +1,11 @@
1
1
  declare const _default: import("vue").DefineComponent<{
2
- isEditing: {
3
- type: BooleanConstructor;
4
- default: boolean;
5
- };
2
+ [x: string]: any;
6
3
  }, {
7
- styleProps: import("vue").ComputedRef<Partial<Readonly<Partial<import("../../defaultProps").CommonComponentProps & {
8
- isEditing: boolean;
9
- }>>>>;
4
+ styleProps: import("vue").ComputedRef<Pick<any, string>>;
10
5
  handleClick: () => void;
11
6
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
12
- isEditing: {
13
- type: BooleanConstructor;
14
- default: boolean;
15
- };
7
+ [x: string]: any;
16
8
  }>>, {
17
- isEditing: boolean;
9
+ [x: string]: any;
18
10
  }, {}>;
19
11
  export default _default;
@@ -1,28 +1,11 @@
1
1
  declare const _default: import("vue").DefineComponent<{
2
- isEditing: {
3
- type: BooleanConstructor;
4
- default: boolean;
5
- };
6
- tag: {
7
- type: StringConstructor;
8
- default: string;
9
- };
2
+ [x: string]: any;
10
3
  }, {
11
- styleProps: import("vue").ComputedRef<Partial<Readonly<Partial<import("../../defaultProps").CommonComponentProps & {
12
- isEditing: boolean;
13
- }>>>>;
4
+ styleProps: import("vue").ComputedRef<Pick<any, string>>;
14
5
  handleClick: () => void;
15
6
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
16
- isEditing: {
17
- type: BooleanConstructor;
18
- default: boolean;
19
- };
20
- tag: {
21
- type: StringConstructor;
22
- default: string;
23
- };
7
+ [x: string]: any;
24
8
  }>>, {
25
- isEditing: boolean;
26
- tag: string;
9
+ [x: string]: any;
27
10
  }, {}>;
28
11
  export default _default;
@@ -28,7 +28,7 @@ export interface PageData {
28
28
  author?: string;
29
29
  status?: string;
30
30
  }
31
- export interface CommonComponentProps {
31
+ export declare const commonDefaultProps: {
32
32
  actionType: string;
33
33
  url: string;
34
34
  height: string;
@@ -42,14 +42,31 @@ export interface CommonComponentProps {
42
42
  borderWidth: string;
43
43
  borderRadius: string;
44
44
  boxShadow: string;
45
- opacity: 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;
46
66
  position: string;
47
67
  left: string;
48
68
  top: string;
49
69
  right: string;
50
- }
51
- export declare const commonDefaultProps: CommonComponentProps;
52
- export interface TextComponentProps extends CommonComponentProps {
53
70
  text: string;
54
71
  fontSize: string;
55
72
  fontFamily: string;
@@ -60,29 +77,140 @@ export interface TextComponentProps extends CommonComponentProps {
60
77
  textAlign: string;
61
78
  color: string;
62
79
  backgroundColor: string;
63
- }
64
- export interface ImageComponentProps extends CommonComponentProps {
65
- imageSrc: string;
66
- }
67
- export interface ShapeComponentProps extends CommonComponentProps {
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;
100
+ 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;
68
121
  backgroundColor: string;
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;
74
- export declare const isEditingProp: {
75
- isEditing: {
76
- type: BooleanConstructor;
77
- default: boolean;
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
+ };
78
201
  };
79
202
  };
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) => {
203
+ export declare const isEditingProp: {
84
204
  isEditing: {
85
205
  type: BooleanConstructor;
86
206
  default: boolean;
87
207
  };
88
208
  };
209
+ export declare const transformToComponentProps: (props: {
210
+ [key: string]: any;
211
+ }, extraProps?: {
212
+ [key: string]: any;
213
+ } | undefined) => {
214
+ [x: string]: any;
215
+ };
216
+ export default componentsDefaultProps;
@@ -0,0 +1,2 @@
1
+ declare const useComponentClick: (props: any) => () => void;
2
+ export default useComponentClick;
@@ -0,0 +1,3 @@
1
+ export declare const defaultStyles: string[];
2
+ declare const useStylePick: (props: any, pickStyles?: string[]) => import("vue").ComputedRef<Pick<any, string>>;
3
+ export default useStylePick;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,10 @@
1
- import { App } from 'vue';
2
- export { textDefaultProps, textStylePropNames, TextComponentProps, imageDefaultProps, imageStylePropsNames, ImageComponentProps, shapeDefaultProps, shapeStylePropsNames, ShapeComponentProps, AllComponentProps } from './defaultProps';
3
1
  import LText from './components/LText';
4
2
  import LImage from './components/LImage';
5
3
  import LShape from './components/LShape';
6
4
  import FinalPage from './components/FinalPage';
7
- declare const install: (app: App) => void;
8
- export { LText, LImage, LShape, install, FinalPage };
5
+ declare const install: (app: any) => void;
6
+ export { install, LText, LImage, LShape, FinalPage };
9
7
  declare const _default: {
10
- install: (app: App<any>) => void;
8
+ install: (app: any) => void;
11
9
  };
12
10
  export default _default;
@@ -1,13 +1,14 @@
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';
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';
3
3
 
4
+ // the common default props, all the components should have these props
4
5
  const commonDefaultProps = {
5
6
  // actions
6
7
  actionType: '',
7
8
  url: '',
8
9
  // size
9
10
  height: '',
10
- width: '373px',
11
+ width: '318px',
11
12
  paddingLeft: '0px',
12
13
  paddingRight: '0px',
13
14
  paddingTop: '0px',
@@ -19,12 +20,12 @@ const commonDefaultProps = {
19
20
  borderRadius: '0',
20
21
  // shadow and opacity
21
22
  boxShadow: '0 0 0 #000000',
22
- opacity: '1',
23
+ opacity: 1,
23
24
  // position and x,y
24
25
  position: 'absolute',
25
26
  left: '0',
26
27
  top: '0',
27
- right: '0'
28
+ right: '0',
28
29
  };
29
30
  const textDefaultProps = {
30
31
  // basic props - font styles
@@ -38,63 +39,81 @@ const textDefaultProps = {
38
39
  textAlign: 'left',
39
40
  color: '#000000',
40
41
  backgroundColor: '',
41
- ...commonDefaultProps
42
+ ...commonDefaultProps,
42
43
  };
43
44
  const imageDefaultProps = {
44
- imageSrc: '',
45
- ...commonDefaultProps
45
+ src: '',
46
+ ...commonDefaultProps,
46
47
  };
47
48
  const shapeDefaultProps = {
48
49
  backgroundColor: '',
49
- ...commonDefaultProps
50
+ ...commonDefaultProps,
51
+ };
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
+ },
50
64
  };
51
65
  const isEditingProp = {
52
66
  isEditing: {
53
67
  type: Boolean,
54
- default: false
55
- }
68
+ default: false,
69
+ },
56
70
  };
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) => {
71
+ const transformToComponentProps = (props, extraProps) => {
72
+ const mapProps = mapValues(props, item => {
62
73
  return {
63
74
  type: item.constructor,
64
- default: item
75
+ default: item,
65
76
  };
66
77
  });
67
- return { ...mapProps, ...isEditingProp };
78
+ if (extraProps) {
79
+ return { ...mapProps, ...extraProps };
80
+ }
81
+ else {
82
+ return mapProps;
83
+ }
68
84
  };
69
85
 
70
- const useComponentCommon = (props, picks) => {
71
- const styleProps = computed(() => pick(props, picks));
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) => {
72
92
  const handleClick = () => {
73
- if (props.actionType === 'url' && props.url && !props.isEditing) {
93
+ if (props.actionType && props.url && !props.isEditing) {
74
94
  window.location.href = props.url;
75
95
  }
76
96
  };
77
- return {
78
- styleProps,
79
- handleClick
80
- };
97
+ return handleClick;
81
98
  };
82
99
 
83
- const defaultProps = transformToComponentProps(textDefaultProps);
100
+ const extraProps = {
101
+ tag: {
102
+ type: String,
103
+ default: 'div'
104
+ },
105
+ ...isEditingProp
106
+ };
107
+ const defaultProps = transformToComponentProps(componentsDefaultProps['l-text'].props, extraProps);
84
108
  // array that contains style props
85
109
  var script = defineComponent({
86
110
  name: 'l-text',
87
111
  props: {
88
- tag: {
89
- type: String,
90
- default: 'div'
91
- },
92
112
  ...defaultProps
93
113
  },
94
114
  setup(props) {
95
- // 重用并且简化
96
- // 抽离并且获得 styleProps
97
- const { styleProps, handleClick } = useComponentCommon(props, textStylePropNames);
115
+ const styleProps = useStylePick(props);
116
+ const handleClick = useComponentClick(props);
98
117
  return {
99
118
  styleProps,
100
119
  handleClick
@@ -104,15 +123,15 @@ var script = defineComponent({
104
123
 
105
124
  function render(_ctx, _cache, $props, $setup, $data, $options) {
106
125
  return (openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), {
126
+ onClick: withModifiers(_ctx.handleClick, ["prevent"]),
107
127
  style: normalizeStyle(_ctx.styleProps),
108
- class: "l-text-component",
109
- onClick: _ctx.handleClick
128
+ class: "l-text-component"
110
129
  }, {
111
130
  default: withCtx(() => [
112
131
  createTextVNode(toDisplayString(_ctx.text), 1 /* TEXT */)
113
132
  ]),
114
133
  _: 1 /* STABLE */
115
- }, 8 /* PROPS */, ["style", "onClick"]))
134
+ }, 8 /* PROPS */, ["onClick", "style"]))
116
135
  }
117
136
 
118
137
  script.render = render;
@@ -123,17 +142,13 @@ script.install = (app) => {
123
142
  app.component(script.name, script);
124
143
  };
125
144
 
126
- const defaultProps$1 = transformToComponentProps(imageDefaultProps);
127
145
  // array that contains style props
128
146
  var script$1 = defineComponent({
129
147
  name: 'l-image',
130
- props: {
131
- ...defaultProps$1
132
- },
148
+ props: transformToComponentProps(componentsDefaultProps['l-image'].props, isEditingProp),
133
149
  setup(props) {
134
- // 重用并且简化
135
- // 抽离并且获得 styleProps
136
- const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames);
150
+ const styleProps = useStylePick(props);
151
+ const handleClick = useComponentClick(props);
137
152
  return {
138
153
  styleProps,
139
154
  handleClick
@@ -145,10 +160,11 @@ const _hoisted_1 = ["src"];
145
160
 
146
161
  function render$1(_ctx, _cache, $props, $setup, $data, $options) {
147
162
  return (openBlock(), createElementBlock("img", {
163
+ src: _ctx.src,
148
164
  style: normalizeStyle(_ctx.styleProps),
165
+ draggable: false,
149
166
  class: "l-image-component",
150
- onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
151
- src: _ctx.src
167
+ onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
152
168
  }, null, 12 /* STYLE, PROPS */, _hoisted_1))
153
169
  }
154
170
 
@@ -160,17 +176,16 @@ script$1.install = (app) => {
160
176
  app.component(script$1.name, script$1);
161
177
  };
162
178
 
163
- const defaultProps$2 = transformToComponentProps(shapeDefaultProps);
179
+ const defaultProps$1 = transformToComponentProps(componentsDefaultProps['l-shape'].props, isEditingProp);
164
180
  // array that contains style props
165
181
  var script$2 = defineComponent({
166
182
  name: 'l-shape',
167
183
  props: {
168
- ...defaultProps$2
184
+ ...defaultProps$1
169
185
  },
170
186
  setup(props) {
171
- // 重用并且简化
172
- // 抽离并且获得 styleProps
173
- const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames);
187
+ const styleProps = useStylePick(props);
188
+ const handleClick = useComponentClick(props);
174
189
  return {
175
190
  styleProps,
176
191
  handleClick
@@ -180,9 +195,10 @@ var script$2 = defineComponent({
180
195
 
181
196
  function render$2(_ctx, _cache, $props, $setup, $data, $options) {
182
197
  return (openBlock(), createElementBlock("div", {
198
+ onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
183
199
  style: normalizeStyle(_ctx.styleProps),
184
200
  class: "l-shape-component",
185
- onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
201
+ draggable: false
186
202
  }, null, 4 /* STYLE */))
187
203
  }
188
204
 
@@ -231,19 +247,15 @@ script$3.install = (app) => {
231
247
  app.component(script$3.name, script$3);
232
248
  };
233
249
 
234
- const components = [
235
- script,
236
- script$1,
237
- script$2
238
- ];
250
+ const components = [script, script$1, script$2, script$3];
239
251
  const install = (app) => {
240
- components.forEach((component) => {
241
- app.component(component.name, component);
252
+ components.map(component => {
253
+ app.use(component);
242
254
  });
243
255
  };
244
256
  var index = {
245
- install
257
+ install,
246
258
  };
247
259
 
248
260
  export default index;
249
- export { script$3 as FinalPage, script$1 as LImage, script$2 as LShape, script as LText, imageDefaultProps, imageStylePropsNames, install, shapeDefaultProps, shapeStylePropsNames, textDefaultProps, textStylePropNames };
261
+ export { script$3 as FinalPage, script$1 as LImage, script$2 as LShape, script as LText, install };
@@ -1,16 +1,17 @@
1
1
  (function (global, factory) {
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';
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';
6
6
 
7
+ // the common default props, all the components should have these props
7
8
  const commonDefaultProps = {
8
9
  // actions
9
10
  actionType: '',
10
11
  url: '',
11
12
  // size
12
13
  height: '',
13
- width: '373px',
14
+ width: '318px',
14
15
  paddingLeft: '0px',
15
16
  paddingRight: '0px',
16
17
  paddingTop: '0px',
@@ -22,12 +23,12 @@
22
23
  borderRadius: '0',
23
24
  // shadow and opacity
24
25
  boxShadow: '0 0 0 #000000',
25
- opacity: '1',
26
+ opacity: 1,
26
27
  // position and x,y
27
28
  position: 'absolute',
28
29
  left: '0',
29
30
  top: '0',
30
- right: '0'
31
+ right: '0',
31
32
  };
32
33
  const textDefaultProps = {
33
34
  // basic props - font styles
@@ -41,63 +42,81 @@
41
42
  textAlign: 'left',
42
43
  color: '#000000',
43
44
  backgroundColor: '',
44
- ...commonDefaultProps
45
+ ...commonDefaultProps,
45
46
  };
46
47
  const imageDefaultProps = {
47
- imageSrc: '',
48
- ...commonDefaultProps
48
+ src: '',
49
+ ...commonDefaultProps,
49
50
  };
50
51
  const shapeDefaultProps = {
51
52
  backgroundColor: '',
52
- ...commonDefaultProps
53
+ ...commonDefaultProps,
54
+ };
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
+ },
53
67
  };
54
68
  const isEditingProp = {
55
69
  isEditing: {
56
70
  type: Boolean,
57
- default: false
58
- }
71
+ default: false,
72
+ },
59
73
  };
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) => {
74
+ const transformToComponentProps = (props, extraProps) => {
75
+ const mapProps = lodashEs.mapValues(props, item => {
65
76
  return {
66
77
  type: item.constructor,
67
- default: item
78
+ default: item,
68
79
  };
69
80
  });
70
- return { ...mapProps, ...isEditingProp };
81
+ if (extraProps) {
82
+ return { ...mapProps, ...extraProps };
83
+ }
84
+ else {
85
+ return mapProps;
86
+ }
71
87
  };
72
88
 
73
- const useComponentCommon = (props, picks) => {
74
- const styleProps = vue.computed(() => lodashEs.pick(props, picks));
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) => {
75
95
  const handleClick = () => {
76
- if (props.actionType === 'url' && props.url && !props.isEditing) {
96
+ if (props.actionType && props.url && !props.isEditing) {
77
97
  window.location.href = props.url;
78
98
  }
79
99
  };
80
- return {
81
- styleProps,
82
- handleClick
83
- };
100
+ return handleClick;
84
101
  };
85
102
 
86
- const defaultProps = transformToComponentProps(textDefaultProps);
103
+ const extraProps = {
104
+ tag: {
105
+ type: String,
106
+ default: 'div'
107
+ },
108
+ ...isEditingProp
109
+ };
110
+ const defaultProps = transformToComponentProps(componentsDefaultProps['l-text'].props, extraProps);
87
111
  // array that contains style props
88
112
  var script = vue.defineComponent({
89
113
  name: 'l-text',
90
114
  props: {
91
- tag: {
92
- type: String,
93
- default: 'div'
94
- },
95
115
  ...defaultProps
96
116
  },
97
117
  setup(props) {
98
- // 重用并且简化
99
- // 抽离并且获得 styleProps
100
- const { styleProps, handleClick } = useComponentCommon(props, textStylePropNames);
118
+ const styleProps = useStylePick(props);
119
+ const handleClick = useComponentClick(props);
101
120
  return {
102
121
  styleProps,
103
122
  handleClick
@@ -107,15 +126,15 @@
107
126
 
108
127
  function render(_ctx, _cache, $props, $setup, $data, $options) {
109
128
  return (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.tag), {
129
+ onClick: vue.withModifiers(_ctx.handleClick, ["prevent"]),
110
130
  style: vue.normalizeStyle(_ctx.styleProps),
111
- class: "l-text-component",
112
- onClick: _ctx.handleClick
131
+ class: "l-text-component"
113
132
  }, {
114
133
  default: vue.withCtx(() => [
115
134
  vue.createTextVNode(vue.toDisplayString(_ctx.text), 1 /* TEXT */)
116
135
  ]),
117
136
  _: 1 /* STABLE */
118
- }, 8 /* PROPS */, ["style", "onClick"]))
137
+ }, 8 /* PROPS */, ["onClick", "style"]))
119
138
  }
120
139
 
121
140
  script.render = render;
@@ -126,17 +145,13 @@
126
145
  app.component(script.name, script);
127
146
  };
128
147
 
129
- const defaultProps$1 = transformToComponentProps(imageDefaultProps);
130
148
  // array that contains style props
131
149
  var script$1 = vue.defineComponent({
132
150
  name: 'l-image',
133
- props: {
134
- ...defaultProps$1
135
- },
151
+ props: transformToComponentProps(componentsDefaultProps['l-image'].props, isEditingProp),
136
152
  setup(props) {
137
- // 重用并且简化
138
- // 抽离并且获得 styleProps
139
- const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames);
153
+ const styleProps = useStylePick(props);
154
+ const handleClick = useComponentClick(props);
140
155
  return {
141
156
  styleProps,
142
157
  handleClick
@@ -148,10 +163,11 @@
148
163
 
149
164
  function render$1(_ctx, _cache, $props, $setup, $data, $options) {
150
165
  return (vue.openBlock(), vue.createElementBlock("img", {
166
+ src: _ctx.src,
151
167
  style: vue.normalizeStyle(_ctx.styleProps),
168
+ draggable: false,
152
169
  class: "l-image-component",
153
- onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
154
- src: _ctx.src
170
+ onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
155
171
  }, null, 12 /* STYLE, PROPS */, _hoisted_1))
156
172
  }
157
173
 
@@ -163,17 +179,16 @@
163
179
  app.component(script$1.name, script$1);
164
180
  };
165
181
 
166
- const defaultProps$2 = transformToComponentProps(shapeDefaultProps);
182
+ const defaultProps$1 = transformToComponentProps(componentsDefaultProps['l-shape'].props, isEditingProp);
167
183
  // array that contains style props
168
184
  var script$2 = vue.defineComponent({
169
185
  name: 'l-shape',
170
186
  props: {
171
- ...defaultProps$2
187
+ ...defaultProps$1
172
188
  },
173
189
  setup(props) {
174
- // 重用并且简化
175
- // 抽离并且获得 styleProps
176
- const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames);
190
+ const styleProps = useStylePick(props);
191
+ const handleClick = useComponentClick(props);
177
192
  return {
178
193
  styleProps,
179
194
  handleClick
@@ -183,9 +198,10 @@
183
198
 
184
199
  function render$2(_ctx, _cache, $props, $setup, $data, $options) {
185
200
  return (vue.openBlock(), vue.createElementBlock("div", {
201
+ onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
186
202
  style: vue.normalizeStyle(_ctx.styleProps),
187
203
  class: "l-shape-component",
188
- onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
204
+ draggable: false
189
205
  }, null, 4 /* STYLE */))
190
206
  }
191
207
 
@@ -234,18 +250,14 @@
234
250
  app.component(script$3.name, script$3);
235
251
  };
236
252
 
237
- const components = [
238
- script,
239
- script$1,
240
- script$2
241
- ];
253
+ const components = [script, script$1, script$2, script$3];
242
254
  const install = (app) => {
243
- components.forEach((component) => {
244
- app.component(component.name, component);
255
+ components.map(component => {
256
+ app.use(component);
245
257
  });
246
258
  };
247
259
  var index = {
248
- install
260
+ install,
249
261
  };
250
262
 
251
263
  exports.FinalPage = script$3;
@@ -253,13 +265,7 @@
253
265
  exports.LShape = script$2;
254
266
  exports.LText = script;
255
267
  exports.default = index;
256
- exports.imageDefaultProps = imageDefaultProps;
257
- exports.imageStylePropsNames = imageStylePropsNames;
258
268
  exports.install = install;
259
- exports.shapeDefaultProps = shapeDefaultProps;
260
- exports.shapeStylePropsNames = shapeStylePropsNames;
261
- exports.textDefaultProps = textDefaultProps;
262
- exports.textStylePropNames = textStylePropNames;
263
269
 
264
270
  Object.defineProperty(exports, '__esModule', { value: true });
265
271
 
package/package.json CHANGED
@@ -1,76 +1,76 @@
1
- {
2
- "name": "@smilekite/lego-bricks",
3
- "version": "1.0.5",
4
- "author": "smiley",
5
- "scripts": {
6
- "serve": "vue-cli-service serve",
7
- "build": "npm run clean && npm run build:esm && npm run build:umd",
8
- "test:watch": "vue-cli-service test:unit --watch",
9
- "test": "vue-cli-service test:unit",
10
- "lint": "vue-cli-service lint",
11
- "build:esm": "rollup --config build/rollup.esm.config.js",
12
- "build:umd": "rollup --config build/rollup.umd.config.js",
13
- "clean": "rimraf ./dist",
14
- "prepublishOnly": "npm run lint && npm run test && npm run build"
15
- },
16
- "husky": {
17
- "hooks": {
18
- "pre-commit": "npm run lint && npm run test"
19
- }
20
- },
21
- "main": "dist/lego-bricks.umd.js",
22
- "module": "dist/lego-bricks.esm.js",
23
- "files": [
24
- "dist"
25
- ],
26
- "dependencies": {
27
- "core-js": "^3.6.5",
28
- "lodash-es": "^4.17.20"
29
- },
30
- "devDependencies": {
31
- "@rollup/plugin-node-resolve": "^11.1.1",
32
- "@rollup/plugin-typescript": "^8.1.1",
33
- "@types/jest": "^24.0.19",
34
- "@types/lodash-es": "^4.17.4",
35
- "@typescript-eslint/eslint-plugin": "^2.33.0",
36
- "@typescript-eslint/parser": "^2.33.0",
37
- "@vue/cli-plugin-babel": "~4.5.0",
38
- "@vue/cli-plugin-eslint": "~4.5.0",
39
- "@vue/cli-plugin-typescript": "~4.5.0",
40
- "@vue/cli-plugin-unit-jest": "~4.5.11",
41
- "@vue/cli-service": "~4.5.0",
42
- "@vue/compiler-sfc": "^3.0.0",
43
- "@vue/eslint-config-typescript": "~5.1.0",
44
- "@vue/test-utils": "2.0.0-alpha.8",
45
- "eslint": "^6.7.2",
46
- "eslint-plugin-vue": "^7.0.0",
47
- "husky": "^4.3.8",
48
- "rimraf": "^3.0.2",
49
- "rollup": "^2.38.5",
50
- "rollup-plugin-css-only": "^3.1.0",
51
- "rollup-plugin-typescript2": "^0.29.0",
52
- "rollup-plugin-vue": "^6.0.0",
53
- "typescript": "^4.3.5",
54
- "vue": "~3.4.0",
55
- "vue-jest": "5.0.0-alpha.9"
56
- },
57
- "peerDependencies": {
58
- "vue": "^3.0.0"
59
- },
60
- "homepage": "https://github.com/Kitesource/lego-bricks",
61
- "keywords": [
62
- "Component",
63
- "UI",
64
- "Vue3"
65
- ],
66
- "license": "MIT",
67
- "repository": {
68
- "type": "git",
69
- "url": "https://github.com/Kitesource/lego-bricks"
70
- },
71
- "types": "dist/index.d.ts",
72
- "publishConfig": {
73
- "access": "public",
74
- "registry": "https://registry.npmjs.org/"
75
- }
76
- }
1
+ {
2
+ "name": "@smilekite/lego-bricks",
3
+ "version": "1.0.6",
4
+ "author": "smiley",
5
+ "scripts": {
6
+ "serve": "vue-cli-service serve",
7
+ "build": "npm run clean && npm run build:esm && npm run build:umd",
8
+ "test:watch": "vue-cli-service test:unit --watch",
9
+ "test": "vue-cli-service test:unit",
10
+ "lint": "vue-cli-service lint",
11
+ "build:esm": "rollup --config build/rollup.esm.config.js",
12
+ "build:umd": "rollup --config build/rollup.umd.config.js",
13
+ "clean": "rimraf ./dist",
14
+ "prepublishOnly": "npm run lint && npm run test && npm run build"
15
+ },
16
+ "husky": {
17
+ "hooks": {
18
+ "pre-commit": "npm run lint && npm run test"
19
+ }
20
+ },
21
+ "main": "dist/lego-bricks.umd.js",
22
+ "module": "dist/lego-bricks.esm.js",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "dependencies": {
27
+ "core-js": "^3.6.5",
28
+ "lodash-es": "^4.17.20"
29
+ },
30
+ "devDependencies": {
31
+ "@rollup/plugin-node-resolve": "^11.1.1",
32
+ "@rollup/plugin-typescript": "^8.1.1",
33
+ "@types/jest": "^24.0.19",
34
+ "@types/lodash-es": "^4.17.4",
35
+ "@typescript-eslint/eslint-plugin": "^2.33.0",
36
+ "@typescript-eslint/parser": "^2.33.0",
37
+ "@vue/cli-plugin-babel": "~4.5.0",
38
+ "@vue/cli-plugin-eslint": "~4.5.0",
39
+ "@vue/cli-plugin-typescript": "~4.5.0",
40
+ "@vue/cli-plugin-unit-jest": "~4.5.11",
41
+ "@vue/cli-service": "~4.5.0",
42
+ "@vue/compiler-sfc": "^3.0.0",
43
+ "@vue/eslint-config-typescript": "~5.1.0",
44
+ "@vue/test-utils": "2.0.0-alpha.8",
45
+ "eslint": "^6.7.2",
46
+ "eslint-plugin-vue": "^7.0.0",
47
+ "husky": "^4.3.8",
48
+ "rimraf": "^3.0.2",
49
+ "rollup": "^2.38.5",
50
+ "rollup-plugin-css-only": "^3.1.0",
51
+ "rollup-plugin-typescript2": "^0.29.0",
52
+ "rollup-plugin-vue": "^6.0.0",
53
+ "typescript": "^4.3.5",
54
+ "vue": "~3.4.0",
55
+ "vue-jest": "5.0.0-alpha.9"
56
+ },
57
+ "peerDependencies": {
58
+ "vue": "^3.0.0"
59
+ },
60
+ "homepage": "https://github.com/Kitesource/lego-bricks",
61
+ "keywords": [
62
+ "Component",
63
+ "UI",
64
+ "Vue3"
65
+ ],
66
+ "license": "MIT",
67
+ "repository": {
68
+ "type": "git",
69
+ "url": "https://github.com/Kitesource/lego-bricks"
70
+ },
71
+ "types": "dist/index.d.ts",
72
+ "publishConfig": {
73
+ "access": "public",
74
+ "registry": "https://registry.npmjs.org/"
75
+ }
76
+ }
@@ -1,10 +0,0 @@
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;