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.

99 lines (98 loc) 3.81 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 { PIDRecord } from "./PIDRecord"; import { PID } from "./PID"; import { PIDDataType } from "./PIDDataType"; import { h } from "@stencil/core"; import { GenericIdentifierType } from "../../utils/GenericIdentifierType"; import { FoldableItem } from "../../utils/FoldableItem"; import { FoldableAction } from "../../utils/FoldableAction"; export class HandleType extends GenericIdentifierType { constructor() { super(...arguments); this._parts = []; } get data() { var _a, _b; return JSON.stringify((_b = (_a = this._pidRecord) === null || _a === void 0 ? void 0 : _a.toObject()) !== null && _b !== void 0 ? _b : {}); } quickCheck() { return PID.isPID(this.value); } async hasMeaningfulInformation() { const pid = PID.getPIDFromString(this.value); this._pidRecord = await pid.resolve(); return this._pidRecord.values.length > 0; } async init(data) { if (data !== undefined) { this._pidRecord = PIDRecord.fromJSON(data); this._parts = await Promise.all([ { text: this._pidRecord.pid.prefix, nextExists: true, }, { text: this._pidRecord.pid.suffix, nextExists: false, }, ]); console.debug('reload PIDRecord from data', this._pidRecord); } else { const pid = PID.getPIDFromString(this.value); this._parts = [ { text: pid.prefix, nextExists: true, }, { text: pid.suffix, nextExists: false, }, ]; if (!this._pidRecord) { this._pidRecord = await pid.resolve(); console.debug('load PIDRecord from API', this._pidRecord); } else { console.debug('using cached PIDRecord'); } } for (const value of this._pidRecord.values) { if (value.type instanceof PIDDataType) { this.items.push(new FoldableItem(0, value.type.name, value.data.value, value.type.description, value.type.redirectURL, value.type.regex)); } } this.actions.push(new FoldableAction(0, 'Open in FAIR-DOscope', `https://kit-data-manager.github.io/fairdoscope/?pid=${this._pidRecord.pid.toString()}`, 'primary')); this.actions.push(new FoldableAction(0, 'View in Handle.net registry', `https://hdl.handle.net/${this._pidRecord.pid.toString()}`, 'secondary')); return; } isResolvable() { return this._pidRecord.values.length > 0; } renderPreview() { return (h("span", { class: 'font-mono font-bold align-baseline' }, this._parts.map(element => { return (h("span", null, h("color-highlight", { text: element.text }), element.nextExists ? h("span", { class: `mx-0.5` }, "/") : '')); }))); } getSettingsKey() { return 'HandleType'; } } //# sourceMappingURL=HandleType.js.map