SelectorQuery.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div>
  3. <div class="flex items-center">
  4. <ui-select
  5. :model-value="selectorType"
  6. :disabled="selectList"
  7. class="w-full"
  8. @change="$emit('update:selectorType', $event)"
  9. >
  10. <option value="css">CSS Selector</option>
  11. <option value="xpath">XPath</option>
  12. </ui-select>
  13. <ui-button
  14. v-if="selectorType === 'css'"
  15. :class="{ 'text-primary': selectList }"
  16. icon
  17. class="ml-2"
  18. title="Select a list of elements"
  19. @click.stop.prevent="$emit('update:selectList', !selectList)"
  20. >
  21. <v-remixicon name="riListUnordered" />
  22. </ui-button>
  23. </div>
  24. <div class="mt-2 flex items-center">
  25. <ui-input
  26. :model-value="selector"
  27. placeholder="Element selector"
  28. class="leading-normal flex-1 h-full element-selector"
  29. @change="$emit('selector', $event)"
  30. >
  31. <template #prepend>
  32. <button
  33. class="absolute ml-2 left-0"
  34. @click.stop.prevent="copySelector"
  35. >
  36. <v-remixicon name="riFileCopyLine" />
  37. </button>
  38. </template>
  39. </ui-input>
  40. <template v-if="selectedCount === 1 && !selector.includes('|>')">
  41. <button
  42. class="mr-1 ml-2"
  43. title="Parent element"
  44. @click.stop.prevent="$emit('parent')"
  45. >
  46. <v-remixicon rotate="90" name="riArrowLeftLine" />
  47. </button>
  48. <button title="Child element" @click.stop.prevent="$emit('child')">
  49. <v-remixicon rotate="-90" name="riArrowLeftLine" />
  50. </button>
  51. </template>
  52. </div>
  53. </div>
  54. </template>
  55. <script setup>
  56. import { inject } from 'vue';
  57. import UiInput from '@/components/ui/UiInput.vue';
  58. const props = defineProps({
  59. selector: {
  60. type: String,
  61. default: '',
  62. },
  63. selectedCount: {
  64. type: Number,
  65. default: 0,
  66. },
  67. selectorType: {
  68. type: String,
  69. default: '',
  70. },
  71. selectList: {
  72. type: Boolean,
  73. default: false,
  74. },
  75. });
  76. defineEmits([
  77. 'change',
  78. 'list',
  79. 'parent',
  80. 'child',
  81. 'selector',
  82. 'update:selectorType',
  83. 'update:selectList',
  84. ]);
  85. const rootElement = inject('rootElement');
  86. function copySelector() {
  87. rootElement.shadowRoot.querySelector('input')?.select();
  88. navigator.clipboard.writeText(props.selector).catch((error) => {
  89. document.execCommand('copy');
  90. console.error(error);
  91. });
  92. }
  93. </script>