@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.
@@ -1 +1 @@
1
- {"version":3,"file":"useEditorState.d.ts","sourceRoot":"","sources":["../../src/hooks/useEditorState.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EACV,MAAM,EACN,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAIlB,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;IACzC,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,wBAAwB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,kBAAkB,CAAC,EAAE,WAAW,CAAC;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,cAAc,CAAC,EAC7B,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,wBAAwB,EACxB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,WAAW,GACZ,EAAE,qBAAqB;;;;;;;;;gCAsON,iBAAiB;;;;2CA3GxB,WAAW;8CAsBN,MAAM;8CA8BN,MAAM;2CAwF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AkMpC"}
package/dist/index.cjs CHANGED
@@ -198,12 +198,13 @@ async function measureFontCalibrations(fonts) {
198
198
  const calibrations = {};
199
199
  const seen = /* @__PURE__ */ new Set();
200
200
  for (const slot of Object.values(fonts)) {
201
+ if (!slot?.config) continue;
201
202
  const { family, fallback } = slot.config;
202
203
  if (seen.has(family)) continue;
203
204
  seen.add(family);
204
205
  const ratio = await components.measureAvgCharWidth(
205
206
  family,
206
- slot.weights.regular,
207
+ slot.weights?.regular ?? 400,
207
208
  fallback
208
209
  );
209
210
  calibrations[family] = ratio;
@@ -221,6 +222,7 @@ async function lookupFontMetrics(fonts, manifestUrl) {
221
222
  const result = {};
222
223
  const seen = /* @__PURE__ */ new Set();
223
224
  for (const slot of Object.values(fonts)) {
225
+ if (!slot?.config) continue;
224
226
  const family = slot.config.family;
225
227
  if (seen.has(family)) continue;
226
228
  seen.add(family);
@@ -473,24 +475,34 @@ function useEditorState({
473
475
  const handlePublish = react.useCallback(async () => {
474
476
  if (debounceRef.current) clearTimeout(debounceRef.current);
475
477
  setPublishing(true);
478
+ const timeout = new Promise(
479
+ (_, reject) => setTimeout(() => reject(new Error("Publish timed out after 15 s")), 15e3)
480
+ );
476
481
  try {
477
- const currentState = latestStateRef.current;
478
- const updatedPresets = publishActivePreset(currentState);
479
- const [calibrations, fontMetrics] = await Promise.all([
480
- measureFontCalibrations(currentState.typography?.fonts),
481
- lookupFontMetrics(currentState.typography?.fonts, manifestUrl)
482
+ await Promise.race([
483
+ (async () => {
484
+ const currentState = latestStateRef.current;
485
+ const updatedPresets = publishActivePreset(currentState);
486
+ const [calibrations, fontMetrics] = await Promise.all([
487
+ measureFontCalibrations(currentState.typography?.fonts),
488
+ lookupFontMetrics(currentState.typography?.fonts, manifestUrl)
489
+ ]);
490
+ const { error } = await persistence.onPublish({
491
+ state: currentState,
492
+ presets: updatedPresets,
493
+ activePresetId,
494
+ calibrations,
495
+ fontMetrics
496
+ });
497
+ if (!error) {
498
+ setSaveStatus("saved");
499
+ setIsPublished(true);
500
+ }
501
+ })(),
502
+ timeout
482
503
  ]);
483
- const { error } = await persistence.onPublish({
484
- state: currentState,
485
- presets: updatedPresets,
486
- activePresetId,
487
- calibrations,
488
- fontMetrics
489
- });
490
- if (!error) {
491
- setSaveStatus("saved");
492
- setIsPublished(true);
493
- }
504
+ } catch (err) {
505
+ console.error("[Editor] Publish failed:", err);
494
506
  } finally {
495
507
  setPublishing(false);
496
508
  }