@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/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/hooks/useEditorState.ts +30 -18
- package/src/utils/lookupFontMetrics.ts +1 -0
- package/src/utils/measureFonts.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lookupFontMetrics.d.ts","sourceRoot":"","sources":["../../src/utils/lookupFontMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,SAAS,EAC9C,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"lookupFontMetrics.d.ts","sourceRoot":"","sources":["../../src/utils/lookupFontMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,SAAS,EAC9C,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CA+B7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measureFonts.d.ts","sourceRoot":"","sources":["../../src/utils/measureFonts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,SAAS,GAC7C,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"measureFonts.d.ts","sourceRoot":"","sources":["../../src/utils/measureFonts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,SAAS,GAC7C,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAqBjC"}
|
package/package.json
CHANGED
|
@@ -314,26 +314,38 @@ export function useEditorState({
|
|
|
314
314
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
315
315
|
setPublishing(true);
|
|
316
316
|
|
|
317
|
+
const timeout = new Promise<never>((_, reject) =>
|
|
318
|
+
setTimeout(() => reject(new Error('Publish timed out after 15 s')), 15_000),
|
|
319
|
+
);
|
|
320
|
+
|
|
317
321
|
try {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
322
|
+
await Promise.race([
|
|
323
|
+
(async () => {
|
|
324
|
+
const currentState = latestStateRef.current;
|
|
325
|
+
const updatedPresets = publishActivePreset(currentState);
|
|
326
|
+
const [calibrations, fontMetrics] = await Promise.all([
|
|
327
|
+
measureFontCalibrations(currentState.typography?.fonts),
|
|
328
|
+
lookupFontMetrics(currentState.typography?.fonts, manifestUrl),
|
|
329
|
+
]);
|
|
330
|
+
|
|
331
|
+
const { error } = await persistence.onPublish({
|
|
332
|
+
state: currentState,
|
|
333
|
+
presets: updatedPresets,
|
|
334
|
+
activePresetId,
|
|
335
|
+
calibrations,
|
|
336
|
+
fontMetrics,
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
if (!error) {
|
|
340
|
+
setSaveStatus("saved");
|
|
341
|
+
setIsPublished(true);
|
|
342
|
+
}
|
|
343
|
+
})(),
|
|
344
|
+
timeout,
|
|
323
345
|
]);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
presets: updatedPresets,
|
|
328
|
-
activePresetId,
|
|
329
|
-
calibrations,
|
|
330
|
-
fontMetrics,
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
if (!error) {
|
|
334
|
-
setSaveStatus("saved");
|
|
335
|
-
setIsPublished(true);
|
|
336
|
-
}
|
|
346
|
+
} catch (err) {
|
|
347
|
+
// Log publish failures (timeout, network, RLS) for debugging
|
|
348
|
+
console.error('[Editor] Publish failed:', err);
|
|
337
349
|
} finally {
|
|
338
350
|
setPublishing(false);
|
|
339
351
|
}
|
|
@@ -31,6 +31,7 @@ export async function lookupFontMetrics(
|
|
|
31
31
|
const seen = new Set<string>();
|
|
32
32
|
|
|
33
33
|
for (const slot of Object.values(fonts) as FontSlot[]) {
|
|
34
|
+
if (!slot?.config) continue;
|
|
34
35
|
const family = slot.config.family;
|
|
35
36
|
if (seen.has(family)) continue;
|
|
36
37
|
seen.add(family);
|
|
@@ -25,13 +25,14 @@ export async function measureFontCalibrations(
|
|
|
25
25
|
const seen = new Set<string>();
|
|
26
26
|
|
|
27
27
|
for (const slot of Object.values(fonts) as FontSlot[]) {
|
|
28
|
+
if (!slot?.config) continue;
|
|
28
29
|
const { family, fallback } = slot.config;
|
|
29
30
|
if (seen.has(family)) continue;
|
|
30
31
|
seen.add(family);
|
|
31
32
|
|
|
32
33
|
const ratio = await measureAvgCharWidth(
|
|
33
34
|
family,
|
|
34
|
-
slot.weights
|
|
35
|
+
slot.weights?.regular ?? 400,
|
|
35
36
|
fallback,
|
|
36
37
|
);
|
|
37
38
|
calibrations[family] = ratio;
|