@newtonedev/editor 0.1.5 → 0.1.7
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/Editor.d.ts +1 -1
- package/dist/Editor.d.ts.map +1 -1
- package/dist/components/CodeBlock.d.ts.map +1 -1
- package/dist/components/ConfiguratorPanel.d.ts +17 -0
- package/dist/components/ConfiguratorPanel.d.ts.map +1 -0
- package/dist/components/FontPicker.d.ts +4 -2
- package/dist/components/FontPicker.d.ts.map +1 -1
- package/dist/components/PresetSelector.d.ts.map +1 -1
- package/dist/components/PreviewWindow.d.ts +9 -3
- package/dist/components/PreviewWindow.d.ts.map +1 -1
- package/dist/components/PrimaryNav.d.ts +7 -0
- package/dist/components/PrimaryNav.d.ts.map +1 -0
- package/dist/components/RightSidebar.d.ts +4 -1
- package/dist/components/RightSidebar.d.ts.map +1 -1
- package/dist/components/Sidebar.d.ts +1 -10
- package/dist/components/Sidebar.d.ts.map +1 -1
- package/dist/components/TableOfContents.d.ts +2 -1
- package/dist/components/TableOfContents.d.ts.map +1 -1
- package/dist/components/sections/DynamicRangeSection.d.ts.map +1 -1
- package/dist/components/sections/FontsSection.d.ts +3 -1
- package/dist/components/sections/FontsSection.d.ts.map +1 -1
- package/dist/hooks/useEditorState.d.ts +4 -1
- package/dist/hooks/useEditorState.d.ts.map +1 -1
- package/dist/index.cjs +2893 -2248
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2895 -2251
- package/dist/index.js.map +1 -1
- package/dist/preview/ComponentDetailView.d.ts +9 -2
- package/dist/preview/ComponentDetailView.d.ts.map +1 -1
- package/dist/preview/ComponentRenderer.d.ts +2 -1
- package/dist/preview/ComponentRenderer.d.ts.map +1 -1
- package/dist/preview/IconBrowserView.d.ts +7 -0
- package/dist/preview/IconBrowserView.d.ts.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/lookupFontMetrics.d.ts +19 -0
- package/dist/utils/lookupFontMetrics.d.ts.map +1 -0
- package/dist/utils/measureFonts.d.ts +18 -0
- package/dist/utils/measureFonts.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/Editor.tsx +57 -11
- package/src/components/CodeBlock.tsx +42 -14
- package/src/components/ConfiguratorPanel.tsx +77 -0
- package/src/components/FontPicker.tsx +38 -29
- package/src/components/PresetSelector.tsx +8 -33
- package/src/components/PreviewWindow.tsx +20 -4
- package/src/components/PrimaryNav.tsx +76 -0
- package/src/components/RightSidebar.tsx +103 -40
- package/src/components/Sidebar.tsx +4 -211
- package/src/components/TableOfContents.tsx +41 -78
- package/src/components/sections/DynamicRangeSection.tsx +2 -225
- package/src/components/sections/FontsSection.tsx +61 -93
- package/src/hooks/useEditorState.ts +68 -9
- package/src/index.ts +2 -0
- package/src/preview/ComponentDetailView.tsx +576 -73
- package/src/preview/ComponentRenderer.tsx +6 -4
- package/src/preview/IconBrowserView.tsx +187 -0
- package/src/types.ts +15 -0
- package/src/utils/lookupFontMetrics.ts +52 -0
- package/src/utils/measureFonts.ts +41 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useCallback, useRef, useEffect, useMemo } from "react";
|
|
2
|
-
import { getComponent } from "@newtonedev/components";
|
|
2
|
+
import { getComponent, CATEGORIES, getComponentsByCategory } from "@newtonedev/components";
|
|
3
3
|
import type { ColorMode } from "@newtonedev/components";
|
|
4
4
|
import type { ConfiguratorState } from "@newtonedev/configurator";
|
|
5
5
|
import { useConfigurator, usePreviewColors } from "@newtonedev/configurator";
|
|
@@ -11,6 +11,8 @@ import type {
|
|
|
11
11
|
SidebarSelection,
|
|
12
12
|
EditorPersistence,
|
|
13
13
|
} from "../types";
|
|
14
|
+
import { measureFontCalibrations } from "../utils/measureFonts";
|
|
15
|
+
import { lookupFontMetrics } from "../utils/lookupFontMetrics";
|
|
14
16
|
|
|
15
17
|
interface UseEditorStateOptions {
|
|
16
18
|
readonly initialState: ConfiguratorState;
|
|
@@ -22,6 +24,7 @@ interface UseEditorStateOptions {
|
|
|
22
24
|
readonly persistence: EditorPersistence;
|
|
23
25
|
readonly onNavigate?: (view: PreviewView) => void;
|
|
24
26
|
readonly initialPreviewView?: PreviewView;
|
|
27
|
+
readonly manifestUrl?: string;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
export function useEditorState({
|
|
@@ -34,6 +37,7 @@ export function useEditorState({
|
|
|
34
37
|
persistence,
|
|
35
38
|
onNavigate,
|
|
36
39
|
initialPreviewView,
|
|
40
|
+
manifestUrl,
|
|
37
41
|
}: UseEditorStateOptions) {
|
|
38
42
|
// --- Configurator state management ---
|
|
39
43
|
const {
|
|
@@ -52,6 +56,9 @@ export function useEditorState({
|
|
|
52
56
|
const [previewView, setPreviewView] = useState<PreviewView>(
|
|
53
57
|
initialPreviewView ?? { kind: "overview" },
|
|
54
58
|
);
|
|
59
|
+
const [activeSectionId, setActiveSectionId] = useState<string>(
|
|
60
|
+
CATEGORIES[0]?.id ?? "colors",
|
|
61
|
+
);
|
|
55
62
|
const [sidebarSelection, setSidebarSelection] =
|
|
56
63
|
useState<SidebarSelection>(null);
|
|
57
64
|
const [propOverrides, setPropOverrides] = useState<Record<string, unknown>>(
|
|
@@ -159,10 +166,13 @@ export function useEditorState({
|
|
|
159
166
|
onNavigate?.(view);
|
|
160
167
|
|
|
161
168
|
if (view.kind === "component") {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
const comp = getComponent(view.componentId);
|
|
170
|
+
const firstVariantId = comp?.variants[0]?.id;
|
|
171
|
+
setSidebarSelection(
|
|
172
|
+
firstVariantId
|
|
173
|
+
? { scope: "variant", componentId: view.componentId, variantId: firstVariantId }
|
|
174
|
+
: { scope: "component", componentId: view.componentId },
|
|
175
|
+
);
|
|
166
176
|
initOverridesFromVariant(view.componentId);
|
|
167
177
|
} else {
|
|
168
178
|
setSidebarSelection(null);
|
|
@@ -172,6 +182,36 @@ export function useEditorState({
|
|
|
172
182
|
[onNavigate, initOverridesFromVariant],
|
|
173
183
|
);
|
|
174
184
|
|
|
185
|
+
const handleSectionChange = useCallback(
|
|
186
|
+
(sectionId: string) => {
|
|
187
|
+
setActiveSectionId(sectionId);
|
|
188
|
+
|
|
189
|
+
const sectionComponents = getComponentsByCategory(sectionId);
|
|
190
|
+
if (sectionComponents.length === 1) {
|
|
191
|
+
// Single-component sections (e.g. Typography, Symbols) skip
|
|
192
|
+
// the category overview and navigate directly to the component.
|
|
193
|
+
const comp = sectionComponents[0];
|
|
194
|
+
const view: PreviewView = { kind: "component", componentId: comp.id };
|
|
195
|
+
setPreviewView(view);
|
|
196
|
+
onNavigate?.(view);
|
|
197
|
+
const firstVariantId = comp.variants[0]?.id;
|
|
198
|
+
setSidebarSelection(
|
|
199
|
+
firstVariantId
|
|
200
|
+
? { scope: "variant", componentId: comp.id, variantId: firstVariantId }
|
|
201
|
+
: { scope: "component", componentId: comp.id },
|
|
202
|
+
);
|
|
203
|
+
initOverridesFromVariant(comp.id);
|
|
204
|
+
} else {
|
|
205
|
+
const view: PreviewView = { kind: "category", categoryId: sectionId };
|
|
206
|
+
setPreviewView(view);
|
|
207
|
+
onNavigate?.(view);
|
|
208
|
+
setSidebarSelection(null);
|
|
209
|
+
setPropOverrides({});
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
[onNavigate, initOverridesFromVariant],
|
|
213
|
+
);
|
|
214
|
+
|
|
175
215
|
const handleSelectVariant = useCallback(
|
|
176
216
|
(variantId: string) => {
|
|
177
217
|
if (previewView.kind === "component") {
|
|
@@ -201,9 +241,20 @@ export function useEditorState({
|
|
|
201
241
|
}
|
|
202
242
|
}, [sidebarSelection, initOverridesFromVariant]);
|
|
203
243
|
|
|
204
|
-
const handlePropOverride = useCallback(
|
|
205
|
-
|
|
206
|
-
|
|
244
|
+
const handlePropOverride = useCallback(
|
|
245
|
+
(propName: string, value: unknown) => {
|
|
246
|
+
setPropOverrides((prev) => ({ ...prev, [propName]: value }));
|
|
247
|
+
// Re-open sidebar if closed while viewing a component (e.g. icon browser click)
|
|
248
|
+
setSidebarSelection((prev) => {
|
|
249
|
+
if (prev !== null) return prev;
|
|
250
|
+
if (previewView.kind === "component") {
|
|
251
|
+
return { scope: "component", componentId: previewView.componentId };
|
|
252
|
+
}
|
|
253
|
+
return prev;
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
[previewView],
|
|
257
|
+
);
|
|
207
258
|
|
|
208
259
|
const handleResetOverrides = useCallback(() => {
|
|
209
260
|
if (sidebarSelection?.scope === "variant") {
|
|
@@ -265,11 +316,17 @@ export function useEditorState({
|
|
|
265
316
|
|
|
266
317
|
const currentState = latestStateRef.current;
|
|
267
318
|
const updatedPresets = publishActivePreset(currentState);
|
|
319
|
+
const [calibrations, fontMetrics] = await Promise.all([
|
|
320
|
+
measureFontCalibrations(currentState.typography?.fonts),
|
|
321
|
+
lookupFontMetrics(currentState.typography?.fonts, manifestUrl),
|
|
322
|
+
]);
|
|
268
323
|
|
|
269
324
|
const { error } = await persistence.onPublish({
|
|
270
325
|
state: currentState,
|
|
271
326
|
presets: updatedPresets,
|
|
272
327
|
activePresetId,
|
|
328
|
+
calibrations,
|
|
329
|
+
fontMetrics,
|
|
273
330
|
});
|
|
274
331
|
|
|
275
332
|
if (!error) {
|
|
@@ -277,7 +334,7 @@ export function useEditorState({
|
|
|
277
334
|
setIsPublished(true);
|
|
278
335
|
}
|
|
279
336
|
setPublishing(false);
|
|
280
|
-
}, [activePresetId, publishActivePreset, persistence]);
|
|
337
|
+
}, [activePresetId, publishActivePreset, persistence, manifestUrl]);
|
|
281
338
|
|
|
282
339
|
// --- beforeunload warning ---
|
|
283
340
|
useEffect(() => {
|
|
@@ -331,7 +388,9 @@ export function useEditorState({
|
|
|
331
388
|
// Preview
|
|
332
389
|
previewView,
|
|
333
390
|
colorMode,
|
|
391
|
+
activeSectionId,
|
|
334
392
|
handlePreviewNavigate,
|
|
393
|
+
handleSectionChange,
|
|
335
394
|
handleSelectVariant,
|
|
336
395
|
handleColorModeChange,
|
|
337
396
|
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type {
|
|
|
7
7
|
EditorPersistence,
|
|
8
8
|
EditorHeaderSlots,
|
|
9
9
|
EditorProps,
|
|
10
|
+
EditorFontEntry,
|
|
10
11
|
} from "./types";
|
|
11
12
|
|
|
12
13
|
// Utilities
|
|
@@ -30,6 +31,7 @@ export { EditorHeader } from "./components/EditorHeader";
|
|
|
30
31
|
export { EditorShell } from "./components/EditorShell";
|
|
31
32
|
export { FontPicker } from "./components/FontPicker";
|
|
32
33
|
export { PresetSelector } from "./components/PresetSelector";
|
|
34
|
+
export { PrimaryNav } from "./components/PrimaryNav";
|
|
33
35
|
export { PreviewWindow } from "./components/PreviewWindow";
|
|
34
36
|
export { RightSidebar } from "./components/RightSidebar";
|
|
35
37
|
export { Sidebar } from "./components/Sidebar";
|