-
-
Notifications
You must be signed in to change notification settings - Fork 616
Expand file tree
/
Copy pathstatamic.js
More file actions
214 lines (178 loc) · 6.26 KB
/
statamic.js
File metadata and controls
214 lines (178 loc) · 6.26 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import { createApp, ref, markRaw } from 'vue';
import App from './App.vue';
import { createPinia, defineStore } from 'pinia';
import axios from 'axios';
import Config from '../components/Config';
import Preferences from '../components/Preference';
import registerGlobalComponents from './components.js';
import registerFieldtypes from './fieldtypes.js';
import registerVueSelect from './vue-select/vue-select';
import useGlobalEventBus from '../composables/global-event-bus';
import useProgressBar from '../composables/progress-bar';
import useDirtyState from '../composables/dirty-state';
import VueClickAway from 'vue3-click-away';
import FloatingVue from 'floating-vue';
import 'floating-vue/dist/style.css';
import VCalendar from '@angelblanco/v-calendar';
import '@angelblanco/v-calendar/style.css';
import Toasts from '../components/Toasts';
import PortalVue from 'portal-vue';
import Keys from '../components/keys/Keys';
import FieldActions from '../components/field-actions/FieldActions.js';
import Callbacks from '../components/Callbacks';
import Slugs from '../components/slugs/Manager';
import Portals from '../components/portals/Portals';
import Stacks from '../components/stacks/Stacks';
import Hooks from '../components/Hooks';
import Bard from '../components/Bard';
import Components from '../components/Components';
import FieldConditions from '../components/FieldConditions';
import Reveal from '../components/Reveal';
import Echo from '../components/Echo';
import Permission from '../components/Permission';
import autosize from 'autosize';
const darkMode = ref(null);
let bootingCallbacks = [];
let bootedCallbacks = [];
let components;
export default {
booting(callback) {
bootingCallbacks.push(callback);
},
booted(callback) {
bootedCallbacks.push(callback);
},
get $config() {
return this.$app.config.globalProperties.$config;
},
get $preferences() {
return this.$app.config.globalProperties.$preferences;
},
get $callbacks() {
return this.$app.config.globalProperties.$callbacks;
},
get $hooks() {
return this.$app.config.globalProperties.$hooks;
},
get $toast() {
return this.$app.config.globalProperties.$toast;
},
get $conditions() {
return this.$app.config.globalProperties.$conditions;
},
get $slug() {
return this.$app.config.globalProperties.$slug;
},
get $bard() {
return this.$app.config.globalProperties.$bard;
},
get $echo() {
return this.$app.config.globalProperties.$echo;
},
get $pinia() {
return { defineStore };
},
get $permissions() {
return this.$app.config.globalProperties.$permissions;
},
get $components() {
return components;
},
get darkMode() {
return darkMode;
},
set darkMode(value) {
darkMode.value = value;
},
get user() {
return this.$config.get('user');
},
config(config) {
this.initialConfig = config;
},
component(name, component) {
this.$components.register(name, component);
},
start() {
this.$app = createApp(App);
this.$app.config.silent = false;
this.$app.config.devtools = true;
this.$app.use(createPinia());
this.$app.use(PortalVue, { portalName: 'v-portal' });
this.$app.use(VueClickAway);
this.$app.use(FloatingVue, { disposeTimeout: 30000, distance: 10 });
this.$app.use(VCalendar);
const portals = markRaw(new Portals());
components = new Components(this.$app);
Object.assign(this.$app.config.globalProperties, {
$config: new Config(this.initialConfig),
});
Object.assign(this.$app.config.globalProperties, {
$axios: axios,
$moment: window.moment,
$events: useGlobalEventBus(),
$preferences: new Preferences(),
$progress: useProgressBar(),
$keys: new Keys(),
$fieldActions: new FieldActions(),
$conditions: new FieldConditions(),
$callbacks: new Callbacks(),
$dirty: useDirtyState(),
$slug: new Slugs(),
$portals: portals,
$stacks: new Stacks(portals),
$hooks: new Hooks(),
$toast: new Toasts(this.$app),
$bard: new Bard(),
$reveal: new Reveal(),
$echo: new Echo(),
$permissions: new Permission(),
});
Object.assign(this.$app.config.globalProperties, {
__(key, replacements) {
return __(key, replacements);
},
__n(key, number, replacements) {
return __n(key, number, replacements);
},
$markdown(value) {
return markdown(value);
},
cp_url(url) {
return cp_url(url);
},
docs_url(url) {
return docs_url(url);
},
can(permission) {
const permissions = JSON.parse(atob(Statamic.$config.get('permissions')));
return permissions.includes('super') || permissions.includes(permission);
},
$wait(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
},
});
this.$app.directive('elastic', {
mounted: (el) => autosize(el),
});
registerGlobalComponents(this.$app);
registerFieldtypes(this.$app);
registerVueSelect(this.$app);
// Suppress the translation warnings
this.$app.config.warnHandler = (msg, vm, trace) => {
if (msg.includes('Property "__" should not start with _ which is a reserved prefix for Vue internals')) {
return;
}
console.warn(msg, vm, trace);
};
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
axios.defaults.headers.common['X-CSRF-TOKEN'] = Statamic.$config.get('csrfToken');
bootingCallbacks.forEach((callback) => callback(this));
bootingCallbacks = [];
this.$app.mount('#statamic');
bootedCallbacks.forEach((callback) => callback(this));
bootedCallbacks = [];
},
};