Skip to content

Commit

Permalink
Add to block presets
Browse files Browse the repository at this point in the history
  • Loading branch information
miazbikowski committed Nov 25, 2024
1 parent d1aa082 commit 42ed549
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 59 deletions.
34 changes: 28 additions & 6 deletions schemas/theme/preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -10,27 +13,45 @@
}
],
"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"
},
"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"
Expand All @@ -42,7 +63,8 @@
"type": "array",
"description": "The order of blocks in the preset.",
"markdownDescription": "The order of blocks in the preset."
}
},
"additionalProperties": false
}
}
}
Expand Down
16 changes: 1 addition & 15 deletions schemas/theme/theme_block.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <strong>Add block</strong> 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"
}
},

Expand Down
81 changes: 43 additions & 38 deletions tests/fixtures/theme-block-presets-as-hash.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}

},
"block_order": ["nested-block-id"]
}
},
"block_order": [
"some-block-id",
"some-other-block-id"
]
}
]
}

0 comments on commit 42ed549

Please sign in to comment.