also looking at this
Bluesky publishing v2: rich-text facets + image upload
#9
8 files
+347
-12
| @@ -59,8 +59,21 @@ | ||
| 59 | 59 | </div> |
| 60 | 60 | |
| 61 | 61 | <footer class="flex gap-3 items-center justify-between p-3 border-t border-zinc-200"> |
| 62 | <span class="text-xs text-zinc-500" data-bluesky-count>0 / 300 characters</span> | |
| 62 | <div class="flex gap-2 items-center min-w-0"> | |
| 63 | <span class="text-xs text-zinc-500 whitespace-nowrap" data-bluesky-count>0 / 300 characters</span> | |
| 64 | <span class="hidden gap-1.5 items-center px-2.5 max-w-48 min-h-7 font-bold text-xs text-zinc-600 bg-zinc-50 border border-zinc-200 rounded-lg" data-attach-chip> | |
| 65 | <span class="shrink-0 h-3.5 w-3.5 i-hugeicons-image-01" aria-hidden="true"></span> | |
| 66 | <span class="truncate" data-attach-name></span> | |
| 67 | <button class="inline-flex items-center justify-center shrink-0 h-4 w-4 text-zinc-500 hover:text-zinc-800 transition-colors" type="button" aria-label="Remove attached image" data-attach-clear> | |
| 68 | <span class="h-3 w-3 i-hugeicons-cancel-01" aria-hidden="true"></span> | |
| 69 | </button> | |
| 70 | </span> | |
| 71 | </div> | |
| 63 | 72 | <div class="flex flex-wrap gap-2 items-center justify-end"> |
| 73 | <input class="hidden" type="file" accept="image/png,image/jpeg,image/webp,image/gif" aria-label="Attach image" data-attach-input> | |
| 74 | <button class="inline-flex items-center justify-center h-9 w-9 text-neutral-950 bg-white hover:bg-zinc-50 border border-zinc-200 rounded-xl shadow-sm transition-colors" type="button" aria-label="Attach image" title="Attach image" data-attach-button> | |
| 75 | <span class="h-4 w-4 i-hugeicons-image-01" aria-hidden="true"></span> | |
| 76 | </button> | |
| 64 | 77 | <input class="hidden px-2 h-9 text-neutral-950 text-xs bg-white border border-zinc-200 outline-none rounded-xl focus:border-blue-500 focus:ring-2 focus:ring-blue-100" type="datetime-local" aria-label="Schedule time" data-compose-schedule> |
| 65 | 78 | <button class="inline-flex items-center justify-center h-9 w-9 text-neutral-950 bg-white hover:bg-zinc-50 border border-zinc-200 rounded-xl shadow-sm transition-colors" type="button" aria-label="Schedule post" title="Schedule post" data-schedule-toggle> |
| 66 | 79 | <span class="h-4 w-4 i-hugeicons-calendar-03" aria-hidden="true"></span> |
| @@ -101,6 +114,19 @@ | ||
| 101 | 114 | const composeImage = root.querySelector('[data-compose-image]') |
| 102 | 115 | const scheduleToggle = root.querySelector('[data-schedule-toggle]') |
| 103 | 116 | const scheduleInput = root.querySelector('[data-compose-schedule]') |
| 117 | const attachButton = root.querySelector('[data-attach-button]') | |
| 118 | const attachInput = root.querySelector('[data-attach-input]') | |
| 119 | const attachChip = root.querySelector('[data-attach-chip]') | |
| 120 | const attachName = root.querySelector('[data-attach-name]') | |
| 121 | const attachClear = root.querySelector('[data-attach-clear]') | |
| 122 | ||
| 123 | const attachedFile = () => attachInput?.files?.[0] || undefined | |
| 124 | ||
| 125 | const clearAttachment = () => { | |
| 126 | if (attachInput) attachInput.value = '' | |
| 127 | attachChip?.classList.add('hidden') | |
| 128 | attachChip?.classList.remove('inline-flex') | |
| 129 | } | |
| 104 | 130 | const postsRoot = root.querySelector('[data-composer-posts]') |
| 105 | 131 | const addPostButton = root.querySelector('[data-add-post]') |
| 106 | 132 | const previewButton = root.querySelector('[data-preview-post]') |
| @@ -568,7 +594,7 @@ | ||
| 568 | 594 | : undefined |
| 569 | 595 | const imageUrl = composeImage?.value.trim() |
| 570 | 596 | const image = imageUrl ? { url: imageUrl } : undefined |
| 571 | return await social.publishCrosspost({ text, providers: targetProviders, external, image }) | |
| 597 | return await social.publishCrosspost({ text, providers: targetProviders, external, image, imageFile: attachedFile() }) | |
| 572 | 598 | } |
| 573 | 599 | |
| 574 | 600 | const publish = async () => { |
| @@ -635,6 +661,7 @@ | ||
| 635 | 661 | providers: targetProviders, |
| 636 | 662 | external, |
| 637 | 663 | image: imageUrl ? { url: imageUrl } : undefined, |
| 664 | imageFile: attachedFile(), | |
| 638 | 665 | })) |
| 639 | 666 | } |
| 640 | 667 | else { |
| @@ -656,6 +683,7 @@ | ||
| 656 | 683 | |
| 657 | 684 | updateCount() |
| 658 | 685 | saveDraft() |
| 686 | clearAttachment() | |
| 659 | 687 | window.postlineToast?.dismiss?.('publish') |
| 660 | 688 | if (failures.length && successCount === 0) { |
| 661 | 689 | setStatus(`Publish failed — ${failures.join('; ')}`, 'error', { title: 'Publish failed' }) |
| @@ -723,6 +751,23 @@ | ||
| 723 | 751 | updatePublishLabel() |
| 724 | 752 | }) |
| 725 | 753 | scheduleInput?.addEventListener('input', updatePublishLabel) |
| 754 | attachButton?.addEventListener('click', () => attachInput?.click()) | |
| 755 | attachInput?.addEventListener('change', () => { | |
| 756 | const file = attachedFile() | |
| 757 | if (!file) { | |
| 758 | clearAttachment() | |
| 759 | return | |
| 760 | } | |
| 761 | if (file.size > 1_000_000) { | |
| 762 | clearAttachment() | |
| 763 | setStatus('Images must be 1MB or smaller for Bluesky.', 'error', { title: 'Attachment' }) | |
| 764 | return | |
| 765 | } | |
| 766 | if (attachName) attachName.textContent = file.name | |
| 767 | attachChip?.classList.remove('hidden') | |
| 768 | attachChip?.classList.add('inline-flex') | |
| 769 | }) | |
| 770 | attachClear?.addEventListener('click', clearAttachment) | |
| 726 | 771 | addPostButton?.addEventListener('click', addPost) |
| 727 | 772 | previewButton?.addEventListener('click', () => { |
| 728 | 773 | const text = activeTextarea()?.value.trim() |