fix: Web Share Target text field merge (#1572)
Co-authored-by: userquin <userquin@gmail.com>zio/stable
parent
6eedaa98bc
commit
faa96c7705
|
@ -111,10 +111,16 @@ useWebShareTarget(async ({ data: { data, action } }: any) => {
|
||||||
|
|
||||||
editor.value?.commands.focus('end')
|
editor.value?.commands.focus('end')
|
||||||
|
|
||||||
if (data.text !== undefined)
|
for (const text of data.textParts) {
|
||||||
editor.value?.commands.insertContent(data.text)
|
for (const line of text.split('\n')) {
|
||||||
|
editor.value?.commands.insertContent({
|
||||||
|
type: 'paragraph',
|
||||||
|
content: [{ type: 'text', text: line }],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (data.files !== undefined)
|
if (data.files.length !== 0)
|
||||||
await uploadAttachments(data.files)
|
await uploadAttachments(data.files)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ interface ExtendedManifestOptions extends ManifestOptions {
|
||||||
method: string
|
method: string
|
||||||
enctype: string
|
enctype: string
|
||||||
params: {
|
params: {
|
||||||
|
title: string
|
||||||
text: string
|
text: string
|
||||||
url: string
|
url: string
|
||||||
files: [{
|
files: [{
|
||||||
|
@ -104,8 +105,9 @@ export const createI18n = async (): Promise<LocalizedWebManifest> => {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
enctype: 'multipart/form-data',
|
enctype: 'multipart/form-data',
|
||||||
params: {
|
params: {
|
||||||
|
title: 'title',
|
||||||
text: 'text',
|
text: 'text',
|
||||||
url: 'text',
|
url: 'url',
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
name: 'files',
|
name: 'files',
|
||||||
|
@ -150,8 +152,9 @@ export const createI18n = async (): Promise<LocalizedWebManifest> => {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
enctype: 'multipart/form-data',
|
enctype: 'multipart/form-data',
|
||||||
params: {
|
params: {
|
||||||
|
title: 'title',
|
||||||
text: 'text',
|
text: 'text',
|
||||||
url: 'text',
|
url: 'url',
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
name: 'files',
|
name: 'files',
|
||||||
|
|
|
@ -32,21 +32,30 @@ async function handleSharedTarget(event: FetchEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendShareTargetMessage(client: Client, data: FormData) {
|
async function sendShareTargetMessage(client: Client, data: FormData) {
|
||||||
const sharedData: { text?: string; files?: File[] } = {}
|
const sharedData: { textParts: string[]; files: File[] } = {
|
||||||
|
textParts: [],
|
||||||
|
files: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
// We collect the text data shared with us
|
||||||
|
const title = data.get('title')
|
||||||
|
if (title !== null)
|
||||||
|
sharedData.textParts.push(title.toString())
|
||||||
|
|
||||||
const text = data.get('text')
|
const text = data.get('text')
|
||||||
if (text !== null)
|
if (text !== null)
|
||||||
sharedData.text = text.toString()
|
sharedData.textParts.push(text.toString())
|
||||||
|
|
||||||
const files: File[] = []
|
const link = data.get('link')
|
||||||
|
if (link !== null)
|
||||||
|
sharedData.textParts.push(link.toString())
|
||||||
|
|
||||||
|
// We collect the files shared with us
|
||||||
for (const [name, file] of data.entries()) {
|
for (const [name, file] of data.entries()) {
|
||||||
if (name === 'files' && file instanceof File)
|
if (name === 'files' && file instanceof File)
|
||||||
files.push(file)
|
sharedData.files.push(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (files.length !== 0)
|
|
||||||
sharedData.files = files
|
|
||||||
|
|
||||||
client.postMessage({ data: sharedData, action: 'compose-with-shared-data' })
|
client.postMessage({ data: sharedData, action: 'compose-with-shared-data' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue