-
-
Notifications
You must be signed in to change notification settings - Fork 568
/
Copy pathApp.vue
191 lines (174 loc) · 7.05 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<script>
import GlobalSiteSelector from '../components/GlobalSiteSelector.vue';
import Login from '../components/login/Login.vue';
import BaseEntryCreateForm from '../components/entries/BaseCreateForm.vue';
import BaseTermCreateForm from '../components/terms/BaseCreateForm.vue';
import CreateTermButton from '../components/terms/CreateTermButton.vue';
import FieldsetListing from '../components/fieldsets/Listing.vue';
import FieldsetCreateForm from '../components/fieldsets/CreateForm.vue';
import FieldsetEditForm from '../components/fieldsets/EditForm.vue';
import BlueprintListing from '../components/blueprints/Listing.vue';
import BlueprintBuilder from '../components/blueprints/Builder.vue';
import FormCreateForm from '../components/forms/CreateForm.vue';
import FormListing from '../components/forms/Listing.vue';
import FormSubmissionListing from '../components/forms/SubmissionListing.vue';
import GlobalListing from '../components/globals/Listing.vue';
import GlobalEditForm from '../components/globals/EditForm.vue';
import GlobalPublishForm from '../components/globals/PublishForm.vue';
import GlobalCreateForm from '../components/globals/Create.vue';
import UserListing from '../components/users/Listing.vue';
import UserWizard from '../components/users/Wizard.vue';
import RoleListing from '../components/roles/Listing.vue';
import RolePublishForm from '../components/roles/PublishForm.vue';
import UserGroupListing from '../components/user-groups/Listing.vue';
import UserGroupPublishForm from '../components/user-groups/PublishForm.vue';
import CollectionCreateForm from '../components/collections/CreateForm.vue';
import CollectionScaffolder from '../components/collections/Scaffolder.vue';
import CollectionEditForm from '../components/collections/EditForm.vue';
import CollectionView from '../components/collections/View.vue';
import CollectionBlueprintListing from '../components/collections/BlueprintListing.vue';
import SessionExpiry from '../components/SessionExpiry.vue';
import NavigationListing from '../components/navigation/Listing.vue';
import NavigationCreateForm from '../components/navigation/CreateForm.vue';
import NavigationEditForm from '../components/navigation/EditForm.vue';
import PreferencesEditForm from '../components/preferences/EditForm.vue';
import NavigationView from '../components/navigation/View.vue';
import TaxonomyCreateForm from '../components/taxonomies/CreateForm.vue';
import TaxonomyEditForm from '../components/taxonomies/EditForm.vue';
import TaxonomyBlueprintListing from '../components/taxonomies/BlueprintListing.vue';
import AssetContainerCreateForm from '../components/asset-containers/CreateForm.vue';
import AssetContainerEditForm from '../components/asset-containers/EditForm.vue';
import Updater from '../components/updater/Updater.vue';
import PortalTargets from '../components/portals/PortalTargets.vue';
import SitesEditForm from '../components/sites/EditForm.vue';
import CommandPalette from '../components/command-palette/CommandPalette.vue';
import { defineAsyncComponent } from 'vue';
import { ConfigProvider } from 'reka-ui';
export default {
components: {
CommandPalette,
GlobalSiteSelector,
Login,
BaseEntryCreateForm,
BaseTermCreateForm,
CreateTermButton,
FieldsetListing,
FieldsetCreateForm,
FieldsetEditForm,
BlueprintListing,
BlueprintBuilder,
FormCreateForm,
FormListing,
FormSubmissionListing,
GlobalListing,
GlobalEditForm,
GlobalPublishForm,
GlobalCreateForm,
UserListing,
UserWizard,
RoleListing,
RolePublishForm,
UserGroupListing,
UserGroupPublishForm,
CollectionCreateForm,
CollectionScaffolder,
CollectionEditForm,
CollectionView,
CollectionBlueprintListing,
SessionExpiry,
NavigationListing,
NavigationCreateForm,
NavigationEditForm,
PreferencesEditForm,
NavigationView,
TaxonomyCreateForm,
TaxonomyEditForm,
TaxonomyBlueprintListing,
AssetContainerCreateForm,
AssetContainerEditForm,
NavBuilder: defineAsyncComponent(() => import('../components/nav/Builder.vue')),
Updater,
PortalTargets,
SitesEditForm,
ConfigProvider,
},
data() {
return {
navOpen: true,
mobileNavOpen: false,
showBanner: true,
appendedComponents: Statamic.$components.components,
isLicensingBannerSnoozed: localStorage.getItem(`statamic.snooze_license_banner`) > new Date().valueOf(),
copyToClipboardModalUrl: null,
};
},
computed: {
version() {
return Statamic.$config.get('version');
},
stackCount() {
return this.$stacks.count();
},
wrapperClass() {
return this.$config.get('wrapperClass', 'max-w-6xl');
},
},
mounted() {
this.$keys.bind(['command+\\'], (e) => {
e.preventDefault();
this.toggleNav();
});
if (this.$config.get('broadcasting.enabled')) {
this.$echo.start();
}
this.fixAutofocus();
this.showBanner = !this.isLicensingBannerSnoozed && Statamic.$config.get('hasLicenseBanner');
this.$toast.registerInterceptor(this.$axios);
this.$toast.displayInitialToasts();
},
created() {
const app = this;
const state = localStorage.getItem('statamic.nav') || 'open';
this.navOpen = state === 'open';
Statamic.$callbacks.add('copyToClipboard', async function (url) {
try {
await navigator.clipboard.writeText(url);
Statamic.$toast.success(__('Copied to clipboard'));
} catch (err) {
app.copyToClipboardModalUrl = url;
}
});
Statamic.$callbacks.add('bustAndReloadImageCaches', function (urls) {
urls.forEach(async (url) => {
await fetch(url, { cache: 'reload', mode: 'no-cors' });
document.body.querySelectorAll(`img[src='${url}']`).forEach((img) => (img.src = url));
});
});
},
methods: {
toggleNav() {
this.navOpen = !this.navOpen;
localStorage.setItem('statamic.nav', this.navOpen ? 'open' : 'closed');
},
toggleMobileNav() {
this.mobileNavOpen = !this.mobileNavOpen;
},
hideBanner() {
this.showBanner = false;
localStorage.setItem(`statamic.snooze_license_banner`, new Date(Date.now() + 5 * 60 * 1000).valueOf());
},
fixAutofocus() {
// Fix autofocus issues in Safari and Firefox
setTimeout(() => {
const inputs = document.querySelectorAll('input[autofocus]');
for (let input of inputs) {
input.blur();
}
if (inputs.length) {
inputs[0].focus();
}
}, 100);
},
},
};
</script>