logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

shadow_control.js (3126B)


  1. import ColorInput from '../color_input/color_input.vue'
  2. import OpacityInput from '../opacity_input/opacity_input.vue'
  3. import Select from '../select/select.vue'
  4. import { getCssShadow } from '../../services/theme_data/theme_data.service.js'
  5. import { hex2rgb } from '../../services/color_convert/color_convert.js'
  6. import { library } from '@fortawesome/fontawesome-svg-core'
  7. import {
  8. faTimes,
  9. faChevronDown,
  10. faChevronUp,
  11. faPlus
  12. } from '@fortawesome/free-solid-svg-icons'
  13. library.add(
  14. faChevronDown,
  15. faChevronUp,
  16. faTimes,
  17. faPlus
  18. )
  19. const toModel = (object = {}) => ({
  20. x: 0,
  21. y: 0,
  22. blur: 0,
  23. spread: 0,
  24. inset: false,
  25. color: '#000000',
  26. alpha: 1,
  27. ...object
  28. })
  29. export default {
  30. // 'modelValue' and 'Fallback' can be undefined, but if they are
  31. // initially vue won't detect it when they become something else
  32. // therefore i'm using "ready" which should be passed as true when
  33. // data becomes available
  34. props: [
  35. 'modelValue', 'fallback', 'ready'
  36. ],
  37. emits: ['update:modelValue'],
  38. data () {
  39. return {
  40. selectedId: 0,
  41. // TODO there are some bugs regarding display of array (it's not getting updated when deleting for some reason)
  42. cValue: (this.modelValue || this.fallback || []).map(toModel)
  43. }
  44. },
  45. components: {
  46. ColorInput,
  47. OpacityInput,
  48. Select
  49. },
  50. methods: {
  51. add () {
  52. this.cValue.push(toModel(this.selected))
  53. this.selectedId = this.cValue.length - 1
  54. },
  55. del () {
  56. this.cValue.splice(this.selectedId, 1)
  57. this.selectedId = this.cValue.length === 0 ? undefined : Math.max(this.selectedId - 1, 0)
  58. },
  59. moveUp () {
  60. const movable = this.cValue.splice(this.selectedId, 1)[0]
  61. this.cValue.splice(this.selectedId - 1, 0, movable)
  62. this.selectedId -= 1
  63. },
  64. moveDn () {
  65. const movable = this.cValue.splice(this.selectedId, 1)[0]
  66. this.cValue.splice(this.selectedId + 1, 0, movable)
  67. this.selectedId += 1
  68. }
  69. },
  70. beforeUpdate () {
  71. this.cValue = this.modelValue || this.fallback
  72. },
  73. computed: {
  74. anyShadows () {
  75. return this.cValue.length > 0
  76. },
  77. anyShadowsFallback () {
  78. return this.fallback.length > 0
  79. },
  80. selected () {
  81. if (this.ready && this.anyShadows) {
  82. return this.cValue[this.selectedId]
  83. } else {
  84. return toModel({})
  85. }
  86. },
  87. currentFallback () {
  88. if (this.ready && this.anyShadowsFallback) {
  89. return this.fallback[this.selectedId]
  90. } else {
  91. return toModel({})
  92. }
  93. },
  94. moveUpValid () {
  95. return this.ready && this.selectedId > 0
  96. },
  97. moveDnValid () {
  98. return this.ready && this.selectedId < this.cValue.length - 1
  99. },
  100. present () {
  101. return this.ready &&
  102. typeof this.cValue[this.selectedId] !== 'undefined' &&
  103. !this.usingFallback
  104. },
  105. usingFallback () {
  106. return typeof this.modelValue === 'undefined'
  107. },
  108. rgb () {
  109. return hex2rgb(this.selected.color)
  110. },
  111. style () {
  112. return this.ready
  113. ? {
  114. boxShadow: getCssShadow(this.fallback)
  115. }
  116. : {}
  117. }
  118. }
  119. }