From 134de78dff8613153953cc9b1f74624c48ab8725 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 10 Jan 2024 15:54:45 -0300 Subject: [PATCH 01/14] move font family to their on definition --- schemas/json/theme.json | 235 ++++++++++++++++++++-------------------- 1 file changed, 119 insertions(+), 116 deletions(-) diff --git a/schemas/json/theme.json b/schemas/json/theme.json index 10695f493c40dd..80d703223cd684 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -609,132 +609,135 @@ "description": "Font family presets for the font family selector.\nGenerates a single custom property (`--wp--preset--font-family--{slug}`) per preset value.", "type": "array", "items": { - "type": "object", - "properties": { - "name": { - "description": "Name of the font family preset, translatable.", - "type": "string" - }, - "slug": { - "description": "Kebab-case unique identifier for the font family preset.", - "type": "string" - }, - "fontFamily": { - "description": "CSS font-family value.", + "$ref": "#/definitions/fontFamily" + } + } + }, + "additionalProperties": false + } + } + }, + "fontFamily": { + "type": "object", + "properties": { + "name": { + "description": "Name of the font family preset, translatable.", + "type": "string" + }, + "slug": { + "description": "Kebab-case unique identifier for the font family preset.", + "type": "string" + }, + "fontFamily": { + "description": "CSS font-family value.", + "type": "string" + }, + "preview": { + "description": "URL to a preview image of the font family.", + "type": "string" + }, + "fontFace": { + "description": "Array of font-face declarations.", + "type": "array", + "items": { + "type": "object", + "properties": { + "fontFamily": { + "description": "CSS font-family value.", + "type": "string", + "default": "" + }, + "fontStyle": { + "description": "CSS font-style value.", + "type": "string", + "default": "normal" + }, + "fontWeight": { + "description": "List of available font weights, separated by a space.", + "default": "400", + "oneOf": [ + { "type": "string" }, - "preview": { - "description": "URL to a preview image of the font family.", + { + "type": "integer" + } + ] + }, + "fontDisplay": { + "description": "CSS font-display value.", + "type": "string", + "default": "fallback", + "enum": [ + "auto", + "block", + "fallback", + "swap", + "optional" + ] + }, + "src": { + "description": "Paths or URLs to the font files.", + "oneOf": [ + { "type": "string" }, - "fontFace": { - "description": "Array of font-face declarations.", + { "type": "array", "items": { - "type": "object", - "properties": { - "fontFamily": { - "description": "CSS font-family value.", - "type": "string", - "default": "" - }, - "fontStyle": { - "description": "CSS font-style value.", - "type": "string", - "default": "normal" - }, - "fontWeight": { - "description": "List of available font weights, separated by a space.", - "default": "400", - "oneOf": [ - { - "type": "string" - }, - { - "type": "integer" - } - ] - }, - "fontDisplay": { - "description": "CSS font-display value.", - "type": "string", - "default": "fallback", - "enum": [ - "auto", - "block", - "fallback", - "swap", - "optional" - ] - }, - "src": { - "description": "Paths or URLs to the font files.", - "oneOf": [ - { - "type": "string" - }, - { - "type": "array", - "items": { - "type": "string" - } - } - ], - "default": [] - }, - "fontStretch": { - "description": "CSS font-stretch value.", - "type": "string" - }, - "ascentOverride": { - "description": "CSS ascent-override value.", - "type": "string" - }, - "descentOverride": { - "description": "CSS descent-override value.", - "type": "string" - }, - "fontVariant": { - "description": "CSS font-variant value.", - "type": "string" - }, - "fontFeatureSettings": { - "description": "CSS font-feature-settings value.", - "type": "string" - }, - "fontVariationSettings": { - "description": "CSS font-variation-settings value.", - "type": "string" - }, - "lineGapOverride": { - "description": "CSS line-gap-override value.", - "type": "string" - }, - "sizeAdjust": { - "description": "CSS size-adjust value.", - "type": "string" - }, - "unicodeRange": { - "description": "CSS unicode-range value.", - "type": "string" - }, - "preview": { - "description": "URL to a preview image of the font face.", - "type": "string" - } - }, - "required": [ "fontFamily", "src" ], - "additionalProperties": false + "type": "string" } } - }, - "additionalProperties": false + ], + "default": [] + }, + "fontStretch": { + "description": "CSS font-stretch value.", + "type": "string" + }, + "ascentOverride": { + "description": "CSS ascent-override value.", + "type": "string" + }, + "descentOverride": { + "description": "CSS descent-override value.", + "type": "string" + }, + "fontVariant": { + "description": "CSS font-variant value.", + "type": "string" + }, + "fontFeatureSettings": { + "description": "CSS font-feature-settings value.", + "type": "string" + }, + "fontVariationSettings": { + "description": "CSS font-variation-settings value.", + "type": "string" + }, + "lineGapOverride": { + "description": "CSS line-gap-override value.", + "type": "string" + }, + "sizeAdjust": { + "description": "CSS size-adjust value.", + "type": "string" + }, + "unicodeRange": { + "description": "CSS unicode-range value.", + "type": "string" + }, + "preview": { + "description": "URL to a preview image of the font face.", + "type": "string" } - } - }, - "additionalProperties": false + }, + "required": [ "fontFamily", "src" ], + "additionalProperties": false + } } - } + }, + "additionalProperties": false }, "settingsPropertiesCustom": { "type": "object", From 36933bcc6b55d76d5d8cd0890601f56d3ada6edf Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 10 Jan 2024 15:55:02 -0300 Subject: [PATCH 02/14] adding font-collection.json schema --- schemas/json/font-collection.json | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 schemas/json/font-collection.json diff --git a/schemas/json/font-collection.json b/schemas/json/font-collection.json new file mode 100644 index 00000000000000..0b12bb2ca054bc --- /dev/null +++ b/schemas/json/font-collection.json @@ -0,0 +1,45 @@ +{ + "title": "JSON schema for WordPress Font Collection", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "fontFamilies": { + "type": "array", + "description": "Array of font families ready to be installed", + "items": { + "type": "object", + "properties": { + "font_family_settings": { + "description": "Font family settings as in theme.json", + "allOf": [ + { "$ref": "./theme.json#/definitions/fontFamily" } + ] + }, + "categories": { + "type": "array", + "description": "Array of category slugs", + "items": { + "type": "string" + } + } + } + } + }, + "categories": { + "type": "array", + "description": "Array of category objects", + "items": { + "type": "object", + "properties": { + "slug": { + "type": "string" + }, + "title": { + "type": "string" + } + }, + "required": [ "slug", "title" ] + } + } + } +} From a2cfd5abc46429ed55cb7d326bd8d6643cf3f453 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 10:00:50 -0300 Subject: [PATCH 03/14] adding settings --- schemas/json/font-collection.json | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/schemas/json/font-collection.json b/schemas/json/font-collection.json index 0b12bb2ca054bc..9625924e521286 100644 --- a/schemas/json/font-collection.json +++ b/schemas/json/font-collection.json @@ -3,7 +3,16 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { - "fontFamilies": { + "$schema": { + "description": "JSON schema URI for font-collection.json.", + "type": "string" + }, + "version": { + "description": "Version of font-collection.json schema to use.", + "type": "integer", + "enum": [ 1 ] + }, + "font_families": { "type": "array", "description": "Array of font families ready to be installed", "items": { @@ -22,7 +31,8 @@ "type": "string" } } - } + }, + "required": [ "font_family_settings" ] } }, "categories": { From 08658adfe32542690cdc1bd8bba9bf156c3ae4a8 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 10:03:30 -0300 Subject: [PATCH 04/14] updating README --- schemas/README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/schemas/README.md b/schemas/README.md index 1b2d8992cccb90..fa695115f33abe 100644 --- a/schemas/README.md +++ b/schemas/README.md @@ -1,6 +1,6 @@ # Schemas -The collection of schemas used in WordPress, including the `theme.json` and `block.json` schemas. +The collection of schemas used in WordPress, including the `theme.json`, `block.json` and `font-collection.json` schemas. JSON schemas are used by code editors to offer tooltips, autocomplete, and validation. @@ -24,6 +24,14 @@ Or in your `theme.json`: } ``` +Or in your `font-collection.json`: + +```json +{ + "$schema": "https://schemas.wp.org/trunk/font-collection.json" +} +``` + For a specific version of the schema, replace `trunk` with `wp/X.X`: ```json @@ -56,8 +64,16 @@ To allow this you will need to: } ``` +- update your font collections's `font-collection.json` to include: + +```json +{ + "$schema": "file://{{FULL_FILE_PATH}}/schemas/json/font-collection.json" +} +``` + Be sure to replace `{{FULL_FILE_PATH}}` with the full local path to your Gutenberg repo. -With this in place you should now be able to edit either `schemas/json/theme .json` or `schemas/json/block.json` in order to see changes reflected in `theme.json` or `block.json` in your IDE. +With this in place you should now be able to edit either `schemas/json/theme .json`, `schemas/json/block.json` or `schemas/json/font-collection.json` in order to see changes reflected in `theme.json`, `block.json` or `font-collection.json` in your IDE.

Code is Poetry.

From 453073864635932e2d92c35f21f3100e6b310cc9 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 13:30:59 -0300 Subject: [PATCH 05/14] update property name --- schemas/json/font-collection.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schemas/json/font-collection.json b/schemas/json/font-collection.json index 9625924e521286..7e21d017584ab2 100644 --- a/schemas/json/font-collection.json +++ b/schemas/json/font-collection.json @@ -44,11 +44,11 @@ "slug": { "type": "string" }, - "title": { + "name": { "type": "string" } }, - "required": [ "slug", "title" ] + "required": [ "slug", "name" ] } } } From 2214b1941930434854b6907ff302a772015e3ca3 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 15:21:48 -0300 Subject: [PATCH 06/14] resolve json schema references --- bin/api-docs/gen-theme-reference.js | 39 ++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/bin/api-docs/gen-theme-reference.js b/bin/api-docs/gen-theme-reference.js index f638bb708890a8..b4b5427544c2f0 100644 --- a/bin/api-docs/gen-theme-reference.js +++ b/bin/api-docs/gen-theme-reference.js @@ -74,6 +74,40 @@ const keys = ( maybeObject ) => { return Object.keys( maybeObject ); }; +/** + * Get definition from ref. + * + * @param {string} ref + * @return {Object} definition + * + * @example + * getDefinition( '#/definitions/typographyProperties/properties/fontFamily' ) + * // returns themejson.definitions.typographyProperties.properties.fontFamily + * + */ +const resolveDefintionRef = ( ref ) => { + const refParts = ref.split( '/' ); + const definition = refParts[ refParts.length - 1 ]; + return themejson.definitions[ definition ]; +}; + +/** + * Get properties from an array. + * + * @param {Object} items + * @return {Object} properties + * + */ +const getPropertiesFromArray = ( items ) => { + // if its a $ref resolve it + if ( items.$ref ) { + return resolveDefintionRef( items.$ref ).properties; + } + + // otherwise just return the properties + return items.properties; +}; + /** * Convert settings properties to markup. * @@ -96,7 +130,10 @@ const getSettingsPropertiesMarkup = ( struct ) => { const def = 'default' in props[ key ] ? props[ key ].default : ''; const ps = props[ key ].type === 'array' - ? keys( props[ key ].items.properties ).sort().join( ', ' ) + ? // ? keys( props[ key ].items.properties ).sort().join( ', ' ) + keys( getPropertiesFromArray( props[ key ].items ) ) + .sort() + .join( ', ' ) : ''; markup += `| ${ key } | ${ props[ key ].type } | ${ def } | ${ ps } |\n`; } ); From 0b10939448d7611ef1f3ba9f4d888f8037e962f9 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 15:30:45 -0300 Subject: [PATCH 07/14] throw error on definition not found --- bin/api-docs/gen-theme-reference.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/api-docs/gen-theme-reference.js b/bin/api-docs/gen-theme-reference.js index b4b5427544c2f0..df83aa63100e3b 100644 --- a/bin/api-docs/gen-theme-reference.js +++ b/bin/api-docs/gen-theme-reference.js @@ -79,15 +79,19 @@ const keys = ( maybeObject ) => { * * @param {string} ref * @return {Object} definition + * @throws {Error} If the referenced definition is not found in 'themejson.definitions'. * * @example * getDefinition( '#/definitions/typographyProperties/properties/fontFamily' ) - * // returns themejson.definitions.typographyProperties.properties.fontFamily + * // returns themejson.definitions.typographyProperties.properties.fontFamily * */ const resolveDefintionRef = ( ref ) => { const refParts = ref.split( '/' ); const definition = refParts[ refParts.length - 1 ]; + if ( ! themejson.definitions[ definition ] ) { + throw new Error( `Can't resolve '${ ref }'. Definition not found` ); + } return themejson.definitions[ definition ]; }; From 24bf540d06f1b96362e68c88759edbd3c2fabcbf Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 15:31:18 -0300 Subject: [PATCH 08/14] add description --- schemas/json/theme.json | 1 + 1 file changed, 1 insertion(+) diff --git a/schemas/json/theme.json b/schemas/json/theme.json index 80d703223cd684..4e195ffb471fe8 100644 --- a/schemas/json/theme.json +++ b/schemas/json/theme.json @@ -619,6 +619,7 @@ }, "fontFamily": { "type": "object", + "description": "Font family preset", "properties": { "name": { "description": "Name of the font family preset, translatable.", From 1e4e1406d303b41e37b27e69cfbc654f42d6a589 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 15:48:02 -0300 Subject: [PATCH 09/14] disallow additional properties --- schemas/json/font-collection.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/schemas/json/font-collection.json b/schemas/json/font-collection.json index 7e21d017584ab2..c4f2374dd72b37 100644 --- a/schemas/json/font-collection.json +++ b/schemas/json/font-collection.json @@ -32,7 +32,8 @@ } } }, - "required": [ "font_family_settings" ] + "required": [ "font_family_settings" ], + "additionalProperties": false } }, "categories": { @@ -48,8 +49,11 @@ "type": "string" } }, - "required": [ "slug", "name" ] + "required": [ "slug", "name" ], + "additionalProperties": false } } - } + }, + "additionalProperties": false, + "required": [ "$schema", "version", "font_families" ] } From 3f0353834568c4cad5173c140f442aefb6e8e2c3 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 18:30:27 -0300 Subject: [PATCH 10/14] fix typo in function name Co-authored-by: Jeff Ong --- bin/api-docs/gen-theme-reference.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/api-docs/gen-theme-reference.js b/bin/api-docs/gen-theme-reference.js index df83aa63100e3b..a028cdc5959315 100644 --- a/bin/api-docs/gen-theme-reference.js +++ b/bin/api-docs/gen-theme-reference.js @@ -86,7 +86,7 @@ const keys = ( maybeObject ) => { * // returns themejson.definitions.typographyProperties.properties.fontFamily * */ -const resolveDefintionRef = ( ref ) => { +const resolveDefinitionRef = ( ref ) => { const refParts = ref.split( '/' ); const definition = refParts[ refParts.length - 1 ]; if ( ! themejson.definitions[ definition ] ) { From 6f1c65d7e364003ee611672456957c8317267f7d Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 18:30:37 -0300 Subject: [PATCH 11/14] fix typo in function name Co-authored-by: Jeff Ong --- bin/api-docs/gen-theme-reference.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/api-docs/gen-theme-reference.js b/bin/api-docs/gen-theme-reference.js index a028cdc5959315..57fc8630ec289c 100644 --- a/bin/api-docs/gen-theme-reference.js +++ b/bin/api-docs/gen-theme-reference.js @@ -105,7 +105,7 @@ const resolveDefinitionRef = ( ref ) => { const getPropertiesFromArray = ( items ) => { // if its a $ref resolve it if ( items.$ref ) { - return resolveDefintionRef( items.$ref ).properties; + return resolveDefinitionRef( items.$ref ).properties; } // otherwise just return the properties From c35ad01fb9d0b701347758298b6dcb55b679ef2d Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 18:30:53 -0300 Subject: [PATCH 12/14] fix wording Co-authored-by: Jeff Ong --- schemas/json/font-collection.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/json/font-collection.json b/schemas/json/font-collection.json index c4f2374dd72b37..a6ca2b1412e6d2 100644 --- a/schemas/json/font-collection.json +++ b/schemas/json/font-collection.json @@ -1,5 +1,5 @@ { - "title": "JSON schema for WordPress Font Collection", + "title": "JSON schema for WordPress Font Collections", "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { From e10a6a3f9e06706f49c92c16b3c798a16190752d Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 18:31:11 -0300 Subject: [PATCH 13/14] remove unwanted comment Co-authored-by: Jeff Ong --- bin/api-docs/gen-theme-reference.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/api-docs/gen-theme-reference.js b/bin/api-docs/gen-theme-reference.js index 57fc8630ec289c..af10e1a7f7ea52 100644 --- a/bin/api-docs/gen-theme-reference.js +++ b/bin/api-docs/gen-theme-reference.js @@ -134,7 +134,7 @@ const getSettingsPropertiesMarkup = ( struct ) => { const def = 'default' in props[ key ] ? props[ key ].default : ''; const ps = props[ key ].type === 'array' - ? // ? keys( props[ key ].items.properties ).sort().join( ', ' ) + ? keys( getPropertiesFromArray( props[ key ].items ) ) .sort() .join( ', ' ) From cf1add29dee8353ebd1f82e382dd741643acacbc Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 18:35:35 -0300 Subject: [PATCH 14/14] format js --- bin/api-docs/gen-theme-reference.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bin/api-docs/gen-theme-reference.js b/bin/api-docs/gen-theme-reference.js index af10e1a7f7ea52..0ea9e282e5463e 100644 --- a/bin/api-docs/gen-theme-reference.js +++ b/bin/api-docs/gen-theme-reference.js @@ -84,7 +84,6 @@ const keys = ( maybeObject ) => { * @example * getDefinition( '#/definitions/typographyProperties/properties/fontFamily' ) * // returns themejson.definitions.typographyProperties.properties.fontFamily - * */ const resolveDefinitionRef = ( ref ) => { const refParts = ref.split( '/' ); @@ -100,7 +99,6 @@ const resolveDefinitionRef = ( ref ) => { * * @param {Object} items * @return {Object} properties - * */ const getPropertiesFromArray = ( items ) => { // if its a $ref resolve it @@ -134,8 +132,7 @@ const getSettingsPropertiesMarkup = ( struct ) => { const def = 'default' in props[ key ] ? props[ key ].default : ''; const ps = props[ key ].type === 'array' - ? - keys( getPropertiesFromArray( props[ key ].items ) ) + ? keys( getPropertiesFromArray( props[ key ].items ) ) .sort() .join( ', ' ) : '';