vue-client-only.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. (global.ClientOnly = factory());
  10. }(this, (function () { 'use strict';
  11. var index = {
  12. name: 'ClientOnly',
  13. functional: true,
  14. props: {
  15. placeholder: String,
  16. placeholderTag: {
  17. type: String,
  18. default: 'div'
  19. }
  20. },
  21. render: function render(h, ref) {
  22. var parent = ref.parent;
  23. var slots = ref.slots;
  24. var props = ref.props;
  25. var ref$1 = slots();
  26. var defaultSlot = ref$1.default; if ( defaultSlot === void 0 ) defaultSlot = [];
  27. var placeholderSlot = ref$1.placeholder;
  28. if (parent._isMounted) {
  29. return defaultSlot
  30. }
  31. parent.$once('hook:mounted', function () {
  32. parent.$forceUpdate();
  33. });
  34. if (props.placeholderTag && (props.placeholder || placeholderSlot)) {
  35. return h(
  36. props.placeholderTag,
  37. {
  38. class: ['client-only-placeholder']
  39. },
  40. props.placeholder || placeholderSlot
  41. )
  42. }
  43. // Return a placeholder element for each child in the default slot
  44. // Or if no children return a single placeholder
  45. return defaultSlot.length > 0 ? defaultSlot.map(function () { return h(false); }) : h(false)
  46. }
  47. };
  48. return index;
  49. })));