|
| 1 | +import { computed, defineComponent, openBlock, createBlock, resolveDynamicComponent, normalizeStyle, withCtx, createTextVNode, toDisplayString, pushScopeId, popScopeId, createElementBlock, withModifiers } from 'vue'; |
| 2 | +import { without, mapValues, pick } from 'lodash-es'; |
| 3 | + |
| 4 | +const commonDefaultProps = { |
| 5 | + // actions |
| 6 | + actionType: '', |
| 7 | + url: '', |
| 8 | + // size |
| 9 | + height: '', |
| 10 | + width: '373px', |
| 11 | + paddingLeft: '0px', |
| 12 | + paddingRight: '0px', |
| 13 | + paddingTop: '0px', |
| 14 | + paddingBottom: '0px', |
| 15 | + // border type |
| 16 | + borderStyle: 'none', |
| 17 | + borderColor: '#000', |
| 18 | + borderWidth: '0', |
| 19 | + borderRadius: '0', |
| 20 | + // shadow and opacity |
| 21 | + boxShadow: '0 0 0 #000000', |
| 22 | + opacity: '1', |
| 23 | + // position and x,y |
| 24 | + position: 'absolute', |
| 25 | + left: '0', |
| 26 | + top: '0', |
| 27 | + right: '0' |
| 28 | +}; |
| 29 | +const textDefaultProps = { |
| 30 | + // basic props - font styles |
| 31 | + text: '正文内容', |
| 32 | + fontSize: '14px', |
| 33 | + fontFamily: '', |
| 34 | + fontWeight: 'normal', |
| 35 | + fontStyle: 'normal', |
| 36 | + textDecoration: 'none', |
| 37 | + lineHeight: '1', |
| 38 | + textAlign: 'left', |
| 39 | + color: '#000000', |
| 40 | + backgroundColor: '', |
| 41 | + ...commonDefaultProps |
| 42 | +}; |
| 43 | +const imageDefaultProps = { |
| 44 | + src: 'test.url', |
| 45 | + ...commonDefaultProps |
| 46 | +}; |
| 47 | +const shapeDefaultProps = { |
| 48 | + backgroundColor: '', |
| 49 | + ...commonDefaultProps |
| 50 | +}; |
| 51 | +const isEditingProp = { |
| 52 | + isEditing: { |
| 53 | + type: Boolean, |
| 54 | + default: false |
| 55 | + } |
| 56 | +}; |
| 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(imageDefaultProps), 'actionType', 'url'); |
| 60 | +const transformToComponentProps = (props) => { |
| 61 | + const mapProps = mapValues(props, (item) => { |
| 62 | + return { |
| 63 | + type: item.constructor, |
| 64 | + default: item |
| 65 | + }; |
| 66 | + }); |
| 67 | + return { ...mapProps, ...isEditingProp }; |
| 68 | +}; |
| 69 | + |
| 70 | +const useComponentCommon = (props, picks) => { |
| 71 | + const styleProps = computed(() => pick(props, picks)); |
| 72 | + const handleClick = () => { |
| 73 | + if (props.actionType === 'url' && props.url && !props.isEditing) { |
| 74 | + window.location.href = props.url; |
| 75 | + } |
| 76 | + }; |
| 77 | + return { |
| 78 | + styleProps, |
| 79 | + handleClick, |
| 80 | + }; |
| 81 | +}; |
| 82 | + |
| 83 | +const defaultProps$2 = transformToComponentProps(textDefaultProps); |
| 84 | +var script$2 = defineComponent({ |
| 85 | + name: 'LText', |
| 86 | + props: { |
| 87 | + ...defaultProps$2, |
| 88 | + tag: { |
| 89 | + type: String, |
| 90 | + default: 'div', |
| 91 | + }, |
| 92 | + }, |
| 93 | + setup(props) { |
| 94 | + const { styleProps, handleClick } = useComponentCommon(props, textStylePropNames); |
| 95 | + return { |
| 96 | + styleProps, |
| 97 | + handleClick, |
| 98 | + }; |
| 99 | + }, |
| 100 | +}); |
| 101 | + |
| 102 | +function render$2(_ctx, _cache, $props, $setup, $data, $options) { |
| 103 | + return (openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), { |
| 104 | + style: normalizeStyle(_ctx.styleProps), |
| 105 | + class: "l-text-component", |
| 106 | + onClick: _ctx.handleClick |
| 107 | + }, { |
| 108 | + default: withCtx(() => [ |
| 109 | + createTextVNode(toDisplayString(_ctx.text), 1 /* TEXT */) |
| 110 | + ]), |
| 111 | + _: 1 /* STABLE */ |
| 112 | + }, 8 /* PROPS */, ["style", "onClick"])) |
| 113 | +} |
| 114 | + |
| 115 | +script$2.render = render$2; |
| 116 | +script$2.__scopeId = "data-v-6bf95b7a"; |
| 117 | +script$2.__file = "src/components/LText/LText.vue"; |
| 118 | + |
| 119 | +script$2.install = (app) => { |
| 120 | + app.component(script$2.name, script$2); |
| 121 | +}; |
| 122 | + |
| 123 | +const defaultProps$1 = transformToComponentProps(imageDefaultProps); |
| 124 | +// array that contains style props |
| 125 | +var script$1 = defineComponent({ |
| 126 | + name: 'l-image', |
| 127 | + props: { |
| 128 | + ...defaultProps$1 |
| 129 | + }, |
| 130 | + setup(props) { |
| 131 | + // 重用并且简化 |
| 132 | + // 抽离并且获得 styleProps |
| 133 | + const { styleProps, handleClick } = useComponentCommon(props, imageStylePropsNames); |
| 134 | + return { |
| 135 | + styleProps, |
| 136 | + handleClick |
| 137 | + }; |
| 138 | + } |
| 139 | +}); |
| 140 | + |
| 141 | +pushScopeId("data-v-1e970aa2"); |
| 142 | +const _hoisted_1 = ["src"]; |
| 143 | +popScopeId(); |
| 144 | + |
| 145 | +function render$1(_ctx, _cache, $props, $setup, $data, $options) { |
| 146 | + return (openBlock(), createElementBlock("img", { |
| 147 | + style: normalizeStyle(_ctx.styleProps), |
| 148 | + class: "l-image-component", |
| 149 | + onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])), |
| 150 | + src: _ctx.src |
| 151 | + }, null, 12 /* STYLE, PROPS */, _hoisted_1)) |
| 152 | +} |
| 153 | + |
| 154 | +script$1.render = render$1; |
| 155 | +script$1.__scopeId = "data-v-1e970aa2"; |
| 156 | +script$1.__file = "src/components/LImage/LImage.vue"; |
| 157 | + |
| 158 | +script$1.install = (app) => { |
| 159 | + app.component(script$1.name, script$1); |
| 160 | +}; |
| 161 | + |
| 162 | +const defaultProps = transformToComponentProps(shapeDefaultProps); |
| 163 | +// array that contains style props |
| 164 | +var script = defineComponent({ |
| 165 | + name: 'l-shape', |
| 166 | + props: { |
| 167 | + ...defaultProps |
| 168 | + }, |
| 169 | + setup(props) { |
| 170 | + // 重用并且简化 |
| 171 | + // 抽离并且获得 styleProps |
| 172 | + const { styleProps, handleClick } = useComponentCommon(props, shapeStylePropsNames); |
| 173 | + return { |
| 174 | + styleProps, |
| 175 | + handleClick |
| 176 | + }; |
| 177 | + } |
| 178 | +}); |
| 179 | + |
| 180 | +function render(_ctx, _cache, $props, $setup, $data, $options) { |
| 181 | + return (openBlock(), createElementBlock("div", { |
| 182 | + style: normalizeStyle(_ctx.styleProps), |
| 183 | + class: "l-shape-component", |
| 184 | + onClick: _cache[0] || (_cache[0] = withModifiers((...args) => (_ctx.handleClick && _ctx.handleClick(...args)), ["prevent"])) |
| 185 | + }, null, 4 /* STYLE */)) |
| 186 | +} |
| 187 | + |
| 188 | +script.render = render; |
| 189 | +script.__file = "src/components/LShape/LShape.vue"; |
| 190 | + |
| 191 | +script.install = (app) => { |
| 192 | + app.component(script.name, script); |
| 193 | +}; |
| 194 | + |
| 195 | +const components = [ |
| 196 | + script$2, |
| 197 | + script$1, |
| 198 | + script |
| 199 | +]; |
| 200 | +const install = (app) => { |
| 201 | + components.forEach(component => { |
| 202 | + app.component(component.name, component); |
| 203 | + }); |
| 204 | +}; |
| 205 | +var index = { |
| 206 | + install |
| 207 | +}; |
| 208 | + |
| 209 | +export { script$1 as LImage, script as LShape, script$2 as LText, index as default, install }; |
0 commit comments