@smilekite/lego-bricks 1.0.4 → 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
+ }
@@ -0,0 +1,20 @@
1
+ import { PropType } from 'vue';
2
+ import { ComponentData, PageData } from '../../defaultProps';
3
+ declare const _default: import("vue").DefineComponent<{
4
+ page: {
5
+ type: PropType<PageData>;
6
+ };
7
+ components: {
8
+ type: PropType<ComponentData[]>;
9
+ required: true;
10
+ };
11
+ }, unknown, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
12
+ page: {
13
+ type: PropType<PageData>;
14
+ };
15
+ components: {
16
+ type: PropType<ComponentData[]>;
17
+ required: true;
18
+ };
19
+ }>>, {}, {}>;
20
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import FinalPage from './FinalPage.vue';
2
+ export default FinalPage;
@@ -1,2 +1,11 @@
1
- declare const _default: any;
1
+ declare const _default: import("vue").DefineComponent<{
2
+ [x: string]: any;
3
+ }, {
4
+ styleProps: import("vue").ComputedRef<Pick<any, string>>;
5
+ handleClick: () => void;
6
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
7
+ [x: string]: any;
8
+ }>>, {
9
+ [x: string]: any;
10
+ }, {}>;
2
11
  export default _default;
@@ -1,2 +1,11 @@
1
- declare const _default: any;
1
+ declare const _default: import("vue").DefineComponent<{
2
+ [x: string]: any;
3
+ }, {
4
+ styleProps: import("vue").ComputedRef<Pick<any, string>>;
5
+ handleClick: () => void;
6
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
7
+ [x: string]: any;
8
+ }>>, {
9
+ [x: string]: any;
10
+ }, {}>;
2
11
  export default _default;
@@ -1,2 +1,11 @@
1
- declare const _default: any;
1
+ declare const _default: import("vue").DefineComponent<{
2
+ [x: string]: any;
3
+ }, {
4
+ styleProps: import("vue").ComputedRef<Pick<any, string>>;
5
+ handleClick: () => void;
6
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
7
+ [x: string]: any;
8
+ }>>, {
9
+ [x: string]: any;
10
+ }, {}>;
2
11
  export default _default;
@@ -1,4 +1,34 @@
1
- export interface CommonComponentProps {
1
+ export interface ComponentData {
2
+ props: {
3
+ [key: string]: any;
4
+ };
5
+ id: string;
6
+ name: string;
7
+ layerName?: string;
8
+ isHidden?: boolean;
9
+ isLocked?: boolean;
10
+ }
11
+ export interface PageData {
12
+ props: {
13
+ [key: string]: any;
14
+ };
15
+ setting: {
16
+ [key: string]: any;
17
+ };
18
+ id?: number;
19
+ title?: string;
20
+ desc?: string;
21
+ coverImg?: string;
22
+ uuid?: string;
23
+ latestPublishAt?: string;
24
+ updatedAt?: string;
25
+ isTemplate?: boolean;
26
+ isHot?: boolean;
27
+ isNew?: boolean;
28
+ author?: string;
29
+ status?: string;
30
+ }
31
+ export declare const commonDefaultProps: {
2
32
  actionType: string;
3
33
  url: string;
4
34
  height: string;
@@ -12,14 +42,31 @@ export interface CommonComponentProps {
12
42
  borderWidth: string;
13
43
  borderRadius: string;
14
44
  boxShadow: string;
15
- 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;
16
66
  position: string;
17
67
  left: string;
18
68
  top: string;
19
69
  right: string;
20
- }
21
- export declare const commonDefaultProps: CommonComponentProps;
22
- export interface TextComponentProps extends CommonComponentProps {
23
70
  text: string;
24
71
  fontSize: string;
25
72
  fontFamily: string;
@@ -30,28 +77,140 @@ export interface TextComponentProps extends CommonComponentProps {
30
77
  textAlign: string;
31
78
  color: string;
32
79
  backgroundColor: string;
33
- }
34
- export interface ImageComponentProps 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;
35
100
  src: string;
36
- }
37
- export interface ShapeComponentProps extends CommonComponentProps {
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;
38
121
  backgroundColor: string;
39
- borderTop: string;
40
- borderBottom: string;
41
- borderLeft: string;
42
- borderRight: string;
43
- }
44
- export declare type AllComponentProps = TextComponentProps & ImageComponentProps & ShapeComponentProps;
45
- export declare const textDefaultProps: TextComponentProps;
46
- export declare const imageDefaultProps: ImageComponentProps;
47
- export declare const shapeDefaultProps: ShapeComponentProps;
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
+ };
48
203
  export declare const isEditingProp: {
49
204
  isEditing: {
50
205
  type: BooleanConstructor;
51
206
  default: boolean;
52
207
  };
53
208
  };
54
- export declare const textStylePropNames: string[];
55
- export declare const imageStylePropsNames: string[];
56
- export declare const shapeStylePropsNames: string[];
57
- export declare const transformToComponentProps: <T extends {}>(props: T) => any;
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,11 +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
- declare const install: (app: App) => void;
7
- export { LText, LImage, LShape, install };
4
+ import FinalPage from './components/FinalPage';
5
+ declare const install: (app: any) => void;
6
+ export { install, LText, LImage, LShape, FinalPage };
8
7
  declare const _default: {
9
- install: (app: App<any>) => void;
8
+ install: (app: any) => void;
10
9
  };
11
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 } 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,67 +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
- src: 'test.url',
45
- ...commonDefaultProps
45
+ src: '',
46
+ ...commonDefaultProps,
46
47
  };
