const defaultInitialVars = { isWatchingSourceFile : false } ; declare var acquireVsCodeApi ; declare var initialContent ; declare var initialConfig ; declare var initialVars ; let vscode = undefined ; if ( typeof acquireVsCodeApi !== 'undefined' ) { vscode = acquireVsCodeApi ( ) ; } if ( typeof initialConfig === 'undefined' ) { var initialConfig = undefined as CsvEditSettings | undefined ; var initialVars = { ... defaultInitialVars } ; } const csv = ( window as any ) . Papa ; let hot ; toFormat ( Big ) ; /**
 * the default csv content to used if we get empty content
 * handson table will throw if we pass in a 1D array because it expects an object?
 */ const defaultCsvContentIfEmpty = `,\n,` ; /**
 * TODO check
 * stores the header row after initial parse...
 * if we have header rows in data (checked) we set this to the header row
 * if we uncheck header row read option then we use this to insert the header row again as data row
 * can be null if we have 0 rows
 * {string[] | null}
 */ let headerRowWithIndex = null ; let lastClickedHeaderCellTh = null ; let editHeaderCellTextInputEl = null ; let editHeaderCellTextInputLeftOffsetInPx = 0 ; let handsontableOverlayScrollLeft = 0 ; let _onTableScrollThrottled = null ; let hiddenPhysicalRowIndices = [ ] ; let copyPasteRowLimit = 10000000 ; let copyPasteColLimit = 10000000 ; type HeaderRowWithIndexUndoStackItem = { action : 'added' | 'removed' ; visualIndex : number ; headerData : Array < string | null > ; } ; let headerRowWithIndexUndoStack = [ ] ; let headerRowWithIndexRedoStack = [ ] ; /**
 * this is part of the output from papaparse
 * for each column
 * 	true: column was originally quoted
 * 	false: was not quoted
 *
 * this is expanded via  _normalizeDataArray so we have information about every column
 * see  parseCsv for quoting rules (e.g. header rows, ...)
 *
 * so this is set in  displayData and should be kept up-to-date because it's used for unparsing
  let columnIsQuoted ; let defaultCsvReadOptions = { header : false , comments : '#' , delimiter : '' , newline : '' , quoteChar : '"' , escapeChar : '"' , skipEmptyLines : true , dynamicTyping : false , _hasHeader : false , } ; let defaultCsvWriteOptions = { header : false , comments : '#' , delimiter : '' , newline : '' , quoteChar : '"' , escapeChar : '"' , quoteAllFields : false , quoteEmptyOrNullFields : false , retainQuoteInformation : true , } ; let newLineFromInput = '\n' ; let lastHandsonMoveWas = null ; /**
 * true: the cell/row color is changed if the first cell is a comment, (might have negative impact on performance e.g. for large data sets),
 * false: no additional highlighting (comments are still treated as comments)
 */ let highlightCsvComments = true ; /**
 * true: new columns will get true as quote information (also for added columns via expanding),
 * false: new columns will get false as quote information
 */ let newColumnQuoteInformationIsQuoted = false ; /**
 * true: cell content is wrapped and the row height is changed,
 * false: no wrapping (content is hidden)
 */ let enableWrapping = true ; /**
 * true: borders are set to 0 (in css). This helps if you encounter some border color issues,
 * false: normal borders
 */ let disableBorders = false ; /**
 * fixes the first X rows so they will stay in view even if you scroll
 */ let fixedRowsTop = 0 ; /**
 * fixes the first X columns so they will stay in view even if you scroll
 */ let fixedColumnsLeft = 0 ; /**
 * true: we started with has header option enabled which caused an event
 *   because we change the table when removing the header row from the table body we need to clear the undo...
 * false: nothing to do
 */ let isFirstHasHeaderChangedEvent = true ; /**
 * the initial width for columns, 0 or a negative number will disable this and auto column size is used on initial render
 */ let initialColumnWidth = 0 ; /**
 * this is only needed if we want to display header rows but we have only 1 row...
 * handsontable always needs at least one row so we cannot remove the first row and use it as header
 * so we store here that we want to set the first row as header row immediately after we have at least 2 rows
 * true: use the first row as header row immediately after we have at least 2 rows
 * false: do not use the first row as header (also false we have toggle has header option and have >= 2 rows)
 */ let shouldApplyHasHeaderAfterRowsAdded = false ; /**
 * table is editable or not, also disables some related ui, e.g. buttons
 * set via  CsvEditSettings . initiallyIsInReadonlyMode let isReadonlyMode = false ; /**
 * stores the widths of the handsontable columns
 * THIS is always synced with the ui
 * it allows us to modify the widths better e.g. restore widths...
 *
 * uses visual column indices!
 *
 * inspired by https://github.com/YaroslavOvdii/fliplet-widget-data-source/blob/master/js/spreadsheet.js (also see https://github.com/Fliplet/fliplet-widget-data-source/pull/81/files)
 */ let allColWidths = [ ] ; let isInitialHotRender = true ; const csvEditorWrapper = _getById ( 'csv-editor-wrapper' ) ; const csvEditorDiv = _getById ( 'csv-editor' ) ; const helModalDiv = _getById ( 'help-modal' ) ; const askReadAgainModalDiv = _getById ( 'ask-read-again-modal' ) ; const askReloadFileModalDiv = _getById ( 'ask-reload-file-modal' ) ; const sourceFileChangedDiv = _getById ( 'source-file-changed-modal' ) ; const readContent = _getById ( 'read-options-content' ) ; const writeContent = _getById ( 'write-options-content' ) ; const previewContent = _getById ( 'preview-content' ) ; const btnApplyChangesToFileAndSave = _getById ( `btn-apply-changes-to-file-and-save` ) ; const readDelimiterTooltip = _getById ( 'read-delimiter-tooltip' ) ; const readDelimiterTooltipText = "Empty to auto detect" ; const receivedCsvProgBar = _getById ( 'received-csv-prog-bar' ) as HTMLProgressElement ; const receivedCsvProgBarWrapper = _getById ( 'received-csv-prog-bar-wrapper' ) as HTMLDivElement ; const statusInfo = _getById ( 'status-info' ) as HTMLSpanElement ; const fixedRowsTopInfoSpan = _getById ( 'fixed-rows-top-info' ) as HTMLDivElement ; const fixedRowsTopIcon = _getById ( 'fixed-rows-icon' ) as HTMLSpanElement ; const fixedRowsTopText = _getById ( 'fixed-rows-text' ) as HTMLSpanElement ; const fixedColumnsTopInfoSpan = _getById ( 'fixed-columns-top-info' ) as HTMLDivElement ; const fixedColumnsTopIcon = _getById ( 'fixed-columns-icon' ) as HTMLSpanElement ; const fixedColumnsTopText = _getById ( 'fixed-columns-text' ) as HTMLSpanElement ; const showCommentsBtn = _getById ( 'show-comments-btn' ) as HTMLButtonElement ; const hideCommentsBtn = _getById ( 'hide-comments-btn' ) as HTMLButtonElement ; const newlineSameSsInputOption = _getById ( 'newline-same-as-input-option' ) as HTMLOptionElement ; const newlineSameSsInputOptionText = `Same as input` ; updateNewLineSelect ( ) ; const warningTooltipTextWhenCommentRowNotFirstCellIsUsed = `Please use only the first cell in comment row (others are not exported)` ; const unsavedChangesIndicator = _getById ( 'unsaved-changes-indicator' ) as HTMLSpanElement ; const reloadFileSpan = _getById ( 'reload-file' ) as HTMLSpanElement ; const sourceFileUnwatchedIndicator = _getById ( 'source-file-unwatched-indicator' ) as HTMLSpanElement ; const hasHeaderReadOptionInput = _getById ( 'has-header' ) as HTMLInputElement ; const hasHeaderLabel = _getById ( `has-header-label` ) as HTMLLabelElement ; const leftSidePanelToggle = document . getElementById ( 'left-panel-toggle' ) ; if ( vscode && ! leftSidePanelToggle ) throw new Error ( `element with id 'left-panel-toggle' not found` ) ; const leftPanelToggleIconExpand = document . getElementById ( `left-panel-toggle-icon-expand` ) as HTMLElement ; if ( vscode && ! leftPanelToggleIconExpand ) throw new Error ( `element with id 'left-panel-toggle-icon-expand' not found` ) ; const sideBarResizeHandle = _getById ( `side-panel-resize-handle` ) as HTMLDivElement ; const sidePanel = _getById ( `side-panel` ) as HTMLDivElement ; const statSelectedRows = _getById ( `stat-selected-rows` ) as HTMLDivElement ; const statSelectedCols = _getById ( `stat-selected-cols` ) as HTMLDivElement ; const statRowsCount = _getById ( `stat-rows-count` ) as HTMLDivElement ; const statColsCount = _getById ( `stat-cols-count` ) as HTMLDivElement ; const statSelectedCellsCount = _getById ( `stat-selected-cells-count` ) as HTMLDivElement ; const statSelectedNotEmptyCells = _getById ( `stat-selected-not-empty-cells` ) as HTMLDivElement ; const statSumOfNumbers = _getById ( `stat-sum-of-numbers` ) as HTMLDivElement ; const numbersStyleEnRadio = _getById ( `numbers-style-en` ) as HTMLInputElement ; const numbersStyleNonEnRadio = _getById ( `numbers-style-non-en` ) as HTMLInputElement ; const isReadonlyModeToggleSpan = _getById ( `is-readonly-mode-toggle` ) as HTMLSpanElement ; const findWidgetInstance = new FindWidget ( ) ; setupSideBarResizeHandle ( ) ; setCsvReadOptionsInitial ( defaultCsvReadOptions ) ; setCsvWriteOptionsInitial ( defaultCsvWriteOptions ) ; if ( typeof initialContent === 'undefined' ) { var initialContent = '' ; } if ( initialContent === undefined ) { initialContent = '' ; } if ( ! vscode ) { console . log ( "initialConfig: " , initialConfig ) ; console . log ( "initialContent: " + initialContent ) ; } setupAndApplyInitialConfigPart1 ( initialConfig , initialVars ) ; setupGlobalShortcutsInVs ( ) ; let _data = parseCsv ( initialContent , defaultCsvReadOptions ) ; if ( _data && ! vscode ) { let _exampleData = [ ] ; let initialRows = 5 ; let initialCols = 5 ; _exampleData = [ ... Array ( initialRows ) . keys ( ) ] . map ( p => [ ... Array ( initialCols ) . keys ( ) ] . map ( k => '' ) ) ; _data = { columnIsQuoted : _exampleData [ 0 ] . map ( p => false ) , data : _exampleData } ; displayData ( _data , defaultCsvReadOptions ) ; } if ( vscode ) { receivedCsvProgBarWrapper . style . display = "block" ; window . addEventListener ( 'message' , ( e ) => { handleVsCodeMessage ( e ) ; } ) ; _postReadyMessage ( ) ; } function setupGlobalShortcutsInVs ( ) { if ( vscode ) { Mousetrap . bindGlobal ( [ 'meta+s' , 'ctrl+s' ] , ( e ) => { e . preventDefault ( ) ; postApplyContent ( true ) ; } ) ; } Mousetrap . bindGlobal ( [ 'ctrl+ins' ] , ( e ) => { insertRowBelow ( ) ; } ) ; Mousetrap . bindGlobal ( [ 'ctrl+shift+ins' ] , ( e ) => { insertRowAbove ( ) ; } ) ; }