UNPKG

@kit-data-manager/pid-component

Version:

The PID-Component is a web component that can be used to evaluate and display FAIR Digital Objects, PIDs, ORCiDs, and possibly other identifiers in a user-friendly way. It is easily extensible to support other identifier types.

75 lines (74 loc) 4.08 kB
/*! * * Copyright 2024-2026 Karlsruhe Institute of Technology. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import { h } from "@stencil/core"; import { GenericIdentifierType } from "../../utils/GenericIdentifierType"; import { DOI } from "./DOI"; import { CrossRefInfo } from "./CrossRef/CrossRefInfo"; import { FoldableItem } from "../../utils/FoldableItem"; import { FoldableAction } from "../../utils/FoldableAction"; import { CrossRefLogo } from "./ResourceTypeIcons"; import { formatCitationPreview, getCitationStyleFromSettings } from "./CitationStyles"; export class CrossRefDOIType extends GenericIdentifierType { get data() { var _a, _b; return JSON.stringify((_b = (_a = this._crossRefInfo) === null || _a === void 0 ? void 0 : _a.toObject()) !== null && _b !== void 0 ? _b : {}); } quickCheck() { return DOI.isDOI(this.value); } async hasMeaningfulInformation() { this._doi = DOI.getDOIFromString(this.value); this._crossRefInfo = await CrossRefInfo.fetch(this._doi); return this._crossRefInfo !== null && this._crossRefInfo.title !== ''; } async init(data) { if (data !== undefined) { this._crossRefInfo = CrossRefInfo.fromObject(this._doi, JSON.parse(data)); console.debug('reload CrossRefDOIInfo from data', this._crossRefInfo); } else { this._doi = DOI.getDOIFromString(this.value); this._crossRefInfo = await CrossRefInfo.fetch(this._doi); console.debug('load CrossRefDOIInfo from API', this._crossRefInfo); } this.items.push(new FoldableItem(0, 'DOI', this._doi.toString(), 'The DOI used for this resource. Digital Object Identifier is a persistent identifier for academic and research resources.', 'https://www.doi.org/', undefined, false)); this.items.push(new FoldableItem(1, 'Metadata Source', 'CrossRef', 'Metadata provided by CrossRef', 'https://www.crossref.org')); const metadataItems = this._crossRefInfo.generateItems(); this.items.push(...metadataItems); if (this._crossRefInfo.url) { this.actions.push(new FoldableAction(0, 'Open Resource', this._crossRefInfo.url, 'primary')); } this.actions.push(new FoldableAction(1, 'Resolve DOI', this._doi.toURL(), 'secondary')); this.actions.push(new FoldableAction(2, 'View CrossRef Metadata', `https://api.crossref.org/works/${this._doi.toString()}`, 'secondary')); } isResolvable() { return this._crossRefInfo !== null && this._crossRefInfo.title !== ''; } renderPreview() { var _a, _b, _c; const citationStyle = getCitationStyleFromSettings(this.settings); const creators = ((_a = this._crossRefInfo) === null || _a === void 0 ? void 0 : _a.creators) || []; const year = (_b = this._crossRefInfo) === null || _b === void 0 ? void 0 : _b.publicationDate; const { citation, tooltip } = formatCitationPreview(((_c = this._crossRefInfo) === null || _c === void 0 ? void 0 : _c.title) || '', creators, year, citationStyle); return (h("span", { class: `inline-flex flex-nowrap items-baseline font-mono min-w-0 max-w-full ${this.isDarkMode ? 'text-gray-200' : ''}` }, h("span", { class: 'flex-none px-0.5 h-4 self-center' }, CrossRefLogo()), h("span", { class: 'min-w-0 pl-2 overflow-hidden text-ellipsis whitespace-nowrap', title: tooltip }, citation))); } getSettingsKey() { return 'CrossRefDOIType'; } } //# sourceMappingURL=CrossRefDOIType.js.map