@liiift-studio/sanity-font-manager 2.4.0 → 2.5.0
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/UploadModal-6LIX7XOK.js +6 -0
- package/dist/UploadModal-NME2W53V.mjs +6 -0
- package/dist/chunk-646WCBRR.mjs +7276 -0
- package/dist/chunk-FH4QKHOH.js +7276 -0
- package/dist/index.js +664 -1647
- package/dist/index.mjs +317 -1209
- package/package.json +5 -5
- package/src/components/BatchUploadFonts.jsx +57 -44
- package/src/components/BulkActions.jsx +99 -0
- package/src/components/ExistingDocumentResolver.jsx +152 -0
- package/src/components/FontReviewCard.jsx +415 -0
- package/src/components/SingleUploaderTool.jsx +3 -4
- package/src/components/UploadModal.jsx +268 -0
- package/src/components/UploadScriptsComponent.jsx +23 -21
- package/src/components/UploadStep1Settings.jsx +272 -0
- package/src/components/UploadStep2Review.jsx +472 -0
- package/src/components/UploadStep3Execute.jsx +234 -0
- package/src/components/UploadSummary.jsx +196 -0
- package/src/index.js +45 -0
- package/src/utils/buildUploadPlan.js +325 -0
- package/src/utils/executeUploadPlan.js +437 -0
- package/src/utils/executionReducer.js +56 -0
- package/src/utils/fontHelpers.js +267 -0
- package/src/utils/generateCssFile.js +79 -77
- package/src/utils/generateFontData.js +47 -94
- package/src/utils/getEmptyFontKit.js +19 -17
- package/src/utils/parseFont.js +55 -0
- package/src/utils/planReducer.js +517 -0
- package/src/utils/planTypes.js +183 -0
- package/src/utils/processFontFiles.js +120 -78
- package/src/utils/regenerateFontData.js +2 -2
- package/src/utils/resolveExistingFont.js +87 -0
- package/src/utils/uploadFontFiles.js +405 -405
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
// Per-font review row — table-style header with expandable detail panel
|
|
2
|
+
|
|
3
|
+
import React, { useState, useCallback, useEffect, useMemo, memo } from 'react';
|
|
4
|
+
import { Card, Stack, Flex, Box, Text, TextInput, Badge, Button, Select, Tooltip, Label } from '@sanity/ui';
|
|
5
|
+
import { ChevronDownIcon, ChevronRightIcon, TrashIcon, ResetIcon, InfoOutlineIcon } from '@sanity/icons';
|
|
6
|
+
import { FONT_STATUS, RECOMMENDATION } from '../utils/planTypes';
|
|
7
|
+
import ExistingDocumentResolver from './ExistingDocumentResolver';
|
|
8
|
+
|
|
9
|
+
/** Standard file types shown in the files row */
|
|
10
|
+
const STANDARD_TYPES = ['ttf', 'otf', 'woff', 'woff2'];
|
|
11
|
+
/** Extended file types shown when expanded */
|
|
12
|
+
const EXTENDED_TYPES = ['eot', 'svg', 'css', 'woff2_subset', 'woff2_web'];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Collapsible review card for a single font in the upload plan.
|
|
16
|
+
* Table-style header row with weight/style/files/action columns.
|
|
17
|
+
*/
|
|
18
|
+
const FontReviewCard = memo(function FontReviewCard({ entry, dispatch, allExpanded }) {
|
|
19
|
+
const [expanded, setExpanded] = useState(false);
|
|
20
|
+
const [showAllFileTypes, setShowAllFileTypes] = useState(false);
|
|
21
|
+
|
|
22
|
+
// Sync with allExpanded toggle from BulkActions
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
setExpanded(allExpanded);
|
|
25
|
+
}, [allExpanded]);
|
|
26
|
+
|
|
27
|
+
// Local state for typing — dispatches on blur
|
|
28
|
+
const [localTitle, setLocalTitle] = useState(entry.title);
|
|
29
|
+
const [localWeight, setLocalWeight] = useState(String(entry.weight));
|
|
30
|
+
const [localWeightName, setLocalWeightName] = useState(entry.weightName);
|
|
31
|
+
const [localSubfamily, setLocalSubfamily] = useState(entry.subfamily);
|
|
32
|
+
|
|
33
|
+
const [localDocId, setLocalDocId] = useState(entry.documentId);
|
|
34
|
+
|
|
35
|
+
const isError = entry.status === FONT_STATUS.ERROR;
|
|
36
|
+
const hasConflict = entry._idConflict;
|
|
37
|
+
const resolution = entry.decisions?.existingDocument;
|
|
38
|
+
const isUpdate = resolution?.userChoice === 'update' ||
|
|
39
|
+
(!resolution?.userChoice && (resolution?.recommendation === RECOMMENDATION.USE_EXACT || resolution?.recommendation === RECOMMENDATION.USE_CANDIDATE));
|
|
40
|
+
|
|
41
|
+
// Document ID is editable when user chose "create new" on a font with an existing match
|
|
42
|
+
const isCreateNewOverride = resolution?.userChoice === 'create' &&
|
|
43
|
+
(resolution?.exact || resolution?.candidates?.length > 0);
|
|
44
|
+
const docIdEditable = isCreateNewOverride || hasConflict;
|
|
45
|
+
|
|
46
|
+
// Detect if user has overridden any suggestions
|
|
47
|
+
const hasUserOverrides = useMemo(() => {
|
|
48
|
+
const d = entry.decisions;
|
|
49
|
+
if (!d) return false;
|
|
50
|
+
return (
|
|
51
|
+
d.title?.userOverride != null ||
|
|
52
|
+
d.weight?.userOverride != null ||
|
|
53
|
+
d.weightName?.userOverride != null ||
|
|
54
|
+
d.style?.userOverride != null ||
|
|
55
|
+
d.subfamily?.userOverride != null ||
|
|
56
|
+
d.documentId?.userOverride != null
|
|
57
|
+
);
|
|
58
|
+
}, [entry.decisions]);
|
|
59
|
+
|
|
60
|
+
// Map of which file extensions are present
|
|
61
|
+
const fileExtMap = useMemo(() => {
|
|
62
|
+
const map = {};
|
|
63
|
+
(entry.files || []).forEach(f => {
|
|
64
|
+
const ext = f.name?.split('.').pop()?.toLowerCase();
|
|
65
|
+
if (ext) map[ext] = f.name;
|
|
66
|
+
});
|
|
67
|
+
return map;
|
|
68
|
+
}, [entry.files]);
|
|
69
|
+
|
|
70
|
+
const fileCount = entry.files?.length || 0;
|
|
71
|
+
const cardTone = isError ? 'critical' : hasConflict ? 'caution' : 'default';
|
|
72
|
+
|
|
73
|
+
const handleTitleBlur = useCallback(() => {
|
|
74
|
+
if (localTitle !== entry.title) {
|
|
75
|
+
dispatch({ type: 'SET_FONT_TITLE', tempId: entry.tempId, title: localTitle });
|
|
76
|
+
}
|
|
77
|
+
}, [localTitle, entry.title, entry.tempId, dispatch]);
|
|
78
|
+
|
|
79
|
+
const handleDocIdBlur = useCallback(() => {
|
|
80
|
+
if (localDocId !== entry.documentId) {
|
|
81
|
+
dispatch({ type: 'SET_FONT_DOCUMENT_ID', tempId: entry.tempId, documentId: localDocId });
|
|
82
|
+
}
|
|
83
|
+
}, [localDocId, entry.documentId, entry.tempId, dispatch]);
|
|
84
|
+
|
|
85
|
+
const handleWeightBlur = useCallback(() => {
|
|
86
|
+
const num = Number(localWeight);
|
|
87
|
+
if (!isNaN(num) && num !== entry.weight) {
|
|
88
|
+
dispatch({ type: 'SET_FONT_WEIGHT', tempId: entry.tempId, weight: num });
|
|
89
|
+
}
|
|
90
|
+
}, [localWeight, entry.weight, entry.tempId, dispatch]);
|
|
91
|
+
|
|
92
|
+
const handleWeightNameBlur = useCallback(() => {
|
|
93
|
+
if (localWeightName !== entry.weightName) {
|
|
94
|
+
dispatch({ type: 'SET_FONT_WEIGHT_NAME', tempId: entry.tempId, weightName: localWeightName });
|
|
95
|
+
}
|
|
96
|
+
}, [localWeightName, entry.weightName, entry.tempId, dispatch]);
|
|
97
|
+
|
|
98
|
+
const handleStyleChange = useCallback((e) => {
|
|
99
|
+
dispatch({ type: 'SET_FONT_STYLE', tempId: entry.tempId, style: e.target.value });
|
|
100
|
+
}, [entry.tempId, dispatch]);
|
|
101
|
+
|
|
102
|
+
const handleSubfamilyBlur = useCallback(() => {
|
|
103
|
+
if (localSubfamily !== entry.subfamily) {
|
|
104
|
+
dispatch({ type: 'SET_FONT_SUBFAMILY', tempId: entry.tempId, subfamily: localSubfamily });
|
|
105
|
+
}
|
|
106
|
+
}, [localSubfamily, entry.subfamily, entry.tempId, dispatch]);
|
|
107
|
+
|
|
108
|
+
const handleReset = useCallback(() => {
|
|
109
|
+
dispatch({ type: 'RESET_FONT_TO_SUGGESTIONS', tempId: entry.tempId });
|
|
110
|
+
setLocalTitle(entry.decisions.title.processed);
|
|
111
|
+
setLocalDocId(entry.decisions.documentId.generated);
|
|
112
|
+
setLocalWeight(String(entry.decisions.weight.detected));
|
|
113
|
+
setLocalWeightName(entry.decisions.weightName.detected);
|
|
114
|
+
setLocalSubfamily(entry.decisions.subfamily.detected || 'Regular');
|
|
115
|
+
}, [entry, dispatch]);
|
|
116
|
+
|
|
117
|
+
const handleRemove = useCallback(() => {
|
|
118
|
+
dispatch({ type: 'REMOVE_FONT', tempId: entry.tempId });
|
|
119
|
+
}, [entry.tempId, dispatch]);
|
|
120
|
+
|
|
121
|
+
/** Format source string — converts nameId references to readable format, appends user override if present */
|
|
122
|
+
const formatSource = (decision) => {
|
|
123
|
+
if (!decision) return null;
|
|
124
|
+
let src = decision.source || '';
|
|
125
|
+
// Format name table references: nameId1-familyName → nameId1 (familyName)
|
|
126
|
+
src = src.replace(/nameId(\d+)-(\w+)/g, 'nameId$1 ($2)');
|
|
127
|
+
src = src.replace(/-/g, ' ').replace('fontkit ', '');
|
|
128
|
+
// Special case: default-empty for subfamily
|
|
129
|
+
if (src === 'default empty' && decision.detected === '') {
|
|
130
|
+
src = 'empty — defaults to "Regular"';
|
|
131
|
+
}
|
|
132
|
+
const reason = decision.reason ? ` (${decision.reason})` : '';
|
|
133
|
+
const override = decision.userOverride != null ? ' (user override)' : '';
|
|
134
|
+
return `Source: ${src}${reason}${override}`;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<Card border radius={2} tone={cardTone} style={{ marginBottom: -1 }}>
|
|
139
|
+
{/* Header row — table-style columns */}
|
|
140
|
+
<Box
|
|
141
|
+
as="button"
|
|
142
|
+
onClick={() => !isError && setExpanded(v => !v)}
|
|
143
|
+
style={{
|
|
144
|
+
width: '100%',
|
|
145
|
+
background: expanded ? 'var(--card-muted-bg-color)' : 'none',
|
|
146
|
+
border: 'none',
|
|
147
|
+
cursor: isError ? 'default' : 'pointer',
|
|
148
|
+
textAlign: 'left',
|
|
149
|
+
padding: 0,
|
|
150
|
+
transition: 'background 0.1s ease',
|
|
151
|
+
}}
|
|
152
|
+
onMouseEnter={(e) => { if (!isError && !expanded) e.currentTarget.style.background = 'var(--card-muted-bg-color)'; }}
|
|
153
|
+
onMouseLeave={(e) => { if (!expanded) e.currentTarget.style.background = 'none'; }}
|
|
154
|
+
>
|
|
155
|
+
<Flex align="center" gap={2} paddingX={2} paddingY={2}>
|
|
156
|
+
<Box style={{ width: 20, flexShrink: 0 }}>
|
|
157
|
+
{!isError && (expanded ? <ChevronDownIcon /> : <ChevronRightIcon />)}
|
|
158
|
+
</Box>
|
|
159
|
+
<Box style={{ flex: 1, whiteSpace: 'nowrap',}}>
|
|
160
|
+
<Text size={1} weight="semibold" style={{ whiteSpace: 'nowrap' }}>
|
|
161
|
+
{entry.title || entry.sourceFileName}
|
|
162
|
+
{entry.variableFont && <Badge tone="primary" fontSize={0} style={{ marginLeft: 6 }}>VF</Badge>}
|
|
163
|
+
{hasConflict && <Badge tone="caution" fontSize={0} style={{ marginLeft: 6 }}>ID Conflict</Badge>}
|
|
164
|
+
</Text>
|
|
165
|
+
</Box>
|
|
166
|
+
<Text size={0} style={{ width: 50, textAlign: 'center', flexShrink: 0 }}>{entry.weight}</Text>
|
|
167
|
+
<Text size={0} style={{ width: 50, textAlign: 'center', flexShrink: 0 }}>{entry.style}</Text>
|
|
168
|
+
<Text size={0} style={{ width: 40, textAlign: 'center', flexShrink: 0 }}>{fileCount}</Text>
|
|
169
|
+
<Box style={{ width: 55, textAlign: 'center', flexShrink: 0 }}>
|
|
170
|
+
<Badge tone={isError ? 'critical' : isUpdate ? 'caution' : 'positive'} fontSize={0}>
|
|
171
|
+
{isError ? 'Error' : isUpdate ? 'Update' : 'Create'}
|
|
172
|
+
</Badge>
|
|
173
|
+
</Box>
|
|
174
|
+
</Flex>
|
|
175
|
+
</Box>
|
|
176
|
+
|
|
177
|
+
{/* Error message */}
|
|
178
|
+
{isError && (
|
|
179
|
+
<Box paddingX={2} paddingBottom={2}>
|
|
180
|
+
<Flex justify="space-between" align="center">
|
|
181
|
+
<Text size={0} muted>{entry.error}</Text>
|
|
182
|
+
<Button mode="bleed" tone="critical" icon={TrashIcon} padding={1} onClick={handleRemove} />
|
|
183
|
+
</Flex>
|
|
184
|
+
</Box>
|
|
185
|
+
)}
|
|
186
|
+
|
|
187
|
+
{/* Expanded detail panel */}
|
|
188
|
+
{expanded && !isError && (
|
|
189
|
+
<Box padding={3} style={{ borderTop: '1px solid var(--card-border-color)', background: 'var(--card-muted-bg-color)' }}>
|
|
190
|
+
<Stack space={4}>
|
|
191
|
+
{/* Files — standard types with grey for missing, expandable for extended */}
|
|
192
|
+
<Stack space={2}>
|
|
193
|
+
<Flex align="center" gap={2}>
|
|
194
|
+
<Label size={0}>Files ({fileCount})</Label>
|
|
195
|
+
<Button
|
|
196
|
+
mode="bleed"
|
|
197
|
+
fontSize={0}
|
|
198
|
+
padding={1}
|
|
199
|
+
text={showAllFileTypes ? 'Hide extended types' : 'Show all types'}
|
|
200
|
+
onClick={() => setShowAllFileTypes(v => !v)}
|
|
201
|
+
style={{ cursor: 'pointer' }}
|
|
202
|
+
/>
|
|
203
|
+
</Flex>
|
|
204
|
+
<Flex gap={1} wrap="wrap">
|
|
205
|
+
{STANDARD_TYPES.map(ext => (
|
|
206
|
+
<Badge
|
|
207
|
+
key={ext}
|
|
208
|
+
fontSize={0}
|
|
209
|
+
tone={fileExtMap[ext] ? 'primary' : 'default'}
|
|
210
|
+
mode={fileExtMap[ext] ? 'default' : 'outline'}
|
|
211
|
+
style={{ opacity: fileExtMap[ext] ? 1 : 0.35 }}
|
|
212
|
+
>
|
|
213
|
+
{ext.toUpperCase()}{fileExtMap[ext] ? `: ${fileExtMap[ext]}` : ''}
|
|
214
|
+
</Badge>
|
|
215
|
+
))}
|
|
216
|
+
{showAllFileTypes && EXTENDED_TYPES.map(ext => (
|
|
217
|
+
<Badge
|
|
218
|
+
key={ext}
|
|
219
|
+
fontSize={0}
|
|
220
|
+
tone={fileExtMap[ext] ? 'primary' : 'default'}
|
|
221
|
+
mode={fileExtMap[ext] ? 'default' : 'outline'}
|
|
222
|
+
style={{ opacity: fileExtMap[ext] ? 1 : 0.35 }}
|
|
223
|
+
>
|
|
224
|
+
{ext.toUpperCase()}{fileExtMap[ext] ? `: ${fileExtMap[ext]}` : ''}
|
|
225
|
+
</Badge>
|
|
226
|
+
))}
|
|
227
|
+
</Flex>
|
|
228
|
+
</Stack>
|
|
229
|
+
|
|
230
|
+
{/* Title */}
|
|
231
|
+
<Stack space={2}>
|
|
232
|
+
<Label size={0}>Font Title</Label>
|
|
233
|
+
<TextInput
|
|
234
|
+
value={localTitle}
|
|
235
|
+
onChange={(e) => setLocalTitle(e.target.value)}
|
|
236
|
+
onBlur={handleTitleBlur}
|
|
237
|
+
fontSize={1}
|
|
238
|
+
/>
|
|
239
|
+
<Text size={0} muted>{formatSource(entry.decisions?.title)}</Text>
|
|
240
|
+
{entry.decisions?.title?.alternatives?.length > 0 && (
|
|
241
|
+
<Flex gap={1} wrap="wrap">
|
|
242
|
+
{entry.decisions.title.alternatives.filter(a => a.value).map((alt, i) => (
|
|
243
|
+
<Tooltip key={i} content={<Box padding={1}><Text size={0}>{alt.source.replace(/nameId(\d+)-(\w+)/g, 'nameId$1 ($2)')}</Text></Box>} portal>
|
|
244
|
+
<Badge
|
|
245
|
+
mode="outline"
|
|
246
|
+
fontSize={0}
|
|
247
|
+
style={{ cursor: 'pointer' }}
|
|
248
|
+
onClick={() => {
|
|
249
|
+
setLocalTitle(alt.value);
|
|
250
|
+
dispatch({ type: 'SET_FONT_TITLE', tempId: entry.tempId, title: alt.value, source: alt.source });
|
|
251
|
+
}}
|
|
252
|
+
>
|
|
253
|
+
{alt.value.length > 30 ? alt.value.slice(0, 30) + '...' : alt.value}
|
|
254
|
+
</Badge>
|
|
255
|
+
</Tooltip>
|
|
256
|
+
))}
|
|
257
|
+
</Flex>
|
|
258
|
+
)}
|
|
259
|
+
</Stack>
|
|
260
|
+
|
|
261
|
+
{/* Document ID */}
|
|
262
|
+
<Stack space={2}>
|
|
263
|
+
<Flex align="center" gap={1}>
|
|
264
|
+
<Label size={0}>Document ID</Label>
|
|
265
|
+
{!docIdEditable && (
|
|
266
|
+
<Tooltip
|
|
267
|
+
content={<Box padding={2} style={{ maxWidth: 260 }}><Text size={1} style={{ lineHeight: 1.6 }}>Document IDs must be unique. This field is auto-derived from the font title. It becomes editable when you choose "Create new instead" on a font with an existing match, or when there is a duplicate ID conflict.</Text></Box>}
|
|
268
|
+
placement="top"
|
|
269
|
+
portal
|
|
270
|
+
>
|
|
271
|
+
<InfoOutlineIcon style={{ opacity: 0.4, fontSize: 12 }} />
|
|
272
|
+
</Tooltip>
|
|
273
|
+
)}
|
|
274
|
+
</Flex>
|
|
275
|
+
<TextInput
|
|
276
|
+
value={docIdEditable ? localDocId : entry.documentId}
|
|
277
|
+
onChange={docIdEditable ? (e) => setLocalDocId(e.target.value) : undefined}
|
|
278
|
+
onBlur={docIdEditable ? handleDocIdBlur : undefined}
|
|
279
|
+
readOnly={!docIdEditable}
|
|
280
|
+
fontSize={1}
|
|
281
|
+
style={{ fontFamily: 'monospace', opacity: docIdEditable ? 1 : 0.7 }}
|
|
282
|
+
/>
|
|
283
|
+
{hasConflict && (
|
|
284
|
+
<Text size={0} tone="caution">This ID conflicts with another font in this batch — edit to make unique</Text>
|
|
285
|
+
)}
|
|
286
|
+
{isCreateNewOverride && !hasConflict && (
|
|
287
|
+
<Text size={0} tone="caution">Creating new document — edit the ID to avoid overwriting the existing document</Text>
|
|
288
|
+
)}
|
|
289
|
+
{!docIdEditable && (
|
|
290
|
+
<Text size={0} muted>Auto-derived from font title</Text>
|
|
291
|
+
)}
|
|
292
|
+
</Stack>
|
|
293
|
+
|
|
294
|
+
{/* Weight + Weight Name row */}
|
|
295
|
+
<Flex gap={3}>
|
|
296
|
+
<Box style={{ flex: 1 }}>
|
|
297
|
+
<Stack space={2}>
|
|
298
|
+
<Label size={0}>Weight</Label>
|
|
299
|
+
<TextInput
|
|
300
|
+
type="number"
|
|
301
|
+
value={localWeight}
|
|
302
|
+
onChange={(e) => setLocalWeight(e.target.value)}
|
|
303
|
+
onBlur={handleWeightBlur}
|
|
304
|
+
fontSize={1}
|
|
305
|
+
/>
|
|
306
|
+
{entry.decisions?.weight && (
|
|
307
|
+
<Text size={0} muted>{formatSource(entry.decisions.weight)}</Text>
|
|
308
|
+
)}
|
|
309
|
+
</Stack>
|
|
310
|
+
</Box>
|
|
311
|
+
<Box style={{ flex: 1 }}>
|
|
312
|
+
<Stack space={2}>
|
|
313
|
+
<Label size={0}>Weight Name</Label>
|
|
314
|
+
<TextInput
|
|
315
|
+
value={localWeightName}
|
|
316
|
+
onChange={(e) => setLocalWeightName(e.target.value)}
|
|
317
|
+
onBlur={handleWeightNameBlur}
|
|
318
|
+
fontSize={1}
|
|
319
|
+
/>
|
|
320
|
+
{entry.decisions?.weightName && (
|
|
321
|
+
<Text size={0} muted>{formatSource(entry.decisions.weightName)}</Text>
|
|
322
|
+
)}
|
|
323
|
+
</Stack>
|
|
324
|
+
</Box>
|
|
325
|
+
</Flex>
|
|
326
|
+
|
|
327
|
+
{/* Style + Subfamily row */}
|
|
328
|
+
<Flex gap={3}>
|
|
329
|
+
<Box style={{ flex: 1 }}>
|
|
330
|
+
<Stack space={2}>
|
|
331
|
+
<Label size={0}>Style</Label>
|
|
332
|
+
<Select value={entry.style} onChange={handleStyleChange} fontSize={1}>
|
|
333
|
+
<option value="Regular">Regular</option>
|
|
334
|
+
<option value="Italic">Italic</option>
|
|
335
|
+
</Select>
|
|
336
|
+
{entry.decisions?.style && (
|
|
337
|
+
<Text size={0} muted>{formatSource(entry.decisions.style)}</Text>
|
|
338
|
+
)}
|
|
339
|
+
</Stack>
|
|
340
|
+
</Box>
|
|
341
|
+
<Box style={{ flex: 1 }}>
|
|
342
|
+
<Stack space={2}>
|
|
343
|
+
<Label size={0}>Subfamily</Label>
|
|
344
|
+
<TextInput
|
|
345
|
+
value={localSubfamily}
|
|
346
|
+
onChange={(e) => setLocalSubfamily(e.target.value)}
|
|
347
|
+
onBlur={handleSubfamilyBlur}
|
|
348
|
+
fontSize={1}
|
|
349
|
+
/>
|
|
350
|
+
{entry.decisions?.subfamily && (
|
|
351
|
+
<Text size={0} muted>{formatSource(entry.decisions.subfamily)}</Text>
|
|
352
|
+
)}
|
|
353
|
+
</Stack>
|
|
354
|
+
</Box>
|
|
355
|
+
</Flex>
|
|
356
|
+
|
|
357
|
+
{/* VF axes info */}
|
|
358
|
+
{entry.variableFont && entry.variationAxes && (
|
|
359
|
+
<Stack space={2}>
|
|
360
|
+
<Label size={0}>Variable Font Axes</Label>
|
|
361
|
+
<Flex gap={1} wrap="wrap">
|
|
362
|
+
{Object.entries(entry.variationAxes).map(([tag, axis]) => (
|
|
363
|
+
<Badge key={tag} mode="outline" fontSize={0}>
|
|
364
|
+
{tag} {axis.min}–{axis.max}
|
|
365
|
+
</Badge>
|
|
366
|
+
))}
|
|
367
|
+
</Flex>
|
|
368
|
+
{entry.decisions?.weight?.userOverride != null && entry.variationAxes?.wght && (
|
|
369
|
+
(entry.weight < entry.variationAxes.wght.min || entry.weight > entry.variationAxes.wght.max) && (
|
|
370
|
+
<Text size={0} tone="caution">
|
|
371
|
+
Weight {entry.weight} is outside the wght axis range ({entry.variationAxes.wght.min}–{entry.variationAxes.wght.max})
|
|
372
|
+
</Text>
|
|
373
|
+
)
|
|
374
|
+
)}
|
|
375
|
+
</Stack>
|
|
376
|
+
)}
|
|
377
|
+
|
|
378
|
+
{/* Existing document resolution */}
|
|
379
|
+
<ExistingDocumentResolver
|
|
380
|
+
decision={entry.decisions?.existingDocument}
|
|
381
|
+
tempId={entry.tempId}
|
|
382
|
+
dispatch={dispatch}
|
|
383
|
+
/>
|
|
384
|
+
|
|
385
|
+
{/* Actions — only show reset if user has overridden suggestions */}
|
|
386
|
+
<Flex justify="flex-end" gap={2}>
|
|
387
|
+
{hasUserOverrides && (
|
|
388
|
+
<Button
|
|
389
|
+
mode="ghost"
|
|
390
|
+
tone="default"
|
|
391
|
+
icon={ResetIcon}
|
|
392
|
+
text="Reset to Suggestions"
|
|
393
|
+
fontSize={1}
|
|
394
|
+
padding={2}
|
|
395
|
+
onClick={handleReset}
|
|
396
|
+
/>
|
|
397
|
+
)}
|
|
398
|
+
<Button
|
|
399
|
+
mode="ghost"
|
|
400
|
+
tone="critical"
|
|
401
|
+
icon={TrashIcon}
|
|
402
|
+
text="Remove"
|
|
403
|
+
fontSize={1}
|
|
404
|
+
padding={2}
|
|
405
|
+
onClick={handleRemove}
|
|
406
|
+
/>
|
|
407
|
+
</Flex>
|
|
408
|
+
</Stack>
|
|
409
|
+
</Box>
|
|
410
|
+
)}
|
|
411
|
+
</Card>
|
|
412
|
+
);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
export default FontReviewCard;
|
|
@@ -4,8 +4,7 @@ import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
|
|
4
4
|
import { Button, Grid, Stack, Flex, Box, Text, Card } from '@sanity/ui';
|
|
5
5
|
import { TrashIcon, ControlsIcon } from '@sanity/icons';
|
|
6
6
|
import { useFormValue, set, unset } from 'sanity';
|
|
7
|
-
import {
|
|
8
|
-
import * as fontkit from 'fontkit';
|
|
7
|
+
import { parseFont } from '../utils/parseFont';
|
|
9
8
|
|
|
10
9
|
import { useSanityClient } from '../hooks/useSanityClient';
|
|
11
10
|
import {
|
|
@@ -193,7 +192,7 @@ export const SingleUploaderTool = (props) => {
|
|
|
193
192
|
if (!ttfAsset?.url) throw new Error('Could not fetch TTF file URL');
|
|
194
193
|
|
|
195
194
|
const arrayBuffer = await (await fetch(ttfAsset.url)).arrayBuffer();
|
|
196
|
-
const font =
|
|
195
|
+
const font = await parseFont(arrayBuffer, `${doc_id}.ttf`);
|
|
197
196
|
|
|
198
197
|
const { weightName, subfamilyName, style, variableFont } = extractFontMetadata(
|
|
199
198
|
font,
|
|
@@ -349,7 +348,7 @@ export const SingleUploaderTool = (props) => {
|
|
|
349
348
|
|
|
350
349
|
if (code === 'ttf') {
|
|
351
350
|
const fontBuffer = await readFontFile(file);
|
|
352
|
-
const font =
|
|
351
|
+
const font = await parseFont(fontBuffer, file.name);
|
|
353
352
|
const { weightName, subfamilyName, style, variableFont } = extractFontMetadata(
|
|
354
353
|
font, doc_typefaceName, weightKeywordList, italicKeywordList
|
|
355
354
|
);
|