diff --git a/_layouts/fomantic.liquid b/_layouts/fomantic.liquid index 53960d28..33c420c5 100644 --- a/_layouts/fomantic.liquid +++ b/_layouts/fomantic.liquid @@ -128,7 +128,9 @@ diff --git a/playground/next/editor.mjs b/playground/next/editor.mjs index 10cdc8c5..48466a4d 100644 --- a/playground/next/editor.mjs +++ b/playground/next/editor.mjs @@ -319,6 +319,7 @@ window.app = createApp({ }, remoteDocURL: '', remoteSideDocURL: '', + message: {type: '', text: ''}, parseError: '', inputTab: 'json-ld', outputTab: 'expanded', @@ -349,6 +350,20 @@ window.app = createApp({ } return ''; }, + get permalinkURL() { + const url = new URL(window.location); + const hash = new URLSearchParams(); + hash.set('json-ld', JSON.stringify(this.doc)); + if (this.contextDoc && JSON.stringify(this.contextDoc) !== '{}') { + hash.set('context', JSON.stringify(this.contextDoc)); + } + if (this.frameDoc && JSON.stringify(this.frameDoc) !== '{}') { + hash.set('frame', JSON.stringify(this.frameDoc)); + } + hash.set('startTab', `tab-${this.outputTab}`); + url.hash = hash.toString(); + return url.toString(); + }, get sideDoc() { if (this.outputTab === 'framed') { return 'frameDoc'; @@ -370,6 +385,14 @@ window.app = createApp({ return 'Context URL'; } }, + copyPermalink() { + const url = this.permalinkURL; + navigator.clipboard.writeText(url).then(() => { + console.log('Permalink copied to clipboard:', url); + }).catch(err => { + console.error('Failed to copy permalink:', err); + }); + }, // methods async retrieveDoc(_editor, docVar, url) { try { @@ -539,5 +562,26 @@ window.app = createApp({ '@context': this.doc['@context'] }; setEditorValue(this.contextEditor, this.contextDoc); + }, + async gatherHash() { + const url = new URL(window.location); + const hash = new URLSearchParams(url?.hash.slice(1)); + this.contextDoc = JSON.parse(hash.get('context')) || {}; + setEditorValue(this.contextEditor, this.contextDoc); + this.frameDoc = JSON.parse(hash.get('frame')) || {}; + setEditorValue(this.frameEditor, this.frameDoc); + // the `json-ld` parameter can be JSON or a URL + const jsonLdOrUrl = hash.get('json-ld'); + try { + this.doc = JSON.parse(jsonLdOrUrl); + setEditorValue(this.mainEditor, this.doc); + } catch { + this.remoteDocURL = jsonLdOrUrl; + await this.retrieveDoc(this.mainEditor, 'doc', this.remoteDocURL); + } + if (hash.get('copyContext') === 'true') { + this.copyContext(); + } + this.outputTab = hash.get('startTab')?.slice(4); } }).mount(); diff --git a/playground/next/index.html b/playground/next/index.html index b12308c0..b6fdb2e8 100644 --- a/playground/next/index.html +++ b/playground/next/index.html @@ -20,8 +20,7 @@

JSON-LD Playground

  • Other related playgrounds: - Classic JSON-LD 1.0 Playground | - RDF Distiller | + Classic JSON-LD 1.0 Playground | Verifiable Credentials Playground
  • @@ -29,7 +28,7 @@

    JSON-LD Playground

    Shift+Tab) to navigate out of the editor.

    -
    +
    - -