@syntrologie/adapt-content 2.8.0-canary.7 → 2.8.0-canary.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cdn.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare const manifest: {
25
25
  icon: string;
26
26
  description: string;
27
27
  };
28
- component: typeof import("./editor").ContentEditor;
28
+ component: typeof import("./content-editor-ui").ContentEditor;
29
29
  };
30
30
  metadata: {
31
31
  isBuiltIn: boolean;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Adaptive Content - Editor State & Logic
3
+ *
4
+ * Pure helpers for the content editor: anchor resolution, types, section config,
5
+ * flatten/filter logic, anchor detection hook, and dismissal management.
6
+ */
7
+ import type { ContentConfig } from './schema';
8
+ /** Extract the CSS selector string from an anchorId (object or legacy string). */
9
+ export declare function resolveAnchorSelector(anchorId: unknown): string;
10
+ /** Extract the target route from an AnchorId object, ignoring wildcard '**'. */
11
+ export declare function resolveAnchorRoute(anchorId: unknown): string | null;
12
+ /** Save a pending highlight selector to sessionStorage (inlined to avoid cross-package import). */
13
+ export declare function savePendingHighlight(selector: string): void;
14
+ export type SectionKey = keyof ContentConfig;
15
+ export interface ItemRef {
16
+ section: SectionKey;
17
+ index: number;
18
+ }
19
+ export declare function itemKey(section: SectionKey, index: number): string;
20
+ export declare function parseItemKey(key: string): ItemRef;
21
+ export declare const SECTION_ICON_MAP: Record<SectionKey, React.ComponentType<{
22
+ size?: number;
23
+ className?: string;
24
+ }>>;
25
+ export interface FlatItem {
26
+ key: string;
27
+ section: SectionKey;
28
+ index: number;
29
+ summary: string;
30
+ anchorId: string;
31
+ rawAnchorId: unknown;
32
+ }
33
+ /** Build a flat list of all items across all section types. */
34
+ export declare function flattenItems(config: ContentConfig): FlatItem[];
35
+ /** Remove items by key set from a config, returning a new config. */
36
+ export declare function filterConfig(config: ContentConfig, dismissedKeys: Set<string>): ContentConfig;
37
+ export interface DetectionEntry {
38
+ found: boolean;
39
+ element: HTMLElement | null;
40
+ }
41
+ export declare function useAnchorDetection(items: Array<{
42
+ key: string;
43
+ anchorId: string;
44
+ }>): Map<string, DetectionEntry>;
45
+ //# sourceMappingURL=content-editor-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-editor-state.d.ts","sourceRoot":"","sources":["../src/content-editor-state.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAO9C,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAK/D;AAED,gFAAgF;AAChF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CASnE;AAED,mGAAmG;AACnG,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,QAMpD;AAMD,MAAM,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC;AAE7C,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGjD;AAMD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,UAAU,EACV,KAAK,CAAC,aAAa,CAAC;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAQ3D,CAAC;AAMF,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,QAAQ,EAAE,CAkB9D;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,aAAa,CAW7F;AAMD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;CAC7B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,GAC9C,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CA6B7B"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Adaptive Content - Editor State & Logic
3
+ *
4
+ * Pure helpers for the content editor: anchor resolution, types, section config,
5
+ * flatten/filter logic, anchor detection hook, and dismissal management.
6
+ */
7
+ import { FileCode, Minus, Palette, Plus, Tag, Type } from 'lucide-react';
8
+ import { useEffect, useRef, useState } from 'react';
9
+ import { summarizeContentChange } from './summarize';
10
+ // ============================================================================
11
+ // Anchor Helpers
12
+ // ============================================================================
13
+ /** Extract the CSS selector string from an anchorId (object or legacy string). */
14
+ export function resolveAnchorSelector(anchorId) {
15
+ if (!anchorId)
16
+ return '';
17
+ if (typeof anchorId === 'string')
18
+ return anchorId;
19
+ if (typeof anchorId === 'object')
20
+ return anchorId.selector ?? '';
21
+ return '';
22
+ }
23
+ /** Extract the target route from an AnchorId object, ignoring wildcard '**'. */
24
+ export function resolveAnchorRoute(anchorId) {
25
+ if (!anchorId || typeof anchorId !== 'object')
26
+ return null;
27
+ const route = anchorId.route;
28
+ if (typeof route === 'string' && route !== '**')
29
+ return route;
30
+ if (Array.isArray(route)) {
31
+ const first = route.find((r) => typeof r === 'string' && r !== '**');
32
+ return first ?? null;
33
+ }
34
+ return null;
35
+ }
36
+ /** Save a pending highlight selector to sessionStorage (inlined to avoid cross-package import). */
37
+ export function savePendingHighlight(selector) {
38
+ try {
39
+ sessionStorage.setItem('syntro:editor:pending-highlight', selector);
40
+ }
41
+ catch {
42
+ // Silently ignore
43
+ }
44
+ }
45
+ export function itemKey(section, index) {
46
+ return `${section}:${index}`;
47
+ }
48
+ export function parseItemKey(key) {
49
+ const [section, indexStr] = key.split(':');
50
+ return { section: section, index: Number(indexStr) };
51
+ }
52
+ // ============================================================================
53
+ // Section Config
54
+ // ============================================================================
55
+ export const SECTION_ICON_MAP = {
56
+ textReplacements: Type,
57
+ attributeChanges: Tag,
58
+ styleChanges: Palette,
59
+ htmlInsertions: FileCode,
60
+ classAdditions: Plus,
61
+ classRemovals: Minus,
62
+ };
63
+ /** Build a flat list of all items across all section types. */
64
+ export function flattenItems(config) {
65
+ const items = [];
66
+ const sections = Object.keys(SECTION_ICON_MAP);
67
+ for (const section of sections) {
68
+ const arr = config[section] || [];
69
+ arr.forEach((item, i) => {
70
+ const rec = item;
71
+ items.push({
72
+ key: itemKey(section, i),
73
+ section,
74
+ index: i,
75
+ summary: summarizeContentChange(section, rec),
76
+ anchorId: resolveAnchorSelector(rec.anchorId),
77
+ rawAnchorId: rec.anchorId,
78
+ });
79
+ });
80
+ }
81
+ return items;
82
+ }
83
+ /** Remove items by key set from a config, returning a new config. */
84
+ export function filterConfig(config, dismissedKeys) {
85
+ const result = { ...config };
86
+ const sections = Object.keys(SECTION_ICON_MAP);
87
+ for (const section of sections) {
88
+ const arr = config[section] || [];
89
+ const filtered = arr.filter((_, i) => !dismissedKeys.has(itemKey(section, i)));
90
+ if (filtered.length > 0 || config[section] !== undefined) {
91
+ result[section] = filtered;
92
+ }
93
+ }
94
+ return result;
95
+ }
96
+ export function useAnchorDetection(items) {
97
+ const [detectionMap, setDetectionMap] = useState(new Map());
98
+ const itemsRef = useRef(items);
99
+ itemsRef.current = items;
100
+ useEffect(() => {
101
+ const runDetection = () => {
102
+ const map = new Map();
103
+ for (const item of itemsRef.current) {
104
+ if (!item.anchorId) {
105
+ map.set(item.key, { found: false, element: null });
106
+ continue;
107
+ }
108
+ try {
109
+ const el = document.querySelector(item.anchorId);
110
+ map.set(item.key, { found: el !== null, element: el });
111
+ }
112
+ catch {
113
+ map.set(item.key, { found: false, element: null });
114
+ }
115
+ }
116
+ setDetectionMap(map);
117
+ };
118
+ runDetection();
119
+ const interval = setInterval(runDetection, 2000);
120
+ return () => clearInterval(interval);
121
+ }, []);
122
+ return detectionMap;
123
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Adaptive Content - Editor UI Component
3
+ *
4
+ * Main editor component with tab switching, item selection, form inputs,
5
+ * save/publish, and highlight on page.
6
+ */
7
+ import type { EditorPanelProps } from './types';
8
+ export declare function ContentEditor({ config, onChange, editor }: EditorPanelProps): import("react/jsx-runtime").JSX.Element;
9
+ /**
10
+ * Editor module configuration.
11
+ */
12
+ export declare const editor: {
13
+ panel: {
14
+ title: string;
15
+ icon: string;
16
+ description: string;
17
+ };
18
+ component: typeof ContentEditor;
19
+ };
20
+ export declare const editorPanel: {
21
+ title: string;
22
+ icon: string;
23
+ description: string;
24
+ };
25
+ export default ContentEditor;
26
+ //# sourceMappingURL=content-editor-ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-editor-ui.d.ts","sourceRoot":"","sources":["../src/content-editor-ui.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAgBhD,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,gBAAgB,2CAsjB3E;AAED;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;;;CAOlB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;CAAe,CAAC;AAExC,eAAe,aAAa,CAAC"}
@@ -0,0 +1,291 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * Adaptive Content - Editor UI Component
4
+ *
5
+ * Main editor component with tab switching, item selection, form inputs,
6
+ * save/publish, and highlight on page.
7
+ */
8
+ import { DetectionBadge, DismissedSection, EditorBody, EditorCard, EditorFooter, EditorHeader, EditorInput, EditorLayout, EditorSelect, EditorTextarea, EmptyState, GroupHeader, } from '@syntrologie/shared-editor-ui';
9
+ import { useCallback, useEffect, useRef, useState } from 'react';
10
+ import { AnchorPicker } from './components/AnchorPicker';
11
+ import { filterConfig, flattenItems, parseItemKey, resolveAnchorRoute, resolveAnchorSelector, SECTION_ICON_MAP, savePendingHighlight, useAnchorDetection, } from './content-editor-state';
12
+ // ============================================================================
13
+ // Section Icon Component
14
+ // ============================================================================
15
+ /** Renders the appropriate Lucide icon for a section type */
16
+ function SectionIcon({ section, className }) {
17
+ const IconComponent = SECTION_ICON_MAP[section];
18
+ return _jsx(IconComponent, { size: 16, className: className });
19
+ }
20
+ // ============================================================================
21
+ // ContentEditor Component
22
+ // ============================================================================
23
+ export function ContentEditor({ config, onChange, editor }) {
24
+ const typedConfig = config;
25
+ const [dismissedKeys, setDismissedKeys] = useState(() => editor.getDismissedKeys?.() ?? new Set());
26
+ const [editingKey, setEditingKey] = useState(null);
27
+ const [, setPreviewMode] = useState('after');
28
+ // Sync dismissed keys back to navigation context on every change
29
+ useEffect(() => {
30
+ editor.setDismissedKeys?.(dismissedKeys);
31
+ }, [dismissedKeys, editor]);
32
+ // Create mode state
33
+ const [createMode, setCreateMode] = useState(null);
34
+ const [createAnchorId, setCreateAnchorId] = useState('');
35
+ const [createText, setCreateText] = useState('');
36
+ const [createDescription, setCreateDescription] = useState('');
37
+ // React to global before/after toggle from the panel
38
+ // biome-ignore lint/correctness/useExhaustiveDependencies: intentionally omitted — adding config/typedConfig/previewConfig would cause infinite re-renders since previewConfig triggers state updates
39
+ useEffect(() => {
40
+ const mode = editor.previewMode;
41
+ if (!mode)
42
+ return;
43
+ if (mode === 'before') {
44
+ // Remove all content changes — push a config with every item filtered out
45
+ const allKeys = new Set(flattenItems(typedConfig).map((item) => item.key));
46
+ const empty = filterConfig(typedConfig, allKeys);
47
+ editor.previewConfig(empty);
48
+ }
49
+ else {
50
+ // Restore the full config
51
+ editor.previewConfig(config);
52
+ }
53
+ }, [editor.previewMode]);
54
+ // Consume initialEditKey from accordion navigation on mount
55
+ const initialConsumed = useRef(false);
56
+ useEffect(() => {
57
+ if (editor.initialEditKey != null && !initialConsumed.current) {
58
+ initialConsumed.current = true;
59
+ const allFlat = flattenItems(typedConfig);
60
+ const targetIdx = Number(editor.initialEditKey);
61
+ if (targetIdx >= 0 && targetIdx < allFlat.length) {
62
+ const target = allFlat[targetIdx];
63
+ setEditingKey(target.key);
64
+ if (target.anchorId) {
65
+ editor.highlightElement(target.anchorId);
66
+ }
67
+ }
68
+ editor.clearInitialState?.();
69
+ }
70
+ else if (editor.initialCreate && !initialConsumed.current) {
71
+ initialConsumed.current = true;
72
+ setCreateMode('form');
73
+ editor.clearInitialState?.();
74
+ }
75
+ }, [editor, typedConfig]);
76
+ const allItems = flattenItems(typedConfig);
77
+ const activeItems = allItems.filter((item) => !dismissedKeys.has(item.key));
78
+ const dismissedItems = allItems.filter((item) => dismissedKeys.has(item.key));
79
+ const totalChanges = activeItems.length;
80
+ const [, setHoveredKey] = useState(null);
81
+ const detectionMap = useAnchorDetection(allItems);
82
+ const foundCount = activeItems.filter((item) => detectionMap.get(item.key)?.found).length;
83
+ const handleDismiss = useCallback((key) => {
84
+ setDismissedKeys((prev) => {
85
+ const next = new Set(prev);
86
+ next.add(key);
87
+ return next;
88
+ });
89
+ if (editingKey === key)
90
+ setEditingKey(null);
91
+ }, [editingKey]);
92
+ const handleRestore = useCallback((key) => {
93
+ setDismissedKeys((prev) => {
94
+ const next = new Set(prev);
95
+ next.delete(key);
96
+ return next;
97
+ });
98
+ }, []);
99
+ const handleCardClick = useCallback((item) => {
100
+ if (item.anchorId) {
101
+ editor.highlightElement(item.anchorId);
102
+ }
103
+ setEditingKey(item.key);
104
+ }, [editor]);
105
+ const handleBackToList = useCallback(() => {
106
+ setEditingKey(null);
107
+ setPreviewMode('after');
108
+ editor.previewConfig(config);
109
+ editor.clearHighlight();
110
+ }, [editor, config]);
111
+ // Register back handler in panel header when editing
112
+ useEffect(() => {
113
+ editor.setBackHandler?.(editingKey !== null ? handleBackToList : null);
114
+ return () => editor.setBackHandler?.(null);
115
+ }, [editingKey, handleBackToList, editor]);
116
+ const handleFieldChange = useCallback((section, index, field, value) => {
117
+ const arr = (typedConfig[section] || []).slice();
118
+ const item = { ...arr[index] };
119
+ item[field] = value;
120
+ arr[index] = item;
121
+ const updated = { ...typedConfig, [section]: arr };
122
+ onChange(updated);
123
+ editor.setDirty(true);
124
+ }, [typedConfig, onChange, editor]);
125
+ const handlePublish = useCallback(() => {
126
+ // Filter dismissed items before publishing
127
+ if (dismissedKeys.size > 0) {
128
+ const filtered = filterConfig(typedConfig, dismissedKeys);
129
+ onChange(filtered);
130
+ }
131
+ editor.publish();
132
+ }, [dismissedKeys, typedConfig, onChange, editor]);
133
+ const handleBadgeClick = useCallback(async (item) => {
134
+ const detection = detectionMap.get(item.key);
135
+ if (detection?.found && item.anchorId) {
136
+ editor.highlightElement(item.anchorId);
137
+ }
138
+ else {
139
+ const route = resolveAnchorRoute(item.rawAnchorId);
140
+ if (route) {
141
+ if (item.anchorId)
142
+ savePendingHighlight(item.anchorId);
143
+ await editor.navigateTo(route);
144
+ if (item.anchorId)
145
+ editor.highlightElement(item.anchorId);
146
+ }
147
+ else if (item.anchorId) {
148
+ editor.highlightElement(item.anchorId);
149
+ }
150
+ }
151
+ }, [editor, detectionMap]);
152
+ const handleCardHover = useCallback((item) => {
153
+ setHoveredKey(item.key);
154
+ if (item.anchorId) {
155
+ editor.highlightElement(item.anchorId);
156
+ }
157
+ }, [editor]);
158
+ const handleCardLeave = useCallback(() => {
159
+ setHoveredKey(null);
160
+ editor.clearHighlight();
161
+ }, [editor]);
162
+ // ---- Create flow handlers ----
163
+ const handleStartCreate = useCallback(() => {
164
+ setEditingKey(null);
165
+ editor.clearHighlight();
166
+ setCreateAnchorId('');
167
+ setCreateText('');
168
+ setCreateDescription('');
169
+ setCreateMode('form');
170
+ }, [editor]);
171
+ const handleElementPicked = useCallback((picked) => {
172
+ setCreateAnchorId(picked.selector);
173
+ setCreateDescription(picked.description);
174
+ // Pre-fill with the element's current text content
175
+ const text = picked.element.textContent?.trim() || '';
176
+ setCreateText(text);
177
+ setCreateMode('form');
178
+ editor.highlightElement(picked.selector);
179
+ }, [editor]);
180
+ const handleCancelCreate = useCallback(() => {
181
+ setCreateMode(null);
182
+ setCreateAnchorId('');
183
+ setCreateText('');
184
+ setCreateDescription('');
185
+ editor.clearHighlight();
186
+ }, [editor]);
187
+ const handleSaveCreate = useCallback(() => {
188
+ if (!createAnchorId)
189
+ return;
190
+ // Add a new textReplacement to the config
191
+ const existing = typedConfig.textReplacements || [];
192
+ const newItem = {
193
+ anchorId: { selector: createAnchorId, route: '**' },
194
+ text: createText,
195
+ summary: `Set text on ${createAnchorId}`,
196
+ };
197
+ const updated = {
198
+ ...typedConfig,
199
+ textReplacements: [...existing, newItem],
200
+ };
201
+ onChange(updated);
202
+ editor.setDirty(true);
203
+ // Return to list
204
+ setCreateMode(null);
205
+ setCreateAnchorId('');
206
+ setCreateText('');
207
+ setCreateDescription('');
208
+ editor.clearHighlight();
209
+ }, [createAnchorId, createText, typedConfig, onChange, editor]);
210
+ // ---- Edit form renderers per section type ----
211
+ const renderEditFields = (section, index) => {
212
+ const arr = typedConfig[section] || [];
213
+ const item = arr[index];
214
+ if (!item)
215
+ return null;
216
+ const anchorId = resolveAnchorSelector(item.anchorId);
217
+ switch (section) {
218
+ case 'textReplacements':
219
+ return (_jsxs("div", { className: "se-py-1", children: [_jsx("div", { className: "se-text-sm se-font-mono se-text-text-secondary se-py-1 se-px-2 se-bg-slate-grey-3 se-rounded-lg se-mb-3", children: anchorId }), _jsx(EditorTextarea, { label: "Text", value: item.text || '', onChange: (e) => handleFieldChange(section, index, 'text', e.target.value) })] }));
220
+ case 'attributeChanges':
221
+ return (_jsxs("div", { className: "se-py-1", children: [_jsx("div", { className: "se-text-sm se-font-mono se-text-text-secondary se-py-1 se-px-2 se-bg-slate-grey-3 se-rounded-lg se-mb-3", children: anchorId }), _jsx(EditorInput, { label: "Attribute", value: item.attr || '', onChange: (e) => handleFieldChange(section, index, 'attr', e.target.value) }), _jsx(EditorInput, { label: "Value", value: item.value || '', onChange: (e) => handleFieldChange(section, index, 'value', e.target.value) })] }));
222
+ case 'styleChanges': {
223
+ const styleObj = item.styles || {};
224
+ return (_jsxs("div", { className: "se-py-1", children: [_jsx("div", { className: "se-text-sm se-font-mono se-text-text-secondary se-py-1 se-px-2 se-bg-slate-grey-3 se-rounded-lg se-mb-3", children: anchorId }), _jsx("label", { className: "se-text-[11px] se-font-semibold se-text-slate-grey-7 se-mb-1 se-block", children: "Styles" }), Object.entries(styleObj).map(([prop, val]) => (_jsxs("div", { className: "se-flex se-gap-1 se-mb-1", children: [_jsx("input", { className: "se-flex-1 se-py-1.5 se-px-2 se-rounded-lg se-border se-border-input-field-border se-bg-slate-grey-3 se-text-text-primary se-text-sm se-font-[inherit] se-box-border", value: prop, readOnly: true }), _jsx("input", { className: "se-flex-1 se-py-1.5 se-px-2 se-rounded-lg se-border se-border-input-field-border se-bg-slate-grey-3 se-text-text-primary se-text-sm se-font-[inherit] se-box-border", value: val, onChange: (e) => {
225
+ const newStyles = { ...styleObj, [prop]: e.target.value };
226
+ handleFieldChange(section, index, 'styles', newStyles);
227
+ } })] }, prop)))] }));
228
+ }
229
+ case 'htmlInsertions':
230
+ return (_jsxs("div", { className: "se-py-1", children: [_jsx("div", { className: "se-text-sm se-font-mono se-text-text-secondary se-py-1 se-px-2 se-bg-slate-grey-3 se-rounded-lg se-mb-3", children: anchorId }), _jsxs(EditorSelect, { label: "Position", value: item.position || 'after', onChange: (e) => handleFieldChange(section, index, 'position', e.target.value), children: [_jsx("option", { value: "before", children: "Before" }), _jsx("option", { value: "after", children: "After" }), _jsx("option", { value: "prepend", children: "Prepend" }), _jsx("option", { value: "append", children: "Append" }), _jsx("option", { value: "replace", children: "Replace" })] }), _jsx(EditorTextarea, { label: "HTML", value: item.html || '', onChange: (e) => handleFieldChange(section, index, 'html', e.target.value), className: "se-font-mono" })] }));
231
+ case 'classAdditions':
232
+ case 'classRemovals':
233
+ return (_jsxs("div", { className: "se-py-1", children: [_jsx("div", { className: "se-text-sm se-font-mono se-text-text-secondary se-py-1 se-px-2 se-bg-slate-grey-3 se-rounded-lg se-mb-3", children: anchorId }), _jsx(EditorInput, { label: "Class Name", value: item.className || '', onChange: (e) => handleFieldChange(section, index, 'className', e.target.value) })] }));
234
+ default:
235
+ return null;
236
+ }
237
+ };
238
+ const headerTitle = createMode === 'form' || createMode === 'picking' ? 'Add Text Change' : 'Content';
239
+ const headerSubtitle = createMode === 'picking'
240
+ ? 'Click an element on the page to select it. Press ESC to go back.'
241
+ : createMode === 'form'
242
+ ? 'Pick an element and set its new text'
243
+ : `${totalChanges} change${totalChanges !== 1 ? 's' : ''}${totalChanges > 0 ? ` (${foundCount} found on this page)` : ''}`;
244
+ const handleHeaderBack = () => {
245
+ if (createMode === 'picking') {
246
+ setCreateMode('form');
247
+ }
248
+ else if (createMode === 'form') {
249
+ handleCancelCreate();
250
+ }
251
+ else if (editingKey !== null) {
252
+ handleBackToList();
253
+ }
254
+ else {
255
+ editor.navigateHome();
256
+ }
257
+ };
258
+ return (_jsxs(EditorLayout, { children: [_jsx(EditorHeader, { title: headerTitle, subtitle: headerSubtitle, onBack: handleHeaderBack }), _jsx(EditorBody, { children: createMode === 'form' || createMode === 'picking' ? (
259
+ /* ---- Create form mode ---- */
260
+ _jsxs("div", { className: "se-flex se-flex-col se-gap-4", children: [_jsxs("div", { className: "se-flex se-flex-col se-gap-1.5", children: [_jsx("span", { className: "se-text-sm se-font-semibold se-text-text-primary se-uppercase se-tracking-wide", children: "Target Element" }), createAnchorId ? (_jsxs("div", { className: "se-flex se-gap-2 se-items-center", children: [_jsx("code", { className: "se-flex-1 se-py-1.5 se-px-2 se-rounded-lg se-border se-border-input-field-border se-bg-slate-grey-3 se-text-text-primary se-text-sm se-overflow-hidden se-text-ellipsis se-whitespace-nowrap", children: createAnchorId }), _jsx("button", { type: "button", onClick: () => setCreateMode('picking'), className: "se-py-1.5 se-px-3 se-rounded-lg se-border se-border-btn-neutral-border se-bg-btn-neutral se-text-btn-neutral-text se-text-sm se-cursor-pointer se-shrink-0 hover:se-text-btn-neutral-text-hover", children: "Re-pick" })] })) : (_jsx("button", { type: "button", onClick: () => setCreateMode('picking'), className: "se-w-full se-h-12 se-px-4 se-py-2 se-rounded-lg se-border-2 se-border-dashed se-border-btn-primary/30 se-bg-btn-primary/5 se-text-btn-primary se-text-sm se-font-medium se-cursor-pointer se-inline-flex se-items-center se-justify-center se-gap-2 hover:se-bg-btn-primary/10 hover:se-border-btn-primary/50", children: "+ Pick Target Element" })), createDescription && (_jsx("span", { className: "se-text-sm se-text-text-secondary", children: createDescription }))] }), _jsxs("div", { className: "se-flex se-flex-col se-gap-1.5", children: [_jsx("span", { className: "se-text-sm se-font-semibold se-text-text-primary se-uppercase se-tracking-wide", children: "Text Content" }), _jsx(EditorTextarea, { value: createText, onChange: (e) => setCreateText(e.target.value) })] }), _jsxs("div", { className: "se-flex se-gap-2 se-mt-2", children: [_jsx("button", { type: "button", onClick: handleCancelCreate, className: "se-flex-1 se-h-10 se-px-4 se-py-2 se-rounded-md se-border se-border-btn-neutral-border se-bg-btn-neutral se-text-btn-neutral-text se-text-sm se-font-medium se-cursor-pointer se-inline-flex se-items-center se-justify-center hover:se-text-btn-neutral-text-hover", children: "Cancel" }), _jsx("button", { type: "button", onClick: handleSaveCreate, disabled: !createAnchorId, className: "se-flex-1 se-h-10 se-px-4 se-py-2 se-rounded-md se-border-none se-bg-btn-primary se-text-btn-primary-text se-text-sm se-font-medium se-cursor-pointer se-inline-flex se-items-center se-justify-center hover:se-bg-btn-primary-hover disabled:se-opacity-50 disabled:se-pointer-events-none", children: "Add Change" })] })] })) : editingKey !== null ? (
261
+ /* ---- Edit mode ---- */
262
+ (() => {
263
+ const ref = parseItemKey(editingKey);
264
+ const editItem = allItems.find((it) => it.key === editingKey);
265
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "se-flex se-items-center se-gap-2 se-mb-3 se-text-lg se-font-semibold se-text-text-primary", children: [_jsx("span", { children: editItem && _jsx(SectionIcon, { section: editItem.section }) }), _jsx("span", { children: editItem?.summary })] }), renderEditFields(ref.section, ref.index)] }));
266
+ })()) : (
267
+ /* ---- List mode ---- */
268
+ _jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: handleStartCreate, className: "se-w-full se-h-10 se-px-4 se-py-2 se-rounded-md se-border se-border-dashed se-border-btn-primary/30 se-bg-btn-primary/5 se-text-btn-primary se-text-sm se-font-medium se-cursor-pointer se-flex se-items-center se-justify-center se-gap-2 se-mb-3", children: "+ Add Text Change" }), allItems.length === 0 && (_jsx(EmptyState, { message: "No content changes configured. Click above to add one." })), activeItems.length > 0 && (_jsxs(_Fragment, { children: [_jsx(GroupHeader, { label: "CONTENT", count: activeItems.length }), activeItems.map((item) => {
269
+ const detection = detectionMap.get(item.key);
270
+ return (_jsxs(EditorCard, { itemKey: item.key, onClick: () => handleCardClick(item), className: "se-flex se-items-center se-gap-2", onMouseEnter: () => handleCardHover(item), onMouseLeave: handleCardLeave, children: [_jsx(DetectionBadge, { found: detection?.found ?? false, onClick: () => handleBadgeClick(item) }), _jsx("span", { className: "se-shrink-0 se-flex se-items-center -se-ml-1", children: _jsx(SectionIcon, { section: item.section }) }), _jsx("span", { className: "se-flex-1 se-overflow-hidden se-text-ellipsis se-whitespace-nowrap", children: item.summary }), _jsx("button", { type: "button", className: "se-py-0.5 se-px-1.5 se-rounded se-border-none se-bg-transparent se-text-slate-grey-7 se-text-sm se-cursor-pointer se-shrink-0 se-leading-none", onClick: (e) => {
271
+ e.stopPropagation();
272
+ handleDismiss(item.key);
273
+ }, title: "Dismiss this change", children: "\u00D7" })] }, item.key));
274
+ })] })), dismissedItems.length > 0 && (_jsx(DismissedSection, { count: dismissedItems.length, children: dismissedItems.map((item) => (_jsxs("div", { className: "se-flex se-items-center se-gap-2 se-py-1.5 se-px-2.5 se-rounded-lg se-border se-border-white/[0.03] se-bg-transparent se-mb-0.5 se-cursor-pointer se-text-sm se-text-text-tertiary se-opacity-60", children: [_jsx("span", { className: "se-shrink-0 se-flex se-items-center -se-ml-1", children: _jsx(SectionIcon, { section: item.section }) }), _jsx("span", { className: "se-flex-1 se-overflow-hidden se-text-ellipsis se-whitespace-nowrap se-line-through", children: item.summary }), _jsx("button", { type: "button", className: "se-py-0.5 se-px-1.5 se-rounded se-border-none se-bg-transparent se-text-blue-5 se-text-[11px] se-cursor-pointer se-shrink-0 se-leading-none", onClick: (e) => {
275
+ e.stopPropagation();
276
+ handleRestore(item.key);
277
+ }, children: "Restore" })] }, item.key))) }))] })) }), _jsx(EditorFooter, { onSave: () => editor.save(), onPublish: handlePublish }), _jsx(AnchorPicker, { isActive: createMode === 'picking', onPick: handleElementPicked, onCancel: () => setCreateMode('form') })] }));
278
+ }
279
+ /**
280
+ * Editor module configuration.
281
+ */
282
+ export const editor = {
283
+ panel: {
284
+ title: 'Content',
285
+ icon: '\u{1f4dd}',
286
+ description: 'Text and attribute modifications',
287
+ },
288
+ component: ContentEditor,
289
+ };
290
+ export const editorPanel = editor.panel;
291
+ export default ContentEditor;
package/dist/editor.d.ts CHANGED
@@ -1,27 +1,9 @@
1
1
  /**
2
- * Adaptive Content - Editor Component
2
+ * Adaptive Content - Editor Module (barrel)
3
3
  *
4
- * Review & tweak editor for AI-generated content modifications.
5
- * Displays a scannable list of one-liner change summaries.
6
- * Clicking a card navigates to the element and shows a floating edit panel.
4
+ * Re-exports from the split state and UI modules for backward compatibility.
7
5
  */
8
- import type { EditorPanelProps } from './types';
9
- export declare function ContentEditor({ config, onChange, editor }: EditorPanelProps): import("react/jsx-runtime").JSX.Element;
10
- /**
11
- * Editor module configuration.
12
- */
13
- export declare const editor: {
14
- panel: {
15
- title: string;
16
- icon: string;
17
- description: string;
18
- };
19
- component: typeof ContentEditor;
20
- };
21
- export declare const editorPanel: {
22
- title: string;
23
- icon: string;
24
- description: string;
25
- };
6
+ import { ContentEditor } from './content-editor-ui';
7
+ export { ContentEditor, editor, editorPanel } from './content-editor-ui';
26
8
  export default ContentEditor;
27
9
  //# sourceMappingURL=editor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuBH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAkLhD,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,gBAAgB,2CAmkB3E;AAED;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;;;CAOlB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;CAAe,CAAC;AAExC,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzE,eAAe,aAAa,CAAC"}