@newtonedev/editor 0.1.8 → 0.1.10
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/hooks/useEditorState.d.ts.map +1 -1
- package/dist/index.cjs +29 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -17
- package/dist/index.js.map +1 -1
- package/dist/utils/lookupFontMetrics.d.ts.map +1 -1
- package/dist/utils/measureFonts.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Editor.tsx +10 -8
- package/src/components/ConfiguratorPanel.tsx +1 -1
- package/src/components/EditorHeader.tsx +28 -1
- package/src/components/PrimaryNav.tsx +8 -1
- package/src/components/Sidebar.tsx +0 -32
- package/src/components/TableOfContents.tsx +1 -1
- package/src/hooks/useEditorState.ts +38 -24
- package/src/preview/ComponentDetailView.tsx +2 -2
- package/src/types.ts +2 -0
- package/src/utils/lookupFontMetrics.ts +1 -0
- package/src/utils/measureFonts.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -196,12 +196,13 @@ async function measureFontCalibrations(fonts) {
|
|
|
196
196
|
const calibrations = {};
|
|
197
197
|
const seen = /* @__PURE__ */ new Set();
|
|
198
198
|
for (const slot of Object.values(fonts)) {
|
|
199
|
+
if (!slot?.config) continue;
|
|
199
200
|
const { family, fallback } = slot.config;
|
|
200
201
|
if (seen.has(family)) continue;
|
|
201
202
|
seen.add(family);
|
|
202
203
|
const ratio = await measureAvgCharWidth(
|
|
203
204
|
family,
|
|
204
|
-
slot.weights
|
|
205
|
+
slot.weights?.regular ?? 400,
|
|
205
206
|
fallback
|
|
206
207
|
);
|
|
207
208
|
calibrations[family] = ratio;
|
|
@@ -219,6 +220,7 @@ async function lookupFontMetrics(fonts, manifestUrl) {
|
|
|
219
220
|
const result = {};
|
|
220
221
|
const seen = /* @__PURE__ */ new Set();
|
|
221
222
|
for (const slot of Object.values(fonts)) {
|
|
223
|
+
if (!slot?.config) continue;
|
|
222
224
|
const family = slot.config.family;
|
|
223
225
|
if (seen.has(family)) continue;
|
|
224
226
|
seen.add(family);
|
|
@@ -471,24 +473,34 @@ function useEditorState({
|
|
|
471
473
|
const handlePublish = useCallback(async () => {
|
|
472
474
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
473
475
|
setPublishing(true);
|
|
476
|
+
const timeout = new Promise(
|
|
477
|
+
(_, reject) => setTimeout(() => reject(new Error("Publish timed out after 15 s")), 15e3)
|
|
478
|
+
);
|
|
474
479
|
try {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
+
await Promise.race([
|
|
481
|
+
(async () => {
|
|
482
|
+
const currentState = latestStateRef.current;
|
|
483
|
+
const updatedPresets = publishActivePreset(currentState);
|
|
484
|
+
const [calibrations, fontMetrics] = await Promise.all([
|
|
485
|
+
measureFontCalibrations(currentState.typography?.fonts),
|
|
486
|
+
lookupFontMetrics(currentState.typography?.fonts, manifestUrl)
|
|
487
|
+
]);
|
|
488
|
+
const { error } = await persistence.onPublish({
|
|
489
|
+
state: currentState,
|
|
490
|
+
presets: updatedPresets,
|
|
491
|
+
activePresetId,
|
|
492
|
+
calibrations,
|
|
493
|
+
fontMetrics
|
|
494
|
+
});
|
|
495
|
+
if (!error) {
|
|
496
|
+
setSaveStatus("saved");
|
|
497
|
+
setIsPublished(true);
|
|
498
|
+
}
|
|
499
|
+
})(),
|
|
500
|
+
timeout
|
|
480
501
|
]);
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
presets: updatedPresets,
|
|
484
|
-
activePresetId,
|
|
485
|
-
calibrations,
|
|
486
|
-
fontMetrics
|
|
487
|
-
});
|
|
488
|
-
if (!error) {
|
|
489
|
-
setSaveStatus("saved");
|
|
490
|
-
setIsPublished(true);
|
|
491
|
-
}
|
|
502
|
+
} catch (err) {
|
|
503
|
+
console.error("[Editor] Publish failed:", err);
|
|
492
504
|
} finally {
|
|
493
505
|
setPublishing(false);
|
|
494
506
|
}
|