Skip to content

Commit e0c1cac

Browse files
committed
Add permalink popup & copy button.
1 parent 30abe17 commit e0c1cac

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

playground/next/editor.bundle.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39775,6 +39775,22 @@ ${O$2.repeat(r.depth)}}`:r.close="}";break}case f$4.TAG:e+=String(i),e+=a(f$4.PO
3977539775
}
3977639776
return '';
3977739777
},
39778+
get permalinkURL() {
39779+
const url = new URL(window.location);
39780+
const hash = new URLSearchParams();
39781+
hash.set('json-ld', JSON.stringify(this.doc));
39782+
hash.set('startTab', `tab-${this.outputTab}`);
39783+
url.hash = hash.toString();
39784+
return url.toString();
39785+
},
39786+
copyPermalink() {
39787+
const url = this.permalinkURL;
39788+
navigator.clipboard.writeText(url).then(() => {
39789+
console.log('Permalink copied to clipboard:', url);
39790+
}).catch(err => {
39791+
console.error('Failed to copy permalink:', err);
39792+
});
39793+
},
3977839794
get sideDoc() {
3977939795
if (this.outputTab === 'framed') {
3978039796
return 'frameDoc';

playground/next/editor.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ window.app = createApp({
348348
}
349349
return '';
350350
},
351+
get permalinkURL() {
352+
const url = new URL(window.location);
353+
const hash = new URLSearchParams();
354+
hash.set('json-ld', JSON.stringify(this.doc));
355+
hash.set('startTab', `tab-${this.outputTab}`);
356+
url.hash = hash.toString();
357+
return url.toString();
358+
},
351359
get sideDoc() {
352360
if (this.outputTab === 'framed') {
353361
return 'frameDoc';
@@ -369,6 +377,14 @@ window.app = createApp({
369377
return 'Context URL';
370378
}
371379
},
380+
copyPermalink() {
381+
const url = this.permalinkURL;
382+
navigator.clipboard.writeText(url).then(() => {
383+
console.log('Permalink copied to clipboard:', url);
384+
}).catch(err => {
385+
console.error('Failed to copy permalink:', err);
386+
});
387+
},
372388
// methods
373389
async retrieveDoc(_editor, docVar, url) {
374390
try {

playground/next/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ <h2 class="ui massive header">JSON-LD Playground</h2>
7070
</div>
7171

7272
<div class="ui right floated buttons">
73+
<button id="permalink" class="ui icon button" data-position="left center">
74+
<i class="icon linkify"></i>
75+
</button>
76+
<div class="ui popup" style="min-width: 20em;">
77+
<div class="ui top attached label">Share this</div>
78+
<div class="ui fluid action input">
79+
<input type="text" readonly v-model="permalinkURL" @focus="$event.target.select()">
80+
<button class="ui icon button" @click="copyPermalink()">
81+
<i class="icon copy"></i>
82+
</button>
83+
</div>
84+
</div>
7385
<button id="keyboard-shortcuts" class="ui icon button" data-position="left center">
7486
<i class="icon keyboard"></i>
7587
</button>

0 commit comments

Comments
 (0)