diff --git a/src/SharedStyles.js b/src/SharedStyles.js index 990db0da..2170ba44 100644 --- a/src/SharedStyles.js +++ b/src/SharedStyles.js @@ -149,6 +149,14 @@ export const sharedStyles = css` cursor: pointer; } + .linkicon { + --md-icon-size: 15px; + margin-right: 8px; + position: relative; + bottom: -1px; + opacity: 0.7; + } + .nopointer { pointer-events: none; } diff --git a/src/components/GrampsjsAttributes.js b/src/components/GrampsjsAttributes.js index e72fbbdd..2cd97b04 100644 --- a/src/components/GrampsjsAttributes.js +++ b/src/components/GrampsjsAttributes.js @@ -1,4 +1,4 @@ -import {html} from 'lit' +import {html, css} from 'lit' import {GrampsjsEditableList} from './GrampsjsEditableList.js' import './GrampsjsFormEditAttribute.js' @@ -7,9 +7,24 @@ import '@material/mwc-icon-button' import '@material/mwc-list' import '@material/mwc-list/mwc-list-item' -import {fireEvent} from '../util.js' +import {fireEvent, linkUrls} from '../util.js' export class GrampsjsAttributes extends GrampsjsEditableList { + static get styles() { + return [ + super.styles, + css` + mwc-list-item { + cursor: default; + } + + mwc-list-item[hasMeta] { + cursor: pointer; + } + `, + ] + } + static get properties() { return { source: {type: Boolean}, @@ -23,13 +38,8 @@ export class GrampsjsAttributes extends GrampsjsEditableList { row(obj) { return html` - - ${obj.value} + + ${this.edit ? obj.value : linkUrls(obj.value, false)} ${this._(obj.type)} info diff --git a/src/components/GrampsjsCitation.js b/src/components/GrampsjsCitation.js index 4c666f29..fc3fba47 100644 --- a/src/components/GrampsjsCitation.js +++ b/src/components/GrampsjsCitation.js @@ -4,7 +4,7 @@ import '@material/mwc-icon' import {GrampsjsObject} from './GrampsjsObject.js' import './GrampsjsFormEditCitationDetails.js' -import {fireEvent} from '../util.js' +import {fireEvent, linkUrls} from '../util.js' const BASE_DIR = '' @@ -60,7 +60,7 @@ export class GrampsjsCitation extends GrampsjsObject { ? html`
${this._('Page')}
-
${this.data.page}
+
${linkUrls(this.data.page, false)}
` : ''} diff --git a/src/components/GrampsjsNoteContent.js b/src/components/GrampsjsNoteContent.js index 08ce8ff9..844bd97f 100644 --- a/src/components/GrampsjsNoteContent.js +++ b/src/components/GrampsjsNoteContent.js @@ -1,15 +1,6 @@ import {html, css, LitElement} from 'lit' import {sharedStyles} from '../SharedStyles.js' - -const urlRegex = - /((?:^|\s)https?:\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi - -function linkUrls(text) { - return text.replace( - urlRegex, - url => `${url}` - ) -} +import {linkUrls} from '../util.js' export class GrampsjsNoteContent extends LitElement { static get styles() { diff --git a/src/util.js b/src/util.js index 46af7417..c41c3410 100644 --- a/src/util.js +++ b/src/util.js @@ -4,7 +4,8 @@ import '@material/mwc-icon' import dayjs from 'dayjs/esm' import relativeTime from 'dayjs/esm/plugin/relativeTime' -import {asteriskIcon, crossIcon} from './icons.js' +import {mdiOpenInNew} from '@mdi/js' +import {asteriskIcon, crossIcon, renderIconSvg} from './icons.js' import {frontendLanguages} from './strings.js' import {hex6ToCss, hex12ToCss} from './color.js' @@ -589,6 +590,27 @@ export function dateIsEmpty(date) { return true } +const urlRegex = + /((?:^|\s)https?:\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi + +export function linkUrls(text, textOnly = true) { + if (textOnly) { + return text.replace( + urlRegex, + url => `${url}` + ) + } + const parts = text.split(urlRegex) + return html`${parts.map(part => + part.match(urlRegex) + ? html`${part} + ${renderIconSvg(mdiOpenInNew, '#0d47a1')} ` + : part + )}` +} + // OpenHistoricalMap functions /**