@liiift-studio/sanity-font-manager 2.3.18 → 2.4.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.
Files changed (42) hide show
  1. package/README.md +437 -437
  2. package/dist/index.js +103 -48
  3. package/dist/index.mjs +103 -48
  4. package/package.json +85 -85
  5. package/src/components/BatchUploadFonts.jsx +640 -639
  6. package/src/components/FontScriptUploaderComponent.jsx +463 -463
  7. package/src/components/GenerateCollectionsPairsComponent.jsx +259 -259
  8. package/src/components/KeyValueInput.jsx +95 -95
  9. package/src/components/KeyValueReferenceInput.jsx +254 -254
  10. package/src/components/NestedObjectArraySelector.jsx +146 -146
  11. package/src/components/PriceInput.jsx +26 -26
  12. package/src/components/PrimaryCollectionGeneratorTypeface.jsx +116 -116
  13. package/src/components/RegenerateSubfamiliesComponent.jsx +185 -185
  14. package/src/components/SetOTF.jsx +87 -87
  15. package/src/components/SingleUploaderTool.jsx +673 -673
  16. package/src/components/StatusDisplay.jsx +26 -26
  17. package/src/components/StyleCountInput.jsx +16 -16
  18. package/src/components/UpdateScriptsComponent.jsx +76 -76
  19. package/src/components/UploadButton.jsx +43 -43
  20. package/src/components/UploadScriptsComponent.jsx +537 -537
  21. package/src/components/VariableInstanceReferencesInput.jsx +190 -190
  22. package/src/hooks/useNestedObjects.js +92 -92
  23. package/src/hooks/useSanityClient.js +9 -9
  24. package/src/index.js +70 -70
  25. package/src/schema/openTypeField.js +1945 -1945
  26. package/src/schema/styleCountField.js +12 -12
  27. package/src/schema/stylesField.js +268 -268
  28. package/src/schema/stylisticSetField.js +301 -301
  29. package/src/utils/generateCssFile.js +205 -205
  30. package/src/utils/generateFontData.js +145 -145
  31. package/src/utils/generateFontFile.js +38 -38
  32. package/src/utils/generateKeywords.js +185 -185
  33. package/src/utils/generateSubset.js +45 -45
  34. package/src/utils/getEmptyFontKit.js +99 -99
  35. package/src/utils/parseVariableFontInstances.js +211 -211
  36. package/src/utils/processFontFiles.js +487 -477
  37. package/src/utils/regenerateFontData.js +146 -146
  38. package/src/utils/sanitizeForSanityId.js +65 -65
  39. package/src/utils/updateFontPrices.js +94 -94
  40. package/src/utils/updateTypefaceDocument.js +149 -160
  41. package/src/utils/uploadFontFiles.js +115 -26
  42. package/src/utils/utils.js +24 -24
