-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathPrimeVue.js
256 lines (233 loc) · 8.39 KB
/
PrimeVue.js
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import { Theme, ThemeService } from '@primeuix/styled';
import { FilterMatchMode } from '@primevue/core/api';
import BaseStyle from '@primevue/core/base/style';
import PrimeVueService from '@primevue/core/service';
import { inject, reactive, ref, watch } from 'vue';
export const defaultOptions = {
ripple: false,
inputStyle: null,
inputVariant: null,
locale: {
startsWith: 'Starts with',
contains: 'Contains',
notContains: 'Not contains',
endsWith: 'Ends with',
equals: 'Equals',
notEquals: 'Not equals',
noFilter: 'No Filter',
lt: 'Less than',
lte: 'Less than or equal to',
gt: 'Greater than',
gte: 'Greater than or equal to',
dateIs: 'Date is',
dateIsNot: 'Date is not',
dateBefore: 'Date is before',
dateAfter: 'Date is after',
clear: 'Clear',
apply: 'Apply',
matchAll: 'Match All',
matchAny: 'Match Any',
addRule: 'Add Rule',
removeRule: 'Remove Rule',
accept: 'Yes',
reject: 'No',
choose: 'Choose',
upload: 'Upload',
cancel: 'Cancel',
completed: 'Completed',
pending: 'Pending',
fileSizeTypes: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
chooseYear: 'Choose Year',
chooseMonth: 'Choose Month',
chooseDate: 'Choose Date',
prevDecade: 'Previous Decade',
nextDecade: 'Next Decade',
prevYear: 'Previous Year',
nextYear: 'Next Year',
prevMonth: 'Previous Month',
nextMonth: 'Next Month',
prevHour: 'Previous Hour',
nextHour: 'Next Hour',
prevMinute: 'Previous Minute',
nextMinute: 'Next Minute',
prevSecond: 'Previous Second',
nextSecond: 'Next Second',
am: 'am',
pm: 'pm',
today: 'Today',
weekHeader: 'Wk',
firstDayOfWeek: 0,
showMonthAfterYear: false,
dateFormat: 'mm/dd/yy',
weak: 'Weak',
medium: 'Medium',
strong: 'Strong',
passwordPrompt: 'Enter a password',
emptyFilterMessage: 'No results found',
searchMessage: '{0} results are available',
selectionMessage: '{0} items selected',
emptySelectionMessage: 'No selected item',
emptySearchMessage: 'No results found',
fileChosenMessage: '{0} files',
noFileChosenMessage: 'No file chosen',
emptyMessage: 'No available options',
aria: {
trueLabel: 'True',
falseLabel: 'False',
nullLabel: 'Not Selected',
star: '1 star',
stars: '{star} stars',
selectAll: 'All items selected',
unselectAll: 'All items unselected',
close: 'Close',
previous: 'Previous',
next: 'Next',
navigation: 'Navigation',
scrollTop: 'Scroll Top',
moveTop: 'Move Top',
moveUp: 'Move Up',
moveDown: 'Move Down',
moveBottom: 'Move Bottom',
moveToTarget: 'Move to Target',
moveToSource: 'Move to Source',
moveAllToTarget: 'Move All to Target',
moveAllToSource: 'Move All to Source',
pageLabel: 'Page {page}',
firstPageLabel: 'First Page',
lastPageLabel: 'Last Page',
nextPageLabel: 'Next Page',
prevPageLabel: 'Previous Page',
rowsPerPageLabel: 'Rows per page',
jumpToPageDropdownLabel: 'Jump to Page Dropdown',
jumpToPageInputLabel: 'Jump to Page Input',
selectRow: 'Row Selected',
unselectRow: 'Row Unselected',
expandRow: 'Row Expanded',
collapseRow: 'Row Collapsed',
showFilterMenu: 'Show Filter Menu',
hideFilterMenu: 'Hide Filter Menu',
filterOperator: 'Filter Operator',
filterConstraint: 'Filter Constraint',
editRow: 'Row Edit',
saveEdit: 'Save Edit',
cancelEdit: 'Cancel Edit',
listView: 'List View',
gridView: 'Grid View',
slide: 'Slide',
slideNumber: '{slideNumber}',
zoomImage: 'Zoom Image',
zoomIn: 'Zoom In',
zoomOut: 'Zoom Out',
rotateRight: 'Rotate Right',
rotateLeft: 'Rotate Left',
listLabel: 'Option List'
}
},
filterMatchModeOptions: {
text: [FilterMatchMode.STARTS_WITH, FilterMatchMode.CONTAINS, FilterMatchMode.NOT_CONTAINS, FilterMatchMode.ENDS_WITH, FilterMatchMode.EQUALS, FilterMatchMode.NOT_EQUALS],
numeric: [FilterMatchMode.EQUALS, FilterMatchMode.NOT_EQUALS, FilterMatchMode.LESS_THAN, FilterMatchMode.LESS_THAN_OR_EQUAL_TO, FilterMatchMode.GREATER_THAN, FilterMatchMode.GREATER_THAN_OR_EQUAL_TO],
date: [FilterMatchMode.DATE_IS, FilterMatchMode.DATE_IS_NOT, FilterMatchMode.DATE_BEFORE, FilterMatchMode.DATE_AFTER]
},
zIndex: {
modal: 1100,
overlay: 1000,
menu: 1000,
tooltip: 1100
},
theme: undefined,
unstyled: false,
pt: undefined,
ptOptions: {
mergeSections: true,
mergeProps: false
},
csp: {
nonce: undefined
}
};
const PrimeVueSymbol = Symbol();
export function usePrimeVue() {
const PrimeVue = inject(PrimeVueSymbol);
if (!PrimeVue) {
throw new Error('PrimeVue is not installed!');
}
return PrimeVue;
}
export function setup(app, options) {
const PrimeVue = {
config: reactive(options)
};
app.config.globalProperties.$primevue = PrimeVue;
app.provide(PrimeVueSymbol, PrimeVue);
setupConfig(app, PrimeVue);
return PrimeVue;
}
export function setupConfig(app, PrimeVue) {
const isThemeChanged = ref(false);
/*** Methods and Services ***/
const loadCommonTheme = () => {
// common
if (!Theme.isStyleNameLoaded('common')) {
const { primitive, semantic } = BaseStyle.getCommonTheme?.() || {};
const styleOptions = { nonce: PrimeVue.config?.csp?.nonce };
BaseStyle.load(primitive?.css, { name: 'primitive-variables', ...styleOptions });
BaseStyle.load(semantic?.css, { name: 'semantic-variables', ...styleOptions });
BaseStyle.loadTheme({ name: 'global-style', ...styleOptions });
Theme.setLoadedStyleName('common');
}
};
ThemeService.on('theme:change', function (newTheme) {
isThemeChanged.value = true;
app.config.globalProperties.$primevue.config.theme = newTheme;
});
/*** Watchers ***/
watch(
PrimeVue.config,
(newValue, oldValue) => {
PrimeVueService.emit('config:change', { newValue, oldValue });
},
{ immediate: true, deep: true }
);
watch(
() => PrimeVue.config.ripple,
(newValue, oldValue) => {
PrimeVueService.emit('config:ripple:change', { newValue, oldValue });
},
{ immediate: true, deep: true }
);
watch(
() => PrimeVue.config.theme,
(newValue, oldValue) => {
if (!isThemeChanged.value) {
Theme.setTheme(newValue);
}
if (!PrimeVue.config.unstyled) {
loadCommonTheme();
}
isThemeChanged.value = false;
PrimeVueService.emit('config:theme:change', { newValue, oldValue });
},
{ immediate: true, deep: true }
);
watch(
() => PrimeVue.config.unstyled,
(newValue, oldValue) => {
if (!newValue && PrimeVue.config.theme) {
loadCommonTheme();
}
PrimeVueService.emit('config:unstyled:change', { newValue, oldValue });
},
{ immediate: true, deep: true }
);
}
export default {
install: (app, options) => {
const configOptions = { ...defaultOptions, ...options };
setup(app, configOptions);
}
};