Repository navigation
docs(administration): Vue single file component extension documentation #2503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
d3574e8
docs(administration): add entrypoint for sfc documentation
davidtraum e257c35
docs(administration): add a hands-on tutorial for SFC extensions
gweiermann 2a13bca
docs(administration): lead every before/after tab with its template
gweiermann fbbd0a0
docs(administration): retake the tutorial screenshots on a clean shop
gweiermann e9c45ef
docs(administration): add the SFC API reference
gweiermann 713c6f7
docs(administration): import the composables in the API reference
gweiermann 07b46a6
docs(administration): nest the tutorial chapters under a parent page
gweiermann 87fcd36
Merge the tutorial branch, and split the reference into one page per API
gweiermann acfe394
docs(administration): group the reference into macros, composables an…
gweiermann 5dac8de
docs: do not show imports for the override composables
gweiermann c911de5
Merge the tutorial branch
gweiermann 42d1885
docs(administration): the override composables are not imported either
gweiermann 8fa33ef
docs(administration): document every Administration composable
gweiermann 9b10458
docs(administration): document useCmsElementDeprecated and how to mov…
gweiermann ddf13e9
docs(administration): one page per composable
gweiermann 9edefee
docs(administration): drop the Vue composables section from the index
gweiermann 521d32d
docs(administration): add the SFC roadmap page
gweiermann 33bd648
docs(administration): explain the SFC internals
gweiermann dbceeaf
docs(administration): add timeline to index page
davidtraum 7136325
docs(administration): improve index page
davidtraum 4429c8a
docs(administration): add link hint
davidtraum b814ce8
docs(administration): fix markdown
davidtraum db28bf7
Merge branch 'main' into docs/admin-vue-sfc-extensions
davidtraum e8591ae
docs(administration): fix table alignment
davidtraum 074b2db
docs(administration): fix table alignments
davidtraum 258b08c
docs: add some improvements, cross references, etc.
jleifeld 500c707
docs: add discussion link
davidtraum 943a9d7
docs: update composable imports
davidtraum 2319277
docs: update v-if usage on sw-block-extends
davidtraum 100cae5
docs: fix code example
davidtraum 9d42471
docs: explain cache clear for new admin snippets
gweiermann a821620
docs: use console commands for extension tooling
gweiermann 624b5bf
docs: update product menu path
gweiermann a1897dd
docs: describe what actually changes at the chapter 4 checkpoint
gweiermann c242a39
docs: address review findings in the SFC extension documentation
jleifeld f133eea
docs: fix spellcheck in the composables reference
jleifeld e73c698
docs: apply review feedback on the SFC tutorial
gweiermann 2fab96c
docs: show the by-name registration before the route exception
gweiermann 6a96a00
docs: correct SFC docs against trunk and fill gaps found in review
gweiermann 3464028
docs: date the SFC system to 6.7.16.0 and separate the BC promise fro…
gweiermann 53092d2
docs: regenerate the SFC internals from the current transform
gweiermann f827893
docs: add demo data to the SFC tutorial setup and trim chapter 2
gweiermann 90c398d
docs: show the template values before the template in chapter 3
gweiermann c165480
Merge branch 'main' into docs/admin-vue-sfc-extensions
gweiermann 0c9892c
docs: update faq for vue-native migration
davidtraum 2464b53
Merge branch 'main' into docs/admin-vue-sfc-extensions
sushmangupta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...s/administration/single-file-components/api-reference/block-components/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| nav: | ||
| title: Block components | ||
| position: 30 | ||
|
|
||
| --- | ||
|
|
||
| # Block components | ||
|
|
||
| <!--@include: ../../../../../../../snippets/guide/administration_sfc_experimental.md--> | ||
|
|
||
| Two globally registered components carry the native block system. You write the tags without importing anything. | ||
|
|
||
| <PageRef page="sw-block" title="sw-block" sub="Declare an extension point, or contribute to one" /> | ||
| <PageRef page="sw-block-parent" title="sw-block-parent" sub="Render what the extension point held before you" /> | ||
|
|
||
| ## The model | ||
|
|
||
| A component **declares** an extension point by wrapping markup in `<sw-block name="…">`. Its children are the default content, and with nothing registered against the name it renders as though the wrapper were not there. | ||
|
|
||
| An override **contributes** to that point with `<sw-block extends="…">`. That tag renders nothing where it stands: it registers its content, and the matching `<sw-block name>` renders it wherever that happens to be. | ||
|
|
||
| ```html | ||
| <!-- swag-greeting-card.vue --> | ||
| <sw-block name="swag_greeting_card_body"> | ||
| <p>Default content</p> | ||
| </sw-block> | ||
|
|
||
| <!-- swag-greeting-card.override.vue --> | ||
| <sw-block extends="swag_greeting_card_body"> | ||
| <sw-block-parent /> | ||
| <p>Mine, underneath</p> | ||
| </sw-block> | ||
| ``` | ||
|
|
||
| ## Names | ||
|
|
||
| A block name is a plain string and nothing validates it, so a typo matches nothing and fails silently. Names must be unique per component. | ||
|
|
||
| The convention is an owner prefix, then the path through the component, in `snake_case`: | ||
|
|
||
| ```text | ||
| sw_product_detail_base_price_form | ||
| swag_greeting_card_body | ||
| ``` | ||
|
|
||
| Core uses `sw_`; a plugin uses its own prefix. A block name you find in core is covered by the backwards-compatibility promise: it stays until the next major version, and if one is removed in a major, the changelog names it. When core converts a component to a Single File Component, its block names stay the same. | ||
|
|
||
| ## Chains | ||
|
|
||
| Several overrides may target one block. They stack in registration order, and each one's `<sw-block-parent />` renders the previous one's output rather than the original default. Leaving `<sw-block-parent />` out replaces everything below it, which is how one plugin removes another plugin's contribution. |
47 changes: 47 additions & 0 deletions
47
...ration/single-file-components/api-reference/block-components/sw-block-parent.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| --- | ||
| nav: | ||
| title: sw-block-parent | ||
| position: 70 | ||
|
|
||
| --- | ||
|
|
||
| # `sw-block-parent` | ||
|
|
||
| <!--@include: ../../../../../../../snippets/guide/administration_sfc_experimental.md--> | ||
|
|
||
| ```html | ||
| <sw-block-parent /> | ||
| ``` | ||
|
|
||
| Takes no props. Renders whatever the extension point held before this override: the default content, or the previous override in the chain. Globally registered, so you write the tag without importing anything. | ||
|
|
||
| Leave it out and the original markup is replaced. | ||
|
|
||
| ## Position decides yours | ||
|
|
||
| ```html | ||
| <!-- append --> | ||
| <sw-block extends="swag_greeting_card_body"> | ||
| <sw-block-parent /> | ||
| <p>I go after</p> | ||
| </sw-block> | ||
|
|
||
| <!-- prepend --> | ||
| <sw-block extends="swag_greeting_card_body"> | ||
| <p>I go before</p> | ||
| <sw-block-parent /> | ||
| </sw-block> | ||
|
|
||
| <!-- replace --> | ||
| <sw-block extends="swag_greeting_card_body"> | ||
| <p>The original content is gone</p> | ||
| </sw-block> | ||
| ``` | ||
|
|
||
| ## Render it once, unconditionally | ||
|
|
||
| It claims its position in the chain when it is created, so a `v-if` on it, or a `v-for` around it, corrupts that chain. One `<sw-block-parent />` per extending block, always rendered. | ||
|
|
||
| ## Chains | ||
|
|
||
| When several overrides target one block they stack, and each one's `<sw-block-parent />` renders the previous one's output rather than the original default. That is what keeps other plugins on the page when your own change is additive. | ||
61 changes: 61 additions & 0 deletions
61
...dministration/single-file-components/api-reference/block-components/sw-block.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| nav: | ||
| title: sw-block | ||
| position: 60 | ||
|
|
||
| --- | ||
|
|
||
| # `sw-block` | ||
|
|
||
| <!--@include: ../../../../../../../snippets/guide/administration_sfc_experimental.md--> | ||
|
|
||
| The extension point. Globally registered, so you write the tag without importing anything. Which prop you pass decides what it does. | ||
|
|
||
| | Prop | Type | Meaning | | ||
| | --------- | -------- | ------------------------------------------------------------------------------------ | | ||
| | `name` | `string` | **Declares** an extension point. Its children are the default content | | ||
| | `extends` | `string` | **Contributes** to the extension point of that name. Renders nothing where it stands | | ||
|
|
||
| Write `name` (base components only) or `extends` (overrides only) as a static attribute and nothing else. The component has other props - your editor may offer them - and they are internal. The build rejects any other attribute or directive on the tag, including `class`, `v-if`, a bound `:extends`, `data`, `v-bind` and an authored `#default`. | ||
|
|
||
| ## Declaring an extension point | ||
|
|
||
| ```html | ||
| <sw-block name="swag_greeting_card_body"> | ||
| <p>Default content</p> | ||
| </sw-block> | ||
| ``` | ||
|
|
||
| With nothing registered against the name, this renders as though the wrapper were not there. | ||
|
|
||
| ## Contributing to one | ||
|
|
||
| ```html | ||
| <sw-block extends="swag_greeting_card_body"> | ||
| <sw-block-parent /> | ||
| <p>Mine, underneath</p> | ||
| </sw-block> | ||
| ``` | ||
|
|
||
| The target block is replaced by what goes inside. To keep what was there, render [`sw-block-parent`](sw-block-parent). | ||
|
|
||
| An `<sw-block extends>` belongs at the root of an override's template and cannot be nested inside another element. Where it sits does not affect where its content renders: it registers the content, and the matching `<sw-block name>` renders it. | ||
|
|
||
| ## Names | ||
|
|
||
| Block names are strings and nothing validates them, so a typo silently matches nothing. They must be unique per component. The convention is an owner prefix and then the path through the component, in `snake_case`: core uses `sw_`, a plugin uses its own. | ||
|
|
||
| ```text | ||
| sw_product_detail_base_price_form | ||
| swag_greeting_card_body | ||
| ``` | ||
|
|
||
| ## Bindings in block content | ||
|
|
||
| Your override's bindings are available inside its `<sw-block extends>` content and read like any other Vue template binding. Mutating one from the template - `@click="counter++"` - is not supported; wrap the mutation in a function and call that instead. | ||
|
|
||
| ## Order, when several extensions meet | ||
|
|
||
| Native `<sw-block extends>` contributions render in registration order, and all of them render after a TwigJS override of the same block. A legacy override is therefore always the parent of a native one, whichever order the plugins load in. | ||
|
|
||
| <PageRef page="../../internals" title="Internals" sub="How the chain is assembled, and why the order is what it is" /> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.