|
1 | 1 | <template> |
2 | 2 | <div> |
3 | | - <button |
4 | | - type="button" |
5 | | - class="btn" |
6 | | - :disabled="!show" |
| 3 | + <Button |
7 | 4 | @click="copyToClipboard" |
8 | | - v-text="__('Copy Review URL to Clipboard')" |
9 | | - > |
10 | | - </button> |
| 5 | + :disabled="!show" |
| 6 | + :text="__('Copy Review URL to Clipboard')" |
| 7 | + /> |
11 | 8 | </div> |
12 | 9 | </template> |
13 | 10 |
|
14 | | -<script> |
15 | | - export default { |
16 | | - mixins: [Fieldtype], |
17 | | -
|
18 | | - computed: { |
19 | | - entryDate() { |
20 | | - let dateTime = this.publishForm.values.date; |
21 | | -
|
22 | | - if (!dateTime) { |
23 | | - return null |
24 | | - } |
25 | | -
|
26 | | - return moment(dateTime.date + 'T' + dateTime.time, 'YYYY-MM-DDTHH:mm'); |
27 | | - }, |
28 | | -
|
29 | | - isFuture() { |
30 | | - return this.entryDate?.isAfter(moment()); |
31 | | - }, |
32 | | -
|
33 | | - isWorkingCopy() { |
34 | | - return this.publishForm.revisionsEnabled && this.publishForm.isWorkingCopy; |
35 | | - }, |
36 | | -
|
37 | | - publishForm() { |
38 | | - let vm = this; |
39 | | - while (true) { |
40 | | - let parent = vm.$parent; |
41 | | -
|
42 | | - if (!parent) { |
43 | | - return false; |
44 | | - } |
45 | | -
|
46 | | - if (parent.$options._componentTag == "entry-publish-form") { |
47 | | - return parent; |
48 | | - } |
49 | | - vm = parent; |
50 | | - } |
51 | | - }, |
52 | | -
|
53 | | - show() { |
54 | | - if (!this.publishForm) { |
55 | | - return false; |
56 | | - } |
57 | | -
|
58 | | - if (this.publishForm.isDirty) { |
59 | | - return false; |
60 | | - } |
61 | | -
|
62 | | - return this.isWorkingCopy || !this.publishForm.published || this.isFuture; |
63 | | - }, |
64 | | -
|
65 | | - }, |
66 | | -
|
67 | | - methods: { |
68 | | - copyToClipboard() { |
69 | | - navigator.clipboard.writeText(this.meta.site_url); |
70 | | - this.$toast.success(__("Review URL copied to clipboard")); |
71 | | - }, |
72 | | -
|
73 | | - }, |
74 | | - }; |
| 11 | +<script setup> |
| 12 | +import { computed } from 'vue'; |
| 13 | +import { Fieldtype } from '@statamic/cms'; |
| 14 | +import { toast } from '@statamic/cms/api'; |
| 15 | +import { Button, injectPublishContext } from '@statamic/cms/ui'; |
| 16 | +
|
| 17 | +const props = defineProps(Fieldtype.props); |
| 18 | +const { isDirty, isWorkingCopy, revisionsEnabled, values } = injectPublishContext(); |
| 19 | +
|
| 20 | +const entryDate = computed(() => values.value.date ? new Date(values.value.date) : null); |
| 21 | +const isFuture = computed(() => entryDate.value > Date.now()); |
| 22 | +const show = computed(() => !isDirty.value && |
| 23 | + ((isWorkingCopy.value && revisionsEnabled.value) || |
| 24 | + !values.value.published || |
| 25 | + isFuture.value) |
| 26 | +); |
| 27 | +
|
| 28 | +function copyToClipboard() { |
| 29 | + navigator.clipboard.writeText(props.meta.site_url); |
| 30 | + toast.success(__("Review URL copied to clipboard")); |
| 31 | +}; |
75 | 32 | </script> |
0 commit comments