-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Cowen <john.cowen@konghq.com>
- Loading branch information
Showing
11 changed files
with
169 additions
and
119 deletions.
There are no files selected for viewing
28 changes: 0 additions & 28 deletions
28
src/app/application/components/debug-k-clipboard-provider/DebugKClipboardProvider.vue
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/app/application/components/debug-k-clipboard-provider/README.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,12 @@ | ||
<template> | ||
<div class="copy-button-wrapper"> | ||
<span class="text"><slot>{{ props.text }}</slot></span> | ||
|
||
<KCopy | ||
format="hidden" | ||
:text="props.text" | ||
/> | ||
</div> | ||
<XCopy | ||
format="custom" | ||
:text="props.text" | ||
/> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
const props = defineProps<{ | ||
text: string | ||
}>() | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.copy-button-wrapper { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: $kui-space-40; | ||
} | ||
.text { | ||
min-width: 0; | ||
word-wrap: break-word; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# x-copy | ||
|
||
## x-copy-debug | ||
|
||
Wraps XCopy in a decorator to also `console.log` the text of any | ||
copy (but not `console.error` the text if the copy fails). | ||
|
||
The component should always be injected as a replacement for XCopy | ||
in debug/dev modes only and never used directly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<template> | ||
<div | ||
class="x-copy" | ||
> | ||
<span | ||
v-if="props.format === 'custom' && props.text" | ||
class="text" | ||
> | ||
<slot | ||
name="default" | ||
> | ||
{{ props.text }} | ||
</slot> | ||
</span> | ||
<KCopy | ||
v-bind="attrs" | ||
ref="component" | ||
:class="{ | ||
'hidden': props.text.length === 0, | ||
}" | ||
:aria-hidden="props.text.length === 0" | ||
:format="props.format === 'custom' ? 'hidden' : props.format" | ||
:text="props.text.length === 0 ? _text : props.text" | ||
/> | ||
<slot | ||
v-if="copy && props.text.length === 0" | ||
name="default" | ||
:copy="copy" | ||
/> | ||
</div> | ||
</template> | ||
<script lang="ts" setup> | ||
import { KCopy } from '@kong/kongponents' | ||
import { ref, nextTick, useAttrs } from 'vue' | ||
type KCopyT = InstanceType<typeof KCopy> | ||
type Format = KCopyT['$props']['format'] | ||
const attrs = useAttrs() | ||
const component = ref<KCopyT | null>(null) | ||
const _text = ref() | ||
const copy = async (text: string) => { | ||
_text.value = text | ||
await nextTick() | ||
component.value!.copy() | ||
} | ||
const props = withDefaults(defineProps<{ | ||
text?: string | ||
format?: Format | 'custom' | ||
}>(), { | ||
text: '', | ||
format: 'custom', | ||
}) | ||
</script> | ||
<style lang="scss" scoped> | ||
.hidden { | ||
display: none; | ||
} | ||
.x-copy { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: $kui-space-40; | ||
} | ||
.text { | ||
min-width: 0; | ||
word-wrap: break-word; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<template> | ||
<CopyButton | ||
:text="props.text" | ||
@mouseup="(e) => { | ||
createCopy(() => {})(props.text) | ||
}" | ||
> | ||
<template | ||
#default="{ copy }" | ||
> | ||
<slot | ||
name="default" | ||
:copy="createCopy(copy)" | ||
/> | ||
</template> | ||
</CopyButton> | ||
</template> | ||
<script lang="ts" setup> | ||
import CopyButton from '@/app/x/components/x-copy/XCopy.vue' | ||
const props = withDefaults(defineProps<{ | ||
text?: '' | ||
}>(), { | ||
text: '', | ||
}) | ||
const createCopy = (copy: (text: string) => void) => (text: string) => { | ||
console.info( | ||
'%cdebug-k-clipboard-provider: The following was copied to the clipboard:', 'color: blue', | ||
` | ||
${text}`, | ||
) | ||
try { | ||
// KCopy gives us no way to detect an error | ||
// so this should never throw unless there is an error with the code | ||
copy(text) | ||
} catch (e) { | ||
console.error( | ||
'debug-k-clipboard-provider: The following wasn\'t copied to the clipboard:', | ||
` | ||
${text}`, | ||
) | ||
console.error(e) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters