refactor: single source for writing styles + action labels; add theme module
- src/lib/actions.ts: canonical ACTIONS/ACTION_LABELS/WRITING_STYLES; context-menu styles derived (WRITING_STYLES minus Default). Replaces the three duplicated style arrays in popup, content, and background. - src/lib/theme.ts: canonical palette. Existing hex literals in the entrypoints are swapped wholesale when light/dark theming lands, so the color plumbing is only rewritten once. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { defineBackground } from 'wxt/utils/define-background';
|
||||
import nacl from 'tweetnacl';
|
||||
import type { AnalyzePayload, LexAIConfig, LexAIResponse } from '@lib/types';
|
||||
import { ACTIONS, ACTION_LABELS, CONTEXT_MENU_STYLES } from '@lib/actions';
|
||||
|
||||
// ─── Fetch with timeout ───────────────────────────────────────────────────────
|
||||
|
||||
@@ -431,25 +432,15 @@ export default defineBackground(() => {
|
||||
console.log('LexAI background service worker started');
|
||||
|
||||
// ─── Context menus ───────────────────────────────────────────────────────
|
||||
const CONTEXT_ACTIONS = ['fix', 'rephrase', 'shorten', 'expand', 'explain'] as const;
|
||||
const CONTEXT_ACTION_LABELS: Record<string, string> = {
|
||||
fix: 'Fix Grammar',
|
||||
rephrase: 'Rephrase',
|
||||
shorten: 'Shorten',
|
||||
expand: 'Expand',
|
||||
explain: 'Explain',
|
||||
};
|
||||
const CONTEXT_STYLES = ['Formal', 'Casual', 'Academic', 'Creative', 'Concise'];
|
||||
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
chrome.contextMenus.removeAll(() => {
|
||||
CONTEXT_ACTIONS.forEach(action => {
|
||||
ACTIONS.forEach(action => {
|
||||
chrome.contextMenus.create({
|
||||
id: `lexai-${action}`,
|
||||
title: `⚡ LexAI: ${CONTEXT_ACTION_LABELS[action]}`,
|
||||
title: `⚡ LexAI: ${ACTION_LABELS[action]}`,
|
||||
contexts: ['selection'],
|
||||
});
|
||||
CONTEXT_STYLES.forEach(style => {
|
||||
CONTEXT_MENU_STYLES.forEach(style => {
|
||||
chrome.contextMenus.create({
|
||||
id: `lexai-${action}-${style.toLowerCase()}`,
|
||||
parentId: `lexai-${action}`,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { defineContentScript } from 'wxt/utils/define-content-script';
|
||||
import { isExtensionValid, safeSendMessage } from '@lib/messaging';
|
||||
import { WRITING_STYLES } from '@lib/actions';
|
||||
|
||||
export default defineContentScript({
|
||||
matches: ['<all_urls>'],
|
||||
@@ -744,7 +745,7 @@ export default defineContentScript({
|
||||
modal.appendChild(body);
|
||||
|
||||
// ─── Style selector row ───────────────────────────────────────────────
|
||||
const STYLES = ['Default', 'Formal', 'Casual', 'Academic', 'Creative', 'Concise'];
|
||||
const STYLES = WRITING_STYLES;
|
||||
|
||||
const styleRow = document.createElement('div');
|
||||
Object.assign(styleRow.style, {
|
||||
|
||||
@@ -2,9 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { safeSendMessage, safeStorageGet, safeStorageSet } from '@lib/messaging';
|
||||
|
||||
// ─── Constants ───────────────────────────────────────────────────────────────
|
||||
|
||||
const WRITING_STYLES = ['Default', 'Formal', 'Casual', 'Academic', 'Creative', 'Concise'];
|
||||
import { WRITING_STYLES } from '@lib/actions';
|
||||
|
||||
// ─── Types ───────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user