imooc-cli-dev-components44 1.0.0 → 1.0.1

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.
Files changed (45) hide show
  1. package/.browserslistrc +3 -0
  2. package/.eslintrc.js +34 -0
  3. package/.gitignore +2 -0
  4. package/.travis.yml +12 -0
  5. package/README.md +8 -24
  6. package/build/rollup.config.js +28 -0
  7. package/build/rollup.esm.config.js +11 -0
  8. package/build/rollup.umd.config.js +14 -0
  9. package/dist/bundle.css +18 -0
  10. package/dist/components/LImage/LImage.vue.d.ts +190 -0
  11. package/dist/components/LImage/index.d.ts +2 -0
  12. package/dist/components/LShape/LShape.vue.d.ts +190 -0
  13. package/dist/components/LShape/index.d.ts +2 -0
  14. package/dist/components/LText/LText.vue.d.ts +280 -0
  15. package/dist/components/LText/index.d.ts +2 -0
  16. package/dist/defaultProps.d.ts +61 -0
  17. package/dist/hooks/useComponentCommon.d.ts +10 -0
  18. package/dist/imooc-cli-dev-components44.esm.js +217 -0
  19. package/dist/imooc-cli-dev-components44.umd.js +232 -0
  20. package/dist/index.d.ts +10 -0
  21. package/examples/README.md +24 -0
  22. package/examples/babel.config.js +5 -0
  23. package/examples/package-lock.json +18240 -0
  24. package/examples/package.json +42 -0
  25. package/jest.config.js +9 -0
  26. package/package.json +70 -25
  27. package/src/components/LImage/LImage.vue +38 -0
  28. package/src/components/LImage/index.ts +7 -0
  29. package/src/components/LShape/LShape.vue +30 -0
  30. package/src/components/LShape/index.ts +7 -0
  31. package/src/components/LText/LText.vue +46 -0
  32. package/src/components/LText/index.ts +7 -0
  33. package/src/defaultProps.ts +110 -0
  34. package/src/hooks/useComponentCommon.ts +17 -0
  35. package/src/index.ts +34 -0
  36. package/src/shims-vue.d.ts +5 -0
  37. package/tests/unit/LText.spec.ts +57 -0
  38. package/tsconfig.json +43 -0
  39. /package/{public → examples/public}/favicon.ico +0 -0
  40. /package/{public → examples/public}/index.html +0 -0
  41. /package/{src → examples/src}/App.vue +0 -0
  42. /package/{src → examples/src}/assets/logo.png +0 -0
  43. /package/{src → examples/src}/components/HelloWorld.vue +0 -0
  44. /package/{src → examples/src}/main.js +0 -0
  45. /package/{vue.config.js → examples/vue.config.js} +0 -0
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "imooc-cli-dev-components44",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "scripts": {
6
+ "serve": "vue-cli-service serve",
7
+ "build": "vue-cli-service build",
8
+ "lint": "vue-cli-service lint"
9
+ },
10
+ "dependencies": {
11
+ "core-js": "^3.6.5",
12
+ "vue": "^3.0.0"
13
+ },
14
+ "devDependencies": {
15
+ "@vue/cli-plugin-babel": "~4.5.0",
16
+ "@vue/cli-plugin-eslint": "~4.5.0",
17
+ "@vue/cli-service": "~4.5.0",
18
+ "@vue/compiler-sfc": "^3.0.0",
19
+ "babel-eslint": "^10.1.0",
20
+ "eslint": "^6.7.2",
21
+ "eslint-plugin-vue": "^7.0.0"
22
+ },
23
+ "eslintConfig": {
24
+ "root": true,
25
+ "env": {
26
+ "node": true
27
+ },
28
+ "extends": [
29
+ "plugin:vue/vue3-essential",
30
+ "eslint:recommended"
31
+ ],
32
+ "parserOptions": {
33
+ "parser": "babel-eslint"
34
+ },
35
+ "rules": {}
36
+ },
37
+ "browserslist": [
38
+ "> 1%",
39
+ "last 2 versions",
40
+ "not dead"
41
+ ]
42
+ }
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
3
+ transform: {
4
+ '^.+\\.vue$': 'vue-jest'
5
+ },
6
+ transformIgnorePatterns: [
7
+ '/!node_modules\\/lodash-es/'
8
+ ]
9
+ }
package/package.json CHANGED
@@ -1,42 +1,87 @@
1
1
  {
2
2
  "name": "imooc-cli-dev-components44",
3
- "version": "1.0.0",
4
- "private": false,
3
+ "version": "1.0.1",
4
+ "description": "imooc-cli-dev-components44",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "author": "Viking Zhang",
5
9
  "scripts": {
6
10
  "serve": "vue-cli-service serve",
7
- "build": "vue-cli-service build",
8
- "lint": "vue-cli-service lint"
11
+ "build": "npm run clean && npm run build:esm && npm run build:umd",
12
+ "test:watch": "vue-cli-service test:unit --watch",
13
+ "test": "vue-cli-service test:unit",
14
+ "lint": "vue-cli-service lint --max-warnings 5",
15
+ "build:esm": "rollup --config build/rollup.esm.config.js",
16
+ "build:umd": "rollup --config build/rollup.umd.config.js",
17
+ "build:demo": "npm install && npm run builda && cd examples && npm install && npm run build",
18
+ "clean": "rimraf ./dist"
19
+ },
20
+ "husky": {
21
+ "hooks": {
22
+ "pre-commit": "npm run lint && npm run test"
23
+ }
9
24
  },
25
+ "main": "dist/lego-bricks.umd.js",
26
+ "module": "dist/lego-bricks.esm.js",
27
+ "files": [
28
+ "build",
29
+ "examples",
30
+ "src",
31
+ "tests",
32
+ "dist",
33
+ ".browserslistrc",
34
+ ".eslintrc.js",
35
+ ".gitignore",
36
+ ".travis.yml",
37
+ "babel.config.js",
38
+ "jest.config.js",
39
+ "README.md",
40
+ "tsconfig.json"
41
+ ],
10
42
  "dependencies": {
11
43
  "core-js": "^3.6.5",
12
- "vue": "^3.0.0"
44
+ "lodash-es": "^4.17.20"
13
45
  },
14
46
  "devDependencies": {
47
+ "@rollup/plugin-node-resolve": "^11.2.1",
48
+ "@rollup/plugin-typescript": "^8.1.1",
49
+ "@types/jest": "^24.0.19",
50
+ "@types/lodash-es": "^4.17.4",
51
+ "@typescript-eslint/eslint-plugin": "^2.33.0",
52
+ "@typescript-eslint/parser": "^2.33.0",
15
53
  "@vue/cli-plugin-babel": "~4.5.0",
16
54
  "@vue/cli-plugin-eslint": "~4.5.0",
55
+ "@vue/cli-plugin-typescript": "~4.5.0",
56
+ "@vue/cli-plugin-unit-jest": "^5.0.6",
17
57
  "@vue/cli-service": "~4.5.0",
18
58
  "@vue/compiler-sfc": "^3.0.0",
19
- "babel-eslint": "^10.1.0",
59
+ "@vue/eslint-config-typescript": "^5.0.2",
60
+ "@vue/test-utils": "^2.0.0-0",
20
61
  "eslint": "^6.7.2",
21
- "eslint-plugin-vue": "^7.0.0"
62
+ "eslint-plugin-vue": "^7.0.0-0",
63
+ "husky": "^4.3.8",
64
+ "rimraf": "^3.0.2",
65
+ "rollup": "^3.29.5",
66
+ "rollup-plugin-css-only": "^3.1.0",
67
+ "rollup-plugin-typescript2": "^0.29.0",
68
+ "rollup-plugin-vue": "^6.0.0",
69
+ "typescript": "^4.9.5",
70
+ "vue": "^3.5.26"
71
+ },
72
+ "peerDependencies": {
73
+ "vue": "^3.0.0"
22
74
  },
23
- "eslintConfig": {
24
- "root": true,
25
- "env": {
26
- "node": true
27
- },
28
- "extends": [
29
- "plugin:vue/vue3-essential",
30
- "eslint:recommended"
31
- ],
32
- "parserOptions": {
33
- "parser": "babel-eslint"
34
- },
35
- "rules": {}
75
+ "homepage": "https://github.com/imooc-lego/lego-components",
76
+ "keywords": [
77
+ "Component",
78
+ "UI",
79
+ "Vue3"
80
+ ],
81
+ "license": "MIT",
82
+ "repository": {
83
+ "type": "git",
84
+ "url": "git+https://github.com/imooc-lego/lego-components.git"
36
85
  },
37
- "browserslist": [
38
- "> 1%",
39
- "last 2 versions",
40
- "not dead"
41
- ]
86
+ "types": "dist/index.d.ts"
42
87
  }
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <img
3
+ :style="styleProps"
4
+ class="l-image-component"
5
+ @click.prevent="handleClick"
6
+ :src="src"
7
+ />
8
+ </template>
9
+ <script lang="ts">
10
+ import { defineComponent } from 'vue'
11
+ import useComponentCommon from '../../hooks/useComponentCommon'
12
+ import { transformToComponentProps, imageDefaultProps, imageStylePropsNames } from '../../defaultProps'
13
+ const defaultProps = transformToComponentProps(imageDefaultProps)
14
+
15
+ // array that contains style props
16
+ export default defineComponent({
17
+ name: 'l-image',
18
+ props: {
19
+ ...defaultProps
20
+ },
21
+ setup (props) {
22
+ // 重用并且简化
23
+ // 抽离并且获得 styleProps
24
+ const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames)
25
+ return {
26
+ styleProps,
27
+ handleClick
28
+ }
29
+ }
30
+ })
31
+ </script>
32
+
33
+ <style scoped>
34
+ .l-image-component {
35
+ max-width: 100%;
36
+ position: relative !important;
37
+ }
38
+ </style>
@@ -0,0 +1,7 @@
1
+ // import { App } from 'vue'
2
+ import LImage from './LImage.vue'
3
+ LImage.install = (app: any) => {
4
+ app.component(LImage.name, LImage)
5
+ }
6
+
7
+ export default LImage
@@ -0,0 +1,30 @@
1
+ <template>
2
+ <div
3
+ :style="styleProps"
4
+ class="l-shape-component"
5
+ @click.prevent="handleClick"
6
+ ></div>
7
+ </template>
8
+ <script lang="ts">
9
+ import { defineComponent } from 'vue'
10
+ import useComponentCommon from '../../hooks/useComponentCommon'
11
+ import { transformToComponentProps, shapeDefaultProps, shapeStylePropsNames } from '../../defaultProps'
12
+ const defaultProps = transformToComponentProps(shapeDefaultProps)
13
+
14
+ // array that contains style props
15
+ export default defineComponent({
16
+ name: 'l-shape',
17
+ props: {
18
+ ...defaultProps
19
+ },
20
+ setup (props) {
21
+ // 重用并且简化
22
+ // 抽离并且获得 styleProps
23
+ const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames)
24
+ return {
25
+ styleProps,
26
+ handleClick
27
+ }
28
+ }
29
+ })
30
+ </script>
@@ -0,0 +1,7 @@
1
+ // import { App } from 'vue'
2
+ import LShape from './LShape.vue'
3
+ LShape.install = (app: any) => {
4
+ app.component(LShape.name, LShape)
5
+ }
6
+
7
+ export default LShape
@@ -0,0 +1,46 @@
1
+ <template>
2
+ <component :is="tag" :style="styleProps" class="l-text-component" @click="handleClick">
3
+ {{text}}
4
+ </component>
5
+ </template>
6
+ <script lang="ts">
7
+ import { defineComponent } from 'vue'
8
+ import useComponentCommon from '../../hooks/useComponentCommon'
9
+ import { transformToComponentProps, textDefaultProps, textStylePropNames } from '../../defaultProps'
10
+ const defaultProps = transformToComponentProps(textDefaultProps)
11
+ // array that contains style props
12
+ export default defineComponent({
13
+ name: 'l-text',
14
+ props: {
15
+ tag: {
16
+ type: String,
17
+ default: 'div'
18
+ },
19
+ ...defaultProps
20
+ },
21
+ setup (props) {
22
+ // 重用并且简化
23
+ // 抽离并且获得 styleProps
24
+ const { styleProps, handleClick} = useComponentCommon(props, textStylePropNames)
25
+ return {
26
+ styleProps,
27
+ handleClick
28
+ }
29
+ }
30
+ })
31
+ </script>
32
+
33
+ <style scoped>
34
+ h2.l-text-component, p.l-text-component {
35
+ margin-bottom: 0;
36
+ }
37
+ button.l-text-component {
38
+ padding: 5px 10px;
39
+ cursor: pointer;
40
+ }
41
+ .l-text-component {
42
+ box-sizing: border-box;
43
+ white-space: pre-wrap;
44
+ position: relative !important;
45
+ }
46
+ </style>
@@ -0,0 +1,7 @@
1
+ // import { App } from 'vue'
2
+ import LText from './LText.vue'
3
+ LText.install = (app: any) => {
4
+ app.component(LText.name, LText)
5
+ }
6
+
7
+ export default LText
@@ -0,0 +1,110 @@
1
+ import { mapValues, without } from 'lodash-es'
2
+ export interface CommonComponentProps {
3
+ // actions
4
+ actionType: string;
5
+ url: string;
6
+ // size
7
+ height: string;
8
+ width: string;
9
+ paddingLeft: string;
10
+ paddingRight: string;
11
+ paddingTop: string;
12
+ paddingBottom: string;
13
+ // border type
14
+ borderStyle: string;
15
+ borderColor: string;
16
+ borderWidth: string;
17
+ borderRadius: string;
18
+ // shadow and opacity
19
+ boxShadow: string;
20
+ opacity: string;
21
+ // position and x,y
22
+ position: string;
23
+ left: string;
24
+ top: string;
25
+ right: string;
26
+ }
27
+ export const commonDefaultProps: CommonComponentProps = {
28
+ // actions
29
+ actionType: '',
30
+ url: '',
31
+ // size
32
+ height: '',
33
+ width: '373px',
34
+ paddingLeft: '0px',
35
+ paddingRight: '0px',
36
+ paddingTop: '0px',
37
+ paddingBottom: '0px',
38
+ // border type
39
+ borderStyle: 'none',
40
+ borderColor: '#000',
41
+ borderWidth: '0',
42
+ borderRadius: '0',
43
+ // shadow and opacity
44
+ boxShadow: '0 0 0 #000000',
45
+ opacity: '1',
46
+ // position and x,y
47
+ position: 'absolute',
48
+ left: '0',
49
+ top: '0',
50
+ right: '0'
51
+ }
52
+ export interface TextComponentProps extends CommonComponentProps {
53
+ text: string;
54
+ fontSize: string;
55
+ fontFamily: string;
56
+ fontWeight: string;
57
+ fontStyle: string;
58
+ textDecoration: string;
59
+ lineHeight: string;
60
+ textAlign: string;
61
+ color: string;
62
+ backgroundColor: string;
63
+ }
64
+ export interface ImageComponentProps extends CommonComponentProps {
65
+ src: string;
66
+ }
67
+ export interface ShapeComponentProps extends CommonComponentProps {
68
+ backgroundColor: string;
69
+ }
70
+ export type AllComponentProps = TextComponentProps & ImageComponentProps & ShapeComponentProps
71
+ export const textDefaultProps: TextComponentProps = {
72
+ // basic props - font styles
73
+ text: '正文内容',
74
+ fontSize: '14px',
75
+ fontFamily: '',
76
+ fontWeight: 'normal',
77
+ fontStyle: 'normal',
78
+ textDecoration: 'none',
79
+ lineHeight: '1',
80
+ textAlign: 'left',
81
+ color: '#000000',
82
+ backgroundColor: '',
83
+ ...commonDefaultProps
84
+ }
85
+ export const imageDefaultProps: ImageComponentProps = {
86
+ src: 'test.url',
87
+ ...commonDefaultProps
88
+ }
89
+ export const shapeDefaultProps: ShapeComponentProps = {
90
+ backgroundColor: '',
91
+ ...commonDefaultProps
92
+ }
93
+ export const isEditingProp = {
94
+ isEditing: {
95
+ type: Boolean,
96
+ default: false
97
+ }
98
+ }
99
+ export const textStylePropNames = without(Object.keys(textDefaultProps), 'actionType', 'url', 'text')
100
+ export const imageStylePropsNames = without(Object.keys(imageDefaultProps), 'actionType', 'url', 'src')
101
+ export const shapeStylePropsNames = without(Object.keys(imageDefaultProps), 'actionType', 'url')
102
+ export const transformToComponentProps = <T extends {}>(props: T) => {
103
+ const mapProps = mapValues(props, (item) => {
104
+ return {
105
+ type: (item as any).constructor as StringConstructor,
106
+ default: item
107
+ }
108
+ })
109
+ return { ...mapProps, ...isEditingProp }
110
+ }
@@ -0,0 +1,17 @@
1
+ import { computed } from 'vue'
2
+ import { pick } from 'lodash-es'
3
+ import { CommonComponentProps } from '../defaultProps'
4
+ const useComponentCommon =(props: Readonly<Partial<CommonComponentProps & { isEditing: boolean }>>, picks: string[]) => {
5
+ const styleProps = computed(() => pick(props, picks))
6
+ const handleClick = () => {
7
+ if (props.actionType === 'url' && props.url && !props.isEditing) {
8
+ window.location.href = props.url
9
+ }
10
+ }
11
+ return {
12
+ styleProps,
13
+ handleClick
14
+ }
15
+ }
16
+
17
+ export default useComponentCommon
package/src/index.ts ADDED
@@ -0,0 +1,34 @@
1
+ // import { App } from 'vue'
2
+ export { textDefaultProps , textStylePropNames, TextComponentProps,
3
+ imageDefaultProps, imageStylePropsNames, ImageComponentProps,
4
+ shapeDefaultProps, shapeStylePropsNames, ShapeComponentProps,
5
+ AllComponentProps
6
+ } from './defaultProps'
7
+
8
+
9
+
10
+ import LText from './components/LText'
11
+ import LImage from './components/LImage'
12
+ import LShape from './components/LShape'
13
+
14
+ const components = [
15
+ LText,
16
+ LImage,
17
+ LShape
18
+ ]
19
+ // @ts-ignore
20
+ const install = (app: App) => {
21
+ components.forEach(component => {
22
+ app.component(component.name, component)
23
+ })
24
+ }
25
+
26
+ export {
27
+ LText,
28
+ LImage,
29
+ LShape,
30
+ install
31
+ }
32
+ export default {
33
+ install
34
+ }
@@ -0,0 +1,5 @@
1
+ declare module '*.vue' {
2
+ import { DefineComponent } from 'vue'
3
+ const component: DefineComponent<{}, {}, any>
4
+ export default component
5
+ }
@@ -0,0 +1,57 @@
1
+ import { shallowMount } from '@vue/test-utils'
2
+ import LText from '../../src/components/LText'
3
+ import { textDefaultProps } from '../../src/defaultProps'
4
+ describe('LText.vue', () => {
5
+ const { location } = window
6
+ beforeEach(() => {
7
+ Object.defineProperty(window, 'location', {
8
+ writable: true,
9
+ value: { href: '' }
10
+ })
11
+ })
12
+ afterEach(() => {
13
+ window.location = location
14
+ })
15
+ it('default LText render', () => {
16
+ const msg = 'test'
17
+ const props = {
18
+ ...textDefaultProps,
19
+ text: msg
20
+ }
21
+ const wrapper = shallowMount(LText, { props })
22
+ // should have the right text
23
+ expect(wrapper.text()).toBe(msg)
24
+ // should be default div tag
25
+ expect(wrapper.element.tagName).toBe('DIV')
26
+ // should have certian css attr
27
+ const style = wrapper.attributes().style
28
+ console.log(style)
29
+ expect(style.includes('font-size')).toBeTruthy()
30
+ // should not have prop has been filtered
31
+ expect(style.includes('actionType')).toBeFalsy()
32
+ })
33
+ it('LText with actionType and URL should trigger location href change', async () => {
34
+ const props = {
35
+ ...textDefaultProps,
36
+ actionType: 'url',
37
+ url: 'http://dummy.url',
38
+ tag: 'h2'
39
+ }
40
+ const wrapper = shallowMount(LText, { props })
41
+ expect(wrapper.element.tagName).toBe('H2')
42
+ await wrapper.trigger('click')
43
+ expect(window.location.href).toBe('http://dummy.url')
44
+ })
45
+ it('LText with isEditing should not trigger location change', async () => {
46
+ const props = {
47
+ ...textDefaultProps,
48
+ actionType: 'url',
49
+ url: 'http://dummy.url',
50
+ tag: 'h2',
51
+ isEditing: true
52
+ }
53
+ const wrapper = shallowMount(LText, { props })
54
+ await wrapper.trigger('click')
55
+ expect(window.location.href).not.toBe('http://dummy.url')
56
+ })
57
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "esnext",
5
+ "strict": false,
6
+ "jsx": "preserve",
7
+ "importHelpers": true,
8
+ "moduleResolution": "node",
9
+ "skipLibCheck": true,
10
+ "esModuleInterop": true,
11
+ "allowSyntheticDefaultImports": true,
12
+ "sourceMap": true,
13
+ "baseUrl": ".",
14
+ "types": ["vue"],
15
+ "paths": {
16
+ "@/*": [
17
+ "src/*"
18
+ ]
19
+ },
20
+ "lib": [
21
+ "esnext",
22
+ "dom",
23
+ "dom.iterable",
24
+ "scripthost"
25
+ ]
26
+ },
27
+ "include": [
28
+ "shims-vue.d.ts", // 添加这一行
29
+ "src/**/*.ts",
30
+ "src/**/*.tsx",
31
+ "src/**/*.vue",
32
+ "tests/**/*.ts",
33
+ "tests/**/*.tsx"
34
+ ],
35
+ "exclude": [
36
+ "node_modules",
37
+ "src/**/*.ts",
38
+ "src/**/*.tsx",
39
+ "src/**/*.vue",
40
+ "tests/**/*.ts",
41
+ "tests/**/*.tsx"
42
+ ]
43
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes