@newtonedev/editor 0.1.8 → 0.1.9

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/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.regular,
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
- const currentState = latestStateRef.current;
476
- const updatedPresets = publishActivePreset(currentState);
477
- const [calibrations, fontMetrics] = await Promise.all([
478
- measureFontCalibrations(currentState.typography?.fonts),
479
- lookupFontMetrics(currentState.typography?.fonts, manifestUrl)
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
- const { error } = await persistence.onPublish({
482
- state: currentState,
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
  }