@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.09 kB
JavaScript
/*!
*
* 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 { DataCiteInfo } from "./DataCite/DataCiteInfo";
import { FoldableItem } from "../../utils/FoldableItem";
import { FoldableAction } from "../../utils/FoldableAction";
import { DataCiteLogo } from "./ResourceTypeIcons";
import { formatCitationPreview, getCitationStyleFromSettings } from "./CitationStyles";
export class DataCiteDOIType extends GenericIdentifierType {
get data() {
var _a, _b;
return JSON.stringify((_b = (_a = this._dataCiteInfo) === 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._dataCiteInfo = await DataCiteInfo.fetch(this._doi);
return this._dataCiteInfo !== null && this._dataCiteInfo.title !== '';
}
async init(data) {
if (data !== undefined) {
this._dataCiteInfo = DataCiteInfo.fromObject(this._doi, JSON.parse(data));
console.debug('reload DataCiteDOIInfo from data', this._dataCiteInfo);
}
else {
this._doi = DOI.getDOIFromString(this.value);
this._dataCiteInfo = await DataCiteInfo.fetch(this._doi);
console.debug('load DataCiteDOIInfo from API', this._dataCiteInfo);
}
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', 'DataCite', 'Metadata provided by DataCite', 'https://datacite.org'));
const metadataItems = this._dataCiteInfo.generateItems();
this.items.push(...metadataItems);
if (this._dataCiteInfo.url) {
this.actions.push(new FoldableAction(0, 'Open Resource', this._dataCiteInfo.url, 'primary'));
}
this.actions.push(new FoldableAction(1, 'Resolve DOI', this._doi.toURL(), 'secondary'));
this.actions.push(new FoldableAction(2, 'View DataCite Metadata', `https://api.datacite.org/dois/${encodeURIComponent(this._doi.toString())}`, 'secondary'));
}
isResolvable() {
return this._dataCiteInfo !== null && this._dataCiteInfo.title !== '';
}
renderPreview() {
var _a, _b, _c;
const citationStyle = getCitationStyleFromSettings(this.settings);
const creators = ((_a = this._dataCiteInfo) === null || _a === void 0 ? void 0 : _a.creators) || [];
const year = (_b = this._dataCiteInfo) === null || _b === void 0 ? void 0 : _b.publicationDate;
const { citation, tooltip } = formatCitationPreview(((_c = this._dataCiteInfo) === 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' }, DataCiteLogo()), h("span", { class: 'min-w-0 pl-2 overflow-hidden text-ellipsis whitespace-nowrap', title: tooltip }, citation)));
}
getSettingsKey() {
return 'DataCiteDOIType';
}
}
//# sourceMappingURL=DataCiteDOIType.js.map