Skip to content

Commit

Permalink
Merge branch 'master' into mpox-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ddooley committed Nov 10, 2023
2 parents 6edbe5a + 14532f6 commit 5bba542
Show file tree
Hide file tree
Showing 27 changed files with 2,444 additions and 2,261 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.

35 changes: 24 additions & 11 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,12 +30,14 @@ 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);
this.textareaStyle = this.TEXTAREA.style;
this.textareaStyle.width = 0;
this.textareaStyle.height = 0;
Handsontable.dom.empty(this.TEXTAREA_PARENT);
this.TEXTAREA_PARENT.innerText = '';
this.TEXTAREA_PARENT.appendChild(this.TEXTAREA);

this.datePicker = this.hot.rootDocument.createElement('DIV');
Expand All @@ -52,10 +55,10 @@ class FlatpickrEditor extends Handsontable.editors.TextEditor {
*/
const eventManager = new Handsontable.EventManager(this);
eventManager.addEventListener(this.datePicker, 'mousedown', (event) => {
Handsontable.dom.stopImmediatePropagation(event);
event.stopPropagation();
});
eventManager.addEventListener(this.datePicker, 'keydown', (event) => {
Handsontable.dom.stopImmediatePropagation(event);
event.stopPropagation();
});
eventManager.addEventListener(this.TEXTAREA, 'keydown', (event) => {
if (event.keyCode === Handsontable.helper.KEY_CODES.ENTER) {
Expand All @@ -75,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 @@ -141,8 +146,10 @@ class FlatpickrEditor extends Handsontable.editors.TextEditor {
*/
showDatepicker(event) {
const offset = this.TD.getBoundingClientRect();
const isMouseDown = this.instance.view.isMouseDown();
const isMeta = event ? Handsontable.helper.isMetaKey(event.keyCode) : false;
const isMouseDown = this.hot.view.isMouseDown();
const isMeta = event
? Handsontable.helper.isFunctionKey(event.keyCode)
: false;

const defaultConfig = this.getFlatpickrConfig();
const cellConfig =
Expand All @@ -153,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
Binary file modified lib/images/changeTemplate.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/doubleClickHeaders.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/editCopyPasteDelete.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/exportingFiles.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/fillColumn.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/jumpToColumn.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/moreInfo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/provenance.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/selectingVals.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/showRows.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/showSection.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/toggleRequiredCols.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/validatingCells.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/images/versionUpdate.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion lib/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export default {
styles({
mode: 'extract',
}),
commonjs(),
commonjs({
namedExports: {
'file-saver': ['saveAs'],
},
}),
babel({ babelHelpers: 'bundled' }),
terser(),
],
Expand Down
35 changes: 28 additions & 7 deletions lib/utils/content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import MarkdownIt from 'markdown-it';
import linkifyIt from 'linkify-it';
import { formatEscapeHTML } from './fields';

const linkify = linkifyIt();

const md = new MarkdownIt({
html: true,
linkify: true,
Expand Down Expand Up @@ -30,12 +30,33 @@ export const urlToMarkdownLink = (content) =>
// Replace operation using the named capture group "url"
// const str = "Visit [my site](https://example.com) or directly go to https://example.org";
// urlToClickableAnchor(str) == `Visit [my site](https://example.com) or directly go to <a href="https://example.org">https://example.org</a>`
export const urlToClickableAnchor = (content) => {
const url = linkify.match(content)[0].url;
return content.replace(
linkify.match(content)[0].url,
`<a href="${url}">${url}</a>`
);

export const urlToClickableAnchor = (string) => {
// Use linkify to find all URLs in the string
const matches = linkify.match(string);

// If no URLs found, return the original string
if (!matches) {
return string;
}

// Create a set of unique URLs to avoid duplicate replacements
const uniqueMatches = [...new Set(matches.map((match) => match.url))];

// Replace all occurrences of each unique URL with an anchor tag
uniqueMatches.forEach((url) => {
// Escape the URL to safely create a regex pattern
const escapedURL = formatEscapeHTML(url);
// Create a global regular expression to match all occurrences of the URL
const regex = new RegExp(
escapedURL.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'),
'g'
);
// Replace the URL with an anchor tag in the string
string = string.replace(regex, `<a href="${escapedURL}">${escapedURL}</a>`);
});

return string;
};

/* Renderer */
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,16 @@ export function formatMultivaluedValue(values) {
.map((v) => (typeof v === 'string' ? v.trim() : String(v)))
.join(MULTIVALUED_DELIMITER);
}

export const formatEscapeHTML = (string) => {
return string.replace(/[&<>"']/g, (char) => {
const escape = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
};
return escape[char] || char;
});
};
2 changes: 1 addition & 1 deletion lib/utils/files.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { utils as XlsxUtils, writeFile } from 'xlsx';
import { utils as XlsxUtils, writeFile } from 'xlsx/xlsx.mjs';
import { saveAs } from 'file-saver';

export function readFileAsync(file) {
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@babel/core": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-image": "^2.1.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
Expand Down Expand Up @@ -75,14 +75,12 @@
"file-saver": "^2.0.5",
"flatpickr": "^4.6.13",
"handsontable": "13.1.0",
"isomorphic-dompurify": "1.8.0",
"linkify-it": "^4.0.1",
"markdown-it": "^13.0.2",
"marked": "^7.0.3",
"punycode": "^2.3.1",
"sifter": "^0.5.4",
"rollup-plugin-polyfill-node": "^0.12.0",
"sheetclip": "^0.3.0",
"tlds": "^1.245.0",
"sifter": "^0.5.4",
"xlsx": "^0.18.5"
},
"jest": {
Expand Down
Loading

0 comments on commit 5bba542

Please sign in to comment.