@liiift-studio/sanity-font-manager 2.5.6 → 2.5.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
@@ -16844,6 +16844,7 @@ __export(index_exports, {
16844
16844
  createFontDecisions: () => createFontDecisions,
16845
16845
  createFontObject: () => createFontObject,
16846
16846
  createInitialExecutionState: () => createInitialExecutionState,
16847
+ createOpenTypeField: () => createOpenTypeField,
16847
16848
  createStylesField: () => createStylesField,
16848
16849
  determineWeight: () => determineWeight,
16849
16850
  escapeCssFontName: () => escapeCssFontName,
@@ -18496,14 +18497,16 @@ var SingleUploaderTool = (props) => {
18496
18497
  if (!(ttfAsset == null ? void 0 : ttfAsset.url)) throw new Error("Could not fetch TTF file URL");
18497
18498
  const arrayBuffer = await (await fetch(ttfAsset.url)).arrayBuffer();
18498
18499
  const font2 = await parseFont(arrayBuffer, `${doc_id}.ttf`);
18499
- const { weightName, subfamilyName, style, variableFont } = extractFontMetadata(
18500
+ const { weightName, subfamilyName, fontTitle, style, variableFont } = extractFontMetadata(
18500
18501
  font2,
18501
18502
  doc_typefaceName,
18502
18503
  weightKeywordList,
18503
- italicKeywordList
18504
+ italicKeywordList,
18505
+ false,
18506
+ null
18504
18507
  );
18505
18508
  const weight = determineWeight(font2, weightName);
18506
- await client.patch(doc_id).set({ weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
18509
+ await client.patch(doc_id).set({ title: fontTitle, weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
18507
18510
  const fontData = await generateFontData({
18508
18511
  url: ttfAsset.url,
18509
18512
  fontKit: font2,
@@ -18653,15 +18656,17 @@ var SingleUploaderTool = (props) => {
18653
18656
  if (code === "ttf") {
18654
18657
  const fontBuffer = await readFontFile(file);
18655
18658
  const font2 = await parseFont(fontBuffer, file.name);
18656
- const { weightName, subfamilyName, style, variableFont } = extractFontMetadata(
18659
+ const { weightName, subfamilyName, fontTitle, style, variableFont } = extractFontMetadata(
18657
18660
  font2,
18658
18661
  doc_typefaceName,
18659
18662
  weightKeywordList,
18660
- italicKeywordList
18663
+ italicKeywordList,
18664
+ false,
18665
+ null
18661
18666
  );
18662
18667
  const weight = determineWeight(font2, weightName);
18663
18668
  const normalizedId = doc_id.startsWith("drafts.") ? doc_id.replace("drafts.", "") : doc_id;
18664
- await client.patch(normalizedId).set({ weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
18669
+ await client.patch(normalizedId).set({ title: fontTitle, weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
18665
18670
  }
18666
18671
  onChange((0, import_sanity6.set)(newFileInput));
18667
18672
  setTimeout(() => {
@@ -19583,6 +19588,9 @@ function KeyValueReferenceInput(props) {
19583
19588
  const [availableReferences, setAvailableReferences] = (0, import_react23.useState)([]);
19584
19589
  const sanityClient = useSanityClient();
19585
19590
  const formDocument = (0, import_sanity10.useFormValue)([]);
19591
+ (0, import_react23.useEffect)(() => {
19592
+ setPairs(value);
19593
+ }, [value]);
19586
19594
  (0, import_react23.useEffect)(() => {
19587
19595
  const refIds = pairs.filter((p2) => {
19588
19596
  var _a2;
@@ -22452,6 +22460,36 @@ var openTypeField = {
22452
22460
  }
22453
22461
  ]
22454
22462
  };
22463
+ function createOpenTypeField({
22464
+ customText = false,
22465
+ customTextType = "string"
22466
+ } = {}) {
22467
+ if (!customText) return { ...openTypeField };
22468
+ const fields = openTypeField.fields.map((field2) => {
22469
+ if (field2.type !== "object" || !field2.fields) return field2;
22470
+ const updatedSubfields = field2.fields.map((subfield) => {
22471
+ if (subfield.name !== "customText") return subfield;
22472
+ const updated = { ...subfield, hidden: false };
22473
+ if (customTextType === "code") {
22474
+ updated.type = "code";
22475
+ updated.options = {
22476
+ language: "html",
22477
+ languageAlternatives: [
22478
+ { title: "HTML", value: "html" }
22479
+ ],
22480
+ withFilename: false
22481
+ };
22482
+ updated.description = 'Use the field below to input custom text to highlight the feature. Wrap featured characters in <span class="bold">CHARACTER</span>.';
22483
+ }
22484
+ return updated;
22485
+ });
22486
+ return { ...field2, fields: updatedSubfields };
22487
+ });
22488
+ return {
22489
+ ...openTypeField,
22490
+ fields
22491
+ };
22492
+ }
22455
22493
 
22456
22494
  // src/schema/styleCountField.js
22457
22495
  var styleCountField = {
@@ -23069,6 +23107,7 @@ init_generateKeywords();
23069
23107
  createFontDecisions,
23070
23108
  createFontObject,
23071
23109
  createInitialExecutionState,
23110
+ createOpenTypeField,
23072
23111
  createStylesField,
23073
23112
  determineWeight,
23074
23113
  escapeCssFontName,
package/dist/index.mjs CHANGED
@@ -18396,14 +18396,16 @@ var SingleUploaderTool = (props) => {
18396
18396
  if (!(ttfAsset == null ? void 0 : ttfAsset.url)) throw new Error("Could not fetch TTF file URL");
18397
18397
  const arrayBuffer = await (await fetch(ttfAsset.url)).arrayBuffer();
18398
18398
  const font2 = await parseFont(arrayBuffer, `${doc_id}.ttf`);
18399
- const { weightName, subfamilyName, style, variableFont } = extractFontMetadata(
18399
+ const { weightName, subfamilyName, fontTitle, style, variableFont } = extractFontMetadata(
18400
18400
  font2,
18401
18401
  doc_typefaceName,
18402
18402
  weightKeywordList,
18403
- italicKeywordList
18403
+ italicKeywordList,
18404
+ false,
18405
+ null
18404
18406
  );
18405
18407
  const weight = determineWeight(font2, weightName);
18406
- await client.patch(doc_id).set({ weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
18408
+ await client.patch(doc_id).set({ title: fontTitle, weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
18407
18409
  const fontData = await generateFontData({
18408
18410
  url: ttfAsset.url,
18409
18411
  fontKit: font2,
@@ -18553,15 +18555,17 @@ var SingleUploaderTool = (props) => {
18553
18555
  if (code === "ttf") {
18554
18556
  const fontBuffer = await readFontFile(file);
18555
18557
  const font2 = await parseFont(fontBuffer, file.name);
18556
- const { weightName, subfamilyName, style, variableFont } = extractFontMetadata(
18558
+ const { weightName, subfamilyName, fontTitle, style, variableFont } = extractFontMetadata(
18557
18559
  font2,
18558
18560
  doc_typefaceName,
18559
18561
  weightKeywordList,
18560
- italicKeywordList
18562
+ italicKeywordList,
18563
+ false,
18564
+ null
18561
18565
  );
18562
18566
  const weight = determineWeight(font2, weightName);
18563
18567
  const normalizedId = doc_id.startsWith("drafts.") ? doc_id.replace("drafts.", "") : doc_id;
18564
- await client.patch(normalizedId).set({ weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
18568
+ await client.patch(normalizedId).set({ title: fontTitle, weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
18565
18569
  }
18566
18570
  onChange(set2(newFileInput));
18567
18571
  setTimeout(() => {
@@ -19483,6 +19487,9 @@ function KeyValueReferenceInput(props) {
19483
19487
  const [availableReferences, setAvailableReferences] = useState16([]);
19484
19488
  const sanityClient = useSanityClient();
19485
19489
  const formDocument = useFormValue8([]);
19490
+ useEffect11(() => {
19491
+ setPairs(value);
19492
+ }, [value]);
19486
19493
  useEffect11(() => {
19487
19494
  const refIds = pairs.filter((p2) => {
19488
19495
  var _a2;
@@ -22352,6 +22359,36 @@ var openTypeField = {
22352
22359
  }
22353
22360
  ]
22354
22361
  };
22362
+ function createOpenTypeField({
22363
+ customText = false,
22364
+ customTextType = "string"
22365
+ } = {}) {
22366
+ if (!customText) return { ...openTypeField };
22367
+ const fields = openTypeField.fields.map((field2) => {
22368
+ if (field2.type !== "object" || !field2.fields) return field2;
22369
+ const updatedSubfields = field2.fields.map((subfield) => {
22370
+ if (subfield.name !== "customText") return subfield;
22371
+ const updated = { ...subfield, hidden: false };
22372
+ if (customTextType === "code") {
22373
+ updated.type = "code";
22374
+ updated.options = {
22375
+ language: "html",
22376
+ languageAlternatives: [
22377
+ { title: "HTML", value: "html" }
22378
+ ],
22379
+ withFilename: false
22380
+ };
22381
+ updated.description = 'Use the field below to input custom text to highlight the feature. Wrap featured characters in <span class="bold">CHARACTER</span>.';
22382
+ }
22383
+ return updated;
22384
+ });
22385
+ return { ...field2, fields: updatedSubfields };
22386
+ });
22387
+ return {
22388
+ ...openTypeField,
22389
+ fields
22390
+ };
22391
+ }
22355
22392
 
22356
22393
  // src/schema/styleCountField.js
22357
22394
  var styleCountField = {
@@ -22968,6 +23005,7 @@ export {
22968
23005
  createFontDecisions,
22969
23006
  createFontObject,
22970
23007
  createInitialExecutionState,
23008
+ createOpenTypeField,
22971
23009
  createStylesField,
22972
23010
  determineWeight,
22973
23011
  escapeCssFontName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liiift-studio/sanity-font-manager",
3
- "version": "2.5.6",
3
+ "version": "2.5.9",
4
4
  "description": "Sanity Studio plugin — full font management suite with batch upload, format conversion, metadata extraction, CSS generation, collection/pair generation, and script variant support. Supports Sanity v3, v4, and v5.",
5
5
  "license": "MIT",
6
6
  "author": "Liiift Studio",
@@ -29,6 +29,11 @@ export function KeyValueReferenceInput(props) {
29
29
  const sanityClient = useSanityClient();
30
30
  const formDocument = useFormValue([]);
31
31
 
32
+ /** Syncs local pairs state when the value prop changes externally (e.g. autofill from parent) */
33
+ useEffect(() => {
34
+ setPairs(value);
35
+ }, [value]);
36
+
32
37
  /** Fetches and caches display titles for all referenced documents whenever pairs change */
33
38
  useEffect(() => {
34
39
  const refIds = pairs.filter(p => p.value?._ref).map(p => p.value._ref);
@@ -194,15 +194,17 @@ export const SingleUploaderTool = (props) => {
194
194
  const arrayBuffer = await (await fetch(ttfAsset.url)).arrayBuffer();
195
195
  const font = await parseFont(arrayBuffer, `${doc_id}.ttf`);
196
196
 
197
- const { weightName, subfamilyName, style, variableFont } = extractFontMetadata(
197
+ const { weightName, subfamilyName, fontTitle, style, variableFont } = extractFontMetadata(
198
198
  font,
199
199
  doc_typefaceName,
200
200
  weightKeywordList,
201
201
  italicKeywordList,
202
+ false,
203
+ null,
202
204
  );
203
205
  const weight = determineWeight(font, weightName);
204
206
 
205
- await client.patch(doc_id).set({ weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
207
+ await client.patch(doc_id).set({ title: fontTitle, weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
206
208
 
207
209
  const fontData = await generateFontData({
208
210
  url: ttfAsset.url,
@@ -349,12 +351,12 @@ export const SingleUploaderTool = (props) => {
349
351
  if (code === 'ttf') {
350
352
  const fontBuffer = await readFontFile(file);
351
353
  const font = await parseFont(fontBuffer, file.name);
352
- const { weightName, subfamilyName, style, variableFont } = extractFontMetadata(
353
- font, doc_typefaceName, weightKeywordList, italicKeywordList
354
+ const { weightName, subfamilyName, fontTitle, style, variableFont } = extractFontMetadata(
355
+ font, doc_typefaceName, weightKeywordList, italicKeywordList, false, null
354
356
  );
355
357
  const weight = determineWeight(font, weightName);
356
358
  const normalizedId = doc_id.startsWith('drafts.') ? doc_id.replace('drafts.', '') : doc_id;
357
- await client.patch(normalizedId).set({ weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
359
+ await client.patch(normalizedId).set({ title: fontTitle, weightName, subfamily: subfamilyName, style, variableFont, weight }).commit();
358
360
  }
359
361
 
360
362
  onChange(set(newFileInput));
package/src/index.js CHANGED
@@ -106,7 +106,7 @@ export {
106
106
  } from './utils/fontHelpers.js';
107
107
 
108
108
  // Schema field definitions
109
- export { openTypeField } from './schema/openTypeField.js';
109
+ export { openTypeField, createOpenTypeField } from './schema/openTypeField.js';
110
110
  export { styleCountField } from './schema/styleCountField.js';
111
111
  export { stylisticSetField } from './schema/stylisticSetField.js';
112
112
  export { createStylesField } from './schema/stylesField.js';
@@ -1943,3 +1943,53 @@ export const openTypeField = {
1943
1943
 
1944
1944
  ],
1945
1945
  };
1946
+
1947
+ /**
1948
+ * Factory function to create a customised OpenType field.
1949
+ * The static `openTypeField` export remains unchanged for backwards compatibility.
1950
+ *
1951
+ * @param {object} [options]
1952
+ * @param {boolean} [options.customText=false] - Unhide the customText field on each feature
1953
+ * @param {'string'|'code'} [options.customTextType='string'] - Type for customText field.
1954
+ * Use 'code' for an HTML code editor (requires @sanity/code-input plugin).
1955
+ * @returns {object} Sanity field definition
1956
+ */
1957
+ export function createOpenTypeField({
1958
+ customText = false,
1959
+ customTextType = 'string',
1960
+ } = {}) {
1961
+ if (!customText) return { ...openTypeField };
1962
+
1963
+ // Deep clone fields and unhide/retype customText on each feature object
1964
+ const fields = openTypeField.fields.map(field => {
1965
+ // Skip the top-level 'features' checkbox array
1966
+ if (field.type !== 'object' || !field.fields) return field;
1967
+
1968
+ const updatedSubfields = field.fields.map(subfield => {
1969
+ if (subfield.name !== 'customText') return subfield;
1970
+
1971
+ const updated = { ...subfield, hidden: false };
1972
+
1973
+ if (customTextType === 'code') {
1974
+ updated.type = 'code';
1975
+ updated.options = {
1976
+ language: 'html',
1977
+ languageAlternatives: [
1978
+ { title: 'HTML', value: 'html' },
1979
+ ],
1980
+ withFilename: false,
1981
+ };
1982
+ updated.description = 'Use the field below to input custom text to highlight the feature. Wrap featured characters in <span class="bold">CHARACTER</span>.';
1983
+ }
1984
+
1985
+ return updated;
1986
+ });
1987
+
1988
+ return { ...field, fields: updatedSubfields };
1989
+ });
1990
+
1991
+ return {
1992
+ ...openTypeField,
1993
+ fields,
1994
+ };
1995
+ }