@dolphinweex/weex-harmony 0.1.2 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolphinweex/weex-harmony",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "weex harmony adapter",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div>
2
+ <div v-on="filteredListeners">
3
3
  <embed
4
4
  :id="embedId"
5
5
  :type="embedType"
@@ -33,6 +33,11 @@ export default {
33
33
  required: false,
34
34
  default: 0,
35
35
  },
36
+ listenEvents:{
37
+ type: Array,
38
+ required: false,
39
+ default: [],
40
+ }
36
41
  },
37
42
  data() {
38
43
  return {
@@ -40,6 +45,17 @@ export default {
40
45
  };
41
46
  },
42
47
  computed: {
48
+ filteredListeners() {
49
+ // 指定传给父级标签的vue原生事件 尝试过外面v-on="{ 'click': $listeners.click }" 局部传但是不行
50
+ if (!this.listenEvents.length) { return {} }
51
+ const filtered = {};
52
+ Object.keys(this.$listeners).forEach(event => {
53
+ if (this.listenEvents.includes(event)) {
54
+ filtered[event] = this.$listeners[event];
55
+ }
56
+ });
57
+ return filtered;
58
+ },
43
59
  embedWidth() {
44
60
  // 如果hosSameLayerArgs.width存在且定义了,则使用该值,否则使用defaultWidth
45
61
  return this.hosSameLayerArgs.width || this.defaultWidth;
@@ -4,6 +4,8 @@
4
4
  embedType="native/midea-lottie-view"
5
5
  :defaultWidth="300"
6
6
  :defaultHeight="300"
7
+ v-on="$listeners"
8
+ :listenEvents="['click']"
7
9
  >
8
10
  </BaseSameLayer>
9
11
  </template>
@@ -152,8 +152,20 @@ function generateCode(moduleResoveRet) {
152
152
  let styleAttrs = ''
153
153
  let scriptAttrs = ''
154
154
 
155
- moduleResoveRet.styles.forEach((item) => {
155
+ let styleStr = ''
156
+ moduleResoveRet.styles.forEach((item, i) => {
157
+ styleTemplate = ''
158
+ styleAttrs = ''
156
159
  styleTemplate += item.content
160
+
161
+ Object.keys(moduleResoveRet.styles[i].attrs).forEach((item) => {
162
+ if (typeof moduleResoveRet.styles[i].attrs[item] === 'boolean') {
163
+ styleAttrs += ` ${item}`
164
+ } else {
165
+ styleAttrs += ` ${item}="${moduleResoveRet.styles[i].attrs[item]}"`
166
+ }
167
+ })
168
+ styleStr += `<style${styleAttrs}>${styleTemplate}</style>\n`
157
169
  })
158
170
 
159
171
  Object.keys(moduleResoveRet.script.attrs).forEach((item) => {
@@ -164,20 +176,10 @@ function generateCode(moduleResoveRet) {
164
176
  }
165
177
  })
166
178
 
167
- if(moduleResoveRet.styles.length){
168
- Object.keys(moduleResoveRet.styles[0].attrs).forEach((item) => {
169
- if (typeof moduleResoveRet.styles[0].attrs[item] === 'boolean') {
170
- styleAttrs += ` ${item}`
171
- } else {
172
- styleAttrs += ` ${item}="${moduleResoveRet.styles[0].attrs[item]}"`
173
- }
174
- })
175
- }
176
-
177
179
  const template = `
178
- <template>${moduleResoveRet.template.content}</template>
179
- <script${scriptAttrs}>${moduleResoveRet.script.content}</script>
180
- <style${styleAttrs}>${styleTemplate}</style>
180
+ <template>${moduleResoveRet.template.content}</template>
181
+ <script${scriptAttrs}>${moduleResoveRet.script.content}</script>
182
+ ${styleStr}
181
183
  `
182
184
  return template
183
185
  }
@@ -220,6 +222,28 @@ module.exports = function (source) {
220
222
  path.unshiftContainer('body', buildImportDeclaration(componentName))
221
223
  })
222
224
  },
225
+ AssignmentExpression(path) {
226
+ const left = path.node.left;
227
+ if (
228
+ left.type === 'MemberExpression' &&
229
+ left.object.name === 'module' &&
230
+ left.property.name === 'exports'
231
+ ) {
232
+ if (componentSet.size !== 0) {
233
+ if (t.isObjectExpression(path.node.right)) {
234
+ const properties = path.node.right.properties
235
+ const result = properties.find(item => item.key.name == 'components')
236
+ if (result) {
237
+ addComponentsProperty(result)
238
+ } else {
239
+ const componentsAst = t.objectProperty(t.identifier('components'), t.objectExpression([]))
240
+ properties.push(componentsAst)
241
+ addComponentsProperty(componentsAst)
242
+ }
243
+ }
244
+ }
245
+ }
246
+ },
223
247
  ExportDefaultDeclaration(path) {
224
248
  if (componentSet.size !== 0) {
225
249
  if (t.isObjectExpression(path.node.declaration)) {