47
48
  const shapeDefaultProps = {
48
49
  backgroundColor: '',
49
- borderTop: '',
50
- borderBottom: '',
51
- borderLeft: '',
52
- borderRight: '',
53
- ...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
+ },
54
64
  };
55
65
  const isEditingProp = {
56
66
  isEditing: {
57
67
  type: Boolean,
58
- default: false
59
- }
68
+ default: false,
69
+ },
60
70
  };
61
- const textStylePropNames = without(Object.keys(textDefaultProps), 'actionType', 'url', 'text');
62
- const imageStylePropsNames = without(Object.keys(imageDefaultProps), 'actionType', 'url', 'src');
63
- const shapeStylePropsNames = without(Object.keys(shapeDefaultProps), 'actionType', 'url');
64
- const transformToComponentProps = (props) => {
65
- const mapProps = mapValues(props, (item) => {
71
+ const transformToComponentProps = (props, extraProps) => {
72
+ const mapProps = mapValues(props, item => {
66
73
  return {
67
74
  type: item.constructor,
68
- default: item
75
+ default: item,
69
76
  };
70
77
  });
71
- return { ...mapProps, ...isEditingProp };
78
+ if (extraProps) {
79
+ return { ...mapProps, ...extraProps };
80
+ }
81
+ else {
82
+ return mapProps;
83
+ }
84
+ };
85
+
86
+ const defaultStyles = without(Object.keys(textDefaultProps), 'actionType', 'url', 'text');
87
+ const useStylePick = (props, pickStyles = defaultStyles) => {
88
+ return computed(() => pick(props, pickStyles));
72
89
  };
73
90
 
74
- const useComponentCommon = (props, picks) => {
75
- const styleProps = computed(() => pick(props, picks));
91
+ const useComponentClick = (props) => {
76
92
  const handleClick = () => {
77
- if (props.actionType === 'url' && props.url && !props.isEditing) {
93
+ if (props.actionType && props.url && !props.isEditing) {
78
94
  window.location.href = props.url;
79
95
  }
80
96
  };
81
- return {
82
- styleProps,
83
- handleClick
84
- };
97
+ return handleClick;
85
98
  };
86
99
 
87
- 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);
88
108
  // array that contains style props
89
109
  var script = defineComponent({
90
110
  name: 'l-text',
91
111
  props: {
92
- tag: {
93
- type: String,
94
- default: 'div'
95
- },
96
112
  ...defaultProps
97
113
  },
98
114
  setup(props) {
99
- // 重用并且简化
100
- // 抽离并且获得 styleProps
101
- const { styleProps, handleClick } = useComponentCommon(props, textStylePropNames);
115
+ const styleProps = useStylePick(props);
116
+ const handleClick = useComponentClick(props);
102
117
  return {
103
118
  styleProps,
104
119
  handleClick
@@ -108,15 +123,15 @@ var script = defineComponent({
108
123
 
109
124
  function render(_ctx, _cache, $props, $setup, $data, $options) {
110
125
  return (openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), {
126
+ onClick: withModifiers(_ctx.handleClick, ["prevent"]),
111
127
  style: normalizeStyle(_ctx.styleProps),
112
- class: "l-text-component",
113
- onClick: _ctx.handleClick
128
+ class: "l-text-component"
114
129
  }, {
115
130
  default: withCtx(() => [
116
131
  createTextVNode(toDisplayString(_ctx.text), 1 /* TEXT */)
117
132
  ]),
118
133
  _: 1 /* STABLE */
119
- }, 8 /* PROPS */, ["style", "onClick"]))
134
+ }, 8 /* PROPS */, ["onClick", "style"]))
120
135
  }
121
136
 
122
137
  script.render = render;
@@ -127,17 +142,13 @@ script.install = (app) => {
127
142
  app.component(script.name, script);
128
143
  };
129
144
 
130
- const defaultProps$1 = transformToComponentProps(imageDefaultProps);
131
145
  // array that contains style props
132
146
  var script$1 = defineComponent({
133
147
  name: 'l-image',
134
- props: {
135
- ...defaultProps$1
136
- },
148
+ props: transformToComponentProps(componentsDefaultProps['l-image'].props, isEditingProp),
137
149
  setup(props) {
138
- // 重用并且简化
139
- // 抽离并且获得 styleProps
140
- const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames);
150
+ const styleProps = useStylePick(props);
151
+ const handleClick = useComponentClick(props);
141
152
  return {
142
153
  styleProps,
143
154
  handleClick
@@ -149,10 +160,11 @@ const _hoisted_1 = ["src"];
149
160
 
150
161
  function render$1(_ctx, _cache, $props, $setup, $data, $options) {
151
162
  return (openBlock(), createElementBlock("img", {
163
+ src: _ctx.src,
152
164
  style: normalizeStyle(_ctx.styleProps),
165
+ draggable: false,
153
166
  class: "l-image-component",
154
- onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
155
- src: _ctx.src
167
+ onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
156
168
  }, null, 12 /* STYLE, PROPS */, _hoisted_1))
157
169
  }
158
170
 
@@ -164,17 +176,16 @@ script$1.install = (app) => {
164
176
  app.component(script$1.name, script$1);
165
177
  };
166
178
 
167
- const defaultProps$2 = transformToComponentProps(shapeDefaultProps);
179
+ const defaultProps$1 = transformToComponentProps(componentsDefaultProps['l-shape'].props, isEditingProp);
168
180
  // array that contains style props
169
181
  var script$2 = defineComponent({
170
182
  name: 'l-shape',
171
183
  props: {
172
- ...defaultProps$2
184
+ ...defaultProps$1
173
185
  },
174
186
  setup(props) {
175
- // 重用并且简化
176
- // 抽离并且获得 styleProps
177
- const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames);
187
+ const styleProps = useStylePick(props);
188
+ const handleClick = useComponentClick(props);
178
189
  return {
179
190
  styleProps,
180
191
  handleClick
@@ -184,9 +195,10 @@ var script$2 = defineComponent({
184
195
 
185
196
  function render$2(_ctx, _cache, $props, $setup, $data, $options) {
186
197
  return (openBlock(), createElementBlock("div", {
198
+ onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
187
199
  style: normalizeStyle(_ctx.styleProps),
188
200
  class: "l-shape-component",
189
- onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
201
+ draggable: false
190
202
  }, null, 4 /* STYLE */))
191
203
  }
192
204
 
@@ -197,19 +209,53 @@ script$2.install = (app) => {
197
209
  app.component(script$2.name, script$2);
198
210
  };
199
211
 
200
- const components = [
201
- script,
202
- script$1,
203
- script$2
204
- ];
212
+ var script$3 = defineComponent({
213
+ name: 'final-page',
214
+ props: {
215
+ page: {
216
+ type: Object
217
+ },
218
+ components: {
219
+ type: Array,
220
+ required: true
221
+ }
222
+ }
223
+ });
224
+
225
+ const _hoisted_1$1 = ["id"];
226
+
227
+ function render$3(_ctx, _cache, $props, $setup, $data, $options) {
228
+ return (openBlock(), createElementBlock("div", {
229
+ class: "final-page",
230
+ style: normalizeStyle(_ctx.page && _ctx.page.props)
231
+ }, [
232
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.components, (item) => {
233
+ return (openBlock(), createElementBlock("div", {
234
+ key: item.id,
235
+ id: `component-${item.id}`
236
+ }, [
237
+ (openBlock(), createBlock(resolveDynamicComponent(item.name), mergeProps({ ref_for: true }, item.props), null, 16 /* FULL_PROPS */))
238
+ ], 8 /* PROPS */, _hoisted_1$1))
239
+ }), 128 /* KEYED_FRAGMENT */))
240
+ ], 4 /* STYLE */))
241
+ }
242
+
243
+ script$3.render = render$3;
244
+ script$3.__file = "src/components/FinalPage/FinalPage.vue";
245
+
246
+ script$3.install = (app) => {
247
+ app.component(script$3.name, script$3);
248
+ };
249
+
250
+ const components = [script, script$1, script$2, script$3];
205
251
  const install = (app) => {
206
- components.forEach(component => {
207
- app.component(component.name, component);
252
+ components.map(component => {
253
+ app.use(component);
208
254
  });
209
255
  };
210
256
  var index = {
211
- install
257
+ install,
212
258
  };
213
259
 
214
260
  export default index;
215
- export { 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,67 +42,81 @@
41
42
  textAlign: 'left',
42
43
  color: '#000000',
43
44
  backgroundColor: '',
44
- ...commonDefaultProps
45
+ ...commonDefaultProps,
45
46
  };
46
47
  const imageDefaultProps = {
47
- src: 'test.url',
48
- ...commonDefaultProps
48
+ src: '',
49
+ ...commonDefaultProps,
49
50
  };
50
51
  const shapeDefaultProps = {
51
52
  backgroundColor: '',
52
- borderTop: '',
53
- borderBottom: '',
54
- borderLeft: '',
55
- borderRight: '',
56
- ...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
+ },
57
67
  };
58
68
  const isEditingProp = {
59
69
  isEditing: {
60
70
  type: Boolean,
61
- default: false
62
- }
71
+ default: false,
72
+ },
63
73
  };
64
- const textStylePropNames = lodashEs.without(Object.keys(textDefaultProps), 'actionType', 'url', 'text');
65
- const imageStylePropsNames = lodashEs.without(Object.keys(imageDefaultProps), 'actionType', 'url', 'src');
66
- const shapeStylePropsNames = lodashEs.without(Object.keys(shapeDefaultProps), 'actionType', 'url');
67
- const transformToComponentProps = (props) => {
68
- const mapProps = lodashEs.mapValues(props, (item) => {
74
+ const transformToComponentProps = (props, extraProps) => {
75
+ const mapProps = lodashEs.mapValues(props, item => {
69
76
  return {
70
77
  type: item.constructor,
71
- default: item
78
+ default: item,
72
79
  };
73
80
  });
74
- return { ...mapProps, ...isEditingProp };
81
+ if (extraProps) {
82
+ return { ...mapProps, ...extraProps };
83
+ }
84
+ else {
85
+ return mapProps;
86
+ }
87
+ };
88
+
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));
75
92
  };
76
93
 
77
- const useComponentCommon = (props, picks) => {
78
- const styleProps = vue.computed(() => lodashEs.pick(props, picks));
94
+ const useComponentClick = (props) => {
79
95
  const handleClick = () => {
80
- if (props.actionType === 'url' && props.url && !props.isEditing) {
96
+ if (props.actionType && props.url && !props.isEditing) {
81
97
  window.location.href = props.url;
82
98
  }
83
99
  };
84
- return {
85
- styleProps,
86
- handleClick
87
- };
100
+ return handleClick;
88
101
  };
89
102
 
90
- 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);
91
111
  // array that contains style props
92
112
  var script = vue.defineComponent({
93
113
  name: 'l-text',
94
114
  props: {
95
- tag: {
96
- type: String,
97
- default: 'div'
98
- },
99
115
  ...defaultProps
100
116
  },
101
117
  setup(props) {
102
- // 重用并且简化
103
- // 抽离并且获得 styleProps
104
- const { styleProps, handleClick } = useComponentCommon(props, textStylePropNames);
118
+ const styleProps = useStylePick(props);
119
+ const handleClick = useComponentClick(props);
105
120
  return {
106
121
  styleProps,
107
122
  handleClick
@@ -111,15 +126,15 @@
111
126
 
112
127
  function render(_ctx, _cache, $props, $setup, $data, $options) {
113
128
  return (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.tag), {
129
+ onClick: vue.withModifiers(_ctx.handleClick, ["prevent"]),
114
130
  style: vue.normalizeStyle(_ctx.styleProps),
115
- class: "l-text-component",
116
- onClick: _ctx.handleClick
131
+ class: "l-text-component"
117
132
  }, {
118
133
  default: vue.withCtx(() => [
119
134
  vue.createTextVNode(vue.toDisplayString(_ctx.text), 1 /* TEXT */)
120
135
  ]),
121
136
  _: 1 /* STABLE */
122
- }, 8 /* PROPS */, ["style", "onClick"]))
137
+ }, 8 /* PROPS */, ["onClick", "style"]))
123
138
  }
124
139
 
125
140
  script.render = render;
@@ -130,17 +145,13 @@
130
145
  app.component(script.name, script);
131
146
  };
132
147
 
133
- const defaultProps$1 = transformToComponentProps(imageDefaultProps);
134
148
  // array that contains style props
135
149
  var script$1 = vue.defineComponent({
136
150
  name: 'l-image',
137
- props: {
138
- ...defaultProps$1
139
- },
151
+ props: transformToComponentProps(componentsDefaultProps['l-image'].props, isEditingProp),
140
152
  setup(props) {
141
- // 重用并且简化
142
- // 抽离并且获得 styleProps
143
- const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames);
153
+ const styleProps = useStylePick(props);
154
+ const handleClick = useComponentClick(props);
144
155
  return {
145
156
  styleProps,
146
157
  handleClick
@@ -152,10 +163,11 @@
152
163
 
153
164
  function render$1(_ctx, _cache, $props, $setup, $data, $options) {
154
165
  return (vue.openBlock(), vue.createElementBlock("img", {
166
+ src: _ctx.src,
155
167
  style: vue.normalizeStyle(_ctx.styleProps),
168
+ draggable: false,
156
169
  class: "l-image-component",
157
- onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
158
- src: _ctx.src
170
+ onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
159
171
  }, null, 12 /* STYLE, PROPS */, _hoisted_1))
160
172
  }
161
173
 
@@ -167,17 +179,16 @@
167
179
  app.component(script$1.name, script$1);
168
180
  };
169
181
 
170
- const defaultProps$2 = transformToComponentProps(shapeDefaultProps);
182
+ const defaultProps$1 = transformToComponentProps(componentsDefaultProps['l-shape'].props, isEditingProp);
171
183
  // array that contains style props
172
184
  var script$2 = vue.defineComponent({
173
185
  name: 'l-shape',
174
186
  props: {
175
- ...defaultProps$2
187
+ ...defaultProps$1
176
188
  },
177
189
  setup(props) {
178
- // 重用并且简化
179
- // 抽离并且获得 styleProps
180
- const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames);
190
+ const styleProps = useStylePick(props);
191
+ const handleClick = useComponentClick(props);
181
192
  return {
182
193
  styleProps,
183
194
  handleClick
@@ -187,9 +198,10 @@
187
198
 
188
199
  function render$2(_ctx, _cache, $props, $setup, $data, $options) {
189
200
  return (vue.openBlock(), vue.createElementBlock("div", {
201
+ onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])),
190
202
  style: vue.normalizeStyle(_ctx.styleProps),
191
203
  class: "l-shape-component",
192
- onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"]))
204
+ draggable: false
193
205
  }, null, 4 /* STYLE */))
194
206
  }
195
207
 
@@ -200,31 +212,60 @@
200
212
  app.component(script$2.name, script$2);
201
213
  };
202
214
 
203
- const components = [
204
- script,
205
- script$1,
206
- script$2
207
- ];
215
+ var script$3 = vue.defineComponent({
216
+ name: 'final-page',
217
+ props: {
218
+ page: {
219
+ type: Object
220
+ },
221
+ components: {
222
+ type: Array,
223
+ required: true
224
+ }
225
+ }
226
+ });
227
+
228
+ const _hoisted_1$1 = ["id"];
229
+
230
+ function render$3(_ctx, _cache, $props, $setup, $data, $options) {
231
+ return (vue.openBlock(), vue.createElementBlock("div", {
232
+ class: "final-page",
233
+ style: vue.normalizeStyle(_ctx.page && _ctx.page.props)
234
+ }, [
235
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.components, (item) => {
236
+ return (vue.openBlock(), vue.createElementBlock("div", {
237
+ key: item.id,
238
+ id: `component-${item.id}`
239
+ }, [
240
+ (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(item.name), vue.mergeProps({ ref_for: true }, item.props), null, 16 /* FULL_PROPS */))
241
+ ], 8 /* PROPS */, _hoisted_1$1))
242
+ }), 128 /* KEYED_FRAGMENT */))
243
+ ], 4 /* STYLE */))
244
+ }
245
+
246
+ script$3.render = render$3;
247
+ script$3.__file = "src/components/FinalPage/FinalPage.vue";
248
+
249
+ script$3.install = (app) => {
250
+ app.component(script$3.name, script$3);
251
+ };
252
+
253
+ const components = [script, script$1, script$2, script$3];
208
254
  const install = (app) => {
209
- components.forEach(component => {
210
- app.component(component.name, component);
255
+ components.map(component => {
256
+ app.use(component);
211
257
  });
212
258
  };
213
259
  var index = {
214
- install
260
+ install,
215
261
  };
216
262
 
263
+ exports.FinalPage = script$3;
217
264
  exports.LImage = script$1;
218
265
  exports.LShape = script$2;
219
266
  exports.LText = script;
220
267
  exports.default = index;
221
- exports.imageDefaultProps = imageDefaultProps;
222
- exports.imageStylePropsNames = imageStylePropsNames;
223
268
  exports.install = install;
224
- exports.shapeDefaultProps = shapeDefaultProps;
225
- exports.shapeStylePropsNames = shapeStylePropsNames;
226
- exports.textDefaultProps = textDefaultProps;
227
- exports.textStylePropNames = textStylePropNames;
228
269
 
229
270
  Object.defineProperty(exports, '__esModule', { value: true });
230
271
 
package/dist/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,76 +1,76 @@
1
- {
2
- "name": "@smilekite/lego-bricks",
3
- "version": "1.0.4",
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 --max-warnings 5",
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": "^3.9.3",
54
- "vue": "^3.0.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
- }
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
76
  }
@@ -1,8 +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<any>;
6
- handleClick: () => void;
7
- };
8
- export default useComponentCommon;