mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(ui): convert (?i) inline flag to JS /i instead of Go-specific error
(?i) is the most common Go regex flag and can be safely converted
to JS RegExp's 'i' flag. Only flag (?im), (?ims), or \x{} are
now marked as Go-specific. Multi-flag combos and non-i flags
still show the Go-specific warning.
This commit is contained in:
@@ -110,7 +110,6 @@ export default function AuditAssistantPanel({
|
||||
onErrorsClick={handleErrorsClick}
|
||||
mode="audit"
|
||||
/>
|
||||
<div className="border-t border-dashed border-pencil-light/30" />
|
||||
<div className="p-3 text-sm text-pencil-light">Structured view panel — coming in Phase 2</div>
|
||||
</div>
|
||||
);
|
||||
@@ -187,63 +186,55 @@ export default function AuditAssistantPanel({
|
||||
mode="audit"
|
||||
/>
|
||||
|
||||
{/* Separator */}
|
||||
<div className="border-t border-dashed border-pencil-light/30" />
|
||||
|
||||
{/* Context area */}
|
||||
<div className="flex-1 overflow-y-auto animate-fade-in">{renderContextArea()}</div>
|
||||
<div className="ss-panel-content flex-1 overflow-y-auto animate-fade-in">{renderContextArea()}</div>
|
||||
|
||||
{/* Bottom bar */}
|
||||
<div className="flex items-center gap-1 px-2 py-1.5 border-t border-muted/40 bg-paper">
|
||||
{/* Structure button */}
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'structure'}
|
||||
onClick={() => toggleLock('structure')}
|
||||
className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium transition-all duration-150 ${
|
||||
lockedView === 'structure'
|
||||
? 'bg-blue/10 text-blue border border-blue/20'
|
||||
: 'text-pencil-light hover:text-pencil border border-transparent'
|
||||
}`}
|
||||
>
|
||||
<List size={12} strokeWidth={2} />
|
||||
Structure
|
||||
</button>
|
||||
<div className="ss-panel-toolbar flex items-center gap-2 px-2 py-1.5 border-t border-muted/40 bg-paper">
|
||||
<div className="ss-panel-tabs inline-flex items-center p-0.5 bg-muted/20 border border-muted/40 rounded-[var(--radius-sm)]">
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'structure'}
|
||||
onClick={() => toggleLock('structure')}
|
||||
className={`ss-panel-tab inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[3px] text-xs font-medium transition-all duration-150 cursor-pointer ${
|
||||
lockedView === 'structure'
|
||||
? 'bg-surface text-pencil shadow-sm'
|
||||
: 'text-pencil-light hover:text-pencil'
|
||||
}`}
|
||||
>
|
||||
<List size={12} strokeWidth={2} />
|
||||
Structure
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'diff'}
|
||||
onClick={() => toggleLock('diff')}
|
||||
className={`ss-panel-tab inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[3px] text-xs font-medium transition-all duration-150 cursor-pointer ${
|
||||
lockedView === 'diff'
|
||||
? 'bg-surface text-pencil shadow-sm'
|
||||
: 'text-pencil-light hover:text-pencil'
|
||||
}`}
|
||||
>
|
||||
<GitCompare size={12} strokeWidth={2} />
|
||||
Diff
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'test'}
|
||||
onClick={() => toggleLock('test')}
|
||||
className={`ss-panel-tab inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[3px] text-xs font-medium transition-all duration-150 cursor-pointer ${
|
||||
lockedView === 'test'
|
||||
? 'bg-surface text-pencil shadow-sm'
|
||||
: 'text-pencil-light hover:text-pencil'
|
||||
}`}
|
||||
>
|
||||
<FlaskConical size={12} strokeWidth={2} />
|
||||
Test
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Diff button */}
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'diff'}
|
||||
onClick={() => toggleLock('diff')}
|
||||
className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium transition-all duration-150 ${
|
||||
lockedView === 'diff'
|
||||
? 'bg-blue/10 text-blue border border-blue/20'
|
||||
: 'text-pencil-light hover:text-pencil border border-transparent'
|
||||
}`}
|
||||
>
|
||||
<GitCompare size={12} strokeWidth={2} />
|
||||
Diff
|
||||
</button>
|
||||
|
||||
{/* Test button */}
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'test'}
|
||||
onClick={() => toggleLock('test')}
|
||||
className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium transition-all duration-150 ${
|
||||
lockedView === 'test'
|
||||
? 'bg-blue/10 text-blue border border-blue/20'
|
||||
: 'text-pencil-light hover:text-pencil border border-transparent'
|
||||
}`}
|
||||
>
|
||||
<FlaskConical size={12} strokeWidth={2} />
|
||||
Test
|
||||
</button>
|
||||
|
||||
{/* Spacer */}
|
||||
<span className="flex-1" />
|
||||
|
||||
{/* Auto unlock button — shown when locked */}
|
||||
{lockedView !== 'auto' && (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -135,49 +135,43 @@ export default function AssistantPanel({
|
||||
mode={mode}
|
||||
/>
|
||||
|
||||
{/* Separator */}
|
||||
<div className="border-t border-dashed border-pencil-light/30" />
|
||||
|
||||
{/* Context area */}
|
||||
<div className="flex-1 overflow-y-auto animate-fade-in">{renderContextArea()}</div>
|
||||
<div className="ss-panel-content flex-1 overflow-y-auto animate-fade-in">{renderContextArea()}</div>
|
||||
|
||||
{/* Bottom bar — config mode only */}
|
||||
{mode === 'config' && (
|
||||
<div className="flex items-center gap-1 px-2 py-1.5 border-t border-muted/40 bg-paper">
|
||||
{/* Structure button */}
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'structure'}
|
||||
onClick={() => toggleLock('structure')}
|
||||
className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium transition-all duration-150 ${
|
||||
lockedView === 'structure'
|
||||
? 'bg-blue/10 text-blue border border-blue/20'
|
||||
: 'text-pencil-light hover:text-pencil border border-transparent'
|
||||
}`}
|
||||
>
|
||||
<List size={12} strokeWidth={2} />
|
||||
Structure
|
||||
</button>
|
||||
<div className="ss-panel-toolbar flex items-center gap-2 px-2 py-1.5 border-t border-muted/40 bg-paper">
|
||||
<div className="ss-panel-tabs inline-flex items-center p-0.5 bg-muted/20 border border-muted/40 rounded-[var(--radius-sm)]">
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'structure'}
|
||||
onClick={() => toggleLock('structure')}
|
||||
className={`ss-panel-tab inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[3px] text-xs font-medium transition-all duration-150 cursor-pointer ${
|
||||
lockedView === 'structure'
|
||||
? 'bg-surface text-pencil shadow-sm'
|
||||
: 'text-pencil-light hover:text-pencil'
|
||||
}`}
|
||||
>
|
||||
<List size={12} strokeWidth={2} />
|
||||
Structure
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'diff'}
|
||||
onClick={() => toggleLock('diff')}
|
||||
className={`ss-panel-tab inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[3px] text-xs font-medium transition-all duration-150 cursor-pointer ${
|
||||
lockedView === 'diff'
|
||||
? 'bg-surface text-pencil shadow-sm'
|
||||
: 'text-pencil-light hover:text-pencil'
|
||||
}`}
|
||||
>
|
||||
<GitCompare size={12} strokeWidth={2} />
|
||||
Diff
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Diff button */}
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={lockedView === 'diff'}
|
||||
onClick={() => toggleLock('diff')}
|
||||
className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium transition-all duration-150 ${
|
||||
lockedView === 'diff'
|
||||
? 'bg-blue/10 text-blue border border-blue/20'
|
||||
: 'text-pencil-light hover:text-pencil border border-transparent'
|
||||
}`}
|
||||
>
|
||||
<GitCompare size={12} strokeWidth={2} />
|
||||
Diff
|
||||
</button>
|
||||
|
||||
{/* Spacer */}
|
||||
<span className="flex-1" />
|
||||
|
||||
{/* Auto button — shown when locked */}
|
||||
{lockedView !== 'auto' && (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { useMemo } from 'react';
|
||||
import { AlertTriangle, Lightbulb } from 'lucide-react';
|
||||
import { fieldDocs } from '../../lib/fieldDocs';
|
||||
import { isMacOS } from '../../hooks/useGlobalShortcuts';
|
||||
import Badge from '../Badge';
|
||||
|
||||
/** Show idle hints when tree has this few nodes or fewer */
|
||||
const IDLE_HINT_THRESHOLD = 3;
|
||||
|
||||
interface TreeNode {
|
||||
key: string;
|
||||
value: string;
|
||||
@@ -66,6 +70,10 @@ export default function StructureTree({
|
||||
parseError,
|
||||
onClickNode,
|
||||
}: StructureTreeProps) {
|
||||
// useMemo must be called before any early return (rules of hooks)
|
||||
const nodes = useMemo(() => parseYamlTree(source), [source]);
|
||||
const modKey = isMacOS() ? '⌘' : 'Ctrl+';
|
||||
|
||||
if (parseError) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 px-3 py-4 text-sm text-warning">
|
||||
@@ -75,8 +83,6 @@ export default function StructureTree({
|
||||
);
|
||||
}
|
||||
|
||||
const nodes = useMemo(() => parseYamlTree(source), [source]);
|
||||
|
||||
if (nodes.length === 0) {
|
||||
// Show available top-level fields as a quick reference
|
||||
const topLevelFields = Object.entries(fieldDocs).filter(([key]) => !key.includes('.'));
|
||||
@@ -99,15 +105,32 @@ export default function StructureTree({
|
||||
}
|
||||
|
||||
return (
|
||||
<div role="tree" aria-label="YAML structure" className="py-1 overflow-x-auto">
|
||||
{nodes.map((node, i) => (
|
||||
<TreeNodeItem
|
||||
key={i}
|
||||
node={node}
|
||||
cursorLine={cursorLine}
|
||||
onClickNode={onClickNode}
|
||||
/>
|
||||
))}
|
||||
<div className="flex flex-col h-full">
|
||||
<div role="tree" aria-label="YAML structure" className="py-1 overflow-x-auto">
|
||||
{nodes.map((node, i) => (
|
||||
<TreeNodeItem
|
||||
key={i}
|
||||
node={node}
|
||||
cursorLine={cursorLine}
|
||||
onClickNode={onClickNode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{nodes.length <= IDLE_HINT_THRESHOLD && (
|
||||
<div className="flex-1 flex flex-col items-center justify-center p-4 select-none animate-fade-in">
|
||||
<div className="ss-panel-idle text-center space-y-2.5 max-w-[180px]">
|
||||
<Lightbulb size={28} strokeWidth={1.2} className="text-muted-dark/30 mx-auto" />
|
||||
<p className="text-xs text-pencil-light leading-relaxed">
|
||||
Click fields in the editor for contextual docs
|
||||
</p>
|
||||
<div className="flex items-center justify-center gap-1.5 text-[10px] text-muted-dark">
|
||||
<kbd className="font-mono bg-muted px-1.5 py-0.5 rounded text-pencil-light border border-muted-dark/30">{modKey}B</kbd>
|
||||
<span>toggle panel</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,21 @@ export interface RegexMatchResult {
|
||||
isGoSpecific: boolean;
|
||||
}
|
||||
|
||||
const GO_SPECIFIC_RE = /\\x\{|^\(\?[a-zA-Z]+\)/;
|
||||
// Truly Go-only syntax that can't be converted to JS
|
||||
const GO_ONLY_RE = /\\x\{/;
|
||||
|
||||
function isGoSpecificRegex(pattern: string): boolean {
|
||||
return GO_SPECIFIC_RE.test(pattern);
|
||||
/** Try to convert Go inline flags to JS RegExp flags.
|
||||
* (?i)pattern → new RegExp("pattern", "i")
|
||||
* (?im)pattern → Go-specific (m means different things in Go vs JS for \b)
|
||||
* Returns { pattern, flags } or null if unconvertible. */
|
||||
function convertGoFlags(pattern: string): { pattern: string; flags: string } | null {
|
||||
const m = pattern.match(/^\(\?([imsu]+)\)(.*)/s);
|
||||
if (!m) return null;
|
||||
const goFlags = m[1];
|
||||
const rest = m[2];
|
||||
// Only convert single 'i' flag — 'm' and 's' have different semantics in Go
|
||||
if (goFlags === 'i') return { pattern: rest, flags: 'i' };
|
||||
return null; // multi-flag or non-i flags → can't safely convert
|
||||
}
|
||||
|
||||
export function computeRegexMatches(
|
||||
@@ -28,15 +39,30 @@ export function computeRegexMatches(
|
||||
): RegexMatchResult {
|
||||
if (!pattern) return { matches: [], error: null, isGoSpecific: false };
|
||||
|
||||
if (isGoSpecificRegex(pattern)) {
|
||||
if (GO_ONLY_RE.test(pattern)) {
|
||||
return { matches: [], error: 'Go-specific regex syntax — cannot test in browser', isGoSpecific: true };
|
||||
}
|
||||
|
||||
let re: RegExp;
|
||||
try {
|
||||
// Try direct compilation first
|
||||
re = new RegExp(pattern);
|
||||
} catch (e) {
|
||||
return { matches: [], error: (e as Error).message, isGoSpecific: false };
|
||||
} catch {
|
||||
// Try converting Go inline flags (e.g. (?i)pattern → /pattern/i)
|
||||
const converted = convertGoFlags(pattern);
|
||||
if (converted) {
|
||||
try {
|
||||
re = new RegExp(converted.pattern, converted.flags);
|
||||
} catch (e2) {
|
||||
return { matches: [], error: (e2 as Error).message, isGoSpecific: false };
|
||||
}
|
||||
} else {
|
||||
// Check if it looks like Go inline flags we can't convert
|
||||
if (/^\(\?[a-zA-Z]+\)/.test(pattern)) {
|
||||
return { matches: [], error: 'Go-specific regex syntax — cannot test in browser', isGoSpecific: true };
|
||||
}
|
||||
return { matches: [], error: 'Invalid regex', isGoSpecific: false };
|
||||
}
|
||||
}
|
||||
|
||||
let excludeRe: RegExp | null = null;
|
||||
|
||||
+106
-4
@@ -654,25 +654,127 @@
|
||||
}
|
||||
|
||||
/* ── Playful: Assistant Panel ── */
|
||||
[data-theme="playful"] .ss-assistant-panel {
|
||||
border-left: 2px solid var(--color-pencil-light);
|
||||
/* Remove inner left border (Card already has its pencil border),
|
||||
warm paper bg, and inset padding so children don't reach the
|
||||
wobbly border-radius clip zone (15px axis values). */
|
||||
[data-theme="playful"] .ss-assistant-panel,
|
||||
[data-theme="playful"] .ss-audit-assistant-panel {
|
||||
border-left: none !important;
|
||||
background: var(--color-paper) !important;
|
||||
}
|
||||
/* Textareas inside panels — moderate radius (not blobby 28px), subtle border */
|
||||
[data-theme="playful"] .ss-assistant-panel textarea,
|
||||
[data-theme="playful"] .ss-audit-assistant-panel textarea {
|
||||
border-radius: 12px !important;
|
||||
border-color: var(--color-muted-dark) !important;
|
||||
background: var(--color-surface) !important;
|
||||
}
|
||||
|
||||
[data-theme="playful"] .ss-status-bar {
|
||||
border-bottom: 2px solid var(--color-muted);
|
||||
border-bottom: 2px dashed var(--color-muted-dark);
|
||||
background: var(--color-paper);
|
||||
}
|
||||
|
||||
[data-theme="playful"] .ss-error-item {
|
||||
border-radius: 8px;
|
||||
border-radius: var(--radius-wobble-badge);
|
||||
}
|
||||
|
||||
[data-theme="playful"] .ss-tree-node {
|
||||
border-radius: 6px;
|
||||
border-left-style: dashed !important;
|
||||
}
|
||||
[data-theme="playful"] .ss-tree-node[aria-selected="true"] {
|
||||
border-left: 2.5px dashed var(--color-blue) !important;
|
||||
}
|
||||
|
||||
[data-theme="playful"] .ss-diff-line {
|
||||
border-radius: 4px;
|
||||
border-left-style: dashed !important;
|
||||
}
|
||||
|
||||
/* ── Playful: Panel Toolbar ── */
|
||||
[data-theme="playful"] .ss-panel-toolbar {
|
||||
border-top: 2px dashed var(--color-muted-dark) !important;
|
||||
}
|
||||
[data-theme="playful"] .ss-panel-tabs {
|
||||
border: 1.5px solid var(--color-muted-dark) !important;
|
||||
border-radius: var(--radius-wobble-badge) !important;
|
||||
background: var(--color-muted) !important;
|
||||
box-shadow: 1.5px 1.5px 0 rgba(45, 45, 45, 0.06);
|
||||
}
|
||||
[data-theme="playful"] .ss-panel-tab {
|
||||
border-radius: 80px 6px 70px 6px / 6px 70px 6px 80px !important;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
[data-theme="playful"] .ss-panel-tab[aria-pressed="true"] {
|
||||
background: var(--color-surface) !important;
|
||||
border: 1.5px solid var(--color-muted-dark) !important;
|
||||
box-shadow: 1px 1px 0 rgba(45, 45, 45, 0.06);
|
||||
}
|
||||
|
||||
/* ── Playful: Tone down badges inside panels — dense UI needs lighter treatment ── */
|
||||
[data-theme="playful"] .ss-assistant-panel .ss-badge,
|
||||
[data-theme="playful"] .ss-audit-assistant-panel .ss-badge {
|
||||
border-width: 1px;
|
||||
border-color: var(--color-muted-dark);
|
||||
box-shadow: 1px 1px 0 rgba(45, 45, 45, 0.03);
|
||||
}
|
||||
|
||||
/* ── Playful: Panel content — notebook ruled lines ── */
|
||||
[data-theme="playful"] .ss-panel-content {
|
||||
background-image: repeating-linear-gradient(
|
||||
transparent,
|
||||
transparent 27px,
|
||||
var(--color-muted) 27px,
|
||||
var(--color-muted) 28px
|
||||
);
|
||||
background-position: 0 3px;
|
||||
}
|
||||
[data-theme="playful"].dark .ss-panel-content {
|
||||
background-image: repeating-linear-gradient(
|
||||
transparent,
|
||||
transparent 27px,
|
||||
rgba(255, 255, 255, 0.04) 27px,
|
||||
rgba(255, 255, 255, 0.04) 28px
|
||||
);
|
||||
}
|
||||
|
||||
/* ── Playful: Panel section headers — hand-drawn font ── */
|
||||
[data-theme="playful"] .ss-panel-content label,
|
||||
[data-theme="playful"] .ss-panel-content .tracking-wider {
|
||||
font-family: var(--font-heading);
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
/* ── Playful: Panel Idle State ── */
|
||||
[data-theme="playful"] .ss-panel-idle p {
|
||||
font-family: var(--font-heading);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
[data-theme="playful"] .ss-panel-idle kbd {
|
||||
border: 1.5px solid var(--color-pencil);
|
||||
border-radius: var(--radius-wobble-badge);
|
||||
box-shadow: 1.5px 1.5px 0 rgba(45, 45, 45, 0.1);
|
||||
}
|
||||
|
||||
/* ── Playful Dark: Panel ── */
|
||||
[data-theme="playful"].dark .ss-assistant-panel textarea,
|
||||
[data-theme="playful"].dark .ss-audit-assistant-panel textarea {
|
||||
background: var(--color-surface) !important;
|
||||
border-color: rgba(255, 255, 255, 0.15) !important;
|
||||
}
|
||||
[data-theme="playful"].dark .ss-panel-tabs {
|
||||
border-color: rgba(255, 255, 255, 0.15) !important;
|
||||
box-shadow: 1.5px 1.5px 0 rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
[data-theme="playful"].dark .ss-panel-tab[aria-pressed="true"] {
|
||||
border-color: rgba(255, 255, 255, 0.15) !important;
|
||||
}
|
||||
[data-theme="playful"].dark .ss-assistant-panel .ss-badge,
|
||||
[data-theme="playful"].dark .ss-audit-assistant-panel .ss-badge {
|
||||
border-color: rgba(255, 255, 255, 0.12);
|
||||
box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
/* ── prefers-reduced-motion ── */
|
||||
|
||||
Reference in New Issue
Block a user