Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/cidgoh/DataHarmonizer
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Nov 14, 2023
2 parents 07a8a97 + 206b7e1 commit b189159
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down
10 changes: 0 additions & 10 deletions .idea/DataHarmonizer.iml

This file was deleted.

30 changes: 0 additions & 30 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

72 changes: 0 additions & 72 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import '@selectize/selectize';
import Handsontable from 'handsontable';
import SheetClip from 'sheetclip';
import $ from 'jquery';
import { utils as XlsxUtils, read as xlsxRead } from 'xlsx/xlsx.mjs';
import { renderContent, urlToClickableAnchor } from './utils/content';
Expand Down Expand Up @@ -471,9 +470,6 @@ class DataHarmonizer {
createHot() {
const self = this;

this.clipboardCache = '';
this.sheetclip = new SheetClip();

this.invalid_cells = {};
if (this.hot) {
this.hot.destroy(); // handles already existing data
Expand All @@ -489,74 +485,6 @@ class DataHarmonizer {
rowHeaders: true,
copyPaste: true,
manualColumnResize: true,

//colWidths: [100], //Just fixes first column width
// beforePaste: (data, coords) => { // commented out for eslint
beforePaste: () => {
//data is a 2d array of rows and columns
},
afterCopy: function (changes) {
self.clipboardCache = self.sheetclip.stringify(changes);
},
afterCut: function (changes) {
self.clipboardCache = self.sheetclip.stringify(changes);
},
afterPaste: function (changes) {
// we want to be sure that our cache is up to date, even if someone pastes data from another source than our tables.
self.clipboardCache = self.sheetclip.stringify(changes);
},
contextMenu: [
'copy',
'cut',
{
key: 'paste',
name: 'Paste',
disabled: function () {
// For now always on, since we can't query whether something is
// in system cut/paste buffer without prompting user for ok.
return false;
},
callback: function () {
var plugin = this.getPlugin('copyPaste');
this.listen();

// Due to asynchronous clipboard calls, this has to be in an
// immediate setTimeout()
setTimeout(async () => {
let text = await navigator.clipboard.readText();
if (text && text.length) {
// An odd issue that with handsontable Paste menu item,
// targeted paste area gets extended a row on each
// subsequent Paste request. This doesn't happen if one
// uses CTRL-V instead (but that doesn't work on
// FlatpickrEditor fields unless they are later in
// multi-column paste).
// See https://github.com/handsontable/handsontable/issues/1930
// Solution is to test for and clear out trailing newline.

if (text.substr(-1, 1) == '\n') text = text.slice(0, -1);
//self.clipboardCache = text;
plugin.paste(text);
}
});

/*
if (
self.clipboardCache &&
self.clipboardCache.length &&
self.clipboardCache.substr(-1, 1) == '\n'
) {
self.clipboardCache = self.clipboardCache.slice(0, -1);
}
plugin.paste(self.clipboardCache);
*/
},
},
'remove_row',
'row_above',
'row_below',
],
minRows: 100,
minSpareRows: 100,
width: '100%',
Expand Down
23 changes: 16 additions & 7 deletions lib/editors/FlatpickrEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import flatpickr from 'flatpickr';
import 'flatpickr/dist/themes/light.css';
import { format, parse } from 'date-fns';

const REF_DATE = new Date(0);
const REF_DATE = new Date();
REF_DATE.setHours(0, 0, 0, 0);

class FlatpickrEditor extends Handsontable.editors.TextEditor {
/**
Expand All @@ -29,6 +30,7 @@ class FlatpickrEditor extends Handsontable.editors.TextEditor {
createElements() {
super.createElements();

this.TEXTAREA.remove();
this.TEXTAREA = this.hot.rootDocument.createElement('input');
this.TEXTAREA.className = 'handsontableInput';
this.TEXTAREA.setAttribute('data-hot-input', true);
Expand Down Expand Up @@ -76,7 +78,9 @@ class FlatpickrEditor extends Handsontable.editors.TextEditor {
destroyElements() {
const datePickerParentElement = this.datePicker.parentNode;

this.fp.destroy();
if (this.fp?.destroy) {
this.fp.destroy();
}

if (datePickerParentElement) {
datePickerParentElement.removeChild(this.datePicker);
Expand Down Expand Up @@ -113,7 +117,6 @@ class FlatpickrEditor extends Handsontable.editors.TextEditor {
*/
close() {
this._opened = false;
this.fp && this.fp.destroy();
this.removeHooksByKey('beforeKeyDown');
super.close();
}
Expand Down Expand Up @@ -157,14 +160,20 @@ class FlatpickrEditor extends Handsontable.editors.TextEditor {
const mandatoryConfig = {
appendTo: this.datePicker,
allowInput: true,
allowInvalidPreload: true,
allowInvalidPreload: false,
inline: true,
clickOpens: false,
// Inject date-fns formatter & parser here for better consistency when
// parsing and formatting of exported data
formatDate: format,
parseDate: (dateString, formatString) =>
parse(dateString, formatString, REF_DATE),
formatDate: (dateObj, formatString) => {
if (!(dateObj instanceof Date && !isNaN(dateObj.getTime()))) {
return '';
}
return format(dateObj, formatString);
},
parseDate: (dateString, formatString) => {
return parse(dateString, formatString, REF_DATE);
},
onChange: (dates, datestr) => {
this.setValue(datestr);
},
Expand Down

0 comments on commit b189159

Please sign in to comment.