@@ -1,95 +1,95 @@
1
- // Ordered key-value string pair editor for Sanity Studio — add, remove, and reorder rows
2
-
3
- import React, { useState, useCallback } from 'react';
4
- import { Button, Grid, Stack, TextInput } from '@sanity/ui';
5
- import { AddIcon, ArrowDownIcon, ArrowUpIcon, TrashIcon } from '@sanity/icons';
6
- import { set } from 'sanity';
7
-
8
- /**
9
- * Ordered key-value string pair editor with add, remove, and reorder controls.
10
- * Writes an array of { _key, key, value } objects to Sanity.
11
- * @param {Array} value - Current array of { _key, key, value } pairs
12
- * @param {Function} onChange - Sanity onChange callback
13
- */
14
- export function KeyValueInput({ value = [], onChange }) {
15
- const [pairs, setPairs] = useState(value);
16
-
17
- /** Updates a specific field for a pair at the given index */
18
- const handlePairChange = useCallback((index, field, fieldValue) => {
19
- const updatedPairs = pairs.map((pair, idx) => idx === index ? { ...pair, [field]: fieldValue } : pair);
20
- setPairs(updatedPairs);
21
- onChange(set(updatedPairs));
22
- }, [pairs, onChange]);
23
-
24
- /** Appends a new empty pair */
25
- const handleAddPair = useCallback(() => {
26
- const newPair = { key: '', value: '', _key: Math.random().toString(36).substr(2, 9) };
27
- const updatedPairs = [...pairs, newPair];
28
- setPairs(updatedPairs);
29
- onChange(set(updatedPairs));
30
- }, [pairs, onChange]);
31
-
32
- /** Removes the pair at the given index */
33
- const handleRemovePair = useCallback((index) => {
34
- const updatedPairs = pairs.filter((_, idx) => idx !== index);
35
- setPairs(updatedPairs);
36
- onChange(set(updatedPairs));
37
- }, [pairs, onChange]);
38
-
39
- /** Swaps a pair with the one above it */
40
- const handleMoveUp = useCallback((index) => {
41
- if (index === 0) return;
42
- const updatedPairs = [...pairs];
43
- [updatedPairs[index], updatedPairs[index - 1]] = [updatedPairs[index - 1], updatedPairs[index]];
44
- setPairs(updatedPairs);
45
- onChange(set(updatedPairs));
46
- }, [pairs, onChange]);
47
-
48
- /** Swaps a pair with the one below it */
49
- const handleMoveDown = useCallback((index) => {
50
- if (index === pairs.length - 1) return;
51
- const updatedPairs = [...pairs];
52
- [updatedPairs[index], updatedPairs[index + 1]] = [updatedPairs[index + 1], updatedPairs[index]];
53
- setPairs(updatedPairs);
54
- onChange(set(updatedPairs));
55
- }, [pairs, onChange]);
56
-
57
- return (
58
- <Stack space={3}>
59
- {pairs.map((pair, index) => (
60
- <Grid className="manualButtonWrap" columns={[2]} key={index} gap={0} style={{ position: 'relative' }}>
61
- <div style={{ position: 'absolute', height: '100%', top: '0', left: '-10px', width: 'min-content', transform: 'translate(-100%, 0%)' }}>
62
- <button className="manualButton manualButtonUp" style={{ fontSize: '15px', height: '50%' }} onClick={() => handleMoveUp(index)}>
63
- <ArrowUpIcon />
64
- </button>
65
- <button className="manualButton manualButtonDown" style={{ fontSize: '15px', height: '50%' }} onClick={() => handleMoveDown(index)}>
66
- <ArrowDownIcon />
67
- </button>
68
- </div>
69
-
70
- <TextInput
71
- value={pair.key}
72
- onChange={(e) => handlePairChange(index, 'key', e.target.value)}
73
- placeholder="Key"
74
- />
75
- <div style={{ marginLeft: '-1px' }}>
76
- <TextInput
77
- value={pair.value}
78
- onChange={(e) => handlePairChange(index, 'value', e.target.value)}
79
- placeholder="Value"
80
- />
81
- </div>
82
-
83
- <button
84
- className="manualButton"
85
- onClick={() => handleRemovePair(index)}
86
- style={{ position: 'absolute', top: '0', right: '-10px', transform: 'translate(100%, 0%)' }}
87
- >
88
- <TrashIcon />
89
- </button>
90
- </Grid>
91
- ))}
92
- <Button tone="primary" onClick={handleAddPair} icon={AddIcon} text="Add Row" />
93
- </Stack>
94
- );
95
- }
1
+ // Ordered key-value string pair editor for Sanity Studio — add, remove, and reorder rows
2
+
3
+ import React, { useState, useCallback } from 'react';
4
+ import { Button, Grid, Stack, TextInput } from '@sanity/ui';
5
+ import { AddIcon, ArrowDownIcon, ArrowUpIcon, TrashIcon } from '@sanity/icons';
6
+ import { set } from 'sanity';
7
+
8
+ /**
9
+ * Ordered key-value string pair editor with add, remove, and reorder controls.
10
+ * Writes an array of { _key, key, value } objects to Sanity.
11
+ * @param {Array} value - Current array of { _key, key, value } pairs
12
+ * @param {Function} onChange - Sanity onChange callback
13
+ */
14
+ export function KeyValueInput({ value = [], onChange }) {
15
+ const [pairs, setPairs] = useState(value);
16
+
17
+ /** Updates a specific field for a pair at the given index */
18
+ const handlePairChange = useCallback((index, field, fieldValue) => {
19
+ const updatedPairs = pairs.map((pair, idx) => idx === index ? { ...pair, [field]: fieldValue } : pair);
20
+ setPairs(updatedPairs);
21
+ onChange(set(updatedPairs));
22
+ }, [pairs, onChange]);
23
+
24
+ /** Appends a new empty pair */
25
+ const handleAddPair = useCallback(() => {
26
+ const newPair = { key: '', value: '', _key: Math.random().toString(36).substr(2, 9) };
27
+ const updatedPairs = [...pairs, newPair];
28
+ setPairs(updatedPairs);
29
+ onChange(set(updatedPairs));
30
+ }, [pairs, onChange]);
31
+
32
+ /** Removes the pair at the given index */
33
+ const handleRemovePair = useCallback((index) => {
34
+ const updatedPairs = pairs.filter((_, idx) => idx !== index);
35
+ setPairs(updatedPairs);
36
+ onChange(set(updatedPairs));
37
+ }, [pairs, onChange]);
38
+
39
+ /** Swaps a pair with the one above it */
40
+ const handleMoveUp = useCallback((index) => {
41
+ if (index === 0) return;
42
+ const updatedPairs = [...pairs];
43
+ [updatedPairs[index], updatedPairs[index - 1]] = [updatedPairs[index - 1], updatedPairs[index]];
44
+ setPairs(updatedPairs);
45
+ onChange(set(updatedPairs));
46
+ }, [pairs, onChange]);
47
+
48
+ /** Swaps a pair with the one below it */
49
+ const handleMoveDown = useCallback((index) => {
50
+ if (index === pairs.length - 1) return;
51
+ const updatedPairs = [...pairs];
52
+ [updatedPairs[index], updatedPairs[index + 1]] = [updatedPairs[index + 1], updatedPairs[index]];
53
+ setPairs(updatedPairs);
54
+ onChange(set(updatedPairs));
55
+ }, [pairs, onChange]);
56
+
57
+ return (
58
+ <Stack space={3}>
59
+ {pairs.map((pair, index) => (
60
+ <Grid className="manualButtonWrap" columns={[2]} key={index} gap={0} style={{ position: 'relative' }}>
61
+ <div style={{ position: 'absolute', height: '100%', top: '0', left: '-10px', width: 'min-content', transform: 'translate(-100%, 0%)' }}>
62
+ <button className="manualButton manualButtonUp" style={{ fontSize: '15px', height: '50%' }} onClick={() => handleMoveUp(index)}>
63
+ <ArrowUpIcon />
64
+ </button>
65
+ <button className="manualButton manualButtonDown" style={{ fontSize: '15px', height: '50%' }} onClick={() => handleMoveDown(index)}>
66
+ <ArrowDownIcon />
67
+ </button>
68
+ </div>
69
+
70
+ <TextInput
71
+ value={pair.key}
72
+ onChange={(e) => handlePairChange(index, 'key', e.target.value)}
73
+ placeholder="Key"
74
+ />
75
+ <div style={{ marginLeft: '-1px' }}>
76
+ <TextInput
77
+ value={pair.value}
78
+ onChange={(e) => handlePairChange(index, 'value', e.target.value)}
79
+ placeholder="Value"
80
+ />
81
+ </div>
82
+
83
+ <button
84
+ className="manualButton"
85
+ onClick={() => handleRemovePair(index)}
86
+ style={{ position: 'absolute', top: '0', right: '-10px', transform: 'translate(100%, 0%)' }}
87
+ >
88
+ <TrashIcon />
89
+ </button>
90
+ </Grid>
91
+ ))}
92
+ <Button tone="primary" onClick={handleAddPair} icon={AddIcon} text="Add Row" />
93
+ </Stack>
94
+ );
95
+ }