diff --git a/schemas/manifest_theme.json b/schemas/manifest_theme.json index 918b222..f825c4a 100644 --- a/schemas/manifest_theme.json +++ b/schemas/manifest_theme.json @@ -13,6 +13,7 @@ { "uri": "theme/theme_block_entry.json" }, { "uri": "theme/targetted_block_entry.json" }, { "uri": "theme/preset_blocks.json" }, + { "uri": "theme/preset.json" }, { "uri": "theme/local_block_entry.json" } ] } diff --git a/schemas/theme/preset.json b/schemas/theme/preset.json new file mode 100644 index 0000000..fc785d8 --- /dev/null +++ b/schemas/theme/preset.json @@ -0,0 +1,66 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Shopify Liquid Section or Block Preset Schema", + "oneOf": [ + { + "$ref": "#/definitions/presetWithBlocksArray" + }, + { + "$ref": "#/definitions/presetWithBlocksHash" + } + ], + "definitions": { + "presetBase": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "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" + } + } + }, + "presetWithBlocksArray": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/presetBase" + } + ], + "properties": { + "name": true, + "settings": true, + "blocks": { + "$ref": "./preset_blocks.json#/definitions/blocksArray" + } + }, + "additionalProperties": false + }, + "presetWithBlocksHash": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/presetBase" + } + ], + "required": ["blocks"], + "properties": { + "name": true, + "settings": true, + "blocks": { + "$ref": "./preset_blocks.json#/definitions/blocksHash" + }, + "block_order": { + "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/preset_blocks.json b/schemas/theme/preset_blocks.json index b9a0c5f..1cad069 100644 --- a/schemas/theme/preset_blocks.json +++ b/schemas/theme/preset_blocks.json @@ -1,14 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Shopify Liquid Preset Blocks Schema", - "oneOf": [ - { - "$ref": "#/definitions/blocksArray" - }, - { - "$ref": "#/definitions/blocksHash" - } - ], "definitions": { "blocksArray": { "type": "array", @@ -25,7 +17,9 @@ "static": true, "type": true, "settings": true, - "blocks": true, + "blocks": { + "$ref": "#/definitions/blocksArray" + }, "id": { "type": "string", "description": "A unique identifier for the block." @@ -50,7 +44,23 @@ "description": "A list of child blocks that you might want to include.", "markdownDescription": "A list of child blocks that you might want to include.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/sections/section-schema#presets)", "additionalProperties": { - "$ref": "#/definitions/commonBlockAttributes", + "allOf": [ + { + "$ref": "#/definitions/commonBlockAttributes" + } + ], + "properties": { + "static": true, + "type": true, + "settings": true, + "blocks": { + "$ref": "#/definitions/blocksHash" + }, + "block_order": { + "type": "array", + "description": "The order of the blocks in the section." + } + }, "additionalProperties": false } }, @@ -65,9 +75,6 @@ "settings": { "$ref": "./default_setting_values.json" }, - "blocks": { - "$ref": "#" - }, "static": { "type": "boolean", "description": "If the block is rendered statically or not." diff --git a/schemas/theme/section.json b/schemas/theme/section.json index d1e7457..4036c80 100644 --- a/schemas/theme/section.json +++ b/schemas/theme/section.json @@ -99,21 +99,7 @@ "description": "Presets are default configurations of sections that enable users to easily add a section to a JSON template through the theme editor.", "markdownDescription": "Presets are default configurations of sections that enable users to easily add a section to a [JSON template](https://shopify.dev/docs/themes/architecture/templates/json-templates) through the theme editor.\n\n---\n\n[Shopify reference](https://shopify.dev/docs/themes/architecture/sections/section-schema#presets)", "items": { - "type": "object", - "required": ["name"], - "properties": { - "name": { - "type": "string", - "description": "The preset name, which will show in the Add section picker of the theme editor.", - "markdownDescription": "The preset name, which will show in the Add section 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" - }, - "blocks": { - "$ref": "./preset_blocks.json" - } - } + "$ref": "./preset.json" } }, 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/section-schema-preset-blocks-as-hash.json b/tests/fixtures/section-schema-preset-blocks-as-hash.json index 981dcda..cd4dadb 100644 --- a/tests/fixtures/section-schema-preset-blocks-as-hash.json +++ b/tests/fixtures/section-schema-preset-blocks-as-hash.json @@ -24,9 +24,14 @@ "nestedExampleBlock": { "type": "text" } - } + }, + "block_order": ["nestedExampleBlock"] + }, + "exampleBlock3": { + "type": "text" } - } + }, + "block_order": ["exampleBlock", "exampleBlock2", "exampleBlock3"] } ], "locales": { diff --git a/tests/fixtures/theme-block-presets-as-hash.json b/tests/fixtures/theme-block-presets-as-hash.json index 7c7ad59..a480e68 100644 --- a/tests/fixtures/theme-block-presets-as-hash.json +++ b/tests/fixtures/theme-block-presets-as-hash.json @@ -1,39 +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": ["nested-block-id"] } - } - ] - } - \ No newline at end of file + }, + "block_order": [ + "some-block-id", + "some-other-block-id" + ] + } + ] +}