@ecomplus/widget-product 1.0.0-beta.13 → 1.0.0-beta.131

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": "@ecomplus/widget-product",
3
- "version": "1.0.0-beta.13",
3
+ "version": "1.0.0-beta.131",
4
4
  "description": "Storefront plugin & Vue component for full product block",
5
5
  "module": "src/index.js",
6
6
  "browser": "dist/widget-product.min.js",
@@ -8,7 +8,7 @@
8
8
  "jsdelivr": "dist/public/widget-product.var.min.js",
9
9
  "unpkg": "dist/public/widget-product.var.min.js",
10
10
  "scripts": {
11
- "build": "NODE_ENV=production webpack",
11
+ "build": "cross-env NODE_ENV=production webpack",
12
12
  "serve": "webpack-dev-server"
13
13
  },
14
14
  "repository": {
@@ -29,12 +29,12 @@
29
29
  },
30
30
  "homepage": "https://github.com/ecomplus/storefront/tree/master/@ecomplus/widget-product#readme",
31
31
  "peerDependencies": {
32
- "@ecomplus/utils": "^1.4.0",
32
+ "@ecomplus/utils": "^1.4.1",
33
33
  "core-js": "3.x",
34
34
  "vue": ">=2 <4"
35
35
  },
36
36
  "dependencies": {
37
- "@ecomplus/storefront-components": "^1.0.0-beta.16"
37
+ "@ecomplus/storefront-components": "^1.0.0-beta.134"
38
38
  },
39
39
  "webpackOutput": {
40
40
  "library": "widgetProduct",
package/src/index.js CHANGED
@@ -5,36 +5,92 @@
5
5
  */
6
6
 
7
7
  import Vue from 'vue'
8
+ import { inStock as checkInStock } from '@ecomplus/utils'
8
9
  import TheProduct from '#components/TheProduct.vue'
9
10
 
10
11
  export default (options = {}, elId = 'product') => {
11
12
  const $productBlock = document.getElementById(elId)
12
13
  if ($productBlock) {
13
- const getScopedSlots = window.storefront && window.storefront.getScopedSlots
14
+ const $dock = document.getElementById(`${elId}-dock`)
15
+ const isSSR = Boolean($dock)
16
+ const { storefront } = window
17
+ let getScopedSlots, body, themeConfig
18
+ if (storefront) {
19
+ getScopedSlots = storefront.getScopedSlots
20
+ body = storefront.context && storefront.context.body
21
+ themeConfig = storefront.theme && storefront.theme.product
22
+ }
23
+
24
+ let mounted
25
+ const removeSpinner = () => {
26
+ const $loading = document.getElementById('product-loading')
27
+ if ($loading) {
28
+ $loading.remove()
29
+ }
30
+ delete $productBlock.dataset.toRender
31
+ }
32
+ if (isSSR) {
33
+ mounted = removeSpinner
34
+ }
35
+
36
+ const {
37
+ buyText,
38
+ strHasQuantitySelector,
39
+ strHasPromotionTimer,
40
+ lowQuantityToWarn,
41
+ maxVariationOptionsBtns
42
+ } = options
43
+
44
+ const strOptionToBool = (strOption, prop) => {
45
+ return strOption === '_'
46
+ ? Boolean(themeConfig && themeConfig[prop])
47
+ : strOption ? Boolean(strOption.trim()) : false
48
+ }
14
49
 
15
50
  new Vue({
16
51
  render: h => h(TheProduct, {
17
52
  attrs: {
18
- id: elId
53
+ id: $dock ? null : elId
19
54
  },
20
55
  props: {
21
56
  ...options.props,
22
- buyText: options.buyText
57
+ product: isSSR && body && body.available && checkInStock(body) ? body : null,
58
+ buyText,
59
+ hasQuantitySelector: strOptionToBool(strHasQuantitySelector, 'hasQuantitySelector'),
60
+ hasPromotionTimer: strOptionToBool(strHasPromotionTimer, 'hasPromotionTimer'),
61
+ lowQuantityToWarn,
62
+ maxVariationOptionsBtns,
63
+ isSSR
64
+ },
65
+ on: {
66
+ 'update:product' (product) {
67
+ if (!isSSR) {
68
+ removeSpinner()
69
+ }
70
+ if (options.$emit) {
71
+ options.$emit('update:product', product)
72
+ }
73
+ }
23
74
  },
24
75
 
25
76
  scopedSlots: Object.assign(
26
77
  {
27
- buy: !options.buy ? undefined : function () {
28
- return h('span', {
29
- domProps: {
30
- innerHTML: options.buy
31
- }
32
- })
33
- }
78
+ buy: !options.buy
79
+ ? undefined
80
+ : function () {
81
+ return h('span', {
82
+ domProps: {
83
+ innerHTML: options.buy
84
+ }
85
+ })
86
+ }
34
87
  },
35
- typeof getScopedSlots === 'function' ? getScopedSlots($productBlock, h) : {}
88
+ typeof getScopedSlots === 'function'
89
+ ? getScopedSlots($productBlock, h, !$dock)
90
+ : {}
36
91
  )
37
- })
38
- }).$mount($productBlock)
92
+ }),
93
+ mounted
94
+ }).$mount($dock || $productBlock)
39
95
  }
40
96
  }
@@ -0,0 +1 @@
1
+ module.exports = require('../../webpack.config')