Skip to content

Commit

Permalink
Merge pull request #497 from awcodes/fix/links-in-blocks
Browse files Browse the repository at this point in the history
Fix: links not working with multiple instance in block modal
  • Loading branch information
awcodes authored Nov 18, 2024
2 parents 11134e3 + 6c3cb23 commit e3bab9a
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 232 deletions.
346 changes: 171 additions & 175 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/dist/filament-tiptap-editor.css

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions resources/dist/filament-tiptap-editor.js

Large diffs are not rendered by default.

29 changes: 2 additions & 27 deletions resources/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ export default function tiptap({
return extensions;
},
init: function() {
this.modalId = this.$el.closest('[x-ref="modalContainer"]')?.getAttribute('wire:key');

let existing = this.$refs.element.querySelector('.tiptap');
if (existing) {
existing.remove();
Expand Down Expand Up @@ -348,22 +346,9 @@ export default function tiptap({
});
}
},
onCreate({editor}) {
if (
_this.$store.previous &&
editor.commands.getStatePath() === _this.$store.previous.statePath
) {
editor.chain().focus()
.setContent(_this.$store.previous.editor.getJSON())
.setTextSelection(_this.$store.previous.editor.state.selection)
.run();

_this.updatedAt = Date.now();
}
},
onUpdate({editor}) {
_this.updatedAt = Date.now();
_this.state = editor.isEmpty ? null : editor.getJSON();
_this.updatedAt = Date.now();
},
onSelectionUpdate() {
_this.updatedAt = Date.now();
Expand All @@ -377,16 +362,6 @@ export default function tiptap({
});
}
},
handleOpenModal() {
if (!this.modalId) return;

this.$nextTick(() => {
this.$store.previous = {
statePath: this.statePath,
editor: editor
};
})
},
isActive(type, opts = {}) {
return editor.isActive(type, opts)
},
Expand Down Expand Up @@ -533,7 +508,7 @@ export default function tiptap({
editor
.chain()
.focus()
.extendMarkRange('link')
.setTextSelection({from: link.coordinates[0].$from.pos, to: link.coordinates[0].$to.pos})
.setLink({
href: link.href,
id: link.id ?? null,
Expand Down
1 change: 1 addition & 0 deletions resources/views/components/tools/link.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
referrerpolicy: link.referrerpolicy || null,
as_button: link.as_button || null,
button_theme: link.button_theme || null,
coordinates: this.editor().view.state.selection.ranges,
};
$wire.dispatchFormEvent('tiptap::setLinkContent', '{{ $statePath }}', arguments);
Expand Down
1 change: 0 additions & 1 deletion resources/views/tiptap-editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class="relative z-0 tiptap-wrapper rounded-md bg-white dark:bg-gray-900 focus-wi
x-on:update-block.window="updateBlock($event)"
x-on:open-block-settings.window="openBlockSettings($event)"
x-on:delete-block.window="deleteBlock()"
x-on:open-modal.window="handleOpenModal()"
x-on:locale-change.window="updateLocale($event)"
x-trap.noscroll="fullScreenMode"
>
Expand Down
3 changes: 2 additions & 1 deletion src/Actions/LinkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function setUp(): void
'accent' => trans('filament-tiptap-editor::link-modal.labels.button_theme.accent'),
]),
]),
])->action(function (TiptapEditor $component, $data) {
])->action(function (TiptapEditor $component, $data, $arguments) {
$component->getLivewire()->dispatch(
event: 'insertFromAction',
type: 'link',
Expand All @@ -93,6 +93,7 @@ protected function setUp(): void
referrerpolicy: $data['referrerpolicy'],
as_button: $data['as_button'],
button_theme: $data['as_button'] ? $data['button_theme'] : '',
coordinates: $arguments['coordinates'],
);

$component->state($component->getState());
Expand Down

0 comments on commit e3bab9a

Please sign in to comment.