Skip to content

Commit

Permalink
fix(context): change copy cell command to make it work in SF (#8)
Browse files Browse the repository at this point in the history
- also simplified the code a lot with this new approach
  • Loading branch information
ghiscoding authored Jul 9, 2020
1 parent eb8aee7 commit c0b8ad9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 40 deletions.
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,7 @@ npm run test:watch
- [x] Row Selection
- [x] Grouping Formatters (12)
- [x] SortComparers (5)
- [ ] Services
- [x] Collection
- [x] Excel Export (**separate package**)
- [x] Export Text (**separate package**)
- [x] Extension
- [x] Filter
- [x] GraphQL (**separate package**)
- [x] OData (**separate package**)
- [x] Grid Event
- [x] Grid Service (helper)
- [x] Grid State
- [x] Grouping & Col Span
- [x] Pagination
- [ ] Resizer
- moved the Service to an Extension
- [x] Shared
- [x] Sort
- [x] Services (14)
- [ ] Others / Vanilla Implementation
- [x] Custom Footer
- [x] Backend Services + Pagination
Expand Down Expand Up @@ -161,5 +145,5 @@ npm run test:watch
- [x] Add possibility to use SVG instead of Font Family
- [x] Add Typings (interfaces) for Slick Grid & DataView objects
- [x] Add interfaces to all SlickGrid core lib classes & plugins (basically add Types to everything)
- [ ] Copy text from cell doesn't work in SF
- [x] Copy text from cell doesn't work in SF
- [ ] Remove all Services init method 2nd argument (we can get DataView directly from the Grid object)
27 changes: 10 additions & 17 deletions packages/common/src/extensions/contextMenuExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class ContextMenuExtension implements Extension {
disabled: false,
command: commandName,
positionOrder: 50,
action: (e: Event, args: MenuCommandItemCallbackArgs) => {
action: (_e: Event, args: MenuCommandItemCallbackArgs) => {
this.copyToClipboard(args);
},
itemUsabilityOverride: (args: MenuCallbackArgs) => {
Expand Down Expand Up @@ -409,25 +409,18 @@ export class ContextMenuExtension implements Extension {
const exportOptions = gridOptions && (gridOptions.excelExportOptions || gridOptions.exportOptions);
const textToCopy = exportWithFormatterWhenDefined(row, cell, dataContext, column, grid, exportOptions);

// create fake <div> to copy into clipboard & delete it from the DOM once we're done
const range = document.createRange();
const tmpElem = document.createElement('div') as HTMLDivElement;
const body = document.querySelector('body') as HTMLElement;
if (tmpElem && body) {
// create fake <textarea> (positioned outside of the screen) to copy into clipboard & delete it from the DOM once we're done
const tmpElem = document.createElement('textarea') as HTMLTextAreaElement;
if (tmpElem && document.body) {
tmpElem.style.position = 'absolute';
tmpElem.style.left = '-1000px';
tmpElem.style.top = '-1000px';
tmpElem.textContent = textToCopy;
body.appendChild(tmpElem);
range.selectNodeContents(tmpElem);
const selection = window.getSelection();
if (selection && selection.addRange && selection.removeAllRanges) {
selection.removeAllRanges();
selection.addRange(range);
const success = document.execCommand('copy', false, textToCopy);
if (success) {
tmpElem.remove();
}
tmpElem.value = textToCopy;
document.body.appendChild(tmpElem);
tmpElem.select();
const success = document.execCommand('copy', false, textToCopy);
if (success) {
tmpElem.remove();
}
}
}
Expand Down
Binary file not shown.
3 changes: 0 additions & 3 deletions packages/vanilla-bundle/src/salesforce-global-grid-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export const SalesforceGlobalGridOptions: GridOption = {
exportOptions: {
exportWithFormatter: true
},
contextMenu: {
hideCopyCellValueCommand: true
},
enableCellNavigation: true,
formatterOptions: {
minDecimal: 0,
Expand Down
4 changes: 2 additions & 2 deletions packages/web-demo-vanilla-bundle/src/examples/example01.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class Example1 {
{ id: 'title', name: 'Title', field: 'title', sortable: true, minWidth: 100, filterable: true },
{ id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true, minWidth: 100, filterable: true },
{ id: '%', name: '% Complete', field: 'percentComplete', sortable: true, minWidth: 100, filterable: true },
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso, filterable: true },
{ id: 'finish', name: 'Finish', field: 'finish', formatter: Formatters.dateIso, filterable: true },
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso, exportWithFormatter: true, filterable: true },
{ id: 'finish', name: 'Finish', field: 'finish', formatter: Formatters.dateIso, exportWithFormatter: true, filterable: true },
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', sortable: true, minWidth: 100, filterable: true }
];
this.gridOptions1 = {
Expand Down

0 comments on commit c0b8ad9

Please sign in to comment.