MCPcopy Index your code
hub / github.com/json-editor/json-editor / _createCopyButton

Method _createCopyButton

src/editors/table.js:360–396  ·  view source on GitHub ↗
(i, holder)

Source from the content-addressed store, hash-verified

358 }
359
360 _createCopyButton (i, holder) {
361 const button = this.getButton('', 'copy', 'button_copy_row_title_short')
362 const schema = this.schema
363 button.classList.add('copy', 'json-editor-btntype-copy')
364 button.setAttribute('data-i', i)
365 button.addEventListener('click', e => {
366 e.preventDefault()
367 e.stopPropagation()
368 const j = e.currentTarget.getAttribute('data-i') * 1
369 const value = this.getValue()
370
371 let newValue = value[j]
372
373 /* On copy, recreate uuid if needed. */
374 if (schema.items.type === 'string' && schema.items.format === 'uuid') {
375 newValue = generateUUID()
376 } else if (schema.items.type === 'object' && schema.items.properties) {
377 value.forEach((row, i) => {
378 if (j === i) {
379 for (const key of Object.keys(row)) {
380 if (schema.items.properties && schema.items.properties[key] && schema.items.properties[key].format === 'uuid') {
381 newValue = Object.assign({}, value[j])
382 newValue[key] = generateUUID()
383 }
384 }
385 }
386 })
387 }
388
389 value.splice(j + 1, 0, newValue)
390 this.setValue(value)
391 this.onChange(true)
392 this.jsoneditor.trigger('copyRow', this.rows[j + 1])
393 })
394 holder.appendChild(button)
395 return button
396 }
397
398 _createMoveUpButton (i, holder) {
399 const button = this.getButton('', 'moveup', 'button_move_up_title')

Callers 1

addRowMethod · 0.95

Calls 8

setValueMethod · 0.95
generateUUIDFunction · 0.90
addMethod · 0.80
assignMethod · 0.80
triggerMethod · 0.80
getButtonMethod · 0.45
getValueMethod · 0.45
onChangeMethod · 0.45

Tested by

no test coverage detected