/** @jsx jsx */ /** @jsxFrag React.Fragment */ import update, { type Spec } from 'immutability-helper'; import React from 'react'; import { jsx, css } from '@emotion/react'; import { useDebounce } from '@riboseinc/paneron-extension-kit'; import { ControlGroup, InputGroup, NumericInput, TextArea, } from '@blueprintjs/core'; import type { Citation, ItemClassConfiguration, ItemEditViewProps, InternalItemReference, } from '@riboseinc/paneron-registry-kit/types'; import { GenericRelatedItemView, PropertyDetailView } from '@riboseinc/paneron-registry-kit'; import ItemList from '../helpers/ItemList'; export { ItemList }; import ItemTable from '../helpers/ItemTable'; import { type ColumnInfo } from '../helpers/ItemTable'; export { ItemTable, type ColumnInfo }; export interface CommonGRItemData { name: string identifier: number remarks: string informationSources: Readonly informationSourceRefs: Readonly aliases: Readonly } export const DEFAULTS: Readonly = Object.freeze({ name: "Unnamed item", // Non-positive identifiers are replaced with next available positive integers // in afterApprovedCR hook. identifier: 0, informationSources: [], informationSourceRefs: [], remarks: '', aliases: [], }); export function getInformationSourceStub(): Readonly { return { title: "Untitled source", revisionDate: null, publicationDate: null, seriesIssueID: null, seriesName: null, seriesPage: null, edition: null, editionDate: null, otherDetails: '', isbn: null, issn: null, } as const; } // /** @deprecated: use AliasesEdit without onChange */ // const AliasesDetail: React.FC<{ aliases: string[] }> = function ({ aliases }) { // return //
    // {aliases.map((a, idx) =>
  • {a}
  • )} //
//
; // }; const AliasesEdit: React.FC<{ aliases: Readonly onChange?: (newAliases: Readonly) => void }> = function ({ aliases, onChange }) { return ( onChange!(update(aliases, spec)) : undefined} placeholderItem="" itemRenderer={(alias, idx, handleChange, deleteButton) => handleChange!({ $set: evt.currentTarget.value })} /> } /> ); }; export const COMMON_PROPERTIES: Pick, 'itemSorter'> = { itemSorter: (a, b) => a.identifier - b.identifier, } as const; export const EditView: React.FC & { hideRemarks?: boolean, hideAliases?: boolean, hideInfoSources?: boolean, showInfoSourceRefs?: boolean, }> = function (props) { const { itemData, onChange, children } = props; function textInputProps > (fieldName: F) { return { readOnly: !onChange, onChange: (evt: React.FormEvent) => { if (!onChange) { return; } onChange({ ...itemData, [fieldName]: evt.currentTarget.value }) }, } } return (
{props.hideAliases ? null : onChange!(update(itemData, { aliases: { $set: newAliases } } )) : undefined} />} {props.hideRemarks || (!onChange && !itemData.remarks?.trim()) ? null :