Browse Source

feat: paste option in cell right click context menu

pull/7207/head
Ramesh Mane 11 months ago
parent
commit
a337870be0
  1. 17
      packages/nc-gui/components/smartsheet/grid/Table.vue
  2. 28
      packages/nc-gui/composables/usePaste.ts
  3. 5
      packages/nc-gui/lang/en.json
  4. 1
      packages/nc-gui/utils/iconUtils.ts

17
packages/nc-gui/components/smartsheet/grid/Table.vue

@ -41,6 +41,7 @@ import {
useViewColumnsOrThrow,
useViewsStore,
watch,
usePaste,
} from '#imports'
import type { CellRange, Row } from '#imports'
@ -168,6 +169,8 @@ const predictNextFormulas = async () => {
await _predictNextFormulas(meta)
}
const { paste } = usePaste()
// #Refs
const rowRefs = ref<any[]>()
@ -1694,6 +1697,20 @@ onKeyStroke('ArrowDown', onDown)
</div>
</NcMenuItem>
<NcMenuItem
v-if="contextMenuTarget"
class="nc-base-menu-item"
data-testid="context-menu-item-paste"
:disabled="isSystemColumn(fields[contextMenuTarget.col])"
@click="paste"
>
<div v-e="['a:row:paste']" class="flex gap-2 items-center">
<GeneralIcon icon="paste" />
<!-- Paste -->
{{ $t('general.paste') }}
</div>
</NcMenuItem>
<!-- Clear cell -->
<NcMenuItem
v-if="

28
packages/nc-gui/composables/usePaste.ts

@ -0,0 +1,28 @@
export const usePaste = () => {
const paste = async (): Promise<boolean> => {
try {
// Check if the Clipboard API is supported
if (!navigator.clipboard) return false
// Read text from the clipboard
const clipboardText = await navigator.clipboard.readText()
// Create a new paste event
const pasteEvent = new Event('paste')
// Attach clipboard data to the event
const clipboardData = {
getData: () => clipboardText || '',
}
Object.defineProperty(pasteEvent, 'clipboardData', { value: clipboardData })
// Dispatch the event on the document or any other target element
document.dispatchEvent(pasteEvent)
return true
} catch (e) {
return false
}
}
return { paste }
}

5
packages/nc-gui/lang/en.json

@ -188,7 +188,8 @@
"useSurveyMode": "Use Survey Mode",
"shift": "Shift",
"enter": "Enter",
"seconds": "Seconds"
"seconds": "Seconds",
"paste": "Paste"
},
"objects": {
"workspace": "Workspace",
@ -1342,4 +1343,4 @@
"roleUpdated": "Role updated successfully"
}
}
}
}

1
packages/nc-gui/utils/iconUtils.ts

@ -452,6 +452,7 @@ export const iconMap = {
role_no_access: NoAccess,
commentHere: NcCommentHere,
fileImage: FileImageIcon,
paste: h('span', { class: 'material-symbols' }, 'content_paste'),
}
export const getMdiIcon = (type: string): any => {

Loading…
Cancel
Save