Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): convert copy manager plugins to vanillaJS #746

Merged
merged 1 commit into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions plugins/slick.cellcopymanager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function ($) {
(function (window) {
// register namespace
$.extend(true, window, {
Slick.Utils.extend(true, window, {
"Slick": {
"CellCopyManager": CellCopyManager
}
Expand All @@ -21,7 +21,7 @@
_grid.onKeyDown.unsubscribe(handleKeyDown);
}

function handleKeyDown(e, args) {
function handleKeyDown(e) {
var ranges;
if (!_grid.getEditorLock().isActive()) {
if (e.which == Slick.keyCode.ESCAPE) {
Expand Down Expand Up @@ -75,7 +75,7 @@
_grid.removeCellCssStyles("copy-manager");
}

$.extend(this, {
Slick.Utils.extend(this, {
"init": init,
"destroy": destroy,
"pluginName": "CellCopyManager",
Expand All @@ -87,4 +87,4 @@
"onPasteCells": new Slick.Event()
});
}
})(jQuery);
})(window);
67 changes: 36 additions & 31 deletions plugins/slick.cellexternalcopymanager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function ($) {
(function (window) {
// register namespace
$.extend(true, window, {
Slick.Utils.extend(true, window, {
"Slick": {
"CellExternalCopyManager": CellExternalCopyManager
}
Expand Down Expand Up @@ -59,8 +59,10 @@
}
// we give focus on the grid when a selection is done on it.
// without this, if the user selects a range of cell without giving focus on a particular cell, the grid doesn't get the focus and key stroke handles (ctrl+c) don't work
cellSelectionModel.onSelectedRangesChanged.subscribe(function(e, args){
_grid.focus();
cellSelectionModel.onSelectedRangesChanged.subscribe(() => {
if (!_grid.getEditorLock().isActive()) {
_grid.focus();
}
});
}

Expand All @@ -78,54 +80,57 @@
return columnDef.name;
}

function getDataItemValueForColumn(item, columnDef, e) {
if (_options.dataItemColumnValueExtractor) {
var val = _options.dataItemColumnValueExtractor(item, columnDef);

if (val) { return val; }
function getDataItemValueForColumn(item, columnDef, event) {
if (typeof _options.dataItemColumnValueExtractor === 'function') {
const val = _options.dataItemColumnValueExtractor(item, columnDef);
if (val) {
return val;
}
}

var retVal = '';
let retVal = '';

// if a custom getter is not defined, we call serializeValue of the editor to serialize
if (columnDef.editor){
var editorArgs = {
'container':$("<p>"), // a dummy container
'column':columnDef,
'position':{'top':0, 'left':0}, // a dummy position required by some editors
'grid':_grid,
'event':e
};
var editor = new columnDef.editor(editorArgs);
if (columnDef && columnDef.editor) {
const tmpP = document.createElement('p');
const editor = new columnDef.editor({
container: tmpP, // a dummy container
column: columnDef,
event,
position: { top: 0, left: 0 }, // a dummy position required by some editors
grid: _grid,
});
editor.loadValue(item);
retVal = editor.serializeValue();
editor.destroy();
tmpP.remove();
} else {
retVal = item[columnDef.field];
retVal = item[columnDef.field || ''];
}

return retVal;
}

function setDataItemValueForColumn(item, columnDef, value) {
if (columnDef.denyPaste) { return null; }

if (_options.dataItemColumnValueSetter) {
return _options.dataItemColumnValueSetter(item, columnDef, value);
}

// if a custom setter is not defined, we call applyValue of the editor to unserialize
if (columnDef.editor){
var editorArgs = {
'container':$("body"), // a dummy container
'column':columnDef,
'position':{'top':0, 'left':0}, // a dummy position required by some editors
'grid':_grid
};
var editor = new columnDef.editor(editorArgs);
if (columnDef.editor) {
const tmpDiv = document.createElement('div');
const editor = new columnDef.editor({
container: tmpDiv, // a dummy container
column: columnDef,
position: { top: 0, left: 0 }, // a dummy position required by some editors
grid: _grid
});
editor.loadValue(item);
editor.applyValue(item, value);
editor.destroy();
tmpDiv.remove();
} else {
item[columnDef.field] = value;
}
Expand Down Expand Up @@ -455,7 +460,7 @@
_options.includeHeaderWhenCopying = includeHeaderWhenCopying;
}

$.extend(this, {
Slick.Utils.extend(this, {
"init": init,
"destroy": destroy,
"pluginName": "CellExternalCopyManager",
Expand All @@ -469,4 +474,4 @@
"setIncludeHeaderWhenCopying" : setIncludeHeaderWhenCopying
});
}
})(jQuery);
})(window);
18 changes: 11 additions & 7 deletions slick.editors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @namespace Slick
*/

(function () {
(function (window) {

const utils = Slick.Utils;

Expand Down Expand Up @@ -333,18 +333,20 @@

this.destroy = function () {
scope.hide();
flatpickrInstance.destroy();
if (flatpickrInstance) {
flatpickrInstance.destroy();
}
input.remove();
};

this.show = function () {
if (!args.compositeEditorOptions) {
if (!args.compositeEditorOptions && flatpickrInstance) {
flatpickrInstance.open();
}
};

this.hide = function () {
if (!args.compositeEditorOptions) {
if (!args.compositeEditorOptions && flatpickrInstance) {
flatpickrInstance.close();
}
};
Expand All @@ -358,7 +360,9 @@
input.value = defaultValue;
input.defaultValue = defaultValue;
input.select();
flatpickrInstance.setDate(defaultValue);
if (flatpickrInstance) {
flatpickrInstance.setDate(defaultValue);
}
};

this.serializeValue = function () {
Expand Down Expand Up @@ -776,7 +780,7 @@
}

// exports
utils.extend(true, window, {
Slick.Utils.extend(true, window, {
"Slick": {
"Editors": {
"Text": TextEditor,
Expand All @@ -790,4 +794,4 @@
}
}
});
})();
})(window);