From 8b1624f00365e8c8eeaebda98c3819a6adc692c6 Mon Sep 17 00:00:00 2001 From: edalzell Date: Tue, 18 Feb 2025 12:56:42 -0800 Subject: [PATCH 1/9] wip --- .../js/components/fieldtypes/LinkFieldtype.vue | 2 ++ .../components/fieldtypes/bard/LinkToolbar.vue | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/resources/js/components/fieldtypes/LinkFieldtype.vue b/resources/js/components/fieldtypes/LinkFieldtype.vue index 16f09af95a..4284dbd38e 100644 --- a/resources/js/components/fieldtypes/LinkFieldtype.vue +++ b/resources/js/components/fieldtypes/LinkFieldtype.vue @@ -34,6 +34,7 @@ @input="entriesSelected" @meta-updated="meta.entry.meta = $event" /> + + +
+ +
+
Date: Wed, 26 Feb 2025 12:20:29 -0800 Subject: [PATCH 2/9] wip --- src/Fieldtypes/Bard.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Fieldtypes/Bard.php b/src/Fieldtypes/Bard.php index d92c3bec0b..bd5ed765ea 100644 --- a/src/Fieldtypes/Bard.php +++ b/src/Fieldtypes/Bard.php @@ -38,7 +38,9 @@ class Bard extends Replicator ]; protected $categories = ['text', 'structured']; + protected $keywords = ['rich', 'richtext', 'rich text', 'editor', 'wysiwg', 'builder', 'page builder', 'gutenberg', 'content']; + protected $rules = []; protected function configFieldItems(): array @@ -713,7 +715,9 @@ private function getLinkDataForUrl($url) switch ($type) { case 'entry': - if ($entry = Entry::find($id)) { + $actualId = str($id)->before('#')->before('?')->before('&'); + + if ($entry = Entry::find($actualId->toString())) { $data = [ 'title' => $entry->get('title'), 'permalink' => $entry->absoluteUrl(), From 7f59104147151d5bf2050300999617b689af1797 Mon Sep 17 00:00:00 2001 From: Erin Dalzell Date: Thu, 6 Mar 2025 10:01:11 -0800 Subject: [PATCH 3/9] Discard changes to resources/js/components/fieldtypes/LinkFieldtype.vue --- resources/js/components/fieldtypes/LinkFieldtype.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources/js/components/fieldtypes/LinkFieldtype.vue b/resources/js/components/fieldtypes/LinkFieldtype.vue index 4284dbd38e..16f09af95a 100644 --- a/resources/js/components/fieldtypes/LinkFieldtype.vue +++ b/resources/js/components/fieldtypes/LinkFieldtype.vue @@ -34,7 +34,6 @@ @input="entriesSelected" @meta-updated="meta.entry.meta = $event" /> - Date: Thu, 6 Mar 2025 11:41:59 -0800 Subject: [PATCH 4/9] better --- .../fieldtypes/bard/LinkToolbar.vue | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/resources/js/components/fieldtypes/bard/LinkToolbar.vue b/resources/js/components/fieldtypes/bard/LinkToolbar.vue index d47597a394..01b7bc3034 100644 --- a/resources/js/components/fieldtypes/bard/LinkToolbar.vue +++ b/resources/js/components/fieldtypes/bard/LinkToolbar.vue @@ -225,7 +225,7 @@ export default { url: {}, urlData: {}, itemData: {}, - append: null, + appends: null, title: null, rel: null, targetBlank: null, @@ -371,10 +371,10 @@ export default { applyAttrs(attrs) { this.linkType = this.getLinkTypeForUrl(attrs.href); - this.url = { [this.linkType]: attrs.href }; + this.appends = this.getAppendsForUrl(attrs.href); + this.url = { [this.linkType]: attrs.href.replace(this.appends, '' ) }; this.urlData = { [this.linkType]: this.getUrlDataForUrl(attrs.href) }; this.itemData = { [this.linkType]: this.getItemDataForUrl(attrs.href) }; - this.title = attrs.title; this.rel = attrs.href ? attrs.rel @@ -521,14 +521,26 @@ export default { return this.bard.meta.linkData[ref]; }, + getAppendsForUrl(urlString) { + const url = URL.parse(urlString.replace('statamic://','')); + const queryParams = url.searchParams.toString(); + + if (queryParams) { + return `?${queryParams}${url.hash}`; + }; + + return url.hash; + }, + parseDataUrl(url) { if (! url) { return {} } + const appends = this.getAppendsForUrl(url); const regex = /^statamic:\/\/((.*?)::(.*))$/; - const matches = url.match(regex); + const matches = url.replace(appends, '').match(regex); if (! matches) { return {}; } From 8f4a1cf6294b1472eca2f60907010d30f1763d55 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 6 Mar 2025 12:02:49 -0800 Subject: [PATCH 5/9] handle initial states --- resources/js/components/fieldtypes/bard/LinkToolbar.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/js/components/fieldtypes/bard/LinkToolbar.vue b/resources/js/components/fieldtypes/bard/LinkToolbar.vue index 01b7bc3034..dbbec827b9 100644 --- a/resources/js/components/fieldtypes/bard/LinkToolbar.vue +++ b/resources/js/components/fieldtypes/bard/LinkToolbar.vue @@ -372,7 +372,7 @@ export default { this.linkType = this.getLinkTypeForUrl(attrs.href); this.appends = this.getAppendsForUrl(attrs.href); - this.url = { [this.linkType]: attrs.href.replace(this.appends, '' ) }; + this.url = { [this.linkType]: attrs.href?.replace(this.appends, '' ) }; this.urlData = { [this.linkType]: this.getUrlDataForUrl(attrs.href) }; this.itemData = { [this.linkType]: this.getItemDataForUrl(attrs.href) }; this.title = attrs.title; @@ -522,6 +522,10 @@ export default { }, getAppendsForUrl(urlString) { + if (! urlString) { + return null; + } + const url = URL.parse(urlString.replace('statamic://','')); const queryParams = url.searchParams.toString(); From 6843e9e42ac1e01dcbcbd6a54156e259947da6ba Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 6 Mar 2025 12:17:14 -0800 Subject: [PATCH 6/9] only useful on entry links --- resources/js/components/fieldtypes/bard/LinkToolbar.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/components/fieldtypes/bard/LinkToolbar.vue b/resources/js/components/fieldtypes/bard/LinkToolbar.vue index dbbec827b9..e7efd35371 100644 --- a/resources/js/components/fieldtypes/bard/LinkToolbar.vue +++ b/resources/js/components/fieldtypes/bard/LinkToolbar.vue @@ -522,7 +522,7 @@ export default { }, getAppendsForUrl(urlString) { - if (! urlString) { + if (! urlString?.includes('statamic://entry::')) { return null; } From 7544f8be9918bf45181b081902e8ec7166de5680 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 6 Mar 2025 14:08:22 -0800 Subject: [PATCH 7/9] wangjangle that pesky url --- .../js/components/fieldtypes/bard/BardFieldtype.vue | 2 ++ .../js/components/fieldtypes/bard/LinkToolbar.vue | 11 +++-------- src/Fieldtypes/Bard.php | 5 ++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/resources/js/components/fieldtypes/bard/BardFieldtype.vue b/resources/js/components/fieldtypes/bard/BardFieldtype.vue index 2e7c1b96dc..88afacea28 100644 --- a/resources/js/components/fieldtypes/bard/BardFieldtype.vue +++ b/resources/js/components/fieldtypes/bard/BardFieldtype.vue @@ -277,6 +277,8 @@ export default { htmlWithReplacedLinks() { return this.html.replaceAll(/\"statamic:\/\/(.*?)\"/g, (match, ref) => { + // Get everything in the "ref" string before a ? or #. + ref = ref.split(/[?#]/)[0] const linkData = this.meta.linkData[ref]; if (! linkData) { this.$toast.error(`${__('No link data found for')} ${ref}`); diff --git a/resources/js/components/fieldtypes/bard/LinkToolbar.vue b/resources/js/components/fieldtypes/bard/LinkToolbar.vue index e7efd35371..e9a0b5bbab 100644 --- a/resources/js/components/fieldtypes/bard/LinkToolbar.vue +++ b/resources/js/components/fieldtypes/bard/LinkToolbar.vue @@ -522,18 +522,13 @@ export default { }, getAppendsForUrl(urlString) { + + // appends is only relevant to entry links if (! urlString?.includes('statamic://entry::')) { return null; } - const url = URL.parse(urlString.replace('statamic://','')); - const queryParams = url.searchParams.toString(); - - if (queryParams) { - return `?${queryParams}${url.hash}`; - }; - - return url.hash; + return urlString.replace(urlString.split(/[?#]/)[0], ''); }, parseDataUrl(url) { diff --git a/src/Fieldtypes/Bard.php b/src/Fieldtypes/Bard.php index bd5ed765ea..88e105ebfb 100644 --- a/src/Fieldtypes/Bard.php +++ b/src/Fieldtypes/Bard.php @@ -715,9 +715,8 @@ private function getLinkDataForUrl($url) switch ($type) { case 'entry': - $actualId = str($id)->before('#')->before('?')->before('&'); - - if ($entry = Entry::find($actualId->toString())) { + $ref = str($ref)->before('?')->before('#')->toString(); + if ($entry = Entry::find(str($ref)->after('entry::')->toString())) { $data = [ 'title' => $entry->get('title'), 'permalink' => $entry->absoluteUrl(), From 4c67efa99b8667c405337f86c3abe7799e9252a9 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 6 Mar 2025 14:10:38 -0800 Subject: [PATCH 8/9] tidy --- src/Fieldtypes/Bard.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Fieldtypes/Bard.php b/src/Fieldtypes/Bard.php index 88e105ebfb..1b0c6f7d1a 100644 --- a/src/Fieldtypes/Bard.php +++ b/src/Fieldtypes/Bard.php @@ -708,15 +708,15 @@ private function extractLinkDataFromNode($node) private function getLinkDataForUrl($url) { - $ref = Str::after($url, 'statamic://'); + $ref = str($url)->after('statamic://'); [$type, $id] = explode('::', $ref, 2); $data = null; switch ($type) { case 'entry': - $ref = str($ref)->before('?')->before('#')->toString(); - if ($entry = Entry::find(str($ref)->after('entry::')->toString())) { + $ref = $ref->before('?')->before('#'); + if ($entry = Entry::find($ref->after('entry::'))) { $data = [ 'title' => $entry->get('title'), 'permalink' => $entry->absoluteUrl(), @@ -733,7 +733,7 @@ private function getLinkDataForUrl($url) break; } - return [$ref => $data]; + return [$ref->toString() => $data]; } private function wrapInlineValue($value) From 07baaa7ab7f4969fc905ceaf15f6b33ed6bf15b0 Mon Sep 17 00:00:00 2001 From: edalzell Date: Thu, 6 Mar 2025 14:36:36 -0800 Subject: [PATCH 9/9] deal w/ null --- resources/js/components/fieldtypes/bard/LinkToolbar.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/resources/js/components/fieldtypes/bard/LinkToolbar.vue b/resources/js/components/fieldtypes/bard/LinkToolbar.vue index e9a0b5bbab..af8175a750 100644 --- a/resources/js/components/fieldtypes/bard/LinkToolbar.vue +++ b/resources/js/components/fieldtypes/bard/LinkToolbar.vue @@ -327,7 +327,11 @@ export default { watch: { - linkType() { + linkType(type) { + if (type != 'entry') { + this.appends = null; + } + this.autofocus(); }, @@ -418,7 +422,7 @@ export default { } this.$emit('updated', { - href: `${this.href}${this.appends}`, + href: this.href + (this.appends ?? ''), rel: this.rel, target: (this.canHaveTarget && this.targetBlank) ? '_blank' : null, title: this.title,