Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

2.3 KB
Raw Blame
import React from 'react';
import { ChangelogEntry } from '../utils/changelog';
import { useI18n } from '../i18n';

export interface ChangelogBoxProps {
  entry: ChangelogEntry;
  maxHeightClass?: string;
}

const SECTION_BADGE_CLASSES: Record<string, string> = {
  new: 'text-ui-success',
  improvements: 'text-ui-accent',
  'bug fixes': 'text-ui-warning',
  other: 'text-ui-muted',
};

const INLINE_CODE_RE = /(`[^`]+`)/g;

/**
 * Safely render inline backtick code spans (e.g. `.inkb`, `.csp`) as styled <code> tags
 * without using dangerouslySetInnerHTML.
 */
function renderInlineCode(text: string): React.ReactNode {
  const parts = text.split(INLINE_CODE_RE);
  if (parts.length === 1) {
    return text;
  }

  return parts.map((part, idx) => {
    if (part.length >= 2 && part.startsWith('`') && part.endsWith('`')) {
      return (
        <code
          key={idx}
          className="font-ui-mono text-[10px] px-1 py-0.5 rounded-ui-xs bg-ui-control border border-ui-subtle text-ui-primary"
        >
          {part.slice(1, -1)}
        </code>
      );
    }
    return <React.Fragment key={idx}>{part}</React.Fragment>;
  });
}

/**
 * Scrollable changelog card rendering categorized release notes from CHANGELOG.md.
 */
export const ChangelogBox: React.FC<ChangelogBoxProps> = ({
  entry,
  maxHeightClass = 'max-h-44',
}) => {
  const { td } = useI18n();
  return (
    <div
      className={`bg-ui-header rounded-ui-md border border-ui-subtle p-3 ${maxHeightClass} overflow-y-auto space-y-3 select-text`}
    >
      {entry.sections.map((section, sectionIdx) => {
        const titleColor =
          SECTION_BADGE_CLASSES[section.title.toLowerCase()] ?? 'text-ui-secondary';
        return (
          <div key={`${section.title || 'items'}-${sectionIdx}`} className="space-y-1">
            {section.title && (
              <div className={`text-[10px] font-semibold uppercase tracking-wider ${titleColor}`}>
                {td(section.title, 'changelog')}
              </div>
            )}
            <ul className="space-y-1 pl-3.5 list-disc text-[11px] text-ui-secondary leading-relaxed">
              {section.items.map((item, idx) => (
                <li key={`${section.title}-${idx}`}>{renderInlineCode(item)}</li>
              ))}
            </ul>
          </div>
        );
      })}
    </div>
  );
};