-
Notifications
You must be signed in to change notification settings - Fork 699
Expand file tree
/
Copy pathdefaults.js
More file actions
444 lines (425 loc) · 13.9 KB
/
defaults.js
File metadata and controls
444 lines (425 loc) · 13.9 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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import { resolvers } from './resolvers.js'
import { editors } from './editors/index.js'
/* default theme */
const theme = 'html'
/* default template engine */
const template = 'default'
/* Global callback list */
const callbacks = {}
const themes = {}
const templates = {}
const iconlibs = {}
const languages = {}
// eslint-disable-next-line camelcase
const custom_validators = []
/* Translation strings and default languages */
// eslint-disable-next-line camelcase
const default_language = 'en'
// eslint-disable-next-line camelcase
const language = default_language
languages.en = {
/**
* When a property is not set
*/
error_notset: 'Property must be set',
/**
* When a string must not be empty
*/
error_notempty: 'Value required',
/**
* When a value is not one of the enumerated values
*/
error_enum: 'Value must be one of the enumerated values',
/**
* When a value is not equal to the constant
*/
error_const: 'Value must be the constant value',
/**
* When a value doesn't validate any schema of a 'anyOf' combination
*/
error_anyOf: 'Value must validate against at least one of the provided schemas',
/**
* When a value doesn't validate
* @variables This key takes one variable: The number of schemas the value does not validate
*/
error_oneOf: 'Value must validate against exactly one of the provided schemas. It currently validates against {{0}} of the schemas.',
/**
* When a value does not validate a 'not' schema
*/
error_not: 'Value must not validate against the provided schema',
/**
* When a value does not match any of the provided types
*/
error_type_union: 'Value must be one of the provided types',
/**
* When a value does not match the given type
* @variables This key takes one variable: The type the value should be of
*/
error_type: 'Value must be of type {{0}}',
/**
* When the value validates one of the disallowed types
*/
error_disallow_union: 'Value must not be one of the provided disallowed types',
/**
* When the value validates a disallowed type
* @variables This key takes one variable: The type the value should not be of
*/
error_disallow: 'Value must not be of type {{0}}',
/**
* When a value is not a multiple of or divisible by a given number
* @variables This key takes one variable: The number mentioned above
*/
error_multipleOf: 'Value must be a multiple of {{0}}',
/**
* When a value is greater than it's supposed to be (exclusive)
* @variables This key takes one variable: The maximum
*/
error_maximum_excl: 'Value must be less than {{0}}',
/**
* When a value is greater than it's supposed to be (inclusive
* @variables This key takes one variable: The maximum
*/
error_maximum_incl: 'Value must be at most {{0}}',
/**
* When a value is lesser than it's supposed to be (exclusive)
* @variables This key takes one variable: The minimum
*/
error_minimum_excl: 'Value must be greater than {{0}}',
/**
* When a value is lesser than it's supposed to be (inclusive)
* @variables This key takes one variable: The minimum
*/
error_minimum_incl: 'Value must be at least {{0}}',
/**
* When a value have too many characters
* @variables This key takes one variable: The maximum character count
*/
error_maxLength: 'Value must be at most {{0}} characters long',
/**
* When no array items validates the contains schema
*/
error_contains: 'No items match contains',
/**
* When an array have too few items that validate agaist contains schema
* @variables This key takes two variable: The valid items count and the minContains value
*/
error_minContains: 'Contains match count {{0}} is less than minimum contains count of {{1}}',
/**
* When an array have too many items that validate agaist contains schema
* @variables This key takes two variable: The valid items count and the maxContains value
*/
error_maxContains: 'Contains match count {{0}} exceeds maximum contains count of {{1}}',
/**
* When a value does not have enough characters
* @variables This key takes one variable: The minimum character count
*/
error_minLength: 'Value must be at least {{0}} characters long',
/**
* When a value does not match a given pattern
*/
error_pattern: 'Value must match the pattern {{0}}',
/**
* When an array has additional items whereas it is not supposed to
*/
error_additionalItems: 'No additional items allowed in this array',
/**
* When there are to many items in an array
* @variables This key takes one variable: The maximum item count
*/
error_maxItems: 'Value must have at most {{0}} items',
/**
* When there are not enough items in an array
* @variables This key takes one variable: The minimum item count
*/
error_minItems: 'Value must have at least {{0}} items',
/**
* When an array is supposed to have unique items but has duplicates
*/
error_uniqueItems: 'Array must have unique items',
/**
* When there are too many properties in an object
* @variables This key takes one variable: The maximum property count
*/
error_maxProperties: 'Object must have at most {{0}} properties',
/**
* When there are not enough properties in an object
* @variables This key takes one variable: The minimum property count
*/
error_minProperties: 'Object must have at least {{0}} properties',
/**
* When a required property is not defined
* @variables This key takes one variable: The name of the missing property
*/
error_required: "Object is missing the required property '{{0}}'",
/**
* When there is an additional property is set whereas there should be none
* @variables This key takes one variable: The name of the additional property
*/
error_additional_properties: 'No additional properties allowed, but property {{0}} is set',
/**
* When there is a propertyName that sets a max length and a property name exceeds the max length
* @variables This key takes one variable: The name of the invalid property
*/
error_property_names_exceeds_maxlength: 'Property name {{0}} exceeds maxLength',
/**
* When there is a propertyName that sets an enum and a property name matches none of the possible enum
* @variables This key takes one variable: The name of the invalid property
*/
error_property_names_enum_mismatch: 'Property name {{0}} does not match any enum values',
/**
* When there is a propertyName that sets a const and a property does not match the const value
* @variables This key takes one variable: The name of the invalid property
*/
error_property_names_const_mismatch: 'Property name {{0}} does not match the const value',
/**
* When there is a propertyName that sets a pattern and a property name does not match the pattern
* @variables This key takes one variable: The name of the invalid property
*/
error_property_names_pattern_mismatch: 'Property name {{0}} does not match pattern',
/**
* When the propertyName is set to false and there is at least one property
* @variables This key takes one variable: The name of the invalid property
*/
error_property_names_false: 'Property name {{0}} fails when propertyName is false',
/**
* When the propertyName specifies a maxLength that is not a number
* @variables This key takes one variable: The name of the current property
*/
error_property_names_maxlength: 'Property name {{0}} cannot match invalid maxLength',
/**
* When the propertyName specifies an enum that is not an array
* @variables This key takes one variable: The name of the current property
*/
error_property_names_enum: 'Property name {{0}} cannot match invalid enum',
/**
* When the propertyName specifies a pattern that is not a string
* @variables This key takes one variable: The name of the current property
*/
error_property_names_pattern: 'Property name {{0}} cannot match invalid pattern',
/**
* When the propertyName is unsupported
* @variables This key takes one variable: The name of the invalid propertyName
*/
error_property_names_unsupported: 'Unsupported propertyName {{0}}',
/**
* When a dependency is not resolved
* @variables This key takes one variable: The name of the missing property for the dependency
*/
error_dependency: 'Must have property {{0}}',
/**
* When a date is in incorrect format
* @variables This key takes one variable: The valid format
*/
error_date: 'Date must be in the format {{0}}',
/**
* When a time is in incorrect format
* @variables This key takes one variable: The valid format
*/
error_time: 'Time must be in the format {{0}}',
/**
* When a datetime-local is in incorrect format
* @variables This key takes one variable: The valid format
*/
error_datetime_local: 'Datetime must be in the format {{0}}',
/**
* When a integer date is less than 1 January 1970
*/
error_invalid_epoch: 'Date must be greater than 1 January 1970',
/**
* When an IPv4 is in incorrect format
*/
error_ipv4: 'Value must be a valid IPv4 address in the form of 4 numbers between 0 and 255, separated by dots',
/**
* When an IPv6 is in incorrect format
*/
error_ipv6: 'Value must be a valid IPv6 address',
/**
* When a hostname is in incorrect format
*/
error_hostname: 'The hostname has the wrong format',
/**
* When uploads max size limit is exceeded
*/
upload_max_size: 'Filesize too large. Max size is ',
/**
* When the mime type does not match the type of the file
*/
upload_wrong_file_format: 'Wrong file format. Allowed format(s): ',
/**
* Text/Title on Save button
*/
button_save: 'Save',
/**
* Text/Title on Copy button
*/
button_copy: 'Copy',
/**
* Text/Title on Cancel button
*/
button_cancel: 'Cancel',
/**
* Text/Title on Add button
*/
button_add: 'Add',
/**
* Text on Delete All buttons
*/
button_delete_all: 'All',
/**
* Title on Delete All buttons
*/
button_delete_all_title: 'Delete All',
/**
* Text on Delete Last buttons
* @variable This key takes one variable: The title of object to delete
*/
button_delete_last: 'Last {{0}}',
/**
* Title on Delete Last buttons
* @variable This key takes one variable: The title of object to delete
*/
button_delete_last_title: 'Delete Last {{0}}',
/**
* Title on Add Row buttons
* @variable This key takes one variable: The title of object to add
*/
button_add_row_title: 'Add {{0}}',
/**
* Title on Move Down buttons
*/
button_move_down_title: 'Move down',
/**
* Title on Move Up buttons
*/
button_move_up_title: 'Move up',
/**
* Text on Object Properties buttons
*/
button_properties: 'Properties',
/**
* Title on Object Properties buttons
*/
button_object_properties: 'Object Properties',
/**
* Title on Copy Row button
* @variable This key takes one variable: The title of object to delete
*/
button_copy_row_title: 'Copy {{0}}',
/**
* Title on Delete Row buttons
* @variable This key takes one variable: The title of object to delete
*/
button_delete_row_title: 'Delete {{0}}',
/**
* Title on Delete Row buttons, short version (no parameter with the object title)
*/
button_delete_row_title_short: 'Delete',
/**
* Title on Copy Row buttons, short version (no parameter with the object title)
*/
button_copy_row_title_short: 'Copy',
/**
* Title on Collapse buttons
*/
button_collapse: 'Collapse',
/**
* Title on Expand buttons
*/
button_expand: 'Expand',
/**
* Title on Edit JSON buttons
*/
button_edit_json: 'Edit JSON',
/**
* Text/Title on Upload buttons
*/
button_upload: 'Upload',
/**
* Title on Flatpickr toggle buttons
*/
flatpickr_toggle_button: 'Toggle',
/**
* Title on Flatpickr clear buttons
*/
flatpickr_clear_button: 'Clear',
/**
* Choices input field placeholder text
*/
choices_placeholder_text: 'Start typing to add value',
/**
* Default title for array items
*/
default_array_item_title: 'item',
/**
* Warning when deleting a node
*/
button_delete_node_warning: 'Are you sure you want to remove this item?',
/**
* Warning when deleting a node
*/
table_controls: 'Controls',
/**
* Warning when paste and length exceeded maxLength
*/
paste_max_length_reached: 'Pasted text exceeded maximum length of {{0}} and will be clipped.'
}
/* Default per-editor options */
Object.entries(editors).forEach(([i, editor]) => { editors[i].options = editor.options || {} })
/* Default upload handler */
function upload (type, file, cbs) {
// eslint-disable-next-line no-console
console.log('Upload handler required for upload editor')
}
/* String translate function */
function translate (key, variables, schema) {
let schemaMessages = {}
if (schema && schema.options && schema.options.error_messages && schema.options.error_messages[defaults.language]) {
schemaMessages = schema.options.error_messages[defaults.language]
}
const lang = defaults.languages[defaults.language]
if (!lang) throw new Error(`Unknown language ${defaults.language}`)
let string = schemaMessages[key] || lang[key] || defaults.languages[default_language][key] || key
if (variables) {
for (let i = 0; i < variables.length; i++) {
string = string.replace(new RegExp(`\\{\\{${i}}}`, 'g'), variables[i])
}
}
return string
}
/* Text element translate function */
function translateProperty (text, variables) {
return text
}
/* Default options when initializing JSON Editor */
const options = {
upload,
use_name_attributes: true,
prompt_before_delete: true,
use_default_values: true,
max_depth: 0,
button_state_mode: 1,
case_sensitive_property_search: true,
show_errors: 'interaction',
prompt_paste_max_length_reached: false,
remove_false_properties: false,
enforce_const: false,
opt_in_widget: 'checkbox'
}
/* This assignment was previously in index.js but makes more sense here */
export const defaults = {
options,
theme,
template,
themes,
callbacks,
templates,
iconlibs,
editors,
languages,
resolvers,
custom_validators,
default_language,
language,
translate,
translateProperty
}