@json-editor/json-editor 2.14.1 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +4 -0
- package/.eslintrc +4 -1
- package/.github/workflows/build.yml +5 -4
- package/CHANGELOG.md +21 -0
- package/README.md +32 -1
- package/config/webpack.common.js +2 -6
- package/dist/jsoneditor.js +1 -1
- package/dist/jsoneditor.js.LICENSE.txt +1 -1
- package/dist/nonmin/jsoneditor.js +4121 -3939
- package/dist/nonmin/jsoneditor.js.map +1 -1
- package/docs/meta-schema.html +793 -0
- package/package.json +13 -13
- package/src/core.js +5 -1
- package/src/defaults.js +9 -2
- package/src/editor.js +33 -14
- package/src/editors/array.js +3 -6
- package/src/editors/base64.js +3 -0
- package/src/editors/describedby.js +2 -2
- package/src/editors/enum.js +9 -1
- package/src/editors/info.js +8 -0
- package/src/editors/multiple.js +9 -2
- package/src/editors/object.js +26 -7
- package/src/editors/radio.js +5 -2
- package/src/editors/select.js +19 -8
- package/src/editors/select2.js +1 -1
- package/src/editors/starrating.js +5 -4
- package/src/editors/string.js +16 -2
- package/src/editors/table.js +2 -2
- package/src/iconlib.js +0 -1
- package/src/schemaloader.js +2 -2
- package/src/style.css +4 -0
- package/src/style.css.js +1 -1
- package/src/templates/default.js +2 -2
- package/src/theme.js +13 -3
- package/src/themes/index.js +0 -1
- package/src/validator.js +4 -4
- package/tests/Dockerfile +1 -1
- package/tests/codeceptjs/core_test.js +8 -2
- package/tests/codeceptjs/editors/array_test.js +11 -6
- package/tests/codeceptjs/editors/autocomplete_test.js +0 -1
- package/tests/codeceptjs/editors/integer_test.js +0 -4
- package/tests/codeceptjs/editors/object_test.js +8 -0
- package/tests/codeceptjs/editors/rating_test.js +1 -1
- package/tests/codeceptjs/editors/select_test.js +18 -0
- package/tests/codeceptjs/editors/starrating_test.js +15 -0
- package/tests/codeceptjs/editors/string_test.js +7 -0
- package/tests/codeceptjs/issues/issue-gh-1158_test.js +1 -1
- package/tests/codeceptjs/issues/issue-gh-1164_test.js +0 -1
- package/tests/codeceptjs/issues/issue-gh-1383_test.js +1 -1
- package/tests/codeceptjs/issues/issue-gh-1452_test.js +10 -0
- package/tests/codeceptjs/issues/issue-gh-1525_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1536_test.js +12 -0
- package/tests/codeceptjs/issues/issue-gh-1538_test.js +10 -0
- package/tests/codeceptjs/issues/issue-gh-1541_test.js +8 -0
- package/tests/docker-compose-local.yml +1 -2
- package/tests/docker-compose.yml +0 -1
- package/tests/pages/array-events-table.html +39 -31
- package/tests/pages/array-events.html +39 -31
- package/tests/pages/assets/autocomplete.css +1 -0
- package/tests/pages/assets/autocomplete.min.js +1 -0
- package/tests/pages/autocomplete.html +4 -4
- package/tests/pages/enforce-const.html +176 -0
- package/tests/pages/issues/issue-gh-1452.html +98 -0
- package/tests/pages/issues/issue-gh-1525.html +62 -0
- package/tests/pages/issues/issue-gh-1536.html +55 -0
- package/tests/pages/issues/issue-gh-1538.html +56 -0
- package/tests/pages/issues/issue-gh-1541.html +51 -0
- package/tests/pages/issues/issue-gh-1541.json +9 -0
- package/tests/pages/placeholder-options.html +57 -0
- package/tests/pages/prompt-paste-max-length-reached.html +51 -0
- package/tests/pages/remove-false-properties.html +85 -0
- package/tests/pages/starrating.html +86 -0
- package/tests/unit/editor.spec.js +1 -1
package/src/theme.js
CHANGED
|
@@ -202,9 +202,9 @@ export class AbstractTheme {
|
|
|
202
202
|
return el
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
getSelectInput (options, multiple) {
|
|
205
|
+
getSelectInput (options, multiple, hasPlaceholderOption = false) {
|
|
206
206
|
const select = document.createElement('select')
|
|
207
|
-
if (options) this.setSelectOptions(select, options)
|
|
207
|
+
if (options) this.setSelectOptions(select, options, [], hasPlaceholderOption)
|
|
208
208
|
return select
|
|
209
209
|
}
|
|
210
210
|
|
|
@@ -222,8 +222,18 @@ export class AbstractTheme {
|
|
|
222
222
|
this.setSelectOptions(switcher, options, titles)
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
setSelectOptions (select, options, titles = []) {
|
|
225
|
+
setSelectOptions (select, options, titles = [], hasPlaceholderOption = false, placeholderOptionText = ' ') {
|
|
226
226
|
select.innerHTML = ''
|
|
227
|
+
|
|
228
|
+
if (hasPlaceholderOption) {
|
|
229
|
+
const option = document.createElement('option')
|
|
230
|
+
option.setAttribute('value', '_placeholder_')
|
|
231
|
+
option.textContent = placeholderOptionText
|
|
232
|
+
option.setAttribute('disabled', '')
|
|
233
|
+
option.setAttribute('hidden', '')
|
|
234
|
+
select.appendChild(option)
|
|
235
|
+
}
|
|
236
|
+
|
|
227
237
|
for (let i = 0; i < options.length; i++) {
|
|
228
238
|
const option = document.createElement('option')
|
|
229
239
|
option.setAttribute('value', options[i])
|
package/src/themes/index.js
CHANGED
package/src/validator.js
CHANGED
|
@@ -32,7 +32,7 @@ export class Validator {
|
|
|
32
32
|
if (invalid) {
|
|
33
33
|
errors.push({
|
|
34
34
|
message: 'Must have the required properties: ' + missingProperties.join(', '),
|
|
35
|
-
path
|
|
35
|
+
path
|
|
36
36
|
})
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -72,14 +72,14 @@ export class Validator {
|
|
|
72
72
|
if (minContainsInvalid) {
|
|
73
73
|
errors.push({
|
|
74
74
|
message: this.translate('error_minContains', [counter, schema.minContains], schema),
|
|
75
|
-
path
|
|
75
|
+
path
|
|
76
76
|
})
|
|
77
77
|
}
|
|
78
78
|
} else {
|
|
79
79
|
if (containsInvalid) {
|
|
80
80
|
errors.push({
|
|
81
81
|
message: this.translate('error_contains', null, schema),
|
|
82
|
-
path
|
|
82
|
+
path
|
|
83
83
|
})
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -90,7 +90,7 @@ export class Validator {
|
|
|
90
90
|
if (maxContainsInvalid) {
|
|
91
91
|
errors.push({
|
|
92
92
|
message: this.translate('error_maxContains', [counter, schema.maxContains], schema),
|
|
93
|
-
path
|
|
93
|
+
path
|
|
94
94
|
})
|
|
95
95
|
}
|
|
96
96
|
}
|
package/tests/Dockerfile
CHANGED
|
@@ -5,6 +5,12 @@ const { DEFAULT_WAIT_TIME } = require('./test-config')
|
|
|
5
5
|
|
|
6
6
|
Feature('core')
|
|
7
7
|
|
|
8
|
+
Scenario('should enforce const @enforce_const', async ({ I }) => {
|
|
9
|
+
I.amOnPage('enforce-const.html')
|
|
10
|
+
I.waitForElement('.je-ready')
|
|
11
|
+
I.waitForValue('#value', '{"string":"Alice","integer":5,"number":5.5,"string-enum":"Bob","boolean":true,"boolean-checkbox":true,"boolean-choices":true,"object":{"name":"Alice"},"array":[{"name":"Alice"},{"name":"Bob"}],"array-table":[{"name":"Alice"},{"name":"Bob"}],"array-tabs":[{"name":"Alice"},{"name":"Bob"}],"array-of-strings":["Alice","Bob"],"array-enum":["Carl","Dennis"],"object-enum":{"name":"Bob"}}')
|
|
12
|
+
})
|
|
13
|
+
|
|
8
14
|
Scenario('should hide titles @titleHidden', async ({ I }) => {
|
|
9
15
|
I.amOnPage('title-hidden.html')
|
|
10
16
|
I.waitForElement('.je-ready')
|
|
@@ -155,7 +161,7 @@ Scenario('should watch form for changes @core @change', async ({ I }) => {
|
|
|
155
161
|
|
|
156
162
|
Scenario('should change the form if form_name_root option is set @core', async ({ I }) => {
|
|
157
163
|
I.amOnPage('form-name.html')
|
|
158
|
-
I.see('
|
|
164
|
+
I.see('Value must be one of the enumerated values', '.invalid-feedback')
|
|
159
165
|
I.seeElement('[data-schemapath="form_1"]')
|
|
160
166
|
I.seeElement('[data-schemapath="form_2"]')
|
|
161
167
|
I.seeElement('[name="form_1"]')
|
|
@@ -174,7 +180,7 @@ Scenario('should change the form if form_name_root option is set @core', async (
|
|
|
174
180
|
I.seeElement('[for="form_2[2]"]')
|
|
175
181
|
I.click('[for="form_1[0]"]')
|
|
176
182
|
I.click('[for="form_2[1]"]')
|
|
177
|
-
I.dontSee('
|
|
183
|
+
I.dontSee('Value must be one of the enumerated values', '.invalid-feedback')
|
|
178
184
|
I.click('#get-value-form-1')
|
|
179
185
|
I.waitForValue('#value-form-1', '"yes"')
|
|
180
186
|
I.click('#get-value-form-2')
|
|
@@ -177,33 +177,38 @@ Scenario('should array editor events @array-events', async ({ I }) => {
|
|
|
177
177
|
I.waitForValue('.debug', '["A","B"]')
|
|
178
178
|
|
|
179
179
|
I.click('.json-editor-btn-moveup')
|
|
180
|
-
I.waitForValue('
|
|
180
|
+
I.waitForValue('#action1', 'moveRow')
|
|
181
181
|
I.click('.get-value')
|
|
182
182
|
I.waitForValue('.debug', '["B","A"]')
|
|
183
183
|
|
|
184
184
|
I.click('.json-editor-btn-movedown')
|
|
185
|
-
I.waitForValue('
|
|
185
|
+
I.waitForValue('#action1', 'moveRow')
|
|
186
186
|
I.click('.get-value')
|
|
187
187
|
I.waitForValue('.debug', '["A","B"]')
|
|
188
188
|
|
|
189
189
|
I.click('.json-editor-btntype-add')
|
|
190
|
-
I.waitForValue('
|
|
190
|
+
I.waitForValue('#action1', 'addRow')
|
|
191
191
|
I.click('.get-value')
|
|
192
192
|
I.waitForValue('.debug', '["A","B",""]')
|
|
193
193
|
|
|
194
|
+
I.click('.json-editor-btntype-copy')
|
|
195
|
+
I.waitForValue('#action2', 'copyRow')
|
|
196
|
+
I.click('.get-value')
|
|
197
|
+
I.waitForValue('.debug', '["A","B","","A"]')
|
|
198
|
+
|
|
194
199
|
I.amAcceptingPopups()
|
|
195
200
|
I.click('.json-editor-btntype-deletelast')
|
|
196
201
|
I.seeInPopup('Are you sure you want to remove this item?')
|
|
197
202
|
I.acceptPopup()
|
|
198
|
-
I.waitForValue('
|
|
203
|
+
I.waitForValue('#action1', 'deleteRow')
|
|
199
204
|
I.click('.get-value')
|
|
200
|
-
I.waitForValue('.debug', '["A","B"]')
|
|
205
|
+
I.waitForValue('.debug', '["A","B",""]')
|
|
201
206
|
|
|
202
207
|
I.amAcceptingPopups()
|
|
203
208
|
I.click('.json-editor-btntype-deleteall')
|
|
204
209
|
I.seeInPopup('Are you sure you want to remove this item?')
|
|
205
210
|
I.acceptPopup()
|
|
206
|
-
I.waitForValue('
|
|
211
|
+
I.waitForValue('#action1', 'deleteAllRows')
|
|
207
212
|
I.click('.get-value')
|
|
208
213
|
I.waitForValue('.debug', '[]')
|
|
209
214
|
})
|
|
@@ -11,6 +11,5 @@ Scenario('autocomplete should work @autocomplete', async ({ I }) => {
|
|
|
11
11
|
I.waitForText('iran', 20, '.autocomplete-result-list')
|
|
12
12
|
I.waitForText('iraq', 20, '.autocomplete-result-list')
|
|
13
13
|
I.click('iraq', '.autocomplete-result:nth-child(2)')
|
|
14
|
-
I.wait(1)
|
|
15
14
|
I.waitForValue('.value', '"iraq"')
|
|
16
15
|
})
|
|
@@ -71,13 +71,9 @@ Scenario('should be readonly if specified and not disabled @readOnly', async ({
|
|
|
71
71
|
|
|
72
72
|
Scenario('should update output when (method) setValue is called', async ({ I }) => {
|
|
73
73
|
I.amOnPage('integer.html')
|
|
74
|
-
I.saveScreenshot('integer-setvalue-1.png')
|
|
75
74
|
I.waitForText('5', DEFAULT_WAIT_TIME, '[data-schemapath="root.integer_range"] output')
|
|
76
|
-
I.saveScreenshot('integer-setvalue-2.png')
|
|
77
75
|
I.click('.set-value')
|
|
78
|
-
I.saveScreenshot('integer-setvalue-3.png')
|
|
79
76
|
I.waitForText('2', DEFAULT_WAIT_TIME, '[data-schemapath="root.integer_range"] output')
|
|
80
|
-
I.saveScreenshot('integer-setvalue-4.png')
|
|
81
77
|
})
|
|
82
78
|
|
|
83
79
|
Scenario('should validate value', async ({ I }) => {
|
|
@@ -327,3 +327,11 @@ Scenario('should open and close the properties modal', ({ I }) => {
|
|
|
327
327
|
I.click('textarea')
|
|
328
328
|
I.dontSeeElement('.je-modal .property-selector')
|
|
329
329
|
})
|
|
330
|
+
|
|
331
|
+
Scenario('should remove false properties @remove_false_properties', ({ I }) => {
|
|
332
|
+
I.amOnPage('remove-false-properties.html')
|
|
333
|
+
I.waitForElement('.je-ready')
|
|
334
|
+
I.waitForValue('#value', '{}')
|
|
335
|
+
I.click('[for="root[a]"]')
|
|
336
|
+
I.waitForValue('#value', '{"a":true}')
|
|
337
|
+
})
|
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Feature('select')
|
|
4
4
|
|
|
5
|
+
Scenario('Should render a non selectable placeholder options for not in enum values @placeholderOption', async ({ I }) => {
|
|
6
|
+
I.amOnPage('placeholder-options.html')
|
|
7
|
+
I.waitForElement('.je-ready')
|
|
8
|
+
I.waitForElement('option[value="_placeholder_"][disabled][hidden]')
|
|
9
|
+
I.waitForElement('option[value="a"]')
|
|
10
|
+
I.waitForElement('option[value="b"]')
|
|
11
|
+
I.click('#set-value')
|
|
12
|
+
I.waitForText('-select-')
|
|
13
|
+
I.waitForText('Value must be one of the enumerated values')
|
|
14
|
+
I.waitForValue('#value', '"other"')
|
|
15
|
+
I.selectOption('[name="root"]', 'a')
|
|
16
|
+
I.waitForValue('#value', '"a"')
|
|
17
|
+
I.dontSee('Value must be one of the enumerated values')
|
|
18
|
+
I.selectOption('[name="root"]', 'b')
|
|
19
|
+
I.waitForValue('#value', '"b"')
|
|
20
|
+
I.dontSee('Value must be one of the enumerated values')
|
|
21
|
+
})
|
|
22
|
+
|
|
5
23
|
Scenario('should return correct booleans values when selected @readOnly', async ({ I }) => {
|
|
6
24
|
I.amOnPage('select.html')
|
|
7
25
|
I.click('.get-value')
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* global Feature Scenario */
|
|
2
|
+
|
|
3
|
+
Feature('starrating')
|
|
4
|
+
|
|
5
|
+
Scenario('should set and get values properly @starrating', async ({ I }) => {
|
|
6
|
+
I.amOnPage('starrating.html')
|
|
7
|
+
I.waitForElement('.je-ready')
|
|
8
|
+
I.waitForValue('#value', '{"integer_rating":0,"string_rating":"","starrating":"Beginner","starrating2":"Beginner","starrating3":"5 Stars"}')
|
|
9
|
+
I.click('[for="root[integer_rating]3"]')
|
|
10
|
+
I.click('[for="root[string_rating]3"]')
|
|
11
|
+
I.click('[for="root[starrating]3"]')
|
|
12
|
+
I.click('[for="root[starrating2]3"]')
|
|
13
|
+
I.click('[for="root[starrating3]10"]')
|
|
14
|
+
I.waitForValue('#value', '{"integer_rating":3,"string_rating":"3","starrating":"Experienced","starrating2":"Experienced","starrating3":"10 Stars"}')
|
|
15
|
+
})
|
|
@@ -116,3 +116,10 @@ Scenario('should work with cleave.js library', async ({ I }) => {
|
|
|
116
116
|
I.click('.get-value')
|
|
117
117
|
I.waitForValue('.debug', JSON.stringify({ cleave_test: '1234.567.890-1234' }))
|
|
118
118
|
})
|
|
119
|
+
|
|
120
|
+
Scenario('ace editor should have correct initial @prompt-paste-max-length-reached', async ({ I }) => {
|
|
121
|
+
I.amOnPage('prompt-paste-max-length-reached.html')
|
|
122
|
+
I.waitForElement('.je-ready')
|
|
123
|
+
I.click('#paste')
|
|
124
|
+
I.seeInPopup('Pasted text exceeded maximum length of 5 and will be clipped.')
|
|
125
|
+
})
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Feature('issues')
|
|
4
4
|
|
|
5
|
-
Scenario('GitHub issue 1158 should remain fixed @issue-1158
|
|
5
|
+
Scenario('GitHub issue 1158 should remain fixed @issue-1158', async ({ I }) => {
|
|
6
6
|
I.amOnPage('issues/issue-gh-1158.html')
|
|
7
7
|
I.seeElement('[name="root[name]"]')
|
|
8
8
|
})
|
|
@@ -5,6 +5,5 @@ Feature('GitHub issue 1164')
|
|
|
5
5
|
Scenario('GitHub issue 1164 should remain fixed @issue-1164', ({ I }) => {
|
|
6
6
|
I.amOnPage('issues/issue-gh-1164.html')
|
|
7
7
|
I.waitForElement('.je-ready')
|
|
8
|
-
I.waitForInvisible('option[value="undefined"]')
|
|
9
8
|
I.waitForValue('#value', '{"arrayEnumSelect":["one"],"stringEnumRadio":"one","numberEnumRadio":1.1,"integerEnumRadio":1}')
|
|
10
9
|
})
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Feature('issues')
|
|
4
4
|
|
|
5
|
-
Scenario('GitHub issue 1383 should remain fixed @issue-1383
|
|
5
|
+
Scenario('GitHub issue 1383 should remain fixed @issue-1383', async ({ I }) => {
|
|
6
6
|
I.amOnPage('issues/issue-gh-1383.html')
|
|
7
7
|
I.waitForElement('.je-ready')
|
|
8
8
|
I.waitForText('activity-timeout')
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* global Feature Scenario */
|
|
2
|
+
|
|
3
|
+
Feature('issues')
|
|
4
|
+
|
|
5
|
+
Scenario('GitHub issue 1452 should remain fixed @issue-1452', async ({ I }) => {
|
|
6
|
+
I.amOnPage('issues/issue-gh-1452.html')
|
|
7
|
+
I.click('#set-value')
|
|
8
|
+
I.selectOption('[id="root[category]"]', 'Vegetables')
|
|
9
|
+
I.waitForElement('[id="root[subcategory2]"]')
|
|
10
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* /* global Feature Scenario */
|
|
2
|
+
|
|
3
|
+
Feature('issues')
|
|
4
|
+
|
|
5
|
+
Scenario('GitHub issue 1525 should remain fixed @issue-1525', async ({ I }) => {
|
|
6
|
+
I.amOnPage('issues/issue-gh-1525.html')
|
|
7
|
+
I.waitForElement('.je-ready')
|
|
8
|
+
I.waitForValue('#value', '{"example":"dd"}')
|
|
9
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* global Feature Scenario */
|
|
2
|
+
|
|
3
|
+
Feature('issues')
|
|
4
|
+
|
|
5
|
+
Scenario('GitHub issue 1536 should remain fixed @issue-1536', async ({ I }) => {
|
|
6
|
+
I.amOnPage('issues/issue-gh-1536.html')
|
|
7
|
+
I.waitForElement('.je-ready')
|
|
8
|
+
I.checkOption('[name="root[dependency_chain_head]')
|
|
9
|
+
I.waitForText('dependent_field_one')
|
|
10
|
+
I.checkOption('[name="root[dependent_field_one]')
|
|
11
|
+
I.waitForText('dependent_field_two')
|
|
12
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* global Feature Scenario */
|
|
2
|
+
|
|
3
|
+
Feature('issues')
|
|
4
|
+
|
|
5
|
+
Scenario('GitHub issue 1538 should remain fixed @issue-1538', async ({ I }) => {
|
|
6
|
+
I.amOnPage('issues/issue-gh-1538.html')
|
|
7
|
+
I.waitForElement('.je-ready')
|
|
8
|
+
I.checkOption('[name="root[watched_field]')
|
|
9
|
+
I.waitForText('dependent_field')
|
|
10
|
+
})
|
package/tests/docker-compose.yml
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
<title>array events table</title>
|
|
5
|
+
<meta charset="utf-8"/>
|
|
6
|
+
<script src="../../dist/jsoneditor.js"></script>
|
|
7
7
|
</head>
|
|
8
8
|
<body>
|
|
9
9
|
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
<div class='container'></div>
|
|
15
15
|
|
|
16
16
|
<script>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const container = document.querySelector('.container');
|
|
18
|
+
const debug = document.querySelector('.debug');
|
|
19
|
+
const schema = {
|
|
20
20
|
"type": "array",
|
|
21
21
|
"title": "Strings",
|
|
22
22
|
"format": "table",
|
|
@@ -25,37 +25,45 @@
|
|
|
25
25
|
"title": "String"
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
const editor = new JSONEditor(container, {
|
|
29
30
|
schema: schema,
|
|
30
31
|
enable_array_copy: true
|
|
31
32
|
});
|
|
33
|
+
|
|
32
34
|
editor.promise.then(() => {
|
|
33
35
|
document.querySelector('.get-value').addEventListener('click', function () {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
debug.value = JSON.stringify(editor.getValue());
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
editor.setValue(["A", "B", "C", "D", "E"]);
|
|
40
|
+
|
|
41
|
+
editor.on('copyRow', function () {
|
|
42
|
+
alert('copyRow');
|
|
43
|
+
console.log('copyRow');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
editor.on('moveRow', function () {
|
|
47
|
+
alert('moveRow');
|
|
48
|
+
console.log('moveRow');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
editor.on('addRow', function () {
|
|
52
|
+
alert('addRow');
|
|
53
|
+
console.log('addRow');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
editor.on('deleteRow', function () {
|
|
57
|
+
alert('deleteRow');
|
|
58
|
+
console.log('deleteRow');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
editor.on('deleteAllRows', function () {
|
|
62
|
+
alert('deleteAllRows');
|
|
63
|
+
console.log('deleteAllRows');
|
|
64
|
+
});
|
|
57
65
|
})
|
|
58
|
-
|
|
66
|
+
|
|
59
67
|
</script>
|
|
60
68
|
|
|
61
69
|
</body>
|
|
@@ -10,16 +10,22 @@
|
|
|
10
10
|
<h1>Test</h1>
|
|
11
11
|
<label for="debug">Value</label>
|
|
12
12
|
<textarea id="debug" class="debug" cols="30" rows="10"></textarea>
|
|
13
|
-
<label for="action">Value</label>
|
|
14
|
-
<textarea id="action" class="action" cols="30" rows="5"></textarea>
|
|
15
13
|
<button class='get-value'>Get Value</button>
|
|
14
|
+
|
|
15
|
+
<label for="action1">Action1</label>
|
|
16
|
+
<textarea id="action1" cols="30" rows="5"></textarea>
|
|
17
|
+
|
|
18
|
+
<label for="action2">Action2</label>
|
|
19
|
+
<textarea id="action2" cols="30" rows="5"></textarea>
|
|
20
|
+
|
|
16
21
|
<div class='container'></div>
|
|
17
22
|
|
|
18
23
|
<script>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const container = document.querySelector('.container');
|
|
25
|
+
const debug = document.querySelector('.debug');
|
|
26
|
+
const action1 = document.querySelector('#action1');
|
|
27
|
+
const action2 = document.querySelector('#action2');
|
|
28
|
+
const schema = {
|
|
23
29
|
"type": "array",
|
|
24
30
|
"title": "Strings",
|
|
25
31
|
"items": {
|
|
@@ -28,40 +34,42 @@
|
|
|
28
34
|
}
|
|
29
35
|
};
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
schema: schema
|
|
37
|
+
const editor = new JSONEditor(container, {
|
|
38
|
+
schema: schema,
|
|
39
|
+
enable_array_copy: true
|
|
33
40
|
});
|
|
34
41
|
editor.promise.then(() => {
|
|
35
42
|
document.querySelector('.get-value').addEventListener('click', function () {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
editor.setValue(["A","B"]);
|
|
43
|
+
debug.value = JSON.stringify(editor.getValue());
|
|
44
|
+
});
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
action.value = 'moveRow';
|
|
43
|
-
console.log('moveRow');
|
|
44
|
-
});
|
|
46
|
+
editor.setValue(["A", "B"]);
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
editor.on('copyRow', function () {
|
|
49
|
+
action2.value = 'copyRow'
|
|
50
|
+
console.log('copyRow');
|
|
51
|
+
});
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
editor.on('moveRow', function () {
|
|
54
|
+
action1.value = 'moveRow';
|
|
55
|
+
console.log('moveRow');
|
|
56
|
+
});
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})
|
|
61
|
-
|
|
58
|
+
editor.on('addRow', function () {
|
|
59
|
+
action1.value = 'addRow'
|
|
60
|
+
console.log('addRow')
|
|
61
|
+
});
|
|
62
62
|
|
|
63
|
+
editor.on('deleteRow', function () {
|
|
64
|
+
action1.value = 'deleteRow'
|
|
65
|
+
console.log('deleteRow')
|
|
66
|
+
});
|
|
63
67
|
|
|
68
|
+
editor.on('deleteAllRows', function () {
|
|
69
|
+
action1.value = 'deleteAllRows'
|
|
70
|
+
console.log('deleteAllRows')
|
|
71
|
+
});
|
|
72
|
+
})
|
|
64
73
|
</script>
|
|
65
|
-
|
|
66
74
|
</body>
|
|
67
75
|
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.autocomplete-input{background-color:#eee;background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2IiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+PGNpcmNsZSBjeD0iMTEiIGN5PSIxMSIgcj0iOCIvPjxwYXRoIGQ9Im0yMSAyMS00LTQiLz48L3N2Zz4=");background-position:12px;background-repeat:no-repeat;border:1px solid #eee;border-radius:8px;box-sizing:border-box;flex:1;font-size:16px;line-height:1.5;padding:12px 12px 12px 48px;position:relative;width:100%}.autocomplete-input:focus,.autocomplete-input[aria-expanded=true]{background-color:#fff;border-color:rgba(0,0,0,.12);box-shadow:0 2px 2px rgba(0,0,0,.16);outline:none}[data-position=below] .autocomplete-input[aria-expanded=true]{border-bottom-color:transparent;border-radius:8px 8px 0 0}[data-position=above] .autocomplete-input[aria-expanded=true]{border-radius:0 0 8px 8px;border-top-color:transparent;z-index:2}.autocomplete[data-loading=true]:after{animation:rotate 1s linear infinite;border:3px solid rgba(0,0,0,.12);border-radius:100%;border-right-color:rgba(0,0,0,.48);content:"";height:20px;position:absolute;right:12px;top:50%;transform:translateY(-50%);width:20px}.autocomplete-result-list{background:#fff;border:1px solid rgba(0,0,0,.12);box-shadow:0 2px 2px rgba(0,0,0,.16);box-sizing:border-box;list-style:none;margin:0;max-height:296px;overflow-y:auto;padding:0}[data-position=below] .autocomplete-result-list{border-radius:0 0 8px 8px;border-top-color:transparent;margin-top:-1px;padding-bottom:8px}[data-position=above] .autocomplete-result-list{border-bottom-color:transparent;border-radius:8px 8px 0 0;margin-bottom:-1px;padding-top:8px}.autocomplete-result{background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjY2NjIiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+PGNpcmNsZSBjeD0iMTEiIGN5PSIxMSIgcj0iOCIvPjxwYXRoIGQ9Im0yMSAyMS00LTQiLz48L3N2Zz4=");background-position:12px;background-repeat:no-repeat;cursor:default;padding:12px 12px 12px 48px}.autocomplete-result:hover,.autocomplete-result[aria-selected=true]{background-color:rgba(0,0,0,.06)}@keyframes rotate{0%{transform:translateY(-50%) rotate(0deg)}to{transform:translateY(-50%) rotate(359deg)}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var Autocomplete=function(){"use strict";function t(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(e,n){for(var i=0;i<n.length;i++){var s=n[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,t(s.key),s)}}function i(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(e,n,i){return(n=t(n))in e?Object.defineProperty(e,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[n]=i,e}var o=function(t,e){return t.matches?t.matches(e):t.msMatchesSelector?t.msMatchesSelector(e):t.webkitMatchesSelector?t.webkitMatchesSelector(e):null},u=function(t,e){return t.closest?t.closest(e):function(t,e){for(var n=t;n&&1===n.nodeType;){if(o(n,e))return n;n=n.parentNode}return null}(t,e)},l=i((function t(){var n,i=this,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=o.search,r=o.autoSelect,a=void 0!==r&&r,c=o.setValue,d=void 0===c?function(){}:c,h=o.setAttribute,p=void 0===h?function(){}:h,b=o.onUpdate,f=void 0===b?function(){}:b,v=o.onSubmit,m=void 0===v?function(){}:v,L=o.onShow,y=void 0===L?function(){}:L,g=o.autocorrect,w=void 0!==g&&g,R=o.onHide,S=void 0===R?function(){}:R,x=o.onLoading,A=void 0===x?function(){}:x,E=o.onLoaded,k=void 0===E?function(){}:E,I=o.submitOnEnter,C=void 0!==I&&I;e(this,t),s(this,"value",""),s(this,"searchCounter",0),s(this,"results",[]),s(this,"selectedIndex",-1),s(this,"selectedResult",null),s(this,"destroy",(function(){i.search=null,i.setValue=null,i.setAttribute=null,i.onUpdate=null,i.onSubmit=null,i.autocorrect=null,i.onShow=null,i.onHide=null,i.onLoading=null,i.onLoaded=null})),s(this,"handleInput",(function(t){var e=t.target.value;i.updateResults(e),i.value=e})),s(this,"handleKeyDown",(function(t){var e=t.key;switch(e){case"Up":case"Down":case"ArrowUp":case"ArrowDown":var n="ArrowUp"===e||"Up"===e?i.selectedIndex-1:i.selectedIndex+1;t.preventDefault(),i.handleArrows(n);break;case"Tab":i.selectResult();break;case"Enter":var s=t.target.getAttribute("aria-activedescendant").length>0;i.selectedResult=i.results[i.selectedIndex]||i.selectedResult,i.selectResult(),i.submitOnEnter?i.selectedResult&&i.onSubmit(i.selectedResult):s?t.preventDefault():(i.selectedResult&&i.onSubmit(i.selectedResult),i.selectedResult=null);break;case"Esc":case"Escape":i.hideResults(),i.setValue();break;default:return}})),s(this,"handleFocus",(function(t){var e=t.target.value;i.updateResults(e),i.value=e})),s(this,"handleBlur",(function(){i.hideResults()})),s(this,"handleResultMouseDown",(function(t){t.preventDefault()})),s(this,"handleResultClick",(function(t){var e=t.target,n=u(e,"[data-result-index]");if(n){i.selectedIndex=parseInt(n.dataset.resultIndex,10);var s=i.results[i.selectedIndex];i.selectResult(),i.onSubmit(s)}})),s(this,"handleArrows",(function(t){var e=i.results.length;i.selectedIndex=(t%e+e)%e,i.onUpdate(i.results,i.selectedIndex)})),s(this,"selectResult",(function(){var t=i.results[i.selectedIndex];t&&i.setValue(t),i.hideResults()})),s(this,"updateResults",(function(t){var e=++i.searchCounter;i.onLoading(),i.search(t).then((function(t){e===i.searchCounter&&(i.results=t,i.onLoaded(),0!==i.results.length?(i.selectedIndex=i.autoSelect?0:-1,i.onUpdate(i.results,i.selectedIndex),i.showResults()):i.hideResults())}))})),s(this,"showResults",(function(){i.setAttribute("aria-expanded",!0),i.onShow()})),s(this,"hideResults",(function(){i.selectedIndex=-1,i.results=[],i.setAttribute("aria-expanded",!1),i.setAttribute("aria-activedescendant",""),i.onUpdate(i.results,i.selectedIndex),i.onHide()})),s(this,"checkSelectedResultVisible",(function(t){var e=t.querySelector('[data-result-index="'.concat(i.selectedIndex,'"]'));if(e){var n=t.getBoundingClientRect(),s=e.getBoundingClientRect();s.top<n.top?t.scrollTop-=n.top-s.top:s.bottom>n.bottom&&(t.scrollTop+=s.bottom-n.bottom)}})),this.search=(n=l,Boolean(n&&"function"==typeof n.then)?l:function(t){return Promise.resolve(l(t))}),this.autoSelect=a,this.setValue=d,this.setAttribute=p,this.onUpdate=f,this.onSubmit=m,this.autocorrect=w,this.onShow=y,this.onHide=S,this.onLoading=A,this.onLoaded=k,this.submitOnEnter=C})),r=0,a=function(){return i((function t(n,i,s){e(this,t),this.id="".concat(s,"-result-").concat(n),this.class="".concat(s,"-result"),this["data-result-index"]=n,this.role="option",n===i&&(this["aria-selected"]="true")}),[{key:"toString",value:function(){var t=this;return Object.keys(this).reduce((function(e,n){return"".concat(e," ").concat(n,'="').concat(t[n],'"')}),"")}}])}(),c=i((function t(n){var i=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=o.search,c=o.onSubmit,d=void 0===c?function(){}:c,h=o.onUpdate,p=void 0===h?function(){}:h,b=o.baseClass,f=void 0===b?"autocomplete":b,v=o.autocorrect,m=void 0!==v&&v,L=o.autoSelect,y=o.getResultValue,g=void 0===y?function(t){return t}:y,w=o.renderResult,R=o.debounceTime,S=void 0===R?0:R,x=o.resultListLabel,A=o.submitOnEnter,E=void 0!==A&&A;e(this,t),s(this,"expanded",!1),s(this,"loading",!1),s(this,"position",{}),s(this,"resetPosition",!0),s(this,"initialize",(function(){i.root.style.position="relative",i.input.setAttribute("role","combobox"),i.input.setAttribute("autocomplete","off"),i.input.setAttribute("autocapitalize","off"),i.autocorrect&&i.input.setAttribute("autocorrect","on"),i.input.setAttribute("spellcheck","false"),i.input.setAttribute("aria-autocomplete","list"),i.input.setAttribute("aria-haspopup","listbox"),i.input.setAttribute("aria-expanded","false"),i.resultList.setAttribute("role","listbox");var t=function(t){if(null!=t&&t.length){var e=t.startsWith("#");return{attribute:e?"aria-labelledby":"aria-label",content:e?t.substring(1):t}}}(i.resultListLabel);t&&i.resultList.setAttribute(t.attribute,t.content),i.resultList.style.position="absolute",i.resultList.style.zIndex="1",i.resultList.style.width="100%",i.resultList.style.boxSizing="border-box",i.resultList.id||(i.resultList.id=function(){return"".concat(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").concat(++r)}("".concat(i.baseClass,"-result-list-"))),i.input.setAttribute("aria-owns",i.resultList.id),document.body.addEventListener("click",i.handleDocumentClick),i.input.addEventListener("input",i.core.handleInput),i.input.addEventListener("keydown",i.core.handleKeyDown),i.input.addEventListener("focus",i.core.handleFocus),i.input.addEventListener("blur",i.core.handleBlur),i.resultList.addEventListener("mousedown",i.core.handleResultMouseDown),i.resultList.addEventListener("click",i.core.handleResultClick),i.updateStyle()})),s(this,"destroy",(function(){document.body.removeEventListener("click",i.handleDocumentClick),i.input.removeEventListener("input",i.core.handleInput),i.input.removeEventListener("keydown",i.core.handleKeyDown),i.input.removeEventListener("focus",i.core.handleFocus),i.input.removeEventListener("blur",i.core.handleBlur),i.resultList.removeEventListener("mousedown",i.core.handleResultMouseDown),i.resultList.removeEventListener("click",i.core.handleResultClick),i.root=null,i.input=null,i.resultList=null,i.getResultValue=null,i.onUpdate=null,i.renderResult=null,i.core.destroy(),i.core=null})),s(this,"setAttribute",(function(t,e){i.input.setAttribute(t,e)})),s(this,"setValue",(function(t){i.input.value=t?i.getResultValue(t):""})),s(this,"renderResult",(function(t,e){return"<li ".concat(e,">").concat(i.getResultValue(t),"</li>")})),s(this,"handleUpdate",(function(t,e){var n,s,o,u;i.resultList.innerHTML="",t.forEach((function(t,n){var s=new a(n,e,i.baseClass),o=i.renderResult(t,s);"string"==typeof o?i.resultList.insertAdjacentHTML("beforeend",o):i.resultList.insertAdjacentElement("beforeend",o)})),i.input.setAttribute("aria-activedescendant",e>-1?"".concat(i.baseClass,"-result-").concat(e):""),i.resetPosition&&(i.resetPosition=!1,i.position=(n=i.input,s=i.resultList,o=n.getBoundingClientRect(),u=s.getBoundingClientRect(),o.bottom+u.height>window.innerHeight&&window.innerHeight-o.bottom<o.top&&window.pageYOffset+o.top-u.height>0?"above":"below"),i.updateStyle()),i.core.checkSelectedResultVisible(i.resultList),i.onUpdate(t,e)})),s(this,"handleShow",(function(){i.expanded=!0,i.updateStyle()})),s(this,"handleHide",(function(){i.expanded=!1,i.resetPosition=!0,i.updateStyle()})),s(this,"handleLoading",(function(){i.loading=!0,i.updateStyle()})),s(this,"handleLoaded",(function(){i.loading=!1,i.updateStyle()})),s(this,"handleDocumentClick",(function(t){i.root.contains(t.target)||i.core.hideResults()})),s(this,"updateStyle",(function(){i.root.dataset.expanded=i.expanded,i.root.dataset.loading=i.loading,i.root.dataset.position=i.position,i.resultList.style.visibility=i.expanded?"visible":"hidden",i.resultList.style.pointerEvents=i.expanded?"auto":"none","below"===i.position?(i.resultList.style.bottom=null,i.resultList.style.top="100%"):(i.resultList.style.top=null,i.resultList.style.bottom="100%")})),this.root="string"==typeof n?document.querySelector(n):n,this.input=this.root.querySelector("input"),this.resultList=this.root.querySelector("ul"),this.baseClass=f,this.autocorrect=m,this.getResultValue=g,this.onUpdate=p,"function"==typeof w&&(this.renderResult=w),this.resultListLabel=x,this.submitOnEnter=E;var k,I,C,U,V=new l({search:u,autoSelect:L,setValue:this.setValue,setAttribute:this.setAttribute,onUpdate:this.handleUpdate,autocorrect:this.autocorrect,onSubmit:d,onShow:this.handleShow,onHide:this.handleHide,onLoading:this.handleLoading,onLoaded:this.handleLoaded,submitOnEnter:this.submitOnEnter});S>0&&(V.handleInput=(k=V.handleInput,I=S,function(){var t=this,e=arguments,n=C&&!U;clearTimeout(U),U=setTimeout((function(){U=null,C||k.apply(t,e)}),I),n&&k.apply(t,e)})),this.core=V,this.initialize()}));return c}();
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
<title>Autocomplete</title>
|
|
6
6
|
<link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
|
|
7
7
|
<link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
|
|
8
|
-
<link rel="stylesheet" href="
|
|
9
|
-
|
|
10
|
-
<script src="../../dist/jsoneditor.js"></script>
|
|
8
|
+
<link rel="stylesheet" href="./assets/autocomplete.css"/>
|
|
9
|
+
|
|
11
10
|
</head>
|
|
12
11
|
<body>
|
|
13
12
|
|
|
@@ -18,7 +17,8 @@
|
|
|
18
17
|
<div class='json-editor-container'></div>
|
|
19
18
|
</div>
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
<script src="./assets/autocomplete.min.js"></script>
|
|
21
|
+
<script src="../../dist/jsoneditor.js"></script>
|
|
22
22
|
<script>
|
|
23
23
|
window.addEventListener('load', function () {
|
|
24
24
|
var jsonEditorContainer = document.querySelector('.json-editor-container')
|