vue-client-only.common.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*!
  2. * vue-client-only v0.0.0-semantic-release
  3. * (c) 2021-present egoist <0x142857@gmail.com>
  4. * Released under the MIT License.
  5. */
  6. 'use strict';
  7. var index = {
  8. name: 'ClientOnly',
  9. functional: true,
  10. props: {
  11. placeholder: String,
  12. placeholderTag: {
  13. type: String,
  14. default: 'div'
  15. }
  16. },
  17. render: function render(h, ref) {
  18. var parent = ref.parent;
  19. var slots = ref.slots;
  20. var props = ref.props;
  21. var ref$1 = slots();
  22. var defaultSlot = ref$1.default; if ( defaultSlot === void 0 ) defaultSlot = [];
  23. var placeholderSlot = ref$1.placeholder;
  24. if (parent._isMounted) {
  25. return defaultSlot
  26. }
  27. parent.$once('hook:mounted', function () {
  28. parent.$forceUpdate();
  29. });
  30. if (props.placeholderTag && (props.placeholder || placeholderSlot)) {
  31. return h(
  32. props.placeholderTag,
  33. {
  34. class: ['client-only-placeholder']
  35. },
  36. props.placeholder || placeholderSlot
  37. )
  38. }
  39. // Return a placeholder element for each child in the default slot
  40. // Or if no children return a single placeholder
  41. return defaultSlot.length > 0 ? defaultSlot.map(function () { return h(false); }) : h(false)
  42. }
  43. };
  44. module.exports = index;