From 42ed5499c300ff09e76d2d838c692717828c8261 Mon Sep 17 00:00:00 2001 From: Mia Zbikowski Date: Mon, 25 Nov 2024 12:58:33 -0500 Subject: [PATCH] Add to block presets --- schemas/theme/preset.json | 34 ++++++-- schemas/theme/theme_block.json | 16 +--- .../fixtures/theme-block-presets-as-hash.json | 81 ++++++++++--------- 3 files changed, 72 insertions(+), 59 deletions(-) diff --git a/schemas/theme/preset.json b/schemas/theme/preset.json index 6742121..0322c0a 100644 --- a/schemas/theme/preset.json +++ b/schemas/theme/preset.json @@ -2,6 +2,9 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Shopify Liquid Section or Block Preset Schema", "oneOf": [ + { + "$ref": "#/definitions/presetWithJustSettings" + }, { "$ref": "#/definitions/presetWithBlocksArray" }, @@ -10,12 +13,27 @@ } ], "definitions": { + "presetWithJustSettings": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string" + }, + "settings": { + "$ref": "./default_setting_values.json" + } + }, + "additionalProperties": false + }, "presetWithBlocksArray": { + "type": "object", + "required": ["name", "blocks"], "properties": { "name": { "type": "string", - "description": "The preset name, which will show in the Add section or block picker of the theme editor.", - "markdownDescription": "The preset name, which will show in the Add section or block picker of the theme editor.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/sections/section-schema#presets)" + "description": "The preset name, which will show in the 'Add section' or 'Add block' picker of the theme editor.", + "markdownDescription": "The preset name, which will show in the 'Add section' or 'Add block' picker of the theme editor.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/sections/section-schema#presets)" }, "settings": { "$ref": "./default_setting_values.json" @@ -23,14 +41,17 @@ "blocks": { "$ref": "./preset_blocks.json#/definitions/blocksArray" } - } + }, + "additionalProperties": false }, "presetWithBlocksHash": { + "type": "object", + "required": ["name", "blocks"], "properties": { "name": { "type": "string", - "description": "The preset name, which will show in the Add section or block picker of the theme editor.", - "markdownDescription": "The preset name, which will show in the Add section or block picker of the theme editor.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/sections/section-schema#presets)" + "description": "The preset name, which will show in the 'Add section' or 'Add block' picker of the theme editor.", + "markdownDescription": "The preset name, which will show in the 'Add section' or 'Add block' picker of the theme editor.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/sections/section-schema#presets)" }, "settings": { "$ref": "./default_setting_values.json" @@ -42,7 +63,8 @@ "type": "array", "description": "The order of blocks in the preset.", "markdownDescription": "The order of blocks in the preset." - } + }, + "additionalProperties": false } } } diff --git a/schemas/theme/theme_block.json b/schemas/theme/theme_block.json index c0a8771..0cb2fa5 100644 --- a/schemas/theme/theme_block.json +++ b/schemas/theme/theme_block.json @@ -60,21 +60,7 @@ "description": "Presets are default configurations of blocks that enable merchants to easily add a block to a JSON template through the theme editor.", "markdownDescription": "Presets are default configurations of blocks that enable merchants to easily add a block to a JSON template through the theme editor.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/blocks/theme-blocks/schema#presets)", "items": { - "type": "object", - "required": ["name"], - "properties": { - "name": { - "type": "string", - "description": "The preset name, which displays in the Add block picker of the theme editor.", - "markdownDescription": "The preset name, which displays in the Add block picker of the theme editor.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/blocks/theme-blocks/schema#presets)" - }, - "settings": { - "$ref": "./default_setting_values.json" - }, - "blocks": { - "$ref": "./preset_blocks.json" - } - } + "$ref": "./preset.json" } }, diff --git a/tests/fixtures/theme-block-presets-as-hash.json b/tests/fixtures/theme-block-presets-as-hash.json index 8e8fe2d..a480e68 100644 --- a/tests/fixtures/theme-block-presets-as-hash.json +++ b/tests/fixtures/theme-block-presets-as-hash.json @@ -1,43 +1,48 @@ { - "name": "my block", - "blocks": [{ "type": "@app" }, { "type": "@theme" }], - "class": "my-class", - "tag": "custom-element", - "settings": [ - { - "type": "header", - "content": "header name", - "info": "header info" + "name": "my block", + "blocks": [{ "type": "@app" }, { "type": "@theme" }], + "class": "my-class", + "tag": "custom-element", + "settings": [ + { + "type": "header", + "content": "header name", + "info": "header info" + }, + { + "type": "number", + "id": "number", + "label": "my number" + } + ], + "presets": [ + { + "name": "preset name", + "settings": { + "number": 1 }, - { - "type": "number", - "id": "number", - "label": "my number" - } - ], - "presets": [ - { - "name": "preset name", - "settings": { - "number": 1 + "blocks": { + "some-block-id": { + "type": "button" }, - "blocks": { - "some-block-id": { - "type": "button" + "some-other-block-id": { + "type": "image", + "static": true, + "settings": { + "some-setting": "some-value" }, - "some-other-block-id": { - "type": "image", - "static": true, - "settings": { - "some-setting": "some-value" + "blocks": { + "nested-block-id": { + "type": "text" } - } - }, - "block_order": [ - "some-block-id", - "some-other-block-id" - ] - } - ] - } - \ No newline at end of file + }, + "block_order": ["nested-block-id"] + } + }, + "block_order": [ + "some-block-id", + "some-other-block-id" + ] + } + ] +}